From dc468dd139a7560446b0a88c8639473c69292e3b Mon Sep 17 00:00:00 2001 From: Allofich Date: Sat, 25 Jun 2016 00:38:59 +0900 Subject: [PATCH] Fix magicka and fatigue calculations from fortifying attributes --- apps/openmw/mwmechanics/actors.cpp | 7 +++++-- apps/openmw/mwmechanics/creaturestats.cpp | 4 +++- apps/openmw/mwmechanics/stat.cpp | 18 ------------------ apps/openmw/mwmechanics/stat.hpp | 4 ---- 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index fa398950d..f28e2cc52 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -425,7 +425,9 @@ namespace MWMechanics DynamicStat magicka = creatureStats.getMagicka(); float diff = (static_cast(magickaFactor*intelligence)) - magicka.getBase(); - magicka.modify(diff); + float currentToBaseRatio = (magicka.getCurrent() / magicka.getBase()); + magicka.setModified(magicka.getModified() + diff, 0); + magicka.setCurrent(magicka.getBase() * currentToBaseRatio); creatureStats.setMagicka(magicka); } @@ -553,8 +555,9 @@ namespace MWMechanics DynamicStat stat = creatureStats.getDynamic(i); stat.setModifier(effects.get(ESM::MagicEffect::FortifyHealth+i).getMagnitude() - effects.get(ESM::MagicEffect::DrainHealth+i).getMagnitude(), + // Magicka can be decreased below zero due to a fortify effect wearing off // Fatigue can be decreased below zero meaning the actor will be knocked out - i == 2); + i == 1 || i == 2); creatureStats.setDynamic(i, stat); } diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index e33a6f7bd..be51cea25 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -157,7 +157,9 @@ namespace MWMechanics int endurance = getAttribute(ESM::Attribute::Endurance).getModified(); DynamicStat fatigue = getFatigue(); float diff = (strength+willpower+agility+endurance) - fatigue.getBase(); - fatigue.modify(diff); + float currentToBaseRatio = (fatigue.getCurrent() / fatigue.getBase()); + fatigue.setModified(fatigue.getModified() + diff, 0); + fatigue.setCurrent(fatigue.getBase() * currentToBaseRatio); setFatigue(fatigue); } } diff --git a/apps/openmw/mwmechanics/stat.cpp b/apps/openmw/mwmechanics/stat.cpp index 6eb5e0246..cf1f228c0 100644 --- a/apps/openmw/mwmechanics/stat.cpp +++ b/apps/openmw/mwmechanics/stat.cpp @@ -33,18 +33,6 @@ namespace MWMechanics mBase = mModified = value; } template - void Stat::modify(const T& diff) - { - mBase += diff; - if(mBase >= static_cast(0)) - mModified += diff; - else - { - mModified += diff - mBase; - mBase = static_cast(0); - } - } - template void Stat::setBase (const T& value) { T diff = value - mBase; @@ -139,12 +127,6 @@ namespace MWMechanics mCurrent = getModified(); } template - void DynamicStat::modify (const T& diff, bool allowCurrentDecreaseBelowZero) - { - mStatic.modify (diff); - setCurrent (getCurrent()+diff, allowCurrentDecreaseBelowZero); - } - template void DynamicStat::setCurrent (const T& value, bool allowDecreaseBelowZero) { if (value > mCurrent) diff --git a/apps/openmw/mwmechanics/stat.hpp b/apps/openmw/mwmechanics/stat.hpp index c075f5fa7..5b5800634 100644 --- a/apps/openmw/mwmechanics/stat.hpp +++ b/apps/openmw/mwmechanics/stat.hpp @@ -32,7 +32,6 @@ namespace MWMechanics /// Set base and modified to \a value. void set (const T& value); - void modify(const T& diff); /// Set base and adjust modified accordingly. void setBase (const T& value); @@ -85,9 +84,6 @@ namespace MWMechanics /// Set modified value an adjust base accordingly. void setModified (T value, const T& min, const T& max = std::numeric_limits::max()); - /// Change modified relatively. - void modify (const T& diff, bool allowCurrentDecreaseBelowZero=false); - void setCurrent (const T& value, bool allowDecreaseBelowZero = false); void setModifier (const T& modifier, bool allowCurrentDecreaseBelowZero=false);