]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/warpzone/common.qc
WarpZoneLib_BoxTouchesBrush: deglobalise, add TODO
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / warpzone / common.qc
index b70e938fe7e987ee9dded47a2e721b151bd9d10d..429f6a1175a37f792c62155c02f1b5e39b56e7c2 100644 (file)
@@ -1,7 +1,7 @@
 #include "common.qh"
 
 #if defined(CSQC)
-    #include <common/t_items.qh>
+    #include <client/items/items.qh>
 #elif defined(MENUQC)
 #elif defined(SVQC)
     #include <common/weapons/_all.qh>
@@ -71,8 +71,11 @@ void WarpZone_SetUp(entity e, vector my_org, vector my_ang, vector other_org, ve
        e.warpzone_targetorigin = other_org;
        e.warpzone_angles = my_ang;
        e.warpzone_targetangles = other_ang;
-       fixedmakevectors(my_ang); e.warpzone_forward = v_forward;
-       fixedmakevectors(other_ang); e.warpzone_targetforward = v_forward;
+       vector forward, right, up;
+       FIXED_MAKE_VECTORS(my_ang, forward, right, up);
+       e.warpzone_forward = forward;
+       FIXED_MAKE_VECTORS(other_ang, forward, right, up);
+       e.warpzone_targetforward = forward;
        setcamera_transform(e, WarpZone_camera_transform);
 }
 
@@ -98,17 +101,12 @@ void WarpZone_Camera_SetUp(entity e, vector my_org, vector my_ang) // we assume
 
 .entity enemy;
 
-vector WarpZoneLib_BoxTouchesBrush_mins;
-vector WarpZoneLib_BoxTouchesBrush_maxs;
-entity WarpZoneLib_BoxTouchesBrush_ent;
-entity WarpZoneLib_BoxTouchesBrush_ignore;
-float WarpZoneLib_BoxTouchesBrush_Recurse()
+float WarpZoneLib_BoxTouchesBrush_Recurse(vector mi, vector ma, entity e, entity ig)
 {
-       float s;
+       float f, s;
        entity se;
-       float f;
 
-       tracebox('0 0 0', WarpZoneLib_BoxTouchesBrush_mins, WarpZoneLib_BoxTouchesBrush_maxs, '0 0 0', MOVE_NOMONSTERS, WarpZoneLib_BoxTouchesBrush_ignore);
+       tracebox('0 0 0', mi, ma, '0 0 0', MOVE_NOMONSTERS, ig);
 #ifdef CSQC
        if (trace_networkentity)
        {
@@ -120,13 +118,13 @@ float WarpZoneLib_BoxTouchesBrush_Recurse()
 #endif
        if (!trace_ent)
                return 0;
-       if (trace_ent == WarpZoneLib_BoxTouchesBrush_ent)
+       if (trace_ent == e)
                return 1;
 
        se = trace_ent;
        s = se.solid;
        se.solid = SOLID_NOT;
-       f = WarpZoneLib_BoxTouchesBrush_Recurse();
+       f = WarpZoneLib_BoxTouchesBrush_Recurse(mi, ma, e, ig);
        se.solid = s;
 
        return f;
@@ -134,21 +132,20 @@ float WarpZoneLib_BoxTouchesBrush_Recurse()
 
 float WarpZoneLib_BoxTouchesBrush(vector mi, vector ma, entity e, entity ig)
 {
-    float f, s;
+       // bones_was_here: TODO: when findbox() builtin is available, use it to
+       // optimise this into a single non-recursive function that only calls tracebox once
 
-    if(!e.modelindex || e.warpzone_isboxy)
-        return 1;
+       float f, s;
 
-    s = e.solid;
-    e.solid = SOLID_BSP;
-    WarpZoneLib_BoxTouchesBrush_mins = mi;
-    WarpZoneLib_BoxTouchesBrush_maxs = ma;
-    WarpZoneLib_BoxTouchesBrush_ent = e;
-    WarpZoneLib_BoxTouchesBrush_ignore = ig;
-    f = WarpZoneLib_BoxTouchesBrush_Recurse();
-    e.solid = s;
+       if(!e.modelindex || e.warpzone_isboxy)
+               return 1;
+
+       s = e.solid;
+       e.solid = SOLID_BSP;
+       f = WarpZoneLib_BoxTouchesBrush_Recurse(mi, ma, e, ig);
+       e.solid = s;
 
-    return f;
+       return f;
 }
 
 entity WarpZone_Find(vector mi, vector ma)
@@ -201,7 +198,6 @@ void WarpZone_TraceBox_ThroughZone(vector org, vector mi, vector ma, vector end,
        float nomonsters_adjusted;
        float frac, sol, i;
        float contentshack;
-       vector o0, e0;
        entity wz;
        vector vf, vr, vu;
 
@@ -231,8 +227,6 @@ void WarpZone_TraceBox_ThroughZone(vector org, vector mi, vector ma, vector end,
        vf = v_forward;
        vr = v_right;
        vu = v_up;
-       o0 = org;
-       e0 = end;
 
        switch(nomonsters)
        {
@@ -571,13 +565,26 @@ vector WarpZoneLib_NearestPointOnBox(vector mi, vector ma, vector org)
        return nearest;
 }
 
+// blacklist of entities that WarpZone_FindRadius doesn't care about
 bool WarpZoneLib_BadEntity(entity e)
 {
        if (is_pure(e)) return true;
        string s = e.classname;
 
-       //if (s == "net_linked") return true; // actually some real entities are linked without classname, fail
-       if (s == "") return true;
+       switch(s)
+       {
+               case "weaponentity":
+               case "exteriorweaponentity":
+               case "sprite_waypoint":
+               case "waypoint":
+               case "spawnfunc":
+               case "weaponchild":
+               case "chatbubbleentity":
+               case "buff_model":
+               //case "net_linked": // actually some real entities are linked without classname, fail
+               case "":
+                       return true;
+       }
 
        if (startsWith(s, "target_")) return true;
 
@@ -778,15 +785,22 @@ void WarpZone_RefSys_Copy(entity me, entity from)
 }
 entity WarpZone_RefSys_SpawnSameRefSys(entity me)
 {
-       entity e;
-       e = spawn();
+       entity e = spawn();
        WarpZone_RefSys_Copy(e, me);
        return e;
 }
 
 bool WarpZoneLib_ExactTrigger_Touch(entity this, entity toucher)
 {
-       return !WarpZoneLib_BoxTouchesBrush(toucher.absmin, toucher.absmax, this, toucher);
+       vector emin = toucher.absmin, emax = toucher.absmax;
+       if(STAT(Q3COMPAT))
+       {
+               // DP's tracebox enlarges absolute bounding boxes by a single quake unit
+               // we must undo that here to allow accurate touching
+               emin += '1 1 1';
+               emax -= '1 1 1';
+       }
+       return !WarpZoneLib_BoxTouchesBrush(emin, emax, this, toucher);
 }