]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/trigger/jumppads.qc
Merge branch 'master' into terencehill/bot_waypoints
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / trigger / jumppads.qc
index dc9cb761ab2cf18b7f0d02f9f9a2b24c49e1c693..a31f5a482f69bf12fff4b93bbe1c162dc9455640 100644 (file)
@@ -207,13 +207,16 @@ bool jumppad_push(entity this, entity targ)
                                        centerprint(targ, this.message);
                        }
                        else
+                       {
                                targ.lastteleporttime = time;
+                               targ.lastteleport_origin = targ.origin;
+                       }
 
                        if (!IS_DEAD(targ))
                                animdecide_setaction(targ, ANIMACTION_JUMP, true);
                }
                else
-                       targ.jumppadcount = true;
+                       targ.jumppadcount = 1;
 
                // reset tracking of who pushed you into a hazard (for kill credit)
                targ.pushltime = 0;
@@ -307,11 +310,14 @@ bool trigger_push_testorigin(entity tracetest_ent, entity targ, entity jp, vecto
        return true;
 }
 #endif
-void trigger_push_findtarget(entity this)
+
+/// if (item != NULL) returns true if the item can be reached by using this jumppad, false otherwise
+/// if (item == NULL) tests jumppad's trajectory and eventually spawns waypoints for it (return value doesn't matter)
+bool trigger_push_test(entity this, entity item)
 {
        // first calculate a typical start point for the jump
        vector org = (this.absmin + this.absmax) * 0.5;
-       org.z = this.absmax.z - PL_MIN_CONST.z - 10;
+       org.z = this.absmax.z - PL_MIN_CONST.z - 7;
 
        if (this.target)
        {
@@ -330,6 +336,16 @@ void trigger_push_findtarget(entity this)
                        setsize(e, PL_MIN_CONST, PL_MAX_CONST);
                        e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
                        e.velocity = trigger_push_calculatevelocity(org, t, this.height, e);
+
+                       if(item)
+                       {
+                               setorigin(e, org);
+                               tracetoss(e, e);
+                               bool r = (trace_ent == item);
+                               delete(e);
+                               return r;
+                       }
+
                        vel = e.velocity;
                        vector best_target = '0 0 0';
                        vector best_org = '0 0 0';
@@ -394,13 +410,16 @@ void trigger_push_findtarget(entity this)
 #endif
                }
 
+               if(item)
+                       return false;
+
                if(!n)
                {
                        // no dest!
 #ifdef SVQC
                        objerror (this, "Jumppad with nonexistant target");
 #endif
-                       return;
+                       return false;
                }
                else if(n == 1)
                {
@@ -422,6 +441,12 @@ void trigger_push_findtarget(entity this)
                setorigin(e, org);
                e.velocity = this.movedir;
                tracetoss(e, e);
+               if(item)
+               {
+                       bool r = (trace_ent == item);
+                       delete(e);
+                       return r;
+               }
                if (!(boxesoverlap(this.absmin, this.absmax + eZ * 50, trace_endpos + PL_MIN_CONST, trace_endpos + PL_MAX_CONST)))
                        waypoint_spawnforteleporter(this, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity), e);
                delete(e);
@@ -429,6 +454,12 @@ void trigger_push_findtarget(entity this)
 
        defer(this, 0.1, trigger_push_updatelink);
 #endif
+       return true;
+}
+
+void trigger_push_findtarget(entity this)
+{
+       trigger_push_test(this, NULL);
 }
 
 #ifdef SVQC
@@ -441,9 +472,7 @@ float trigger_push_send(entity this, entity to, float sf)
        WriteByte(MSG_ENTITY, this.active);
        WriteCoord(MSG_ENTITY, this.height);
 
-       WriteCoord(MSG_ENTITY, this.movedir_x);
-       WriteCoord(MSG_ENTITY, this.movedir_y);
-       WriteCoord(MSG_ENTITY, this.movedir_z);
+       WriteVector(MSG_ENTITY, this.movedir);
 
        trigger_common_write(this, true);
 
@@ -493,6 +522,8 @@ spawnfunc(trigger_push)
 
        trigger_push_link(this); // link it now
 
+       IL_PUSH(g_jumppads, this);
+
        // this must be called to spawn the teleport waypoints for bots
        InitializeEntity(this, trigger_push_findtarget, INITPRIO_FINDTARGET);
 }
@@ -504,9 +535,7 @@ bool target_push_send(entity this, entity to, float sf)
 
        WriteByte(MSG_ENTITY, this.cnt);
        WriteString(MSG_ENTITY, this.targetname);
-       WriteCoord(MSG_ENTITY, this.origin_x);
-       WriteCoord(MSG_ENTITY, this.origin_y);
-       WriteCoord(MSG_ENTITY, this.origin_z);
+       WriteVector(MSG_ENTITY, this.origin);
 
        WriteAngle(MSG_ENTITY, this.angles_x);
        WriteAngle(MSG_ENTITY, this.angles_y);
@@ -562,9 +591,7 @@ NET_HANDLE(ENT_CLIENT_TRIGGER_PUSH, bool isnew)
        this.active = ReadByte();
        this.height = ReadCoord();
 
-       this.movedir_x = ReadCoord();
-       this.movedir_y = ReadCoord();
-       this.movedir_z = ReadCoord();
+       this.movedir = ReadVector();
 
        trigger_common_read(this, true);
 
@@ -579,13 +606,8 @@ NET_HANDLE(ENT_CLIENT_TRIGGER_PUSH, bool isnew)
 
 void target_push_remove(entity this)
 {
-       //if(this.classname)
-               //strunzone(this.classname);
-       //this.classname = string_null;
-
-       if(this.targetname)
-               strunzone(this.targetname);
-       this.targetname = string_null;
+       // strfree(this.classname);
+       strfree(this.targetname);
 }
 
 NET_HANDLE(ENT_CLIENT_TARGET_PUSH, bool isnew)
@@ -593,9 +615,7 @@ NET_HANDLE(ENT_CLIENT_TARGET_PUSH, bool isnew)
        this.classname = "push_target";
        this.cnt = ReadByte();
        this.targetname = strzone(ReadString());
-       this.origin_x = ReadCoord();
-       this.origin_y = ReadCoord();
-       this.origin_z = ReadCoord();
+       this.origin = ReadVector();
 
        this.angles_x = ReadAngle();
        this.angles_y = ReadAngle();