[9065] Implement motionmaster function UpdateFinalDistanceToTarget()

To update a creatures distance to it's target without creating a new movement generator. Note it can only be used where creature is using TargetedMovementGenerator.

Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
NoFantasy 2009-12-25 18:06:22 +01:00
parent 441aa50bad
commit 3c2327e6e0
6 changed files with 30 additions and 1 deletions

View file

@ -463,3 +463,12 @@ bool MotionMaster::GetDestination(float &x, float &y, float &z)
return top()->GetDestination(x,y,z); return top()->GetDestination(x,y,z);
} }
void MotionMaster::UpdateFinalDistanceToTarget(float fDistance)
{
if (!empty())
{
if (top()->GetMovementGeneratorType() == TARGETED_MOTION_TYPE)
top()->UpdateFinalDistance(fDistance);
}
}

View file

@ -121,6 +121,9 @@ class MANGOS_DLL_SPEC MotionMaster : private std::stack<MovementGenerator *>
void propagateSpeedChange(); void propagateSpeedChange();
// will only work in MMgens where we have a target (TARGETED_MOTION_TYPE)
void UpdateFinalDistanceToTarget(float fDistance);
bool GetDestination(float &x, float &y, float &z); bool GetDestination(float &x, float &y, float &z);
private: private:
void Mutate(MovementGenerator *m); // use Move* functions instead void Mutate(MovementGenerator *m); // use Move* functions instead

View file

@ -44,6 +44,8 @@ class MANGOS_DLL_SPEC MovementGenerator
virtual void unitSpeedChanged() { } virtual void unitSpeedChanged() { }
virtual void UpdateFinalDistance(float fDistance) { }
virtual bool GetDestination(float& /*x*/, float& /*y*/, float& /*z*/) const { return false; } virtual bool GetDestination(float& /*x*/, float& /*y*/, float& /*z*/) const { return false; }
}; };

View file

@ -102,6 +102,19 @@ void TargetedMovementGenerator<Creature>::Initialize(Creature &owner)
_setTargetLocation(owner); _setTargetLocation(owner);
} }
template<>
void TargetedMovementGenerator<Player>::UpdateFinalDistance(float fDistance)
{
// nothing to do for Player
}
template<>
void TargetedMovementGenerator<Creature>::UpdateFinalDistance(float fDistance)
{
i_offset = fDistance;
i_recalculateTravel = true;
}
template<> template<>
void TargetedMovementGenerator<Player>::Initialize(Player &owner) void TargetedMovementGenerator<Player>::Initialize(Player &owner)
{ {

View file

@ -61,6 +61,8 @@ class MANGOS_DLL_SPEC TargetedMovementGenerator
} }
void unitSpeedChanged() { i_recalculateTravel=true; } void unitSpeedChanged() { i_recalculateTravel=true; }
void UpdateFinalDistance(float fDistance);
private: private:
void _setTargetLocation(T &); void _setTargetLocation(T &);

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "9064" #define REVISION_NR "9065"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__