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
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
|
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
Copyright (C) 2000-2006 Tim Angus
This file is part of Tremulous.
Tremulous is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Tremulous is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Tremulous; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
#include "g_local.h"
#define QVM_NAME "cQVM"
#define MAJ_VERSION "5.5"
#ifdef SVN_ID
#define QVM_VERSIONNUM MAJ_VERSION " svn" SVN_ID
#else
#define QVM_VERSIONNUM MAJ_VERSION
#endif
level_locals_t level;
typedef struct
{
vmCvar_t *vmCvar;
char *cvarName;
char *defaultString;
int cvarFlags;
int modificationCount; // for tracking changes
qboolean trackChange; // track this variable, and announce if changed
qboolean teamShader; // track and if changed, update shader state
} cvarTable_t;
gentity_t g_entities[ MAX_GENTITIES ];
gclient_t g_clients[ MAX_CLIENTS ];
vmCvar_t g_fraglimit;
vmCvar_t g_timelimit;
vmCvar_t g_suddenDeathTime;
vmCvar_t g_suddenDeath;
vmCvar_t g_suddenDeathMode;
vmCvar_t g_vampireDeathTime;
vmCvar_t g_vampireDeath;
vmCvar_t g_vampireDeathInfo;
vmCvar_t g_capturelimit;
vmCvar_t g_friendlyFire;
vmCvar_t g_friendlyFireAliens;
vmCvar_t g_friendlyFireHumans;
vmCvar_t g_friendlyFireMovementAttacks;
vmCvar_t g_retribution;
vmCvar_t g_friendlyBuildableFire;
vmCvar_t g_password;
vmCvar_t g_needpass;
vmCvar_t g_maxclients;
vmCvar_t g_maxGameClients;
vmCvar_t g_dedicated;
vmCvar_t g_speed;
vmCvar_t g_gravity;
vmCvar_t g_cheats;
vmCvar_t g_knockback;
vmCvar_t g_quadfactor;
vmCvar_t g_inactivity;
vmCvar_t g_inactivityMode;
vmCvar_t g_debugMove;
vmCvar_t g_debugDamage;
vmCvar_t g_debugAlloc;
vmCvar_t g_weaponRespawn;
vmCvar_t g_weaponTeamRespawn;
vmCvar_t g_motd;
vmCvar_t g_synchronousClients;
vmCvar_t g_warmup;
vmCvar_t g_warmupMode;
vmCvar_t g_doWarmup;
vmCvar_t g_restarted;
vmCvar_t g_lockTeamsAtStart;
vmCvar_t g_logFile;
vmCvar_t g_logFileSync;
vmCvar_t g_blood;
vmCvar_t g_podiumDist;
vmCvar_t g_podiumDrop;
vmCvar_t g_allowVote;
vmCvar_t g_requireVoteReasons;
vmCvar_t g_voteLimit;
vmCvar_t g_pollVotes;
vmCvar_t g_suddenDeathVotePercent;
vmCvar_t g_suddenDeathVoteDelay;
vmCvar_t g_extendVotesPercent;
vmCvar_t g_extendVotesTime;
vmCvar_t g_extendVotesCount;
vmCvar_t g_kickVotesPercent;
vmCvar_t g_customVote1;
vmCvar_t g_customVote2;
vmCvar_t g_customVote3;
vmCvar_t g_customVote4;
vmCvar_t g_customVote5;
vmCvar_t g_customVote6;
vmCvar_t g_customVote7;
vmCvar_t g_customVote8;
vmCvar_t g_customVotePercent;
vmCvar_t g_mapVotesPercent;
vmCvar_t g_mapRotationVote;
vmCvar_t g_readyPercent;
vmCvar_t g_designateVotes;
vmCvar_t g_teamAutoJoin;
vmCvar_t g_teamForceBalance;
vmCvar_t g_popularMaps;
vmCvar_t g_popularMapsVotePercent;
vmCvar_t g_banIPs;
vmCvar_t g_filterBan;
vmCvar_t g_smoothClients;
vmCvar_t g_outdatedClientMessage;
vmCvar_t pmove_fixed;
vmCvar_t pmove_msec;
vmCvar_t g_rankings;
vmCvar_t g_listEntity;
vmCvar_t g_minCommandPeriod;
vmCvar_t g_minNameChangePeriod;
vmCvar_t g_maxNameChanges;
vmCvar_t g_newbieNumbering;
vmCvar_t g_newbieNamePrefix;
vmCvar_t g_newbieNoBuild;
vmCvar_t g_newbieNoBuildMessage;
vmCvar_t g_humanBuildPoints;
vmCvar_t g_alienBuildPoints;
vmCvar_t g_humanStage;
vmCvar_t g_humanKills;
vmCvar_t g_humanMaxStage;
vmCvar_t g_humanStage2Threshold;
vmCvar_t g_humanStage3Threshold;
vmCvar_t g_alienStage;
vmCvar_t g_alienKills;
vmCvar_t g_alienMaxStage;
vmCvar_t g_alienStage2Threshold;
vmCvar_t g_alienStage3Threshold;
vmCvar_t g_teamImbalanceWarnings;
vmCvar_t g_unlagged;
vmCvar_t g_disabledEquipment;
vmCvar_t g_disabledClasses;
vmCvar_t g_disabledBuildables;
vmCvar_t g_buildPointsRecoverRate;
vmCvar_t g_dynamicBuildPoints;
vmCvar_t g_instantBuild;
vmCvar_t g_gradualFreeFunds;
vmCvar_t g_markDeconstruct;
vmCvar_t g_markDeconstructMode;
vmCvar_t g_deconDead;
vmCvar_t g_debugMapRotation;
vmCvar_t g_currentMapRotation;
vmCvar_t g_currentMap;
vmCvar_t g_nextMap;
vmCvar_t g_idleMapSwitch;
vmCvar_t g_initialMapRotation;
vmCvar_t g_shove;
vmCvar_t g_mapConfigs;
vmCvar_t g_chatTeamPrefix;
vmCvar_t g_sayAreaRange;
vmCvar_t g_actionPrefix;
vmCvar_t g_floodMaxDemerits;
vmCvar_t g_floodMinTime;
vmCvar_t g_layouts;
vmCvar_t g_layoutAuto;
vmCvar_t g_admin;
vmCvar_t g_report;
vmCvar_t g_adminLog;
vmCvar_t g_adminParseSay;
vmCvar_t g_adminSayFilter;
vmCvar_t g_adminNameProtect;
vmCvar_t g_adminTempMute;
vmCvar_t g_adminTempBan;
vmCvar_t g_adminBanRepeatKicks;
vmCvar_t g_adminMaxBan;
vmCvar_t g_adminTempSpec;
vmCvar_t g_adminMapLog;
vmCvar_t g_adminRegisterLevel;
vmCvar_t g_adminRegisterAdminPass;
vmCvar_t g_adminRegisterAdminLevel;
vmCvar_t g_minLevelToJoinTeam;
vmCvar_t g_forceAutoSelect;
vmCvar_t g_privateMessages;
vmCvar_t g_logPrivateMessages;
vmCvar_t g_decolourLogfiles;
vmCvar_t g_minLevelToSpecMM1;
vmCvar_t g_publicSayadmins;
vmCvar_t g_myStats;
vmCvar_t g_teamStatus;
vmCvar_t g_antiSpawnBlock;
vmCvar_t g_killingSpree;
vmCvar_t g_feedingSpree;
vmCvar_t g_bleedingSpree;
vmCvar_t g_bleedingSpreeKick;
vmCvar_t g_autoRevert;
vmCvar_t g_banNotice;
vmCvar_t g_karma;
vmCvar_t g_chat;
vmCvar_t g_adminExpireTime;
vmCvar_t g_devmapKillerHP;
vmCvar_t g_killerHP;
vmCvar_t g_nullifyTyrantKills;
vmCvar_t g_buildLogMaxLength;
vmCvar_t g_maxGhosts;
vmCvar_t g_tag;
vmCvar_t g_dretchPunt;
vmCvar_t g_allowShare;
vmCvar_t g_creditOverflow;
vmCvar_t g_devmapNoGod;
vmCvar_t g_devmapNoStructDmg;
vmCvar_t g_slapKnockback;
vmCvar_t g_slapDamage;
vmCvar_t g_voteMinTime;
vmCvar_t g_mapvoteMaxTime;
vmCvar_t g_votableMaps;
vmCvar_t g_defeatVoteMinTime;
vmCvar_t g_practiceText;
vmCvar_t g_practiceCount;
vmCvar_t g_freeCredits;
vmCvar_t g_msg;
vmCvar_t g_msgTime;
vmCvar_t g_welcomeMsg;
vmCvar_t g_welcomeMsgTime;
vmCvar_t g_turretAim;
vmCvar_t g_modBuildableHealth;
vmCvar_t g_modBuildableSpeed;
vmCvar_t g_modBuildableCount;
vmCvar_t g_modHumanStamina;
vmCvar_t g_modHumanHealth;
vmCvar_t g_modAlienHealth;
vmCvar_t g_modAlienRegenRange;
vmCvar_t g_modHumanRate;
vmCvar_t g_modAlienRate;
vmCvar_t g_modWeaponAmmo;
vmCvar_t g_modWeaponReload;
vmCvar_t g_modTurretAngle;
vmCvar_t g_modStage3Strength;
vmCvar_t g_modMainStrength;
vmCvar_t mod_jetpackFuel;
vmCvar_t mod_jetpackConsume;
vmCvar_t mod_jetpackRegen;
vmCvar_t g_maxReports;
vmCvar_t g_maxUnregReports;
vmCvar_t g_reportWelcomeComment;
vmCvar_t g_reportAdminListMinLvl;
vmCvar_t g_schachtmeisterClearThreshold;
vmCvar_t g_schachtmeisterAutobahnThreshold;
vmCvar_t g_schachtmeisterAutobahnMessage;
vmCvar_t g_scrimMode;
vmCvar_t g_revertCooldownTime;
static cvarTable_t gameCvarTable[ ] =
{
// don't override the cheat state set by the system
{ &g_cheats, "sv_cheats", "", 0, 0, qfalse },
// noset vars
{ NULL, "gamename", GAME_VERSION , CVAR_SERVERINFO | CVAR_ROM, 0, qfalse },
{ &g_restarted, "g_restarted", "0", CVAR_ROM, 0, qfalse },
{ &g_lockTeamsAtStart, "g_lockTeamsAtStart", "0", CVAR_ROM, 0, qfalse },
{ NULL, "sv_mapname", "", CVAR_SERVERINFO | CVAR_ROM, 0, qfalse },
{ NULL, "P", "", CVAR_SERVERINFO | CVAR_ROM, 0, qfalse },
{ NULL, "ff", "0", CVAR_SERVERINFO | CVAR_ROM, 0, qfalse },
// latched vars
{ &g_maxclients, "sv_maxclients", "8", CVAR_SERVERINFO | CVAR_LATCH | CVAR_ARCHIVE, 0, qfalse },
{ &g_maxGameClients, "g_maxGameClients", "0", CVAR_SERVERINFO | CVAR_ARCHIVE | CVAR_NORESTART, 0, qtrue },
// change anytime vars
{ &g_timelimit, "timelimit", "45", CVAR_SERVERINFO | CVAR_ARCHIVE | CVAR_NORESTART, 0, qtrue },
{ &g_suddenDeathTime, "g_suddenDeathTime", "30", CVAR_SERVERINFO | CVAR_ARCHIVE | CVAR_NORESTART, 0, qtrue },
{ &g_suddenDeathMode, "g_suddenDeathMode", "0", CVAR_SERVERINFO | CVAR_ARCHIVE | CVAR_NORESTART, 0, qtrue },
{ &g_suddenDeath, "g_suddenDeath", "0", CVAR_SERVERINFO | CVAR_NORESTART, 0, qtrue },
{ &g_vampireDeathTime, "g_vampireDeathTime", "0", CVAR_ARCHIVE | CVAR_NORESTART, 0, qtrue },
{ &g_vampireDeath, "g_vampireDeath", "0", CVAR_NORESTART, 0, qtrue },
{ &g_vampireDeathInfo, "g_vampireDeathInfo", "( !info vampire )", CVAR_ARCHIVE, 0, qtrue },
{ &g_synchronousClients, "g_synchronousClients", "0", CVAR_SYSTEMINFO, 0, qfalse },
{ &g_friendlyFire, "g_friendlyFire", "0", CVAR_ARCHIVE | CVAR_SERVERINFO, 0, qtrue },
{ &g_friendlyFireAliens, "g_friendlyFireAliens", "0", CVAR_ARCHIVE, 0, qtrue },
{ &g_friendlyFireHumans, "g_friendlyFireHumans", "0", CVAR_ARCHIVE, 0, qtrue },
{ &g_retribution, "g_retribution", "0", CVAR_ARCHIVE, 0, qtrue },
{ &g_friendlyBuildableFire, "g_friendlyBuildableFire", "0", CVAR_ARCHIVE | CVAR_SERVERINFO, 0, qtrue },
{ &g_friendlyFireMovementAttacks, "g_friendlyFireMovementAttacks", "1", CVAR_ARCHIVE, 0, qtrue },
{ &g_devmapNoGod, "g_devmapNoGod", "0", CVAR_ARCHIVE, 0, qtrue },
{ &g_devmapNoStructDmg, "g_devmapNoStructDmg", "0", CVAR_ARCHIVE, 0, qtrue },
{ &g_slapKnockback, "g_slapKnockback", "200", CVAR_ARCHIVE, 0, qfalse},
{ &g_slapDamage, "g_slapDamage", "5", CVAR_ARCHIVE, 0, qfalse},
{ &g_teamAutoJoin, "g_teamAutoJoin", "0", CVAR_ARCHIVE },
{ &g_teamForceBalance, "g_teamForceBalance", "1", CVAR_ARCHIVE },
{ &g_popularMaps, "g_popularMaps", "arachnid2 atcs karith nexus6 niveus transit tremor", CVAR_ARCHIVE },
{ &g_popularMapsVotePercent, "g_popularMapsVotePercent", "0", CVAR_ARCHIVE },
{ &g_warmup, "g_warmup", "10", CVAR_ARCHIVE, 0, qtrue },
{ &g_warmupMode, "g_warmupMode", "1", CVAR_ARCHIVE, 0, qtrue },
{ &g_doWarmup, "g_doWarmup", "1", CVAR_ARCHIVE, 0, qtrue },
{ &g_logFile, "g_logFile", "games.log", CVAR_ARCHIVE, 0, qfalse },
{ &g_logFileSync, "g_logFileSync", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_password, "g_password", "", CVAR_USERINFO, 0, qfalse },
{ &g_banIPs, "g_banIPs", "", CVAR_ARCHIVE, 0, qfalse },
{ &g_filterBan, "g_filterBan", "1", CVAR_ARCHIVE, 0, qfalse },
{ &g_needpass, "g_needpass", "0", CVAR_SERVERINFO | CVAR_ROM, 0, qfalse },
{ &g_dedicated, "dedicated", "0", 0, 0, qfalse },
{ &g_speed, "g_speed", "320", CVAR_SERVERINFO, 0, qtrue },
{ &g_gravity, "g_gravity", "800", CVAR_SERVERINFO, 0, qtrue },
{ &g_knockback, "g_knockback", "1000", CVAR_SERVERINFO, 0, qtrue },
{ &g_quadfactor, "g_quadfactor", "3", 0, 0, qtrue },
{ &g_weaponRespawn, "g_weaponrespawn", "5", 0, 0, qtrue },
{ &g_weaponTeamRespawn, "g_weaponTeamRespawn", "30", 0, 0, qtrue },
{ &g_inactivity, "g_inactivity", "0", 0, 0, qtrue },
{ &g_inactivityMode, "g_inactivityMode", "0", 0, 0, qfalse },
{ &g_debugMove, "g_debugMove", "0", 0, 0, qfalse },
{ &g_debugDamage, "g_debugDamage", "0", 0, 0, qfalse },
{ &g_debugAlloc, "g_debugAlloc", "0", 0, 0, qfalse },
{ &g_motd, "g_motd", "", 0, 0, qfalse },
{ &g_blood, "com_blood", "1", 0, 0, qfalse },
{ &g_podiumDist, "g_podiumDist", "80", 0, 0, qfalse },
{ &g_podiumDrop, "g_podiumDrop", "70", 0, 0, qfalse },
{ &g_allowVote, "g_allowVote", "1", CVAR_ARCHIVE, 0, qfalse },
{ &g_requireVoteReasons, "g_requireVoteReasons", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_pollVotes, "g_pollVotes", "1", CVAR_ARCHIVE, 0, qfalse },
{ &g_voteLimit, "g_voteLimit", "5", CVAR_ARCHIVE, 0, qfalse },
{ &g_voteMinTime, "g_voteMinTime", "120", CVAR_ARCHIVE, 0, qfalse },
{ &g_mapvoteMaxTime, "g_mapvoteMaxTime", "240", CVAR_ARCHIVE, 0, qfalse },
{ &g_votableMaps, "g_votableMaps", "", CVAR_ARCHIVE, 0, qtrue },
{ &g_defeatVoteMinTime, "g_defeatVoteMinTime", "60", CVAR_ARCHIVE, 0, qfalse },
{ &g_suddenDeathVotePercent, "g_suddenDeathVotePercent", "74", CVAR_ARCHIVE, 0, qfalse },
{ &g_suddenDeathVoteDelay, "g_suddenDeathVoteDelay", "180", CVAR_ARCHIVE, 0, qfalse },
{ &g_extendVotesPercent, "g_extendVotesPercent", "74", CVAR_ARCHIVE, 0, qfalse },
{ &g_extendVotesTime, "g_extendVotesTime", "10", CVAR_ARCHIVE, 0, qfalse },
{ &g_extendVotesCount, "g_extendVotesCount", "2", CVAR_ARCHIVE, 0, qfalse },
{ &g_kickVotesPercent, "g_kickVotesPercent", "50", CVAR_ARCHIVE, 0, qtrue },
{ &g_customVote1, "g_customVote1", "", CVAR_ARCHIVE, 0, qfalse },
{ &g_customVote2, "g_customVote2", "", CVAR_ARCHIVE, 0, qfalse },
{ &g_customVote3, "g_customVote3", "", CVAR_ARCHIVE, 0, qfalse },
{ &g_customVote4, "g_customVote4", "", CVAR_ARCHIVE, 0, qfalse },
{ &g_customVote5, "g_customVote5", "", CVAR_ARCHIVE, 0, qfalse },
{ &g_customVote6, "g_customVote6", "", CVAR_ARCHIVE, 0, qfalse },
{ &g_customVote7, "g_customVote7", "", CVAR_ARCHIVE, 0, qfalse },
{ &g_customVote8, "g_customVote8", "", CVAR_ARCHIVE, 0, qfalse },
{ &g_customVotePercent, "g_customVotePercent", "50", CVAR_ARCHIVE, 0, qfalse },
{ &g_mapVotesPercent, "g_mapVotesPercent", "50", CVAR_ARCHIVE, 0, qfalse },
{ &g_mapRotationVote, "g_mapRotationVote", "15", CVAR_ARCHIVE, 0, qfalse },
{ &g_readyPercent, "g_readyPercent", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_designateVotes, "g_designateVotes", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_practiceText, "g_practiceText", "", 0, 0, qfalse},
{ &g_practiceCount, "g_practiceCount", "0", 0, 0, qfalse},
{ &g_freeCredits, "g_freeCredits", "0", CVAR_ARCHIVE, 0, qtrue },
{ &g_listEntity, "g_listEntity", "0", 0, 0, qfalse },
{ &g_minCommandPeriod, "g_minCommandPeriod", "500", 0, 0, qfalse},
{ &g_minNameChangePeriod, "g_minNameChangePeriod", "5", 0, 0, qfalse},
{ &g_maxNameChanges, "g_maxNameChanges", "5", 0, 0, qfalse},
{ &g_newbieNumbering, "g_newbieNumbering", "0", CVAR_ARCHIVE, 0, qfalse},
{ &g_newbieNamePrefix, "g_newbieNamePrefix", "Newbie#", CVAR_ARCHIVE, 0, qfalse},
{ &g_newbieNoBuild, "g_newbieNoBuild", "0", CVAR_ARCHIVE, 0, qfalse},
{ &g_newbieNoBuildMessage, "g_newbieNoBuildMessage",
"Set a name by pressing Escape and choosing Options", CVAR_ARCHIVE, 0, qfalse},
{ &g_smoothClients, "g_smoothClients", "1", 0, 0, qfalse},
{ &g_outdatedClientMessage, "g_outdatedClientMessage", "", CVAR_ARCHIVE, 0, qfalse},
{ &pmove_fixed, "pmove_fixed", "0", CVAR_SYSTEMINFO, 0, qfalse},
{ &pmove_msec, "pmove_msec", "8", CVAR_SYSTEMINFO, 0, qfalse},
{ &g_humanBuildPoints, "g_humanBuildPoints", DEFAULT_HUMAN_BUILDPOINTS, CVAR_SERVERINFO, 0, qfalse },
{ &g_alienBuildPoints, "g_alienBuildPoints", DEFAULT_ALIEN_BUILDPOINTS, CVAR_SERVERINFO, 0, qfalse },
{ &g_humanStage, "g_humanStage", "0", 0, 0, qfalse },
{ &g_humanKills, "g_humanKills", "0", 0, 0, qfalse },
{ &g_humanMaxStage, "g_humanMaxStage", DEFAULT_HUMAN_MAX_STAGE, 0, 0, qfalse },
{ &g_humanStage2Threshold, "g_humanStage2Threshold", DEFAULT_HUMAN_STAGE2_THRESH, 0, 0, qfalse },
{ &g_humanStage3Threshold, "g_humanStage3Threshold", DEFAULT_HUMAN_STAGE3_THRESH, 0, 0, qfalse },
{ &g_alienStage, "g_alienStage", "0", 0, 0, qfalse },
{ &g_alienKills, "g_alienKills", "0", 0, 0, qfalse },
{ &g_alienMaxStage, "g_alienMaxStage", DEFAULT_ALIEN_MAX_STAGE, 0, 0, qfalse },
{ &g_alienStage2Threshold, "g_alienStage2Threshold", DEFAULT_ALIEN_STAGE2_THRESH, 0, 0, qfalse },
{ &g_alienStage3Threshold, "g_alienStage3Threshold", DEFAULT_ALIEN_STAGE3_THRESH, 0, 0, qfalse },
{ &g_teamImbalanceWarnings, "g_teamImbalanceWarnings", "30", CVAR_ARCHIVE, 0, qfalse },
{ &g_unlagged, "g_unlagged", "1", CVAR_SERVERINFO | CVAR_ARCHIVE, 0, qfalse },
{ &g_disabledEquipment, "g_disabledEquipment", "", CVAR_ROM, 0, qfalse },
{ &g_disabledClasses, "g_disabledClasses", "", CVAR_ROM, 0, qfalse },
{ &g_disabledBuildables, "g_disabledBuildables", "", CVAR_ROM, 0, qfalse },
{ &g_buildPointsRecoverRate, "g_buildPointsRecoverRate", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_dynamicBuildPoints, "g_dynamicBuildPoints", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_instantBuild, "g_instantBuild", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_gradualFreeFunds, "g_gradualFreeFunds", "2", CVAR_ARCHIVE, 0, qtrue },
{ &g_chatTeamPrefix, "g_chatTeamPrefix", "1", CVAR_ARCHIVE },
{ &g_sayAreaRange, "g_sayAreaRange", "1000", CVAR_ARCHIVE, 0, qtrue },
{ &g_actionPrefix, "g_actionPrefix", "* ", CVAR_ARCHIVE, 0, qfalse },
{ &g_floodMaxDemerits, "g_floodMaxDemerits", "5000", CVAR_ARCHIVE, 0, qfalse },
{ &g_floodMinTime, "g_floodMinTime", "2000", CVAR_ARCHIVE, 0, qfalse },
{ &g_markDeconstruct, "g_markDeconstruct", "0", CVAR_ARCHIVE, 0, qtrue },
{ &g_markDeconstructMode, "g_markDeconstructMode", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_deconDead, "g_deconDead", "0", CVAR_ARCHIVE, 0, qtrue },
{ &g_debugMapRotation, "g_debugMapRotation", "0", 0, 0, qfalse },
{ &g_currentMapRotation, "g_currentMapRotation", "-1", 0, 0, qfalse }, // -1 = NOT_ROTATING
{ &g_currentMap, "g_currentMap", "0", 0, 0, qfalse },
{ &g_nextMap, "g_nextMap", "", 0 , 0, qtrue },
{ &g_idleMapSwitch, "g_idleMapSwitch", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_initialMapRotation, "g_initialMapRotation", "", CVAR_ARCHIVE, 0, qfalse },
{ &g_shove, "g_shove", "15", CVAR_ARCHIVE, 0, qfalse },
{ &g_mapConfigs, "g_mapConfigs", "", CVAR_ARCHIVE, 0, qfalse },
{ NULL, "g_mapConfigsLoaded", "0", CVAR_ROM, 0, qfalse },
{ &g_layouts, "g_layouts", "", CVAR_LATCH, 0, qfalse },
{ &g_layoutAuto, "g_layoutAuto", "1", CVAR_ARCHIVE, 0, qfalse },
{ &g_admin, "g_admin", "admin.dat", CVAR_ARCHIVE, 0, qfalse },
{ &g_report, "g_report", "report.dat", CVAR_ARCHIVE, 0, qfalse },
{ &g_adminLog, "g_adminLog", "admin.log", CVAR_ARCHIVE, 0, qfalse },
{ &g_adminParseSay, "g_adminParseSay", "1", CVAR_ARCHIVE, 0, qfalse },
{ &g_adminSayFilter, "g_adminSayFilter", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_adminNameProtect, "g_adminNameProtect", "1", CVAR_ARCHIVE, 0, qfalse },
{ &g_adminTempMute, "g_adminTempMute", "5m", CVAR_ARCHIVE, 0, qfalse },
{ &g_adminTempBan, "g_adminTempBan", "2m", CVAR_ARCHIVE, 0, qfalse },
{ &g_adminBanRepeatKicks, "g_adminBanRepeatKicks", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_adminMaxBan, "g_adminMaxBan", "2w", CVAR_ARCHIVE, 0, qfalse },
{ &g_adminTempSpec, "g_adminTempSpec", "2m", CVAR_ARCHIVE, 0, qfalse },
{ &g_adminMapLog, "g_adminMapLog", "", CVAR_ROM, 0, qfalse },
{ &g_adminRegisterLevel, "g_adminRegisterLevel", "1", CVAR_ARCHIVE, 0, qfalse },
{ &g_adminRegisterAdminPass, "g_adminRegisterAdminPass", "", CVAR_ARCHIVE, 0, qfalse },
{ &g_adminRegisterAdminLevel, "g_adminRegisterAdminLevel", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_minLevelToJoinTeam, "g_minLevelToJoinTeam", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_forceAutoSelect, "g_forceAutoSelect", "0", CVAR_ARCHIVE, 0, qtrue },
{ &g_maxGhosts, "g_maxGhosts", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_privateMessages, "g_privateMessages", "1", CVAR_ARCHIVE, 0, qfalse },
{ &g_logPrivateMessages, "g_logPrivateMessages", "1", CVAR_ARCHIVE, 0, qfalse },
{ &g_decolourLogfiles, "g_decolourLogfiles", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_buildLogMaxLength, "g_buildLogMaxLength", "50", CVAR_ARCHIVE, 0, qfalse },
{ &g_myStats, "g_myStats", "1", CVAR_ARCHIVE, 0, qtrue },
{ &g_teamStatus, "g_teamStatus", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_publicSayadmins, "g_publicSayadmins", "1", CVAR_ARCHIVE, 0, qfalse },
{ &g_minLevelToSpecMM1, "g_minLevelToSpecMM1", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_antiSpawnBlock, "g_antiSpawnBlock", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_karma, "g_karma", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_chat, "g_chat", "chat.dat", CVAR_ARCHIVE, 0, qfalse },
{ &g_adminExpireTime, "g_adminExpireTime", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_devmapKillerHP, "g_devmapKillerHP", "0", CVAR_ARCHIVE, 0, qtrue },
{ &g_killerHP, "g_killerHP", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_tag, "g_tag", "main", CVAR_INIT, 0, qfalse },
{ &g_dretchPunt, "g_dretchPunt", "1", CVAR_ARCHIVE, 0, qfalse },
{ &g_killingSpree, "g_killingSpree", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_feedingSpree, "g_feedingSpree", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_bleedingSpree, "g_bleedingSpree", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_bleedingSpreeKick, "g_bleedingSpreeKick", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_autoRevert, "g_autoRevert", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_msg, "g_msg", "", CVAR_ARCHIVE, 0, qfalse },
{ &g_msgTime, "g_msgTime", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_welcomeMsg, "g_welcomeMsg", "", CVAR_ARCHIVE, 0, qfalse },
{ &g_welcomeMsgTime, "g_welcomeMsgTime", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_turretAim, "g_turretAim", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_modBuildableHealth, "g_modBuildableHealth", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_modBuildableSpeed, "g_modBuildableSpeed", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_modBuildableCount, "g_modBuildableCount", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_modHumanStamina, "g_modHumanStamina", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_modHumanHealth, "g_modHumanHealth", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_modAlienHealth, "g_modAlienHealth", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_modAlienRegenRange, "g_modAlienRegenRange", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_modHumanRate, "g_modHumanRate", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_modAlienRate, "g_modAlienRate", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_modWeaponAmmo, "g_modWeaponAmmo", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_modWeaponReload, "g_modWeaponReload", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_modTurretAngle, "g_modTurretAngle", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_modStage3Strength, "g_modStage3Strength", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_modMainStrength, "g_modMainStrength", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_rankings, "g_rankings", "0", 0, 0, qfalse },
{ &g_allowShare, "g_allowShare", "0", CVAR_ARCHIVE | CVAR_SERVERINFO, 0, qfalse},
{ &g_creditOverflow, "g_creditOverflow", "0", CVAR_ARCHIVE | CVAR_SERVERINFO, 0, qfalse},
{ &g_banNotice, "g_banNotice", "", CVAR_ARCHIVE, 0, qfalse },
{ &g_nullifyTyrantKills, "g_nullifyTyrantKills", "0", CVAR_ARCHIVE, 0, qfalse },
{ &mod_jetpackFuel, "mod_jetpackFuel", "0", CVAR_ARCHIVE, 0, qfalse },
{ &mod_jetpackConsume, "mod_jetpackConsume", "2", CVAR_ARCHIVE, 0, qfalse },
{ &mod_jetpackRegen, "mod_jetpackRegen", "3", CVAR_ARCHIVE, 0, qfalse },
{ &g_maxReports, "g_maxReports", "3", CVAR_ARCHIVE, 0, qfalse },
{ &g_maxUnregReports, "g_maxUnregReports", "1", CVAR_ARCHIVE, 0, qfalse },
{ &g_reportWelcomeComment, "g_reportWelcomeComment", "", CVAR_ARCHIVE, 0, qfalse },
{ &g_reportAdminListMinLvl, "g_reportAdminListMinLvl", "4", CVAR_ARCHIVE, 0, qfalse },
{ &g_scrimMode, "g_scrimMode", "0", CVAR_ARCHIVE, 0, qfalse },
{ &g_schachtmeisterClearThreshold, "g_schachtmeisterClearThreshold", "-10", CVAR_ARCHIVE, 0, qfalse },
{ &g_schachtmeisterAutobahnThreshold, "g_schachtmeisterAutobahnThreshold", "-30", CVAR_ARCHIVE, 0, qfalse },
{ &g_schachtmeisterAutobahnMessage, "g_schachtmeisterAutobahnMessage", "Your host is blacklisted.", CVAR_ARCHIVE, 0, qfalse },
{ &g_revertCooldownTime, "g_revertCooldownTime", "30", CVAR_ARCHIVE, 0, qfalse }
};
static int gameCvarTableSize = sizeof( gameCvarTable ) / sizeof( gameCvarTable[ 0 ] );
void G_InitGame( int levelTime, int randomSeed, int restart );
void G_RunFrame( int levelTime );
void G_ShutdownGame( int restart );
void CheckExitRules( void );
void G_CountSpawns( void );
void G_CalculateBuildPoints( void );
/*
================
vmMain
This is the only way control passes into the module.
This must be the very first function compiled into the .q3vm file
================
*/
Q_EXPORT intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4,
int arg5, int arg6, int arg7, int arg8, int arg9,
int arg10, int arg11 )
{
switch( command )
{
case GAME_INIT:
G_InitGame( arg0, arg1, arg2 );
return 0;
case GAME_SHUTDOWN:
G_ShutdownGame( arg0 );
return 0;
case GAME_CLIENT_CONNECT:
return (intptr_t)ClientConnect( arg0, arg1 );
case GAME_CLIENT_THINK:
ClientThink( arg0 );
return 0;
case GAME_CLIENT_USERINFO_CHANGED:
ClientUserinfoChanged( arg0, qfalse );
return 0;
case GAME_CLIENT_DISCONNECT:
ClientDisconnect( arg0 );
return 0;
case GAME_CLIENT_BEGIN:
ClientBegin( arg0 );
return 0;
case GAME_CLIENT_COMMAND:
ClientCommand( arg0 );
return 0;
case GAME_RUN_FRAME:
G_RunFrame( arg0 );
return 0;
case GAME_CONSOLE_COMMAND:
return ConsoleCommand( );
}
return -1;
}
void QDECL G_Printf( const char *fmt, ... )
{
va_list argptr;
char text[ 1024 ];
va_start( argptr, fmt );
vsprintf( text, fmt, argptr );
va_end( argptr );
trap_Printf( text );
}
void QDECL G_Error( const char *fmt, ... )
{
va_list argptr;
char text[ 1024 ];
va_start( argptr, fmt );
vsprintf( text, fmt, argptr );
va_end( argptr );
trap_Error( text );
}
/*
================
G_FindTeams
Chain together all entities with a matching team field.
Entity teams are used for item groups and multi-entity mover groups.
All but the first will have the FL_TEAMSLAVE flag set and teammaster field set
All but the last will have the teamchain field set to the next one
================
*/
void G_FindTeams( void )
{
gentity_t *e, *e2;
int i, j;
int c, c2;
c = 0;
c2 = 0;
for( i = 1, e = g_entities+i; i < level.num_entities; i++, e++ )
{
if( !e->inuse )
continue;
if( !e->team )
continue;
if( e->flags & FL_TEAMSLAVE )
continue;
e->teammaster = e;
c++;
c2++;
for( j = i + 1, e2 = e + 1; j < level.num_entities; j++, e2++ )
{
if( !e2->inuse )
continue;
if( !e2->team )
continue;
if( e2->flags & FL_TEAMSLAVE )
continue;
if( !strcmp( e->team, e2->team ) )
{
c2++;
e2->teamchain = e->teamchain;
e->teamchain = e2;
e2->teammaster = e;
e2->flags |= FL_TEAMSLAVE;
// make sure that targets only point at the master
if( e2->targetname )
{
e->targetname = e2->targetname;
e2->targetname = NULL;
}
}
}
}
G_Printf( "%i teams with %i entities\n", c, c2 );
}
void G_RemapTeamShaders( void )
{
}
/*
=================
G_RegisterCvars
=================
*/
void G_RegisterCvars( void )
{
int i;
cvarTable_t *cv;
qboolean remapped = qfalse;
for( i = 0, cv = gameCvarTable; i < gameCvarTableSize; i++, cv++ )
{
trap_Cvar_Register( cv->vmCvar, cv->cvarName,
cv->defaultString, cv->cvarFlags );
if( cv->vmCvar )
cv->modificationCount = cv->vmCvar->modificationCount;
if( cv->teamShader )
remapped = qtrue;
}
if( remapped )
G_RemapTeamShaders( );
}
/*
=================
G_UpdateCvars
=================
*/
void G_UpdateCvars( void )
{
int i;
cvarTable_t *cv;
qboolean remapped = qfalse;
for( i = 0, cv = gameCvarTable; i < gameCvarTableSize; i++, cv++ )
{
if( cv->vmCvar )
{
trap_Cvar_Update( cv->vmCvar );
if( cv->modificationCount != cv->vmCvar->modificationCount )
{
cv->modificationCount = cv->vmCvar->modificationCount;
if( cv->trackChange )
{
trap_SendServerCommand( -1, va( "print \"Server: %s changed to %s\n\"",
cv->cvarName, cv->vmCvar->string ) );
// update serverinfo in case this cvar is passed to clients indirectly
CalculateRanks( );
}
if( cv->teamShader )
remapped = qtrue;
}
}
}
if( remapped )
G_RemapTeamShaders( );
}
static void G_InitModCvars( void )
{
BG_MOD_set( MOD_BG_BUILDABLE_HEALTH, g_modBuildableHealth.integer );
BG_MOD_set( MOD_BG_BUILDABLE_SPEED, g_modBuildableSpeed.integer );
BG_MOD_set( MOD_BG_HUMAN_STAMINA, g_modHumanStamina.integer );
BG_MOD_set( MOD_BG_HUMAN_HEALTH, g_modHumanHealth.integer );
BG_MOD_set( MOD_BG_ALIEN_HEALTH, g_modAlienHealth.integer );
BG_MOD_set( MOD_BG_HUMAN_RATE, g_modHumanRate.integer );
BG_MOD_set( MOD_BG_ALIEN_RATE, g_modAlienRate.integer );
BG_MOD_set( MOD_BG_WEAPON_AMMO, g_modWeaponAmmo.integer );
BG_MOD_set( MOD_BG_WEAPON_RELOAD, g_modWeaponReload.integer );
BG_MOD_set( MOD_BG_TURRET_ANGLE, g_modTurretAngle.integer );
BG_MOD_set( MOD_BG_STAGE3_STRENGTH, g_modStage3Strength.integer );
BG_MOD_update( );
}
/*
=================
G_MapConfigs
=================
*/
void G_MapConfigs( const char *mapname )
{
if( !g_mapConfigs.string[0] )
return;
if( trap_Cvar_VariableIntegerValue( "g_mapConfigsLoaded" ) )
return;
trap_SendConsoleCommand( EXEC_APPEND,
va( "exec \"%s/default.cfg\"\n", g_mapConfigs.string ) );
trap_SendConsoleCommand( EXEC_APPEND,
va( "exec \"%s/%s.cfg\"\n", g_mapConfigs.string, mapname ) );
trap_Cvar_Set( "g_mapConfigsLoaded", "1" );
}
/*
============
G_InitGame
============
*/
void G_InitGame( int levelTime, int randomSeed, int restart )
{
int i;
srand( randomSeed );
G_RegisterCvars( );
G_Printf( "------- Game Initialization -------\n" );
G_Printf( "gamename: %s\n", GAME_VERSION );
G_ProcessIPBans( );
G_InitMemory( );
// set some level globals
memset( &level, 0, sizeof( level ) );
level.time = levelTime;
level.startTime = levelTime;
level.alienStage2Time = level.alienStage3Time =
level.humanStage2Time = level.humanStage3Time = level.startTime;
level.snd_fry = G_SoundIndex( "sound/misc/fry.wav" ); // FIXME standing in lava / slime
if( g_logFile.string[ 0 ] )
{
if( g_logFileSync.integer )
trap_FS_FOpenFile( g_logFile.string, &level.logFile, FS_APPEND_SYNC );
else
trap_FS_FOpenFile( g_logFile.string, &level.logFile, FS_APPEND );
if( !level.logFile )
G_Printf( "WARNING: Couldn't open logfile: %s\n", g_logFile.string );
else
{
char serverinfo[ MAX_INFO_STRING ];
qtime_t qt;
trap_GetServerinfo( serverinfo, sizeof( serverinfo ) );
G_LogPrintf( "------------------------------------------------------------\n" );
G_LogPrintf( "InitGame: %s\n", serverinfo );
trap_RealTime( &qt );
G_LogPrintf("RealTime: %04i/%02i/%02i %02i:%02i:%02i\n",
qt.tm_year+1900, qt.tm_mon+1, qt.tm_mday,
qt.tm_hour, qt.tm_min, qt.tm_sec );
}
}
else
G_Printf( "Not logging to disk\n" );
{
char map[ MAX_CVAR_VALUE_STRING ] = {""};
trap_Cvar_VariableStringBuffer( "mapname", map, sizeof( map ) );
G_MapConfigs( map );
}
// we're done with g_mapConfigs, so reset this for the next map
trap_Cvar_Set( "g_mapConfigsLoaded", "0" );
if ( g_admin.string[ 0 ] ) {
G_admin_readconfig( NULL, 0 );
}
// initialize all entities for this game
memset( g_entities, 0, MAX_GENTITIES * sizeof( g_entities[ 0 ] ) );
level.gentities = g_entities;
// initialize all clients for this game
level.maxclients = g_maxclients.integer;
memset( g_clients, 0, MAX_CLIENTS * sizeof( g_clients[ 0 ] ) );
level.clients = g_clients;
// set client fields on player ents
for( i = 0; i < level.maxclients; i++ )
g_entities[ i ].client = level.clients + i;
// always leave room for the max number of clients,
// even if they aren't all used, so numbers inside that
// range are NEVER anything but clients
level.num_entities = MAX_CLIENTS;
// let the server system know where the entites are
trap_LocateGameData( level.gentities, level.num_entities, sizeof( gentity_t ),
&level.clients[ 0 ].ps, sizeof( level.clients[ 0 ] ) );
trap_SetConfigstring( CS_INTERMISSION, "0" );
// update maplog
G_admin_maplog_update( );
// test to see if a custom buildable layout will be loaded
G_LayoutSelect( );
// parse the key/value pairs and spawn gentities
G_SpawnEntitiesFromString( );
// load up a custom building layout if there is one
G_LayoutLoad( );
// load up nobuild zones
nobuild_init( );
// the map might disable some things
BG_InitAllowedGameElements( );
// practice counter
if( g_practiceCount.integer > 0 )
{
trap_Cvar_Set( "g_practiceCount", va( "%d", g_practiceCount.integer - 1 ) );
}
// free credits expiration
if( g_freeCredits.integer > 1 )
{
trap_Cvar_Set( "g_freeCredits",
va( "%d", ( g_freeCredits.integer > 2 ) ? g_freeCredits.integer - 1 : 0 ) );
}
// syncronize mod cvars
G_InitModCvars( );
// general initialization
G_FindTeams( );
//TA:
G_InitDamageLocations( );
G_InitMapRotations( );
G_InitSpawnQueue( &level.alienSpawnQueue );
G_InitSpawnQueue( &level.humanSpawnQueue );
if( g_debugMapRotation.integer )
G_PrintRotations( );
//reset stages
trap_Cvar_Set( "g_alienStage", va( "%d", S1 ) );
trap_Cvar_Set( "g_humanStage", va( "%d", S1 ) );
trap_Cvar_Set( "g_alienKills", 0 );
trap_Cvar_Set( "g_humanKills", 0 );
trap_Cvar_Set( "g_suddenDeath", 0 );
level.suddenDeathBeginTime = g_suddenDeathTime.integer * 60000;
trap_Cvar_Set( "g_vampireDeath", 0 );
G_Printf( "-----------------------------------\n" );
G_RemapTeamShaders( );
//TA: so the server counts the spawns without a client attached
G_CountSpawns( );
G_ResetPTRConnections( );
if(g_lockTeamsAtStart.integer)
{
level.alienTeamLocked=qtrue;
level.humanTeamLocked=qtrue;
trap_Cvar_Set( "g_lockTeamsAtStart", "0" );
}
}
/*
==================
G_ClearVotes
remove all currently active votes
==================
*/
static void G_ClearVotes( void )
{
level.voteTime = 0;
trap_SetConfigstring( CS_VOTE_TIME, "" );
trap_SetConfigstring( CS_VOTE_STRING, "" );
level.teamVoteTime[ 0 ] = 0;
trap_SetConfigstring( CS_TEAMVOTE_TIME, "" );
trap_SetConfigstring( CS_TEAMVOTE_STRING, "" );
level.teamVoteTime[ 1 ] = 0;
trap_SetConfigstring( CS_TEAMVOTE_TIME + 1, "" );
trap_SetConfigstring( CS_TEAMVOTE_STRING + 1, "" );
}
/*
=================
G_ShutdownGame
=================
*/
void G_ShutdownGame( int restart )
{
// in case of a map_restart
G_ClearVotes( );
G_Printf( "==== ShutdownGame ====\n" );
G_admin_chat_writeconfig();
if( level.logFile )
{
G_LogPrintf( "ShutdownGame:\n" );
G_LogPrintf( "------------------------------------------------------------\n" );
trap_FS_FCloseFile( level.logFile );
}
// write all the client session data so we can get it back
G_WriteSessionData( );
G_admin_cleanup( );
G_admin_namelog_cleanup( );
G_admin_adminlog_cleanup( );
G_admin_tklog_cleanup( );
level.restarted = qfalse;
level.surrenderTeam = PTE_NONE;
trap_SetConfigstring( CS_WINNER, "" );
}
//===================================================================
void QDECL Com_Error( int level, const char *error, ... )
{
va_list argptr;
char text[ 1024 ];
va_start( argptr, error );
vsprintf( text, error, argptr );
va_end( argptr );
G_Error( "%s", text );
}
void QDECL Com_Printf( const char *msg, ... )
{
va_list argptr;
char text[ 1024 ];
va_start( argptr, msg );
vsprintf( text, msg, argptr );
va_end( argptr );
G_Printf( "%s", text );
}
/*
========================================================================
PLAYER COUNTING / SCORE SORTING
========================================================================
*/
/*
=============
SortRanks
=============
*/
int QDECL SortRanks( const void *a, const void *b )
{
gclient_t *ca, *cb;
ca = &level.clients[ *(int *)a ];
cb = &level.clients[ *(int *)b ];
// then sort by score
if( ca->pers.score > cb->pers.score )
return -1;
else if( ca->pers.score < cb->pers.score )
return 1;
else
return 0;
}
/*
============
G_InitSpawnQueue
Initialise a spawn queue
============
*/
void G_InitSpawnQueue( spawnQueue_t *sq )
{
int i;
sq->back = sq->front = 0;
sq->back = QUEUE_MINUS1( sq->back );
//0 is a valid clientNum, so use something else
for( i = 0; i < MAX_CLIENTS; i++ )
sq->clients[ i ] = -1;
}
/*
============
G_GetSpawnQueueLength
Return tha length of a spawn queue
============
*/
int G_GetSpawnQueueLength( spawnQueue_t *sq )
{
int length = sq->back - sq->front + 1;
while( length < 0 )
length += MAX_CLIENTS;
while( length >= MAX_CLIENTS )
length -= MAX_CLIENTS;
return length;
}
/*
============
G_PopSpawnQueue
Remove from front element from a spawn queue
============
*/
int G_PopSpawnQueue( spawnQueue_t *sq )
{
int clientNum = sq->clients[ sq->front ];
if( G_GetSpawnQueueLength( sq ) > 0 )
{
sq->clients[ sq->front ] = -1;
sq->front = QUEUE_PLUS1( sq->front );
g_entities[ clientNum ].client->ps.pm_flags &= ~PMF_QUEUED;
return clientNum;
}
else
return -1;
}
/*
============
G_PeekSpawnQueue
Look at front element from a spawn queue
============
*/
int G_PeekSpawnQueue( spawnQueue_t *sq )
{
return sq->clients[ sq->front ];
}
/*
============
G_SearchSpawnQueue
Look to see if clientNum is already in the spawnQueue
============
*/
qboolean G_SearchSpawnQueue( spawnQueue_t *sq, int clientNum )
{
int i;
for( i = 0; i < MAX_CLIENTS; i++ )
if( sq->clients[ i ] == clientNum )
return qtrue;
return qfalse;
}
/*
============
G_PushSpawnQueue
Add an element to the back of the spawn queue
============
*/
qboolean G_PushSpawnQueue( spawnQueue_t *sq, int clientNum )
{
// don't add the same client more than once
if( G_SearchSpawnQueue( sq, clientNum ) )
return qfalse;
sq->back = QUEUE_PLUS1( sq->back );
sq->clients[ sq->back ] = clientNum;
g_entities[ clientNum ].client->ps.pm_flags |= PMF_QUEUED;
return qtrue;
}
/*
============
G_RemoveFromSpawnQueue
remove a specific client from a spawn queue
============
*/
qboolean G_RemoveFromSpawnQueue( spawnQueue_t *sq, int clientNum )
{
int i = sq->front;
if( G_GetSpawnQueueLength( sq ) )
{
do
{
if( sq->clients[ i ] == clientNum )
{
//and this kids is why it would have
//been better to use an LL for internal
//representation
do
{
sq->clients[ i ] = sq->clients[ QUEUE_PLUS1( i ) ];
i = QUEUE_PLUS1( i );
} while( i != QUEUE_PLUS1( sq->back ) );
sq->back = QUEUE_MINUS1( sq->back );
g_entities[ clientNum ].client->ps.pm_flags &= ~PMF_QUEUED;
return qtrue;
}
i = QUEUE_PLUS1( i );
} while( i != QUEUE_PLUS1( sq->back ) );
}
return qfalse;
}
/*
============
G_GetPosInSpawnQueue
Get the position of a client in a spawn queue
============
*/
int G_GetPosInSpawnQueue( spawnQueue_t *sq, int clientNum )
{
int i = sq->front;
if( G_GetSpawnQueueLength( sq ) )
{
do
{
if( sq->clients[ i ] == clientNum )
{
if( i < sq->front )
return i + MAX_CLIENTS - sq->front;
else
return i - sq->front;
}
i = QUEUE_PLUS1( i );
} while( i != QUEUE_PLUS1( sq->back ) );
}
return -1;
}
/*
============
G_PrintSpawnQueue
Print the contents of a spawn queue
============
*/
void G_PrintSpawnQueue( spawnQueue_t *sq )
{
int i = sq->front;
int length = G_GetSpawnQueueLength( sq );
G_Printf( "l:%d f:%d b:%d :", length, sq->front, sq->back );
if( length > 0 )
{
do
{
if( sq->clients[ i ] == -1 )
G_Printf( "*:" );
else
G_Printf( "%d:", sq->clients[ i ] );
i = QUEUE_PLUS1( i );
} while( i != QUEUE_PLUS1( sq->back ) );
}
G_Printf( "\n" );
}
/*
============
G_SpawnClients
Spawn queued clients
============
*/
void G_SpawnClients( pTeam_t team )
{
int clientNum;
gentity_t *ent, *spawn;
vec3_t spawn_origin, spawn_angles;
spawnQueue_t *sq = NULL;
int numSpawns = 0;
if( g_doWarmup.integer && ( g_warmupMode.integer==1 || g_warmupMode.integer == 2 ) &&
level.time - level.startTime < g_warmup.integer * 1000 )
{
return;
}
if( team == PTE_ALIENS )
{
sq = &level.alienSpawnQueue;
numSpawns = level.numAlienSpawns;
}
else if( team == PTE_HUMANS )
{
sq = &level.humanSpawnQueue;
numSpawns = level.numHumanSpawns;
}
if( G_GetSpawnQueueLength( sq ) > 0 && numSpawns > 0 )
{
clientNum = G_PeekSpawnQueue( sq );
ent = &g_entities[ clientNum ];
if( ( spawn = G_SelectTremulousSpawnPoint( team,
ent->client->pers.lastDeathLocation,
spawn_origin, spawn_angles ) ) )
{
clientNum = G_PopSpawnQueue( sq );
if( clientNum < 0 )
return;
ent = &g_entities[ clientNum ];
ent->client->sess.sessionTeam = TEAM_FREE;
ClientUserinfoChanged( clientNum, qfalse );
ClientSpawn( ent, spawn, spawn_origin, spawn_angles );
}
}
}
/*
============
G_CountSpawns
Counts the number of spawns for each team
============
*/
void G_CountSpawns( void )
{
int i;
gentity_t *ent;
level.numAlienSpawns = 0;
level.numHumanSpawns = 0;
for( i = 1, ent = g_entities + i ; i < level.num_entities ; i++, ent++ )
{
if( !ent->inuse || ent->s.eType != ET_BUILDABLE ||
( ent->spawned && ent->health <= 0 ) )
continue;
if( ent->s.modelindex == BA_A_SPAWN )
level.numAlienSpawns++;
if( ent->s.modelindex == BA_H_SPAWN )
level.numHumanSpawns++;
}
//let the client know how many spawns there are
trap_SetConfigstring( CS_SPAWNS, va( "%d %d",
level.numAlienSpawns, level.numHumanSpawns ) );
}
/*
============
G_TimeTilSuddenDeath
============
*/
int G_TimeTilSuddenDeath( void )
{
if( (!g_suddenDeathTime.integer && level.suddenDeathBeginTime==0 ) || level.suddenDeathBeginTime<0 )
return 999999999; // Always some time away
return ( ( level.suddenDeathBeginTime ) - ( level.time - level.startTime ) );
}
int G_TimeTilVampireDeath( void )
{
if( !g_vampireDeathTime.integer )
return 3600000; // Always some time away
return ( g_vampireDeathTime.integer * 60000 ) -
( level.time - level.startTime );
}
#define PLAYER_COUNT_MOD 5.0f
/*
============
G_CalculateBuildPoints
Recalculate the quantity of building points available to the teams
============
*/
void G_CalculateBuildPoints( void )
{
int i;
buildable_t buildable;
gentity_t *ent;
int localHTP = g_humanBuildPoints.integer,
localATP = g_alienBuildPoints.integer;
// g_suddenDeath sets what state we want it to be.
// level.suddenDeath says whether we've calculated BPs at the 'start' of SD or not
// reset if SD was on, but now it's off
if(!g_suddenDeath.integer && level.suddenDeath)
{
level.suddenDeath=qfalse;
level.suddenDeathWarning=0;
level.suddenDeathBeginTime = -1;
if((level.time - level.startTime) < (g_suddenDeathTime.integer * 60000 ) )
level.suddenDeathBeginTime = g_suddenDeathTime.integer * 60000;
else
level.suddenDeathBeginTime = -1;
}
if(!level.suddenDeath)
{
if(g_suddenDeath.integer || G_TimeTilSuddenDeath( ) <= 0 ) //Conditions to enter SD
{
//begin sudden death
if( level.suddenDeathWarning < TW_PASSED )
{
trap_SendServerCommand( -1, "cp \"Sudden Death!\"" );
G_LogPrintf("Beginning Sudden Death (Mode %d)\n",g_suddenDeathMode.integer);
localHTP = 0;
localATP = 0;
if( g_suddenDeathMode.integer == SDMODE_SELECTIVE )
{
for( i = 1, ent = g_entities + i; i < level.num_entities; i++, ent++ )
{
if( ent->s.eType != ET_BUILDABLE )
continue;
if( BG_FindReplaceableTestForBuildable( ent->s.modelindex ) )
{
int t = BG_FindTeamForBuildable( ent->s.modelindex );
if( t == BIT_HUMANS )
localHTP += BG_FindBuildPointsForBuildable( ent->s.modelindex );
else if( t == BIT_ALIENS )
localATP += BG_FindBuildPointsForBuildable( ent->s.modelindex );
}
}
}
level.suddenDeathHBuildPoints = localHTP;
level.suddenDeathABuildPoints = localATP;
level.suddenDeathBeginTime = level.time;
level.suddenDeath=qtrue;
trap_Cvar_Set( "g_suddenDeath", "1" );
level.suddenDeathWarning = TW_PASSED;
}
}
else
{
//warn about sudden death
if( ( G_TimeTilSuddenDeath( ) <= 60000 ) &&
( level.suddenDeathWarning < TW_IMMINENT ) )
{
trap_SendServerCommand( -1, va("cp \"Sudden Death in %d seconds!\"",
(int)(G_TimeTilSuddenDeath() / 1000 ) ) );
level.suddenDeathWarning = TW_IMMINENT;
}
}
}
//vampire death
if( !g_vampireDeath.integer && level.vampireDeath )
{
level.vampireDeath = 0;
level.vampireDeathWarning = 0;
}
if( !level.vampireDeath )
{
if( g_vampireDeath.integer || G_TimeTilVampireDeath( ) <= 0 ) //Conditions to enter VD
{
if( level.vampireDeathWarning < TW_PASSED )
{
trap_SendServerCommand( -1, "cp \"^1Vampire Sudden Death!\"" );
level.vampireDeath = 1;
level.vampireDeathBeginTime = level.time;
level.vampireDeathWarning = TW_PASSED;
g_vampireDeath.integer = 1;
}
}
else if( G_TimeTilVampireDeath( ) <= 60000 && level.vampireDeathWarning < TW_IMMINENT )
{
trap_SendServerCommand( -1,
va( "cp \"^1Vampire\n^7Sudden Death in 60 seconds!%s%s\"",
( g_vampireDeathInfo.string[ 0 ] ) ? "\n\n" : "",
g_vampireDeathInfo.string ) );
level.vampireDeathWarning = TW_IMMINENT;
}
else if( G_TimeTilVampireDeath( ) <= 300000 && level.vampireDeathWarning < TW_SOON )
{
trap_SendServerCommand( -1,
va ("cp \"^1Vampire\n^7Sudden Death in 5 minutes!%s%s\"",
( g_vampireDeathInfo.string[ 0 ] ) ? "\n\n" : "",
g_vampireDeathInfo.string ) );
level.vampireDeathWarning = TW_SOON;
}
}
//set BP at each cycle
if( g_suddenDeath.integer )
{
localHTP = level.suddenDeathHBuildPoints;
localATP = level.suddenDeathABuildPoints;
}
else
{
localHTP = g_humanBuildPoints.integer;
localATP = g_alienBuildPoints.integer;
}
// Build Point Recovery
// each gained stage adds 50% delay
if( g_buildPointsRecoverRate.integer )
{
while( level.humanRecoverBuildPoints > 0 &&
level.humanRecoverTime < level.time )
{
level.humanRecoverBuildPoints--;
level.humanRecoverTime +=
( 60000 + g_humanStage.integer * 30000 ) / g_buildPointsRecoverRate.integer;
}
while( level.alienRecoverBuildPoints > 0 &&
level.alienRecoverTime < level.time )
{
level.alienRecoverBuildPoints--;
level.alienRecoverTime +=
( 60000 + g_alienStage.integer * 30000 ) / g_buildPointsRecoverRate.integer;
}
}
else
{
// recover may have been turned off, reset
level.humanRecoverBuildPoints = 0;
level.alienRecoverBuildPoints = 0;
}
level.humanBuildPoints = level.humanBuildPointsPowered = localHTP - level.humanRecoverBuildPoints;
level.alienBuildPoints = localATP - level.alienRecoverBuildPoints;
level.reactorPresent = qfalse;
level.overmindPresent = qfalse;
for( i = 1, ent = g_entities + i ; i < level.num_entities ; i++, ent++ )
{
if( !ent->inuse )
continue;
if( ent->s.eType != ET_BUILDABLE )
continue;
if( ent->s.eFlags & EF_DEAD )
continue;
buildable = ent->s.modelindex;
if( buildable != BA_NONE )
{
if( buildable == BA_H_REACTOR && ent->spawned && ent->health > 0 )
level.reactorPresent = qtrue;
if( buildable == BA_A_OVERMIND && ent->spawned && ent->health > 0 )
level.overmindPresent = qtrue;
if( !g_suddenDeath.integer || BG_FindReplaceableTestForBuildable( buildable ) )
{
if( BG_FindTeamForBuildable( buildable ) == BIT_HUMANS )
{
level.humanBuildPoints -= BG_FindBuildPointsForBuildable( buildable );
if( ent->powered )
level.humanBuildPointsPowered -= BG_FindBuildPointsForBuildable( buildable );
}
else
{
level.alienBuildPoints -= BG_FindBuildPointsForBuildable( buildable );
}
}
}
}
if( level.humanBuildPoints < 0 )
{
localHTP -= level.humanBuildPoints;
level.humanBuildPointsPowered -= level.humanBuildPoints;
level.humanBuildPoints = 0;
}
if( level.alienBuildPoints < 0 )
{
localATP -= level.alienBuildPoints;
level.alienBuildPoints = 0;
}
trap_SetConfigstring( CS_BUILDPOINTS, va( "%d %d %d %d %d",
level.alienBuildPoints, localATP,
level.humanBuildPoints, localHTP,
level.humanBuildPointsPowered ) );
//may as well pump the stages here too
{
float alienPlayerCountMod = level.averageNumAlienClients / PLAYER_COUNT_MOD;
float humanPlayerCountMod = level.averageNumHumanClients / PLAYER_COUNT_MOD;
int alienNextStageThreshold, humanNextStageThreshold;
if( alienPlayerCountMod < 0.1f )
alienPlayerCountMod = 0.1f;
if( humanPlayerCountMod < 0.1f )
humanPlayerCountMod = 0.1f;
if( g_alienStage.integer == S1 && g_alienMaxStage.integer > S1 )
alienNextStageThreshold = (int)( ceil( (float)g_alienStage2Threshold.integer * alienPlayerCountMod ) );
else if( g_alienStage.integer == S2 && g_alienMaxStage.integer > S2 )
alienNextStageThreshold = (int)( ceil( (float)g_alienStage3Threshold.integer * alienPlayerCountMod ) );
else
alienNextStageThreshold = -1;
if( g_humanStage.integer == S1 && g_humanMaxStage.integer > S1 )
humanNextStageThreshold = (int)( ceil( (float)g_humanStage2Threshold.integer * humanPlayerCountMod ) );
else if( g_humanStage.integer == S2 && g_humanMaxStage.integer > S2 )
humanNextStageThreshold = (int)( ceil( (float)g_humanStage3Threshold.integer * humanPlayerCountMod ) );
else
humanNextStageThreshold = -1;
trap_SetConfigstring( CS_STAGES, va( "%d %d %d %d %d %d",
g_alienStage.integer, g_humanStage.integer,
g_alienKills.integer, g_humanKills.integer,
alienNextStageThreshold, humanNextStageThreshold ) );
}
}
/*
============
G_CalculateStages
============
*/
void G_CalculateStages( void )
{
float alienPlayerCountMod = level.averageNumAlienClients / PLAYER_COUNT_MOD;
float humanPlayerCountMod = level.averageNumHumanClients / PLAYER_COUNT_MOD;
static int lastAlienStageModCount = 1;
static int lastHumanStageModCount = 1;
static int alienTriggerStage = 0;
static int humanTriggerStage = 0;
if( alienPlayerCountMod < 0.1f )
alienPlayerCountMod = 0.1f;
if( humanPlayerCountMod < 0.1f )
humanPlayerCountMod = 0.1f;
if( g_alienKills.integer >=
(int)( ceil( (float)g_alienStage2Threshold.integer * alienPlayerCountMod ) ) &&
g_alienStage.integer == S1 && g_alienMaxStage.integer > S1 )
{
trap_Cvar_Set( "g_alienStage", va( "%d", S2 ) );
level.alienStage2Time = level.time;
lastAlienStageModCount = g_alienStage.modificationCount;
G_LogPrintf("Stage: A 2: Aliens reached Stage 2\n");
}
if( g_alienKills.integer >=
(int)( ceil( (float)g_alienStage3Threshold.integer * alienPlayerCountMod ) ) &&
g_alienStage.integer == S2 && g_alienMaxStage.integer > S2 )
{
trap_Cvar_Set( "g_alienStage", va( "%d", S3 ) );
level.alienStage3Time = level.time;
lastAlienStageModCount = g_alienStage.modificationCount;
G_LogPrintf("Stage: A 3: Aliens reached Stage 3\n");
}
if( g_humanKills.integer >=
(int)( ceil( (float)g_humanStage2Threshold.integer * humanPlayerCountMod ) ) &&
g_humanStage.integer == S1 && g_humanMaxStage.integer > S1 )
{
trap_Cvar_Set( "g_humanStage", va( "%d", S2 ) );
level.humanStage2Time = level.time;
lastHumanStageModCount = g_humanStage.modificationCount;
G_LogPrintf("Stage: H 2: Humans reached Stage 2\n");
}
if( g_humanKills.integer >=
(int)( ceil( (float)g_humanStage3Threshold.integer * humanPlayerCountMod ) ) &&
g_humanStage.integer == S2 && g_humanMaxStage.integer > S2 )
{
trap_Cvar_Set( "g_humanStage", va( "%d", S3 ) );
level.humanStage3Time = level.time;
G_LogPrintf("Stage: H 3: Humans reached Stage 3\n");
lastHumanStageModCount = g_humanStage.modificationCount;
}
if( g_alienStage.modificationCount > lastAlienStageModCount )
{
G_Checktrigger_stages( PTE_ALIENS, g_alienStage.integer );
while( alienTriggerStage < MIN( g_alienStage.integer, S3 ) )
G_Checktrigger_stages( PTE_ALIENS, ++alienTriggerStage );
if( g_alienStage.integer == S2 )
level.alienStage2Time = level.time;
else if( g_alienStage.integer == S3 )
level.alienStage3Time = level.time;
lastAlienStageModCount = g_alienStage.modificationCount;
}
if( g_humanStage.modificationCount > lastHumanStageModCount )
{
while( humanTriggerStage < MIN( g_humanStage.integer, S3 ) )
G_Checktrigger_stages( PTE_HUMANS, ++humanTriggerStage );
if( g_humanStage.integer == S2 )
level.humanStage2Time = level.time;
else if( g_humanStage.integer == S3 )
level.humanStage3Time = level.time;
lastHumanStageModCount = g_humanStage.modificationCount;
}
}
/*
============
CalculateAvgPlayers
Calculates the average number of players playing this game
============
*/
void G_CalculateAvgPlayers( void )
{
//there are no clients or only spectators connected, so
//reset the number of samples in order to avoid the situation
//where the average tends to 0
if( !level.numAlienClients )
{
level.numAlienSamples = 0;
trap_Cvar_Set( "g_alienKills", "0" );
}
if( !level.numHumanClients )
{
level.numHumanSamples = 0;
trap_Cvar_Set( "g_humanKills", "0" );
}
//calculate average number of clients for stats
level.averageNumAlienClients =
( ( level.averageNumAlienClients * level.numAlienSamples )
+ level.numAlienClients ) /
(float)( level.numAlienSamples + 1 );
level.numAlienSamples++;
level.averageNumHumanClients =
( ( level.averageNumHumanClients * level.numHumanSamples )
+ level.numHumanClients ) /
(float)( level.numHumanSamples + 1 );
level.numHumanSamples++;
}
/*
============
CalculateRanks
Recalculates the score ranks of all players
This will be called on every client connect, begin, disconnect, death,
and team change.
============
*/
void CalculateRanks( void )
{
int i;
char P[ MAX_CLIENTS + 1 ] = {""};
int ff = 0;
level.numConnectedClients = 0;
level.numNonSpectatorClients = 0;
level.numPlayingClients = 0;
level.numVotingClients = 0; // don't count bots
level.numAlienClients = 0;
level.numHumanClients = 0;
level.numLiveAlienClients = 0;
level.numLiveHumanClients = 0;
level.bleeders = 0;
for( i = 0; i < level.maxclients; i++ )
{
P[ i ] = '-';
if ( level.clients[ i ].pers.connected != CON_DISCONNECTED )
{
level.sortedClients[ level.numConnectedClients ] = i;
level.numConnectedClients++;
P[ i ] = (char)'0' + level.clients[ i ].pers.teamSelection;
if( level.clients[ i ].pers.connected != CON_CONNECTED )
continue;
level.numVotingClients++;
if( level.clients[ i ].pers.teamSelection != PTE_NONE )
{
level.numPlayingClients++;
if( level.clients[ i ].sess.sessionTeam != TEAM_SPECTATOR )
level.numNonSpectatorClients++;
if( level.clients[ i ].pers.teamSelection == PTE_ALIENS )
{
level.numAlienClients++;
if( level.clients[ i ].sess.sessionTeam != TEAM_SPECTATOR )
level.numLiveAlienClients++;
}
else if( level.clients[ i ].pers.teamSelection == PTE_HUMANS )
{
level.numHumanClients++;
if( level.clients[ i ].sess.sessionTeam != TEAM_SPECTATOR )
level.numLiveHumanClients++;
}
if( level.clients[ i ].pers.bleeder )
level.bleeders++;
}
}
}
level.numteamVotingClients[ 0 ] = level.numHumanClients;
level.numteamVotingClients[ 1 ] = level.numAlienClients;
P[ i ] = '\0';
trap_Cvar_Set( "P", P );
if( g_friendlyFire.value>0 )
ff |= ( FFF_HUMANS | FFF_ALIENS );
if( g_friendlyFireHumans.value>0 )
ff |= FFF_HUMANS;
if( g_friendlyFireAliens.value>0 )
ff |= FFF_ALIENS;
if( g_friendlyBuildableFire.value>0 )
ff |= FFF_BUILDABLES;
trap_Cvar_Set( "ff", va( "%i", ff ) );
qsort( level.sortedClients, level.numConnectedClients,
sizeof( level.sortedClients[ 0 ] ), SortRanks );
// see if it is time to end the level
CheckExitRules( );
// if we are at the intermission, send the new info to everyone
if( level.intermissiontime && !level.mapRotationVoteTime )
SendScoreboardMessageToAllClients( );
}
/*
========================================================================
MAP CHANGING
========================================================================
*/
/*
========================
SendScoreboardMessageToAllClients
Do this at BeginIntermission time and whenever ranks are recalculated
due to enters/exits/forced team changes
========================
*/
void SendScoreboardMessageToAllClients( void )
{
int i;
for( i = 0; i < level.maxclients; i++ )
{
if( level.clients[ i ].pers.connected == CON_CONNECTED )
ScoreboardMessage( g_entities + i );
}
}
/*
========================
MoveClientToIntermission
When the intermission starts, this will be called for all players.
If a new client connects, this will be called after the spawn function.
========================
*/
void MoveClientToIntermission( gentity_t *ent )
{
// take out of follow mode if needed
if( ent->client->sess.spectatorState == SPECTATOR_FOLLOW )
G_StopFollowing( ent );
// move to the spot
VectorCopy( level.intermission_origin, ent->s.origin );
VectorCopy( level.intermission_origin, ent->client->ps.origin );
VectorCopy( level.intermission_angle, ent->client->ps.viewangles );
ent->client->ps.pm_type = PM_INTERMISSION;
// clean up powerup info
memset( ent->client->ps.misc, 0, sizeof( ent->client->ps.misc ) );
ent->client->ps.eFlags = 0;
ent->s.eFlags = 0;
ent->s.eType = ET_GENERAL;
ent->s.modelindex = 0;
ent->s.loopSound = 0;
ent->s.event = 0;
ent->r.contents = 0;
}
/*
==================
FindIntermissionPoint
This is also used for spectator spawns
==================
*/
void FindIntermissionPoint( void )
{
gentity_t *ent, *target;
vec3_t dir;
// find the intermission spot
ent = G_Find( NULL, FOFS( classname ), "info_player_intermission" );
if( !ent )
{ // the map creator forgot to put in an intermission point...
G_SelectSpawnPoint( vec3_origin, level.intermission_origin, level.intermission_angle );
}
else
{
VectorCopy( ent->s.origin, level.intermission_origin );
VectorCopy( ent->s.angles, level.intermission_angle );
// if it has a target, look towards it
if( ent->target )
{
target = G_PickTarget( ent->target );
if( target )
{
VectorSubtract( target->s.origin, level.intermission_origin, dir );
vectoangles( dir, level.intermission_angle );
}
}
}
}
/*
==================
BeginIntermission
==================
*/
void BeginIntermission( void )
{
int i;
gentity_t *client;
if( level.intermissiontime )
return; // already active
level.numTeamWarnings = 99;
level.intermissiontime = level.time;
G_ClearVotes( );
FindIntermissionPoint( );
// move all clients to the intermission point
for( i = 0; i < level.maxclients; i++ )
{
client = g_entities + i;
if( !client->inuse )
continue;
// respawn if dead
if( client->health <= 0 )
respawn(client);
MoveClientToIntermission( client );
}
// send the current scoring to all clients
SendScoreboardMessageToAllClients( );
if( g_nextMap.string[ 0 ] )
{
trap_SendServerCommand( -1,
va( "print \"next map has been set to %s^7%s\n\"",
g_nextMap.string,
( G_CheckMapRotationVote() ) ? ", voting will be skipped" : "" ) );
}
}
void BeginMapRotationVote( void )
{
gentity_t *ent;
int length;
int i;
if( level.mapRotationVoteTime )
return;
length = g_mapRotationVote.integer;
if( length > 60 )
length = 60;
level.mapRotationVoteTime = level.time + ( length * 1000 );
for( i = 0; i < level.maxclients; i++ )
{
ent = g_entities + i;
if( !ent->inuse )
continue;
ent->client->ps.pm_type = PM_SPECTATOR;
ent->client->sess.sessionTeam = TEAM_SPECTATOR;
ent->client->sess.spectatorState = SPECTATOR_LOCKED;
}
}
/*
=============
ExitLevel
When the intermission has been exited, the server is either moved
to a new map based on the map rotation or the current map restarted
=============
*/
void ExitLevel( void )
{
int i;
gclient_t *cl;
buildHistory_t *tmp, *mark;
char currentmap[ MAX_CVAR_VALUE_STRING ];
trap_Cvar_VariableStringBuffer( "mapname", currentmap, sizeof( currentmap ));
if( level.mapRotationVoteTime )
{
if( level.time < level.mapRotationVoteTime &&
!G_IntermissionMapVoteWinner( ) )
return;
}
else if( g_mapRotationVote.integer > 0 &&
G_CheckMapRotationVote() &&
!g_nextMap.string[ 0 ] )
{
BeginMapRotationVote( );
return;
}
while( ( tmp = level.buildHistory ) )
{
level.buildHistory = level.buildHistory->next;
while( ( mark = tmp ) )
{
tmp = tmp->marked;
G_Free( mark );
}
}
if( !Q_stricmp( currentmap, g_nextMap.string ) )
trap_SendConsoleCommand( EXEC_APPEND, "map_restart\n" );
else if ( G_MapExists( g_nextMap.string ) )
trap_SendConsoleCommand( EXEC_APPEND, va("!map %s\n", g_nextMap.string ) );
else if( G_MapRotationActive( ) )
G_AdvanceMapRotation( );
else
trap_SendConsoleCommand( EXEC_APPEND, "map_restart\n" );
trap_Cvar_Set( "g_nextMap", "" );
level.restarted = qtrue;
level.changemap = NULL;
level.intermissiontime = 0;
// reset all the scores so we don't enter the intermission again
for( i = 0; i < g_maxclients.integer; i++ )
{
cl = level.clients + i;
if( cl->pers.connected != CON_CONNECTED )
continue;
cl->ps.persistant[ PERS_SCORE ] = 0;
}
// we need to do this here before chaning to CON_CONNECTING
G_WriteSessionData( );
// change all client states to connecting, so the early players into the
// next level will know the others aren't done reconnecting
for( i = 0; i < g_maxclients.integer; i++ )
{
if( level.clients[ i ].pers.connected == CON_CONNECTED )
level.clients[ i ].pers.connected = CON_CONNECTING;
}
}
/*
=================
G_AdminsPrintf
Print to all active admins, and the logfile with a time stamp if it is open, and to the console
=================
*/
void QDECL G_AdminsPrintf( const char *fmt, ... )
{
va_list argptr;
char string[ 1024 ];
gentity_t *tempent;
int j;
va_start( argptr, fmt );
vsprintf( string, fmt,argptr );
va_end( argptr );
for( j = 0; j < level.maxclients; j++ )
{
tempent = &g_entities[ j ];
if( G_admin_permission( tempent, ADMF_ADMINCHAT) &&
!tempent->client->pers.ignoreAdminWarnings )
{
trap_SendServerCommand(tempent-g_entities,va( "print \"^7[^5ADMIN^7] %s\"", string) );
}
}
G_LogPrintf("%s",string);
}
/*
=================
G_LogPrintf
Print to the logfile with a time stamp if it is open
=================
*/
void QDECL G_LogPrintf( const char *fmt, ... )
{
va_list argptr;
char string[ 1024 ], decoloured[ 1024 ];
int min, tens, sec;
sec = ( level.time - level.startTime ) / 1000;
min = sec / 60;
sec -= min * 60;
tens = sec / 10;
sec -= tens * 10;
Com_sprintf( string, sizeof( string ), "%3i:%i%i ", min, tens, sec );
va_start( argptr, fmt );
vsprintf( string +7 , fmt,argptr );
va_end( argptr );
if( g_dedicated.integer )
G_Printf( "%s", string + 7 );
if( !level.logFile )
return;
if( g_decolourLogfiles.integer )
{
G_DecolorString( string, decoloured );
trap_FS_Write( decoloured, strlen( decoloured ), level.logFile );
}
else
{
trap_FS_Write( string, strlen( string ), level.logFile );
}
}
/*
=================
G_LogPrintfColoured
Bypasses g_decolourLogfiles for events that need colors in the logs
=================
*/
void QDECL G_LogPrintfColoured( const char *fmt, ... )
{
va_list argptr;
char string[ 1024 ];
int min, tens, sec;
sec = (level.time - level.startTime) / 1000;
min = sec / 60;
sec -= min * 60;
tens = sec / 10;
sec -= tens * 10;
Com_sprintf( string, sizeof( string ), "%3i:%i%i ", min, tens, sec );
va_start( argptr, fmt );
vsprintf( string +7 , fmt,argptr );
va_end( argptr );
if( g_dedicated.integer )
G_Printf( "%s", string + 7 );
if( !level.logFile )
return;
trap_FS_Write( string, strlen( string ), level.logFile );
}
/*
=================
G_LogOnlyPrintf
Print to the logfile only (not console) with a time stamp if it is open
=================
*/
void QDECL G_LogOnlyPrintf( const char *fmt, ... )
{
va_list argptr;
char string[ 1024 ], decoloured[ 1024 ];
int min, tens, sec;
sec = (level.time - level.startTime) / 1000;
min = sec / 60;
sec -= min * 60;
tens = sec / 10;
sec -= tens * 10;
Com_sprintf( string, sizeof( string ), "%3i:%i%i ", min, tens, sec );
va_start( argptr, fmt );
vsprintf( string +7 , fmt,argptr );
va_end( argptr );
if( !level.logFile )
return;
if( g_decolourLogfiles.integer )
{
G_DecolorString( string, decoloured );
trap_FS_Write( decoloured, strlen( decoloured ), level.logFile );
}
else
{
trap_FS_Write( string, strlen( string ), level.logFile );
}
}
/*
=================
G_SendGameStat
=================
*/
void G_SendGameStat( pTeam_t team )
{
char map[ MAX_STRING_CHARS ];
char teamChar;
char data[ BIG_INFO_STRING ];
char entry[ MAX_STRING_CHARS ];
int i, dataLength, entryLength;
gclient_t *cl;
trap_Cvar_VariableStringBuffer( "mapname", map, sizeof( map ) );
switch( team )
{
case PTE_ALIENS: teamChar = 'A'; break;
case PTE_HUMANS: teamChar = 'H'; break;
case PTE_NONE: teamChar = 'L'; break;
default: return;
}
Com_sprintf( data, BIG_INFO_STRING,
"%s %s T:%c A:%f H:%f M:%s D:%d SD:%d AS:%d AS2T:%d AS3T:%d HS:%d HS2T:%d HS3T:%d CL:%d",
Q3_VERSION,
g_tag.string,
teamChar,
level.averageNumAlienClients,
level.averageNumHumanClients,
map,
level.time - level.startTime,
G_TimeTilSuddenDeath( ),
g_alienStage.integer,
level.alienStage2Time - level.startTime,
level.alienStage3Time - level.startTime,
g_humanStage.integer,
level.humanStage2Time - level.startTime,
level.humanStage3Time - level.startTime,
level.numConnectedClients );
dataLength = strlen( data );
for( i = 0; i < level.numConnectedClients; i++ )
{
int ping;
cl = &level.clients[ level.sortedClients[ i ] ];
// Ignore invisible players
if ( cl->sess.invisible == qtrue )
continue;
if( cl->pers.connected == CON_CONNECTING )
ping = -1;
else
ping = cl->ps.ping < 999 ? cl->ps.ping : 999;
switch( cl->ps.stats[ STAT_PTEAM ] )
{
case PTE_ALIENS: teamChar = 'A'; break;
case PTE_HUMANS: teamChar = 'H'; break;
case PTE_NONE: teamChar = 'S'; break;
default: return;
}
Com_sprintf( entry, MAX_STRING_CHARS,
" \"%s\" %c %d %d %d",
cl->pers.netname,
teamChar,
cl->ps.persistant[ PERS_SCORE ],
ping,
( level.time - cl->pers.enterTime ) / 60000 );
entryLength = strlen( entry );
if( dataLength + entryLength >= BIG_INFO_STRING )
break;
strcpy( data + dataLength, entry );
dataLength += entryLength;
}
trap_SendGameStat( data );
}
/*
================
LogExit
Append information about this game to the log file
================
*/
void LogExit( const char *string )
{
int i, numSorted;
gclient_t *cl;
gentity_t *ent;
G_LogPrintf( "Exit: %s\n", string );
level.intermissionQueued = level.time;
// this will keep the clients from playing any voice sounds
// that will get cut off when the queued intermission starts
trap_SetConfigstring( CS_INTERMISSION, "1" );
// don't send more than 32 scores (FIXME?)
numSorted = level.numConnectedClients;
if( numSorted > 32 )
numSorted = 32;
for( i = 0; i < numSorted; i++ )
{
int ping;
cl = &level.clients[ level.sortedClients[ i ] ];
if( cl->ps.stats[ STAT_PTEAM ] == PTE_NONE )
continue;
if( cl->pers.connected == CON_CONNECTING )
continue;
ping = cl->ps.ping < 999 ? cl->ps.ping : 999;
G_LogPrintf( "score: %i ping: %i client: %i %s\n",
cl->ps.persistant[ PERS_SCORE ], ping, level.sortedClients[ i ],
cl->pers.netname );
}
for( i = 1, ent = g_entities + i ; i < level.num_entities ; i++, ent++ )
{
if( !ent->inuse )
continue;
if( !Q_stricmp( ent->classname, "trigger_win" ) )
{
if( level.lastWin == ent->stageTeam )
ent->use( ent, ent, ent );
}
}
G_SendGameStat( level.lastWin );
}
/*
=================
CheckIntermissionExit
The level will stay at the intermission for a minimum of 5 seconds
If all players wish to continue, the level will then exit.
If one or more players have not acknowledged the continue, the game will
wait 10 seconds before going on.
=================
*/
void CheckIntermissionExit( void )
{
int ready, notReady, numPlayers;
int i;
gclient_t *cl;
int readyMask;
//if no clients are connected, just exit
if( !level.numConnectedClients )
{
ExitLevel( );
return;
}
// map vote started
if( level.mapRotationVoteTime )
{
ExitLevel( );
return;
}
// see which players are ready
ready = 0;
notReady = 0;
readyMask = 0;
numPlayers = 0;
for( i = 0; i < g_maxclients.integer; i++ )
{
cl = level.clients + i;
if( cl->pers.connected != CON_CONNECTED )
continue;
if( cl->ps.stats[ STAT_PTEAM ] == PTE_NONE )
continue;
if( cl->readyToExit )
{
ready++;
if( i < 16 )
readyMask |= 1 << i;
}
else
notReady++;
numPlayers++;
}
trap_SetConfigstring( CS_CLIENTS_READY, va( "%d", readyMask ) );
// never exit in less than five seconds
if( level.time < level.intermissiontime + 5000 )
return;
// never let intermission go on for over 1 minute
if( level.time > level.intermissiontime + 60000 )
{
ExitLevel( );
return;
}
// if nobody wants to go, clear timer
if( !ready && numPlayers )
{
level.readyToExit = qfalse;
return;
}
// if everyone wants to go, go now
if( !notReady )
{
ExitLevel( );
return;
}
// if only a percent is needed to ready, check for it
if( g_readyPercent.integer && numPlayers &&
ready * 100 / numPlayers >= g_readyPercent.integer )
{
ExitLevel( );
return;
}
// the first person to ready starts the thirty second timeout
if( !level.readyToExit )
{
level.readyToExit = qtrue;
level.exitTime = level.time;
}
// if we have waited thirty seconds since at least one player
// wanted to exit, go ahead
if( level.time < level.exitTime + 30000 )
return;
ExitLevel( );
}
/*
=============
ScoreIsTied
=============
*/
qboolean ScoreIsTied( void )
{
int a, b;
if( level.numPlayingClients < 2 )
return qfalse;
a = level.clients[ level.sortedClients[ 0 ] ].ps.persistant[ PERS_SCORE ];
b = level.clients[ level.sortedClients[ 1 ] ].ps.persistant[ PERS_SCORE ];
return a == b;
}
/*
=================
CheckExitRules
There will be a delay between the time the exit is qualified for
and the time everyone is moved to the intermission spot, so you
can see the last frag.
=================
*/
void CheckExitRules( void )
{
// if at the intermission, wait for all non-bots to
// signal ready, then go to next level
if( level.intermissiontime )
{
CheckIntermissionExit( );
return;
}
if( level.intermissionQueued )
{
if( level.time - level.intermissionQueued >= INTERMISSION_DELAY_TIME )
{
level.intermissionQueued = 0;
BeginIntermission( );
}
return;
}
if( g_timelimit.integer )
{
if( level.time - level.startTime >= g_timelimit.integer * 60000 )
{
level.lastWin = PTE_NONE;
trap_SendServerCommand( -1, "print \"Timelimit hit\n\"" );
trap_SetConfigstring( CS_WINNER, "Stalemate" );
LogExit( "Timelimit hit." );
G_admin_maplog_result( "t" );
return;
}
else if( level.time - level.startTime >= ( g_timelimit.integer - 5 ) * 60000 &&
level.timelimitWarning < TW_IMMINENT )
{
trap_SendServerCommand( -1, "cp \"5 minutes remaining!\"" );
level.timelimitWarning = TW_IMMINENT;
}
else if( level.time - level.startTime >= ( g_timelimit.integer - 1 ) * 60000 &&
level.timelimitWarning < TW_PASSED )
{
trap_SendServerCommand( -1, "cp \"1 minute remaining!\"" );
level.timelimitWarning = TW_PASSED;
}
}
if( level.uncondHumanWin ||
( ( level.time > level.startTime + 1000 ) &&
( level.numAlienSpawns == 0 ) &&
( level.numLiveAlienClients == 0 ) ) )
{
//humans win
level.lastWin = PTE_HUMANS;
trap_SendServerCommand( -1, "print \"Humans win\n\"");
trap_SetConfigstring( CS_WINNER, "Humans Win" );
LogExit( "Humans win." );
G_admin_maplog_result( "h" );
}
else if( level.uncondAlienWin ||
( ( level.time > level.startTime + 1000 ) &&
( level.numHumanSpawns == 0 ) &&
( level.numLiveHumanClients == 0 ) ) )
{
//aliens win
level.lastWin = PTE_ALIENS;
trap_SendServerCommand( -1, "print \"Aliens win\n\"");
trap_SetConfigstring( CS_WINNER, "Aliens Win" );
LogExit( "Aliens win." );
G_admin_maplog_result( "a" );
}
}
/*
========================================================================
FUNCTIONS CALLED EVERY FRAME
========================================================================
*/
/*
==================
CheckVote
==================
*/
void CheckVote( void )
{
int votePassThreshold=level.votePassThreshold;
int voteYesPercent;
int minVotes = 0;
qboolean pass = qfalse;
if( level.voteExecuteTime && level.voteExecuteTime < level.time )
{
level.voteExecuteTime = 0;
if( !Q_stricmp( level.voteString, "map_restart" ) )
{
G_admin_maplog_result( "r" );
}
else if( !Q_stricmpn( level.voteString, "map", 3 ) )
{
G_admin_maplog_result( "m" );
}
else if( !Q_stricmpn( level.voteString, "!restart", 8 ) )
{
G_admin_maplog_result( "l" );
}
if( !Q_stricmp( level.voteString, "suddendeath" ) )
{
level.suddenDeathBeginTime = level.time + ( 1000 * g_suddenDeathVoteDelay.integer ) - level.startTime;
level.voteString[0] = '\0';
if( g_suddenDeathVoteDelay.integer )
trap_SendServerCommand( -1, va("cp \"Sudden Death will begin in %d seconds\n\"", g_suddenDeathVoteDelay.integer ) );
}
if( level.voteString[0] )
trap_SendConsoleCommand( EXEC_APPEND, va( "%s\n", level.voteString ) );
if( !Q_stricmp( level.voteString, "map_restart" ) ||
!Q_stricmpn( level.voteString, "map", 3 ) )
{
level.restarted = qtrue;
}
}
if( !level.voteTime )
return;
if( !Q_stricmpn( level.voteString, "ban", 3 ) )
{
minVotes = 3;
if( level.numConnectedClients < minVotes )
minVotes = level.numConnectedClients;
}
if( level.voteYes + level.voteNo > 0 )
voteYesPercent = (int)( 100 * ( level.voteYes ) / ( level.voteYes + level.voteNo ) );
else
voteYesPercent = 0;
if( ( level.time - level.voteTime >= VOTE_TIME ) ||
( level.voteYes + level.voteNo == level.numConnectedClients ) )
{
if( level.voteYes + level.voteNo < minVotes )
{
// not enough voters
trap_SendServerCommand( -1, va( "print \"This vote type requires at least %d voters\n\"", minVotes ) );
pass = qfalse;
}
else if( voteYesPercent > votePassThreshold )
{
// execute the command, then remove the vote
level.voteExecuteTime = level.time + 3000;
pass = qtrue;
}
else
{
// same behavior as a timeout
pass = qfalse;
}
}
else
{
if( level.voteYes > (int)( (double) level.numConnectedClients *
( (double) votePassThreshold/100.0 ) ) )
{
// execute the command, then remove the vote
level.voteExecuteTime = level.time + 3000;
pass = qtrue;
}
else if( level.voteNo > (int)( (double) level.numConnectedClients *
( (double) ( 100.0-votePassThreshold )/ 100.0 ) ) )
{
// same behavior as a timeout
pass = qfalse;
}
else
{
// still waiting for a majority
return;
}
}
trap_SendServerCommand( -1,
va( "print \"Vote %s^7 (^2Y:%d^7-^1N:%d^7, %d percent) (%s)\n\"",
( pass ) ? "^2passed" : "^1failed",
level.voteYes, level.voteNo, voteYesPercent,
level.voteDisplayString ) );
G_LogPrintf( "Vote: Vote %s (%d - %d)\n",
( pass ) ? "passed" : "failed",
level.voteYes, level.voteNo );
G_admin_adminlog_log( NULL, "vote",
va( "%s^7 (^2Y:%d^7-^1N:%d^7, %d percent)",
( pass ) ? "^2passed" : "^1failed",
level.voteYes, level.voteNo, voteYesPercent ),
0, pass );
level.voteTime = 0;
trap_SetConfigstring( CS_VOTE_TIME, "" );
trap_SetConfigstring( CS_VOTE_STRING, "" );
}
/*
==================
CheckTeamVote
==================
*/
void CheckTeamVote( int team )
{
int cs_offset;
int votePassThreshold;
int voteYesPercent = 0;
qboolean pass = qfalse;
if ( team == PTE_HUMANS )
cs_offset = 0;
else if ( team == PTE_ALIENS )
cs_offset = 1;
else
return;
votePassThreshold = level.teamVotePassThreshold[ cs_offset ];
if( !level.teamVoteTime[ cs_offset ] )
return;
if( ( level.teamVoteYes[ cs_offset ] + level.teamVoteNo[ cs_offset ] ) )
{
voteYesPercent = (100 * level.teamVoteYes[ cs_offset ]) /
(level.teamVoteYes[ cs_offset ] + level.teamVoteNo[ cs_offset ]);
}
if( level.time - level.teamVoteTime[ cs_offset ] >= VOTE_TIME )
{
if( voteYesPercent > votePassThreshold && level.teamVoteYes[ cs_offset ] >= 2 )
{
// execute the command, then remove the vote
trap_SendConsoleCommand( EXEC_APPEND, va( "%s\n", level.teamVoteString[ cs_offset ] ) );
pass = qtrue;
}
else
{
pass = qfalse;
}
}
else
{
if( level.teamVoteYes[ cs_offset ] > (int)((double)level.numteamVotingClients[ cs_offset ] *
(double)votePassThreshold/100.0) )
{
// execute the command, then remove the vote
trap_SendConsoleCommand( EXEC_APPEND, va( "%s\n", level.teamVoteString[ cs_offset ] ) );
pass = qtrue;
}
else if( level.teamVoteNo[ cs_offset ] > (int)((double)level.numteamVotingClients[ cs_offset ] *
((double)(100.0-votePassThreshold)/100.0)) )
{
// same behavior as a timeout
pass = qfalse;
}
else
{
// still waiting for a majority
return;
}
}
trap_SendServerCommand( -1,
va( "print \"Team vote %s^7 (^2Y:%d^7-^1N:%d^7, %d percent)\n\"",
( pass ) ? "^2passed" : "^1failed",
level.teamVoteYes[ cs_offset ], level.teamVoteNo[ cs_offset ], voteYesPercent ) );
G_LogPrintf( "Teamvote: Team vote %s (%d - %d)\n",
( pass ) ? "passed" : "failed",
level.teamVoteYes[ cs_offset ], level.teamVoteNo[ cs_offset ] );
G_admin_adminlog_log( NULL, "teamvote",
va( "%s^7 (^2Y:%d^7-^1N:%d^7, %d percent)",
( pass ) ? "^2passed" : "^1failed",
level.teamVoteYes[ cs_offset ], level.teamVoteNo[ cs_offset ], voteYesPercent ),
0, pass );
level.teamVoteTime[ cs_offset ] = 0;
trap_SetConfigstring( CS_TEAMVOTE_TIME + cs_offset, "" );
trap_SetConfigstring( CS_TEAMVOTE_STRING + cs_offset, "" );
}
/*
==================
CheckIdleMap
==================
*/
void CheckIdleMap( void )
{
static int nextCheck = 0;
static int idleCount = 0;
static qboolean triggered = qfalse;
if( !g_idleMapSwitch.integer )
return;
if( triggered ||
nextCheck > level.time )
return;
nextCheck = level.time + 60000;
if( !level.numPlayingClients )
idleCount++;
else
idleCount = 0;
if( idleCount > g_idleMapSwitch.integer &&
!G_CurrentMapIsRotation() )
{
int newTL;
triggered = qtrue;
newTL = ( level.time - level.startTime ) / 60000;
newTL += 5;
if( !g_timelimit.integer || g_timelimit.integer > newTL )
{
trap_Cvar_Set( "timelimit", va( "%d", newTL ) );
trap_SendServerCommand( -1, va( "print \"Timelimit reduced due to idle server\n\"" ) );
G_LogPrintf( "Server is idle, timelimit reduced to %d\n", newTL );
}
}
}
/*
==================
CheckMsgTimer
==================
*/
void CheckMsgTimer( void )
{
static int LastTime = 0;
if( level.time - LastTime < 1000 )
return;
LastTime = level.time;
if( level.mapRotationVoteTime )
{
G_IntermissionMapVoteMessageAll( );
return;
}
if( g_welcomeMsgTime.integer && g_welcomeMsg.string[ 0 ] )
{
char buffer[ MAX_STRING_CHARS ];
int wt;
int i;
buffer[ 0 ] = '\0';
wt = g_welcomeMsgTime.integer * 1000;
for( i = 0; i < level.maxclients; i++ )
{
if( level.clients[ i ].pers.connected != CON_CONNECTED )
continue;
if( level.time - level.clients[ i ].pers.enterTime < wt )
{
if( buffer[ 0 ] == '\0' )
{
Q_strncpyz( buffer, g_welcomeMsg.string, sizeof( buffer ) );
G_ParseEscapedString( buffer );
}
trap_SendServerCommand( i, va( "cp \"%s\"", buffer ) );
}
}
}
if( !g_msgTime.integer )
return;
if( level.time - level.lastMsgTime < abs( g_msgTime.integer ) * 60000 )
return;
// negative settings only print once per map
if( ( level.lastMsgTime ) && g_msgTime.integer < 0 )
return;
level.lastMsgTime = level.time;
if( g_msg.string[0] )
{
char buffer[ MAX_STRING_CHARS ];
Q_strncpyz( buffer, g_msg.string, sizeof( buffer ) );
G_ParseEscapedString( buffer );
trap_SendServerCommand( -1, va( "cp \"%s\"", buffer ) );
trap_SendServerCommand( -1, va( "print \"%s\n\"", buffer ) );
}
}
/*
==================
CheckCountdown
==================
*/
void CheckCountdown( void )
{
static int lastmsg = 0;
int timeleft = g_warmup.integer - ( level.time - level.startTime ) / 1000;
if( !g_doWarmup.integer || timeleft < 0 )
return;
if( level.time - lastmsg < 1000 )
return;
lastmsg = level.time;
if( timeleft > 0 )
trap_SendServerCommand( -1, va( "cp \"^1Warmup Time:^7\n^%i----- ^7%i ^%i-----\"", timeleft % 7, timeleft, timeleft % 7 ) );
else if( timeleft == 0 )
trap_SendServerCommand( -1, "cp \"^2----- GO! -----^7\"" );
}
/*
==================
G_CalculateDynamicBuildPoints
==================
*/
static void G_CalculateDynamicBuildPoints( void )
{
static int LastTime = 0;
int count = 0;
gentity_t *ent;
int bps;
int i;
if( !g_dynamicBuildPoints.integer )
return;
if( level.time - LastTime < 10000 )
return;
if( level.time - level.startTime < 30000 ||
!level.defaultAlienBuildPoints )
{
// remember default build points, after some time for exec commands
if( level.time - level.startTime > 1000 &&
level.defaultAlienBuildPoints == 0 )
{
level.defaultAlienBuildPoints = g_alienBuildPoints.integer;
level.defaultHumanBuildPoints = g_humanBuildPoints.integer;
}
return;
}
LastTime = level.time;
for( i = 0; i < level.maxclients; i++ )
{
ent = &g_entities[ i ];
if( ent && ent->client &&
ent->client->pers.connected == CON_CONNECTED &&
(ent->client->pers.teamSelection == PTE_ALIENS || ent->client->pers.teamSelection == PTE_HUMANS) )
{
count++;
}
}
bps = level.defaultAlienBuildPoints + count * g_dynamicBuildPoints.integer;
if( g_alienBuildPoints.integer < bps )
trap_Cvar_Set( "g_alienBuildPoints", va( "%d", bps ) );
bps = level.defaultHumanBuildPoints + count * g_dynamicBuildPoints.integer;
if( g_humanBuildPoints.integer < bps )
trap_Cvar_Set( "g_humanBuildPoints", va( "%d", bps ) );
}
/*
==================
CheckCvars
==================
*/
void CheckCvars( void )
{
static int lastPasswordModCount = -1;
static int lastMarkDeconModCount = -1;
static int lastSDTimeModCount = -1;
if( g_password.modificationCount != lastPasswordModCount )
{
lastPasswordModCount = g_password.modificationCount;
if( *g_password.string && Q_stricmp( g_password.string, "none" ) )
trap_Cvar_Set( "g_needpass", "1" );
else
trap_Cvar_Set( "g_needpass", "0" );
}
// Unmark any structures for deconstruction when
// the server setting is changed
if( g_markDeconstruct.modificationCount != lastMarkDeconModCount )
{
int i;
gentity_t *ent;
lastMarkDeconModCount = g_markDeconstruct.modificationCount;
for( i = 1, ent = g_entities + i ; i < level.num_entities ; i++, ent++ )
{
if( !ent->inuse )
continue;
if( ent->s.eType != ET_BUILDABLE )
continue;
ent->deconstruct = qfalse;
}
}
if( g_suddenDeathTime.modificationCount != lastSDTimeModCount )
{
lastSDTimeModCount = g_suddenDeathTime.modificationCount;
level.suddenDeathBeginTime = g_suddenDeathTime.integer * 60000;
}
level.frameMsec = trap_Milliseconds( );
}
/*
==================
G_CheckVampireDeathBuildables
==================
*/
static int G_VampireDeathKillBuildable( buildable_t buildable, int count )
{
int i;
gentity_t *ent;
int n = 0;
for ( i = 1, ent = g_entities + i; i < level.num_entities; i++, ent++ )
{
if( ent->s.eType != ET_BUILDABLE )
continue;
if( ent->s.modelindex == buildable && ent->health > 0 )
{
G_Damage( ent, NULL, NULL, NULL, NULL, 10000, 0, MOD_SUICIDE );
n++;
if( count && n >= count )
return n;
}
}
return n;
}
static void G_CheckVampireDeathBuildables( void )
{
static int LastAmmoTime = 0;
static int LastSuckTime = 0;
static int LastDestructTime = 0;
int i;
gentity_t *ent;
qboolean done = qtrue;
if( !level.vampireDeath )
return;
if( level.intermissionQueued ||
level.intermissiontime )
return;
// humans get more ammo every 20 seconds
if( level.time - LastAmmoTime >= 20000 )
{
LastAmmoTime = level.time;
for( i = 0; i < level.maxclients; i++ )
{
ent = g_entities + i;
if( !ent->inuse || ent->health <= 0 ||
ent->client->pers.connected != CON_CONNECTED)
continue;
if( ent->client->pers.teamSelection == PTE_HUMANS )
{
int maxClips, maxAmmo;
BG_FindAmmoForWeapon( ent->client->ps.weapon, &maxAmmo, &maxClips );
if( maxClips )
{
if( ent->client->ps.clips < maxClips )
ent->client->ps.clips++;
}
else
{
ent->client->ps.ammo += maxAmmo / 5;
if( ent->client->ps.ammo > maxAmmo )
ent->client->ps.ammo = maxAmmo;
}
}
}
}
// health countdown
if( level.time - LastSuckTime >= 3000 )
{
int value;
int hp_rate;
int damage;
LastSuckTime = level.time;
// increase health removal each minute after 1
hp_rate = 1 + ( level.time - level.vampireDeathBeginTime ) / 60000;
if( hp_rate < 1 ) hp_rate = 1;
if( hp_rate > 10) hp_rate = 10;
for( i = 0; i < level.maxclients; i++ )
{
ent = g_entities + i;
if( !ent->inuse ||
ent->health <= 0 ||
!ent->client ||
ent->client->pers.connected != CON_CONNECTED ||
ent->client->sess.sessionTeam == TEAM_SPECTATOR ||
( ent->client->pers.teamSelection != PTE_ALIENS && ent->client->pers.teamSelection != PTE_HUMANS ) )
continue;
value = BG_FindHealthForClass( ent->client->pers.classSelection );
if( value < 1 )
value = 1;
// death from full HP in 60s with damage every 3s, 1000 / 60 * 3 = 50
ent->client->pers.vampireSuckFraction += value * 50 * hp_rate;
damage = ent->client->pers.vampireSuckFraction / 1000;
ent->client->pers.vampireSuckFraction -= damage * 1000;
if ( ent->health > damage )
ent->health -= damage;
else
G_Damage( ent, NULL, NULL, NULL, NULL, damage,
DAMAGE_NO_ARMOR|DAMAGE_NO_KNOCKBACK|DAMAGE_NO_PROTECTION|DAMAGE_NO_LOCDAMAGE, MOD_SUICIDE );
}
}
// base self destruct
if( level.vampireDeath == 2 )
return;
if( level.time - LastDestructTime < 1000 )
return;
LastDestructTime = level.time;
if( level.numLiveAlienClients == 0 &&
level.numLiveHumanClients == 0 )
{
level.lastWin = PTE_NONE;
trap_SendServerCommand( -1, "print \"Timelimit hit\n\"" );
trap_SetConfigstring( CS_WINNER, "Stalemate" );
LogExit( "Timelimit hit." );
G_admin_maplog_result( "t" );
}
if( G_VampireDeathKillBuildable( BA_A_ACIDTUBE, 1 ) ||
G_VampireDeathKillBuildable( BA_A_HIVE, 1 ) ||
G_VampireDeathKillBuildable( BA_A_TRAPPER, 1 ) ||
G_VampireDeathKillBuildable( BA_A_BARRICADE, 1 ) ||
G_VampireDeathKillBuildable( BA_A_BOOSTER, 1 ) ||
G_VampireDeathKillBuildable( BA_A_SPAWN, 1 ) ||
G_VampireDeathKillBuildable( BA_A_OVERMIND, 1 ) )
{
done = qfalse;
}
if( G_VampireDeathKillBuildable( BA_H_MGTURRET, 1 ) ||
G_VampireDeathKillBuildable( BA_H_TESLAGEN, 1 ) ||
G_VampireDeathKillBuildable( BA_H_DCC, 1 ) ||
G_VampireDeathKillBuildable( BA_H_REPEATER, 1 ) ||
G_VampireDeathKillBuildable( BA_H_MEDISTAT, 1 ) ||
G_VampireDeathKillBuildable( BA_H_ARMOURY, 1 ) ||
G_VampireDeathKillBuildable( BA_H_SPAWN, 1 ) ||
G_VampireDeathKillBuildable( BA_H_REACTOR, 1 ) )
{
done = qfalse;
}
if( done )
{
level.vampireDeath = 2;
}
}
/*
=============
G_RunThink
Runs thinking code for this frame if necessary
=============
*/
void G_RunThink( gentity_t *ent )
{
float thinktime;
thinktime = ent->nextthink;
if( thinktime <= 0 )
return;
if( thinktime > level.time )
return;
ent->nextthink = 0;
if( !ent->think )
G_Error( "NULL ent->think" );
ent->think( ent );
}
/*
=============
G_EvaluateAcceleration
Calculates the acceleration for an entity
=============
*/
void G_EvaluateAcceleration( gentity_t *ent, int msec )
{
vec3_t deltaVelocity;
vec3_t deltaAccel;
VectorSubtract( ent->s.pos.trDelta, ent->oldVelocity, deltaVelocity );
VectorScale( deltaVelocity, 1.0f / (float)msec, ent->acceleration );
VectorSubtract( ent->acceleration, ent->oldAccel, deltaAccel );
VectorScale( deltaAccel, 1.0f / (float)msec, ent->jerk );
VectorCopy( ent->s.pos.trDelta, ent->oldVelocity );
VectorCopy( ent->acceleration, ent->oldAccel );
}
/*
================
G_RunFrame
Advances the non-player objects in the world
================
*/
void G_RunFrame( int levelTime )
{
int i;
gentity_t *ent;
int msec;
// if we are waiting for the level to restart, do nothing
if( level.restarted )
return;
if( level.paused )
{
if( ( levelTime % 6000 ) == 0)
trap_SendServerCommand( -1, "cp \"^3Game is paused.\"" );
level.startTime += levelTime - level.time;
trap_SetConfigstring( CS_LEVEL_START_TIME, va( "%i", level.startTime ) );
if( levelTime - level.pauseTime > 3 * 60000 )
{
trap_SendConsoleCommand( EXEC_APPEND, "!unpause" );
}
}
CheckMsgTimer( );
CheckCountdown( );
level.framenum++;
level.previousTime = level.time;
level.time = levelTime;
msec = level.time - level.previousTime;
//TA: seed the rng
srand( level.framenum );
// get any cvar changes
G_UpdateCvars( );
//
// go through all allocated objects
//
ent = &g_entities[ 0 ];
for( i = 0; i < level.num_entities; i++, ent++ )
{
if( !ent->inuse )
continue;
// clear events that are too old
if( level.time - ent->eventTime > EVENT_VALID_MSEC )
{
if( ent->s.event )
{
ent->s.event = 0; // &= EV_EVENT_BITS;
if ( ent->client )
{
ent->client->ps.externalEvent = 0;
//ent->client->ps.events[0] = 0;
//ent->client->ps.events[1] = 0;
}
}
if( ent->freeAfterEvent )
{
// tempEntities or dropped items completely go away after their event
G_FreeEntity( ent );
continue;
}
else if( ent->unlinkAfterEvent )
{
// items that will respawn will hide themselves after their pickup event
ent->unlinkAfterEvent = qfalse;
trap_UnlinkEntity( ent );
}
}
// temporary entities don't think
if( ent->freeAfterEvent )
continue;
//TA: calculate the acceleration of this entity
if( ent->evaluateAcceleration )
G_EvaluateAcceleration( ent, msec );
if( !ent->r.linked && ent->neverFree )
continue;
if( ent->s.eType == ET_MISSILE )
{
G_RunMissile( ent );
continue;
}
if( ent->s.eType == ET_BUILDABLE )
{
G_BuildableThink( ent, msec );
continue;
}
if( ent->s.eType == ET_CORPSE || ent->physicsObject )
{
G_Physics( ent, msec );
continue;
}
if( ent->s.eType == ET_MOVER )
{
G_RunMover( ent );
continue;
}
if( i < MAX_CLIENTS )
{
G_RunClient( ent );
continue;
}
G_RunThink( ent );
}
// perform final fixups on the players
ent = &g_entities[ 0 ];
for( i = 0; i < level.maxclients; i++, ent++ )
{
if( ent->inuse )
ClientEndFrame( ent );
}
G_CheckVampireDeathBuildables();
// save position information for all active clients
G_UnlaggedStore( );
//TA:
G_CountSpawns( );
G_CalculateBuildPoints( );
G_CalculateStages( );
G_SpawnClients( PTE_ALIENS );
G_SpawnClients( PTE_HUMANS );
G_CalculateAvgPlayers( );
G_UpdateZaps( msec );
G_CalculateDynamicBuildPoints( );
// see if it is time to end the level
CheckExitRules( );
CheckIdleMap( );
// update to team status?
CheckTeamStatus( );
// cancel vote if timed out
CheckVote( );
// check team votes
CheckTeamVote( PTE_HUMANS );
CheckTeamVote( PTE_ALIENS );
G_admin_schachtmeisterFrame();
// for tracking changes
CheckCvars( );
if( g_listEntity.integer )
{
for( i = 0; i < MAX_GENTITIES; i++ )
G_Printf( "%4i: %s\n", i, g_entities[ i ].classname );
trap_Cvar_Set( "g_listEntity", "0" );
}
}
|