From 3fa6bf46db06b95549ce8eac12ba77f13360c4a2 Mon Sep 17 00:00:00 2001 From: sneed <56992013+Sneed69@users.noreply.github.com> Date: Sun, 21 Jul 2024 22:20:39 +0300 Subject: [PATCH] Test battlers always have their forced abilities (#4707) * Test battlers always have their forced abilities * indentation --- src/battle_controllers.c | 9 +++++++++ src/battle_main.c | 9 +++++++++ src/battle_script_commands.c | 19 +++++++++++++++++++ test/battle/test_runner_features.c | 27 +++++++++++++++++++++++++++ test/test_runner_battle.c | 1 + 5 files changed, 65 insertions(+) create mode 100644 test/battle/test_runner_features.c diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 1f9cf0d7f6..230c3464dd 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -1609,6 +1609,15 @@ static u32 GetBattlerMonData(u32 battler, struct Pokemon *party, u32 monId, u8 * src = (u8 *)&battleMon; for (size = 0; size < sizeof(battleMon); size++) dst[size] = src[size]; + #if TESTING + if (gTestRunnerEnabled) + { + u32 side = GetBattlerSide(battler); + u32 partyIndex = gBattlerPartyIndexes[battler]; + if (TestRunner_Battle_GetForcedAbility(side, partyIndex)) + gBattleMons[battler].ability = gBattleStruct->overwrittenAbilities[battler] = TestRunner_Battle_GetForcedAbility(side, partyIndex); + } + #endif break; case REQUEST_SPECIES_BATTLE: data16 = GetMonData(&party[monId], MON_DATA_SPECIES); diff --git a/src/battle_main.c b/src/battle_main.c index e95103d574..2b95bad975 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3477,6 +3477,15 @@ static void DoBattleIntro(void) gBattleMons[battler].status2 = 0; for (i = 0; i < NUM_BATTLE_STATS; i++) gBattleMons[battler].statStages[i] = DEFAULT_STAT_STAGE; + #if TESTING + if (gTestRunnerEnabled) + { + u32 side = GetBattlerSide(battler); + u32 partyIndex = gBattlerPartyIndexes[battler]; + if (TestRunner_Battle_GetForcedAbility(side, partyIndex)) + gBattleMons[battler].ability = gBattleStruct->overwrittenAbilities[battler] = TestRunner_Battle_GetForcedAbility(side, partyIndex); + } + #endif } // Draw sprite. diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 5a8f442d91..62b2ac0cdb 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -6518,6 +6518,15 @@ static void Cmd_switchindataupdate(void) gBattleMons[battler].type2 = gSpeciesInfo[gBattleMons[battler].species].types[1]; gBattleMons[battler].type3 = TYPE_MYSTERY; gBattleMons[battler].ability = GetAbilityBySpecies(gBattleMons[battler].species, gBattleMons[battler].abilityNum); + #if TESTING + if (gTestRunnerEnabled) + { + u32 side = GetBattlerSide(battler); + u32 partyIndex = gBattlerPartyIndexes[battler]; + if (TestRunner_Battle_GetForcedAbility(side, partyIndex)) + gBattleMons[battler].ability = gBattleStruct->overwrittenAbilities[battler] = TestRunner_Battle_GetForcedAbility(side, partyIndex); + } + #endif // check knocked off item i = GetBattlerSide(battler); @@ -13232,7 +13241,17 @@ static void Cmd_healpartystatus(void) else if (isDoublesPartner) ability = GetBattlerAbility(partner); else + { ability = GetAbilityBySpecies(species, abilityNum); + #if TESTING + if (gTestRunnerEnabled) + { + u32 side = GetBattlerSide(gBattlerAttacker); + if (TestRunner_Battle_GetForcedAbility(side, i)) + ability = TestRunner_Battle_GetForcedAbility(side, i); + } + #endif + } if (ability != ABILITY_SOUNDPROOF) toHeal |= (1 << i); diff --git a/test/battle/test_runner_features.c b/test/battle/test_runner_features.c new file mode 100644 index 0000000000..6b84c4fc2d --- /dev/null +++ b/test/battle/test_runner_features.c @@ -0,0 +1,27 @@ +#include "global.h" +#include "test/battle.h" + +ASSUMPTIONS { + int i; + for (i = 0; i < NUM_ABILITY_SLOTS; i++) { + ASSUME(gSpeciesInfo[SPECIES_KADABRA].abilities[i] != ABILITY_QUARK_DRIVE); + ASSUME(gSpeciesInfo[SPECIES_ALAKAZAM].abilities[i] != ABILITY_ELECTRIC_SURGE); + } +} + +SINGLE_BATTLE_TEST("Forced abilities activate on switch-in") +{ + GIVEN { + PLAYER(SPECIES_ALAKAZAM); + PLAYER(SPECIES_KADABRA) { Ability(ABILITY_QUARK_DRIVE); SpAttack(400);} + OPPONENT(SPECIES_ARON); + OPPONENT(SPECIES_ALAKAZAM) { Ability(ABILITY_ELECTRIC_SURGE); }; + } WHEN { + TURN { SWITCH(player, 1); SWITCH(opponent, 1);} + } SCENE { + ABILITY_POPUP(opponent, ABILITY_ELECTRIC_SURGE); + ABILITY_POPUP(player, ABILITY_QUARK_DRIVE); + MESSAGE("The Electric Terrain activated Kadabra's Quark Drive!"); + MESSAGE("Kadabra's Sp. Atk was heightened!"); + } +} diff --git a/test/test_runner_battle.c b/test/test_runner_battle.c index 6f58531c57..11432bd12b 100644 --- a/test/test_runner_battle.c +++ b/test/test_runner_battle.c @@ -1624,6 +1624,7 @@ void Ability_(u32 sourceLine, u32 ability) u32 species; const struct SpeciesInfo *info; INVALID_IF(!DATA.currentMon, "Ability outside of PLAYER/OPPONENT"); + INVALID_IF(ability >= ABILITIES_COUNT, "Illegal ability id: %d", ability); species = GetMonData(DATA.currentMon, MON_DATA_SPECIES); info = &gSpeciesInfo[species]; for (i = 0; i < NUM_ABILITY_SLOTS; i++)