From 83e60fef4eaaa752fb4a6f459222b65dbaf30ffa Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 9 Apr 2023 03:00:16 +0200 Subject: [PATCH] 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. --- apps/openmw/mwbase/world.hpp | 3 --- apps/openmw/mwscript/cellextensions.cpp | 18 +++++++++++++----- apps/openmw/mwworld/worldimp.cpp | 19 ------------------- apps/openmw/mwworld/worldimp.hpp | 2 +- 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index bd43d689d3..c33655ee65 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -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; diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index 1d012c0d0a..1c212d5f8c 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -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"); } }; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index df0b0bcb3e..218aefcdf6 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -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; diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index dac6df120c..7b24beb9d6 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -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;