*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget --HG-- branch : trunk
This commit is contained in:
1 parent
f21f47005d
commit
26b5e033ff
2257 files changed
+750
-103852
No files matched your search
@@ -17,12 +17,10 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "MotionMaster.h"
|
||||
#include "CreatureAISelector.h"
|
||||
#include "Creature.h"
|
||||
#include "Traveller.h"
|
||||
|
||||
#include "ConfusedMovementGenerator.h"
|
||||
#include "FleeingMovementGenerator.h"
|
||||
#include "HomeMovementGenerator.h"
|
||||
@@ -31,14 +29,11 @@
|
||||
#include "TargetedMovementGenerator.h"
|
||||
#include "WaypointMovementGenerator.h"
|
||||
#include "RandomMovementGenerator.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
inline bool isStatic(MovementGenerator *mv)
|
||||
{
|
||||
return (mv == &si_idleMovement);
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::Initialize()
|
||||
{
|
||||
@@ -49,10 +44,8 @@ MotionMaster::Initialize()
|
||||
pop();
|
||||
if(curr) DirectDelete(curr);
|
||||
}
|
||||
|
||||
InitDefault();
|
||||
}
|
||||
|
||||
// set new default movement generator
|
||||
void MotionMaster::InitDefault()
|
||||
{
|
||||
@@ -66,7 +59,6 @@ void MotionMaster::InitDefault()
|
||||
Mutate(&si_idleMovement, MOTION_SLOT_IDLE);
|
||||
}
|
||||
}
|
||||
|
||||
MotionMaster::~MotionMaster()
|
||||
{
|
||||
// clear ALL movement generators (including default)
|
||||
@@ -77,7 +69,6 @@ MotionMaster::~MotionMaster()
|
||||
if(curr) DirectDelete(curr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::UpdateMotion(uint32 diff)
|
||||
{
|
||||
@@ -92,7 +83,6 @@ MotionMaster::UpdateMotion(uint32 diff)
|
||||
}
|
||||
else
|
||||
m_cleanFlag &= ~MMCF_UPDATE;
|
||||
|
||||
if (m_expList)
|
||||
{
|
||||
for (size_t i = 0; i < m_expList->size(); ++i)
|
||||
@@ -100,21 +90,17 @@ MotionMaster::UpdateMotion(uint32 diff)
|
||||
MovementGenerator* mg = (*m_expList)[i];
|
||||
DirectDelete(mg);
|
||||
}
|
||||
|
||||
delete m_expList;
|
||||
m_expList = NULL;
|
||||
|
||||
if(empty())
|
||||
Initialize();
|
||||
else if(needInitTop())
|
||||
InitTop();
|
||||
else if (m_cleanFlag & MMCF_RESET)
|
||||
top()->Reset(*i_owner);
|
||||
|
||||
m_cleanFlag &= ~MMCF_RESET;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::DirectClean(bool reset)
|
||||
{
|
||||
@@ -124,13 +110,11 @@ MotionMaster::DirectClean(bool reset)
|
||||
pop();
|
||||
if(curr) DirectDelete(curr);
|
||||
}
|
||||
|
||||
if(needInitTop())
|
||||
InitTop();
|
||||
else if(reset)
|
||||
top()->Reset(*i_owner);
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::DelayedClean()
|
||||
{
|
||||
@@ -141,7 +125,6 @@ MotionMaster::DelayedClean()
|
||||
if(curr) DelayedDelete(curr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::DirectExpire(bool reset)
|
||||
{
|
||||
@@ -151,10 +134,8 @@ MotionMaster::DirectExpire(bool reset)
|
||||
pop();
|
||||
DirectDelete(curr);
|
||||
}
|
||||
|
||||
while(!top())
|
||||
--i_top;
|
||||
|
||||
if(empty())
|
||||
Initialize();
|
||||
else if(needInitTop())
|
||||
@@ -162,7 +143,6 @@ MotionMaster::DirectExpire(bool reset)
|
||||
else if(reset)
|
||||
top()->Reset(*i_owner);
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::DelayedExpire()
|
||||
{
|
||||
@@ -172,11 +152,9 @@ MotionMaster::DelayedExpire()
|
||||
pop();
|
||||
DelayedDelete(curr);
|
||||
}
|
||||
|
||||
while(!top())
|
||||
--i_top;
|
||||
}
|
||||
|
||||
void MotionMaster::MoveIdle(MovementSlot slot)
|
||||
{
|
||||
//if( empty() || !isStatic( top() ) )
|
||||
@@ -184,7 +162,6 @@ void MotionMaster::MoveIdle(MovementSlot slot)
|
||||
if(!isStatic(Impl[slot]))
|
||||
Mutate(&si_idleMovement, slot);
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::MoveRandom(float spawndist)
|
||||
{
|
||||
@@ -194,15 +171,12 @@ MotionMaster::MoveRandom(float spawndist)
|
||||
Mutate(new RandomMovementGenerator<Creature>(spawndist), MOTION_SLOT_IDLE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::MoveTargetedHome()
|
||||
{
|
||||
//if(i_owner->hasUnitState(UNIT_STAT_FLEEING))
|
||||
// return;
|
||||
|
||||
Clear(false);
|
||||
|
||||
if(i_owner->GetTypeId() == TYPEID_UNIT)
|
||||
{
|
||||
DEBUG_LOG("Creature (Entry: %u GUID: %u) targeted home", i_owner->GetEntry(), i_owner->GetGUIDLow());
|
||||
@@ -213,7 +187,6 @@ MotionMaster::MoveTargetedHome()
|
||||
sLog.outError("Player (GUID: %u) attempt targeted home", i_owner->GetGUIDLow() );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::MoveConfused()
|
||||
{
|
||||
@@ -229,14 +202,12 @@ MotionMaster::MoveConfused()
|
||||
Mutate(new ConfusedMovementGenerator<Creature>(), MOTION_SLOT_CONTROLLED);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::MoveChase(Unit* target, float dist, float angle)
|
||||
{
|
||||
// ignore movement request if target not exist
|
||||
if(!target || target == i_owner)
|
||||
return;
|
||||
|
||||
i_owner->clearUnitState(UNIT_STAT_FOLLOW);
|
||||
if(i_owner->GetTypeId()==TYPEID_PLAYER)
|
||||
{
|
||||
@@ -255,14 +226,12 @@ MotionMaster::MoveChase(Unit* target, float dist, float angle)
|
||||
Mutate(new TargetedMovementGenerator<Creature>(*target,dist,angle), MOTION_SLOT_ACTIVE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::MoveFollow(Unit* target, float dist, float angle, MovementSlot slot)
|
||||
{
|
||||
// ignore movement request if target not exist
|
||||
if(!target || target == i_owner)
|
||||
return;
|
||||
|
||||
i_owner->addUnitState(UNIT_STAT_FOLLOW);
|
||||
if(i_owner->GetTypeId()==TYPEID_PLAYER)
|
||||
{
|
||||
@@ -280,7 +249,6 @@ MotionMaster::MoveFollow(Unit* target, float dist, float angle, MovementSlot slo
|
||||
Mutate(new TargetedMovementGenerator<Creature>(*target,dist,angle), slot);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::MovePoint(uint32 id, float x, float y, float z)
|
||||
{
|
||||
@@ -296,36 +264,30 @@ MotionMaster::MovePoint(uint32 id, float x, float y, float z)
|
||||
Mutate(new PointMovementGenerator<Creature>(id,x,y,z), MOTION_SLOT_ACTIVE);
|
||||
}
|
||||
}
|
||||
|
||||
void MotionMaster::MoveKnockbackFrom(float srcX, float srcY, float speedXY, float speedZ)
|
||||
{
|
||||
//this function may make players fall below map
|
||||
if(i_owner->GetTypeId()==TYPEID_PLAYER)
|
||||
return;
|
||||
|
||||
float x, y, z;
|
||||
float dist = speedXY * speedZ * 0.1f;
|
||||
i_owner->GetNearPoint(i_owner, x, y, z, i_owner->GetObjectSize(), dist, i_owner->GetAngle(srcX, srcY) + M_PI);
|
||||
MoveJump(x, y, z, speedXY, speedZ);
|
||||
}
|
||||
|
||||
void MotionMaster::MoveJumpTo(float angle, float speedXY, float speedZ)
|
||||
{
|
||||
//this function may make players fall below map
|
||||
if(i_owner->GetTypeId()==TYPEID_PLAYER)
|
||||
return;
|
||||
|
||||
float x, y, z;
|
||||
float dist = speedXY * speedZ * 0.1f;
|
||||
i_owner->GetClosePoint(x, y, z, i_owner->GetObjectSize(), dist, angle);
|
||||
MoveJump(x, y, z, speedXY, speedZ);
|
||||
}
|
||||
|
||||
void MotionMaster::MoveJump(float x, float y, float z, float speedXY, float speedZ)
|
||||
{
|
||||
uint32 moveFlag = MOVEFLAG_JUMP | MOVEFLAG_WALK;
|
||||
uint32 time = speedZ * 100;
|
||||
|
||||
i_owner->addUnitState(UNIT_STAT_CHARGING | UNIT_STAT_JUMPING);
|
||||
i_owner->m_TempSpeed = speedXY;
|
||||
if(i_owner->GetTypeId()==TYPEID_PLAYER)
|
||||
@@ -339,16 +301,13 @@ void MotionMaster::MoveJump(float x, float y, float z, float speedXY, float spee
|
||||
i_owner->GetEntry(), i_owner->GetGUIDLow(), x, y, z );
|
||||
Mutate(new PointMovementGenerator<Creature>(0,x,y,z), MOTION_SLOT_CONTROLLED);
|
||||
}
|
||||
|
||||
i_owner->SendMonsterMove(x, y, z, moveFlag, time, speedZ);
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::MoveCharge(float x, float y, float z, float speed, uint32 id)
|
||||
{
|
||||
if(Impl[MOTION_SLOT_CONTROLLED] && Impl[MOTION_SLOT_CONTROLLED]->GetMovementGeneratorType() != DISTRACT_MOTION_TYPE)
|
||||
return;
|
||||
|
||||
i_owner->addUnitState(UNIT_STAT_CHARGING);
|
||||
i_owner->m_TempSpeed = speed;
|
||||
if(i_owner->GetTypeId()==TYPEID_PLAYER)
|
||||
@@ -363,7 +322,6 @@ MotionMaster::MoveCharge(float x, float y, float z, float speed, uint32 id)
|
||||
Mutate(new PointMovementGenerator<Creature>(id,x,y,z), MOTION_SLOT_CONTROLLED);
|
||||
}
|
||||
}
|
||||
|
||||
void MotionMaster::MoveFall(float z, uint32 id)
|
||||
{
|
||||
i_owner->SetFlying(false);
|
||||
@@ -371,7 +329,6 @@ void MotionMaster::MoveFall(float z, uint32 id)
|
||||
//AddUnitMovementFlag(MOVEMENTFLAG_FALLING);
|
||||
MoveCharge(i_owner->GetPositionX(), i_owner->GetPositionY(), z, SPEED_CHARGE, id);
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::MoveSeekAssistance(float x, float y, float z)
|
||||
{
|
||||
@@ -388,7 +345,6 @@ MotionMaster::MoveSeekAssistance(float x, float y, float z)
|
||||
Mutate(new AssistanceMovementGenerator(x,y,z), MOTION_SLOT_ACTIVE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::MoveSeekAssistanceDistract(uint32 time)
|
||||
{
|
||||
@@ -403,16 +359,13 @@ MotionMaster::MoveSeekAssistanceDistract(uint32 time)
|
||||
Mutate(new AssistanceDistractMovementGenerator(time), MOTION_SLOT_ACTIVE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::MoveFleeing(Unit* enemy, uint32 time)
|
||||
{
|
||||
if(!enemy)
|
||||
return;
|
||||
|
||||
if(i_owner->HasAuraType(SPELL_AURA_PREVENTS_FLEEING))
|
||||
return;
|
||||
|
||||
if(i_owner->GetTypeId()==TYPEID_PLAYER)
|
||||
{
|
||||
DEBUG_LOG("Player (GUID: %u) flee from %s (GUID: %u)", i_owner->GetGUIDLow(),
|
||||
@@ -433,7 +386,6 @@ MotionMaster::MoveFleeing(Unit* enemy, uint32 time)
|
||||
Mutate(new FleeingMovementGenerator<Creature>(enemy->GetGUID()), MOTION_SLOT_CONTROLLED);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::MoveTaxiFlight(uint32 path, uint32 pathnode)
|
||||
{
|
||||
@@ -449,13 +401,11 @@ MotionMaster::MoveTaxiFlight(uint32 path, uint32 pathnode)
|
||||
i_owner->GetEntry(), i_owner->GetGUIDLow(), path, pathnode );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MotionMaster::MoveDistract(uint32 timer)
|
||||
{
|
||||
if(Impl[MOTION_SLOT_CONTROLLED])
|
||||
return;
|
||||
|
||||
if(i_owner->GetTypeId()==TYPEID_PLAYER)
|
||||
{
|
||||
DEBUG_LOG("Player (GUID: %u) distracted (timer: %u)", i_owner->GetGUIDLow(), timer);
|
||||
@@ -465,11 +415,9 @@ MotionMaster::MoveDistract(uint32 timer)
|
||||
DEBUG_LOG("Creature (Entry: %u GUID: %u) (timer: %u)",
|
||||
i_owner->GetEntry(), i_owner->GetGUIDLow(), timer);
|
||||
}
|
||||
|
||||
DistractMovementGenerator* mgen = new DistractMovementGenerator(timer);
|
||||
Mutate(mgen, MOTION_SLOT_CONTROLLED);
|
||||
}
|
||||
|
||||
void MotionMaster::Mutate(MovementGenerator *m, MovementSlot slot)
|
||||
{
|
||||
if(MovementGenerator *curr = Impl[slot])
|
||||
@@ -484,7 +432,6 @@ void MotionMaster::Mutate(MovementGenerator *m, MovementSlot slot)
|
||||
{
|
||||
i_top = slot;
|
||||
}
|
||||
|
||||
if(i_top > slot)
|
||||
needInit[slot] = true;
|
||||
else
|
||||
@@ -494,7 +441,6 @@ void MotionMaster::Mutate(MovementGenerator *m, MovementSlot slot)
|
||||
}
|
||||
Impl[slot] = m;
|
||||
}
|
||||
|
||||
void MotionMaster::MovePath(uint32 path_id, bool repeatable)
|
||||
{
|
||||
if(!path_id)
|
||||
@@ -509,24 +455,19 @@ void MotionMaster::MovePath(uint32 path_id, bool repeatable)
|
||||
if( !isStatic( curr ) )
|
||||
delete curr;
|
||||
}*/
|
||||
|
||||
//i_owner->GetTypeId()==TYPEID_PLAYER ?
|
||||
//Mutate(new WaypointMovementGenerator<Player>(path_id, repeatable)):
|
||||
Mutate(new WaypointMovementGenerator<Creature>(path_id, repeatable), MOTION_SLOT_IDLE);
|
||||
|
||||
DEBUG_LOG("%s (GUID: %u) start moving over path(Id:%u, repeatable: %s)",
|
||||
i_owner->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature",
|
||||
i_owner->GetGUIDLow(), path_id, repeatable ? "YES" : "NO" );
|
||||
}
|
||||
|
||||
void MotionMaster::MoveRotate(uint32 time, RotateDirection direction)
|
||||
{
|
||||
if(!time)
|
||||
return;
|
||||
|
||||
Mutate(new RotateMovementGenerator(time, direction), MOTION_SLOT_ACTIVE);
|
||||
}
|
||||
|
||||
void MotionMaster::propagateSpeedChange()
|
||||
{
|
||||
/*Impl::container_type::iterator it = Impl::c.begin();
|
||||
@@ -540,15 +481,12 @@ void MotionMaster::propagateSpeedChange()
|
||||
Impl[i]->unitSpeedChanged();
|
||||
}
|
||||
}
|
||||
|
||||
MovementGeneratorType MotionMaster::GetCurrentMovementGeneratorType() const
|
||||
{
|
||||
if(empty())
|
||||
return IDLE_MOTION_TYPE;
|
||||
|
||||
return top()->GetMovementGeneratorType();
|
||||
}
|
||||
|
||||
MovementGeneratorType MotionMaster::GetMotionSlotType(int slot) const
|
||||
{
|
||||
if(!Impl[slot])
|
||||
@@ -556,13 +494,11 @@ MovementGeneratorType MotionMaster::GetMotionSlotType(int slot) const
|
||||
else
|
||||
return Impl[slot]->GetMovementGeneratorType();
|
||||
}
|
||||
|
||||
void MotionMaster::InitTop()
|
||||
{
|
||||
top()->Initialize(*i_owner);
|
||||
needInit[i_top] = false;
|
||||
}
|
||||
|
||||
void MotionMaster::DirectDelete(_Ty curr)
|
||||
{
|
||||
if(isStatic(curr))
|
||||
@@ -570,7 +506,6 @@ void MotionMaster::DirectDelete(_Ty curr)
|
||||
curr->Finalize(*i_owner);
|
||||
delete curr;
|
||||
}
|
||||
|
||||
void MotionMaster::DelayedDelete(_Ty curr)
|
||||
{
|
||||
sLog.outCrash("Unit (Entry %u) is trying to delete its updating MG (Type %u)!", i_owner->GetEntry(), curr->GetMovementGeneratorType());
|
||||
@@ -580,12 +515,10 @@ void MotionMaster::DelayedDelete(_Ty curr)
|
||||
m_expList = new ExpireList();
|
||||
m_expList->push_back(curr);
|
||||
}
|
||||
|
||||
bool MotionMaster::GetDestination(float &x, float &y, float &z)
|
||||
{
|
||||
if(empty())
|
||||
return false;
|
||||
|
||||
return top()->GetDestination(x,y,z);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user