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

#include <CreatureGroups.h>

Public Member Functions

 CreatureGroup (ObjectGuid::LowType id)
 
 ~CreatureGroup ()
 
CreaturegetLeader () const
 
ObjectGuid::LowType GetId () const
 
bool isEmpty () const
 
bool isFormed () const
 
void AddMember (Creature *member)
 
void RemoveMember (Creature *member)
 
void FormationReset (bool dismiss)
 
void LeaderMoveTo (float x, float y, float z)
 
void MemberAttackStart (Creature *member, Unit *target)
 

Private Types

typedef std::map< Creature
*, FormationInfo * > 
CreatureGroupMemberType
 

Private Attributes

Creaturem_leader
 
CreatureGroupMemberType m_members
 
ObjectGuid::LowType m_groupID
 
bool m_Formed
 

Member Typedef Documentation

Constructor & Destructor Documentation

CreatureGroup::CreatureGroup ( ObjectGuid::LowType  id)
inlineexplicit
68 : m_leader(NULL), m_groupID(id), m_Formed(false) { }
arena_t NULL
Definition: jemalloc_internal.h:624
ObjectGuid::LowType m_groupID
Definition: CreatureGroups.h:63
Creature * m_leader
Definition: CreatureGroups.h:59
bool m_Formed
Definition: CreatureGroups.h:64
CreatureGroup::~CreatureGroup ( )
inline
69 { }

Member Function Documentation

void CreatureGroup::AddMember ( Creature member)
150 {
151  TC_LOG_DEBUG("entities.unit", "CreatureGroup::AddMember: Adding %s.", member->GetGUID().ToString().c_str());
152 
153  //Check if it is a leader
154  if (member->GetSpawnId() == m_groupID)
155  {
156  TC_LOG_DEBUG("entities.unit", "%s is formation leader. Adding group.", member->GetGUID().ToString().c_str());
157  m_leader = member;
158  }
159 
160  m_members[member] = sFormationMgr->CreatureGroupMap.find(member->GetSpawnId())->second;
161  member->SetFormation(this);
162 }
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:487
void SetFormation(CreatureGroup *formation)
Definition: Creature.h:688
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
ObjectGuid::LowType m_groupID
Definition: CreatureGroups.h:63
ObjectGuid const & GetGUID() const
Definition: Object.h:105
Creature * m_leader
Definition: CreatureGroups.h:59
#define sFormationMgr
Definition: CreatureGroups.h:84
std::string ToString() const
Definition: ObjectGuid.cpp:99
CreatureGroupMemberType m_members
Definition: CreatureGroups.h:61

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CreatureGroup::FormationReset ( bool  dismiss)
205 {
206  for (CreatureGroupMemberType::iterator itr = m_members.begin(); itr != m_members.end(); ++itr)
207  {
208  if (itr->first != m_leader && itr->first->IsAlive())
209  {
210  if (dismiss)
211  itr->first->GetMotionMaster()->Initialize();
212  else
213  itr->first->GetMotionMaster()->MoveIdle();
214  TC_LOG_DEBUG("entities.unit", "Set %s movement for member %s", dismiss ? "default" : "idle", itr->first->GetGUID().ToString().c_str());
215  }
216  }
217  m_Formed = !dismiss;
218 }
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
bool IsAlive() const
Definition: Unit.h:1692
Creature * m_leader
Definition: CreatureGroups.h:59
bool m_Formed
Definition: CreatureGroups.h:64
CreatureGroupMemberType m_members
Definition: CreatureGroups.h:61

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ObjectGuid::LowType CreatureGroup::GetId ( ) const
inline
72 { return m_groupID; }
ObjectGuid::LowType m_groupID
Definition: CreatureGroups.h:63

+ Here is the caller graph for this function:

Creature* CreatureGroup::getLeader ( ) const
inline
71 { return m_leader; }
Creature * m_leader
Definition: CreatureGroups.h:59

+ Here is the caller graph for this function:

bool CreatureGroup::isEmpty ( ) const
inline
73 { return m_members.empty(); }
CreatureGroupMemberType m_members
Definition: CreatureGroups.h:61

+ Here is the caller graph for this function:

bool CreatureGroup::isFormed ( ) const
inline
74 { return m_Formed; }
bool m_Formed
Definition: CreatureGroups.h:64

+ Here is the caller graph for this function:

void CreatureGroup::LeaderMoveTo ( float  x,
float  y,
float  z 
)

To do: This should probably get its own movement generator or use WaypointMovementGenerator. If the leader's path is known, member's path can be plotted as well using formation offsets.

221 {
224  if (!m_leader)
225  return;
226 
227  float pathangle = std::atan2(m_leader->GetPositionY() - y, m_leader->GetPositionX() - x);
228 
229  for (CreatureGroupMemberType::iterator itr = m_members.begin(); itr != m_members.end(); ++itr)
230  {
231  Creature* member = itr->first;
232  if (member == m_leader || !member->IsAlive() || member->GetVictim())
233  continue;
234 
235  if (itr->second->point_1)
236  if (m_leader->GetCurrentWaypointID() == itr->second->point_1 - 1 || m_leader->GetCurrentWaypointID() == itr->second->point_2 - 1)
237  itr->second->follow_angle = float(M_PI) * 2 - itr->second->follow_angle;
238 
239  float angle = itr->second->follow_angle;
240  float dist = itr->second->follow_dist;
241 
242  float dx = x + std::cos(angle + pathangle) * dist;
243  float dy = y + std::sin(angle + pathangle) * dist;
244  float dz = z;
245 
248 
249  if (!member->IsFlying())
250  member->UpdateGroundPositionZ(dx, dy, dz);
251 
252  if (member->IsWithinDist(m_leader, dist + MAX_DESYNC))
254  else
255  member->SetWalk(false);
256 
257  member->GetMotionMaster()->MovePoint(0, dx, dy, dz);
258  member->SetHomePosition(dx, dy, dz, pathangle);
259  }
260 }
bool IsFlying() const
Definition: Unit.h:2189
uint32 GetUnitMovementFlags() const
Definition: Unit.h:2110
#define M_PI
Definition: Common.h:163
MotionMaster * GetMotionMaster()
Definition: Unit.h:2101
void SetHomePosition(float x, float y, float z, float o)
Definition: Creature.h:670
Definition: Creature.h:467
#define MAX_DESYNC
Definition: CreatureGroups.cpp:25
uint32 GetCurrentWaypointID() const
Definition: Creature.h:683
bool IsWithinDist(WorldObject const *obj, float dist2compare, bool is3D=true) const
Definition: Object.cpp:1658
void MovePoint(uint32 id, Position const &pos, bool generatePath=true)
Definition: MotionMaster.h:172
bool IsAlive() const
Definition: Unit.h:1692
Unit * GetVictim() const
Definition: Unit.h:1379
float GetPositionY() const
Definition: Position.h:105
G3D::int16 z
Definition: Vector3int16.h:46
void SetUnitMovementFlags(uint32 f)
Definition: Unit.h:2111
G3D::int16 y
Definition: Vector2int16.h:38
void NormalizeMapCoord(float &c)
Definition: GridDefines.h:210
Creature * m_leader
Definition: CreatureGroups.h:59
bool SetWalk(bool enable)
Definition: Unit.cpp:15800
G3D::int16 x
Definition: Vector2int16.h:37
float GetPositionX() const
Definition: Position.h:104
CreatureGroupMemberType m_members
Definition: CreatureGroups.h:61
void UpdateGroundPositionZ(float x, float y, float &z) const
Definition: Object.cpp:1827

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CreatureGroup::MemberAttackStart ( Creature member,
Unit target 
)
174 {
175  uint8 groupAI = sFormationMgr->CreatureGroupMap[member->GetSpawnId()]->groupAI;
176  if (!groupAI)
177  return;
178 
179  if (groupAI == 1 && member != m_leader)
180  return;
181 
182  for (CreatureGroupMemberType::iterator itr = m_members.begin(); itr != m_members.end(); ++itr)
183  {
184  if (m_leader) // avoid crash if leader was killed and reset.
185  TC_LOG_DEBUG("entities.unit", "GROUP ATTACK: group instance id %u calls member instid %u", m_leader->GetInstanceId(), member->GetInstanceId());
186 
187  Creature* other = itr->first;
188 
189  // Skip self
190  if (other == member)
191  continue;
192 
193  if (!other->IsAlive())
194  continue;
195 
196  if (other->GetVictim())
197  continue;
198 
199  if (other->IsValidAttackTarget(target))
200  other->AI()->AttackStart(target);
201  }
202 }
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:487
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: Creature.h:467
CreatureAI * AI() const
Definition: Creature.h:525
uint32 GetInstanceId() const
Definition: Object.h:451
Creature * m_leader
Definition: CreatureGroups.h:59
#define sFormationMgr
Definition: CreatureGroups.h:84
uint8_t uint8
Definition: Define.h:152
virtual void AttackStart(Unit *)
Definition: UnitAI.cpp:29
CreatureGroupMemberType m_members
Definition: CreatureGroups.h:61

+ Here is the call graph for this function:

void CreatureGroup::RemoveMember ( Creature member)
165 {
166  if (m_leader == member)
167  m_leader = NULL;
168 
169  m_members.erase(member);
170  member->SetFormation(NULL);
171 }
arena_t NULL
Definition: jemalloc_internal.h:624
void SetFormation(CreatureGroup *formation)
Definition: Creature.h:688
Creature * m_leader
Definition: CreatureGroups.h:59
CreatureGroupMemberType m_members
Definition: CreatureGroups.h:61

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

bool CreatureGroup::m_Formed
private
ObjectGuid::LowType CreatureGroup::m_groupID
private
Creature* CreatureGroup::m_leader
private
CreatureGroupMemberType CreatureGroup::m_members
private

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