summaryrefslogtreecommitdiff
path: root/src/engine/bank05.asm
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/bank05.asm')
-rw-r--r--src/engine/bank05.asm419
1 files changed, 1 insertions, 418 deletions
diff --git a/src/engine/bank05.asm b/src/engine/bank05.asm
index 5417ecc..762d5c8 100644
--- a/src/engine/bank05.asm
+++ b/src/engine/bank05.asm
@@ -1213,424 +1213,7 @@ AIProcessHandTrainerCards: ; 14663 (5:4663)
farcall _AIProcessHandTrainerCards
ret
-AIActionTable_GeneralDecks: ; 14668 (05:4668)
- dw .do_turn ; unused
- dw .do_turn
- dw .start_duel
- dw .forced_switch
- dw .ko_switch
- dw .take_prize
-
-.do_turn ; 14674 (5:4674)
- call AIMainTurnLogic
- ret
-
-.start_duel ; 14678 (5:4678)
- call InitAIDuelVars
- call AIPlayInitialBasicCards
- ret
-
-.forced_switch ; 1467f (5:467f)
- call AIDecideBenchPokemonToSwitchTo
- ret
-
-.ko_switch ; 14683 (5:4683)
- call AIDecideBenchPokemonToSwitchTo
- ret
-
-.take_prize: ; 14687 (5:4687)
- call AIPickPrizeCards
- ret
-
-; handle AI routines for a whole turn
-AIMainTurnLogic: ; 1468b (5:468b)
-; initialize variables
- call InitAITurnVars
- ld a, AI_TRAINER_CARD_PHASE_01
- call AIProcessHandTrainerCards
- farcall HandleAIAntiMewtwoDeckStrategy
- jp nc, .try_attack
-; handle Pkmn Powers
- farcall HandleAIGoGoRainDanceEnergy
- farcall HandleAIDamageSwap
- farcall HandleAIPkmnPowers
- ret c ; return if turn ended
- farcall HandleAICowardice
-; process Trainer cards
-; phase 2 through 4.
- ld a, AI_TRAINER_CARD_PHASE_02
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_03
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_04
- call AIProcessHandTrainerCards
-; play Pokemon from hand
- call AIDecidePlayPokemonCard
- ret c ; return if turn ended
-; process Trainer cards
-; phase 5 through 12.
- ld a, AI_TRAINER_CARD_PHASE_05
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_06
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_07
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_08
- call AIProcessHandTrainerCards
- call AIProcessRetreat
- ld a, AI_TRAINER_CARD_PHASE_10
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_11
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_12
- call AIProcessHandTrainerCards
-; play Energy card if possible
- ld a, [wAlreadyPlayedEnergy]
- or a
- jr nz, .skip_energy_attach_1
- call AIProcessAndTryToPlayEnergy
-.skip_energy_attach_1
-; play Pokemon from hand again
- call AIDecidePlayPokemonCard
-; handle Pkmn Powers again
- farcall HandleAIDamageSwap
- farcall HandleAIPkmnPowers
- ret c ; return if turn ended
- farcall HandleAIGoGoRainDanceEnergy
- ld a, AI_ENERGY_TRANS_ATTACK
- farcall HandleAIEnergyTrans
-; process Trainer cards phases 13 and 15
- ld a, AI_TRAINER_CARD_PHASE_13
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_15
- call AIProcessHandTrainerCards
-; if used Professor Oak, process new hand
-; if not, then proceed to attack.
- ld a, [wPreviousAIFlags]
- and AI_FLAG_USED_PROFESSOR_OAK
- jr z, .try_attack
- ld a, AI_TRAINER_CARD_PHASE_01
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_02
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_03
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_04
- call AIProcessHandTrainerCards
- call AIDecidePlayPokemonCard
- ret c ; return if turn ended
- ld a, AI_TRAINER_CARD_PHASE_05
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_06
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_07
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_08
- call AIProcessHandTrainerCards
- call AIProcessRetreat
- ld a, AI_TRAINER_CARD_PHASE_10
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_11
- call AIProcessHandTrainerCards
- ld a, AI_TRAINER_CARD_PHASE_12
- call AIProcessHandTrainerCards
- ld a, [wAlreadyPlayedEnergy]
- or a
- jr nz, .skip_energy_attach_2
- call AIProcessAndTryToPlayEnergy
-.skip_energy_attach_2
- call AIDecidePlayPokemonCard
- farcall HandleAIDamageSwap
- farcall HandleAIPkmnPowers
- ret c ; return if turn ended
- farcall HandleAIGoGoRainDanceEnergy
- ld a, AI_ENERGY_TRANS_ATTACK
- farcall HandleAIEnergyTrans
- ld a, AI_TRAINER_CARD_PHASE_13
- call AIProcessHandTrainerCards
- ; skip AI_TRAINER_CARD_PHASE_15
-.try_attack
- ld a, AI_ENERGY_TRANS_TO_BENCH
- farcall HandleAIEnergyTrans
-; attack if possible, if not,
-; finish turn without attacking.
- call AIProcessAndTryToUseAttack
- ret c ; return if AI attacked
- ld a, OPPACTION_FINISH_NO_ATTACK
- bank1call AIMakeDecision
- ret
-; 0x14786
-
-; handles AI retreating logic
-AIProcessRetreat: ; 14786 (5:4786)
- ld a, [wAIRetreatedThisTurn]
- or a
- ret nz ; return, already retreated this turn
-
- call AIDecideWhetherToRetreat
- ret nc ; return if not retreating
-
- call AIDecideBenchPokemonToSwitchTo
- ret c ; return if no Bench Pokemon
-
-; store Play Area to retreat to and
-; set wAIRetreatedThisTurn to true
- ld [wAIPlayAreaCardToSwitch], a
- ld a, $01
- ld [wAIRetreatedThisTurn], a
-
-; if AI can use Switch from hand, use it instead...
- ld a, AI_TRAINER_CARD_PHASE_09
- call AIProcessHandTrainerCards
- ld a, [wPreviousAIFlags]
- and AI_FLAG_USED_SWITCH
- jr nz, .used_switch
-; ... else try retreating normally.
- ld a, [wAIPlayAreaCardToSwitch]
- call AITryToRetreat
- ret
-
-.used_switch
-; if AI used switch, unset its AI flag
- ld a, [wPreviousAIFlags]
- and ~AI_FLAG_USED_SWITCH ; clear Switch flag
- ld [wPreviousAIFlags], a
-
-; bug, this doesn't make sense being here, since at this point
-; Switch Trainer card was already used to retreat the Pokemon.
-; what the routine will do is just transfer Energy cards to
-; the Arena Pokemon for the purpose of retreating, and
-; then not actually retreat, resulting in unusual behaviour.
-; this would only work placed right after the AI checks whether
-; they have Switch card in hand to use and doesn't have one.
-; (and probably that was the original intention.)
- ld a, AI_ENERGY_TRANS_RETREAT ; retreat
- farcall HandleAIEnergyTrans
- ret
-; 0x147bd
-
-AIActionTable_SamPractice: ; 147bd (05:47bd)
- dw .do_turn ; unused
- dw .do_turn
- dw .start_duel
- dw .forced_switch
- dw .ko_switch
- dw .take_prize
-
-.do_turn ; 147c9 (5:47c9)
- call IsAIPracticeScriptedTurn
- jr nc, .scripted_1
-; not scripted, use AI main turn logic
- call AIMainTurnLogic
- ret
-.scripted_1 ; use scripted actions instead
- call AIPerformSciptedTurn
- ret
-; 0x147d6
-
-.start_duel ; 147d6 (5:47d6)
- call Func_14801
- ret
-; 0x147da
-
-.forced_switch ; 147da (5:47da)
- call IsAIPracticeScriptedTurn
- jr nc, .scripted_2
- call AIDecideBenchPokemonToSwitchTo
- ret
-.scripted_2
- call PickRandomBenchPokemon
- ret
-; 0x147e7
-
-.ko_switch: ; 147e7 (5:47e7)
- call IsAIPracticeScriptedTurn
- jr nc, .scripted_3
- call AIDecideBenchPokemonToSwitchTo
- ret
-.scripted_3
- call GetPlayAreaLocationOfRaticateOrRattata
- ret
-; 0x147f4
-
-.take_prize: ; 147f4 (5:47f4)
- call AIPickPrizeCards
- ret
-; 0x147f8
-
-; returns carry if number of turns
-; the AI has taken >= 7.
-; used to know whether AI Sam is still
-; doing scripted turns.
-IsAIPracticeScriptedTurn: ; 147f8 (5:47f8)
- ld a, [wDuelTurns]
- srl a
- cp 7
- ccf
- ret
-; 0x14801
-
-; places one Machop from the hand to the Play Area
-; and sets the number of prizes to 2.
-Func_14801: ; 14801 (5:4801)
- call CreateHandCardList
- ld hl, wDuelTempList
-.loop_hand
- ld a, [hli]
- ldh [hTempCardIndex_ff98], a
- cp $ff
- ret z
- call LoadCardDataToBuffer1_FromDeckIndex
- cp MACHOP
- jr nz, .loop_hand
- ldh a, [hTempCardIndex_ff98]
- call PutHandPokemonCardInPlayArea
- ld a, 2
- ld [wDuelInitialPrizes], a
- ret
-; 0x1481f
-
-; outputs in a Play Area location of Raticate or Rattata
-; in the Bench. If neither is found, just output PLAY_AREA_BENCH_1.
-GetPlayAreaLocationOfRaticateOrRattata: ; 1481f (5:481f)
- ld a, RATICATE
- ld b, PLAY_AREA_BENCH_1
- call LookForCardIDInPlayArea_Bank5
- cp $ff
- jr nz, .found
- ld a, RATTATA
- ld b, PLAY_AREA_BENCH_1
- call LookForCardIDInPlayArea_Bank5
- cp $ff
- jr nz, .found
- ld a, PLAY_AREA_BENCH_1
-.found
- ldh [hTempPlayAreaLocation_ff9d], a
- ret
-; 0x1483a
-
-; has AI execute some scripted actions depending on Duel turn.
-AIPerformSciptedTurn: ; 1483a (5:483a)
- ld a, [wDuelTurns]
- srl a
- ld hl, .scripted_actions_list
- call JumpToFunctionInTable
-
-; always attack with Arena card's first attack.
-; if it's unusable end turn without attacking.
- xor a
- ldh [hTempPlayAreaLocation_ff9d], a
- ld [wSelectedAttack], a
- call CheckIfSelectedMoveIsUnusable
- jr c, .unusable
- call AITryUseAttack
- ret
-
-.unusable
- ld a, OPPACTION_FINISH_NO_ATTACK
- bank1call AIMakeDecision
- ret
-; 0x1485a
-
-.scripted_actions_list ; 1485a (05:485a)
- dw .turn_1
- dw .turn_2
- dw .turn_3
- dw .turn_4
- dw .turn_5
- dw .turn_6
- dw .turn_7
-; 0x14868
-
-.turn_1 ; 14868 (5:4868)
- ld d, MACHOP
- ld e, FIGHTING_ENERGY
- call AIAttachEnergyInHandToCardInPlayArea
- ret
-; 0x14870
-
-.turn_2 ; 14870 (5:4870)
- ld a, RATTATA
- call LookForCardIDInHandList_Bank5
- ldh [hTemp_ffa0], a
- ld a, OPPACTION_PLAY_BASIC_PKMN
- bank1call AIMakeDecision
- ld d, RATTATA
- ld e, FIGHTING_ENERGY
- call AIAttachEnergyInHandToCardInPlayArea
- ret
-; 0x14884
-
-.turn_3 ; 14884 (5:4884)
- ld a, RATTATA
- ld b, PLAY_AREA_ARENA
- call LookForCardIDInPlayArea_Bank5
- ldh [hTempPlayAreaLocation_ffa1], a
- ld a, RATICATE
- call LookForCardIDInHandList_Bank5
- ldh [hTemp_ffa0], a
- ld a, OPPACTION_EVOLVE_PKMN
- bank1call AIMakeDecision
- ld d, RATICATE
- ld e, LIGHTNING_ENERGY
- call AIAttachEnergyInHandToCardInPlayArea
- ret
-; 0x148a1
-
-.turn_4 ; 148a1 (5:48a1)
- ld d, RATICATE
- ld e, LIGHTNING_ENERGY
- call AIAttachEnergyInHandToCardInPlayArea
- ret
-; 0x148a9
-
-.turn_5 ; 148a9 (5:48a9)
- ld a, MACHOP
- call LookForCardIDInHandList_Bank5
- ldh [hTemp_ffa0], a
- ld a, OPPACTION_PLAY_BASIC_PKMN
- bank1call AIMakeDecision
- ld d, MACHOP
- ld e, FIGHTING_ENERGY
- call AIAttachEnergyInHandToCardInBench
-
-; this is a bug, it's attempting to compare a card ID with a deck index.
-; the intention was to change the card to switch to depending on whether
-; the first Machop was KO'd at this point in the Duel or not.
-; because of the buggy comparison, this will always jump the
-; 'inc a' instruction and switch to PLAY_AREA_BENCH_1.
-; in a normal Practice Duel following Dr. Mason's instructions,
-; this will always lead to the AI correctly switching Raticate with Machop,
-; but in case of a "Free" Duel where the first Machop is not KO'd,
-; the intention was to switch to PLAY_AREA_BENCH_2 instead.
-; but due to 'inc a' always being skipped, it will switch to Raticate.
- ld a, DUELVARS_ARENA_CARD
- call GetTurnDuelistVariable
- cp MACHOP ; wrong
- ld a, PLAY_AREA_BENCH_1
- jr nz, .retreat
- inc a ; PLAY_AREA_BENCH_2
-
-.retreat
- call AITryToRetreat
- ret
-; 0x148cc
-
-.turn_6 ; 148cc (5:48cc)
- ld d, MACHOP
- ld e, FIGHTING_ENERGY
- call AIAttachEnergyInHandToCardInPlayArea
- ret
-; 0x148d4
-
-.turn_7 ; 148d4 (5:48d4)
- ld d, MACHOP
- ld e, FIGHTING_ENERGY
- call AIAttachEnergyInHandToCardInPlayArea
- ret
-; 0x148dc
-
-INCLUDE "engine/deck_ai.asm"
+INCLUDE "engine/deck_ai/deck_ai.asm"
; return carry if card ID loaded in a is found in hand
; and outputs in a the deck index of that card