Core/Movement: Make MovementGenerators use pointers instead of references. cleanup

This commit is contained in:
Subv
2012-08-25 22:57:55 -05:00
parent e0abbfd86c
commit 97c3e2e6c1
24 changed files with 484 additions and 481 deletions
+4 -4
View File
@@ -372,7 +372,7 @@ bool Unit::haveOffhandWeapon() const
void Unit::MonsterMoveWithSpeed(float x, float y, float z, float speed, bool generatePath, bool forceDestination) void Unit::MonsterMoveWithSpeed(float x, float y, float z, float speed, bool generatePath, bool forceDestination)
{ {
Movement::MoveSplineInit init(*this); Movement::MoveSplineInit init(this);
init.MoveTo(x, y, z, generatePath, forceDestination); init.MoveTo(x, y, z, generatePath, forceDestination);
init.SetVelocity(speed); init.SetVelocity(speed);
init.Launch(); init.Launch();
@@ -14750,7 +14750,7 @@ void Unit::StopMoving()
if (!IsInWorld()) if (!IsInWorld())
return; return;
Movement::MoveSplineInit init(*this); Movement::MoveSplineInit init(this);
init.MoveTo(GetPositionX(), GetPositionY(), GetPositionZMinusOffset()); init.MoveTo(GetPositionX(), GetPositionY(), GetPositionZMinusOffset());
init.SetFacing(GetOrientation()); init.SetFacing(GetOrientation());
init.Launch(); init.Launch();
@@ -17152,7 +17152,7 @@ void Unit::_ExitVehicle(Position const* exitPosition)
SendMessageToSet(&data, false); SendMessageToSet(&data, false);
} }
Movement::MoveSplineInit init(*this); Movement::MoveSplineInit init(this);
init.MoveTo(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ()); init.MoveTo(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ());
init.SetFacing(GetOrientation()); init.SetFacing(GetOrientation());
init.SetTransportExit(); init.SetTransportExit();
@@ -17562,7 +17562,7 @@ void Unit::SetInFront(Unit const* target)
void Unit::SetFacingTo(float ori) void Unit::SetFacingTo(float ori)
{ {
Movement::MoveSplineInit init(*this); Movement::MoveSplineInit init(this);
init.MoveTo(GetPositionX(), GetPositionY(), GetPositionZMinusOffset()); init.MoveTo(GetPositionX(), GetPositionY(), GetPositionZMinusOffset());
init.SetFacing(ori); init.SetFacing(ori);
init.Launch(); init.Launch();
+1 -1
View File
@@ -365,7 +365,7 @@ bool Vehicle::AddPassenger(Unit* unit, int8 seatId)
unit->SendClearTarget(); // SMSG_BREAK_TARGET unit->SendClearTarget(); // SMSG_BREAK_TARGET
unit->SetControlled(true, UNIT_STATE_ROOT); // SMSG_FORCE_ROOT - In some cases we send SMSG_SPLINE_MOVE_ROOT here (for creatures) unit->SetControlled(true, UNIT_STATE_ROOT); // SMSG_FORCE_ROOT - In some cases we send SMSG_SPLINE_MOVE_ROOT here (for creatures)
// also adds MOVEMENTFLAG_ROOT // also adds MOVEMENTFLAG_ROOT
Movement::MoveSplineInit init(*unit); Movement::MoveSplineInit init(unit);
init.DisableTransportPathTransformations(); init.DisableTransportPathTransformations();
init.MoveTo(veSeat->m_attachmentOffsetX, veSeat->m_attachmentOffsetY, veSeat->m_attachmentOffsetZ); init.MoveTo(veSeat->m_attachmentOffsetX, veSeat->m_attachmentOffsetY, veSeat->m_attachmentOffsetZ);
init.SetFacing(0.0f); init.SetFacing(0.0f);
+1 -1
View File
@@ -125,7 +125,7 @@ void WorldSession::HandleMoveWorldportAckOpcode()
{ {
// short preparations to continue flight // short preparations to continue flight
FlightPathMovementGenerator* flight = (FlightPathMovementGenerator*)(GetPlayer()->GetMotionMaster()->top()); FlightPathMovementGenerator* flight = (FlightPathMovementGenerator*)(GetPlayer()->GetMotionMaster()->top());
flight->Initialize(*GetPlayer()); flight->Initialize(GetPlayer());
return; return;
} }
+20 -20
View File
@@ -86,7 +86,7 @@ void MotionMaster::UpdateMotion(uint32 diff)
ASSERT(!empty()); ASSERT(!empty());
_cleanFlag |= MMCF_UPDATE; _cleanFlag |= MMCF_UPDATE;
if (!top()->Update(*_owner, diff)) if (!top()->Update(_owner, diff))
{ {
_cleanFlag &= ~MMCF_UPDATE; _cleanFlag &= ~MMCF_UPDATE;
MovementExpired(); MovementExpired();
@@ -110,7 +110,7 @@ void MotionMaster::UpdateMotion(uint32 diff)
else if (needInitTop()) else if (needInitTop())
InitTop(); InitTop();
else if (_cleanFlag & MMCF_RESET) else if (_cleanFlag & MMCF_RESET)
top()->Reset(*_owner); top()->Reset(_owner);
_cleanFlag &= ~MMCF_RESET; _cleanFlag &= ~MMCF_RESET;
} }
@@ -131,7 +131,7 @@ void MotionMaster::DirectClean(bool reset)
if (needInitTop()) if (needInitTop())
InitTop(); InitTop();
else if (reset) else if (reset)
top()->Reset(*_owner); top()->Reset(_owner);
} }
void MotionMaster::DelayedClean() void MotionMaster::DelayedClean()
@@ -162,7 +162,7 @@ void MotionMaster::DirectExpire(bool reset)
else if (needInitTop()) else if (needInitTop())
InitTop(); InitTop();
else if (reset) else if (reset)
top()->Reset(*_owner); top()->Reset(_owner);
} }
void MotionMaster::DelayedExpire() void MotionMaster::DelayedExpire()
@@ -198,19 +198,19 @@ void MotionMaster::MoveTargetedHome()
{ {
Clear(false); Clear(false);
if (_owner->GetTypeId()==TYPEID_UNIT && !((Creature*)_owner)->GetCharmerOrOwnerGUID()) if (_owner->GetTypeId() == TYPEID_UNIT && !_owner->ToCreature()->GetCharmerOrOwnerGUID())
{ {
sLog->outDebug(LOG_FILTER_GENERAL, "Creature (Entry: %u GUID: %u) targeted home", _owner->GetEntry(), _owner->GetGUIDLow()); sLog->outDebug(LOG_FILTER_GENERAL, "Creature (Entry: %u GUID: %u) targeted home", _owner->GetEntry(), _owner->GetGUIDLow());
Mutate(new HomeMovementGenerator<Creature>(), MOTION_SLOT_ACTIVE); Mutate(new HomeMovementGenerator<Creature>(), MOTION_SLOT_ACTIVE);
} }
else if (_owner->GetTypeId()==TYPEID_UNIT && ((Creature*)_owner)->GetCharmerOrOwnerGUID()) else if (_owner->GetTypeId() == TYPEID_UNIT && _owner->ToCreature()->GetCharmerOrOwnerGUID())
{ {
sLog->outDebug(LOG_FILTER_GENERAL, "Pet or controlled creature (Entry: %u GUID: %u) targeting home", _owner->GetEntry(), _owner->GetGUIDLow()); sLog->outDebug(LOG_FILTER_GENERAL, "Pet or controlled creature (Entry: %u GUID: %u) targeting home", _owner->GetEntry(), _owner->GetGUIDLow());
Unit *target = ((Creature*)_owner)->GetCharmerOrOwner(); Unit* target = _owner->ToCreature()->GetCharmerOrOwner();
if (target) if (target)
{ {
sLog->outDebug(LOG_FILTER_GENERAL, "Following %s (GUID: %u)", target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", target->GetTypeId() == TYPEID_PLAYER ? target->GetGUIDLow() : ((Creature*)target)->GetDBTableGUIDLow()); sLog->outDebug(LOG_FILTER_GENERAL, "Following %s (GUID: %u)", target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", target->GetTypeId() == TYPEID_PLAYER ? target->GetGUIDLow() : ((Creature*)target)->GetDBTableGUIDLow());
Mutate(new FollowMovementGenerator<Creature>(*target,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE), MOTION_SLOT_ACTIVE); Mutate(new FollowMovementGenerator<Creature>(target, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE), MOTION_SLOT_ACTIVE);
} }
} }
else else
@@ -247,7 +247,7 @@ void MotionMaster::MoveChase(Unit* target, float dist, float angle)
_owner->GetGUIDLow(), _owner->GetGUIDLow(),
target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature",
target->GetTypeId() == TYPEID_PLAYER ? target->GetGUIDLow() : target->ToCreature()->GetDBTableGUIDLow()); target->GetTypeId() == TYPEID_PLAYER ? target->GetGUIDLow() : target->ToCreature()->GetDBTableGUIDLow());
Mutate(new ChaseMovementGenerator<Player>(*target,dist,angle), MOTION_SLOT_ACTIVE); Mutate(new ChaseMovementGenerator<Player>(target, dist, angle), MOTION_SLOT_ACTIVE);
} }
else else
{ {
@@ -255,7 +255,7 @@ void MotionMaster::MoveChase(Unit* target, float dist, float angle)
_owner->GetEntry(), _owner->GetGUIDLow(), _owner->GetEntry(), _owner->GetGUIDLow(),
target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature",
target->GetTypeId() == TYPEID_PLAYER ? target->GetGUIDLow() : target->ToCreature()->GetDBTableGUIDLow()); target->GetTypeId() == TYPEID_PLAYER ? target->GetGUIDLow() : target->ToCreature()->GetDBTableGUIDLow());
Mutate(new ChaseMovementGenerator<Creature>(*target,dist,angle), MOTION_SLOT_ACTIVE); Mutate(new ChaseMovementGenerator<Creature>(target, dist, angle), MOTION_SLOT_ACTIVE);
} }
} }
@@ -271,7 +271,7 @@ void MotionMaster::MoveFollow(Unit* target, float dist, float angle, MovementSlo
sLog->outDebug(LOG_FILTER_GENERAL, "Player (GUID: %u) follow to %s (GUID: %u)", _owner->GetGUIDLow(), sLog->outDebug(LOG_FILTER_GENERAL, "Player (GUID: %u) follow to %s (GUID: %u)", _owner->GetGUIDLow(),
target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature",
target->GetTypeId() == TYPEID_PLAYER ? target->GetGUIDLow() : target->ToCreature()->GetDBTableGUIDLow()); target->GetTypeId() == TYPEID_PLAYER ? target->GetGUIDLow() : target->ToCreature()->GetDBTableGUIDLow());
Mutate(new FollowMovementGenerator<Player>(*target,dist,angle), slot); Mutate(new FollowMovementGenerator<Player>(target, dist, angle), slot);
} }
else else
{ {
@@ -279,7 +279,7 @@ void MotionMaster::MoveFollow(Unit* target, float dist, float angle, MovementSlo
_owner->GetEntry(), _owner->GetGUIDLow(), _owner->GetEntry(), _owner->GetGUIDLow(),
target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature", target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature",
target->GetTypeId() == TYPEID_PLAYER ? target->GetGUIDLow() : target->ToCreature()->GetDBTableGUIDLow()); target->GetTypeId() == TYPEID_PLAYER ? target->GetGUIDLow() : target->ToCreature()->GetDBTableGUIDLow());
Mutate(new FollowMovementGenerator<Creature>(*target,dist,angle), slot); Mutate(new FollowMovementGenerator<Creature>(target, dist, angle), slot);
} }
} }
@@ -305,7 +305,7 @@ void MotionMaster::MoveLand(uint32 id, Position const& pos)
sLog->outDebug(LOG_FILTER_GENERAL, "Creature (Entry: %u) landing point (ID: %u X: %f Y: %f Z: %f)", _owner->GetEntry(), id, x, y, z); sLog->outDebug(LOG_FILTER_GENERAL, "Creature (Entry: %u) landing point (ID: %u X: %f Y: %f Z: %f)", _owner->GetEntry(), id, x, y, z);
Movement::MoveSplineInit init(*_owner); Movement::MoveSplineInit init(_owner);
init.MoveTo(x,y,z); init.MoveTo(x,y,z);
init.SetAnimation(Movement::ToGround); init.SetAnimation(Movement::ToGround);
init.Launch(); init.Launch();
@@ -319,7 +319,7 @@ void MotionMaster::MoveTakeoff(uint32 id, Position const& pos)
sLog->outDebug(LOG_FILTER_GENERAL, "Creature (Entry: %u) landing point (ID: %u X: %f Y: %f Z: %f)", _owner->GetEntry(), id, x, y, z); sLog->outDebug(LOG_FILTER_GENERAL, "Creature (Entry: %u) landing point (ID: %u X: %f Y: %f Z: %f)", _owner->GetEntry(), id, x, y, z);
Movement::MoveSplineInit init(*_owner); Movement::MoveSplineInit init(_owner);
init.MoveTo(x,y,z); init.MoveTo(x,y,z);
init.SetAnimation(Movement::ToFly); init.SetAnimation(Movement::ToFly);
init.Launch(); init.Launch();
@@ -339,7 +339,7 @@ void MotionMaster::MoveKnockbackFrom(float srcX, float srcY, float speedXY, floa
_owner->GetNearPoint(_owner, x, y, z, _owner->GetObjectSize(), dist, _owner->GetAngle(srcX, srcY) + M_PI); _owner->GetNearPoint(_owner, x, y, z, _owner->GetObjectSize(), dist, _owner->GetAngle(srcX, srcY) + M_PI);
Movement::MoveSplineInit init(*_owner); Movement::MoveSplineInit init(_owner);
init.MoveTo(x,y,z); init.MoveTo(x,y,z);
init.SetParabolic(max_height,0); init.SetParabolic(max_height,0);
init.SetOrientationFixed(true); init.SetOrientationFixed(true);
@@ -369,7 +369,7 @@ void MotionMaster::MoveJump(float x, float y, float z, float speedXY, float spee
float moveTimeHalf = speedZ / Movement::gravity; float moveTimeHalf = speedZ / Movement::gravity;
float max_height = -Movement::computeFallElevation(moveTimeHalf,false,-speedZ); float max_height = -Movement::computeFallElevation(moveTimeHalf,false,-speedZ);
Movement::MoveSplineInit init(*_owner); Movement::MoveSplineInit init(_owner);
init.MoveTo(x, y, z, false); init.MoveTo(x, y, z, false);
init.SetParabolic(max_height,0); init.SetParabolic(max_height,0);
init.SetVelocity(speedXY); init.SetVelocity(speedXY);
@@ -398,7 +398,7 @@ void MotionMaster::MoveFall(uint32 id/*=0*/)
_owner->m_movementInfo.SetFallTime(0); _owner->m_movementInfo.SetFallTime(0);
} }
Movement::MoveSplineInit init(*_owner); Movement::MoveSplineInit init(_owner);
init.MoveTo(_owner->GetPositionX(), _owner->GetPositionY(), tz); init.MoveTo(_owner->GetPositionX(), _owner->GetPositionY(), tz);
init.SetFall(); init.SetFall();
init.Launch(); init.Launch();
@@ -545,7 +545,7 @@ void MotionMaster::Mutate(MovementGenerator *m, MovementSlot slot)
else else
{ {
_needInit[slot] = false; _needInit[slot] = false;
m->Initialize(*_owner); m->Initialize(_owner);
} }
} }
@@ -613,7 +613,7 @@ MovementGeneratorType MotionMaster::GetMotionSlotType(int slot) const
void MotionMaster::InitTop() void MotionMaster::InitTop()
{ {
top()->Initialize(*_owner); top()->Initialize(_owner);
_needInit[_top] = false; _needInit[_top] = false;
} }
@@ -621,7 +621,7 @@ void MotionMaster::DirectDelete(_Ty curr)
{ {
if (isStatic(curr)) if (isStatic(curr))
return; return;
curr->Finalize(*_owner); curr->Finalize(_owner);
delete curr; delete curr;
} }
+20 -17
View File
@@ -33,51 +33,54 @@ class MovementGenerator
public: public:
virtual ~MovementGenerator(); virtual ~MovementGenerator();
virtual void Initialize(Unit &) = 0; virtual void Initialize(Unit*) = 0;
virtual void Finalize(Unit &) = 0; virtual void Finalize(Unit*) = 0;
virtual void Reset(Unit &) = 0; virtual void Reset(Unit*) = 0;
virtual bool Update(Unit &, const uint32& time_diff) = 0; virtual bool Update(Unit*, const uint32& time_diff) = 0;
virtual MovementGeneratorType GetMovementGeneratorType() = 0; virtual MovementGeneratorType GetMovementGeneratorType() = 0;
virtual void unitSpeedChanged() { } virtual void unitSpeedChanged() { }
// used by Evade code for select point to evade with expected restart default movement // used by Evade code for select point to evade with expected restart default movement
virtual bool GetResetPosition(Unit &, float& /*x*/, float& /*y*/, float& /*z*/) { return false; } virtual bool GetResetPosition(Unit*, float& /*x*/, float& /*y*/, float& /*z*/) { return false; }
}; };
template<class T, class D> template<class T, class D>
class MovementGeneratorMedium : public MovementGenerator class MovementGeneratorMedium : public MovementGenerator
{ {
public: public:
void Initialize(Unit &u) void Initialize(Unit* u)
{ {
//u->AssertIsType<T>(); //u->AssertIsType<T>();
(static_cast<D*>(this))->Initialize(*((T*)&u)); (static_cast<D*>(this))->Initialize(static_cast<T*>(u));
} }
void Finalize(Unit &u)
void Finalize(Unit* u)
{ {
//u->AssertIsType<T>(); //u->AssertIsType<T>();
(static_cast<D*>(this))->Finalize(*((T*)&u)); (static_cast<D*>(this))->Finalize(static_cast<T*>(u));
} }
void Reset(Unit &u)
void Reset(Unit* u)
{ {
//u->AssertIsType<T>(); //u->AssertIsType<T>();
(static_cast<D*>(this))->Reset(*((T*)&u)); (static_cast<D*>(this))->Reset(static_cast<T*>(u));
} }
bool Update(Unit &u, const uint32& time_diff)
bool Update(Unit* u, const uint32& time_diff)
{ {
//u->AssertIsType<T>(); //u->AssertIsType<T>();
return (static_cast<D*>(this))->Update(*((T*)&u), time_diff); return (static_cast<D*>(this))->Update(static_cast<T*>(u), time_diff);
} }
public: public:
// will not link if not overridden in the generators // will not link if not overridden in the generators
void Initialize(T &u); void Initialize(T* u);
void Finalize(T &u); void Finalize(T* u);
void Reset(T &u); void Reset(T* u);
bool Update(T &u, const uint32& time_diff); bool Update(T* u, const uint32& time_diff);
}; };
struct SelectableMovement : public FactoryHolder<MovementGenerator, MovementGeneratorType> struct SelectableMovement : public FactoryHolder<MovementGenerator, MovementGeneratorType>
@@ -31,34 +31,34 @@
#endif #endif
template<class T> template<class T>
void ConfusedMovementGenerator<T>::Initialize(T &unit) void ConfusedMovementGenerator<T>::Initialize(T* unit)
{ {
unit.GetPosition(i_x, i_y, i_z); unit->GetPosition(i_x, i_y, i_z);
unit.StopMoving(); unit->StopMoving();
unit.SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED); unit->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
unit.AddUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE); unit->AddUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
} }
template<class T> template<class T>
void ConfusedMovementGenerator<T>::Reset(T &unit) void ConfusedMovementGenerator<T>::Reset(T* unit)
{ {
i_nextMoveTime.Reset(0); i_nextMoveTime.Reset(0);
unit.StopMoving(); unit->StopMoving();
unit.AddUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE); unit->AddUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
} }
template<class T> template<class T>
bool ConfusedMovementGenerator<T>::Update(T &unit, const uint32 &diff) bool ConfusedMovementGenerator<T>::Update(T* unit, const uint32& diff)
{ {
if (unit.HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED | UNIT_STATE_DISTRACTED)) if (unit->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED | UNIT_STATE_DISTRACTED))
return true; return true;
if (i_nextMoveTime.Passed()) if (i_nextMoveTime.Passed())
{ {
// currently moving, update location // currently moving, update location
unit.AddUnitState(UNIT_STATE_CONFUSED_MOVE); unit->AddUnitState(UNIT_STATE_CONFUSED_MOVE);
if (unit.movespline->Finalized()) if (unit->movespline->Finalized())
i_nextMoveTime.Reset(urand(800, 1500)); i_nextMoveTime.Reset(urand(800, 1500));
} }
else else
@@ -68,15 +68,15 @@ bool ConfusedMovementGenerator<T>::Update(T &unit, const uint32 &diff)
if (i_nextMoveTime.Passed()) if (i_nextMoveTime.Passed())
{ {
// start moving // start moving
unit.AddUnitState(UNIT_STATE_CONFUSED_MOVE); unit->AddUnitState(UNIT_STATE_CONFUSED_MOVE);
float x = i_x + 10.0f*((float)rand_norm() - 0.5f); float x = i_x + 10.0f*((float)rand_norm() - 0.5f);
float y = i_y + 10.0f*((float)rand_norm() - 0.5f); float y = i_y + 10.0f*((float)rand_norm() - 0.5f);
float z = i_z; float z = i_z;
unit.UpdateAllowedPositionZ(x, y, z); unit->UpdateAllowedPositionZ(x, y, z);
PathGenerator path(&unit); PathGenerator path(unit);
path.setPathLengthLimit(30.0f); path.setPathLengthLimit(30.0f);
path.CalculatePath(x, y, z); path.CalculatePath(x, y, z);
if (path.getPathType() & PATHFIND_NOPATH) if (path.getPathType() & PATHFIND_NOPATH)
@@ -96,26 +96,26 @@ bool ConfusedMovementGenerator<T>::Update(T &unit, const uint32 &diff)
} }
template<> template<>
void ConfusedMovementGenerator<Player>::Finalize(Player &unit) void ConfusedMovementGenerator<Player>::Finalize(Player* unit)
{ {
unit.RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED); unit->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
unit.ClearUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE); unit->ClearUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
unit.StopMoving(); unit->StopMoving();
} }
template<> template<>
void ConfusedMovementGenerator<Creature>::Finalize(Creature &unit) void ConfusedMovementGenerator<Creature>::Finalize(Creature* unit)
{ {
unit.RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED); unit->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
unit.ClearUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE); unit->ClearUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
if (unit.getVictim()) if (unit->getVictim())
unit.SetTarget(unit.getVictim()->GetGUID()); unit->SetTarget(unit->getVictim()->GetGUID());
} }
template void ConfusedMovementGenerator<Player>::Initialize(Player &player); template void ConfusedMovementGenerator<Player>::Initialize(Player*);
template void ConfusedMovementGenerator<Creature>::Initialize(Creature &creature); template void ConfusedMovementGenerator<Creature>::Initialize(Creature*);
template void ConfusedMovementGenerator<Player>::Reset(Player &player); template void ConfusedMovementGenerator<Player>::Reset(Player*);
template void ConfusedMovementGenerator<Creature>::Reset(Creature &creature); template void ConfusedMovementGenerator<Creature>::Reset(Creature*);
template bool ConfusedMovementGenerator<Player>::Update(Player &player, const uint32 &diff); template bool ConfusedMovementGenerator<Player>::Update(Player*, const uint32&);
template bool ConfusedMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff); template bool ConfusedMovementGenerator<Creature>::Update(Creature*, const uint32&);
@@ -28,10 +28,10 @@ class ConfusedMovementGenerator : public MovementGeneratorMedium< T, ConfusedMov
public: public:
explicit ConfusedMovementGenerator() : i_nextMoveTime(0) {} explicit ConfusedMovementGenerator() : i_nextMoveTime(0) {}
void Initialize(T &); void Initialize(T*);
void Finalize(T &); void Finalize(T*);
void Reset(T &); void Reset(T*);
bool Update(T &, const uint32 &); bool Update(T*, const uint32&);
MovementGeneratorType GetMovementGeneratorType() { return CONFUSED_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return CONFUSED_MOTION_TYPE; }
private: private:
@@ -29,21 +29,21 @@
#define MAX_QUIET_DISTANCE 43.0f #define MAX_QUIET_DISTANCE 43.0f
template<class T> template<class T>
void FleeingMovementGenerator<T>::_setTargetLocation(T &owner) void FleeingMovementGenerator<T>::_setTargetLocation(T* owner)
{ {
if (!&owner) if (!owner)
return; return;
if (owner.HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED)) if (owner->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED))
return; return;
float x, y, z; float x, y, z;
if (!_getPoint(owner, x, y, z)) if (!_getPoint(owner, x, y, z))
return; return;
owner.AddUnitState(UNIT_STATE_FLEEING_MOVE); owner->AddUnitState(UNIT_STATE_FLEEING_MOVE);
PathGenerator path(&owner); PathGenerator path(owner);
path.setPathLengthLimit(30.0f); path.setPathLengthLimit(30.0f);
path.CalculatePath(x, y, z); path.CalculatePath(x, y, z);
if (path.getPathType() & PATHFIND_NOPATH) if (path.getPathType() & PATHFIND_NOPATH)
@@ -60,17 +60,17 @@ void FleeingMovementGenerator<T>::_setTargetLocation(T &owner)
} }
template<class T> template<class T>
bool FleeingMovementGenerator<T>::_getPoint(T &owner, float &x, float &y, float &z) bool FleeingMovementGenerator<T>::_getPoint(T* owner, float &x, float &y, float &z)
{ {
if (!&owner) if (!owner)
return false; return false;
float dist_from_caster, angle_to_caster; float dist_from_caster, angle_to_caster;
if (Unit* fright = ObjectAccessor::GetUnit(owner, i_frightGUID)) if (Unit* fright = ObjectAccessor::GetUnit(*owner, i_frightGUID))
{ {
dist_from_caster = fright->GetDistance(&owner); dist_from_caster = fright->GetDistance(owner);
if (dist_from_caster > 0.2f) if (dist_from_caster > 0.2f)
angle_to_caster = fright->GetAngle(&owner); angle_to_caster = fright->GetAngle(owner);
else else
angle_to_caster = frand(0, 2 * static_cast<float>(M_PI)); angle_to_caster = frand(0, 2 * static_cast<float>(M_PI));
} }
@@ -98,106 +98,106 @@ bool FleeingMovementGenerator<T>::_getPoint(T &owner, float &x, float &y, float
} }
float curr_x, curr_y, curr_z; float curr_x, curr_y, curr_z;
owner.GetPosition(curr_x, curr_y, curr_z); owner->GetPosition(curr_x, curr_y, curr_z);
x = curr_x + dist*cos(angle); x = curr_x + dist*cos(angle);
y = curr_y + dist*sin(angle); y = curr_y + dist*sin(angle);
z = curr_z; z = curr_z;
owner.UpdateAllowedPositionZ(x, y, z); owner->UpdateAllowedPositionZ(x, y, z);
return true; return true;
} }
template<class T> template<class T>
void FleeingMovementGenerator<T>::Initialize(T &owner) void FleeingMovementGenerator<T>::Initialize(T* owner)
{ {
if (!&owner) if (!owner)
return; return;
owner.SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING); owner->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
owner.AddUnitState(UNIT_STATE_FLEEING|UNIT_STATE_FLEEING_MOVE); owner->AddUnitState(UNIT_STATE_FLEEING|UNIT_STATE_FLEEING_MOVE);
if (owner.GetTypeId() == TYPEID_UNIT) if (owner->GetTypeId() == TYPEID_UNIT)
return; return;
_setTargetLocation(owner); _setTargetLocation(owner);
} }
template<> template<>
void FleeingMovementGenerator<Player>::Finalize(Player &owner) void FleeingMovementGenerator<Player>::Finalize(Player* owner)
{ {
owner.RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING); owner->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
owner.ClearUnitState(UNIT_STATE_FLEEING|UNIT_STATE_FLEEING_MOVE); owner->ClearUnitState(UNIT_STATE_FLEEING | UNIT_STATE_FLEEING_MOVE);
owner.StopMoving(); owner->StopMoving();
} }
template<> template<>
void FleeingMovementGenerator<Creature>::Finalize(Creature &owner) void FleeingMovementGenerator<Creature>::Finalize(Creature* owner)
{ {
owner.RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING); owner->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
owner.ClearUnitState(UNIT_STATE_FLEEING|UNIT_STATE_FLEEING_MOVE); owner->ClearUnitState(UNIT_STATE_FLEEING|UNIT_STATE_FLEEING_MOVE);
if (owner.getVictim()) if (owner->getVictim())
owner.SetTarget(owner.getVictim()->GetGUID()); owner->SetTarget(owner->getVictim()->GetGUID());
} }
template<class T> template<class T>
void FleeingMovementGenerator<T>::Reset(T &owner) void FleeingMovementGenerator<T>::Reset(T* owner)
{ {
Initialize(owner); Initialize(owner);
} }
template<class T> template<class T>
bool FleeingMovementGenerator<T>::Update(T &owner, const uint32 &time_diff) bool FleeingMovementGenerator<T>::Update(T* owner, const uint32& time_diff)
{ {
if (!&owner || !owner.isAlive()) if (!owner || !owner->isAlive())
return false; return false;
if (owner.HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED)) if (owner->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED))
{ {
owner.ClearUnitState(UNIT_STATE_FLEEING_MOVE); owner->ClearUnitState(UNIT_STATE_FLEEING_MOVE);
return true; return true;
} }
i_nextCheckTime.Update(time_diff); i_nextCheckTime.Update(time_diff);
if (i_nextCheckTime.Passed() && owner.movespline->Finalized()) if (i_nextCheckTime.Passed() && owner->movespline->Finalized())
_setTargetLocation(owner); _setTargetLocation(owner);
return true; return true;
} }
template void FleeingMovementGenerator<Player>::Initialize(Player &); template void FleeingMovementGenerator<Player>::Initialize(Player*);
template void FleeingMovementGenerator<Creature>::Initialize(Creature &); template void FleeingMovementGenerator<Creature>::Initialize(Creature*);
template bool FleeingMovementGenerator<Player>::_getPoint(Player &, float &, float &, float &); template bool FleeingMovementGenerator<Player>::_getPoint(Player*, float&, float&, float&);
template bool FleeingMovementGenerator<Creature>::_getPoint(Creature &, float &, float &, float &); template bool FleeingMovementGenerator<Creature>::_getPoint(Creature*, float&, float&, float&);
template void FleeingMovementGenerator<Player>::_setTargetLocation(Player &); template void FleeingMovementGenerator<Player>::_setTargetLocation(Player*);
template void FleeingMovementGenerator<Creature>::_setTargetLocation(Creature &); template void FleeingMovementGenerator<Creature>::_setTargetLocation(Creature*);
template void FleeingMovementGenerator<Player>::Reset(Player &); template void FleeingMovementGenerator<Player>::Reset(Player*);
template void FleeingMovementGenerator<Creature>::Reset(Creature &); template void FleeingMovementGenerator<Creature>::Reset(Creature*);
template bool FleeingMovementGenerator<Player>::Update(Player &, const uint32 &); template bool FleeingMovementGenerator<Player>::Update(Player*, const uint32&);
template bool FleeingMovementGenerator<Creature>::Update(Creature &, const uint32 &); template bool FleeingMovementGenerator<Creature>::Update(Creature*, const uint32&);
void TimedFleeingMovementGenerator::Finalize(Unit &owner) void TimedFleeingMovementGenerator::Finalize(Unit* owner)
{ {
owner.RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING); owner->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
owner.ClearUnitState(UNIT_STATE_FLEEING|UNIT_STATE_FLEEING_MOVE); owner->ClearUnitState(UNIT_STATE_FLEEING|UNIT_STATE_FLEEING_MOVE);
if (Unit* victim = owner.getVictim()) if (Unit* victim = owner->getVictim())
{ {
if (owner.isAlive()) if (owner->isAlive())
{ {
owner.AttackStop(); owner->AttackStop();
owner.ToCreature()->AI()->AttackStart(victim); owner->ToCreature()->AI()->AttackStart(victim);
} }
} }
} }
bool TimedFleeingMovementGenerator::Update(Unit & owner, const uint32& time_diff) bool TimedFleeingMovementGenerator::Update(Unit* owner, const uint32& time_diff)
{ {
if (!owner.isAlive()) if (!owner->isAlive())
return false; return false;
if (owner.HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED)) if (owner->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED))
{ {
owner.ClearUnitState(UNIT_STATE_FLEEING_MOVE); owner->ClearUnitState(UNIT_STATE_FLEEING_MOVE);
return true; return true;
} }
@@ -27,16 +27,16 @@ class FleeingMovementGenerator : public MovementGeneratorMedium< T, FleeingMovem
public: public:
FleeingMovementGenerator(uint64 fright) : i_frightGUID(fright), i_nextCheckTime(0) {} FleeingMovementGenerator(uint64 fright) : i_frightGUID(fright), i_nextCheckTime(0) {}
void Initialize(T &); void Initialize(T*);
void Finalize(T &); void Finalize(T*);
void Reset(T &); void Reset(T*);
bool Update(T &, const uint32 &); bool Update(T*, const uint32&);
MovementGeneratorType GetMovementGeneratorType() { return FLEEING_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return FLEEING_MOTION_TYPE; }
private: private:
void _setTargetLocation(T &owner); void _setTargetLocation(T*);
bool _getPoint(T &owner, float &x, float &y, float &z); bool _getPoint(T*, float &x, float &y, float &z);
uint64 i_frightGUID; uint64 i_frightGUID;
TimeTracker i_nextCheckTime; TimeTracker i_nextCheckTime;
@@ -50,8 +50,8 @@ class TimedFleeingMovementGenerator : public FleeingMovementGenerator<Creature>
i_totalFleeTime(time) {} i_totalFleeTime(time) {}
MovementGeneratorType GetMovementGeneratorType() { return TIMED_FLEEING_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return TIMED_FLEEING_MOTION_TYPE; }
bool Update(Unit &, const uint32&); bool Update(Unit*, const uint32&);
void Finalize(Unit &); void Finalize(Unit*);
private: private:
TimeTracker i_totalFleeTime; TimeTracker i_totalFleeTime;
@@ -23,37 +23,37 @@
#include "MoveSplineInit.h" #include "MoveSplineInit.h"
#include "MoveSpline.h" #include "MoveSpline.h"
void HomeMovementGenerator<Creature>::Initialize(Creature& owner) void HomeMovementGenerator<Creature>::Initialize(Creature* owner)
{ {
_setTargetLocation(owner); _setTargetLocation(owner);
} }
void HomeMovementGenerator<Creature>::Finalize(Creature& owner) void HomeMovementGenerator<Creature>::Finalize(Creature* owner)
{ {
if (arrived) if (arrived)
{ {
owner.ClearUnitState(UNIT_STATE_EVADE); owner->ClearUnitState(UNIT_STATE_EVADE);
owner.SetWalk(true); owner->SetWalk(true);
owner.LoadCreaturesAddon(true); owner->LoadCreaturesAddon(true);
owner.AI()->JustReachedHome(); owner->AI()->JustReachedHome();
} }
} }
void HomeMovementGenerator<Creature>::Reset(Creature &) void HomeMovementGenerator<Creature>::Reset(Creature*)
{ {
} }
void HomeMovementGenerator<Creature>::_setTargetLocation(Creature & owner) void HomeMovementGenerator<Creature>::_setTargetLocation(Creature* owner)
{ {
if (owner.HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED | UNIT_STATE_DISTRACTED)) if (owner->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED | UNIT_STATE_DISTRACTED))
return; return;
Movement::MoveSplineInit init(owner); Movement::MoveSplineInit init(owner);
float x, y, z, o; float x, y, z, o;
// at apply we can select more nice return points base at current movegen // at apply we can select more nice return points base at current movegen
if (owner.GetMotionMaster()->empty() || !owner.GetMotionMaster()->top()->GetResetPosition(owner,x,y,z)) if (owner->GetMotionMaster()->empty() || !owner->GetMotionMaster()->top()->GetResetPosition(owner, x, y, z))
{ {
owner.GetHomePosition(x, y, z, o); owner->GetHomePosition(x, y, z, o);
init.SetFacing(o); init.SetFacing(o);
} }
init.MoveTo(x, y, z); init.MoveTo(x, y, z);
@@ -61,11 +61,11 @@ void HomeMovementGenerator<Creature>::_setTargetLocation(Creature & owner)
init.Launch(); init.Launch();
arrived = false; arrived = false;
owner.ClearUnitState(UNIT_STATE_ALL_STATE & ~UNIT_STATE_EVADE); owner->ClearUnitState(UNIT_STATE_ALL_STATE & ~UNIT_STATE_EVADE);
} }
bool HomeMovementGenerator<Creature>::Update(Creature &owner, const uint32 /*time_diff*/) bool HomeMovementGenerator<Creature>::Update(Creature* owner, const uint32 /*time_diff*/)
{ {
arrived = owner.movespline->Finalized(); arrived = owner->movespline->Finalized();
return !arrived; return !arrived;
} }
@@ -34,14 +34,14 @@ class HomeMovementGenerator<Creature> : public MovementGeneratorMedium< Creature
HomeMovementGenerator() : arrived(false) {} HomeMovementGenerator() : arrived(false) {}
~HomeMovementGenerator() {} ~HomeMovementGenerator() {}
void Initialize(Creature &); void Initialize(Creature*);
void Finalize(Creature &); void Finalize(Creature*);
void Reset(Creature &); void Reset(Creature*);
bool Update(Creature &, const uint32); bool Update(Creature*, const uint32);
MovementGeneratorType GetMovementGeneratorType() { return HOME_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return HOME_MOTION_TYPE; }
private: private:
void _setTargetLocation(Creature &); void _setTargetLocation(Creature*);
bool arrived; bool arrived;
}; };
#endif #endif
@@ -24,33 +24,33 @@ IdleMovementGenerator si_idleMovement;
// StopMoving is needed to make unit stop if its last movement generator expires // StopMoving is needed to make unit stop if its last movement generator expires
// But it should not be sent otherwise there are many redundent packets // But it should not be sent otherwise there are many redundent packets
void IdleMovementGenerator::Initialize(Unit &owner) void IdleMovementGenerator::Initialize(Unit* owner)
{ {
Reset(owner); Reset(owner);
} }
void IdleMovementGenerator::Reset(Unit& owner) void IdleMovementGenerator::Reset(Unit* owner)
{ {
if (!owner.IsStopped()) if (!owner->IsStopped())
owner.StopMoving(); owner->StopMoving();
} }
void RotateMovementGenerator::Initialize(Unit& owner) void RotateMovementGenerator::Initialize(Unit* owner)
{ {
if (!owner.IsStopped()) if (!owner->IsStopped())
owner.StopMoving(); owner->StopMoving();
if (owner.getVictim()) if (owner->getVictim())
owner.SetInFront(owner.getVictim()); owner->SetInFront(owner->getVictim());
owner.AddUnitState(UNIT_STATE_ROTATING); owner->AddUnitState(UNIT_STATE_ROTATING);
owner.AttackStop(); owner->AttackStop();
} }
bool RotateMovementGenerator::Update(Unit& owner, const uint32& diff) bool RotateMovementGenerator::Update(Unit* owner, const uint32& diff)
{ {
float angle = owner.GetOrientation(); float angle = owner->GetOrientation();
if (m_direction == ROTATE_DIRECTION_LEFT) if (m_direction == ROTATE_DIRECTION_LEFT)
{ {
angle += (float)diff * static_cast<float>(M_PI * 2) / m_maxDuration; angle += (float)diff * static_cast<float>(M_PI * 2) / m_maxDuration;
@@ -61,8 +61,8 @@ bool RotateMovementGenerator::Update(Unit& owner, const uint32& diff)
angle -= (float)diff * static_cast<float>(M_PI * 2) / m_maxDuration; angle -= (float)diff * static_cast<float>(M_PI * 2) / m_maxDuration;
while (angle < 0) angle += static_cast<float>(M_PI * 2); while (angle < 0) angle += static_cast<float>(M_PI * 2);
} }
owner.SetOrientation(angle); owner->SetOrientation(angle);
owner.SendMovementFlagUpdate(); // this is a hack. we do not have anything correct to send in the beginning owner->SendMovementFlagUpdate(); // this is a hack. we do not have anything correct to send in the beginning
if (m_duration > diff) if (m_duration > diff)
m_duration -= diff; m_duration -= diff;
@@ -72,24 +72,24 @@ bool RotateMovementGenerator::Update(Unit& owner, const uint32& diff)
return true; return true;
} }
void RotateMovementGenerator::Finalize(Unit &unit) void RotateMovementGenerator::Finalize(Unit* unit)
{ {
unit.ClearUnitState(UNIT_STATE_ROTATING); unit->ClearUnitState(UNIT_STATE_ROTATING);
if (unit.GetTypeId() == TYPEID_UNIT) if (unit->GetTypeId() == TYPEID_UNIT)
unit.ToCreature()->AI()->MovementInform(ROTATE_MOTION_TYPE, 0); unit->ToCreature()->AI()->MovementInform(ROTATE_MOTION_TYPE, 0);
} }
void DistractMovementGenerator::Initialize(Unit& owner) void DistractMovementGenerator::Initialize(Unit* owner)
{ {
owner.AddUnitState(UNIT_STATE_DISTRACTED); owner->AddUnitState(UNIT_STATE_DISTRACTED);
} }
void DistractMovementGenerator::Finalize(Unit& owner) void DistractMovementGenerator::Finalize(Unit* owner)
{ {
owner.ClearUnitState(UNIT_STATE_DISTRACTED); owner->ClearUnitState(UNIT_STATE_DISTRACTED);
} }
bool DistractMovementGenerator::Update(Unit& /*owner*/, const uint32& time_diff) bool DistractMovementGenerator::Update(Unit* /*owner*/, const uint32& time_diff)
{ {
if (time_diff > m_timer) if (time_diff > m_timer)
return false; return false;
@@ -98,9 +98,9 @@ bool DistractMovementGenerator::Update(Unit& /*owner*/, const uint32& time_diff)
return true; return true;
} }
void AssistanceDistractMovementGenerator::Finalize(Unit &unit) void AssistanceDistractMovementGenerator::Finalize(Unit* unit)
{ {
unit.ClearUnitState(UNIT_STATE_DISTRACTED); unit->ClearUnitState(UNIT_STATE_DISTRACTED);
unit.ToCreature()->SetReactState(REACT_AGGRESSIVE); unit->ToCreature()->SetReactState(REACT_AGGRESSIVE);
} }
@@ -25,10 +25,10 @@ class IdleMovementGenerator : public MovementGenerator
{ {
public: public:
void Initialize(Unit &); void Initialize(Unit*);
void Finalize(Unit &) { } void Finalize(Unit*) { }
void Reset(Unit &); void Reset(Unit*);
bool Update(Unit &, const uint32&) { return true; } bool Update(Unit*, const uint32&) { return true; }
MovementGeneratorType GetMovementGeneratorType() { return IDLE_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return IDLE_MOTION_TYPE; }
}; };
@@ -39,10 +39,10 @@ class RotateMovementGenerator : public MovementGenerator
public: public:
explicit RotateMovementGenerator(uint32 time, RotateDirection direction) : m_duration(time), m_maxDuration(time), m_direction(direction) {} explicit RotateMovementGenerator(uint32 time, RotateDirection direction) : m_duration(time), m_maxDuration(time), m_direction(direction) {}
void Initialize(Unit& owner); void Initialize(Unit*);
void Finalize(Unit& owner); void Finalize(Unit*);
void Reset(Unit& owner) { Initialize(owner); } void Reset(Unit* owner) { Initialize(owner); }
bool Update(Unit& owner, const uint32& time_diff); bool Update(Unit*, const uint32&);
MovementGeneratorType GetMovementGeneratorType() { return ROTATE_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return ROTATE_MOTION_TYPE; }
private: private:
@@ -55,10 +55,10 @@ class DistractMovementGenerator : public MovementGenerator
public: public:
explicit DistractMovementGenerator(uint32 timer) : m_timer(timer) {} explicit DistractMovementGenerator(uint32 timer) : m_timer(timer) {}
void Initialize(Unit& owner); void Initialize(Unit*);
void Finalize(Unit& owner); void Finalize(Unit*);
void Reset(Unit& owner) { Initialize(owner); } void Reset(Unit* owner) { Initialize(owner); }
bool Update(Unit& owner, const uint32& time_diff); bool Update(Unit*, const uint32&);
MovementGeneratorType GetMovementGeneratorType() { return DISTRACT_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return DISTRACT_MOTION_TYPE; }
private: private:
@@ -72,7 +72,7 @@ class AssistanceDistractMovementGenerator : public DistractMovementGenerator
DistractMovementGenerator(timer) {} DistractMovementGenerator(timer) {}
MovementGeneratorType GetMovementGeneratorType() { return ASSISTANCE_DISTRACT_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return ASSISTANCE_DISTRACT_MOTION_TYPE; }
void Finalize(Unit& unit); void Finalize(Unit*);
}; };
#endif #endif
@@ -27,12 +27,12 @@
//----- Point Movement Generator //----- Point Movement Generator
template<class T> template<class T>
void PointMovementGenerator<T>::Initialize(T &unit) void PointMovementGenerator<T>::Initialize(T* unit)
{ {
if (!unit.IsStopped()) if (!unit->IsStopped())
unit.StopMoving(); unit->StopMoving();
unit.AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE); unit->AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
i_recalculateSpeed = false; i_recalculateSpeed = false;
Movement::MoveSplineInit init(unit); Movement::MoveSplineInit init(unit);
init.MoveTo(i_x, i_y, i_z, m_generatePath); init.MoveTo(i_x, i_y, i_z, m_generatePath);
@@ -42,20 +42,20 @@ void PointMovementGenerator<T>::Initialize(T &unit)
} }
template<class T> template<class T>
bool PointMovementGenerator<T>::Update(T &unit, const uint32 & /*diff*/) bool PointMovementGenerator<T>::Update(T* unit, const uint32& /*diff*/)
{ {
if (!&unit) if (!unit)
return false; return false;
if (unit.HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED)) if (unit->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED))
{ {
unit.ClearUnitState(UNIT_STATE_ROAMING_MOVE); unit->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
return true; return true;
} }
unit.AddUnitState(UNIT_STATE_ROAMING_MOVE); unit->AddUnitState(UNIT_STATE_ROAMING_MOVE);
if (i_recalculateSpeed && !unit.movespline->Finalized()) if (i_recalculateSpeed && !unit->movespline->Finalized())
{ {
i_recalculateSpeed = false; i_recalculateSpeed = false;
Movement::MoveSplineInit init(unit); Movement::MoveSplineInit init(unit);
@@ -65,74 +65,74 @@ bool PointMovementGenerator<T>::Update(T &unit, const uint32 & /*diff*/)
init.Launch(); init.Launch();
} }
return !unit.movespline->Finalized(); return !unit->movespline->Finalized();
} }
template<class T> template<class T>
void PointMovementGenerator<T>::Finalize(T &unit) void PointMovementGenerator<T>::Finalize(T* unit)
{ {
if (unit.HasUnitState(UNIT_STATE_CHARGING)) if (unit->HasUnitState(UNIT_STATE_CHARGING))
unit.ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE); unit->ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
if (unit.movespline->Finalized()) if (unit->movespline->Finalized())
MovementInform(unit); MovementInform(unit);
} }
template<class T> template<class T>
void PointMovementGenerator<T>::Reset(T &unit) void PointMovementGenerator<T>::Reset(T* unit)
{ {
if (!unit.IsStopped()) if (!unit->IsStopped())
unit.StopMoving(); unit->StopMoving();
unit.AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE); unit->AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
} }
template<class T> template<class T>
void PointMovementGenerator<T>::MovementInform(T & /*unit*/) void PointMovementGenerator<T>::MovementInform(T* /*unit*/)
{ {
} }
template <> void PointMovementGenerator<Creature>::MovementInform(Creature &unit) template <> void PointMovementGenerator<Creature>::MovementInform(Creature* unit)
{ {
if (unit.AI()) if (unit->AI())
unit.AI()->MovementInform(POINT_MOTION_TYPE, id); unit->AI()->MovementInform(POINT_MOTION_TYPE, id);
} }
template void PointMovementGenerator<Player>::Initialize(Player&); template void PointMovementGenerator<Player>::Initialize(Player*);
template void PointMovementGenerator<Creature>::Initialize(Creature&); template void PointMovementGenerator<Creature>::Initialize(Creature*);
template void PointMovementGenerator<Player>::Finalize(Player&); template void PointMovementGenerator<Player>::Finalize(Player*);
template void PointMovementGenerator<Creature>::Finalize(Creature&); template void PointMovementGenerator<Creature>::Finalize(Creature*);
template void PointMovementGenerator<Player>::Reset(Player&); template void PointMovementGenerator<Player>::Reset(Player*);
template void PointMovementGenerator<Creature>::Reset(Creature&); template void PointMovementGenerator<Creature>::Reset(Creature*);
template bool PointMovementGenerator<Player>::Update(Player &, const uint32 &); template bool PointMovementGenerator<Player>::Update(Player*, const uint32&);
template bool PointMovementGenerator<Creature>::Update(Creature&, const uint32 &); template bool PointMovementGenerator<Creature>::Update(Creature*, const uint32&);
void AssistanceMovementGenerator::Finalize(Unit &unit) void AssistanceMovementGenerator::Finalize(Unit* unit)
{ {
unit.ToCreature()->SetNoCallAssistance(false); unit->ToCreature()->SetNoCallAssistance(false);
unit.ToCreature()->CallAssistance(); unit->ToCreature()->CallAssistance();
if (unit.isAlive()) if (unit->isAlive())
unit.GetMotionMaster()->MoveSeekAssistanceDistract(sWorld->getIntConfig(CONFIG_CREATURE_FAMILY_ASSISTANCE_DELAY)); unit->GetMotionMaster()->MoveSeekAssistanceDistract(sWorld->getIntConfig(CONFIG_CREATURE_FAMILY_ASSISTANCE_DELAY));
} }
bool EffectMovementGenerator::Update(Unit &unit, const uint32&) bool EffectMovementGenerator::Update(Unit* unit, const uint32&)
{ {
return !unit.movespline->Finalized(); return !unit->movespline->Finalized();
} }
void EffectMovementGenerator::Finalize(Unit &unit) void EffectMovementGenerator::Finalize(Unit* unit)
{ {
if (unit.GetTypeId() != TYPEID_UNIT) if (unit->GetTypeId() != TYPEID_UNIT)
return; return;
if (((Creature&)unit).AI()) if (unit->ToCreature()->AI())
((Creature&)unit).AI()->MovementInform(EFFECT_MOTION_TYPE, m_Id); unit->ToCreature()->AI()->MovementInform(EFFECT_MOTION_TYPE, m_Id);
// Need restore previous movement since we have no proper states system // Need restore previous movement since we have no proper states system
if (unit.isAlive() && !unit.HasUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_FLEEING)) if (unit->isAlive() && !unit->HasUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_FLEEING))
{ {
if (Unit* victim = unit.getVictim()) if (Unit* victim = unit->getVictim())
unit.GetMotionMaster()->MoveChase(victim); unit->GetMotionMaster()->MoveChase(victim);
else else
unit.GetMotionMaster()->Initialize(); unit->GetMotionMaster()->Initialize();
} }
} }
@@ -29,18 +29,18 @@ class PointMovementGenerator : public MovementGeneratorMedium< T, PointMovementG
PointMovementGenerator(uint32 _id, float _x, float _y, float _z, bool _generatePath, float _speed = 0.0f) : id(_id), PointMovementGenerator(uint32 _id, float _x, float _y, float _z, bool _generatePath, float _speed = 0.0f) : id(_id),
i_x(_x), i_y(_y), i_z(_z), m_generatePath(_generatePath), speed(_speed) {} i_x(_x), i_y(_y), i_z(_z), m_generatePath(_generatePath), speed(_speed) {}
void Initialize(T &); void Initialize(T*);
void Finalize(T &); void Finalize(T*);
void Reset(T &); void Reset(T*);
bool Update(T &, const uint32 &); bool Update(T*, const uint32 &);
void MovementInform(T &); void MovementInform(T*);
void unitSpeedChanged() { i_recalculateSpeed = true; } void unitSpeedChanged() { i_recalculateSpeed = true; }
MovementGeneratorType GetMovementGeneratorType() { return POINT_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return POINT_MOTION_TYPE; }
bool GetDestination(float& x, float& y, float& z) const { x=i_x; y=i_y; z=i_z; return true; } void GetDestination(float& x, float& y, float& z) const { x = i_x; y = i_y; z = i_z; }
private: private:
uint32 id; uint32 id;
float i_x, i_y, i_z; float i_x, i_y, i_z;
@@ -56,7 +56,7 @@ class AssistanceMovementGenerator : public PointMovementGenerator<Creature>
PointMovementGenerator<Creature>(0, _x, _y, _z, true) {} PointMovementGenerator<Creature>(0, _x, _y, _z, true) {}
MovementGeneratorType GetMovementGeneratorType() { return ASSISTANCE_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return ASSISTANCE_MOTION_TYPE; }
void Finalize(Unit &); void Finalize(Unit*);
}; };
// Does almost nothing - just doesn't allows previous movegen interrupt current effect. // Does almost nothing - just doesn't allows previous movegen interrupt current effect.
@@ -64,10 +64,10 @@ class EffectMovementGenerator : public MovementGenerator
{ {
public: public:
explicit EffectMovementGenerator(uint32 Id) : m_Id(Id) {} explicit EffectMovementGenerator(uint32 Id) : m_Id(Id) {}
void Initialize(Unit &) {} void Initialize(Unit*) {}
void Finalize(Unit &unit); void Finalize(Unit*);
void Reset(Unit &) {} void Reset(Unit*) {}
bool Update(Unit &u, const uint32&); bool Update(Unit*, const uint32&);
MovementGeneratorType GetMovementGeneratorType() { return EFFECT_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return EFFECT_MOTION_TYPE; }
private: private:
uint32 m_Id; uint32 m_Id;
@@ -33,16 +33,16 @@
#endif #endif
template<> template<>
void RandomMovementGenerator<Creature>::_setRandomLocation(Creature& creature) void RandomMovementGenerator<Creature>::_setRandomLocation(Creature* creature)
{ {
float respX, respY, respZ, respO, destX, destY, destZ, travelDistZ; float respX, respY, respZ, respO, destX, destY, destZ, travelDistZ;
creature.GetHomePosition(respX, respY, respZ, respO); creature->GetHomePosition(respX, respY, respZ, respO);
Map const* map = creature.GetBaseMap(); Map const* map = creature->GetBaseMap();
// For 2D/3D system selection // For 2D/3D system selection
//bool is_land_ok = creature.CanWalk(); // not used? //bool is_land_ok = creature.CanWalk(); // not used?
//bool is_water_ok = creature.CanSwim(); // not used? //bool is_water_ok = creature.CanSwim(); // not used?
bool is_air_ok = creature.CanFly(); bool is_air_ok = creature->CanFly();
const float angle = float(rand_norm()) * static_cast<float>(M_PI*2.0f); const float angle = float(rand_norm()) * static_cast<float>(M_PI*2.0f);
const float range = float(rand_norm()) * wander_distance; const float range = float(rand_norm()) * wander_distance;
@@ -77,17 +77,17 @@ void RandomMovementGenerator<Creature>::_setRandomLocation(Creature& creature)
// The fastest way to get an accurate result 90% of the time. // The fastest way to get an accurate result 90% of the time.
// Better result can be obtained like 99% accuracy with a ray light, but the cost is too high and the code is too long. // Better result can be obtained like 99% accuracy with a ray light, but the cost is too high and the code is too long.
destZ = map->GetHeight(creature.GetPhaseMask(), destX, destY, respZ+travelDistZ-2.0f, false); destZ = map->GetHeight(creature->GetPhaseMask(), destX, destY, respZ+travelDistZ-2.0f, false);
if (fabs(destZ - respZ) > travelDistZ) // Map check if (fabs(destZ - respZ) > travelDistZ) // Map check
{ {
// Vmap Horizontal or above // Vmap Horizontal or above
destZ = map->GetHeight(creature.GetPhaseMask(), destX, destY, respZ - 2.0f, true); destZ = map->GetHeight(creature->GetPhaseMask(), destX, destY, respZ - 2.0f, true);
if (fabs(destZ - respZ) > travelDistZ) if (fabs(destZ - respZ) > travelDistZ)
{ {
// Vmap Higher // Vmap Higher
destZ = map->GetHeight(creature.GetPhaseMask(), destX, destY, respZ+travelDistZ-2.0f, true); destZ = map->GetHeight(creature->GetPhaseMask(), destX, destY, respZ+travelDistZ-2.0f, true);
// let's forget this bad coords where a z cannot be find and retry at next tick // let's forget this bad coords where a z cannot be find and retry at next tick
if (fabs(destZ - respZ) > travelDistZ) if (fabs(destZ - respZ) > travelDistZ)
@@ -101,7 +101,7 @@ void RandomMovementGenerator<Creature>::_setRandomLocation(Creature& creature)
else else
i_nextMoveTime.Reset(urand(500, 10000)); i_nextMoveTime.Reset(urand(500, 10000));
creature.AddUnitState(UNIT_STATE_ROAMING_MOVE); creature->AddUnitState(UNIT_STATE_ROAMING_MOVE);
Movement::MoveSplineInit init(creature); Movement::MoveSplineInit init(creature);
init.MoveTo(destX, destY, destZ); init.MoveTo(destX, destY, destZ);
@@ -109,47 +109,47 @@ void RandomMovementGenerator<Creature>::_setRandomLocation(Creature& creature)
init.Launch(); init.Launch();
//Call for creature group update //Call for creature group update
if (creature.GetFormation() && creature.GetFormation()->getLeader() == &creature) if (creature->GetFormation() && creature->GetFormation()->getLeader() == creature)
creature.GetFormation()->LeaderMoveTo(destX, destY, destZ); creature->GetFormation()->LeaderMoveTo(destX, destY, destZ);
} }
template<> template<>
void RandomMovementGenerator<Creature>::Initialize(Creature &creature) void RandomMovementGenerator<Creature>::Initialize(Creature* creature)
{ {
if (!creature.isAlive()) if (!creature->isAlive())
return; return;
if (!wander_distance) if (!wander_distance)
wander_distance = creature.GetRespawnRadius(); wander_distance = creature->GetRespawnRadius();
creature.AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE); creature->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
_setRandomLocation(creature); _setRandomLocation(creature);
} }
template<> template<>
void RandomMovementGenerator<Creature>::Reset(Creature &creature) void RandomMovementGenerator<Creature>::Reset(Creature* creature)
{ {
Initialize(creature); Initialize(creature);
} }
template<> template<>
void RandomMovementGenerator<Creature>::Finalize(Creature &creature) void RandomMovementGenerator<Creature>::Finalize(Creature* creature)
{ {
creature.ClearUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE); creature->ClearUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
creature.SetWalk(false); creature->SetWalk(false);
} }
template<> template<>
bool RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 diff) bool RandomMovementGenerator<Creature>::Update(Creature* creature, const uint32 diff)
{ {
if (creature.HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED | UNIT_STATE_DISTRACTED)) if (creature->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED | UNIT_STATE_DISTRACTED))
{ {
i_nextMoveTime.Reset(0); // Expire the timer i_nextMoveTime.Reset(0); // Expire the timer
creature.ClearUnitState(UNIT_STATE_ROAMING_MOVE); creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
return true; return true;
} }
if (creature.movespline->Finalized()) if (creature->movespline->Finalized())
{ {
i_nextMoveTime.Update(diff); i_nextMoveTime.Update(diff);
if (i_nextMoveTime.Passed()) if (i_nextMoveTime.Passed())
@@ -159,14 +159,14 @@ bool RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32
} }
template<> template<>
bool RandomMovementGenerator<Creature>::GetResetPosition(Creature &creature, float& x, float& y, float& z) bool RandomMovementGenerator<Creature>::GetResetPosition(Creature* creature, float& x, float& y, float& z)
{ {
float radius; float radius;
creature.GetRespawnPosition(x, y, z, NULL, &radius); creature->GetRespawnPosition(x, y, z, NULL, &radius);
// use current if in range // use current if in range
if (creature.IsWithinDist2d(x,y,radius)) if (creature->IsWithinDist2d(x,y,radius))
creature.GetPosition(x,y,z); creature->GetPosition(x,y,z);
return true; return true;
} }
@@ -27,12 +27,12 @@ class RandomMovementGenerator : public MovementGeneratorMedium< T, RandomMovemen
public: public:
RandomMovementGenerator(float spawn_dist = 0.0f) : i_nextMoveTime(0), wander_distance(spawn_dist) {} RandomMovementGenerator(float spawn_dist = 0.0f) : i_nextMoveTime(0), wander_distance(spawn_dist) {}
void _setRandomLocation(T &); void _setRandomLocation(T*);
void Initialize(T &); void Initialize(T*);
void Finalize(T &); void Finalize(T*);
void Reset(T &); void Reset(T*);
bool Update(T &, const uint32); bool Update(T*, const uint32);
bool GetResetPosition(T&, float& x, float& y, float& z); bool GetResetPosition(T*, float& x, float& y, float& z);
MovementGeneratorType GetMovementGeneratorType() { return RANDOM_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return RANDOM_MOTION_TYPE; }
private: private:
TimeTrackerSmall i_nextMoveTime; TimeTrackerSmall i_nextMoveTime;
@@ -27,12 +27,12 @@
#include "Player.h" #include "Player.h"
template<class T, typename D> template<class T, typename D>
void TargetedMovementGeneratorMedium<T,D>::_setTargetLocation(T &owner) void TargetedMovementGeneratorMedium<T,D>::_setTargetLocation(T* owner)
{ {
if (!i_target.isValid() || !i_target->IsInWorld()) if (!i_target.isValid() || !i_target->IsInWorld())
return; return;
if (owner.HasUnitState(UNIT_STATE_NOT_MOVE)) if (owner->HasUnitState(UNIT_STATE_NOT_MOVE))
return; return;
float x, y, z; float x, y, z;
@@ -49,26 +49,26 @@ void TargetedMovementGeneratorMedium<T,D>::_setTargetLocation(T &owner)
// else // else
if (!i_offset) if (!i_offset)
{ {
if (i_target->IsWithinMeleeRange(&owner)) if (i_target->IsWithinMeleeRange(owner))
return; return;
// to nearest random contact position // to nearest random contact position
i_target->GetRandomContactPoint(&owner, x, y, z, 0, MELEE_RANGE - 0.5f); i_target->GetRandomContactPoint(owner, x, y, z, 0, MELEE_RANGE - 0.5f);
} }
else else
{ {
if (i_target->IsWithinDistInMap(&owner, i_offset + 1.0f)) if (i_target->IsWithinDistInMap(owner, i_offset + 1.0f))
return; return;
// to at i_offset distance from target and i_angle from target facing // to at i_offset distance from target and i_angle from target facing
i_target->GetClosePoint(x, y, z, owner.GetObjectSize(), i_offset, i_angle); i_target->GetClosePoint(x, y, z, owner->GetObjectSize(), i_offset, i_angle);
} }
if (!i_path) if (!i_path)
i_path = new PathGenerator(&owner); i_path = new PathGenerator(owner);
// allow pets following their master to cheat while generating paths // allow pets following their master to cheat while generating paths
bool forceDest = (owner.GetTypeId() == TYPEID_UNIT && ((Creature*)&owner)->isPet() bool forceDest = (owner->GetTypeId() == TYPEID_UNIT && owner->ToCreature()->isPet()
&& owner.HasUnitState(UNIT_STATE_FOLLOW)); && owner->HasUnitState(UNIT_STATE_FOLLOW));
i_path->CalculatePath(x, y, z, forceDest); i_path->CalculatePath(x, y, z, forceDest);
if (i_path->getPathType() & PATHFIND_NOPATH) if (i_path->getPathType() & PATHFIND_NOPATH)
return; return;
@@ -76,7 +76,7 @@ void TargetedMovementGeneratorMedium<T,D>::_setTargetLocation(T &owner)
D::_addUnitStateMove(owner); D::_addUnitStateMove(owner);
i_targetReached = false; i_targetReached = false;
i_recalculateTravel = false; i_recalculateTravel = false;
owner.AddUnitState(UNIT_STATE_CHASE); owner->AddUnitState(UNIT_STATE_CHASE);
Movement::MoveSplineInit init(owner); Movement::MoveSplineInit init(owner);
init.MovebyPath(i_path->getPath()); init.MovebyPath(i_path->getPath());
@@ -111,25 +111,25 @@ void TargetedMovementGeneratorMedium<Creature,FollowMovementGenerator<Creature>
} }
template<class T, typename D> template<class T, typename D>
bool TargetedMovementGeneratorMedium<T,D>::Update(T &owner, const uint32 & time_diff) bool TargetedMovementGeneratorMedium<T,D>::Update(T* owner, const uint32& time_diff)
{ {
if (!i_target.isValid() || !i_target->IsInWorld()) if (!i_target.isValid() || !i_target->IsInWorld())
return false; return false;
if (!&owner || !owner.isAlive()) if (!owner || !owner->isAlive())
return true; return true;
if (owner.HasUnitState(UNIT_STATE_NOT_MOVE)) if (owner->HasUnitState(UNIT_STATE_NOT_MOVE))
{ {
D::_clearUnitStateMove(owner); D::_clearUnitStateMove(owner);
return true; return true;
} }
// prevent movement while casting spells with cast time or channel time // prevent movement while casting spells with cast time or channel time
if (owner.HasUnitState(UNIT_STATE_CASTING)) if (owner->HasUnitState(UNIT_STATE_CASTING))
{ {
if (!owner.IsStopped()) if (!owner->IsStopped())
owner.StopMoving(); owner->StopMoving();
return true; return true;
} }
@@ -145,11 +145,11 @@ bool TargetedMovementGeneratorMedium<T,D>::Update(T &owner, const uint32 & time_
{ {
i_recheckDistance.Reset(100); i_recheckDistance.Reset(100);
//More distance let have better performance, less distance let have more sensitive reaction at target move. //More distance let have better performance, less distance let have more sensitive reaction at target move.
float allowed_dist = owner.GetCombatReach() + sWorld->getRate(RATE_TARGET_POS_RECALCULATION_RANGE); float allowed_dist = owner->GetCombatReach() + sWorld->getRate(RATE_TARGET_POS_RECALCULATION_RANGE);
G3D::Vector3 dest = owner.movespline->FinalDestination(); G3D::Vector3 dest = owner->movespline->FinalDestination();
bool targetMoved = false; bool targetMoved = false;
if (owner.GetTypeId() == TYPEID_UNIT && ((Creature*)&owner)->CanFly()) if (owner->GetTypeId() == TYPEID_UNIT && owner->ToCreature()->CanFly())
targetMoved = !i_target->IsWithinDist3d(dest.x, dest.y, dest.z, allowed_dist); targetMoved = !i_target->IsWithinDist3d(dest.x, dest.y, dest.z, allowed_dist);
else else
targetMoved = !i_target->IsWithinDist2d(dest.x, dest.y, allowed_dist); targetMoved = !i_target->IsWithinDist2d(dest.x, dest.y, allowed_dist);
@@ -158,11 +158,11 @@ bool TargetedMovementGeneratorMedium<T,D>::Update(T &owner, const uint32 & time_
_setTargetLocation(owner); _setTargetLocation(owner);
} }
if (owner.movespline->Finalized()) if (owner->movespline->Finalized())
{ {
static_cast<D*>(this)->MovementInform(owner); static_cast<D*>(this)->MovementInform(owner);
if (i_angle == 0.f && !owner.HasInArc(0.01f, i_target.getTarget())) if (i_angle == 0.f && !owner->HasInArc(0.01f, i_target.getTarget()))
owner.SetInFront(i_target.getTarget()); owner->SetInFront(i_target.getTarget());
if (!i_targetReached) if (!i_targetReached)
{ {
@@ -180,50 +180,50 @@ bool TargetedMovementGeneratorMedium<T,D>::Update(T &owner, const uint32 & time_
//-----------------------------------------------// //-----------------------------------------------//
template<class T> template<class T>
void ChaseMovementGenerator<T>::_reachTarget(T &owner) void ChaseMovementGenerator<T>::_reachTarget(T* owner)
{ {
if (owner.IsWithinMeleeRange(this->i_target.getTarget())) if (owner->IsWithinMeleeRange(this->i_target.getTarget()))
owner.Attack(this->i_target.getTarget(),true); owner->Attack(this->i_target.getTarget(),true);
} }
template<> template<>
void ChaseMovementGenerator<Player>::Initialize(Player &owner) void ChaseMovementGenerator<Player>::Initialize(Player* owner)
{ {
owner.AddUnitState(UNIT_STATE_CHASE|UNIT_STATE_CHASE_MOVE); owner->AddUnitState(UNIT_STATE_CHASE | UNIT_STATE_CHASE_MOVE);
_setTargetLocation(owner); _setTargetLocation(owner);
} }
template<> template<>
void ChaseMovementGenerator<Creature>::Initialize(Creature &owner) void ChaseMovementGenerator<Creature>::Initialize(Creature* owner)
{ {
owner.SetWalk(false); owner->SetWalk(false);
owner.AddUnitState(UNIT_STATE_CHASE|UNIT_STATE_CHASE_MOVE); owner->AddUnitState(UNIT_STATE_CHASE | UNIT_STATE_CHASE_MOVE);
_setTargetLocation(owner); _setTargetLocation(owner);
} }
template<class T> template<class T>
void ChaseMovementGenerator<T>::Finalize(T &owner) void ChaseMovementGenerator<T>::Finalize(T* owner)
{ {
owner.ClearUnitState(UNIT_STATE_CHASE|UNIT_STATE_CHASE_MOVE); owner->ClearUnitState(UNIT_STATE_CHASE | UNIT_STATE_CHASE_MOVE);
} }
template<class T> template<class T>
void ChaseMovementGenerator<T>::Reset(T &owner) void ChaseMovementGenerator<T>::Reset(T* owner)
{ {
Initialize(owner); Initialize(owner);
} }
template<class T> template<class T>
void ChaseMovementGenerator<T>::MovementInform(T & /*unit*/) void ChaseMovementGenerator<T>::MovementInform(T* /*unit*/)
{ {
} }
template<> template<>
void ChaseMovementGenerator<Creature>::MovementInform(Creature &unit) void ChaseMovementGenerator<Creature>::MovementInform(Creature* unit)
{ {
// Pass back the GUIDLow of the target. If it is pet's owner then PetAI will handle // Pass back the GUIDLow of the target. If it is pet's owner then PetAI will handle
if (unit.AI()) if (unit->AI())
unit.AI()->MovementInform(CHASE_MOTION_TYPE, i_target.getTarget()->GetGUIDLow()); unit->AI()->MovementInform(CHASE_MOTION_TYPE, i_target.getTarget()->GetGUIDLow());
} }
//-----------------------------------------------// //-----------------------------------------------//
@@ -240,85 +240,85 @@ bool FollowMovementGenerator<Player>::EnableWalking() const
} }
template<> template<>
void FollowMovementGenerator<Player>::_updateSpeed(Player &/*u*/) void FollowMovementGenerator<Player>::_updateSpeed(Player* /*u*/)
{ {
// nothing to do for Player // nothing to do for Player
} }
template<> template<>
void FollowMovementGenerator<Creature>::_updateSpeed(Creature &u) void FollowMovementGenerator<Creature>::_updateSpeed(Creature* u)
{ {
// pet only sync speed with owner // pet only sync speed with owner
if (!((Creature&)u).isPet() || !i_target.isValid() || i_target->GetGUID() != u.GetOwnerGUID()) if (!u->isPet() || !i_target.isValid() || i_target->GetGUID() != u->GetOwnerGUID())
return; return;
u.UpdateSpeed(MOVE_RUN,true); u->UpdateSpeed(MOVE_RUN,true);
u.UpdateSpeed(MOVE_WALK,true); u->UpdateSpeed(MOVE_WALK,true);
u.UpdateSpeed(MOVE_SWIM,true); u->UpdateSpeed(MOVE_SWIM,true);
} }
template<> template<>
void FollowMovementGenerator<Player>::Initialize(Player &owner) void FollowMovementGenerator<Player>::Initialize(Player* owner)
{ {
owner.AddUnitState(UNIT_STATE_FOLLOW|UNIT_STATE_FOLLOW_MOVE); owner->AddUnitState(UNIT_STATE_FOLLOW | UNIT_STATE_FOLLOW_MOVE);
_updateSpeed(owner); _updateSpeed(owner);
_setTargetLocation(owner); _setTargetLocation(owner);
} }
template<> template<>
void FollowMovementGenerator<Creature>::Initialize(Creature &owner) void FollowMovementGenerator<Creature>::Initialize(Creature* owner)
{ {
owner.AddUnitState(UNIT_STATE_FOLLOW|UNIT_STATE_FOLLOW_MOVE); owner->AddUnitState(UNIT_STATE_FOLLOW | UNIT_STATE_FOLLOW_MOVE);
_updateSpeed(owner); _updateSpeed(owner);
_setTargetLocation(owner); _setTargetLocation(owner);
} }
template<class T> template<class T>
void FollowMovementGenerator<T>::Finalize(T &owner) void FollowMovementGenerator<T>::Finalize(T* owner)
{ {
owner.ClearUnitState(UNIT_STATE_FOLLOW|UNIT_STATE_FOLLOW_MOVE); owner->ClearUnitState(UNIT_STATE_FOLLOW | UNIT_STATE_FOLLOW_MOVE);
_updateSpeed(owner); _updateSpeed(owner);
} }
template<class T> template<class T>
void FollowMovementGenerator<T>::Reset(T &owner) void FollowMovementGenerator<T>::Reset(T* owner)
{ {
Initialize(owner); Initialize(owner);
} }
template<class T> template<class T>
void FollowMovementGenerator<T>::MovementInform(T & /*unit*/) void FollowMovementGenerator<T>::MovementInform(T* /*unit*/)
{ {
} }
template<> template<>
void FollowMovementGenerator<Creature>::MovementInform(Creature &unit) void FollowMovementGenerator<Creature>::MovementInform(Creature* unit)
{ {
// Pass back the GUIDLow of the target. If it is pet's owner then PetAI will handle // Pass back the GUIDLow of the target. If it is pet's owner then PetAI will handle
if (unit.AI()) if (unit->AI())
unit.AI()->MovementInform(FOLLOW_MOTION_TYPE, i_target.getTarget()->GetGUIDLow()); unit->AI()->MovementInform(FOLLOW_MOTION_TYPE, i_target.getTarget()->GetGUIDLow());
} }
//-----------------------------------------------// //-----------------------------------------------//
template void TargetedMovementGeneratorMedium<Player,ChaseMovementGenerator<Player> >::_setTargetLocation(Player &); template void TargetedMovementGeneratorMedium<Player,ChaseMovementGenerator<Player> >::_setTargetLocation(Player*);
template void TargetedMovementGeneratorMedium<Player,FollowMovementGenerator<Player> >::_setTargetLocation(Player &); template void TargetedMovementGeneratorMedium<Player,FollowMovementGenerator<Player> >::_setTargetLocation(Player*);
template void TargetedMovementGeneratorMedium<Creature,ChaseMovementGenerator<Creature> >::_setTargetLocation(Creature &); template void TargetedMovementGeneratorMedium<Creature,ChaseMovementGenerator<Creature> >::_setTargetLocation(Creature*);
template void TargetedMovementGeneratorMedium<Creature,FollowMovementGenerator<Creature> >::_setTargetLocation(Creature &); template void TargetedMovementGeneratorMedium<Creature,FollowMovementGenerator<Creature> >::_setTargetLocation(Creature*);
template bool TargetedMovementGeneratorMedium<Player,ChaseMovementGenerator<Player> >::Update(Player &, const uint32 &); template bool TargetedMovementGeneratorMedium<Player,ChaseMovementGenerator<Player> >::Update(Player*, const uint32&);
template bool TargetedMovementGeneratorMedium<Player,FollowMovementGenerator<Player> >::Update(Player &, const uint32 &); template bool TargetedMovementGeneratorMedium<Player,FollowMovementGenerator<Player> >::Update(Player*, const uint32&);
template bool TargetedMovementGeneratorMedium<Creature,ChaseMovementGenerator<Creature> >::Update(Creature &, const uint32 &); template bool TargetedMovementGeneratorMedium<Creature,ChaseMovementGenerator<Creature> >::Update(Creature*, const uint32&);
template bool TargetedMovementGeneratorMedium<Creature,FollowMovementGenerator<Creature> >::Update(Creature &, const uint32 &); template bool TargetedMovementGeneratorMedium<Creature,FollowMovementGenerator<Creature> >::Update(Creature*, const uint32&);
template void ChaseMovementGenerator<Player>::_reachTarget(Player &); template void ChaseMovementGenerator<Player>::_reachTarget(Player*);
template void ChaseMovementGenerator<Creature>::_reachTarget(Creature &); template void ChaseMovementGenerator<Creature>::_reachTarget(Creature*);
template void ChaseMovementGenerator<Player>::Finalize(Player &); template void ChaseMovementGenerator<Player>::Finalize(Player*);
template void ChaseMovementGenerator<Creature>::Finalize(Creature &); template void ChaseMovementGenerator<Creature>::Finalize(Creature*);
template void ChaseMovementGenerator<Player>::Reset(Player &); template void ChaseMovementGenerator<Player>::Reset(Player*);
template void ChaseMovementGenerator<Creature>::Reset(Creature &); template void ChaseMovementGenerator<Creature>::Reset(Creature*);
template void ChaseMovementGenerator<Player>::MovementInform(Player &unit); template void ChaseMovementGenerator<Player>::MovementInform(Player*);
template void FollowMovementGenerator<Player>::Finalize(Player &); template void FollowMovementGenerator<Player>::Finalize(Player*);
template void FollowMovementGenerator<Creature>::Finalize(Creature &); template void FollowMovementGenerator<Creature>::Finalize(Creature*);
template void FollowMovementGenerator<Player>::Reset(Player &); template void FollowMovementGenerator<Player>::Reset(Player*);
template void FollowMovementGenerator<Creature>::Reset(Creature &); template void FollowMovementGenerator<Creature>::Reset(Creature*);
template void FollowMovementGenerator<Player>::MovementInform(Player &unit); template void FollowMovementGenerator<Player>::MovementInform(Player*);
@@ -28,7 +28,7 @@
class TargetedMovementGeneratorBase class TargetedMovementGeneratorBase
{ {
public: public:
TargetedMovementGeneratorBase(Unit &target) { i_target.link(&target, this); } TargetedMovementGeneratorBase(Unit* target) { i_target.link(target, this); }
void stopFollowing() { } void stopFollowing() { }
protected: protected:
FollowerReference i_target; FollowerReference i_target;
@@ -38,7 +38,7 @@ template<class T, typename D>
class TargetedMovementGeneratorMedium : public MovementGeneratorMedium< T, D >, public TargetedMovementGeneratorBase class TargetedMovementGeneratorMedium : public MovementGeneratorMedium< T, D >, public TargetedMovementGeneratorBase
{ {
protected: protected:
TargetedMovementGeneratorMedium(Unit &target, float offset, float angle) : TargetedMovementGeneratorMedium(Unit* target, float offset, float angle) :
TargetedMovementGeneratorBase(target), i_recheckDistance(0), i_path(NULL), TargetedMovementGeneratorBase(target), i_recheckDistance(0), i_path(NULL),
i_offset(offset), i_angle(angle), i_offset(offset), i_angle(angle),
i_recalculateTravel(false), i_targetReached(false) i_recalculateTravel(false), i_targetReached(false)
@@ -47,14 +47,14 @@ class TargetedMovementGeneratorMedium : public MovementGeneratorMedium< T, D >,
~TargetedMovementGeneratorMedium() { delete i_path; } ~TargetedMovementGeneratorMedium() { delete i_path; }
public: public:
bool Update(T &, const uint32 &); bool Update(T*, const uint32 &);
Unit* GetTarget() const { return i_target.getTarget(); } Unit* GetTarget() const { return i_target.getTarget(); }
void unitSpeedChanged() { i_recalculateTravel = true; } void unitSpeedChanged() { i_recalculateTravel = true; }
void UpdateFinalDistance(float fDistance); void UpdateFinalDistance(float fDistance);
bool IsReachable() const { return (i_path) ? (i_path->getPathType() & PATHFIND_NORMAL) : true; } bool IsReachable() const { return (i_path) ? (i_path->getPathType() & PATHFIND_NORMAL) : true; }
protected: protected:
void _setTargetLocation(T &); void _setTargetLocation(T*);
TimeTrackerSmall i_recheckDistance; TimeTrackerSmall i_recheckDistance;
float i_offset; float i_offset;
@@ -68,50 +68,50 @@ template<class T>
class ChaseMovementGenerator : public TargetedMovementGeneratorMedium<T, ChaseMovementGenerator<T> > class ChaseMovementGenerator : public TargetedMovementGeneratorMedium<T, ChaseMovementGenerator<T> >
{ {
public: public:
ChaseMovementGenerator(Unit &target) ChaseMovementGenerator(Unit* target)
: TargetedMovementGeneratorMedium<T, ChaseMovementGenerator<T> >(target) {} : TargetedMovementGeneratorMedium<T, ChaseMovementGenerator<T> >(target) {}
ChaseMovementGenerator(Unit &target, float offset, float angle) ChaseMovementGenerator(Unit* target, float offset, float angle)
: TargetedMovementGeneratorMedium<T, ChaseMovementGenerator<T> >(target, offset, angle) {} : TargetedMovementGeneratorMedium<T, ChaseMovementGenerator<T> >(target, offset, angle) {}
~ChaseMovementGenerator() {} ~ChaseMovementGenerator() {}
MovementGeneratorType GetMovementGeneratorType() { return CHASE_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return CHASE_MOTION_TYPE; }
void Initialize(T &); void Initialize(T*);
void Finalize(T &); void Finalize(T*);
void Reset(T &); void Reset(T*);
void MovementInform(T &); void MovementInform(T*);
static void _clearUnitStateMove(T &u) { u.ClearUnitState(UNIT_STATE_CHASE_MOVE); } static void _clearUnitStateMove(T* u) { u->ClearUnitState(UNIT_STATE_CHASE_MOVE); }
static void _addUnitStateMove(T &u) { u.AddUnitState(UNIT_STATE_CHASE_MOVE); } static void _addUnitStateMove(T* u) { u->AddUnitState(UNIT_STATE_CHASE_MOVE); }
bool EnableWalking() const { return false;} bool EnableWalking() const { return false;}
bool _lostTarget(T &u) const { return u.getVictim() != this->GetTarget(); } bool _lostTarget(T* u) const { return u->getVictim() != GetTarget(); }
void _reachTarget(T &); void _reachTarget(T*);
}; };
template<class T> template<class T>
class FollowMovementGenerator : public TargetedMovementGeneratorMedium<T, FollowMovementGenerator<T> > class FollowMovementGenerator : public TargetedMovementGeneratorMedium<T, FollowMovementGenerator<T> >
{ {
public: public:
FollowMovementGenerator(Unit &target) FollowMovementGenerator(Unit* target)
: TargetedMovementGeneratorMedium<T, FollowMovementGenerator<T> >(target){} : TargetedMovementGeneratorMedium<T, FollowMovementGenerator<T> >(target){}
FollowMovementGenerator(Unit &target, float offset, float angle) FollowMovementGenerator(Unit* target, float offset, float angle)
: TargetedMovementGeneratorMedium<T, FollowMovementGenerator<T> >(target, offset, angle) {} : TargetedMovementGeneratorMedium<T, FollowMovementGenerator<T> >(target, offset, angle) {}
~FollowMovementGenerator() {} ~FollowMovementGenerator() {}
MovementGeneratorType GetMovementGeneratorType() { return FOLLOW_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return FOLLOW_MOTION_TYPE; }
void Initialize(T &); void Initialize(T*);
void Finalize(T &); void Finalize(T*);
void Reset(T &); void Reset(T*);
void MovementInform(T &); void MovementInform(T*);
static void _clearUnitStateMove(T &u) { u.ClearUnitState(UNIT_STATE_FOLLOW_MOVE); } static void _clearUnitStateMove(T* u) { u->ClearUnitState(UNIT_STATE_FOLLOW_MOVE); }
static void _addUnitStateMove(T &u) { u.AddUnitState(UNIT_STATE_FOLLOW_MOVE); } static void _addUnitStateMove(T* u) { u->AddUnitState(UNIT_STATE_FOLLOW_MOVE); }
bool EnableWalking() const; bool EnableWalking() const;
bool _lostTarget(T &) const { return false; } bool _lostTarget(T*) const { return false; }
void _reachTarget(T &) {} void _reachTarget(T*) {}
private: private:
void _updateSpeed(T &u); void _updateSpeed(T* u);
}; };
#endif #endif
@@ -31,64 +31,64 @@
#include "MoveSplineInit.h" #include "MoveSplineInit.h"
#include "MoveSpline.h" #include "MoveSpline.h"
void WaypointMovementGenerator<Creature>::LoadPath(Creature &creature) void WaypointMovementGenerator<Creature>::LoadPath(Creature* creature)
{ {
if (!path_id) if (!path_id)
path_id = creature.GetWaypointPath(); path_id = creature->GetWaypointPath();
i_path = sWaypointMgr->GetPath(path_id); i_path = sWaypointMgr->GetPath(path_id);
if (!i_path) if (!i_path)
{ {
// No movement found for entry // No movement found for entry
sLog->outError(LOG_FILTER_SQL, "WaypointMovementGenerator::LoadPath: creature %s (Entry: %u GUID: %u) doesn't have waypoint path id: %u", creature.GetName(), creature.GetEntry(), creature.GetGUIDLow(), path_id); sLog->outError(LOG_FILTER_SQL, "WaypointMovementGenerator::LoadPath: creature %s (Entry: %u GUID: %u) doesn't have waypoint path id: %u", creature->GetName(), creature->GetEntry(), creature->GetGUIDLow(), path_id);
return; return;
} }
StartMoveNow(creature); StartMoveNow(creature);
} }
void WaypointMovementGenerator<Creature>::Initialize(Creature &creature) void WaypointMovementGenerator<Creature>::Initialize(Creature* creature)
{ {
LoadPath(creature); LoadPath(creature);
creature.AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE); creature->AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
} }
void WaypointMovementGenerator<Creature>::Finalize(Creature &creature) void WaypointMovementGenerator<Creature>::Finalize(Creature* creature)
{ {
creature.ClearUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE); creature->ClearUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
creature.SetWalk(false); creature->SetWalk(false);
} }
void WaypointMovementGenerator<Creature>::Reset(Creature &creature) void WaypointMovementGenerator<Creature>::Reset(Creature* creature)
{ {
creature.AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE); creature->AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
StartMoveNow(creature); StartMoveNow(creature);
} }
void WaypointMovementGenerator<Creature>::OnArrived(Creature& creature) void WaypointMovementGenerator<Creature>::OnArrived(Creature* creature)
{ {
if (!i_path || i_path->empty()) if (!i_path || i_path->empty())
return; return;
if (m_isArrivalDone) if (m_isArrivalDone)
return; return;
creature.ClearUnitState(UNIT_STATE_ROAMING_MOVE); creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
m_isArrivalDone = true; m_isArrivalDone = true;
if (i_path->at(i_currentNode)->event_id && urand(0, 99) < i_path->at(i_currentNode)->event_chance) if (i_path->at(i_currentNode)->event_id && urand(0, 99) < i_path->at(i_currentNode)->event_chance)
{ {
sLog->outDebug(LOG_FILTER_MAPSCRIPTS, "Creature movement start script %u at point %u for "UI64FMTD".", i_path->at(i_currentNode)->event_id, i_currentNode, creature.GetGUID()); sLog->outDebug(LOG_FILTER_MAPSCRIPTS, "Creature movement start script %u at point %u for "UI64FMTD".", i_path->at(i_currentNode)->event_id, i_currentNode, creature->GetGUID());
creature.GetMap()->ScriptsStart(sWaypointScripts, i_path->at(i_currentNode)->event_id, &creature, NULL); creature->GetMap()->ScriptsStart(sWaypointScripts, i_path->at(i_currentNode)->event_id, creature, NULL);
} }
// Inform script // Inform script
MovementInform(creature); MovementInform(creature);
creature.UpdateWaypointID(i_currentNode); creature->UpdateWaypointID(i_currentNode);
Stop(i_path->at(i_currentNode)->delay); Stop(i_path->at(i_currentNode)->delay);
} }
bool WaypointMovementGenerator<Creature>::StartMove(Creature &creature) bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature)
{ {
if (!i_path || i_path->empty()) if (!i_path || i_path->empty())
return false; return false;
@@ -99,8 +99,8 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature &creature)
{ {
if ((i_currentNode == i_path->size() - 1) && !repeating) // If that's our last waypoint if ((i_currentNode == i_path->size() - 1) && !repeating) // If that's our last waypoint
{ {
creature.SetHomePosition(i_path->at(i_currentNode)->x, i_path->at(i_currentNode)->y, i_path->at(i_currentNode)->z, creature.GetOrientation()); creature->SetHomePosition(i_path->at(i_currentNode)->x, i_path->at(i_currentNode)->y, i_path->at(i_currentNode)->z, creature->GetOrientation());
creature.GetMotionMaster()->Initialize(); creature->GetMotionMaster()->Initialize();
return false; return false;
} }
@@ -111,7 +111,7 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature &creature)
m_isArrivalDone = false; m_isArrivalDone = false;
creature.AddUnitState(UNIT_STATE_ROAMING_MOVE); creature->AddUnitState(UNIT_STATE_ROAMING_MOVE);
Movement::MoveSplineInit init(creature); Movement::MoveSplineInit init(creature);
init.MoveTo(node->x, node->y, node->z); init.MoveTo(node->x, node->y, node->z);
@@ -124,19 +124,19 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature &creature)
init.Launch(); init.Launch();
//Call for creature group update //Call for creature group update
if (creature.GetFormation() && creature.GetFormation()->getLeader() == &creature) if (creature->GetFormation() && creature->GetFormation()->getLeader() == creature)
creature.GetFormation()->LeaderMoveTo(node->x, node->y, node->z); creature->GetFormation()->LeaderMoveTo(node->x, node->y, node->z);
return true; return true;
} }
bool WaypointMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff) bool WaypointMovementGenerator<Creature>::Update(Creature* creature, const uint32& diff)
{ {
// Waypoint movement can be switched on/off // Waypoint movement can be switched on/off
// This is quite handy for escort quests and other stuff // This is quite handy for escort quests and other stuff
if (creature.HasUnitState(UNIT_STATE_NOT_MOVE)) if (creature->HasUnitState(UNIT_STATE_NOT_MOVE))
{ {
creature.ClearUnitState(UNIT_STATE_ROAMING_MOVE); creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
return true; return true;
} }
// prevent a crash at empty waypoint path. // prevent a crash at empty waypoint path.
@@ -150,9 +150,9 @@ bool WaypointMovementGenerator<Creature>::Update(Creature &creature, const uint3
} }
else else
{ {
if (creature.IsStopped()) if (creature->IsStopped())
Stop(STOP_TIME_FOR_PLAYER); Stop(STOP_TIME_FOR_PLAYER);
else if (creature.movespline->Finalized()) else if (creature->movespline->Finalized())
{ {
OnArrived(creature); OnArrived(creature);
return StartMove(creature); return StartMove(creature);
@@ -161,13 +161,13 @@ bool WaypointMovementGenerator<Creature>::Update(Creature &creature, const uint3
return true; return true;
} }
void WaypointMovementGenerator<Creature>::MovementInform(Creature &creature) void WaypointMovementGenerator<Creature>::MovementInform(Creature* creature)
{ {
if (creature.AI()) if (creature->AI())
creature.AI()->MovementInform(WAYPOINT_MOTION_TYPE, i_currentNode); creature->AI()->MovementInform(WAYPOINT_MOTION_TYPE, i_currentNode);
} }
bool WaypointMovementGenerator<Creature>::GetResetPosition(Creature&, float& x, float& y, float& z) bool WaypointMovementGenerator<Creature>::GetResetPosition(Creature*, float& x, float& y, float& z)
{ {
// prevent a crash at empty waypoint path. // prevent a crash at empty waypoint path.
if (!i_path || i_path->empty()) if (!i_path || i_path->empty())
@@ -196,37 +196,37 @@ uint32 FlightPathMovementGenerator::GetPathAtMapEnd() const
return i_path->size(); return i_path->size();
} }
void FlightPathMovementGenerator::Initialize(Player &player) void FlightPathMovementGenerator::Initialize(Player* player)
{ {
Reset(player); Reset(player);
InitEndGridInfo(); InitEndGridInfo();
} }
void FlightPathMovementGenerator::Finalize(Player& player) void FlightPathMovementGenerator::Finalize(Player* player)
{ {
// remove flag to prevent send object build movement packets for flight state and crash (movement generator already not at top of stack) // remove flag to prevent send object build movement packets for flight state and crash (movement generator already not at top of stack)
player.ClearUnitState(UNIT_STATE_IN_FLIGHT); player->ClearUnitState(UNIT_STATE_IN_FLIGHT);
player.Dismount(); player->Dismount();
player.RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE | UNIT_FLAG_TAXI_FLIGHT); player->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE | UNIT_FLAG_TAXI_FLIGHT);
if (player.m_taxi.empty()) if (player->m_taxi.empty())
{ {
player.getHostileRefManager().setOnlineOfflineState(true); player->getHostileRefManager().setOnlineOfflineState(true);
// update z position to ground and orientation for landing point // update z position to ground and orientation for landing point
// this prevent cheating with landing point at lags // this prevent cheating with landing point at lags
// when client side flight end early in comparison server side // when client side flight end early in comparison server side
player.StopMoving(); player->StopMoving();
} }
} }
#define PLAYER_FLIGHT_SPEED 32.0f #define PLAYER_FLIGHT_SPEED 32.0f
void FlightPathMovementGenerator::Reset(Player & player) void FlightPathMovementGenerator::Reset(Player* player)
{ {
player.getHostileRefManager().setOnlineOfflineState(false); player->getHostileRefManager().setOnlineOfflineState(false);
player.AddUnitState(UNIT_STATE_IN_FLIGHT); player->AddUnitState(UNIT_STATE_IN_FLIGHT);
player.SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE | UNIT_FLAG_TAXI_FLIGHT); player->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE | UNIT_FLAG_TAXI_FLIGHT);
Movement::MoveSplineInit init(player); Movement::MoveSplineInit init(player);
uint32 end = GetPathAtMapEnd(); uint32 end = GetPathAtMapEnd();
@@ -241,9 +241,9 @@ void FlightPathMovementGenerator::Reset(Player & player)
init.Launch(); init.Launch();
} }
bool FlightPathMovementGenerator::Update(Player &player, const uint32& /*diff*/) bool FlightPathMovementGenerator::Update(Player* player, const uint32& /*diff*/)
{ {
uint32 pointId = (uint32)player.movespline->currentPathIdx(); uint32 pointId = (uint32)player->movespline->currentPathIdx();
if (pointId > i_currentNode) if (pointId > i_currentNode)
{ {
bool departureEvent = true; bool departureEvent = true;
@@ -279,16 +279,16 @@ void FlightPathMovementGenerator::SetCurrentNodeAfterTeleport()
} }
} }
void FlightPathMovementGenerator::DoEventIfAny(Player& player, TaxiPathNodeEntry const& node, bool departure) void FlightPathMovementGenerator::DoEventIfAny(Player* player, TaxiPathNodeEntry const& node, bool departure)
{ {
if (uint32 eventid = departure ? node.departureEventID : node.arrivalEventID) if (uint32 eventid = departure ? node.departureEventID : node.arrivalEventID)
{ {
sLog->outDebug(LOG_FILTER_MAPSCRIPTS, "Taxi %s event %u of node %u of path %u for player %s", departure ? "departure" : "arrival", eventid, node.index, node.path, player.GetName()); sLog->outDebug(LOG_FILTER_MAPSCRIPTS, "Taxi %s event %u of node %u of path %u for player %s", departure ? "departure" : "arrival", eventid, node.index, node.path, player->GetName());
player.GetMap()->ScriptsStart(sEventScripts, eventid, &player, &player); player->GetMap()->ScriptsStart(sEventScripts, eventid, player, player);
} }
} }
bool FlightPathMovementGenerator::GetResetPosition(Player&, float& x, float& y, float& z) bool FlightPathMovementGenerator::GetResetPosition(Player*, float& x, float& y, float& z)
{ {
const TaxiPathNodeEntry& node = (*i_path)[i_currentNode]; const TaxiPathNodeEntry& node = (*i_path)[i_currentNode];
x = node.x; y = node.y; z = node.z; x = node.x; y = node.y; z = node.z;
@@ -65,19 +65,19 @@ class WaypointMovementGenerator<Creature> : public MovementGeneratorMedium< Crea
WaypointMovementGenerator(uint32 _path_id = 0, bool _repeating = true) WaypointMovementGenerator(uint32 _path_id = 0, bool _repeating = true)
: i_nextMoveTime(0), m_isArrivalDone(false), path_id(_path_id), repeating(_repeating) {} : i_nextMoveTime(0), m_isArrivalDone(false), path_id(_path_id), repeating(_repeating) {}
~WaypointMovementGenerator() { i_path = NULL; } ~WaypointMovementGenerator() { i_path = NULL; }
void Initialize(Creature &); void Initialize(Creature*);
void Finalize(Creature &); void Finalize(Creature*);
void Reset(Creature &); void Reset(Creature*);
bool Update(Creature &, const uint32 &diff); bool Update(Creature*, const uint32 &diff);
void MovementInform(Creature &); void MovementInform(Creature*);
MovementGeneratorType GetMovementGeneratorType() { return WAYPOINT_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return WAYPOINT_MOTION_TYPE; }
// now path movement implmementation // now path movement implmementation
void LoadPath(Creature &c); void LoadPath(Creature*);
bool GetResetPosition(Creature&, float& x, float& y, float& z); bool GetResetPosition(Creature*, float& x, float& y, float& z);
private: private:
@@ -91,10 +91,10 @@ class WaypointMovementGenerator<Creature> : public MovementGeneratorMedium< Crea
return i_nextMoveTime.Passed(); return i_nextMoveTime.Passed();
} }
void OnArrived(Creature&); void OnArrived(Creature*);
bool StartMove(Creature&); bool StartMove(Creature*);
void StartMoveNow(Creature& creature) void StartMoveNow(Creature* creature)
{ {
i_nextMoveTime.Reset(0); i_nextMoveTime.Reset(0);
StartMove(creature); StartMove(creature);
@@ -118,10 +118,10 @@ class FlightPathMovementGenerator : public MovementGeneratorMedium< Player, Flig
i_path = &pathnodes; i_path = &pathnodes;
i_currentNode = startNode; i_currentNode = startNode;
} }
void Initialize(Player &); void Initialize(Player*);
void Reset(Player &); void Reset(Player*);
void Finalize(Player &); void Finalize(Player*);
bool Update(Player &, const uint32&); bool Update(Player*, const uint32&);
MovementGeneratorType GetMovementGeneratorType() { return FLIGHT_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return FLIGHT_MOTION_TYPE; }
TaxiPathNodeList const& GetPath() { return *i_path; } TaxiPathNodeList const& GetPath() { return *i_path; }
@@ -129,9 +129,9 @@ class FlightPathMovementGenerator : public MovementGeneratorMedium< Player, Flig
bool HasArrived() const { return (i_currentNode >= i_path->size()); } bool HasArrived() const { return (i_currentNode >= i_path->size()); }
void SetCurrentNodeAfterTeleport(); void SetCurrentNodeAfterTeleport();
void SkipCurrentNode() { ++i_currentNode; } void SkipCurrentNode() { ++i_currentNode; }
void DoEventIfAny(Player& player, TaxiPathNodeEntry const& node, bool departure); void DoEventIfAny(Player* player, TaxiPathNodeEntry const& node, bool departure);
bool GetResetPosition(Player&, float& x, float& y, float& z); bool GetResetPosition(Player*, float& x, float& y, float& z);
void InitEndGridInfo(); void InitEndGridInfo();
void PreloadEndGrid(); void PreloadEndGrid();
@@ -58,18 +58,18 @@ namespace Movement
int32 MoveSplineInit::Launch() int32 MoveSplineInit::Launch()
{ {
MoveSpline& move_spline = *unit.movespline; MoveSpline& move_spline = *unit->movespline;
bool transport = false; bool transport = false;
Location real_position(unit.GetPositionX(), unit.GetPositionY(), unit.GetPositionZMinusOffset(), unit.GetOrientation()); Location real_position(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZMinusOffset(), unit->GetOrientation());
// Elevators also use MOVEMENTFLAG_ONTRANSPORT but we do not keep track of their position changes // Elevators also use MOVEMENTFLAG_ONTRANSPORT but we do not keep track of their position changes
if (unit.HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && unit.GetTransGUID()) if (unit->HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && unit->GetTransGUID())
{ {
transport = true; transport = true;
real_position.x = unit.GetTransOffsetX(); real_position.x = unit->GetTransOffsetX();
real_position.y = unit.GetTransOffsetY(); real_position.y = unit->GetTransOffsetY();
real_position.z = unit.GetTransOffsetZ(); real_position.z = unit->GetTransOffsetZ();
real_position.orientation = unit.GetTransOffsetO(); real_position.orientation = unit->GetTransOffsetO();
} }
// there is a big chance that current position is unknown if current state is not finalized, need compute it // there is a big chance that current position is unknown if current state is not finalized, need compute it
@@ -85,7 +85,7 @@ namespace Movement
args.path[0] = real_position; args.path[0] = real_position;
args.initialOrientation = real_position.orientation; args.initialOrientation = real_position.orientation;
uint32 moveFlags = unit.m_movementInfo.GetMovementFlags(); uint32 moveFlags = unit->m_movementInfo.GetMovementFlags();
if (args.flags.walkmode) if (args.flags.walkmode)
moveFlags |= MOVEMENTFLAG_WALKING; moveFlags |= MOVEMENTFLAG_WALKING;
else else
@@ -94,7 +94,7 @@ namespace Movement
moveFlags |= (MOVEMENTFLAG_SPLINE_ENABLED|MOVEMENTFLAG_FORWARD); moveFlags |= (MOVEMENTFLAG_SPLINE_ENABLED|MOVEMENTFLAG_FORWARD);
if (!args.HasVelocity) if (!args.HasVelocity)
args.velocity = unit.GetSpeed(SelectSpeedType(moveFlags)); args.velocity = unit->GetSpeed(SelectSpeedType(moveFlags));
if (!args.Validate()) if (!args.Validate())
return 0; return 0;
@@ -102,30 +102,30 @@ namespace Movement
if (moveFlags & MOVEMENTFLAG_ROOT) if (moveFlags & MOVEMENTFLAG_ROOT)
moveFlags &= ~MOVEMENTFLAG_MASK_MOVING; moveFlags &= ~MOVEMENTFLAG_MASK_MOVING;
unit.m_movementInfo.SetMovementFlags((MovementFlags)moveFlags); unit->m_movementInfo.SetMovementFlags((MovementFlags)moveFlags);
move_spline.Initialize(args); move_spline.Initialize(args);
WorldPacket data(!transport ? SMSG_MONSTER_MOVE : SMSG_MONSTER_MOVE_TRANSPORT, 64); WorldPacket data(!transport ? SMSG_MONSTER_MOVE : SMSG_MONSTER_MOVE_TRANSPORT, 64);
data.append(unit.GetPackGUID()); data.append(unit->GetPackGUID());
if (transport) if (transport)
{ {
data.appendPackGUID(unit.GetTransGUID()); data.appendPackGUID(unit->GetTransGUID());
data << int8(unit.GetTransSeat()); data << int8(unit->GetTransSeat());
} }
PacketBuilder::WriteMonsterMove(move_spline, data); PacketBuilder::WriteMonsterMove(move_spline, data);
unit.SendMessageToSet(&data,true); unit->SendMessageToSet(&data,true);
return move_spline.Duration(); return move_spline.Duration();
} }
MoveSplineInit::MoveSplineInit(Unit& m) : unit(m) MoveSplineInit::MoveSplineInit(Unit* m) : unit(m)
{ {
// Elevators also use MOVEMENTFLAG_ONTRANSPORT but we do not keep track of their position changes // Elevators also use MOVEMENTFLAG_ONTRANSPORT but we do not keep track of their position changes
args.TransformForTransport = unit.HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && unit.GetTransGUID(); args.TransformForTransport = unit->HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && unit->GetTransGUID();
// mix existing state into new // mix existing state into new
args.flags.walkmode = unit.m_movementInfo.HasMovementFlag(MOVEMENTFLAG_WALKING); args.flags.walkmode = unit->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_WALKING);
args.flags.flying = unit.m_movementInfo.HasMovementFlag((MovementFlags)(MOVEMENTFLAG_CAN_FLY|MOVEMENTFLAG_DISABLE_GRAVITY)); args.flags.flying = unit->m_movementInfo.HasMovementFlag((MovementFlags)(MOVEMENTFLAG_CAN_FLY | MOVEMENTFLAG_DISABLE_GRAVITY));
} }
void MoveSplineInit::SetFacing(const Unit* target) void MoveSplineInit::SetFacing(const Unit* target)
@@ -138,9 +138,9 @@ namespace Movement
{ {
if (args.TransformForTransport) if (args.TransformForTransport)
{ {
if (Unit* vehicle = unit.GetVehicleBase()) if (Unit* vehicle = unit->GetVehicleBase())
angle -= vehicle->GetOrientation(); angle -= vehicle->GetOrientation();
else if (Transport* transport = unit.GetTransport()) else if (Transport* transport = unit->GetTransport())
angle -= transport->GetOrientation(); angle -= transport->GetOrientation();
} }
@@ -152,7 +152,7 @@ namespace Movement
{ {
if (generatePath) if (generatePath)
{ {
PathGenerator path(&unit); PathGenerator path(unit);
path.CalculatePath(dest.x, dest.y, dest.z, forceDestination); path.CalculatePath(dest.x, dest.y, dest.z, forceDestination);
MovebyPath(path.getPath()); MovebyPath(path.getPath());
} }
@@ -169,13 +169,13 @@ namespace Movement
{ {
if (_transformForTransport) if (_transformForTransport)
{ {
if (Unit* vehicle = _owner.GetVehicleBase()) if (Unit* vehicle = _owner->GetVehicleBase())
{ {
input.x -= vehicle->GetPositionX(); input.x -= vehicle->GetPositionX();
input.y -= vehicle->GetPositionY(); input.y -= vehicle->GetPositionY();
input.z -= vehicle->GetPositionZMinusOffset(); input.z -= vehicle->GetPositionZMinusOffset();
} }
else if (Transport* transport = _owner.GetTransport()) else if (Transport* transport = _owner->GetTransport())
{ {
float unused = 0.0f; float unused = 0.0f;
transport->CalculatePassengerOffset(input.x, input.y, input.z, unused); transport->CalculatePassengerOffset(input.x, input.y, input.z, unused);
@@ -38,12 +38,12 @@ namespace Movement
class TransportPathTransform class TransportPathTransform
{ {
public: public:
TransportPathTransform(Unit& owner, bool transformForTransport) TransportPathTransform(Unit* owner, bool transformForTransport)
: _owner(owner), _transformForTransport(transformForTransport) { } : _owner(owner), _transformForTransport(transformForTransport) { }
Vector3 operator()(Vector3 input); Vector3 operator()(Vector3 input);
private: private:
Unit& _owner; Unit* _owner;
bool _transformForTransport; bool _transformForTransport;
}; };
@@ -53,7 +53,7 @@ namespace Movement
{ {
public: public:
explicit MoveSplineInit(Unit& m); explicit MoveSplineInit(Unit* m);
/* Final pass of initialization that launches spline movement. /* Final pass of initialization that launches spline movement.
*/ */
@@ -138,7 +138,7 @@ namespace Movement
protected: protected:
MoveSplineInitArgs args; MoveSplineInitArgs args;
Unit& unit; Unit* unit;
}; };
inline void MoveSplineInit::SetFly() { args.flags.EnableFlying(); } inline void MoveSplineInit::SetFly() { args.flags.EnableFlying(); }
@@ -342,7 +342,7 @@ class boss_algalon_the_observer : public CreatureScript
DoCast(me, SPELL_RIDE_THE_LIGHTNING, true); DoCast(me, SPELL_RIDE_THE_LIGHTNING, true);
me->GetMotionMaster()->MovePoint(POINT_ALGALON_LAND, AlgalonLandPos); me->GetMotionMaster()->MovePoint(POINT_ALGALON_LAND, AlgalonLandPos);
me->SetHomePosition(AlgalonLandPos); me->SetHomePosition(AlgalonLandPos);
Movement::MoveSplineInit init(*me); Movement::MoveSplineInit init(me);
init.MoveTo(AlgalonLandPos.GetPositionX(), AlgalonLandPos.GetPositionY(), AlgalonLandPos.GetPositionZ()); init.MoveTo(AlgalonLandPos.GetPositionX(), AlgalonLandPos.GetPositionY(), AlgalonLandPos.GetPositionZ());
init.SetOrientationFixed(true); init.SetOrientationFixed(true);
init.Launch(); init.Launch();