aboutsummaryrefslogtreecommitdiff
path: root/src/game/MotionMaster.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/MotionMaster.cpp')
-rw-r--r--src/game/MotionMaster.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/game/MotionMaster.cpp b/src/game/MotionMaster.cpp
index 1b0b57219b8..e32fffaa8ac 100644
--- a/src/game/MotionMaster.cpp
+++ b/src/game/MotionMaster.cpp
@@ -17,10 +17,12 @@
* 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"
@@ -29,11 +31,14 @@
#include "TargetedMovementGenerator.h"
#include "WaypointMovementGenerator.h"
#include "RandomMovementGenerator.h"
+
#include <cassert>
+
inline bool isStatic(MovementGenerator *mv)
{
return (mv == &si_idleMovement);
}
+
void
MotionMaster::Initialize()
{
@@ -44,8 +49,10 @@ MotionMaster::Initialize()
pop();
if(curr) DirectDelete(curr);
}
+
InitDefault();
}
+
// set new default movement generator
void MotionMaster::InitDefault()
{
@@ -59,6 +66,7 @@ void MotionMaster::InitDefault()
Mutate(&si_idleMovement, MOTION_SLOT_IDLE);
}
}
+
MotionMaster::~MotionMaster()
{
// clear ALL movement generators (including default)
@@ -69,6 +77,7 @@ MotionMaster::~MotionMaster()
if(curr) DirectDelete(curr);
}
}
+
void
MotionMaster::UpdateMotion(uint32 diff)
{
@@ -83,6 +92,7 @@ MotionMaster::UpdateMotion(uint32 diff)
}
else
m_cleanFlag &= ~MMCF_UPDATE;
+
if (m_expList)
{
for (size_t i = 0; i < m_expList->size(); ++i)
@@ -90,17 +100,21 @@ 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)
{
@@ -110,11 +124,13 @@ MotionMaster::DirectClean(bool reset)
pop();
if(curr) DirectDelete(curr);
}
+
if(needInitTop())
InitTop();
else if(reset)
top()->Reset(*i_owner);
}
+
void
MotionMaster::DelayedClean()
{
@@ -125,6 +141,7 @@ MotionMaster::DelayedClean()
if(curr) DelayedDelete(curr);
}
}
+
void
MotionMaster::DirectExpire(bool reset)
{
@@ -134,8 +151,10 @@ MotionMaster::DirectExpire(bool reset)
pop();
DirectDelete(curr);
}
+
while(!top())
--i_top;
+
if(empty())
Initialize();
else if(needInitTop())
@@ -143,6 +162,7 @@ MotionMaster::DirectExpire(bool reset)
else if(reset)
top()->Reset(*i_owner);
}
+
void
MotionMaster::DelayedExpire()
{
@@ -152,9 +172,11 @@ MotionMaster::DelayedExpire()
pop();
DelayedDelete(curr);
}
+
while(!top())
--i_top;
}
+
void MotionMaster::MoveIdle(MovementSlot slot)
{
//if( empty() || !isStatic( top() ) )
@@ -162,6 +184,7 @@ void MotionMaster::MoveIdle(MovementSlot slot)
if(!isStatic(Impl[slot]))
Mutate(&si_idleMovement, slot);
}
+
void
MotionMaster::MoveRandom(float spawndist)
{
@@ -171,12 +194,15 @@ 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());
@@ -187,6 +213,7 @@ MotionMaster::MoveTargetedHome()
sLog.outError("Player (GUID: %u) attempt targeted home", i_owner->GetGUIDLow() );
}
}
+
void
MotionMaster::MoveConfused()
{
@@ -202,12 +229,14 @@ 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)
{
@@ -226,12 +255,14 @@ 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)
{
@@ -249,6 +280,7 @@ 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)
{
@@ -264,30 +296,36 @@ 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)
@@ -301,13 +339,16 @@ 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)
@@ -322,6 +363,7 @@ 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);
@@ -329,6 +371,7 @@ 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)
{
@@ -345,6 +388,7 @@ MotionMaster::MoveSeekAssistance(float x, float y, float z)
Mutate(new AssistanceMovementGenerator(x,y,z), MOTION_SLOT_ACTIVE);
}
}
+
void
MotionMaster::MoveSeekAssistanceDistract(uint32 time)
{
@@ -359,13 +403,16 @@ 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(),
@@ -386,6 +433,7 @@ MotionMaster::MoveFleeing(Unit* enemy, uint32 time)
Mutate(new FleeingMovementGenerator<Creature>(enemy->GetGUID()), MOTION_SLOT_CONTROLLED);
}
}
+
void
MotionMaster::MoveTaxiFlight(uint32 path, uint32 pathnode)
{
@@ -401,11 +449,13 @@ 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);
@@ -415,9 +465,11 @@ 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])
@@ -432,6 +484,7 @@ void MotionMaster::Mutate(MovementGenerator *m, MovementSlot slot)
{
i_top = slot;
}
+
if(i_top > slot)
needInit[slot] = true;
else
@@ -441,6 +494,7 @@ void MotionMaster::Mutate(MovementGenerator *m, MovementSlot slot)
}
Impl[slot] = m;
}
+
void MotionMaster::MovePath(uint32 path_id, bool repeatable)
{
if(!path_id)
@@ -455,19 +509,24 @@ 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();
@@ -481,12 +540,15 @@ 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])
@@ -494,11 +556,13 @@ 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))
@@ -506,6 +570,7 @@ 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());
@@ -515,10 +580,12 @@ 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);
}