-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathcontest_link_util.c
2911 lines (2718 loc) · 86.8 KB
/
contest_link_util.c
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
#include "global.h"
#include "contest_link_util.h"
#include "battle.h"
#include "blend_palette.h"
#include "constants/songs.h"
#include "contest.h"
#include "contest_link.h"
#include "data2.h"
#include "decompress.h"
#include "event_data.h"
#include "ewram.h"
#include "field_effect.h"
#include "field_specials.h"
#include "graphics.h"
#include "link.h"
#include "main.h"
#include "menu.h"
#include "overworld.h"
#include "palette.h"
#include "pokedex.h"
#include "pokemon_icon.h"
#include "pokemon_storage_system.h"
#include "random.h"
#include "scanline_effect.h"
#include "script.h"
#include "sound.h"
#include "string_util.h"
#include "strings2.h"
#include "text.h"
#include "trig.h"
#include "tv.h"
#include "util.h"
#define ABS(x) ((x) < 0 ? -(x) : (x))
#define GET_CONTEST_WINNER(var) { \
for ((var) = 0; (var) < 4; (var)++) \
{ \
if (gContestFinalStandings[i] == 0) \
break; \
} \
}
struct UnkEwramStruct18000 {
u8 unk_00;
u8 unk_01;
u8 unk_02;
u8 unk_03;
u8 unk_04;
u8 unk_05;
u8 unk_06;
u8 unk_07;
u8 unk_08;
u8 unk_09;
u8 unk_0a;
s16 unk_0c[4];
u8 unk_14;
};
struct UnkEwramStruct18018 {
s32 unk_00;
s32 unk_04;
u32 unk_08;
u32 unk_0c;
u8 unk_10;
u8 unk_11;
u8 unk_12;
};
#define eContestLink80C2020Struct2018000 (*(struct UnkEwramStruct18000 *)(gSharedMem + 0x18000))
#define eContestLink80C2020Struct2018018 ((struct UnkEwramStruct18018 *)(gSharedMem + 0x18018))
#define eContestLink80C2020Struct2018068 (gSharedMem + 0x18068)
static void sub_80C2430(void);
static void sub_80C2448(void);
static void sub_80C24F4(u8 taskId);
static void sub_80C255C(u8 taskId);
static void sub_80C25A4(u8 taskId);
static void sub_80C25C0(u8 taskId);
static void sub_80C2600(u8 taskId);
static void sub_80C26E4(u8 taskId);
static void sub_80C2770(u8 taskId);
static void sub_80C27EC(u8 taskId);
static void sub_80C2878(u8 taskId);
static void sub_80C2A8C(u8 taskId);
static void sub_80C2D1C(u8 taskId);
static void sub_80C2D80(u8 taskId);
static void sub_80C2DD8(u8 taskId);
static void sub_80C2E14(u8 taskId);
static void sub_80C2EA0(u8 taskId);
static void sub_80C2F28(u8 taskId);
static void sub_80C2F64(u8 taskId);
static void LoadAllContestMonIcons(u8 srcOffset, bool8 useDmaNow);
void sub_80C310C(void);
void sub_80C3158(const u8 *string, u8 spriteId);
void sub_80C33DC(void);
u16 sub_80C34AC(const u8 *string);
void sub_80C34CC(s16 data4, u16 pos0y, u16 data5, u16 data6);
void sub_80C3520(u16 a0);
void sub_80C3588(struct Sprite *sprite);
void sub_80C35FC(struct Sprite *sprite);
void sub_80C3630(struct Sprite *sprite);
void sub_80C3698(const u8 *string);
void sub_80C3764(void);
void sub_80C37E4(void);
u8 sub_80C3990(u8 a0, u8 a1);
s8 sub_80C39E4(u8 a0, u8 a1);
void sub_80C3A5C(u8 taskId);
void sub_80C3BD8(u8 taskId);
void sub_80C3B30(u8 taskId);
void sub_80C3C44(struct Sprite *sprite);
void sub_80C3CB8(struct Sprite *sprite);
void sub_80C3D04(u8 taskId);
void sub_80C3DF0(struct Sprite *sprite);
void sub_80C3E60(u8 a0, u8 a1);
void sub_80C3EA4(u8 taskId);
void sub_80C3F00(void);
void sub_80C40D4(u8 a0, u8 a1);
void sub_80C42C0(u8 taskId);
void Task_StartCommunication(u8 taskId);
void Task_StartCommunicateRng(u8 taskId);
void Task_StartCommunicateLeaderIds(u8 taskId);
void Task_StartCommunicateCategory(u8 taskId);
void Task_LinkContest_SetUpContest(u8 taskId);
void Task_LinkContest_CalculateTurnOrder(u8 taskId);
void Task_LinkContest_FinalizeConnection(u8 taskId);
void Task_LinkContest_Disconnect(u8 taskId);
void Task_LinkContest_WaitDisconnect(u8 taskId);
const u16 gUnknown_083D1624[] = INCBIN_U16("graphics/unknown/unknown_3D1624/0.4bpp");
const u16 gUnknown_083D1644[] = INCBIN_U16("graphics/unknown/unknown_3D1624/1.4bpp");
const u16 gUnknown_083D1664[] = INCBIN_U16("graphics/unknown/unknown_3D1624/2.4bpp");
const u16 gUnknown_083D1684[] = INCBIN_U16("graphics/unknown/unknown_3D1624/3.4bpp");
const u16 gUnknown_083D16A4[] = INCBIN_U16("graphics/unknown/unknown_3D1624/4.4bpp");
const u16 gUnknown_083D16C4[] = INCBIN_U16("graphics/unknown/unknown_3D1624/5.4bpp");
const u16 gUnknown_083D16E4[] = INCBIN_U16("graphics/unknown/unknown_3D1624/6.4bpp");
const u16 gUnknown_083D1704[] = INCBIN_U16("graphics/unknown/unknown_3D1624/7.4bpp");
const u16 gMiscBlank_Pal[] = INCBIN_U16("graphics/interface/blank.gbapal");
const struct OamData gOamData_83D1744 = {
.shape = ST_OAM_H_RECTANGLE,
.size = 3,
.priority = 3,
.paletteNum = 2
};
const struct SpriteTemplate gSpriteTemplate_83D174C = {
0xbc1,
0xbc1,
&gOamData_83D1744,
gDummySpriteAnimTable,
NULL,
gDummySpriteAffineAnimTable,
SpriteCallbackDummy
};
const struct SpriteSheet gUnknown_083D1764[] = {
{gMiscBlank_Gfx, 0x400, 0xbc1},
{gMiscBlank_Gfx, 0x400, 0xbc2},
{gMiscBlank_Gfx, 0x400, 0xbc3},
{gMiscBlank_Gfx, 0x400, 0xbc4},
{gMiscBlank_Gfx, 0x400, 0xbc5},
{gMiscBlank_Gfx, 0x400, 0xbc6},
{gMiscBlank_Gfx, 0x400, 0xbc7},
{gMiscBlank_Gfx, 0x400, 0xbc8},
};
const struct SpritePalette gUnknown_083D17A4 = {
gMiscBlank_Pal, 0xbc1
};
const struct OamData gOamData_83D17AC = {};
const struct SpriteTemplate gSpriteTemplate_83D17B4 = {
0xbc9,
0xbc9,
&gOamData_83D17AC,
gDummySpriteAnimTable,
NULL,
gDummySpriteAffineAnimTable,
sub_80C3DF0
};
const struct CompressedSpriteSheet gUnknown_083D17CC = {gContestConfetti_Gfx, 0x220, 0xbc9};
const struct CompressedSpritePalette gUnknown_083D17D4 = {gContestConfetti_Pal, 0xbc9};
const u8 gUnknown_083D17DC[] = _("{COLOR RED}");
const u8 gUnknown_083D17E0[] = _("/");
const u8 gUnknown_083D17E2[] = _("{SIZE 3}{COLOR_HIGHLIGHT_SHADOW WHITE2 DARK_GREY LIGHT_BLUE}");
void sub_80C2020(void)
{
REG_DISPCNT = DISPCNT_OBJ_1D_MAP;
Text_LoadWindowTemplate(&gWindowTemplate_81E6FA0);
Text_InitWindowWithTemplate(&gMenuWindow, &gWindowTemplate_81E6FA0);
REG_BG0CNT = BGCNT_WRAP | BGCNT_SCREENBASE(30);
REG_BG1CNT = BGCNT_PRIORITY(3) | BGCNT_SCREENBASE(24);
REG_BG2CNT = BGCNT_PRIORITY(3) | BGCNT_SCREENBASE(28);
REG_BG3CNT = BGCNT_WRAP | BGCNT_PRIORITY(3) | BGCNT_SCREENBASE(26);
REG_MOSAIC = 0;
REG_WININ = 0x3f3f;
REG_WINOUT = 0x3f2e;
REG_WIN0H = 0;
REG_WIN0V = 0;
REG_WIN1H = 0;
REG_WIN1V = 0;
REG_BLDCNT = 0;
REG_BLDALPHA = 0;
REG_BLDY = 0;
REG_BG0HOFS = 0;
REG_BG0VOFS = 0;
REG_BG1HOFS = 0;
REG_BG1VOFS = 0;
REG_BG2HOFS = 0;
REG_BG2VOFS = 0;
REG_BG3HOFS = 0;
REG_BG3VOFS = 0;
REG_DISPCNT |= DISPCNT_BG_ALL_ON | DISPCNT_OBJ_ON | DISPCNT_WIN0_ON | DISPCNT_WIN1_ON;
gBattle_BG0_X = 0;
gBattle_BG0_Y = 0;
gBattle_BG1_X = 0;
gBattle_BG1_Y = 0;
gBattle_BG2_X = 0;
gBattle_BG2_Y = 0;
gBattle_BG3_X = 0;
gBattle_BG3_Y = 0;
gBattle_WIN0H = 0;
gBattle_WIN0V = 0;
gBattle_WIN1H = 0;
gBattle_WIN1V = 0;
}
void sub_80C2144(void)
{
int i;
int j;
s8 r7;
s8 r4;
u16 r6;
u16 r3;
DmaFill32Large(3, 0, VRAM, VRAM_SIZE, 0x1000);
LZDecompressVram(gUnknown_08D1977C, BG_SCREEN_ADDR(0));
LZDecompressVram(gUnknown_08D1A490, BG_SCREEN_ADDR(26));
LZDecompressVram(gUnknown_08D1A364, BG_SCREEN_ADDR(28));
LZDecompressVram(gUnknown_08D1A250, BG_SCREEN_ADDR(30));
sub_80C37E4();
LoadCompressedPalette(gUnknown_08D1A618, 0, 0x200);
LoadFontDefaultPalette(&gWindowTemplate_81E6FA0);
for (i = 0; i < 4; i++)
{
r7 = sub_80C3990(i, 1);
r4 = sub_80C39E4(i, 1);
for (j = 0; j < 10; j++)
{
r6 = 0x60b2;
if (j < r7)
r6 = 0x60b4;
if (j < ABS(r4))
{
r3 = 0x60a4;
if (r4 < 0)
r3 = 0x60a6;
}
else
r3 = 0x60a2;
((u16 *)BG_VRAM)[i * 0x60 + j + 0x60b3] = r6;
((u16 *)BG_VRAM)[i * 0x60 + j + 0x60d3] = r3;
}
}
}
void sub_80C226C(u8 a0)
{
u8 *strbuf;
if (a0 == gContestPlayerMonIndex)
strbuf = StringCopy(gDisplayedStringBattle, gUnknown_083D17DC);
else
strbuf = gDisplayedStringBattle;
strbuf[0] = EXT_CTRL_CODE_BEGIN;
strbuf[1] = 0x06;
strbuf[2] = 0x04;
strbuf += 3;
strbuf = StringCopy(strbuf, gContestMons[a0].nickname);
strbuf[0] = EXT_CTRL_CODE_BEGIN;
strbuf[1] = 0x13;
strbuf[2] = 0x32;
strbuf += 3;
strbuf = StringCopy(strbuf, gUnknown_083D17E0);
if (gIsLinkContest & 1)
StringCopy(strbuf, gLinkPlayers[a0].name);
else
StringCopy(strbuf, gContestMons[a0].trainerName);
Text_InitWindowAndPrintText(&gMenuWindow, gDisplayedStringBattle, a0 * 36 + 770, 7, a0 * 3 + 4);
}
void sub_80C2340(void)
{
int i;
for (i = 0; i < 4; i++)
sub_80C226C(i);
}
void sub_80C2358(void)
{
gPaletteFade.bufferTransferDisabled = TRUE;
SetVBlankCallback(NULL);
sub_80C2020();
ScanlineEffect_Clear();
ResetPaletteFade();
ResetSpriteData();
ResetTasks();
FreeAllSpritePalettes();
sub_80C2144();
sub_80C310C();
LoadAllContestMonIcons(0, TRUE);
sub_80C2340();
eContestLink80C2020Struct2018000 = (struct UnkEwramStruct18000){};
memset(eContestLink80C2020Struct2018018, 0, 4 * sizeof(struct UnkEwramStruct18018));
sub_80C33DC();
BeginNormalPaletteFade(0xffffffff, 0, 16, 0, 0);
gPaletteFade.bufferTransferDisabled = FALSE;
eContestLink80C2020Struct2018000.unk_02 = CreateTask(sub_80C24F4, 5);
SetMainCallback2(sub_80C2430);
gBattle_WIN1H = 0xf0;
gBattle_WIN1V = 0x80a0;
CreateTask(sub_80C2F28, 20);
sub_80C3F00();
PlayBGM(MUS_CONTEST_RESULTS);
SetVBlankCallback(sub_80C2448);
}
static void sub_80C2430(void)
{
AnimateSprites();
BuildOamBuffer();
RunTasks();
UpdatePaletteFade();
}
static void sub_80C2448(void)
{
REG_BG0HOFS = gBattle_BG0_X;
REG_BG0VOFS = gBattle_BG0_Y;
REG_BG1HOFS = gBattle_BG1_X;
REG_BG1VOFS = gBattle_BG1_Y;
REG_BG2HOFS = gBattle_BG2_X;
REG_BG2VOFS = gBattle_BG2_Y;
REG_BG3HOFS = gBattle_BG3_X;
REG_BG3VOFS = gBattle_BG3_Y;
REG_WIN0H = gBattle_WIN0H;
REG_WIN0V = gBattle_WIN0V;
REG_WIN1H = gBattle_WIN1H;
REG_WIN1V = gBattle_WIN1V;
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
ScanlineEffect_InitHBlankDmaTransfer();
}
static void sub_80C24F4(u8 taskId)
{
if (!gPaletteFade.active)
{
if (gIsLinkContest & 1)
{
sub_80C3698(gOtherText_LinkStandby);
gTasks[taskId].func = sub_80C255C;
}
else
{
gTasks[taskId].func = sub_80C2600;
}
}
}
static void sub_80C255C(u8 taskId)
{
if (gReceivedRemoteLinkPlayers && GetLinkPlayerCount() == MAX_LINK_PLAYERS)
{
CreateTask(sub_80C25A4, 0);
gTasks[taskId].func = TaskDummy;
}
}
static void sub_80C25A4(u8 taskId)
{
SetTaskFuncWithFollowupFunc(taskId, Task_LinkContest_CommunicateMonIdxs, sub_80C25C0);
}
static void sub_80C25C0(u8 taskId)
{
if (IsLinkTaskFinished())
{
DestroyTask(taskId);
gTasks[eContestLink80C2020Struct2018000.unk_02].func = sub_80C2600;
sub_80C3764();
}
}
static void sub_80C2600(u8 taskId)
{
if (gTasks[taskId].data[0] == 0)
{
CreateTask(sub_80C2F64, 20);
sub_80C3158(gContestText_AnnounceResults, eContestLink80C2020Struct2018000.unk_00);
sub_80C34CC(sub_80C34AC(gContestText_AnnounceResults), 0x90, 0x78, 0x440);
gTasks[taskId].data[0]++;
}
else if (gTasks[taskId].data[0] == 1)
{
if (eContestLink80C2020Struct2018000.unk_04 == 0)
{
gTasks[taskId].data[1] = 0;
gTasks[taskId].data[0]++;
}
}
else if (gTasks[taskId].data[0] == 2)
{
if (++gTasks[taskId].data[1] == 0x15)
{
gTasks[taskId].data[1] = 0;
gTasks[taskId].data[0]++;
}
}
else if (gTasks[taskId].data[0] == 3)
{
sub_80C3158(gContestText_PreliminaryResults, eContestLink80C2020Struct2018000.unk_00);
sub_80C34CC(sub_80C34AC(gContestText_PreliminaryResults), 0x90, 0xffff, 0x440);
gTasks[taskId].data[0]++;
}
else if (gTasks[taskId].data[0] == 4)
{
if (eContestLink80C2020Struct2018000.unk_04 == 2)
{
gTasks[taskId].data[0] = 0;
gTasks[taskId].func = sub_80C26E4;
}
}
}
static void sub_80C26E4(u8 taskId)
{
switch (gTasks[taskId].data[0])
{
case 0:
if (eContestLink80C2020Struct2018000.unk_0a == 0)
{
sub_80C40D4(0, gTasks[taskId].data[2]++);
if (eContestLink80C2020Struct2018000.unk_14 == 0)
{
gTasks[taskId].data[0] = 2;
}
else
{
gTasks[taskId].data[0]++;
}
}
break;
case 1:
if (eContestLink80C2020Struct2018000.unk_14 == 0)
{
gTasks[taskId].data[0] = 0;
}
break;
case 2:
sub_80C3520(0x440);
gTasks[taskId].data[0] = 0;
gTasks[taskId].data[2] = 0;
gTasks[taskId].func = sub_80C2770;
break;
}
}
static void sub_80C2770(u8 taskId)
{
if (eContestLink80C2020Struct2018000.unk_04 == 0)
{
if (++gTasks[taskId].data[1] == 21)
{
gTasks[taskId].data[1] = 0;
sub_80C3158(gContestText_Round2Results, eContestLink80C2020Struct2018000.unk_00);
sub_80C34CC(sub_80C34AC(gContestText_Round2Results), 0x90, 0xffff, 0x440);
}
}
else if (eContestLink80C2020Struct2018000.unk_04 == 2)
{
gTasks[taskId].func = sub_80C27EC;
}
}
static void sub_80C27EC(u8 taskId)
{
switch (gTasks[taskId].data[0])
{
case 0:
if (eContestLink80C2020Struct2018000.unk_0a == 0)
{
sub_80C40D4(1, gTasks[taskId].data[2]++);
if (eContestLink80C2020Struct2018000.unk_14 == 0)
{
gTasks[taskId].data[0] = 2;
}
else
{
gTasks[taskId].data[0]++;
}
}
break;
case 1:
if (eContestLink80C2020Struct2018000.unk_14 == 0)
{
gTasks[taskId].data[0] = 0;
}
break;
case 2:
sub_80C3520(0x440);
gTasks[taskId].data[0] = 0;
gTasks[taskId].func = sub_80C2878;
break;
}
}
static void sub_80C2878(u8 taskId)
{
int i;
u8 taskId2;
u8 strbuf[100];
switch (gTasks[taskId].data[0])
{
case 0:
if (eContestLink80C2020Struct2018000.unk_04 == 0)
gTasks[taskId].data[0]++;
break;
case 1:
if (++gTasks[taskId].data[1] == 31)
{
gTasks[taskId].data[1] = 0;
gTasks[taskId].data[0]++;
}
break;
case 2:
for (i = 0; i < 4; i++)
{
taskId2 = CreateTask(sub_80C3A5C, 10);
gTasks[taskId2].data[0] = gContestFinalStandings[i];
gTasks[taskId2].data[1] = i;
}
gTasks[taskId].data[0]++;
break;
case 3:
if (eContestLink80C2020Struct2018000.unk_05 == 4)
{
if (++gTasks[taskId].data[1] == 31)
{
gTasks[taskId].data[1] = 0;
CreateTask(sub_80C3B30, 10);
gTasks[taskId].data[0]++;
GET_CONTEST_WINNER(i);
sub_80C3E60(i, 14);
}
}
break;
case 4:
if (++gTasks[taskId].data[1] == 21)
{
gTasks[taskId].data[1] = 0;
GET_CONTEST_WINNER(i);
if (gIsLinkContest & 1)
{
StringCopy(gStringVar1, gLinkPlayers[i].name);
}
else
{
StringCopy(gStringVar1, gContestMons[i].trainerName);
}
StringCopy(gStringVar2, gContestMons[i].nickname);
StringExpandPlaceholders(strbuf, gContestText_PokeWon);
sub_80C3158(strbuf, eContestLink80C2020Struct2018000.unk_00);
sub_80C34CC(sub_80C34AC(strbuf), 0x90, 0xffff, 0x440);
gTasks[taskId].data[0]++;
}
break;
case 5:
gTasks[taskId].data[0] = 0;
gTasks[taskId].func = sub_80C2A8C;
break;
}
}
static void sub_80C2A8C(u8 taskId)
{
int i;
u8 spriteId;
u16 species;
u32 personality;
u32 otId;
const struct CompressedSpritePalette *monPal;
switch (gTasks[taskId].data[0])
{
case 0:
gBattle_WIN0H = 0xf0;
gBattle_WIN0V = 0x5050;
GET_CONTEST_WINNER(i);
species = gContestMons[i].species;
personality = gContestMons[i].personality;
otId = gContestMons[i].otId;
HandleLoadSpecialPokePic(gMonFrontPicTable + species, gMonFrontPicCoords[species].coords, gMonFrontPicCoords[species].y_offset, (void *)gSharedMem, gMonSpriteGfx_Sprite_ptr[1], species, personality);
monPal = GetMonSpritePalStructFromOtIdPersonality(species, otId, personality);
LoadCompressedObjectPalette(monPal);
GetMonSpriteTemplate_803C56C(species, 1);
gCreatingSpriteTemplate.paletteTag = monPal->tag;
spriteId = CreateSprite(&gCreatingSpriteTemplate, 0x110, 0x50, 10);
gSprites[spriteId].data[1] = species;
gSprites[spriteId].oam.priority = 0;
gSprites[spriteId].callback = sub_80C3C44;
eContestLink80C2020Struct2018000.unk_08 = spriteId;
LoadCompressedObjectPic(&gUnknown_083D17CC);
LoadCompressedObjectPalette(&gUnknown_083D17D4);
CreateTask(sub_80C3D04, 10);
gTasks[taskId].data[0]++;
break;
case 1:
if (++gTasks[taskId].data[3] == 1)
{
u8 win0v;
gTasks[taskId].data[3] = 0;
gTasks[taskId].data[2] += 2;
if (gTasks[taskId].data[2] > 0x20)
gTasks[taskId].data[2] = 0x20;
win0v = gTasks[taskId].data[2];
gBattle_WIN0V = ((0x50 - win0v) << 8) | (0x50 + win0v);
if (win0v == 0x20)
{
gTasks[taskId].data[0]++;
}
}
break;
case 2:
if (eContestLink80C2020Struct2018000.unk_06 == 1)
{
gTasks[taskId].data[0]++;
}
break;
case 3:
if (++gTasks[taskId].data[1] == 121)
{
gTasks[taskId].data[1] = 0;
gSprites[eContestLink80C2020Struct2018000.unk_08].callback = sub_80C3CB8;
gTasks[taskId].data[0]++;
}
break;
case 4:
if (eContestLink80C2020Struct2018000.unk_06 == 2)
{
u8 win0v = (gBattle_WIN0V >> 8);
win0v += 2;
if (win0v > 0x50)
win0v = 0x50;
gBattle_WIN0V = (win0v << 8) | (0xa0 - win0v);
if (win0v == 0x50)
{
gTasks[taskId].data[0]++;
}
}
break;
case 5:
if (eContestLink80C2020Struct2018000.unk_06 == 2)
{
eContestLink80C2020Struct2018000.unk_09 = 1;
gTasks[taskId].data[0] = 0;
gTasks[taskId].func = sub_80C2D1C;
}
break;
}
}
static void sub_80C2D1C(u8 taskId)
{
int i;
if (gMain.newKeys & A_BUTTON)
{
if (!(gIsLinkContest & 1))
{
for (i = 0; i < 4; i++)
{
GetSetPokedexFlag(SpeciesToNationalPokedexNum(gContestMons[i].species), FLAG_SET_SEEN);
}
}
gTasks[taskId].func = sub_80C2D80;
}
}
static void sub_80C2D80(u8 taskId)
{
if (gIsLinkContest & 1)
{
sub_80C3698(gOtherText_LinkStandby);
SetCloseLinkCallback();
gTasks[taskId].func = sub_80C2DD8;
}
else
{
gTasks[taskId].func = sub_80C2E14;
}
}
static void sub_80C2DD8(u8 taskId)
{
if (gReceivedRemoteLinkPlayers == 0)
{
gIsLinkContest = 0;
sub_80C3764();
gTasks[taskId].func = sub_80C2E14;
}
}
static void sub_80C2E14(u8 taskId)
{
sub_80BE284(gContestFinalStandings[gContestPlayerMonIndex]);
sub_810FB10(2);
Contest_SaveWinner(gSpecialVar_ContestRank);
Contest_SaveWinner(0xFE);
eCurContestWinnerIsForArtist = TRUE;
eCurContestWinnerSaveIdx = GetContestWinnerSaveIdx(0xfe, 0);
BeginHardwarePaletteFade(0xff, 0, 0, 16, 0);
gTasks[taskId].func = sub_80C2EA0;
}
static void sub_80C2EA0(u8 taskId)
{
if (!gPaletteFade.active)
{
if (gTasks[taskId].data[1] == 0)
{
DestroyTask(eContestLink80C2020Struct2018000.unk_03);
BlendPalettes(0x0000ffff, 16, 0);
gTasks[taskId].data[1]++;
}
else if (gTasks[taskId].data[1] == 1)
{
BlendPalettes(0xffff0000, 16, 0);
gTasks[taskId].data[1]++;
}
else
{
REG_BLDCNT = 0;
REG_BLDY = 0;
DestroyTask(taskId);
SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
}
}
}
static void sub_80C2F28(u8 taskId)
{
gBattle_BG3_X += 2;
gBattle_BG3_Y++;
if (gBattle_BG3_X > 0xff)
gBattle_BG3_X -= 0xff;
if (gBattle_BG3_Y > 0xff)
gBattle_BG3_Y -= 0xff;
}
static void sub_80C2F64(u8 taskId)
{
if (++gTasks[taskId].data[0] == 2)
{
gTasks[taskId].data[0] = 0;
if (gTasks[taskId].data[2] == 0)
gTasks[taskId].data[1]++;
else
gTasks[taskId].data[1]--;
if (gTasks[taskId].data[1] == 16)
gTasks[taskId].data[2] = 1;
else if (gTasks[taskId].data[1] == 0)
gTasks[taskId].data[2] = 0;
BlendPalette(0x6b, 0x01, gTasks[taskId].data[1], RGB(30, 22, 11));
BlendPalette(0x68, 0x01, gTasks[taskId].data[1], RGB(31, 31, 31));
BlendPalette(0x6e, 0x01, gTasks[taskId].data[1], RGB(30, 29, 29));
}
if (gTasks[taskId].data[1] == 0)
eContestLink80C2020Struct2018000.unk_0a = 0;
else
eContestLink80C2020Struct2018000.unk_0a = 1;
}
void sub_80C3024(u16 species, u8 destOffset, u8 srcOffset, bool8 useDmaNow, u32 personality)
{
int i;
int j;
u16 tile;
u16 offset;
u16 var0;
u16 var1;
if (useDmaNow)
{
DmaCopy32Defvars(3, GetMonIconPtr(species, personality) + (srcOffset << 9) + 0x80, BG_CHAR_ADDR(1) + (destOffset << 9), 0x180);
var0 = ((destOffset + 10) << 12);
var1 = (destOffset * 16 + 0x200);
tile = var1 | var0;
offset = destOffset * 0x60 + 0x83;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 4; j++)
{
((u16 *)BG_CHAR_ADDR(3))[(i << 5) + j + offset] = tile;
tile++;
}
}
}
else
{
RequestSpriteCopy(GetMonIconPtr(species, personality) + (srcOffset << 9) + 0x80, BG_CHAR_ADDR(1) + (destOffset << 9), 0x180);
}
}
static void LoadAllContestMonIcons(u8 srcOffset, bool8 useDmaNow)
{
int i;
for (i = 0; i < 4; i++)
{
sub_80C3024(gContestMons[i].species, i, srcOffset, useDmaNow, gContestMons[i].personality);
}
}
void sub_80C310C(void)
{
int i;
register u16 species asm("r0");
for (i = 0; i < 4; i++)
{
species = mon_icon_convert_unown_species_id(gContestMons[i].species, 0);
LoadPalette(gMonIconPalettes[gMonIconPaletteIndices[species]], 0xa0 + 0x10 * i, 0x20);
}
}
#ifdef NONMATCHING
void sub_80C3158(const u8 *string, u8 spriteId)
{
int i, j;
u8 width;
u8 * displayedStringBattle;
void * dest;
u8 * d1;
u8 * d2;
void *d3;
void *d4;
void *d5;
void *d6;
int w;
u16 sp00[4];
struct Sprite *sprite = &gSprites[spriteId];
sp00[0] = gSprites[spriteId].oam.tileNum;
sp00[1] = gSprites[sprite->data[0]].oam.tileNum;
sp00[2] = gSprites[sprite->data[1]].oam.tileNum;
sp00[3] = gSprites[sprite->data[2]].oam.tileNum;
for (i = 0; i < 4; i++)
{
DmaClear32(3, (void *)VRAM + 0x10000 + 32 * sp00[i], 0x400);
}
width = Text_GetStringWidthFromWindowTemplate(&gWindowTemplate_81E7278, string);
displayedStringBattle = gDisplayedStringBattle;
displayedStringBattle = StringCopy(displayedStringBattle, gUnknown_083D17E2);
if ((~width + 1) & 7)
{
displayedStringBattle[0] = EXT_CTRL_CODE_BEGIN;
displayedStringBattle[1] = 0x11;
displayedStringBattle[2] = ((~width + 1) & 7) / 2;
displayedStringBattle += 3;
}
width += -8 & (width + 7);
displayedStringBattle = StringCopy(displayedStringBattle, string);
displayedStringBattle[0] = EXT_CTRL_CODE_BEGIN;
displayedStringBattle[1] = 0x13;
displayedStringBattle[2] = width;
displayedStringBattle[3] = EOS;
RenderTextHandleBold(eContestLink80C2020Struct2018068, gDisplayedStringBattle);
CpuCopy32(&gUnknown_083D1624[0x0], (void *)(VRAM + 0x10000) + 32 * sp00[0], 32);
CpuCopy32(&gUnknown_083D1624[0x40], (void *)(VRAM + 0x10000) + 32 * sp00[0] + 0x100, 32);
CpuCopy32(&gUnknown_083D1624[0x40], (void *)(VRAM + 0x10000) + 32 * sp00[0] + 0x200, 32);
CpuCopy32(&gUnknown_083D1624[0x20], (void *)(VRAM + 0x10000) + 32 * sp00[0] + 0x300, 32);
w = width / 8;
j = 0;
if (j <= w)
{
d2 = eContestLink80C2020Struct2018068 + 0x20;
d1 = eContestLink80C2020Struct2018068;
d3 = (void *)VRAM + 0x0FD20;
d4 = (void *)VRAM + 0x0FE20;
d5 = (void *)VRAM + 0x0FF20;
d6 = (void *)VRAM + 0x10020;
while (j <= w)
{
if (j < 7)
dest = 32 * sp00[0] + d6;
else if (j < 15)
dest = 32 * sp00[1] + d5;
else if (j < 23)
dest = 32 * sp00[2] + d4;
else
dest = 32 * sp00[3] + d3;
if (j == w)
break;
CpuCopy32(gUnknown_083D16E4, dest, 32);
CpuCopy32(gUnknown_083D16E4 + 0x10, dest + 0x300, 32);
CpuCopy32(j * 0x40 + d2, dest + 0x100, 32);
CpuCopy32(j * 0x40 + d1, dest + 0x200, 32);
d3 += 0x20;
d4 += 0x20;
d5 += 0x20;
d6 += 0x20;
j++;
}
}
CpuCopy32(gUnknown_083D1644, dest, 32);
CpuCopy32(gUnknown_083D1644 + 0x40, dest + 0x100, 32);
CpuCopy32(gUnknown_083D1644 + 0x40, dest + 0x200, 32);
CpuCopy32(gUnknown_083D1644 + 0x20, dest + 0x300, 32);
}
#else
asm(".include \"constants/gba_constants.inc\"");
asm(".include \"include/macros.inc\"");
NAKED
void sub_80C3158(const u8 * string, u8 spriteId)
{
asm_unified("\tpush {r4-r7,lr}\n"
"\tmov r7, r10\n"
"\tmov r6, r9\n"
"\tmov r5, r8\n"
"\tpush {r5-r7}\n"
"\tsub sp, 0x1C\n"
"\tmov r9, r0\n"
"\tlsls r1, 24\n"
"\tlsrs r1, 24\n"
"\tlsls r2, r1, 4\n"
"\tadds r2, r1\n"
"\tlsls r2, 2\n"
"\tldr r3, _080C32C0 @ =gSprites\n"
"\tadds r2, r3\n"
"\tmov r1, sp\n"
"\tldrh r0, [r2, 0x4]\n"
"\tlsls r0, 22\n"
"\tlsrs r0, 22\n"
"\tstrh r0, [r1]\n"
"\tmov r4, sp\n"
"\tmovs r0, 0x2E\n"
"\tldrsh r1, [r2, r0]\n"
"\tlsls r0, r1, 4\n"
"\tadds r0, r1\n"
"\tlsls r0, 2\n"
"\tadds r0, r3\n"
"\tldrh r0, [r0, 0x4]\n"
"\tlsls r0, 22\n"
"\tlsrs r0, 22\n"
"\tstrh r0, [r4, 0x2]\n"
"\tmovs r0, 0x30\n"
"\tldrsh r1, [r2, r0]\n"
"\tlsls r0, r1, 4\n"
"\tadds r0, r1\n"
"\tlsls r0, 2\n"
"\tadds r0, r3\n"
"\tldrh r0, [r0, 0x4]\n"
"\tlsls r0, 22\n"
"\tlsrs r0, 22\n"
"\tstrh r0, [r4, 0x4]\n"
"\tmovs r0, 0x32\n"
"\tldrsh r1, [r2, r0]\n"
"\tlsls r0, r1, 4\n"
"\tadds r0, r1\n"
"\tlsls r0, 2\n"
"\tadds r0, r3\n"
"\tldrh r0, [r0, 0x4]\n"
"\tlsls r0, 22\n"
"\tlsrs r0, 22\n"
"\tstrh r0, [r4, 0x6]\n"
"\tldr r1, _080C32C4 @ =gWindowTemplate_81E7278\n"
"\tmov r8, r1\n"
"\tldr r7, _080C32C8 @ =0x06010000\n"
"\tldr r2, _080C32CC @ =0x040000d4\n"