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
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
47
49{
50 private:
53
54 std::unordered_map<ObjectGuid::LowType /*spawnID*/, FormationInfo> _creatureGroupMap;
55
56 public:
57 FormationMgr(FormationMgr const&) = delete;
61
62 static FormationMgr* instance();
63
64 static void AddCreatureToGroup(ObjectGuid::LowType leaderSpawnId, Creature* creature);
65 static void RemoveCreatureFromGroup(CreatureGroup* group, Creature* member);
66
67 void LoadCreatureFormations();
68 FormationInfo* GetFormationInfo(ObjectGuid::LowType spawnId);
69
70 void AddFormationMember(ObjectGuid::LowType spawnId, float followAng, float followDist, ObjectGuid::LowType leaderSpawnId, uint32 groupAI);
71};
72
74{
75 private:
77
78 using MembersMap = std::unordered_map<Creature*, FormationInfo*>;
80
82 bool _formed;
84
85 public:
86 //Group cannot be created empty
87 explicit CreatureGroup(ObjectGuid::LowType leaderSpawnId);
88 CreatureGroup(CreatureGroup const&) = delete;
93
94 Creature* GetLeader() const { return _leader; }
95 ObjectGuid::LowType GetLeaderSpawnId() const { return _leaderSpawnId; }
96 bool IsEmpty() const { return _members.empty(); }
97 bool IsFormed() const { return _formed; }
98 bool IsLeader(Creature const* creature) const { return _leader == creature; }
99
100 bool HasMember(Creature* member) const { return _members.contains(member); }
101 void AddMember(Creature* member);
102 void RemoveMember(Creature* member);
103 void FormationReset(bool dismiss);
104
105 void LeaderStartedMoving();
106 void MemberEngagingTarget(Creature* member, Unit* target);
107 bool CanLeaderStartMoving() const;
108
109 bool HasAliveMembers() const;
110
111 bool LeaderHasStringId(std::string_view id) const;
112};
113
114#define sFormationMgr FormationMgr::instance()
115
116#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:129
uint32_t uint32
Definition Define.h:154
Creature * GetLeader() const
ObjectGuid::LowType GetLeaderSpawnId() const
CreatureGroup & operator=(CreatureGroup &&)=delete
bool IsFormed() const
MembersMap _members
CreatureGroup(CreatureGroup const &)=delete
std::unordered_map< Creature *, FormationInfo * > MembersMap
bool IsLeader(Creature const *creature) const
CreatureGroup(CreatureGroup &&)=delete
bool IsEmpty() const
ObjectGuid::LowType _leaderSpawnId
CreatureGroup & operator=(CreatureGroup const &)=delete
bool HasMember(Creature *member) const
Creature * _leader
FormationMgr & operator=(FormationMgr const &)=delete
FormationMgr(FormationMgr const &)=delete
FormationMgr(FormationMgr &&)=delete
FormationMgr & operator=(FormationMgr &&)=delete
std::unordered_map< ObjectGuid::LowType, FormationInfo > _creatureGroupMap
uint64 LowType
Definition ObjectGuid.h:321
Definition Unit.h:635
ObjectGuid::LowType LeaderSpawnId
uint32 LeaderWaypointIDs[2]