Attempt to port Xonotic's multi-jump feature (previously written by me in Nexuiz)
authorMirceaKitsune <sonichedgehog_hyperblast00@yahoo.com>
Thu, 14 Apr 2011 11:13:33 +0000 (14:13 +0300)
committerMirceaKitsune <sonichedgehog_hyperblast00@yahoo.com>
Thu, 14 Apr 2011 11:13:33 +0000 (14:13 +0300)
data/qcsrc/common/util.qc
data/qcsrc/server/antilag.qc
data/qcsrc/server/antilag.qh
data/qcsrc/server/cl_physics.qc

index 3e2f269..990e3c4 100644 (file)
@@ -1754,6 +1754,12 @@ string getcurrentmod()
                return argv(n - 1);\r
 }\r
 \r
+vector vec2(vector v)\r
+{\r
+       v_z = 0;\r
+       return v;\r
+}\r
+\r
 #ifndef MENUQC\r
 #ifdef CSQC\r
 float ReadInt24_t()\r
index e1a2c7f..cc10654 100644 (file)
@@ -72,6 +72,16 @@ vector antilag_takebackorigin(entity e, float t)
        return lerp(e.(antilag_times[i0]), e.(antilag_origins[i0]), e.(antilag_times[i1]), e.(antilag_origins[i1]), t);\r
 }\r
 \r
+vector antilag_takebackavgvelocity(entity e, float t0, float t1)\r
+{\r
+       vector o0, o1;\r
+       if(t0 >= t1)\r
+               return '0 0 0';\r
+       o0 = antilag_takebackorigin(e, t0);\r
+       o1 = antilag_takebackorigin(e, t1);\r
+       return (o1 - o0) * (1 / (t1 - t0));\r
+}\r
+\r
 void antilag_takeback(entity e, float t)\r
 {\r
        e.antilag_saved_origin = e.origin;\r
index fd72543..cf190bb 100644 (file)
@@ -1,6 +1,7 @@
 void antilag_record(entity e, float t);\r
 float antilag_find(entity e, float t);\r
 vector antilag_takebackorigin(entity e, float t);\r
+vector antilag_takebackavgvelocity(entity e, float t0, float t1);\r
 void antilag_takeback(entity e, float t);\r
 void antilag_restore(entity e);\r
 \r
index bd04e84..e2993af 100644 (file)
@@ -29,6 +29,10 @@ float sv_warsowbunny_backtosideratio;
 .float wasFlying;\r
 .float spectatorspeed;\r
 \r
+.float multijump_count;\r
+.float multijump_ready;\r
+.float prevjumpbutton;\r
+\r
 /*\r
 =============\r
 PlayerJump\r
@@ -39,6 +43,15 @@ When you press the jump key
 void PlayerJump (void)\r
 {\r
        float mjumpheight;\r
+       float doublejump;\r
+\r
+       doublejump = FALSE;\r
+       if (cvar("sv_doublejump"))\r
+       {\r
+               tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);\r
+               if (trace_fraction < 1 && trace_plane_normal_z > 0.7)\r
+                       doublejump = TRUE;\r
+       }\r
 \r
        mjumpheight = cvar("sv_jumpvelocity");\r
        if (self.waterlevel >= WATERLEVEL_SWIMMING)\r
@@ -53,8 +66,58 @@ void PlayerJump (void)
                return;\r
        }\r
 \r
-       if (!(self.flags & FL_ONGROUND))\r
-               return;\r
+       if (cvar("g_multijump"))\r
+       {\r
+               if (self.prevjumpbutton == FALSE && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair\r
+                       self.multijump_ready = TRUE;  // this is necessary to check that we released the jump button and pressed it again\r
+               else\r
+                       self.multijump_ready = FALSE;\r
+       }\r
+\r
+       if(!doublejump && self.multijump_ready && self.multijump_count < cvar("g_multijump") && self.velocity_z > cvar("g_multijump_speed"))\r
+       {\r
+               // doublejump = FALSE; // checked above in the if\r
+               if (cvar("g_multijump") > 0)\r
+               {\r
+                       if (cvar("g_multijump_add") == 0) // in this case we make the z velocity == jumpvelocity\r
+                       {\r
+                               if (self.velocity_z < mjumpheight)\r
+                               {\r
+                                       doublejump = TRUE;\r
+                                       self.velocity_z = 0;\r
+                               }\r
+                       }\r
+                       else\r
+                               doublejump = TRUE;\r
+\r
+                       if(doublejump)\r
+                       {\r
+                               if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys\r
+                               {\r
+                                       float curspeed;\r
+                                       vector wishvel, wishdir;\r
+\r
+                                       curspeed = max(\r
+                                               vlen(vec2(self.velocity)), // current xy speed\r
+                                               vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs\r
+                                       );\r
+                                       makevectors(self.v_angle_y * '0 1 0');\r
+                                       wishvel = v_forward * self.movement_x + v_right * self.movement_y;\r
+                                       wishdir = normalize(wishvel);\r
+\r
+                                       self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump\r
+                                       self.velocity_y = wishdir_y * curspeed;\r
+                                       // keep velocity_z unchanged!\r
+                               }\r
+                               self.multijump_count += 1;\r
+                       }\r
+               }\r
+               self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump\r
+       }\r
+\r
+       if (!doublejump)\r
+               if (!(self.flags & FL_ONGROUND))\r
+                       return;\r
 \r
        if(!sv_pogostick)\r
                if (!(self.flags & FL_JUMPRELEASED))\r
@@ -787,12 +850,12 @@ void SV_PlayerPhysics()
 \r
        if(self.classname == "player")\r
        {\r
-               if(sv_doublejump && time - self.jumppadusetime > 2 * sys_frametime)\r
+               if(self.flags & FL_ONGROUND)\r
                {\r
-                       tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);\r
-                       self.flags &~= FL_ONGROUND;\r
-                       if(trace_fraction < 1 && trace_plane_normal_z > 0.7)\r
-                               self.flags |= FL_ONGROUND;\r
+                       if (cvar("g_multijump") > 0)\r
+                               self.multijump_count = 0;\r
+                       else\r
+                               self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller\r
                }\r
 \r
                if (self.BUTTON_JUMP)\r