From 0530f49fd44c6d29e87f54991ea1d1337b14329c Mon Sep 17 00:00:00 2001 From: Pawkkie <61265402+Pawkkie@users.noreply.github.com> Date: Thu, 22 May 2025 15:05:02 -0400 Subject: [PATCH] Fix AI boosting stats into mon with Haze (#6894) --- src/battle_ai_util.c | 63 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index 6789fa58aa..1079cd7367 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -2192,6 +2192,31 @@ bool32 HasMoveWithEffect(u32 battlerId, enum BattleMoveEffects effect) return FALSE; } +bool32 HasBattlerSideMoveWithEffect(u32 battler, u32 effect) +{ + if (HasMoveWithEffect(battler, effect)) + return TRUE; + if (IsDoubleBattle() && HasMoveWithEffect(BATTLE_OPPOSITE(battler), effect)) + return TRUE; + return FALSE; +} + +// HasSideMoveWithMoveEffect checks if the AI knows a side has a move effect, +// while HasBattlerSideUsedMoveWithEffect checks if the side has ever used a move effect. +// The former acts the same way as the latter if AI_FLAG_OMNISCIENT isn't used. +bool32 HasBattlerSideUsedMoveWithEffect(u32 battler, u32 effect) +{ + u32 i; + for (i = 0; i < MAX_MON_MOVES; i++) + { + if (GetMoveEffect(gBattleHistory->usedMoves[battler][i]) == effect) + return TRUE; + if (IsDoubleBattle() && GetMoveEffect(gBattleHistory->usedMoves[BATTLE_OPPOSITE(battler)][i]) == effect) + return TRUE; + } + return FALSE; +} + bool32 HasNonVolatileMoveEffect(u32 battlerId, u32 effect) { s32 i; @@ -2237,6 +2262,31 @@ bool32 HasMoveWithAdditionalEffect(u32 battlerId, u32 moveEffect) return FALSE; } +bool32 HasBattlerSideMoveWithAdditionalEffect(u32 battler, u32 moveEffect) +{ + if (HasMoveWithAdditionalEffect(battler, moveEffect)) + return TRUE; + if (IsDoubleBattle() && HasMoveWithAdditionalEffect(BATTLE_OPPOSITE(battler), moveEffect)) + return TRUE; + return FALSE; +} + +// HasBattlerSideMoveWithAdditionalEffect checks if the AI knows a side has a move effect, +// while HasBattlerSideUsedMoveWithAdditionalEffect checks if the side has ever used a move effect. +// The former acts the same way as the latter if AI_FLAG_OMNISCIENT isn't used. +bool32 HasBattlerSideUsedMoveWithAdditionalEffect(u32 battler, u32 moveEffect) +{ + u32 i; + for (i = 0; i < MAX_MON_MOVES; i++) + { + if (MoveHasAdditionalEffect(gBattleHistory->usedMoves[battler][i], moveEffect)) + return TRUE; + if (IsDoubleBattle() && MoveHasAdditionalEffect(gBattleHistory->usedMoves[BATTLE_OPPOSITE(battler)][i], moveEffect)) + return TRUE; + } + return FALSE; +} + bool32 HasMoveWithCriticalHitChance(u32 battlerId) { s32 i; @@ -4071,10 +4121,19 @@ static enum AIScore IncreaseStatUpScoreInternal(u32 battlerAtk, u32 battlerDef, return NO_INCREASE; // Don't increase stats if opposing battler has Encore - if (HasMoveWithEffect(battlerDef, EFFECT_ENCORE)) + if (HasBattlerSideMoveWithEffect(battlerDef, EFFECT_ENCORE)) return NO_INCREASE; - if (IsDoubleBattle() && HasMoveWithEffect(GetPartnerBattler(battlerDef), EFFECT_ENCORE)) + // Don't increase stats if opposing battler has used Haze effect + if (HasBattlerSideUsedMoveWithEffect(battlerDef, EFFECT_HAZE) + || HasBattlerSideUsedMoveWithAdditionalEffect(battlerDef, MOVE_EFFECT_CLEAR_SMOG) + || HasBattlerSideUsedMoveWithAdditionalEffect(battlerDef, MOVE_EFFECT_HAZE)) + return NO_INCREASE; + + // Don't increase if AI is at +1 and opponent has Haze effect + if (gBattleMons[battlerAtk].statStages[statId] >= MAX_STAT_STAGE - 5 && (HasBattlerSideMoveWithEffect(battlerDef, EFFECT_HAZE) + || HasBattlerSideMoveWithAdditionalEffect(battlerDef, MOVE_EFFECT_CLEAR_SMOG) + || HasBattlerSideMoveWithAdditionalEffect(battlerDef, MOVE_EFFECT_HAZE))) return NO_INCREASE; // Predicting switch