]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/trigger/impulse.qc
Merge branch 'master' into terencehill/hud_shake_fix
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / trigger / impulse.qc
index d4368812f0be850fb52572cf0dbd2ed7fe56fef3..91381f4877c9954ccc54ca618640503cd32bd058 100644 (file)
@@ -1,12 +1,11 @@
-#ifdef SVQC
 // targeted (directional) mode
-void trigger_impulse_touch1()
+void trigger_impulse_touch1(entity this)
 {
        entity targ;
-    float pushdeltatime;
-    float str;
+       float pushdeltatime;
+       float str;
 
-       if (self.active != ACTIVE_ACTIVE)
+       if (this.active != ACTIVE_ACTIVE)
                return;
 
        if (!isPushable(other))
@@ -14,39 +13,72 @@ void trigger_impulse_touch1()
 
        EXACTTRIGGER_TOUCH;
 
-    targ = find(world, targetname, self.target);
-    if(!targ)
-    {
-        objerror("trigger_force without a (valid) .target!\n");
-        remove(self);
-        return;
-    }
-
-    str = min(self.radius, vlen(self.origin - other.origin));
-
-    if(self.falloff == 1)
-        str = (str / self.radius) * self.strength;
-    else if(self.falloff == 2)
-        str = (1 - (str / self.radius)) * self.strength;
-    else
-        str = self.strength;
-
-    pushdeltatime = time - other.lastpushtime;
-    if (pushdeltatime > 0.15) pushdeltatime = 0;
-    other.lastpushtime = time;
-    if(!pushdeltatime) return;
-
-    other.velocity = other.velocity + normalize(targ.origin - self.origin) * str * pushdeltatime;
-    other.flags &= ~FL_ONGROUND;
-    UpdateCSQCProjectile(other);
+       targ = find(NULL, targetname, this.target);
+       if(!targ)
+       {
+               objerror(this, "trigger_force without a (valid) .target!\n");
+               remove(this);
+               return;
+       }
+
+#ifdef SVQC
+       str = min(this.radius, vlen(this.origin - other.origin));
+#elif defined(CSQC)
+       str = min(this.radius, vlen(this.origin - other.move_origin));
+#endif
+
+       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;
+
+       pushdeltatime = time - other.lastpushtime;
+       if (pushdeltatime > 0.15) pushdeltatime = 0;
+       other.lastpushtime = time;
+       if(!pushdeltatime) return;
+
+       if(this.spawnflags & 64)
+       {
+#ifdef SVQC
+               float addspeed = str - other.velocity * normalize(targ.origin - this.origin);
+               if (addspeed > 0)
+               {
+                       float accelspeed = min(8 * pushdeltatime * str, addspeed);
+                       other.velocity += accelspeed * normalize(targ.origin - this.origin);
+               }
+#elif defined(CSQC)
+               float addspeed = str - other.move_velocity * normalize(targ.origin - this.origin);
+               if (addspeed > 0)
+               {
+                       float accelspeed = min(8 * pushdeltatime * str, addspeed);
+                       other.move_velocity += accelspeed * normalize(targ.origin - this.origin);
+               }
+#endif
+       }
+       else
+#ifdef SVQC
+               other.velocity = other.velocity + normalize(targ.origin - this.origin) * str * pushdeltatime;
+#elif defined(CSQC)
+               other.move_velocity = other.move_velocity + normalize(targ.origin - this.origin) * str * pushdeltatime;
+#endif
+
+#ifdef SVQC
+       UNSET_ONGROUND(other);
+
+       UpdateCSQCProjectile(other);
+#elif defined(CSQC)
+       other.move_flags &= ~FL_ONGROUND;
+#endif
 }
 
 // Directionless (accelerator/decelerator) mode
-void trigger_impulse_touch2()
+void trigger_impulse_touch2(entity this)
 {
-    float pushdeltatime;
+       float pushdeltatime;
 
-       if (self.active != ACTIVE_ACTIVE)
+       if (this.active != ACTIVE_ACTIVE)
                return;
 
        if (!isPushable(other))
@@ -54,23 +86,28 @@ void trigger_impulse_touch2()
 
        EXACTTRIGGER_TOUCH;
 
-    pushdeltatime = time - other.lastpushtime;
-    if (pushdeltatime > 0.15) pushdeltatime = 0;
-    other.lastpushtime = time;
-    if(!pushdeltatime) return;
+       pushdeltatime = time - other.lastpushtime;
+       if (pushdeltatime > 0.15) pushdeltatime = 0;
+       other.lastpushtime = time;
+       if(!pushdeltatime) return;
+
+       // div0: ticrate independent, 1 = identity (not 20)
+#ifdef SVQC
+       other.velocity = other.velocity * pow(this.strength, pushdeltatime);
 
-    // div0: ticrate independent, 1 = identity (not 20)
-    other.velocity = other.velocity * pow(self.strength, pushdeltatime);
-    UpdateCSQCProjectile(other);
+       UpdateCSQCProjectile(other);
+#elif defined(CSQC)
+       other.move_velocity = other.move_velocity * pow(this.strength, pushdeltatime);
+#endif
 }
 
 // Spherical (gravity/repulsor) mode
-void trigger_impulse_touch3()
+void trigger_impulse_touch3(entity this)
 {
-    float pushdeltatime;
-    float str;
+       float pushdeltatime;
+       float str;
 
-       if (self.active != ACTIVE_ACTIVE)
+       if (this.active != ACTIVE_ACTIVE)
                return;
 
        if (!isPushable(other))
@@ -78,34 +115,45 @@ void trigger_impulse_touch3()
 
        EXACTTRIGGER_TOUCH;
 
-    pushdeltatime = time - other.lastpushtime;
-    if (pushdeltatime > 0.15) pushdeltatime = 0;
-    other.lastpushtime = time;
-    if(!pushdeltatime) return;
+       pushdeltatime = time - other.lastpushtime;
+       if (pushdeltatime > 0.15) pushdeltatime = 0;
+       other.lastpushtime = time;
+       if(!pushdeltatime) return;
 
-    setsize(self, '-1 -1 -1' * self.radius,'1 1 1' * self.radius);
+       setsize(this, '-1 -1 -1' * this.radius,'1 1 1' * this.radius);
 
-       str = min(self.radius, vlen(self.origin - other.origin));
+#ifdef SVQC
+       str = min(this.radius, vlen(this.origin - other.origin));
+#elif defined(CSQC)
+       str = min(this.radius, vlen(this.origin - other.move_origin));
+#endif
 
-    if(self.falloff == 1)
-        str = (1 - str / self.radius) * self.strength; // 1 in the inside
-    else if(self.falloff == 2)
-        str = (str / self.radius) * self.strength; // 0 in the inside
-    else
-        str = self.strength;
+       if(this.falloff == 1)
+               str = (1 - str / this.radius) * this.strength; // 1 in the inside
+       else if(this.falloff == 2)
+               str = (str / this.radius) * this.strength; // 0 in the inside
+       else
+               str = this.strength;
+
+#ifdef SVQC
+       other.velocity = other.velocity + normalize(other.origin - this.origin) * str * pushdeltatime;
 
-    other.velocity = other.velocity + normalize(other.origin - self.origin) * str * pushdeltatime;
-    UpdateCSQCProjectile(other);
+       UpdateCSQCProjectile(other);
+#elif defined(CSQC)
+       other.move_velocity = other.move_velocity + normalize(other.move_origin - this.origin) * str * pushdeltatime;
+#endif
 }
 
+REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_IMPULSE)
+
 /*QUAKED spawnfunc_trigger_impulse (.5 .5 .5) ?
 -------- 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.
+                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)
+                  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)
 
 radius   : If set, act as a spherical device rather then a liniar one.
 
@@ -115,32 +163,76 @@ falloff : 0 = none, 1 = liniar, 2 = inverted liniar
 Use a brush textured with common/origin in the trigger entity to determine the origin of the force
 in directional and sperical mode. For damper/accelerator mode this is not nessesary (and has no effect).
 */
+#ifdef SVQC
+bool trigger_impulse_send(entity this, entity to, int sf)
+{
+       WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_IMPULSE);
 
-void spawnfunc_trigger_impulse()
+       WriteInt24_t(MSG_ENTITY, this.spawnflags);
+       WriteCoord(MSG_ENTITY, this.radius);
+       WriteCoord(MSG_ENTITY, this.strength);
+       WriteByte(MSG_ENTITY, this.falloff);
+       WriteByte(MSG_ENTITY, this.active);
+
+       trigger_common_write(this, true);
+
+       return true;
+}
+
+void trigger_impulse_link(entity this)
+{
+       trigger_link(this, trigger_impulse_send);
+}
+
+spawnfunc(trigger_impulse)
+{
+       this.active = ACTIVE_ACTIVE;
+
+       trigger_init(this);
+
+       if(this.radius)
+       {
+               if(!this.strength) this.strength = 2000 * 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);
+       }
+       else
+       {
+               if(this.target)
+               {
+                       if(!this.strength) this.strength = 950 * autocvar_g_triggerimpulse_directional_multiplier;
+                       settouch(this, trigger_impulse_touch1);
+               }
+               else
+               {
+                       if(!this.strength) this.strength = 0.9;
+                       this.strength = pow(this.strength, autocvar_g_triggerimpulse_accel_power) * autocvar_g_triggerimpulse_accel_multiplier;
+                       settouch(this, trigger_impulse_touch2);
+               }
+       }
+
+       trigger_impulse_link(this);
+}
+#elif defined(CSQC)
+NET_HANDLE(ENT_CLIENT_TRIGGER_IMPULSE, bool isnew)
 {
-       self.active = ACTIVE_ACTIVE;
-
-       EXACTTRIGGER_INIT;
-    if(self.radius)
-    {
-        if(!self.strength) self.strength = 2000 * autocvar_g_triggerimpulse_radial_multiplier;
-        setorigin(self, self.origin);
-        setsize(self, '-1 -1 -1' * self.radius,'1 1 1' * self.radius);
-        self.touch = trigger_impulse_touch3;
-    }
-    else
-    {
-        if(self.target)
-        {
-            if(!self.strength) self.strength = 950 * autocvar_g_triggerimpulse_directional_multiplier;
-            self.touch = trigger_impulse_touch1;
-        }
-        else
-        {
-            if(!self.strength) self.strength = 0.9;
-                       self.strength = pow(self.strength, autocvar_g_triggerimpulse_accel_power) * autocvar_g_triggerimpulse_accel_multiplier;
-            self.touch = trigger_impulse_touch2;
-        }
-    }
+       this.spawnflags = ReadInt24_t();
+       this.radius = ReadCoord();
+       this.strength = ReadCoord();
+       this.falloff = ReadByte();
+       this.active = ReadByte();
+
+       trigger_common_read(this, true);
+       return = true;
+
+       this.classname = "trigger_impulse";
+       this.solid = SOLID_TRIGGER;
+       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); }
 }
 #endif