With [Game] real time combat on: - An attack's fatigue cost is paid when the swing is released, not when it lands. The base cost (fFatigueAttackBase plus fFatigueAttackMult times encumbrance) scales from half at no wind-up to full at full wind-up; the weapon part stays weight * strength * fWeaponFatigueMult. - No weapon attack can start at zero fatigue or below the new [Game] attack fatigue threshold (0.1 of max). The player gets a "too tired to attack" message once per press; combat AI waits for fatigue to recover instead of winding up. Spells aren't affected. - Below [Game] attack fatigue cap (0.5 of max), the strongest possible attack falls linearly to a quarter strength at zero fatigue. The rules are in mwmechanics/stamina.cpp, with unit tests. Behavior with real time combat off is unchanged. Closes #21 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
86 lines
3.3 KiB
C++
86 lines
3.3 KiB
C++
#include <apps/openmw/mwmechanics/stamina.hpp>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
namespace
|
|
{
|
|
using namespace MWMechanics;
|
|
|
|
// Morrowind-style GMST defaults: fFatigueAttackBase 2, fFatigueAttackMult 0, fWeaponFatigueMult 1.
|
|
constexpr float base = 2.f;
|
|
constexpr float encumbranceMult = 0.f;
|
|
constexpr float weaponMult = 1.f;
|
|
|
|
TEST(MWMechanicsStaminaTest, fullWindUpCostsTheClassicFullStrengthCost)
|
|
{
|
|
EXPECT_FLOAT_EQ(getAttackFatigueCost(base, encumbranceMult, 0.5f, 20.f, weaponMult, 1.f), 22.f);
|
|
}
|
|
|
|
TEST(MWMechanicsStaminaTest, quickTapCostsHalfTheBaseAndNothingForTheWeapon)
|
|
{
|
|
EXPECT_FLOAT_EQ(getAttackFatigueCost(base, encumbranceMult, 0.5f, 20.f, weaponMult, 0.f), 1.f);
|
|
}
|
|
|
|
TEST(MWMechanicsStaminaTest, costGrowsWithWindUpAndWeaponWeight)
|
|
{
|
|
const float light = getAttackFatigueCost(base, encumbranceMult, 0.f, 5.f, weaponMult, 0.5f);
|
|
const float heavy = getAttackFatigueCost(base, encumbranceMult, 0.f, 30.f, weaponMult, 0.5f);
|
|
const float heavyFull = getAttackFatigueCost(base, encumbranceMult, 0.f, 30.f, weaponMult, 1.f);
|
|
EXPECT_LT(light, heavy);
|
|
EXPECT_LT(heavy, heavyFull);
|
|
EXPECT_FLOAT_EQ(heavy, 1.5f + 15.f);
|
|
}
|
|
|
|
TEST(MWMechanicsStaminaTest, encumbranceAddsToTheBaseCost)
|
|
{
|
|
EXPECT_FLOAT_EQ(getAttackFatigueCost(2.f, 4.f, 0.5f, 0.f, weaponMult, 1.f), 4.f);
|
|
EXPECT_FLOAT_EQ(getAttackFatigueCost(2.f, 4.f, 0.5f, 0.f, weaponMult, 0.f), 2.f);
|
|
}
|
|
|
|
TEST(MWMechanicsStaminaTest, costClampsStrengthAndIsNeverNegative)
|
|
{
|
|
EXPECT_FLOAT_EQ(getAttackFatigueCost(base, encumbranceMult, 0.f, 10.f, weaponMult, 2.f),
|
|
getAttackFatigueCost(base, encumbranceMult, 0.f, 10.f, weaponMult, 1.f));
|
|
EXPECT_FLOAT_EQ(getAttackFatigueCost(-5.f, 0.f, 0.f, 0.f, weaponMult, 1.f), 0.f);
|
|
}
|
|
|
|
TEST(MWMechanicsStaminaTest, thresholdBlocksAttacksBelowTheShare)
|
|
{
|
|
EXPECT_TRUE(hasFatigueToAttack(10.f, 100.f, 0.1f));
|
|
EXPECT_FALSE(hasFatigueToAttack(9.9f, 100.f, 0.1f));
|
|
EXPECT_TRUE(hasFatigueToAttack(100.f, 100.f, 0.1f));
|
|
}
|
|
|
|
TEST(MWMechanicsStaminaTest, noAttacksAtZeroOrNegativeFatigueEvenWithNoThreshold)
|
|
{
|
|
EXPECT_FALSE(hasFatigueToAttack(0.f, 100.f, 0.f));
|
|
EXPECT_FALSE(hasFatigueToAttack(-3.f, 100.f, 0.f));
|
|
EXPECT_TRUE(hasFatigueToAttack(0.1f, 100.f, 0.f));
|
|
}
|
|
|
|
TEST(MWMechanicsStaminaTest, zeroMaxFatigueOnlyNeedsPositiveFatigue)
|
|
{
|
|
EXPECT_TRUE(hasFatigueToAttack(1.f, 0.f, 0.5f));
|
|
EXPECT_FALSE(hasFatigueToAttack(0.f, 0.f, 0.5f));
|
|
}
|
|
|
|
TEST(MWMechanicsStaminaTest, capIsFullAboveTheCapShare)
|
|
{
|
|
EXPECT_FLOAT_EQ(getAttackStrengthCap(100.f, 100.f, 0.5f), 1.f);
|
|
EXPECT_FLOAT_EQ(getAttackStrengthCap(50.f, 100.f, 0.5f), 1.f);
|
|
}
|
|
|
|
TEST(MWMechanicsStaminaTest, capFallsLinearlyToAQuarterAtZeroFatigue)
|
|
{
|
|
EXPECT_FLOAT_EQ(getAttackStrengthCap(0.f, 100.f, 0.5f), sMinAttackStrengthCap);
|
|
EXPECT_FLOAT_EQ(getAttackStrengthCap(25.f, 100.f, 0.5f), 0.625f);
|
|
EXPECT_FLOAT_EQ(getAttackStrengthCap(-10.f, 100.f, 0.5f), sMinAttackStrengthCap);
|
|
}
|
|
|
|
TEST(MWMechanicsStaminaTest, capDisabledByZeroShareOrZeroMaxFatigue)
|
|
{
|
|
EXPECT_FLOAT_EQ(getAttackStrengthCap(0.f, 100.f, 0.f), 1.f);
|
|
EXPECT_FLOAT_EQ(getAttackStrengthCap(0.f, 0.f, 0.5f), 1.f);
|
|
}
|
|
}
|