From 5cfa174396a8af8d7a8cbf9c8784fa43eaad769c Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 27 Mar 2021 15:34:04 +0100 Subject: [PATCH] Adds new run prevention script hooks. --- .../AngelScript/AngelScriptScript.cpp | 12 +++++++++ .../AngelScript/AngelScriptScript.hpp | 3 +++ .../AngelScript/AngelScriptTypeInfo.hpp | 3 +++ .../TypeRegistry/BasicScriptClass.cpp | 7 +++-- .../Battling/RegisterTurnChoices.cpp | 26 +++++++++++++++++-- .../Battling/RegisterTurnChoices.hpp | 1 + 6 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.cpp b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp index 15a4fd8..11d3135 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.cpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp @@ -273,3 +273,15 @@ void AngelScriptScript::OnFail(CreatureLib::Battling::Creature* target) { void AngelScriptScript::OnOpponentFail(CreatureLib::Battling::Creature* target) { CALL_HOOK(OnOpponentFail, { ctx->SetArgObject(0, (void*)target); }) } +void AngelScriptScript::PreventRunAway(const CreatureLib::Battling::FleeTurnChoice* choice, bool* result) { + CALL_HOOK(PreventRunAway, { + ctx->SetArgObject(0, (void*)choice); + ctx->SetArgAddress(1, result); + }) +} +void AngelScriptScript::PreventOpponentRunAway(const CreatureLib::Battling::FleeTurnChoice* choice, bool* result) { + CALL_HOOK(PreventOpponentRunAway, { + ctx->SetArgObject(0, (void*)choice); + ctx->SetArgAddress(1, result); + }) +} diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp index 08dd636..a56ef2a 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp @@ -101,6 +101,9 @@ public: void OnFail(CreatureLib::Battling::Creature* target) override; void OnOpponentFail(CreatureLib::Battling::Creature* target) override; + void PreventRunAway(const CreatureLib::Battling::FleeTurnChoice* choice, bool* result) override; + void PreventOpponentRunAway(const CreatureLib::Battling::FleeTurnChoice* choice, bool* result) override; + //////////////////// // PkmnLib methods// //////////////////// diff --git a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp index e8840a3..0f0871d 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp @@ -136,6 +136,9 @@ public: SCRIPT_HOOK_FUNCTION(ChangePriority, "void ChangePriority(MoveTurnChoice@ choice, int8& priority)"); SCRIPT_HOOK_FUNCTION(OnFail, "void OnFail(Pokemon@ user)"); SCRIPT_HOOK_FUNCTION(OnOpponentFail, "void OnOpponentFail(Pokemon@ user)"); + + SCRIPT_HOOK_FUNCTION(PreventRunAway, "void PreventRunAway(FleeTurnChoice@ choice, bool& result)"); + SCRIPT_HOOK_FUNCTION(PreventOpponentRunAway, "void PreventOpponentRunAway(FleeTurnChoice@ choice, ool& result)"); }; #undef SCRIPT_HOOK_FUNCTION diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp index bcabad6..4d3e566 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp @@ -37,8 +37,11 @@ shared abstract class PkmnScript { void OverrideDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint& damage){}; void ChangePriority(MoveTurnChoice@ choice, int8& priority){}; - void OnFail(Pokemon@ user){} - void OnOpponentFail(Pokemon@ user){} + void OnFail(Pokemon@ user){}; + void OnOpponentFail(Pokemon@ user){}; + + void PreventRunAway(FleeTurnChoice@ choice, bool& result){}; + void PreventOpponentRunAway(FleeTurnChoice@ choice, bool& result){}; // PkmnLib methods void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage){}; diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.cpp index 87272a5..6ef763d 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.cpp @@ -9,6 +9,7 @@ void RegisterTurnChoices::Register(asIScriptEngine* engine) { RegisterBaseTurnChoice(engine); RegisterMoveTurnChoice(engine); RegisterSwitchTurnChoice(engine); + RegisterFleeTurnChoice(engine); } void RegisterTurnChoices::RegisterTurnChoiceKindEnum(asIScriptEngine* engine) { [[maybe_unused]] int r = engine->RegisterEnum("TurnChoiceKind"); @@ -78,13 +79,34 @@ void RegisterTurnChoices::RegisterSwitchTurnChoice(asIScriptEngine* engine) { Ensure(r >= 0); r = engine->RegisterObjectMethod( - "SwitchTurnChoice", "MoveTurnChoice@ opCast()", + "BaseTurnChoice", "SwitchTurnChoice@ opCast()", asFUNCTION((refCast)), asCALL_CDECL_OBJLAST); Ensure(r >= 0); r = engine->RegisterObjectMethod( "SwitchTurnChoice", "BaseTurnChoice@ opImplCast()", - asFUNCTION((refCast)), + asFUNCTION((refCast)), + asCALL_CDECL_OBJLAST); + Ensure(r >= 0); +} +void RegisterTurnChoices::RegisterFleeTurnChoice(asIScriptEngine* engine) { + [[maybe_unused]] int r = engine->RegisterObjectType("FleeTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT); + Ensure(r >= 0); + r = engine->RegisterObjectMethod("FleeTurnChoice", "TurnChoiceKind get_Kind() const property", + asMETHOD(CreatureLib::Battling::FleeTurnChoice, GetKind), asCALL_THISCALL); + Ensure(r >= 0); + r = engine->RegisterObjectMethod("FleeTurnChoice", "Pokemon@ get_User() const property", + asMETHOD(CreatureLib::Battling::FleeTurnChoice, GetUser), asCALL_THISCALL); + Ensure(r >= 0); + + r = engine->RegisterObjectMethod( + "BaseTurnChoice", "FleeTurnChoice@ opCast()", + asFUNCTION((refCast)), + asCALL_CDECL_OBJLAST); + Ensure(r >= 0); + r = engine->RegisterObjectMethod( + "FleeTurnChoice", "BaseTurnChoice@ opImplCast()", + asFUNCTION((refCast)), asCALL_CDECL_OBJLAST); Ensure(r >= 0); } diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.hpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.hpp index 1dc5448..2ae11aa 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.hpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.hpp @@ -8,6 +8,7 @@ class RegisterTurnChoices { static void RegisterBaseTurnChoice(asIScriptEngine* engine); static void RegisterMoveTurnChoice(asIScriptEngine* engine); static void RegisterSwitchTurnChoice(asIScriptEngine* engine); + static void RegisterFleeTurnChoice(asIScriptEngine* engine); public: static void Register(asIScriptEngine* engine);