summaryrefslogtreecommitdiff
path: root/engine/battle/ai/items.asm
diff options
context:
space:
mode:
Diffstat (limited to 'engine/battle/ai/items.asm')
-rw-r--r--engine/battle/ai/items.asm156
1 files changed, 53 insertions, 103 deletions
diff --git a/engine/battle/ai/items.asm b/engine/battle/ai/items.asm
index 218ecd375..29bc23b20 100644
--- a/engine/battle/ai/items.asm
+++ b/engine/battle/ai/items.asm
@@ -1,4 +1,4 @@
-AI_SwitchOrTryItem: ; 38000
+AI_SwitchOrTryItem:
and a
ld a, [wBattleMode]
@@ -38,12 +38,11 @@ AI_SwitchOrTryItem: ; 38000
jp nz, SwitchSometimes
; fallthrough
-DontSwitch: ; 38041
+DontSwitch:
call AI_TryItem
ret
-; 38045
-SwitchOften: ; 38045
+SwitchOften:
callfar CheckAbleToSwitch
ld a, [wEnemySwitchMonParam]
and $f0
@@ -77,9 +76,8 @@ SwitchOften: ; 38045
; In register 'a' is the number (1-6) of the mon to switch to
ld [wEnemySwitchMonIndex], a
jp AI_TrySwitch
-; 38083
-SwitchRarely: ; 38083
+SwitchRarely:
callfar CheckAbleToSwitch
ld a, [wEnemySwitchMonParam]
and $f0
@@ -112,9 +110,8 @@ SwitchRarely: ; 38083
inc a
ld [wEnemySwitchMonIndex], a
jp AI_TrySwitch
-; 380c1
-SwitchSometimes: ; 380c1
+SwitchSometimes:
callfar CheckAbleToSwitch
ld a, [wEnemySwitchMonParam]
and $f0
@@ -147,17 +144,13 @@ SwitchSometimes: ; 380c1
inc a
ld [wEnemySwitchMonIndex], a
jp AI_TrySwitch
-; 380ff
-
-CheckSubstatusCantRun: ; 380ff
+CheckSubstatusCantRun:
ld a, [wEnemySubStatus5]
bit SUBSTATUS_CANT_RUN, a
ret
-; 38105
-
-AI_TryItem: ; 38105
+AI_TryItem:
; items are not allowed in the BattleTower
ld a, [wInBattleTowerBattle]
and a
@@ -243,8 +236,7 @@ AI_TryItem: ; 38105
scf
ret
-
-.IsHighestLevel: ; 38170
+.IsHighestLevel:
ld a, [wOTPartyCount]
ld d, a
ld e, 0
@@ -274,10 +266,8 @@ AI_TryItem: ; 38105
.yes
scf
ret
-; 38196
-
-AI_Items: ; 39196
+AI_Items:
dbw FULL_RESTORE, .FullRestore
dbw MAX_POTION, .MaxPotion
dbw HYPER_POTION, .HyperPotion
@@ -292,16 +282,14 @@ AI_Items: ; 39196
dbw X_SPEED, .XSpeed
dbw X_SPECIAL, .XSpecial
db -1 ; end
-; 381be
-.FullHeal: ; 381be
+.FullHeal:
call .Status
jp c, .DontUse
call EnemyUsedFullHeal
jp .Use
-; 381ca
-.Status: ; 381ca (e:41ca)
+.Status:
ld a, [wEnemyMonStatus]
and a
jp z, .DontUse
@@ -332,9 +320,8 @@ AI_Items: ; 39196
and 1 << FRZ | SLP
jp z, .DontUse
jp .Use
-; 38208
-.FullRestore: ; 38208
+.FullRestore:
call .HealItem
jp nc, .UseFullRestore
ld a, [bc]
@@ -346,15 +333,14 @@ AI_Items: ; 39196
.UseFullRestore:
call EnemyUsedFullRestore
jp .Use
-; 38220
-.MaxPotion: ; 38220
+.MaxPotion:
call .HealItem
jp c, .DontUse
call EnemyUsedMaxPotion
jp .Use
-.HealItem: ; 3822c (e:422c)
+.HealItem:
ld a, [bc]
bit CONTEXT_USE_F, a
jr nz, .CheckHalfOrQuarterHP
@@ -370,7 +356,7 @@ AI_Items: ; 39196
jp c, .UseHealItem
jp .DontUse
-.CheckQuarterHP: ; 38254 (e:4254)
+.CheckQuarterHP:
callfar AICheckEnemyQuarterHP
jp c, .DontUse
call Random
@@ -378,7 +364,7 @@ AI_Items: ; 39196
jp c, .DontUse
jr .UseHealItem
-.CheckHalfOrQuarterHP: ; 38267 (e:4267)
+.CheckHalfOrQuarterHP:
callfar AICheckEnemyHalfHP
jp c, .DontUse
callfar AICheckEnemyQuarterHP
@@ -387,33 +373,29 @@ AI_Items: ; 39196
cp 20 percent - 1
jp nc, .DontUse
-.UseHealItem: ; 38281 (e:4281)
+.UseHealItem:
jp .Use
-; 38284
-.HyperPotion: ; 38284
+.HyperPotion:
call .HealItem
jp c, .DontUse
ld b, 200
call EnemyUsedHyperPotion
jp .Use
-; 38292 (e:4292)
-.SuperPotion: ; 38292
+.SuperPotion:
call .HealItem
jp c, .DontUse
ld b, 50
call EnemyUsedSuperPotion
jp .Use
-; 382a0
-.Potion: ; 382a0
+.Potion:
call .HealItem
jp c, .DontUse
ld b, 20
call EnemyUsedPotion
jp .Use
-; 382ae
.asm_382ae ; This appears to be unused
callfar AICheckEnemyMaxHP
@@ -457,58 +439,50 @@ AI_Items: ; 39196
cp 39 percent + 1
jp c, .Use
jp .DontUse
-; 382f9
-.XAccuracy: ; 382f9
+.XAccuracy:
call .XItem
jp c, .DontUse
call EnemyUsedXAccuracy
jp .Use
-; 38305
-.GuardSpec: ; 38305
+.GuardSpec:
call .XItem
jp c, .DontUse
call EnemyUsedGuardSpec
jp .Use
-; 38311
-.DireHit: ; 38311
+.DireHit:
call .XItem
jp c, .DontUse
call EnemyUsedDireHit
jp .Use
-; 3831d (e:431d)
-.XAttack: ; 3831d
+.XAttack:
call .XItem
jp c, .DontUse
call EnemyUsedXAttack
jp .Use
-; 38329
-.XDefend: ; 38329
+.XDefend:
call .XItem
jp c, .DontUse
call EnemyUsedXDefend
jp .Use
-; 38335
-.XSpeed: ; 38335
+.XSpeed:
call .XItem
jp c, .DontUse
call EnemyUsedXSpeed
jp .Use
-; 38341
-.XSpecial: ; 38341
+.XSpecial:
call .XItem
jp c, .DontUse
call EnemyUsedXSpecial
jp .Use
-; 3834d
-.XItem: ; 3834d (e:434d)
+.XItem:
ld a, [wEnemyTurnsTaken]
and a
jr nz, .notfirstturnout
@@ -542,8 +516,7 @@ AI_Items: ; 39196
and a
ret
-
-AIUpdateHUD: ; 38387
+AIUpdateHUD:
call UpdateEnemyMonInParty
farcall UpdateEnemyHUD
ld a, $1
@@ -552,29 +525,26 @@ AIUpdateHUD: ; 38387
dec [hl]
scf
ret
-; 3839a
-AIUsedItemSound: ; 3839a
+AIUsedItemSound:
push de
ld de, SFX_FULL_HEAL
call PlaySFX
pop de
ret
-; 383a3
-
-EnemyUsedFullHeal: ; 383a3 (e:43a3)
+EnemyUsedFullHeal:
call AIUsedItemSound
call AI_HealStatus
ld a, FULL_HEAL
jp PrintText_UsedItemOn_AND_AIUpdateHUD
-EnemyUsedMaxPotion: ; 383ae (e:43ae)
+EnemyUsedMaxPotion:
ld a, MAX_POTION
ld [wCurEnemyItem], a
jr FullRestoreContinue
-EnemyUsedFullRestore: ; 383b5 (e:43b5)
+EnemyUsedFullRestore:
call AI_HealStatus
ld a, FULL_RESTORE
ld [wCurEnemyItem], a
@@ -583,7 +553,7 @@ EnemyUsedFullRestore: ; 383b5 (e:43b5)
xor a
ld [wEnemyConfuseCount], a
-FullRestoreContinue: ; 383c6
+FullRestoreContinue:
ld de, wCurHPAnimOldHP
ld hl, wEnemyMonHP + 1
ld a, [hld]
@@ -603,23 +573,22 @@ FullRestoreContinue: ; 383c6
ld [wCurHPAnimMaxHP + 1], a
ld [wEnemyMonHP], a
jr EnemyPotionFinish
-; 383e8 (e:43e8)
-EnemyUsedPotion: ; 383e8
+EnemyUsedPotion:
ld a, POTION
ld b, 20
jr EnemyPotionContinue
-EnemyUsedSuperPotion: ; 383ee
+EnemyUsedSuperPotion:
ld a, SUPER_POTION
ld b, 50
jr EnemyPotionContinue
-EnemyUsedHyperPotion: ; 383f4 (e:43f4)
+EnemyUsedHyperPotion:
ld a, HYPER_POTION
ld b, 200
-EnemyPotionContinue: ; 383f8
+EnemyPotionContinue:
ld [wCurEnemyItem], a
ld hl, wEnemyMonHP + 1
ld a, [hl]
@@ -658,7 +627,7 @@ EnemyPotionContinue: ; 383f8
ld [hl], a
ld [wCurHPAnimNewHP + 1], a
-EnemyPotionFinish: ; 38436
+EnemyPotionFinish:
call PrintText_UsedItemOn
hlcoord 2, 2
xor a
@@ -667,8 +636,7 @@ EnemyPotionFinish: ; 38436
predef AnimateHPBar
jp AIUpdateHUD
-
-AI_TrySwitch: ; 3844b
+AI_TrySwitch:
; Determine whether the AI can switch based on how many Pokemon are still alive.
; If it can switch, it will.
ld a, [wOTPartyCount]
@@ -695,9 +663,8 @@ AI_TrySwitch: ; 3844b
jp nc, AI_Switch
and a
ret
-; 3846c
-AI_Switch: ; 3846c
+AI_Switch:
ld a, $1
ld [wEnemyIsSwitching], a
ld [wEnemyGoesFirst], a
@@ -739,21 +706,18 @@ AI_Switch: ; 3846c
ret nz
scf
ret
-; 384d0
-TextJump_EnemyWithdrew: ; 384d0
+TextJump_EnemyWithdrew:
text_jump Text_EnemyWithdrew
db "@"
-; 384d5
Function384d5: ; This appears to be unused
call AIUsedItemSound
call AI_HealStatus
ld a, FULL_HEAL_RED ; X_SPEED
jp PrintText_UsedItemOn_AND_AIUpdateHUD
-; 384e0
-AI_HealStatus: ; 384e0
+AI_HealStatus:
ld a, [wCurOTMon]
ld hl, wOTPartyMon1Status
ld bc, PARTYMON_STRUCT_LENGTH
@@ -768,31 +732,27 @@ AI_HealStatus: ; 384e0
ld hl, wEnemySubStatus5
res SUBSTATUS_TOXIC, [hl]
ret
-; 384f7
-EnemyUsedXAccuracy: ; 384f7
+EnemyUsedXAccuracy:
call AIUsedItemSound
ld hl, wEnemySubStatus4
set SUBSTATUS_X_ACCURACY, [hl]
ld a, X_ACCURACY
jp PrintText_UsedItemOn_AND_AIUpdateHUD
-; 38504
-EnemyUsedGuardSpec: ; 38504
+EnemyUsedGuardSpec:
call AIUsedItemSound
ld hl, wEnemySubStatus4
set SUBSTATUS_MIST, [hl]
ld a, GUARD_SPEC
jp PrintText_UsedItemOn_AND_AIUpdateHUD
-; 38511
-EnemyUsedDireHit: ; 38511
+EnemyUsedDireHit:
call AIUsedItemSound
ld hl, wEnemySubStatus4
set SUBSTATUS_FOCUS_ENERGY, [hl]
ld a, DIRE_HIT
jp PrintText_UsedItemOn_AND_AIUpdateHUD
-; 3851e
Function3851e: ; This appears to be unused
ld [hDivisor], a
@@ -818,31 +778,26 @@ Function3851e: ; This appears to be unused
ld a, e
sub c
ret
-; 38541
-EnemyUsedXAttack: ; 38541
+EnemyUsedXAttack:
ld b, ATTACK
ld a, X_ATTACK
jr EnemyUsedXItem
-; 38547
-EnemyUsedXDefend: ; 38547
+EnemyUsedXDefend:
ld b, DEFENSE
ld a, X_DEFEND
jr EnemyUsedXItem
-; 3854d
-EnemyUsedXSpeed: ; 3854d
+EnemyUsedXSpeed:
ld b, SPEED
ld a, X_SPEED
jr EnemyUsedXItem
-; 38553
-EnemyUsedXSpecial: ; 38553
+EnemyUsedXSpecial:
ld b, SP_ATTACK
ld a, X_SPECIAL
-
; Parameter
; a = ITEM_CONSTANT
; b = BATTLE_CONSTANT (ATTACK, DEFENSE, SPEED, SP_ATTACK, SP_DEFENSE, ACCURACY, EVASION)
@@ -853,18 +808,15 @@ EnemyUsedXItem:
pop bc
farcall CheckIfStatCanBeRaised
jp AIUpdateHUD
-; 38568
-
; Parameter
; a = ITEM_CONSTANT
-PrintText_UsedItemOn_AND_AIUpdateHUD: ; 38568
+PrintText_UsedItemOn_AND_AIUpdateHUD:
ld [wCurEnemyItem], a
call PrintText_UsedItemOn
jp AIUpdateHUD
-; 38571
-PrintText_UsedItemOn: ; 38571
+PrintText_UsedItemOn:
ld a, [wCurEnemyItem]
ld [wd265], a
call GetItemName
@@ -874,9 +826,7 @@ PrintText_UsedItemOn: ; 38571
call CopyBytes
ld hl, TextJump_EnemyUsedOn
jp PrintText
-; 3858c
-TextJump_EnemyUsedOn: ; 3858c
+TextJump_EnemyUsedOn:
text_jump Text_EnemyUsedOn
db "@"
-; 38591