// (type *)STRUCT_FROM_LINK(link_t *link, type, member)
// ent = STRUCT_FROM_LINK(link,entity_t,order)
// FIXME: remove this mess!
-//#define STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (int)&(((t *)0)->m)))
+//#define STRUCT_FROM_LINK(l,t,m) ((t *)((qbyte *)l - (int)&(((t *)0)->m)))
-#define EDICT_FROM_AREA(l) ((edict_t *)((byte *)l - (int)&(((edict_t *)0)->area)))
+#define EDICT_FROM_AREA(l) ((edict_t *)((qbyte *)l - (int)&(((edict_t *)0)->area)))
//============================================================================
typedef struct
{
- vec3_t boxmins, boxmaxs;// enclose the test object along entire move
- float *mins, *maxs; // size of the moving object
- vec3_t mins2, maxs2; // size when clipping against mosnters
- float *start, *end;
+ // bounding box of entire move area
+ vec3_t boxmins, boxmaxs;
+
+ // size of the moving object
+ vec3_t mins, maxs;
+
+ // size when clipping against monsters
+ vec3_t mins2, maxs2;
+
+ // size when clipping against brush models
+ vec3_t hullmins, hullmaxs;
+
+ // start and end origin of move
+ vec3_t start, end;
+
+ // trace results
trace_t trace;
+
+ // type of move (like ignoring monsters, or similar)
int type;
+
+ // the edict that is moving (if any)
edict_t *passedict;
-} moveclip_t;
+}
+moveclip_t;
/*
for (i=0 ; i<6 ; i++)
{
box_clipnodes[i].planenum = i;
-
+
side = i&1;
-
+
box_clipnodes[i].children[side] = CONTENTS_EMPTY;
if (i != 5)
box_clipnodes[i].children[side^1] = i + 1;
else
box_clipnodes[i].children[side^1] = CONTENTS_SOLID;
-
+
box_planes[i].type = i>>1;
box_planes[i].normal[i>>1] = 1;
}
-
}
// decide which clipping hull to use, based on the size
if (ent->v.solid == SOLID_BSP)
- { // explicit hulls in the BSP model
+ {
+ // explicit hulls in the BSP model
if (ent->v.movetype != MOVETYPE_PUSH)
Host_Error ("SOLID_BSP without MOVETYPE_PUSH");
VectorSubtract (maxs, mins, size);
// LordHavoc: FIXME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- if (sv.worldmodel->ishlbsp)
+ if (model->ishlbsp)
{
if (size[0] < 3)
hull = &model->hulls[0]; // 0x0x0
return hull;
}
+void SV_RoundUpToHullSize(vec3_t inmins, vec3_t inmaxs, vec3_t outmins, vec3_t outmaxs)
+{
+ vec3_t size;
+ hull_t *hull;
+
+ VectorSubtract(inmaxs, inmins, size);
+ if (sv.worldmodel->ishlbsp)
+ {
+ if (size[0] < 3)
+ hull = &sv.worldmodel->hulls[0]; // 0x0x0
+ else if (size[0] <= 32)
+ {
+ if (size[2] < 54) // pick the nearest of 36 or 72
+ hull = &sv.worldmodel->hulls[3]; // 32x32x36
+ else
+ hull = &sv.worldmodel->hulls[1]; // 32x32x72
+ }
+ else
+ hull = &sv.worldmodel->hulls[2]; // 64x64x64
+ }
+ else
+ {
+ if (size[0] < 3)
+ hull = &sv.worldmodel->hulls[0]; // 0x0x0
+ else if (size[0] <= 32)
+ hull = &sv.worldmodel->hulls[1]; // 32x32x56
+ else
+ hull = &sv.worldmodel->hulls[2]; // 64x64x88
+ }
+ VectorCopy(inmins, outmins);
+ VectorAdd(inmins, hull->clip_size, outmaxs);
+}
+
/*
===============================================================================
*/
void SV_LinkEdict (edict_t *ent, qboolean touch_triggers)
{
+ model_t *model;
areanode_t *node;
if (ent->area.prev)
SV_UnlinkEdict (ent); // unlink from old position
-
+
if (ent == sv.edicts)
return; // don't add the world
// set the abs box
+ /*
// LordHavoc: enabling rotating bmodels
if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
{
if (max < v)
max = v;
max = sqrt(max);
+ */
/*
max = 0;
for (i=0 ; i<3 ; i++)
max = v;
}
*/
+ /*
for (i=0 ; i<3 ; i++)
{
ent->v.absmin[i] = ent->v.origin[i] - max;
VectorAdd (ent->v.origin, ent->v.mins, ent->v.absmin);
VectorAdd (ent->v.origin, ent->v.maxs, ent->v.absmax);
}
+ */
+
+ if (ent->v.solid == SOLID_BSP)
+ {
+ if (ent->v.modelindex < 0 || ent->v.modelindex > MAX_MODELS)
+ PR_RunError("SOLID_BSP with invalid modelindex!\n");
+ model = sv.models[(int) ent->v.modelindex];
+ if (model != NULL)
+ {
+ if (model->type != mod_brush)
+ PR_RunError("SOLID_BSP with non-BSP model\n");
+
+ if (ent->v.angles[0] || ent->v.angles[2] || ent->v.avelocity[0] || ent->v.avelocity[2])
+ {
+ VectorAdd(ent->v.origin, model->rotatedmins, ent->v.absmin);
+ VectorAdd(ent->v.origin, model->rotatedmaxs, ent->v.absmax);
+ }
+ else if (ent->v.angles[1] || ent->v.avelocity[1])
+ {
+ VectorAdd(ent->v.origin, model->yawmins, ent->v.absmin);
+ VectorAdd(ent->v.origin, model->yawmaxs, ent->v.absmax);
+ }
+ else
+ {
+ VectorAdd(ent->v.origin, model->normalmins, ent->v.absmin);
+ VectorAdd(ent->v.origin, model->normalmaxs, ent->v.absmax);
+ }
+ }
+ else
+ {
+ // SOLID_BSP with no model is valid, mainly because some QC setup code does so temporarily
+ VectorAdd (ent->v.origin, ent->v.mins, ent->v.absmin);
+ VectorAdd (ent->v.origin, ent->v.maxs, ent->v.absmax);
+ }
+ }
+ else
+ {
+ VectorAdd (ent->v.origin, ent->v.mins, ent->v.absmin);
+ VectorAdd (ent->v.origin, ent->v.maxs, ent->v.absmax);
+ }
//
// to make items easier to pick up and allow them to be grabbed off
{
ent->v.absmin[0] -= 15;
ent->v.absmin[1] -= 15;
+ ent->v.absmin[2] -= 1;
ent->v.absmax[0] += 15;
ent->v.absmax[1] += 15;
+ ent->v.absmax[2] += 1;
}
else
{
VectorSubtract(start, offset, startd);
VectorSubtract(end, offset, endd);
- // rotate start and end into the models frame of reference
+ // rotate start and end into the model's frame of reference
if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
{
AngleVectorsFLU (ent->v.angles, forward, left, up);
VectorAdd (trace.endpos, offset, trace.endpos);
trace.ent = ent;
}
- else if (trace.startsolid)
+ else if (trace.allsolid || trace.startsolid)
trace.ent = ent;
return trace;
edict_t *touch;
trace_t trace;
+loc0:
if (clip->trace.allsolid)
return;
-loc0:
// touch linked edicts
for (l = node->solid_edicts.next ; l != &node->solid_edicts ; l = next)
{
if (PROG_TO_EDICT(clip->passedict->v.owner) == touch)
continue; // don't clip against owner
// LordHavoc: corpse code
- if (clip->passedict->v.solid == SOLID_CORPSE && touch->v.solid == SOLID_SLIDEBOX)
+ if (clip->passedict->v.solid == SOLID_CORPSE && (touch->v.solid == SOLID_SLIDEBOX || touch->v.solid == SOLID_CORPSE))
continue;
if (clip->passedict->v.solid == SOLID_SLIDEBOX && touch->v.solid == SOLID_CORPSE)
continue;
// might interact, so do an exact clip
if ((int)touch->v.flags & FL_MONSTER)
trace = SV_ClipMoveToEntity (touch, clip->start, clip->mins2, clip->maxs2, clip->end);
+ else if (touch->v.solid == SOLID_BSP)
+ trace = SV_ClipMoveToEntity (touch, clip->start, clip->hullmins, clip->hullmaxs, clip->end);
else
trace = SV_ClipMoveToEntity (touch, clip->start, clip->mins, clip->maxs, clip->end);
- if (trace.allsolid || trace.startsolid || trace.fraction < clip->trace.fraction)
+ // LordHavoc: take the 'best' answers from the new trace and combine with existing data
+ if (trace.allsolid)
+ clip->trace.allsolid = true;
+ if (trace.startsolid)
{
- trace.ent = touch;
- if (clip->trace.startsolid)
+ clip->trace.startsolid = true;
+ if (!clip->trace.ent)
+ clip->trace.ent = trace.ent;
+ }
+ if (trace.inopen)
+ clip->trace.inopen = true;
+ if (trace.inwater)
+ clip->trace.inwater = true;
+ if (trace.fraction < clip->trace.fraction)
+ {
+ clip->trace.fraction = trace.fraction;
+ VectorCopy(trace.endpos, clip->trace.endpos);
+ clip->trace.plane = trace.plane;
+ clip->trace.endcontents = trace.endcontents;
+ clip->trace.ent = trace.ent;
+ }
+ /*
+ if (trace.allsolid)
+ {
+ clip->trace = trace;
+ return;
+ }
+ if (trace.startsolid || trace.fraction < clip->trace.fraction)
+ {
+ if (clip->trace.startsolid)
{
clip->trace = trace;
clip->trace.startsolid = true;
else
clip->trace = trace;
}
- if (clip->trace.allsolid)
- return;
+ */
}
// recurse down both sides
{
#if 0
// debug to test against everything
-boxmins[0] = boxmins[1] = boxmins[2] = -9999;
-boxmaxs[0] = boxmaxs[1] = boxmaxs[2] = 9999;
+boxmins[0] = boxmins[1] = boxmins[2] = -999999999;
+boxmaxs[0] = boxmaxs[1] = boxmaxs[2] = 999999999;
#else
int i;
trace_t SV_Move (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int type, edict_t *passedict)
{
moveclip_t clip;
+ vec3_t bigmins, bigmaxs;
int i;
memset ( &clip, 0, sizeof ( moveclip_t ) );
- clip.start = start;
- clip.end = end;
- clip.mins = mins;
- clip.maxs = maxs;
+ VectorCopy(start, clip.start);
+ VectorCopy(end, clip.end);
+ VectorCopy(mins, clip.mins);
+ VectorCopy(maxs, clip.maxs);
clip.type = type;
clip.passedict = passedict;
+ SV_RoundUpToHullSize(clip.mins, clip.maxs, clip.hullmins, clip.hullmaxs);
+
if (type == MOVE_MISSILE)
{
+ // LordHavoc: modified this, was = -15, now = clip.mins[i] - 15
for (i=0 ; i<3 ; i++)
{
- clip.mins2[i] = -15;
- clip.maxs2[i] = 15;
+ clip.mins2[i] = clip.mins[i] - 15;
+ clip.maxs2[i] = clip.maxs[i] + 15;
}
}
else
VectorCopy (clip.maxs, clip.maxs2);
}
+ bigmins[0] = min(clip.mins2[0], clip.hullmins[0]);
+ bigmaxs[0] = max(clip.maxs2[0], clip.hullmaxs[0]);
+ bigmins[1] = min(clip.mins2[1], clip.hullmins[1]);
+ bigmaxs[1] = max(clip.maxs2[1], clip.hullmaxs[1]);
+ bigmins[2] = min(clip.mins2[2], clip.hullmins[2]);
+ bigmaxs[2] = max(clip.maxs2[2], clip.hullmaxs[2]);
+
// clip to world
clip.trace = SV_ClipMoveToEntity (sv.edicts, start, mins, maxs, end);
// clip to entities
- if (!clip.trace.allsolid)
+ //if (!clip.trace.allsolid)
{
// create the bounding box of the entire move
- SV_MoveBounds ( start, clip.mins2, clip.maxs2, end, clip.boxmins, clip.boxmaxs );
+ SV_MoveBounds ( start, bigmins, bigmaxs, end, clip.boxmins, clip.boxmaxs );
SV_ClipToLinks ( sv_areanodes, &clip );
}