From 2ce8323a422776f957067fde24ebe40317f17d11 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 16 Jun 2014 16:34:00 +0200 Subject: [PATCH] Fix getDistance not detecting references in inactive cells properly --- apps/openmw/mwscript/interpretercontext.cpp | 12 ++++++++++-- apps/openmw/mwscript/interpretercontext.hpp | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index ebe88c3a4..028f83a61 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -378,12 +378,20 @@ namespace MWScript float InterpreterContext::getDistance (const std::string& name, const std::string& id) const { - const MWWorld::Ptr ref2 = getReference (id, false, false); + // NOTE: id may be empty, indicating an implicit reference + + MWWorld::Ptr ref2; + + if (id.empty()) + ref2 = getReference("", true, true); + else + ref2 = MWBase::Environment::get().getWorld()->searchPtr(id, true); + // If either actor is in a non-active cell, return a large value (just like vanilla) if (ref2.isEmpty()) return std::numeric_limits().max(); - const MWWorld::Ptr ref = getReference (name, false, false); + const MWWorld::Ptr ref = MWBase::Environment::get().getWorld()->searchPtr(name, true); if (ref.isEmpty()) return std::numeric_limits().max(); diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index fdf9d6424..99026392e 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -118,6 +118,7 @@ namespace MWScript virtual void stopScript (const std::string& name); virtual float getDistance (const std::string& name, const std::string& id = "") const; + ///< @note if \a id is empty, assumes an implicit reference bool hasBeenActivated (const MWWorld::Ptr& ptr); ///< \attention Calling this function for the right reference will mark the action as