2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // world.c -- world query functions
26 entities never clip against themselves, or their owner
28 line of sight checks trace->inopen and trace->inwater, but bullets don't
32 cvar_t sv_debugmove = {CVAR_NOTIFY, "sv_debugmove", "0"};
33 cvar_t sv_areagrid_mingridsize = {CVAR_NOTIFY, "sv_areagrid_mingridsize", "64"};
35 void SV_AreaStats_f(void);
37 void SV_World_Init(void)
39 Cvar_RegisterVariable(&sv_debugmove);
40 Cvar_RegisterVariable(&sv_areagrid_mingridsize);
41 Cmd_AddCommand("sv_areastats", SV_AreaStats_f);
47 // bounding box of entire move area
48 vec3_t boxmins, boxmaxs;
50 // size of the moving object
53 // size when clipping against monsters
56 // start and end origin of move
62 // type of move (like ignoring monsters, or similar)
65 // the edict that is moving (if any)
70 //============================================================================
72 // ClearLink is used for new headnodes
73 static void ClearLink (link_t *l)
76 l->prev = l->next = l;
79 static void RemoveLink (link_t *l)
81 l->next->prev = l->prev;
82 l->prev->next = l->next;
85 static void InsertLinkBefore (link_t *l, link_t *before, int entitynumber)
87 l->entitynumber = entitynumber;
89 l->prev = before->prev;
96 ===============================================================================
100 ===============================================================================
103 int sv_areagrid_stats_calls = 0;
104 int sv_areagrid_stats_nodechecks = 0;
105 int sv_areagrid_stats_entitychecks = 0;
107 void SV_AreaStats_f(void)
109 Con_Printf("areagrid check stats: %d calls %d nodes (%f per call) %d entities (%f per call)\n", sv_areagrid_stats_calls, sv_areagrid_stats_nodechecks, (double) sv_areagrid_stats_nodechecks / (double) sv_areagrid_stats_calls, sv_areagrid_stats_entitychecks, (double) sv_areagrid_stats_entitychecks / (double) sv_areagrid_stats_calls);
110 sv_areagrid_stats_calls = 0;
111 sv_areagrid_stats_nodechecks = 0;
112 sv_areagrid_stats_entitychecks = 0;
115 typedef struct areagrid_s
117 link_t trigger_edicts;
122 #define AREA_GRID 512
123 #define AREA_GRIDNODES (AREA_GRID * AREA_GRID)
125 static areagrid_t sv_areagrid[AREA_GRIDNODES], sv_areagrid_outside;
126 static vec3_t sv_areagrid_bias, sv_areagrid_scale, sv_areagrid_mins, sv_areagrid_maxs, sv_areagrid_size;
127 static int sv_areagrid_marknumber = 1;
129 void SV_CreateAreaGrid (vec3_t mins, vec3_t maxs)
132 ClearLink (&sv_areagrid_outside.trigger_edicts);
133 ClearLink (&sv_areagrid_outside.solid_edicts);
134 // choose either the world box size, or a larger box to ensure the grid isn't too fine
135 sv_areagrid_size[0] = max(maxs[0] - mins[0], AREA_GRID * sv_areagrid_mingridsize.value);
136 sv_areagrid_size[1] = max(maxs[1] - mins[1], AREA_GRID * sv_areagrid_mingridsize.value);
137 sv_areagrid_size[2] = max(maxs[2] - mins[2], AREA_GRID * sv_areagrid_mingridsize.value);
138 // figure out the corners of such a box, centered at the center of the world box
139 sv_areagrid_mins[0] = (mins[0] + maxs[0] - sv_areagrid_size[0]) * 0.5f;
140 sv_areagrid_mins[1] = (mins[1] + maxs[1] - sv_areagrid_size[1]) * 0.5f;
141 sv_areagrid_mins[2] = (mins[2] + maxs[2] - sv_areagrid_size[2]) * 0.5f;
142 sv_areagrid_maxs[0] = (mins[0] + maxs[0] + sv_areagrid_size[0]) * 0.5f;
143 sv_areagrid_maxs[1] = (mins[1] + maxs[1] + sv_areagrid_size[1]) * 0.5f;
144 sv_areagrid_maxs[2] = (mins[2] + maxs[2] + sv_areagrid_size[2]) * 0.5f;
145 // now calculate the actual useful info from that
146 VectorNegate(sv_areagrid_mins, sv_areagrid_bias);
147 sv_areagrid_scale[0] = AREA_GRID / sv_areagrid_size[0];
148 sv_areagrid_scale[1] = AREA_GRID / sv_areagrid_size[1];
149 sv_areagrid_scale[2] = AREA_GRID / sv_areagrid_size[2];
150 for (i = 0;i < AREA_GRIDNODES;i++)
152 ClearLink (&sv_areagrid[i].trigger_edicts);
153 ClearLink (&sv_areagrid[i].solid_edicts);
155 Con_DPrintf("sv_areagrid settings: divisions %ix%ix1 : box %f %f %f : %f %f %f size %f %f %f grid %f %f %f (mingrid %f)\n", AREA_GRID, AREA_GRID, sv_areagrid_mins[0], sv_areagrid_mins[1], sv_areagrid_mins[2], sv_areagrid_maxs[0], sv_areagrid_maxs[1], sv_areagrid_maxs[2], sv_areagrid_size[0], sv_areagrid_size[1], sv_areagrid_size[2], 1.0f / sv_areagrid_scale[0], 1.0f / sv_areagrid_scale[1], 1.0f / sv_areagrid_scale[2], sv_areagrid_mingridsize.value);
164 void SV_ClearWorld (void)
166 Mod_CheckLoaded(sv.worldmodel);
167 SV_CreateAreaGrid(sv.worldmodel->normalmins, sv.worldmodel->normalmaxs);
177 void SV_UnlinkEdict (edict_t *ent)
180 for (i = 0;i < ENTITYGRIDAREAS;i++)
182 if (ent->e->areagrid[i].prev)
184 RemoveLink (&ent->e->areagrid[i]);
185 ent->e->areagrid[i].prev = ent->e->areagrid[i].next = NULL;
191 void SV_TouchAreaGrid(edict_t *ent)
196 int old_self, old_other, igrid[3], igridmins[3], igridmaxs[3];
197 int i, numtouchedicts;
198 unsigned short touchedictnumbers[MAX_EDICTS];
200 sv_areagrid_marknumber++;
201 igridmins[0] = (int) ((ent->v->absmin[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]);
202 igridmins[1] = (int) ((ent->v->absmin[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]);
203 //igridmins[2] = (int) ((ent->v->absmin[2] + sv_areagrid_bias[2]) * sv_areagrid_scale[2]);
204 igridmaxs[0] = (int) ((ent->v->absmax[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]) + 1;
205 igridmaxs[1] = (int) ((ent->v->absmax[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]) + 1;
206 //igridmaxs[2] = (int) ((ent->v->absmax[2] + sv_areagrid_bias[2]) * sv_areagrid_scale[2]) + 1;
207 igridmins[0] = max(0, igridmins[0]);
208 igridmins[1] = max(0, igridmins[1]);
209 //igridmins[2] = max(0, igridmins[2]);
210 igridmaxs[0] = min(AREA_GRID, igridmaxs[0]);
211 igridmaxs[1] = min(AREA_GRID, igridmaxs[1]);
212 //igridmaxs[2] = min(AREA_GRID, igridmaxs[2]);
214 // build a list of edicts to touch, because the link loop can be corrupted
215 // by SV_IncreaseEdicts called during touch functions
217 for (l = sv_areagrid_outside.trigger_edicts.next;l != &sv_areagrid_outside.trigger_edicts;l = l->next)
218 touchedictnumbers[numtouchedicts++] = l->entitynumber;
220 for (igrid[1] = igridmins[1];igrid[1] < igridmaxs[1];igrid[1]++)
222 grid = sv_areagrid + igrid[1] * AREA_GRID + igridmins[0];
223 for (igrid[0] = igridmins[0];igrid[0] < igridmaxs[0];igrid[0]++, grid++)
224 for (l = grid->trigger_edicts.next;l != &grid->trigger_edicts;l = l->next)
225 touchedictnumbers[numtouchedicts++] = l->entitynumber;
228 old_self = pr_global_struct->self;
229 old_other = pr_global_struct->other;
230 for (i = 0;i < numtouchedicts && !ent->e->free;i++)
232 touch = EDICT_NUM_UNSIGNED(touchedictnumbers[i]);
233 if (ent->v->absmin[0] > touch->v->absmax[0]
234 || ent->v->absmax[0] < touch->v->absmin[0]
235 || ent->v->absmin[1] > touch->v->absmax[1]
236 || ent->v->absmax[1] < touch->v->absmin[1]
237 || ent->v->absmin[2] > touch->v->absmax[2]
238 || ent->v->absmax[2] < touch->v->absmin[2])
242 if (!touch->v->touch || touch->v->solid != SOLID_TRIGGER)
244 pr_global_struct->self = EDICT_TO_PROG(touch);
245 pr_global_struct->other = EDICT_TO_PROG(ent);
246 pr_global_struct->time = sv.time;
247 PR_ExecuteProgram (touch->v->touch, "");
249 pr_global_struct->self = old_self;
250 pr_global_struct->other = old_other;
253 void SV_LinkEdict_AreaGrid(edict_t *ent)
256 int igrid[3], igridmins[3], igridmaxs[3], gridnum, entitynumber = NUM_FOR_EDICT(ent);
258 if (entitynumber <= 0 || entitynumber >= sv.max_edicts || EDICT_NUM(entitynumber) != ent)
259 Host_Error("SV_LinkEdict_AreaGrid: invalid edict %p (sv.edicts is %p, edict compared to sv.edicts is %i)\n", ent, sv.edicts, entitynumber);
261 igridmins[0] = (int) ((ent->v->absmin[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]);
262 igridmins[1] = (int) ((ent->v->absmin[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]);
263 //igridmins[2] = (int) ((ent->v->absmin[2] + sv_areagrid_bias[2]) * sv_areagrid_scale[2]);
264 igridmaxs[0] = (int) ((ent->v->absmax[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]) + 1;
265 igridmaxs[1] = (int) ((ent->v->absmax[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]) + 1;
266 //igridmaxs[2] = (int) ((ent->v->absmax[2] + sv_areagrid_bias[2]) * sv_areagrid_scale[2]) + 1;
267 if (igridmins[0] < 0 || igridmaxs[0] > AREA_GRID || igridmins[1] < 0 || igridmaxs[1] > AREA_GRID || ((igridmaxs[0] - igridmins[0]) * (igridmaxs[1] - igridmins[1])) > ENTITYGRIDAREAS)
269 // wow, something outside the grid, store it as such
270 if (ent->v->solid == SOLID_TRIGGER)
271 InsertLinkBefore (&ent->e->areagrid[0], &sv_areagrid_outside.trigger_edicts, entitynumber);
273 InsertLinkBefore (&ent->e->areagrid[0], &sv_areagrid_outside.solid_edicts, entitynumber);
278 for (igrid[1] = igridmins[1];igrid[1] < igridmaxs[1];igrid[1]++)
280 grid = sv_areagrid + igrid[1] * AREA_GRID + igridmins[0];
281 for (igrid[0] = igridmins[0];igrid[0] < igridmaxs[0];igrid[0]++, grid++, gridnum++)
283 if (ent->v->solid == SOLID_TRIGGER)
284 InsertLinkBefore (&ent->e->areagrid[gridnum], &grid->trigger_edicts, entitynumber);
286 InsertLinkBefore (&ent->e->areagrid[gridnum], &grid->solid_edicts, entitynumber);
297 void SV_LinkEdict (edict_t *ent, qboolean touch_triggers)
301 if (ent->e->areagrid[0].prev)
302 SV_UnlinkEdict (ent); // unlink from old position
304 if (ent == sv.edicts)
305 return; // don't add the world
312 if (ent->v->solid == SOLID_BSP)
314 int modelindex = ent->v->modelindex;
315 if (modelindex < 0 || modelindex > MAX_MODELS)
317 Con_DPrintf("edict %i: SOLID_BSP with invalid modelindex!\n", NUM_FOR_EDICT(ent));
320 model = sv.models[modelindex];
323 Mod_CheckLoaded(model);
324 if (!model->TraceBox)
325 Con_DPrintf("edict %i: SOLID_BSP with non-collidable model\n", NUM_FOR_EDICT(ent));
327 if (ent->v->angles[0] || ent->v->angles[2] || ent->v->avelocity[0] || ent->v->avelocity[2])
329 VectorAdd(ent->v->origin, model->rotatedmins, ent->v->absmin);
330 VectorAdd(ent->v->origin, model->rotatedmaxs, ent->v->absmax);
332 else if (ent->v->angles[1] || ent->v->avelocity[1])
334 VectorAdd(ent->v->origin, model->yawmins, ent->v->absmin);
335 VectorAdd(ent->v->origin, model->yawmaxs, ent->v->absmax);
339 VectorAdd(ent->v->origin, model->normalmins, ent->v->absmin);
340 VectorAdd(ent->v->origin, model->normalmaxs, ent->v->absmax);
345 // SOLID_BSP with no model is valid, mainly because some QC setup code does so temporarily
346 VectorAdd(ent->v->origin, ent->v->mins, ent->v->absmin);
347 VectorAdd(ent->v->origin, ent->v->maxs, ent->v->absmax);
352 VectorAdd(ent->v->origin, ent->v->mins, ent->v->absmin);
353 VectorAdd(ent->v->origin, ent->v->maxs, ent->v->absmax);
357 // to make items easier to pick up and allow them to be grabbed off
358 // of shelves, the abs sizes are expanded
360 if ((int)ent->v->flags & FL_ITEM)
362 ent->v->absmin[0] -= 15;
363 ent->v->absmin[1] -= 15;
364 ent->v->absmin[2] -= 1;
365 ent->v->absmax[0] += 15;
366 ent->v->absmax[1] += 15;
367 ent->v->absmax[2] += 1;
371 // because movement is clipped an epsilon away from an actual edge,
372 // we must fully check even when bounding boxes don't quite touch
373 ent->v->absmin[0] -= 1;
374 ent->v->absmin[1] -= 1;
375 ent->v->absmin[2] -= 1;
376 ent->v->absmax[0] += 1;
377 ent->v->absmax[1] += 1;
378 ent->v->absmax[2] += 1;
381 if (ent->v->solid == SOLID_NOT)
384 SV_LinkEdict_AreaGrid(ent);
386 // if touch_triggers, touch all entities at this node and descend for more
388 SV_TouchAreaGrid(ent);
394 ===============================================================================
396 POINT TESTING IN HULLS
398 ===============================================================================
403 SV_TestEntityPosition
405 This could be a lot more efficient...
408 int SV_TestEntityPosition (edict_t *ent)
410 return SV_Move (ent->v->origin, ent->v->mins, ent->v->maxs, ent->v->origin, MOVE_NORMAL, ent).startsolid;
415 ===============================================================================
417 LINE TESTING IN HULLS
419 ===============================================================================
426 Handles selection or creation of a clipping hull, and offseting (and
427 eventually rotation) of the end points
430 trace_t SV_ClipMoveToEntity(edict_t *ent, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int movetype)
433 model_t *model = NULL;
434 matrix4x4_t matrix, imatrix;
435 float tempnormal[3], starttransformed[3], endtransformed[3];
436 float starttransformedmins[3], starttransformedmaxs[3], endtransformedmins[3], endtransformedmaxs[3];
438 memset(&trace, 0, sizeof(trace));
439 trace.fraction = trace.realfraction = 1;
440 VectorCopy(end, trace.endpos);
442 if ((int) ent->v->solid == SOLID_BSP || movetype == MOVE_HITMODEL)
444 unsigned int modelindex = ent->v->modelindex;
445 // if the modelindex is 0, it shouldn't be SOLID_BSP!
448 Con_DPrintf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with no model\n", NUM_FOR_EDICT(ent));
451 if (modelindex >= MAX_MODELS)
453 Con_DPrintf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with invalid modelindex\n", NUM_FOR_EDICT(ent));
456 model = sv.models[modelindex];
457 if (modelindex != 0 && model == NULL)
459 Con_DPrintf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with invalid modelindex\n", NUM_FOR_EDICT(ent));
463 Mod_CheckLoaded(model);
464 if ((int) ent->v->solid == SOLID_BSP)
466 if (!model->TraceBox)
468 Con_DPrintf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with a non-collidable model\n", NUM_FOR_EDICT(ent));
471 //if (ent->v->movetype != MOVETYPE_PUSH)
473 // Con_DPrintf("SV_ClipMoveToEntity: edict %i: SOLID_BSP without MOVETYPE_PUSH\n", NUM_FOR_EDICT(ent));
477 Matrix4x4_CreateFromQuakeEntity(&matrix, ent->v->origin[0], ent->v->origin[1], ent->v->origin[2], ent->v->angles[0], ent->v->angles[1], ent->v->angles[2], 1);
480 Matrix4x4_CreateTranslate(&matrix, ent->v->origin[0], ent->v->origin[1], ent->v->origin[2]);
482 Matrix4x4_Invert_Simple(&imatrix, &matrix);
483 Matrix4x4_Transform(&imatrix, start, starttransformed);
484 Matrix4x4_Transform(&imatrix, end, endtransformed);
485 #if COLLISIONPARANOID >= 3
486 Con_Printf("trans(%f %f %f -> %f %f %f, %f %f %f -> %f %f %f)", start[0], start[1], start[2], starttransformed[0], starttransformed[1], starttransformed[2], end[0], end[1], end[2], endtransformed[0], endtransformed[1], endtransformed[2]);
489 if (model && model->TraceBox)
492 frame = (int)ent->v->frame;
493 frame = bound(0, frame, (model->numframes - 1));
494 VectorAdd(starttransformed, maxs, starttransformedmaxs);
495 VectorAdd(endtransformed, maxs, endtransformedmaxs);
496 VectorAdd(starttransformed, mins, starttransformedmins);
497 VectorAdd(endtransformed, mins, endtransformedmins);
498 model->TraceBox(model, frame, &trace, starttransformedmins, starttransformedmaxs, endtransformedmins, endtransformedmaxs, SUPERCONTENTS_SOLID);
501 Collision_ClipTrace_Box(&trace, ent->v->mins, ent->v->maxs, starttransformed, mins, maxs, endtransformed, SUPERCONTENTS_SOLID, SUPERCONTENTS_SOLID);
503 if (trace.fraction < 1)
505 VectorLerp(start, trace.fraction, end, trace.endpos);
506 VectorCopy(trace.plane.normal, tempnormal);
507 Matrix4x4_Transform3x3(&matrix, tempnormal, trace.plane.normal);
508 // FIXME: should recalc trace.plane.dist
511 VectorCopy(end, trace.endpos);
516 //===========================================================================
518 void SV_ClipToNode(moveclip_t *clip, link_t *list)
524 sv_areagrid_stats_nodechecks++;
525 for (l = list->next;l != list;l = next)
528 touch = EDICT_NUM(l->entitynumber);
529 if (touch->e->areagridmarknumber == sv_areagrid_marknumber)
531 touch->e->areagridmarknumber = sv_areagrid_marknumber;
532 sv_areagrid_stats_entitychecks++;
534 // LordHavoc: this box comparison isn't much use with the high resolution areagrid
536 if (clip->boxmins[0] > touch->v->absmax[0]
537 || clip->boxmaxs[0] < touch->v->absmin[0]
538 || clip->boxmins[1] > touch->v->absmax[1]
539 || clip->boxmaxs[1] < touch->v->absmin[1]
540 || clip->boxmins[2] > touch->v->absmax[2]
541 || clip->boxmaxs[2] < touch->v->absmin[2])
545 if (clip->type == MOVE_NOMONSTERS && touch->v->solid != SOLID_BSP)
548 if (touch->v->solid == SOLID_NOT)
553 if (touch == clip->passedict)
555 if (!clip->passedict->v->size[0] && !touch->v->size[0])
556 continue; // points never interact
557 if (PROG_TO_EDICT(touch->v->owner) == clip->passedict)
558 continue; // don't clip against own missiles
559 if (PROG_TO_EDICT(clip->passedict->v->owner) == touch)
560 continue; // don't clip against owner
561 // LordHavoc: corpse code
562 if (clip->passedict->v->solid == SOLID_CORPSE && (touch->v->solid == SOLID_SLIDEBOX || touch->v->solid == SOLID_CORPSE))
564 if (clip->passedict->v->solid == SOLID_SLIDEBOX && touch->v->solid == SOLID_CORPSE)
568 if (touch->v->solid == SOLID_TRIGGER)
571 Host_Error ("Trigger in clipping list");
574 // might interact, so do an exact clip
575 if ((int)touch->v->flags & FL_MONSTER)
576 trace = SV_ClipMoveToEntity(touch, clip->start, clip->mins2, clip->maxs2, clip->end, clip->type);
578 trace = SV_ClipMoveToEntity(touch, clip->start, clip->mins, clip->maxs, clip->end, clip->type);
579 // LordHavoc: take the 'best' answers from the new trace and combine with existing data
581 clip->trace.allsolid = true;
582 if (trace.startsolid)
584 clip->trace.startsolid = true;
585 if (clip->trace.realfraction == 1)
586 clip->trace.ent = touch;
588 // don't set this except on the world, because it can easily confuse
589 // monsters underwater if there's a bmodel involved in the trace
590 // (inopen && inwater is how they check water visibility)
592 // clip->trace.inopen = true;
594 clip->trace.inwater = true;
595 if (trace.realfraction < clip->trace.realfraction)
597 clip->trace.fraction = trace.fraction;
598 clip->trace.realfraction = trace.realfraction;
599 VectorCopy(trace.endpos, clip->trace.endpos);
600 clip->trace.plane = trace.plane;
601 clip->trace.ent = touch;
603 clip->trace.startsupercontents |= trace.startsupercontents;
612 #if COLLISIONPARANOID >= 1
613 trace_t SV_Move_(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, edict_t *passedict)
615 trace_t SV_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, edict_t *passedict)
619 vec3_t hullmins, hullmaxs;
621 int i, igrid[3], igridmins[3], igridmaxs[3];
623 // if the passedict is world, make it NULL (to avoid two checks each time)
624 if (passedict == sv.edicts)
627 memset(&clip, 0, sizeof(moveclip_t));
629 VectorCopy(start, clip.start);
630 VectorCopy(end, clip.end);
631 VectorCopy(mins, clip.mins);
632 VectorCopy(maxs, clip.maxs);
633 VectorCopy(mins, clip.mins2);
634 VectorCopy(maxs, clip.maxs2);
636 clip.passedict = passedict;
637 #if COLLISIONPARANOID >= 3
638 Con_Printf("move(%f %f %f,%f %f %f)", clip.start[0], clip.start[1], clip.start[2], clip.end[0], clip.end[1], clip.end[2]);
642 clip.trace = SV_ClipMoveToEntity(sv.edicts, clip.start, clip.mins, clip.maxs, clip.end, clip.type);
643 if (clip.trace.startsolid || clip.trace.fraction < 1)
644 clip.trace.ent = sv.edicts;
645 if (clip.type == MOVE_WORLDONLY)
648 if (clip.type == MOVE_MISSILE)
650 // LordHavoc: modified this, was = -15, now -= 15
651 for (i = 0;i < 3;i++)
658 // get adjusted box for bmodel collisions if the world is q1bsp or hlbsp
659 if (sv.worldmodel && sv.worldmodel->brush.RoundUpToHullSize)
660 sv.worldmodel->brush.RoundUpToHullSize(sv.worldmodel, clip.mins, clip.maxs, hullmins, hullmaxs);
663 VectorCopy(clip.mins, hullmins);
664 VectorCopy(clip.maxs, hullmaxs);
667 // create the bounding box of the entire move
668 for (i = 0;i < 3;i++)
670 clip.boxmins[i] = min(clip.start[i], clip.trace.endpos[i]) + min(hullmins[i], clip.mins2[i]) - 1;
671 clip.boxmaxs[i] = max(clip.start[i], clip.trace.endpos[i]) + max(hullmaxs[i], clip.maxs2[i]) + 1;
674 // debug override to test against everything
675 if (sv_debugmove.integer)
677 clip.boxmins[0] = clip.boxmins[1] = clip.boxmins[2] = -999999999;
678 clip.boxmaxs[0] = clip.boxmaxs[1] = clip.boxmaxs[2] = 999999999;
682 sv_areagrid_stats_calls++;
683 sv_areagrid_marknumber++;
684 igridmins[0] = (int) ((clip.boxmins[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]);
685 igridmins[1] = (int) ((clip.boxmins[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]);
686 //igridmins[2] = (int) ((clip->boxmins[2] + sv_areagrid_bias[2]) * sv_areagrid_scale[2]);
687 igridmaxs[0] = (int) ((clip.boxmaxs[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]) + 1;
688 igridmaxs[1] = (int) ((clip.boxmaxs[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]) + 1;
689 //igridmaxs[2] = (int) ((clip->boxmaxs[2] + sv_areagrid_bias[2]) * sv_areagrid_scale[2]) + 1;
690 igridmins[0] = max(0, igridmins[0]);
691 igridmins[1] = max(0, igridmins[1]);
692 //igridmins[2] = max(0, igridmins[2]);
693 igridmaxs[0] = min(AREA_GRID, igridmaxs[0]);
694 igridmaxs[1] = min(AREA_GRID, igridmaxs[1]);
695 //igridmaxs[2] = min(AREA_GRID, igridmaxs[2]);
697 if (sv_areagrid_outside.solid_edicts.next != &sv_areagrid_outside.solid_edicts)
698 SV_ClipToNode(&clip, &sv_areagrid_outside.solid_edicts);
700 for (igrid[1] = igridmins[1];igrid[1] < igridmaxs[1];igrid[1]++)
701 for (grid = sv_areagrid + igrid[1] * AREA_GRID + igridmins[0], igrid[0] = igridmins[0];igrid[0] < igridmaxs[0];igrid[0]++, grid++)
702 if (grid->solid_edicts.next != &grid->solid_edicts)
703 SV_ClipToNode(&clip, &grid->solid_edicts);
708 #if COLLISIONPARANOID >= 1
709 trace_t SV_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, edict_t *passedict)
714 trace = SV_Move_(start, mins, maxs, end, type, passedict);
717 VectorCopy(trace.endpos, temp);
718 endstuck = SV_Move_(temp, mins, maxs, temp, type, passedict).startsolid;
719 #if COLLISIONPARANOID < 3
720 if (trace.startsolid || endstuck)
722 Con_Printf("%s{e%i:%f %f %f:%f %f %f:%f:%f %f %f%s%s}\n", (trace.startsolid || endstuck) ? "\002" : "", passedict ? passedict - sv.edicts : -1, passedict->v->origin[0], passedict->v->origin[1], passedict->v->origin[2], end[0] - passedict->v->origin[0], end[1] - passedict->v->origin[1], end[2] - passedict->v->origin[2], trace.fraction, trace.endpos[0] - passedict->v->origin[0], trace.endpos[1] - passedict->v->origin[1], trace.endpos[2] - passedict->v->origin[2], trace.startsolid ? " startstuck" : "", endstuck ? " endstuck" : "");
728 int SV_PointSuperContents(const vec3_t point)
730 return SV_Move(point, vec3_origin, vec3_origin, point, sv_gameplayfix_swiminbmodels.integer ? MOVE_NOMONSTERS : MOVE_WORLDONLY, NULL).startsupercontents;
733 int SV_PointQ1Contents(const vec3_t point)
735 return Mod_Q1BSP_NativeContentsFromSuperContents(NULL, SV_PointSuperContents(point));