mirror of
https://github.com/OpenMW/openmw.git
synced 2025-07-06 08:11:35 +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;
|
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
|
int InterpreterContext::getLocalShort (int index) const
|
||||||
{
|
{
|
||||||
if (!mLocals)
|
if (!mLocals)
|
||||||
|
@ -474,7 +482,7 @@ namespace MWScript
|
||||||
locals.mFloats[findLocalVariableIndex (scriptId, name, 'f')] = value;
|
locals.mFloats[findLocalVariableIndex (scriptId, name, 'f')] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
MWWorld::Ptr InterpreterContext::getReference(bool required)
|
MWWorld::Ptr InterpreterContext::getReference(bool required) const
|
||||||
{
|
{
|
||||||
return getReferenceImp ("", true, required);
|
return getReferenceImp ("", true, required);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,8 @@ namespace MWScript
|
||||||
InterpreterContext (MWScript::Locals *locals, const MWWorld::Ptr& reference);
|
InterpreterContext (MWScript::Locals *locals, const MWWorld::Ptr& reference);
|
||||||
///< The ownership of \a locals is not transferred. 0-pointer allowed.
|
///< The ownership of \a locals is not transferred. 0-pointer allowed.
|
||||||
|
|
||||||
|
std::string getTarget() const override;
|
||||||
|
|
||||||
int getLocalShort (int index) const override;
|
int getLocalShort (int index) const override;
|
||||||
|
|
||||||
int getLocalLong (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;
|
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)
|
///< Reference, that the script is running from (can be empty)
|
||||||
|
|
||||||
void updatePtr(const MWWorld::Ptr& base, const MWWorld::Ptr& updated);
|
void updatePtr(const MWWorld::Ptr& base, const MWWorld::Ptr& updated);
|
||||||
|
|
|
@ -109,7 +109,8 @@ namespace MWScript
|
||||||
}
|
}
|
||||||
|
|
||||||
// execute script
|
// 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
|
try
|
||||||
{
|
{
|
||||||
if (!mOpcodesInstalled)
|
if (!mOpcodesInstalled)
|
||||||
|
@ -129,7 +130,7 @@ namespace MWScript
|
||||||
{
|
{
|
||||||
Log(Debug::Error) << "Execution of script " << name << " failed: " << e.what();
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +139,7 @@ namespace MWScript
|
||||||
{
|
{
|
||||||
for (auto& script : mScripts)
|
for (auto& script : mScripts)
|
||||||
{
|
{
|
||||||
script.second.mActive = true;
|
script.second.mInactive.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
mGlobalScripts.clear();
|
mGlobalScripts.clear();
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define GAME_SCRIPT_SCRIPTMANAGER_H
|
#define GAME_SCRIPT_SCRIPTMANAGER_H
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <components/compiler/streamerrorhandler.hpp>
|
#include <components/compiler/streamerrorhandler.hpp>
|
||||||
|
@ -45,13 +46,12 @@ namespace MWScript
|
||||||
{
|
{
|
||||||
std::vector<Interpreter::Type_Code> mByteCode;
|
std::vector<Interpreter::Type_Code> mByteCode;
|
||||||
Compiler::Locals mLocals;
|
Compiler::Locals mLocals;
|
||||||
bool mActive;
|
std::set<std::string> mInactive;
|
||||||
|
|
||||||
CompiledScript(const std::vector<Interpreter::Type_Code>& code, const Compiler::Locals& locals)
|
CompiledScript(const std::vector<Interpreter::Type_Code>& code, const Compiler::Locals& locals)
|
||||||
{
|
{
|
||||||
mByteCode = code;
|
mByteCode = code;
|
||||||
mLocals = locals;
|
mLocals = locals;
|
||||||
mActive = true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ namespace Interpreter
|
||||||
|
|
||||||
virtual ~Context() {}
|
virtual ~Context() {}
|
||||||
|
|
||||||
|
virtual std::string getTarget() const = 0;
|
||||||
|
|
||||||
virtual int getLocalShort (int index) const = 0;
|
virtual int getLocalShort (int index) const = 0;
|
||||||
|
|
||||||
virtual int getLocalLong (int index) const = 0;
|
virtual int getLocalLong (int index) const = 0;
|
||||||
|
|
Loading…
Reference in a new issue