Fix ai vs ai battles switch issue (#3283)

This commit is contained in:
DizzyEggg 2023-09-11 00:01:12 +02:00 committed by GitHub
parent 755e260da4
commit 4dff0362df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -397,19 +397,21 @@ static void PlayerPartnerHandleChoosePokemon(u32 battler)
chosenMonId = gSelectedMonPartyId = GetFirstFaintedPartyIndex(battler); chosenMonId = gSelectedMonPartyId = GetFirstFaintedPartyIndex(battler);
} }
// Switching out // Switching out
else if (gBattleStruct->monToSwitchIntoId[battler] == PARTY_SIZE) else if (gBattleStruct->monToSwitchIntoId[battler] >= PARTY_SIZE || !IsValidForBattle(&gPlayerParty[gBattleStruct->monToSwitchIntoId[battler]]))
{ {
chosenMonId = GetMostSuitableMonToSwitchInto(battler); chosenMonId = GetMostSuitableMonToSwitchInto(battler);
if (chosenMonId == PARTY_SIZE) // just switch to the next mon
{
u8 playerMonIdentity = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT);
u8 selfIdentity = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT);
for (chosenMonId = PARTY_SIZE / 2; chosenMonId < PARTY_SIZE; chosenMonId++) if (chosenMonId == PARTY_SIZE || !IsValidForBattle(&gPlayerParty[chosenMonId])) // just switch to the next mon
{
s32 firstId = (IsAiVsAiBattle()) ? 0 : (PARTY_SIZE / 2);
u32 battler1 = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT);
u32 battler2 = IsDoubleBattle() ? GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT) : battler1;
for (chosenMonId = firstId; chosenMonId < PARTY_SIZE; chosenMonId++)
{ {
if (GetMonData(&gPlayerParty[chosenMonId], MON_DATA_HP) != 0 if (GetMonData(&gPlayerParty[chosenMonId], MON_DATA_HP) != 0
&& chosenMonId != gBattlerPartyIndexes[playerMonIdentity] && chosenMonId != gBattlerPartyIndexes[battler1]
&& chosenMonId != gBattlerPartyIndexes[selfIdentity]) && chosenMonId != gBattlerPartyIndexes[battler2])
{ {
break; break;
} }