-
Notifications
You must be signed in to change notification settings - Fork 801
/
battle_tower.asm
1592 lines (1447 loc) · 24.6 KB
/
battle_tower.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
BattleTowerRoomMenu:
; special
call InitBattleTowerChallengeRAM
farcall _BattleTowerRoomMenu
ret
Function1700ba:
; special
call InitBattleTowerChallengeRAM
farcall Function11811a
ret
Function1700c4:
ldh a, [rSVBK]
push af
ld a, BANK(w3_d202TrainerData) ; aka BANK(w3_dffc) and BANK(w3_d202Name)
ldh [rSVBK], a
call Function17042c
ld a, BANK(s5_be45) ; aka BANK(s5_be46), BANK(s5_aa41), and BANK(s5_aa5d)
call OpenSRAM
ld a, 1
ld [s5_be45], a
xor a
ld [s5_be46], a
ld hl, w3_dffc
ld de, s5_aa41
ld bc, 4
call CopyBytes
ld hl, w3_d202Name
ld de, s5_aa8e
ld bc, BATTLETOWER_STREAK_LENGTH * $cc ; length of battle tower struct from japanese games?
call CopyBytes
ld hl, s5_aa5d ; some sort of count
ld a, [hl]
inc [hl]
inc hl
sla a
sla a
ld e, a
ld d, 0
add hl, de
ld e, l
ld d, h
ld hl, w3_dffc
ld bc, 4
call CopyBytes
call CloseSRAM
pop af
ldh [rSVBK], a
ret
Function170114:
call InitBattleTowerChallengeRAM
call .Function170121
farcall Function11805f
ret
.Function170121:
ld a, BANK(s5_a948)
call OpenSRAM
ld hl, s5_a948
ld de, wc608
ld bc, 246
call CopyBytes
call CloseSRAM
call Function170c8b
ret
Function170139: ; unreferenced
; Convert the 4-digit decimal number at s5_aa41 into binary
ld a, BANK(s5_aa41)
call OpenSRAM
ld de, s5_aa41
ld h, 0
ld l, h
ld bc, 1000
call .DecToBin
ld bc, 100
call .DecToBin
ld bc, 10
call .DecToBin
ld a, [de]
ld c, a
ld b, 0
add hl, bc
call CloseSRAM
; Store that number in wc608
ld a, h
ld [wc608], a
ld a, l
ld [wc608 + 1], a
ld hl, wBT_OTTempMon1DVs
ld a, [wPlayerID]
ld [hli], a
ld a, [wPlayerID + 1]
ld [hli], a
ld a, [wSecretID]
ld [hli], a
ld a, [wSecretID + 1]
ld [hli], a
ld e, l
ld d, h
ld hl, wPlayerName
ld bc, NAME_LENGTH_JAPANESE - 1
call CopyBytes
ld bc, wPlayerID
ld de, wPlayerGender
farcall GetMobileOTTrainerClass
ld de, wBT_OTTempMon1CaughtGender
ld a, c
ld [de], a
inc de
ld a, LOW(wPartyMons)
ld [wcd49], a
ld a, HIGH(wPartyMons)
ld [wcd4a], a
ld a, LOW(wPartyMonNicknames)
ld [wcd4b], a
ld a, HIGH(wPartyMonNicknames)
ld [wcd4c], a
ld a, 3
.CopyLoop:
push af
ld a, [wcd49]
ld l, a
ld a, [wcd4a]
ld h, a
ld bc, PARTYMON_STRUCT_LENGTH
call CopyBytes
ld a, l
ld [wcd49], a
ld a, h
ld [wcd4a], a
ld a, [wcd4b]
ld l, a
ld a, [wcd4c]
ld h, a
ld bc, 6
call CopyBytes
ld a, l
ld [wcd4b], a
ld a, h
ld [wcd4c], a
pop af
dec a
jr nz, .CopyLoop
ld a, BANK(sEZChatBeginBattleMessage)
call OpenSRAM
ld hl, sEZChatBattleMessages
ld bc, EASY_CHAT_MESSAGE_LENGTH * 3
call CopyBytes
call CloseSRAM
ld a, BANK(s5_a894) ; aka BANK(s5_a948)
call OpenSRAM
ld hl, s5_a894
ld bc, 6
call CopyBytes
ld hl, wc608
ld de, s5_a948
ld bc, 246
call CopyBytes
call CloseSRAM
ret
.DecToBin:
ld a, [de]
inc de
and a
ret z
.digit_loop
add hl, bc
dec a
jr nz, .digit_loop
ret
BattleTowerBattle:
xor a ; FALSE
ld [wBattleTowerBattleEnded], a
call _BattleTowerBattle
ret
UnusedBattleTowerDummySpecial1:
ret
InitBattleTowerChallengeRAM:
xor a
ld [wBattleTowerBattleEnded], a
ld [wNrOfBeatenBattleTowerTrainers], a
ld [wcf65], a
ld [wcf66], a
ret
_BattleTowerBattle:
.loop
call .do_dw
call DelayFrame
ld a, [wBattleTowerBattleEnded]
cp TRUE
jr nz, .loop
ret
.do_dw
jumptable .dw, wBattleTowerBattleEnded
.dw
dw RunBattleTowerTrainer
dw SkipBattleTowerTrainer
RunBattleTowerTrainer:
ld a, [wOptions]
push af
ld hl, wOptions
set BATTLE_SHIFT, [hl] ; SET MODE
ld a, [wInBattleTowerBattle]
push af
or 1
ld [wInBattleTowerBattle], a
xor a
ld [wLinkMode], a
farcall StubbedTrainerRankings_Healings
farcall HealParty
call ReadBTTrainerParty
call Clears5_a89a
predef StartBattle
farcall LoadPokemonData
farcall HealParty
ld a, [wBattleResult]
ld [wScriptVar], a
and a ; WIN?
jr nz, .lost
ld a, BANK(sNrOfBeatenBattleTowerTrainers)
call OpenSRAM
ld a, [sNrOfBeatenBattleTowerTrainers]
ld [wNrOfBeatenBattleTowerTrainers], a
call CloseSRAM
ld hl, wStringBuffer3
ld a, [wNrOfBeatenBattleTowerTrainers]
add "1"
ld [hli], a
ld a, "@"
ld [hl], a
.lost
pop af
ld [wInBattleTowerBattle], a
pop af
ld [wOptions], a
ld a, TRUE
ld [wBattleTowerBattleEnded], a
ret
ReadBTTrainerParty:
; Initialise the BattleTower-Trainer and his mon
call CopyBTTrainer_FromBT_OT_TowBT_OTTemp
; Check the nicknames for illegal characters, and replace bad nicknames
; with their species names.
ld de, wBT_OTTempMon1Name
ld c, MON_NAME_LENGTH
farcall CheckStringForErrors
jr nc, .skip_mon_1
ld a, [wBT_OTTempMon1]
ld [wNamedObjectIndex], a
call GetPokemonName
ld l, e
ld h, d
ld de, wBT_OTTempMon1Name
ld bc, MON_NAME_LENGTH
call CopyBytes
.skip_mon_1
ld de, wBT_OTTempMon2Name
ld c, MON_NAME_LENGTH
farcall CheckStringForErrors
jr nc, .skip_mon_2
ld a, [wBT_OTTempMon2]
ld [wNamedObjectIndex], a
call GetPokemonName
ld l, e
ld h, d
ld de, wBT_OTTempMon2Name
ld bc, MON_NAME_LENGTH
call CopyBytes
.skip_mon_2
ld de, wBT_OTTempMon3Name
ld c, MON_NAME_LENGTH
farcall CheckStringForErrors
jr nc, .skip_mon_3
ld a, [wBT_OTTempMon3]
ld [wNamedObjectIndex], a
call GetPokemonName
ld l, e
ld h, d
ld de, wBT_OTTempMon3Name
ld bc, MON_NAME_LENGTH
call CopyBytes
.skip_mon_3
; Add the terminator character to each of these names
ld a, "@"
ld [wBT_OTTempMon1Name + MON_NAME_LENGTH - 1], a
ld [wBT_OTTempMon2Name + MON_NAME_LENGTH - 1], a
ld [wBT_OTTempMon3Name + MON_NAME_LENGTH - 1], a
; Fix errors in the movesets
call CheckBTMonMovesForErrors
; Repair the trainer name if needed, then copy it to wOTPlayerName
ld de, wBT_OTTempName
ld c, NAME_LENGTH - 1
farcall CheckStringForErrors
jr nc, .trainer_name_okay
ld hl, BT_ChrisName
jr .done_trainer_name
.trainer_name_okay
ld hl, wBT_OTTempName
.done_trainer_name
ld de, wOTPlayerName
ld bc, NAME_LENGTH - 1
call CopyBytes
ld a, "@"
ld [de], a
ld hl, wBT_OTTempTrainerClass
ld a, [hli]
ld [wOtherTrainerClass], a
ld a, LOW(wOTPartyMonNicknames)
ld [wBGMapBuffer], a
ld a, HIGH(wOTPartyMonNicknames)
ld [wBGMapBuffer + 1], a
; Copy mon into Memory from the address in hl
ld de, wOTPartyMon1Species
ld bc, wOTPartyCount
ld a, BATTLETOWER_PARTY_LENGTH
ld [bc], a
inc bc
.otpartymon_loop
push af
ld a, [hl]
ld [bc], a
inc bc
push bc
ld bc, PARTYMON_STRUCT_LENGTH
call CopyBytes
push de
ld a, [wBGMapBuffer]
ld e, a
ld a, [wBGMapBuffer + 1]
ld d, a
ld bc, MON_NAME_LENGTH
call CopyBytes
ld a, e
ld [wBGMapBuffer], a
ld a, d
ld [wBGMapBuffer + 1], a
pop de
pop bc
pop af
dec a
and a
jr nz, .otpartymon_loop
ld a, -1
ld [bc], a
ret
ValidateBTParty: ; unreferenced
; Check for and fix errors in party data
ld hl, wBT_OTTempMon1Species
ld d, BATTLETOWER_PARTY_LENGTH
.pkmn_loop
push de
push hl
ld b, h
ld c, l
ld a, [hl]
and a
for x, $ff, NUM_POKEMON, -1
jr z, .invalid
cp x
endr
jr nz, .valid
.invalid
ld a, SMEARGLE
ld [hl], a
.valid
ld [wCurSpecies], a
call GetBaseData
ld a, BANK(s5_b2fb)
call OpenSRAM
ld a, [s5_b2fb] ; s5_b2fb ; max level?
call CloseSRAM
ld e, a
ld hl, MON_LEVEL
add hl, bc
ld a, [hl]
cp MIN_LEVEL
ld a, MIN_LEVEL
jr c, .load
ld a, [hl]
cp e
jr c, .dont_load
ld a, e
.load
ld [hl], a
.dont_load
ld [wCurPartyLevel], a
ld hl, MON_MOVES
add hl, bc
ld d, NUM_MOVES - 1
ld a, [hli]
and a
jr z, .not_move
cp NUM_ATTACKS + 1
jr nc, .not_move
jr .valid_move
.not_move
dec hl
ld a, POUND
ld [hli], a
xor a
ld [hli], a
ld [hli], a
ld [hl], a
jr .done_moves
.valid_move
ld a, [hl]
cp NUM_ATTACKS + 1
jr c, .next
ld [hl], $0
.next
inc hl
dec d
jr nz, .valid_move
.done_moves
ld hl, MON_MAXHP
add hl, bc
ld d, h
ld e, l
push hl
push de
ld hl, MON_STAT_EXP - 1
add hl, bc
ld b, TRUE
predef CalcMonStats
pop de
pop hl
dec de
dec de
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
pop hl
ld bc, NICKNAMED_MON_STRUCT_LENGTH
add hl, bc
pop de
dec d
jp nz, .pkmn_loop
ret
BT_ChrisName:
db "CHRIS@"
Function17042c:
ld hl, w3_d202TrainerData
ld a, BATTLETOWER_STREAK_LENGTH
.loop
push af
push hl
ld c, BATTLETOWER_TRAINERDATALENGTH / 2
.loop2
; First byte is a comparison value.
ld a, [hli]
ld b, a
; Second byte is a lookup index.
ld a, [hli]
and a
jr z, .empty
cp (Unknown_170470.end - Unknown_170470) + 1
jr nc, .copy_data
push hl
ld hl, Unknown_170470
dec a
ld e, a
ld d, 0
add hl, de
ld a, [hl]
pop hl
; If Unknown_170470[a-1] <= b, overwrite the current trainer's data
; with Unknown_17047e, and exit the inner loop.
cp b
jr c, .copy_data
jr z, .copy_data
jr .next_iteration
.empty
; If a == 0 and b >= $fc, overwrite the current trainer's data with
; Unknown_17047e, and exit the inner loop.
ld a, b
cp NUM_POKEMON + 1
jr nc, .copy_data
.next_iteration
dec c
jr nz, .loop2
jr .next_trainer
.copy_data
pop de
push de
ld hl, Unknown_17047e
ld bc, BATTLETOWER_TRAINERDATALENGTH
call CopyBytes
.next_trainer
pop hl
ld de, BATTLE_TOWER_STRUCT_LENGTH
add hl, de
pop af
dec a
jr nz, .loop
ret
INCLUDE "data/battle_tower/unknown_levels.asm"
CopyBTTrainer_FromBT_OT_TowBT_OTTemp:
; copy the BattleTower-Trainer data that lies at 'wBT_OTTrainer' to 'wBT_OTTemp'
ldh a, [rSVBK]
push af
ld a, BANK(wBT_OTTrainer)
ldh [rSVBK], a
ld hl, wBT_OTTrainer
ld de, wBT_OTTemp
ld bc, BATTLE_TOWER_STRUCT_LENGTH
call CopyBytes
pop af
ldh [rSVBK], a
ld a, BANK(sBattleTowerChallengeState)
call OpenSRAM
ld a, BATTLETOWER_CHALLENGE_IN_PROGRESS
ld [sBattleTowerChallengeState], a
ld hl, sNrOfBeatenBattleTowerTrainers
inc [hl]
call CloseSRAM
SkipBattleTowerTrainer:
ret
Function1704ca: ; unreferenced
ld a, [s5_be46]
cp BATTLETOWER_STREAK_LENGTH
jr c, .not_max
ld a, BATTLETOWER_STREAK_LENGTH - 1
.not_max
ld hl, s5_aa8e + BATTLE_TOWER_STRUCT_LENGTH * (BATTLETOWER_STREAK_LENGTH - 1)
ld de, -BATTLE_TOWER_STRUCT_LENGTH
.loop
and a
jr z, .done
add hl, de
dec a
jr .loop
.done
ret
Function1704e1:
call SpeechTextbox
call FadeToMenu
call InitBattleTowerChallengeRAM
call .JumptableLoop
call CloseSubmenu
ret
.JumptableLoop:
call ClearBGPalettes
call ClearSprites
call ClearScreen
.loop
call JoyTextDelay
ld a, [wJumptableIndex]
bit 7, a
jr nz, .done
call .DoJumptable
farcall HDMATransferTilemapAndAttrmap_Overworld
jr .loop
.done
ret
.DoJumptable:
jumptable .dw, wJumptableIndex
.dw
dw .Jumptable_0
dw .Jumptable_1
dw .Jumptable_2
.Jumptable_0:
ld a, BANK(s5_a89c)
call OpenSRAM
ld hl, s5_a89c
ld de, wStringBuffer3
ld bc, 22
call CopyBytes
ld hl, s5_a8b2
ld de, wc608
ld bc, 150
call CopyBytes
call CloseSRAM
hlcoord 1, 1
ld de, wStringBuffer3
call PlaceString
hlcoord 1, 3
ld de, .String_Mail
call PlaceString
hlcoord 4, 3
ld de, wStringBuffer4
call PlaceString
hlcoord 8, 3
ld de, .String_PastReaders
call PlaceString
call .DrawBorder
call .PlaceTextItems
jr .NextJumptableFunction
.Jumptable_1:
call SetDefaultBGPAndOBP
call .NextJumptableFunction
.Jumptable_2:
ld hl, hJoyPressed
ld a, [hl]
and A_BUTTON
jr nz, .pressed_a_or_b
ld a, [hl]
and B_BUTTON
jr nz, .pressed_a_or_b
ld a, [hl]
and D_UP
jr nz, .pressed_up
ld a, [hl]
and D_DOWN
jr nz, .pressed_down
ret
.pressed_up
ld a, [wNrOfBeatenBattleTowerTrainers]
and a
ret z
sub 15
ld [wNrOfBeatenBattleTowerTrainers], a
call .PlaceTextItems
ret
.pressed_down
ld a, [wNrOfBeatenBattleTowerTrainers]
cp 60
ret z
add 15
ld [wNrOfBeatenBattleTowerTrainers], a
call .PlaceTextItems
ret
.pressed_a_or_b
ld hl, wJumptableIndex
set 7, [hl]
ret
.NextJumptableFunction:
ld hl, wJumptableIndex
inc [hl]
ret
.DrawBorder:
hlcoord 0, 4
ld a, "┌"
ld [hli], a
ld c, SCREEN_WIDTH - 2
.top_border_loop
ld a, "─"
ld [hli], a
dec c
jr nz, .top_border_loop
ld a, "┐"
ld [hli], a
ld de, SCREEN_WIDTH
ld c, 12
.left_border_loop
ld a, "│"
ld [hl], a
add hl, de
dec c
jr nz, .left_border_loop
ld a, "└"
ld [hli], a
ld c, SCREEN_WIDTH - 2
.bottom_border_loop
ld a, "─"
ld [hli], a
dec c
jr nz, .bottom_border_loop
ld a, "┘"
ld [hl], a
ld de, -SCREEN_WIDTH
add hl, de
ld c, 12
.right_border_loop
ld a, "│"
ld [hl], a
add hl, de
dec c
jr nz, .right_border_loop
ret
.PlaceTextItems:
call .ClearBox
call .PlaceUpDownArrows
ld a, $50
ld [wcd4e], a
ld hl, wc608
ld a, [wNrOfBeatenBattleTowerTrainers]
ld c, a
xor a
ld b, a
add hl, bc
push hl
pop bc
hlcoord 1, 6
ld a, 6
.loop1
push af
push hl
ld a, 3
.loop2
push af
ld de, wcd49
ld a, [bc]
and a
jr z, .fill_with_e3
; .copy
ld a, 5
.loop3a
push af
ld a, [bc]
ld [de], a
inc bc
inc de
pop af
dec a
jr nz, .loop3a
jr .rejoin
.fill_with_e3
ld a, 5
.loop3b
push af
ld a, $e3
ld [de], a
inc de
inc bc
pop af
dec a
jr nz, .loop3b
.rejoin
ld de, wcd49
push bc
call PlaceString
ld de, NAME_LENGTH_JAPANESE
add hl, de
pop bc
pop af
dec a
jr nz, .loop2
pop hl
ld de, $28
add hl, de
pop af
dec a
jr nz, .loop1
ret
.ClearBox:
hlcoord 1, 5
xor a
ld b, 12
.clearbox_row
ld c, SCREEN_WIDTH - 2
.clearbox_column
ld [hli], a
dec c
jr nz, .clearbox_column
inc hl
inc hl
dec b
jr nz, .clearbox_row
ret
.PlaceUpDownArrows:
ld a, [wNrOfBeatenBattleTowerTrainers]
and a
jr z, .nope
hlcoord 18, 5
ld a, "▲"
ld [hl], a
.nope
ld a, [wNrOfBeatenBattleTowerTrainers]
cp 60
ret z
hlcoord 18, 16
ld a, "▼"
ld [hl], a
ret
.String_Mail:
db "ルーム@"
.String_PastReaders:
db "れきだいりーダーいちらん@"
BattleTowerAction:
jumptable .dw, wScriptVar
.dw
dw BattleTowerAction_CheckExplanationRead
dw BattleTowerAction_SetExplanationRead
dw BattleTowerAction_GetChallengeState
dw BattleTowerAction_SetByteToQuickSaveChallenge
dw BattleTowerAction_SetByteToCancelChallenge
dw BattleTowerAction_05
dw BattleTowerAction_06
dw SaveBattleTowerLevelGroup
dw LoadBattleTowerLevelGroup
dw BattleTower_CheckSaveFileExistsAndIsYours
dw BattleTowerAction_0A
dw BattleTowerAction_GSBall
dw BattleTowerAction_0C
dw BattleTowerAction_0D
dw BattleTowerAction_EggTicket
dw BattleTowerAction_0F
dw BattleTowerAction_10
dw BattleTowerAction_11
dw BattleTowerAction_12
dw BattleTowerAction_13
dw BattleTowerAction_14
dw BattleTowerAction_15
dw BattleTowerAction_16
dw BattleTowerAction_17
dw BattleTowerAction_LevelCheck
dw BattleTowerAction_UbersCheck
dw ResetBattleTowerTrainersSRAM
dw BattleTower_GiveReward
dw BattleTowerAction_1C
dw BattleTowerAction_1D
dw BattleTower_RandomlyChooseReward
dw BattleTower_SaveOptions
; Reset the save memory for BattleTower-Trainers (Counter and all 7 TrainerBytes)
ResetBattleTowerTrainersSRAM:
ld a, BANK(sBTTrainers)
call OpenSRAM
ld a, $ff
ld hl, sBTTrainers
ld bc, BATTLETOWER_STREAK_LENGTH
call ByteFill
xor a
ld [sNrOfBeatenBattleTowerTrainers], a
call CloseSRAM
ret
BattleTower_GiveReward:
ld a, BANK(sBattleTowerReward)
call OpenSRAM
ld a, [sBattleTowerReward]
call CloseSRAM
ld [wScriptVar], a
ld hl, wNumItems
ld a, [hli]
cp MAX_ITEMS
ret c
ld b, MAX_ITEMS
ld a, [wScriptVar]
ld c, a
.loop
ld a, [hli]
cp c
jr nz, .next
ld a, [hl]
cp 95
ret c
.next
inc hl
dec b
jr nz, .loop
ld a, POTION
ld [wScriptVar], a
ret
BattleTowerAction_1C:
ld a, BANK(sBattleTowerChallengeState)
call OpenSRAM
ld a, BATTLETOWER_WON_CHALLENGE
ld [sBattleTowerChallengeState], a
call CloseSRAM
ret
BattleTowerAction_1D:
ld a, BANK(sBattleTowerChallengeState)
call OpenSRAM
ld a, BATTLETOWER_RECEIVED_REWARD
ld [sBattleTowerChallengeState], a
call CloseSRAM
ret
BattleTower_SaveOptions:
farcall SaveOptions
ret
BattleTower_RandomlyChooseReward:
; Generate a random stat boosting item.
.loop
call Random
ldh a, [hRandomAdd]
and $7
cp 6
jr c, .okay
sub 6
.okay
add HP_UP
cp LUCKY_PUNCH
jr z, .loop
push af
ld a, BANK(sBattleTowerReward)
call OpenSRAM
pop af
ld [sBattleTowerReward], a
call CloseSRAM
ret
BattleTowerAction_CheckExplanationRead:
call BattleTower_CheckSaveFileExistsAndIsYours
ld a, [wScriptVar]
and a
ret z
ld a, BANK(sBattleTowerSaveFileFlags)
call OpenSRAM
ld a, [sBattleTowerSaveFileFlags]
and 2
ld [wScriptVar], a
call CloseSRAM
ret
BattleTowerAction_GetChallengeState:
ld hl, sBattleTowerChallengeState
ld a, BANK(sBattleTowerChallengeState)
call OpenSRAM
ld a, [hl]
ld [wScriptVar], a
call CloseSRAM
ret
BattleTowerAction_SetExplanationRead:
ld a, BANK(sBattleTowerSaveFileFlags)