]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
trigger_gravity: use .active instead of .state, remove magic numbers
authorFreddy <schro.sb@gmail.com>
Mon, 12 Mar 2018 14:32:27 +0000 (15:32 +0100)
committerFreddy <schro.sb@gmail.com>
Mon, 12 Mar 2018 14:32:27 +0000 (15:32 +0100)
qcsrc/common/triggers/spawnflags.qh
qcsrc/common/triggers/trigger/gravity.qc
qcsrc/common/triggers/trigger/relay_activators.qc
qcsrc/common/triggers/triggers.qc
qcsrc/common/triggers/triggers.qh

index f91b037fbec7da3b2a3346fe4254b33a053c78d5..eaf7914688c5546f961496619760539a5003de8d 100644 (file)
@@ -5,6 +5,10 @@ const int START_ENABLED = BIT(0);
 const int ON_MAPLOAD = BIT(1);
 const int NOSPLASH = BIT(8); // generic anti-splashdamage spawnflag
 
+// triggers
+const int SPAWNFLAG_NOMESSAGE = BIT(0);
+const int SPAWNFLAG_NOTOUCH = BIT(0); // why are these the same?
+
 // bobbing
 const int BOBBING_XAXIS = BIT(0);
 const int BOBBING_YAXIS = BIT(1);
@@ -96,13 +100,13 @@ const int TELEPORT_FLAG_PARTICLES = BIT(1);
 const int TELEPORT_FLAG_TDEATH = BIT(2);
 const int TELEPORT_FLAG_FORCE_TDEATH = BIT(3);
 
-// triggers
-const int SPAWNFLAG_NOMESSAGE = BIT(0);
-const int SPAWNFLAG_NOTOUCH = BIT(0); // why are these the same?
-
 // counter
 const int COUNTER_FIRE_AT_COUNT = BIT(2);
 
+// gravity
+const int GRAVITY_STICKY = BIT(0); // keep gravity multiplier even after exiting the trigger_gravity
+const int GRAVITY_START_DISABLED = BIT(1);
+
 //----------
 // SENDFLAGS
 //----------
index 3ea1562f084a93e4c73b7fdb0c9a26ac64dad90e..1ac0f8768d5d355b1a4b0d8d7cea8f97935c6cf5 100644 (file)
@@ -33,29 +33,31 @@ void trigger_gravity_check_think(entity this)
        }
 }
 
+// legacy
 void trigger_gravity_use(entity this, entity actor, entity trigger)
 {
-       this.state = !this.state;
+       this.setactive(this, ACTIVE_TOGGLE);
 }
 
 void trigger_gravity_touch(entity this, entity toucher)
 {
        float g;
 
-       if(this.state != true)
+       if(this.active == ACTIVE_NOT)
                return;
 
        EXACTTRIGGER_TOUCH(this, toucher);
 
        g = this.gravity;
 
-       if (!(this.spawnflags & 1))
+       if (!(this.spawnflags & GRAVITY_STICKY))
        {
                if(toucher.trigger_gravity_check)
                {
                        if(this == toucher.trigger_gravity_check.enemy)
                        {
                                // same?
+                               // NOTE: see explanation in trigger_gravity_check_think
                                toucher.trigger_gravity_check.count = 2; // gravity one more frame...
                                return;
                        }
@@ -96,12 +98,14 @@ spawnfunc(trigger_gravity)
        if(this.noise != "")
                precache_sound(this.noise);
 
-       this.state = true;
+       this.active = ACTIVE_ACTIVE;
+       this.setactive = generic_setactive;
        IFTARGETED
        {
+               // legacy use
                this.use = trigger_gravity_use;
-               if(this.spawnflags & 2)
-                       this.state = false;
+               if(this.spawnflags & GRAVITY_START_DISABLED)
+                       this.active = ACTIVE_NOT;
        }
 }
 #endif
index d713a05837728245f18a604f96647b5a300d40ca..18c2a40d01d569bb48cb1ba054484d1e624c4cfc 100644 (file)
@@ -9,13 +9,7 @@ void relay_activators_use(entity this, entity actor, entity trigger)
                else
                {
                        //bprint("Not using setactive\n");
-                       if(this.cnt == ACTIVE_TOGGLE)
-                               if(trg.active == ACTIVE_ACTIVE)
-                                       trg.active = ACTIVE_NOT;
-                               else
-                                       trg.active = ACTIVE_ACTIVE;
-                       else
-                               trg.active = this.cnt;
+                       generic_setactive(trg, this.cnt);
                }
        }
 }
index 034f66e1a8cef25fd5accec32f32ff769eeb6347..144f6bfb0de01681ce70239f3645b3f0d237b488 100644 (file)
@@ -21,9 +21,8 @@ void FixSize(entity e)
 }
 
 #ifdef SVQC
-void generic_netlinked_setactive(entity this, int act)
+void generic_setactive(entity this, int act)
 {
-       int old_status = this.active;
        if(act == ACTIVE_TOGGLE)
        {
                if(this.active == ACTIVE_ACTIVE)
@@ -39,6 +38,12 @@ void generic_netlinked_setactive(entity this, int act)
        {
                this.active = act;
        }
+}
+
+void generic_netlinked_setactive(entity this, int act)
+{
+       int old_status = this.active;
+       generic_setactive(this, act);
 
        if (this.active != old_status)
        {
index 681bb898ba14b2abe2b973b28e00d30aa4ea1d0d..1ecef76383b47e3d6cb4e25c2d18cef6bfaf02ba 100644 (file)
@@ -23,6 +23,7 @@ void target_voicescript_clear(entity pl);
 
 void SUB_UseTargets_PreventReuse(entity this, entity actor, entity trigger);
 
+void generic_setactive(entity this, int act);
 // generic methods for netlinked entities
 void generic_netlinked_reset(entity this);
 void generic_netlinked_setactive(entity this, int act);