pokered/engine/menu/prize_menu.asm

307 lines
5.7 KiB
NASM
Raw Normal View History

2014-05-22 22:13:20 +00:00
CeladonPrizeMenu: ; 5271b (14:671b)
ld b,COIN_CASE
call IsItemInBag
jr nz,.havingCoinCase
ld hl,RequireCoinCaseTextPtr
jp PrintText
.havingCoinCase
ld hl,wd730
2015-01-24 20:52:11 +00:00
set 6,[hl] ; disable letter-printing delay
2014-05-22 22:13:20 +00:00
ld hl,ExchangeCoinsForPrizesTextPtr
call PrintText
; the following are the menu settings
xor a
ld [wCurrentMenuItem],a
ld [wLastMenuItem],a
2015-08-11 05:34:32 +00:00
ld a,A_BUTTON | B_BUTTON
ld [wMenuWatchedKeys],a
2014-05-22 22:13:20 +00:00
ld a,$03
ld [wMaxMenuItem],a
2014-05-22 22:13:20 +00:00
ld a,$04
ld [wTopMenuItemY],a
2014-05-22 22:13:20 +00:00
ld a,$01
ld [wTopMenuItemX],a
call PrintPrizePrice
2015-07-18 20:52:03 +00:00
coord hl, 0, 2
2014-05-22 22:13:20 +00:00
ld b,$08
ld c,$10
call TextBoxBorder
call GetPrizeMenuId
2014-05-22 22:13:20 +00:00
call UpdateSprites
ld hl,WhichPrizeTextPtr
call PrintText
call HandleMenuInput ; menu choice handler
bit 1,a ; keypress = B (Cancel)
jr nz,.NoChoice
ld a,[wCurrentMenuItem]
2014-05-22 22:13:20 +00:00
cp a,$03 ; "NO,THANKS" choice
jr z,.NoChoice
call HandlePrizeChoice
2014-05-22 22:13:20 +00:00
.NoChoice
ld hl,wd730
2014-05-22 22:13:20 +00:00
res 6,[hl]
ret
RequireCoinCaseTextPtr: ; 5277e (14:677e)
TX_FAR _RequireCoinCaseText
db $0D
db "@"
ExchangeCoinsForPrizesTextPtr: ; 52784 (14:6784)
TX_FAR _ExchangeCoinsForPrizesText
db "@"
WhichPrizeTextPtr: ; 52789 (14:6789)
TX_FAR _WhichPrizeText
db "@"
GetPrizeMenuId: ; 5278e (14:678e)
; determine which one among the three
; prize-texts has been selected
2015-07-18 15:17:29 +00:00
; using the text ID (stored in [hSpriteIndexOrTextID])
; load the three prizes at wd13d-wd13f
; load the three prices at wd141-wd146
2014-05-22 22:13:20 +00:00
; display the three prizes' names
; (distinguishing between Pokemon names
; and Items (specifically TMs) names)
2015-07-18 15:17:29 +00:00
ld a,[hSpriteIndexOrTextID]
2015-07-26 02:26:54 +00:00
sub a,3 ; prize-texts' id are 3, 4 and 5
ld [wWhichPrizeWindow],a ; prize-texts' id (relative, i.e. 0, 1 or 2)
2014-05-22 22:13:20 +00:00
add a
add a
2015-07-26 02:26:54 +00:00
ld d,0
2014-05-22 22:13:20 +00:00
ld e,a
ld hl,PrizeDifferentMenuPtrs
add hl,de
ld a,[hli]
ld d,[hl]
ld e,a
inc hl
push hl
ld hl,W_PRIZE1
call CopyString
2014-05-22 22:13:20 +00:00
pop hl
ld a,[hli]
ld h,[hl]
ld l,a
2015-07-26 02:26:54 +00:00
ld de,wPrize1Price
ld bc,6
2014-05-22 22:13:20 +00:00
call CopyData
2015-07-26 02:26:54 +00:00
ld a,[wWhichPrizeWindow]
2014-05-22 22:13:20 +00:00
cp a,$02 ;is TM_menu?
jr nz,.putMonName
ld a,[W_PRIZE1]
ld [wd11e],a
2014-05-22 22:13:20 +00:00
call GetItemName
2015-07-18 20:52:03 +00:00
coord hl, 2, 4
2014-05-22 22:13:20 +00:00
call PlaceString
ld a,[W_PRIZE2]
ld [wd11e],a
2014-05-22 22:13:20 +00:00
call GetItemName
2015-07-18 20:52:03 +00:00
coord hl, 2, 6
2014-05-22 22:13:20 +00:00
call PlaceString
ld a,[W_PRIZE3]
ld [wd11e],a
2014-05-22 22:13:20 +00:00
call GetItemName
2015-07-18 20:52:03 +00:00
coord hl, 2, 8
2014-05-22 22:13:20 +00:00
call PlaceString
jr .putNoThanksText
.putMonName
2014-05-22 22:13:20 +00:00
ld a,[W_PRIZE1]
ld [wd11e],a
2014-05-22 22:13:20 +00:00
call GetMonName
2015-07-18 20:52:03 +00:00
coord hl, 2, 4
2014-05-22 22:13:20 +00:00
call PlaceString
ld a,[W_PRIZE2]
ld [wd11e],a
2014-05-22 22:13:20 +00:00
call GetMonName
2015-07-18 20:52:03 +00:00
coord hl, 2, 6
2014-05-22 22:13:20 +00:00
call PlaceString
ld a,[W_PRIZE3]
ld [wd11e],a
2014-05-22 22:13:20 +00:00
call GetMonName
2015-07-18 20:52:03 +00:00
coord hl, 2, 8
2014-05-22 22:13:20 +00:00
call PlaceString
.putNoThanksText
2015-07-18 20:52:03 +00:00
coord hl, 2, 10
2014-05-22 22:13:20 +00:00
ld de,NoThanksText
call PlaceString
; put prices on the right side of the textbox
2015-07-26 02:26:54 +00:00
ld de,wPrize1Price
2015-07-18 20:52:03 +00:00
coord hl, 13, 5
2014-05-22 22:13:20 +00:00
; reg. c:
; [low nybble] number of bytes
; [bit 765 = %100] space-padding (not zero-padding)
ld c,(1 << 7 | 2)
; Function $15CD displays BCD value (same routine
; used by text-command $02)
call PrintBCDNumber
2015-07-26 02:26:54 +00:00
ld de,wPrize2Price
2015-07-18 20:52:03 +00:00
coord hl, 13, 7
2014-05-22 22:13:20 +00:00
ld c,(%1 << 7 | 2)
call PrintBCDNumber
2015-07-26 02:26:54 +00:00
ld de,wPrize3Price
2015-07-18 20:52:03 +00:00
coord hl, 13, 9
2014-05-22 22:13:20 +00:00
ld c,(1 << 7 | 2)
jp PrintBCDNumber
INCLUDE "data/prizes.asm"
PrintPrizePrice: ; 5287a (14:687a)
2015-07-18 20:52:03 +00:00
coord hl, 11, 0
2014-05-22 22:13:20 +00:00
ld b,$01
ld c,$07
call TextBoxBorder
call UpdateSprites
2015-07-18 20:52:03 +00:00
coord hl, 12, 0
2014-05-22 22:13:20 +00:00
ld de,.CoinText
call PlaceString
2015-07-18 20:52:03 +00:00
coord hl, 13, 1
2014-05-22 22:13:20 +00:00
ld de,.SixSpacesText
call PlaceString
2015-07-18 20:52:03 +00:00
coord hl, 13, 1
2014-05-22 22:13:20 +00:00
ld de,wPlayerCoins
ld c,%10000010
call PrintBCDNumber
ret
.CoinText
2014-05-22 22:13:20 +00:00
db "COIN@"
.SixSpacesText
2014-05-22 22:13:20 +00:00
db " @"
LoadCoinsToSubtract: ; 528b1 (14:68b1)
2015-07-26 02:26:54 +00:00
ld a,[wWhichPrize]
2014-05-22 22:13:20 +00:00
add a
2015-07-26 02:26:54 +00:00
ld d,0
2014-05-22 22:13:20 +00:00
ld e,a
2015-07-26 02:26:54 +00:00
ld hl,wPrize1Price
2014-05-22 22:13:20 +00:00
add hl,de ; get selected prize's price
xor a
2015-07-19 21:01:08 +00:00
ld [hUnusedCoinsByte],a
2014-05-22 22:13:20 +00:00
ld a,[hli]
2015-07-17 08:21:40 +00:00
ld [hCoins],a
2014-05-22 22:13:20 +00:00
ld a,[hl]
2015-07-17 08:21:40 +00:00
ld [hCoins + 1],a
2014-05-22 22:13:20 +00:00
ret
HandlePrizeChoice: ; 528c6 (14:68c6)
2015-07-26 02:26:54 +00:00
ld a,[wCurrentMenuItem]
ld [wWhichPrize],a
ld d,0
2014-05-22 22:13:20 +00:00
ld e,a
ld hl,W_PRIZE1
add hl,de
ld a,[hl]
ld [wd11e],a
2015-07-26 02:26:54 +00:00
ld a,[wWhichPrizeWindow]
2014-05-22 22:13:20 +00:00
cp a,$02 ; is prize a TM?
jr nz,.GetMonName
call GetItemName
jr .GivePrize
.GetMonName
2014-05-22 22:13:20 +00:00
call GetMonName
.GivePrize
2014-05-22 22:13:20 +00:00
ld hl,SoYouWantPrizeTextPtr
call PrintText
2015-07-26 02:26:54 +00:00
call YesNoChoice
ld a,[wCurrentMenuItem] ; yes/no answer (Y=0, N=1)
2014-05-22 22:13:20 +00:00
and a
jr nz,.PrintOhFineThen
call LoadCoinsToSubtract
call HasEnoughCoins
jr c,.NotEnoughCoins
2015-07-26 02:26:54 +00:00
ld a,[wWhichPrizeWindow]
2014-05-22 22:13:20 +00:00
cp a,$02
jr nz,.GiveMon
ld a,[wd11e]
2014-05-22 22:13:20 +00:00
ld b,a
ld a,1
ld c,a
call GiveItem
2014-05-22 22:13:20 +00:00
jr nc,.BagFull
jr .SubtractCoins
.GiveMon
ld a,[wd11e]
ld [wcf91],a
2014-05-22 22:13:20 +00:00
push af
call GetPrizeMonLevel
2014-05-22 22:13:20 +00:00
ld c,a
pop af
ld b,a
call GivePokemon
2015-07-19 03:49:52 +00:00
; If either the party or box was full, wait after displaying message.
2014-05-22 22:13:20 +00:00
push af
2015-07-19 03:49:52 +00:00
ld a,[wAddedToParty]
2014-05-22 22:13:20 +00:00
and a
call z,WaitForTextScrollButtonPress
pop af
2015-07-19 03:49:52 +00:00
; If the mon couldn't be given to the player (because both the party and box
; were full), return without subtracting coins.
2014-05-22 22:13:20 +00:00
ret nc
2015-07-19 03:49:52 +00:00
.SubtractCoins
2014-05-22 22:13:20 +00:00
call LoadCoinsToSubtract
2015-07-17 08:21:40 +00:00
ld hl,hCoins + 1
2014-05-22 22:13:20 +00:00
ld de,wPlayerCoins + 1
ld c,$02 ; how many bytes
2015-07-19 03:49:52 +00:00
predef SubBCDPredef
2014-05-22 22:13:20 +00:00
jp PrintPrizePrice
.BagFull
ld hl,PrizeRoomBagIsFullTextPtr
jp PrintText
.NotEnoughCoins
2014-05-22 22:13:20 +00:00
ld hl,SorryNeedMoreCoinsText
jp PrintText
.PrintOhFineThen
2014-05-22 22:13:20 +00:00
ld hl,OhFineThenTextPtr
jp PrintText
UnknownData52951: ; 52951 (14:6951)
; XXX what's this?
db $00,$01,$00,$01,$00,$01,$00,$00,$01
HereYouGoTextPtr: ; 5295a (14:695a)
TX_FAR _HereYouGoText
db $0D
db "@"
SoYouWantPrizeTextPtr: ; 52960 (14:6960)
TX_FAR _SoYouWantPrizeText
db "@"
SorryNeedMoreCoinsText: ; 52965 (14:6965)
TX_FAR _SorryNeedMoreCoinsText
db $0D
db "@"
PrizeRoomBagIsFullTextPtr: ; 5296b (14:696b)
TX_FAR _OopsYouDontHaveEnoughRoomText
db $0D
db "@"
OhFineThenTextPtr: ; 52971 (14:6971)
TX_FAR _OhFineThenText
db $0D ; wait keypress (A/B) without blink
db "@"
GetPrizeMonLevel: ; 52977 (14:6977)
ld a,[wcf91]
2014-05-22 22:13:20 +00:00
ld b,a
ld hl,PrizeMonLevelDictionary
.loop
2014-05-22 22:13:20 +00:00
ld a,[hli]
cp b
jr z,.matchFound
inc hl
jr .loop
.matchFound
2014-05-22 22:13:20 +00:00
ld a,[hl]
ld [W_CURENEMYLVL],a
2014-05-22 22:13:20 +00:00
ret
INCLUDE "data/prize_mon_levels.asm"