From c9c9599ec54c3e06947e859d9e2227fe5009750e Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Fri, 22 May 2020 14:04:26 +0300 Subject: [PATCH] Improve GetDistance and object search warnings (bug #5427) Allow GetDistance to work with a non-existent object argument or with inventory items that belong to a container store that doesn't exist --- CHANGELOG.md | 1 + .../mwscript/transformationextensions.cpp | 20 ++++++++++++++++--- apps/openmw/mwworld/worldimp.cpp | 5 ++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fc9e827c..285301a1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Bug #5415: Environment maps in ebony cuirass and HiRez Armors Indoril cuirass don't work Bug #5416: Junk non-node records before the root node are not handled gracefully Bug #5424: Creatures do not headtrack player + Bug #5427: GetDistance unknown ID error is misleading Feature #5362: Show the soul gems' trapped soul in count dialog 0.46.0 diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index 3af54b394..791d054f3 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -46,10 +46,10 @@ namespace MWScript virtual void execute (Interpreter::Runtime& runtime) { + MWWorld::Ptr from = R()(runtime); std::string name = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - MWWorld::Ptr from = R()(runtime); if (from.getContainerStore()) // is the object contained? { MWWorld::Ptr container = MWBase::Environment::get().getWorld()->findContainer(from); @@ -57,10 +57,24 @@ namespace MWScript if (!container.isEmpty()) from = container; else - throw std::runtime_error("failed to find container ptr"); + { + std::string error = "Failed to find the container of object '" + from.getCellRef().getRefId() + "'"; + runtime.getContext().report(error); + Log(Debug::Error) << error; + runtime.push(0.f); + return; + } } - const MWWorld::Ptr to = MWBase::Environment::get().getWorld()->getPtr(name, false); + const MWWorld::Ptr to = MWBase::Environment::get().getWorld()->searchPtr(name, false); + if (to.isEmpty()) + { + std::string error = "Failed to find an instance of object '" + name + "'"; + runtime.getContext().report(error); + Log(Debug::Error) << error; + runtime.push(0.f); + return; + } float distance; // If the objects are in different worldspaces, return a large value (just like vanilla) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 8caec9876..ba4a6467a 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -741,7 +741,10 @@ namespace MWWorld Ptr ret = searchPtr(name, activeOnly); if (!ret.isEmpty()) return ret; - throw std::runtime_error ("unknown ID: " + name); + std::string error = "failed to find an instance of object '" + name + "'"; + if (activeOnly) + error += " in active cells"; + throw std::runtime_error(error); } Ptr World::searchPtrViaActorId (int actorId)