pokered/engine/menu/prize_menu.asm

307 lines
5.4 KiB
NASM
Raw Normal View History

2016-06-12 00:24:04 +00:00
CeladonPrizeMenu:
ld b, COIN_CASE
2014-05-22 22:13:20 +00:00
call IsItemInBag
jr nz, .havingCoinCase
ld hl, RequireCoinCaseTextPtr
2014-05-22 22:13:20 +00:00
jp PrintText
.havingCoinCase
ld hl, wd730
set 6, [hl] ; disable letter-printing delay
ld hl, ExchangeCoinsForPrizesTextPtr
2014-05-22 22:13:20 +00:00
call PrintText
; the following are the menu settings
xor a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
ld a, A_BUTTON | B_BUTTON
ld [wMenuWatchedKeys], a
ld a, $03
ld [wMaxMenuItem], a
ld a, $04
ld [wTopMenuItemY], a
ld a, $01
ld [wTopMenuItemX], a
call PrintPrizePrice
2015-07-18 20:52:03 +00:00
coord hl, 0, 2
2016-06-12 04:30:05 +00:00
ld b, 8
ld c, 16
2014-05-22 22:13:20 +00:00
call TextBoxBorder
call GetPrizeMenuId
2014-05-22 22:13:20 +00:00
call UpdateSprites
ld hl, WhichPrizeTextPtr
2014-05-22 22:13:20 +00:00
call PrintText
call HandleMenuInput ; menu choice handler
bit 1, a ; keypress = B (Cancel)
2016-06-12 04:30:05 +00:00
jr nz, .noChoice
ld a, [wCurrentMenuItem]
2016-06-12 04:30:05 +00:00
cp 3 ; "NO,THANKS" choice
jr z, .noChoice
call HandlePrizeChoice
2016-06-12 04:30:05 +00:00
.noChoice
ld hl, wd730
res 6, [hl]
2014-05-22 22:13:20 +00:00
ret
2016-06-12 00:24:04 +00:00
RequireCoinCaseTextPtr:
2014-05-22 22:13:20 +00:00
TX_FAR _RequireCoinCaseText
2016-07-18 06:17:03 +00:00
TX_WAIT
2014-05-22 22:13:20 +00:00
db "@"
2016-06-12 00:24:04 +00:00
ExchangeCoinsForPrizesTextPtr:
2014-05-22 22:13:20 +00:00
TX_FAR _ExchangeCoinsForPrizesText
db "@"
2016-06-12 00:24:04 +00:00
WhichPrizeTextPtr:
2014-05-22 22:13:20 +00:00
TX_FAR _WhichPrizeText
db "@"
2016-06-12 00:24:04 +00:00
GetPrizeMenuId:
2014-05-22 22:13:20 +00:00
; 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)
ld a, [hSpriteIndexOrTextID]
2016-06-12 04:30:05 +00:00
sub 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
ld d, 0
ld e, a
ld hl, PrizeDifferentMenuPtrs
add hl, de
ld a, [hli]
ld d, [hl]
ld e, a
2014-05-22 22:13:20 +00:00
inc hl
push hl
ld hl, wPrize1
call CopyString
2014-05-22 22:13:20 +00:00
pop hl
ld a, [hli]
ld h, [hl]
ld l, a
ld de, wPrize1Price
ld bc, 6
2014-05-22 22:13:20 +00:00
call CopyData
ld a, [wWhichPrizeWindow]
2016-06-12 04:30:05 +00:00
cp 2 ;is TM_menu?
jr nz, .putMonName
ld a, [wPrize1]
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, [wPrize2]
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, [wPrize3]
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
ld a, [wPrize1]
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, [wPrize2]
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, [wPrize3]
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
ld de, NoThanksText
2014-05-22 22:13:20 +00:00
call PlaceString
; put prices on the right side of the textbox
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)
2014-05-22 22:13:20 +00:00
; Function $15CD displays BCD value (same routine
; used by text-command $02)
call PrintBCDNumber
ld de, wPrize2Price
2015-07-18 20:52:03 +00:00
coord hl, 13, 7
ld c, (1 << 7 | 2)
2014-05-22 22:13:20 +00:00
call PrintBCDNumber
ld de, wPrize3Price
2015-07-18 20:52:03 +00:00
coord hl, 13, 9
ld c, (1 << 7 | 2)
2014-05-22 22:13:20 +00:00
jp PrintBCDNumber
INCLUDE "data/prizes.asm"
2016-06-12 00:24:04 +00:00
PrintPrizePrice:
2015-07-18 20:52:03 +00:00
coord hl, 11, 0
2016-06-12 04:30:05 +00:00
ld b, 1
ld c, 7
2014-05-22 22:13:20 +00:00
call TextBoxBorder
call UpdateSprites
2015-07-18 20:52:03 +00:00
coord hl, 12, 0
2016-06-12 04:30:05 +00:00
ld de, .CoinString
2014-05-22 22:13:20 +00:00
call PlaceString
2015-07-18 20:52:03 +00:00
coord hl, 13, 1
2016-06-12 04:30:05 +00:00
ld de, .SixSpacesString
2014-05-22 22:13:20 +00:00
call PlaceString
2015-07-18 20:52:03 +00:00
coord hl, 13, 1
ld de, wPlayerCoins
ld c, %10000010
2014-05-22 22:13:20 +00:00
call PrintBCDNumber
ret
2016-06-12 04:30:05 +00:00
.CoinString:
2014-05-22 22:13:20 +00:00
db "COIN@"
2016-06-12 04:30:05 +00:00
.SixSpacesString:
2014-05-22 22:13:20 +00:00
db " @"
2016-06-12 00:24:04 +00:00
LoadCoinsToSubtract:
ld a, [wWhichPrize]
2014-05-22 22:13:20 +00:00
add a
ld d, 0
ld e, a
ld hl, wPrize1Price
add hl, de ; get selected prize's price
2014-05-22 22:13:20 +00:00
xor a
ld [hUnusedCoinsByte], a
ld a, [hli]
ld [hCoins], a
ld a, [hl]
ld [hCoins + 1], a
2014-05-22 22:13:20 +00:00
ret
2016-06-12 00:24:04 +00:00
HandlePrizeChoice:
ld a, [wCurrentMenuItem]
ld [wWhichPrize], a
ld d, 0
ld e, a
ld hl, wPrize1
add hl, de
ld a, [hl]
ld [wd11e], a
ld a, [wWhichPrizeWindow]
2016-06-12 04:30:05 +00:00
cp 2 ; is prize a TM?
jr nz, .getMonName
2014-05-22 22:13:20 +00:00
call GetItemName
2016-06-12 04:30:05 +00:00
jr .givePrize
.getMonName
2014-05-22 22:13:20 +00:00
call GetMonName
2016-06-12 04:30:05 +00:00
.givePrize
ld hl, SoYouWantPrizeTextPtr
2014-05-22 22:13:20 +00:00
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
2016-06-12 04:30:05 +00:00
jr nz, .printOhFineThen
2014-05-22 22:13:20 +00:00
call LoadCoinsToSubtract
call HasEnoughCoins
2016-06-12 04:30:05 +00:00
jr c, .notEnoughCoins
ld a, [wWhichPrizeWindow]
2016-06-12 04:30:05 +00:00
cp $02
jr nz, .giveMon
ld a, [wd11e]
ld b, a
ld a, 1
ld c, a
call GiveItem
2016-06-12 04:30:05 +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
ld c, a
2014-05-22 22:13:20 +00:00
pop af
ld b, a
2014-05-22 22:13:20 +00:00
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
ld a, [wAddedToParty]
2014-05-22 22:13:20 +00:00
and a
call z, WaitForTextScrollButtonPress
2014-05-22 22:13:20 +00:00
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
2016-06-12 04:30:05 +00:00
.subtractCoins
2014-05-22 22:13:20 +00:00
call LoadCoinsToSubtract
ld hl, hCoins + 1
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
2016-06-12 04:30:05 +00:00
.bagFull
ld hl, PrizeRoomBagIsFullTextPtr
2014-05-22 22:13:20 +00:00
jp PrintText
2016-06-12 04:30:05 +00:00
.notEnoughCoins
ld hl, SorryNeedMoreCoinsText
2014-05-22 22:13:20 +00:00
jp PrintText
2016-06-12 04:30:05 +00:00
.printOhFineThen
ld hl, OhFineThenTextPtr
2014-05-22 22:13:20 +00:00
jp PrintText
2016-06-12 04:30:05 +00:00
UnknownPrizeData:
2014-05-22 22:13:20 +00:00
; XXX what's this?
db $00,$01,$00,$01,$00,$01,$00,$00,$01
2016-06-12 00:24:04 +00:00
HereYouGoTextPtr:
2014-05-22 22:13:20 +00:00
TX_FAR _HereYouGoText
2016-07-18 06:17:03 +00:00
TX_WAIT
2014-05-22 22:13:20 +00:00
db "@"
2016-06-12 00:24:04 +00:00
SoYouWantPrizeTextPtr:
2014-05-22 22:13:20 +00:00
TX_FAR _SoYouWantPrizeText
db "@"
2016-06-12 00:24:04 +00:00
SorryNeedMoreCoinsText:
2014-05-22 22:13:20 +00:00
TX_FAR _SorryNeedMoreCoinsText
2016-07-18 06:17:03 +00:00
TX_WAIT
2014-05-22 22:13:20 +00:00
db "@"
2016-06-12 00:24:04 +00:00
PrizeRoomBagIsFullTextPtr:
2014-05-22 22:13:20 +00:00
TX_FAR _OopsYouDontHaveEnoughRoomText
2016-07-18 06:17:03 +00:00
TX_WAIT
2014-05-22 22:13:20 +00:00
db "@"
2016-06-12 00:24:04 +00:00
OhFineThenTextPtr:
2014-05-22 22:13:20 +00:00
TX_FAR _OhFineThenText
2016-07-18 06:17:03 +00:00
TX_WAIT
2014-05-22 22:13:20 +00:00
db "@"
2016-06-12 00:24:04 +00:00
GetPrizeMonLevel:
ld a, [wcf91]
ld b, a
ld hl, PrizeMonLevelDictionary
.loop
ld a, [hli]
2014-05-22 22:13:20 +00:00
cp b
jr z, .matchFound
2014-05-22 22:13:20 +00:00
inc hl
jr .loop
.matchFound
ld a, [hl]
ld [wCurEnemyLVL], a
2014-05-22 22:13:20 +00:00
ret
INCLUDE "data/prize_mon_levels.asm"