]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/physics/movetypes/movetypes.qc
Merge branch 'master' into terencehill/hud_shake_fix
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / physics / movetypes / movetypes.qc
index fa169e9f82115565045c107218052da5b4f50cfd..eee217200f7da8baf8015dfae9c87d06516079fb 100644 (file)
@@ -1,15 +1,15 @@
 #include "../player.qh"
 
 #if defined(CSQC)
-       #include "../../../client/defs.qh"
-       #include "../../stats.qh"
-       #include "../../util.qh"
+       #include <client/defs.qh>
+       #include <common/stats.qh>
+       #include <common/util.qh>
        #include "movetypes.qh"
-       #include "../../../lib/csqcmodel/common.qh"
-       #include "../../../server/t_items.qh"
+       #include <lib/csqcmodel/common.qh>
+       #include <common/t_items.qh>
 #elif defined(MENUQC)
 #elif defined(SVQC)
-       #include "../../../server/autocvars.qh"
+       #include <server/autocvars.qh>
 #endif
 
 void _Movetype_WallFriction(entity this, vector stepnormal)  // SV_WallFriction
@@ -96,7 +96,7 @@ int _Movetype_FlyMove(entity this, float dt, bool applygravity, vector stepnorma
                                if(!trace_ent)
                                {
                                        //dprint("_Movetype_FlyMove: !trace_ent\n");
-                                       trace_ent = world;
+                                       trace_ent = NULL;
                                }
 
                                this.move_flags |= FL_ONGROUND;
@@ -317,20 +317,20 @@ void _Movetype_Impact(entity this, entity oth)  // SV_Impact
 {
        entity oldother = other;
 
-       if(this.move_touch)
+       if(gettouch(this))
        {
                other = oth;
 
-               WITH(entity, self, this, this.move_touch());
+               gettouch(this)(this);
 
                other = oldother;
        }
 
-       if(oth.move_touch)
+       if(gettouch(oth))
        {
                other = this;
 
-               WITH(entity, self, oth, oth.move_touch());
+               gettouch(oth)(oth);
 
                other = oldother;
        }
@@ -338,12 +338,15 @@ void _Movetype_Impact(entity this, entity oth)  // SV_Impact
 
 void _Movetype_LinkEdict_TouchAreaGrid(entity this)  // SV_LinkEdict_TouchAreaGrid
 {
+       if(this.solid == SOLID_NOT)
+               return;
+
        entity oldother = other;
 
-       for (entity e = findradius(0.5 * (this.absmin + this.absmax), 0.5 * vlen(this.absmax - this.absmin)); e; e = e.chain)
-       {
-               if(e.move_nomonsters != MOVE_NOMONSTERS && e.move_nomonsters != MOVE_WORLDONLY)
-               if(e.move_touch && boxesoverlap(e.absmin, e.absmax, this.absmin, this.absmax))
+    FOREACH_ENTITY_RADIUS(0.5 * (this.absmin + this.absmax), 0.5 * vlen(this.absmax - this.absmin), true, {
+               if (it.solid == SOLID_TRIGGER && it != this)
+               if (it.move_nomonsters != MOVE_NOMONSTERS && it.move_nomonsters != MOVE_WORLDONLY)
+               if (gettouch(it) && boxesoverlap(it.absmin, it.absmax, this.absmin, this.absmax))
                {
                        other = this;
 
@@ -352,14 +355,14 @@ void _Movetype_LinkEdict_TouchAreaGrid(entity this)  // SV_LinkEdict_TouchAreaGr
                        trace_fraction = 1;
                        trace_inwater = false;
                        trace_inopen = true;
-                       trace_endpos = e.move_origin;
+                       trace_endpos = it.move_origin;
                        trace_plane_normal = '0 0 1';
                        trace_plane_dist = 0;
                        trace_ent = this;
 
-                       WITH(entity, self, e, e.move_touch());
+                       gettouch(it)(it);
                }
-       }
+    });
 
        other = oldother;
 }
@@ -407,8 +410,10 @@ void _Movetype_LinkEdict(entity this, bool touch_triggers)  // SV_LinkEdict
                _Movetype_LinkEdict_TouchAreaGrid(this);
 }
 
-bool _Movetype_TestEntityPosition(entity this, vector ofs)  // SV_TestEntityPosition
+entity _Movetype_TestEntityPosition_ent;
+bool _Movetype_TestEntityPosition(vector ofs)  // SV_TestEntityPosition
 {
+    entity this = _Movetype_TestEntityPosition_ent;
 //     vector org = this.move_origin + ofs;
 
        int cont = this.dphitcontentsmask;
@@ -419,31 +424,37 @@ bool _Movetype_TestEntityPosition(entity this, vector ofs)  // SV_TestEntityPosi
        if(trace_startsolid)
                return true;
 
-       if(vlen(trace_endpos - this.move_origin) > 0.0001)
+       if(vdist(trace_endpos - this.move_origin, >, 0.0001))
                this.move_origin = trace_endpos;
        return false;
 }
 
 bool _Movetype_UnstickEntity(entity this)  // SV_UnstickEntity
 {
-       if(!_Movetype_TestEntityPosition(this, '0 0 0')) return true;
-       if(!_Movetype_TestEntityPosition(this, '-1 0 0')) goto success;
-       if(!_Movetype_TestEntityPosition(this, '1 0 0')) goto success;
-       if(!_Movetype_TestEntityPosition(this, '0 -1 0')) goto success;
-       if(!_Movetype_TestEntityPosition(this, '0 1 0')) goto success;
-       if(!_Movetype_TestEntityPosition(this, '-1 -1 0')) goto success;
-       if(!_Movetype_TestEntityPosition(this, '1 -1 0')) goto success;
-       if(!_Movetype_TestEntityPosition(this, '-1 1 0')) goto success;
-       if(!_Movetype_TestEntityPosition(this, '1 1 0')) goto success;
-       for (int i = 1; i <= 17; ++i)
+    _Movetype_TestEntityPosition_ent = this;
+       if (!_Movetype_TestEntityPosition(' 0  0  0')) {
+           return true;
+       }
+       #define X(v) if (_Movetype_TestEntityPosition(v))
+       X('-1  0  0') X(' 1  0  0')
+       X(' 0 -1  0') X(' 0  1  0')
+       X('-1 -1  0') X(' 1 -1  0')
+       X('-1  1  0') X(' 1  1  0')
+       #undef X
        {
-               if(!_Movetype_TestEntityPosition(this, '0 0 -1' * i)) goto success;
-               if(!_Movetype_TestEntityPosition(this, '0 0 1' * i)) goto success;
+        #define X(i) \
+            if (_Movetype_TestEntityPosition('0 0 -1' * i)) \
+            if (_Movetype_TestEntityPosition('0 0 1' * i))
+        X(01) X(02) X(03) X(04) X(05) X(06) X(07) X(08)
+        X(09) X(10) X(11) X(12) X(13) X(14) X(15) X(16)
+        X(17)
+        #undef X
+        {
+            LOG_DEBUGF("Can't unstick an entity (edict: %d, classname: %s, origin: %s)\n",
+                etof(this), this.classname, vtos(this.move_origin));
+            return false;
+        }
        }
-       LOG_DEBUGF("Can't unstick an entity (edict: %d, classname: %s, origin: %s)\n",
-               etof(this), this.classname, vtos(this.move_origin));
-       return false;
-       : success;
        LOG_DEBUGF("Sucessfully unstuck an entity (edict: %d, classname: %s, origin: %s)\n",
                etof(this), this.classname, vtos(this.move_origin));
        _Movetype_LinkEdict(this, true);