+ // 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(passedict->fields.server->owner) : 0;
+
+ // clip to enttiies
+ 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 (touch->fields.server->solid < SOLID_BBOX)
+ continue;
+ if (type == MOVE_NOMONSTERS && touch->fields.server->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 == touch->fields.server->owner)
+ continue;
+ // don't clip points against points (they can't collide)
+ if (pointtrace && VectorCompare(touch->fields.server->mins, touch->fields.server->maxs) && (type != MOVE_MISSILE || !((int)touch->fields.server->flags & FL_MONSTER)))
+ continue;
+ }
+
+ // might interact, so do an exact clip
+ if ((int)touch->fields.server->flags & FL_MONSTER)
+ trace = SV_ClipMoveToEntity(touch, clipstart, clipmins2, clipmaxs2, clipend, type, hitsupercontentsmask);
+ else
+ trace = SV_ClipMoveToEntity(touch, clipstart, clipmins, clipmaxs, clipend, type, hitsupercontentsmask);
+ // LordHavoc: take the 'best' answers from the new trace and combine with existing data
+ if (trace.allsolid)
+ cliptrace.allsolid = true;
+ if (trace.startsolid)
+ {
+ if (touch->fields.server->solid == SOLID_BSP)
+ cliptrace.bmodelstartsolid = true;
+ cliptrace.startsolid = true;
+ if (cliptrace.realfraction == 1)
+ cliptrace.ent = touch;
+ }
+ // don't set this except on the world, because it can easily confuse
+ // monsters underwater if there's a bmodel involved in the trace
+ // (inopen && inwater is how they check water visibility)
+ //if (trace.inopen)
+ // cliptrace.inopen = true;
+ if (trace.inwater)
+ cliptrace.inwater = true;
+ if (trace.realfraction < cliptrace.realfraction)
+ {
+ cliptrace.fraction = trace.fraction;
+ cliptrace.realfraction = trace.realfraction;
+ VectorCopy(trace.endpos, cliptrace.endpos);
+ cliptrace.plane = trace.plane;
+ cliptrace.ent = touch;
+ cliptrace.hitsupercontents = trace.hitsupercontents;
+ cliptrace.hitq3surfaceflags = trace.hitq3surfaceflags;
+ cliptrace.hittexture = trace.hittexture;
+ }
+ cliptrace.startsupercontents |= trace.startsupercontents;
+ }