From a9483c361bf69e75c8dae0efa937bcf8b41f75ec Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 6 Aug 2023 12:41:36 +0200 Subject: [PATCH] trainer intro ball throw --- include/battle_controllers.h | 6 +- src/battle_controller_link_opponent.c | 57 +------- src/battle_controller_link_partner.c | 153 ++------------------ src/battle_controller_opponent.c | 71 +-------- src/battle_controller_player.c | 101 +------------ src/battle_controller_player_partner.c | 90 ++---------- src/battle_controller_recorded_opponent.c | 57 +------- src/battle_controller_recorded_player.c | 70 +-------- src/battle_controller_safari.c | 8 +- src/battle_controller_wally.c | 52 +------ src/battle_controllers.c | 168 ++++++++++++++++++---- 11 files changed, 190 insertions(+), 643 deletions(-) diff --git a/include/battle_controllers.h b/include/battle_controllers.h index 6dbdb1431..2dab0d8e4 100644 --- a/include/battle_controllers.h +++ b/include/battle_controllers.h @@ -252,6 +252,7 @@ void BtlController_EmitResetActionMoveSelection(u8 bufferId, u8 caseId); void BtlController_EmitEndLinkBattle(u8 bufferId, u8 battleOutcome); void BtlController_EmitDebugMenu(u8 bufferId); +void BattleControllerComplete(u32 battler); // Can be used for all the controllers. 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); @@ -282,6 +283,9 @@ void BtlController_HandlePlayFanfareOrBGM(void); void BtlController_HandleFaintingCry(void); void BtlController_HandleIntroSlide(void); void BtlController_HandleSpriteInvisibility(void); +bool32 TwoPlayerIntroMons(u32 battlerId); // Double battle with both player pokemon active. +bool32 TwoOpponentIntroMons(u32 battlerId); // Double battle with both opponent pokemon active. +void BtlController_HandleIntroTrainerBallThrow(u32 battler, u16 tagTrainerPal, const u32 *trainerPal, s16 framesToWait, void (*controllerCallback)(void)); void BtlController_HandleDrawPartyStatusSummary(u32 battler, u32 side, bool32 considerDelay); void BtlController_HandleHidePartyStatusSummary(void); void BtlController_HandleBattleAnimation(u32 battler, bool32 ignoreSE, bool32 updateTvData); @@ -291,7 +295,6 @@ void SetControllerToPlayer(void); void BattleControllerDummy(void); void SetBattleEndCallbacks(void); void PlayerHandleExpUpdate(void); -void SpriteCB_FreePlayerSpriteLoadMonSprite(struct Sprite *sprite); void CB2_SetUpReshowBattleScreenAfterMenu(void); void CB2_SetUpReshowBattleScreenAfterMenu2(void); void Task_PlayerController_RestoreBgmAfterCry(u8 taskId); @@ -308,6 +311,7 @@ void SetControllerToRecordedPlayer(void); void SetControllerToOpponent(void); // player partner controller +void Controller_PlayerPartnerShowIntroHealthbox(void); // Also used by the link partner. void SetControllerToPlayerPartner(void); // safari controller diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index a003387ed..9b3432170 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -49,8 +49,6 @@ static void SwitchIn_HandleSoundAndEnd(void); static u32 CopyLinkOpponentMonData(u8 monId, u8 *dst); static void SetLinkOpponentMonData(u8 monId); static void LinkOpponentDoMoveAnimation(void); -static void Task_StartSendOutAnim(u8 taskId); -static void SpriteCB_FreeOpponentSprite(struct Sprite *sprite); static void (*const sLinkOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void) = { @@ -114,10 +112,6 @@ static void (*const sLinkOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void) = [CONTROLLER_TERMINATOR_NOP] = BtlController_TerminatorNop }; -static void LinkOpponentDummy(void) -{ -} - void SetControllerToLinkOpponent(void) { gBattlerControllerEndFuncs[gActiveBattler] = LinkOpponentBufferExecCompleted; @@ -661,56 +655,7 @@ static void LinkOpponentHandleHealthBarUpdate(void) static void LinkOpponentHandleIntroTrainerBallThrow(void) { - u8 taskId; - - SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - - gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = 35; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[2] = 280; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[4] = gSprites[gBattlerSpriteIds[gActiveBattler]].y; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = StartAnimLinearTranslation; - - StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[gActiveBattler]], SpriteCB_FreeOpponentSprite); - - taskId = CreateTask(Task_StartSendOutAnim, 5); - gTasks[taskId].data[0] = gActiveBattler; - - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; - - gBattleSpritesDataPtr->animationData->introAnimActive = TRUE; - gBattlerControllerFuncs[gActiveBattler] = LinkOpponentDummy; -} - -static void Task_StartSendOutAnim(u8 taskId) -{ - u8 savedActiveBank = gActiveBattler; - - gActiveBattler = gTasks[taskId].data[0]; - if (!IsDoubleBattle() || (gBattleTypeFlags & BATTLE_TYPE_MULTI)) - { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - } - else - { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler = BATTLE_PARTNER(gActiveBattler); - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler = BATTLE_PARTNER(gActiveBattler); - } - gBattlerControllerFuncs[gActiveBattler] = Intro_TryShinyAnimShowHealthbox; - gActiveBattler = savedActiveBank; - DestroyTask(taskId); -} - -static void SpriteCB_FreeOpponentSprite(struct Sprite *sprite) -{ - FreeTrainerFrontPicPalette(sprite->oam.affineParam); - FreeSpriteOamMatrix(sprite); - DestroySprite(sprite); + BtlController_HandleIntroTrainerBallThrow(gActiveBattler, 0, NULL, 0, Intro_TryShinyAnimShowHealthbox); } static void LinkOpponentHandleDrawPartyStatusSummary(void) diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index 7f9e382af..689316d44 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -112,10 +112,6 @@ static void (*const sLinkPartnerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = [CONTROLLER_TERMINATOR_NOP] = BtlController_TerminatorNop }; -static void SpriteCB_Null2(void) -{ -} - void SetControllerToLinkPartner(void) { gBattlerControllerEndFuncs[gActiveBattler] = LinkPartnerBufferExecCompleted; @@ -150,72 +146,6 @@ static void FreeTrainerSpriteAfterSlide(void) } } -static void Intro_DelayAndEnd(void) -{ - if (--gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay == (u8)-1) - { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay = 0; - LinkPartnerBufferExecCompleted(); - } -} - -static void Intro_WaitForHealthbox(void) -{ - bool32 finished = FALSE; - - if (!IsDoubleBattle() || (IsDoubleBattle() && (gBattleTypeFlags & BATTLE_TYPE_MULTI))) - { - if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) - finished = TRUE; - } - else - { - if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy - && gSprites[gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]].callback == SpriteCallbackDummy) - { - finished = TRUE; - } - } - - if (IsCryPlayingOrClearCrySongs()) - finished = FALSE; - - if (finished) - { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay = 3; - gBattlerControllerFuncs[gActiveBattler] = Intro_DelayAndEnd; - } -} - -static void Intro_ShowHealthbox(void) -{ - if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive - && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].ballAnimActive - && gSprites[gBattleControllerData[gActiveBattler]].callback == SpriteCallbackDummy - && gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy - && ++gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay != 1) - { - gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay = 0; - - if (IsDoubleBattle() && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) - { - DestroySprite(&gSprites[gBattleControllerData[BATTLE_PARTNER(gActiveBattler)]]); - UpdateHealthboxAttribute(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)], &gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]], HEALTHBOX_ALL); - StartHealthboxSlideIn(BATTLE_PARTNER(gActiveBattler)); - SetHealthboxSpriteVisible(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]); - } - - DestroySprite(&gSprites[gBattleControllerData[gActiveBattler]]); - UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler], &gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], HEALTHBOX_ALL); - StartHealthboxSlideIn(gActiveBattler); - SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler]); - - gBattleSpritesDataPtr->animationData->introAnimActive = FALSE; - - gBattlerControllerFuncs[gActiveBattler] = Intro_WaitForHealthbox; - } -} - static void WaitForMonAnimAfterLoad(void) { if (gSprites[gBattlerSpriteIds[gActiveBattler]].animEnded && gSprites[gBattlerSpriteIds[gActiveBattler]].x2 == 0) @@ -482,82 +412,23 @@ static void LinkPartnerHandleHealthBarUpdate(void) static void LinkPartnerHandleIntroTrainerBallThrow(void) { - u8 paletteNum; - u8 taskId; u32 trainerPicId; + u8 gameVersion, playerGender; + const u32 *trainerPal; - SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[gActiveBattler]]); + gameVersion = gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].version & 0xFF; + playerGender = gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].gender; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = 50; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[2] = -40; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[4] = gSprites[gBattlerSpriteIds[gActiveBattler]].y; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = StartAnimLinearTranslation; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[5] = gActiveBattler; - - StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[gActiveBattler]], SpriteCB_FreePlayerSpriteLoadMonSprite); - StartSpriteAnim(&gSprites[gBattlerSpriteIds[gActiveBattler]], 1); - - paletteNum = AllocSpritePalette(0xD6F9); - - if ((gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].version & 0xFF) == VERSION_FIRE_RED - || (gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].version & 0xFF) == VERSION_LEAF_GREEN) - { - trainerPicId = gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].gender + TRAINER_BACK_PIC_RED; - } - else if ((gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].version & 0xFF) == VERSION_RUBY - || (gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].version & 0xFF) == VERSION_SAPPHIRE) - { - trainerPicId = gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].gender + TRAINER_BACK_PIC_RUBY_SAPPHIRE_BRENDAN; - } + if (gameVersion == VERSION_FIRE_RED || gameVersion == VERSION_LEAF_GREEN) + trainerPicId = playerGender + TRAINER_BACK_PIC_RED; + else if (gameVersion == VERSION_RUBY || gameVersion == VERSION_SAPPHIRE) + trainerPicId = playerGender + TRAINER_BACK_PIC_RUBY_SAPPHIRE_BRENDAN; else - { - trainerPicId = gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].gender; - } + trainerPicId = playerGender + TRAINER_BACK_PIC_BRENDAN; - LoadCompressedPalette(gTrainerBackPicPaletteTable[trainerPicId].data, OBJ_PLTT_ID(paletteNum), PLTT_SIZE_4BPP); - - gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = paletteNum; - - taskId = CreateTask(Task_StartSendOutAnim, 5); - gTasks[taskId].data[0] = gActiveBattler; - - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; - - gBattleSpritesDataPtr->animationData->introAnimActive = TRUE; - gBattlerControllerFuncs[gActiveBattler] = SpriteCB_Null2; -} - -static void Task_StartSendOutAnim(u8 taskId) -{ - if (gTasks[taskId].data[1] < 24) - { - gTasks[taskId].data[1]++; - } - else - { - u8 savedActiveBank = gActiveBattler; - - gActiveBattler = gTasks[taskId].data[0]; - if (!IsDoubleBattle() || (gBattleTypeFlags & BATTLE_TYPE_MULTI)) - { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - } - else - { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler ^= BIT_FLANK; - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - BattleLoadMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler ^= BIT_FLANK; - } - gBattlerControllerFuncs[gActiveBattler] = Intro_ShowHealthbox; - gActiveBattler = savedActiveBank; - DestroyTask(taskId); - } + trainerPal = gTrainerBackPicPaletteTable[trainerPicId].data; + // Link partner uses the same intro sequence as the player partner. + BtlController_HandleIntroTrainerBallThrow(gActiveBattler, 0xD6F9, trainerPal, 24, Controller_PlayerPartnerShowIntroHealthbox); } static void LinkPartnerHandleDrawPartyStatusSummary(void) diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 145fe81f7..43be340f0 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -128,10 +128,6 @@ static void (*const sOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void) = [CONTROLLER_TERMINATOR_NOP] = BtlController_TerminatorNop }; -static void OpponentDummy(void) -{ -} - void SetControllerToOpponent(void) { gBattlerControllerEndFuncs[gActiveBattler] = OpponentBufferExecCompleted; @@ -181,19 +177,12 @@ static void Intro_DelayAndEnd(void) } } -static bool32 TwoIntroMons(u32 battlerId) // Double battle with both opponent pokemon active. -{ - return (IsDoubleBattle() - && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[battlerId]]) - && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)]])); -} - static void Intro_WaitForShinyAnimAndHealthbox(void) { bool8 healthboxAnimDone = FALSE; bool8 twoMons; - twoMons = TwoIntroMons(gActiveBattler); + twoMons = TwoOpponentIntroMons(gActiveBattler); if (!twoMons || ((twoMons && (gBattleTypeFlags & BATTLE_TYPE_MULTI) && !BATTLE_TWO_VS_ONE_OPPONENT) || (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS))) { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) @@ -263,7 +252,7 @@ static void Intro_TryShinyAnimShowHealthbox(void) && !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].finishedShinyMonAnim) TryShinyAnimation(gActiveBattler, &gEnemyParty[gBattlerPartyIndexes[gActiveBattler]]); - twoMons = TwoIntroMons(gActiveBattler); + twoMons = TwoOpponentIntroMons(gActiveBattler); if (!(gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) && (!(gBattleTypeFlags & BATTLE_TYPE_MULTI) || BATTLE_TWO_VS_ONE_OPPONENT) && twoMons @@ -928,61 +917,7 @@ static void OpponentHandleHealthBarUpdate(void) static void OpponentHandleIntroTrainerBallThrow(void) { - u8 taskId; - - SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - - gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = 35; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[2] = 280; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[4] = gSprites[gBattlerSpriteIds[gActiveBattler]].y; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = StartAnimLinearTranslation; - - StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[gActiveBattler]], SpriteCB_FreeOpponentSprite); - - taskId = CreateTask(Task_StartSendOutAnim, 5); - gTasks[taskId].data[0] = gActiveBattler; - - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; - - gBattleSpritesDataPtr->animationData->introAnimActive = TRUE; - gBattlerControllerFuncs[gActiveBattler] = OpponentDummy; -} - -static void SpriteCB_FreeOpponentSprite(struct Sprite *sprite) -{ - FreeTrainerFrontPicPalette(sprite->oam.affineParam); - FreeSpriteOamMatrix(sprite); - DestroySprite(sprite); -} - -static void Task_StartSendOutAnim(u8 taskId) -{ - u8 savedActiveBattler = gActiveBattler; - - gActiveBattler = gTasks[taskId].data[0]; - if ((!TwoIntroMons(gActiveBattler) || (gBattleTypeFlags & BATTLE_TYPE_MULTI)) && !BATTLE_TWO_VS_ONE_OPPONENT) - { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - } - else if ((gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) || (BATTLE_TWO_VS_ONE_OPPONENT && !TwoIntroMons(gActiveBattler))) - { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - } - else - { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler ^= BIT_FLANK; - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler ^= BIT_FLANK; - } - gBattlerControllerFuncs[gActiveBattler] = Intro_TryShinyAnimShowHealthbox; - gActiveBattler = savedActiveBattler; - DestroyTask(taskId); + BtlController_HandleIntroTrainerBallThrow(gActiveBattler, 0, NULL, 0, Intro_TryShinyAnimShowHealthbox); } static void OpponentHandleDrawPartyStatusSummary(void) diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 21a58a93c..d8a115722 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -1119,17 +1119,12 @@ static void Intro_DelayAndEnd(void) } } -static bool32 TwoIntroMons(u32 battlerId) // Double battle with both player pokemon active. -{ - return (IsDoubleBattle() && IsValidForBattle(&gPlayerParty[gBattlerPartyIndexes[battlerId ^ BIT_FLANK]])); -} - static void Intro_WaitForShinyAnimAndHealthbox(void) { bool8 healthboxAnimDone = FALSE; // Check if healthbox has finished sliding in - if (TwoIntroMons(gActiveBattler) && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) + if (TwoPlayerIntroMons(gActiveBattler) && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy && gSprites[gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)]].callback == SpriteCallbackDummy) @@ -1155,7 +1150,7 @@ static void Intro_WaitForShinyAnimAndHealthbox(void) HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); - if (TwoIntroMons(gActiveBattler)) + if (TwoPlayerIntroMons(gActiveBattler)) HandleLowHpMusicChange(&gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]], BATTLE_PARTNER(gActiveBattler)); gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay = 3; @@ -1184,7 +1179,7 @@ static void Intro_TryShinyAnimShowHealthbox(void) { if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].healthboxSlideInStarted) { - if (TwoIntroMons(gActiveBattler) && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) + if (TwoPlayerIntroMons(gActiveBattler) && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) { UpdateHealthboxAttribute(gHealthboxSpriteIds[BATTLE_PARTNER(gActiveBattler)], &gPlayerParty[gBattlerPartyIndexes[BATTLE_PARTNER(gActiveBattler)]], HEALTHBOX_ALL); StartHealthboxSlideIn(BATTLE_PARTNER(gActiveBattler)); @@ -1215,7 +1210,7 @@ static void Intro_TryShinyAnimShowHealthbox(void) } // Wait for battler anims - if (TwoIntroMons(gActiveBattler) && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) + if (TwoPlayerIntroMons(gActiveBattler) && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) { if (gSprites[gBattleControllerData[gActiveBattler]].callback == SpriteCallbackDummy && gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy @@ -1237,7 +1232,7 @@ static void Intro_TryShinyAnimShowHealthbox(void) // Clean up if (bgmRestored && battlerAnimsDone) { - if (TwoIntroMons(gActiveBattler) && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) + if (TwoPlayerIntroMons(gActiveBattler) && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) DestroySprite(&gSprites[gBattleControllerData[BATTLE_PARTNER(gActiveBattler)]]); DestroySprite(&gSprites[gBattleControllerData[gActiveBattler]]); @@ -2219,94 +2214,12 @@ static void PlayerHandleOneReturnValue_Duplicate(void) PlayerBufferExecCompleted(); } -// Task data for Task_StartSendOutAnim -#define tBattlerId data[0] -#define tStartTimer data[1] - -#define sBattlerId data[5] - static void PlayerHandleIntroTrainerBallThrow(void) { - u8 paletteNum; - u8 taskId; - - SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - - gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = 50; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[2] = -40; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[4] = gSprites[gBattlerSpriteIds[gActiveBattler]].y; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = StartAnimLinearTranslation; - gSprites[gBattlerSpriteIds[gActiveBattler]].sBattlerId = gActiveBattler; - - StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[gActiveBattler]], SpriteCB_FreePlayerSpriteLoadMonSprite); - StartSpriteAnim(&gSprites[gBattlerSpriteIds[gActiveBattler]], 1); - - paletteNum = AllocSpritePalette(0xD6F8); - LoadCompressedPalette(gTrainerBackPicPaletteTable[gSaveBlock2Ptr->playerGender].data, OBJ_PLTT_ID(paletteNum), PLTT_SIZE_4BPP); - gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = paletteNum; - - taskId = CreateTask(Task_StartSendOutAnim, 5); - gTasks[taskId].tBattlerId = gActiveBattler; - - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; - - gBattleSpritesDataPtr->animationData->introAnimActive = TRUE; - gBattlerControllerFuncs[gActiveBattler] = BattleControllerDummy; + const u32 *trainerPal = gTrainerBackPicPaletteTable[gSaveBlock2Ptr->playerGender].data; + BtlController_HandleIntroTrainerBallThrow(gActiveBattler, 0xD6F8, trainerPal, 31, Intro_TryShinyAnimShowHealthbox); } -void SpriteCB_FreePlayerSpriteLoadMonSprite(struct Sprite *sprite) -{ - u8 battlerId = sprite->sBattlerId; - - // Free player trainer sprite - FreeSpriteOamMatrix(sprite); - FreeSpritePaletteByTag(GetSpritePaletteTagByPaletteNum(sprite->oam.paletteNum)); - DestroySprite(sprite); - - // Load mon sprite - BattleLoadMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[battlerId]], battlerId); - StartSpriteAnim(&gSprites[gBattlerSpriteIds[battlerId]], 0); -} - -#undef sBattlerId - -// Send out at start of battle -static void Task_StartSendOutAnim(u8 taskId) -{ - if (gTasks[taskId].tStartTimer < 31) - { - gTasks[taskId].tStartTimer++; - } - else - { - u8 savedActiveBattler = gActiveBattler; - - gActiveBattler = gTasks[taskId].tBattlerId; - if (TwoIntroMons(gActiveBattler) && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) - { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler ^= BIT_FLANK; - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - BattleLoadMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler ^= BIT_FLANK; - } - else - { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - } - gBattlerControllerFuncs[gActiveBattler] = Intro_TryShinyAnimShowHealthbox; - gActiveBattler = savedActiveBattler; - DestroyTask(taskId); - } -} - -#undef tBattlerId -#undef tStartTimer - static void PlayerHandleDrawPartyStatusSummary(void) { BtlController_HandleDrawPartyStatusSummary(gActiveBattler, B_SIDE_PLAYER, TRUE); diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index 8676ecade..ea16351f3 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -121,10 +121,6 @@ static void (*const sPlayerPartnerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = [CONTROLLER_TERMINATOR_NOP] = BtlController_TerminatorNop }; -static void PlayerPartnerDummy(void) -{ -} - void SetControllerToPlayerPartner(void) { gBattlerControllerEndFuncs[gActiveBattler] = PlayerPartnerBufferExecCompleted; @@ -164,7 +160,7 @@ static void Intro_DelayAndEnd(void) if (--gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay == (u8)-1) { gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay = 0; - PlayerPartnerBufferExecCompleted(); + BattleControllerComplete(gActiveBattler); } } @@ -196,7 +192,8 @@ static void Intro_WaitForHealthbox(void) } } -static void Intro_ShowHealthbox(void) +// Also used by the link partner. +void Controller_PlayerPartnerShowIntroHealthbox(void) { if (!gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].ballAnimActive && !gBattleSpritesDataPtr->healthBoxesData[BATTLE_PARTNER(gActiveBattler)].ballAnimActive @@ -569,87 +566,18 @@ static void PlayerPartnerHandleHealthBarUpdate(void) gBattlerControllerFuncs[gActiveBattler] = CompleteOnHealthbarDone; } -#undef tExpTask_monId -#undef tExpTask_gainedExp -#undef tExpTask_bank -#undef tExpTask_frames - static void PlayerPartnerHandleIntroTrainerBallThrow(void) { - u8 paletteNum; - u8 taskId; + const u32 *trainerPal; - SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - - gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = 50; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[2] = -40; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[4] = gSprites[gBattlerSpriteIds[gActiveBattler]].y; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = StartAnimLinearTranslation; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[5] = gActiveBattler; - - StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[gActiveBattler]], SpriteCB_FreePlayerSpriteLoadMonSprite); - StartSpriteAnim(&gSprites[gBattlerSpriteIds[gActiveBattler]], 1); - - paletteNum = AllocSpritePalette(0xD6F9); if (gPartnerTrainerId == TRAINER_STEVEN_PARTNER) - { - u8 spriteId = TRAINER_BACK_PIC_STEVEN; - LoadCompressedPalette(gTrainerBackPicPaletteTable[spriteId].data, OBJ_PLTT_ID(paletteNum), PLTT_SIZE_4BPP); - } - else if (gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER) - { - u8 spriteId = gPartnerSpriteId; - LoadCompressedPalette(gTrainerBackPicPaletteTable[spriteId].data, 0x100 + paletteNum * 16, 32); - } + trainerPal = gTrainerBackPicPaletteTable[TRAINER_STEVEN_PARTNER].data; + else if (gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER) // Custom multi battle. + trainerPal = gTrainerBackPicPaletteTable[gPartnerSpriteId].data; else - { - u8 spriteId = GetFrontierTrainerFrontSpriteId(gPartnerTrainerId); - LoadCompressedPalette(gTrainerFrontPicPaletteTable[spriteId].data, OBJ_PLTT_ID(paletteNum), PLTT_SIZE_4BPP); - } + trainerPal = gTrainerFrontPicPaletteTable[GetFrontierTrainerFrontSpriteId(gPartnerTrainerId)].data; // 2 vs 2 multi battle in Battle Frontier, load front sprite and pal. - - gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = paletteNum; - - taskId = CreateTask(Task_StartSendOutAnim, 5); - gTasks[taskId].data[0] = gActiveBattler; - - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; - - gBattleSpritesDataPtr->animationData->introAnimActive = TRUE; - gBattlerControllerFuncs[gActiveBattler] = PlayerPartnerDummy; -} - -static void Task_StartSendOutAnim(u8 taskId) -{ - if (gTasks[taskId].data[1] < 24) - { - gTasks[taskId].data[1]++; - } - else - { - u8 savedActiveBank = gActiveBattler; - - gActiveBattler = gTasks[taskId].data[0]; - if (!IsDoubleBattle() || (gBattleTypeFlags & BATTLE_TYPE_MULTI)) - { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - } - else - { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler ^= BIT_FLANK; - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - BattleLoadMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler ^= BIT_FLANK; - } - gBattlerControllerFuncs[gActiveBattler] = Intro_ShowHealthbox; - gActiveBattler = savedActiveBank; - DestroyTask(taskId); - } + BtlController_HandleIntroTrainerBallThrow(gActiveBattler, 0xD6F9, trainerPal, 24, Controller_PlayerPartnerShowIntroHealthbox); } static void PlayerPartnerHandleDrawPartyStatusSummary(void) diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index ce2d667ee..17fcb3b1c 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -56,8 +56,6 @@ static void SwitchIn_HandleSoundAndEnd(void); static u32 CopyRecordedOpponentMonData(u8 monId, u8 *dst); static void SetRecordedOpponentMonData(u8 monId); static void RecordedOpponentDoMoveAnimation(void); -static void Task_StartSendOutAnim(u8 taskId); -static void SpriteCB_FreeOpponentSprite(struct Sprite *sprite); static void EndDrawPartyStatusSummary(void); static void (*const sRecordedOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void) = @@ -122,10 +120,6 @@ static void (*const sRecordedOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void [CONTROLLER_TERMINATOR_NOP] = BtlController_TerminatorNop }; -static void RecordedOpponentDummy(void) -{ -} - void SetControllerToRecordedOpponent(void) { gBattlerControllerEndFuncs[gActiveBattler] = RecordedOpponentBufferExecCompleted; @@ -670,56 +664,7 @@ static void RecordedOpponentHandleStatusAnimation(void) static void RecordedOpponentHandleIntroTrainerBallThrow(void) { - u8 taskId; - - SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - - gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = 35; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[2] = 280; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[4] = gSprites[gBattlerSpriteIds[gActiveBattler]].y; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = StartAnimLinearTranslation; - - StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[gActiveBattler]], SpriteCB_FreeOpponentSprite); - - taskId = CreateTask(Task_StartSendOutAnim, 5); - gTasks[taskId].data[0] = gActiveBattler; - - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; - - gBattleSpritesDataPtr->animationData->introAnimActive = TRUE; - gBattlerControllerFuncs[gActiveBattler] = RecordedOpponentDummy; -} - -static void Task_StartSendOutAnim(u8 taskId) -{ - u8 savedActiveBank = gActiveBattler; - - gActiveBattler = gTasks[taskId].data[0]; - if (!IsDoubleBattle() || (gBattleTypeFlags & BATTLE_TYPE_MULTI)) - { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - } - else - { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler ^= BIT_FLANK; - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler ^= BIT_FLANK; - } - gBattlerControllerFuncs[gActiveBattler] = Intro_TryShinyAnimShowHealthbox; - gActiveBattler = savedActiveBank; - DestroyTask(taskId); -} - -static void SpriteCB_FreeOpponentSprite(struct Sprite *sprite) -{ - FreeTrainerFrontPicPalette(sprite->oam.affineParam); - FreeSpriteOamMatrix(sprite); - DestroySprite(sprite); + BtlController_HandleIntroTrainerBallThrow(gActiveBattler, 0, NULL, 0, Intro_TryShinyAnimShowHealthbox); } static void RecordedOpponentHandleDrawPartyStatusSummary(void) diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index d18b17fd5..fc35735b2 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -27,6 +27,7 @@ #include "window.h" #include "constants/battle_anim.h" #include "constants/songs.h" +#include "constants/trainers.h" static void RecordedPlayerHandleLoadMonSprite(void); static void RecordedPlayerHandleSwitchInAnim(void); @@ -116,10 +117,6 @@ static void (*const sRecordedPlayerBufferCommands[CONTROLLER_CMDS_COUNT])(void) [CONTROLLER_TERMINATOR_NOP] = BtlController_TerminatorNop }; -static void RecordedPlayerDummy(void) -{ -} - void SetControllerToRecordedPlayer(void) { gBattlerControllerEndFuncs[gActiveBattler] = RecordedPlayerBufferExecCompleted; @@ -683,71 +680,16 @@ static void RecordedPlayerHandleStatusAnimation(void) static void RecordedPlayerHandleIntroTrainerBallThrow(void) { - u8 paletteNum; - u8 taskId; u32 trainerPicId; + const u32 *trainerPal; - SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - - gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = 50; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[2] = -40; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[4] = gSprites[gBattlerSpriteIds[gActiveBattler]].y; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = StartAnimLinearTranslation; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[5] = gActiveBattler; - - StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[gActiveBattler]], SpriteCB_FreePlayerSpriteLoadMonSprite); - StartSpriteAnim(&gSprites[gBattlerSpriteIds[gActiveBattler]], 1); - - paletteNum = AllocSpritePalette(0xD6F9); if (gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK) - trainerPicId = gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].gender; + trainerPicId = gLinkPlayers[GetBattlerMultiplayerId(gActiveBattler)].gender + TRAINER_BACK_PIC_BRENDAN; else - trainerPicId = gSaveBlock2Ptr->playerGender; + trainerPicId = gSaveBlock2Ptr->playerGender + TRAINER_BACK_PIC_BRENDAN; - LoadCompressedPalette(gTrainerBackPicPaletteTable[trainerPicId].data, OBJ_PLTT_ID(paletteNum), PLTT_SIZE_4BPP); - - gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = paletteNum; - - taskId = CreateTask(Task_StartSendOutAnim, 5); - gTasks[taskId].data[0] = gActiveBattler; - - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; - - gBattleSpritesDataPtr->animationData->introAnimActive = TRUE; - gBattlerControllerFuncs[gActiveBattler] = RecordedPlayerDummy; -} - -static void Task_StartSendOutAnim(u8 taskId) -{ - if (gTasks[taskId].data[1] < 24) - { - gTasks[taskId].data[1]++; - } - else - { - u8 savedActiveBank = gActiveBattler; - - gActiveBattler = gTasks[taskId].data[0]; - if (!IsDoubleBattle() || (gBattleTypeFlags & BATTLE_TYPE_MULTI)) - { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - } - else - { - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler ^= BIT_FLANK; - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - BattleLoadMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); - StartSendOutAnim(gActiveBattler, FALSE); - gActiveBattler ^= BIT_FLANK; - } - gBattlerControllerFuncs[gActiveBattler] = Intro_TryShinyAnimShowHealthbox; - gActiveBattler = savedActiveBank; - DestroyTask(taskId); - } + trainerPal = gTrainerFrontPicPaletteTable[trainerPicId].data; + BtlController_HandleIntroTrainerBallThrow(gActiveBattler, 0xD6F9, trainerPal, 24, Intro_TryShinyAnimShowHealthbox); } static void RecordedPlayerHandleDrawPartyStatusSummary(void) diff --git a/src/battle_controller_safari.c b/src/battle_controller_safari.c index a8761b1b3..24d4abf82 100644 --- a/src/battle_controller_safari.c +++ b/src/battle_controller_safari.c @@ -185,13 +185,13 @@ static void HandleInputChooseAction(void) } } -static void CompleteOnBattlerSpriteCallbackDummy(void) +static void Controller_WaitForTrainerPic(void) { if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) SafariBufferExecCompleted(); } -static void CompleteOnHealthboxSpriteCallbackDummy(void) +static void Controller_WaitForHealthbox(void) { if (gSprites[gHealthboxSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) SafariBufferExecCompleted(); @@ -263,7 +263,7 @@ static void SafariHandleDrawTrainerPic(void) gSprites[gBattlerSpriteIds[gActiveBattler]].x2 = DISPLAY_WIDTH; gSprites[gBattlerSpriteIds[gActiveBattler]].sSpeedX = -2; gSprites[gBattlerSpriteIds[gActiveBattler]].callback = SpriteCB_TrainerSlideIn; - gBattlerControllerFuncs[gActiveBattler] = CompleteOnBattlerSpriteCallbackDummy; + gBattlerControllerFuncs[gActiveBattler] = Controller_WaitForTrainerPic; } #undef sSpeedX @@ -344,7 +344,7 @@ static void SafariHandleIntroTrainerBallThrow(void) UpdateHealthboxAttribute(gHealthboxSpriteIds[gActiveBattler], &gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], HEALTHBOX_SAFARI_ALL_TEXT); StartHealthboxSlideIn(gActiveBattler); SetHealthboxSpriteVisible(gHealthboxSpriteIds[gActiveBattler]); - gBattlerControllerFuncs[gActiveBattler] = CompleteOnHealthboxSpriteCallbackDummy; + gBattlerControllerFuncs[gActiveBattler] = Controller_WaitForHealthbox; } static void SafariHandleBattleAnimation(void) diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index 37aaf93fb..9376e1e69 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -57,7 +57,6 @@ static void Intro_WaitForShinyAnimAndHealthbox(void); static u32 CopyWallyMonData(u8 monId, u8 *dst); static void SetWallyMonData(u8 monId); static void WallyDoMoveAnimation(void); -static void Task_StartSendOutAnim(u8 taskId); static void (*const sWallyBufferCommands[CONTROLLER_CMDS_COUNT])(void) = { @@ -121,10 +120,6 @@ static void (*const sWallyBufferCommands[CONTROLLER_CMDS_COUNT])(void) = [CONTROLLER_TERMINATOR_NOP] = BtlController_TerminatorNop }; -static void SpriteCB_Null7(void) -{ -} - void SetControllerToWally(void) { gBattlerControllerEndFuncs[gActiveBattler] = WallyBufferExecCompleted; @@ -551,51 +546,8 @@ static void WallyHandleFaintingCry(void) static void WallyHandleIntroTrainerBallThrow(void) { - u8 paletteNum; - u8 taskId; - - SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - - gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = 50; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[2] = -40; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[4] = gSprites[gBattlerSpriteIds[gActiveBattler]].y; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = StartAnimLinearTranslation; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[5] = gActiveBattler; - - StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[gActiveBattler]], SpriteCB_FreePlayerSpriteLoadMonSprite); - StartSpriteAnim(&gSprites[gBattlerSpriteIds[gActiveBattler]], 1); - - paletteNum = AllocSpritePalette(0xD6F8); - LoadCompressedPalette(gTrainerBackPicPaletteTable[TRAINER_BACK_PIC_WALLY].data, OBJ_PLTT_ID(paletteNum), PLTT_SIZE_4BPP); - gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = paletteNum; - - taskId = CreateTask(Task_StartSendOutAnim, 5); - gTasks[taskId].data[0] = gActiveBattler; - - if (gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].partyStatusSummaryShown) - gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; - - gBattleSpritesDataPtr->animationData->introAnimActive = TRUE; - gBattlerControllerFuncs[gActiveBattler] = BattleControllerDummy; -} - -static void Task_StartSendOutAnim(u8 taskId) -{ - if (gTasks[taskId].data[1] < 31) - { - gTasks[taskId].data[1]++; - } - else - { - u8 savedActiveBank = gActiveBattler; - - gActiveBattler = gTasks[taskId].data[0]; - gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; - StartSendOutAnim(gActiveBattler, FALSE); - gBattlerControllerFuncs[gActiveBattler] = Intro_TryShinyAnimShowHealthbox; - gActiveBattler = savedActiveBank; - DestroyTask(taskId); - } + const u32 *trainerPal = gTrainerBackPicPaletteTable[TRAINER_BACK_PIC_WALLY].data; + BtlController_HandleIntroTrainerBallThrow(gActiveBattler, 0xD6F8, trainerPal, 31, Intro_TryShinyAnimShowHealthbox); } static void WallyHandleDrawPartyStatusSummary(void) diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 4d6367f9e..c321ef7a3 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -12,6 +12,7 @@ #include "cable_club.h" #include "link.h" #include "link_rfu.h" +#include "palette.h" #include "party_menu.h" #include "recorded_battle.h" #include "string_util.h" @@ -34,6 +35,9 @@ static void InitSinglePlayerBtlControllers(void); static void SetBattlePartyIds(void); static void Task_HandleSendLinkBuffersData(u8 taskId); static void Task_HandleCopyReceivedLinkBuffersData(u8 taskId); +static void Task_StartSendOutAnim(u8 taskId); +static void SpriteCB_FreePlayerSpriteLoadMonSprite(struct Sprite *sprite); +static void SpriteCB_FreeOpponentSprite(struct Sprite *sprite); void HandleLinkBattleSetup(void) { @@ -2578,7 +2582,136 @@ void BtlController_HandleSpriteInvisibility(void) BattleControllerComplete(gActiveBattler); } -void SpriteCB_FreePlayerSpriteLoadMonSprite(struct Sprite *sprite) +bool32 TwoPlayerIntroMons(u32 battlerId) // Double battle with both player pokemon active. +{ + return (IsDoubleBattle() && IsValidForBattle(&gPlayerParty[gBattlerPartyIndexes[battlerId ^ BIT_FLANK]])); +} + +bool32 TwoOpponentIntroMons(u32 battlerId) // Double battle with both opponent pokemon active. +{ + return (IsDoubleBattle() + && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[battlerId]]) + && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)]])); +} + +// Task data for Task_StartSendOutAnim +#define tBattlerId data[0] +#define tStartTimer data[1] +#define tFramesToWait data[2] +#define tControllerFunc_1 3 // Stored as two halfwords +#define tControllerFunc_2 4 + +// Sprite data for SpriteCB_FreePlayerSpriteLoadMonSprite +#define sBattlerId data[5] + +void BtlController_HandleIntroTrainerBallThrow(u32 battler, u16 tagTrainerPal, const u32 *trainerPal, s16 framesToWait, void (*controllerCallback)(void)) +{ + u8 paletteNum, taskId; + u32 side = GetBattlerSide(battler); + + SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[battler]]); + if (side == B_SIDE_PLAYER) + { + gSprites[gBattlerSpriteIds[battler]].data[0] = 50; + gSprites[gBattlerSpriteIds[battler]].data[2] = -40; + } + else + { + gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = 35; + gSprites[gBattlerSpriteIds[gActiveBattler]].data[2] = 280; + } + + gSprites[gBattlerSpriteIds[battler]].data[4] = gSprites[gBattlerSpriteIds[battler]].y; + gSprites[gBattlerSpriteIds[battler]].callback = StartAnimLinearTranslation; + gSprites[gBattlerSpriteIds[battler]].sBattlerId = battler; + + if (side == B_SIDE_PLAYER) + { + StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[battler]], SpriteCB_FreePlayerSpriteLoadMonSprite); + StartSpriteAnim(&gSprites[gBattlerSpriteIds[battler]], 1); + + paletteNum = AllocSpritePalette(tagTrainerPal); + LoadCompressedPalette(trainerPal, OBJ_PLTT_ID(paletteNum), PLTT_SIZE_4BPP); + gSprites[gBattlerSpriteIds[battler]].oam.paletteNum = paletteNum; + } + else + { + StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[battler]], SpriteCB_FreeOpponentSprite); + } + + taskId = CreateTask(Task_StartSendOutAnim, 5); + gTasks[taskId].tBattlerId = battler; + gTasks[taskId].tFramesToWait = framesToWait; + SetWordTaskArg(taskId, tControllerFunc_1, (uint32_t)(controllerCallback)); + + if (gBattleSpritesDataPtr->healthBoxesData[battler].partyStatusSummaryShown) + gTasks[gBattlerStatusSummaryTaskId[battler]].func = Task_HidePartyStatusSummary; + + gBattleSpritesDataPtr->animationData->introAnimActive = TRUE; + gBattlerControllerFuncs[battler] = BattleControllerDummy; +} + +static bool32 TwoMonsAtSendOut(u32 battlerId) +{ + if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) + { + if (TwoPlayerIntroMons(battlerId) && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) + return TRUE; + else + return FALSE; + } + else + { + if ((!TwoOpponentIntroMons(battlerId) || (gBattleTypeFlags & BATTLE_TYPE_MULTI)) && !BATTLE_TWO_VS_ONE_OPPONENT) + return FALSE; + else if ((gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) || (BATTLE_TWO_VS_ONE_OPPONENT && !TwoOpponentIntroMons(battlerId))) + return FALSE; + else + return TRUE; + } + return FALSE; +} + +// Send out at start of battle +static void Task_StartSendOutAnim(u8 taskId) +{ + if (gTasks[taskId].tFramesToWait != 0 && gTasks[taskId].tStartTimer < gTasks[taskId].tFramesToWait) + { + gTasks[taskId].tStartTimer++; + } + else + { + u8 savedActiveBattler = gActiveBattler; + + gActiveBattler = gTasks[taskId].tBattlerId; + if (TwoMonsAtSendOut(gActiveBattler)) + { + gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; + StartSendOutAnim(gActiveBattler, FALSE); + gActiveBattler ^= BIT_FLANK; + gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; + BattleLoadMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); + StartSendOutAnim(gActiveBattler, FALSE); + gActiveBattler ^= BIT_FLANK; + } + else + { + gBattleResources->bufferA[gActiveBattler][1] = gBattlerPartyIndexes[gActiveBattler]; + StartSendOutAnim(gActiveBattler, FALSE); + } + gBattlerControllerFuncs[gActiveBattler] = (void*)(GetWordTaskArg(taskId, tControllerFunc_1)); + gActiveBattler = savedActiveBattler; + DestroyTask(taskId); + } +} + +#undef tBattlerId +#undef tStartTimer +#undef tFramesToWait +#undef tControllerFunc_1 +#undef tControllerFunc_2 + +static void SpriteCB_FreePlayerSpriteLoadMonSprite(struct Sprite *sprite) { u8 battlerId = sprite->sBattlerId; @@ -2592,36 +2725,15 @@ void SpriteCB_FreePlayerSpriteLoadMonSprite(struct Sprite *sprite) StartSpriteAnim(&gSprites[gBattlerSpriteIds[battlerId]], 0); } -void BtlController_HandleIntroTrainerBallThrow(u32 battlerId, u16 const u32 *trainerPal, TaskFunc *introTask) +static void SpriteCB_FreeOpponentSprite(struct Sprite *sprite) { - u8 paletteNum; - u8 taskId; - - SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[battler]]); - - gSprites[gBattlerSpriteIds[battler]].data[0] = 50; - gSprites[gBattlerSpriteIds[battler]].data[2] = -40; - gSprites[gBattlerSpriteIds[battler]].data[4] = gSprites[gBattlerSpriteIds[battler]].y; - gSprites[gBattlerSpriteIds[battler]].callback = StartAnimLinearTranslation; - gSprites[gBattlerSpriteIds[battler]].sBattlerId = battler; - - StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[battler]], SpriteCB_FreePlayerSpriteLoadMonSprite); - StartSpriteAnim(&gSprites[gBattlerSpriteIds[battler]], 1); - - paletteNum = AllocSpritePalette(0xD6F8); - LoadCompressedPalette(trainerPal, OBJ_PLTT_ID(paletteNum), PLTT_SIZE_4BPP); - gSprites[gBattlerSpriteIds[battler]].oam.paletteNum = paletteNum; - - taskId = CreateTask(Task_StartSendOutAnim, 5); - gTasks[taskId].tBattlerId = battler; - - if (gBattleSpritesDataPtr->healthBoxesData[battler].partyStatusSummaryShown) - gTasks[gBattlerStatusSummaryTaskId[battler]].func = introTask; - - gBattleSpritesDataPtr->animationData->introAnimActive = TRUE; - gBattlerControllerFuncs[battler] = BattleControllerDummy; + FreeTrainerFrontPicPalette(sprite->oam.affineParam); + FreeSpriteOamMatrix(sprite); + DestroySprite(sprite); } +#undef sBattlerId + void BtlController_HandleDrawPartyStatusSummary(u32 battler, u32 side, bool32 considerDelay) { if (gBattleResources->bufferA[battler][1] != 0 && GetBattlerSide(battler) == B_SIDE_PLAYER)