2010-07-18 19:48:02 +02:00
|
|
|
#include "skyextensions.hpp"
|
|
|
|
|
2017-06-13 18:55:22 +09:00
|
|
|
#include <algorithm>
|
|
|
|
|
2013-08-06 20:38:41 -04:00
|
|
|
#include <components/compiler/opcodes.hpp>
|
2010-07-18 19:48:02 +02:00
|
|
|
|
|
|
|
#include <components/interpreter/interpreter.hpp>
|
|
|
|
#include <components/interpreter/runtime.hpp>
|
|
|
|
#include <components/interpreter/opcodes.hpp>
|
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2014-12-19 11:26:54 +01:00
|
|
|
#include "../mwbase/world.hpp"
|
2012-04-23 15:27:03 +02:00
|
|
|
|
2021-12-03 16:05:18 +00:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
|
2010-07-18 19:48:02 +02:00
|
|
|
#include "interpretercontext.hpp"
|
|
|
|
|
|
|
|
namespace MWScript
|
|
|
|
{
|
|
|
|
namespace Sky
|
|
|
|
{
|
|
|
|
class OpToggleSky : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2011-04-26 21:38:21 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2010-07-18 19:48:02 +02:00
|
|
|
{
|
2012-04-23 15:27:03 +02:00
|
|
|
bool enabled = MWBase::Environment::get().getWorld()->toggleSky();
|
|
|
|
|
2015-03-03 23:46:53 +01:00
|
|
|
runtime.getContext().report (enabled ? "Sky -> On" : "Sky -> Off");
|
2011-04-26 21:38:21 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-18 19:48:02 +02:00
|
|
|
class OpTurnMoonWhite : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2011-04-26 21:38:21 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2010-07-18 19:48:02 +02:00
|
|
|
{
|
2012-04-23 15:27:03 +02:00
|
|
|
MWBase::Environment::get().getWorld()->setMoonColour (false);
|
2011-04-26 21:38:21 +02:00
|
|
|
}
|
|
|
|
};
|
2010-07-18 19:48:02 +02:00
|
|
|
|
|
|
|
class OpTurnMoonRed : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2011-04-26 21:38:21 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2010-07-18 19:48:02 +02:00
|
|
|
{
|
2012-04-23 15:27:03 +02:00
|
|
|
MWBase::Environment::get().getWorld()->setMoonColour (true);
|
2011-04-26 21:38:21 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-18 19:48:02 +02:00
|
|
|
class OpGetMasserPhase : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2011-04-26 21:38:21 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2010-07-18 19:48:02 +02:00
|
|
|
{
|
2012-04-23 15:27:03 +02:00
|
|
|
runtime.push (MWBase::Environment::get().getWorld()->getMasserPhase());
|
2011-04-26 21:38:21 +02:00
|
|
|
}
|
|
|
|
};
|
2010-07-18 19:48:02 +02:00
|
|
|
|
|
|
|
class OpGetSecundaPhase : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2011-04-26 21:38:21 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2010-07-18 19:48:02 +02:00
|
|
|
{
|
2012-04-23 15:27:03 +02:00
|
|
|
runtime.push (MWBase::Environment::get().getWorld()->getSecundaPhase());
|
2011-04-26 21:38:21 +02:00
|
|
|
}
|
|
|
|
};
|
2012-04-23 15:27:03 +02:00
|
|
|
|
2012-02-25 21:34:38 +01:00
|
|
|
class OpGetCurrentWeather : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2012-04-23 15:27:03 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-02-25 21:34:38 +01:00
|
|
|
{
|
2012-04-23 15:27:03 +02:00
|
|
|
runtime.push (MWBase::Environment::get().getWorld()->getCurrentWeather());
|
2012-02-25 21:34:38 +01:00
|
|
|
}
|
|
|
|
};
|
2012-04-23 15:27:03 +02:00
|
|
|
|
2012-02-26 11:51:02 +01:00
|
|
|
class OpChangeWeather : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2012-04-23 15:27:03 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-02-26 11:51:02 +01:00
|
|
|
{
|
2022-05-22 09:29:03 +02:00
|
|
|
std::string region{runtime.getStringLiteral(runtime[0].mInteger)};
|
2012-02-26 11:51:02 +01:00
|
|
|
runtime.pop();
|
2012-04-23 15:27:03 +02:00
|
|
|
|
2012-02-26 11:51:02 +01:00
|
|
|
Interpreter::Type_Integer id = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
2012-04-23 15:27:03 +02:00
|
|
|
|
2021-12-03 16:05:18 +00:00
|
|
|
const ESM::Region* reg = MWBase::Environment::get().getWorld()->getStore().get<ESM::Region>().search(region);
|
|
|
|
if (reg)
|
|
|
|
MWBase::Environment::get().getWorld()->changeWeather(region, id);
|
|
|
|
else
|
|
|
|
runtime.getContext().report("Warning: Region \"" + region + "\" was not found");
|
2012-02-26 11:51:02 +01:00
|
|
|
}
|
|
|
|
};
|
2011-04-26 21:38:21 +02:00
|
|
|
|
2013-07-27 07:10:18 -07:00
|
|
|
class OpModRegion : public Interpreter::Opcode1
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute (Interpreter::Runtime& runtime, unsigned int arg0) override
|
2013-07-27 07:10:18 -07:00
|
|
|
{
|
2022-05-22 09:29:03 +02:00
|
|
|
std::string region{runtime.getStringLiteral(runtime[0].mInteger)};
|
2013-07-27 07:10:18 -07:00
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
std::vector<char> chances;
|
|
|
|
chances.reserve(10);
|
|
|
|
while(arg0 > 0)
|
|
|
|
{
|
2021-11-06 07:30:28 +03:00
|
|
|
chances.push_back(std::clamp(runtime[0].mInteger, 0, 127));
|
2013-07-27 07:10:18 -07:00
|
|
|
runtime.pop();
|
|
|
|
arg0--;
|
|
|
|
}
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWorld()->modRegion(region, chances);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-04-26 21:38:21 +02:00
|
|
|
|
2010-07-18 19:48:02 +02:00
|
|
|
void installOpcodes (Interpreter::Interpreter& interpreter)
|
|
|
|
{
|
2022-01-27 19:18:57 +00:00
|
|
|
interpreter.installSegment5<OpToggleSky>(Compiler::Sky::opcodeToggleSky);
|
|
|
|
interpreter.installSegment5<OpTurnMoonWhite>(Compiler::Sky::opcodeTurnMoonWhite);
|
|
|
|
interpreter.installSegment5<OpTurnMoonRed>(Compiler::Sky::opcodeTurnMoonRed);
|
|
|
|
interpreter.installSegment5<OpGetMasserPhase>(Compiler::Sky::opcodeGetMasserPhase);
|
|
|
|
interpreter.installSegment5<OpGetSecundaPhase>(Compiler::Sky::opcodeGetSecundaPhase);
|
|
|
|
interpreter.installSegment5<OpGetCurrentWeather>(Compiler::Sky::opcodeGetCurrentWeather);
|
|
|
|
interpreter.installSegment5<OpChangeWeather>(Compiler::Sky::opcodeChangeWeather);
|
|
|
|
interpreter.installSegment3<OpModRegion>(Compiler::Sky::opcodeModRegion);
|
2011-04-26 21:38:21 +02:00
|
|
|
}
|
2010-07-18 19:48:02 +02:00
|
|
|
}
|
|
|
|
}
|