1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-10 15:39:02 +00:00
OpenMW/apps/openmw/mwscript/cellextensions.cpp

68 lines
2.2 KiB
C++
Raw Normal View History

2010-07-03 10:12:13 +00:00
#include "cellextensions.hpp"
#include <components/compiler/extensions.hpp>
#include <components/interpreter/interpreter.hpp>
#include <components/interpreter/runtime.hpp>
#include <components/interpreter/opcodes.hpp>
2010-07-03 13:41:20 +00:00
#include "../mwworld/world.hpp"
2010-07-03 10:12:13 +00:00
#include "interpretercontext.hpp"
namespace MWScript
{
namespace Cell
{
class OpCellChanged : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context
= static_cast<InterpreterContext&> (runtime.getContext());
runtime.push (context.getWorld().hasCellChanged() ? 1 : 0);
2010-07-03 10:12:13 +00:00
}
};
2010-07-22 10:29:23 +00:00
class OpCOC : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context
= static_cast<InterpreterContext&> (runtime.getContext());
std::string cell = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
ESM::Position pos;
pos.pos[0] = pos.pos[1] = pos.pos[2] = 0;
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
context.getWorld().changeCell (cell, pos);
}
};
2010-07-03 10:12:13 +00:00
const int opcodeCellChanged = 0x2000000;
2010-07-22 10:29:23 +00:00
const int opcodeCOC = 0x2000026;
2010-07-03 10:12:13 +00:00
void registerExtensions (Compiler::Extensions& extensions)
{
extensions.registerFunction ("cellchanged", 'l', "", opcodeCellChanged);
2010-07-22 10:29:23 +00:00
extensions.registerInstruction ("coc", "S", opcodeCOC);
extensions.registerInstruction ("centeroncell", "S", opcodeCOC);
2010-07-03 10:12:13 +00:00
}
void installOpcodes (Interpreter::Interpreter& interpreter)
{
interpreter.installSegment5 (opcodeCellChanged, new OpCellChanged);
2010-07-22 10:29:23 +00:00
interpreter.installSegment5 (opcodeCOC, new OpCOC);
2010-07-03 10:12:13 +00:00
}
}
}