TrinityCore
CreatureGroups.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef _FORMATIONS_H
19#define _FORMATIONS_H
20
21#include "Define.h"
22#include "ObjectGuid.h"
23#include <unordered_map>
24
26{
27 FLAG_AGGRO_NONE = 0, // No creature group behavior
28 FLAG_MEMBERS_ASSIST_LEADER = 0x00000001, // The member aggroes if the leader aggroes
29 FLAG_LEADER_ASSISTS_MEMBER = 0x00000002, // The leader aggroes if the member aggroes
30 FLAG_MEMBERS_ASSIST_MEMBER = (FLAG_MEMBERS_ASSIST_LEADER | FLAG_LEADER_ASSISTS_MEMBER), // every member will assist if any member is attacked
31 FLAG_IDLE_IN_FORMATION = 0x00000200, // The member will follow the leader when pathing idly
32};
33
34class Creature;
35class CreatureGroup;
36class Unit;
37struct Position;
38
40{
46};
47
49{
50 private:
53
54 std::unordered_map<ObjectGuid::LowType /*spawnID*/, FormationInfo> _creatureGroupMap;
55
56 public:
57 static FormationMgr* instance();
58
59 void AddCreatureToGroup(ObjectGuid::LowType leaderSpawnId, Creature* creature);
60 void RemoveCreatureFromGroup(CreatureGroup* group, Creature* creature);
61
62 void LoadCreatureFormations();
63 FormationInfo* GetFormationInfo(ObjectGuid::LowType spawnId);
64
65 void AddFormationMember(ObjectGuid::LowType spawnId, float followAng, float followDist, ObjectGuid::LowType leaderSpawnId, uint32 groupAI);
66};
67
69{
70 private:
71 Creature* _leader; //Important do not forget sometimes to work with pointers instead synonims :D:D
72 std::unordered_map<Creature*, FormationInfo*> _members;
73
75 bool _formed;
77
78 public:
79 //Group cannot be created empty
80 explicit CreatureGroup(ObjectGuid::LowType leaderSpawnId);
82
83 Creature* GetLeader() const { return _leader; }
84 ObjectGuid::LowType GetLeaderSpawnId() const { return _leaderSpawnId; }
85 bool IsEmpty() const { return _members.empty(); }
86 bool IsFormed() const { return _formed; }
87 bool IsLeader(Creature const* creature) const { return _leader == creature; }
88
89 bool HasMember(Creature* member) const { return _members.count(member) > 0; }
90 void AddMember(Creature* member);
91 void RemoveMember(Creature* member);
92 void FormationReset(bool dismiss);
93
94 void LeaderStartedMoving();
95 void MemberEngagingTarget(Creature* member, Unit* target);
96 bool CanLeaderStartMoving() const;
97};
98
99#define sFormationMgr FormationMgr::instance()
100
101#endif
GroupAIFlags
@ FLAG_MEMBERS_ASSIST_MEMBER
@ FLAG_AGGRO_NONE
@ FLAG_LEADER_ASSISTS_MEMBER
@ FLAG_IDLE_IN_FORMATION
@ FLAG_MEMBERS_ASSIST_LEADER
#define TC_GAME_API
Definition: Define.h:123
uint32_t uint32
Definition: Define.h:142
Creature * GetLeader() const
ObjectGuid::LowType GetLeaderSpawnId() const
bool IsFormed() const
bool IsLeader(Creature const *creature) const
bool IsEmpty() const
std::unordered_map< Creature *, FormationInfo * > _members
ObjectGuid::LowType _leaderSpawnId
bool HasMember(Creature *member) const
Creature * _leader
std::unordered_map< ObjectGuid::LowType, FormationInfo > _creatureGroupMap
uint64 LowType
Definition: ObjectGuid.h:278
Definition: Unit.h:627
ObjectGuid::LowType LeaderSpawnId
uint32 LeaderWaypointIDs[2]