diff options
author | ElectroDeoxys <ElectroDeoxys@gmail.com> | 2020-04-29 20:42:00 +0100 |
---|---|---|
committer | ElectroDeoxys <ElectroDeoxys@gmail.com> | 2020-04-29 20:42:00 +0100 |
commit | 75678c46233e53c4508c811a80923216b36c61bb (patch) | |
tree | 66b3a1ad97447138d526c92f5f409cce3ff8c2ab /src | |
parent | ed0543d3d31c879a5f331c23384971f7d316b93e (diff) |
AI init duel and turn logic
Diffstat (limited to 'src')
-rw-r--r-- | src/engine/bank01.asm | 10 | ||||
-rw-r--r-- | src/engine/bank05.asm | 122 | ||||
-rw-r--r-- | src/engine/bank08.asm | 12 | ||||
-rw-r--r-- | src/wram.asm | 11 |
4 files changed, 114 insertions, 41 deletions
diff --git a/src/engine/bank01.asm b/src/engine/bank01.asm index 7668903..7eb7340 100644 --- a/src/engine/bank01.asm +++ b/src/engine/bank01.asm @@ -3720,7 +3720,7 @@ Func_57df: ; 57df (1:57df) Func_5805: ; 5805 (1:5805) call Func_3b31 - ld a, [wccc8] + ld a, [wNumberPrizeCardsToTake] ld l, a ld h, $00 call LoadTxRam3 @@ -3731,7 +3731,7 @@ Func_5805: ; 5805 (1:5805) ldtx hl, WillDrawNPrizesText call DrawWideTextBox_WaitForInput - ld a, [wccc8] + ld a, [wNumberPrizeCardsToTake] call Func_310a ld hl, hTemp_ffa0 ld d, [hl] @@ -3775,7 +3775,7 @@ Func_5805: ; 5805 (1:5805) call nz, AddCardToHand .asm_586f ld a, [wcbfc] - ld hl, wccc8 + ld hl, wNumberPrizeCardsToTake cp [hl] jr nc, .asm_587e ld l, a @@ -7525,7 +7525,7 @@ Func_6fa5: ; 6fa5 (1:6fa5) ret ; 0x6fc7 -; return in wccc8 the amount of Pokemon in the turn holder's +; return in wNumberPrizeCardsToTake the amount of Pokemon in the turn holder's ; play area that are still there despite having 0 HP. ; that is, the number of Pokemon that have just been knocked out. ; Clefairy Doll and Mysterious Fossil don't count. @@ -7558,7 +7558,7 @@ CountKnockedOutPokemon: ; 6fc7 (1:6fc7) dec c jr nz, .loop ld a, b - ld [wccc8], a + ld [wNumberPrizeCardsToTake], a or a ret z scf diff --git a/src/engine/bank05.asm b/src/engine/bank05.asm index d6a99b9..d8a0a31 100644 --- a/src/engine/bank05.asm +++ b/src/engine/bank05.asm @@ -333,24 +333,90 @@ CheckIfEnergyIsUseful: ; 14184 (5:4184) ; 0x141da Func_141da: ; 141da (5:41da) - INCROM $141da, $14226 + INCROM $141da, $141e5 -Func_14226: ; 14226 (5:4226) +_AIPickPrizeCards: ; 141e5 (5:41e5) + ld a, [wNumberPrizeCardsToTake] + ld b, a +.loop + call .PickPrizeCard + ld a, DUELVARS_PRIZES + call GetTurnDuelistVariable + or a + jr z, .done + dec b + jr nz, .loop +.done + ret +; 0x141f8 + +; picks a prize card at random +; and adds it to the hand. +.PickPrizeCard: ; 141f8 (5:41f8) + ld a, DUELVARS_PRIZES + call GetTurnDuelistVariable + push hl + ld c, a + +; choose a random prize card until +; one is found that isn't taken already. +.loop_pick_prize + ld a, 6 + call Random + ld e, a + ld d, $00 + ld hl, .prize_flags + add hl, de + ld a, [hl] + and c + jr z, .loop_pick_prize ; no prize + +; prize card was found +; remove this prize from wOpponentPrizes + ld a, [hl] + pop hl + cpl + and [hl] + ld [hl], a + +; add this prize card to the hand + ld a, e + add DUELVARS_PRIZE_CARDS + call GetTurnDuelistVariable + call AddCardToHand + ret + +.prize_flags ; 1421e (5:421e) + db $1 << 0 + db $1 << 1 + db $1 << 2 + db $1 << 3 + db $1 << 4 + db $1 << 5 + db $1 << 6 + db $1 << 7 +; 0x14226 + +; routine for AI to play all Basic cards from its hand +; in the beginning of the Duel. +AIPlayInitialBasicCards: ; 14226 (5:4226) call CreateHandCardList ld hl, wDuelTempList .check_for_next_card ld a, [hli] ldh [hTempCardIndex_ff98], a cp $ff - ret z + ret z ; return when done call LoadCardDataToBuffer1_FromDeckIndex ld a, [wLoadedCard1Type] cp TYPE_ENERGY - jr nc, .check_for_next_card + jr nc, .check_for_next_card ; skip if not Pokemon card ld a, [wLoadedCard1Stage] or a - jr nz, .check_for_next_card + jr nz, .check_for_next_card ; skip if not Basic Stage + +; play Basic card from hand push hl ldh a, [hTempCardIndex_ff98] call PutHandPokemonCardInPlayArea @@ -1178,24 +1244,23 @@ AIProcessHandTrainerCards: ; 14663 (5:4663) ; GENERAL DECK POINTER LIST - Not sure on all of these. ; This is an example of an AI pointer table, there's one for each AI type. PointerTable_14668: ; 14668 (05:4668) - dw Func_14674 ; not used - dw Func_14674 ; general AI for battles - dw Func_14678 ; basic pokemon placement / cheater shuffling on better AI - dw Func_1467f ; deciding which Bench Pokemon to switch to + dw AIMainTurnLogic ; not used + dw AIMainTurnLogic ; general AI for battles + dw AIDuelStart ; basic pokemon placement / cheater shuffling on better AI + dw AIRetreatLogic ; deciding which Bench Pokemon to switch to dw Func_14683 - dw Func_14687 + dw AIPickPrizeCards -; when battle AI gets called -Func_14674: ; 14674 (5:4674) - call Func_1468b +AIMainTurnLogic: ; 14674 (5:4674) + call _AIMainTurnLogic ret -Func_14678: ; 14678 (5:4678) - call Func_15636 - call $4226 +AIDuelStart: ; 14678 (5:4678) + call InitAIDuelVars + call AIPlayInitialBasicCards ret -Func_1467f: ; 1467f (5:467f) +AIRetreatLogic: ; 1467f (5:467f) call AIDecideBenchPokemonToSwitchTo ret @@ -1203,13 +1268,13 @@ Func_14683: ; 14683 (5:4683) call AIDecideBenchPokemonToSwitchTo ret -Func_14687: ; 14687 (5:4687) - call $41e5 +AIPickPrizeCards: ; 14687 (5:4687) + call _AIPickPrizeCards ret -; AI for general decks i think -Func_1468b: ; 1468b (5:468b) - call Func_15649 +; handle AI routines for a whole turn +_AIMainTurnLogic: ; 1468b (5:468b) + call InitAITurnVars ld a, AI_TRAINER_CARD_PHASE_01 call AIProcessHandTrainerCards @@ -1532,22 +1597,23 @@ LookForCardIDInPlayArea_Bank5: ; 155ef (5:55ef) Func_15612: ; 15612 (5:5612) INCROM $15612, $15636 -Func_15636: ; 15636 (5:5636) +InitAIDuelVars: ; 15636 (5:5636) ld a, $10 ld hl, wcda5 call ClearMemory_Bank5 - ld a, $5 - ld [wcda6], a + ld a, 5 + ld [wAIPokedexCounter], a ld a, $ff ld [wcda5], a ret ; initializes some variables and ; sets value of wcda7. -Func_15649: ; 15649 (5:5649) - ld a, [wcda6] +InitAITurnVars: ; 15649 (5:5649) +; increase Pokedex counter by one + ld a, [wAIPokedexCounter] inc a - ld [wcda6], a + ld [wAIPokedexCounter], a xor a ld [wPreviousAIFlags], a diff --git a/src/engine/bank08.asm b/src/engine/bank08.asm index 1113dc9..1c6f82a 100644 --- a/src/engine/bank08.asm +++ b/src/engine/bank08.asm @@ -3589,9 +3589,9 @@ AIPlay_Pokedex: ; 212b4 (8:52b4) ; 0x212dc AIDecide_Pokedex: ; 212dc (8:52dc) - ld a, [wcda6] - cp $06 - jr c, .no_carry + ld a, [wAIPokedexCounter] + cp 5 + 1 + jr c, .no_carry ; return if counter hasn't reached 6 yet ; return no carry if number of cards in deck <= 4 ld a, DUELVARS_NUMBER_OF_CARDS_NOT_IN_DECK @@ -3624,7 +3624,7 @@ AIDecide_Pokedex: ; 212dc (8:52dc) PickPokedexCards_Unreferenced: ; 212ff (8:52ff) ; unreferenced xor a - ld [wcda6], a + ld [wAIPokedexCounter], a ; reset counter ld a, DUELVARS_NUMBER_OF_CARDS_NOT_IN_DECK call GetTurnDuelistVariable @@ -3756,7 +3756,7 @@ PickPokedexCards_Unreferenced: ; 212ff (8:52ff) ; stores the resulting order in wce1a. PickPokedexCards: ; 2138e (8:538e) xor a - ld [wcda6], a + ld [wAIPokedexCounter], a ; reset counter ; reset counter ld a, DUELVARS_NUMBER_OF_CARDS_NOT_IN_DECK call GetTurnDuelistVariable @@ -6949,7 +6949,7 @@ HandleAIPeek: ; 224e6 (8:64e6) and [hl] ld [hl], a or a - ret z ; return if no prizes (should never happen) + ret z ; return if no prizes ld c, a ld b, $1 diff --git a/src/wram.asm b/src/wram.asm index cb97ddc..534297e 100644 --- a/src/wram.asm +++ b/src/wram.asm @@ -967,7 +967,7 @@ wNoDamageOrEffect:: ; ccc7 ; used by CountKnockedOutPokemon and Func_5805 to store the amount ; of prizes to take (equal to the number of Pokemon knocked out) -wccc8:: ; ccc8 +wNumberPrizeCardsToTake:: ; ccc8 ds $1 ; set to 1 if the coin toss in the confusion check is heads (CheckSelfConfusionDamage) @@ -1182,7 +1182,14 @@ wcd9f:: ; cd9f wcda5:: ; cda5 ds $1 -wcda6:: ; cda6 +; this is used by AI in order to determine whether +; it should use Pokedex Trainer card. +; duel starts at 5 and counts up by one every turn. +; only when it's higher than 5 is AI allowed to use Pokedex, +; in which case it set the counter to 0. +; this stops the AI from using Pokedex right after using another one +; while still drawing cards that were ordered. +wAIPokedexCounter:: ; cda6 ds $1 wcda7:: ; cda7 |