Core/Movement: Refactor jump speed calculation out of spell code

This commit is contained in:
Shauren
2023-03-06 00:14:42 +01:00
parent cdc09d29bc
commit 705d5701bf
4 changed files with 27 additions and 16 deletions

View File

@@ -107,7 +107,7 @@ enum UnitPetFlag : uint8
DEFINE_ENUM_FLAG(UnitPetFlag);
enum UnitMoveType
enum UnitMoveType : uint8
{
MOVE_WALK = 0,
MOVE_RUN = 1,

View File

@@ -1123,6 +1123,27 @@ void MotionMaster::LaunchMoveSpline(std::function<void(Movement::MoveSplineInit&
Add(movement);
}
void MotionMaster::CalculateJumpSpeeds(float dist, UnitMoveType moveType, float speedMultiplier, float minHeight, float maxHeight, float& speedXY, float& speedZ) const
{
float baseSpeed = _owner->IsControlledByPlayer() ? playerBaseMoveSpeed[moveType] : baseMoveSpeed[moveType];
if (Creature* creature = _owner->ToCreature())
baseSpeed *= creature->GetCreatureTemplate()->speed_run;
speedXY = std::min(baseSpeed * 3.0f * speedMultiplier, std::max(28.0f, _owner->GetSpeed(moveType) * 4.0f));
float duration = dist / speedXY;
float durationSqr = duration * duration;
float height;
if (durationSqr < minHeight * 8 / Movement::gravity)
height = minHeight;
else if (durationSqr > maxHeight * 8 / Movement::gravity)
height = maxHeight;
else
height = Movement::gravity * durationSqr / 8;
speedZ = std::sqrt(2 * Movement::gravity * height);
}
/******************** Private methods ********************/
void MotionMaster::ResolveDelayedActions()

View File

@@ -37,6 +37,7 @@ struct Position;
struct SplineChainLink;
struct SplineChainResumeInfo;
struct WaypointPath;
enum UnitMoveType : uint8;
namespace Movement
{
@@ -199,6 +200,9 @@ class TC_GAME_API MotionMaster
void MoveFormation(Unit* leader, float range, float angle, uint32 point1, uint32 point2);
void LaunchMoveSpline(std::function<void(Movement::MoveSplineInit& init)>&& initializer, uint32 id = 0, MovementGeneratorPriority priority = MOTION_PRIORITY_NORMAL, MovementGeneratorType type = EFFECT_MOTION_TYPE);
void CalculateJumpSpeeds(float dist, UnitMoveType moveType, float speedMultiplier, float minHeight, float maxHeight, float& speedXY, float& speedZ) const;
private:
typedef std::unique_ptr<MovementGenerator, MovementGeneratorDeleter> MovementGeneratorPointer;
typedef std::multiset<MovementGenerator*, MovementGeneratorComparator> MotionMasterContainer;

View File

@@ -830,29 +830,15 @@ void Spell::CalculateJumpSpeeds(SpellEffectInfo const* effInfo, float dist, floa
{
Unit* unitCaster = GetUnitCasterForEffectHandlers();
ASSERT(unitCaster);
float runSpeed = unitCaster->IsControlledByPlayer() ? playerBaseMoveSpeed[MOVE_RUN] : baseMoveSpeed[MOVE_RUN];
if (Creature* creature = unitCaster->ToCreature())
runSpeed *= creature->GetCreatureTemplate()->speed_run;
float multiplier = effInfo->Amplitude;
if (multiplier <= 0.0f)
multiplier = 1.0f;
speedXY = std::min(runSpeed * 3.0f * multiplier, std::max(28.0f, unitCaster->GetSpeed(MOVE_RUN) * 4.0f));
float duration = dist / speedXY;
float durationSqr = duration * duration;
float minHeight = effInfo->MiscValue ? effInfo->MiscValue / 10.0f : 0.5f; // Lower bound is blizzlike
float maxHeight = effInfo->MiscValueB ? effInfo->MiscValueB / 10.0f : 1000.0f; // Upper bound is unknown
float height;
if (durationSqr < minHeight * 8 / Movement::gravity)
height = minHeight;
else if (durationSqr > maxHeight * 8 / Movement::gravity)
height = maxHeight;
else
height = Movement::gravity * durationSqr / 8;
speedZ = std::sqrt(2 * Movement::gravity * height);
unitCaster->GetMotionMaster()->CalculateJumpSpeeds(dist, MOVE_RUN, multiplier, minHeight, maxHeight, speedXY, speedZ);
}
void Spell::EffectJump()