2 #include "triggers/trigger/swamp.qh"
3 #include "triggers/trigger/jumppads.qh"
7 #include "../server/miscfunctions.qh"
9 void Physics_AddStats()
11 // g_movementspeed hack
12 addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
13 addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
14 addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
15 addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
16 addstat(STAT_MOVEVARS_HIGHSPEED, AS_FLOAT, stat_movement_highspeed);
19 addstat(STAT_JETPACK_ACCEL_SIDE, AS_FLOAT, stat_jetpack_accel_side);
20 addstat(STAT_JETPACK_ACCEL_UP, AS_FLOAT, stat_jetpack_accel_up);
21 addstat(STAT_JETPACK_ANTIGRAVITY, AS_FLOAT, stat_jetpack_antigravity);
22 addstat(STAT_JETPACK_FUEL, AS_FLOAT, stat_jetpack_fuel);
23 addstat(STAT_JETPACK_MAXSPEED_UP, AS_FLOAT, stat_jetpack_maxspeed_up);
24 addstat(STAT_JETPACK_MAXSPEED_SIDE, AS_FLOAT, stat_jetpack_maxspeed_side);
26 // hack to fix track_canjump
27 addstat(STAT_MOVEVARS_TRACK_CANJUMP, AS_INT, cvar_cl_movement_track_canjump);
30 addstat(STAT_DOUBLEJUMP, AS_INT, stat_doublejump);
33 addstat(STAT_MOVEVARS_JUMPSPEEDCAP_MIN, AS_FLOAT, stat_jumpspeedcap_min);
34 addstat(STAT_MOVEVARS_JUMPSPEEDCAP_MIN, AS_FLOAT, stat_jumpspeedcap_min);
35 addstat(STAT_MOVEVARS_JUMPSPEEDCAP_DISABLE_ONRAMPS, AS_INT, stat_jumpspeedcap_disable_onramps);
38 addstat(STAT_MOVEVARS_FRICTION_ONLAND, AS_FLOAT, stat_sv_friction_on_land);
39 addstat(STAT_MOVEVARS_FRICTION_SLICK, AS_FLOAT, stat_sv_friction_slick);
40 addstat(STAT_GAMEPLAYFIX_EASIERWATERJUMP, AS_INT, stat_gameplayfix_easierwaterjump);
43 void Physics_UpdateStats(float maxspd_mod)
45 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
46 if (autocvar_sv_airstrafeaccel_qw)
47 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
49 self.stat_sv_airstrafeaccel_qw = 0;
50 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
51 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
52 self.stat_movement_highspeed = PHYS_HIGHSPEED; // TODO: remove this!
54 self.stat_doublejump = PHYS_DOUBLEJUMP;
56 self.stat_jetpack_antigravity = PHYS_JETPACK_ANTIGRAVITY;
57 self.stat_jetpack_accel_up = PHYS_JETPACK_ACCEL_UP;
58 self.stat_jetpack_accel_side = PHYS_JETPACK_ACCEL_SIDE;
59 self.stat_jetpack_maxspeed_side = PHYS_JETPACK_MAXSPEED_SIDE;
60 self.stat_jetpack_maxspeed_up = PHYS_JETPACK_MAXSPEED_UP;
61 self.stat_jetpack_fuel = PHYS_JETPACK_FUEL;
63 self.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MIN;
64 self.stat_jumpspeedcap_max = PHYS_JUMPSPEEDCAP_MAX;
65 self.stat_jumpspeedcap_disable_onramps = PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS;
67 self.stat_sv_friction_on_land = PHYS_FRICTION_ONLAND;
68 self.stat_sv_friction_slick = PHYS_FRICTION_SLICK;
70 self.stat_gameplayfix_easierwaterjump = GAMEPLAYFIX_EASIERWATERJUMP;
74 float IsMoveInDirection(vector mv, float angle) // key mix factor
76 if (mv_x == 0 && mv_y == 0)
77 return 0; // avoid division by zero
78 angle -= RAD2DEG * atan2(mv_y, mv_x);
79 angle = remainder(angle, 360) / 45;
80 return angle > 1 ? 0 : angle < -1 ? 0 : 1 - fabs(angle);
83 float GeomLerp(float a, float lerp, float b)
85 return a == 0 ? (lerp < 1 ? 0 : b)
86 : b == 0 ? (lerp > 0 ? 0 : a)
87 : a * pow(fabs(b / a), lerp);
90 noref float pmove_waterjumptime;
92 const float unstick_count = 27;
93 vector unstick_offsets[unstick_count] =
95 // 1 no nudge (just return the original if this test passes)
98 ' 0.000 0.000 0.125', '0.000 0.000 -0.125',
99 '-0.125 0.000 0.000', '0.125 0.000 0.000',
100 ' 0.000 -0.125 0.000', '0.000 0.125 0.000',
101 // 4 diagonal flat nudges
102 '-0.125 -0.125 0.000', '0.125 -0.125 0.000',
103 '-0.125 0.125 0.000', '0.125 0.125 0.000',
104 // 8 diagonal upward nudges
105 '-0.125 0.000 0.125', '0.125 0.000 0.125',
106 ' 0.000 -0.125 0.125', '0.000 0.125 0.125',
107 '-0.125 -0.125 0.125', '0.125 -0.125 0.125',
108 '-0.125 0.125 0.125', '0.125 0.125 0.125',
109 // 8 diagonal downward nudges
110 '-0.125 0.000 -0.125', '0.125 0.000 -0.125',
111 ' 0.000 -0.125 -0.125', '0.000 0.125 -0.125',
112 '-0.125 -0.125 -0.125', '0.125 -0.125 -0.125',
113 '-0.125 0.125 -0.125', '0.125 0.125 -0.125',
116 void PM_ClientMovement_Unstick()
119 for (i = 0; i < unstick_count; i++)
121 vector neworigin = unstick_offsets[i] + self.origin;
122 tracebox(neworigin, PL_CROUCH_MIN, PL_CROUCH_MAX, neworigin, MOVE_NORMAL, self);
123 if (!trace_startsolid)
125 setorigin(self, neworigin);
131 void PM_ClientMovement_UpdateStatus(bool ground)
133 // make sure player is not stuck
134 PM_ClientMovement_Unstick();
137 if (PHYS_INPUT_BUTTON_CROUCH(self))
139 // wants to crouch, this always works..
140 if (!IS_DUCKED(self))
145 // wants to stand, if currently crouching we need to check for a
149 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, MOVE_NORMAL, self);
150 if (!trace_startsolid)
156 vector origin1 = self.origin + '0 0 1';
157 vector origin2 = self.origin - '0 0 1';
161 tracebox(origin1, self.mins, self.maxs, origin2, MOVE_NORMAL, self);
162 if (trace_fraction < 1.0 && trace_plane_normal_z > 0.7)
166 // this code actually "predicts" an impact; so let's clip velocity first
167 float f = self.velocity * trace_plane_normal;
168 self.velocity -= f * trace_plane_normal;
171 UNSET_ONGROUND(self);
174 // set watertype/waterlevel
175 origin1 = self.origin;
176 origin1_z += self.mins_z + 1;
177 self.waterlevel = WATERLEVEL_NONE;
179 self.watertype = (pointcontents(origin1) == CONTENT_WATER);
183 self.waterlevel = WATERLEVEL_WETFEET;
184 origin1_z = self.origin_z + (self.mins_z + self.maxs_z) * 0.5;
185 if(pointcontents(origin1) == CONTENT_WATER)
187 self.waterlevel = WATERLEVEL_SWIMMING;
188 origin1_z = self.origin_z + 22;
189 if(pointcontents(origin1) == CONTENT_WATER)
190 self.waterlevel = WATERLEVEL_SUBMERGED;
194 if(IS_ONGROUND(self) || self.velocity_z <= 0 || pmove_waterjumptime <= 0)
195 pmove_waterjumptime = 0;
198 void PM_ClientMovement_Move()
201 float t = PHYS_INPUT_TIMELENGTH;
202 vector primalvelocity = self.velocity;
203 PM_ClientMovement_UpdateStatus(false);
205 for (bump = 0; bump < MAX_CLIP_PLANES && (self.velocity * self.velocity) > 0; bump++)
207 vector neworigin = self.origin + t * self.velocity;
208 tracebox(self.origin, self.mins, self.maxs, neworigin, MOVE_NORMAL, self);
209 float old_trace1_fraction = trace_fraction;
210 vector old_trace1_endpos = trace_endpos;
211 vector old_trace1_plane_normal = trace_plane_normal;
212 if (trace_fraction < 1 && trace_plane_normal_z == 0)
214 // may be a step or wall, try stepping up
215 // first move forward at a higher level
216 vector currentorigin2 = self.origin;
217 currentorigin2_z += PHYS_STEPHEIGHT;
218 vector neworigin2 = neworigin;
219 neworigin2_z = self.origin_z + PHYS_STEPHEIGHT;
220 tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
221 if (!trace_startsolid)
223 // then move down from there
224 currentorigin2 = trace_endpos;
225 neworigin2 = trace_endpos;
226 neworigin2_z = self.origin_z;
227 float old_trace2_fraction = trace_fraction;
228 vector old_trace2_plane_normal = trace_plane_normal;
229 tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
230 // accept the new trace if it made some progress
231 if (fabs(trace_endpos_x - old_trace1_endpos_x) >= 0.03125 || fabs(trace_endpos_y - old_trace1_endpos_y) >= 0.03125)
233 trace_fraction = old_trace2_fraction;
234 trace_endpos = trace_endpos;
235 trace_plane_normal = old_trace2_plane_normal;
239 trace_fraction = old_trace1_fraction;
240 trace_endpos = old_trace1_endpos;
241 trace_plane_normal = old_trace1_plane_normal;
246 // check if it moved at all
247 if (trace_fraction >= 0.001)
248 setorigin(self, trace_endpos);
250 // check if it moved all the way
251 if (trace_fraction == 1)
254 // this is only really needed for nogravityonground combined with gravityunaffectedbyticrate
255 // <LordHavoc> I'm pretty sure I commented it out solely because it seemed redundant
256 // this got commented out in a change that supposedly makes the code match QW better
257 // so if this is broken, maybe put it in an if (cls.protocol != PROTOCOL_QUAKEWORLD) block
258 if (trace_plane_normal_z > 0.7)
261 t -= t * trace_fraction;
263 float f = self.velocity * trace_plane_normal;
264 self.velocity -= f * trace_plane_normal;
266 if (pmove_waterjumptime > 0)
267 self.velocity = primalvelocity;
271 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
273 float k = 32 * (2 * IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), 0) - 1);
277 k *= bound(0, wishspeed / PHYS_MAXAIRSPEED, 1);
279 float zspeed = self.velocity_z;
281 float xyspeed = vlen(self.velocity);
282 self.velocity = normalize(self.velocity);
284 float dot = self.velocity * wishdir;
286 if (dot > 0) // we can't change direction while slowing down
288 k *= pow(dot, PHYS_AIRCONTROL_POWER) * PHYS_INPUT_TIMELENGTH;
289 xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY * sqrt(max(0, 1 - dot*dot)) * k/32);
290 k *= PHYS_AIRCONTROL;
291 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
294 self.velocity = self.velocity * xyspeed;
295 self.velocity_z = zspeed;
298 float AdjustAirAccelQW(float accelqw, float factor)
300 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
303 // example config for alternate speed clamping:
304 // sv_airaccel_qw 0.8
305 // sv_airaccel_sideways_friction 0
306 // prvm_globalset server speedclamp_mode 1
308 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
310 float speedclamp = stretchfactor > 0 ? stretchfactor
311 : accelqw < 0 ? 1 // full clamping, no stretch
314 accelqw = fabs(accelqw);
316 if (GAMEPLAYFIX_Q2AIRACCELERATE)
317 wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
319 float vel_straight = self.velocity * wishdir;
320 float vel_z = self.velocity_z;
321 vector vel_xy = vec2(self.velocity);
322 vector vel_perpend = vel_xy - vel_straight * wishdir;
324 float step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
326 float vel_xy_current = vlen(vel_xy);
328 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
329 float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
330 float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
331 vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
332 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
334 if (sidefric < 0 && (vel_perpend*vel_perpend))
335 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
337 float f = max(0, 1 + PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
338 float fmin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
340 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
341 // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
342 // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
343 // obviously, this cannot be
349 vel_perpend *= max(fmin, f);
353 vel_perpend *= max(0, 1 - PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
355 vel_xy = vel_straight * wishdir + vel_perpend;
359 float vel_xy_preclamp;
360 vel_xy_preclamp = vlen(vel_xy);
361 if (vel_xy_preclamp > 0) // prevent division by zero
363 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
364 if (vel_xy_current < vel_xy_preclamp)
365 vel_xy *= (vel_xy_current / vel_xy_preclamp);
369 self.velocity = vel_xy + vel_z * '0 0 1';
372 void PM_AirAccelerate(vector wishdir, float wishspeed)
377 vector curvel = self.velocity;
379 float curspeed = vlen(curvel);
381 if (wishspeed > curspeed * 1.01)
382 wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH);
385 float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED - PHYS_MAXSPEED(self)));
386 wishspeed = max(curspeed, PHYS_MAXSPEED(self)) + PHYS_WARSOWBUNNY_ACCEL * f * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH;
388 vector wishvel = wishdir * wishspeed;
389 vector acceldir = wishvel - curvel;
390 float addspeed = vlen(acceldir);
391 acceldir = normalize(acceldir);
393 float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH);
395 if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO < 1)
397 vector curdir = normalize(curvel);
398 float dot = acceldir * curdir;
400 acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO) * dot * curdir;
403 self.velocity += accelspeed * acceldir;
411 When you press the jump key
412 returns true if handled
415 float PlayerJump (void)
417 if (PHYS_FROZEN(self))
418 return true; // no jumping in freezetag when frozen
421 if (self.player_blocked)
422 return true; // no jumping while blocked
425 float doublejump = false;
426 float mjumpheight = PHYS_JUMPVELOCITY;
428 player_multijump = doublejump;
429 player_jumpheight = mjumpheight;
431 if (MUTATOR_CALLHOOK(PlayerJump))
433 if(PM_multijump_checkjump())
437 doublejump = player_multijump;
438 mjumpheight = player_jumpheight;
442 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
443 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
447 // we MUST clip velocity here!
449 f = self.velocity * trace_plane_normal;
451 self.velocity -= f * trace_plane_normal;
455 if (self.waterlevel >= WATERLEVEL_SWIMMING)
457 self.velocity_z = PHYS_MAXSPEED(self) * 0.7;
462 if (!IS_ONGROUND(self))
463 return IS_JUMP_HELD(self);
465 if (PHYS_TRACK_CANJUMP(self))
466 if (IS_JUMP_HELD(self))
469 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
470 // velocity bounds. Final velocity is bound between (jumpheight *
471 // min + jumpheight) and (jumpheight * max + jumpheight);
473 if(PHYS_JUMPSPEEDCAP_MIN)
475 float minjumpspeed = mjumpheight * PHYS_JUMPSPEEDCAP_MIN;
477 if (self.velocity_z < minjumpspeed)
478 mjumpheight += minjumpspeed - self.velocity_z;
481 if(PHYS_JUMPSPEEDCAP_MAX)
483 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
484 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
486 if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS))
488 float maxjumpspeed = mjumpheight * PHYS_JUMPSPEEDCAP_MAX;
490 if (self.velocity_z > maxjumpspeed)
491 mjumpheight -= self.velocity_z - maxjumpspeed;
495 if (!WAS_ONGROUND(self))
497 if(autocvar_speedmeter)
498 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
499 if(self.lastground < time - 0.3)
501 self.velocity_x *= (1 - PHYS_FRICTION_ONLAND);
502 self.velocity_y *= (1 - PHYS_FRICTION_ONLAND);
504 if(self.jumppadcount > 1)
505 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
506 self.jumppadcount = 0;
509 self.velocity_z += mjumpheight;
511 UNSET_ONGROUND(self);
516 self.oldvelocity_z = self.velocity_z;
518 animdecide_setaction(self, ANIMACTION_JUMP, true);
520 if (autocvar_g_jump_grunt)
521 PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
526 void CheckWaterJump()
528 // check for a jump-out-of-water
529 makevectors(PHYS_INPUT_ANGLES(self));
530 vector start = self.origin;
533 normalize(v_forward);
534 vector end = start + v_forward*24;
535 traceline (start, end, true, self);
536 if (trace_fraction < 1)
538 start_z = start_z + self.maxs_z - 8;
539 end = start + v_forward*24;
540 self.movedir = trace_plane_normal * -50;
541 traceline(start, end, true, self);
542 if (trace_fraction == 1)
543 { // open at eye level
544 self.velocity_z = 225;
546 self.flags |= FL_WATERJUMP;
548 self.teleport_time = time + 2; // safety net
556 #define JETPACK_JUMP(s) s.cvar_cl_jetpack_jump
558 float autocvar_cl_jetpack_jump;
559 #define JETPACK_JUMP(s) autocvar_cl_jetpack_jump
561 .float jetpack_stopped;
562 // Hack: shouldn't need to know about this
563 .float multijump_count;
564 void CheckPlayerJump()
567 float was_flying = ITEMS(self) & IT_USING_JETPACK;
569 if (JETPACK_JUMP(self) < 2)
571 ITEMS(self) &= ~IT_USING_JETPACK;
574 if(PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_JETPACK(self))
577 float air_jump = !PlayerJump() || self.multijump_count > 0; // PlayerJump() has important side effects
578 float activate = JETPACK_JUMP(self) && air_jump && PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_JETPACK(self);
579 float has_fuel = !autocvar_g_jetpack_fuel || self.ammo_fuel || ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO;
581 PlayerJump(); // Client only
582 float has_fuel = true; // TODO
584 if (!(ITEMS(self) & IT_JETPACK)) { }
585 else if (self.jetpack_stopped) { }
589 if (was_flying) // TODO: ran out of fuel message
590 Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL);
592 Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL);
594 self.jetpack_stopped = true;
596 ITEMS(self) &= ~IT_USING_JETPACK;
600 else if (activate && !PHYS_FROZEN(self))
601 ITEMS(self) |= IT_USING_JETPACK;
606 self.jetpack_stopped = false;
608 ITEMS(self) &= ~IT_USING_JETPACK;
611 if (!PHYS_INPUT_BUTTON_JUMP(self))
612 UNSET_JUMP_HELD(self);
614 if (self.waterlevel == WATERLEVEL_SWIMMING)
618 float racecar_angle(float forward, float down)
626 float ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
628 float angle_mult = forward / (800 + forward);
631 return ret * angle_mult + 360 * (1 - angle_mult);
633 return ret * angle_mult;
636 void RaceCarPhysics()
639 // using this move type for "big rigs"
640 // the engine does not push the entity!
644 vector angles_save = self.angles;
645 float accel = bound(-1, PHYS_INPUT_MOVEVALUES(self).x / PHYS_MAXSPEED(self), 1);
646 float steer = bound(-1, PHYS_INPUT_MOVEVALUES(self).y / PHYS_MAXSPEED(self), 1);
648 if (g_bugrigs_reverse_speeding)
652 // back accel is DIGITAL
653 // to prevent speedhack
663 makevectors(self.angles); // new forward direction!
665 if (IS_ONGROUND(self) || g_bugrigs_air_steering)
667 float myspeed = self.velocity * v_forward;
668 float upspeed = self.velocity * v_up;
670 // responsiveness factor for steering and acceleration
671 float f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
672 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
675 if (myspeed < 0 && g_bugrigs_reverse_spinning)
676 steerfactor = -myspeed * g_bugrigs_steer;
678 steerfactor = -myspeed * f * g_bugrigs_steer;
681 if (myspeed < 0 && g_bugrigs_reverse_speeding)
682 accelfactor = g_bugrigs_accel;
684 accelfactor = f * g_bugrigs_accel;
685 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
691 myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
695 if (!g_bugrigs_reverse_speeding)
696 myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
703 myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
707 if (g_bugrigs_reverse_stopping)
710 myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
713 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
714 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
716 self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
717 makevectors(self.angles); // new forward direction!
719 myspeed += accel * accelfactor * PHYS_INPUT_TIMELENGTH;
721 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
725 float myspeed = vlen(self.velocity);
727 // responsiveness factor for steering and acceleration
728 float f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
729 float steerfactor = -myspeed * f;
730 self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
732 rigvel = self.velocity;
733 makevectors(self.angles); // new forward direction!
736 rigvel *= max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * PHYS_INPUT_TIMELENGTH);
737 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
738 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
739 //MAXIMA: solve(total_acceleration(v) = 0, v);
741 if (g_bugrigs_planar_movement)
743 vector rigvel_xy, neworigin, up;
746 rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
747 rigvel_xy = vec2(rigvel);
749 if (g_bugrigs_planar_movement_car_jumping)
752 mt = MOVE_NOMONSTERS;
754 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
755 up = trace_endpos - self.origin;
757 // BUG RIGS: align the move to the surface instead of doing collision testing
759 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * PHYS_INPUT_TIMELENGTH, mt, self);
762 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * PHYS_INPUT_TIMELENGTH, mt, self);
764 if (trace_fraction < 0.5)
767 neworigin = self.origin;
770 neworigin = trace_endpos;
772 if (trace_fraction < 1)
774 // now set angles_x so that the car points parallel to the surface
775 self.angles = vectoangles(
776 '1 0 0' * v_forward_x * trace_plane_normal_z
778 '0 1 0' * v_forward_y * trace_plane_normal_z
780 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
786 // now set angles_x so that the car points forward, but is tilted in velocity direction
787 UNSET_ONGROUND(self);
790 self.velocity = (neworigin - self.origin) * (1.0 / PHYS_INPUT_TIMELENGTH);
791 self.movetype = MOVETYPE_NOCLIP;
795 rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
796 self.velocity = rigvel;
797 self.movetype = MOVETYPE_FLY;
801 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
802 if (trace_fraction != 1)
804 self.angles = vectoangles2(
805 '1 0 0' * v_forward_x * trace_plane_normal_z
807 '0 1 0' * v_forward_y * trace_plane_normal_z
809 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
817 vel_local_x = v_forward * self.velocity;
818 vel_local_y = v_right * self.velocity;
819 vel_local_z = v_up * self.velocity;
821 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
822 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
826 vector vf1, vu1, smoothangles;
827 makevectors(self.angles);
828 float f = bound(0, PHYS_INPUT_TIMELENGTH * g_bugrigs_angle_smoothing, 1);
833 makevectors(angles_save);
834 vf1 = vf1 + v_forward * (1 - f);
835 vu1 = vu1 + v_up * (1 - f);
836 smoothangles = vectoangles2(vf1, vu1);
837 self.angles_x = -smoothangles_x;
838 self.angles_z = smoothangles_z;
842 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
843 .float specialcommand_pos;
844 void SpecialCommand()
850 if (!CheatImpulse(99))
851 print("A hollow voice says \"Plugh\".\n");
856 float PM_check_keepaway(void)
859 return (self.ballcarried && g_keepaway) ? autocvar_g_keepaway_ballcarrier_highspeed : 1;
865 void PM_check_race_movetime(void)
868 self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
869 float f = floor(self.race_movetime_frac);
870 self.race_movetime_frac -= f;
871 self.race_movetime_count += f;
872 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
876 float PM_check_specialcommand(float buttons)
882 else if (buttons == 1)
884 else if (buttons == 2)
886 else if (buttons == 128)
888 else if (buttons == 256)
890 else if (buttons == 512)
892 else if (buttons == 1024)
897 if (c == substring(specialcommand, self.specialcommand_pos, 1))
899 self.specialcommand_pos += 1;
900 if (self.specialcommand_pos >= strlen(specialcommand))
902 self.specialcommand_pos = 0;
907 else if (self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
908 self.specialcommand_pos = 0;
913 void PM_check_nickspam(void)
916 if (time >= self.nickspamtime)
918 if (self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
920 // slight annoyance for nick change scripts
921 PHYS_INPUT_MOVEVALUES(self) = -1 * PHYS_INPUT_MOVEVALUES(self);
922 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
924 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!
926 PHYS_INPUT_ANGLES(self)_x = random() * 360;
927 PHYS_INPUT_ANGLES(self)_y = random() * 360;
928 // at least I'm not forcing retardedview by also assigning to angles_z
929 self.fixangle = true;
935 void PM_check_punch()
938 if (self.punchangle != '0 0 0')
940 float f = vlen(self.punchangle) - 10 * PHYS_INPUT_TIMELENGTH;
942 self.punchangle = normalize(self.punchangle) * f;
944 self.punchangle = '0 0 0';
947 if (self.punchvector != '0 0 0')
949 float f = vlen(self.punchvector) - 30 * PHYS_INPUT_TIMELENGTH;
951 self.punchvector = normalize(self.punchvector) * f;
953 self.punchvector = '0 0 0';
958 void PM_check_spider(void)
961 if (time >= self.spider_slowness)
963 PHYS_MAXSPEED(self) *= 0.5; // half speed while slow from spider
964 self.stat_sv_airspeedlimit_nonqw *= 0.5;
968 // predict frozen movement, as frozen players CAN move in some cases
969 void PM_check_frozen(void)
971 if (!PHYS_FROZEN(self))
973 if (PHYS_DODGING_FROZEN
975 && IS_REAL_CLIENT(self)
979 PHYS_INPUT_MOVEVALUES(self)_x = bound(-5, PHYS_INPUT_MOVEVALUES(self).x, 5);
980 PHYS_INPUT_MOVEVALUES(self)_y = bound(-5, PHYS_INPUT_MOVEVALUES(self).y, 5);
981 PHYS_INPUT_MOVEVALUES(self)_z = bound(-5, PHYS_INPUT_MOVEVALUES(self).z, 5);
984 PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
986 vector midpoint = ((self.absmin + self.absmax) * 0.5);
987 if (pointcontents(midpoint) == CONTENT_WATER)
989 self.velocity = self.velocity * 0.5;
991 if (pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
992 self.velocity_z = 200;
996 void PM_check_hitground()
999 if (IS_ONGROUND(self))
1000 if (IS_PLAYER(self)) // no fall sounds for observers thank you very much
1004 if (self.waterlevel < WATERLEVEL_SWIMMING)
1005 if (time >= self.ladder_time)
1008 self.nextstep = time + 0.3 + random() * 0.1;
1009 trace_dphitq3surfaceflags = 0;
1010 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
1011 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
1013 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
1014 GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
1016 GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
1023 void PM_check_blocked(void)
1026 if (!self.player_blocked)
1028 PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
1029 self.disableclientprediction = 1;
1034 float speedaward_lastsent;
1035 float speedaward_lastupdate;
1037 void PM_check_race(void)
1040 if(!(g_cts || g_race))
1042 if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
1044 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1045 speedaward_holder = self.netname;
1046 speedaward_uid = self.crypto_idfp;
1047 speedaward_lastupdate = time;
1049 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
1051 string rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
1052 race_send_speedaward(MSG_ALL);
1053 speedaward_lastsent = speedaward_speed;
1054 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
1056 speedaward_alltimebest = speedaward_speed;
1057 speedaward_alltimebest_holder = speedaward_holder;
1058 speedaward_alltimebest_uid = speedaward_uid;
1059 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1060 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1061 race_send_speedaward_alltimebest(MSG_ALL);
1067 void PM_check_vortex(void)
1071 float xyspeed = vlen(vec2(self.velocity));
1072 if (self.weapon == WEP_VORTEX && WEP_CVAR(vortex, charge) && WEP_CVAR(vortex, charge_velocity_rate) && xyspeed > WEP_CVAR(vortex, charge_minspeed))
1074 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1075 xyspeed = min(xyspeed, WEP_CVAR(vortex, charge_maxspeed));
1076 float f = (xyspeed - WEP_CVAR(vortex, charge_minspeed)) / (WEP_CVAR(vortex, charge_maxspeed) - WEP_CVAR(vortex, charge_minspeed));
1077 // add the extra charge
1078 self.vortex_charge = min(1, self.vortex_charge + WEP_CVAR(vortex, charge_velocity_rate) * f * PHYS_INPUT_TIMELENGTH);
1083 void PM_fly(float maxspd_mod)
1085 // noclipping or flying
1086 UNSET_ONGROUND(self);
1088 self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
1089 makevectors(PHYS_INPUT_ANGLES(self));
1090 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1091 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1092 + v_right * PHYS_INPUT_MOVEVALUES(self).y
1093 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
1095 vector wishdir = normalize(wishvel);
1096 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod);
1097 if (time >= self.teleport_time)
1098 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
1101 void PM_swim(float maxspd_mod)
1104 UNSET_ONGROUND(self);
1106 float jump = PHYS_INPUT_BUTTON_JUMP(self);
1107 // water jump only in certain situations
1108 // this mimics quakeworld code
1109 if (jump && self.waterlevel == WATERLEVEL_SWIMMING && self.velocity_z >= -180)
1111 vector yawangles = '0 1 0' * PHYS_INPUT_ANGLES(self).y;
1112 makevectors(yawangles);
1113 vector forward = v_forward;
1114 vector spot = self.origin + 24 * forward;
1116 traceline(spot, spot, MOVE_NOMONSTERS, self);
1117 if (trace_startsolid)
1120 traceline(spot, spot, MOVE_NOMONSTERS, self);
1121 if (!trace_startsolid)
1123 self.velocity = forward * 50;
1124 self.velocity_z = 310;
1125 pmove_waterjumptime = 2;
1126 UNSET_ONGROUND(self);
1127 SET_JUMP_HELD(self);
1131 makevectors(PHYS_INPUT_ANGLES(self));
1132 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1133 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1134 + v_right * PHYS_INPUT_MOVEVALUES(self).y
1135 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
1136 if (wishvel == '0 0 0')
1137 wishvel = '0 0 -60'; // drift towards bottom
1139 vector wishdir = normalize(wishvel);
1140 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod) * 0.7;
1142 if (IS_DUCKED(self))
1145 // if (pmove_waterjumptime <= 0) // TODO: use
1148 float f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION;
1149 f = min(max(0, f), 1);
1152 f = wishspeed - self.velocity * wishdir;
1155 float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, f);
1156 self.velocity += accelspeed * wishdir;
1159 // holding jump button swims upward slowly
1163 if (self.watertype & CONTENT_LAVA)
1164 self.velocity_z = 50;
1165 else if (self.watertype & CONTENT_SLIME)
1166 self.velocity_z = 80;
1169 if (IS_NEXUIZ_DERIVED(gamemode))
1171 self.velocity_z = 200;
1174 self.velocity_z = 100;
1179 PM_ClientMovement_Move();
1180 // water acceleration
1181 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
1184 void PM_ladder(float maxspd_mod)
1186 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
1187 UNSET_ONGROUND(self);
1190 g = PHYS_GRAVITY * PHYS_INPUT_TIMELENGTH;
1191 if (PHYS_ENTGRAVITY(self))
1192 g *= PHYS_ENTGRAVITY(self);
1193 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1196 self.velocity_z += g;
1199 self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
1200 makevectors(PHYS_INPUT_ANGLES(self));
1201 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1202 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self)_x
1203 + v_right * PHYS_INPUT_MOVEVALUES(self)_y
1204 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self)_z;
1205 self.velocity_z += g;
1206 if (self.ladder_entity.classname == "func_water")
1208 float f = vlen(wishvel);
1209 if (f > self.ladder_entity.speed)
1210 wishvel *= (self.ladder_entity.speed / f);
1212 self.watertype = self.ladder_entity.skin;
1213 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1214 if ((self.origin_z + self.view_ofs_z) < f)
1215 self.waterlevel = WATERLEVEL_SUBMERGED;
1216 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1217 self.waterlevel = WATERLEVEL_SWIMMING;
1218 else if ((self.origin_z + self.mins_z + 1) < f)
1219 self.waterlevel = WATERLEVEL_WETFEET;
1222 self.waterlevel = WATERLEVEL_NONE;
1223 self.watertype = CONTENT_EMPTY;
1227 vector wishdir = normalize(wishvel);
1228 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod);
1229 PM_ClientMovement_Move();
1231 if (time >= self.teleport_time)
1233 // water acceleration
1234 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE*maxspd_mod, 1, 0, 0, 0);
1237 void PM_jetpack(float maxspd_mod)
1239 //makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1240 makevectors(PHYS_INPUT_ANGLES(self));
1241 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self)_x
1242 + v_right * PHYS_INPUT_MOVEVALUES(self)_y;
1243 // add remaining speed as Z component
1244 float maxairspd = PHYS_MAXAIRSPEED * max(1, maxspd_mod);
1245 // fix speedhacks :P
1246 wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
1247 // add the unused velocity as up component
1250 // if (self.BUTTON_JUMP)
1251 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1253 // it is now normalized, so...
1254 float a_side = PHYS_JETPACK_ACCEL_SIDE;
1255 float a_up = PHYS_JETPACK_ACCEL_UP;
1256 float a_add = PHYS_JETPACK_ANTIGRAVITY * PHYS_GRAVITY;
1258 wishvel_x *= a_side;
1259 wishvel_y *= a_side;
1264 //////////////////////////////////////////////////////////////////////////////////////
1265 // finding the maximum over all vectors of above form
1266 // with wishvel having an absolute value of 1
1267 //////////////////////////////////////////////////////////////////////////////////////
1268 // we're finding the maximum over
1269 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1270 // for z in the range from -1 to 1
1271 //////////////////////////////////////////////////////////////////////////////////////
1272 // maximum is EITHER attained at the single extreme point:
1273 float a_diff = a_side * a_side - a_up * a_up;
1277 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1278 if (f > -1 && f < 1) // can it be attained?
1280 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1281 //print("middle\n");
1284 // OR attained at z = 1:
1285 f = (a_up + a_add) * (a_up + a_add);
1291 // OR attained at z = -1:
1292 f = (a_up - a_add) * (a_up - a_add);
1296 //print("bottom\n");
1299 //////////////////////////////////////////////////////////////////////////////////////
1301 //print("best possible acceleration: ", ftos(best), "\n");
1304 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE, 1);
1305 if (wishvel_z - PHYS_GRAVITY > 0)
1306 fz = bound(0, 1 - self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
1308 fz = bound(0, 1 + self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
1311 fvel = vlen(wishvel);
1314 wishvel_z = (wishvel_z - PHYS_GRAVITY) * fz + PHYS_GRAVITY;
1316 fvel = min(1, vlen(wishvel) / best);
1317 if (PHYS_JETPACK_FUEL && !(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO))
1318 f = min(1, PHYS_AMMO_FUEL(self) / (PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel));
1322 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1324 if (f > 0 && wishvel != '0 0 0')
1326 self.velocity = self.velocity + wishvel * f * PHYS_INPUT_TIMELENGTH;
1327 UNSET_ONGROUND(self);
1330 if (!(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO))
1331 self.ammo_fuel -= PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel * f;
1333 ITEMS(self) |= IT_USING_JETPACK;
1335 // jetpack also inhibits health regeneration, but only for 1 second
1336 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1341 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1342 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1343 self.velocity_z -= g * 0.5;
1345 self.velocity_z -= g;
1346 PM_ClientMovement_Move();
1347 if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1348 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1349 self.velocity_z -= g * 0.5;
1355 // if PHYS_INPUT_TIMELENGTH is 0 (due to client sending the same timestamp twice),
1357 if (PHYS_INPUT_TIMELENGTH <= 0)
1360 // if (autocvar_sv_gameplayfix_unstickplayers)
1361 // SV_CheckStuck (self);
1363 // applygravity = !SV_CheckWater(self) && self.movetype == MOVETYPE_WALK && !(self.flags & FL_WATERJUMP);
1365 // hitsupercontentsmask = SV_GenericHitSuperContentsMask(self);
1367 // SV_CheckVelocity(self);
1369 // do a regular slide move unless it looks like you ran into a step
1370 // float oldonground = self.flags & FL_ONGROUND;
1372 vector start_origin = self.origin;
1373 vector start_velocity = self.velocity;
1376 // clip = SV_FlyMove (self, PHYS_INPUT_TIMELENGTH, applygravity, NULL, hitsupercontentsmask, sv_gameplayfix_stepmultipletimes.integer ? sv_stepheight.value : 0);
1378 // if(sv_gameplayfix_downtracesupportsongroundflag.integer)
1381 // only try this if there was no floor in the way in the trace (no,
1382 // this check seems to be not REALLY necessary, because if clip & 1,
1383 // our trace will hit that thing too)
1384 vector upmove = self.origin;
1386 vector downmove = self.origin;
1389 if (self.movetype == MOVETYPE_FLYMISSILE)
1390 type = MOVE_MISSILE;
1391 else if (self.movetype == MOVETYPE_FLY_WORLDONLY)
1392 type = MOVE_WORLDONLY;
1393 else if (self.solid == SOLID_TRIGGER || self.solid == SOLID_NOT)
1394 type = MOVE_NOMONSTERS; // only clip against bmodels
1397 vector entmins = self.mins;
1398 vector entmaxs = self.maxs;
1399 tracebox(upmove, entmins, entmaxs, downmove, type, self);
1400 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
1401 clip |= 1; // but we HAVE found a floor
1404 // if the move did not hit the ground at any point, we're not on ground
1406 // self.flags = self.flags & ~FL_ONGROUND;
1408 // SV_CheckVelocity(self);
1409 // SV_LinkEdict(self);
1410 // SV_LinkEdict_TouchAreaGrid(self);
1412 if(clip & 8) // teleport
1415 if (self.flags & FL_WATERJUMP)
1418 // if (autocvar_sv_nostep)
1421 vector originalmove_origin = self.origin;
1422 vector originalmove_velocity = self.velocity;
1423 float originalmove_flags = self.flags;
1424 entity originalmove_groundentity = self.groundentity;
1426 // if move didn't block on a step, return
1429 // if move was not trying to move into the step, return
1430 if (fabs(start_velocity_x) < 0.03125 && fabs(start_velocity_y) < 0.03125)
1433 if (self.movetype != MOVETYPE_FLY)
1435 // return if gibbed by a trigger
1436 if (self.movetype != MOVETYPE_WALK)
1439 // return if attempting to jump while airborn (unless sv_jumpstep)
1440 // if (!autocvar_sv_jumpstep)
1441 // if (!oldonground && PRVM_serveredictfloat(self, waterlevel) == 0)
1445 // try moving up and forward to go up a step
1446 // back to start pos
1447 setorigin(self, start_origin);
1448 self.velocity = start_velocity;
1451 vector upmove = '0 0 0';
1452 upmove_z = autocvar_sv_stepheight;
1453 // if(!SV_PushEntity(&trace, self, upmove, true))
1455 // // we got teleported when upstepping... must abort the move
1460 self.velocity_z = 0;
1461 // clip = SV_FlyMove (self, PHYS_INPUT_TIMELENGTH, applygravity, stepnormal, hitsupercontentsmask, 0);
1462 self.velocity_z += start_velocity_z;
1465 // // we got teleported when upstepping... must abort the move
1466 // // note that z velocity handling may not be what QC expects here, but we cannot help it
1470 // SV_CheckVelocity(self);
1471 // SV_LinkEdict(self);
1472 // SV_LinkEdict_TouchAreaGrid(self);
1474 // check for stuckness, possibly due to the limited precision of floats
1475 // in the clipping hulls
1477 && fabs(originalmove_origin_y - self.origin_y < 0.03125)
1478 && fabs(originalmove_origin_x - self.origin_x < 0.03125))
1480 //Con_Printf("wall\n");
1481 // stepping up didn't make any progress, revert to original move
1482 setorigin(self, originalmove_origin);
1483 self.velocity = originalmove_velocity;
1484 self.flags = originalmove_flags;
1485 self.groundentity = originalmove_groundentity;
1489 //Con_Printf("step - ");
1491 // extra friction based on view angle
1492 // if (clip & 2 && sv_wallfriction.integer)
1493 // SV_WallFriction (self, stepnormal);
1495 // don't do the down move if stepdown is disabled, moving upward, not in water, or the move started offground or ended onground
1496 // else if (!autocvar_sv_gameplayfix_stepdown || self.waterlevel >= 3 || start_velocity_z >= (1.0 / 32.0) || !oldonground || (self.flags & FL_ONGROUND))
1500 vector downmove = '0 0 0';
1501 downmove_z = -autocvar_sv_stepheight + start_velocity_z*PHYS_INPUT_TIMELENGTH;
1502 // if(!SV_PushEntity (&downtrace, self, downmove, true))
1504 // // we got teleported when downstepping... must abort the move
1508 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
1510 // this has been disabled so that you can't jump when you are stepping
1511 // up while already jumping (also known as the Quake2 double jump bug)
1515 //Con_Printf("slope\n");
1516 // if the push down didn't end up on good ground, use the move without
1517 // the step up. This happens near wall / slope combinations, and can
1518 // cause the player to hop up higher on a slope too steep to climb
1519 setorigin(self, originalmove_origin);
1520 self.velocity = originalmove_velocity;
1521 self.flags = originalmove_flags;
1522 self.groundentity = originalmove_groundentity;
1525 // SV_CheckVelocity(self);
1526 // SV_LinkEdict(self);
1527 // SV_LinkEdict_TouchAreaGrid(self);
1530 void PM_walk(float buttons_prev, float maxspd_mod)
1532 if (!WAS_ONGROUND(self))
1534 if (autocvar_speedmeter)
1535 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1536 if (self.lastground < time - 0.3)
1537 self.velocity *= (1 - PHYS_FRICTION_ONLAND);
1538 if (self.jumppadcount > 1)
1539 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1540 self.jumppadcount = 0;
1543 makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1544 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1545 + v_right * PHYS_INPUT_MOVEVALUES(self).y;
1547 vector wishdir = normalize(wishvel);
1548 float wishspeed = vlen(wishvel);
1550 wishspeed = min(wishspeed, PHYS_MAXSPEED(self) * maxspd_mod);
1551 if (IS_DUCKED(self))
1554 // apply edge friction
1555 float f = vlen(vec2(self.velocity));
1559 trace_dphitq3surfaceflags = 0;
1560 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
1561 // TODO: apply edge friction
1562 // apply ground friction
1563 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK)
1564 realfriction = PHYS_FRICTION_SLICK;
1566 realfriction = PHYS_FRICTION;
1568 f = 1 - PHYS_INPUT_TIMELENGTH * realfriction * ((f < PHYS_STOPSPEED) ? (PHYS_STOPSPEED / f) : 1);
1572 Mathematical analysis time!
1574 Our goal is to invert this mess.
1576 For the two cases we get:
1577 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * (PHYS_STOPSPEED / v0) * PHYS_FRICTION)
1578 = v0 - PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION
1579 v0 = v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION
1581 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1582 v0 = v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1584 These cases would be chosen ONLY if:
1586 v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION < PHYS_STOPSPEED
1587 v < PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1589 v0 >= PHYS_STOPSPEED
1590 v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION) >= PHYS_STOPSPEED
1591 v >= PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1594 float addspeed = wishspeed - self.velocity * wishdir;
1597 float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
1598 self.velocity += accelspeed * wishdir;
1600 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1601 if (!(GAMEPLAYFIX_NOGRAVITYONGROUND))
1602 self.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1);
1603 if (self.velocity * self.velocity)
1604 PM_ClientMovement_Move();
1605 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1606 if (!IS_ONGROUND(self) || !GAMEPLAYFIX_NOGRAVITYONGROUND)
1607 self.velocity_z -= g * 0.5;
1610 void PM_air(float buttons_prev, float maxspd_mod)
1612 makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1613 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1614 + v_right * PHYS_INPUT_MOVEVALUES(self).y;
1616 vector wishdir = normalize(wishvel);
1617 float wishspeed = vlen(wishvel);
1620 if (time >= self.teleport_time)
1622 if (pmove_waterjumptime <= 0)
1625 float maxairspd = PHYS_MAXAIRSPEED * min(maxspd_mod, 1);
1627 // apply air speed limit
1628 float airaccelqw = PHYS_AIRACCEL_QW(self);
1629 float wishspeed0 = wishspeed;
1630 wishspeed = min(wishspeed, maxairspd);
1631 if (IS_DUCKED(self))
1633 float airaccel = PHYS_AIRACCELERATE * min(maxspd_mod, 1);
1635 float accelerating = (self.velocity * wishdir > 0);
1636 float wishspeed2 = wishspeed;
1639 if (PHYS_AIRSTOPACCELERATE)
1641 vector curdir = normalize(vec2(self.velocity));
1642 airaccel += (PHYS_AIRSTOPACCELERATE*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1644 // note that for straight forward jumping:
1645 // step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
1646 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1648 // dv/dt = accel * maxspeed (when slow)
1649 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1650 // log dv/dt = logaccel + logmaxspeed (when slow)
1651 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1652 float strafity = IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), -90) + IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), +90); // if one is nonzero, other is always zero
1653 if (PHYS_MAXAIRSTRAFESPEED)
1654 wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED*maxspd_mod));
1655 if (PHYS_AIRSTRAFEACCELERATE)
1656 airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE*maxspd_mod);
1657 if (PHYS_AIRSTRAFEACCEL_QW(self))
1659 (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(self) : PHYS_AIRACCEL_QW(self)) >= 0) ? +1 : -1)
1661 (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(self)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(self))));
1664 if (PHYS_WARSOWBUNNY_TURNACCEL && accelerating && PHYS_INPUT_MOVEVALUES(self).y == 0 && PHYS_INPUT_MOVEVALUES(self).x != 0)
1665 PM_AirAccelerate(wishdir, wishspeed2);
1667 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(self), PHYS_AIRACCEL_SIDEWAYS_FRICTION / maxairspd, PHYS_AIRSPEEDLIMIT_NONQW(self));
1669 if (PHYS_AIRCONTROL)
1670 CPM_PM_Aircontrol(wishdir, wishspeed2);
1672 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1673 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1674 self.velocity_z -= g * 0.5;
1676 self.velocity_z -= g;
1677 PM_ClientMovement_Move();
1678 if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1679 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1680 self.velocity_z -= g * 0.5;
1683 // used for calculating airshots
1684 bool IsFlying(entity a)
1688 if(a.waterlevel >= WATERLEVEL_SWIMMING)
1690 traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
1691 if(trace_fraction < 1)
1698 float buttons = PHYS_INPUT_BUTTON_MASK(self);
1700 self.team = myteam + 1; // is this correct?
1701 if (!(PHYS_INPUT_BUTTON_JUMP(self))) // !jump
1702 UNSET_JUMP_HELD(self); // canjump = true
1703 pmove_waterjumptime -= PHYS_INPUT_TIMELENGTH;
1705 PM_ClientMovement_UpdateStatus(true);
1710 WarpZone_PlayerPhysics_FixVAngle();
1712 float maxspeed_mod = 1;
1713 maxspeed_mod *= PM_check_keepaway();
1714 maxspeed_mod *= PHYS_HIGHSPEED;
1717 Physics_UpdateStats(maxspeed_mod);
1719 if (self.PlayerPhysplug)
1720 if (self.PlayerPhysplug())
1724 PM_check_race_movetime();
1726 anticheat_physics();
1729 if (PM_check_specialcommand(buttons))
1734 if (buttons != self.buttons_old || PHYS_INPUT_MOVEVALUES(self) != self.movement_old || PHYS_INPUT_ANGLES(self) != self.v_angle_old)
1735 self.parm_idlesince = time;
1738 float buttons_prev = self.buttons_old;
1739 self.buttons_old = buttons;
1740 self.movement_old = PHYS_INPUT_MOVEVALUES(self);
1741 self.v_angle_old = PHYS_INPUT_ANGLES(self);
1743 PM_check_nickspam();
1747 if (IS_BOT_CLIENT(self))
1749 if (playerdemo_read())
1754 if (IS_PLAYER(self))
1758 if (self.race_penalty)
1759 if (time > self.race_penalty)
1760 self.race_penalty = 0;
1763 float not_allowed_to_move = 0;
1765 if (self.race_penalty)
1766 not_allowed_to_move = 1;
1769 if (time < game_starttime)
1770 not_allowed_to_move = 1;
1773 if (not_allowed_to_move)
1775 self.velocity = '0 0 0';
1776 self.movetype = MOVETYPE_NONE;
1778 self.disableclientprediction = 2;
1782 else if (self.disableclientprediction == 2)
1784 if (self.movetype == MOVETYPE_NONE)
1785 self.movetype = MOVETYPE_WALK;
1786 self.disableclientprediction = 0;
1792 if (self.movetype == MOVETYPE_NONE)
1795 // when we get here, disableclientprediction cannot be 2
1796 self.disableclientprediction = 0;
1808 maxspeed_mod *= self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
1810 // conveyors: first fix velocity
1811 if (self.conveyor.state)
1812 self.velocity -= self.conveyor.movedir;
1815 MUTATOR_CALLHOOK(PlayerPhysics);
1821 // float forcedodge = 1;
1824 // PM_dodging_checkpressedkeys();
1827 // PM_ClientMovement_Move();
1832 if (!IS_PLAYER(self))
1834 maxspeed_mod *= autocvar_sv_spectator_speed_multiplier;
1835 if (!self.spectatorspeed)
1836 self.spectatorspeed = maxspeed_mod;
1837 if (self.impulse && self.impulse <= 19 || (self.impulse >= 200 && self.impulse <= 209) || (self.impulse >= 220 && self.impulse <= 229))
1839 if (self.lastclassname != "player")
1841 if (self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209))
1842 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
1843 else if (self.impulse == 11)
1844 self.spectatorspeed = maxspeed_mod;
1845 else if (self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229))
1846 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
1847 else if (self.impulse >= 1 && self.impulse <= 9)
1848 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
1849 } // otherwise just clear
1852 maxspeed_mod *= self.spectatorspeed;
1860 if (!self.fixangle && !g_bugrigs)
1861 self.angles = '0 1 0' * PHYS_INPUT_ANGLES(self).y;
1864 PM_check_hitground();
1869 if (IS_PLAYER(self))
1872 if (self.flags & /* FL_WATERJUMP */ 2048)
1874 self.velocity_x = self.movedir_x;
1875 self.velocity_y = self.movedir_y;
1876 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
1878 self.flags &= ~/* FL_WATERJUMP */ 2048;
1879 self.teleport_time = 0;
1884 else if (g_bugrigs && IS_PLAYER(self))
1888 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
1889 PM_fly(maxspeed_mod);
1891 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
1892 PM_swim(maxspeed_mod);
1894 else if (time < self.ladder_time)
1895 PM_ladder(maxspeed_mod);
1897 else if (ITEMS(self) & IT_USING_JETPACK)
1898 PM_jetpack(maxspeed_mod);
1900 else if (IS_ONGROUND(self))
1901 PM_walk(buttons_prev, maxspeed_mod);
1904 PM_air(buttons_prev, maxspeed_mod);
1907 if (!IS_OBSERVER(self))
1913 if (IS_ONGROUND(self))
1914 self.lastground = time;
1916 // conveyors: then break velocity again
1917 if(self.conveyor.state)
1918 self.velocity += self.conveyor.movedir;
1920 self.lastflags = FLAGS(self);
1922 self.lastclassname = self.classname;
1926 void SV_PlayerPhysics(void)
1928 void CSQC_ClientMovement_PlayerMove_Frame(void)
1934 pmove_org = self.origin;
1935 pmove_vel = self.velocity;