]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mapobjects/trigger/jumppads.qc
Fix trigger_push and trigger_impulse prediction
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / trigger / jumppads.qc
index 3b9276d6e74683cb3e4a165a2d338928656c6fcc..517a2d48414cdbca42039cfaccf5eaaa142ede38 100644 (file)
@@ -2,7 +2,6 @@
 // TODO: split target_push and put it in the target folder
 #ifdef SVQC
 #include <common/physics/movetypes/movetypes.qh>
-#include <server/main.qh>
 
 void trigger_push_use(entity this, entity actor, entity trigger)
 {
@@ -40,6 +39,14 @@ vector trigger_push_calculatevelocity(vector org, entity tgt, float ht, entity p
        if(pushed_entity && pushed_entity.gravity)
                grav *= pushed_entity.gravity;
 
+       // Q3 has frametime-dependent gravity, but its trigger_push velocity calculation doesn't account for that.
+       // This discrepancy can be simulated accurately which ensures that all entities will arrive
+       // where they would in Q3 with gravity 800 at 125fps, even if entity-specific gravity is applied.
+       // This can be hard-coded because we don't support the Q3 world.gravity field at this time.
+       // See physicsCPMA.cfg for maths and test results.
+       if (Q3COMPAT_COMMON)
+               grav /= 750/800; // exact float, unlike 800/750
+
        zdist = torg.z - org.z;
        sdist = vlen(torg - org - zdist * '0 0 1');
        sdir = normalize(torg - org - zdist * '0 0 1');
@@ -70,7 +77,7 @@ vector trigger_push_calculatevelocity(vector org, entity tgt, float ht, entity p
                and ti.
         */
 
-       // push him so high...
+       // push them so high...
        vz = sqrt(fabs(2 * grav * jumpheight)); // NOTE: sqrt(positive)!
 
        // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump!
@@ -136,11 +143,8 @@ bool jumppad_push(entity this, entity targ)
 
        vector org = targ.origin;
 
-       if(STAT(Q3COMPAT))
-       {
-               org.z += targ.mins_z;
-               org.z += 1; // off by 1!
-       }
+       if(Q3COMPAT_COMMON || this.spawnflags & PUSH_STATIC)
+               org = (this.absmin + this.absmax) * 0.5;
 
        if(this.enemy)
        {
@@ -190,7 +194,9 @@ bool jumppad_push(entity this, entity targ)
                // reset tracking of oldvelocity for impact damage (sudden velocity changes)
                targ.oldvelocity = targ.velocity;
 
-               if(this.pushltime < time)  // prevent "snorring" sound when a player hits the jumppad more than once
+               // prevent sound spam when a player hits the jumppad more than once
+               // or when a dead player gets stuck in the jumppad for some reason
+               if(this.pushltime < time && !(IS_DEAD(targ) && targ.velocity == '0 0 0'))
                {
                        // flash when activated
                        Send_Effect(EFFECT_JUMPPAD, targ.origin, targ.velocity, 1);
@@ -600,8 +606,8 @@ spawnfunc(trigger_push)
 {
        SetMovedir(this);
 
-       trigger_init(this);
-
+       WarpZoneLib_ExactTrigger_Init(this, false);
+       BITSET_ASSIGN(this.effects, EF_NODEPTHTEST);
        this.active = ACTIVE_ACTIVE;
        this.use = trigger_push_use;
        settouch(this, trigger_push_touch);
@@ -688,12 +694,7 @@ spawnfunc(target_position)
 
 NET_HANDLE(ENT_CLIENT_TRIGGER_PUSH, bool isnew)
 {
-       this.classname = "jumppad";
-       int mytm = ReadByte();
-       if(mytm)
-       {
-               this.team = mytm - 1;
-       }
+       int mytm = ReadByte(); if(mytm) { this.team = mytm - 1; }
        this.spawnflags = ReadInt24_t();
        this.active = ReadByte();
        this.height = ReadCoord();
@@ -717,7 +718,6 @@ void target_push_remove(entity this)
 
 NET_HANDLE(ENT_CLIENT_TARGET_PUSH, bool isnew)
 {
-       this.classname = "push_target";
        this.cnt = ReadByte();
        this.targetname = strzone(ReadString());
        this.origin = ReadVector();