#include "skyextensions.hpp" #include #include #include #include #include #include #include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwworld/esmstore.hpp" namespace MWScript { namespace Sky { class OpToggleSky : public Interpreter::Opcode0 { public: void execute(Interpreter::Runtime& runtime) override { bool enabled = MWBase::Environment::get().getWorld()->toggleSky(); runtime.getContext().report(enabled ? "Sky -> On" : "Sky -> Off"); } }; class OpTurnMoonWhite : public Interpreter::Opcode0 { public: void execute(Interpreter::Runtime& runtime) override { MWBase::Environment::get().getWorld()->setMoonColour(false); } }; class OpTurnMoonRed : public Interpreter::Opcode0 { public: void execute(Interpreter::Runtime& runtime) override { MWBase::Environment::get().getWorld()->setMoonColour(true); } }; class OpGetMasserPhase : public Interpreter::Opcode0 { public: void execute(Interpreter::Runtime& runtime) override { runtime.push(MWBase::Environment::get().getWorld()->getMasserPhase()); } }; class OpGetSecundaPhase : public Interpreter::Opcode0 { public: void execute(Interpreter::Runtime& runtime) override { runtime.push(MWBase::Environment::get().getWorld()->getSecundaPhase()); } }; class OpGetCurrentWeather : public Interpreter::Opcode0 { public: void execute(Interpreter::Runtime& runtime) override { runtime.push(MWBase::Environment::get().getWorld()->getCurrentWeather()); } }; class OpChangeWeather : public Interpreter::Opcode0 { public: void execute(Interpreter::Runtime& runtime) override { ESM::RefId region = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); Interpreter::Type_Integer id = runtime[0].mInteger; runtime.pop(); const ESM::Region* reg = MWBase::Environment::get().getESMStore()->get().search(region); if (reg) MWBase::Environment::get().getWorld()->changeWeather(region, id); else runtime.getContext().report("Warning: Region \"" + region.getRefIdString() + "\" was not found"); } }; class OpModRegion : public Interpreter::Opcode1 { public: void execute(Interpreter::Runtime& runtime, unsigned int arg0) override { std::string_view region{ runtime.getStringLiteral(runtime[0].mInteger) }; runtime.pop(); std::vector chances; chances.reserve(10); while (arg0 > 0) { chances.push_back(std::clamp(runtime[0].mInteger, 0, 100)); runtime.pop(); arg0--; } MWBase::Environment::get().getWorld()->modRegion(ESM::RefId::stringRefId(region), chances); } }; void installOpcodes(Interpreter::Interpreter& interpreter) { interpreter.installSegment5(Compiler::Sky::opcodeToggleSky); interpreter.installSegment5(Compiler::Sky::opcodeTurnMoonWhite); interpreter.installSegment5(Compiler::Sky::opcodeTurnMoonRed); interpreter.installSegment5(Compiler::Sky::opcodeGetMasserPhase); interpreter.installSegment5(Compiler::Sky::opcodeGetSecundaPhase); interpreter.installSegment5(Compiler::Sky::opcodeGetCurrentWeather); interpreter.installSegment5(Compiler::Sky::opcodeChangeWeather); interpreter.installSegment3(Compiler::Sky::opcodeModRegion); } } }