mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 22:37:03 +00:00
[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:
parent
f47f5a1deb
commit
d3fc17a81d
7 changed files with 41 additions and 12 deletions
|
|
@ -39,14 +39,14 @@ HomeMovementGenerator<Creature>::Reset(Creature &)
|
||||||
void
|
void
|
||||||
HomeMovementGenerator<Creature>::_setTargetLocation(Creature & owner)
|
HomeMovementGenerator<Creature>::_setTargetLocation(Creature & owner)
|
||||||
{
|
{
|
||||||
if( !&owner )
|
if (owner.hasUnitState(UNIT_STAT_NOT_MOVE))
|
||||||
return;
|
|
||||||
|
|
||||||
if( owner.hasUnitState(UNIT_STAT_NOT_MOVE) )
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
owner.GetRespawnCoord(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);
|
CreatureTraveller traveller(owner);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,9 @@ class MANGOS_DLL_SPEC MovementGenerator
|
||||||
virtual void UpdateFinalDistance(float /*fDistance*/) { }
|
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; }
|
||||||
|
|
||||||
|
// 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>
|
template<class T, class D>
|
||||||
|
|
@ -83,6 +86,11 @@ class MANGOS_DLL_SPEC MovementGeneratorMedium : public MovementGenerator
|
||||||
//u->AssertIsType<T>();
|
//u->AssertIsType<T>();
|
||||||
return (static_cast<D*>(this))->Update(*((T*)&u), time_diff);
|
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:
|
public:
|
||||||
// will not link if not overridden in the generators
|
// will not link if not overridden in the generators
|
||||||
void Initialize(T &u);
|
void Initialize(T &u);
|
||||||
|
|
@ -90,6 +98,9 @@ class MANGOS_DLL_SPEC MovementGeneratorMedium : public MovementGenerator
|
||||||
void Interrupt(T &u);
|
void Interrupt(T &u);
|
||||||
void Reset(T &u);
|
void Reset(T &u);
|
||||||
bool Update(T &u, const uint32 &time_diff);
|
bool Update(T &u, const uint32 &time_diff);
|
||||||
|
|
||||||
|
// not need always overwrites
|
||||||
|
bool GetResetPosition(T& /*u*/, float& /*x*/, float& /*y*/, float& /*z*/) { return false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SelectableMovement : public FactoryHolder<MovementGenerator,MovementGeneratorType>
|
struct SelectableMovement : public FactoryHolder<MovementGenerator,MovementGeneratorType>
|
||||||
|
|
|
||||||
|
|
@ -137,15 +137,13 @@ void RandomMovementGenerator<Creature>::Interrupt(Creature &creature)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void
|
void RandomMovementGenerator<Creature>::Finalize(Creature &creature)
|
||||||
RandomMovementGenerator<Creature>::Finalize(Creature &creature)
|
|
||||||
{
|
{
|
||||||
creature.clearUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
|
creature.clearUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
bool
|
bool RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff)
|
||||||
RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff)
|
|
||||||
{
|
{
|
||||||
if (creature.hasUnitState(UNIT_STAT_NOT_MOVE))
|
if (creature.hasUnitState(UNIT_STAT_NOT_MOVE))
|
||||||
{
|
{
|
||||||
|
|
@ -183,3 +181,16 @@ RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff
|
||||||
}
|
}
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,8 @@ class MANGOS_DLL_SPEC RandomMovementGenerator
|
||||||
i_destinationHolder.GetLocationNow(mapid, x,y,z);
|
i_destinationHolder.GetLocationNow(mapid, x,y,z);
|
||||||
}
|
}
|
||||||
MovementGeneratorType GetMovementGeneratorType() { return RANDOM_MOTION_TYPE; }
|
MovementGeneratorType GetMovementGeneratorType() { return RANDOM_MOTION_TYPE; }
|
||||||
|
|
||||||
|
bool GetResetPosition(T&, float& x, float& y, float& z);
|
||||||
private:
|
private:
|
||||||
TimeTrackerSmall i_nextMoveTime;
|
TimeTrackerSmall i_nextMoveTime;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,6 @@ void WaypointMovementGenerator<Creature>::Interrupt( Creature &u )
|
||||||
|
|
||||||
void WaypointMovementGenerator<Creature>::Reset( Creature &u )
|
void WaypointMovementGenerator<Creature>::Reset( Creature &u )
|
||||||
{
|
{
|
||||||
ReloadPath(u);
|
|
||||||
b_StoppedByPlayer = false;
|
b_StoppedByPlayer = false;
|
||||||
i_nextMoveTime.Reset(0);
|
i_nextMoveTime.Reset(0);
|
||||||
u.addUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
|
u.addUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ class MANGOS_DLL_SPEC PathMovementBase
|
||||||
uint32 GetCurrentNode() const { return i_currentNode; }
|
uint32 GetCurrentNode() const { return i_currentNode; }
|
||||||
|
|
||||||
bool GetDestination(float& x, float& y, float& z) const { i_destinationHolder.GetDestination(x,y,z); return true; }
|
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:
|
protected:
|
||||||
uint32 i_currentNode;
|
uint32 i_currentNode;
|
||||||
DestinationHolder< Traveller<T> > i_destinationHolder;
|
DestinationHolder< Traveller<T> > i_destinationHolder;
|
||||||
|
|
@ -97,6 +98,11 @@ public PathMovementBase<Creature, WaypointPath const*>
|
||||||
// allow use for overwrite empty implementation
|
// 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 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:
|
private:
|
||||||
void ClearWaypoints();
|
void ClearWaypoints();
|
||||||
|
|
||||||
|
|
@ -135,4 +141,4 @@ public PathMovementBase<Player>
|
||||||
// allow use for overwrite empty implementation
|
// allow use for overwrite empty implementation
|
||||||
bool GetDestination(float& x, float& y, float& z) const { return PathMovementBase<Player>::GetDestination(x,y,z); }
|
bool GetDestination(float& x, float& y, float& z) const { return PathMovementBase<Player>::GetDestination(x,y,z); }
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "9434"
|
#define REVISION_NR "9435"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue