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

Replace hp checks with IsBattlerAlive #4429

Merged
merged 5 commits into from
May 7, 2024
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
2 changes: 1 addition & 1 deletion src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4072,7 +4072,7 @@ static void TryDoEventsBeforeFirstTurn(void)
{
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))
if (!IsBattlerAlive(i) || gBattleMons[i].species == SPECIES_NONE || GetMonData(mon, MON_DATA_IS_EGG))
gAbsentBattlerFlags |= gBitTable[i];
}
}
Expand Down
54 changes: 27 additions & 27 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ static void Cmd_attackcanceler(void)
gCurrentActionFuncId = B_ACTION_FINISHED;
return;
}
if (gBattleMons[gBattlerAttacker].hp == 0 && !(gHitMarker & HITMARKER_NO_ATTACKSTRING))
if (!IsBattlerAlive(gBattlerAttacker) && !(gHitMarker & HITMARKER_NO_ATTACKSTRING))
{
gHitMarker |= HITMARKER_UNABLE_TO_USE_MOVE;
gBattlescriptCurrInstr = BattleScript_MoveEnd;
Expand Down Expand Up @@ -2798,7 +2798,7 @@ void SetMoveEffect(bool32 primary, bool32 certain)
return;

if (gSpecialStatuses[gBattlerAttacker].parentalBondState == PARENTAL_BOND_1ST_HIT
&& gBattleMons[gBattlerTarget].hp != 0
&& IsBattlerAlive(gBattlerTarget)
&& IsFinalStrikeEffect(gBattleScripting.moveEffect))
{
gBattlescriptCurrInstr++;
Expand Down Expand Up @@ -2862,7 +2862,7 @@ void SetMoveEffect(bool32 primary, bool32 certain)
&& gBattleScripting.moveEffect != MOVE_EFFECT_CHARGING)
INCREMENT_RESET_RETURN

if (gBattleMons[gEffectBattler].hp == 0 && !activateAfterFaint)
if (!IsBattlerAlive(gEffectBattler) && !activateAfterFaint)
INCREMENT_RESET_RETURN

if (DoesSubstituteBlockMove(gBattlerAttacker, gEffectBattler, gCurrentMove) && affectsUser != MOVE_EFFECT_AFFECTS_USER)
Expand Down Expand Up @@ -4010,7 +4010,7 @@ static void Cmd_tryfaintmon(void)
faintScript = BattleScript_FaintTarget;
}
if (!(gAbsentBattlerFlags & gBitTable[battler])
&& gBattleMons[battler].hp == 0)
&& !IsBattlerAlive(battler))
{
gHitMarker |= HITMARKER_FAINTED(battler);
BattleScriptPush(cmd->nextInstr);
Expand All @@ -4030,7 +4030,7 @@ static void Cmd_tryfaintmon(void)
gBattleResults.lastOpponentSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[battler]], MON_DATA_SPECIES, NULL);
gSideTimers[B_SIDE_OPPONENT].retaliateTimer = 2;
}
if ((gHitMarker & HITMARKER_DESTINYBOND) && gBattleMons[gBattlerAttacker].hp != 0
if ((gHitMarker & HITMARKER_DESTINYBOND) && IsBattlerAlive(gBattlerAttacker)
&& !IsDynamaxed(gBattlerAttacker))
{
gHitMarker &= ~HITMARKER_DESTINYBOND;
Expand All @@ -4041,7 +4041,7 @@ static void Cmd_tryfaintmon(void)
if ((gStatuses3[gBattlerTarget] & STATUS3_GRUDGE)
&& !(gHitMarker & HITMARKER_GRUDGE)
&& GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)
&& gBattleMons[gBattlerAttacker].hp != 0
&& IsBattlerAlive(gBattlerAttacker)
&& gCurrentMove != MOVE_STRUGGLE)
{
u8 moveIndex = *(gBattleStruct->chosenMovePositions + gBattlerAttacker);
Expand Down Expand Up @@ -4083,7 +4083,7 @@ static void Cmd_cleareffectsonfaint(void)
{
u32 battler = GetBattlerForBattleScript(cmd->battler);
const u8 *clearDataResult = NULL;
if (!(gBattleTypeFlags & BATTLE_TYPE_ARENA) || gBattleMons[battler].hp == 0)
if (!(gBattleTypeFlags & BATTLE_TYPE_ARENA) || !IsBattlerAlive(battler))
{
gBattleMons[battler].status1 = 0;
BtlController_EmitSetMonData(battler, BUFFER_A, REQUEST_STATUS_BATTLE, 0, sizeof(gBattleMons[battler].status1), &gBattleMons[battler].status1);
Expand All @@ -4106,7 +4106,7 @@ static void Cmd_jumpifstatus(void)
u32 flags = cmd->flags;
const u8 *jumpInstr = cmd->jumpInstr;

if (gBattleMons[battler].status1 & flags && gBattleMons[battler].hp != 0)
if (gBattleMons[battler].status1 & flags && IsBattlerAlive(battler))
gBattlescriptCurrInstr = jumpInstr;
else
gBattlescriptCurrInstr = cmd->nextInstr;
Expand All @@ -4120,7 +4120,7 @@ static void Cmd_jumpifstatus2(void)
u32 flags = cmd->flags;
const u8 *jumpInstr = cmd->jumpInstr;

if (gBattleMons[battler].status2 & flags && gBattleMons[battler].hp != 0)
if (gBattleMons[battler].status2 & flags && IsBattlerAlive(battler))
gBattlescriptCurrInstr = jumpInstr;
else
gBattlescriptCurrInstr = cmd->nextInstr;
Expand Down Expand Up @@ -5407,14 +5407,14 @@ static bool32 TryKnockOffBattleScript(u32 battlerDef)
return FALSE;
}

#define SYMBIOSIS_CHECK(battler, ally) \
#define SYMBIOSIS_CHECK(battler, ally) \
GetBattlerAbility(ally) == ABILITY_SYMBIOSIS \
&& gBattleMons[battler].item == ITEM_NONE \
&& gBattleMons[ally].item != ITEM_NONE \
&& CanBattlerGetOrLoseItem(battler, gBattleMons[ally].item) \
&& CanBattlerGetOrLoseItem(ally, gBattleMons[ally].item) \
&& gBattleMons[battler].hp != 0 \
&& gBattleMons[ally].hp != 0
&& IsBattlerAlive(battler) \
&& IsBattlerAlive(ally)

static u32 GetNextTarget(u32 moveTarget, bool32 excludeCurrent)
{
Expand Down Expand Up @@ -5549,7 +5549,7 @@ static void Cmd_moveend(void)
break;
case MOVEEND_RAGE: // rage check
if (gBattleMons[gBattlerTarget].status2 & STATUS2_RAGE
&& gBattleMons[gBattlerTarget].hp != 0
&& IsBattlerAlive(gBattlerTarget)
&& gBattlerAttacker != gBattlerTarget
&& GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)
&& !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT)
Expand All @@ -5566,7 +5566,7 @@ static void Cmd_moveend(void)
break;
case MOVEEND_DEFROST: // defrosting check
if (gBattleMons[gBattlerTarget].status1 & STATUS1_FREEZE
&& gBattleMons[gBattlerTarget].hp != 0
&& IsBattlerAlive(gBattlerTarget)
&& gBattlerAttacker != gBattlerTarget
&& (moveType == TYPE_FIRE || CanBurnHitThaw(gCurrentMove))
&& !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT))
Expand All @@ -5579,7 +5579,7 @@ static void Cmd_moveend(void)
effect = TRUE;
}
if (gBattleMons[gBattlerTarget].status1 & STATUS1_FROSTBITE
&& gBattleMons[gBattlerTarget].hp != 0
&& IsBattlerAlive(gBattlerTarget)
&& gBattlerAttacker != gBattlerTarget
&& gMovesInfo[originallyUsedMove].thawsUser
&& !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT))
Expand Down Expand Up @@ -6453,7 +6453,7 @@ static void Cmd_switchindataupdate(void)
monData[i] = gBattleResources->bufferB[battler][4 + i];

// Edge case: the sent out pokemon has 0 HP. This should never happen.
if (gBattleMons[battler].hp == 0)
if (!IsBattlerAlive(battler))
{
// If it's a test, mark it as invalid.
if (gTestRunnerEnabled)
Expand Down Expand Up @@ -6506,7 +6506,7 @@ static void Cmd_switchindataupdate(void)

if (gBattleTypeFlags & BATTLE_TYPE_PALACE
&& gBattleMons[battler].maxHP / 2 >= gBattleMons[battler].hp
&& gBattleMons[battler].hp != 0
&& IsBattlerAlive(battler)
&& !(gBattleMons[battler].status1 & STATUS1_SLEEP))
{
gBattleStruct->palaceFlags |= gBitTable[battler];
Expand Down Expand Up @@ -8359,7 +8359,7 @@ static void Cmd_hpthresholds(void)
if (result == 0)
result = 1;

if (result > 69 || gBattleMons[opposingBattler].hp == 0)
if (result > 69 || !IsBattlerAlive(opposingBattler))
gBattleStruct->hpScale = 0;
else if (result > 39)
gBattleStruct->hpScale = 1;
Expand Down Expand Up @@ -9208,8 +9208,8 @@ static void Cmd_various(void)
VARIOUS_ARGS();
if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_DOUBLE))
&& gBattleTypeFlags & BATTLE_TYPE_TRAINER
&& gBattleMons[0].hp != 0
&& gBattleMons[1].hp != 0)
&& IsBattlerAlive(B_POSITION_PLAYER_LEFT)
&& IsBattlerAlive(B_POSITION_OPPONENT_LEFT))
{
gHitMarker &= ~HITMARKER_PLAYER_FAINTED;
}
Expand All @@ -9223,7 +9223,7 @@ static void Cmd_various(void)
gBattleScripting.battler = battler = gBattleCommunication[1];
if (!(gBattleStruct->palaceFlags & gBitTable[battler])
&& gBattleMons[battler].maxHP / 2 >= gBattleMons[battler].hp
&& gBattleMons[battler].hp != 0
&& IsBattlerAlive(battler)
&& !(gBattleMons[battler].status1 & STATUS1_SLEEP))
{
gBattleStruct->palaceFlags |= gBitTable[battler];
Expand Down Expand Up @@ -9323,7 +9323,7 @@ static void Cmd_various(void)
{
VARIOUS_ARGS();
battler = 1;
if (gBattleMons[battler].hp != 0)
if (IsBattlerAlive(battler))
{
BtlController_EmitReturnMonToBall(battler, BUFFER_A, FALSE);
MarkBattlerForControllerExec(battler);
Expand All @@ -9336,7 +9336,7 @@ static void Cmd_various(void)
if (gBattlersCount > 3)
{
battler = 3;
if (gBattleMons[battler].hp != 0)
if (IsBattlerAlive(battler))
{
BtlController_EmitReturnMonToBall(battler, BUFFER_A, FALSE);
MarkBattlerForControllerExec(battler);
Expand Down Expand Up @@ -11438,7 +11438,7 @@ static void Cmd_stockpiletobasedamage(void)
if (gBattleCommunication[MISS_TYPE] != B_MSG_PROTECTED)
gBattleScripting.animTurn = gDisableStructs[gBattlerAttacker].stockpileCounter;

if (!(gSpecialStatuses[gBattlerAttacker].parentalBondState == PARENTAL_BOND_1ST_HIT && gBattleMons[gBattlerTarget].hp != 0))
if (!(gSpecialStatuses[gBattlerAttacker].parentalBondState == PARENTAL_BOND_1ST_HIT && IsBattlerAlive(gBattlerTarget)))
{
gBattleStruct->moveEffect2 = MOVE_EFFECT_STOCKPILE_WORE_OFF;
}
Expand Down Expand Up @@ -13815,7 +13815,7 @@ static void Cmd_trydobeatup(void)
CMD_ARGS(const u8 *endInstr, const u8 *failInstr);
struct Pokemon *party = GetBattlerParty(gBattlerAttacker);

if (gBattleMons[gBattlerTarget].hp == 0)
if (!IsBattlerAlive(gBattlerTarget))
{
gBattlescriptCurrInstr = cmd->endInstr;
}
Expand Down Expand Up @@ -14640,7 +14640,7 @@ static void Cmd_jumpifhasnohp(void)

u32 battler = GetBattlerForBattleScript(cmd->battler);

if (gBattleMons[battler].hp == 0)
if (!IsBattlerAlive(battler))
gBattlescriptCurrInstr = cmd->jumpInstr;
else
gBattlescriptCurrInstr = cmd->nextInstr;
Expand Down Expand Up @@ -15903,7 +15903,7 @@ void BS_CheckParentalBondCounter(void)
NATIVE_ARGS(u8 counter, const u8 *jumpInstr);
// Some effects should only happen on the first or second strike of Parental Bond,
// so a way to check this in battle scripts is useful
if (gSpecialStatuses[gBattlerAttacker].parentalBondState == cmd->counter && gBattleMons[gBattlerTarget].hp != 0)
if (gSpecialStatuses[gBattlerAttacker].parentalBondState == cmd->counter && IsBattlerAlive(gBattlerTarget))
gBattlescriptCurrInstr = cmd->jumpInstr;
else
gBattlescriptCurrInstr = cmd->nextInstr;
Expand Down
Loading
Loading