Identify remaining battle AI labels

This commit is contained in:
Rangi 2020-10-21 21:34:18 -04:00
parent 0e3857eac7
commit 650686476c
3 changed files with 197 additions and 172 deletions

View File

@ -28,6 +28,9 @@ EFFECTIVE EQU 10
NOT_VERY_EFFECTIVE EQU 05 NOT_VERY_EFFECTIVE EQU 05
NO_EFFECT EQU 00 NO_EFFECT EQU 00
; enemy AI behavior
BASE_AI_SWITCH_SCORE EQU 10
; wPlayerStatLevels and wEnemyStatLevels indexes (see wram.asm) ; wPlayerStatLevels and wEnemyStatLevels indexes (see wram.asm)
; GetStatName arguments (see data/battle/stat_names.asm) ; GetStatName arguments (see data/battle/stat_names.asm)
const_def const_def

View File

@ -445,48 +445,48 @@ AI_Smart_LeechHit:
AI_Smart_LockOn: AI_Smart_LockOn:
ld a, [wPlayerSubStatus5] ld a, [wPlayerSubStatus5]
bit SUBSTATUS_LOCK_ON, a bit SUBSTATUS_LOCK_ON, a
jr nz, .asm_38882 jr nz, .player_locked_on
push hl push hl
call AICheckEnemyQuarterHP call AICheckEnemyQuarterHP
jr nc, .asm_38877 jr nc, .discourage
call AICheckEnemyHalfHP call AICheckEnemyHalfHP
jr c, .asm_38834 jr c, .skip_speed_check
call AICompareSpeed call AICompareSpeed
jr nc, .asm_38877 jr nc, .discourage
.asm_38834 .skip_speed_check
ld a, [wPlayerEvaLevel] ld a, [wPlayerEvaLevel]
cp BASE_STAT_LEVEL + 3 cp BASE_STAT_LEVEL + 3
jr nc, .asm_3887a jr nc, .maybe_encourage
cp BASE_STAT_LEVEL + 1 cp BASE_STAT_LEVEL + 1
jr nc, .asm_38875 jr nc, .do_nothing
ld a, [wEnemyAccLevel] ld a, [wEnemyAccLevel]
cp BASE_STAT_LEVEL - 2 cp BASE_STAT_LEVEL - 2
jr c, .asm_3887a jr c, .maybe_encourage
cp BASE_STAT_LEVEL cp BASE_STAT_LEVEL
jr c, .asm_38875 jr c, .do_nothing
ld hl, wEnemyMonMoves ld hl, wEnemyMonMoves
ld c, NUM_MOVES + 1 ld c, NUM_MOVES + 1
.asm_3884f .checkmove
dec c dec c
jr z, .asm_38877 jr z, .discourage
ld a, [hli] ld a, [hli]
and a and a
jr z, .asm_38877 jr z, .discourage
call AIGetEnemyMove call AIGetEnemyMove
ld a, [wEnemyMoveStruct + MOVE_ACC] ld a, [wEnemyMoveStruct + MOVE_ACC]
cp 71 percent - 1 cp 71 percent - 1
jr nc, .asm_3884f jr nc, .checkmove
ld a, $1 ld a, 1
ldh [hBattleTurn], a ldh [hBattleTurn], a
push hl push hl
@ -496,18 +496,18 @@ AI_Smart_LockOn:
cp EFFECTIVE cp EFFECTIVE
pop bc pop bc
pop hl pop hl
jr c, .asm_3884f jr c, .checkmove
.asm_38875 .do_nothing
pop hl pop hl
ret ret
.asm_38877 .discourage
pop hl pop hl
inc [hl] inc [hl]
ret ret
.asm_3887a .maybe_encourage
pop hl pop hl
call AI_50_50 call AI_50_50
ret c ret c
@ -516,33 +516,33 @@ AI_Smart_LockOn:
dec [hl] dec [hl]
ret ret
.asm_38882 .player_locked_on
push hl push hl
ld hl, wBuffer1 - 1 ld hl, wBuffer1 - 1
ld de, wEnemyMonMoves ld de, wEnemyMonMoves
ld c, NUM_MOVES + 1 ld c, NUM_MOVES + 1
.asm_3888b .checkmove2
inc hl inc hl
dec c dec c
jr z, .asm_388a2 jr z, .dismiss
ld a, [de] ld a, [de]
and a and a
jr z, .asm_388a2 jr z, .dismiss
inc de inc de
call AIGetEnemyMove call AIGetEnemyMove
ld a, [wEnemyMoveStruct + MOVE_ACC] ld a, [wEnemyMoveStruct + MOVE_ACC]
cp 71 percent - 1 cp 71 percent - 1
jr nc, .asm_3888b jr nc, .checkmove2
dec [hl] dec [hl]
dec [hl] dec [hl]
jr .asm_3888b jr .checkmove2
.asm_388a2 .dismiss
pop hl pop hl
jp AIDiscourageMove jp AIDiscourageMove
@ -602,49 +602,49 @@ AI_Smart_EvasionUp:
; If enemy's HP is full... ; If enemy's HP is full...
call AICheckEnemyMaxHP call AICheckEnemyMaxHP
jr nc, .asm_388f2 jr nc, .hp_mismatch_1
; ...greatly encourage this move if player is badly poisoned. ; ...greatly encourage this move if player is badly poisoned.
ld a, [wPlayerSubStatus5] ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TOXIC, a bit SUBSTATUS_TOXIC, a
jr nz, .encourage jr nz, .greatly_encourage
; ...70% chance to greatly encourage this move if player is not badly poisoned. ; ...70% chance to greatly encourage this move if player is not badly poisoned.
call Random call Random
cp 70 percent cp 70 percent
jr nc, .asm_38911 jr nc, .not_encouraged
.encourage .greatly_encourage
dec [hl] dec [hl]
dec [hl] dec [hl]
ret ret
.asm_388f2 .hp_mismatch_1
; Greatly discourage this move if enemy's HP is below 25%. ; Greatly discourage this move if enemy's HP is below 25%.
call AICheckEnemyQuarterHP 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. ; If enemy's HP is above 25% but not full, 4% chance to greatly encourage this move.
call Random call Random
cp 4 percent cp 4 percent
jr c, .encourage jr c, .greatly_encourage
; If enemy's HP is between 25% and 50%,... ; If enemy's HP is between 25% and 50%,...
call AICheckEnemyHalfHP 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. ; If enemy's HP is above 50% but not full, 20% chance to greatly encourage this move.
call AI_80_20 call AI_80_20
jr c, .encourage jr c, .greatly_encourage
jr .asm_38911 jr .not_encouraged
.asm_3890a .hp_mismatch_3
; ...50% chance to greatly discourage this move. ; ...50% chance to greatly discourage this move.
call AI_50_50 call AI_50_50
jr c, .asm_38911 jr c, .not_encouraged
.asm_3890f .hp_mismatch_2
inc [hl] inc [hl]
inc [hl] inc [hl]
@ -653,42 +653,43 @@ AI_Smart_EvasionUp:
; 96% chance to end up here if enemy's HP is between 25% and 50%. ; 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%. ; 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. ; In other words, we only end up here if the move has not been encouraged or dismissed.
.asm_38911 .not_encouraged
ld a, [wPlayerSubStatus5] ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TOXIC, a bit SUBSTATUS_TOXIC, a
jr nz, .asm_38938 jr nz, .maybe_greatly_encourage
ld a, [wPlayerSubStatus4] ld a, [wPlayerSubStatus4]
bit SUBSTATUS_LEECH_SEED, a 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. ; Discourage this move if enemy's evasion level is higher than player's accuracy level.
ld a, [wEnemyEvaLevel] ld a, [wEnemyEvaLevel]
ld b, a ld b, a
ld a, [wPlayerAccLevel] ld a, [wPlayerAccLevel]
cp b 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. ; Greatly encourage this move if the player is in the middle of Fury Cutter or Rollout.
ld a, [wPlayerFuryCutterCount] ld a, [wPlayerFuryCutterCount]
and a and a
jr nz, .encourage jr nz, .greatly_encourage
ld a, [wPlayerSubStatus1] ld a, [wPlayerSubStatus1]
bit SUBSTATUS_ROLLOUT, a bit SUBSTATUS_ROLLOUT, a
jr nz, .encourage jr nz, .greatly_encourage
.asm_38936 .discourage
inc [hl] inc [hl]
ret ret
; Player is badly poisoned. ; Player is badly poisoned.
; 70% chance to greatly encourage this move. ; 70% chance to greatly encourage this move.
; This would counter any previous discouragement. ; This would counter any previous discouragement.
.asm_38938 .maybe_greatly_encourage
call Random call Random
cp 31 percent + 1 cp 31 percent + 1
ret c ret c
dec [hl] dec [hl]
dec [hl] dec [hl]
ret ret
@ -696,7 +697,7 @@ AI_Smart_EvasionUp:
; Player is seeded. ; Player is seeded.
; 50% chance to encourage this move. ; 50% chance to encourage this move.
; This would partly counter any previous discouragement. ; This would partly counter any previous discouragement.
.asm_38941 .maybe_encourage
call AI_50_50 call AI_50_50
ret c ret c
@ -768,93 +769,94 @@ AI_Smart_MirrorMove:
AI_Smart_AccuracyDown: AI_Smart_AccuracyDown:
; If player's HP is full... ; If player's HP is full...
call AICheckPlayerMaxHP call AICheckPlayerMaxHP
jr nc, .asm_389a0 jr nc, .hp_mismatch_1
; ...and enemy's HP is above 50%... ; ...and enemy's HP is above 50%...
call AICheckEnemyHalfHP call AICheckEnemyHalfHP
jr nc, .asm_389a0 jr nc, .hp_mismatch_1
; ...greatly encourage this move if player is badly poisoned. ; ...greatly encourage this move if player is badly poisoned.
ld a, [wPlayerSubStatus5] ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TOXIC, a bit SUBSTATUS_TOXIC, a
jr nz, .encourage jr nz, .greatly_encourage
; ...70% chance to greatly encourage this move if player is not badly poisoned. ; ...70% chance to greatly encourage this move if player is not badly poisoned.
call Random call Random
cp 70 percent cp 70 percent
jr nc, .asm_389bf jr nc, .not_encouraged
.encourage .greatly_encourage
dec [hl] dec [hl]
dec [hl] dec [hl]
ret ret
.asm_389a0 .hp_mismatch_1
; Greatly discourage this move if player's HP is below 25%. ; Greatly discourage this move if player's HP is below 25%.
call AICheckPlayerQuarterHP 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. ; If player's HP is above 25% but not full, 4% chance to greatly encourage this move.
call Random call Random
cp 4 percent cp 4 percent
jr c, .encourage jr c, .greatly_encourage
; If player's HP is between 25% and 50%,... ; If player's HP is between 25% and 50%,...
call AICheckPlayerHalfHP 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. ; If player's HP is above 50% but not full, 20% chance to greatly encourage this move.
call AI_80_20 call AI_80_20
jr c, .encourage jr c, .greatly_encourage
jr .asm_389bf jr .not_encouraged
; ...50% chance to greatly discourage this move. ; ...50% chance to greatly discourage this move.
.asm_389b8 .hp_mismatch_3
call AI_50_50 call AI_50_50
jr c, .asm_389bf jr c, .not_encouraged
.asm_389bd .hp_mismatch_2
inc [hl] inc [hl]
inc [hl] inc [hl]
; We only end up here if the move has not been already encouraged. ; We only end up here if the move has not been already encouraged.
.asm_389bf .not_encouraged
ld a, [wPlayerSubStatus5] ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TOXIC, a bit SUBSTATUS_TOXIC, a
jr nz, .asm_389e6 jr nz, .maybe_greatly_encourage
ld a, [wPlayerSubStatus4] ld a, [wPlayerSubStatus4]
bit SUBSTATUS_LEECH_SEED, a 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. ; Discourage this move if enemy's evasion level is higher than player's accuracy level.
ld a, [wEnemyEvaLevel] ld a, [wEnemyEvaLevel]
ld b, a ld b, a
ld a, [wPlayerAccLevel] ld a, [wPlayerAccLevel]
cp b 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. ; Greatly encourage this move if the player is in the middle of Fury Cutter or Rollout.
ld a, [wPlayerFuryCutterCount] ld a, [wPlayerFuryCutterCount]
and a and a
jr nz, .encourage jr nz, .greatly_encourage
ld a, [wPlayerSubStatus1] ld a, [wPlayerSubStatus1]
bit SUBSTATUS_ROLLOUT, a bit SUBSTATUS_ROLLOUT, a
jr nz, .encourage jr nz, .greatly_encourage
.asm_389e4 .discourage
inc [hl] inc [hl]
ret ret
; Player is badly poisoned. ; Player is badly poisoned.
; 70% chance to greatly encourage this move. ; 70% chance to greatly encourage this move.
; This would counter any previous discouragement. ; This would counter any previous discouragement.
.asm_389e6 .maybe_greatly_encourage
call Random call Random
cp 31 percent + 1 cp 31 percent + 1
ret c ret c
dec [hl] dec [hl]
dec [hl] dec [hl]
ret ret
@ -862,7 +864,7 @@ AI_Smart_AccuracyDown:
; Player is seeded. ; Player is seeded.
; 50% chance to encourage this move. ; 50% chance to encourage this move.
; This would partly counter any previous discouragement. ; This would partly counter any previous discouragement.
.asm_389ef .encourage
call AI_50_50 call AI_50_50
ret c ret c
@ -930,7 +932,7 @@ AI_Smart_ForceSwitch:
push hl push hl
callfar CheckPlayerMoveTypeMatchups callfar CheckPlayerMoveTypeMatchups
ld a, [wEnemyAISwitchScore] ld a, [wEnemyAISwitchScore]
cp 10 ; neutral cp BASE_AI_SWITCH_SCORE
pop hl pop hl
ret c ret c
inc [hl] inc [hl]
@ -1037,49 +1039,49 @@ AI_Smart_RazorWind:
AI_Smart_Unused2B: AI_Smart_Unused2B:
ld a, [wEnemySubStatus1] ld a, [wEnemySubStatus1]
bit SUBSTATUS_PERISH, a bit SUBSTATUS_PERISH, a
jr z, .asm_38aaa jr z, .no_perish_count
ld a, [wEnemyPerishCount] ld a, [wEnemyPerishCount]
cp 3 cp 3
jr c, .asm_38ad3 jr c, .discourage
.asm_38aaa .no_perish_count
push hl push hl
ld hl, wPlayerUsedMoves ld hl, wPlayerUsedMoves
ld c, NUM_MOVES ld c, NUM_MOVES
.asm_38ab0 .checkmove
ld a, [hli] ld a, [hli]
and a and a
jr z, .asm_38ac1 jr z, .movesdone
call AIGetEnemyMove call AIGetEnemyMove
ld a, [wEnemyMoveStruct + MOVE_EFFECT] ld a, [wEnemyMoveStruct + MOVE_EFFECT]
cp EFFECT_PROTECT cp EFFECT_PROTECT
jr z, .asm_38ad5 jr z, .dismiss
dec c dec c
jr nz, .asm_38ab0 jr nz, .checkmove
.asm_38ac1 .movesdone
pop hl pop hl
ld a, [wEnemySubStatus3] ld a, [wEnemySubStatus3]
bit SUBSTATUS_CONFUSED, a bit SUBSTATUS_CONFUSED, a
jr nz, .asm_38acd jr nz, .maybe_discourage
call AICheckEnemyHalfHP call AICheckEnemyHalfHP
ret c ret c
.asm_38acd .maybe_discourage
call Random call Random
cp 79 percent - 1 cp 79 percent - 1
ret c ret c
.asm_38ad3 .discourage
inc [hl] inc [hl]
ret ret
.asm_38ad5 .dismiss
pop hl pop hl
ld a, [hl] ld a, [hl]
add 6 add 6
@ -1278,33 +1280,34 @@ AI_Smart_Rage:
ret ret
AI_Smart_Mimic: AI_Smart_Mimic:
; Discourage this move if the player did not use any move last turn.
ld a, [wLastPlayerCounterMove] ld a, [wLastPlayerCounterMove]
and a and a
jr z, .asm_38be9 jr z, .dismiss
call AICheckEnemyHalfHP call AICheckEnemyHalfHP
jr nc, .asm_38bef jr nc, .discourage
push hl push hl
ld a, [wLastPlayerCounterMove] ld a, [wLastPlayerCounterMove]
call AIGetEnemyMove call AIGetEnemyMove
ld a, $1 ld a, 1
ldh [hBattleTurn], a ldh [hBattleTurn], a
callfar BattleCheckTypeMatchup callfar BattleCheckTypeMatchup
ld a, [wTypeMatchup] ld a, [wTypeMatchup]
cp EFFECTIVE cp EFFECTIVE
pop hl pop hl
jr c, .asm_38bef jr c, .discourage
jr z, .asm_38bd4 jr z, .skip_encourage
call AI_50_50 call AI_50_50
jr c, .asm_38bd4 jr c, .skip_encourage
dec [hl] dec [hl]
.asm_38bd4 .skip_encourage
ld a, [wLastPlayerCounterMove] ld a, [wLastPlayerCounterMove]
push hl push hl
ld hl, UsefulMoves ld hl, UsefulMoves
@ -1318,11 +1321,12 @@ AI_Smart_Mimic:
dec [hl] dec [hl]
ret ret
.asm_38be9 .dismiss
; Dismiss this move if the enemy is faster than the player.
call AICompareSpeed call AICompareSpeed
jp c, AIDiscourageMove jp c, AIDiscourageMove
.asm_38bef .discourage
inc [hl] inc [hl]
ret ret
@ -1551,7 +1555,7 @@ AI_Smart_Spite:
dec [hl] dec [hl]
ret ret
CallAIDiscourageMove: ; unreferenced .dismiss ; unreferenced
jp AIDiscourageMove jp AIDiscourageMove
AI_Smart_DestinyBond: AI_Smart_DestinyBond:
@ -1631,7 +1635,7 @@ AI_Smart_PriorityHit:
jp nz, AIDiscourageMove jp nz, AIDiscourageMove
; Greatly encourage this move if it will KO the player. ; Greatly encourage this move if it will KO the player.
ld a, $1 ld a, 1
ldh [hBattleTurn], a ldh [hBattleTurn], a
push hl push hl
callfar EnemyAttackDamage callfar EnemyAttackDamage
@ -1755,7 +1759,7 @@ AI_Smart_MeanLook:
push hl push hl
callfar CheckPlayerMoveTypeMatchups callfar CheckPlayerMoveTypeMatchups
ld a, [wEnemyAISwitchScore] ld a, [wEnemyAISwitchScore]
cp $b ; not very effective cp BASE_AI_SWITCH_SCORE + 1 ; not very effective
pop hl pop hl
ret nc ret nc
@ -1820,23 +1824,23 @@ endr
AI_Smart_Curse: AI_Smart_Curse:
ld a, [wEnemyMonType1] ld a, [wEnemyMonType1]
cp GHOST cp GHOST
jr z, .ghostcurse jr z, .ghost_curse
ld a, [wEnemyMonType2] ld a, [wEnemyMonType2]
cp GHOST cp GHOST
jr z, .ghostcurse jr z, .ghost_curse
call AICheckEnemyHalfHP call AICheckEnemyHalfHP
jr nc, .asm_38e93 jr nc, .encourage
ld a, [wEnemyAtkLevel] ld a, [wEnemyAtkLevel]
cp BASE_STAT_LEVEL + 4 cp BASE_STAT_LEVEL + 4
jr nc, .asm_38e93 jr nc, .encourage
cp BASE_STAT_LEVEL + 2 cp BASE_STAT_LEVEL + 2
ret nc ret nc
ld a, [wBattleMonType1] ld a, [wBattleMonType1]
cp GHOST cp GHOST
jr z, .asm_38e92 jr z, .greatly_encourage
cp SPECIAL cp SPECIAL
ret nc ret nc
ld a, [wBattleMonType2] ld a, [wBattleMonType2]
@ -1848,16 +1852,16 @@ AI_Smart_Curse:
dec [hl] dec [hl]
ret ret
.asm_38e90 .approve
inc [hl] inc [hl]
inc [hl] inc [hl]
.asm_38e92 .greatly_encourage
inc [hl] inc [hl]
.asm_38e93 .encourage
inc [hl] inc [hl]
ret ret
.ghostcurse .ghost_curse
ld a, [wPlayerSubStatus1] ld a, [wPlayerSubStatus1]
bit SUBSTATUS_CURSE, a bit SUBSTATUS_CURSE, a
jp nz, AIDiscourageMove jp nz, AIDiscourageMove
@ -1865,27 +1869,27 @@ AI_Smart_Curse:
push hl push hl
farcall FindAliveEnemyMons farcall FindAliveEnemyMons
pop hl pop hl
jr nc, .asm_38eb0 jr nc, .notlastmon
push hl push hl
call AICheckLastPlayerMon call AICheckLastPlayerMon
pop hl pop hl
jr nz, .asm_38e90 jr nz, .approve
jr .asm_38eb7 jr .ghost_continue
.asm_38eb0 .notlastmon
push hl push hl
call AICheckLastPlayerMon call AICheckLastPlayerMon
pop hl pop hl
jr z, .asm_38ecb jr z, .maybe_greatly_encourage
.asm_38eb7 .ghost_continue
call AICheckEnemyQuarterHP call AICheckEnemyQuarterHP
jp nc, .asm_38e90 jp nc, .approve
call AICheckEnemyHalfHP call AICheckEnemyHalfHP
jr nc, .asm_38e92 jr nc, .greatly_encourage
call AICheckEnemyMaxHP call AICheckEnemyMaxHP
ret nc ret nc
@ -1894,7 +1898,7 @@ AI_Smart_Curse:
and a and a
ret nz ret nz
.asm_38ecb .maybe_greatly_encourage
call AI_50_50 call AI_50_50
ret c ret c
@ -1903,81 +1907,96 @@ AI_Smart_Curse:
ret ret
AI_Smart_Protect: AI_Smart_Protect:
; Greatly discourage this move if the enemy already used Protect.
ld a, [wEnemyProtectCount] ld a, [wEnemyProtectCount]
and a and a
jr nz, .asm_38f13 jr nz, .greatly_discourage
; Discourage this move if the player is locked on.
ld a, [wPlayerSubStatus5] ld a, [wPlayerSubStatus5]
bit SUBSTATUS_LOCK_ON, a 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] ld a, [wPlayerFuryCutterCount]
cp 3 cp 3
jr nc, .asm_38f0d jr nc, .encourage
; Encourage this move if the player has charged a two-turn move.
ld a, [wPlayerSubStatus3] ld a, [wPlayerSubStatus3]
bit SUBSTATUS_CHARGED, a 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] ld a, [wPlayerSubStatus5]
bit SUBSTATUS_TOXIC, a bit SUBSTATUS_TOXIC, a
jr nz, .asm_38f0d jr nz, .encourage
ld a, [wPlayerSubStatus4] ld a, [wPlayerSubStatus4]
bit SUBSTATUS_LEECH_SEED, a bit SUBSTATUS_LEECH_SEED, a
jr nz, .asm_38f0d jr nz, .encourage
ld a, [wPlayerSubStatus1] ld a, [wPlayerSubStatus1]
bit SUBSTATUS_CURSE, a 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 bit SUBSTATUS_ROLLOUT, a
jr z, .asm_38f14 jr z, .discourage
ld a, [wPlayerRolloutCount] ld a, [wPlayerRolloutCount]
cp 3 cp 3
jr c, .asm_38f14 jr c, .discourage
.asm_38f0d ; 80% chance to encourage this move otherwise.
.encourage
call AI_80_20 call AI_80_20
ret c ret c
dec [hl] dec [hl]
ret ret
.asm_38f13 .greatly_discourage
inc [hl] inc [hl]
.asm_38f14 .discourage
call Random call Random
cp 8 percent cp 8 percent
ret c ret c
inc [hl] inc [hl]
inc [hl] inc [hl]
ret ret
AI_Smart_Foresight: AI_Smart_Foresight:
; 60% chance to encourage this move if the enemy's accuracy is sharply lowered.
ld a, [wEnemyAccLevel] ld a, [wEnemyAccLevel]
cp BASE_STAT_LEVEL - 2 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] ld a, [wPlayerEvaLevel]
cp BASE_STAT_LEVEL + 3 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] ld a, [wBattleMonType1]
cp GHOST cp GHOST
jr z, .asm_38f41 jr z, .encourage
ld a, [wBattleMonType2] ld a, [wBattleMonType2]
cp GHOST cp GHOST
jr z, .asm_38f41 jr z, .encourage
; 92% chance to discourage this move otherwise.
call Random call Random
cp 8 percent cp 8 percent
ret c ret c
inc [hl] inc [hl]
ret ret
.asm_38f41 .encourage
call Random call Random
cp 39 percent + 1 cp 39 percent + 1
ret c ret c
dec [hl] dec [hl]
dec [hl] dec [hl]
ret ret
@ -1995,7 +2014,7 @@ AI_Smart_PerishSong:
push hl push hl
callfar CheckPlayerMoveTypeMatchups callfar CheckPlayerMoveTypeMatchups
ld a, [wEnemyAISwitchScore] ld a, [wEnemyAISwitchScore]
cp 10 ; 1.0 cp BASE_AI_SWITCH_SCORE
pop hl pop hl
ret c ret c
@ -2026,7 +2045,7 @@ AI_Smart_Sandstorm:
ld de, 1 ld de, 1
call IsInArray call IsInArray
pop hl pop hl
jr c, .asm_38fa5 jr c, .greatly_discourage
ld a, [wBattleMonType2] ld a, [wBattleMonType2]
push hl push hl
@ -2034,11 +2053,11 @@ AI_Smart_Sandstorm:
ld de, 1 ld de, 1
call IsInArray call IsInArray
pop hl pop hl
jr c, .asm_38fa5 jr c, .greatly_discourage
; Discourage this move if player's HP is below 50%. ; Discourage this move if player's HP is below 50%.
call AICheckPlayerHalfHP call AICheckPlayerHalfHP
jr nc, .asm_38fa6 jr nc, .discourage
; 50% chance to encourage this move otherwise. ; 50% chance to encourage this move otherwise.
call AI_50_50 call AI_50_50
@ -2047,10 +2066,9 @@ AI_Smart_Sandstorm:
dec [hl] dec [hl]
ret ret
.asm_38fa5 .greatly_discourage
inc [hl] inc [hl]
.discourage
.asm_38fa6
inc [hl] inc [hl]
ret ret
@ -2061,20 +2079,25 @@ AI_Smart_Sandstorm:
db -1 ; end db -1 ; end
AI_Smart_Endure: AI_Smart_Endure:
; Greatly discourage this move if the enemy already used Protect.
ld a, [wEnemyProtectCount] ld a, [wEnemyProtectCount]
and a and a
jr nz, .asm_38fd8 jr nz, .greatly_discourage
; Greatly discourage this move if the enemy's HP is full.
call AICheckEnemyMaxHP call AICheckEnemyMaxHP
jr c, .asm_38fd8 jr c, .greatly_discourage
; Discourage this move if the enemy's HP is at least 25%.
call AICheckEnemyQuarterHP call AICheckEnemyQuarterHP
jr c, .asm_38fd9 jr c, .discourage
; If the enemy has Reversal...
ld b, EFFECT_REVERSAL ld b, EFFECT_REVERSAL
call AIHasMoveEffect call AIHasMoveEffect
jr nc, .asm_38fcb jr nc, .no_reversal
; ...80% chance to greatly encourage this move.
call AI_80_20 call AI_80_20
ret c ret c
@ -2083,11 +2106,13 @@ AI_Smart_Endure:
dec [hl] dec [hl]
ret ret
.asm_38fcb .no_reversal
; If the enemy is not locked on, do nothing.
ld a, [wEnemySubStatus5] ld a, [wEnemySubStatus5]
bit SUBSTATUS_LOCK_ON, a bit SUBSTATUS_LOCK_ON, a
ret z ret z
; 50% chance to greatly encourage this move.
call AI_50_50 call AI_50_50
ret c ret c
@ -2095,10 +2120,9 @@ AI_Smart_Endure:
dec [hl] dec [hl]
ret ret
.asm_38fd8 .greatly_discourage
inc [hl] inc [hl]
.discourage
.asm_38fd9
inc [hl] inc [hl]
ret ret
@ -2107,22 +2131,20 @@ AI_Smart_FuryCutter:
ld a, [wEnemyFuryCutterCount] ld a, [wEnemyFuryCutterCount]
and a and a
jr z, .end jr z, AI_Smart_Rollout
dec [hl] dec [hl]
cp 2 cp 2
jr c, .end jr c, AI_Smart_Rollout
dec [hl] dec [hl]
dec [hl] dec [hl]
cp 3 cp 3
jr c, .end jr c, AI_Smart_Rollout
dec [hl] dec [hl]
dec [hl] dec [hl]
dec [hl] dec [hl]
.end
; fallthrough ; fallthrough
AI_Smart_Rollout: AI_Smart_Rollout:
@ -2131,29 +2153,29 @@ AI_Smart_Rollout:
; 80% chance to discourage this move if the enemy is in love, confused, or paralyzed. ; 80% chance to discourage this move if the enemy is in love, confused, or paralyzed.
ld a, [wEnemySubStatus1] ld a, [wEnemySubStatus1]
bit SUBSTATUS_IN_LOVE, a bit SUBSTATUS_IN_LOVE, a
jr nz, .asm_39020 jr nz, .maybe_discourage
ld a, [wEnemySubStatus3] ld a, [wEnemySubStatus3]
bit SUBSTATUS_CONFUSED, a bit SUBSTATUS_CONFUSED, a
jr nz, .asm_39020 jr nz, .maybe_discourage
ld a, [wEnemyMonStatus] ld a, [wEnemyMonStatus]
bit PAR, a 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%, ; 80% chance to discourage this move if the enemy's HP is below 25%,
; or if accuracy or evasion modifiers favour the player. ; or if accuracy or evasion modifiers favour the player.
call AICheckEnemyQuarterHP call AICheckEnemyQuarterHP
jr nc, .asm_39020 jr nc, .maybe_discourage
ld a, [wEnemyAccLevel] ld a, [wEnemyAccLevel]
cp BASE_STAT_LEVEL cp BASE_STAT_LEVEL
jr c, .asm_39020 jr c, .maybe_discourage
ld a, [wPlayerEvaLevel] ld a, [wPlayerEvaLevel]
cp BASE_STAT_LEVEL + 1 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 call Random
cp 79 percent - 1 cp 79 percent - 1
ret nc ret nc
@ -2161,7 +2183,7 @@ AI_Smart_Rollout:
dec [hl] dec [hl]
ret ret
.asm_39020 .maybe_discourage
call AI_80_20 call AI_80_20
ret c ret c
inc [hl] inc [hl]
@ -2235,7 +2257,7 @@ AI_Smart_BatonPass:
push hl push hl
callfar CheckPlayerMoveTypeMatchups callfar CheckPlayerMoveTypeMatchups
ld a, [wEnemyAISwitchScore] ld a, [wEnemyAISwitchScore]
cp 10 ; neutral cp BASE_AI_SWITCH_SCORE
pop hl pop hl
ret c ret c
inc [hl] inc [hl]
@ -2438,38 +2460,38 @@ AI_Smart_BellyDrum:
AI_Smart_PsychUp: AI_Smart_PsychUp:
push hl push hl
ld hl, wEnemyAtkLevel ld hl, wEnemyAtkLevel
ld b, $8 ld b, NUM_LEVEL_STATS
ld c, 100 ld c, 100
; Calculate the sum of all enemy's stat level modifiers. Add 100 first to prevent underflow. ; 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. ; Put the result in c. c will range between 58 and 142.
.asm_3915a .enemy_loop
ld a, [hli] ld a, [hli]
sub $7 sub BASE_STAT_LEVEL
add c add c
ld c, a ld c, a
dec b 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. ; 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. ; Put the result in d. d will range between 58 and 142.
ld hl, wPlayerAtkLevel ld hl, wPlayerAtkLevel
ld b, $8 ld b, NUM_LEVEL_STATS
ld d, 100 ld d, 100
.asm_39169 .player_loop
ld a, [hli] ld a, [hli]
sub $7 sub BASE_STAT_LEVEL
add d add d
ld d, a ld d, a
dec b 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). ; Greatly discourage this move if enemy's stat levels are higher than player's (if c>=d).
ld a, c ld a, c
sub d sub d
pop hl 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... ; Else, 80% chance to encourage this move unless player's accuracy level is lower than -1...
ld a, [wPlayerAccLevel] ld a, [wPlayerAccLevel]
@ -2487,7 +2509,7 @@ AI_Smart_PsychUp:
dec [hl] dec [hl]
ret ret
.asm_39188 .discourage
inc [hl] inc [hl]
inc [hl] inc [hl]
ret ret

View File

@ -5,7 +5,7 @@ CheckPlayerMoveTypeMatchups:
push hl push hl
push de push de
push bc push bc
ld a, 10 ld a, BASE_AI_SWITCH_SCORE
ld [wEnemyAISwitchScore], a ld [wEnemyAISwitchScore], a
ld hl, wPlayerUsedMoves ld hl, wPlayerUsedMoves
ld a, [hl] ld a, [hl]
@ -37,7 +37,7 @@ CheckPlayerMoveTypeMatchups:
cp EFFECTIVE ; 1.0 cp EFFECTIVE ; 1.0
jr nc, .neutral jr nc, .neutral
.not_very_effective ; not very effective
ld a, e ld a, e
cp 1 ; 0.1 cp 1 ; 0.1
jr nc, .next jr nc, .next