mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 08:15:37 +00:00
Allow scripts to fail per target
This commit is contained in:
parent
879e66a043
commit
67c8d73fe0
5 changed files with 20 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define GAME_SCRIPT_SCRIPTMANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include <components/compiler/streamerrorhandler.hpp>
|
||||
|
@ -45,13 +46,12 @@ namespace MWScript
|
|||
{
|
||||
std::vector<Interpreter::Type_Code> mByteCode;
|
||||
Compiler::Locals mLocals;
|
||||
bool mActive;
|
||||
std::set<std::string> mInactive;
|
||||
|
||||
CompiledScript(const std::vector<Interpreter::Type_Code>& code, const Compiler::Locals& locals)
|
||||
{
|
||||
mByteCode = code;
|
||||
mLocals = locals;
|
||||
mActive = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue