summaryrefslogtreecommitdiff
path: root/src/spawn_players.c
blob: 5233f428af4602d8b29eeca034d10253afdc651c (plain)
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
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
#include <defines.h>
#include <mk64.h>
#include <stubs.h>
#include <stdio.h>

#include "spawn_players.h"
#include "code_800029B0.h"
#include "engine/editor/Editor.h"
#include "kart_attributes.h"
#include "memory.h"
#include "waypoints.h"
#include "buffers.h"
#include "kart_dma.h"
#include "camera.h"
#include "racing/math_util.h"
#include "player_controller.h"
#include "code_80057C60.h"
#include "racing/collision.h"
#include "racing/render_courses.h"
#include "replays.h"
#include "code_80005FD0.h"
#include "render_player.h"
#include "ending/podium_ceremony_actors.h"
#include "main.h"
#include "menus.h"
#include "render_player.h"
#include "menu_items.h"
#include "effects.h"
#include "decode.h"
#include "port/Game.h"

f32 D_80165210[8];
f32 D_80165230[8];
UNUSED f32 D_80165250[8];
s16 D_80165270[8];
f32 gPlayerCurrentSpeed[8];
f32 gPlayerWaterLevel[8];
s32 D_801652C0[8];
s32 D_801652E0[8];
s16 D_80165300[8];
// Shadows values from gPathIndexByPlayerId, but is an array
u16 gCopyPathIndexByPlayerId[8];
// Shadows values from gNearestPathPointByPlayerId, but is an array
s16 gCopyNearestWaypointByPlayerId[8];
s16 D_80165330[8];
s16 D_80165340;
UNUSED s32 D_80165348[29];
Player* D_801653C0[8];

bool gPlayerIsThrottleActive[8];
s32 gPlayerAButtonComboActiveThisFrame[8];
s32 gFrameSinceLastACombo[8];
s32 gCountASwitch[8];
bool gIsPlayerTripleAButtonCombo[8];
s32 gTimerBoostTripleACombo[8];

bool gPlayerIsBrakeActive[8];
s32 gPlayerBButtonComboActiveThisFrame[8];
s32 gFrameSinceLastBCombo[8];
s32 gCountBChangement[8];
bool gIsPlayerTripleBButtonCombo[8];
s32 gTimerBoostTripleBCombo[8];

s16 chooseCPUPlayers[7];

s16 D_8016556E;
s16 D_80165570;
s16 D_80165572;
s16 D_80165574;
s16 D_80165576;
s16 D_80165578;
s16 D_8016557A;
s16 D_8016557C;
s16 D_8016557E;
s16 D_80165580;
s16 D_80165582;

// arg4 is height? Or something like that?
void spawn_player(Player* player, s8 playerIndex, f32 startingRow, f32 startingColumn, f32 arg4, f32 arg5,
                  u16 characterId, s16 playerType) {
    f32 ret;
    s8 idx;

    player->type = PLAYER_INACTIVE;
    player->kartPropulsionStrength = 0;
    player->characterId = characterId;
    player->kartGraphics = 0;
    player->kartFriction = gKartFrictionTable[player->characterId];
    player->boundingBoxSize = gKartBoundingBoxSizeTable[player->characterId];
    player->kartGravity = gKartGravityTable[player->characterId];

    switch (gModeSelection) {
        case GRAND_PRIX:
        case VERSUS:
            player->unk_084 = D_800E2400[gCCSelection][player->characterId];
            player->unk_088 = D_800E24B4[gCCSelection][player->characterId];
            player->unk_210 = D_800E2568[gCCSelection][player->characterId];
            player->topSpeed = gTopSpeedTable[gCCSelection][player->characterId];
            break;

        // Uses 100CC values
        case TIME_TRIALS:
            player->unk_084 = D_800E2400[CC_100][player->characterId];
            player->unk_088 = D_800E24B4[CC_100][player->characterId];
            player->unk_210 = D_800E2568[CC_100][player->characterId];
            player->topSpeed = gTopSpeedTable[CC_100][player->characterId];
            break;

        case BATTLE:
            player->unk_084 = D_800E2400[CC_BATTLE][player->characterId];
            player->unk_088 = D_800E24B4[CC_BATTLE][player->characterId];
            player->unk_210 = D_800E2568[CC_BATTLE][player->characterId];
            player->topSpeed = gTopSpeedTable[CC_BATTLE][player->characterId];
            break;
    }
    if (CVarGetInteger("gEnableCustomCC", 0) == 1) {
#define calc_a(x, y, x2, y2) (y2 - y) / (x2 - x)
#define calc_b(x, y, b) y - (b * x)
        f32 a;
        f32 b;

#define calc(table, field)                                                                      \
    a = calc_a(50, table[CC_50][player->characterId], 150, table[CC_150][player->characterId]); \
    b = calc_b(50, table[CC_50][player->characterId], a);                                       \
    player->field = a * CVarGetFloat("gCustomCC", 150.0f) + b;

        calc(gTopSpeedTable, topSpeed);
        calc(D_800E2400, unk_084);
        calc(D_800E24B4, unk_088);
        calc(D_800E2568, unk_210);
#undef calc_a
#undef calc_b
#undef calc
    }

    if (Editor_IsEnabled()) {
        f32 height = spawn_actor_on_surface(startingRow, arg4 + 50.0f, startingColumn);

        if ((height > 2900.0f) || (height < -2900.0f)) {
            printf("[spawn_player] Player %d appears to have spawned in the air!\n", playerIndex);
            printf("  Make sure some track surface is below the player at\n");
            printf("  %f %f\n", startingRow, startingColumn);
            printf("  Double check! Often a missed export or incorrect mesh placement can trick you!");
        }
    }

    player->pos[0] = startingRow;
    ret = spawn_actor_on_surface(startingRow, arg4 + 50.0f, startingColumn) + player->boundingBoxSize;
    player->pos[2] = startingColumn;
    player->pos[1] = ret;
    player->oldPos[0] = startingRow;
    player->oldPos[1] = ret;

    gPlayerPathY[playerIndex] = ret;

    player->rotation[0] = 0;
    player->oldPos[2] = startingColumn;
    player->unk_05C = 1.0f;
    player->unk_058 = 0.0f;
    player->unk_060 = 0.0f;
    player->velocity[0] = 0.0f;
    player->velocity[1] = 0.0f;
    player->velocity[2] = 0.0f;
    player->rotation[1] = arg5;
    player->rotation[2] = 0;
    player->unk_0FA = 0;
    player->unk_002 = 0;

    player->effects = 0;
    player->unk_0C0 = 0;
    player->unk_07C = 0;
    player->hopFrameCounter = 0;
    player->unk_006 = 0;
    player->lapCount = -1;
    player->kartPropulsionStrength = 0.0f;
    player->unk_090 = 0.0f;
    player->speed = 0.0f;
    player->unk_074 = 0.0f;
    player->type = playerType;
    player->lakituProps = 0;
    player->oobProps = 0;
    player->unk_10C = 0;
    player->unk_0E2 = 0;
    player->unk_0E8 = 0.0f;
    player->unk_0A0 = 0.0f;
    player->unk_104 = 0.0f;
    player->currentSpeed = 0.0f;
    player->unk_20C = 0.0f;
    player->unk_DAC = 0.0f;
    player->kartProps = 0;
    player->unk_046 = 0;
    player->triggers = 0;
    player->alpha = ALPHA_MAX;

    player->unk_206 = 0;
    player->slopeAccel = 0;
    player->unk_D98 = 0;
    player->unk_D9A = 0;
    player->unk_DA4 = 0;
    player->unk_DA6 = 0;
    player->unk_DB4.unk0 = 0;
    player->unk_DB4.unk2 = 0;
    player->unk_DB4.unk18 = 0;
    player->unk_DB4.unk1A = 0;
    player->unk_DB4.unk1C = 0;
    player->unk_DB4.unk1E = 0;
    player->unk_DB4.unk20 = 0;

    player->unk_042 = 0;
    player->unk_078 = 0;
    player->unk_0A8 = 0;
    player->unk_0AA = 0;
    player->unk_0AC = 0;
    player->unk_0AE = 0;
    player->unk_0B0 = 0;
    player->unk_0B2 = 0;
    player->unk_0B4 = 0;
    player->unk_0C0 = 0;
    player->unk_0C2 = 0;
    player->unk_0C8 = 0;
    player->lakituProps = 0;
    player->boostTimer = 0;
    player->oobProps = 0;
    player->unk_0E0 = 0;
    player->unk_0E2 = 0;
    player->unk_10C = 0;
    player->unk_200 = 0;
    player->driftDuration = 0;
    player->nearestPathPointId = 0;
    player->unk_228 = 0;
    player->driftState = 0;
    player->unk_234 = 0;
    player->unk_236 = 0;
    player->unk_238 = 0;
    player->unk_23A = 0;
    player->tyreSpeed = 0;
    player->unk_256 = 0;

    player->size = 1.0f;
    player->unk_DAC = 1.0f;

    player->unk_064[0] = 0.0f;
    player->unk_064[1] = 0.0f;
    player->unk_064[2] = 0.0f;
    player->boostPower = 0.0f;
    player->unk_D9C = 0.0f;
    player->unk_DA0 = 0.0f;
    player->unk_DA8 = 0.0f;
    player->unk_DB0 = 0.0f;
    player->unk_DB4.unk4 = 0.0f;
    player->unk_DB4.unk8 = 0.0f;
    player->unk_DB4.unkC = 0.0f;
    player->unk_DB4.unk10 = 0.0f;
    player->unk_DB4.unk14 = 0.0f;
    player->unk_084 = 0.0f;
    player->unk_088 = 0.0f;
    player->kartPropulsionStrength = 0.0f;
    player->unk_090 = 0.0f;
    player->speed = 0.0f;
    player->unk_098 = 0.0f;
    player->currentSpeed = 0.0f;
    player->unk_0A0 = 0.0f;
    player->unk_0A4 = 0.0f;
    player->unk_0B8 = 0.0f;
    player->unk_0E4 = 0.0f;
    player->unk_0E8 = 0.0f;
    player->kartHopVelocity = 0.0f;
    player->kartHopJerk = 0.0f;
    player->kartHopAcceleration = 0.0f;
    player->unk_104 = 0.0f;
    player->hopVerticalOffset = 0.0f;
    player->unk_1F8 = 0.0f;
    player->unk_1FC = 0.0f;
    player->unk_208 = 0.0f;
    player->unk_20C = 0.0f;
    player->unk_210 = 0.0f;
    player->unk_218 = 0.0f;
    player->unk_21C = 0.0f;
    player->previousSpeed = 0.0f;
    player->unk_230 = 0.0f;
    player->unk_23C = 0.0f;

    idx = playerIndex;

    gLastAnimFrameSelector[0][idx] = 0;
    gLastAnimFrameSelector[1][idx] = 0;
    gLastAnimFrameSelector[2][idx] = 0;
    gLastAnimFrameSelector[3][idx] = 0;
    gLastAnimGroupSelector[0][idx] = 0;
    gLastAnimGroupSelector[1][idx] = 0;
    gLastAnimGroupSelector[2][idx] = 0;
    gLastAnimGroupSelector[3][idx] = 0;
    D_80165190[0][idx] = 0;
    D_80165190[1][idx] = 0;
    D_80165190[2][idx] = 0;
    D_80165190[3][idx] = 0;
    D_801651D0[0][idx] = 0;
    D_801651D0[1][idx] = 0;
    D_801651D0[2][idx] = 0;
    D_801651D0[3][idx] = 0;

    gFrameSinceLastACombo[idx] = 0;
    gCountASwitch[idx] = 0;
    gIsPlayerTripleAButtonCombo[idx] = false;
    gTimerBoostTripleACombo[idx] = 0;
    gFrameSinceLastBCombo[idx] = 0;
    gCountBChangement[idx] = 0;
    gIsPlayerTripleBButtonCombo[idx] = false;
    gTimerBoostTripleBCombo[playerIndex] = 0;
    D_8018D900[0] = 0;

    D_801652E0[playerIndex] = 0;
    D_801652C0[playerIndex] = 0;
    D_80165020[playerIndex] = 0;
    gPlayerLastVelocity[playerIndex][0] = 0.0f;
    gPlayerLastVelocity[playerIndex][1] = 0.0f;
    gPlayerLastVelocity[playerIndex][2] = 0.0f;
    gPlayerCurrentSpeed[playerIndex] = 0.0f;
    gPlayerWaterLevel[playerIndex] = 0.0f;
    gPlayerIsThrottleActive[playerIndex] = 0;
    gPlayerAButtonComboActiveThisFrame[playerIndex] = 0;
    gPlayerIsBrakeActive[playerIndex] = 0;
    gPlayerBButtonComboActiveThisFrame[playerIndex] = 0;
    D_80165340 = 0;

    player->tyres[FRONT_LEFT].surfaceType = 0;
    player->tyres[FRONT_RIGHT].surfaceType = 0;
    player->tyres[BACK_LEFT].surfaceType = 0;
    player->tyres[BACK_RIGHT].surfaceType = 0;

    player->tyres[FRONT_LEFT].surfaceFlags = 0;
    player->tyres[FRONT_RIGHT].surfaceFlags = 0;
    player->tyres[BACK_LEFT].surfaceFlags = 0;
    player->tyres[BACK_RIGHT].surfaceFlags = 0;

    player->tyres[FRONT_LEFT].collisionMeshIndex = 0;
    player->tyres[FRONT_RIGHT].collisionMeshIndex = 0;
    player->tyres[BACK_LEFT].collisionMeshIndex = 0;
    player->tyres[BACK_RIGHT].collisionMeshIndex = 0;

    player->tyres[FRONT_RIGHT].unk_14 = 0;
    player->tyres[FRONT_LEFT].unk_14 = 0;
    player->tyres[BACK_LEFT].unk_14 = 0;
    player->tyres[BACK_RIGHT].unk_14 = 0;

    player->collision.unk30 = 0;
    player->collision.unk32 = 0;
    player->collision.unk34 = 0;
    player->collision.meshIndexYX = 0;
    player->collision.meshIndexZY = 0;
    player->collision.meshIndexZX = 0;

    player->tyres[FRONT_LEFT].pos[0] = 0.0f;
    player->tyres[FRONT_LEFT].pos[1] = 0.0f;
    player->tyres[FRONT_LEFT].pos[2] = 0.0f;

    player->tyres[FRONT_RIGHT].pos[0] = 0.0f;
    player->tyres[FRONT_RIGHT].pos[1] = 0.0f;
    player->tyres[FRONT_RIGHT].pos[2] = 0.0f;

    player->tyres[BACK_LEFT].pos[0] = 0.0f;
    player->tyres[BACK_LEFT].pos[1] = 0.0f;
    player->tyres[BACK_LEFT].pos[2] = 0.0f;

    player->tyres[BACK_RIGHT].pos[0] = 0.0f;
    player->tyres[BACK_RIGHT].pos[1] = 0.0f;
    player->tyres[BACK_RIGHT].pos[2] = 0.0f;

    player->tyres[FRONT_LEFT].baseHeight = 0.0f;
    player->tyres[FRONT_RIGHT].baseHeight = 0.0f;
    player->tyres[BACK_LEFT].baseHeight = 0.0f;
    player->tyres[BACK_RIGHT].baseHeight = 0.0f;

    player->collision.surfaceDistance[0] = 0.0f;
    player->collision.surfaceDistance[1] = 0.0f;
    player->collision.surfaceDistance[2] = 0.0f;
    player->collision.unk48[0] = 0.0f;
    player->collision.unk48[1] = 0.0f;
    player->collision.unk48[2] = 0.0f;
    player->collision.unk54[0] = 0.0f;
    player->collision.unk54[1] = 0.0f;
    player->collision.unk54[2] = 0.0f;
    player->collision.orientationVector[0] = 0.0f;
    player->collision.orientationVector[1] = 0.0f;
    player->collision.orientationVector[2] = 0.0f;

    D_80165300[playerIndex] = 0;
    D_8018CE10[playerIndex].unk_04[0] = 0.0f;
    D_8018CE10[playerIndex].unk_04[2] = 0.0f;
    func_80295BF8(playerIndex);
    reset_player_particle_pool(player);
    clear_all_player_balloons(player, playerIndex);
    if (gModeSelection == BATTLE) {
        init_all_player_balloons(player, playerIndex);
    }
    calculate_orientation_matrix(player->unk_150, player->unk_058, player->unk_05C, player->unk_060,
                                 player->rotation[1]);
    calculate_orientation_matrix(player->orientationMatrix, player->unk_058, player->unk_05C, player->unk_060,
                                 player->rotation[1]);
}

void func_80039AE4(void) {
    switch (gActiveScreenMode) {
        case SCREEN_MODE_1P:
            if (gGamestate == ENDING) {
                D_80165578 = 0x898;
                D_8016557A = 0;
                D_8016557C = 0x384;
                D_8016557E = 0;
                D_80165574 = 0x384;
                D_80165576 = 0;
                D_80165570 = 0x35C;
                D_80165572 = 0;
                D_80165580 = 0x1F4;
                D_80165582 = 0;
            } else {
                D_80165578 = 0x4B0;
                D_8016557A = -0xA;
                D_8016557C = 0x384;
                D_8016557E = 0x32;
                D_80165574 = 0x1F4;
                D_80165576 = 0;
                D_80165570 = 0x15E;
                D_80165572 = 0;
                D_80165580 = 0xFA;
                D_80165582 = 0;
            }
            break;

        case SCREEN_MODE_2P_SPLITSCREEN_HORIZONTAL:
        case SCREEN_MODE_2P_SPLITSCREEN_VERTICAL:
            if (gModeSelection == BATTLE) {
                D_80165578 = 0x898;
                D_8016557A = 0;
                D_8016557C = 0x320;
                D_8016557E = 0;
                D_80165574 = 0x190;
                D_80165576 = 0;
                D_80165570 = 0xC8;
                D_80165572 = 0;
                D_80165580 = 0xC8;
                D_80165582 = 0;
            } else {
                D_80165578 = 0x4B0;
                D_8016557A = 0x32;
                D_8016557C = 0x320;
                D_8016557E = 0x32;
                D_80165574 = 0x190;
                D_80165576 = 0;
                D_80165570 = 0x96;
                D_80165572 = 0;
                D_80165580 = 0x96;
                D_80165582 = 0;
            }
            break;

        default:
            if (gModeSelection == BATTLE) {
                D_80165578 = 0x898;
                D_8016557A = 0;
                D_8016557C = 0x320;
                D_8016557E = 0;
                D_80165574 = 0x190;
                D_80165576 = 0;
                D_80165570 = 0xC8;
                D_80165572 = 0;
                D_80165580 = 0xC8;
                D_80165582 = 0;
            } else {
                D_80165578 = 0x3E8;
                D_8016557A = 0;
                D_8016557C = 0x258;
                D_8016557E = 0;
                D_80165574 = 0x15E;
                D_80165576 = 0;
                D_80165570 = 0x96;
                D_80165572 = 0;
                D_80165580 = 0x96;
                D_80165582 = 0;
            }
            break;
    }
}

// typedef struct {
//     s32 unk00[8];
// } temp_80039DA4; // to be removed when data is compilable
// extern temp_80039DA4 D_800E4360;
// extern temp_80039DA4 D_800E4380;

void func_80039DA4(void) {
    s32 i;

    static const s32 sp2C[] = {
        7, 6, 5, 4, 3, 2, 1, 0,
    };

    static const s32 spC[] = {
        0, 1, 2, 3, 4, 5, 6, 7,
    };

    if (((GetCupCursorPosition() == TRACK_ONE) && (D_8016556E == 0)) || (gDemoMode == 1) ||
        (gDebugMenuSelection == DEBUG_MENU_OPTION_SELECTED)) {
        for (i = 0; i < NUM_PLAYERS; i++) {
            D_80165270[i] = sp2C[i];
        }
    } else {
        for (i = 0; i < NUM_PLAYERS; i++) {
            D_80165270[i] = spC[gGPCurrentRaceRankByPlayerId[i]];
        }
    }
}

UNUSED f32 D_800E43A0 = 1.0f;
UNUSED s16 D_800E43A4 = 1;
UNUSED s16 D_800E43A8 = 0;

void spawn_players_gp_one_player(f32* arg0, f32* arg1, f32 arg2) {
    func_80039DA4();
    if (((GetCupCursorPosition() == TRACK_ONE) && (D_8016556E == 0)) || (gDemoMode == 1) ||
        (gDebugMenuSelection == DEBUG_MENU_OPTION_SELECTED)) {
        s16 rand;
        s16 i;

        do {
            rand = random_int(7);
        } while (rand == gCharacterSelections[0]);

        // Randomize gPlayerTwo
        chooseCPUPlayers[0] = rand;

        // Chooses arr[0] as a fallback to prevent duplicating characters.
        // If it doesn't find the if, it will grab the final index as a fallback.
        for (i = 1; i < 7; i++) {
            u16* arr = (u16*) cpu_forPlayer[gCharacterSelections[0]];
            if (rand == arr[i]) {
                chooseCPUPlayers[i] = arr[0];
            } else {
                chooseCPUPlayers[i] = arr[i];
            }
        }
    }

    D_8016556E = 0;
    if (gDemoMode == 1) {
        spawn_player(gPlayerOne, 0, arg0[D_80165270[0]], arg1[D_80165270[0]], arg2, 32768.0f,
                     gCharacterSelections[0], PLAYER_HUMAN_AND_CPU);
        spawn_player(gPlayerTwo, 1, arg0[D_80165270[1]], arg1[D_80165270[1]], arg2, 32768.0f, chooseCPUPlayers[0],
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
        spawn_player(gPlayerThree, 2, arg0[D_80165270[2]], arg1[D_80165270[2]], arg2, 32768.0f, chooseCPUPlayers[1],
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
        spawn_player(gPlayerFour, 3, arg0[D_80165270[3]], arg1[D_80165270[3]], arg2, 32768.0f, chooseCPUPlayers[2],
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
        spawn_player(gPlayerFive, 4, arg0[D_80165270[4]], arg1[D_80165270[4]], arg2, 32768.0f, chooseCPUPlayers[3],
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
        spawn_player(gPlayerSix, 5, arg0[D_80165270[5]], arg1[D_80165270[5]], arg2, 32768.0f, chooseCPUPlayers[4],
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
        spawn_player(gPlayerSeven, 6, arg0[D_80165270[6]], arg1[D_80165270[6]], arg2, 32768.0f, chooseCPUPlayers[5],
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
        spawn_player(gPlayerEight, 7, arg0[D_80165270[7]], arg1[D_80165270[7]], arg2, 32768.0f, chooseCPUPlayers[6],
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
        D_80164A28 = 0;
    } else {
        spawn_player(gPlayerOne, 0, arg0[D_80165270[0]], arg1[D_80165270[0]] + 250.0f, arg2, 32768.0f,
                        gCharacterSelections[0],
                        PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
        spawn_player(gPlayerTwo, 1, arg0[D_80165270[1]], arg1[D_80165270[1]] + 250.0f, arg2, 32768.0f,
                        chooseCPUPlayers[0], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_CPU);
        spawn_player(gPlayerThree, 2, arg0[D_80165270[3]], arg1[D_80165270[2]] + 250.0f, arg2, 32768.0f,
                        chooseCPUPlayers[1], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_CPU);
        spawn_player(gPlayerFour, 3, arg0[D_80165270[2]], arg1[D_80165270[3]] + 250.0f, arg2, 32768.0f,
                        chooseCPUPlayers[2], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_CPU);
        spawn_player(gPlayerFive, 4, arg0[D_80165270[5]], arg1[D_80165270[4]] + 250.0f, arg2, 32768.0f,
                        chooseCPUPlayers[3], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_CPU);
        spawn_player(gPlayerSix, 5, arg0[D_80165270[4]], arg1[D_80165270[5]] + 250.0f, arg2, 32768.0f,
                        chooseCPUPlayers[4], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_CPU);
        spawn_player(gPlayerSeven, 6, arg0[D_80165270[7]], arg1[D_80165270[6]] + 250.0f, arg2, 32768.0f,
                        chooseCPUPlayers[5], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_CPU);
        spawn_player(gPlayerEight, 7, arg0[D_80165270[6]], arg1[D_80165270[7]] + 250.0f, arg2, 32768.0f,
                        chooseCPUPlayers[6], PLAYER_EXISTS | PLAYER_STAGING | PLAYER_START_SEQUENCE | PLAYER_CPU);
        D_80164A28 = 1;
    }
    func_80039AE4();
}

void spawn_players_versus_one_player(f32* arg0, f32* arg1, f32 arg2) {
    spawn_player(gPlayerFour, 3, arg0[2], arg1[2], arg2, 32768.0f, gCharacterSelections[0],
                 PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerFive, 4, arg0[3], arg1[3], arg2, 32768.0f, gCharacterSelections[0],
                 PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerSix, 5, arg0[4], arg1[4], arg2, 32768.0f, gCharacterSelections[0],
                 PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerSeven, 6, arg0[5], arg1[5], arg2, 32768.0f, gCharacterSelections[0],
                 PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerEight, 7, arg0[6], arg1[6], arg2, 32768.0f, gCharacterSelections[0],
                 PLAYER_START_SEQUENCE | PLAYER_CPU);
    if (gDemoMode == 1) {
        spawn_player(gPlayerOne, 0, arg0[0], arg1[0], arg2, 32768.0f, gCharacterSelections[0],
                     PLAYER_HUMAN_AND_CPU);
        spawn_player(gPlayerTwo, 1, arg0[0], arg1[0], arg2, 32768.0f, gCharacterSelections[0],
                     PLAYER_START_SEQUENCE | PLAYER_CPU);
        spawn_player(gPlayerThree, 2, arg0[1], arg1[1], arg2, 32768.0f, gCharacterSelections[0],
                     PLAYER_START_SEQUENCE | PLAYER_CPU);
    } else if (D_8015F890 != 1) {
        spawn_player(gPlayerOne, 0, arg0[0], arg1[0], arg2, 32768.0f, gCharacterSelections[0],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
        if (bPlayerGhostDisabled == 0) {
            spawn_player(gPlayerTwo, 1, arg0[0], arg1[0], arg2, 32768.0f, D_80162DE0,
                         PLAYER_EXISTS | PLAYER_HUMAN | PLAYER_START_SEQUENCE | PLAYER_INVISIBLE_OR_BOMB);
        } else {
            spawn_player(gPlayerTwo, 1, arg0[0], arg1[0], arg2, 32768.0f, gCharacterSelections[0],
                         PLAYER_START_SEQUENCE | PLAYER_CPU);
        }
        if (bCourseGhostDisabled == 0) {
            spawn_player(gPlayerThree, 2, arg0[0], arg1[0], arg2, 32768.0f, D_80162DE4,
                         PLAYER_EXISTS | PLAYER_HUMAN | PLAYER_START_SEQUENCE | PLAYER_INVISIBLE_OR_BOMB);
        } else {
            spawn_player(gPlayerThree, 2, arg0[1], arg1[1], arg2, 32768.0f, gCharacterSelections[0],
                         PLAYER_START_SEQUENCE | PLAYER_CPU);
        }
    } else {
        spawn_player(gPlayerOne, 0, arg0[0], arg1[0], arg2, 32768.0f, D_80162DE8,
                     PLAYER_EXISTS | PLAYER_HUMAN | PLAYER_START_SEQUENCE | PLAYER_INVISIBLE_OR_BOMB);
        if (D_80162DD8 == 0) {
            spawn_player(gPlayerTwo, 1, arg0[0], arg1[0], arg2, 32768.0f, D_80162DE0,
                         PLAYER_EXISTS | PLAYER_HUMAN | PLAYER_START_SEQUENCE | PLAYER_INVISIBLE_OR_BOMB);
        } else {
            spawn_player(gPlayerTwo, 1, arg0[0], arg1[0], arg2, 32768.0f, gCharacterSelections[0],
                         PLAYER_START_SEQUENCE | PLAYER_CPU);
        }
        if (bCourseGhostDisabled == 0) {
            spawn_player(gPlayerThree, 2, arg0[0], arg1[0], arg2, 32768.0f, D_80162DE4,
                         PLAYER_EXISTS | PLAYER_HUMAN | PLAYER_START_SEQUENCE | PLAYER_INVISIBLE_OR_BOMB);
        } else {
            spawn_player(gPlayerThree, 2, arg0[1], arg1[1], arg2, 32768.0f, gCharacterSelections[0],
                         PLAYER_START_SEQUENCE | PLAYER_CPU);
        }
    }
    D_80164A28 = 0;
    func_80039AE4();
}

void spawn_players_gp_two_player(f32* arg0, f32* arg1, f32 arg2) {
    func_80039DA4();
    if ((GetCupCursorPosition() == TRACK_ONE) || (gDemoMode == 1) ||
        (gDebugMenuSelection == DEBUG_MENU_OPTION_SELECTED)) {
        s16 rand;
        s16 i;

        // @todo: this is a do-while loop
    getRand:
        rand = random_int(7);
        if (gCharacterSelections[0] == rand) {
            goto getRand;
        }
        if (gCharacterSelections[1] == rand) {
            goto getRand;
        }

        chooseCPUPlayers[0] = rand;

        for (i = 1; i < 6; i++) {
            u16* arr = (u16*) cpu_forTwoPlayer[gCharacterSelections[0]][gCharacterSelections[1]];
            if (rand == arr[i]) {
                chooseCPUPlayers[i] = arr[0];
            } else {
                chooseCPUPlayers[i] = arr[i];
            }
        }
    }

    spawn_player(gPlayerThree, 2, arg0[D_80165270[2]], arg1[D_80165270[2]], arg2, 32768.0f, chooseCPUPlayers[0],
                 PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
    spawn_player(gPlayerFour, 3, arg0[D_80165270[3]], arg1[D_80165270[3]], arg2, 32768.0f, chooseCPUPlayers[1],
                 PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
    spawn_player(gPlayerFive, 4, arg0[D_80165270[4]], arg1[D_80165270[4]], arg2, 32768.0f, chooseCPUPlayers[2],
                 PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
    spawn_player(gPlayerSix, 5, arg0[D_80165270[5]], arg1[D_80165270[5]], arg2, 32768.0f, chooseCPUPlayers[3],
                 PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
    spawn_player(gPlayerSeven, 6, arg0[D_80165270[6]], arg1[D_80165270[6]], arg2, 32768.0f, chooseCPUPlayers[4],
                 PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
    spawn_player(gPlayerEight, 7, arg0[D_80165270[7]], arg1[D_80165270[7]], arg2, 32768.0f, chooseCPUPlayers[5],
                 PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);

    if (gDemoMode == 1) {
        spawn_player(gPlayerOne, 0, arg0[D_80165270[0]], arg1[D_80165270[0]], arg2, 32768.0f,
                     gCharacterSelections[0], PLAYER_HUMAN_AND_CPU);
    } else {
        spawn_player(gPlayerOne, 0, arg0[D_80165270[0]], arg1[D_80165270[0]], arg2, 32768.0f,
                     gCharacterSelections[0], PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    }
    if (gDemoMode == 1) {
        spawn_player(gPlayerTwo, 1, arg0[D_80165270[1]], arg1[D_80165270[1]], arg2, 32768.0f, gCharacterSelections[1],
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
    } else {
        spawn_player(gPlayerTwo, 1, arg0[D_80165270[1]], arg1[D_80165270[1]], arg2, 32768.0f, gCharacterSelections[1],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    }

    D_80164A28 = 0;
    func_80039AE4();
}

void spawn_players_versus_two_player(f32* arg0, f32* arg1, f32 arg2) {
    spawn_player(gPlayerThree, 2, arg0[1], arg1[1], arg2, 32768.0f, gCharacterSelections[0],
                 PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerFour, 3, arg0[2], arg1[2], arg2, 32768.0f, gCharacterSelections[0],
                 PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerFive, 4, arg0[3], arg1[3], arg2, 32768.0f, gCharacterSelections[0],
                 PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerSix, 5, arg0[4], arg1[4], arg2, 32768.0f, gCharacterSelections[0],
                 PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerSeven, 6, arg0[5], arg1[5], arg2, 32768.0f, gCharacterSelections[0],
                 PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerEight, 7, arg0[6], arg1[6], arg2, 32768.0f, gCharacterSelections[0],
                 PLAYER_START_SEQUENCE | PLAYER_CPU);
    if (gDemoMode == 1) {
        spawn_player(gPlayerOne, 0, arg0[0], arg1[0], arg2, 32768.0f, gCharacterSelections[0],
                     PLAYER_HUMAN_AND_CPU);
    } else {
        spawn_player(gPlayerOne, 0, arg0[0], arg1[0], arg2, 32768.0f, gCharacterSelections[0],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    }
    if (gDemoMode == 1) {
        spawn_player(gPlayerTwo, 1, arg0[1], arg1[1], arg2, 32768.0f, gCharacterSelections[1], PLAYER_HUMAN_AND_CPU);
    } else {
        spawn_player(gPlayerTwo, 1, arg0[1], arg1[1], arg2, 32768.0f, gCharacterSelections[1],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    }
    D_80164A28 = 0;
    func_80039AE4();
}

void spawn_players_2p_battle(f32* arg0, f32* arg1, f32 arg2) {
    if (IsBigDonut()) {
        spawn_player(gPlayerOne, 0, arg0[0], arg1[0], arg2, -16384.0f, gCharacterSelections[0],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
        spawn_player(gPlayerTwo, 1, arg0[1], arg1[1], arg2, 16384.0f, gCharacterSelections[1],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    } else {
        spawn_player(gPlayerOne, 0, arg0[0], arg1[0], arg2, 32768.0f, gCharacterSelections[0],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
        spawn_player(gPlayerTwo, 1, arg0[1], arg1[1], arg2, 0.0f, gCharacterSelections[1],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    }
    spawn_player(gPlayerThree, 2, arg0[2], arg1[2], arg2, 32768.0f, gCharacterSelections[2],
                 PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    spawn_player(gPlayerFour, 3, arg0[3], arg1[3], arg2, 32768.0f, gCharacterSelections[3],
                 PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    spawn_player(gPlayerFive, 4, arg0[4], arg1[4], arg2, 32768.0f, 4, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerSix, 5, arg0[5], arg1[5], arg2, 32768.0f, 5, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerSeven, 6, arg0[6], arg1[6], arg2, 32768.0f, 6, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerEight, 7, arg0[0], arg1[0], arg2, 32768.0f, 7, PLAYER_START_SEQUENCE | PLAYER_CPU);
    D_80164A28 = 0;
    func_80039AE4();
}

void func_8003B318(f32* arg0, f32* arg1, f32 arg2) {
    spawn_player(gPlayerOne, 0, arg0[0], arg1[0], arg2, 32768.0f, gCharacterSelections[0],
                 PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    spawn_player(gPlayerTwo, 1, arg0[1], arg1[1], arg2, 32768.0f, gCharacterSelections[1],
                 PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    spawn_player(gPlayerThree, 2, arg0[2], arg1[2], arg2, 32768.0f, gCharacterSelections[2],
                 PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    if (gDemoMode == 1) {
        spawn_player(gPlayerOne, 0, arg0[0], arg1[0], arg2, 32768.0f, gCharacterSelections[0], PLAYER_HUMAN_AND_CPU);
        spawn_player(gPlayerTwo, 1, arg0[1], arg1[1], arg2, 32768.0f, gCharacterSelections[1], PLAYER_HUMAN_AND_CPU);
        spawn_player(gPlayerThree, 2, arg0[2], arg1[2], arg2, 32768.0f, gCharacterSelections[2], PLAYER_HUMAN_AND_CPU);
    }

    spawn_player(gPlayerFour, 3, arg0[3], arg1[3], arg2, 32768.0f, 3, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerFive, 4, arg0[4], arg1[4], arg2, 32768.0f, 4, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerSix, 5, arg0[5], arg1[5], arg2, 32768.0f, 5, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerSeven, 6, arg0[6], arg1[6], arg2, 32768.0f, 6, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerEight, 7, arg0[0], arg1[0], arg2, 32768.0f, 7, PLAYER_START_SEQUENCE | PLAYER_CPU);
    D_80164A28 = 0;
    func_80039AE4();
}

void spawn_players_3p_battle(f32* arg0, f32* arg1, f32 arg2) {
    if (IsBigDonut()) {
        spawn_player(gPlayerOne, 0, arg0[0], arg1[0], arg2, -16384.0f, gCharacterSelections[0],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
        spawn_player(gPlayerTwo, 1, arg0[1], arg1[1], arg2, 16384.0f, gCharacterSelections[1],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
        spawn_player(gPlayerThree, 2, arg0[2], arg1[2], arg2, 0.0f, gCharacterSelections[2],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    } else {
        spawn_player(gPlayerOne, 0, arg0[0], arg1[0], arg2, 32768.0f, gCharacterSelections[0],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
        spawn_player(gPlayerTwo, 1, arg0[1], arg1[1], arg2, 0.0f, gCharacterSelections[1],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
        spawn_player(gPlayerThree, 2, arg0[2], arg1[2], arg2, -16384.0f, gCharacterSelections[2],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    }
    spawn_player(gPlayerFour, 3, arg0[3], arg1[3], arg2, 32768.0f, 3, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerFive, 4, arg0[4], arg1[4], arg2, 32768.0f, 4, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerSix, 5, arg0[5], arg1[5], arg2, 32768.0f, 5, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerSeven, 6, arg0[6], arg1[6], arg2, 32768.0f, 6, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerEight, 7, arg0[0], arg1[0], arg2, 32768.0f, 7, PLAYER_START_SEQUENCE | PLAYER_CPU);
    D_80164A28 = 0;
    func_80039AE4();
}

void func_8003B870(f32* arg0, f32* arg1, f32 arg2) {
    spawn_player(gPlayerOne, 0, arg0[0], arg1[0], arg2, 32768.0f, gCharacterSelections[0],
                 PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    spawn_player(gPlayerTwo, 1, arg0[1], arg1[1], arg2, 32768.0f, gCharacterSelections[1],
                 PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    spawn_player(gPlayerThree, 2, arg0[2], arg1[2], arg2, 32768.0f, gCharacterSelections[2],
                 PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    spawn_player(gPlayerFour, 3, arg0[3], arg1[3], arg2, 32768.0f, gCharacterSelections[3],
                 PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    if (gDemoMode == 1) {
        spawn_player(gPlayerOne, 0, arg0[0], arg1[0], arg2, 32768.0f, gCharacterSelections[0], PLAYER_HUMAN_AND_CPU);
        spawn_player(gPlayerTwo, 1, arg0[1], arg1[1], arg2, 32768.0f, gCharacterSelections[1], PLAYER_HUMAN_AND_CPU);
        spawn_player(gPlayerThree, 2, arg0[2], arg1[2], arg2, 32768.0f, gCharacterSelections[2], PLAYER_HUMAN_AND_CPU);
        spawn_player(gPlayerFour, 3, arg0[3], arg1[3], arg2, 32768.0f, gCharacterSelections[3], PLAYER_HUMAN_AND_CPU);
    }
    spawn_player(gPlayerFive, 4, arg0[4], arg1[4], arg2, 32768.0f, 4, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerSix, 5, arg0[5], arg1[5], arg2, 32768.0f, 5, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerSeven, 6, arg0[6], arg1[6], arg2, 32768.0f, 6, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerEight, 7, arg0[0], arg1[0], arg2, 32768.0f, 7, PLAYER_START_SEQUENCE | PLAYER_CPU);
    D_80164A28 = 0;
    func_80039AE4();
}

void spawn_players_4p_battle(f32* arg0, f32* arg1, f32 arg2) {
    if (IsBigDonut()) {
        spawn_player(gPlayerOne, 0, arg0[0], arg1[0], arg2, -16384.0f, gCharacterSelections[0],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
        spawn_player(gPlayerTwo, 1, arg0[1], arg1[1], arg2, 16384.0f, gCharacterSelections[1],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
        spawn_player(gPlayerThree, 2, arg0[2], arg1[2], arg2, 0.0f, gCharacterSelections[2],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
        spawn_player(gPlayerFour, 3, arg0[3], arg1[3], arg2, 32768.0f, gCharacterSelections[3],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    } else {
        spawn_player(gPlayerOne, 0, arg0[0], arg1[0], arg2, 32768.0f, gCharacterSelections[0],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
        spawn_player(gPlayerTwo, 1, arg0[1], arg1[1], arg2, 0.0f, gCharacterSelections[1],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
        spawn_player(gPlayerThree, 2, arg0[2], arg1[2], arg2, -16384.0f, gCharacterSelections[2],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
        spawn_player(gPlayerFour, 3, arg0[3], arg1[3], arg2, 16384.0f, gCharacterSelections[3],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
    }
    spawn_player(gPlayerFive, 4, arg0[4], arg1[4], arg2, 32768.0f, 4, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerSix, 5, arg0[5], arg1[5], arg2, 32768.0f, 5, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerSeven, 6, arg0[6], arg1[6], arg2, 32768.0f, 6, PLAYER_START_SEQUENCE | PLAYER_CPU);
    spawn_player(gPlayerEight, 7, arg0[0], arg1[0], arg2, 32768.0f, 7, PLAYER_START_SEQUENCE | PLAYER_CPU);
    D_80164A28 = 0;
    func_80039AE4();
}

void func_8003BE30(void) {
    spawn_player(gPlayerOne, 0, -2770.774f, -345.187f, -34.6f, 0.0f, gCharacterIdByGPOverallRank[0],
                 PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
    spawn_player(gPlayerTwo, 1, -3691.506f, -6.822f, -6.95f, 36400.0f, gCharacterIdByGPOverallRank[1],
                 PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
    spawn_player(gPlayerThree, 2, -3475.028f, -998.485f, -8.059f, 45500.0f, gCharacterIdByGPOverallRank[2],
                 PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
    if (D_802874D8.unk1D >= 3) {
        spawn_player(gPlayerFour, 3, -3025.772f, 110.039f, -23.224f, 28210.0f, D_802874D8.unk1E,
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
    } else {
        spawn_player(gPlayerFour, 3, -3025.772f, 110.039f, -23.224f, 28210.0f, gCharacterIdByGPOverallRank[3],
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
    }
    spawn_player(gPlayerFive, 4, -2770.774f, -345.187f, -34.6f, 0.0f, 0, 0x7000);
    spawn_player(gPlayerSix, 5, -3691.506f, -6.822f, -6.95f, 36400.0f, 0, 0x7000);
    spawn_player(gPlayerSeven, 6, -3475.028f, -998.485f, -8.059f, 45500.0f, 0, 0x7000);
    spawn_player(gPlayerEight, 7, -3025.772f, 110.039f, -23.224f, 28210.0f, 0, 0x7000);
    D_80164A28 = 0;
    func_80039AE4();
}

void func_8003C0F0(void) {
    if (gModeSelection == BATTLE) {
        func_8000EEDC();
    } else if (!IsPodiumCeremony()) {
        init_course_path_point();
    }

    // The tour delays player spawning until the end of the tour
    if ((CM_IsTourEnabled() == false) || (Editor_IsPaused() == true)) {
        spawn_and_set_player_spawns();
    }
}

void spawn_and_set_player_spawns(void) {
    s16 sp5E;
    s16 sp5C;
    s16 sp5A = 0;
    s32 temp;

    if ((!IsPodiumCeremony()) && (gModeSelection != BATTLE)) {
        sp5E = (f32) gTrackPaths[0][0].x;
        sp5C = (f32) gTrackPaths[0][0].z;
        sp5A = (f32) gTrackPaths[0][0].y;
        if (IsToadsTurnpike()) {
            sp5E = 0;
        }
    }

    if ((gModeSelection != BATTLE) && (!IsPodiumCeremony())) {
        switch (gActiveScreenMode) {
            case SCREEN_MODE_1P:
                switch (gModeSelection) {
                    case GRAND_PRIX:
                        D_80165210[0] = (D_80165210[2] = (D_80165210[4] = (D_80165210[6] = sp5E + 0x14)));
                        D_80165210[1] = (D_80165210[3] = (D_80165210[5] = (D_80165210[7] = sp5E - 0x14)));
                        D_80165230[0] = sp5C + 0x1E;
                        D_80165230[1] = sp5C + 0x32;
                        D_80165230[2] = sp5C + 0x46;
                        D_80165230[3] = sp5C + 0x5A;
                        D_80165230[4] = sp5C + 0x6E;
                        D_80165230[5] = sp5C + 0x82;
                        D_80165230[6] = sp5C + 0x96;
                        D_80165230[7] = sp5C + 0xAA;
                        spawn_players_gp_one_player(D_80165210, D_80165230, sp5A);
                        break;

                    case TIME_TRIALS:
                        D_80165210[0] = (D_80165210[2] = (D_80165210[4] = (D_80165210[6] = sp5E)));
                        D_80165210[1] = (D_80165210[3] = (D_80165210[5] = (D_80165210[7] = sp5E)));
                        D_80165230[0] = sp5C + 0x1E;
                        D_80165230[1] = sp5C + 0x1E;
                        D_80165230[2] = sp5C + 0x1E;
                        D_80165230[3] = sp5C + 0x1E;
                        D_80165230[4] = sp5C + 0x1E;
                        D_80165230[5] = sp5C + 0x1E;
                        D_80165230[6] = sp5C + 0x1E;
                        D_80165230[7] = sp5C + 0x1E;
                        spawn_players_versus_one_player(D_80165210, D_80165230, sp5A);
                        break;
                }
                break;

            case SCREEN_MODE_2P_SPLITSCREEN_HORIZONTAL:
            case SCREEN_MODE_2P_SPLITSCREEN_VERTICAL:
                switch (gModeSelection) {
                    case GRAND_PRIX:
                        D_80165210[0] = (D_80165210[2] = (D_80165210[4] = (D_80165210[6] = sp5E + 0x14)));
                        D_80165210[1] = (D_80165210[3] = (D_80165210[5] = (D_80165210[7] = sp5E - 0x14)));
                        D_80165230[0] = sp5C + 0x1E;
                        D_80165230[1] = sp5C + 0x32;
                        D_80165230[2] = sp5C + 0x46;
                        D_80165230[3] = sp5C + 0x5A;
                        D_80165230[4] = sp5C + 0x6E;
                        D_80165230[5] = sp5C + 0x82;
                        D_80165230[6] = sp5C + 0x96;
                        D_80165230[7] = sp5C + 0xAA;
                        spawn_players_gp_two_player(D_80165210, D_80165230, sp5A);
                        break;

                    case VERSUS:
                        D_80165210[0] = (D_80165210[2] = (D_80165210[4] = (D_80165210[6] = sp5E + 0xA)));
                        D_80165210[1] = (D_80165210[3] = (D_80165210[5] = (D_80165210[7] = sp5E - 0xA)));
                        D_80165230[0] = sp5C + 0x1E;
                        D_80165230[1] = sp5C + 0x1E;
                        D_80165230[2] = sp5C + 0x1E;
                        D_80165230[3] = sp5C + 0x1E;
                        D_80165230[4] = sp5C + 0x1E;
                        D_80165230[5] = sp5C + 0x1E;
                        D_80165230[6] = sp5C + 0x1E;
                        D_80165230[7] = sp5C + 0x1E;
                        spawn_players_versus_two_player(D_80165210, D_80165230, sp5A);
                        break;
                }
                break;

            case SCREEN_MODE_3P_4P_SPLITSCREEN:
                switch (gModeSelection) {
                    case VERSUS:
                        D_80165210[0] = sp5E + 0x1E;
                        D_80165210[6] = sp5E - 0xA;
                        D_80165210[1] = sp5E + 0xA;
                        D_80165210[7] = sp5E - 0x1E;
                        D_80165210[4] = sp5E - 0xA;
                        D_80165210[2] = sp5E - 0xA;
                        D_80165210[5] = sp5E - 0x1E;
                        D_80165210[3] = sp5E - 0x1E;
                        D_80165230[0] = sp5C + 0x1E;
                        D_80165230[1] = sp5C + 0x1E;
                        D_80165230[2] = sp5C + 0x1E;
                        D_80165230[3] = sp5C + 0x1E;
                        D_80165230[4] = sp5C + 0x1E;
                        D_80165230[5] = sp5C + 0x1E;
                        D_80165230[6] = sp5C + 0x1E;
                        D_80165230[7] = sp5C + 0x1E;
                        if (gPlayerCountSelection1 == 4) {
                            func_8003B870(D_80165210, D_80165230, sp5A);
                        } else {
                            func_8003B318(D_80165210, D_80165230, sp5A);
                        }
                        break;
                }
                break;
        }
    } else if (IsBlockFort()) {
        switch (gActiveScreenMode) {
            case SCREEN_MODE_2P_SPLITSCREEN_HORIZONTAL:
            case SCREEN_MODE_2P_SPLITSCREEN_VERTICAL:
                temp = 5;
                if (1) {};
                D_80165210[0] = 0;
                D_80165210[1] = 0;
                D_80165230[1] = -200.0f;
                D_80165230[0] = 200.0f;
                spawn_players_2p_battle(D_80165210, D_80165230, temp);
                break;

            case SCREEN_MODE_3P_4P_SPLITSCREEN:
                temp = 5;
                D_80165210[2] = -200.0f;
                D_80165230[1] = -200.0f;
                D_80165210[0] = 0.0f;
                D_80165210[1] = 0.0f;
                D_80165230[2] = 0.0f;
                D_80165230[3] = 0.0f;
                D_80165210[3] = 200.0f;
                D_80165230[0] = 200.0f;
                if (gPlayerCountSelection1 == 4) {
                    spawn_players_4p_battle(D_80165210, D_80165230, temp);
                } else {
                    spawn_players_3p_battle(D_80165210, D_80165230, temp);
                }
                break;
        }
    } else if (IsSkyscraper()) {
        switch (gActiveScreenMode) {
            case SCREEN_MODE_2P_SPLITSCREEN_HORIZONTAL:
            case SCREEN_MODE_2P_SPLITSCREEN_VERTICAL:
                temp = 0x1E0;
                if (1) {};
                D_80165210[0] = 0.0f;
                D_80165210[1] = 0.0f;
                D_80165230[1] = -400.0f;
                D_80165230[0] = 400.0f;
                spawn_players_2p_battle(D_80165210, D_80165230, temp);
                break;

            case SCREEN_MODE_3P_4P_SPLITSCREEN:
                temp = 0x1E0;
                D_80165210[0] = 0.0f;
                D_80165210[1] = 0.0f;
                D_80165210[2] = -400.0f;
                D_80165210[3] = 400.0f;
                D_80165230[0] = 400.0f;
                D_80165230[1] = -400.0f;
                D_80165230[2] = 0.0f;
                D_80165230[3] = 0.0f;
                if (gPlayerCountSelection1 == 4) {
                    spawn_players_4p_battle(D_80165210, D_80165230, temp);
                } else {
                    spawn_players_3p_battle(D_80165210, D_80165230, temp);
                }
                break;
        }
    } else if (IsDoubleDeck()) {
        switch (gActiveScreenMode) {
            case SCREEN_MODE_2P_SPLITSCREEN_HORIZONTAL:
            case SCREEN_MODE_2P_SPLITSCREEN_VERTICAL:
                temp = 0x37;
                if (1) {};
                D_80165210[0] = 0.0f;
                D_80165210[1] = 0.0f;
                D_80165230[1] = -160.0f;
                D_80165230[0] = 160.0f;
                spawn_players_2p_battle(D_80165210, D_80165230, temp);
                break;

            case 3:
                temp = 0x37;
                D_80165210[0] = 0.0f;
                D_80165210[1] = 0.0f;
                D_80165210[2] = -160.0f;
                D_80165210[3] = 160.0f;
                D_80165230[0] = 160.0f;
                D_80165230[1] = -160.0f;
                D_80165230[2] = 0.0f;
                D_80165230[3] = 0.0f;
                if (gPlayerCountSelection1 == 4) {
                    spawn_players_4p_battle(D_80165210, D_80165230, temp);
                } else {
                    spawn_players_3p_battle(D_80165210, D_80165230, temp);
                }
                break;
        }
    } else if (IsBigDonut()) {
        switch (gActiveScreenMode) {
            case SCREEN_MODE_2P_SPLITSCREEN_HORIZONTAL:
            case SCREEN_MODE_2P_SPLITSCREEN_VERTICAL:
                temp = 0xC8;
                if (1) {};
                D_80165210[0] = 0.0f;
                D_80165210[1] = 0.0f;
                D_80165230[1] = -575.0f;
                D_80165230[0] = 575.0f;
                spawn_players_2p_battle(D_80165210, D_80165230, temp);
                break;

            case SCREEN_MODE_3P_4P_SPLITSCREEN:
                temp = 0xC8;
                D_80165210[0] = 0.0f;
                D_80165210[1] = 0.0f;
                D_80165210[2] = -575.0f;
                D_80165210[3] = 575.0f;
                D_80165230[0] = 575.0f;
                D_80165230[1] = -575.0f;
                D_80165230[2] = 0.0f;
                D_80165230[3] = 0.0f;
                if (gPlayerCountSelection1 == 4) {
                    spawn_players_4p_battle(D_80165210, D_80165230, temp);
                } else {
                    spawn_players_3p_battle(D_80165210, D_80165230, temp);
                }
                break;
        }
    } else {
        D_80165210[0] = (D_80165210[2] = (D_80165210[4] = (D_80165210[6] = 20.0f)));
        D_80165210[1] = (D_80165210[3] = (D_80165210[5] = (D_80165210[7] = -20.0f)));
        D_80165230[0] = 30.0f;
        D_80165230[1] = 50.0f;
        D_80165230[2] = 70.0f;
        D_80165230[3] = 90.0f;
        D_80165230[4] = 110.0f;
        D_80165230[5] = 130.0f;
        D_80165230[6] = 150.0f;
        D_80165230[7] = 170.0f;
        spawn_player(gPlayerOne, 0, D_80165210[0], D_80165230[0], sp5A, 32768.0f, gCharacterSelections[0],
                     PLAYER_EXISTS | PLAYER_START_SEQUENCE | PLAYER_HUMAN);
        spawn_player(gPlayerTwo, 1, D_80165210[1], D_80165230[1], sp5A, 32768.0f, 1,
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
        spawn_player(gPlayerThree, 2, D_80165210[2], D_80165230[2], sp5A, 32768.0f, 2,
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
        spawn_player(gPlayerFour, 3, D_80165210[3], D_80165230[3], sp5A, 32768.0f, 3,
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
        spawn_player(gPlayerFive, 4, D_80165210[4], D_80165230[4], sp5A, 32768.0f, 4,
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
        spawn_player(gPlayerSix, 5, D_80165210[5], D_80165230[5], sp5A, 32768.0f, 5,
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
        spawn_player(gPlayerSeven, 6, D_80165210[6], D_80165230[6], sp5A, 32768.0f, 6,
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
        spawn_player(gPlayerEight, 7, D_80165210[7], D_80165230[7], sp5A, 32768.0f, 7,
                     PLAYER_EXISTS | PLAYER_CPU | PLAYER_START_SEQUENCE);
        D_80164A28 = 0;
    }

    if (gModeSelection != BATTLE) {
        init_players();
    }
}

void func_8003CD78(void) {
    func_8003BE30();
}

void func_8003CD98(Player* player, Camera* camera, s8 playerId, s8 screenId) {
    if (player->type & PLAYER_EXISTS) {
        if (screenId == 0) {
            func_8002D268(player, camera, screenId, playerId);
        }
        func_8002934C(player, camera, screenId, playerId);
        if ((screenId == 0) || (screenId == 1)) {
            load_kart_palette(player, playerId, screenId, 0);
            load_kart_palette(player, playerId, screenId, 1);
            load_kart_texture(player, playerId, screenId, screenId, 0);
#ifdef TARGET_N64
            mio0decode((u8*) &gEncodedKartTexture[0][screenId][playerId],
                       (u8*) &D_802BFB80.arraySize8[0][screenId][playerId]);
#endif
        } else {
            load_kart_palette(player, playerId, screenId, 0);
            load_kart_palette(player, playerId, screenId, 1);
            load_kart_texture(player, (s8) (playerId + 4), screenId, (s8) (screenId - 2), 0);
#ifdef TARGET_N64
            mio0decode((u8*) &gEncodedKartTexture[0][screenId - 2][playerId + 4],
                       (u8*) &D_802BFB80.arraySize8[0][screenId - 2][playerId + 4]);
#endif
        }

        gLastAnimFrameSelector[screenId][playerId] = player->animFrameSelector[screenId];
        gLastAnimGroupSelector[screenId][playerId] = player->animGroupSelector[screenId];
        D_80165150[screenId][playerId] = player->unk_0A8;
        D_801651D0[screenId][playerId] = 0;
        render_player(player, playerId, screenId);
    }
}

void spawn_players_and_cameras(void) {
    UNUSED s32 pad;
    Player* player = &gPlayers[0];
    Camera* camera;

    // Load textures for balloons and kart shadows
    func_8005D290();
    // Spawn players
    if (gGamestate == ENDING) {
        func_8003CD78();
    } else {
        func_8003C0F0();
    }

    u32 mode; // set camera mode
    switch (gModeSelection) {
        case GRAND_PRIX:
            if (gActiveScreenMode == SCREEN_MODE_1P) {
                mode = 8;
            } else {
                mode = 1;
            }
            break;
        case TIME_TRIALS:
            mode = 1;
            break;
        case BATTLE:
            mode = 9;
            break;
        default:
            mode = 1;
            break;
    }

    if (gDemoMode) {
        mode = 3;
    }

    for (size_t i = 0; i < 4; i++) {
        D_80164A08[i] = 0;
        D_80164498[i] = 0;
    }

    if (gActiveScreenMode == SCREEN_MODE_1P) {
        spawn_single_player_camera(mode);
    } else {
        spawn_multiplayer_cameras(mode);
    }

    // Add freecam, tourcam, and lookbehind cameras
    Vec3f spawn = {player->pos[0], player->pos[1], player->pos[2]};

    camera = CM_AddFreeCamera(spawn, player->rotation[1], 1);
    if (!camera) {
        CM_ThrowRuntimeError("[spawn_players] [spawn_players_and_cameras] NULL camera while attempting to create FreeCamera for player one");
    }
    gScreenContexts[PLAYER_ONE].freeCamera = camera;

    if (CVarGetInteger("gFreecam", false) == true) {
        CM_SetFreeCamera(true);
        gScreenContexts[PLAYER_ONE].camera = camera;
    }

    if ((CM_IsTourEnabled() == true) && (gModeSelection == GRAND_PRIX) && (Editor_IsPaused() == false)) {
        camera = CM_AddTourCamera(spawn, player->rotation[1], 1);
        if (!camera) {
            CM_ThrowRuntimeError("[spawn_players] [spawn_players_and_cameras] NULL camera while attempting to create TourCamera for player one");
        }
        CM_AttachCamera(camera, PLAYER_ONE);
        gScreenContexts[PLAYER_ONE].camera = camera;
        gScreenContexts[PLAYER_ONE].pendingCamera = NULL;
        CM_CameraSetActive(0, false);
        CM_ActivateTourCamera(camera);
    }
}

void spawn_single_player_camera(u32 mode) {
    Vec3f spawn = {gPlayerOne->pos[0], gPlayerOne->pos[1], gPlayerOne->pos[2]};
    Vec3f spawn2 = {gPlayerTwo->pos[0], gPlayerTwo->pos[1], gPlayerTwo->pos[2]};

    // Technically there should be a default case of mode 10 here. Except it never gets used.
    if (gModeSelection == GRAND_PRIX && !gDemoMode) {
        if (IsToadsTurnpike()) {
            spawn[0] = 0.0f;
            spawn[2] = D_80165230[7];
        } else {
            spawn[0] = (D_80165210[7] + D_80165210[6]) / 2;
            spawn[2] = D_80165230[7];

        }
    }

    Camera* camera = CM_AddCamera(spawn, gPlayerOne->rotation[1], mode);
    if (!camera) {
        CM_ThrowRuntimeError("[spawn_players] [spawn_single_player_camera] NULL camera while attempting to create camera for player one");
    }
    CM_AttachCamera(camera, PLAYER_ONE);
    gScreenContexts[PLAYER_ONE].camera = camera;
    gScreenContexts[PLAYER_ONE].raceCamera = camera;

    // For end of race scene
    camera = CM_AddCamera(spawn2, gPlayerTwo->rotation[1], mode);
    if (!camera) {
        CM_ThrowRuntimeError("[spawn_players] [spawn_single_player_camera] NULL camera while attempting to create camera for player two");
    }
    CM_AttachCamera(camera, PLAYER_TWO);
    gScreenContexts[PLAYER_TWO].camera = camera;
    gScreenContexts[PLAYER_TWO].raceCamera = camera;

    camera = CM_AddLookBehindCamera(spawn, gPlayerOne->rotation[1], mode);
    if (!camera) {
        CM_ThrowRuntimeError("[spawn_players] [spawn_single_player_camera] NULL camera while attempting to create LookBehind camera for player one");
    }
    CM_AttachCamera(camera, PLAYER_ONE);
    gScreenContexts[PLAYER_ONE].lookBehindCamera = camera;
}

void spawn_multiplayer_cameras(u32 mode) {
    Camera* camera;
    size_t screens = 0;
    switch(gActiveScreenMode) {
        case SCREEN_MODE_1P:
            screens = 1;
            break;
        case SCREEN_MODE_2P_SPLITSCREEN_HORIZONTAL:
        case SCREEN_MODE_2P_SPLITSCREEN_VERTICAL:
            screens = 2;
            break;
        case SCREEN_MODE_3P_4P_SPLITSCREEN:
            screens = 4;
            break;
    }
    for (size_t i = 0; i < screens; i++) {
        Vec3f spawn = {gPlayers[i].pos[0], gPlayers[i].pos[1], gPlayers[i].pos[2]};
        camera = CM_AddCamera(spawn, gPlayers[i].rotation[1], mode);
        if (!camera) {
            CM_ThrowRuntimeError("[spawn_players] [spawn_multiplayer_cameras] NULL camera while attempting to create camera for player %d", i);
        }
        CM_AttachCamera(camera, i);
        gScreenContexts[i].camera = camera;
        gScreenContexts[i].raceCamera = camera;
    }

    for (size_t i = 0; i < screens; i++) {
        Vec3f spawn = {gPlayers[i].pos[0], gPlayers[i].pos[1], gPlayers[i].pos[2]};
        camera = CM_AddLookBehindCamera(spawn, gPlayers[i].rotation[1], mode);
        if (!camera) {
            CM_ThrowRuntimeError("[spawn_players] [spawn_multiplayer_cameras] NULL camera while attempting to create LookBehind camera for player %d", i);
        }
        CM_AttachCamera(camera, i);
        gScreenContexts[i].lookBehindCamera = camera;
    }

}

/**
 * Loads 8 players per screen in 1p/2p mode
 * Loads 4 players per screen in 3p/4p mode
 */
void load_kart_textures(void) {
    size_t screens = 0;
    switch(gActiveScreenMode) {
        case SCREEN_MODE_1P:
            screens = 1;
            break;
        case SCREEN_MODE_2P_SPLITSCREEN_HORIZONTAL:
        case SCREEN_MODE_2P_SPLITSCREEN_VERTICAL:
            screens = 2;
            break;
        case SCREEN_MODE_3P_4P_SPLITSCREEN:
            screens = 4;
            break;
    }

    static const size_t playerCounts[4] = { 8, 8, 4, 4 };
    for (size_t i = 0; i < screens; i++) {
        for (size_t ply = 0; ply < playerCounts[gPlayerCountSelection1 - 1]; ply++) {
            func_8003CD98(&gPlayers[ply], gScreenContexts[i].camera, ply, i);
        }
    }
}

void func_8003DB5C(void) {
    Player* player = gPlayerOne;
    Camera* camera;
    s32 playerId;

    Vec3f spawn = {player->pos[0], player->pos[1], player->pos[2]};
    camera = CM_AddCamera(spawn, player->rotation[1], 3);
    if (!camera) {
        CM_ThrowRuntimeError("[spawn_players] [func_8003DB5C] NULL camera while attempting to create camera for player one");
    }
    CM_AttachCamera(camera, PLAYER_ONE);
    camera = CM_AddCamera(spawn, player->rotation[1], 3);
    if (!camera) {
        CM_ThrowRuntimeError("[spawn_players] [func_8003DB5C] NULL camera while attempting to create camera for player two");
    }
    CM_AttachCamera(camera, PLAYER_TWO);

    for (playerId = 0; playerId < NUM_PLAYERS; playerId++, player++) {
        load_kart_palette(player, playerId, 1, 0);
        load_kart_palette(player, playerId, 1, 1);
    }
}