mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-06 21:45:35 +00:00
Avoid using findCellPosition for coc command implementation
It breaks teleport to interior cells and in general is very fragile because of using exception for common logic path. Remove the function since it's not used anywhere else.
This commit is contained in:
parent
f5d470395d
commit
83e60fef4e
4 changed files with 14 additions and 28 deletions
|
@ -519,9 +519,6 @@ namespace MWBase
|
|||
/// \return empty RefId if interior with given name not exists, the cell's RefId otherwise
|
||||
virtual ESM::RefId findInteriorPosition(std::string_view name, ESM::Position& pos) = 0;
|
||||
|
||||
/// Find default position inside interior or exterior cell specified by name
|
||||
/// \return empty RefId if interior with given name not exists, the cell's RefId otherwise
|
||||
virtual ESM::RefId findCellPosition(std::string_view cellName, ESM::Position& pos) = 0;
|
||||
/// Enables or disables use of teleport spell effects (recall, intervention, etc).
|
||||
virtual void enableTeleporting(bool enable) = 0;
|
||||
|
||||
|
|
|
@ -92,11 +92,19 @@ namespace MWScript
|
|||
ESM::Position pos;
|
||||
MWBase::World* world = MWBase::Environment::get().getWorld();
|
||||
const MWWorld::Ptr playerPtr = world->getPlayerPtr();
|
||||
ESM::RefId cellId = world->findCellPosition(cell, pos);
|
||||
if (cellId.empty())
|
||||
throw std::runtime_error("Cell '" + std::string{ cell } + "' not found");
|
||||
MWWorld::ActionTeleport(cellId, pos, false).execute(playerPtr);
|
||||
world->adjustPosition(playerPtr, false);
|
||||
|
||||
if (const ESM::RefId refId = world->findExteriorPosition(cell, pos); !refId.empty())
|
||||
{
|
||||
MWWorld::ActionTeleport(refId, pos, false).execute(playerPtr);
|
||||
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");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -2841,25 +2841,6 @@ namespace MWWorld
|
|||
return ESM::RefId::sEmpty;
|
||||
}
|
||||
|
||||
ESM::RefId World::findCellPosition(std::string_view cellName, ESM::Position& pos)
|
||||
{
|
||||
ESM::RefId foundCell;
|
||||
try
|
||||
{
|
||||
foundCell = findInteriorPosition(cellName, pos);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
Log(Debug::Error) << e.what();
|
||||
}
|
||||
if (foundCell.empty())
|
||||
{
|
||||
return findExteriorPosition(cellName, pos);
|
||||
}
|
||||
|
||||
return foundCell;
|
||||
}
|
||||
|
||||
ESM::RefId World::findExteriorPosition(std::string_view nameId, ESM::Position& pos)
|
||||
{
|
||||
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
|
||||
|
|
|
@ -606,7 +606,7 @@ namespace MWWorld
|
|||
/// Find position in interior cell near door entrance
|
||||
/// \return false if interior with given name not exists, true otherwise
|
||||
ESM::RefId findInteriorPosition(std::string_view name, ESM::Position& pos) override;
|
||||
ESM::RefId findCellPosition(std::string_view cellName, ESM::Position& pos) override;
|
||||
|
||||
/// Enables or disables use of teleport spell effects (recall, intervention, etc).
|
||||
void enableTeleporting(bool enable) override;
|
||||
|
||||
|
|
Loading…
Reference in a new issue