2010-07-03 12:12:13 +02:00
|
|
|
|
|
|
|
#include "cellextensions.hpp"
|
|
|
|
|
2012-10-01 19:17:04 +04:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2012-07-03 12:30:50 +02:00
|
|
|
|
2010-07-03 12:12:13 +02:00
|
|
|
#include <components/compiler/extensions.hpp>
|
2013-08-06 20:38:41 -04:00
|
|
|
#include <components/compiler/opcodes.hpp>
|
2010-07-03 12:12:13 +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"
|
2012-07-03 12:30:50 +02:00
|
|
|
#include "../mwbase/world.hpp"
|
2011-01-17 10:18:12 +01:00
|
|
|
#include "../mwworld/player.hpp"
|
2014-02-23 20:11:05 +01:00
|
|
|
#include "../mwworld/cellstore.hpp"
|
2010-07-03 15:04:00 +02:00
|
|
|
|
2010-07-03 12:12:13 +02:00
|
|
|
#include "interpretercontext.hpp"
|
|
|
|
|
|
|
|
namespace MWScript
|
|
|
|
{
|
|
|
|
namespace Cell
|
|
|
|
{
|
|
|
|
class OpCellChanged : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2010-08-20 13:33:03 +02:00
|
|
|
|
2010-07-03 12:12:13 +02:00
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
2012-04-23 15:27:03 +02:00
|
|
|
runtime.push (MWBase::Environment::get().getWorld()->hasCellChanged() ? 1 : 0);
|
2010-08-20 13:33:03 +02:00
|
|
|
}
|
2010-07-03 12:12:13 +02:00
|
|
|
};
|
2010-07-22 12:29:23 +02:00
|
|
|
|
|
|
|
class OpCOC : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2010-08-20 13:33:03 +02:00
|
|
|
|
2010-07-22 12:29:23 +02:00
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
|
|
|
std::string cell = runtime.getStringLiteral (runtime[0].mInteger);
|
2010-08-20 13:33:03 +02:00
|
|
|
runtime.pop();
|
|
|
|
|
2010-07-22 12:29:23 +02:00
|
|
|
ESM::Position pos;
|
2013-07-06 12:42:29 +04:00
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
2010-09-11 11:55:28 +02:00
|
|
|
|
2013-12-31 20:40:23 +01:00
|
|
|
world->getPlayer().setTeleported(true);
|
|
|
|
if (world->findExteriorPosition(cell, pos))
|
|
|
|
{
|
2013-07-06 12:42:29 +04:00
|
|
|
world->changeToExteriorCell(pos);
|
2010-09-11 11:55:28 +02:00
|
|
|
}
|
2013-12-31 20:40:23 +01:00
|
|
|
else
|
|
|
|
{
|
2013-07-06 12:42:29 +04:00
|
|
|
// Change to interior even if findInteriorPosition()
|
|
|
|
// yields false. In this case position will be zero-point.
|
2013-07-07 15:03:06 +04:00
|
|
|
world->findInteriorPosition(cell, pos);
|
2013-07-06 12:42:29 +04:00
|
|
|
world->changeToInteriorCell(cell, pos);
|
2010-09-11 11:55:28 +02:00
|
|
|
}
|
2010-08-20 13:33:03 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpCOE : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
|
|
|
Interpreter::Type_Integer x = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
Interpreter::Type_Integer y = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
ESM::Position pos;
|
2013-12-31 20:40:23 +01:00
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
|
|
|
world->getPlayer().setTeleported(true);
|
|
|
|
world->indexToPosition (x, y, pos.pos[0], pos.pos[1], true);
|
2010-08-20 13:33:03 +02:00
|
|
|
pos.pos[2] = 0;
|
2010-08-22 21:30:48 +02:00
|
|
|
|
2010-08-20 13:33:03 +02:00
|
|
|
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
|
2010-08-22 21:30:48 +02:00
|
|
|
|
2013-12-31 20:40:23 +01:00
|
|
|
world->changeToExteriorCell (pos);
|
2010-08-20 13:33:03 +02:00
|
|
|
}
|
2010-07-22 12:29:23 +02:00
|
|
|
};
|
2010-08-20 13:33:03 +02:00
|
|
|
|
2011-01-17 10:18:12 +01:00
|
|
|
class OpGetInterior : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
|
|
|
bool interior =
|
2014-02-21 11:35:46 +01:00
|
|
|
!MWBase::Environment::get().getWorld()->getPlayerPtr().getCell()->getCell()->isExterior();
|
2011-01-17 10:18:12 +01:00
|
|
|
|
|
|
|
runtime.push (interior ? 1 : 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-04-04 15:10:37 +02:00
|
|
|
class OpGetPCCell : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
|
|
|
std::string name = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
|
2014-02-21 11:35:46 +01:00
|
|
|
const ESM::Cell *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell()->getCell();
|
2011-04-04 15:10:37 +02:00
|
|
|
|
2012-09-17 11:37:50 +04:00
|
|
|
std::string current = cell->mName;
|
2011-04-04 15:10:37 +02:00
|
|
|
|
2014-01-08 19:57:13 +01:00
|
|
|
if (!(cell->mData.mFlags & ESM::Cell::Interior) && current.empty()
|
|
|
|
&& !cell->mRegion.empty())
|
2011-04-04 15:10:37 +02:00
|
|
|
{
|
|
|
|
const ESM::Region *region =
|
2012-11-05 22:34:08 +04:00
|
|
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Region>().find (cell->mRegion);
|
2011-04-04 15:10:37 +02:00
|
|
|
|
2012-09-17 11:37:50 +04:00
|
|
|
current = region->mName;
|
2011-04-04 15:10:37 +02:00
|
|
|
}
|
2014-01-22 14:45:36 +01:00
|
|
|
Misc::StringUtils::toLower(current);
|
2011-04-04 15:10:37 +02:00
|
|
|
|
|
|
|
bool match = current.length()>=name.length() &&
|
|
|
|
current.substr (0, name.length())==name;
|
|
|
|
|
|
|
|
runtime.push (match ? 1 : 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-29 15:50:15 +02:00
|
|
|
class OpGetWaterLevel : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
2014-01-24 18:21:52 +01:00
|
|
|
MWWorld::CellStore *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell();
|
2014-02-21 11:35:46 +01:00
|
|
|
if (cell->getCell()->hasWater())
|
2014-02-23 17:34:18 +01:00
|
|
|
runtime.push (cell->getWaterLevel());
|
2014-01-08 20:19:47 +01:00
|
|
|
else
|
|
|
|
runtime.push (-std::numeric_limits<float>().max());
|
2012-03-29 15:50:15 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpSetWaterLevel : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
|
|
|
Interpreter::Type_Float level = runtime[0].mFloat;
|
|
|
|
|
2014-01-24 18:21:52 +01:00
|
|
|
MWWorld::CellStore *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell();
|
2012-03-29 16:23:02 +02:00
|
|
|
|
2014-02-21 11:35:46 +01:00
|
|
|
if (cell->getCell()->isExterior())
|
2012-03-29 16:23:02 +02:00
|
|
|
throw std::runtime_error("Can't set water level in exterior cell");
|
|
|
|
|
2014-02-23 17:34:18 +01:00
|
|
|
cell->setWaterLevel (level);
|
|
|
|
MWBase::Environment::get().getWorld()->setWaterHeight (cell->getWaterLevel());
|
2012-03-29 15:50:15 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpModWaterLevel : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void execute (Interpreter::Runtime& runtime)
|
|
|
|
{
|
|
|
|
Interpreter::Type_Float level = runtime[0].mFloat;
|
|
|
|
|
2014-01-24 18:21:52 +01:00
|
|
|
MWWorld::CellStore *cell = MWBase::Environment::get().getWorld()->getPlayerPtr().getCell();
|
2012-03-29 16:23:02 +02:00
|
|
|
|
2014-02-21 11:35:46 +01:00
|
|
|
if (cell->getCell()->isExterior())
|
2012-03-29 16:23:02 +02:00
|
|
|
throw std::runtime_error("Can't set water level in exterior cell");
|
2012-04-23 15:27:03 +02:00
|
|
|
|
2014-02-23 17:34:18 +01:00
|
|
|
cell->setWaterLevel (cell->getWaterLevel()+level);
|
|
|
|
MWBase::Environment::get().getWorld()->setWaterHeight(cell->getWaterLevel());
|
2012-03-29 15:50:15 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-08-20 13:33:03 +02:00
|
|
|
|
2010-07-03 12:12:13 +02:00
|
|
|
void installOpcodes (Interpreter::Interpreter& interpreter)
|
|
|
|
{
|
2013-08-06 20:38:41 -04:00
|
|
|
interpreter.installSegment5 (Compiler::Cell::opcodeCellChanged, new OpCellChanged);
|
|
|
|
interpreter.installSegment5 (Compiler::Cell::opcodeCOC, new OpCOC);
|
|
|
|
interpreter.installSegment5 (Compiler::Cell::opcodeCOE, new OpCOE);
|
|
|
|
interpreter.installSegment5 (Compiler::Cell::opcodeGetInterior, new OpGetInterior);
|
|
|
|
interpreter.installSegment5 (Compiler::Cell::opcodeGetPCCell, new OpGetPCCell);
|
|
|
|
interpreter.installSegment5 (Compiler::Cell::opcodeGetWaterLevel, new OpGetWaterLevel);
|
|
|
|
interpreter.installSegment5 (Compiler::Cell::opcodeSetWaterLevel, new OpSetWaterLevel);
|
|
|
|
interpreter.installSegment5 (Compiler::Cell::opcodeModWaterLevel, new OpModWaterLevel);
|
2010-07-03 12:12:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|