Disassemble special-AI-attacks handlers

the same structure as TCG1
This commit is contained in:
earthoul 2026-02-22 01:47:04 +09:00
parent 50b3bdb218
commit e445434834
No known key found for this signature in database
GPG Key ID: 9049439C902677E4
7 changed files with 1825 additions and 26 deletions

View File

@ -8584,7 +8584,7 @@ GetAIScoreOfAttack:
jp .asm_17969
.asm_17532
xor a
ld [wd05f], a
ld [wAICannotDamage], a
ld a, DUELVARS_ARENA_CARD
get_turn_duelist_var
call GetCardIDFromDeckIndex
@ -8604,7 +8604,7 @@ GetAIScoreOfAttack:
call SwapTurn
jr nc, .asm_17581
ld a, $01
ld [wd05f], a
ld [wAICannotDamage], a
ld a, [wSelectedAttack]
call EstimateDamage_VersusDefendingCard
ld a, $12

View File

@ -1319,7 +1319,7 @@ AISelectSpecialAttackParameters:
ld a, [wSelectedAttack]
or a
jp nz, .no_carry
farcall Func_4acba
farcall IsPlayerArenaCardImmune
ld a, PLAY_AREA_BENCH_1
jr c, .asm_287e8
xor a ; PLAY_AREA_ARENA
@ -1567,7 +1567,7 @@ AISelectSpecialAttackParameters:
ld a, $ff ; terminating byte
ld [hli], a
push hl
farcall Func_4acba
farcall IsPlayerArenaCardImmune
pop hl
jr c, .defending_is_invulnerable_to_rock_blast
; choose all of them on the Defending card
@ -1805,7 +1805,7 @@ AISelectSpecialAttackParameters:
ld a, [wSelectedAttack]
or a
jp z, .no_carry
farcall Func_4c237
farcall IsPlayerArenaCardImmuneAndNoBenchedPokemon
jp c, .no_carry
farcall AILookForFocusBlastTargetToKO
jr c, .got_focus_blast_target
@ -1871,7 +1871,7 @@ AIChooseRagingThunderTarget:
ret
AILookForShortCircuitTargetToKO:
farcall Func_4acba
farcall IsPlayerArenaCardImmune
jr nc, .include_arena
; exclude Arena
call SwapTurn
@ -1946,7 +1946,7 @@ AIChooseShortCircuitTarget:
xor a
ld [wd06a], a
ld [wd06b], a
farcall Func_4acba
farcall IsPlayerArenaCardImmune
jr nc, .include_arena
; exclude Arena
call SwapTurn
@ -2380,12 +2380,12 @@ CheckIfAnyBasicPokemonInDeck:
; a = card location of Pokémon card, if found;
; carry set if such a card is found.
LookForCardThatIsKnockedOutOnDevolution:
farcall Func_4c237
farcall IsPlayerArenaCardImmuneAndNoBenchedPokemon
ccf
ret nc
ldh a, [hTempPlayAreaLocation_ff9d]
push af
farcall Func_4acba
farcall IsPlayerArenaCardImmune
jr nc, .start_with_arena_card
; skip arena card
@ -2444,10 +2444,8 @@ LookForCardThatIsKnockedOutOnDevolution:
ld a, c
scf
ret
; 0x28dff
; HandleSpecialAIAttacks
SECTION "Bank a@58f9", ROMX[$58f9], BANK[$a]
INCLUDE "engine/duel/special_attacks.asm"
; loops through wDuelTempList and
; returns carry if a card is found that evolves

View File

@ -4337,7 +4337,55 @@ Func_3a887:
ret
; 0x3a8b5
SECTION "Bank e@6994", ROMX[$6994], BANK[$e]
SECTION "Bank e@6928", ROMX[$6928], BANK[$e]
; return a = b = number of Weezing family in own play area,
; set carry if KOing enough amount of Pokémon for player to win
; (c = (number of prizes for player to take) + 1)
AICountMassExplosion:
lb bc, 0, 1
ld a, DUELVARS_ARENA_CARD
get_turn_duelist_var
push hl
.loop_play_area
pop hl
ld a, [hli]
cp $ff
jr z, .check_prizes
push hl
ld [wTempAI], a
push bc
call GetCardIDFromDeckIndex
pop bc
cp16 KOFFING_LV12
jr z, .check_remaining_hp
cp16 KOFFING_LV13
jr z, .check_remaining_hp
cp16 KOFFING_LV14
jr z, .check_remaining_hp
cp16 WEEZING_LV26
jr z, .check_remaining_hp
cp16 WEEZING_LV27
jr z, .check_remaining_hp
cp16 DARK_WEEZING
jr nz, .loop_play_area
.check_remaining_hp
inc b
ld a, [wTempAI]
add DUELVARS_ARENA_CARD_HP
get_turn_duelist_var
cp 30
jr nc, .loop_play_area
inc c
jr .loop_play_area
.check_prizes
call SwapTurn
call CountPrizes
call SwapTurn
cp c
ld a, b
ret
AIChooseStareTarget:
bank1call CheckGoopGasAttackAndToxicGasActive

View File

@ -3562,7 +3562,53 @@ CheckIfHasSpecificEnergyAttached:
ret
; 0x4a005
SECTION "Bank 12@62a0", ROMX[$62a0], BANK[$12]
SECTION "Bank 12@625d", ROMX[$625d], BANK[$12]
; 128 + 10 if
; not KOing with Psyshock,
; Abra in KO range, and
; 2+ of Kadabra, Alakazam, Mr. Mime, or Scyther on his Bench;
; 128 - 28 otherwise
AIMagicianHandleVanish:
farcall CheckIfArenaCardCanKnockOutDefendingCard
jr nc, .check_abra
.discourage
ld a, 100
ret
.check_abra
farcall CheckIfDefendingPokemonCanKnockOut
jr nc, .discourage
; tally bench
ld de, KADABRA_LV39
ld b, PLAY_AREA_BENCH_1
farcall CountCardIDInTurnDuelistPlayArea
push af
ld de, ALAKAZAM_LV42
ld b, PLAY_AREA_BENCH_1
farcall CountCardIDInTurnDuelistPlayArea
pop bc
add b
push af
ld de, MR_MIME_LV28
ld b, PLAY_AREA_BENCH_1
farcall CountCardIDInTurnDuelistPlayArea
pop bc
add b
push af
ld de, SCYTHER_LV25
ld b, PLAY_AREA_ARENA
farcall CountCardIDInTurnDuelistPlayArea
pop bc
add b
cp 2
jr c, .discourage
; encourage
ld a, 138
ret
; returns carry if Alakazam lv42 is found in Play Area
; with Pkmn Power active and outputs its Play Area location
@ -3833,7 +3879,48 @@ Func_4a3dc:
pop bc
ld a, d ; output chosen card location
ret
; 0x4a441
; de = card ID
; return a = number of cards in hand with that card ID
; set carry if not found
CountCardIDInHand:
push de
call CreateHandCardList
pop de
ld b, 0
ld hl, wDuelTempList
.loop_hand_cards
ld a, [hli]
cp $ff
jr z, .tally
push de
push bc
push hl
call GetCardIDFromDeckIndex
pop hl
pop bc
ld c, d
ld a, e
pop de
cp e
jr nz, .loop_hand_cards
ld a, c
cp d
jr nz, .loop_hand_cards
inc b
jr .loop_hand_cards
.tally
ld a, b
or a
jr z, .not_found
ret
.not_found
scf
ret
; 0x4a46c
SECTION "Bank 12@64ae", ROMX[$64ae], BANK[$12]
@ -3867,7 +3954,9 @@ CountNumberOfBasicPokemonInHand:
SECTION "Bank 12@6cba", ROMX[$6cba], BANK[$12]
Func_4acba:
; return carry if the defending (player's arena) card is under
; no-damage-or-effect substatus
IsPlayerArenaCardImmune:
ld a, DUELVARS_ARENA_CARD
get_turn_duelist_var
call GetCardIDFromDeckIndex
@ -3890,6 +3979,38 @@ Func_4acba:
ret
; 0x4ace4
SECTION "Bank 12@6f01", ROMX[$6f01], BANK[$12]
CountNonDrawEngineCardsInHand:
ld a, DUELVARS_NUMBER_OF_CARDS_IN_HAND
get_turn_duelist_var
push af
ld de, PROFESSOR_OAK
call CountCardIDInHand
ld b, a
pop af
sub b
push af
ld de, BILL
call CountCardIDInHand
ld b, a
pop af
sub b
push af
ld de, BILLS_TELEPORTER
call CountCardIDInHand
ld b, a
pop af
sub b
push af
ld de, POKEMON_TRADER
call CountCardIDInHand
ld b, a
pop af
sub b
ret
; 0x4af2d
SECTION "Bank 12@7029", ROMX[$7029], BANK[$12]
AIDecideFirefoxTarget:
@ -4297,6 +4418,55 @@ CheckIfHasDittoWithLessThan3Energies:
ret
; 0x4bae4
SECTION "Bank 12@7cdf", ROMX[$7cdf], BANK[$12]
; e = location (PLAY_AREA_*)
; return a = number of energy cards attached, except for Recycle Energy
CountNumberOfNonRecycleEnergyCardsAttached:
push hl
push de
push bc
ld a, CARD_LOCATION_ARENA
or e
ld e, a
ldh a, [hWhoseTurn]
ld h, a
ld l, 0
ld d, 0
.loop_deck_cards
ld a, [hl]
cp e
jr nz, .next_card
push hl
push de
ld a, l
call GetCardIDFromDeckIndex
cp16 RECYCLE_ENERGY
jr z, .next_card_pop
call GetCardType
bit TYPE_ENERGY_F, a
jr z, .next_card_pop
; found at the target area
pop de
inc d
pop hl
jr .next_card
.next_card_pop
pop de
pop hl
.next_card
inc l
ld a, l
cp DECK_SIZE
jr nz, .loop_deck_cards
ld a, d
pop bc
pop de
pop hl
ret
; 0x4bd1a
SECTION "Bank 12@7d72", ROMX[$7d72], BANK[$12]
Func_4bd72:

View File

@ -1,5 +1,5 @@
FindBenchCardThatCanBeDamaged:
farcall Func_4acba
farcall IsPlayerArenaCardImmune
jr c, .find
xor a
farcall CheckIfCanDamageDefendingPokemon
@ -67,12 +67,13 @@ FindBenchCardThatCanBeDamaged:
SECTION "Bank 13@4237", ROMX[$4237], BANK[$13]
Func_4c237:
; return carry if thd defending (player's arena) card is immune, with no Benched Pokémon
IsPlayerArenaCardImmuneAndNoBenchedPokemon:
ld a, DUELVARS_NUMBER_OF_POKEMON_IN_PLAY_AREA
call GetNonTurnDuelistVariable
cp 1
jr nz, .no_carry
farcall Func_4acba
farcall IsPlayerArenaCardImmune
ret c
.no_carry
or a
@ -129,7 +130,7 @@ Func_4c25c:
ret
.potion_energy
call .CountBasicEnergyCardsInHand
call CountBasicEnergyCardsInHand
jr nc, .skip_card
ld de, POTION_ENERGY
farcall CheckIfHandHasRepeatedCard
@ -140,7 +141,7 @@ Func_4c25c:
ret
.full_heal_energy
call .CountBasicEnergyCardsInHand
call CountBasicEnergyCardsInHand
jr nc, .skip_card
ld de, FULLHEAL_ENERGY
farcall CheckIfHandHasRepeatedCard
@ -150,7 +151,7 @@ Func_4c25c:
ld a, 0
ret
.CountBasicEnergyCardsInHand:
CountBasicEnergyCardsInHand:
bank1call CreateEnergyCardListFromHand
ld a, 0
ret c ; no energy cards
@ -332,9 +333,22 @@ CheckIfArenaCardIsWeakToDefendingCard:
.set_carry
scf
ret
; 0x4c3df
SECTION "Bank 13@43f7", ROMX[$43f7], BANK[$13]
CheckIfArenaCardIsResistantToDefendingCard:
call SwapTurn
bank1call GetArenaCardColor
call SwapTurn
call TranslateColorToWR
push af
bank1call GetArenaCardResistance
pop bc
cp b
jr z, .set_carry
or a
ret
.set_carry
scf
ret
CheckIfDefendingCardIsWeakToArenaCard:
bank1call GetArenaCardColor
@ -440,7 +454,7 @@ Func_4c56b:
cp16 SANDSLASH_LV33
jr z, .hitmonchan_or_sandslash
.asm_4c599
farcall Func_4acba
farcall IsPlayerArenaCardImmune
ret nc
ld a, $ff
scf

File diff suppressed because it is too large Load Diff

View File

@ -1624,7 +1624,9 @@ wPlayAreaEnergyAIScore:: ; d053
wSamePokemonEnergyScore:: ; d059
ds MAX_PLAY_AREA_POKEMON
wd05f:: ; d05f
; TRUE: can't inflict damage on player's active Pokémon due to No Damage or Effect substatus
; FALSE: can inflict damage
wAICannotDamage:: ; d05f
ds $1
; used by AI to store variable information