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"
|
2011-01-17 09:18:12 +00:00
|
|
|
#include "../mwworld/player.hpp"
|
2010-07-03 13:04:00 +00:00
|
|
|
|
2010-07-03 10:12:13 +00:00
|
|
|
#include "interpretercontext.hpp"
|
|
|
|
|
|
|
|
namespace MWScript
|
|
|
|
{
|
|
|
|
namespace Cell
|
|
|
|
{
|
|
|
|
class OpCellChanged : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2010-08-20 11:33:03 +00:00
|
|
|
|
2010-07-03 10:12:13 +00:00
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
|
|
|
InterpreterContext& context
|
|
|
|
= static_cast<InterpreterContext&> (runtime.getContext());
|
2010-08-20 11:33:03 +00:00
|
|
|
|
2010-07-03 13:04:00 +00:00
|
|
|
runtime.push (context.getWorld().hasCellChanged() ? 1 : 0);
|
2010-08-20 11:33:03 +00:00
|
|
|
}
|
2010-07-03 10:12:13 +00:00
|
|
|
};
|
2010-07-22 10:29:23 +00:00
|
|
|
|
|
|
|
class OpCOC : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2010-08-20 11:33:03 +00:00
|
|
|
|
2010-07-22 10:29:23 +00:00
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
|
|
|
InterpreterContext& context
|
|
|
|
= static_cast<InterpreterContext&> (runtime.getContext());
|
2010-08-20 11:33:03 +00:00
|
|
|
|
2010-07-22 10:29:23 +00:00
|
|
|
std::string cell = runtime.getStringLiteral (runtime[0].mInteger);
|
2010-08-20 11:33:03 +00:00
|
|
|
runtime.pop();
|
|
|
|
|
2010-07-22 10:29:23 +00:00
|
|
|
ESM::Position pos;
|
|
|
|
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
|
2010-09-11 09:55:28 +00:00
|
|
|
pos.pos[2] = 0;
|
|
|
|
|
|
|
|
if (const ESM::Cell *exterior = context.getWorld().getExterior (cell))
|
|
|
|
{
|
|
|
|
context.getWorld().indexToPosition (exterior->data.gridX, exterior->data.gridY,
|
2010-09-11 10:21:55 +00:00
|
|
|
pos.pos[0], pos.pos[1], true);
|
2010-09-11 09:55:28 +00:00
|
|
|
context.getWorld().changeToExteriorCell (pos);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos.pos[0] = pos.pos[1] = 0;
|
2011-02-10 09:38:45 +00:00
|
|
|
context.getWorld().changeToInteriorCell (cell, pos);
|
2010-09-11 09:55:28 +00:00
|
|
|
}
|
2010-08-20 11:33:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpCOE : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
|
|
|
InterpreterContext& context
|
|
|
|
= static_cast<InterpreterContext&> (runtime.getContext());
|
|
|
|
|
|
|
|
Interpreter::Type_Integer x = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
Interpreter::Type_Integer y = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
ESM::Position pos;
|
2010-08-22 19:30:48 +00:00
|
|
|
|
2010-09-11 10:21:55 +00:00
|
|
|
context.getWorld().indexToPosition (x, y, pos.pos[0], pos.pos[1], true);
|
2010-08-20 11:33:03 +00:00
|
|
|
pos.pos[2] = 0;
|
2010-08-22 19:30:48 +00:00
|
|
|
|
2010-08-20 11:33:03 +00:00
|
|
|
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
|
2010-08-22 19:30:48 +00:00
|
|
|
|
2010-08-20 11:33:03 +00:00
|
|
|
context.getWorld().changeToExteriorCell (pos);
|
|
|
|
}
|
2010-07-22 10:29:23 +00:00
|
|
|
};
|
2010-08-20 11:33:03 +00:00
|
|
|
|
2011-01-17 09:18:12 +00:00
|
|
|
class OpGetInterior : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
|
|
|
InterpreterContext& context
|
|
|
|
= static_cast<InterpreterContext&> (runtime.getContext());
|
|
|
|
|
|
|
|
bool interior =
|
|
|
|
context.getWorld().getPlayer().getPlayer().getCell()->cell->data.flags &
|
|
|
|
ESM::Cell::Interior;
|
|
|
|
|
|
|
|
runtime.push (interior ? 1 : 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-04-04 13:10:37 +00:00
|
|
|
class OpGetPCCell : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
|
|
|
InterpreterContext& context
|
|
|
|
= static_cast<InterpreterContext&> (runtime.getContext());
|
|
|
|
|
|
|
|
std::string name = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
const ESM::Cell *cell = context.getWorld().getPlayer().getPlayer().getCell()->cell;
|
|
|
|
|
|
|
|
std::string current = cell->name;
|
|
|
|
|
|
|
|
if (!(cell->data.flags & ESM::Cell::Interior) && current.empty())
|
|
|
|
{
|
|
|
|
const ESM::Region *region =
|
|
|
|
context.getWorld().getStore().regions.find (cell->region);
|
|
|
|
|
|
|
|
current = region->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool match = current.length()>=name.length() &&
|
|
|
|
current.substr (0, name.length())==name;
|
|
|
|
|
|
|
|
runtime.push (match ? 1 : 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-29 13:50:15 +00:00
|
|
|
class OpGetWaterLevel : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
|
|
|
InterpreterContext& context
|
|
|
|
= static_cast<InterpreterContext&> (runtime.getContext());
|
|
|
|
|
2012-03-30 08:12:28 +00:00
|
|
|
MWWorld::Ptr::CellStore *cell = context.getWorld().getPlayer().getPlayer().getCell();
|
|
|
|
runtime.push (cell->mWaterLevel);
|
2012-03-29 13:50:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpSetWaterLevel : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
|
|
|
InterpreterContext& context
|
|
|
|
= static_cast<InterpreterContext&> (runtime.getContext());
|
|
|
|
|
|
|
|
Interpreter::Type_Float level = runtime[0].mFloat;
|
|
|
|
|
|
|
|
MWWorld::Ptr::CellStore *cell = context.getWorld().getPlayer().getPlayer().getCell();
|
2012-03-29 14:23:02 +00:00
|
|
|
|
|
|
|
if (!(cell->cell->data.flags & ESM::Cell::Interior))
|
|
|
|
throw std::runtime_error("Can't set water level in exterior cell");
|
|
|
|
|
2012-03-29 13:50:15 +00:00
|
|
|
cell->mWaterLevel = level;
|
|
|
|
context.getEnvironment().mWorld->setWaterHeight(cell->mWaterLevel);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpModWaterLevel : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
|
|
|
InterpreterContext& context
|
|
|
|
= static_cast<InterpreterContext&> (runtime.getContext());
|
|
|
|
|
|
|
|
Interpreter::Type_Float level = runtime[0].mFloat;
|
|
|
|
|
|
|
|
MWWorld::Ptr::CellStore *cell = context.getWorld().getPlayer().getPlayer().getCell();
|
2012-03-29 14:23:02 +00:00
|
|
|
|
|
|
|
if (!(cell->cell->data.flags & ESM::Cell::Interior))
|
|
|
|
throw std::runtime_error("Can't set water level in exterior cell");
|
|
|
|
|
2012-03-29 13:50:15 +00:00
|
|
|
cell->mWaterLevel +=level;
|
|
|
|
context.getEnvironment().mWorld->setWaterHeight(cell->mWaterLevel);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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-09-10 11:01:37 +00:00
|
|
|
const int opcodeCOE = 0x200008e;
|
2011-01-17 09:18:12 +00:00
|
|
|
const int opcodeGetInterior = 0x2000131;
|
2011-04-04 13:10:37 +00:00
|
|
|
const int opcodeGetPCCell = 0x2000136;
|
2012-03-29 13:50:15 +00:00
|
|
|
const int opcodeGetWaterLevel = 0x2000141;
|
|
|
|
const int opcodeSetWaterLevel = 0x2000142;
|
|
|
|
const int opcodeModWaterLevel = 0x2000143;
|
2010-08-20 11:33:03 +00:00
|
|
|
|
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-08-20 11:33:03 +00:00
|
|
|
extensions.registerInstruction ("coe", "ll", opcodeCOE);
|
|
|
|
extensions.registerInstruction ("centeronexterior", "ll", opcodeCOE);
|
2012-03-29 13:50:15 +00:00
|
|
|
extensions.registerInstruction ("setwaterlevel", "f", opcodeSetWaterLevel);
|
|
|
|
extensions.registerInstruction ("modwaterlevel", "f", opcodeModWaterLevel);
|
2011-01-17 09:18:12 +00:00
|
|
|
extensions.registerFunction ("getinterior", 'l', "", opcodeGetInterior);
|
2011-04-04 13:10:37 +00:00
|
|
|
extensions.registerFunction ("getpccell", 'l', "c", opcodeGetPCCell);
|
2012-03-29 13:50:15 +00:00
|
|
|
extensions.registerFunction ("getwaterlevel", 'f', "", opcodeGetWaterLevel);
|
2010-07-03 10:12:13 +00:00
|
|
|
}
|
2010-08-20 11:33:03 +00:00
|
|
|
|
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-08-20 11:33:03 +00:00
|
|
|
interpreter.installSegment5 (opcodeCOE, new OpCOE);
|
2011-01-17 09:18:12 +00:00
|
|
|
interpreter.installSegment5 (opcodeGetInterior, new OpGetInterior);
|
2011-04-04 13:10:37 +00:00
|
|
|
interpreter.installSegment5 (opcodeGetPCCell, new OpGetPCCell);
|
2012-03-29 13:50:15 +00:00
|
|
|
interpreter.installSegment5 (opcodeGetWaterLevel, new OpGetWaterLevel);
|
|
|
|
interpreter.installSegment5 (opcodeSetWaterLevel, new OpSetWaterLevel);
|
|
|
|
interpreter.installSegment5 (opcodeModWaterLevel, new OpModWaterLevel);
|
2010-07-03 10:12:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|