]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/trigger/jumppads.qc
Merge branch 'master' into terencehill/min_spec_time
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / trigger / jumppads.qc
index c9729f52226503d0e0fe3d03a48ddeb05abb4272..fde6e1fb9d6cf58e091ead371e1705dab06fbf49 100644 (file)
@@ -25,19 +25,20 @@ REGISTER_NET_LINKED(ENT_CLIENT_TARGET_PUSH)
          tgt - target entity (can be either a point or a model entity; if it is
                the latter, its midpoint is used)
          ht  - jump height, measured from the higher one of org and tgt's midpoint
+         pushed_entity - object that is to be pushed
 
        Returns: velocity for the jump
  */
-vector trigger_push_calculatevelocity(vector org, entity tgt, float ht)
+vector trigger_push_calculatevelocity(vector org, entity tgt, float ht, entity pushed_entity)
 {
        float grav, sdist, zdist, vs, vz, jumpheight;
        vector sdir, torg;
 
        torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
 
-       grav = PHYS_GRAVITY(other);
-       if(PHYS_ENTGRAVITY(other))
-               grav *= PHYS_ENTGRAVITY(other);
+       grav = PHYS_GRAVITY(NULL);
+       if(pushed_entity && PHYS_ENTGRAVITY(pushed_entity))
+               grav *= PHYS_ENTGRAVITY(pushed_entity);
 
        zdist = torg.z - org.z;
        sdist = vlen(torg - org - zdist * '0 0 1');
@@ -135,7 +136,7 @@ bool jumppad_push(entity this, entity targ)
 
        if(this.enemy)
        {
-               targ.velocity = trigger_push_calculatevelocity(targ.origin, this.enemy, this.height);
+               targ.velocity = trigger_push_calculatevelocity(targ.origin, this.enemy, this.height, targ);
        }
        else if(this.target && this.target != "")
        {
@@ -148,7 +149,7 @@ bool jumppad_push(entity this, entity targ)
                        else
                                RandomSelection_AddEnt(e, 1, 1);
                }
-               targ.velocity = trigger_push_calculatevelocity(targ.origin, RandomSelection_chosen_ent, this.height);
+               targ.velocity = trigger_push_calculatevelocity(targ.origin, RandomSelection_chosen_ent, this.height, targ);
        }
        else
        {
@@ -206,7 +207,10 @@ 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);
@@ -277,23 +281,27 @@ bool trigger_push_testorigin(entity tracetest_ent, entity targ, entity jp, vecto
        if(trace_startsolid)
                return false;
 
-       if(!jp.height)
+       if (!jp.height)
        {
                // since tracetoss starting from jumppad's origin often fails when target
                // is very close to real destination, start it directly from target's
                // origin instead
+               vector ofs = '0 0 0';
+               if (vdist(vec2(tracetest_ent.velocity), <, autocvar_sv_maxspeed))
+                       ofs = stepheightvec;
+
                tracetest_ent.velocity.z = 0;
-               setorigin(tracetest_ent, targ.origin + stepheightvec);
+               setorigin(tracetest_ent, targ.origin + ofs);
                tracetoss(tracetest_ent, tracetest_ent);
-               if(trace_startsolid)
+               if (trace_startsolid && ofs.z)
                {
-                       setorigin(tracetest_ent, targ.origin + stepheightvec / 2);
+                       setorigin(tracetest_ent, targ.origin + ofs / 2);
                        tracetoss(tracetest_ent, tracetest_ent);
-                       if(trace_startsolid)
+                       if (trace_startsolid && ofs.z)
                        {
                                setorigin(tracetest_ent, targ.origin);
                                tracetoss(tracetest_ent, tracetest_ent);
-                               if(trace_startsolid)
+                               if (trace_startsolid)
                                        return false;
                        }
                }
@@ -309,7 +317,7 @@ 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;
+       org.z = this.absmax.z - PL_MIN_CONST.z - 10;
 
        if (this.target)
        {
@@ -327,7 +335,7 @@ bool trigger_push_test(entity this, entity item)
                        entity e = spawn();
                        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.velocity = trigger_push_calculatevelocity(org, t, this.height, e);
 
                        if(item)
                        {
@@ -361,7 +369,7 @@ bool trigger_push_test(entity this, entity item)
                                vector flatdir = normalize(dist - eZ * dist.z);
                                vector ofs = flatdir * 0.5 * min(fabs(this.absmax.x - this.absmin.x), fabs(this.absmax.y - this.absmin.y));
                                new_org = org + ofs;
-                               e.velocity = trigger_push_calculatevelocity(new_org, t, this.height);
+                               e.velocity = trigger_push_calculatevelocity(new_org, t, this.height, e);
                                vel = e.velocity;
                                if (vdist(vec2(e.velocity), <, autocvar_sv_maxspeed))
                                        e.velocity = autocvar_sv_maxspeed * flatdir;
@@ -373,7 +381,7 @@ bool trigger_push_test(entity this, entity item)
                                        valid_best_target = true;
                                }
                                new_org = org - ofs;
-                               e.velocity = trigger_push_calculatevelocity(new_org, t, this.height);
+                               e.velocity = trigger_push_calculatevelocity(new_org, t, this.height, e);
                                vel = e.velocity;
                                if (vdist(vec2(e.velocity), <, autocvar_sv_maxspeed))
                                        e.velocity = autocvar_sv_maxspeed * flatdir;
@@ -464,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);
 
@@ -529,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);
@@ -587,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);
 
@@ -618,9 +620,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();