-
Notifications
You must be signed in to change notification settings - Fork 993
/
item_effects.asm
2943 lines (2763 loc) · 61.6 KB
/
item_effects.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
UseItem_::
ld a, 1
ld [wActionResultOrTookBattleTurn], a ; initialise to success value
ld a, [wCurItem]
cp HM01
jp nc, ItemUseTMHM
ld hl, ItemUsePtrTable
dec a
add a
ld c, a
ld b, 0
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
ItemUsePtrTable:
; entries correspond to item ids
dw ItemUseBall ; MASTER_BALL
dw ItemUseBall ; ULTRA_BALL
dw ItemUseBall ; GREAT_BALL
dw ItemUseBall ; POKE_BALL
dw ItemUseTownMap ; TOWN_MAP
dw ItemUseBicycle ; BICYCLE
dw ItemUseSurfboard ; SURFBOARD
dw ItemUseBall ; SAFARI_BALL
dw ItemUsePokedex ; POKEDEX
dw ItemUseEvoStone ; MOON_STONE
dw ItemUseMedicine ; ANTIDOTE
dw ItemUseMedicine ; BURN_HEAL
dw ItemUseMedicine ; ICE_HEAL
dw ItemUseMedicine ; AWAKENING
dw ItemUseMedicine ; PARLYZ_HEAL
dw ItemUseMedicine ; FULL_RESTORE
dw ItemUseMedicine ; MAX_POTION
dw ItemUseMedicine ; HYPER_POTION
dw ItemUseMedicine ; SUPER_POTION
dw ItemUseMedicine ; POTION
dw ItemUseBait ; BOULDERBADGE
dw ItemUseRock ; CASCADEBADGE
dw UnusableItem ; THUNDERBADGE
dw UnusableItem ; RAINBOWBADGE
dw UnusableItem ; SOULBADGE
dw UnusableItem ; MARSHBADGE
dw UnusableItem ; VOLCANOBADGE
dw UnusableItem ; EARTHBADGE
dw ItemUseEscapeRope ; ESCAPE_ROPE
dw ItemUseRepel ; REPEL
dw UnusableItem ; OLD_AMBER
dw ItemUseEvoStone ; FIRE_STONE
dw ItemUseEvoStone ; THUNDER_STONE
dw ItemUseEvoStone ; WATER_STONE
dw ItemUseVitamin ; HP_UP
dw ItemUseVitamin ; PROTEIN
dw ItemUseVitamin ; IRON
dw ItemUseVitamin ; CARBOS
dw ItemUseVitamin ; CALCIUM
dw ItemUseVitamin ; RARE_CANDY
dw UnusableItem ; DOME_FOSSIL
dw UnusableItem ; HELIX_FOSSIL
dw UnusableItem ; SECRET_KEY
dw UnusableItem ; ITEM_2C
dw UnusableItem ; BIKE_VOUCHER
dw ItemUseXAccuracy ; X_ACCURACY
dw ItemUseEvoStone ; LEAF_STONE
dw ItemUseCardKey ; CARD_KEY
dw UnusableItem ; NUGGET
dw UnusableItem ; ITEM_32
dw ItemUsePokeDoll ; POKE_DOLL
dw ItemUseMedicine ; FULL_HEAL
dw ItemUseMedicine ; REVIVE
dw ItemUseMedicine ; MAX_REVIVE
dw ItemUseGuardSpec ; GUARD_SPEC
dw ItemUseSuperRepel ; SUPER_REPEL
dw ItemUseMaxRepel ; MAX_REPEL
dw ItemUseDireHit ; DIRE_HIT
dw UnusableItem ; COIN
dw ItemUseMedicine ; FRESH_WATER
dw ItemUseMedicine ; SODA_POP
dw ItemUseMedicine ; LEMONADE
dw UnusableItem ; S_S_TICKET
dw UnusableItem ; GOLD_TEETH
dw ItemUseXStat ; X_ATTACK
dw ItemUseXStat ; X_DEFEND
dw ItemUseXStat ; X_SPEED
dw ItemUseXStat ; X_SPECIAL
dw ItemUseCoinCase ; COIN_CASE
dw ItemUseOaksParcel ; OAKS_PARCEL
dw ItemUseItemfinder ; ITEMFINDER
dw UnusableItem ; SILPH_SCOPE
dw ItemUsePokeFlute ; POKE_FLUTE
dw UnusableItem ; LIFT_KEY
dw UnusableItem ; EXP_ALL
dw ItemUseOldRod ; OLD_ROD
dw ItemUseGoodRod ; GOOD_ROD
dw ItemUseSuperRod ; SUPER_ROD
dw ItemUsePPUp ; PP_UP
dw ItemUsePPRestore ; ETHER
dw ItemUsePPRestore ; MAX_ETHER
dw ItemUsePPRestore ; ELIXER
dw ItemUsePPRestore ; MAX_ELIXER
ItemUseBall:
; Balls can't be used out of battle.
ld a, [wIsInBattle]
and a
jp z, ItemUseNotTime
; Balls can't catch trainers' Pokémon.
dec a
jp nz, ThrowBallAtTrainerMon
; If this is for the old man battle, skip checking if the party & box are full.
ld a, [wBattleType]
dec a
jr z, .canUseBall
ld a, [wPartyCount] ; is party full?
cp PARTY_LENGTH
jr nz, .canUseBall
ld a, [wBoxCount] ; is box full?
cp MONS_PER_BOX
jp z, BoxFullCannotThrowBall
.canUseBall
xor a
ld [wCapturedMonSpecies], a
ld a, [wBattleType]
cp BATTLE_TYPE_SAFARI
jr nz, .skipSafariZoneCode
.safariZone
ld hl, wNumSafariBalls
dec [hl] ; remove a Safari Ball
.skipSafariZoneCode
call RunDefaultPaletteCommand
ld a, $43 ; successful capture value
ld [wPokeBallAnimData], a
call LoadScreenTilesFromBuffer1
ld hl, ItemUseText00
call PrintText
; If the player is fighting an unidentified ghost, set the value that indicates
; the Pokémon can't be caught and skip the capture calculations.
callfar IsGhostBattle
ld b, $10 ; can't be caught value
jp z, .setAnimData
ld a, [wBattleType]
dec a
jr nz, .notOldManBattle
.oldManBattle
ld hl, wGrassRate
ld de, wPlayerName
ld bc, NAME_LENGTH
call CopyData ; save the player's name in the Wild Monster data (part of the Cinnabar Island Missingno. glitch)
jp .captured
.notOldManBattle
; If the player is fighting the ghost Marowak, set the value that indicates the
; Pokémon can't be caught and skip the capture calculations.
ld a, [wCurMap]
cp POKEMON_TOWER_6F
jr nz, .loop
ld a, [wEnemyMonSpecies2]
cp RESTLESS_SOUL
ld b, $10 ; can't be caught value
jp z, .setAnimData
; Get the first random number. Let it be called Rand1.
; Rand1 must be within a certain range according the kind of ball being thrown.
; The ranges are as follows.
; Poké Ball: [0, 255]
; Great Ball: [0, 200]
; Ultra/Safari Ball: [0, 150]
; Loop until an acceptable number is found.
.loop
call Random
ld b, a
; Get the item ID.
ld hl, wCurItem
ld a, [hl]
; The Master Ball always succeeds.
cp MASTER_BALL
jp z, .captured
; Anything will do for the basic Poké Ball.
cp POKE_BALL
jr z, .checkForAilments
; If it's a Great/Ultra/Safari Ball and Rand1 is greater than 200, try again.
ld a, 200
cp b
jr c, .loop
; Less than or equal to 200 is good enough for a Great Ball.
ld a, [hl]
cp GREAT_BALL
jr z, .checkForAilments
; If it's an Ultra/Safari Ball and Rand1 is greater than 150, try again.
ld a, 150
cp b
jr c, .loop
.checkForAilments
; Pokémon can be caught more easily with a status ailment.
; Depending on the status ailment, a certain value will be subtracted from
; Rand1. Let this value be called Status.
; The larger Status is, the more easily the Pokémon can be caught.
; no status ailment: Status = 0
; Burn/Paralysis/Poison: Status = 12
; Freeze/Sleep: Status = 25
; If Status is greater than Rand1, the Pokémon will be caught for sure.
ld a, [wEnemyMonStatus]
and a
jr z, .skipAilmentValueSubtraction ; no ailments
and (1 << FRZ) | SLP_MASK
ld c, 12
jr z, .notFrozenOrAsleep
ld c, 25
.notFrozenOrAsleep
ld a, b
sub c
jp c, .captured
ld b, a
.skipAilmentValueSubtraction
push bc ; save (Rand1 - Status)
; Calculate MaxHP * 255.
xor a
ldh [hMultiplicand], a
ld hl, wEnemyMonMaxHP
ld a, [hli]
ldh [hMultiplicand + 1], a
ld a, [hl]
ldh [hMultiplicand + 2], a
ld a, 255
ldh [hMultiplier], a
call Multiply
; Determine BallFactor. It's 8 for Great Balls and 12 for the others.
ld a, [wCurItem]
cp GREAT_BALL
ld a, 12
jr nz, .skip1
ld a, 8
.skip1
; Note that the results of all division operations are floored.
; Calculate (MaxHP * 255) / BallFactor.
ldh [hDivisor], a
ld b, 4 ; number of bytes in dividend
call Divide
; Divide the enemy's current HP by 4. HP is not supposed to exceed 999 so
; the result should fit in a. If the division results in a quotient of 0,
; change it to 1.
ld hl, wEnemyMonHP
ld a, [hli]
ld b, a
ld a, [hl]
srl b
rr a
srl b
rr a
and a
jr nz, .skip2
inc a
.skip2
; Let W = ((MaxHP * 255) / BallFactor) / max(HP / 4, 1). Calculate W.
ldh [hDivisor], a
ld b, 4
call Divide
; If W > 255, store 255 in [hQuotient + 3].
; Let X = min(W, 255) = [hQuotient + 3].
ldh a, [hQuotient + 2]
and a
jr z, .skip3
ld a, 255
ldh [hQuotient + 3], a
.skip3
pop bc ; b = Rand1 - Status
; If Rand1 - Status > CatchRate, the ball fails to capture the Pokémon.
ld a, [wEnemyMonActualCatchRate]
cp b
jr c, .failedToCapture
; If W > 255, the ball captures the Pokémon.
ldh a, [hQuotient + 2]
and a
jr nz, .captured
call Random ; Let this random number be called Rand2.
; If Rand2 > X, the ball fails to capture the Pokémon.
ld b, a
ldh a, [hQuotient + 3]
cp b
jr c, .failedToCapture
.captured
jr .skipShakeCalculations
.failedToCapture
ldh a, [hQuotient + 3]
ld [wPokeBallCaptureCalcTemp], a ; Save X.
; Calculate CatchRate * 100.
xor a
ldh [hMultiplicand], a
ldh [hMultiplicand + 1], a
ld a, [wEnemyMonActualCatchRate]
ldh [hMultiplicand + 2], a
ld a, 100
ldh [hMultiplier], a
call Multiply
; Determine BallFactor2.
; Poké Ball: BallFactor2 = 255
; Great Ball: BallFactor2 = 200
; Ultra/Safari Ball: BallFactor2 = 150
ld a, [wCurItem]
ld b, 255
cp POKE_BALL
jr z, .skip4
ld b, 200
cp GREAT_BALL
jr z, .skip4
ld b, 150
cp ULTRA_BALL
jr z, .skip4
.skip4
; Let Y = (CatchRate * 100) / BallFactor2. Calculate Y.
ld a, b
ldh [hDivisor], a
ld b, 4
call Divide
; If Y > 255, there are 3 shakes.
; Note that this shouldn't be possible.
; The maximum value of Y is (255 * 100) / 150 = 170.
ldh a, [hQuotient + 2]
and a
ld b, $63 ; 3 shakes
jr nz, .setAnimData
; Calculate X * Y.
ld a, [wPokeBallCaptureCalcTemp]
ldh [hMultiplier], a
call Multiply
; Calculate (X * Y) / 255.
ld a, 255
ldh [hDivisor], a
ld b, 4
call Divide
; Determine Status2.
; no status ailment: Status2 = 0
; Burn/Paralysis/Poison: Status2 = 5
; Freeze/Sleep: Status2 = 10
ld a, [wEnemyMonStatus]
and a
jr z, .skip5
and (1 << FRZ) | SLP_MASK
ld b, 5
jr z, .addAilmentValue
ld b, 10
.addAilmentValue
; If the Pokémon has a status ailment, add Status2.
ldh a, [hQuotient + 3]
add b
ldh [hQuotient + 3], a
.skip5
; Finally determine the number of shakes.
; Let Z = ((X * Y) / 255) + Status2 = [hQuotient + 3].
; The number of shakes depend on the range Z is in.
; 0 ≤ Z < 10: 0 shakes (the ball misses)
; 10 ≤ Z < 30: 1 shake
; 30 ≤ Z < 70: 2 shakes
; 70 ≤ Z: 3 shakes
ldh a, [hQuotient + 3]
cp 10
ld b, $20
jr c, .setAnimData
cp 30
ld b, $61
jr c, .setAnimData
cp 70
ld b, $62
jr c, .setAnimData
ld b, $63
.setAnimData
ld a, b
ld [wPokeBallAnimData], a
.skipShakeCalculations
ld c, 20
call DelayFrames
; Do the animation.
ld a, TOSS_ANIM
ld [wAnimationID], a
xor a
ldh [hWhoseTurn], a
ld [wAnimationType], a
ld [wDamageMultipliers], a
ld a, [wWhichPokemon]
push af
ld a, [wCurItem]
push af
predef MoveAnimation
pop af
ld [wCurItem], a
pop af
ld [wWhichPokemon], a
; Determine the message to display from the animation.
ld a, [wPokeBallAnimData]
cp $10
ld hl, ItemUseBallText00
jp z, .printMessage
cp $20
ld hl, ItemUseBallText01
jp z, .printMessage
cp $61
ld hl, ItemUseBallText02
jp z, .printMessage
cp $62
ld hl, ItemUseBallText03
jp z, .printMessage
cp $63
ld hl, ItemUseBallText04
jp z, .printMessage
; Save current HP.
ld hl, wEnemyMonHP
ld a, [hli]
push af
ld a, [hli]
push af
; Save status ailment.
inc hl
ld a, [hl]
push af
push hl
; If the Pokémon is transformed, the Pokémon is assumed to be a Ditto.
; This is a bug because a wild Pokémon could have used Transform via
; Mirror Move even though the only wild Pokémon that knows Transform is Ditto.
ld hl, wEnemyBattleStatus3
bit TRANSFORMED, [hl]
jr z, .notTransformed
ld a, DITTO
ld [wEnemyMonSpecies2], a
jr .skip6
.notTransformed
; If the Pokémon is not transformed, set the transformed bit and copy the
; DVs to wTransformedEnemyMonOriginalDVs so that LoadEnemyMonData won't generate
; new DVs.
set TRANSFORMED, [hl]
ld hl, wTransformedEnemyMonOriginalDVs
ld a, [wEnemyMonDVs]
ld [hli], a
ld a, [wEnemyMonDVs + 1]
ld [hl], a
.skip6
ld a, [wCurPartySpecies]
push af
ld a, [wEnemyMonSpecies2]
ld [wCurPartySpecies], a
ld a, [wEnemyMonLevel]
ld [wCurEnemyLevel], a
callfar LoadEnemyMonData
pop af
ld [wCurPartySpecies], a
pop hl
pop af
ld [hld], a
dec hl
pop af
ld [hld], a
pop af
ld [hl], a
ld a, [wEnemyMonSpecies]
ld [wCapturedMonSpecies], a
ld [wCurPartySpecies], a
ld [wPokedexNum], a
ld a, [wBattleType]
dec a ; is this the old man battle?
jr z, .oldManCaughtMon ; if so, don't give the player the caught Pokémon
ld hl, ItemUseBallText05
call PrintText
; Add the caught Pokémon to the Pokédex.
predef IndexToPokedex
ld a, [wPokedexNum]
dec a
ld c, a
ld b, FLAG_TEST
ld hl, wPokedexOwned
predef FlagActionPredef
ld a, c
push af
ld a, [wPokedexNum]
dec a
ld c, a
ld b, FLAG_SET
predef FlagActionPredef
pop af
and a ; was the Pokémon already in the Pokédex?
jr nz, .skipShowingPokedexData ; if so, don't show the Pokédex data
ld hl, ItemUseBallText06
call PrintText
call ClearSprites
ld a, [wEnemyMonSpecies]
ld [wPokedexNum], a
predef ShowPokedexData
.skipShowingPokedexData
ld a, [wPartyCount]
cp PARTY_LENGTH ; is party full?
jr z, .sendToBox
xor a ; PLAYER_PARTY_DATA
ld [wMonDataLocation], a
call ClearSprites
call AddPartyMon
jr .done
.sendToBox
call ClearSprites
call SendNewMonToBox
ld hl, ItemUseBallText07
CheckEvent EVENT_MET_BILL
jr nz, .printTransferredToPCText
ld hl, ItemUseBallText08
.printTransferredToPCText
call PrintText
jr .done
.oldManCaughtMon
ld hl, ItemUseBallText05
.printMessage
call PrintText
call ClearSprites
.done
ld a, [wBattleType]
and a ; is this the old man battle?
ret nz ; if so, don't remove a ball from the bag
; Remove a ball from the bag.
ld hl, wNumBagItems
inc a
ld [wItemQuantity], a
jp RemoveItemFromInventory
ItemUseBallText00:
;"It dodged the thrown ball!"
;"This pokemon can't be caught"
text_far _ItemUseBallText00
text_end
ItemUseBallText01:
;"You missed the pokemon!"
text_far _ItemUseBallText01
text_end
ItemUseBallText02:
;"Darn! The pokemon broke free!"
text_far _ItemUseBallText02
text_end
ItemUseBallText03:
;"Aww! It appeared to be caught!"
text_far _ItemUseBallText03
text_end
ItemUseBallText04:
;"Shoot! It was so close too!"
text_far _ItemUseBallText04
text_end
ItemUseBallText05:
;"All right! {MonName} was caught!"
;play sound
text_far _ItemUseBallText05
sound_caught_mon
text_promptbutton
text_end
ItemUseBallText07:
;"X was transferred to Bill's PC"
text_far _ItemUseBallText07
text_end
ItemUseBallText08:
;"X was transferred to someone's PC"
text_far _ItemUseBallText08
text_end
ItemUseBallText06:
;"New DEX data will be added..."
;play sound
text_far _ItemUseBallText06
sound_dex_page_added
text_promptbutton
text_end
ItemUseTownMap:
ld a, [wIsInBattle]
and a
jp nz, ItemUseNotTime
farjp DisplayTownMap
ItemUseBicycle:
ld a, [wIsInBattle]
and a
jp nz, ItemUseNotTime
ld a, [wWalkBikeSurfState]
ld [wWalkBikeSurfStateCopy], a
cp 2 ; is the player surfing?
jp z, ItemUseNotTime
dec a ; is player already bicycling?
jr nz, .tryToGetOnBike
.getOffBike
call ItemUseReloadOverworldData
xor a
ld [wWalkBikeSurfState], a ; change player state to walking
call PlayDefaultMusic ; play walking music
ld hl, GotOffBicycleText
jr .printText
.tryToGetOnBike
call IsBikeRidingAllowed
jp nc, NoCyclingAllowedHere
call ItemUseReloadOverworldData
xor a ; no keys pressed
ldh [hJoyHeld], a ; current joypad state
inc a
ld [wWalkBikeSurfState], a ; change player state to bicycling
ld hl, GotOnBicycleText
call PlayDefaultMusic ; play bike riding music
.printText
jp PrintText
; indirectly used by SURF in StartMenu_Pokemon.surf
ItemUseSurfboard:
ld a, [wWalkBikeSurfState]
ld [wWalkBikeSurfStateCopy], a
cp 2 ; is the player already surfing?
jr z, .tryToStopSurfing
.tryToSurf
call IsNextTileShoreOrWater
jp c, SurfingAttemptFailed
ld hl, TilePairCollisionsWater
call CheckForTilePairCollisions
jp c, SurfingAttemptFailed
.surf
call .makePlayerMoveForward
ld hl, wStatusFlags5
set BIT_SCRIPTED_MOVEMENT_STATE, [hl]
ld a, 2
ld [wWalkBikeSurfState], a ; change player state to surfing
call PlayDefaultMusic ; play surfing music
ld hl, SurfingGotOnText
jp PrintText
.tryToStopSurfing
xor a
ldh [hSpriteIndex], a
ld d, 16 ; talking range in pixels (normal range)
call IsSpriteInFrontOfPlayer2
res BIT_FACE_PLAYER, [hl]
ldh a, [hSpriteIndex]
and a ; is there a sprite in the way?
jr nz, .cannotStopSurfing
ld hl, TilePairCollisionsWater
call CheckForTilePairCollisions
jr c, .cannotStopSurfing
ld hl, wTilesetCollisionPtr ; pointer to list of passable tiles
ld a, [hli]
ld h, [hl]
ld l, a ; hl now points to passable tiles
ld a, [wTileInFrontOfPlayer] ; tile in front of the player
ld b, a
.passableTileLoop
ld a, [hli]
cp b
jr z, .stopSurfing
cp $ff
jr nz, .passableTileLoop
.cannotStopSurfing
ld hl, SurfingNoPlaceToGetOffText
jp PrintText
.stopSurfing
call .makePlayerMoveForward
ld hl, wStatusFlags5
set BIT_SCRIPTED_MOVEMENT_STATE, [hl]
xor a
ld [wWalkBikeSurfState], a ; change player state to walking
dec a
ld [wJoyIgnore], a
call PlayDefaultMusic ; play walking music
jp LoadWalkingPlayerSpriteGraphics
; uses a simulated button press to make the player move forward
.makePlayerMoveForward
ld a, [wPlayerDirection] ; direction the player is going
bit PLAYER_DIR_BIT_UP, a
ld b, D_UP
jr nz, .storeSimulatedButtonPress
bit PLAYER_DIR_BIT_DOWN, a
ld b, D_DOWN
jr nz, .storeSimulatedButtonPress
bit PLAYER_DIR_BIT_LEFT, a
ld b, D_LEFT
jr nz, .storeSimulatedButtonPress
ld b, D_RIGHT
.storeSimulatedButtonPress
ld a, b
ld [wSimulatedJoypadStatesEnd], a
xor a
ld [wUnusedSimulatedJoypadStatesMask], a
inc a
ld [wSimulatedJoypadStatesIndex], a
ret
SurfingGotOnText:
text_far _SurfingGotOnText
text_end
SurfingNoPlaceToGetOffText:
text_far _SurfingNoPlaceToGetOffText
text_end
ItemUsePokedex:
predef_jump ShowPokedexMenu
ItemUseEvoStone:
ld a, [wIsInBattle]
and a
jp nz, ItemUseNotTime
ld a, [wWhichPokemon]
push af
ld a, [wCurItem]
ld [wEvoStoneItemID], a
push af
ld a, EVO_STONE_PARTY_MENU
ld [wPartyMenuTypeOrMessageID], a
ld a, $ff
ld [wUpdateSpritesEnabled], a
call DisplayPartyMenu
pop bc
jr c, .canceledItemUse
ld a, b
ld [wCurPartySpecies], a
ld a, $01
ld [wForceEvolution], a
ld a, SFX_HEAL_AILMENT
call PlaySoundWaitForCurrent
call WaitForSoundToFinish
callfar TryEvolvingMon ; try to evolve pokemon
ld a, [wEvolutionOccurred]
and a
jr z, .noEffect
pop af
ld [wWhichPokemon], a
ld hl, wNumBagItems
ld a, 1 ; remove 1 stone
ld [wItemQuantity], a
jp RemoveItemFromInventory
.noEffect
call ItemUseNoEffect
.canceledItemUse
xor a
ld [wActionResultOrTookBattleTurn], a ; item not used
pop af
ret
ItemUseVitamin:
ld a, [wIsInBattle]
and a
jp nz, ItemUseNotTime
ItemUseMedicine:
ld a, [wPartyCount]
and a
jp z, .emptyParty
ld a, [wWhichPokemon]
push af
ld a, [wCurItem]
push af
ld a, USE_ITEM_PARTY_MENU
ld [wPartyMenuTypeOrMessageID], a
ld a, $ff
ld [wUpdateSpritesEnabled], a
ld a, [wPseudoItemID]
and a ; using Softboiled?
jr z, .notUsingSoftboiled
; if using softboiled
call GoBackToPartyMenu
jr .getPartyMonDataAddress
.emptyParty
ld hl, .emptyPartyText
xor a
ld [wActionResultOrTookBattleTurn], a ; item use failed
jp PrintText
.emptyPartyText
text "You don't have"
line "any #MON!"
prompt
.notUsingSoftboiled
call DisplayPartyMenu
.getPartyMonDataAddress
jp c, .canceledItemUse
ld hl, wPartyMons
ld bc, wPartyMon2 - wPartyMon1
ld a, [wWhichPokemon]
call AddNTimes
ld a, [wWhichPokemon]
ld [wUsedItemOnWhichPokemon], a
ld d, a
ld a, [wCurPartySpecies]
ld e, a
ld [wCurSpecies], a
pop af
ld [wCurItem], a
pop af
ld [wWhichPokemon], a
ld a, [wPseudoItemID]
and a ; using Softboiled?
jr z, .checkItemType
; if using softboiled
ld a, [wWhichPokemon]
cp d ; is the pokemon trying to use softboiled on itself?
jr z, ItemUseMedicine ; if so, force another choice
.checkItemType
ld a, [wCurItem]
cp REVIVE
jr nc, .healHP ; if it's a Revive or Max Revive
cp FULL_HEAL
jr z, .cureStatusAilment ; if it's a Full Heal
cp HP_UP
jp nc, .useVitamin ; if it's a vitamin or Rare Candy
cp FULL_RESTORE
jr nc, .healHP ; if it's a Full Restore or one of the potions
; fall through if it's one of the status-specific healing items
.cureStatusAilment
ld bc, wPartyMon1Status - wPartyMon1
add hl, bc ; hl now points to status
ld a, [wCurItem]
lb bc, ANTIDOTE_MSG, 1 << PSN
cp ANTIDOTE
jr z, .checkMonStatus
lb bc, BURN_HEAL_MSG, 1 << BRN
cp BURN_HEAL
jr z, .checkMonStatus
lb bc, ICE_HEAL_MSG, 1 << FRZ
cp ICE_HEAL
jr z, .checkMonStatus
lb bc, AWAKENING_MSG, SLP_MASK
cp AWAKENING
jr z, .checkMonStatus
lb bc, PARALYZ_HEAL_MSG, 1 << PAR
cp PARLYZ_HEAL
jr z, .checkMonStatus
lb bc, FULL_HEAL_MSG, $ff ; Full Heal
.checkMonStatus
ld a, [hl] ; pokemon's status
and c ; does the pokemon have a status ailment the item can cure?
jp z, .healingItemNoEffect
; if the pokemon has a status the item can heal
xor a
ld [hl], a ; remove the status ailment in the party data
ld a, b
ld [wPartyMenuTypeOrMessageID], a ; the message to display for the item used
ld a, [wPlayerMonNumber]
cp d ; is pokemon the item was used on active in battle?
jp nz, .doneHealing
; if it is active in battle
xor a
ld [wBattleMonStatus], a ; remove the status ailment in the in-battle pokemon data
push hl
ld hl, wPlayerBattleStatus3
res BADLY_POISONED, [hl] ; heal Toxic status
pop hl
ld bc, wPartyMon1Stats - wPartyMon1Status
add hl, bc ; hl now points to party stats
ld de, wBattleMonStats
ld bc, NUM_STATS * 2
call CopyData ; copy party stats to in-battle stat data
predef DoubleOrHalveSelectedStats
jp .doneHealing
.healHP
inc hl ; hl = address of current HP
ld a, [hli]
ld b, a
ld [wHPBarOldHP+1], a
ld a, [hl]
ld c, a
ld [wHPBarOldHP], a ; current HP stored at wHPBarOldHP (2 bytes, big-endian)
or b
jr nz, .notFainted
.fainted
ld a, [wCurItem]
cp REVIVE
jr z, .updateInBattleFaintedData
cp MAX_REVIVE
jr z, .updateInBattleFaintedData
jp .healingItemNoEffect
.updateInBattleFaintedData
ld a, [wIsInBattle]
and a
jr z, .compareCurrentHPToMaxHP
push hl
push de
push bc
ld a, [wUsedItemOnWhichPokemon]
ld c, a
ld hl, wPartyFoughtCurrentEnemyFlags
ld b, FLAG_TEST
predef FlagActionPredef
ld a, c
and a
jr z, .next
ld a, [wUsedItemOnWhichPokemon]
ld c, a
ld hl, wPartyGainExpFlags
ld b, FLAG_SET
predef FlagActionPredef
.next
pop bc
pop de
pop hl
jr .compareCurrentHPToMaxHP
.notFainted
ld a, [wCurItem]
cp REVIVE
jp z, .healingItemNoEffect
cp MAX_REVIVE
jp z, .healingItemNoEffect
.compareCurrentHPToMaxHP
push hl
push bc
ld bc, wPartyMon1MaxHP - (wPartyMon1HP + 1)
add hl, bc ; hl now points to max HP
pop bc
ld a, [hli]
cp b
jr nz, .skipComparingLSB ; no need to compare the LSB's if the MSB's don't match
ld a, [hl]
cp c
.skipComparingLSB
pop hl
jr nz, .notFullHP
.fullHP ; if the pokemon's current HP equals its max HP
ld a, [wCurItem]
cp FULL_RESTORE
jp nz, .healingItemNoEffect
inc hl
inc hl
ld a, [hld] ; status ailment
and a ; does the pokemon have a status ailment?
jp z, .healingItemNoEffect
ld a, FULL_HEAL
ld [wCurItem], a
dec hl
dec hl
dec hl
jp .cureStatusAilment
.notFullHP ; if the pokemon's current HP doesn't equal its max HP
xor a
ld [wLowHealthAlarm], a ;disable low health alarm
ld [wChannelSoundIDs + CHAN5], a
push hl
push de
ld bc, wPartyMon1MaxHP - (wPartyMon1HP + 1)
add hl, bc ; hl now points to max HP
ld a, [hli]
ld [wHPBarMaxHP+1], a