2010-07-03 12:12:13 +02:00
|
|
|
#include "cellextensions.hpp"
|
|
|
|
|
2015-06-03 23:04:35 +02:00
|
|
|
#include <limits>
|
|
|
|
|
2013-08-06 20:38:41 -04:00
|
|
|
#include <components/compiler/opcodes.hpp>
|
2010-07-03 12:12:13 +02:00
|
|
|
|
2023-07-28 15:23:53 +02:00
|
|
|
#include <components/interpreter/context.hpp>
|
2010-07-03 12:12:13 +02:00
|
|
|
#include <components/interpreter/interpreter.hpp>
|
|
|
|
#include <components/interpreter/opcodes.hpp>
|
|
|
|
#include <components/interpreter/runtime.hpp>
|
|
|
|
|
2023-07-28 15:23:53 +02:00
|
|
|
#include <components/misc/strings/algorithm.hpp>
|
|
|
|
|
2012-04-23 15:27:03 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2019-11-24 17:40:19 +04:00
|
|
|
#include "../mwbase/statemanager.hpp"
|
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
#include "../mwworld/actionteleport.hpp"
|
|
|
|
#include "../mwworld/cellstore.hpp"
|
2022-11-06 20:06:45 +01:00
|
|
|
#include "../mwworld/scene.hpp"
|
2010-07-03 15:04:00 +02:00
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
|
|
|
|
2010-07-03 12:12:13 +02:00
|
|
|
namespace MWScript
|
|
|
|
{
|
|
|
|
namespace Cell
|
|
|
|
{
|
|
|
|
class OpCellChanged : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2010-07-03 12:12:13 +02:00
|
|
|
{
|
2022-11-06 20:06:45 +01:00
|
|
|
runtime.push(MWBase::Environment::get().getWorldScene()->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
|
|
|
|
2019-11-24 17:40:19 +04:00
|
|
|
class OpTestCells : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2020-10-16 22:18:54 +04:00
|
|
|
if (MWBase::Environment::get().getStateManager()->getState() != MWBase::StateManager::State_NoGame)
|
2019-11-24 17:40:19 +04:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
2022-11-06 20:06:45 +01:00
|
|
|
MWBase::Environment::get().getWorldScene()->testExteriorCells();
|
2019-11-24 17:40:19 +04:00
|
|
|
|
|
|
|
if (wasConsole)
|
|
|
|
MWBase::Environment::get().getWindowManager()->toggleConsole();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpTestInteriorCells : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2020-10-16 22:18:54 +04:00
|
|
|
if (MWBase::Environment::get().getStateManager()->getState() != MWBase::StateManager::State_NoGame)
|
2019-11-24 17:40:19 +04:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
2022-11-06 20:06:45 +01:00
|
|
|
MWBase::Environment::get().getWorldScene()->testInteriorCells();
|
2019-11-24 17:40:19 +04:00
|
|
|
|
|
|
|
if (wasConsole)
|
|
|
|
MWBase::Environment::get().getWindowManager()->toggleConsole();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-22 12:29:23 +02:00
|
|
|
class OpCOC : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2023-01-19 17:31:45 +01:00
|
|
|
std::string_view cell = runtime.getStringLiteral(runtime[0].mInteger);
|
2010-08-20 13:33:03 +02:00
|
|
|
runtime.pop();
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
ESM::Position pos;
|
|
|
|
MWBase::World* world = MWBase::Environment::get().getWorld();
|
2023-07-20 02:13:55 +02:00
|
|
|
MWWorld::Ptr playerPtr = world->getPlayerPtr();
|
2023-04-09 03:00:16 +02:00
|
|
|
|
|
|
|
if (const ESM::RefId refId = world->findExteriorPosition(cell, pos); !refId.empty())
|
|
|
|
{
|
|
|
|
MWWorld::ActionTeleport(refId, pos, false).execute(playerPtr);
|
2023-07-20 02:13:55 +02:00
|
|
|
playerPtr = world->getPlayerPtr(); // could be changed by ActionTeleport
|
2023-04-09 03:00:16 +02:00
|
|
|
world->adjustPosition(playerPtr, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (const ESM::RefId refId = world->findInteriorPosition(cell, pos); !refId.empty())
|
|
|
|
{
|
|
|
|
MWWorld::ActionTeleport(refId, pos, false).execute(playerPtr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
throw std::runtime_error("Cell " + std::string(cell) + " is not found");
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2010-08-20 13:33:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class OpCOE : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2010-08-20 13:33:03 +02: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 20:40:23 +01:00
|
|
|
MWBase::World* world = MWBase::Environment::get().getWorld();
|
2023-07-20 02:13:55 +02:00
|
|
|
MWWorld::Ptr playerPtr = world->getPlayerPtr();
|
2017-02-20 20:26:45 +01:00
|
|
|
|
2023-05-09 23:44:57 +02:00
|
|
|
osg::Vec2 posFromIndex
|
2023-05-12 13:24:59 +02:00
|
|
|
= ESM::indexToPosition(ESM::ExteriorCellLocation(x, y, ESM::Cell::sDefaultWorldspaceId), true);
|
2023-05-09 23:44:57 +02:00
|
|
|
pos.pos[0] = posFromIndex.x();
|
|
|
|
pos.pos[1] = posFromIndex.y();
|
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
|
|
|
|
2023-04-06 12:52:52 +02:00
|
|
|
MWWorld::ActionTeleport(ESM::RefId::esm3ExteriorCell(x, y), pos, false).execute(playerPtr);
|
2023-07-20 02:13:55 +02:00
|
|
|
playerPtr = world->getPlayerPtr(); // could be changed by ActionTeleport
|
2018-09-13 13:21:38 +04:00
|
|
|
world->adjustPosition(playerPtr, false);
|
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:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2020-10-16 22:18:54 +04:00
|
|
|
if (!MWMechanics::getPlayer().isInCell())
|
2011-01-17 10:18:12 +01:00
|
|
|
{
|
2014-05-25 07:50:19 +10:00
|
|
|
runtime.push(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
bool interior = !MWMechanics::getPlayer().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:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2022-05-21 01:21:55 +02:00
|
|
|
std::string_view name = runtime.getStringLiteral(runtime[0].mInteger);
|
2011-04-04 15:10:37 +02:00
|
|
|
runtime.pop();
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
if (!MWMechanics::getPlayer().isInCell())
|
2011-04-04 15:10:37 +02:00
|
|
|
{
|
2014-05-19 14:09:16 +02:00
|
|
|
runtime.push(0);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-21 21:12:39 +12:00
|
|
|
const MWWorld::CellStore* cell = MWMechanics::getPlayer().getCell();
|
2011-04-04 15:10:37 +02:00
|
|
|
|
2022-12-01 22:09:30 +01:00
|
|
|
std::string_view current = MWBase::Environment::get().getWorld()->getCellName(cell);
|
2022-08-12 19:42:35 +02:00
|
|
|
bool match = Misc::StringUtils::ciCompareLen(name, current, name.length()) == 0;
|
2011-04-04 15:10:37 +02:00
|
|
|
|
|
|
|
runtime.push(match ? 1 : 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-03-29 15:50:15 +02:00
|
|
|
class OpGetWaterLevel : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2020-10-16 22:18:54 +04:00
|
|
|
if (!MWMechanics::getPlayer().isInCell())
|
2012-03-29 15:50:15 +02:00
|
|
|
{
|
2014-05-25 15:06:53 +02:00
|
|
|
runtime.push(0.f);
|
|
|
|
return;
|
2012-03-29 15:50:15 +02:00
|
|
|
}
|
2015-08-21 21:12:39 +12:00
|
|
|
MWWorld::CellStore* cell = MWMechanics::getPlayer().getCell();
|
2015-12-03 15:48:27 +01: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 17:34:18 +01:00
|
|
|
runtime.push(cell->getWaterLevel());
|
2022-09-22 21:26:05 +03:00
|
|
|
else
|
2014-10-12 23:26:03 +02:00
|
|
|
runtime.push(-std::numeric_limits<float>::max());
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2012-03-29 15:50:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class OpSetWaterLevel : public Interpreter::Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2012-03-29 15:50:15 +02:00
|
|
|
Interpreter::Type_Float level = runtime[0].mFloat;
|
2022-04-30 16:45:45 +02:00
|
|
|
runtime.pop();
|
2012-03-29 15:50:15 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
if (!MWMechanics::getPlayer().isInCell())
|
2012-03-29 15:50:15 +02:00
|
|
|
{
|
2014-05-25 15:06:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
MWWorld::CellStore* cell = MWMechanics::getPlayer().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:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Interpreter::Runtime& runtime) override
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2012-03-29 15:50:15 +02:00
|
|
|
Interpreter::Type_Float level = runtime[0].mFloat;
|
2022-04-30 16:45:45 +02:00
|
|
|
runtime.pop();
|
2012-03-29 15:50:15 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
if (!MWMechanics::getPlayer().isInCell())
|
2012-03-29 15:50:15 +02:00
|
|
|
{
|
2014-05-25 15:06:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
MWWorld::CellStore* cell = MWMechanics::getPlayer().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-07-03 12:12:13 +02:00
|
|
|
void installOpcodes(Interpreter::Interpreter& interpreter)
|
|
|
|
{
|
2022-01-27 19:18:57 +00:00
|
|
|
interpreter.installSegment5<OpCellChanged>(Compiler::Cell::opcodeCellChanged);
|
|
|
|
interpreter.installSegment5<OpTestCells>(Compiler::Cell::opcodeTestCells);
|
|
|
|
interpreter.installSegment5<OpTestInteriorCells>(Compiler::Cell::opcodeTestInteriorCells);
|
|
|
|
interpreter.installSegment5<OpCOC>(Compiler::Cell::opcodeCOC);
|
|
|
|
interpreter.installSegment5<OpCOE>(Compiler::Cell::opcodeCOE);
|
|
|
|
interpreter.installSegment5<OpGetInterior>(Compiler::Cell::opcodeGetInterior);
|
|
|
|
interpreter.installSegment5<OpGetPCCell>(Compiler::Cell::opcodeGetPCCell);
|
|
|
|
interpreter.installSegment5<OpGetWaterLevel>(Compiler::Cell::opcodeGetWaterLevel);
|
|
|
|
interpreter.installSegment5<OpSetWaterLevel>(Compiler::Cell::opcodeSetWaterLevel);
|
|
|
|
interpreter.installSegment5<OpModWaterLevel>(Compiler::Cell::opcodeModWaterLevel);
|
2010-07-03 12:12:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|