/
k_kart.c
8498 lines (7322 loc) · 266 KB
/
k_kart.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
// SONIC ROBO BLAST 2 KART ~ ZarroTsu
//-----------------------------------------------------------------------------
/// \file k_kart.c
/// \brief SRB2kart general.
/// All of the SRB2kart-unique stuff.
#include "doomdef.h"
#include "hu_stuff.h"
#include "g_game.h"
#include "m_random.h"
#include "p_local.h"
#include "p_slopes.h"
#include "r_draw.h"
#include "r_local.h"
#include "s_sound.h"
#include "st_stuff.h"
#include "v_video.h"
#include "z_zone.h"
#include "m_misc.h"
#include "m_cond.h"
#include "k_kart.h"
#include "f_finale.h"
#include "lua_hud.h" // For Lua hud checks
#include "lua_hook.h" // For MobjDamage and ShouldDamage
// SOME IMPORTANT VARIABLES DEFINED IN DOOMDEF.H:
// gamespeed is cc (0 for easy, 1 for normal, 2 for hard)
// franticitems is Frantic Mode items, bool
// encoremode is Encore Mode (duh), bool
// comeback is Battle Mode's karma comeback, also bool
// battlewanted is an array of the WANTED player nums, -1 for no player in that slot
// indirectitemcooldown is timer before anyone's allowed another Shrink/SPB
// mapreset is set when enough players fill an empty server
// nospectategrief is the players in-game needed to eliminate the person in last
//{ SRB2kart Color Code
#define SKIN_RAMP_LENGTH 16
#define DEFAULT_STARTTRANSCOLOR 160
#define NUM_PALETTE_ENTRIES 256
// These should be within 14 characters to fit on the character select screen
const char *KartColor_Names[MAXSKINCOLORS] =
{
"None", // 00 // SKINCOLOR_NONE
"White", // 01 // SKINCOLOR_WHITE
"Silver", // 02 // SKINCOLOR_SILVER
"Grey", // 03 // SKINCOLOR_GREY
"Nickel", // 04 // SKINCOLOR_NICKEL
"Black", // 05 // SKINCOLOR_BLACK
"Sepia", // 06 // SKINCOLOR_SEPIA
"Beige", // 07 // SKINCOLOR_BEIGE
"Brown", // 08 // SKINCOLOR_BROWN
"Leather", // 09 // SKINCOLOR_LEATHER
"Salmon", // 10 // SKINCOLOR_SALMON
"Pink", // 11 // SKINCOLOR_PINK
"Rose", // 12 // SKINCOLOR_ROSE
"Ruby", // 13 // SKINCOLOR_RUBY
"Raspberry", // 14 // SKINCOLOR_RASPBERRY
"Red", // 15 // SKINCOLOR_RED
"Crimson", // 16 // SKINCOLOR_CRIMSON
"Ketchup", // 17 // SKINCOLOR_KETCHUP
"Dawn", // 18 // SKINCOLOR_DAWN
"Creamsicle", // 19 // SKINCOLOR_CREAMSICLE
"Orange", // 20 // SKINCOLOR_ORANGE
"Pumpkin", // 21 // SKINCOLOR_PUMPKIN
"Rosewood", // 22 // SKINCOLOR_ROSEWOOD
"Burgundy", // 23 // SKINCOLOR_BURGUNDY
"Tangerine", // 24 // SKINCOLOR_TANGERINE
"Peach", // 25 // SKINCOLOR_PEACH
"Caramel", // 26 // SKINCOLOR_CARAMEL
"Gold", // 27 // SKINCOLOR_GOLD
"Bronze", // 28 // SKINCOLOR_BRONZE
"Yellow", // 29 // SKINCOLOR_YELLOW
"Mustard", // 30 // SKINCOLOR_MUSTARD
"Olive", // 31 // SKINCOLOR_OLIVE
"Vomit", // 32 // SKINCOLOR_VOMIT
"Garden", // 33 // SKINCOLOR_GARDEN
"Lime", // 34 // SKINCOLOR_LIME
"Tea", // 35 // SKINCOLOR_TEA
"Pistachio", // 36 // SKINCOLOR_PISTACHIO
"Robo-Hood", // 37 // SKINCOLOR_ROBOHOOD
"Moss", // 38 // SKINCOLOR_MOSS
"Mint", // 39 // SKINCOLOR_MINT
"Green", // 40 // SKINCOLOR_GREEN
"Pinetree", // 41 // SKINCOLOR_PINETREE
"Emerald", // 42 // SKINCOLOR_EMERALD
"Swamp", // 43 // SKINCOLOR_SWAMP
"Dream", // 44 // SKINCOLOR_DREAM
"Aqua", // 45 // SKINCOLOR_AQUA
"Teal", // 46 // SKINCOLOR_TEAL
"Cyan", // 47 // SKINCOLOR_CYAN
"Jawz", // 48 // SKINCOLOR_JAWZ
"Cerulean", // 49 // SKINCOLOR_CERULEAN
"Navy", // 50 // SKINCOLOR_NAVY
"Slate", // 51 // SKINCOLOR_SLATE
"Steel", // 52 // SKINCOLOR_STEEL
"Jet", // 53 // SKINCOLOR_JET
"Sapphire", // 54 // SKINCOLOR_SAPPHIRE
"Periwinkle", // 55 // SKINCOLOR_PERIWINKLE
"Blue", // 56 // SKINCOLOR_BLUE
"Blueberry", // 57 // SKINCOLOR_BLUEBERRY
"Dusk", // 58 // SKINCOLOR_DUSK
"Purple", // 59 // SKINCOLOR_PURPLE
"Lavender", // 60 // SKINCOLOR_LAVENDER
"Byzantium", // 61 // SKINCOLOR_BYZANTIUM
"Pomegranate", // 62 // SKINCOLOR_POMEGRANATE
"Lilac" // 63 // SKINCOLOR_LILAC
};
// Color_Opposite replacement; frame setting has not been changed from 8 for most, should be done later
const UINT8 KartColor_Opposite[MAXSKINCOLORS*2] =
{
SKINCOLOR_NONE,8, // 00 // SKINCOLOR_NONE
SKINCOLOR_BLACK,8, // 01 // SKINCOLOR_WHITE
SKINCOLOR_NICKEL,8, // 02 // SKINCOLOR_SILVER
SKINCOLOR_GREY,8, // 03 // SKINCOLOR_GREY
SKINCOLOR_SILVER,8, // 04 // SKINCOLOR_NICKEL
SKINCOLOR_WHITE,8, // 05 // SKINCOLOR_BLACK
SKINCOLOR_LEATHER,6, // 06 // SKINCOLOR_SEPIA
SKINCOLOR_BROWN,2, // 07 // SKINCOLOR_BEIGE
SKINCOLOR_BEIGE,8, // 08 // SKINCOLOR_BROWN
SKINCOLOR_SEPIA,8, // 09 // SKINCOLOR_LEATHER
SKINCOLOR_TEA,8, // 10 // SKINCOLOR_SALMON
SKINCOLOR_PISTACHIO,8, // 11 // SKINCOLOR_PINK
SKINCOLOR_MOSS,8, // 12 // SKINCOLOR_ROSE
SKINCOLOR_SAPPHIRE,8, // 13 // SKINCOLOR_RUBY
SKINCOLOR_MINT,8, // 14 // SKINCOLOR_RASPBERRY
SKINCOLOR_GREEN,6, // 15 // SKINCOLOR_RED
SKINCOLOR_PINETREE,6, // 16 // SKINCOLOR_CRIMSON
SKINCOLOR_MUSTARD,10, // 17 // SKINCOLOR_KETCHUP
SKINCOLOR_DUSK,8, // 18 // SKINCOLOR_DAWN
SKINCOLOR_PERIWINKLE,8, // 19 // SKINCOLOR_CREAMSICLE
SKINCOLOR_BLUE,8, // 20 // SKINCOLOR_ORANGE
SKINCOLOR_BLUEBERRY,8, // 21 // SKINCOLOR_PUMPKIN
SKINCOLOR_NAVY,6, // 22 // SKINCOLOR_ROSEWOOD
SKINCOLOR_JET,8, // 23 // SKINCOLOR_BURGUNDY
SKINCOLOR_LIME,8, // 24 // SKINCOLOR_TANGERINE
SKINCOLOR_CYAN,8, // 25 // SKINCOLOR_PEACH
SKINCOLOR_CERULEAN,8, // 26 // SKINCOLOR_CARAMEL
SKINCOLOR_SLATE,8, // 27 // SKINCOLOR_GOLD
SKINCOLOR_STEEL,8, // 28 // SKINCOLOR_BRONZE
SKINCOLOR_AQUA,8, // 29 // SKINCOLOR_YELLOW
SKINCOLOR_KETCHUP,8, // 30 // SKINCOLOR_MUSTARD
SKINCOLOR_TEAL,8, // 31 // SKINCOLOR_OLIVE
SKINCOLOR_ROBOHOOD,8, // 32 // SKINCOLOR_VOMIT
SKINCOLOR_LAVENDER,6, // 33 // SKINCOLOR_GARDEN
SKINCOLOR_TANGERINE,8, // 34 // SKINCOLOR_LIME
SKINCOLOR_SALMON,8, // 35 // SKINCOLOR_TEA
SKINCOLOR_PINK,6, // 36 // SKINCOLOR_PISTACHIO
SKINCOLOR_VOMIT,8, // 37 // SKINCOLOR_ROBOHOOD
SKINCOLOR_ROSE,8, // 38 // SKINCOLOR_MOSS
SKINCOLOR_RASPBERRY,8, // 39 // SKINCOLOR_MINT
SKINCOLOR_RED,8, // 40 // SKINCOLOR_GREEN
SKINCOLOR_CRIMSON,8, // 41 // SKINCOLOR_PINETREE
SKINCOLOR_PURPLE,8, // 42 // SKINCOLOR_EMERALD
SKINCOLOR_BYZANTIUM,8, // 43 // SKINCOLOR_SWAMP
SKINCOLOR_POMEGRANATE,8, // 44 // SKINCOLOR_DREAM
SKINCOLOR_YELLOW,8, // 45 // SKINCOLOR_AQUA
SKINCOLOR_OLIVE,8, // 46 // SKINCOLOR_TEAL
SKINCOLOR_PEACH,8, // 47 // SKINCOLOR_CYAN
SKINCOLOR_LILAC,10, // 48 // SKINCOLOR_JAWZ
SKINCOLOR_CARAMEL,8, // 49 // SKINCOLOR_CERULEAN
SKINCOLOR_ROSEWOOD,8, // 50 // SKINCOLOR_NAVY
SKINCOLOR_GOLD,10, // 51 // SKINCOLOR_SLATE
SKINCOLOR_BRONZE,10, // 52 // SKINCOLOR_STEEL
SKINCOLOR_BURGUNDY,8, // 53 // SKINCOLOR_JET
SKINCOLOR_RUBY,6, // 54 // SKINCOLOR_SAPPHIRE
SKINCOLOR_CREAMSICLE,8, // 55 // SKINCOLOR_PERIWINKLE
SKINCOLOR_ORANGE,8, // 56 // SKINCOLOR_BLUE
SKINCOLOR_PUMPKIN,8, // 57 // SKINCOLOR_BLUEBERRY
SKINCOLOR_DAWN,6, // 58 // SKINCOLOR_DUSK
SKINCOLOR_EMERALD,8, // 59 // SKINCOLOR_PURPLE
SKINCOLOR_GARDEN,6, // 60 // SKINCOLOR_LAVENDER
SKINCOLOR_SWAMP,8, // 61 // SKINCOLOR_BYZANTIUM
SKINCOLOR_DREAM,8, // 62 // SKINCOLOR_POMEGRANATE
SKINCOLOR_JAWZ,6 // 63 // SKINCOLOR_LILAC
};
UINT8 colortranslations[MAXSKINCOLORS][16] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // SKINCOLOR_NONE
{120, 120, 120, 120, 0, 1, 3, 4, 6, 7, 10, 14, 18, 22, 25, 28}, // SKINCOLOR_WHITE
{ 0, 1, 2, 4, 5, 7, 8, 10, 13, 15, 18, 20, 23, 25, 28, 30}, // SKINCOLOR_SILVER
{ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}, // SKINCOLOR_GREY
{ 12, 14, 16, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}, // SKINCOLOR_NICKEL
{ 16, 17, 19, 21, 22, 24, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31}, // SKINCOLOR_BLACK
{ 0, 1, 3, 5, 7, 9, 34, 36, 38, 40, 42, 44, 60, 61, 62, 63}, // SKINCOLOR_SEPIA
{ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}, // SKINCOLOR_BEIGE
{ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63}, // SKINCOLOR_BROWN
{ 51, 52, 53, 55, 56, 57, 58, 60, 61, 63, 28, 28, 29, 29, 30, 31}, // SKINCOLOR_LEATHER
{120, 120, 120, 121, 121, 122, 122, 123, 124, 125, 126, 128, 129, 131, 133, 135}, // SKINCOLOR_SALMON
{120, 121, 121, 122, 144, 145, 146, 147, 148, 149, 150, 151, 134, 136, 138, 140}, // SKINCOLOR_PINK
{144, 145, 146, 147, 148, 149, 150, 151, 134, 135, 136, 137, 138, 139, 140, 141}, // SKINCOLOR_ROSE
{121, 122, 145, 146, 147, 149, 131, 132, 133, 134, 135, 197, 197, 198, 199, 255}, // SKINCOLOR_RUBY
{120, 121, 122, 123, 124, 125, 126, 127, 128, 130, 131, 133, 134, 136, 137, 139}, // SKINCOLOR_RASPBERRY
{125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140}, // SKINCOLOR_RED
{130, 131, 132, 133, 134, 136, 137, 138, 139, 139, 140, 140, 141, 141, 142, 143}, // SKINCOLOR_CRIMSON
{104, 113, 113, 85, 86, 88, 128, 129, 131, 133, 134, 136, 138, 139, 141, 143}, // SKINCOLOR_KETCHUP
{120, 121, 122, 123, 124, 147, 147, 148, 90, 91, 92, 93, 94, 95, 152, 154}, // SKINCOLOR_DAWN
{120, 120, 80, 80, 81, 82, 83, 83, 84, 85, 86, 88, 89, 91, 93, 95}, // SKINCOLOR_CREAMSICLE
{ 80, 81, 82, 83, 84, 85, 86, 88, 89, 91, 94, 95, 154, 156, 158, 159}, // SKINCOLOR_ORANGE
{ 84, 85, 86, 87, 88, 90, 92, 93, 94, 95, 152, 153, 154, 156, 157, 159}, // SKINCOLOR_PUMPKIN
{ 90, 91, 92, 93, 94, 152, 153, 154, 155, 156, 157, 158, 159, 139, 141, 143}, // SKINCOLOR_ROSEWOOD
{ 94, 95, 152, 153, 154, 156, 157, 159, 141, 141, 141, 142, 142, 143, 143, 31}, // SKINCOLOR_BURGUNDY
{ 98, 98, 112, 112, 113, 113, 84, 85, 87, 89, 91, 93, 95, 153, 156, 159}, // SKINCOLOR_TANGERINE
{ 64, 65, 67, 68, 70, 71, 73, 74, 76, 77, 79, 48, 50, 53, 56, 59}, // SKINCOLOR_PEACH
{ 64, 66, 68, 70, 72, 74, 76, 78, 48, 50, 52, 54, 56, 58, 60, 62}, // SKINCOLOR_CARAMEL
{112, 112, 112, 113, 113, 114, 114, 115, 115, 116, 116, 117, 117, 118, 118, 119}, // SKINCOLOR_GOLD
{112, 113, 114, 115, 116, 117, 118, 119, 156, 157, 158, 159, 141, 141, 142, 143}, // SKINCOLOR_BRONZE
{ 96, 97, 98, 100, 101, 102, 104, 113, 114, 115, 116, 117, 118, 119, 156, 159}, // SKINCOLOR_YELLOW
{ 96, 98, 99, 112, 113, 114, 114, 106, 106, 107, 107, 108, 108, 109, 110, 111}, // SKINCOLOR_MUSTARD
{105, 105, 105, 106, 106, 107, 107, 108, 108, 109, 109, 110, 110, 111, 111, 31}, // SKINCOLOR_OLIVE
{121, 144, 145, 72, 73, 84, 114, 115, 107, 108, 109, 183, 223, 207, 30, 246}, // SKINCOLOR_VOMIT
{ 98, 99, 112, 101, 113, 114, 106, 179, 180, 180, 181, 182, 183, 173, 174, 175}, // SKINCOLOR_GARDEN
{ 96, 97, 99, 100, 102, 104, 160, 162, 164, 166, 168, 171, 223, 223, 207, 31}, // SKINCOLOR_LIME
{120, 120, 176, 176, 176, 177, 177, 178, 178, 179, 179, 180, 180, 181, 182, 183}, // SKINCOLOR_TEA
{120, 120, 176, 176, 177, 177, 178, 179, 165, 166, 167, 168, 169, 170, 171, 172}, // SKINCOLOR_PISTACHIO
{176, 176, 177, 178, 165, 166, 167, 167, 168, 169, 182, 182, 182, 183, 183, 183}, // SKINCOLOR_ROBOHOOD
{178, 178, 178, 179, 179, 180, 181, 182, 183, 172, 172, 173, 173, 174, 174, 175}, // SKINCOLOR_MOSS
{120, 176, 176, 176, 177, 163, 164, 165, 167, 221, 221, 222, 223, 207, 207, 31}, // SKINCOLOR_MINT
{160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175}, // SKINCOLOR_GREEN
{160, 161, 162, 164, 165, 167, 169, 170, 171, 171, 172, 173, 174, 175, 30, 31}, // SKINCOLOR_PINETREE
{160, 184, 184, 185, 185, 186, 186, 187, 187, 188, 188, 189, 189, 190, 191, 175}, // SKINCOLOR_EMERALD
{186, 187, 188, 188, 188, 189, 189, 190, 190, 191, 175, 175, 30, 30, 31, 31}, // SKINCOLOR_SWAMP
{120, 120, 80, 80, 81, 177, 162, 164, 228, 228, 204, 204, 205, 205, 206, 207}, // SKINCOLOR_DREAM
{120, 208, 208, 210, 212, 214, 220, 220, 220, 221, 221, 222, 222, 223, 223, 191}, // SKINCOLOR_AQUA
{210, 213, 220, 220, 220, 216, 216, 221, 221, 221, 222, 222, 223, 223, 191, 31}, // SKINCOLOR_TEAL
{120, 120, 208, 208, 209, 210, 211, 212, 213, 215, 216, 217, 218, 219, 222, 223}, // SKINCOLOR_CYAN
{120, 120, 208, 209, 210, 226, 215, 216, 217, 229, 229, 205, 205, 206, 207, 31}, // SKINCOLOR_JAWZ
{208, 209, 211, 213, 215, 216, 216, 217, 217, 218, 218, 219, 205, 206, 207, 207}, // SKINCOLOR_CERULEAN
{211, 212, 213, 215, 216, 218, 219, 205, 206, 206, 207, 207, 28, 29, 30, 31}, // SKINCOLOR_NAVY
{120, 120, 200, 200, 200, 201, 201, 201, 202, 202, 202, 203, 204, 205, 206, 207}, // SKINCOLOR_SLATE
{120, 200, 200, 201, 201, 202, 202, 203, 203, 204, 204, 205, 205, 206, 207, 31}, // SKINCOLOR_STEEL
{225, 226, 227, 228, 229, 205, 205, 206, 207, 207, 28, 28, 29, 29, 30, 31}, // SKINCOLOR_JET
{208, 209, 211, 213, 215, 217, 229, 230, 232, 234, 236, 238, 240, 242, 244, 246}, // SKINCOLOR_SAPPHIRE
{120, 224, 225, 226, 226, 227, 228, 228, 229, 230, 231, 234, 235, 237, 239, 241}, // SKINCOLOR_PERIWINKLE
{224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239}, // SKINCOLOR_BLUE
{228, 229, 230, 231, 232, 233, 234, 235, 237, 238, 239, 240, 242, 243, 244, 245}, // SKINCOLOR_BLUEBERRY
{192, 192, 248, 249, 250, 251, 204, 204, 205, 205, 206, 206, 207, 29, 30, 31}, // SKINCOLOR_DUSK
{192, 192, 192, 193, 193, 194, 194, 195, 195, 196, 196, 197, 197, 198, 198, 199}, // SKINCOLOR_PURPLE
{248, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252, 253, 253, 254, 254, 255}, // SKINCOLOR_LAVENDER
{192, 248, 249, 250, 251, 252, 253, 254, 255, 255, 29, 29, 30, 30, 31, 31}, // SKINCOLOR_BYZANTIUM
{144, 145, 146, 147, 148, 149, 150, 251, 251, 252, 252, 253, 254, 255, 29, 30}, // SKINCOLOR_POMEGRANATE
{120, 120, 120, 121, 121, 122, 122, 123, 192, 248, 249, 250, 251, 252, 253, 254}, // SKINCOLOR_LILAC
/* Removed Colours
{120, 121, 123, 124, 126, 127, 129, 130, 132, 133, 135, 136, 138, 139, 141, 143}, // old SKINCOLOR_RUBY, removed for other colors
{224, 225, 226, 228, 229, 231, 232, 234, 235, 237, 238, 240, 241, 243, 244, 246}, // old SKINCOLOR_SAPPHIRE, removed for other colors
{ 72, 73, 74, 75, 76, 77, 78, 79, 48, 49, 50, 51, 52, 53, 54, 55}, // old SKINCOLOR_CARAMEL, new Caramel was previously Shiny Caramel
{215, 216, 217, 218, 204, 205, 206, 237, 238, 239, 240, 241, 242, 243, 244, 245}, // old SKINCOLOR_NAVY, too similar to Jet
{ 80, 81, 83, 85, 86, 88, 90, 91, 93, 95, 152, 153, 154, 156, 157, 159}, // SKINCOLOR_AMBER, removed for other colors
{160, 160, 160, 184, 184, 184, 185, 185, 185, 186, 187, 187, 188, 188, 189, 190}, // SKINCOLOR_JADE, removed for other colors
{224, 225, 226, 212, 213, 213, 214, 215, 220, 221, 172, 222, 173, 223, 174, 175}, // SKINCOLOR_FROST, merged into Aqua
{ 96, 97, 99, 100, 102, 104, 105, 105, 106, 107, 107, 108, 109, 109, 110, 111}, // SKINCOLOR_CANARY, replaced with Mustard
{192, 193, 194, 195, 196, 197, 198, 199, 255, 255, 29, 29, 30, 30, 31, 31}, // SKINCOLOR_INDIGO, too similar to Byzantium
{ 1, 145, 125, 73, 83, 114, 106, 180, 187, 168, 219, 205, 236, 206, 199, 255}, // SKINCOLOR_RAINBOW, is Vomit 2.0
*/
};
// Define for getting accurate color brightness readings according to how the human eye sees them.
// https://en.wikipedia.org/wiki/Relative_luminance
// 0.2126 to red
// 0.7152 to green
// 0.0722 to blue
// (See this same define in hw_md2.c!)
#define SETBRIGHTNESS(brightness,r,g,b) \
brightness = (UINT8)(((1063*((UINT16)r)/5000) + (3576*((UINT16)g)/5000) + (361*((UINT16)b)/5000)) / 3)
/** \brief Generates the rainbow colourmaps that are used when a player has the invincibility power
\param dest_colormap colormap to populate
\param skincolor translation color
*/
void K_RainbowColormap(UINT8 *dest_colormap, UINT8 skincolor)
{
INT32 i;
RGBA_t color;
UINT8 brightness;
INT32 j;
UINT8 colorbrightnesses[16];
UINT16 brightdif;
INT32 temp;
// first generate the brightness of all the colours of that skincolour
for (i = 0; i < 16; i++)
{
color = V_GetColor(colortranslations[skincolor][i]);
SETBRIGHTNESS(colorbrightnesses[i], color.s.red, color.s.green, color.s.blue);
}
// next, for every colour in the palette, choose the transcolor that has the closest brightness
for (i = 0; i < NUM_PALETTE_ENTRIES; i++)
{
if (i == 0 || i == 31 || i == 120) // pure black and pure white don't change
{
dest_colormap[i] = (UINT8)i;
continue;
}
color = V_GetColor(i);
SETBRIGHTNESS(brightness, color.s.red, color.s.green, color.s.blue);
brightdif = 256;
for (j = 0; j < 16; j++)
{
temp = abs((INT16)brightness - (INT16)colorbrightnesses[j]);
if (temp < brightdif)
{
brightdif = (UINT16)temp;
dest_colormap[i] = colortranslations[skincolor][j];
}
}
}
}
#undef SETBRIGHTNESS
/** \brief Generates a translation colormap for Kart, to replace R_GenerateTranslationColormap in r_draw.c
\param dest_colormap colormap to populate
\param skinnum number of skin, TC_DEFAULT or TC_BOSS
\param color translation color
\return void
*/
void K_GenerateKartColormap(UINT8 *dest_colormap, INT32 skinnum, UINT8 color)
{
INT32 i;
INT32 starttranscolor;
// Handle a couple of simple special cases
if (skinnum == TC_BOSS
|| skinnum == TC_ALLWHITE
|| skinnum == TC_METALSONIC
|| skinnum == TC_BLINK
|| color == SKINCOLOR_NONE)
{
for (i = 0; i < NUM_PALETTE_ENTRIES; i++)
{
if (skinnum == TC_ALLWHITE)
dest_colormap[i] = 0;
else if (skinnum == TC_BLINK)
dest_colormap[i] = colortranslations[color][3];
else
dest_colormap[i] = (UINT8)i;
}
// White!
if (skinnum == TC_BOSS)
dest_colormap[31] = 0;
else if (skinnum == TC_METALSONIC)
dest_colormap[239] = 0;
return;
}
else if (skinnum == TC_RAINBOW)
{
K_RainbowColormap(dest_colormap, color);
return;
}
starttranscolor = (skinnum != TC_DEFAULT) ? skins[skinnum].starttranscolor : DEFAULT_STARTTRANSCOLOR;
// Fill in the entries of the palette that are fixed
for (i = 0; i < starttranscolor; i++)
dest_colormap[i] = (UINT8)i;
for (i = (UINT8)(starttranscolor + 16); i < NUM_PALETTE_ENTRIES; i++)
dest_colormap[i] = (UINT8)i;
// Build the translated ramp
for (i = 0; i < SKIN_RAMP_LENGTH; i++)
{
// Sryder 2017-10-26: What was here before was most definitely not particularly readable, check above for new color translation table
dest_colormap[starttranscolor + i] = colortranslations[color][i];
}
}
/** \brief Pulls kart color by name, to replace R_GetColorByName in r_draw.c
\param name color name
\return 0
*/
UINT8 K_GetKartColorByName(const char *name)
{
UINT8 color = (UINT8)atoi(name);
if (color > 0 && color < MAXSKINCOLORS)
return color;
for (color = 1; color < MAXSKINCOLORS; color++)
if (!stricmp(KartColor_Names[color], name))
return color;
return 0;
}
//}
//{ SRB2kart Net Variables
void K_RegisterKartStuff(void)
{
CV_RegisterVar(&cv_sneaker);
CV_RegisterVar(&cv_rocketsneaker);
CV_RegisterVar(&cv_invincibility);
CV_RegisterVar(&cv_banana);
CV_RegisterVar(&cv_eggmanmonitor);
CV_RegisterVar(&cv_orbinaut);
CV_RegisterVar(&cv_jawz);
CV_RegisterVar(&cv_mine);
CV_RegisterVar(&cv_ballhog);
CV_RegisterVar(&cv_selfpropelledbomb);
CV_RegisterVar(&cv_grow);
CV_RegisterVar(&cv_shrink);
CV_RegisterVar(&cv_thundershield);
CV_RegisterVar(&cv_hyudoro);
CV_RegisterVar(&cv_pogospring);
CV_RegisterVar(&cv_kitchensink);
CV_RegisterVar(&cv_triplesneaker);
CV_RegisterVar(&cv_triplebanana);
CV_RegisterVar(&cv_decabanana);
CV_RegisterVar(&cv_tripleorbinaut);
CV_RegisterVar(&cv_quadorbinaut);
CV_RegisterVar(&cv_dualjawz);
CV_RegisterVar(&cv_kartminimap);
CV_RegisterVar(&cv_kartcheck);
CV_RegisterVar(&cv_kartinvinsfx);
CV_RegisterVar(&cv_kartspeed);
CV_RegisterVar(&cv_kartbumpers);
CV_RegisterVar(&cv_kartfrantic);
CV_RegisterVar(&cv_kartcomeback);
CV_RegisterVar(&cv_kartencore);
CV_RegisterVar(&cv_kartvoterulechanges);
CV_RegisterVar(&cv_kartspeedometer);
CV_RegisterVar(&cv_kartvoices);
CV_RegisterVar(&cv_karteliminatelast);
CV_RegisterVar(&cv_votetime);
CV_RegisterVar(&cv_kartdebugitem);
CV_RegisterVar(&cv_kartdebugamount);
CV_RegisterVar(&cv_kartdebugshrink);
CV_RegisterVar(&cv_kartdebugdistribution);
CV_RegisterVar(&cv_kartdebughuddrop);
CV_RegisterVar(&cv_kartdebugcheckpoint);
CV_RegisterVar(&cv_kartdebugnodes);
}
//}
boolean K_IsPlayerLosing(player_t *player)
{
INT32 winningpos = 1;
UINT8 i, pcount = 0;
if (player->kartstuff[k_position] == 1)
return false;
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i] || players[i].spectator)
continue;
if (players[i].kartstuff[k_position] > pcount)
pcount = players[i].kartstuff[k_position];
}
if (pcount <= 1)
return false;
winningpos = pcount/2;
if (pcount % 2) // any remainder?
winningpos++;
return (player->kartstuff[k_position] > winningpos);
}
boolean K_IsPlayerWanted(player_t *player)
{
UINT8 i;
if (!(G_BattleGametype()))
return false;
for (i = 0; i < 4; i++)
{
if (battlewanted[i] == -1)
break;
if (player == &players[battlewanted[i]])
return true;
}
return false;
}
//{ SRB2kart Roulette Code - Position Based
#define NUMKARTODDS 80
// Less ugly 2D arrays
static INT32 K_KartItemOddsRace[NUMKARTRESULTS][10] =
{
//P-Odds 0 1 2 3 4 5 6 7 8 9
/*Sneaker*/ {20, 0, 0, 4, 6, 6, 0, 0, 0, 0 }, // Sneaker
/*Rocket Sneaker*/ { 0, 0, 0, 0, 0, 1, 3, 5, 3, 0 }, // Rocket Sneaker
/*Invincibility*/ { 0, 0, 0, 0, 0, 1, 4, 6,14, 0 }, // Invincibility
/*Banana*/ { 0, 9, 4, 2, 1, 0, 0, 0, 0, 0 }, // Banana
/*Eggman Monitor*/ { 0, 4, 3, 2, 0, 0, 0, 0, 0, 0 }, // Eggman Monitor
/*Orbinaut*/ { 0, 6, 5, 3, 2, 0, 0, 0, 0, 0 }, // Orbinaut
/*Jawz*/ { 0, 0, 3, 2, 1, 1, 0, 0, 0, 0 }, // Jawz
/*Mine*/ { 0, 0, 2, 2, 1, 0, 0, 0, 0, 0 }, // Mine
/*Ballhog*/ { 0, 0, 0, 2, 1, 0, 0, 0, 0, 0 }, // Ballhog
/*Self-Propelled Bomb*/ { 0, 0, 1, 2, 3, 4, 2, 2, 0,20 }, // Self-Propelled Bomb
/*Grow*/ { 0, 0, 0, 0, 0, 1, 3, 5, 3, 0 }, // Grow
/*Shrink*/ { 0, 0, 0, 0, 0, 0, 0, 2, 0, 0 }, // Shrink
/*Thunder Shield*/ { 0, 1, 2, 0, 0, 0, 0, 0, 0, 0 }, // Thunder Shield
/*Hyudoro*/ { 0, 0, 0, 0, 1, 2, 1, 0, 0, 0 }, // Hyudoro
/*Pogo Spring*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // Pogo Spring
/*Kitchen Sink*/ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // Kitchen Sink
/*Sneaker x3*/ { 0, 0, 0, 0, 3, 7, 9, 2, 0, 0 }, // Sneaker x3
/*Banana x3*/ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 }, // Banana x3
/*Banana x10*/ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 }, // Banana x10
/*Orbinaut x3*/ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, // Orbinaut x3
/*Orbinaut x4*/ { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 }, // Orbinaut x4
/*Jawz x2*/ { 0, 0, 0, 1, 2, 0, 0, 0, 0, 0 } // Jawz x2
};
static INT32 K_KartItemOddsBattle[NUMKARTRESULTS][6] =
{
//P-Odds 0 1 2 3 4 5
/*Sneaker*/ { 3, 2, 2, 2, 0, 2 }, // Sneaker
/*Rocket Sneaker*/ { 0, 0, 0, 0, 0, 0 }, // Rocket Sneaker
/*Invincibility*/ { 0, 1, 2, 3, 4, 2 }, // Invincibility
/*Banana*/ { 2, 1, 0, 0, 0, 0 }, // Banana
/*Eggman Monitor*/ { 1, 1, 0, 0, 0, 0 }, // Eggman Monitor
/*Orbinaut*/ { 6, 2, 1, 0, 0, 0 }, // Orbinaut
/*Jawz*/ { 3, 3, 3, 2, 0, 2 }, // Jawz
/*Mine*/ { 2, 3, 3, 1, 0, 2 }, // Mine
/*Ballhog*/ { 0, 1, 2, 1, 0, 2 }, // Ballhog
/*Self-Propelled Bomb*/ { 0, 0, 0, 0, 0, 0 }, // Self-Propelled Bomb
/*Grow*/ { 0, 0, 1, 2, 4, 2 }, // Grow
/*Shrink*/ { 0, 0, 0, 0, 0, 0 }, // Shrink
/*Thunder Shield*/ { 0, 0, 0, 0, 0, 0 }, // Thunder Shield
/*Hyudoro*/ { 1, 1, 0, 0, 0, 0 }, // Hyudoro
/*Pogo Spring*/ { 1, 1, 0, 0, 0, 0 }, // Pogo Spring
/*Kitchen Sink*/ { 0, 0, 0, 0, 0, 0 }, // Kitchen Sink
/*Sneaker x3*/ { 0, 0, 0, 2, 4, 2 }, // Sneaker x3
/*Banana x3*/ { 1, 2, 1, 0, 0, 0 }, // Banana x3
/*Banana x10*/ { 0, 0, 1, 1, 0, 2 }, // Banana x10
/*Orbinaut x3*/ { 0, 1, 2, 1, 0, 0 }, // Orbinaut x3
/*Orbinaut x4*/ { 0, 0, 1, 3, 4, 2 }, // Orbinaut x4
/*Jawz x2*/ { 0, 0, 1, 2, 4, 2 } // Jawz x2
};
/** \brief Item Roulette for Kart
\param player player
\param getitem what item we're looking for
\return void
*/
static void K_KartGetItemResult(player_t *player, SINT8 getitem)
{
switch (getitem)
{
// Special roulettes first, then the generic ones are handled by default
case KRITEM_TRIPLESNEAKER: // Sneaker x3
player->kartstuff[k_itemtype] = KITEM_SNEAKER;
player->kartstuff[k_itemamount] = 3;
break;
case KRITEM_TRIPLEBANANA: // Banana x3
player->kartstuff[k_itemtype] = KITEM_BANANA;
player->kartstuff[k_itemamount] = 3;
break;
case KRITEM_TENFOLDBANANA: // Banana x10
player->kartstuff[k_itemtype] = KITEM_BANANA;
player->kartstuff[k_itemamount] = 10;
break;
case KRITEM_TRIPLEORBINAUT: // Orbinaut x3
player->kartstuff[k_itemtype] = KITEM_ORBINAUT;
player->kartstuff[k_itemamount] = 3;
break;
case KRITEM_QUADORBINAUT: // Orbinaut x4
player->kartstuff[k_itemtype] = KITEM_ORBINAUT;
player->kartstuff[k_itemamount] = 4;
break;
case KRITEM_DUALJAWZ: // Jawz x2
player->kartstuff[k_itemtype] = KITEM_JAWZ;
player->kartstuff[k_itemamount] = 2;
break;
case KITEM_SPB:
case KITEM_SHRINK: // Indirect items
indirectitemcooldown = 20*TICRATE;
/* FALLTHRU */
default:
if (getitem <= 0 || getitem >= NUMKARTRESULTS) // Sad (Fallback)
{
if (getitem != 0)
CONS_Printf("ERROR: P_KartGetItemResult - Item roulette gave bad item (%d) :(\n", getitem);
player->kartstuff[k_itemtype] = KITEM_SAD;
}
else
player->kartstuff[k_itemtype] = getitem;
player->kartstuff[k_itemamount] = 1;
break;
}
}
/** \brief Item Roulette for Kart
\param player player object passed from P_KartPlayerThink
\return void
*/
static INT32 K_KartGetItemOdds(UINT8 pos, SINT8 item, fixed_t mashed)
{
const INT32 distvar = (64*14);
INT32 newodds;
INT32 i;
UINT8 pingame = 0, pexiting = 0, pinvin = 0;
SINT8 first = -1, second = -1;
INT32 secondist = 0;
if (G_BattleGametype())
newodds = K_KartItemOddsBattle[item-1][pos];
else
newodds = K_KartItemOddsRace[item-1][pos];
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i] || players[i].spectator)
continue;
pingame++;
if (players[i].exiting)
pexiting++;
if (players[i].mo)
{
if (players[i].kartstuff[k_position] == 1 && first == -1)
first = i;
if (players[i].kartstuff[k_position] == 2 && second == -1)
second = i;
if (players[i].kartstuff[k_itemtype] == KITEM_INVINCIBILITY
|| players[i].kartstuff[k_itemtype] == KITEM_GROW
|| players[i].kartstuff[k_invincibilitytimer]
|| players[i].kartstuff[k_growshrinktimer] > 0)
pinvin++;
}
}
if (first != -1 && second != -1) // calculate 2nd's distance from 1st, for SPB
{
secondist = P_AproxDistance(P_AproxDistance(players[first].mo->x - players[second].mo->x,
players[first].mo->y - players[second].mo->y),
players[first].mo->z - players[second].mo->z) / mapobjectscale;
if (franticitems)
secondist = (15*secondist/14);
if (pingame < 8 && !G_BattleGametype())
secondist = ((28+(8-pingame))*secondist/28);
}
// POWERITEMODDS handles all of the "frantic item" related functionality, for all of our powerful items.
// First, it multiplies it by 2 if franticitems is true; easy-peasy.
// Next, it multiplies it again if it's in SPB mode and 2nd needs to apply pressure to 1st.
// Then, it multiplies it further if there's less than 8 players in game.
// This is done to make low player count races more fair & interesting. (1v1s are basically the same as franticitems false in a normal race)
// Lastly, it *divides* it by your mashed value, which was determined in K_KartItemRoulette, to punish those who are impatient.
// The last two are very fractional and complicated, very sorry!
#define POWERITEMODDS(odds) \
if (franticitems) \
odds *= 2; \
if (pingame < 8 && !G_BattleGametype()) \
odds = FixedMul(odds*FRACUNIT, FRACUNIT+min((8-pingame)*(FRACUNIT/25), FRACUNIT))/FRACUNIT; \
if (mashed > 0) \
odds = FixedDiv(odds*FRACUNIT, mashed+FRACUNIT)/FRACUNIT \
switch (item)
{
case KITEM_SNEAKER:
if ((!cv_sneaker.value) && (!modeattacking)) newodds = 0;
break;
case KITEM_ROCKETSNEAKER:
POWERITEMODDS(newodds);
if (!cv_rocketsneaker.value) newodds = 0;
break;
case KITEM_INVINCIBILITY:
POWERITEMODDS(newodds);
if ((!cv_invincibility.value) || (pinvin >= 2)) newodds = 0;
break;
case KITEM_BANANA:
if (!cv_banana.value) newodds = 0;
break;
case KITEM_EGGMAN:
if (!cv_eggmanmonitor.value) newodds = 0;
break;
case KITEM_ORBINAUT:
if (!cv_orbinaut.value) newodds = 0;
break;
case KITEM_JAWZ:
POWERITEMODDS(newodds);
if (!cv_jawz.value) newodds = 0;
break;
case KITEM_MINE:
POWERITEMODDS(newodds);
if (!cv_mine.value) newodds = 0;
break;
case KITEM_BALLHOG:
POWERITEMODDS(newodds);
if (!cv_ballhog.value) newodds = 0;
break;
case KITEM_SPB:
//POWERITEMODDS(newodds);
if (((!cv_selfpropelledbomb.value)
|| (indirectitemcooldown > 0)
|| (pexiting > 0)
|| (secondist/distvar < 3))
&& (pos != 9)) // Force SPB
newodds = 0;
newodds *= min((secondist/distvar)-4, 3);
break;
case KITEM_GROW:
POWERITEMODDS(newodds);
if ((!cv_grow.value) || (pinvin >= 2)) newodds = 0;
break;
case KITEM_SHRINK:
POWERITEMODDS(newodds);
if ((!cv_shrink.value)
|| (indirectitemcooldown > 0)
|| (pingame-1 <= pexiting)) newodds = 0;
break;
case KITEM_THUNDERSHIELD:
POWERITEMODDS(newodds);
if (!cv_thundershield.value) newodds = 0;
break;
case KITEM_HYUDORO:
if (!cv_hyudoro.value) newodds = 0;
break;
case KITEM_POGOSPRING:
if (!cv_pogospring.value) newodds = 0;
break;
case KITEM_KITCHENSINK:
newodds = 0; // Not obtained via normal means.
break;
case KRITEM_TRIPLESNEAKER:
POWERITEMODDS(newodds);
if (!cv_triplesneaker.value) newodds = 0;
break;
case KRITEM_TRIPLEBANANA:
POWERITEMODDS(newodds);
if (!cv_triplebanana.value) newodds = 0;
break;
case KRITEM_TENFOLDBANANA:
POWERITEMODDS(newodds);
if (!cv_decabanana.value) newodds = 0;
break;
case KRITEM_TRIPLEORBINAUT:
POWERITEMODDS(newodds);
if (!cv_tripleorbinaut.value) newodds = 0;
break;
case KRITEM_QUADORBINAUT:
POWERITEMODDS(newodds);
if (!cv_quadorbinaut.value) newodds = 0;
break;
case KRITEM_DUALJAWZ:
POWERITEMODDS(newodds);
if (!cv_dualjawz.value) newodds = 0;
break;
default:
break;
}
#undef POWERITEMODDS
return newodds;
}
//{ SRB2kart Roulette Code - Distance Based, no waypoints
static INT32 K_FindUseodds(player_t *player, fixed_t mashed, INT32 pingame, INT32 bestbumper, boolean spbrush, boolean dontforcespb)
{
const INT32 distvar = (64*14);
INT32 i;
INT32 pdis = 0, useodds = 0;
UINT8 disttable[14];
UINT8 distlen = 0;
boolean oddsvalid[10];
for (i = 0; i < 10; i++)
{
INT32 j;
boolean available = false;
if (G_BattleGametype() && i > 5)
{
oddsvalid[i] = false;
break;
}
for (j = 0; j < NUMKARTRESULTS; j++)
{
if (K_KartGetItemOdds(i, j, mashed) > 0)
{
available = true;
break;
}
}
oddsvalid[i] = available;
}
for (i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i] && !players[i].spectator && players[i].mo
&& players[i].kartstuff[k_position] < player->kartstuff[k_position])
pdis += P_AproxDistance(P_AproxDistance(players[i].mo->x - player->mo->x,
players[i].mo->y - player->mo->y),
players[i].mo->z - player->mo->z) / mapobjectscale
* (pingame - players[i].kartstuff[k_position])
/ max(1, ((pingame - 1) * (pingame + 1) / 3));
}
#define SETUPDISTTABLE(odds, num) \
for (i = num; i; --i) disttable[distlen++] = odds
if (G_BattleGametype()) // Battle Mode
{
if (oddsvalid[0]) SETUPDISTTABLE(0,1);
if (oddsvalid[1]) SETUPDISTTABLE(1,1);
if (oddsvalid[2]) SETUPDISTTABLE(2,1);
if (oddsvalid[3]) SETUPDISTTABLE(3,1);
if (oddsvalid[4]) SETUPDISTTABLE(4,1);
if (player->kartstuff[k_roulettetype] == 1 && oddsvalid[5]) // 5 is the extreme odds of player-controlled "Karma" items
useodds = 5;
else
{
SINT8 wantedpos = (bestbumper-player->kartstuff[k_bumper]); // 0 is the best player's bumper count, 1 is a bumper below best, 2 is two bumpers below, etc
if (K_IsPlayerWanted(player))
wantedpos++;
if (wantedpos > 4) // Don't run off into karma items
wantedpos = 4;
if (wantedpos < 0) // Don't go below somehow
wantedpos = 0;
useodds = disttable[(wantedpos * distlen) / 5];
}
}
else
{
if (oddsvalid[1]) SETUPDISTTABLE(1,1);
if (oddsvalid[2]) SETUPDISTTABLE(2,1);
if (oddsvalid[3]) SETUPDISTTABLE(3,1);
if (oddsvalid[4]) SETUPDISTTABLE(4,2);
if (oddsvalid[5]) SETUPDISTTABLE(5,2);
if (oddsvalid[6]) SETUPDISTTABLE(6,3);
if (oddsvalid[7]) SETUPDISTTABLE(7,3);
if (oddsvalid[8]) SETUPDISTTABLE(8,1);
if (franticitems) // Frantic items make the distances between everyone artifically higher, for crazier items
pdis = (15*pdis)/14;
if (spbrush) // SPB Rush Mode: It's 2nd place's job to catch-up items and make 1st place's job hell
pdis = (3*pdis)/2;
if (pingame < 8)
pdis = ((28+(8-pingame))*pdis)/28;
if (pingame == 1 && oddsvalid[0]) // Record Attack, or just alone
useodds = 0;
else if (pdis <= 0) // (64*14) * 0 = 0
useodds = disttable[0];
else if (player->kartstuff[k_position] == 2 && pdis > (distvar*6)
&& spbplace == -1 && !indirectitemcooldown && !dontforcespb
&& oddsvalid[9]) // Force SPB in 2nd
useodds = 9;
else if (pdis > distvar * ((12 * distlen) / 14)) // (64*14) * 12 = 10752
useodds = disttable[distlen-1];
else
{
for (i = 1; i < 13; i++)
{
if (pdis <= distvar * ((i * distlen) / 14))
{
useodds = disttable[((i * distlen) / 14)];
break;
}
}
}
}
#undef SETUPDISTTABLE
//CONS_Printf("Got useodds %d. (position: %d, distance: %d)\n", useodds, player->kartstuff[k_position], pdis);
return useodds;
}
static void K_KartItemRoulette(player_t *player, ticcmd_t *cmd)
{
INT32 i;
UINT8 pingame = 0;
UINT8 roulettestop;
INT32 useodds = 0;
INT32 spawnchance[NUMKARTRESULTS * NUMKARTODDS];
INT32 chance = 0, numchoices = 0;
INT32 bestbumper = 0;
fixed_t mashed = 0;
boolean dontforcespb = false;
// This makes the roulette cycle through items - if this is 0, you shouldn't be here.
if (player->kartstuff[k_itemroulette])
player->kartstuff[k_itemroulette]++;
else
return;
// Gotta check how many players are active at this moment.
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i] || players[i].spectator)
continue;
pingame++;
if (players[i].exiting)
dontforcespb = true;
if (players[i].kartstuff[k_bumper] > bestbumper)
bestbumper = players[i].kartstuff[k_bumper];
}
// This makes the roulette produce the random noises.
if ((player->kartstuff[k_itemroulette] % 3) == 1 && P_IsLocalPlayer(player))
{
#define PLAYROULETTESND S_StartSound(NULL, sfx_itrol1 + ((player->kartstuff[k_itemroulette] / 3) % 8));
if (splitscreen)
{
if (players[displayplayer].kartstuff[k_itemroulette])
{
if (player == &players[displayplayer])
PLAYROULETTESND;
}
else if (players[secondarydisplayplayer].kartstuff[k_itemroulette])
{
if (player == &players[secondarydisplayplayer])
PLAYROULETTESND;
}
else if (players[thirddisplayplayer].kartstuff[k_itemroulette] && splitscreen > 1)
{
if (player == &players[thirddisplayplayer])
PLAYROULETTESND;
}
else if (players[fourthdisplayplayer].kartstuff[k_itemroulette] && splitscreen > 2)
{
if (player == &players[fourthdisplayplayer])
PLAYROULETTESND;
}
}
else
PLAYROULETTESND;
#undef PLAYROULETTESND
}
roulettestop = TICRATE + (3*(pingame - player->kartstuff[k_position]));
// If the roulette finishes or the player presses BT_ATTACK, stop the roulette and calculate the item.
// I'm returning via the exact opposite, however, to forgo having another bracket embed. Same result either way, I think.
// Finally, if you get past this check, now you can actually start calculating what item you get.
if ((cmd->buttons & BT_ATTACK) && !(player->kartstuff[k_eggmanheld] || player->kartstuff[k_itemheld]) && player->kartstuff[k_itemroulette] >= roulettestop && !modeattacking)
{
// Mashing reduces your chances for the good items
mashed = FixedDiv((player->kartstuff[k_itemroulette])*FRACUNIT, ((TICRATE*3)+roulettestop)*FRACUNIT) - FRACUNIT;
}
else if (!(player->kartstuff[k_itemroulette] >= (TICRATE*3)))
return;
if (cmd->buttons & BT_ATTACK)
player->pflags |= PF_ATTACKDOWN;
if (player->kartstuff[k_roulettetype] == 2) // Fake items
{
player->kartstuff[k_eggmanexplode] = 4*TICRATE;
//player->kartstuff[k_itemblink] = TICRATE;
//player->kartstuff[k_itemblinkmode] = 1;
player->kartstuff[k_itemroulette] = 0;
player->kartstuff[k_roulettetype] = 0;
if (P_IsLocalPlayer(player))
S_StartSound(NULL, sfx_itrole);
return;
}
if (cv_kartdebugitem.value != 0 && !modeattacking)
{
K_KartGetItemResult(player, cv_kartdebugitem.value);
player->kartstuff[k_itemamount] = cv_kartdebugamount.value;
player->kartstuff[k_itemblink] = TICRATE;
player->kartstuff[k_itemblinkmode] = 2;
player->kartstuff[k_itemroulette] = 0;
player->kartstuff[k_roulettetype] = 0;
if (P_IsLocalPlayer(player))
S_StartSound(NULL, sfx_dbgsal);
return;
}
// Initializes existing spawnchance values
for (i = 0; i < (NUMKARTRESULTS * NUMKARTODDS); i++)
spawnchance[i] = 0;
// Split into another function for a debug function below
useodds = K_FindUseodds(player, mashed, pingame, bestbumper, (spbplace != -1 && player->kartstuff[k_position] == spbplace+1), dontforcespb);
#define SETITEMRESULT(itemnum) \