[9435] Avoid useless creature running around at evade

* If creature near respawn point and by defult do random movement
  then restart from current point
* If creature have default waypoints movegen restart from last
  updated point. Not reload waypoints
This commit is contained in:
VladimirMangos 2010-02-22 22:38:19 +03:00
parent f47f5a1deb
commit d3fc17a81d
7 changed files with 41 additions and 12 deletions

View file

@ -39,13 +39,13 @@ HomeMovementGenerator<Creature>::Reset(Creature &)
void
HomeMovementGenerator<Creature>::_setTargetLocation(Creature & owner)
{
if( !&owner )
return;
if( owner.hasUnitState(UNIT_STAT_NOT_MOVE) )
if (owner.hasUnitState(UNIT_STAT_NOT_MOVE))
return;
float x, y, z;
// 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))
owner.GetRespawnCoord(x, y, z);
CreatureTraveller traveller(owner);

View file

@ -52,6 +52,9 @@ class MANGOS_DLL_SPEC MovementGenerator
virtual void UpdateFinalDistance(float /*fDistance*/) { }
virtual bool GetDestination(float& /*x*/, float& /*y*/, float& /*z*/) const { return false; }
// 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; }
};
template<class T, class D>
@ -83,6 +86,11 @@ class MANGOS_DLL_SPEC MovementGeneratorMedium : public MovementGenerator
//u->AssertIsType<T>();
return (static_cast<D*>(this))->Update(*((T*)&u), time_diff);
}
bool GetResetPosition(Unit& u, float& x, float& y, float& z)
{
//u->AssertIsType<T>();
return (static_cast<D*>(this))->GetResetPosition(*((T*)&u), x, y, z);
}
public:
// will not link if not overridden in the generators
void Initialize(T &u);
@ -90,6 +98,9 @@ class MANGOS_DLL_SPEC MovementGeneratorMedium : public MovementGenerator
void Interrupt(T &u);
void Reset(T &u);
bool Update(T &u, const uint32 &time_diff);
// not need always overwrites
bool GetResetPosition(T& /*u*/, float& /*x*/, float& /*y*/, float& /*z*/) { return false; }
};
struct SelectableMovement : public FactoryHolder<MovementGenerator,MovementGeneratorType>

View file

@ -137,15 +137,13 @@ void RandomMovementGenerator<Creature>::Interrupt(Creature &creature)
}
template<>
void
RandomMovementGenerator<Creature>::Finalize(Creature &creature)
void RandomMovementGenerator<Creature>::Finalize(Creature &creature)
{
creature.clearUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
}
template<>
bool
RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff)
bool RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff)
{
if (creature.hasUnitState(UNIT_STAT_NOT_MOVE))
{
@ -183,3 +181,16 @@ RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff
}
return true;
}
template<>
bool RandomMovementGenerator<Creature>::GetResetPosition(Creature& c, float& x, float& y, float& z)
{
float radius;
c.GetRespawnCoord(x, y, z, NULL, &radius);
// use current if in range
if (c.IsWithinDist2d(x,y,radius))
c.GetPosition(x,y,z);
return true;
}

View file

@ -41,6 +41,8 @@ class MANGOS_DLL_SPEC RandomMovementGenerator
i_destinationHolder.GetLocationNow(mapid, x,y,z);
}
MovementGeneratorType GetMovementGeneratorType() { return RANDOM_MOTION_TYPE; }
bool GetResetPosition(T&, float& x, float& y, float& z);
private:
TimeTrackerSmall i_nextMoveTime;

View file

@ -94,7 +94,6 @@ void WaypointMovementGenerator<Creature>::Interrupt( Creature &u )
void WaypointMovementGenerator<Creature>::Reset( Creature &u )
{
ReloadPath(u);
b_StoppedByPlayer = false;
i_nextMoveTime.Reset(0);
u.addUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);

View file

@ -54,6 +54,7 @@ class MANGOS_DLL_SPEC PathMovementBase
uint32 GetCurrentNode() const { return i_currentNode; }
bool GetDestination(float& x, float& y, float& z) const { i_destinationHolder.GetDestination(x,y,z); return true; }
bool GetPosition(float& x, float& y, float& z) const { i_destinationHolder.GetLocationNowNoMicroMovement(x,y,z); return true; }
protected:
uint32 i_currentNode;
DestinationHolder< Traveller<T> > i_destinationHolder;
@ -97,6 +98,11 @@ public PathMovementBase<Creature, WaypointPath const*>
// allow use for overwrite empty implementation
bool GetDestination(float& x, float& y, float& z) const { return PathMovementBase<Creature, WaypointPath const*>::GetDestination(x,y,z); }
bool GetResetPosition(Creature&, float& x, float& y, float& z)
{
return PathMovementBase<Creature, WaypointPath const*>::GetPosition(x,y,z);
}
private:
void ClearWaypoints();

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9434"
#define REVISION_NR "9435"
#endif // __REVISION_NR_H__