From b2accd720eb17c3232a8131646478dbfe6d5a1d7 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 19 Nov 2021 14:56:29 +0100 Subject: [PATCH] Support for (un)suppressing weather, adds hook to block weather changes. --- src/Battling/Battle/Battle.cpp | 9 ++++++++- src/Battling/Battle/Battle.hpp | 13 ++++++++++++- src/Battling/PkmnScript.hpp | 2 ++ src/Battling/PkmnScriptHook.hpp | 3 +++ .../TypeRegistry/Battling/RegisterBattleClass.cpp | 10 ++++++++-- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Battling/Battle/Battle.cpp b/src/Battling/Battle/Battle.cpp index a2b877e..e63ec03 100644 --- a/src/Battling/Battle/Battle.cpp +++ b/src/Battling/Battle/Battle.cpp @@ -1,11 +1,18 @@ #include "Battle.hpp" -void PkmnLib::Battling::Battle::SetWeather(const ArbUt::StringView& name) { +#include "../PkmnScriptHook.hpp" +bool PkmnLib::Battling::Battle::SetWeather(const ArbUt::StringView& name) { + bool blockWeather = false; + PKMN_HOOK(BlockWeather, this, this, &blockWeather); + if (blockWeather) { + return false; + } if (_weatherScript != nullptr) { _weatherScript->OnRemove(); } _weatherScript = std::unique_ptr( _library->LoadScript(this, static_cast(PkmnScriptCategory::Weather), name)); _eventHook.Trigger(name); + return true; } void PkmnLib::Battling::Battle::ClearWeather() { if (_weatherScript == nullptr) diff --git a/src/Battling/Battle/Battle.hpp b/src/Battling/Battle/Battle.hpp index a9a2813..746ba97 100644 --- a/src/Battling/Battle/Battle.hpp +++ b/src/Battling/Battle/Battle.hpp @@ -22,8 +22,19 @@ namespace PkmnLib::Battling { virtual ~Battle() = default; - void SetWeather(const ArbUt::StringView& name); + bool SetWeather(const ArbUt::StringView& name); void ClearWeather(); + void SuppressWeather() { + if (_weatherScript != nullptr) { + _weatherScript->Suppress(); + } + } + void UnsuppressWeather() { + if (_weatherScript != nullptr) { + _weatherScript->Unsuppress(); + } + } + const ArbUt::StringView& GetWeatherName() noexcept { if (_weatherScript == nullptr) return ArbUt::StringView::EmptyString(); diff --git a/src/Battling/PkmnScript.hpp b/src/Battling/PkmnScript.hpp index f48bc25..cd13278 100644 --- a/src/Battling/PkmnScript.hpp +++ b/src/Battling/PkmnScript.hpp @@ -1,6 +1,7 @@ #ifndef PKMNLIB_PKMNSCRIPT_HPP #define PKMNLIB_PKMNSCRIPT_HPP #include +#include "Battle/Battle.hpp" #ifdef __clang__ #pragma clang diagnostic push @@ -27,6 +28,7 @@ namespace PkmnLib::Battling { CreatureLib::Battling::Creature* winningMon, uint32_t* experienceGain){}; virtual void DoesShareExperience(CreatureLib::Battling::Creature* faintedMon, CreatureLib::Battling::Creature* winningMon, bool* shareExperience){}; + virtual void BlockWeather(CreatureLib::Battling::Battle* battle, bool* blockWeather){}; }; } diff --git a/src/Battling/PkmnScriptHook.hpp b/src/Battling/PkmnScriptHook.hpp index 76d4558..abbb600 100644 --- a/src/Battling/PkmnScriptHook.hpp +++ b/src/Battling/PkmnScriptHook.hpp @@ -5,6 +5,9 @@ auto aggregator = source->GetScriptIterator(); \ ArbUt::BorrowedPtr next = (CreatureLib::Battling::BattleScript*)1; \ while (aggregator.GetNext(next)) { \ + if (next->IsSuppressed()) { \ + continue; \ + } \ auto castNext = next.ForceAs(); \ castNext->hookName(__VA_ARGS__); \ } \ diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp index ada8852..a8386a7 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp @@ -191,8 +191,8 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) { asCALL_THISCALL); Ensure(r >= 0); r = engine->RegisterObjectMethod( - "Battle", "void SetWeather(const constString &in name) const", - asMETHODPR(PkmnLib::Battling::Battle, SetWeather, (const ArbUt::StringView&), void), asCALL_THISCALL); + "Battle", "bool SetWeather(const constString &in name) const", + asMETHODPR(PkmnLib::Battling::Battle, SetWeather, (const ArbUt::StringView&), bool), asCALL_THISCALL); Ensure(r >= 0); r = engine->RegisterObjectMethod("Battle", "void ClearWeather(const constString &in name) const", asMETHODPR(PkmnLib::Battling::Battle, ClearWeather, (), void), asCALL_THISCALL); @@ -201,6 +201,12 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) { "Battle", "const constString& GetWeatherName() const", asMETHODPR(PkmnLib::Battling::Battle, GetWeatherName, (), const ArbUt::StringView&), asCALL_THISCALL); Ensure(r >= 0); + r = engine->RegisterObjectMethod("Battle", "void SuppressWeather() const", + asMETHOD(PkmnLib::Battling::Battle, SuppressWeather), asCALL_THISCALL); + Ensure(r >= 0); + r = engine->RegisterObjectMethod("Battle", "void UnsuppressWeather() const", + asMETHOD(PkmnLib::Battling::Battle, UnsuppressWeather), asCALL_THISCALL); + Ensure(r >= 0); r = engine->RegisterObjectMethod("Battle", "BattleSide@ GetBattleSide(uint8 index)", asFUNCTION(GetBattleSideWrapper), asCALL_CDECL_OBJFIRST); Ensure(r >= 0);