diff --git a/include/battle_controllers.h b/include/battle_controllers.h index 14bf29606f..0e7715e9f0 100644 --- a/include/battle_controllers.h +++ b/include/battle_controllers.h @@ -258,9 +258,10 @@ void BtlController_HandleGetMonData(u32 battler, struct Pokemon *party); void BtlController_HandleGetRawMonData(u32 battler, struct Pokemon *party); void BtlController_HandleSetMonData(u32 battler, struct Pokemon *party); void BtlController_HandleSetRawMonData(u32 battler, struct Pokemon *party); -void BtlController_HandleLoadMonSprite(u32 battler, struct Pokemon *party, void (*controllerFunc)(void)); -void BtlController_HandleSwitchInAnim(u32 battler, bool32 isPlayerSide, void (*controllerFunc)(void)); +void BtlController_HandleLoadMonSprite(u32 battler, struct Pokemon *party, void (*controllerCallback)(void)); +void BtlController_HandleSwitchInAnim(u32 battler, bool32 isPlayerSide, void (*controllerCallback)(void)); void BtlController_HandleReturnMonToBall(u32 battler); +void BtlController_HandleFaintAnimation(u32 battler); // player controller void SetControllerToPlayer(void); diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index 873dee9c6c..2b195e5993 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -392,15 +392,6 @@ static void CompleteOnHealthbarDone(void) LinkOpponentBufferExecCompleted(); } -static void HideHealthboxAfterMonFaint(void) -{ - if (!gSprites[gBattlerSpriteIds[gActiveBattler]].inUse) - { - SetHealthboxSpriteInvisible(gHealthboxSpriteIds[gActiveBattler]); - LinkOpponentBufferExecCompleted(); - } -} - static void CompleteOnInactiveTextPrinter(void) { if (!IsTextPrinterActive(B_WIN_MSG)) @@ -680,22 +671,7 @@ static void LinkOpponentHandleTrainerSlideBack(void) static void LinkOpponentHandleFaintAnimation(void) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState == 0) - { - if (gBattleSpritesDataPtr->battlerData[gActiveBattler].behindSubstitute) - InitAndLaunchSpecialAnimation(gActiveBattler, gActiveBattler, gActiveBattler, B_ANIM_SUBSTITUTE_TO_MON); - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState++; - } - else - { - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].specialAnimActive) - { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState = 0; - PlaySE12WithPanning(SE_FAINT, SOUND_PAN_TARGET); - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = SpriteCB_FaintOpponentMon; - gBattlerControllerFuncs[gActiveBattler] = HideHealthboxAfterMonFaint; - } - } + BtlController_HandleFaintAnimation(gActiveBattler); } static void LinkOpponentHandlePaletteFade(void) diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index 3756dda923..073fb9823d 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -286,20 +286,6 @@ static void CompleteOnHealthbarDone(void) } } -static void FreeMonSpriteAfterFaintAnim(void) -{ - if (gSprites[gBattlerSpriteIds[gActiveBattler]].y + gSprites[gBattlerSpriteIds[gActiveBattler]].y2 > DISPLAY_HEIGHT) - { - u16 species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES); - - BattleGfxSfxDummy2(species); - FreeOamMatrix(gSprites[gBattlerSpriteIds[gActiveBattler]].oam.matrixNum); - DestroySprite(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - SetHealthboxSpriteInvisible(gHealthboxSpriteIds[gActiveBattler]); - LinkPartnerBufferExecCompleted(); - } -} - static void CompleteOnInactiveTextPrinter(void) { if (!IsTextPrinterActive(B_WIN_MSG)) @@ -510,35 +496,11 @@ static void LinkPartnerHandleTrainerSlideBack(void) gBattlerControllerFuncs[gActiveBattler] = FreeTrainerSpriteAfterSlide; } -#define sSpeedX data[1] -#define sSpeedY data[2] - static void LinkPartnerHandleFaintAnimation(void) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState == 0) - { - if (gBattleSpritesDataPtr->battlerData[gActiveBattler].behindSubstitute) - InitAndLaunchSpecialAnimation(gActiveBattler, gActiveBattler, gActiveBattler, B_ANIM_SUBSTITUTE_TO_MON); - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState++; - } - else - { - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].specialAnimActive) - { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState = 0; - HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); - PlaySE12WithPanning(SE_FAINT, SOUND_PAN_ATTACKER); - gSprites[gBattlerSpriteIds[gActiveBattler]].sSpeedX = 0; - gSprites[gBattlerSpriteIds[gActiveBattler]].sSpeedY = 5; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = SpriteCB_FaintSlideAnim; - gBattlerControllerFuncs[gActiveBattler] = FreeMonSpriteAfterFaintAnim; - } - } + BtlController_HandleFaintAnimation(gActiveBattler); } -#undef sSpeedX -#undef sSpeedY - static void LinkPartnerHandlePaletteFade(void) { LinkPartnerBufferExecCompleted(); diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 4323beba5b..2cdc9f6620 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -416,15 +416,6 @@ static void CompleteOnHealthbarDone(void) OpponentBufferExecCompleted(); } -static void HideHealthboxAfterMonFaint(void) -{ - if (!gSprites[gBattlerSpriteIds[gActiveBattler]].inUse) - { - SetHealthboxSpriteInvisible(gHealthboxSpriteIds[gActiveBattler]); - OpponentBufferExecCompleted(); - } -} - static void CompleteOnInactiveTextPrinter(void) { if (!IsTextPrinterActive(B_WIN_MSG)) @@ -742,22 +733,7 @@ static void OpponentHandleTrainerSlideBack(void) static void OpponentHandleFaintAnimation(void) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState == 0) - { - if (gBattleSpritesDataPtr->battlerData[gActiveBattler].behindSubstitute) - InitAndLaunchSpecialAnimation(gActiveBattler, gActiveBattler, gActiveBattler, B_ANIM_SUBSTITUTE_TO_MON); - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState++; - } - else - { - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].specialAnimActive) - { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState = 0; - PlaySE12WithPanning(SE_FAINT, SOUND_PAN_TARGET); - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = SpriteCB_FaintOpponentMon; - gBattlerControllerFuncs[gActiveBattler] = HideHealthboxAfterMonFaint; - } - } + BtlController_HandleFaintAnimation(gActiveBattler); } static void OpponentHandlePaletteFade(void) diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 1a6f1f9edb..fc5ca9fde6 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -1529,20 +1529,6 @@ static void DestroyExpTaskAndCompleteOnInactiveTextPrinter(u8 taskId) DestroyTask(taskId); } -static void FreeMonSpriteAfterFaintAnim(void) -{ - if (gSprites[gBattlerSpriteIds[gActiveBattler]].y + gSprites[gBattlerSpriteIds[gActiveBattler]].y2 > DISPLAY_HEIGHT) - { - u16 species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES); - - BattleGfxSfxDummy2(species); - FreeOamMatrix(gSprites[gBattlerSpriteIds[gActiveBattler]].oam.matrixNum); - DestroySprite(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - SetHealthboxSpriteInvisible(gHealthboxSpriteIds[gActiveBattler]); - PlayerBufferExecCompleted(); - } -} - static void CompleteOnInactiveTextPrinter2(void) { if (!IsTextPrinterActive(B_WIN_MSG)) @@ -1965,35 +1951,11 @@ static void PlayerHandleTrainerSlideBack(void) gBattlerControllerFuncs[gActiveBattler] = FreeTrainerSpriteAfterSlide; } -#define sSpeedX data[1] -#define sSpeedY data[2] - static void PlayerHandleFaintAnimation(void) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState == 0) - { - if (gBattleSpritesDataPtr->battlerData[gActiveBattler].behindSubstitute) - InitAndLaunchSpecialAnimation(gActiveBattler, gActiveBattler, gActiveBattler, B_ANIM_SUBSTITUTE_TO_MON); - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState++; - } - else - { - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].specialAnimActive) - { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState = 0; - HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); - PlaySE12WithPanning(SE_FAINT, SOUND_PAN_ATTACKER); - gSprites[gBattlerSpriteIds[gActiveBattler]].sSpeedX = 0; - gSprites[gBattlerSpriteIds[gActiveBattler]].sSpeedY = 5; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = SpriteCB_FaintSlideAnim; - gBattlerControllerFuncs[gActiveBattler] = FreeMonSpriteAfterFaintAnim; - } - } + BtlController_HandleFaintAnimation(gActiveBattler); } -#undef sSpeedX -#undef sSpeedY - static void PlayerHandlePaletteFade(void) { BeginNormalPaletteFade(PALETTES_ALL, 2, 0, 16, RGB_BLACK); diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index 87f7b5c270..65295ebaad 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -465,20 +465,6 @@ static void DestroyExpTaskAndCompleteOnInactiveTextPrinter(u8 taskId) DestroyTask(taskId); } -static void FreeMonSpriteAfterFaintAnim(void) -{ - if (gSprites[gBattlerSpriteIds[gActiveBattler]].y + gSprites[gBattlerSpriteIds[gActiveBattler]].y2 > DISPLAY_HEIGHT) - { - u16 species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES); - - BattleGfxSfxDummy2(species); - FreeOamMatrix(gSprites[gBattlerSpriteIds[gActiveBattler]].oam.matrixNum); - DestroySprite(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - SetHealthboxSpriteInvisible(gHealthboxSpriteIds[gActiveBattler]); - PlayerPartnerBufferExecCompleted(); - } -} - static void CompleteOnInactiveTextPrinter2(void) { if (!IsTextPrinterActive(B_WIN_MSG)) @@ -702,35 +688,11 @@ static void PlayerPartnerHandleTrainerSlideBack(void) gBattlerControllerFuncs[gActiveBattler] = FreeTrainerSpriteAfterSlide; } -#define sSpeedX data[1] -#define sSpeedY data[2] - static void PlayerPartnerHandleFaintAnimation(void) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState == 0) - { - if (gBattleSpritesDataPtr->battlerData[gActiveBattler].behindSubstitute) - InitAndLaunchSpecialAnimation(gActiveBattler, gActiveBattler, gActiveBattler, B_ANIM_SUBSTITUTE_TO_MON); - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState++; - } - else - { - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].specialAnimActive) - { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState = 0; - HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); - PlaySE12WithPanning(SE_FAINT, SOUND_PAN_ATTACKER); - gSprites[gBattlerSpriteIds[gActiveBattler]].sSpeedX = 0; - gSprites[gBattlerSpriteIds[gActiveBattler]].sSpeedY = 5; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = SpriteCB_FaintSlideAnim; - gBattlerControllerFuncs[gActiveBattler] = FreeMonSpriteAfterFaintAnim; - } - } + BtlController_HandleFaintAnimation(gActiveBattler); } -#undef sSpeedX -#undef sSpeedY - static void PlayerPartnerHandlePaletteFade(void) { PlayerPartnerBufferExecCompleted(); diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index 3aedbe4c33..40fe8a56c7 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -382,15 +382,6 @@ static void CompleteOnHealthbarDone(void) RecordedOpponentBufferExecCompleted(); } -static void HideHealthboxAfterMonFaint(void) -{ - if (!gSprites[gBattlerSpriteIds[gActiveBattler]].inUse) - { - SetHealthboxSpriteInvisible(gHealthboxSpriteIds[gActiveBattler]); - RecordedOpponentBufferExecCompleted(); - } -} - static void CompleteOnInactiveTextPrinter(void) { if (!IsTextPrinterActive(B_WIN_MSG)) @@ -615,22 +606,7 @@ static void RecordedOpponentHandleTrainerSlideBack(void) static void RecordedOpponentHandleFaintAnimation(void) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState == 0) - { - if (gBattleSpritesDataPtr->battlerData[gActiveBattler].behindSubstitute) - InitAndLaunchSpecialAnimation(gActiveBattler, gActiveBattler, gActiveBattler, B_ANIM_SUBSTITUTE_TO_MON); - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState++; - } - else - { - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].specialAnimActive) - { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState = 0; - PlaySE12WithPanning(SE_FAINT, SOUND_PAN_TARGET); - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = SpriteCB_FaintOpponentMon; - gBattlerControllerFuncs[gActiveBattler] = HideHealthboxAfterMonFaint; - } - } + BtlController_HandleFaintAnimation(gActiveBattler); } static void RecordedOpponentHandlePaletteFade(void) diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index 2846e1bef8..2e208f2396 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -362,20 +362,6 @@ static void CompleteOnHealthbarDone(void) } } -static void FreeMonSpriteAfterFaintAnim(void) -{ - if (gSprites[gBattlerSpriteIds[gActiveBattler]].y + gSprites[gBattlerSpriteIds[gActiveBattler]].y2 > DISPLAY_HEIGHT) - { - u16 species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES); - - BattleGfxSfxDummy2(species); - FreeOamMatrix(gSprites[gBattlerSpriteIds[gActiveBattler]].oam.matrixNum); - DestroySprite(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - SetHealthboxSpriteInvisible(gHealthboxSpriteIds[gActiveBattler]); - RecordedPlayerBufferExecCompleted(); - } -} - static void CompleteOnInactiveTextPrinter(void) { if (!IsTextPrinterActive(B_WIN_MSG)) @@ -613,35 +599,11 @@ static void RecordedPlayerHandleTrainerSlideBack(void) gBattlerControllerFuncs[gActiveBattler] = FreeTrainerSpriteAfterSlide; } -#define sSpeedX data[1] -#define sSpeedY data[2] - static void RecordedPlayerHandleFaintAnimation(void) { - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState == 0) - { - if (gBattleSpritesDataPtr->battlerData[gActiveBattler].behindSubstitute) - InitAndLaunchSpecialAnimation(gActiveBattler, gActiveBattler, gActiveBattler, B_ANIM_SUBSTITUTE_TO_MON); - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState++; - } - else - { - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].specialAnimActive) - { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState = 0; - HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); - PlaySE12WithPanning(SE_FAINT, -64); - gSprites[gBattlerSpriteIds[gActiveBattler]].sSpeedX = 0; - gSprites[gBattlerSpriteIds[gActiveBattler]].sSpeedY = 5; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = SpriteCB_FaintSlideAnim; - gBattlerControllerFuncs[gActiveBattler] = FreeMonSpriteAfterFaintAnim; - } - } + BtlController_HandleFaintAnimation(gActiveBattler); } -#undef sSpeedX -#undef sSpeedY - static void RecordedPlayerHandlePaletteFade(void) { RecordedPlayerBufferExecCompleted(); diff --git a/src/battle_controllers.c b/src/battle_controllers.c index b9a25321af..5f5a0fcfc3 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -13,9 +13,11 @@ #include "party_menu.h" #include "recorded_battle.h" #include "string_util.h" +#include "sound.h" #include "task.h" #include "util.h" #include "constants/abilities.h" +#include "constants/songs.h" static EWRAM_DATA u8 sLinkSendTaskId = 0; static EWRAM_DATA u8 sLinkReceiveTaskId = 0; @@ -2122,7 +2124,7 @@ static void FreeMonSprite(u32 battler) SetHealthboxSpriteInvisible(gHealthboxSpriteIds[battler]); } -static void FreeMonSpriteAfterSwitchOutAnim(void) +static void Controller_ReturnMonToBall2(void) { if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].specialAnimActive) { @@ -2131,7 +2133,7 @@ static void FreeMonSpriteAfterSwitchOutAnim(void) } } -static void DoSwitchOutAnimation(void) +static void Controller_ReturnMonToBall(void) { switch (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState) { @@ -2146,12 +2148,35 @@ static void DoSwitchOutAnimation(void) { gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].animationState = 0; InitAndLaunchSpecialAnimation(gActiveBattler, gActiveBattler, gActiveBattler, (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT) ? B_ANIM_SWITCH_OUT_OPPONENT_MON : B_ANIM_SWITCH_OUT_PLAYER_MON); - gBattlerControllerFuncs[gActiveBattler] = FreeMonSpriteAfterSwitchOutAnim; + gBattlerControllerFuncs[gActiveBattler] = Controller_ReturnMonToBall2; } break; } } +static void Controller_FaintPlayerMon(void) +{ + u32 spriteId = gBattlerSpriteIds[gActiveBattler]; + if (gSprites[spriteId].y + gSprites[spriteId].y2 > DISPLAY_HEIGHT) + { + BattleGfxSfxDummy2(GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_SPECIES)); + FreeOamMatrix(gSprites[spriteId].oam.matrixNum); + DestroySprite(&gSprites[spriteId]); + SetHealthboxSpriteInvisible(gHealthboxSpriteIds[gActiveBattler]); + BattleControllerComplete(gActiveBattler); + } +} + +static void Controller_FaintOpponentMon(void) +{ + if (!gSprites[gBattlerSpriteIds[gActiveBattler]].inUse) + { + SetHealthboxSpriteInvisible(gHealthboxSpriteIds[gActiveBattler]); + BattleControllerComplete(gActiveBattler); + } +} + +// Handlers of all the controller commands void BtlController_HandleGetMonData(u32 battler, struct Pokemon *party) { u8 monData[sizeof(struct Pokemon) * 2 + 56]; // this allows to get full data of two pokemon, trying to get more will result in overwriting data @@ -2223,7 +2248,7 @@ void BtlController_HandleSetRawMonData(u32 battler, struct Pokemon *party) BattleControllerComplete(battler); } -void BtlController_HandleLoadMonSprite(u32 battler, struct Pokemon *party, void (*controllerFunc)(void)) +void BtlController_HandleLoadMonSprite(u32 battler, struct Pokemon *party, void (*controllerCallback)(void)) { u16 species = GetMonData(&party[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES); @@ -2243,10 +2268,10 @@ void BtlController_HandleLoadMonSprite(u32 battler, struct Pokemon *party, void SetBattlerShadowSpriteCallback(battler, species); - gBattlerControllerFuncs[battler] = controllerFunc; + gBattlerControllerFuncs[battler] = controllerCallback; } -void BtlController_HandleSwitchInAnim(u32 battler, bool32 isPlayerSide, void (*controllerFunc)(void)) +void BtlController_HandleSwitchInAnim(u32 battler, bool32 isPlayerSide, void (*controllerCallback)(void)) { if (isPlayerSide) ClearTemporarySpeciesSpriteData(battler, gBattleResources->bufferA[battler][2]); @@ -2254,7 +2279,7 @@ void BtlController_HandleSwitchInAnim(u32 battler, bool32 isPlayerSide, void (*c if (isPlayerSide) BattleLoadMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[battler]], battler); StartSendOutAnim(battler, gBattleResources->bufferA[battler][2]); - gBattlerControllerFuncs[battler] = controllerFunc; + gBattlerControllerFuncs[battler] = controllerCallback; } void BtlController_HandleReturnMonToBall(u32 battler) @@ -2262,7 +2287,7 @@ void BtlController_HandleReturnMonToBall(u32 battler) if (gBattleResources->bufferA[battler][1] == 0) { gBattleSpritesDataPtr->healthBoxesData[battler].animationState = 0; - gBattlerControllerFuncs[battler] = DoSwitchOutAnimation; + gBattlerControllerFuncs[battler] = Controller_ReturnMonToBall; } else { @@ -2270,3 +2295,43 @@ void BtlController_HandleReturnMonToBall(u32 battler) BattleControllerComplete(battler); } } + +#define sSpeedX data[1] +#define sSpeedY data[2] + +void BtlController_HandleFaintAnimation(u32 battler) +{ + if (gBattleSpritesDataPtr->healthBoxesData[battler].animationState == 0) + { + if (gBattleSpritesDataPtr->battlerData[battler].behindSubstitute) + InitAndLaunchSpecialAnimation(battler, battler, battler, B_ANIM_SUBSTITUTE_TO_MON); + gBattleSpritesDataPtr->healthBoxesData[battler].animationState++; + } + else + { + if (!gBattleSpritesDataPtr->healthBoxesData[battler].specialAnimActive) + { + gBattleSpritesDataPtr->healthBoxesData[battler].animationState = 0; + if (GetBattlerSide(battler) == B_SIDE_PLAYER) + { + HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[battler]], battler); + gSprites[gBattlerSpriteIds[battler]].sSpeedX = 0; + gSprites[gBattlerSpriteIds[battler]].sSpeedY = 5; + PlaySE12WithPanning(SE_FAINT, SOUND_PAN_ATTACKER); + gSprites[gBattlerSpriteIds[battler]].callback = SpriteCB_FaintSlideAnim; + gBattlerControllerFuncs[battler] = Controller_FaintPlayerMon; + } + else + { + PlaySE12WithPanning(SE_FAINT, SOUND_PAN_TARGET); + gSprites[gBattlerSpriteIds[battler]].callback = SpriteCB_FaintOpponentMon; + gBattlerControllerFuncs[battler] = Controller_FaintOpponentMon; + } + // The player's sprite callback just slides the mon, the opponent's removes the sprite. + // The player's sprite is removed in Controller_FaintPlayerMon. Controller_FaintOpponentMon only removes the healthbox once the sprite is removed by SpriteCB_FaintOpponentMon. + } + } +} + +#undef sSpeedX +#undef sSpeedY diff --git a/src/battle_main.c b/src/battle_main.c index eea745356a..77499d6e0e 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -565,8 +565,8 @@ static void CB2_InitBattleInternal(void) gBattle_BG3_X = 0; gBattle_BG3_Y = 0; -#if DEBUG_OVERWORLD_MENU == FALSE - +#if DEBUG_OVERWORLD_MENU == FALSE + gBattleTerrain = BattleSetup_GetTerrainId(); #else if (!gIsDebugBattle) @@ -594,7 +594,7 @@ static void CB2_InitBattleInternal(void) else SetMainCallback2(CB2_HandleStartBattle); -#if DEBUG_OVERWORLD_MENU == FALSE +#if DEBUG_OVERWORLD_MENU == FALSE if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED))) { CreateNPCTrainerParty(&gEnemyParty[0], gTrainerBattleOpponent_A, TRUE); @@ -2815,8 +2815,6 @@ void SpriteCB_FaintOpponentMon(struct Sprite *sprite) else species = sprite->sSpeciesId; - GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_PERSONALITY); // Unused return value. - if (species == SPECIES_UNOWN) { species = GetUnownSpeciesId(personality);