-
Notifications
You must be signed in to change notification settings - Fork 17
/
party_menu.asm
875 lines (801 loc) · 12.4 KB
/
party_menu.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
SelectMonFromParty:
call DisableSpriteUpdates
xor a
ld [wPartyMenuActionText], a
call ClearBGPalettes
call InitPartyMenuLayout
call WaitBGMap
call SetPalettes
call DelayFrame
call PartyMenuSelect
call ReturnToMapWithSpeechTextbox
ret
SelectTradeOrDayCareMon:
ld a, b
ld [wPartyMenuActionText], a
call DisableSpriteUpdates
call ClearBGPalettes
call InitPartyMenuLayout
call WaitBGMap
ld b, SCGB_PARTY_MENU
call GetSGBLayout
call SetPalettes
call DelayFrame
call PartyMenuSelect
call ReturnToMapWithSpeechTextbox
ret
InitPartyMenuLayout:
call LoadPartyMenuGFX
call InitPartyMenuWithCancel
call InitPartyMenuGFX
call WritePartyMenuTilemap
call PrintPartyMenuText
ret
LoadPartyMenuGFX:
call LoadFontsBattleExtra
callfar InitPartyMenuPalettes ; engine/color.asm
callfar ClearSpriteAnims2
ret
WritePartyMenuTilemap:
ld hl, wOptions
ld a, [hl]
push af
set NO_TEXT_SCROLL, [hl]
xor a
ldh [hBGMapMode], a
hlcoord 0, 0
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
ld a, " "
call ByteFill ; blank the tilemap
call GetPartyMenuQualityIndexes
.loop
ld a, [hli]
cp -1
jr z, .end
push hl
ld hl, .Jumptable
rst JumpTable
pop hl
jr .loop
.end
pop af
ld [wOptions], a
ret
.Jumptable:
; entries correspond to PARTYMENUQUALITY_* constants
dw PlacePartyNicknames
dw PlacePartyHPBar
dw PlacePartyMenuHPDigits
dw PlacePartyMonLevel
dw PlacePartyMonStatus
dw PlacePartyMonTMHMCompatibility
dw PlacePartyMonEvoStoneCompatibility
dw PlacePartyMonGender
dw PlacePartyMonMobileBattleSelection
PlacePartyNicknames:
hlcoord 3, 1
ld a, [wPartyCount]
and a
jr z, .end
ld c, a
ld b, 0
.loop
push bc
push hl
push hl
ld hl, wPartyMonNicknames
ld a, b
call GetNick
pop hl
call PlaceString
pop hl
ld de, 2 * SCREEN_WIDTH
add hl, de
pop bc
inc b
dec c
jr nz, .loop
.end
dec hl
dec hl
ld de, .CANCEL
call PlaceString
ret
.CANCEL:
db "CANCEL@"
PlacePartyHPBar:
xor a
ld [wSGBPals], a
ld a, [wPartyCount]
and a
ret z
ld c, a
ld b, 0
hlcoord 11, 2
.loop
push bc
push hl
call PartyMenuCheckEgg
jr z, .skip
push hl
call PlacePartymonHPBar
pop hl
ld d, $6
ld b, $0
call DrawBattleHPBar
ld hl, wHPPals
ld a, [wSGBPals]
ld c, a
ld b, $0
add hl, bc
call SetHPPal
ld b, SCGB_PARTY_MENU_HP_PALS
call GetSGBLayout
.skip
ld hl, wSGBPals
inc [hl]
pop hl
ld de, 2 * SCREEN_WIDTH
add hl, de
pop bc
inc b
dec c
jr nz, .loop
ld b, SCGB_PARTY_MENU
call GetSGBLayout
ret
PlacePartymonHPBar:
ld a, b
ld bc, PARTYMON_STRUCT_LENGTH
ld hl, wPartyMon1HP
call AddNTimes
ld a, [hli]
or [hl]
jr nz, .not_fainted
xor a
ld e, a
ld c, a
ret
.not_fainted
dec hl
ld a, [hli]
ld b, a
ld a, [hli]
ld c, a
ld a, [hli]
ld d, a
ld a, [hli]
ld e, a
predef ComputeHPBarPixels
ret
PlacePartyMenuHPDigits:
ld a, [wPartyCount]
and a
ret z
ld c, a
ld b, 0
hlcoord 13, 1
.loop
push bc
push hl
call PartyMenuCheckEgg
jr z, .next
push hl
ld a, b
ld bc, PARTYMON_STRUCT_LENGTH
ld hl, wPartyMon1HP
call AddNTimes
ld e, l
ld d, h
pop hl
push de
lb bc, 2, 3
call PrintNum
pop de
ld a, "/"
ld [hli], a
inc de
inc de
lb bc, 2, 3
call PrintNum
.next
pop hl
ld de, 2 * SCREEN_WIDTH
add hl, de
pop bc
inc b
dec c
jr nz, .loop
ret
PlacePartyMonLevel:
ld a, [wPartyCount]
and a
ret z
ld c, a
ld b, 0
hlcoord 8, 2
.loop
push bc
push hl
call PartyMenuCheckEgg
jr z, .next
push hl
ld a, b
ld bc, PARTYMON_STRUCT_LENGTH
ld hl, wPartyMon1Level
call AddNTimes
ld e, l
ld d, h
pop hl
ld a, [de]
cp 100 ; This is distinct from MAX_LEVEL.
jr nc, .ThreeDigits
ld a, "<LV>"
ld [hli], a
lb bc, PRINTNUM_RIGHTALIGN | 1, 2
; jr .okay
.ThreeDigits:
lb bc, PRINTNUM_RIGHTALIGN | 1, 3
; .okay
call PrintNum
.next
pop hl
ld de, SCREEN_WIDTH * 2
add hl, de
pop bc
inc b
dec c
jr nz, .loop
ret
PlacePartyMonStatus:
ld a, [wPartyCount]
and a
ret z
ld c, a
ld b, 0
hlcoord 5, 2
.loop
push bc
push hl
call PartyMenuCheckEgg
jr z, .next
push hl
ld a, b
ld bc, PARTYMON_STRUCT_LENGTH
ld hl, wPartyMon1Status
call AddNTimes
ld e, l
ld d, h
pop hl
call PlaceStatusString
.next
pop hl
ld de, SCREEN_WIDTH * 2
add hl, de
pop bc
inc b
dec c
jr nz, .loop
ret
PlacePartyMonTMHMCompatibility:
ld a, [wPartyCount]
and a
ret z
ld c, a
ld b, 0
hlcoord 12, 2
.loop
push bc
push hl
call PartyMenuCheckEgg
jr z, .next
push hl
ld hl, wPartySpecies
ld e, b
ld d, 0
add hl, de
ld a, [hl]
ld [wCurPartySpecies], a
predef CanLearnTMHMMove
pop hl
call .PlaceAbleNotAble
call PlaceString
.next
pop hl
ld de, SCREEN_WIDTH * 2
add hl, de
pop bc
inc b
dec c
jr nz, .loop
ret
.PlaceAbleNotAble:
ld a, c
and a
jr nz, .able
ld de, .string_not_able
ret
.able
ld de, .string_able
ret
.string_able
db "ABLE@"
.string_not_able
db "NOT ABLE@"
PlacePartyMonEvoStoneCompatibility:
ld a, [wPartyCount]
and a
ret z
ld c, a
ld b, 0
hlcoord 12, 2
.loop
push bc
push hl
call PartyMenuCheckEgg
jr z, .next
push hl
ld a, b
ld bc, PARTYMON_STRUCT_LENGTH
ld hl, wPartyMon1Species
call AddNTimes
ld a, [hl]
dec a
ld e, a
ld d, 0
ld hl, EvosAttacksPointers
add hl, de
add hl, de
call .DetermineCompatibility
pop hl
call PlaceString
.next
pop hl
ld de, 2 * SCREEN_WIDTH
add hl, de
pop bc
inc b
dec c
jr nz, .loop
ret
.DetermineCompatibility:
ld de, wStringBuffer1
ld a, BANK(EvosAttacksPointers)
ld bc, 2
call FarCopyBytes
ld hl, wStringBuffer1
ld a, [hli]
ld h, [hl]
ld l, a
ld de, wStringBuffer1
ld a, BANK("Evolutions and Attacks")
ld bc, wStringBuffer2 - wStringBuffer1 ; fixed when I got here, thanks somebody :^)
call FarCopyBytes
ld hl, wStringBuffer1
.loop2
ld a, [hli]
and a
jr z, .nope
cp EVOLVE_STAT
jr nz, .not_four_bytes
inc hl
.not_four_bytes
inc hl
inc hl
cp EVOLVE_ITEM
jr nz, .loop2
dec hl
dec hl
ld a, [wCurItem]
cp [hl]
inc hl
inc hl
jr nz, .loop2
ld de, .string_able
ret
.nope
ld de, .string_not_able
ret
.string_able
db "ABLE@"
.string_not_able
db "NOT ABLE@"
PlacePartyMonGender:
ld a, [wPartyCount]
and a
ret z
ld c, a
ld b, 0
hlcoord 12, 2
.loop
push bc
push hl
call PartyMenuCheckEgg
jr z, .next
ld [wCurPartySpecies], a
push hl
ld a, b
ld [wCurPartyMon], a
xor a
ld [wMonType], a
call GetGender
ld de, .unknown
jr c, .got_gender
ld de, .male
jr nz, .got_gender
ld de, .female
.got_gender
pop hl
call PlaceString
.next
pop hl
ld de, 2 * SCREEN_WIDTH
add hl, de
pop bc
inc b
dec c
jr nz, .loop
ret
.male
db "♂…MALE@"
.female
db "♀…FEMALE@"
.unknown
db "…UNKNOWN@"
PlacePartyMonMobileBattleSelection:
ld a, [wPartyCount]
and a
ret z
ld c, a
ld b, 0
hlcoord 12, 1
.loop
push bc
push hl
ld de, .String_Sanka_Shinai
call PlaceString
pop hl
ld de, 2 * SCREEN_WIDTH
add hl, de
pop bc
inc b
dec c
jr nz, .loop
ld a, l
ld e, MON_NAME_LENGTH
sub e
ld l, a
ld a, h
sbc $0
ld h, a
ld de, .String_Kettei_Yameru
call PlaceString
ld b, $3
ld c, $0
ld hl, wd002
ld a, [hl]
.loop2
push hl
push bc
hlcoord 12, 1
.loop3
and a
jr z, .done
ld de, 2 * SCREEN_WIDTH
add hl, de
dec a
jr .loop3
.done
ld de, .String_Banme
push hl
call PlaceString
pop hl
pop bc
push bc
push hl
ld a, c
ld hl, .Strings_1_2_3
call GetNthString
ld d, h
ld e, l
pop hl
call PlaceString
pop bc
pop hl
inc hl
ld a, [hl]
inc c
dec b
ret z
jr .loop2
.String_Banme:
db " ばんめ @" ; Place
.String_Sanka_Shinai:
db "さんかしない@" ; Cancel
.String_Kettei_Yameru:
db "けってい やめる@" ; Quit
.Strings_1_2_3:
db "1@", "2@", "3@" ; 1st, 2nd, 3rd
PartyMenuCheckEgg:
ld a, LOW(wPartySpecies)
add b
ld e, a
ld a, HIGH(wPartySpecies)
adc 0
ld d, a
ld a, [de]
cp EGG
ret
GetPartyMenuQualityIndexes:
ld a, [wPartyMenuActionText]
and $f0
jr nz, .skip
ld a, [wPartyMenuActionText]
and $f
ld e, a
ld d, 0
ld hl, PartyMenuQualityPointers
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ret
.skip
ld hl, PartyMenuQualityPointers.Default
ret
INCLUDE "data/party_menu_qualities.asm"
InitPartyMenuGFX:
ld hl, wPartyCount
ld a, [hli]
and a
ret z
ld c, a
xor a
ldh [hObjectStructIndexBuffer], a
.loop
push bc
push hl
ld hl, LoadMenuMonIcon
ld a, BANK(LoadMenuMonIcon)
ld e, MONICON_PARTYMENU
rst FarCall
ldh a, [hObjectStructIndexBuffer]
inc a
ldh [hObjectStructIndexBuffer], a
pop hl
pop bc
dec c
jr nz, .loop
callfar PlaySpriteAnimations
ret
InitPartyMenuWithCancel:
; with cancel
xor a
ld [wSwitchMon], a
ld de, PartyMenuAttributes
call SetMenuAttributes
ld a, [wPartyCount]
inc a
ld [w2DMenuNumRows], a ; list length
dec a
ld b, a
ld a, [wPartyMenuCursor]
and a
jr z, .skip
inc b
cp b
jr c, .done
.skip
ld a, 1
.done
ld [wMenuCursorY], a
ld a, A_BUTTON | B_BUTTON
ld [wMenuJoypadFilter], a
ret
InitPartyMenuNoCancel:
; no cancel
ld de, PartyMenuAttributes
call SetMenuAttributes
ld a, [wPartyCount]
ld [w2DMenuNumRows], a ; list length
ld b, a
ld a, [wPartyMenuCursor]
and a
jr z, .skip
inc b
cp b
jr c, .done
.skip
ld a, 1
.done
ld [wMenuCursorY], a
ld a, A_BUTTON | B_BUTTON
ld [wMenuJoypadFilter], a
ret
PartyMenuAttributes:
; cursor y
; cursor x
; num rows
; num cols
; bit 6: animate sprites bit 5: wrap around
; ?
; distance between items (hi: y, lo: x)
; allowed buttons (mask)
db 1, 0
db 0, 1
db $60, $00
dn 2, 0
db 0
PartyMenuSelect:
; sets carry if exitted menu.
call StaticMenuJoypad
call PlaceHollowCursor
ld a, [wPartyCount]
inc a
ld b, a
ld a, [wMenuCursorY] ; menu selection?
cp b
jr z, .exitmenu ; CANCEL
ld [wPartyMenuCursor], a
ldh a, [hJoyLast]
ld b, a
bit B_BUTTON_F, b
jr nz, .exitmenu ; B button
ld a, [wMenuCursorY]
dec a
ld [wCurPartyMon], a
ld c, a
ld b, $0
ld hl, wPartySpecies
add hl, bc
ld a, [hl]
ld [wCurPartySpecies], a
ld de, SFX_READ_TEXT_2
call PlaySFX
call WaitSFX
and a
ret
.exitmenu
ld de, SFX_READ_TEXT_2
call PlaySFX
call WaitSFX
scf
ret
PrintPartyMenuText:
hlcoord 0, 14
lb bc, 2, 18
call TextBox
ld a, [wPartyCount]
and a
jr nz, .haspokemon
ld de, YouHaveNoPKMNString
jr .gotstring
.haspokemon
ld a, [wPartyMenuActionText]
and $f ; drop high nibble
ld hl, PartyMenuStrings
ld e, a
ld d, $0
add hl, de
add hl, de
ld a, [hli]
ld d, [hl]
ld e, a
.gotstring
ld a, [wOptions]
push af
set NO_TEXT_SCROLL, a
ld [wOptions], a
hlcoord 1, 16 ; Coord
call PlaceString
pop af
ld [wOptions], a
ret
PartyMenuStrings:
dw ChooseAMonString
dw UseOnWhichPKMNString
dw WhichPKMNString
dw TeachWhichPKMNString
dw MoveToWhereString
dw UseOnWhichPKMNString
dw ChooseAMonString ; Probably used to be ChooseAFemalePKMNString
dw ChooseAMonString ; Probably used to be ChooseAMalePKMNString
dw ToWhichPKMNString
ChooseAMonString:
db "Choose a #MON.@"
UseOnWhichPKMNString:
db "Use on which <PK><MN>?@"
WhichPKMNString:
db "Which <PK><MN>?@"
TeachWhichPKMNString:
db "Teach which <PK><MN>?@"
MoveToWhereString:
db "Move to where?@"
ChooseAFemalePKMNString:
; unused
db "Choose a ♀<PK><MN>.@"
ChooseAMalePKMNString:
; unused
db "Choose a ♂<PK><MN>.@"
ToWhichPKMNString:
db "To which <PK><MN>?@"
YouHaveNoPKMNString:
db "You have no <PK><MN>!@"
PrintPartyMenuActionText:
ld a, [wCurPartyMon]
ld hl, wPartyMonNicknames
call GetNick
ld a, [wPartyMenuActionText]
and $f
ld hl, .MenuActionTexts
call .PrintText
ret
.MenuActionTexts:
; entries correspond to PARTYMENUTEXT_* constants
dw .Text_CuredOfPoison
dw .Text_BurnWasHealed
dw .Text_Defrosted
dw .Text_WokeUp
dw .Text_RidOfParalysis
dw .Text_RecoveredSomeHP
dw .Text_HealthReturned
dw .Text_Revitalized
dw .Text_GrewToLevel
dw .Text_CameToItsSenses
.Text_RecoveredSomeHP:
; recovered @ HP!
text_far UnknownText_0x1bc0a2
text_end
.Text_CuredOfPoison:
; 's cured of poison.
text_far UnknownText_0x1bc0bb
text_end
.Text_RidOfParalysis:
; 's rid of paralysis.
text_far UnknownText_0x1bc0d2
text_end
.Text_BurnWasHealed:
; 's burn was healed.
text_far UnknownText_0x1bc0ea
text_end
.Text_Defrosted:
; was defrosted.
text_far UnknownText_0x1bc101
text_end
.Text_WokeUp:
; woke up.
text_far UnknownText_0x1bc115
text_end
.Text_HealthReturned:
; 's health returned.
text_far UnknownText_0x1bc123
text_end
.Text_Revitalized:
; is revitalized.
text_far UnknownText_0x1bc13a
text_end
.Text_GrewToLevel:
; grew to level @ !@ @
text_far UnknownText_0x1bc14f
text_end
.Text_CameToItsSenses:
; came to its senses.
text_far UnknownText_0x1bc16e
text_end
.PrintText:
ld e, a
ld d, 0
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wOptions]
push af
set NO_TEXT_SCROLL, a
ld [wOptions], a
call PrintText
pop af
ld [wOptions], a
ret