From be03feca94bc66e313dcd864532da6b1242b7c84 Mon Sep 17 00:00:00 2001 From: cawtds <38510667+cawtds@users.noreply.github.com> Date: Mon, 12 May 2025 18:07:22 +0200 Subject: [PATCH] Fixed double battles send out breaking (#6822) --- src/battle_script_commands.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index cd3ef5a232..f6fbff240f 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -5345,6 +5345,27 @@ static void Cmd_getexp(void) } } +static u32 CountAliveMonsForBattlerSide(u32 battler) +{ + u32 aliveMons = 0; + struct Pokemon *party = GetBattlerParty(battler); + + for (u32 partyMon = 0; partyMon < PARTY_SIZE; partyMon++) + { + if (GetMonData(&party[partyMon], MON_DATA_SPECIES) + && GetMonData(&party[partyMon], MON_DATA_HP) > 0 + && !GetMonData(&party[partyMon], MON_DATA_IS_EGG)) + aliveMons++; + } + + return aliveMons; +} + +bool32 NoAliveMonsForBattlerSide(u32 battler) +{ + return CountAliveMonsForBattlerSide(battler) == 0; +} + bool32 NoAliveMonsForPlayer(void) { u32 i; @@ -5460,7 +5481,12 @@ static void Cmd_checkteamslost(void) } else { - if (emptyOpponentSpots != 0 && emptyPlayerSpots != 0) + u32 occupiedPlayerSpots = (gBattlersCount / 2) - emptyPlayerSpots; + u32 occupiedOpponentSpots = (gBattlersCount / 2) - emptyOpponentSpots; + u32 alivePlayerPartyMons = CountAliveMonsForBattlerSide(B_POSITION_PLAYER_LEFT) - occupiedPlayerSpots; + u32 aliveOpponentPartyMons = CountAliveMonsForBattlerSide(B_POSITION_OPPONENT_LEFT) - occupiedOpponentSpots; + + if (emptyPlayerSpots > 0 && alivePlayerPartyMons > 0 && emptyOpponentSpots > 0 && aliveOpponentPartyMons > 0) gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr;