1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-26 15:39:51 +00:00

Merge branch 'bitter_and_very_negative' into 'master'

Fix modstat for negative numbers

Closes #6870

See merge request OpenMW/openmw!2129
This commit is contained in:
psi29a 2022-07-12 22:01:44 +00:00
commit f26079b2b8

View File

@ -43,18 +43,24 @@ namespace
void modStat(MWMechanics::AttributeValue& stat, float amount)
{
float base = stat.getBase();
float modifier = stat.getModifier() - stat.getDamage();
float modified = base + modifier;
if(modified <= 0.f && amount < 0.f)
amount = 0.f;
else if(amount < 0.f && modified + amount < 0.f)
amount = -modified;
else if((modifier <= 0.f || base >= 100.f) && amount > 0.f)
const float base = stat.getBase();
const float modifier = stat.getModifier() - stat.getDamage();
const float modified = base + modifier;
// Clamp to 100 unless base < 100 and we have a fortification going
if((modifier <= 0.f || base >= 100.f) && amount > 0.f)
amount = std::clamp(100.f - modified, 0.f, amount);
stat.setBase(std::min(base + amount, 100.f), true);
modifier += base - stat.getBase() + amount;
stat.setModifier(modifier);
// Clamp the modified value in a way that doesn't properly account for negative numbers
float newModified = modified + amount;
if(newModified < 0.f)
{
if(modified >= 0.f)
newModified = 0.f;
else if(newModified < modified)
newModified = modified;
}
// Calculate damage/fortification based on the clamped base value
stat.setBase(std::clamp(base + amount, 0.f, 100.f), true);
stat.setModifier(newModified - stat.getBase());
}
}