diff options
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 = {}) |