X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fcl_physics.qc;h=bba558769eb19cb0b7e023d32dd9f0527481e0f7;hb=a417525a41a93eb6df571b00c13a32d36a8e93cd;hp=77003999acc3fe58dac12c4bc48f90c49bdc8b6f;hpb=c27ab5cce2fb780bc326e19db1b2b15a3869f224;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/cl_physics.qc b/qcsrc/server/cl_physics.qc index 77003999a..bba558769 100644 --- a/qcsrc/server/cl_physics.qc +++ b/qcsrc/server/cl_physics.qc @@ -1,29 +1,6 @@ .float race_penalty; .float restart_jump; -float autocvar_sv_accelerate; -float autocvar_sv_friction; -float autocvar_sv_maxspeed; -float autocvar_sv_airaccelerate; -float autocvar_sv_maxairspeed; -float autocvar_sv_stopspeed; -float autocvar_sv_gravity; -float sv_airaccel_sideways_friction; -float autocvar_sv_airaccel_qw; -float autocvar_sv_airstopaccelerate; -float autocvar_sv_airstrafeaccelerate; -float sv_maxairstrafespeed; -float autocvar_sv_airstrafeaccel_qw; -float autocvar_sv_aircontrol; -float autocvar_sv_aircontrol_power; -float autocvar_sv_aircontrol_penalty; -float autocvar_sv_warsowbunny_airforwardaccel; -float autocvar_sv_warsowbunny_accel; -float autocvar_sv_warsowbunny_topspeed; -float autocvar_sv_warsowbunny_turnaccel; -float autocvar_sv_warsowbunny_backtosideratio; -float autocvar_sv_airspeedlimit_nonqw; - .float ladder_time; .entity ladder_entity; .float gravity; @@ -46,21 +23,21 @@ When you press the jump key */ void PlayerJump (void) { - if(g_freezetag && self.freezetag_frozen) + if(self.freezetag_frozen) return; // no jumping in freezetag when frozen float mjumpheight; float doublejump; doublejump = FALSE; - if (sv_doublejump) + if (autocvar_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"); + mjumpheight = autocvar_sv_jumpvelocity; if (self.waterlevel >= WATERLEVEL_SWIMMING) { if (self.watertype == CONTENT_WATER) @@ -73,7 +50,7 @@ void PlayerJump (void) return; } - if (cvar("g_multijump")) + if (autocvar_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 @@ -81,12 +58,12 @@ void PlayerJump (void) self.multijump_ready = FALSE; } - if(!doublejump && self.multijump_ready && self.multijump_count < cvar("g_multijump") && self.velocity_z > cvar("g_multijump_speed")) + if(!doublejump && self.multijump_ready && self.multijump_count < autocvar_g_multijump && self.velocity_z > autocvar_g_multijump_speed) { // doublejump = FALSE; // checked above in the if - if (cvar("g_multijump") > 0) + if (autocvar_g_multijump) { - if (cvar("g_multijump_add") == 0) // in this case we make the z velocity == jumpvelocity + if (autocvar_g_multijump_add == 0) // in this case we make the z velocity == jumpvelocity { if (self.velocity_z < mjumpheight) { @@ -116,7 +93,8 @@ void PlayerJump (void) self.velocity_y = wishdir_y * curspeed; // keep velocity_z unchanged! } - self.multijump_count += 1; + if (autocvar_g_multijump > 0) + self.multijump_count += 1; } } self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump @@ -137,26 +115,26 @@ void PlayerJump (void) // velocity bounds. Final velocity is bound between (jumpheight * // min + jumpheight) and (jumpheight * max + jumpheight); - if(cvar_string("sv_jumpspeedcap_min") != "") + if(autocvar_sv_jumpspeedcap_min != "") { float minjumpspeed; - minjumpspeed = mjumpheight * cvar("sv_jumpspeedcap_min"); + minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min); if (self.velocity_z < minjumpspeed) mjumpheight += minjumpspeed - self.velocity_z; } - if(cvar_string("sv_jumpspeedcap_max") != "") + if(autocvar_sv_jumpspeedcap_max != "") { // don't do jump speedcaps on ramps to preserve old xonotic ramjump style 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.98 && cvar("sv_jumpspeedcap_max_disable_on_ramps"))) + if(!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && autocvar_sv_jumpspeedcap_max_disable_on_ramps)) { float maxjumpspeed; - maxjumpspeed = mjumpheight * cvar("sv_jumpspeedcap_max"); + maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max); if (self.velocity_z > maxjumpspeed) mjumpheight -= self.velocity_z - maxjumpspeed; @@ -165,12 +143,12 @@ void PlayerJump (void) if(!(self.lastflags & FL_ONGROUND)) { - if(cvar("speedmeter")) + if(autocvar_speedmeter) dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n")); if(self.lastground < time - 0.3) { - self.velocity_x *= (1 - cvar("sv_friction_on_land")); - self.velocity_y *= (1 - cvar("sv_friction_on_land")); + self.velocity_x *= (1 - autocvar_sv_friction_on_land); + self.velocity_y *= (1 - autocvar_sv_friction_on_land); } if(self.jumppadcount > 1) dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n")); @@ -522,11 +500,11 @@ float AdjustAirAccelQW(float accelqw, float factor) } // example config for alternate speed clamping: -// autocvar_sv_airaccel_qw 0.8 +// sv_airaccel_qw 0.8 // sv_airaccel_sideways_friction 0 // prvm_globalset server speedclamp_mode 1 // (or 2) -void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float sidefric, float speedlimit) +void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit) { float vel_straight; float vel_z; @@ -538,11 +516,17 @@ void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float acce float vel_xy_backward, vel_xy_forward; float speedclamp; - speedclamp = (accelqw < 0); - if(speedclamp) + if(stretchfactor > 0) + speedclamp = stretchfactor; + else if(accelqw < 0) + speedclamp = 1; // full clamping, no stretch + else + speedclamp = -1; // no clamping + + if(accelqw < 0) accelqw = -accelqw; - if(cvar("sv_gameplayfix_q2airaccelerate")) + if(autocvar_sv_gameplayfix_q2airaccelerate) wishspeed0 = wishspeed; vel_straight = self.velocity * wishdir; @@ -582,12 +566,16 @@ void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float acce vel_xy = vel_straight * wishdir + vel_perpend; - if(speedclamp) + if(speedclamp >= 0) { - // ensure we don't get too fast or decelerate faster than we should - vel_xy_current = min(vlen(vel_xy), vel_xy_forward); - if(vel_xy_current > 0) // prevent division by zero - vel_xy = normalize(vel_xy) * vel_xy_current; + float vel_xy_preclamp; + vel_xy_preclamp = vlen(vel_xy); + if(vel_xy_preclamp > 0) // prevent division by zero + { + vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp; + if(vel_xy_current < vel_xy_preclamp) + vel_xy = vel_xy * (vel_xy_current / vel_xy_preclamp); + } } self.velocity = vel_xy + vel_z * '0 0 1'; @@ -689,28 +677,30 @@ void SV_PlayerPhysics() float buttons_prev; float not_allowed_to_move; string c; + + WarpZone_PlayerPhysics_FixVAngle(); maxspd_mod = 1; if(g_minstagib && (self.items & IT_INVINCIBLE)) - maxspd_mod *= cvar("g_minstagib_speed_highspeed"); + maxspd_mod *= autocvar_g_minstagib_speed_highspeed; if(self.ballcarried) if(g_nexball) - maxspd_mod *= cvar("g_nexball_basketball_carrier_highspeed"); + maxspd_mod *= autocvar_g_nexball_basketball_carrier_highspeed; else if(g_keepaway) - maxspd_mod *= cvar("g_keepaway_ballcarrier_highspeed"); + maxspd_mod *= autocvar_g_keepaway_ballcarrier_highspeed; if(g_runematch) { if(self.runes & RUNE_SPEED) { if(self.runes & CURSE_SLOW) - maxspd_mod *= cvar("g_balance_rune_speed_combo_highspeed"); + maxspd_mod *= autocvar_g_balance_rune_speed_combo_highspeed; else - maxspd_mod *= cvar("g_balance_rune_speed_highspeed"); + maxspd_mod *= autocvar_g_balance_rune_speed_highspeed; } else if(self.runes & CURSE_SLOW) { - maxspd_mod *= cvar("g_balance_curse_slow_highspeed"); + maxspd_mod *= autocvar_g_balance_curse_slow_highspeed; } } maxspd_mod *= autocvar_g_movement_highspeed; @@ -779,18 +769,18 @@ void SV_PlayerPhysics() self.v_angle_old = self.v_angle; if(time < self.nickspamtime) - if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow")) + if(self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow) { // slight annoyance for nick change scripts self.movement = -1 * self.movement; self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0; - if(self.nickspamcount >= cvar("g_nick_flood_penalty_red")) // if you are persistent and the slight annoyance above does not stop you, I'll show you! + if(self.nickspamcount >= autocvar_g_nick_flood_penalty_red) // if you are persistent and the slight annoyance above does not stop you, I'll show you! { self.angles_x = random() * 360; self.angles_y = random() * 360; // at least I'm not forcing retardedview by also assigning to angles_z - self.fixangle = 1; + self.fixangle = TRUE; } } @@ -819,8 +809,6 @@ void SV_PlayerPhysics() bot_think(); } - MUTATOR_CALLHOOK(PlayerPhysics); - self.items &~= IT_USING_JETPACK; if(self.classname == "player") @@ -832,7 +820,7 @@ void SV_PlayerPhysics() not_allowed_to_move = 0; if(self.race_penalty) not_allowed_to_move = 1; - if(!cvar("sv_ready_restart_after_countdown")) + if(!autocvar_sv_ready_restart_after_countdown) if(time < game_starttime) not_allowed_to_move = 1; @@ -853,6 +841,13 @@ void SV_PlayerPhysics() if (self.movetype == MOVETYPE_NONE) return; + // when we get here, disableclientprediction cannot be 2 + self.disableclientprediction = 0; + if(time < self.ladder_time) + self.disableclientprediction = 1; + + MUTATOR_CALLHOOK(PlayerPhysics); + maxspd_mod = 1; swampspd_mod = 1; @@ -862,7 +857,7 @@ void SV_PlayerPhysics() if(self.classname != "player") { - maxspd_mod = cvar("sv_spectator_speed_multiplier"); + maxspd_mod = autocvar_sv_spectator_speed_multiplier; if(!self.spectatorspeed) self.spectatorspeed = maxspd_mod; if(self.impulse && self.impulse <= 19) @@ -937,7 +932,7 @@ void SV_PlayerPhysics() { if(self.flags & FL_ONGROUND) { - if (cvar("g_multijump") > 0) + if (autocvar_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 @@ -982,7 +977,7 @@ void SV_PlayerPhysics() if (wishspeed > self.stat_sv_maxspeed*maxspd_mod) wishspeed = self.stat_sv_maxspeed*maxspd_mod; if (time >= self.teleport_time) - PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0); + PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0); } else if (self.waterlevel >= WATERLEVEL_SWIMMING) { @@ -1005,21 +1000,28 @@ void SV_PlayerPhysics() self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction); // water acceleration - PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0); + PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0); } else if (time < self.ladder_time) { // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water self.flags &~= FL_ONGROUND; + float g; + g = autocvar_sv_gravity * frametime; + if(self.gravity) + g *= self.gravity; + if(autocvar_sv_gameplayfix_gravityunaffectedbyticrate) + { + g *= 0.5; + self.velocity_z += g; + } + self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction); makevectors(self.v_angle); //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z; wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z; - if (self.gravity) - self.velocity_z = self.velocity_z + self.gravity * autocvar_sv_gravity * frametime; - else - self.velocity_z = self.velocity_z + autocvar_sv_gravity * frametime; + self.velocity_z += g; if (self.ladder_entity.classname == "func_water") { f = vlen(wishvel); @@ -1048,10 +1050,10 @@ void SV_PlayerPhysics() if (time >= self.teleport_time) { // water acceleration - PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0); + PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0); } } - else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO)) + else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!autocvar_g_jetpack_fuel || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO)) { //makevectors(self.v_angle_y * '0 1 0'); makevectors(self.v_angle); @@ -1068,9 +1070,9 @@ void SV_PlayerPhysics() // it is now normalized, so... float a_side, a_up, a_add, a_diff; - a_side = cvar("g_jetpack_acceleration_side"); - a_up = cvar("g_jetpack_acceleration_up"); - a_add = cvar("g_jetpack_antigravity") * autocvar_sv_gravity; + a_side = autocvar_g_jetpack_acceleration_side; + a_up = autocvar_g_jetpack_acceleration_up; + a_add = autocvar_g_jetpack_antigravity * autocvar_sv_gravity; wishvel_x *= a_side; wishvel_y *= a_side; @@ -1118,11 +1120,11 @@ void SV_PlayerPhysics() //print("best possible acceleration: ", ftos(best), "\n"); 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); + fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / autocvar_g_jetpack_maxspeed_side, 1); if(wishvel_z - autocvar_sv_gravity > 0) - fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1); + fz = bound(0, 1 - self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1); else - fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1); + fz = bound(0, 1 + self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1); float fvel; fvel = vlen(wishvel); @@ -1131,8 +1133,8 @@ void SV_PlayerPhysics() wishvel_z = (wishvel_z - autocvar_sv_gravity) * fz + autocvar_sv_gravity; fvel = min(1, vlen(wishvel) / best); - if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO)) - f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel)); + if(autocvar_g_jetpack_fuel && !(self.items & IT_UNLIMITED_WEAPON_AMMO)) + f = min(1, self.ammo_fuel / (autocvar_g_jetpack_fuel * frametime * fvel)); else f = 1; @@ -1142,12 +1144,12 @@ void SV_PlayerPhysics() { self.velocity = self.velocity + wishvel * f * frametime; if not(self.items & IT_UNLIMITED_WEAPON_AMMO) - self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f; + self.ammo_fuel -= autocvar_g_jetpack_fuel * frametime * fvel * f; self.flags &~= FL_ONGROUND; self.items |= IT_USING_JETPACK; // jetpack also inhibits health regeneration, but only for 1 second - self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen")); + self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen); } } else if (self.flags & FL_ONGROUND) @@ -1162,10 +1164,10 @@ void SV_PlayerPhysics() if(!(self.lastflags & FL_ONGROUND)) { - if(cvar("speedmeter")) + if(autocvar_speedmeter) dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n")); if(self.lastground < time - 0.3) - self.velocity = self.velocity * (1 - cvar("sv_friction_on_land")); + self.velocity = self.velocity * (1 - autocvar_sv_friction_on_land); if(self.jumppadcount > 1) dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n")); self.jumppadcount = 0; @@ -1208,7 +1210,7 @@ void SV_PlayerPhysics() if (self.crouch) wishspeed = wishspeed * 0.5; if (time >= self.teleport_time) - PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0); + PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0); } else { @@ -1268,8 +1270,8 @@ void SV_PlayerPhysics() // log dv/dt = logaccel + logmaxspeed (when slow) // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast) strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero - if(sv_maxairstrafespeed) - wishspeed = min(wishspeed, GeomLerp(autocvar_sv_maxairspeed*maxspd_mod, strafity, sv_maxairstrafespeed*maxspd_mod)); + if(autocvar_sv_maxairstrafespeed) + wishspeed = min(wishspeed, GeomLerp(autocvar_sv_maxairspeed*maxspd_mod, strafity, autocvar_sv_maxairstrafespeed*maxspd_mod)); if(autocvar_sv_airstrafeaccelerate) airaccel = GeomLerp(airaccel, strafity, autocvar_sv_airstrafeaccelerate*maxspd_mod); if(self.stat_sv_airstrafeaccel_qw) @@ -1279,7 +1281,7 @@ void SV_PlayerPhysics() if(autocvar_sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0) PM_AirAccelerate(wishdir, wishspeed); else - PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw); + PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, autocvar_sv_airaccel_qw_stretchfactor, autocvar_sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw); if(autocvar_sv_aircontrol) CPM_PM_Aircontrol(wishdir, wishspeed2); @@ -1314,13 +1316,13 @@ void SV_PlayerPhysics() float xyspeed; xyspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y); - if(self.weapon == WEP_NEX && cvar("g_balance_nex_charge") && cvar("g_balance_nex_charge_velocity_rate") && xyspeed > cvar("g_balance_nex_charge_minspeed")) + if(self.weapon == WEP_NEX && autocvar_g_balance_nex_charge && autocvar_g_balance_nex_charge_velocity_rate && xyspeed > autocvar_g_balance_nex_charge_minspeed) { // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed - xyspeed = min(xyspeed, cvar("g_balance_nex_charge_maxspeed")); - f = (xyspeed - cvar("g_balance_nex_charge_minspeed")) / (cvar("g_balance_nex_charge_maxspeed") - cvar("g_balance_nex_charge_minspeed")); + xyspeed = min(xyspeed, autocvar_g_balance_nex_charge_maxspeed); + f = (xyspeed - autocvar_g_balance_nex_charge_minspeed) / (autocvar_g_balance_nex_charge_maxspeed - autocvar_g_balance_nex_charge_minspeed); // add the extra charge - self.nex_charge = min(1, self.nex_charge + cvar("g_balance_nex_charge_velocity_rate") * f * frametime); + self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_velocity_rate * f * frametime); } :end if(self.flags & FL_ONGROUND)