diff --git a/include/frontier_util.h b/include/frontier_util.h index 637b7f91bb..0d617782a3 100644 --- a/include/frontier_util.h +++ b/include/frontier_util.h @@ -24,5 +24,6 @@ u16 GetFrontierBrainMonMove(u8 monId, u8 moveSlotId); u8 GetFrontierBrainMonNature(u8 monId); u8 GetFrontierBrainMonEvs(u8 monId, u8 evStatId); s32 GetFronterBrainSymbol(void); +void ClearEnemyPartyAfterChallenge(void); #endif // GUARD_FRONTIER_UTIL_H diff --git a/src/battle_arena.c b/src/battle_arena.c index 26df519be0..d0819fa8f0 100644 --- a/src/battle_arena.c +++ b/src/battle_arena.c @@ -529,6 +529,7 @@ static void SetArenaData(void) static void SaveArenaChallenge(void) { + ClearEnemyPartyAfterChallenge(); gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); gSaveBlock2Ptr->frontier.challengePaused = TRUE; diff --git a/src/battle_dome.c b/src/battle_dome.c index 06acf6e2f2..a91da6fda7 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -2593,6 +2593,7 @@ static void SetDomeOpponentGraphicsId(void) static void SaveDomeChallenge(void) { + ClearEnemyPartyAfterChallenge(); gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); gSaveBlock2Ptr->frontier.challengePaused = TRUE; diff --git a/src/battle_factory.c b/src/battle_factory.c index b5645368c2..8edd9a2ddf 100644 --- a/src/battle_factory.c +++ b/src/battle_factory.c @@ -268,6 +268,7 @@ static void SetBattleFactoryData(void) static void SaveFactoryChallenge(void) { + ClearEnemyPartyAfterChallenge(); gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); gSaveBlock2Ptr->frontier.challengePaused = TRUE; @@ -430,9 +431,6 @@ static void SetPlayerAndOpponentParties(void) ivs = gSaveBlock2Ptr->frontier.rentalMons[i].ivs; CreateFacilityMon(&gFacilityTrainerMons[monId], monLevel, ivs, OT_ID_PLAYER_ID, FLAG_FRONTIER_MON_FACTORY, &gPlayerParty[i]); - SetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY, - &gSaveBlock2Ptr->frontier.rentalMons[i].personality); - CalculateMonStats(&gPlayerParty[i]); } } @@ -444,12 +442,7 @@ static void SetPlayerAndOpponentParties(void) { monId = gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].monId; ivs = gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].ivs; - CreateFacilityMon(&gFacilityTrainerMons[monId], - monLevel, ivs, OT_ID_PLAYER_ID, FLAG_FRONTIER_MON_FACTORY, - &gEnemyParty[i]); - SetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY, - &gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].personality); - CalculateMonStats(&gPlayerParty[i]); + CreateFacilityMon(&gFacilityTrainerMons[monId], monLevel, ivs, OT_ID_PLAYER_ID, FLAG_FRONTIER_MON_FACTORY, &gEnemyParty[i]); } break; } diff --git a/src/battle_main.c b/src/battle_main.c index 4165dea20d..d011cde1db 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -5624,9 +5624,14 @@ static void FreeResetData_ReturnToOvOrDoEvolutions(void) } FreeAllWindowBuffers(); - if (gBattleStruct != NULL && !(gBattleTypeFlags & BATTLE_TYPE_LINK)) + if (!(gBattleTypeFlags & BATTLE_TYPE_LINK)) { - ZeroEnemyPartyMons(); + // To account for Battle Factory and Slateport Battle Tent, enemy parties are zeroed out in the facilitites respective src/xxx.c files + // The ZeroEnemyPartyMons() call happens in SaveXXXChallenge function (eg. SaveFactoryChallenge) + if (!(gBattleTypeFlags & BATTLE_TYPE_FRONTIER)) + { + ZeroEnemyPartyMons(); + } ResetDynamicAiFunc(); FreeMonSpritesGfx(); FreeBattleResources(); diff --git a/src/battle_palace.c b/src/battle_palace.c index a521acea2b..fdcb8d3903 100644 --- a/src/battle_palace.c +++ b/src/battle_palace.c @@ -180,6 +180,7 @@ static void IncrementPalaceStreak(void) static void SavePalaceChallenge(void) { + ClearEnemyPartyAfterChallenge(); gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); gSaveBlock2Ptr->frontier.challengePaused = TRUE; diff --git a/src/battle_pike.c b/src/battle_pike.c index 3869531d20..3ce3cd443a 100644 --- a/src/battle_pike.c +++ b/src/battle_pike.c @@ -707,6 +707,7 @@ static void ClearInWildMonRoom(void) static void SavePikeChallenge(void) { + ClearEnemyPartyAfterChallenge(); gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); gSaveBlock2Ptr->frontier.challengePaused = TRUE; diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index ce7a0526f2..0a82124428 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -2,6 +2,7 @@ #include "battle_pyramid.h" #include "battle_pyramid_bag.h" #include "event_data.h" +#include "frontier_util.h" #include "battle.h" #include "battle_setup.h" #include "battle_tower.h" @@ -936,6 +937,7 @@ static void SetBattlePyramidData(void) static void SavePyramidChallenge(void) { + ClearEnemyPartyAfterChallenge(); gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); gSaveBlock2Ptr->frontier.challengePaused = TRUE; diff --git a/src/battle_tent.c b/src/battle_tent.c index 8c6a94509a..49df90ffd6 100644 --- a/src/battle_tent.c +++ b/src/battle_tent.c @@ -139,6 +139,7 @@ static void BufferVerdanturfTentTrainerIntro(void) static void SaveVerdanturfTentChallenge(void) { + ClearEnemyPartyAfterChallenge(); gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); gSaveBlock2Ptr->frontier.challengePaused = TRUE; @@ -189,6 +190,7 @@ static void SetFallarborTentPrize(void) static void SaveFallarborTentChallenge(void) { + ClearEnemyPartyAfterChallenge(); gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); gSaveBlock2Ptr->frontier.challengePaused = TRUE; @@ -244,6 +246,7 @@ static void SetSlateportTentPrize(void) static void SaveSlateportTentChallenge(void) { + ClearEnemyPartyAfterChallenge(); gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); gSaveBlock2Ptr->frontier.challengePaused = TRUE; diff --git a/src/battle_tower.c b/src/battle_tower.c index 51200512f1..72858a854c 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -2206,6 +2206,7 @@ static void SaveTowerChallenge(void) if (gSpecialVar_0x8005 == 0 && (challengeNum > 1 || gSaveBlock2Ptr->frontier.curChallengeBattleNum != 0)) SaveBattleTowerRecord(); + ClearEnemyPartyAfterChallenge(); gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); gSaveBlock2Ptr->frontier.challengePaused = TRUE; diff --git a/src/frontier_util.c b/src/frontier_util.c index ca8c76a0fd..3561ef5472 100644 --- a/src/frontier_util.c +++ b/src/frontier_util.c @@ -2578,3 +2578,14 @@ static void CopyFrontierBrainText(bool8 playerWonText) break; } } + +void ClearEnemyPartyAfterChallenge() +{ + // We zero out the Enemy's party here when the player either wins or loses the challenge since we + // can't do it the usual way in FreeResetData_ReturnToOvOrDoEvolutions() in battle_main.c due to the + // way facilities like the Battle Factory and the Slateport Battle Tent work + if (gSpecialVar_0x8005 == 0) + { + ZeroEnemyPartyMons(); + } +}