]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mapobjects/func/ladder.qc
Remove legacy Quake bbox expansion: map entities
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / func / ladder.qc
index 020ecca0855beb2260ad48608fd77bf917286b39..d60c28abc81cf04cb54c0d390a4166a8b5c36da8 100644 (file)
@@ -1,22 +1,36 @@
 #include "ladder.qh"
 REGISTER_NET_LINKED(ENT_CLIENT_LADDER)
 
-void func_ladder_touch(entity this, entity toucher)
+void func_ladder_think(entity this)
 {
-#ifdef SVQC
-       if (!toucher.iscreature)
-               return;
-       if(IS_VEHICLE(toucher))
-               return;
-#elif defined(CSQC)
-       if(!toucher.isplayermodel)
-               return;
+
+#ifdef CSQC
+       // TODO: check if this is what is causing the glitchiness when switching between them
+       float dt = time - this.move_time;
+       this.move_time = time;
+       if(dt <= 0) { return; }
 #endif
 
-       EXACTTRIGGER_TOUCH(this, toucher);
+       // set myself as current ladders where possible
+       IL_EACH(g_ladderents, it.ladder_entity == this,
+       {
+               it.ladder_entity = NULL;
+               IL_REMOVE(g_ladderents, it);
+       });
 
-       toucher.ladder_time = time + 0.1;
-       toucher.ladder_entity = this;
+       FOREACH_ENTITY_RADIUS((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1, !it.ladder_entity && IS_PLAYER(it) && it.move_movetype != MOVETYPE_NOCLIP && !IS_DEAD(it),
+       {
+               if (WarpZoneLib_ExactTrigger_Touch(this, it, false))
+               {
+                       if(!it.ladder_entity)
+                               IL_PUSH(g_ladderents, it);
+                       it.ladder_entity = this;
+               }
+       });
+
+#ifdef SVQC
+       this.nextthink = time;
+#endif
 }
 
 #ifdef SVQC
@@ -41,9 +55,11 @@ void func_ladder_link(entity this)
 
 void func_ladder_init(entity this)
 {
-       settouch(this, func_ladder_touch);
-       trigger_init(this);
+       EXACTTRIGGER_INIT;
+       BITSET_ASSIGN(this.effects, EF_NODEPTHTEST);
        func_ladder_link(this);
+       setthink(this, func_ladder_think);
+       this.nextthink = time;
 
        if(min(this.absmax.x - this.absmin.x, this.absmax.y - this.absmin.y) > 100)
                return;
@@ -97,9 +113,9 @@ void func_ladder_init(entity this)
                        }
                }
        }
+       delete(tracetest_ent);
        if(trace_startsolid || trace_endpos.z < this.absmax.z)
        {
-               delete(tracetest_ent);
                return;
        }
 
@@ -124,8 +140,15 @@ spawnfunc(func_water)
 #elif defined(CSQC)
 .float speed;
 
+void func_ladder_draw(entity this) { func_ladder_think(this); }
+
 void func_ladder_remove(entity this)
 {
+       IL_EACH(g_ladderents, it.ladder_entity == this,
+       {
+               it.ladder_entity = NULL;
+               IL_REMOVE(g_ladderents, it);
+       });
        strfree(this.classname);
 }
 
@@ -134,12 +157,15 @@ NET_HANDLE(ENT_CLIENT_LADDER, bool isnew)
        this.classname = strzone(ReadString());
        this.skin = ReadByte();
        this.speed = ReadCoord();
+       this.solid = SOLID_TRIGGER;
 
        trigger_common_read(this, false);
 
-       this.solid = SOLID_TRIGGER;
-       settouch(this, func_ladder_touch);
+       if(isnew)
+               IL_PUSH(g_drawables, this);
+       this.draw = func_ladder_draw;
        this.drawmask = MASK_NORMAL;
+
        this.move_time = time;
        this.entremove = func_ladder_remove;