Adds angelscript functions for creating a party, and battles using them

This commit is contained in:
Deukhoofd 2021-08-29 11:10:07 +02:00
parent 651fff3292
commit b46b1184b2
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 49 additions and 1 deletions

@ -1 +1 @@
Subproject commit 73d50ab98b53f77d97b4e3a1cc56b9101db24d93 Subproject commit 4e11fdddb391ede68cee265f19fffdc65087e6b5

View File

@ -9,6 +9,27 @@
#include "../TestEnvironment.hpp" #include "../TestEnvironment.hpp"
class BattleFunctions { class BattleFunctions {
static CreatureLib::Battling::CreatureParty* CreateSimpleParty(CScriptArray* species, u8 level) {
auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(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<const ArbUt::StringView*>(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, static PkmnLib::Battling::Battle* CreateSimpleBattle(u32 seed, const ArbUt::StringView& species1,
const ArbUt::StringView& species2, u8 level) { const ArbUt::StringView& species2, u8 level) {
auto* ctx = asGetActiveContext(); auto* ctx = asGetActiveContext();
@ -54,6 +75,28 @@ class BattleFunctions {
return battle; return battle;
} }
static PkmnLib::Battling::Battle* CreateSimpleBattleFromParties(u32 seed, CreatureLib::Battling::CreatureParty* p1,
CreatureLib::Battling::CreatureParty* p2) {
auto* ctx = asGetActiveContext();
TestEnvironment* env = static_cast<TestEnvironment*>(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) { static bool UseMove(PkmnLib::Battling::Pokemon* user, const ArbUt::StringView& moveName, u8 sideTarget, u8 target) {
auto battle = user->GetBattle(); auto battle = user->GetBattle();
if (!battle.HasValue()) { if (!battle.HasValue()) {
@ -96,9 +139,14 @@ class BattleFunctions {
public: public:
static void Register(AngelScriptResolver* scriptResolver) { static void Register(AngelScriptResolver* scriptResolver) {
auto engine = scriptResolver->GetBuilder().GetEngine(); auto engine = scriptResolver->GetBuilder().GetEngine();
Ensure(
engine->RegisterGlobalFunction("Party@ CreateSimpleParty(const array<constString>&in species, uint8 level)",
asFUNCTION(CreateSimpleParty), asCALL_CDECL) >= 0);
Ensure(engine->RegisterGlobalFunction("Battle@ CreateSimpleBattle(uint seed, const constString&in species1, " Ensure(engine->RegisterGlobalFunction("Battle@ CreateSimpleBattle(uint seed, const constString&in species1, "
"const constString&in species2, uint8 level)", "const constString&in species2, uint8 level)",
asFUNCTION(CreateSimpleBattle), asCALL_CDECL) >= 0); 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", Ensure(engine->RegisterObjectMethod("Pokemon",
"bool UseMove(const constString&in move, uint8 side, uint8 index)", "bool UseMove(const constString&in move, uint8 side, uint8 index)",
asFUNCTION(UseMove), asCALL_CDECL_OBJFIRST) >= 0); asFUNCTION(UseMove), asCALL_CDECL_OBJFIRST) >= 0);