-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathscripting.asm
2094 lines (1867 loc) · 44.2 KB
/
scripting.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
SetNextNPCAndScript:
push bc
call FindLoadedNPC
ld a, [wLoadedNPCTempIndex]
ld [wScriptNPC], a
farcall SetNewScriptNPC
pop bc
; fallthrough
SetNextScript:
push hl
ld hl, wNextScript
ld [hl], c
inc hl
ld [hl], b
ld a, OWMODE_SCRIPT
ld [wOverworldMode], a
pop hl
ret
Func_c943:
push hl
push bc
push de
ld l, MAP_SCRIPT_NPCS
call GetMapScriptPointer
jr nc, .quit
.load_npc_loop
ld a, l
ld [wTempPointer], a
ld a, h
ld [wTempPointer + 1], a
ld a, BANK(MapScripts)
ld [wTempPointerBank], a
ld de, wTempNPC
ld bc, NPC_MAP_SIZE
call CopyBankedDataToDE
ld a, [wTempNPC]
or a
jr z, .quit
push hl
ld a, [wLoadNPCFunction]
ld l, a
ld a, [wLoadNPCFunction + 1]
ld h, a
or l
jr z, .no_script
call CallHL2
jr nc, .next_npc
.no_script
ld a, [wTempNPC]
farcall LoadNPCSpriteData
call Func_c998
farcall LoadNPC
.next_npc
pop hl
ld bc, NPC_MAP_SIZE
add hl, bc
jr .load_npc_loop
.quit
ld l, MAP_SCRIPT_POST_NPC
call CallMapScriptPointerIfExists
pop de
pop bc
pop hl
ret
Func_c998:
ld a, [wTempNPC]
cp NPC_AMY
ret nz
ld a, [wd3d0]
or a
ret z
ld b, $4
ld a, [wConsole]
cp CONSOLE_CGB
jr nz, .not_cgb
ld b, $e
.not_cgb
ld a, b
ld [wNPCAnim], a
ld a, $0
ld [wNPCAnimFlags], a
ret
Func_c9b8:
ld l, MAP_SCRIPT_LOAD_MAP
jr CallMapScriptPointerIfExists
Func_c9bc:
ld l, MAP_SCRIPT_AFTER_DUEL
jr CallMapScriptPointerIfExists
Func_c9c0:
ld l, MAP_SCRIPT_MOVED_PLAYER
CallMapScriptPointerIfExists::
call GetMapScriptPointer
ret nc
jp hl
Func_c9c7:
ld l, MAP_SCRIPT_CLOSE_TEXTBOX
jr CallMapScriptPointerIfExists
ClearEvents:
push hl
push bc
ld hl, wEventVars
ld bc, EVENT_VAR_BYTES
.loop
xor a
ld [hli], a
dec bc
ld a, b
or c
jr nz, .loop
pop bc
pop hl
ret
; Clears temporary event vars before determining Imakuni Room
DetermineImakuniAndChallengeHall:
xor a
ld [wEventVars + EVENT_VAR_BYTES - 1], a
call DetermineImakuniRoom
call DetermineChallengeHallEvent
ret
; Determines what room Imakuni is in when you reset
; Skips current room and does not occur if you haven't talked to Imakuni
DetermineImakuniRoom:
ld c, IMAKUNI_FIGHTING_CLUB
get_event_value EVENT_IMAKUNI_STATE
cp IMAKUNI_TALKED
jr c, .skip
.loop
call UpdateRNGSources
and %11
ld c, a
ld b, 0
ld hl, ImakuniPossibleRooms
add hl, bc
ld a, [wTempMap]
cp [hl]
jr z, .loop
.skip
ld a, c
set_event_value EVENT_IMAKUNI_ROOM
ret
ImakuniPossibleRooms:
db FIGHTING_CLUB_LOBBY
db SCIENCE_CLUB_LOBBY
db LIGHTNING_CLUB_LOBBY
db WATER_CLUB_LOBBY
DetermineChallengeHallEvent:
ld a, [wOverworldMapSelection]
cp OWMAP_CHALLENGE_HALL
jr z, .done
get_event_value EVENT_RECEIVED_LEGENDARY_CARDS
or a
jr nz, .challenge_cup_three
; challenge cup two
get_event_value EVENT_CHALLENGE_CUP_2_STATE
cp CHALLENGE_CUP_OVER
jr z, .done
or a ; cp CHALLENGE_CUP_NOT_STARTED
jr z, .challenge_cup_one
cp CHALLENGE_CUP_WON
jr z, .close_challenge_cup_one
ld c, CHALLENGE_CUP_READY_TO_START
set_event_value EVENT_CHALLENGE_CUP_2_STATE
jr .close_challenge_cup_one
.challenge_cup_one
get_event_value EVENT_CHALLENGE_CUP_1_STATE
cp CHALLENGE_CUP_OVER
jr z, .done
or a ; cp CHALLENGE_CUP_NOT_STARTED
jr z, .done
cp CHALLENGE_CUP_WON
jr z, .done
ld c, CHALLENGE_CUP_READY_TO_START
set_event_value EVENT_CHALLENGE_CUP_1_STATE
jr .done
.challenge_cup_three
call UpdateRNGSources
ld c, CHALLENGE_CUP_READY_TO_START
and %11
or a
jr z, .start_challenge_cup_three
ld c, CHALLENGE_CUP_NOT_STARTED
.start_challenge_cup_three
set_event_value EVENT_CHALLENGE_CUP_3_STATE
jr .close_challenge_cup_two
.close_challenge_cup_two
ld c, CHALLENGE_CUP_OVER
set_event_value EVENT_CHALLENGE_CUP_2_STATE
.close_challenge_cup_one
ld c, CHALLENGE_CUP_OVER
set_event_value EVENT_CHALLENGE_CUP_1_STATE
.done
ret
GetStackEventValue:
call GetByteAfterCall
; fallthrough
; returns the event var's value in a
; also ors it with itself before returning
GetEventValue::
push hl
push bc
call GetEventVar
ld c, [hl]
ld a, [wLoadedEventBits]
.loop
bit 0, a
jr nz, .done
srl a
srl c
jr .loop
.done
and c
pop bc
pop hl
or a
ret
SetStackEventZero:
call GetByteAfterCall
push bc
ld c, 0
call SetEventValue
pop bc
ret
; Use macro set_event_value. The byte db'd after this func is called
; is used as the event value argument for SetEventValue
SetStackEventValue:
call GetByteAfterCall
; fallthrough
; a - event
; c - value - truncated to fit only the event var's bounds
SetEventValue:
push hl
push bc
call GetEventVar
ld a, [wLoadedEventBits]
.loop
bit 0, a
jr nz, .done
srl a
sla c
jr .loop
.done
ld a, [wLoadedEventBits]
and c
ld c, a
ld a, [wLoadedEventBits]
cpl
and [hl]
or c
ld [hl], a
pop bc
pop hl
ret
; returns in a the byte db'd after the call to a function that calls this
GetByteAfterCall:
push hl
ld hl, sp+4
push bc
ld c, [hl]
inc hl
ld b, [hl]
ld a, [bc]
inc bc
ld [hl], b
dec hl
ld [hl], c
pop bc
pop hl
ret
MaxStackEventValue:
call GetByteAfterCall
; fallthrough
MaxOutEventValue:
push bc
ld c, $ff
call SetEventValue
pop bc
ret
SetStackEventFalse:
call GetByteAfterCall
; fallthrough
ZeroOutEventValue:
push bc
ld c, 0
call SetEventValue
pop bc
ret
TryGiveMedalPCPacks:
push hl
push bc
ld hl, MedalEvents
lb bc, 0, 8
.loop
ld a, [hli]
call GetEventValue
jr z, .no_medal
inc b
.no_medal
dec c
jr nz, .loop
ld c, b
set_event_value EVENT_MEDAL_COUNT
ld a, c
push af
cp 8
jr nc, .give_packs_for_eight_medals
cp 7
jr nc, .give_packs_for_seven_medals
cp 3
jr nc, .give_packs_for_three_medals
jr .done
.give_packs_for_eight_medals
ld a, $c
farcall TryGivePCPack
.give_packs_for_seven_medals
ld a, $b
farcall TryGivePCPack
.give_packs_for_three_medals
ld a, $a
farcall TryGivePCPack
.done
pop af
pop bc
pop hl
ret
MedalEvents:
db EVENT_BEAT_NIKKI
db EVENT_BEAT_RICK
db EVENT_BEAT_KEN
db EVENT_BEAT_AMY
db EVENT_BEAT_ISAAC
db EVENT_BEAT_MURRAY
db EVENT_BEAT_GENE
db EVENT_BEAT_MITCH
; returns wEventVars byte in hl, related bits in wLoadedEventBits
GetEventVar:
push bc
ld c, a
ld b, 0
sla c
rl b
ld hl, EventVarMasks
add hl, bc
ld a, [hli]
ld c, a
ld a, [hl]
ld [wLoadedEventBits], a
ld b, 0
ld hl, wEventVars
add hl, bc
pop bc
ret
; location in wEventVars of each event var:
; offset - which byte holds the event value
; mask - which bits in the byte hold the value
; events 0-7 are reset when game resets
EventVarMasks:
table_width 2, EventVarMasks
event_def $3f, %10000000 ; EVENT_TEMP_TRADED_WITH_ISHIHARA
event_def $3f, %01000000 ; EVENT_TEMP_GIFTED_TO_MAN1
event_def $3f, %00100000 ; EVENT_TEMP_TALKED_TO_IMAKUNI
event_def $3f, %00010000 ; EVENT_TEMP_DUELED_IMAKUNI
event_def $3f, %00001000 ; EVENT_TEMP_TRADED_WITH_LASS2
event_def $3f, %00000100 ; EVENT_TEMP_05 unused?
event_def $3f, %00000010 ; EVENT_TEMP_06 unused?
event_def $3f, %00000001 ; EVENT_TEMP_07 unused?
event_def $00, %10000000 ; EVENT_BEAT_NIKKI
event_def $00, %01000000 ; EVENT_BEAT_RICK
event_def $00, %00100000 ; EVENT_BEAT_KEN
event_def $00, %00010000 ; EVENT_BEAT_AMY
event_def $00, %00001000 ; EVENT_BEAT_ISAAC
event_def $00, %00000100 ; EVENT_BEAT_MURRAY
event_def $00, %00000010 ; EVENT_BEAT_GENE
event_def $00, %00000001 ; EVENT_BEAT_MITCH
event_def $00, %11111111 ; EVENT_MEDAL_FLAGS
event_def $01, %11110000 ; EVENT_PUPIL_MICHAEL_STATE
event_def $01, %00001111 ; EVENT_GAL1_TRADE_STATE
event_def $02, %11000000 ; EVENT_IMAKUNI_STATE
event_def $02, %00110000 ; EVENT_LASS1_MENTIONED_IMAKUNI
event_def $02, %00001000 ; EVENT_BEAT_SARA
event_def $02, %00000100 ; EVENT_BEAT_AMANDA
event_def $03, %11110000 ; EVENT_PUPIL_CHRIS_STATE
event_def $03, %00001111 ; EVENT_MATTHEW_STATE
event_def $04, %11110000 ; EVENT_CHAP2_TRADE_STATE
event_def $04, %00001111 ; EVENT_DAVID_STATE
event_def $05, %10000000 ; EVENT_BEAT_JOSEPH
event_def $05, %01000000 ; EVENT_ISHIHARA_MENTIONED
event_def $05, %00100000 ; EVENT_ISHIHARA_MET
event_def $05, %00010000 ; EVENT_ISHIHARAS_HOUSE_MENTIONED
event_def $05, %00001111 ; EVENT_ISHIHARA_TRADE_STATE
event_def $06, %11110000 ; EVENT_PUPIL_JESSICA_STATE
event_def $06, %00001100 ; EVENT_LAD2_STATE
event_def $06, %00000010 ; EVENT_RECEIVED_LEGENDARY_CARDS
event_def $06, %00000001 ; EVENT_KEN_HAD_ENOUGH_CARDS
event_def $07, %11000000 ; EVENT_KEN_TALKED
event_def $07, %00100000 ; EVENT_BEAT_JENNIFER
event_def $07, %00010000 ; EVENT_BEAT_NICHOLAS
event_def $07, %00001000 ; EVENT_BEAT_BRANDON
event_def $07, %00000100 ; EVENT_ISAAC_TALKED
event_def $07, %00000010 ; EVENT_MAN1_TALKED
event_def $07, %00000001 ; EVENT_MAN1_WAITING_FOR_CARD
event_def $08, %11111111 ; EVENT_MAN1_REQUESTED_CARD_ID
event_def $09, %11100000 ; EVENT_MAN1_GIFT_SEQUENCE_STATE
event_def $09, %00011111 ; EVENT_MAN1_GIFTED_CARD_FLAGS
event_def $0a, %11110000 ; EVENT_MEDAL_COUNT
event_def $0a, %00001000 ; EVENT_DANIEL_TALKED
event_def $0a, %00000100 ; EVENT_MURRAY_TALKED
event_def $0a, %00000011 ; EVENT_PAPPY1_STATE
event_def $0b, %10000000 ; EVENT_RONALD_PSYCHIC_CLUB_LOBBY_ENCOUNTER
event_def $0b, %01110000 ; EVENT_JOSHUA_STATE
event_def $0b, %00001100 ; EVENT_IMAKUNI_ROOM
event_def $0b, %00000011 ; EVENT_NIKKI_STATE
event_def $0c, %11100000 ; EVENT_IMAKUNI_WIN_COUNT
event_def $0c, %00011100 ; EVENT_LASS2_TRADE_STATE
event_def $0c, %00000010 ; EVENT_ISHIHARA_WANTS_TO_TRADE
event_def $0c, %00000001 ; EVENT_ISHIHARA_CONGRATULATED_PLAYER
event_def $0d, %10000000 ; EVENT_BEAT_KRISTIN
event_def $0d, %01000000 ; EVENT_BEAT_HEATHER
event_def $0d, %00100000 ; EVENT_BEAT_BRITTANY
event_def $0d, %00010000 ; EVENT_DRMASON_CONGRATULATED_PLAYER
event_def $0d, %00001110 ; EVENT_MASON_LAB_STATE
event_def $0e, %11100000 ; EVENT_CHALLENGE_CUP_1_STATE
event_def $0e, %00011100 ; EVENT_CHALLENGE_CUP_2_STATE
event_def $0f, %11100000 ; EVENT_CHALLENGE_CUP_3_STATE
event_def $10, %10000000 ; EVENT_CHALLENGE_CUP_STARTING
event_def $10, %01000000 ; EVENT_CHALLENGE_CUP_STAGE_VISITED
event_def $10, %00110000 ; EVENT_CHALLENGE_CUP_NUMBER
event_def $10, %00001100 ; EVENT_CHALLENGE_CUP_OPPONENT_NUMBER
event_def $10, %00000010 ; EVENT_CHALLENGE_CUP_OPPONENT_CHOSEN
event_def $10, %00000001 ; EVENT_CHALLENGE_CUP_IN_MENU
event_def $11, %11100000 ; EVENT_CHALLENGE_CUP_1_RESULT
event_def $11, %00011100 ; EVENT_CHALLENGE_CUP_2_RESULT
event_def $12, %11100000 ; EVENT_CHALLENGE_CUP_3_RESULT
event_def $13, %10000000 ; EVENT_RONALD_FIRST_CLUB_ENTRANCE_ENCOUNTER
event_def $13, %01100000 ; EVENT_RONALD_FIRST_DUEL_STATE
event_def $13, %00011000 ; EVENT_RONALD_SECOND_DUEL_STATE
event_def $13, %00000100 ; EVENT_RONALD_TALKED
event_def $13, %00000010 ; EVENT_RONALD_POKEMON_DOME_ENTRANCE_ENCOUNTER
event_def $14, %10000000 ; EVENT_RONALD_CHALLENGE_HALL_LOBBY_CONVO_1
event_def $14, %01000000 ; EVENT_RONALD_CHALLENGE_HALL_LOBBY_CONVO_2
event_def $14, %00100000 ; EVENT_RONALD_CHALLENGE_HALL_LOBBY_CONVO_3
event_def $14, %00010000 ; EVENT_RONALD_CHALLENGE_HALL_LOBBY_CONVO_4
event_def $14, %00001000 ; EVENT_RONALD_CHALLENGE_HALL_LOBBY_CONVO_5
event_def $14, %00000100 ; EVENT_RONALD_CHALLENGE_HALL_LOBBY_CONVO_6
event_def $14, %00000010 ; EVENT_RONALD_CHALLENGE_HALL_LOBBY_CONVO_7
event_def $14, %00000001 ; EVENT_RONALD_CHALLENGE_HALL_LOBBY_CONVO_8
event_def $15, %11110000 ; EVENT_RONALD_CHALLENGE_HALL_LOBBY_STATE
event_def $15, %00001000 ; EVENT_PLAYER_ENTERED_CHALLENGE_CUP
event_def $16, %10000000 ; EVENT_FIGHTING_DECK_MACHINE_ACTIVE
event_def $16, %01000000 ; EVENT_ROCK_DECK_MACHINE_ACTIVE
event_def $16, %00100000 ; EVENT_WATER_DECK_MACHINE_ACTIVE
event_def $16, %00010000 ; EVENT_LIGHTNING_DECK_MACHINE_ACTIVE
event_def $16, %00001000 ; EVENT_GRASS_DECK_MACHINE_ACTIVE
event_def $16, %00000100 ; EVENT_PSYCHIC_DECK_MACHINE_ACTIVE
event_def $16, %00000010 ; EVENT_SCIENCE_DECK_MACHINE_ACTIVE
event_def $16, %00000001 ; EVENT_FIRE_DECK_MACHINE_ACTIVE
event_def $16, %11111111 ; EVENT_ALL_DECK_MACHINE_FLAGS
event_def $17, %10000000 ; EVENT_HALL_OF_HONOR_DOORS_OPEN
event_def $17, %01000000 ; EVENT_CHALLENGED_GRAND_MASTERS
event_def $17, %00110000 ; EVENT_POKEMON_DOME_STATE
event_def $17, %00001000 ; EVENT_POKEMON_DOME_IN_MENU
event_def $17, %00000100 ; EVENT_CHALLENGED_RONALD
event_def $18, %11000000 ; EVENT_COURTNEY_STATE
event_def $18, %00110000 ; EVENT_STEVE_STATE
event_def $18, %00001100 ; EVENT_JACK_STATE
event_def $18, %00000011 ; EVENT_ROD_STATE
event_def $19, %11000000 ; EVENT_RONALD_POKEMON_DOME_STATE
event_def $19, %00100000 ; EVENT_RECEIVED_ZAPDOS
event_def $19, %00010000 ; EVENT_RECEIVED_MOLTRES
event_def $19, %00001000 ; EVENT_RECEIVED_ARTICUNO
event_def $19, %00000100 ; EVENT_RECEIVED_DRAGONITE
event_def $19, %00111100 ; EVENT_LEGENDARY_CARDS_RECEIVED_FLAGS
event_def $1a, %11111100 ; EVENT_GIFT_CENTER_MENU_CHOICE
event_def $1a, %00000011 ; EVENT_AARON_BOOSTER_REWARD
event_def $1b, %11111111 ; EVENT_CONSOLE
event_def $1c, %11110000 ; EVENT_SAM_MENU_CHOICE
event_def $1c, %00001111 ; EVENT_AARON_DECK_MENU_CHOICE
assert_table_length NUM_EVENT_FLAGS
; Used for basic level objects that just print text and quit
PrintInteractableObjectText:
ld hl, wDefaultObjectText
ld a, [hli]
ld h, [hl]
ld l, a
call Func_cc32
call CloseAdvancedDialogueBox
ret
Func_cc32:
push hl
ld hl, wCurrentNPCNameTx
ld e, [hl]
inc hl
ld d, [hl]
pop hl
call Func_c8ba
ret
; Used for things that are represented as NPCs but don't have a Script
; EX: Clerks and legendary cards that interact through Level Objects
Script_Clerk10:
Script_GiftCenterClerk:
Script_Woman2:
Script_Torch:
Script_LegendaryCardTopLeft:
Script_LegendaryCardTopRight:
Script_LegendaryCardLeftSpark:
Script_LegendaryCardBottomLeft:
Script_LegendaryCardBottomRight:
Script_LegendaryCardRightSpark:
call CloseAdvancedDialogueBox
ret
; Enters into the script loop, continuing until wBreakScriptLoop > 0
; When the loop is broken, it resumes normal code execution where script ended
; Note: Some scripts "double return" and skip this.
RST20::
pop hl
ld a, l
ld [wScriptPointer], a
ld a, h
ld [wScriptPointer + 1], a
xor a
ld [wBreakScriptLoop], a
.loop
call RunOverworldScript
ld a, [wBreakScriptLoop] ; if you break out, it jumps
or a
jr z, .loop
ld hl, wScriptPointer
ld a, [hli]
ld c, a
ld b, [hl]
retbc
IncreaseScriptPointerBy1:
ld a, 1
jr IncreaseScriptPointer
IncreaseScriptPointerBy2:
ld a, 2
jr IncreaseScriptPointer
IncreaseScriptPointerBy4:
ld a, 4
jr IncreaseScriptPointer
IncreaseScriptPointerBy5:
ld a, 5
jr IncreaseScriptPointer
IncreaseScriptPointerBy6:
ld a, 6
jr IncreaseScriptPointer
IncreaseScriptPointerBy7:
ld a, 7
jr IncreaseScriptPointer
IncreaseScriptPointerBy3:
ld a, 3
IncreaseScriptPointer:
ld c, a
ld a, [wScriptPointer]
add c
ld [wScriptPointer], a
ld a, [wScriptPointer + 1]
adc 0
ld [wScriptPointer + 1], a
ret
SetScriptPointer:
ld hl, wScriptPointer
ld [hl], c
inc hl
ld [hl], b
ret
GetScriptArgs5AfterPointer:
ld a, 5
jr GetScriptArgsAfterPointer
GetScriptArgs1AfterPointer:
ld a, 1
jr GetScriptArgsAfterPointer
GetScriptArgs2AfterPointer:
ld a, 2
jr GetScriptArgsAfterPointer
GetScriptArgs3AfterPointer:
ld a, 3
GetScriptArgsAfterPointer:
push hl
ld l, a
ld a, [wScriptPointer]
add l
ld l, a
ld a, [wScriptPointer + 1]
adc 0
ld h, a
ld a, [hli]
ld c, a
ld b, [hl]
pop hl
or b
ret
SetScriptControlBytePass:
ld a, $ff
ld [wScriptControlByte], a
ret
SetScriptControlByteFail:
xor a
ld [wScriptControlByte], a
ret
; Exits Script mode and runs the next instruction like normal
ScriptCommand_EndScript:
ld a, TRUE
ld [wBreakScriptLoop], a
jp IncreaseScriptPointerBy1
ScriptCommand_CloseAdvancedTextBox:
call CloseAdvancedDialogueBox
jp IncreaseScriptPointerBy1
ScriptCommand_QuitScriptFully:
call ScriptCommand_CloseAdvancedTextBox
call ScriptCommand_EndScript
pop hl
ret
; args: 2-Text String Index
ScriptCommand_PrintNPCText:
ld l, c
ld h, b
call Func_cc32
jp IncreaseScriptPointerBy3
ScriptCommand_PrintText:
ld l, c
ld h, b
call Func_c891
jp IncreaseScriptPointerBy3
ScriptCommand_AskQuestionJumpDefaultYes:
ld a, TRUE
ld [wDefaultYesOrNo], a
; fallthrough
; Asks the player a question then jumps if they answer yes. Seem to be able to
; take a text of 0000 (NULL) to overwrite last with (yes no) prompt at the bottom
ScriptCommand_AskQuestionJump:
ld l, c
ld h, b
call Func_c8ed
ld a, [hCurMenuItem]
ld [wScriptControlByte], a
jr c, .no_jump
call GetScriptArgs3AfterPointer
jr z, .no_jump
jp SetScriptPointer
.no_jump
jp IncreaseScriptPointerBy5
; args - prize cards, deck id, duel theme index
; sets a duel up, doesn't start until we break out of the script system.
ScriptCommand_StartDuel:
call SetNPCDuelParams
ld a, [wScriptNPC]
ld l, LOADED_NPC_ID
call GetItemInLoadedNPCIndex
ld a, [hl]
farcall SetNPCMatchStartTheme
ld a, [wNPCDuelDeckID]
cp $ff
jr nz, .not_aaron_duel
ld a, [wMultichoiceTextboxResult_ChooseDeckToDuelAgainst]
ld c, a
ld b, 0
ld hl, AaronDeckIDs
add hl, bc
ld a, [hl]
ld [wNPCDuelDeckID], a
.not_aaron_duel
ld a, [wScriptNPC]
ld l, LOADED_NPC_ID
call GetItemInLoadedNPCIndex
ld a, [hl]
.start_duel
ld [wNPCDuelist], a
ld [wNPCDuelistCopy], a
push af
farcall Func_1c557
ld [wNPCDuelistDirection], a
pop af
farcall SetNPCOpponentNameAndPortrait
ld a, GAME_EVENT_DUEL
ld [wGameEvent], a
ld hl, wOverworldTransition
set 6, [hl]
jp IncreaseScriptPointerBy4
ScriptCommand_StartChallengeHallDuel:
call SetNPCDuelParams
ld a, [wChallengeHallNPC]
farcall SetNPCDeckIDAndDuelTheme
ld a, MUSIC_MATCH_START_2
ld [wMatchStartTheme], a
ld a, [wChallengeHallNPC]
jr ScriptCommand_StartDuel.start_duel
AaronDeckIDs:
db LIGHTNING_AND_FIRE_DECK_ID
db WATER_AND_FIGHTING_DECK_ID
db GRASS_AND_PSYCHIC_DECK_ID
SetNPCDuelParams:
ld a, c
ld [wNPCDuelPrizes], a
ld a, b
ld [wNPCDuelDeckID], a
call GetScriptArgs3AfterPointer
ld a, c
ld [wDuelTheme], a
ret
ScriptCommand_BattleCenter:
ld a, GAME_EVENT_BATTLE_CENTER
ld [wGameEvent], a
ld hl, wOverworldTransition
set 6, [hl]
jp IncreaseScriptPointerBy1
; prints text arg 1 or arg 2 depending on wScriptControlByte.
ScriptCommand_PrintVariableNPCText:
ld a, [wScriptControlByte]
or a
jr nz, .print_text
call GetScriptArgs3AfterPointer
.print_text
ld l, c
ld h, b
call Func_cc32
jp IncreaseScriptPointerBy5
ScriptCommand_PrintTextForChallengeCup:
get_event_value EVENT_CHALLENGE_CUP_NUMBER
dec a
and %11
add a
inc a
call GetScriptArgsAfterPointer
ld l, c
ld h, b
call Func_cc32
jp IncreaseScriptPointerBy7
ScriptCommand_PrintVariableText:
ld a, [wScriptControlByte]
or a
jr nz, .print_text
call GetScriptArgs3AfterPointer
.print_text
ld l, c
ld h, b
call Func_c891
jp IncreaseScriptPointerBy5
; Does not return to RST20 - pops an extra time to skip that.
ScriptCommand_PrintTextQuitFully:
ld l, c
ld h, b
call Func_cc32
call CloseAdvancedDialogueBox
ld a, TRUE
ld [wBreakScriptLoop], a
call IncreaseScriptPointerBy3
pop hl
ret
ScriptCommand_UnloadActiveNPC:
ld a, [wScriptNPC]
ld [wLoadedNPCTempIndex], a
Func_cdd1:
farcall UnloadNPC
jp IncreaseScriptPointerBy1
ScriptCommand_UnloadChallengeHallNPC:
ld a, [wLoadedNPCTempIndex]
push af
ld a, [wTempNPC]
push af
ld a, [wChallengeHallNPC]
ld [wTempNPC], a
call FindLoadedNPC
call Func_cdd1
pop af
ld [wTempNPC], a
pop af
ld [wLoadedNPCTempIndex], a
ret
ScriptCommand_SetChallengeHallNPCCoords:
ld a, [wLoadedNPCTempIndex]
push af
ld a, [wTempNPC]
push af
ld a, [wChallengeHallNPC]
ld [wTempNPC], a
ld a, c
ld [wLoadNPCXPos], a
ld a, b
ld [wLoadNPCYPos], a
ld a, SOUTH
ld [wLoadNPCDirection], a
ld a, [wTempNPC]
farcall LoadNPCSpriteData
farcall LoadNPC
pop af
ld [wTempNPC], a
pop af
ld [wLoadedNPCTempIndex], a
jp IncreaseScriptPointerBy3
; Finds and executes an NPCMovement script in the table provided in bc
; based on the active NPC's current direction
ScriptCommand_MoveActiveNPCByDirection:
ld a, [wScriptNPC]
ld [wLoadedNPCTempIndex], a
farcall GetNPCDirection
rlca
add c
ld l, a
ld a, b
adc 0
ld h, a
ld c, [hl]
inc hl
ld b, [hl]
; fallthrough
; Moves an NPC given the list of directions pointed to by bc
; set bit 7 to only rotate the NPC
ExecuteNPCMovement::
farcall StartNPCMovement
.loop
call DoFrameIfLCDEnabled
farcall CheckIsAnNPCMoving
jr nz, .loop
jp IncreaseScriptPointerBy3
; Begin a series of NPC movements on the currently talking NPC
; based on the series of directions pointed to by bc
ScriptCommand_MoveActiveNPC:
ld a, [wScriptNPC]
ld [wLoadedNPCTempIndex], a
jr ExecuteNPCMovement
; Begin a series of NPC movements on the Challenge Hall opponent NPC
; based on the series of directions pointed to by bc
ScriptCommand_MoveChallengeHallNPC:
ld a, [wLoadedNPCTempIndex]
push af
ld a, [wTempNPC]
push af
ld a, [wChallengeHallNPC]
; fallthrough
; Executes movement on an arbitrary NPC using values in a and on the stack
; Changes and fixes Temp NPC using stack values
ExecuteArbitraryNPCMovementFromStack:
ld [wTempNPC], a
call FindLoadedNPC
call ExecuteNPCMovement
pop af
ld [wTempNPC], a
pop af
ld [wLoadedNPCTempIndex], a
ret
ScriptCommand_MoveArbitraryNPC:
ld a, [wLoadedNPCTempIndex]
push af
ld a, [wTempNPC]
push af
ld a, c
push af
call GetScriptArgs2AfterPointer
push bc
call IncreaseScriptPointerBy1
pop bc
pop af
jr ExecuteArbitraryNPCMovementFromStack
ScriptCommand_CloseTextBox:
call CloseTextBox
jp IncreaseScriptPointerBy1
; args: booster pack index, booster pack index, booster pack index
ScriptCommand_GiveBoosterPacks:
xor a
ld [wAnotherBoosterPack], a
push bc
call Func_c2a3
pop bc
push bc
ld a, c
farcall GiveBoosterPack
ld a, TRUE
ld [wAnotherBoosterPack], a
pop bc
ld a, b
cp NO_BOOSTER
jr z, .done
farcall GiveBoosterPack
call GetScriptArgs3AfterPointer
ld a, c
cp NO_BOOSTER
jr z, .done
farcall GiveBoosterPack
.done
call ReturnToOverworldNoCallback
jp IncreaseScriptPointerBy4
ScriptCommand_GiveOneOfEachTrainerBooster:
xor a
ld [wAnotherBoosterPack], a
call Func_c2a3
ld hl, .booster_type_table
.loop
ld a, [hl]
cp NO_BOOSTER
jr z, .done
push hl
farcall GiveBoosterPack
ld a, TRUE
ld [wAnotherBoosterPack], a
pop hl
inc hl
jr .loop
.done
call ReturnToOverworldNoCallback
jp IncreaseScriptPointerBy1
.booster_type_table
db BOOSTER_COLOSSEUM_TRAINER
db BOOSTER_EVOLUTION_TRAINER
db BOOSTER_MYSTERY_TRAINER_COLORLESS
db BOOSTER_LABORATORY_TRAINER
db NO_BOOSTER ; $ff
; Shows the card received screen for a given promotional card
; arg can either be the card, $00 for a wram card, or $ff for the 4 legendary cards
ScriptCommand_ShowCardReceivedScreen:
call Func_c2a3
ld a, c
cp $ff
jr z, .legendary_card
or a
jr nz, .show_card
ld a, [wCardReceived]
.show_card
push af