diff options
author | Treeston <treeston.mmoc@gmail.com> | 2018-04-06 18:09:55 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2021-09-24 23:37:43 +0200 |
commit | 14939204955d1a24fe465cdfcbf307daf3ce4f09 (patch) | |
tree | 18e2bc2c0fa726bdcea65384c99742805e6d0cdf /src/server/game/Movement/MotionMaster.h | |
parent | 27fa6f3e341bb5a52b8c9b37b5a018d40b8e88a5 (diff) |
Core/Movement: Replace old TargetedMovementGenerator into ChaseMovementGenerator and FollowMovementGenerator, full rewrite for both.
- Chase to angle is now functional. Pets use this to chase behind the target. Closes #19925.
- Chase to arbitrary range interval works. Not used anywhere, but you can technically make hunter-like mobs.
- Pets now follow the hunter cleanly and without stutter stepping. Also fix some other things. Closes #8924.
(cherry picked from commit 2a84562dc85516f432bb1e5de9add23c28b26ce4)
Diffstat (limited to 'src/server/game/Movement/MotionMaster.h')
-rw-r--r-- | src/server/game/Movement/MotionMaster.h | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/server/game/Movement/MotionMaster.h b/src/server/game/Movement/MotionMaster.h index 79050edadd5..f03f553e288 100644 --- a/src/server/game/Movement/MotionMaster.h +++ b/src/server/game/Movement/MotionMaster.h @@ -20,6 +20,7 @@ #include "Common.h" #include "Errors.h" +#include "ObjectDefines.h" #include "ObjectGuid.h" #include "Optional.h" #include "Position.h" @@ -93,6 +94,35 @@ enum RotateDirection ROTATE_DIRECTION_RIGHT }; +struct ChaseRange +{ + ChaseRange(float range) : MinRange(range > CONTACT_DISTANCE ? 0 : range - CONTACT_DISTANCE), MinTolerance(range), MaxRange(range + CONTACT_DISTANCE), MaxTolerance(range) {} + ChaseRange(float min, float max) : MinRange(min), MinTolerance(std::min(min + CONTACT_DISTANCE, (min + max) / 2)), MaxRange(max), MaxTolerance(std::max(max - CONTACT_DISTANCE, MinTolerance)) {} + ChaseRange(float min, float tMin, float tMax, float max) : MinRange(min), MinTolerance(tMin), MaxRange(max), MaxTolerance(tMax) {} + + // this contains info that informs how we should path! + float MinRange; // we have to move if we are within this range... (min. attack range) + float MinTolerance; // ...and if we are, we will move this far away + float MaxRange; // we have to move if we are outside this range... (max. attack range) + float MaxTolerance; // ...and if we are, we will move into this range +}; + +struct ChaseAngle +{ + ChaseAngle(float angle, float tol = M_PI_4) : RelativeAngle(Position::NormalizeOrientation(angle)), Tolerance(tol) {} + + float RelativeAngle; // we want to be at this angle relative to the target (0 = front, M_PI = back) + float Tolerance; // but we'll tolerate anything within +- this much + + float UpperBound() const { return Position::NormalizeOrientation(RelativeAngle + Tolerance); } + float LowerBound() const { return Position::NormalizeOrientation(RelativeAngle - Tolerance); } + bool IsAngleOkay(float relAngle) const + { + float const diff = std::abs(relAngle - RelativeAngle); + return (std::min(diff, float(2 * M_PI) - diff) <= Tolerance); + } +}; + struct JumpArrivalCastArgs { uint32 SpellId; @@ -136,8 +166,9 @@ class TC_GAME_API MotionMaster void MoveIdle(); void MoveTargetedHome(); void MoveRandom(float spawndist = 0.0f); - void MoveFollow(Unit* target, float dist, float angle, MovementSlot slot = MOTION_SLOT_ACTIVE); - void MoveChase(Unit* target, float dist = 0.0f, float angle = 0.0f); + void MoveFollow(Unit* target, float dist, ChaseAngle angle, MovementSlot slot = MOTION_SLOT_ACTIVE); + void MoveChase(Unit* target, Optional<ChaseRange> dist = {}, Optional<ChaseAngle> angle = {}); + void MoveChase(Unit* target, float dist, float angle = 0.0f) { MoveChase(target, Optional<ChaseRange>(dist), Optional<ChaseAngle>(angle)); } void MoveConfused(); void MoveFleeing(Unit* enemy, uint32 time = 0); void MovePoint(uint32 id, Position const& pos, bool generatePath = true, Optional<float> finalOrient = {}) |