From 3d75e8233d92886fd074071cdfb54b5be66e9560 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Thu, 28 Oct 2021 16:27:59 +0200 Subject: [PATCH] Adds Angelscript functions for setting volatile scripts on a battleside. --- .../Battling/RegisterBattleClass.cpp | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp index 35abe86..83196ed 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp @@ -67,7 +67,7 @@ CreatureLib::Battling::BattleParty* FindPartyWrapper(PkmnLib::Battling::Battle* return {}; } -static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) { +static CScriptHandle Battle_AddVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) { auto handle = CScriptHandle(); auto* resolver = static_cast(obj->GetLibrary()->GetScriptResolver().get()); auto script = static_cast(obj->AddVolatileScript(name))->GetRawAngelscriptObject(); @@ -75,6 +75,15 @@ static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Battle* obj, const Ar return handle; } +static CScriptHandle BattleSide_AddVolatileWrapper(CreatureLib::Battling::BattleSide* obj, + const ArbUt::StringView& name) { + auto handle = CScriptHandle(); + auto* resolver = static_cast(obj->GetBattle()->GetLibrary()->GetScriptResolver().get()); + auto script = static_cast(obj->AddVolatileScript(name))->GetRawAngelscriptObject(); + handle.Set(script, resolver->GetBaseType("PkmnScript")); + return handle; +} + static u8 GetPokemonIndexWrapper(CreatureLib::Battling::BattleSide* obj, PkmnLib::Battling::Pokemon* pokemon) { return obj->GetCreatureIndex(pokemon); } @@ -91,6 +100,10 @@ void RegisterBattleClass::RegisterBattleSide(asIScriptEngine* engine) { REGISTER_GETTER("BattleSide", "uint8 get_SideIndex() const property", CreatureLib::Battling::BattleSide, GetSideIndex); + REGISTER_GETTER("BattleSide", "bool get_IsDefeated() const property", CreatureLib::Battling::BattleSide, + IsDefeated); + REGISTER_GETTER("BattleSide", "bool get_HasFled() const property", CreatureLib::Battling::BattleSide, HasFled); + REGISTER_GETTER("BattleSide", "Battle@ get_Battle() const property", CreatureLib::Battling::BattleSide, GetBattle); r = engine->RegisterObjectMethod("BattleSide", "uint8 GetPokemonIndex(const Pokemon@ pokemon) const", asFUNCTION(GetPokemonIndexWrapper), asCALL_CDECL_OBJFIRST); @@ -98,6 +111,15 @@ void RegisterBattleClass::RegisterBattleSide(asIScriptEngine* engine) { r = engine->RegisterObjectMethod("BattleSide", "Pokemon@ GetPokemon(uint8 index) const", asFUNCTION(GetPokemonWrapper), asCALL_CDECL_OBJFIRST); Ensure(r >= 0); + + r = engine->RegisterObjectMethod("BattleSide", "ref@ AddVolatile(const constString &in name)", + asFUNCTION(BattleSide_AddVolatileWrapper), asCALL_CDECL_OBJFIRST); + Ensure(r >= 0); + r = engine->RegisterObjectMethod( + "BattleSide", "void RemoveVolatile(const constString &in name) const", + asMETHODPR(CreatureLib::Battling::BattleSide, RemoveVolatileScript, (const ArbUt::BasicStringView&), void), + asCALL_THISCALL); + Ensure(r >= 0); } void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) { @@ -112,14 +134,13 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) { GetSides); REGISTER_GETTER("Battle", "narray@ get_Parties() const property", CreatureLib::Battling::Battle, GetParties); - REGISTER_GETTER("Battle", "BattleHistory@ get_History() const property", CreatureLib::Battling::Battle, - GetHistory); + REGISTER_GETTER("Battle", "BattleHistory@ get_History() const property", CreatureLib::Battling::Battle, GetHistory); auto r = engine->RegisterObjectMethod("Battle", "bool CanUse(BaseTurnChoice@ choice)", asMETHOD(PkmnLib::Battling::Battle, CanUse), asCALL_THISCALL); Ensure(r >= 0); r = engine->RegisterObjectMethod("Battle", "ref@ AddVolatile(const constString &in name)", - asFUNCTION(AddVolatileWrapper), asCALL_CDECL_OBJFIRST); + asFUNCTION(Battle_AddVolatileWrapper), asCALL_CDECL_OBJFIRST); Ensure(r >= 0); r = engine->RegisterObjectMethod( "Battle", "void RemoveVolatile(const constString &in name) const",