]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Conveyors: use .active instead of .state
authorFreddy <schro.sb@gmail.com>
Wed, 7 Mar 2018 16:20:55 +0000 (17:20 +0100)
committerFreddy <schro.sb@gmail.com>
Wed, 7 Mar 2018 16:20:55 +0000 (17:20 +0100)
qcsrc/common/triggers/func/conveyor.qc
qcsrc/common/triggers/states.qh
qcsrc/ecs/systems/physics.qc

index 375a6adb867bca7c02d800a7a26c05b43548b31d..acb6529ff3c196a1853b3213f500b47e29eb5c54 100644 (file)
@@ -17,9 +17,9 @@ void conveyor_think(entity this)
                IL_REMOVE(g_conveyed, it);
        });
 
-       if(this.state)
+       if(this.active)
        {
-               FOREACH_ENTITY_RADIUS((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1, !it.conveyor.state && isPushable(it),
+               FOREACH_ENTITY_RADIUS((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1, !it.conveyor.active && isPushable(it),
                {
                        vector emin = it.absmin;
                        vector emax = it.absmax;
@@ -63,18 +63,49 @@ void conveyor_think(entity this)
 
 #ifdef SVQC
 
-void conveyor_use(entity this, entity actor, entity trigger)
+void conveyor_setactive(entity this, int act)
 {
-       this.state = !this.state;
+       int old_status = this.active;
+       if(act == ACTIVE_TOGGLE)
+       {
+               if(this.active == ACTIVE_ACTIVE)
+               {
+                       this.active = ACTIVE_NOT;
+               }
+               else
+               {
+                       this.active = ACTIVE_ACTIVE;
+               }
+       }
+       else
+       {
+               this.active = act;
+       }
 
-       this.SendFlags |= SF_TRIGGER_UPDATE;
+       if (this.active != old_status)
+       {
+               this.SendFlags |= SF_TRIGGER_UPDATE;
+       }
+}
+
+// Compatibility with old maps
+void conveyor_use(entity this, entity actor, entity trigger)
+{
+       conveyor_setactive(this, ACTIVE_TOGGLE);
 }
 
 void conveyor_reset(entity this)
 {
-       if(this.spawnflags & CONVEYOR_START_ENABLED)
+       IFTARGETED
        {
-               this.state = STATE_ON;
+               if(this.spawnflags & CONVEYOR_START_ENABLED)
+               {
+                       this.active = ACTIVE_ACTIVE;
+               }
+       }
+       else
+       {
+               this.active = ACTIVE_ACTIVE;
        }
 
        this.SendFlags |= SF_TRIGGER_UPDATE;
@@ -96,14 +127,14 @@ bool conveyor_send(entity this, entity to, int sendflags)
                WriteVector(MSG_ENTITY, this.movedir);
 
                WriteByte(MSG_ENTITY, this.speed);
-               WriteByte(MSG_ENTITY, this.state);
+               WriteByte(MSG_ENTITY, this.active);
 
                WriteString(MSG_ENTITY, this.targetname);
                WriteString(MSG_ENTITY, this.target);
        }
 
        if(sendflags & SF_TRIGGER_UPDATE)
-               WriteByte(MSG_ENTITY, this.state);
+               WriteByte(MSG_ENTITY, this.active);
 
        return true;
 }
@@ -114,14 +145,14 @@ void conveyor_init(entity this)
        this.movedir *= this.speed;
        setthink(this, conveyor_think);
        this.nextthink = time;
+       this.setactive = conveyor_setactive;
        IFTARGETED
        {
+               // backwards compatibility
                this.use = conveyor_use;
-               this.reset = conveyor_reset;
-               this.reset(this);
        }
-       else
-               this.state = STATE_ON;
+       this.reset = conveyor_reset;
+       this.reset(this);
 
        FixSize(this);
 
@@ -179,7 +210,7 @@ NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew)
                this.movedir = ReadVector();
 
                this.speed = ReadByte();
-               this.state = ReadByte();
+               this.active = ReadByte();
 
                this.targetname = strzone(ReadString());
                this.target = strzone(ReadString());
@@ -188,7 +219,7 @@ NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew)
        }
 
        if(sendflags & SF_TRIGGER_UPDATE)
-               this.state = ReadByte();
+               this.active = ReadByte();
 
        return true;
 }
index ace3de8f378c30885e0428e0b66cbbfe27a77c60..6ed47df3db48e8e99e7c7fe4c05127f707516d54 100644 (file)
@@ -8,10 +8,6 @@ const int STATE_UP = 2;
 const int STATE_DOWN = 3;
 #endif
 
-// generic
-const int STATE_OFF = 0;
-const int STATE_ON = 1;
-
 // breakable
 const int STATE_ALIVE = 0;
 const int STATE_BROKEN = 1;
index c8b459962eb0102247c4f308459d680e2965cf76..8896b5a442ba42d78c4420ee3c0332dacb2956c6 100644 (file)
@@ -43,7 +43,7 @@ void sys_phys_update(entity this, float dt)
        float maxspeed_mod = (!this.in_swamp) ? 1 : this.swamp_slowdown;  // cvar("g_balance_swamp_moverate");
 
 // conveyors: first fix velocity
-       if (this.conveyor.state) { this.velocity -= this.conveyor.movedir; }
+       if (this.conveyor.active) { this.velocity -= this.conveyor.movedir; }
        MUTATOR_CALLHOOK(PlayerPhysics, this, dt);
 
        if (!IS_PLAYER(this)) {
@@ -156,7 +156,7 @@ void sys_phys_update(entity this, float dt)
        LABEL(end)
        if (IS_ONGROUND(this)) { this.lastground = time; }
 // conveyors: then break velocity again
-       if (this.conveyor.state) { this.velocity += this.conveyor.movedir; }
+       if (this.conveyor.active) { this.velocity += this.conveyor.movedir; }
        this.lastflags = this.flags;
 
        this.lastclassname = this.classname;