Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Core/Movement: one more attempt to fix follow motion checks - added distance checks #422

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <optional>

// Helpers
inline UnitMoveType SelectSpeedType(uint32 moveFlags)
static UnitMoveType SelectSpeedType(uint32 moveFlags)
{
if (moveFlags & MOVEMENTFLAG_FLYING)
{
Expand All @@ -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))
sanctum32 marked this conversation as resolved.
Show resolved Hide resolved
return true;

return false;
}

inline 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;
Expand Down Expand Up @@ -90,17 +96,17 @@ inline 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));
else if (distance < 3.f)
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;
Expand Down Expand Up @@ -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);
Expand Down