forked from skullernet/openffa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp_client.c
1951 lines (1624 loc) · 52.3 KB
/
p_client.c
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) 1997-2001 Id Software, Inc.
This program 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.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "g_local.h"
#include "m_player.h"
void ClientUserinfoChanged(edict_t *ent, char *userinfo);
void SP_misc_teleporter_dest(edict_t *ent);
/*QUAKED info_player_start (1 0 0) (-16 -16 -24) (16 16 32)
The normal starting point for a level.
*/
void SP_info_player_start(edict_t *self)
{
}
/*QUAKED info_player_deathmatch (1 0 1) (-16 -16 -24) (16 16 32)
potential spawning position for deathmatch games
*/
void SP_info_player_deathmatch(edict_t *self)
{
SP_misc_teleporter_dest(self);
}
/*QUAKED info_player_coop (1 0 1) (-16 -16 -24) (16 16 32)
potential spawning position for coop games
*/
void SP_info_player_coop(edict_t *self)
{
G_FreeEdict(self);
}
/*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'
*/
void SP_info_player_intermission(void)
{
}
//=======================================================================
void player_pain(edict_t *self, edict_t *other, float kick, int damage)
{
// player pain is handled at the end of the frame in P_DamageFeedback
}
int G_UpdateRanks(void)
{
gclient_t *ranks[MAX_CLIENTS];
gclient_t *c;
char buffer[MAX_QPATH];
int i, j, total, topscore;
total = G_CalcRanks(ranks);
if (!total) {
return 0;
}
// top player
c = ranks[0];
topscore = c->resp.score;
j = total > 1 ? ranks[1]->resp.score : 0;
Q_snprintf(buffer, sizeof(buffer), " +%2d", topscore - j);
G_PrivateString(c->edict, PCS_DELTA, buffer);
Q_snprintf(buffer, sizeof(buffer), "1/%d", total);
G_PrivateString(c->edict, PCS_RANK, va("%5s", buffer));
UpdateChaseTargets(CHASE_LEADER, c->edict);
// other players
for (i = 1; i < total; i++) {
c = ranks[i];
Q_snprintf(buffer, sizeof(buffer), " -%2d",
topscore - c->resp.score);
for (j = 0; buffer[j]; j++) {
buffer[j] |= 128;
}
G_PrivateString(c->edict, PCS_DELTA, buffer);
Q_snprintf(buffer, sizeof(buffer), "%d/%d", i + 1, total);
G_PrivateString(c->edict, PCS_RANK, va("%5s", buffer));
}
return total;
}
void G_ScoreChanged(edict_t *ent)
{
char buffer[MAX_QPATH];
int total;
total = (int)fraglimit->value;
if (total > 0) {
Q_snprintf(buffer, sizeof(buffer), "%2d/%-2d",
ent->client->resp.score, total);
} else {
Q_snprintf(buffer, sizeof(buffer), "%5d",
ent->client->resp.score);
}
G_PrivateString(ent, PCS_FRAGS, buffer);
}
bool G_IsSameView(edict_t *ent, edict_t *other)
{
if (ent == other) {
return true;
}
if (ent->client->chase_target == other) {
return true;
}
return false;
}
static const byte mod_to_frag[MOD_TOTAL] = {
FRAG_UNKNOWN,
FRAG_BLASTER,
FRAG_SHOTGUN,
FRAG_SUPERSHOTGUN,
FRAG_MACHINEGUN,
FRAG_CHAINGUN,
FRAG_GRENADELAUNCHER,
FRAG_GRENADELAUNCHER,
FRAG_ROCKETLAUNCHER,
FRAG_ROCKETLAUNCHER,
FRAG_HYPERBLASTER,
FRAG_RAILGUN,
FRAG_BFG,
FRAG_BFG,
FRAG_BFG,
FRAG_GRENADES,
FRAG_GRENADES,
FRAG_WATER,
FRAG_SLIME,
FRAG_LAVA,
FRAG_CRUSH,
FRAG_TELEPORT,
FRAG_FALLING,
FRAG_SUICIDE,
FRAG_GRENADES
};
static void AccountItemKills(edict_t *ent)
{
int index;
if (ent->flags & FL_MEGAHEALTH) {
ent->client->resp.items[ITEM_HEALTH].kills++;
}
if (ent->client->quad_framenum > level.framenum) {
// FIXME: should account based on inflictor?
ent->client->resp.items[ITEM_QUAD].kills++;
}
if (ent->client->invincible_framenum > level.framenum) {
ent->client->resp.items[ITEM_INVULNERABILITY].kills++;
}
index = ArmorIndex(ent);
if (index) {
ent->client->resp.items[index].kills++;
}
index = PowerArmorIndex(ent);
if (index) {
ent->client->resp.items[index].kills++;
}
}
static void ClientObituary(edict_t *self, edict_t *inflictor, edict_t *attacker)
{
int mod;
frag_t frag;
char *message, *name;
char *message2, *name2;
bool ff;
edict_t *ent;
char buffer[MAX_NETNAME];
int i;
int level;
ff = meansOfDeath & MOD_FRIENDLY_FIRE;
mod = meansOfDeath & ~MOD_FRIENDLY_FIRE;
message = NULL;
message2 = "";
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;
}
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:
switch (self->client->pers.gender) {
case GENDER_FEMALE:
message = "tripped on her own grenade";
break;
case GENDER_MALE:
message = "tripped on his own grenade";
break;
default:
message = "tripped on its own grenade";
break;
}
break;
case MOD_R_SPLASH:
switch (self->client->pers.gender) {
case GENDER_FEMALE:
message = "blew herself up";
break;
case GENDER_MALE:
message = "blew himself up";
break;
default:
message = "blew itself up";
break;
}
break;
case MOD_BFG_BLAST:
message = "should have used a smaller gun";
break;
default:
switch (self->client->pers.gender) {
case GENDER_FEMALE:
message = "killed herself";
break;
case GENDER_MALE:
message = "killed himself";
break;
default:
message = "killed itself";
break;
}
break;
}
}
if (message) {
for (i = 0, ent = &g_edicts[1]; i < game.maxclients; i++, ent++) {
if (!ent->inuse) {
continue;
}
if (ent->client->pers.connected <= CONN_CONNECTED) {
continue;
}
name = self->client->pers.netname;
level = PRINT_MEDIUM;
if (G_IsSameView(ent, self)) {
G_HighlightStr(buffer, name, MAX_NETNAME);
name = buffer;
level = PRINT_HIGH;
}
gi.cprintf(ent, level, "%s %s.\n", name, message);
}
if ((int)dedicated->value) {
gi.dprintf("%s %s.\n", self->client->pers.netname, message);
}
frag = mod_to_frag[mod];
self->client->resp.score--;
self->client->resp.frags[frag].suicides++;
self->enemy = NULL;
G_ScoreChanged(self);
G_UpdateRanks();
return;
}
self->enemy = attacker;
if (attacker && attacker->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;
}
if (message) {
for (i = 0, ent = &g_edicts[1]; i < game.maxclients; i++, ent++) {
if (!ent->inuse) {
continue;
}
if (ent->client->pers.connected <= CONN_CONNECTED) {
continue;
}
name = self->client->pers.netname;
name2 = attacker->client->pers.netname;
level = PRINT_MEDIUM;
if (G_IsSameView(ent, attacker)) {
G_HighlightStr(buffer, name, MAX_NETNAME);
name = buffer;
level = PRINT_HIGH;
} else if (G_IsSameView(ent, self)) {
G_HighlightStr(buffer, name2, MAX_NETNAME);
name2 = buffer;
level = PRINT_HIGH;
}
gi.cprintf(ent, level, "%s %s %s%s\n",
name, message, name2, message2);
}
if ((int)dedicated->value) {
gi.dprintf("%s %s %s%s\n", self->client->pers.netname,
message, attacker->client->pers.netname, message2);
}
if (ff) {
attacker->client->resp.score--;
} else {
frag = mod_to_frag[mod];
attacker->client->resp.score++;
attacker->client->resp.frags[frag].kills++;
self->client->resp.deaths++;
self->client->resp.frags[frag].deaths++;
AccountItemKills(attacker);
}
G_ScoreChanged(attacker);
G_UpdateRanks();
return;
}
}
gi.bprintf(PRINT_MEDIUM, "%s died.\n", self->client->pers.netname);
frag = mod_to_frag[mod];
self->client->resp.score--;
self->client->resp.frags[frag].suicides++;
G_ScoreChanged(self);
G_UpdateRanks();
}
static int damaging;
void G_BeginDamage(void)
{
damaging = 1;
}
// called from T_Damage only when target is a living player
// and inflictor is a real entity (not world)
void G_AccountDamage(edict_t *targ, edict_t *inflictor, edict_t *attacker, int points)
{
frag_t frag;
if (!damaging) {
return;
}
frag = mod_to_frag[meansOfDeath & ~MOD_FRIENDLY_FIRE];
if (frag < FRAG_BLASTER || frag > FRAG_BFG) {
return; // only care about weapons
}
targ->client->resp.damage_recvd += points;
if (targ == attacker) {
return; // no credit for shooting yourself
}
attacker->client->resp.damage_given += points;
// don't count multiple damage as multiple hits (but railgun still counts)
if (damaging == 1 || frag == FRAG_RAILGUN) {
attacker->client->resp.frags[frag].hits++;
}
damaging++;
}
void G_EndDamage(void)
{
damaging = 0;
}
void Touch_Item(edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf);
static void TossClientWeapon(edict_t *self)
{
gitem_t *item;
edict_t *drop;
bool quad;
float spread;
item = self->client->weapon;
if (!self->client->inventory[self->client->ammo_index])
item = NULL;
if (item == INDEX_ITEM(ITEM_BLASTER))
item = NULL;
if (!DF(QUAD_DROP))
quad = false;
else
quad = (self->client->quad_framenum > (level.framenum + 1 * HZ));
if (item && quad)
spread = 22.5f;
else
spread = 0.0f;
if (item) {
self->client->v_angle[YAW] -= spread;
drop = Drop_Item(self, item);
self->client->v_angle[YAW] += spread;
drop->spawnflags = DROPPED_PLAYER_ITEM;
}
if (quad) {
self->client->v_angle[YAW] += spread;
drop = Drop_Item(self, INDEX_ITEM(ITEM_QUAD));
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;
}
}
/*
==================
LookAtKiller
==================
*/
static void LookAtKiller(edict_t *self, edict_t *inflictor, edict_t *attacker)
{
vec3_t dir;
if (attacker && attacker != world && attacker != self) {
VectorSubtract(attacker->s.origin, self->s.origin, dir);
} else if (inflictor && inflictor != world && inflictor != self) {
VectorSubtract(inflictor->s.origin, self->s.origin, dir);
} else {
self->client->killer_yaw = self->s.angles[YAW];
return;
}
if (dir[0])
self->client->killer_yaw = RAD2DEG(atan2(dir[1], dir[0]));
else {
self->client->killer_yaw = 0;
if (dir[1] > 0)
self->client->killer_yaw = 90;
else if (dir[1] < 0)
self->client->killer_yaw = -90;
}
if (self->client->killer_yaw < 0)
self->client->killer_yaw += 360;
}
/*
==================
player_die
==================
*/
void player_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
VectorClear(self->avelocity);
self->takedamage = DAMAGE_YES;
self->movetype = MOVETYPE_TOSS;
self->s.modelindex2 = 0; // remove linked weapon model
self->s.angles[0] = 0;
self->s.angles[2] = 0;
self->s.sound = 0;
self->client->weapon_sound = 0;
self->maxs[2] = -8;
// self->solid = SOLID_NOT;
self->svflags |= SVF_DEADMONSTER;
if (!self->deadflag) {
self->client->respawn_framenum = level.framenum + 1 * HZ;
LookAtKiller(self, inflictor, attacker);
self->client->ps.pmove.pm_type = PM_DEAD;
ClientObituary(self, inflictor, attacker);
TossClientWeapon(self);
// show scores
if (!self->client->layout) {
self->client->layout = LAYOUT_SCORES;
DeathmatchScoreboardMessage(self, false);
}
// clear inventory
// this is kind of ugly, but it's how we want to handle keys in coop
for (n = 0; n < MAX_ITEMS; n++) {
self->client->inventory[n] = 0;
}
}
// remove powerups
self->client->quad_framenum = 0;
self->client->invincible_framenum = 0;
self->client->breather_framenum = 0;
self->client->enviro_framenum = 0;
self->flags &= ~FL_POWER_ARMOR;
if (self->health < -40) {
// gib
gi.sound(self, CHAN_BODY, level.sounds.udeath, 1, ATTN_NORM, 0);
for (n = 0; n < 4; n++)
ThrowGib(self, level.models.meat, damage, GIB_ORGANIC);
ThrowClientHead(self, damage);
self->takedamage = DAMAGE_NO;
} else {
// normal death
if (!self->deadflag) {
static int i;
int r;
i = (i + 1) % 3;
// start a death animation
self->client->anim_priority = ANIM_DEATH;
if (self->client->ps.pmove.pm_flags & PMF_DUCKED) {
self->client->anim_start = FRAME_crdeath1;
self->client->anim_end = FRAME_crdeath5;
} else {
switch (i) {
case 0:
self->client->anim_start = FRAME_death101;
self->client->anim_end = FRAME_death106;
break;
case 1:
self->client->anim_start = FRAME_death201;
self->client->anim_end = FRAME_death206;
break;
case 2:
self->client->anim_start = FRAME_death301;
self->client->anim_end = FRAME_death308;
break;
}
}
r = Q_rand() & 3;
gi.sound(self, CHAN_VOICE, level.sounds.death[r], 1, ATTN_NORM, 0);
}
}
// no normal pain sound
self->pain_debounce_framenum = KEYFRAME(FRAMEDIV);
self->deadflag = DEAD_DEAD;
gi.linkentity(self);
}
/*
=======================================================================
SelectSpawnPoint
=======================================================================
*/
static edict_t *SelectRandomDeathmatchSpawnPoint(void)
{
return level.spawns[Q_rand_uniform(level.numspawns)];
}
/*
================
PlayersRangeFromSpot
Returns the distance to the nearest player from the given spot
================
*/
static float PlayersRangeFromSpot(edict_t *spot)
{
edict_t *player;
float bestplayerdistance;
vec3_t v;
int n;
float playerdistance;
bestplayerdistance = 9999999;
for (n = 1; n <= game.maxclients; n++) {
player = &g_edicts[n];
if (!player->inuse)
continue;
if (!PlayerSpawned(player))
continue;
if (player->health <= 0)
continue;
VectorSubtract(spot->s.origin, player->s.origin, v);
playerdistance = VectorLength(v);
if (playerdistance < bestplayerdistance)
bestplayerdistance = playerdistance;
}
return bestplayerdistance;
}
static edict_t *SelectRandomDeathmatchSpawnPointAvoidingTelefrag(void)
{
edict_t *spawns[MAX_SPAWNS];
edict_t *spot;
float range;
int i;
for (i = 0; i < level.numspawns; i++) {
spawns[i] = level.spawns[i];
}
G_ShuffleArray(spawns, level.numspawns);
for (i = 0; i < level.numspawns; i++) {
spot = spawns[i];
range = PlayersRangeFromSpot(spot);
if (range > 64) {
return spot;
}
}
// all spots were taken
return SelectRandomDeathmatchSpawnPoint();
}
static edict_t *SelectRandomDeathmatchSpawnPointAvoidingTwoClosest(void)
{
edict_t *spot, *spot1, *spot2;
float range, range1, range2;
int i;
range1 = range2 = 99999;
spot1 = spot2 = NULL;
for (i = 0; i < level.numspawns; i++) {
spot = level.spawns[i];
range = PlayersRangeFromSpot(spot);
if (range < range1) {
range1 = range;
spot1 = spot;
}
}
for (i = 0; i < level.numspawns; i++) {
spot = level.spawns[i];
if (spot == spot1) {
continue; // already recorded this one
}
range = PlayersRangeFromSpot(spot);
if (range < range2) {
range2 = range;
spot2 = spot;
}
}
do {
spot = SelectRandomDeathmatchSpawnPoint();
} while (spot == spot1 || spot == spot2);
return spot;
}
/*
================
SelectRandomDeathmatchSpawnPointAvoidingTwoClosestBugged
go to a random point, but NOT the two points closest
to other players
original bugged version: if points are in decreasing
range order, spot2 will never be set
================
*/
static edict_t *SelectRandomDeathmatchSpawnPointAvoidingTwoClosestBugged(void)
{
edict_t *spot, *spot1, *spot2;
float range, range1, range2;
int i;
range1 = range2 = 99999;
spot1 = spot2 = NULL;
for (i = 0; i < level.numspawns; i++) {
spot = level.spawns[i];
range = PlayersRangeFromSpot(spot);
if (range < range1) {
range1 = range;
spot1 = spot;
} else if (range < range2) {
range2 = range;
spot2 = spot;
}
}
do {
spot = SelectRandomDeathmatchSpawnPoint();
} while (spot == spot1 || spot == spot2);
return spot;
}
/*
================
SelectFarthestDeathmatchSpawnPoint
================
*/
static edict_t *SelectFarthestDeathmatchSpawnPoint(void)
{
edict_t *bestspot;
float bestdistance, bestplayerdistance;
edict_t *spot;
int i;
bestspot = NULL;
bestdistance = 0;
for (i = 0; i < level.numspawns; i++) {
spot = level.spawns[i];
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 level.spawns[0];
}
static edict_t *SelectDeathmatchSpawnPoint(void)
{
// in the first 5 seconds of a level start,
// avoid telefrags above all other conditions
if (level.framenum < 5 * HZ) {
return SelectRandomDeathmatchSpawnPointAvoidingTelefrag();
}
// spawn farthest overrides g_spawn_mode
if (DF(SPAWN_FARTHEST)) {
return SelectFarthestDeathmatchSpawnPoint();
}
if (level.numspawns > 2) {
if ((int)g_spawn_mode->value == 0) {
return SelectRandomDeathmatchSpawnPointAvoidingTwoClosestBugged();
}
if ((int)g_spawn_mode->value == 1) {
return SelectRandomDeathmatchSpawnPointAvoidingTwoClosest();
}
}
return SelectRandomDeathmatchSpawnPoint();
}
/*
===========
SelectSpawnPoint
Chooses a player start, deathmatch start, coop start, etc
============
*/
static void SelectSpawnPoint(edict_t *ent, vec3_t origin, vec3_t angles)
{
edict_t *spot = NULL;
if (level.numspawns && PlayerSpawned(ent)) {
spot = SelectDeathmatchSpawnPoint();
}
// find a single player start spot
if (!spot) {
while ((spot = G_Find(spot, FOFS(classname), "info_player_start")) != NULL) {
if (!spot->targetname)
break;
}
if (!spot) {
// there wasn't a spawnpoint without a target, so use any
spot = G_Find(spot, FOFS(classname), "info_player_start");
if (!spot) {
gi.dprintf("Couldn't find spawn point!\n");
spot = world;
}
}
}
VectorCopy(spot->s.origin, origin);
VectorCopy(spot->s.angles, angles);
}
//======================================================================
void InitBodyQue(void)
{
int i;
edict_t *ent;
level.body_que = 0;
for (i = 0; i < BODY_QUEUE_SIZE; i++) {
ent = G_Spawn();
ent->classname = "bodyque";
}
}
static void body_die(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
int n;
if (self->health < -40) {
gi.sound(self, CHAN_BODY, level.sounds.udeath, 1, ATTN_NORM, 0);
for (n = 0; n < 4; n++)
ThrowGib(self, level.models.meat, damage, GIB_ORGANIC);
#if 0
ThrowGib(self, level.models.arm, damage, GIB_ORGANIC);
ThrowGib(self, level.models.leg, damage, GIB_ORGANIC);
ThrowGib(self, level.models.chest, damage, GIB_ORGANIC);
ThrowGib(self, level.models.bones[0], damage, GIB_ORGANIC);
ThrowGib(self, level.models.bones[1], damage, GIB_ORGANIC);
#endif
self->s.origin[2] -= 48;
ThrowClientHead(self, damage);
self->takedamage = DAMAGE_NO;
}
}
static void CopyToBodyQue(edict_t *ent)
{
edict_t *body;
gi.unlinkentity(ent);
// grab a body que and cycle to the next one
body = &g_edicts[game.maxclients + level.body_que + 1];
level.body_que = (level.body_que + 1) % BODY_QUEUE_SIZE;
// send an effect on the removed body
if (body->s.modelindex) {
gi.WriteByte(svc_temp_entity);
gi.WriteByte(TE_BLOOD);
gi.WritePosition(body->s.origin);
gi.WriteDir(vec3_origin);
gi.multicast(body->s.origin, MULTICAST_PVS);
}
gi.unlinkentity(body);
body->s.number = body - g_edicts;
VectorCopy(ent->s.origin, body->s.origin);
VectorCopy(ent->s.origin, body->s.old_origin);
VectorCopy(ent->s.origin, body->old_origin);
VectorCopy(ent->s.angles, body->s.angles);
body->s.modelindex = ent->s.modelindex;
body->s.frame = ent->s.frame;
body->s.skinnum = ent->s.skinnum;
body->s.event = EV_OTHER_TELEPORT;
// start with dead player frame
if (ent->s.modelindex == 255 && ent->client && ent->client->anim_priority == ANIM_DEATH)
body->s.frame = ent->client->anim_end;
body->svflags = ent->svflags;
VectorCopy(ent->mins, body->mins);
VectorCopy(ent->maxs, body->maxs);
VectorCopy(ent->absmin, body->absmin);
VectorCopy(ent->absmax, body->absmax);
VectorCopy(ent->size, body->size);