From 8f324811e549be7d556d77ce90059a2ceb62c0ea Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Sat, 16 Jan 2010 06:53:17 +0300 Subject: [PATCH] [9188] Implement MoveGen::Interrupt call. It can be used in time when need do some tasks before another movement generator add on top to motion stack. This just finish pair Interrupt->Reset similar Initilize->Finilize In general movementgenerator have states: Initilize=>Interrupt<=>[-some addition movegen->]<=>Reset=>Finalize --- src/game/ConfusedMovementGenerator.cpp | 13 +++++++++---- src/game/ConfusedMovementGenerator.h | 1 + src/game/FleeingMovementGenerator.cpp | 13 +++++++++---- src/game/FleeingMovementGenerator.h | 1 + src/game/HomeMovementGenerator.h | 1 + src/game/IdleMovementGenerator.h | 6 ++++-- src/game/MotionMaster.cpp | 3 +++ src/game/MovementGenerator.h | 11 +++++++++++ src/game/PointMovementGenerator.h | 3 ++- src/game/RandomMovementGenerator.h | 1 + src/game/TargetedMovementGenerator.cpp | 27 +++++++++++++++------------ src/game/TargetedMovementGenerator.h | 1 + src/game/WaypointMovementGenerator.h | 2 ++ src/shared/revision_nr.h | 2 +- 14 files changed, 61 insertions(+), 24 deletions(-) diff --git a/src/game/ConfusedMovementGenerator.cpp b/src/game/ConfusedMovementGenerator.cpp index 128b2374f..fbc3eb1e8 100644 --- a/src/game/ConfusedMovementGenerator.cpp +++ b/src/game/ConfusedMovementGenerator.cpp @@ -86,8 +86,12 @@ ConfusedMovementGenerator::_InitSpecific(Player &, bool &is_water_ok, bo } template -void -ConfusedMovementGenerator::Reset(T &unit) +void ConfusedMovementGenerator::Interrupt(T &unit) +{ +} + +template +void ConfusedMovementGenerator::Reset(T &unit) { i_nextMove = 1; i_nextMoveTime.Reset(0); @@ -96,8 +100,7 @@ ConfusedMovementGenerator::Reset(T &unit) } template -bool -ConfusedMovementGenerator::Update(T &unit, const uint32 &diff) +bool ConfusedMovementGenerator::Update(T &unit, const uint32 &diff) { if(!&unit) return true; @@ -154,6 +157,8 @@ void ConfusedMovementGenerator::Finalize(Creature &unit) template void ConfusedMovementGenerator::Initialize(Player &player); template void ConfusedMovementGenerator::Initialize(Creature &creature); +template void ConfusedMovementGenerator::Interrupt(Player &player); +template void ConfusedMovementGenerator::Interrupt(Creature &creature); template void ConfusedMovementGenerator::Reset(Player &player); template void ConfusedMovementGenerator::Reset(Creature &creature); template bool ConfusedMovementGenerator::Update(Player &player, const uint32 &diff); diff --git a/src/game/ConfusedMovementGenerator.h b/src/game/ConfusedMovementGenerator.h index 1686cc58f..e4cd7e65d 100644 --- a/src/game/ConfusedMovementGenerator.h +++ b/src/game/ConfusedMovementGenerator.h @@ -34,6 +34,7 @@ class MANGOS_DLL_SPEC ConfusedMovementGenerator void Initialize(T &); void Finalize(T &); + void Interrupt(T &); void Reset(T &); bool Update(T &, const uint32 &); diff --git a/src/game/FleeingMovementGenerator.cpp b/src/game/FleeingMovementGenerator.cpp index 67a6cb732..7ec9f10e9 100644 --- a/src/game/FleeingMovementGenerator.cpp +++ b/src/game/FleeingMovementGenerator.cpp @@ -341,15 +341,18 @@ void FleeingMovementGenerator::Finalize(Creature &owner) } template -void -FleeingMovementGenerator::Reset(T &owner) +void FleeingMovementGenerator::Interrupt(T &owner) +{ +} + +template +void FleeingMovementGenerator::Reset(T &owner) { Initialize(owner); } template -bool -FleeingMovementGenerator::Update(T &owner, const uint32 & time_diff) +bool FleeingMovementGenerator::Update(T &owner, const uint32 & time_diff) { if( !&owner || !owner.isAlive() ) return false; @@ -386,6 +389,8 @@ template bool FleeingMovementGenerator::_getPoint(Player &, float &, flo template bool FleeingMovementGenerator::_getPoint(Creature &, float &, float &, float &); template void FleeingMovementGenerator::_setTargetLocation(Player &); template void FleeingMovementGenerator::_setTargetLocation(Creature &); +template void FleeingMovementGenerator::Interrupt(Player &); +template void FleeingMovementGenerator::Interrupt(Creature &); template void FleeingMovementGenerator::Reset(Player &); template void FleeingMovementGenerator::Reset(Creature &); template bool FleeingMovementGenerator::Update(Player &, const uint32 &); diff --git a/src/game/FleeingMovementGenerator.h b/src/game/FleeingMovementGenerator.h index b0cc24fd0..47290382d 100644 --- a/src/game/FleeingMovementGenerator.h +++ b/src/game/FleeingMovementGenerator.h @@ -32,6 +32,7 @@ class MANGOS_DLL_SPEC FleeingMovementGenerator void Initialize(T &); void Finalize(T &); + void Interrupt(T &); void Reset(T &); bool Update(T &, const uint32 &); diff --git a/src/game/HomeMovementGenerator.h b/src/game/HomeMovementGenerator.h index 9c2dc7310..af6f68c05 100644 --- a/src/game/HomeMovementGenerator.h +++ b/src/game/HomeMovementGenerator.h @@ -39,6 +39,7 @@ class MANGOS_DLL_SPEC HomeMovementGenerator void Initialize(Creature &); void Finalize(Creature &) {} + void Interrupt(Creature &) {} void Reset(Creature &); bool Update(Creature &, const uint32 &); void modifyTravelTime(uint32 travel_time) { i_travel_timer = travel_time; } diff --git a/src/game/IdleMovementGenerator.h b/src/game/IdleMovementGenerator.h index ad3cbc815..56a142c4d 100644 --- a/src/game/IdleMovementGenerator.h +++ b/src/game/IdleMovementGenerator.h @@ -25,8 +25,9 @@ class MANGOS_DLL_SPEC IdleMovementGenerator : public MovementGenerator { public: - void Initialize(Unit &) { } - void Finalize(Unit &) { } + void Initialize(Unit &) {} + void Finalize(Unit &) {} + void Interrupt(Unit &) {} void Reset(Unit &); bool Update(Unit &, const uint32 &) { return true; } MovementGeneratorType GetMovementGeneratorType() { return IDLE_MOTION_TYPE; } @@ -41,6 +42,7 @@ class MANGOS_DLL_SPEC DistractMovementGenerator : public MovementGenerator void Initialize(Unit& owner); void Finalize(Unit& owner); + void Interrupt(Unit& ) {} void Reset(Unit& owner) { Initialize(owner); } bool Update(Unit& owner, const uint32& time_diff); MovementGeneratorType GetMovementGeneratorType() { return DISTRACT_MOTION_TYPE; } diff --git a/src/game/MotionMaster.cpp b/src/game/MotionMaster.cpp index 97701de8c..94cbdb082 100644 --- a/src/game/MotionMaster.cpp +++ b/src/game/MotionMaster.cpp @@ -434,6 +434,9 @@ void MotionMaster::Mutate(MovementGenerator *m) default: break; } + + if (!empty()) + top()->Interrupt(*i_owner); } m->Initialize(*i_owner); push(m); diff --git a/src/game/MovementGenerator.h b/src/game/MovementGenerator.h index 3cc3a9d59..bd77fb00e 100644 --- a/src/game/MovementGenerator.h +++ b/src/game/MovementGenerator.h @@ -33,9 +33,14 @@ class MANGOS_DLL_SPEC MovementGenerator public: virtual ~MovementGenerator(); + // called before adding movement generator to motion stack virtual void Initialize(Unit &) = 0; + // called aftre remove movement generator from motion stack virtual void Finalize(Unit &) = 0; + // called before lost top position (before push new movement generator above) + virtual void Interrupt(Unit &) = 0; + // called after return movement generator to top position (after remove above movement generator) virtual void Reset(Unit &) = 0; virtual bool Update(Unit &, const uint32 &time_diff) = 0; @@ -63,6 +68,11 @@ class MANGOS_DLL_SPEC MovementGeneratorMedium : public MovementGenerator //u->AssertIsType(); (static_cast(this))->Finalize(*((T*)&u)); } + void Interrupt(Unit &u) + { + //u->AssertIsType(); + (static_cast(this))->Interrupt(*((T*)&u)); + } void Reset(Unit &u) { //u->AssertIsType(); @@ -77,6 +87,7 @@ class MANGOS_DLL_SPEC MovementGeneratorMedium : public MovementGenerator // will not link if not overridden in the generators void Initialize(T &u); void Finalize(T &u); + void Interrupt(T &u); void Reset(T &u); bool Update(T &u, const uint32 &time_diff); }; diff --git a/src/game/PointMovementGenerator.h b/src/game/PointMovementGenerator.h index e2ef7d25a..0d0756952 100644 --- a/src/game/PointMovementGenerator.h +++ b/src/game/PointMovementGenerator.h @@ -34,7 +34,8 @@ class MANGOS_DLL_SPEC PointMovementGenerator void Initialize(T &); void Finalize(T &){} - void Reset(T &unit){unit.StopMoving();} + void Interrupt(T &) {} + void Reset(T &unit){ unit.StopMoving(); } bool Update(T &, const uint32 &diff); void MovementInform(T &); diff --git a/src/game/RandomMovementGenerator.h b/src/game/RandomMovementGenerator.h index 26ae1f123..d2ecdd51c 100644 --- a/src/game/RandomMovementGenerator.h +++ b/src/game/RandomMovementGenerator.h @@ -33,6 +33,7 @@ class MANGOS_DLL_SPEC RandomMovementGenerator void _setRandomLocation(T &); void Initialize(T &); void Finalize(T &) {} + void Interrupt(T &) {} void Reset(T &); bool Update(T &, const uint32 &); void UpdateMapPosition(uint32 mapid, float &x ,float &y, float &z) diff --git a/src/game/TargetedMovementGenerator.cpp b/src/game/TargetedMovementGenerator.cpp index 0c80e09bf..6cfe5b2ed 100644 --- a/src/game/TargetedMovementGenerator.cpp +++ b/src/game/TargetedMovementGenerator.cpp @@ -89,6 +89,12 @@ TargetedMovementGenerator::_setTargetLocation(T &owner) } template<> +void TargetedMovementGenerator::Initialize(Player &owner) +{ + _setTargetLocation(owner); +} + +template<> void TargetedMovementGenerator::Initialize(Creature &owner) { if (owner.isInCombat()) @@ -113,29 +119,25 @@ void TargetedMovementGenerator::UpdateFinalDistance(float fDistance) i_recalculateTravel = true; } -template<> -void TargetedMovementGenerator::Initialize(Player &owner) +template +void TargetedMovementGenerator::Finalize(T &owner) { - _setTargetLocation(owner); + owner.clearUnitState(UNIT_STAT_CHASE | UNIT_STAT_FOLLOW); } template -void -TargetedMovementGenerator::Finalize(T &owner) +void TargetedMovementGenerator::Interrupt(T &owner) { - owner.clearUnitState(UNIT_STAT_CHASE); } template -void -TargetedMovementGenerator::Reset(T &owner) +void TargetedMovementGenerator::Reset(T &owner) { Initialize(owner); } template -bool -TargetedMovementGenerator::Update(T &owner, const uint32 & time_diff) +bool TargetedMovementGenerator::Update(T &owner, const uint32 & time_diff) { if (!i_target.isValid() || !i_target->IsInWorld()) return false; @@ -207,8 +209,7 @@ TargetedMovementGenerator::Update(T &owner, const uint32 & time_diff) } template -Unit* -TargetedMovementGenerator::GetTarget() const +Unit* TargetedMovementGenerator::GetTarget() const { return i_target.getTarget(); } @@ -217,6 +218,8 @@ template void TargetedMovementGenerator::_setTargetLocation(Player &); template void TargetedMovementGenerator::_setTargetLocation(Creature &); template void TargetedMovementGenerator::Finalize(Player &); template void TargetedMovementGenerator::Finalize(Creature &); +template void TargetedMovementGenerator::Interrupt(Player &); +template void TargetedMovementGenerator::Interrupt(Creature &); template void TargetedMovementGenerator::Reset(Player &); template void TargetedMovementGenerator::Reset(Creature &); template bool TargetedMovementGenerator::Update(Player &, const uint32 &); diff --git a/src/game/TargetedMovementGenerator.h b/src/game/TargetedMovementGenerator.h index ee3e5a743..250c31db5 100644 --- a/src/game/TargetedMovementGenerator.h +++ b/src/game/TargetedMovementGenerator.h @@ -47,6 +47,7 @@ class MANGOS_DLL_SPEC TargetedMovementGenerator void Initialize(T &); void Finalize(T &); + void Interrupt(T &); void Reset(T &); bool Update(T &, const uint32 &); MovementGeneratorType GetMovementGeneratorType() { return TARGETED_MOTION_TYPE; } diff --git a/src/game/WaypointMovementGenerator.h b/src/game/WaypointMovementGenerator.h index 62b471e8b..bf92d60cf 100644 --- a/src/game/WaypointMovementGenerator.h +++ b/src/game/WaypointMovementGenerator.h @@ -82,6 +82,7 @@ public PathMovementBase u.StopMoving(); LoadPath(u); } + void Interrupt(Creature &) {} void Finalize(Creature &) {} void Reset(Creature &u) { @@ -130,6 +131,7 @@ public PathMovementBase explicit FlightPathMovementGenerator(uint32 id, uint32 startNode = 0) : i_pathId(id) { i_currentNode = startNode; } void Initialize(Player &); void Finalize(Player &); + void Interrupt(Player &) {} void Reset(Player &) {} bool Update(Player &, const uint32 &); MovementGeneratorType GetMovementGeneratorType() { return FLIGHT_MOTION_TYPE; } diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 2e0bca581..f6c1d0a29 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 "9187" + #define REVISION_NR "9188" #endif // __REVISION_NR_H__ -- 2.11.4.GIT