-/*
-============
-SV_TestEntityPosition
-
-returns true if the entity is in solid currently
-============
-*/
-static int SV_TestEntityPosition (prvm_edict_t *ent, vec3_t offset)
-{
- int contents;
- vec3_t org;
- trace_t trace;
- contents = SV_GenericHitSuperContentsMask(ent);
- VectorAdd(ent->fields.server->origin, offset, org);
- trace = SV_TraceBox(org, ent->fields.server->mins, ent->fields.server->maxs, ent->fields.server->origin, MOVE_NOMONSTERS, ent, contents);
- if (trace.startsupercontents & contents)
- return true;
- else
- {
- if (sv.worldmodel->brushq1.numclipnodes && !VectorCompare(ent->fields.server->mins, ent->fields.server->maxs))
- {
- // q1bsp/hlbsp use hulls and if the entity does not exactly match
- // a hull size it is incorrectly tested, so this code tries to
- // 'fix' it slightly...
- // FIXME: this breaks entities larger than the hull size
- int i;
- vec3_t v, m1, m2, s;
- VectorAdd(org, ent->fields.server->mins, m1);
- VectorAdd(org, ent->fields.server->maxs, m2);
- VectorSubtract(m2, m1, s);
-#define EPSILON (1.0f / 32.0f)
- if (s[0] >= EPSILON*2) {m1[0] += EPSILON;m2[0] -= EPSILON;}
- if (s[1] >= EPSILON*2) {m1[1] += EPSILON;m2[1] -= EPSILON;}
- if (s[2] >= EPSILON*2) {m1[2] += EPSILON;m2[2] -= EPSILON;}
- for (i = 0;i < 8;i++)
- {
- v[0] = (i & 1) ? m2[0] : m1[0];
- v[1] = (i & 2) ? m2[1] : m1[1];
- v[2] = (i & 4) ? m2[2] : m1[2];
- if (SV_PointSuperContents(v) & contents)
- return true;
- }
- }
- }
- // if the trace found a better position for the entity, move it there
- if (VectorDistance2(trace.endpos, ent->fields.server->origin) >= 0.0001)
- {
-#if 0
- // please switch back to this code when trace.endpos sometimes being in solid bug is fixed
- VectorCopy(trace.endpos, ent->fields.server->origin);
-#else
- // verify if the endpos is REALLY outside solid
- VectorCopy(trace.endpos, org);
- trace = SV_TraceBox(org, ent->fields.server->mins, ent->fields.server->maxs, org, MOVE_NOMONSTERS, ent, contents);
- if(trace.startsolid)
- Con_Printf("SV_TestEntityPosition: trace.endpos detected to be in solid. NOT using it.\n");
- else
- VectorCopy(org, ent->fields.server->origin);
-#endif
- }
- return false;
-}
-
-/*
-================
-SV_CheckAllEnts
-================
-*/
-void SV_CheckAllEnts (void)
-{
- int e;
- prvm_edict_t *check;
-
- // see if any solid entities are inside the final position
- check = PRVM_NEXT_EDICT(prog->edicts);
- for (e = 1;e < prog->num_edicts;e++, check = PRVM_NEXT_EDICT(check))
- {
- if (check->priv.server->free)
- continue;
- if (check->fields.server->movetype == MOVETYPE_PUSH
- || check->fields.server->movetype == MOVETYPE_NONE
- || check->fields.server->movetype == MOVETYPE_FOLLOW
- || check->fields.server->movetype == MOVETYPE_NOCLIP)
- continue;
-
- if (SV_TestEntityPosition (check, vec3_origin))
- Con_Print("entity in invalid position\n");
- }
-}
-