-void SV_UnlinkEdict (edict_t *ent)
-{
- if (!ent->area.prev)
- return; // not linked in anywhere
- RemoveLink (&ent->area);
- ent->area.prev = ent->area.next = NULL;
-}
-
-
-/*
-====================
-SV_TouchLinks
-====================
-*/
-void SV_TouchLinks ( edict_t *ent, areanode_t *node )
-{
- link_t *l, *next;
- edict_t *touch;
- int old_self, old_other;
-
-loc0:
-// touch linked edicts
- for (l = node->trigger_edicts.next ; l != &node->trigger_edicts ; l = next)
- {
- next = l->next;
- touch = EDICT_FROM_AREA(l);
- if (touch == ent)
- continue;
- if (!touch->v.touch || touch->v.solid != SOLID_TRIGGER)
- continue;
- if (ent->v.absmin[0] > touch->v.absmax[0]
- || ent->v.absmin[1] > touch->v.absmax[1]
- || ent->v.absmin[2] > touch->v.absmax[2]
- || ent->v.absmax[0] < touch->v.absmin[0]
- || ent->v.absmax[1] < touch->v.absmin[1]
- || ent->v.absmax[2] < touch->v.absmin[2] )
- continue;
- old_self = pr_global_struct->self;
- old_other = pr_global_struct->other;
-
- pr_global_struct->self = EDICT_TO_PROG(touch);
- pr_global_struct->other = EDICT_TO_PROG(ent);
- pr_global_struct->time = sv.time;
- PR_ExecuteProgram (touch->v.touch);
-
- pr_global_struct->self = old_self;
- pr_global_struct->other = old_other;
- }
-
-// recurse down both sides
- if (node->axis == -1)
- return;
-
- // LordHavoc: optimized recursion
-// if (ent->v.absmax[node->axis] > node->dist) SV_TouchLinks (ent, node->children[0]);
-// if (ent->v.absmin[node->axis] < node->dist) SV_TouchLinks (ent, node->children[1]);
- if (ent->v.absmax[node->axis] > node->dist)
- {
- if (ent->v.absmin[node->axis] < node->dist)
- SV_TouchLinks(ent, node->children[1]); // order reversed to reduce code
- node = node->children[0];
- goto loc0;
- }
- else
- {
- if (ent->v.absmin[node->axis] < node->dist)
- {
- node = node->children[1];
- goto loc0;
- }
- }
-}
-
-
-/*
-===============
-SV_FindTouchedLeafs
-
-===============
-*/
-void SV_FindTouchedLeafs (edict_t *ent, mnode_t *node)
-{
- mplane_t *splitplane;
- mleaf_t *leaf;
- int sides;
- int leafnum;
-
-loc0:
- if (node->contents == CONTENTS_SOLID)
- return;
-
-// add an efrag if the node is a leaf
-
- if ( node->contents < 0)
- {
- if (ent->num_leafs == MAX_ENT_LEAFS)
- {
- Con_DPrintf("FindTouchedLeafs overflow\n");
- return;
- }
-
- leaf = (mleaf_t *)node;
- leafnum = leaf - sv.worldmodel->leafs - 1;
-
- ent->leafnums[ent->num_leafs] = leafnum;
- ent->num_leafs++;
- return;
- }
-
-// NODE_MIXED
-
- splitplane = node->plane;
- sides = BOX_ON_PLANE_SIDE(ent->v.absmin, ent->v.absmax, splitplane);
-
-// recurse down the contacted sides
- // LordHavoc: optimized recursion
-// if (sides & 1) SV_FindTouchedLeafs (ent, node->children[0]);
-// if (sides & 2) SV_FindTouchedLeafs (ent, node->children[1]);
- switch (sides)
- {
- case 1:
- node = node->children[0];
- goto loc0;
- case 2:
- node = node->children[1];
- goto loc0;
- default: // 3
- if (node->children[0]->contents != CONTENTS_SOLID)
- SV_FindTouchedLeafs (ent, node->children[0]);
- node = node->children[1];
- goto loc0;
- }
-}
-
-/*
-===============
-SV_LinkEdict
-
-===============
-*/
-void SV_LinkEdict (edict_t *ent, qboolean touch_triggers)
-{
- areanode_t *node;
-
- if (ent->area.prev)
- SV_UnlinkEdict (ent); // unlink from old position
-
- if (ent == sv.edicts)
- return; // don't add the world
-
- if (ent->free)
- return;
-
-// 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]))
- { // expand for rotation
- float max, v;
- int i;
-
- max = DotProduct(ent->v.mins, ent->v.mins);
- v = DotProduct(ent->v.maxs, ent->v.maxs);
- if (max < v)
- max = v;
- max = sqrt(max);
- /*
- max = 0;
- for (i=0 ; i<3 ; i++)
- {
- v = fabs(ent->v.mins[i]);
- if (max < v)
- max = v;
- v = fabs(ent->v.maxs[i]);
- if (max < v)
- max = v;
- }
- */
- for (i=0 ; i<3 ; i++)
- {
- ent->v.absmin[i] = ent->v.origin[i] - max;
- ent->v.absmax[i] = ent->v.origin[i] + max;
- }
- }
- 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
-// of shelves, the abs sizes are expanded
-//
- if ((int)ent->v.flags & FL_ITEM)
- {
- ent->v.absmin[0] -= 15;
- ent->v.absmin[1] -= 15;
- ent->v.absmax[0] += 15;
- ent->v.absmax[1] += 15;
- }
- else
- { // because movement is clipped an epsilon away from an actual edge,
- // we must fully check even when bounding boxes don't quite touch
- ent->v.absmin[0] -= 1;
- ent->v.absmin[1] -= 1;
- ent->v.absmin[2] -= 1;
- ent->v.absmax[0] += 1;
- ent->v.absmax[1] += 1;
- ent->v.absmax[2] += 1;
- }
-
-// link to PVS leafs
- ent->num_leafs = 0;
- if (ent->v.modelindex)
- SV_FindTouchedLeafs (ent, sv.worldmodel->nodes);
-
- if (ent->v.solid == SOLID_NOT)
- return;
-
-// find the first node that the ent's box crosses
- node = sv_areanodes;
- while (1)
- {
- if (node->axis == -1)
- break;
- if (ent->v.absmin[node->axis] > node->dist)
- node = node->children[0];
- else if (ent->v.absmax[node->axis] < node->dist)
- node = node->children[1];
- else
- break; // crosses the node
- }
-
-// link it in
-
- if (ent->v.solid == SOLID_TRIGGER)
- InsertLinkBefore (&ent->area, &node->trigger_edicts);
- else
- InsertLinkBefore (&ent->area, &node->solid_edicts);
-
-// if touch_triggers, touch all entities at this node and descend for more
- if (touch_triggers)
- SV_TouchLinks ( ent, sv_areanodes );
-}
-
-
-
-/*
-===============================================================================
-
-POINT TESTING IN HULLS
-
-===============================================================================
-*/
-
-// SV_HullPointContents moved to cpu_noasm.c
-
-/*
-============
-SV_TestEntityPosition
-
-This could be a lot more efficient...
-============
-*/
-edict_t *SV_TestEntityPosition (edict_t *ent)
-{
- trace_t trace;
-
- trace = SV_Move (ent->v.origin, ent->v.mins, ent->v.maxs, ent->v.origin, 0, ent);
-
- if (trace.startsolid)
- return sv.edicts;
-
- return NULL;
-}
-
-
-/*
-===============================================================================
-
-LINE TESTING IN HULLS
-
-===============================================================================
-*/
-
-// 1/32 epsilon to keep floating point happy
-#define DIST_EPSILON (0.03125)
-
-/*
-==================
-SV_RecursiveHullCheck
-
-==================
-*/
-/*
-qboolean SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, trace_t *trace)