]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mapobjects/trigger/jumppads.qc
target_push: implement Q3 wind tunnel and angles+speed modes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / trigger / jumppads.qc
index f7281e5e4ae2619098dffa22cefb386b9236105f..5ded24a28c0b27559110e9164c308c845061270d 100644 (file)
@@ -242,6 +242,25 @@ vector trigger_push_velocity_calculatevelocity(entity this, vector org, entity t
        return vs + '0 0 1' * vz;
 }
 
+#ifdef SVQC
+void trigger_push_velocity_think(entity this)
+{
+       bool found = false;
+       IL_EACH(g_moveables, it.last_pushed == this,
+       {
+               if(!WarpZoneLib_ExactTrigger_Touch(this, it, false))
+                       it.last_pushed = NULL;
+               else
+                       found = true;
+       });
+
+       if(found)
+               this.nextthink = time;
+       else
+               setthink(this, func_null);
+}
+#endif
+
 bool jumppad_push(entity this, entity targ, bool is_velocity_pad)
 {
        if (!isPushable(targ))
@@ -249,7 +268,7 @@ bool jumppad_push(entity this, entity targ, bool is_velocity_pad)
 
        vector org = targ.origin;
 
-       if(Q3COMPAT_COMMON || this.spawnflags & PUSH_STATIC)
+       if(Q3COMPAT_COMMON || (this.spawnflags & PUSH_STATIC))
                org = (this.absmin + this.absmax) * 0.5;
 
        bool already_pushed = false;
@@ -262,6 +281,11 @@ bool jumppad_push(entity this, entity targ, bool is_velocity_pad)
                else
                {
                        targ.last_pushed = this; // may be briefly out of sync between client and server if client prediction is toggled
+
+                       #ifdef SVQC
+                       setthink(this, trigger_push_velocity_think);
+                       this.nextthink = time;
+                       #endif
                }
        }
 
@@ -341,11 +365,17 @@ bool jumppad_push(entity this, entity targ, bool is_velocity_pad)
                // or when a dead player gets stuck in the jumppad for some reason
                if(!already_pushed && this.pushltime < time && !(IS_DEAD(targ) && targ.velocity == '0 0 0'))
                {
-                       // flash when activated
-                       Send_Effect(EFFECT_JUMPPAD, targ.origin, targ.velocity, 1);
+                       if (Q3COMPAT_COMMON && this.classname == "target_push")
+                               this.pushltime = time + 1.5;
+                       else
+                       {
+                               // flash when activated
+                               Send_Effect(EFFECT_JUMPPAD, targ.origin, targ.velocity, 1);
+                               this.pushltime = time + 0.2;
+                       }
                        _sound (targ, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
-                       this.pushltime = time + 0.2;
                }
+
                if(IS_REAL_CLIENT(targ) || IS_BOT_CLIENT(targ))
                {
                        bool found = false;
@@ -588,7 +618,10 @@ bool trigger_push_test(entity this, entity item)
                        }
                        else
                        {
-                               if (trigger_push_testorigin(e, t, this, org))
+                               // optimization: if horizontal velocity is 0 then target is not good since the trajectory
+                               // will definitely go back to the jumppad (horizontal velocity of best_vel can't be 0 anyway)
+                               if ((e.velocity.x != 0 || e.velocity.y != 0)
+                                       && trigger_push_testorigin(e, t, this, org))
                                {
                                        best_target = trace_endpos;
                                        best_org = org;
@@ -776,7 +809,7 @@ void trigger_push_velocity_link(entity this)
  *            or OUTSIDE (negative) of the jump trajectory. General rule: use
  *            positive values for targets mounted on the floor, and use negative
  *            values to target a point on the ceiling.
- *   movedir: if target is not set, this * speed * 10 is the velocity to be reached.
+ *   movedir: if target is not set, movedir * speed * 10 is the velocity to be reached.
  */
 spawnfunc(trigger_push)
 {
@@ -864,20 +897,29 @@ void target_push_init(entity this)
        target_push_link(this);
 }
 
-void target_push_init2(entity this)
+spawnfunc(target_push)
 {
-       if(this.target && this.target != "") // we have an old style pusher!
-       {
+       target_push_init(this); // normal push target behaviour can be combined with a legacy pusher?
+       this.use = target_push_use;
+
+       if(this.target && this.target != "") // Q3 or old style Nexuiz pusher
                InitializeEntity(this, trigger_push_findtarget, INITPRIO_FINDTARGET);
-               this.use = target_push_use;
+       else // Q3 .angles and .speed pusher
+       {
+               if (!this.speed)
+                       this.speed = 1000;
+               SetMovedir(this); // this clears .angles so it must be after target_push_init()
+               this.movedir *= this.speed;
        }
 
-       target_push_init(this); // normal push target behaviour can be combined with a legacy pusher?
-}
-
-spawnfunc(target_push)
-{
-       target_push_init2(this);
+       if (!this.noise)
+       {
+               if (Q3COMPAT_COMMON && !(this.spawnflags & Q3_TARGET_PUSH_JUMPPAD))
+                       this.noise = "sound/misc/windfly.wav"; // Q3 mappers provide this, it's not in pak0
+               else
+                       this.noise = "misc/jumppad.wav";
+       }
+       precache_sound (this.noise);
 }
 
 spawnfunc(info_notnull)