From 14939204955d1a24fe465cdfcbf307daf3ce4f09 Mon Sep 17 00:00:00 2001 From: Treeston Date: Fri, 6 Apr 2018 18:09:55 +0200 Subject: 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) --- src/server/game/Movement/MotionMaster.h | 35 +++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src/server/game/Movement/MotionMaster.h') 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 dist = {}, Optional angle = {}); + void MoveChase(Unit* target, float dist, float angle = 0.0f) { MoveChase(target, Optional(dist), Optional(angle)); } void MoveConfused(); void MoveFleeing(Unit* enemy, uint32 time = 0); void MovePoint(uint32 id, Position const& pos, bool generatePath = true, Optional finalOrient = {}) -- cgit v1.2.3