From a505cd7fb94b968f5a680eb89ec5fd7781f3a8d2 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 5 Aug 2023 12:53:14 +0200 Subject: [PATCH] simplify the get mon set mon data functions more --- include/battle_controllers.h | 8 +++--- src/battle_controller_link_opponent.c | 24 +++-------------- src/battle_controller_link_partner.c | 24 +++-------------- src/battle_controller_opponent.c | 32 +++-------------------- src/battle_controller_player.c | 32 +++-------------------- src/battle_controller_player_partner.c | 24 +++-------------- src/battle_controller_recorded_opponent.c | 24 +++-------------- src/battle_controller_recorded_player.c | 24 +++-------------- src/battle_controller_wally.c | 25 +++--------------- src/battle_controllers.c | 19 ++++++++++---- 10 files changed, 44 insertions(+), 192 deletions(-) diff --git a/include/battle_controllers.h b/include/battle_controllers.h index da2ccaff0..1597dcf09 100644 --- a/include/battle_controllers.h +++ b/include/battle_controllers.h @@ -257,10 +257,10 @@ void BtlController_TerminatorNop(void); // Dummy function at the end of the tabl void StartSendOutAnim(u32 battler, bool32 dontClearSubstituteBit); // handlers -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_HandleGetMonData(void); +void BtlController_HandleGetRawMonData(void); +void BtlController_HandleSetMonData(void); +void BtlController_HandleSetRawMonData(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); diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index 4434f2dcd..ea7f38620 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -29,9 +29,6 @@ #include "constants/trainers.h" #include "recorded_battle.h" -static void LinkOpponentHandleGetMonData(void); -static void LinkOpponentHandleSetMonData(void); -static void LinkOpponentHandleSetRawMonData(void); static void LinkOpponentHandleLoadMonSprite(void); static void LinkOpponentHandleSwitchInAnim(void); static void LinkOpponentHandleReturnMonToBall(void); @@ -70,10 +67,10 @@ static void EndDrawPartyStatusSummary(void); static void (*const sLinkOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void) = { - [CONTROLLER_GETMONDATA] = LinkOpponentHandleGetMonData, + [CONTROLLER_GETMONDATA] = BtlController_HandleGetMonData, [CONTROLLER_GETRAWMONDATA] = BtlController_Empty, - [CONTROLLER_SETMONDATA] = LinkOpponentHandleSetMonData, - [CONTROLLER_SETRAWMONDATA] = LinkOpponentHandleSetRawMonData, + [CONTROLLER_SETMONDATA] = BtlController_HandleSetMonData, + [CONTROLLER_SETRAWMONDATA] = BtlController_HandleSetRawMonData, [CONTROLLER_LOADMONSPRITE] = LinkOpponentHandleLoadMonSprite, [CONTROLLER_SWITCHINANIM] = LinkOpponentHandleSwitchInAnim, [CONTROLLER_RETURNMONTOBALL] = LinkOpponentHandleReturnMonToBall, @@ -477,21 +474,6 @@ static void LinkOpponentBufferExecCompleted(void) } } -static void LinkOpponentHandleGetMonData(void) -{ - BtlController_HandleGetMonData(gActiveBattler, gEnemyParty); -} - -static void LinkOpponentHandleSetMonData(void) -{ - BtlController_HandleSetMonData(gActiveBattler, gEnemyParty); -} - -static void LinkOpponentHandleSetRawMonData(void) -{ - BtlController_HandleSetRawMonData(gActiveBattler, gEnemyParty); -} - static void LinkOpponentHandleLoadMonSprite(void) { BtlController_HandleLoadMonSprite(gActiveBattler, gEnemyParty, TryShinyAnimAfterMonAnim); diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index 6fc1620ca..ec2a2a462 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -29,9 +29,6 @@ #include "constants/trainers.h" #include "recorded_battle.h" -static void LinkPartnerHandleGetMonData(void); -static void LinkPartnerHandleSetMonData(void); -static void LinkPartnerHandleSetRawMonData(void); static void LinkPartnerHandleLoadMonSprite(void); static void LinkPartnerHandleSwitchInAnim(void); static void LinkPartnerHandleReturnMonToBall(void); @@ -68,10 +65,10 @@ static void EndDrawPartyStatusSummary(void); static void (*const sLinkPartnerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = { - [CONTROLLER_GETMONDATA] = LinkPartnerHandleGetMonData, + [CONTROLLER_GETMONDATA] = BtlController_HandleGetMonData, [CONTROLLER_GETRAWMONDATA] = BtlController_Empty, - [CONTROLLER_SETMONDATA] = LinkPartnerHandleSetMonData, - [CONTROLLER_SETRAWMONDATA] = LinkPartnerHandleSetRawMonData, + [CONTROLLER_SETMONDATA] = BtlController_HandleSetMonData, + [CONTROLLER_SETRAWMONDATA] = BtlController_HandleSetRawMonData, [CONTROLLER_LOADMONSPRITE] = LinkPartnerHandleLoadMonSprite, [CONTROLLER_SWITCHINANIM] = LinkPartnerHandleSwitchInAnim, [CONTROLLER_RETURNMONTOBALL] = LinkPartnerHandleReturnMonToBall, @@ -366,21 +363,6 @@ static void CompleteOnFinishedBattleAnimation(void) LinkPartnerBufferExecCompleted(); } -static void LinkPartnerHandleGetMonData(void) -{ - BtlController_HandleGetMonData(gActiveBattler, gPlayerParty); -} - -static void LinkPartnerHandleSetMonData(void) -{ - BtlController_HandleSetMonData(gActiveBattler, gPlayerParty); -} - -static void LinkPartnerHandleSetRawMonData(void) -{ - BtlController_HandleSetRawMonData(gActiveBattler, gPlayerParty); -} - static void LinkPartnerHandleLoadMonSprite(void) { BtlController_HandleLoadMonSprite(gActiveBattler, gPlayerParty, WaitForMonAnimAfterLoad); diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index d721f9d3b..177c209da 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -39,10 +39,6 @@ #include "constants/trainers.h" #include "trainer_hill.h" -static void OpponentHandleGetMonData(void); -static void OpponentHandleGetRawMonData(void); -static void OpponentHandleSetMonData(void); -static void OpponentHandleSetRawMonData(void); static void OpponentHandleLoadMonSprite(void); static void OpponentHandleSwitchInAnim(void); static void OpponentHandleReturnMonToBall(void); @@ -85,10 +81,10 @@ static void EndDrawPartyStatusSummary(void); static void (*const sOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void) = { - [CONTROLLER_GETMONDATA] = OpponentHandleGetMonData, - [CONTROLLER_GETRAWMONDATA] = OpponentHandleGetRawMonData, - [CONTROLLER_SETMONDATA] = OpponentHandleSetMonData, - [CONTROLLER_SETRAWMONDATA] = OpponentHandleSetRawMonData, + [CONTROLLER_GETMONDATA] = BtlController_HandleGetMonData, + [CONTROLLER_GETRAWMONDATA] = BtlController_HandleGetRawMonData, + [CONTROLLER_SETMONDATA] = BtlController_HandleSetMonData, + [CONTROLLER_SETRAWMONDATA] = BtlController_HandleSetRawMonData, [CONTROLLER_LOADMONSPRITE] = OpponentHandleLoadMonSprite, [CONTROLLER_SWITCHINANIM] = OpponentHandleSwitchInAnim, [CONTROLLER_RETURNMONTOBALL] = OpponentHandleReturnMonToBall, @@ -499,26 +495,6 @@ static void OpponentBufferExecCompleted(void) } } -static void OpponentHandleGetMonData(void) -{ - BtlController_HandleGetMonData(gActiveBattler, gEnemyParty); -} - -static void OpponentHandleGetRawMonData(void) -{ - BtlController_HandleGetRawMonData(gActiveBattler, gEnemyParty); -} - -static void OpponentHandleSetMonData(void) -{ - BtlController_HandleSetMonData(gActiveBattler, gEnemyParty); -} - -static void OpponentHandleSetRawMonData(void) -{ - BtlController_HandleSetRawMonData(gActiveBattler, gEnemyParty); -} - static void OpponentHandleLoadMonSprite(void) { BtlController_HandleLoadMonSprite(gActiveBattler, gEnemyParty, TryShinyAnimAfterMonAnim); diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 774ef5eb4..e26e386f4 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -38,10 +38,6 @@ #include "constants/rgb.h" static void PlayerBufferExecCompleted(void); -static void PlayerHandleGetMonData(void); -static void PlayerHandleGetRawMonData(void); -static void PlayerHandleSetMonData(void); -static void PlayerHandleSetRawMonData(void); static void PlayerHandleLoadMonSprite(void); static void PlayerHandleSwitchInAnim(void); static void PlayerHandleReturnMonToBall(void); @@ -117,10 +113,10 @@ static void ReloadMoveNames(void); static void (*const sPlayerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = { - [CONTROLLER_GETMONDATA] = PlayerHandleGetMonData, - [CONTROLLER_GETRAWMONDATA] = PlayerHandleGetRawMonData, - [CONTROLLER_SETMONDATA] = PlayerHandleSetMonData, - [CONTROLLER_SETRAWMONDATA] = PlayerHandleSetRawMonData, + [CONTROLLER_GETMONDATA] = BtlController_HandleGetMonData, + [CONTROLLER_GETRAWMONDATA] = BtlController_HandleGetRawMonData, + [CONTROLLER_SETMONDATA] = BtlController_HandleSetMonData, + [CONTROLLER_SETRAWMONDATA] = BtlController_HandleSetRawMonData, [CONTROLLER_LOADMONSPRITE] = PlayerHandleLoadMonSprite, [CONTROLLER_SWITCHINANIM] = PlayerHandleSwitchInAnim, [CONTROLLER_RETURNMONTOBALL] = PlayerHandleReturnMonToBall, @@ -1759,26 +1755,6 @@ static void PrintLinkStandbyMsg(void) } } -static void PlayerHandleGetMonData(void) -{ - BtlController_HandleGetMonData(gActiveBattler, gPlayerParty); -} - -static void PlayerHandleGetRawMonData(void) -{ - BtlController_HandleGetRawMonData(gActiveBattler, gPlayerParty); -} - -static void PlayerHandleSetMonData(void) -{ - BtlController_HandleSetMonData(gActiveBattler, gPlayerParty); -} - -static void PlayerHandleSetRawMonData(void) -{ - BtlController_HandleSetRawMonData(gActiveBattler, gPlayerParty); -} - static void PlayerHandleLoadMonSprite(void) { BattleLoadMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index 22d566ef3..34c0ad454 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -31,9 +31,6 @@ #include "constants/party_menu.h" #include "constants/trainers.h" -static void PlayerPartnerHandleGetMonData(void); -static void PlayerPartnerHandleSetMonData(void); -static void PlayerPartnerHandleSetRawMonData(void); static void PlayerPartnerHandleLoadMonSprite(void); static void PlayerPartnerHandleSwitchInAnim(void); static void PlayerPartnerHandleReturnMonToBall(void); @@ -78,10 +75,10 @@ static void EndDrawPartyStatusSummary(void); static void (*const sPlayerPartnerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = { - [CONTROLLER_GETMONDATA] = PlayerPartnerHandleGetMonData, + [CONTROLLER_GETMONDATA] = BtlController_HandleGetMonData, [CONTROLLER_GETRAWMONDATA] = BtlController_Empty, - [CONTROLLER_SETMONDATA] = PlayerPartnerHandleSetMonData, - [CONTROLLER_SETRAWMONDATA] = PlayerPartnerHandleSetRawMonData, + [CONTROLLER_SETMONDATA] = BtlController_HandleSetMonData, + [CONTROLLER_SETRAWMONDATA] = BtlController_HandleSetRawMonData, [CONTROLLER_LOADMONSPRITE] = PlayerPartnerHandleLoadMonSprite, [CONTROLLER_SWITCHINANIM] = PlayerPartnerHandleSwitchInAnim, [CONTROLLER_RETURNMONTOBALL] = PlayerPartnerHandleReturnMonToBall, @@ -548,21 +545,6 @@ static void CompleteOnFinishedBattleAnimation(void) PlayerPartnerBufferExecCompleted(); } -static void PlayerPartnerHandleGetMonData(void) -{ - BtlController_HandleGetMonData(gActiveBattler, gPlayerParty); -} - -static void PlayerPartnerHandleSetMonData(void) -{ - BtlController_HandleSetMonData(gActiveBattler, gPlayerParty); -} - -static void PlayerPartnerHandleSetRawMonData(void) -{ - BtlController_HandleSetRawMonData(gActiveBattler, gPlayerParty); -} - static void PlayerPartnerHandleLoadMonSprite(void) { BtlController_HandleLoadMonSprite(gActiveBattler, gPlayerParty, WaitForMonAnimAfterLoad); diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index dbb6825da..e55cb3550 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -32,9 +32,6 @@ #include "constants/songs.h" #include "constants/trainers.h" -static void RecordedOpponentHandleGetMonData(void); -static void RecordedOpponentHandleSetMonData(void); -static void RecordedOpponentHandleSetRawMonData(void); static void RecordedOpponentHandleLoadMonSprite(void); static void RecordedOpponentHandleSwitchInAnim(void); static void RecordedOpponentHandleReturnMonToBall(void); @@ -75,10 +72,10 @@ static void EndDrawPartyStatusSummary(void); static void (*const sRecordedOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void) = { - [CONTROLLER_GETMONDATA] = RecordedOpponentHandleGetMonData, + [CONTROLLER_GETMONDATA] = BtlController_HandleGetMonData, [CONTROLLER_GETRAWMONDATA] = BtlController_Empty, - [CONTROLLER_SETMONDATA] = RecordedOpponentHandleSetMonData, - [CONTROLLER_SETRAWMONDATA] = RecordedOpponentHandleSetRawMonData, + [CONTROLLER_SETMONDATA] = BtlController_HandleSetMonData, + [CONTROLLER_SETRAWMONDATA] = BtlController_HandleSetRawMonData, [CONTROLLER_LOADMONSPRITE] = RecordedOpponentHandleLoadMonSprite, [CONTROLLER_SWITCHINANIM] = RecordedOpponentHandleSwitchInAnim, [CONTROLLER_RETURNMONTOBALL] = RecordedOpponentHandleReturnMonToBall, @@ -468,21 +465,6 @@ static void RecordedOpponentBufferExecCompleted(void) } } -static void RecordedOpponentHandleGetMonData(void) -{ - BtlController_HandleGetMonData(gActiveBattler, gEnemyParty); -} - -static void RecordedOpponentHandleSetMonData(void) -{ - BtlController_HandleSetMonData(gActiveBattler, gEnemyParty); -} - -static void RecordedOpponentHandleSetRawMonData(void) -{ - BtlController_HandleSetRawMonData(gActiveBattler, gEnemyParty); -} - static void RecordedOpponentHandleLoadMonSprite(void) { BtlController_HandleLoadMonSprite(gActiveBattler, gEnemyParty, TryShinyAnimAfterMonAnim); diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index ef3606998..9e792b56b 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -28,9 +28,6 @@ #include "constants/battle_anim.h" #include "constants/songs.h" -static void RecordedPlayerHandleGetMonData(void); -static void RecordedPlayerHandleSetMonData(void); -static void RecordedPlayerHandleSetRawMonData(void); static void RecordedPlayerHandleLoadMonSprite(void); static void RecordedPlayerHandleSwitchInAnim(void); static void RecordedPlayerHandleReturnMonToBall(void); @@ -70,10 +67,10 @@ static void EndDrawPartyStatusSummary(void); static void (*const sRecordedPlayerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = { - [CONTROLLER_GETMONDATA] = RecordedPlayerHandleGetMonData, + [CONTROLLER_GETMONDATA] = BtlController_HandleGetMonData, [CONTROLLER_GETRAWMONDATA] = BtlController_Empty, - [CONTROLLER_SETMONDATA] = RecordedPlayerHandleSetMonData, - [CONTROLLER_SETRAWMONDATA] = RecordedPlayerHandleSetRawMonData, + [CONTROLLER_SETMONDATA] = BtlController_HandleSetMonData, + [CONTROLLER_SETRAWMONDATA] = BtlController_HandleSetRawMonData, [CONTROLLER_LOADMONSPRITE] = RecordedPlayerHandleLoadMonSprite, [CONTROLLER_SWITCHINANIM] = RecordedPlayerHandleSwitchInAnim, [CONTROLLER_RETURNMONTOBALL] = RecordedPlayerHandleReturnMonToBall, @@ -447,21 +444,6 @@ static void CompleteOnFinishedBattleAnimation(void) RecordedPlayerBufferExecCompleted(); } -static void RecordedPlayerHandleGetMonData(void) -{ - BtlController_HandleGetMonData(gActiveBattler, gPlayerParty); -} - -static void RecordedPlayerHandleSetMonData(void) -{ - BtlController_HandleSetMonData(gActiveBattler, gPlayerParty); -} - -static void RecordedPlayerHandleSetRawMonData(void) -{ - BtlController_HandleSetRawMonData(gActiveBattler, gPlayerParty); -} - static void RecordedPlayerHandleLoadMonSprite(void) { BtlController_HandleLoadMonSprite(gActiveBattler, gPlayerParty, WaitForMonAnimAfterLoad); diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index c4bcc8c72..2bb77a806 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -32,10 +32,6 @@ #include "constants/trainers.h" #include "constants/rgb.h" -// this file's functions -static void WallyHandleGetMonData(void); -static void WallyHandleGetRawMonData(void); -static void WallyHandleSetMonData(void); static void WallyHandleReturnMonToBall(void); static void WallyHandleDrawTrainerPic(void); static void WallyHandleTrainerSlide(void); @@ -68,9 +64,9 @@ static void Task_StartSendOutAnim(u8 taskId); static void (*const sWallyBufferCommands[CONTROLLER_CMDS_COUNT])(void) = { - [CONTROLLER_GETMONDATA] = WallyHandleGetMonData, - [CONTROLLER_GETRAWMONDATA] = WallyHandleGetRawMonData, - [CONTROLLER_SETMONDATA] = WallyHandleSetMonData, + [CONTROLLER_GETMONDATA] = BtlController_HandleGetMonData, + [CONTROLLER_GETRAWMONDATA] = BtlController_HandleGetRawMonData, + [CONTROLLER_SETMONDATA] = BtlController_HandleSetMonData, [CONTROLLER_SETRAWMONDATA] = BtlController_Empty, [CONTROLLER_LOADMONSPRITE] = BtlController_Empty, [CONTROLLER_SWITCHINANIM] = BtlController_Empty, @@ -368,21 +364,6 @@ static void WallyBufferExecCompleted(void) } } -static void WallyHandleGetMonData(void) -{ - BtlController_HandleGetMonData(gActiveBattler, gPlayerParty); -} - -static void WallyHandleGetRawMonData(void) -{ - BtlController_HandleGetRawMonData(gActiveBattler, gPlayerParty); -} - -static void WallyHandleSetMonData(void) -{ - BtlController_HandleSetMonData(gActiveBattler, gPlayerParty); -} - static void WallyHandleReturnMonToBall(void) { BtlController_HandleReturnMonToBall(gActiveBattler); diff --git a/src/battle_controllers.c b/src/battle_controllers.c index ef51be8bd..413094015 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -2195,10 +2195,12 @@ void BtlController_TerminatorNop(void) { } -// Handlers of all the controller commands -void BtlController_HandleGetMonData(u32 battler, struct Pokemon *party) +// Handlers of the controller commands +void BtlController_HandleGetMonData(void) { 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 + u32 battler = gActiveBattler; + struct Pokemon *party = GetBattlerParty(battler); u32 size = 0; u8 monToCheck; s32 i; @@ -2221,9 +2223,12 @@ void BtlController_HandleGetMonData(u32 battler, struct Pokemon *party) BattleControllerComplete(battler); } -void BtlController_HandleGetRawMonData(u32 battler, struct Pokemon *party) +void BtlController_HandleGetRawMonData(void) { struct BattlePokemon battleMon; + u32 battler = gActiveBattler; + struct Pokemon *party = GetBattlerParty(battler); + u8 *src = (u8 *)&party[gBattlerPartyIndexes[battler]] + gBattleResources->bufferA[battler][1]; u8 *dst = (u8 *)&battleMon + gBattleResources->bufferA[battler][1]; u8 i; @@ -2235,8 +2240,10 @@ void BtlController_HandleGetRawMonData(u32 battler, struct Pokemon *party) BattleControllerComplete(battler); } -void BtlController_HandleSetMonData(u32 battler, struct Pokemon *party) +void BtlController_HandleSetMonData(void) { + u32 battler = gActiveBattler; + struct Pokemon *party = GetBattlerParty(battler); u32 i, monToCheck; if (gBattleResources->bufferA[battler][2] == 0) @@ -2256,9 +2263,11 @@ void BtlController_HandleSetMonData(u32 battler, struct Pokemon *party) BattleControllerComplete(battler); } -void BtlController_HandleSetRawMonData(u32 battler, struct Pokemon *party) +void BtlController_HandleSetRawMonData(void) { u32 i; + u32 battler = gActiveBattler; + struct Pokemon *party = GetBattlerParty(battler); u8 *dst = (u8 *)&party[gBattlerPartyIndexes[battler]] + gBattleResources->bufferA[battler][1]; for (i = 0; i < gBattleResources->bufferA[battler][2]; i++)