2010-07-03 10:12:13 +00:00
|
|
|
#include "cellextensions.hpp"
|
|
|
|
|
2015-06-03 21:04:35 +00:00
|
|
|
#include <limits>
|
|
|
|
|
2012-10-01 15:17:04 +00:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2012-07-03 10:30:50 +00:00
|
|
|
|
2013-08-07 00:38:41 +00:00
|
|
|
#include <components/compiler/opcodes.hpp>
|
2010-07-03 10:12:13 +00:00
|
|
|
|
|
|
|
#include <components/interpreter/interpreter.hpp>
|
|
|
|
#include <components/interpreter/runtime.hpp>
|
|
|
|
#include <components/interpreter/opcodes.hpp>
|
|
|
|
|
2019-11-24 13:40:19 +00:00
|
|
|
#include "../mwworld/actionteleport.hpp"
|
|
|
|
#include "../mwworld/cellstore.hpp"
|
2012-04-23 13:27:03 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2011-01-17 09:18:12 +00:00
|
|
|
#include "../mwworld/player.hpp"
|
2019-11-24 13:40:19 +00:00
|
|
|
#include "../mwbase/statemanager.hpp"
|
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
2010-07-03 13:04:00 +00:00
|
|
|
|
2015-08-21 09:12:39 +00:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
|
|
|
|
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
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2010-07-03 10:12:13 +00:00
|
|
|
{
|
2012-04-23 13:27:03 +00:00
|
|
|
runtime.push (MWBase::Environment::get().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
|
|
|
|
2019-11-24 13:40:19 +00:00
|
|
|
class OpTestCells : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2019-11-24 13:40:19 +00:00
|
|
|
{
|
|
|
|
if (MWBase::Environment::get().getStateManager()->getState() != MWBase::StateManager::State_NoGame)
|
|
|
|
{
|
|
|
|
runtime.getContext().report("Use TestCells from the main menu, when there is no active game session.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wasConsole = MWBase::Environment::get().getWindowManager()->isConsoleMode();
|
|
|
|
if (wasConsole)
|
|
|
|
MWBase::Environment::get().getWindowManager()->toggleConsole();
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWorld()->testExteriorCells();
|
|
|
|
|
|
|
|
if (wasConsole)
|
|
|
|
MWBase::Environment::get().getWindowManager()->toggleConsole();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpTestInteriorCells : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2019-11-24 13:40:19 +00:00
|
|
|
{
|
|
|
|
if (MWBase::Environment::get().getStateManager()->getState() != MWBase::StateManager::State_NoGame)
|
|
|
|
{
|
|
|
|
runtime.getContext().report("Use TestInteriorCells from the main menu, when there is no active game session.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wasConsole = MWBase::Environment::get().getWindowManager()->isConsoleMode();
|
|
|
|
if (wasConsole)
|
|
|
|
MWBase::Environment::get().getWindowManager()->toggleConsole();
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWorld()->testInteriorCells();
|
|
|
|
|
|
|
|
if (wasConsole)
|
|
|
|
MWBase::Environment::get().getWindowManager()->toggleConsole();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-22 10:29:23 +00:00
|
|
|
class OpCOC : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2010-08-20 11:33:03 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
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;
|
2013-07-06 08:42:29 +00:00
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
2018-09-13 09:21:38 +00:00
|
|
|
const MWWorld::Ptr playerPtr = world->getPlayerPtr();
|
2010-09-11 09:55:28 +00:00
|
|
|
|
2013-12-31 19:40:23 +00:00
|
|
|
if (world->findExteriorPosition(cell, pos))
|
|
|
|
{
|
2018-09-13 09:21:38 +00:00
|
|
|
MWWorld::ActionTeleport("", pos, false).execute(playerPtr);
|
|
|
|
world->adjustPosition(playerPtr, false);
|
2010-09-11 09:55:28 +00:00
|
|
|
}
|
2013-12-31 19:40:23 +00:00
|
|
|
else
|
|
|
|
{
|
2013-07-06 08:42:29 +00:00
|
|
|
// Change to interior even if findInteriorPosition()
|
|
|
|
// yields false. In this case position will be zero-point.
|
2013-07-07 11:03:06 +00:00
|
|
|
world->findInteriorPosition(cell, pos);
|
2018-09-13 09:21:38 +00:00
|
|
|
MWWorld::ActionTeleport(cell, pos, false).execute(playerPtr);
|
2010-09-11 09:55:28 +00:00
|
|
|
}
|
2010-08-20 11:33:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpCOE : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2010-08-20 11:33:03 +00:00
|
|
|
{
|
|
|
|
Interpreter::Type_Integer x = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
Interpreter::Type_Integer y = runtime[0].mInteger;
|
|
|
|
runtime.pop();
|
|
|
|
|
|
|
|
ESM::Position pos;
|
2013-12-31 19:40:23 +00:00
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
2018-09-13 09:21:38 +00:00
|
|
|
const MWWorld::Ptr playerPtr = world->getPlayerPtr();
|
2017-02-20 19:26:45 +00:00
|
|
|
|
2013-12-31 19:40:23 +00:00
|
|
|
world->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
|
|
|
|
2018-09-13 09:21:38 +00:00
|
|
|
MWWorld::ActionTeleport("", pos, false).execute(playerPtr);
|
|
|
|
world->adjustPosition(playerPtr, false);
|
2010-08-20 11:33:03 +00:00
|
|
|
}
|
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:
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2011-01-17 09:18:12 +00:00
|
|
|
{
|
2015-08-21 09:12:39 +00:00
|
|
|
if (!MWMechanics::getPlayer().isInCell())
|
2014-05-24 21:50:19 +00:00
|
|
|
{
|
|
|
|
runtime.push (0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-17 09:18:12 +00:00
|
|
|
bool interior =
|
2015-08-21 09:12:39 +00:00
|
|
|
!MWMechanics::getPlayer().getCell()->getCell()->isExterior();
|
2011-01-17 09:18:12 +00:00
|
|
|
|
|
|
|
runtime.push (interior ? 1 : 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-04-04 13:10:37 +00:00
|
|
|
class OpGetPCCell : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2011-04-04 13:10:37 +00:00
|
|
|
{
|
|
|
|
std::string name = runtime.getStringLiteral (runtime[0].mInteger);
|
|
|
|
runtime.pop();
|
|
|
|
|
2015-08-21 09:12:39 +00:00
|
|
|
if (!MWMechanics::getPlayer().isInCell())
|
2014-05-19 12:09:16 +00:00
|
|
|
{
|
|
|
|
runtime.push(0);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-21 09:12:39 +00:00
|
|
|
const MWWorld::CellStore *cell = MWMechanics::getPlayer().getCell();
|
2011-04-04 13:10:37 +00:00
|
|
|
|
2014-12-18 16:48:46 +00:00
|
|
|
std::string current = MWBase::Environment::get().getWorld()->getCellName(cell);
|
2015-12-07 21:49:15 +00:00
|
|
|
Misc::StringUtils::lowerCaseInPlace(current);
|
2011-04-04 13:10:37 +00:00
|
|
|
|
|
|
|
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:
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-03-29 13:50:15 +00:00
|
|
|
{
|
2015-08-21 09:12:39 +00:00
|
|
|
if (!MWMechanics::getPlayer().isInCell())
|
2014-05-25 13:06:53 +00:00
|
|
|
{
|
|
|
|
runtime.push(0.f);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-21 09:12:39 +00:00
|
|
|
MWWorld::CellStore *cell = MWMechanics::getPlayer().getCell();
|
2015-12-03 14:48:27 +00:00
|
|
|
if (cell->isExterior())
|
|
|
|
runtime.push(0.f); // vanilla oddity, return 0 even though water is actually at -1
|
|
|
|
else if (cell->getCell()->hasWater())
|
2014-02-23 16:34:18 +00:00
|
|
|
runtime.push (cell->getWaterLevel());
|
2014-01-08 19:19:47 +00:00
|
|
|
else
|
2014-10-12 21:26:03 +00:00
|
|
|
runtime.push (-std::numeric_limits<float>::max());
|
2012-03-29 13:50:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpSetWaterLevel : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-03-29 13:50:15 +00:00
|
|
|
{
|
|
|
|
Interpreter::Type_Float level = runtime[0].mFloat;
|
|
|
|
|
2015-08-21 09:12:39 +00:00
|
|
|
if (!MWMechanics::getPlayer().isInCell())
|
2014-05-25 13:06:53 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-21 09:12:39 +00:00
|
|
|
MWWorld::CellStore *cell = MWMechanics::getPlayer().getCell();
|
2012-03-29 14:23:02 +00:00
|
|
|
|
2014-02-21 10:35:46 +00:00
|
|
|
if (cell->getCell()->isExterior())
|
2012-03-29 14:23:02 +00:00
|
|
|
throw std::runtime_error("Can't set water level in exterior cell");
|
|
|
|
|
2014-02-23 16:34:18 +00:00
|
|
|
cell->setWaterLevel (level);
|
|
|
|
MWBase::Environment::get().getWorld()->setWaterHeight (cell->getWaterLevel());
|
2012-03-29 13:50:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpModWaterLevel : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void execute (Interpreter::Runtime& runtime) override
|
2012-03-29 13:50:15 +00:00
|
|
|
{
|
|
|
|
Interpreter::Type_Float level = runtime[0].mFloat;
|
|
|
|
|
2015-08-21 09:12:39 +00:00
|
|
|
if (!MWMechanics::getPlayer().isInCell())
|
2014-05-25 13:06:53 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-21 09:12:39 +00:00
|
|
|
MWWorld::CellStore *cell = MWMechanics::getPlayer().getCell();
|
2012-03-29 14:23:02 +00:00
|
|
|
|
2014-02-21 10:35:46 +00:00
|
|
|
if (cell->getCell()->isExterior())
|
2012-03-29 14:23:02 +00:00
|
|
|
throw std::runtime_error("Can't set water level in exterior cell");
|
2012-04-23 13:27:03 +00:00
|
|
|
|
2014-02-23 16:34:18 +00:00
|
|
|
cell->setWaterLevel (cell->getWaterLevel()+level);
|
|
|
|
MWBase::Environment::get().getWorld()->setWaterHeight(cell->getWaterLevel());
|
2012-03-29 13:50:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-08-20 11:33:03 +00:00
|
|
|
|
2010-07-03 10:12:13 +00:00
|
|
|
void installOpcodes (Interpreter::Interpreter& interpreter)
|
|
|
|
{
|
2013-08-07 00:38:41 +00:00
|
|
|
interpreter.installSegment5 (Compiler::Cell::opcodeCellChanged, new OpCellChanged);
|
2019-11-24 13:40:19 +00:00
|
|
|
interpreter.installSegment5 (Compiler::Cell::opcodeTestCells, new OpTestCells);
|
|
|
|
interpreter.installSegment5 (Compiler::Cell::opcodeTestInteriorCells, new OpTestInteriorCells);
|
2013-08-07 00:38:41 +00:00
|
|
|
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 10:12:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|