11 .float spectatorspeed;
16 .string lastclassname;
18 .float() PlayerPhysplug;
19 float AdjustAirAccelQW(float accelqw, float factor);
22 .float stat_dodging_frozen;
23 .float stat_sv_airaccel_qw;
24 .float stat_sv_airstrafeaccel_qw;
25 .float stat_sv_airspeedlimit_nonqw;
26 .float stat_sv_maxspeed;
27 .float stat_movement_highspeed;
29 .float stat_jetpack_accel_side;
30 .float stat_jetpack_accel_up;
31 .float stat_jetpack_antigravity;
32 .float stat_jetpack_fuel;
33 .float stat_jetpack_maxspeed_up;
34 .float stat_jetpack_maxspeed_side;
36 void Physics_AddStats()
38 // g_movementspeed hack
39 addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
40 addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
41 addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
42 addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
43 addstat(STAT_MOVEVARS_HIGHSPEED, AS_FLOAT, stat_movement_highspeed);
46 addstat(STAT_DODGING_FROZEN, AS_INT, stat_dodging_frozen);
49 addstat(STAT_JETPACK_ACCEL_SIDE, AS_FLOAT, stat_jetpack_accel_side);
50 addstat(STAT_JETPACK_ACCEL_UP, AS_FLOAT, stat_jetpack_accel_up);
51 addstat(STAT_JETPACK_ANTIGRAVITY, AS_FLOAT, stat_jetpack_antigravity);
52 addstat(STAT_JETPACK_FUEL, AS_FLOAT, stat_jetpack_fuel);
53 addstat(STAT_JETPACK_MAXSPEED_UP, AS_FLOAT, stat_jetpack_maxspeed_up);
54 addstat(STAT_JETPACK_MAXSPEED_SIDE, AS_FLOAT, stat_jetpack_maxspeed_side);
58 // Client/server mappings
62 #define PHYS_INPUT_ANGLES(s) input_angles
63 #define PHYS_INPUT_BUTTONS(s) input_buttons
64 #define PHYS_INPUT_TIMELENGTH input_timelength
65 #define PHYS_INPUT_MOVEVALUES(s) input_movevalues
67 #define GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE moveflags & MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE
68 #define GAMEPLAYFIX_NOGRAVITYONGROUND cvar("sv_gameplayfix_nogravityonground")
69 #define GAMEPLAYFIX_Q2AIRACCELERATE cvar("sv_gameplayfix_q2airaccelerate")
71 #define IS_DUCKED(s) (s.pmove_flags & PMF_DUCKED)
72 #define SET_DUCKED(s) s.pmove_flags |= PMF_DUCKED
73 #define UNSET_DUCKED(s) s.pmove_flags &= ~PMF_DUCKED
75 #define IS_JUMP_HELD(s) (s.pmove_flags & PMF_JUMP_HELD)
76 #define SET_JUMP_HELD(s) s.pmove_flags |= PMF_JUMP_HELD
77 #define UNSET_JUMP_HELD(s) s.pmove_flags &= ~PMF_JUMP_HELD
79 #define IS_ONGROUND(s) (s.pmove_flags & PMF_ONGROUND)
80 #define SET_ONGROUND(s) s.pmove_flags |= PMF_ONGROUND
81 #define UNSET_ONGROUND(s) s.pmove_flags &= ~PMF_ONGROUND
83 #define ITEMS(s) getstati(STAT_ITEMS, 0, 24)
84 #define PHYS_AMMO_FUEL(s) getstati(STAT_FUEL)
85 #define PHYS_FROZEN(s) getstati(STAT_FROZEN)
87 #define PHYS_ACCELERATE getstatf(STAT_MOVEVARS_ACCELERATE)
88 #define PHYS_AIRACCEL_QW(s) getstatf(STAT_MOVEVARS_AIRACCEL_QW)
89 #define PHYS_AIRACCEL_QW_STRETCHFACTOR(s) getstatf(STAT_MOVEVARS_AIRACCEL_QW_STRETCHFACTOR)
90 #define PHYS_AIRACCEL_SIDEWAYS_FRICTION getstatf(STAT_MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION)
91 #define PHYS_AIRACCELERATE getstatf(STAT_MOVEVARS_AIRACCELERATE)
92 #define PHYS_AIRCONTROL getstatf(STAT_MOVEVARS_AIRCONTROL)
93 #define PHYS_AIRCONTROL_PENALTY getstatf(STAT_MOVEVARS_AIRCONTROL_PENALTY)
94 #define PHYS_AIRCONTROL_POWER getstatf(STAT_MOVEVARS_AIRCONTROL_POWER)
95 #define PHYS_AIRSPEEDLIMIT_NONQW(s) getstatf(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW)
96 #define PHYS_AIRSTOPACCELERATE getstatf(STAT_MOVEVARS_AIRSTOPACCELERATE)
97 #define PHYS_AIRSTRAFEACCEL_QW(s) getstatf(STAT_MOVEVARS_AIRSTRAFEACCEL_QW)
98 #define PHYS_AIRSTRAFEACCELERATE getstatf(STAT_MOVEVARS_AIRSTRAFEACCELERATE)
99 #define PHYS_ENTGRAVITY(s) getstatf(STAT_MOVEVARS_ENTGRAVITY)
100 #define PHYS_FRICTION getstatf(STAT_MOVEVARS_FRICTION)
101 #define PHYS_GRAVITY getstatf(STAT_MOVEVARS_GRAVITY)
102 #define PHYS_HIGHSPEED getstatf(STAT_MOVEVARS_HIGHSPEED)
103 #define PHYS_JUMPVELOCITY getstatf(STAT_MOVEVARS_JUMPVELOCITY)
104 #define PHYS_MAXAIRSPEED getstatf(STAT_MOVEVARS_MAXAIRSPEED)
105 #define PHYS_MAXAIRSTRAFESPEED getstatf(STAT_MOVEVARS_MAXAIRSTRAFESPEED)
106 #define PHYS_MAXSPEED(s) getstatf(STAT_MOVEVARS_MAXSPEED)
107 #define PHYS_STEPHEIGHT getstatf(STAT_MOVEVARS_STEPHEIGHT)
108 #define PHYS_STOPSPEED getstatf(STAT_MOVEVARS_STOPSPEED)
109 #define PHYS_WARSOWBUNNY_ACCEL getstatf(STAT_MOVEVARS_WARSOWBUNNY_ACCEL)
110 #define PHYS_WARSOWBUNNY_BACKTOSIDERATIO getstatf(STAT_MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO)
111 #define PHYS_WARSOWBUNNY_AIRFORWARDACCEL getstatf(STAT_MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL)
112 #define PHYS_WARSOWBUNNY_TOPSPEED getstatf(STAT_MOVEVARS_WARSOWBUNNY_TOPSPEED)
113 #define PHYS_WARSOWBUNNY_TURNACCEL getstatf(STAT_MOVEVARS_WARSOWBUNNY_TURNACCEL)
115 #define PHYS_JETPACK_ACCEL_UP getstatf(STAT_JETPACK_ACCEL_UP)
116 #define PHYS_JETPACK_ACCEL_SIDE getstatf(STAT_JETPACK_ACCEL_SIDE)
117 #define PHYS_JETPACK_ANTIGRAVITY getstatf(STAT_JETPACK_ANTIGRAVITY)
118 #define PHYS_JETPACK_FUEL getstatf(STAT_JETPACK_FUEL)
119 #define PHYS_JETPACK_MAXSPEED_UP getstatf(STAT_JETPACK_MAXSPEED_UP)
120 #define PHYS_JETPACK_MAXSPEED_SIDE getstatf(STAT_JETPACK_MAXSPEED_SIDE)
122 #define PHYS_BUTTON_HOOK(s) (input_buttons & 32)
124 #define PHYS_DODGING_FROZEN getstati(STAT_DODGING_FROZEN)
128 #define PHYS_INPUT_ANGLES(s) s.v_angle
130 #define PHYS_INPUT_BUTTONS(s) (s.BUTTON_ATCK + 2 * s.BUTTON_JUMP + 4 * s.BUTTON_ATCK2 + 8 * s.BUTTON_ZOOM + 16 * s.BUTTON_CROUCH + 32 * s.BUTTON_HOOK + 64 * s.BUTTON_USE + 128 * (s.movement_x < 0) + 256 * (s.movement_x > 0) + 512 * (s.movement_y < 0) + 1024 * (s.movement_y > 0))
131 #define PHYS_INPUT_TIMELENGTH frametime
132 #define PHYS_INPUT_MOVEVALUES(s) s.movement
134 #define GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE autocvar_sv_gameplayfix_gravityunaffectedbyticrate
135 #define GAMEPLAYFIX_NOGRAVITYONGROUND cvar("sv_gameplayfix_nogravityonground")
136 #define GAMEPLAYFIX_Q2AIRACCELERATE autocvar_sv_gameplayfix_q2airaccelerate
138 #define IS_DUCKED(s) s.crouch
139 #define SET_DUCKED(s) s.crouch = TRUE
140 #define UNSET_DUCKED(s) s.crouch = FALSE
142 #define IS_JUMP_HELD(s) (s.flags & FL_JUMPRELEASED == 0)
143 #define SET_JUMP_HELD(s) s.flags &= ~FL_JUMPRELEASED
144 #define UNSET_JUMP_HELD(s) s.flags |= FL_JUMPRELEASED
146 #define IS_ONGROUND(s) (s.flags & FL_ONGROUND)
147 #define SET_ONGROUND(s) s.flags |= FL_ONGROUND
148 #define UNSET_ONGROUND(s) s.flags &= ~FL_ONGROUND
150 #define ITEMS(s) s.items
151 #define PHYS_AMMO_FUEL(s) s.ammo_fuel
152 #define PHYS_FROZEN(s) s.frozen
154 #define PHYS_ACCELERATE autocvar_sv_accelerate
155 #define PHYS_AIRACCEL_QW(s) s.stat_sv_airaccel_qw
156 #define PHYS_AIRACCEL_QW_STRETCHFACTOR(s) autocvar_sv_airaccel_qw_stretchfactor
157 #define PHYS_AIRACCEL_SIDEWAYS_FRICTION autocvar_sv_airaccel_sideways_friction
158 #define PHYS_AIRACCELERATE autocvar_sv_airaccelerate
159 #define PHYS_AIRCONTROL autocvar_sv_aircontrol
160 #define PHYS_AIRCONTROL_PENALTY autocvar_sv_aircontrol_penalty
161 #define PHYS_AIRCONTROL_POWER autocvar_sv_aircontrol_power
162 #define PHYS_AIRSPEEDLIMIT_NONQW(s) s.stat_sv_airspeedlimit_nonqw
163 #define PHYS_AIRSTOPACCELERATE autocvar_sv_airstopaccelerate
164 #define PHYS_AIRSTRAFEACCEL_QW(s) s.stat_sv_airstrafeaccel_qw
165 #define PHYS_AIRSTRAFEACCELERATE autocvar_sv_airstrafeaccelerate
166 #define PHYS_ENTGRAVITY(s) s.gravity
167 #define PHYS_FRICTION autocvar_sv_friction
168 #define PHYS_GRAVITY autocvar_sv_gravity
169 #define PHYS_HIGHSPEED autocvar_g_movement_highspeed
170 #define PHYS_JUMPVELOCITY autocvar_sv_jumpvelocity
171 #define PHYS_MAXAIRSPEED autocvar_sv_maxairspeed
172 #define PHYS_MAXAIRSTRAFESPEED autocvar_sv_maxairstrafespeed
173 #define PHYS_MAXSPEED(s) s.stat_sv_maxspeed
174 #define PHYS_STEPHEIGHT autocvar_sv_stepheight
175 #define PHYS_STOPSPEED autocvar_sv_stopspeed
176 #define PHYS_WARSOWBUNNY_ACCEL autocvar_sv_warsowbunny_accel
177 #define PHYS_WARSOWBUNNY_BACKTOSIDERATIO autocvar_sv_warsowbunny_backtosideratio
178 #define PHYS_WARSOWBUNNY_AIRFORWARDACCEL autocvar_sv_warsowbunny_airforwardaccel
179 #define PHYS_WARSOWBUNNY_TOPSPEED autocvar_sv_warsowbunny_topspeed
180 #define PHYS_WARSOWBUNNY_TURNACCEL autocvar_sv_warsowbunny_turnaccel
182 #define PHYS_JETPACK_ACCEL_UP autocvar_g_jetpack_acceleration_up
183 #define PHYS_JETPACK_ACCEL_SIDE autocvar_g_jetpack_acceleration_side
184 #define PHYS_JETPACK_ANTIGRAVITY autocvar_g_jetpack_antigravity
185 #define PHYS_JETPACK_FUEL autocvar_g_jetpack_fuel
186 #define PHYS_JETPACK_MAXSPEED_UP autocvar_g_jetpack_maxspeed_up
187 #define PHYS_JETPACK_MAXSPEED_SIDE autocvar_g_jetpack_maxspeed_side
189 #define PHYS_BUTTON_HOOK(s) s.BUTTON_HOOK
191 #define PHYS_DODGING_FROZEN autocvar_sv_dodging_frozen
194 void Physics_UpdateStats(float maxspd_mod)
196 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
197 if (autocvar_sv_airstrafeaccel_qw)
198 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
200 self.stat_sv_airstrafeaccel_qw = 0;
201 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
202 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
203 self.stat_movement_highspeed = PHYS_HIGHSPEED; // TODO: remove this!
205 self.stat_jetpack_antigravity = PHYS_JETPACK_ANTIGRAVITY;
206 self.stat_jetpack_accel_up = PHYS_JETPACK_ACCEL_UP;
207 self.stat_jetpack_accel_side = PHYS_JETPACK_ACCEL_SIDE;
208 self.stat_jetpack_maxspeed_side = PHYS_JETPACK_MAXSPEED_SIDE;
209 self.stat_jetpack_maxspeed_up = PHYS_JETPACK_MAXSPEED_UP;
210 self.stat_jetpack_fuel = PHYS_JETPACK_FUEL;
214 float IsMoveInDirection(vector mv, float angle) // key mix factor
216 if (mv_x == 0 && mv_y == 0)
217 return 0; // avoid division by zero
218 angle -= RAD2DEG * atan2(mv_y, mv_x);
219 angle = remainder(angle, 360) / 45;
220 return angle > 1 ? 0 : angle < -1 ? 0 : 1 - fabs(angle);
223 float GeomLerp(float a, float lerp, float b)
225 return a == 0 ? (lerp < 1 ? 0 : b)
226 : b == 0 ? (lerp > 0 ? 0 : a)
227 : a * pow(fabs(b / a), lerp);
230 noref float pmove_waterjumptime;
232 const float unstick_count = 27;
233 vector unstick_offsets[unstick_count] =
235 // 1 no nudge (just return the original if this test passes)
238 ' 0.000 0.000 0.125', '0.000 0.000 -0.125',
239 '-0.125 0.000 0.000', '0.125 0.000 0.000',
240 ' 0.000 -0.125 0.000', '0.000 0.125 0.000',
241 // 4 diagonal flat nudges
242 '-0.125 -0.125 0.000', '0.125 -0.125 0.000',
243 '-0.125 0.125 0.000', '0.125 0.125 0.000',
244 // 8 diagonal upward nudges
245 '-0.125 0.000 0.125', '0.125 0.000 0.125',
246 ' 0.000 -0.125 0.125', '0.000 0.125 0.125',
247 '-0.125 -0.125 0.125', '0.125 -0.125 0.125',
248 '-0.125 0.125 0.125', '0.125 0.125 0.125',
249 // 8 diagonal downward nudges
250 '-0.125 0.000 -0.125', '0.125 0.000 -0.125',
251 ' 0.000 -0.125 -0.125', '0.000 0.125 -0.125',
252 '-0.125 -0.125 -0.125', '0.125 -0.125 -0.125',
253 '-0.125 0.125 -0.125', '0.125 0.125 -0.125',
256 void PM_ClientMovement_Unstick()
259 for (i = 0; i < unstick_count; i++)
261 vector neworigin = unstick_offsets[i] + self.origin;
262 tracebox(neworigin, PL_CROUCH_MIN, PL_CROUCH_MAX, neworigin, MOVE_NORMAL, self);
263 if (!trace_startsolid)
265 self.origin = neworigin;
271 void PM_ClientMovement_UpdateStatus()
273 // make sure player is not stuck
274 PM_ClientMovement_Unstick();
277 if (PHYS_INPUT_BUTTONS(self) & 16)
279 // wants to crouch, this always works..
280 if (!IS_DUCKED(self))
285 // wants to stand, if currently crouching we need to check for a
289 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, MOVE_NORMAL, self);
290 if (!trace_startsolid)
296 vector origin1 = self.origin + '0 0 1';
297 vector origin2 = self.origin - '0 0 1';
299 tracebox(origin1, self.mins, self.maxs, origin2, MOVE_NORMAL, self);
300 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
304 // this code actually "predicts" an impact; so let's clip velocity first
305 float f = dotproduct(self.velocity, trace_plane_normal);
306 if (f < 0) // only if moving downwards actually
307 self.velocity -= f * trace_plane_normal;
310 UNSET_ONGROUND(self);
312 // set watertype/waterlevel
313 origin1 = self.origin;
314 origin1_z += self.mins_z + 1;
315 self.waterlevel = WATERLEVEL_NONE;
317 self.watertype = (pointcontents(origin1) == CONTENT_WATER);
321 self.waterlevel = WATERLEVEL_WETFEET;
322 origin1_z = self.origin_z + (self.mins_z + self.maxs_z) * 0.5;
323 if(pointcontents(origin1) == CONTENT_WATER)
325 self.waterlevel = WATERLEVEL_SWIMMING;
326 origin1_z = self.origin_z + 22;
327 if(pointcontents(origin1) == CONTENT_WATER)
328 self.waterlevel = WATERLEVEL_SUBMERGED;
332 if(IS_ONGROUND(self) || self.velocity_z <= 0 || pmove_waterjumptime <= 0)
333 pmove_waterjumptime = 0;
336 void PM_ClientMovement_Move()
339 float t = PHYS_INPUT_TIMELENGTH;
340 vector primalvelocity = self.velocity;
341 PM_ClientMovement_UpdateStatus();
343 for (bump = 0; bump < 8 && self.velocity * self.velocity > 0; bump++)
345 vector neworigin = self.origin + t * self.velocity;
346 tracebox(self.origin, self.mins, self.maxs, neworigin, MOVE_NORMAL, self);
347 float old_trace1_fraction = trace_fraction;
348 vector old_trace1_endpos = trace_endpos;
349 vector old_trace1_plane_normal = trace_plane_normal;
350 if (trace_fraction < 1 && trace_plane_normal_z == 0)
352 // may be a step or wall, try stepping up
353 // first move forward at a higher level
354 vector currentorigin2 = self.origin;
355 currentorigin2_z += PHYS_STEPHEIGHT;
356 vector neworigin2 = neworigin;
357 neworigin2_z = self.origin_z + PHYS_STEPHEIGHT;
358 tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
359 if (!trace_startsolid)
361 // then move down from there
362 currentorigin2 = trace_endpos;
363 neworigin2 = trace_endpos;
364 neworigin2_z = self.origin_z;
365 float old_trace2_fraction = trace_fraction;
366 vector old_trace2_plane_normal = trace_plane_normal;
367 tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
368 //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]);
369 // accept the new trace if it made some progress
370 if (fabs(trace_endpos_x - old_trace1_endpos_x) >= 0.03125 || fabs(trace_endpos_y - old_trace1_endpos_y) >= 0.03125)
372 trace_fraction = old_trace2_fraction;
373 trace_endpos = trace_endpos;
374 trace_plane_normal = old_trace2_plane_normal;
378 trace_fraction = old_trace1_fraction;
379 trace_endpos = old_trace1_endpos;
380 trace_plane_normal = old_trace1_plane_normal;
385 // check if it moved at all
386 if (trace_fraction >= 0.001)
387 self.origin = trace_endpos;
389 // check if it moved all the way
390 if (trace_fraction == 1)
393 // this is only really needed for nogravityonground combined with gravityunaffectedbyticrate
394 // <LordHavoc> I'm pretty sure I commented it out solely because it seemed redundant
395 // this got commented out in a change that supposedly makes the code match QW better
396 // so if this is broken, maybe put it in an if (cls.protocol != PROTOCOL_QUAKEWORLD) block
397 if (trace_plane_normal_z > 0.7)
400 t -= t * trace_fraction;
402 float f = dotproduct(self.velocity, trace_plane_normal);
403 self.velocity -= f * trace_plane_normal;
405 if (pmove_waterjumptime > 0)
406 self.velocity = primalvelocity;
410 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
414 // this doesn't play well with analog input
415 if (PHYS_INPUT_MOVEVALUES(self).x == 0 || PHYS_INPUT_MOVEVALUES(self).y != 0)
416 return; // can't control movement if not moving forward or backward
419 k = 32 * (2 * IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), 0) - 1);
424 k *= bound(0, wishspeed / PHYS_MAXAIRSPEED, 1);
426 float zspeed = self.velocity_z;
428 float xyspeed = vlen(self.velocity);
429 self.velocity = normalize(self.velocity);
431 float dot = self.velocity * wishdir;
433 if (dot > 0) // we can't change direction while slowing down
435 k *= pow(dot, PHYS_AIRCONTROL_POWER)*PHYS_INPUT_TIMELENGTH;
436 xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY * sqrt(max(0, 1 - dot*dot)) * k/32);
437 k *= PHYS_AIRCONTROL;
438 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
441 self.velocity = self.velocity * xyspeed;
442 self.velocity_z = zspeed;
445 float AdjustAirAccelQW(float accelqw, float factor)
447 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
450 // example config for alternate speed clamping:
451 // sv_airaccel_qw 0.8
452 // sv_airaccel_sideways_friction 0
453 // prvm_globalset server speedclamp_mode 1
455 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
457 float speedclamp = stretchfactor > 0 ? stretchfactor
458 : accelqw < 0 ? 1 // full clamping, no stretch
461 accelqw = fabs(accelqw);
463 if (GAMEPLAYFIX_Q2AIRACCELERATE)
464 wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
466 float vel_straight = self.velocity * wishdir;
467 float vel_z = self.velocity_z;
468 vector vel_xy = vec2(self.velocity);
469 vector vel_perpend = vel_xy - vel_straight * wishdir;
471 float step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
473 float vel_xy_current = vlen(vel_xy);
475 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
476 float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
477 float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
478 vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
479 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
481 if (sidefric < 0 && (vel_perpend*vel_perpend))
482 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
484 float f = max(0, 1 + PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
485 float fmin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
487 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
488 // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
489 // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
490 // obviously, this cannot be
496 vel_perpend *= max(fmin, f);
500 vel_perpend *= max(0, 1 - PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
502 vel_xy = vel_straight * wishdir + vel_perpend;
506 float vel_xy_preclamp;
507 vel_xy_preclamp = vlen(vel_xy);
508 if (vel_xy_preclamp > 0) // prevent division by zero
510 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
511 if (vel_xy_current < vel_xy_preclamp)
512 vel_xy *= (vel_xy_current / vel_xy_preclamp);
516 self.velocity = vel_xy + vel_z * '0 0 1';
519 void PM_AirAccelerate(vector wishdir, float wishspeed)
524 vector curvel = self.velocity;
526 float curspeed = vlen(curvel);
528 if (wishspeed > curspeed * 1.01)
529 wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH);
532 float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED - PHYS_MAXSPEED(self)));
533 wishspeed = max(curspeed, PHYS_MAXSPEED(self)) + PHYS_WARSOWBUNNY_ACCEL * f * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH;
535 vector wishvel = wishdir * wishspeed;
536 vector acceldir = wishvel - curvel;
537 float addspeed = vlen(acceldir);
538 acceldir = normalize(acceldir);
540 float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH);
542 if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO < 1)
544 vector curdir = normalize(curvel);
545 float dot = acceldir * curdir;
547 acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO) * dot * curdir;
550 self.velocity += accelspeed * acceldir;
558 When you press the jump key
561 void PlayerJump (void)
564 if (PHYS_FROZEN(self))
565 return; // no jumping in freezetag when frozen
567 if (self.player_blocked)
568 return; // no jumping while blocked
570 float doublejump = FALSE;
571 float mjumpheight = PHYS_JUMPVELOCITY;
573 player_multijump = doublejump;
574 player_jumpheight = mjumpheight;
575 if (MUTATOR_CALLHOOK(PlayerJump))
578 doublejump = player_multijump;
579 mjumpheight = player_jumpheight;
581 if (autocvar_sv_doublejump)
583 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
584 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
588 // we MUST clip velocity here!
590 f = self.velocity * trace_plane_normal;
592 self.velocity -= f * trace_plane_normal;
596 if (self.waterlevel >= WATERLEVEL_SWIMMING)
598 self.velocity_z = self.stat_sv_maxspeed * 0.7;
603 if (!IS_ONGROUND(self))
606 if (self.cvar_cl_movement_track_canjump)
607 if (!(self.flags & FL_JUMPRELEASED))
610 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
611 // velocity bounds. Final velocity is bound between (jumpheight *
612 // min + jumpheight) and (jumpheight * max + jumpheight);
614 if (autocvar_sv_jumpspeedcap_min != "")
616 float minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min);
618 if (self.velocity_z < minjumpspeed)
619 mjumpheight += minjumpspeed - self.velocity_z;
622 if (autocvar_sv_jumpspeedcap_max != "")
624 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
625 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
627 if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && autocvar_sv_jumpspeedcap_max_disable_on_ramps))
629 float maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max);
631 if (self.velocity_z > maxjumpspeed)
632 mjumpheight -= self.velocity_z - maxjumpspeed;
636 if (!(self.lastflags & FL_ONGROUND))
638 if (autocvar_speedmeter)
639 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
640 if (self.lastground < time - 0.3)
642 self.velocity_x *= (1 - autocvar_sv_friction_on_land);
643 self.velocity_y *= (1 - autocvar_sv_friction_on_land);
645 if (self.jumppadcount > 1)
646 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
647 self.jumppadcount = 0;
650 self.oldvelocity_z = self.velocity_z += mjumpheight;
652 UNSET_ONGROUND(self);
653 self.flags &= ~FL_JUMPRELEASED;
655 animdecide_setaction(self, ANIMACTION_JUMP, TRUE);
657 if (autocvar_g_jump_grunt)
658 PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
660 self.restart_jump = -1; // restart jump anim next time
661 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
665 void CheckWaterJump()
667 // check for a jump-out-of-water
668 makevectors(PHYS_INPUT_ANGLES(self));
669 vector start = self.origin;
672 normalize(v_forward);
673 vector end = start + v_forward*24;
674 traceline (start, end, TRUE, self);
675 if (trace_fraction < 1)
677 start_z = start_z + self.maxs_z - 8;
678 end = start + v_forward*24;
679 self.movedir = trace_plane_normal * -50;
680 traceline(start, end, TRUE, self);
681 if (trace_fraction == 1)
682 { // open at eye level
683 self.velocity_z = 225;
685 self.flags |= FL_WATERJUMP;
686 self.flags &= ~FL_JUMPRELEASED;
687 self.teleport_time = time + 2; // safety net
693 void CheckPlayerJump()
696 if (self.BUTTON_JUMP)
699 self.flags |= FL_JUMPRELEASED;
702 if (self.waterlevel == WATERLEVEL_SWIMMING)
706 float racecar_angle(float forward, float down)
714 float ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
716 float angle_mult = forward / (800 + forward);
719 return ret * angle_mult + 360 * (1 - angle_mult);
721 return ret * angle_mult;
724 void RaceCarPhysics()
727 // using this move type for "big rigs"
728 // the engine does not push the entity!
732 vector angles_save = self.angles;
733 float accel = bound(-1, PHYS_INPUT_MOVEVALUES(self).x / self.stat_sv_maxspeed, 1);
734 float steer = bound(-1, PHYS_INPUT_MOVEVALUES(self).y / self.stat_sv_maxspeed, 1);
736 if (g_bugrigs_reverse_speeding)
740 // back accel is DIGITAL
741 // to prevent speedhack
751 makevectors(self.angles); // new forward direction!
753 if (IS_ONGROUND(self) || g_bugrigs_air_steering)
755 float myspeed = self.velocity * v_forward;
756 float upspeed = self.velocity * v_up;
758 // responsiveness factor for steering and acceleration
759 float f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
760 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
763 if (myspeed < 0 && g_bugrigs_reverse_spinning)
764 steerfactor = -myspeed * g_bugrigs_steer;
766 steerfactor = -myspeed * f * g_bugrigs_steer;
769 if (myspeed < 0 && g_bugrigs_reverse_speeding)
770 accelfactor = g_bugrigs_accel;
772 accelfactor = f * g_bugrigs_accel;
773 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
779 myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
783 if (!g_bugrigs_reverse_speeding)
784 myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
791 myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
795 if (g_bugrigs_reverse_stopping)
798 myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
801 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
802 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
804 self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
805 makevectors(self.angles); // new forward direction!
807 myspeed += accel * accelfactor * PHYS_INPUT_TIMELENGTH;
809 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
813 float myspeed = vlen(self.velocity);
815 // responsiveness factor for steering and acceleration
816 float f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
817 float steerfactor = -myspeed * f;
818 self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
820 rigvel = self.velocity;
821 makevectors(self.angles); // new forward direction!
824 rigvel *= max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * PHYS_INPUT_TIMELENGTH);
825 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
826 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
827 //MAXIMA: solve(total_acceleration(v) = 0, v);
829 if (g_bugrigs_planar_movement)
831 vector rigvel_xy, neworigin, up;
834 rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
835 rigvel_xy = vec2(rigvel);
837 if (g_bugrigs_planar_movement_car_jumping)
840 mt = MOVE_NOMONSTERS;
842 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
843 up = trace_endpos - self.origin;
845 // BUG RIGS: align the move to the surface instead of doing collision testing
847 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * PHYS_INPUT_TIMELENGTH, mt, self);
850 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * PHYS_INPUT_TIMELENGTH, mt, self);
852 if (trace_fraction < 0.5)
855 neworigin = self.origin;
858 neworigin = trace_endpos;
860 if (trace_fraction < 1)
862 // now set angles_x so that the car points parallel to the surface
863 self.angles = vectoangles(
864 '1 0 0' * v_forward_x * trace_plane_normal_z
866 '0 1 0' * v_forward_y * trace_plane_normal_z
868 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
874 // now set angles_x so that the car points forward, but is tilted in velocity direction
875 UNSET_ONGROUND(self);
878 self.velocity = (neworigin - self.origin) * (1.0 / PHYS_INPUT_TIMELENGTH);
879 self.movetype = MOVETYPE_NOCLIP;
883 rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
884 self.velocity = rigvel;
885 self.movetype = MOVETYPE_FLY;
889 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
890 if (trace_fraction != 1)
892 self.angles = vectoangles2(
893 '1 0 0' * v_forward_x * trace_plane_normal_z
895 '0 1 0' * v_forward_y * trace_plane_normal_z
897 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
905 vel_local_x = v_forward * self.velocity;
906 vel_local_y = v_right * self.velocity;
907 vel_local_z = v_up * self.velocity;
909 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
910 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
914 vector vf1, vu1, smoothangles;
915 makevectors(self.angles);
916 float f = bound(0, PHYS_INPUT_TIMELENGTH * g_bugrigs_angle_smoothing, 1);
921 makevectors(angles_save);
922 vf1 = vf1 + v_forward * (1 - f);
923 vu1 = vu1 + v_up * (1 - f);
924 smoothangles = vectoangles2(vf1, vu1);
925 self.angles_x = -smoothangles_x;
926 self.angles_z = smoothangles_z;
930 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
931 .float specialcommand_pos;
932 void SpecialCommand()
938 if (!CheatImpulse(99))
939 print("A hollow voice says \"Plugh\".\n");
945 float speedaward_speed;
946 string speedaward_holder;
947 string speedaward_uid;
949 void race_send_speedaward(float msg)
952 // send the best speed of the round
953 WriteByte(msg, SVC_TEMPENTITY);
954 WriteByte(msg, TE_CSQC_RACE);
955 WriteByte(msg, RACE_NET_SPEED_AWARD);
956 WriteInt24_t(msg, floor(speedaward_speed+0.5));
957 WriteString(msg, speedaward_holder);
962 float speedaward_alltimebest;
963 string speedaward_alltimebest_holder;
964 string speedaward_alltimebest_uid;
966 void race_send_speedaward_alltimebest(float msg)
969 // send the best speed
970 WriteByte(msg, SVC_TEMPENTITY);
971 WriteByte(msg, TE_CSQC_RACE);
972 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
973 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
974 WriteString(msg, speedaward_alltimebest_holder);
978 float PM_check_keepaway(void)
981 return (self.ballcarried && g_keepaway) ? autocvar_g_keepaway_ballcarrier_highspeed : 1;
987 void PM_check_race_movetime(void)
990 self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
991 float f = floor(self.race_movetime_frac);
992 self.race_movetime_frac -= f;
993 self.race_movetime_count += f;
994 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
998 float PM_check_specialcommand(float buttons)
1004 else if (buttons == 1)
1006 else if (buttons == 2)
1008 else if (buttons == 128)
1010 else if (buttons == 256)
1012 else if (buttons == 512)
1014 else if (buttons == 1024)
1019 if (c == substring(specialcommand, self.specialcommand_pos, 1))
1021 self.specialcommand_pos += 1;
1022 if (self.specialcommand_pos >= strlen(specialcommand))
1024 self.specialcommand_pos = 0;
1029 else if (self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
1030 self.specialcommand_pos = 0;
1035 void PM_check_nickspam(void)
1038 if (time >= self.nickspamtime)
1040 if (self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
1042 // slight annoyance for nick change scripts
1043 PHYS_INPUT_MOVEVALUES(self) = -1 * PHYS_INPUT_MOVEVALUES(self);
1044 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
1046 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!
1048 PHYS_INPUT_ANGLES(self)_x = random() * 360;
1049 PHYS_INPUT_ANGLES(self)_y = random() * 360;
1050 // at least I'm not forcing retardedview by also assigning to angles_z
1051 self.fixangle = TRUE;
1057 void PM_check_punch()
1060 if (self.punchangle != '0 0 0')
1062 float f = vlen(self.punchangle) - 10 * PHYS_INPUT_TIMELENGTH;
1064 self.punchangle = normalize(self.punchangle) * f;
1066 self.punchangle = '0 0 0';
1069 if (self.punchvector != '0 0 0')
1071 float f = vlen(self.punchvector) - 30 * PHYS_INPUT_TIMELENGTH;
1073 self.punchvector = normalize(self.punchvector) * f;
1075 self.punchvector = '0 0 0';
1080 void PM_check_spider(void)
1083 if (time >= self.spider_slowness)
1085 self.stat_sv_maxspeed *= 0.5; // half speed while slow from spider
1086 self.stat_sv_airspeedlimit_nonqw *= 0.5;
1090 // predict frozen movement, as frozen players CAN move in some cases
1091 void PM_check_frozen(void)
1093 if (!PHYS_FROZEN(self))
1095 if (PHYS_DODGING_FROZEN
1097 && IS_REAL_CLIENT(self)
1101 PHYS_INPUT_MOVEVALUES(self)_x = bound(-5, PHYS_INPUT_MOVEVALUES(self).x, 5);
1102 PHYS_INPUT_MOVEVALUES(self)_y = bound(-5, PHYS_INPUT_MOVEVALUES(self).y, 5);
1103 PHYS_INPUT_MOVEVALUES(self)_z = bound(-5, PHYS_INPUT_MOVEVALUES(self).z, 5);
1106 PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
1108 vector midpoint = ((self.absmin + self.absmax) * 0.5);
1109 if (pointcontents(midpoint) == CONTENT_WATER)
1111 self.velocity = self.velocity * 0.5;
1113 if (pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
1114 self.velocity_z = 200;
1118 void PM_check_blocked(void)
1121 if (!self.player_blocked)
1123 PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
1124 self.disableclientprediction = 1;
1129 float speedaward_lastsent;
1130 float speedaward_lastupdate;
1131 string GetMapname(void);
1133 void PM_check_race(void)
1136 if not(g_cts || g_race)
1138 if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
1140 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1141 speedaward_holder = self.netname;
1142 speedaward_uid = self.crypto_idfp;
1143 speedaward_lastupdate = time;
1145 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
1147 string rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
1148 race_send_speedaward(MSG_ALL);
1149 speedaward_lastsent = speedaward_speed;
1150 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
1152 speedaward_alltimebest = speedaward_speed;
1153 speedaward_alltimebest_holder = speedaward_holder;
1154 speedaward_alltimebest_uid = speedaward_uid;
1155 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1156 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1157 race_send_speedaward_alltimebest(MSG_ALL);
1163 void PM_check_vortex(void)
1166 float xyspeed = vlen(vec2(self.velocity));
1167 if (self.weapon == WEP_NEX && autocvar_g_balance_nex_charge && autocvar_g_balance_nex_charge_velocity_rate && xyspeed > autocvar_g_balance_nex_charge_minspeed)
1169 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1170 xyspeed = min(xyspeed, autocvar_g_balance_nex_charge_maxspeed);
1171 float f = (xyspeed - autocvar_g_balance_nex_charge_minspeed) / (autocvar_g_balance_nex_charge_maxspeed - autocvar_g_balance_nex_charge_minspeed);
1172 // add the extra charge
1173 self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_velocity_rate * f * PHYS_INPUT_TIMELENGTH);
1178 void PM_fly(float maxspd_mod)
1180 // noclipping or flying
1181 UNSET_ONGROUND(self);
1183 self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
1184 makevectors(PHYS_INPUT_ANGLES(self));
1185 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1186 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1187 + v_right * PHYS_INPUT_MOVEVALUES(self).y
1188 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
1190 vector wishdir = normalize(wishvel);
1191 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod);
1192 if (time >= self.teleport_time)
1193 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
1196 void PM_swim(float maxspd_mod)
1199 UNSET_ONGROUND(self);
1201 float jump = PHYS_INPUT_BUTTONS(self) & 2;
1202 // water jump only in certain situations
1203 // this mimics quakeworld code
1204 if (jump && self.waterlevel == WATERLEVEL_SWIMMING && self.velocity_z >= -180)
1206 vector yawangles = '0 1 0' * PHYS_INPUT_ANGLES(self).y;
1207 makevectors(yawangles);
1208 vector forward = v_forward;
1209 vector spot = self.origin + 24 * forward;
1211 traceline(spot, spot, MOVE_NOMONSTERS, self);
1212 if (trace_startsolid)
1215 traceline(spot, spot, MOVE_NOMONSTERS, self);
1216 if (!trace_startsolid)
1218 self.velocity = forward * 50;
1219 self.velocity_z = 310;
1220 pmove_waterjumptime = 2;
1221 UNSET_ONGROUND(self);
1222 SET_JUMP_HELD(self);
1226 makevectors(PHYS_INPUT_ANGLES(self));
1227 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1228 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1229 + v_right * PHYS_INPUT_MOVEVALUES(self).y
1230 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
1231 if (wishvel == '0 0 0')
1232 wishvel = '0 0 -60'; // drift towards bottom
1234 vector wishdir = normalize(wishvel);
1235 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod) * 0.7;
1237 if (IS_DUCKED(self))
1240 // if (pmove_waterjumptime <= 0) // TODO: use
1243 float f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION;
1244 f = min(max(0, f), 1);
1247 f = wishspeed - self.velocity * wishdir;
1250 float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, f);
1251 self.velocity += accelspeed * wishdir;
1254 // holding jump button swims upward slowly
1258 if (self.watertype & CONTENT_LAVA)
1259 self.velocity_z = 50;
1260 else if (self.watertype & CONTENT_SLIME)
1261 self.velocity_z = 80;
1264 if (IS_NEXUIZ_DERIVED(gamemode))
1266 self.velocity_z = 200;
1269 self.velocity_z = 100;
1274 PM_ClientMovement_Move();
1275 // water acceleration
1276 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
1279 void PM_ladder(float maxspd_mod)
1282 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
1283 UNSET_ONGROUND(self);
1286 g = PHYS_GRAVITY * PHYS_INPUT_TIMELENGTH;
1287 if (PHYS_ENTGRAVITY(self))
1288 g *= PHYS_ENTGRAVITY(self);
1289 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1292 self.velocity_z += g;
1295 self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
1296 makevectors(PHYS_INPUT_ANGLES(self));
1297 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1298 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1299 + v_right * PHYS_INPUT_MOVEVALUES(self).y
1300 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
1301 self.velocity_z += g;
1302 if (self.ladder_entity.classname == "func_water")
1304 float f = vlen(wishvel);
1305 if (f > self.ladder_entity.speed)
1306 wishvel *= (self.ladder_entity.speed / f);
1308 self.watertype = self.ladder_entity.skin;
1309 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1310 if ((self.origin_z + self.view_ofs_z) < f)
1311 self.waterlevel = WATERLEVEL_SUBMERGED;
1312 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1313 self.waterlevel = WATERLEVEL_SWIMMING;
1314 else if ((self.origin_z + self.mins_z + 1) < f)
1315 self.waterlevel = WATERLEVEL_WETFEET;
1318 self.waterlevel = WATERLEVEL_NONE;
1319 self.watertype = CONTENT_EMPTY;
1323 vector wishdir = normalize(wishvel);
1324 float wishspeed = min(vlen(wishvel), self.stat_sv_maxspeed * maxspd_mod);
1325 if (time >= self.teleport_time)
1326 // water acceleration
1327 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE*maxspd_mod, 1, 0, 0, 0);
1331 void PM_jetpack(float maxspd_mod)
1333 //makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1334 makevectors(PHYS_INPUT_ANGLES(self));
1335 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self)_x
1336 + v_right * PHYS_INPUT_MOVEVALUES(self)_y;
1337 // add remaining speed as Z component
1338 float maxairspd = PHYS_MAXAIRSPEED * max(1, maxspd_mod);
1339 // fix speedhacks :P
1340 wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
1341 // add the unused velocity as up component
1344 // if (self.BUTTON_JUMP)
1345 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1347 // it is now normalized, so...
1348 float a_side = PHYS_JETPACK_ACCEL_SIDE;
1349 float a_up = PHYS_JETPACK_ACCEL_UP;
1350 float a_add = PHYS_JETPACK_ANTIGRAVITY * PHYS_GRAVITY;
1352 wishvel_x *= a_side;
1353 wishvel_y *= a_side;
1358 //////////////////////////////////////////////////////////////////////////////////////
1359 // finding the maximum over all vectors of above form
1360 // with wishvel having an absolute value of 1
1361 //////////////////////////////////////////////////////////////////////////////////////
1362 // we're finding the maximum over
1363 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1364 // for z in the range from -1 to 1
1365 //////////////////////////////////////////////////////////////////////////////////////
1366 // maximum is EITHER attained at the single extreme point:
1367 float a_diff = a_side * a_side - a_up * a_up;
1371 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1372 if (f > -1 && f < 1) // can it be attained?
1374 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1375 //print("middle\n");
1378 // OR attained at z = 1:
1379 f = (a_up + a_add) * (a_up + a_add);
1385 // OR attained at z = -1:
1386 f = (a_up - a_add) * (a_up - a_add);
1390 //print("bottom\n");
1393 //////////////////////////////////////////////////////////////////////////////////////
1395 //print("best possible acceleration: ", ftos(best), "\n");
1398 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE, 1);
1399 if (wishvel_z - PHYS_GRAVITY > 0)
1400 fz = bound(0, 1 - self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
1402 fz = bound(0, 1 + self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
1405 fvel = vlen(wishvel);
1408 wishvel_z = (wishvel_z - PHYS_GRAVITY) * fz + PHYS_GRAVITY;
1410 fvel = min(1, vlen(wishvel) / best);
1411 if (PHYS_JETPACK_FUEL && !(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO))
1412 f = min(1, PHYS_AMMO_FUEL(self) / (PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel));
1416 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1418 if (f > 0 && wishvel != '0 0 0')
1420 self.velocity = self.velocity + wishvel * f * PHYS_INPUT_TIMELENGTH;
1421 UNSET_ONGROUND(self);
1424 if (!(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO))
1425 self.ammo_fuel -= PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel * f;
1427 self.items |= IT_USING_JETPACK;
1429 // jetpack also inhibits health regeneration, but only for 1 second
1430 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1435 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1436 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1437 self.velocity_z -= g * 0.5;
1439 self.velocity_z -= g;
1440 PM_ClientMovement_Move();
1441 if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1442 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1443 self.velocity_z -= g * 0.5;
1447 void PM_walk(float buttons_prev, float maxspd_mod)
1450 // we get here if we ran out of ammo
1451 if ((ITEMS(self) & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
1452 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1453 if (!(self.lastflags & FL_ONGROUND))
1455 if (autocvar_speedmeter)
1456 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1457 if (self.lastground < time - 0.3)
1458 self.velocity *= (1 - autocvar_sv_friction_on_land);
1459 if (self.jumppadcount > 1)
1460 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1461 self.jumppadcount = 0;
1465 makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1466 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1467 + v_right * PHYS_INPUT_MOVEVALUES(self).y;
1469 vector wishdir = normalize(wishvel);
1470 float wishspeed = vlen(wishvel);
1472 wishspeed = min(wishspeed, PHYS_MAXSPEED(self) * maxspd_mod);
1473 if (IS_DUCKED(self))
1476 // apply edge friction
1477 float f = vlen(vec2(self.velocity));
1480 // TODO: apply edge friction
1481 // apply ground friction
1482 f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION * ((f < PHYS_STOPSPEED) ? (PHYS_STOPSPEED / f) : 1);
1486 Mathematical analysis time!
1488 Our goal is to invert this mess.
1490 For the two cases we get:
1491 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * (PHYS_STOPSPEED / v0) * PHYS_FRICTION)
1492 = v0 - PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION
1493 v0 = v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION
1495 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1496 v0 = v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1498 These cases would be chosen ONLY if:
1500 v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION < PHYS_STOPSPEED
1501 v < PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1503 v0 >= PHYS_STOPSPEED
1504 v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION) >= PHYS_STOPSPEED
1505 v >= PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1508 float addspeed = wishspeed - self.velocity * wishdir;
1511 float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
1512 self.velocity += accelspeed * wishdir;
1514 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1515 if (!(GAMEPLAYFIX_NOGRAVITYONGROUND))
1516 self.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1);
1517 if (self.velocity * self.velocity)
1518 PM_ClientMovement_Move();
1519 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1520 if (!IS_ONGROUND(self) || !GAMEPLAYFIX_NOGRAVITYONGROUND)
1521 self.velocity_z -= g * 0.5;
1524 void PM_air(float buttons_prev, float maxspd_mod)
1527 // we get here if we ran out of ammo
1528 if ((ITEMS(self) & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && PHYS_AMMO_FUEL(self) < 0.01)
1529 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1531 makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1532 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1533 + v_right * PHYS_INPUT_MOVEVALUES(self).y;
1535 vector wishdir = normalize(wishvel);
1536 float wishspeed = vlen(wishvel);
1539 if (time >= self.teleport_time)
1541 if (pmove_waterjumptime <= 0)
1544 float maxairspd = PHYS_MAXAIRSPEED * min(maxspd_mod, 1);
1546 // apply air speed limit
1547 float airaccelqw = PHYS_AIRACCEL_QW(self);
1548 float wishspeed0 = wishspeed;
1549 wishspeed = min(wishspeed, maxairspd);
1550 if (IS_DUCKED(self))
1552 float airaccel = PHYS_AIRACCELERATE * min(maxspd_mod, 1);
1554 float accelerating = (self.velocity * wishdir > 0);
1555 float wishspeed2 = wishspeed;
1558 if (PHYS_AIRSTOPACCELERATE)
1560 vector curdir = normalize(vec2(self.velocity));
1561 airaccel += (PHYS_AIRSTOPACCELERATE*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1563 // note that for straight forward jumping:
1564 // step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
1565 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1567 // dv/dt = accel * maxspeed (when slow)
1568 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1569 // log dv/dt = logaccel + logmaxspeed (when slow)
1570 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1571 float strafity = IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), -90) + IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), +90); // if one is nonzero, other is always zero
1572 if (PHYS_MAXAIRSTRAFESPEED)
1573 wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED*maxspd_mod));
1574 if (PHYS_AIRSTRAFEACCELERATE)
1575 airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE*maxspd_mod);
1576 if (PHYS_AIRSTRAFEACCEL_QW(self))
1578 (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(self) : PHYS_AIRACCEL_QW(self)) >= 0) ? +1 : -1)
1580 (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(self)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(self))));
1583 if (PHYS_WARSOWBUNNY_TURNACCEL && accelerating && PHYS_INPUT_MOVEVALUES(self).y == 0 && PHYS_INPUT_MOVEVALUES(self).x != 0)
1584 PM_AirAccelerate(wishdir, wishspeed2);
1586 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(self), PHYS_AIRACCEL_SIDEWAYS_FRICTION / maxairspd, PHYS_AIRSPEEDLIMIT_NONQW(self));
1588 if (PHYS_AIRCONTROL)
1589 CPM_PM_Aircontrol(wishdir, wishspeed2);
1591 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1592 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1593 self.velocity_z -= g * 0.5;
1595 self.velocity_z -= g;
1596 PM_ClientMovement_Move();
1597 if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1598 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1599 self.velocity_z -= g * 0.5;
1602 // used for calculating airshots
1603 float PM_is_flying()
1605 if (IS_ONGROUND(self))
1607 if (self.waterlevel >= WATERLEVEL_SWIMMING)
1609 traceline(self.origin, self.origin - '0 0 48', MOVE_NORMAL, self);
1610 return trace_fraction >= 1;
1616 //Con_Printf(" %f", PHYS_INPUT_TIMELENGTH);
1617 if (!(PHYS_INPUT_BUTTONS(self) & 2)) // !jump
1618 UNSET_JUMP_HELD(self); // canjump = true
1619 pmove_waterjumptime -= PHYS_INPUT_TIMELENGTH;
1620 PM_ClientMovement_UpdateStatus();
1624 WarpZone_PlayerPhysics_FixVAngle();
1626 float maxspeed_mod = 1;
1627 maxspeed_mod *= PM_check_keepaway();
1628 maxspeed_mod *= PHYS_HIGHSPEED;
1631 Physics_UpdateStats(maxspeed_mod);
1633 if (self.PlayerPhysplug)
1634 if (self.PlayerPhysplug())
1638 PM_check_race_movetime();
1640 anticheat_physics();
1642 float buttons = PHYS_INPUT_BUTTONS(self);
1644 if (PM_check_specialcommand(buttons))
1649 if (buttons != self.buttons_old || PHYS_INPUT_MOVEVALUES(self) != self.movement_old || PHYS_INPUT_ANGLES(self) != self.v_angle_old)
1650 self.parm_idlesince = time;
1653 float buttons_prev = self.buttons_old;
1654 self.buttons_old = buttons;
1655 self.movement_old = PHYS_INPUT_MOVEVALUES(self);
1656 self.v_angle_old = PHYS_INPUT_ANGLES(self);
1658 PM_check_nickspam();
1662 if (IS_BOT_CLIENT(self))
1664 if (playerdemo_read())
1669 self.items &= ~IT_USING_JETPACK;
1671 if (IS_PLAYER(self))
1675 if (self.race_penalty)
1676 if (time > self.race_penalty)
1677 self.race_penalty = 0;
1680 float not_allowed_to_move = 0;
1682 if (self.race_penalty)
1683 not_allowed_to_move = 1;
1686 if (!autocvar_sv_ready_restart_after_countdown)
1687 if (time < game_starttime)
1688 not_allowed_to_move = 1;
1691 if (not_allowed_to_move)
1693 self.velocity = '0 0 0';
1694 self.movetype = MOVETYPE_NONE;
1696 self.disableclientprediction = 2;
1700 else if (self.disableclientprediction == 2)
1702 if (self.movetype == MOVETYPE_NONE)
1703 self.movetype = MOVETYPE_WALK;
1704 self.disableclientprediction = 0;
1710 if (self.movetype == MOVETYPE_NONE)
1715 // when we get here, disableclientprediction cannot be 2
1716 self.disableclientprediction = 0;
1717 if (time < self.ladder_time)
1718 self.disableclientprediction = 1;
1726 MUTATOR_CALLHOOK(PlayerPhysics);
1734 if (self.in_swamp) {
1735 maxspeed_mod *= self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
1740 // conveyors: first fix velocity
1741 if (self.conveyor.state)
1742 self.velocity -= self.conveyor.movedir;
1746 if (!IS_PLAYER(self))
1748 maxspeed_mod *= autocvar_sv_spectator_speed_multiplier;
1749 if (!self.spectatorspeed)
1750 self.spectatorspeed = maxspeed_mod;
1751 if (self.impulse && self.impulse <= 19 || (self.impulse >= 200 && self.impulse <= 209) || (self.impulse >= 220 && self.impulse <= 229))
1753 if (self.lastclassname != "player")
1755 if (self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209))
1756 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
1757 else if (self.impulse == 11)
1758 self.spectatorspeed = maxspeed_mod;
1759 else if (self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229))
1760 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
1761 else if (self.impulse >= 1 && self.impulse <= 9)
1762 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
1763 } // otherwise just clear
1766 maxspeed_mod *= self.spectatorspeed;
1771 // if dead, behave differently
1772 // in CSQC, physics don't handle dead player
1778 if (!self.fixangle && !g_bugrigs)
1779 self.angles = '0 1 0' * PHYS_INPUT_ANGLES(self).y;
1783 if (IS_ONGROUND(self))
1784 if (IS_PLAYER(self)) // no fall sounds for observers thank you very much
1788 if (self.waterlevel < WATERLEVEL_SWIMMING)
1789 if (time >= self.ladder_time)
1792 self.nextstep = time + 0.3 + random() * 0.1;
1793 trace_dphitq3surfaceflags = 0;
1794 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
1795 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
1797 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
1798 GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
1800 GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
1810 if (IS_PLAYER(self))
1815 if (self.flags & /* FL_WATERJUMP */ 2048)
1817 self.velocity_x = self.movedir_x;
1818 self.velocity_y = self.movedir_y;
1819 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
1821 self.flags &= ~/* FL_WATERJUMP */ 2048;
1822 self.teleport_time = 0;
1827 else if (g_bugrigs && IS_PLAYER(self))
1831 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
1832 PM_fly(maxspeed_mod);
1834 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
1835 PM_swim(maxspeed_mod);
1838 else if (time < self.ladder_time)
1839 PM_ladder(maxspeed_mod);
1842 else if ((ITEMS(self) & IT_JETPACK) && PHYS_BUTTON_HOOK(self) && (!PHYS_JETPACK_FUEL || PHYS_AMMO_FUEL(self) > 0 || (ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO)) && !PHYS_FROZEN(self))
1843 PM_jetpack(maxspeed_mod);
1848 // jump if on ground with jump button pressed but only if it has been
1849 // released at least once since the last jump
1850 if (PHYS_INPUT_BUTTONS(self) & 2)
1852 if (IS_ONGROUND(self) && (!IS_JUMP_HELD(self) || !cvar("cl_movement_track_canjump")))
1854 self.velocity_z += PHYS_JUMPVELOCITY;
1855 UNSET_ONGROUND(self);
1856 SET_JUMP_HELD(self); // canjump = false
1860 UNSET_JUMP_HELD(self); // canjump = true
1862 if (IS_ONGROUND(self))
1863 PM_walk(buttons_prev, maxspeed_mod);
1865 PM_air(buttons_prev, maxspeed_mod);
1869 if (!IS_OBSERVER(self))
1875 if (IS_ONGROUND(self))
1876 self.lastground = time;
1879 // conveyors: then break velocity again
1880 if (self.conveyor.state)
1881 self.velocity += self.conveyor.movedir;
1884 self.lastflags = self.flags;
1885 self.lastclassname = self.classname;
1888 void CSQC_ClientMovement_PlayerMove_Frame()
1890 // if a move is more than 50ms, do it as two moves (matching qwsv)
1891 //Con_Printf("%i ", self.cmd.msec);
1892 if (PHYS_INPUT_TIMELENGTH > 0.0005)
1894 if (PHYS_INPUT_TIMELENGTH > 0.05)
1896 PHYS_INPUT_TIMELENGTH /= 2;
1902 // we REALLY need this handling to happen, even if the move is not executed
1903 if (!(PHYS_INPUT_BUTTONS(self) & 2)) // !jump
1904 UNSET_JUMP_HELD(self); // canjump = true
1907 #undef PHYS_INPUT_ANGLES
1908 #undef PHYS_INPUT_BUTTONS
1909 #undef PHYS_INPUT_TIMELENGTH
1910 #undef PHYS_INPUT_MOVEVALUES
1912 #undef GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE
1913 #undef GAMEPLAYFIX_NOGRAVITYONGROUND
1914 #undef GAMEPLAYFIX_Q2AIRACCELERATE
1921 #undef SET_JUMP_HELD
1922 #undef UNSET_JUMP_HELD
1926 #undef UNSET_ONGROUND
1928 #undef PHYS_ACCELERATE
1929 #undef PHYS_AIRACCEL_QW
1930 #undef PHYS_AIRACCEL_QW_STRETCHFACTOR
1931 #undef PHYS_AIRACCEL_SIDEWAYS_FRICTION
1932 #undef PHYS_AIRACCELERATE
1933 #undef PHYS_AIRCONTROL
1934 #undef PHYS_AIRCONTROL_PENALTY
1935 #undef PHYS_AIRCONTROL_POWER
1936 #undef PHYS_AIRSPEEDLIMIT_NONQW
1937 #undef PHYS_AIRSTOPACCELERATE
1938 #undef PHYS_AIRSTRAFEACCEL_QW
1939 #undef PHYS_AIRSTRAFEACCELERATE
1940 #undef PHYS_EDGEFRICTION
1941 #undef PHYS_ENTGRAVITY
1942 #undef PHYS_FRICTION
1944 #undef PHYS_HIGHSPEED
1945 #undef PHYS_JUMPVELOCITY
1946 #undef PHYS_MAXAIRSPEED
1947 #undef PHYS_MAXAIRSTRAFESPEED
1948 #undef PHYS_MAXSPEED
1949 #undef PHYS_STEPHEIGHT
1950 #undef PHYS_STOPSPEED
1951 #undef PHYS_WARSOWBUNNY_ACCEL
1952 #undef PHYS_WARSOWBUNNY_BACKTOSIDERATIO
1953 #undef PHYS_WARSOWBUNNY_AIRFORWARDACCEL
1954 #undef PHYS_WARSOWBUNNY_TOPSPEED
1955 #undef PHYS_WARSOWBUNNY_TURNACCEL
1959 void SV_PlayerPhysics(void)