diff options
Diffstat (limited to 'engine/battle/trainer_ai.asm')
-rw-r--r-- | engine/battle/trainer_ai.asm | 169 |
1 files changed, 90 insertions, 79 deletions
diff --git a/engine/battle/trainer_ai.asm b/engine/battle/trainer_ai.asm index 2209fb57..0af1b86d 100644 --- a/engine/battle/trainer_ai.asm +++ b/engine/battle/trainer_ai.asm @@ -1,13 +1,13 @@ ; 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: ; 3969c (e:569c) ld a, $a 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 @@ -19,7 +19,7 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719) ld [hl], $50 ; forbid (highly discourage) disabled move .noMoveDisabled ld hl, TrainerClassMoveChoiceModifications - ld a, [W_TRAINERCLASS] + ld a, [wTrainerClass] ld b, a .loopTrainerClasses dec b @@ -103,14 +103,14 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719) ld hl, wEnemyMonMoves ; use original move set ret -AIMoveChoiceModificationFunctionPointers: ; 397a3 (e:57a3) +AIMoveChoiceModificationFunctionPointers: ; 39726 (e:5726) 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: ; 3972e (e:572e) ld a, [wBattleMonStatus] and a ret z ; return if no status ailment on player's mon @@ -129,7 +129,7 @@ AIMoveChoiceModification1: ; 397ab (e:57ab) ld a, [W_ENEMYMOVEPOWER] 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: ; 39765 (e:5765) db $01 ; unused sleep effect db SLEEP_EFFECT db POISON_EFFECT @@ -155,7 +155,7 @@ 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: ; 3976a (e:576a) ld a, [wAILayer2Encouragement] cp $1 ret nz @@ -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,13 +182,13 @@ 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: ; 3979a (e:579a) ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset) ld de, wEnemyMonMoves ; enemy moves ld b, NUM_MOVES + 1 @@ -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,14 +230,14 @@ 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] @@ -255,10 +255,10 @@ AIMoveChoiceModification3: ; 39817 (e:5817) jr z, .nextMove inc [hl] ; sligthly discourage this move jr .nextMove -AIMoveChoiceModification4: ; 39883 (e:5883) +AIMoveChoiceModification4: ; 39806 (e:5806) ret -ReadMove: ; 39884 (e:5884) +ReadMove: ; 39807 (e:5807) push hl push de push bc @@ -266,7 +266,7 @@ ReadMove: ; 39884 (e:5884) ld hl,Moves ld bc,MoveEnd - Moves call AddNTimes - ld de,W_ENEMYMOVENUM + ld de,wEnemyMoveNum call CopyData pop bc pop de @@ -275,7 +275,7 @@ ReadMove: ; 39884 (e:5884) ; move choice modification methods that are applied for each trainer class ; 0 is sentinel value -TrainerClassMoveChoiceModifications: ; 3989b (e:589b) +TrainerClassMoveChoiceModifications: ; 3981e (e:581e) db 0 ; YOUNGSTER db 1,0 ; BUG CATCHER db 1,0 ; LASS @@ -295,7 +295,7 @@ TrainerClassMoveChoiceModifications: ; 3989b (e:589b) db 1,0 ; GAMBLER db 1,3,0 ; BEAUTY db 1,2,0 ; PSYCHIC_TR - db 1,3,0 ; ROCKER + db 1,0 ; ROCKER db 1,0 ; JUGGLER db 1,0 ; TAMER db 1,0 ; BIRD_KEEPER @@ -311,11 +311,11 @@ 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,0 ; LT__SURGE db 1,3,0 ; ERIKA db 1,3,0 ; KOGA - db 1,3,0 ; BLAINE - db 1,3,0 ; SABRINA + db 1,0 ; BLAINE + db 1,0 ; SABRINA db 1,2,0 ; GENTLEMAN db 1,3,0 ; SONY2 db 1,3,0 ; SONY3 @@ -336,15 +336,21 @@ INCLUDE "data/trainer_moves.asm" INCLUDE "data/trainer_parties.asm" -TrainerAI: ; 3a52e (e:652e) - and a +TrainerAI: ; 3a5b2 (e:65b2) ld a,[wIsInBattle] dec a - ret z ; if not a trainer, we're done here + jr z, .done ; 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? + jr z, .done ; if in a link battle, we're done as well + ld a, [wEnemyBattleStatus1] + and 1 << ChargingUp | 1 << ThrashingAbout | 1 << StoringEnergy ; %10011 + jr nz, .done ; don't follow trainer ai if opponent is in a locked state + ld a, [wEnemyBattleStatus2] + and 1 << UsingRage ; %1000000 + jr nz, .done ; don't follow trainer ai if opponent is locked in rage + ; note that this doesn't check for hyper beam recharge which can cause problems + ld a,[wTrainerClass] ; what trainer class is this? dec a ld c,a ld b,0 @@ -354,7 +360,7 @@ TrainerAI: ; 3a52e (e:652e) add hl,bc ld a,[wAICount] and a - ret z ; if no AI uses left, we're done here + jr z, .done; if no AI uses left, we're done here inc hl inc a jr nz,.getpointer @@ -367,8 +373,11 @@ TrainerAI: ; 3a52e (e:652e) ld l,a call Random jp [hl] +.done + and a + ret -TrainerAIPointers: ; 3a55c (e:655c) +TrainerAIPointers: ; 3a5f2 (e:65f2) ; 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 @@ -420,27 +429,27 @@ TrainerAIPointers: ; 3a55c (e:655c) dbw 2,AgathaAI ; agatha dbw 1,LanceAI ; lance -JugglerAI: ; 3a5e9 (e:65e9) +JugglerAI: ; 3a67f (e:667f) cp $40 ret nc jp AISwitchIfEnoughMons -BlackbeltAI: ; 3a5ef (e:65ef) +BlackbeltAI: ; 3a685 (e:6685) cp $20 ret nc jp AIUseXAttack -GiovanniAI: ; 3a5f5 (e:65f5) +GiovanniAI: ; 3a68b (e:668b) cp $40 ret nc jp AIUseGuardSpec -CooltrainerMAI: ; 3a5fb (e:65fb) +CooltrainerMAI: ; 3a691 (e:6691) cp $40 ret nc jp AIUseXAttack -CooltrainerFAI: ; 3a601 (e:6601) +CooltrainerFAI: ; 3a697 (e:6697) cp $40 ld a,$A call AICheckIfHPBelowFraction @@ -450,24 +459,24 @@ CooltrainerFAI: ; 3a601 (e:6601) ret nc jp AISwitchIfEnoughMons -BrockAI: ; 3a614 (e:6614) +BrockAI: ; 3a6aa (e:66aa) ; 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: ; 3a6b2 (e:66b2) cp $40 ret nc jp AIUseXDefend -LtSurgeAI: ; 3a622 (e:6622) +LtSurgeAI: ; 3a6b8 (e:66b8) cp $40 ret nc jp AIUseXSpeed -ErikaAI: ; 3a628 (e:6628) +ErikaAI: ; 3a6be (e:66be) cp $80 ret nc ld a,$A @@ -475,25 +484,25 @@ ErikaAI: ; 3a628 (e:6628) ret nc jp AIUseSuperPotion -KogaAI: ; 3a634 (e:6634) - cp $40 +KogaAI: ; 3a6ca (e:66ca) + cp $20 ret nc jp AIUseXAttack -BlaineAI: ; 3a63a (e:663a) +BlaineAI: ; 3a6d0 (e:66d0) cp $40 ret nc + ld a,$A + call AICheckIfHPBelowFraction + ret nc jp AIUseSuperPotion -SabrinaAI: ; 3a640 (e:6640) +SabrinaAI: ; 3a6dc (e:66dc) cp $40 ret nc - ld a,$A - call AICheckIfHPBelowFraction - ret nc - jp AIUseHyperPotion + jp AIUseXDefend -Sony2AI: ; 3a64c (e:664c) +Sony2AI: ; 3a6e2 (e:66e2) cp $20 ret nc ld a,5 @@ -501,7 +510,7 @@ Sony2AI: ; 3a64c (e:664c) ret nc jp AIUsePotion -Sony3AI: ; 3a658 (e:6658) +Sony3AI: ; 3a6ee (e:66ee) cp $20 ret nc ld a,5 @@ -509,7 +518,7 @@ Sony3AI: ; 3a658 (e:6658) ret nc jp AIUseFullRestore -LoreleiAI: ; 3a664 (e:6664) +LoreleiAI: ; 3a6fa (e:66fa) cp $80 ret nc ld a,5 @@ -517,12 +526,12 @@ LoreleiAI: ; 3a664 (e:6664) ret nc jp AIUseSuperPotion -BrunoAI: ; 3a670 (e:6670) +BrunoAI: ; 3a706 (e:6706) cp $40 ret nc jp AIUseXDefend -AgathaAI: ; 3a676 (e:6676) +AgathaAI: ; 3a70c (e:670c) cp $14 jp c,AISwitchIfEnoughMons cp $80 @@ -532,7 +541,7 @@ AgathaAI: ; 3a676 (e:6676) ret nc jp AIUseSuperPotion -LanceAI: ; 3a687 (e:6687) +LanceAI: ; 3a71d (e:671d) cp $80 ret nc ld a,5 @@ -540,23 +549,23 @@ LanceAI: ; 3a687 (e:6687) ret nc jp AIUseHyperPotion -GenericAI: ; 3a693 (e:6693) +GenericAI: ; 3a729 (e:6729) and a ; clear carry ret ; end of individual trainer AI routines -DecrementAICount: ; 3a695 (e:6695) +DecrementAICount: ; 3a72b (e:672b) ld hl,wAICount dec [hl] scf ret -AIPlayRestoringSFX: ; 3a69b (e:669b) +AIPlayRestoringSFX: ; 3a731 (e:6731) ld a,SFX_HEAL_AILMENT jp PlaySoundWaitForCurrent -AIUseFullRestore: ; 3a6a0 (e:66a0) +AIUseFullRestore: ; 3a736 (e:6736) call AICureStatus ld a,FULL_RESTORE ld [wAIItem],a @@ -580,25 +589,25 @@ AIUseFullRestore: ; 3a6a0 (e:66a0) ld [wEnemyMonHP],a jr AIPrintItemUseAndUpdateHPBar -AIUsePotion: ; 3a6ca (e:66ca) +AIUsePotion: ; 3a760 (e:6760) ; enemy trainer heals his monster with a potion ld a,POTION ld b,20 jr AIRecoverHP -AIUseSuperPotion: ; 3a6d0 (e:66d0) +AIUseSuperPotion: ; 3a766 (e:6766) ; enemy trainer heals his monster with a super potion ld a,SUPER_POTION ld b,50 jr AIRecoverHP -AIUseHyperPotion: ; 3a6d6 (e:66d6) +AIUseHyperPotion: ; 3a76c (e:676c) ; enemy trainer heals his monster with a hyper potion ld a,HYPER_POTION ld b,200 ; fallthrough -AIRecoverHP: ; 3a6da (e:66da) +AIRecoverHP: ; 3a770 (e:6770) ; heal b HP and print "trainer used $(a) on pokemon!" ld [wAIItem],a ld hl,wEnemyMonHP + 1 @@ -639,7 +648,7 @@ AIRecoverHP: ; 3a6da (e:66da) ld [wHPBarNewHP+1],a ; fallthrough -AIPrintItemUseAndUpdateHPBar: ; 3a718 (e:6718) +AIPrintItemUseAndUpdateHPBar: ; 3a7ae (e:67ae) call AIPrintItemUse_ coord hl, 2, 2 xor a @@ -647,7 +656,7 @@ AIPrintItemUseAndUpdateHPBar: ; 3a718 (e:6718) predef UpdateHPBar2 jp DecrementAICount -AISwitchIfEnoughMons: ; 3a72a (e:672a) +AISwitchIfEnoughMons: ; 3a7c0 (e:67c0) ; enemy trainer switches if there are 3 or more unfainted mons in party ld a,[wEnemyPartyCount] ld c,a @@ -677,7 +686,7 @@ AISwitchIfEnoughMons: ; 3a72a (e:672a) and a ret -SwitchEnemyMon: ; 3a74b (e:674b) +SwitchEnemyMon: ; 3a7e1 (e:67e1) ; prepare to withdraw the active monster: copy hp, number, and status to roster @@ -708,17 +717,17 @@ SwitchEnemyMon: ; 3a74b (e:674b) scf ret -AIBattleWithdrawText: ; 3a781 (e:6781) +AIBattleWithdrawText: ; 3a817 (e:6817) TX_FAR _AIBattleWithdrawText db "@" -AIUseFullHeal: ; 3a786 (e:6786) +AIUseFullHeal: ; 3a81c (e:681c) call AIPlayRestoringSFX call AICureStatus ld a,FULL_HEAL jp AIPrintItemUse -AICureStatus: ; 3a791 (e:6791) +AICureStatus: ; 3a827 (e:6827) ; cures the status of enemy's active pokemon ld a,[wEnemyMonPartyPos] ld hl,wEnemyMon1Status @@ -731,28 +740,30 @@ AICureStatus: ; 3a791 (e:6791) res 0,[hl] ret -AIUseXAccuracy: ; 0x3a7a8 unused +AIUseXAccuracy: ; 3a83e (e:683e) +; unused call AIPlayRestoringSFX ld hl,wEnemyBattleStatus2 set 0,[hl] ld a,X_ACCURACY jp AIPrintItemUse -AIUseGuardSpec: ; 3a7b5 (e:67b5) +AIUseGuardSpec: ; 3a84b (e:684b) call AIPlayRestoringSFX ld hl,wEnemyBattleStatus2 set 1,[hl] ld a,GUARD_SPEC_ jp AIPrintItemUse -AIUseDireHit: ; 0x3a7c2 unused +AIUseDireHit: ; 3a858 (e:6858) +; unused call AIPlayRestoringSFX ld hl,wEnemyBattleStatus2 set 2,[hl] ld a,DIRE_HIT jp AIPrintItemUse -AICheckIfHPBelowFraction: ; 3a7cf (e:67cf) +AICheckIfHPBelowFraction: ; 3a865 (e:6865) ; return carry if enemy trainer's current HP is below 1 / a of the maximum ld [H_DIVISOR],a ld hl,wEnemyMonMaxHP @@ -778,32 +789,32 @@ AICheckIfHPBelowFraction: ; 3a7cf (e:67cf) sub c ret -AIUseXAttack: ; 3a7f2 (e:67f2) +AIUseXAttack: ; 3a888 (e:6888) ld b,$A ld a,X_ATTACK jr AIIncreaseStat -AIUseXDefend: ; 3a7f8 (e:67f8) +AIUseXDefend: ; 3a88e (e:688e) ld b,$B ld a,X_DEFEND jr AIIncreaseStat -AIUseXSpeed: ; 3a7fe (e:67fe) +AIUseXSpeed: ; 3a894 (e:6894) ld b,$C ld a,X_SPEED jr AIIncreaseStat -AIUseXSpecial: ; 3a804 (e:6804) +AIUseXSpecial: ; 3a89a (e:689a) ld b,$D ld a,X_SPECIAL ; fallthrough -AIIncreaseStat: ; 3a808 (e:6808) +AIIncreaseStat: ; 3a89e (e:689e) ld [wAIItem],a push bc call AIPrintItemUse_ pop bc - ld hl,W_ENEMYMOVEEFFECT + ld hl,wEnemyMoveEffect ld a,[hld] push af ld a,[hl] @@ -820,12 +831,12 @@ AIIncreaseStat: ; 3a808 (e:6808) ld [hl],a jp DecrementAICount -AIPrintItemUse: ; 3a82c (e:682c) +AIPrintItemUse: ; 3a8c2 (e:68c2) ld [wAIItem],a call AIPrintItemUse_ jp DecrementAICount -AIPrintItemUse_: ; 3a835 (e:6835) +AIPrintItemUse_: ; 3a8cb (e:68cb) ; print "x used [wAIItem] on z!" ld a,[wAIItem] ld [wd11e],a @@ -833,6 +844,6 @@ AIPrintItemUse_: ; 3a835 (e:6835) ld hl, AIBattleUseItemText jp PrintText -AIBattleUseItemText: ; 3a844 (e:6844) +AIBattleUseItemText: ; 3a8da (e:68da) TX_FAR _AIBattleUseItemText db "@" |