-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathsv_phys.c
3104 lines (2739 loc) · 112 KB
/
sv_phys.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) 1996-1997 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.
*/
// sv_phys.c
#include "quakedef.h"
#include "prvm_cmds.h"
/*
pushmove objects do not obey gravity, and do not interact with each other or trigger fields, but block normal movement and push normal objects when they move.
onground is set for toss objects when they come to a complete rest. it is set for steping or walking objects
doors, plats, etc are SOLID_BSP, and MOVETYPE_PUSH
bonus items are SOLID_TRIGGER touch, and MOVETYPE_TOSS
corpses are SOLID_NOT and MOVETYPE_TOSS
crates are SOLID_BBOX and MOVETYPE_TOSS
walking monsters are SOLID_SLIDEBOX and MOVETYPE_STEP
flying/floating monsters are SOLID_SLIDEBOX and MOVETYPE_FLY
solid_edge items only clip against bsp models.
*/
#define MOVE_EPSILON 0.01
void SV_Physics_Toss (prvm_edict_t *ent);
int SV_GetPitchSign(prvm_prog_t *prog, prvm_edict_t *ent)
{
model_t *model;
if (
(model = SV_GetModelFromEdict(ent))
?
model->type == mod_alias
:
(
(((unsigned char)PRVM_serveredictfloat(ent, pflags)) & PFLAGS_FULLDYNAMIC)
||
((gamemode == GAME_TENEBRAE) && ((unsigned int)PRVM_serveredictfloat(ent, effects) & (16 | 32)))
)
)
return -1;
return 1;
}
/*
===============================================================================
LINE TESTING IN HULLS
===============================================================================
*/
int SV_GenericHitSuperContentsMask(const prvm_edict_t *passedict)
{
prvm_prog_t *prog = SVVM_prog;
if (passedict)
{
int dphitcontentsmask = (int)PRVM_serveredictfloat(passedict, dphitcontentsmask);
if (dphitcontentsmask)
return dphitcontentsmask;
else if (PRVM_serveredictfloat(passedict, solid) == SOLID_SLIDEBOX)
{
if ((int)PRVM_serveredictfloat(passedict, flags) & FL_MONSTER)
return SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_MONSTERCLIP;
else
return SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_PLAYERCLIP;
}
else if (PRVM_serveredictfloat(passedict, solid) == SOLID_CORPSE)
return SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY;
else if (PRVM_serveredictfloat(passedict, solid) == SOLID_TRIGGER)
return SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY;
else
return SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_CORPSE;
}
else
return SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_CORPSE;
}
/*
==================
SV_TracePoint
==================
*/
trace_t SV_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask)
{
prvm_prog_t *prog = SVVM_prog;
int i, bodysupercontents;
int passedictprog;
float pitchsign = 1;
prvm_edict_t *traceowner, *touch;
trace_t trace;
// temporary storage because prvm_vec_t may differ from vec_t
vec3_t touchmins, touchmaxs;
// bounding box of entire move area
vec3_t clipboxmins, clipboxmaxs;
// size when clipping against monsters
vec3_t clipmins2, clipmaxs2;
// start and end origin of move
vec3_t clipstart;
// trace results
trace_t cliptrace;
// matrices to transform into/out of other entity's space
matrix4x4_t matrix, imatrix;
// model of other entity
model_t *model;
// list of entities to test for collisions
int numtouchedicts;
static prvm_edict_t *touchedicts[MAX_EDICTS];
int clipgroup;
//return SV_TraceBox(start, vec3_origin, vec3_origin, end, type, passedict, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask);
VectorCopy(start, clipstart);
VectorClear(clipmins2);
VectorClear(clipmaxs2);
#if COLLISIONPARANOID >= 3
Con_Printf("move(%f %f %f)", clipstart[0], clipstart[1], clipstart[2]);
#endif
// clip to world
Collision_ClipPointToWorld(&cliptrace, sv.worldmodel, clipstart, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask);
cliptrace.worldstartsolid = cliptrace.bmodelstartsolid = cliptrace.startsolid;
if (cliptrace.startsolid || cliptrace.fraction < 1)
cliptrace.ent = prog->edicts;
if (type == MOVE_WORLDONLY)
goto finished;
if (type == MOVE_MISSILE)
{
// LadyHavoc: modified this, was = -15, now -= 15
for (i = 0;i < 3;i++)
{
clipmins2[i] -= 15;
clipmaxs2[i] += 15;
}
}
// create the bounding box of the entire move
for (i = 0;i < 3;i++)
{
clipboxmins[i] = min(clipstart[i], cliptrace.endpos[i]) + clipmins2[i] - 1;
clipboxmaxs[i] = max(clipstart[i], cliptrace.endpos[i]) + clipmaxs2[i] + 1;
}
// debug override to test against everything
if (sv_debugmove.integer)
{
clipboxmins[0] = clipboxmins[1] = clipboxmins[2] = (vec_t)-999999999;
clipboxmaxs[0] = clipboxmaxs[1] = clipboxmaxs[2] = (vec_t)999999999;
}
// if the passedict is world, make it NULL (to avoid two checks each time)
if (passedict == prog->edicts)
passedict = NULL;
// precalculate prog value for passedict for comparisons
passedictprog = PRVM_EDICT_TO_PROG(passedict);
// precalculate passedict's owner edict pointer for comparisons
traceowner = passedict ? PRVM_PROG_TO_EDICT(PRVM_serveredictedict(passedict, owner)) : 0;
clipgroup = passedict ? (int)PRVM_serveredictfloat(passedict, clipgroup) : 0;
// clip to entities
// because this uses World_EntitiestoBox, we know all entity boxes overlap
// the clip region, so we can skip culling checks in the loop below
numtouchedicts = SV_EntitiesInBox(clipboxmins, clipboxmaxs, MAX_EDICTS, touchedicts);
if (numtouchedicts > MAX_EDICTS)
{
// this never happens
Con_Printf("SV_EntitiesInBox returned %i edicts, max was %i\n", numtouchedicts, MAX_EDICTS);
numtouchedicts = MAX_EDICTS;
}
for (i = 0;i < numtouchedicts;i++)
{
touch = touchedicts[i];
if (PRVM_serveredictfloat(touch, solid) < SOLID_BBOX)
continue;
if (type == MOVE_NOMONSTERS && PRVM_serveredictfloat(touch, solid) != SOLID_BSP)
continue;
if (passedict)
{
// don't clip against self
if (passedict == touch)
continue;
// don't clip owned entities against owner
if (traceowner == touch)
continue;
// don't clip owner against owned entities
if (passedictprog == PRVM_serveredictedict(touch, owner))
continue;
// don't clip against any entities in the same clipgroup (DP_RM_CLIPGROUP)
if (clipgroup && clipgroup == (int)PRVM_serveredictfloat(touch, clipgroup))
continue;
// don't clip points against points (they can't collide)
if (VectorCompare(PRVM_serveredictvector(touch, mins), PRVM_serveredictvector(touch, maxs)) && (type != MOVE_MISSILE || !((int)PRVM_serveredictfloat(touch, flags) & FL_MONSTER)))
continue;
}
bodysupercontents = PRVM_serveredictfloat(touch, solid) == SOLID_CORPSE ? SUPERCONTENTS_CORPSE : SUPERCONTENTS_BODY;
// might interact, so do an exact clip
model = NULL;
if ((int) PRVM_serveredictfloat(touch, solid) == SOLID_BSP || type == MOVE_HITMODEL)
{
model = SV_GetModelFromEdict(touch);
pitchsign = SV_GetPitchSign(prog, touch);
}
if (model)
Matrix4x4_CreateFromQuakeEntity(&matrix, PRVM_serveredictvector(touch, origin)[0], PRVM_serveredictvector(touch, origin)[1], PRVM_serveredictvector(touch, origin)[2], pitchsign * PRVM_serveredictvector(touch, angles)[0], PRVM_serveredictvector(touch, angles)[1], PRVM_serveredictvector(touch, angles)[2], 1);
else
Matrix4x4_CreateTranslate(&matrix, PRVM_serveredictvector(touch, origin)[0], PRVM_serveredictvector(touch, origin)[1], PRVM_serveredictvector(touch, origin)[2]);
Matrix4x4_Invert_Simple(&imatrix, &matrix);
VM_GenerateFrameGroupBlend(prog, touch->priv.server->framegroupblend, touch);
VM_FrameBlendFromFrameGroupBlend(touch->priv.server->frameblend, touch->priv.server->framegroupblend, model, sv.time);
VM_UpdateEdictSkeleton(prog, touch, model, touch->priv.server->frameblend);
VectorCopy(PRVM_serveredictvector(touch, mins), touchmins);
VectorCopy(PRVM_serveredictvector(touch, maxs), touchmaxs);
if (type == MOVE_MISSILE && (int)PRVM_serveredictfloat(touch, flags) & FL_MONSTER)
Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipstart, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, 0.0f);
else
Collision_ClipPointToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask);
Collision_CombineTraces(&cliptrace, &trace, (void *)touch, PRVM_serveredictfloat(touch, solid) == SOLID_BSP);
}
finished:
return cliptrace;
}
/*
==================
SV_TraceLine
==================
*/
trace_t SV_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, float extend)
{
prvm_prog_t *prog = SVVM_prog;
int i, bodysupercontents;
int passedictprog;
float pitchsign = 1;
prvm_edict_t *traceowner, *touch;
trace_t trace;
// temporary storage because prvm_vec_t may differ from vec_t
vec3_t touchmins, touchmaxs;
// bounding box of entire move area
vec3_t clipboxmins, clipboxmaxs;
// size when clipping against monsters
vec3_t clipmins2, clipmaxs2;
// start and end origin of move
vec3_t clipstart, clipend;
// trace results
trace_t cliptrace;
// matrices to transform into/out of other entity's space
matrix4x4_t matrix, imatrix;
// model of other entity
model_t *model;
// list of entities to test for collisions
int numtouchedicts;
static prvm_edict_t *touchedicts[MAX_EDICTS];
int clipgroup;
if (VectorCompare(start, end))
return SV_TracePoint(start, type, passedict, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask);
//return SV_TraceBox(start, vec3_origin, vec3_origin, end, type, passedict, hitsupercontentsmask);
VectorCopy(start, clipstart);
VectorCopy(end, clipend);
VectorClear(clipmins2);
VectorClear(clipmaxs2);
#if COLLISIONPARANOID >= 3
Con_Printf("move(%f %f %f,%f %f %f)", clipstart[0], clipstart[1], clipstart[2], clipend[0], clipend[1], clipend[2]);
#endif
// clip to world
Collision_ClipLineToWorld(&cliptrace, sv.worldmodel, clipstart, clipend, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend, false);
cliptrace.worldstartsolid = cliptrace.bmodelstartsolid = cliptrace.startsolid;
if (cliptrace.startsolid || cliptrace.fraction < 1)
cliptrace.ent = prog->edicts;
if (type == MOVE_WORLDONLY)
goto finished;
if (type == MOVE_MISSILE)
{
// LadyHavoc: modified this, was = -15, now -= 15
for (i = 0;i < 3;i++)
{
clipmins2[i] -= 15;
clipmaxs2[i] += 15;
}
}
// create the bounding box of the entire move
for (i = 0;i < 3;i++)
{
clipboxmins[i] = min(clipstart[i], cliptrace.endpos[i]) + clipmins2[i] - 1;
clipboxmaxs[i] = max(clipstart[i], cliptrace.endpos[i]) + clipmaxs2[i] + 1;
}
// debug override to test against everything
if (sv_debugmove.integer)
{
clipboxmins[0] = clipboxmins[1] = clipboxmins[2] = (vec_t)-999999999;
clipboxmaxs[0] = clipboxmaxs[1] = clipboxmaxs[2] = (vec_t)999999999;
}
// if the passedict is world, make it NULL (to avoid two checks each time)
if (passedict == prog->edicts)
passedict = NULL;
// precalculate prog value for passedict for comparisons
passedictprog = PRVM_EDICT_TO_PROG(passedict);
// precalculate passedict's owner edict pointer for comparisons
traceowner = passedict ? PRVM_PROG_TO_EDICT(PRVM_serveredictedict(passedict, owner)) : 0;
clipgroup = passedict ? (int)PRVM_serveredictfloat(passedict, clipgroup) : 0;
// clip to entities
// because this uses World_EntitiestoBox, we know all entity boxes overlap
// the clip region, so we can skip culling checks in the loop below
numtouchedicts = SV_EntitiesInBox(clipboxmins, clipboxmaxs, MAX_EDICTS, touchedicts);
if (numtouchedicts > MAX_EDICTS)
{
// this never happens
Con_Printf("SV_EntitiesInBox returned %i edicts, max was %i\n", numtouchedicts, MAX_EDICTS);
numtouchedicts = MAX_EDICTS;
}
for (i = 0;i < numtouchedicts;i++)
{
touch = touchedicts[i];
if (PRVM_serveredictfloat(touch, solid) < SOLID_BBOX)
continue;
if (type == MOVE_NOMONSTERS && PRVM_serveredictfloat(touch, solid) != SOLID_BSP)
continue;
if (passedict)
{
// don't clip against self
if (passedict == touch)
continue;
// don't clip owned entities against owner
if (traceowner == touch)
continue;
// don't clip owner against owned entities
if (passedictprog == PRVM_serveredictedict(touch, owner))
continue;
// don't clip against any entities in the same clipgroup (DP_RM_CLIPGROUP)
if (clipgroup && clipgroup == (int)PRVM_serveredictfloat(touch, clipgroup))
continue;
// don't clip points against points (they can't collide)
if (VectorCompare(PRVM_serveredictvector(touch, mins), PRVM_serveredictvector(touch, maxs)) && (type != MOVE_MISSILE || !((int)PRVM_serveredictfloat(touch, flags) & FL_MONSTER)))
continue;
}
bodysupercontents = PRVM_serveredictfloat(touch, solid) == SOLID_CORPSE ? SUPERCONTENTS_CORPSE : SUPERCONTENTS_BODY;
// might interact, so do an exact clip
model = NULL;
if ((int) PRVM_serveredictfloat(touch, solid) == SOLID_BSP || type == MOVE_HITMODEL)
{
model = SV_GetModelFromEdict(touch);
pitchsign = SV_GetPitchSign(prog, touch);
}
if (model)
Matrix4x4_CreateFromQuakeEntity(&matrix, PRVM_serveredictvector(touch, origin)[0], PRVM_serveredictvector(touch, origin)[1], PRVM_serveredictvector(touch, origin)[2], pitchsign * PRVM_serveredictvector(touch, angles)[0], PRVM_serveredictvector(touch, angles)[1], PRVM_serveredictvector(touch, angles)[2], 1);
else
Matrix4x4_CreateTranslate(&matrix, PRVM_serveredictvector(touch, origin)[0], PRVM_serveredictvector(touch, origin)[1], PRVM_serveredictvector(touch, origin)[2]);
Matrix4x4_Invert_Simple(&imatrix, &matrix);
VM_GenerateFrameGroupBlend(prog, touch->priv.server->framegroupblend, touch);
VM_FrameBlendFromFrameGroupBlend(touch->priv.server->frameblend, touch->priv.server->framegroupblend, model, sv.time);
VM_UpdateEdictSkeleton(prog, touch, model, touch->priv.server->frameblend);
VectorCopy(PRVM_serveredictvector(touch, mins), touchmins);
VectorCopy(PRVM_serveredictvector(touch, maxs), touchmaxs);
if (type == MOVE_MISSILE && (int)PRVM_serveredictfloat(touch, flags) & FL_MONSTER)
Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipend, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend);
else
Collision_ClipLineToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipend, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend, false);
Collision_CombineTraces(&cliptrace, &trace, (void *)touch, PRVM_serveredictfloat(touch, solid) == SOLID_BSP);
}
finished:
return cliptrace;
}
/*
==================
SV_Move
==================
*/
#if COLLISIONPARANOID >= 1
static trace_t SV_TraceBox_(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, float extend)
#else
trace_t SV_TraceBox(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, float extend)
#endif
{
prvm_prog_t *prog = SVVM_prog;
vec3_t hullmins, hullmaxs;
int i, bodysupercontents;
int passedictprog;
float pitchsign = 1;
qbool pointtrace;
prvm_edict_t *traceowner, *touch;
trace_t trace;
// temporary storage because prvm_vec_t may differ from vec_t
vec3_t touchmins, touchmaxs;
// bounding box of entire move area
vec3_t clipboxmins, clipboxmaxs;
// size of the moving object
vec3_t clipmins, clipmaxs;
// size when clipping against monsters
vec3_t clipmins2, clipmaxs2;
// start and end origin of move
vec3_t clipstart, clipend;
// trace results
trace_t cliptrace;
// matrices to transform into/out of other entity's space
matrix4x4_t matrix, imatrix;
// model of other entity
model_t *model;
// list of entities to test for collisions
int numtouchedicts;
static prvm_edict_t *touchedicts[MAX_EDICTS];
int clipgroup;
if (VectorCompare(mins, maxs))
{
vec3_t shiftstart, shiftend;
VectorAdd(start, mins, shiftstart);
VectorAdd(end, mins, shiftend);
if (VectorCompare(start, end))
trace = SV_TracePoint(shiftstart, type, passedict, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask);
else
trace = SV_TraceLine(shiftstart, shiftend, type, passedict, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend);
VectorSubtract(trace.endpos, mins, trace.endpos);
return trace;
}
VectorCopy(start, clipstart);
VectorCopy(end, clipend);
VectorCopy(mins, clipmins);
VectorCopy(maxs, clipmaxs);
VectorCopy(mins, clipmins2);
VectorCopy(maxs, clipmaxs2);
#if COLLISIONPARANOID >= 3
Con_Printf("move(%f %f %f,%f %f %f)", clipstart[0], clipstart[1], clipstart[2], clipend[0], clipend[1], clipend[2]);
#endif
// clip to world
Collision_ClipToWorld(&cliptrace, sv.worldmodel, clipstart, clipmins, clipmaxs, clipend, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend);
cliptrace.worldstartsolid = cliptrace.bmodelstartsolid = cliptrace.startsolid;
if (cliptrace.startsolid || cliptrace.fraction < 1)
cliptrace.ent = prog->edicts;
if (type == MOVE_WORLDONLY)
goto finished;
if (type == MOVE_MISSILE)
{
// LadyHavoc: modified this, was = -15, now -= 15
for (i = 0;i < 3;i++)
{
clipmins2[i] -= 15;
clipmaxs2[i] += 15;
}
}
// get adjusted box for bmodel collisions if the world is q1bsp or hlbsp
if (sv.worldmodel && sv.worldmodel->brush.RoundUpToHullSize)
sv.worldmodel->brush.RoundUpToHullSize(sv.worldmodel, clipmins, clipmaxs, hullmins, hullmaxs);
else
{
VectorCopy(clipmins, hullmins);
VectorCopy(clipmaxs, hullmaxs);
}
// create the bounding box of the entire move
for (i = 0;i < 3;i++)
{
clipboxmins[i] = min(clipstart[i], cliptrace.endpos[i]) + min(hullmins[i], clipmins2[i]) - 1;
clipboxmaxs[i] = max(clipstart[i], cliptrace.endpos[i]) + max(hullmaxs[i], clipmaxs2[i]) + 1;
}
// debug override to test against everything
if (sv_debugmove.integer)
{
clipboxmins[0] = clipboxmins[1] = clipboxmins[2] = (vec_t)-999999999;
clipboxmaxs[0] = clipboxmaxs[1] = clipboxmaxs[2] = (vec_t)999999999;
}
// if the passedict is world, make it NULL (to avoid two checks each time)
if (passedict == prog->edicts)
passedict = NULL;
// precalculate prog value for passedict for comparisons
passedictprog = PRVM_EDICT_TO_PROG(passedict);
// figure out whether this is a point trace for comparisons
pointtrace = VectorCompare(clipmins, clipmaxs);
// precalculate passedict's owner edict pointer for comparisons
traceowner = passedict ? PRVM_PROG_TO_EDICT(PRVM_serveredictedict(passedict, owner)) : 0;
clipgroup = passedict ? (int)PRVM_serveredictfloat(passedict, clipgroup) : 0;
// clip to entities
// because this uses World_EntitiestoBox, we know all entity boxes overlap
// the clip region, so we can skip culling checks in the loop below
numtouchedicts = SV_EntitiesInBox(clipboxmins, clipboxmaxs, MAX_EDICTS, touchedicts);
if (numtouchedicts > MAX_EDICTS)
{
// this never happens
Con_Printf("SV_EntitiesInBox returned %i edicts, max was %i\n", numtouchedicts, MAX_EDICTS);
numtouchedicts = MAX_EDICTS;
}
for (i = 0;i < numtouchedicts;i++)
{
touch = touchedicts[i];
if (PRVM_serveredictfloat(touch, solid) < SOLID_BBOX)
continue;
if (type == MOVE_NOMONSTERS && PRVM_serveredictfloat(touch, solid) != SOLID_BSP)
continue;
if (passedict)
{
// don't clip against self
if (passedict == touch)
continue;
// don't clip owned entities against owner
if (traceowner == touch)
continue;
// don't clip owner against owned entities
if (passedictprog == PRVM_serveredictedict(touch, owner))
continue;
// don't clip against any entities in the same clipgroup (DP_RM_CLIPGROUP)
if (clipgroup && clipgroup == (int)PRVM_serveredictfloat(touch, clipgroup))
continue;
// don't clip points against points (they can't collide)
if (pointtrace && VectorCompare(PRVM_serveredictvector(touch, mins), PRVM_serveredictvector(touch, maxs)) && (type != MOVE_MISSILE || !((int)PRVM_serveredictfloat(touch, flags) & FL_MONSTER)))
continue;
}
bodysupercontents = PRVM_serveredictfloat(touch, solid) == SOLID_CORPSE ? SUPERCONTENTS_CORPSE : SUPERCONTENTS_BODY;
// might interact, so do an exact clip
model = NULL;
if ((int) PRVM_serveredictfloat(touch, solid) == SOLID_BSP || type == MOVE_HITMODEL)
{
model = SV_GetModelFromEdict(touch);
pitchsign = SV_GetPitchSign(prog, touch);
}
if (model)
Matrix4x4_CreateFromQuakeEntity(&matrix, PRVM_serveredictvector(touch, origin)[0], PRVM_serveredictvector(touch, origin)[1], PRVM_serveredictvector(touch, origin)[2], pitchsign * PRVM_serveredictvector(touch, angles)[0], PRVM_serveredictvector(touch, angles)[1], PRVM_serveredictvector(touch, angles)[2], 1);
else
Matrix4x4_CreateTranslate(&matrix, PRVM_serveredictvector(touch, origin)[0], PRVM_serveredictvector(touch, origin)[1], PRVM_serveredictvector(touch, origin)[2]);
Matrix4x4_Invert_Simple(&imatrix, &matrix);
VM_GenerateFrameGroupBlend(prog, touch->priv.server->framegroupblend, touch);
VM_FrameBlendFromFrameGroupBlend(touch->priv.server->frameblend, touch->priv.server->framegroupblend, model, sv.time);
VM_UpdateEdictSkeleton(prog, touch, model, touch->priv.server->frameblend);
VectorCopy(PRVM_serveredictvector(touch, mins), touchmins);
VectorCopy(PRVM_serveredictvector(touch, maxs), touchmaxs);
if (type == MOVE_MISSILE && (int)PRVM_serveredictfloat(touch, flags) & FL_MONSTER)
Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipend, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend);
else
Collision_ClipToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins, clipmaxs, clipend, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend);
Collision_CombineTraces(&cliptrace, &trace, (void *)touch, PRVM_serveredictfloat(touch, solid) == SOLID_BSP);
}
finished:
return cliptrace;
}
#if COLLISIONPARANOID >= 1
trace_t SV_TraceBox(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, float extend)
{
prvm_prog_t *prog = SVVM_prog;
int endstuck;
trace_t trace;
vec3_t temp;
trace = SV_TraceBox_(start, mins, maxs, end, type, passedict, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend);
if (passedict)
{
VectorCopy(trace.endpos, temp);
endstuck = SV_TraceBox_(temp, mins, maxs, temp, type, passedict, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend).startsolid;
#if COLLISIONPARANOID < 3
if (trace.startsolid || endstuck)
#endif
Con_Printf("%s{e%i:%f %f %f:%f %f %f:%f:%f %f %f%s%s}\n", (trace.startsolid || endstuck) ? "^3" : "", passedict ? (int)(passedict - prog->edicts) : -1, PRVM_serveredictvector(passedict, origin)[0], PRVM_serveredictvector(passedict, origin)[1], PRVM_serveredictvector(passedict, origin)[2], end[0] - PRVM_serveredictvector(passedict, origin)[0], end[1] - PRVM_serveredictvector(passedict, origin)[1], end[2] - PRVM_serveredictvector(passedict, origin)[2], trace.fraction, trace.endpos[0] - PRVM_serveredictvector(passedict, origin)[0], trace.endpos[1] - PRVM_serveredictvector(passedict, origin)[1], trace.endpos[2] - PRVM_serveredictvector(passedict, origin)[2], trace.startsolid ? " startstuck" : "", endstuck ? " endstuck" : "");
}
return trace;
}
#endif
int SV_PointSuperContents(const vec3_t point)
{
prvm_prog_t *prog = SVVM_prog;
int supercontents = 0;
int i;
prvm_edict_t *touch;
vec3_t transformed;
// matrices to transform into/out of other entity's space
matrix4x4_t matrix, imatrix;
// model of other entity
model_t *model;
int frame;
// list of entities to test for collisions
int numtouchedicts;
static prvm_edict_t *touchedicts[MAX_EDICTS];
// get world supercontents at this point
if (sv.worldmodel && sv.worldmodel->PointSuperContents)
supercontents = sv.worldmodel->PointSuperContents(sv.worldmodel, 0, point);
// if sv_gameplayfix_swiminbmodels is off we're done
if (!sv_gameplayfix_swiminbmodels.integer)
return supercontents;
// get list of entities at this point
numtouchedicts = SV_EntitiesInBox(point, point, MAX_EDICTS, touchedicts);
if (numtouchedicts > MAX_EDICTS)
{
// this never happens
Con_Printf("SV_EntitiesInBox returned %i edicts, max was %i\n", numtouchedicts, MAX_EDICTS);
numtouchedicts = MAX_EDICTS;
}
for (i = 0;i < numtouchedicts;i++)
{
touch = touchedicts[i];
// we only care about SOLID_BSP for pointcontents
if (PRVM_serveredictfloat(touch, solid) != SOLID_BSP)
continue;
// might interact, so do an exact clip
model = SV_GetModelFromEdict(touch);
if (!model || !model->PointSuperContents)
continue;
Matrix4x4_CreateFromQuakeEntity(&matrix, PRVM_serveredictvector(touch, origin)[0], PRVM_serveredictvector(touch, origin)[1], PRVM_serveredictvector(touch, origin)[2], PRVM_serveredictvector(touch, angles)[0], PRVM_serveredictvector(touch, angles)[1], PRVM_serveredictvector(touch, angles)[2], 1);
Matrix4x4_Invert_Simple(&imatrix, &matrix);
Matrix4x4_Transform(&imatrix, point, transformed);
frame = (int)PRVM_serveredictfloat(touch, frame);
supercontents |= model->PointSuperContents(model, bound(0, frame, (model->numframes - 1)), transformed);
}
return supercontents;
}
/*
===============================================================================
Linking entities into the world culling system
===============================================================================
*/
int SV_EntitiesInBox(const vec3_t mins, const vec3_t maxs, int maxedicts, prvm_edict_t **resultedicts)
{
prvm_prog_t *prog = SVVM_prog;
vec3_t paddedmins, paddedmaxs;
if (maxedicts < 1 || resultedicts == NULL)
return 0;
// LadyHavoc: discovered this actually causes its own bugs (dm6 teleporters being too close to info_teleport_destination)
//VectorSet(paddedmins, mins[0] - 10, mins[1] - 10, mins[2] - 1);
//VectorSet(paddedmaxs, maxs[0] + 10, maxs[1] + 10, maxs[2] + 1);
VectorCopy(mins, paddedmins);
VectorCopy(maxs, paddedmaxs);
if (sv_areadebug.integer)
{
int numresultedicts = 0;
int edictindex;
prvm_edict_t *ed;
for (edictindex = 1;edictindex < prog->num_edicts;edictindex++)
{
ed = PRVM_EDICT_NUM(edictindex);
if (!ed->free && BoxesOverlap(PRVM_serveredictvector(ed, absmin), PRVM_serveredictvector(ed, absmax), paddedmins, paddedmaxs))
{
resultedicts[numresultedicts++] = ed;
if (numresultedicts == maxedicts)
break;
}
}
return numresultedicts;
}
else
return World_EntitiesInBox(&sv.world, paddedmins, paddedmaxs, maxedicts, resultedicts);
}
void SV_LinkEdict_TouchAreaGrid_Call(prvm_edict_t *touch, prvm_edict_t *ent)
{
prvm_prog_t *prog = SVVM_prog;
PRVM_serverglobaledict(self) = PRVM_EDICT_TO_PROG(touch);
PRVM_serverglobaledict(other) = PRVM_EDICT_TO_PROG(ent);
PRVM_serverglobalfloat(time) = sv.time;
PRVM_serverglobalfloat(trace_allsolid) = false;
PRVM_serverglobalfloat(trace_startsolid) = false;
PRVM_serverglobalfloat(trace_fraction) = 1;
PRVM_serverglobalfloat(trace_inwater) = false;
PRVM_serverglobalfloat(trace_inopen) = true;
VectorCopy (PRVM_serveredictvector(touch, origin), PRVM_serverglobalvector(trace_endpos));
VectorSet (PRVM_serverglobalvector(trace_plane_normal), 0, 0, 1);
PRVM_serverglobalfloat(trace_plane_dist) = 0;
PRVM_serverglobaledict(trace_ent) = PRVM_EDICT_TO_PROG(ent);
PRVM_serverglobalfloat(trace_dpstartcontents) = 0;
PRVM_serverglobalfloat(trace_dphitcontents) = 0;
PRVM_serverglobalfloat(trace_dphitq3surfaceflags) = 0;
PRVM_serverglobalstring(trace_dphittexturename) = 0;
prog->ExecuteProgram(prog, PRVM_serveredictfunction(touch, touch), "QC function self.touch is missing");
}
void SV_LinkEdict_TouchAreaGrid(prvm_edict_t *ent)
{
prvm_prog_t *prog = SVVM_prog;
int i, numtouchedicts, old_self, old_other;
prvm_edict_t *touch;
static prvm_edict_t *touchedicts[MAX_EDICTS];
if (ent == prog->edicts)
return; // don't add the world
if (ent->free)
return;
if (PRVM_serveredictfloat(ent, solid) == SOLID_NOT)
return;
// build a list of edicts to touch, because the link loop can be corrupted
// by IncreaseEdicts called during touch functions
numtouchedicts = SV_EntitiesInBox(ent->priv.server->areamins, ent->priv.server->areamaxs, MAX_EDICTS, touchedicts);
if (numtouchedicts > MAX_EDICTS)
{
// this never happens
Con_Printf("SV_EntitiesInBox returned %i edicts, max was %i\n", numtouchedicts, MAX_EDICTS);
numtouchedicts = MAX_EDICTS;
}
old_self = PRVM_serverglobaledict(self);
old_other = PRVM_serverglobaledict(other);
for (i = 0;i < numtouchedicts;i++)
{
touch = touchedicts[i];
if (touch != ent && (int)PRVM_serveredictfloat(touch, solid) == SOLID_TRIGGER && PRVM_serveredictfunction(touch, touch))
{
SV_LinkEdict_TouchAreaGrid_Call(touch, ent);
}
}
PRVM_serverglobaledict(self) = old_self;
PRVM_serverglobaledict(other) = old_other;
}
static void RotateBBox(const vec3_t mins, const vec3_t maxs, const vec3_t angles, vec3_t rotatedmins, vec3_t rotatedmaxs)
{
vec3_t v, u;
matrix4x4_t m;
Matrix4x4_CreateFromQuakeEntity(&m, 0, 0, 0, angles[PITCH], angles[YAW], angles[ROLL], 1.0);
v[0] = mins[0]; v[1] = mins[1]; v[2] = mins[2]; Matrix4x4_Transform(&m, v, u);
VectorCopy(u, rotatedmins); VectorCopy(u, rotatedmaxs);
v[0] = maxs[0]; v[1] = mins[1]; v[2] = mins[2]; Matrix4x4_Transform(&m, v, u);
if(rotatedmins[0] > u[0]) { rotatedmins[0] = u[0]; } if(rotatedmins[1] > u[1]) { rotatedmins[1] = u[1]; } if(rotatedmins[2] > u[2]) { rotatedmins[2] = u[2]; }
if(rotatedmaxs[0] < u[0]) { rotatedmaxs[0] = u[0]; } if(rotatedmaxs[1] < u[1]) { rotatedmaxs[1] = u[1]; } if(rotatedmaxs[2] < u[2]) { rotatedmaxs[2] = u[2]; }
v[0] = mins[0]; v[1] = maxs[1]; v[2] = mins[2]; Matrix4x4_Transform(&m, v, u);
if(rotatedmins[0] > u[0]) { rotatedmins[0] = u[0]; } if(rotatedmins[1] > u[1]) { rotatedmins[1] = u[1]; } if(rotatedmins[2] > u[2]) { rotatedmins[2] = u[2]; }
if(rotatedmaxs[0] < u[0]) { rotatedmaxs[0] = u[0]; } if(rotatedmaxs[1] < u[1]) { rotatedmaxs[1] = u[1]; } if(rotatedmaxs[2] < u[2]) { rotatedmaxs[2] = u[2]; }
v[0] = maxs[0]; v[1] = maxs[1]; v[2] = mins[2]; Matrix4x4_Transform(&m, v, u);
if(rotatedmins[0] > u[0]) { rotatedmins[0] = u[0]; } if(rotatedmins[1] > u[1]) { rotatedmins[1] = u[1]; } if(rotatedmins[2] > u[2]) { rotatedmins[2] = u[2]; }
if(rotatedmaxs[0] < u[0]) { rotatedmaxs[0] = u[0]; } if(rotatedmaxs[1] < u[1]) { rotatedmaxs[1] = u[1]; } if(rotatedmaxs[2] < u[2]) { rotatedmaxs[2] = u[2]; }
v[0] = mins[0]; v[1] = mins[1]; v[2] = maxs[2]; Matrix4x4_Transform(&m, v, u);
if(rotatedmins[0] > u[0]) { rotatedmins[0] = u[0]; } if(rotatedmins[1] > u[1]) { rotatedmins[1] = u[1]; } if(rotatedmins[2] > u[2]) { rotatedmins[2] = u[2]; }
if(rotatedmaxs[0] < u[0]) { rotatedmaxs[0] = u[0]; } if(rotatedmaxs[1] < u[1]) { rotatedmaxs[1] = u[1]; } if(rotatedmaxs[2] < u[2]) { rotatedmaxs[2] = u[2]; }
v[0] = maxs[0]; v[1] = mins[1]; v[2] = maxs[2]; Matrix4x4_Transform(&m, v, u);
if(rotatedmins[0] > u[0]) { rotatedmins[0] = u[0]; } if(rotatedmins[1] > u[1]) { rotatedmins[1] = u[1]; } if(rotatedmins[2] > u[2]) { rotatedmins[2] = u[2]; }
if(rotatedmaxs[0] < u[0]) { rotatedmaxs[0] = u[0]; } if(rotatedmaxs[1] < u[1]) { rotatedmaxs[1] = u[1]; } if(rotatedmaxs[2] < u[2]) { rotatedmaxs[2] = u[2]; }
v[0] = mins[0]; v[1] = maxs[1]; v[2] = maxs[2]; Matrix4x4_Transform(&m, v, u);
if(rotatedmins[0] > u[0]) { rotatedmins[0] = u[0]; } if(rotatedmins[1] > u[1]) { rotatedmins[1] = u[1]; } if(rotatedmins[2] > u[2]) { rotatedmins[2] = u[2]; }
if(rotatedmaxs[0] < u[0]) { rotatedmaxs[0] = u[0]; } if(rotatedmaxs[1] < u[1]) { rotatedmaxs[1] = u[1]; } if(rotatedmaxs[2] < u[2]) { rotatedmaxs[2] = u[2]; }
v[0] = maxs[0]; v[1] = maxs[1]; v[2] = maxs[2]; Matrix4x4_Transform(&m, v, u);
if(rotatedmins[0] > u[0]) { rotatedmins[0] = u[0]; } if(rotatedmins[1] > u[1]) { rotatedmins[1] = u[1]; } if(rotatedmins[2] > u[2]) { rotatedmins[2] = u[2]; }
if(rotatedmaxs[0] < u[0]) { rotatedmaxs[0] = u[0]; } if(rotatedmaxs[1] < u[1]) { rotatedmaxs[1] = u[1]; } if(rotatedmaxs[2] < u[2]) { rotatedmaxs[2] = u[2]; }
}
/*
===============
SV_LinkEdict
===============
*/
void SV_LinkEdict (prvm_edict_t *ent)
{
prvm_prog_t *prog = SVVM_prog;
model_t *model;
vec3_t mins, maxs, entmins, entmaxs, entangles;
int modelindex;
if (ent == prog->edicts)
return; // don't add the world
if (ent->free)
return;
modelindex = (int)PRVM_serveredictfloat(ent, modelindex);
if (modelindex < 0 || modelindex >= MAX_MODELS)
{
Con_Printf("edict %i: SOLID_BSP with invalid modelindex!\n", PRVM_NUM_FOR_EDICT(ent));
modelindex = 0;
}
model = SV_GetModelByIndex(modelindex);
VM_GenerateFrameGroupBlend(prog, ent->priv.server->framegroupblend, ent);
VM_FrameBlendFromFrameGroupBlend(ent->priv.server->frameblend, ent->priv.server->framegroupblend, model, sv.time);
VM_UpdateEdictSkeleton(prog, ent, model, ent->priv.server->frameblend);
// set the abs box
if (PRVM_serveredictfloat(ent, movetype) == MOVETYPE_PHYSICS)
{
// TODO maybe should do this for rotating SOLID_BSP too? Would behave better with rotating doors
// TODO special handling for spheres?
VectorCopy(PRVM_serveredictvector(ent, mins), entmins);
VectorCopy(PRVM_serveredictvector(ent, maxs), entmaxs);
VectorCopy(PRVM_serveredictvector(ent, angles), entangles);
RotateBBox(entmins, entmaxs, entangles, mins, maxs);
VectorAdd(PRVM_serveredictvector(ent, origin), mins, mins);
VectorAdd(PRVM_serveredictvector(ent, origin), maxs, maxs);
}
else if (PRVM_serveredictfloat(ent, solid) == SOLID_BSP)
{
if (model != NULL)
{
if (!model->TraceBox)
Con_DPrintf("edict %i: SOLID_BSP with non-collidable model\n", PRVM_NUM_FOR_EDICT(ent));
if (PRVM_serveredictvector(ent, angles)[0] || PRVM_serveredictvector(ent, angles)[2] || PRVM_serveredictvector(ent, avelocity)[0] || PRVM_serveredictvector(ent, avelocity)[2])
{
VectorAdd(PRVM_serveredictvector(ent, origin), model->rotatedmins, mins);
VectorAdd(PRVM_serveredictvector(ent, origin), model->rotatedmaxs, maxs);
}
else if (PRVM_serveredictvector(ent, angles)[1] || PRVM_serveredictvector(ent, avelocity)[1])
{
VectorAdd(PRVM_serveredictvector(ent, origin), model->yawmins, mins);
VectorAdd(PRVM_serveredictvector(ent, origin), model->yawmaxs, maxs);
}
else
{
VectorAdd(PRVM_serveredictvector(ent, origin), model->normalmins, mins);
VectorAdd(PRVM_serveredictvector(ent, origin), model->normalmaxs, maxs);
}
}
else
{
// SOLID_BSP with no model is valid, mainly because some QC setup code does so temporarily
VectorAdd(PRVM_serveredictvector(ent, origin), PRVM_serveredictvector(ent, mins), mins);
VectorAdd(PRVM_serveredictvector(ent, origin), PRVM_serveredictvector(ent, maxs), maxs);
}
}
else
{
VectorAdd(PRVM_serveredictvector(ent, origin), PRVM_serveredictvector(ent, mins), mins);
VectorAdd(PRVM_serveredictvector(ent, origin), PRVM_serveredictvector(ent, maxs), maxs);
}
if (sv_legacy_bbox_expand.integer)
{
if ((int)PRVM_serveredictfloat(ent, flags) & FL_ITEM)
{
// to make items easier to pick up and allow them to be grabbed off
// of shelves, the abs sizes are expanded
mins[0] -= 15;
mins[1] -= 15;
mins[2] -= 1;
maxs[0] += 15;
maxs[1] += 15;
maxs[2] += 1;
}
else
{
// because movement is clipped an epsilon away from an actual edge,
// we must fully check even when bounding boxes don't quite touch
mins[0] -= 1;
mins[1] -= 1;
mins[2] -= 1;
maxs[0] += 1;
maxs[1] += 1;
maxs[2] += 1;
}
}
VectorCopy(mins, PRVM_serveredictvector(ent, absmin));
VectorCopy(maxs, PRVM_serveredictvector(ent, absmax));
World_LinkEdict(&sv.world, ent, mins, maxs, sv_areagrid_link_SOLID_NOT.integer);
}
/*
===============================================================================
Utility functions
===============================================================================
*/
// DRESK - Support for Entity Contents Transition Event
/*
================
SV_CheckContentsTransition
returns true if entity had a valid contentstransition function call
================
*/
static int SV_CheckContentsTransition(prvm_edict_t *ent, const int nContents)
{
prvm_prog_t *prog = SVVM_prog;
int bValidFunctionCall;
// Default Valid Function Call to False
bValidFunctionCall = false;
if(PRVM_serveredictfloat(ent, watertype) != nContents)
{ // Changed Contents
// Acquire Contents Transition Function from QC
if(PRVM_serveredictfunction(ent, contentstransition))
{ // Valid Function; Execute
// Assign Valid Function
bValidFunctionCall = true;
// Prepare Parameters (Original Contents, New Contents)
// Original Contents
PRVM_G_FLOAT(OFS_PARM0) = PRVM_serveredictfloat(ent, watertype);
// New Contents
PRVM_G_FLOAT(OFS_PARM1) = nContents;
// Assign Self
PRVM_serverglobaledict(self) = PRVM_EDICT_TO_PROG(ent);
// Set Time
PRVM_serverglobalfloat(time) = sv.time;
// Execute VM Function
prog->ExecuteProgram(prog, PRVM_serveredictfunction(ent, contentstransition), "contentstransition: NULL function");
}
}
// Return if Function Call was Valid
return bValidFunctionCall;
}
/*
================
SV_CheckVelocity
================
*/
void SV_CheckVelocity (prvm_edict_t *ent)
{
prvm_prog_t *prog = SVVM_prog;
int i;
float wishspeed;
//
// bound velocity
//
for (i=0 ; i<3 ; i++)
{
if (isnan(PRVM_serveredictvector(ent, velocity)[i]))
{
Con_Printf("Got a NaN velocity on entity #%i (%s)\n", PRVM_NUM_FOR_EDICT(ent), PRVM_GetString(prog, PRVM_serveredictstring(ent, classname)));
PRVM_serveredictvector(ent, velocity)[i] = 0;
}
if (isnan(PRVM_serveredictvector(ent, origin)[i]))
{
Con_Printf("Got a NaN origin on entity #%i (%s)\n", PRVM_NUM_FOR_EDICT(ent), PRVM_GetString(prog, PRVM_serveredictstring(ent, classname)));
PRVM_serveredictvector(ent, origin)[i] = 0;
}
}
// LadyHavoc: a hack to ensure that the (rather silly) id1 quakec
// player_run/player_stand1 does not horribly malfunction if the
// velocity becomes a denormalized float
if (VectorLength2(PRVM_serveredictvector(ent, velocity)) < 0.0000001)
VectorClear(PRVM_serveredictvector(ent, velocity));
// LadyHavoc: max velocity fix, inspired by Maddes's source fixes, but this is faster
wishspeed = DotProduct(PRVM_serveredictvector(ent, velocity), PRVM_serveredictvector(ent, velocity));
if (wishspeed > sv_maxvelocity.value * sv_maxvelocity.value)
{
wishspeed = sv_maxvelocity.value / sqrt(wishspeed);
PRVM_serveredictvector(ent, velocity)[0] *= wishspeed;
PRVM_serveredictvector(ent, velocity)[1] *= wishspeed;