-
Notifications
You must be signed in to change notification settings - Fork 92
/
g_active.c
2413 lines (2098 loc) · 65.1 KB
/
g_active.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
/*
* Wolfenstein: Enemy Territory GPL Source Code
* Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
*
* ET: Legacy
* Copyright (C) 2012-2023 ET:Legacy team <mail@etlegacy.com>
*
* This file is part of ET: Legacy - http://www.etlegacy.com
*
* ET: Legacy 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 3 of the License, or
* (at your option) any later version.
*
* ET: Legacy 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 ET: Legacy. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, Wolfenstein: Enemy Territory GPL Source Code is also
* subject to certain additional terms. You should have received a copy
* of these additional terms immediately following the terms and conditions
* of the GNU General Public License which accompanied the source code.
* If not, please request a copy in writing from id Software at the address below.
*
* id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
*/
/**
* @file g_active.c
*/
#include "g_local.h"
#ifdef FEATURE_OMNIBOT
#include "g_etbot_interface.h"
#endif
#ifdef FEATURE_SERVERMDX
#include "g_mdx.h"
#endif
/**
* @brief Called just before a snapshot is sent to the given player.
*
* @details Totals up all damage and generates both the player_state_t
* damage values to that client for pain blends and kicks, and
* global pain sound events for all clients.
*
* @param[in,out] player Player Entity
*/
void P_DamageFeedback(gentity_t *player)
{
gclient_t *client = player->client;
int count;
if (client->ps.pm_type == PM_DEAD)
{
return;
}
// total points of damage shot at the player this frame
count = client->damage_blood;
if (count == 0)
{
return; // didn't take any damage
}
if (count > 127)
{
count = 127;
}
// send the information to the client
// world damage (falling, slime, etc) uses a special code
// to make the blend blob centered instead of positional
if (client->damage_fromWorld)
{
client->ps.damagePitch = 255;
client->ps.damageYaw = 255;
client->damage_fromWorld = qfalse;
}
else
{
vec3_t angles;
vectoangles(client->damage_from, angles);
client->ps.damagePitch = angles[PITCH] / 360.0f * 256;
client->ps.damageYaw = angles[YAW] / 360.0f * 256;
}
// play an apropriate pain sound
if ((level.time > player->pain_debounce_time) && !(player->flags & FL_GODMODE) && !(player->s.powerups & PW_INVULNERABLE))
{
player->pain_debounce_time = level.time + 700;
G_AddEvent(player, EV_PAIN, player->health);
//BG_AnimScriptEvent(&client->ps, client->pers.character->animModelInfo, ANIM_ET_PAIN, qfalse, qtrue);
}
client->ps.damageEvent++; // always increment this since we do multiple view damage anims
client->ps.damageCount = count;
// clear totals
client->damage_blood = 0;
client->damage_knockback = 0;
}
#define MIN_BURN_INTERVAL 399 // set burn timeinterval so we can do more precise damage (was 199 old model)
#define UNDERWATER_DAMAGE 2
/**
* @brief Check for lava/slime contents and drowning
* @param[in,out] ent Entity
*/
void P_WorldEffects(gentity_t *ent)
{
if (ent->client->noclip)
{
// air left while underwater
ent->client->ps.stats[STAT_AIRLEFT] = HOLDBREATHTIME;
ent->client->airOutTime = level.time + HOLDBREATHTIME;
return;
}
// check for drowning
if (ent->waterlevel == 3)
{
// if out of air, start drowning
if (ent->client->airOutTime < level.time)
{
// drown!
ent->client->airOutTime += 1000;
if (ent->health >= FORCE_LIMBO_HEALTH)
{
// take more damage the longer underwater
ent->damage += 2;
if (ent->damage > 15)
{
ent->damage = 15;
}
if (ent->health > 0)
{
// play a gurp sound instead of a normal pain sound
if (ent->health <= ent->damage)
{
G_Sound(ent, GAMESOUND_PLAYER_BUBBLE);
}
else if (rand() & 1)
{
G_Sound(ent, GAMESOUND_PLAYER_GURP1);
}
else
{
G_Sound(ent, GAMESOUND_PLAYER_GURP2);
}
// don't play a normal pain sound
ent->pain_debounce_time = level.time + 200;
}
if (ent->watertype & CONTENTS_SLIME) // slag
{
G_Damage(ent, NULL, NULL, NULL, NULL, ent->damage, 0, MOD_SLIME);
}
else
{
G_Damage(ent, NULL, NULL, NULL, NULL, ent->damage, 0, MOD_WATER);
}
}
}
}
else
{
// air left while underwater
ent->client->airOutTime = level.time + ent->client->ps.stats[STAT_AIRLEFT];
ent->damage = UNDERWATER_DAMAGE;
}
// check for sizzle damage (move to pmove?)
if (ent->waterlevel && (ent->watertype & CONTENTS_LAVA))
{
if (ent->health > 0 && ent->pain_debounce_time <= level.time)
{
G_Damage(ent, NULL, NULL, NULL, NULL, 30 * ent->waterlevel, 0, MOD_LAVA);
}
}
// check for burning from flamethrower - MP way
if (ent->s.onFireEnd && ent->client)
{
if (level.time - ent->client->lastBurnTime >= MIN_BURN_INTERVAL)
{
// server-side incremental damage routine / player damage/health is int (not float)
// so I can't allocate 1.5 points per server tick, and 1 is too weak and 2 is too strong.
// solution: allocate damage far less often (MIN_BURN_INTERVAL often) and do more damage.
// That way minimum resolution (1 point) damage changes become less critical.
ent->client->lastBurnTime = level.time;
if (ent->s.onFireEnd > level.time && ent->health > 0)
{
gentity_t *attacker = g_entities + ent->flameBurnEnt;
G_Damage(ent, attacker, attacker, NULL, NULL, GetWeaponTableData(WP_FLAMETHROWER)->damage, DAMAGE_NO_KNOCKBACK, MOD_FLAMETHROWER);
}
}
}
}
/**
* @brief Disables sound looping in entity
* @param[in,out] ent Entity
*/
void G_SetClientSound(gentity_t *ent)
{
ent->s.loopSound = 0;
}
#ifdef FEATURE_OMNIBOT
/**
* @brief PushBot
* @param[in] ent
* @param[in] other
*/
void PushBot(gentity_t *ent, gentity_t *other)
{
vec3_t dir, ang, f, r;
float oldspeed;
float s;
if (!other->client)
{
return;
}
// dont push when mounted in certain stationary weapons or scripted not to be pushed
if (Bot_Util_AllowPush(other->client->ps.weapon) == qfalse || !other->client->sess.botPush)
{
return;
}
oldspeed = VectorLength(other->client->ps.velocity);
if (oldspeed < 200)
{
oldspeed = 200;
}
VectorSubtract(other->r.currentOrigin, ent->r.currentOrigin, dir);
VectorNormalize(dir);
vectoangles(dir, ang);
AngleVectors(ang, f, r, NULL);
f[2] = 0;
r[2] = 0;
VectorMA(other->client->ps.velocity, 200, f, other->client->ps.velocity);
s = 100 * ((level.time + (ent->s.number * 1000)) % 4000 < 2000 ? 1.0f : -1.0f);
VectorMA(other->client->ps.velocity, s, r, other->client->ps.velocity);
if (VectorLengthSquared(other->client->ps.velocity) > Square(oldspeed))
{
VectorNormalize(other->client->ps.velocity);
VectorScale(other->client->ps.velocity, oldspeed, other->client->ps.velocity);
}
}
#endif
/**
* @brief Does ent have enough "energy" to call artillery?
* @param[in] ent Entity
*/
qboolean ReadyToCallArtillery(gentity_t *ent)
{
if (BG_IsSkillAvailable(ent->client->sess.skill, SK_BATTLE_SENSE, SK_BATTLE_SENSE_STAMINA_RECHARGE))
{
if (level.time - ent->client->ps.classWeaponTime <= (level.fieldopsChargeTime[ent->client->sess.sessionTeam - 1] * 0.66f))
{
return qfalse;
}
}
else if (level.time - ent->client->ps.classWeaponTime <= level.fieldopsChargeTime[ent->client->sess.sessionTeam - 1])
{
return qfalse;
}
return qtrue;
}
/**
* @brief Are we ready to construct?
* @param[in,out] ent Entity
* @param[in] constructible Constructible Entity
* @param[in] updateState Do we want to update Entity weapon time?
*
* Optionally, will also update the time while we are constructing
*/
qboolean ReadyToConstruct(gentity_t *ent, gentity_t *constructible, qboolean updateState)
{
int weaponTime = ent->client->ps.classWeaponTime;
// "Ammo" for this weapon is time based
if (weaponTime + level.engineerChargeTime[ent->client->sess.sessionTeam - 1] < level.time)
{
weaponTime = level.time - level.engineerChargeTime[ent->client->sess.sessionTeam - 1];
}
if (g_debugConstruct.integer)
{
weaponTime += 0.5f * ((float)level.engineerChargeTime[ent->client->sess.sessionTeam - 1] / (constructible->constructibleStats.duration / (float)FRAMETIME));
}
else
{
if (BG_IsSkillAvailable(ent->client->sess.skill, SK_EXPLOSIVES_AND_CONSTRUCTION, SK_ENGINEER_STAMINA))
{
weaponTime += 0.66f * constructible->constructibleStats.chargebarreq * ((float)level.engineerChargeTime[ent->client->sess.sessionTeam - 1] / (constructible->constructibleStats.duration / (float)FRAMETIME));
}
//weaponTime += 0.66f*((float)level.engineerChargeTime[ent->client->sess.sessionTeam-1]/(constructible->wait/(float)FRAMETIME));
//weaponTime += 0.66f * 2.f * ((float)level.engineerChargeTime[ent->client->sess.sessionTeam-1]/(constructible->wait/(float)FRAMETIME));
else
{
weaponTime += constructible->constructibleStats.chargebarreq * ((float)level.engineerChargeTime[ent->client->sess.sessionTeam - 1] / (constructible->constructibleStats.duration / (float)FRAMETIME));
}
//weaponTime += 2.f * ((float)level.engineerChargeTime[ent->client->sess.sessionTeam-1]/(constructible->wait/(float)FRAMETIME));
}
// if the time is in the future, we have NO energy left
if (weaponTime > level.time)
{
// if we're supposed to update the state, reset the time to now
//if (updateState)
//{
// ent->client->ps.classWeaponTime = level.time;
//}
return qfalse;
}
// only set the actual weapon time for this entity if they want us to
if (updateState)
{
ent->client->ps.classWeaponTime = weaponTime;
}
return qtrue;
}
//==============================================================
/**
* @brief ClientImpacts
*
* @param[in] ent Entity
* @param[in] pm Player Move
*/
void ClientImpacts(gentity_t *ent, pmove_t *pm)
{
int i, j;
gentity_t *other;
trace_t trace;
Com_Memset(&trace, 0, sizeof(trace));
for (i = 0 ; i < pm->numtouch ; i++)
{
for (j = 0 ; j < i ; j++)
{
if (pm->touchents[j] == pm->touchents[i])
{
break;
}
}
if (j != i)
{
continue; // duplicated
}
other = &g_entities[pm->touchents[i]];
#ifdef FEATURE_OMNIBOT
if ((ent->client) /*&& !(ent->r.svFlags & SVF_BOT)*/ && (other->r.svFlags & SVF_BOT) &&
!other->client->ps.powerups[PW_INVULNERABLE])
{
PushBot(ent, other);
}
// if we are standing on their head, then we should be pushed also
if ((ent->r.svFlags & SVF_BOT) && (ent->s.groundEntityNum == other->s.number && other->client) &&
!other->client->ps.powerups[PW_INVULNERABLE])
{
PushBot(other, ent);
}
#endif
if (!other->touch)
{
continue;
}
other->touch(other, ent, &trace);
}
}
/**
* @brief Find all trigger entities that ent's current position touches.
* @param[in,out] ent Entity
*
* Spectators will only interact with teleporters.
*/
void G_TouchTriggers(gentity_t *ent)
{
int i, num;
int touch[MAX_GENTITIES];
gentity_t *hit;
trace_t trace;
vec3_t mins, maxs;
static vec3_t range = { 40, 40, 52 };
if (!ent->client)
{
return;
}
// reset the pointer that keeps track of trigger_objective_info tracking
ent->client->touchingTOI = NULL;
// dead clients don't activate triggers!
if (ent->client->ps.stats[STAT_HEALTH] <= 0)
{
return;
}
VectorSubtract(ent->client->ps.origin, range, mins);
VectorAdd(ent->client->ps.origin, range, maxs);
num = trap_EntitiesInBox(mins, maxs, touch, MAX_GENTITIES);
// can't use ent->absmin, because that has a one unit pad
VectorAdd(ent->client->ps.origin, ent->r.mins, mins);
VectorAdd(ent->client->ps.origin, ent->r.maxs, maxs);
for (i = 0 ; i < num ; i++)
{
hit = &g_entities[touch[i]];
if (!hit->touch && !ent->touch)
{
continue;
}
if (!(hit->r.contents & CONTENTS_TRIGGER))
{
continue;
}
// invisible entities can't be touched
if (hit->entstate == STATE_INVISIBLE ||
hit->entstate == STATE_UNDERCONSTRUCTION)
{
continue;
}
// ignore most entities if a spectator
if (ent->client->sess.sessionTeam == TEAM_SPECTATOR)
{
if (hit->s.eType != ET_TELEPORT_TRIGGER)
{
continue;
}
}
// use seperate code for determining if an item is picked up
// so you don't have to actually contact its bounding box
if (hit->s.eType == ET_ITEM)
{
if (!BG_PlayerTouchesItem(&ent->client->ps, &hit->s, level.time))
{
continue;
}
}
else
{
// always use capsule for player
if (!trap_EntityContactCapsule(mins, maxs, hit))
{
//if ( !trap_EntityContact( mins, maxs, hit ) ) {
continue;
}
}
Com_Memset(&trace, 0, sizeof(trace));
if (hit->touch)
{
hit->touch(hit, ent, &trace);
}
}
}
/**
* @brief G_SpectatorAttackFollow
* @param ent
* @return true if a player was found to follow, otherwise false
*/
qboolean G_SpectatorAttackFollow(gentity_t *ent)
{
trace_t tr;
vec3_t forward, right, up;
vec3_t start, end;
vec3_t mins, maxs;
static vec3_t enlargeMins = { -64.0f, -64.0f, -48.0f };
static vec3_t enlargeMaxs = { 64.0f, 64.0f, 0.0f };
if (!ent->client)
{
return qfalse;
}
AngleVectors(ent->client->ps.viewangles, forward, right, up);
VectorCopy(ent->client->ps.origin, start);
VectorMA(start, MAX_TRACE, forward, end);
// enlarge the hitboxes, so spectators can easily click on them..
VectorCopy(ent->r.mins, mins);
VectorCopy(ent->r.maxs, maxs);
VectorAdd(mins, enlargeMins, mins);
VectorAdd(maxs, enlargeMaxs, maxs);
// also put the start-point a bit forward, so we don't start the trace in solid..
VectorMA(start, 75.0f, forward, start);
// trap_Trace(&tr, start, mins, maxs, end, ent->client->ps.clientNum, CONTENTS_BODY | CONTENTS_CORPSE);
G_HistoricalTrace(ent, &tr, start, mins, maxs, end, ent->s.number, CONTENTS_BODY | CONTENTS_CORPSE);
if ((&g_entities[tr.entityNum])->client)
{
ent->client->sess.spectatorState = SPECTATOR_FOLLOW;
ent->client->sess.spectatorClient = tr.entityNum;
return qtrue;
}
return qfalse;
}
/**
* @brief SpectatorThink
* @param[in,out] ent
* @param[in] ucmd
*/
void SpectatorThink(gentity_t *ent, usercmd_t *ucmd)
{
gclient_t *client = ent->client;
gentity_t *crosshairEnt = &g_entities[ent->client->ps.identifyClient];
// sanity check - check .active in case the client sends us something completely bogus
if (crosshairEnt->inuse && crosshairEnt->client &&
(ent->client->sess.sessionTeam == crosshairEnt->client->sess.sessionTeam ||
crosshairEnt->client->ps.powerups[PW_OPS_DISGUISED]))
{
// identifyClientHealth sent as unsigned char, so we
// can't transmit negative numbers
if (crosshairEnt->health >= 0)
{
ent->client->ps.identifyClientHealth = crosshairEnt->health;
}
else
{
ent->client->ps.identifyClientHealth = 0;
}
}
if (client->sess.spectatorState != SPECTATOR_FOLLOW)
{
pmove_t pm;
client->ps.pm_type = PM_SPECTATOR;
client->ps.speed = 800; // was: 400 // faster than normal
if (client->ps.sprintExertTime)
{
client->ps.speed *= 3; // allow sprint in free-cam mode
}
// dead players are frozen too, in a timeout
if ((client->ps.pm_flags & PMF_LIMBO) && level.match_pause != PAUSE_NONE)
{
client->ps.pm_type = PM_FREEZE;
}
else if (client->noclip)
{
client->ps.pm_type = PM_NOCLIP;
}
// set up for pmove
Com_Memset(&pm, 0, sizeof(pm));
pm.ps = &client->ps;
pm.pmext = &client->pmext;
pm.character = client->pers.character;
pm.cmd = *ucmd;
pm.skill = client->sess.skill;
pm.tracemask = MASK_PLAYERSOLID & ~CONTENTS_BODY; // spectators can fly through bodies
pm.trace = trap_TraceCapsuleNoEnts;
pm.pointcontents = trap_PointContents;
pm.activateLean = client->pers.activateLean;
Pmove(&pm);
// Activate - made it a latched event (occurs on keydown only)
if (client->latched_buttons & BUTTON_ACTIVATE)
{
Cmd_Activate_f(ent);
}
// save results of pmove
VectorCopy(client->ps.origin, ent->s.origin);
G_TouchTriggers(ent);
trap_UnlinkEntity(ent);
}
if (ent->flags & FL_NOFATIGUE)
{
ent->client->ps.stats[STAT_SPRINTTIME] = SPRINTTIME;
}
if (ent->flags & FL_NOSTAMINA)
{
ent->client->ps.classWeaponTime = 0;
}
client->oldbuttons = client->buttons;
client->buttons = ucmd->buttons;
client->oldwbuttons = client->wbuttons;
client->wbuttons = ucmd->wbuttons;
#ifdef FEATURE_MULTIVIEW
// MV clients use these buttons locally for other things
if (client->pers.mvCount < 1)
{
#endif
// attack button + "firing" a players = spectate that "victim"
if ((client->buttons & BUTTON_ATTACK) && !(client->oldbuttons & BUTTON_ATTACK) &&
client->sess.spectatorState != SPECTATOR_FOLLOW &&
client->sess.sessionTeam == TEAM_SPECTATOR) // don't do it if on a team
{
if (G_SpectatorAttackFollow(ent))
{
return;
}
else
{
// not clicked on a player?.. then follow next,
// to prevent constant traces done by server.
if (client->buttons & BUTTON_SPRINT)
{
Cmd_FollowCycle_f(ent, 1, qtrue);
}
// no humans playing?.. then follow a bot
if (client->sess.spectatorState != SPECTATOR_FOLLOW)
{
Cmd_FollowCycle_f(ent, 1, qfalse);
}
}
// attack + sprint button cycles through non-bot/human players
// attack button cycles through all players
}
else if ((client->buttons & BUTTON_ATTACK) && !(client->oldbuttons & BUTTON_ATTACK) &&
!(client->buttons & BUTTON_ACTIVATE))
{
Cmd_FollowCycle_f(ent, 1, (client->buttons & BUTTON_SPRINT));
}
// FIXME: WBUTTON_ATTACK2
else if ((client->wbuttons & WBUTTON_ATTACK2) && !(client->oldwbuttons & WBUTTON_ATTACK2) &&
!(client->buttons & BUTTON_ACTIVATE))
{
Cmd_FollowCycle_f(ent, -1, (client->buttons & BUTTON_SPRINT));
}
#ifdef ETLEGACY_DEBUG
#ifdef FEATURE_OMNIBOT
// activate button swaps places with bot
else if (client->sess.sessionTeam != TEAM_SPECTATOR && g_allowBotSwap.integer &&
((client->buttons & BUTTON_ACTIVATE) && !(client->oldbuttons & BUTTON_ACTIVATE)) &&
(g_entities[ent->client->sess.spectatorClient].client) &&
(g_entities[ent->client->sess.spectatorClient].r.svFlags & SVF_BOT))
{
Cmd_SwapPlacesWithBot_f(ent, ent->client->sess.spectatorClient);
}
#endif
#endif
else if (client->sess.sessionTeam == TEAM_SPECTATOR && client->sess.spectatorState == SPECTATOR_FOLLOW &&
(((client->buttons & BUTTON_ACTIVATE) && !(client->oldbuttons & BUTTON_ACTIVATE)) || ucmd->upmove > 0) &&
G_allowFollow(ent, TEAM_AXIS) && G_allowFollow(ent, TEAM_ALLIES))
{
StopFollowing(ent);
}
#ifdef FEATURE_MULTIVIEW
}
#endif
}
/**
* @brief
* g_inactivity and g_spectatorinactivity :
* Values have to be higher then 10 seconds, that is the time after the warn message is sent.
* (if it's lower than that value, it will not work at all)
*
* @param[in,out] client Client
*
* @return Returns qfalse if the client is dropped
*/
qboolean ClientInactivityTimer(gclient_t *client)
{
int inactivity = G_InactivityValue;
int inactivityspec = G_SpectatorInactivityValue;
qboolean inTeam = (client->sess.sessionTeam == TEAM_ALLIES || client->sess.sessionTeam == TEAM_AXIS) ? qtrue : qfalse;
#ifdef FEATURE_OMNIBOT
qboolean doDrop = (g_spectatorInactivity.integer && (g_maxclients.integer - level.numNonSpectatorClients + g_OmniBotPlaying.integer <= 0)) ? qtrue : qfalse;
#else
qboolean doDrop = (g_spectatorInactivity.integer && (g_maxclients.integer - level.numNonSpectatorClients <= 0)) ? qtrue : qfalse;
#endif
// no countdown in warmup and intermission
if (g_gamestate.integer != GS_PLAYING)
{
return qtrue;
}
// inactivity settings disabled?
if (g_inactivity.integer == 0 && g_spectatorInactivity.integer == 0)
{
// Give everyone some time, so if the operator sets g_inactivity or g_spectatorinactivity during
// gameplay, everyone isn't kicked or moved to spectators
client->inactivityTime = level.time + 60000;
client->inactivityWarning = qfalse;
return qtrue;
}
// the client is still active?
if (client->pers.cmd.forwardmove || client->pers.cmd.rightmove || client->pers.cmd.upmove ||
(client->pers.cmd.wbuttons & (WBUTTON_ATTACK2 | WBUTTON_LEANLEFT | WBUTTON_LEANRIGHT)) ||
(client->pers.cmd.buttons & BUTTON_ATTACK) ||
BG_PlayerMounted(client->ps.eFlags) ||
((client->ps.eFlags & EF_PRONE) && (client->ps.weapon == WP_MOBILE_MG42_SET || client->ps.weapon == WP_MOBILE_BROWNING_SET)) ||
(client->ps.pm_flags & PMF_LIMBO) || (client->ps.pm_type == PM_DEAD) ||
client->sess.shoutcaster)
{
client->inactivityWarning = qfalse;
if (inTeam)
{
client->inactivityTime = level.time + 1000 * inactivity;
}
else
{
client->inactivityTime = level.time + 1000 * inactivityspec;
}
return qtrue;
}
// no inactivity for localhost
if (client->pers.localClient)
{
return qtrue;
}
// start countdown
if (!client->inactivityWarning)
{
if (g_inactivity.integer && (level.time > client->inactivityTime - inactivity) && inTeam)
{
client->inactivityWarning = qtrue;
client->inactivityTime = level.time + 1000 * inactivity;
client->inactivitySecondsLeft = inactivity;
}
// if a player will not be kicked from the server (because there are still free slots),
// do not display messages for inactivity-drop/kick.
else if (doDrop && g_spectatorInactivity.integer &&
(level.time > client->inactivityTime - inactivityspec) && !inTeam)
{
client->inactivityWarning = qtrue;
client->inactivityTime = level.time + 1000 * inactivityspec;
client->inactivitySecondsLeft = inactivityspec;
}
if (g_inactivity.integer && inTeam)
{
int secondsLeft = (client->inactivityTime + inactivity - level.time) / 1000;
// countdown expired..
if (secondsLeft <= 0)
{
CPx(client - level.clients, "cp \"^3Moved to spectator for inactivity\n\"");
}
// display a message at 30 seconds, and countdown at last 10 ..
else if (secondsLeft <= 10 || secondsLeft == 30)
{
CPx(client - level.clients, va("cp \"^1%i ^3seconds until moving to spectator for inactivity\n\"", secondsLeft));
}
}
else if (doDrop && g_spectatorInactivity.integer && !inTeam)
{
int secondsLeft = (client->inactivityTime + inactivityspec - level.time) / 1000;
// countdown expired..
if (secondsLeft <= 0)
{
CPx(client - level.clients, "cp \"^3Dropped for inactivity\n\"");
}
// display a message at 30 seconds, and countdown at last 10 ..
else if (secondsLeft <= 10 || secondsLeft == 30)
{
CPx(client - level.clients, va("cp \"^1%i ^3seconds until inactivity drop\n\"", secondsLeft));
}
}
}
else
{
if (inTeam && g_inactivity.integer)
{
SetTeam(&g_entities[client - level.clients], "s", qtrue, WP_NONE, WP_NONE, qfalse);
client->inactivityWarning = qfalse;
client->inactivityTime = level.time + 1000 * inactivityspec;
client->inactivitySecondsLeft = inactivityspec;
G_Printf("Moved to spectator for inactivity: %s\n", client->pers.netname);
}
else if (doDrop && g_spectatorInactivity.integer && !inTeam)
{
// slots occupied by bots should be considered "free",
// because bots will disconnect if a human player connects..
G_Printf("Spectator dropped for inactivity: %s\n", client->pers.netname);
trap_DropClient(client - level.clients, "Dropped due to inactivity", 0);
return qfalse;
}
}
// do not kick by default
return qtrue;
}
/**
* @brief Actions that happen once a second
* @param[in,out] ent Entity
* @param msec Scheduler time
*/
void ClientTimerActions(gentity_t *ent, int msec)
{
gclient_t *client = ent->client;
client->timeResidual += msec;
while (client->timeResidual >= 1000)
{
client->timeResidual -= 1000;
// regenerate
if (ent->health < client->ps.stats[STAT_MAX_HEALTH])
{
// medic only
if (client->sess.playerType == PC_MEDIC)
{
if (ent->health > client->ps.stats[STAT_MAX_HEALTH] / 1.11)
{
ent->health += 2;
if (ent->health > client->ps.stats[STAT_MAX_HEALTH])
{
ent->health = client->ps.stats[STAT_MAX_HEALTH];
}
}
else
{
ent->health += 3;
if (ent->health > client->ps.stats[STAT_MAX_HEALTH] / 1.1)
{
ent->health = client->ps.stats[STAT_MAX_HEALTH] / 1.1;
}
}
}
}
else if (ent->health > client->ps.stats[STAT_MAX_HEALTH]) // count down health when over max
{
ent->health--;
}
}
}
/**
* @brief ClientIntermissionThink
* @param[in,out] client Client
*/
void ClientIntermissionThink(gclient_t *client)
{
client->ps.eFlags &= ~EF_TALK;
client->ps.eFlags &= ~EF_FIRING;
// the level will exit when everyone wants to or after timeouts
// swap and latch button actions
client->oldbuttons = client->buttons;
client->buttons = client->pers.cmd.buttons;
client->oldwbuttons = client->wbuttons;
client->wbuttons = client->pers.cmd.wbuttons;
}
/**
* @brief G_FallDamage
* @param[in,out] ent
* @param[in] event
*/
void G_FallDamage(gentity_t *ent, int event)
{
int damage;
if (ent->s.eType != ET_PLAYER)
{
return; // not in the player model
}
if (event == EV_FALL_NDIE)
{
// this damage is used for stats (pushing players to death) - ensure we gib
if (ent->health > 0)
{
damage = GIB_DAMAGE(ent->health);
}
else
{
damage = -GIB_HEALTH + 1;
}
}
else if (event == EV_FALL_DMG_50)
{
damage = 50;
}
else if (event == EV_FALL_DMG_25)
{
damage = 25;
}
else if (event == EV_FALL_DMG_15)
{
damage = 15;
}
else if (event == EV_FALL_DMG_10)
{
damage = 10;
}
else
{
damage = 5; // never used
}
ent->pain_debounce_time = level.time + 200; // no normal pain sound
G_Damage(ent, NULL, NULL, NULL, NULL, damage, 0, MOD_FALLING);
}
/**
* @brief Events will be passed on to the clients for presentation,
* but any server game effects are handled here
*
* @param[in] ent Pointer to Entity
* @param oldEventSequence Old event sequence number
*/
void ClientEvents(gentity_t *ent, int oldEventSequence)
{
int i;
int event;
gclient_t *client = ent->client;
gentity_t *self;
if (oldEventSequence < client->ps.eventSequence - MAX_EVENTS)
{
oldEventSequence = client->ps.eventSequence - MAX_EVENTS;
}
for (i = oldEventSequence ; i < client->ps.eventSequence ; i++)
{
event = client->ps.events[i & (MAX_EVENTS - 1)];
switch (event)
{
case EV_FALL_NDIE:
//case EV_FALL_SHORT:
case EV_FALL_DMG_10:
case EV_FALL_DMG_15:
case EV_FALL_DMG_25:
case EV_FALL_DMG_50:
G_FallDamage(ent, event);
ent->client->pmext.shoved = qfalse;
break;
case EV_FIRE_WEAPON_MG42:
// reset player disguise on firing mounted mg
ent->client->ps.powerups[PW_OPS_DISGUISED] = 0;
ent->client->disguiseClientNum = -1;
G_HistoricalTraceBegin(ent);
mg42_fire(ent);