X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fphysics.qc;h=32c2fbfa84ad95d51e4c29637612a0536b755e45;hb=00150d254602fa31f9dad646575697b2fc6b8ba3;hp=54a7002056f9b681e4a741034ec24656911a6742;hpb=437d67dbc7631d6c49e922990d96461d3ff4b7b2;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/physics.qc b/qcsrc/common/physics.qc index 54a700205..32c2fbfa8 100644 --- a/qcsrc/common/physics.qc +++ b/qcsrc/common/physics.qc @@ -13,11 +13,11 @@ bool Physics_Valid(string thecvar) return autocvar_g_physics_clientselect && strhasword(autocvar_g_physics_clientselect_options, thecvar); } -float Physics_ClientOption(entity pl, string option) +float Physics_ClientOption(entity this, string option) { - if(Physics_Valid(pl.cvar_cl_physics)) + if(Physics_Valid(this.cvar_cl_physics)) { - string s = sprintf("g_physics_%s_%s", pl.cvar_cl_physics, option); + string s = sprintf("g_physics_%s_%s", this.cvar_cl_physics, option); if(cvar_type(s) & CVAR_TYPEFLAG_EXISTS) return cvar(s); } @@ -30,147 +30,37 @@ float Physics_ClientOption(entity pl, string option) return cvar(strcat("sv_", option)); } -void Physics_AddStats() +void Physics_UpdateStats(entity this, float maxspd_mod) { - // 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); - addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw); - addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw); - addstat(STAT_MOVEVARS_HIGHSPEED, AS_FLOAT, stat_movement_highspeed); - - // jet pack - addstat(STAT_JETPACK_ACCEL_SIDE, AS_FLOAT, stat_jetpack_accel_side); - addstat(STAT_JETPACK_ACCEL_UP, AS_FLOAT, stat_jetpack_accel_up); - addstat(STAT_JETPACK_ANTIGRAVITY, AS_FLOAT, stat_jetpack_antigravity); - 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_CL_TRACK_CANJUMP, AS_INT, cvar_cl_movement_track_canjump); - addstat(STAT_MOVEVARS_TRACK_CANJUMP, AS_INT, stat_sv_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) -{SELFPARAM(); - // 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 = 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; - + STAT(MOVEVARS_AIRACCEL_QW, this) = AdjustAirAccelQW(Physics_ClientOption(this, "airaccel_qw"), maxspd_mod); + STAT(MOVEVARS_AIRSTRAFEACCEL_QW, this) = (Physics_ClientOption(this, "airstrafeaccel_qw")) + ? AdjustAirAccelQW(Physics_ClientOption(this, "airstrafeaccel_qw"), maxspd_mod) + : 0; + STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW, this) = Physics_ClientOption(this, "airspeedlimit_nonqw") * maxspd_mod; + STAT(MOVEVARS_MAXSPEED, this) = Physics_ClientOption(this, "maxspeed") * maxspd_mod; // also slow walking // 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_sv_track_canjump = Physics_ClientOption(self, "track_canjump"); - - self.stat_gameplayfix_upvelocityclearsonground = UPWARD_VELOCITY_CLEARS_ONGROUND; + STAT(MOVEVARS_AIRACCEL_QW_STRETCHFACTOR, this) = Physics_ClientOption(this, "airaccel_qw_stretchfactor"); + STAT(MOVEVARS_MAXAIRSTRAFESPEED, this) = Physics_ClientOption(this, "maxairstrafespeed"); + STAT(MOVEVARS_MAXAIRSPEED, this) = Physics_ClientOption(this, "maxairspeed"); + STAT(MOVEVARS_AIRSTRAFEACCELERATE, this) = Physics_ClientOption(this, "airstrafeaccelerate"); + STAT(MOVEVARS_WARSOWBUNNY_TURNACCEL, this) = Physics_ClientOption(this, "warsowbunny_turnaccel"); + STAT(MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION, this) = Physics_ClientOption(this, "airaccel_sideways_friction"); + STAT(MOVEVARS_AIRCONTROL, this) = Physics_ClientOption(this, "aircontrol"); + STAT(MOVEVARS_AIRCONTROL_POWER, this) = Physics_ClientOption(this, "aircontrol_power"); + STAT(MOVEVARS_AIRCONTROL_PENALTY, this) = Physics_ClientOption(this, "aircontrol_penalty"); + STAT(MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL, this) = Physics_ClientOption(this, "warsowbunny_airforwardaccel"); + STAT(MOVEVARS_WARSOWBUNNY_TOPSPEED, this) = Physics_ClientOption(this, "warsowbunny_topspeed"); + STAT(MOVEVARS_WARSOWBUNNY_ACCEL, this) = Physics_ClientOption(this, "warsowbunny_accel"); + STAT(MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO, this) = Physics_ClientOption(this, "warsowbunny_backtosideratio"); + STAT(MOVEVARS_FRICTION, this) = Physics_ClientOption(this, "friction"); + STAT(MOVEVARS_ACCELERATE, this) = Physics_ClientOption(this, "accelerate"); + STAT(MOVEVARS_STOPSPEED, this) = Physics_ClientOption(this, "stopspeed"); + STAT(MOVEVARS_AIRACCELERATE, this) = Physics_ClientOption(this, "airaccelerate"); + STAT(MOVEVARS_AIRSTOPACCELERATE, this) = Physics_ClientOption(this, "airstopaccelerate"); + STAT(MOVEVARS_JUMPVELOCITY, this) = Physics_ClientOption(this, "jumpvelocity"); + STAT(MOVEVARS_TRACK_CANJUMP, this) = Physics_ClientOption(this, "track_canjump"); } #endif @@ -190,121 +80,127 @@ float GeomLerp(float a, float lerp, float b) : a * pow(fabs(b / a), lerp); } -noref float pmove_waterjumptime; - -const float unstick_count = 27; -vector unstick_offsets[unstick_count] = +#define unstick_offsets(X) \ +/* 1 no nudge (just return the original if this test passes) */ \ + X(' 0.000 0.000 0.000') \ +/* 6 simple nudges */ \ + X(' 0.000 0.000 0.125') X('0.000 0.000 -0.125') \ + X('-0.125 0.000 0.000') X('0.125 0.000 0.000') \ + X(' 0.000 -0.125 0.000') X('0.000 0.125 0.000') \ +/* 4 diagonal flat nudges */ \ + X('-0.125 -0.125 0.000') X('0.125 -0.125 0.000') \ + X('-0.125 0.125 0.000') X('0.125 0.125 0.000') \ +/* 8 diagonal upward nudges */ \ + X('-0.125 0.000 0.125') X('0.125 0.000 0.125') \ + X(' 0.000 -0.125 0.125') X('0.000 0.125 0.125') \ + X('-0.125 -0.125 0.125') X('0.125 -0.125 0.125') \ + X('-0.125 0.125 0.125') X('0.125 0.125 0.125') \ +/* 8 diagonal downward nudges */ \ + X('-0.125 0.000 -0.125') X('0.125 0.000 -0.125') \ + X(' 0.000 -0.125 -0.125') X('0.000 0.125 -0.125') \ + X('-0.125 -0.125 -0.125') X('0.125 -0.125 -0.125') \ + X('-0.125 0.125 -0.125') X('0.125 0.125 -0.125') \ +/**/ + +void PM_ClientMovement_Unstick(entity this) { -// 1 no nudge (just return the original if this test passes) - '0.000 0.000 0.000', -// 6 simple nudges - ' 0.000 0.000 0.125', '0.000 0.000 -0.125', - '-0.125 0.000 0.000', '0.125 0.000 0.000', - ' 0.000 -0.125 0.000', '0.000 0.125 0.000', -// 4 diagonal flat nudges - '-0.125 -0.125 0.000', '0.125 -0.125 0.000', - '-0.125 0.125 0.000', '0.125 0.125 0.000', -// 8 diagonal upward nudges - '-0.125 0.000 0.125', '0.125 0.000 0.125', - ' 0.000 -0.125 0.125', '0.000 0.125 0.125', - '-0.125 -0.125 0.125', '0.125 -0.125 0.125', - '-0.125 0.125 0.125', '0.125 0.125 0.125', -// 8 diagonal downward nudges - '-0.125 0.000 -0.125', '0.125 0.000 -0.125', - ' 0.000 -0.125 -0.125', '0.000 0.125 -0.125', - '-0.125 -0.125 -0.125', '0.125 -0.125 -0.125', - '-0.125 0.125 -0.125', '0.125 0.125 -0.125', -}; - -void PM_ClientMovement_Unstick() -{SELFPARAM(); - float i; - for (i = 0; i < unstick_count; i++) - { - vector neworigin = unstick_offsets[i] + self.origin; - tracebox(neworigin, PL_CROUCH_MIN, PL_CROUCH_MAX, neworigin, MOVE_NORMAL, self); - if (!trace_startsolid) - { - setorigin(self, neworigin); - return;// true; - } + #define X(unstick_offset) \ + { \ + vector neworigin = unstick_offset + this.origin; \ + tracebox(neworigin, PL_CROUCH_MIN, PL_CROUCH_MAX, neworigin, MOVE_NORMAL, this); \ + if (!trace_startsolid) \ + { \ + setorigin(this, neworigin); \ + return; \ + } \ } + unstick_offsets(X); + #undef X } -void PM_ClientMovement_UpdateStatus(bool ground) -{SELFPARAM(); +void PM_ClientMovement_UpdateStatus(entity this, bool ground) +{ +#ifdef CSQC + if(!IS_PLAYER(this)) + return; // make sure player is not stuck - PM_ClientMovement_Unstick(); + if(autocvar_cl_movement == 3) + PM_ClientMovement_Unstick(this); // set crouched - if (PHYS_INPUT_BUTTON_CROUCH(self)) + if (PHYS_INPUT_BUTTON_CROUCH(this)) { - // wants to crouch, this always works.. - if (!IS_DUCKED(self)) - SET_DUCKED(self); + // wants to crouch, this always works + if (!IS_DUCKED(this)) SET_DUCKED(this); } else { - // wants to stand, if currently crouching we need to check for a - // low ceiling first - if (IS_DUCKED(self)) + // wants to stand, if currently crouching we need to check for a low ceiling first + if (IS_DUCKED(this)) { - tracebox(self.origin, PL_MIN, PL_MAX, self.origin, MOVE_NORMAL, self); - if (!trace_startsolid) - UNSET_DUCKED(self); + tracebox(this.origin, PL_MIN, PL_MAX, this.origin, MOVE_NORMAL, this); + if (!trace_startsolid) UNSET_DUCKED(this); } } // set onground - vector origin1 = self.origin + '0 0 1'; - vector origin2 = self.origin - '0 0 1'; + vector origin1 = this.origin + '0 0 1'; + vector origin2 = this.origin - '0 0 1'; - if(ground) + if (ground && autocvar_cl_movement == 3) { - tracebox(origin1, self.mins, self.maxs, origin2, MOVE_NORMAL, self); - if (trace_fraction < 1.0 && trace_plane_normal_z > 0.7) + tracebox(origin1, this.mins, this.maxs, origin2, MOVE_NORMAL, this); + if (trace_fraction < 1.0 && trace_plane_normal.z > 0.7) { - SET_ONGROUND(self); + SET_ONGROUND(this); // 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; + this.velocity -= this.velocity * trace_plane_normal * trace_plane_normal; } else - UNSET_ONGROUND(self); + UNSET_ONGROUND(this); } - // set watertype/waterlevel - origin1 = self.origin; - origin1_z += self.mins_z + 1; - self.waterlevel = WATERLEVEL_NONE; + if(autocvar_cl_movement == 3) + { + // set watertype/waterlevel + origin1 = this.origin; + origin1.z += this.mins_z + 1; + this.waterlevel = WATERLEVEL_NONE; - int thepoint = pointcontents(origin1); + int thepoint = pointcontents(origin1); - self.watertype = (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME); + this.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; - thepoint = pointcontents(origin1); - if(thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME) + if (this.watertype) { - self.waterlevel = WATERLEVEL_SWIMMING; - origin1_z = self.origin_z + 22; + this.waterlevel = WATERLEVEL_WETFEET; + origin1.z = this.origin.z + (this.mins.z + this.maxs.z) * 0.5; thepoint = pointcontents(origin1); - if(thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME) - self.waterlevel = WATERLEVEL_SUBMERGED; + if (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME) + { + this.waterlevel = WATERLEVEL_SWIMMING; + origin1.z = this.origin.z + 22; + thepoint = pointcontents(origin1); + if (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME) + this.waterlevel = WATERLEVEL_SUBMERGED; + } } } - if(IS_ONGROUND(self) || self.velocity_z <= 0 || pmove_waterjumptime <= 0) + if (IS_ONGROUND(this) || this.velocity.z <= 0 || pmove_waterjumptime <= 0) pmove_waterjumptime = 0; +#endif } -void PM_ClientMovement_Move() -{SELFPARAM(); +void PM_ClientMovement_Move(entity this) +{ #ifdef CSQC + + PM_ClientMovement_UpdateStatus(this, false); + if(autocvar_cl_movement == 1) + return; + int bump; float t; float f; @@ -323,13 +219,11 @@ void PM_ClientMovement_Move() 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++) + primalvelocity = this.velocity; + for(bump = 0, t = PHYS_INPUT_TIMELENGTH; bump < 8 && (this.velocity * this.velocity) > 0; bump++) { - neworigin = self.origin + t * self.velocity; - tracebox(self.origin, self.mins, self.maxs, neworigin, MOVE_NORMAL, self); + neworigin = this.origin + t * this.velocity; + tracebox(this.origin, this.mins, this.maxs, neworigin, MOVE_NORMAL, this); trace1_endpos = trace_endpos; trace1_fraction = trace_fraction; trace1_plane_normal = trace_plane_normal; @@ -337,11 +231,11 @@ void PM_ClientMovement_Move() { // may be a step or wall, try stepping up // first move forward at a higher level - currentorigin2 = self.origin; - currentorigin2_z += PHYS_STEPHEIGHT; + currentorigin2 = this.origin; + currentorigin2_z += PHYS_STEPHEIGHT(this); neworigin2 = neworigin; - neworigin2_z += PHYS_STEPHEIGHT; - tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self); + neworigin2_z += PHYS_STEPHEIGHT(this); + tracebox(currentorigin2, this.mins, this.maxs, neworigin2, MOVE_NORMAL, this); trace2_endpos = trace_endpos; trace2_fraction = trace_fraction; trace2_plane_normal = trace_plane_normal; @@ -350,8 +244,8 @@ void PM_ClientMovement_Move() // then move down from there currentorigin2 = trace2_endpos; neworigin2 = trace2_endpos; - neworigin2_z = self.origin_z; - tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self); + neworigin2_z = this.origin_z; + tracebox(currentorigin2, this.mins, this.maxs, neworigin2, MOVE_NORMAL, this); trace3_endpos = trace_endpos; trace3_fraction = trace_fraction; trace3_plane_normal = trace_plane_normal; @@ -368,7 +262,7 @@ void PM_ClientMovement_Move() // check if it moved at all if(trace1_fraction >= 0.001) - setorigin(self, trace1_endpos); + setorigin(this, trace1_endpos); // check if it moved all the way if(trace1_fraction == 1) @@ -379,43 +273,43 @@ void PM_ClientMovement_Move() // 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(trace1_plane_normal_z > 0.7) - SET_ONGROUND(self); + SET_ONGROUND(this); t -= t * trace1_fraction; - f = (self.velocity * trace1_plane_normal); - self.velocity = self.velocity + -f * trace1_plane_normal; + f = (this.velocity * trace1_plane_normal); + this.velocity = this.velocity + -f * trace1_plane_normal; } - if(pmove_waterjumptime > 0) - self.velocity = primalvelocity; + if(PHYS_TELEPORT_TIME(this) > 0) + this.velocity = primalvelocity; #endif } -void CPM_PM_Aircontrol(vector wishdir, float wishspeed) -{SELFPARAM(); - float k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1); +void CPM_PM_Aircontrol(entity this, vector wishdir, float wishspeed) +{ + float k = 32 * (2 * IsMoveInDirection(this.movement, 0) - 1); if (k <= 0) return; - k *= bound(0, wishspeed / PHYS_MAXAIRSPEED(self), 1); + k *= bound(0, wishspeed / PHYS_MAXAIRSPEED(this), 1); - float zspeed = self.velocity_z; - self.velocity_z = 0; - float xyspeed = vlen(self.velocity); - self.velocity = normalize(self.velocity); + float zspeed = this.velocity_z; + this.velocity_z = 0; + float xyspeed = vlen(this.velocity); + this.velocity = normalize(this.velocity); - float dot = self.velocity * wishdir; + float dot = this.velocity * wishdir; if (dot > 0) // we can't change direction while slowing down { - 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); + k *= pow(dot, PHYS_AIRCONTROL_POWER(this)) * PHYS_INPUT_TIMELENGTH; + xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY(this) * sqrt(max(0, 1 - dot*dot)) * k/32); + k *= PHYS_AIRCONTROL(this); + this.velocity = normalize(this.velocity * xyspeed + wishdir * k); } - self.velocity = self.velocity * xyspeed; - self.velocity_z = zspeed; + this.velocity = this.velocity * xyspeed; + this.velocity_z = zspeed; } float AdjustAirAccelQW(float accelqw, float factor) @@ -428,8 +322,8 @@ float AdjustAirAccelQW(float accelqw, float factor) // 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 stretchfactor, float sidefric, float speedlimit) -{SELFPARAM(); +void PM_Accelerate(entity this, vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit) +{ float speedclamp = stretchfactor > 0 ? stretchfactor : accelqw < 0 ? 1 // full clamping, no stretch : -1; // no clamping @@ -439,9 +333,9 @@ void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float acce if (GAMEPLAYFIX_Q2AIRACCELERATE) wishspeed0 = wishspeed; // don't need to emulate this Q1 bug - float vel_straight = self.velocity * wishdir; - float vel_z = self.velocity_z; - vector vel_xy = vec2(self.velocity); + float vel_straight = this.velocity * wishdir; + float vel_z = this.velocity_z; + vector vel_xy = vec2(this.velocity); vector vel_perpend = vel_xy - vel_straight * wishdir; float step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0; @@ -458,18 +352,18 @@ void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float acce // negative: only apply so much sideways friction to stay below the speed you could get by "braking" { float f = max(0, 1 + PHYS_INPUT_TIMELENGTH * wishspeed * sidefric); - float fmin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend); - // assume: fmin > 1 + float themin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend); + // assume: themin > 1 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy // obviously, this cannot be - if (fmin <= 0) + if (themin <= 0) vel_perpend *= f; else { - fmin = sqrt(fmin); - vel_perpend *= max(fmin, f); + themin = sqrt(themin); + vel_perpend *= max(themin, f); } } else @@ -489,41 +383,41 @@ void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float acce } } - self.velocity = vel_xy + vel_z * '0 0 1'; + this.velocity = vel_xy + vel_z * '0 0 1'; } -void PM_AirAccelerate(vector wishdir, float wishspeed) -{SELFPARAM(); +void PM_AirAccelerate(entity this, vector wishdir, float wishspeed) +{ if (wishspeed == 0) return; - vector curvel = self.velocity; + vector curvel = this.velocity; curvel_z = 0; float curspeed = vlen(curvel); if (wishspeed > curspeed * 1.01) - wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH); + wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL(this) * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH); else { - float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED - PHYS_MAXSPEED(self))); - wishspeed = max(curspeed, PHYS_MAXSPEED(self)) + PHYS_WARSOWBUNNY_ACCEL * f * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH; + float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED(this) - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED(this) - PHYS_MAXSPEED(this))); + wishspeed = max(curspeed, PHYS_MAXSPEED(this)) + PHYS_WARSOWBUNNY_ACCEL(this) * f * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH; } vector wishvel = wishdir * wishspeed; vector acceldir = wishvel - curvel; float addspeed = vlen(acceldir); acceldir = normalize(acceldir); - float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH); + float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL(this) * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH); - if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO < 1) + if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this) < 1) { vector curdir = normalize(curvel); float dot = acceldir * curdir; if (dot < 0) - acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO) * dot * curdir; + acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this)) * dot * curdir; } - self.velocity += accelspeed * acceldir; + this.velocity += accelspeed * acceldir; } @@ -535,63 +429,49 @@ When you press the jump key returns true if handled ============= */ -bool PlayerJump (void) -{SELFPARAM(); - if (PHYS_FROZEN(self)) +bool PlayerJump(entity this) +{ + if (PHYS_FROZEN(this)) return true; // no jumping in freezetag when frozen #ifdef SVQC - if (self.player_blocked) + if (this.player_blocked) return true; // no jumping while blocked #endif bool doublejump = false; - float mjumpheight = PHYS_JUMPVELOCITY; -#ifdef CSQC - player_multijump = doublejump; - player_jumpheight = mjumpheight; -#endif + float mjumpheight = PHYS_JUMPVELOCITY(this); - if (MUTATOR_CALLHOOK(PlayerJump, doublejump, mjumpheight) -#ifdef CSQC - || PM_multijump_checkjump() -#endif - ) { return true; } + if (MUTATOR_CALLHOOK(PlayerJump, this, doublejump, mjumpheight)) + return true; doublejump = player_multijump; mjumpheight = player_jumpheight; - if (PHYS_DOUBLEJUMP) + if (this.waterlevel >= WATERLEVEL_SWIMMING) { - 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) + if(this.viewloc) { doublejump = true; - - // we MUST clip velocity here! - float f; - f = self.velocity * trace_plane_normal; - if (f < 0) - self.velocity -= f * trace_plane_normal; + mjumpheight *= 0.7; + } + else + { + this.velocity_z = PHYS_MAXSPEED(this) * 0.7; + return true; } - } - - if (self.waterlevel >= WATERLEVEL_SWIMMING) - { - self.velocity_z = PHYS_MAXSPEED(self) * 0.7; - return true; } if (!doublejump) - if (!IS_ONGROUND(self)) - return IS_JUMP_HELD(self); + if (!IS_ONGROUND(this)) + return IS_JUMP_HELD(this); - bool track_jump = PHYS_CL_TRACK_CANJUMP(self); - if(PHYS_TRACK_CANJUMP(self)) + bool track_jump = PHYS_CL_TRACK_CANJUMP(this); + if(PHYS_TRACK_CANJUMP(this)) track_jump = true; if (track_jump) - if (IS_JUMP_HELD(self)) + if (IS_JUMP_HELD(this)) return true; // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline @@ -602,85 +482,86 @@ bool PlayerJump (void) { float minjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MIN); - if (self.velocity_z < minjumpspeed) - mjumpheight += minjumpspeed - self.velocity_z; + if (this.velocity_z < minjumpspeed) + mjumpheight += minjumpspeed - this.velocity_z; } 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); + tracebox(this.origin + '0 0 0.01', this.mins, this.maxs, this.origin - '0 0 0.01', MOVE_NORMAL, this); - if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS)) + if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS(this))) { float maxjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MAX); - if (self.velocity_z > maxjumpspeed) - mjumpheight -= self.velocity_z - maxjumpspeed; + if (this.velocity_z > maxjumpspeed) + mjumpheight -= this.velocity_z - maxjumpspeed; } } - if (!WAS_ONGROUND(self)) + if (!WAS_ONGROUND(this)) { #ifdef SVQC if(autocvar_speedmeter) - LOG_TRACE(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n")); + LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n")); #endif - if(self.lastground < time - 0.3) + if(this.lastground < time - 0.3) { - self.velocity_x *= (1 - PHYS_FRICTION_ONLAND); - self.velocity_y *= (1 - PHYS_FRICTION_ONLAND); + float f = (1 - PHYS_FRICTION_ONLAND(this)); + this.velocity_x *= f; + this.velocity_y *= f; } #ifdef SVQC - if(self.jumppadcount > 1) - LOG_TRACE(strcat(ftos(self.jumppadcount), "x jumppad combo\n")); - self.jumppadcount = 0; + if(this.jumppadcount > 1) + LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n")); + this.jumppadcount = 0; #endif } - self.velocity_z += mjumpheight; + this.velocity_z += mjumpheight; - UNSET_ONGROUND(self); - SET_JUMP_HELD(self); + UNSET_ONGROUND(this); + SET_JUMP_HELD(this); #ifdef SVQC - self.oldvelocity_z = self.velocity_z; + this.oldvelocity_z = this.velocity_z; - animdecide_setaction(self, ANIMACTION_JUMP, true); + animdecide_setaction(this, ANIMACTION_JUMP, true); if (autocvar_g_jump_grunt) - PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND); + PlayerSound(this, playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND); #endif return true; } -void CheckWaterJump() -{SELFPARAM(); +void CheckWaterJump(entity this) +{ // check for a jump-out-of-water - makevectors(self.v_angle); - vector start = self.origin; + makevectors(this.v_angle); + vector start = this.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, this); if (trace_fraction < 1) { // solid at waist - start_z = start_z + self.maxs_z - 8; + start_z = start_z + this.maxs_z - 8; end = start + v_forward*24; - self.movedir = trace_plane_normal * -50; - traceline(start, end, true, self); + this.movedir = trace_plane_normal * -50; + traceline(start, end, true, this); if (trace_fraction == 1) { // open at eye level - self.velocity_z = 225; - self.flags |= FL_WATERJUMP; - SET_JUMP_HELD(self); -#ifdef SVQC - self.teleport_time = time + 2; // safety net -#elif defined(CSQC) + this.velocity_z = 225; + this.flags |= FL_WATERJUMP; + SET_JUMP_HELD(this); + #ifdef SVQC + PHYS_TELEPORT_TIME(this) = time + 2; // safety net + #elif defined(CSQC) pmove_waterjumptime = time + 2; -#endif + #endif } } } @@ -693,48 +574,46 @@ void CheckWaterJump() #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() -{SELFPARAM(); +void CheckPlayerJump(entity this) +{ #ifdef SVQC - float was_flying = ITEMS_STAT(self) & IT_USING_JETPACK; + float was_flying = ITEMS_STAT(this) & IT_USING_JETPACK; #endif - if (JETPACK_JUMP(self) < 2) - ITEMS_STAT(self) &= ~IT_USING_JETPACK; + if (JETPACK_JUMP(this) < 2) + ITEMS_STAT(this) &= ~IT_USING_JETPACK; - if(PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_JETPACK(self)) + if(PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this)) { - 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; + float air_jump = !PlayerJump(this) || player_multijump; // PlayerJump() has important side effects + float activate = JETPACK_JUMP(this) && air_jump && PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this); + float has_fuel = !PHYS_JETPACK_FUEL(this) || PHYS_AMMO_FUEL(this) || ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO; - if (!(ITEMS_STAT(self) & ITEM_Jetpack.m_itemid)) { } - else if (self.jetpack_stopped) { } + if (!(ITEMS_STAT(this) & ITEM_Jetpack.m_itemid)) { } + else if (this.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); + Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL); else if (activate) - Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL); + Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL); #endif - self.jetpack_stopped = true; - ITEMS_STAT(self) &= ~IT_USING_JETPACK; + this.jetpack_stopped = true; + ITEMS_STAT(this) &= ~IT_USING_JETPACK; } - else if (activate && !PHYS_FROZEN(self)) - ITEMS_STAT(self) |= IT_USING_JETPACK; + else if (activate && !PHYS_FROZEN(this)) + ITEMS_STAT(this) |= IT_USING_JETPACK; } else { - self.jetpack_stopped = false; - ITEMS_STAT(self) &= ~IT_USING_JETPACK; + this.jetpack_stopped = false; + ITEMS_STAT(this) &= ~IT_USING_JETPACK; } - if (!PHYS_INPUT_BUTTON_JUMP(self)) - UNSET_JUMP_HELD(self); + if (!PHYS_INPUT_BUTTON_JUMP(this)) + UNSET_JUMP_HELD(this); - if (self.waterlevel == WATERLEVEL_SWIMMING) - CheckWaterJump(); + if (this.waterlevel == WATERLEVEL_SWIMMING) + CheckWaterJump(this); } float racecar_angle(float forward, float down) @@ -755,239 +634,18 @@ float racecar_angle(float forward, float down) return ret * angle_mult; } -void RaceCarPhysics() -{SELFPARAM(); -#ifdef SVQC - // using this move type for "big rigs" - // the engine does not push the entity! - - vector rigvel; - - vector angles_save = self.angles; - 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) - { - if (accel < 0) - { - // back accel is DIGITAL - // to prevent speedhack - if (accel < -0.5) - accel = -1; - else - accel = 0; - } - } - - self.angles_x = 0; - self.angles_z = 0; - makevectors(self.angles); // new forward direction! - - if (IS_ONGROUND(self) || g_bugrigs_air_steering) - { - float myspeed = self.velocity * v_forward; - float upspeed = self.velocity * v_up; - - // responsiveness factor for steering and acceleration - float f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow)); - //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow); - - float steerfactor; - if (myspeed < 0 && g_bugrigs_reverse_spinning) - steerfactor = -myspeed * g_bugrigs_steer; - else - steerfactor = -myspeed * f * g_bugrigs_steer; - - float accelfactor; - if (myspeed < 0 && g_bugrigs_reverse_speeding) - accelfactor = g_bugrigs_accel; - else - accelfactor = f * g_bugrigs_accel; - //MAXIMA: accel(v) := f(v) * g_bugrigs_accel; - - if (accel < 0) - { - if (myspeed > 0) - { - myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel)); - } - else - { - if (!g_bugrigs_reverse_speeding) - myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor); - } - } - else - { - if (myspeed >= 0) - { - myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor); - } - else - { - if (g_bugrigs_reverse_stopping) - myspeed = 0; - else - myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel)); - } - } - // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec - //MAXIMA: friction(v) := g_bugrigs_friction_floor; - - self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering - makevectors(self.angles); // new forward direction! - - myspeed += accel * accelfactor * PHYS_INPUT_TIMELENGTH; - - rigvel = myspeed * v_forward + '0 0 1' * upspeed; - } - else - { - float myspeed = vlen(self.velocity); - - // responsiveness factor for steering and acceleration - float f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow)); - float steerfactor = -myspeed * f; - self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering - - rigvel = self.velocity; - makevectors(self.angles); // new forward direction! - } - - rigvel *= max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * PHYS_INPUT_TIMELENGTH); - //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air; - //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v); - //MAXIMA: solve(total_acceleration(v) = 0, v); - - if (g_bugrigs_planar_movement) - { - vector rigvel_xy, neworigin, up; - float mt; - - rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better - rigvel_xy = vec2(rigvel); - - if (g_bugrigs_planar_movement_car_jumping) - mt = MOVE_NORMAL; - else - mt = MOVE_NOMONSTERS; - - tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self); - up = trace_endpos - self.origin; - - // BUG RIGS: align the move to the surface instead of doing collision testing - // can we move? - tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * PHYS_INPUT_TIMELENGTH, mt, self); - - // align to surface - tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * PHYS_INPUT_TIMELENGTH, mt, self); - - if (trace_fraction < 0.5) - { - trace_fraction = 1; - neworigin = self.origin; - } - else - neworigin = trace_endpos; - - if (trace_fraction < 1) - { - // now set angles_x so that the car points parallel to the surface - self.angles = vectoangles( - '1 0 0' * v_forward_x * trace_plane_normal_z - + - '0 1 0' * v_forward_y * trace_plane_normal_z - + - '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y) - ); - SET_ONGROUND(self); - } - else - { - // now set angles_x so that the car points forward, but is tilted in velocity direction - UNSET_ONGROUND(self); - } - - self.velocity = (neworigin - self.origin) * (1.0 / PHYS_INPUT_TIMELENGTH); - self.movetype = MOVETYPE_NOCLIP; - } - else - { - rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better - self.velocity = rigvel; - self.movetype = MOVETYPE_FLY; - } - - trace_fraction = 1; - tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self); - if (trace_fraction != 1) - { - self.angles = vectoangles2( - '1 0 0' * v_forward_x * trace_plane_normal_z - + - '0 1 0' * v_forward_y * trace_plane_normal_z - + - '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y), - trace_plane_normal - ); - } - else - { - vector vel_local; - - vel_local_x = v_forward * self.velocity; - vel_local_y = v_right * self.velocity; - vel_local_z = v_up * self.velocity; - - self.angles_x = racecar_angle(vel_local_x, vel_local_z); - self.angles_z = racecar_angle(-vel_local_y, vel_local_z); - } - - // smooth the angles - vector vf1, vu1, smoothangles; - makevectors(self.angles); - float f = bound(0, PHYS_INPUT_TIMELENGTH * g_bugrigs_angle_smoothing, 1); - if (f == 0) - f = 1; - vf1 = v_forward * f; - vu1 = v_up * f; - makevectors(angles_save); - vf1 = vf1 + v_forward * (1 - f); - vu1 = vu1 + v_up * (1 - f); - smoothangles = vectoangles2(vf1, vu1); - self.angles_x = -smoothangles_x; - self.angles_z = smoothangles_z; -#endif -} - string specialcommand = "xwxwxsxsxaxdxaxdx1x "; .float specialcommand_pos; void SpecialCommand() { #ifdef SVQC -#ifdef TETRIS - TetrisImpulse(); -#else - if (!CheatImpulse(99)) + if (!CheatImpulse(CHIMPULSE_GIVE_ALL.impulse)) LOG_INFO("A hollow voice says \"Plugh\".\n"); #endif -#endif -} - -void PM_check_race_movetime(void) -{SELFPARAM(); -#ifdef SVQC - self.race_movetime_frac += PHYS_INPUT_TIMELENGTH; - float f = floor(self.race_movetime_frac); - self.race_movetime_frac -= f; - self.race_movetime_count += f; - self.race_movetime = self.race_movetime_frac + self.race_movetime_count; -#endif } -float PM_check_specialcommand(float buttons) -{SELFPARAM(); +float PM_check_specialcommand(entity this, float buttons) +{ #ifdef SVQC string c; if (!buttons) @@ -1007,371 +665,340 @@ float PM_check_specialcommand(float buttons) else c = "?"; - if (c == substring(specialcommand, self.specialcommand_pos, 1)) + if (c == substring(specialcommand, this.specialcommand_pos, 1)) { - self.specialcommand_pos += 1; - if (self.specialcommand_pos >= strlen(specialcommand)) + this.specialcommand_pos += 1; + if (this.specialcommand_pos >= strlen(specialcommand)) { - self.specialcommand_pos = 0; + this.specialcommand_pos = 0; SpecialCommand(); return true; } } - else if (self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1))) - self.specialcommand_pos = 0; + else if (this.specialcommand_pos && (c != substring(specialcommand, this.specialcommand_pos - 1, 1))) + this.specialcommand_pos = 0; #endif return false; } -void PM_check_nickspam(void) -{SELFPARAM(); +void PM_check_nickspam(entity this) +{ #ifdef SVQC - if (time >= self.nickspamtime) + if (time >= this.nickspamtime) return; - if (self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow) + if (this.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; + this.movement = -1 * this.movement; + this.BUTTON_ATCK = this.BUTTON_JUMP = this.BUTTON_ATCK2 = this.BUTTON_ZOOM = this.BUTTON_CROUCH = this.BUTTON_HOOK = this.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! + if (this.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.v_angle_x = random() * 360; - self.v_angle_y = random() * 360; + this.v_angle_x = random() * 360; + this.v_angle_y = random() * 360; // at least I'm not forcing retardedview by also assigning to angles_z - self.fixangle = true; + this.fixangle = true; } } #endif } -void PM_check_punch() -{SELFPARAM(); +void PM_check_punch(entity this) +{ #ifdef SVQC - if (self.punchangle != '0 0 0') + if (this.punchangle != '0 0 0') { - float f = vlen(self.punchangle) - 10 * PHYS_INPUT_TIMELENGTH; + float f = vlen(this.punchangle) - 10 * PHYS_INPUT_TIMELENGTH; if (f > 0) - self.punchangle = normalize(self.punchangle) * f; + this.punchangle = normalize(this.punchangle) * f; else - self.punchangle = '0 0 0'; + this.punchangle = '0 0 0'; } - if (self.punchvector != '0 0 0') + if (this.punchvector != '0 0 0') { - float f = vlen(self.punchvector) - 30 * PHYS_INPUT_TIMELENGTH; + float f = vlen(this.punchvector) - 30 * PHYS_INPUT_TIMELENGTH; if (f > 0) - self.punchvector = normalize(self.punchvector) * f; + this.punchvector = normalize(this.punchvector) * f; else - self.punchvector = '0 0 0'; + this.punchvector = '0 0 0'; } #endif } -void PM_check_spider(void) -{SELFPARAM(); -#ifdef SVQC - if (time >= self.spider_slowness) - return; - 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 -} - // predict frozen movement, as frozen players CAN move in some cases -void PM_check_frozen(void) -{SELFPARAM(); - if (!PHYS_FROZEN(self)) +void PM_check_frozen(entity this) +{ + if (!PHYS_FROZEN(this)) return; - if (PHYS_DODGING_FROZEN + if (PHYS_DODGING_FROZEN(this) #ifdef SVQC - && IS_REAL_CLIENT(self) + && IS_REAL_CLIENT(this) #endif ) { - 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); + this.movement_x = bound(-5, this.movement.x, 5); + this.movement_y = bound(-5, this.movement.y, 5); + this.movement_z = bound(-5, this.movement.z, 5); } else - self.movement = '0 0 0'; + this.movement = '0 0 0'; - vector midpoint = ((self.absmin + self.absmax) * 0.5); + vector midpoint = ((this.absmin + this.absmax) * 0.5); if (pointcontents(midpoint) == CONTENT_WATER) { - self.velocity = self.velocity * 0.5; + this.velocity = this.velocity * 0.5; if (pointcontents(midpoint + '0 0 16') == CONTENT_WATER) - self.velocity_z = 200; + this.velocity_z = 200; } } -void PM_check_hitground() -{SELFPARAM(); +void PM_check_hitground(entity this) +{ #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); - } - } - } + if (!this.wasFlying) return; + this.wasFlying = false; + if (this.waterlevel >= WATERLEVEL_SWIMMING) return; + if (time < this.ladder_time) return; + if (this.hook) return; + this.nextstep = time + 0.3 + random() * 0.1; + trace_dphitq3surfaceflags = 0; + tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this); + if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return; + entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS) + ? GS_FALL_METAL + : GS_FALL; + GlobalSound(this, gs, CH_PLAYER, VOICETYPE_PLAYERSOUND); #endif } -void PM_check_blocked(void) -{SELFPARAM(); -#ifdef SVQC - if (!self.player_blocked) - return; - self.movement = '0 0 0'; - self.disableclientprediction = 1; -#endif -} - -#ifdef SVQC -float speedaward_lastsent; -float speedaward_lastupdate; -#endif -void PM_check_race(void) -{SELFPARAM(); +void PM_Footsteps(entity this) +{ #ifdef SVQC - if(!(g_cts || g_race)) - return; - if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) - { - speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1'); - speedaward_holder = self.netname; - speedaward_uid = self.crypto_idfp; - speedaward_lastupdate = time; - } - if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) + if (!g_footsteps) return; + if (IS_DUCKED(this)) return; + if (time >= this.lastground + 0.2) return; + if (vdist(this.velocity, <=, autocvar_sv_maxspeed * 0.6)) return; + if ((time > this.nextstep) || (time < (this.nextstep - 10.0))) { - string rr = (g_cts) ? CTS_RECORD : RACE_RECORD; - race_send_speedaward(MSG_ALL); - speedaward_lastsent = speedaward_speed; - if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") - { - speedaward_alltimebest = speedaward_speed; - speedaward_alltimebest_holder = speedaward_holder; - speedaward_alltimebest_uid = speedaward_uid; - db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest)); - db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid); - race_send_speedaward_alltimebest(MSG_ALL); - } + this.nextstep = time + 0.3 + random() * 0.1; + trace_dphitq3surfaceflags = 0; + tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this); + if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return; + entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS) + ? GS_STEP_METAL + : GS_STEP; + GlobalSound(this, gs, CH_PLAYER, VOICETYPE_PLAYERSOUND); } #endif } -void PM_check_vortex(void) -{SELFPARAM(); +void PM_check_blocked(entity this) +{ #ifdef SVQC - // WEAPONTODO - float xyspeed = vlen(vec2(self.velocity)); - if (self.weapon == WEP_VORTEX.m_id && 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, 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.vortex_charge = min(1, self.vortex_charge + WEP_CVAR(vortex, charge_velocity_rate) * f * PHYS_INPUT_TIMELENGTH); - } + if (!this.player_blocked) + return; + this.movement = '0 0 0'; + this.disableclientprediction = 1; #endif } -void PM_fly(float maxspd_mod) -{SELFPARAM(); +void PM_fly(entity this, float maxspd_mod) +{ // noclipping or flying - UNSET_ONGROUND(self); - - self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION); - 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; + UNSET_ONGROUND(this); + + this.velocity = this.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this)); + makevectors(this.v_angle); + //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z; + vector wishvel = v_forward * this.movement.x + + v_right * this.movement.y + + '0 0 1' * this.movement.z; // acceleration vector wishdir = normalize(wishvel); - float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod); + float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod); #ifdef SVQC - if (time >= self.teleport_time) + if(time >= PHYS_TELEPORT_TIME(this)) #endif - PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0); - PM_ClientMovement_Move(); + PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this) * maxspd_mod, 1, 0, 0, 0); + PM_ClientMovement_Move(this); } -void PM_swim(float maxspd_mod) -{SELFPARAM(); +void PM_swim(entity this, float maxspd_mod) +{ // swimming - UNSET_ONGROUND(self); + UNSET_ONGROUND(this); - float jump = PHYS_INPUT_BUTTON_JUMP(self); + float jump = PHYS_INPUT_BUTTON_JUMP(this); // water jump only in certain situations // this mimics quakeworld code - if (jump && self.waterlevel == WATERLEVEL_SWIMMING && self.velocity_z >= -180) + if (jump && this.waterlevel == WATERLEVEL_SWIMMING && this.velocity_z >= -180 && !this.viewloc) { - vector yawangles = '0 1 0' * self.v_angle.y; + vector yawangles = '0 1 0' * this.v_angle.y; makevectors(yawangles); vector forward = v_forward; - vector spot = self.origin + 24 * forward; + vector spot = this.origin + 24 * forward; spot_z += 8; - traceline(spot, spot, MOVE_NOMONSTERS, self); + traceline(spot, spot, MOVE_NOMONSTERS, this); if (trace_startsolid) { spot_z += 24; - traceline(spot, spot, MOVE_NOMONSTERS, self); + traceline(spot, spot, MOVE_NOMONSTERS, this); if (!trace_startsolid) { - self.velocity = forward * 50; - self.velocity_z = 310; + this.velocity = forward * 50; + this.velocity_z = 310; + #ifdef CSQC pmove_waterjumptime = 2; - UNSET_ONGROUND(self); - SET_JUMP_HELD(self); + #endif + UNSET_ONGROUND(this); + SET_JUMP_HELD(this); } } } - 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') + makevectors(this.v_angle); + //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z; + vector wishvel = v_forward * this.movement.x + + v_right * this.movement.y + + '0 0 1' * this.movement.z; + if(this.viewloc) + wishvel.z = -160; // drift anyway + else if (wishvel == '0 0 0') wishvel = '0 0 -60'; // drift towards bottom + vector wishdir = normalize(wishvel); - float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod) * 0.7; + float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod) * 0.7; - if (IS_DUCKED(self)) + if (IS_DUCKED(this)) wishspeed *= 0.5; // if (pmove_waterjumptime <= 0) // TODO: use { // water friction - float f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION; + float f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this); f = min(max(0, f), 1); - self.velocity *= f; + this.velocity *= f; - f = wishspeed - self.velocity * wishdir; + f = wishspeed - this.velocity * wishdir; if (f > 0) { - float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, f); - self.velocity += accelspeed * wishdir; + float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, f); + this.velocity += accelspeed * wishdir; } // holding jump button swims upward slowly - if (jump) + if (jump && !this.viewloc) { #if 0 - if (self.watertype & CONTENT_LAVA) - self.velocity_z = 50; - else if (self.watertype & CONTENT_SLIME) - self.velocity_z = 80; + if (this.watertype & CONTENT_LAVA) + this.velocity_z = 50; + else if (this.watertype & CONTENT_SLIME) + this.velocity_z = 80; else { if (IS_NEXUIZ_DERIVED(gamemode)) #endif - self.velocity_z = 200; + this.velocity_z = 200; #if 0 else - self.velocity_z = 100; + this.velocity_z = 100; } #endif } } - // water acceleration - PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0); - PM_ClientMovement_Move(); + if(this.viewloc) + { + const float addspeed = wishspeed - this.velocity * wishdir; + if (addspeed > 0) + { + const float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed); + this.velocity += accelspeed * wishdir; + } + } + else + { + // water acceleration + PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this) * maxspd_mod, 1, 0, 0, 0); + PM_ClientMovement_Move(this); + } } -void PM_ladder(float maxspd_mod) -{SELFPARAM(); +.vector oldmovement; +void PM_ladder(entity this, float maxspd_mod) +{ // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water - UNSET_ONGROUND(self); + UNSET_ONGROUND(this); float g; - g = PHYS_GRAVITY * PHYS_INPUT_TIMELENGTH; - if (PHYS_ENTGRAVITY(self)) - g *= PHYS_ENTGRAVITY(self); + g = PHYS_GRAVITY(this) * PHYS_INPUT_TIMELENGTH; + if (PHYS_ENTGRAVITY(this)) + g *= PHYS_ENTGRAVITY(this); if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE) { g *= 0.5; - self.velocity_z += g; + this.velocity_z += g; } - self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION); - 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") + this.velocity = this.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this)); + makevectors(this.v_angle); + //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z; + vector wishvel = v_forward * this.movement_x + + v_right * this.movement_y + + '0 0 1' * this.movement_z; + if(this.viewloc) + wishvel.z = this.oldmovement.x; + this.velocity_z += g; + if (this.ladder_entity.classname == "func_water") { float f = vlen(wishvel); - if (f > self.ladder_entity.speed) - wishvel *= (self.ladder_entity.speed / f); - - self.watertype = self.ladder_entity.skin; - f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z; - if ((self.origin_z + self.view_ofs_z) < f) - self.waterlevel = WATERLEVEL_SUBMERGED; - else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f) - self.waterlevel = WATERLEVEL_SWIMMING; - else if ((self.origin_z + self.mins_z + 1) < f) - self.waterlevel = WATERLEVEL_WETFEET; + if (f > this.ladder_entity.speed) + wishvel *= (this.ladder_entity.speed / f); + + this.watertype = this.ladder_entity.skin; + f = this.ladder_entity.origin_z + this.ladder_entity.maxs_z; + if ((this.origin_z + this.view_ofs_z) < f) + this.waterlevel = WATERLEVEL_SUBMERGED; + else if ((this.origin_z + (this.mins_z + this.maxs_z) * 0.5) < f) + this.waterlevel = WATERLEVEL_SWIMMING; + else if ((this.origin_z + this.mins_z + 1) < f) + this.waterlevel = WATERLEVEL_WETFEET; else { - self.waterlevel = WATERLEVEL_NONE; - self.watertype = CONTENT_EMPTY; + this.waterlevel = WATERLEVEL_NONE; + this.watertype = CONTENT_EMPTY; } } // acceleration vector wishdir = normalize(wishvel); - float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod); -#ifdef SVQC - if (time >= self.teleport_time) -#endif + float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod); + if(time >= PHYS_TELEPORT_TIME(this)) // water acceleration - PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE*maxspd_mod, 1, 0, 0, 0); - PM_ClientMovement_Move(); + PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this)*maxspd_mod, 1, 0, 0, 0); + PM_ClientMovement_Move(this); } -void PM_jetpack(float maxspd_mod) -{SELFPARAM(); - //makevectors(self.v_angle.y * '0 1 0'); - makevectors(self.v_angle); - vector wishvel = v_forward * self.movement_x - + v_right * self.movement_y; +void PM_jetpack(entity this, float maxspd_mod) +{ + //makevectors(this.v_angle.y * '0 1 0'); + makevectors(this.v_angle); + vector wishvel = v_forward * this.movement_x + + v_right * this.movement_y; // add remaining speed as Z component - float maxairspd = PHYS_MAXAIRSPEED(self) * max(1, maxspd_mod); + float maxairspd = PHYS_MAXAIRSPEED(this) * max(1, maxspd_mod); // fix speedhacks :P wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd); // add the unused velocity as up component wishvel_z = 0; - // if (self.BUTTON_JUMP) + // if (this.BUTTON_JUMP) wishvel_z = sqrt(max(0, 1 - wishvel * wishvel)); // it is now normalized, so... - float a_side = PHYS_JETPACK_ACCEL_SIDE; - float a_up = PHYS_JETPACK_ACCEL_UP; - float a_add = PHYS_JETPACK_ANTIGRAVITY * PHYS_GRAVITY; + float a_side = PHYS_JETPACK_ACCEL_SIDE(this); + float a_up = PHYS_JETPACK_ACCEL_UP(this); + float a_add = PHYS_JETPACK_ANTIGRAVITY(this) * PHYS_GRAVITY(this); wishvel_x *= a_side; wishvel_y *= a_side; @@ -1419,21 +1046,21 @@ void PM_jetpack(float maxspd_mod) //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')) / PHYS_JETPACK_MAXSPEED_SIDE, 1); - if (wishvel_z - PHYS_GRAVITY > 0) - fz = bound(0, 1 - self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1); + fxy = bound(0, 1 - (this.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE(this), 1); + if (wishvel_z - PHYS_GRAVITY(this) > 0) + fz = bound(0, 1 - this.velocity_z / PHYS_JETPACK_MAXSPEED_UP(this), 1); else - fz = bound(0, 1 + self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1); + fz = bound(0, 1 + this.velocity_z / PHYS_JETPACK_MAXSPEED_UP(this), 1); float fvel; fvel = vlen(wishvel); wishvel_x *= fxy; wishvel_y *= fxy; - wishvel_z = (wishvel_z - PHYS_GRAVITY) * fz + PHYS_GRAVITY; + wishvel_z = (wishvel_z - PHYS_GRAVITY(this)) * fz + PHYS_GRAVITY(this); fvel = min(1, vlen(wishvel) / best); - 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)); + if (PHYS_JETPACK_FUEL(this) && !(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO)) + f = min(1, PHYS_AMMO_FUEL(this) / (PHYS_JETPACK_FUEL(this) * PHYS_INPUT_TIMELENGTH * fvel)); else f = 1; @@ -1441,151 +1068,162 @@ void PM_jetpack(float maxspd_mod) if (f > 0 && wishvel != '0 0 0') { - self.velocity = self.velocity + wishvel * f * PHYS_INPUT_TIMELENGTH; - UNSET_ONGROUND(self); + this.velocity = this.velocity + wishvel * f * PHYS_INPUT_TIMELENGTH; + UNSET_ONGROUND(this); #ifdef SVQC - if (!(ITEMS_STAT(self) & IT_UNLIMITED_WEAPON_AMMO)) - self.ammo_fuel -= PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel * f; + if (!(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO)) + this.ammo_fuel -= PHYS_JETPACK_FUEL(this) * PHYS_INPUT_TIMELENGTH * fvel * f; - ITEMS_STAT(self) |= IT_USING_JETPACK; + ITEMS_STAT(this) |= 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); + this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen); #endif } #ifdef CSQC - float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH; - if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE) - self.velocity_z -= g * 0.5; - else - self.velocity_z -= g; - PM_ClientMovement_Move(); - if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND)) + float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH; + if(autocvar_cl_movement == 3) + { if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE) - self.velocity_z -= g * 0.5; + this.velocity_z -= g * 0.5; + else + this.velocity_z -= g; + } + PM_ClientMovement_Move(this); + if(autocvar_cl_movement == 3) + { + if (!IS_ONGROUND(this) || !(GAMEPLAYFIX_NOGRAVITYONGROUND)) + if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE) + this.velocity_z -= g * 0.5; + } #endif } -void PM_walk(float buttons_prev, float maxspd_mod) -{SELFPARAM(); - if (!WAS_ONGROUND(self)) +void PM_walk(entity this, float maxspd_mod) +{ + if (!WAS_ONGROUND(this)) { #ifdef SVQC if (autocvar_speedmeter) - LOG_TRACE(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n")); + LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n")); #endif - if (self.lastground < time - 0.3) - self.velocity *= (1 - PHYS_FRICTION_ONLAND); + if (this.lastground < time - 0.3) + this.velocity *= (1 - PHYS_FRICTION_ONLAND(this)); #ifdef SVQC - if (self.jumppadcount > 1) - LOG_TRACE(strcat(ftos(self.jumppadcount), "x jumppad combo\n")); - self.jumppadcount = 0; + if (this.jumppadcount > 1) + LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n")); + this.jumppadcount = 0; #endif } // walking - makevectors(self.v_angle.y * '0 1 0'); - vector wishvel = v_forward * self.movement.x - + v_right * self.movement.y; + makevectors(this.v_angle.y * '0 1 0'); + const vector wishvel = v_forward * this.movement.x + + v_right * this.movement.y; // acceleration - vector wishdir = normalize(wishvel); + const vector wishdir = normalize(wishvel); float wishspeed = vlen(wishvel); - - wishspeed = min(wishspeed, PHYS_MAXSPEED(self) * maxspd_mod); - if (IS_DUCKED(self)) - wishspeed *= 0.5; + wishspeed = min(wishspeed, PHYS_MAXSPEED(this) * maxspd_mod); + if (IS_DUCKED(this)) wishspeed *= 0.5; // apply edge friction - float f = vlen(vec2(self.velocity)); - if (f > 0) + const float f2 = vlen2(vec2(this.velocity)); + if (f2 > 0) { - float realfriction; trace_dphitq3surfaceflags = 0; - tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self); + tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this); // TODO: apply edge friction // apply ground friction - if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) - realfriction = PHYS_FRICTION_SLICK; - else - realfriction = PHYS_FRICTION; + const int realfriction = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) + ? PHYS_FRICTION_SLICK(this) + : PHYS_FRICTION(this); - f = 1 - PHYS_INPUT_TIMELENGTH * realfriction * ((f < PHYS_STOPSPEED) ? (PHYS_STOPSPEED / f) : 1); + float f = sqrt(f2); + f = 1 - PHYS_INPUT_TIMELENGTH * realfriction * ((f < PHYS_STOPSPEED(this)) ? (PHYS_STOPSPEED(this) / f) : 1); f = max(0, f); - self.velocity *= f; + this.velocity *= f; /* Mathematical analysis time! Our goal is to invert this mess. For the two cases we get: - v = v0 * (1 - PHYS_INPUT_TIMELENGTH * (PHYS_STOPSPEED / v0) * PHYS_FRICTION) - = v0 - PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION - v0 = v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION + v = v0 * (1 - PHYS_INPUT_TIMELENGTH * (PHYS_STOPSPEED(this) / v0) * PHYS_FRICTION(this)) + = v0 - PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this) + v0 = v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this) and - v = v0 * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION) - v0 = v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION) + v = v0 * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this)) + v0 = v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this)) These cases would be chosen ONLY if: - v0 < PHYS_STOPSPEED - v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION < PHYS_STOPSPEED - v < PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION) + v0 < PHYS_STOPSPEED(this) + v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this) < PHYS_STOPSPEED(this) + v < PHYS_STOPSPEED(this) * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this)) and, respectively: - v0 >= PHYS_STOPSPEED - v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION) >= PHYS_STOPSPEED - v >= PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION) + v0 >= PHYS_STOPSPEED(this) + v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this)) >= PHYS_STOPSPEED(this) + v >= PHYS_STOPSPEED(this) * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this)) */ } - float addspeed = wishspeed - self.velocity * wishdir; + const float addspeed = wishspeed - this.velocity * wishdir; if (addspeed > 0) { - float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed); - self.velocity += accelspeed * wishdir; + const float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed); + this.velocity += accelspeed * wishdir; } - float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH; - if (!(GAMEPLAYFIX_NOGRAVITYONGROUND)) - self.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1); - if (self.velocity * self.velocity) - PM_ClientMovement_Move(); - if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE) - if (!IS_ONGROUND(self) || !GAMEPLAYFIX_NOGRAVITYONGROUND) - self.velocity_z -= g * 0.5; +#ifdef CSQC + float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH; + if(autocvar_cl_movement == 3) + { + if (!(GAMEPLAYFIX_NOGRAVITYONGROUND)) + this.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1); + } + if (vdist(this.velocity, >, 0)) + PM_ClientMovement_Move(this); + if(autocvar_cl_movement == 3) + { + if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE) + if (!IS_ONGROUND(this) || !GAMEPLAYFIX_NOGRAVITYONGROUND) + this.velocity_z -= g * 0.5; + } +#endif } -void PM_air(float buttons_prev, float maxspd_mod) -{SELFPARAM(); - makevectors(self.v_angle.y * '0 1 0'); - vector wishvel = v_forward * self.movement.x - + v_right * self.movement.y; +void PM_air(entity this, float buttons_prev, float maxspd_mod) +{ + makevectors(this.v_angle.y * '0 1 0'); + vector wishvel = v_forward * this.movement.x + + v_right * this.movement.y; // acceleration vector wishdir = normalize(wishvel); float wishspeed = vlen(wishvel); #ifdef SVQC - if (time >= self.teleport_time) -#else - if (pmove_waterjumptime <= 0) + if(time >= PHYS_TELEPORT_TIME(this)) +#elif defined(CSQC) + if(pmove_waterjumptime <= 0) #endif { - float maxairspd = PHYS_MAXAIRSPEED(self) * min(maxspd_mod, 1); + float maxairspd = PHYS_MAXAIRSPEED(this) * min(maxspd_mod, 1); // apply air speed limit - float airaccelqw = PHYS_AIRACCEL_QW(self); + float airaccelqw = PHYS_AIRACCEL_QW(this); float wishspeed0 = wishspeed; wishspeed = min(wishspeed, maxairspd); - if (IS_DUCKED(self)) + if (IS_DUCKED(this)) wishspeed *= 0.5; - float airaccel = PHYS_AIRACCELERATE * min(maxspd_mod, 1); + float airaccel = PHYS_AIRACCELERATE(this) * min(maxspd_mod, 1); - float accelerating = (self.velocity * wishdir > 0); + float accelerating = (this.velocity * wishdir > 0); float wishspeed2 = wishspeed; // CPM: air control - if (PHYS_AIRSTOPACCELERATE) + if (PHYS_AIRSTOPACCELERATE(this)) { - vector curdir = normalize(vec2(self.velocity)); - airaccel += (PHYS_AIRSTOPACCELERATE*maxspd_mod - airaccel) * max(0, -(curdir * wishdir)); + vector curdir = normalize(vec2(this.velocity)); + airaccel += (PHYS_AIRSTOPACCELERATE(this)*maxspd_mod - airaccel) * max(0, -(curdir * wishdir)); } // note that for straight forward jumping: // step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0; @@ -1595,340 +1233,313 @@ 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(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero - if (PHYS_MAXAIRSTRAFESPEED) - 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)) + float strafity = IsMoveInDirection(this.movement, -90) + IsMoveInDirection(this.movement, +90); // if one is nonzero, other is always zero + if (PHYS_MAXAIRSTRAFESPEED(this)) + wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED(this)*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED(this)*maxspd_mod)); + if (PHYS_AIRSTRAFEACCELERATE(this)) + airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE(this)*maxspd_mod); + if (PHYS_AIRSTRAFEACCEL_QW(this)) airaccelqw = - (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(self) : PHYS_AIRACCEL_QW(self)) >= 0) ? +1 : -1) + (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(this) : PHYS_AIRACCEL_QW(this)) >= 0) ? +1 : -1) * - (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(self)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(self)))); + (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(this)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(this)))); // !CPM - if (PHYS_WARSOWBUNNY_TURNACCEL && accelerating && self.movement.y == 0 && self.movement.x != 0) - PM_AirAccelerate(wishdir, wishspeed2); + if (PHYS_WARSOWBUNNY_TURNACCEL(this) && accelerating && this.movement.y == 0 && this.movement.x != 0) + PM_AirAccelerate(this, wishdir, wishspeed2); else - PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(self), PHYS_AIRACCEL_SIDEWAYS_FRICTION / maxairspd, PHYS_AIRSPEEDLIMIT_NONQW(self)); + PM_Accelerate(this, wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(this), PHYS_AIRACCEL_SIDEWAYS_FRICTION(this) / maxairspd, PHYS_AIRSPEEDLIMIT_NONQW(this)); - if (PHYS_AIRCONTROL) - CPM_PM_Aircontrol(wishdir, wishspeed2); + if (PHYS_AIRCONTROL(this)) + CPM_PM_Aircontrol(this, wishdir, wishspeed2); } - float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH; +#ifdef CSQC + float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH; + if(autocvar_cl_movement == 3) if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE) - self.velocity_z -= g * 0.5; + this.velocity_z -= g * 0.5; else - self.velocity_z -= g; - PM_ClientMovement_Move(); - if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND)) + this.velocity_z -= g; +#endif + PM_ClientMovement_Move(this); +#ifdef CSQC + if(autocvar_cl_movement == 3) + if (!IS_ONGROUND(this) || !(GAMEPLAYFIX_NOGRAVITYONGROUND)) if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE) - self.velocity_z -= g * 0.5; + this.velocity_z -= g * 0.5; +#endif } // used for calculating airshots -bool IsFlying(entity a) +bool IsFlying(entity this) { - if(IS_ONGROUND(a)) + if(IS_ONGROUND(this)) return false; - if(a.waterlevel >= WATERLEVEL_SWIMMING) + if(this.waterlevel >= WATERLEVEL_SWIMMING) return false; - traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a); + traceline(this.origin, this.origin - '0 0 48', MOVE_NORMAL, this); if(trace_fraction < 1) return false; return true; } -void PM_Main() -{SELFPARAM(); - int buttons = PHYS_INPUT_BUTTON_MASK(self); +void PM_Main(entity this) +{ + int buttons = PHYS_INPUT_BUTTON_MASK(this); #ifdef CSQC - self.items = getstati(STAT_ITEMS, 0, 24); + this.items = STAT(ITEMS); - self.movement = PHYS_INPUT_MOVEVALUES(self); + this.movement = PHYS_INPUT_MOVEVALUES(this); - 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); + this.spectatorspeed = STAT(SPECTATORSPEED); - self.team = myteam + 1; // is this correct? - if (!(PHYS_INPUT_BUTTON_JUMP(self))) // !jump - UNSET_JUMP_HELD(self); // canjump = true + vector oldv_angle = this.v_angle; + vector oldangles = this.angles; // we need to save these, as they're abused by other code + this.v_angle = PHYS_INPUT_ANGLES(this); + this.angles = PHYS_WORLD_ANGLES(this); + + this.team = myteam + 1; // is this correct? + if (!(PHYS_INPUT_BUTTON_JUMP(this))) // !jump + UNSET_JUMP_HELD(this); // canjump = true pmove_waterjumptime -= PHYS_INPUT_TIMELENGTH; - PM_ClientMovement_UpdateStatus(true); + PM_ClientMovement_UpdateStatus(this, true); #endif + this.oldmovement = this.movement; + #ifdef SVQC WarpZone_PlayerPhysics_FixVAngle(); #endif float maxspeed_mod = 1; - maxspeed_mod *= PHYS_HIGHSPEED; + maxspeed_mod *= PHYS_HIGHSPEED(this); #ifdef SVQC - Physics_UpdateStats(maxspeed_mod); + Physics_UpdateStats(this, maxspeed_mod); - if (self.PlayerPhysplug) - if (self.PlayerPhysplug()) + if (this.PlayerPhysplug) + if (this.PlayerPhysplug()) return; #endif - PM_check_race_movetime(); #ifdef SVQC - anticheat_physics(); + anticheat_physics(this); #endif - if (PM_check_specialcommand(buttons)) + if (PM_check_specialcommand(this, buttons)) return; #ifdef SVQC if (sv_maxidle > 0) { - if (buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old) - self.parm_idlesince = time; + if (buttons != this.buttons_old || this.movement != this.movement_old || this.v_angle != this.v_angle_old) + this.parm_idlesince = time; } #endif - int buttons_prev = self.buttons_old; - self.buttons_old = buttons; - self.movement_old = self.movement; - self.v_angle_old = self.v_angle; + int buttons_prev = this.buttons_old; + this.buttons_old = buttons; + this.movement_old = this.movement; + this.v_angle_old = this.v_angle; - PM_check_nickspam(); + PM_check_nickspam(this); - PM_check_punch(); + PM_check_punch(this); #ifdef SVQC - if (IS_BOT_CLIENT(self)) + if (IS_BOT_CLIENT(this)) { - if (playerdemo_read()) + if (playerdemo_read(this)) return; - bot_think(); + WITH(entity, self, this, bot_think()); } - - if (IS_PLAYER(self)) -#endif - { -#ifdef SVQC - if (self.race_penalty) - if (time > self.race_penalty) - self.race_penalty = 0; #endif - bool not_allowed_to_move = false; -#ifdef SVQC - if (self.race_penalty) - not_allowed_to_move = true; -#endif #ifdef SVQC - if (time < game_starttime) - not_allowed_to_move = true; -#endif - - if (not_allowed_to_move) + if (IS_PLAYER(this)) + { + const bool allowed_to_move = (time >= game_starttime); + if (!allowed_to_move) { - self.velocity = '0 0 0'; - self.movetype = MOVETYPE_NONE; -#ifdef SVQC - self.disableclientprediction = 2; -#endif + this.velocity = '0 0 0'; + this.movetype = MOVETYPE_NONE; + this.disableclientprediction = 2; } -#ifdef SVQC - else if (self.disableclientprediction == 2) + else if (this.disableclientprediction == 2) { - if (self.movetype == MOVETYPE_NONE) - self.movetype = MOVETYPE_WALK; - self.disableclientprediction = 0; + if (this.movetype == MOVETYPE_NONE) + this.movetype = MOVETYPE_WALK; + this.disableclientprediction = 0; } -#endif } +#endif #ifdef SVQC - if (self.movetype == MOVETYPE_NONE) + if (this.movetype == MOVETYPE_NONE) return; // when we get here, disableclientprediction cannot be 2 - self.disableclientprediction = 0; + this.disableclientprediction = 0; #endif - viewloc_PlayerPhysics(); + viewloc_PlayerPhysics(this); - PM_check_spider(); + PM_check_frozen(this); - PM_check_frozen(); - - PM_check_blocked(); + PM_check_blocked(this); maxspeed_mod = 1; - if (self.in_swamp) - maxspeed_mod *= self.swamp_slowdown; //cvar("g_balance_swamp_moverate"); + if (this.in_swamp) + maxspeed_mod *= this.swamp_slowdown; //cvar("g_balance_swamp_moverate"); // conveyors: first fix velocity - if (self.conveyor.state) - self.velocity -= self.conveyor.movedir; - -#ifdef SVQC - MUTATOR_CALLHOOK(PlayerPhysics); -#endif -#ifdef CSQC - PM_multijump(); -#endif + if (this.conveyor.state) + this.velocity -= this.conveyor.movedir; -// float forcedodge = 1; -// if(forcedodge) { -//#ifdef CSQC -// PM_dodging_checkpressedkeys(); -//#endif -// PM_dodging(); -// PM_ClientMovement_Move(); -// return; -// } + MUTATOR_CALLHOOK(PlayerPhysics, this); -#ifdef SVQC - if (!IS_PLAYER(self)) + if (!IS_PLAYER(this)) { +#ifdef SVQC 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)) + if (!this.spectatorspeed) + this.spectatorspeed = maxspeed_mod; + if (this.impulse && this.impulse <= 19 || (this.impulse >= 200 && this.impulse <= 209) || (this.impulse >= 220 && this.impulse <= 229)) { - if (self.lastclassname != "player") + if (this.lastclassname != "player") { - if (self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209)) - self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5); - else if (self.impulse == 11) - self.spectatorspeed = maxspeed_mod; - else if (self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229)) - self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5); - else if (self.impulse >= 1 && self.impulse <= 9) - self.spectatorspeed = 1 + 0.5 * (self.impulse - 1); + if (this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209)) + this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5); + else if (this.impulse == 11) + this.spectatorspeed = maxspeed_mod; + else if (this.impulse == 12 || this.impulse == 16 || this.impulse == 19 || (this.impulse >= 220 && this.impulse <= 229)) + this.spectatorspeed = bound(1, this.spectatorspeed - 0.5, 5); + else if (this.impulse >= 1 && this.impulse <= 9) + this.spectatorspeed = 1 + 0.5 * (this.impulse - 1); } // otherwise just clear - self.impulse = 0; + this.impulse = 0; } - maxspeed_mod = self.spectatorspeed; +#endif + maxspeed_mod = this.spectatorspeed; } +#ifdef SVQC - float spd = max(PHYS_MAXSPEED(self), PHYS_MAXAIRSPEED(self)) * maxspeed_mod; - if(self.speed != spd) + float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod; + if(this.speed != spd) { - self.speed = spd; + this.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")); + stuffcmd(this, strcat("cl_forwardspeed ", temps, "\n")); + stuffcmd(this, strcat("cl_backspeed ", temps, "\n")); + stuffcmd(this, strcat("cl_sidespeed ", temps, "\n")); + stuffcmd(this, strcat("cl_upspeed ", temps, "\n")); } - if(self.stat_jumpspeedcap_min != PHYS_JUMPSPEEDCAP_MIN) + if(this.jumpspeedcap_min != autocvar_sv_jumpspeedcap_min) { - self.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MIN; - stuffcmd(self, strcat("cl_jumpspeedcap_min ", PHYS_JUMPSPEEDCAP_MIN, "\n")); + this.jumpspeedcap_min = autocvar_sv_jumpspeedcap_min; + stuffcmd(this, sprintf("\ncl_jumpspeedcap_min \"%s\"\n", autocvar_sv_jumpspeedcap_min)); } - if(self.stat_jumpspeedcap_max != PHYS_JUMPSPEEDCAP_MAX) + if(this.jumpspeedcap_max != autocvar_sv_jumpspeedcap_max) { - self.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MAX; - stuffcmd(self, strcat("cl_jumpspeedcap_max ", PHYS_JUMPSPEEDCAP_MAX, "\n")); + this.jumpspeedcap_max = autocvar_sv_jumpspeedcap_max; + stuffcmd(this, sprintf("\ncl_jumpspeedcap_max \"%s\"\n", autocvar_sv_jumpspeedcap_max)); } #endif - if(PHYS_DEAD(self)) + if(PHYS_DEAD(this)) { // handle water here - vector midpoint = ((self.absmin + self.absmax) * 0.5); + vector midpoint = ((this.absmin + this.absmax) * 0.5); if(pointcontents(midpoint) == CONTENT_WATER) { - self.velocity = self.velocity * 0.5; + this.velocity = this.velocity * 0.5; // do we want this? //if(pointcontents(midpoint + '0 0 2') == CONTENT_WATER) - //{ self.velocity_z = 70; } + //{ this.velocity_z = 70; } } goto end; } #ifdef SVQC - if (!self.fixangle && !g_bugrigs) - self.angles = '0 1 0' * self.v_angle.y; + if (!this.fixangle) + this.angles = '0 1 0' * this.v_angle.y; #endif - PM_check_hitground(); + if (IS_PLAYER(this) && IS_ONGROUND(this)) + { + PM_check_hitground(this); + PM_Footsteps(this); + } - if(IsFlying(self)) - self.wasFlying = 1; + if(IsFlying(this)) + this.wasFlying = 1; - if (IS_PLAYER(self)) - CheckPlayerJump(); + if (IS_PLAYER(this)) + CheckPlayerJump(this); - if (self.flags & FL_WATERJUMP) + if (this.flags & FL_WATERJUMP) { - self.velocity_x = self.movedir_x; - self.velocity_y = self.movedir_y; - if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE) + this.velocity_x = this.movedir.x; + this.velocity_y = this.movedir.y; + if (time > PHYS_TELEPORT_TIME(this) || this.waterlevel == WATERLEVEL_NONE) { - self.flags &= ~FL_WATERJUMP; - self.teleport_time = 0; + this.flags &= ~FL_WATERJUMP; + PHYS_TELEPORT_TIME(this) = 0; } } + else if (MUTATOR_CALLHOOK(PM_Physics, this, maxspeed_mod)) + { } + #ifdef SVQC - else if (g_bugrigs && IS_PLAYER(self)) - RaceCarPhysics(); + else if (this.movetype == MOVETYPE_NOCLIP || this.movetype == MOVETYPE_FLY || this.movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this)) +#elif defined(CSQC) + else if (this.move_movetype == MOVETYPE_NOCLIP || this.move_movetype == MOVETYPE_FLY || this.move_movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this)) #endif + PM_fly(this, maxspeed_mod); - 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 (this.waterlevel >= WATERLEVEL_SWIMMING) + PM_swim(this, maxspeed_mod); - else if (self.waterlevel >= WATERLEVEL_SWIMMING) - PM_swim(maxspeed_mod); + else if (time < this.ladder_time) + PM_ladder(this, maxspeed_mod); - else if (time < self.ladder_time) - PM_ladder(maxspeed_mod); + else if (ITEMS_STAT(this) & IT_USING_JETPACK) + PM_jetpack(this, maxspeed_mod); - else if (ITEMS_STAT(self) & IT_USING_JETPACK) - PM_jetpack(maxspeed_mod); - - else if (IS_ONGROUND(self)) - PM_walk(buttons_prev, maxspeed_mod); + else if (IS_ONGROUND(this)) + PM_walk(this, maxspeed_mod); else - PM_air(buttons_prev, maxspeed_mod); - -#ifdef SVQC - if (!IS_OBSERVER(self)) - PM_check_race(); -#endif - PM_check_vortex(); + PM_air(this, buttons_prev, maxspeed_mod); :end - if (IS_ONGROUND(self)) - self.lastground = time; + if (IS_ONGROUND(this)) + this.lastground = time; // conveyors: then break velocity again - if(self.conveyor.state) - self.velocity += self.conveyor.movedir; + if(this.conveyor.state) + this.velocity += this.conveyor.movedir; - self.lastflags = self.flags; + this.lastflags = this.flags; - self.lastclassname = self.classname; + this.lastclassname = this.classname; #ifdef CSQC - self.v_angle = oldv_angle; - self.angles = oldangles; + this.v_angle = oldv_angle; + this.angles = oldangles; #endif } -#ifdef SVQC -void SV_PlayerPhysics(void) +#if defined(SVQC) +void SV_PlayerPhysics() #elif defined(CSQC) -void CSQC_ClientMovement_PlayerMove_Frame(void) +void CSQC_ClientMovement_PlayerMove_Frame(entity this) #endif -{SELFPARAM(); - 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); +{ +#ifdef SVQC + SELFPARAM(); #endif + PM_Main(this); }