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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
|
HasNoItems:
ld a, [wNumItems]
and a
ret nz
ld a, [wNumKeyItems]
and a
ret nz
ld a, [wNumBalls]
and a
ret nz
ld hl, wTMsHMs
ld b, NUM_TMS + NUM_HMS
.loop
ld a, [hli]
and a
jr nz, .done
dec b
jr nz, .loop
scf
ret
.done
and a
ret
TossItemFromPC:
push de
call PartyMonItemName
farcall _CheckTossableItem
ld a, [wItemAttributeValue]
and a
jr nz, .key_item
ld hl, .ItemsTossOutHowManyText
call MenuTextbox
farcall SelectQuantityToToss
push af
call CloseWindow
call ExitMenu
pop af
jr c, .quit
ld hl, .ItemsThrowAwayText
call MenuTextbox
call YesNoBox
push af
call ExitMenu
pop af
jr c, .quit
pop hl
ld a, [wCurItemQuantity]
call TossItem
call PartyMonItemName
ld hl, .ItemsDiscardedText
call MenuTextbox
call ExitMenu
and a
ret
.key_item
call .CantToss
.quit
pop hl
scf
ret
.ItemsTossOutHowManyText:
text_far _ItemsTossOutHowManyText
text_end
.ItemsThrowAwayText:
text_far _ItemsThrowAwayText
text_end
.ItemsDiscardedText:
text_far _ItemsDiscardedText
text_end
.CantToss:
ld hl, .ItemsTooImportantText
call MenuTextboxBackup
ret
.ItemsTooImportantText:
text_far _ItemsTooImportantText
text_end
CantUseItem:
ld hl, ItemsOakWarningText
call MenuTextboxWaitButton
ret
ItemsOakWarningText:
text_far _ItemsOakWarningText
text_end
PartyMonItemName:
ld a, [wCurItem]
ld [wNamedObjectIndex], a
call GetItemName
call CopyName1
ret
CancelPokemonAction:
farcall InitPartyMenuWithCancel
farcall UnfreezeMonIcons
ld a, 1
ret
PokemonActionSubmenu:
hlcoord 1, 15
lb bc, 2, 18
call ClearBox
farcall MonSubmenu
call GetCurNickname
ld a, [wMenuSelection]
ld hl, .Actions
ld de, 3
call IsInArray
jr nc, .nothing
inc hl
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.nothing
ld a, 0
ret
.Actions:
dbw MONMENUITEM_CUT, MonMenu_Cut
dbw MONMENUITEM_FLY, MonMenu_Fly
dbw MONMENUITEM_SURF, MonMenu_Surf
dbw MONMENUITEM_STRENGTH, MonMenu_Strength
dbw MONMENUITEM_FLASH, MonMenu_Flash
dbw MONMENUITEM_WHIRLPOOL, MonMenu_Whirlpool
dbw MONMENUITEM_DIG, MonMenu_Dig
dbw MONMENUITEM_TELEPORT, MonMenu_Teleport
dbw MONMENUITEM_SOFTBOILED, MonMenu_Softboiled_MilkDrink
dbw MONMENUITEM_MILKDRINK, MonMenu_Softboiled_MilkDrink
dbw MONMENUITEM_HEADBUTT, MonMenu_Headbutt
dbw MONMENUITEM_WATERFALL, MonMenu_Waterfall
dbw MONMENUITEM_ROCKSMASH, MonMenu_RockSmash
dbw MONMENUITEM_SWEETSCENT, MonMenu_SweetScent
dbw MONMENUITEM_STATS, OpenPartyStats
dbw MONMENUITEM_SWITCH, SwitchPartyMons
dbw MONMENUITEM_ITEM, GiveTakePartyMonItem
dbw MONMENUITEM_CANCEL, CancelPokemonAction
dbw MONMENUITEM_MOVE, ManagePokemonMoves
dbw MONMENUITEM_MAIL, MonMailAction
SwitchPartyMons:
; Don't try if there's nothing to switch!
ld a, [wPartyCount]
cp 2
jr c, .DontSwitch
ld a, [wCurPartyMon]
inc a
ld [wSwitchMon], a
farcall HoldSwitchmonIcon
farcall InitPartyMenuNoCancel
ld a, PARTYMENUACTION_MOVE
ld [wPartyMenuActionText], a
farcall WritePartyMenuTilemap
farcall PrintPartyMenuText
hlcoord 0, 1
ld bc, SCREEN_WIDTH * 2
ld a, [wSwitchMon]
dec a
call AddNTimes
ld [hl], "▷"
call WaitBGMap
call SetPalettes
call DelayFrame
farcall PartyMenuSelect
bit 1, b
jr c, .DontSwitch
farcall _SwitchPartyMons
xor a
ld [wPartyMenuActionText], a
farcall LoadPartyMenuGFX
farcall InitPartyMenuWithCancel
farcall InitPartyMenuGFX
ld a, 1
ret
.DontSwitch:
xor a
ld [wPartyMenuActionText], a
call CancelPokemonAction
ret
GiveTakePartyMonItem:
; Eggs can't hold items!
ld a, [wCurPartySpecies]
cp EGG
jr z, .cancel
ld hl, GiveTakeItemMenuData
call LoadMenuHeader
call VerticalMenu
call ExitMenu
jr c, .cancel
call GetCurNickname
ld hl, wStringBuffer1
ld de, wMonOrItemNameBuffer
ld bc, MON_NAME_LENGTH
call CopyBytes
ld a, [wMenuCursorY]
cp 1
jr nz, .take
call LoadStandardMenuHeader
call ClearPalettes
call .GiveItem
call ClearPalettes
call LoadFontsBattleExtra
call ExitMenu
ld a, 0
ret
.take
call TakePartyItem
ld a, 3
ret
.cancel
ld a, 3
ret
.GiveItem:
farcall DepositSellInitPackBuffers
.loop
farcall DepositSellPack
ld a, [wPackUsedItem]
and a
jr z, .quit
ld a, [wCurPocket]
cp KEY_ITEM_POCKET
jr z, .next
call CheckTossableItem
ld a, [wItemAttributeValue]
and a
jr nz, .next
call TryGiveItemToPartymon
jr .quit
.next
ld hl, ItemCantHeldText
call MenuTextboxBackup
jr .loop
.quit
ret
TryGiveItemToPartymon:
call SpeechTextbox
call PartyMonItemName
call GetPartyItemLocation
ld a, [hl]
and a
jr z, .give_item_to_mon
push hl
ld d, a
farcall ItemIsMail
pop hl
jr c, .please_remove_mail
ld a, [hl]
jr .already_holding_item
.give_item_to_mon
call GiveItemToPokemon
ld hl, PokemonHoldItemText
call MenuTextboxBackup
call GivePartyItem
ret
.please_remove_mail
ld hl, PokemonRemoveMailText
call MenuTextboxBackup
ret
.already_holding_item
ld [wNamedObjectIndex], a
call GetItemName
ld hl, PokemonAskSwapItemText
call StartMenuYesNo
jr c, .abort
call GiveItemToPokemon
ld a, [wNamedObjectIndex]
push af
ld a, [wCurItem]
ld [wNamedObjectIndex], a
pop af
ld [wCurItem], a
call ReceiveItemFromPokemon
jr nc, .bag_full
ld hl, PokemonSwapItemText
call MenuTextboxBackup
ld a, [wNamedObjectIndex]
ld [wCurItem], a
call GivePartyItem
ret
.bag_full
ld a, [wNamedObjectIndex]
ld [wCurItem], a
call ReceiveItemFromPokemon
ld hl, ItemStorageFullText
call MenuTextboxBackup
.abort
ret
GivePartyItem:
call GetPartyItemLocation
ld a, [wCurItem]
ld [hl], a
ld d, a
farcall ItemIsMail
jr nc, .done
call ComposeMailMessage
.done
ret
TakePartyItem:
call SpeechTextbox
call GetPartyItemLocation
ld a, [hl]
and a
jr z, .not_holding_item
ld [wCurItem], a
call ReceiveItemFromPokemon
jr nc, .item_storage_full
farcall ItemIsMail
call GetPartyItemLocation
ld a, [hl]
ld [wNamedObjectIndex], a
ld [hl], NO_ITEM
call GetItemName
ld hl, PokemonTookItemText
call MenuTextboxBackup
jr .done
.not_holding_item
ld hl, PokemonNotHoldingText
call MenuTextboxBackup
jr .done
.item_storage_full
ld hl, ItemStorageFullText
call MenuTextboxBackup
.done
ret
GiveTakeItemMenuData:
db MENU_SPRITE_ANIMS | MENU_BACKUP_TILES ; flags
menu_coords 12, 12, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
dw .Items
db 1 ; default option
.Items:
db STATICMENU_CURSOR ; flags
db 2 ; # items
db "GIVE@"
db "TAKE@"
PokemonSwapItemText:
text_far _PokemonSwapItemText
text_end
PokemonHoldItemText:
text_far _PokemonHoldItemText
text_end
PokemonRemoveMailText:
text_far _PokemonRemoveMailText
text_end
PokemonNotHoldingText:
text_far _PokemonNotHoldingText
text_end
ItemStorageFullText:
text_far _ItemStorageFullText
text_end
PokemonTookItemText:
text_far _PokemonTookItemText
text_end
PokemonAskSwapItemText:
text_far _PokemonAskSwapItemText
text_end
ItemCantHeldText:
text_far _ItemCantHeldText
text_end
GetPartyItemLocation:
push af
ld a, MON_ITEM
call GetPartyParamLocation
pop af
ret
ReceiveItemFromPokemon:
ld a, 1
ld [wItemQuantityChange], a
ld hl, wNumItems
jp ReceiveItem
GiveItemToPokemon:
ld a, 1
ld [wItemQuantityChange], a
ld hl, wNumItems
jp TossItem
StartMenuYesNo:
call MenuTextbox
call YesNoBox
jp ExitMenu
ComposeMailMessage:
ld de, wTempMailMessage
farcall _ComposeMailMessage
ld hl, wPlayerName
ld de, wTempMailAuthor
ld bc, NAME_LENGTH - 1
call CopyBytes
ld hl, wPlayerID
ld bc, 2
call CopyBytes
ld a, [wCurPartySpecies]
ld [de], a
inc de
ld a, [wCurItem]
ld [de], a
ld a, [wCurPartyMon]
ld hl, sPartyMail
ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
ld d, h
ld e, l
ld hl, wTempMail
ld bc, MAIL_STRUCT_LENGTH
ld a, BANK(sPartyMail)
call OpenSRAM
call CopyBytes
call CloseSRAM
ret
MonMailAction:
; If in the time capsule or trade center,
; selecting the mail only allows you to
; read the mail.
ld a, [wLinkMode]
cp LINK_TIMECAPSULE
jr z, .read
cp LINK_TRADECENTER
jr z, .read
; Show the READ/TAKE/QUIT menu.
ld hl, .MenuHeader
call LoadMenuHeader
call VerticalMenu
call ExitMenu
; Interpret the menu.
jp c, .done
ld a, [wMenuCursorY]
cp $1
jr z, .read
cp $2
jr z, .take
jp .done
.read
farcall ReadPartyMonMail
ld a, $0
ret
.take
ld hl, .MailAskSendToPCText
call StartMenuYesNo
jr c, .RemoveMailToBag
ld a, [wCurPartyMon]
ld b, a
farcall SendMailToPC
jr c, .MailboxFull
ld hl, .MailSentToPCText
call MenuTextboxBackup
jr .done
.MailboxFull:
ld hl, .MailboxFullText
call MenuTextboxBackup
jr .done
.RemoveMailToBag:
ld hl, .MailLoseMessageText
call StartMenuYesNo
jr c, .done
call GetPartyItemLocation
ld a, [hl]
ld [wCurItem], a
call ReceiveItemFromPokemon
jr nc, .BagIsFull
call GetPartyItemLocation
ld [hl], $0
call GetCurNickname
ld hl, .MailDetachedText
call MenuTextboxBackup
jr .done
.BagIsFull:
ld hl, .MailNoSpaceText
call MenuTextboxBackup
jr .done
.done
ld a, $3
ret
.MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 12, 10, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_CURSOR ; flags
db 3 ; items
db "READ@"
db "TAKE@"
db "QUIT@"
.MailLoseMessageText:
text_far _MailLoseMessageText
text_end
.MailDetachedText:
text_far _MailDetachedText
text_end
.MailNoSpaceText:
text_far _MailNoSpaceText
text_end
.MailAskSendToPCText:
text_far _MailAskSendToPCText
text_end
.MailboxFullText:
text_far _MailboxFullText
text_end
.MailSentToPCText:
text_far _MailSentToPCText
text_end
OpenPartyStats:
call LoadStandardMenuHeader
call ClearSprites
; PartyMon
xor a
ld [wMonType], a
call LowVolume
predef StatsScreenInit
call MaxVolume
call Call_ExitMenu
ld a, 0
ret
MonMenu_Cut:
farcall CutFunction
ld a, [wFieldMoveSucceeded]
cp $1
jr nz, .Fail
ld b, $4
ld a, $2
ret
.Fail:
ld a, $3
ret
MonMenu_Fly:
farcall FlyFunction
ld a, [wFieldMoveSucceeded]
cp $2
jr z, .Fail
cp $0
jr z, .Error
farcall StubbedTrainerRankings_Fly
ld b, $4
ld a, $2
ret
.Fail:
ld a, $3
ret
.Error:
ld a, $0
ret
.NoReload: ; unreferenced
ld a, $1
ret
MonMenu_Flash:
farcall FlashFunction
ld a, [wFieldMoveSucceeded]
cp $1
jr nz, .Fail
ld b, $4
ld a, $2
ret
.Fail:
ld a, $3
ret
MonMenu_Strength:
farcall StrengthFunction
ld a, [wFieldMoveSucceeded]
cp $1
jr nz, .Fail
ld b, $4
ld a, $2
ret
.Fail:
ld a, $3
ret
MonMenu_Whirlpool:
farcall WhirlpoolFunction
ld a, [wFieldMoveSucceeded]
cp $1
jr nz, .Fail
ld b, $4
ld a, $2
ret
.Fail:
ld a, $3
ret
MonMenu_Waterfall:
farcall WaterfallFunction
ld a, [wFieldMoveSucceeded]
cp $1
jr nz, .Fail
ld b, $4
ld a, $2
ret
.Fail:
ld a, $3
ret
MonMenu_Teleport:
farcall TeleportFunction
ld a, [wFieldMoveSucceeded]
and a
jr z, .Fail
ld b, $4
ld a, $2
ret
.Fail:
ld a, $3
ret
MonMenu_Surf:
farcall SurfFunction
ld a, [wFieldMoveSucceeded]
and a
jr z, .Fail
ld b, $4
ld a, $2
ret
.Fail:
ld a, $3
ret
MonMenu_Dig:
farcall DigFunction
ld a, [wFieldMoveSucceeded]
cp $1
jr nz, .Fail
ld b, $4
ld a, $2
ret
.Fail:
ld a, $3
ret
MonMenu_Softboiled_MilkDrink:
call .CheckMonHasEnoughHP
jr nc, .NotEnoughHP
farcall Softboiled_MilkDrinkFunction
jr .finish
.NotEnoughHP:
ld hl, .PokemonNotEnoughHPText
call PrintText
.finish
xor a
ld [wPartyMenuActionText], a
ld a, $3
ret
.PokemonNotEnoughHPText:
text_far _PokemonNotEnoughHPText
text_end
.CheckMonHasEnoughHP:
; Need to have at least (MaxHP / 5) HP left.
ld a, MON_MAXHP
call GetPartyParamLocation
ld a, [hli]
ldh [hDividend + 0], a
ld a, [hl]
ldh [hDividend + 1], a
ld a, 5
ldh [hDivisor], a
ld b, 2
call Divide
ld a, MON_HP + 1
call GetPartyParamLocation
ldh a, [hQuotient + 3]
sub [hl]
dec hl
ldh a, [hQuotient + 2]
sbc [hl]
ret
MonMenu_Headbutt:
farcall HeadbuttFunction
ld a, [wFieldMoveSucceeded]
cp $1
jr nz, .Fail
ld b, $4
ld a, $2
ret
.Fail:
ld a, $3
ret
MonMenu_RockSmash:
farcall RockSmashFunction
ld a, [wFieldMoveSucceeded]
cp $1
jr nz, .Fail
ld b, $4
ld a, $2
ret
.Fail:
ld a, $3
ret
MonMenu_SweetScent:
farcall SweetScentFromMenu
ld b, $4
ld a, $2
ret
ChooseMoveToDelete:
ld hl, wOptions
ld a, [hl]
push af
set NO_TEXT_SCROLL, [hl]
call LoadFontsBattleExtra
call .ChooseMoveToDelete
pop bc
ld a, b
ld [wOptions], a
push af
call ClearBGPalettes
pop af
ret
.ChooseMoveToDelete
call SetUpMoveScreenBG
ld de, DeleteMoveScreen2DMenuData
call Load2DMenuData
call SetUpMoveList
ld hl, w2DMenuFlags1
set 6, [hl]
jr .enter_loop
.loop
call ScrollingMenuJoypad
bit B_BUTTON_F, a
jp nz, .b_button
bit A_BUTTON_F, a
jp nz, .a_button
.enter_loop
call PrepareToPlaceMoveData
call PlaceMoveData
jp .loop
.a_button
and a
jr .finish
.b_button
scf
.finish
push af
xor a
ld [wSwitchMon], a
ld hl, w2DMenuFlags1
res 6, [hl]
call ClearSprites
call ClearTilemap
pop af
ret
DeleteMoveScreen2DMenuData:
db 3, 1 ; cursor start y, x
db 3, 1 ; rows, columns
db $40, $00 ; flags
dn 2, 0 ; cursor offset
db D_UP | D_DOWN | A_BUTTON | B_BUTTON ; accepted buttons
ManagePokemonMoves:
ld a, [wCurPartySpecies]
cp EGG
jr z, .egg
ld hl, wOptions
ld a, [hl]
push af
set NO_TEXT_SCROLL, [hl]
call MoveScreenLoop
pop af
ld [wOptions], a
call ClearBGPalettes
.egg
ld a, $0
ret
MoveScreenLoop:
ld a, [wCurPartyMon]
inc a
ld [wPartyMenuCursor], a
call SetUpMoveScreenBG
call PlaceMoveScreenArrows
ld de, MoveScreen2DMenuData
call Load2DMenuData
.loop
call SetUpMoveList
ld hl, w2DMenuFlags1
set 6, [hl]
jr .skip_joy
.joy_loop
call ScrollingMenuJoypad
bit 1, a
jp nz, .b_button
bit 0, a
jp nz, .a_button
bit 4, a
jp nz, .d_right
bit 5, a
jp nz, .d_left
.skip_joy
call PrepareToPlaceMoveData
ld a, [wSwappingMove]
and a
jr nz, .moving_move
call PlaceMoveData
jp .joy_loop
.moving_move
ld a, " "
hlcoord 1, 11
ld bc, 5
call ByteFill
hlcoord 1, 12
lb bc, 5, SCREEN_WIDTH - 2
call ClearBox
hlcoord 1, 12
ld de, String_MoveWhere
call PlaceString
jp .joy_loop
.b_button
call PlayClickSFX
call WaitSFX
ld a, [wSwappingMove]
and a
jp z, .exit
ld a, [wSwappingMove]
ld [wMenuCursorY], a
xor a
ld [wSwappingMove], a
hlcoord 1, 2
lb bc, 8, SCREEN_WIDTH - 2
call ClearBox
jp .loop
.d_right
ld a, [wSwappingMove]
and a
jp nz, .joy_loop
ld a, [wCurPartyMon]
ld b, a
push bc
call .cycle_right
pop bc
ld a, [wCurPartyMon]
cp b
jp z, .joy_loop
jp MoveScreenLoop
.d_left
ld a, [wSwappingMove]
and a
jp nz, .joy_loop
ld a, [wCurPartyMon]
ld b, a
push bc
call .cycle_left
pop bc
ld a, [wCurPartyMon]
cp b
jp z, .joy_loop
jp MoveScreenLoop
.cycle_right
ld a, [wCurPartyMon]
inc a
ld [wCurPartyMon], a
ld c, a
ld b, 0
ld hl, wPartySpecies
add hl, bc
ld a, [hl]
cp -1
jr z, .cycle_left
cp EGG
ret nz
jr .cycle_right
.cycle_left
ld a, [wCurPartyMon]
and a
ret z
.cycle_left_loop
ld a, [wCurPartyMon]
dec a
ld [wCurPartyMon], a
ld c, a
ld b, 0
ld hl, wPartySpecies
add hl, bc
ld a, [hl]
cp EGG
ret nz
ld a, [wCurPartyMon]
and a
jr z, .cycle_right
jr .cycle_left_loop
.a_button
call PlayClickSFX
call WaitSFX
ld a, [wSwappingMove]
and a
jr nz, .place_move
ld a, [wMenuCursorY]
ld [wSwappingMove], a
call PlaceHollowCursor
jp .moving_move
.place_move
ld hl, wPartyMon1Moves
ld bc, PARTYMON_STRUCT_LENGTH
ld a, [wCurPartyMon]
call AddNTimes
push hl
call .copy_move
pop hl
ld bc, wPartyMon1PP - wPartyMon1Moves
add hl, bc
call .copy_move
ld a, [wBattleMode]
jr z, .swap_moves
ld hl, wBattleMonMoves
ld bc, wBattleMonStructEnd - wBattleMon
ld a, [wCurPartyMon]
call AddNTimes
push hl
call .copy_move
pop hl
ld bc, wBattleMonPP - wBattleMonMoves
add hl, bc
call .copy_move
.swap_moves
ld de, SFX_SWITCH_POKEMON
call PlaySFX
call WaitSFX
ld de, SFX_SWITCH_POKEMON
call PlaySFX
call WaitSFX
hlcoord 1, 2
lb bc, 8, 18
call ClearBox
hlcoord 10, 10
lb bc, 1, 9
call ClearBox
jp .loop
.copy_move
push hl
ld a, [wMenuCursorY]
dec a
ld c, a
ld b, 0
add hl, bc
ld d, h
ld e, l
pop hl
ld a, [wSwappingMove]
dec a
ld c, a
ld b, 0
add hl, bc
ld a, [de]
ld b, [hl]
ld [hl], a
ld a, b
ld [de], a
ret
.exit
xor a
ld [wSwappingMove], a
ld hl, w2DMenuFlags1
res 6, [hl]
call ClearSprites
jp ClearTilemap
MoveScreen2DMenuData:
db 3, 1 ; cursor start y, x
db 3, 1 ; rows, columns
db $40, $00 ; flags
dn 2, 0 ; cursor offsets
db D_UP | D_DOWN | D_LEFT | D_RIGHT | A_BUTTON | B_BUTTON ; accepted buttons
String_MoveWhere:
db "Where?@"
SetUpMoveScreenBG:
call ClearBGPalettes
call ClearTilemap
call ClearSprites
xor a
ldh [hBGMapMode], a
farcall LoadStatsScreenPageTilesGFX
farcall ClearSpriteAnims2
ld a, [wCurPartyMon]
ld e, a
ld d, 0
ld hl, wPartySpecies
add hl, de
ld a, [hl]
ld [wTempIconSpecies], a
ld e, MONICON_MOVES
farcall LoadMenuMonIcon
hlcoord 0, 1
ld b, 9
ld c, 18
call Textbox
hlcoord 0, 11
ld b, 5
ld c, 18
call Textbox
hlcoord 2, 0
lb bc, 2, 3
call ClearBox
xor a
ld [wMonType], a
ld hl, wPartyMonNicknames
ld a, [wCurPartyMon]
call GetNickname
hlcoord 5, 1
call PlaceString
push bc
farcall CopyMonToTempMon
pop hl
call PrintLevel
ld hl, wPlayerHPPal
call SetHPPal
ld b, SCGB_MOVE_LIST
call GetSGBLayout
hlcoord 16, 0
lb bc, 1, 3
jp ClearBox
SetUpMoveList:
xor a
ldh [hBGMapMode], a
ld [wSwappingMove], a
ld [wMonType], a
predef CopyMonToTempMon
ld hl, wTempMonMoves
ld de, wListMoves_MoveIndicesBuffer
ld bc, NUM_MOVES
call CopyBytes
ld a, SCREEN_WIDTH * 2
ld [wListMovesLineSpacing], a
hlcoord 2, 3
predef ListMoves
hlcoord 10, 4
predef ListMovePP
call WaitBGMap
call SetPalettes
ld a, [wNumMoves]
inc a
ld [w2DMenuNumRows], a
hlcoord 0, 11
ld b, 5
ld c, 18
jp Textbox
PrepareToPlaceMoveData:
ld hl, wPartyMon1Moves
ld bc, PARTYMON_STRUCT_LENGTH
ld a, [wCurPartyMon]
call AddNTimes
ld a, [wMenuCursorY]
dec a
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
ld [wCurSpecies], a
hlcoord 1, 12
lb bc, 5, 18
jp ClearBox
PlaceMoveData:
xor a
ldh [hBGMapMode], a
hlcoord 0, 10
ld de, String_MoveType_Top
call PlaceString
hlcoord 0, 11
ld de, String_MoveType_Bottom
call PlaceString
hlcoord 12, 12
ld de, String_MoveAtk
call PlaceString
ld a, [wCurSpecies]
ld b, a
hlcoord 2, 12
predef PrintMoveType
ld a, [wCurSpecies]
dec a
ld hl, Moves + MOVE_POWER
ld bc, MOVE_LENGTH
call AddNTimes
ld a, BANK(Moves)
call GetFarByte
hlcoord 16, 12
cp 2
jr c, .no_power
ld [wTextDecimalByte], a
ld de, wTextDecimalByte
lb bc, 1, 3
call PrintNum
jr .description
.no_power
ld de, String_MoveNoPower
call PlaceString
.description
hlcoord 1, 14
predef PrintMoveDescription
ld a, $1
ldh [hBGMapMode], a
ret
String_MoveType_Top:
db "┌─────┐@"
String_MoveType_Bottom:
db "│TYPE/└@"
String_MoveAtk:
db "ATK/@"
String_MoveNoPower:
db "---@"
PlaceMoveScreenArrows:
call PlaceMoveScreenLeftArrow
call PlaceMoveScreenRightArrow
ret
PlaceMoveScreenLeftArrow:
ld a, [wCurPartyMon]
and a
ret z
ld c, a
ld e, a
ld d, 0
ld hl, wPartyCount
add hl, de
.loop
ld a, [hl]
and a
jr z, .prev
cp EGG
jr z, .prev
cp NUM_POKEMON + 1
jr c, .legal
.prev
dec hl
dec c
jr nz, .loop
ret
.legal
hlcoord 16, 0
ld [hl], "◀"
ret
PlaceMoveScreenRightArrow:
ld a, [wCurPartyMon]
inc a
ld c, a
ld a, [wPartyCount]
cp c
ret z
ld e, c
ld d, 0
ld hl, wPartySpecies
add hl, de
.loop
ld a, [hl]
cp -1
ret z
and a
jr z, .next
cp EGG
jr z, .next
cp NUM_POKEMON + 1
jr c, .legal
.next
inc hl
jr .loop
.legal
hlcoord 18, 0
ld [hl], "▶"
ret
|