summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/engine/bank01.asm30
-rw-r--r--src/engine/home.asm10
-rw-r--r--src/wram.asm2
3 files changed, 33 insertions, 9 deletions
diff --git a/src/engine/bank01.asm b/src/engine/bank01.asm
index c662354..d459c81 100644
--- a/src/engine/bank01.asm
+++ b/src/engine/bank01.asm
@@ -561,6 +561,12 @@ DuelMenu_Retreat: ; 43ab (1:43ab)
jp PrintDuelMenu
.not_confused
+ ; note that the energy cards are discarded (DiscardRetreatCostCards), then returned
+ ; (ReturnRetreatCostCardsToArena), then discarded again for good (AttemptRetreat).
+ ; It's done this way so that the retreating Pokemon is listed with its energies updated
+ ; when the Play Area screen is shown to select the Pokemon to switch to. The reason why
+ ; AttemptRetreat is responsible for discarding the energy cards is because, if the
+ ; Pokemon is confused, it may not be able to retreat, so they cannot be discarded earlier.
call CheckAbleToRetreat
jr c, .unable_to_retreat
call Func_4611
@@ -572,7 +578,7 @@ DuelMenu_Retreat: ; 43ab (1:43ab)
ld [wBenchSelectedPokemon], a
ldh [hTempPlayAreaLocationOffset_ffa1], a
push af
- call $6564
+ call ReturnRetreatCostCardsToArena
pop af
jp c, DuelMainInterface
ld a, $04
@@ -3637,10 +3643,26 @@ DiscardRetreatCostCards: ; 6558 (1:6558)
jr .discard_loop
; 0x6564
- INCROM $6564, $657a
+; moves the discard pile cards that were loaded to hTempRetreatCostCards back to the active Pokemon.
+; this exists because they will be discarded again during the call to AttemptRetreat, so
+; it prevents the energy cards from being discarded twice.
+ReturnRetreatCostCardsToArena: ; 6564 (1:6564)
+ ld hl, hTempRetreatCostCards
+.loop
+ ld a, [hli]
+ cp $ff
+ ret z
+ push hl
+ call MoveDiscardPileCardToHand
+ call AddCardToHand
+ ld e, PLAY_AREA_ARENA
+ call PutHandCardInPlayArea
+ pop hl
+ jr .loop
+; 0x657a
-; discard retreat cost energy cards and attempt retreat
-; return carry if unable to retreat this turn due to unsuccesful confusion check
+; discard retreat cost energy cards and attempt retreat.
+; return carry if unable to retreat this turn due to unsuccessful confusion check
AttemptRetreat: ; 657a (1:657a)
call DiscardRetreatCostCards
ldh a, [hTemp_ffa0]
diff --git a/src/engine/home.asm b/src/engine/home.asm
index c9b262b..b9fe48f 100644
--- a/src/engine/home.asm
+++ b/src/engine/home.asm
@@ -20,7 +20,7 @@ SECTION "rst38", ROM0
SECTION "vblank", ROM0
jp VBlankHandler
SECTION "lcdc", ROM0
- call wLCDCFunctiontrampoline
+ call wLCDCFunctionTrampoline
reti
SECTION "timer", ROM0
jp TimerHandler
@@ -339,7 +339,7 @@ SetupLCD: ; 030b (0:030b)
xor a
ld [wReentrancyFlag], a
ld a, $c3 ; $c3 = jp nn
- ld [wLCDCFunctiontrampoline], a
+ ld [wLCDCFunctionTrampoline], a
ld [wVBlankFunctionTrampoline], a
ld hl, wVBlankFunctionTrampoline + 1
ld [hl], LOW(NopF) ;
@@ -3036,7 +3036,8 @@ ReturnCardToDeck: ; 10e8 (0:10e8)
ret
; 0x10fc
-; search a card in the turn holder's deck, extract it, and add it to the hand
+; search a card in the turn holder's deck, extract it, and set its location to
+; CARD_LOCATION_JUST_DRAWN. AddCardToHand is meant to be called next.
; the card is identified by register a, which contains the card number within the deck (0-59)
SearchCardInDeckAndAddToHand: ; 10fc (0:10fc)
push af
@@ -3170,7 +3171,8 @@ PutCardInDiscardPile: ; 116a (0:116a)
ret
; 0x1182
-; search a card in the turn holder's discard pile, extract it, and add it to the hand
+; search a card in the turn holder's discard pile, extract it, and set its location to
+; CARD_LOCATION_JUST_DRAWN. AddCardToHand is meant to be called next.
; the card is identified by register a, which contains the card number within the deck (0-59)
MoveDiscardPileCardToHand: ; 1182 (0:1182)
push hl
diff --git a/src/wram.asm b/src/wram.asm
index 6619a17..02b6296 100644
--- a/src/wram.asm
+++ b/src/wram.asm
@@ -461,7 +461,7 @@ wCounter:: ; cacc
ds $1
; the LCDC status interrupt is always disabled and this always reads as jp $0000
-wLCDCFunctiontrampoline:: ; cacd
+wLCDCFunctionTrampoline:: ; cacd
ds $3
wVBlankFunctionTrampoline:: ; cad0