items.asm 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990
  1. UseItem_:
  2. ld a, 1
  3. ld [wActionResultOrTookBattleTurn], a ; initialise to success value
  4. ld a, [wcf91] ;contains item_ID
  5. cp HM_01
  6. jp nc, ItemUseTMHM
  7. ld hl, ItemUsePtrTable
  8. dec a
  9. add a
  10. ld c, a
  11. ld b, 0
  12. add hl, bc
  13. ld a, [hli]
  14. ld h, [hl]
  15. ld l, a
  16. jp hl
  17. ItemUsePtrTable:
  18. dw ItemUseBall ; MASTER_BALL
  19. dw ItemUseBall ; ULTRA_BALL
  20. dw ItemUseBall ; GREAT_BALL
  21. dw ItemUseBall ; POKE_BALL
  22. dw ItemUseTownMap ; TOWN_MAP
  23. dw ItemUseBicycle ; BICYCLE
  24. dw ItemUseSurfboard ; out-of-battle Surf effect
  25. dw ItemUseBall ; SAFARI_BALL
  26. dw ItemUsePokedex ; POKEDEX
  27. dw ItemUseEvoStone ; MOON_STONE
  28. dw ItemUseMedicine ; ANTIDOTE
  29. dw ItemUseMedicine ; BURN_HEAL
  30. dw ItemUseMedicine ; ICE_HEAL
  31. dw ItemUseMedicine ; AWAKENING
  32. dw ItemUseMedicine ; PARLYZ_HEAL
  33. dw ItemUseMedicine ; FULL_RESTORE
  34. dw ItemUseMedicine ; MAX_POTION
  35. dw ItemUseMedicine ; HYPER_POTION
  36. dw ItemUseMedicine ; SUPER_POTION
  37. dw ItemUseMedicine ; POTION
  38. dw ItemUseBait ; BOULDERBADGE
  39. dw ItemUseRock ; CASCADEBADGE
  40. dw UnusableItem ; THUNDERBADGE
  41. dw UnusableItem ; RAINBOWBADGE
  42. dw UnusableItem ; SOULBADGE
  43. dw UnusableItem ; MARSHBADGE
  44. dw UnusableItem ; VOLCANOBADGE
  45. dw UnusableItem ; EARTHBADGE
  46. dw ItemUseEscapeRope ; ESCAPE_ROPE
  47. dw ItemUseRepel ; REPEL
  48. dw UnusableItem ; OLD_AMBER
  49. dw ItemUseEvoStone ; FIRE_STONE
  50. dw ItemUseEvoStone ; THUNDER_STONE
  51. dw ItemUseEvoStone ; WATER_STONE
  52. dw ItemUseVitamin ; HP_UP
  53. dw ItemUseVitamin ; PROTEIN
  54. dw ItemUseVitamin ; IRON
  55. dw ItemUseVitamin ; CARBOS
  56. dw ItemUseVitamin ; CALCIUM
  57. dw ItemUseVitamin ; RARE_CANDY
  58. dw UnusableItem ; DOME_FOSSIL
  59. dw UnusableItem ; HELIX_FOSSIL
  60. dw UnusableItem ; SECRET_KEY
  61. dw UnusableItem
  62. dw UnusableItem ; BIKE_VOUCHER
  63. dw ItemUseXAccuracy ; X_ACCURACY
  64. dw ItemUseEvoStone ; LEAF_STONE
  65. dw ItemUseCardKey ; CARD_KEY
  66. dw UnusableItem ; NUGGET
  67. dw UnusableItem ; ??? PP_UP
  68. dw ItemUsePokedoll ; POKE_DOLL
  69. dw ItemUseMedicine ; FULL_HEAL
  70. dw ItemUseMedicine ; REVIVE
  71. dw ItemUseMedicine ; MAX_REVIVE
  72. dw ItemUseGuardSpec ; GUARD_SPEC
  73. dw ItemUseSuperRepel ; SUPER_REPL
  74. dw ItemUseMaxRepel ; MAX_REPEL
  75. dw ItemUseDireHit ; DIRE_HIT
  76. dw UnusableItem ; COIN
  77. dw ItemUseMedicine ; FRESH_WATER
  78. dw ItemUseMedicine ; SODA_POP
  79. dw ItemUseMedicine ; LEMONADE
  80. dw UnusableItem ; S_S_TICKET
  81. dw UnusableItem ; GOLD_TEETH
  82. dw ItemUseXStat ; X_ATTACK
  83. dw ItemUseXStat ; X_DEFEND
  84. dw ItemUseXStat ; X_SPEED
  85. dw ItemUseXStat ; X_SPECIAL
  86. dw ItemUseCoinCase ; COIN_CASE
  87. dw ItemUseOaksParcel ; OAKS_PARCEL
  88. dw ItemUseItemfinder ; ITEMFINDER
  89. dw UnusableItem ; SILPH_SCOPE
  90. dw ItemUsePokeflute ; POKE_FLUTE
  91. dw UnusableItem ; LIFT_KEY
  92. dw UnusableItem ; EXP_ALL
  93. dw ItemUseOldRod ; OLD_ROD
  94. dw ItemUseGoodRod ; GOOD_ROD
  95. dw ItemUseSuperRod ; SUPER_ROD
  96. dw ItemUsePPUp ; PP_UP (real one)
  97. dw ItemUsePPRestore ; ETHER
  98. dw ItemUsePPRestore ; MAX_ETHER
  99. dw ItemUsePPRestore ; ELIXER
  100. dw ItemUsePPRestore ; MAX_ELIXER
  101. ItemUseBall:
  102. ; Balls can't be used out of battle.
  103. ld a, [wIsInBattle]
  104. and a
  105. jp z, ItemUseNotTime
  106. ; Balls can't catch trainers' Pokémon.
  107. dec a
  108. jp nz, ThrowBallAtTrainerMon
  109. ; If this is for the old man battle, skip checking if the party & box are full.
  110. ld a, [wBattleType]
  111. dec a
  112. jr z, .canUseBall
  113. ld a, [wPartyCount] ; is party full?
  114. cp PARTY_LENGTH
  115. jr nz, .canUseBall
  116. ld a, [wNumInBox] ; is box full?
  117. cp MONS_PER_BOX
  118. jp z, BoxFullCannotThrowBall
  119. .canUseBall
  120. xor a
  121. ld [wCapturedMonSpecies], a
  122. ld a, [wBattleType]
  123. cp BATTLE_TYPE_SAFARI
  124. jr nz, .skipSafariZoneCode
  125. .safariZone
  126. ld hl, wNumSafariBalls
  127. dec [hl] ; remove a Safari Ball
  128. .skipSafariZoneCode
  129. call RunDefaultPaletteCommand
  130. ld a, $43 ; successful capture value
  131. ld [wPokeBallAnimData], a
  132. call LoadScreenTilesFromBuffer1
  133. ld hl, ItemUseText00
  134. call PrintText
  135. ; If the player is fighting an unidentified ghost, set the value that indicates
  136. ; the Pokémon can't be caught and skip the capture calculations.
  137. callab IsGhostBattle
  138. ld b, $10 ; can't be caught value
  139. jp z, .setAnimData
  140. ld a, [wBattleType]
  141. dec a
  142. jr nz, .notOldManBattle
  143. .oldManBattle
  144. ld hl, wGrassRate
  145. ld de, wPlayerName
  146. ld bc, NAME_LENGTH
  147. call CopyData ; save the player's name in the Wild Monster data (part of the Cinnabar Island Missingno. glitch)
  148. jp .captured
  149. .notOldManBattle
  150. ; If the player is fighting the ghost Marowak, set the value that indicates the
  151. ; Pokémon can't be caught and skip the capture calculations.
  152. ld a, [wCurMap]
  153. cp POKEMONTOWER_6
  154. jr nz, .loop
  155. ld a, [wEnemyMonSpecies2]
  156. cp MAROWAK
  157. ld b, $10 ; can't be caught value
  158. jp z, .setAnimData
  159. ; Get the first random number. Let it be called Rand1.
  160. ; Rand1 must be within a certain range according the kind of ball being thrown.
  161. ; The ranges are as follows.
  162. ; Poké Ball: [0, 255]
  163. ; Great Ball: [0, 200]
  164. ; Ultra/Safari Ball: [0, 150]
  165. ; Loop until an acceptable number is found.
  166. .loop
  167. call Random
  168. ld b, a
  169. ; Get the item ID.
  170. ld hl, wcf91
  171. ld a, [hl]
  172. ; The Master Ball always succeeds.
  173. cp MASTER_BALL
  174. jp z, .captured
  175. ; Anything will do for the basic Poké Ball.
  176. cp POKE_BALL
  177. jr z, .checkForAilments
  178. ; If it's a Great/Ultra/Safari Ball and Rand1 is greater than 200, try again.
  179. ld a, 200
  180. cp b
  181. jr c, .loop
  182. ; Less than or equal to 200 is good enough for a Great Ball.
  183. ld a, [hl]
  184. cp GREAT_BALL
  185. jr z, .checkForAilments
  186. ; If it's an Ultra/Safari Ball and Rand1 is greater than 150, try again.
  187. ld a, 150
  188. cp b
  189. jr c, .loop
  190. .checkForAilments
  191. ; Pokémon can be caught more easily with a status ailment.
  192. ; Depending on the status ailment, a certain value will be subtracted from
  193. ; Rand1. Let this value be called Status.
  194. ; The larger Status is, the more easily the Pokémon can be caught.
  195. ; no status ailment: Status = 0
  196. ; Burn/Paralysis/Poison: Status = 12
  197. ; Freeze/Sleep: Status = 25
  198. ; If Status is greater than Rand1, the Pokémon will be caught for sure.
  199. ld a, [wEnemyMonStatus]
  200. and a
  201. jr z, .skipAilmentValueSubtraction ; no ailments
  202. and 1 << FRZ | SLP
  203. ld c, 12
  204. jr z, .notFrozenOrAsleep
  205. ld c, 25
  206. .notFrozenOrAsleep
  207. ld a, b
  208. sub c
  209. jp c, .captured
  210. ld b, a
  211. .skipAilmentValueSubtraction
  212. push bc ; save (Rand1 - Status)
  213. ; Calculate MaxHP * 255.
  214. xor a
  215. ld [H_MULTIPLICAND], a
  216. ld hl, wEnemyMonMaxHP
  217. ld a, [hli]
  218. ld [H_MULTIPLICAND + 1], a
  219. ld a, [hl]
  220. ld [H_MULTIPLICAND + 2], a
  221. ld a, 255
  222. ld [H_MULTIPLIER], a
  223. call Multiply
  224. ; Determine BallFactor. It's 8 for Great Balls and 12 for the others.
  225. ld a, [wcf91]
  226. cp GREAT_BALL
  227. ld a, 12
  228. jr nz, .skip1
  229. ld a, 8
  230. .skip1
  231. ; Note that the results of all division operations are floored.
  232. ; Calculate (MaxHP * 255) / BallFactor.
  233. ld [H_DIVISOR], a
  234. ld b, 4 ; number of bytes in dividend
  235. call Divide
  236. ; Divide the enemy's current HP by 4. HP is not supposed to exceed 999 so
  237. ; the result should fit in a. If the division results in a quotient of 0,
  238. ; change it to 1.
  239. ld hl, wEnemyMonHP
  240. ld a, [hli]
  241. ld b, a
  242. ld a, [hl]
  243. srl b
  244. rr a
  245. srl b
  246. rr a
  247. and a
  248. jr nz, .skip2
  249. inc a
  250. .skip2
  251. ; Let W = ((MaxHP * 255) / BallFactor) / max(HP / 4, 1). Calculate W.
  252. ld [H_DIVISOR], a
  253. ld b, 4
  254. call Divide
  255. ; If W > 255, store 255 in [H_QUOTIENT + 3].
  256. ; Let X = min(W, 255) = [H_QUOTIENT + 3].
  257. ld a, [H_QUOTIENT + 2]
  258. and a
  259. jr z, .skip3
  260. ld a, 255
  261. ld [H_QUOTIENT + 3], a
  262. .skip3
  263. pop bc ; b = Rand1 - Status
  264. ; If Rand1 - Status > CatchRate, the ball fails to capture the Pokémon.
  265. ld a, [wEnemyMonActualCatchRate]
  266. cp b
  267. jr c, .failedToCapture
  268. ; If W > 255, the ball captures the Pokémon.
  269. ld a, [H_QUOTIENT + 2]
  270. and a
  271. jr nz, .captured
  272. call Random ; Let this random number be called Rand2.
  273. ; If Rand2 > X, the ball fails to capture the Pokémon.
  274. ld b, a
  275. ld a, [H_QUOTIENT + 3]
  276. cp b
  277. jr c, .failedToCapture
  278. .captured
  279. jr .skipShakeCalculations
  280. .failedToCapture
  281. ld a, [H_QUOTIENT + 3]
  282. ld [wPokeBallCaptureCalcTemp], a ; Save X.
  283. ; Calculate CatchRate * 100.
  284. xor a
  285. ld [H_MULTIPLICAND], a
  286. ld [H_MULTIPLICAND + 1], a
  287. ld a, [wEnemyMonActualCatchRate]
  288. ld [H_MULTIPLICAND + 2], a
  289. ld a, 100
  290. ld [H_MULTIPLIER], a
  291. call Multiply
  292. ; Determine BallFactor2.
  293. ; Poké Ball: BallFactor2 = 255
  294. ; Great Ball: BallFactor2 = 200
  295. ; Ultra/Safari Ball: BallFactor2 = 150
  296. ld a, [wcf91]
  297. ld b, 255
  298. cp POKE_BALL
  299. jr z, .skip4
  300. ld b, 200
  301. cp GREAT_BALL
  302. jr z, .skip4
  303. ld b, 150
  304. cp ULTRA_BALL
  305. jr z, .skip4
  306. .skip4
  307. ; Let Y = (CatchRate * 100) / BallFactor2. Calculate Y.
  308. ld a, b
  309. ld [H_DIVISOR], a
  310. ld b, 4
  311. call Divide
  312. ; If Y > 255, there are 3 shakes.
  313. ; Note that this shouldn't be possible.
  314. ; The maximum value of Y is (255 * 100) / 150 = 170.
  315. ld a, [H_QUOTIENT + 2]
  316. and a
  317. ld b, $63 ; 3 shakes
  318. jr nz, .setAnimData
  319. ; Calculate X * Y.
  320. ld a, [wPokeBallCaptureCalcTemp]
  321. ld [H_MULTIPLIER], a
  322. call Multiply
  323. ; Calculate (X * Y) / 255.
  324. ld a, 255
  325. ld [H_DIVISOR], a
  326. ld b, 4
  327. call Divide
  328. ; Determine Status2.
  329. ; no status ailment: Status2 = 0
  330. ; Burn/Paralysis/Poison: Status2 = 5
  331. ; Freeze/Sleep: Status2 = 10
  332. ld a, [wEnemyMonStatus]
  333. and a
  334. jr z, .skip5
  335. and 1 << FRZ | SLP
  336. ld b, 5
  337. jr z, .addAilmentValue
  338. ld b, 10
  339. .addAilmentValue
  340. ; If the Pokémon has a status ailment, add Status2.
  341. ld a, [H_QUOTIENT + 3]
  342. add b
  343. ld [H_QUOTIENT + 3], a
  344. .skip5
  345. ; Finally determine the number of shakes.
  346. ; Let Z = ((X * Y) / 255) + Status2 = [H_QUOTIENT + 3].
  347. ; The number of shakes depend on the range Z is in.
  348. ; 0 ≤ Z < 10: 0 shakes (the ball misses)
  349. ; 10 ≤ Z < 30: 1 shake
  350. ; 30 ≤ Z < 70: 2 shakes
  351. ; 70 ≤ Z: 3 shakes
  352. ld a, [H_QUOTIENT + 3]
  353. cp 10
  354. ld b, $20
  355. jr c, .setAnimData
  356. cp 30
  357. ld b, $61
  358. jr c, .setAnimData
  359. cp 70
  360. ld b, $62
  361. jr c, .setAnimData
  362. ld b, $63
  363. .setAnimData
  364. ld a, b
  365. ld [wPokeBallAnimData], a
  366. .skipShakeCalculations
  367. ld c, 20
  368. call DelayFrames
  369. ; Do the animation.
  370. ld a, TOSS_ANIM
  371. ld [wAnimationID], a
  372. xor a
  373. ld [H_WHOSETURN], a
  374. ld [wAnimationType], a
  375. ld [wDamageMultipliers], a
  376. ld a, [wWhichPokemon]
  377. push af
  378. ld a, [wcf91]
  379. push af
  380. predef MoveAnimation
  381. pop af
  382. ld [wcf91], a
  383. pop af
  384. ld [wWhichPokemon], a
  385. ; Determine the message to display from the animation.
  386. ld a, [wPokeBallAnimData]
  387. cp $10
  388. ld hl, ItemUseBallText00
  389. jp z, .printMessage
  390. cp $20
  391. ld hl, ItemUseBallText01
  392. jp z, .printMessage
  393. cp $61
  394. ld hl, ItemUseBallText02
  395. jp z, .printMessage
  396. cp $62
  397. ld hl, ItemUseBallText03
  398. jp z, .printMessage
  399. cp $63
  400. ld hl, ItemUseBallText04
  401. jp z, .printMessage
  402. ; Save current HP.
  403. ld hl, wEnemyMonHP
  404. ld a, [hli]
  405. push af
  406. ld a, [hli]
  407. push af
  408. ; Save status ailment.
  409. inc hl
  410. ld a, [hl]
  411. push af
  412. push hl
  413. ; If the Pokémon is transformed, the Pokémon is assumed to be a Ditto.
  414. ; This is a bug because a wild Pokémon could have used Transform via
  415. ; Mirror Move even though the only wild Pokémon that knows Transform is Ditto.
  416. ld hl, wEnemyBattleStatus3
  417. bit TRANSFORMED, [hl]
  418. jr z, .notTransformed
  419. ld a, DITTO
  420. ld [wEnemyMonSpecies2], a
  421. jr .skip6
  422. .notTransformed
  423. ; If the Pokémon is not transformed, set the transformed bit and copy the
  424. ; DVs to wTransformedEnemyMonOriginalDVs so that LoadEnemyMonData won't generate
  425. ; new DVs.
  426. set TRANSFORMED, [hl]
  427. ld hl, wTransformedEnemyMonOriginalDVs
  428. ld a, [wEnemyMonDVs]
  429. ld [hli], a
  430. ld a, [wEnemyMonDVs + 1]
  431. ld [hl], a
  432. .skip6
  433. ld a, [wcf91]
  434. push af
  435. ld a, [wEnemyMonSpecies2]
  436. ld [wcf91], a
  437. ld a, [wEnemyMonLevel]
  438. ld [wCurEnemyLVL], a
  439. callab LoadEnemyMonData
  440. pop af
  441. ld [wcf91], a
  442. pop hl
  443. pop af
  444. ld [hld], a
  445. dec hl
  446. pop af
  447. ld [hld], a
  448. pop af
  449. ld [hl], a
  450. ld a, [wEnemyMonSpecies]
  451. ld [wCapturedMonSpecies], a
  452. ld [wcf91], a
  453. ld [wd11e], a
  454. ld a, [wBattleType]
  455. dec a ; is this the old man battle?
  456. jr z, .oldManCaughtMon ; if so, don't give the player the caught Pokémon
  457. ld hl, ItemUseBallText05
  458. call PrintText
  459. ; Add the caught Pokémon to the Pokédex.
  460. predef IndexToPokedex
  461. ld a, [wd11e]
  462. dec a
  463. ld c, a
  464. ld b, FLAG_TEST
  465. ld hl, wPokedexOwned
  466. predef FlagActionPredef
  467. ld a, c
  468. push af
  469. ld a, [wd11e]
  470. dec a
  471. ld c, a
  472. ld b, FLAG_SET
  473. predef FlagActionPredef
  474. pop af
  475. and a ; was the Pokémon already in the Pokédex?
  476. jr nz, .skipShowingPokedexData ; if so, don't show the Pokédex data
  477. ld hl, ItemUseBallText06
  478. call PrintText
  479. call ClearSprites
  480. ld a, [wEnemyMonSpecies]
  481. ld [wd11e], a
  482. predef ShowPokedexData
  483. .skipShowingPokedexData
  484. ld a, [wPartyCount]
  485. cp PARTY_LENGTH ; is party full?
  486. jr z, .sendToBox
  487. xor a ; PLAYER_PARTY_DATA
  488. ld [wMonDataLocation], a
  489. call ClearSprites
  490. call AddPartyMon
  491. jr .done
  492. .sendToBox
  493. call ClearSprites
  494. call SendNewMonToBox
  495. ld hl, ItemUseBallText07
  496. CheckEvent EVENT_MET_BILL
  497. jr nz, .printTransferredToPCText
  498. ld hl, ItemUseBallText08
  499. .printTransferredToPCText
  500. call PrintText
  501. jr .done
  502. .oldManCaughtMon
  503. ld hl, ItemUseBallText05
  504. .printMessage
  505. call PrintText
  506. call ClearSprites
  507. .done
  508. ld a, [wBattleType]
  509. and a ; is this the old man battle?
  510. ret nz ; if so, don't remove a ball from the bag
  511. ; Remove a ball from the bag.
  512. ld hl, wNumBagItems
  513. inc a
  514. ld [wItemQuantity], a
  515. jp RemoveItemFromInventory
  516. ItemUseBallText00:
  517. ;"It dodged the thrown ball!"
  518. ;"This pokemon can't be caught"
  519. TX_FAR _ItemUseBallText00
  520. db "@"
  521. ItemUseBallText01:
  522. ;"You missed the pokemon!"
  523. TX_FAR _ItemUseBallText01
  524. db "@"
  525. ItemUseBallText02:
  526. ;"Darn! The pokemon broke free!"
  527. TX_FAR _ItemUseBallText02
  528. db "@"
  529. ItemUseBallText03:
  530. ;"Aww! It appeared to be caught!"
  531. TX_FAR _ItemUseBallText03
  532. db "@"
  533. ItemUseBallText04:
  534. ;"Shoot! It was so close too!"
  535. TX_FAR _ItemUseBallText04
  536. db "@"
  537. ItemUseBallText05:
  538. ;"All right! {MonName} was caught!"
  539. ;play sound
  540. TX_FAR _ItemUseBallText05
  541. TX_SFX_CAUGHT_MON
  542. TX_BLINK
  543. db "@"
  544. ItemUseBallText07:
  545. ;"X was transferred to Bill's PC"
  546. TX_FAR _ItemUseBallText07
  547. db "@"
  548. ItemUseBallText08:
  549. ;"X was transferred to someone's PC"
  550. TX_FAR _ItemUseBallText08
  551. db "@"
  552. ItemUseBallText06:
  553. ;"New DEX data will be added..."
  554. ;play sound
  555. TX_FAR _ItemUseBallText06
  556. TX_SFX_DEX_PAGE_ADDED
  557. TX_BLINK
  558. db "@"
  559. ItemUseTownMap:
  560. ld a, [wIsInBattle]
  561. and a
  562. jp nz, ItemUseNotTime
  563. jpba DisplayTownMap
  564. ItemUseBicycle:
  565. ld a, [wIsInBattle]
  566. and a
  567. jp nz, ItemUseNotTime
  568. ld a, [wWalkBikeSurfState]
  569. ld [wWalkBikeSurfStateCopy], a
  570. cp 2 ; is the player surfing?
  571. jp z, ItemUseNotTime
  572. dec a ; is player already bicycling?
  573. jr nz, .tryToGetOnBike
  574. .getOffBike
  575. call ItemUseReloadOverworldData
  576. xor a
  577. ld [wWalkBikeSurfState], a ; change player state to walking
  578. call PlayDefaultMusic ; play walking music
  579. ld hl, GotOffBicycleText
  580. jr .printText
  581. .tryToGetOnBike
  582. call IsBikeRidingAllowed
  583. jp nc, NoCyclingAllowedHere
  584. call ItemUseReloadOverworldData
  585. xor a ; no keys pressed
  586. ld [hJoyHeld], a ; current joypad state
  587. inc a
  588. ld [wWalkBikeSurfState], a ; change player state to bicycling
  589. ld hl, GotOnBicycleText
  590. call PlayDefaultMusic ; play bike riding music
  591. .printText
  592. jp PrintText
  593. ; used for Surf out-of-battle effect
  594. ItemUseSurfboard:
  595. ld a, [wWalkBikeSurfState]
  596. ld [wWalkBikeSurfStateCopy], a
  597. cp 2 ; is the player already surfing?
  598. jr z, .tryToStopSurfing
  599. .tryToSurf
  600. call IsNextTileShoreOrWater
  601. jp c, SurfingAttemptFailed
  602. ld hl, TilePairCollisionsWater
  603. call CheckForTilePairCollisions
  604. jp c, SurfingAttemptFailed
  605. .surf
  606. call .makePlayerMoveForward
  607. ld hl, wd730
  608. set 7, [hl]
  609. ld a, 2
  610. ld [wWalkBikeSurfState], a ; change player state to surfing
  611. call PlayDefaultMusic ; play surfing music
  612. ld hl, SurfingGotOnText
  613. jp PrintText
  614. .tryToStopSurfing
  615. xor a
  616. ld [hSpriteIndexOrTextID], a
  617. ld d, 16 ; talking range in pixels (normal range)
  618. call IsSpriteInFrontOfPlayer2
  619. res 7, [hl]
  620. ld a, [hSpriteIndexOrTextID]
  621. and a ; is there a sprite in the way?
  622. jr nz, .cannotStopSurfing
  623. ld hl, TilePairCollisionsWater
  624. call CheckForTilePairCollisions
  625. jr c, .cannotStopSurfing
  626. ld hl, wTilesetCollisionPtr ; pointer to list of passable tiles
  627. ld a, [hli]
  628. ld h, [hl]
  629. ld l, a ; hl now points to passable tiles
  630. ld a, [wTileInFrontOfPlayer] ; tile in front of the player
  631. ld b, a
  632. .passableTileLoop
  633. ld a, [hli]
  634. cp b
  635. jr z, .stopSurfing
  636. cp $ff
  637. jr nz, .passableTileLoop
  638. .cannotStopSurfing
  639. ld hl, SurfingNoPlaceToGetOffText
  640. jp PrintText
  641. .stopSurfing
  642. call .makePlayerMoveForward
  643. ld hl, wd730
  644. set 7, [hl]
  645. xor a
  646. ld [wWalkBikeSurfState], a ; change player state to walking
  647. dec a
  648. ld [wJoyIgnore], a
  649. call PlayDefaultMusic ; play walking music
  650. jp LoadWalkingPlayerSpriteGraphics
  651. ; uses a simulated button press to make the player move forward
  652. .makePlayerMoveForward
  653. ld a, [wPlayerDirection] ; direction the player is going
  654. bit PLAYER_DIR_BIT_UP, a
  655. ld b, D_UP
  656. jr nz, .storeSimulatedButtonPress
  657. bit PLAYER_DIR_BIT_DOWN, a
  658. ld b, D_DOWN
  659. jr nz, .storeSimulatedButtonPress
  660. bit PLAYER_DIR_BIT_LEFT, a
  661. ld b, D_LEFT
  662. jr nz, .storeSimulatedButtonPress
  663. ld b, D_RIGHT
  664. .storeSimulatedButtonPress
  665. ld a, b
  666. ld [wSimulatedJoypadStatesEnd], a
  667. xor a
  668. ld [wWastedByteCD39], a
  669. inc a
  670. ld [wSimulatedJoypadStatesIndex], a
  671. ret
  672. SurfingGotOnText:
  673. TX_FAR _SurfingGotOnText
  674. db "@"
  675. SurfingNoPlaceToGetOffText:
  676. TX_FAR _SurfingNoPlaceToGetOffText
  677. db "@"
  678. ItemUsePokedex:
  679. predef_jump ShowPokedexMenu
  680. ItemUseEvoStone:
  681. ld a, [wIsInBattle]
  682. and a
  683. jp nz, ItemUseNotTime
  684. ld a, [wWhichPokemon]
  685. push af
  686. ld a, [wcf91]
  687. ld [wEvoStoneItemID], a
  688. push af
  689. ld a, EVO_STONE_PARTY_MENU
  690. ld [wPartyMenuTypeOrMessageID], a
  691. ld a, $ff
  692. ld [wUpdateSpritesEnabled], a
  693. call DisplayPartyMenu
  694. pop bc
  695. jr c, .canceledItemUse
  696. ld a, b
  697. ld [wcf91], a
  698. ld a, $01
  699. ld [wForceEvolution], a
  700. ld a, SFX_HEAL_AILMENT
  701. call PlaySoundWaitForCurrent
  702. call WaitForSoundToFinish
  703. callab TryEvolvingMon ; try to evolve pokemon
  704. ld a, [wEvolutionOccurred]
  705. and a
  706. jr z, .noEffect
  707. pop af
  708. ld [wWhichPokemon], a
  709. ld hl, wNumBagItems
  710. ld a, 1 ; remove 1 stone
  711. ld [wItemQuantity], a
  712. jp RemoveItemFromInventory
  713. .noEffect
  714. call ItemUseNoEffect
  715. .canceledItemUse
  716. xor a
  717. ld [wActionResultOrTookBattleTurn], a ; item not used
  718. pop af
  719. ret
  720. ItemUseVitamin:
  721. ld a, [wIsInBattle]
  722. and a
  723. jp nz, ItemUseNotTime
  724. ItemUseMedicine:
  725. ld a, [wPartyCount]
  726. and a
  727. jp z, .emptyParty
  728. ld a, [wWhichPokemon]
  729. push af
  730. ld a, [wcf91]
  731. push af
  732. ld a, USE_ITEM_PARTY_MENU
  733. ld [wPartyMenuTypeOrMessageID], a
  734. ld a, $ff
  735. ld [wUpdateSpritesEnabled], a
  736. ld a, [wPseudoItemID]
  737. and a ; using Softboiled?
  738. jr z, .notUsingSoftboiled
  739. ; if using softboiled
  740. call GoBackToPartyMenu
  741. jr .getPartyMonDataAddress
  742. .emptyParty
  743. ld hl, .emptyPartyText
  744. xor a
  745. ld [wActionResultOrTookBattleTurn], a ; item use failed
  746. jp PrintText
  747. .emptyPartyText
  748. text "You don't have"
  749. line "any #MON!"
  750. prompt
  751. .notUsingSoftboiled
  752. call DisplayPartyMenu
  753. .getPartyMonDataAddress
  754. jp c, .canceledItemUse
  755. ld hl, wPartyMons
  756. ld bc, wPartyMon2 - wPartyMon1
  757. ld a, [wWhichPokemon]
  758. call AddNTimes
  759. ld a, [wWhichPokemon]
  760. ld [wUsedItemOnWhichPokemon], a
  761. ld d, a
  762. ld a, [wcf91]
  763. ld e, a
  764. ld [wd0b5], a
  765. pop af
  766. ld [wcf91], a
  767. pop af
  768. ld [wWhichPokemon], a
  769. ld a, [wPseudoItemID]
  770. and a ; using Softboiled?
  771. jr z, .checkItemType
  772. ; if using softboiled
  773. ld a, [wWhichPokemon]
  774. cp d ; is the pokemon trying to use softboiled on itself?
  775. jr z, ItemUseMedicine ; if so, force another choice
  776. .checkItemType
  777. ld a, [wcf91]
  778. cp REVIVE
  779. jr nc, .healHP ; if it's a Revive or Max Revive
  780. cp FULL_HEAL
  781. jr z, .cureStatusAilment ; if it's a Full Heal
  782. cp HP_UP
  783. jp nc, .useVitamin ; if it's a vitamin or Rare Candy
  784. cp FULL_RESTORE
  785. jr nc, .healHP ; if it's a Full Restore or one of the potions
  786. ; fall through if it's one of the status-specific healing items
  787. .cureStatusAilment
  788. ld bc, wPartyMon1Status - wPartyMon1
  789. add hl, bc ; hl now points to status
  790. ld a, [wcf91]
  791. lb bc, ANTIDOTE_MSG, 1 << PSN
  792. cp ANTIDOTE
  793. jr z, .checkMonStatus
  794. lb bc, BURN_HEAL_MSG, 1 << BRN
  795. cp BURN_HEAL
  796. jr z, .checkMonStatus
  797. lb bc, ICE_HEAL_MSG, 1 << FRZ
  798. cp ICE_HEAL
  799. jr z, .checkMonStatus
  800. lb bc, AWAKENING_MSG, SLP
  801. cp AWAKENING
  802. jr z, .checkMonStatus
  803. lb bc, PARALYZ_HEAL_MSG, 1 << PAR
  804. cp PARLYZ_HEAL
  805. jr z, .checkMonStatus
  806. lb bc, FULL_HEAL_MSG, $ff ; Full Heal
  807. .checkMonStatus
  808. ld a, [hl] ; pokemon's status
  809. and c ; does the pokemon have a status ailment the item can cure?
  810. jp z, .healingItemNoEffect
  811. ; if the pokemon has a status the item can heal
  812. xor a
  813. ld [hl], a ; remove the status ailment in the party data
  814. ld a, b
  815. ld [wPartyMenuTypeOrMessageID], a ; the message to display for the item used
  816. ld a, [wPlayerMonNumber]
  817. cp d ; is pokemon the item was used on active in battle?
  818. jp nz, .doneHealing
  819. ; if it is active in battle
  820. xor a
  821. ld [wBattleMonStatus], a ; remove the status ailment in the in-battle pokemon data
  822. push hl
  823. ld hl, wPlayerBattleStatus3
  824. res BADLY_POISONED, [hl] ; heal Toxic status
  825. pop hl
  826. ld bc, wPartyMon1Stats - wPartyMon1Status
  827. add hl, bc ; hl now points to party stats
  828. ld de, wBattleMonStats
  829. ld bc, NUM_STATS * 2
  830. call CopyData ; copy party stats to in-battle stat data
  831. predef DoubleOrHalveSelectedStats
  832. jp .doneHealing
  833. .healHP
  834. inc hl ; hl = address of current HP
  835. ld a, [hli]
  836. ld b, a
  837. ld [wHPBarOldHP+1], a
  838. ld a, [hl]
  839. ld c, a
  840. ld [wHPBarOldHP], a ; current HP stored at wHPBarOldHP (2 bytes, big-endian)
  841. or b
  842. jr nz, .notFainted
  843. .fainted
  844. ld a, [wcf91]
  845. cp REVIVE
  846. jr z, .updateInBattleFaintedData
  847. cp MAX_REVIVE
  848. jr z, .updateInBattleFaintedData
  849. jp .healingItemNoEffect
  850. .updateInBattleFaintedData
  851. ld a, [wIsInBattle]
  852. and a
  853. jr z, .compareCurrentHPToMaxHP
  854. push hl
  855. push de
  856. push bc
  857. ld a, [wUsedItemOnWhichPokemon]
  858. ld c, a
  859. ld hl, wPartyFoughtCurrentEnemyFlags
  860. ld b, FLAG_TEST
  861. predef FlagActionPredef
  862. ld a, c
  863. and a
  864. jr z, .next
  865. ld a, [wUsedItemOnWhichPokemon]
  866. ld c, a
  867. ld hl, wPartyGainExpFlags
  868. ld b, FLAG_SET
  869. predef FlagActionPredef
  870. .next
  871. pop bc
  872. pop de
  873. pop hl
  874. jr .compareCurrentHPToMaxHP
  875. .notFainted
  876. ld a, [wcf91]
  877. cp REVIVE
  878. jp z, .healingItemNoEffect
  879. cp MAX_REVIVE
  880. jp z, .healingItemNoEffect
  881. .compareCurrentHPToMaxHP
  882. push hl
  883. push bc
  884. ld bc, wPartyMon1MaxHP - (wPartyMon1HP + 1)
  885. add hl, bc ; hl now points to max HP
  886. pop bc
  887. ld a, [hli]
  888. cp b
  889. jr nz, .skipComparingLSB ; no need to compare the LSB's if the MSB's don't match
  890. ld a, [hl]
  891. cp c
  892. .skipComparingLSB
  893. pop hl
  894. jr nz, .notFullHP
  895. .fullHP ; if the pokemon's current HP equals its max HP
  896. ld a, [wcf91]
  897. cp FULL_RESTORE
  898. jp nz, .healingItemNoEffect
  899. inc hl
  900. inc hl
  901. ld a, [hld] ; status ailment
  902. and a ; does the pokemon have a status ailment?
  903. jp z, .healingItemNoEffect
  904. ld a, FULL_HEAL
  905. ld [wcf91], a
  906. dec hl
  907. dec hl
  908. dec hl
  909. jp .cureStatusAilment
  910. .notFullHP ; if the pokemon's current HP doesn't equal its max HP
  911. xor a
  912. ld [wLowHealthAlarm], a ;disable low health alarm
  913. ld [wChannelSoundIDs + Ch4], a
  914. push hl
  915. push de
  916. ld bc, wPartyMon1MaxHP - (wPartyMon1HP + 1)
  917. add hl, bc ; hl now points to max HP
  918. ld a, [hli]
  919. ld [wHPBarMaxHP+1], a
  920. ld a, [hl]
  921. ld [wHPBarMaxHP], a ; max HP stored at wHPBarMaxHP (2 bytes, big-endian)
  922. ld a, [wPseudoItemID]
  923. and a ; using Softboiled?
  924. jp z, .notUsingSoftboiled2
  925. ; if using softboiled
  926. ld hl, wHPBarMaxHP
  927. ld a, [hli]
  928. push af
  929. ld a, [hli]
  930. push af
  931. ld a, [hli]
  932. push af
  933. ld a, [hl]
  934. push af
  935. ld hl, wPartyMon1MaxHP
  936. ld a, [wWhichPokemon]
  937. ld bc, wPartyMon2 - wPartyMon1
  938. call AddNTimes
  939. ld a, [hli]
  940. ld [wHPBarMaxHP + 1], a
  941. ld [H_DIVIDEND], a
  942. ld a, [hl]
  943. ld [wHPBarMaxHP], a
  944. ld [H_DIVIDEND + 1], a
  945. ld a, 5
  946. ld [H_DIVISOR], a
  947. ld b, 2 ; number of bytes
  948. call Divide ; get 1/5 of max HP of pokemon that used Softboiled
  949. ld bc, (wPartyMon1HP + 1) - (wPartyMon1MaxHP + 1)
  950. add hl, bc ; hl now points to LSB of current HP of pokemon that used Softboiled
  951. ; subtract 1/5 of max HP from current HP of pokemon that used Softboiled
  952. ld a, [H_QUOTIENT + 3]
  953. push af
  954. ld b, a
  955. ld a, [hl]
  956. ld [wHPBarOldHP], a
  957. sub b
  958. ld [hld], a
  959. ld [wHPBarNewHP], a
  960. ld a, [H_QUOTIENT + 2]
  961. ld b, a
  962. ld a, [hl]
  963. ld [wHPBarOldHP+1], a
  964. sbc b
  965. ld [hl], a
  966. ld [wHPBarNewHP+1], a
  967. coord hl, 4, 1
  968. ld a, [wWhichPokemon]
  969. ld bc, 2 * SCREEN_WIDTH
  970. call AddNTimes ; calculate coordinates of HP bar of pokemon that used Softboiled
  971. ld a, SFX_HEAL_HP
  972. call PlaySoundWaitForCurrent
  973. ld a, [hFlags_0xFFF6]
  974. set 0, a
  975. ld [hFlags_0xFFF6], a
  976. ld a, $02
  977. ld [wHPBarType], a
  978. predef UpdateHPBar2 ; animate HP bar decrease of pokemon that used Softboiled
  979. ld a, [hFlags_0xFFF6]
  980. res 0, a
  981. ld [hFlags_0xFFF6], a
  982. pop af
  983. ld b, a ; store heal amount (1/5 of max HP)
  984. ld hl, wHPBarOldHP + 1
  985. pop af
  986. ld [hld], a
  987. pop af
  988. ld [hld], a
  989. pop af
  990. ld [hld], a
  991. pop af
  992. ld [hl], a
  993. jr .addHealAmount
  994. .notUsingSoftboiled2
  995. ld a, [wcf91]
  996. cp SODA_POP
  997. ld b, 60 ; Soda Pop heal amount
  998. jr z, .addHealAmount
  999. ld b, 80 ; Lemonade heal amount
  1000. jr nc, .addHealAmount
  1001. cp FRESH_WATER
  1002. ld b, 50 ; Fresh Water heal amount
  1003. jr z, .addHealAmount
  1004. cp SUPER_POTION
  1005. ld b, 200 ; Hyper Potion heal amount
  1006. jr c, .addHealAmount
  1007. ld b, 50 ; Super Potion heal amount
  1008. jr z, .addHealAmount
  1009. ld b, 20 ; Potion heal amount
  1010. .addHealAmount
  1011. pop de
  1012. pop hl
  1013. ld a, [hl]
  1014. add b
  1015. ld [hld], a
  1016. ld [wHPBarNewHP], a
  1017. ld a, [hl]
  1018. ld [wHPBarNewHP+1], a
  1019. jr nc, .noCarry
  1020. inc [hl]
  1021. ld a, [hl]
  1022. ld [wHPBarNewHP + 1], a
  1023. .noCarry
  1024. push de
  1025. inc hl
  1026. ld d, h
  1027. ld e, l ; de now points to current HP
  1028. ld hl, (wPartyMon1MaxHP + 1) - (wPartyMon1HP + 1)
  1029. add hl, de ; hl now points to max HP
  1030. ld a, [wcf91]
  1031. cp REVIVE
  1032. jr z, .setCurrentHPToHalfMaxHP
  1033. ld a, [hld]
  1034. ld b, a
  1035. ld a, [de]
  1036. sub b
  1037. dec de
  1038. ld b, [hl]
  1039. ld a, [de]
  1040. sbc b
  1041. jr nc, .setCurrentHPToMaxHp ; if current HP exceeds max HP after healing
  1042. ld a, [wcf91]
  1043. cp HYPER_POTION
  1044. jr c, .setCurrentHPToMaxHp ; if using a Full Restore or Max Potion
  1045. cp MAX_REVIVE
  1046. jr z, .setCurrentHPToMaxHp ; if using a Max Revive
  1047. jr .updateInBattleData
  1048. .setCurrentHPToHalfMaxHP
  1049. dec hl
  1050. dec de
  1051. ld a, [hli]
  1052. srl a
  1053. ld [de], a
  1054. ld [wHPBarNewHP+1], a
  1055. ld a, [hl]
  1056. rr a
  1057. inc de
  1058. ld [de], a
  1059. ld [wHPBarNewHP], a
  1060. dec de
  1061. jr .doneHealingPartyHP
  1062. .setCurrentHPToMaxHp
  1063. ld a, [hli]
  1064. ld [de], a
  1065. ld [wHPBarNewHP+1], a
  1066. inc de
  1067. ld a, [hl]
  1068. ld [de], a
  1069. ld [wHPBarNewHP], a
  1070. dec de
  1071. .doneHealingPartyHP ; done updating the pokemon's current HP in the party data structure
  1072. ld a, [wcf91]
  1073. cp FULL_RESTORE
  1074. jr nz, .updateInBattleData
  1075. ld bc, wPartyMon1Status - (wPartyMon1MaxHP + 1)
  1076. add hl, bc
  1077. xor a
  1078. ld [hl], a ; remove the status ailment in the party data
  1079. .updateInBattleData
  1080. ld h, d
  1081. ld l, e
  1082. pop de
  1083. ld a, [wPlayerMonNumber]
  1084. cp d ; is pokemon the item was used on active in battle?
  1085. jr nz, .calculateHPBarCoords
  1086. ; copy party HP to in-battle HP
  1087. ld a, [hli]
  1088. ld [wBattleMonHP], a
  1089. ld a, [hld]
  1090. ld [wBattleMonHP + 1], a
  1091. ld a, [wcf91]
  1092. cp FULL_RESTORE
  1093. jr nz, .calculateHPBarCoords
  1094. xor a
  1095. ld [wBattleMonStatus], a ; remove the status ailment in the in-battle pokemon data
  1096. .calculateHPBarCoords
  1097. ld hl, wOAMBuffer + $90
  1098. ld bc, 2 * SCREEN_WIDTH
  1099. inc d
  1100. .calculateHPBarCoordsLoop
  1101. add hl, bc
  1102. dec d
  1103. jr nz, .calculateHPBarCoordsLoop
  1104. jr .doneHealing
  1105. .healingItemNoEffect
  1106. call ItemUseNoEffect
  1107. jp .done
  1108. .doneHealing
  1109. ld a, [wPseudoItemID]
  1110. and a ; using Softboiled?
  1111. jr nz, .skipRemovingItem ; no item to remove if using Softboiled
  1112. push hl
  1113. call RemoveUsedItem
  1114. pop hl
  1115. .skipRemovingItem
  1116. ld a, [wcf91]
  1117. cp FULL_RESTORE
  1118. jr c, .playStatusAilmentCuringSound
  1119. cp FULL_HEAL
  1120. jr z, .playStatusAilmentCuringSound
  1121. ld a, SFX_HEAL_HP
  1122. call PlaySoundWaitForCurrent
  1123. ld a, [hFlags_0xFFF6]
  1124. set 0, a
  1125. ld [hFlags_0xFFF6], a
  1126. ld a, $02
  1127. ld [wHPBarType], a
  1128. predef UpdateHPBar2 ; animate the HP bar lengthening
  1129. ld a, [hFlags_0xFFF6]
  1130. res 0, a
  1131. ld [hFlags_0xFFF6], a
  1132. ld a, REVIVE_MSG
  1133. ld [wPartyMenuTypeOrMessageID], a
  1134. ld a, [wcf91]
  1135. cp REVIVE
  1136. jr z, .showHealingItemMessage
  1137. cp MAX_REVIVE
  1138. jr z, .showHealingItemMessage
  1139. ld a, POTION_MSG
  1140. ld [wPartyMenuTypeOrMessageID], a
  1141. jr .showHealingItemMessage
  1142. .playStatusAilmentCuringSound
  1143. ld a, SFX_HEAL_AILMENT
  1144. call PlaySoundWaitForCurrent
  1145. .showHealingItemMessage
  1146. xor a
  1147. ld [H_AUTOBGTRANSFERENABLED], a
  1148. call ClearScreen
  1149. dec a
  1150. ld [wUpdateSpritesEnabled], a
  1151. call RedrawPartyMenu ; redraws the party menu and displays the message
  1152. ld a, 1
  1153. ld [H_AUTOBGTRANSFERENABLED], a
  1154. ld c, 50
  1155. call DelayFrames
  1156. call WaitForTextScrollButtonPress
  1157. jr .done
  1158. .canceledItemUse
  1159. xor a
  1160. ld [wActionResultOrTookBattleTurn], a ; item use failed
  1161. pop af
  1162. pop af
  1163. .done
  1164. ld a, [wPseudoItemID]
  1165. and a ; using Softboiled?
  1166. ret nz ; if so, return
  1167. call GBPalWhiteOut
  1168. call z, RunDefaultPaletteCommand
  1169. ld a, [wIsInBattle]
  1170. and a
  1171. ret nz
  1172. jp ReloadMapData
  1173. .useVitamin
  1174. push hl
  1175. ld a, [hl]
  1176. ld [wd0b5], a
  1177. ld [wd11e], a
  1178. ld bc, wPartyMon1Level - wPartyMon1
  1179. add hl, bc ; hl now points to level
  1180. ld a, [hl] ; a = level
  1181. ld [wCurEnemyLVL], a ; store level
  1182. call GetMonHeader
  1183. push de
  1184. ld a, d
  1185. ld hl, wPartyMonNicks
  1186. call GetPartyMonName
  1187. pop de
  1188. pop hl
  1189. ld a, [wcf91]
  1190. cp RARE_CANDY
  1191. jp z, .useRareCandy
  1192. push hl
  1193. sub HP_UP
  1194. add a
  1195. ld bc, wPartyMon1HPExp - wPartyMon1
  1196. add hl, bc
  1197. add l
  1198. ld l, a
  1199. jr nc, .noCarry2
  1200. inc h
  1201. .noCarry2
  1202. ld a, 10
  1203. ld b, a
  1204. ld a, [hl] ; a = MSB of stat experience of the appropriate stat
  1205. cp 100 ; is there already at least 25600 (256 * 100) stat experience?
  1206. jr nc, .vitaminNoEffect ; if so, vitamins can't add any more
  1207. add b ; add 2560 (256 * 10) stat experience
  1208. jr nc, .noCarry3 ; a carry should be impossible here, so this will always jump
  1209. ld a, 255
  1210. .noCarry3
  1211. ld [hl], a
  1212. pop hl
  1213. call .recalculateStats
  1214. ld hl, VitaminText
  1215. ld a, [wcf91]
  1216. sub HP_UP - 1
  1217. ld c, a
  1218. .statNameLoop ; loop to get the address of the name of the stat the vitamin increases
  1219. dec c
  1220. jr z, .gotStatName
  1221. .statNameInnerLoop
  1222. ld a, [hli]
  1223. ld b, a
  1224. ld a, $50
  1225. cp b
  1226. jr nz, .statNameInnerLoop
  1227. jr .statNameLoop
  1228. .gotStatName
  1229. ld de, wcf4b
  1230. ld bc, 10
  1231. call CopyData ; copy the stat's name to wcf4b
  1232. ld a, SFX_HEAL_AILMENT
  1233. call PlaySound
  1234. ld hl, VitaminStatRoseText
  1235. call PrintText
  1236. jp RemoveUsedItem
  1237. .vitaminNoEffect
  1238. pop hl
  1239. ld hl, VitaminNoEffectText
  1240. call PrintText
  1241. jp GBPalWhiteOut
  1242. .recalculateStats
  1243. ld bc, wPartyMon1Stats - wPartyMon1
  1244. add hl, bc
  1245. ld d, h
  1246. ld e, l ; de now points to stats
  1247. ld bc, (wPartyMon1Exp + 2) - wPartyMon1Stats
  1248. add hl, bc ; hl now points to LSB of experience
  1249. ld b, 1
  1250. jp CalcStats ; recalculate stats
  1251. .useRareCandy
  1252. push hl
  1253. ld bc, wPartyMon1Level - wPartyMon1
  1254. add hl, bc ; hl now points to level
  1255. ld a, [hl] ; a = level
  1256. cp MAX_LEVEL
  1257. jr z, .vitaminNoEffect ; can't raise level above 100
  1258. inc a
  1259. ld [hl], a ; store incremented level
  1260. ld [wCurEnemyLVL], a
  1261. push hl
  1262. push de
  1263. ld d, a
  1264. callab CalcExperience ; calculate experience for next level and store it at $ff96
  1265. pop de
  1266. pop hl
  1267. ld bc, wPartyMon1Exp - wPartyMon1Level
  1268. add hl, bc ; hl now points to MSB of experience
  1269. ; update experience to minimum for new level
  1270. ld a, [hExperience]
  1271. ld [hli], a
  1272. ld a, [hExperience + 1]
  1273. ld [hli], a
  1274. ld a, [hExperience + 2]
  1275. ld [hl], a
  1276. pop hl
  1277. ld a, [wWhichPokemon]
  1278. push af
  1279. ld a, [wcf91]
  1280. push af
  1281. push de
  1282. push hl
  1283. ld bc, wPartyMon1MaxHP - wPartyMon1
  1284. add hl, bc ; hl now points to MSB of max HP
  1285. ld a, [hli]
  1286. ld b, a
  1287. ld c, [hl]
  1288. pop hl
  1289. push bc
  1290. push hl
  1291. call .recalculateStats
  1292. pop hl
  1293. ld bc, (wPartyMon1MaxHP + 1) - wPartyMon1
  1294. add hl, bc ; hl now points to LSB of max HP
  1295. pop bc
  1296. ld a, [hld]
  1297. sub c
  1298. ld c, a
  1299. ld a, [hl]
  1300. sbc b
  1301. ld b, a ; bc = the amount of max HP gained from leveling up
  1302. ; add the amount gained to the current HP
  1303. ld de, (wPartyMon1HP + 1) - wPartyMon1MaxHP
  1304. add hl, de ; hl now points to LSB of current HP
  1305. ld a, [hl]
  1306. add c
  1307. ld [hld], a
  1308. ld a, [hl]
  1309. adc b
  1310. ld [hl], a
  1311. ld a, RARE_CANDY_MSG
  1312. ld [wPartyMenuTypeOrMessageID], a
  1313. call RedrawPartyMenu
  1314. pop de
  1315. ld a, d
  1316. ld [wWhichPokemon], a
  1317. ld a, e
  1318. ld [wd11e], a
  1319. xor a ; PLAYER_PARTY_DATA
  1320. ld [wMonDataLocation], a
  1321. call LoadMonData
  1322. ld d, $01
  1323. callab PrintStatsBox ; display new stats text box
  1324. call WaitForTextScrollButtonPress ; wait for button press
  1325. xor a ; PLAYER_PARTY_DATA
  1326. ld [wMonDataLocation], a
  1327. predef LearnMoveFromLevelUp ; learn level up move, if any
  1328. xor a
  1329. ld [wForceEvolution], a
  1330. callab TryEvolvingMon ; evolve pokemon, if appropriate
  1331. ld a, $01
  1332. ld [wUpdateSpritesEnabled], a
  1333. pop af
  1334. ld [wcf91], a
  1335. pop af
  1336. ld [wWhichPokemon], a
  1337. jp RemoveUsedItem
  1338. VitaminStatRoseText:
  1339. TX_FAR _VitaminStatRoseText
  1340. db "@"
  1341. VitaminNoEffectText:
  1342. TX_FAR _VitaminNoEffectText
  1343. db "@"
  1344. VitaminText:
  1345. db "HEALTH@"
  1346. db "ATTACK@"
  1347. db "DEFENSE@"
  1348. db "SPEED@"
  1349. db "SPECIAL@"
  1350. ItemUseBait:
  1351. ld hl, ThrewBaitText
  1352. call PrintText
  1353. ld hl, wEnemyMonActualCatchRate ; catch rate
  1354. srl [hl] ; halve catch rate
  1355. ld a, BAIT_ANIM
  1356. ld hl, wSafariBaitFactor ; bait factor
  1357. ld de, wSafariEscapeFactor ; escape factor
  1358. jr BaitRockCommon
  1359. ItemUseRock:
  1360. ld hl, ThrewRockText
  1361. call PrintText
  1362. ld hl, wEnemyMonActualCatchRate ; catch rate
  1363. ld a, [hl]
  1364. add a ; double catch rate
  1365. jr nc, .noCarry
  1366. ld a, $ff
  1367. .noCarry
  1368. ld [hl], a
  1369. ld a, ROCK_ANIM
  1370. ld hl, wSafariEscapeFactor ; escape factor
  1371. ld de, wSafariBaitFactor ; bait factor
  1372. BaitRockCommon:
  1373. ld [wAnimationID], a
  1374. xor a
  1375. ld [wAnimationType], a
  1376. ld [H_WHOSETURN], a
  1377. ld [de], a ; zero escape factor (for bait), zero bait factor (for rock)
  1378. .randomLoop ; loop until a random number less than 5 is generated
  1379. call Random
  1380. and 7
  1381. cp 5
  1382. jr nc, .randomLoop
  1383. inc a ; increment the random number, giving a range from 1 to 5 inclusive
  1384. ld b, a
  1385. ld a, [hl]
  1386. add b ; increase bait factor (for bait), increase escape factor (for rock)
  1387. jr nc, .noCarry
  1388. ld a, $ff
  1389. .noCarry
  1390. ld [hl], a
  1391. predef MoveAnimation ; do animation
  1392. ld c, 70
  1393. jp DelayFrames
  1394. ThrewBaitText:
  1395. TX_FAR _ThrewBaitText
  1396. db "@"
  1397. ThrewRockText:
  1398. TX_FAR _ThrewRockText
  1399. db "@"
  1400. ; also used for Dig out-of-battle effect
  1401. ItemUseEscapeRope:
  1402. ld a, [wIsInBattle]
  1403. and a
  1404. jr nz, .notUsable
  1405. ld a, [wCurMap]
  1406. cp AGATHAS_ROOM
  1407. jr z, .notUsable
  1408. ld a, [wCurMapTileset]
  1409. ld b, a
  1410. ld hl, EscapeRopeTilesets
  1411. .loop
  1412. ld a, [hli]
  1413. cp $ff
  1414. jr z, .notUsable
  1415. cp b
  1416. jr nz, .loop
  1417. ld hl, wd732
  1418. set 3, [hl]
  1419. set 6, [hl]
  1420. ld hl, wd72e
  1421. res 4, [hl]
  1422. ResetEvent EVENT_IN_SAFARI_ZONE
  1423. xor a
  1424. ld [wNumSafariBalls], a
  1425. ld [wSafariZoneEntranceCurScript], a
  1426. inc a
  1427. ld [wEscapedFromBattle], a
  1428. ld [wActionResultOrTookBattleTurn], a ; item used
  1429. ld a, [wPseudoItemID]
  1430. and a ; using Dig?
  1431. ret nz ; if so, return
  1432. call ItemUseReloadOverworldData
  1433. ld c, 30
  1434. call DelayFrames
  1435. jp RemoveUsedItem
  1436. .notUsable
  1437. jp ItemUseNotTime
  1438. EscapeRopeTilesets:
  1439. db FOREST, CEMETERY, CAVERN, FACILITY, INTERIOR
  1440. db $ff ; terminator
  1441. ItemUseRepel:
  1442. ld b, 100
  1443. ItemUseRepelCommon:
  1444. ld a, [wIsInBattle]
  1445. and a
  1446. jp nz, ItemUseNotTime
  1447. ld a, b
  1448. ld [wRepelRemainingSteps], a
  1449. jp PrintItemUseTextAndRemoveItem
  1450. ; handles X Accuracy item
  1451. ItemUseXAccuracy:
  1452. ld a, [wIsInBattle]
  1453. and a
  1454. jp z, ItemUseNotTime
  1455. ld hl, wPlayerBattleStatus2
  1456. set USING_X_ACCURACY, [hl] ; X Accuracy bit
  1457. jp PrintItemUseTextAndRemoveItem
  1458. ; This function is bugged and never works. It always jumps to ItemUseNotTime.
  1459. ; The Card Key is handled in a different way.
  1460. ItemUseCardKey:
  1461. xor a
  1462. ld [wUnusedD71F], a
  1463. call GetTileAndCoordsInFrontOfPlayer
  1464. ld a, [GetTileAndCoordsInFrontOfPlayer]
  1465. cp $18
  1466. jr nz, .next0
  1467. ld hl, CardKeyTable1
  1468. jr .next1
  1469. .next0
  1470. cp $24
  1471. jr nz, .next2
  1472. ld hl, CardKeyTable2
  1473. jr .next1
  1474. .next2
  1475. cp $5e
  1476. jp nz, ItemUseNotTime
  1477. ld hl, CardKeyTable3
  1478. .next1
  1479. ld a, [wCurMap]
  1480. ld b, a
  1481. .loop
  1482. ld a, [hli]
  1483. cp $ff
  1484. jp z, ItemUseNotTime
  1485. cp b
  1486. jr nz, .nextEntry1
  1487. ld a, [hli]
  1488. cp d
  1489. jr nz, .nextEntry2
  1490. ld a, [hli]
  1491. cp e
  1492. jr nz, .nextEntry3
  1493. ld a, [hl]
  1494. ld [wUnusedD71F], a
  1495. jr .done
  1496. .nextEntry1
  1497. inc hl
  1498. .nextEntry2
  1499. inc hl
  1500. .nextEntry3
  1501. inc hl
  1502. jr .loop
  1503. .done
  1504. ld hl, ItemUseText00
  1505. call PrintText
  1506. ld hl, wd728
  1507. set 7, [hl]
  1508. ret
  1509. ; These tables are probably supposed to be door locations in Silph Co.,
  1510. ; but they are unused.
  1511. ; The reason there are 3 tables is unknown.
  1512. ; Format:
  1513. ; 00: Map ID
  1514. ; 01: Y
  1515. ; 02: X
  1516. ; 03: ID?
  1517. CardKeyTable1:
  1518. db SILPH_CO_2F,$04,$04,$00
  1519. db SILPH_CO_2F,$04,$05,$01
  1520. db SILPH_CO_4F,$0C,$04,$02
  1521. db SILPH_CO_4F,$0C,$05,$03
  1522. db SILPH_CO_7F,$06,$0A,$04
  1523. db SILPH_CO_7F,$06,$0B,$05
  1524. db SILPH_CO_9F,$04,$12,$06
  1525. db SILPH_CO_9F,$04,$13,$07
  1526. db SILPH_CO_10F,$08,$0A,$08
  1527. db SILPH_CO_10F,$08,$0B,$09
  1528. db $ff
  1529. CardKeyTable2:
  1530. db SILPH_CO_3F,$08,$09,$0A
  1531. db SILPH_CO_3F,$09,$09,$0B
  1532. db SILPH_CO_5F,$04,$07,$0C
  1533. db SILPH_CO_5F,$05,$07,$0D
  1534. db SILPH_CO_6F,$0C,$05,$0E
  1535. db SILPH_CO_6F,$0D,$05,$0F
  1536. db SILPH_CO_8F,$08,$07,$10
  1537. db SILPH_CO_8F,$09,$07,$11
  1538. db SILPH_CO_9F,$08,$03,$12
  1539. db SILPH_CO_9F,$09,$03,$13
  1540. db $ff
  1541. CardKeyTable3:
  1542. db SILPH_CO_11F,$08,$09,$14
  1543. db SILPH_CO_11F,$09,$09,$15
  1544. db $ff
  1545. ItemUsePokedoll:
  1546. ld a, [wIsInBattle]
  1547. dec a
  1548. jp nz, ItemUseNotTime
  1549. ld a, $01
  1550. ld [wEscapedFromBattle], a
  1551. jp PrintItemUseTextAndRemoveItem
  1552. ItemUseGuardSpec:
  1553. ld a, [wIsInBattle]
  1554. and a
  1555. jp z, ItemUseNotTime
  1556. ld hl, wPlayerBattleStatus2
  1557. set PROTECTED_BY_MIST, [hl] ; Mist bit
  1558. jp PrintItemUseTextAndRemoveItem
  1559. ItemUseSuperRepel:
  1560. ld b, 200
  1561. jp ItemUseRepelCommon
  1562. ItemUseMaxRepel:
  1563. ld b, 250
  1564. jp ItemUseRepelCommon
  1565. ItemUseDireHit:
  1566. ld a, [wIsInBattle]
  1567. and a
  1568. jp z, ItemUseNotTime
  1569. ld hl, wPlayerBattleStatus2
  1570. set GETTING_PUMPED, [hl] ; Focus Energy bit
  1571. jp PrintItemUseTextAndRemoveItem
  1572. ItemUseXStat:
  1573. ld a, [wIsInBattle]
  1574. and a
  1575. jr nz, .inBattle
  1576. call ItemUseNotTime
  1577. ld a, 2
  1578. ld [wActionResultOrTookBattleTurn], a ; item not used
  1579. ret
  1580. .inBattle
  1581. ld hl, wPlayerMoveNum
  1582. ld a, [hli]
  1583. push af ; save [wPlayerMoveNum]
  1584. ld a, [hl]
  1585. push af ; save [wPlayerMoveEffect]
  1586. push hl
  1587. ld a, [wcf91]
  1588. sub X_ATTACK - ATTACK_UP1_EFFECT
  1589. ld [hl], a ; store player move effect
  1590. call PrintItemUseTextAndRemoveItem
  1591. ld a, XSTATITEM_ANIM ; X stat item animation ID
  1592. ld [wPlayerMoveNum], a
  1593. call LoadScreenTilesFromBuffer1 ; restore saved screen
  1594. call Delay3
  1595. xor a
  1596. ld [H_WHOSETURN], a ; set turn to player's turn
  1597. callba StatModifierUpEffect ; do stat increase move
  1598. pop hl
  1599. pop af
  1600. ld [hld], a ; restore [wPlayerMoveEffect]
  1601. pop af
  1602. ld [hl], a ; restore [wPlayerMoveNum]
  1603. ret
  1604. ItemUsePokeflute:
  1605. ld a, [wIsInBattle]
  1606. and a
  1607. jr nz, .inBattle
  1608. ; if not in battle
  1609. call ItemUseReloadOverworldData
  1610. ld a, [wCurMap]
  1611. cp ROUTE_12
  1612. jr nz, .notRoute12
  1613. CheckEvent EVENT_BEAT_ROUTE12_SNORLAX
  1614. jr nz, .noSnorlaxToWakeUp
  1615. ; if the player hasn't beaten Route 12 Snorlax
  1616. ld hl, Route12SnorlaxFluteCoords
  1617. call ArePlayerCoordsInArray
  1618. jr nc, .noSnorlaxToWakeUp
  1619. ld hl, PlayedFluteHadEffectText
  1620. call PrintText
  1621. SetEvent EVENT_FIGHT_ROUTE12_SNORLAX
  1622. ret
  1623. .notRoute12
  1624. cp ROUTE_16
  1625. jr nz, .noSnorlaxToWakeUp
  1626. CheckEvent EVENT_BEAT_ROUTE16_SNORLAX
  1627. jr nz, .noSnorlaxToWakeUp
  1628. ; if the player hasn't beaten Route 16 Snorlax
  1629. ld hl, Route16SnorlaxFluteCoords
  1630. call ArePlayerCoordsInArray
  1631. jr nc, .noSnorlaxToWakeUp
  1632. ld hl, PlayedFluteHadEffectText
  1633. call PrintText
  1634. SetEvent EVENT_FIGHT_ROUTE16_SNORLAX
  1635. ret
  1636. .noSnorlaxToWakeUp
  1637. ld hl, PlayedFluteNoEffectText
  1638. jp PrintText
  1639. .inBattle
  1640. xor a
  1641. ld [wWereAnyMonsAsleep], a
  1642. ld b, ~SLP & $ff
  1643. ld hl, wPartyMon1Status
  1644. call WakeUpEntireParty
  1645. ld a, [wIsInBattle]
  1646. dec a ; is it a trainer battle?
  1647. jr z, .skipWakingUpEnemyParty
  1648. ; if it's a trainer battle
  1649. ld hl, wEnemyMon1Status
  1650. call WakeUpEntireParty
  1651. .skipWakingUpEnemyParty
  1652. ld hl, wBattleMonStatus
  1653. ld a, [hl]
  1654. and b ; remove Sleep status
  1655. ld [hl], a
  1656. ld hl, wEnemyMonStatus
  1657. ld a, [hl]
  1658. and b ; remove Sleep status
  1659. ld [hl], a
  1660. call LoadScreenTilesFromBuffer2 ; restore saved screen
  1661. ld a, [wWereAnyMonsAsleep]
  1662. and a ; were any pokemon asleep before playing the flute?
  1663. ld hl, PlayedFluteNoEffectText
  1664. jp z, PrintText ; if no pokemon were asleep
  1665. ; if some pokemon were asleep
  1666. ld hl, PlayedFluteHadEffectText
  1667. call PrintText
  1668. ld a, [wLowHealthAlarm]
  1669. and $80
  1670. jr nz, .skipMusic
  1671. call WaitForSoundToFinish ; wait for sound to end
  1672. callba Music_PokeFluteInBattle ; play in-battle pokeflute music
  1673. .musicWaitLoop ; wait for music to finish playing
  1674. ld a, [wChannelSoundIDs + Ch6]
  1675. and a ; music off?
  1676. jr nz, .musicWaitLoop
  1677. .skipMusic
  1678. ld hl, FluteWokeUpText
  1679. jp PrintText
  1680. ; wakes up all party pokemon
  1681. ; INPUT:
  1682. ; hl must point to status of first pokemon in party (player's or enemy's)
  1683. ; b must equal ~SLP
  1684. ; [wWereAnyMonsAsleep] should be initialized to 0
  1685. ; OUTPUT:
  1686. ; [wWereAnyMonsAsleep]: set to 1 if any pokemon were asleep
  1687. WakeUpEntireParty:
  1688. ld de, 44
  1689. ld c, 6
  1690. .loop
  1691. ld a, [hl]
  1692. push af
  1693. and SLP ; is pokemon asleep?
  1694. jr z, .notAsleep
  1695. ld a, 1
  1696. ld [wWereAnyMonsAsleep], a ; indicate that a pokemon had to be woken up
  1697. .notAsleep
  1698. pop af
  1699. and b ; remove Sleep status
  1700. ld [hl], a
  1701. add hl, de
  1702. dec c
  1703. jr nz, .loop
  1704. ret
  1705. ; Format:
  1706. ; 00: Y
  1707. ; 01: X
  1708. Route12SnorlaxFluteCoords:
  1709. db 62,9 ; one space West of Snorlax
  1710. db 61,10 ; one space North of Snorlax
  1711. db 63,10 ; one space South of Snorlax
  1712. db 62,11 ; one space East of Snorlax
  1713. db $ff ; terminator
  1714. ; Format:
  1715. ; 00: Y
  1716. ; 01: X
  1717. Route16SnorlaxFluteCoords:
  1718. db 10,27 ; one space East of Snorlax
  1719. db 10,25 ; one space West of Snorlax
  1720. db $ff ; terminator
  1721. PlayedFluteNoEffectText:
  1722. TX_FAR _PlayedFluteNoEffectText
  1723. db "@"
  1724. FluteWokeUpText:
  1725. TX_FAR _FluteWokeUpText
  1726. db "@"
  1727. PlayedFluteHadEffectText:
  1728. TX_FAR _PlayedFluteHadEffectText
  1729. TX_BLINK
  1730. TX_ASM
  1731. ld a, [wIsInBattle]
  1732. and a
  1733. jr nz, .done
  1734. ; play out-of-battle pokeflute music
  1735. ld a, $ff
  1736. call PlaySound ; turn off music
  1737. ld a, SFX_POKEFLUTE
  1738. ld c, BANK(SFX_Pokeflute)
  1739. call PlayMusic
  1740. .musicWaitLoop ; wait for music to finish playing
  1741. ld a, [wChannelSoundIDs + Ch2]
  1742. cp SFX_POKEFLUTE
  1743. jr z, .musicWaitLoop
  1744. call PlayDefaultMusic ; start playing normal music again
  1745. .done
  1746. jp TextScriptEnd ; end text
  1747. ItemUseCoinCase:
  1748. ld a, [wIsInBattle]
  1749. and a
  1750. jp nz, ItemUseNotTime
  1751. ld hl, CoinCaseNumCoinsText
  1752. jp PrintText
  1753. CoinCaseNumCoinsText:
  1754. TX_FAR _CoinCaseNumCoinsText
  1755. db "@"
  1756. ItemUseOldRod:
  1757. call FishingInit
  1758. jp c, ItemUseNotTime
  1759. lb bc, 5, MAGIKARP
  1760. ld a, $1 ; set bite
  1761. jr RodResponse
  1762. ItemUseGoodRod:
  1763. call FishingInit
  1764. jp c, ItemUseNotTime
  1765. .RandomLoop
  1766. call Random
  1767. srl a
  1768. jr c, .SetBite
  1769. and %11
  1770. cp 2
  1771. jr nc, .RandomLoop
  1772. ; choose which monster appears
  1773. ld hl, GoodRodMons
  1774. add a
  1775. ld c, a
  1776. ld b, 0
  1777. add hl, bc
  1778. ld b, [hl]
  1779. inc hl
  1780. ld c, [hl]
  1781. and a
  1782. .SetBite
  1783. ld a, 0
  1784. rla
  1785. xor 1
  1786. jr RodResponse
  1787. INCLUDE "data/good_rod.asm"
  1788. ItemUseSuperRod:
  1789. call FishingInit
  1790. jp c, ItemUseNotTime
  1791. call ReadSuperRodData
  1792. ld a, e
  1793. RodResponse:
  1794. ld [wRodResponse], a
  1795. dec a ; is there a bite?
  1796. jr nz, .next
  1797. ; if yes, store level and species data
  1798. ld a, 1
  1799. ld [wMoveMissed], a
  1800. ld a, b ; level
  1801. ld [wCurEnemyLVL], a
  1802. ld a, c ; species
  1803. ld [wCurOpponent], a
  1804. .next
  1805. ld hl, wWalkBikeSurfState
  1806. ld a, [hl] ; store the value in a
  1807. push af
  1808. push hl
  1809. ld [hl], 0
  1810. callba FishingAnim
  1811. pop hl
  1812. pop af
  1813. ld [hl], a
  1814. ret
  1815. ; checks if fishing is possible and if so, runs initialization code common to all rods
  1816. ; unsets carry if fishing is possible, sets carry if not
  1817. FishingInit:
  1818. ld a, [wIsInBattle]
  1819. and a
  1820. jr z, .notInBattle
  1821. scf ; can't fish during battle
  1822. ret
  1823. .notInBattle
  1824. call IsNextTileShoreOrWater
  1825. ret c
  1826. ld a, [wWalkBikeSurfState]
  1827. cp 2 ; Surfing?
  1828. jr z, .surfing
  1829. call ItemUseReloadOverworldData
  1830. ld hl, ItemUseText00
  1831. call PrintText
  1832. ld a, SFX_HEAL_AILMENT
  1833. call PlaySound
  1834. ld c, 80
  1835. call DelayFrames
  1836. and a
  1837. ret
  1838. .surfing
  1839. scf ; can't fish when surfing
  1840. ret
  1841. ItemUseOaksParcel:
  1842. jp ItemUseNotYoursToUse
  1843. ItemUseItemfinder:
  1844. ld a, [wIsInBattle]
  1845. and a
  1846. jp nz, ItemUseNotTime
  1847. call ItemUseReloadOverworldData
  1848. callba HiddenItemNear ; check for hidden items
  1849. ld hl, ItemfinderFoundNothingText
  1850. jr nc, .printText ; if no hidden items
  1851. ld c, 4
  1852. .loop
  1853. ld a, SFX_HEALING_MACHINE
  1854. call PlaySoundWaitForCurrent
  1855. ld a, SFX_PURCHASE
  1856. call PlaySoundWaitForCurrent
  1857. dec c
  1858. jr nz, .loop
  1859. ld hl, ItemfinderFoundItemText
  1860. .printText
  1861. jp PrintText
  1862. ItemfinderFoundItemText:
  1863. TX_FAR _ItemfinderFoundItemText
  1864. db "@"
  1865. ItemfinderFoundNothingText:
  1866. TX_FAR _ItemfinderFoundNothingText
  1867. db "@"
  1868. ItemUsePPUp:
  1869. ld a, [wIsInBattle]
  1870. and a
  1871. jp nz, ItemUseNotTime
  1872. ItemUsePPRestore:
  1873. ld a, [wWhichPokemon]
  1874. push af
  1875. ld a, [wcf91]
  1876. ld [wPPRestoreItem], a
  1877. .chooseMon
  1878. xor a
  1879. ld [wUpdateSpritesEnabled], a
  1880. ld a, USE_ITEM_PARTY_MENU
  1881. ld [wPartyMenuTypeOrMessageID], a
  1882. call DisplayPartyMenu
  1883. jr nc, .chooseMove
  1884. jp .itemNotUsed
  1885. .chooseMove
  1886. ld a, [wPPRestoreItem]
  1887. cp ELIXER
  1888. jp nc, .useElixir ; if Elixir or Max Elixir
  1889. ld a, $02
  1890. ld [wMoveMenuType], a
  1891. ld hl, RaisePPWhichTechniqueText
  1892. ld a, [wPPRestoreItem]
  1893. cp ETHER ; is it a PP Up?
  1894. jr c, .printWhichTechniqueMessage ; if so, print the raise PP message
  1895. ld hl, RestorePPWhichTechniqueText ; otherwise, print the restore PP message
  1896. .printWhichTechniqueMessage
  1897. call PrintText
  1898. xor a
  1899. ld [wPlayerMoveListIndex], a
  1900. callab MoveSelectionMenu ; move selection menu
  1901. ld a, 0
  1902. ld [wPlayerMoveListIndex], a
  1903. jr nz, .chooseMon
  1904. ld hl, wPartyMon1Moves
  1905. ld bc, wPartyMon2 - wPartyMon1
  1906. call GetSelectedMoveOffset
  1907. push hl
  1908. ld a, [hl]
  1909. ld [wd11e], a
  1910. call GetMoveName
  1911. call CopyStringToCF4B ; copy name to wcf4b
  1912. pop hl
  1913. ld a, [wPPRestoreItem]
  1914. cp ETHER
  1915. jr nc, .useEther ; if Ether or Max Ether
  1916. .usePPUp
  1917. ld bc, wPartyMon1PP - wPartyMon1Moves
  1918. add hl, bc
  1919. ld a, [hl] ; move PP
  1920. cp 3 << 6 ; have 3 PP Ups already been used?
  1921. jr c, .PPNotMaxedOut
  1922. ld hl, PPMaxedOutText
  1923. call PrintText
  1924. jr .chooseMove
  1925. .PPNotMaxedOut
  1926. ld a, [hl]
  1927. add 1 << 6 ; increase PP Up count by 1
  1928. ld [hl], a
  1929. ld a, 1 ; 1 PP Up used
  1930. ld [wd11e], a
  1931. call RestoreBonusPP ; add the bonus PP to current PP
  1932. ld hl, PPIncreasedText
  1933. call PrintText
  1934. .done
  1935. pop af
  1936. ld [wWhichPokemon], a
  1937. call GBPalWhiteOut
  1938. call RunDefaultPaletteCommand
  1939. jp RemoveUsedItem
  1940. .afterRestoringPP ; after using a (Max) Ether/Elixir
  1941. ld a, [wWhichPokemon]
  1942. ld b, a
  1943. ld a, [wPlayerMonNumber]
  1944. cp b ; is the pokemon whose PP was restored active in battle?
  1945. jr nz, .skipUpdatingInBattleData
  1946. ld hl, wPartyMon1PP
  1947. ld bc, wPartyMon2 - wPartyMon1
  1948. call AddNTimes
  1949. ld de, wBattleMonPP
  1950. ld bc, 4
  1951. call CopyData ; copy party data to in-battle data
  1952. .skipUpdatingInBattleData
  1953. ld a, SFX_HEAL_AILMENT
  1954. call PlaySound
  1955. ld hl, PPRestoredText
  1956. call PrintText
  1957. jr .done
  1958. .useEther
  1959. call .restorePP
  1960. jr nz, .afterRestoringPP
  1961. jp .noEffect
  1962. ; unsets zero flag if PP was restored, sets zero flag if not
  1963. ; however, this is bugged for Max Ethers and Max Elixirs (see below)
  1964. .restorePP
  1965. xor a ; PLAYER_PARTY_DATA
  1966. ld [wMonDataLocation], a
  1967. call GetMaxPP
  1968. ld hl, wPartyMon1Moves
  1969. ld bc, wPartyMon2 - wPartyMon1
  1970. call GetSelectedMoveOffset
  1971. ld bc, wPartyMon1PP - wPartyMon1Moves
  1972. add hl, bc ; hl now points to move's PP
  1973. ld a, [wMaxPP]
  1974. ld b, a
  1975. ld a, [wPPRestoreItem]
  1976. cp MAX_ETHER
  1977. jr z, .fullyRestorePP
  1978. ld a, [hl] ; move PP
  1979. and %00111111 ; lower 6 bit bits store current PP
  1980. cp b ; does current PP equal max PP?
  1981. ret z ; if so, return
  1982. add 10 ; increase current PP by 10
  1983. ; b holds the max PP amount and b will hold the new PP amount.
  1984. ; So, if the new amount meets or exceeds the max amount,
  1985. ; cap the amount to the max amount by leaving b unchanged.
  1986. ; Otherwise, store the new amount in b.
  1987. cp b ; does the new amount meet or exceed the maximum?
  1988. jr nc, .storeNewAmount
  1989. ld b, a
  1990. .storeNewAmount
  1991. ld a, [hl] ; move PP
  1992. and %11000000 ; PP Up counter bits
  1993. add b
  1994. ld [hl], a
  1995. ret
  1996. .fullyRestorePP
  1997. ld a, [hl] ; move PP
  1998. ; Note that this code has a bug. It doesn't mask out the upper two bits, which
  1999. ; are used to count how many PP Ups have been used on the move. So, Max Ethers
  2000. ; and Max Elixirs will not be detected as having no effect on a move with full
  2001. ; PP if the move has had any PP Ups used on it.
  2002. cp b ; does current PP equal max PP?
  2003. ret z
  2004. jr .storeNewAmount
  2005. .useElixir
  2006. ; decrement the item ID so that ELIXER becomes ETHER and MAX_ELIXER becomes MAX_ETHER
  2007. ld hl, wPPRestoreItem
  2008. dec [hl]
  2009. dec [hl]
  2010. xor a
  2011. ld hl, wCurrentMenuItem
  2012. ld [hli], a
  2013. ld [hl], a ; zero the counter for number of moves that had their PP restored
  2014. ld b, 4
  2015. ; loop through each move and restore PP
  2016. .elixirLoop
  2017. push bc
  2018. ld hl, wPartyMon1Moves
  2019. ld bc, wPartyMon2 - wPartyMon1
  2020. call GetSelectedMoveOffset
  2021. ld a, [hl]
  2022. and a ; does the current slot have a move?
  2023. jr z, .nextMove
  2024. call .restorePP
  2025. jr z, .nextMove
  2026. ; if some PP was restored
  2027. ld hl, wTileBehindCursor ; counter for number of moves that had their PP restored
  2028. inc [hl]
  2029. .nextMove
  2030. ld hl, wCurrentMenuItem
  2031. inc [hl]
  2032. pop bc
  2033. dec b
  2034. jr nz, .elixirLoop
  2035. ld a, [wTileBehindCursor]
  2036. and a ; did any moves have their PP restored?
  2037. jp nz, .afterRestoringPP
  2038. .noEffect
  2039. call ItemUseNoEffect
  2040. .itemNotUsed
  2041. call GBPalWhiteOut
  2042. call RunDefaultPaletteCommand
  2043. pop af
  2044. xor a
  2045. ld [wActionResultOrTookBattleTurn], a ; item use failed
  2046. ret
  2047. RaisePPWhichTechniqueText:
  2048. TX_FAR _RaisePPWhichTechniqueText
  2049. db "@"
  2050. RestorePPWhichTechniqueText:
  2051. TX_FAR _RestorePPWhichTechniqueText
  2052. db "@"
  2053. PPMaxedOutText:
  2054. TX_FAR _PPMaxedOutText
  2055. db "@"
  2056. PPIncreasedText:
  2057. TX_FAR _PPIncreasedText
  2058. db "@"
  2059. PPRestoredText:
  2060. TX_FAR _PPRestoredText
  2061. db "@"
  2062. ; for items that can't be used from the Item menu
  2063. UnusableItem:
  2064. jp ItemUseNotTime
  2065. ItemUseTMHM:
  2066. ld a, [wIsInBattle]
  2067. and a
  2068. jp nz, ItemUseNotTime
  2069. ld a, [wcf91]
  2070. sub TM_01
  2071. push af
  2072. jr nc, .skipAdding
  2073. add 55 ; if item is an HM, add 55
  2074. .skipAdding
  2075. inc a
  2076. ld [wd11e], a
  2077. predef TMToMove ; get move ID from TM/HM ID
  2078. ld a, [wd11e]
  2079. ld [wMoveNum], a
  2080. call GetMoveName
  2081. call CopyStringToCF4B ; copy name to wcf4b
  2082. pop af
  2083. ld hl, BootedUpTMText
  2084. jr nc, .printBootedUpMachineText
  2085. ld hl, BootedUpHMText
  2086. .printBootedUpMachineText
  2087. call PrintText
  2088. ld hl, TeachMachineMoveText
  2089. call PrintText
  2090. coord hl, 14, 7
  2091. lb bc, 8, 15
  2092. ld a, TWO_OPTION_MENU
  2093. ld [wTextBoxID], a
  2094. call DisplayTextBoxID ; yes/no menu
  2095. ld a, [wCurrentMenuItem]
  2096. and a
  2097. jr z, .useMachine
  2098. ld a, 2
  2099. ld [wActionResultOrTookBattleTurn], a ; item not used
  2100. ret
  2101. .useMachine
  2102. ld a, [wWhichPokemon]
  2103. push af
  2104. ld a, [wcf91]
  2105. push af
  2106. .chooseMon
  2107. ld hl, wcf4b
  2108. ld de, wTempMoveNameBuffer
  2109. ld bc, 14
  2110. call CopyData ; save the move name because DisplayPartyMenu will overwrite it
  2111. ld a, $ff
  2112. ld [wUpdateSpritesEnabled], a
  2113. ld a, TMHM_PARTY_MENU
  2114. ld [wPartyMenuTypeOrMessageID], a
  2115. call DisplayPartyMenu
  2116. push af
  2117. ld hl, wTempMoveNameBuffer
  2118. ld de, wcf4b
  2119. ld bc, 14
  2120. call CopyData
  2121. pop af
  2122. jr nc, .checkIfAbleToLearnMove
  2123. ; if the player canceled teaching the move
  2124. pop af
  2125. pop af
  2126. call GBPalWhiteOutWithDelay3
  2127. call ClearSprites
  2128. call RunDefaultPaletteCommand
  2129. jp LoadScreenTilesFromBuffer1 ; restore saved screen
  2130. .checkIfAbleToLearnMove
  2131. predef CanLearnTM ; check if the pokemon can learn the move
  2132. push bc
  2133. ld a, [wWhichPokemon]
  2134. ld hl, wPartyMonNicks
  2135. call GetPartyMonName
  2136. pop bc
  2137. ld a, c
  2138. and a ; can the pokemon learn the move?
  2139. jr nz, .checkIfAlreadyLearnedMove
  2140. ; if the pokemon can't learn the move
  2141. ld a, SFX_DENIED
  2142. call PlaySoundWaitForCurrent
  2143. ld hl, MonCannotLearnMachineMoveText
  2144. call PrintText
  2145. jr .chooseMon
  2146. .checkIfAlreadyLearnedMove
  2147. callab CheckIfMoveIsKnown ; check if the pokemon already knows the move
  2148. jr c, .chooseMon
  2149. predef LearnMove ; teach move
  2150. pop af
  2151. ld [wcf91], a
  2152. pop af
  2153. ld [wWhichPokemon], a
  2154. ld a, b
  2155. and a
  2156. ret z
  2157. ld a, [wcf91]
  2158. call IsItemHM
  2159. ret c
  2160. jp RemoveUsedItem
  2161. BootedUpTMText:
  2162. TX_FAR _BootedUpTMText
  2163. db "@"
  2164. BootedUpHMText:
  2165. TX_FAR _BootedUpHMText
  2166. db "@"
  2167. TeachMachineMoveText:
  2168. TX_FAR _TeachMachineMoveText
  2169. db "@"
  2170. MonCannotLearnMachineMoveText:
  2171. TX_FAR _MonCannotLearnMachineMoveText
  2172. db "@"
  2173. PrintItemUseTextAndRemoveItem:
  2174. ld hl, ItemUseText00
  2175. call PrintText
  2176. ld a, SFX_HEAL_AILMENT
  2177. call PlaySound
  2178. call WaitForTextScrollButtonPress ; wait for button press
  2179. RemoveUsedItem:
  2180. ld hl, wNumBagItems
  2181. ld a, 1 ; one item
  2182. ld [wItemQuantity], a
  2183. jp RemoveItemFromInventory
  2184. ItemUseNoEffect:
  2185. ld hl, ItemUseNoEffectText
  2186. jr ItemUseFailed
  2187. ItemUseNotTime:
  2188. ld hl, ItemUseNotTimeText
  2189. jr ItemUseFailed
  2190. ItemUseNotYoursToUse:
  2191. ld hl, ItemUseNotYoursToUseText
  2192. jr ItemUseFailed
  2193. ThrowBallAtTrainerMon:
  2194. call RunDefaultPaletteCommand
  2195. call LoadScreenTilesFromBuffer1 ; restore saved screen
  2196. call Delay3
  2197. ld a, TOSS_ANIM
  2198. ld [wAnimationID], a
  2199. predef MoveAnimation ; do animation
  2200. ld hl, ThrowBallAtTrainerMonText1
  2201. call PrintText
  2202. ld hl, ThrowBallAtTrainerMonText2
  2203. call PrintText
  2204. jr RemoveUsedItem
  2205. NoCyclingAllowedHere:
  2206. ld hl, NoCyclingAllowedHereText
  2207. jr ItemUseFailed
  2208. BoxFullCannotThrowBall:
  2209. ld hl, BoxFullCannotThrowBallText
  2210. jr ItemUseFailed
  2211. SurfingAttemptFailed:
  2212. ld hl, NoSurfingHereText
  2213. ItemUseFailed:
  2214. xor a
  2215. ld [wActionResultOrTookBattleTurn], a ; item use failed
  2216. jp PrintText
  2217. ItemUseNotTimeText:
  2218. TX_FAR _ItemUseNotTimeText
  2219. db "@"
  2220. ItemUseNotYoursToUseText:
  2221. TX_FAR _ItemUseNotYoursToUseText
  2222. db "@"
  2223. ItemUseNoEffectText:
  2224. TX_FAR _ItemUseNoEffectText
  2225. db "@"
  2226. ThrowBallAtTrainerMonText1:
  2227. TX_FAR _ThrowBallAtTrainerMonText1
  2228. db "@"
  2229. ThrowBallAtTrainerMonText2:
  2230. TX_FAR _ThrowBallAtTrainerMonText2
  2231. db "@"
  2232. NoCyclingAllowedHereText:
  2233. TX_FAR _NoCyclingAllowedHereText
  2234. db "@"
  2235. NoSurfingHereText:
  2236. TX_FAR _NoSurfingHereText
  2237. db "@"
  2238. BoxFullCannotThrowBallText:
  2239. TX_FAR _BoxFullCannotThrowBallText
  2240. db "@"
  2241. ItemUseText00:
  2242. TX_FAR _ItemUseText001
  2243. TX_LINE
  2244. TX_FAR _ItemUseText002
  2245. db "@"
  2246. GotOnBicycleText:
  2247. TX_FAR _GotOnBicycleText1
  2248. TX_LINE
  2249. TX_FAR _GotOnBicycleText2
  2250. db "@"
  2251. GotOffBicycleText:
  2252. TX_FAR _GotOffBicycleText1
  2253. TX_LINE
  2254. TX_FAR _GotOffBicycleText2
  2255. db "@"
  2256. ; restores bonus PP (from PP Ups) when healing at a pokemon center
  2257. ; also, when a PP Up is used, it increases the current PP by one PP Up bonus
  2258. ; INPUT:
  2259. ; [wWhichPokemon] = index of pokemon in party
  2260. ; [wCurrentMenuItem] = index of move (when using a PP Up)
  2261. RestoreBonusPP:
  2262. ld hl, wPartyMon1Moves
  2263. ld bc, wPartyMon2 - wPartyMon1
  2264. ld a, [wWhichPokemon]
  2265. call AddNTimes
  2266. push hl
  2267. ld de, wNormalMaxPPList - 1
  2268. predef LoadMovePPs ; loads the normal max PP of each of the pokemon's moves to wNormalMaxPPList
  2269. pop hl
  2270. ld c, wPartyMon1PP - wPartyMon1Moves
  2271. ld b, 0
  2272. add hl, bc ; hl now points to move 1 PP
  2273. ld de, wNormalMaxPPList
  2274. ld b, 0 ; initialize move counter to zero
  2275. ; loop through the pokemon's moves
  2276. .loop
  2277. inc b
  2278. ld a, b
  2279. cp 5 ; reached the end of the pokemon's moves?
  2280. ret z ; if so, return
  2281. ld a, [wUsingPPUp]
  2282. dec a ; using a PP Up?
  2283. jr nz, .skipMenuItemIDCheck
  2284. ; if using a PP Up, check if this is the move it's being used on
  2285. ld a, [wCurrentMenuItem]
  2286. inc a
  2287. cp b
  2288. jr nz, .nextMove
  2289. .skipMenuItemIDCheck
  2290. ld a, [hl]
  2291. and %11000000 ; have any PP Ups been used?
  2292. call nz, AddBonusPP ; if so, add bonus PP
  2293. .nextMove
  2294. inc hl
  2295. inc de
  2296. jr .loop
  2297. ; adds bonus PP from PP Ups to current PP
  2298. ; 1/5 of normal max PP (capped at 7) is added for each PP Up
  2299. ; INPUT:
  2300. ; [de] = normal max PP
  2301. ; [hl] = move PP
  2302. AddBonusPP:
  2303. push bc
  2304. ld a, [de] ; normal max PP of move
  2305. ld [H_DIVIDEND + 3], a
  2306. xor a
  2307. ld [H_DIVIDEND], a
  2308. ld [H_DIVIDEND + 1], a
  2309. ld [H_DIVIDEND + 2], a
  2310. ld a, 5
  2311. ld [H_DIVISOR], a
  2312. ld b, 4
  2313. call Divide
  2314. ld a, [hl] ; move PP
  2315. ld b, a
  2316. swap a
  2317. and %00001111
  2318. srl a
  2319. srl a
  2320. ld c, a ; c = number of PP Ups used
  2321. .loop
  2322. ld a, [H_QUOTIENT + 3]
  2323. cp 8 ; is the amount greater than or equal to 8?
  2324. jr c, .addAmount
  2325. ld a, 7 ; cap the amount at 7
  2326. .addAmount
  2327. add b
  2328. ld b, a
  2329. ld a, [wUsingPPUp]
  2330. dec a ; is the player using a PP Up right now?
  2331. jr z, .done ; if so, only add the bonus once
  2332. dec c
  2333. jr nz, .loop
  2334. .done
  2335. ld [hl], b
  2336. pop bc
  2337. ret
  2338. ; gets max PP of a pokemon's move (including PP from PP Ups)
  2339. ; INPUT:
  2340. ; [wWhichPokemon] = index of pokemon within party/box
  2341. ; [wMonDataLocation] = pokemon source
  2342. ; 00: player's party
  2343. ; 01: enemy's party
  2344. ; 02: current box
  2345. ; 03: daycare
  2346. ; 04: player's in-battle pokemon
  2347. ; [wCurrentMenuItem] = move index
  2348. ; OUTPUT:
  2349. ; [wMaxPP] = max PP
  2350. GetMaxPP:
  2351. ld a, [wMonDataLocation]
  2352. and a
  2353. ld hl, wPartyMon1Moves
  2354. ld bc, wPartyMon2 - wPartyMon1
  2355. jr z, .sourceWithMultipleMon
  2356. ld hl, wEnemyMon1Moves
  2357. dec a
  2358. jr z, .sourceWithMultipleMon
  2359. ld hl, wBoxMon1Moves
  2360. ld bc, wBoxMon2 - wBoxMon1
  2361. dec a
  2362. jr z, .sourceWithMultipleMon
  2363. ld hl, wDayCareMonMoves
  2364. dec a
  2365. jr z, .sourceWithOneMon
  2366. ld hl, wBattleMonMoves ; player's in-battle pokemon
  2367. .sourceWithOneMon
  2368. call GetSelectedMoveOffset2
  2369. jr .next
  2370. .sourceWithMultipleMon
  2371. call GetSelectedMoveOffset
  2372. .next
  2373. ld a, [hl]
  2374. dec a
  2375. push hl
  2376. ld hl, Moves
  2377. ld bc, MoveEnd - Moves
  2378. call AddNTimes
  2379. ld de, wcd6d
  2380. ld a, BANK(Moves)
  2381. call FarCopyData
  2382. ld de, wcd6d + 5 ; PP is byte 5 of move data
  2383. ld a, [de]
  2384. ld b, a ; b = normal max PP
  2385. pop hl
  2386. push bc
  2387. ld bc, wPartyMon1PP - wPartyMon1Moves ; PP offset if not player's in-battle pokemon data
  2388. ld a, [wMonDataLocation]
  2389. cp 4 ; player's in-battle pokemon?
  2390. jr nz, .addPPOffset
  2391. ld bc, wBattleMonPP - wBattleMonMoves ; PP offset if player's in-battle pokemon data
  2392. .addPPOffset
  2393. add hl, bc
  2394. ld a, [hl] ; a = current PP
  2395. and %11000000 ; get PP Up count
  2396. pop bc
  2397. or b ; place normal max PP in 6 lower bits of a
  2398. ld h, d
  2399. ld l, e
  2400. inc hl ; hl = wcd73
  2401. ld [hl], a
  2402. xor a ; add the bonus for the existing PP Up count
  2403. ld [wUsingPPUp], a
  2404. call AddBonusPP ; add bonus PP from PP Ups
  2405. ld a, [hl]
  2406. and %00111111 ; mask out the PP Up count
  2407. ld [wMaxPP], a ; store max PP
  2408. ret
  2409. GetSelectedMoveOffset:
  2410. ld a, [wWhichPokemon]
  2411. call AddNTimes
  2412. GetSelectedMoveOffset2:
  2413. ld a, [wCurrentMenuItem]
  2414. ld c, a
  2415. ld b, 0
  2416. add hl, bc
  2417. ret
  2418. ; confirms the item toss and then tosses the item
  2419. ; INPUT:
  2420. ; hl = address of inventory (either wNumBagItems or wNumBoxItems)
  2421. ; [wcf91] = item ID
  2422. ; [wWhichPokemon] = index of item within inventory
  2423. ; [wItemQuantity] = quantity to toss
  2424. ; OUTPUT:
  2425. ; clears carry flag if the item is tossed, sets carry flag if not
  2426. TossItem_:
  2427. push hl
  2428. ld a, [wcf91]
  2429. call IsItemHM
  2430. pop hl
  2431. jr c, .tooImportantToToss
  2432. push hl
  2433. call IsKeyItem_
  2434. ld a, [wIsKeyItem]
  2435. pop hl
  2436. and a
  2437. jr nz, .tooImportantToToss
  2438. push hl
  2439. ld a, [wcf91]
  2440. ld [wd11e], a
  2441. call GetItemName
  2442. call CopyStringToCF4B ; copy name to wcf4b
  2443. ld hl, IsItOKToTossItemText
  2444. call PrintText
  2445. coord hl, 14, 7
  2446. lb bc, 8, 15
  2447. ld a, TWO_OPTION_MENU
  2448. ld [wTextBoxID], a
  2449. call DisplayTextBoxID ; yes/no menu
  2450. ld a, [wMenuExitMethod]
  2451. cp CHOSE_SECOND_ITEM
  2452. pop hl
  2453. scf
  2454. ret z ; return if the player chose No
  2455. ; if the player chose Yes
  2456. push hl
  2457. ld a, [wWhichPokemon]
  2458. call RemoveItemFromInventory
  2459. ld a, [wcf91]
  2460. ld [wd11e], a
  2461. call GetItemName
  2462. call CopyStringToCF4B ; copy name to wcf4b
  2463. ld hl, ThrewAwayItemText
  2464. call PrintText
  2465. pop hl
  2466. and a
  2467. ret
  2468. .tooImportantToToss
  2469. push hl
  2470. ld hl, TooImportantToTossText
  2471. call PrintText
  2472. pop hl
  2473. scf
  2474. ret
  2475. ThrewAwayItemText:
  2476. TX_FAR _ThrewAwayItemText
  2477. db "@"
  2478. IsItOKToTossItemText:
  2479. TX_FAR _IsItOKToTossItemText
  2480. db "@"
  2481. TooImportantToTossText:
  2482. TX_FAR _TooImportantToTossText
  2483. db "@"
  2484. ; checks if an item is a key item
  2485. ; INPUT:
  2486. ; [wcf91] = item ID
  2487. ; OUTPUT:
  2488. ; [wIsKeyItem] = result
  2489. ; 00: item is not key item
  2490. ; 01: item is key item
  2491. IsKeyItem_:
  2492. ld a, $01
  2493. ld [wIsKeyItem], a
  2494. ld a, [wcf91]
  2495. cp HM_01 ; is the item an HM or TM?
  2496. jr nc, .checkIfItemIsHM
  2497. ; if the item is not an HM or TM
  2498. push af
  2499. ld hl, KeyItemBitfield
  2500. ld de, wBuffer
  2501. ld bc, 15 ; only 11 bytes are actually used
  2502. call CopyData
  2503. pop af
  2504. dec a
  2505. ld c, a
  2506. ld hl, wBuffer
  2507. ld b, FLAG_TEST
  2508. predef FlagActionPredef
  2509. ld a, c
  2510. and a
  2511. ret nz
  2512. .checkIfItemIsHM
  2513. ld a, [wcf91]
  2514. call IsItemHM
  2515. ret c
  2516. xor a
  2517. ld [wIsKeyItem], a
  2518. ret
  2519. INCLUDE "data/key_items.asm"
  2520. SendNewMonToBox:
  2521. ld de, wNumInBox
  2522. ld a, [de]
  2523. inc a
  2524. ld [de], a
  2525. ld a, [wcf91]
  2526. ld [wd0b5], a
  2527. ld c, a
  2528. .asm_e7b1
  2529. inc de
  2530. ld a, [de]
  2531. ld b, a
  2532. ld a, c
  2533. ld c, b
  2534. ld [de], a
  2535. cp $ff
  2536. jr nz, .asm_e7b1
  2537. call GetMonHeader
  2538. ld hl, wBoxMonOT
  2539. ld bc, NAME_LENGTH
  2540. ld a, [wNumInBox]
  2541. dec a
  2542. jr z, .asm_e7ee
  2543. dec a
  2544. call AddNTimes
  2545. push hl
  2546. ld bc, NAME_LENGTH
  2547. add hl, bc
  2548. ld d, h
  2549. ld e, l
  2550. pop hl
  2551. ld a, [wNumInBox]
  2552. dec a
  2553. ld b, a
  2554. .asm_e7db
  2555. push bc
  2556. push hl
  2557. ld bc, NAME_LENGTH
  2558. call CopyData
  2559. pop hl
  2560. ld d, h
  2561. ld e, l
  2562. ld bc, -NAME_LENGTH
  2563. add hl, bc
  2564. pop bc
  2565. dec b
  2566. jr nz, .asm_e7db
  2567. .asm_e7ee
  2568. ld hl, wPlayerName
  2569. ld de, wBoxMonOT
  2570. ld bc, NAME_LENGTH
  2571. call CopyData
  2572. ld a, [wNumInBox]
  2573. dec a
  2574. jr z, .asm_e82a
  2575. ld hl, wBoxMonNicks
  2576. ld bc, NAME_LENGTH
  2577. dec a
  2578. call AddNTimes
  2579. push hl
  2580. ld bc, NAME_LENGTH
  2581. add hl, bc
  2582. ld d, h
  2583. ld e, l
  2584. pop hl
  2585. ld a, [wNumInBox]
  2586. dec a
  2587. ld b, a
  2588. .asm_e817
  2589. push bc
  2590. push hl
  2591. ld bc, NAME_LENGTH
  2592. call CopyData
  2593. pop hl
  2594. ld d, h
  2595. ld e, l
  2596. ld bc, -NAME_LENGTH
  2597. add hl, bc
  2598. pop bc
  2599. dec b
  2600. jr nz, .asm_e817
  2601. .asm_e82a
  2602. ld hl, wBoxMonNicks
  2603. ld a, NAME_MON_SCREEN
  2604. ld [wNamingScreenType], a
  2605. predef AskName
  2606. ld a, [wNumInBox]
  2607. dec a
  2608. jr z, .asm_e867
  2609. ld hl, wBoxMons
  2610. ld bc, wBoxMon2 - wBoxMon1
  2611. dec a
  2612. call AddNTimes
  2613. push hl
  2614. ld bc, wBoxMon2 - wBoxMon1
  2615. add hl, bc
  2616. ld d, h
  2617. ld e, l
  2618. pop hl
  2619. ld a, [wNumInBox]
  2620. dec a
  2621. ld b, a
  2622. .asm_e854
  2623. push bc
  2624. push hl
  2625. ld bc, wBoxMon2 - wBoxMon1
  2626. call CopyData
  2627. pop hl
  2628. ld d, h
  2629. ld e, l
  2630. ld bc, wBoxMon1 - wBoxMon2
  2631. add hl, bc
  2632. pop bc
  2633. dec b
  2634. jr nz, .asm_e854
  2635. .asm_e867
  2636. ld a, [wEnemyMonLevel]
  2637. ld [wEnemyMonBoxLevel], a
  2638. ld hl, wEnemyMon
  2639. ld de, wBoxMon1
  2640. ld bc, wEnemyMonDVs - wEnemyMon
  2641. call CopyData
  2642. ld hl, wPlayerID
  2643. ld a, [hli]
  2644. ld [de], a
  2645. inc de
  2646. ld a, [hl]
  2647. ld [de], a
  2648. inc de
  2649. push de
  2650. ld a, [wCurEnemyLVL]
  2651. ld d, a
  2652. callab CalcExperience
  2653. pop de
  2654. ld a, [hExperience]
  2655. ld [de], a
  2656. inc de
  2657. ld a, [hExperience + 1]
  2658. ld [de], a
  2659. inc de
  2660. ld a, [hExperience + 2]
  2661. ld [de], a
  2662. inc de
  2663. xor a
  2664. ld b, NUM_STATS * 2
  2665. .asm_e89f
  2666. ld [de], a
  2667. inc de
  2668. dec b
  2669. jr nz, .asm_e89f
  2670. ld hl, wEnemyMonDVs
  2671. ld a, [hli]
  2672. ld [de], a
  2673. inc de
  2674. ld a, [hli]
  2675. ld [de], a
  2676. ld hl, wEnemyMonPP
  2677. ld b, NUM_MOVES
  2678. .asm_e8b1
  2679. ld a, [hli]
  2680. inc de
  2681. ld [de], a
  2682. dec b
  2683. jr nz, .asm_e8b1
  2684. ret
  2685. ; checks if the tile in front of the player is a shore or water tile
  2686. ; used for surfing and fishing
  2687. ; unsets carry if it is, sets carry if not
  2688. IsNextTileShoreOrWater:
  2689. ld a, [wCurMapTileset]
  2690. ld hl, WaterTilesets
  2691. ld de, 1
  2692. call IsInArray
  2693. jr nc, .notShoreOrWater
  2694. ld a, [wCurMapTileset]
  2695. cp SHIP_PORT ; Vermilion Dock tileset
  2696. ld a, [wTileInFrontOfPlayer] ; tile in front of player
  2697. jr z, .skipShoreTiles ; if it's the Vermilion Dock tileset
  2698. cp $48 ; eastern shore tile in Safari Zone
  2699. jr z, .shoreOrWater
  2700. cp $32 ; usual eastern shore tile
  2701. jr z, .shoreOrWater
  2702. .skipShoreTiles
  2703. cp $14 ; water tile
  2704. jr z, .shoreOrWater
  2705. .notShoreOrWater
  2706. scf
  2707. ret
  2708. .shoreOrWater
  2709. and a
  2710. ret
  2711. ; tilesets with water
  2712. WaterTilesets:
  2713. db OVERWORLD, FOREST, DOJO, GYM, SHIP, SHIP_PORT, CAVERN, FACILITY, PLATEAU
  2714. db $ff ; terminator
  2715. ReadSuperRodData:
  2716. ; return e = 2 if no fish on this map
  2717. ; return e = 1 if a bite, bc = level,species
  2718. ; return e = 0 if no bite
  2719. ld a, [wCurMap]
  2720. ld de, 3 ; each fishing group is three bytes wide
  2721. ld hl, SuperRodData
  2722. call IsInArray
  2723. jr c, .ReadFishingGroup
  2724. ld e, $2 ; $2 if no fishing groups found
  2725. ret
  2726. .ReadFishingGroup
  2727. ; hl points to the fishing group entry in the index
  2728. inc hl ; skip map id
  2729. ; read fishing group address
  2730. ld a, [hli]
  2731. ld h, [hl]
  2732. ld l, a
  2733. ld b, [hl] ; how many mons in group
  2734. inc hl ; point to data
  2735. ld e, $0 ; no bite yet
  2736. .RandomLoop
  2737. call Random
  2738. srl a
  2739. ret c ; 50% chance of no battle
  2740. and %11 ; 2-bit random number
  2741. cp b
  2742. jr nc, .RandomLoop ; if a is greater than the number of mons, regenerate
  2743. ; get the mon
  2744. add a
  2745. ld c, a
  2746. ld b, $0
  2747. add hl, bc
  2748. ld b, [hl] ; level
  2749. inc hl
  2750. ld c, [hl] ; species
  2751. ld e, $1 ; $1 if there's a bite
  2752. ret
  2753. INCLUDE "data/super_rod.asm"
  2754. ; reloads map view and processes sprite data
  2755. ; for items that cause the overworld to be displayed
  2756. ItemUseReloadOverworldData:
  2757. call LoadCurrentMapView
  2758. jp UpdateSprites
  2759. ; creates a list at wBuffer of maps where the mon in [wd11e] can be found.
  2760. ; this is used by the pokedex to display locations the mon can be found on the map.
  2761. FindWildLocationsOfMon:
  2762. ld hl, WildDataPointers
  2763. ld de, wBuffer
  2764. ld c, $0
  2765. .loop
  2766. inc hl
  2767. ld a, [hld]
  2768. inc a
  2769. jr z, .done
  2770. push hl
  2771. ld a, [hli]
  2772. ld h, [hl]
  2773. ld l, a
  2774. ld a, [hli]
  2775. and a
  2776. call nz, CheckMapForMon ; land
  2777. ld a, [hli]
  2778. and a
  2779. call nz, CheckMapForMon ; water
  2780. pop hl
  2781. inc hl
  2782. inc hl
  2783. inc c
  2784. jr .loop
  2785. .done
  2786. ld a, $ff ; list terminator
  2787. ld [de], a
  2788. ret
  2789. CheckMapForMon:
  2790. inc hl
  2791. ld b, $a
  2792. .loop
  2793. ld a, [wd11e]
  2794. cp [hl]
  2795. jr nz, .nextEntry
  2796. ld a, c
  2797. ld [de], a
  2798. inc de
  2799. .nextEntry
  2800. inc hl
  2801. inc hl
  2802. dec b
  2803. jr nz, .loop
  2804. dec hl
  2805. ret