Fix Slateport Battle Tent/Battle Factory (#5281)

* Fix Slateport Battle Tent/Battle Factory

Stops the Battle Factory and Slateport Battle Tent from returning no Pokémon when player wants to swap their Pokémon.

* Fix player rental party being junk data after rest

Fixes #5280

* Consolidate checks into single method

Consolidates every gSpecialVar_0x8005 check into a singular method.
This commit is contained in:
SarnPoke 2024-09-02 22:53:03 +02:00 committed by GitHub
parent fb1f12aa1b
commit a422db09c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 31 additions and 11 deletions

View file

@ -24,5 +24,6 @@ u16 GetFrontierBrainMonMove(u8 monId, u8 moveSlotId);
u8 GetFrontierBrainMonNature(u8 monId); u8 GetFrontierBrainMonNature(u8 monId);
u8 GetFrontierBrainMonEvs(u8 monId, u8 evStatId); u8 GetFrontierBrainMonEvs(u8 monId, u8 evStatId);
s32 GetFronterBrainSymbol(void); s32 GetFronterBrainSymbol(void);
void ClearEnemyPartyAfterChallenge(void);
#endif // GUARD_FRONTIER_UTIL_H #endif // GUARD_FRONTIER_UTIL_H

View file

@ -529,6 +529,7 @@ static void SetArenaData(void)
static void SaveArenaChallenge(void) static void SaveArenaChallenge(void)
{ {
ClearEnemyPartyAfterChallenge();
gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005;
VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); VarSet(VAR_TEMP_CHALLENGE_STATUS, 0);
gSaveBlock2Ptr->frontier.challengePaused = TRUE; gSaveBlock2Ptr->frontier.challengePaused = TRUE;

View file

@ -2593,6 +2593,7 @@ static void SetDomeOpponentGraphicsId(void)
static void SaveDomeChallenge(void) static void SaveDomeChallenge(void)
{ {
ClearEnemyPartyAfterChallenge();
gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005;
VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); VarSet(VAR_TEMP_CHALLENGE_STATUS, 0);
gSaveBlock2Ptr->frontier.challengePaused = TRUE; gSaveBlock2Ptr->frontier.challengePaused = TRUE;

View file

@ -268,6 +268,7 @@ static void SetBattleFactoryData(void)
static void SaveFactoryChallenge(void) static void SaveFactoryChallenge(void)
{ {
ClearEnemyPartyAfterChallenge();
gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005;
VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); VarSet(VAR_TEMP_CHALLENGE_STATUS, 0);
gSaveBlock2Ptr->frontier.challengePaused = TRUE; gSaveBlock2Ptr->frontier.challengePaused = TRUE;
@ -430,9 +431,6 @@ static void SetPlayerAndOpponentParties(void)
ivs = gSaveBlock2Ptr->frontier.rentalMons[i].ivs; ivs = gSaveBlock2Ptr->frontier.rentalMons[i].ivs;
CreateFacilityMon(&gFacilityTrainerMons[monId], monLevel, ivs, OT_ID_PLAYER_ID, FLAG_FRONTIER_MON_FACTORY, &gPlayerParty[i]); 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; monId = gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].monId;
ivs = gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].ivs; ivs = gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].ivs;
CreateFacilityMon(&gFacilityTrainerMons[monId], CreateFacilityMon(&gFacilityTrainerMons[monId], monLevel, ivs, OT_ID_PLAYER_ID, FLAG_FRONTIER_MON_FACTORY, &gEnemyParty[i]);
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]);
} }
break; break;
} }

View file

@ -5624,9 +5624,14 @@ static void FreeResetData_ReturnToOvOrDoEvolutions(void)
} }
FreeAllWindowBuffers(); 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(); ResetDynamicAiFunc();
FreeMonSpritesGfx(); FreeMonSpritesGfx();
FreeBattleResources(); FreeBattleResources();

View file

@ -180,6 +180,7 @@ static void IncrementPalaceStreak(void)
static void SavePalaceChallenge(void) static void SavePalaceChallenge(void)
{ {
ClearEnemyPartyAfterChallenge();
gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005;
VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); VarSet(VAR_TEMP_CHALLENGE_STATUS, 0);
gSaveBlock2Ptr->frontier.challengePaused = TRUE; gSaveBlock2Ptr->frontier.challengePaused = TRUE;

View file

@ -707,6 +707,7 @@ static void ClearInWildMonRoom(void)
static void SavePikeChallenge(void) static void SavePikeChallenge(void)
{ {
ClearEnemyPartyAfterChallenge();
gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005;
VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); VarSet(VAR_TEMP_CHALLENGE_STATUS, 0);
gSaveBlock2Ptr->frontier.challengePaused = TRUE; gSaveBlock2Ptr->frontier.challengePaused = TRUE;

View file

@ -2,6 +2,7 @@
#include "battle_pyramid.h" #include "battle_pyramid.h"
#include "battle_pyramid_bag.h" #include "battle_pyramid_bag.h"
#include "event_data.h" #include "event_data.h"
#include "frontier_util.h"
#include "battle.h" #include "battle.h"
#include "battle_setup.h" #include "battle_setup.h"
#include "battle_tower.h" #include "battle_tower.h"
@ -936,6 +937,7 @@ static void SetBattlePyramidData(void)
static void SavePyramidChallenge(void) static void SavePyramidChallenge(void)
{ {
ClearEnemyPartyAfterChallenge();
gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005;
VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); VarSet(VAR_TEMP_CHALLENGE_STATUS, 0);
gSaveBlock2Ptr->frontier.challengePaused = TRUE; gSaveBlock2Ptr->frontier.challengePaused = TRUE;

View file

@ -139,6 +139,7 @@ static void BufferVerdanturfTentTrainerIntro(void)
static void SaveVerdanturfTentChallenge(void) static void SaveVerdanturfTentChallenge(void)
{ {
ClearEnemyPartyAfterChallenge();
gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005;
VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); VarSet(VAR_TEMP_CHALLENGE_STATUS, 0);
gSaveBlock2Ptr->frontier.challengePaused = TRUE; gSaveBlock2Ptr->frontier.challengePaused = TRUE;
@ -189,6 +190,7 @@ static void SetFallarborTentPrize(void)
static void SaveFallarborTentChallenge(void) static void SaveFallarborTentChallenge(void)
{ {
ClearEnemyPartyAfterChallenge();
gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005;
VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); VarSet(VAR_TEMP_CHALLENGE_STATUS, 0);
gSaveBlock2Ptr->frontier.challengePaused = TRUE; gSaveBlock2Ptr->frontier.challengePaused = TRUE;
@ -244,6 +246,7 @@ static void SetSlateportTentPrize(void)
static void SaveSlateportTentChallenge(void) static void SaveSlateportTentChallenge(void)
{ {
ClearEnemyPartyAfterChallenge();
gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005;
VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); VarSet(VAR_TEMP_CHALLENGE_STATUS, 0);
gSaveBlock2Ptr->frontier.challengePaused = TRUE; gSaveBlock2Ptr->frontier.challengePaused = TRUE;

View file

@ -2206,6 +2206,7 @@ static void SaveTowerChallenge(void)
if (gSpecialVar_0x8005 == 0 && (challengeNum > 1 || gSaveBlock2Ptr->frontier.curChallengeBattleNum != 0)) if (gSpecialVar_0x8005 == 0 && (challengeNum > 1 || gSaveBlock2Ptr->frontier.curChallengeBattleNum != 0))
SaveBattleTowerRecord(); SaveBattleTowerRecord();
ClearEnemyPartyAfterChallenge();
gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005; gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005;
VarSet(VAR_TEMP_CHALLENGE_STATUS, 0); VarSet(VAR_TEMP_CHALLENGE_STATUS, 0);
gSaveBlock2Ptr->frontier.challengePaused = TRUE; gSaveBlock2Ptr->frontier.challengePaused = TRUE;

View file

@ -2578,3 +2578,14 @@ static void CopyFrontierBrainText(bool8 playerWonText)
break; 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();
}
}