From ac747f02f32b71d65e0211f375c04ed0e0af70e8 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 26 Dec 2021 15:27:25 +0000 Subject: [PATCH] Don't teleport NPCs to unknown cells --- .../mwscript/transformationextensions.cpp | 19 +++++++---- apps/openmw/mwworld/worldimp.cpp | 8 +++++ components/compiler/lineparser.cpp | 33 +++---------------- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index 292965fd94..8a159a5685 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -355,7 +355,8 @@ namespace MWScript if (ptr.getContainerStore()) return; - if (ptr == MWMechanics::getPlayer()) + bool isPlayer = ptr == MWMechanics::getPlayer(); + if (isPlayer) { MWBase::Environment::get().getWorld()->getPlayer().setTeleported(true); } @@ -378,17 +379,21 @@ namespace MWScript } catch(std::exception&) { - // cell not found, move to exterior instead (vanilla PositionCell compatibility) + // cell not found, move to exterior instead if moving the player (vanilla PositionCell compatibility) const ESM::Cell* cell = MWBase::Environment::get().getWorld()->getExterior(cellID); - int cx,cy; - MWBase::Environment::get().getWorld()->positionToIndex(x,y,cx,cy); - store = MWBase::Environment::get().getWorld()->getExterior(cx,cy); if(!cell) { - std::string error = "Warning: PositionCell: unknown interior cell (" + cellID + "), moving to exterior instead"; + std::string error = "Warning: PositionCell: unknown interior cell (" + cellID + ")"; + if(isPlayer) + error += ", moving to exterior instead"; runtime.getContext().report (error); Log(Debug::Warning) << error; + if(!isPlayer) + return; } + int cx,cy; + MWBase::Environment::get().getWorld()->positionToIndex(x,y,cx,cy); + store = MWBase::Environment::get().getWorld()->getExterior(cx,cy); } if(store) { @@ -400,7 +405,7 @@ namespace MWScript // Note that you must specify ZRot in minutes (1 degree = 60 minutes; north = 0, east = 5400, south = 10800, west = 16200) // except for when you position the player, then degrees must be used. // See "Morrowind Scripting for Dummies (9th Edition)" pages 50 and 54 for reference. - if(ptr != MWMechanics::getPlayer()) + if(!isPlayer) zRot = zRot/60.0f; rot.z() = osg::DegreesToRadians(zRot); MWBase::Environment::get().getWorld()->rotateObject(ptr,rot); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index a44646ef37..325e048958 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -550,6 +550,14 @@ namespace MWWorld const ESM::Cell *cell = mStore.get().searchExtByName (cellName); if (cell) return cell; + // treat "Wilderness" like an empty string + static const std::string defaultName = mStore.get().find("sDefaultCellname")->mValue.getString(); + if (Misc::StringUtils::ciEqual(cellName, defaultName)) + { + cell = mStore.get().searchExtByName(""); + if (cell) + return cell; + } // didn't work -> now check for regions for (const ESM::Region ®ion : mStore.get()) diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp index 2e398618a3..3ad8c5bbe2 100644 --- a/components/compiler/lineparser.cpp +++ b/components/compiler/lineparser.cpp @@ -12,7 +12,6 @@ #include "generator.hpp" #include "extensions.hpp" #include "declarationparser.hpp" -#include "exception.hpp" namespace Compiler { @@ -259,33 +258,11 @@ namespace Compiler mExplicit.clear(); } - try - { - // workaround for broken positioncell instructions. - /// \todo add option to disable this - std::unique_ptr errorDowngrade (nullptr); - if (Misc::StringUtils::lowerCase (loc.mLiteral)=="positioncell") - errorDowngrade = std::make_unique (getErrorHandler()); - - std::vector code; - int optionals = mExprParser.parseArguments (argumentType, scanner, code, keyword); - mCode.insert (mCode.end(), code.begin(), code.end()); - extensions->generateInstructionCode (keyword, mCode, mLiterals, - mExplicit, optionals); - } - catch (const SourceException&) - { - // Ignore argument exceptions for positioncell. - /// \todo add option to disable this - if (Misc::StringUtils::lowerCase (loc.mLiteral)=="positioncell") - { - SkipParser skip (getErrorHandler(), getContext()); - scanner.scan (skip); - return false; - } - - throw; - } + std::vector code; + int optionals = mExprParser.parseArguments (argumentType, scanner, code, keyword); + mCode.insert (mCode.end(), code.begin(), code.end()); + extensions->generateInstructionCode (keyword, mCode, mLiterals, + mExplicit, optionals); mState = EndState; return true;