Skip to content

Commit

Permalink
Add flooring and proper order to each speed factor
Browse files Browse the repository at this point in the history
Co-authored-by: cocosolos <[email protected]>
  • Loading branch information
Xaver-DaRed and cocosolos committed Sep 4, 2024
1 parent b3fd755 commit a5e84e6
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/map/entities/battleentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,32 +256,34 @@ uint8 CBattleEntity::GetSpeed()
}

// Gear penalties, Bolters Roll.
float additiveMods = static_cast<float>(getMod(Mod::MOVE_SPEED_STACKABLE));
uint8 additiveMods = static_cast<uint8>(getMod(Mod::MOVE_SPEED_STACKABLE));

// Quickening and Mazurka. They share a cap. Additive.
float effectAdditiveBonus = std::clamp<float>(getMod(Mod::MOVE_SPEED_QUICKENING) + getMod(Mod::MOVE_SPEED_MAZURKA), 0.0f, 10.0f);
uint8 effectAdditiveBonus = std::clamp<uint8>(getMod(Mod::MOVE_SPEED_QUICKENING) + getMod(Mod::MOVE_SPEED_MAZURKA), 0, 10);

// Flee.
float fleeFactor = std::clamp<float>(1.0f + static_cast<float>(getMod(Mod::MOVE_SPEED_FLEE)) / 100.0f, 1.0f, 2.0f);

// Positive movement speed from gear and from Atmas. Only highest applies. Multiplicative to base speed.
float gearBonus = 1.0f;
float gearFactor = 1.0f;

if (objtype == TYPE_PC)
{
gearBonus = std::clamp<float>(1.0f + static_cast<float>(getMaxGearMod(Mod::MOVE_SPEED_GEAR_BONUS)) / 100.0f, 1.0f, 1.25f);
gearFactor = std::clamp<float>(1.0f + static_cast<float>(getMaxGearMod(Mod::MOVE_SPEED_GEAR_BONUS)) / 100.0f, 1.0f, 1.25f);
}

// Gravity and Curse. They seem additive to each other and the sum seems to be multiplicative.
float weightPenalties = std::clamp<float>(1.0f - static_cast<float>(getMod(Mod::MOVE_SPEED_WEIGHT_PENALTY)) / 100.0f, 0.1f, 1.0f);
float weightFactor = std::clamp<float>(1.0f - static_cast<float>(getMod(Mod::MOVE_SPEED_WEIGHT_PENALTY)) / 100.0f, 0.1f, 1.0f);

// We have all the modifiers needed. Calculate final speed.
// Final speed = (base speed + addtive bonuses/penalties) * flee * positive bonus from gear * weight penalties
float modifiedSpeed = static_cast<float>(baseSpeed + additiveMods + effectAdditiveBonus) * fleeFactor * gearBonus * weightPenalties;

outputSpeed = static_cast<uint8>(modifiedSpeed);

// Set cap.
// This MUST BE DONE IN THIS ORDER. Using uint8 data type, we use that to floor.
outputSpeed = baseSpeed + additiveMods + effectAdditiveBonus;
outputSpeed = outputSpeed * fleeFactor;
outputSpeed = outputSpeed * gearFactor;
outputSpeed = outputSpeed * weightFactor;
// outputSpeed = outputSpeed * cheerFactor;

// Set cap (Default 80).
outputSpeed = std::clamp<uint8>(outputSpeed, 0, 80 + settings::get<int8>("map.SPEED_MOD"));

// Speed cap can be bypassed. Ex. Feast of swords. GM speed.
Expand Down

0 comments on commit a5e84e6

Please sign in to comment.