Adds helper functions to create Pokemon with more control.
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing

This commit is contained in:
2021-10-24 15:57:05 +02:00
parent 35527f68bd
commit 3b2e4f20ac
4 changed files with 95 additions and 2 deletions

View File

@@ -31,6 +31,21 @@ class BattleFunctions {
return p1;
}
static CreatureLib::Battling::CreatureParty* CreateParty(CScriptArray* mons) {
auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData(684));
auto p1 = new PkmnLib::Battling::PokemonParty(mons->GetSize());
for (u32 i = 0; i < mons->GetSize(); ++i) {
auto s = *reinterpret_cast<PkmnLib::Battling::Pokemon**>(mons->At(i));
p1->SwapInto(i, s);
// Party becomes owner of mon, so take it from GC.
env->TakeOwnershipOfGarbage(s);
}
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();
@@ -152,6 +167,8 @@ public:
Ensure(
engine->RegisterGlobalFunction("Party@ CreateSimpleParty(const array<constString>&in species, uint8 level)",
asFUNCTION(CreateSimpleParty), asCALL_CDECL) >= 0);
Ensure(engine->RegisterGlobalFunction("Party@ CreateParty(const array<Pokemon@>&in mons)",
asFUNCTION(CreateParty), 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);