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

GetSideParty/GetBattlerParty #2910

Merged
merged 2 commits into from
Apr 26, 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
11 changes: 11 additions & 0 deletions include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,17 @@ struct BattleStruct
#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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have added #include "battle_anim.h" to the top of this file instead of declaring GetBattlerSide. I don't really mind which approach is chosen.

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
1 change: 0 additions & 1 deletion include/battle_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ bool32 SetIllusionMon(struct Pokemon *mon, u32 battlerId);
bool8 ShouldGetStatBadgeBoost(u16 flagId, u8 battlerId);
u8 GetBattleMoveSplit(u32 moveId);
bool32 TestMoveFlags(u16 move, u32 flag);
struct Pokemon *GetBattlerPartyData(u8 battlerId);
bool32 CanFling(u8 battlerId);
bool32 IsTelekinesisBannedSpecies(u16 species);
bool32 IsHealBlockPreventingMove(u32 battler, u32 move);
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 @@ -3420,7 +3420,7 @@ bool32 IsPartyFullyHealedExceptBattler(u8 battlerId)
bool32 PartyHasMoveSplit(u8 battlerId, u8 split)
{
u8 firstId, lastId;
struct Pokemon* party = GetBattlerPartyData(battlerId);
struct Pokemon *party = GetBattlerParty(battlerId);
u32 i, j;

for (i = 0; i < PARTY_SIZE; i++)
Expand Down
3 changes: 0 additions & 3 deletions src/battle_anim_new.c
Original file line number Diff line number Diff line change
Expand Up @@ -7897,9 +7897,6 @@ void AnimTask_TerrainPulse(u8 taskId)

void AnimTask_AffectionHangedOn(u8 taskId)
{
int side = GetBattlerSide(gBattleAnimTarget);
struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty;

gBattleAnimArgs[0] = GetBattlerFriendshipScore(gBattleAnimTarget);
DestroyAnimVisualTask(taskId);
}
7 changes: 5 additions & 2 deletions src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3800,7 +3800,9 @@ static void TryDoEventsBeforeFirstTurn(void)
{
for (i = 0; i < gBattlersCount; i++)
{
if (gBattleMons[i].hp == 0 || gBattleMons[i].species == SPECIES_NONE || GetMonData(GetBattlerPartyData(i), MON_DATA_IS_EGG))
struct Pokemon *party = GetBattlerParty(i);
struct Pokemon *mon = &party[gBattlerPartyIndexes[i]];
if (gBattleMons[i].hp == 0 || gBattleMons[i].species == SPECIES_NONE || GetMonData(mon, MON_DATA_IS_EGG))
gAbsentBattlerFlags |= gBitTable[i];
}
}
Expand Down Expand Up @@ -5047,7 +5049,8 @@ static void CheckMegaEvolutionBeforeTurn(void)
if (gBattleStruct->mega.toEvolve & gBitTable[gActiveBattler]
&& !(gProtectStructs[gActiveBattler].noValidMoves))
{
struct Pokemon *mon = GetBattlerPartyData(gActiveBattler);
struct Pokemon *party = GetBattlerParty(gActiveBattler);
struct Pokemon *mon = &party[gBattlerPartyIndexes[gActiveBattler]];

gBattleStruct->mega.toEvolve &= ~(gBitTable[gActiveBattler]);
gLastUsedItem = gBattleMons[gActiveBattler].item;
Expand Down
53 changes: 14 additions & 39 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -6515,10 +6515,7 @@ bool32 CanBattlerSwitch(u32 battlerId)
}
else if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER)
{
if (GetBattlerSide(battlerId) == B_SIDE_OPPONENT)
party = gEnemyParty;
else
party = gPlayerParty;
party = GetBattlerParty(battlerId);

lastMonId = 0;
if (battlerId & 2)
Expand Down Expand Up @@ -6559,10 +6556,7 @@ bool32 CanBattlerSwitch(u32 battlerId)
}
else
{
if (GetBattlerSide(battlerId) == B_SIDE_OPPONENT)
party = gEnemyParty;
else
party = gPlayerParty;
party = GetBattlerParty(battlerId);

lastMonId = 0;
if (GetLinkTrainerFlankId(GetBattlerMultiplayerId(battlerId)) == TRUE)
Expand Down Expand Up @@ -7716,10 +7710,7 @@ static void Cmd_drawpartystatussummary(void)

gActiveBattler = GetBattlerForBattleScript(cmd->battler);

if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER)
party = gPlayerParty;
else
party = gEnemyParty;
party = GetBattlerParty(gActiveBattler);

for (i = 0; i < PARTY_SIZE; i++)
{
Expand Down Expand Up @@ -8793,7 +8784,8 @@ static bool32 CourtChangeSwapSideStatuses(void)

static void HandleScriptMegaPrimal(u32 caseId, u32 battlerId, bool32 isMega)
{
struct Pokemon *mon = GetBattlerPartyData(battlerId);
struct Pokemon *party = GetBattlerParty(battlerId);
struct Pokemon *mon = &party[gBattlerPartyIndexes[battlerId]];
u32 position = GetBattlerPosition(battlerId);
u32 side = GET_BATTLER_SIDE(battlerId);

Expand Down Expand Up @@ -8861,8 +8853,7 @@ static void HandleScriptMegaPrimal(u32 caseId, u32 battlerId, bool32 isMega)

static bool32 CanTeleport(u8 battlerId)
{
u8 side = GetBattlerSide(battlerId);
struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty;
struct Pokemon *party = GetBattlerParty(battlerId);
u32 species, count, i;

for (i = 0; i < PARTY_SIZE; i++)
Expand Down Expand Up @@ -11289,7 +11280,7 @@ static void Cmd_various(void)
// Battler selected! Revive and go to next instruction.
if (gSelectedMonPartyId != PARTY_SIZE)
{
struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty;
struct Pokemon *party = GetSideParty(side);

u16 hp = GetMonData(&party[gSelectedMonPartyId], MON_DATA_MAX_HP) / 2;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_HP_BATTLE, gBitTable[gSelectedMonPartyId], sizeof(hp), &hp);
Expand Down Expand Up @@ -12397,10 +12388,7 @@ static void Cmd_forcerandomswitch(void)
|| redCardForcedSwitch
)
{
if (GetBattlerSide(gBattlerTarget) == B_SIDE_PLAYER)
party = gPlayerParty;
else
party = gEnemyParty;
party = GetBattlerParty(gBattlerTarget);

if (BATTLE_TWO_VS_ONE_OPPONENT && GetBattlerSide(gBattlerTarget) == B_SIDE_OPPONENT)
{
Expand Down Expand Up @@ -13599,16 +13587,11 @@ static void Cmd_healpartystatus(void)

if (gCurrentMove == MOVE_HEAL_BELL)
{
struct Pokemon *party;
struct Pokemon *party = GetBattlerParty(gBattlerAttacker);
s32 i;

gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_BELL;

if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER)
party = gPlayerParty;
else
party = gEnemyParty;

if (GetBattlerAbility(gBattlerAttacker) != ABILITY_SOUNDPROOF)
{
gBattleMons[gBattlerAttacker].status1 = 0;
Expand Down Expand Up @@ -14236,12 +14219,7 @@ static void Cmd_trydobeatup(void)
gBattleStruct->beatUpSlot++;
gBattlescriptCurrInstr = cmd->nextInstr;
#else
struct Pokemon *party;

if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER)
party = gPlayerParty;
else
party = gEnemyParty;
struct Pokemon *party = GetBattlerParty(gBattlerAttacker);

if (gBattleMons[gBattlerTarget].hp == 0)
{
Expand Down Expand Up @@ -14935,10 +14913,7 @@ static void Cmd_assistattackselect(void)

if (validMoves != NULL)
{
if (GET_BATTLER_SIDE(gBattlerAttacker) != B_SIDE_PLAYER)
party = gEnemyParty;
else
party = gPlayerParty;
party = GetBattlerParty(gBattlerAttacker);

for (monId = 0; monId < PARTY_SIZE; monId++)
{
Expand Down Expand Up @@ -16467,7 +16442,7 @@ u8 GetFirstFaintedPartyIndex(u8 battlerId)
u32 i;
u32 start = 0;
u32 end = PARTY_SIZE;
struct Pokemon *party = (GetBattlerSide(battlerId) == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty;
struct Pokemon *party = GetBattlerParty(battlerId);

// Check whether partner is separate trainer.
if ((GetBattlerSide(battlerId) == B_SIDE_PLAYER && gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER)
Expand Down Expand Up @@ -16506,7 +16481,7 @@ void BS_ItemRestoreHP(void) {
u32 battlerId = MAX_BATTLERS_COUNT;
u32 healParam = GetItemEffect(gLastUsedItem)[6];
u32 side = GetBattlerSide(gBattlerAttacker);
struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty;
struct Pokemon *party = GetSideParty(side);
u16 hp = GetMonData(&party[gBattleStruct->itemPartyIndex[gBattlerAttacker]], MON_DATA_HP);
u16 maxHP = GetMonData(&party[gBattleStruct->itemPartyIndex[gBattlerAttacker]], MON_DATA_MAX_HP);
gBattleCommunication[MULTIUSE_STATE] = 0;
Expand Down Expand Up @@ -16564,7 +16539,7 @@ void BS_ItemRestoreHP(void) {

void BS_ItemCureStatus(void) {
NATIVE_ARGS();
struct Pokemon *party = (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty;
struct Pokemon *party = GetBattlerParty(gBattlerAttacker);

// Heal Status1 conditions.
HealStatusConditions(&party[gBattleStruct->itemPartyIndex[gBattlerAttacker]], gBattleStruct->itemPartyIndex[gBattlerAttacker], GetItemStatus1Mask(gLastUsedItem), gBattlerAttacker);
Expand Down
55 changes: 11 additions & 44 deletions src/battle_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,9 @@ static const u16 sEntrainmentTargetSimpleBeamBannedAbilities[] =

static u8 CalcBeatUpPower(void)
{
struct Pokemon *party;
u8 basePower;
u16 species;

if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER)
party = gPlayerParty;
else
party = gEnemyParty;
struct Pokemon *party = GetBattlerParty(gBattlerAttacker);

// Party slot is incremented by the battle script for Beat Up after this damage calculation
species = GetMonData(&party[gBattleStruct->beatUpSlot], MON_DATA_SPECIES);
Expand Down Expand Up @@ -1995,7 +1990,7 @@ u8 GetImprisonedMovesCount(u8 battlerId, u16 move)
u32 GetBattlerFriendshipScore(u8 battlerId)
{
u8 side = GetBattlerSide(battlerId);
struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty;
struct Pokemon *party = GetSideParty(side);
u16 species = GetMonData(&party[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES);

if (side != B_SIDE_PLAYER)
Expand Down Expand Up @@ -3755,14 +3750,9 @@ u8 AtkCanceller_UnableToUseMove(void)
#if B_BEAT_UP >= GEN_5
else if (gBattleMoves[gCurrentMove].effect == EFFECT_BEAT_UP)
{
struct Pokemon* party;
struct Pokemon* party = GetBattlerParty(gBattlerAttacker);
int i;

if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER)
party = gPlayerParty;
else
party = gEnemyParty;

for (i = 0; i < PARTY_SIZE; i++)
{
if (GetMonData(&party[i], MON_DATA_HP)
Expand Down Expand Up @@ -3859,10 +3849,7 @@ bool8 HasNoMonsToSwitch(u8 battler, u8 partyIdBattlerOn1, u8 partyIdBattlerOn2)
}
else if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER)
{
if (GetBattlerSide(battler) == B_SIDE_PLAYER)
party = gPlayerParty;
else
party = gEnemyParty;
party = GetBattlerParty(battler);

playerId = ((battler & BIT_FLANK) / 2);
for (i = playerId * MULTI_PARTY_SIZE; i < playerId * MULTI_PARTY_SIZE + MULTI_PARTY_SIZE; i++)
Expand Down Expand Up @@ -3896,12 +3883,7 @@ bool8 HasNoMonsToSwitch(u8 battler, u8 partyIdBattlerOn1, u8 partyIdBattlerOn2)
else
{
flankId = GetBattlerMultiplayerId(battler);

if (GetBattlerSide(battler) == B_SIDE_PLAYER)
party = gPlayerParty;
else
party = gEnemyParty;

party = GetBattlerParty(battler);
playerId = GetLinkTrainerFlankId(flankId);
}

Expand Down Expand Up @@ -4070,7 +4052,7 @@ static void ShouldChangeFormInWeather(u8 battler)
{
int i;
int side = GetBattlerSide(battler);
struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty;
struct Pokemon *party = GetSideParty(side);

for (i = 0; i < PARTY_SIZE; i++)
{
Expand Down Expand Up @@ -4261,8 +4243,7 @@ bool8 ChangeTypeBasedOnTerrain(u8 battlerId)
static u16 GetSupremeOverlordModifier(u8 battlerId)
{
u32 i;
u8 side = GetBattlerSide(battlerId);
struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty;
struct Pokemon *party = GetBattlerParty(battlerId);
u16 modifier = UQ_4_12(1.0);
bool8 appliedFirstBoost = FALSE;

Expand Down Expand Up @@ -7291,11 +7272,11 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn)
case HOLD_EFFECT_RESTORE_PP:
if (!moveTurn)
{
struct Pokemon *mon;
struct Pokemon *party = GetBattlerParty(battlerId);
struct Pokemon *mon = &party[gBattlerPartyIndexes[battlerId]];
u8 ppBonuses;
u16 move;

mon = GetBattlerPartyData(battlerId);
for (i = 0; i < MAX_MON_MOVES; i++)
{
move = GetMonData(mon, MON_DATA_MOVE1 + i);
Expand Down Expand Up @@ -10169,7 +10150,7 @@ void UndoMegaEvolution(u32 monId)
void UndoFormChange(u32 monId, u32 side, bool32 isSwitchingOut)
{
u32 i, currSpecies, targetSpecies;
struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty;
struct Pokemon *party = GetSideParty(side);
static const u16 species[][3] =
{
// Changed Form ID Default Form ID Should change on switch
Expand Down Expand Up @@ -10304,10 +10285,7 @@ bool32 SetIllusionMon(struct Pokemon *mon, u32 battlerId)
if (GetMonAbility(mon) != ABILITY_ILLUSION)
return FALSE;

if (GetBattlerSide(battlerId) == B_SIDE_PLAYER)
party = gPlayerParty;
else
party = gEnemyParty;
party = GetBattlerParty(battlerId);

if (IsBattlerAlive(BATTLE_PARTNER(battlerId)))
partnerMon = &party[gBattlerPartyIndexes[BATTLE_PARTNER(battlerId)]];
Expand Down Expand Up @@ -10432,17 +10410,6 @@ bool32 TestMoveFlags(u16 move, u32 flag)
return FALSE;
}

struct Pokemon *GetBattlerPartyData(u8 battlerId)
{
struct Pokemon *mon;
if (GetBattlerSide(battlerId) == B_SIDE_PLAYER)
mon = &gPlayerParty[gBattlerPartyIndexes[battlerId]];
else
mon = &gEnemyParty[gBattlerPartyIndexes[battlerId]];

return mon;
}

static u8 GetFlingPowerFromItemId(u16 itemId)
{
if (itemId >= ITEM_TM01 && itemId <= ITEM_HM08)
Expand Down