+trace_t CL_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, qboolean hitnetworkbrushmodels, qboolean hitnetworkplayers, int *hitnetworkentity, qboolean hitcsqcentities)
+{
+ prvm_prog_t *prog = CLVM_prog;
+ int i, bodysupercontents;
+ int passedictprog;
+ prvm_edict_t *traceowner, *touch;
+ trace_t trace;
+ // temporary storage because prvm_vec_t may need conversion
+ 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
+ dp_model_t *model;
+ // list of entities to test for collisions
+ int numtouchedicts;
+ static prvm_edict_t *touchedicts[MAX_EDICTS];
+
+ if (hitnetworkentity)
+ *hitnetworkentity = 0;
+
+ 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, cl.worldmodel, clipstart, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask);
+ cliptrace.worldstartsolid = cliptrace.bmodelstartsolid = cliptrace.startsolid;
+ if (cliptrace.startsolid || cliptrace.fraction < 1)
+ cliptrace.ent = prog ? prog->edicts : NULL;
+ if (type == MOVE_WORLDONLY)
+ goto finished;
+
+ if (type == MOVE_MISSILE)
+ {
+ // LordHavoc: 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] = clipstart[i] - 1;
+ clipboxmaxs[i] = clipstart[i] + 1;
+ }
+
+ // debug override to test against everything
+ if (sv_debugmove.integer)
+ {
+ clipboxmins[0] = clipboxmins[1] = clipboxmins[2] = -999999999;
+ clipboxmaxs[0] = clipboxmaxs[1] = clipboxmaxs[2] = 999999999;
+ }
+
+ // if the passedict is world, make it NULL (to avoid two checks each time)
+ // this checks prog because this function is often called without a CSQC
+ // VM context
+ if (prog == NULL || passedict == prog->edicts)
+ passedict = NULL;
+ // precalculate prog value for passedict for comparisons
+ passedictprog = prog != NULL ? PRVM_EDICT_TO_PROG(passedict) : 0;
+ // precalculate passedict's owner edict pointer for comparisons
+ traceowner = passedict ? PRVM_PROG_TO_EDICT(PRVM_clientedictedict(passedict, owner)) : NULL;
+
+ // collide against network entities
+ if (hitnetworkbrushmodels)
+ {
+ for (i = 0;i < cl.num_brushmodel_entities;i++)
+ {
+ entity_render_t *ent = &cl.entities[cl.brushmodel_entities[i]].render;
+ if (!BoxesOverlap(clipboxmins, clipboxmaxs, ent->mins, ent->maxs))
+ continue;
+ Collision_ClipPointToGenericEntity(&trace, ent->model, ent->frameblend, ent->skeleton, vec3_origin, vec3_origin, 0, &ent->matrix, &ent->inversematrix, start, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask);
+ if (cliptrace.fraction > trace.fraction && hitnetworkentity)
+ *hitnetworkentity = cl.brushmodel_entities[i];
+ Collision_CombineTraces(&cliptrace, &trace, NULL, true);
+ }
+ }
+
+ // collide against player entities
+ if (hitnetworkplayers)
+ {
+ vec3_t origin, entmins, entmaxs;
+ matrix4x4_t entmatrix, entinversematrix;
+
+ if(IS_OLDNEXUIZ_DERIVED(gamemode))
+ {
+ // don't hit network players, if we are a nonsolid player
+ if(cl.scores[cl.playerentity-1].frags == -666 || cl.scores[cl.playerentity-1].frags == -616)
+ goto skipnetworkplayers;
+ }
+
+ for (i = 1;i <= cl.maxclients;i++)
+ {
+ entity_render_t *ent = &cl.entities[i].render;
+
+ // don't hit ourselves
+ if (i == cl.playerentity)
+ continue;
+
+ // don't hit players that don't exist
+ if (!cl.entities_active[i])
+ continue;
+ if (!cl.scores[i-1].name[0])
+ continue;
+
+ if(IS_OLDNEXUIZ_DERIVED(gamemode))
+ {
+ // don't hit spectators or nonsolid players
+ if(cl.scores[i-1].frags == -666 || cl.scores[i-1].frags == -616)
+ continue;
+ }
+
+ Matrix4x4_OriginFromMatrix(&ent->matrix, origin);
+ VectorAdd(origin, cl.playerstandmins, entmins);
+ VectorAdd(origin, cl.playerstandmaxs, entmaxs);
+ if (!BoxesOverlap(clipboxmins, clipboxmaxs, entmins, entmaxs))
+ continue;
+ Matrix4x4_CreateTranslate(&entmatrix, origin[0], origin[1], origin[2]);
+ Matrix4x4_CreateTranslate(&entinversematrix, -origin[0], -origin[1], -origin[2]);
+ Collision_ClipPointToGenericEntity(&trace, NULL, NULL, NULL, cl.playerstandmins, cl.playerstandmaxs, SUPERCONTENTS_BODY, &entmatrix, &entinversematrix, start, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask);
+ if (cliptrace.fraction > trace.fraction && hitnetworkentity)
+ *hitnetworkentity = i;
+ Collision_CombineTraces(&cliptrace, &trace, NULL, false);
+ }
+
+skipnetworkplayers:
+ ;
+ }
+
+ // 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
+ // note: if prog is NULL then there won't be any linked entities
+ numtouchedicts = 0;
+ if (hitcsqcentities && prog != NULL)
+ {
+ numtouchedicts = World_EntitiesInBox(&cl.world, clipboxmins, clipboxmaxs, MAX_EDICTS, touchedicts);
+ if (numtouchedicts > MAX_EDICTS)
+ {
+ // this never happens
+ Con_Printf("CL_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_clientedictfloat(touch, solid) < SOLID_BBOX)
+ continue;
+ if (type == MOVE_NOMONSTERS && PRVM_clientedictfloat(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_clientedictedict(touch, owner))
+ continue;
+ // don't clip points against points (they can't collide)
+ if (VectorCompare(PRVM_clientedictvector(touch, mins), PRVM_clientedictvector(touch, maxs)) && (type != MOVE_MISSILE || !((int)PRVM_clientedictfloat(touch, flags) & FL_MONSTER)))
+ continue;
+ }
+
+ bodysupercontents = PRVM_clientedictfloat(touch, solid) == SOLID_CORPSE ? SUPERCONTENTS_CORPSE : SUPERCONTENTS_BODY;
+
+ // might interact, so do an exact clip
+ model = NULL;
+ if ((int) PRVM_clientedictfloat(touch, solid) == SOLID_BSP || type == MOVE_HITMODEL)
+ model = CL_GetModelFromEdict(touch);
+ if (model)
+ 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);
+ else
+ Matrix4x4_CreateTranslate(&matrix, PRVM_clientedictvector(touch, origin)[0], PRVM_clientedictvector(touch, origin)[1], PRVM_clientedictvector(touch, origin)[2]);
+ Matrix4x4_Invert_Simple(&imatrix, &matrix);
+ VectorCopy(PRVM_clientedictvector(touch, mins), touchmins);
+ VectorCopy(PRVM_clientedictvector(touch, maxs), touchmaxs);
+ if ((int)PRVM_clientedictfloat(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);
+
+ if (cliptrace.fraction > trace.fraction && hitnetworkentity)
+ *hitnetworkentity = 0;
+ Collision_CombineTraces(&cliptrace, &trace, (void *)touch, PRVM_clientedictfloat(touch, solid) == SOLID_BSP);
+ }
+
+finished:
+ return cliptrace;
+}
+
+/*
+==================
+CL_TraceLine
+==================
+*/
+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, qboolean hitnetworkbrushmodels, qboolean hitnetworkplayers, int *hitnetworkentity, qboolean hitcsqcentities, qboolean hitsurfaces)
+{
+ prvm_prog_t *prog = CLVM_prog;
+ int i, bodysupercontents;
+ int passedictprog;
+ prvm_edict_t *traceowner, *touch;
+ trace_t trace;
+ // temporary storage because prvm_vec_t may need conversion
+ 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
+ dp_model_t *model;
+ // list of entities to test for collisions
+ int numtouchedicts;
+ static prvm_edict_t *touchedicts[MAX_EDICTS];
+ if (VectorCompare(start, end))
+ return CL_TracePoint(start, type, passedict, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, hitnetworkbrushmodels, hitnetworkplayers, hitnetworkentity, hitcsqcentities);
+
+ if (hitnetworkentity)
+ *hitnetworkentity = 0;
+
+ 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]);