summaryrefslogtreecommitdiff
path: root/engine/battle/trainer_ai.asm
diff options
context:
space:
mode:
Diffstat (limited to 'engine/battle/trainer_ai.asm')
-rw-r--r--engine/battle/trainer_ai.asm225
1 files changed, 113 insertions, 112 deletions
diff --git a/engine/battle/trainer_ai.asm b/engine/battle/trainer_ai.asm
index 191cfd5e..b175fcaf 100644
--- a/engine/battle/trainer_ai.asm
+++ b/engine/battle/trainer_ai.asm
@@ -1,25 +1,25 @@
; creates a set of moves that may be used and returns its address in hl
; unused slots are filled with 0, all used slots may be chosen with equal probability
-AIEnemyTrainerChooseMoves: ; 39719 (e:5719)
+AIEnemyTrainerChooseMoves:
ld a, $a
- ld hl, wHPBarMaxHP ; init temporary move selection array. Only the moves with the lowest numbers are chosen in the end
+ ld hl, wBuffer ; init temporary move selection array. Only the moves with the lowest numbers are chosen in the end
ld [hli], a ; move 1
ld [hli], a ; move 2
ld [hli], a ; move 3
ld [hl], a ; move 4
- ld a, [W_ENEMYDISABLEDMOVE] ; forbid disabled move (if any)
+ ld a, [wEnemyDisabledMove] ; forbid disabled move (if any)
swap a
and $f
jr z, .noMoveDisabled
- ld hl, wHPBarMaxHP
+ ld hl, wBuffer
dec a
ld c, a
ld b, $0
add hl, bc ; advance pointer to forbidden move
ld [hl], $50 ; forbid (highly discourage) disabled move
.noMoveDisabled
- ld hl, TrainerClassMoveChoiceModifications ; 589B
- ld a, [W_TRAINERCLASS]
+ ld hl, TrainerClassMoveChoiceModifications
+ ld a, [wTrainerClass]
ld b, a
.loopTrainerClasses
dec b
@@ -40,11 +40,11 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719)
and a
jr z, .loopFindMinimumEntries
push hl
- ld hl, AIMoveChoiceModificationFunctionPointers ; $57a3
+ ld hl, AIMoveChoiceModificationFunctionPointers
dec a
add a
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc ; skip to pointer
ld a, [hli] ; read pointer into hl
ld h, [hl]
@@ -53,9 +53,9 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719)
push de
jp [hl] ; execute modification function
.loopFindMinimumEntries ; all entries will be decremented sequentially until one of them is zero
- ld hl, wHPBarMaxHP ; temp move selection array
+ ld hl, wBuffer ; temp move selection array
ld de, wEnemyMonMoves ; enemy moves
- ld c, $4
+ ld c, NUM_MOVES
.loopDecrementEntries
ld a, [de]
inc de
@@ -73,15 +73,15 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719)
inc [hl]
dec hl
inc a
- cp $5
+ cp NUM_MOVES + 1
jr nz, .loopUndoPartialIteration
- ld hl, wHPBarMaxHP ; temp move selection array
+ ld hl, wBuffer ; temp move selection array
ld de, wEnemyMonMoves ; enemy moves
- ld c, $4
+ ld c, NUM_MOVES
.filterMinimalEntries ; all minimal entries now have value 1. All other slots will be disabled (move set to 0)
ld a, [de]
and a
- jr nz, .moveExisting ; 0x3978a $1
+ jr nz, .moveExisting
ld [hl], a
.moveExisting
ld a, [hl]
@@ -97,20 +97,20 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719)
inc de
dec c
jr nz, .filterMinimalEntries
- ld hl, wHPBarMaxHP ; use created temporary array as move set
+ ld hl, wBuffer ; use created temporary array as move set
ret
.useOriginalMoveSet
ld hl, wEnemyMonMoves ; use original move set
ret
-AIMoveChoiceModificationFunctionPointers: ; 397a3 (e:57a3)
+AIMoveChoiceModificationFunctionPointers:
dw AIMoveChoiceModification1
dw AIMoveChoiceModification2
dw AIMoveChoiceModification3
dw AIMoveChoiceModification4 ; unused, does nothing
; discourages moves that cause no damage but only a status ailment if player's mon already has one
-AIMoveChoiceModification1: ; 397ab (e:57ab)
+AIMoveChoiceModification1:
ld a, [wBattleMonStatus]
and a
ret z ; return if no status ailment on player's mon
@@ -126,10 +126,10 @@ AIMoveChoiceModification1: ; 397ab (e:57ab)
ret z ; no more moves in move set
inc de
call ReadMove
- ld a, [W_ENEMYMOVEPOWER]
+ ld a, [wEnemyMovePower]
and a
jr nz, .nextMove
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
push hl
push de
push bc
@@ -145,7 +145,7 @@ AIMoveChoiceModification1: ; 397ab (e:57ab)
ld [hl], a
jr .nextMove
-StatusAilmentMoveEffects ; 57e2
+StatusAilmentMoveEffects:
db $01 ; unused sleep effect
db SLEEP_EFFECT
db POISON_EFFECT
@@ -155,9 +155,9 @@ StatusAilmentMoveEffects ; 57e2
; slightly encourage moves with specific effects.
; in particular, stat-modifying moves and other move effects
; that fall in-bewteen
-AIMoveChoiceModification2: ; 397e7 (e:57e7)
+AIMoveChoiceModification2:
ld a, [wAILayer2Encouragement]
- cp $1
+ cp $1
ret nz
ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset)
ld de, wEnemyMonMoves ; enemy moves
@@ -171,7 +171,7 @@ AIMoveChoiceModification2: ; 397e7 (e:57e7)
ret z ; no more moves in move set
inc de
call ReadMove
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
cp ATTACK_UP1_EFFECT
jr c, .nextMove
cp BIDE_EFFECT
@@ -182,16 +182,16 @@ AIMoveChoiceModification2: ; 397e7 (e:57e7)
jr c, .preferMove
jr .nextMove
.preferMove
- dec [hl] ; sligthly encourage this move
+ dec [hl] ; slightly encourage this move
jr .nextMove
; encourages moves that are effective against the player's mon (even if non-damaging).
; discourage damaging moves that are ineffective or not very effective against the player's mon,
; unless there's no damaging move that deals at least neutral damage
-AIMoveChoiceModification3: ; 39817 (e:5817)
+AIMoveChoiceModification3:
ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset)
ld de, wEnemyMonMoves ; enemy moves
- ld b, $5
+ ld b, NUM_MOVES + 1
.nextMove
dec b
ret z ; processed all 4 moves
@@ -208,7 +208,7 @@ AIMoveChoiceModification3: ; 39817 (e:5817)
pop de
pop bc
pop hl
- ld a, [wd11e]
+ ld a, [wTypeEffectiveness]
cp $10
jr z, .nextMove
jr c, .notEffectiveMove
@@ -218,7 +218,7 @@ AIMoveChoiceModification3: ; 39817 (e:5817)
push hl
push de
push bc
- ld a, [W_ENEMYMOVETYPE]
+ ld a, [wEnemyMoveType]
ld d, a
ld hl, wEnemyMonMoves ; enemy moves
ld b, NUM_MOVES + 1
@@ -230,17 +230,17 @@ AIMoveChoiceModification3: ; 39817 (e:5817)
and a
jr z, .done
call ReadMove
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
cp SUPER_FANG_EFFECT
jr z, .betterMoveFound ; Super Fang is considered to be a better move
cp SPECIAL_DAMAGE_EFFECT
jr z, .betterMoveFound ; any special damage moves are considered to be better moves
cp FLY_EFFECT
jr z, .betterMoveFound ; Fly is considered to be a better move
- ld a, [W_ENEMYMOVETYPE]
+ ld a, [wEnemyMoveType]
cp d
jr z, .loopMoves
- ld a, [W_ENEMYMOVEPOWER]
+ ld a, [wEnemyMovePower]
and a
jr nz, .betterMoveFound ; damaging moves of a different type are considered to be better moves
jr .loopMoves
@@ -255,18 +255,18 @@ AIMoveChoiceModification3: ; 39817 (e:5817)
jr z, .nextMove
inc [hl] ; sligthly discourage this move
jr .nextMove
-AIMoveChoiceModification4: ; 39883 (e:5883)
+AIMoveChoiceModification4:
ret
-ReadMove: ; 39884 (e:5884)
+ReadMove:
push hl
push de
push bc
dec a
ld hl,Moves
- ld bc,6
+ ld bc,MoveEnd - Moves
call AddNTimes
- ld de,W_ENEMYMOVENUM
+ ld de,wEnemyMoveNum
call CopyData
pop bc
pop de
@@ -275,13 +275,13 @@ ReadMove: ; 39884 (e:5884)
; move choice modification methods that are applied for each trainer class
; 0 is sentinel value
-TrainerClassMoveChoiceModifications: ; 3989b (e:589b)
+TrainerClassMoveChoiceModifications:
db 0 ; YOUNGSTER
db 1,0 ; BUG CATCHER
db 1,0 ; LASS
db 1,3,0 ; SAILOR
- db 1,0 ; JR__TRAINER_M
- db 1,0 ; JR__TRAINER_F
+ db 1,0 ; JR_TRAINER_M
+ db 1,0 ; JR_TRAINER_F
db 1,2,3,0; POKEMANIAC
db 1,2,0 ; SUPER_NERD
db 1,0 ; HIKER
@@ -311,7 +311,7 @@ TrainerClassMoveChoiceModifications: ; 3989b (e:589b)
db 1,0 ; BRUNO
db 1,0 ; BROCK
db 1,3,0 ; MISTY
- db 1,3,0 ; LT__SURGE
+ db 1,3,0 ; LT_SURGE
db 1,3,0 ; ERIKA
db 1,3,0 ; KOGA
db 1,3,0 ; BLAINE
@@ -325,8 +325,8 @@ TrainerClassMoveChoiceModifications: ; 3989b (e:589b)
db 1,3,0 ; LANCE
INCLUDE "engine/battle/trainer_pic_money_pointers.asm"
-
-INCLUDE "text/trainer_names.asm"
+
+INCLUDE "text/trainer_names.asm"
INCLUDE "engine/battle/bank_e_misc.asm"
@@ -336,16 +336,15 @@ INCLUDE "data/trainer_moves.asm"
INCLUDE "data/trainer_parties.asm"
-TrainerAI: ; 3a52e (e:652e)
-;XXX called at 34964, 3c342, 3c398
+TrainerAI:
and a
- ld a,[W_ISINBATTLE]
+ ld a,[wIsInBattle]
dec a
ret z ; if not a trainer, we're done here
ld a,[wLinkState]
cp LINK_STATE_BATTLING
ret z
- ld a,[W_TRAINERCLASS] ; what trainer class is this?
+ ld a,[wTrainerClass] ; what trainer class is this?
dec a
ld c,a
ld b,0
@@ -369,7 +368,7 @@ TrainerAI: ; 3a52e (e:652e)
call Random
jp [hl]
-TrainerAIPointers: ; 3a55c (e:655c)
+TrainerAIPointers:
; one entry per trainer class
; first byte, number of times (per Pokémon) it can occur
; next two bytes, pointer to AI subroutine for trainer class
@@ -421,27 +420,27 @@ TrainerAIPointers: ; 3a55c (e:655c)
dbw 2,AgathaAI ; agatha
dbw 1,LanceAI ; lance
-JugglerAI: ; 3a5e9 (e:65e9)
+JugglerAI:
cp $40
ret nc
jp AISwitchIfEnoughMons
-BlackbeltAI: ; 3a5ef (e:65ef)
+BlackbeltAI:
cp $20
ret nc
jp AIUseXAttack
-GiovanniAI: ; 3a5f5 (e:65f5)
+GiovanniAI:
cp $40
ret nc
jp AIUseGuardSpec
-CooltrainerMAI: ; 3a5fb (e:65fb)
+CooltrainerMAI:
cp $40
ret nc
jp AIUseXAttack
-CooltrainerFAI: ; 3a601 (e:6601)
+CooltrainerFAI:
cp $40
ld a,$A
call AICheckIfHPBelowFraction
@@ -451,24 +450,24 @@ CooltrainerFAI: ; 3a601 (e:6601)
ret nc
jp AISwitchIfEnoughMons
-BrockAI: ; 3a614 (e:6614)
+BrockAI:
; if his active monster has a status condition, use a full heal
ld a,[wEnemyMonStatus]
and a
ret z
jp AIUseFullHeal
-MistyAI: ; 3a61c (e:661c)
+MistyAI:
cp $40
ret nc
jp AIUseXDefend
-LtSurgeAI: ; 3a622 (e:6622)
+LtSurgeAI:
cp $40
ret nc
jp AIUseXSpeed
-ErikaAI: ; 3a628 (e:6628)
+ErikaAI:
cp $80
ret nc
ld a,$A
@@ -476,17 +475,17 @@ ErikaAI: ; 3a628 (e:6628)
ret nc
jp AIUseSuperPotion
-KogaAI: ; 3a634 (e:6634)
+KogaAI:
cp $40
ret nc
jp AIUseXAttack
-BlaineAI: ; 3a63a (e:663a)
+BlaineAI:
cp $40
ret nc
jp AIUseSuperPotion
-SabrinaAI: ; 3a640 (e:6640)
+SabrinaAI:
cp $40
ret nc
ld a,$A
@@ -494,7 +493,7 @@ SabrinaAI: ; 3a640 (e:6640)
ret nc
jp AIUseHyperPotion
-Sony2AI: ; 3a64c (e:664c)
+Sony2AI:
cp $20
ret nc
ld a,5
@@ -502,7 +501,7 @@ Sony2AI: ; 3a64c (e:664c)
ret nc
jp AIUsePotion
-Sony3AI: ; 3a658 (e:6658)
+Sony3AI:
cp $20
ret nc
ld a,5
@@ -510,7 +509,7 @@ Sony3AI: ; 3a658 (e:6658)
ret nc
jp AIUseFullRestore
-LoreleiAI: ; 3a664 (e:6664)
+LoreleiAI:
cp $80
ret nc
ld a,5
@@ -518,12 +517,12 @@ LoreleiAI: ; 3a664 (e:6664)
ret nc
jp AIUseSuperPotion
-BrunoAI: ; 3a670 (e:6670)
+BrunoAI:
cp $40
ret nc
jp AIUseXDefend
-AgathaAI: ; 3a676 (e:6676)
+AgathaAI:
cp $14
jp c,AISwitchIfEnoughMons
cp $80
@@ -533,7 +532,7 @@ AgathaAI: ; 3a676 (e:6676)
ret nc
jp AIUseSuperPotion
-LanceAI: ; 3a687 (e:6687)
+LanceAI:
cp $80
ret nc
ld a,5
@@ -541,26 +540,26 @@ LanceAI: ; 3a687 (e:6687)
ret nc
jp AIUseHyperPotion
-GenericAI: ; 3a693 (e:6693)
+GenericAI:
and a ; clear carry
ret
; end of individual trainer AI routines
-DecrementAICount: ; 3a695 (e:6695)
+DecrementAICount:
ld hl,wAICount
dec [hl]
scf
ret
-Func_3a69b: ; 3a69b (e:669b)
- ld a,(SFX_08_3e - SFX_Headers_08) / 3
+AIPlayRestoringSFX:
+ ld a,SFX_HEAL_AILMENT
jp PlaySoundWaitForCurrent
-AIUseFullRestore: ; 3a6a0 (e:66a0)
+AIUseFullRestore:
call AICureStatus
ld a,FULL_RESTORE
- ld [wcf05],a
+ ld [wAIItem],a
ld de,wHPBarOldHP
ld hl,wEnemyMonHP + 1
ld a,[hld]
@@ -581,27 +580,27 @@ AIUseFullRestore: ; 3a6a0 (e:66a0)
ld [wEnemyMonHP],a
jr AIPrintItemUseAndUpdateHPBar
-AIUsePotion: ; 3a6ca (e:66ca)
+AIUsePotion:
; enemy trainer heals his monster with a potion
ld a,POTION
ld b,20
jr AIRecoverHP
-AIUseSuperPotion: ; 3a6d0 (e:66d0)
+AIUseSuperPotion:
; enemy trainer heals his monster with a super potion
ld a,SUPER_POTION
ld b,50
jr AIRecoverHP
-AIUseHyperPotion: ; 3a6d6 (e:66d6)
+AIUseHyperPotion:
; enemy trainer heals his monster with a hyper potion
ld a,HYPER_POTION
ld b,200
; fallthrough
-AIRecoverHP: ; 3a6da (e:66da)
+AIRecoverHP:
; heal b HP and print "trainer used $(a) on pokemon!"
- ld [wcf05],a
+ ld [wAIItem],a
ld hl,wEnemyMonHP + 1
ld a,[hl]
ld [wHPBarOldHP],a
@@ -640,15 +639,15 @@ AIRecoverHP: ; 3a6da (e:66da)
ld [wHPBarNewHP+1],a
; fallthrough
-AIPrintItemUseAndUpdateHPBar: ; 3a718 (e:6718)
+AIPrintItemUseAndUpdateHPBar:
call AIPrintItemUse_
- hlCoord 2, 2
+ coord hl, 2, 2
xor a
ld [wHPBarType],a
predef UpdateHPBar2
jp DecrementAICount
-AISwitchIfEnoughMons: ; 3a72a (e:672a)
+AISwitchIfEnoughMons:
; enemy trainer switches if there are 3 or more unfainted mons in party
ld a,[wEnemyPartyCount]
ld c,a
@@ -666,7 +665,7 @@ AISwitchIfEnoughMons: ; 3a72a (e:672a)
inc d
.Fainted
push bc
- ld bc,$2C
+ ld bc, wEnemyMon2 - wEnemyMon1
add hl,bc
pop bc
dec c
@@ -678,7 +677,7 @@ AISwitchIfEnoughMons: ; 3a72a (e:672a)
and a
ret
-SwitchEnemyMon: ; 3a74b (e:674b)
+SwitchEnemyMon:
; prepare to withdraw the active monster: copy hp, number, and status to roster
@@ -695,11 +694,13 @@ SwitchEnemyMon: ; 3a74b (e:674b)
ld hl, AIBattleWithdrawText
call PrintText
+ ; This wFirstMonsNotOutYet variable is abused to prevent the player from
+ ; switching in a new mon in response to this switch.
ld a,1
- ld [wd11d],a
+ ld [wFirstMonsNotOutYet],a
callab EnemySendOut
xor a
- ld [wd11d],a
+ ld [wFirstMonsNotOutYet],a
ld a,[wLinkState]
cp LINK_STATE_BATTLING
@@ -707,17 +708,17 @@ SwitchEnemyMon: ; 3a74b (e:674b)
scf
ret
-AIBattleWithdrawText: ; 3a781 (e:6781)
+AIBattleWithdrawText:
TX_FAR _AIBattleWithdrawText
db "@"
-AIUseFullHeal: ; 3a786 (e:6786)
- call Func_3a69b
+AIUseFullHeal:
+ call AIPlayRestoringSFX
call AICureStatus
ld a,FULL_HEAL
jp AIPrintItemUse
-AICureStatus: ; 3a791 (e:6791)
+AICureStatus:
; cures the status of enemy's active pokemon
ld a,[wEnemyMonPartyPos]
ld hl,wEnemyMon1Status
@@ -726,32 +727,32 @@ AICureStatus: ; 3a791 (e:6791)
xor a
ld [hl],a ; clear status in enemy team roster
ld [wEnemyMonStatus],a ; clear status of active enemy
- ld hl,W_ENEMYBATTSTATUS3
+ ld hl,wEnemyBattleStatus3
res 0,[hl]
ret
-AIUseXAccuracy: ; 0x3a7a8 unused
- call Func_3a69b
- ld hl,W_ENEMYBATTSTATUS2
+AIUseXAccuracy: ; unused
+ call AIPlayRestoringSFX
+ ld hl,wEnemyBattleStatus2
set 0,[hl]
ld a,X_ACCURACY
jp AIPrintItemUse
-AIUseGuardSpec: ; 3a7b5 (e:67b5)
- call Func_3a69b
- ld hl,W_ENEMYBATTSTATUS2
+AIUseGuardSpec:
+ call AIPlayRestoringSFX
+ ld hl,wEnemyBattleStatus2
set 1,[hl]
- ld a,GUARD_SPEC_
+ ld a,GUARD_SPEC
jp AIPrintItemUse
-AIUseDireHit: ; 0x3a7c2 unused
- call Func_3a69b
- ld hl,W_ENEMYBATTSTATUS2
+AIUseDireHit: ; unused
+ call AIPlayRestoringSFX
+ ld hl,wEnemyBattleStatus2
set 2,[hl]
ld a,DIRE_HIT
jp AIPrintItemUse
-AICheckIfHPBelowFraction: ; 3a7cf (e:67cf)
+AICheckIfHPBelowFraction:
; return carry if enemy trainer's current HP is below 1 / a of the maximum
ld [H_DIVISOR],a
ld hl,wEnemyMonMaxHP
@@ -777,38 +778,38 @@ AICheckIfHPBelowFraction: ; 3a7cf (e:67cf)
sub c
ret
-AIUseXAttack: ; 3a7f2 (e:67f2)
+AIUseXAttack:
ld b,$A
ld a,X_ATTACK
jr AIIncreaseStat
-AIUseXDefend: ; 3a7f8 (e:67f8)
+AIUseXDefend:
ld b,$B
ld a,X_DEFEND
jr AIIncreaseStat
-AIUseXSpeed: ; 3a7fe (e:67fe)
+AIUseXSpeed:
ld b,$C
ld a,X_SPEED
jr AIIncreaseStat
-AIUseXSpecial: ; 3a804 (e:6804)
+AIUseXSpecial:
ld b,$D
ld a,X_SPECIAL
; fallthrough
-AIIncreaseStat: ; 3a808 (e:6808)
- ld [wcf05],a
+AIIncreaseStat:
+ ld [wAIItem],a
push bc
call AIPrintItemUse_
pop bc
- ld hl,W_ENEMYMOVEEFFECT
+ ld hl,wEnemyMoveEffect
ld a,[hld]
push af
ld a,[hl]
push af
push hl
- ld a,$AF
+ ld a,ANIM_AF
ld [hli],a
ld [hl],b
callab StatModifierUpEffect
@@ -819,19 +820,19 @@ AIIncreaseStat: ; 3a808 (e:6808)
ld [hl],a
jp DecrementAICount
-AIPrintItemUse: ; 3a82c (e:682c)
- ld [wcf05],a
+AIPrintItemUse:
+ ld [wAIItem],a
call AIPrintItemUse_
jp DecrementAICount
-AIPrintItemUse_: ; 3a835 (e:6835)
-; print "x used [wcf05] on z!"
- ld a,[wcf05]
+AIPrintItemUse_:
+; print "x used [wAIItem] on z!"
+ ld a,[wAIItem]
ld [wd11e],a
call GetItemName
ld hl, AIBattleUseItemText
jp PrintText
-AIBattleUseItemText: ; 3a844 (e:6844)
+AIBattleUseItemText:
TX_FAR _AIBattleUseItemText
db "@"