AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
FormationMgr Class Reference

#include "CreatureGroups.h"

Public Member Functions

 FormationMgr ()
 
 ~FormationMgr ()
 
void AddCreatureToGroup (uint32 group_id, Creature *creature)
 
void RemoveCreatureFromGroup (CreatureGroup *group, Creature *creature)
 
void LoadCreatureFormations ()
 

Static Public Member Functions

static FormationMgrinstance ()
 

Public Attributes

CreatureGroupInfoType CreatureGroupMap
 

Detailed Description

Constructor & Destructor Documentation

◆ FormationMgr()

FormationMgr::FormationMgr ( )
inline
78{ }

◆ ~FormationMgr()

FormationMgr::~FormationMgr ( )
28{
29}

Member Function Documentation

◆ AddCreatureToGroup()

void FormationMgr::AddCreatureToGroup ( uint32  group_id,
Creature creature 
)
38{
39 Map* map = member->FindMap();
40 if (!map)
41 {
42 return;
43 }
44
45 CreatureGroupHolderType::iterator itr = map->CreatureGroupHolder.find(groupId);
46
47 //Add member to an existing group
48 if (itr != map->CreatureGroupHolder.end())
49 {
50 LOG_DEBUG("entities.unit", "Group found: {}, inserting creature {}, Group InstanceID {}", groupId, member->GetGUID().ToString(), member->GetInstanceId());
51 itr->second->AddMember(member);
52 }
53 //Create new group
54 else
55 {
56 LOG_DEBUG("entities.unit", "Group not found: {}. Creating new group.", groupId);
57 CreatureGroup* group = new CreatureGroup(groupId);
58 map->CreatureGroupHolder[groupId] = group;
59 group->AddMember(member);
60 }
61}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:169
Definition: CreatureGroups.h:90
void AddMember(Creature *member)
Definition: CreatureGroups.cpp:169
Definition: Map.h:311
CreatureGroupHolderType CreatureGroupHolder
Definition: Map.h:499

References CreatureGroup::AddMember(), Map::CreatureGroupHolder, WorldObject::FindMap(), Object::GetGUID(), WorldObject::GetInstanceId(), LOG_DEBUG, and ObjectGuid::ToString().

◆ instance()

FormationMgr * FormationMgr::instance ( )
static
32{
34 return &instance;
35}
Definition: CreatureGroups.h:76
static FormationMgr * instance()
Definition: CreatureGroups.cpp:31

References instance().

Referenced by instance().

◆ LoadCreatureFormations()

void FormationMgr::LoadCreatureFormations ( )
83{
84 uint32 const oldMSTime = getMSTime();
85 CreatureGroupMap.clear();
86
87 //Get group data
88 QueryResult result = WorldDatabase.Query("SELECT leaderGUID, memberGUID, dist, angle, groupAI, point_1, point_2 FROM creature_formations ORDER BY leaderGUID");
89 if (!result)
90 {
91 LOG_WARN("server.loading", ">> Loaded 0 creatures in formations. DB table `creature_formations` is empty!");
92 LOG_INFO("server.loading", " ");
93 return;
94 }
95
96 uint32 count = 0;
97 do
98 {
99 Field const* fields = result->Fetch();
100
101 //Load group member data
102 FormationInfo group_member;
103 group_member.leaderGUID = fields[0].Get<uint32>();
104 ObjectGuid::LowType const memberGUID = fields[1].Get<uint32>();
105 float const follow_dist = fields[2].Get<float>();
106 float const follow_angle = fields[3].Get<float>() * (static_cast<float>(M_PI) / 180);
107 group_member.groupAI = fields[4].Get<uint16>();
108 group_member.point_1 = fields[5].Get<uint16>();
109 group_member.point_2 = fields[6].Get<uint16>();
110
111 //If creature is group leader we may skip loading of dist/angle
112 if (group_member.leaderGUID != memberGUID)
113 {
114 if (!group_member.HasGroupFlag(std::underlying_type_t<GroupAIFlags>(GroupAIFlags::GROUP_AI_FLAG_SUPPORTED)))
115 {
116 LOG_ERROR("sql.sql", "creature_formations table leader guid {} and member guid {} has unsupported GroupAI flag value ({}). Skipped", group_member.leaderGUID, memberGUID, group_member.groupAI);
117 continue;
118 }
119
120 if (!group_member.HasGroupFlag(std::underlying_type_t<GroupAIFlags>(GroupAIFlags::GROUP_AI_FLAG_FOLLOW_LEADER)) && (follow_dist > 0.0f || follow_angle > 0.0f))
121 {
122 LOG_ERROR("sql.sql", "creature_formations table member guid {} and leader guid {} cannot have follow distance or follow angle because don't have GROUP_AI_FLAG_FOLLOW_LEADER flag. Values are not gonna be used", memberGUID, group_member.leaderGUID);
123 group_member.follow_dist = 0.0f;
124 group_member.follow_angle = 0.0f;
125 }
126 else
127 {
128 group_member.follow_dist = follow_dist;
129 group_member.follow_angle = follow_angle;
130 }
131 }
132 else
133 {
134 // Leader can have 0 AI flags - its allowed
135 if (group_member.groupAI && !group_member.HasGroupFlag(std::underlying_type_t<GroupAIFlags>(GroupAIFlags::GROUP_AI_FLAG_SUPPORTED)))
136 {
137 LOG_ERROR("sql.sql", "creature_formations table leader guid {} and member guid {} has unsupported GroupAI flag value ({}). Skipped", group_member.leaderGUID, memberGUID, group_member.groupAI);
138 continue;
139 }
140
141 group_member.follow_dist = 0.0f;
142 group_member.follow_angle = 0.0f;
143 if (follow_dist > 0.0f || follow_angle > 0.0f)
144 {
145 LOG_ERROR("sql.sql", "creature_formations table member guid {} and leader guid {} cannot have follow distance or follow angle. Values are not gonna be used", memberGUID, group_member.leaderGUID);
146 }
147 }
148
149 if (!sObjectMgr->GetCreatureData(group_member.leaderGUID))
150 {
151 LOG_ERROR("sql.sql", "creature_formations table leader guid {} incorrect (does not exist). Skipped", group_member.leaderGUID);
152 continue;
153 }
154
155 if (!sObjectMgr->GetCreatureData(memberGUID))
156 {
157 LOG_ERROR("sql.sql", "creature_formations table member guid {} incorrect (does not exist). Skipped", memberGUID);
158 continue;
159 }
160
161 CreatureGroupMap[memberGUID] = group_member;
162 ++count;
163 } while (result->NextRow());
164
165 LOG_INFO("server.loading", ">> Loaded {} Creatures In Formations in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
166 LOG_INFO("server.loading", " ");
167}
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
#define LOG_WARN(filterType__,...)
Definition: Log.h:161
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
std::uint32_t uint32
Definition: Define.h:107
std::uint16_t uint16
Definition: Define.h:108
#define sObjectMgr
Definition: ObjectMgr.h:1635
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
Class used to access individual fields of database query result.
Definition: Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:112
Definition: CreatureGroups.h:52
float follow_dist
Definition: CreatureGroups.h:64
uint32 point_1
Definition: CreatureGroups.h:67
float follow_angle
Definition: CreatureGroups.h:65
uint32 point_2
Definition: CreatureGroups.h:68
ObjectGuid::LowType leaderGUID
Definition: CreatureGroups.h:63
uint16 groupAI
Definition: CreatureGroups.h:66
bool HasGroupFlag(uint16 flag) const
Definition: CreatureGroups.h:70
CreatureGroupInfoType CreatureGroupMap
Definition: CreatureGroups.h:86
uint32 LowType
Definition: ObjectGuid.h:122

References CreatureGroupMap, FormationInfo::follow_angle, FormationInfo::follow_dist, Field::Get(), getMSTime(), GetMSTimeDiffToNow(), FormationInfo::groupAI, FormationInfo::HasGroupFlag(), FormationInfo::leaderGUID, LOG_ERROR, LOG_INFO, LOG_WARN, FormationInfo::point_1, FormationInfo::point_2, sObjectMgr, and WorldDatabase.

◆ RemoveCreatureFromGroup()

void FormationMgr::RemoveCreatureFromGroup ( CreatureGroup group,
Creature creature 
)
64{
65 LOG_DEBUG("entities.unit", "Deleting member pointer to spawnId: {} from group {}", member->GetSpawnId(), group->GetId());
66 group->RemoveMember(member);
67
68 if (group->IsEmpty())
69 {
70 Map* map = member->FindMap();
71 if (!map)
72 {
73 return;
74 }
75
76 LOG_DEBUG("entities.unit", "Deleting group with InstanceID {}", member->GetInstanceId());
77 map->CreatureGroupHolder.erase(group->GetId());
78 delete group;
79 }
80}
uint32 GetId() const
Definition: CreatureGroups.h:100
void RemoveMember(Creature *member)
Definition: CreatureGroups.cpp:184
bool IsEmpty() const
Definition: CreatureGroups.h:102

References Map::CreatureGroupHolder, WorldObject::FindMap(), CreatureGroup::GetId(), WorldObject::GetInstanceId(), Creature::GetSpawnId(), CreatureGroup::IsEmpty(), LOG_DEBUG, and CreatureGroup::RemoveMember().

Member Data Documentation

◆ CreatureGroupMap

CreatureGroupInfoType FormationMgr::CreatureGroupMap

Referenced by LoadCreatureFormations().