From 983c33b5c9ab8bc88083469f3ebd64d1848a6ebf Mon Sep 17 00:00:00 2001 From: MichailTalReborn Date: Thu, 12 Mar 2026 16:44:29 +0100 Subject: [PATCH] Document bug: AI does not discourage Nightmare if the player has any status condition (#1242) --- docs/bugs_and_glitches.md | 21 ++++++++++++++++++++- engine/battle/ai/redundant.asm | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/bugs_and_glitches.md b/docs/bugs_and_glitches.md index ae8cec4fb..bd2b5fba5 100644 --- a/docs/bugs_and_glitches.md +++ b/docs/bugs_and_glitches.md @@ -54,6 +54,7 @@ Fixes in the [multi-player battle engine](#multi-player-battle-engine) category - ["Smart" AI discourages Conversion2 after the first turn](#smart-ai-discourages-conversion2-after-the-first-turn) - ["Smart" AI does not encourage Solar Beam, Flame Wheel, or Moonlight during Sunny Day](#smart-ai-does-not-encourage-solar-beam-flame-wheel-or-moonlight-during-sunny-day) - ["Cautious" AI may fail to discourage residual moves](#cautious-ai-may-fail-to-discourage-residual-moves) + - [AI does not discourage Nightmare if the player has any status condition](#ai-does-not-discourage-nightmare-if-the-player-has-any-status-condition) - [AI does not discourage Future Sight when it's already been used](#ai-does-not-discourage-future-sight-when-its-already-been-used) - [AI makes a false assumption about `CheckTypeMatchup`](#ai-makes-a-false-assumption-about-checktypematchup) - [AI use of Full Heal or Full Restore does not cure Nightmare status](#ai-use-of-full-heal-or-full-restore-does-not-cure-nightmare-status) @@ -1355,9 +1356,26 @@ AI_Cautious: ``` +### AI does not discourage Nightmare if the player has any status condition + +**Fix** Edit `AI_Redundant.Nightmare` in [engine/battle/ai/redundant.asm](https://github.com/pret/pokecrystal/blob/master/engine/battle/ai/redundant.asm): + +```diff + .Nightmare: +-; BUG: AI does not discourage Nightmare if the player has any status condition (see docs/bugs_and_glitches.md) + ld a, [wBattleMonStatus] +- and a ++ and SLP_MASK + jr z, .Redundant + ld a, [wPlayerSubStatus1] + bit SUBSTATUS_NIGHTMARE, a + ret +``` + + ### AI does not discourage Future Sight when it's already been used -**Fix:** Edit `AI_Redundant` in [engine/battle/ai/redundant.asm](https://github.com/pret/pokecrystal/blob/master/engine/battle/ai/redundant.asm): +**Fix:** Edit `AI_Redundant.FutureSight` in [engine/battle/ai/redundant.asm](https://github.com/pret/pokecrystal/blob/master/engine/battle/ai/redundant.asm): ```diff .FutureSight: @@ -1480,6 +1498,7 @@ AI_Cautious: ret ``` + ### AI might use its base reward value as an item In the `AI_TryItem` routine, an item pointer is set to `wEnemyTrainerItem1` and then increments to `wEnemyTrainerItem2` to see if either of the AI's items are in the `AI_Items` list. However, if the AI has used its first item (or its first one is `ITEM_NONE`) and hasn't used its second item, the item pointer can increment from `wEnemyTrainerItem2` to `wEnemyTrainerBaseReward`. If the value at this address then matches an item in the `AI_Items` list, the AI could mistakenly use it. diff --git a/engine/battle/ai/redundant.asm b/engine/battle/ai/redundant.asm index bb9338fb7..98a22640c 100644 --- a/engine/battle/ai/redundant.asm +++ b/engine/battle/ai/redundant.asm @@ -112,6 +112,7 @@ AI_Redundant: ret .Nightmare: +; BUG: AI does not discourage Nightmare if the player has any status condition (see docs/bugs_and_glitches.md) ld a, [wBattleMonStatus] and a jr z, .Redundant