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