]> git.xonotic.org Git - xonotic/darkplaces.git/blob - cl_collision.c
Rename indent/dedent functions
[xonotic/darkplaces.git] / cl_collision.c
1
2 #include "quakedef.h"
3 #include "cl_collision.h"
4
5 float CL_SelectTraceLine(const vec3_t start, const vec3_t end, vec3_t impact, vec3_t normal, int *hitent, entity_render_t *ignoreent)
6 {
7         float maxfrac;
8         int n;
9         entity_render_t *ent;
10         vec_t tracemins[3], tracemaxs[3];
11         trace_t trace;
12         vec_t tempnormal[3], starttransformed[3], endtransformed[3];
13
14         memset (&trace, 0 , sizeof(trace_t));
15         trace.fraction = 1;
16         VectorCopy (end, trace.endpos);
17
18         if (hitent)
19                 *hitent = 0;
20         if (cl.worldmodel && cl.worldmodel->TraceLine)
21                 cl.worldmodel->TraceLine(cl.worldmodel, NULL, NULL, &trace, start, end, SUPERCONTENTS_SOLID, 0, 0);
22
23         if (normal)
24                 VectorCopy(trace.plane.normal, normal);
25         maxfrac = trace.fraction;
26
27         tracemins[0] = min(start[0], end[0]);
28         tracemaxs[0] = max(start[0], end[0]);
29         tracemins[1] = min(start[1], end[1]);
30         tracemaxs[1] = max(start[1], end[1]);
31         tracemins[2] = min(start[2], end[2]);
32         tracemaxs[2] = max(start[2], end[2]);
33
34         // look for embedded bmodels
35         for (n = 0;n < cl.num_entities;n++)
36         {
37                 if (!cl.entities_active[n])
38                         continue;
39                 ent = &cl.entities[n].render;
40                 if (!BoxesOverlap(ent->mins, ent->maxs, tracemins, tracemaxs))
41                         continue;
42                 if (!ent->model || !ent->model->TraceLine)
43                         continue;
44                 if ((ent->flags & RENDER_EXTERIORMODEL) && !chase_active.integer)
45                         continue;
46                 // if transparent and not selectable, skip entity
47                 if (!(cl.entities[n].state_current.effects & EF_SELECTABLE) && (ent->alpha < 1 || (ent->effects & (EF_ADDITIVE | EF_NODEPTHTEST))))
48                         continue;
49                 if (ent == ignoreent)
50                         continue;
51                 Matrix4x4_Transform(&ent->inversematrix, start, starttransformed);
52                 Matrix4x4_Transform(&ent->inversematrix, end, endtransformed);
53                 Collision_ClipTrace_Box(&trace, ent->model->normalmins, ent->model->normalmaxs, starttransformed, vec3_origin, vec3_origin, endtransformed, SUPERCONTENTS_SOLID, 0, 0, SUPERCONTENTS_SOLID, 0, NULL);
54                 if (maxfrac < trace.fraction)
55                         continue;
56
57                 ent->model->TraceLine(ent->model, ent->frameblend, ent->skeleton, &trace, starttransformed, endtransformed, SUPERCONTENTS_SOLID, 0, 0);
58
59                 if (maxfrac > trace.fraction)
60                 {
61                         if (hitent)
62                                 *hitent = n;
63                         maxfrac = trace.fraction;
64                         if (normal)
65                         {
66                                 VectorCopy(trace.plane.normal, tempnormal);
67                                 Matrix4x4_Transform3x3(&ent->matrix, tempnormal, normal);
68                         }
69                 }
70         }
71         maxfrac = bound(0, maxfrac, 1);
72         //maxrealfrac = bound(0, maxrealfrac, 1);
73         //if (maxfrac < 0 || maxfrac > 1) Con_Printf("fraction out of bounds %f %s:%d\n", maxfrac, __FILE__, __LINE__);
74         if (impact)
75                 VectorLerp(start, maxfrac, end, impact);
76         return maxfrac;
77 }
78
79 void CL_FindNonSolidLocation(const vec3_t in, vec3_t out, vec_t radius)
80 {
81         // FIXME: check multiple brush models
82         if (cl.worldmodel && cl.worldmodel->brush.FindNonSolidLocation)
83                 cl.worldmodel->brush.FindNonSolidLocation(cl.worldmodel, in, out, radius);
84 }
85
86 model_t *CL_GetModelByIndex(int modelindex)
87 {
88         if(!modelindex)
89                 return NULL;
90         if (modelindex < 0)
91         {
92                 modelindex = -(modelindex+1);
93                 if (modelindex < MAX_MODELS)
94                         return cl.csqc_model_precache[modelindex];
95         }
96         else
97         {
98                 if(modelindex < MAX_MODELS)
99                         return cl.model_precache[modelindex];
100         }
101         return NULL;
102 }
103
104 model_t *CL_GetModelFromEdict(prvm_edict_t *ed)
105 {
106         prvm_prog_t *prog = CLVM_prog;
107         if (!ed || ed->priv.server->free)
108                 return NULL;
109         return CL_GetModelByIndex((int)PRVM_clientedictfloat(ed, modelindex));
110 }
111
112 void CL_LinkEdict(prvm_edict_t *ent)
113 {
114         prvm_prog_t *prog = CLVM_prog;
115         vec3_t mins, maxs;
116
117         if (ent == prog->edicts)
118                 return;         // don't add the world
119
120         if (ent->priv.server->free)
121                 return;
122
123         // set the abs box
124
125         if (PRVM_clientedictfloat(ent, solid) == SOLID_BSP)
126         {
127                 model_t *model = CL_GetModelByIndex( (int)PRVM_clientedictfloat(ent, modelindex) );
128                 if (model == NULL)
129                 {
130                         Con_Printf("edict %i: SOLID_BSP with invalid modelindex!\n", PRVM_NUM_FOR_EDICT(ent));
131
132                         model = CL_GetModelByIndex( 0 );
133                 }
134
135                 if( model != NULL )
136                 {
137                         if (!model->TraceBox)
138                                 Con_DPrintf("edict %i: SOLID_BSP with non-collidable model\n", PRVM_NUM_FOR_EDICT(ent));
139
140                         if (PRVM_clientedictvector(ent, angles)[0] || PRVM_clientedictvector(ent, angles)[2] || PRVM_clientedictvector(ent, avelocity)[0] || PRVM_clientedictvector(ent, avelocity)[2])
141                         {
142                                 VectorAdd(PRVM_clientedictvector(ent, origin), model->rotatedmins, mins);
143                                 VectorAdd(PRVM_clientedictvector(ent, origin), model->rotatedmaxs, maxs);
144                         }
145                         else if (PRVM_clientedictvector(ent, angles)[1] || PRVM_clientedictvector(ent, avelocity)[1])
146                         {
147                                 VectorAdd(PRVM_clientedictvector(ent, origin), model->yawmins, mins);
148                                 VectorAdd(PRVM_clientedictvector(ent, origin), model->yawmaxs, maxs);
149                         }
150                         else
151                         {
152                                 VectorAdd(PRVM_clientedictvector(ent, origin), model->normalmins, mins);
153                                 VectorAdd(PRVM_clientedictvector(ent, origin), model->normalmaxs, maxs);
154                         }
155                 }
156                 else
157                 {
158                         // SOLID_BSP with no model is valid, mainly because some QC setup code does so temporarily
159                         VectorAdd(PRVM_clientedictvector(ent, origin), PRVM_clientedictvector(ent, mins), mins);
160                         VectorAdd(PRVM_clientedictvector(ent, origin), PRVM_clientedictvector(ent, maxs), maxs);
161                 }
162         }
163         else
164         {
165                 VectorAdd(PRVM_clientedictvector(ent, origin), PRVM_clientedictvector(ent, mins), mins);
166                 VectorAdd(PRVM_clientedictvector(ent, origin), PRVM_clientedictvector(ent, maxs), maxs);
167         }
168
169         VectorCopy(mins, PRVM_clientedictvector(ent, absmin));
170         VectorCopy(maxs, PRVM_clientedictvector(ent, absmax));
171
172         World_LinkEdict(&cl.world, ent, mins, maxs);
173 }
174
175 int CL_GenericHitSuperContentsMask(const prvm_edict_t *passedict)
176 {
177         prvm_prog_t *prog = CLVM_prog;
178         if (passedict)
179         {
180                 int dphitcontentsmask = (int)PRVM_clientedictfloat(passedict, dphitcontentsmask);
181                 if (dphitcontentsmask)
182                         return dphitcontentsmask;
183                 else if (PRVM_clientedictfloat(passedict, solid) == SOLID_SLIDEBOX)
184                 {
185                         if ((int)PRVM_clientedictfloat(passedict, flags) & FL_MONSTER)
186                                 return SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_MONSTERCLIP;
187                         else
188                                 return SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_PLAYERCLIP;
189                 }
190                 else if (PRVM_clientedictfloat(passedict, solid) == SOLID_CORPSE)
191                         return SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY;
192                 else if (PRVM_clientedictfloat(passedict, solid) == SOLID_TRIGGER)
193                         return SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY;
194                 else
195                         return SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_CORPSE;
196         }
197         else
198                 return SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_CORPSE;
199 }
200
201 /*
202 ==================
203 CL_Move
204 ==================
205 */
206 trace_t CL_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, qbool hitnetworkbrushmodels, qbool hitnetworkplayers, int *hitnetworkentity, qbool hitcsqcentities)
207 {
208         prvm_prog_t *prog = CLVM_prog;
209         int i, bodysupercontents;
210         int passedictprog;
211         prvm_edict_t *traceowner, *touch;
212         trace_t trace;
213         // temporary storage because prvm_vec_t may need conversion
214         vec3_t touchmins, touchmaxs;
215         // bounding box of entire move area
216         vec3_t clipboxmins, clipboxmaxs;
217         // size when clipping against monsters
218         vec3_t clipmins2, clipmaxs2;
219         // start and end origin of move
220         vec3_t clipstart;
221         // trace results
222         trace_t cliptrace;
223         // matrices to transform into/out of other entity's space
224         matrix4x4_t matrix, imatrix;
225         // model of other entity
226         model_t *model;
227         // list of entities to test for collisions
228         int numtouchedicts;
229         static prvm_edict_t *touchedicts[MAX_EDICTS];
230         int clipgroup;
231
232         if (hitnetworkentity)
233                 *hitnetworkentity = 0;
234
235         VectorCopy(start, clipstart);
236         VectorClear(clipmins2);
237         VectorClear(clipmaxs2);
238 #if COLLISIONPARANOID >= 3
239         Con_Printf("move(%f %f %f)", clipstart[0], clipstart[1], clipstart[2]);
240 #endif
241
242         // clip to world
243         Collision_ClipPointToWorld(&cliptrace, cl.worldmodel, clipstart, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask);
244         cliptrace.worldstartsolid = cliptrace.bmodelstartsolid = cliptrace.startsolid;
245         if (cliptrace.startsolid || cliptrace.fraction < 1)
246                 cliptrace.ent = prog ? prog->edicts : NULL;
247         if (type == MOVE_WORLDONLY)
248                 goto finished;
249
250         if (type == MOVE_MISSILE)
251         {
252                 // LadyHavoc: modified this, was = -15, now -= 15
253                 for (i = 0;i < 3;i++)
254                 {
255                         clipmins2[i] -= 15;
256                         clipmaxs2[i] += 15;
257                 }
258         }
259
260         // create the bounding box of the entire move
261         for (i = 0;i < 3;i++)
262         {
263                 clipboxmins[i] = clipstart[i] - 1;
264                 clipboxmaxs[i] = clipstart[i] + 1;
265         }
266
267         // debug override to test against everything
268         if (sv_debugmove.integer)
269         {
270                 clipboxmins[0] = clipboxmins[1] = clipboxmins[2] = (vec_t)-999999999;
271                 clipboxmaxs[0] = clipboxmaxs[1] = clipboxmaxs[2] =  (vec_t)999999999;
272         }
273
274         // if the passedict is world, make it NULL (to avoid two checks each time)
275         // this checks prog because this function is often called without a CSQC
276         // VM context
277         if (prog == NULL || passedict == prog->edicts)
278                 passedict = NULL;
279         // precalculate prog value for passedict for comparisons
280         passedictprog = prog != NULL ? PRVM_EDICT_TO_PROG(passedict) : 0;
281         // precalculate passedict's owner edict pointer for comparisons
282         traceowner = passedict ? PRVM_PROG_TO_EDICT(PRVM_clientedictedict(passedict, owner)) : NULL;
283
284         clipgroup = passedict ? (int)PRVM_clientedictfloat(passedict, clipgroup) : 0;
285
286         // collide against network entities
287         if (hitnetworkbrushmodels)
288         {
289                 for (i = 0;i < cl.num_brushmodel_entities;i++)
290                 {
291                         entity_render_t *ent = &cl.entities[cl.brushmodel_entities[i]].render;
292                         if (!BoxesOverlap(clipboxmins, clipboxmaxs, ent->mins, ent->maxs))
293                                 continue;
294                         Collision_ClipPointToGenericEntity(&trace, ent->model, ent->frameblend, ent->skeleton, vec3_origin, vec3_origin, 0, &ent->matrix, &ent->inversematrix, start, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask);
295                         if (cliptrace.fraction > trace.fraction && hitnetworkentity)
296                                 *hitnetworkentity = cl.brushmodel_entities[i];
297                         Collision_CombineTraces(&cliptrace, &trace, NULL, true);
298                 }
299         }
300
301         // collide against player entities
302         if (hitnetworkplayers)
303         {
304                 vec3_t origin, entmins, entmaxs;
305                 matrix4x4_t entmatrix, entinversematrix;
306
307                 if(IS_OLDNEXUIZ_DERIVED(gamemode))
308                 {
309                         // don't hit network players, if we are a nonsolid player
310                         if(cl.scores[cl.playerentity-1].frags == -666 || cl.scores[cl.playerentity-1].frags == -616)
311                                 goto skipnetworkplayers;
312                 }
313
314                 for (i = 1;i <= cl.maxclients;i++)
315                 {
316                         entity_render_t *ent = &cl.entities[i].render;
317
318                         // don't hit ourselves
319                         if (i == cl.playerentity)
320                                 continue;
321
322                         // don't hit players that don't exist
323                         if (!cl.entities_active[i])
324                                 continue;
325                         if (!cl.scores[i-1].name[0])
326                                 continue;
327
328                         if(IS_OLDNEXUIZ_DERIVED(gamemode))
329                         {
330                                 // don't hit spectators or nonsolid players
331                                 if(cl.scores[i-1].frags == -666 || cl.scores[i-1].frags == -616)
332                                         continue;
333                         }
334
335                         Matrix4x4_OriginFromMatrix(&ent->matrix, origin);
336                         VectorAdd(origin, cl.playerstandmins, entmins);
337                         VectorAdd(origin, cl.playerstandmaxs, entmaxs);
338                         if (!BoxesOverlap(clipboxmins, clipboxmaxs, entmins, entmaxs))
339                                 continue;
340                         Matrix4x4_CreateTranslate(&entmatrix, origin[0], origin[1], origin[2]);
341                         Matrix4x4_CreateTranslate(&entinversematrix, -origin[0], -origin[1], -origin[2]);
342                         Collision_ClipPointToGenericEntity(&trace, NULL, NULL, NULL, cl.playerstandmins, cl.playerstandmaxs, SUPERCONTENTS_BODY, &entmatrix, &entinversematrix, start, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask);
343                         if (cliptrace.fraction > trace.fraction && hitnetworkentity)
344                                 *hitnetworkentity = i;
345                         Collision_CombineTraces(&cliptrace, &trace, NULL, false);
346                 }
347
348 skipnetworkplayers:
349                 ;
350         }
351
352         // clip to entities
353         // because this uses World_EntitiestoBox, we know all entity boxes overlap
354         // the clip region, so we can skip culling checks in the loop below
355         // note: if prog is NULL then there won't be any linked entities
356         numtouchedicts = 0;
357         if (hitcsqcentities && prog != NULL)
358         {
359                 numtouchedicts = World_EntitiesInBox(&cl.world, clipboxmins, clipboxmaxs, MAX_EDICTS, touchedicts);
360                 if (numtouchedicts > MAX_EDICTS)
361                 {
362                         // this never happens
363                         Con_Printf("CL_EntitiesInBox returned %i edicts, max was %i\n", numtouchedicts, MAX_EDICTS);
364                         numtouchedicts = MAX_EDICTS;
365                 }
366         }
367         for (i = 0;i < numtouchedicts;i++)
368         {
369                 touch = touchedicts[i];
370
371                 if (PRVM_clientedictfloat(touch, solid) < SOLID_BBOX)
372                         continue;
373                 if (type == MOVE_NOMONSTERS && PRVM_clientedictfloat(touch, solid) != SOLID_BSP)
374                         continue;
375
376                 if (passedict)
377                 {
378                         // don't clip against self
379                         if (passedict == touch)
380                                 continue;
381                         // don't clip owned entities against owner
382                         if (traceowner == touch)
383                                 continue;
384                         // don't clip owner against owned entities
385                         if (passedictprog == PRVM_clientedictedict(touch, owner))
386                                 continue;
387                         // don't clip against any entities in the same clipgroup (DP_RM_CLIPGROUP)
388                         if (clipgroup && clipgroup == (int)PRVM_clientedictfloat(touch, clipgroup))
389                                 continue;
390                         // don't clip points against points (they can't collide)
391                         if (VectorCompare(PRVM_clientedictvector(touch, mins), PRVM_clientedictvector(touch, maxs)) && (type != MOVE_MISSILE || !((int)PRVM_clientedictfloat(touch, flags) & FL_MONSTER)))
392                                 continue;
393                 }
394
395                 bodysupercontents = PRVM_clientedictfloat(touch, solid) == SOLID_CORPSE ? SUPERCONTENTS_CORPSE : SUPERCONTENTS_BODY;
396
397                 // might interact, so do an exact clip
398                 model = NULL;
399                 if ((int) PRVM_clientedictfloat(touch, solid) == SOLID_BSP || type == MOVE_HITMODEL)
400                         model = CL_GetModelFromEdict(touch);
401                 if (model)
402                         Matrix4x4_CreateFromQuakeEntity(&matrix, PRVM_clientedictvector(touch, origin)[0], PRVM_clientedictvector(touch, origin)[1], PRVM_clientedictvector(touch, origin)[2], PRVM_clientedictvector(touch, angles)[0], PRVM_clientedictvector(touch, angles)[1], PRVM_clientedictvector(touch, angles)[2], 1);
403                 else
404                         Matrix4x4_CreateTranslate(&matrix, PRVM_clientedictvector(touch, origin)[0], PRVM_clientedictvector(touch, origin)[1], PRVM_clientedictvector(touch, origin)[2]);
405                 Matrix4x4_Invert_Simple(&imatrix, &matrix);
406                 VectorCopy(PRVM_clientedictvector(touch, mins), touchmins);
407                 VectorCopy(PRVM_clientedictvector(touch, maxs), touchmaxs);
408                 if ((int)PRVM_clientedictfloat(touch, flags) & FL_MONSTER)
409                         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);
410                 else
411                         Collision_ClipPointToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask);
412
413                 if (cliptrace.fraction > trace.fraction && hitnetworkentity)
414                         *hitnetworkentity = 0;
415                 Collision_CombineTraces(&cliptrace, &trace, (void *)touch, PRVM_clientedictfloat(touch, solid) == SOLID_BSP);
416         }
417
418 finished:
419         return cliptrace;
420 }
421
422 /*
423 ==================
424 CL_TraceLine
425 ==================
426 */
427 trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, float extend, qbool hitnetworkbrushmodels, qbool hitnetworkplayers, int *hitnetworkentity, qbool hitcsqcentities, qbool hitsurfaces)
428 {
429         prvm_prog_t *prog = CLVM_prog;
430         int i, bodysupercontents;
431         int passedictprog;
432         prvm_edict_t *traceowner, *touch;
433         trace_t trace;
434         // temporary storage because prvm_vec_t may need conversion
435         vec3_t touchmins, touchmaxs;
436         // bounding box of entire move area
437         vec3_t clipboxmins, clipboxmaxs;
438         // size when clipping against monsters
439         vec3_t clipmins2, clipmaxs2;
440         // start and end origin of move
441         vec3_t clipstart, clipend;
442         // trace results
443         trace_t cliptrace;
444         // matrices to transform into/out of other entity's space
445         matrix4x4_t matrix, imatrix;
446         // model of other entity
447         model_t *model;
448         // list of entities to test for collisions
449         int numtouchedicts;
450         static prvm_edict_t *touchedicts[MAX_EDICTS];
451         int clipgroup;
452         if (VectorCompare(start, end))
453                 return CL_TracePoint(start, type, passedict, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, hitnetworkbrushmodels, hitnetworkplayers, hitnetworkentity, hitcsqcentities);
454
455         if (hitnetworkentity)
456                 *hitnetworkentity = 0;
457
458         VectorCopy(start, clipstart);
459         VectorCopy(end, clipend);
460         VectorClear(clipmins2);
461         VectorClear(clipmaxs2);
462 #if COLLISIONPARANOID >= 3
463         Con_Printf("move(%f %f %f,%f %f %f)", clipstart[0], clipstart[1], clipstart[2], clipend[0], clipend[1], clipend[2]);
464 #endif
465
466         // clip to world
467         Collision_ClipLineToWorld(&cliptrace, cl.worldmodel, clipstart, clipend, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend, hitsurfaces);
468         cliptrace.worldstartsolid = cliptrace.bmodelstartsolid = cliptrace.startsolid;
469         if (cliptrace.startsolid || cliptrace.fraction < 1)
470                 cliptrace.ent = prog ? prog->edicts : NULL;
471         if (type == MOVE_WORLDONLY)
472                 goto finished;
473
474         if (type == MOVE_MISSILE)
475         {
476                 // LadyHavoc: modified this, was = -15, now -= 15
477                 for (i = 0;i < 3;i++)
478                 {
479                         clipmins2[i] -= 15;
480                         clipmaxs2[i] += 15;
481                 }
482         }
483
484         // create the bounding box of the entire move
485         for (i = 0;i < 3;i++)
486         {
487                 clipboxmins[i] = min(clipstart[i], cliptrace.endpos[i]) + clipmins2[i] - 1;
488                 clipboxmaxs[i] = max(clipstart[i], cliptrace.endpos[i]) + clipmaxs2[i] + 1;
489         }
490
491         // debug override to test against everything
492         if (sv_debugmove.integer)
493         {
494                 clipboxmins[0] = clipboxmins[1] = clipboxmins[2] = (vec_t)-999999999;
495                 clipboxmaxs[0] = clipboxmaxs[1] = clipboxmaxs[2] =  (vec_t)999999999;
496         }
497
498         // if the passedict is world, make it NULL (to avoid two checks each time)
499         // this checks prog because this function is often called without a CSQC
500         // VM context
501         if (prog == NULL || passedict == prog->edicts)
502                 passedict = NULL;
503         // precalculate prog value for passedict for comparisons
504         passedictprog = prog != NULL ? PRVM_EDICT_TO_PROG(passedict) : 0;
505         // precalculate passedict's owner edict pointer for comparisons
506         traceowner = passedict ? PRVM_PROG_TO_EDICT(PRVM_clientedictedict(passedict, owner)) : NULL;
507
508         clipgroup = passedict ? (int)PRVM_clientedictfloat(passedict, clipgroup) : 0;
509
510         // collide against network entities
511         if (hitnetworkbrushmodels)
512         {
513                 for (i = 0;i < cl.num_brushmodel_entities;i++)
514                 {
515                         entity_render_t *ent = &cl.entities[cl.brushmodel_entities[i]].render;
516                         if (!BoxesOverlap(clipboxmins, clipboxmaxs, ent->mins, ent->maxs))
517                                 continue;
518                         Collision_ClipLineToGenericEntity(&trace, ent->model, ent->frameblend, ent->skeleton, vec3_origin, vec3_origin, 0, &ent->matrix, &ent->inversematrix, start, end, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend, hitsurfaces);
519                         if (cliptrace.fraction > trace.fraction && hitnetworkentity)
520                                 *hitnetworkentity = cl.brushmodel_entities[i];
521                         Collision_CombineTraces(&cliptrace, &trace, NULL, true);
522                 }
523         }
524
525         // collide against player entities
526         if (hitnetworkplayers)
527         {
528                 vec3_t origin, entmins, entmaxs;
529                 matrix4x4_t entmatrix, entinversematrix;
530
531                 if(IS_OLDNEXUIZ_DERIVED(gamemode))
532                 {
533                         // don't hit network players, if we are a nonsolid player
534                         if(cl.scores[cl.playerentity-1].frags == -666 || cl.scores[cl.playerentity-1].frags == -616)
535                                 goto skipnetworkplayers;
536                 }
537
538                 for (i = 1;i <= cl.maxclients;i++)
539                 {
540                         entity_render_t *ent = &cl.entities[i].render;
541
542                         // don't hit ourselves
543                         if (i == cl.playerentity)
544                                 continue;
545
546                         // don't hit players that don't exist
547                         if (!cl.entities_active[i])
548                                 continue;
549                         if (!cl.scores[i-1].name[0])
550                                 continue;
551
552                         if(IS_OLDNEXUIZ_DERIVED(gamemode))
553                         {
554                                 // don't hit spectators or nonsolid players
555                                 if(cl.scores[i-1].frags == -666 || cl.scores[i-1].frags == -616)
556                                         continue;
557                         }
558
559                         Matrix4x4_OriginFromMatrix(&ent->matrix, origin);
560                         VectorAdd(origin, cl.playerstandmins, entmins);
561                         VectorAdd(origin, cl.playerstandmaxs, entmaxs);
562                         if (!BoxesOverlap(clipboxmins, clipboxmaxs, entmins, entmaxs))
563                                 continue;
564                         Matrix4x4_CreateTranslate(&entmatrix, origin[0], origin[1], origin[2]);
565                         Matrix4x4_CreateTranslate(&entinversematrix, -origin[0], -origin[1], -origin[2]);
566                         Collision_ClipLineToGenericEntity(&trace, NULL, NULL, NULL, cl.playerstandmins, cl.playerstandmaxs, SUPERCONTENTS_BODY, &entmatrix, &entinversematrix, start, end, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend, hitsurfaces);
567                         if (cliptrace.fraction > trace.fraction && hitnetworkentity)
568                                 *hitnetworkentity = i;
569                         Collision_CombineTraces(&cliptrace, &trace, NULL, false);
570                 }
571
572 skipnetworkplayers:
573                 ;
574         }
575
576         // clip to entities
577         // because this uses World_EntitiestoBox, we know all entity boxes overlap
578         // the clip region, so we can skip culling checks in the loop below
579         // note: if prog is NULL then there won't be any linked entities
580         numtouchedicts = 0;
581         if (hitcsqcentities && prog != NULL)
582         {
583                 numtouchedicts = World_EntitiesInBox(&cl.world, clipboxmins, clipboxmaxs, MAX_EDICTS, touchedicts);
584                 if (numtouchedicts > MAX_EDICTS)
585                 {
586                         // this never happens
587                         Con_Printf("CL_EntitiesInBox returned %i edicts, max was %i\n", numtouchedicts, MAX_EDICTS);
588                         numtouchedicts = MAX_EDICTS;
589                 }
590         }
591         for (i = 0;i < numtouchedicts;i++)
592         {
593                 touch = touchedicts[i];
594
595                 if (PRVM_clientedictfloat(touch, solid) < SOLID_BBOX)
596                         continue;
597                 if (type == MOVE_NOMONSTERS && PRVM_clientedictfloat(touch, solid) != SOLID_BSP)
598                         continue;
599
600                 if (passedict)
601                 {
602                         // don't clip against self
603                         if (passedict == touch)
604                                 continue;
605                         // don't clip owned entities against owner
606                         if (traceowner == touch)
607                                 continue;
608                         // don't clip owner against owned entities
609                         if (passedictprog == PRVM_clientedictedict(touch, owner))
610                                 continue;
611                         // don't clip against any entities in the same clipgroup (DP_RM_CLIPGROUP)
612                         if (clipgroup && clipgroup == (int)PRVM_clientedictfloat(touch, clipgroup))
613                                 continue;
614                         // don't clip points against points (they can't collide)
615                         if (VectorCompare(PRVM_clientedictvector(touch, mins), PRVM_clientedictvector(touch, maxs)) && (type != MOVE_MISSILE || !((int)PRVM_clientedictfloat(touch, flags) & FL_MONSTER)))
616                                 continue;
617                 }
618
619                 bodysupercontents = PRVM_clientedictfloat(touch, solid) == SOLID_CORPSE ? SUPERCONTENTS_CORPSE : SUPERCONTENTS_BODY;
620
621                 // might interact, so do an exact clip
622                 model = NULL;
623                 if ((int) PRVM_clientedictfloat(touch, solid) == SOLID_BSP || type == MOVE_HITMODEL)
624                         model = CL_GetModelFromEdict(touch);
625                 if (model)
626                         Matrix4x4_CreateFromQuakeEntity(&matrix, PRVM_clientedictvector(touch, origin)[0], PRVM_clientedictvector(touch, origin)[1], PRVM_clientedictvector(touch, origin)[2], PRVM_clientedictvector(touch, angles)[0], PRVM_clientedictvector(touch, angles)[1], PRVM_clientedictvector(touch, angles)[2], 1);
627                 else
628                         Matrix4x4_CreateTranslate(&matrix, PRVM_clientedictvector(touch, origin)[0], PRVM_clientedictvector(touch, origin)[1], PRVM_clientedictvector(touch, origin)[2]);
629                 Matrix4x4_Invert_Simple(&imatrix, &matrix);
630                 VectorCopy(PRVM_clientedictvector(touch, mins), touchmins);
631                 VectorCopy(PRVM_clientedictvector(touch, maxs), touchmaxs);
632                 if (type == MOVE_MISSILE && (int)PRVM_clientedictfloat(touch, flags) & FL_MONSTER)
633                         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);
634                 else
635                         Collision_ClipLineToGenericEntity(&trace, model, touch->priv.server->frameblend, &touch->priv.server->skeleton, touchmins, touchmaxs, bodysupercontents, &matrix, &imatrix, clipstart, clipend, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend, hitsurfaces);
636
637                 if (cliptrace.fraction > trace.fraction && hitnetworkentity)
638                         *hitnetworkentity = 0;
639                 Collision_CombineTraces(&cliptrace, &trace, (void *)touch, PRVM_clientedictfloat(touch, solid) == SOLID_BSP);
640         }
641
642 finished:
643         return cliptrace;
644 }
645
646 /*
647 ==================
648 CL_Move
649 ==================
650 */
651 trace_t CL_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, qbool hitnetworkbrushmodels, qbool hitnetworkplayers, int *hitnetworkentity, qbool hitcsqcentities)
652 {
653         prvm_prog_t *prog = CLVM_prog;
654         vec3_t hullmins, hullmaxs;
655         int i, bodysupercontents;
656         int passedictprog;
657         qbool pointtrace;
658         prvm_edict_t *traceowner, *touch;
659         trace_t trace;
660         // temporary storage because prvm_vec_t may need conversion
661         vec3_t touchmins, touchmaxs;
662         // bounding box of entire move area
663         vec3_t clipboxmins, clipboxmaxs;
664         // size of the moving object
665         vec3_t clipmins, clipmaxs;
666         // size when clipping against monsters
667         vec3_t clipmins2, clipmaxs2;
668         // start and end origin of move
669         vec3_t clipstart, clipend;
670         // trace results
671         trace_t cliptrace;
672         // matrices to transform into/out of other entity's space
673         matrix4x4_t matrix, imatrix;
674         // model of other entity
675         model_t *model;
676         // list of entities to test for collisions
677         int numtouchedicts;
678         static prvm_edict_t *touchedicts[MAX_EDICTS];
679         int clipgroup;
680         if (VectorCompare(mins, maxs))
681         {
682                 vec3_t shiftstart, shiftend;
683                 VectorAdd(start, mins, shiftstart);
684                 VectorAdd(end, mins, shiftend);
685                 if (VectorCompare(start, end))
686                         trace = CL_TracePoint(shiftstart, type, passedict, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, hitnetworkbrushmodels, hitnetworkplayers, hitnetworkentity, hitcsqcentities);
687                 else
688                         trace = CL_TraceLine(shiftstart, shiftend, type, passedict, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend, hitnetworkbrushmodels, hitnetworkplayers, hitnetworkentity, hitcsqcentities, false);
689                 VectorSubtract(trace.endpos, mins, trace.endpos);
690                 return trace;
691         }
692
693         if (hitnetworkentity)
694                 *hitnetworkentity = 0;
695
696         VectorCopy(start, clipstart);
697         VectorCopy(end, clipend);
698         VectorCopy(mins, clipmins);
699         VectorCopy(maxs, clipmaxs);
700         VectorCopy(mins, clipmins2);
701         VectorCopy(maxs, clipmaxs2);
702 #if COLLISIONPARANOID >= 3
703         Con_Printf("move(%f %f %f,%f %f %f)", clipstart[0], clipstart[1], clipstart[2], clipend[0], clipend[1], clipend[2]);
704 #endif
705
706         // clip to world
707         Collision_ClipToWorld(&cliptrace, cl.worldmodel, clipstart, clipmins, clipmaxs, clipend, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend);
708         cliptrace.worldstartsolid = cliptrace.bmodelstartsolid = cliptrace.startsolid;
709         if (cliptrace.startsolid || cliptrace.fraction < 1)
710                 cliptrace.ent = prog ? prog->edicts : NULL;
711         if (type == MOVE_WORLDONLY)
712                 goto finished;
713
714         if (type == MOVE_MISSILE)
715         {
716                 // LadyHavoc: modified this, was = -15, now -= 15
717                 for (i = 0;i < 3;i++)
718                 {
719                         clipmins2[i] -= 15;
720                         clipmaxs2[i] += 15;
721                 }
722         }
723
724         // get adjusted box for bmodel collisions if the world is q1bsp or hlbsp
725         if (cl.worldmodel && cl.worldmodel->brush.RoundUpToHullSize)
726                 cl.worldmodel->brush.RoundUpToHullSize(cl.worldmodel, clipmins, clipmaxs, hullmins, hullmaxs);
727         else
728         {
729                 VectorCopy(clipmins, hullmins);
730                 VectorCopy(clipmaxs, hullmaxs);
731         }
732
733         // create the bounding box of the entire move
734         for (i = 0;i < 3;i++)
735         {
736                 clipboxmins[i] = min(clipstart[i], cliptrace.endpos[i]) + min(hullmins[i], clipmins2[i]) - 1;
737                 clipboxmaxs[i] = max(clipstart[i], cliptrace.endpos[i]) + max(hullmaxs[i], clipmaxs2[i]) + 1;
738         }
739
740         // debug override to test against everything
741         if (sv_debugmove.integer)
742         {
743                 clipboxmins[0] = clipboxmins[1] = clipboxmins[2] = (vec_t)-999999999;
744                 clipboxmaxs[0] = clipboxmaxs[1] = clipboxmaxs[2] =  (vec_t)999999999;
745         }
746
747         // if the passedict is world, make it NULL (to avoid two checks each time)
748         // this checks prog because this function is often called without a CSQC
749         // VM context
750         if (prog == NULL || passedict == prog->edicts)
751                 passedict = NULL;
752         // precalculate prog value for passedict for comparisons
753         passedictprog = prog != NULL ? PRVM_EDICT_TO_PROG(passedict) : 0;
754         // figure out whether this is a point trace for comparisons
755         pointtrace = VectorCompare(clipmins, clipmaxs);
756         // precalculate passedict's owner edict pointer for comparisons
757         traceowner = passedict ? PRVM_PROG_TO_EDICT(PRVM_clientedictedict(passedict, owner)) : NULL;
758
759         clipgroup = passedict ? (int)PRVM_clientedictfloat(passedict, clipgroup) : 0;
760
761         // collide against network entities
762         if (hitnetworkbrushmodels)
763         {
764                 for (i = 0;i < cl.num_brushmodel_entities;i++)
765                 {
766                         entity_render_t *ent = &cl.entities[cl.brushmodel_entities[i]].render;
767                         if (!BoxesOverlap(clipboxmins, clipboxmaxs, ent->mins, ent->maxs))
768                                 continue;
769                         Collision_ClipToGenericEntity(&trace, ent->model, ent->frameblend, ent->skeleton, vec3_origin, vec3_origin, 0, &ent->matrix, &ent->inversematrix, start, mins, maxs, end, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend);
770                         if (cliptrace.fraction > trace.fraction && hitnetworkentity)
771                                 *hitnetworkentity = cl.brushmodel_entities[i];
772                         Collision_CombineTraces(&cliptrace, &trace, NULL, true);
773                 }
774         }
775
776         // collide against player entities
777         if (hitnetworkplayers)
778         {
779                 vec3_t origin, entmins, entmaxs;
780                 matrix4x4_t entmatrix, entinversematrix;
781
782                 if(IS_OLDNEXUIZ_DERIVED(gamemode))
783                 {
784                         // don't hit network players, if we are a nonsolid player
785                         if(cl.scores[cl.playerentity-1].frags == -666 || cl.scores[cl.playerentity-1].frags == -616)
786                                 goto skipnetworkplayers;
787                 }
788
789                 for (i = 1;i <= cl.maxclients;i++)
790                 {
791                         entity_render_t *ent = &cl.entities[i].render;
792
793                         // don't hit ourselves
794                         if (i == cl.playerentity)
795                                 continue;
796
797                         // don't hit players that don't exist
798                         if (!cl.entities_active[i])
799                                 continue;
800                         if (!cl.scores[i-1].name[0])
801                                 continue;
802
803                         if(IS_OLDNEXUIZ_DERIVED(gamemode))
804                         {
805                                 // don't hit spectators or nonsolid players
806                                 if(cl.scores[i-1].frags == -666 || cl.scores[i-1].frags == -616)
807                                         continue;
808                         }
809
810                         Matrix4x4_OriginFromMatrix(&ent->matrix, origin);
811                         VectorAdd(origin, cl.playerstandmins, entmins);
812                         VectorAdd(origin, cl.playerstandmaxs, entmaxs);
813                         if (!BoxesOverlap(clipboxmins, clipboxmaxs, entmins, entmaxs))
814                                 continue;
815                         Matrix4x4_CreateTranslate(&entmatrix, origin[0], origin[1], origin[2]);
816                         Matrix4x4_CreateTranslate(&entinversematrix, -origin[0], -origin[1], -origin[2]);
817                         Collision_ClipToGenericEntity(&trace, NULL, NULL, NULL, cl.playerstandmins, cl.playerstandmaxs, SUPERCONTENTS_BODY, &entmatrix, &entinversematrix, start, mins, maxs, end, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend);
818                         if (cliptrace.fraction > trace.fraction && hitnetworkentity)
819                                 *hitnetworkentity = i;
820                         Collision_CombineTraces(&cliptrace, &trace, NULL, false);
821                 }
822
823 skipnetworkplayers:
824                 ;
825         }
826
827         // clip to entities
828         // because this uses World_EntitiestoBox, we know all entity boxes overlap
829         // the clip region, so we can skip culling checks in the loop below
830         // note: if prog is NULL then there won't be any linked entities
831         numtouchedicts = 0;
832         if (hitcsqcentities && prog != NULL)
833         {
834                 numtouchedicts = World_EntitiesInBox(&cl.world, clipboxmins, clipboxmaxs, MAX_EDICTS, touchedicts);
835                 if (numtouchedicts > MAX_EDICTS)
836                 {
837                         // this never happens
838                         Con_Printf("CL_EntitiesInBox returned %i edicts, max was %i\n", numtouchedicts, MAX_EDICTS);
839                         numtouchedicts = MAX_EDICTS;
840                 }
841         }
842         for (i = 0;i < numtouchedicts;i++)
843         {
844                 touch = touchedicts[i];
845
846                 if (PRVM_clientedictfloat(touch, solid) < SOLID_BBOX)
847                         continue;
848                 if (type == MOVE_NOMONSTERS && PRVM_clientedictfloat(touch, solid) != SOLID_BSP)
849                         continue;
850
851                 if (passedict)
852                 {
853                         // don't clip against self
854                         if (passedict == touch)
855                                 continue;
856                         // don't clip owned entities against owner
857                         if (traceowner == touch)
858                                 continue;
859                         // don't clip owner against owned entities
860                         if (passedictprog == PRVM_clientedictedict(touch, owner))
861                                 continue;
862                         // don't clip against any entities in the same clipgroup (DP_RM_CLIPGROUP)
863                         if (clipgroup && clipgroup == (int)PRVM_clientedictfloat(touch, clipgroup))
864                                 continue;
865                         // don't clip points against points (they can't collide)
866                         if (pointtrace && VectorCompare(PRVM_clientedictvector(touch, mins), PRVM_clientedictvector(touch, maxs)) && (type != MOVE_MISSILE || !((int)PRVM_clientedictfloat(touch, flags) & FL_MONSTER)))
867                                 continue;
868                 }
869
870                 bodysupercontents = PRVM_clientedictfloat(touch, solid) == SOLID_CORPSE ? SUPERCONTENTS_CORPSE : SUPERCONTENTS_BODY;
871
872                 // might interact, so do an exact clip
873                 model = NULL;
874                 if ((int) PRVM_clientedictfloat(touch, solid) == SOLID_BSP || type == MOVE_HITMODEL)
875                         model = CL_GetModelFromEdict(touch);
876                 if (model)
877                         Matrix4x4_CreateFromQuakeEntity(&matrix, PRVM_clientedictvector(touch, origin)[0], PRVM_clientedictvector(touch, origin)[1], PRVM_clientedictvector(touch, origin)[2], PRVM_clientedictvector(touch, angles)[0], PRVM_clientedictvector(touch, angles)[1], PRVM_clientedictvector(touch, angles)[2], 1);
878                 else
879                         Matrix4x4_CreateTranslate(&matrix, PRVM_clientedictvector(touch, origin)[0], PRVM_clientedictvector(touch, origin)[1], PRVM_clientedictvector(touch, origin)[2]);
880                 Matrix4x4_Invert_Simple(&imatrix, &matrix);
881                 VectorCopy(PRVM_clientedictvector(touch, mins), touchmins);
882                 VectorCopy(PRVM_clientedictvector(touch, maxs), touchmaxs);
883                 if ((int)PRVM_clientedictfloat(touch, flags) & FL_MONSTER)
884                         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);
885                 else
886                         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);
887
888                 if (cliptrace.fraction > trace.fraction && hitnetworkentity)
889                         *hitnetworkentity = 0;
890                 Collision_CombineTraces(&cliptrace, &trace, (void *)touch, PRVM_clientedictfloat(touch, solid) == SOLID_BSP);
891         }
892
893 finished:
894         return cliptrace;
895 }
896
897 /*
898 ==================
899 CL_Cache_TraceLine
900 ==================
901 */
902 trace_t CL_Cache_TraceLineSurfaces(const vec3_t start, const vec3_t end, int type, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask)
903 {
904         prvm_prog_t *prog = CLVM_prog;
905         int i;
906         prvm_edict_t *touch;
907         trace_t trace;
908         // bounding box of entire move area
909         vec3_t clipboxmins, clipboxmaxs;
910         // start and end origin of move
911         vec3_t clipstart, clipend;
912         // trace results
913         trace_t cliptrace;
914         // matrices to transform into/out of other entity's space
915         matrix4x4_t matrix, imatrix;
916         // model of other entity
917         model_t *model;
918         // list of entities to test for collisions
919         int numtouchedicts;
920         static prvm_edict_t *touchedicts[MAX_EDICTS];
921
922         VectorCopy(start, clipstart);
923         VectorCopy(end, clipend);
924 #if COLLISIONPARANOID >= 3
925         Con_Printf("move(%f %f %f,%f %f %f)", clipstart[0], clipstart[1], clipstart[2], clipend[0], clipend[1], clipend[2]);
926 #endif
927
928         // clip to world
929         Collision_Cache_ClipLineToWorldSurfaces(&cliptrace, cl.worldmodel, clipstart, clipend, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask);
930         cliptrace.worldstartsolid = cliptrace.bmodelstartsolid = cliptrace.startsolid;
931         if (cliptrace.startsolid || cliptrace.fraction < 1)
932                 cliptrace.ent = prog ? prog->edicts : NULL;
933         if (type == MOVE_WORLDONLY)
934                 goto finished;
935
936         // create the bounding box of the entire move
937         for (i = 0;i < 3;i++)
938         {
939                 clipboxmins[i] = min(clipstart[i], cliptrace.endpos[i]) - 1;
940                 clipboxmaxs[i] = max(clipstart[i], cliptrace.endpos[i]) + 1;
941         }
942
943         // if the passedict is world, make it NULL (to avoid two checks each time)
944         // this checks prog because this function is often called without a CSQC
945         // VM context
946
947         // collide against network entities
948         for (i = 0;i < cl.num_brushmodel_entities;i++)
949         {
950                 entity_render_t *ent = &cl.entities[cl.brushmodel_entities[i]].render;
951                 if (!BoxesOverlap(clipboxmins, clipboxmaxs, ent->mins, ent->maxs))
952                         continue;
953                 Collision_Cache_ClipLineToGenericEntitySurfaces(&trace, ent->model, &ent->matrix, &ent->inversematrix, start, end, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask);
954                 Collision_CombineTraces(&cliptrace, &trace, NULL, true);
955         }
956
957         // clip to entities
958         // because this uses World_EntitiestoBox, we know all entity boxes overlap
959         // the clip region, so we can skip culling checks in the loop below
960         // note: if prog is NULL then there won't be any linked entities
961         numtouchedicts = 0;
962         if (prog != NULL)
963         {
964                 numtouchedicts = World_EntitiesInBox(&cl.world, clipboxmins, clipboxmaxs, MAX_EDICTS, touchedicts);
965                 if (numtouchedicts > MAX_EDICTS)
966                 {
967                         // this never happens
968                         Con_Printf("CL_EntitiesInBox returned %i edicts, max was %i\n", numtouchedicts, MAX_EDICTS);
969                         numtouchedicts = MAX_EDICTS;
970                 }
971         }
972         for (i = 0;i < numtouchedicts;i++)
973         {
974                 touch = touchedicts[i];
975                 // might interact, so do an exact clip
976                 // only hit entity models, not collision shapes
977                 model = CL_GetModelFromEdict(touch);
978                 if (!model)
979                         continue;
980                 // animated models are not suitable for caching
981                 if ((&touch->priv.server->frameblend[0] && (touch->priv.server->frameblend[0].lerp != 1.0 || touch->priv.server->frameblend[0].subframe != 0)) || touch->priv.server->skeleton.relativetransforms)
982                         continue;
983                 if (type == MOVE_NOMONSTERS && PRVM_clientedictfloat(touch, solid) != SOLID_BSP)
984                         continue;
985                 Matrix4x4_CreateFromQuakeEntity(&matrix, PRVM_clientedictvector(touch, origin)[0], PRVM_clientedictvector(touch, origin)[1], PRVM_clientedictvector(touch, origin)[2], PRVM_clientedictvector(touch, angles)[0], PRVM_clientedictvector(touch, angles)[1], PRVM_clientedictvector(touch, angles)[2], 1);
986                 Matrix4x4_Invert_Simple(&imatrix, &matrix);
987                 Collision_Cache_ClipLineToGenericEntitySurfaces(&trace, model, &matrix, &imatrix, clipstart, clipend, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask);
988                 Collision_CombineTraces(&cliptrace, &trace, (void *)touch, PRVM_clientedictfloat(touch, solid) == SOLID_BSP);
989         }
990
991 finished:
992         return cliptrace;
993 }
994