Movement #5242

Closed
wants to merge 4 commits into
from
@@ -32,31 +32,15 @@ void PointMovementGenerator<T>::Initialize(T &unit)
if (!unit.IsStopped())
unit.StopMoving();
- unit.AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
+ unit.AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
Movement::MoveSplineInit init(unit);
- init.MoveTo(i_x, i_y, i_z);
- if (speed > 0.0f)
- init.SetVelocity(speed);
+ init.MoveTo(_x, _y, _z);
+ if (_speed > 0.0f)
+ init.SetVelocity(_speed);
init.Launch();
}
template<class T>
-bool PointMovementGenerator<T>::Update(T &unit, const uint32 &diff)
-{
- if (!&unit)
- return false;
-
- if(unit.HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED))
- {
- unit.ClearUnitState(UNIT_STATE_ROAMING_MOVE);
- return true;
- }
-
- unit.AddUnitState(UNIT_STATE_ROAMING_MOVE);
- return !unit.movespline->Finalized();
-}
-
-template<class T>
void PointMovementGenerator<T>:: Finalize(T &unit)
{
unit.ClearUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
@@ -66,12 +50,31 @@ void PointMovementGenerator<T>:: Finalize(T &unit)
}
template<class T>
+void PointMovementGenerator<T>::Interrupt(T &unit)
+{
+ unit.ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
+}
+
+template<class T>
void PointMovementGenerator<T>::Reset(T &unit)
{
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>
+bool PointMovementGenerator<T>::Update(T &unit, uint32 const& diff)
+{
+ if (unit.HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED))
+ {
+ unit.ClearUnitState(UNIT_STATE_ROAMING_MOVE);
+ return true;
+ }
+
+ unit.AddUnitState(UNIT_STATE_ROAMING_MOVE);
+ return !unit.movespline->Finalized();
}
template<class T>
@@ -81,13 +84,8 @@ void PointMovementGenerator<T>::MovementInform(T & /*unit*/)
template <> void PointMovementGenerator<Creature>::MovementInform(Creature &unit)
{
- //if (id == EVENT_FALL_GROUND)
- //{
- // unit.setDeathState(JUST_DIED);
- // unit.SetFlying(true);
- //}
if (unit.AI())
- unit.AI()->MovementInform(POINT_MOTION_TYPE, id);
+ unit.AI()->MovementInform(POINT_MOTION_TYPE, _id);
}
template void PointMovementGenerator<Player>::Initialize(Player&);
@@ -118,13 +116,5 @@ void EffectMovementGenerator::Finalize(Unit &unit)
return;
if (((Creature&)unit).AI() && unit.movespline->Finalized())
- ((Creature&)unit).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 * victim = unit.getVictim())
- // unit.GetMotionMaster()->MoveChase(victim);
- // else
- // unit.GetMotionMaster()->Initialize();
- //}
+ ((Creature&)unit).AI()->MovementInform(EFFECT_MOTION_TYPE, _Id);
}
@@ -27,23 +27,24 @@ class PointMovementGenerator
: public MovementGeneratorMedium< T, PointMovementGenerator<T> >
{
public:
- PointMovementGenerator(uint32 _id, float _x, float _y, float _z, float _speed = 0.0f) : id(_id),
- i_x(_x), i_y(_y), i_z(_z), speed(_speed) {}
+ PointMovementGenerator(uint32 _id, float _x, float _y, float _z, float _speed = 0.0f) : _id(_id),
+ _x(_x), _y(_y), _z(_z), _speed(_speed) {}
void Initialize(T &);
void Finalize(T &);
+ void Interrupt(T &);
void Reset(T &);
bool Update(T &, const uint32 &);
void MovementInform(T &);
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; }
+ bool GetDestination(float& x, float& y, float& z) const { x = _x; y = _y; z = _z; return true; }
private:
- uint32 id;
- float i_x, i_y, i_z;
- float speed;
+ uint32 _id;
+ float _x, _y, _z;
+ float _speed;
};
class AssistanceMovementGenerator
@@ -61,14 +62,14 @@ class AssistanceMovementGenerator
class EffectMovementGenerator : public MovementGenerator
{
public:
- explicit EffectMovementGenerator(uint32 Id) : m_Id(Id) {}
+ explicit EffectMovementGenerator(uint32 Id) : _Id(Id) {}
void Initialize(Unit &) {}
void Finalize(Unit &unit);
void Reset(Unit &) {}
bool Update(Unit &u, const uint32);
MovementGeneratorType GetMovementGeneratorType() { return EFFECT_MOTION_TYPE; }
private:
- uint32 m_Id;
+ uint32 _Id;
};
#endif
@@ -33,7 +33,7 @@
#endif
template<>
-void RandomMovementGenerator<Creature>::_setRandomLocation(Creature& creature)
+void RandomMovementGenerator<Creature>::SetRandomLocation(Creature& creature)
{
float respX, respY, respZ, respO, currZ, destX, destY, destZ, travelDistZ;
creature.GetHomePosition(respX, respY, respZ, respO);
@@ -46,7 +46,7 @@ void RandomMovementGenerator<Creature>::_setRandomLocation(Creature& creature)
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;
+ const float range = float(rand_norm()) * _wanderDistance;
const float distanceX = range * cos(angle);
const float distanceY = range * sin(angle);
@@ -98,9 +98,9 @@ void RandomMovementGenerator<Creature>::_setRandomLocation(Creature& creature)
}
if (is_air_ok)
- i_nextMoveTime.Reset(0);
+ _nextMoveTime.Reset(0);
else
- i_nextMoveTime.Reset(urand(500, 10000));
+ _nextMoveTime.Reset(urand(500, 10000));
creature.AddUnitState(UNIT_STATE_ROAMING_MOVE);
@@ -120,11 +120,11 @@ void RandomMovementGenerator<Creature>::Initialize(Creature &creature)
if (!creature.isAlive())
return;
- if (!wander_distance)
- wander_distance = creature.GetRespawnRadius();
+ if (!_wanderDistance)
+ _wanderDistance = creature.GetRespawnRadius();
- creature.AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE);
- _setRandomLocation(creature);
+ creature.AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
+ SetRandomLocation(creature);
}
template<>
@@ -135,9 +135,16 @@ RandomMovementGenerator<Creature>::Reset(Creature &creature)
}
template<>
+void RandomMovementGenerator<Creature>::Interrupt(Creature &creature)
+{
+ creature.ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
+ creature.SetWalk(false);
+}
+
+template<>
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);
}
@@ -147,16 +154,16 @@ RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 diff)
{
if (creature.HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED | UNIT_STATE_DISTRACTED))
{
- i_nextMoveTime.Reset(0); // Expire the timer
+ _nextMoveTime.Reset(0); // Expire the timer
creature.ClearUnitState(UNIT_STATE_ROAMING_MOVE);
return true;
}
if (creature.movespline->Finalized())
{
- i_nextMoveTime.Update(diff);
- if (i_nextMoveTime.Passed())
- _setRandomLocation(creature);
+ _nextMoveTime.Update(diff);
+ if (_nextMoveTime.Passed())
+ SetRandomLocation(creature);
}
return true;
}
@@ -26,20 +26,21 @@ class RandomMovementGenerator
: public MovementGeneratorMedium< T, RandomMovementGenerator<T> >
{
public:
- RandomMovementGenerator(float spawn_dist = 0.0f) : i_nextMoveTime(0), wander_distance(spawn_dist) {}
+ RandomMovementGenerator(float spawnDist = 0.0f) : _nextMoveTime(0), _wanderDistance(spawnDist) {}
- void _setRandomLocation(T &);
+ void SetRandomLocation(T &);
void Initialize(T &);
void Finalize(T &);
void Reset(T &);
+ void Interrupt(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;
+ TimeTrackerSmall _nextMoveTime;
- uint32 i_nextMove;
- float wander_distance;
+ uint32 _nextMove;
+ float _wanderDistance;
};
#endif