From d3fc17a81db82423d8ea6dc9910d390f152b36f7 Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Mon, 22 Feb 2010 22:38:19 +0300 Subject: [PATCH] [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 --- src/game/HomeMovementGenerator.cpp | 10 +++++----- src/game/MovementGenerator.h | 11 +++++++++++ src/game/RandomMovementGenerator.cpp | 19 +++++++++++++++---- src/game/RandomMovementGenerator.h | 2 ++ src/game/WaypointMovementGenerator.cpp | 1 - src/game/WaypointMovementGenerator.h | 8 +++++++- src/shared/revision_nr.h | 2 +- 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/game/HomeMovementGenerator.cpp b/src/game/HomeMovementGenerator.cpp index 7ecef5eb2..75ec2467c 100644 --- a/src/game/HomeMovementGenerator.cpp +++ b/src/game/HomeMovementGenerator.cpp @@ -39,14 +39,14 @@ HomeMovementGenerator::Reset(Creature &) void HomeMovementGenerator::_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; - 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); diff --git a/src/game/MovementGenerator.h b/src/game/MovementGenerator.h index af3680d50..37b481a64 100644 --- a/src/game/MovementGenerator.h +++ b/src/game/MovementGenerator.h @@ -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 @@ -83,6 +86,11 @@ class MANGOS_DLL_SPEC MovementGeneratorMedium : public MovementGenerator //u->AssertIsType(); return (static_cast(this))->Update(*((T*)&u), time_diff); } + bool GetResetPosition(Unit& u, float& x, float& y, float& z) + { + //u->AssertIsType(); + return (static_cast(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 diff --git a/src/game/RandomMovementGenerator.cpp b/src/game/RandomMovementGenerator.cpp index 4d68406f8..dacd112d2 100644 --- a/src/game/RandomMovementGenerator.cpp +++ b/src/game/RandomMovementGenerator.cpp @@ -137,15 +137,13 @@ void RandomMovementGenerator::Interrupt(Creature &creature) } template<> -void -RandomMovementGenerator::Finalize(Creature &creature) +void RandomMovementGenerator::Finalize(Creature &creature) { creature.clearUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE); } template<> -bool -RandomMovementGenerator::Update(Creature &creature, const uint32 &diff) +bool RandomMovementGenerator::Update(Creature &creature, const uint32 &diff) { if (creature.hasUnitState(UNIT_STAT_NOT_MOVE)) { @@ -183,3 +181,16 @@ RandomMovementGenerator::Update(Creature &creature, const uint32 &diff } return true; } + +template<> +bool RandomMovementGenerator::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; +} diff --git a/src/game/RandomMovementGenerator.h b/src/game/RandomMovementGenerator.h index 1293b4170..f2ebbff08 100644 --- a/src/game/RandomMovementGenerator.h +++ b/src/game/RandomMovementGenerator.h @@ -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; diff --git a/src/game/WaypointMovementGenerator.cpp b/src/game/WaypointMovementGenerator.cpp index d8832cb70..a27172994 100644 --- a/src/game/WaypointMovementGenerator.cpp +++ b/src/game/WaypointMovementGenerator.cpp @@ -94,7 +94,6 @@ void WaypointMovementGenerator::Interrupt( Creature &u ) void WaypointMovementGenerator::Reset( Creature &u ) { - ReloadPath(u); b_StoppedByPlayer = false; i_nextMoveTime.Reset(0); u.addUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE); diff --git a/src/game/WaypointMovementGenerator.h b/src/game/WaypointMovementGenerator.h index 9fcbf4cbd..0114b1a53 100644 --- a/src/game/WaypointMovementGenerator.h +++ b/src/game/WaypointMovementGenerator.h @@ -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 > i_destinationHolder; @@ -97,6 +98,11 @@ public PathMovementBase // allow use for overwrite empty implementation bool GetDestination(float& x, float& y, float& z) const { return PathMovementBase::GetDestination(x,y,z); } + bool GetResetPosition(Creature&, float& x, float& y, float& z) + { + return PathMovementBase::GetPosition(x,y,z); + } + private: void ClearWaypoints(); @@ -135,4 +141,4 @@ public PathMovementBase // allow use for overwrite empty implementation bool GetDestination(float& x, float& y, float& z) const { return PathMovementBase::GetDestination(x,y,z); } }; -#endif +#endif \ No newline at end of file diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 456391338..f264dda02 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "9434" + #define REVISION_NR "9435" #endif // __REVISION_NR_H__