Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant side macros/funcs #3299

Merged
merged 8 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -747,17 +744,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
Expand Down Expand Up @@ -1028,4 +1014,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
2 changes: 0 additions & 2 deletions include/battle_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,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);
Expand Down Expand Up @@ -2584,7 +2584,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;
Expand Down
2 changes: 1 addition & 1 deletion src/battle_ai_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/battle_anim.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/battle_anim_effects_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/battle_anim_fight.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/battle_anim_ice.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 2 additions & 12 deletions src/battle_anim_mons.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -880,7 +870,7 @@ bool8 IsBattlerSpritePresent(u8 battlerId)
}
else
{
if (gBattlerPositions[battlerId] == 0xff)
if (GetBattlerPosition(battlerId) == 0xff)
return FALSE;

if (!gBattleStruct->spriteIgnore0Hp)
Expand Down
2 changes: 1 addition & 1 deletion src/battle_controller_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions src/battle_controllers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
{
Expand All @@ -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)
{
Expand Down
16 changes: 8 additions & 8 deletions src/battle_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions src/battle_gfx_sfx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/battle_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand Down
Loading