-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.qc
2023 lines (1721 loc) · 45 KB
/
client.qc
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
#include "m_player.h"
#ifdef SINGLE_PLAYER
//
// Gross, ugly, disgustuing hack section
//
// this function is an ugly as hell hack to fix some map flaws
//
// the coop spawn spots on some maps are SNAFU. There are coop spots
// with the wrong targetname as well as spots with no name at all
//
// we use carnal knowledge of the maps to fix the coop spot targetnames to match
// that of the nearest named single player spot
static void(entity self) SP_FixCoopSpots =
{
entity spot = world;
while ((spot = G_Find(spot, classname, "info_player_start")))
{
if (!spot.targetname)
continue;
vector d = self.s.origin - spot.s.origin;
if (VectorLength(d) < 384)
{
if (!striequals(self.targetname, spot.targetname))
self.targetname = spot.targetname;
return;
}
}
}
// now if that one wasn't ugly enough for you then try this one on for size
// some maps don't have any coop spots at all, so we need to create them
// where they should have been
static void(entity self) SP_CreateCoopSpots =
{
if (level.mapname == "security")
{
entity spot = G_Spawn();
spot.classname = "info_player_coop";
spot.s.origin[0] = 188f - 64f;
spot.s.origin[1] = -164f;
spot.s.origin[2] = 80f;
spot.targetname = "jail3";
spot.s.angles[1] = 90f;
spot = G_Spawn();
spot.classname = "info_player_coop";
spot.s.origin[0] = 188f + 64f;
spot.s.origin[1] = -164f;
spot.s.origin[2] = 80f;
spot.targetname = "jail3";
spot.s.angles[1] = 90f;
spot = G_Spawn();
spot.classname = "info_player_coop";
spot.s.origin[0] = 188f + 128f;
spot.s.origin[1] = -164f;
spot.s.origin[2] = 80f;
spot.targetname = "jail3";
spot.s.angles[1] = 90f;
}
}
#endif
/*QUAKED info_player_start (1 0 0) (-16 -16 -24) (16 16 32)
The normal starting point for a level.
*/
API_FUNC static void(entity self) SP_info_player_start =
{
#ifdef SINGLE_PLAYER
if (!coop.intVal)
return;
if (level.mapname == "security")
{
// invoke one of our gross, ugly, disgusting hacks
self.think = SP_CreateCoopSpots;
self.nextthink = level.framenum + 1;
}
#endif
}
void(entity) SP_misc_teleporter_dest;
/*QUAKED info_player_deathmatch (1 0 1) (-16 -16 -24) (16 16 32)
potential spawning position for deathmatch games
*/
API_FUNC static void(entity self) SP_info_player_deathmatch =
{
#ifdef SINGLE_PLAYER
if (!deathmatch.intVal)
{
G_FreeEdict(self);
return;
}
#endif
SP_misc_teleporter_dest(self);
}
#ifdef SINGLE_PLAYER
/*QUAKED info_player_coop (1 0 1) (-16 -16 -24) (16 16 32)
potential spawning position for coop games
*/
API_FUNC static void(entity self) SP_info_player_coop =
{
if (!coop.intVal)
{
G_FreeEdict(self);
return;
}
if (level.mapname == "jail2" ||
level.mapname == "jail4" ||
level.mapname == "mine1" ||
level.mapname == "mine2" ||
level.mapname == "mine3" ||
level.mapname == "mine4" ||
level.mapname == "lab" ||
level.mapname == "boss1" ||
level.mapname == "fact3" ||
level.mapname == "biggun" ||
level.mapname == "space" ||
level.mapname == "command" ||
level.mapname == "power2" ||
level.mapname == "strike")
{
// invoke one of our gross, ugly, disgusting hacks
self.think = SP_FixCoopSpots;
self.nextthink = level.framenum + 1;
}
}
#endif
/*QUAKED info_player_intermission (1 0 1) (-16 -16 -24) (16 16 32)
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'
*/
API_FUNC static void() SP_info_player_intermission =
{
}
#if defined(GROUND_ZERO) && defined(SINGLE_PLAYER)
/*QUAKED info_player_coop_lava (1 0 1) (-16 -16 -24) (16 16 32)
potential spawning position for coop games on rmine2 where lava level
needs to be checked
*/
API_FUNC static void(entity self) SP_info_player_coop_lava =
{
if (!coop.intVal)
{
G_FreeEdict (self);
return;
}
}
#endif
//=======================================================================
void(entity self, entity other, float kick, int damage) player_pain =
{
// player pain is handled at the end of the frame in P_DamageFeedback
}
typedef enum : int
{
GENDER_MALE,
GENDER_FEMALE,
GENDER_NEUTRAL
} gender_t;
static gender_t(entity ent) GetGender =
{
if (!ent.is_client)
return GENDER_MALE;
string info = Info_ValueForKey(ent.client.pers.userinfo, "gender");
if (strat(info, 0) == 'f' || strat(info, 0) == 'F')
return GENDER_FEMALE;
else if (strat(info, 0) != 'm' && strat(info, 0) != 'm')
return GENDER_NEUTRAL;
return GENDER_MALE;
}
// from cmds.qc
bool(entity, entity) OnSameTeam;
PROGS_LOCAL means_of_death_t meansOfDeath;
static void(entity self, entity inflictor, entity attacker) ClientObituary =
{
if (OnSameTeam(self, attacker))
meansOfDeath |= MOD_FRIENDLY_FIRE;
int ff = meansOfDeath & MOD_FRIENDLY_FIRE;
int mod = meansOfDeath & ~MOD_FRIENDLY_FIRE;
string message = 0;
string message2 = 0;
gender_t gender = GetGender(self);
static const string their[] = {
"his",
"her",
"their"
};
static const string themself[] = {
"himself",
"herself",
"themself"
};
switch (mod)
{
case MOD_SUICIDE:
message = "suicides";
break;
case MOD_FALLING:
message = "cratered";
break;
case MOD_CRUSH:
message = "was squished";
break;
case MOD_WATER:
message = "sank like a rock";
break;
case MOD_SLIME:
message = "melted";
break;
case MOD_LAVA:
message = "does a back flip into the lava";
break;
case MOD_EXPLOSIVE:
case MOD_BARREL:
message = "blew up";
break;
case MOD_EXIT:
message = "found a way out";
break;
case MOD_TARGET_LASER:
message = "saw the light";
break;
case MOD_TARGET_BLASTER:
message = "got blasted";
break;
case MOD_BOMB:
case MOD_SPLASH:
case MOD_TRIGGER_HURT:
message = "was in the wrong place";
break;
#ifdef THE_RECKONING
case MOD_GEKK:
case MOD_BRAINTENTACLE:
message = "... that's gotta hurt!";
break;
#endif
}
if (attacker == self)
{
switch (mod)
{
case MOD_HELD_GRENADE:
message = "tried to put the pin back in";
break;
case MOD_HG_SPLASH:
case MOD_G_SPLASH:
message = va("tripped on %s own grenade", their[gender]);
break;
case MOD_R_SPLASH:
message = va("blew %s up", themself[gender]);
break;
case MOD_BFG_BLAST:
message = "should have used a smaller gun";
break;
#ifdef THE_RECKONING
case MOD_TRAP:
message = va("was sucked into %s own trap", their[gender]);
break;
#endif
default:
message = va("killed %s", themself[gender]);
break;
}
}
if (message)
{
gi.bprintf(PRINT_MEDIUM, "%s %s.\n", self.client.pers.netname, message);
#ifdef SINGLE_PLAYER
if (deathmatch.intVal)
#endif
self.client.resp.score--;
self.enemy = world;
return;
}
self.enemy = attacker;
if (attacker && attacker.is_client)
{
switch (mod) {
case MOD_BLASTER:
message = "was blasted by";
break;
case MOD_SHOTGUN:
message = "was gunned down by";
break;
case MOD_SSHOTGUN:
message = "was blown away by";
message2 = "'s super shotgun";
break;
case MOD_MACHINEGUN:
message = "was machinegunned by";
break;
case MOD_CHAINGUN:
message = "was cut in half by";
message2 = "'s chaingun";
break;
case MOD_GRENADE:
message = "was popped by";
message2 = "'s grenade";
break;
case MOD_G_SPLASH:
message = "was shredded by";
message2 = "'s shrapnel";
break;
case MOD_ROCKET:
message = "ate";
message2 = "'s rocket";
break;
case MOD_R_SPLASH:
message = "almost dodged";
message2 = "'s rocket";
break;
case MOD_HYPERBLASTER:
message = "was melted by";
message2 = "'s hyperblaster";
break;
case MOD_RAILGUN:
message = "was railed by";
break;
case MOD_BFG_LASER:
message = "saw the pretty lights from";
message2 = "'s BFG";
break;
case MOD_BFG_BLAST:
message = "was disintegrated by";
message2 = "'s BFG blast";
break;
case MOD_BFG_EFFECT:
message = "couldn't hide from";
message2 = "'s BFG";
break;
case MOD_HANDGRENADE:
message = "caught";
message2 = "'s handgrenade";
break;
case MOD_HG_SPLASH:
message = "didn't see";
message2 = "'s handgrenade";
break;
case MOD_HELD_GRENADE:
message = "feels";
message2 = "'s pain";
break;
case MOD_TELEFRAG:
message = "tried to invade";
message2 = "'s personal space";
break;
#ifdef THE_RECKONING
case MOD_RIPPER:
message = "was ripped to shreds by";
message2 = "'s ripper gun";
break;
case MOD_PHALANX:
message = "was evaporated by";
break;
case MOD_TRAP:
message = "was caught in";
message2 = "'s trap";
break;
#endif
#ifdef GROUND_ZERO
case MOD_CHAINFIST:
message = "was shredded by";
message2 = "'s ripsaw";
break;
case MOD_DISINTEGRATOR:
message = "lost his grip courtesy of";
message2 = "'s disintegrator";
break;
case MOD_ETF_RIFLE:
message = "was perforated by";
break;
case MOD_HEATBEAM:
message = "was scorched by";
message2 = "'s plasma beam";
break;
case MOD_TESLA:
message = "was enlightened by";
message2 = "'s tesla mine";
break;
case MOD_PROX:
message = "got too close to";
message2 = "'s proximity mine";
break;
case MOD_NUKE:
message = "was nuked by";
message2 = "'s antimatter bomb";
break;
case MOD_TRACKER:
message = "was annihilated by";
message2 = "'s disruptor";
break;
#endif
#ifdef HOOK_CODE
case MOD_GRAPPLE:
message = "was caught by";
message2 = "'s grapple";
break;
#endif
}
if (message)
{
gi.bprintf(PRINT_MEDIUM, "%s %s %s%s\n", self.client.pers.netname, message, attacker.client.pers.netname, message2);
#ifdef SINGLE_PLAYER
if (deathmatch.intVal)
{
#endif
if (ff)
attacker.client.resp.score--;
else
attacker.client.resp.score++;
#ifdef SINGLE_PLAYER
}
#endif
return;
}
}
}
static void(entity self) TossClientWeapon =
{
#ifdef SINGLE_PLAYER
if (!deathmatch.intVal)
return;
#endif
gitem_t *it = self.client.pers.weapon;
if (!self.client.pers.inventory[self.client.ammo_index] || it->pickup_name == "Blaster")
it = 0;
bool quad = (dmflags.intVal & DF_QUAD_DROP) && (self.client.quad_framenum > (level.framenum + 10));
#ifdef THE_RECKONING
bool quadfire = (dmflags.intVal & DF_QUADFIRE_DROP) && (self.client.quadfire_framenum > (level.framenum + 10));
#endif
float spread;
if (it && quad)
spread = 22.5f;
#ifdef THE_RECKONING
else if (it && quadfire)
spread = 12.5;
#endif
else
spread = 0.0f;
if (it)
{
self.client.v_angle[YAW] -= spread;
entity drop = Drop_Item(self, it);
self.client.v_angle[YAW] += spread;
drop.spawnflags = DROPPED_PLAYER_ITEM;
}
if (quad)
{
self.client.v_angle[YAW] += spread;
entity drop = Drop_Item(self, GetItemByIndex(ITEM_QUAD_DAMAGE));
self.client.v_angle[YAW] -= spread;
drop.spawnflags |= DROPPED_PLAYER_ITEM;
drop.touch = Touch_Item;
drop.nextthink = self.client.quad_framenum;
drop.think = G_FreeEdict;
}
#ifdef THE_RECKONING
if (quadfire)
{
self.client.v_angle[YAW] += spread;
entity drop = Drop_Item (self, GetItemByIndex(ITEM_DUALFIRE_DAMAGE));
self.client.v_angle[YAW] -= spread;
drop.spawnflags |= DROPPED_PLAYER_ITEM;
drop.touch = Touch_Item;
drop.nextthink = self.client.quadfire_framenum;
drop.think = G_FreeEdict;
}
#endif
}
/*
==================
LookAtKiller
==================
*/
void(entity self, entity inflictor, entity attacker) LookAtKiller =
{
if (attacker && attacker != self)
self.client.killer_yaw = vectoyaw(attacker.s.origin - self.s.origin);
else if (inflictor && inflictor != self)
self.client.killer_yaw = vectoyaw(inflictor.s.origin - self.s.origin);
else
self.client.killer_yaw = self.s.angles[YAW];
}
// from hud.qc
void(entity) Cmd_Help_f;
// from misc.qc
void(entity, string, int, int) ThrowGib;
void(entity, int) ThrowClientHead;
#ifdef HOOK_CODE
void(entity) GrapplePlayerReset;
#endif
#ifdef CTF
void(entity, entity, entity) CTFFragBonuses;
void(entity) CTFDeadDropFlag;
void(entity) CTFDeadDropTech;
#endif
/*
==================
player_die
==================
*/
void(entity self, entity inflictor, entity attacker, int damage, vector point) player_die =
{
self.avelocity = vec3_origin;
self.takedamage = true;
self.movetype = MOVETYPE_TOSS;
self.s.modelindex2 = 0; // remove linked weapon model
#ifdef CTF
self.s.modelindex3 = 0; // remove linked flag
#endif
self.s.angles[PITCH] = 0;
self.s.angles[ROLL] = 0;
self.s.sound = 0;
self.client.weapon_sound = 0;
self.maxs.z = -8f;
self.svflags |= SVF_DEADMONSTER;
if (!self.deadflag)
{
self.client.respawn_framenum = (int)(level.framenum + 1.0f * BASE_FRAMERATE);
LookAtKiller(self, inflictor, attacker);
self.client.ps.pmove.pm_type = PM_DEAD;
ClientObituary(self, inflictor, attacker);
#ifdef CTF
// if at start and same team, clear
if (ctf.intVal && meansOfDeath == MOD_TELEFRAG &&
self.client.resp.ctf_state < 2 &&
self.client.resp.ctf_team == attacker.client.resp.ctf_team)
{
attacker.client.resp.score--;
self.client.resp.ctf_state = 0;
}
CTFFragBonuses(self, inflictor, attacker);
#endif
TossClientWeapon(self);
#ifdef HOOK_CODE
GrapplePlayerReset(self);
#endif
#ifdef CTF
CTFDeadDropFlag(self);
CTFDeadDropTech(self);
#endif
#ifdef SINGLE_PLAYER
if (deathmatch.intVal)
#endif
Cmd_Help_f(self); // show scores
// clear inventory
// this is kind of ugly, but it's how we want to handle keys in coop
for (int n = 0; n < itemlist.length; n++)
#ifdef SINGLE_PLAYER
{
if (coop.intVal && itemlist[n].flags & IT_KEY)
self.client.resp.coop_respawn.inventory[n] = self.client.pers.inventory[n];
#endif
self.client.pers.inventory[n] = 0;
#ifdef SINGLE_PLAYER
}
#endif
}
// remove powerups
self.client.quad_framenum = 0;
self.client.invincible_framenum = 0;
self.client.breather_framenum = 0;
self.client.enviro_framenum = 0;
#ifdef THE_RECKONING
self.client.quadfire_framenum = 0;
#endif
self.flags &= ~FL_POWER_ARMOR;
#ifdef GROUND_ZERO
self.client.double_framenum = 0;
// if we've been killed by the tracker, GIB!
if ((meansOfDeath & ~MOD_FRIENDLY_FIRE) == MOD_TRACKER)
{
self.health = -100;
damage = 400;
}
// if we got obliterated by the nuke, don't gib
if ((self.health < -80) && (meansOfDeath == MOD_NUKE))
self.flags |= FL_NOGIB;
#endif
if (self.health < -40)
{
// gib
#ifdef GROUND_ZERO
if (!(self.flags & FL_NOGIB))
{
#endif
gi.sound(self, CHAN_BODY, gi.soundindex("misc/udeath.wav"), 1, ATTN_NORM, 0);
for (int n = 0; n < 4; n++)
ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
#ifdef GROUND_ZERO
}
self.flags &= ~FL_NOGIB;
#endif
ThrowClientHead(self, damage);
self.client.anim_priority = ANIM_DEATH;
self.client.anim_end = 0;
self.takedamage = false;
}
else if (!self.deadflag) // normal death
{
static int i;
i = (i + 1) % 3;
// start a death animation
self.client.anim_priority = ANIM_DEATH;
if (self.client.ps.pmove.pm_flags & PMF_DUCKED)
{
self.s.frame = FRAME_crdeath1 - 1;
self.client.anim_end = FRAME_crdeath5;
}
else switch (i)
{
case 0:
self.s.frame = FRAME_death101 - 1;
self.client.anim_end = FRAME_death106;
break;
case 1:
self.s.frame = FRAME_death201 - 1;
self.client.anim_end = FRAME_death206;
break;
case 2:
self.s.frame = FRAME_death301 - 1;
self.client.anim_end = FRAME_death308;
break;
}
gi.sound(self, CHAN_VOICE, gi.soundindex(va("*death%i.wav", (Q_rand() % 4) + 1)), 1, ATTN_NORM, 0);
}
self.deadflag = DEAD_DEAD;
gi.linkentity(self);
}
//=======================================================================
static inline void(entity other, ammo_t ammo_id, int new_max) SetAmmoMax =
{
other.client.pers.max_ammo[ammo_id] = new_max;
}
#ifdef CTF
void(entity) CTFAssignTeam;
#endif
/*
==============
InitClientPersistant
This is only called when the game first initializes in single player,
but is called after each death and level change in deathmatch
==============
*/
void(entity ent) InitClientPersistant =
{
memclear(&ent.client.pers, sizeof(ent.client.pers));
ent.client.pers.selected_item = ITEM_BLASTER;
ent.client.pers.inventory[ent.client.pers.selected_item] = 1;
ent.client.pers.weapon = ent.client.pers.lastweapon = GetItemByIndex(ent.client.pers.selected_item);
#ifdef GRAPPLE
ent.client.pers.inventory[ITEM_GRAPPLE] = 1;
#endif
ent.client.pers.health = 100;
ent.client.pers.max_health = 100;
SetAmmoMax(ent, AMMO_BULLETS, 200);
SetAmmoMax(ent, AMMO_SHELLS, 100);
SetAmmoMax(ent, AMMO_ROCKETS, 50);
SetAmmoMax(ent, AMMO_GRENADES, 50);
SetAmmoMax(ent, AMMO_CELLS, 200);
SetAmmoMax(ent, AMMO_SLUGS, 50);
#ifdef THE_RECKONING
SetAmmoMax(ent, AMMO_MAGSLUG, 50);
SetAmmoMax(ent, AMMO_TRAP, 5);
#endif
#ifdef GROUND_ZERO
SetAmmoMax(ent, AMMO_PROX, 50);
SetAmmoMax(ent, AMMO_TESLA, 50);
SetAmmoMax(ent, AMMO_FLECHETTES, 200);
SetAmmoMax(ent, AMMO_DISRUPTOR, 100);
#endif
ent.client.pers.connected = true;
}
static void(entity ent) InitClientResp =
{
#ifdef CTF
ctfteam_t ctf_team = ent.client.resp.ctf_team;
bool id_state = ent.client.resp.id_state;
#endif
memclear(&ent.client.resp, sizeof(client_respawn_t));
#ifdef CTF
ent.client.resp.ctf_team = ctf_team;
ent.client.resp.id_state = id_state;
#endif
ent.client.resp.enterframe = level.framenum;
#ifdef SINGLE_PLAYER
memcpy(&ent.client.resp.coop_respawn, &ent.client.pers, sizeof(client_persistant_t));
#endif
#ifdef CTF
if (ctf.intVal && ent.client.resp.ctf_team < CTF_TEAM1)
CTFAssignTeam(ent);
#endif
}
#ifdef SINGLE_PLAYER
/*
==================
SaveClientData
Some information that should be persistant, like health,
is still stored in the edict structure, so it needs to
be mirrored out to the client structure before all the
edicts are wiped.
==================
*/
void() SaveClientData =
{
for (int i = 0; i < game.maxclients; i++)
{
entity ent = itoe(1 + i);
if (!ent.inuse)
continue;
ent.client.pers.health = ent.health;
ent.client.pers.max_health = ent.max_health;
ent.client.pers.savedFlags = (ent.flags & (FL_GODMODE | FL_NOTARGET | FL_POWER_ARMOR));
if (coop.intVal)
ent.client.pers.score = ent.client.resp.score;
}
}
#endif
static void(entity ent) FetchClientEntData =
{
ent.health = ent.client.pers.health;
ent.max_health = ent.client.pers.max_health;
#ifdef SINGLE_PLAYER
ent.flags |= ent.client.pers.savedFlags;
if (coop.intVal)
ent.client.resp.score = ent.client.pers.score;
#endif
}
/*
=======================================================================
SelectSpawnPoint
=======================================================================
*/
/*
================
PlayersRangeFromSpot
Returns the distance to the nearest player from the given spot
================
*/
float(entity spot) PlayersRangeFromSpot =
{
float bestplayerdistance = 9999999f;
for (int n = 1; n <= game.maxclients; n++)
{
entity player = itoe(n);
if (!player.inuse)
continue;
if (player.health <= 0)
continue;
float playerdistance = VectorDistance(spot.s.origin, player.s.origin);
if (playerdistance < bestplayerdistance)
bestplayerdistance = playerdistance;
}
return bestplayerdistance;
}
/*
================
SelectRandomDeathmatchSpawnPoint
go to a random point, but NOT the two points closest
to other players
================
*/
entity() SelectRandomDeathmatchSpawnPoint =
{
int count = 0;
entity spot = world, spot1 = world, spot2 = world;
float range1 = FLT_MAX, range2 = FLT_MAX;
while ((spot = G_Find(spot, classname, "info_player_deathmatch")))
{
count++;
float range = PlayersRangeFromSpot(spot);
if (range < range1)
{
range1 = range;
spot1 = spot;
}
else if (range < range2)
{
range2 = range;
spot2 = spot;
}
}
if (!count)
return world;
if (count <= 2)
spot1 = spot2 = world;
else
count -= 2;
int selection = Q_rand_uniform(count);
spot = world;
do
{
spot = G_Find(spot, classname, "info_player_deathmatch");
if ((spot1 && spot == spot1) || (spot2 && spot == spot2))
selection++;
} while (selection--);
return spot;
}
/*
================
SelectFarthestDeathmatchSpawnPoint
================
*/
entity() SelectFarthestDeathmatchSpawnPoint =
{
entity spot = world;
entity bestspot = world;
float bestdistance = 0;
while ((spot = G_Find(spot, classname, "info_player_deathmatch")))
{
float bestplayerdistance = PlayersRangeFromSpot(spot);
if (bestplayerdistance > bestdistance)
{
bestspot = spot;
bestdistance = bestplayerdistance;
}
}
if (bestspot)
return bestspot;
// if there is a player just spawned on each and every start spot
// we have no choice to turn one into a telefrag meltdown
return G_Find(world, classname, "info_player_deathmatch");
}
static entity() SelectDeathmatchSpawnPoint =
{
if (dmflags.intVal & DF_SPAWN_FARTHEST)
return SelectFarthestDeathmatchSpawnPoint();
else
return SelectRandomDeathmatchSpawnPoint();
}
#ifdef SINGLE_PLAYER
#ifdef GROUND_ZERO
static entity(entity ent) SelectLavaCoopSpawnPoint =
{
float lavatop = -99999f;
entity highestlava = world;
// first, find the highest lava
// remember that some will stop moving when they've filled their
// areas...
entity lava = world;
while ((lava = G_Find (lava, classname, "func_door")))
{
vector center = (lava.absmax + lava.absmin) * 0.5f;
if (lava.spawnflags & 2 && (gi.pointcontents(center) & MASK_WATER))
{
if (lava.absmax[2] > lavatop)
{
lavatop = lava.absmax[2];
highestlava = lava;
}
}
}
// if we didn't find ANY lava, then return NULL
if !(highestlava)
return world;
// find the top of the lava and include a small margin of error (plus bbox size)
lavatop = highestlava.absmax[2] + 64;
// find all the lava spawn points and store them in spawnPoints[]
entity spot = world;
int numPoints = 0;
entity spawnPoints[64] = { 0 };
while ((spot = G_Find (spot, classname, "info_player_coop_lava")))
{
if (numPoints == 64)
break;
spawnPoints[numPoints++] = spot;
}
if (numPoints < 1)
return world;