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

GetBattlerHoldEffect usage optimizations #3330

Merged
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
12 changes: 6 additions & 6 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -11431,8 +11431,7 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
{
bool32 certain = FALSE;
bool32 notProtectAffected = FALSE;
u32 index, battler;
u16 battlerAbility;
u32 index, battler, battlerAbility, battlerHoldEffect;
bool32 affectsUser = (flags & MOVE_EFFECT_AFFECTS_USER);
bool32 mirrorArmored = (flags & STAT_CHANGE_MIRROR_ARMOR);

Expand All @@ -11442,6 +11441,7 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
battler = gBattlerTarget;

battlerAbility = GetBattlerAbility(battler);
battlerHoldEffect = GetBattlerHoldEffect(battler, TRUE);

gSpecialStatuses[battler].changedStatsBattlerId = gBattlerAttacker;

Expand Down Expand Up @@ -11500,13 +11500,13 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
gBattlescriptCurrInstr = BattleScript_ButItFailed;
return STAT_CHANGE_DIDNT_WORK;
}
else if ((GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_CLEAR_AMULET
else if ((battlerHoldEffect == HOLD_EFFECT_CLEAR_AMULET
|| battlerAbility == ABILITY_CLEAR_BODY
|| battlerAbility == ABILITY_FULL_METAL_BODY
|| battlerAbility == ABILITY_WHITE_SMOKE)
&& (!affectsUser || mirrorArmored) && !certain && gCurrentMove != MOVE_CURSE)
{
if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_CLEAR_AMULET)
if (battlerHoldEffect == HOLD_EFFECT_CLEAR_AMULET)
{
RecordItemEffectBattle(battler, HOLD_EFFECT_CLEAR_AMULET);
}
Expand All @@ -11521,7 +11521,7 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
{
BattleScriptPush(BS_ptr);
gBattleScripting.battler = battler;
if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_CLEAR_AMULET)
if (battlerHoldEffect == HOLD_EFFECT_CLEAR_AMULET)
{
gBattlescriptCurrInstr = BattleScript_ItemNoStatLoss;
}
Expand Down Expand Up @@ -11591,7 +11591,7 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
RecordAbilityBattle(battler, ABILITY_SHIELD_DUST);
return STAT_CHANGE_DIDNT_WORK;
}
else if (flags == 0 && GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_COVERT_CLOAK)
else if (flags == 0 && battlerHoldEffect == HOLD_EFFECT_COVERT_CLOAK)
{
RecordItemEffectBattle(battler, HOLD_EFFECT_COVERT_CLOAK);
return STAT_CHANGE_DIDNT_WORK;
Expand Down
6 changes: 4 additions & 2 deletions src/battle_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -8288,7 +8288,9 @@ bool32 IsBattlerProtected(u8 battler, u16 move)
// Only called directly when calculating damage type effectiveness
static bool32 IsBattlerGrounded2(u8 battler, bool32 considerInverse)
{
if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_IRON_BALL)
u32 holdEffect = GetBattlerHoldEffect(battler, TRUE);

if (holdEffect == HOLD_EFFECT_IRON_BALL)
return TRUE;
if (gFieldStatuses & STATUS_FIELD_GRAVITY)
return TRUE;
Expand All @@ -8302,7 +8304,7 @@ static bool32 IsBattlerGrounded2(u8 battler, bool32 considerInverse)
return FALSE;
if (gStatuses3[battler] & STATUS3_MAGNET_RISE)
return FALSE;
if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_AIR_BALLOON)
if (holdEffect == HOLD_EFFECT_AIR_BALLOON)
return FALSE;
if (GetBattlerAbility(battler) == ABILITY_LEVITATE)
return FALSE;
Expand Down
Loading