From e8d6c99e6d3453401bace13425019dfb8122c097 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 7 Aug 2023 01:05:09 +0200 Subject: [PATCH] more controllers work --- include/battle_controllers.h | 2 + include/battle_gfx_sfx_util.h | 1 - src/battle_controller_link_opponent.c | 44 +----------- src/battle_controller_link_partner.c | 23 +----- src/battle_controller_opponent.c | 43 +---------- src/battle_controller_player.c | 42 +---------- src/battle_controller_player_partner.c | 23 +----- src/battle_controller_recorded_opponent.c | 23 +----- src/battle_controller_recorded_player.c | 19 +---- src/battle_controller_wally.c | 12 +--- src/battle_controllers.c | 88 +++++++++++++++++++---- src/battle_gfx_sfx_util.c | 4 -- 12 files changed, 88 insertions(+), 236 deletions(-) diff --git a/include/battle_controllers.h b/include/battle_controllers.h index 0d9a106bc..84339c6cf 100644 --- a/include/battle_controllers.h +++ b/include/battle_controllers.h @@ -267,6 +267,8 @@ void BtlController_HandleLoadMonSprite(u32 battler, struct Pokemon *party, void void BtlController_HandleSwitchInAnim(u32 battler, bool32 isPlayerSide, void (*controllerCallback)(void)); void BtlController_HandleReturnMonToBall(void); void BtlController_HandleDrawTrainerPic(u32 battlerId, u32 trainerPicId, bool32 isFrontPic, s16 xPos, s16 yPos, s32 subpriority); +void BtlController_HandleTrainerSlide(u32 battler, u32 trainerPicId); +void BtlController_HandleTrainerSlideBack(u32 battlerId, s16 data0, bool32 startAnim); 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); diff --git a/include/battle_gfx_sfx_util.h b/include/battle_gfx_sfx_util.h index d59ce9b04..794447446 100644 --- a/include/battle_gfx_sfx_util.h +++ b/include/battle_gfx_sfx_util.h @@ -14,7 +14,6 @@ void BattleLoadMonSpriteGfx(struct Pokemon *mon, u32 battlerId); void BattleGfxSfxDummy2(u16 species); void DecompressTrainerFrontPic(u16 frontPicId, u8 battlerId); void DecompressTrainerBackPic(u16 backPicId, u8 battlerId); -void BattleGfxSfxDummy3(u8 gender); void FreeTrainerFrontPicPalette(u16 frontPicId); bool8 BattleLoadAllHealthBoxesGfx(u8 state); void LoadBattleBarGfx(u8 unused); diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index 01978826b..9af5aa72b 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -129,23 +129,6 @@ static void LinkOpponentBufferRunCommand(void) } } -static void CompleteOnBankSpriteCallbackDummy2(void) -{ - if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) - LinkOpponentBufferExecCompleted(); -} - -static void FreeTrainerSpriteAfterSlide(void) -{ - if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) - { - FreeTrainerFrontPicPalette(gSprites[gBattlerSpriteIds[gActiveBattler]].oam.affineParam); - FreeSpriteOamMatrix(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - DestroySprite(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - LinkOpponentBufferExecCompleted(); - } -} - static void Intro_DelayAndEnd(void) { if (--gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay == (u8)-1) @@ -421,8 +404,6 @@ static void LinkOpponentHandleSwitchInAnim(void) BtlController_HandleSwitchInAnim(gActiveBattler, FALSE, SwitchIn_TryShinyAnim); } -#define sSpeedX data[0] - static void LinkOpponentHandleDrawTrainerPic(void) { s16 xPos; @@ -509,32 +490,13 @@ static void LinkOpponentHandleTrainerSlide(void) else trainerPicId = GetFrontierTrainerFrontSpriteId(gTrainerBattleOpponent_B); - DecompressTrainerFrontPic(trainerPicId, gActiveBattler); - SetMultiuseSpriteTemplateToTrainerBack(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, 176, (8 - gTrainerFrontPicCoords[trainerPicId].size) * 4 + 40, 0x1E); - - gSprites[gBattlerSpriteIds[gActiveBattler]].x2 = 96; - gSprites[gBattlerSpriteIds[gActiveBattler]].x += 32; - gSprites[gBattlerSpriteIds[gActiveBattler]].sSpeedX = -2; - gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = IndexOfSpritePaletteTag(gTrainerFrontPicPaletteTable[trainerPicId].tag); - gSprites[gBattlerSpriteIds[gActiveBattler]].oam.affineParam = trainerPicId; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = SpriteCB_TrainerSlideIn; - - gBattlerControllerFuncs[gActiveBattler] = CompleteOnBankSpriteCallbackDummy2; // this line is redundant, because LinkOpponentBufferExecCompleted changes the battle battlerId function - LinkOpponentBufferExecCompleted(); + BtlController_HandleTrainerSlide(gActiveBattler, trainerPicId); + LinkOpponentBufferExecCompleted(); // Possibly a bug, because execution should be completed after the slide in finishes. See Controller_WaitForTrainerPic. } -#undef sSpeedX - static void LinkOpponentHandleTrainerSlideBack(void) { - 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]], SpriteCallbackDummy); - gBattlerControllerFuncs[gActiveBattler] = FreeTrainerSpriteAfterSlide; + BtlController_HandleTrainerSlideBack(gActiveBattler, 35, FALSE); } static void LinkOpponentHandleMoveAnimation(void) diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index c15498a7c..655923eca 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -129,17 +129,6 @@ static void LinkPartnerBufferRunCommand(void) } } -static void FreeTrainerSpriteAfterSlide(void) -{ - if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) - { - BattleGfxSfxDummy3(MALE); - FreeSpriteOamMatrix(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - DestroySprite(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - LinkPartnerBufferExecCompleted(); - } -} - static void WaitForMonAnimAfterLoad(void) { if (gSprites[gBattlerSpriteIds[gActiveBattler]].animEnded && gSprites[gBattlerSpriteIds[gActiveBattler]].x2 == 0) @@ -247,8 +236,6 @@ static void LinkPartnerHandleSwitchInAnim(void) BtlController_HandleSwitchInAnim(gActiveBattler, TRUE, SwitchIn_TryShinyAnim); } -#define sSpeedX data[0] - static void LinkPartnerHandleDrawTrainerPic(void) { s16 xPos; @@ -272,17 +259,9 @@ static void LinkPartnerHandleDrawTrainerPic(void) -1); } -#undef sSpeedX - static void LinkPartnerHandleTrainerSlideBack(void) { - SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = 35; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[2] = -40; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[4] = gSprites[gBattlerSpriteIds[gActiveBattler]].y; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = StartAnimLinearTranslation; - StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[gActiveBattler]], SpriteCallbackDummy); - gBattlerControllerFuncs[gActiveBattler] = FreeTrainerSpriteAfterSlide; + BtlController_HandleTrainerSlideBack(gActiveBattler, 35, FALSE); } static void LinkPartnerHandleMoveAnimation(void) diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 34846f5f4..81045b3c7 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -145,23 +145,6 @@ static void OpponentBufferRunCommand(void) } } -static void CompleteOnBankSpriteCallbackDummy2(void) -{ - if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) - OpponentBufferExecCompleted(); -} - -static void FreeTrainerSpriteAfterSlide(void) -{ - if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) - { - FreeTrainerFrontPicPalette(gSprites[gBattlerSpriteIds[gActiveBattler]].oam.affineParam); - FreeSpriteOamMatrix(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - DestroySprite(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - OpponentBufferExecCompleted(); - } -} - static void Intro_DelayAndEnd(void) { if (--gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay == (u8)-1) @@ -498,8 +481,6 @@ static u32 OpponentGetTrainerPicId(u32 battlerId) return trainerPicId; } -#define sSpeedX data[0] - static void OpponentHandleDrawTrainerPic(void) { s16 xPos; @@ -525,32 +506,12 @@ static void OpponentHandleDrawTrainerPic(void) static void OpponentHandleTrainerSlide(void) { u32 trainerPicId = OpponentGetTrainerPicId(gActiveBattler); - - DecompressTrainerFrontPic(trainerPicId, gActiveBattler); - SetMultiuseSpriteTemplateToTrainerBack(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, 176, (8 - gTrainerFrontPicCoords[trainerPicId].size) * 4 + 40, 0x1E); - - gSprites[gBattlerSpriteIds[gActiveBattler]].x2 = 96; - gSprites[gBattlerSpriteIds[gActiveBattler]].x += 32; - gSprites[gBattlerSpriteIds[gActiveBattler]].sSpeedX = -2; - gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = IndexOfSpritePaletteTag(gTrainerFrontPicPaletteTable[trainerPicId].tag); - gSprites[gBattlerSpriteIds[gActiveBattler]].oam.affineParam = trainerPicId; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = SpriteCB_TrainerSlideIn; - - gBattlerControllerFuncs[gActiveBattler] = CompleteOnBankSpriteCallbackDummy2; + BtlController_HandleTrainerSlide(gActiveBattler, trainerPicId); } -#undef sSpeedX - static void OpponentHandleTrainerSlideBack(void) { - 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]], SpriteCallbackDummy); - gBattlerControllerFuncs[gActiveBattler] = FreeTrainerSpriteAfterSlide; + BtlController_HandleTrainerSlideBack(gActiveBattler, 35, FALSE); } static void OpponentHandleMoveAnimation(void) diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index cf86913af..edae63996 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -1087,23 +1087,6 @@ void SetBattleEndCallbacks(void) } } -static void CompleteOnBankSpriteCallbackDummy2(void) -{ - if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) - PlayerBufferExecCompleted(); -} - -static void FreeTrainerSpriteAfterSlide(void) -{ - if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) - { - BattleGfxSfxDummy3(gSaveBlock2Ptr->playerGender); - FreeSpriteOamMatrix(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - DestroySprite(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - PlayerBufferExecCompleted(); - } -} - static void Intro_DelayAndEnd(void) { if (--gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay == (u8)-1) @@ -1691,8 +1674,6 @@ static void PlayerHandleSwitchInAnim(void) BtlController_HandleSwitchInAnim(gActiveBattler, TRUE, SwitchIn_TryShinyAnimShowHealthbox); } -#define sSpeedX data[0] - u32 LinkPlayerGetTrainerPicId(u32 multiplayerId) { u32 trainerPicId; @@ -1773,31 +1754,12 @@ static void PlayerHandleDrawTrainerPic(void) static void PlayerHandleTrainerSlide(void) { u32 trainerPicId = PlayerGetTrainerBackPicId(); - - DecompressTrainerBackPic(trainerPicId, gActiveBattler); - SetMultiuseSpriteTemplateToTrainerBack(trainerPicId, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, 80, (8 - gTrainerBackPicCoords[trainerPicId].size) * 4 + 80, 30); - - gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = gActiveBattler; - gSprites[gBattlerSpriteIds[gActiveBattler]].x2 = -96; - gSprites[gBattlerSpriteIds[gActiveBattler]].sSpeedX = 2; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = SpriteCB_TrainerSlideIn; - - gBattlerControllerFuncs[gActiveBattler] = CompleteOnBankSpriteCallbackDummy2; + BtlController_HandleTrainerSlide(gActiveBattler, trainerPicId); } -#undef sSpeedX - static void PlayerHandleTrainerSlideBack(void) { - 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; - StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[gActiveBattler]], SpriteCallbackDummy); - StartSpriteAnim(&gSprites[gBattlerSpriteIds[gActiveBattler]], 1); - gBattlerControllerFuncs[gActiveBattler] = FreeTrainerSpriteAfterSlide; + BtlController_HandleTrainerSlideBack(gActiveBattler, 50, TRUE); } static void PlayerHandlePaletteFade(void) diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index 4fe93d6d2..54d56b688 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -138,17 +138,6 @@ static void PlayerPartnerBufferRunCommand(void) } } -static void FreeTrainerSpriteAfterSlide(void) -{ - if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) - { - BattleGfxSfxDummy3(MALE); - FreeSpriteOamMatrix(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - DestroySprite(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - PlayerPartnerBufferExecCompleted(); - } -} - static void Intro_DelayAndEnd(void) { if (--gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay == (u8)-1) @@ -323,8 +312,6 @@ static void PlayerPartnerHandleSwitchInAnim(void) BtlController_HandleSwitchInAnim(gActiveBattler, TRUE, SwitchIn_TryShinyAnim); } -#define sSpeedX data[0] - // some explanation here // in emerald it's possible to have a tag battle in the battle frontier facilities with AI // which use the front sprite for both the player and the partner as opposed to any other battles (including the one with Steven) that use the back pic as well as animate it @@ -362,17 +349,9 @@ static void PlayerPartnerHandleDrawTrainerPic(void) BtlController_HandleDrawTrainerPic(gActiveBattler, trainerPicId, isFrontPic, xPos, yPos, -1); } -#undef sSpeedX - static void PlayerPartnerHandleTrainerSlideBack(void) { - SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = 35; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[2] = -40; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[4] = gSprites[gBattlerSpriteIds[gActiveBattler]].y; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = StartAnimLinearTranslation; - StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[gActiveBattler]], SpriteCallbackDummy); - gBattlerControllerFuncs[gActiveBattler] = FreeTrainerSpriteAfterSlide; + BtlController_HandleTrainerSlideBack(gActiveBattler, 35, FALSE); } static void PlayerPartnerHandleMoveAnimation(void) diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index fbc28ae56..624f28c79 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -143,17 +143,6 @@ static void CompleteOnBankSpriteCallbackDummy2(void) RecordedOpponentBufferExecCompleted(); } -static void FreeTrainerSpriteAfterSlide(void) -{ - if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) - { - FreeTrainerFrontPicPalette(gSprites[gBattlerSpriteIds[gActiveBattler]].oam.affineParam); - FreeSpriteOamMatrix(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - DestroySprite(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - RecordedOpponentBufferExecCompleted(); - } -} - static void Intro_DelayAndEnd(void) { if (--gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay == (u8)-1) @@ -416,8 +405,6 @@ static void RecordedOpponentHandleSwitchInAnim(void) BtlController_HandleSwitchInAnim(gActiveBattler, FALSE, SwitchIn_TryShinyAnim); } -#define sSpeedX data[0] - static void RecordedOpponentHandleDrawTrainerPic(void) { s16 xPos; @@ -460,17 +447,9 @@ static void RecordedOpponentHandleDrawTrainerPic(void) -1); } -#undef sSpeedX - static void RecordedOpponentHandleTrainerSlideBack(void) { - 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]], SpriteCallbackDummy); - gBattlerControllerFuncs[gActiveBattler] = FreeTrainerSpriteAfterSlide; + BtlController_HandleTrainerSlideBack(gActiveBattler, 35, FALSE); } static void RecordedOpponentHandleMoveAnimation(void) diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index 0644e6fca..9d64a3c62 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -134,17 +134,6 @@ static void RecordedPlayerBufferRunCommand(void) } } -static void FreeTrainerSpriteAfterSlide(void) -{ - if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) - { - BattleGfxSfxDummy3(MALE); - FreeSpriteOamMatrix(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - DestroySprite(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - RecordedPlayerBufferExecCompleted(); - } -} - static void Intro_DelayAndEnd(void) { if (--gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].introEndDelay == (u8)-1) @@ -449,13 +438,7 @@ static void RecordedPlayerHandleDrawTrainerPic(void) static void RecordedPlayerHandleTrainerSlideBack(void) { - SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[gActiveBattler]]); - gSprites[gBattlerSpriteIds[gActiveBattler]].data[0] = 35; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[2] = -40; - gSprites[gBattlerSpriteIds[gActiveBattler]].data[4] = gSprites[gBattlerSpriteIds[gActiveBattler]].y; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = StartAnimLinearTranslation; - StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[gActiveBattler]], SpriteCallbackDummy); - gBattlerControllerFuncs[gActiveBattler] = FreeTrainerSpriteAfterSlide; + BtlController_HandleTrainerSlideBack(gActiveBattler, 35, FALSE); } static void RecordedPlayerHandleMoveAnimation(void) diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index e9e644daf..b9b3cdedb 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -329,17 +329,7 @@ static void WallyHandleDrawTrainerPic(void) static void WallyHandleTrainerSlide(void) { - DecompressTrainerBackPic(TRAINER_BACK_PIC_WALLY, gActiveBattler); - SetMultiuseSpriteTemplateToTrainerBack(TRAINER_BACK_PIC_WALLY, GetBattlerPosition(gActiveBattler)); - gBattlerSpriteIds[gActiveBattler] = CreateSprite(&gMultiuseSpriteTemplate, - 80, - 80 + 4 * (8 - gTrainerBackPicCoords[TRAINER_BACK_PIC_WALLY].size), - 30); - gSprites[gBattlerSpriteIds[gActiveBattler]].oam.paletteNum = gActiveBattler; - gSprites[gBattlerSpriteIds[gActiveBattler]].x2 = -96; - gSprites[gBattlerSpriteIds[gActiveBattler]].sSpeedX = 2; - gSprites[gBattlerSpriteIds[gActiveBattler]].callback = SpriteCB_TrainerSlideIn; - //gBattlerControllerFuncs[gActiveBattler] = CompleteOnBankSpriteCallbackDummy2; + BtlController_HandleTrainerSlide(gActiveBattler, TRAINER_BACK_PIC_WALLY); } #undef sSpeedX diff --git a/src/battle_controllers.c b/src/battle_controllers.c index d8f1a17ab..d41df69d8 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -2185,6 +2185,18 @@ static void Controller_FaintOpponentMon(void) } } +static void Controller_HandleTrainerSlideBack(void) +{ + if (gSprites[gBattlerSpriteIds[gActiveBattler]].callback == SpriteCallbackDummy) + { + if (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT) + FreeTrainerFrontPicPalette(gSprites[gBattlerSpriteIds[gActiveBattler]].oam.affineParam); + FreeSpriteOamMatrix(&gSprites[gBattlerSpriteIds[gActiveBattler]]); + DestroySprite(&gSprites[gBattlerSpriteIds[gActiveBattler]]); + BattleControllerComplete(gActiveBattler); + } +} + static void Controller_WaitForBallThrow(void) { if (!gDoingBattleAnim || !gBattleSpritesDataPtr->healthBoxesData[gActiveBattler].specialAnimActive) @@ -2443,11 +2455,59 @@ void BtlController_HandleDrawTrainerPic(u32 battler, u32 trainerPicId, bool32 is } gSprites[gBattlerSpriteIds[battler]].callback = SpriteCB_TrainerSlideIn; - gBattlerControllerFuncs[gActiveBattler] = Controller_WaitForTrainerPic; + gBattlerControllerFuncs[battler] = Controller_WaitForTrainerPic; +} + +void BtlController_HandleTrainerSlide(u32 battler, u32 trainerPicId) +{ + if (GetBattlerSide(battler) == B_SIDE_PLAYER) + { + DecompressTrainerBackPic(trainerPicId, battler); + SetMultiuseSpriteTemplateToTrainerBack(trainerPicId, GetBattlerPosition(battler)); + gBattlerSpriteIds[battler] = CreateSprite(&gMultiuseSpriteTemplate, + 80, + (8 - gTrainerBackPicCoords[trainerPicId].size) * 4 + 80, + 30); + gSprites[gBattlerSpriteIds[battler]].oam.paletteNum = battler; + gSprites[gBattlerSpriteIds[battler]].x2 = -96; + gSprites[gBattlerSpriteIds[battler]].sSpeedX = 2; + } + else + { + DecompressTrainerFrontPic(trainerPicId, battler); + SetMultiuseSpriteTemplateToTrainerBack(trainerPicId, GetBattlerPosition(battler)); + gBattlerSpriteIds[battler] = CreateSprite(&gMultiuseSpriteTemplate, + 176, + (8 - gTrainerFrontPicCoords[trainerPicId].size) * 4 + 40, + 30); + gSprites[gBattlerSpriteIds[battler]].oam.affineParam = trainerPicId; + gSprites[gBattlerSpriteIds[battler]].oam.paletteNum = IndexOfSpritePaletteTag(gTrainerFrontPicPaletteTable[trainerPicId].tag); + gSprites[gBattlerSpriteIds[battler]].x2 = 96; + gSprites[gBattlerSpriteIds[battler]].x += 32; + gSprites[gBattlerSpriteIds[battler]].sSpeedX = -2; + } + gSprites[gBattlerSpriteIds[battler]].callback = SpriteCB_TrainerSlideIn; + + gBattlerControllerFuncs[battler] = Controller_WaitForTrainerPic; } #undef sSpeedX +void BtlController_HandleTrainerSlideBack(u32 battlerId, s16 data0, bool32 startAnim) +{ + u32 side = GetBattlerSide(battlerId); + + SetSpritePrimaryCoordsFromSecondaryCoords(&gSprites[gBattlerSpriteIds[battlerId]]); + gSprites[gBattlerSpriteIds[battlerId]].data[0] = data0; + gSprites[gBattlerSpriteIds[battlerId]].data[2] = (side == B_SIDE_PLAYER) ? -40 : 280; + gSprites[gBattlerSpriteIds[battlerId]].data[4] = gSprites[gBattlerSpriteIds[battlerId]].y; + gSprites[gBattlerSpriteIds[battlerId]].callback = StartAnimLinearTranslation; + StoreSpriteCallbackInData6(&gSprites[gBattlerSpriteIds[battlerId]], SpriteCallbackDummy); + if (startAnim) + StartSpriteAnim(&gSprites[gBattlerSpriteIds[battlerId]], 1); + gBattlerControllerFuncs[battlerId] = Controller_HandleTrainerSlideBack; +} + #define sSpeedX data[1] #define sSpeedY data[2] @@ -2653,16 +2713,16 @@ void BtlController_HandleSpriteInvisibility(void) BattleControllerComplete(gActiveBattler); } -bool32 TwoPlayerIntroMons(u32 battlerId) // Double battle with both player pokemon active. +bool32 TwoPlayerIntroMons(u32 battler) // Double battle with both player pokemon active. { - return (IsDoubleBattle() && IsValidForBattle(&gPlayerParty[gBattlerPartyIndexes[battlerId ^ BIT_FLANK]])); + return (IsDoubleBattle() && IsValidForBattle(&gPlayerParty[gBattlerPartyIndexes[battler ^ BIT_FLANK]])); } -bool32 TwoOpponentIntroMons(u32 battlerId) // Double battle with both opponent pokemon active. +bool32 TwoOpponentIntroMons(u32 battler) // Double battle with both opponent pokemon active. { return (IsDoubleBattle() - && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[battlerId]]) - && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)]])); + && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[battler]]) + && IsValidForBattle(&gEnemyParty[gBattlerPartyIndexes[BATTLE_PARTNER(battler)]])); } // Task data for Task_StartSendOutAnim @@ -2722,20 +2782,20 @@ void BtlController_HandleIntroTrainerBallThrow(u32 battler, u16 tagTrainerPal, c gBattlerControllerFuncs[battler] = BattleControllerDummy; } -static bool32 TwoMonsAtSendOut(u32 battlerId) +static bool32 TwoMonsAtSendOut(u32 battler) { - if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) { - if (TwoPlayerIntroMons(battlerId) && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) + if (TwoPlayerIntroMons(battler) && !(gBattleTypeFlags & BATTLE_TYPE_MULTI)) return TRUE; else return FALSE; } else { - if ((!TwoOpponentIntroMons(battlerId) || (gBattleTypeFlags & BATTLE_TYPE_MULTI)) && !BATTLE_TWO_VS_ONE_OPPONENT) + if ((!TwoOpponentIntroMons(battler) || (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))) + else if ((gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) || (BATTLE_TWO_VS_ONE_OPPONENT && !TwoOpponentIntroMons(battler))) return FALSE; else return TRUE; @@ -2784,7 +2844,7 @@ static void Task_StartSendOutAnim(u8 taskId) static void SpriteCB_FreePlayerSpriteLoadMonSprite(struct Sprite *sprite) { - u8 battlerId = sprite->sBattlerId; + u8 battler = sprite->sBattlerId; // Free player trainer sprite FreeSpriteOamMatrix(sprite); @@ -2792,8 +2852,8 @@ static void SpriteCB_FreePlayerSpriteLoadMonSprite(struct Sprite *sprite) DestroySprite(sprite); // Load mon sprite - BattleLoadMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[battlerId]], battlerId); - StartSpriteAnim(&gSprites[gBattlerSpriteIds[battlerId]], 0); + BattleLoadMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[battler]], battler); + StartSpriteAnim(&gSprites[gBattlerSpriteIds[battler]], 0); } static void SpriteCB_FreeOpponentSprite(struct Sprite *sprite) diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index dddb3675d..9da563057 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -632,10 +632,6 @@ void DecompressTrainerBackPic(u16 backPicId, u8 battlerId) OBJ_PLTT_ID(battlerId), PLTT_SIZE_4BPP); } -void BattleGfxSfxDummy3(u8 gender) -{ -} - void FreeTrainerFrontPicPalette(u16 frontPicId) { FreeSpritePaletteByTag(gTrainerFrontPicPaletteTable[frontPicId].tag);