-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathg_local.h
4034 lines (3372 loc) · 127 KB
/
g_local.h
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
// Copyright (c) ZeniMax Media Inc.
// Licensed under the GNU General Public License 2.0.
// g_local.h -- local definitions for game module
#pragma once
#include "bg_local.h"
// the "gameversion" client command will print this plus compile date
constexpr const char *GAMEVERSION = "baseq2";
constexpr const char *GAMEMOD_TITLE = "Choppuh!";
constexpr const char *GAMEMOD_VERSION = "0.01.0";
//==================================================================
#define ARRAY_LEN(x) (sizeof(x) / sizeof(*(x)))
constexpr const int32_t GIB_HEALTH = -40;
constexpr const int32_t AMMO_INFINITE = 1000;
constexpr size_t MAX_CLIENTS_KEX = 32; // absolute limit
enum mstats_t : uint32_t {
MSTAT_NONE,
MSTAT_KILLS,
MSTAT_DEATHS,
MSTAT_SHOTS,
MSTAT_HITS,
MSTAT_DMG_DEALT,
MSTAT_DMG_RECEIVED,
MSTAT_TOTAL
};
// gameplay rulesets
enum ruleset_t : uint8_t {
RS_NONE,
RS_Q2RE,
RS_MM,
RS_Q3A,
RS_Q1,
RS_NUM_RULESETS
};
#define RS( x ) game.ruleset == (x)
constexpr const char *rs_short_name[RS_NUM_RULESETS] = {
"",
"q2re",
"mm",
"q3a",
"q",
};
constexpr const char *rs_long_name[RS_NUM_RULESETS] = {
"",
"QUAKE II Rerelease",
"Muff Mode",
"QUAKE III Arena style",
"QUAKE style",
};
constexpr const char *stock_maps[] = {
"badlands", "base1", "base2", "base3", "base64", "biggun", "boss1", "boss2", "bunk1", "city1", "city2", "city3", "city64", "command", "cool1",
"e3/bunk_e3", "e3/fact_e3", "e3/jail_e3", "e3/jail4_e3", "e3/lab_e3", "e3/mine_e3", "e3/space_e3", "e3/ware1a_e3", "e3/ware2_e3", "e3/waste_e3",
"ec/base_ec", "ec/base3_ec", "ec/command_ec", "ec/factx_ec", "ec/jail_ec", "ec/kmdm3_ec", "ec/mine1_ec", "ec/power_ec", "ec/space_ec", "ec/waste_ec",
"fact1", "fact2", "fact3", "hangar1", "hangar2", "industry", "jail1", "jail2", "jail3", "jail4", "jail5", "lab", "mgdm1", "mgu1m1", "mgu1m2", "mgu1m3",
"mgu1m4", "mgu1m5", "mgu1trial", "mgu2m1", "mgu2m2", "mgu2m3", "mgu3m1", "mgu3m2", "mgu3m3", "mgu3m4", "mgu3secret", "mgu4m1", "mgu4m2", "mgu4m3", "mgu4trial",
"mgu5m1", "mgu5m2", "mgu5m3", "mgu5trial", "mgu6m1", "mgu6m2", "mgu6m3", "mgu6trial", "mguboss", "mguhub", "mine1", "mine2", "mine3", "mine4", "mintro", "ndctf0",
"old/baseold", "old/city2_4", "old/fact1", "old/fact2", "old/fact3", "old/facthub", "old/hangarold", "old/kmdm3", "old/pjtrain1", "old/ware1", "old/xcommand5",
"outbase", "power1", "power2", "q2ctf1", "q2ctf2", "q2ctf3", "q2ctf4", "q2ctf5", "q2dm1", "q2dm2", "q2dm3", "q2dm4", "q2dm5", "q2dm6", "q2dm7", "q2dm8", "q2kctf1",
"q2kctf2", "q64/bio", "q64/cargo", "q64/comm", "q64/command", "q64/complex", "q64/conduits", "q64/core", "q64/dm1", "q64/dm10", "q64/dm2", "q64/dm3", "q64/dm4",
"q64/dm5", "q64/dm6", "q64/dm7", "q64/dm8", "q64/dm9", "q64/geo-stat", "q64/intel", "q64/jail", "q64/lab", "q64/mines", "q64/orbit", "q64/organic", "q64/outpost",
"q64/process", "q64/rtest", "q64/ship", "q64/station", "q64/storage", "rammo1", "rammo2", "rbase1", "rbase2", "rboss", "rdm1", "rdm10", "rdm11", "rdm12", "rdm13",
"rdm14", "rdm2", "rdm3", "rdm4", "rdm5", "rdm6", "rdm7", "rdm8", "rdm9", "refinery", "rhangar1", "rhangar2", "rlava1", "rlava2", "rmine1", "rmine2", "rsewer1",
"rsewer2", "rware1", "rware2", "security", "sewer64", "space", "strike", "test/base1_flashlight", "test/gekk", "test/mals_barrier_test", "test/mals_box",
"test/mals_ladder_test", "test/mals_locked_door_test", "test/paril_health_relay", "test/paril_ladder", "test/paril_poi", "test/paril_scaled_monsters",
"test/paril_soundstage", "test/paril_steps", "test/paril_waterlight", "test/skysort", "test/spbox", "test/spbox2", "test/test_jerry", "test/test_kaiser",
"test/tom_test_01", "train", "tutorial", "w_treat", "ware1", "ware2", "waste1", "waste2", "waste3", "xcompnd1", "xcompnd2", "xdm1", "xdm2", "xdm3", "xdm4", "xdm5",
"xdm6", "xdm7", "xhangar1", "xhangar2", "xintell", "xmoon1", "xmoon2", "xreactor", "xsewer1", "xsewer2", "xship", "xswamp", "xware"
};
enum team_t {
TEAM_NONE,
TEAM_SPECTATOR,
TEAM_FREE,
TEAM_SOLDIERS,
TEAM_PREDATOR,
TEAM_NUM_TEAMS
};
enum monflags_t {
MF_NONE = 0x00,
MF_GROUND = 0x01,
MF_AIR = 0x02,
MF_WATER = 0x04,
MF_MEDIUM = 0x08,
MF_BOSS = 0x10
};
typedef enum {
MATCH_NONE,
MATCH_WARMUP_DELAYED, // pre-warmup (delay is active)
MATCH_WARMUP_DEFAULT, // 'waiting for players' / match short of players / imbalanced teams
MATCH_WARMUP_READYUP, // time for players to get ready
MATCH_COUNTDOWN, // all conditions met, counting down to match start, check conditions again at end of countdown before match start
MATCH_IN_PROGRESS, // match is in progress, not used in round-based gametypes
MATCH_ENDED // match or final round has ended
} matchst_t;
typedef enum {
WARMUP_REQ_NONE,
WARMUP_REQ_MORE_PLAYERS,
WARMUP_REQ_BALANCE,
WARMUP_REQ_READYUP
} warmupreq_t;
typedef enum {
ROUND_NONE,
ROUND_COUNTDOWN, // round-based gametypes only: initial delay before round starts
ROUND_IN_PROGRESS, // round-based gametypes only: round is in progress
ROUND_ENDED // round-based gametypes only: round has ended
} roundst_t;
enum playerspawn_t {
SPAWN_FULL_RAND,
SPAWN_FAR_HALF,
SPAWN_FARTHEST,
SPAWN_NEAREST
};
#define RANK_TIED_FLAG 0x4000
typedef enum {
SPECTATOR_NOT,
SPECTATOR_FREE,
SPECTATOR_FOLLOW
} spectator_state_t;
typedef enum {
TEAM_BEGIN, // Beginning a team game, spawn at base
TEAM_ACTIVE // Now actively playing
} player_team_state_state_t;
enum grapple_state_t {
GRAPPLE_STATE_FLY,
GRAPPLE_STATE_PULL,
GRAPPLE_STATE_HANG
};
struct vcmds_t {
const char *name;
bool (*val_func)(gentity_t *ent);
void (*func)();
int32_t flag;
int8_t min_args;
const char *args;
const char *help;
};
extern vcmds_t vote_cmds[];
extern int ii_highlight;
extern int ii_teams_red_default;
extern int ii_teams_blue_default;
extern int ii_ctf_red_dropped;
extern int ii_ctf_blue_dropped;
extern int ii_ctf_red_taken;
extern int ii_ctf_blue_taken;
extern int ii_teams_red_tiny;
extern int ii_teams_blue_tiny;
extern int ii_teams_header_red;
extern int ii_teams_header_blue;
extern int mi_ctf_red_flag, mi_ctf_blue_flag; // [Paril-KEX]
//==================================================================
constexpr vec3_t PLAYER_MINS = { -16, -16, -24 };
constexpr vec3_t PLAYER_MAXS = { 16, 16, 32 };
#include <charconv>
template<typename T>
constexpr bool is_char_ptr_v = std::is_convertible_v<T, const char *>;
template<typename T>
constexpr bool is_valid_loc_embed_v = !std::is_null_pointer_v<T> && (std::is_floating_point_v<std::remove_reference_t<T>> || std::is_integral_v<std::remove_reference_t<T>> || is_char_ptr_v<T>);
struct local_game_import_t : game_import_t {
inline local_game_import_t() = default;
inline local_game_import_t(const game_import_t &imports) :
game_import_t(imports) {}
private:
// shared buffer for wrappers below
static char print_buffer[0x10000];
public:
#ifdef USE_CPP20_FORMAT
template<typename... Args>
inline void Com_PrintFmt(std::format_string<Args...> format_str, Args &&... args)
#else
#define Com_PrintFmt(str, ...) \
Com_PrintFmt_(FMT_STRING(str), __VA_ARGS__)
template<typename S, typename... Args>
inline void Com_PrintFmt_(const S &format_str, Args &&... args)
#endif
{
G_FmtTo_(print_buffer, format_str, std::forward<Args>(args)...);
Com_Print(print_buffer);
}
#ifdef USE_CPP20_FORMAT
template<typename... Args>
inline void Com_ErrorFmt(std::format_string<Args...> format_str, Args &&... args)
#else
#define Com_ErrorFmt(str, ...) \
Com_ErrorFmt_(FMT_STRING(str), __VA_ARGS__)
template<typename S, typename... Args>
inline void Com_ErrorFmt_(const S &format_str, Args &&... args)
#endif
{
G_FmtTo_(print_buffer, format_str, std::forward<Args>(args)...);
Com_Error(print_buffer);
}
private:
// localized print functions
template<typename T>
inline void loc_embed(T input, char *buffer, const char *&output) {
if constexpr (std::is_floating_point_v<T> || std::is_integral_v<T>) {
auto result = std::to_chars(buffer, buffer + MAX_INFO_STRING - 1, input);
*result.ptr = '\0';
output = buffer;
} else if constexpr (is_char_ptr_v<T>) {
if (!input)
Com_Error("null const char ptr passed to loc");
output = input;
} else
Com_Error("invalid loc argument");
}
static std::array<char[MAX_INFO_STRING], MAX_LOCALIZATION_ARGS> buffers;
static std::array<const char *, MAX_LOCALIZATION_ARGS> buffer_ptrs;
public:
template<typename... Args>
inline void LocClient_Print(gentity_t *e, print_type_t level, const char *base, Args&& ...args) {
static_assert(sizeof...(args) < MAX_LOCALIZATION_ARGS, "too many arguments to gi.LocClient_Print");
static_assert(((is_valid_loc_embed_v<Args>) && ...), "invalid argument passed to gi.LocClient_Print");
size_t n = 0;
((loc_embed(args, buffers[n], buffer_ptrs[n]), ++n), ...);
Loc_Print(e, level, base, &buffer_ptrs.front(), sizeof...(args));
}
template<typename... Args>
inline void LocBroadcast_Print(print_type_t level, const char *base, Args&& ...args) {
static_assert(sizeof...(args) < MAX_LOCALIZATION_ARGS, "too many arguments to gi.LocBroadcast_Print");
static_assert(((is_valid_loc_embed_v<Args>) && ...), "invalid argument passed to gi.LocBroadcast_Print");
size_t n = 0;
((loc_embed(args, buffers[n], buffer_ptrs[n]), ++n), ...);
Loc_Print(nullptr, (print_type_t)(level | print_type_t::PRINT_BROADCAST), base, &buffer_ptrs.front(), sizeof...(args));
}
template<typename... Args>
inline void LocCenter_Print(gentity_t *e, const char *base, Args&& ...args) {
static_assert(sizeof...(args) < MAX_LOCALIZATION_ARGS, "too many arguments to gi.LocCenter_Print");
static_assert(((is_valid_loc_embed_v<Args>) && ...), "invalid argument passed to gi.LocCenter_Print");
size_t n = 0;
((loc_embed(args, buffers[n], buffer_ptrs[n]), ++n), ...);
Loc_Print(e, PRINT_CENTER, base, &buffer_ptrs.front(), sizeof...(args));
}
// collision detection
[[nodiscard]] inline trace_t trace(const vec3_t &start, const vec3_t &mins, const vec3_t &maxs, const vec3_t &end, const gentity_t *passent, contents_t contentmask) {
return game_import_t::trace(start, &mins, &maxs, end, passent, contentmask);
}
[[nodiscard]] inline trace_t traceline(const vec3_t &start, const vec3_t &end, const gentity_t *passent, contents_t contentmask) {
return game_import_t::trace(start, nullptr, nullptr, end, passent, contentmask);
}
// [Paril-KEX] clip the box against the specified entity
[[nodiscard]] inline trace_t clip(gentity_t *entity, const vec3_t &start, const vec3_t &mins, const vec3_t &maxs, const vec3_t &end, contents_t contentmask) {
return game_import_t::clip(entity, start, &mins, &maxs, end, contentmask);
}
[[nodiscard]] inline trace_t clip(gentity_t *entity, const vec3_t &start, const vec3_t &end, contents_t contentmask) {
return game_import_t::clip(entity, start, nullptr, nullptr, end, contentmask);
}
void unicast(gentity_t *ent, bool reliable, uint32_t dupe_key = 0) {
game_import_t::unicast(ent, reliable, dupe_key);
}
void local_sound(gentity_t *target, const vec3_t &origin, gentity_t *ent, soundchan_t channel, int soundindex, float volume, float attenuation, float timeofs, uint32_t dupe_key = 0) {
game_import_t::local_sound(target, &origin, ent, channel, soundindex, volume, attenuation, timeofs, dupe_key);
}
void local_sound(gentity_t *target, gentity_t *ent, soundchan_t channel, int soundindex, float volume, float attenuation, float timeofs, uint32_t dupe_key = 0) {
game_import_t::local_sound(target, nullptr, ent, channel, soundindex, volume, attenuation, timeofs, dupe_key);
}
void local_sound(const vec3_t &origin, gentity_t *ent, soundchan_t channel, int soundindex, float volume, float attenuation, float timeofs, uint32_t dupe_key = 0) {
game_import_t::local_sound(ent, &origin, ent, channel, soundindex, volume, attenuation, timeofs, dupe_key);
}
void local_sound(gentity_t *ent, soundchan_t channel, int soundindex, float volume, float attenuation, float timeofs, uint32_t dupe_key = 0) {
game_import_t::local_sound(ent, nullptr, ent, channel, soundindex, volume, attenuation, timeofs, dupe_key);
}
};
extern local_game_import_t gi;
// entity->spawnflags
// these are set with checkboxes on each entity in the map editor.
// the following 8 are reserved and should never be used by any entity.
// (power cubes in coop use these after spawning as well)
struct spawnflags_t {
uint32_t value;
explicit constexpr spawnflags_t(uint32_t v) :
value(v) {}
explicit operator uint32_t() const {
return value;
}
// has any flags at all (!!a)
constexpr bool any() const { return !!value; }
// has any of the given flags (!!(a & b))
constexpr bool has(const spawnflags_t &flags) const { return !!(value & flags.value); }
// has all of the given flags ((a & b) == b)
constexpr bool has_all(const spawnflags_t &flags) const { return (value & flags.value) == flags.value; }
constexpr bool operator!() const { return !value; }
constexpr bool operator==(const spawnflags_t &flags) const {
return value == flags.value;
}
constexpr bool operator!=(const spawnflags_t &flags) const {
return value != flags.value;
}
constexpr spawnflags_t operator~() const {
return spawnflags_t(~value);
}
constexpr spawnflags_t operator|(const spawnflags_t &v2) const {
return spawnflags_t(value | v2.value);
}
constexpr spawnflags_t operator&(const spawnflags_t &v2) const {
return spawnflags_t(value & v2.value);
}
constexpr spawnflags_t operator^(const spawnflags_t &v2) const {
return spawnflags_t(value ^ v2.value);
}
constexpr spawnflags_t &operator|=(const spawnflags_t &v2) {
value |= v2.value;
return *this;
}
constexpr spawnflags_t &operator&=(const spawnflags_t &v2) {
value &= v2.value;
return *this;
}
constexpr spawnflags_t &operator^=(const spawnflags_t &v2) {
value ^= v2.value;
return *this;
}
};
// these spawnflags affect every entity. note that items are a bit special
// because these 8 bits are instead used for power cube bits.
constexpr spawnflags_t SPAWNFLAG_NONE = spawnflags_t(0);
constexpr spawnflags_t SPAWNFLAG_NOT_EASY = spawnflags_t(0x00000100),
SPAWNFLAG_NOT_MEDIUM = spawnflags_t(0x00000200),
SPAWNFLAG_NOT_HARD = spawnflags_t(0x00000400),
SPAWNFLAG_NOT_DEATHMATCH = spawnflags_t(0x00000800),
SPAWNFLAG_NOT_COOP = spawnflags_t(0x00001000),
SPAWNFLAG_RESERVED1 = spawnflags_t(0x00002000),
SPAWNFLAG_COOP_ONLY = spawnflags_t(0x00004000);
constexpr spawnflags_t SPAWNFLAG_EDITOR_MASK = (SPAWNFLAG_NOT_EASY | SPAWNFLAG_NOT_MEDIUM | SPAWNFLAG_NOT_HARD | SPAWNFLAG_NOT_DEATHMATCH |
SPAWNFLAG_NOT_COOP | SPAWNFLAG_RESERVED1 | SPAWNFLAG_COOP_ONLY);
// use this for global spawnflags
constexpr spawnflags_t operator "" _spawnflag(unsigned long long int v) {
if (v & SPAWNFLAG_EDITOR_MASK.value)
throw std::invalid_argument("attempting to use reserved spawnflag");
return static_cast<spawnflags_t>(static_cast<uint32_t>(v));
}
// use this for global spawnflags
constexpr spawnflags_t operator "" _spawnflag_bit(unsigned long long int v) {
v = 1ull << v;
if (v & SPAWNFLAG_EDITOR_MASK.value)
throw std::invalid_argument("attempting to use reserved spawnflag");
return static_cast<spawnflags_t>(static_cast<uint32_t>(v));
}
// stores a level time; most newer engines use int64_t for
// time storage, but seconds are handy for compatibility
// with Quake and older mods.
struct gtime_t {
private:
// times always start at zero, just to prevent memory issues
int64_t _ms = 0;
// internal; use _sec/_ms/_min or gtime_t::from_sec(n)/gtime_t::from_ms(n)/gtime_t::from_min(n)
constexpr explicit gtime_t(const int64_t &ms) : _ms(ms) {}
public:
constexpr gtime_t() = default;
constexpr gtime_t(const gtime_t &) = default;
constexpr gtime_t &operator=(const gtime_t &) = default;
// constructors are here, explicitly named, so you always
// know what you're getting.
// new time from ms
static constexpr gtime_t from_ms(const int64_t &ms) {
return gtime_t(ms);
}
// new time from seconds
template<typename T, typename = std::enable_if_t<std::is_floating_point_v<T> || std::is_integral_v<T>>>
static constexpr gtime_t from_sec(const T &s) {
return gtime_t(static_cast<int64_t>(s * 1000));
}
// new time from minutes
template<typename T, typename = std::enable_if_t<std::is_floating_point_v<T> || std::is_integral_v<T>>>
static constexpr gtime_t from_min(const T &s) {
return gtime_t(static_cast<int64_t>(s * 60000));
}
// new time from hz
static constexpr gtime_t from_hz(const uint64_t &hz) {
return from_ms(static_cast<int64_t>((1.0 / hz) * 1000));
}
// get value in minutes (truncated for integers)
template<typename T = float>
constexpr T minutes() const {
return static_cast<T>(_ms / static_cast<std::conditional_t<std::is_floating_point_v<T>, T, float>>(60000));
}
// get value in seconds (truncated for integers)
template<typename T = float>
constexpr T seconds() const {
return static_cast<T>(_ms / static_cast<std::conditional_t<std::is_floating_point_v<T>, T, float>>(1000));
}
// get value in milliseconds
constexpr const int64_t &milliseconds() const {
return _ms;
}
int64_t frames() const {
return _ms / gi.frame_time_ms;
}
// check if non-zero
constexpr explicit operator bool() const {
return !!_ms;
}
// invert time
constexpr gtime_t operator-() const {
return gtime_t(-_ms);
}
// operations with other times as input
constexpr gtime_t operator+(const gtime_t &r) const {
return gtime_t(_ms + r._ms);
}
constexpr gtime_t operator-(const gtime_t &r) const {
return gtime_t(_ms - r._ms);
}
constexpr gtime_t &operator+=(const gtime_t &r) {
return *this = *this + r;
}
constexpr gtime_t &operator-=(const gtime_t &r) {
return *this = *this - r;
}
// operations with scalars as input
template<typename T, typename = std::enable_if_t<std::is_floating_point_v<T> || std::is_integral_v<T>>>
constexpr gtime_t operator*(const T &r) const {
return gtime_t::from_ms(static_cast<int64_t>(_ms * r));
}
template<typename T, typename = std::enable_if_t<std::is_floating_point_v<T> || std::is_integral_v<T>>>
constexpr gtime_t operator/(const T &r) const {
return gtime_t::from_ms(static_cast<int64_t>(_ms / r));
}
template<typename T, typename = std::enable_if_t<std::is_floating_point_v<T> || std::is_integral_v<T>>>
constexpr gtime_t &operator*=(const T &r) {
return *this = *this * r;
}
template<typename T, typename = std::enable_if_t<std::is_floating_point_v<T> || std::is_integral_v<T>>>
constexpr gtime_t &operator/=(const T &r) {
return *this = *this / r;
}
// comparisons with gtime_ts
constexpr bool operator==(const gtime_t &time) const {
return _ms == time._ms;
}
constexpr bool operator!=(const gtime_t &time) const {
return _ms != time._ms;
}
constexpr bool operator<(const gtime_t &time) const {
return _ms < time._ms;
}
constexpr bool operator>(const gtime_t &time) const {
return _ms > time._ms;
}
constexpr bool operator<=(const gtime_t &time) const {
return _ms <= time._ms;
}
constexpr bool operator>=(const gtime_t &time) const {
return _ms >= time._ms;
}
};
// user literals, allowing you to specify times
// as 128_sec and 128_ms
constexpr gtime_t operator"" _min(long double s) {
return gtime_t::from_min(s);
}
constexpr gtime_t operator"" _min(unsigned long long int s) {
return gtime_t::from_min(s);
}
constexpr gtime_t operator"" _sec(long double s) {
return gtime_t::from_sec(s);
}
constexpr gtime_t operator"" _sec(unsigned long long int s) {
return gtime_t::from_sec(s);
}
constexpr gtime_t operator"" _ms(long double s) {
return gtime_t::from_ms(static_cast<int64_t>(s));
}
constexpr gtime_t operator"" _ms(unsigned long long int s) {
return gtime_t::from_ms(static_cast<int64_t>(s));
}
constexpr gtime_t operator"" _hz(unsigned long long int s) {
return gtime_t::from_ms(static_cast<int64_t>((1.0 / s) * 1000));
}
#define SERVER_TICK_RATE gi.tick_rate // in hz
extern gtime_t FRAME_TIME_S;
extern gtime_t FRAME_TIME_MS;
// view pitching times
inline gtime_t DAMAGE_TIME_SLACK() {
return (100_ms - FRAME_TIME_MS);
}
inline gtime_t DAMAGE_TIME() {
return 500_ms + DAMAGE_TIME_SLACK();
}
inline gtime_t FALL_TIME() {
return 300_ms + DAMAGE_TIME_SLACK();
}
// every save_data_list_t has a tag
// which is used for integrity checks.
enum save_data_tag_t {
SAVE_DATA_MMOVE,
SAVE_FUNC_MONSTERINFO_STAND,
SAVE_FUNC_MONSTERINFO_IDLE,
SAVE_FUNC_MONSTERINFO_SEARCH,
SAVE_FUNC_MONSTERINFO_WALK,
SAVE_FUNC_MONSTERINFO_RUN,
SAVE_FUNC_MONSTERINFO_DODGE,
SAVE_FUNC_MONSTERINFO_ATTACK,
SAVE_FUNC_MONSTERINFO_MELEE,
SAVE_FUNC_MONSTERINFO_SIGHT,
SAVE_FUNC_MONSTERINFO_CHECKATTACK,
SAVE_FUNC_MONSTERINFO_SETSKIN,
SAVE_FUNC_MONSTERINFO_BLOCKED,
SAVE_FUNC_MONSTERINFO_DUCK,
SAVE_FUNC_MONSTERINFO_UNDUCK,
SAVE_FUNC_MONSTERINFO_SIDESTEP,
SAVE_FUNC_MONSTERINFO_PHYSCHANGED,
SAVE_FUNC_MOVEINFO_ENDFUNC,
SAVE_FUNC_MOVEINFO_BLOCKED,
SAVE_FUNC_PRETHINK,
SAVE_FUNC_THINK,
SAVE_FUNC_TOUCH,
SAVE_FUNC_USE,
SAVE_FUNC_PAIN,
SAVE_FUNC_DIE
};
// forward-linked list, storing data for
// saving pointers. every save_data_ptr has an
// instance of this; there's one head instance of this
// in g_save.cpp.
struct save_data_list_t {
const char *name; // name of savable object; persisted in the JSON file
save_data_tag_t tag;
const void *ptr; // pointer to raw data
const save_data_list_t *next; // next in list
save_data_list_t(const char *name, save_data_tag_t tag, const void *ptr);
static const save_data_list_t *fetch(const void *link_ptr, save_data_tag_t tag);
};
#include <functional>
// save data wrapper, which holds a pointer to a T
// and the tag value for integrity. this is how you
// store a savable pointer of data safely.
template<typename T, size_t Tag>
struct save_data_t {
using value_type = typename std::conditional<std::is_pointer<T>::value &&
std::is_function<typename std::remove_pointer<T>::type>::value,
T,
const T *>::type;
private:
value_type value;
const save_data_list_t *list;
public:
constexpr save_data_t() :
value(nullptr),
list(nullptr) {}
constexpr save_data_t(nullptr_t) :
save_data_t() {}
constexpr save_data_t(const save_data_list_t *list_in) :
value(list_in->ptr),
list(list_in) {}
inline save_data_t(value_type ptr_in) :
value(ptr_in),
list(ptr_in ? save_data_list_t::fetch(reinterpret_cast<const void *>(ptr_in), static_cast<save_data_tag_t>(Tag)) : nullptr) {}
inline save_data_t(const save_data_t<T, Tag> &ref_in) :
save_data_t(ref_in.value) {}
inline save_data_t &operator=(value_type ptr_in) {
if (value != ptr_in) {
value = ptr_in;
list = value ? save_data_list_t::fetch(reinterpret_cast<const void *>(ptr_in), static_cast<save_data_tag_t>(Tag)) : nullptr;
}
return *this;
}
constexpr const value_type pointer() const { return value; }
constexpr const save_data_list_t *save_list() const { return list; }
constexpr const char *name() const { return value ? list->name : "null"; }
constexpr const value_type operator->() const { return value; }
constexpr explicit operator bool() const { return value; }
constexpr bool operator==(value_type ptr_in) const { return value == ptr_in; }
constexpr bool operator!=(value_type ptr_in) const { return value != ptr_in; }
constexpr bool operator==(const save_data_t<T, Tag> *ptr_in) const { return value == ptr_in->value; }
constexpr bool operator==(const save_data_t<T, Tag> &ref_in) const { return value == ref_in.value; }
constexpr bool operator!=(const save_data_t<T, Tag> *ptr_in) const { return value != ptr_in->value; }
constexpr bool operator!=(const save_data_t<T, Tag> &ref_in) const { return value != ref_in.value; }
// invoke wrapper, for function-likes
template<typename... Args>
inline auto operator()(Args&& ...args) const {
static_assert(std::is_invocable_v<std::remove_pointer_t<T>, Args...>, "bad invoke args");
return std::invoke(value, std::forward<Args>(args)...);
}
};
// memory tags to allow dynamic memory to be cleaned up
enum {
TAG_GAME = 765, // clear when unloading the dll
TAG_LEVEL = 766 // clear when loading a new level
};
constexpr float MELEE_DISTANCE = 50;
constexpr size_t BODY_QUEUE_SIZE = 8;
// null trace used when touches don't need a trace
constexpr trace_t null_trace{};
enum weaponstate_t {
WEAPON_READY,
WEAPON_ACTIVATING,
WEAPON_DROPPING,
WEAPON_FIRING
};
// gib flags
enum gib_type_t {
GIB_NONE = 0, // no flags (organic)
GIB_METALLIC = 1, // bouncier
GIB_ACID = 2, // acidic (gekk)
GIB_HEAD = 4, // head gib; the input entity will transform into this
GIB_DEBRIS = 8, // explode outwards rather than in velocity, no blood
GIB_SKINNED = 16, // use skinnum
GIB_UPRIGHT = 32, // stay upright on ground
};
MAKE_ENUM_BITFLAGS(gib_type_t);
// monster ai flags
enum monster_ai_flags_t : uint64_t {
AI_NONE = 0,
AI_STAND_GROUND = bit_v<0>,
AI_TEMP_STAND_GROUND = bit_v<1>,
AI_SOUND_TARGET = bit_v<2>,
AI_LOST_SIGHT = bit_v<3>,
AI_PURSUIT_LAST_SEEN = bit_v<4>,
AI_PURSUE_NEXT = bit_v<5>,
AI_PURSUE_TEMP = bit_v<6>,
AI_HOLD_FRAME = bit_v<7>,
AI_GOOD_GUY = bit_v<8>,
AI_BRUTAL = bit_v<9>,
AI_NOSTEP = bit_v<10>,
AI_DUCKED = bit_v<11>,
AI_COMBAT_POINT = bit_v<12>,
AI_MEDIC = bit_v<13>,
AI_RESURRECTING = bit_v<14>,
AI_MANUAL_STEERING = bit_v<15>,
AI_TARGET_ANGER = bit_v<16>,
AI_DODGING = bit_v<17>,
AI_CHARGING = bit_v<18>,
AI_HINT_PATH = bit_v<19>,
AI_IGNORE_SHOTS = bit_v<20>,
// PMM - FIXME - last second added for E3 .. there's probably a better way to do this, but
// this works
AI_DO_NOT_COUNT = bit_v<21>, // set for healed monsters
AI_SPAWNED_CARRIER = bit_v<22>, // both do_not_count and spawned are set for spawned monsters
AI_SPAWNED_MEDIC_C = bit_v<23>, // both do_not_count and spawned are set for spawned monsters
AI_SPAWNED_WIDOW = bit_v<24>, // both do_not_count and spawned are set for spawned monsters
AI_BLOCKED = bit_v<25>, // used by blocked_checkattack: set to say I'm attacking while blocked (prevents run-attacks)
AI_SPAWNED_ALIVE = bit_v<26>, // [Paril-KEX] for spawning dead
AI_SPAWNED_DEAD = bit_v<27>,
AI_HIGH_TICK_RATE = bit_v<28>, // not limited by 10hz actions
AI_NO_PATH_FINDING = bit_v<29>, // don't try nav nodes for path finding
AI_PATHING = bit_v<30>, // using nav nodes currently
AI_STINKY = bit_v<31>, // spawn flies
AI_STUNK = bit_v<32>, // already spawned files
AI_ALTERNATE_FLY = bit_v<33>, // use alternate flying mechanics; see monsterinfo.fly_xxx
AI_TEMP_MELEE_COMBAT = bit_v<34>, // temporarily switch to the melee combat style
AI_FORGET_ENEMY = bit_v<35>, // forget the current enemy
AI_DOUBLE_TROUBLE = bit_v<36>, // JORG only
AI_REACHED_HOLD_COMBAT = bit_v<37>,
AI_THIRD_EYE = bit_v<38>
};
MAKE_ENUM_BITFLAGS(monster_ai_flags_t);
constexpr monster_ai_flags_t AI_SPAWNED_MASK =
AI_SPAWNED_CARRIER | AI_SPAWNED_MEDIC_C | AI_SPAWNED_WIDOW; // mask to catch all three flavors of spawned
// monster attack state
enum monster_attack_state_t {
AS_NONE,
AS_STRAIGHT,
AS_SLIDING,
AS_MELEE,
AS_MISSILE,
AS_BLIND // PMM - used by boss code to do nasty things even if it can't see you
};
// handedness values
enum handedness_t {
RIGHT_HANDED,
LEFT_HANDED,
CENTER_HANDED
};
enum class auto_switch_t {
SMART,
ALWAYS,
ALWAYS_NO_AMMO,
NEVER
};
constexpr uint32_t SFL_CROSS_TRIGGER_MASK = (0xffffffffu & ~SPAWNFLAG_EDITOR_MASK.value);
// noise types for PlayerNoise
enum player_noise_t {
PNOISE_SELF,
PNOISE_WEAPON,
PNOISE_IMPACT
};
struct gitem_armor_t {
int32_t base_count;
int32_t max_count;
float normal_protection;
float energy_protection;
};
static constexpr gitem_armor_t jacketarmor_info = { 25, 50, .30f, .00f };
static constexpr gitem_armor_t combatarmor_info = { 50, 100, .60f, .30f };
static constexpr gitem_armor_t bodyarmor_info = { 100, 200, .80f, .60f };
// entity->movetype values
enum movetype_t {
MOVETYPE_NONE, // never moves
MOVETYPE_NOCLIP, // origin and angles change with no interaction
MOVETYPE_PUSH, // no clip to world, push on box contact
MOVETYPE_STOP, // no clip to world, stops on box contact
MOVETYPE_WALK, // gravity
MOVETYPE_STEP, // gravity, special edge handling
MOVETYPE_FLY,
MOVETYPE_TOSS, // gravity
MOVETYPE_FLYMISSILE, // extra size to monsters
MOVETYPE_BOUNCE,
MOVETYPE_WALLBOUNCE,
MOVETYPE_NEWTOSS, // PGM - for deathball
MOVETYPE_FREECAM, // spectator free cam
};
// entity->flags
enum ent_flags_t : uint64_t {
FL_NONE = 0, // no flags
FL_FLY = bit_v<0>,
FL_SWIM = bit_v<1>, // implied immunity to drowning
FL_IMMUNE_LASER = bit_v<2>,
FL_INWATER = bit_v<3>,
FL_GODMODE = bit_v<4>,
FL_NOTARGET = bit_v<5>,
FL_IMMUNE_SLIME = bit_v<6>,
FL_IMMUNE_LAVA = bit_v<7>,
FL_PARTIALGROUND = bit_v<8>, // not all corners are valid
FL_WATERJUMP = bit_v<9>, // player jumping out of water
FL_TEAMSLAVE = bit_v<10>, // not the first on the team
FL_NO_KNOCKBACK = bit_v<11>,
FL_POWER_ARMOR = bit_v<12>, // power armor (if any) is active
FL_MECHANICAL = bit_v<13>, // entity is mechanical, use sparks not blood
FL_SAM_RAIMI = bit_v<14>, // entity is in sam raimi cam mode
FL_DISGUISED = bit_v<15>, // entity is in disguise, monsters will not recognize.
FL_NOGIB = bit_v<16>, // player has been vaporized by a nuke, drop no gibs
FL_DAMAGEABLE = bit_v<17>,
FL_STATIONARY = bit_v<18>,
FL_ALIVE_KNOCKBACK_ONLY = bit_v<19>, // only apply knockback if alive or on same frame as death
FL_NO_DAMAGE_EFFECTS = bit_v<20>,
// [Paril-KEX] gets scaled by coop health scaling
FL_COOP_HEALTH_SCALE = bit_v<21>,
FL_FLASHLIGHT = bit_v<22>, // enable flashlight
FL_KILL_VELOCITY = bit_v<23>, // for berserker slam
FL_NOVISIBLE = bit_v<24>, // super invisibility
FL_DODGE = bit_v<25>, // monster should try to dodge this
FL_TEAMMASTER = bit_v<26>, // is a team master (only here so that entities abusing teammaster/teamchain for stuff don't break)
FL_LOCKED = bit_v<27>, // entity is locked for the purposes of navigation
FL_ALWAYS_TOUCH = bit_v<28>, // always touch, even if we normally wouldn't
FL_NO_STANDING = bit_v<29>, // don't allow "standing" on non-brush entities
FL_WANTS_POWER_ARMOR = bit_v<30>, // for players, auto-shield
FL_RESPAWN = bit_v<31>, // used for item respawning
FL_TRAP = bit_v<32>, // entity is a trap of some kind
FL_TRAP_LASER_FIELD = bit_v<33>, // enough of a special case to get it's own flag...
FL_IMMORTAL = bit_v<34>, // never go below 1hp
FL_NO_BOTS = bit_v<35>, // not to be used by bots
FL_NO_HUMANS = bit_v<36>, // not to be used by humans
};
MAKE_ENUM_BITFLAGS(ent_flags_t);
// gitem_t->flags
enum item_flags_t : uint32_t {
IF_NONE = 0,
IF_WEAPON = bit_v<0>, // use makes active weapon
IF_AMMO = bit_v<1>,
IF_ARMOR = bit_v<2>,
IF_STAY_COOP = bit_v<3>,
IF_KEY = bit_v<4>,
IF_TIMED = bit_v<5>, // minor powerup items
IF_NOT_GIVEABLE = bit_v<6>, // item can not be given
IF_HEALTH = bit_v<7>,
IF_TECH = bit_v<8>,
IF_NO_HASTE = bit_v<9>,
IF_NO_INFINITE_AMMO = bit_v<10>, // [Paril-KEX] don't allow infinite ammo to affect
IF_POWERUP_WHEEL = bit_v<11>, // [Paril-KEX] item should be in powerup wheel
IF_POWERUP_ONOFF = bit_v<12>, // [Paril-KEX] for wheel; can't store more than one, show on/off state
IF_NOT_RANDOM = bit_v<13>, // [Paril-KEX] item never shows up in randomizations
IF_POWER_ARMOR = bit_v<14>,
IF_POWERUP = bit_v<15>,
IF_SPHERE = bit_v<16>,
IF_ANY = 0xFFFFFFFF
};
MAKE_ENUM_BITFLAGS(item_flags_t);
constexpr item_flags_t IF_TYPE_MASK = (IF_WEAPON | IF_AMMO | IF_TIMED | IF_POWERUP | IF_SPHERE | IF_ARMOR | IF_POWER_ARMOR | IF_KEY);
// health gentity_t->style
enum {
HEALTH_IGNORE_MAX = 1,
HEALTH_TIMED = 2
};
enum superpu_t {
SPW_NONE,
SPW_QUAD,
SPW_DUELFIRE,
SPW_PROTECTION,
SPW_DOUBLE,
SPW_INVISIBILITY,
SPW_MAX_SPW
};
// item IDs; must match itemlist order
enum item_id_t : int32_t {
IT_NULL, // must always be zero
IT_ARMOR_BODY,
IT_ARMOR_COMBAT,
IT_ARMOR_JACKET,
IT_ARMOR_SHARD,
IT_POWER_SCREEN,
IT_POWER_SHIELD,
IT_WEAPON_GRAPPLE,
IT_WEAPON_BLASTER,
IT_WEAPON_CHAINFIST,
IT_WEAPON_SHOTGUN,
IT_WEAPON_SSHOTGUN,
IT_WEAPON_MACHINEGUN,
IT_WEAPON_ETF_RIFLE,
IT_WEAPON_CHAINGUN,
IT_AMMO_GRENADES,
IT_AMMO_TRAP,
IT_AMMO_TESLA,
IT_WEAPON_GLAUNCHER,
IT_WEAPON_PROXLAUNCHER,
IT_WEAPON_RLAUNCHER,
IT_WEAPON_HYPERBLASTER,
IT_WEAPON_IONRIPPER,
IT_WEAPON_PLASMABEAM,
IT_WEAPON_RAILGUN,
IT_WEAPON_PHALANX,
IT_WEAPON_BFG,
IT_WEAPON_DISRUPTOR,
IT_AMMO_SHELLS,
IT_AMMO_BULLETS,
IT_AMMO_CELLS,
IT_AMMO_ROCKETS,
IT_AMMO_SLUGS,
IT_AMMO_MAGSLUG,
IT_AMMO_FLECHETTES,
IT_AMMO_PROX,
IT_AMMO_NUKE,
IT_AMMO_ROUNDS,
IT_POWERUP_QUAD,
IT_POWERUP_DUELFIRE,
IT_POWERUP_PROTECTION,
IT_POWERUP_INVISIBILITY,
IT_POWERUP_SILENCER,
IT_POWERUP_REBREATHER,
IT_POWERUP_ENVIROSUIT,
IT_ANCIENT_HEAD,
IT_LEGACY_HEAD,
IT_ADRENALINE,
IT_BANDOLIER,
IT_PACK,
IT_IR_GOGGLES,
IT_POWERUP_DOUBLE,
IT_POWERUP_SPHERE_VENGEANCE,
IT_POWERUP_SPHERE_HUNTER,
IT_POWERUP_SPHERE_DEFENDER,
IT_DOPPELGANGER,
IT_TAG_TOKEN,
IT_KEY_DATA_CD,
IT_KEY_POWER_CUBE,
IT_KEY_EXPLOSIVE_CHARGES,
IT_KEY_YELLOW,
IT_KEY_POWER_CORE,
IT_KEY_PYRAMID,
IT_KEY_DATA_SPINNER,
IT_KEY_PASS,
IT_KEY_BLUE_KEY,