From 9ede453587129b2db4a8f31b8d588a2802452fa5 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 19 Nov 2021 14:07:27 +0100 Subject: [PATCH] Support for suppressing a script, so that it temporarily does not function. --- src/Battling/ScriptHandling/BattleScript.hpp | 4 ++++ src/Battling/ScriptHandling/ScriptMacros.hpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/Battling/ScriptHandling/BattleScript.hpp b/src/Battling/ScriptHandling/BattleScript.hpp index 7e3ff80..047030a 100644 --- a/src/Battling/ScriptHandling/BattleScript.hpp +++ b/src/Battling/ScriptHandling/BattleScript.hpp @@ -17,12 +17,16 @@ namespace CreatureLib::Battling { class BattleScript { ArbUt::OptionalBorrowedPtr _owner; + size_t _suppressed = 0; public: BattleScript(const ArbUt::OptionalBorrowedPtr& owner) { _owner = owner; }; NO_COPY_OR_MOVE(BattleScript); inline ArbUt::OptionalBorrowedPtr GetOwner() const noexcept { return _owner; } + inline bool IsSuppressed() const noexcept { return _suppressed > 0; } + inline void Suppress() { _suppressed++; } + inline void Unsuppress() { _suppressed--; } virtual ~BattleScript() = default; diff --git a/src/Battling/ScriptHandling/ScriptMacros.hpp b/src/Battling/ScriptHandling/ScriptMacros.hpp index f537c6e..21b86fb 100644 --- a/src/Battling/ScriptHandling/ScriptMacros.hpp +++ b/src/Battling/ScriptHandling/ScriptMacros.hpp @@ -4,6 +4,9 @@ auto aggregator = (source)->GetScriptIterator(); \ ArbUt::BorrowedPtr next = (CreatureLib::Battling::BattleScript*)1; \ while (aggregator.GetNext(next)) { \ + if (next->IsSuppressed()) { \ + continue; \ + } \ try { \ next->hookName(__VA_ARGS__); \ } catch (const std::exception& e) { \ @@ -23,9 +26,15 @@ if (scriptWrapper.HasValue()) { \ if (scriptWrapper.IsSet()) { \ for (const auto& sv : scriptWrapper.GetScriptSet()->GetIterator()) { \ + if (sv->IsSuppressed()) { \ + continue; \ + } \ sv->hookName(__VA_ARGS__); \ } \ } else { \ + if (scriptWrapper.GetScript()->get()->IsSuppressed()) { \ + continue; \ + } \ scriptWrapper.GetScript()->get()->hookName(__VA_ARGS__); \ } \ } \