diff options
author | Chaouki Dhib <chaodhib@gmail.com> | 2016-04-11 16:52:23 +0200 |
---|---|---|
committer | DDuarte <dnpd.dd@gmail.com> | 2016-04-16 01:31:15 +0100 |
commit | d26b0419c3fc5aa7e3cfee25170453770027eae9 (patch) | |
tree | 16671b3e92443c75e067f4c155961cfc6a0f219f | |
parent | 4ab56dc309dbbea78d5f14266b496dd3b9a79dde (diff) |
Core/Movement: Added a wrapper method in MotionMaster for a unit to move toward another unit and stop once it reaches the target at a certain distance. (#16806)
(cherry picked from commit 97b053d2034825c58246d79ebdbb3eb23fc2f28f)
-rw-r--r-- | src/server/game/Movement/MotionMaster.cpp | 21 | ||||
-rw-r--r-- | src/server/game/Movement/MotionMaster.h | 6 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index 931c3602612..da9cbed9374 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -296,6 +296,27 @@ void MotionMaster::MovePoint(uint32 id, float x, float y, float z, bool generate } } +void MotionMaster::MoveCloserAndStop(uint32 id, Unit* target, float distance) +{ + float distanceToTravel = _owner->GetExactDist2d(target) - distance; + if (distanceToTravel > 0.0f) + { + float angle = _owner->GetAngle(target); + float destx = _owner->GetPositionX() + distanceToTravel * std::cos(angle); + float desty = _owner->GetPositionY() + distanceToTravel * std::sin(angle); + MovePoint(id, destx, desty, target->GetPositionZ()); + } + else + { + // we are already close enough. We just need to turn toward the target without changing position. + Movement::MoveSplineInit init(_owner); + init.MoveTo(_owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZMinusOffset()); + init.SetFacing(target); + init.Launch(); + Mutate(new EffectMovementGenerator(id), MOTION_SLOT_ACTIVE); + } +} + void MotionMaster::MoveLand(uint32 id, Position const& pos) { float x, y, z; diff --git a/src/server/game/Movement/MotionMaster.h b/src/server/game/Movement/MotionMaster.h index 4f396f80d3b..07c928da63b 100644 --- a/src/server/game/Movement/MotionMaster.h +++ b/src/server/game/Movement/MotionMaster.h @@ -173,6 +173,12 @@ class TC_GAME_API MotionMaster //: private std::stack<MovementGenerator *> { MovePoint(id, pos.m_positionX, pos.m_positionY, pos.m_positionZ, generatePath); } void MovePoint(uint32 id, float x, float y, float z, bool generatePath = true); + /* Makes the unit move toward the target until it is at a certain distance from it. The unit then stops. + Only works in 2D. + This method doesn't account for any movement done by the target. in other words, it only works if the target is stationary. + */ + void MoveCloserAndStop(uint32 id, Unit* target, float distance); + // These two movement types should only be used with creatures having landing/takeoff animations void MoveLand(uint32 id, Position const& pos); void MoveTakeoff(uint32 id, Position const& pos); |