From 2bade602f4160f76a69c284ed4444d0a282b1c7e Mon Sep 17 00:00:00 2001 From: sanctum32 Date: Thu, 5 Oct 2023 15:03:15 +0300 Subject: [PATCH 1/6] Core/Movement: one more attempt to fix follow motion checks - added distance checks --- .../FollowMovementGenerator.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp index 42499002d60..34913e28c3c 100644 --- a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp @@ -29,7 +29,7 @@ #include // Helpers -inline UnitMoveType SelectSpeedType(uint32 moveFlags) +static UnitMoveType SelectSpeedType(uint32 moveFlags) { if (moveFlags & MOVEMENTFLAG_FLYING) { @@ -53,12 +53,18 @@ inline UnitMoveType SelectSpeedType(uint32 moveFlags) return MOVE_RUN; } -inline bool IsTargetMoving(Unit const* target) +static bool IsTargetMoving(Unit const* owner, Unit const* target, float distance) { - return target->HasUnitMovementFlag(MOVEMENTFLAG_FORWARD | MOVEMENTFLAG_BACKWARD | MOVEMENTFLAG_STRAFE_LEFT | MOVEMENTFLAG_STRAFE_RIGHT) || !target->movespline->Finalized(); + if (target->HasUnitMovementFlag(MOVEMENTFLAG_FORWARD | MOVEMENTFLAG_BACKWARD | MOVEMENTFLAG_STRAFE_LEFT | MOVEMENTFLAG_STRAFE_RIGHT) || !target->movespline->Finalized()) + return true; + + if (owner->GetExactDistSq(target) > square(owner->GetCombatReach() + target->GetCombatReach() + distance)) + return true; + + return false; } -inline float GetVelocity(Unit* owner, Unit* target, bool catchUp) +static float GetVelocity(Unit* owner, Unit* target, bool catchUp) { float targetSpeed = 0.f; float velocity = 0.f; @@ -224,7 +230,7 @@ bool FollowMovementGenerator::Update(Unit* owner, uint32 diff) { _followMovementTimer.Reset(FOLLOW_MOVEMENT_INTERVAL); - if (IsTargetMoving(target)) + if (IsTargetMoving(owner, target, _distance)) { _events.Reset(); LaunchMovement(owner); From 435c26a683ee93267592f0060b1381ccbe104844 Mon Sep 17 00:00:00 2001 From: sanctum32 Date: Thu, 5 Oct 2023 15:11:29 +0300 Subject: [PATCH 2/6] added const correctness to few other Follow motion helper functions --- .../MovementGenerators/FollowMovementGenerator.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp index 34913e28c3c..8964518230f 100644 --- a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp @@ -64,7 +64,7 @@ static bool IsTargetMoving(Unit const* owner, Unit const* target, float distance return false; } -static float GetVelocity(Unit* owner, Unit* target, bool catchUp) +static float GetVelocity(Unit const* owner, Unit const* target, bool catchUp) { float targetSpeed = 0.f; float velocity = 0.f; @@ -96,9 +96,9 @@ static float GetVelocity(Unit* owner, Unit* target, bool catchUp) return velocity; } -static void ApplyCatchUpMod(Unit* owner, Position dest, float& velocity) +static void ApplyCatchUpMod(Unit const* owner, Position dest, float& velocity) { - float distance = owner->GetExactDist2d(dest); + float const distance = owner->GetExactDist2d(dest); if (!dest.HasInArc(float(M_PI), owner)) // owner is falling back. Catch up AddPct(velocity, ((distance / velocity) * 100.f)); @@ -106,7 +106,7 @@ static void ApplyCatchUpMod(Unit* owner, Position dest, float& velocity) AddPct(velocity, -((distance / velocity) * 100.f)); } -static void DoMovementInform(Unit* owner, Unit* target) +static void DoMovementInform(Unit const* owner, Unit const* target) { if (owner->GetTypeId() != TYPEID_UNIT) return; From cb173f1cf29a4e6d7a7b1e79427b724ebd6709e3 Mon Sep 17 00:00:00 2001 From: sanctum32 Date: Tue, 10 Oct 2023 07:15:31 +0300 Subject: [PATCH 3/6] Applied requested changes --- .../FollowMovementGenerator.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp index 8964518230f..6499eab8deb 100644 --- a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp @@ -53,15 +53,14 @@ static UnitMoveType SelectSpeedType(uint32 moveFlags) return MOVE_RUN; } -static bool IsTargetMoving(Unit const* owner, Unit const* target, float distance) +static bool IsTargetMoving(Unit const* target) { - if (target->HasUnitMovementFlag(MOVEMENTFLAG_FORWARD | MOVEMENTFLAG_BACKWARD | MOVEMENTFLAG_STRAFE_LEFT | MOVEMENTFLAG_STRAFE_RIGHT) || !target->movespline->Finalized()) - return true; - - if (owner->GetExactDistSq(target) > square(owner->GetCombatReach() + target->GetCombatReach() + distance)) - return true; + return target->HasUnitMovementFlag(MOVEMENTFLAG_FORWARD | MOVEMENTFLAG_BACKWARD | MOVEMENTFLAG_STRAFE_LEFT | MOVEMENTFLAG_STRAFE_RIGHT) || !target->movespline->Finalized(); +} - return false; +static bool IsWithinRadiusDistance(Unit const* owner, Unit const* target, float followDistance) +{ + return owner->GetExactDistSq(target) > square(followDistance); } static float GetVelocity(Unit const* owner, Unit const* target, bool catchUp) @@ -230,7 +229,7 @@ bool FollowMovementGenerator::Update(Unit* owner, uint32 diff) { _followMovementTimer.Reset(FOLLOW_MOVEMENT_INTERVAL); - if (IsTargetMoving(owner, target, _distance)) + if (IsTargetMoving(target) || IsWithinRadiusDistance(owner, target, _distance)) { _events.Reset(); LaunchMovement(owner); From f08b88023ce3d58b5f2a0c0968ef3d58b512fc6d Mon Sep 17 00:00:00 2001 From: sanctum32 Date: Tue, 10 Oct 2023 07:18:06 +0300 Subject: [PATCH 4/6] Minor rename --- .../Movement/MovementGenerators/FollowMovementGenerator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp index 6499eab8deb..257c41d6b4c 100644 --- a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp @@ -58,7 +58,7 @@ static bool IsTargetMoving(Unit const* target) return target->HasUnitMovementFlag(MOVEMENTFLAG_FORWARD | MOVEMENTFLAG_BACKWARD | MOVEMENTFLAG_STRAFE_LEFT | MOVEMENTFLAG_STRAFE_RIGHT) || !target->movespline->Finalized(); } -static bool IsWithinRadiusDistance(Unit const* owner, Unit const* target, float followDistance) +static bool IsWithinFollowDistance(Unit const* owner, Unit const* target, float followDistance) { return owner->GetExactDistSq(target) > square(followDistance); } @@ -229,7 +229,7 @@ bool FollowMovementGenerator::Update(Unit* owner, uint32 diff) { _followMovementTimer.Reset(FOLLOW_MOVEMENT_INTERVAL); - if (IsTargetMoving(target) || IsWithinRadiusDistance(owner, target, _distance)) + if (IsTargetMoving(target) || IsWithinFollowDistance(owner, target, _distance)) { _events.Reset(); LaunchMovement(owner); From 60b364987fcd723e61244a63e491e04bad3cfcdf Mon Sep 17 00:00:00 2001 From: sanctum32 Date: Tue, 10 Oct 2023 07:20:48 +0300 Subject: [PATCH 5/6] One more rename for better readibility - i'm sorry, bit sleepy --- .../Movement/MovementGenerators/FollowMovementGenerator.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp index 257c41d6b4c..526823a19ca 100644 --- a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp @@ -58,9 +58,9 @@ static bool IsTargetMoving(Unit const* target) return target->HasUnitMovementFlag(MOVEMENTFLAG_FORWARD | MOVEMENTFLAG_BACKWARD | MOVEMENTFLAG_STRAFE_LEFT | MOVEMENTFLAG_STRAFE_RIGHT) || !target->movespline->Finalized(); } -static bool IsWithinFollowDistance(Unit const* owner, Unit const* target, float followDistance) +static bool IsFarFromFollowDistance(Unit const* owner, Unit const* target, float followDistance) { - return owner->GetExactDistSq(target) > square(followDistance); + return owner->GetExactDistSq(target) > square(followDistance; } static float GetVelocity(Unit const* owner, Unit const* target, bool catchUp) @@ -229,7 +229,7 @@ bool FollowMovementGenerator::Update(Unit* owner, uint32 diff) { _followMovementTimer.Reset(FOLLOW_MOVEMENT_INTERVAL); - if (IsTargetMoving(target) || IsWithinFollowDistance(owner, target, _distance)) + if (IsTargetMoving(target) || IsFarFromFollowDistance(owner, target, _distance)) { _events.Reset(); LaunchMovement(owner); From bf81196d0a38a448210753f5278dd70005aa9e49 Mon Sep 17 00:00:00 2001 From: sanctum32 Date: Tue, 10 Oct 2023 07:21:27 +0300 Subject: [PATCH 6/6] build fix --- .../Movement/MovementGenerators/FollowMovementGenerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp index 526823a19ca..4ce84ca2db5 100644 --- a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp @@ -60,7 +60,7 @@ static bool IsTargetMoving(Unit const* target) static bool IsFarFromFollowDistance(Unit const* owner, Unit const* target, float followDistance) { - return owner->GetExactDistSq(target) > square(followDistance; + return owner->GetExactDistSq(target) > square(followDistance); } static float GetVelocity(Unit const* owner, Unit const* target, bool catchUp)