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)
{
Movement::MoveSplineInit init(*this);
Movement::MoveSplineInit init(this);
init.MoveTo(x, y, z, generatePath, forceDestination);
init.SetVelocity(speed);
init.Launch();
@@ -14750,7 +14750,7 @@ void Unit::StopMoving()
if (!IsInWorld())
return;
Movement::MoveSplineInit init(*this);
Movement::MoveSplineInit init(this);
init.MoveTo(GetPositionX(), GetPositionY(), GetPositionZMinusOffset());
init.SetFacing(GetOrientation());
init.Launch();
@@ -17152,7 +17152,7 @@ void Unit::_ExitVehicle(Position const* exitPosition)
SendMessageToSet(&data, false);
}
Movement::MoveSplineInit init(*this);
Movement::MoveSplineInit init(this);
init.MoveTo(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ());
init.SetFacing(GetOrientation());
init.SetTransportExit();
@@ -17562,7 +17562,7 @@ void Unit::SetInFront(Unit const* target)
void Unit::SetFacingTo(float ori)
{
Movement::MoveSplineInit init(*this);
Movement::MoveSplineInit init(this);
init.MoveTo(GetPositionX(), GetPositionY(), GetPositionZMinusOffset());
init.SetFacing(ori);
init.Launch();
+1 -1
View File
@@ -365,7 +365,7 @@ bool Vehicle::AddPassenger(Unit* unit, int8 seatId)
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)
// also adds MOVEMENTFLAG_ROOT
Movement::MoveSplineInit init(*unit);
Movement::MoveSplineInit init(unit);
init.DisableTransportPathTransformations();
init.MoveTo(veSeat->m_attachmentOffsetX, veSeat->m_attachmentOffsetY, veSeat->m_attachmentOffsetZ);
init.SetFacing(0.0f);
+1 -1
View File
@@ -125,7 +125,7 @@ void WorldSession::HandleMoveWorldportAckOpcode()
{
// short preparations to continue flight
FlightPathMovementGenerator* flight = (FlightPathMovementGenerator*)(GetPlayer()->GetMotionMaster()->top());
flight->Initialize(*GetPlayer());
flight->Initialize(GetPlayer());
return;
}
+20 -20
View File
@@ -86,7 +86,7 @@ void MotionMaster::UpdateMotion(uint32 diff)
ASSERT(!empty());
_cleanFlag |= MMCF_UPDATE;
if (!top()->Update(*_owner, diff))
if (!top()->Update(_owner, diff))
{
_cleanFlag &= ~MMCF_UPDATE;
MovementExpired();
@@ -110,7 +110,7 @@ void MotionMaster::UpdateMotion(uint32 diff)
else if (needInitTop())
InitTop();
else if (_cleanFlag & MMCF_RESET)
top()->Reset(*_owner);
top()->Reset(_owner);
_cleanFlag &= ~MMCF_RESET;
}
@@ -131,7 +131,7 @@ void MotionMaster::DirectClean(bool reset)
if (needInitTop())
InitTop();
else if (reset)
top()->Reset(*_owner);
top()->Reset(_owner);
}
void MotionMaster::DelayedClean()
@@ -162,7 +162,7 @@ void MotionMaster::DirectExpire(bool reset)
else if (needInitTop())
InitTop();
else if (reset)
top()->Reset(*_owner);
top()->Reset(_owner);
}
void MotionMaster::DelayedExpire()
@@ -198,19 +198,19 @@ void MotionMaster::MoveTargetedHome()
{
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());
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());
Unit *target = ((Creature*)_owner)->GetCharmerOrOwner();
Unit* target = _owner->ToCreature()->GetCharmerOrOwner();
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());
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
@@ -247,7 +247,7 @@ void MotionMaster::MoveChase(Unit* target, float dist, float angle)
_owner->GetGUIDLow(),
target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature",
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
{
@@ -255,7 +255,7 @@ void MotionMaster::MoveChase(Unit* target, float dist, float angle)
_owner->GetEntry(), _owner->GetGUIDLow(),
target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature",
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(),
target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature",
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
{
@@ -279,7 +279,7 @@ void MotionMaster::MoveFollow(Unit* target, float dist, float angle, MovementSlo
_owner->GetEntry(), _owner->GetGUIDLow(),
target->GetTypeId() == TYPEID_PLAYER ? "player" : "creature",
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);
Movement::MoveSplineInit init(*_owner);
Movement::MoveSplineInit init(_owner);
init.MoveTo(x,y,z);
init.SetAnimation(Movement::ToGround);
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);
Movement::MoveSplineInit init(*_owner);
Movement::MoveSplineInit init(_owner);
init.MoveTo(x,y,z);
init.SetAnimation(Movement::ToFly);
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);
Movement::MoveSplineInit init(*_owner);
Movement::MoveSplineInit init(_owner);
init.MoveTo(x,y,z);
init.SetParabolic(max_height,0);
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 max_height = -Movement::computeFallElevation(moveTimeHalf,false,-speedZ);
Movement::MoveSplineInit init(*_owner);
Movement::MoveSplineInit init(_owner);
init.MoveTo(x, y, z, false);
init.SetParabolic(max_height,0);
init.SetVelocity(speedXY);
@@ -398,7 +398,7 @@ void MotionMaster::MoveFall(uint32 id/*=0*/)
_owner->m_movementInfo.SetFallTime(0);
}
Movement::MoveSplineInit init(*_owner);
Movement::MoveSplineInit init(_owner);
init.MoveTo(_owner->GetPositionX(), _owner->GetPositionY(), tz);
init.SetFall();
init.Launch();
@@ -545,7 +545,7 @@ void MotionMaster::Mutate(MovementGenerator *m, MovementSlot slot)
else
{
_needInit[slot] = false;
m->Initialize(*_owner);
m->Initialize(_owner);
}
}
@@ -613,7 +613,7 @@ MovementGeneratorType MotionMaster::GetMotionSlotType(int slot) const
void MotionMaster::InitTop()
{
top()->Initialize(*_owner);
top()->Initialize(_owner);
_needInit[_top] = false;
}
@@ -621,7 +621,7 @@ void MotionMaster::DirectDelete(_Ty curr)
{
if (isStatic(curr))
return;
curr->Finalize(*_owner);
curr->Finalize(_owner);
delete curr;
}
+20 -17
View File
@@ -33,51 +33,54 @@ class MovementGenerator
public:
virtual ~MovementGenerator();
virtual void Initialize(Unit &) = 0;
virtual void Finalize(Unit &) = 0;
virtual void Initialize(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 void unitSpeedChanged() { }
// 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>
class MovementGeneratorMedium : public MovementGenerator
{
public:
void Initialize(Unit &u)
void Initialize(Unit* u)
{
//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>();
(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>();
(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>();
return (static_cast<D*>(this))->Update(*((T*)&u), time_diff);
return (static_cast<D*>(this))->Update(static_cast<T*>(u), time_diff);
}
public:
// will not link if not overridden in the generators
void Initialize(T &u);
void Finalize(T &u);
void Reset(T &u);
bool Update(T &u, const uint32& time_diff);
void Initialize(T* u);
void Finalize(T* u);
void Reset(T* u);
bool Update(T* u, const uint32& time_diff);
};
struct SelectableMovement : public FactoryHolder<MovementGenerator, MovementGeneratorType>
@@ -31,34 +31,34 @@
#endif
template<class T>
void ConfusedMovementGenerator<T>::Initialize(T &unit)
void ConfusedMovementGenerator<T>::Initialize(T* unit)
{
unit.GetPosition(i_x, i_y, i_z);
unit.StopMoving();
unit.SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
unit.AddUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
unit->GetPosition(i_x, i_y, i_z);
unit->StopMoving();
unit->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
unit->AddUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
}
template<class T>
void ConfusedMovementGenerator<T>::Reset(T &unit)
void ConfusedMovementGenerator<T>::Reset(T* unit)
{
i_nextMoveTime.Reset(0);
unit.StopMoving();
unit.AddUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
unit->StopMoving();
unit->AddUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
}
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;
if (i_nextMoveTime.Passed())
{
// 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));
}
else
@@ -68,15 +68,15 @@ bool ConfusedMovementGenerator<T>::Update(T &unit, const uint32 &diff)
if (i_nextMoveTime.Passed())
{
// 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 y = i_y + 10.0f*((float)rand_norm() - 0.5f);
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.CalculatePath(x, y, z);
if (path.getPathType() & PATHFIND_NOPATH)
@@ -96,26 +96,26 @@ bool ConfusedMovementGenerator<T>::Update(T &unit, const uint32 &diff)
}
template<>
void ConfusedMovementGenerator<Player>::Finalize(Player &unit)
void ConfusedMovementGenerator<Player>::Finalize(Player* unit)
{
unit.RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
unit.ClearUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
unit.StopMoving();
unit->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
unit->ClearUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
unit->StopMoving();
}
template<>
void ConfusedMovementGenerator<Creature>::Finalize(Creature &unit)
void ConfusedMovementGenerator<Creature>::Finalize(Creature* unit)
{
unit.RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
unit.ClearUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
if (unit.getVictim())
unit.SetTarget(unit.getVictim()->GetGUID());
unit->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
unit->ClearUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
if (unit->getVictim())
unit->SetTarget(unit->getVictim()->GetGUID());
}
template void ConfusedMovementGenerator<Player>::Initialize(Player &player);
template void ConfusedMovementGenerator<Creature>::Initialize(Creature &creature);
template void ConfusedMovementGenerator<Player>::Reset(Player &player);
template void ConfusedMovementGenerator<Creature>::Reset(Creature &creature);
template bool ConfusedMovementGenerator<Player>::Update(Player &player, const uint32 &diff);
template bool ConfusedMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff);
template void ConfusedMovementGenerator<Player>::Initialize(Player*);
template void ConfusedMovementGenerator<Creature>::Initialize(Creature*);
template void ConfusedMovementGenerator<Player>::Reset(Player*);
template void ConfusedMovementGenerator<Creature>::Reset(Creature*);
template bool ConfusedMovementGenerator<Player>::Update(Player*, const uint32&);
template bool ConfusedMovementGenerator<Creature>::Update(Creature*, const uint32&);
@@ -28,10 +28,10 @@ class ConfusedMovementGenerator : public MovementGeneratorMedium< T, ConfusedMov
public:
explicit ConfusedMovementGenerator() : i_nextMoveTime(0) {}
void Initialize(T &);
void Finalize(T &);
void Reset(T &);
bool Update(T &, const uint32 &);
void Initialize(T*);
void Finalize(T*);
void Reset(T*);
bool Update(T*, const uint32&);
MovementGeneratorType GetMovementGeneratorType() { return CONFUSED_MOTION_TYPE; }
private:
@@ -29,21 +29,21 @@
#define MAX_QUIET_DISTANCE 43.0f
template<class T>
void FleeingMovementGenerator<T>::_setTargetLocation(T &owner)
void FleeingMovementGenerator<T>::_setTargetLocation(T* owner)
{
if (!&owner)
if (!owner)
return;
if (owner.HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED))
if (owner->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED))
return;
float x, y, z;
if (!_getPoint(owner, x, y, z))
return;
owner.AddUnitState(UNIT_STATE_FLEEING_MOVE);
owner->AddUnitState(UNIT_STATE_FLEEING_MOVE);
PathGenerator path(&owner);
PathGenerator path(owner);
path.setPathLengthLimit(30.0f);
path.CalculatePath(x, y, z);
if (path.getPathType() & PATHFIND_NOPATH)
@@ -60,17 +60,17 @@ void FleeingMovementGenerator<T>::_setTargetLocation(T &owner)
}
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;
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)
angle_to_caster = fright->GetAngle(&owner);
angle_to_caster = fright->GetAngle(owner);
else
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;
owner.GetPosition(curr_x, curr_y, curr_z);
owner->GetPosition(curr_x, curr_y, curr_z);
x = curr_x + dist*cos(angle);
y = curr_y + dist*sin(angle);
z = curr_z;
owner.UpdateAllowedPositionZ(x, y, z);
owner->UpdateAllowedPositionZ(x, y, z);
return true;
}
template<class T>
void FleeingMovementGenerator<T>::Initialize(T &owner)
void FleeingMovementGenerator<T>::Initialize(T* owner)
{
if (!&owner)
if (!owner)
return;
owner.SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
owner.AddUnitState(UNIT_STATE_FLEEING|UNIT_STATE_FLEEING_MOVE);
owner->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
owner->AddUnitState(UNIT_STATE_FLEEING|UNIT_STATE_FLEEING_MOVE);
if (owner.GetTypeId() == TYPEID_UNIT)
if (owner->GetTypeId() == TYPEID_UNIT)
return;
_setTargetLocation(owner);
}
template<>
void FleeingMovementGenerator<Player>::Finalize(Player &owner)
void FleeingMovementGenerator<Player>::Finalize(Player* owner)
{
owner.RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
owner.ClearUnitState(UNIT_STATE_FLEEING|UNIT_STATE_FLEEING_MOVE);
owner.StopMoving();
owner->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
owner->ClearUnitState(UNIT_STATE_FLEEING | UNIT_STATE_FLEEING_MOVE);
owner->StopMoving();
}
template<>
void FleeingMovementGenerator<Creature>::Finalize(Creature &owner)
void FleeingMovementGenerator<Creature>::Finalize(Creature* owner)
{
owner.RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
owner.ClearUnitState(UNIT_STATE_FLEEING|UNIT_STATE_FLEEING_MOVE);
if (owner.getVictim())
owner.SetTarget(owner.getVictim()->GetGUID());
owner->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
owner->ClearUnitState(UNIT_STATE_FLEEING|UNIT_STATE_FLEEING_MOVE);
if (owner->getVictim())
owner->SetTarget(owner->getVictim()->GetGUID());
}
template<class T>
void FleeingMovementGenerator<T>::Reset(T &owner)
void FleeingMovementGenerator<T>::Reset(T* owner)
{
Initialize(owner);
}
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;
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;
}
i_nextCheckTime.Update(time_diff);
if (i_nextCheckTime.Passed() && owner.movespline->Finalized())
if (i_nextCheckTime.Passed() && owner->movespline->Finalized())
_setTargetLocation(owner);
return true;
}
template void FleeingMovementGenerator<Player>::Initialize(Player &);
template void FleeingMovementGenerator<Creature>::Initialize(Creature &);
template bool FleeingMovementGenerator<Player>::_getPoint(Player &, float &, float &, float &);
template bool FleeingMovementGenerator<Creature>::_getPoint(Creature &, float &, float &, float &);
template void FleeingMovementGenerator<Player>::_setTargetLocation(Player &);
template void FleeingMovementGenerator<Creature>::_setTargetLocation(Creature &);
template void FleeingMovementGenerator<Player>::Reset(Player &);
template void FleeingMovementGenerator<Creature>::Reset(Creature &);
template bool FleeingMovementGenerator<Player>::Update(Player &, const uint32 &);
template bool FleeingMovementGenerator<Creature>::Update(Creature &, const uint32 &);
template void FleeingMovementGenerator<Player>::Initialize(Player*);
template void FleeingMovementGenerator<Creature>::Initialize(Creature*);
template bool FleeingMovementGenerator<Player>::_getPoint(Player*, float&, float&, float&);
template bool FleeingMovementGenerator<Creature>::_getPoint(Creature*, float&, float&, float&);
template void FleeingMovementGenerator<Player>::_setTargetLocation(Player*);
template void FleeingMovementGenerator<Creature>::_setTargetLocation(Creature*);
template void FleeingMovementGenerator<Player>::Reset(Player*);
template void FleeingMovementGenerator<Creature>::Reset(Creature*);
template bool FleeingMovementGenerator<Player>::Update(Player*, 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.ClearUnitState(UNIT_STATE_FLEEING|UNIT_STATE_FLEEING_MOVE);
if (Unit* victim = owner.getVictim())
owner->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
owner->ClearUnitState(UNIT_STATE_FLEEING|UNIT_STATE_FLEEING_MOVE);
if (Unit* victim = owner->getVictim())
{
if (owner.isAlive())
if (owner->isAlive())
{
owner.AttackStop();
owner.ToCreature()->AI()->AttackStart(victim);
owner->AttackStop();
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;
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;
}
@@ -27,16 +27,16 @@ class FleeingMovementGenerator : public MovementGeneratorMedium< T, FleeingMovem
public:
FleeingMovementGenerator(uint64 fright) : i_frightGUID(fright), i_nextCheckTime(0) {}
void Initialize(T &);
void Finalize(T &);
void Reset(T &);
bool Update(T &, const uint32 &);
void Initialize(T*);
void Finalize(T*);
void Reset(T*);
bool Update(T*, const uint32&);
MovementGeneratorType GetMovementGeneratorType() { return FLEEING_MOTION_TYPE; }
private:
void _setTargetLocation(T &owner);
bool _getPoint(T &owner, float &x, float &y, float &z);
void _setTargetLocation(T*);
bool _getPoint(T*, float &x, float &y, float &z);
uint64 i_frightGUID;
TimeTracker i_nextCheckTime;
@@ -50,8 +50,8 @@ class TimedFleeingMovementGenerator : public FleeingMovementGenerator<Creature>
i_totalFleeTime(time) {}
MovementGeneratorType GetMovementGeneratorType() { return TIMED_FLEEING_MOTION_TYPE; }
bool Update(Unit &, const uint32&);
void Finalize(Unit &);
bool Update(Unit*, const uint32&);
void Finalize(Unit*);
private:
TimeTracker i_totalFleeTime;
@@ -23,49 +23,49 @@
#include "MoveSplineInit.h"
#include "MoveSpline.h"
void HomeMovementGenerator<Creature>::Initialize(Creature& owner)
void HomeMovementGenerator<Creature>::Initialize(Creature* owner)
{
_setTargetLocation(owner);
}
void HomeMovementGenerator<Creature>::Finalize(Creature& owner)
void HomeMovementGenerator<Creature>::Finalize(Creature* owner)
{
if (arrived)
{
owner.ClearUnitState(UNIT_STATE_EVADE);
owner.SetWalk(true);
owner.LoadCreaturesAddon(true);
owner.AI()->JustReachedHome();
owner->ClearUnitState(UNIT_STATE_EVADE);
owner->SetWalk(true);
owner->LoadCreaturesAddon(true);
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;
Movement::MoveSplineInit init(owner);
float x, y, z, o;
// 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.MoveTo(x,y,z);
init.MoveTo(x, y, z);
init.SetWalk(false);
init.Launch();
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;
}
@@ -34,14 +34,14 @@ class HomeMovementGenerator<Creature> : public MovementGeneratorMedium< Creature
HomeMovementGenerator() : arrived(false) {}
~HomeMovementGenerator() {}
void Initialize(Creature &);
void Finalize(Creature &);
void Reset(Creature &);
bool Update(Creature &, const uint32);
void Initialize(Creature*);
void Finalize(Creature*);
void Reset(Creature*);
bool Update(Creature*, const uint32);
MovementGeneratorType GetMovementGeneratorType() { return HOME_MOTION_TYPE; }
private:
void _setTargetLocation(Creature &);
void _setTargetLocation(Creature*);
bool arrived;
};
#endif
@@ -24,33 +24,33 @@ IdleMovementGenerator si_idleMovement;
// 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
void IdleMovementGenerator::Initialize(Unit &owner)
void IdleMovementGenerator::Initialize(Unit* owner)
{
Reset(owner);
}
void IdleMovementGenerator::Reset(Unit& owner)
void IdleMovementGenerator::Reset(Unit* owner)
{
if (!owner.IsStopped())
owner.StopMoving();
if (!owner->IsStopped())
owner->StopMoving();
}
void RotateMovementGenerator::Initialize(Unit& owner)
void RotateMovementGenerator::Initialize(Unit* owner)
{
if (!owner.IsStopped())
owner.StopMoving();
if (!owner->IsStopped())
owner->StopMoving();
if (owner.getVictim())
owner.SetInFront(owner.getVictim());
if (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)
{
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;
while (angle < 0) angle += static_cast<float>(M_PI * 2);
}
owner.SetOrientation(angle);
owner.SendMovementFlagUpdate(); // this is a hack. we do not have anything correct to send in the beginning
owner->SetOrientation(angle);
owner->SendMovementFlagUpdate(); // this is a hack. we do not have anything correct to send in the beginning
if (m_duration > diff)
m_duration -= diff;
@@ -72,24 +72,24 @@ bool RotateMovementGenerator::Update(Unit& owner, const uint32& diff)
return true;
}
void RotateMovementGenerator::Finalize(Unit &unit)
void RotateMovementGenerator::Finalize(Unit* unit)
{
unit.ClearUnitState(UNIT_STATE_ROTATING);
if (unit.GetTypeId() == TYPEID_UNIT)
unit.ToCreature()->AI()->MovementInform(ROTATE_MOTION_TYPE, 0);
unit->ClearUnitState(UNIT_STATE_ROTATING);
if (unit->GetTypeId() == TYPEID_UNIT)
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)
return false;
@@ -98,9 +98,9 @@ bool DistractMovementGenerator::Update(Unit& /*owner*/, const uint32& time_diff)
return true;
}
void AssistanceDistractMovementGenerator::Finalize(Unit &unit)
void AssistanceDistractMovementGenerator::Finalize(Unit* unit)
{
unit.ClearUnitState(UNIT_STATE_DISTRACTED);
unit.ToCreature()->SetReactState(REACT_AGGRESSIVE);
unit->ClearUnitState(UNIT_STATE_DISTRACTED);
unit->ToCreature()->SetReactState(REACT_AGGRESSIVE);
}
@@ -25,10 +25,10 @@ class IdleMovementGenerator : public MovementGenerator
{
public:
void Initialize(Unit &);
void Finalize(Unit &) { }
void Reset(Unit &);
bool Update(Unit &, const uint32&) { return true; }
void Initialize(Unit*);
void Finalize(Unit*) { }
void Reset(Unit*);
bool Update(Unit*, const uint32&) { return true; }
MovementGeneratorType GetMovementGeneratorType() { return IDLE_MOTION_TYPE; }
};
@@ -39,10 +39,10 @@ class RotateMovementGenerator : public MovementGenerator
public:
explicit RotateMovementGenerator(uint32 time, RotateDirection direction) : m_duration(time), m_maxDuration(time), m_direction(direction) {}
void Initialize(Unit& owner);
void Finalize(Unit& owner);
void Reset(Unit& owner) { Initialize(owner); }
bool Update(Unit& owner, const uint32& time_diff);
void Initialize(Unit*);
void Finalize(Unit*);
void Reset(Unit* owner) { Initialize(owner); }
bool Update(Unit*, const uint32&);
MovementGeneratorType GetMovementGeneratorType() { return ROTATE_MOTION_TYPE; }
private:
@@ -55,10 +55,10 @@ class DistractMovementGenerator : public MovementGenerator
public:
explicit DistractMovementGenerator(uint32 timer) : m_timer(timer) {}
void Initialize(Unit& owner);
void Finalize(Unit& owner);
void Reset(Unit& owner) { Initialize(owner); }
bool Update(Unit& owner, const uint32& time_diff);
void Initialize(Unit*);
void Finalize(Unit*);
void Reset(Unit* owner) { Initialize(owner); }
bool Update(Unit*, const uint32&);
MovementGeneratorType GetMovementGeneratorType() { return DISTRACT_MOTION_TYPE; }
private:
@@ -72,7 +72,7 @@ class AssistanceDistractMovementGenerator : public DistractMovementGenerator
DistractMovementGenerator(timer) {}
MovementGeneratorType GetMovementGeneratorType() { return ASSISTANCE_DISTRACT_MOTION_TYPE; }
void Finalize(Unit& unit);
void Finalize(Unit*);
};
#endif
@@ -27,12 +27,12 @@
//----- Point Movement Generator
template<class T>
void PointMovementGenerator<T>::Initialize(T &unit)
void PointMovementGenerator<T>::Initialize(T* unit)
{
if (!unit.IsStopped())
unit.StopMoving();
if (!unit->IsStopped())
unit->StopMoving();
unit.AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
unit->AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
i_recalculateSpeed = false;
Movement::MoveSplineInit init(unit);
init.MoveTo(i_x, i_y, i_z, m_generatePath);
@@ -42,20 +42,20 @@ void PointMovementGenerator<T>::Initialize(T &unit)
}
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;
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;
}
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;
Movement::MoveSplineInit init(unit);
@@ -65,74 +65,74 @@ bool PointMovementGenerator<T>::Update(T &unit, const uint32 & /*diff*/)
init.Launch();
}
return !unit.movespline->Finalized();
return !unit->movespline->Finalized();
}
template<class T>
void PointMovementGenerator<T>::Finalize(T &unit)
void PointMovementGenerator<T>::Finalize(T* unit)
{
if (unit.HasUnitState(UNIT_STATE_CHARGING))
unit.ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
if (unit->HasUnitState(UNIT_STATE_CHARGING))
unit->ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
if (unit.movespline->Finalized())
if (unit->movespline->Finalized())
MovementInform(unit);
}
template<class T>
void PointMovementGenerator<T>::Reset(T &unit)
void PointMovementGenerator<T>::Reset(T* unit)
{
if (!unit.IsStopped())
unit.StopMoving();
if (!unit->IsStopped())
unit->StopMoving();
unit.AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
unit->AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
}
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())
unit.AI()->MovementInform(POINT_MOTION_TYPE, id);
if (unit->AI())
unit->AI()->MovementInform(POINT_MOTION_TYPE, id);
}
template void PointMovementGenerator<Player>::Initialize(Player&);
template void PointMovementGenerator<Creature>::Initialize(Creature&);
template void PointMovementGenerator<Player>::Finalize(Player&);
template void PointMovementGenerator<Creature>::Finalize(Creature&);
template void PointMovementGenerator<Player>::Reset(Player&);
template void PointMovementGenerator<Creature>::Reset(Creature&);
template bool PointMovementGenerator<Player>::Update(Player &, const uint32 &);
template bool PointMovementGenerator<Creature>::Update(Creature&, const uint32 &);
template void PointMovementGenerator<Player>::Initialize(Player*);
template void PointMovementGenerator<Creature>::Initialize(Creature*);
template void PointMovementGenerator<Player>::Finalize(Player*);
template void PointMovementGenerator<Creature>::Finalize(Creature*);
template void PointMovementGenerator<Player>::Reset(Player*);
template void PointMovementGenerator<Creature>::Reset(Creature*);
template bool PointMovementGenerator<Player>::Update(Player*, 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()->CallAssistance();
if (unit.isAlive())
unit.GetMotionMaster()->MoveSeekAssistanceDistract(sWorld->getIntConfig(CONFIG_CREATURE_FAMILY_ASSISTANCE_DELAY));
unit->ToCreature()->SetNoCallAssistance(false);
unit->ToCreature()->CallAssistance();
if (unit->isAlive())
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;
if (((Creature&)unit).AI())
((Creature&)unit).AI()->MovementInform(EFFECT_MOTION_TYPE, m_Id);
if (unit->ToCreature()->AI())
unit->ToCreature()->AI()->MovementInform(EFFECT_MOTION_TYPE, m_Id);
// 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())
unit.GetMotionMaster()->MoveChase(victim);
if (Unit* victim = unit->getVictim())
unit->GetMotionMaster()->MoveChase(victim);
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),
i_x(_x), i_y(_y), i_z(_z), m_generatePath(_generatePath), speed(_speed) {}
void Initialize(T &);
void Finalize(T &);
void Reset(T &);
bool Update(T &, const uint32 &);
void Initialize(T*);
void Finalize(T*);
void Reset(T*);
bool Update(T*, const uint32 &);
void MovementInform(T &);
void MovementInform(T*);
void unitSpeedChanged() { i_recalculateSpeed = true; }
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:
uint32 id;
float i_x, i_y, i_z;
@@ -56,7 +56,7 @@ class AssistanceMovementGenerator : public PointMovementGenerator<Creature>
PointMovementGenerator<Creature>(0, _x, _y, _z, true) {}
MovementGeneratorType GetMovementGeneratorType() { return ASSISTANCE_MOTION_TYPE; }
void Finalize(Unit &);
void Finalize(Unit*);
};
// Does almost nothing - just doesn't allows previous movegen interrupt current effect.
@@ -64,10 +64,10 @@ class EffectMovementGenerator : public MovementGenerator
{
public:
explicit EffectMovementGenerator(uint32 Id) : m_Id(Id) {}
void Initialize(Unit &) {}
void Finalize(Unit &unit);
void Reset(Unit &) {}
bool Update(Unit &u, const uint32&);
void Initialize(Unit*) {}
void Finalize(Unit*);
void Reset(Unit*) {}
bool Update(Unit*, const uint32&);
MovementGeneratorType GetMovementGeneratorType() { return EFFECT_MOTION_TYPE; }
private:
uint32 m_Id;
@@ -33,16 +33,16 @@
#endif
template<>
void RandomMovementGenerator<Creature>::_setRandomLocation(Creature& creature)
void RandomMovementGenerator<Creature>::_setRandomLocation(Creature* creature)
{
float respX, respY, respZ, respO, destX, destY, destZ, travelDistZ;
creature.GetHomePosition(respX, respY, respZ, respO);
Map const* map = creature.GetBaseMap();
creature->GetHomePosition(respX, respY, respZ, respO);
Map const* map = creature->GetBaseMap();
// For 2D/3D system selection
//bool is_land_ok = creature.CanWalk(); // 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 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.
// 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
{
// 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)
{
// 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
if (fabs(destZ - respZ) > travelDistZ)
@@ -101,7 +101,7 @@ void RandomMovementGenerator<Creature>::_setRandomLocation(Creature& creature)
else
i_nextMoveTime.Reset(urand(500, 10000));
creature.AddUnitState(UNIT_STATE_ROAMING_MOVE);
creature->AddUnitState(UNIT_STATE_ROAMING_MOVE);
Movement::MoveSplineInit init(creature);
init.MoveTo(destX, destY, destZ);
@@ -109,47 +109,47 @@ void RandomMovementGenerator<Creature>::_setRandomLocation(Creature& creature)
init.Launch();
//Call for creature group update
if (creature.GetFormation() && creature.GetFormation()->getLeader() == &creature)
creature.GetFormation()->LeaderMoveTo(destX, destY, destZ);
if (creature->GetFormation() && creature->GetFormation()->getLeader() == creature)
creature->GetFormation()->LeaderMoveTo(destX, destY, destZ);
}
template<>
void RandomMovementGenerator<Creature>::Initialize(Creature &creature)
void RandomMovementGenerator<Creature>::Initialize(Creature* creature)
{
if (!creature.isAlive())
if (!creature->isAlive())
return;
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);
}
template<>
void RandomMovementGenerator<Creature>::Reset(Creature &creature)
void RandomMovementGenerator<Creature>::Reset(Creature* creature)
{
Initialize(creature);
}
template<>
void RandomMovementGenerator<Creature>::Finalize(Creature &creature)
void RandomMovementGenerator<Creature>::Finalize(Creature* creature)
{
creature.ClearUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
creature.SetWalk(false);
creature->ClearUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
creature->SetWalk(false);
}
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
creature.ClearUnitState(UNIT_STATE_ROAMING_MOVE);
creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
return true;
}
if (creature.movespline->Finalized())
if (creature->movespline->Finalized())
{
i_nextMoveTime.Update(diff);
if (i_nextMoveTime.Passed())
@@ -159,14 +159,14 @@ bool RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32
}
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;
creature.GetRespawnPosition(x, y, z, NULL, &radius);
creature->GetRespawnPosition(x, y, z, NULL, &radius);
// use current if in range
if (creature.IsWithinDist2d(x,y,radius))
creature.GetPosition(x,y,z);
if (creature->IsWithinDist2d(x,y,radius))
creature->GetPosition(x,y,z);
return true;
}
@@ -27,12 +27,12 @@ class RandomMovementGenerator : public MovementGeneratorMedium< T, RandomMovemen
public:
RandomMovementGenerator(float spawn_dist = 0.0f) : i_nextMoveTime(0), wander_distance(spawn_dist) {}
void _setRandomLocation(T &);
void Initialize(T &);
void Finalize(T &);
void Reset(T &);
bool Update(T &, const uint32);
bool GetResetPosition(T&, float& x, float& y, float& z);
void _setRandomLocation(T*);
void Initialize(T*);
void Finalize(T*);
void Reset(T*);
bool Update(T*, const uint32);
bool GetResetPosition(T*, float& x, float& y, float& z);
MovementGeneratorType GetMovementGeneratorType() { return RANDOM_MOTION_TYPE; }
private:
TimeTrackerSmall i_nextMoveTime;
@@ -27,12 +27,12 @@
#include "Player.h"
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())
return;
if (owner.HasUnitState(UNIT_STATE_NOT_MOVE))
if (owner->HasUnitState(UNIT_STATE_NOT_MOVE))
return;
float x, y, z;
@@ -49,26 +49,26 @@ void TargetedMovementGeneratorMedium<T,D>::_setTargetLocation(T &owner)
// else
if (!i_offset)
{
if (i_target->IsWithinMeleeRange(&owner))
if (i_target->IsWithinMeleeRange(owner))
return;
// 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
{
if (i_target->IsWithinDistInMap(&owner, i_offset + 1.0f))
if (i_target->IsWithinDistInMap(owner, i_offset + 1.0f))
return;
// 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)
i_path = new PathGenerator(&owner);
i_path = new PathGenerator(owner);
// allow pets following their master to cheat while generating paths
bool forceDest = (owner.GetTypeId() == TYPEID_UNIT && ((Creature*)&owner)->isPet()
&& owner.HasUnitState(UNIT_STATE_FOLLOW));
bool forceDest = (owner->GetTypeId() == TYPEID_UNIT && owner->ToCreature()->isPet()
&& owner->HasUnitState(UNIT_STATE_FOLLOW));
i_path->CalculatePath(x, y, z, forceDest);
if (i_path->getPathType() & PATHFIND_NOPATH)
return;
@@ -76,7 +76,7 @@ void TargetedMovementGeneratorMedium<T,D>::_setTargetLocation(T &owner)
D::_addUnitStateMove(owner);
i_targetReached = false;
i_recalculateTravel = false;
owner.AddUnitState(UNIT_STATE_CHASE);
owner->AddUnitState(UNIT_STATE_CHASE);
Movement::MoveSplineInit init(owner);
init.MovebyPath(i_path->getPath());
@@ -111,25 +111,25 @@ void TargetedMovementGeneratorMedium<Creature,FollowMovementGenerator<Creature>
}
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())
return false;
if (!&owner || !owner.isAlive())
if (!owner || !owner->isAlive())
return true;
if (owner.HasUnitState(UNIT_STATE_NOT_MOVE))
if (owner->HasUnitState(UNIT_STATE_NOT_MOVE))
{
D::_clearUnitStateMove(owner);
return true;
}
// 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())
owner.StopMoving();
if (!owner->IsStopped())
owner->StopMoving();
return true;
}
@@ -145,11 +145,11 @@ bool TargetedMovementGeneratorMedium<T,D>::Update(T &owner, const uint32 & time_
{
i_recheckDistance.Reset(100);
//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);
G3D::Vector3 dest = owner.movespline->FinalDestination();
float allowed_dist = owner->GetCombatReach() + sWorld->getRate(RATE_TARGET_POS_RECALCULATION_RANGE);
G3D::Vector3 dest = owner->movespline->FinalDestination();
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);
else
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);
}
if (owner.movespline->Finalized())
if (owner->movespline->Finalized())
{
static_cast<D*>(this)->MovementInform(owner);
if (i_angle == 0.f && !owner.HasInArc(0.01f, i_target.getTarget()))
owner.SetInFront(i_target.getTarget());
if (i_angle == 0.f && !owner->HasInArc(0.01f, i_target.getTarget()))
owner->SetInFront(i_target.getTarget());
if (!i_targetReached)
{
@@ -180,50 +180,50 @@ bool TargetedMovementGeneratorMedium<T,D>::Update(T &owner, const uint32 & time_
//-----------------------------------------------//
template<class T>
void ChaseMovementGenerator<T>::_reachTarget(T &owner)
void ChaseMovementGenerator<T>::_reachTarget(T* owner)
{
if (owner.IsWithinMeleeRange(this->i_target.getTarget()))
owner.Attack(this->i_target.getTarget(),true);
if (owner->IsWithinMeleeRange(this->i_target.getTarget()))
owner->Attack(this->i_target.getTarget(),true);
}
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);
}
template<>
void ChaseMovementGenerator<Creature>::Initialize(Creature &owner)
void ChaseMovementGenerator<Creature>::Initialize(Creature* owner)
{
owner.SetWalk(false);
owner.AddUnitState(UNIT_STATE_CHASE|UNIT_STATE_CHASE_MOVE);
owner->SetWalk(false);
owner->AddUnitState(UNIT_STATE_CHASE | UNIT_STATE_CHASE_MOVE);
_setTargetLocation(owner);
}
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>
void ChaseMovementGenerator<T>::Reset(T &owner)
void ChaseMovementGenerator<T>::Reset(T* owner)
{
Initialize(owner);
}
template<class T>
void ChaseMovementGenerator<T>::MovementInform(T & /*unit*/)
void ChaseMovementGenerator<T>::MovementInform(T* /*unit*/)
{
}
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
if (unit.AI())
unit.AI()->MovementInform(CHASE_MOTION_TYPE, i_target.getTarget()->GetGUIDLow());
if (unit->AI())
unit->AI()->MovementInform(CHASE_MOTION_TYPE, i_target.getTarget()->GetGUIDLow());
}
//-----------------------------------------------//
@@ -240,85 +240,85 @@ bool FollowMovementGenerator<Player>::EnableWalking() const
}
template<>
void FollowMovementGenerator<Player>::_updateSpeed(Player &/*u*/)
void FollowMovementGenerator<Player>::_updateSpeed(Player* /*u*/)
{
// nothing to do for Player
}
template<>
void FollowMovementGenerator<Creature>::_updateSpeed(Creature &u)
void FollowMovementGenerator<Creature>::_updateSpeed(Creature* u)
{
// 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;
u.UpdateSpeed(MOVE_RUN,true);
u.UpdateSpeed(MOVE_WALK,true);
u.UpdateSpeed(MOVE_SWIM,true);
u->UpdateSpeed(MOVE_RUN,true);
u->UpdateSpeed(MOVE_WALK,true);
u->UpdateSpeed(MOVE_SWIM,true);
}
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);
_setTargetLocation(owner);
}
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);
_setTargetLocation(owner);
}
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);
}
template<class T>
void FollowMovementGenerator<T>::Reset(T &owner)
void FollowMovementGenerator<T>::Reset(T* owner)
{
Initialize(owner);
}
template<class T>
void FollowMovementGenerator<T>::MovementInform(T & /*unit*/)
void FollowMovementGenerator<T>::MovementInform(T* /*unit*/)
{
}
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
if (unit.AI())
unit.AI()->MovementInform(FOLLOW_MOTION_TYPE, i_target.getTarget()->GetGUIDLow());
if (unit->AI())
unit->AI()->MovementInform(FOLLOW_MOTION_TYPE, i_target.getTarget()->GetGUIDLow());
}
//-----------------------------------------------//
template void TargetedMovementGeneratorMedium<Player,ChaseMovementGenerator<Player> >::_setTargetLocation(Player &);
template void TargetedMovementGeneratorMedium<Player,FollowMovementGenerator<Player> >::_setTargetLocation(Player &);
template void TargetedMovementGeneratorMedium<Creature,ChaseMovementGenerator<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,FollowMovementGenerator<Player> >::Update(Player &, const uint32 &);
template bool TargetedMovementGeneratorMedium<Creature,ChaseMovementGenerator<Creature> >::Update(Creature &, const uint32 &);
template bool TargetedMovementGeneratorMedium<Creature,FollowMovementGenerator<Creature> >::Update(Creature &, const uint32 &);
template void TargetedMovementGeneratorMedium<Player,ChaseMovementGenerator<Player> >::_setTargetLocation(Player*);
template void TargetedMovementGeneratorMedium<Player,FollowMovementGenerator<Player> >::_setTargetLocation(Player*);
template void TargetedMovementGeneratorMedium<Creature,ChaseMovementGenerator<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,FollowMovementGenerator<Player> >::Update(Player*, const uint32&);
template bool TargetedMovementGeneratorMedium<Creature,ChaseMovementGenerator<Creature> >::Update(Creature*, const uint32&);
template bool TargetedMovementGeneratorMedium<Creature,FollowMovementGenerator<Creature> >::Update(Creature*, const uint32&);
template void ChaseMovementGenerator<Player>::_reachTarget(Player &);
template void ChaseMovementGenerator<Creature>::_reachTarget(Creature &);
template void ChaseMovementGenerator<Player>::Finalize(Player &);
template void ChaseMovementGenerator<Creature>::Finalize(Creature &);
template void ChaseMovementGenerator<Player>::Reset(Player &);
template void ChaseMovementGenerator<Creature>::Reset(Creature &);
template void ChaseMovementGenerator<Player>::MovementInform(Player &unit);
template void ChaseMovementGenerator<Player>::_reachTarget(Player*);
template void ChaseMovementGenerator<Creature>::_reachTarget(Creature*);
template void ChaseMovementGenerator<Player>::Finalize(Player*);
template void ChaseMovementGenerator<Creature>::Finalize(Creature*);
template void ChaseMovementGenerator<Player>::Reset(Player*);
template void ChaseMovementGenerator<Creature>::Reset(Creature*);
template void ChaseMovementGenerator<Player>::MovementInform(Player*);
template void FollowMovementGenerator<Player>::Finalize(Player &);
template void FollowMovementGenerator<Creature>::Finalize(Creature &);
template void FollowMovementGenerator<Player>::Reset(Player &);
template void FollowMovementGenerator<Creature>::Reset(Creature &);
template void FollowMovementGenerator<Player>::MovementInform(Player &unit);
template void FollowMovementGenerator<Player>::Finalize(Player*);
template void FollowMovementGenerator<Creature>::Finalize(Creature*);
template void FollowMovementGenerator<Player>::Reset(Player*);
template void FollowMovementGenerator<Creature>::Reset(Creature*);
template void FollowMovementGenerator<Player>::MovementInform(Player*);
@@ -28,7 +28,7 @@
class TargetedMovementGeneratorBase
{
public:
TargetedMovementGeneratorBase(Unit &target) { i_target.link(&target, this); }
TargetedMovementGeneratorBase(Unit* target) { i_target.link(target, this); }
void stopFollowing() { }
protected:
FollowerReference i_target;
@@ -38,7 +38,7 @@ template<class T, typename D>
class TargetedMovementGeneratorMedium : public MovementGeneratorMedium< T, D >, public TargetedMovementGeneratorBase
{
protected:
TargetedMovementGeneratorMedium(Unit &target, float offset, float angle) :
TargetedMovementGeneratorMedium(Unit* target, float offset, float angle) :
TargetedMovementGeneratorBase(target), i_recheckDistance(0), i_path(NULL),
i_offset(offset), i_angle(angle),
i_recalculateTravel(false), i_targetReached(false)
@@ -47,14 +47,14 @@ class TargetedMovementGeneratorMedium : public MovementGeneratorMedium< T, D >,
~TargetedMovementGeneratorMedium() { delete i_path; }
public:
bool Update(T &, const uint32 &);
bool Update(T*, const uint32 &);
Unit* GetTarget() const { return i_target.getTarget(); }
void unitSpeedChanged() { i_recalculateTravel=true; }
void unitSpeedChanged() { i_recalculateTravel = true; }
void UpdateFinalDistance(float fDistance);
bool IsReachable() const { return (i_path) ? (i_path->getPathType() & PATHFIND_NORMAL) : true; }
protected:
void _setTargetLocation(T &);
void _setTargetLocation(T*);
TimeTrackerSmall i_recheckDistance;
float i_offset;
@@ -68,50 +68,50 @@ template<class T>
class ChaseMovementGenerator : public TargetedMovementGeneratorMedium<T, ChaseMovementGenerator<T> >
{
public:
ChaseMovementGenerator(Unit &target)
ChaseMovementGenerator(Unit* 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) {}
~ChaseMovementGenerator() {}
MovementGeneratorType GetMovementGeneratorType() { return CHASE_MOTION_TYPE; }
void Initialize(T &);
void Finalize(T &);
void Reset(T &);
void MovementInform(T &);
void Initialize(T*);
void Finalize(T*);
void Reset(T*);
void MovementInform(T*);
static void _clearUnitStateMove(T &u) { u.ClearUnitState(UNIT_STATE_CHASE_MOVE); }
static void _addUnitStateMove(T &u) { u.AddUnitState(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); }
bool EnableWalking() const { return false;}
bool _lostTarget(T &u) const { return u.getVictim() != this->GetTarget(); }
void _reachTarget(T &);
bool _lostTarget(T* u) const { return u->getVictim() != GetTarget(); }
void _reachTarget(T*);
};
template<class T>
class FollowMovementGenerator : public TargetedMovementGeneratorMedium<T, FollowMovementGenerator<T> >
{
public:
FollowMovementGenerator(Unit &target)
FollowMovementGenerator(Unit* 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) {}
~FollowMovementGenerator() {}
MovementGeneratorType GetMovementGeneratorType() { return FOLLOW_MOTION_TYPE; }
void Initialize(T &);
void Finalize(T &);
void Reset(T &);
void MovementInform(T &);
void Initialize(T*);
void Finalize(T*);
void Reset(T*);
void MovementInform(T*);
static void _clearUnitStateMove(T &u) { u.ClearUnitState(UNIT_STATE_FOLLOW_MOVE); }
static void _addUnitStateMove(T &u) { u.AddUnitState(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); }
bool EnableWalking() const;
bool _lostTarget(T &) const { return false; }
void _reachTarget(T &) {}
bool _lostTarget(T*) const { return false; }
void _reachTarget(T*) {}
private:
void _updateSpeed(T &u);
void _updateSpeed(T* u);
};
#endif
@@ -31,64 +31,64 @@
#include "MoveSplineInit.h"
#include "MoveSpline.h"
void WaypointMovementGenerator<Creature>::LoadPath(Creature &creature)
void WaypointMovementGenerator<Creature>::LoadPath(Creature* creature)
{
if (!path_id)
path_id = creature.GetWaypointPath();
path_id = creature->GetWaypointPath();
i_path = sWaypointMgr->GetPath(path_id);
if (!i_path)
{
// 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;
}
StartMoveNow(creature);
}
void WaypointMovementGenerator<Creature>::Initialize(Creature &creature)
void WaypointMovementGenerator<Creature>::Initialize(Creature* 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.SetWalk(false);
creature->ClearUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
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);
}
void WaypointMovementGenerator<Creature>::OnArrived(Creature& creature)
void WaypointMovementGenerator<Creature>::OnArrived(Creature* creature)
{
if (!i_path || i_path->empty())
return;
if (m_isArrivalDone)
return;
creature.ClearUnitState(UNIT_STATE_ROAMING_MOVE);
creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
m_isArrivalDone = true;
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());
creature.GetMap()->ScriptsStart(sWaypointScripts, i_path->at(i_currentNode)->event_id, &creature, NULL);
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);
}
// Inform script
MovementInform(creature);
creature.UpdateWaypointID(i_currentNode);
creature->UpdateWaypointID(i_currentNode);
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())
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
{
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->SetHomePosition(i_path->at(i_currentNode)->x, i_path->at(i_currentNode)->y, i_path->at(i_currentNode)->z, creature->GetOrientation());
creature->GetMotionMaster()->Initialize();
return false;
}
@@ -111,7 +111,7 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature &creature)
m_isArrivalDone = false;
creature.AddUnitState(UNIT_STATE_ROAMING_MOVE);
creature->AddUnitState(UNIT_STATE_ROAMING_MOVE);
Movement::MoveSplineInit init(creature);
init.MoveTo(node->x, node->y, node->z);
@@ -124,19 +124,19 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature &creature)
init.Launch();
//Call for creature group update
if (creature.GetFormation() && creature.GetFormation()->getLeader() == &creature)
creature.GetFormation()->LeaderMoveTo(node->x, node->y, node->z);
if (creature->GetFormation() && creature->GetFormation()->getLeader() == creature)
creature->GetFormation()->LeaderMoveTo(node->x, node->y, node->z);
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
// 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;
}
// prevent a crash at empty waypoint path.
@@ -150,9 +150,9 @@ bool WaypointMovementGenerator<Creature>::Update(Creature &creature, const uint3
}
else
{
if (creature.IsStopped())
if (creature->IsStopped())
Stop(STOP_TIME_FOR_PLAYER);
else if (creature.movespline->Finalized())
else if (creature->movespline->Finalized())
{
OnArrived(creature);
return StartMove(creature);
@@ -161,13 +161,13 @@ bool WaypointMovementGenerator<Creature>::Update(Creature &creature, const uint3
return true;
}
void WaypointMovementGenerator<Creature>::MovementInform(Creature &creature)
void WaypointMovementGenerator<Creature>::MovementInform(Creature* creature)
{
if (creature.AI())
creature.AI()->MovementInform(WAYPOINT_MOTION_TYPE, i_currentNode);
if (creature->AI())
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.
if (!i_path || i_path->empty())
@@ -196,37 +196,37 @@ uint32 FlightPathMovementGenerator::GetPathAtMapEnd() const
return i_path->size();
}
void FlightPathMovementGenerator::Initialize(Player &player)
void FlightPathMovementGenerator::Initialize(Player* player)
{
Reset(player);
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)
player.ClearUnitState(UNIT_STATE_IN_FLIGHT);
player->ClearUnitState(UNIT_STATE_IN_FLIGHT);
player.Dismount();
player.RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE | UNIT_FLAG_TAXI_FLIGHT);
player->Dismount();
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
// this prevent cheating with landing point at lags
// when client side flight end early in comparison server side
player.StopMoving();
player->StopMoving();
}
}
#define PLAYER_FLIGHT_SPEED 32.0f
void FlightPathMovementGenerator::Reset(Player & player)
void FlightPathMovementGenerator::Reset(Player* player)
{
player.getHostileRefManager().setOnlineOfflineState(false);
player.AddUnitState(UNIT_STATE_IN_FLIGHT);
player.SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE | UNIT_FLAG_TAXI_FLIGHT);
player->getHostileRefManager().setOnlineOfflineState(false);
player->AddUnitState(UNIT_STATE_IN_FLIGHT);
player->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE | UNIT_FLAG_TAXI_FLIGHT);
Movement::MoveSplineInit init(player);
uint32 end = GetPathAtMapEnd();
@@ -241,9 +241,9 @@ void FlightPathMovementGenerator::Reset(Player & player)
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)
{
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)
{
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);
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);
}
}
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];
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)
: i_nextMoveTime(0), m_isArrivalDone(false), path_id(_path_id), repeating(_repeating) {}
~WaypointMovementGenerator() { i_path = NULL; }
void Initialize(Creature &);
void Finalize(Creature &);
void Reset(Creature &);
bool Update(Creature &, const uint32 &diff);
void Initialize(Creature*);
void Finalize(Creature*);
void Reset(Creature*);
bool Update(Creature*, const uint32 &diff);
void MovementInform(Creature &);
void MovementInform(Creature*);
MovementGeneratorType GetMovementGeneratorType() { return WAYPOINT_MOTION_TYPE; }
// 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:
@@ -91,10 +91,10 @@ class WaypointMovementGenerator<Creature> : public MovementGeneratorMedium< Crea
return i_nextMoveTime.Passed();
}
void OnArrived(Creature&);
bool StartMove(Creature&);
void OnArrived(Creature*);
bool StartMove(Creature*);
void StartMoveNow(Creature& creature)
void StartMoveNow(Creature* creature)
{
i_nextMoveTime.Reset(0);
StartMove(creature);
@@ -118,10 +118,10 @@ class FlightPathMovementGenerator : public MovementGeneratorMedium< Player, Flig
i_path = &pathnodes;
i_currentNode = startNode;
}
void Initialize(Player &);
void Reset(Player &);
void Finalize(Player &);
bool Update(Player &, const uint32&);
void Initialize(Player*);
void Reset(Player*);
void Finalize(Player*);
bool Update(Player*, const uint32&);
MovementGeneratorType GetMovementGeneratorType() { return FLIGHT_MOTION_TYPE; }
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()); }
void SetCurrentNodeAfterTeleport();
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 PreloadEndGrid();
@@ -58,18 +58,18 @@ namespace Movement
int32 MoveSplineInit::Launch()
{
MoveSpline& move_spline = *unit.movespline;
MoveSpline& move_spline = *unit->movespline;
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
if (unit.HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && unit.GetTransGUID())
if (unit->HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && unit->GetTransGUID())
{
transport = true;
real_position.x = unit.GetTransOffsetX();
real_position.y = unit.GetTransOffsetY();
real_position.z = unit.GetTransOffsetZ();
real_position.orientation = unit.GetTransOffsetO();
real_position.x = unit->GetTransOffsetX();
real_position.y = unit->GetTransOffsetY();
real_position.z = unit->GetTransOffsetZ();
real_position.orientation = unit->GetTransOffsetO();
}
// 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.initialOrientation = real_position.orientation;
uint32 moveFlags = unit.m_movementInfo.GetMovementFlags();
uint32 moveFlags = unit->m_movementInfo.GetMovementFlags();
if (args.flags.walkmode)
moveFlags |= MOVEMENTFLAG_WALKING;
else
@@ -94,7 +94,7 @@ namespace Movement
moveFlags |= (MOVEMENTFLAG_SPLINE_ENABLED|MOVEMENTFLAG_FORWARD);
if (!args.HasVelocity)
args.velocity = unit.GetSpeed(SelectSpeedType(moveFlags));
args.velocity = unit->GetSpeed(SelectSpeedType(moveFlags));
if (!args.Validate())
return 0;
@@ -102,33 +102,33 @@ namespace Movement
if (moveFlags & MOVEMENTFLAG_ROOT)
moveFlags &= ~MOVEMENTFLAG_MASK_MOVING;
unit.m_movementInfo.SetMovementFlags((MovementFlags)moveFlags);
unit->m_movementInfo.SetMovementFlags((MovementFlags)moveFlags);
move_spline.Initialize(args);
WorldPacket data(!transport ? SMSG_MONSTER_MOVE : SMSG_MONSTER_MOVE_TRANSPORT, 64);
data.append(unit.GetPackGUID());
data.append(unit->GetPackGUID());
if (transport)
{
data.appendPackGUID(unit.GetTransGUID());
data << int8(unit.GetTransSeat());
data.appendPackGUID(unit->GetTransGUID());
data << int8(unit->GetTransSeat());
}
PacketBuilder::WriteMonsterMove(move_spline, data);
unit.SendMessageToSet(&data,true);
unit->SendMessageToSet(&data,true);
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
args.TransformForTransport = unit.HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && unit.GetTransGUID();
args.TransformForTransport = unit->HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && unit->GetTransGUID();
// mix existing state into new
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.walkmode = unit->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_WALKING);
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)
{
args.flags.EnableFacingTarget();
args.facing.target = target->GetGUID();
@@ -138,9 +138,9 @@ namespace Movement
{
if (args.TransformForTransport)
{
if (Unit* vehicle = unit.GetVehicleBase())
if (Unit* vehicle = unit->GetVehicleBase())
angle -= vehicle->GetOrientation();
else if (Transport* transport = unit.GetTransport())
else if (Transport* transport = unit->GetTransport())
angle -= transport->GetOrientation();
}
@@ -152,7 +152,7 @@ namespace Movement
{
if (generatePath)
{
PathGenerator path(&unit);
PathGenerator path(unit);
path.CalculatePath(dest.x, dest.y, dest.z, forceDestination);
MovebyPath(path.getPath());
}
@@ -169,13 +169,13 @@ namespace Movement
{
if (_transformForTransport)
{
if (Unit* vehicle = _owner.GetVehicleBase())
if (Unit* vehicle = _owner->GetVehicleBase())
{
input.x -= vehicle->GetPositionX();
input.y -= vehicle->GetPositionY();
input.z -= vehicle->GetPositionZMinusOffset();
}
else if (Transport* transport = _owner.GetTransport())
else if (Transport* transport = _owner->GetTransport())
{
float unused = 0.0f;
transport->CalculatePassengerOffset(input.x, input.y, input.z, unused);
@@ -38,12 +38,12 @@ namespace Movement
class TransportPathTransform
{
public:
TransportPathTransform(Unit& owner, bool transformForTransport)
TransportPathTransform(Unit* owner, bool transformForTransport)
: _owner(owner), _transformForTransport(transformForTransport) { }
Vector3 operator()(Vector3 input);
private:
Unit& _owner;
Unit* _owner;
bool _transformForTransport;
};
@@ -53,7 +53,7 @@ namespace Movement
{
public:
explicit MoveSplineInit(Unit& m);
explicit MoveSplineInit(Unit* m);
/* Final pass of initialization that launches spline movement.
*/
@@ -76,7 +76,7 @@ namespace Movement
*/
void SetFacing(float angle);
void SetFacing(Vector3 const& point);
void SetFacing(const Unit * target);
void SetFacing(const Unit* target);
/* Initializes movement by path
* @param path - array of points, shouldn't be empty
@@ -138,7 +138,7 @@ namespace Movement
protected:
MoveSplineInitArgs args;
Unit& unit;
Unit* unit;
};
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);
me->GetMotionMaster()->MovePoint(POINT_ALGALON_LAND, AlgalonLandPos);
me->SetHomePosition(AlgalonLandPos);
Movement::MoveSplineInit init(*me);
Movement::MoveSplineInit init(me);
init.MoveTo(AlgalonLandPos.GetPositionX(), AlgalonLandPos.GetPositionY(), AlgalonLandPos.GetPositionZ());
init.SetOrientationFixed(true);
init.Launch();