From a8c974d2e788a316f34c1a87c8f27a4ae17fb601 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 20 Oct 2010 11:31:42 +0200 Subject: [PATCH] added set/get/mod instructions for skills --- apps/openmw/mwscript/docs/vmformat.txt | 8 +- apps/openmw/mwscript/statsextensions.cpp | 196 +++++++++++++++++++++++ 2 files changed, 203 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 8f606a8198..2a859c57f0 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -95,4 +95,10 @@ op 0x2000085-0x200008b: Disable Controls op 0x200008c: Unlock op 0x200008d: Unlock, explicit reference op 0x200008e: COE -opcodes 0x200008f-0x3ffffff unused +op 0x200008e-0x20000a8: GetSkill +op 0x20000a9-0x20000c3: GetSkill, explicit reference +op 0x20000c4-0x20000de: SetSkill +op 0x20000df-0x20000f9: SetSkill, explicit reference +op 0x20000fa-0x2000114: ModSkill +op 0x2000115-0x200012f: ModSKill, explicit reference +opcodes 0x2000130-0x3ffffff unused diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index e28b5593bc..17635667c4 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -468,6 +468,160 @@ namespace MWScript } }; + class OpGetSkill : public Interpreter::Opcode0 + { + int mIndex; + + public: + + OpGetSkill (int index) : mIndex (index) {} + + virtual void execute (Interpreter::Runtime& runtime) + { + MWScript::InterpreterContext& context + = static_cast (runtime.getContext()); + + MWWorld::Ptr ptr = context.getReference(); + + Interpreter::Type_Integer value = + MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex]. + getModified(); + + runtime.push (value); + } + }; + + class OpGetSkillExplicit : public Interpreter::Opcode0 + { + int mIndex; + + public: + + OpGetSkillExplicit (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(); + + MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); + + Interpreter::Type_Integer value = + MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex]. + getModified(); + + runtime.push (value); + } + }; + + class OpSetSkill : public Interpreter::Opcode0 + { + int mIndex; + + public: + + OpSetSkill (int index) : mIndex (index) {} + + virtual void execute (Interpreter::Runtime& runtime) + { + MWScript::InterpreterContext& context + = static_cast (runtime.getContext()); + + Interpreter::Type_Integer value = runtime[0].mInteger; + runtime.pop(); + + MWWorld::Ptr ptr = context.getReference(); + + MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex]. + setModified (value, 0); + } + }; + + class OpSetSkillExplicit : public Interpreter::Opcode0 + { + int mIndex; + + public: + + OpSetSkillExplicit (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 value = runtime[0].mInteger; + runtime.pop(); + + MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); + + MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex]. + setModified (value, 0); + } + }; + + class OpModSkill : public Interpreter::Opcode0 + { + int mIndex; + + public: + + OpModSkill (int index) : mIndex (index) {} + + virtual void execute (Interpreter::Runtime& runtime) + { + MWScript::InterpreterContext& context + = static_cast (runtime.getContext()); + + Interpreter::Type_Integer value = runtime[0].mInteger; + runtime.pop(); + + MWWorld::Ptr ptr = context.getReference(); + + value += MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex]. + getModified(); + + MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex]. + setModified (value, 0, 100); + } + }; + + class OpModSkillExplicit : public Interpreter::Opcode0 + { + int mIndex; + + public: + + OpModSkillExplicit (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 value = runtime[0].mInteger; + runtime.pop(); + + MWWorld::Ptr ptr = context.getWorld().getPtr (id, false); + + value += + MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex]. + getModified(); + + MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex]. + setModified (value, 0, 100); + } + }; + const int numberOfAttributes = 8; const int opcodeGetAttribute = 0x2000027; @@ -490,6 +644,15 @@ namespace MWScript const int opcodeGetDynamicGetRatio = 0x200006f; const int opcodeGetDynamicGetRatioExplicit = 0x2000072; + const int numberOfSkills = 27; + + const int opcodeGetSkill = 0x200008e; + const int opcodeGetSkillExplicit = 0x20000a9; + const int opcodeSetSkill = 0x20000c4; + const int opcodeSetSkillExplicit = 0x20000df; + const int opcodeModSkill = 0x20000fa; + const int opcodeModSkillExplicit = 0x2000115; + void registerExtensions (Compiler::Extensions& extensions) { static const char *attributes[numberOfAttributes] = @@ -503,6 +666,16 @@ namespace MWScript "health", "magicka", "fatigue" }; + static const char *skills[numberOfSkills] = + { + "block", "armorer", "mediumarmor", "heavyarmor", "bluntweapon", + "longblade", "axe", "spear", "athletics", "enchant", "destruction", + "alteration", "illusion", "conjuration", "mysticism", + "restoration", "alchemy", "unarmored", "security", "sneak", + "acrobatics", "lightarmor", "shortblade", "marksman", + "merchantile", "speechcraft", "handtohand" + }; + std::string get ("get"); std::string set ("set"); std::string mod ("mod"); @@ -537,7 +710,18 @@ namespace MWScript extensions.registerFunction (get + dynamics[i] + getRatio, 'f', "", opcodeGetDynamicGetRatio+i, opcodeGetDynamicGetRatioExplicit+i); + } + for (int i=0; i