summaryrefslogtreecommitdiff
path: root/battle/ai/items.asm
diff options
context:
space:
mode:
Diffstat (limited to 'battle/ai/items.asm')
-rw-r--r--battle/ai/items.asm215
1 files changed, 112 insertions, 103 deletions
diff --git a/battle/ai/items.asm b/battle/ai/items.asm
index 5cd3fd7fc..95997a67e 100644
--- a/battle/ai/items.asm
+++ b/battle/ai/items.asm
@@ -1,11 +1,11 @@
-Function38000: ; 38000
+AI_SwitchOrTryItem: ; 38000
and a
- ld a, [IsInBattle]
+ ld a, [wBattleMode]
dec a
ret z
- ld a, [InLinkBattle]
+ ld a, [wLinkMode]
and a
ret nz
@@ -21,7 +21,7 @@ Function38000: ; 38000
jr nz, DontSwitch
ld hl, TrainerClassAttributes + 5
- ld a, [wcfc0]
+ ld a, [InBattleTowerBattle] ; Load always the first TrainerClass for BattleTower-Trainers
and a
jr nz, .ok
ld a, [TrainerClass]
@@ -73,6 +73,7 @@ SwitchOften: ; 38045
ld a, [wc717]
and $f
inc a
+ ; In register 'a' is the number (1-6) of the Pkmn to switch to
ld [wc718], a
jp AI_TrySwitch
; 38083
@@ -148,7 +149,7 @@ SwitchSometimes: ; 380c1
; 380ff
-Function380ff: ; 380ff
+CheckSubstatusCantRun: ; 380ff
ld a, [EnemySubStatus5]
bit SUBSTATUS_CANT_RUN, a
ret
@@ -156,7 +157,8 @@ Function380ff: ; 380ff
AI_TryItem: ; 38105
- ld a, [wcfc0]
+ ; items are not allowed in the BattleTower
+ ld a, [InBattleTowerBattle]
and a
ret nz
@@ -295,7 +297,7 @@ AI_Items: ; 39196
.FullHeal: ; 381be
call .Status
jp c, .DontUse
- call Function383a3
+ call EnemyUsedFullHeal
jp .Use
; 381ca
@@ -306,7 +308,7 @@ AI_Items: ; 39196
ld a, [bc]
bit CONTEXT_USE_F, a
- jr nz, .asm_381e7
+ jr nz, .StatusCheckContext
ld a, [bc]
bit ALWAYS_USE_F, a
jp nz, .Use
@@ -315,17 +317,17 @@ AI_Items: ; 39196
jp c, .Use
jp .DontUse
-.asm_381e7
+.StatusCheckContext
ld a, [EnemySubStatus5]
bit SUBSTATUS_TOXIC, a
- jr z, .asm_381fd
+ jr z, .FailToxicCheck
ld a, [EnemyToxicCount]
cp 4
- jr c, .asm_381fd
+ jr c, .FailToxicCheck
call Random
cp $80
jp c, .Use
-.asm_381fd
+.FailToxicCheck
ld a, [EnemyMonStatus]
and 1 << FRZ | SLP
jp z, .DontUse
@@ -334,58 +336,58 @@ AI_Items: ; 39196
.FullRestore: ; 38208
call .HealItem
- jp nc, .asm_3821a
+ jp nc, .UseFullRestore
ld a, [bc]
bit CONTEXT_USE_F, a
jp z, .DontUse
call .Status
jp c, .DontUse
-.asm_3821a
- call Function383b5
+.UseFullRestore
+ call EnemyUsedFullRestore
jp .Use
; 38220
.MaxPotion: ; 38220
call .HealItem
jp c, .DontUse
- call Function383ae
+ call EnemyUsedMaxPotion
jp .Use
.HealItem: ; 3822c (e:422c)
ld a, [bc]
bit CONTEXT_USE_F, a
- jr nz, .asm_38267
+ jr nz, .CheckHalfOrQuarterHP
callab AICheckEnemyHalfHP
jp c, .DontUse
ld a, [bc]
bit UNKNOWN_USE_F, a
- jp nz, .asm_38254
+ jp nz, .CheckQuarterHP
callab AICheckEnemyQuarterHP
- jp nc, .asm_38281
+ jp nc, .UseHealItem
call Random
cp $80
- jp c, .asm_38281
+ jp c, .UseHealItem
jp .DontUse
-.asm_38254: ; 38254 (e:4254)
+.CheckQuarterHP: ; 38254 (e:4254)
callab AICheckEnemyQuarterHP
jp c, .DontUse
call Random
- cp 50
+ cp $32
jp c, .DontUse
- jr .asm_38281
+ jr .UseHealItem
-.asm_38267: ; 38267 (e:4267)
+.CheckHalfOrQuarterHP: ; 38267 (e:4267)
callab AICheckEnemyHalfHP
jp c, .DontUse
callab AICheckEnemyQuarterHP
- jp nc, .asm_38281
+ jp nc, .UseHealItem
call Random
- cp 50
+ cp $32
jp nc, .DontUse
-.asm_38281: ; 38281 (e:4281)
+.UseHealItem: ; 38281 (e:4281)
jp .Use
; 38284
@@ -393,7 +395,7 @@ AI_Items: ; 39196
call .HealItem
jp c, .DontUse
ld b, 200
- call Function383f4
+ call EnemyUsedHyperPotion
jp .Use
; 38292 (e:4292)
@@ -401,7 +403,7 @@ AI_Items: ; 39196
call .HealItem
jp c, .DontUse
ld b, 50
- call Function383ee
+ call EnemyUsedSuperPotion
jp .Use
; 382a0
@@ -409,11 +411,11 @@ AI_Items: ; 39196
call .HealItem
jp c, .DontUse
ld b, 20
- call Function383e8
+ call EnemyUsedPotion
jp .Use
; 382ae
-.asm_382ae: ; 382ae
+.asm_382ae: ; This appears to be unused
callab AICheckEnemyMaxHP
jr c, .asm_382e4
push bc
@@ -452,7 +454,7 @@ AI_Items: ; 39196
bit UNKNOWN_USE_F, a
jp z, .DontUse
call Random
- cp 100
+ cp $64
jp c, .Use
jp .DontUse
; 382f9
@@ -460,56 +462,56 @@ AI_Items: ; 39196
.XAccuracy: ; 382f9
call .XItem
jp c, .DontUse
- call Function384f7
+ call EnemyUsedXAccuracy
jp .Use
; 38305
.GuardSpec: ; 38305
call .XItem
jp c, .DontUse
- call Function38504
+ call EnemyUsedGuardSpec
jp .Use
; 38311
.DireHit: ; 38311
call .XItem
jp c, .DontUse
- call Function38511
+ call EnemyUsedDireHit
jp .Use
; 3831d (e:431d)
.XAttack: ; 3831d
call .XItem
jp c, .DontUse
- call Function38541
+ call EnemyUsedXAttack
jp .Use
; 38329
.XDefend: ; 38329
call .XItem
jp c, .DontUse
- call Function38547
+ call EnemyUsedXDefend
jp .Use
; 38335
.XSpeed: ; 38335
call .XItem
jp c, .DontUse
- call Function3854d
+ call EnemyUsedXSpeed
jp .Use
; 38341
.XSpecial: ; 38341
call .XItem
jp c, .DontUse
- call Function38553
+ call EnemyUsedXSpecial
jp .Use
; 3834d
.XItem: ; 3834d (e:434d)
ld a, [EnemyTurnsTaken]
and a
- jr nz, .asm_38372
+ jr nz, .notfirstturnout
ld a, [bc]
bit ALWAYS_USE_F, a
jp nz, .Use
@@ -523,12 +525,12 @@ AI_Items: ; 39196
cp $80
jp c, .DontUse
jp .Use
-.asm_38372
+.notfirstturnout
ld a, [bc]
bit ALWAYS_USE_F, a
jp z, .DontUse
call Random
- cp 50
+ cp $32
jp nc, .DontUse
jp .Use
@@ -561,18 +563,18 @@ AIUsedItemSound: ; 3839a
; 383a3
-Function383a3: ; 383a3 (e:43a3)
+EnemyUsedFullHeal: ; 383a3 (e:43a3)
call AIUsedItemSound
call AI_HealStatus
ld a, FULL_HEAL
- jp Function38568
+ jp PrintText_UsedItemOn_AND_AIUpdateHUD
-Function383ae: ; 383ae (e:43ae)
+EnemyUsedMaxPotion: ; 383ae (e:43ae)
ld a, MAX_POTION
ld [wd1f1], a
- jr asm_383c6
+ jr FullRestoreContinue
-Function383b5: ; 383b5 (e:43b5)
+EnemyUsedFullRestore: ; 383b5 (e:43b5)
call AI_HealStatus
ld a, FULL_RESTORE
ld [wd1f1], a
@@ -581,7 +583,7 @@ Function383b5: ; 383b5 (e:43b5)
xor a
ld [EnemyConfuseCount], a
-asm_383c6: ; 383c6
+FullRestoreContinue: ; 383c6
ld de, wd1ec
ld hl, EnemyMonHP + 1
ld a, [hld]
@@ -600,24 +602,24 @@ asm_383c6: ; 383c6
ld [de], a
ld [Buffer2], a
ld [EnemyMonHP], a
- jr Function38436
+ jr EnemyPotionFinish
; 383e8 (e:43e8)
-Function383e8: ; 383e8
+EnemyUsedPotion: ; 383e8
ld a, POTION
ld b, 20
- jr Function383f8
+ jr EnemyPotionContinue
-Function383ee: ; 383ee
+EnemyUsedSuperPotion: ; 383ee
ld a, SUPER_POTION
ld b, 50
- jr Function383f8
+ jr EnemyPotionContinue
-Function383f4: ; 383f4 (e:43f4)
+EnemyUsedHyperPotion: ; 383f4 (e:43f4)
ld a, HYPER_POTION
ld b, 200
-Function383f8: ; 383f8
+EnemyPotionContinue: ; 383f8
ld [wd1f1], a
ld hl, EnemyMonHP + 1
ld a, [hl]
@@ -628,11 +630,11 @@ Function383f8: ; 383f8
ld a, [hl]
ld [wd1ec + 1], a
ld [wd1ee + 1], a
- jr nc, .asm_38415
+ jr nc, .ok
inc a
ld [hl], a
ld [wd1ee + 1], a
-.asm_38415
+.ok
inc hl
ld a, [hld]
ld b, a
@@ -646,7 +648,7 @@ Function383f8: ; 383f8
ld a, [de]
ld [Buffer2], a
sbc b
- jr nc, .asm_38436
+ jr nc, EnemyPotionFinish
inc de
ld a, [de]
dec de
@@ -655,10 +657,9 @@ Function383f8: ; 383f8
ld a, [de]
ld [hl], a
ld [wd1ef], a
-.asm_38436
-Function38436: ; 38436
- call Function38571
+EnemyPotionFinish: ; 38436
+ call PrintText_UsedItemOn
hlcoord 2, 2
xor a
ld [wd10a], a
@@ -668,24 +669,26 @@ Function38436: ; 38436
AI_TrySwitch: ; 3844b
+; Determine whether the AI can switch based on how many Pokemon are still alive.
+; If it can switch, it will.
ld a, [OTPartyCount]
ld c, a
ld hl, OTPartyMon1HP
ld d, 0
-.asm_38454
+.SwitchLoop
ld a, [hli]
ld b, a
ld a, [hld]
or b
- jr z, .asm_3845b
+ jr z, .fainted
inc d
-.asm_3845b
+.fainted
push bc
ld bc, PartyMon2 - PartyMon1
add hl, bc
pop bc
dec c
- jr nz, .asm_38454
+ jr nz, .SwitchLoop
ld a, d
cp 2
@@ -714,10 +717,10 @@ AI_Switch: ; 3846c
ld bc, $0004
call CopyBytes
pop af
- jr c, .asm_384a3
- ld hl, UnknownText_0x384d0
+ jr c, .skiptext
+ ld hl, TextJump_EnemyWithdrew
call PrintText
-.asm_384a3
+.skiptext
ld a, $1
ld [wd264], a
callab NewEnemyMonStatus
@@ -728,23 +731,23 @@ AI_Switch: ; 3846c
callba Function3d57a
xor a
ld [wd264], a
- ld a, [InLinkBattle]
+ ld a, [wLinkMode]
and a
ret nz
scf
ret
; 384d0
-UnknownText_0x384d0: ; 384d0
- text_jump UnknownText_0x1bcf9c
+TextJump_EnemyWithdrew: ; 384d0
+ text_jump Text_EnemyWithdrew
db "@"
; 384d5
-Function384d5: ; 384d5
+Function384d5: ; This appears to be unused
call AIUsedItemSound
call AI_HealStatus
- ld a, FULL_HEAL_RED
- jp Function38568
+ ld a, X_SPEED
+ jp PrintText_UsedItemOn_AND_AIUpdateHUD
; 384e0
AI_HealStatus: ; 384e0
@@ -760,42 +763,42 @@ AI_HealStatus: ; 384e0
ret
; 384f7
-Function384f7: ; 384f7
+EnemyUsedXAccuracy: ; 384f7
call AIUsedItemSound
ld hl, EnemySubStatus4
set SUBSTATUS_X_ACCURACY, [hl]
ld a, X_ACCURACY
- jp Function38568
+ jp PrintText_UsedItemOn_AND_AIUpdateHUD
; 38504
-Function38504: ; 38504
+EnemyUsedGuardSpec: ; 38504
call AIUsedItemSound
ld hl, EnemySubStatus4
set SUBSTATUS_MIST, [hl]
ld a, GUARD_SPEC
- jp Function38568
+ jp PrintText_UsedItemOn_AND_AIUpdateHUD
; 38511
-Function38511: ; 38511
+EnemyUsedDireHit: ; 38511
call AIUsedItemSound
ld hl, EnemySubStatus4
set SUBSTATUS_FOCUS_ENERGY, [hl]
ld a, DIRE_HIT
- jp Function38568
+ jp PrintText_UsedItemOn_AND_AIUpdateHUD
; 3851e
-Function3851e: ; 3851e
- ld [hMultiplier], a
+Function3851e: ; This appears to be unused
+ ld [hDivisor], a
ld hl, EnemyMonMaxHP
ld a, [hli]
- ld [hProduct], a
+ ld [hDividend], a
ld a, [hl]
- ld [hMultiplicand], a
- ld b, $2
+ ld [hDividend + 1], a
+ ld b, 2
call Divide
- ld a, [$ffb6]
+ ld a, [hQuotient + 2]
ld c, a
- ld a, [$ffb5]
+ ld a, [hQuotient + 1]
ld b, a
ld hl, EnemyMonHP + 1
ld a, [hld]
@@ -810,45 +813,51 @@ Function3851e: ; 3851e
ret
; 38541
-Function38541: ; 38541
+EnemyUsedXAttack: ; 38541
ld b, ATTACK
ld a, X_ATTACK
- jr Function38557
+ jr EnemyUsedXItem
; 38547
-Function38547: ; 38547
+EnemyUsedXDefend: ; 38547
ld b, DEFENSE
ld a, X_DEFEND
- jr Function38557
+ jr EnemyUsedXItem
; 3854d
-Function3854d: ; 3854d
+EnemyUsedXSpeed: ; 3854d
ld b, SPEED
ld a, X_SPEED
- jr Function38557
+ jr EnemyUsedXItem
; 38553
-Function38553: ; 38553
+EnemyUsedXSpecial: ; 38553
ld b, SP_ATTACK
ld a, X_SPECIAL
-Function38557:
+
+; Parameter
+; a = ITEM_CONSTANT
+; b = BATTLE_CONSTANT (ATTACK, DEFENSE, SPEED, SP_ATTACK, SP_DEFENSE, ACCURACY, EVASION)
+EnemyUsedXItem:
ld [wd1f1], a
push bc
- call Function38571
+ call PrintText_UsedItemOn
pop bc
- callba Function361ef
+ callba CheckIfStatCanBeRaised
jp AIUpdateHUD
; 38568
-Function38568: ; 38568
+; Parameter
+; a = ITEM_CONSTANT
+PrintText_UsedItemOn_AND_AIUpdateHUD: ; 38568
ld [wd1f1], a
- call Function38571
+ call PrintText_UsedItemOn
jp AIUpdateHUD
; 38571
-Function38571: ; 38571
+PrintText_UsedItemOn: ; 38571
ld a, [wd1f1]
ld [wd265], a
call GetItemName
@@ -856,11 +865,11 @@ Function38571: ; 38571
ld de, wd050
ld bc, ITEM_NAME_LENGTH
call CopyBytes
- ld hl, UnknownText_0x3858c
+ ld hl, TextJump_EnemyUsedOn
jp PrintText
; 3858c
-UnknownText_0x3858c: ; 3858c
- text_jump UnknownText_0x1bcfaf
+TextJump_EnemyUsedOn: ; 3858c
+ text_jump Text_EnemyUsedOn
db "@"
; 38591