From: MirceaKitsune Date: Thu, 14 Apr 2011 11:13:33 +0000 (+0300) Subject: Attempt to port Xonotic's multi-jump feature (previously written by me in Nexuiz) X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=047cc04bbf24da439ce3cd9c6177c29abf68f10b;p=voretournament%2Fvoretournament.git Attempt to port Xonotic's multi-jump feature (previously written by me in Nexuiz) --- diff --git a/data/qcsrc/common/util.qc b/data/qcsrc/common/util.qc index 3e2f269f..990e3c4d 100644 --- a/data/qcsrc/common/util.qc +++ b/data/qcsrc/common/util.qc @@ -1754,6 +1754,12 @@ string getcurrentmod() return argv(n - 1); } +vector vec2(vector v) +{ + v_z = 0; + return v; +} + #ifndef MENUQC #ifdef CSQC float ReadInt24_t() diff --git a/data/qcsrc/server/antilag.qc b/data/qcsrc/server/antilag.qc index e1a2c7f1..cc10654b 100644 --- a/data/qcsrc/server/antilag.qc +++ b/data/qcsrc/server/antilag.qc @@ -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); } +vector antilag_takebackavgvelocity(entity e, float t0, float t1) +{ + vector o0, o1; + if(t0 >= t1) + return '0 0 0'; + o0 = antilag_takebackorigin(e, t0); + o1 = antilag_takebackorigin(e, t1); + return (o1 - o0) * (1 / (t1 - t0)); +} + void antilag_takeback(entity e, float t) { e.antilag_saved_origin = e.origin; diff --git a/data/qcsrc/server/antilag.qh b/data/qcsrc/server/antilag.qh index fd725432..cf190bbe 100644 --- a/data/qcsrc/server/antilag.qh +++ b/data/qcsrc/server/antilag.qh @@ -1,6 +1,7 @@ void antilag_record(entity e, float t); float antilag_find(entity e, float t); vector antilag_takebackorigin(entity e, float t); +vector antilag_takebackavgvelocity(entity e, float t0, float t1); void antilag_takeback(entity e, float t); void antilag_restore(entity e); diff --git a/data/qcsrc/server/cl_physics.qc b/data/qcsrc/server/cl_physics.qc index bd04e84b..e2993af3 100644 --- a/data/qcsrc/server/cl_physics.qc +++ b/data/qcsrc/server/cl_physics.qc @@ -29,6 +29,10 @@ float sv_warsowbunny_backtosideratio; .float wasFlying; .float spectatorspeed; +.float multijump_count; +.float multijump_ready; +.float prevjumpbutton; + /* ============= PlayerJump @@ -39,6 +43,15 @@ When you press the jump key void PlayerJump (void) { float mjumpheight; + float doublejump; + + doublejump = FALSE; + if (cvar("sv_doublejump")) + { + tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self); + if (trace_fraction < 1 && trace_plane_normal_z > 0.7) + doublejump = TRUE; + } mjumpheight = cvar("sv_jumpvelocity"); if (self.waterlevel >= WATERLEVEL_SWIMMING) @@ -53,8 +66,58 @@ void PlayerJump (void) return; } - if (!(self.flags & FL_ONGROUND)) - return; + if (cvar("g_multijump")) + { + if (self.prevjumpbutton == FALSE && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair + self.multijump_ready = TRUE; // this is necessary to check that we released the jump button and pressed it again + else + self.multijump_ready = FALSE; + } + + if(!doublejump && self.multijump_ready && self.multijump_count < cvar("g_multijump") && self.velocity_z > cvar("g_multijump_speed")) + { + // doublejump = FALSE; // checked above in the if + if (cvar("g_multijump") > 0) + { + if (cvar("g_multijump_add") == 0) // in this case we make the z velocity == jumpvelocity + { + if (self.velocity_z < mjumpheight) + { + doublejump = TRUE; + self.velocity_z = 0; + } + } + else + doublejump = TRUE; + + if(doublejump) + { + if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys + { + float curspeed; + vector wishvel, wishdir; + + curspeed = max( + vlen(vec2(self.velocity)), // current xy speed + vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs + ); + makevectors(self.v_angle_y * '0 1 0'); + wishvel = v_forward * self.movement_x + v_right * self.movement_y; + wishdir = normalize(wishvel); + + self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump + self.velocity_y = wishdir_y * curspeed; + // keep velocity_z unchanged! + } + self.multijump_count += 1; + } + } + self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump + } + + if (!doublejump) + if (!(self.flags & FL_ONGROUND)) + return; if(!sv_pogostick) if (!(self.flags & FL_JUMPRELEASED)) @@ -787,12 +850,12 @@ void SV_PlayerPhysics() if(self.classname == "player") { - if(sv_doublejump && time - self.jumppadusetime > 2 * sys_frametime) + if(self.flags & FL_ONGROUND) { - tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self); - self.flags &~= FL_ONGROUND; - if(trace_fraction < 1 && trace_plane_normal_z > 0.7) - self.flags |= FL_ONGROUND; + if (cvar("g_multijump") > 0) + self.multijump_count = 0; + else + self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller } if (self.BUTTON_JUMP)