11 .float spectatorspeed;
16 .string lastclassname;
18 .float() PlayerPhysplug;
19 float AdjustAirAccelQW(float accelqw, float factor);
22 .float stat_sv_airaccel_qw;
23 .float stat_sv_airstrafeaccel_qw;
24 .float stat_sv_airspeedlimit_nonqw;
25 .float stat_sv_maxspeed;
26 .float stat_movement_highspeed;
28 .float stat_jetpack_accel_side;
29 .float stat_jetpack_accel_up;
30 .float stat_jetpack_antigravity;
31 .float stat_jetpack_fuel;
32 .float stat_jetpack_maxspeed_up;
33 .float stat_jetpack_maxspeed_side;
35 void Physics_AddStats()
37 // g_movementspeed hack
38 addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
39 addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
40 addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
41 addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
42 addstat(STAT_MOVEVARS_HIGHSPEED, AS_FLOAT, stat_movement_highspeed);
45 addstat(STAT_JETPACK_ACCEL_SIDE, AS_FLOAT, stat_jetpack_accel_side);
46 addstat(STAT_JETPACK_ACCEL_UP, AS_FLOAT, stat_jetpack_accel_up);
47 addstat(STAT_JETPACK_ANTIGRAVITY, AS_FLOAT, stat_jetpack_antigravity);
48 addstat(STAT_JETPACK_FUEL, AS_FLOAT, stat_jetpack_fuel);
49 addstat(STAT_JETPACK_MAXSPEED_UP, AS_FLOAT, stat_jetpack_maxspeed_up);
50 addstat(STAT_JETPACK_MAXSPEED_SIDE, AS_FLOAT, stat_jetpack_maxspeed_side);
54 // Client/server mappings
58 #define PHYS_INPUT_ANGLES(s) input_angles
59 #define PHYS_INPUT_BUTTONS(s) input_buttons
60 #define PHYS_INPUT_TIMELENGTH input_timelength
61 #define PHYS_INPUT_MOVEVALUES(s) input_movevalues
63 #define GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE moveflags & MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE
64 #define GAMEPLAYFIX_NOGRAVITYONGROUND cvar("sv_gameplayfix_nogravityonground")
65 #define GAMEPLAYFIX_Q2AIRACCELERATE cvar("sv_gameplayfix_q2airaccelerate")
67 #define IS_DUCKED(s) (s.pmove_flags & PMF_DUCKED)
68 #define SET_DUCKED(s) s.pmove_flags |= PMF_DUCKED
69 #define UNSET_DUCKED(s) s.pmove_flags &= ~PMF_DUCKED
71 #define IS_JUMP_HELD(s) (s.pmove_flags & PMF_JUMP_HELD)
72 #define SET_JUMP_HELD(s) s.pmove_flags |= PMF_JUMP_HELD
73 #define UNSET_JUMP_HELD(s) s.pmove_flags &= ~PMF_JUMP_HELD
75 #define IS_ONGROUND(s) (s.pmove_flags & PMF_ONGROUND)
76 #define SET_ONGROUND(s) s.pmove_flags |= PMF_ONGROUND
77 #define UNSET_ONGROUND(s) s.pmove_flags &= ~PMF_ONGROUND
79 #define ITEMS(s) getstati(STAT_ITEMS, 0, 24)
80 #define PHYS_AMMO_FUEL(s) getstati(STAT_FUEL)
81 #define PHYS_FROZEN(s) getstati(STAT_FROZEN)
83 #define PHYS_ACCELERATE getstatf(STAT_MOVEVARS_ACCELERATE)
84 #define PHYS_AIRACCEL_QW(s) getstatf(STAT_MOVEVARS_AIRACCEL_QW)
85 #define PHYS_AIRACCEL_QW_STRETCHFACTOR(s) getstatf(STAT_MOVEVARS_AIRACCEL_QW_STRETCHFACTOR)
86 #define PHYS_AIRACCEL_SIDEWAYS_FRICTION getstatf(STAT_MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION)
87 #define PHYS_AIRACCELERATE getstatf(STAT_MOVEVARS_AIRACCELERATE)
88 #define PHYS_AIRCONTROL getstatf(STAT_MOVEVARS_AIRCONTROL)
89 #define PHYS_AIRCONTROL_PENALTY getstatf(STAT_MOVEVARS_AIRCONTROL_PENALTY)
90 #define PHYS_AIRCONTROL_POWER getstatf(STAT_MOVEVARS_AIRCONTROL_POWER)
91 #define PHYS_AIRSPEEDLIMIT_NONQW(s) getstatf(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW)
92 #define PHYS_AIRSTOPACCELERATE getstatf(STAT_MOVEVARS_AIRSTOPACCELERATE)
93 #define PHYS_AIRSTRAFEACCEL_QW(s) getstatf(STAT_MOVEVARS_AIRSTRAFEACCEL_QW)
94 #define PHYS_AIRSTRAFEACCELERATE getstatf(STAT_MOVEVARS_AIRSTRAFEACCELERATE)
95 #define PHYS_ENTGRAVITY(s) getstatf(STAT_MOVEVARS_ENTGRAVITY)
96 #define PHYS_FRICTION getstatf(STAT_MOVEVARS_FRICTION)
97 #define PHYS_GRAVITY getstatf(STAT_MOVEVARS_GRAVITY)
98 #define PHYS_HIGHSPEED getstatf(STAT_MOVEVARS_HIGHSPEED)
99 #define PHYS_JUMPVELOCITY getstatf(STAT_MOVEVARS_JUMPVELOCITY)
100 #define PHYS_MAXAIRSPEED getstatf(STAT_MOVEVARS_MAXAIRSPEED)
101 #define PHYS_MAXAIRSTRAFESPEED getstatf(STAT_MOVEVARS_MAXAIRSTRAFESPEED)
102 #define PHYS_MAXSPEED(s) getstatf(STAT_MOVEVARS_MAXSPEED)
103 #define PHYS_STEPHEIGHT getstatf(STAT_MOVEVARS_STEPHEIGHT)
104 #define PHYS_STOPSPEED getstatf(STAT_MOVEVARS_STOPSPEED)
105 #define PHYS_WARSOWBUNNY_ACCEL getstatf(STAT_MOVEVARS_WARSOWBUNNY_ACCEL)
106 #define PHYS_WARSOWBUNNY_BACKTOSIDERATIO getstatf(STAT_MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO)
107 #define PHYS_WARSOWBUNNY_AIRFORWARDACCEL getstatf(STAT_MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL)
108 #define PHYS_WARSOWBUNNY_TOPSPEED getstatf(STAT_MOVEVARS_WARSOWBUNNY_TOPSPEED)
109 #define PHYS_WARSOWBUNNY_TURNACCEL getstatf(STAT_MOVEVARS_WARSOWBUNNY_TURNACCEL)
111 #define PHYS_JETPACK_ACCEL_UP getstatf(STAT_JETPACK_ACCEL_UP)
112 #define PHYS_JETPACK_ACCEL_SIDE getstatf(STAT_JETPACK_ACCEL_SIDE)
113 #define PHYS_JETPACK_ANTIGRAVITY getstatf(STAT_JETPACK_ANTIGRAVITY)
114 #define PHYS_JETPACK_FUEL getstatf(STAT_JETPACK_FUEL)
115 #define PHYS_JETPACK_MAXSPEED_UP getstatf(STAT_JETPACK_MAXSPEED_UP)
116 #define PHYS_JETPACK_MAXSPEED_SIDE getstatf(STAT_JETPACK_MAXSPEED_SIDE)
118 #define PHYS_DODGING_FROZEN getstati(STAT_DODGING_FROZEN)
120 #define PHYS_BUTTON_HOOK(s) (input_buttons & 32)
125 #define PHYS_INPUT_ANGLES(s) s.v_angle
127 #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))
128 #define PHYS_INPUT_TIMELENGTH frametime
129 #define PHYS_INPUT_MOVEVALUES(s) s.movement
131 #define GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE autocvar_sv_gameplayfix_gravityunaffectedbyticrate
132 #define GAMEPLAYFIX_NOGRAVITYONGROUND cvar("sv_gameplayfix_nogravityonground")
133 #define GAMEPLAYFIX_Q2AIRACCELERATE autocvar_sv_gameplayfix_q2airaccelerate
135 #define IS_DUCKED(s) s.crouch
136 #define SET_DUCKED(s) s.crouch = TRUE
137 #define UNSET_DUCKED(s) s.crouch = FALSE
139 #define IS_JUMP_HELD(s) (s.flags & FL_JUMPRELEASED == 0)
140 #define SET_JUMP_HELD(s) s.flags &= ~FL_JUMPRELEASED
141 #define UNSET_JUMP_HELD(s) s.flags |= FL_JUMPRELEASED
143 #define IS_ONGROUND(s) (s.flags & FL_ONGROUND)
144 #define SET_ONGROUND(s) s.flags |= FL_ONGROUND
145 #define UNSET_ONGROUND(s) s.flags &= ~FL_ONGROUND
147 #define ITEMS(s) s.items
148 #define PHYS_AMMO_FUEL(s) s.ammo_fuel
149 #define PHYS_FROZEN(s) s.frozen
151 #define PHYS_ACCELERATE autocvar_sv_accelerate
152 #define PHYS_AIRACCEL_QW(s) s.stat_sv_airaccel_qw
153 #define PHYS_AIRACCEL_QW_STRETCHFACTOR(s) autocvar_sv_airaccel_qw_stretchfactor
154 #define PHYS_AIRACCEL_SIDEWAYS_FRICTION autocvar_sv_airaccel_sideways_friction
155 #define PHYS_AIRACCELERATE autocvar_sv_airaccelerate
156 #define PHYS_AIRCONTROL autocvar_sv_aircontrol
157 #define PHYS_AIRCONTROL_PENALTY autocvar_sv_aircontrol_penalty
158 #define PHYS_AIRCONTROL_POWER autocvar_sv_aircontrol_power
159 #define PHYS_AIRSPEEDLIMIT_NONQW(s) s.stat_sv_airspeedlimit_nonqw
160 #define PHYS_AIRSTOPACCELERATE autocvar_sv_airstopaccelerate
161 #define PHYS_AIRSTRAFEACCEL_QW(s) s.stat_sv_airstrafeaccel_qw
162 #define PHYS_AIRSTRAFEACCELERATE autocvar_sv_airstrafeaccelerate
163 #define PHYS_ENTGRAVITY(s) s.gravity
164 #define PHYS_FRICTION autocvar_sv_friction
165 #define PHYS_GRAVITY autocvar_sv_gravity
166 #define PHYS_HIGHSPEED autocvar_g_movement_highspeed
167 #define PHYS_JUMPVELOCITY autocvar_sv_jumpvelocity
168 #define PHYS_MAXAIRSPEED autocvar_sv_maxairspeed
169 #define PHYS_MAXAIRSTRAFESPEED autocvar_sv_maxairstrafespeed
170 #define PHYS_MAXSPEED(s) s.stat_sv_maxspeed
171 #define PHYS_STEPHEIGHT autocvar_sv_stepheight
172 #define PHYS_STOPSPEED autocvar_sv_stopspeed
173 #define PHYS_WARSOWBUNNY_ACCEL autocvar_sv_warsowbunny_accel
174 #define PHYS_WARSOWBUNNY_BACKTOSIDERATIO autocvar_sv_warsowbunny_backtosideratio
175 #define PHYS_WARSOWBUNNY_AIRFORWARDACCEL autocvar_sv_warsowbunny_airforwardaccel
176 #define PHYS_WARSOWBUNNY_TOPSPEED autocvar_sv_warsowbunny_topspeed
177 #define PHYS_WARSOWBUNNY_TURNACCEL autocvar_sv_warsowbunny_turnaccel
179 #define PHYS_JETPACK_ACCEL_UP autocvar_g_jetpack_acceleration_up
180 #define PHYS_JETPACK_ACCEL_SIDE autocvar_g_jetpack_acceleration_side
181 #define PHYS_JETPACK_ANTIGRAVITY autocvar_g_jetpack_antigravity
182 #define PHYS_JETPACK_FUEL autocvar_g_jetpack_fuel
183 #define PHYS_JETPACK_MAXSPEED_UP autocvar_g_jetpack_maxspeed_up
184 #define PHYS_JETPACK_MAXSPEED_SIDE autocvar_g_jetpack_maxspeed_side
186 #define PHYS_DODGING_FROZEN autocvar_sv_dodging_frozen
188 #define PHYS_BUTTON_HOOK(s) s.BUTTON_HOOK
191 void Physics_UpdateStats(float maxspd_mod)
193 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
194 if (autocvar_sv_airstrafeaccel_qw)
195 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
197 self.stat_sv_airstrafeaccel_qw = 0;
198 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
199 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
200 self.stat_movement_highspeed = PHYS_HIGHSPEED; // TODO: remove this!
202 self.stat_jetpack_antigravity = PHYS_JETPACK_ANTIGRAVITY;
203 self.stat_jetpack_accel_up = PHYS_JETPACK_ACCEL_UP;
204 self.stat_jetpack_accel_side = PHYS_JETPACK_ACCEL_SIDE;
205 self.stat_jetpack_maxspeed_side = PHYS_JETPACK_MAXSPEED_SIDE;
206 self.stat_jetpack_maxspeed_up = PHYS_JETPACK_MAXSPEED_UP;
207 self.stat_jetpack_fuel = PHYS_JETPACK_FUEL;
211 float IsMoveInDirection(vector mv, float angle) // key mix factor
213 if (mv_x == 0 && mv_y == 0)
214 return 0; // avoid division by zero
215 angle -= RAD2DEG * atan2(mv_y, mv_x);
216 angle = remainder(angle, 360) / 45;
217 return angle > 1 ? 0 : angle < -1 ? 0 : 1 - fabs(angle);
220 float GeomLerp(float a, float lerp, float b)
222 return a == 0 ? (lerp < 1 ? 0 : b)
223 : b == 0 ? (lerp > 0 ? 0 : a)
224 : a * pow(fabs(b / a), lerp);
227 noref float pmove_waterjumptime;
229 const float unstick_count = 27;
230 vector unstick_offsets[unstick_count] =
232 // 1 no nudge (just return the original if this test passes)
235 ' 0.000 0.000 0.125', '0.000 0.000 -0.125',
236 '-0.125 0.000 0.000', '0.125 0.000 0.000',
237 ' 0.000 -0.125 0.000', '0.000 0.125 0.000',
238 // 4 diagonal flat nudges
239 '-0.125 -0.125 0.000', '0.125 -0.125 0.000',
240 '-0.125 0.125 0.000', '0.125 0.125 0.000',
241 // 8 diagonal upward nudges
242 '-0.125 0.000 0.125', '0.125 0.000 0.125',
243 ' 0.000 -0.125 0.125', '0.000 0.125 0.125',
244 '-0.125 -0.125 0.125', '0.125 -0.125 0.125',
245 '-0.125 0.125 0.125', '0.125 0.125 0.125',
246 // 8 diagonal downward nudges
247 '-0.125 0.000 -0.125', '0.125 0.000 -0.125',
248 ' 0.000 -0.125 -0.125', '0.000 0.125 -0.125',
249 '-0.125 -0.125 -0.125', '0.125 -0.125 -0.125',
250 '-0.125 0.125 -0.125', '0.125 0.125 -0.125',
253 void PM_ClientMovement_Unstick()
256 for (i = 0; i < unstick_count; i++)
258 vector neworigin = unstick_offsets[i] + self.origin;
259 tracebox(neworigin, PL_CROUCH_MIN, PL_CROUCH_MAX, neworigin, MOVE_NORMAL, self);
260 if (!trace_startsolid)
262 self.origin = neworigin;
268 void PM_ClientMovement_UpdateStatus()
270 // make sure player is not stuck
271 PM_ClientMovement_Unstick();
274 if (PHYS_INPUT_BUTTONS(self) & 16)
276 // wants to crouch, this always works..
277 if (!IS_DUCKED(self))
282 // wants to stand, if currently crouching we need to check for a
286 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, MOVE_NORMAL, self);
287 if (!trace_startsolid)
293 vector origin1 = self.origin + '0 0 1';
294 vector origin2 = self.origin - '0 0 1';
296 tracebox(origin1, self.mins, self.maxs, origin2, MOVE_NORMAL, self);
297 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
301 // this code actually "predicts" an impact; so let's clip velocity first
302 float f = dotproduct(self.velocity, trace_plane_normal);
303 if (f < 0) // only if moving downwards actually
304 self.velocity -= f * trace_plane_normal;
307 UNSET_ONGROUND(self);
309 // set watertype/waterlevel
310 origin1 = self.origin;
311 origin1_z += self.mins_z + 1;
312 self.waterlevel = WATERLEVEL_NONE;
314 self.watertype = (pointcontents(origin1) == CONTENT_WATER);
318 self.waterlevel = WATERLEVEL_WETFEET;
319 origin1_z = self.origin_z + (self.mins_z + self.maxs_z) * 0.5;
320 if(pointcontents(origin1) == CONTENT_WATER)
322 self.waterlevel = WATERLEVEL_SWIMMING;
323 origin1_z = self.origin_z + 22;
324 if(pointcontents(origin1) == CONTENT_WATER)
325 self.waterlevel = WATERLEVEL_SUBMERGED;
329 if(IS_ONGROUND(self) || self.velocity_z <= 0 || pmove_waterjumptime <= 0)
330 pmove_waterjumptime = 0;
333 void PM_ClientMovement_Move()
336 float t = PHYS_INPUT_TIMELENGTH;
337 vector primalvelocity = self.velocity;
338 PM_ClientMovement_UpdateStatus();
340 for (bump = 0; bump < 8 && self.velocity * self.velocity > 0; bump++)
342 vector neworigin = self.origin + t * self.velocity;
343 tracebox(self.origin, self.mins, self.maxs, neworigin, MOVE_NORMAL, self);
344 float old_trace1_fraction = trace_fraction;
345 vector old_trace1_endpos = trace_endpos;
346 vector old_trace1_plane_normal = trace_plane_normal;
347 if (trace_fraction < 1 && trace_plane_normal_z == 0)
349 // may be a step or wall, try stepping up
350 // first move forward at a higher level
351 vector currentorigin2 = self.origin;
352 currentorigin2_z += PHYS_STEPHEIGHT;
353 vector neworigin2 = neworigin;
354 neworigin2_z = self.origin_z + PHYS_STEPHEIGHT;
355 tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
356 if (!trace_startsolid)
358 // then move down from there
359 currentorigin2 = trace_endpos;
360 neworigin2 = trace_endpos;
361 neworigin2_z = self.origin_z;
362 float old_trace2_fraction = trace_fraction;
363 vector old_trace2_plane_normal = trace_plane_normal;
364 tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
365 //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]);
366 // accept the new trace if it made some progress
367 if (fabs(trace_endpos_x - old_trace1_endpos_x) >= 0.03125 || fabs(trace_endpos_y - old_trace1_endpos_y) >= 0.03125)
369 trace_fraction = old_trace2_fraction;
370 trace_endpos = trace_endpos;
371 trace_plane_normal = old_trace2_plane_normal;
375 trace_fraction = old_trace1_fraction;
376 trace_endpos = old_trace1_endpos;
377 trace_plane_normal = old_trace1_plane_normal;
382 // check if it moved at all
383 if (trace_fraction >= 0.001)
384 self.origin = trace_endpos;
386 // check if it moved all the way
387 if (trace_fraction == 1)
390 // this is only really needed for nogravityonground combined with gravityunaffectedbyticrate
391 // <LordHavoc> I'm pretty sure I commented it out solely because it seemed redundant
392 // this got commented out in a change that supposedly makes the code match QW better
393 // so if this is broken, maybe put it in an if (cls.protocol != PROTOCOL_QUAKEWORLD) block
394 if (trace_plane_normal_z > 0.7)
397 t -= t * trace_fraction;
399 float f = dotproduct(self.velocity, trace_plane_normal);
400 self.velocity -= f * trace_plane_normal;
402 if (pmove_waterjumptime > 0)
403 self.velocity = primalvelocity;
407 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
411 // this doesn't play well with analog input
412 if (PHYS_INPUT_MOVEVALUES(self).x == 0 || PHYS_INPUT_MOVEVALUES(self).y != 0)
413 return; // can't control movement if not moving forward or backward
416 k = 32 * (2 * IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), 0) - 1);
421 k *= bound(0, wishspeed / PHYS_MAXAIRSPEED, 1);
423 float zspeed = self.velocity_z;
425 float xyspeed = vlen(self.velocity);
426 self.velocity = normalize(self.velocity);
428 float dot = self.velocity * wishdir;
430 if (dot > 0) // we can't change direction while slowing down
432 k *= pow(dot, PHYS_AIRCONTROL_POWER)*PHYS_INPUT_TIMELENGTH;
433 xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY * sqrt(max(0, 1 - dot*dot)) * k/32);
434 k *= PHYS_AIRCONTROL;
435 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
438 self.velocity = self.velocity * xyspeed;
439 self.velocity_z = zspeed;
442 float AdjustAirAccelQW(float accelqw, float factor)
444 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
447 // example config for alternate speed clamping:
448 // sv_airaccel_qw 0.8
449 // sv_airaccel_sideways_friction 0
450 // prvm_globalset server speedclamp_mode 1
452 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
454 float speedclamp = stretchfactor > 0 ? stretchfactor
455 : accelqw < 0 ? 1 // full clamping, no stretch
458 accelqw = fabs(accelqw);
460 if (GAMEPLAYFIX_Q2AIRACCELERATE)
461 wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
463 float vel_straight = self.velocity * wishdir;
464 float vel_z = self.velocity_z;
465 vector vel_xy = vec2(self.velocity);
466 vector vel_perpend = vel_xy - vel_straight * wishdir;
468 float step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
470 float vel_xy_current = vlen(vel_xy);
472 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
473 float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
474 float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
475 vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
476 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
478 if (sidefric < 0 && (vel_perpend*vel_perpend))
479 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
481 float f = max(0, 1 + PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
482 float fmin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
484 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
485 // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
486 // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
487 // obviously, this cannot be
493 vel_perpend *= max(fmin, f);
497 vel_perpend *= max(0, 1 - PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
499 vel_xy = vel_straight * wishdir + vel_perpend;
503 float vel_xy_preclamp;
504 vel_xy_preclamp = vlen(vel_xy);
505 if (vel_xy_preclamp > 0) // prevent division by zero
507 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
508 if (vel_xy_current < vel_xy_preclamp)
509 vel_xy *= (vel_xy_current / vel_xy_preclamp);
513 self.velocity = vel_xy + vel_z * '0 0 1';
516 void PM_AirAccelerate(vector wishdir, float wishspeed)
521 vector curvel = self.velocity;
523 float curspeed = vlen(curvel);
525 if (wishspeed > curspeed * 1.01)
526 wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH);
529 float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED - PHYS_MAXSPEED(self)));
530 wishspeed = max(curspeed, PHYS_MAXSPEED(self)) + PHYS_WARSOWBUNNY_ACCEL * f * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH;
532 vector wishvel = wishdir * wishspeed;
533 vector acceldir = wishvel - curvel;
534 float addspeed = vlen(acceldir);
535 acceldir = normalize(acceldir);
537 float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH);
539 if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO < 1)
541 vector curdir = normalize(curvel);
542 float dot = acceldir * curdir;
544 acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO) * dot * curdir;
547 self.velocity += accelspeed * acceldir;
555 When you press the jump key
558 void PlayerJump (void)
561 if (PHYS_FROZEN(self))
562 return; // no jumping in freezetag when frozen
564 if (self.player_blocked)
565 return; // no jumping while blocked
567 float doublejump = FALSE;
568 float mjumpheight = PHYS_JUMPVELOCITY;
570 player_multijump = doublejump;
571 player_jumpheight = mjumpheight;
572 if (MUTATOR_CALLHOOK(PlayerJump))
575 doublejump = player_multijump;
576 mjumpheight = player_jumpheight;
578 if (autocvar_sv_doublejump)
580 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
581 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
585 // we MUST clip velocity here!
587 f = self.velocity * trace_plane_normal;
589 self.velocity -= f * trace_plane_normal;
593 if (self.waterlevel >= WATERLEVEL_SWIMMING)
595 self.velocity_z = self.stat_sv_maxspeed * 0.7;
600 if (!IS_ONGROUND(self))
603 if (self.cvar_cl_movement_track_canjump)
604 if (!(self.flags & FL_JUMPRELEASED))
607 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
608 // velocity bounds. Final velocity is bound between (jumpheight *
609 // min + jumpheight) and (jumpheight * max + jumpheight);
611 if (autocvar_sv_jumpspeedcap_min != "")
613 float minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min);
615 if (self.velocity_z < minjumpspeed)
616 mjumpheight += minjumpspeed - self.velocity_z;
619 if (autocvar_sv_jumpspeedcap_max != "")
621 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
622 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
624 if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && autocvar_sv_jumpspeedcap_max_disable_on_ramps))
626 float maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max);
628 if (self.velocity_z > maxjumpspeed)
629 mjumpheight -= self.velocity_z - maxjumpspeed;
633 if (!(self.lastflags & FL_ONGROUND))
635 if (autocvar_speedmeter)
636 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
637 if (self.lastground < time - 0.3)
639 self.velocity_x *= (1 - autocvar_sv_friction_on_land);
640 self.velocity_y *= (1 - autocvar_sv_friction_on_land);
642 if (self.jumppadcount > 1)
643 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
644 self.jumppadcount = 0;
647 self.oldvelocity_z = self.velocity_z += mjumpheight;
649 UNSET_ONGROUND(self);
650 self.flags &= ~FL_JUMPRELEASED;
652 animdecide_setaction(self, ANIMACTION_JUMP, TRUE);
654 if (autocvar_g_jump_grunt)
655 PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
657 self.restart_jump = -1; // restart jump anim next time
658 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
662 void CheckWaterJump()
664 // check for a jump-out-of-water
665 makevectors(PHYS_INPUT_ANGLES(self));
666 vector start = self.origin;
669 normalize(v_forward);
670 vector end = start + v_forward*24;
671 traceline (start, end, TRUE, self);
672 if (trace_fraction < 1)
674 start_z = start_z + self.maxs_z - 8;
675 end = start + v_forward*24;
676 self.movedir = trace_plane_normal * -50;
677 traceline(start, end, TRUE, self);
678 if (trace_fraction == 1)
679 { // open at eye level
680 self.velocity_z = 225;
682 self.flags |= FL_WATERJUMP;
683 self.flags &= ~FL_JUMPRELEASED;
684 self.teleport_time = time + 2; // safety net
690 void CheckPlayerJump()
693 if (self.BUTTON_JUMP)
696 self.flags |= FL_JUMPRELEASED;
699 if (self.waterlevel == WATERLEVEL_SWIMMING)
703 float racecar_angle(float forward, float down)
711 float ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
713 float angle_mult = forward / (800 + forward);
716 return ret * angle_mult + 360 * (1 - angle_mult);
718 return ret * angle_mult;
721 void RaceCarPhysics()
724 // using this move type for "big rigs"
725 // the engine does not push the entity!
729 vector angles_save = self.angles;
730 float accel = bound(-1, PHYS_INPUT_MOVEVALUES(self).x / self.stat_sv_maxspeed, 1);
731 float steer = bound(-1, PHYS_INPUT_MOVEVALUES(self).y / self.stat_sv_maxspeed, 1);
733 if (g_bugrigs_reverse_speeding)
737 // back accel is DIGITAL
738 // to prevent speedhack
748 makevectors(self.angles); // new forward direction!
750 if (IS_ONGROUND(self) || g_bugrigs_air_steering)
752 float myspeed = self.velocity * v_forward;
753 float upspeed = self.velocity * v_up;
755 // responsiveness factor for steering and acceleration
756 float f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
757 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
760 if (myspeed < 0 && g_bugrigs_reverse_spinning)
761 steerfactor = -myspeed * g_bugrigs_steer;
763 steerfactor = -myspeed * f * g_bugrigs_steer;
766 if (myspeed < 0 && g_bugrigs_reverse_speeding)
767 accelfactor = g_bugrigs_accel;
769 accelfactor = f * g_bugrigs_accel;
770 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
776 myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
780 if (!g_bugrigs_reverse_speeding)
781 myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
788 myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
792 if (g_bugrigs_reverse_stopping)
795 myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
798 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
799 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
801 self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
802 makevectors(self.angles); // new forward direction!
804 myspeed += accel * accelfactor * PHYS_INPUT_TIMELENGTH;
806 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
810 float myspeed = vlen(self.velocity);
812 // responsiveness factor for steering and acceleration
813 float f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
814 float steerfactor = -myspeed * f;
815 self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
817 rigvel = self.velocity;
818 makevectors(self.angles); // new forward direction!
821 rigvel *= max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * PHYS_INPUT_TIMELENGTH);
822 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
823 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
824 //MAXIMA: solve(total_acceleration(v) = 0, v);
826 if (g_bugrigs_planar_movement)
828 vector rigvel_xy, neworigin, up;
831 rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
832 rigvel_xy = vec2(rigvel);
834 if (g_bugrigs_planar_movement_car_jumping)
837 mt = MOVE_NOMONSTERS;
839 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
840 up = trace_endpos - self.origin;
842 // BUG RIGS: align the move to the surface instead of doing collision testing
844 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * PHYS_INPUT_TIMELENGTH, mt, self);
847 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * PHYS_INPUT_TIMELENGTH, mt, self);
849 if (trace_fraction < 0.5)
852 neworigin = self.origin;
855 neworigin = trace_endpos;
857 if (trace_fraction < 1)
859 // now set angles_x so that the car points parallel to the surface
860 self.angles = vectoangles(
861 '1 0 0' * v_forward_x * trace_plane_normal_z
863 '0 1 0' * v_forward_y * trace_plane_normal_z
865 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
871 // now set angles_x so that the car points forward, but is tilted in velocity direction
872 UNSET_ONGROUND(self);
875 self.velocity = (neworigin - self.origin) * (1.0 / PHYS_INPUT_TIMELENGTH);
876 self.movetype = MOVETYPE_NOCLIP;
880 rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
881 self.velocity = rigvel;
882 self.movetype = MOVETYPE_FLY;
886 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
887 if (trace_fraction != 1)
889 self.angles = vectoangles2(
890 '1 0 0' * v_forward_x * trace_plane_normal_z
892 '0 1 0' * v_forward_y * trace_plane_normal_z
894 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
902 vel_local_x = v_forward * self.velocity;
903 vel_local_y = v_right * self.velocity;
904 vel_local_z = v_up * self.velocity;
906 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
907 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
911 vector vf1, vu1, smoothangles;
912 makevectors(self.angles);
913 float f = bound(0, PHYS_INPUT_TIMELENGTH * g_bugrigs_angle_smoothing, 1);
918 makevectors(angles_save);
919 vf1 = vf1 + v_forward * (1 - f);
920 vu1 = vu1 + v_up * (1 - f);
921 smoothangles = vectoangles2(vf1, vu1);
922 self.angles_x = -smoothangles_x;
923 self.angles_z = smoothangles_z;
927 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
928 .float specialcommand_pos;
929 void SpecialCommand()
935 if (!CheatImpulse(99))
936 print("A hollow voice says \"Plugh\".\n");
942 float speedaward_speed;
943 string speedaward_holder;
944 string speedaward_uid;
946 void race_send_speedaward(float msg)
949 // send the best speed of the round
950 WriteByte(msg, SVC_TEMPENTITY);
951 WriteByte(msg, TE_CSQC_RACE);
952 WriteByte(msg, RACE_NET_SPEED_AWARD);
953 WriteInt24_t(msg, floor(speedaward_speed+0.5));
954 WriteString(msg, speedaward_holder);
959 float speedaward_alltimebest;
960 string speedaward_alltimebest_holder;
961 string speedaward_alltimebest_uid;
963 void race_send_speedaward_alltimebest(float msg)
966 // send the best speed
967 WriteByte(msg, SVC_TEMPENTITY);
968 WriteByte(msg, TE_CSQC_RACE);
969 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
970 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
971 WriteString(msg, speedaward_alltimebest_holder);
975 float PM_check_keepaway(void)
978 return (self.ballcarried && g_keepaway) ? autocvar_g_keepaway_ballcarrier_highspeed : 1;
984 void PM_check_race_movetime(void)
987 self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
988 float f = floor(self.race_movetime_frac);
989 self.race_movetime_frac -= f;
990 self.race_movetime_count += f;
991 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
995 float PM_check_specialcommand(float buttons)
1001 else if (buttons == 1)
1003 else if (buttons == 2)
1005 else if (buttons == 128)
1007 else if (buttons == 256)
1009 else if (buttons == 512)
1011 else if (buttons == 1024)
1016 if (c == substring(specialcommand, self.specialcommand_pos, 1))
1018 self.specialcommand_pos += 1;
1019 if (self.specialcommand_pos >= strlen(specialcommand))
1021 self.specialcommand_pos = 0;
1026 else if (self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
1027 self.specialcommand_pos = 0;
1032 void PM_check_nickspam(void)
1035 if (time >= self.nickspamtime)
1037 if (self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
1039 // slight annoyance for nick change scripts
1040 PHYS_INPUT_MOVEVALUES(self) = -1 * PHYS_INPUT_MOVEVALUES(self);
1041 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
1043 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!
1045 PHYS_INPUT_ANGLES(self)_x = random() * 360;
1046 PHYS_INPUT_ANGLES(self)_y = random() * 360;
1047 // at least I'm not forcing retardedview by also assigning to angles_z
1048 self.fixangle = TRUE;
1054 void PM_check_punch()
1057 if (self.punchangle != '0 0 0')
1059 float f = vlen(self.punchangle) - 10 * PHYS_INPUT_TIMELENGTH;
1061 self.punchangle = normalize(self.punchangle) * f;
1063 self.punchangle = '0 0 0';
1066 if (self.punchvector != '0 0 0')
1068 float f = vlen(self.punchvector) - 30 * PHYS_INPUT_TIMELENGTH;
1070 self.punchvector = normalize(self.punchvector) * f;
1072 self.punchvector = '0 0 0';
1077 void PM_check_spider(void)
1080 if (time >= self.spider_slowness)
1082 self.stat_sv_maxspeed *= 0.5; // half speed while slow from spider
1083 self.stat_sv_airspeedlimit_nonqw *= 0.5;
1087 // predict frozen movement, as frozen players CAN move in some cases
1088 void PM_check_frozen(void)
1090 if (!PHYS_FROZEN(self))
1092 if (PHYS_DODGING_FROZEN
1094 && IS_REAL_CLIENT(self)
1098 PHYS_INPUT_MOVEVALUES(self)_x = bound(-5, PHYS_INPUT_MOVEVALUES(self).x, 5);
1099 PHYS_INPUT_MOVEVALUES(self)_y = bound(-5, PHYS_INPUT_MOVEVALUES(self).y, 5);
1100 PHYS_INPUT_MOVEVALUES(self)_z = bound(-5, PHYS_INPUT_MOVEVALUES(self).z, 5);
1103 PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
1105 vector midpoint = ((self.absmin + self.absmax) * 0.5);
1106 if (pointcontents(midpoint) == CONTENT_WATER)
1108 self.velocity = self.velocity * 0.5;
1110 if (pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
1111 self.velocity_z = 200;
1115 void PM_check_blocked(void)
1118 if (!self.player_blocked)
1120 PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
1121 self.disableclientprediction = 1;
1126 float speedaward_lastsent;
1127 float speedaward_lastupdate;
1128 string GetMapname(void);
1130 void PM_check_race(void)
1133 if not(g_cts || g_race)
1135 if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
1137 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1138 speedaward_holder = self.netname;
1139 speedaward_uid = self.crypto_idfp;
1140 speedaward_lastupdate = time;
1142 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
1144 string rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
1145 race_send_speedaward(MSG_ALL);
1146 speedaward_lastsent = speedaward_speed;
1147 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
1149 speedaward_alltimebest = speedaward_speed;
1150 speedaward_alltimebest_holder = speedaward_holder;
1151 speedaward_alltimebest_uid = speedaward_uid;
1152 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1153 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1154 race_send_speedaward_alltimebest(MSG_ALL);
1160 void PM_check_vortex(void)
1163 float xyspeed = vlen(vec2(self.velocity));
1164 if (self.weapon == WEP_NEX && autocvar_g_balance_nex_charge && autocvar_g_balance_nex_charge_velocity_rate && xyspeed > autocvar_g_balance_nex_charge_minspeed)
1166 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1167 xyspeed = min(xyspeed, autocvar_g_balance_nex_charge_maxspeed);
1168 float f = (xyspeed - autocvar_g_balance_nex_charge_minspeed) / (autocvar_g_balance_nex_charge_maxspeed - autocvar_g_balance_nex_charge_minspeed);
1169 // add the extra charge
1170 self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_velocity_rate * f * PHYS_INPUT_TIMELENGTH);
1175 void PM_fly(float maxspd_mod)
1177 // noclipping or flying
1178 UNSET_ONGROUND(self);
1180 self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
1181 makevectors(PHYS_INPUT_ANGLES(self));
1182 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1183 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1184 + v_right * PHYS_INPUT_MOVEVALUES(self).y
1185 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
1187 vector wishdir = normalize(wishvel);
1188 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod);
1189 if (time >= self.teleport_time)
1190 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
1193 void PM_swim(float maxspd_mod)
1196 UNSET_ONGROUND(self);
1198 float jump = PHYS_INPUT_BUTTONS(self) & 2;
1199 // water jump only in certain situations
1200 // this mimics quakeworld code
1201 if (jump && self.waterlevel == WATERLEVEL_SWIMMING && self.velocity_z >= -180)
1203 vector yawangles = '0 1 0' * PHYS_INPUT_ANGLES(self).y;
1204 makevectors(yawangles);
1205 vector forward = v_forward;
1206 vector spot = self.origin + 24 * forward;
1208 traceline(spot, spot, MOVE_NOMONSTERS, self);
1209 if (trace_startsolid)
1212 traceline(spot, spot, MOVE_NOMONSTERS, self);
1213 if (!trace_startsolid)
1215 self.velocity = forward * 50;
1216 self.velocity_z = 310;
1217 pmove_waterjumptime = 2;
1218 UNSET_ONGROUND(self);
1219 SET_JUMP_HELD(self);
1223 makevectors(PHYS_INPUT_ANGLES(self));
1224 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1225 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1226 + v_right * PHYS_INPUT_MOVEVALUES(self).y
1227 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
1228 if (wishvel == '0 0 0')
1229 wishvel = '0 0 -60'; // drift towards bottom
1231 vector wishdir = normalize(wishvel);
1232 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod) * 0.7;
1234 if (IS_DUCKED(self))
1237 // if (pmove_waterjumptime <= 0) // TODO: use
1240 float f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION;
1241 f = min(max(0, f), 1);
1244 f = wishspeed - self.velocity * wishdir;
1247 float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, f);
1248 self.velocity += accelspeed * wishdir;
1251 // holding jump button swims upward slowly
1255 if (self.watertype & CONTENT_LAVA)
1256 self.velocity_z = 50;
1257 else if (self.watertype & CONTENT_SLIME)
1258 self.velocity_z = 80;
1261 if (IS_NEXUIZ_DERIVED(gamemode))
1263 self.velocity_z = 200;
1266 self.velocity_z = 100;
1271 PM_ClientMovement_Move();
1272 // water acceleration
1273 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
1276 void PM_ladder(float maxspd_mod)
1279 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
1280 UNSET_ONGROUND(self);
1283 g = PHYS_GRAVITY * PHYS_INPUT_TIMELENGTH;
1284 if (PHYS_ENTGRAVITY(self))
1285 g *= PHYS_ENTGRAVITY(self);
1286 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1289 self.velocity_z += g;
1292 self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
1293 makevectors(PHYS_INPUT_ANGLES(self));
1294 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1295 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1296 + v_right * PHYS_INPUT_MOVEVALUES(self).y
1297 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
1298 self.velocity_z += g;
1299 if (self.ladder_entity.classname == "func_water")
1301 float f = vlen(wishvel);
1302 if (f > self.ladder_entity.speed)
1303 wishvel *= (self.ladder_entity.speed / f);
1305 self.watertype = self.ladder_entity.skin;
1306 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1307 if ((self.origin_z + self.view_ofs_z) < f)
1308 self.waterlevel = WATERLEVEL_SUBMERGED;
1309 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1310 self.waterlevel = WATERLEVEL_SWIMMING;
1311 else if ((self.origin_z + self.mins_z + 1) < f)
1312 self.waterlevel = WATERLEVEL_WETFEET;
1315 self.waterlevel = WATERLEVEL_NONE;
1316 self.watertype = CONTENT_EMPTY;
1320 vector wishdir = normalize(wishvel);
1321 float wishspeed = min(vlen(wishvel), self.stat_sv_maxspeed * maxspd_mod);
1322 if (time >= self.teleport_time)
1323 // water acceleration
1324 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE*maxspd_mod, 1, 0, 0, 0);
1328 void PM_jetpack(float maxspd_mod)
1330 //makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1331 makevectors(PHYS_INPUT_ANGLES(self));
1332 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self)_x
1333 + v_right * PHYS_INPUT_MOVEVALUES(self)_y;
1334 // add remaining speed as Z component
1335 float maxairspd = PHYS_MAXAIRSPEED * max(1, maxspd_mod);
1336 // fix speedhacks :P
1337 wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
1338 // add the unused velocity as up component
1341 // if (self.BUTTON_JUMP)
1342 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1344 // it is now normalized, so...
1345 float a_side = PHYS_JETPACK_ACCEL_SIDE;
1346 float a_up = PHYS_JETPACK_ACCEL_UP;
1347 float a_add = PHYS_JETPACK_ANTIGRAVITY * PHYS_GRAVITY;
1349 wishvel_x *= a_side;
1350 wishvel_y *= a_side;
1355 //////////////////////////////////////////////////////////////////////////////////////
1356 // finding the maximum over all vectors of above form
1357 // with wishvel having an absolute value of 1
1358 //////////////////////////////////////////////////////////////////////////////////////
1359 // we're finding the maximum over
1360 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1361 // for z in the range from -1 to 1
1362 //////////////////////////////////////////////////////////////////////////////////////
1363 // maximum is EITHER attained at the single extreme point:
1364 float a_diff = a_side * a_side - a_up * a_up;
1368 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1369 if (f > -1 && f < 1) // can it be attained?
1371 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1372 //print("middle\n");
1375 // OR attained at z = 1:
1376 f = (a_up + a_add) * (a_up + a_add);
1382 // OR attained at z = -1:
1383 f = (a_up - a_add) * (a_up - a_add);
1387 //print("bottom\n");
1390 //////////////////////////////////////////////////////////////////////////////////////
1392 //print("best possible acceleration: ", ftos(best), "\n");
1395 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE, 1);
1396 if (wishvel_z - PHYS_GRAVITY > 0)
1397 fz = bound(0, 1 - self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
1399 fz = bound(0, 1 + self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
1402 fvel = vlen(wishvel);
1405 wishvel_z = (wishvel_z - PHYS_GRAVITY) * fz + PHYS_GRAVITY;
1407 fvel = min(1, vlen(wishvel) / best);
1408 if (PHYS_JETPACK_FUEL && !(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO))
1409 f = min(1, PHYS_AMMO_FUEL(self) / (PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel));
1413 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1415 if (f > 0 && wishvel != '0 0 0')
1417 self.velocity = self.velocity + wishvel * f * PHYS_INPUT_TIMELENGTH;
1418 UNSET_ONGROUND(self);
1421 if (!(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO))
1422 self.ammo_fuel -= PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel * f;
1424 self.items |= IT_USING_JETPACK;
1426 // jetpack also inhibits health regeneration, but only for 1 second
1427 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1432 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1433 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1434 self.velocity_z -= g * 0.5;
1436 self.velocity_z -= g;
1437 PM_ClientMovement_Move();
1438 if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1439 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1440 self.velocity_z -= g * 0.5;
1444 void PM_walk(float buttons_prev, float maxspd_mod)
1447 // we get here if we ran out of ammo
1448 if ((ITEMS(self) & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
1449 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1450 if (!(self.lastflags & FL_ONGROUND))
1452 if (autocvar_speedmeter)
1453 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1454 if (self.lastground < time - 0.3)
1455 self.velocity *= (1 - autocvar_sv_friction_on_land);
1456 if (self.jumppadcount > 1)
1457 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1458 self.jumppadcount = 0;
1462 makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1463 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1464 + v_right * PHYS_INPUT_MOVEVALUES(self).y;
1466 vector wishdir = normalize(wishvel);
1467 float wishspeed = vlen(wishvel);
1469 wishspeed = min(wishspeed, PHYS_MAXSPEED(self) * maxspd_mod);
1470 if (IS_DUCKED(self))
1473 // apply edge friction
1474 float f = vlen(vec2(self.velocity));
1477 // TODO: apply edge friction
1478 // apply ground friction
1479 f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION * ((f < PHYS_STOPSPEED) ? (PHYS_STOPSPEED / f) : 1);
1483 Mathematical analysis time!
1485 Our goal is to invert this mess.
1487 For the two cases we get:
1488 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * (PHYS_STOPSPEED / v0) * PHYS_FRICTION)
1489 = v0 - PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION
1490 v0 = v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION
1492 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1493 v0 = v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1495 These cases would be chosen ONLY if:
1497 v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION < PHYS_STOPSPEED
1498 v < PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1500 v0 >= PHYS_STOPSPEED
1501 v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION) >= PHYS_STOPSPEED
1502 v >= PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1505 float addspeed = wishspeed - self.velocity * wishdir;
1508 float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
1509 self.velocity += accelspeed * wishdir;
1511 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1512 if (!(GAMEPLAYFIX_NOGRAVITYONGROUND))
1513 self.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1);
1514 if (self.velocity * self.velocity)
1515 PM_ClientMovement_Move();
1516 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1517 if (!IS_ONGROUND(self) || !GAMEPLAYFIX_NOGRAVITYONGROUND)
1518 self.velocity_z -= g * 0.5;
1521 void PM_air(float buttons_prev, float maxspd_mod)
1524 // we get here if we ran out of ammo
1525 if ((ITEMS(self) & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && PHYS_AMMO_FUEL(self) < 0.01)
1526 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1528 makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1529 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1530 + v_right * PHYS_INPUT_MOVEVALUES(self).y;
1532 vector wishdir = normalize(wishvel);
1533 float wishspeed = vlen(wishvel);
1536 if (time >= self.teleport_time)
1538 if (pmove_waterjumptime <= 0)
1541 float maxairspd = PHYS_MAXAIRSPEED * min(maxspd_mod, 1);
1543 // apply air speed limit
1544 float airaccelqw = PHYS_AIRACCEL_QW(self);
1545 float wishspeed0 = wishspeed;
1546 wishspeed = min(wishspeed, maxairspd);
1547 if (IS_DUCKED(self))
1549 float airaccel = PHYS_AIRACCELERATE * min(maxspd_mod, 1);
1551 float accelerating = (self.velocity * wishdir > 0);
1552 float wishspeed2 = wishspeed;
1555 if (PHYS_AIRSTOPACCELERATE)
1557 vector curdir = normalize(vec2(self.velocity));
1558 airaccel += (PHYS_AIRSTOPACCELERATE*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1560 // note that for straight forward jumping:
1561 // step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
1562 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1564 // dv/dt = accel * maxspeed (when slow)
1565 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1566 // log dv/dt = logaccel + logmaxspeed (when slow)
1567 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1568 float strafity = IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), -90) + IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), +90); // if one is nonzero, other is always zero
1569 if (PHYS_MAXAIRSTRAFESPEED)
1570 wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED*maxspd_mod));
1571 if (PHYS_AIRSTRAFEACCELERATE)
1572 airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE*maxspd_mod);
1573 if (PHYS_AIRSTRAFEACCEL_QW(self))
1575 (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(self) : PHYS_AIRACCEL_QW(self)) >= 0) ? +1 : -1)
1577 (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(self)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(self))));
1580 if (PHYS_WARSOWBUNNY_TURNACCEL && accelerating && PHYS_INPUT_MOVEVALUES(self).y == 0 && PHYS_INPUT_MOVEVALUES(self).x != 0)
1581 PM_AirAccelerate(wishdir, wishspeed2);
1583 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(self), PHYS_AIRACCEL_SIDEWAYS_FRICTION / maxairspd, PHYS_AIRSPEEDLIMIT_NONQW(self));
1585 if (PHYS_AIRCONTROL)
1586 CPM_PM_Aircontrol(wishdir, wishspeed2);
1588 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1589 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1590 self.velocity_z -= g * 0.5;
1592 self.velocity_z -= g;
1593 PM_ClientMovement_Move();
1594 if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1595 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1596 self.velocity_z -= g * 0.5;
1599 // used for calculating airshots
1600 float PM_is_flying()
1602 if (IS_ONGROUND(self))
1604 if (self.waterlevel >= WATERLEVEL_SWIMMING)
1606 traceline(self.origin, self.origin - '0 0 48', MOVE_NORMAL, self);
1607 return trace_fraction >= 1;
1613 //Con_Printf(" %f", PHYS_INPUT_TIMELENGTH);
1614 if (!(PHYS_INPUT_BUTTONS(self) & 2)) // !jump
1615 UNSET_JUMP_HELD(self); // canjump = true
1616 pmove_waterjumptime -= PHYS_INPUT_TIMELENGTH;
1617 PM_ClientMovement_UpdateStatus();
1621 WarpZone_PlayerPhysics_FixVAngle();
1623 float maxspeed_mod = 1;
1624 maxspeed_mod *= PM_check_keepaway();
1625 maxspeed_mod *= PHYS_HIGHSPEED;
1628 Physics_UpdateStats(maxspeed_mod);
1630 if (self.PlayerPhysplug)
1631 if (self.PlayerPhysplug())
1635 PM_check_race_movetime();
1637 anticheat_physics();
1639 float buttons = PHYS_INPUT_BUTTONS(self);
1641 if (PM_check_specialcommand(buttons))
1646 if (buttons != self.buttons_old || PHYS_INPUT_MOVEVALUES(self) != self.movement_old || PHYS_INPUT_ANGLES(self) != self.v_angle_old)
1647 self.parm_idlesince = time;
1650 float buttons_prev = self.buttons_old;
1651 self.buttons_old = buttons;
1652 self.movement_old = PHYS_INPUT_MOVEVALUES(self);
1653 self.v_angle_old = PHYS_INPUT_ANGLES(self);
1655 PM_check_nickspam();
1659 if (IS_BOT_CLIENT(self))
1661 if (playerdemo_read())
1666 self.items &= ~IT_USING_JETPACK;
1668 if (IS_PLAYER(self))
1672 if (self.race_penalty)
1673 if (time > self.race_penalty)
1674 self.race_penalty = 0;
1677 float not_allowed_to_move = 0;
1679 if (self.race_penalty)
1680 not_allowed_to_move = 1;
1683 if (!autocvar_sv_ready_restart_after_countdown)
1684 if (time < game_starttime)
1685 not_allowed_to_move = 1;
1688 if (not_allowed_to_move)
1690 self.velocity = '0 0 0';
1691 self.movetype = MOVETYPE_NONE;
1693 self.disableclientprediction = 2;
1697 else if (self.disableclientprediction == 2)
1699 if (self.movetype == MOVETYPE_NONE)
1700 self.movetype = MOVETYPE_WALK;
1701 self.disableclientprediction = 0;
1707 if (self.movetype == MOVETYPE_NONE)
1712 // when we get here, disableclientprediction cannot be 2
1713 self.disableclientprediction = 0;
1714 if (time < self.ladder_time)
1715 self.disableclientprediction = 1;
1723 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;
1883 self.lastflags = self.flags;
1884 self.lastclassname = self.classname;
1887 PM_dodging_checkpressedkeys();
1888 PM_dodging_updatepressedkeys();
1892 void CSQC_ClientMovement_PlayerMove_Frame()
1894 // if a move is more than 50ms, do it as two moves (matching qwsv)
1895 //Con_Printf("%i ", self.cmd.msec);
1896 if (PHYS_INPUT_TIMELENGTH > 0.0005)
1898 if (PHYS_INPUT_TIMELENGTH > 0.05)
1900 PHYS_INPUT_TIMELENGTH /= 2;
1906 // we REALLY need this handling to happen, even if the move is not executed
1907 if (!(PHYS_INPUT_BUTTONS(self) & 2)) // !jump
1908 UNSET_JUMP_HELD(self); // canjump = true
1911 #undef PHYS_INPUT_ANGLES
1912 #undef PHYS_INPUT_BUTTONS
1913 #undef PHYS_INPUT_TIMELENGTH
1914 #undef PHYS_INPUT_MOVEVALUES
1917 #undef PHYS_DODGING_FROZEN
1919 #undef GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE
1920 #undef GAMEPLAYFIX_NOGRAVITYONGROUND
1921 #undef GAMEPLAYFIX_Q2AIRACCELERATE
1928 #undef SET_JUMP_HELD
1929 #undef UNSET_JUMP_HELD
1933 #undef UNSET_ONGROUND
1935 #undef PHYS_ACCELERATE
1936 #undef PHYS_AIRACCEL_QW
1937 #undef PHYS_AIRACCEL_QW_STRETCHFACTOR
1938 #undef PHYS_AIRACCEL_SIDEWAYS_FRICTION
1939 #undef PHYS_AIRACCELERATE
1940 #undef PHYS_AIRCONTROL
1941 #undef PHYS_AIRCONTROL_PENALTY
1942 #undef PHYS_AIRCONTROL_POWER
1943 #undef PHYS_AIRSPEEDLIMIT_NONQW
1944 #undef PHYS_AIRSTOPACCELERATE
1945 #undef PHYS_AIRSTRAFEACCEL_QW
1946 #undef PHYS_AIRSTRAFEACCELERATE
1947 #undef PHYS_EDGEFRICTION
1948 #undef PHYS_ENTGRAVITY
1949 #undef PHYS_FRICTION
1951 #undef PHYS_HIGHSPEED
1952 #undef PHYS_JUMPVELOCITY
1953 #undef PHYS_MAXAIRSPEED
1954 #undef PHYS_MAXAIRSTRAFESPEED
1955 #undef PHYS_MAXSPEED
1956 #undef PHYS_STEPHEIGHT
1957 #undef PHYS_STOPSPEED
1958 #undef PHYS_WARSOWBUNNY_ACCEL
1959 #undef PHYS_WARSOWBUNNY_BACKTOSIDERATIO
1960 #undef PHYS_WARSOWBUNNY_AIRFORWARDACCEL
1961 #undef PHYS_WARSOWBUNNY_TOPSPEED
1962 #undef PHYS_WARSOWBUNNY_TURNACCEL
1966 void SV_PlayerPhysics(void)