#include "controlextensions.hpp" #include #include #include #include #include "../mwbase/environment.hpp" #include "../mwbase/inputmanager.hpp" #include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/world.hpp" #include "../mwworld/class.hpp" #include "../mwworld/ptr.hpp" #include "../mwmechanics/creaturestats.hpp" #include "interpretercontext.hpp" #include "ref.hpp" namespace MWScript { namespace Control { class OpSetControl : public Interpreter::Opcode0 { std::string mControl; bool mEnable; public: OpSetControl(const std::string& control, bool enable) : mControl(control) , mEnable(enable) { } void execute(Interpreter::Runtime& runtime) override { MWBase::Environment::get().getInputManager()->toggleControlSwitch(mControl, mEnable); } }; class OpGetDisabled : public Interpreter::Opcode0 { std::string mControl; public: OpGetDisabled(const std::string& control) : mControl(control) { } void execute(Interpreter::Runtime& runtime) override { runtime.push(!MWBase::Environment::get().getInputManager()->getControlSwitch(mControl)); } }; class OpToggleCollision : public Interpreter::Opcode0 { public: void execute(Interpreter::Runtime& runtime) override { bool enabled = MWBase::Environment::get().getWorld()->toggleCollisionMode(); runtime.getContext().report(enabled ? "Collision -> On" : "Collision -> Off"); } }; template class OpClearMovementFlag : public Interpreter::Opcode0 { MWMechanics::CreatureStats::Flag mFlag; public: OpClearMovementFlag(MWMechanics::CreatureStats::Flag flag) : mFlag(flag) { } void execute(Interpreter::Runtime& runtime) override { MWWorld::Ptr ptr = R()(runtime); ptr.getClass().getCreatureStats(ptr).setMovementFlag(mFlag, false); } }; template class OpSetMovementFlag : public Interpreter::Opcode0 { MWMechanics::CreatureStats::Flag mFlag; public: OpSetMovementFlag(MWMechanics::CreatureStats::Flag flag) : mFlag(flag) { } void execute(Interpreter::Runtime& runtime) override { MWWorld::Ptr ptr = R()(runtime); ptr.getClass().getCreatureStats(ptr).setMovementFlag(mFlag, true); } }; template class OpGetForceRun : public Interpreter::Opcode0 { public: void execute(Interpreter::Runtime& runtime) override { MWWorld::Ptr ptr = R()(runtime); MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); runtime.push(stats.getMovementFlag(MWMechanics::CreatureStats::Flag_ForceRun)); } }; template class OpGetForceJump : public Interpreter::Opcode0 { public: void execute(Interpreter::Runtime& runtime) override { MWWorld::Ptr ptr = R()(runtime); MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); runtime.push(stats.getMovementFlag(MWMechanics::CreatureStats::Flag_ForceJump)); } }; template class OpGetForceMoveJump : public Interpreter::Opcode0 { public: void execute(Interpreter::Runtime& runtime) override { MWWorld::Ptr ptr = R()(runtime); MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); runtime.push(stats.getMovementFlag(MWMechanics::CreatureStats::Flag_ForceMoveJump)); } }; template class OpGetForceSneak : public Interpreter::Opcode0 { public: void execute(Interpreter::Runtime& runtime) override { MWWorld::Ptr ptr = R()(runtime); MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); runtime.push(stats.getMovementFlag(MWMechanics::CreatureStats::Flag_ForceSneak)); } }; class OpGetPcRunning : public Interpreter::Opcode0 { public: void execute(Interpreter::Runtime& runtime) override { MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); MWBase::World* world = MWBase::Environment::get().getWorld(); bool stanceOn = stats.getStance(MWMechanics::CreatureStats::Stance_Run); bool running = MWBase::Environment::get().getMechanicsManager()->isRunning(ptr); bool inair = !world->isOnGround(ptr) && !world->isSwimming(ptr) && !world->isFlying(ptr); runtime.push(stanceOn && (running || inair)); } }; class OpGetPcSneaking : public Interpreter::Opcode0 { public: void execute(Interpreter::Runtime& runtime) override { MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); runtime.push(MWBase::Environment::get().getMechanicsManager()->isSneaking(ptr)); } }; void installOpcodes(Interpreter::Interpreter& interpreter) { for (int i = 0; i < Compiler::Control::numberOfControls; ++i) { interpreter.installSegment5( Compiler::Control::opcodeEnable + i, Compiler::Control::controls[i], true); interpreter.installSegment5( Compiler::Control::opcodeDisable + i, Compiler::Control::controls[i], false); interpreter.installSegment5( Compiler::Control::opcodeGetDisabled + i, Compiler::Control::controls[i]); } interpreter.installSegment5(Compiler::Control::opcodeToggleCollision); // Force Run interpreter.installSegment5>( Compiler::Control::opcodeClearForceRun, MWMechanics::CreatureStats::Flag_ForceRun); interpreter.installSegment5>( Compiler::Control::opcodeClearForceRunExplicit, MWMechanics::CreatureStats::Flag_ForceRun); interpreter.installSegment5>( Compiler::Control::opcodeForceRun, MWMechanics::CreatureStats::Flag_ForceRun); interpreter.installSegment5>( Compiler::Control::opcodeForceRunExplicit, MWMechanics::CreatureStats::Flag_ForceRun); // Force Jump interpreter.installSegment5>( Compiler::Control::opcodeClearForceJump, MWMechanics::CreatureStats::Flag_ForceJump); interpreter.installSegment5>( Compiler::Control::opcodeClearForceJumpExplicit, MWMechanics::CreatureStats::Flag_ForceJump); interpreter.installSegment5>( Compiler::Control::opcodeForceJump, MWMechanics::CreatureStats::Flag_ForceJump); interpreter.installSegment5>( Compiler::Control::opcodeForceJumpExplicit, MWMechanics::CreatureStats::Flag_ForceJump); // Force MoveJump interpreter.installSegment5>( Compiler::Control::opcodeClearForceMoveJump, MWMechanics::CreatureStats::Flag_ForceMoveJump); interpreter.installSegment5>( Compiler::Control::opcodeClearForceMoveJumpExplicit, MWMechanics::CreatureStats::Flag_ForceMoveJump); interpreter.installSegment5>( Compiler::Control::opcodeForceMoveJump, MWMechanics::CreatureStats::Flag_ForceMoveJump); interpreter.installSegment5>( Compiler::Control::opcodeForceMoveJumpExplicit, MWMechanics::CreatureStats::Flag_ForceMoveJump); // Force Sneak interpreter.installSegment5>( Compiler::Control::opcodeClearForceSneak, MWMechanics::CreatureStats::Flag_ForceSneak); interpreter.installSegment5>( Compiler::Control::opcodeClearForceSneakExplicit, MWMechanics::CreatureStats::Flag_ForceSneak); interpreter.installSegment5>( Compiler::Control::opcodeForceSneak, MWMechanics::CreatureStats::Flag_ForceSneak); interpreter.installSegment5>( Compiler::Control::opcodeForceSneakExplicit, MWMechanics::CreatureStats::Flag_ForceSneak); interpreter.installSegment5(Compiler::Control::opcodeGetPcRunning); interpreter.installSegment5(Compiler::Control::opcodeGetPcSneaking); interpreter.installSegment5>(Compiler::Control::opcodeGetForceRun); interpreter.installSegment5>(Compiler::Control::opcodeGetForceRunExplicit); interpreter.installSegment5>(Compiler::Control::opcodeGetForceJump); interpreter.installSegment5>(Compiler::Control::opcodeGetForceJumpExplicit); interpreter.installSegment5>(Compiler::Control::opcodeGetForceMoveJump); interpreter.installSegment5>( Compiler::Control::opcodeGetForceMoveJumpExplicit); interpreter.installSegment5>(Compiler::Control::opcodeGetForceSneak); interpreter.installSegment5>(Compiler::Control::opcodeGetForceSneakExplicit); } } }