summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorElectroDeoxys <ElectroDeoxys@gmail.com>2019-09-16 19:47:04 +0100
committerElectroDeoxys <ElectroDeoxys@gmail.com>2019-09-16 19:47:04 +0100
commitc1d4866ff3b74f8290689adf798ef512711c2247 (patch)
treeaea2dc6ce59312530778b8a226d35895cf4d3340 /src
parentae822f8889f486835c7194eead6f3ba0ce7e1da2 (diff)
Work on AI Super Potion routines
Diffstat (limited to 'src')
-rw-r--r--src/engine/bank08.asm89
-rw-r--r--src/wram.asm4
2 files changed, 89 insertions, 4 deletions
diff --git a/src/engine/bank08.asm b/src/engine/bank08.asm
index 3e34714..461ada6 100644
--- a/src/engine/bank08.asm
+++ b/src/engine/bank08.asm
@@ -8,7 +8,7 @@ ENDM
Data_20000: ; 20000 (8:4000)
unknown_data_20000 $07, POTION, CheckIfPotionPreventsKnockOut, AIPlayPotion
unknown_data_20000 $0a, POTION, FindTargetCardForPotion, AIPlayPotion
- unknown_data_20000 $08, SUPER_POTION, $42cc, $42a8
+ unknown_data_20000 $08, SUPER_POTION, CheckIfSuperPotionPreventsKnockOut, $42a8
unknown_data_20000 $0b, SUPER_POTION, $430f, $42a8
unknown_data_20000 $0d, DEFENDER, $4406, $43f8
unknown_data_20000 $0e, DEFENDER, $4486, $43f8
@@ -176,7 +176,7 @@ Func_200e5: ; 200e5 (8:40e5)
jp .loop_hand
; 0x201b5
-; makes AI use potion card.
+; makes AI use Potion card.
AIPlayPotion: ; 201b5 (8:41b5)
ld a, [wce16]
ldh [hTempCardIndex_ff9f], a
@@ -366,8 +366,89 @@ CheckIfEitherAttackHaveBoostIfTakenDamageEffect: ; 2027e (8:427e)
ret
; 0x202a8
-Func_202a8: ; 202a8 (8:42a8)
- INCROM $202a8, $2297b
+; makes AI use Super Potion card.
+AIPlaySuperPotion: ; 202a8 (8:42a8)
+ ld a, [wce16]
+ ldh [hTempCardIndex_ff9f], a
+ ld a, [wce19]
+ ldh [hTempPlayAreaLocation_ffa1], a
+ call Func_2282e
+ ldh [hTemp_ffa0], a
+ ld a, [wce19]
+ ld e, a
+ call GetCardDamage
+ cp 40
+ jr c, .play_card
+ ld a, 40
+.play_card
+ ldh [hTempRetreatCostCards], a
+ ld a, OPPACTION_EXECUTE_TRAINER_EFFECTS
+ bank1call AIMakeDecision
+ ret
+; 0x202cc
+
+; if AI doesn't decide to retreat this card and card has
+; any energy cards attached, check if defending Pokémon can KO
+; active card next turn after using Super Potion.
+; if it cannot, return carry.
+; also take into account whether move is high recoil.
+CheckIfSuperPotionPreventsKnockOut: ; 202cc (8:42cc)
+ farcall AIDecideWhetherToRetreat
+ jr c, .no_carry
+ call Func_22bad
+ jr c, .no_carry
+ xor a
+ ldh [hTempPlayAreaLocation_ff9d], a
+ ld e, a
+ call CheckIfHasAttachedEnergy
+ ret nc
+ farcall CheckIfDefendingPokemonCanKnockOut
+ jr nc, .no_carry
+
+ ld d, a
+ ld d, a
+ ld a, DUELVARS_ARENA_CARD_HP
+ call GetTurnDuelistVariable
+ ld h, a
+ ld e, $00
+ call GetCardDamage
+ cp 40 + 1 ; if damage >= 40
+ jr c, .calculate_hp
+ ld a, 40
+.calculate_hp
+ ld l, a
+ ld a, h
+ add l
+ sub d
+ jr c, .no_carry
+ jr z, .no_carry
+
+; return carry
+ ld a, e
+ scf
+ ret
+.no_carry
+ or a
+ ret
+; 0x20305
+
+; returns carry if card has energies attached.
+; input:
+; e = location to check, i.e. PLAY_AREA_*
+CheckIfHasAttachedEnergy: ; 20305 (8:4305)
+ call GetPlayAreaCardAttachedEnergies
+ ld a, [wTotalAttachedEnergies]
+ or a
+ ret z
+ scf
+ ret
+; 0x2030f
+
+Func_2030f: ; 2030f (8:430f)
+ INCROM $2030f, $2282e
+
+Func_2282e: ; 2282e (8:630f)
+ INCROM $2282e, $2297b
; copies $ff terminated buffer from hl to de
CopyBuffer: ; 2297b (8:697b)
diff --git a/src/wram.asm b/src/wram.asm
index 7015d96..42e008d 100644
--- a/src/wram.asm
+++ b/src/wram.asm
@@ -1227,6 +1227,8 @@ wTempCardType:: ; cdba
wAIScore:: ; cdbe
ds $1
+; used for AI decisions that involve
+; each card in the Play Area.
wPlayAreaAIScore:: ; cdbf
ds MAX_PLAY_AREA_POKEMON
@@ -1282,6 +1284,8 @@ wcddb:: ; cddb
wcddc:: ; cddc
ds $1
+; used to compliment wPlayAreaAIScore,
+; to temporarily do calculations and store results.
wTempPlayAreaAIScore:: ; cddd
ds MAX_PLAY_AREA_POKEMON