Skip to content

Commit 95aa41f

Browse files
authored
Fixed switchout bug in multibattle where order of mons gets messed up (#2099)
1 parent a3d0978 commit 95aa41f

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

src/battle_script_commands.c

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7189,7 +7189,7 @@ static void Cmd_forcerandomswitch(void)
71897189
s32 battler2PartyId = 0;
71907190

71917191
s32 firstMonId;
7192-
s32 lastMonId = 0; // + 1
7192+
s32 lastMonId = 0;
71937193
s32 monsCount;
71947194
struct Pokemon *party = NULL;
71957195
s32 validMons = 0;
@@ -7209,12 +7209,20 @@ static void Cmd_forcerandomswitch(void)
72097209
if ((gBattlerTarget & BIT_FLANK) != B_FLANK_LEFT)
72107210
{
72117211
firstMonId = PARTY_SIZE / 2;
7212+
#ifdef BUGFIX
7213+
lastMonId = PARTY_SIZE - 1;
7214+
#else
72127215
lastMonId = PARTY_SIZE;
7216+
#endif
72137217
}
72147218
else
72157219
{
72167220
firstMonId = 0;
7221+
#ifdef BUGFIX
7222+
lastMonId = PARTY_SIZE / 2 - 1;
7223+
#else
72177224
lastMonId = PARTY_SIZE / 2;
7225+
#endif
72187226
}
72197227
monsCount = PARTY_SIZE / 2;
72207228
minNeeded = 1;
@@ -7227,12 +7235,20 @@ static void Cmd_forcerandomswitch(void)
72277235
if (GetLinkTrainerFlankId(GetBattlerMultiplayerId(gBattlerTarget)) == B_FLANK_RIGHT)
72287236
{
72297237
firstMonId = PARTY_SIZE / 2;
7238+
#ifdef BUGFIX
7239+
lastMonId = PARTY_SIZE - 1;
7240+
#else
72307241
lastMonId = PARTY_SIZE;
7242+
#endif
72317243
}
72327244
else
72337245
{
72347246
firstMonId = 0;
7247+
#ifdef BUGFIX
7248+
lastMonId = PARTY_SIZE / 2 - 1;
7249+
#else
72357250
lastMonId = PARTY_SIZE / 2;
7251+
#endif
72367252
}
72377253
monsCount = PARTY_SIZE / 2;
72387254
minNeeded = 1;
@@ -7244,7 +7260,11 @@ static void Cmd_forcerandomswitch(void)
72447260
if (GetBattlerSide(gBattlerTarget) == B_SIDE_PLAYER)
72457261
{
72467262
firstMonId = 0;
7263+
#ifdef BUGFIX
7264+
lastMonId = PARTY_SIZE - 1;
7265+
#else
72477266
lastMonId = PARTY_SIZE;
7267+
#endif
72487268
monsCount = PARTY_SIZE;
72497269
minNeeded = 2; // since there are two opponents, it has to be a double battle
72507270
}
@@ -7253,12 +7273,20 @@ static void Cmd_forcerandomswitch(void)
72537273
if ((gBattlerTarget & BIT_FLANK) != B_FLANK_LEFT)
72547274
{
72557275
firstMonId = PARTY_SIZE / 2;
7276+
#ifdef BUGFIX
7277+
lastMonId = PARTY_SIZE - 1;
7278+
#else
72567279
lastMonId = PARTY_SIZE;
7280+
#endif
72577281
}
72587282
else
72597283
{
72607284
firstMonId = 0;
7285+
#ifdef BUGFIX
7286+
lastMonId = PARTY_SIZE / 2 - 1;
7287+
#else
72617288
lastMonId = PARTY_SIZE / 2;
7289+
#endif
72627290
}
72637291
monsCount = PARTY_SIZE / 2;
72647292
minNeeded = 1;
@@ -7269,7 +7297,11 @@ static void Cmd_forcerandomswitch(void)
72697297
else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
72707298
{
72717299
firstMonId = 0;
7300+
#ifdef BUGFIX
7301+
lastMonId = PARTY_SIZE - 1;
7302+
#else
72727303
lastMonId = PARTY_SIZE;
7304+
#endif
72737305
monsCount = PARTY_SIZE;
72747306
minNeeded = 2;
72757307
battler2PartyId = gBattlerPartyIndexes[gBattlerTarget];
@@ -7278,7 +7310,11 @@ static void Cmd_forcerandomswitch(void)
72787310
else
72797311
{
72807312
firstMonId = 0;
7313+
#ifdef BUGFIX
7314+
lastMonId = PARTY_SIZE - 1;
7315+
#else
72817316
lastMonId = PARTY_SIZE;
7317+
#endif
72827318
monsCount = PARTY_SIZE;
72837319
minNeeded = 1;
72847320
battler2PartyId = gBattlerPartyIndexes[gBattlerTarget]; // there is only one Pokémon out in single battles
@@ -7301,6 +7337,38 @@ static void Cmd_forcerandomswitch(void)
73017337
}
73027338
else
73037339
{
7340+
#ifdef BUGFIX
7341+
if (TryDoForceSwitchOut())
7342+
{
7343+
do
7344+
{
7345+
do
7346+
{
7347+
i = Random() % monsCount;
7348+
i += firstMonId;
7349+
}
7350+
while (i == battler2PartyId || i == battler1PartyId);
7351+
} while (GetMonData(&party[i], MON_DATA_SPECIES) == SPECIES_NONE
7352+
|| GetMonData(&party[i], MON_DATA_IS_EGG) == TRUE
7353+
|| GetMonData(&party[i], MON_DATA_HP) == 0); //should be one while loop, but that doesn't match.
7354+
*(gBattleStruct->monToSwitchIntoId + gBattlerTarget) = i;
7355+
7356+
if (!IsMultiBattle())
7357+
SwitchPartyOrder(gBattlerTarget);
7358+
7359+
if ((gBattleTypeFlags & BATTLE_TYPE_LINK && gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER)
7360+
|| (gBattleTypeFlags & BATTLE_TYPE_LINK && gBattleTypeFlags & BATTLE_TYPE_MULTI)
7361+
|| (gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK && gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER)
7362+
|| (gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK && gBattleTypeFlags & BATTLE_TYPE_MULTI))
7363+
{
7364+
SwitchPartyOrderLinkMulti(gBattlerTarget, i, 0);
7365+
SwitchPartyOrderLinkMulti(BATTLE_PARTNER(gBattlerTarget), i, 1);
7366+
}
7367+
7368+
if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER)
7369+
SwitchPartyOrderInGameMulti(gBattlerTarget, i);
7370+
}
7371+
#else
73047372
if (TryDoForceSwitchOut())
73057373
{
73067374
do
@@ -7331,6 +7399,7 @@ static void Cmd_forcerandomswitch(void)
73317399

73327400
if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER)
73337401
SwitchPartyOrderInGameMulti(gBattlerTarget, i);
7402+
#endif
73347403
}
73357404
}
73367405
else

src/battle_util2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ void SwitchPartyOrderInGameMulti(u8 battlerId, u8 arg1)
109109
{
110110
s32 i;
111111
for (i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); i++)
112-
gBattlePartyCurrentOrder[i] = *(0 * 3 + i + (u8 *)(gBattleStruct->battlerPartyOrders));
112+
gBattlePartyCurrentOrder[i] = *(i + (u8 *)(gBattleStruct->battlerPartyOrders));
113113

114114
SwitchPartyMonSlots(GetPartyIdFromBattlePartyId(gBattlerPartyIndexes[battlerId]), GetPartyIdFromBattlePartyId(arg1));
115115

116116
for (i = 0; i < (int)ARRAY_COUNT(gBattlePartyCurrentOrder); i++)
117-
*(0 * 3 + i + (u8 *)(gBattleStruct->battlerPartyOrders)) = gBattlePartyCurrentOrder[i];
117+
*(i + (u8 *)(gBattleStruct->battlerPartyOrders)) = gBattlePartyCurrentOrder[i];
118118
}
119119
}
120120

0 commit comments

Comments
 (0)