From 75500c86ab9b3a73ab7c1c15f82a83d78c2e36d8 Mon Sep 17 00:00:00 2001 From: GGbond Date: Sun, 8 Feb 2026 18:50:59 +0800 Subject: [PATCH] Add missing weather checks for AI sandstorm/hail damage helpers (#9155) --- src/battle_ai_util.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index c607450315..83a93bb60c 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -3162,23 +3162,31 @@ static u32 GetPoisonDamage(u32 battlerId) return damage; } -static bool32 BattlerAffectedBySandstorm(u32 battlerId, enum Ability ability) +static bool32 DoesBattlerTakeSandstormDamage(u32 battlerId, enum Ability ability) { + if (!(AI_GetWeather() & B_WEATHER_SANDSTORM)) + return FALSE; + if (!IS_BATTLER_ANY_TYPE(battlerId, TYPE_ROCK, TYPE_GROUND, TYPE_STEEL) && ability != ABILITY_SAND_VEIL && ability != ABILITY_SAND_FORCE && ability != ABILITY_SAND_RUSH + && ability != ABILITY_MAGIC_GUARD && ability != ABILITY_OVERCOAT) return TRUE; return FALSE; } -static bool32 BattlerAffectedByHail(u32 battlerId, enum Ability ability) +static bool32 DoesBattlerTakeHailDamage(u32 battlerId, enum Ability ability) { + if (!(AI_GetWeather() & B_WEATHER_HAIL)) + return FALSE; + if (!IS_BATTLER_OF_TYPE(battlerId, TYPE_ICE) && ability != ABILITY_SNOW_CLOAK - && ability != ABILITY_OVERCOAT - && ability != ABILITY_ICE_BODY) + && ability != ABILITY_ICE_BODY + && ability != ABILITY_MAGIC_GUARD + && ability != ABILITY_OVERCOAT) return TRUE; return FALSE; } @@ -3194,7 +3202,7 @@ static u32 GetWeatherDamage(u32 battlerId) if (weather & B_WEATHER_SANDSTORM) { - if (BattlerAffectedBySandstorm(battlerId, ability) + if (DoesBattlerTakeSandstormDamage(battlerId, ability) && gBattleMons[battlerId].volatiles.semiInvulnerable != STATE_UNDERGROUND && gBattleMons[battlerId].volatiles.semiInvulnerable != STATE_UNDERWATER && holdEffect != HOLD_EFFECT_SAFETY_GOGGLES) @@ -3206,7 +3214,7 @@ static u32 GetWeatherDamage(u32 battlerId) } if ((weather & B_WEATHER_HAIL) && ability != ABILITY_ICE_BODY) { - if (BattlerAffectedByHail(battlerId, ability) + if (DoesBattlerTakeHailDamage(battlerId, ability) && gBattleMons[battlerId].volatiles.semiInvulnerable != STATE_UNDERGROUND && gBattleMons[battlerId].volatiles.semiInvulnerable != STATE_UNDERWATER && holdEffect != HOLD_EFFECT_SAFETY_GOGGLES) @@ -3238,8 +3246,11 @@ u32 GetBattlerSecondaryDamage(u32 battlerId) bool32 BattlerWillFaintFromWeather(u32 battler, enum Ability ability) { - if ((BattlerAffectedBySandstorm(battler, ability) || BattlerAffectedByHail(battler, ability)) - && gBattleMons[battler].hp <= max(1, gBattleMons[battler].maxHP / 16)) + if (gAiLogicData->holdEffects[battler] == HOLD_EFFECT_SAFETY_GOGGLES) + return FALSE; + + if ((DoesBattlerTakeSandstormDamage(battler, ability) || DoesBattlerTakeHailDamage(battler, ability)) + && gBattleMons[battler].hp <= max(1, GetNonDynamaxMaxHP(battler) / 16)) return TRUE; return FALSE;