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);
45 //============================================================================
47 // ClearLink is used for new headnodes
48 static void ClearLink (link_t *l)
51 l->prev = l->next = l;
54 static void RemoveLink (link_t *l)
56 l->next->prev = l->prev;
57 l->prev->next = l->next;
60 static void InsertLinkBefore (link_t *l, link_t *before, int entitynumber)
62 l->entitynumber = entitynumber;
64 l->prev = before->prev;
71 ===============================================================================
75 ===============================================================================
78 int sv_areagrid_stats_calls = 0;
79 int sv_areagrid_stats_nodechecks = 0;
80 int sv_areagrid_stats_entitychecks = 0;
82 void SV_AreaStats_f(void)
84 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);
85 sv_areagrid_stats_calls = 0;
86 sv_areagrid_stats_nodechecks = 0;
87 sv_areagrid_stats_entitychecks = 0;
90 typedef struct areagrid_s
97 #define AREA_GRIDNODES (AREA_GRID * AREA_GRID)
99 static areagrid_t sv_areagrid[AREA_GRIDNODES], sv_areagrid_outside;
100 static vec3_t sv_areagrid_bias, sv_areagrid_scale, sv_areagrid_mins, sv_areagrid_maxs, sv_areagrid_size;
101 static int sv_areagrid_marknumber = 1;
103 void SV_CreateAreaGrid (vec3_t mins, vec3_t maxs)
106 ClearLink (&sv_areagrid_outside.edicts);
107 // choose either the world box size, or a larger box to ensure the grid isn't too fine
108 sv_areagrid_size[0] = max(maxs[0] - mins[0], AREA_GRID * sv_areagrid_mingridsize.value);
109 sv_areagrid_size[1] = max(maxs[1] - mins[1], AREA_GRID * sv_areagrid_mingridsize.value);
110 sv_areagrid_size[2] = max(maxs[2] - mins[2], AREA_GRID * sv_areagrid_mingridsize.value);
111 // figure out the corners of such a box, centered at the center of the world box
112 sv_areagrid_mins[0] = (mins[0] + maxs[0] - sv_areagrid_size[0]) * 0.5f;
113 sv_areagrid_mins[1] = (mins[1] + maxs[1] - sv_areagrid_size[1]) * 0.5f;
114 sv_areagrid_mins[2] = (mins[2] + maxs[2] - sv_areagrid_size[2]) * 0.5f;
115 sv_areagrid_maxs[0] = (mins[0] + maxs[0] + sv_areagrid_size[0]) * 0.5f;
116 sv_areagrid_maxs[1] = (mins[1] + maxs[1] + sv_areagrid_size[1]) * 0.5f;
117 sv_areagrid_maxs[2] = (mins[2] + maxs[2] + sv_areagrid_size[2]) * 0.5f;
118 // now calculate the actual useful info from that
119 VectorNegate(sv_areagrid_mins, sv_areagrid_bias);
120 sv_areagrid_scale[0] = AREA_GRID / sv_areagrid_size[0];
121 sv_areagrid_scale[1] = AREA_GRID / sv_areagrid_size[1];
122 sv_areagrid_scale[2] = AREA_GRID / sv_areagrid_size[2];
123 for (i = 0;i < AREA_GRIDNODES;i++)
125 ClearLink (&sv_areagrid[i].edicts);
127 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);
136 void SV_ClearWorld (void)
138 SV_CreateAreaGrid(sv.worldmodel->normalmins, sv.worldmodel->normalmaxs);
148 void SV_UnlinkEdict (prvm_edict_t *ent)
151 for (i = 0;i < ENTITYGRIDAREAS;i++)
153 if (ent->priv.server->areagrid[i].prev)
155 RemoveLink (&ent->priv.server->areagrid[i]);
156 ent->priv.server->areagrid[i].prev = ent->priv.server->areagrid[i].next = NULL;
161 int SV_EntitiesInBox(vec3_t mins, vec3_t maxs, int maxlist, prvm_edict_t **list)
167 int igrid[3], igridmins[3], igridmaxs[3];
169 sv_areagrid_stats_calls++;
170 sv_areagrid_marknumber++;
171 igridmins[0] = (int) floor((mins[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]);
172 igridmins[1] = (int) floor((mins[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]);
173 //igridmins[2] = (int) ((mins[2] + sv_areagrid_bias[2]) * sv_areagrid_scale[2]);
174 igridmaxs[0] = (int) floor((maxs[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]) + 1;
175 igridmaxs[1] = (int) floor((maxs[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]) + 1;
176 //igridmaxs[2] = (int) ((maxs[2] + sv_areagrid_bias[2]) * sv_areagrid_scale[2]) + 1;
177 igridmins[0] = max(0, igridmins[0]);
178 igridmins[1] = max(0, igridmins[1]);
179 //igridmins[2] = max(0, igridmins[2]);
180 igridmaxs[0] = min(AREA_GRID, igridmaxs[0]);
181 igridmaxs[1] = min(AREA_GRID, igridmaxs[1]);
182 //igridmaxs[2] = min(AREA_GRID, igridmaxs[2]);
185 // add entities not linked into areagrid because they are too big or
186 // outside the grid bounds
187 if (sv_areagrid_outside.edicts.next != &sv_areagrid_outside.edicts)
189 for (l = sv_areagrid_outside.edicts.next;l != &sv_areagrid_outside.edicts;l = l->next)
191 ent = PRVM_EDICT_NUM_UNSIGNED(l->entitynumber);
192 if (ent->priv.server->areagridmarknumber != sv_areagrid_marknumber)
194 ent->priv.server->areagridmarknumber = sv_areagrid_marknumber;
195 if (!ent->priv.server->free && BoxesOverlap(mins, maxs, ent->fields.server->absmin, ent->fields.server->absmax))
197 if (numlist < maxlist)
201 sv_areagrid_stats_entitychecks++;
205 // add grid linked entities
206 for (igrid[1] = igridmins[1];igrid[1] < igridmaxs[1];igrid[1]++)
208 grid = sv_areagrid + igrid[1] * AREA_GRID + igridmins[0];
209 for (igrid[0] = igridmins[0];igrid[0] < igridmaxs[0];igrid[0]++, grid++)
211 if (grid->edicts.next != &grid->edicts)
213 for (l = grid->edicts.next;l != &grid->edicts;l = l->next)
215 ent = PRVM_EDICT_NUM_UNSIGNED(l->entitynumber);
216 if (ent->priv.server->areagridmarknumber != sv_areagrid_marknumber)
218 ent->priv.server->areagridmarknumber = sv_areagrid_marknumber;
219 if (!ent->priv.server->free && BoxesOverlap(mins, maxs, ent->fields.server->absmin, ent->fields.server->absmax))
221 if (numlist < maxlist)
225 // Con_Printf("%d %f %f %f %f %f %f : %d : %f %f %f %f %f %f\n", BoxesOverlap(mins, maxs, ent->fields.server->absmin, ent->fields.server->absmax), ent->fields.server->absmin[0], ent->fields.server->absmin[1], ent->fields.server->absmin[2], ent->fields.server->absmax[0], ent->fields.server->absmax[1], ent->fields.server->absmax[2], PRVM_NUM_FOR_EDICT(ent), mins[0], mins[1], mins[2], maxs[0], maxs[1], maxs[2]);
227 sv_areagrid_stats_entitychecks++;
235 void SV_TouchAreaGrid(prvm_edict_t *ent)
237 int i, numtouchedicts, old_self, old_other;
238 prvm_edict_t *touch, *touchedicts[MAX_EDICTS];
240 // build a list of edicts to touch, because the link loop can be corrupted
241 // by SV_IncreaseEdicts called during touch functions
242 numtouchedicts = SV_EntitiesInBox(ent->fields.server->absmin, ent->fields.server->absmax, MAX_EDICTS, touchedicts);
243 if (numtouchedicts > MAX_EDICTS)
245 // this never happens
246 Con_Printf("SV_EntitiesInBox returned %i edicts, max was %i\n", numtouchedicts, MAX_EDICTS);
247 numtouchedicts = MAX_EDICTS;
250 old_self = prog->globals.server->self;
251 old_other = prog->globals.server->other;
252 for (i = 0;i < numtouchedicts;i++)
254 touch = touchedicts[i];
255 if (touch != ent && (int)touch->fields.server->solid == SOLID_TRIGGER && touch->fields.server->touch)
257 prog->globals.server->self = PRVM_EDICT_TO_PROG(touch);
258 prog->globals.server->other = PRVM_EDICT_TO_PROG(ent);
259 prog->globals.server->time = sv.time;
260 PRVM_ExecuteProgram (touch->fields.server->touch, "QC function self.touch is missing");
263 prog->globals.server->self = old_self;
264 prog->globals.server->other = old_other;
267 void SV_LinkEdict_AreaGrid(prvm_edict_t *ent)
270 int igrid[3], igridmins[3], igridmaxs[3], gridnum, entitynumber = PRVM_NUM_FOR_EDICT(ent);
272 if (entitynumber <= 0 || entitynumber >= prog->max_edicts || PRVM_EDICT_NUM(entitynumber) != ent)
274 Con_Printf ("SV_LinkEdict_AreaGrid: invalid edict %p (edicts is %p, edict compared to prog->edicts is %i)\n", ent, prog->edicts, entitynumber);
278 igridmins[0] = (int) floor((ent->fields.server->absmin[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]);
279 igridmins[1] = (int) floor((ent->fields.server->absmin[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]);
280 //igridmins[2] = (int) ((ent->fields.server->absmin[2] + sv_areagrid_bias[2]) * sv_areagrid_scale[2]);
281 igridmaxs[0] = (int) floor((ent->fields.server->absmax[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]) + 1;
282 igridmaxs[1] = (int) floor((ent->fields.server->absmax[1] + sv_areagrid_bias[1]) * sv_areagrid_scale[1]) + 1;
283 //igridmaxs[2] = (int) ((ent->fields.server->absmax[2] + sv_areagrid_bias[2]) * sv_areagrid_scale[2]) + 1;
284 if (igridmins[0] < 0 || igridmaxs[0] > AREA_GRID || igridmins[1] < 0 || igridmaxs[1] > AREA_GRID || ((igridmaxs[0] - igridmins[0]) * (igridmaxs[1] - igridmins[1])) > ENTITYGRIDAREAS)
286 // wow, something outside the grid, store it as such
287 InsertLinkBefore (&ent->priv.server->areagrid[0], &sv_areagrid_outside.edicts, entitynumber);
292 for (igrid[1] = igridmins[1];igrid[1] < igridmaxs[1];igrid[1]++)
294 grid = sv_areagrid + igrid[1] * AREA_GRID + igridmins[0];
295 for (igrid[0] = igridmins[0];igrid[0] < igridmaxs[0];igrid[0]++, grid++, gridnum++)
296 InsertLinkBefore (&ent->priv.server->areagrid[gridnum], &grid->edicts, entitynumber);
306 void SV_LinkEdict (prvm_edict_t *ent, qboolean touch_triggers)
310 if (ent->priv.server->areagrid[0].prev)
311 SV_UnlinkEdict (ent); // unlink from old position
313 if (ent == prog->edicts)
314 return; // don't add the world
316 if (ent->priv.server->free)
321 if (ent->fields.server->solid == SOLID_BSP)
323 int modelindex = ent->fields.server->modelindex;
324 if (modelindex < 0 || modelindex > MAX_MODELS)
326 Con_Printf("edict %i: SOLID_BSP with invalid modelindex!\n", PRVM_NUM_FOR_EDICT(ent));
329 model = sv.models[modelindex];
332 if (!model->TraceBox)
333 Con_Printf("edict %i: SOLID_BSP with non-collidable model\n", PRVM_NUM_FOR_EDICT(ent));
335 if (ent->fields.server->angles[0] || ent->fields.server->angles[2] || ent->fields.server->avelocity[0] || ent->fields.server->avelocity[2])
337 VectorAdd(ent->fields.server->origin, model->rotatedmins, ent->fields.server->absmin);
338 VectorAdd(ent->fields.server->origin, model->rotatedmaxs, ent->fields.server->absmax);
340 else if (ent->fields.server->angles[1] || ent->fields.server->avelocity[1])
342 VectorAdd(ent->fields.server->origin, model->yawmins, ent->fields.server->absmin);
343 VectorAdd(ent->fields.server->origin, model->yawmaxs, ent->fields.server->absmax);
347 VectorAdd(ent->fields.server->origin, model->normalmins, ent->fields.server->absmin);
348 VectorAdd(ent->fields.server->origin, model->normalmaxs, ent->fields.server->absmax);
353 // SOLID_BSP with no model is valid, mainly because some QC setup code does so temporarily
354 VectorAdd(ent->fields.server->origin, ent->fields.server->mins, ent->fields.server->absmin);
355 VectorAdd(ent->fields.server->origin, ent->fields.server->maxs, ent->fields.server->absmax);
360 VectorAdd(ent->fields.server->origin, ent->fields.server->mins, ent->fields.server->absmin);
361 VectorAdd(ent->fields.server->origin, ent->fields.server->maxs, ent->fields.server->absmax);
365 // to make items easier to pick up and allow them to be grabbed off
366 // of shelves, the abs sizes are expanded
368 if ((int)ent->fields.server->flags & FL_ITEM)
370 ent->fields.server->absmin[0] -= 15;
371 ent->fields.server->absmin[1] -= 15;
372 ent->fields.server->absmin[2] -= 1;
373 ent->fields.server->absmax[0] += 15;
374 ent->fields.server->absmax[1] += 15;
375 ent->fields.server->absmax[2] += 1;
379 // because movement is clipped an epsilon away from an actual edge,
380 // we must fully check even when bounding boxes don't quite touch
381 ent->fields.server->absmin[0] -= 1;
382 ent->fields.server->absmin[1] -= 1;
383 ent->fields.server->absmin[2] -= 1;
384 ent->fields.server->absmax[0] += 1;
385 ent->fields.server->absmax[1] += 1;
386 ent->fields.server->absmax[2] += 1;
389 //if (ent->fields.server->solid == SOLID_NOT)
392 SV_LinkEdict_AreaGrid(ent);
394 // if touch_triggers, touch all entities at this node and descend for more
396 SV_TouchAreaGrid(ent);
402 ===============================================================================
404 POINT TESTING IN HULLS
406 ===============================================================================
411 SV_TestEntityPosition
413 This could be a lot more efficient...
416 int SV_TestEntityPosition (prvm_edict_t *ent)
418 return SV_Move (ent->fields.server->origin, ent->fields.server->mins, ent->fields.server->maxs, ent->fields.server->origin, MOVE_NORMAL, ent).startsolid;
423 ===============================================================================
425 LINE TESTING IN HULLS
427 ===============================================================================
434 Handles selection or creation of a clipping hull, and offseting (and
435 eventually rotation) of the end points
438 trace_t SV_ClipMoveToEntity(prvm_edict_t *ent, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int movetype, int hitsupercontents)
441 model_t *model = NULL;
442 matrix4x4_t matrix, imatrix;
443 float tempnormal[3], starttransformed[3], endtransformed[3];
444 float starttransformedmins[3], starttransformedmaxs[3], endtransformedmins[3], endtransformedmaxs[3];
446 memset(&trace, 0, sizeof(trace));
447 trace.fraction = trace.realfraction = 1;
448 VectorCopy(end, trace.endpos);
450 if ((int) ent->fields.server->solid == SOLID_BSP || movetype == MOVE_HITMODEL)
452 unsigned int modelindex = ent->fields.server->modelindex;
453 // if the modelindex is 0, it shouldn't be SOLID_BSP!
456 Con_Printf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with no model\n", PRVM_NUM_FOR_EDICT(ent));
459 if (modelindex >= MAX_MODELS)
461 Con_Printf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with invalid modelindex\n", PRVM_NUM_FOR_EDICT(ent));
464 model = sv.models[modelindex];
465 if (modelindex != 0 && model == NULL)
467 Con_Printf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with invalid modelindex\n", PRVM_NUM_FOR_EDICT(ent));
471 if ((int) ent->fields.server->solid == SOLID_BSP)
473 if (!model->TraceBox)
475 Con_Printf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with a non-collidable model\n", PRVM_NUM_FOR_EDICT(ent));
478 //if ((int) ent->fields.server->movetype != MOVETYPE_PUSH)
480 // Con_Printf("SV_ClipMoveToEntity: edict %i: SOLID_BSP without MOVETYPE_PUSH\n", PRVM_NUM_FOR_EDICT(ent));
484 Matrix4x4_CreateFromQuakeEntity(&matrix, ent->fields.server->origin[0], ent->fields.server->origin[1], ent->fields.server->origin[2], ent->fields.server->angles[0], ent->fields.server->angles[1], ent->fields.server->angles[2], 1);
487 Matrix4x4_CreateTranslate(&matrix, ent->fields.server->origin[0], ent->fields.server->origin[1], ent->fields.server->origin[2]);
489 Matrix4x4_Invert_Simple(&imatrix, &matrix);
490 Matrix4x4_Transform(&imatrix, start, starttransformed);
491 Matrix4x4_Transform(&imatrix, end, endtransformed);
492 #if COLLISIONPARANOID >= 3
493 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]);
496 if (model && model->TraceBox)
499 frame = (int)ent->fields.server->frame;
500 frame = bound(0, frame, (model->numframes - 1));
501 VectorAdd(starttransformed, maxs, starttransformedmaxs);
502 VectorAdd(endtransformed, maxs, endtransformedmaxs);
503 VectorAdd(starttransformed, mins, starttransformedmins);
504 VectorAdd(endtransformed, mins, endtransformedmins);
505 model->TraceBox(model, frame, &trace, starttransformedmins, starttransformedmaxs, endtransformedmins, endtransformedmaxs, hitsupercontents);
508 Collision_ClipTrace_Box(&trace, ent->fields.server->mins, ent->fields.server->maxs, starttransformed, mins, maxs, endtransformed, hitsupercontents, SUPERCONTENTS_SOLID);
509 trace.fraction = bound(0, trace.fraction, 1);
510 trace.realfraction = bound(0, trace.realfraction, 1);
512 if (trace.fraction < 1)
514 VectorLerp(start, trace.fraction, end, trace.endpos);
515 VectorCopy(trace.plane.normal, tempnormal);
516 Matrix4x4_Transform3x3(&matrix, tempnormal, trace.plane.normal);
517 // FIXME: should recalc trace.plane.dist
520 VectorCopy(end, trace.endpos);
530 trace_t SV_ClipMoveToWorld(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int movetype, int hitsupercontents)
533 float starttransformedmins[3], starttransformedmaxs[3], endtransformedmins[3], endtransformedmaxs[3];
534 memset(&trace, 0, sizeof(trace));
535 trace.fraction = trace.realfraction = 1;
536 VectorAdd(start, maxs, starttransformedmaxs);
537 VectorAdd(end, maxs, endtransformedmaxs);
538 VectorAdd(start, mins, starttransformedmins);
539 VectorAdd(end, mins, endtransformedmins);
540 sv.worldmodel->TraceBox(sv.worldmodel, 0, &trace, starttransformedmins, starttransformedmaxs, endtransformedmins, endtransformedmaxs, hitsupercontents);
541 trace.fraction = bound(0, trace.fraction, 1);
542 trace.realfraction = bound(0, trace.realfraction, 1);
543 VectorLerp(start, trace.fraction, end, trace.endpos);
547 //===========================================================================
554 #if COLLISIONPARANOID >= 1
555 trace_t SV_Move_(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, prvm_edict_t *passedict)
557 trace_t SV_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, prvm_edict_t *passedict)
560 vec3_t hullmins, hullmaxs;
562 int hitsupercontentsmask;
565 prvm_edict_t *traceowner, *touch;
567 // bounding box of entire move area
568 vec3_t clipboxmins, clipboxmaxs;
569 // size of the moving object
570 vec3_t clipmins, clipmaxs;
571 // size when clipping against monsters
572 vec3_t clipmins2, clipmaxs2;
573 // start and end origin of move
574 vec3_t clipstart, clipend;
578 prvm_edict_t *touchedicts[MAX_EDICTS];
580 VectorCopy(start, clipstart);
581 VectorCopy(end, clipend);
582 VectorCopy(mins, clipmins);
583 VectorCopy(maxs, clipmaxs);
584 VectorCopy(mins, clipmins2);
585 VectorCopy(maxs, clipmaxs2);
586 #if COLLISIONPARANOID >= 3
587 Con_Printf("move(%f %f %f,%f %f %f)", clipstart[0], clipstart[1], clipstart[2], clipend[0], clipend[1], clipend[2]);
590 hitsupercontentsmask = SUPERCONTENTS_SOLID;
593 if (passedict->fields.server->solid == SOLID_SLIDEBOX)
594 hitsupercontentsmask |= SUPERCONTENTS_PLAYERCLIP;
595 if ((int)passedict->fields.server->flags & FL_MONSTER)
596 hitsupercontentsmask |= SUPERCONTENTS_MONSTERCLIP;
600 cliptrace = SV_ClipMoveToWorld(clipstart, clipmins, clipmaxs, clipend, type, hitsupercontentsmask);
601 if (cliptrace.startsolid || cliptrace.fraction < 1)
602 cliptrace.ent = prog->edicts;
603 if (type == MOVE_WORLDONLY)
606 if (type == MOVE_MISSILE)
608 // LordHavoc: modified this, was = -15, now -= 15
609 for (i = 0;i < 3;i++)
616 // get adjusted box for bmodel collisions if the world is q1bsp or hlbsp
617 if (sv.worldmodel && sv.worldmodel->brush.RoundUpToHullSize)
618 sv.worldmodel->brush.RoundUpToHullSize(sv.worldmodel, clipmins, clipmaxs, hullmins, hullmaxs);
621 VectorCopy(clipmins, hullmins);
622 VectorCopy(clipmaxs, hullmaxs);
625 // create the bounding box of the entire move
626 for (i = 0;i < 3;i++)
628 clipboxmins[i] = min(clipstart[i], cliptrace.endpos[i]) + min(hullmins[i], clipmins2[i]) - 1;
629 clipboxmaxs[i] = max(clipstart[i], cliptrace.endpos[i]) + max(hullmaxs[i], clipmaxs2[i]) + 1;
632 // debug override to test against everything
633 if (sv_debugmove.integer)
635 clipboxmins[0] = clipboxmins[1] = clipboxmins[2] = -999999999;
636 clipboxmaxs[0] = clipboxmaxs[1] = clipboxmaxs[2] = 999999999;
639 // if the passedict is world, make it NULL (to avoid two checks each time)
640 if (passedict == prog->edicts)
642 // precalculate prog value for passedict for comparisons
643 passedictprog = PRVM_EDICT_TO_PROG(passedict);
644 // figure out whether this is a point trace for comparisons
645 pointtrace = VectorCompare(clipmins, clipmaxs);
646 // precalculate passedict's owner edict pointer for comparisons
647 traceowner = passedict ? PRVM_PROG_TO_EDICT(passedict->fields.server->owner) : 0;
650 numtouchedicts = SV_EntitiesInBox(clipboxmins, clipboxmaxs, MAX_EDICTS, touchedicts);
651 if (numtouchedicts > MAX_EDICTS)
653 // this never happens
654 Con_Printf("SV_EntitiesInBox returned %i edicts, max was %i\n", numtouchedicts, MAX_EDICTS);
655 numtouchedicts = MAX_EDICTS;
657 for (i = 0;i < numtouchedicts;i++)
659 touch = touchedicts[i];
661 if (touch->fields.server->solid < SOLID_BBOX)
663 if (type == MOVE_NOMONSTERS && touch->fields.server->solid != SOLID_BSP)
668 // don't clip against self
669 if (passedict == touch)
671 // don't clip owned entities against owner
672 if (traceowner == touch)
674 // don't clip owner against owned entities
675 if (passedictprog == touch->fields.server->owner)
677 // don't clip points against points (they can't collide)
678 if (pointtrace && VectorCompare(touch->fields.server->mins, touch->fields.server->maxs) && (type != MOVE_MISSILE || !((int)touch->fields.server->flags & FL_MONSTER)))
680 // don't clip corpse against character
681 if (passedict->fields.server->solid == SOLID_CORPSE && (touch->fields.server->solid == SOLID_SLIDEBOX || touch->fields.server->solid == SOLID_CORPSE))
683 // don't clip character against corpse
684 if (passedict->fields.server->solid == SOLID_SLIDEBOX && touch->fields.server->solid == SOLID_CORPSE)
688 // might interact, so do an exact clip
689 if ((int)touch->fields.server->flags & FL_MONSTER)
690 trace = SV_ClipMoveToEntity(touch, clipstart, clipmins2, clipmaxs2, clipend, type, hitsupercontentsmask);
692 trace = SV_ClipMoveToEntity(touch, clipstart, clipmins, clipmaxs, clipend, type, hitsupercontentsmask);
693 // LordHavoc: take the 'best' answers from the new trace and combine with existing data
695 cliptrace.allsolid = true;
696 if (trace.startsolid)
698 cliptrace.startsolid = true;
699 if (cliptrace.realfraction == 1)
700 cliptrace.ent = touch;
702 // don't set this except on the world, because it can easily confuse
703 // monsters underwater if there's a bmodel involved in the trace
704 // (inopen && inwater is how they check water visibility)
706 // cliptrace.inopen = true;
708 cliptrace.inwater = true;
709 if (trace.realfraction < cliptrace.realfraction)
711 cliptrace.fraction = trace.fraction;
712 cliptrace.realfraction = trace.realfraction;
713 VectorCopy(trace.endpos, cliptrace.endpos);
714 cliptrace.plane = trace.plane;
715 cliptrace.ent = touch;
717 cliptrace.startsupercontents |= trace.startsupercontents;
723 #if COLLISIONPARANOID >= 1
724 trace_t SV_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, prvm_edict_t *passedict)
729 trace = SV_Move_(start, mins, maxs, end, type, passedict);
732 VectorCopy(trace.endpos, temp);
733 endstuck = SV_Move_(temp, mins, maxs, temp, type, passedict).startsolid;
734 #if COLLISIONPARANOID < 3
735 if (trace.startsolid || endstuck)
737 Con_Printf("%s{e%i:%f %f %f:%f %f %f:%f:%f %f %f%s%s}\n", (trace.startsolid || endstuck) ? "\002" : "", passedict ? passedict - prog->edicts : -1, passedict->fields.server->origin[0], passedict->fields.server->origin[1], passedict->fields.server->origin[2], end[0] - passedict->fields.server->origin[0], end[1] - passedict->fields.server->origin[1], end[2] - passedict->fields.server->origin[2], trace.fraction, trace.endpos[0] - passedict->fields.server->origin[0], trace.endpos[1] - passedict->fields.server->origin[1], trace.endpos[2] - passedict->fields.server->origin[2], trace.startsolid ? " startstuck" : "", endstuck ? " endstuck" : "");