From 67c8d73fe01a31932adb437054805440857f0d71 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 14 Feb 2021 16:25:38 +0100 Subject: [PATCH] Allow scripts to fail per target --- apps/openmw/mwscript/interpretercontext.cpp | 10 +++++++++- apps/openmw/mwscript/interpretercontext.hpp | 4 +++- apps/openmw/mwscript/scriptmanagerimp.cpp | 7 ++++--- apps/openmw/mwscript/scriptmanagerimp.hpp | 4 ++-- components/interpreter/context.hpp | 2 ++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index d8fd287d72..270b0ea549 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -129,6 +129,14 @@ namespace MWScript mGlobalScriptDesc = globalScriptDesc; } + std::string InterpreterContext::getTarget() const + { + auto ptr = getReference(false); + if(!ptr.isEmpty()) + return ptr.mRef->mRef.getRefId(); + return {}; + } + int InterpreterContext::getLocalShort (int index) const { if (!mLocals) @@ -474,7 +482,7 @@ namespace MWScript locals.mFloats[findLocalVariableIndex (scriptId, name, 'f')] = value; } - MWWorld::Ptr InterpreterContext::getReference(bool required) + MWWorld::Ptr InterpreterContext::getReference(bool required) const { return getReferenceImp ("", true, required); } diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index 298454bcd2..84982f6356 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -47,6 +47,8 @@ namespace MWScript InterpreterContext (MWScript::Locals *locals, const MWWorld::Ptr& reference); ///< The ownership of \a locals is not transferred. 0-pointer allowed. + std::string getTarget() const override; + int getLocalShort (int index) const override; int getLocalLong (int index) const override; @@ -124,7 +126,7 @@ namespace MWScript void setMemberFloat (const std::string& id, const std::string& name, float value, bool global) override; - MWWorld::Ptr getReference(bool required=true); + MWWorld::Ptr getReference(bool required=true) const; ///< Reference, that the script is running from (can be empty) void updatePtr(const MWWorld::Ptr& base, const MWWorld::Ptr& updated); diff --git a/apps/openmw/mwscript/scriptmanagerimp.cpp b/apps/openmw/mwscript/scriptmanagerimp.cpp index e1652b311c..15b416fd04 100644 --- a/apps/openmw/mwscript/scriptmanagerimp.cpp +++ b/apps/openmw/mwscript/scriptmanagerimp.cpp @@ -109,7 +109,8 @@ namespace MWScript } // execute script - if (!iter->second.mByteCode.empty() && iter->second.mActive) + std::string target = Misc::StringUtils::lowerCase(interpreterContext.getTarget()); + if (!iter->second.mByteCode.empty() && iter->second.mInactive.find(target) == iter->second.mInactive.end()) try { if (!mOpcodesInstalled) @@ -129,7 +130,7 @@ namespace MWScript { Log(Debug::Error) << "Execution of script " << name << " failed: " << e.what(); - iter->second.mActive = false; // don't execute again. + iter->second.mInactive.insert(target); // don't execute again. } return false; } @@ -138,7 +139,7 @@ namespace MWScript { for (auto& script : mScripts) { - script.second.mActive = true; + script.second.mInactive.clear(); } mGlobalScripts.clear(); diff --git a/apps/openmw/mwscript/scriptmanagerimp.hpp b/apps/openmw/mwscript/scriptmanagerimp.hpp index 7ddcd2489d..04693eea6a 100644 --- a/apps/openmw/mwscript/scriptmanagerimp.hpp +++ b/apps/openmw/mwscript/scriptmanagerimp.hpp @@ -2,6 +2,7 @@ #define GAME_SCRIPT_SCRIPTMANAGER_H #include +#include #include #include @@ -45,13 +46,12 @@ namespace MWScript { std::vector mByteCode; Compiler::Locals mLocals; - bool mActive; + std::set mInactive; CompiledScript(const std::vector& code, const Compiler::Locals& locals) { mByteCode = code; mLocals = locals; - mActive = true; } }; diff --git a/components/interpreter/context.hpp b/components/interpreter/context.hpp index 862018bdc0..18d36ffee9 100644 --- a/components/interpreter/context.hpp +++ b/components/interpreter/context.hpp @@ -12,6 +12,8 @@ namespace Interpreter virtual ~Context() {} + virtual std::string getTarget() const = 0; + virtual int getLocalShort (int index) const = 0; virtual int getLocalLong (int index) const = 0;