summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorElectroDeoxys <ElectroDeoxys@gmail.com>2020-05-09 12:11:05 +0100
committerElectroDeoxys <ElectroDeoxys@gmail.com>2020-05-09 12:11:05 +0100
commit86d8cfb0fd86326e4534fc33c7bb384d515bbe0e (patch)
tree625d2b2c14fef5740592114a1470082fa5e3098a /src
parentd20d490df325c1671357acd894ec14ed36599797 (diff)
Separate AI constants and new AIACTION_*
Diffstat (limited to 'src')
-rw-r--r--src/constants.asm1
-rw-r--r--src/constants/deck_ai_constants.asm61
-rw-r--r--src/constants/duel_constants.asm53
-rw-r--r--src/data/deck_ai_pointers.asm2
-rw-r--r--src/engine/bank01.asm8
-rw-r--r--src/engine/deck_ai/deck_ai.asm1
-rw-r--r--src/engine/effect_functions.asm2
-rw-r--r--src/engine/home.asm40
8 files changed, 91 insertions, 77 deletions
diff --git a/src/constants.asm b/src/constants.asm
index 4e6f410..6e6f0b3 100644
--- a/src/constants.asm
+++ b/src/constants.asm
@@ -1,6 +1,7 @@
INCLUDE "constants/booster_constants.asm"
INCLUDE "constants/card_constants.asm"
INCLUDE "constants/card_data_constants.asm"
+INCLUDE "constants/deck_ai_constants.asm"
INCLUDE "constants/deck_constants.asm"
INCLUDE "constants/duel_constants.asm"
INCLUDE "constants/duel_interface_constants.asm"
diff --git a/src/constants/deck_ai_constants.asm b/src/constants/deck_ai_constants.asm
new file mode 100644
index 0000000..ceae8ed
--- /dev/null
+++ b/src/constants/deck_ai_constants.asm
@@ -0,0 +1,61 @@
+; wPreviousAIFlags and wCurrentAIFlags constants
+AI_FLAG_USED_PLUSPOWER EQU 1 << 0
+AI_FLAG_USED_SWITCH EQU 1 << 1
+AI_FLAG_USED_PROFESSOR_OAK EQU 1 << 2
+AI_FLAG_MODIFIED_HAND EQU 1 << 3
+AI_FLAG_USED_GUST_OF_WIND EQU 1 << 4
+
+; used as input for AIProcessEnergyCards to determine what to check
+; and whether to play card after the routine is over.
+; I suspect AI_ENERGY_FLAG_DONT_PLAY to be a flag to signal the routine
+; not to actually play the energy card after it's finished,
+; but AIProcessEnergyCards checks whether ANY flag is set in order
+; to decide not to play it, so it's redundant in the presence of another flag.
+AI_ENERGY_FLAG_DONT_PLAY EQU 1 << 0 ; whether to play energy card (?)
+AI_ENERGY_FLAG_SKIP_EVOLUTION EQU 1 << 1 ; whether to check if card has evolutions
+AI_ENERGY_FLAG_SKIP_ARENA_CARD EQU 1 << 7 ; whether to include Arena card in determining which card to attach energy
+
+; used to determine which Trainer cards for AI
+; to process in AIProcessHandTrainerCards.
+; these go in chronological order, except for
+; AI_TRAINER_CARD_PHASE_14 which happens just before AI attacks.
+; AI_TRAINER_CARD_PHASE_15 is reserved for Professor Oak card.
+; if Professor Oak is played, all other Trainer card phases
+; are processed again except AI_TRAINER_CARD_PHASE_15.
+ const_def 1
+ const AI_TRAINER_CARD_PHASE_01 ; $1
+ const AI_TRAINER_CARD_PHASE_02 ; $2
+ const AI_TRAINER_CARD_PHASE_03 ; $3
+ const AI_TRAINER_CARD_PHASE_04 ; $4
+ const AI_TRAINER_CARD_PHASE_05 ; $5
+ const AI_TRAINER_CARD_PHASE_06 ; $6
+ const AI_TRAINER_CARD_PHASE_07 ; $7
+ const AI_TRAINER_CARD_PHASE_08 ; $8
+ const AI_TRAINER_CARD_PHASE_09 ; $9
+ const AI_TRAINER_CARD_PHASE_10 ; $a
+ const AI_TRAINER_CARD_PHASE_11 ; $b
+ const AI_TRAINER_CARD_PHASE_12 ; $c
+ const AI_TRAINER_CARD_PHASE_13 ; $d
+ const AI_TRAINER_CARD_PHASE_14 ; $e, just before attack
+ const AI_TRAINER_CARD_PHASE_15 ; $f, for Professor Oak
+
+; used by wAIBarrierFlagCounter to determine
+; whether Player is running Mewtwo1 mill deck.
+; flag set means true, flag not set means false.
+AI_FLAG_MEWTWO_MILL EQU 1 << 7
+
+; defines the behaviour of HandleAIEnergyTrans, for determining
+; whether to move energy cards from the Bench to the Arena or vice-versa
+; and the number of energy cards needed for achieving that.
+AI_ENERGY_TRANS_RETREAT EQU $9 ; moves energy cards needed for Retreat Cost
+AI_ENERGY_TRANS_ATTACK EQU $d ; moves energy cards needed for second attack
+AI_ENERGY_TRANS_TO_BENCH EQU $e ; moves energy cards away from Arena card
+
+; used to know which AI routine to call in
+; the AIAction pointer tables in AIDoAction
+ const_def 1
+ const AIACTION_DO_TURN ; $1
+ const AIACTION_START_DUEL ; $2
+ const AIACTION_FORCED_SWITCH ; $3
+ const AIACTION_KO_SWITCH ; $4
+ const AIACTION_TAKE_PRIZE ; $5
diff --git a/src/constants/duel_constants.asm b/src/constants/duel_constants.asm
index dd692d0..d461d24 100644
--- a/src/constants/duel_constants.asm
+++ b/src/constants/duel_constants.asm
@@ -226,56 +226,3 @@ EFFECT_FAILED_UNSUCCESSFUL EQU $02
; wAnimationQueue length
ANIMATION_QUEUE_LENGTH EQU 7
-
-; wPreviousAIFlags and wCurrentAIFlags constants
-AI_FLAG_USED_PLUSPOWER EQU 1 << 0
-AI_FLAG_USED_SWITCH EQU 1 << 1
-AI_FLAG_USED_PROFESSOR_OAK EQU 1 << 2
-AI_FLAG_MODIFIED_HAND EQU 1 << 3
-AI_FLAG_USED_GUST_OF_WIND EQU 1 << 4
-
-; used as input for AIProcessEnergyCards to determine what to check
-; and whether to play card after the routine is over.
-; I suspect AI_ENERGY_FLAG_DONT_PLAY to be a flag to signal the routine
-; not to actually play the energy card after it's finished,
-; but AIProcessEnergyCards checks whether ANY flag is set in order
-; to decide not to play it, so it's redundant in the presence of another flag.
-AI_ENERGY_FLAG_DONT_PLAY EQU 1 << 0 ; whether to play energy card (?)
-AI_ENERGY_FLAG_SKIP_EVOLUTION EQU 1 << 1 ; whether to check if card has evolutions
-AI_ENERGY_FLAG_SKIP_ARENA_CARD EQU 1 << 7 ; whether to include Arena card in determining which card to attach energy
-
-; used to determine which Trainer cards for AI
-; to process in AIProcessHandTrainerCards.
-; these go in chronological order, except for
-; AI_TRAINER_CARD_PHASE_14 which happens just before AI attacks.
-; AI_TRAINER_CARD_PHASE_15 is reserved for Professor Oak card.
-; if Professor Oak is played, all other Trainer card phases
-; are processed again except AI_TRAINER_CARD_PHASE_15.
- const_def 1
- const AI_TRAINER_CARD_PHASE_01 ; $1
- const AI_TRAINER_CARD_PHASE_02 ; $2
- const AI_TRAINER_CARD_PHASE_03 ; $3
- const AI_TRAINER_CARD_PHASE_04 ; $4
- const AI_TRAINER_CARD_PHASE_05 ; $5
- const AI_TRAINER_CARD_PHASE_06 ; $6
- const AI_TRAINER_CARD_PHASE_07 ; $7
- const AI_TRAINER_CARD_PHASE_08 ; $8
- const AI_TRAINER_CARD_PHASE_09 ; $9
- const AI_TRAINER_CARD_PHASE_10 ; $a
- const AI_TRAINER_CARD_PHASE_11 ; $b
- const AI_TRAINER_CARD_PHASE_12 ; $c
- const AI_TRAINER_CARD_PHASE_13 ; $d
- const AI_TRAINER_CARD_PHASE_14 ; $e, just before attack
- const AI_TRAINER_CARD_PHASE_15 ; $f, for Professor Oak
-
-; used by wAIBarrierFlagCounter to determine
-; whether Player is running Mewtwo1 mill deck.
-; flag set means true, flag not set means false.
-AI_FLAG_MEWTWO_MILL EQU 1 << 7
-
-; defines the behaviour of HandleAIEnergyTrans, for determining
-; whether to move energy cards from the Bench to the Arena or vice-versa
-; and the number of energy cards needed for achieving that.
-AI_ENERGY_TRANS_RETREAT EQU $9 ; moves energy cards needed for Retreat Cost
-AI_ENERGY_TRANS_ATTACK EQU $d ; moves energy cards needed for second attack
-AI_ENERGY_TRANS_TO_BENCH EQU $e ; moves energy cards away from Arena card
diff --git a/src/data/deck_ai_pointers.asm b/src/data/deck_ai_pointers.asm
index 72cbfb0..4f00299 100644
--- a/src/data/deck_ai_pointers.asm
+++ b/src/data/deck_ai_pointers.asm
@@ -1,4 +1,4 @@
-PointerTable_14000: ; 14000 (05:4000)
+DeckAIPointerTable: ; 14000 (05:4000)
dw AIActionTable_SamPractice ; SAMS_PRACTICE_DECK
dw AIActionTable_GeneralDecks ; PRACTICE_PLAYER_DECK
dw AIActionTable_GeneralDecks ; SAMS_NORMAL_DECK
diff --git a/src/engine/bank01.asm b/src/engine/bank01.asm
index 7eb7340..8f780eb 100644
--- a/src/engine/bank01.asm
+++ b/src/engine/bank01.asm
@@ -353,7 +353,7 @@ DuelMainInterface: ; 426d (1:426d)
ld [wSkipDuelistIsThinkingDelay], a
ldtx hl, DuelistIsThinkingText
call DrawWideTextBox_PrintTextNoDelay
- call Func_2bbf
+ call AIDoAction_Turn
ld a, $ff
ld [wPlayerAttackingCardIndex], a
ld [wPlayerAttackingMoveIndex], a
@@ -1967,7 +1967,7 @@ ChooseInitialArenaAndBenchPokemon: ; 4cd5 (1:4cd5)
; AI opponent's turn
push af
push hl
- call Func_2bc3
+ call AIDoAction_StartDuel
pop hl
pop af
ld [hl], a
@@ -3757,7 +3757,7 @@ Func_5805: ; 5805 (1:5805)
call GetTurnDuelistVariable
cp DUELIST_TYPE_LINK_OPP
jr z, .link_opponent
- call Func_2bd7
+ call AIDoAction_TakePrize
ld c, DECK_SIZE
.asm_5858
call DoFrame
@@ -7492,7 +7492,7 @@ ReplaceKnockedOutPokemon: ; 6f23 (1:6f23)
.opponent
cp DUELIST_TYPE_LINK_OPP
jr z, .link_opponent
- call Func_2bcf
+ call AIDoAction_KOSwitch
ldh a, [hTemp_ffa0]
ldh [hTempPlayAreaLocation_ff9d], a
jr .replace_pokemon
diff --git a/src/engine/deck_ai/deck_ai.asm b/src/engine/deck_ai/deck_ai.asm
index a906472..c8b73f3 100644
--- a/src/engine/deck_ai/deck_ai.asm
+++ b/src/engine/deck_ai/deck_ai.asm
@@ -33,6 +33,7 @@ ENDM
; deck AIs are specialized to work on a given deck ID.
; they decide what happens during a turn, what Pokemon cards
; to pick during the start of the duel, etc.
+; the different scenarios these are used are listed in AIACTION_* constants.
; each of these have a pointer table with the following structure:
; dw .do_turn : never called;
;
diff --git a/src/engine/effect_functions.asm b/src/engine/effect_functions.asm
index 762e82d..75b0f76 100644
--- a/src/engine/effect_functions.asm
+++ b/src/engine/effect_functions.asm
@@ -437,7 +437,7 @@ DuelistSelectForcedSwitch: ; 2c487 (b:4487)
; AI opponent
call SwapTurn
- bank1call Func_2bc7
+ bank1call AIDoAction_ForcedSwitch
call SwapTurn
ld a, [wPlayerAttackingMoveIndex]
diff --git a/src/engine/home.asm b/src/engine/home.asm
index c56e0c6..a9d28d6 100644
--- a/src/engine/home.asm
+++ b/src/engine/home.asm
@@ -8280,37 +8280,41 @@ LoadOpponentDeck: ; 2b78 (0:2b78)
ld [hl], a
ret
-Func_2bbf: ; 2bbf (0:2bbf)
- ld a, $1
- jr Func_2bdb
+AIDoAction_Turn: ; 2bbf (0:2bbf)
+ ld a, AIACTION_DO_TURN
+ jr AIDoAction
-Func_2bc3: ; 2bc3 (0:2bc3)
- ld a, $2
- jr Func_2bdb
+AIDoAction_StartDuel: ; 2bc3 (0:2bc3)
+ ld a, AIACTION_START_DUEL
+ jr AIDoAction
-Func_2bc7: ; 2bc7 (0:2bc7)
- ld a, $3
- call Func_2bdb
+AIDoAction_ForcedSwitch: ; 2bc7 (0:2bc7)
+ ld a, AIACTION_FORCED_SWITCH
+ call AIDoAction
ldh [hTempPlayAreaLocation_ff9d], a
ret
-Func_2bcf: ; 2bcf (0:2bcf)
- ld a, $4
- call Func_2bdb
+AIDoAction_KOSwitch: ; 2bcf (0:2bcf)
+ ld a, AIACTION_KO_SWITCH
+ call AIDoAction
ldh [hTemp_ffa0], a
ret
-Func_2bd7: ; 2bd7 (0:2bd7)
- ld a, $5
- jr Func_2bdb ; this line is not needed
+AIDoAction_TakePrize: ; 2bd7 (0:2bd7)
+ ld a, AIACTION_TAKE_PRIZE
+ jr AIDoAction ; this line is not needed
-Func_2bdb: ; 2bdb (0:2bdb)
+; calls the appropriate AI routine to handle action,
+; depending on the deck ID (see engine/deck_ai/deck_ai.asm)
+; input:
+; - a = AIACTION_* constant
+AIDoAction: ; 2bdb (0:2bdb)
ld c, a
; load bank for Opponent Deck pointer table
ldh a, [hBankROM]
push af
- ld a, BANK(PointerTable_14000)
+ ld a, BANK(DeckAIPointerTable)
call BankswitchROM
; load hl with the corresponding pointer
@@ -8318,7 +8322,7 @@ Func_2bdb: ; 2bdb (0:2bdb)
ld l, a
ld h, $0
add hl, hl ; two bytes per deck
- ld de, PointerTable_14000
+ ld de, DeckAIPointerTable
add hl, de
ld a, [hli]
ld h, [hl]