prize_menu.asm 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. CeladonPrizeMenu:
  2. ld b, COIN_CASE
  3. call IsItemInBag
  4. jr nz, .havingCoinCase
  5. ld hl, RequireCoinCaseTextPtr
  6. jp PrintText
  7. .havingCoinCase
  8. ld hl, wd730
  9. set 6, [hl] ; disable letter-printing delay
  10. ld hl, ExchangeCoinsForPrizesTextPtr
  11. call PrintText
  12. ; the following are the menu settings
  13. xor a
  14. ld [wCurrentMenuItem], a
  15. ld [wLastMenuItem], a
  16. ld a, A_BUTTON | B_BUTTON
  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. coord hl, 0, 2
  26. ld b, 8
  27. ld c, 16
  28. call TextBoxBorder
  29. call GetPrizeMenuId
  30. call UpdateSprites
  31. ld hl, WhichPrizeTextPtr
  32. call PrintText
  33. call HandleMenuInput ; menu choice handler
  34. bit 1, a ; keypress = B (Cancel)
  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, wd730
  42. res 6, [hl]
  43. ret
  44. RequireCoinCaseTextPtr:
  45. TX_FAR _RequireCoinCaseText
  46. TX_WAIT
  47. db "@"
  48. ExchangeCoinsForPrizesTextPtr:
  49. TX_FAR _ExchangeCoinsForPrizesText
  50. db "@"
  51. WhichPrizeTextPtr:
  52. TX_FAR _WhichPrizeText
  53. db "@"
  54. GetPrizeMenuId:
  55. ; determine which one among the three
  56. ; prize-texts has been selected
  57. ; using the text ID (stored in [hSpriteIndexOrTextID])
  58. ; load the three prizes at wd13d-wd13f
  59. ; load the three prices at wd141-wd146
  60. ; display the three prizes' names
  61. ; (distinguishing between Pokemon names
  62. ; and Items (specifically TMs) names)
  63. ld a, [hSpriteIndexOrTextID]
  64. sub 3 ; prize-texts' id are 3, 4 and 5
  65. ld [wWhichPrizeWindow], a ; prize-texts' id (relative, i.e. 0, 1 or 2)
  66. add a
  67. add a
  68. ld d, 0
  69. ld e, a
  70. ld hl, PrizeDifferentMenuPtrs
  71. add hl, de
  72. ld a, [hli]
  73. ld d, [hl]
  74. ld e, a
  75. inc hl
  76. push hl
  77. ld hl, wPrize1
  78. call CopyString
  79. pop hl
  80. ld a, [hli]
  81. ld h, [hl]
  82. ld l, a
  83. ld de, wPrize1Price
  84. ld bc, 6
  85. call CopyData
  86. ld a, [wWhichPrizeWindow]
  87. cp 2 ;is TM_menu?
  88. jr nz, .putMonName
  89. ld a, [wPrize1]
  90. ld [wd11e], a
  91. call GetItemName
  92. coord hl, 2, 4
  93. call PlaceString
  94. ld a, [wPrize2]
  95. ld [wd11e], a
  96. call GetItemName
  97. coord hl, 2, 6
  98. call PlaceString
  99. ld a, [wPrize3]
  100. ld [wd11e], a
  101. call GetItemName
  102. coord hl, 2, 8
  103. call PlaceString
  104. jr .putNoThanksText
  105. .putMonName
  106. ld a, [wPrize1]
  107. ld [wd11e], a
  108. call GetMonName
  109. coord hl, 2, 4
  110. call PlaceString
  111. ld a, [wPrize2]
  112. ld [wd11e], a
  113. call GetMonName
  114. coord hl, 2, 6
  115. call PlaceString
  116. ld a, [wPrize3]
  117. ld [wd11e], a
  118. call GetMonName
  119. coord hl, 2, 8
  120. call PlaceString
  121. .putNoThanksText
  122. coord hl, 2, 10
  123. ld de, NoThanksText
  124. call PlaceString
  125. ; put prices on the right side of the textbox
  126. ld de, wPrize1Price
  127. coord hl, 13, 5
  128. ; reg. c:
  129. ; [low nybble] number of bytes
  130. ; [bit 765 = %100] space-padding (not zero-padding)
  131. ld c, (1 << 7 | 2)
  132. ; Function $15CD displays BCD value (same routine
  133. ; used by text-command $02)
  134. call PrintBCDNumber
  135. ld de, wPrize2Price
  136. coord hl, 13, 7
  137. ld c, (1 << 7 | 2)
  138. call PrintBCDNumber
  139. ld de, wPrize3Price
  140. coord hl, 13, 9
  141. ld c, (1 << 7 | 2)
  142. jp PrintBCDNumber
  143. INCLUDE "data/prizes.asm"
  144. PrintPrizePrice:
  145. coord hl, 11, 0
  146. ld b, 1
  147. ld c, 7
  148. call TextBoxBorder
  149. call UpdateSprites
  150. coord hl, 12, 0
  151. ld de, .CoinString
  152. call PlaceString
  153. coord hl, 13, 1
  154. ld de, .SixSpacesString
  155. call PlaceString
  156. coord hl, 13, 1
  157. ld de, wPlayerCoins
  158. ld c, %10000010
  159. call PrintBCDNumber
  160. ret
  161. .CoinString:
  162. db "COIN@"
  163. .SixSpacesString:
  164. db " @"
  165. LoadCoinsToSubtract:
  166. ld a, [wWhichPrize]
  167. add a
  168. ld d, 0
  169. ld e, a
  170. ld hl, wPrize1Price
  171. add hl, de ; get selected prize's price
  172. xor a
  173. ld [hUnusedCoinsByte], a
  174. ld a, [hli]
  175. ld [hCoins], a
  176. ld a, [hl]
  177. ld [hCoins + 1], a
  178. ret
  179. HandlePrizeChoice:
  180. ld a, [wCurrentMenuItem]
  181. ld [wWhichPrize], a
  182. ld d, 0
  183. ld e, a
  184. ld hl, wPrize1
  185. add hl, de
  186. ld a, [hl]
  187. ld [wd11e], a
  188. ld a, [wWhichPrizeWindow]
  189. cp 2 ; is prize a TM?
  190. jr nz, .getMonName
  191. call GetItemName
  192. jr .givePrize
  193. .getMonName
  194. call GetMonName
  195. .givePrize
  196. ld hl, SoYouWantPrizeTextPtr
  197. call PrintText
  198. call YesNoChoice
  199. ld a, [wCurrentMenuItem] ; yes/no answer (Y=0, N=1)
  200. and a
  201. jr nz, .printOhFineThen
  202. call LoadCoinsToSubtract
  203. call HasEnoughCoins
  204. jr c, .notEnoughCoins
  205. ld a, [wWhichPrizeWindow]
  206. cp $02
  207. jr nz, .giveMon
  208. ld a, [wd11e]
  209. ld b, a
  210. ld a, 1
  211. ld c, a
  212. call GiveItem
  213. jr nc, .bagFull
  214. jr .subtractCoins
  215. .giveMon
  216. ld a, [wd11e]
  217. ld [wcf91], a
  218. push af
  219. call GetPrizeMonLevel
  220. ld c, a
  221. pop af
  222. ld b, a
  223. call GivePokemon
  224. ; If either the party or box was full, wait after displaying message.
  225. push af
  226. ld a, [wAddedToParty]
  227. and a
  228. call z, WaitForTextScrollButtonPress
  229. pop af
  230. ; If the mon couldn't be given to the player (because both the party and box
  231. ; were full), return without subtracting coins.
  232. ret nc
  233. .subtractCoins
  234. call LoadCoinsToSubtract
  235. ld hl, hCoins + 1
  236. ld de, wPlayerCoins + 1
  237. ld c, $02 ; how many bytes
  238. predef SubBCDPredef
  239. jp PrintPrizePrice
  240. .bagFull
  241. ld hl, PrizeRoomBagIsFullTextPtr
  242. jp PrintText
  243. .notEnoughCoins
  244. ld hl, SorryNeedMoreCoinsText
  245. jp PrintText
  246. .printOhFineThen
  247. ld hl, OhFineThenTextPtr
  248. jp PrintText
  249. UnknownPrizeData:
  250. ; XXX what's this?
  251. db $00,$01,$00,$01,$00,$01,$00,$00,$01
  252. HereYouGoTextPtr:
  253. TX_FAR _HereYouGoText
  254. TX_WAIT
  255. db "@"
  256. SoYouWantPrizeTextPtr:
  257. TX_FAR _SoYouWantPrizeText
  258. db "@"
  259. SorryNeedMoreCoinsText:
  260. TX_FAR _SorryNeedMoreCoinsText
  261. TX_WAIT
  262. db "@"
  263. PrizeRoomBagIsFullTextPtr:
  264. TX_FAR _OopsYouDontHaveEnoughRoomText
  265. TX_WAIT
  266. db "@"
  267. OhFineThenTextPtr:
  268. TX_FAR _OhFineThenText
  269. TX_WAIT
  270. db "@"
  271. GetPrizeMonLevel:
  272. ld a, [wcf91]
  273. ld b, a
  274. ld hl, PrizeMonLevelDictionary
  275. .loop
  276. ld a, [hli]
  277. cp b
  278. jr z, .matchFound
  279. inc hl
  280. jr .loop
  281. .matchFound
  282. ld a, [hl]
  283. ld [wCurEnemyLVL], a
  284. ret
  285. INCLUDE "data/prize_mon_levels.asm"