-/*
-============
-SV_TestEntityPosition
-
-returns true if the entity is in solid currently
-============
-*/
-static int SV_TestEntityPosition (prvm_edict_t *ent, vec3_t offset)
-{
- prvm_prog_t *prog = SVVM_prog;
- int contents;
- vec3_t org;
- trace_t trace;
- contents = SV_GenericHitSuperContentsMask(ent);
- VectorAdd(PRVM_serveredictvector(ent, origin), offset, org);
- trace = SV_TraceBox(org, PRVM_serveredictvector(ent, mins), PRVM_serveredictvector(ent, maxs), PRVM_serveredictvector(ent, origin), ((PRVM_serveredictfloat(ent, movetype) == MOVETYPE_FLY_WORLDONLY) ? MOVE_WORLDONLY : MOVE_NOMONSTERS), ent, contents);
- if (trace.startsupercontents & contents)
- return true;
- else
- {
- if (sv.worldmodel->brushq1.numclipnodes && !VectorCompare(PRVM_serveredictvector(ent, mins), PRVM_serveredictvector(ent, 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, PRVM_serveredictvector(ent, mins), m1);
- VectorAdd(org, PRVM_serveredictvector(ent, 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, PRVM_serveredictvector(ent, origin)) >= 0.0001)
- {
-#if 0
- // please switch back to this code when trace.endpos sometimes being in solid bug is fixed
- VectorCopy(trace.endpos, PRVM_serveredictvector(ent, origin));
-#else
- // verify if the endpos is REALLY outside solid
- VectorCopy(trace.endpos, org);
- trace = SV_TraceBox(org, PRVM_serveredictvector(ent, mins), PRVM_serveredictvector(ent, 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, PRVM_serveredictvector(ent, origin));
-#endif
- }
- return false;
-}
-