OregonCore  revision fb2a440-git
Your Favourite TBC server
CreatureGroups.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore 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 "Common.h"
22 #include <ace/Basic_Types.h>
23 #include <ace/Singleton.h>
24 #include <ace/Thread_Mutex.h>
25 #include <unordered_map>
26 #include <map>
27 
29 {
30  FLAG_AGGRO_NONE = 0, // No creature group behavior
31  FLAG_MEMBERS_ASSIST_LEADER = 0x00000001, // The member aggroes if the leader aggroes
32  FLAG_LEADER_ASSISTS_MEMBER = 0x00000002, // The leader aggroes if the member aggroes
33  FLAG_MEMBERS_ASSIST_MEMBER = (FLAG_MEMBERS_ASSIST_LEADER | FLAG_LEADER_ASSISTS_MEMBER), // every member will assist if any member is attacked
34  FLAG_IDLE_IN_FORMATION = 0x00000004, // The member will follow the leader when pathing idly
35 };
36 
37 class Creature;
38 class CreatureGroup;
39 
41 {
43  float follow_dist;
44  float follow_angle;
48 };
49 
50 typedef std::unordered_map<uint32/*memberDBGUID*/, FormationInfo*> CreatureGroupInfoType;
51 
53 {
54  friend class ACE_Singleton<FormationMgr, ACE_Null_Mutex>;
55  public:
57  ~FormationMgr();
58  void AddCreatureToGroup(uint32 group_id, Creature* creature);
59  void RemoveCreatureFromGroup(CreatureGroup* group, Creature* creature);
60  void LoadCreatureFormations();
62 };
63 
65 {
66  private:
67  Creature* m_leader; //Important do not forget sometimes to work with pointers instead synonims :D:D
68  typedef std::map<Creature*, FormationInfo*> CreatureGroupMemberType;
69  CreatureGroupMemberType m_members;
70 
72  bool m_Formed;
73 
74  public:
75  //Group cannot be created empty
76  explicit CreatureGroup(uint32 id) : m_leader(NULL), m_groupID(id), m_Formed(false) { }
78 
79  Creature* getLeader() const { return m_leader; }
80  uint32 GetId() const { return m_groupID; }
81  bool isEmpty() const { return m_members.empty(); }
82  bool isFormed() const { return m_Formed; }
83 
84  void AddMember(Creature* member);
85  void RemoveMember(Creature* member);
86  void FormationReset(bool dismiss);
87 
88  void LeaderMoveTo(float x, float y, float z);
89  void MemberAttackStart(Creature* member, Unit* target);
90 };
91 
92 #define sFormationMgr Oregon::Singleton<FormationMgr>::Instance()
93 
94 #endif
95 
CreatureGroupInfoType CreatureGroupMap
CreatureGroup(uint32 id)
GroupAIFlags
NULL Dbg ErrDB Arena Chat Char Map MMap false
Definition: Log.cpp:556
Creature * getLeader() const
uint32 GetId() const
ACE_UINT8 uint8
Definition: Define.h:73
bool isFormed() const
std::map< Creature *, FormationInfo * > CreatureGroupMemberType
Creature * m_leader
ACE_UINT32 uint32
Definition: Define.h:71
Definition: Unit.h:908
bool isEmpty() const
CreatureGroupMemberType m_members
std::unordered_map< uint32, FormationInfo * > CreatureGroupInfoType