forked from Unvanquished/Unvanquished
/
sg_main.cpp
2864 lines (2376 loc) · 85.2 KB
/
sg_main.cpp
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
/*
===========================================================================
Unvanquished GPL Source Code
Copyright (C) 1999-2005 Id Software, Inc.
Copyright (C) 2000-2009 Darklegion Development
This file is part of the Unvanquished GPL Source Code (Unvanquished Source Code).
Unvanquished 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.
Unvanquished 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 Unvanquished; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
#include "sg_local.h"
#include "Entities.h"
#include "CBSE.h"
#include "backend/CBSEBackend.h"
#define INTERMISSION_DELAY_TIME 1000
level_locals_t level;
namespace {
struct cvarTable_t
{
vmCvar_t *vmCvar;
const char *cvarName;
const char *defaultString;
int cvarFlags;
int modificationCount; // for tracking changes
bool trackChange; // track this variable, and announce if changed
/* certain cvars can be set in worldspawn, but we don't want those values to
persist, so keep track of non-worldspawn changes and restore that on map
end. unfortunately, if the server crashes, the value set in worldspawn may
persist */
char *explicit_;
};
} //namespace
gentity_t *g_entities;
gclient_t *g_clients;
vmCvar_t g_showHelpOnConnection;
vmCvar_t g_timelimit;
vmCvar_t g_friendlyFire;
vmCvar_t g_friendlyBuildableFire;
vmCvar_t g_dretchPunt;
vmCvar_t g_password;
vmCvar_t g_needpass;
vmCvar_t g_maxclients;
vmCvar_t g_maxGameClients;
vmCvar_t g_speed;
vmCvar_t g_gravity;
vmCvar_t g_cheats;
vmCvar_t g_inactivity;
vmCvar_t g_debugMove;
vmCvar_t g_debugDamage;
vmCvar_t g_debugKnockback;
vmCvar_t g_debugTurrets;
vmCvar_t g_debugFire;
vmCvar_t g_motd;
vmCvar_t g_synchronousClients;
vmCvar_t g_warmup;
vmCvar_t g_doWarmup;
vmCvar_t g_lockTeamsAtStart;
vmCvar_t g_mapRestarted;
vmCvar_t g_logFile;
vmCvar_t g_logGameplayStatsFrequency;
vmCvar_t g_logFileSync;
vmCvar_t g_allowVote;
vmCvar_t g_voteLimit;
vmCvar_t g_extendVotesPercent;
vmCvar_t g_extendVotesTime;
vmCvar_t g_kickVotesPercent;
vmCvar_t g_denyVotesPercent;
vmCvar_t g_mapVotesPercent;
vmCvar_t g_mapVotesBefore;
vmCvar_t g_drawVotesPercent;
vmCvar_t g_drawVotesAfter;
vmCvar_t g_drawVoteReasonRequired;
vmCvar_t g_admitDefeatVotesPercent;
vmCvar_t g_nextMapVotesPercent;
vmCvar_t g_pollVotesPercent;
vmCvar_t g_botKickVotesAllowed;
vmCvar_t g_botKickVotesAllowedThisMap;
vmCvar_t g_teamForceBalance;
vmCvar_t g_smoothClients;
vmCvar_t pmove_fixed;
vmCvar_t pmove_msec;
vmCvar_t pmove_accurate;
vmCvar_t g_minNameChangePeriod;
vmCvar_t g_maxNameChanges;
Cvar::Callback<Cvar::Cvar<int>> g_buildPointInitialBudget(
"g_BPInitialBudget",
"Initial Budget",
Cvar::SERVERINFO,
DEFAULT_BP_INITIAL_BUDGET,
[](int) {
G_UpdateBuildPointBudgets();
});
Cvar::Callback<Cvar::Cvar<int>> g_buildPointBudgetPerMiner(
"g_BPBudgetPerMiner",
"Budget per Miner",
Cvar::SERVERINFO,
DEFAULT_BP_BUDGET_PER_MINER,
[](int) {
G_UpdateBuildPointBudgets();
});
vmCvar_t g_buildPointRecoveryInititalRate;
vmCvar_t g_buildPointRecoveryRateHalfLife;
vmCvar_t g_debugMomentum;
vmCvar_t g_momentumHalfLife;
vmCvar_t g_momentumRewardDoubleTime;
vmCvar_t g_unlockableMinTime;
vmCvar_t g_momentumBaseMod;
vmCvar_t g_momentumKillMod;
vmCvar_t g_momentumBuildMod;
vmCvar_t g_momentumDeconMod;
vmCvar_t g_momentumDestroyMod;
vmCvar_t g_humanAllowBuilding;
vmCvar_t g_alienAllowBuilding;
vmCvar_t g_alienOffCreepRegenHalfLife;
vmCvar_t g_teamImbalanceWarnings;
vmCvar_t g_freeFundPeriod;
vmCvar_t g_unlagged;
vmCvar_t g_disabledEquipment;
vmCvar_t g_disabledClasses;
vmCvar_t g_disabledBuildables;
vmCvar_t g_disabledVoteCalls;
vmCvar_t g_debugMapRotation;
vmCvar_t g_currentMapRotation;
vmCvar_t g_mapRotationNodes;
vmCvar_t g_mapRotationStack;
vmCvar_t g_nextMap;
vmCvar_t g_nextMapLayouts;
vmCvar_t g_initialMapRotation;
vmCvar_t g_mapLog;
vmCvar_t g_mapStartupMessageDelay;
vmCvar_t g_debugVoices;
vmCvar_t g_enableVsays;
vmCvar_t g_shove;
vmCvar_t g_antiSpawnBlock;
vmCvar_t g_mapConfigs;
vmCvar_t g_sayAreaRange;
vmCvar_t g_floodMaxDemerits;
vmCvar_t g_floodMinTime;
vmCvar_t g_defaultLayouts;
vmCvar_t g_layouts;
vmCvar_t g_layoutAuto;
vmCvar_t g_emoticonsAllowedInNames;
vmCvar_t g_unnamedNumbering;
vmCvar_t g_unnamedNamePrefix;
vmCvar_t g_admin;
vmCvar_t g_adminWarn;
vmCvar_t g_adminTempBan;
vmCvar_t g_adminMaxBan;
vmCvar_t g_adminRetainExpiredBans;
vmCvar_t g_privateMessages;
vmCvar_t g_specChat;
vmCvar_t g_publicAdminMessages;
vmCvar_t g_allowTeamOverlay;
vmCvar_t g_tag;
vmCvar_t g_showKillerHP;
vmCvar_t g_combatCooldown;
vmCvar_t g_geoip;
vmCvar_t g_debugEntities;
vmCvar_t g_instantBuilding;
vmCvar_t g_emptyTeamsSkipMapTime;
Cvar::Cvar<bool> g_neverEnd("g_neverEnd", "cheat to never end a game, helpful to load a map without spawn for testing purpose", Cvar::NONE, false);
Cvar::Cvar<float> g_evolveAroundHumans("g_evolveAroundHumans", "Ratio of alien buildings to human entities that always allow evolution", Cvar::NONE, 1.5f);
Cvar::Cvar<float> g_devolveMaxBaseDistance("g_devolveMaxBaseDistance", "Max Overmind distance to allow devolving", Cvar::NONE, 1000.0f);
// <bot stuff>
// bot buy cvars
vmCvar_t g_bot_buy;
vmCvar_t g_bot_rifle;
vmCvar_t g_bot_painsaw;
vmCvar_t g_bot_shotgun;
vmCvar_t g_bot_lasgun;
vmCvar_t g_bot_mdriver;
vmCvar_t g_bot_chaingun;
vmCvar_t g_bot_prifle;
vmCvar_t g_bot_flamer;
vmCvar_t g_bot_lcannon;
// bot evolution cvars
vmCvar_t g_bot_evolve;
vmCvar_t g_bot_level1;
vmCvar_t g_bot_level2;
vmCvar_t g_bot_level2upg;
vmCvar_t g_bot_level3;
vmCvar_t g_bot_level3upg;
vmCvar_t g_bot_level4;
// misc bot cvars
vmCvar_t g_bot_attackStruct;
vmCvar_t g_bot_roam;
vmCvar_t g_bot_rush;
vmCvar_t g_bot_repair;
vmCvar_t g_bot_build;
vmCvar_t g_bot_retreat;
vmCvar_t g_bot_fov;
vmCvar_t g_bot_chasetime;
vmCvar_t g_bot_reactiontime;
vmCvar_t g_bot_infinite_funds;
vmCvar_t g_bot_numInGroup;
vmCvar_t g_bot_persistent;
vmCvar_t g_bot_debug;
vmCvar_t g_bot_buildLayout;
//</bot stuff>
// copy cvars that can be set in worldspawn so they can be restored later
static char cv_gravity[ MAX_CVAR_VALUE_STRING ];
static cvarTable_t gameCvarTable[] =
{
// special purpose (external source, read only, etc.)
// TODO: Split and comment this section
{ nullptr, "gamename", GAME_VERSION, CVAR_SERVERINFO | CVAR_ROM, 0, false , nullptr },
{ nullptr, "gamedate", __DATE__, CVAR_ROM, 0, false , nullptr },
{ nullptr, "sv_mapname", "", CVAR_SERVERINFO, 0, false , nullptr },
{ nullptr, "P", "", CVAR_SERVERINFO, 0, false , nullptr },
{ nullptr, "B", "", CVAR_SERVERINFO, 0, false , nullptr },
{ nullptr, "g_mapStartupMessage", "", 0, 0, false , nullptr },
{ nullptr, "g_mapConfigsLoaded", "0", 0, 0, false , nullptr },
{ &g_maxclients, "sv_maxclients", "24", CVAR_SERVERINFO | CVAR_LATCH, 0, false , nullptr },
{ &g_mapRestarted, "g_mapRestarted", "0", 0, 0, false , nullptr },
{ &g_lockTeamsAtStart, "g_lockTeamsAtStart", "0", 0, 0, false , nullptr },
{ &g_tag, "g_tag", "unv", CVAR_INIT, 0, false , nullptr },
// server: basic
{ &g_maxGameClients, "g_maxGameClients", "0", CVAR_SERVERINFO, 0, false , nullptr },
{ &g_needpass, "g_needpass", "0", CVAR_SERVERINFO, 0, false , nullptr },
{ &g_password, "g_password", "", CVAR_USERINFO, 0, false , nullptr },
{ &g_motd, "g_motd", "", 0, 0, false , nullptr },
{ &g_showHelpOnConnection, "g_showHelpOnConnection", "1", 0, 0, false , nullptr },
// server: network related
{ &g_unlagged, "g_unlagged", "1", CVAR_SERVERINFO, 0, true , nullptr },
{ &g_smoothClients, "g_smoothClients", "1", 0, 0, false , nullptr },
{ &g_synchronousClients, "g_synchronousClients", "0", 0, 0, false , nullptr },
{ &pmove_fixed, "pmove_fixed", "0", 0, 0, false , nullptr },
{ &pmove_msec, "pmove_msec", "8", 0, 0, false , nullptr },
{ &pmove_accurate, "pmove_accurate", "1", 0, 0, false , nullptr },
{ &g_floodMaxDemerits, "g_floodMaxDemerits", "5000", 0, 0, false , nullptr },
{ &g_floodMinTime, "g_floodMinTime", "2000", 0, 0, false , nullptr },
// clients: limits
{ &g_minNameChangePeriod, "g_minNameChangePeriod", "5", 0, 0, false , nullptr },
{ &g_maxNameChanges, "g_maxNameChanges", "5", 0, 0, false , nullptr },
{ &g_enableVsays, "g_voiceChats", "1", 0, 0, false , nullptr },
{ &g_inactivity, "g_inactivity", "0", 0, 0, true , nullptr },
{ &g_emoticonsAllowedInNames, "g_emoticonsAllowedInNames", "1", CVAR_LATCH, 0, false , nullptr },
{ &g_privateMessages, "g_privateMessages", "1", 0, 0, false , nullptr },
{ &g_specChat, "g_specChat", "1", 0, 0, false , nullptr },
// clients: voting
{ &g_allowVote, "g_allowVote", "1", 0, 0, false , nullptr },
{ &g_voteLimit, "g_voteLimit", "5", 0, 0, false , nullptr },
{ &g_disabledVoteCalls, "g_disabledVoteCalls", "", 0, 0, false , nullptr },
{ &g_extendVotesPercent, "g_extendVotesPercent", "74", 0, 0, false , nullptr },
{ &g_extendVotesTime, "g_extendVotesTime", "10", 0, 0, false , nullptr },
{ &g_kickVotesPercent, "g_kickVotesPercent", "51", 0, 0, true , nullptr },
{ &g_denyVotesPercent, "g_denyVotesPercent", "51", 0, 0, true , nullptr },
{ &g_mapVotesPercent, "g_mapVotesPercent", "51", 0, 0, true , nullptr },
{ &g_mapVotesBefore, "g_mapVotesBefore", "5", 0, 0, true , nullptr },
{ &g_nextMapVotesPercent, "g_nextMapVotesPercent", "51", 0, 0, true , nullptr },
{ &g_drawVotesPercent, "g_drawVotesPercent", "51", 0, 0, true , nullptr },
{ &g_drawVotesAfter, "g_drawVotesAfter", "0", 0, 0, true , nullptr },
{ &g_drawVoteReasonRequired, "g_drawVoteReasonRequired", "0", 0, 0, true , nullptr },
{ &g_admitDefeatVotesPercent, "g_admitDefeatVotesPercent", "74", 0, 0, true , nullptr },
{ &g_pollVotesPercent, "g_pollVotesPercent", "0", 0, 0, true , nullptr },
{ &g_botKickVotesAllowed, "g_botKickVotesAllowed", "1", 0, 0, true , nullptr },
{ &g_botKickVotesAllowedThisMap, "g_botKickVotesAllowedThisMap", "1", 0, 0, true , nullptr },
// clients: misc
{ &g_geoip, "g_geoip", "1", 0, 0, false , nullptr },
{ &g_unnamedNumbering, "g_unnamedNumbering", "-1", 0, 0, false , nullptr },
{ &g_unnamedNamePrefix, "g_unnamedNamePrefix", UNNAMED_PLAYER"#", 0, 0, false , nullptr },
// admin system
{ &g_admin, "g_admin", "admin.dat", 0, 0, false , nullptr },
{ &g_adminWarn, "g_adminWarn", "1h", 0, 0, false , nullptr },
{ &g_adminTempBan, "g_adminTempBan", "2m", 0, 0, false , nullptr },
{ &g_adminMaxBan, "g_adminMaxBan", "2w", 0, 0, false , nullptr },
{ &g_adminRetainExpiredBans, "g_adminRetainExpiredBans", "1", 0, 0, false , nullptr },
{ &g_publicAdminMessages, "g_publicAdminMessages", "1", 0, 0, false , nullptr },
// logging
{ &g_logFile, "g_logFile", "games.log", 0, 0, false , nullptr },
{ &g_logGameplayStatsFrequency, "g_logGameplayStatsFrequency", "10", 0, 0, false , nullptr },
{ &g_logFileSync, "g_logFileSync", "0", 0, 0, false , nullptr },
// maps, layouts & rotation
{ &g_currentMapRotation, "g_currentMapRotation", "-1", 0, 0, false , nullptr },
{ &g_mapRotationNodes, "g_mapRotationNodes", "", 0, 0, false , nullptr },
{ &g_mapRotationStack, "g_mapRotationStack", "", 0, 0, false , nullptr },
{ &g_nextMap, "g_nextMap", "", 0, 0, true , nullptr },
{ &g_nextMapLayouts, "g_nextMapLayouts", "", 0, 0, true , nullptr },
{ &g_initialMapRotation, "g_initialMapRotation", "rotation1", 0, 0, false , nullptr },
{ &g_mapLog, "g_mapLog", "", 0, 0, false , nullptr },
{ &g_mapStartupMessageDelay, "g_mapStartupMessageDelay", "5000", CVAR_LATCH, 0, false , nullptr },
{ &g_mapConfigs, "g_mapConfigs", "", 0, 0, false , nullptr },
{ &g_defaultLayouts, "g_defaultLayouts", "", CVAR_LATCH, 0, false , nullptr },
{ &g_layouts, "g_layouts", "", CVAR_LATCH, 0, false , nullptr },
{ &g_layoutAuto, "g_layoutAuto", "0", 0, 0, false , nullptr },
// debug switches
{ &g_debugMove, "g_debugMove", "0", 0, 0, false , nullptr },
{ &g_debugDamage, "g_debugDamage", "0", 0, 0, false , nullptr },
{ &g_debugKnockback, "g_debugKnockback", "0", 0, 0, false , nullptr },
{ &g_debugTurrets, "g_debugTurrets", "0", 0, 0, false , nullptr },
{ &g_debugMomentum, "g_debugMomentum", "0", 0, 0, false , nullptr },
{ &g_debugMapRotation, "g_debugMapRotation", "0", 0, 0, false , nullptr },
{ &g_debugVoices, "g_debugVoices", "0", 0, 0, false , nullptr },
{ &g_debugEntities, "g_debugEntities", "0", 0, 0, false , nullptr },
{ &g_debugFire, "g_debugFire", "0", 0, 0, false , nullptr },
// gameplay: basic
{ &g_timelimit, "timelimit", "45", CVAR_SERVERINFO, 0, true , nullptr },
{ &g_friendlyFire, "g_friendlyFire", "1", CVAR_SERVERINFO, 0, true , nullptr },
{ &g_friendlyBuildableFire, "g_friendlyBuildableFire", "1", CVAR_SERVERINFO, 0, true , nullptr },
// gameplay: team balance
{ &g_teamForceBalance, "g_teamForceBalance", "0", 0, 0, true , nullptr },
{ &g_teamImbalanceWarnings, "g_teamImbalanceWarnings", "30", 0, 0, false , nullptr },
{ &g_warmup, "g_warmup", "10", 0, 0, true , nullptr },
{ &g_doWarmup, "g_doWarmup", "0", 0, 0, true , nullptr },
// gameplay: mining
{ &g_buildPointRecoveryInititalRate, "g_BPRecoveryInitialRate", DEFAULT_BP_RECOVERY_INITIAL_RATE, CVAR_SERVERINFO, 0, false , nullptr },
{ &g_buildPointRecoveryRateHalfLife, "g_BPRecoveryRateHalfLife", DEFAULT_BP_RECOVERY_RATE_HALF_LIFE, CVAR_SERVERINFO, 0, false , nullptr },
// gameplay: momentum
{ &g_unlockableMinTime, "g_unlockableMinTime", DEFAULT_UNLOCKABLE_MIN_TIME, CVAR_SERVERINFO, 0, false , nullptr },
{ &g_momentumHalfLife, "g_momentumHalfLife", DEFAULT_MOMENTUM_HALF_LIFE, CVAR_SERVERINFO, 0, false , nullptr },
{ &g_momentumRewardDoubleTime, "g_momentumRewardDoubleTime", DEFAULT_CONF_REWARD_DOUBLE_TIME, 0, 0, false , nullptr },
{ &g_momentumBaseMod, "g_momentumBaseMod", DEFAULT_MOMENTUM_BASE_MOD, 0, 0, false , nullptr },
{ &g_momentumKillMod, "g_momentumKillMod", DEFAULT_MOMENTUM_KILL_MOD, 0, 0, false , nullptr },
{ &g_momentumBuildMod, "g_momentumBuildMod", DEFAULT_MOMENTUM_BUILD_MOD, 0, 0, false , nullptr },
{ &g_momentumDeconMod, "g_momentumDeconMod", DEFAULT_MOMENTUM_DECON_MOD, 0, 0, false , nullptr },
{ &g_momentumDestroyMod, "g_momentumDestroyMod", DEFAULT_MOMENTUM_DESTROY_MOD, 0, 0, false , nullptr },
// gameplay: limits
{ &g_humanAllowBuilding, "g_humanAllowBuilding", "1", 0, 0, false , nullptr },
{ &g_alienAllowBuilding, "g_alienAllowBuilding", "1", 0, 0, false , nullptr },
{ &g_disabledEquipment, "g_disabledEquipment", "", CVAR_SYSTEMINFO, 0, false , nullptr },
{ &g_disabledClasses, "g_disabledClasses", "", CVAR_SYSTEMINFO, 0, false , nullptr },
{ &g_disabledBuildables, "g_disabledBuildables", "", CVAR_SYSTEMINFO, 0, false , nullptr },
// gameplay: misc
{ &g_alienOffCreepRegenHalfLife, "g_alienOffCreepRegenHalfLife", "0", 0, 0, false , nullptr },
{ &g_freeFundPeriod, "g_freeFundPeriod", DEFAULT_FREEKILL_PERIOD, 0, 0, true , nullptr },
{ &g_sayAreaRange, "g_sayAreaRange", "1000", 0, 0, true , nullptr },
{ &g_speed, "g_speed", "320", 0, 0, true , nullptr },
{ &g_gravity, "g_gravity", "800", 0, 0, true, cv_gravity},
{ &g_antiSpawnBlock, "g_antiSpawnBlock", "0", 0, 0, false , nullptr },
{ &g_shove, "g_shove", "0.0", 0, 0, false , nullptr },
{ &g_dretchPunt, "g_dretchPunt", "1", 0, 0, true , nullptr },
{ &g_allowTeamOverlay, "g_allowTeamOverlay", "1", 0, 0, true , nullptr },
{ &g_showKillerHP, "g_showKillerHP", "0", 0, 0, false , nullptr },
{ &g_combatCooldown, "g_combatCooldown", "15", 0, 0, false , nullptr },
{ &g_instantBuilding, "g_instantBuilding", "0", 0, 0, true , nullptr },
{ &g_emptyTeamsSkipMapTime, "g_emptyTeamsSkipMapTime", "0", 0, 0, true , nullptr },
// bots: buying
{ &g_bot_buy, "g_bot_buy", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_rifle, "g_bot_rifle", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_painsaw, "g_bot_painsaw", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_shotgun, "g_bot_shotgun", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_lasgun, "g_bot_lasgun", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_mdriver, "g_bot_mdriver", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_chaingun, "g_bot_chain", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_prifle, "g_bot_prifle", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_flamer, "g_bot_flamer", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_lcannon, "g_bot_lcannon", "1", CVAR_NORESTART, 0, false, nullptr },
// bots: evolution
{ &g_bot_evolve, "g_bot_evolve", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_level1, "g_bot_level1", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_level2, "g_bot_level2", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_level2upg, "g_bot_level2upg", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_level3, "g_bot_level3", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_level3upg, "g_bot_level3upg", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_level4, "g_bot_level4", "1", CVAR_NORESTART, 0, false, nullptr },
// bots: misc
{ &g_bot_attackStruct, "g_bot_attackStruct", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_roam, "g_bot_roam", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_rush, "g_bot_rush", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_repair, "g_bot_repair", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_build, "g_bot_build", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_retreat, "g_bot_retreat", "1", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_fov, "g_bot_fov", "125", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_chasetime, "g_bot_chasetime", "5000", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_reactiontime, "g_bot_reactiontime", "500", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_infinite_funds, "g_bot_infinite_funds", "0", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_numInGroup, "g_bot_numInGroup", "3", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_debug, "g_bot_debug", "0", CVAR_NORESTART, 0, false, nullptr },
{ &g_bot_buildLayout, "g_bot_buildLayout", "botbuild", CVAR_NORESTART, 0, false, nullptr }
};
static const size_t gameCvarTableSize = ARRAY_LEN( gameCvarTable );
void CheckExitRules();
static void G_LogGameplayStats( int state );
// state field of G_LogGameplayStats
enum
{
LOG_GAMEPLAY_STATS_HEADER,
LOG_GAMEPLAY_STATS_BODY,
LOG_GAMEPLAY_STATS_FOOTER
};
/*
================
G_FindEntityGroups
Chain together all entities with a matching groupName field.
Entity groups are used for item groups and multi-entity mover groups.
All but the first will have the FL_GROUPSLAVE flag set and groupMaster field set
All but the last will have the groupChain field set to the next one
================
*/
void G_FindEntityGroups()
{
gentity_t *masterEntity, *comparedEntity;
int i, j, k;
int groupCount, entityCount;
groupCount = 0;
entityCount = 0;
for ( i = MAX_CLIENTS, masterEntity = g_entities + i; i < level.num_entities; i++, masterEntity++ )
{
if ( !masterEntity->groupName )
{
continue;
}
if ( masterEntity->flags & FL_GROUPSLAVE )
{
continue;
}
masterEntity->groupMaster = masterEntity;
groupCount++;
entityCount++;
for ( j = i + 1, comparedEntity = masterEntity + 1; j < level.num_entities; j++, comparedEntity++ )
{
if ( !comparedEntity->groupName )
{
continue;
}
if ( comparedEntity->flags & FL_GROUPSLAVE )
{
continue;
}
if ( !strcmp( masterEntity->groupName, comparedEntity->groupName ) )
{
entityCount++;
comparedEntity->groupChain = masterEntity->groupChain;
masterEntity->groupChain = comparedEntity;
comparedEntity->groupMaster = masterEntity;
comparedEntity->flags |= FL_GROUPSLAVE;
// make sure that targets only point at the master
for (k = 0; comparedEntity->names[k]; k++)
{
masterEntity->names[k] = comparedEntity->names[k];
comparedEntity->names[k] = nullptr;
}
}
}
}
Log::Notice( "%i groups with %i entities", groupCount, entityCount );
}
/*
================
G_InitSetEntities
goes through all entities and concludes the spawn
by calling their reset function as initiation if available
================
*/
void G_InitSetEntities()
{
int i;
gentity_t *entity;
for ( i = MAX_CLIENTS, entity = g_entities + i; i < level.num_entities; i++, entity++ )
{
if(entity->inuse && entity->reset)
entity->reset( entity );
}
}
static int cvarCompare( const void *a, const void *b )
{
cvarTable_t *ac = ( cvarTable_t * ) a;
cvarTable_t *bc = ( cvarTable_t * ) b;
return Q_stricmp( ac->cvarName, bc->cvarName );
}
/*
=================
G_RegisterCvars
=================
*/
void G_RegisterCvars()
{
unsigned i;
cvarTable_t *cvarTable;
// sort the table for fast lookup
qsort( gameCvarTable, gameCvarTableSize, sizeof( *gameCvarTable ), cvarCompare );
for ( i = 0, cvarTable = gameCvarTable; i < gameCvarTableSize; i++, cvarTable++ )
{
trap_Cvar_Register( cvarTable->vmCvar, cvarTable->cvarName,
cvarTable->defaultString, cvarTable->cvarFlags );
if ( cvarTable->vmCvar )
{
cvarTable->modificationCount = cvarTable->vmCvar->modificationCount;
if ( cvarTable->explicit_ )
{
strcpy( cvarTable->explicit_, cvarTable->vmCvar->string );
}
}
}
}
/*
=================
G_UpdateCvars
=================
*/
void G_UpdateCvars()
{
unsigned i;
cvarTable_t *cv;
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_tr %s %s %s", QQ( N_("Server: $1$ changed to $2$") ),
Quote( cv->cvarName ), Quote( cv->vmCvar->string ) ) );
}
if ( !level.spawning && cv->explicit_ )
{
strcpy( cv->explicit_, cv->vmCvar->string );
}
}
}
}
}
/*
=================
G_RestoreCvars
=================
*/
void G_RestoreCvars()
{
unsigned i;
cvarTable_t *cv;
for ( i = 0, cv = gameCvarTable; i < gameCvarTableSize; i++, cv++ )
{
if ( cv->vmCvar && cv->explicit_ )
{
trap_Cvar_Set( cv->cvarName, cv->explicit_ );
}
}
}
vmCvar_t *G_FindCvar( const char *name )
{
cvarTable_t *c = nullptr;
cvarTable_t comp;
comp.cvarName = name;
c = ( cvarTable_t * ) bsearch( &comp, gameCvarTable, gameCvarTableSize, sizeof( *gameCvarTable ), cvarCompare );
if ( !c )
{
return nullptr;
}
return c->vmCvar;
}
/*
=================
G_MapConfigs
=================
*/
void G_MapConfigs( const char *mapname )
{
if ( !g_mapConfigs.string[ 0 ] )
{
return;
}
if ( trap_Cvar_VariableIntegerValue( "g_mapConfigsLoaded" ) )
{
return;
}
trap_SendConsoleCommand( va( "exec %s/default.cfg", Quote( g_mapConfigs.string ) ) );
trap_SendConsoleCommand( va( "exec %s/%s.cfg", Quote( g_mapConfigs.string ), Quote( mapname ) ) );
trap_Cvar_Set( "g_mapConfigsLoaded", "1" );
trap_SendConsoleCommand( "maprestarted" );
}
/*
============
G_InitGame
============
*/
void G_InitGame( int levelTime, int randomSeed, bool inClient )
{
int i;
srand( randomSeed );
G_RegisterCvars();
Log::Notice( "------- Game Initialization -------" );
Log::Notice( "gamename: %s", GAME_VERSION );
Log::Notice( "gamedate: %s", __DATE__ );
// set some level globals
memset( &level, 0, sizeof( level ) );
level.time = levelTime;
level.inClient = inClient;
level.startTime = levelTime;
level.snd_fry = G_SoundIndex( "sound/misc/fry" ); // FIXME standing in lava / slime
// TODO: Move this in a seperate function
if ( g_logFile.string[ 0 ] )
{
if ( g_logFileSync.integer )
{
trap_FS_FOpenFile( g_logFile.string, &level.logFile, fsMode_t::FS_APPEND_SYNC );
}
else
{
trap_FS_FOpenFile( g_logFile.string, &level.logFile, fsMode_t::FS_APPEND );
}
if ( !level.logFile )
{
Log::Warn("Couldn't open logfile: %s", g_logFile.string );
}
else
{
char serverinfo[ MAX_INFO_STRING ];
qtime_t qt;
trap_GetServerinfo( serverinfo, sizeof( serverinfo ) );
G_LogPrintf( "------------------------------------------------------------" );
G_LogPrintf( "InitGame: %s", serverinfo );
Com_GMTime( &qt );
G_LogPrintf( "RealTime: %04i-%02i-%02i %02i:%02i:%02i Z",
1900 + qt.tm_year, qt.tm_mon + 1, qt.tm_mday,
qt.tm_hour, qt.tm_min, qt.tm_sec );
}
}
else
{
Log::Notice( "Not logging to disk" );
}
// gameplay statistics logging
// TODO: Move this in a seperate function
if ( g_logGameplayStatsFrequency.integer > 0 )
{
char logfile[ 128 ], mapname[ 64 ];
qtime_t qt;
Com_GMTime( &qt );
trap_Cvar_VariableStringBuffer( "mapname", mapname, sizeof( mapname ) );
Com_sprintf( logfile, sizeof( logfile ),
"stats/gameplay/%04i%02i%02i_%02i%02i%02i_%s.log",
1900 + qt.tm_year, qt.tm_mon + 1, qt.tm_mday,
qt.tm_hour, qt.tm_min, qt.tm_sec,
mapname );
trap_FS_FOpenFile( logfile, &level.logGameplayFile, fsMode_t::FS_WRITE );
if ( !level.logGameplayFile )
{
Log::Warn("Couldn't open gameplay statistics logfile: %s", logfile );
}
else
{
G_LogGameplayStats( LOG_GAMEPLAY_STATS_HEADER );
}
}
// initialise whether bot vote kicks are allowed. the map rotation may clear this flag.
trap_Cvar_Set( "g_botKickVotesAllowedThisMap", g_botKickVotesAllowed.integer ? "1" : "0" );
// clear these now; they'll be set, if needed, from rotation
trap_Cvar_Set( "g_mapStartupMessage", "" );
trap_Cvar_Set( "g_disabledVoteCalls", "" );
// retrieve map name and load per-map configuration
{
char map[ MAX_CVAR_VALUE_STRING ] = { "" };
trap_Cvar_VariableStringBuffer( "mapname", map, sizeof( map ) );
G_MapConfigs( map );
}
// load config files
BG_InitAllConfigs();
// we're done with g_mapConfigs, so reset this for the next map
trap_Cvar_Set( "g_mapConfigsLoaded", "0" );
G_RegisterCommands();
G_admin_readconfig( nullptr );
// initialize all entities for this game
memset( g_entities, 0, MAX_GENTITIES * sizeof( g_entities[ 0 ] ) );
level.gentities = g_entities;
// entity used as drop-in for unmigrated entities
level.emptyEntity = new EmptyEntity({ nullptr });
// initialize special entities so they don't need to be special cased in the CBSE code later on
G_InitGentityMinimal( g_entities + ENTITYNUM_NONE );
G_InitGentityMinimal( g_entities + ENTITYNUM_WORLD );
// 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;
for( i = 0; i < MAX_CLIENTS; i++ )
{
g_entities[ i ].classname = "clientslot";
}
// let the server system know where the entites are
trap_LocateGameData( level.num_entities, sizeof( gentity_t ),
&level.clients[ 0 ].ps, sizeof( level.clients[ 0 ] ) );
level.emoticonCount = BG_LoadEmoticons( level.emoticons, MAX_EMOTICONS );
trap_SetConfigstring( CS_INTERMISSION, "0" );
// test to see if a custom buildable layout will be loaded
G_LayoutSelect();
// this has to be flipped after the first UpdateCvars
level.spawning = true;
// parse the key/value pairs and spawn gentities
G_SpawnEntitiesFromString();
// add any fake entities
G_SpawnFakeEntities();
BaseClustering::Init();
// load up a custom building layout if there is one
G_LayoutLoad();
// setup bot code
G_BotInit();
// the map might disable some things
BG_InitAllowedGameElements();
// Initialize item locking state
BG_InitUnlockackables();
G_FindEntityGroups();
G_InitSetEntities();
G_CheckPmoveParamChanges();
G_InitDamageLocations();
G_InitMapRotations();
G_InitSpawnQueue( &level.team[ TEAM_ALIENS ].spawnQueue );
G_InitSpawnQueue( &level.team[ TEAM_HUMANS ].spawnQueue );
if ( g_debugMapRotation.integer )
{
G_PrintRotations();
}
level.voices = BG_VoiceInit();
BG_PrintVoices( level.voices, g_debugVoices.integer );
// Spend build points for layout buildables.
for (team_t team = TEAM_NONE; (team = G_IterateTeams(team)); ) {
G_SpendBudget(team, level.team[team].layoutBuildPoints);
}
Log::Notice( "-----------------------------------" );
G_UpdateTeamConfigStrings();
G_MapLog_NewMap();
if ( g_lockTeamsAtStart.integer )
{
level.team[ TEAM_ALIENS ].locked = true;
level.team[ TEAM_HUMANS ].locked = true;
trap_Cvar_Set( "g_lockTeamsAtStart", "0" );
}
G_notify_sensor_start();
// Initialize build point counts for the intial layout.
G_UpdateBuildPointBudgets();
}
/*
==================
G_ClearVotes
remove all currently active votes
==================
*/
static void G_ClearVotes( bool all )
{
int i;
for ( i = 0; i < NUM_TEAMS; i++ )
{
if ( all || G_CheckStopVote( (team_t) i ) )
{
level.team[ i ].voteTime = 0;
trap_SetConfigstring( CS_VOTE_TIME + i, "" );
trap_SetConfigstring( CS_VOTE_STRING + i, "" );
}
}
}
/*
==================
G_VotesRunning
Check if there are any votes currently running
==================
*/
static bool G_VotesRunning()
{
int i;
for ( i = 0; i < NUM_TEAMS; i++ )
{
if ( level.team[ i ].voteTime )
{
return true;
}
}
return false;
}
/*
=================
G_ShutdownGame
=================
*/
void G_ShutdownGame( int /* restart */ )
{
// in case of a map_restart
G_ClearVotes( true );
G_RestoreCvars();
Log::Notice( "==== ShutdownGame ====" );
if ( level.logFile )
{
G_LogPrintf( "ShutdownGame:" );
G_LogPrintf( "------------------------------------------------------------" );
trap_FS_FCloseFile( level.logFile );
level.logFile = 0;
}
// finalize logging of gameplay statistics
if ( level.logGameplayFile )
{
G_LogGameplayStats( LOG_GAMEPLAY_STATS_FOOTER );
trap_FS_FCloseFile( level.logGameplayFile );
level.logGameplayFile = 0;
}
// write all the client session data so we can get it back
G_WriteSessionData();
G_admin_cleanup();
G_BotCleanup();
G_namelog_cleanup();
G_UnregisterCommands();
G_ShutdownMapRotations();
BG_UnloadAllConfigs();
level.restarted = false;
level.surrenderTeam = TEAM_NONE;
trap_SetConfigstring( CS_WINNER, "" );
/*
* delete cbse entities attached to gentities
* note, that this does not deal with several gentities having the same Entity attached
* (except for the EmptyEntity) as we'd otherwise be trying to delete dangling pointers
*/
for (int i = 0; i < level.num_entities; i++) {
Entity* entity = level.gentities[i].entity;
if (entity != level.emptyEntity)
delete entity;