]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Cleanup for trigger_impulse
authorFreddy <schro.sb@gmail.com>
Mon, 12 Mar 2018 17:28:01 +0000 (18:28 +0100)
committerFreddy <schro.sb@gmail.com>
Mon, 12 Mar 2018 18:58:03 +0000 (19:58 +0100)
qcsrc/common/triggers/spawnflags.qh
qcsrc/common/triggers/trigger/impulse.qc
qcsrc/common/triggers/trigger/impulse.qh

index c4b9746314aa11d5ff427cf5da7e5ccaf9f79ab6..c1ef338b262660dd5f1784a4a6721e56d8924352 100644 (file)
@@ -111,6 +111,9 @@ const int GRAVITY_START_DISABLED = BIT(1);
 // heal
 const int HEAL_SOUND_ALWAYS = BIT(2);
 
+// impulse
+const int IMPULSE_DIRECTIONAL_SPEEDTARGET = BIT(6);
+
 //----------
 // SENDFLAGS
 //----------
index 4be6e86bca66c6c02fcf2adbd3c7141721292647..c4e7ae287a8e9a6eda6d79532d0c06684cc38b6b 100644 (file)
@@ -1,6 +1,6 @@
 #include "impulse.qh"
 // targeted (directional) mode
-void trigger_impulse_touch1(entity this, entity toucher)
+void trigger_impulse_touch_directional(entity this, entity toucher)
 {
        entity targ;
        float pushdeltatime;
@@ -22,26 +22,26 @@ void trigger_impulse_touch1(entity this, entity toucher)
                return;
        }
 
-       str = min(this.radius, vlen(this.origin - toucher.origin));
-
-       if(this.falloff == 1)
-               str = (str / this.radius) * this.strength;
-       else if(this.falloff == 2)
-               str = (1 - (str / this.radius)) * this.strength;
-       else
-               str = this.strength;
+       // falloff is not supported because radius is always 0 in directional mode
+       str = this.strength;
 
        pushdeltatime = time - toucher.lastpushtime;
-       if (pushdeltatime > 0.15) pushdeltatime = 0;
+       if (pushdeltatime > IMPULSE_MAX_PUSHDELTATIME)
+       {
+               pushdeltatime = 0;
+       }
        toucher.lastpushtime = time;
-       if(!pushdeltatime) return;
+       if(!pushdeltatime)
+       {
+               return;
+       }
 
-       if(this.spawnflags & 64)
+       if(this.spawnflags & IMPULSE_DIRECTIONAL_SPEEDTARGET)
        {
                float addspeed = str - toucher.velocity * normalize(targ.origin - this.origin);
                if (addspeed > 0)
                {
-                       float accelspeed = min(8 * pushdeltatime * str, addspeed);
+                       float accelspeed = min(IMPULSE_DIRECTIONAL_MAX_ACCEL_FACTOR * pushdeltatime * str, addspeed);
                        toucher.velocity += accelspeed * normalize(targ.origin - this.origin);
                }
        }
@@ -56,7 +56,7 @@ void trigger_impulse_touch1(entity this, entity toucher)
 }
 
 // Directionless (accelerator/decelerator) mode
-void trigger_impulse_touch2(entity this, entity toucher)
+void trigger_impulse_touch_accel(entity this, entity toucher)
 {
        float pushdeltatime;
 
@@ -69,9 +69,15 @@ void trigger_impulse_touch2(entity this, entity toucher)
        EXACTTRIGGER_TOUCH(this, toucher);
 
        pushdeltatime = time - toucher.lastpushtime;
-       if (pushdeltatime > 0.15) pushdeltatime = 0;
+       if (pushdeltatime > IMPULSE_MAX_PUSHDELTATIME)
+       {
+               pushdeltatime = 0;
+       }
        toucher.lastpushtime = time;
-       if(!pushdeltatime) return;
+       if(!pushdeltatime)
+       {
+               return;
+       }
 
        // div0: ticrate independent, 1 = identity (not 20)
        toucher.velocity = toucher.velocity * (this.strength ** pushdeltatime);
@@ -82,7 +88,7 @@ void trigger_impulse_touch2(entity this, entity toucher)
 }
 
 // Spherical (gravity/repulsor) mode
-void trigger_impulse_touch3(entity this, entity toucher)
+void trigger_impulse_touch_radial(entity this, entity toucher)
 {
        float pushdeltatime;
        float str;
@@ -96,17 +102,23 @@ void trigger_impulse_touch3(entity this, entity toucher)
        EXACTTRIGGER_TOUCH(this, toucher);
 
        pushdeltatime = time - toucher.lastpushtime;
-       if (pushdeltatime > 0.15) pushdeltatime = 0;
+       if (pushdeltatime > IMPULSE_MAX_PUSHDELTATIME)
+       {
+               pushdeltatime = 0;
+       }
        toucher.lastpushtime = time;
-       if(!pushdeltatime) return;
+       if(!pushdeltatime)
+       {
+               return;
+       }
 
        setsize(this, '-1 -1 -1' * this.radius,'1 1 1' * this.radius);
 
        str = min(this.radius, vlen(this.origin - toucher.origin));
 
-       if(this.falloff == 1)
+       if(this.falloff == FALLOFF_LINEAR)
                str = (1 - str / this.radius) * this.strength; // 1 in the inside
-       else if(this.falloff == 2)
+       else if(this.falloff == FALLOFF_LINEAR_INV)
                str = (str / this.radius) * this.strength; // 0 in the inside
        else
                str = this.strength;
@@ -121,15 +133,16 @@ void trigger_impulse_touch3(entity this, entity toucher)
 REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_IMPULSE)
 
 /*QUAKED spawnfunc_trigger_impulse (.5 .5 .5) ?
+Force field
 -------- KEYS --------
 target : If this is set, this points to the spawnfunc_target_position to which the player will get pushed.
                 If not, this trigger acts like a damper/accelerator field.
 
-strength : This is how mutch force to add in the direction of .target each second
-                  when .target is set. If not, this is hoe mutch to slow down/accelerate
-                  someting cought inside this trigger. (1=no change, 0,5 half speed rougthly each tic, 2 = doubble)
+strength : This is how much force to add in the direction of .target each second
+                  when .target is set. If not, this is how much to slow down/accelerate
+                  something cought inside this trigger. (1=no change, 0,5 half speed rougthly each tic, 2 = doubble)
 
-radius   : If set, act as a spherical device rather then a liniar one.
+radius   : If set, act as a spherical device rather then a linear one.
 
 falloff : 0 = none, 1 = liniar, 2 = inverted liniar
 
@@ -142,7 +155,7 @@ bool trigger_impulse_send(entity this, entity to, int sf)
 {
        WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_IMPULSE);
 
-       WriteInt24_t(MSG_ENTITY, this.spawnflags);
+       WriteByte(MSG_ENTITY, this.spawnflags);
        WriteCoord(MSG_ENTITY, this.radius);
        WriteCoord(MSG_ENTITY, this.strength);
        WriteByte(MSG_ENTITY, this.falloff);
@@ -166,23 +179,32 @@ spawnfunc(trigger_impulse)
 
        if(this.radius)
        {
-               if(!this.strength) this.strength = 2000 * autocvar_g_triggerimpulse_radial_multiplier;
+               if(!this.strength)
+               {
+                       this.strength = IMPULSE_DEFAULT_RADIAL_STRENGTH * autocvar_g_triggerimpulse_radial_multiplier;
+               }
                setorigin(this, this.origin);
                setsize(this, '-1 -1 -1' * this.radius,'1 1 1' * this.radius);
-               settouch(this, trigger_impulse_touch3);
+               settouch(this, trigger_impulse_touch_radial);
        }
        else
        {
                if(this.target)
                {
-                       if(!this.strength) this.strength = 950 * autocvar_g_triggerimpulse_directional_multiplier;
-                       settouch(this, trigger_impulse_touch1);
+                       if(!this.strength)
+                       {
+                               this.strength = IMPULSE_DEFAULT_DIRECTIONAL_STRENGTH * autocvar_g_triggerimpulse_directional_multiplier;
+                       }
+                       settouch(this, trigger_impulse_touch_directional);
                }
                else
                {
-                       if(!this.strength) this.strength = 0.9;
+                       if(!this.strength)
+                       {
+                               this.strength = IMPULSE_DEFAULT_ACCEL_STRENGTH;
+                       }
                        this.strength = (this.strength ** autocvar_g_triggerimpulse_accel_power) * autocvar_g_triggerimpulse_accel_multiplier;
-                       settouch(this, trigger_impulse_touch2);
+                       settouch(this, trigger_impulse_touch_accel);
                }
        }
 
@@ -191,7 +213,7 @@ spawnfunc(trigger_impulse)
 #elif defined(CSQC)
 NET_HANDLE(ENT_CLIENT_TRIGGER_IMPULSE, bool isnew)
 {
-       this.spawnflags = ReadInt24_t();
+       this.spawnflags = ReadByte();
        this.radius = ReadCoord();
        this.strength = ReadCoord();
        this.falloff = ReadByte();
@@ -205,8 +227,17 @@ NET_HANDLE(ENT_CLIENT_TRIGGER_IMPULSE, bool isnew)
        this.entremove = trigger_remove_generic;
        this.move_time = time;
 
-       if (this.radius) { settouch(this, trigger_impulse_touch3); }
-       else if (this.target) { settouch(this, trigger_impulse_touch1); }
-       else { settouch(this, trigger_impulse_touch2); }
+       if (this.radius)
+       {
+               settouch(this, trigger_impulse_touch_radial);
+       }
+       else if (this.target)
+       {
+               settouch(this, trigger_impulse_touch_directional);
+       }
+       else
+       {
+               settouch(this, trigger_impulse_touch_accel);
+       }
 }
 #endif
index a6961f5d2e7693920f56dac39df1d78011b88f91..5c3ff7bc90c0671e1562bb1202a04f5d95518e22 100644 (file)
@@ -2,6 +2,18 @@
 
 // tZorks trigger impulse / gravity
 .float radius;
-.float falloff;
+.int falloff;
 .float strength;
 .float lastpushtime;
+
+const int FALLOFF_NO = 0;
+const int FALLOFF_LINEAR = 1;
+const int FALLOFF_LINEAR_INV = 2;
+
+const float IMPULSE_DEFAULT_RADIAL_STRENGTH = 2000;
+const float IMPULSE_DEFAULT_DIRECTIONAL_STRENGTH = 950;
+const float IMPULSE_DEFAULT_ACCEL_STRENGTH = 0.9;
+
+const float IMPULSE_MAX_PUSHDELTATIME = 0.15;
+
+const float IMPULSE_DIRECTIONAL_MAX_ACCEL_FACTOR = 8;