From dcee6260b1a90a1e1343d783ff266afd026ba8af Mon Sep 17 00:00:00 2001 From: div0 Date: Thu, 26 Mar 2009 08:32:08 +0000 Subject: [PATCH] new and better jetpack code and settings git-svn-id: svn://svn.icculus.org/nexuiz/trunk@6296 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/defaultNexuiz.cfg | 13 +++-- data/qcsrc/server/cl_physics.qc | 98 ++++++++++++++++++--------------- 2 files changed, 62 insertions(+), 49 deletions(-) diff --git a/data/defaultNexuiz.cfg b/data/defaultNexuiz.cfg index 2fc2b8318..aabdd4670 100644 --- a/data/defaultNexuiz.cfg +++ b/data/defaultNexuiz.cfg @@ -1416,9 +1416,10 @@ seta sbar_increment_maptime 0 "set to 1 if you prefer an increasing hud timer" seta cl_showpressedkeys 0 "Show which movement keys someone is pressing: 1 for spectating, 2 for always" set cl_showpressedkeys_position "1 0.8" "1 0 would be upper right corner, 0.5 0.5 the center" -set g_jetpack 0 "Jetpack mutator (experimental)" -set g_jetpack_accel_side 400 "max jetpack sideways acceleration" -set g_jetpack_accel_up 1150 "max jetpack upwards acceleration" -set g_jetpack_accel_upadjust 1.5 "view angle adjustment" -set g_jetpack_accel_maxspeed 2000 "max speed for jetpack (also, when jetpack becomes inoperative because of this, it takes no cells)" -set g_jetpack_accel_ammo 2 "cells per second for jetpack" +set g_jetpack 0 "Jetpack mutator (experimental)"2 +set g_jetpack_antigravity 0.8 "factor of gravity compensation of the jetpack" +set g_jetpack_acceleration_side 1000 "acceleration of the jetpack in xy direction" +set g_jetpack_acceleration_up 500 "acceleration of the jetpack in z direction (note: you have to factor in gravity here, if antigravity is not 1)" +set g_jetpack_maxspeed_side 1500 "max speed of the jetpack in xy direction" +set g_jetpack_maxspeed_up 400 "max speed of the jetpack in z direction" +set g_jetpack_ammo 2 "cells per second for jetpack" diff --git a/data/qcsrc/server/cl_physics.qc b/data/qcsrc/server/cl_physics.qc index e892cb85c..c9f20011c 100644 --- a/data/qcsrc/server/cl_physics.qc +++ b/data/qcsrc/server/cl_physics.qc @@ -529,49 +529,6 @@ void SV_PlayerPhysics() if (self.waterlevel == WATERLEVEL_SWIMMING) CheckWaterJump (); - - if (g_jetpack && self.BUTTON_HOOK) - { - //makevectors(self.v_angle_y * '0 1 0'); - makevectors(self.v_angle); - wishvel = v_forward * self.movement_x + v_right * self.movement_y; - // add remaining speed as Z component - maxairspd = sv_maxairspeed*max(1, maxspd_mod); - wishvel_x *= 1 / maxairspd; - wishvel_y *= 1 / maxairspd; - wishvel_z = 0; - wishvel_z += sqrt(max(0, 1 - wishvel * wishvel)); - wishvel_z += cvar("g_jetpack_accel_upadjust"); - wishvel = normalize(wishvel); - wishvel_x *= cvar("g_jetpack_accel_side"); - wishvel_y *= cvar("g_jetpack_accel_side"); - wishvel_z *= cvar("g_jetpack_accel_up"); - - wishdir = normalize(wishvel); - wishspeed = vlen(wishvel); - - f = (1 - (self.velocity * wishdir) / cvar("g_jetpack_maxspeed")); - if(cvar("g_jetpack_ammo")) - { - if(self.ammo_cells < 0.01) - f = 0; - else - f = min(f, self.ammo_cells / (cvar("g_jetpack_ammo") * frametime)); - } - if (f > 0) - { - self.velocity = self.velocity + wishvel * f * frametime; - float c; - c = self.ammo_cells; - self.ammo_cells -= frametime * cvar("g_jetpack_ammo") * f; - if(floor(c / 5) != floor(self.ammo_cells / 5)) - sprint(self, "jetpack: less than ", ftos(floor(c)), " cells left\n"); - else if(self.ammo_cells < 0.01 && cvar("g_jetpack_ammo")) - sprint(self, "jetpack: out of fuel\n"); - self.flags &~= FL_ONGROUND; - self.modelflags |= MF_ROCKET; - } - } } if (self.flags & FL_WATERJUMP ) @@ -679,6 +636,61 @@ void SV_PlayerPhysics() self.velocity = self.velocity + wishdir * min(f, sv_accelerate*maxspd_mod * frametime * wishspeed); } } + else if (g_jetpack && self.BUTTON_HOOK && (!cvar("g_jetpack_ammo") || self.ammo_cells >= 0.01)) + { + //makevectors(self.v_angle_y * '0 1 0'); + makevectors(self.v_angle); + wishvel = v_forward * self.movement_x + v_right * self.movement_y; + // add remaining speed as Z component + maxairspd = sv_maxairspeed*max(1, maxspd_mod); + // fix speedhacks :P + wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1); + // add the unused velocity as up component + wishvel_z += sqrt(max(0, 1 - wishvel * wishvel)); + // it is now normalized, so... + wishvel_x *= cvar("g_jetpack_acceleration_side"); + wishvel_y *= cvar("g_jetpack_acceleration_side"); + wishvel_z *= cvar("g_jetpack_acceleration_up"); + wishvel_z += cvar("g_jetpack_antigravity") * sv_gravity; + + float fxy, fz; + fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1); + if(wishvel_z - sv_gravity > 0) + fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1); + else + fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1); + + float fvel; + fvel = vlen(wishvel); + wishvel_x *= fxy; + wishvel_y *= fxy; + wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity; + fvel = vlen(wishvel) / fvel; + + if(cvar("g_jetpack_ammo")) + { + if(self.ammo_cells < 0.01) + f = 0; + else + f = min(1, self.ammo_cells / (cvar("g_jetpack_ammo") * frametime * fvel)); + } + else + f = 1; + + if (f > 0 && wishvel != '0 0 0') + { + self.velocity = self.velocity + wishvel * f * frametime; + float c; + c = self.ammo_cells; + self.ammo_cells -= cvar("g_jetpack_ammo") * frametime * fvel * f; + if(floor(c / 5) != floor(self.ammo_cells / 5)) + sprint(self, strcat("jetpack: less than ", ftos(floor(c)), " cells left\n")); + else if(self.ammo_cells < 0.01 && cvar("g_jetpack_ammo")) + sprint(self, "jetpack: out of fuel\n"); + self.flags &~= FL_ONGROUND; + self.modelflags |= MF_ROCKET; + } + } else if (self.flags & FL_ONGROUND) { // walking -- 2.39.2