X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fphysics.qc;h=0cac08bb0c0fab1c7ac93ccdb160863753907c56;hb=c14f2b067c9ab0b4fb8a5b7805c8679be61f1fe0;hp=998f0f5fa12a645f4a675a132b4a0eb198ae53ef;hpb=991d99371a47aceca9b548192b27e9c874d05a3c;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/physics.qc b/qcsrc/common/physics.qc index 998f0f5fa..0cac08bb0 100644 --- a/qcsrc/common/physics.qc +++ b/qcsrc/common/physics.qc @@ -1,43 +1,67 @@ -.float race_penalty; -.float restart_jump; - -.float ladder_time; -.entity ladder_entity; -.float gravity; -.float swamp_slowdown; -.float lastflags; -.float lastground; -.float wasFlying; -.float spectatorspeed; - -.vector movement_old; -.float buttons_old; -.vector v_angle_old; -.string lastclassname; - -.float() PlayerPhysplug; -float AdjustAirAccelQW(float accelqw, float factor); +#include "physics.qh" +#include "triggers/trigger/swamp.qh" +#include "triggers/trigger/jumppads.qh" +#include "viewloc.qh" -#ifdef CSQC +#ifdef SVQC + +#include "../server/miscfunctions.qh" +#include "triggers/trigger/viewloc.qh" + +// client side physics +bool Physics_Valid(string thecvar) +{ + if(!autocvar_g_physics_clientselect) { return false; } -.float watertype; + string l = strcat(" ", autocvar_g_physics_clientselect_options, " "); -#elif defined(SVQC) -.float stat_sv_airaccel_qw; -.float stat_sv_airstrafeaccel_qw; -.float stat_sv_airspeedlimit_nonqw; -.float stat_sv_maxspeed; -.float stat_movement_highspeed; + if(strstrofs(l, strcat(" ", thecvar, " "), 0) >= 0) + return true; -.float stat_jetpack_accel_side; -.float stat_jetpack_accel_up; -.float stat_jetpack_antigravity; -.float stat_jetpack_fuel; -.float stat_jetpack_maxspeed_up; -.float stat_jetpack_maxspeed_side; + return false; +} + +float Physics_ClientOption(entity pl, string option) +{ + if(Physics_Valid(pl.cvar_cl_physics)) + { + string var = sprintf("g_physics_%s_%s", pl.cvar_cl_physics, option); + if(cvar_type(var) & CVAR_TYPEFLAG_EXISTS) + return cvar(var); + } + if(autocvar_g_physics_clientselect && autocvar_g_physics_clientselect_default) + { + string var = sprintf("g_physics_%s_%s", autocvar_g_physics_clientselect_default, option); + if(cvar_type(var) & CVAR_TYPEFLAG_EXISTS) + return cvar(var); + } + return cvar(strcat("sv_", option)); +} void Physics_AddStats() { + // static view offset and hitbox vectors + // networked for all you bandwidth pigs out there + addstat(STAT_PL_VIEW_OFS1, AS_FLOAT, stat_pl_view_ofs_x); + addstat(STAT_PL_VIEW_OFS2, AS_FLOAT, stat_pl_view_ofs_y); + addstat(STAT_PL_VIEW_OFS3, AS_FLOAT, stat_pl_view_ofs_z); + addstat(STAT_PL_CROUCH_VIEW_OFS1, AS_FLOAT, stat_pl_crouch_view_ofs_x); + addstat(STAT_PL_CROUCH_VIEW_OFS2, AS_FLOAT, stat_pl_crouch_view_ofs_y); + addstat(STAT_PL_CROUCH_VIEW_OFS3, AS_FLOAT, stat_pl_crouch_view_ofs_z); + + addstat(STAT_PL_MIN1, AS_FLOAT, stat_pl_min_x); + addstat(STAT_PL_MIN2, AS_FLOAT, stat_pl_min_y); + addstat(STAT_PL_MIN3, AS_FLOAT, stat_pl_min_z); + addstat(STAT_PL_MAX1, AS_FLOAT, stat_pl_max_x); + addstat(STAT_PL_MAX2, AS_FLOAT, stat_pl_max_y); + addstat(STAT_PL_MAX3, AS_FLOAT, stat_pl_max_z); + addstat(STAT_PL_CROUCH_MIN1, AS_FLOAT, stat_pl_crouch_min_x); + addstat(STAT_PL_CROUCH_MIN2, AS_FLOAT, stat_pl_crouch_min_y); + addstat(STAT_PL_CROUCH_MIN3, AS_FLOAT, stat_pl_crouch_min_z); + addstat(STAT_PL_CROUCH_MAX1, AS_FLOAT, stat_pl_crouch_max_x); + addstat(STAT_PL_CROUCH_MAX2, AS_FLOAT, stat_pl_crouch_max_y); + addstat(STAT_PL_CROUCH_MAX3, AS_FLOAT, stat_pl_crouch_max_z); + // g_movementspeed hack addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw); addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed); @@ -52,35 +76,116 @@ void Physics_AddStats() addstat(STAT_JETPACK_FUEL, AS_FLOAT, stat_jetpack_fuel); addstat(STAT_JETPACK_MAXSPEED_UP, AS_FLOAT, stat_jetpack_maxspeed_up); addstat(STAT_JETPACK_MAXSPEED_SIDE, AS_FLOAT, stat_jetpack_maxspeed_side); + + // hack to fix track_canjump + addstat(STAT_MOVEVARS_TRACK_CANJUMP, AS_INT, cvar_cl_movement_track_canjump); + + // double jump + addstat(STAT_DOUBLEJUMP, AS_INT, stat_doublejump); + + // jump speed caps + addstat(STAT_MOVEVARS_JUMPSPEEDCAP_DISABLE_ONRAMPS, AS_INT, stat_jumpspeedcap_disable_onramps); + + // hacks + addstat(STAT_MOVEVARS_FRICTION_ONLAND, AS_FLOAT, stat_sv_friction_on_land); + addstat(STAT_MOVEVARS_FRICTION_SLICK, AS_FLOAT, stat_sv_friction_slick); + addstat(STAT_GAMEPLAYFIX_EASIERWATERJUMP, AS_INT, stat_gameplayfix_easierwaterjump); + + // new properties + addstat(STAT_MOVEVARS_JUMPVELOCITY, AS_FLOAT, stat_sv_jumpvelocity); + addstat(STAT_MOVEVARS_AIRACCEL_QW_STRETCHFACTOR, AS_FLOAT, stat_sv_airaccel_qw_stretchfactor); + addstat(STAT_MOVEVARS_MAXAIRSTRAFESPEED, AS_FLOAT, stat_sv_maxairstrafespeed); + addstat(STAT_MOVEVARS_MAXAIRSPEED, AS_FLOAT, stat_sv_maxairspeed); + addstat(STAT_MOVEVARS_AIRSTRAFEACCELERATE, AS_FLOAT, stat_sv_airstrafeaccelerate); + addstat(STAT_MOVEVARS_WARSOWBUNNY_TURNACCEL, AS_FLOAT, stat_sv_warsowbunny_turnaccel); + addstat(STAT_MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION, AS_FLOAT, stat_sv_airaccel_sideways_friction); + addstat(STAT_MOVEVARS_AIRCONTROL, AS_FLOAT, stat_sv_aircontrol); + addstat(STAT_MOVEVARS_AIRCONTROL_POWER, AS_FLOAT, stat_sv_aircontrol_power); + addstat(STAT_MOVEVARS_AIRCONTROL_PENALTY, AS_FLOAT, stat_sv_aircontrol_penalty); + addstat(STAT_MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL, AS_FLOAT, stat_sv_warsowbunny_airforwardaccel); + addstat(STAT_MOVEVARS_WARSOWBUNNY_TOPSPEED, AS_FLOAT, stat_sv_warsowbunny_topspeed); + addstat(STAT_MOVEVARS_WARSOWBUNNY_ACCEL, AS_FLOAT, stat_sv_warsowbunny_accel); + addstat(STAT_MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO, AS_FLOAT, stat_sv_warsowbunny_backtosideratio); + addstat(STAT_MOVEVARS_FRICTION, AS_FLOAT, stat_sv_friction); + addstat(STAT_MOVEVARS_ACCELERATE, AS_FLOAT, stat_sv_accelerate); + addstat(STAT_MOVEVARS_STOPSPEED, AS_FLOAT, stat_sv_stopspeed); + addstat(STAT_MOVEVARS_AIRACCELERATE, AS_FLOAT, stat_sv_airaccelerate); + addstat(STAT_MOVEVARS_AIRSTOPACCELERATE, AS_FLOAT, stat_sv_airstopaccelerate); + + addstat(STAT_GAMEPLAYFIX_UPVELOCITYCLEARSONGROUND, AS_INT, stat_gameplayfix_upvelocityclearsonground); } void Physics_UpdateStats(float maxspd_mod) { - self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod); - if (autocvar_sv_airstrafeaccel_qw) - self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod); + // blah + self.stat_pl_view_ofs = PL_VIEW_OFS; + self.stat_pl_crouch_view_ofs = PL_CROUCH_VIEW_OFS; + + self.stat_pl_min = PL_MIN; + self.stat_pl_max = PL_MAX; + self.stat_pl_crouch_min = PL_CROUCH_MIN; + self.stat_pl_crouch_max = PL_CROUCH_MAX; + + + self.stat_sv_airaccel_qw = AdjustAirAccelQW(Physics_ClientOption(self, "airaccel_qw"), maxspd_mod); + if(Physics_ClientOption(self, "airstrafeaccel_qw")) + self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(Physics_ClientOption(self, "airstrafeaccel_qw"), maxspd_mod); else self.stat_sv_airstrafeaccel_qw = 0; - self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod; - self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking + self.stat_sv_airspeedlimit_nonqw = Physics_ClientOption(self, "airspeedlimit_nonqw") * maxspd_mod; + self.stat_sv_maxspeed = Physics_ClientOption(self, "maxspeed") * maxspd_mod; // also slow walking self.stat_movement_highspeed = PHYS_HIGHSPEED; // TODO: remove this! + self.stat_doublejump = PHYS_DOUBLEJUMP; + self.stat_jetpack_antigravity = PHYS_JETPACK_ANTIGRAVITY; self.stat_jetpack_accel_up = PHYS_JETPACK_ACCEL_UP; self.stat_jetpack_accel_side = PHYS_JETPACK_ACCEL_SIDE; self.stat_jetpack_maxspeed_side = PHYS_JETPACK_MAXSPEED_SIDE; self.stat_jetpack_maxspeed_up = PHYS_JETPACK_MAXSPEED_UP; self.stat_jetpack_fuel = PHYS_JETPACK_FUEL; + + self.stat_jumpspeedcap_disable_onramps = PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS; + + self.stat_sv_friction_on_land = PHYS_FRICTION_ONLAND; + self.stat_sv_friction_slick = PHYS_FRICTION_SLICK; + + self.stat_gameplayfix_easierwaterjump = GAMEPLAYFIX_EASIERWATERJUMP; + + + // old stats + // fix some new settings + self.stat_sv_airaccel_qw_stretchfactor = Physics_ClientOption(self, "airaccel_qw_stretchfactor"); + self.stat_sv_maxairstrafespeed = Physics_ClientOption(self, "maxairstrafespeed"); + self.stat_sv_maxairspeed = Physics_ClientOption(self, "maxairspeed"); + self.stat_sv_airstrafeaccelerate = Physics_ClientOption(self, "airstrafeaccelerate"); + self.stat_sv_warsowbunny_turnaccel = Physics_ClientOption(self, "warsowbunny_turnaccel"); + self.stat_sv_airaccel_sideways_friction = Physics_ClientOption(self, "airaccel_sideways_friction"); + self.stat_sv_aircontrol = Physics_ClientOption(self, "aircontrol"); + self.stat_sv_aircontrol_power = Physics_ClientOption(self, "aircontrol_power"); + self.stat_sv_aircontrol_penalty = Physics_ClientOption(self, "aircontrol_penalty"); + self.stat_sv_warsowbunny_airforwardaccel = Physics_ClientOption(self, "warsowbunny_airforwardaccel"); + self.stat_sv_warsowbunny_topspeed = Physics_ClientOption(self, "warsowbunny_topspeed"); + self.stat_sv_warsowbunny_accel = Physics_ClientOption(self, "warsowbunny_accel"); + self.stat_sv_warsowbunny_backtosideratio = Physics_ClientOption(self, "warsowbunny_backtosideratio"); + self.stat_sv_friction = Physics_ClientOption(self, "friction"); + self.stat_sv_accelerate = Physics_ClientOption(self, "accelerate"); + self.stat_sv_stopspeed = Physics_ClientOption(self, "stopspeed"); + self.stat_sv_airaccelerate = Physics_ClientOption(self, "airaccelerate"); + self.stat_sv_airstopaccelerate = Physics_ClientOption(self, "airstopaccelerate"); + self.stat_sv_jumpvelocity = Physics_ClientOption(self, "jumpvelocity"); + + self.stat_gameplayfix_upvelocityclearsonground = UPWARD_VELOCITY_CLEARS_ONGROUND; } #endif -float IsMoveInDirection(vector mv, float angle) // key mix factor +float IsMoveInDirection(vector mv, float ang) // key mix factor { if (mv_x == 0 && mv_y == 0) return 0; // avoid division by zero - angle -= RAD2DEG * atan2(mv_y, mv_x); - angle = remainder(angle, 360) / 45; - return angle > 1 ? 0 : angle < -1 ? 0 : 1 - fabs(angle); + ang -= RAD2DEG * atan2(mv_y, mv_x); + ang = remainder(ang, 360) / 45; + return ang > 1 ? 0 : ang < -1 ? 0 : 1 - fabs(ang); } float GeomLerp(float a, float lerp, float b) @@ -125,13 +230,13 @@ void PM_ClientMovement_Unstick() tracebox(neworigin, PL_CROUCH_MIN, PL_CROUCH_MAX, neworigin, MOVE_NORMAL, self); if (!trace_startsolid) { - self.origin = neworigin; + setorigin(self, neworigin); return;// true; } } } -void PM_ClientMovement_UpdateStatus() +void PM_ClientMovement_UpdateStatus(bool ground) { // make sure player is not stuck PM_ClientMovement_Unstick(); @@ -159,35 +264,41 @@ void PM_ClientMovement_UpdateStatus() vector origin1 = self.origin + '0 0 1'; vector origin2 = self.origin - '0 0 1'; - tracebox(origin1, self.mins, self.maxs, origin2, MOVE_NORMAL, self); - if (trace_fraction < 1 && trace_plane_normal_z > 0.7) + if(ground) { - SET_ONGROUND(self); + tracebox(origin1, self.mins, self.maxs, origin2, MOVE_NORMAL, self); + if (trace_fraction < 1.0 && trace_plane_normal_z > 0.7) + { + SET_ONGROUND(self); - // this code actually "predicts" an impact; so let's clip velocity first - float f = dotproduct(self.velocity, trace_plane_normal); - if (f < 0) // only if moving downwards actually + // this code actually "predicts" an impact; so let's clip velocity first + float f = self.velocity * trace_plane_normal; self.velocity -= f * trace_plane_normal; + } + else + UNSET_ONGROUND(self); } - else - UNSET_ONGROUND(self); // set watertype/waterlevel origin1 = self.origin; origin1_z += self.mins_z + 1; self.waterlevel = WATERLEVEL_NONE; - self.watertype = (pointcontents(origin1) == CONTENT_WATER); + int thepoint = pointcontents(origin1); + + self.watertype = (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME); if(self.watertype) { self.waterlevel = WATERLEVEL_WETFEET; origin1_z = self.origin_z + (self.mins_z + self.maxs_z) * 0.5; - if(pointcontents(origin1) == CONTENT_WATER) + thepoint = pointcontents(origin1); + if(thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME) { self.waterlevel = WATERLEVEL_SWIMMING; origin1_z = self.origin_z + 22; - if(pointcontents(origin1) == CONTENT_WATER) + thepoint = pointcontents(origin1); + if(thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME) self.waterlevel = WATERLEVEL_SUBMERGED; } } @@ -199,92 +310,99 @@ void PM_ClientMovement_UpdateStatus() void PM_ClientMovement_Move() { #ifdef CSQC - float t = PHYS_INPUT_TIMELENGTH; - vector primalvelocity = self.velocity; - PM_ClientMovement_UpdateStatus(); - float bump = 0; - for (bump = 0; bump < 8 && self.velocity * self.velocity > 0; bump++) + int bump; + float t; + float f; + vector neworigin; + vector currentorigin2; + vector neworigin2; + vector primalvelocity; + + vector trace1_endpos = '0 0 0'; + vector trace2_endpos = '0 0 0'; + vector trace3_endpos = '0 0 0'; + float trace1_fraction = 0; + float trace2_fraction = 0; + float trace3_fraction = 0; + vector trace1_plane_normal = '0 0 0'; + vector trace2_plane_normal = '0 0 0'; + vector trace3_plane_normal = '0 0 0'; + + + PM_ClientMovement_UpdateStatus(false); + primalvelocity = self.velocity; + for(bump = 0, t = PHYS_INPUT_TIMELENGTH; bump < 8 && (self.velocity * self.velocity) > 0; bump++) { - vector neworigin = self.origin + t * self.velocity; + neworigin = self.origin + t * self.velocity; tracebox(self.origin, self.mins, self.maxs, neworigin, MOVE_NORMAL, self); - float old_trace1_fraction = trace_fraction; - vector old_trace1_endpos = trace_endpos; - vector old_trace1_plane_normal = trace_plane_normal; - if (trace_fraction < 1 && trace_plane_normal_z == 0) + trace1_endpos = trace_endpos; + trace1_fraction = trace_fraction; + trace1_plane_normal = trace_plane_normal; + if(trace1_fraction < 1 && trace1_plane_normal_z == 0) { // may be a step or wall, try stepping up // first move forward at a higher level - vector currentorigin2 = self.origin; + currentorigin2 = self.origin; currentorigin2_z += PHYS_STEPHEIGHT; - vector neworigin2 = neworigin; - neworigin2_z = self.origin_z + PHYS_STEPHEIGHT; + neworigin2 = neworigin; + neworigin2_z += PHYS_STEPHEIGHT; tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self); - if (!trace_startsolid) + trace2_endpos = trace_endpos; + trace2_fraction = trace_fraction; + trace2_plane_normal = trace_plane_normal; + if(!trace_startsolid) { // then move down from there - currentorigin2 = trace_endpos; - neworigin2 = trace_endpos; + currentorigin2 = trace2_endpos; + neworigin2 = trace2_endpos; neworigin2_z = self.origin_z; - float old_trace2_fraction = trace_fraction; - vector old_trace2_plane_normal = trace_plane_normal; tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self); - //Con_Printf("%f %f %f %f : %f %f %f %f : %f %f %f %f\n", trace.fraction, trace.endpos[0], trace.endpos[1], trace.endpos[2], trace2.fraction, trace2.endpos[0], trace2.endpos[1], trace2.endpos[2], trace3.fraction, trace3.endpos[0], trace3.endpos[1], trace3.endpos[2]); + trace3_endpos = trace_endpos; + trace3_fraction = trace_fraction; + trace3_plane_normal = trace_plane_normal; // accept the new trace if it made some progress - if (fabs(trace_endpos_x - old_trace1_endpos_x) >= 0.03125 || fabs(trace_endpos_y - old_trace1_endpos_y) >= 0.03125) - { - trace_fraction = old_trace2_fraction; - trace_endpos = trace_endpos; - trace_plane_normal = old_trace2_plane_normal; - } - else + if(fabs(trace3_endpos_x - trace1_endpos_x) >= 0.03125 || fabs(trace3_endpos_y - trace1_endpos_y) >= 0.03125) { - trace_fraction = old_trace1_fraction; - trace_endpos = old_trace1_endpos; - trace_plane_normal = old_trace1_plane_normal; + trace1_endpos = trace2_endpos; + trace1_fraction = trace2_fraction; + trace1_plane_normal = trace2_plane_normal; + trace1_endpos = trace3_endpos; } } } // check if it moved at all - if (trace_fraction >= 0.001) - self.origin = trace_endpos; + if(trace1_fraction >= 0.001) + setorigin(self, trace1_endpos); // check if it moved all the way - if (trace_fraction == 1) + if(trace1_fraction == 1) break; // this is only really needed for nogravityonground combined with gravityunaffectedbyticrate // I'm pretty sure I commented it out solely because it seemed redundant // this got commented out in a change that supposedly makes the code match QW better - // so if this is broken, maybe put it in an if (cls.protocol != PROTOCOL_QUAKEWORLD) block - if (trace_plane_normal_z > 0.7) + // so if this is broken, maybe put it in an if(cls.protocol != PROTOCOL_QUAKEWORLD) block + if(trace1_plane_normal_z > 0.7) SET_ONGROUND(self); - t -= t * trace_fraction; + t -= t * trace1_fraction; - float f = dotproduct(self.velocity, trace_plane_normal); - self.velocity -= f * trace_plane_normal; + f = (self.velocity * trace1_plane_normal); + self.velocity = self.velocity + -f * trace1_plane_normal; } - if (pmove_waterjumptime > 0) + if(pmove_waterjumptime > 0) self.velocity = primalvelocity; #endif } void CPM_PM_Aircontrol(vector wishdir, float wishspeed) { - float k; -#if 0 - // this doesn't play well with analog input - if (PHYS_INPUT_MOVEVALUES(self).x == 0 || PHYS_INPUT_MOVEVALUES(self).y != 0) - return; // can't control movement if not moving forward or backward - k = 32; -#else - k = 32 * (2 * IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), 0) - 1); + float k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1); if (k <= 0) return; -#endif - k *= bound(0, wishspeed / PHYS_MAXAIRSPEED, 1); + k *= bound(0, wishspeed / PHYS_MAXAIRSPEED(self), 1); float zspeed = self.velocity_z; self.velocity_z = 0; @@ -295,7 +413,7 @@ void CPM_PM_Aircontrol(vector wishdir, float wishspeed) if (dot > 0) // we can't change direction while slowing down { - k *= pow(dot, PHYS_AIRCONTROL_POWER)*PHYS_INPUT_TIMELENGTH; + k *= pow(dot, PHYS_AIRCONTROL_POWER) * PHYS_INPUT_TIMELENGTH; xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY * sqrt(max(0, 1 - dot*dot)) * k/32); k *= PHYS_AIRCONTROL; self.velocity = normalize(self.velocity * xyspeed + wishdir * k); @@ -419,34 +537,40 @@ void PM_AirAccelerate(vector wishdir, float wishspeed) PlayerJump When you press the jump key +returns true if handled ============= */ -void PlayerJump (void) +bool PlayerJump (void) { -#ifdef SVQC if (PHYS_FROZEN(self)) - return; // no jumping in freezetag when frozen + return true; // no jumping in freezetag when frozen +#ifdef SVQC if (self.player_blocked) - return; // no jumping while blocked + return true; // no jumping while blocked +#endif - float doublejump = FALSE; + bool doublejump = false; float mjumpheight = PHYS_JUMPVELOCITY; +#ifdef SVQC + if (MUTATOR_CALLHOOK(PlayerJump, doublejump, mjumpheight)) +#elif defined(CSQC) player_multijump = doublejump; player_jumpheight = mjumpheight; - if (MUTATOR_CALLHOOK(PlayerJump)) - return; + if (PM_multijump_checkjump()) +#endif + return true; doublejump = player_multijump; mjumpheight = player_jumpheight; - if (autocvar_sv_doublejump) + if (PHYS_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; + doublejump = true; // we MUST clip velocity here! float f; @@ -458,110 +582,157 @@ void PlayerJump (void) if (self.waterlevel >= WATERLEVEL_SWIMMING) { - self.velocity_z = self.stat_sv_maxspeed * 0.7; - return; + self.velocity_z = PHYS_MAXSPEED(self) * 0.7; + return true; } if (!doublejump) if (!IS_ONGROUND(self)) - return; + return IS_JUMP_HELD(self); - if (self.cvar_cl_movement_track_canjump) - if (!(self.flags & FL_JUMPRELEASED)) - return; + if (PHYS_TRACK_CANJUMP(self)) + if (IS_JUMP_HELD(self)) + return true; // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline // velocity bounds. Final velocity is bound between (jumpheight * // min + jumpheight) and (jumpheight * max + jumpheight); - if (autocvar_sv_jumpspeedcap_min != "") + if(PHYS_JUMPSPEEDCAP_MIN != "") { - float minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min); + float minjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MIN); if (self.velocity_z < minjumpspeed) mjumpheight += minjumpspeed - self.velocity_z; } - if (autocvar_sv_jumpspeedcap_max != "") + if(PHYS_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 && autocvar_sv_jumpspeedcap_max_disable_on_ramps)) + if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS)) { - float maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max); + float maxjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MAX); if (self.velocity_z > maxjumpspeed) mjumpheight -= self.velocity_z - maxjumpspeed; } } - if (!(self.lastflags & FL_ONGROUND)) + if (!WAS_ONGROUND(self)) { - if (autocvar_speedmeter) +#ifdef SVQC + if(autocvar_speedmeter) dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n")); - if (self.lastground < time - 0.3) +#endif + if(self.lastground < time - 0.3) { - self.velocity_x *= (1 - autocvar_sv_friction_on_land); - self.velocity_y *= (1 - autocvar_sv_friction_on_land); + self.velocity_x *= (1 - PHYS_FRICTION_ONLAND); + self.velocity_y *= (1 - PHYS_FRICTION_ONLAND); } - if (self.jumppadcount > 1) +#ifdef SVQC + if(self.jumppadcount > 1) dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n")); self.jumppadcount = 0; +#endif } - self.oldvelocity_z = self.velocity_z += mjumpheight; + self.velocity_z += mjumpheight; UNSET_ONGROUND(self); - self.flags &= ~FL_JUMPRELEASED; + SET_JUMP_HELD(self); - animdecide_setaction(self, ANIMACTION_JUMP, TRUE); +#ifdef SVQC + + self.oldvelocity_z = self.velocity_z; + + animdecide_setaction(self, ANIMACTION_JUMP, true); if (autocvar_g_jump_grunt) PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND); - - self.restart_jump = -1; // restart jump anim next time - // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping) #endif + return true; } void CheckWaterJump() { // check for a jump-out-of-water - makevectors(PHYS_INPUT_ANGLES(self)); + makevectors(self.v_angle); vector start = self.origin; start_z += 8; v_forward_z = 0; normalize(v_forward); vector end = start + v_forward*24; - traceline (start, end, TRUE, self); + traceline (start, end, true, self); if (trace_fraction < 1) { // solid at waist start_z = start_z + self.maxs_z - 8; end = start + v_forward*24; self.movedir = trace_plane_normal * -50; - traceline(start, end, TRUE, self); + traceline(start, end, true, self); if (trace_fraction == 1) { // open at eye level self.velocity_z = 225; -#ifdef SVQC self.flags |= FL_WATERJUMP; - self.flags &= ~FL_JUMPRELEASED; + SET_JUMP_HELD(self); +#ifdef SVQC self.teleport_time = time + 2; // safety net +#elif defined(CSQC) + pmove_waterjumptime = time + 2; #endif } } } + +#ifdef SVQC + #define JETPACK_JUMP(s) s.cvar_cl_jetpack_jump +#elif defined(CSQC) + float autocvar_cl_jetpack_jump; + #define JETPACK_JUMP(s) autocvar_cl_jetpack_jump +#endif +.float jetpack_stopped; +// Hack: shouldn't need to know about this +.float multijump_count; void CheckPlayerJump() { #ifdef SVQC - if (self.BUTTON_JUMP) - PlayerJump(); - else - self.flags |= FL_JUMPRELEASED; + float was_flying = ITEMS_STAT(self) & IT_USING_JETPACK; +#endif + if (JETPACK_JUMP(self) < 2) + ITEMS_STAT(self) &= ~IT_USING_JETPACK; + if(PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_JETPACK(self)) + { + float air_jump = !PlayerJump() || self.multijump_count > 0; // PlayerJump() has important side effects + float activate = JETPACK_JUMP(self) && air_jump && PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_JETPACK(self); + float has_fuel = !PHYS_JETPACK_FUEL || PHYS_AMMO_FUEL(self) || ITEMS_STAT(self) & IT_UNLIMITED_WEAPON_AMMO; + + if (!(ITEMS_STAT(self) & IT_JETPACK)) { } + else if (self.jetpack_stopped) { } + else if (!has_fuel) + { +#ifdef SVQC + if (was_flying) // TODO: ran out of fuel message + Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL); + else if (activate) + Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL); #endif + self.jetpack_stopped = true; + ITEMS_STAT(self) &= ~IT_USING_JETPACK; + } + else if (activate && !PHYS_FROZEN(self)) + ITEMS_STAT(self) |= IT_USING_JETPACK; + } + else + { + self.jetpack_stopped = false; + ITEMS_STAT(self) &= ~IT_USING_JETPACK; + } + if (!PHYS_INPUT_BUTTON_JUMP(self)) + UNSET_JUMP_HELD(self); + if (self.waterlevel == WATERLEVEL_SWIMMING) CheckWaterJump(); } @@ -593,8 +764,8 @@ void RaceCarPhysics() vector rigvel; vector angles_save = self.angles; - float accel = bound(-1, PHYS_INPUT_MOVEVALUES(self).x / self.stat_sv_maxspeed, 1); - float steer = bound(-1, PHYS_INPUT_MOVEVALUES(self).y / self.stat_sv_maxspeed, 1); + float accel = bound(-1, self.movement.x / PHYS_MAXSPEED(self), 1); + float steer = bound(-1, self.movement.y / PHYS_MAXSPEED(self), 1); if (g_bugrigs_reverse_speeding) { @@ -804,40 +975,6 @@ void SpecialCommand() #endif } -#ifdef SVQC -float speedaward_speed; -string speedaward_holder; -string speedaward_uid; -#endif -void race_send_speedaward(float msg) -{ -#ifdef SVQC - // send the best speed of the round - WriteByte(msg, SVC_TEMPENTITY); - WriteByte(msg, TE_CSQC_RACE); - WriteByte(msg, RACE_NET_SPEED_AWARD); - WriteInt24_t(msg, floor(speedaward_speed+0.5)); - WriteString(msg, speedaward_holder); -#endif -} - -#ifdef SVQC -float speedaward_alltimebest; -string speedaward_alltimebest_holder; -string speedaward_alltimebest_uid; -#endif -void race_send_speedaward_alltimebest(float msg) -{ -#ifdef SVQC - // send the best speed - WriteByte(msg, SVC_TEMPENTITY); - WriteByte(msg, TE_CSQC_RACE); - WriteByte(msg, RACE_NET_SPEED_AWARD_BEST); - WriteInt24_t(msg, floor(speedaward_alltimebest+0.5)); - WriteString(msg, speedaward_alltimebest_holder); -#endif -} - float PM_check_keepaway(void) { #ifdef SVQC @@ -886,13 +1023,13 @@ float PM_check_specialcommand(float buttons) { self.specialcommand_pos = 0; SpecialCommand(); - return TRUE; + return true; } } else if (self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1))) self.specialcommand_pos = 0; #endif - return FALSE; + return false; } void PM_check_nickspam(void) @@ -903,15 +1040,15 @@ void PM_check_nickspam(void) if (self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow) { // slight annoyance for nick change scripts - PHYS_INPUT_MOVEVALUES(self) = -1 * PHYS_INPUT_MOVEVALUES(self); + 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 >= autocvar_g_nick_flood_penalty_red) // if you are persistent and the slight annoyance above does not stop you, I'll show you! { - PHYS_INPUT_ANGLES(self)_x = random() * 360; - PHYS_INPUT_ANGLES(self)_y = random() * 360; + self.v_angle_x = random() * 360; + self.v_angle_y = random() * 360; // at least I'm not forcing retardedview by also assigning to angles_z - self.fixangle = TRUE; + self.fixangle = true; } } #endif @@ -945,8 +1082,10 @@ void PM_check_spider(void) #ifdef SVQC if (time >= self.spider_slowness) return; - self.stat_sv_maxspeed *= 0.5; // half speed while slow from spider - self.stat_sv_airspeedlimit_nonqw *= 0.5; + PHYS_MAXSPEED(self) *= 0.5; // half speed while slow from spider + PHYS_MAXAIRSPEED(self) *= 0.5; + PHYS_AIRSPEEDLIMIT_NONQW(self) *= 0.5; + PHYS_AIRSTRAFEACCELERATE(self) *= 0.5; #endif } @@ -961,12 +1100,12 @@ void PM_check_frozen(void) #endif ) { - PHYS_INPUT_MOVEVALUES(self)_x = bound(-5, PHYS_INPUT_MOVEVALUES(self).x, 5); - PHYS_INPUT_MOVEVALUES(self)_y = bound(-5, PHYS_INPUT_MOVEVALUES(self).y, 5); - PHYS_INPUT_MOVEVALUES(self)_z = bound(-5, PHYS_INPUT_MOVEVALUES(self).z, 5); + self.movement_x = bound(-5, self.movement.x, 5); + self.movement_y = bound(-5, self.movement.y, 5); + self.movement_z = bound(-5, self.movement.z, 5); } else - PHYS_INPUT_MOVEVALUES(self) = '0 0 0'; + self.movement = '0 0 0'; vector midpoint = ((self.absmin + self.absmax) * 0.5); if (pointcontents(midpoint) == CONTENT_WATER) @@ -978,12 +1117,39 @@ void PM_check_frozen(void) } } +void PM_check_hitground() +{ +#ifdef SVQC + if (IS_ONGROUND(self)) + if (IS_PLAYER(self)) // no fall sounds for observers thank you very much + if (self.wasFlying) + { + self.wasFlying = 0; + if (self.waterlevel < WATERLEVEL_SWIMMING) + if (time >= self.ladder_time) + if (!self.hook) + { + self.nextstep = time + 0.3 + random() * 0.1; + trace_dphitq3surfaceflags = 0; + tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self); + if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)) + { + if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS) + GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND); + else + GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND); + } + } + } +#endif +} + void PM_check_blocked(void) { #ifdef SVQC if (!self.player_blocked) return; - PHYS_INPUT_MOVEVALUES(self) = '0 0 0'; + self.movement = '0 0 0'; self.disableclientprediction = 1; #endif } @@ -991,12 +1157,11 @@ void PM_check_blocked(void) #ifdef SVQC float speedaward_lastsent; float speedaward_lastupdate; -string GetMapname(void); #endif void PM_check_race(void) { #ifdef SVQC - if not(g_cts || g_race) + if(!(g_cts || g_race)) return; if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) { @@ -1026,14 +1191,15 @@ void PM_check_race(void) void PM_check_vortex(void) { #ifdef SVQC + // WEAPONTODO float xyspeed = vlen(vec2(self.velocity)); - if (self.weapon == WEP_NEX && autocvar_g_balance_nex_charge && autocvar_g_balance_nex_charge_velocity_rate && xyspeed > autocvar_g_balance_nex_charge_minspeed) + if (self.weapon == WEP_VORTEX && WEP_CVAR(vortex, charge) && WEP_CVAR(vortex, charge_velocity_rate) && xyspeed > WEP_CVAR(vortex, 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, autocvar_g_balance_nex_charge_maxspeed); - float f = (xyspeed - autocvar_g_balance_nex_charge_minspeed) / (autocvar_g_balance_nex_charge_maxspeed - autocvar_g_balance_nex_charge_minspeed); + xyspeed = min(xyspeed, WEP_CVAR(vortex, charge_maxspeed)); + float f = (xyspeed - WEP_CVAR(vortex, charge_minspeed)) / (WEP_CVAR(vortex, charge_maxspeed) - WEP_CVAR(vortex, charge_minspeed)); // add the extra charge - self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_velocity_rate * f * PHYS_INPUT_TIMELENGTH); + self.vortex_charge = min(1, self.vortex_charge + WEP_CVAR(vortex, charge_velocity_rate) * f * PHYS_INPUT_TIMELENGTH); } #endif } @@ -1044,16 +1210,19 @@ void PM_fly(float maxspd_mod) UNSET_ONGROUND(self); self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION); - makevectors(PHYS_INPUT_ANGLES(self)); - //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z; - vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x - + v_right * PHYS_INPUT_MOVEVALUES(self).y - + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z; + makevectors(self.v_angle); + //wishvel = v_forward * self.movement.x + v_right * self.movement.y + v_up * self.movement.z; + vector wishvel = v_forward * self.movement.x + + v_right * self.movement.y + + '0 0 1' * self.movement.z; // acceleration vector wishdir = normalize(wishvel); float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod); +#ifdef SVQC if (time >= self.teleport_time) +#endif PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0); + PM_ClientMovement_Move(); } void PM_swim(float maxspd_mod) @@ -1066,7 +1235,7 @@ void PM_swim(float maxspd_mod) // this mimics quakeworld code if (jump && self.waterlevel == WATERLEVEL_SWIMMING && self.velocity_z >= -180) { - vector yawangles = '0 1 0' * PHYS_INPUT_ANGLES(self).y; + vector yawangles = '0 1 0' * self.v_angle.y; makevectors(yawangles); vector forward = v_forward; vector spot = self.origin + 24 * forward; @@ -1086,11 +1255,11 @@ void PM_swim(float maxspd_mod) } } } - makevectors(PHYS_INPUT_ANGLES(self)); - //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z; - vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x - + v_right * PHYS_INPUT_MOVEVALUES(self).y - + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z; + makevectors(self.v_angle); + //wishvel = v_forward * self.movement.x + v_right * self.movement.y + v_up * self.movement.z; + vector wishvel = v_forward * self.movement.x + + v_right * self.movement.y + + '0 0 1' * self.movement.z; if (wishvel == '0 0 0') wishvel = '0 0 -60'; // drift towards bottom @@ -1134,14 +1303,13 @@ void PM_swim(float maxspd_mod) #endif } } - PM_ClientMovement_Move(); // water acceleration PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0); + PM_ClientMovement_Move(); } void PM_ladder(float maxspd_mod) { -#ifdef SVQC // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water UNSET_ONGROUND(self); @@ -1156,11 +1324,11 @@ void PM_ladder(float maxspd_mod) } self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION); - makevectors(PHYS_INPUT_ANGLES(self)); - //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z; - vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x - + v_right * PHYS_INPUT_MOVEVALUES(self).y - + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z; + makevectors(self.v_angle); + //wishvel = v_forward * self.movement.x + v_right * self.movement.y + v_up * self.movement.z; + vector wishvel = v_forward * self.movement_x + + v_right * self.movement_y + + '0 0 1' * self.movement_z; self.velocity_z += g; if (self.ladder_entity.classname == "func_water") { @@ -1184,21 +1352,23 @@ void PM_ladder(float maxspd_mod) } // acceleration vector wishdir = normalize(wishvel); - float wishspeed = min(vlen(wishvel), self.stat_sv_maxspeed * maxspd_mod); + float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod); +#ifdef SVQC if (time >= self.teleport_time) +#endif // water acceleration PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE*maxspd_mod, 1, 0, 0, 0); -#endif + PM_ClientMovement_Move(); } void PM_jetpack(float maxspd_mod) { - //makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0'); - makevectors(PHYS_INPUT_ANGLES(self)); - vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self)_x - + v_right * PHYS_INPUT_MOVEVALUES(self)_y; + //makevectors(self.v_angle.y * '0 1 0'); + makevectors(self.v_angle); + vector wishvel = v_forward * self.movement_x + + v_right * self.movement_y; // add remaining speed as Z component - float maxairspd = PHYS_MAXAIRSPEED * max(1, maxspd_mod); + float maxairspd = PHYS_MAXAIRSPEED(self) * max(1, maxspd_mod); // fix speedhacks :P wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd); // add the unused velocity as up component @@ -1271,7 +1441,7 @@ void PM_jetpack(float maxspd_mod) wishvel_z = (wishvel_z - PHYS_GRAVITY) * fz + PHYS_GRAVITY; fvel = min(1, vlen(wishvel) / best); - if (PHYS_JETPACK_FUEL && !(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO)) + if (PHYS_JETPACK_FUEL && !(ITEMS_STAT(self) & IT_UNLIMITED_WEAPON_AMMO)) f = min(1, PHYS_AMMO_FUEL(self) / (PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel)); else f = 1; @@ -1284,10 +1454,10 @@ void PM_jetpack(float maxspd_mod) UNSET_ONGROUND(self); #ifdef SVQC - if (!(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO)) + if (!(ITEMS_STAT(self) & IT_UNLIMITED_WEAPON_AMMO)) self.ammo_fuel -= PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel * f; - self.items |= IT_USING_JETPACK; + ITEMS_STAT(self) |= IT_USING_JETPACK; // jetpack also inhibits health regeneration, but only for 1 second self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen); @@ -1309,25 +1479,25 @@ void PM_jetpack(float maxspd_mod) void PM_walk(float buttons_prev, float maxspd_mod) { -#ifdef SVQC - // we get here if we ran out of ammo - if ((ITEMS(self) & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01) - sprint(self, "You don't have any fuel for the ^2Jetpack\n"); - if (!(self.lastflags & FL_ONGROUND)) + if (!WAS_ONGROUND(self)) { +#ifdef SVQC if (autocvar_speedmeter) dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n")); +#endif if (self.lastground < time - 0.3) - self.velocity *= (1 - autocvar_sv_friction_on_land); + self.velocity *= (1 - PHYS_FRICTION_ONLAND); +#ifdef SVQC if (self.jumppadcount > 1) dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n")); self.jumppadcount = 0; - } #endif + } + // walking - makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0'); - vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x - + v_right * PHYS_INPUT_MOVEVALUES(self).y; + makevectors(self.v_angle.y * '0 1 0'); + vector wishvel = v_forward * self.movement.x + + v_right * self.movement.y; // acceleration vector wishdir = normalize(wishvel); float wishspeed = vlen(wishvel); @@ -1340,9 +1510,17 @@ void PM_walk(float buttons_prev, float maxspd_mod) float f = vlen(vec2(self.velocity)); if (f > 0) { + float realfriction; + trace_dphitq3surfaceflags = 0; + tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self); // TODO: apply edge friction // apply ground friction - f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION * ((f < PHYS_STOPSPEED) ? (PHYS_STOPSPEED / f) : 1); + if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) + realfriction = PHYS_FRICTION_SLICK; + else + realfriction = PHYS_FRICTION; + + f = 1 - PHYS_INPUT_TIMELENGTH * realfriction * ((f < PHYS_STOPSPEED) ? (PHYS_STOPSPEED / f) : 1); f = max(0, f); self.velocity *= f; /* @@ -1386,14 +1564,9 @@ void PM_walk(float buttons_prev, float maxspd_mod) void PM_air(float buttons_prev, float maxspd_mod) { -#ifdef SVQC - // we get here if we ran out of ammo - if ((ITEMS(self) & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && PHYS_AMMO_FUEL(self) < 0.01) - sprint(self, "You don't have any fuel for the ^2Jetpack\n"); -#endif - makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0'); - vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x - + v_right * PHYS_INPUT_MOVEVALUES(self).y; + makevectors(self.v_angle.y * '0 1 0'); + vector wishvel = v_forward * self.movement.x + + v_right * self.movement.y; // acceleration vector wishdir = normalize(wishvel); float wishspeed = vlen(wishvel); @@ -1404,7 +1577,7 @@ void PM_air(float buttons_prev, float maxspd_mod) if (pmove_waterjumptime <= 0) #endif { - float maxairspd = PHYS_MAXAIRSPEED * min(maxspd_mod, 1); + float maxairspd = PHYS_MAXAIRSPEED(self) * min(maxspd_mod, 1); // apply air speed limit float airaccelqw = PHYS_AIRACCEL_QW(self); @@ -1431,11 +1604,11 @@ void PM_air(float buttons_prev, float maxspd_mod) // dv/dt = accel * maxspeed * (1 - accelqw) (when fast) // log dv/dt = logaccel + logmaxspeed (when slow) // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast) - float strafity = IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), -90) + IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), +90); // if one is nonzero, other is always zero + float strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero if (PHYS_MAXAIRSTRAFESPEED) - wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED*maxspd_mod)); - if (PHYS_AIRSTRAFEACCELERATE) - airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE*maxspd_mod); + wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED(self)*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED*maxspd_mod)); + if (PHYS_AIRSTRAFEACCELERATE(self)) + airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE(self)*maxspd_mod); if (PHYS_AIRSTRAFEACCEL_QW(self)) airaccelqw = (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(self) : PHYS_AIRACCEL_QW(self)) >= 0) ? +1 : -1) @@ -1443,7 +1616,7 @@ void PM_air(float buttons_prev, float maxspd_mod) (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(self)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(self)))); // !CPM - if (PHYS_WARSOWBUNNY_TURNACCEL && accelerating && PHYS_INPUT_MOVEVALUES(self).y == 0 && PHYS_INPUT_MOVEVALUES(self).x != 0) + if (PHYS_WARSOWBUNNY_TURNACCEL && accelerating && self.movement.y == 0 && self.movement.x != 0) PM_AirAccelerate(wishdir, wishspeed2); else PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(self), PHYS_AIRACCEL_SIDEWAYS_FRICTION / maxairspd, PHYS_AIRSPEEDLIMIT_NONQW(self)); @@ -1463,26 +1636,39 @@ void PM_air(float buttons_prev, float maxspd_mod) } // used for calculating airshots -float PM_is_flying() +bool IsFlying(entity a) { - if (IS_ONGROUND(self)) - return 0; - if (self.waterlevel >= WATERLEVEL_SWIMMING) - return 0; - traceline(self.origin, self.origin - '0 0 48', MOVE_NORMAL, self); - return trace_fraction >= 1; + if(IS_ONGROUND(a)) + return false; + if(a.waterlevel >= WATERLEVEL_SWIMMING) + return false; + traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a); + if(trace_fraction < 1) + return false; + return true; } void PM_Main() { - float buttons = PHYS_INPUT_BUTTON_MASK(self); + int buttons = PHYS_INPUT_BUTTON_MASK(self); #ifdef CSQC - //Con_Printf(" %f", PHYS_INPUT_TIMELENGTH); + self.items = getstati(STAT_ITEMS, 0, 24); + + self.movement = PHYS_INPUT_MOVEVALUES(self); + + vector oldv_angle = self.v_angle; + vector oldangles = self.angles; // we need to save these, as they're abused by other code + self.v_angle = PHYS_INPUT_ANGLES(self); + self.angles = PHYS_WORLD_ANGLES(self); + + self.team = myteam + 1; // is this correct? if (!(PHYS_INPUT_BUTTON_JUMP(self))) // !jump UNSET_JUMP_HELD(self); // canjump = true pmove_waterjumptime -= PHYS_INPUT_TIMELENGTH; - PM_ClientMovement_UpdateStatus(); + + PM_ClientMovement_UpdateStatus(true); #endif + #ifdef SVQC WarpZone_PlayerPhysics_FixVAngle(); @@ -1509,14 +1695,14 @@ void PM_Main() #ifdef SVQC if (sv_maxidle > 0) { - if (buttons != self.buttons_old || PHYS_INPUT_MOVEVALUES(self) != self.movement_old || PHYS_INPUT_ANGLES(self) != self.v_angle_old) + if (buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old) self.parm_idlesince = time; } #endif - float buttons_prev = self.buttons_old; + int buttons_prev = self.buttons_old; self.buttons_old = buttons; - self.movement_old = PHYS_INPUT_MOVEVALUES(self); - self.v_angle_old = PHYS_INPUT_ANGLES(self); + self.movement_old = self.movement; + self.v_angle_old = self.v_angle; PM_check_nickspam(); @@ -1529,8 +1715,6 @@ void PM_Main() bot_think(); } - self.items &= ~IT_USING_JETPACK; - if (IS_PLAYER(self)) #endif { @@ -1540,15 +1724,14 @@ void PM_Main() self.race_penalty = 0; #endif - float not_allowed_to_move = 0; + bool not_allowed_to_move = false; #ifdef SVQC if (self.race_penalty) - not_allowed_to_move = 1; + not_allowed_to_move = true; #endif #ifdef SVQC - if (!autocvar_sv_ready_restart_after_countdown) - if (time < game_starttime) - not_allowed_to_move = 1; + if (time < game_starttime) + not_allowed_to_move = true; #endif if (not_allowed_to_move) @@ -1572,15 +1755,13 @@ void PM_Main() #ifdef SVQC if (self.movetype == MOVETYPE_NONE) return; -#endif -#ifdef SVQC // when we get here, disableclientprediction cannot be 2 self.disableclientprediction = 0; - if (time < self.ladder_time) - self.disableclientprediction = 1; #endif + viewloc_PlayerPhysics(); + PM_check_spider(); PM_check_frozen(); @@ -1589,21 +1770,20 @@ void PM_Main() maxspeed_mod = 1; -#ifdef SVQC - if (self.in_swamp) { + if (self.in_swamp) maxspeed_mod *= self.swamp_slowdown; //cvar("g_balance_swamp_moverate"); - } -#endif -#ifdef SVQC // conveyors: first fix velocity if (self.conveyor.state) self.velocity -= self.conveyor.movedir; -#endif #ifdef SVQC MUTATOR_CALLHOOK(PlayerPhysics); #endif +#ifdef CSQC + PM_multijump(); +#endif + // float forcedodge = 1; // if(forcedodge) { //#ifdef CSQC @@ -1617,7 +1797,7 @@ void PM_Main() #ifdef SVQC if (!IS_PLAYER(self)) { - maxspeed_mod *= autocvar_sv_spectator_speed_multiplier; + maxspeed_mod = autocvar_sv_spectator_speed_multiplier; if (!self.spectatorspeed) self.spectatorspeed = maxspeed_mod; if (self.impulse && self.impulse <= 19 || (self.impulse >= 200 && self.impulse <= 209) || (self.impulse >= 220 && self.impulse <= 229)) @@ -1635,62 +1815,67 @@ void PM_Main() } // otherwise just clear self.impulse = 0; } - maxspeed_mod *= self.spectatorspeed; + maxspeed_mod = self.spectatorspeed; } -#endif -#ifdef SVQC - // if dead, behave differently - // in CSQC, physics don't handle dead player - if (self.deadflag) - goto end; -#endif + float spd = max(PHYS_MAXSPEED(self), PHYS_MAXAIRSPEED(self)) * maxspeed_mod; + if(self.speed != spd) + { + self.speed = spd; + string temps = ftos(spd); + stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n")); + stuffcmd(self, strcat("cl_backspeed ", temps, "\n")); + stuffcmd(self, strcat("cl_sidespeed ", temps, "\n")); + stuffcmd(self, strcat("cl_upspeed ", temps, "\n")); + } -#ifdef SVQC - if (!self.fixangle && !g_bugrigs) - self.angles = '0 1 0' * PHYS_INPUT_ANGLES(self).y; + if(self.stat_jumpspeedcap_min != PHYS_JUMPSPEEDCAP_MIN) + { + self.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MIN; + stuffcmd(self, strcat("cl_jumpspeedcap_min ", PHYS_JUMPSPEEDCAP_MIN, "\n")); + } + if(self.stat_jumpspeedcap_max != PHYS_JUMPSPEEDCAP_MAX) + { + self.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MAX; + stuffcmd(self, strcat("cl_jumpspeedcap_max ", PHYS_JUMPSPEEDCAP_MAX, "\n")); + } #endif -#ifdef SVQC - if (IS_ONGROUND(self)) - if (IS_PLAYER(self)) // no fall sounds for observers thank you very much - if (self.wasFlying) + if(PHYS_DEAD(self)) { - self.wasFlying = 0; - if (self.waterlevel < WATERLEVEL_SWIMMING) - if (time >= self.ladder_time) - if (!self.hook) + // handle water here + vector midpoint = ((self.absmin + self.absmax) * 0.5); + if(pointcontents(midpoint) == CONTENT_WATER) { - self.nextstep = time + 0.3 + random() * 0.1; - trace_dphitq3surfaceflags = 0; - tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self); - if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)) - { - if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS) - GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND); - else - GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND); - } + self.velocity = self.velocity * 0.5; + + // do we want this? + //if(pointcontents(midpoint + '0 0 2') == CONTENT_WATER) + //{ self.velocity_z = 70; } } + goto end; } + +#ifdef SVQC + if (!self.fixangle && !g_bugrigs) + self.angles = '0 1 0' * self.v_angle.y; #endif - if (PM_is_flying()) + PM_check_hitground(); + + if(IsFlying(self)) self.wasFlying = 1; -#ifdef SVQC if (IS_PLAYER(self)) -#endif CheckPlayerJump(); - - if (self.flags & /* FL_WATERJUMP */ 2048) + if (self.flags & FL_WATERJUMP) { self.velocity_x = self.movedir_x; self.velocity_y = self.movedir_y; if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE) { - self.flags &= ~/* FL_WATERJUMP */ 2048; + self.flags &= ~FL_WATERJUMP; self.teleport_time = 0; } } @@ -1700,42 +1885,23 @@ void PM_Main() RaceCarPhysics(); #endif - else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY) + else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY || (BUFFS_STAT(self) & BUFF_FLIGHT.m_itemid)) PM_fly(maxspeed_mod); else if (self.waterlevel >= WATERLEVEL_SWIMMING) PM_swim(maxspeed_mod); -#ifdef SVQC else if (time < self.ladder_time) PM_ladder(maxspeed_mod); -#endif - else if ((ITEMS(self) & IT_JETPACK) && PHYS_INPUT_BUTTON_HOOK(self) && (!PHYS_JETPACK_FUEL || PHYS_AMMO_FUEL(self) > 0 || (ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO)) && !PHYS_FROZEN(self)) + else if (ITEMS_STAT(self) & IT_USING_JETPACK) PM_jetpack(maxspeed_mod); + else if (IS_ONGROUND(self)) + PM_walk(buttons_prev, maxspeed_mod); + else - { -#ifdef CSQC - // jump if on ground with jump button pressed but only if it has been - // released at least once since the last jump - if (PHYS_INPUT_BUTTON_JUMP(self)) - { - if (IS_ONGROUND(self) && (!IS_JUMP_HELD(self) || !cvar("cl_movement_track_canjump"))) - { - self.velocity_z += PHYS_JUMPVELOCITY; - UNSET_ONGROUND(self); - SET_JUMP_HELD(self); // canjump = false - } - } - else - UNSET_JUMP_HELD(self); // canjump = true -#endif - if (IS_ONGROUND(self)) - PM_walk(buttons_prev, maxspeed_mod); - else - PM_air(buttons_prev, maxspeed_mod); - } + PM_air(buttons_prev, maxspeed_mod); #ifdef SVQC if (!IS_OBSERVER(self)) @@ -1747,38 +1913,32 @@ void PM_Main() if (IS_ONGROUND(self)) self.lastground = time; -#ifdef SVQC // conveyors: then break velocity again - if (self.conveyor.state) + if(self.conveyor.state) self.velocity += self.conveyor.movedir; -#endif + self.lastflags = self.flags; + self.lastclassname = self.classname; -} -void CSQC_ClientMovement_PlayerMove_Frame() -{ - // if a move is more than 50ms, do it as two moves (matching qwsv) - //Con_Printf("%i ", self.cmd.msec); - if (PHYS_INPUT_TIMELENGTH > 0.0005) - { - if (PHYS_INPUT_TIMELENGTH > 0.05) - { - PHYS_INPUT_TIMELENGTH /= 2; - PM_Main(); - } - PM_Main(); - } - else - // we REALLY need this handling to happen, even if the move is not executed - if (!(PHYS_INPUT_BUTTON_JUMP(self))) // !jump - UNSET_JUMP_HELD(self); // canjump = true +#ifdef CSQC + self.v_angle = oldv_angle; + self.angles = oldangles; +#endif } #ifdef SVQC -// Entry point void SV_PlayerPhysics(void) +#elif defined(CSQC) +void CSQC_ClientMovement_PlayerMove_Frame(void) +#endif { PM_Main(); + +#ifdef CSQC + self.pmove_flags = + ((self.flags & FL_DUCKED) ? PMF_DUCKED : 0) | + (!(self.flags & FL_JUMPRELEASED) ? 0 : PMF_JUMP_HELD) | + ((self.flags & FL_ONGROUND) ? PMF_ONGROUND : 0); +#endif } -#endif \ No newline at end of file