[10481] Use prefix m_ for member variable in motionMaster

Some additional code style cleanup.

Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
NoFantasy 2010-09-14 10:52:34 +02:00
parent d7994c1df4
commit 3027d4ba61
3 changed files with 89 additions and 100 deletions

View file

@ -37,22 +37,21 @@ inline bool isStatic(MovementGenerator *mv)
return (mv == &si_idleMovement); return (mv == &si_idleMovement);
} }
void void MotionMaster::Initialize()
MotionMaster::Initialize()
{ {
// stop current move // stop current move
if (!i_owner->IsStopped()) if (!m_owner->IsStopped())
i_owner->StopMoving(); m_owner->StopMoving();
// clear ALL movement generators (including default) // clear ALL movement generators (including default)
Clear(false,true); Clear(false,true);
// set new default movement generator // set new default movement generator
if (i_owner->GetTypeId() == TYPEID_UNIT && !i_owner->hasUnitState(UNIT_STAT_CONTROLLED)) if (m_owner->GetTypeId() == TYPEID_UNIT && !m_owner->hasUnitState(UNIT_STAT_CONTROLLED))
{ {
MovementGenerator* movement = FactorySelector::selectMovementGenerator((Creature*)i_owner); MovementGenerator* movement = FactorySelector::selectMovementGenerator((Creature*)m_owner);
push(movement == NULL ? &si_idleMovement : movement); push(movement == NULL ? &si_idleMovement : movement);
top()->Initialize(*i_owner); top()->Initialize(*m_owner);
} }
else else
push(&si_idleMovement); push(&si_idleMovement);
@ -64,14 +63,15 @@ MotionMaster::~MotionMaster()
DirectClean(false,true); DirectClean(false,true);
} }
void void MotionMaster::UpdateMotion(uint32 diff)
MotionMaster::UpdateMotion(uint32 diff)
{ {
if( i_owner->hasUnitState(UNIT_STAT_CAN_NOT_MOVE) ) if (m_owner->hasUnitState(UNIT_STAT_CAN_NOT_MOVE))
return; return;
MANGOS_ASSERT( !empty() ); MANGOS_ASSERT( !empty() );
m_cleanFlag |= MMCF_UPDATE; m_cleanFlag |= MMCF_UPDATE;
if (!top()->Update(*i_owner, diff))
if (!top()->Update(*m_owner, diff))
{ {
m_cleanFlag &= ~MMCF_UPDATE; m_cleanFlag &= ~MMCF_UPDATE;
MovementExpired(); MovementExpired();
@ -96,35 +96,34 @@ MotionMaster::UpdateMotion(uint32 diff)
if (m_cleanFlag & MMCF_RESET) if (m_cleanFlag & MMCF_RESET)
{ {
top()->Reset(*i_owner); top()->Reset(*m_owner);
m_cleanFlag &= ~MMCF_RESET; m_cleanFlag &= ~MMCF_RESET;
} }
} }
} }
void void MotionMaster::DirectClean(bool reset, bool all)
MotionMaster::DirectClean(bool reset, bool all)
{ {
while( all ? !empty() : size() > 1 ) while( all ? !empty() : size() > 1 )
{ {
MovementGenerator *curr = top(); MovementGenerator *curr = top();
pop(); pop();
curr->Finalize(*i_owner); curr->Finalize(*m_owner);
if (!isStatic( curr ))
if (!isStatic(curr))
delete curr; delete curr;
} }
if (!all && reset) if (!all && reset)
{ {
MANGOS_ASSERT( !empty() ); MANGOS_ASSERT( !empty() );
top()->Reset(*i_owner); top()->Reset(*m_owner);
} }
} }
void void MotionMaster::DelayedClean(bool reset, bool all)
MotionMaster::DelayedClean(bool reset, bool all)
{ {
if(reset) if (reset)
m_cleanFlag |= MMCF_RESET; m_cleanFlag |= MMCF_RESET;
else else
m_cleanFlag &= ~MMCF_RESET; m_cleanFlag &= ~MMCF_RESET;
@ -139,14 +138,14 @@ MotionMaster::DelayedClean(bool reset, bool all)
{ {
MovementGenerator *curr = top(); MovementGenerator *curr = top();
pop(); pop();
curr->Finalize(*i_owner); curr->Finalize(*m_owner);
if (!isStatic( curr ))
if (!isStatic(curr))
m_expList->push_back(curr); m_expList->push_back(curr);
} }
} }
void void MotionMaster::DirectExpire(bool reset)
MotionMaster::DirectExpire(bool reset)
{ {
if (empty() || size() == 1) if (empty() || size() == 1)
return; return;
@ -159,12 +158,12 @@ MotionMaster::DirectExpire(bool reset)
{ {
MovementGenerator *temp = top(); MovementGenerator *temp = top();
pop(); pop();
temp ->Finalize(*i_owner); temp->Finalize(*m_owner);
delete temp; delete temp;
} }
// it can add another motions instead // it can add another motions instead
curr->Finalize(*i_owner); curr->Finalize(*m_owner);
if (!isStatic(curr)) if (!isStatic(curr))
delete curr; delete curr;
@ -173,11 +172,10 @@ MotionMaster::DirectExpire(bool reset)
Initialize(); Initialize();
if (reset) if (reset)
top()->Reset(*i_owner); top()->Reset(*m_owner);
} }
void void MotionMaster::DelayedExpire(bool reset)
MotionMaster::DelayedExpire(bool reset)
{ {
if (reset) if (reset)
m_cleanFlag |= MMCF_RESET; m_cleanFlag |= MMCF_RESET;
@ -198,11 +196,11 @@ MotionMaster::DelayedExpire(bool reset)
{ {
MovementGenerator *temp = top(); MovementGenerator *temp = top();
pop(); pop();
temp ->Finalize(*i_owner); temp ->Finalize(*m_owner);
m_expList->push_back(temp ); m_expList->push_back(temp );
} }
curr->Finalize(*i_owner); curr->Finalize(*m_owner);
if (!isStatic(curr)) if (!isStatic(curr))
m_expList->push_back(curr); m_expList->push_back(curr);
@ -216,142 +214,134 @@ void MotionMaster::MoveIdle()
void MotionMaster::MoveRandom() void MotionMaster::MoveRandom()
{ {
if (i_owner->GetTypeId() == TYPEID_PLAYER) if (m_owner->GetTypeId() == TYPEID_PLAYER)
{ {
sLog.outError("%s attempt to move random.", i_owner->GetObjectGuid().GetString().c_str()); sLog.outError("%s attempt to move random.", m_owner->GetObjectGuid().GetString().c_str());
} }
else else
{ {
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s move random.", i_owner->GetObjectGuid().GetString().c_str()); DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s move random.", m_owner->GetObjectGuid().GetString().c_str());
Mutate(new RandomMovementGenerator<Creature>(*i_owner)); Mutate(new RandomMovementGenerator<Creature>(*m_owner));
} }
} }
void void MotionMaster::MoveTargetedHome()
MotionMaster::MoveTargetedHome()
{ {
if(i_owner->hasUnitState(UNIT_STAT_LOST_CONTROL)) if (m_owner->hasUnitState(UNIT_STAT_LOST_CONTROL))
return; return;
Clear(false); Clear(false);
if(i_owner->GetTypeId()==TYPEID_UNIT && !((Creature*)i_owner)->GetCharmerOrOwnerGUID()) if (m_owner->GetTypeId() == TYPEID_UNIT && !((Creature*)m_owner)->GetCharmerOrOwnerGUID())
{ {
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s targeted home", i_owner->GetObjectGuid().GetString().c_str()); DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s targeted home", m_owner->GetObjectGuid().GetString().c_str());
Mutate(new HomeMovementGenerator<Creature>()); Mutate(new HomeMovementGenerator<Creature>());
} }
else if(i_owner->GetTypeId()==TYPEID_UNIT && ((Creature*)i_owner)->GetCharmerOrOwnerGUID()) else if (m_owner->GetTypeId() == TYPEID_UNIT && ((Creature*)m_owner)->GetCharmerOrOwnerGUID())
{ {
if (Unit *target = ((Creature*)i_owner)->GetCharmerOrOwner()) if (Unit *target = ((Creature*)m_owner)->GetCharmerOrOwner())
{ {
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s follow to %s", i_owner->GetObjectGuid().GetString().c_str(), target->GetObjectGuid().GetString().c_str()); DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s follow to %s", m_owner->GetObjectGuid().GetString().c_str(), target->GetObjectGuid().GetString().c_str());
Mutate(new FollowMovementGenerator<Creature>(*target,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE)); Mutate(new FollowMovementGenerator<Creature>(*target,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE));
} }
else else
{ {
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s attempt but fail to follow owner", i_owner->GetObjectGuid().GetString().c_str()); DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s attempt but fail to follow owner", m_owner->GetObjectGuid().GetString().c_str());
} }
} }
else else
sLog.outError("%s attempt targeted home", i_owner->GetObjectGuid().GetString().c_str()); sLog.outError("%s attempt targeted home", m_owner->GetObjectGuid().GetString().c_str());
} }
void void MotionMaster::MoveConfused()
MotionMaster::MoveConfused()
{ {
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s move confused", i_owner->GetObjectGuid().GetString().c_str()); DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s move confused", m_owner->GetObjectGuid().GetString().c_str());
if(i_owner->GetTypeId()==TYPEID_PLAYER) if (m_owner->GetTypeId() == TYPEID_PLAYER)
Mutate(new ConfusedMovementGenerator<Player>()); Mutate(new ConfusedMovementGenerator<Player>());
else else
Mutate(new ConfusedMovementGenerator<Creature>()); Mutate(new ConfusedMovementGenerator<Creature>());
} }
void void MotionMaster::MoveChase(Unit* target, float dist, float angle)
MotionMaster::MoveChase(Unit* target, float dist, float angle)
{ {
// ignore movement request if target not exist // ignore movement request if target not exist
if(!target) if (!target)
return; return;
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s chase to %s", i_owner->GetObjectGuid().GetString().c_str(), target->GetObjectGuid().GetString().c_str()); DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s chase to %s", m_owner->GetObjectGuid().GetString().c_str(), target->GetObjectGuid().GetString().c_str());
if(i_owner->GetTypeId()==TYPEID_PLAYER) if (m_owner->GetTypeId() == TYPEID_PLAYER)
Mutate(new ChaseMovementGenerator<Player>(*target,dist,angle)); Mutate(new ChaseMovementGenerator<Player>(*target,dist,angle));
else else
Mutate(new ChaseMovementGenerator<Creature>(*target,dist,angle)); Mutate(new ChaseMovementGenerator<Creature>(*target,dist,angle));
} }
void void MotionMaster::MoveFollow(Unit* target, float dist, float angle)
MotionMaster::MoveFollow(Unit* target, float dist, float angle)
{ {
if(i_owner->hasUnitState(UNIT_STAT_LOST_CONTROL)) if (m_owner->hasUnitState(UNIT_STAT_LOST_CONTROL))
return; return;
Clear(); Clear();
// ignore movement request if target not exist // ignore movement request if target not exist
if(!target) if (!target)
return; return;
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s follow to %s", i_owner->GetObjectGuid().GetString().c_str(), target->GetObjectGuid().GetString().c_str()); DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s follow to %s", m_owner->GetObjectGuid().GetString().c_str(), target->GetObjectGuid().GetString().c_str());
if(i_owner->GetTypeId()==TYPEID_PLAYER) if (m_owner->GetTypeId() == TYPEID_PLAYER)
Mutate(new FollowMovementGenerator<Player>(*target,dist,angle)); Mutate(new FollowMovementGenerator<Player>(*target,dist,angle));
else else
Mutate(new FollowMovementGenerator<Creature>(*target,dist,angle)); Mutate(new FollowMovementGenerator<Creature>(*target,dist,angle));
} }
void void MotionMaster::MovePoint(uint32 id, float x, float y, float z)
MotionMaster::MovePoint(uint32 id, float x, float y, float z)
{ {
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s targeted point (Id: %u X: %f Y: %f Z: %f)", i_owner->GetObjectGuid().GetString().c_str(), id, x, y, z ); DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s targeted point (Id: %u X: %f Y: %f Z: %f)", m_owner->GetObjectGuid().GetString().c_str(), id, x, y, z );
if(i_owner->GetTypeId()==TYPEID_PLAYER) if (m_owner->GetTypeId() == TYPEID_PLAYER)
Mutate(new PointMovementGenerator<Player>(id,x,y,z)); Mutate(new PointMovementGenerator<Player>(id,x,y,z));
else else
Mutate(new PointMovementGenerator<Creature>(id,x,y,z)); Mutate(new PointMovementGenerator<Creature>(id,x,y,z));
} }
void void MotionMaster::MoveSeekAssistance(float x, float y, float z)
MotionMaster::MoveSeekAssistance(float x, float y, float z)
{ {
if(i_owner->GetTypeId()==TYPEID_PLAYER) if (m_owner->GetTypeId() == TYPEID_PLAYER)
{ {
sLog.outError("%s attempt to seek assistance",i_owner->GetObjectGuid().GetString().c_str()); sLog.outError("%s attempt to seek assistance", m_owner->GetObjectGuid().GetString().c_str());
} }
else else
{ {
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s seek assistance (X: %f Y: %f Z: %f)", DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s seek assistance (X: %f Y: %f Z: %f)",
i_owner->GetObjectGuid().GetString().c_str(), x, y, z ); m_owner->GetObjectGuid().GetString().c_str(), x, y, z );
Mutate(new AssistanceMovementGenerator(x,y,z)); Mutate(new AssistanceMovementGenerator(x,y,z));
} }
} }
void void MotionMaster::MoveSeekAssistanceDistract(uint32 time)
MotionMaster::MoveSeekAssistanceDistract(uint32 time)
{ {
if(i_owner->GetTypeId()==TYPEID_PLAYER) if (m_owner->GetTypeId() == TYPEID_PLAYER)
{ {
sLog.outError("%s attempt to call distract after assistance",i_owner->GetObjectGuid().GetString().c_str()); sLog.outError("%s attempt to call distract after assistance", m_owner->GetObjectGuid().GetString().c_str());
} }
else else
{ {
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s is distracted after assistance call (Time: %u)", DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s is distracted after assistance call (Time: %u)",
i_owner->GetObjectGuid().GetString().c_str(), time ); m_owner->GetObjectGuid().GetString().c_str(), time );
Mutate(new AssistanceDistractMovementGenerator(time)); Mutate(new AssistanceDistractMovementGenerator(time));
} }
} }
void void MotionMaster::MoveFleeing(Unit* enemy, uint32 time)
MotionMaster::MoveFleeing(Unit* enemy, uint32 time)
{ {
if(!enemy) if (!enemy)
return; return;
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s flee from %s", i_owner->GetObjectGuid().GetString().c_str(), enemy->GetObjectGuid().GetString().c_str()); DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s flee from %s", m_owner->GetObjectGuid().GetString().c_str(), enemy->GetObjectGuid().GetString().c_str());
if(i_owner->GetTypeId()==TYPEID_PLAYER) if (m_owner->GetTypeId() == TYPEID_PLAYER)
Mutate(new FleeingMovementGenerator<Player>(enemy->GetGUID())); Mutate(new FleeingMovementGenerator<Player>(enemy->GetGUID()));
else else
{ {
@ -362,34 +352,32 @@ MotionMaster::MoveFleeing(Unit* enemy, uint32 time)
} }
} }
void void MotionMaster::MoveTaxiFlight(uint32 path, uint32 pathnode)
MotionMaster::MoveTaxiFlight(uint32 path, uint32 pathnode)
{ {
if(i_owner->GetTypeId()==TYPEID_PLAYER) if (m_owner->GetTypeId() == TYPEID_PLAYER)
{ {
if(path < sTaxiPathNodesByPath.size()) if (path < sTaxiPathNodesByPath.size())
{ {
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s taxi to (Path %u node %u)", i_owner->GetObjectGuid().GetString().c_str(), path, pathnode); DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s taxi to (Path %u node %u)", m_owner->GetObjectGuid().GetString().c_str(), path, pathnode);
FlightPathMovementGenerator* mgen = new FlightPathMovementGenerator(sTaxiPathNodesByPath[path],pathnode); FlightPathMovementGenerator* mgen = new FlightPathMovementGenerator(sTaxiPathNodesByPath[path],pathnode);
Mutate(mgen); Mutate(mgen);
} }
else else
{ {
sLog.outError("%s attempt taxi to (nonexistent Path %u node %u)", sLog.outError("%s attempt taxi to (nonexistent Path %u node %u)",
i_owner->GetObjectGuid().GetString().c_str(), path, pathnode ); m_owner->GetObjectGuid().GetString().c_str(), path, pathnode);
} }
} }
else else
{ {
sLog.outError("%s attempt taxi to (Path %u node %u)", sLog.outError("%s attempt taxi to (Path %u node %u)",
i_owner->GetObjectGuid().GetString().c_str(), path, pathnode ); m_owner->GetObjectGuid().GetString().c_str(), path, pathnode);
} }
} }
void void MotionMaster::MoveDistract(uint32 timer)
MotionMaster::MoveDistract(uint32 timer)
{ {
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s distracted (timer: %u)", i_owner->GetObjectGuid().GetString().c_str(), timer); DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "%s distracted (timer: %u)", m_owner->GetObjectGuid().GetString().c_str(), timer);
DistractMovementGenerator* mgen = new DistractMovementGenerator(timer); DistractMovementGenerator* mgen = new DistractMovementGenerator(timer);
Mutate(mgen); Mutate(mgen);
} }
@ -410,9 +398,10 @@ void MotionMaster::Mutate(MovementGenerator *m)
} }
if (!empty()) if (!empty())
top()->Interrupt(*i_owner); top()->Interrupt(*m_owner);
} }
m->Initialize(*i_owner);
m->Initialize(*m_owner);
push(m); push(m);
} }
@ -427,18 +416,18 @@ void MotionMaster::propagateSpeedChange()
MovementGeneratorType MotionMaster::GetCurrentMovementGeneratorType() const MovementGeneratorType MotionMaster::GetCurrentMovementGeneratorType() const
{ {
if(empty()) if (empty())
return IDLE_MOTION_TYPE; return IDLE_MOTION_TYPE;
return top()->GetMovementGeneratorType(); return top()->GetMovementGeneratorType();
} }
bool MotionMaster::GetDestination(float &x, float &y, float &z) bool MotionMaster::GetDestination(float &x, float &y, float &z)
{ {
if(empty()) if (empty())
return false; return false;
return top()->GetDestination(x,y,z); return top()->GetDestination(x,y,z);
} }
void MotionMaster::UpdateFinalDistanceToTarget(float fDistance) void MotionMaster::UpdateFinalDistanceToTarget(float fDistance)

View file

@ -53,8 +53,8 @@ enum MovementGeneratorType
enum MMCleanFlag enum MMCleanFlag
{ {
MMCF_NONE = 0, MMCF_NONE = 0,
MMCF_UPDATE = 1, // Clear or Expire called from update MMCF_UPDATE = 1, // Clear or Expire called from update
MMCF_RESET = 2 // Flag if need top()->Reset() MMCF_RESET = 2 // Flag if need top()->Reset()
}; };
class MANGOS_DLL_SPEC MotionMaster : private std::stack<MovementGenerator *> class MANGOS_DLL_SPEC MotionMaster : private std::stack<MovementGenerator *>
@ -64,7 +64,7 @@ class MANGOS_DLL_SPEC MotionMaster : private std::stack<MovementGenerator *>
typedef std::vector<MovementGenerator *> ExpireList; typedef std::vector<MovementGenerator *> ExpireList;
public: public:
explicit MotionMaster(Unit *unit) : i_owner(unit), m_expList(NULL), m_cleanFlag(MMCF_NONE) {} explicit MotionMaster(Unit *unit) : m_owner(unit), m_expList(NULL), m_cleanFlag(MMCF_NONE) {}
~MotionMaster(); ~MotionMaster();
void Initialize(); void Initialize();
@ -124,7 +124,7 @@ class MANGOS_DLL_SPEC MotionMaster : private std::stack<MovementGenerator *>
void DirectExpire(bool reset); void DirectExpire(bool reset);
void DelayedExpire(bool reset); void DelayedExpire(bool reset);
Unit *i_owner; Unit *m_owner;
ExpireList *m_expList; ExpireList *m_expList;
uint8 m_cleanFlag; uint8 m_cleanFlag;
}; };

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "10480" #define REVISION_NR "10481"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__