diff --git a/include/battle_controllers.h b/include/battle_controllers.h index 1e3b23959a..aa1d28c428 100644 --- a/include/battle_controllers.h +++ b/include/battle_controllers.h @@ -255,6 +255,7 @@ void BtlController_EmitDebugMenu(u8 bufferId); void BtlController_Empty(void); // Empty command, does nothing, only completes the execution. void BtlController_TerminatorNop(void); // Dummy function at the end of the table. void StartSendOutAnim(u32 battler, bool32 dontClearSubstituteBit); +void Controller_WaitForString(void); // handlers void BtlController_HandleGetMonData(void); @@ -267,6 +268,7 @@ void BtlController_HandleReturnMonToBall(void); void BtlController_HandleFaintAnimation(void); void BtlController_HandleSuccessBallThrowAnim(u32 battler, u32 target, u32 animId, bool32 allowCriticalCapture); void BtlController_HandleBallThrowAnim(u32 battler, u32 target, u32 animId, bool32 allowCriticalCapture); +void BtlController_HandlePrintString(u32 battler, bool32 updateTvData, bool32 arenaPtsDeduct); void DoStatusIconUpdate(u32 battler); void BtlController_HandleStatusIconUpdate(void); void BtlController_HandleStatusAnimation(void); diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index e8863c75e6..aa6c3b55c0 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -348,12 +348,6 @@ static void CompleteOnHealthbarDone(void) LinkOpponentBufferExecCompleted(); } -static void CompleteOnInactiveTextPrinter(void) -{ - if (!IsTextPrinterActive(B_WIN_MSG)) - LinkOpponentBufferExecCompleted(); -} - static void SwitchIn_ShowSubstitute(void) { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) @@ -640,15 +634,7 @@ static void LinkOpponentDoMoveAnimation(void) static void LinkOpponentHandlePrintString(void) { - u16 *stringId; - - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - stringId = (u16 *)(&gBattleResources->bufferA[gActiveBattler][2]); - BufferStringBattle(*stringId); - BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_MSG); - gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter; - BattleTv_SetDataBasedOnString(*stringId); + BtlController_HandlePrintString(gActiveBattler, TRUE, FALSE); } static void LinkOpponentHandleHealthBarUpdate(void) diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index 20cc10dadc..7d489c1f62 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -241,12 +241,6 @@ static void CompleteOnHealthbarDone(void) } } -static void CompleteOnInactiveTextPrinter(void) -{ - if (!IsTextPrinterActive(B_WIN_MSG)) - LinkPartnerBufferExecCompleted(); -} - static void SwitchIn_ShowSubstitute(void) { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) @@ -461,15 +455,7 @@ static void LinkPartnerDoMoveAnimation(void) static void LinkPartnerHandlePrintString(void) { - u16 *stringId; - - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - stringId = (u16 *)(&gBattleResources->bufferA[gActiveBattler][2]); - BufferStringBattle(*stringId); - BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_MSG); - gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter; - BattleTv_SetDataBasedOnString(*stringId); + BtlController_HandlePrintString(gActiveBattler, TRUE, FALSE); } static void LinkPartnerHandleHealthBarUpdate(void) diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 51a59ec56c..37dc2760e8 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -375,12 +375,6 @@ static void CompleteOnHealthbarDone(void) OpponentBufferExecCompleted(); } -static void CompleteOnInactiveTextPrinter(void) -{ - if (!IsTextPrinterActive(B_WIN_MSG)) - OpponentBufferExecCompleted(); -} - static void SwitchIn_ShowSubstitute(void) { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) @@ -704,15 +698,7 @@ static void OpponentDoMoveAnimation(void) static void OpponentHandlePrintString(void) { - u16 *stringId; - - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - stringId = (u16 *)(&gBattleResources->bufferA[gActiveBattler][2]); - BufferStringBattle(*stringId); - BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_MSG); - gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter; - BattleArena_DeductSkillPoints(gActiveBattler, *stringId); + BtlController_HandlePrintString(gActiveBattler, FALSE, TRUE); } static void OpponentHandleChooseAction(void) diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 39829c1feb..730e0b2688 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -87,7 +87,7 @@ static void WaitForMonSelection(void); static void CompleteWhenChoseItem(void); static void Task_LaunchLvlUpAnim(u8); static void Task_PrepareToGiveExpWithExpBar(u8); -static void DestroyExpTaskAndCompleteOnInactiveTextPrinter(u8); +static void Task_SetControllerToWaitForString(u8); static void Task_GiveExpWithExpBar(u8); static void Task_UpdateLvlInHealthbox(u8); static void PrintLinkStandbyMsg(void); @@ -1329,12 +1329,6 @@ static void CompleteOnHealthbarDone(void) } } -static void CompleteOnInactiveTextPrinter(void) -{ - if (!IsTextPrinterActive(B_WIN_MSG)) - PlayerBufferExecCompleted(); -} - #define tExpTask_monId data[0] #define tExpTask_battler data[2] #define tExpTask_gainedExp_1 data[3] @@ -1375,13 +1369,13 @@ static void Task_GiveExpToMon(u8 taskId) && (monId == gBattlerPartyIndexes[battlerId] || monId == gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)])) gTasks[taskId].func = Task_LaunchLvlUpAnim; else - gTasks[taskId].func = DestroyExpTaskAndCompleteOnInactiveTextPrinter; + gTasks[taskId].func = Task_SetControllerToWaitForString; } else { currExp += gainedExp; SetMonData(mon, MON_DATA_EXP, &currExp); - gBattlerControllerFuncs[battlerId] = CompleteOnInactiveTextPrinter; + gBattlerControllerFuncs[battlerId] = Controller_WaitForString; DestroyTask(taskId); } } @@ -1453,7 +1447,7 @@ static void Task_GiveExpWithExpBar(u8 taskId) { currExp += gainedExp; SetMonData(&gPlayerParty[monId], MON_DATA_EXP, &currExp); - gBattlerControllerFuncs[battlerId] = CompleteOnInactiveTextPrinter; + gBattlerControllerFuncs[battlerId] = Controller_WaitForString; DestroyTask(taskId); } } @@ -1485,23 +1479,17 @@ static void Task_UpdateLvlInHealthbox(u8 taskId) else UpdateHealthboxAttribute(gHealthboxSpriteIds[battlerId], &gPlayerParty[monIndex], HEALTHBOX_ALL); - gTasks[taskId].func = DestroyExpTaskAndCompleteOnInactiveTextPrinter; + gTasks[taskId].func = Task_SetControllerToWaitForString; } } -static void DestroyExpTaskAndCompleteOnInactiveTextPrinter(u8 taskId) +static void Task_SetControllerToWaitForString(u8 taskId) { u8 battlerId = gTasks[taskId].tExpTask_battler; - gBattlerControllerFuncs[battlerId] = CompleteOnInactiveTextPrinter; + gBattlerControllerFuncs[battlerId] = Controller_WaitForString; DestroyTask(taskId); } -static void CompleteOnInactiveTextPrinter2(void) -{ - if (!IsTextPrinterActive(B_WIN_MSG)) - PlayerBufferExecCompleted(); -} - static void OpenPartyMenuToChooseMon(void) { if (!gPaletteFade.active) @@ -1953,16 +1941,7 @@ static void PlayerDoMoveAnimation(void) static void PlayerHandlePrintString(void) { - u16 *stringId; - - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - stringId = (u16 *)(&gBattleResources->bufferA[gActiveBattler][2]); - BufferStringBattle(*stringId); - BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_MSG); - gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter2; - BattleTv_SetDataBasedOnString(*stringId); - BattleArena_DeductSkillPoints(gActiveBattler, *stringId); + BtlController_HandlePrintString(gActiveBattler, TRUE, TRUE); } static void PlayerHandlePrintSelectionString(void) diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index d4ce6f41b3..8da64af4e5 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -88,7 +88,7 @@ static void (*const sPlayerPartnerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = [CONTROLLER_CHOOSEPOKEMON] = PlayerPartnerHandleChoosePokemon, [CONTROLLER_23] = BtlController_Empty, [CONTROLLER_HEALTHBARUPDATE] = PlayerPartnerHandleHealthBarUpdate, - [CONTROLLER_EXPUPDATE] = PlayerHandleExpUpdate, + [CONTROLLER_EXPUPDATE] = PlayerHandleExpUpdate, // Partner's player gets experience the same way as the player. [CONTROLLER_STATUSICONUPDATE] = BtlController_HandleStatusIconUpdate, [CONTROLLER_STATUSANIMATION] = BtlController_HandleStatusAnimation, [CONTROLLER_STATUSXOR] = BtlController_Empty, @@ -250,18 +250,6 @@ static void CompleteOnHealthbarDone(void) } } -static void CompleteOnInactiveTextPrinter(void) -{ - if (!IsTextPrinterActive(B_WIN_MSG)) - PlayerPartnerBufferExecCompleted(); -} - -static void CompleteOnInactiveTextPrinter2(void) -{ - if (!IsTextPrinterActive(B_WIN_MSG)) - PlayerPartnerBufferExecCompleted(); -} - static void SwitchIn_ShowSubstitute(void) { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) @@ -488,14 +476,7 @@ static void PlayerPartnerDoMoveAnimation(void) static void PlayerPartnerHandlePrintString(void) { - u16 *stringId; - - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - stringId = (u16 *)(&gBattleResources->bufferA[gActiveBattler][2]); - BufferStringBattle(*stringId); - BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_MSG); - gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter2; + BtlController_HandlePrintString(gActiveBattler, FALSE, FALSE); } static void PlayerPartnerHandleChooseAction(void) diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index c238b30246..917a78473b 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -342,12 +342,6 @@ static void CompleteOnHealthbarDone(void) RecordedOpponentBufferExecCompleted(); } -static void CompleteOnInactiveTextPrinter(void) -{ - if (!IsTextPrinterActive(B_WIN_MSG)) - RecordedOpponentBufferExecCompleted(); -} - static void SwitchIn_ShowSubstitute(void) { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) @@ -591,7 +585,7 @@ static void RecordedOpponentHandlePrintString(void) } BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_MSG); - gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter; + gBattlerControllerFuncs[gActiveBattler] = Controller_WaitForString; } static void RecordedOpponentHandleChooseAction(void) diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index c6145a27f1..57a978546e 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -324,12 +324,6 @@ static void CompleteOnHealthbarDone(void) } } -static void CompleteOnInactiveTextPrinter(void) -{ - if (!IsTextPrinterActive(B_WIN_MSG)) - RecordedPlayerBufferExecCompleted(); -} - static void SwitchIn_ShowSubstitute(void) { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) @@ -588,7 +582,7 @@ static void RecordedPlayerHandlePrintString(void) } BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_MSG); - gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter; + gBattlerControllerFuncs[gActiveBattler] = Controller_WaitForString; } static void ChooseActionInBattlePalace(void) diff --git a/src/battle_controller_safari.c b/src/battle_controller_safari.c index e8c000d5d1..7252bfa403 100644 --- a/src/battle_controller_safari.c +++ b/src/battle_controller_safari.c @@ -192,12 +192,6 @@ static void CompleteOnBattlerSpriteCallbackDummy(void) SafariBufferExecCompleted(); } -static void CompleteOnInactiveTextPrinter(void) -{ - if (!IsTextPrinterActive(B_WIN_MSG)) - SafariBufferExecCompleted(); -} - static void CompleteOnHealthboxSpriteCallbackDummy(void) { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) @@ -287,14 +281,7 @@ static void SafariHandleBallThrowAnim(void) static void SafariHandlePrintString(void) { - u16 *stringId; - - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - stringId = (u16 *)(&gBattleResources->bufferA[gActiveBattler][2]); - BufferStringBattle(*stringId); - BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_MSG); - gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter; + BtlController_HandlePrintString(gActiveBattler, FALSE, FALSE); } static void SafariHandlePrintSelectionString(void) diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index 644e39455f..9633a3be80 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -212,12 +212,6 @@ static void CompleteOnBattlerSpriteCallbackDummy(void) WallyBufferExecCompleted(); } -static void CompleteOnInactiveTextPrinter(void) -{ - if (!IsTextPrinterActive(B_WIN_MSG)) - WallyBufferExecCompleted(); -} - static void OpenBagAfterPaletteFade(void) { if (!gPaletteFade.active) @@ -443,14 +437,7 @@ static void WallyDoMoveAnimation(void) static void WallyHandlePrintString(void) { - u16 *stringId; - - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - stringId = (u16 *)(&gBattleResources->bufferA[gActiveBattler][2]); - BufferStringBattle(*stringId); - BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_MSG); - gBattlerControllerFuncs[gActiveBattler] = CompleteOnInactiveTextPrinter; + BtlController_HandlePrintString(gActiveBattler, FALSE, FALSE); } static void WallyHandlePrintSelectionString(void) diff --git a/src/battle_controllers.c b/src/battle_controllers.c index d01cd5b4b4..7499ca91ad 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -1,6 +1,7 @@ #include "global.h" #include "battle.h" #include "battle_ai_main.h" +#include "battle_arena.h" #include "battle_anim.h" #include "battle_controllers.h" #include "battle_gfx_sfx_util.h" @@ -17,6 +18,7 @@ #include "sound.h" #include "task.h" #include "util.h" +#include "text.h" #include "constants/abilities.h" #include "constants/songs.h" @@ -2197,6 +2199,12 @@ static void Controller_WaitForStatusAnimation(void) BattleControllerComplete(gActiveBattler); } +void Controller_WaitForString(void) +{ + if (!IsTextPrinterActive(B_WIN_MSG)) + BattleControllerComplete(gActiveBattler); +} + static void Controller_HitAnimation(void) { u32 spriteId = gBattlerSpriteIds[gActiveBattler]; @@ -2419,6 +2427,22 @@ void BtlController_HandleBallThrowAnim(u32 battler, u32 target, u32 animId, bool HandleBallThrow(battler, target, animId, allowCriticalCapture); } +void BtlController_HandlePrintString(u32 battler, bool32 updateTvData, bool32 arenaPtsDeduct) +{ + u16 *stringId; + + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + stringId = (u16 *)(&gBattleResources->bufferA[battler][2]); + BufferStringBattle(*stringId); + BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_MSG); + gBattlerControllerFuncs[battler] = Controller_WaitForString; + if (updateTvData) + BattleTv_SetDataBasedOnString(*stringId); + if (arenaPtsDeduct) + BattleArena_DeductSkillPoints(battler, *stringId); +} + void DoStatusIconUpdate(u32 battler) { struct Pokemon *party = GetBattlerParty(battler);