]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Allow target_push to be used as a pusher itself (Quake 3 compatibility)
authorMario <mario@smbclan.net>
Sat, 10 Dec 2016 16:29:29 +0000 (02:29 +1000)
committerMario <mario@smbclan.net>
Sat, 10 Dec 2016 16:29:29 +0000 (02:29 +1000)
qcsrc/common/triggers/trigger/jumppads.qc

index 498f0ff2dbbffb885c36a546ff7f4faba2bac378..edbe9c580a28ec33d50314236a3346f58feed121 100644 (file)
@@ -130,23 +130,14 @@ vector trigger_push_calculatevelocity(vector org, entity tgt, float ht)
        return sdir * vs + '0 0 1' * vz;
 }
 
-void trigger_push_touch(entity this, entity toucher)
+bool jumppad_push(entity this, entity targ)
 {
-       if (this.active == ACTIVE_NOT)
-               return;
-
-       if (!isPushable(toucher))
-               return;
-
-       if(this.team)
-               if(((this.spawnflags & 4) == 0) == (DIFF_TEAM(this, toucher)))
-                       return;
-
-       EXACTTRIGGER_TOUCH(this, toucher);
+       if (!isPushable(targ))
+               return false;
 
        if(this.enemy)
        {
-               toucher.velocity = trigger_push_calculatevelocity(toucher.origin, this.enemy, this.height);
+               targ.velocity = trigger_push_calculatevelocity(targ.origin, this.enemy, this.height);
        }
        else if(this.target && this.target != "")
        {
@@ -159,105 +150,117 @@ void trigger_push_touch(entity this, entity toucher)
                        else
                                RandomSelection_AddEnt(e, 1, 1);
                }
-               toucher.velocity = trigger_push_calculatevelocity(toucher.origin, RandomSelection_chosen_ent, this.height);
+               targ.velocity = trigger_push_calculatevelocity(targ.origin, RandomSelection_chosen_ent, this.height);
        }
        else
        {
-               toucher.velocity = this.movedir;
+               targ.velocity = this.movedir;
        }
 
-       UNSET_ONGROUND(toucher);
+       UNSET_ONGROUND(targ);
 
 #ifdef CSQC
-       if (toucher.flags & FL_PROJECTILE)
+       if (targ.flags & FL_PROJECTILE)
        {
-               toucher.angles = vectoangles (toucher.velocity);
-               switch(toucher.move_movetype)
+               targ.angles = vectoangles (targ.velocity);
+               switch(targ.move_movetype)
                {
                        case MOVETYPE_FLY:
-                               set_movetype(toucher, MOVETYPE_TOSS);
-                               toucher.gravity = 1;
+                               set_movetype(targ, MOVETYPE_TOSS);
+                               targ.gravity = 1;
                                break;
                        case MOVETYPE_BOUNCEMISSILE:
-                               set_movetype(toucher, MOVETYPE_BOUNCE);
-                               toucher.gravity = 1;
+                               set_movetype(targ, MOVETYPE_BOUNCE);
+                               targ.gravity = 1;
                                break;
                }
        }
 #endif
 
 #ifdef SVQC
-       if (IS_PLAYER(toucher))
+       if (IS_PLAYER(targ))
        {
                // reset tracking of oldvelocity for impact damage (sudden velocity changes)
-               toucher.oldvelocity = toucher.velocity;
+               targ.oldvelocity = targ.velocity;
 
                if(this.pushltime < time)  // prevent "snorring" sound when a player hits the jumppad more than once
                {
                        // flash when activated
-                       Send_Effect(EFFECT_JUMPPAD, toucher.origin, toucher.velocity, 1);
-                       _sound (toucher, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
+                       Send_Effect(EFFECT_JUMPPAD, targ.origin, targ.velocity, 1);
+                       _sound (targ, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
                        this.pushltime = time + 0.2;
                }
-               if(IS_REAL_CLIENT(toucher) || IS_BOT_CLIENT(toucher))
+               if(IS_REAL_CLIENT(targ) || IS_BOT_CLIENT(targ))
                {
                        bool found = false;
-                       for(int i = 0; i < toucher.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
-                               if(toucher.(jumppadsused[i]) == this)
+                       for(int i = 0; i < targ.jumppadcount && i < NUM_JUMPPADSUSED; ++i)
+                               if(targ.(jumppadsused[i]) == this)
                                        found = true;
                        if(!found)
                        {
-                               toucher.(jumppadsused[toucher.jumppadcount % NUM_JUMPPADSUSED]) = this;
-                               toucher.jumppadcount = toucher.jumppadcount + 1;
+                               targ.(jumppadsused[targ.jumppadcount % NUM_JUMPPADSUSED]) = this;
+                               targ.jumppadcount = targ.jumppadcount + 1;
                        }
 
-                       if(IS_REAL_CLIENT(toucher))
+                       if(IS_REAL_CLIENT(targ))
                        {
                                if(this.message)
-                                       centerprint(toucher, this.message);
+                                       centerprint(targ, this.message);
                        }
                        else
-                               toucher.lastteleporttime = time;
+                               targ.lastteleporttime = time;
 
-                       if (!IS_DEAD(toucher))
-                               animdecide_setaction(toucher, ANIMACTION_JUMP, true);
+                       if (!IS_DEAD(targ))
+                               animdecide_setaction(targ, ANIMACTION_JUMP, true);
                }
                else
-                       toucher.jumppadcount = true;
+                       targ.jumppadcount = true;
 
                // reset tracking of who pushed you into a hazard (for kill credit)
-               toucher.pushltime = 0;
-               toucher.istypefrag = 0;
+               targ.pushltime = 0;
+               targ.istypefrag = 0;
        }
 
        if(this.enemy.target)
-               SUB_UseTargets(this.enemy, toucher, toucher); // TODO: do we need toucher as trigger too?
+               SUB_UseTargets(this.enemy, targ, targ); // TODO: do we need targ as trigger too?
 
-       if (toucher.flags & FL_PROJECTILE)
+       if (targ.flags & FL_PROJECTILE)
        {
-               toucher.angles = vectoangles (toucher.velocity);
-               toucher.com_phys_gravity_factor = 1;
-               switch(toucher.move_movetype)
+               targ.angles = vectoangles (targ.velocity);
+               targ.com_phys_gravity_factor = 1;
+               switch(targ.move_movetype)
                {
                        case MOVETYPE_FLY:
-                               set_movetype(toucher, MOVETYPE_TOSS);
-                               toucher.gravity = 1;
+                               set_movetype(targ, MOVETYPE_TOSS);
+                               targ.gravity = 1;
                                break;
                        case MOVETYPE_BOUNCEMISSILE:
-                               set_movetype(toucher, MOVETYPE_BOUNCE);
-                               toucher.gravity = 1;
+                               set_movetype(targ, MOVETYPE_BOUNCE);
+                               targ.gravity = 1;
                                break;
                }
-               UpdateCSQCProjectile(toucher);
+               UpdateCSQCProjectile(targ);
        }
+#endif
 
-       /*if (toucher.flags & FL_ITEM)
-       {
-               ItemUpdate(toucher);
-               toucher.SendFlags |= ISF_DROP;
-       }*/
+       return true;
+}
+
+void trigger_push_touch(entity this, entity toucher)
+{
+       if (this.active == ACTIVE_NOT)
+               return;
 
-       if (this.spawnflags & PUSH_ONCE)
+       if(this.team)
+               if(((this.spawnflags & 4) == 0) == (DIFF_TEAM(this, toucher)))
+                       return;
+
+       EXACTTRIGGER_TOUCH(this, toucher);
+
+       noref bool success = jumppad_push(this, toucher);
+
+#ifdef SVQC
+       if (success && (this.spawnflags & PUSH_ONCE))
        {
                settouch(this, func_null);
                setthink(this, SUB_Remove);
@@ -272,17 +275,14 @@ void trigger_push_updatelink(entity this);
 #endif
 void trigger_push_findtarget(entity this)
 {
-       entity t;
-       vector org;
-
        // first calculate a typical start point for the jump
-       org = (this.absmin + this.absmax) * 0.5;
+       vector org = (this.absmin + this.absmax) * 0.5;
        org_z = this.absmax.z - STAT(PL_MIN, NULL).z;
 
        if (this.target)
        {
-               float n = 0;
-               for(t = NULL; (t = find(t, targetname, this.target)); )
+               int n = 0;
+               for(entity t = NULL; (t = find(t, targetname, this.target)); )
                {
                        ++n;
 #ifdef SVQC
@@ -328,7 +328,6 @@ void trigger_push_findtarget(entity this)
                delete(e);
        }
 
-       trigger_push_link(this);
        defer(this, 0.1, trigger_push_updatelink);
 #endif
 }
@@ -393,6 +392,8 @@ spawnfunc(trigger_push)
                this.noise = "misc/jumppad.wav";
        precache_sound (this.noise);
 
+       trigger_push_link(this); // link it now
+
        // this must be called to spawn the teleport waypoints for bots
        InitializeEntity(this, trigger_push_findtarget, INITPRIO_FINDTARGET);
 }
@@ -415,6 +416,11 @@ bool target_push_send(entity this, entity to, float sf)
        return true;
 }
 
+void target_push_use(entity this, entity actor, entity trigger)
+{
+       jumppad_push(this, actor);
+}
+
 void target_push_link(entity this)
 {
        BITSET_ASSIGN(this.effects, EF_NODEPTHTEST);
@@ -429,7 +435,18 @@ void target_push_init(entity this)
        target_push_link(this);
 }
 
-spawnfunc(target_push) { target_push_init(this); }
+void target_push_init2(entity this)
+{
+       if(this.target && this.target != "") // we have an old style pusher!
+       {
+               InitializeEntity(this, trigger_push_findtarget, INITPRIO_FINDTARGET);
+               this.use = target_push_use;
+       }
+
+       target_push_init(this); // normal push target behaviour can be combined with a legacy pusher?
+}
+
+spawnfunc(target_push) { target_push_init2(this); }
 spawnfunc(info_notnull) { target_push_init(this); }
 spawnfunc(target_position) { target_push_init(this); }