Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/events/prize_menu.asm
1271 views
1
CeladonPrizeMenu::
2
ld b, COIN_CASE
3
call IsItemInBag
4
jr nz, .havingCoinCase
5
ld hl, RequireCoinCaseText
6
jp PrintText
7
.havingCoinCase
8
ld hl, wStatusFlags5
9
set BIT_NO_TEXT_DELAY, [hl]
10
ld hl, ExchangeCoinsForPrizesText
11
call PrintText
12
; the following are the menu settings
13
xor a
14
ld [wCurrentMenuItem], a
15
ld [wLastMenuItem], a
16
ld a, PAD_A | PAD_B
17
ld [wMenuWatchedKeys], a
18
ld a, $03
19
ld [wMaxMenuItem], a
20
ld a, $04
21
ld [wTopMenuItemY], a
22
ld a, $01
23
ld [wTopMenuItemX], a
24
call PrintPrizePrice
25
hlcoord 0, 2
26
ld b, 8
27
ld c, 16
28
call TextBoxBorder
29
call GetPrizeMenuId
30
call UpdateSprites
31
ld hl, WhichPrizeText
32
call PrintText
33
call HandleMenuInput ; menu choice handler
34
bit B_PAD_B, a
35
jr nz, .noChoice
36
ld a, [wCurrentMenuItem]
37
cp 3 ; "NO,THANKS" choice
38
jr z, .noChoice
39
call HandlePrizeChoice
40
.noChoice
41
ld hl, wStatusFlags5
42
res BIT_NO_TEXT_DELAY, [hl]
43
ret
44
45
RequireCoinCaseText:
46
text_far _RequireCoinCaseText
47
text_waitbutton
48
text_end
49
50
ExchangeCoinsForPrizesText:
51
text_far _ExchangeCoinsForPrizesText
52
text_end
53
54
WhichPrizeText:
55
text_far _WhichPrizeText
56
text_end
57
58
GetPrizeMenuId:
59
; determine which one among the three prize texts has been selected using the text ID (stored in [hTextID])
60
; prize texts' IDs are TEXT_GAMECORNERPRIZEROOM_PRIZE_VENDOR_1-TEXT_GAMECORNERPRIZEROOM_PRIZE_VENDOR_3
61
; load the three prizes at wPrize1-wPrice3
62
; load the three prices at wPrize1Price-wPrize3Price
63
; display the three prizes' names, distinguishing between Pokemon names and item names (specifically TMs)
64
ldh a, [hTextID]
65
sub TEXT_GAMECORNERPRIZEROOM_PRIZE_VENDOR_1
66
ld [wWhichPrizeWindow], a ; prize texts' relative ID (i.e. 0-2)
67
add a
68
add a
69
ld d, 0
70
ld e, a
71
ld hl, PrizeDifferentMenuPtrs
72
add hl, de
73
ld a, [hli]
74
ld d, [hl]
75
ld e, a
76
inc hl
77
push hl
78
ld hl, wPrize1
79
call CopyString
80
pop hl
81
ld a, [hli]
82
ld h, [hl]
83
ld l, a
84
ld de, wPrize1Price
85
ld bc, 6
86
call CopyData
87
ld a, [wWhichPrizeWindow]
88
cp 2 ; is TM_menu?
89
jr nz, .putMonName
90
ld a, [wPrize1]
91
ld [wNamedObjectIndex], a
92
call GetItemName
93
hlcoord 2, 4
94
call PlaceString
95
ld a, [wPrize2]
96
ld [wNamedObjectIndex], a
97
call GetItemName
98
hlcoord 2, 6
99
call PlaceString
100
ld a, [wPrize3]
101
ld [wNamedObjectIndex], a
102
call GetItemName
103
hlcoord 2, 8
104
call PlaceString
105
jr .putNoThanksText
106
.putMonName
107
ld a, [wPrize1]
108
ld [wNamedObjectIndex], a
109
call GetMonName
110
hlcoord 2, 4
111
call PlaceString
112
ld a, [wPrize2]
113
ld [wNamedObjectIndex], a
114
call GetMonName
115
hlcoord 2, 6
116
call PlaceString
117
ld a, [wPrize3]
118
ld [wNamedObjectIndex], a
119
call GetMonName
120
hlcoord 2, 8
121
call PlaceString
122
.putNoThanksText
123
hlcoord 2, 10
124
ld de, NoThanksText
125
call PlaceString
126
; put prices on the right side of the textbox
127
ld de, wPrize1Price
128
hlcoord 13, 5
129
ld c, 2 | LEADING_ZEROES
130
call PrintBCDNumber
131
ld de, wPrize2Price
132
hlcoord 13, 7
133
ld c, 2 | LEADING_ZEROES
134
call PrintBCDNumber
135
ld de, wPrize3Price
136
hlcoord 13, 9
137
ld c, 2 | LEADING_ZEROES
138
jp PrintBCDNumber
139
140
INCLUDE "data/events/prizes.asm"
141
142
PrintPrizePrice:
143
hlcoord 11, 0
144
ld b, 1
145
ld c, 7
146
call TextBoxBorder
147
call UpdateSprites
148
hlcoord 12, 0
149
ld de, .CoinString
150
call PlaceString
151
hlcoord 13, 1
152
ld de, .SixSpacesString
153
call PlaceString
154
hlcoord 13, 1
155
ld de, wPlayerCoins
156
ld c, 2 | LEADING_ZEROES
157
call PrintBCDNumber
158
ret
159
160
.CoinString:
161
db "COIN@"
162
163
.SixSpacesString:
164
db " @"
165
166
LoadCoinsToSubtract:
167
ld a, [wWhichPrize]
168
add a
169
ld d, 0
170
ld e, a
171
ld hl, wPrize1Price
172
add hl, de ; get selected prize's price
173
xor a
174
ldh [hUnusedCoinsByte], a
175
ld a, [hli]
176
ldh [hCoins], a
177
ld a, [hl]
178
ldh [hCoins + 1], a
179
ret
180
181
HandlePrizeChoice:
182
ld a, [wCurrentMenuItem]
183
ld [wWhichPrize], a
184
ld d, 0
185
ld e, a
186
ld hl, wPrize1
187
add hl, de
188
ld a, [hl]
189
ld [wNamedObjectIndex], a
190
ld a, [wWhichPrizeWindow]
191
cp 2 ; is prize a TM?
192
jr nz, .getMonName
193
call GetItemName
194
jr .givePrize
195
.getMonName
196
call GetMonName
197
.givePrize
198
ld hl, SoYouWantPrizeTextPtr
199
call PrintText
200
call YesNoChoice
201
ld a, [wCurrentMenuItem] ; yes/no answer (Y=0, N=1)
202
and a
203
jr nz, .printOhFineThen
204
call LoadCoinsToSubtract
205
call HasEnoughCoins
206
jr c, .notEnoughCoins
207
ld a, [wWhichPrizeWindow]
208
cp 2 ; is prize a TM?
209
jr nz, .giveMon
210
ld a, [wNamedObjectIndex]
211
ld b, a
212
ld a, 1
213
ld c, a
214
call GiveItem
215
jr nc, .bagFull
216
jr .subtractCoins
217
.giveMon
218
ld a, [wNamedObjectIndex]
219
ld [wCurPartySpecies], a
220
push af
221
call GetPrizeMonLevel
222
ld c, a
223
pop af
224
ld b, a
225
call GivePokemon
226
227
; If either the party or box was full, wait after displaying message.
228
push af
229
ld a, [wAddedToParty]
230
and a
231
call z, WaitForTextScrollButtonPress
232
pop af
233
234
; If the mon couldn't be given to the player (because both the party and box
235
; were full), return without subtracting coins.
236
ret nc
237
238
.subtractCoins
239
call LoadCoinsToSubtract
240
ld hl, hCoins + 1
241
ld de, wPlayerCoins + 1
242
ld c, $02 ; how many bytes
243
predef SubBCDPredef
244
jp PrintPrizePrice
245
.bagFull
246
ld hl, PrizeRoomBagIsFullTextPtr
247
jp PrintText
248
.notEnoughCoins
249
ld hl, SorryNeedMoreCoinsText
250
jp PrintText
251
.printOhFineThen
252
ld hl, OhFineThenTextPtr
253
jp PrintText
254
255
UnknownPrizeData:
256
; XXX what's this?
257
db $00,$01,$00,$01,$00,$01,$00,$00,$01
258
259
HereYouGoTextPtr:
260
text_far _HereYouGoText
261
text_waitbutton
262
text_end
263
264
SoYouWantPrizeTextPtr:
265
text_far _SoYouWantPrizeText
266
text_end
267
268
SorryNeedMoreCoinsText:
269
text_far _SorryNeedMoreCoinsText
270
text_waitbutton
271
text_end
272
273
PrizeRoomBagIsFullTextPtr:
274
text_far _OopsYouDontHaveEnoughRoomText
275
text_waitbutton
276
text_end
277
278
OhFineThenTextPtr:
279
text_far _OhFineThenText
280
text_waitbutton
281
text_end
282
283
GetPrizeMonLevel:
284
ld a, [wCurPartySpecies]
285
ld b, a
286
ld hl, PrizeMonLevelDictionary
287
.loop
288
ld a, [hli]
289
cp b
290
jr z, .matchFound
291
inc hl
292
jr .loop
293
.matchFound
294
ld a, [hl]
295
ld [wCurEnemyLevel], a
296
ret
297
298
INCLUDE "data/events/prize_mon_levels.asm"
299
300