From 94a3e80c8eebc831ab1a39cc8d0ea47975d8aec6 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 13 Sep 2023 14:19:18 +0200 Subject: [PATCH] Remove redundant side macros/funcs (#3299) Co-authored-by: gruxor --- include/battle.h | 34 +++++++------ include/battle_anim.h | 2 - src/battle_ai_main.c | 4 +- src/battle_ai_util.c | 2 +- src/battle_anim.c | 2 +- src/battle_anim_effects_2.c | 2 +- src/battle_anim_fight.c | 2 +- src/battle_anim_ice.c | 8 ++-- src/battle_anim_mons.c | 14 +----- src/battle_controller_player.c | 2 +- src/battle_controllers.c | 4 +- src/battle_debug.c | 16 +++---- src/battle_gfx_sfx_util.c | 18 +++---- src/battle_main.c | 2 +- src/battle_message.c | 2 +- src/battle_script_commands.c | 88 ++++++++++++++++------------------ src/battle_util.c | 14 +++--- src/pokemon.c | 2 +- 18 files changed, 103 insertions(+), 115 deletions(-) diff --git a/include/battle.h b/include/battle.h index eb878b2a5..0dab993d0 100644 --- a/include/battle.h +++ b/include/battle.h @@ -15,9 +15,6 @@ #include "pokeball.h" #include "battle_debug.h" -#define GET_BATTLER_SIDE(battler) (GetBattlerPosition(battler) & BIT_SIDE) -#define GET_BATTLER_SIDE2(battler) (gBattlerPositions[battler] & BIT_SIDE) - // Used to exclude moves learned temporarily by Transform or Mimic #define MOVE_IS_PERMANENT(battler, moveSlot) \ (!(gBattleMons[battler].status2 & STATUS2_TRANSFORMED) \ @@ -749,17 +746,6 @@ STATIC_ASSERT(sizeof(((struct BattleStruct *)0)->palaceFlags) * 8 >= MAX_BATTLER #define SET_STATCHANGER(statId, stage, goesDown)(gBattleScripting.statChanger = (statId) + ((stage) << 3) + (goesDown << 7)) #define SET_STATCHANGER2(dst, statId, stage, goesDown)(dst = (statId) + ((stage) << 3) + (goesDown << 7)) -static inline struct Pokemon *GetSideParty(u32 side) -{ - return side == B_SIDE_PLAYER ? gPlayerParty : gEnemyParty; -} - -static inline struct Pokemon *GetBattlerParty(u32 battlerId) -{ - extern u8 GetBattlerSide(u8 battler); - return GetSideParty(GetBattlerSide(battlerId)); -} - // NOTE: The members of this struct have hard-coded offsets // in include/constants/battle_script_commands.h struct BattleScripting @@ -1030,4 +1016,24 @@ extern u16 gBallToDisplay; extern bool8 gLastUsedBallMenuPresent; extern u8 gPartyCriticalHits[PARTY_SIZE]; +static inline u32 GetBattlerPosition(u32 battler) +{ + return gBattlerPositions[battler]; +} + +static inline u32 GetBattlerSide(u32 battler) +{ + return GetBattlerPosition(battler) & BIT_SIDE; +} + +static inline struct Pokemon *GetSideParty(u32 side) +{ + return (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty; +} + +static inline struct Pokemon *GetBattlerParty(u32 battler) +{ + return GetSideParty(GetBattlerSide(battler)); +} + #endif // GUARD_BATTLE_H diff --git a/include/battle_anim.h b/include/battle_anim.h index 9a1ac0193..7aaa09951 100644 --- a/include/battle_anim.h +++ b/include/battle_anim.h @@ -165,8 +165,6 @@ void Trade_MoveSelectedMonToTarget(struct Sprite *sprite); void DestroyAnimVisualTaskAndDisableBlend(u8 taskId); void DestroySpriteAndFreeResources_(struct Sprite *sprite); void SetBattlerSpriteYOffsetFromOtherYScale(u8 spriteId, u8 otherSpriteId); -u8 GetBattlerSide(u8 battler); -u8 GetBattlerPosition(u8 battler); u8 GetBattlerAtPosition(u8 position); void ConvertPosDataToTranslateLinearData(struct Sprite *sprite); void InitAnimFastLinearTranslationWithSpeedAndPos(struct Sprite *sprite); diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index a8946bcec..39f5dbe08 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -329,7 +329,7 @@ void Ai_UpdateSwitchInData(u32 battler) void Ai_UpdateFaintData(u32 battler) { - struct AiPartyMon *aiMon = &AI_PARTY->mons[GET_BATTLER_SIDE(battler)][gBattlerPartyIndexes[battler]]; + struct AiPartyMon *aiMon = &AI_PARTY->mons[GetBattlerSide(battler)][gBattlerPartyIndexes[battler]]; ClearBattlerMoveHistory(battler); ClearBattlerAbilityHistory(battler); ClearBattlerItemEffectHistory(battler); @@ -2587,7 +2587,7 @@ static s16 AI_CheckBadMove(u8 battlerAtk, u8 battlerDef, u16 move, s16 score) score -= 10; break; case EFFECT_LUCKY_CHANT: - if (gSideTimers[GET_BATTLER_SIDE(battlerAtk)].luckyChantTimer != 0 + if (gSideTimers[GetBattlerSide(battlerAtk)].luckyChantTimer != 0 || PartnerMoveIsSameNoTarget(BATTLE_PARTNER(battlerAtk), move, AI_DATA->partnerMove)) score -= 10; break; diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index 5072645bd..28113e3f1 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -3409,7 +3409,7 @@ s32 AI_CalcPartyMonBestMoveDamage(u32 battlerAtk, u32 battlerDef, struct Pokemon if (BattlerHasAi(battlerAtk)) move = GetMonData(attackerMon, MON_DATA_MOVE1 + i); else - move = AI_PARTY->mons[GET_BATTLER_SIDE2(battlerAtk)][gBattlerPartyIndexes[battlerAtk]].moves[i]; + move = AI_PARTY->mons[GetBattlerSide(battlerAtk)][gBattlerPartyIndexes[battlerAtk]].moves[i]; if (move != MOVE_NONE && gBattleMoves[move].power != 0) { diff --git a/src/battle_anim.c b/src/battle_anim.c index 6b48d38da..9d0c9d77a 100644 --- a/src/battle_anim.c +++ b/src/battle_anim.c @@ -216,7 +216,7 @@ void DoMoveAnim(u16 move) // Make sure the anim target of moves hitting everyone is at the opposite side. if (GetBattlerMoveTargetType(gBattlerAttacker, move) & MOVE_TARGET_FOES_AND_ALLY && IsDoubleBattle()) { - while (GET_BATTLER_SIDE(gBattleAnimAttacker) == GET_BATTLER_SIDE(gBattleAnimTarget)) + while (GetBattlerSide(gBattleAnimAttacker) == GetBattlerSide(gBattleAnimTarget)) { if (++gBattleAnimTarget >= MAX_BATTLERS_COUNT) gBattleAnimTarget = 0; diff --git a/src/battle_anim_effects_2.c b/src/battle_anim_effects_2.c index 18f94fab7..cd7f4221b 100755 --- a/src/battle_anim_effects_2.c +++ b/src/battle_anim_effects_2.c @@ -1704,7 +1704,7 @@ void AnimTask_AirCutterProjectile(u8 taskId) } else { - if (GET_BATTLER_SIDE2(gBattleAnimTarget) == B_SIDE_PLAYER) + if (GetBattlerSide(gBattleAnimTarget) == B_SIDE_PLAYER) { gTasks[taskId].data[4] = 1; gBattleAnimArgs[0] = -gBattleAnimArgs[0]; diff --git a/src/battle_anim_fight.c b/src/battle_anim_fight.c index 9ffe2d3c2..90bd9391e 100644 --- a/src/battle_anim_fight.c +++ b/src/battle_anim_fight.c @@ -564,7 +564,7 @@ static void AnimFistOrFootRandomPos(struct Sprite *sprite) if (Random2() & 1) y *= -1; - if (GET_BATTLER_SIDE2(battler) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) y += 0xFFF0; sprite->x += x; diff --git a/src/battle_anim_ice.c b/src/battle_anim_ice.c index 5750e7d7d..41566d047 100644 --- a/src/battle_anim_ice.c +++ b/src/battle_anim_ice.c @@ -1276,12 +1276,12 @@ static void InitPoisonGasCloudAnim(struct Sprite *sprite) if (GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_X_2) < GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_X_2)) sprite->data[7] = 0x8000; - if (GET_BATTLER_SIDE2(gBattleAnimTarget) == B_SIDE_PLAYER) + if (GetBattlerSide(gBattleAnimTarget) == B_SIDE_PLAYER) { gBattleAnimArgs[1] = -gBattleAnimArgs[1]; gBattleAnimArgs[3] = -gBattleAnimArgs[3]; - if ((sprite->data[7] & 0x8000) && GET_BATTLER_SIDE2(gBattleAnimAttacker) == B_SIDE_PLAYER) + if ((sprite->data[7] & 0x8000) && GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) sprite->subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority + 1; sprite->data[6] = 1; @@ -1362,7 +1362,7 @@ static void MovePoisonGasCloud(struct Sprite *sprite) sprite->data[7]++; if (IsContest()) sprite->data[5] = 80; - else if (GET_BATTLER_SIDE2(gBattleAnimTarget) != B_SIDE_PLAYER) + else if (GetBattlerSide(gBattleAnimTarget) != B_SIDE_PLAYER) sprite->data[5] = 204; else sprite->data[5] = 80; @@ -1408,7 +1408,7 @@ static void MovePoisonGasCloud(struct Sprite *sprite) sprite->data[4] = sprite->y + 4; if (IsContest()) sprite->data[2] = -16; - else if (GET_BATTLER_SIDE2(gBattleAnimTarget) != B_SIDE_PLAYER) + else if (GetBattlerSide(gBattleAnimTarget) != B_SIDE_PLAYER) sprite->data[2] = DISPLAY_WIDTH + 16; else sprite->data[2] = -16; diff --git a/src/battle_anim_mons.c b/src/battle_anim_mons.c index f2016dd5e..4d97cd2c7 100644 --- a/src/battle_anim_mons.c +++ b/src/battle_anim_mons.c @@ -845,23 +845,13 @@ bool32 InitSpritePosToAnimBattler(u32 animBattlerId, struct Sprite *sprite, bool return TRUE; } -u8 GetBattlerSide(u8 battlerId) -{ - return GET_BATTLER_SIDE2(battlerId); -} - -u8 GetBattlerPosition(u8 battlerId) -{ - return gBattlerPositions[battlerId]; -} - u8 GetBattlerAtPosition(u8 position) { u8 i; for (i = 0; i < gBattlersCount; i++) { - if (gBattlerPositions[i] == position) + if (GetBattlerPosition(i) == position) break; } return i; @@ -880,7 +870,7 @@ bool8 IsBattlerSpritePresent(u8 battlerId) } else { - if (gBattlerPositions[battlerId] == 0xff) + if (GetBattlerPosition(battlerId) == 0xff) return FALSE; if (!gBattleStruct->spriteIgnore0Hp) diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index d20fbbb51..3a464910e 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -692,7 +692,7 @@ static void HandleInputChooseMove(u32 battler) if (moveTarget & MOVE_TARGET_USER) gMultiUsePlayerCursor = battler; else - gMultiUsePlayerCursor = GetBattlerAtPosition(BATTLE_OPPOSITE(GET_BATTLER_SIDE(battler))); + gMultiUsePlayerCursor = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerSide(battler))); if (!gBattleResources->bufferA[battler][1]) // not a double battle { diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 7c835a241..5deadd26e 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -629,7 +629,7 @@ static void SetBattlePartyIds(void) { if (i < 2) { - if (GET_BATTLER_SIDE2(i) == B_SIDE_PLAYER) + if (GetBattlerSide(i) == B_SIDE_PLAYER) { if (IsValidForBattle(&gPlayerParty[j])) { @@ -648,7 +648,7 @@ static void SetBattlePartyIds(void) } else { - if (GET_BATTLER_SIDE2(i) == B_SIDE_PLAYER) + if (GetBattlerSide(i) == B_SIDE_PLAYER) { if (IsValidForBattle(&gPlayerParty[j]) && gBattlerPartyIndexes[i - 2] != j) { diff --git a/src/battle_debug.c b/src/battle_debug.c index 3e704b586..92c108238 100644 --- a/src/battle_debug.c +++ b/src/battle_debug.c @@ -855,7 +855,7 @@ static void PutAiInfoText(struct BattleDebugMenu *data) // items info for (i = 0; i < gBattlersCount; i++) { - if (GET_BATTLER_SIDE(i) == B_SIDE_PLAYER && IsBattlerAlive(i)) + if (GetBattlerSide(i) == B_SIDE_PLAYER && IsBattlerAlive(i)) { u16 ability = AI_GetAbility(i); u16 holdEffect = AI_GetHoldEffect(i); @@ -875,10 +875,10 @@ static void PutAiPartyText(struct BattleDebugMenu *data) { u32 i, j, count; u8 *text = Alloc(0x50), *txtPtr; - struct AiPartyMon *aiMons = AI_PARTY->mons[GET_BATTLER_SIDE(data->aiBattlerId)]; + struct AiPartyMon *aiMons = AI_PARTY->mons[GetBattlerSide(data->aiBattlerId)]; FillWindowPixelBuffer(data->aiMovesWindowId, 0x11); - count = AI_PARTY->count[GET_BATTLER_SIDE(data->aiBattlerId)]; + count = AI_PARTY->count[GetBattlerSide(data->aiBattlerId)]; for (i = 0; i < count; i++) { if (aiMons[i].wasSentInBattle) @@ -941,7 +941,7 @@ static void Task_ShowAiKnowledge(u8 taskId) LoadMonIconPalettes(); for (count = 0, i = 0; i < MAX_BATTLERS_COUNT; i++) { - if (GET_BATTLER_SIDE(i) == B_SIDE_PLAYER && IsBattlerAlive(i)) + if (GetBattlerSide(i) == B_SIDE_PLAYER && IsBattlerAlive(i)) { data->spriteIds.aiIconSpriteIds[i] = CreateMonIcon(gBattleMons[i].species, SpriteCallbackDummy, @@ -1000,8 +1000,8 @@ static void Task_ShowAiParty(u8 taskId) LoadMonIconPalettes(); LoadPartyMenuAilmentGfx(); data->aiBattlerId = data->battlerId; - aiMons = AI_PARTY->mons[GET_BATTLER_SIDE(data->aiBattlerId)]; - for (i = 0; i < AI_PARTY->count[GET_BATTLER_SIDE(data->aiBattlerId)]; i++) + aiMons = AI_PARTY->mons[GetBattlerSide(data->aiBattlerId)]; + for (i = 0; i < AI_PARTY->count[GetBattlerSide(data->aiBattlerId)]; i++) { u16 species = SPECIES_NONE; // Question mark if (aiMons[i].wasSentInBattle && aiMons[i].species) @@ -1626,7 +1626,7 @@ static void ValueToCharDigits(u8 *charDigits, u32 newValue, u8 maxDigits) static u8 *GetSideStatusValue(struct BattleDebugMenu *data, bool32 changeStatus, bool32 statusTrue) { - struct SideTimer *sideTimer = &gSideTimers[GET_BATTLER_SIDE(data->battlerId)]; + struct SideTimer *sideTimer = &gSideTimers[GetBattlerSide(data->battlerId)]; switch (data->currentSecondaryListItemId) { @@ -1909,7 +1909,7 @@ static void SetUpModifyArrows(struct BattleDebugMenu *data) data->modifyArrows.maxValue = 9; data->modifyArrows.maxDigits = 2; - data->modifyArrows.modifiedValPtr = &gSideStatuses[GET_BATTLER_SIDE(data->battlerId)]; + data->modifyArrows.modifiedValPtr = &gSideStatuses[GetBattlerSide(data->battlerId)]; data->modifyArrows.typeOfVal = VAR_SIDE_STATUS; data->modifyArrows.currValue = *GetSideStatusValue(data, FALSE, FALSE); break; diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index 3bcbe3ae5..3e48a0147 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -278,7 +278,7 @@ u16 ChooseMoveAndTargetInBattlePalace(u32 battler) else if (moveTarget == MOVE_TARGET_SELECTED) chosenMoveId |= GetBattlePalaceTarget(battler); else - chosenMoveId |= (GetBattlerAtPosition(BATTLE_OPPOSITE(GET_BATTLER_SIDE(battler))) << 8); + chosenMoveId |= (GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerSide(battler))) << 8); return chosenMoveId; } @@ -684,7 +684,7 @@ void BattleLoadAllHealthBoxesGfxAtOnce(void) numberOfBattlers = MAX_BATTLERS_COUNT; } for (i = 0; i < numberOfBattlers; i++) - LoadCompressedSpriteSheet(&sSpriteSheets_HealthBar[gBattlerPositions[i]]); + LoadCompressedSpriteSheet(&sSpriteSheets_HealthBar[GetBattlerPosition(i)]); } bool8 BattleLoadAllHealthBoxesGfx(u8 state) @@ -711,9 +711,9 @@ bool8 BattleLoadAllHealthBoxesGfx(u8 state) else if (state == 3) LoadCompressedSpriteSheet(&sSpriteSheet_SinglesOpponentHealthbox); else if (state == 4) - LoadCompressedSpriteSheet(&sSpriteSheets_HealthBar[gBattlerPositions[0]]); + LoadCompressedSpriteSheet(&sSpriteSheets_HealthBar[GetBattlerPosition(0)]); else if (state == 5) - LoadCompressedSpriteSheet(&sSpriteSheets_HealthBar[gBattlerPositions[1]]); + LoadCompressedSpriteSheet(&sSpriteSheets_HealthBar[GetBattlerPosition(1)]); else retVal = TRUE; } @@ -733,13 +733,13 @@ bool8 BattleLoadAllHealthBoxesGfx(u8 state) else if (state == 5) LoadCompressedSpriteSheet(&sSpriteSheets_DoublesOpponentHealthbox[1]); else if (state == 6) - LoadCompressedSpriteSheet(&sSpriteSheets_HealthBar[gBattlerPositions[0]]); + LoadCompressedSpriteSheet(&sSpriteSheets_HealthBar[GetBattlerPosition(0)]); else if (state == 7) - LoadCompressedSpriteSheet(&sSpriteSheets_HealthBar[gBattlerPositions[1]]); + LoadCompressedSpriteSheet(&sSpriteSheets_HealthBar[GetBattlerPosition(1)]); else if (state == 8) - LoadCompressedSpriteSheet(&sSpriteSheets_HealthBar[gBattlerPositions[2]]); + LoadCompressedSpriteSheet(&sSpriteSheets_HealthBar[GetBattlerPosition(2)]); else if (state == 9) - LoadCompressedSpriteSheet(&sSpriteSheets_HealthBar[gBattlerPositions[3]]); + LoadCompressedSpriteSheet(&sSpriteSheets_HealthBar[GetBattlerPosition(3)]); else retVal = TRUE; } @@ -792,7 +792,7 @@ bool8 BattleInitAllSprites(u8 *state1, u8 *battler) break; case 4: InitBattlerHealthboxCoords(*battler); - if (gBattlerPositions[*battler] <= B_POSITION_OPPONENT_LEFT) + if (GetBattlerPosition(*battler) <= B_POSITION_OPPONENT_LEFT) DummyBattleInterfaceFunc(gHealthboxSpriteIds[*battler], FALSE); else DummyBattleInterfaceFunc(gHealthboxSpriteIds[*battler], TRUE); diff --git a/src/battle_main.c b/src/battle_main.c index 7f985f16e..9dc4c5ac8 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -4653,7 +4653,7 @@ u32 GetBattlerTotalSpeedStat(u8 battler) speed *= 2; // various effects - if (gSideStatuses[GET_BATTLER_SIDE(battler)] & SIDE_STATUS_TAILWIND) + if (gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_TAILWIND) speed *= 2; if (gBattleResources->flags->flags[battler] & RESOURCE_FLAG_UNBURDEN) speed *= 2; diff --git a/src/battle_message.c b/src/battle_message.c index 5c86685e0..397cc213e 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -2980,7 +2980,7 @@ static void GetBattlerNick(u32 battler, u8 *dst) { struct Pokemon *mon, *illusionMon; - if (GET_BATTLER_SIDE(battler) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) mon = &gPlayerParty[gBattlerPartyIndexes[battler]]; else mon = &gEnemyParty[gBattlerPartyIndexes[battler]]; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index b75520ff9..b89b7d844 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -2817,7 +2817,7 @@ void SetMoveEffect(bool32 primary, u32 certain) INCREMENT_RESET_RETURN } - if (gSideStatuses[GET_BATTLER_SIDE(gEffectBattler)] & SIDE_STATUS_SAFEGUARD && !(gHitMarker & HITMARKER_IGNORE_SAFEGUARD) + if (gSideStatuses[GetBattlerSide(gEffectBattler)] & SIDE_STATUS_SAFEGUARD && !(gHitMarker & HITMARKER_IGNORE_SAFEGUARD) && !primary && gBattleScripting.moveEffect <= MOVE_EFFECT_CONFUSION) INCREMENT_RESET_RETURN @@ -3157,7 +3157,7 @@ void SetMoveEffect(bool32 primary, u32 certain) break; case MOVE_EFFECT_PAYDAY: // Don't scatter coins on the second hit of Parental Bond - if (GET_BATTLER_SIDE(gBattlerAttacker) == B_SIDE_PLAYER && gSpecialStatuses[gBattlerAttacker].parentalBondState!= PARENTAL_BOND_2ND_HIT) + if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER && gSpecialStatuses[gBattlerAttacker].parentalBondState!= PARENTAL_BOND_2ND_HIT) { u16 payday = gPaydayMoney; gPaydayMoney += (gBattleMons[gBattlerAttacker].level * 5); @@ -3173,7 +3173,7 @@ void SetMoveEffect(bool32 primary, u32 certain) } break; case MOVE_EFFECT_HAPPY_HOUR: - if (GET_BATTLER_SIDE(gBattlerAttacker) == B_SIDE_PLAYER && !gBattleStruct->moneyMultiplierMove) + if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER && !gBattleStruct->moneyMultiplierMove) { gBattleStruct->moneyMultiplier *= 2; gBattleStruct->moneyMultiplierMove = 1; @@ -3948,16 +3948,10 @@ static void Cmd_jumpifsideaffecting(void) { CMD_ARGS(u8 battler, u32 flags, const u8 *jumpInstr); - u8 side; - u32 flags; - const u8 *jumpInstr; + u32 side = GetBattlerSide(GetBattlerForBattleScript(cmd->battler)); - side = GET_BATTLER_SIDE(GetBattlerForBattleScript(cmd->battler)); - flags = cmd->flags; - jumpInstr = cmd->jumpInstr; - - if (gSideStatuses[side] & flags) - gBattlescriptCurrInstr = jumpInstr; + if (gSideStatuses[side] & cmd->flags) + gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; } @@ -5086,7 +5080,7 @@ static void Cmd_playstatchangeanimation(void) changeableStatsCount++; } } - else if (!gSideTimers[GET_BATTLER_SIDE(battler)].mistTimer + else if (!gSideTimers[GetBattlerSide(battler)].mistTimer && GetBattlerHoldEffect(battler, TRUE) != HOLD_EFFECT_CLEAR_AMULET && ability != ABILITY_CLEAR_BODY && ability != ABILITY_FULL_METAL_BODY @@ -8462,7 +8456,7 @@ static void HandleScriptMegaPrimalBurst(u32 caseId, u32 battler, u32 type) struct Pokemon *party = GetBattlerParty(battler); struct Pokemon *mon = &party[gBattlerPartyIndexes[battler]]; u32 position = GetBattlerPosition(battler); - u32 side = GET_BATTLER_SIDE(battler); + u32 side = GetBattlerSide(battler); // Change species. if (caseId == 0) @@ -8671,7 +8665,7 @@ static void Cmd_various(void) while (gBattleStruct->friskedBattler < gBattlersCount) { gBattlerTarget = gBattleStruct->friskedBattler++; - if (GET_BATTLER_SIDE2(battler) != GET_BATTLER_SIDE2(gBattlerTarget) + if (GetBattlerSide(battler) != GetBattlerSide(gBattlerTarget) && IsBattlerAlive(gBattlerTarget) && gBattleMons[gBattlerTarget].item != ITEM_NONE) { @@ -9305,11 +9299,11 @@ static void Cmd_various(void) case VARIOUS_SET_LUCKY_CHANT: { VARIOUS_ARGS(const u8 *failInstr); - if (!(gSideStatuses[GET_BATTLER_SIDE(battler)] & SIDE_STATUS_LUCKY_CHANT)) + if (!(gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_LUCKY_CHANT)) { - gSideStatuses[GET_BATTLER_SIDE(battler)] |= SIDE_STATUS_LUCKY_CHANT; - gSideTimers[GET_BATTLER_SIDE(battler)].luckyChantBattlerId = battler; - gSideTimers[GET_BATTLER_SIDE(battler)].luckyChantTimer = 5; + gSideStatuses[GetBattlerSide(battler)] |= SIDE_STATUS_LUCKY_CHANT; + gSideTimers[GetBattlerSide(battler)].luckyChantBattlerId = battler; + gSideTimers[GetBattlerSide(battler)].luckyChantTimer = 5; gBattlescriptCurrInstr = cmd->nextInstr; } else @@ -9896,7 +9890,7 @@ static void Cmd_various(void) case VARIOUS_SET_AURORA_VEIL: { VARIOUS_ARGS(); - if (gSideStatuses[GET_BATTLER_SIDE(battler)] & SIDE_STATUS_AURORA_VEIL + if (gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_AURORA_VEIL || !(WEATHER_HAS_EFFECT && gBattleWeather & (B_WEATHER_HAIL | B_WEATHER_SNOW))) { gMoveResultFlags |= MOVE_RESULT_MISSED; @@ -9904,12 +9898,12 @@ static void Cmd_various(void) } else { - gSideStatuses[GET_BATTLER_SIDE(battler)] |= SIDE_STATUS_AURORA_VEIL; + gSideStatuses[GetBattlerSide(battler)] |= SIDE_STATUS_AURORA_VEIL; if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_LIGHT_CLAY) - gSideTimers[GET_BATTLER_SIDE(battler)].auroraVeilTimer = 8; + gSideTimers[GetBattlerSide(battler)].auroraVeilTimer = 8; else - gSideTimers[GET_BATTLER_SIDE(battler)].auroraVeilTimer = 5; - gSideTimers[GET_BATTLER_SIDE(battler)].auroraVeilBattlerId = battler; + gSideTimers[GetBattlerSide(battler)].auroraVeilTimer = 5; + gSideTimers[GetBattlerSide(battler)].auroraVeilBattlerId = battler; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && CountAliveMonsInBattle(BATTLE_ALIVE_SIDE, gBattlerAttacker) == 2) gBattleCommunication[MULTISTRING_CHOOSER] = 5; @@ -10309,11 +10303,11 @@ static void Cmd_various(void) if (gBattleMons[gBattlerAttacker].species == SPECIES_GRENINJA_BATTLE_BOND && HasAttackerFaintedTarget() && CalculateBattlerPartyCount(gBattlerTarget) > 1 - && !(gBattleStruct->battleBondTransformed[GET_BATTLER_SIDE2(gBattlerAttacker)] & gBitTable[gBattlerPartyIndexes[gBattlerAttacker]])) + && !(gBattleStruct->battleBondTransformed[GetBattlerSide(gBattlerAttacker)] & gBitTable[gBattlerPartyIndexes[gBattlerAttacker]])) { - gBattleStruct->battleBondTransformed[GET_BATTLER_SIDE2(gBattlerAttacker)] |= gBitTable[gBattlerPartyIndexes[gBattlerAttacker]]; + gBattleStruct->battleBondTransformed[GetBattlerSide(gBattlerAttacker)] |= gBitTable[gBattlerPartyIndexes[gBattlerAttacker]]; PREPARE_SPECIES_BUFFER(gBattleTextBuff1, gBattleMons[gBattlerAttacker].species); - gBattleStruct->changedSpecies[GET_BATTLER_SIDE2(gBattlerAttacker)][gBattlerPartyIndexes[gBattlerAttacker]] = gBattleMons[gBattlerAttacker].species; + gBattleStruct->changedSpecies[GetBattlerSide(gBattlerAttacker)][gBattlerPartyIndexes[gBattlerAttacker]] = gBattleMons[gBattlerAttacker].species; gBattleMons[gBattlerAttacker].species = SPECIES_GRENINJA_ASH; BattleScriptPushCursor(); gBattlescriptCurrInstr = BattleScript_BattleBondActivatesOnMoveEndAttacker; @@ -11066,19 +11060,19 @@ static void Cmd_setreflect(void) { CMD_ARGS(); - if (gSideStatuses[GET_BATTLER_SIDE(gBattlerAttacker)] & SIDE_STATUS_REFLECT) + if (gSideStatuses[GetBattlerSide(gBattlerAttacker)] & SIDE_STATUS_REFLECT) { gMoveResultFlags |= MOVE_RESULT_MISSED; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SIDE_STATUS_FAILED; } else { - gSideStatuses[GET_BATTLER_SIDE(gBattlerAttacker)] |= SIDE_STATUS_REFLECT; + gSideStatuses[GetBattlerSide(gBattlerAttacker)] |= SIDE_STATUS_REFLECT; if (GetBattlerHoldEffect(gBattlerAttacker, TRUE) == HOLD_EFFECT_LIGHT_CLAY) - gSideTimers[GET_BATTLER_SIDE(gBattlerAttacker)].reflectTimer = 8; + gSideTimers[GetBattlerSide(gBattlerAttacker)].reflectTimer = 8; else - gSideTimers[GET_BATTLER_SIDE(gBattlerAttacker)].reflectTimer = 5; - gSideTimers[GET_BATTLER_SIDE(gBattlerAttacker)].reflectBattlerId = gBattlerAttacker; + gSideTimers[GetBattlerSide(gBattlerAttacker)].reflectTimer = 5; + gSideTimers[GetBattlerSide(gBattlerAttacker)].reflectBattlerId = gBattlerAttacker; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && CountAliveMonsInBattle(BATTLE_ALIVE_SIDE, gBattlerAttacker) == 2) gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SET_REFLECT_DOUBLE; @@ -11482,7 +11476,7 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr if (statValue <= -1) // Stat decrease. { - if (gSideTimers[GET_BATTLER_SIDE(battler)].mistTimer + if (gSideTimers[GetBattlerSide(battler)].mistTimer && !certain && gCurrentMove != MOVE_CURSE && !(battler == gBattlerTarget && GetBattlerAbility(gBattlerAttacker) == ABILITY_INFILTRATOR)) { @@ -12124,19 +12118,19 @@ static void Cmd_setlightscreen(void) { CMD_ARGS(); - if (gSideStatuses[GET_BATTLER_SIDE(gBattlerAttacker)] & SIDE_STATUS_LIGHTSCREEN) + if (gSideStatuses[GetBattlerSide(gBattlerAttacker)] & SIDE_STATUS_LIGHTSCREEN) { gMoveResultFlags |= MOVE_RESULT_MISSED; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SIDE_STATUS_FAILED; } else { - gSideStatuses[GET_BATTLER_SIDE(gBattlerAttacker)] |= SIDE_STATUS_LIGHTSCREEN; + gSideStatuses[GetBattlerSide(gBattlerAttacker)] |= SIDE_STATUS_LIGHTSCREEN; if (GetBattlerHoldEffect(gBattlerAttacker, TRUE) == HOLD_EFFECT_LIGHT_CLAY) - gSideTimers[GET_BATTLER_SIDE(gBattlerAttacker)].lightscreenTimer = 8; + gSideTimers[GetBattlerSide(gBattlerAttacker)].lightscreenTimer = 8; else - gSideTimers[GET_BATTLER_SIDE(gBattlerAttacker)].lightscreenTimer = 5; - gSideTimers[GET_BATTLER_SIDE(gBattlerAttacker)].lightscreenBattlerId = gBattlerAttacker; + gSideTimers[GetBattlerSide(gBattlerAttacker)].lightscreenTimer = 5; + gSideTimers[GetBattlerSide(gBattlerAttacker)].lightscreenBattlerId = gBattlerAttacker; if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && CountAliveMonsInBattle(BATTLE_ALIVE_SIDE, gBattlerAttacker) == 2) gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SET_LIGHTSCREEN_DOUBLE; @@ -12398,16 +12392,16 @@ static void Cmd_setmist(void) { CMD_ARGS(); - if (gSideTimers[GET_BATTLER_SIDE(gBattlerAttacker)].mistTimer) + if (gSideTimers[GetBattlerSide(gBattlerAttacker)].mistTimer) { gMoveResultFlags |= MOVE_RESULT_FAILED; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_MIST_FAILED; } else { - gSideTimers[GET_BATTLER_SIDE(gBattlerAttacker)].mistTimer = 5; - gSideTimers[GET_BATTLER_SIDE(gBattlerAttacker)].mistBattlerId = gBattlerAttacker; - gSideStatuses[GET_BATTLER_SIDE(gBattlerAttacker)] |= SIDE_STATUS_MIST; + gSideTimers[GetBattlerSide(gBattlerAttacker)].mistTimer = 5; + gSideTimers[GetBattlerSide(gBattlerAttacker)].mistBattlerId = gBattlerAttacker; + gSideStatuses[GetBattlerSide(gBattlerAttacker)] |= SIDE_STATUS_MIST; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SET_MIST; } gBattlescriptCurrInstr = cmd->nextInstr; @@ -13355,16 +13349,16 @@ static void Cmd_setsafeguard(void) { CMD_ARGS(); - if (gSideStatuses[GET_BATTLER_SIDE(gBattlerAttacker)] & SIDE_STATUS_SAFEGUARD) + if (gSideStatuses[GetBattlerSide(gBattlerAttacker)] & SIDE_STATUS_SAFEGUARD) { gMoveResultFlags |= MOVE_RESULT_MISSED; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SIDE_STATUS_FAILED; } else { - gSideStatuses[GET_BATTLER_SIDE(gBattlerAttacker)] |= SIDE_STATUS_SAFEGUARD; - gSideTimers[GET_BATTLER_SIDE(gBattlerAttacker)].safeguardTimer = 5; - gSideTimers[GET_BATTLER_SIDE(gBattlerAttacker)].safeguardBattlerId = gBattlerAttacker; + gSideStatuses[GetBattlerSide(gBattlerAttacker)] |= SIDE_STATUS_SAFEGUARD; + gSideTimers[GetBattlerSide(gBattlerAttacker)].safeguardTimer = 5; + gSideTimers[GetBattlerSide(gBattlerAttacker)].safeguardBattlerId = gBattlerAttacker; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SET_SAFEGUARD; } @@ -13675,7 +13669,7 @@ static void Cmd_trysetfutureattack(void) } else { - gSideStatuses[GET_BATTLER_SIDE(gBattlerTarget)] |= SIDE_STATUS_FUTUREATTACK; + gSideStatuses[GetBattlerSide(gBattlerTarget)] |= SIDE_STATUS_FUTUREATTACK; gWishFutureKnock.futureSightMove[gBattlerTarget] = gCurrentMove; gWishFutureKnock.futureSightAttacker[gBattlerTarget] = gBattlerAttacker; gWishFutureKnock.futureSightCounter[gBattlerTarget] = 3; diff --git a/src/battle_util.c b/src/battle_util.c index d4e873b7e..aabb6e6e8 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -3139,7 +3139,7 @@ bool8 HandleWishPerishSongOnTurnEnd(void) if (gWishFutureKnock.futureSightCounter[battler] == 0 && gWishFutureKnock.futureSightCounter[BATTLE_PARTNER(battler)] == 0) { - gSideStatuses[GET_BATTLER_SIDE(gBattlerTarget)] &= ~SIDE_STATUS_FUTUREATTACK; + gSideStatuses[GetBattlerSide(gBattlerTarget)] &= ~SIDE_STATUS_FUTUREATTACK; } return TRUE; } @@ -4244,7 +4244,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move gBattleWeather = B_WEATHER_SNOW; gBattleScripting.animArg1 = B_ANIM_SNOW_CONTINUES; effect++; - #else + #else gBattleWeather = B_WEATHER_HAIL; gBattleScripting.animArg1 = B_ANIM_HAIL_CONTINUES; effect++; @@ -7932,7 +7932,7 @@ u32 GetMoveTarget(u16 move, u8 setTarget) case MOVE_TARGET_BOTH: case MOVE_TARGET_FOES_AND_ALLY: case MOVE_TARGET_OPPONENTS_FIELD: - targetBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GET_BATTLER_SIDE(gBattlerAttacker))); + targetBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerSide(gBattlerAttacker))); if (!IsBattlerAlive(targetBattler)) targetBattler ^= BIT_FLANK; break; @@ -7943,7 +7943,7 @@ u32 GetMoveTarget(u16 move, u8 setTarget) else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && moveTarget & MOVE_TARGET_RANDOM) targetBattler = SetRandomTarget(gBattlerAttacker); else - targetBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GET_BATTLER_SIDE(gBattlerAttacker))); + targetBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerSide(gBattlerAttacker))); break; case MOVE_TARGET_USER_OR_SELECTED: case MOVE_TARGET_USER: @@ -8723,7 +8723,7 @@ static u32 CalcMoveBasePowerAfterModifiers(u16 move, u8 battlerAtk, u8 battlerDe u16 basePower = CalcMoveBasePower(move, battlerAtk, battlerDef); uq4_12_t holdEffectModifier; uq4_12_t modifier = UQ_4_12(1.0); - u32 atkSide = GET_BATTLER_SIDE(battlerAtk); + u32 atkSide = GetBattlerSide(battlerAtk); u16 atkAbility = GetBattlerAbility(battlerAtk); u16 defAbility = GetBattlerAbility(battlerDef); @@ -9584,7 +9584,7 @@ static inline uq4_12_t GetAirborneModifier(u32 move, u32 battlerDef) static inline uq4_12_t GetScreensModifier(u32 move, u32 battlerAtk, u32 battlerDef, bool32 isCrit) { - u32 sideStatus = gSideStatuses[GET_BATTLER_SIDE(battlerDef)]; + u32 sideStatus = gSideStatuses[GetBattlerSide(battlerDef)]; bool32 lightScreen = (sideStatus & SIDE_STATUS_LIGHTSCREEN) && IS_MOVE_SPECIAL(move); bool32 reflect = (sideStatus & SIDE_STATUS_REFLECT) && IS_MOVE_PHYSICAL(move); bool32 auroraVeil = sideStatus & SIDE_STATUS_AURORA_VEIL; @@ -10372,7 +10372,7 @@ bool32 CanBattlerFormChange(u8 battler, u16 method) bool32 TryBattleFormChange(u8 battler, u16 method) { u8 monId = gBattlerPartyIndexes[battler]; - u8 side = GET_BATTLER_SIDE(battler); + u8 side = GetBattlerSide(battler); struct Pokemon *party = GetBattlerParty(battler); u16 targetSpecies; diff --git a/src/pokemon.c b/src/pokemon.c index 474044e80..838d0068c 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -4436,7 +4436,7 @@ u8 CountAliveMonsInBattle(u8 caseId, u32 battler) u8 GetDefaultMoveTarget(u8 battlerId) { - u8 opposing = BATTLE_OPPOSITE(GET_BATTLER_SIDE(battlerId)); + u8 opposing = BATTLE_OPPOSITE(GetBattlerSide(battlerId)); if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) return GetBattlerAtPosition(opposing);