-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathg_active.cpp
3327 lines (2889 loc) · 136 KB
/
g_active.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) 1999-2000 Id Software, Inc.
//
#include "g_local.h"
#include "bg_saga.h"
#include "bg_local.h"
#include "JAPP/jp_csflags.h"
#include "bg_lua.h"
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <map>
#include <unordered_map>
#include <cmath>
qboolean PM_SaberInTransition(int move);
qboolean PM_SaberInReturn(int move);
qboolean WP_SaberStyleValidForSaber(saberInfo_t *saber1, saberInfo_t *saber2, int saberHolstered, int saberAnimLevel);
qboolean saberCheckKnockdown_DuelLoss(gentity_t *saberent, gentity_t *saberOwner, gentity_t *other);
void P_SetTwitchInfo(gclient_t *client) {
client->ps.painTime = level.time;
client->ps.painDirection ^= 1;
}
// Called just before a snapshot is sent to the given player.
// 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.
void P_DamageFeedback(gentity_t *player) {
gclient_t *client;
float count;
vector3 angles;
client = player->client;
if (client->ps.pm_type == PM_DEAD) {
return;
}
// total points of damage shot at the player this frame
count = client->damage_blood + client->damage_armor;
if (count == 0) {
return; // didn't take any damage
}
if (count > 255) {
count = 255;
}
// 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 {
vectoangles(&client->damage_from, &angles);
client->ps.damagePitch = angles.pitch / 360.0f * 256;
client->ps.damageYaw = angles.yaw / 360.0f * 256;
// cap them since we can't send negative values in here across the net
if (client->ps.damagePitch < 0)
client->ps.damagePitch = 0;
if (client->ps.damageYaw < 0)
client->ps.damageYaw = 0;
}
// play an apropriate pain sound
if ((level.time > player->pain_debounce_time) && !(player->flags & FL_GODMODE) && !(player->s.eFlags & EF_DEAD)) {
// don't do more than two pain sounds a second
// nmckenzie: also don't make him loud and whiny if he's only getting nicked.
if (level.time - client->ps.painTime < 500 || count < 10) {
return;
}
P_SetTwitchInfo(client);
player->pain_debounce_time = level.time + 700;
// Raz: Render health ESP's useless
G_AddEvent(player, EV_PAIN, 100 /*player->health*/);
client->ps.damageEvent++;
if (client->damage_armor && !client->damage_blood)
client->ps.damageType = 1; // pure shields
else if (client->damage_armor)
client->ps.damageType = 2; // shields and health
else
client->ps.damageType = 0; // pure health
}
client->ps.damageCount = count;
//
// clear totals
//
client->damage_blood = 0;
client->damage_armor = 0;
}
// Check for lava / slime contents and drowning
void P_WorldEffects(gentity_t *ent) {
qboolean envirosuit;
int waterlevel;
if (ent->client->noclip || (dmflags.bits & DF_NO_DROWN)) {
ent->client->airOutTime = level.time + 12000; // don't need air
return;
}
waterlevel = ent->waterlevel;
envirosuit = ent->client->ps.powerups[PW_BATTLESUIT] > level.time;
//
// check for drowning
//
if (waterlevel == 3) {
// envirosuit give air
if (envirosuit) {
ent->client->airOutTime = level.time + 10000;
}
// if out of air, start drowning
if (ent->client->airOutTime < level.time) {
// drown!
ent->client->airOutTime += 1000;
if (ent->health > 0) {
// take more damage the longer underwater
ent->damage += 2;
if (ent->damage > 15)
ent->damage = 15;
// play a gurp sound instead of a normal pain sound
if (ent->health <= ent->damage) {
G_Sound(ent, CHAN_VOICE, G_SoundIndex(/*"*drown.wav"*/ "sound/player/gurp1.wav"));
} else if (rand() & 1) {
G_Sound(ent, CHAN_VOICE, G_SoundIndex("sound/player/gurp1.wav"));
} else {
G_Sound(ent, CHAN_VOICE, G_SoundIndex("sound/player/gurp2.wav"));
}
// don't play a normal pain sound
ent->pain_debounce_time = level.time + 200;
G_Damage(ent, NULL, NULL, NULL, NULL, ent->damage, DAMAGE_NO_ARMOR, MOD_WATER);
}
}
} else {
ent->client->airOutTime = level.time + 12000;
ent->damage = 2;
}
//
// check for sizzle damage (move to pmove?)
//
if (waterlevel && (ent->watertype & (CONTENTS_LAVA | CONTENTS_SLIME))) {
if (ent->health > 0 && ent->pain_debounce_time <= level.time) {
if (envirosuit) {
G_AddEvent(ent, EV_POWERUP_BATTLESUIT, 0);
} else {
if (ent->watertype & CONTENTS_LAVA) {
G_Damage(ent, NULL, NULL, NULL, NULL, 30 * waterlevel, 0, MOD_LAVA);
}
if (ent->watertype & CONTENTS_SLIME) {
G_Damage(ent, NULL, NULL, NULL, NULL, 10 * waterlevel, 0, MOD_SLIME);
}
}
}
}
}
void G_ApplyKnockback(gentity_t *targ, vector3 *newDir, float knockback);
void DoImpact(gentity_t *self, gentity_t *other, qboolean damageSelf) {
float magnitude, my_mass;
vector3 velocity;
int cont;
qboolean easyBreakBrush = qtrue;
if (self->client) {
VectorCopy(&self->client->ps.velocity, &velocity);
if (!self->mass)
my_mass = 10;
else
my_mass = self->mass;
} else {
VectorCopy(&self->s.pos.trDelta, &velocity);
if (self->s.pos.trType == TR_GRAVITY)
velocity.z -= 0.25f * g_gravity.value;
if (!self->mass)
my_mass = 1;
else if (self->mass <= 10)
my_mass = 10;
else
my_mass = self->mass; /// 10;
}
magnitude = VectorLength(&velocity) * my_mass / 10;
if (other->material == MAT_GLASS || other->material == MAT_GLASS_METAL || other->material == MAT_GRATE1 ||
((other->flags & FL_BBRUSH) && (other->spawnflags & 8 /*THIN*/)) || (other->r.svFlags & SVF_GLASS_BRUSH)) {
easyBreakBrush = qtrue;
}
if (!self->client || self->client->ps.lastOnGround + 300 < level.time || (self->client->ps.lastOnGround + 100 < level.time && easyBreakBrush)) {
vector3 dir1, dir2;
float force = 0, dot;
if (easyBreakBrush)
magnitude *= 2;
// damage them
if (magnitude >= 100 && other->s.number < ENTITYNUM_WORLD) {
VectorCopy(&velocity, &dir1);
VectorNormalize(&dir1);
if (VectorCompare(&other->r.currentOrigin, &vec3_origin)) { // a brush with no origin
VectorCopy(&dir1, &dir2);
} else {
VectorSubtract(&other->r.currentOrigin, &self->r.currentOrigin, &dir2);
VectorNormalize(&dir2);
}
dot = DotProduct(&dir1, &dir2);
if (dot >= 0.2f)
force = dot;
else
force = 0;
force *= (magnitude / 50);
cont = trap->PointContents(&other->r.absmax, other->s.number);
if ((cont & CONTENTS_WATER)) //|| (self.classname=="barrel"&&self.aflag))//FIXME: or other watertypes
{
force /= 3; // water absorbs 2/3 velocity
}
/*
if(self.frozen>0&&force>10)
force=10;
*/
if ((force >= 1 && other->s.number >= MAX_CLIENTS) || force >= 10) {
/*
dprint("Damage other (");
dprint(loser.classname);
dprint("): ");
dprint(ftos(force));
dprint("\n");
*/
if (other->r.svFlags & SVF_GLASS_BRUSH) {
other->splashRadius = (float)(self->r.maxs.x - self->r.mins.x) / 4.0f;
}
if (other->takedamage) {
G_Damage(other, self, self, &velocity, &self->r.currentOrigin, force, DAMAGE_NO_ARMOR, MOD_CRUSH); // FIXME: MOD_IMPACT
} else {
G_ApplyKnockback(other, &dir2, force);
}
}
}
if (damageSelf && self->takedamage) {
// Now damage me
// FIXME: more lenient falling damage, especially for when driving a vehicle
if (self->client && self->client->ps.fd.forceJumpZStart) { // we were force-jumping
if (self->r.currentOrigin.z >= self->client->ps.fd.forceJumpZStart) { // we landed at same height or higher than we landed
magnitude = 0;
} else { // FIXME: take off some of it, at least?
magnitude = (self->client->ps.fd.forceJumpZStart - self->r.currentOrigin.z) / 3;
}
}
// if(self.classname!="monster_mezzoman"&&self.netname!="spider")//Cats always land on their feet
if ((magnitude >= 100 + self->health && self->s.number >= MAX_CLIENTS && self->s.weapon != WP_SABER) ||
(magnitude >= 700)) //&& self.safe_time < level.time ))//health here is used to simulate structural integrity
{
if ((self->s.weapon == WP_SABER) && self->client && self->client->ps.groundEntityNum < ENTITYNUM_NONE &&
magnitude < 1000) { // players and jedi take less impact damage
// allow for some lenience on high falls
magnitude /= 2;
/*
if ( self.absorb_time >= time )//crouching on impact absorbs 1/2 the damage
{
magnitude/=2;
}
*/
}
magnitude /= 40;
magnitude = magnitude - force / 2; // If damage other, subtract half of that damage off of own injury
if (magnitude >= 1) {
// FIXME: Put in a thingtype impact sound function
/*
dprint("Damage self (");
dprint(self.classname);
dprint("): ");
dprint(ftos(magnitude));
dprint("\n");
*/
/*
if ( self.classname=="player_sheep "&& self.flags&FL_ONGROUND && self.velocity_z > -50 )
return;
*/
G_Damage(self, NULL, NULL, NULL, &self->r.currentOrigin, magnitude / 2, DAMAGE_NO_ARMOR, MOD_FALLING); // FIXME: MOD_IMPACT
}
}
}
// FIXME: slow my velocity some?
// NOTENOTE We don't use lastimpact as of yet
// self->lastImpact = level.time;
/*
if(self.flags&FL_ONGROUND)
self.last_onground=time;
*/
}
}
void Client_CheckImpactBBrush(gentity_t *self, gentity_t *other) {
if (!other || !other->inuse) {
return;
}
if (!self || !self->inuse || !self->client || self->client->tempSpectate >= level.time ||
self->client->sess.sessionTeam == TEAM_SPECTATOR) { // hmm.. let's not let spectators ram into breakables.
return;
}
/*
if (BG_InSpecialJump(self->client->ps.legsAnim))
{ //don't do this either, qa says it creates "balance issues"
return;
}
*/
if (other->material == MAT_GLASS || other->material == MAT_GLASS_METAL || other->material == MAT_GRATE1 ||
((other->flags & FL_BBRUSH) && (other->spawnflags & 8 /*THIN*/)) || ((other->flags & FL_BBRUSH) && (other->health <= 10)) ||
(other->r.svFlags & SVF_GLASS_BRUSH)) { // clients only do impact damage against easy-break breakables
DoImpact(self, other, qfalse);
}
}
void G_SetClientSound(gentity_t *ent) {
if (ent->client && ent->client->isHacking) { // loop hacking sound
ent->client->ps.loopSound = level.snd_hack;
ent->s.loopIsSoundset = qfalse;
} else if (ent->client && ent->client->timeMedHealed > level.time) { // loop healing sound
ent->client->ps.loopSound = level.snd_medHealed;
ent->s.loopIsSoundset = qfalse;
} else if (ent->client && ent->client->timeMedSupplied > level.time) { // loop supplying sound
ent->client->ps.loopSound = level.snd_medSupplied;
ent->s.loopIsSoundset = qfalse;
} else if (ent->waterlevel && (ent->watertype & (CONTENTS_LAVA | CONTENTS_SLIME))) {
ent->client->ps.loopSound = level.snd_fry;
ent->s.loopIsSoundset = qfalse;
} else {
ent->client->ps.loopSound = 0;
ent->s.loopIsSoundset = qfalse;
}
}
void ClientImpacts(gentity_t *ent, pmove_t *pm) {
int i, j;
trace_t trace;
gentity_t *other;
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]];
if (ent->r.svFlags & SVF_BOT) {
JPLua::Entity_CallFunction(ent, JPLua::JPLUA_ENTITY_TOUCH, (intptr_t)other, (intptr_t)&trace);
if (ent->touch) {
ent->touch(ent, other, &trace);
}
}
if (other->touch) {
other->touch(other, ent, &trace);
}
JPLua::Entity_CallFunction(ent, JPLua::JPLUA_ENTITY_TOUCH, (intptr_t)other, (intptr_t)&trace);
}
}
// Find all trigger entities that ent's current position touches.
// 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;
vector3 mins, maxs;
static vector3 range = {40, 40, 52};
if (!ent->client) {
return;
}
// 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->r.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 && (!hit->uselua && !hit->lua_touch) && !ent->touch && (!ent->uselua && !ent->lua_touch)) {
continue;
}
if (!(hit->r.contents & CONTENTS_TRIGGER)) {
continue;
}
// ignore most entities if a spectator
if (ent->client->sess.sessionTeam == TEAM_SPECTATOR) {
if (hit->s.eType != ET_TELEPORT_TRIGGER &&
// this is ugly but adding a new ET_? type will
// most likely cause network incompatibilities
hit->touch != Touch_DoorTrigger) {
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 {
if (!trap->EntityContact(&mins, &maxs, (sharedEntity_t *)hit, qfalse))
continue;
}
memset(&trace, 0, sizeof(trace));
if (hit->touch) {
hit->touch(hit, ent, &trace);
}
JPLua::Entity_CallFunction(hit, JPLua::JPLUA_ENTITY_TOUCH, (intptr_t)ent, (intptr_t)&trace);
if (ent->r.svFlags & SVF_BOT) {
if (ent->touch) {
ent->touch(ent, hit, &trace);
}
JPLua::Entity_CallFunction(ent, JPLua::JPLUA_ENTITY_TOUCH, (intptr_t)hit, (intptr_t)&trace);
}
}
// if we didn't touch a jump pad this pmove frame
if (ent->client->ps.jumppad_frame != ent->client->ps.pmove_framecount) {
ent->client->ps.jumppad_frame = 0;
ent->client->ps.jumppad_ent = 0;
}
}
// Find all trigger entities that ent's current position touches.
// Spectators will only interact with teleporters.
void G_MoverTouchPushTriggers(gentity_t *ent, vector3 *oldOrg) {
int i, num;
float step, stepSize, dist;
int touch[MAX_GENTITIES];
gentity_t *hit;
trace_t trace;
vector3 mins, maxs, dir, size, checkSpot;
const vector3 range = {40, 40, 52};
// non-moving movers don't hit triggers!
if (!VectorLengthSquared(&ent->s.pos.trDelta)) {
return;
}
VectorSubtract(&ent->r.mins, &ent->r.maxs, &size);
stepSize = VectorLength(&size);
if (stepSize < 1) {
stepSize = 1;
}
VectorSubtract(&ent->r.currentOrigin, oldOrg, &dir);
dist = VectorNormalize(&dir);
for (step = 0; step <= dist; step += stepSize) {
VectorMA(&ent->r.currentOrigin, step, &dir, &checkSpot);
VectorSubtract(&checkSpot, &range, &mins);
VectorAdd(&checkSpot, &range, &maxs);
num = trap->EntitiesInBox(&mins, &maxs, touch, MAX_GENTITIES);
// can't use ent->r.absmin, because that has a one unit pad
VectorAdd(&checkSpot, &ent->r.mins, &mins);
VectorAdd(&checkSpot, &ent->r.maxs, &maxs);
for (i = 0; i < num; i++) {
hit = &g_entities[touch[i]];
if (hit->s.eType != ET_PUSH_TRIGGER)
continue;
if (hit->touch == NULL)
continue;
if (!(hit->r.contents & CONTENTS_TRIGGER))
continue;
if (!trap->EntityContact(&mins, &maxs, (sharedEntity_t *)hit, qfalse)) {
continue;
}
memset(&trace, 0, sizeof(trace));
if (hit->touch != NULL)
hit->touch(hit, ent, &trace);
JPLua::Entity_CallFunction(hit, JPLua::JPLUA_ENTITY_TOUCH, (intptr_t)ent, (intptr_t)&trace);
}
}
}
static void SV_PMTrace(trace_t *results, const vector3 *start, const vector3 *mins, const vector3 *maxs, const vector3 *end, int passEntityNum,
int contentMask) {
trap->Trace(results, start, mins, maxs, end, passEntityNum, contentMask, qfalse, 0, 0);
}
void SpectatorThink(gentity_t *ent, usercmd_t *ucmd) {
pmove_t pm;
gclient_t *client;
client = ent->client;
if (client->sess.spectatorState != SPECTATOR_FOLLOW) {
client->ps.pm_type = PM_SPECTATOR;
client->ps.speed = 400; // faster than normal
client->ps.basespeed = 400;
// OSP: pause
if (level.pause.state != PAUSE_NONE)
client->ps.pm_type = PM_FREEZE;
// hmm, shouldn't have an anim if you're a spectator, make sure
// it gets cleared.
client->ps.legsAnim = 0;
client->ps.legsTimer = 0;
client->ps.torsoAnim = 0;
client->ps.torsoTimer = 0;
// set up for pmove
memset(&pm, 0, sizeof(pm));
pm.ps = &client->ps;
pm.cmd = *ucmd;
pm.tracemask = MASK_PLAYERSOLID & ~CONTENTS_BODY; // spectators can fly through bodies
pm.trace = SV_PMTrace;
pm.pointcontents = trap->PointContents;
pm.noSpecMove = g_noSpecMove.integer;
pm.animations = NULL;
pm.nonHumanoid = qfalse;
// Set up bg entity data
pm.baseEnt = (bgEntity_t *)g_entities;
pm.entSize = sizeof(gentity_t);
// perform a pmove
Pmove(&pm);
// save results of pmove
VectorCopy(&client->ps.origin, &ent->s.origin);
if (ent->client->tempSpectate < level.time) {
G_TouchTriggers(ent);
}
trap->UnlinkEntity((sharedEntity_t *)ent);
}
client->oldbuttons = client->buttons;
client->buttons = ucmd->buttons;
if (client->tempSpectate < level.time) {
// attack button cycles through spectators
if ((client->buttons & BUTTON_ATTACK) && !(client->oldbuttons & BUTTON_ATTACK))
Cmd_FollowCycle_f(ent, 1);
else if (client->sess.spectatorState == SPECTATOR_FOLLOW && (client->buttons & BUTTON_ALT_ATTACK) && !(client->oldbuttons & BUTTON_ALT_ATTACK))
Cmd_FollowCycle_f(ent, -1);
if (client->sess.spectatorState == SPECTATOR_FOLLOW && (ucmd->upmove > 0)) { // jump now removes you from follow mode
StopFollowing(ent);
}
}
}
// Returns qfalse if the client is dropped
qboolean ClientInactivityTimer(gclient_t *client) {
if (!g_inactivity.integer) {
// give everyone some time, so if the operator sets g_inactivity during
// gameplay, everyone isn't kicked
client->inactivityTime = level.time + 60 * 1000;
client->inactivityWarning = qfalse;
} else if (client->pers.cmd.forwardmove || client->pers.cmd.rightmove || client->pers.cmd.upmove ||
(client->pers.cmd.buttons & (BUTTON_ATTACK | BUTTON_ALT_ATTACK))) {
client->inactivityTime = level.time + g_inactivity.integer * 1000;
client->inactivityWarning = qfalse;
} else if (!client->pers.localClient) {
if (level.time > client->inactivityTime) {
trap->DropClient(client - level.clients, "Dropped due to inactivity");
return qfalse;
}
if (level.time > client->inactivityTime - 10000 && !client->inactivityWarning) {
client->inactivityWarning = qtrue;
trap->SendServerCommand(client - level.clients, "cp \"Ten seconds until inactivity drop!\n\"");
}
}
return qtrue;
}
// Actions that happen once a second
void ClientTimerActions(gentity_t *ent, int msec) {
gclient_t *client;
client = ent->client;
client->timeResidual += msec;
while (client->timeResidual >= 1000) {
client->timeResidual -= 1000;
// count down health when over max
if (ent->health > client->ps.stats[STAT_MAX_HEALTH]) {
ent->health--;
}
// count down armor when over max
if (client->ps.stats[STAT_ARMOR] > client->ps.stats[STAT_MAX_HEALTH]) {
client->ps.stats[STAT_ARMOR]--;
}
}
}
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;
if (client->buttons & (BUTTON_ATTACK | BUTTON_USE_HOLDABLE) & (client->oldbuttons ^ client->buttons)) {
// this used to be an ^1 but once a player says ready, it should stick
client->readyToExit = 1;
}
}
void NPC_SetAnim(gentity_t *ent, int setAnimParts, int anim, uint32_t setAnimFlags);
void G_VehicleAttachDroidUnit(gentity_t *vehEnt) {
if (vehEnt && vehEnt->m_pVehicle && vehEnt->m_pVehicle->m_pDroidUnit != NULL) {
gentity_t *droidEnt = (gentity_t *)vehEnt->m_pVehicle->m_pDroidUnit;
mdxaBone_t boltMatrix;
vector3 fwd;
trap->G2API_GetBoltMatrix(vehEnt->ghoul2, 0, vehEnt->m_pVehicle->m_iDroidUnitTag, &boltMatrix, &vehEnt->r.currentAngles, &vehEnt->r.currentOrigin,
level.time, NULL, &vehEnt->modelScale);
BG_GiveMeVectorFromMatrix(&boltMatrix, ORIGIN, &droidEnt->r.currentOrigin);
BG_GiveMeVectorFromMatrix(&boltMatrix, NEGATIVE_Y, &fwd);
vectoangles(&fwd, &droidEnt->r.currentAngles);
if (droidEnt->client) {
VectorCopy(&droidEnt->r.currentAngles, &droidEnt->client->ps.viewangles);
VectorCopy(&droidEnt->r.currentOrigin, &droidEnt->client->ps.origin);
}
G_SetOrigin(droidEnt, &droidEnt->r.currentOrigin);
trap->LinkEntity((sharedEntity_t *)droidEnt);
if (droidEnt->NPC) {
NPC_SetAnim(droidEnt, SETANIM_BOTH, BOTH_STAND2, SETANIM_FLAG_OVERRIDE | SETANIM_FLAG_HOLD);
}
}
}
// called gameside only from pmove code (convenience)
void G_CheapWeaponFire(int entNum, int ev) {
gentity_t *ent = &g_entities[entNum];
if (!ent->inuse || !ent->client) {
return;
}
switch (ev) {
case EV_FIRE_WEAPON:
if (ent->m_pVehicle && ent->m_pVehicle->m_pVehicleInfo->type == VH_SPEEDER && ent->client && ent->client->ps.m_iVehicleNum) { // a speeder with a pilot
gentity_t *rider = &g_entities[ent->client->ps.m_iVehicleNum - 1];
if (rider->inuse && rider->client) {
// pilot is valid...
if (rider->client->ps.weapon != WP_MELEE &&
(rider->client->ps.weapon != WP_SABER ||
!BG_SabersOff(&rider->client->ps))) { // can only attack on speeder when using melee or when saber is holstered
break;
}
}
}
FireWeapon(ent, qfalse);
ent->client->dangerTime = level.time;
ent->client->ps.eFlags &= ~EF_INVULNERABLE;
ent->client->invulnerableTimer = 0;
break;
case EV_ALT_FIRE:
FireWeapon(ent, qtrue);
ent->client->dangerTime = level.time;
ent->client->ps.eFlags &= ~EF_INVULNERABLE;
ent->client->invulnerableTimer = 0;
break;
default:
break;
}
}
qboolean BG_InKnockDownOnly(int anim);
// Events will be passed on to the clients for presentation, but any server game effects are handled here
void ClientEvents(gentity_t *ent, int oldEventSequence) {
int i; //, j;
int event;
gclient_t *client;
int damage;
vector3 dir;
// vector3 origin, angles;
// qboolean fired;
// gitem_t *item;
// gentity_t *drop;
client = ent->client;
if (oldEventSequence < client->ps.eventSequence - MAX_PS_EVENTS) {
oldEventSequence = client->ps.eventSequence - MAX_PS_EVENTS;
}
for (i = oldEventSequence; i < client->ps.eventSequence; i++) {
event = client->ps.events[i & (MAX_PS_EVENTS - 1)];
switch (event) {
case EV_FALL:
case EV_ROLL: {
int delta = client->ps.eventParms[i & (MAX_PS_EVENTS - 1)];
qboolean knockDownage = qfalse;
if (ent->client && ent->client->ps.fallingToDeath) {
break;
}
if (ent->s.eType != ET_PLAYER) {
break; // not in the player model
}
if (dmflags.bits & DF_NO_FALLING) {
break;
}
if (BG_InKnockDownOnly(ent->client->ps.legsAnim)) {
if (delta <= 14) {
break;
}
knockDownage = qtrue;
} else {
if (delta <= 44) {
break;
}
}
if (knockDownage) {
damage = delta * 1; // you suffer for falling unprepared. A lot. Makes throws and things useful, and more realistic I suppose.
} else {
if (level.gametype == GT_SIEGE && delta > 60) { // longer falls hurt more
damage = delta * 1; // good enough for now, I guess
} else {
damage = delta * 0.16f; // good enough for now, I guess
}
}
VectorSet(&dir, 0, 0, 1);
ent->pain_debounce_time = level.time + 200; // no normal pain sound
G_Damage(ent, NULL, NULL, NULL, NULL, damage, DAMAGE_NO_ARMOR, MOD_FALLING);
if (ent->health < 1) {
G_Sound(ent, CHAN_AUTO, G_SoundIndex("sound/player/fallsplat.wav"));
}
} break;
case EV_FIRE_WEAPON:
FireWeapon(ent, qfalse);
ent->client->dangerTime = level.time;
ent->client->ps.eFlags &= ~EF_INVULNERABLE;
ent->client->invulnerableTimer = 0;
break;
case EV_ALT_FIRE:
FireWeapon(ent, qtrue);
ent->client->dangerTime = level.time;
ent->client->ps.eFlags &= ~EF_INVULNERABLE;
ent->client->invulnerableTimer = 0;
break;
case EV_SABER_ATTACK:
ent->client->dangerTime = level.time;
ent->client->ps.eFlags &= ~EF_INVULNERABLE;
ent->client->invulnerableTimer = 0;
break;
// rww - Note that these must be in the same order (ITEM#-wise) as they are in holdable_e
case EV_USE_ITEM1: // seeker droid
ItemUse_Seeker(ent);
break;
case EV_USE_ITEM2: // shield
ItemUse_Shield(ent);
break;
case EV_USE_ITEM3: // medpack
ItemUse_MedPack(ent);
break;
case EV_USE_ITEM4: // big medpack
ItemUse_MedPack_Big(ent);
break;
case EV_USE_ITEM5: // binoculars
ItemUse_Binoculars(ent);
break;
case EV_USE_ITEM6: // sentry gun
ItemUse_Sentry(ent);
break;
case EV_USE_ITEM7: // jetpack
ItemUse_Jetpack(ent);
break;
case EV_USE_ITEM8: // health disp
// ItemUse_UseDisp(ent, HI_HEALTHDISP);
break;
case EV_USE_ITEM9: // ammo disp
// ItemUse_UseDisp(ent, HI_AMMODISP);
break;
case EV_USE_ITEM10: // eweb
ItemUse_UseEWeb(ent);
break;
case EV_USE_ITEM11: // cloak
ItemUse_UseCloak(ent);
break;
default:
break;
}
}
}
void SendPendingPredictableEvents(playerState_t *ps) {
gentity_t *t;
int event, seq;
int extEvent, number;
// if there are still events pending
if (ps->entityEventSequence < ps->eventSequence) {
// create a temporary entity for this event which is sent to everyone
// except the client who generated the event
seq = ps->entityEventSequence & (MAX_PS_EVENTS - 1);
event = ps->events[seq] | ((ps->entityEventSequence & 3) << 8);
// set external event to zero before calling BG_PlayerStateToEntityState
extEvent = ps->externalEvent;
ps->externalEvent = 0;
// create temporary entity for event
t = G_TempEntity(&ps->origin, event);
number = t->s.number;
BG_PlayerStateToEntityState(ps, &t->s, qtrue);
t->s.number = number;
t->s.eType = ET_EVENTS + event;
t->s.eFlags |= EF_PLAYER_EVENT;
t->s.otherEntityNum = ps->clientNum;
// send to everyone except the client who generated the event
t->r.svFlags |= SVF_NOTSINGLECLIENT;
t->r.singleClient = ps->clientNum;
// set back external event
ps->externalEvent = extEvent;
}
}
static const float maxJediMasterDistance = (float)(2500 * 2500); // x^2, optimisation
static const float maxJediMasterFOV = 100.0f;
static const float maxForceSightDistance = (float)(1500 * 1500); // x^2, optimisation
static const float maxForceSightFOV = 100.0f;
void G_UpdateClientBroadcasts(gentity_t *self) {
int i;
gentity_t *other;
// we are always sent to ourselves
// we are always sent to other clients if we are in their PVS
// if we are not in their PVS, we must set the broadcastClients bit field
// if we do not wish to be sent to any particular entity, we must set the broadcastClients bit field and the
// SVF_BROADCASTCLIENTS bit flag
self->r.broadcastClients[0] = 0u;
self->r.broadcastClients[1] = 0u;
if (self->client->pers.adminData.isGhost || japp_antiWallhack.integer) {
self->r.svFlags |= SVF_BROADCASTCLIENTS;
} else {
self->r.svFlags &= ~SVF_BROADCASTCLIENTS;
}
for (i = 0, other = g_entities; i < MAX_CLIENTS; i++, other++) {
qboolean send = qfalse;
float dist;
vector3 angles;
if (!other->inuse || other->client->pers.connected != CON_CONNECTED) {
// no need to compute visibility for non-connected clients
continue;
}
if (other == self) {
// we are always sent to ourselves anyway, this is purely an optimisation
continue;
}
if (self->client->pers.adminData.isGhost) {
if (other->client->pers.adminUser /*&& AM_HasPrivilege( other, PRIV_GHOST )*/) {
send = qtrue;
} else {
// do not send if we are a ghost and they can't see us
continue;
}
}
if (japp_antiWallhack.integer) {
if (G_EntityOccluded(self, other)) {
continue;
} else {
send = qtrue;
}
}
VectorSubtract(&self->client->ps.origin, &other->client->ps.origin, &angles);
dist = VectorLengthSquared(&angles);
vectoangles(&angles, &angles);
// broadcast jedi master to everyone if we are in distance/field of view
if (level.gametype == GT_JEDIMASTER && self->client->ps.isJediMaster) {
if (dist < maxJediMasterDistance && InFieldOfVision(&other->client->ps.viewangles, maxJediMasterFOV, &angles)) {
send = qtrue;
}
}
// broadcast this client to everyone using force sight if we are in distance/field of view
if ((other->client->ps.fd.forcePowersActive & (1 << FP_SEE))) {
if (dist < maxForceSightDistance && InFieldOfVision(&other->client->ps.viewangles, maxForceSightFOV, &angles)) {
send = qtrue;
}
}
if (send) {
Q_AddToBitflags(self->r.broadcastClients, i, 32);
}
}
trap->LinkEntity((sharedEntity_t *)self);
}
void G_AddPushVecToUcmd(gentity_t *self, usercmd_t *ucmd) {
vector3 forward, right, moveDir;
float pushSpeed, fMove, rMove;
if (!self->client) {
return;
}
pushSpeed = VectorLengthSquared(&self->client->pushVec);
if (!pushSpeed) { // not being pushed
return;
}
AngleVectors(&self->client->ps.viewangles, &forward, &right, NULL);
VectorScale(&forward, ucmd->forwardmove / 127.0f * self->client->ps.speed, &moveDir);
VectorMA(&moveDir, ucmd->rightmove / 127.0f * self->client->ps.speed, &right, &moveDir);
// moveDir is now our intended move velocity
VectorAdd(&moveDir, &self->client->pushVec, &moveDir);
self->client->ps.speed = VectorNormalize(&moveDir);
// moveDir is now our intended move velocity plus our push Vector
fMove = 127.0f * DotProduct(&forward, &moveDir);
rMove = 127.0f * DotProduct(&right, &moveDir);