TrinityCore
Loading...
Searching...
No Matches
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#include <map>
25
27{
28 FLAG_AGGRO_NONE = 0, // No creature group behavior
29 FLAG_MEMBERS_ASSIST_LEADER = 0x00000001, // The member aggroes if the leader aggroes
30 FLAG_LEADER_ASSISTS_MEMBER = 0x00000002, // The leader aggroes if the member aggroes
31 FLAG_MEMBERS_ASSIST_MEMBER = (FLAG_MEMBERS_ASSIST_LEADER | FLAG_LEADER_ASSISTS_MEMBER), // every member will assist if any member is attacked
32 FLAG_IDLE_IN_FORMATION = 0x00000200, // The member will follow the leader when pathing idly
33};
34
35class Creature;
36class CreatureGroup;
37class Unit;
38struct Position;
39
48
50{
51 private:
54
55 std::unordered_map<ObjectGuid::LowType /*spawnID*/, FormationInfo> _creatureGroupMap;
56
57 public:
58 static FormationMgr* instance();
59
60 void AddCreatureToGroup(ObjectGuid::LowType leaderSpawnId, Creature* creature);
61 void RemoveCreatureFromGroup(CreatureGroup* group, Creature* creature);
62
63 void LoadCreatureFormations();
64 FormationInfo* GetFormationInfo(ObjectGuid::LowType spawnId);
65
66 void AddFormationMember(ObjectGuid::LowType spawnId, float followAng, float followDist, ObjectGuid::LowType leaderSpawnId, uint32 groupAI);
67};
68
70{
71 private:
72 Creature* _leader; //Important do not forget sometimes to work with pointers instead synonims :D:D
73 std::unordered_map<Creature*, FormationInfo*> _members;
74
76 bool _formed;
78
79 public:
80 //Group cannot be created empty
81 explicit CreatureGroup(ObjectGuid::LowType leaderSpawnId);
83
84 Creature* GetLeader() const { return _leader; }
85 ObjectGuid::LowType GetLeaderSpawnId() const { return _leaderSpawnId; }
86 bool IsEmpty() const { return _members.empty(); }
87 bool IsFormed() const { return _formed; }
88 bool IsLeader(Creature const* creature) const { return _leader == creature; }
89
90 bool HasMember(Creature* member) const { return _members.count(member) > 0; }
91 void AddMember(Creature* member);
92 void RemoveMember(Creature* member);
93 void FormationReset(bool dismiss);
94
95 void LeaderStartedMoving();
96 void MemberEngagingTarget(Creature* member, Unit* target);
97 bool CanLeaderStartMoving() const;
98};
99
100#define sFormationMgr FormationMgr::instance()
101
102#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:114
uint32_t uint32
Definition Define.h:133
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
uint32 LowType
Definition ObjectGuid.h:142
Definition Unit.h:769
ObjectGuid::LowType LeaderSpawnId
uint32 LeaderWaypointIDs[2]