-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathp_client.cpp
4449 lines (3660 loc) · 126 KB
/
p_client.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
// Copyright (c) ZeniMax Media Inc.
// Licensed under the GNU General Public License 2.0.
#include "g_local.h"
#include "monsters/m_player.h"
#include "bots/bot_includes.h"
void SP_misc_teleporter_dest(gentity_t *ent);
static THINK(info_player_start_drop) (gentity_t *self) -> void {
// allow them to drop
self->solid = SOLID_TRIGGER;
self->movetype = MOVETYPE_TOSS;
self->mins = PLAYER_MINS;
self->maxs = PLAYER_MAXS;
gi.linkentity(self);
}
static inline void deathmatch_spawn_flags(gentity_t *self) {
if (st.nobots)
self->flags = FL_NO_BOTS;
if (st.nohumans)
self->flags = FL_NO_HUMANS;
}
/*QUAKED info_player_start (1 0 0) (-16 -16 -24) (16 16 32) x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
The normal starting point for a level.
"nobots" will prevent bots from using this spot.
"nohumans" will prevent humans from using this spot.
*/
void SP_info_player_start(gentity_t *self) {
// fix stuck spawn points
if (gi.trace(self->s.origin, PLAYER_MINS, PLAYER_MAXS, self->s.origin, self, MASK_SOLID).startsolid)
G_FixStuckObject(self, self->s.origin);
// [Paril-KEX] on n64, since these can spawn riding elevators,
// allow them to "ride" the elevators so respawning works
if (level.is_n64) {
self->think = info_player_start_drop;
self->nextthink = level.time + FRAME_TIME_S;
}
deathmatch_spawn_flags(self);
}
/*QUAKED info_player_deathmatch (1 0 1) (-16 -16 -24) (16 16 32) INITIAL x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
A potential spawning position for deathmatch games.
The first time a player enters the game, they will be at an 'INITIAL' spot.
Targets will be fired when someone spawns in on them.
"nobots" will prevent bots from using this spot.
"nohumans" will prevent humans from using this spot.
*/
void SP_info_player_deathmatch(gentity_t *self) {
if (!deathmatch->integer) {
G_FreeEntity(self);
return;
}
SP_misc_teleporter_dest(self);
deathmatch_spawn_flags(self);
}
/*QUAKED info_player_team_red (1 0 0) (-16 -16 -24) (16 16 32) x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
A potential Red Team spawning position for CTF games.
*/
void SP_info_player_team_red(gentity_t *self) {}
/*QUAKED info_player_team_blue (0 0 1) (-16 -16 -24) (16 16 32) x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
A potential Blue Team spawning position for CTF games.
*/
void SP_info_player_team_blue(gentity_t *self) {}
/*QUAKED info_player_coop (1 0 1) (-16 -16 -24) (16 16 32) x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
A potential spawning position for coop games.
*/
void SP_info_player_coop(gentity_t *self) {
if (!coop->integer) {
G_FreeEntity(self);
return;
}
SP_info_player_start(self);
}
/*QUAKED info_player_coop_lava (1 0 1) (-16 -16 -24) (16 16 32) x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
A potential spawning position for coop games on rmine2 where lava level
needs to be checked.
*/
void SP_info_player_coop_lava(gentity_t *self) {
if (!coop->integer) {
G_FreeEntity(self);
return;
}
// fix stuck spawn points
if (gi.trace(self->s.origin, PLAYER_MINS, PLAYER_MAXS, self->s.origin, self, MASK_SOLID).startsolid)
G_FixStuckObject(self, self->s.origin);
}
/*QUAKED info_player_intermission (1 0 1) (-16 -16 -24) (16 16 32) x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
The deathmatch intermission point will be at one of these
Use 'angles' instead of 'angle', so you can set pitch or roll as well as yaw. 'pitch yaw roll'
*/
void SP_info_player_intermission(gentity_t *ent) {}
/*QUAKED info_ctf_teleport_destination (0.5 0.5 0.5) (-16 -16 -24) (16 16 32) x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
Point trigger_teleports at these.
*/
void SP_info_ctf_teleport_destination(gentity_t *ent) {
ent->s.origin[2] += 16;
}
// [Paril-KEX] whether instanced items should be used or not
bool P_UseCoopInstancedItems() {
// squad respawn forces instanced items on, since we don't
// want players to need to backtrack just to get their stuff.
return g_coop_instanced_items->integer || g_coop_squad_respawn->integer;
}
//=======================================================================
constexpr int8_t MAX_PLAYER_STOCK_MODELS = 3;
constexpr int8_t MAX_PLAYER_STOCK_SKINS = 24;
struct p_mods_skins_t {
const char *mname; // first model will be default model
const char *sname[MAX_PLAYER_STOCK_SKINS]; //index 0 will be default skin
};
p_mods_skins_t original_models[MAX_PLAYER_STOCK_MODELS] = {
{
"male",
{
"grunt",
"cipher", "claymore", "ctf_b",
"ctf_r", "deaddude", "disguise",
"flak", "howitzer", "insane1",
"insane2", "insane3", "major",
"nightops", "pointman", "psycho",
"rampage", "razor", "recon",
"rogue_b", "rogue_r", "scout",
"sniper", "viper"
}
},
{
"female",
{
"athena",
"brianna", "cobalt", "ctf_b",
"ctf_r", "disguise", "ensign",
"jezebel", "jungle", "lotus",
"rogue_b", "rogue_r", "stiletto",
"venus", "voodoo"
}
},
{
"cyborg",
{
"oni911",
"ctf_b", "ctf_r", "disguise",
"ps9000", "tyr574"
}
}
};
static const char *ClientSkinOverride(const char *s) {
if (g_allow_custom_skins->integer) {
//gi.Com_PrintFmt("{}: returning {}\n", __FUNCTION__, s);
return s;
}
size_t i;
std::string pm(s);
std::string ps(s);
std::string_view t(s);
if (i = t.find_first_of('/'); i != std::string_view::npos) {
pm = t.substr(0, i);
ps = t.substr(i + 1, strlen(s) - i - 1);
}
if (!pm.length()) {
pm = "male";
ps = "grunt";
}
// check stock model list
for (i = 0; i < MAX_PLAYER_STOCK_MODELS; i++) {
if (pm == original_models[i].mname) {
// found the model, now check stock skin list
for (size_t j = 0; j < MAX_PLAYER_STOCK_SKINS; j++)
if (ps == original_models[i].sname[j]) {
//return G_Fmt("{}/{}", pm, ps).data();
// found the skin, no change in player skin
return s;
}
// didn't find the skin but found the model, return model default skin
gi.Com_PrintFmt("{}: reverting to default skin for model: {} -> {}\n", __FUNCTION__, s, original_models[i].mname, original_models[i].sname[0]);
return G_Fmt("{}/{}", original_models[i].mname, original_models[i].sname[0]).data();
}
}
//gi.Com_PrintFmt("{}: returning {}\n", __FUNCTION__, s);
gi.Com_PrintFmt("{}: reverting to default model: {} -> male/grunt\n", __FUNCTION__, s);
return "male/grunt";
}
//=======================================================================
// PLAYER CONFIGS
//=======================================================================
/*
static void PCfg_WriteConfig(gentity_t *ent) {
if (!std::strcmp(ent->client->pers.social_id, "me_a_bot"))
return;
const char *name = G_Fmt("baseq2/pcfg/wtest/{}.cfg", ent->client->pers.social_id).data();
char *buffer = nullptr;
std::string string;
string.clear();
FILE *f = std::fopen(name, "wb");
if (!f)
return;
string = G_Fmt("// {}'s Player Config\n// Generated by Muff Mode\n", ent->client->resp.netname).data();
string += G_Fmt("name {}\n", ent->client->resp.netname).data();
string += G_Fmt("show_id {}\n", ent->client->sess.pc.show_id ? 1 : 0).data();
string += G_Fmt("show_fragmessages {}\n", ent->client->sess.pc.show_fragmessages ? 1 : 0).data();
string += G_Fmt("show_timer {}\n", ent->client->sess.pc.show_timer ? 1 : 0).data();
string += G_Fmt("killbeep_num {}\n", (int)ent->client->sess.pc.killbeep_num).data();
std::fwrite(buffer, 1, strlen(buffer), f);
std::fclose(f);
gi.Com_PrintFmt("Player config written to: \"{}\"\n", name);
}
*/
static void PCfg_ClientInitPConfig(gentity_t *ent) {
bool file_exists = false;
bool cfg_valid = true;
if (!ent->client) return;
if (ent->svflags & SVF_BOT) return;
// load up file
const char *name = G_Fmt("baseq2/pcfg/{}.cfg", ent->client->pers.social_id).data();
FILE *f = fopen(name, "rb");
if (f != NULL) {
char *buffer = nullptr;
size_t length;
size_t read_length;
fseek(f, 0, SEEK_END);
length = ftell(f);
fseek(f, 0, SEEK_SET);
if (length > 0x40000) {
cfg_valid = false;
}
if (cfg_valid) {
buffer = (char *)gi.TagMalloc(length + 1, '\0');
if (length) {
read_length = fread(buffer, 1, length, f);
if (length != read_length) {
cfg_valid = false;
}
}
}
file_exists = true;
fclose(f);
if (!cfg_valid) {
gi.Com_PrintFmt("{}: Player config load error for \"{}\", discarding.\n", __FUNCTION__, name);
return;
}
}
// save file if it doesn't exist
if (!file_exists) {
f = fopen(name, "w");
if (f) {
const char *str = G_Fmt("// {}'s Player Config\n// Generated by Muff Mode\n", ent->client->resp.netname).data();
fwrite(str, 1, strlen(str), f);
gi.Com_PrintFmt("{}: Player config written to: \"{}\"\n", __FUNCTION__, name);
fclose(f);
} else {
gi.Com_PrintFmt("{}: Cannot save player config: {}\n", __FUNCTION__, name);
}
} else {
//gi.Com_PrintFmt("{}: Player config not saved as file already exists: \"{}\"\n", __FUNCTION__, name);
}
}
//=======================================================================
struct mon_name_t {
const char *classname;
const char *longname;
};
mon_name_t monname[] = {
{ "monster_arachnid", "Arachnid" },
{ "monster_berserk", "Berserker" },
{ "monster_boss2", "Hornet" },
{ "monster_boss5", "Super Tank" },
{ "monster_brain", "Brains" },
{ "monster_carrier", "Carrier" },
{ "monster_chick", "Iron Maiden" },
{ "monster_chick_heat", "Iron Maiden" },
{ "monster_daedalus", "Daedalus" },
{ "monster_fixbot", "Fixbot" },
{ "monster_flipper", "Barracuda Shark" },
{ "monster_floater", "Technician" },
{ "monster_flyer", "Flyer" },
{ "monster_gekk", "Gekk" },
{ "monster_gladb", "Gladiator" },
{ "monster_gladiator", "Gladiator" },
{ "monster_guardian", "Guardian" },
{ "monster_guncmdr", "Gunner Commander" },
{ "monster_gunner", "Gunner" },
{ "monster_hover", "Icarus" },
{ "monster_infantry", "Infantry" },
{ "monster_jorg", "Jorg" },
{ "monster_kamikaze", "Kamikaze" },
{ "monster_makron", "Makron" },
{ "monster_medic", "Medic" },
{ "monster_medic_commander", "Medic Commander" },
{ "monster_mutant", "Mutant" },
{ "monster_parasite", "Parasite" },
{ "monster_shambler", "Shambler" },
{ "monster_soldier", "Machinegun Guard" },
{ "monster_soldier_hypergun", "Hypergun Guard" },
{ "monster_soldier_lasergun", "Laser Guard" },
{ "monster_soldier_light", "Light Guard" },
{ "monster_soldier_ripper", "Ripper Guard" },
{ "monster_soldier_ss", "Shotgun Guard" },
{ "monster_stalker", "Stalker" },
{ "monster_supertank", "Super Tank" },
{ "monster_tank", "Tank" },
{ "monster_tank_commander", "Tank Commander" },
{ "monster_turret", "Turret" },
{ "monster_widow", "Black Widow" },
{ "monster_widow2", "Black Widow" },
};
static const char *MonsterName(const char *classname) {
for (size_t i = 0; i < ARRAY_LEN(monname); i++) {
if (!Q_strncasecmp(classname, monname[i].classname, strlen(classname)))
return monname[i].longname;
}
}
static bool IsVowel(const char c) {
if (c == 'A' || c == 'a' ||
c == 'E' || c == 'e' ||
c == 'I' || c == 'i' ||
c == 'O' || c == 'o' ||
c == 'U' || c == 'u')
return true;
return false;
}
static void ClientObituary(gentity_t *self, gentity_t *inflictor, gentity_t *attacker, mod_t mod) {
const char *base = nullptr;
if (InCoopStyle() && attacker->client)
mod.friendly_fire = true;
if (mod.id == MOD_CHANGE_TEAM)
return;
switch (mod.id) {
case MOD_SUICIDE:
base = "$g_mod_generic_suicide";
break;
case MOD_FALLING:
base = "$g_mod_generic_falling";
break;
case MOD_CRUSH:
base = "$g_mod_generic_crush";
break;
case MOD_WATER:
base = "$g_mod_generic_water";
break;
case MOD_SLIME:
base = "$g_mod_generic_slime";
break;
case MOD_LAVA:
base = "$g_mod_generic_lava";
break;
case MOD_EXPLOSIVE:
case MOD_BARREL:
base = "$g_mod_generic_explosive";
break;
case MOD_EXIT:
base = "$g_mod_generic_exit";
break;
case MOD_TARGET_LASER:
base = "$g_mod_generic_laser";
break;
case MOD_TARGET_BLASTER:
base = "$g_mod_generic_blaster";
break;
case MOD_BOMB:
case MOD_SPLASH:
case MOD_TRIGGER_HURT:
base = "$g_mod_generic_hurt";
break;
/*
case MOD_GEKK:
case MOD_BRAINTENTACLE:
base = "$g_mod_generic_gekk";
break;
*/
case MOD_EXPIRE:
base = "$g_mod_generic_suicide";
break;
default:
base = nullptr;
break;
}
if (attacker == self) {
switch (mod.id) {
case MOD_HELD_GRENADE:
base = "$g_mod_self_held_grenade";
break;
case MOD_HG_SPLASH:
case MOD_G_SPLASH:
base = "$g_mod_self_grenade_splash";
break;
case MOD_R_SPLASH:
base = "$g_mod_self_rocket_splash";
break;
case MOD_BFG_BLAST:
base = "$g_mod_self_bfg_blast";
break;
case MOD_TRAP:
base = "$g_mod_self_trap";
break;
case MOD_DOPPEL_EXPLODE:
base = "$g_mod_self_dopple_explode";
break;
default:
base = "$g_mod_self_default";
break;
}
}
// send generic/self
if (base) {
gi.LocBroadcast_Print(PRINT_MEDIUM, base, self->client->resp.netname);
self->enemy = nullptr;
return;
}
// has a killer
self->enemy = attacker;
if (!attacker)
return;
if (attacker->svflags & SVF_MONSTER) {
const char *monname = MonsterName(attacker->classname);
if (monname)
gi.LocBroadcast_Print(PRINT_MEDIUM, "{} was killed by a{} {}\n", self->client->resp.netname, IsVowel(monname[0]) ? "n" : "", monname);
return;
}
if (!attacker->client)
return;
switch (mod.id) {
case MOD_BLASTER:
base = "$g_mod_kill_blaster";
break;
case MOD_SHOTGUN:
base = "$g_mod_kill_shotgun";
break;
case MOD_SSHOTGUN:
base = "$g_mod_kill_sshotgun";
break;
case MOD_MACHINEGUN:
base = "$g_mod_kill_machinegun";
break;
case MOD_CHAINGUN:
base = "$g_mod_kill_chaingun";
break;
case MOD_GRENADE:
base = "$g_mod_kill_grenade";
break;
case MOD_G_SPLASH:
base = "$g_mod_kill_grenade_splash";
break;
case MOD_ROCKET:
base = "$g_mod_kill_rocket";
break;
case MOD_R_SPLASH:
base = "$g_mod_kill_rocket_splash";
break;
case MOD_HYPERBLASTER:
base = "$g_mod_kill_hyperblaster";
break;
case MOD_RAILGUN:
base = "$g_mod_kill_railgun";
break;
case MOD_BFG_LASER:
base = "$g_mod_kill_bfg_laser";
break;
case MOD_BFG_BLAST:
base = "$g_mod_kill_bfg_blast";
break;
case MOD_BFG_EFFECT:
base = "$g_mod_kill_bfg_effect";
break;
case MOD_HANDGRENADE:
base = "$g_mod_kill_handgrenade";
break;
case MOD_HG_SPLASH:
base = "$g_mod_kill_handgrenade_splash";
break;
case MOD_HELD_GRENADE:
base = "$g_mod_kill_held_grenade";
break;
case MOD_TELEFRAG:
case MOD_TELEFRAG_SPAWN:
base = "$g_mod_kill_telefrag";
break;
case MOD_RIPPER:
base = "$g_mod_kill_ripper";
break;
case MOD_PHALANX:
base = "$g_mod_kill_phalanx";
break;
case MOD_TRAP:
base = "$g_mod_kill_trap";
break;
case MOD_CHAINFIST:
base = "$g_mod_kill_chainfist";
break;
case MOD_DISINTEGRATOR:
base = "$g_mod_kill_disintegrator";
break;
case MOD_ETF_RIFLE:
base = "$g_mod_kill_etf_rifle";
break;
case MOD_PLASMABEAM:
base = "$g_mod_kill_heatbeam";
break;
case MOD_TESLA:
base = "$g_mod_kill_tesla";
break;
case MOD_PROX:
base = "$g_mod_kill_prox";
break;
case MOD_NUKE:
base = "$g_mod_kill_nuke";
break;
case MOD_VENGEANCE_SPHERE:
base = "$g_mod_kill_vengeance_sphere";
break;
case MOD_DEFENDER_SPHERE:
base = "$g_mod_kill_defender_sphere";
break;
case MOD_HUNTER_SPHERE:
base = "$g_mod_kill_hunter_sphere";
break;
case MOD_TRACKER:
base = "$g_mod_kill_tracker";
break;
case MOD_DOPPEL_EXPLODE:
base = "$g_mod_kill_dopple_explode";
break;
case MOD_DOPPEL_VENGEANCE:
base = "$g_mod_kill_dopple_vengeance";
break;
case MOD_DOPPEL_HUNTER:
base = "$g_mod_kill_dopple_hunter";
break;
case MOD_GRAPPLE:
base = "$g_mod_kill_grapple";
break;
default:
base = "$g_mod_kill_generic";
break;
}
gi.LocBroadcast_Print(PRINT_MEDIUM, base, self->client->resp.netname, attacker->client->resp.netname);
if (Teams()) {
// if at start and same team, clear.
// [Paril-KEX] moved here so it's not an outlier in player_die.
if (mod.id == MOD_TELEFRAG_SPAWN &&
self->client->resp.ctf_state < 2 &&
self->client->sess.team == attacker->client->sess.team) {
self->client->resp.ctf_state = 0;
return;
}
}
// frag messages
if (deathmatch->integer && self != attacker && self->client && attacker->client) {
if (!(self->svflags & SVF_BOT)) {
if (level.match_state == matchst_t::MATCH_WARMUP_READYUP) {
BroadcastReadyReminderMessage();
} else {
if (level.round_state == roundst_t::ROUND_IN_PROGRESS) {
gi.LocClient_Print(self, PRINT_CENTER, "You were fragged by {}\nYou will respawn next round.", attacker->client->resp.netname);
} else {
gi.LocClient_Print(self, PRINT_CENTER, "You were fragged by {}", attacker->client->resp.netname);
}
}
}
if (!(attacker->svflags & SVF_BOT)) {
if (Teams() && OnSameTeam(self, attacker)) {
gi.LocClient_Print(attacker, PRINT_CENTER, "You fragged {}, your team mate :(", self->client->resp.netname);
} else {
if (level.match_state == matchst_t::MATCH_WARMUP_READYUP) {
BroadcastReadyReminderMessage();
} else if (attacker->client->resp.kill_count && !(attacker->client->resp.kill_count % 10)) {
gi.LocBroadcast_Print(PRINT_CENTER, "{} is on a fragging spree\nwith {} frags!", attacker->client->resp.netname, attacker->client->resp.kill_count);
} else if (self->client->resp.kill_count >= 10) {
gi.LocBroadcast_Print(PRINT_CENTER, "{} put an end to {}'s\nfragging spree!", attacker->client->resp.netname, self->client->resp.netname);
} else if (Teams() || level.match_state != matchst_t::MATCH_IN_PROGRESS) {
if (attacker->client->sess.pc.show_fragmessages)
gi.LocClient_Print(attacker, PRINT_CENTER, "You fragged {}", self->client->resp.netname);
} else {
if (attacker->client->sess.pc.show_fragmessages)
gi.LocClient_Print(attacker, PRINT_CENTER, "You fragged {}\n{} place with {}",
self->client->resp.netname, G_PlaceString(attacker->client->resp.rank + 1), attacker->client->resp.score);
}
}
if (attacker->client->sess.pc.killbeep_num > 0 && attacker->client->sess.pc.killbeep_num < 5) {
const char *sb[5] = { "", "nav_editor/select_node.wav", "misc/comp_up.wav", "insane/insane7.wav", "nav_editor/finish_node_move.wav" };
gi.local_sound(attacker, CHAN_AUTO, gi.soundindex(sb[attacker->client->sess.pc.killbeep_num]), 1, ATTN_NONE, 0);
}
}
}
self->client->resp.kill_count = 0;
if (base)
return;
gi.LocBroadcast_Print(PRINT_MEDIUM, "$g_mod_generic_died", self->client->resp.netname);
}
/*
=================
TossClientItems
Toss the weapon, tech, CTF flag and powerups for the killed player
=================
*/
static void TossClientItems(gentity_t *self) {
if (!deathmatch->integer)
return;
// don't drop anything when combat is disabled
if (IsCombatDisabled())
return;
gitem_t *wp;
gentity_t *drop;
bool quad, doubled, duelfire, protection, invis, regen;
// drop weapon
wp = self->client->pers.weapon;
if (wp) {
if (g_instagib->integer)
wp = nullptr;
else if (g_nadefest->integer)
wp = nullptr;
else if (!self->client->pers.inventory[self->client->pers.weapon->ammo])
wp = nullptr;
else if (!wp->drop)
wp = nullptr;
else if (RS(RS_Q3A) && wp->id == IT_WEAPON_MACHINEGUN)
wp = nullptr;
else if (RS(RS_Q1) && wp->id == IT_WEAPON_SHOTGUN)
wp = nullptr;
if (wp) {
self->client->v_angle[YAW] = 0.0;
drop = Drop_Item(self, wp);
drop->spawnflags |= SPAWNFLAG_ITEM_DROPPED_PLAYER;
drop->spawnflags &= ~SPAWNFLAG_ITEM_DROPPED;
drop->svflags &= ~SVF_INSTANCED;
}
}
//drop tech
Tech_DeadDrop(self);
// drop powerup
quad = g_dm_no_quad_drop->integer ? false : (self->client->pu_time_quad > (level.time + 1_sec));
duelfire = g_dm_no_quadfire_drop->integer ? false : (self->client->pu_time_duelfire > (level.time + 1_sec));
doubled = (self->client->pu_time_double > (level.time + 1_sec));
protection = (self->client->pu_time_protection > (level.time + 1_sec));
invis = (self->client->pu_time_invisibility > (level.time + 1_sec));
regen = (self->client->pu_time_regeneration > (level.time + 1_sec));
if (!g_dm_powerup_drop->integer) {
quad = doubled = duelfire = protection = invis = regen = false;
}
if (quad) {
self->client->v_angle[YAW] += 45.0;
drop = Drop_Item(self, GetItemByIndex(IT_POWERUP_QUAD));
drop->spawnflags |= SPAWNFLAG_ITEM_DROPPED_PLAYER;
drop->spawnflags &= ~SPAWNFLAG_ITEM_DROPPED;
drop->svflags &= ~SVF_INSTANCED;
drop->touch = Touch_Item;
drop->nextthink = self->client->pu_time_quad;
drop->think = g_quadhog->integer ? QuadHog_DoReset : G_FreeEntity;
if (g_quadhog->integer) {
drop->s.renderfx |= RF_SHELL_BLUE;
drop->s.effects |= EF_COLOR_SHELL;
}
// decide how many seconds it has left
drop->count = self->client->pu_time_quad.seconds<int>() - level.time.seconds<int>();
if (drop->count < 1) {
drop->count = 1;
}
}
if (duelfire) {
self->client->v_angle[YAW] += 45;
drop = Drop_Item(self, GetItemByIndex(IT_POWERUP_DUELFIRE));
drop->spawnflags |= SPAWNFLAG_ITEM_DROPPED_PLAYER;
drop->spawnflags &= ~SPAWNFLAG_ITEM_DROPPED;
drop->svflags &= ~SVF_INSTANCED;
drop->touch = Touch_Item;
drop->nextthink = self->client->pu_time_duelfire;
drop->think = G_FreeEntity;
// decide how many seconds it has left
drop->count = self->client->pu_time_duelfire.seconds<int>() - level.time.seconds<int>();
if (drop->count < 1) {
drop->count = 1;
}
}
if (protection) {
self->client->v_angle[YAW] += 45;
drop = Drop_Item(self, GetItemByIndex(IT_POWERUP_PROTECTION));
drop->spawnflags |= SPAWNFLAG_ITEM_DROPPED_PLAYER;
drop->spawnflags &= ~SPAWNFLAG_ITEM_DROPPED;
drop->svflags &= ~SVF_INSTANCED;
drop->touch = Touch_Item;
drop->nextthink = self->client->pu_time_protection;
drop->think = G_FreeEntity;
// decide how many seconds it has left
drop->count = self->client->pu_time_protection.seconds<int>() - level.time.seconds<int>();
if (drop->count < 1) {
drop->count = 1;
}
}
if (regen) {
self->client->v_angle[YAW] += 45;
drop = Drop_Item(self, GetItemByIndex(IT_POWERUP_REGEN));
drop->spawnflags |= SPAWNFLAG_ITEM_DROPPED_PLAYER;
drop->spawnflags &= ~SPAWNFLAG_ITEM_DROPPED;
drop->svflags &= ~SVF_INSTANCED;
drop->touch = Touch_Item;
drop->nextthink = self->client->pu_time_regeneration;
drop->think = G_FreeEntity;
// decide how many seconds it has left
drop->count = self->client->pu_time_regeneration.seconds<int>() - level.time.seconds<int>();
if (drop->count < 1) {
drop->count = 1;
}
}
if (invis) {
self->client->v_angle[YAW] += 45;
drop = Drop_Item(self, GetItemByIndex(IT_POWERUP_INVISIBILITY));
drop->spawnflags |= SPAWNFLAG_ITEM_DROPPED_PLAYER;
drop->spawnflags &= ~SPAWNFLAG_ITEM_DROPPED;
drop->svflags &= ~SVF_INSTANCED;
drop->touch = Touch_Item;
drop->nextthink = self->client->pu_time_invisibility;
drop->think = G_FreeEntity;
// decide how many seconds it has left
drop->count = self->client->pu_time_invisibility.seconds<int>() - level.time.seconds<int>();
if (drop->count < 1) {
drop->count = 1;
}
}
if (doubled) {
self->client->v_angle[YAW] += 45;
drop = Drop_Item(self, GetItemByIndex(IT_POWERUP_DOUBLE));
drop->spawnflags |= SPAWNFLAG_ITEM_DROPPED_PLAYER;
drop->spawnflags &= ~SPAWNFLAG_ITEM_DROPPED;
drop->svflags &= ~SVF_INSTANCED;
drop->touch = Touch_Item;
drop->nextthink = self->client->pu_time_double;
drop->think = G_FreeEntity;
// decide how many seconds it has left
drop->count = self->client->pu_time_double.seconds<int>() - level.time.seconds<int>();
if (drop->count < 1) {
drop->count = 1;
}
}
self->client->v_angle[YAW] = 0.0;
}
/*
==================
LookAtKiller
==================
*/
void LookAtKiller(gentity_t *self, gentity_t *inflictor, gentity_t *attacker) {
vec3_t dir;
if (attacker && attacker != world && attacker != self) {
dir = attacker->s.origin - self->s.origin;
} else if (inflictor && inflictor != world && inflictor != self) {
dir = inflictor->s.origin - self->s.origin;
} else {
self->client->killer_yaw = self->s.angles[YAW];
return;
}
// PMM - fixed to correct for pitch of 0
if (dir[0])
self->client->killer_yaw = 180 / PIf * atan2f(dir[1], dir[0]);
else if (dir[1] > 0)
self->client->killer_yaw = 90;
else if (dir[1] < 0)
self->client->killer_yaw = 270;
else
self->client->killer_yaw = 0;
}
/*
================
Match_CanScore
================
*/
static bool Match_CanScore() {
if (level.intermission_queued)
return false;
switch (level.match_state) {
case matchst_t::MATCH_WARMUP_DELAYED:
case matchst_t::MATCH_WARMUP_DEFAULT:
case matchst_t::MATCH_WARMUP_READYUP:
case matchst_t::MATCH_COUNTDOWN:
case matchst_t::MATCH_ENDED:
return false;
}
return true;
}
/*
==================
player_die
==================
*/
DIE(player_die) (gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, const vec3_t &point, const mod_t &mod) -> void {
if (self->client->ps.pmove.pm_type == PM_DEAD)
return;
PlayerTrail_Destroy(self);
self->avelocity = {};
self->takedamage = true;
self->movetype = MOVETYPE_TOSS;
self->s.modelindex2 = 0; // remove linked weapon model
self->s.modelindex3 = 0; // remove linked ctf flag
self->s.angles[PITCH] = 0;
self->s.angles[ROLL] = 0;
self->s.sound = 0;
self->client->weapon_sound = 0;
self->maxs[2] = -8;
if (attacker && attacker->client && level.match_state == matchst_t::MATCH_IN_PROGRESS) {
if (attacker == self || mod.friendly_fire) {
if (!mod.no_point_loss)
G_AdjustPlayerScore(attacker->client, -1, false, -1);
attacker->client->resp.kill_count = 0;
} else {
G_AdjustPlayerScore(attacker->client, 1, false, 1);
if (attacker->health > 0)
attacker->client->resp.kill_count++;
MS_Adjust(attacker->client, MSTAT_KILLS, 1);
}
} else {
if (!mod.no_point_loss)
G_AdjustPlayerScore(self->client, -1, false, -1);
}
MS_Adjust(self->client, MSTAT_DEATHS, 1);
self->svflags |= SVF_DEADMONSTER;
if (!self->deadflag) {
self->client->respawn_time = (level.time + 1_sec);
self->client->respawn_min_time = (level.time + gtime_t::from_sec(g_dm_respawn_delay_min->value));
if (deathmatch->integer && g_dm_force_respawn_time->integer) {
self->client->respawn_time = (level.time + gtime_t::from_sec(g_dm_force_respawn_time->value));
}
LookAtKiller(self, inflictor, attacker);
self->client->ps.pmove.pm_type = PM_DEAD;
ClientObituary(self, inflictor, attacker, mod);
TossClientItems(self);
Weapon_Grapple_DoReset(self->client);
if (deathmatch->integer && !self->client->showscores)
Cmd_Help_f(self); // show scores
if (coop->integer && !P_UseCoopInstancedItems()) {
// clear inventory
// this is kind of ugly, but it's how we want to handle keys in coop
for (int n = 0; n < IT_TOTAL; n++) {
if (itemlist[n].flags & IF_KEY)
self->client->resp.coop_respawn.inventory[n] = self->client->pers.inventory[n];
self->client->pers.inventory[n] = 0;
}
}
}
// remove powerups
self->client->pu_time_quad = 0_ms;
self->client->pu_time_duelfire = 0_ms;
self->client->pu_time_double = 0_ms;
self->client->pu_time_protection = 0_ms;
self->client->pu_time_invisibility = 0_ms;
self->client->pu_time_regeneration = 0_ms;
self->client->pu_time_rebreather = 0_ms;
self->client->pu_time_enviro = 0_ms;
self->flags &= ~FL_POWER_ARMOR;
// clear inventory
if (Teams())
self->client->pers.inventory.fill(0);
// if there's a sphere around, let it know the player died.
// vengeance and hunter will die if they're not attacking,
// defender should always die
if (self->client->owned_sphere) {
gentity_t *sphere;
sphere = self->client->owned_sphere;
sphere->die(sphere, self, self, 0, vec3_origin, mod);
}
// if we've been killed by the tracker, GIB!
if (mod.id == MOD_TRACKER) {
self->health = -100;
damage = 400;
}
self->s.effects = EF_NONE;
self->s.renderfx = RF_NONE;
// make sure no trackers are still hurting us.
if (self->client->tracker_pain_time) {
RemoveAttackingPainDaemons(self);
}
// if we got obliterated by the nuke, don't gib
if ((self->health < -80) && (mod.id == MOD_NUKE))
self->flags |= FL_NOGIB;
if (self->health < GIB_HEALTH) {
// don't toss gibs if we got vaped by the nuke
if (!(self->flags & FL_NOGIB)) {
// gib