13 .string lastclassname;
15 .float() PlayerPhysplug;
16 float AdjustAirAccelQW(float accelqw, float factor);
23 .float stat_sv_airaccel_qw;
24 .float stat_sv_airstrafeaccel_qw;
25 .float stat_sv_airspeedlimit_nonqw;
26 .float stat_sv_maxspeed;
27 .float stat_movement_highspeed;
29 .float stat_doublejump;
31 .float stat_jumpspeedcap_min;
32 .float stat_jumpspeedcap_max;
33 .float stat_jumpspeedcap_disable_onramps;
35 .float stat_jetpack_accel_side;
36 .float stat_jetpack_accel_up;
37 .float stat_jetpack_antigravity;
38 .float stat_jetpack_fuel;
39 .float stat_jetpack_maxspeed_up;
40 .float stat_jetpack_maxspeed_side;
42 void Physics_AddStats()
44 // g_movementspeed hack
45 addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
46 addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
47 addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
48 addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
49 addstat(STAT_MOVEVARS_HIGHSPEED, AS_FLOAT, stat_movement_highspeed);
52 addstat(STAT_JETPACK_ACCEL_SIDE, AS_FLOAT, stat_jetpack_accel_side);
53 addstat(STAT_JETPACK_ACCEL_UP, AS_FLOAT, stat_jetpack_accel_up);
54 addstat(STAT_JETPACK_ANTIGRAVITY, AS_FLOAT, stat_jetpack_antigravity);
55 addstat(STAT_JETPACK_FUEL, AS_FLOAT, stat_jetpack_fuel);
56 addstat(STAT_JETPACK_MAXSPEED_UP, AS_FLOAT, stat_jetpack_maxspeed_up);
57 addstat(STAT_JETPACK_MAXSPEED_SIDE, AS_FLOAT, stat_jetpack_maxspeed_side);
59 // hack to fix track_canjump
60 addstat(STAT_MOVEVARS_TRACK_CANJUMP, AS_INT, cvar_cl_movement_track_canjump);
63 addstat(STAT_DOUBLEJUMP, AS_INT, stat_doublejump);
66 addstat(STAT_MOVEVARS_JUMPSPEEDCAP_MIN, AS_FLOAT, stat_jumpspeedcap_min);
67 addstat(STAT_MOVEVARS_JUMPSPEEDCAP_MIN, AS_FLOAT, stat_jumpspeedcap_min);
68 addstat(STAT_MOVEVARS_JUMPSPEEDCAP_DISABLE_ONRAMPS, AS_INT, stat_jumpspeedcap_disable_onramps);
71 void Physics_UpdateStats(float maxspd_mod)
73 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
74 if (autocvar_sv_airstrafeaccel_qw)
75 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
77 self.stat_sv_airstrafeaccel_qw = 0;
78 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
79 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
80 self.stat_movement_highspeed = PHYS_HIGHSPEED; // TODO: remove this!
82 self.stat_doublejump = PHYS_DOUBLEJUMP;
84 self.stat_jetpack_antigravity = PHYS_JETPACK_ANTIGRAVITY;
85 self.stat_jetpack_accel_up = PHYS_JETPACK_ACCEL_UP;
86 self.stat_jetpack_accel_side = PHYS_JETPACK_ACCEL_SIDE;
87 self.stat_jetpack_maxspeed_side = PHYS_JETPACK_MAXSPEED_SIDE;
88 self.stat_jetpack_maxspeed_up = PHYS_JETPACK_MAXSPEED_UP;
89 self.stat_jetpack_fuel = PHYS_JETPACK_FUEL;
91 self.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MIN;
92 self.stat_jumpspeedcap_max = PHYS_JUMPSPEEDCAP_MAX;
93 self.stat_jumpspeedcap_disable_onramps = PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS;
97 float IsMoveInDirection(vector mv, float angle) // key mix factor
99 if (mv_x == 0 && mv_y == 0)
100 return 0; // avoid division by zero
101 angle -= RAD2DEG * atan2(mv_y, mv_x);
102 angle = remainder(angle, 360) / 45;
103 return angle > 1 ? 0 : angle < -1 ? 0 : 1 - fabs(angle);
106 float GeomLerp(float a, float lerp, float b)
108 return a == 0 ? (lerp < 1 ? 0 : b)
109 : b == 0 ? (lerp > 0 ? 0 : a)
110 : a * pow(fabs(b / a), lerp);
113 noref float pmove_waterjumptime;
115 const float unstick_count = 27;
116 vector unstick_offsets[unstick_count] =
118 // 1 no nudge (just return the original if this test passes)
121 ' 0.000 0.000 0.125', '0.000 0.000 -0.125',
122 '-0.125 0.000 0.000', '0.125 0.000 0.000',
123 ' 0.000 -0.125 0.000', '0.000 0.125 0.000',
124 // 4 diagonal flat nudges
125 '-0.125 -0.125 0.000', '0.125 -0.125 0.000',
126 '-0.125 0.125 0.000', '0.125 0.125 0.000',
127 // 8 diagonal upward nudges
128 '-0.125 0.000 0.125', '0.125 0.000 0.125',
129 ' 0.000 -0.125 0.125', '0.000 0.125 0.125',
130 '-0.125 -0.125 0.125', '0.125 -0.125 0.125',
131 '-0.125 0.125 0.125', '0.125 0.125 0.125',
132 // 8 diagonal downward nudges
133 '-0.125 0.000 -0.125', '0.125 0.000 -0.125',
134 ' 0.000 -0.125 -0.125', '0.000 0.125 -0.125',
135 '-0.125 -0.125 -0.125', '0.125 -0.125 -0.125',
136 '-0.125 0.125 -0.125', '0.125 0.125 -0.125',
139 void PM_ClientMovement_Unstick()
142 for (i = 0; i < unstick_count; i++)
144 vector neworigin = unstick_offsets[i] + self.origin;
145 tracebox(neworigin, PL_CROUCH_MIN, PL_CROUCH_MAX, neworigin, MOVE_NORMAL, self);
146 if (!trace_startsolid)
148 self.origin = neworigin;
154 void PM_ClientMovement_UpdateStatus()
156 // make sure player is not stuck
157 PM_ClientMovement_Unstick();
160 if (PHYS_INPUT_BUTTON_CROUCH(self))
162 // wants to crouch, this always works..
163 if (!IS_DUCKED(self))
168 // wants to stand, if currently crouching we need to check for a
172 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, MOVE_NORMAL, self);
173 if (!trace_startsolid)
179 vector origin1 = self.origin + '0 0 1';
180 vector origin2 = self.origin - '0 0 1';
182 tracebox(origin1, self.mins, self.maxs, origin2, MOVE_NORMAL, self);
183 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
187 // this code actually "predicts" an impact; so let's clip velocity first
188 float f = self.velocity * trace_plane_normal;
189 if (f < 0) // only if moving downwards actually
190 self.velocity -= f * trace_plane_normal;
193 UNSET_ONGROUND(self);
195 // set watertype/waterlevel
196 origin1 = self.origin;
197 origin1_z += self.mins_z + 1;
198 self.waterlevel = WATERLEVEL_NONE;
200 self.watertype = (pointcontents(origin1) == CONTENT_WATER);
204 self.waterlevel = WATERLEVEL_WETFEET;
205 origin1_z = self.origin_z + (self.mins_z + self.maxs_z) * 0.5;
206 if(pointcontents(origin1) == CONTENT_WATER)
208 self.waterlevel = WATERLEVEL_SWIMMING;
209 origin1_z = self.origin_z + 22;
210 if(pointcontents(origin1) == CONTENT_WATER)
211 self.waterlevel = WATERLEVEL_SUBMERGED;
215 if(IS_ONGROUND(self) || self.velocity_z <= 0 || pmove_waterjumptime <= 0)
216 pmove_waterjumptime = 0;
219 void PM_ClientMovement_Move()
222 float t = PHYS_INPUT_TIMELENGTH;
223 vector primalvelocity = self.velocity;
224 PM_ClientMovement_UpdateStatus();
226 for (bump = 0; bump < 8 && self.velocity * self.velocity > 0; bump++)
228 vector neworigin = self.origin + t * self.velocity;
229 tracebox(self.origin, self.mins, self.maxs, neworigin, MOVE_NORMAL, self);
230 float old_trace1_fraction = trace_fraction;
231 vector old_trace1_endpos = trace_endpos;
232 vector old_trace1_plane_normal = trace_plane_normal;
233 if (trace_fraction < 1 && trace_plane_normal_z == 0)
235 // may be a step or wall, try stepping up
236 // first move forward at a higher level
237 vector currentorigin2 = self.origin;
238 currentorigin2_z += PHYS_STEPHEIGHT;
239 vector neworigin2 = neworigin;
240 neworigin2_z = self.origin_z + PHYS_STEPHEIGHT;
241 tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
242 if (!trace_startsolid)
244 // then move down from there
245 currentorigin2 = trace_endpos;
246 neworigin2 = trace_endpos;
247 neworigin2_z = self.origin_z;
248 float old_trace2_fraction = trace_fraction;
249 vector old_trace2_plane_normal = trace_plane_normal;
250 tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
251 // accept the new trace if it made some progress
252 if (fabs(trace_endpos_x - old_trace1_endpos_x) >= 0.03125 || fabs(trace_endpos_y - old_trace1_endpos_y) >= 0.03125)
254 trace_fraction = old_trace2_fraction;
255 trace_endpos = trace_endpos;
256 trace_plane_normal = old_trace2_plane_normal;
260 trace_fraction = old_trace1_fraction;
261 trace_endpos = old_trace1_endpos;
262 trace_plane_normal = old_trace1_plane_normal;
267 // check if it moved at all
268 if (trace_fraction >= 0.001)
269 self.origin = trace_endpos;
271 // check if it moved all the way
272 if (trace_fraction == 1)
275 // this is only really needed for nogravityonground combined with gravityunaffectedbyticrate
276 // <LordHavoc> I'm pretty sure I commented it out solely because it seemed redundant
277 // this got commented out in a change that supposedly makes the code match QW better
278 // so if this is broken, maybe put it in an if (cls.protocol != PROTOCOL_QUAKEWORLD) block
279 if (trace_plane_normal_z > 0.7)
282 t -= t * trace_fraction;
284 float f = self.velocity * trace_plane_normal;
285 self.velocity -= f * trace_plane_normal;
287 if (pmove_waterjumptime > 0)
288 self.velocity = primalvelocity;
292 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
294 float k = 32 * (2 * IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), 0) - 1);
298 k *= bound(0, wishspeed / PHYS_MAXAIRSPEED, 1);
300 float zspeed = self.velocity_z;
302 float xyspeed = vlen(self.velocity);
303 self.velocity = normalize(self.velocity);
305 float dot = self.velocity * wishdir;
307 if (dot > 0) // we can't change direction while slowing down
309 k *= pow(dot, PHYS_AIRCONTROL_POWER)*PHYS_INPUT_TIMELENGTH;
310 xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY * sqrt(max(0, 1 - dot*dot)) * k/32);
311 k *= PHYS_AIRCONTROL;
312 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
315 self.velocity = self.velocity * xyspeed;
316 self.velocity_z = zspeed;
319 float AdjustAirAccelQW(float accelqw, float factor)
321 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
324 // example config for alternate speed clamping:
325 // sv_airaccel_qw 0.8
326 // sv_airaccel_sideways_friction 0
327 // prvm_globalset server speedclamp_mode 1
329 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
331 float speedclamp = stretchfactor > 0 ? stretchfactor
332 : accelqw < 0 ? 1 // full clamping, no stretch
335 accelqw = fabs(accelqw);
337 if (GAMEPLAYFIX_Q2AIRACCELERATE)
338 wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
340 float vel_straight = self.velocity * wishdir;
341 float vel_z = self.velocity_z;
342 vector vel_xy = vec2(self.velocity);
343 vector vel_perpend = vel_xy - vel_straight * wishdir;
345 float step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
347 float vel_xy_current = vlen(vel_xy);
349 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
350 float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
351 float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
352 vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
353 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
355 if (sidefric < 0 && (vel_perpend*vel_perpend))
356 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
358 float f = max(0, 1 + PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
359 float fmin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
361 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
362 // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
363 // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
364 // obviously, this cannot be
370 vel_perpend *= max(fmin, f);
374 vel_perpend *= max(0, 1 - PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
376 vel_xy = vel_straight * wishdir + vel_perpend;
380 float vel_xy_preclamp;
381 vel_xy_preclamp = vlen(vel_xy);
382 if (vel_xy_preclamp > 0) // prevent division by zero
384 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
385 if (vel_xy_current < vel_xy_preclamp)
386 vel_xy *= (vel_xy_current / vel_xy_preclamp);
390 self.velocity = vel_xy + vel_z * '0 0 1';
393 void PM_AirAccelerate(vector wishdir, float wishspeed)
398 vector curvel = self.velocity;
400 float curspeed = vlen(curvel);
402 if (wishspeed > curspeed * 1.01)
403 wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH);
406 float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED - PHYS_MAXSPEED(self)));
407 wishspeed = max(curspeed, PHYS_MAXSPEED(self)) + PHYS_WARSOWBUNNY_ACCEL * f * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH;
409 vector wishvel = wishdir * wishspeed;
410 vector acceldir = wishvel - curvel;
411 float addspeed = vlen(acceldir);
412 acceldir = normalize(acceldir);
414 float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH);
416 if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO < 1)
418 vector curdir = normalize(curvel);
419 float dot = acceldir * curdir;
421 acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO) * dot * curdir;
424 self.velocity += accelspeed * acceldir;
432 When you press the jump key
433 returns TRUE if handled
436 float PlayerJump (void)
438 if (PHYS_FROZEN(self))
439 return TRUE; // no jumping in freezetag when frozen
442 if (self.player_blocked)
443 return TRUE; // no jumping while blocked
446 float doublejump = FALSE;
447 float mjumpheight = PHYS_JUMPVELOCITY;
449 player_multijump = doublejump;
450 player_jumpheight = mjumpheight;
452 if (MUTATOR_CALLHOOK(PlayerJump))
454 if(PM_multijump_checkjump())
458 doublejump = player_multijump;
459 mjumpheight = player_jumpheight;
463 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
464 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
468 // we MUST clip velocity here!
470 f = self.velocity * trace_plane_normal;
472 self.velocity -= f * trace_plane_normal;
476 if (self.waterlevel >= WATERLEVEL_SWIMMING)
478 self.velocity_z = PHYS_MAXSPEED(self) * 0.7;
483 if (!IS_ONGROUND(self))
484 return IS_JUMP_HELD(self);
486 if (PHYS_TRACK_CANJUMP(self))
487 if (IS_JUMP_HELD(self))
490 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
491 // velocity bounds. Final velocity is bound between (jumpheight *
492 // min + jumpheight) and (jumpheight * max + jumpheight);
494 if(PHYS_JUMPSPEEDCAP_MIN)
496 float minjumpspeed = mjumpheight * PHYS_JUMPSPEEDCAP_MIN;
498 if (self.velocity_z < minjumpspeed)
499 mjumpheight += minjumpspeed - self.velocity_z;
502 if(PHYS_JUMPSPEEDCAP_MAX)
504 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
505 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
507 if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS))
509 float maxjumpspeed = mjumpheight * PHYS_JUMPSPEEDCAP_MAX;
511 if (self.velocity_z > maxjumpspeed)
512 mjumpheight -= self.velocity_z - maxjumpspeed;
516 if (!WAS_ONGROUND(self))
518 if(autocvar_speedmeter)
519 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
520 if(self.lastground < time - 0.3)
522 self.velocity_x *= (1 - PHYS_FRICTION_ONLAND);
523 self.velocity_y *= (1 - PHYS_FRICTION_ONLAND);
525 if(self.jumppadcount > 1)
526 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
527 self.jumppadcount = 0;
530 self.velocity_z += mjumpheight;
532 UNSET_ONGROUND(self);
537 self.oldvelocity_z = self.velocity_z;
539 animdecide_setaction(self, ANIMACTION_JUMP, TRUE);
541 if (autocvar_g_jump_grunt)
542 PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
547 void CheckWaterJump()
549 // check for a jump-out-of-water
550 makevectors(PHYS_INPUT_ANGLES(self));
551 vector start = self.origin;
554 normalize(v_forward);
555 vector end = start + v_forward*24;
556 traceline (start, end, TRUE, self);
557 if (trace_fraction < 1)
559 start_z = start_z + self.maxs_z - 8;
560 end = start + v_forward*24;
561 self.movedir = trace_plane_normal * -50;
562 traceline(start, end, TRUE, self);
563 if (trace_fraction == 1)
564 { // open at eye level
565 self.velocity_z = 225;
567 self.flags |= FL_WATERJUMP;
569 self.teleport_time = time + 2; // safety net
577 #define JETPACK_JUMP(s) s.cvar_cl_jetpack_jump
579 float autocvar_cl_jetpack_jump;
580 #define JETPACK_JUMP(s) autocvar_cl_jetpack_jump
582 .float jetpack_stopped;
583 // Hack: shouldn't need to know about this
584 .float multijump_count;
585 void CheckPlayerJump()
588 float was_flying = ITEMS(self) & IT_USING_JETPACK;
590 if (JETPACK_JUMP(self) < 2)
592 ITEMS(self) &= ~IT_USING_JETPACK;
595 if(PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_JETPACK(self))
598 float air_jump = !PlayerJump() || self.multijump_count > 0; // PlayerJump() has important side effects
599 float activate = JETPACK_JUMP(self) && air_jump && PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_JETPACK(self);
600 float has_fuel = !autocvar_g_jetpack_fuel || self.ammo_fuel || ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO;
602 PlayerJump(); // Client only
603 float has_fuel = TRUE; // TODO
605 if (!(ITEMS(self) & IT_JETPACK)) { }
606 else if (self.jetpack_stopped) { }
610 if (was_flying) // TODO: ran out of fuel message
611 Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL);
613 Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL);
615 self.jetpack_stopped = TRUE;
617 ITEMS(self) &= ~IT_USING_JETPACK;
621 else if (activate && !PHYS_FROZEN(self))
622 ITEMS(self) |= IT_USING_JETPACK;
627 self.jetpack_stopped = FALSE;
629 ITEMS(self) &= ~IT_USING_JETPACK;
632 if (!PHYS_INPUT_BUTTON_JUMP(self))
633 UNSET_JUMP_HELD(self);
635 if (self.waterlevel == WATERLEVEL_SWIMMING)
639 float racecar_angle(float forward, float down)
647 float ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
649 float angle_mult = forward / (800 + forward);
652 return ret * angle_mult + 360 * (1 - angle_mult);
654 return ret * angle_mult;
657 void RaceCarPhysics()
660 // using this move type for "big rigs"
661 // the engine does not push the entity!
665 vector angles_save = self.angles;
666 float accel = bound(-1, PHYS_INPUT_MOVEVALUES(self).x / PHYS_MAXSPEED(self), 1);
667 float steer = bound(-1, PHYS_INPUT_MOVEVALUES(self).y / PHYS_MAXSPEED(self), 1);
669 if (g_bugrigs_reverse_speeding)
673 // back accel is DIGITAL
674 // to prevent speedhack
684 makevectors(self.angles); // new forward direction!
686 if (IS_ONGROUND(self) || g_bugrigs_air_steering)
688 float myspeed = self.velocity * v_forward;
689 float upspeed = self.velocity * v_up;
691 // responsiveness factor for steering and acceleration
692 float f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
693 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
696 if (myspeed < 0 && g_bugrigs_reverse_spinning)
697 steerfactor = -myspeed * g_bugrigs_steer;
699 steerfactor = -myspeed * f * g_bugrigs_steer;
702 if (myspeed < 0 && g_bugrigs_reverse_speeding)
703 accelfactor = g_bugrigs_accel;
705 accelfactor = f * g_bugrigs_accel;
706 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
712 myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
716 if (!g_bugrigs_reverse_speeding)
717 myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
724 myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
728 if (g_bugrigs_reverse_stopping)
731 myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
734 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
735 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
737 self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
738 makevectors(self.angles); // new forward direction!
740 myspeed += accel * accelfactor * PHYS_INPUT_TIMELENGTH;
742 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
746 float myspeed = vlen(self.velocity);
748 // responsiveness factor for steering and acceleration
749 float f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
750 float steerfactor = -myspeed * f;
751 self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
753 rigvel = self.velocity;
754 makevectors(self.angles); // new forward direction!
757 rigvel *= max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * PHYS_INPUT_TIMELENGTH);
758 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
759 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
760 //MAXIMA: solve(total_acceleration(v) = 0, v);
762 if (g_bugrigs_planar_movement)
764 vector rigvel_xy, neworigin, up;
767 rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
768 rigvel_xy = vec2(rigvel);
770 if (g_bugrigs_planar_movement_car_jumping)
773 mt = MOVE_NOMONSTERS;
775 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
776 up = trace_endpos - self.origin;
778 // BUG RIGS: align the move to the surface instead of doing collision testing
780 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * PHYS_INPUT_TIMELENGTH, mt, self);
783 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * PHYS_INPUT_TIMELENGTH, mt, self);
785 if (trace_fraction < 0.5)
788 neworigin = self.origin;
791 neworigin = trace_endpos;
793 if (trace_fraction < 1)
795 // now set angles_x so that the car points parallel to the surface
796 self.angles = vectoangles(
797 '1 0 0' * v_forward_x * trace_plane_normal_z
799 '0 1 0' * v_forward_y * trace_plane_normal_z
801 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
807 // now set angles_x so that the car points forward, but is tilted in velocity direction
808 UNSET_ONGROUND(self);
811 self.velocity = (neworigin - self.origin) * (1.0 / PHYS_INPUT_TIMELENGTH);
812 self.movetype = MOVETYPE_NOCLIP;
816 rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
817 self.velocity = rigvel;
818 self.movetype = MOVETYPE_FLY;
822 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
823 if (trace_fraction != 1)
825 self.angles = vectoangles2(
826 '1 0 0' * v_forward_x * trace_plane_normal_z
828 '0 1 0' * v_forward_y * trace_plane_normal_z
830 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
838 vel_local_x = v_forward * self.velocity;
839 vel_local_y = v_right * self.velocity;
840 vel_local_z = v_up * self.velocity;
842 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
843 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
847 vector vf1, vu1, smoothangles;
848 makevectors(self.angles);
849 float f = bound(0, PHYS_INPUT_TIMELENGTH * g_bugrigs_angle_smoothing, 1);
854 makevectors(angles_save);
855 vf1 = vf1 + v_forward * (1 - f);
856 vu1 = vu1 + v_up * (1 - f);
857 smoothangles = vectoangles2(vf1, vu1);
858 self.angles_x = -smoothangles_x;
859 self.angles_z = smoothangles_z;
863 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
864 .float specialcommand_pos;
865 void SpecialCommand()
871 if (!CheatImpulse(99))
872 print("A hollow voice says \"Plugh\".\n");
878 float speedaward_speed;
879 string speedaward_holder;
880 string speedaward_uid;
882 void race_send_speedaward(float msg)
885 // send the best speed of the round
886 WriteByte(msg, SVC_TEMPENTITY);
887 WriteByte(msg, TE_CSQC_RACE);
888 WriteByte(msg, RACE_NET_SPEED_AWARD);
889 WriteInt24_t(msg, floor(speedaward_speed+0.5));
890 WriteString(msg, speedaward_holder);
895 float speedaward_alltimebest;
896 string speedaward_alltimebest_holder;
897 string speedaward_alltimebest_uid;
899 void race_send_speedaward_alltimebest(float msg)
902 // send the best speed
903 WriteByte(msg, SVC_TEMPENTITY);
904 WriteByte(msg, TE_CSQC_RACE);
905 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
906 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
907 WriteString(msg, speedaward_alltimebest_holder);
911 float PM_check_keepaway(void)
914 return (self.ballcarried && g_keepaway) ? autocvar_g_keepaway_ballcarrier_highspeed : 1;
920 void PM_check_race_movetime(void)
923 self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
924 float f = floor(self.race_movetime_frac);
925 self.race_movetime_frac -= f;
926 self.race_movetime_count += f;
927 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
931 float PM_check_specialcommand(float buttons)
937 else if (buttons == 1)
939 else if (buttons == 2)
941 else if (buttons == 128)
943 else if (buttons == 256)
945 else if (buttons == 512)
947 else if (buttons == 1024)
952 if (c == substring(specialcommand, self.specialcommand_pos, 1))
954 self.specialcommand_pos += 1;
955 if (self.specialcommand_pos >= strlen(specialcommand))
957 self.specialcommand_pos = 0;
962 else if (self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
963 self.specialcommand_pos = 0;
968 void PM_check_nickspam(void)
971 if (time >= self.nickspamtime)
973 if (self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
975 // slight annoyance for nick change scripts
976 PHYS_INPUT_MOVEVALUES(self) = -1 * PHYS_INPUT_MOVEVALUES(self);
977 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
979 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!
981 PHYS_INPUT_ANGLES(self)_x = random() * 360;
982 PHYS_INPUT_ANGLES(self)_y = random() * 360;
983 // at least I'm not forcing retardedview by also assigning to angles_z
984 self.fixangle = TRUE;
990 void PM_check_punch()
993 if (self.punchangle != '0 0 0')
995 float f = vlen(self.punchangle) - 10 * PHYS_INPUT_TIMELENGTH;
997 self.punchangle = normalize(self.punchangle) * f;
999 self.punchangle = '0 0 0';
1002 if (self.punchvector != '0 0 0')
1004 float f = vlen(self.punchvector) - 30 * PHYS_INPUT_TIMELENGTH;
1006 self.punchvector = normalize(self.punchvector) * f;
1008 self.punchvector = '0 0 0';
1013 void PM_check_spider(void)
1016 if (time >= self.spider_slowness)
1018 PHYS_MAXSPEED(self) *= 0.5; // half speed while slow from spider
1019 self.stat_sv_airspeedlimit_nonqw *= 0.5;
1023 // predict frozen movement, as frozen players CAN move in some cases
1024 void PM_check_frozen(void)
1026 if (!PHYS_FROZEN(self))
1028 if (PHYS_DODGING_FROZEN
1030 && IS_REAL_CLIENT(self)
1034 PHYS_INPUT_MOVEVALUES(self)_x = bound(-5, PHYS_INPUT_MOVEVALUES(self).x, 5);
1035 PHYS_INPUT_MOVEVALUES(self)_y = bound(-5, PHYS_INPUT_MOVEVALUES(self).y, 5);
1036 PHYS_INPUT_MOVEVALUES(self)_z = bound(-5, PHYS_INPUT_MOVEVALUES(self).z, 5);
1039 PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
1041 vector midpoint = ((self.absmin + self.absmax) * 0.5);
1042 if (pointcontents(midpoint) == CONTENT_WATER)
1044 self.velocity = self.velocity * 0.5;
1046 if (pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
1047 self.velocity_z = 200;
1051 void PM_check_blocked(void)
1054 if (!self.player_blocked)
1056 PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
1057 self.disableclientprediction = 1;
1062 float speedaward_lastsent;
1063 float speedaward_lastupdate;
1064 string GetMapname(void);
1066 void PM_check_race(void)
1069 if not(g_cts || g_race)
1071 if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
1073 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1074 speedaward_holder = self.netname;
1075 speedaward_uid = self.crypto_idfp;
1076 speedaward_lastupdate = time;
1078 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
1080 string rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
1081 race_send_speedaward(MSG_ALL);
1082 speedaward_lastsent = speedaward_speed;
1083 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
1085 speedaward_alltimebest = speedaward_speed;
1086 speedaward_alltimebest_holder = speedaward_holder;
1087 speedaward_alltimebest_uid = speedaward_uid;
1088 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1089 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1090 race_send_speedaward_alltimebest(MSG_ALL);
1096 void PM_check_vortex(void)
1100 float xyspeed = vlen(vec2(self.velocity));
1101 if (self.weapon == WEP_VORTEX && WEP_CVAR(vortex, charge) && WEP_CVAR(vortex, charge_velocity_rate) && xyspeed > WEP_CVAR(vortex, charge_minspeed))
1103 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1104 xyspeed = min(xyspeed, WEP_CVAR(vortex, charge_maxspeed));
1105 float f = (xyspeed - WEP_CVAR(vortex, charge_minspeed)) / (WEP_CVAR(vortex, charge_maxspeed) - WEP_CVAR(vortex, charge_minspeed));
1106 // add the extra charge
1107 self.vortex_charge = min(1, self.vortex_charge + WEP_CVAR(vortex, charge_velocity_rate) * f * PHYS_INPUT_TIMELENGTH);
1112 void PM_fly(float maxspd_mod)
1114 // noclipping or flying
1115 UNSET_ONGROUND(self);
1117 self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
1118 makevectors(PHYS_INPUT_ANGLES(self));
1119 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1120 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1121 + v_right * PHYS_INPUT_MOVEVALUES(self).y
1122 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
1124 vector wishdir = normalize(wishvel);
1125 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod);
1126 if (time >= self.teleport_time)
1127 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
1130 void PM_swim(float maxspd_mod)
1133 UNSET_ONGROUND(self);
1135 float jump = PHYS_INPUT_BUTTON_JUMP(self);
1136 // water jump only in certain situations
1137 // this mimics quakeworld code
1138 if (jump && self.waterlevel == WATERLEVEL_SWIMMING && self.velocity_z >= -180)
1140 vector yawangles = '0 1 0' * PHYS_INPUT_ANGLES(self).y;
1141 makevectors(yawangles);
1142 vector forward = v_forward;
1143 vector spot = self.origin + 24 * forward;
1145 traceline(spot, spot, MOVE_NOMONSTERS, self);
1146 if (trace_startsolid)
1149 traceline(spot, spot, MOVE_NOMONSTERS, self);
1150 if (!trace_startsolid)
1152 self.velocity = forward * 50;
1153 self.velocity_z = 310;
1154 pmove_waterjumptime = 2;
1155 UNSET_ONGROUND(self);
1156 SET_JUMP_HELD(self);
1160 makevectors(PHYS_INPUT_ANGLES(self));
1161 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1162 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1163 + v_right * PHYS_INPUT_MOVEVALUES(self).y
1164 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
1165 if (wishvel == '0 0 0')
1166 wishvel = '0 0 -60'; // drift towards bottom
1168 vector wishdir = normalize(wishvel);
1169 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod) * 0.7;
1171 if (IS_DUCKED(self))
1174 // if (pmove_waterjumptime <= 0) // TODO: use
1177 float f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION;
1178 f = min(max(0, f), 1);
1181 f = wishspeed - self.velocity * wishdir;
1184 float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, f);
1185 self.velocity += accelspeed * wishdir;
1188 // holding jump button swims upward slowly
1192 if (self.watertype & CONTENT_LAVA)
1193 self.velocity_z = 50;
1194 else if (self.watertype & CONTENT_SLIME)
1195 self.velocity_z = 80;
1198 if (IS_NEXUIZ_DERIVED(gamemode))
1200 self.velocity_z = 200;
1203 self.velocity_z = 100;
1208 PM_ClientMovement_Move();
1209 // water acceleration
1210 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
1213 void PM_ladder(float maxspd_mod)
1215 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
1216 UNSET_ONGROUND(self);
1219 g = PHYS_GRAVITY * PHYS_INPUT_TIMELENGTH;
1220 if (PHYS_ENTGRAVITY(self))
1221 g *= PHYS_ENTGRAVITY(self);
1222 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1225 self.velocity_z += g;
1228 self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
1229 makevectors(PHYS_INPUT_ANGLES(self));
1230 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1231 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self)_x
1232 + v_right * PHYS_INPUT_MOVEVALUES(self)_y
1233 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self)_z;
1234 self.velocity_z += g;
1235 if (self.ladder_entity.classname == "func_water")
1237 float f = vlen(wishvel);
1238 if (f > self.ladder_entity.speed)
1239 wishvel *= (self.ladder_entity.speed / f);
1241 self.watertype = self.ladder_entity.skin;
1242 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1243 if ((self.origin_z + self.view_ofs_z) < f)
1244 self.waterlevel = WATERLEVEL_SUBMERGED;
1245 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1246 self.waterlevel = WATERLEVEL_SWIMMING;
1247 else if ((self.origin_z + self.mins_z + 1) < f)
1248 self.waterlevel = WATERLEVEL_WETFEET;
1251 self.waterlevel = WATERLEVEL_NONE;
1252 self.watertype = CONTENT_EMPTY;
1256 vector wishdir = normalize(wishvel);
1257 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod);
1258 PM_ClientMovement_Move();
1260 if (time >= self.teleport_time)
1262 // water acceleration
1263 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE*maxspd_mod, 1, 0, 0, 0);
1266 void PM_check_jumppad()
1269 entity oldself = self;
1271 for(self = world; (self = find(self, classname, "jumppad")); )
1272 trigger_push_draw();
1278 void PM_jetpack(float maxspd_mod)
1280 //makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1281 makevectors(PHYS_INPUT_ANGLES(self));
1282 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self)_x
1283 + v_right * PHYS_INPUT_MOVEVALUES(self)_y;
1284 // add remaining speed as Z component
1285 float maxairspd = PHYS_MAXAIRSPEED * max(1, maxspd_mod);
1286 // fix speedhacks :P
1287 wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
1288 // add the unused velocity as up component
1291 // if (self.BUTTON_JUMP)
1292 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1294 // it is now normalized, so...
1295 float a_side = PHYS_JETPACK_ACCEL_SIDE;
1296 float a_up = PHYS_JETPACK_ACCEL_UP;
1297 float a_add = PHYS_JETPACK_ANTIGRAVITY * PHYS_GRAVITY;
1299 wishvel_x *= a_side;
1300 wishvel_y *= a_side;
1305 //////////////////////////////////////////////////////////////////////////////////////
1306 // finding the maximum over all vectors of above form
1307 // with wishvel having an absolute value of 1
1308 //////////////////////////////////////////////////////////////////////////////////////
1309 // we're finding the maximum over
1310 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1311 // for z in the range from -1 to 1
1312 //////////////////////////////////////////////////////////////////////////////////////
1313 // maximum is EITHER attained at the single extreme point:
1314 float a_diff = a_side * a_side - a_up * a_up;
1318 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1319 if (f > -1 && f < 1) // can it be attained?
1321 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1322 //print("middle\n");
1325 // OR attained at z = 1:
1326 f = (a_up + a_add) * (a_up + a_add);
1332 // OR attained at z = -1:
1333 f = (a_up - a_add) * (a_up - a_add);
1337 //print("bottom\n");
1340 //////////////////////////////////////////////////////////////////////////////////////
1342 //print("best possible acceleration: ", ftos(best), "\n");
1345 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE, 1);
1346 if (wishvel_z - PHYS_GRAVITY > 0)
1347 fz = bound(0, 1 - self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
1349 fz = bound(0, 1 + self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
1352 fvel = vlen(wishvel);
1355 wishvel_z = (wishvel_z - PHYS_GRAVITY) * fz + PHYS_GRAVITY;
1357 fvel = min(1, vlen(wishvel) / best);
1358 if (PHYS_JETPACK_FUEL && !(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO))
1359 f = min(1, PHYS_AMMO_FUEL(self) / (PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel));
1363 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1365 if (f > 0 && wishvel != '0 0 0')
1367 self.velocity = self.velocity + wishvel * f * PHYS_INPUT_TIMELENGTH;
1368 UNSET_ONGROUND(self);
1371 if (!(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO))
1372 self.ammo_fuel -= PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel * f;
1374 ITEMS(self) |= IT_USING_JETPACK;
1376 // jetpack also inhibits health regeneration, but only for 1 second
1377 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1382 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1383 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1384 self.velocity_z -= g * 0.5;
1386 self.velocity_z -= g;
1387 PM_ClientMovement_Move();
1388 if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1389 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1390 self.velocity_z -= g * 0.5;
1396 // if PHYS_INPUT_TIMELENGTH is 0 (due to client sending the same timestamp twice),
1398 if (PHYS_INPUT_TIMELENGTH <= 0)
1401 // if (autocvar_sv_gameplayfix_unstickplayers)
1402 // SV_CheckStuck (self);
1404 // applygravity = !SV_CheckWater(self) && self.movetype == MOVETYPE_WALK && !(self.flags & FL_WATERJUMP);
1406 // hitsupercontentsmask = SV_GenericHitSuperContentsMask(self);
1408 // SV_CheckVelocity(self);
1410 // do a regular slide move unless it looks like you ran into a step
1411 // float oldonground = self.flags & FL_ONGROUND;
1413 vector start_origin = self.origin;
1414 vector start_velocity = self.velocity;
1417 // clip = SV_FlyMove (self, PHYS_INPUT_TIMELENGTH, applygravity, NULL, hitsupercontentsmask, sv_gameplayfix_stepmultipletimes.integer ? sv_stepheight.value : 0);
1419 // if(sv_gameplayfix_downtracesupportsongroundflag.integer)
1422 // only try this if there was no floor in the way in the trace (no,
1423 // this check seems to be not REALLY necessary, because if clip & 1,
1424 // our trace will hit that thing too)
1425 vector upmove = self.origin;
1427 vector downmove = self.origin;
1430 if (self.movetype == MOVETYPE_FLYMISSILE)
1431 type = MOVE_MISSILE;
1432 else if (self.movetype == MOVETYPE_FLY_WORLDONLY)
1433 type = MOVE_WORLDONLY;
1434 else if (self.solid == SOLID_TRIGGER || self.solid == SOLID_NOT)
1435 type = MOVE_NOMONSTERS; // only clip against bmodels
1438 vector entmins = self.mins;
1439 vector entmaxs = self.maxs;
1440 tracebox(upmove, entmins, entmaxs, downmove, type, self);
1441 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
1442 clip |= 1; // but we HAVE found a floor
1445 // if the move did not hit the ground at any point, we're not on ground
1447 // self.flags = self.flags & ~FL_ONGROUND;
1449 // SV_CheckVelocity(self);
1450 // SV_LinkEdict(self);
1451 // SV_LinkEdict_TouchAreaGrid(self);
1453 if(clip & 8) // teleport
1456 if (self.flags & FL_WATERJUMP)
1459 // if (autocvar_sv_nostep)
1462 vector originalmove_origin = self.origin;
1463 vector originalmove_velocity = self.velocity;
1464 float originalmove_flags = self.flags;
1465 entity originalmove_groundentity = self.groundentity;
1467 // if move didn't block on a step, return
1470 // if move was not trying to move into the step, return
1471 if (fabs(start_velocity_x) < 0.03125 && fabs(start_velocity_y) < 0.03125)
1474 if (self.movetype != MOVETYPE_FLY)
1476 // return if gibbed by a trigger
1477 if (self.movetype != MOVETYPE_WALK)
1480 // return if attempting to jump while airborn (unless sv_jumpstep)
1481 // if (!autocvar_sv_jumpstep)
1482 // if (!oldonground && PRVM_serveredictfloat(self, waterlevel) == 0)
1486 // try moving up and forward to go up a step
1487 // back to start pos
1488 self.origin = start_origin;
1489 self.velocity = start_velocity;
1492 vector upmove = '0 0 0';
1493 upmove_z = autocvar_sv_stepheight;
1494 // if(!SV_PushEntity(&trace, self, upmove, true))
1496 // // we got teleported when upstepping... must abort the move
1501 self.velocity_z = 0;
1502 // clip = SV_FlyMove (self, PHYS_INPUT_TIMELENGTH, applygravity, stepnormal, hitsupercontentsmask, 0);
1503 self.velocity_z += start_velocity_z;
1506 // // we got teleported when upstepping... must abort the move
1507 // // note that z velocity handling may not be what QC expects here, but we cannot help it
1511 // SV_CheckVelocity(self);
1512 // SV_LinkEdict(self);
1513 // SV_LinkEdict_TouchAreaGrid(self);
1515 // check for stuckness, possibly due to the limited precision of floats
1516 // in the clipping hulls
1518 && fabs(originalmove_origin_y - self.origin_y < 0.03125)
1519 && fabs(originalmove_origin_x - self.origin_x < 0.03125))
1521 //Con_Printf("wall\n");
1522 // stepping up didn't make any progress, revert to original move
1523 self.origin = originalmove_origin;
1524 self.velocity = originalmove_velocity;
1525 self.flags = originalmove_flags;
1526 self.groundentity = originalmove_groundentity;
1530 //Con_Printf("step - ");
1532 // extra friction based on view angle
1533 // if (clip & 2 && sv_wallfriction.integer)
1534 // SV_WallFriction (self, stepnormal);
1536 // don't do the down move if stepdown is disabled, moving upward, not in water, or the move started offground or ended onground
1537 // else if (!autocvar_sv_gameplayfix_stepdown || self.waterlevel >= 3 || start_velocity_z >= (1.0 / 32.0) || !oldonground || (self.flags & FL_ONGROUND))
1541 vector downmove = '0 0 0';
1542 downmove_z = -autocvar_sv_stepheight + start_velocity_z*PHYS_INPUT_TIMELENGTH;
1543 // if(!SV_PushEntity (&downtrace, self, downmove, true))
1545 // // we got teleported when downstepping... must abort the move
1549 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
1551 // this has been disabled so that you can't jump when you are stepping
1552 // up while already jumping (also known as the Quake2 double jump bug)
1556 //Con_Printf("slope\n");
1557 // if the push down didn't end up on good ground, use the move without
1558 // the step up. This happens near wall / slope combinations, and can
1559 // cause the player to hop up higher on a slope too steep to climb
1560 self.origin = originalmove_origin;
1561 self.velocity = originalmove_velocity;
1562 self.flags = originalmove_flags;
1563 self.groundentity = originalmove_groundentity;
1566 // SV_CheckVelocity(self);
1567 // SV_LinkEdict(self);
1568 // SV_LinkEdict_TouchAreaGrid(self);
1571 void PM_walk(float buttons_prev, float maxspd_mod)
1573 if (!WAS_ONGROUND(self))
1575 if (autocvar_speedmeter)
1576 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1577 if (self.lastground < time - 0.3)
1578 self.velocity *= (1 - PHYS_FRICTION_ONLAND);
1579 if (self.jumppadcount > 1)
1580 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1581 self.jumppadcount = 0;
1584 makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1585 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1586 + v_right * PHYS_INPUT_MOVEVALUES(self).y;
1588 vector wishdir = normalize(wishvel);
1589 float wishspeed = vlen(wishvel);
1591 wishspeed = min(wishspeed, PHYS_MAXSPEED(self) * maxspd_mod);
1592 if (IS_DUCKED(self))
1595 // apply edge friction
1596 float f = vlen(vec2(self.velocity));
1599 // TODO: apply edge friction
1600 // apply ground friction
1601 f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION * ((f < PHYS_STOPSPEED) ? (PHYS_STOPSPEED / f) : 1);
1605 Mathematical analysis time!
1607 Our goal is to invert this mess.
1609 For the two cases we get:
1610 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * (PHYS_STOPSPEED / v0) * PHYS_FRICTION)
1611 = v0 - PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION
1612 v0 = v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION
1614 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1615 v0 = v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1617 These cases would be chosen ONLY if:
1619 v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION < PHYS_STOPSPEED
1620 v < PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1622 v0 >= PHYS_STOPSPEED
1623 v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION) >= PHYS_STOPSPEED
1624 v >= PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1627 float addspeed = wishspeed - self.velocity * wishdir;
1630 float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
1631 self.velocity += accelspeed * wishdir;
1633 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1634 if (!(GAMEPLAYFIX_NOGRAVITYONGROUND))
1635 self.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1);
1636 if (self.velocity * self.velocity)
1637 PM_ClientMovement_Move();
1638 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1639 if (!IS_ONGROUND(self) || !GAMEPLAYFIX_NOGRAVITYONGROUND)
1640 self.velocity_z -= g * 0.5;
1643 void PM_air(float buttons_prev, float maxspd_mod)
1645 makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1646 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1647 + v_right * PHYS_INPUT_MOVEVALUES(self).y;
1649 vector wishdir = normalize(wishvel);
1650 float wishspeed = vlen(wishvel);
1653 if (time >= self.teleport_time)
1655 if (pmove_waterjumptime <= 0)
1658 float maxairspd = PHYS_MAXAIRSPEED * min(maxspd_mod, 1);
1660 // apply air speed limit
1661 float airaccelqw = PHYS_AIRACCEL_QW(self);
1662 float wishspeed0 = wishspeed;
1663 wishspeed = min(wishspeed, maxairspd);
1664 if (IS_DUCKED(self))
1666 float airaccel = PHYS_AIRACCELERATE * min(maxspd_mod, 1);
1668 float accelerating = (self.velocity * wishdir > 0);
1669 float wishspeed2 = wishspeed;
1672 if (PHYS_AIRSTOPACCELERATE)
1674 vector curdir = normalize(vec2(self.velocity));
1675 airaccel += (PHYS_AIRSTOPACCELERATE*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1677 // note that for straight forward jumping:
1678 // step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
1679 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1681 // dv/dt = accel * maxspeed (when slow)
1682 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1683 // log dv/dt = logaccel + logmaxspeed (when slow)
1684 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1685 float strafity = IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), -90) + IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), +90); // if one is nonzero, other is always zero
1686 if (PHYS_MAXAIRSTRAFESPEED)
1687 wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED*maxspd_mod));
1688 if (PHYS_AIRSTRAFEACCELERATE)
1689 airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE*maxspd_mod);
1690 if (PHYS_AIRSTRAFEACCEL_QW(self))
1692 (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(self) : PHYS_AIRACCEL_QW(self)) >= 0) ? +1 : -1)
1694 (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(self)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(self))));
1697 if (PHYS_WARSOWBUNNY_TURNACCEL && accelerating && PHYS_INPUT_MOVEVALUES(self).y == 0 && PHYS_INPUT_MOVEVALUES(self).x != 0)
1698 PM_AirAccelerate(wishdir, wishspeed2);
1700 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(self), PHYS_AIRACCEL_SIDEWAYS_FRICTION / maxairspd, PHYS_AIRSPEEDLIMIT_NONQW(self));
1702 if (PHYS_AIRCONTROL)
1703 CPM_PM_Aircontrol(wishdir, wishspeed2);
1705 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1706 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1707 self.velocity_z -= g * 0.5;
1709 self.velocity_z -= g;
1710 PM_ClientMovement_Move();
1711 if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1712 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1713 self.velocity_z -= g * 0.5;
1716 // used for calculating airshots
1717 float PM_is_flying()
1719 if (IS_ONGROUND(self))
1721 if (self.waterlevel >= WATERLEVEL_SWIMMING)
1723 traceline(self.origin, self.origin - '0 0 48', MOVE_NORMAL, self);
1724 return trace_fraction >= 1;
1729 float buttons = PHYS_INPUT_BUTTON_MASK(self);
1731 self.team = myteam + 1; // is this correct?
1732 if (!(PHYS_INPUT_BUTTON_JUMP(self))) // !jump
1733 UNSET_JUMP_HELD(self); // canjump = true
1734 pmove_waterjumptime -= PHYS_INPUT_TIMELENGTH;
1736 PM_ClientMovement_UpdateStatus();
1739 WarpZone_PlayerPhysics_FixVAngle();
1741 float maxspeed_mod = 1;
1742 maxspeed_mod *= PM_check_keepaway();
1743 maxspeed_mod *= PHYS_HIGHSPEED;
1746 Physics_UpdateStats(maxspeed_mod);
1748 if (self.PlayerPhysplug)
1749 if (self.PlayerPhysplug())
1753 PM_check_race_movetime();
1755 anticheat_physics();
1758 if (PM_check_specialcommand(buttons))
1763 if (buttons != self.buttons_old || PHYS_INPUT_MOVEVALUES(self) != self.movement_old || PHYS_INPUT_ANGLES(self) != self.v_angle_old)
1764 self.parm_idlesince = time;
1767 float buttons_prev = self.buttons_old;
1768 self.buttons_old = buttons;
1769 self.movement_old = PHYS_INPUT_MOVEVALUES(self);
1770 self.v_angle_old = PHYS_INPUT_ANGLES(self);
1772 PM_check_nickspam();
1776 if (IS_BOT_CLIENT(self))
1778 if (playerdemo_read())
1783 if (IS_PLAYER(self))
1787 if (self.race_penalty)
1788 if (time > self.race_penalty)
1789 self.race_penalty = 0;
1792 float not_allowed_to_move = 0;
1794 if (self.race_penalty)
1795 not_allowed_to_move = 1;
1798 if (!autocvar_sv_ready_restart_after_countdown)
1799 if (time < game_starttime)
1800 not_allowed_to_move = 1;
1803 if (not_allowed_to_move)
1805 self.velocity = '0 0 0';
1806 self.movetype = MOVETYPE_NONE;
1808 self.disableclientprediction = 2;
1812 else if (self.disableclientprediction == 2)
1814 if (self.movetype == MOVETYPE_NONE)
1815 self.movetype = MOVETYPE_WALK;
1816 self.disableclientprediction = 0;
1822 if (self.movetype == MOVETYPE_NONE)
1825 // when we get here, disableclientprediction cannot be 2
1826 self.disableclientprediction = 0;
1838 if (self.in_swamp) {
1839 maxspeed_mod *= self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
1843 // conveyors: first fix velocity
1844 if (self.conveyor.state)
1845 self.velocity -= self.conveyor.movedir;
1848 MUTATOR_CALLHOOK(PlayerPhysics);
1854 // float forcedodge = 1;
1857 // PM_dodging_checkpressedkeys();
1860 // PM_ClientMovement_Move();
1865 if (!IS_PLAYER(self))
1867 maxspeed_mod *= autocvar_sv_spectator_speed_multiplier;
1868 if (!self.spectatorspeed)
1869 self.spectatorspeed = maxspeed_mod;
1870 if (self.impulse && self.impulse <= 19 || (self.impulse >= 200 && self.impulse <= 209) || (self.impulse >= 220 && self.impulse <= 229))
1872 if (self.lastclassname != "player")
1874 if (self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209))
1875 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
1876 else if (self.impulse == 11)
1877 self.spectatorspeed = maxspeed_mod;
1878 else if (self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229))
1879 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
1880 else if (self.impulse >= 1 && self.impulse <= 9)
1881 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
1882 } // otherwise just clear
1885 maxspeed_mod *= self.spectatorspeed;
1890 // if dead, behave differently
1891 // in CSQC, physics don't handle dead player
1897 if (!self.fixangle && !g_bugrigs)
1898 self.angles = '0 1 0' * PHYS_INPUT_ANGLES(self).y;
1902 if (IS_ONGROUND(self))
1903 if (IS_PLAYER(self)) // no fall sounds for observers thank you very much
1907 if (self.waterlevel < WATERLEVEL_SWIMMING)
1908 if (time >= self.ladder_time)
1911 self.nextstep = time + 0.3 + random() * 0.1;
1912 trace_dphitq3surfaceflags = 0;
1913 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
1914 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
1916 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
1917 GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
1919 GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
1929 if (IS_PLAYER(self))
1935 if (self.flags & /* FL_WATERJUMP */ 2048)
1937 self.velocity_x = self.movedir_x;
1938 self.velocity_y = self.movedir_y;
1939 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
1941 self.flags &= ~/* FL_WATERJUMP */ 2048;
1942 self.teleport_time = 0;
1947 else if (g_bugrigs && IS_PLAYER(self))
1951 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
1952 PM_fly(maxspeed_mod);
1954 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
1955 PM_swim(maxspeed_mod);
1957 else if (time < self.ladder_time)
1958 PM_ladder(maxspeed_mod);
1960 else if (ITEMS(self) & IT_USING_JETPACK)
1961 PM_jetpack(maxspeed_mod);
1965 if (IS_ONGROUND(self))
1966 PM_walk(buttons_prev, maxspeed_mod);
1968 PM_air(buttons_prev, maxspeed_mod);
1972 if (!IS_OBSERVER(self))
1978 if (IS_ONGROUND(self))
1979 self.lastground = time;
1981 // conveyors: then break velocity again
1982 if (self.conveyor.state)
1983 self.velocity += self.conveyor.movedir;
1986 self.lastflags = self.flags;
1988 self.lastflags = self.pmove_flags;
1991 self.lastclassname = self.classname;
1995 void SV_PlayerPhysics(void)
1997 void CSQC_ClientMovement_PlayerMove_Frame(void)