]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/warpzone/common.qc
Merge branch 'master' into martin-t/globals
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / warpzone / common.qc
index 704feeb7e7c8b84a60bef620a15aa7505965be37..3bff39be1fd954f89ff4984828aa0af67dad42bd 100644 (file)
@@ -4,7 +4,7 @@
     #include <common/t_items.qh>
 #elif defined(MENUQC)
 #elif defined(SVQC)
-    #include <common/weapons/all.qh>
+    #include <common/weapons/_all.qh>
 #endif
 
 void WarpZone_Accumulator_Clear(entity acc)
@@ -54,7 +54,7 @@ vector WarpZone_camera_transform(entity this, vector org, vector ang)
        vr = WarpZone_TransformVelocity(this, vr);
        vu = WarpZone_TransformVelocity(this, vu);
        if(autocvar_cl_warpzone_usetrace)
-               traceline(this.warpzone_targetorigin, org, MOVE_NOMONSTERS, world);
+               traceline(this.warpzone_targetorigin, org, MOVE_NOMONSTERS, NULL);
        else
                trace_endpos = this.warpzone_targetorigin;
        v_forward = vf;
@@ -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);
 }
 
@@ -112,7 +115,7 @@ float WarpZoneLib_BoxTouchesBrush_Recurse()
 #ifdef CSQC
        if (trace_networkentity)
        {
-               LOG_TRACE("hit a network ent, cannot continue WarpZoneLib_BoxTouchesBrush\n");
+               LOG_TRACE("hit a network ent, cannot continue WarpZoneLib_BoxTouchesBrush");
                // we cannot continue, as a player blocks us...
                // so, abort
                return 0;
@@ -154,31 +157,33 @@ float WarpZoneLib_BoxTouchesBrush(vector mi, vector ma, entity e, entity ig)
 entity WarpZone_Find(vector mi, vector ma)
 {
        // if we are near any warpzone planes - MOVE AWAY (work around nearclip)
-       entity e;
        if(!warpzone_warpzones_exist)
-               return world;
-       for(e = world; (e = find(e, classname, "trigger_warpzone")); )
-               if(WarpZoneLib_BoxTouchesBrush(mi, ma, e, world))
-                       return e;
-       return world;
+               return NULL;
+       IL_EACH(g_warpzones, WarpZoneLib_BoxTouchesBrush(mi, ma, it, NULL),
+       {
+               return it;
+       });
+       return NULL;
 }
 
 void WarpZone_MakeAllSolid()
 {
-       entity e;
        if(!warpzone_warpzones_exist)
                return;
-       for(e = world; (e = find(e, classname, "trigger_warpzone")); )
-               e.solid = SOLID_BSP;
+       IL_EACH(g_warpzones, true,
+       {
+               it.solid = SOLID_BSP;
+       });
 }
 
 void WarpZone_MakeAllOther()
 {
-       entity e;
        if(!warpzone_warpzones_exist)
                return;
-       for(e = world; (e = find(e, classname, "trigger_warpzone")); )
-               e.solid = SOLID_TRIGGER;
+       IL_EACH(g_warpzones, true,
+       {
+               it.solid = SOLID_TRIGGER;
+       });
 }
 
 void WarpZone_Trace_InitTransform()
@@ -199,13 +204,12 @@ 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;
 
        WarpZone_trace_forent = forent;
-       WarpZone_trace_firstzone = world;
-       WarpZone_trace_lastzone = world;
+       WarpZone_trace_firstzone = NULL;
+       WarpZone_trace_lastzone = NULL;
        WarpZone_Trace_InitTransform();
        if(!warpzone_warpzones_exist)
        {
@@ -229,8 +233,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)
        {
@@ -271,8 +273,8 @@ void WarpZone_TraceBox_ThroughZone(vector org, vector mi, vector ma, vector end,
        {
                if(--i < 1)
                {
-                       LOG_TRACE("Too many warpzones in sequence, aborting trace.\n");
-                       trace_ent = world;
+                       LOG_TRACE("Too many warpzones in sequence, aborting trace.");
+                       trace_ent = NULL;
                        break;
                }
                tracebox(org, mi, ma, end, nomonsters_adjusted, WarpZone_trace_forent);
@@ -296,13 +298,13 @@ void WarpZone_TraceBox_ThroughZone(vector org, vector mi, vector ma, vector end,
                        }
                        break;
                }
-               if(trace_ent == wz)
+               /*if(trace_ent == wz)
                {
                        // FIXME can this check be removed? Do we really need it?
-                       LOG_TRACE("I transformed into the same zone again, wtf, aborting the trace\n");
-                       trace_ent = world;
+                       LOG_TRACE("I transformed into the same zone again, wtf, aborting the trace");
+                       trace_ent = NULL;
                        break;
-               }
+               }*/
                wz = trace_ent;
                if(!WarpZone_trace_firstzone)
                        WarpZone_trace_firstzone = wz;
@@ -330,7 +332,7 @@ LABEL(fail)
 
 void WarpZone_TraceBox(vector org, vector mi, vector ma, vector end, float nomonsters, entity forent)
 {
-       WarpZone_TraceBox_ThroughZone(org, mi, ma, end, nomonsters, forent, world, WarpZone_trace_callback_t_null);
+       WarpZone_TraceBox_ThroughZone(org, mi, ma, end, nomonsters, forent, NULL, WarpZone_trace_callback_t_null);
 }
 
 void WarpZone_TraceLine(vector org, vector end, float nomonsters, entity forent)
@@ -349,8 +351,8 @@ void WarpZone_TraceToss_ThroughZone(entity e, entity forent, entity zone, WarpZo
        g = cvar("sv_gravity") * e.gravity;
 
        WarpZone_trace_forent = forent;
-       WarpZone_trace_firstzone = world;
-       WarpZone_trace_lastzone = world;
+       WarpZone_trace_firstzone = NULL;
+       WarpZone_trace_lastzone = NULL;
        WarpZone_Trace_InitTransform();
        WarpZone_tracetoss_time = 0;
        if(!warpzone_warpzones_exist)
@@ -395,8 +397,8 @@ void WarpZone_TraceToss_ThroughZone(entity e, entity forent, entity zone, WarpZo
        {
                if(--i < 1)
                {
-                       LOG_TRACE("Too many warpzones in sequence, aborting trace.\n");
-                       trace_ent = world;
+                       LOG_TRACE("Too many warpzones in sequence, aborting trace.");
+                       trace_ent = NULL;
                        break;
                }
                tracetoss(e, WarpZone_trace_forent);
@@ -413,8 +415,8 @@ void WarpZone_TraceToss_ThroughZone(entity e, entity forent, entity zone, WarpZo
                if(trace_ent == wz)
                {
                        // FIXME can this check be removed? Do we really need it?
-                       LOG_TRACE("I transformed into the same zone again, wtf, aborting the trace\n");
-                       trace_ent = world;
+                       LOG_TRACE("I transformed into the same zone again, wtf, aborting the trace");
+                       trace_ent = NULL;
                        break;
                }
                wz = trace_ent;
@@ -449,7 +451,7 @@ LABEL(fail)
 
 void WarpZone_TraceToss(entity e, entity forent)
 {
-       WarpZone_TraceToss_ThroughZone(e, forent, world, WarpZone_trace_callback_t_null);
+       WarpZone_TraceToss_ThroughZone(e, forent, NULL, WarpZone_trace_callback_t_null);
 }
 
 entity WarpZone_TrailParticles_trace_callback_own;
@@ -463,7 +465,7 @@ void WarpZone_TrailParticles(entity own, float eff, vector org, vector end)
 {
        WarpZone_TrailParticles_trace_callback_own = own;
        WarpZone_TrailParticles_trace_callback_eff = eff;
-       WarpZone_TraceBox_ThroughZone(org, '0 0 0', '0 0 0', end, MOVE_NOMONSTERS, world, world, WarpZone_TrailParticles_trace_callback);
+       WarpZone_TraceBox_ThroughZone(org, '0 0 0', '0 0 0', end, MOVE_NOMONSTERS, NULL, NULL, WarpZone_TrailParticles_trace_callback);
 }
 
 #ifdef CSQC
@@ -480,7 +482,7 @@ void WarpZone_TrailParticles_WithMultiplier(entity own, float eff, vector org, v
        WarpZone_TrailParticles_trace_callback_eff = eff;
        WarpZone_TrailParticles_trace_callback_f = f;
        WarpZone_TrailParticles_trace_callback_flags = boxflags | PARTICLES_DRAWASTRAIL;
-       WarpZone_TraceBox_ThroughZone(org, '0 0 0', '0 0 0', end, MOVE_NOMONSTERS, world, world, WarpZone_TrailParticles_WithMultiplier_trace_callback);
+       WarpZone_TraceBox_ThroughZone(org, '0 0 0', '0 0 0', end, MOVE_NOMONSTERS, NULL, NULL, WarpZone_TrailParticles_WithMultiplier_trace_callback);
 }
 #endif
 
@@ -573,12 +575,9 @@ bool WarpZoneLib_BadEntity(entity e)
 {
        if (is_pure(e)) return true;
        string s = e.classname;
-       switch (s)
-       {
-               // case "net_linked": // actually some real entities are linked without classname, fail
-               case "":
-                       return true;
-       }
+
+       //if (s == "net_linked") return true; // actually some real entities are linked without classname, fail
+       if (s == "") return true;
 
        if (startsWith(s, "target_")) return true;
 
@@ -671,7 +670,7 @@ void WarpZone_RefSys_GC(entity this)
        // garbage collect unused reference systems
        this.nextthink = time + 1;
        if(this.owner.WarpZone_refsys != this)
-               remove(this);
+               delete(this);
 }
 void WarpZone_RefSys_CheckCreate(entity me)
 {
@@ -688,8 +687,8 @@ void WarpZone_RefSys_Clear(entity me)
 {
        if(me.WarpZone_refsys)
        {
-               remove(me.WarpZone_refsys);
-               me.WarpZone_refsys = world;
+               delete(me.WarpZone_refsys);
+               me.WarpZone_refsys = NULL;
        }
 }
 void WarpZone_RefSys_AddTransform(entity me, vector t, vector s)
@@ -785,7 +784,7 @@ entity WarpZone_RefSys_SpawnSameRefSys(entity me)
        return e;
 }
 
-float WarpZoneLib_ExactTrigger_Touch(entity this, entity toucher)
+bool WarpZoneLib_ExactTrigger_Touch(entity this, entity toucher)
 {
        return !WarpZoneLib_BoxTouchesBrush(toucher.absmin, toucher.absmax, this, toucher);
 }
@@ -793,7 +792,7 @@ float WarpZoneLib_ExactTrigger_Touch(entity this, entity toucher)
 
 void WarpZoneLib_MoveOutOfSolid_Expand(entity e, vector by)
 {
-       float eps = 0.0625;
+       const float eps = 0.0625;
        tracebox(e.origin, e.mins - '1 1 1' * eps, e.maxs + '1 1 1' * eps, e.origin + by, MOVE_WORLDONLY, e);
        if (trace_startsolid)
                return;
@@ -801,15 +800,13 @@ void WarpZoneLib_MoveOutOfSolid_Expand(entity e, vector by)
        {
                // hit something
                // adjust origin in the other direction...
-               setorigin(e,e.origin - by * (1 - trace_fraction));
+               setorigin(e, e.origin - by * (1 - trace_fraction));
        }
 }
 
-float WarpZoneLib_MoveOutOfSolid(entity e)
+bool WarpZoneLib_MoveOutOfSolid(entity e)
 {
-       vector o, m0, m1;
-
-       o = e.origin;
+       vector o = e.origin;
        traceline(o, o, MOVE_WORLDONLY, e);
        if (trace_startsolid)
                return false;
@@ -818,22 +815,16 @@ float WarpZoneLib_MoveOutOfSolid(entity e)
        if (!trace_startsolid)
                return true;
 
-       m0 = e.mins;
-       m1 = e.maxs;
+       vector m0 = e.mins;
+       vector m1 = e.maxs;
        e.mins = '0 0 0';
        e.maxs = '0 0 0';
-       WarpZoneLib_MoveOutOfSolid_Expand(e, '1 0 0' * m0_x);
-       e.mins_x = m0_x;
-       WarpZoneLib_MoveOutOfSolid_Expand(e, '1 0 0' * m1_x);
-       e.maxs_x = m1_x;
-       WarpZoneLib_MoveOutOfSolid_Expand(e, '0 1 0' * m0_y);
-       e.mins_y = m0_y;
-       WarpZoneLib_MoveOutOfSolid_Expand(e, '0 1 0' * m1_y);
-       e.maxs_y = m1_y;
-       WarpZoneLib_MoveOutOfSolid_Expand(e, '0 0 1' * m0_z);
-       e.mins_z = m0_z;
-       WarpZoneLib_MoveOutOfSolid_Expand(e, '0 0 1' * m1_z);
-       e.maxs_z = m1_z;
+       WarpZoneLib_MoveOutOfSolid_Expand(e, eX * m0.x); e.mins_x = m0.x;
+       WarpZoneLib_MoveOutOfSolid_Expand(e, eX * m1.x); e.maxs_x = m1.x;
+       WarpZoneLib_MoveOutOfSolid_Expand(e, eY * m0.y); e.mins_y = m0.y;
+       WarpZoneLib_MoveOutOfSolid_Expand(e, eY * m1.y); e.maxs_y = m1.y;
+       WarpZoneLib_MoveOutOfSolid_Expand(e, eZ * m0.z); e.mins_z = m0.z;
+       WarpZoneLib_MoveOutOfSolid_Expand(e, eZ * m1.z); e.maxs_z = m1.z;
        setorigin(e, e.origin);
 
        tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_WORLDONLY, e);