diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 705d65814..1317794fa 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -133,4 +133,6 @@ op 0x2000147: AddSpell op 0x2000148: AddSpell, explicit reference op 0x2000149: RemoveSpell op 0x200014a: RemoveSpell, explicit reference -opcodes 0x200014b-0x3ffffff unused +op 0x200014b: GetSpell +op 0x200014c: GetSpell, explicit reference +opcodes 0x200014d-0x3ffffff unused diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 10641903e..011b8b010 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -312,6 +312,33 @@ namespace MWScript } }; + template + class OpGetSpell : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWWorld::Ptr ptr = R()(runtime); + + std::string id = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + Interpreter::Type_Integer value = 0; + + for (MWMechanics::Spells::TIterator iter ( + MWWorld::Class::get (ptr).getCreatureStats (ptr).mSpells.begin()); + iter!=MWWorld::Class::get (ptr).getCreatureStats (ptr).mSpells.end(); ++iter) + if (*iter==id) + { + value = 1; + break; + } + + runtime.push (value); + } + }; + const int numberOfAttributes = 8; const int opcodeGetAttribute = 0x2000027; @@ -347,6 +374,8 @@ namespace MWScript const int opcodeAddSpellExplicit = 0x2000148; const int opcodeRemoveSpell = 0x2000149; const int opcodeRemoveSpellExplicit = 0x200014a; + const int opcodeGetSpell = 0x200014b; + const int opcodeGetSpellExplicit = 0x200014c; void registerExtensions (Compiler::Extensions& extensions) { @@ -422,6 +451,7 @@ namespace MWScript extensions.registerInstruction ("addspell", "c", opcodeAddSpell, opcodeAddSpellExplicit); extensions.registerInstruction ("removespell", "c", opcodeRemoveSpell, opcodeRemoveSpellExplicit); + extensions.registerFunction ("getspell", 'l', "c", opcodeGetSpell, opcodeGetSpellExplicit); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -483,6 +513,8 @@ namespace MWScript interpreter.installSegment5 (opcodeRemoveSpell, new OpRemoveSpell); interpreter.installSegment5 (opcodeRemoveSpellExplicit, new OpRemoveSpell); + interpreter.installSegment5 (opcodeGetSpell, new OpGetSpell); + interpreter.installSegment5 (opcodeGetSpellExplicit, new OpGetSpell); } } }