TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
FormationMgr Class Reference

#include <CreatureGroups.h>

Public Member Functions

void AddCreatureToGroup (ObjectGuid::LowType leaderGuid, Creature *creature)
 
void RemoveCreatureFromGroup (CreatureGroup *group, Creature *creature)
 
void LoadCreatureFormations ()
 

Static Public Member Functions

static FormationMgrinstance ()
 

Public Attributes

CreatureGroupInfoType CreatureGroupMap
 

Private Member Functions

 FormationMgr ()
 
 ~FormationMgr ()
 

Constructor & Destructor Documentation

FormationMgr::FormationMgr ( )
inlineprivate
44 { }
FormationMgr::~FormationMgr ( )
private
28 {
29  for (CreatureGroupInfoType::iterator itr = CreatureGroupMap.begin(); itr != CreatureGroupMap.end(); ++itr)
30  delete itr->second;
31 }
CreatureGroupInfoType CreatureGroupMap
Definition: CreatureGroups.h:53

Member Function Documentation

void FormationMgr::AddCreatureToGroup ( ObjectGuid::LowType  leaderGuid,
Creature creature 
)
40 {
41  Map* map = creature->FindMap();
42  if (!map)
43  return;
44 
45  CreatureGroupHolderType::iterator itr = map->CreatureGroupHolder.find(leaderGuid);
46 
47  //Add member to an existing group
48  if (itr != map->CreatureGroupHolder.end())
49  {
50  TC_LOG_DEBUG("entities.unit", "Group found: " UI64FMTD ", inserting %s, Group InstanceID %u", leaderGuid, creature->GetGUID().ToString().c_str(), creature->GetInstanceId());
51  itr->second->AddMember(creature);
52  }
53  //Create new group
54  else
55  {
56  TC_LOG_DEBUG("entities.unit", "Group not found: " UI64FMTD ". Creating new group.", leaderGuid);
57  CreatureGroup* group = new CreatureGroup(leaderGuid);
58  map->CreatureGroupHolder[leaderGuid] = group;
59  group->AddMember(creature);
60  }
61 }
void AddMember(Creature *member)
Definition: CreatureGroups.cpp:149
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: CreatureGroups.h:56
Map * FindMap() const
Definition: Object.h:544
CreatureGroupHolderType CreatureGroupHolder
Definition: Map.h:452
#define UI64FMTD
Definition: Define.h:137
uint32 GetInstanceId() const
Definition: Object.h:451
Definition: Map.h:259
ObjectGuid const & GetGUID() const
Definition: Object.h:105
std::string ToString() const
Definition: ObjectGuid.cpp:99

+ Here is the call graph for this function:

FormationMgr * FormationMgr::instance ( )
static
34 {
35  static FormationMgr instance;
36  return &instance;
37 }
static FormationMgr * instance()
Definition: CreatureGroups.cpp:33
Definition: CreatureGroups.h:41
void FormationMgr::LoadCreatureFormations ( )
81 {
82  uint32 oldMSTime = getMSTime();
83 
84  for (CreatureGroupInfoType::iterator itr = CreatureGroupMap.begin(); itr != CreatureGroupMap.end(); ++itr) // for reload case
85  delete itr->second;
86  CreatureGroupMap.clear();
87 
88  //Get group data
89  QueryResult result = WorldDatabase.Query("SELECT leaderGUID, memberGUID, dist, angle, groupAI, point_1, point_2 FROM creature_formations ORDER BY leaderGUID");
90 
91  if (!result)
92  {
93  TC_LOG_ERROR("server.loading", ">> Loaded 0 creatures in formations. DB table `creature_formations` is empty!");
94  return;
95  }
96 
97  uint32 count = 0;
98  Field* fields;
99  FormationInfo* group_member;
100 
101  do
102  {
103  fields = result->Fetch();
104 
105  //Load group member data
106  group_member = new FormationInfo();
107  group_member->leaderGUID = fields[0].GetUInt64();
108  ObjectGuid::LowType memberGUID = fields[1].GetUInt64();
109  group_member->groupAI = fields[4].GetUInt32();
110  group_member->point_1 = fields[5].GetUInt16();
111  group_member->point_2 = fields[6].GetUInt16();
112  //If creature is group leader we may skip loading of dist/angle
113  if (group_member->leaderGUID != memberGUID)
114  {
115  group_member->follow_dist = fields[2].GetFloat();
116  group_member->follow_angle = fields[3].GetFloat() * float(M_PI) / 180;
117  }
118  else
119  {
120  group_member->follow_dist = 0;
121  group_member->follow_angle = 0;
122  }
123 
124  // check data correctness
125  {
126  if (!sObjectMgr->GetCreatureData(group_member->leaderGUID))
127  {
128  TC_LOG_ERROR("sql.sql", "creature_formations table leader guid " UI64FMTD " incorrect (not exist)", group_member->leaderGUID);
129  delete group_member;
130  continue;
131  }
132 
133  if (!sObjectMgr->GetCreatureData(memberGUID))
134  {
135  TC_LOG_ERROR("sql.sql", "creature_formations table member guid " UI64FMTD " incorrect (not exist)", memberGUID);
136  delete group_member;
137  continue;
138  }
139  }
140 
141  CreatureGroupMap[memberGUID] = group_member;
142  ++count;
143  }
144  while (result->NextRow());
145 
146  TC_LOG_INFO("server.loading", ">> Loaded %u creatures in formations in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
147 }
CreatureGroupInfoType CreatureGroupMap
Definition: CreatureGroups.h:53
uint64 GetUInt64() const
Definition: Field.h:184
float GetFloat() const
Definition: Field.h:222
ObjectGuid::LowType leaderGUID
Definition: CreatureGroups.h:31
#define M_PI
Definition: Common.h:163
Class used to access individual fields of database query result.
Definition: Field.h:56
uint32 point_2
Definition: CreatureGroups.h:36
uint32 getMSTime()
Definition: Timer.h:24
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
Definition: CreatureGroups.h:29
uint64 LowType
Definition: ObjectGuid.h:199
#define sObjectMgr
Definition: ObjectMgr.h:1567
float follow_dist
Definition: CreatureGroups.h:32
#define UI64FMTD
Definition: Define.h:137
uint32_t uint32
Definition: Define.h:150
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
uint16 GetUInt16() const
Definition: Field.h:108
uint32 point_1
Definition: CreatureGroups.h:35
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
uint32 GetUInt32() const
Definition: Field.h:146
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
float follow_angle
Definition: CreatureGroups.h:33
uint8 groupAI
Definition: CreatureGroups.h:34

+ Here is the call graph for this function:

void FormationMgr::RemoveCreatureFromGroup ( CreatureGroup group,
Creature creature 
)
64 {
65  TC_LOG_DEBUG("entities.unit", "Deleting member pointer to GUID: " UI64FMTD " from group " UI64FMTD, group->GetId(), member->GetSpawnId());
66  group->RemoveMember(member);
67 
68  if (group->isEmpty())
69  {
70  Map* map = member->FindMap();
71  if (!map)
72  return;
73 
74  TC_LOG_DEBUG("entities.unit", "Deleting group with InstanceID %u", member->GetInstanceId());
75  map->CreatureGroupHolder.erase(group->GetId());
76  delete group;
77  }
78 }
void RemoveMember(Creature *member)
Definition: CreatureGroups.cpp:164
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
CreatureGroupHolderType CreatureGroupHolder
Definition: Map.h:452
#define UI64FMTD
Definition: Define.h:137
Definition: Map.h:259
ObjectGuid::LowType GetId() const
Definition: CreatureGroups.h:72
bool isEmpty() const
Definition: CreatureGroups.h:73

+ Here is the call graph for this function:

Member Data Documentation

CreatureGroupInfoType FormationMgr::CreatureGroupMap

The documentation for this class was generated from the following files: