#include "statsextensions.hpp" #include #include #include #include #include "interpretercontext.hpp" namespace MWScript { namespace Stats { class OpGetAttribute : public Interpreter::Opcode0 { int mIndex; public: OpGetAttribute (int index) : mIndex (index) {} virtual void execute (Interpreter::Runtime& runtime) { MWScript::InterpreterContext& context = static_cast (runtime.getContext()); Interpreter::Type_Integer value = context.getReference().getCreatureStats().mAttributes[mIndex]. getModified(); runtime.push (value); } }; class OpGetAttributeExplicit : public Interpreter::Opcode0 { int mIndex; public: OpGetAttributeExplicit (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 = context.getWorld().getPtr (id, false).getCreatureStats().mAttributes[mIndex]. getModified(); runtime.push (value); } }; class OpSetAttribute : public Interpreter::Opcode0 { int mIndex; public: OpSetAttribute (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(); context.getReference().getCreatureStats().mAttributes[mIndex]. setModified (value, 0); } }; class OpSetAttributeExplicit : public Interpreter::Opcode0 { int mIndex; public: OpSetAttributeExplicit (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(); context.getWorld().getPtr (id, false).getCreatureStats().mAttributes[mIndex]. setModified (value, 0); } }; class OpModAttribute : public Interpreter::Opcode0 { int mIndex; public: OpModAttribute (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(); value += context.getReference().getCreatureStats().mAttributes[mIndex]. getModified(); context.getReference().getCreatureStats().mAttributes[mIndex]. setModified (value, 0, 100); } }; class OpModAttributeExplicit : public Interpreter::Opcode0 { int mIndex; public: OpModAttributeExplicit (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(); value += context.getWorld().getPtr (id, false).getCreatureStats().mAttributes[mIndex]. getModified(); context.getWorld().getPtr (id, false).getCreatureStats().mAttributes[mIndex]. setModified (value, 0, 100); } }; const int numberOfAttributes = 8; const int opcodeGetAttribute = 0x2000027; const int opcodeGetAttributeExplicit = 0x200002f; const int opcodeSetAttribute = 0x2000037; const int opcodeSetAttributeExplicit = 0x200003f; const int opcodeModAttribute = 0x2000047; const int opcodeModAttributeExplicit = 0x200004f; void registerExtensions (Compiler::Extensions& extensions) { static const char *attributes[numberOfAttributes] = { "strength", "intelligence", "willpower", "agility", "speed", "endurance", "personality", "luck" }; std::string get ("get"); std::string set ("set"); std::string mod ("mod"); for (int i=0; i