ref: 650686476c47d03148dfb93de1388b1a7294e385
parent: 0e3857eac7b849515ff98ac9b6cad82cbd3a12c7
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Wed Oct 21 17:34:18 EDT 2020
Identify remaining battle AI labels
--- a/constants/battle_constants.asm
+++ b/constants/battle_constants.asm
@@ -28,6 +28,9 @@
NOT_VERY_EFFECTIVE EQU 05
NO_EFFECT EQU 00
+; enemy AI behavior
+BASE_AI_SWITCH_SCORE EQU 10
+
; wPlayerStatLevels and wEnemyStatLevels indexes (see wram.asm)
; GetStatName arguments (see data/battle/stat_names.asm)
const_def
--- a/engine/battle/ai/scoring.asm
+++ b/engine/battle/ai/scoring.asm
@@ -445,48 +445,48 @@
AI_Smart_LockOn:
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_LOCK_ON, a
- jr nz, .asm_38882
+ jr nz, .player_locked_on
push hl
call AICheckEnemyQuarterHP
- jr nc, .asm_38877
+ jr nc, .discourage
call AICheckEnemyHalfHP
- jr c, .asm_38834
+ jr c, .skip_speed_check
call AICompareSpeed
- jr nc, .asm_38877
+ jr nc, .discourage
-.asm_38834
+.skip_speed_check
ld a, [wPlayerEvaLevel]
cp BASE_STAT_LEVEL + 3
- jr nc, .asm_3887a
+ jr nc, .maybe_encourage
cp BASE_STAT_LEVEL + 1
- jr nc, .asm_38875
+ jr nc, .do_nothing
ld a, [wEnemyAccLevel]
cp BASE_STAT_LEVEL - 2
- jr c, .asm_3887a
+ jr c, .maybe_encourage
cp BASE_STAT_LEVEL
- jr c, .asm_38875
+ jr c, .do_nothing
ld hl, wEnemyMonMoves
ld c, NUM_MOVES + 1
-.asm_3884f
+.checkmove
dec c
- jr z, .asm_38877
+ jr z, .discourage
ld a, [hli]
and a
- jr z, .asm_38877
+ jr z, .discourage
call AIGetEnemyMove
ld a, [wEnemyMoveStruct + MOVE_ACC]
cp 71 percent - 1
- jr nc, .asm_3884f
+ jr nc, .checkmove
- ld a, $1
+ ld a, 1
ldh [hBattleTurn], a
push hl
@@ -496,18 +496,18 @@
cp EFFECTIVE
pop bc
pop hl
- jr c, .asm_3884f
+ jr c, .checkmove
-.asm_38875
+.do_nothing
pop hl
ret
-.asm_38877
+.discourage
pop hl
inc [hl]
ret
-.asm_3887a
+.maybe_encourage
pop hl
call AI_50_50
ret c
@@ -516,20 +516,20 @@
dec [hl]
ret
-.asm_38882
+.player_locked_on
push hl
ld hl, wBuffer1 - 1
ld de, wEnemyMonMoves
ld c, NUM_MOVES + 1
-.asm_3888b
+.checkmove2
inc hl
dec c
- jr z, .asm_388a2
+ jr z, .dismiss
ld a, [de]
and a
- jr z, .asm_388a2
+ jr z, .dismiss
inc de
call AIGetEnemyMove
@@ -536,13 +536,13 @@
ld a, [wEnemyMoveStruct + MOVE_ACC]
cp 71 percent - 1
- jr nc, .asm_3888b
+ jr nc, .checkmove2
dec [hl]
dec [hl]
- jr .asm_3888b
+ jr .checkmove2
-.asm_388a2
+.dismiss
pop hl
jp AIDiscourageMove
@@ -602,49 +602,49 @@
; If enemy's HP is full...
call AICheckEnemyMaxHP
- jr nc, .asm_388f2
+ jr nc, .hp_mismatch_1
; ...greatly encourage this move if player is badly poisoned.
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TOXIC, a
- jr nz, .encourage
+ jr nz, .greatly_encourage
; ...70% chance to greatly encourage this move if player is not badly poisoned.
call Random
cp 70 percent
- jr nc, .asm_38911
+ jr nc, .not_encouraged
-.encourage
+.greatly_encourage
dec [hl]
dec [hl]
ret
-.asm_388f2
+.hp_mismatch_1
; Greatly discourage this move if enemy's HP is below 25%.
call AICheckEnemyQuarterHP
- jr nc, .asm_3890f
+ jr nc, .hp_mismatch_2
; If enemy's HP is above 25% but not full, 4% chance to greatly encourage this move.
call Random
cp 4 percent
- jr c, .encourage
+ jr c, .greatly_encourage
; If enemy's HP is between 25% and 50%,...
call AICheckEnemyHalfHP
- jr nc, .asm_3890a
+ jr nc, .hp_mismatch_3
; If enemy's HP is above 50% but not full, 20% chance to greatly encourage this move.
call AI_80_20
- jr c, .encourage
- jr .asm_38911
+ jr c, .greatly_encourage
+ jr .not_encouraged
-.asm_3890a
+.hp_mismatch_3
; ...50% chance to greatly discourage this move.
call AI_50_50
- jr c, .asm_38911
+ jr c, .not_encouraged
-.asm_3890f
+.hp_mismatch_2
inc [hl]
inc [hl]
@@ -653,14 +653,14 @@
; 96% chance to end up here if enemy's HP is between 25% and 50%.
; 100% chance to end up here if enemy's HP is below 25%.
; In other words, we only end up here if the move has not been encouraged or dismissed.
-.asm_38911
+.not_encouraged
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TOXIC, a
- jr nz, .asm_38938
+ jr nz, .maybe_greatly_encourage
ld a, [wPlayerSubStatus4]
bit SUBSTATUS_LEECH_SEED, a
- jr nz, .asm_38941
+ jr nz, .maybe_encourage
; Discourage this move if enemy's evasion level is higher than player's accuracy level.
ld a, [wEnemyEvaLevel]
@@ -667,18 +667,18 @@
ld b, a
ld a, [wPlayerAccLevel]
cp b
- jr c, .asm_38936
+ jr c, .discourage
; Greatly encourage this move if the player is in the middle of Fury Cutter or Rollout.
ld a, [wPlayerFuryCutterCount]
and a
- jr nz, .encourage
+ jr nz, .greatly_encourage
ld a, [wPlayerSubStatus1]
bit SUBSTATUS_ROLLOUT, a
- jr nz, .encourage
+ jr nz, .greatly_encourage
-.asm_38936
+.discourage
inc [hl]
ret
@@ -685,10 +685,11 @@
; Player is badly poisoned.
; 70% chance to greatly encourage this move.
; This would counter any previous discouragement.
-.asm_38938
+.maybe_greatly_encourage
call Random
cp 31 percent + 1
ret c
+
dec [hl]
dec [hl]
ret
@@ -696,7 +697,7 @@
; Player is seeded.
; 50% chance to encourage this move.
; This would partly counter any previous discouragement.
-.asm_38941
+.maybe_encourage
call AI_50_50
ret c
@@ -768,65 +769,65 @@
AI_Smart_AccuracyDown:
; If player's HP is full...
call AICheckPlayerMaxHP
- jr nc, .asm_389a0
+ jr nc, .hp_mismatch_1
; ...and enemy's HP is above 50%...
call AICheckEnemyHalfHP
- jr nc, .asm_389a0
+ jr nc, .hp_mismatch_1
; ...greatly encourage this move if player is badly poisoned.
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TOXIC, a
- jr nz, .encourage
+ jr nz, .greatly_encourage
; ...70% chance to greatly encourage this move if player is not badly poisoned.
call Random
cp 70 percent
- jr nc, .asm_389bf
+ jr nc, .not_encouraged
-.encourage
+.greatly_encourage
dec [hl]
dec [hl]
ret
-.asm_389a0
+.hp_mismatch_1
; Greatly discourage this move if player's HP is below 25%.
call AICheckPlayerQuarterHP
- jr nc, .asm_389bd
+ jr nc, .hp_mismatch_2
; If player's HP is above 25% but not full, 4% chance to greatly encourage this move.
call Random
cp 4 percent
- jr c, .encourage
+ jr c, .greatly_encourage
; If player's HP is between 25% and 50%,...
call AICheckPlayerHalfHP
- jr nc, .asm_389b8
+ jr nc, .hp_mismatch_3
; If player's HP is above 50% but not full, 20% chance to greatly encourage this move.
call AI_80_20
- jr c, .encourage
- jr .asm_389bf
+ jr c, .greatly_encourage
+ jr .not_encouraged
; ...50% chance to greatly discourage this move.
-.asm_389b8
+.hp_mismatch_3
call AI_50_50
- jr c, .asm_389bf
+ jr c, .not_encouraged
-.asm_389bd
+.hp_mismatch_2
inc [hl]
inc [hl]
; We only end up here if the move has not been already encouraged.
-.asm_389bf
+.not_encouraged
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TOXIC, a
- jr nz, .asm_389e6
+ jr nz, .maybe_greatly_encourage
ld a, [wPlayerSubStatus4]
bit SUBSTATUS_LEECH_SEED, a
- jr nz, .asm_389ef
+ jr nz, .encourage
; Discourage this move if enemy's evasion level is higher than player's accuracy level.
ld a, [wEnemyEvaLevel]
@@ -833,18 +834,18 @@
ld b, a
ld a, [wPlayerAccLevel]
cp b
- jr c, .asm_389e4
+ jr c, .discourage
; Greatly encourage this move if the player is in the middle of Fury Cutter or Rollout.
ld a, [wPlayerFuryCutterCount]
and a
- jr nz, .encourage
+ jr nz, .greatly_encourage
ld a, [wPlayerSubStatus1]
bit SUBSTATUS_ROLLOUT, a
- jr nz, .encourage
+ jr nz, .greatly_encourage
-.asm_389e4
+.discourage
inc [hl]
ret
@@ -851,10 +852,11 @@
; Player is badly poisoned.
; 70% chance to greatly encourage this move.
; This would counter any previous discouragement.
-.asm_389e6
+.maybe_greatly_encourage
call Random
cp 31 percent + 1
ret c
+
dec [hl]
dec [hl]
ret
@@ -862,7 +864,7 @@
; Player is seeded.
; 50% chance to encourage this move.
; This would partly counter any previous discouragement.
-.asm_389ef
+.encourage
call AI_50_50
ret c
@@ -930,7 +932,7 @@
push hl
callfar CheckPlayerMoveTypeMatchups
ld a, [wEnemyAISwitchScore]
- cp 10 ; neutral
+ cp BASE_AI_SWITCH_SCORE
pop hl
ret c
inc [hl]
@@ -1037,49 +1039,49 @@
AI_Smart_Unused2B:
ld a, [wEnemySubStatus1]
bit SUBSTATUS_PERISH, a
- jr z, .asm_38aaa
+ jr z, .no_perish_count
ld a, [wEnemyPerishCount]
cp 3
- jr c, .asm_38ad3
+ jr c, .discourage
-.asm_38aaa
+.no_perish_count
push hl
ld hl, wPlayerUsedMoves
ld c, NUM_MOVES
-.asm_38ab0
+.checkmove
ld a, [hli]
and a
- jr z, .asm_38ac1
+ jr z, .movesdone
call AIGetEnemyMove
ld a, [wEnemyMoveStruct + MOVE_EFFECT]
cp EFFECT_PROTECT
- jr z, .asm_38ad5
+ jr z, .dismiss
dec c
- jr nz, .asm_38ab0
+ jr nz, .checkmove
-.asm_38ac1
+.movesdone
pop hl
ld a, [wEnemySubStatus3]
bit SUBSTATUS_CONFUSED, a
- jr nz, .asm_38acd
+ jr nz, .maybe_discourage
call AICheckEnemyHalfHP
ret c
-.asm_38acd
+.maybe_discourage
call Random
cp 79 percent - 1
ret c
-.asm_38ad3
+.discourage
inc [hl]
ret
-.asm_38ad5
+.dismiss
pop hl
ld a, [hl]
add 6
@@ -1278,18 +1280,19 @@
ret
AI_Smart_Mimic:
+; Discourage this move if the player did not use any move last turn.
ld a, [wLastPlayerCounterMove]
and a
- jr z, .asm_38be9
+ jr z, .dismiss
call AICheckEnemyHalfHP
- jr nc, .asm_38bef
+ jr nc, .discourage
push hl
ld a, [wLastPlayerCounterMove]
call AIGetEnemyMove
- ld a, $1
+ ld a, 1
ldh [hBattleTurn], a
callfar BattleCheckTypeMatchup
@@ -1296,15 +1299,15 @@
ld a, [wTypeMatchup]
cp EFFECTIVE
pop hl
- jr c, .asm_38bef
- jr z, .asm_38bd4
+ jr c, .discourage
+ jr z, .skip_encourage
call AI_50_50
- jr c, .asm_38bd4
+ jr c, .skip_encourage
dec [hl]
-.asm_38bd4
+.skip_encourage
ld a, [wLastPlayerCounterMove]
push hl
ld hl, UsefulMoves
@@ -1318,11 +1321,12 @@
dec [hl]
ret
-.asm_38be9
+.dismiss
+; Dismiss this move if the enemy is faster than the player.
call AICompareSpeed
jp c, AIDiscourageMove
-.asm_38bef
+.discourage
inc [hl]
ret
@@ -1551,7 +1555,7 @@
dec [hl]
ret
-CallAIDiscourageMove: ; unreferenced
+.dismiss ; unreferenced
jp AIDiscourageMove
AI_Smart_DestinyBond:
@@ -1631,7 +1635,7 @@
jp nz, AIDiscourageMove
; Greatly encourage this move if it will KO the player.
- ld a, $1
+ ld a, 1
ldh [hBattleTurn], a
push hl
callfar EnemyAttackDamage
@@ -1755,7 +1759,7 @@
push hl
callfar CheckPlayerMoveTypeMatchups
ld a, [wEnemyAISwitchScore]
- cp $b ; not very effective
+ cp BASE_AI_SWITCH_SCORE + 1 ; not very effective
pop hl
ret nc
@@ -1820,23 +1824,23 @@
AI_Smart_Curse:
ld a, [wEnemyMonType1]
cp GHOST
- jr z, .ghostcurse
+ jr z, .ghost_curse
ld a, [wEnemyMonType2]
cp GHOST
- jr z, .ghostcurse
+ jr z, .ghost_curse
call AICheckEnemyHalfHP
- jr nc, .asm_38e93
+ jr nc, .encourage
ld a, [wEnemyAtkLevel]
cp BASE_STAT_LEVEL + 4
- jr nc, .asm_38e93
+ jr nc, .encourage
cp BASE_STAT_LEVEL + 2
ret nc
ld a, [wBattleMonType1]
cp GHOST
- jr z, .asm_38e92
+ jr z, .greatly_encourage
cp SPECIAL
ret nc
ld a, [wBattleMonType2]
@@ -1848,16 +1852,16 @@
dec [hl]
ret
-.asm_38e90
+.approve
inc [hl]
inc [hl]
-.asm_38e92
+.greatly_encourage
inc [hl]
-.asm_38e93
+.encourage
inc [hl]
ret
-.ghostcurse
+.ghost_curse
ld a, [wPlayerSubStatus1]
bit SUBSTATUS_CURSE, a
jp nz, AIDiscourageMove
@@ -1865,27 +1869,27 @@
push hl
farcall FindAliveEnemyMons
pop hl
- jr nc, .asm_38eb0
+ jr nc, .notlastmon
push hl
call AICheckLastPlayerMon
pop hl
- jr nz, .asm_38e90
+ jr nz, .approve
- jr .asm_38eb7
+ jr .ghost_continue
-.asm_38eb0
+.notlastmon
push hl
call AICheckLastPlayerMon
pop hl
- jr z, .asm_38ecb
+ jr z, .maybe_greatly_encourage
-.asm_38eb7
+.ghost_continue
call AICheckEnemyQuarterHP
- jp nc, .asm_38e90
+ jp nc, .approve
call AICheckEnemyHalfHP
- jr nc, .asm_38e92
+ jr nc, .greatly_encourage
call AICheckEnemyMaxHP
ret nc
@@ -1894,7 +1898,7 @@
and a
ret nz
-.asm_38ecb
+.maybe_greatly_encourage
call AI_50_50
ret c
@@ -1903,81 +1907,96 @@
ret
AI_Smart_Protect:
+; Greatly discourage this move if the enemy already used Protect.
ld a, [wEnemyProtectCount]
and a
- jr nz, .asm_38f13
+ jr nz, .greatly_discourage
+; Discourage this move if the player is locked on.
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_LOCK_ON, a
- jr nz, .asm_38f14
+ jr nz, .discourage
+; Encourage this move if the player's Fury Cutter is boosted enough.
ld a, [wPlayerFuryCutterCount]
cp 3
- jr nc, .asm_38f0d
+ jr nc, .encourage
+; Encourage this move if the player has charged a two-turn move.
ld a, [wPlayerSubStatus3]
bit SUBSTATUS_CHARGED, a
- jr nz, .asm_38f0d
+ jr nz, .encourage
+; Encourage this move if the player is affected by Toxic, Leech Seed, or Curse.
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TOXIC, a
- jr nz, .asm_38f0d
+ jr nz, .encourage
ld a, [wPlayerSubStatus4]
bit SUBSTATUS_LEECH_SEED, a
- jr nz, .asm_38f0d
+ jr nz, .encourage
ld a, [wPlayerSubStatus1]
bit SUBSTATUS_CURSE, a
- jr nz, .asm_38f0d
+ jr nz, .encourage
+; Discourage this move if the player's Rollout count is not boosted enough.
bit SUBSTATUS_ROLLOUT, a
- jr z, .asm_38f14
-
+ jr z, .discourage
ld a, [wPlayerRolloutCount]
cp 3
- jr c, .asm_38f14
+ jr c, .discourage
-.asm_38f0d
+; 80% chance to encourage this move otherwise.
+.encourage
call AI_80_20
ret c
+
dec [hl]
ret
-.asm_38f13
+.greatly_discourage
inc [hl]
-.asm_38f14
+.discourage
call Random
cp 8 percent
ret c
+
inc [hl]
inc [hl]
ret
AI_Smart_Foresight:
+; 60% chance to encourage this move if the enemy's accuracy is sharply lowered.
ld a, [wEnemyAccLevel]
cp BASE_STAT_LEVEL - 2
- jr c, .asm_38f41
+ jr c, .encourage
+
+; 60% chance to encourage this move if the player's evasion is sharply raised.
ld a, [wPlayerEvaLevel]
cp BASE_STAT_LEVEL + 3
- jr nc, .asm_38f41
+ jr nc, .encourage
+; 60% chance to encourage this move if the player is a Ghost type.
ld a, [wBattleMonType1]
cp GHOST
- jr z, .asm_38f41
+ jr z, .encourage
ld a, [wBattleMonType2]
cp GHOST
- jr z, .asm_38f41
+ jr z, .encourage
+; 92% chance to discourage this move otherwise.
call Random
cp 8 percent
ret c
+
inc [hl]
ret
-.asm_38f41
+.encourage
call Random
cp 39 percent + 1
ret c
+
dec [hl]
dec [hl]
ret
@@ -1995,7 +2014,7 @@
push hl
callfar CheckPlayerMoveTypeMatchups
ld a, [wEnemyAISwitchScore]
- cp 10 ; 1.0
+ cp BASE_AI_SWITCH_SCORE
pop hl
ret c
@@ -2026,7 +2045,7 @@
ld de, 1
call IsInArray
pop hl
- jr c, .asm_38fa5
+ jr c, .greatly_discourage
ld a, [wBattleMonType2]
push hl
@@ -2034,11 +2053,11 @@
ld de, 1
call IsInArray
pop hl
- jr c, .asm_38fa5
+ jr c, .greatly_discourage
; Discourage this move if player's HP is below 50%.
call AICheckPlayerHalfHP
- jr nc, .asm_38fa6
+ jr nc, .discourage
; 50% chance to encourage this move otherwise.
call AI_50_50
@@ -2047,10 +2066,9 @@
dec [hl]
ret
-.asm_38fa5
+.greatly_discourage
inc [hl]
-
-.asm_38fa6
+.discourage
inc [hl]
ret
@@ -2061,20 +2079,25 @@
db -1 ; end
AI_Smart_Endure:
+; Greatly discourage this move if the enemy already used Protect.
ld a, [wEnemyProtectCount]
and a
- jr nz, .asm_38fd8
+ jr nz, .greatly_discourage
+; Greatly discourage this move if the enemy's HP is full.
call AICheckEnemyMaxHP
- jr c, .asm_38fd8
+ jr c, .greatly_discourage
+; Discourage this move if the enemy's HP is at least 25%.
call AICheckEnemyQuarterHP
- jr c, .asm_38fd9
+ jr c, .discourage
+; If the enemy has Reversal...
ld b, EFFECT_REVERSAL
call AIHasMoveEffect
- jr nc, .asm_38fcb
+ jr nc, .no_reversal
+; ...80% chance to greatly encourage this move.
call AI_80_20
ret c
@@ -2083,11 +2106,13 @@
dec [hl]
ret
-.asm_38fcb
+.no_reversal
+; If the enemy is not locked on, do nothing.
ld a, [wEnemySubStatus5]
bit SUBSTATUS_LOCK_ON, a
ret z
+; 50% chance to greatly encourage this move.
call AI_50_50
ret c
@@ -2095,10 +2120,9 @@
dec [hl]
ret
-.asm_38fd8
+.greatly_discourage
inc [hl]
-
-.asm_38fd9
+.discourage
inc [hl]
ret
@@ -2107,22 +2131,20 @@
ld a, [wEnemyFuryCutterCount]
and a
- jr z, .end
+ jr z, AI_Smart_Rollout
dec [hl]
cp 2
- jr c, .end
+ jr c, AI_Smart_Rollout
dec [hl]
dec [hl]
cp 3
- jr c, .end
+ jr c, AI_Smart_Rollout
dec [hl]
dec [hl]
dec [hl]
-.end
-
; fallthrough
AI_Smart_Rollout:
@@ -2131,29 +2153,29 @@
; 80% chance to discourage this move if the enemy is in love, confused, or paralyzed.
ld a, [wEnemySubStatus1]
bit SUBSTATUS_IN_LOVE, a
- jr nz, .asm_39020
+ jr nz, .maybe_discourage
ld a, [wEnemySubStatus3]
bit SUBSTATUS_CONFUSED, a
- jr nz, .asm_39020
+ jr nz, .maybe_discourage
ld a, [wEnemyMonStatus]
bit PAR, a
- jr nz, .asm_39020
+ jr nz, .maybe_discourage
; 80% chance to discourage this move if the enemy's HP is below 25%,
; or if accuracy or evasion modifiers favour the player.
call AICheckEnemyQuarterHP
- jr nc, .asm_39020
+ jr nc, .maybe_discourage
ld a, [wEnemyAccLevel]
cp BASE_STAT_LEVEL
- jr c, .asm_39020
+ jr c, .maybe_discourage
ld a, [wPlayerEvaLevel]
cp BASE_STAT_LEVEL + 1
- jr nc, .asm_39020
+ jr nc, .maybe_discourage
-; Otherwise, 80% chance to greatly encourage this move.
+; 80% chance to greatly encourage this move otherwise.
call Random
cp 79 percent - 1
ret nc
@@ -2161,7 +2183,7 @@
dec [hl]
ret
-.asm_39020
+.maybe_discourage
call AI_80_20
ret c
inc [hl]
@@ -2235,7 +2257,7 @@
push hl
callfar CheckPlayerMoveTypeMatchups
ld a, [wEnemyAISwitchScore]
- cp 10 ; neutral
+ cp BASE_AI_SWITCH_SCORE
pop hl
ret c
inc [hl]
@@ -2438,38 +2460,38 @@
AI_Smart_PsychUp:
push hl
ld hl, wEnemyAtkLevel
- ld b, $8
+ ld b, NUM_LEVEL_STATS
ld c, 100
; Calculate the sum of all enemy's stat level modifiers. Add 100 first to prevent underflow.
; Put the result in c. c will range between 58 and 142.
-.asm_3915a
+.enemy_loop
ld a, [hli]
- sub $7
+ sub BASE_STAT_LEVEL
add c
ld c, a
dec b
- jr nz, .asm_3915a
+ jr nz, .enemy_loop
; Calculate the sum of all player's stat level modifiers. Add 100 first to prevent underflow.
; Put the result in d. d will range between 58 and 142.
ld hl, wPlayerAtkLevel
- ld b, $8
+ ld b, NUM_LEVEL_STATS
ld d, 100
-.asm_39169
+.player_loop
ld a, [hli]
- sub $7
+ sub BASE_STAT_LEVEL
add d
ld d, a
dec b
- jr nz, .asm_39169
+ jr nz, .player_loop
; Greatly discourage this move if enemy's stat levels are higher than player's (if c>=d).
ld a, c
sub d
pop hl
- jr nc, .asm_39188
+ jr nc, .discourage
; Else, 80% chance to encourage this move unless player's accuracy level is lower than -1...
ld a, [wPlayerAccLevel]
@@ -2487,7 +2509,7 @@
dec [hl]
ret
-.asm_39188
+.discourage
inc [hl]
inc [hl]
ret
--- a/engine/battle/ai/switch.asm
+++ b/engine/battle/ai/switch.asm
@@ -5,7 +5,7 @@
push hl
push de
push bc
- ld a, 10
+ ld a, BASE_AI_SWITCH_SCORE
ld [wEnemyAISwitchScore], a
ld hl, wPlayerUsedMoves
ld a, [hl]
@@ -37,7 +37,7 @@
cp EFFECTIVE ; 1.0
jr nc, .neutral
-.not_very_effective
+; not very effective
ld a, e
cp 1 ; 0.1
jr nc, .next