From 25e9ca2ac66b1f87ad5ca4ca3b50166ab2c8a9ed Mon Sep 17 00:00:00 2001 From: Alex <93446519+AlexOn1ine@users.noreply.github.com> Date: Sun, 15 Sep 2024 08:24:26 +0200 Subject: [PATCH] Cleaned up a bit of code with GetBattlerPartyData (#5378) * rename GetBattlerPartyData --- include/battle.h | 8 ++++---- src/battle_anim_mons.c | 6 +----- src/battle_debug.c | 7 +------ src/battle_message.c | 9 ++------- src/battle_script_commands.c | 5 +---- src/battle_tv.c | 13 ++----------- src/pokeball.c | 8 ++------ src/type_icons.c | 2 +- 8 files changed, 14 insertions(+), 44 deletions(-) diff --git a/include/battle.h b/include/battle.h index 66f8531ae7..7ccbcfbfe4 100644 --- a/include/battle.h +++ b/include/battle.h @@ -1153,11 +1153,10 @@ static inline u32 GetBattlerSide(u32 battler) return GetBattlerPosition(battler) & BIT_SIDE; } -static inline struct Pokemon* GetBattlerData(u32 battlerId) +static inline struct Pokemon* GetPartyBattlerData(u32 battler) { - u32 index = gBattlerPartyIndexes[battlerId]; - - return (GetBattlerSide(battlerId) == B_SIDE_OPPONENT) ? &gEnemyParty[index] : &gPlayerParty[index]; + u32 index = gBattlerPartyIndexes[battler]; + return (GetBattlerSide(battler) == B_SIDE_OPPONENT) ? &gEnemyParty[index] : &gPlayerParty[index]; } static inline struct Pokemon *GetSideParty(u32 side) @@ -1176,3 +1175,4 @@ static inline bool32 IsDoubleBattle(void) } #endif // GUARD_BATTLE_H + diff --git a/src/battle_anim_mons.c b/src/battle_anim_mons.c index e0b4820409..dec12e0dc6 100644 --- a/src/battle_anim_mons.c +++ b/src/battle_anim_mons.c @@ -116,11 +116,7 @@ u8 GetBattlerSpriteCoord(u8 battlerId, u8 coordType) } else { - if (GetBattlerSide(battlerId) != B_SIDE_PLAYER) - mon = &gEnemyParty[gBattlerPartyIndexes[battlerId]]; - else - mon = &gPlayerParty[gBattlerPartyIndexes[battlerId]]; - + mon = GetPartyBattlerData(battlerId); illusionMon = GetIllusionMonPtr(battlerId); if (illusionMon != NULL) mon = illusionMon; diff --git a/src/battle_debug.c b/src/battle_debug.c index b088aa73ba..a5421a932b 100644 --- a/src/battle_debug.c +++ b/src/battle_debug.c @@ -2269,14 +2269,9 @@ static void UpdateMonData(struct BattleDebugMenu *data) { if (data->battlerWasChanged[i]) { - struct Pokemon *mon; + struct Pokemon *mon = GetPartyBattlerData(i); struct BattlePokemon *battleMon = &gBattleMons[i]; - if (GetBattlerSide(i) == B_SIDE_PLAYER) - mon = &gPlayerParty[gBattlerPartyIndexes[i]]; - else - mon = &gEnemyParty[gBattlerPartyIndexes[i]]; - SetMonData(mon, MON_DATA_HELD_ITEM, &battleMon->item); SetMonData(mon, MON_DATA_STATUS, &battleMon->status1); SetMonData(mon, MON_DATA_HP, &battleMon->hp); diff --git a/src/battle_message.c b/src/battle_message.c index 7c009f5a73..727091cec6 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -3091,14 +3091,9 @@ static const u8 *TryGetStatusString(u8 *src) static void GetBattlerNick(u32 battler, u8 *dst) { - struct Pokemon *mon, *illusionMon; + struct Pokemon *illusionMon = GetIllusionMonPtr(battler); + struct Pokemon *mon = GetPartyBattlerData(battler); - if (GetBattlerSide(battler) == B_SIDE_PLAYER) - mon = &gPlayerParty[gBattlerPartyIndexes[battler]]; - else - mon = &gEnemyParty[gBattlerPartyIndexes[battler]]; - - illusionMon = GetIllusionMonPtr(battler); if (illusionMon != NULL) mon = illusionMon; GetMonData(mon, MON_DATA_NICKNAME, dst); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index bfb7eec56d..283f42a23b 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -9877,10 +9877,7 @@ static void Cmd_various(void) case VARIOUS_HANDLE_FORM_CHANGE: { VARIOUS_ARGS(u8 case_); - if (GetBattlerSide(battler) == B_SIDE_OPPONENT) - mon = &gEnemyParty[gBattlerPartyIndexes[battler]]; - else - mon = &gPlayerParty[gBattlerPartyIndexes[battler]]; + mon = GetPartyBattlerData(battler); // Change species. if (cmd->case_ == 0) diff --git a/src/battle_tv.c b/src/battle_tv.c index 24d573d0bf..22e5ab1c31 100644 --- a/src/battle_tv.c +++ b/src/battle_tv.c @@ -338,17 +338,8 @@ void BattleTv_SetDataBasedOnString(u16 stringId) defSide = GetBattlerSide(gBattlerTarget); effSide = GetBattlerSide(gEffectBattler); scriptingSide = GetBattlerSide(gBattleMsgDataPtr->scrActive); - - if (atkSide == B_SIDE_PLAYER) - atkMon = &gPlayerParty[gBattlerPartyIndexes[gBattlerAttacker]]; - else - atkMon = &gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker]]; - - if (defSide == B_SIDE_PLAYER) - defMon = &gPlayerParty[gBattlerPartyIndexes[gBattlerTarget]]; - else - defMon = &gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]]; - + atkMon = GetPartyBattlerData(gBattlerAttacker); + defMon = GetPartyBattlerData(gBattlerTarget); moveSlot = GetBattlerMoveSlotId(gBattlerAttacker, gBattleMsgDataPtr->currentMove); if (moveSlot >= MAX_MON_MOVES && IsNotSpecialBattleString(stringId) && stringId > BATTLESTRINGS_TABLE_START) diff --git a/src/pokeball.c b/src/pokeball.c index 914455af5a..21557d973a 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -1571,12 +1571,8 @@ void FreeBallGfx(u8 ballId) static u16 GetBattlerPokeballItemId(u8 battlerId) { - struct Pokemon *mon, *illusionMon; - - if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) - mon = &gPlayerParty[gBattlerPartyIndexes[battlerId]]; - else - mon = &gEnemyParty[gBattlerPartyIndexes[battlerId]]; + struct Pokemon *illusionMon; + struct Pokemon *mon = GetPartyBattlerData(battlerId); illusionMon = GetIllusionMonPtr(battlerId); if (illusionMon != NULL) diff --git a/src/type_icons.c b/src/type_icons.c index 361312ab91..41fa102bb9 100644 --- a/src/type_icons.c +++ b/src/type_icons.c @@ -291,7 +291,7 @@ static bool32 UseDoubleBattleCoords(u32 position) static u32 GetMonPublicType(u32 battlerId, u32 typeNum) { - struct Pokemon* mon = GetBattlerData(battlerId); + struct Pokemon* mon = GetPartyBattlerData(battlerId); u32 monSpecies = GetMonData(mon,MON_DATA_SPECIES,NULL); struct Pokemon* monIllusion; u32 illusionSpecies;