diff --git a/include/battle_controllers.h b/include/battle_controllers.h index f7788129ee..681ee519f4 100644 --- a/include/battle_controllers.h +++ b/include/battle_controllers.h @@ -438,4 +438,6 @@ void BtlController_HandleSwitchInSoundAndEnd(u32 battler); void BtlController_HandleSwitchInShowSubstitute(u32 battler); bool32 ShouldBattleRestrictionsApply(u32 battler); +void FreeShinyStars(void); + #endif // GUARD_BATTLE_CONTROLLERS_H diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index 658a2d3831..3418293530 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -150,8 +150,7 @@ static void Intro_WaitForShinyAnimAndHealthbox(u32 battler) gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(battler)].triedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(battler)].finishedShinyMonAnim = FALSE; - FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); - FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); + FreeShinyStars(); } else { @@ -163,8 +162,7 @@ static void Intro_WaitForShinyAnimAndHealthbox(u32 battler) if (GetBattlerPosition(battler) == B_POSITION_OPPONENT_RIGHT) { - FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); - FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); + FreeShinyStars(); } } diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 8c469733c1..15985aa0b4 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -159,8 +159,7 @@ static void Intro_WaitForShinyAnimAndHealthbox(u32 battler) gBattleSpritesDataPtr->healthBoxesData[battler].finishedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(battler)].triedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(battler)].finishedShinyMonAnim = FALSE; - FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); - FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); + FreeShinyStars(); } else { @@ -174,8 +173,7 @@ static void Intro_WaitForShinyAnimAndHealthbox(u32 battler) if (!gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(battler)].triedShinyMonAnim && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(battler)].finishedShinyMonAnim) { - FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); - FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); + FreeShinyStars(); } else { diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index f98b3ca3d6..564afa3446 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -1247,8 +1247,7 @@ static void Intro_WaitForShinyAnimAndHealthbox(u32 battler) gBattleSpritesDataPtr->healthBoxesData[battler].finishedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(battler)].triedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(battler)].finishedShinyMonAnim = FALSE; - FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); - FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); + FreeShinyStars(); HandleLowHpMusicChange(GetBattlerMon(battler), battler); diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index a27318aee8..21ecb79801 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -170,8 +170,7 @@ static void Intro_WaitForShinyAnimAndHealthbox(u32 battler) gBattleSpritesDataPtr->healthBoxesData[battler].finishedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(battler)].triedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(battler)].finishedShinyMonAnim = FALSE; - FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); - FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); + FreeShinyStars(); } gBattleSpritesDataPtr->healthBoxesData[battler].introEndDelay = 3; diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index 0230451827..c86cf4a9d5 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -147,8 +147,7 @@ static void Intro_WaitForShinyAnimAndHealthbox(u32 battler) gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(battler)].triedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(battler)].finishedShinyMonAnim = FALSE; - FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); - FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); + FreeShinyStars(); HandleLowHpMusicChange(GetBattlerMon(battler), battler); if (IsDoubleBattle()) diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index 932b4a26b4..11955787d9 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -255,8 +255,7 @@ static void Intro_WaitForShinyAnimAndHealthbox(u32 battler) gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(battler)].triedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(battler)].finishedShinyMonAnim = FALSE; - FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); - FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); + FreeShinyStars(); CreateTask(Task_PlayerController_RestoreBgmAfterCry, 10); HandleLowHpMusicChange(GetBattlerMon(battler), battler); diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 3c9f0a21cd..9818879e7b 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -2940,8 +2940,7 @@ void TryShinyAnimAfterMonAnim(u32 battler) { gBattleSpritesDataPtr->healthBoxesData[battler].triedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[battler].finishedShinyMonAnim = FALSE; - FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); - FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); + FreeShinyStars(); BtlController_Complete(battler); } } @@ -3012,8 +3011,7 @@ void BtlController_HandleSwitchInShowHealthbox(u32 battler) { gBattleSpritesDataPtr->healthBoxesData[battler].triedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[battler].finishedShinyMonAnim = FALSE; - FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); - FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); + FreeShinyStars(); if (side == B_SIDE_PLAYER) { @@ -3043,8 +3041,7 @@ static void SwitchIn_CleanShinyAnimShowSubstitute(u32 battler) // Reset shiny anim (even if it didn't occur) gBattleSpritesDataPtr->healthBoxesData[battler].triedShinyMonAnim = FALSE; gBattleSpritesDataPtr->healthBoxesData[battler].finishedShinyMonAnim = FALSE; - FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); - FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); + FreeShinyStars(); // Check if Substitute should be shown if (gBattleSpritesDataPtr->battlerData[battler].behindSubstitute) @@ -3129,3 +3126,14 @@ bool32 ShouldBattleRestrictionsApply(u32 battler) { return IsControllerPlayer(battler); } + +void FreeShinyStars(void) +{ + for (u32 battler = 0; battler < gBattlersCount; battler++) + { + if (gBattleSpritesDataPtr->healthBoxesData[battler].triedShinyMonAnim) + return; + } + FreeSpriteTilesByTag(ANIM_TAG_GOLD_STARS); + FreeSpritePaletteByTag(ANIM_TAG_GOLD_STARS); +}