From 4e52c96cf58e7b0c8b59db490e12c850bed2f7ca Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Thu, 10 Feb 2022 20:31:27 +0100 Subject: [PATCH] Make Set/Mod[DynamicStat] work with negative values as in vanilla --- apps/openmw/mwgui/statswindow.cpp | 2 +- apps/openmw/mwscript/statsextensions.cpp | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwgui/statswindow.cpp b/apps/openmw/mwgui/statswindow.cpp index 0830af0744..49ee7698ee 100644 --- a/apps/openmw/mwgui/statswindow.cpp +++ b/apps/openmw/mwgui/statswindow.cpp @@ -179,7 +179,7 @@ namespace MWGui void StatsWindow::setValue (const std::string& id, const MWMechanics::DynamicStat& value) { int current = static_cast(value.getCurrent()); - int modified = static_cast(value.getModified()); + int modified = static_cast(value.getModified(false)); // Fatigue can be negative if (id != "FBar") diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 78195b3693..f127b2bc4b 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -218,8 +218,8 @@ namespace MWScript MWMechanics::DynamicStat stat (ptr.getClass().getCreatureStats (ptr) .getDynamic (mIndex)); - stat.setModified (value, 0); - stat.setCurrent(value); + stat.setBase(value); + stat.setCurrent(value, true); ptr.getClass().getCreatureStats (ptr).setDynamic (mIndex, stat); } @@ -259,19 +259,18 @@ namespace MWScript } } - MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats (ptr); + MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); - Interpreter::Type_Float current = stats.getDynamic(mIndex).getCurrent(); + MWMechanics::DynamicStat stat = stats.getDynamic(mIndex); - MWMechanics::DynamicStat stat (ptr.getClass().getCreatureStats (ptr) - .getDynamic (mIndex)); + float current = stat.getCurrent(); + float base = diff + stat.getBase(); + if(mIndex != 2) + base = std::max(base, 0.f); + stat.setBase(base); + stat.setCurrent(diff + current, true); - stat.setModified (diff + stat.getModified(), 0); - stat.setCurrentModified (diff + stat.getCurrentModified()); - - stat.setCurrent (diff + current); - - ptr.getClass().getCreatureStats (ptr).setDynamic (mIndex, stat); + stats.setDynamic (mIndex, stat); } };