summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorxCrystal <rgr.crystal@gmail.com>2019-07-23 21:03:39 +0200
committerxCrystal <rgr.crystal@gmail.com>2019-07-23 21:03:39 +0200
commitb7ee18f262b1d88582fdc55879f1abaad17cc5ce (patch)
treeb3ccca487812143478c8369fa810abe00ef3efef /src
parent0d2dce27ff7ad77a12f5182bbb8618d871446aa4 (diff)
Disassemble and document code related to knocking out Pokemon and taking prizes
Diffstat (limited to 'src')
-rw-r--r--src/engine/bank01.asm310
-rw-r--r--src/engine/home.asm4
-rw-r--r--src/text/text1.asm10
-rw-r--r--src/text/text2.asm4
-rw-r--r--src/text/text_offsets.asm14
-rw-r--r--src/wram.asm9
6 files changed, 316 insertions, 35 deletions
diff --git a/src/engine/bank01.asm b/src/engine/bank01.asm
index 6058fcd..433b120 100644
--- a/src/engine/bank01.asm
+++ b/src/engine/bank01.asm
@@ -852,7 +852,7 @@ CheckAbleToRetreat: ; 45bb (1:45bb)
ret c
call CheckIfActiveCardParalyzedOrAsleep
ret c
- call HasAlivePokemonOnBench
+ call HasAlivePokemonInBench
jr c, .unable_to_retreat
ld a, DUELVARS_ARENA_CARD
call GetTurnDuelistVariable
@@ -2794,7 +2794,7 @@ PracticeDuel_ReplaceKnockedOutPokemon: ; 52b0 (1:52b0)
cp PLAY_AREA_BENCH_1
ret z
; if player selected Drowzee instead (which is at PLAY_AREA_BENCH_2)
- call HasAlivePokemonOnBench
+ call HasAlivePokemonInBench
ldtx hl, SelectStaryuPracticeDuelText
scf
; fallthrough
@@ -3700,8 +3700,100 @@ DisplayCardPageOnLeftOrRightPressed: ; 57cd (1:57cd)
ret
; 0x57df
-Func_57df:
- INCROM $57df, $5892
+Func_57df: ; 57df (1:57df)
+ push hl
+ call EmptyScreen
+ lb de, 0, 0
+ lb bc, 20, 18
+ call DrawRegularTextBox
+ ld a, 19
+ lb de, 1, 1
+ call InitTextPrintingInTextbox
+ call SetNoLineSeparation
+ pop hl
+ call ProcessTextFromID
+ call EnableLCD
+ call SetOneLineSeparation
+ call WaitForWideTextBoxInput
+ ret
+; 0x5805
+
+Func_5805: ; 5805 (1:5805)
+ call Func_3b31
+ ld a, [wccc8]
+ ld l, a
+ ld h, $00
+ call LoadTxRam3
+ ld a, DUELVARS_DUELIST_TYPE
+ call GetTurnDuelistVariable
+ cp DUELIST_TYPE_PLAYER
+ jr nz, .opponent
+
+ ldtx hl, WillDrawNPrizesText
+ call DrawWideTextBox_WaitForInput
+ ld a, [wccc8]
+ call Func_310a
+ ld hl, hTemp_ffa0
+ ld d, [hl]
+ inc hl
+ ld e, [hl]
+ call SerialSend8Bytes
+.asm_582f
+ call ExchangeRNG
+ ld a, DUELVARS_PRIZES
+ call GetTurnDuelistVariable
+ or a
+ ret nz
+ scf
+ ret
+
+.opponent
+ call Func_588a
+ ldtx hl, WillDrawNPrizesText
+ call DrawWideTextBox_PrintText
+ call CountPrizes
+ ld [wcbfc], a
+ ld a, DUELVARS_DUELIST_TYPE
+ call GetTurnDuelistVariable
+ cp DUELIST_TYPE_LINK_OPP
+ jr z, .link_opponent
+ call Func_2bd7
+ ld c, DECK_SIZE
+.asm_5858
+ call DoFrame
+ dec c
+ jr nz, .asm_5858
+ jr .asm_586f
+
+.link_opponent
+ call SerialRecv8Bytes
+ ld a, DUELVARS_PRIZES
+ call GetTurnDuelistVariable
+ ld [hl], d
+ ld a, e
+ cp $ff
+ call nz, AddCardToHand
+.asm_586f
+ ld a, [wcbfc]
+ ld hl, wccc8
+ cp [hl]
+ jr nc, .asm_587e
+ ld l, a
+ ld h, $00
+ call LoadTxRam3
+.asm_587e
+ farcall Func_82b6
+ ldtx hl, DrewNPrizesText
+ call DrawWideTextBox_WaitForInput
+ jr .asm_582f
+; 0x588a
+
+Func_588a: ; 588a (1:588a)
+ ld l, PLAYER_TURN
+ ldh a, [hWhoseTurn]
+ ld h, a
+ jp DrawYourOrOppPlayAreaScreen_Bank0
+; 0x5892
; display the previous valid card page
DisplayPreviousCardPage: ; 5892 (1:5892)
@@ -4985,7 +5077,7 @@ PrintPokemonCardLength: ; 5f9a (1:5f9a)
; return carry if the turn holder has any Pokemon with non-zero HP on the bench.
; return how many Pokemon with non-zero HP in b.
; does this by calculating how many Pokemon in play area minus one
-HasAlivePokemonOnBench: ; 5fd9 (1:5fd9)
+HasAlivePokemonInBench: ; 5fd9 (1:5fd9)
ld a, $01
jr _HasAlivePokemonInPlayArea
@@ -5186,7 +5278,7 @@ Func_60dd: ; 60dd (1:60dd)
and SELECT
jr z, .asm_60f2
.asm_6119
- call HasAlivePokemonOnBench
+ call HasAlivePokemonInBench
ld a, $01
ld [wcbd4], a
.asm_6121
@@ -6698,7 +6790,7 @@ OppAction_ForceSwitchActive: ; 6aba (1:6aba)
ldtx hl, SelectPkmnOnBenchToSwitchWithActiveText
call DrawWideTextBox_WaitForInput
call SwapTurn
- call HasAlivePokemonOnBench
+ call HasAlivePokemonInBench
ld a, $01
ld [wcbd4], a
.force_selection
@@ -7221,9 +7313,9 @@ Func_6e49: ; 6e49 (1:6e49)
ld a, [wcce8]
or a
jr z, .asm_6e86
- call $6ff7
+ call Func_6ff7
jr c, .asm_6e86
- call $6fc7
+ call CountKnockedOutPokemon
ld c, a
call SwapTurn
call CountPrizes
@@ -7233,7 +7325,7 @@ Func_6e49: ; 6e49 (1:6e49)
jr c, .asm_6e86
ld a, c
call SwapTurn
- call DrawPrizes
+ call TakeAPrizes
call SwapTurn
ld a, $01
jr .asm_6ecc
@@ -7243,25 +7335,25 @@ Func_6e49: ; 6e49 (1:6e49)
cp $01
jr nz, .asm_6e9f
call SwapTurn
- call $6ff7
+ call Func_6ff7
call SwapTurn
jr c, .asm_6e9f
ld a, $02
jr .asm_6ecc
.asm_6e9f
call SwapTurn
- call $6eff
+ call Func_6eff
call SwapTurn
- call $6eff
+ call Func_6eff
ld a, [wcce8]
or a
jr nz, .asm_6ec4
xor a
.asm_6eb2
push af
- call $6f08
+ call MoveAllTurnHolderKnockedOutPokemonToDiscardPile
call SwapTurn
- call $6f08
+ call MoveAllTurnHolderKnockedOutPokemonToDiscardPile
call SwapTurn
call ShiftAllPokemonToFirstPlayAreaSlots
pop af
@@ -7300,13 +7392,195 @@ ClearDamageReductionSubstatus2OfKnockedOutPokemon: ; 6ee2 (1:6ee2)
; 0x6ef6
Func_6ef6: ; 6ef6 (1:6ef6)
- call $6fa5
+ call Func_6fa5
ld hl, wcce8
rl [hl]
ret
; 0x6eff
- INCROM $6eff, $700a
+Func_6eff: ; 6eff (1:6eff)
+ call ReplaceKnockedOutPokemon
+ ld hl, wcce8
+ rl [hl]
+ ret
+; 0x6f08
+
+; for each Pokemon in the turn holder's play area (arena and bench),
+; move that card to the discard pile if its HP is 0
+MoveAllTurnHolderKnockedOutPokemonToDiscardPile: ; 6f08 (1:6f08)
+ ld a, DUELVARS_NUMBER_OF_POKEMON_IN_PLAY_AREA
+ call GetTurnDuelistVariable
+ ld d, a
+ ld l, DUELVARS_ARENA_CARD_HP
+ ld e, PLAY_AREA_ARENA
+.loop
+ ld a, [hl]
+ or a
+ jr nz, .next
+ push hl
+ push de
+ call MovePlayAreaCardToDiscardPile
+ pop de
+ pop hl
+.next
+ inc hl
+ inc e
+ dec d
+ jr nz, .loop
+ ret
+; 0x6f23
+
+; have the turn holder replace the arena Pokemon card when it's been knocked out.
+; if there are no Pokemon cards in the turn holder's bench, return carry.
+ReplaceKnockedOutPokemon: ; 6f23 (1:6f23)
+ ld a, DUELVARS_ARENA_CARD_HP
+ call GetTurnDuelistVariable
+ or a
+ ret nz
+ call ClearAllStatusConditions
+ call HasAlivePokemonInBench
+ jr nc, .can_replace_pokemon
+
+; if we made it here, the duelist can't replace the knocked out Pokemon
+ bank1call DrawDuelMainScene
+ ldtx hl, ThereAreNoPokemonInPlayAreaText
+ call DrawWideTextBox_WaitForInput
+ call ExchangeRNG
+ scf
+ ret
+
+.can_replace_pokemon
+ ld a, DUELVARS_DUELIST_TYPE
+ call GetTurnDuelistVariable
+ cp DUELIST_TYPE_PLAYER
+ jr nz, .opponent
+
+; prompt the player to replace the knocked out Pokemon with one from bench
+ bank1call DrawDuelMainScene
+ ldtx hl, SelectPokemonToPlaceInTheArenaText
+ call DrawWideTextBox_WaitForInput
+ ld a, $01
+ ld [wcbd4], a
+ ld a, PRACTICEDUEL_PLAY_STARYU_FROM_BENCH
+ call DoPracticeDuelAction
+.select_pokemon
+ call OpenPlayAreaScreenForSelection
+ jr c, .select_pokemon
+ ldh a, [hTempPlayAreaLocation_ff9d]
+ call SerialSend8Bytes
+
+; replace the arena Pokemon with the one at location [hTempPlayAreaLocation_ff9d]
+.replace_pokemon
+ call Func_3b31
+ ld a, PRACTICEDUEL_REPLACE_KNOCKED_OUT_POKEMON
+ call DoPracticeDuelAction
+ jr c, .select_pokemon
+ ldh a, [hTempPlayAreaLocation_ff9d]
+ ld d, a
+ ld e, PLAY_AREA_ARENA
+ call SwapPlayAreaPokemon
+ ld a, DUELVARS_ARENA_CARD
+ call GetTurnDuelistVariable
+ ldtx hl, DuelistPlacedACardText
+ bank1call DisplayCardDetailScreen
+ call ExchangeRNG
+ or a
+ ret
+
+; the AI opponent replaces the knocked out Pokemon with one from bench
+.opponent
+ cp DUELIST_TYPE_LINK_OPP
+ jr z, .link_opponent
+ call Func_2bcf
+ ldh a, [hTemp_ffa0]
+ ldh [hTempPlayAreaLocation_ff9d], a
+ jr .replace_pokemon
+
+; wait for link opponent to replace the knocked out Pokemon with one from bench
+.link_opponent
+ bank1call DrawDuelMainScene
+ ldtx hl, DuelistIsSelectingPokemonToPlaceInArenaText
+ call DrawWideTextBox_PrintText
+ call SerialRecv8Bytes
+ ldh [hTempPlayAreaLocation_ff9d], a
+ jr .replace_pokemon
+; 0x6fa5
+
+Func_6fa5: ; 6fa5 (1:6fa5)
+ call CountKnockedOutPokemon
+ ret nc
+ ; at least one Pokemon knocked out
+ call SwapTurn
+ bank1call Func_5805
+ call SwapTurn
+ ret nc
+ call SwapTurn
+ bank1call DrawDuelMainScene
+ ldtx hl, TookAllThePrizesText
+ call DrawWideTextBox_WaitForInput
+ call ExchangeRNG
+ call SwapTurn
+ scf
+ ret
+; 0x6fc7
+
+; return in wccc8 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.
+CountKnockedOutPokemon: ; 6fc7 (1:6fc7)
+ ld a, DUELVARS_ARENA_CARD_HP
+ call GetTurnDuelistVariable
+ ld d, h
+ ld e, DUELVARS_ARENA_CARD
+ ld b, PLAY_AREA_ARENA
+ ld c, MAX_PLAY_AREA_POKEMON
+.loop
+ ld a, [de]
+ cp -1
+ jr z, .next ; jump if no Pokemon in this location
+ ld a, [hl]
+ or a
+ jr nz, .next ; jump if this Pokemon's HP isn't 0
+ ; this Pokemon's HP has just become 0
+ ld a, [de]
+ push de
+ call GetCardIDFromDeckIndex
+ call GetCardType
+ pop de
+ cp TYPE_TRAINER
+ jr z, .next ; jump if this is a trainer card (Clefairy Doll or Mysterious Fossil)
+ inc b
+.next
+ inc hl
+ inc de
+ dec c
+ jr nz, .loop
+ ld a, b
+ ld [wccc8], a
+ or a
+ ret z
+ scf
+ ret
+; 0x6ff7
+
+Func_6ff7: ; 6ff7 (1:6ff7)
+ ld a, DUELVARS_NUMBER_OF_POKEMON_IN_PLAY_AREA
+ call GetTurnDuelistVariable
+ ld c, a
+ ld l, DUELVARS_ARENA_CARD_HP
+.loop
+ ld a, [hli]
+ or a
+ jr nz, .non_zero_hp
+ dec c
+ jr nz, .loop
+ scf
+ ret
+.non_zero_hp
+ or a
+ ret
+; 0x700a
; print one of the "There was no effect from" texts depending
; on the value at wNoEffectFromStatus (NO_STATUS or a status condition constant)
@@ -7488,7 +7762,7 @@ PrizeBitmasks: ; 715a (1:715a)
; update the turn holder's DUELVARS_PRIZES following that duelist
; drawing a number of prizes equal to register a
-DrawPrizes: ; 7161 (1:7161)
+TakeAPrizes: ; 7161 (1:7161)
or a
ret z
ld c, a
diff --git a/src/engine/home.asm b/src/engine/home.asm
index b46bc44..6ff4cbb 100644
--- a/src/engine/home.asm
+++ b/src/engine/home.asm
@@ -4023,8 +4023,8 @@ PutHandCardInPlayArea: ; 14d2 (0:14d2)
ret
; 0x14dd
-; move the play area Pokemon card of the turn holder at CARD_LOCATION_PLAY_AREA + a
-; to the discard pile
+; move the Pokemon card of the turn holder in the
+; PLAY_AREA_* location given in e to the discard pile
MovePlayAreaCardToDiscardPile: ; 14dd (0:14dd)
call EmptyPlayAreaSlot
ld l, DUELVARS_NUMBER_OF_POKEMON_IN_PLAY_AREA
diff --git a/src/text/text1.asm b/src/text/text1.asm
index 8789758..075a9ef 100644
--- a/src/text/text1.asm
+++ b/src/text/text1.asm
@@ -277,15 +277,15 @@ DiscardDescription: ; 36757 (d:6757)
line "a Pokémon Power)"
done
-Text0042: ; 367cc (d:67cc)
+WillDrawNPrizesText: ; 367cc (d:67cc)
text "<RAMNAME> will draw <RAMNUM> Prize(s)."
done
-Text0043: ; 367e5 (d:67e5)
+DrewNPrizesText: ; 367e5 (d:67e5)
text "<RAMNAME> drew <RAMNUM> Prize(s)."
done
-Text0044: ; 367f9 (d:67f9)
+DuelistPlacedACardText: ; 367f9 (d:67f9)
text "<RAMNAME> placed"
line "a <RAMTEXT>."
done
@@ -561,12 +561,12 @@ CardsText: ; 36e63 (d:6e63)
text "Cards"
done
-Text007f: ; 36e6a (d:6e6a)
+TookAllThePrizesText: ; 36e6a (d:6e6a)
text "<RAMNAME> took"
line "all the Prizes!"
done
-Text0080: ; 36e82 (d:6e82)
+ThereAreNoPokemonInPlayAreaText: ; 36e82 (d:6e82)
text "There are no Pokémon"
line "in <RAMNAME>'s Play Area!"
done
diff --git a/src/text/text2.asm b/src/text/text2.asm
index 8dac791..97ecf45 100644
--- a/src/text/text2.asm
+++ b/src/text/text2.asm
@@ -126,12 +126,12 @@ SelectPkmnOnBenchToSwitchWithActiveText: ; 38533 (e:4533)
line "to switch with the Active Pokémon."
done
-Text010f: ; 38575 (e:4575)
+SelectPokemonToPlaceInTheArenaText: ; 38575 (e:4575)
text "Select a Pokémon to place"
line "in the Arena."
done
-Text0110: ; 3859e (e:459e)
+DuelistIsSelectingPokemonToPlaceInArenaText: ; 3859e (e:459e)
text "<RAMNAME> is selecting a Pokémon"
line "to place in the Arena."
done
diff --git a/src/text/text_offsets.asm b/src/text/text_offsets.asm
index 6e03ba2..cf89644 100644
--- a/src/text/text_offsets.asm
+++ b/src/text/text_offsets.asm
@@ -67,9 +67,9 @@ TextOffsets:: ; 34000 (d:4000)
textpointer Text003f ; 0x003f
textpointer Text0040 ; 0x0040
textpointer DiscardDescription ; 0x0041
- textpointer Text0042 ; 0x0042
- textpointer Text0043 ; 0x0043
- textpointer Text0044 ; 0x0044
+ textpointer WillDrawNPrizesText ; 0x0042
+ textpointer DrewNPrizesText ; 0x0043
+ textpointer DuelistPlacedACardText ; 0x0044
textpointer Text0045 ; 0x0045
textpointer Text0046 ; 0x0046
textpointer Text0047 ; 0x0047
@@ -128,8 +128,8 @@ TextOffsets:: ; 34000 (d:4000)
textpointer NoneText ; 0x007c
textpointer YesText ; 0x007d
textpointer CardsText ; 0x007e
- textpointer Text007f ; 0x007f
- textpointer Text0080 ; 0x0080
+ textpointer TookAllThePrizesText ; 0x007f
+ textpointer ThereAreNoPokemonInPlayAreaText ; 0x0080
textpointer WasKnockedOutText ; 0x0081
textpointer HavePokemonPowerText ; 0x0082
textpointer UnableToUsePkmnPowerDueToToxicGasText ; 0x0083
@@ -272,8 +272,8 @@ TextOffsets:: ; 34000 (d:4000)
textpointer NoDamageOrEffectDueToTransparencyText ; 0x010c
textpointer Text010d ; 0x010d
textpointer SelectPkmnOnBenchToSwitchWithActiveText ; 0x010e
- textpointer Text010f ; 0x010f
- textpointer Text0110 ; 0x0110
+ textpointer SelectPokemonToPlaceInTheArenaText ; 0x010f
+ textpointer DuelistIsSelectingPokemonToPlaceInArenaText ; 0x0110
textpointer Text0111 ; 0x0111
textpointer Text0112 ; 0x0112
textpointer Text0113 ; 0x0113
diff --git a/src/wram.asm b/src/wram.asm
index 38ebd4a..7399551 100644
--- a/src/wram.asm
+++ b/src/wram.asm
@@ -780,6 +780,8 @@ wcbfa:: ; cbfa
wcbfb:: ; cbfb
ds $1
+; used by Func_5805 to store the remaining Prizes, so that if more than that
+; amount would be taken, only the remaining amount is taken
wcbfc:: ; cbfc
ds $1
@@ -959,7 +961,12 @@ wSelectedMoveIndex:: ; ccc6
; if affected by a no damage or effect substatus, this flag indicates what the cause was
wNoDamageOrEffect:: ; ccc7
- ds $2
+ ds $1
+
+; used by CountKnockedOutPokemon and Func_5805 to store the amount
+; of prizes to take (equal to the number of Pokemon knocked out)
+wccc8:: ; ccc8
+ ds $1
; set to 1 if the coin toss in the confusion check is heads (CheckSelfConfusionDamage)
wGotHeadsFromConfusionCheck:: ; ccc9