]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_collision.c
add a fs_gamedir cvar containing the currently active gamedirs (for use by menu QC...
[xonotic/darkplaces.git] / cl_collision.c
index 10e8f4c23b59c4ea092528b3e6a6695cc6288751..140e0e681e61554e6054e70e0d4c29a62492809e 100644 (file)
@@ -2,7 +2,11 @@
 #include "quakedef.h"
 #include "cl_collision.h"
 
+#ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
+float CL_SelectTraceLine(const vec3_t start, const vec3_t pEnd, vec3_t impact, vec3_t normal, int *hitent, entity_render_t *ignoreent)
+#else
 float CL_SelectTraceLine(const vec3_t start, const vec3_t end, vec3_t impact, vec3_t normal, int *hitent, entity_render_t *ignoreent)
+#endif
 {
        float maxfrac, maxrealfrac;
        int n;
@@ -10,6 +14,20 @@ float CL_SelectTraceLine(const vec3_t start, const vec3_t end, vec3_t impact, ve
        float tracemins[3], tracemaxs[3];
        trace_t trace;
        float tempnormal[3], starttransformed[3], endtransformed[3];
+#ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
+       vec3_t end;
+       vec_t len = 0;
+
+       if(!VectorCompare(start, pEnd))
+       {
+               // TRICK: make the trace 1 qu longer!
+               VectorSubtract(pEnd, start, end);
+               len = VectorNormalizeLength(end);
+               VectorAdd(pEnd, end, end);
+       }
+       else
+               VectorCopy(pEnd, end);
+#endif
 
        memset (&trace, 0 , sizeof(trace_t));
        trace.fraction = 1;
@@ -53,11 +71,14 @@ float CL_SelectTraceLine(const vec3_t start, const vec3_t end, vec3_t impact, ve
                Matrix4x4_Transform(&ent->inversematrix, start, starttransformed);
                Matrix4x4_Transform(&ent->inversematrix, end, endtransformed);
                Collision_ClipTrace_Box(&trace, ent->model->normalmins, ent->model->normalmaxs, starttransformed, vec3_origin, vec3_origin, endtransformed, SUPERCONTENTS_SOLID, SUPERCONTENTS_SOLID, 0, NULL);
+#ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
+               if(!VectorCompare(start, pEnd))
+                       Collision_ShortenTrace(&trace, len / (len + 1), pEnd);
+#endif
                if (maxrealfrac < trace.realfraction)
                        continue;
 
-               //if (ent->model && ent->model->TraceBox)
-                       ent->model->TraceBox(ent->model, ent->frameblend[0].frame, &trace, starttransformed, vec3_origin, vec3_origin, endtransformed, SUPERCONTENTS_SOLID);
+               ent->model->TraceBox(ent->model, ent->frameblend[0].subframe, &trace, starttransformed, vec3_origin, vec3_origin, endtransformed, SUPERCONTENTS_SOLID);
 
                if (maxrealfrac > trace.realfraction)
                {
@@ -205,7 +226,11 @@ int CL_GenericHitSuperContentsMask(const prvm_edict_t *passedict)
 CL_Move
 ==================
 */
+#ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
+trace_t CL_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t pEnd, int type, prvm_edict_t *passedict, int hitsupercontentsmask, qboolean hitnetworkbrushmodels, qboolean hitnetworkplayers, int *hitnetworkentity, qboolean hitcsqcentities)
+#else
 trace_t CL_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask, qboolean hitnetworkbrushmodels, qboolean hitnetworkplayers, int *hitnetworkentity, qboolean hitcsqcentities)
+#endif
 {
        vec3_t hullmins, hullmaxs;
        int i, bodysupercontents;
@@ -230,6 +255,20 @@ trace_t CL_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const
        // list of entities to test for collisions
        int numtouchedicts;
        prvm_edict_t *touchedicts[MAX_EDICTS];
+#ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
+       vec3_t end;
+       vec_t len = 0;
+
+       if(!VectorCompare(start, pEnd))
+       {
+               // TRICK: make the trace 1 qu longer!
+               VectorSubtract(pEnd, start, end);
+               len = VectorNormalizeLength(end);
+               VectorAdd(pEnd, end, end);
+       }
+       else
+               VectorCopy(pEnd, end);
+#endif
 
        if (hitnetworkentity)
                *hitnetworkentity = 0;
@@ -250,7 +289,7 @@ trace_t CL_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const
        if (cliptrace.startsolid || cliptrace.fraction < 1)
                cliptrace.ent = prog ? prog->edicts : NULL;
        if (type == MOVE_WORLDONLY)
-               return cliptrace;
+               goto finished;
 
        if (type == MOVE_MISSILE)
        {
@@ -305,7 +344,7 @@ trace_t CL_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const
                        entity_render_t *ent = &cl.entities[cl.brushmodel_entities[i]].render;
                        if (!BoxesOverlap(clipboxmins, clipboxmaxs, ent->mins, ent->maxs))
                                continue;
-                       Collision_ClipToGenericEntity(&trace, ent->model, ent->frame2, vec3_origin, vec3_origin, 0, &ent->matrix, &ent->inversematrix, start, mins, maxs, end, hitsupercontentsmask);
+                       Collision_ClipToGenericEntity(&trace, ent->model, ent->frameblend[0].subframe, vec3_origin, vec3_origin, 0, &ent->matrix, &ent->inversematrix, start, mins, maxs, end, hitsupercontentsmask);
                        if (cliptrace.realfraction > trace.realfraction && hitnetworkentity)
                                *hitnetworkentity = cl.brushmodel_entities[i];
                        Collision_CombineTraces(&cliptrace, &trace, NULL, true);
@@ -317,15 +356,33 @@ trace_t CL_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const
        {
                vec3_t origin, entmins, entmaxs;
                matrix4x4_t entmatrix, entinversematrix;
+
+               if(gamemode == GAME_NEXUIZ)
+               {
+                       // don't hit network players, if we are a nonsolid player
+                       if(cl.scores[cl.playerentity-1].frags == -666 || cl.scores[cl.playerentity-1].frags == -616)
+                               goto skipnetworkplayers;
+               }
+
                for (i = 1;i <= cl.maxclients;i++)
                {
                        entity_render_t *ent = &cl.entities[i].render;
-                       // don't hit players that don't exist
-                       if (!cl.scores[i-1].name[0])
-                               continue;
+
                        // don't hit ourselves
                        if (i == cl.playerentity)
                                continue;
+
+                       // don't hit players that don't exist
+                       if (!cl.scores[i-1].name[0])
+                               continue;
+
+                       if(gamemode == GAME_NEXUIZ)
+                       {
+                               // don't hit spectators or nonsolid players
+                               if(cl.scores[i-1].frags == -666 || cl.scores[i-1].frags == -616)
+                                       continue;
+                       }
+
                        Matrix4x4_OriginFromMatrix(&ent->matrix, origin);
                        VectorAdd(origin, cl.playerstandmins, entmins);
                        VectorAdd(origin, cl.playerstandmaxs, entmaxs);
@@ -338,6 +395,9 @@ trace_t CL_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const
                                *hitnetworkentity = i;
                        Collision_CombineTraces(&cliptrace, &trace, NULL, false);
                }
+
+skipnetworkplayers:
+               ;
        }
 
        // clip to entities
@@ -397,14 +457,19 @@ trace_t CL_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const
                        Matrix4x4_CreateTranslate(&matrix, touch->fields.client->origin[0], touch->fields.client->origin[1], touch->fields.client->origin[2]);
                Matrix4x4_Invert_Simple(&imatrix, &matrix);
                if ((int)touch->fields.client->flags & FL_MONSTER)
-                       Collision_ClipToGenericEntity(&trace, model, touch->fields.client->frame, touch->fields.client->mins, touch->fields.client->maxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipend, hitsupercontentsmask);
+                       Collision_ClipToGenericEntity(&trace, model, (int) touch->fields.client->frame, touch->fields.client->mins, touch->fields.client->maxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins2, clipmaxs2, clipend, hitsupercontentsmask);
                else
-                       Collision_ClipToGenericEntity(&trace, model, touch->fields.client->frame, touch->fields.client->mins, touch->fields.client->maxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins, clipmaxs, clipend, hitsupercontentsmask);
+                       Collision_ClipToGenericEntity(&trace, model, (int) touch->fields.client->frame, touch->fields.client->mins, touch->fields.client->maxs, bodysupercontents, &matrix, &imatrix, clipstart, clipmins, clipmaxs, clipend, hitsupercontentsmask);
 
                if (cliptrace.realfraction > trace.realfraction && hitnetworkentity)
                        *hitnetworkentity = 0;
                Collision_CombineTraces(&cliptrace, &trace, (void *)touch, touch->fields.client->solid == SOLID_BSP);
        }
 
+finished:
+#ifdef COLLISION_STUPID_TRACE_ENDPOS_IN_SOLID_WORKAROUND
+       if(!VectorCompare(start, pEnd))
+               Collision_ShortenTrace(&cliptrace, len / (len + 1), pEnd);
+#endif
        return cliptrace;
 }