]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/func/conveyor.qc
Merge branch 'master' into TimePath/scrollpanel
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / conveyor.qc
index e86eefb2c10158c3ae4bfadd7a106bbc0e4eee99..1802a75db4a96a74ab2b56eb9531a748923bfa91 100644 (file)
@@ -1,3 +1,4 @@
+#include "conveyor.qh"
 REGISTER_NET_LINKED(ENT_CLIENT_CONVEYOR)
 
 void conveyor_think(entity this)
@@ -8,47 +9,51 @@ void conveyor_think(entity this)
        this.move_time = time;
        if(dt <= 0) { return; }
 #endif
-       entity e;
 
-       // set mythis as current conveyor where possible
-       for(e = world; (e = findentity(e, conveyor, this)); )
-               e.conveyor = world;
+       // set myself as current conveyor where possible
+       IL_EACH(g_conveyed, it.conveyor == this,
+       {
+               it.conveyor = NULL;
+               IL_REMOVE(g_conveyed, it);
+       });
 
        if(this.state)
        {
-               for(e = findradius((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1); e; e = e.chain)
-                       if(!e.conveyor.state)
-                               if(isPushable(e))
+               FOREACH_ENTITY_RADIUS((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1, !it.conveyor.state && isPushable(it),
+               {
+                       vector emin = it.absmin;
+                       vector emax = it.absmax;
+                       if(this.solid == SOLID_BSP)
+                       {
+                               emin -= '1 1 1';
+                               emax += '1 1 1';
+                       }
+                       if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick
+                               if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, it)) // accurate
                                {
-                                       vector emin = e.absmin;
-                                       vector emax = e.absmax;
-                                       if(this.solid == SOLID_BSP)
-                                       {
-                                               emin -= '1 1 1';
-                                               emax += '1 1 1';
-                                       }
-                                       if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick
-                                               if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, e)) // accurate
-                                                       e.conveyor = this;
+                                       if(!it.conveyor)
+                                               IL_PUSH(g_conveyed, it);
+                                       it.conveyor = this;
                                }
+               });
 
-               for(e = world; (e = findentity(e, conveyor, this)); )
+               IL_EACH(g_conveyed, it.conveyor == this,
                {
-                       if(IS_CLIENT(e)) // doing it via velocity has quite some advantages
+                       if(IS_CLIENT(it)) // doing it via velocity has quite some advantages
                                continue; // done in SV_PlayerPhysics   continue;
 
-                       setorigin(e, e.origin + this.movedir * PHYS_INPUT_FRAMETIME);
-                       move_out_of_solid(e);
+                       setorigin(it, it.origin + this.movedir * PHYS_INPUT_FRAMETIME);
+                       move_out_of_solid(it);
 #ifdef SVQC
-                       UpdateCSQCProjectile(e);
+                       UpdateCSQCProjectile(it);
 #endif
                        /*
                        // stupid conveyor code
-                       tracebox(e.origin, e.mins, e.maxs, e.origin + this.movedir * sys_frametime, MOVE_NORMAL, e);
+                       tracebox(it.origin, it.mins, it.maxs, it.origin + this.movedir * sys_frametime, MOVE_NORMAL, it);
                        if(trace_fraction > 0)
-                               setorigin(e, trace_endpos);
+                               setorigin(it, trace_endpos);
                        */
-               }
+               });
        }
 
 #ifdef SVQC
@@ -80,20 +85,12 @@ bool conveyor_send(entity this, entity to, int sf)
        if(sf & 1)
        {
                WriteByte(MSG_ENTITY, this.warpzone_isboxy);
-               WriteCoord(MSG_ENTITY, this.origin_x);
-               WriteCoord(MSG_ENTITY, this.origin_y);
-               WriteCoord(MSG_ENTITY, this.origin_z);
+               WriteVector(MSG_ENTITY, this.origin);
 
-               WriteCoord(MSG_ENTITY, this.mins_x);
-               WriteCoord(MSG_ENTITY, this.mins_y);
-               WriteCoord(MSG_ENTITY, this.mins_z);
-               WriteCoord(MSG_ENTITY, this.maxs_x);
-               WriteCoord(MSG_ENTITY, this.maxs_y);
-               WriteCoord(MSG_ENTITY, this.maxs_z);
+               WriteVector(MSG_ENTITY, this.mins);
+               WriteVector(MSG_ENTITY, this.maxs);
 
-               WriteCoord(MSG_ENTITY, this.movedir_x);
-               WriteCoord(MSG_ENTITY, this.movedir_y);
-               WriteCoord(MSG_ENTITY, this.movedir_z);
+               WriteVector(MSG_ENTITY, this.movedir);
 
                WriteByte(MSG_ENTITY, this.speed);
                WriteByte(MSG_ENTITY, this.state);
@@ -141,23 +138,24 @@ spawnfunc(func_conveyor)
 {
        SetMovedir(this);
        InitMovingBrushTrigger(this);
-       this.movetype = MOVETYPE_NONE;
+       set_movetype(this, MOVETYPE_NONE);
        conveyor_init(this);
 }
 
 #elif defined(CSQC)
 
-void conveyor_draw(entity this) { WITHSELF(this, conveyor_think(this)); }
+void conveyor_draw(entity this) { conveyor_think(this); }
 
-void conveyor_init(entity this)
+void conveyor_init(entity this, bool isnew)
 {
+       if(isnew)
+               IL_PUSH(g_drawables, this);
        this.draw = conveyor_draw;
        this.drawmask = MASK_NORMAL;
 
-       this.movetype = MOVETYPE_NONE;
+       set_movetype(this, MOVETYPE_NONE);
        this.model = "";
        this.solid = SOLID_TRIGGER;
-       this.move_origin = this.origin;
        this.move_time = time;
 }
 
@@ -168,22 +166,14 @@ NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew)
        if(sf & 1)
        {
                this.warpzone_isboxy = ReadByte();
-               this.origin_x = ReadCoord();
-               this.origin_y = ReadCoord();
-               this.origin_z = ReadCoord();
+               this.origin = ReadVector();
                setorigin(this, this.origin);
 
-               this.mins_x = ReadCoord();
-               this.mins_y = ReadCoord();
-               this.mins_z = ReadCoord();
-               this.maxs_x = ReadCoord();
-               this.maxs_y = ReadCoord();
-               this.maxs_z = ReadCoord();
+               this.mins = ReadVector();
+               this.maxs = ReadVector();
                setsize(this, this.mins, this.maxs);
 
-               this.movedir_x = ReadCoord();
-               this.movedir_y = ReadCoord();
-               this.movedir_z = ReadCoord();
+               this.movedir = ReadVector();
 
                this.speed = ReadByte();
                this.state = ReadByte();
@@ -191,7 +181,7 @@ NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew)
                this.targetname = strzone(ReadString());
                this.target = strzone(ReadString());
 
-               conveyor_init(this);
+               conveyor_init(this, isnew);
        }
 
        if(sf & 2)