diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 205cdeeb18..64877d3995 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -72,4 +72,6 @@ op 0x200005d-0x200005f: SetDynamic (health, magicka, fatigue) op 0x2000060-0x2000062: SetDynamic (health, magicka, fatigue), explicit reference op 0x2000063-0x2000065: ModDynamic (health, magicka, fatigue) op 0x2000066-0x2000068: ModDynamic (health, magicka, fatigue), explicit reference -opcodes 0x2000069-0x3ffffff unused +op 0x2000069-0x200006b: ModDynamic (health, magicka, fatigue) +op 0x200006c-0x200006e: ModDynamic (health, magicka, fatigue), explicit reference +opcodes 0x200006f-0x3ffffff unused diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 3ff6c67ce0..388a5b6c79 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -310,6 +310,59 @@ namespace MWScript } }; + + class OpModCurrentDynamic : public Interpreter::Opcode0 + { + int mIndex; + + public: + + OpModCurrentDynamic (int index) : mIndex (index) {} + + virtual void execute (Interpreter::Runtime& runtime) + { + MWScript::InterpreterContext& context + = static_cast (runtime.getContext()); + + Interpreter::Type_Integer diff = runtime[0].mInteger; + runtime.pop(); + + MWMechanics::CreatureStats& stats = context.getReference().getCreatureStats(); + + Interpreter::Type_Integer current = stats.mDynamic[mIndex].getCurrent(); + + stats.mDynamic[mIndex].setCurrent (diff + current); + } + }; + + class OpModCurrentDynamicExplicit : public Interpreter::Opcode0 + { + int mIndex; + + public: + + OpModCurrentDynamicExplicit (int index) : mIndex (index) {} + + virtual void execute (Interpreter::Runtime& runtime) + { + MWScript::InterpreterContext& context + = static_cast (runtime.getContext()); + + std::string id = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + Interpreter::Type_Integer diff = runtime[0].mInteger; + runtime.pop(); + + MWMechanics::CreatureStats& stats = + context.getWorld().getPtr (id, false).getCreatureStats(); + + Interpreter::Type_Integer current = stats.mDynamic[mIndex].getCurrent(); + + stats.mDynamic[mIndex].setCurrent (diff + current); + } + }; + const int numberOfAttributes = 8; const int opcodeGetAttribute = 0x2000027; @@ -327,6 +380,8 @@ namespace MWScript const int opcodeSetDynamicExplicit = 0x2000060; const int opcodeModDynamic = 0x2000063; const int opcodeModDynamicExplicit = 0x2000066; + const int opcodeModCurrentDynamic = 0x2000069; + const int opcodeModCurrentDynamicExplicit = 0x200006c; void registerExtensions (Compiler::Extensions& extensions) { @@ -344,6 +399,7 @@ namespace MWScript std::string get ("get"); std::string set ("set"); std::string mod ("mod"); + std::string modCurrent ("modcurrent"); for (int i=0; i