Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed switchout bug in multibattle where order of mons gets messed up #2099

Merged
merged 10 commits into from
Jan 29, 2025
69 changes: 69 additions & 0 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -7209,12 +7209,20 @@ static void Cmd_forcerandomswitch(void)
if ((gBattlerTarget & BIT_FLANK) != B_FLANK_LEFT)
{
firstMonId = PARTY_SIZE / 2;
#ifdef BUGFIX
lastMonId = PARTY_SIZE; - 1
#else
lastMonId = PARTY_SIZE;
#endif
}
else
{
firstMonId = 0;
#ifdef BUGFIX
lastMonId = PARTY_SIZE / 2 - 1;
#else
lastMonId = PARTY_SIZE / 2;
#endif
}
monsCount = PARTY_SIZE / 2;
minNeeded = 1;
Expand All @@ -7227,12 +7235,20 @@ static void Cmd_forcerandomswitch(void)
if (GetLinkTrainerFlankId(GetBattlerMultiplayerId(gBattlerTarget)) == B_FLANK_RIGHT)
{
firstMonId = PARTY_SIZE / 2;
#ifdef BUGFIX
lastMonId = PARTY_SIZE - 1;
#else
lastMonId = PARTY_SIZE;
#endif
}
else
{
firstMonId = 0;
#ifdef BUGFIX
lastMonId = PARTY_SIZE / 2 - 1;
#else
lastMonId = PARTY_SIZE / 2;
#endif
}
monsCount = PARTY_SIZE / 2;
minNeeded = 1;
Expand All @@ -7244,7 +7260,11 @@ static void Cmd_forcerandomswitch(void)
if (GetBattlerSide(gBattlerTarget) == B_SIDE_PLAYER)
{
firstMonId = 0;
#ifdef BUGFIX
lastMonId = PARTY_SIZE - 1;
#else
lastMonId = PARTY_SIZE;
#endif
monsCount = PARTY_SIZE;
minNeeded = 2; // since there are two opponents, it has to be a double battle
}
Expand All @@ -7253,12 +7273,20 @@ static void Cmd_forcerandomswitch(void)
if ((gBattlerTarget & BIT_FLANK) != B_FLANK_LEFT)
{
firstMonId = PARTY_SIZE / 2;
#ifdef BUGFIX
lastMonId = PARTY_SIZE - 1;
#else
lastMonId = PARTY_SIZE;
#endif
}
else
{
firstMonId = 0;
#ifdef BUGFIX
lastMonId = PARTY_SIZE / 2 - 1;
#else
lastMonId = PARTY_SIZE / 2;
#endif
}
monsCount = PARTY_SIZE / 2;
minNeeded = 1;
Expand All @@ -7269,7 +7297,11 @@ static void Cmd_forcerandomswitch(void)
else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
{
firstMonId = 0;
#ifdef BUGFIX
lastMonId = PARTY_SIZE - 1;
#else
lastMonId = PARTY_SIZE;
#endif
monsCount = PARTY_SIZE;
minNeeded = 2;
battler2PartyId = gBattlerPartyIndexes[gBattlerTarget];
Expand All @@ -7278,7 +7310,11 @@ static void Cmd_forcerandomswitch(void)
else
{
firstMonId = 0;
#ifdef BUGFIX
lastMonId = PARTY_SIZE - 1;
#else
lastMonId = PARTY_SIZE;
#endif
monsCount = PARTY_SIZE;
minNeeded = 1;
battler2PartyId = gBattlerPartyIndexes[gBattlerTarget]; // there is only one Pokémon out in single battles
Expand All @@ -7301,6 +7337,38 @@ static void Cmd_forcerandomswitch(void)
}
else
{
#ifdef BUGFIX
if (TryDoForceSwitchOut())
{
do
{
do
{
i = Random() % monsCount;
i += firstMonId;
}
while (i == battler2PartyId || i == battler1PartyId);
} while (GetMonData(&party[i], MON_DATA_SPECIES) == SPECIES_NONE
|| GetMonData(&party[i], MON_DATA_IS_EGG) == TRUE
|| GetMonData(&party[i], MON_DATA_HP) == 0); //should be one while loop, but that doesn't match.
*(gBattleStruct->monToSwitchIntoId + gBattlerTarget) = i;

if (!IsMultiBattle())
SwitchPartyOrder(gBattlerTarget);

if ((gBattleTypeFlags & BATTLE_TYPE_LINK && gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER)
|| (gBattleTypeFlags & BATTLE_TYPE_LINK && gBattleTypeFlags & BATTLE_TYPE_MULTI)
|| (gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK && gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER)
|| (gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK && gBattleTypeFlags & BATTLE_TYPE_MULTI))
{
SwitchPartyOrderLinkMulti(gBattlerTarget, i, 0);
SwitchPartyOrderLinkMulti(BATTLE_PARTNER(gBattlerTarget), i, 1);
}

if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER)
SwitchPartyOrderInGameMulti(gBattlerTarget, i);
}
#else
if (TryDoForceSwitchOut())
{
do
Expand Down Expand Up @@ -7331,6 +7399,7 @@ static void Cmd_forcerandomswitch(void)

if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER)
SwitchPartyOrderInGameMulti(gBattlerTarget, i);
#endif
}
}
else
Expand Down