From 1b1b0ac6ea1bb0ca11c2aa05411ece130f9cb98c Mon Sep 17 00:00:00 2001 From: Rangi Date: Mon, 7 Jan 2019 18:12:00 -0500 Subject: [PATCH] Document a bugfix: AI makes a false assumption about CheckTypeMatchup --- docs/bugs_and_glitches.md | 47 ++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/docs/bugs_and_glitches.md b/docs/bugs_and_glitches.md index 91c8dd578..f95d519cb 100644 --- a/docs/bugs_and_glitches.md +++ b/docs/bugs_and_glitches.md @@ -513,32 +513,33 @@ This bug existed for all battles in Gold and Silver, and was only fixed for sing ## AI makes a false assumption about `CheckTypeMatchup` -In [engine/battle/effect_commands.asm](/engine/battle/effect_commands.asm). +**Fix:** Edit `BattleCheckTypeMatchup` in [engine/battle/effect_commands.asm](/engine/battle/effect_commands.asm): -```asm -BattleCheckTypeMatchup: - ld hl, wEnemyMonType1 - ldh a, [hBattleTurn] - and a - jr z, CheckTypeMatchup - ld hl, wBattleMonType1 -CheckTypeMatchup: -; There is an incorrect assumption about this function made in the AI related code: when -; the AI calls CheckTypeMatchup (not BattleCheckTypeMatchup), it assumes that placing the -; offensive type in a will make this function do the right thing. Since a is overwritten, -; this assumption is incorrect. A simple fix would be to load the move type for the -; current move into a in BattleCheckTypeMatchup, before falling through, which is -; consistent with how the rest of the code assumes this code works like. - push hl - push de - push bc - ld a, BATTLE_VARS_MOVE_TYPE - call GetBattleVar - ld d, a +```diff + BattleCheckTypeMatchup: + ld hl, wEnemyMonType1 + ldh a, [hBattleTurn] + and a + jr z, CheckTypeMatchup + ld hl, wBattleMonType1 ++ ld a, BATTLE_VARS_MOVE_TYPE ++ call GetBattleVar ; preserves hl, de, and bc + CheckTypeMatchup: +-; There is an incorrect assumption about this function made in the AI related code: when +-; the AI calls CheckTypeMatchup (not BattleCheckTypeMatchup), it assumes that placing the +-; offensive type in a will make this function do the right thing. Since a is overwritten, +-; this assumption is incorrect. A simple fix would be to load the move type for the +-; current move into a in BattleCheckTypeMatchup, before falling through, which is +-; consistent with how the rest of the code assumes this code works like. + push hl + push de + push bc +- ld a, BATTLE_VARS_MOVE_TYPE +- call GetBattleVar + ld d, a + ... ``` -*To do:* Fix this bug. - ## NPC use of Full Heal or Full Restore does not cure Nightmare status