diff --git a/src/BuildData b/src/BuildData index 73d50ab..4e11fdd 160000 --- a/src/BuildData +++ b/src/BuildData @@ -1 +1 @@ -Subproject commit 73d50ab98b53f77d97b4e3a1cc56b9101db24d93 +Subproject commit 4e11fdddb391ede68cee265f19fffdc65087e6b5 diff --git a/src/Tester/AngelScript/BattleFunctions.hpp b/src/Tester/AngelScript/BattleFunctions.hpp index cbb80dd..c924799 100644 --- a/src/Tester/AngelScript/BattleFunctions.hpp +++ b/src/Tester/AngelScript/BattleFunctions.hpp @@ -9,6 +9,27 @@ #include "../TestEnvironment.hpp" class BattleFunctions { + static CreatureLib::Battling::CreatureParty* CreateSimpleParty(CScriptArray* species, u8 level) { + auto* ctx = asGetActiveContext(); + TestEnvironment* env = static_cast(ctx->GetUserData()); + + auto lib = Globals::Library.GetValue(); + auto p1 = new CreatureLib::Battling::CreatureParty(species->GetSize()); + for (u32 i = 0; i < species->GetSize(); ++i) { + auto s = reinterpret_cast(species->At(i)); + auto mon1 = PkmnLib::Battling::CreatePokemon(lib, *s, level) + .WithEffortValues(0, 0, 0, 0, 0, 0) + .WithIndividualValues(31, 31, 31, 31, 31, 31) + .WithNature("hardy"_cnc) + .WithGender(CreatureLib::Library::Gender::Male) + .IsAllowedExperienceGain(false) + .Build(); + p1->SwapInto(i, mon1); + } + env->AddGarbage(p1); + return p1; + } + static PkmnLib::Battling::Battle* CreateSimpleBattle(u32 seed, const ArbUt::StringView& species1, const ArbUt::StringView& species2, u8 level) { auto* ctx = asGetActiveContext(); @@ -54,6 +75,28 @@ class BattleFunctions { return battle; } + static PkmnLib::Battling::Battle* CreateSimpleBattleFromParties(u32 seed, CreatureLib::Battling::CreatureParty* p1, + CreatureLib::Battling::CreatureParty* p2) { + auto* ctx = asGetActiveContext(); + TestEnvironment* env = static_cast(ctx->GetUserData()); + auto lib = Globals::Library.GetValue(); + + auto battle = new PkmnLib::Battling::Battle( + lib, + {new CreatureLib::Battling::BattleParty(p1, {CreatureLib::Battling::CreatureIndex(0, 0)}), + new CreatureLib::Battling::BattleParty(p2, {CreatureLib::Battling::CreatureIndex(1, 0)})}, + true, // can flee + 2, // 2 sides + 1, // 1 mon per side + seed // with seed + ); + battle->SwitchCreature(0, 0, p1->GetAtIndex(0)); + battle->SwitchCreature(1, 0, p2->GetAtIndex(1)); + + env->AddGarbage(battle); + return battle; + } + static bool UseMove(PkmnLib::Battling::Pokemon* user, const ArbUt::StringView& moveName, u8 sideTarget, u8 target) { auto battle = user->GetBattle(); if (!battle.HasValue()) { @@ -96,9 +139,14 @@ class BattleFunctions { public: static void Register(AngelScriptResolver* scriptResolver) { auto engine = scriptResolver->GetBuilder().GetEngine(); + Ensure( + engine->RegisterGlobalFunction("Party@ CreateSimpleParty(const array&in species, uint8 level)", + asFUNCTION(CreateSimpleParty), asCALL_CDECL) >= 0); Ensure(engine->RegisterGlobalFunction("Battle@ CreateSimpleBattle(uint seed, const constString&in species1, " "const constString&in species2, uint8 level)", asFUNCTION(CreateSimpleBattle), asCALL_CDECL) >= 0); + Ensure(engine->RegisterGlobalFunction("Battle@ CreateSimpleBattle(uint seed, Party@ p1, Party@ p2)", + asFUNCTION(CreateSimpleBattleFromParties), asCALL_CDECL) >= 0); Ensure(engine->RegisterObjectMethod("Pokemon", "bool UseMove(const constString&in move, uint8 side, uint8 index)", asFUNCTION(UseMove), asCALL_CDECL_OBJFIRST) >= 0);