11 .float spectatorspeed;
16 .string lastclassname;
18 .float() PlayerPhysplug;
20 // Client/server mappings
23 #define PHYS_INPUT_ANGLES(s) input_angles
24 #define PHYS_INPUT_BUTTONS(s) input_buttons
26 #define PHYS_INPUT_TIMELENGTH input_timelength
28 #define PHYS_INPUT_MOVEVALUES(s) input_movevalues
30 #define GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE moveflags & MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE
31 #define GAMEPLAYFIX_NOGRAVITYONGROUND moveflags & MOVEFLAG_NOGRAVITYONGROUND
32 #define GAMEPLAYFIX_Q2AIRACCELERATE moveflags & MOVEFLAG_Q2AIRACCELERATE
34 #define IS_DUCKED(s) (s.pmove_flags & PMF_DUCKED)
35 #define SET_DUCKED(s) s.pmove_flags |= PMF_DUCKED
36 #define UNSET_DUCKED(s) s.pmove_flags &= ~PMF_DUCKED
38 #define IS_JUMP_HELD(s) (s.pmove_flags & PMF_JUMP_HELD)
39 #define SET_JUMP_HELD(s) s.pmove_flags |= PMF_JUMP_HELD
40 #define UNSET_JUMP_HELD(s) s.pmove_flags &= ~PMF_JUMP_HELD
42 #define IS_ONGROUND(s) (s.pmove_flags & PMF_ONGROUND)
43 #define SET_ONGROUND(s) s.pmove_flags |= PMF_ONGROUND
44 #define UNSET_ONGROUND(s) s.pmove_flags &= ~PMF_ONGROUND
46 #define PHYS_ACCELERATE getstatf(STAT_MOVEVARS_ACCELERATE)
47 #define PHYS_AIRACCEL_QW(s) getstatf(STAT_MOVEVARS_AIRACCEL_QW)
48 #define PHYS_AIRACCEL_QW_STRETCHFACTOR(s) getstatf(STAT_MOVEVARS_AIRACCEL_QW_STRETCHFACTOR)
49 #define PHYS_AIRACCEL_SIDEWAYS_FRICTION getstatf(STAT_MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION)
50 #define PHYS_AIRACCELERATE getstatf(STAT_MOVEVARS_AIRACCELERATE)
51 #define PHYS_AIRCONTROL getstatf(STAT_MOVEVARS_AIRCONTROL)
52 #define PHYS_AIRCONTROL_PENALTY getstatf(STAT_MOVEVARS_AIRCONTROL_PENALTY)
53 #define PHYS_AIRCONTROL_POWER getstatf(STAT_MOVEVARS_AIRCONTROL_POWER)
54 #define PHYS_AIRSPEEDLIMIT_NONQW(s) getstatf(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW)
55 #define PHYS_AIRSTOPACCELERATE getstatf(STAT_MOVEVARS_AIRSTOPACCELERATE)
56 #define PHYS_AIRSTRAFEACCEL_QW(s) getstatf(STAT_MOVEVARS_AIRSTRAFEACCEL_QW)
57 #define PHYS_AIRSTRAFEACCELERATE getstatf(STAT_MOVEVARS_AIRSTRAFEACCELERATE)
58 #define PHYS_ENTGRAVITY(s) getstatf(STAT_MOVEVARS_ENTGRAVITY)
59 #define PHYS_FRICTION getstatf(STAT_MOVEVARS_FRICTION)
60 #define PHYS_GRAVITY getstatf(STAT_MOVEVARS_GRAVITY)
61 #define PHYS_HIGHSPEED getstatf(STAT_MOVEVARS_HIGHSPEED)
62 #define PHYS_JUMPVELOCITY getstatf(STAT_MOVEVARS_JUMPVELOCITY)
63 #define PHYS_MAXAIRSPEED getstatf(STAT_MOVEVARS_MAXAIRSPEED)
64 #define PHYS_MAXAIRSTRAFESPEED getstatf(STAT_MOVEVARS_MAXAIRSTRAFESPEED)
65 #define PHYS_MAXSPEED(s) getstatf(STAT_MOVEVARS_MAXSPEED)
66 #define PHYS_STEPHEIGHT getstatf(STAT_MOVEVARS_STEPHEIGHT)
67 #define PHYS_STOPSPEED getstatf(STAT_MOVEVARS_STOPSPEED)
68 #define PHYS_WARSOWBUNNY_ACCEL getstatf(STAT_MOVEVARS_WARSOWBUNNY_ACCEL)
69 #define PHYS_WARSOWBUNNY_BACKTOSIDERATIO getstatf(STAT_MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO)
70 #define PHYS_WARSOWBUNNY_AIRFORWARDACCEL getstatf(STAT_MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL)
71 #define PHYS_WARSOWBUNNY_TOPSPEED getstatf(STAT_MOVEVARS_WARSOWBUNNY_TOPSPEED)
72 #define PHYS_WARSOWBUNNY_TURNACCEL getstatf(STAT_MOVEVARS_WARSOWBUNNY_TURNACCEL)
76 #define PHYS_INPUT_ANGLES(s) s.v_angle
78 #define PHYS_INPUT_BUTTONS(s) (s.BUTTON_ATCK + 2 * s.BUTTON_JUMP + 4 * s.BUTTON_ATCK2 + 8 * s.BUTTON_ZOOM + 16 * s.BUTTON_CROUCH + 32 * s.BUTTON_HOOK + 64 * s.BUTTON_USE + 128 * (s.movement_x < 0) + 256 * (s.movement_x > 0) + 512 * (s.movement_y < 0) + 1024 * (s.movement_y > 0))
80 #define PHYS_INPUT_TIMELENGTH frametime
82 #define PHYS_INPUT_MOVEVALUES(s) s.movement
84 #define GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE autocvar_sv_gameplayfix_gravityunaffectedbyticrate
85 #define GAMEPLAYFIX_NOGRAVITYONGROUND cvar("sv_gameplayfix_nogravityonground")
86 #define GAMEPLAYFIX_Q2AIRACCELERATE autocvar_sv_gameplayfix_q2airaccelerate
88 #define IS_DUCKED(s) s.crouch
89 #define SET_DUCKED(s) s.crouch = TRUE
90 #define UNSET_DUCKED(s) s.crouch = FALSE
92 #define IS_JUMP_HELD(s) (s.flags & FL_JUMPRELEASED == 0)
93 #define SET_JUMP_HELD(s) s.flags &= ~FL_JUMPRELEASED
94 #define UNSET_JUMP_HELD(s) s.flags |= FL_JUMPRELEASED
96 #define IS_ONGROUND(s) (s.flags & FL_ONGROUND)
97 #define SET_ONGROUND(s) s.flags |= FL_ONGROUND
98 #define UNSET_ONGROUND(s) s.flags &= ~FL_ONGROUND
100 #define PHYS_ACCELERATE autocvar_sv_accelerate
101 #define PHYS_AIRACCEL_QW(s) s.stat_sv_airaccel_qw
102 #define PHYS_AIRACCEL_QW_STRETCHFACTOR(s) autocvar_sv_airaccel_qw_stretchfactor
103 #define PHYS_AIRACCEL_SIDEWAYS_FRICTION autocvar_sv_airaccel_sideways_friction
104 #define PHYS_AIRACCELERATE autocvar_sv_airaccelerate
105 #define PHYS_AIRCONTROL autocvar_sv_aircontrol
106 #define PHYS_AIRCONTROL_PENALTY autocvar_sv_aircontrol_penalty
107 #define PHYS_AIRCONTROL_POWER autocvar_sv_aircontrol_power
108 #define PHYS_AIRSPEEDLIMIT_NONQW(s) s.stat_sv_airspeedlimit_nonqw
109 #define PHYS_AIRSTOPACCELERATE autocvar_sv_airstopaccelerate
110 #define PHYS_AIRSTRAFEACCEL_QW(s) s.stat_sv_airstrafeaccel_qw
111 #define PHYS_AIRSTRAFEACCELERATE autocvar_sv_airstrafeaccelerate
112 #define PHYS_ENTGRAVITY(s) s.gravity
113 #define PHYS_FRICTION autocvar_sv_friction
114 #define PHYS_GRAVITY autocvar_sv_gravity
115 #define PHYS_HIGHSPEED autocvar_g_movement_highspeed
116 #define PHYS_JUMPVELOCITY autocvar_sv_jumpvelocity
117 #define PHYS_MAXAIRSPEED autocvar_sv_maxairspeed
118 #define PHYS_MAXAIRSTRAFESPEED autocvar_sv_maxairstrafespeed
119 #define PHYS_MAXSPEED(s) s.stat_sv_maxspeed
120 #define PHYS_STEPHEIGHT autocvar_sv_stepheight
121 #define PHYS_STOPSPEED autocvar_sv_stopspeed
122 #define PHYS_WARSOWBUNNY_ACCEL autocvar_sv_warsowbunny_accel
123 #define PHYS_WARSOWBUNNY_BACKTOSIDERATIO autocvar_sv_warsowbunny_backtosideratio
124 #define PHYS_WARSOWBUNNY_AIRFORWARDACCEL autocvar_sv_warsowbunny_airforwardaccel
125 #define PHYS_WARSOWBUNNY_TOPSPEED autocvar_sv_warsowbunny_topspeed
126 #define PHYS_WARSOWBUNNY_TURNACCEL autocvar_sv_warsowbunny_turnaccel
130 float IsMoveInDirection(vector mv, float angle) // key mix factor
132 if (mv_x == 0 && mv_y == 0)
133 return 0; // avoid division by zero
134 angle -= RAD2DEG * atan2(mv_y, mv_x);
135 angle = remainder(angle, 360) / 45;
136 return angle > 1 ? 0 : angle < -1 ? 0 : 1 - fabs(angle);
139 float GeomLerp(float a, float lerp, float b)
141 return a == 0 ? (lerp < 1 ? 0 : b)
142 : b == 0 ? (lerp > 0 ? 0 : a)
143 : a * pow(fabs(b / a), lerp);
147 float pmove_waterjumptime; // weird engine flag we shouldn't really use but have to for now
150 const float unstick_count = 27;
151 vector unstick_offsets[unstick_count] =
153 // 1 no nudge (just return the original if this test passes)
156 ' 0.000 0.000 0.125', '0.000 0.000 -0.125',
157 '-0.125 0.000 0.000', '0.125 0.000 0.000',
158 ' 0.000 -0.125 0.000', '0.000 0.125 0.000',
159 // 4 diagonal flat nudges
160 '-0.125 -0.125 0.000', '0.125 -0.125 0.000',
161 '-0.125 0.125 0.000', '0.125 0.125 0.000',
162 // 8 diagonal upward nudges
163 '-0.125 0.000 0.125', '0.125 0.000 0.125',
164 ' 0.000 -0.125 0.125', '0.000 0.125 0.125',
165 '-0.125 -0.125 0.125', '0.125 -0.125 0.125',
166 '-0.125 0.125 0.125', '0.125 0.125 0.125',
167 // 8 diagonal downward nudges
168 '-0.125 0.000 -0.125', '0.125 0.000 -0.125',
169 ' 0.000 -0.125 -0.125', '0.000 0.125 -0.125',
170 '-0.125 -0.125 -0.125', '0.125 -0.125 -0.125',
171 '-0.125 0.125 -0.125', '0.125 0.125 -0.125',
174 void CSQC_ClientMovement_Unstick()
177 for (i = 0; i < unstick_count; i++)
179 vector neworigin = unstick_offsets[i] + self.origin;
180 tracebox(neworigin, PL_CROUCH_MIN, PL_CROUCH_MAX, neworigin, MOVE_NORMAL, self);
181 if (!trace_startsolid)
183 self.origin = neworigin;
189 void CSQC_ClientMovement_Move()
191 float t = PHYS_INPUT_TIMELENGTH;
192 // vector primalvelocity = self.velocity; // FIXME: unused
194 for (bump = 0; bump < 8 && self.velocity * self.velocity > 0; bump++)
196 vector neworigin = self.origin + t * self.velocity;
197 tracebox(self.origin, self.mins, self.maxs, neworigin, MOVE_NORMAL, self);
198 float old_trace1_fraction = trace_fraction;
199 vector old_trace1_endpos = trace_endpos;
200 vector old_trace1_plane_normal = trace_plane_normal;
201 if (trace_fraction < 1 && trace_plane_normal_z == 0)
203 // may be a step or wall, try stepping up
204 // first move forward at a higher level
205 vector currentorigin2 = self.origin;
206 currentorigin2_z += PHYS_STEPHEIGHT;
207 vector neworigin2 = neworigin;
208 neworigin2_z = self.origin_z + PHYS_STEPHEIGHT;
209 tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
210 if (!trace_startsolid)
212 // then move down from there
213 currentorigin2 = trace_endpos;
214 neworigin2 = trace_endpos;
215 neworigin2_z = self.origin_z;
216 float old_trace2_fraction = trace_fraction;
217 vector old_trace2_plane_normal = trace_plane_normal;
218 tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
219 //Con_Printf("%f %f %f %f : %f %f %f %f : %f %f %f %f\n", trace.fraction, trace.endpos[0], trace.endpos[1], trace.endpos[2], trace2.fraction, trace2.endpos[0], trace2.endpos[1], trace2.endpos[2], trace3.fraction, trace3.endpos[0], trace3.endpos[1], trace3.endpos[2]);
220 // accept the new trace if it made some progress
221 if (fabs(trace_endpos_x - old_trace1_endpos_x) >= 0.03125 || fabs(trace_endpos_y - old_trace1_endpos_y) >= 0.03125)
223 trace_fraction = old_trace2_fraction;
224 trace_endpos = trace_endpos;
225 trace_plane_normal = old_trace2_plane_normal;
229 trace_fraction = old_trace1_fraction;
230 trace_endpos = old_trace1_endpos;
231 trace_plane_normal = old_trace1_plane_normal;
236 // check if it moved at all
237 if (trace_fraction >= 0.001)
238 self.origin = trace_endpos;
240 // check if it moved all the way
241 if (trace_fraction == 1)
244 // this is only really needed for nogravityonground combined with gravityunaffectedbyticrate
245 // <LordHavoc> I'm pretty sure I commented it out solely because it seemed redundant
246 // this got commented out in a change that supposedly makes the code match QW better
247 // so if this is broken, maybe put it in an if (cls.protocol != PROTOCOL_QUAKEWORLD) block
248 if (trace_plane_normal_z > 0.7)
251 t -= t * trace_fraction;
253 float f = dotproduct(self.velocity, trace_plane_normal);
254 self.velocity -= f * trace_plane_normal;
256 // if (pmove_waterjumptime > 0)
257 // self.velocity = primalvelocity;
260 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
264 // this doesn't play well with analog input
265 if (PHYS_INPUT_MOVEVALUES(self).x == 0 || PHYS_INPUT_MOVEVALUES(self).y != 0)
266 return; // can't control movement if not moving forward or backward
269 k = 32 * (2 * IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), 0) - 1);
274 k *= bound(0, wishspeed / PHYS_MAXAIRSPEED, 1);
276 float zspeed = self.velocity_z;
278 float xyspeed = vlen(self.velocity);
279 self.velocity = normalize(self.velocity);
281 float dot = self.velocity * wishdir;
283 if (dot > 0) // we can't change direction while slowing down
285 k *= pow(dot, PHYS_AIRCONTROL_POWER)*PHYS_INPUT_TIMELENGTH;
286 xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY * sqrt(max(0, 1 - dot*dot)) * k/32);
287 k *= PHYS_AIRCONTROL;
288 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
291 self.velocity = self.velocity * xyspeed;
292 self.velocity_z = zspeed;
295 float AdjustAirAccelQW(float accelqw, float factor)
297 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
300 // example config for alternate speed clamping:
301 // sv_airaccel_qw 0.8
302 // sv_airaccel_sideways_friction 0
303 // prvm_globalset server speedclamp_mode 1
305 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
307 float speedclamp = stretchfactor > 0 ? stretchfactor
308 : accelqw < 0 ? 1 // full clamping, no stretch
311 accelqw = fabs(accelqw);
313 if (GAMEPLAYFIX_Q2AIRACCELERATE)
314 wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
316 float vel_straight = self.velocity * wishdir;
317 float vel_z = self.velocity_z;
318 vector vel_xy = vec2(self.velocity);
319 vector vel_perpend = vel_xy - vel_straight * wishdir;
321 float step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
323 float vel_xy_current = vlen(vel_xy);
325 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
326 float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
327 float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
328 vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
329 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
331 if (sidefric < 0 && (vel_perpend*vel_perpend))
332 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
334 float f = max(0, 1 + PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
335 float fmin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
337 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
338 // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
339 // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
340 // obviously, this cannot be
346 vel_perpend *= max(fmin, f);
350 vel_perpend *= max(0, 1 - PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
352 vel_xy = vel_straight * wishdir + vel_perpend;
356 float vel_xy_preclamp;
357 vel_xy_preclamp = vlen(vel_xy);
358 if (vel_xy_preclamp > 0) // prevent division by zero
360 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
361 if (vel_xy_current < vel_xy_preclamp)
362 vel_xy *= (vel_xy_current / vel_xy_preclamp);
366 self.velocity = vel_xy + vel_z * '0 0 1';
369 void PM_AirAccelerate(vector wishdir, float wishspeed)
374 vector curvel = self.velocity;
376 float curspeed = vlen(curvel);
378 if (wishspeed > curspeed * 1.01)
379 wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH);
382 float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED - PHYS_MAXSPEED(self)));
383 wishspeed = max(curspeed, PHYS_MAXSPEED(self)) + PHYS_WARSOWBUNNY_ACCEL * f * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH;
385 vector wishvel = wishdir * wishspeed;
386 vector acceldir = wishvel - curvel;
387 float addspeed = vlen(acceldir);
388 acceldir = normalize(acceldir);
390 float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH);
392 if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO < 1)
394 vector curdir = normalize(curvel);
395 float dot = acceldir * curdir;
397 acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO) * dot * curdir;
400 self.velocity += accelspeed * acceldir;
408 When you press the jump key
411 void PlayerJump (void)
415 return; // no jumping in freezetag when frozen
417 if (self.player_blocked)
418 return; // no jumping while blocked
420 float doublejump = FALSE;
421 float mjumpheight = autocvar_sv_jumpvelocity;
423 player_multijump = doublejump;
424 player_jumpheight = mjumpheight;
425 if (MUTATOR_CALLHOOK(PlayerJump))
428 doublejump = player_multijump;
429 mjumpheight = player_jumpheight;
431 if (autocvar_sv_doublejump)
433 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
434 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
438 // we MUST clip velocity here!
440 f = self.velocity * trace_plane_normal;
442 self.velocity -= f * trace_plane_normal;
446 if (self.waterlevel >= WATERLEVEL_SWIMMING)
448 self.velocity_z = self.stat_sv_maxspeed * 0.7;
453 if (!(self.flags & FL_ONGROUND))
456 if (self.cvar_cl_movement_track_canjump)
457 if (!(self.flags & FL_JUMPRELEASED))
460 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
461 // velocity bounds. Final velocity is bound between (jumpheight *
462 // min + jumpheight) and (jumpheight * max + jumpheight);
464 if (autocvar_sv_jumpspeedcap_min != "")
466 float minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min);
468 if (self.velocity_z < minjumpspeed)
469 mjumpheight += minjumpspeed - self.velocity_z;
472 if (autocvar_sv_jumpspeedcap_max != "")
474 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
475 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
477 if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && autocvar_sv_jumpspeedcap_max_disable_on_ramps))
479 float maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max);
481 if (self.velocity_z > maxjumpspeed)
482 mjumpheight -= self.velocity_z - maxjumpspeed;
486 if (!(self.lastflags & FL_ONGROUND))
488 if (autocvar_speedmeter)
489 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
490 if (self.lastground < time - 0.3)
492 self.velocity_x *= (1 - autocvar_sv_friction_on_land);
493 self.velocity_y *= (1 - autocvar_sv_friction_on_land);
495 if (self.jumppadcount > 1)
496 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
497 self.jumppadcount = 0;
500 self.oldvelocity_z = self.velocity_z += mjumpheight;
502 self.flags &= ~FL_ONGROUND;
503 self.flags &= ~FL_JUMPRELEASED;
505 animdecide_setaction(self, ANIMACTION_JUMP, TRUE);
507 if (autocvar_g_jump_grunt)
508 PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
510 self.restart_jump = -1; // restart jump anim next time
511 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
515 void CheckWaterJump()
519 // check for a jump-out-of-water
520 makevectors(self.angles);
521 vector start = self.origin;
524 normalize(v_forward);
525 vector end = start + v_forward*24;
526 traceline (start, end, TRUE, self);
527 if (trace_fraction < 1)
529 start_z = start_z + self.maxs_z - 8;
530 end = start + v_forward*24;
531 self.movedir = trace_plane_normal * -50;
532 traceline(start, end, TRUE, self);
533 if (trace_fraction == 1)
534 { // open at eye level
535 self.flags |= FL_WATERJUMP;
536 self.velocity_z = 225;
537 self.flags &= ~FL_JUMPRELEASED;
538 self.teleport_time = time + 2; // safety net
544 void CheckPlayerJump()
547 if (self.BUTTON_JUMP)
550 self.flags |= FL_JUMPRELEASED;
552 if (self.waterlevel == WATERLEVEL_SWIMMING)
557 float racecar_angle(float forward, float down)
565 float ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
567 float angle_mult = forward / (800 + forward);
570 return ret * angle_mult + 360 * (1 - angle_mult);
572 return ret * angle_mult;
575 void RaceCarPhysics()
578 // using this move type for "big rigs"
579 // the engine does not push the entity!
583 vector angles_save = self.angles;
584 float accel = bound(-1, PHYS_INPUT_MOVEVALUES(self).x / self.stat_sv_maxspeed, 1);
585 float steer = bound(-1, PHYS_INPUT_MOVEVALUES(self).y / self.stat_sv_maxspeed, 1);
587 if (g_bugrigs_reverse_speeding)
591 // back accel is DIGITAL
592 // to prevent speedhack
602 makevectors(self.angles); // new forward direction!
604 if (self.flags & FL_ONGROUND || g_bugrigs_air_steering)
606 float myspeed = self.velocity * v_forward;
607 float upspeed = self.velocity * v_up;
609 // responsiveness factor for steering and acceleration
610 float f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
611 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
614 if (myspeed < 0 && g_bugrigs_reverse_spinning)
615 steerfactor = -myspeed * g_bugrigs_steer;
617 steerfactor = -myspeed * f * g_bugrigs_steer;
620 if (myspeed < 0 && g_bugrigs_reverse_speeding)
621 accelfactor = g_bugrigs_accel;
623 accelfactor = f * g_bugrigs_accel;
624 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
630 myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
634 if (!g_bugrigs_reverse_speeding)
635 myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
642 myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
646 if (g_bugrigs_reverse_stopping)
649 myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
652 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
653 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
655 self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
656 makevectors(self.angles); // new forward direction!
658 myspeed += accel * accelfactor * PHYS_INPUT_TIMELENGTH;
660 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
664 float myspeed = vlen(self.velocity);
666 // responsiveness factor for steering and acceleration
667 float f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
668 float steerfactor = -myspeed * f;
669 self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
671 rigvel = self.velocity;
672 makevectors(self.angles); // new forward direction!
675 rigvel *= max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * PHYS_INPUT_TIMELENGTH);
676 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
677 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
678 //MAXIMA: solve(total_acceleration(v) = 0, v);
680 if (g_bugrigs_planar_movement)
682 vector rigvel_xy, neworigin, up;
685 rigvel_z -= PHYS_INPUT_TIMELENGTH * autocvar_sv_gravity; // 4x gravity plays better
686 rigvel_xy = vec2(rigvel);
688 if (g_bugrigs_planar_movement_car_jumping)
691 mt = MOVE_NOMONSTERS;
693 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
694 up = trace_endpos - self.origin;
696 // BUG RIGS: align the move to the surface instead of doing collision testing
698 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * PHYS_INPUT_TIMELENGTH, mt, self);
701 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * PHYS_INPUT_TIMELENGTH, mt, self);
703 if (trace_fraction < 0.5)
706 neworigin = self.origin;
709 neworigin = trace_endpos;
711 if (trace_fraction < 1)
713 // now set angles_x so that the car points parallel to the surface
714 self.angles = vectoangles(
715 '1 0 0' * v_forward_x * trace_plane_normal_z
717 '0 1 0' * v_forward_y * trace_plane_normal_z
719 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
721 self.flags |= FL_ONGROUND;
725 // now set angles_x so that the car points forward, but is tilted in velocity direction
726 self.flags &= ~FL_ONGROUND;
729 self.velocity = (neworigin - self.origin) * (1.0 / PHYS_INPUT_TIMELENGTH);
730 self.movetype = MOVETYPE_NOCLIP;
734 rigvel_z -= PHYS_INPUT_TIMELENGTH * autocvar_sv_gravity; // 4x gravity plays better
735 self.velocity = rigvel;
736 self.movetype = MOVETYPE_FLY;
740 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
741 if (trace_fraction != 1)
743 self.angles = vectoangles2(
744 '1 0 0' * v_forward_x * trace_plane_normal_z
746 '0 1 0' * v_forward_y * trace_plane_normal_z
748 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
756 vel_local_x = v_forward * self.velocity;
757 vel_local_y = v_right * self.velocity;
758 vel_local_z = v_up * self.velocity;
760 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
761 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
765 vector vf1, vu1, smoothangles;
766 makevectors(self.angles);
767 float f = bound(0, PHYS_INPUT_TIMELENGTH * g_bugrigs_angle_smoothing, 1);
772 makevectors(angles_save);
773 vf1 = vf1 + v_forward * (1 - f);
774 vu1 = vu1 + v_up * (1 - f);
775 smoothangles = vectoangles2(vf1, vu1);
776 self.angles_x = -smoothangles_x;
777 self.angles_z = smoothangles_z;
781 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
782 .float specialcommand_pos;
783 void SpecialCommand()
789 if (!CheatImpulse(99))
790 print("A hollow voice says \"Plugh\".\n");
796 float speedaward_speed;
797 string speedaward_holder;
798 string speedaward_uid;
800 void race_send_speedaward(float msg)
803 // send the best speed of the round
804 WriteByte(msg, SVC_TEMPENTITY);
805 WriteByte(msg, TE_CSQC_RACE);
806 WriteByte(msg, RACE_NET_SPEED_AWARD);
807 WriteInt24_t(msg, floor(speedaward_speed+0.5));
808 WriteString(msg, speedaward_holder);
813 float speedaward_alltimebest;
814 string speedaward_alltimebest_holder;
815 string speedaward_alltimebest_uid;
817 void race_send_speedaward_alltimebest(float msg)
820 // send the best speed
821 WriteByte(msg, SVC_TEMPENTITY);
822 WriteByte(msg, TE_CSQC_RACE);
823 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
824 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
825 WriteString(msg, speedaward_alltimebest_holder);
829 float PM_check_keepaway(void)
832 return (self.ballcarried && g_keepaway) ? autocvar_g_keepaway_ballcarrier_highspeed : 1;
838 void PM_check_race_movetime(void)
841 self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
842 float f = floor(self.race_movetime_frac);
843 self.race_movetime_frac -= f;
844 self.race_movetime_count += f;
845 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
849 float PM_check_specialcommand(float buttons)
855 else if (buttons == 1)
857 else if (buttons == 2)
859 else if (buttons == 128)
861 else if (buttons == 256)
863 else if (buttons == 512)
865 else if (buttons == 1024)
870 if (c == substring(specialcommand, self.specialcommand_pos, 1))
872 self.specialcommand_pos += 1;
873 if (self.specialcommand_pos >= strlen(specialcommand))
875 self.specialcommand_pos = 0;
880 else if (self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
881 self.specialcommand_pos = 0;
886 void PM_check_nickspam(void)
889 if (time >= self.nickspamtime)
891 if (self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
893 // slight annoyance for nick change scripts
894 PHYS_INPUT_MOVEVALUES(self) = -1 * PHYS_INPUT_MOVEVALUES(self);
895 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
897 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!
899 PHYS_INPUT_ANGLES(self)_x = random() * 360;
900 PHYS_INPUT_ANGLES(self)_y = random() * 360;
901 // at least I'm not forcing retardedview by also assigning to angles_z
902 self.fixangle = TRUE;
908 void PM_check_punch()
911 if (self.punchangle != '0 0 0')
913 float f = vlen(self.punchangle) - 10 * PHYS_INPUT_TIMELENGTH;
915 self.punchangle = normalize(self.punchangle) * f;
917 self.punchangle = '0 0 0';
920 if (self.punchvector != '0 0 0')
922 float f = vlen(self.punchvector) - 30 * PHYS_INPUT_TIMELENGTH;
924 self.punchvector = normalize(self.punchvector) * f;
926 self.punchvector = '0 0 0';
931 void PM_check_spider(void)
934 if (time >= self.spider_slowness)
936 self.stat_sv_maxspeed *= 0.5; // half speed while slow from spider
937 self.stat_sv_airspeedlimit_nonqw *= 0.5;
941 void PM_check_frozen(void)
946 if (autocvar_sv_dodging_frozen && IS_REAL_CLIENT(self))
948 PHYS_INPUT_MOVEVALUES(self)_x = bound(-5, PHYS_INPUT_MOVEVALUES(self).x, 5);
949 PHYS_INPUT_MOVEVALUES(self)_y = bound(-5, PHYS_INPUT_MOVEVALUES(self).y, 5);
950 PHYS_INPUT_MOVEVALUES(self)_z = bound(-5, PHYS_INPUT_MOVEVALUES(self).z, 5);
953 PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
954 self.disableclientprediction = 1;
956 vector midpoint = ((self.absmin + self.absmax) * 0.5);
957 if (pointcontents(midpoint) == CONTENT_WATER)
959 self.velocity = self.velocity * 0.5;
961 if (pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
962 self.velocity_z = 200;
967 void PM_check_blocked(void)
970 if (!self.player_blocked)
972 PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
973 self.disableclientprediction = 1;
978 float speedaward_lastsent;
979 float speedaward_lastupdate;
980 string GetMapname(void);
982 void PM_check_race(void)
985 if not(g_cts || g_race)
987 if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
989 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
990 speedaward_holder = self.netname;
991 speedaward_uid = self.crypto_idfp;
992 speedaward_lastupdate = time;
994 if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
996 string rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
997 race_send_speedaward(MSG_ALL);
998 speedaward_lastsent = speedaward_speed;
999 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
1001 speedaward_alltimebest = speedaward_speed;
1002 speedaward_alltimebest_holder = speedaward_holder;
1003 speedaward_alltimebest_uid = speedaward_uid;
1004 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1005 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1006 race_send_speedaward_alltimebest(MSG_ALL);
1012 void PM_check_vortex(void)
1015 float xyspeed = vlen(vec2(self.velocity));
1016 if (self.weapon == WEP_NEX && autocvar_g_balance_nex_charge && autocvar_g_balance_nex_charge_velocity_rate && xyspeed > autocvar_g_balance_nex_charge_minspeed)
1018 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1019 xyspeed = min(xyspeed, autocvar_g_balance_nex_charge_maxspeed);
1020 float f = (xyspeed - autocvar_g_balance_nex_charge_minspeed) / (autocvar_g_balance_nex_charge_maxspeed - autocvar_g_balance_nex_charge_minspeed);
1021 // add the extra charge
1022 self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_velocity_rate * f * PHYS_INPUT_TIMELENGTH);
1027 void PM_fly(float maxspd_mod)
1029 // noclipping or flying
1030 self.flags &= ~FL_ONGROUND;
1032 self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
1033 makevectors(PHYS_INPUT_ANGLES(self));
1034 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1035 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1036 + v_right * PHYS_INPUT_MOVEVALUES(self).y
1037 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
1039 vector wishdir = normalize(wishvel);
1040 float wishspeed = vlen(wishvel);
1041 if (wishspeed > PHYS_MAXSPEED(self) * maxspd_mod)
1042 wishspeed = PHYS_MAXSPEED(self) * maxspd_mod;
1043 if (time >= self.teleport_time)
1044 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
1047 void PM_swim(float maxspd_mod)
1050 self.flags &= ~FL_ONGROUND;
1052 makevectors(PHYS_INPUT_ANGLES(self));
1053 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1054 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1055 + v_right * PHYS_INPUT_MOVEVALUES(self).y
1056 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
1057 if (wishvel == '0 0 0')
1058 wishvel = '0 0 -60'; // drift towards bottom
1060 vector wishdir = normalize(wishvel);
1061 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod);
1062 wishspeed = wishspeed * 0.7;
1065 self.velocity *= (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
1067 // water acceleration
1068 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
1071 void PM_ladder(float maxspd_mod)
1074 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
1075 self.flags &= ~FL_ONGROUND;
1078 g = autocvar_sv_gravity * PHYS_INPUT_TIMELENGTH;
1081 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1084 self.velocity_z += g;
1087 self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
1088 makevectors(PHYS_INPUT_ANGLES(self));
1089 //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
1090 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1091 + v_right * PHYS_INPUT_MOVEVALUES(self).y
1092 + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
1093 self.velocity_z += g;
1094 if (self.ladder_entity.classname == "func_water")
1096 float f = vlen(wishvel);
1097 if (f > self.ladder_entity.speed)
1098 wishvel *= (self.ladder_entity.speed / f);
1100 self.watertype = self.ladder_entity.skin;
1101 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1102 if ((self.origin_z + self.view_ofs_z) < f)
1103 self.waterlevel = WATERLEVEL_SUBMERGED;
1104 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1105 self.waterlevel = WATERLEVEL_SWIMMING;
1106 else if ((self.origin_z + self.mins_z + 1) < f)
1107 self.waterlevel = WATERLEVEL_WETFEET;
1110 self.waterlevel = WATERLEVEL_NONE;
1111 self.watertype = CONTENT_EMPTY;
1115 vector wishdir = normalize(wishvel);
1116 float wishspeed = min(vlen(wishvel), self.stat_sv_maxspeed * maxspd_mod);
1117 if (time >= self.teleport_time)
1118 // water acceleration
1119 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE*maxspd_mod, 1, 0, 0, 0);
1123 void PM_jetpack(float maxspd_mod)
1126 //makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1127 makevectors(PHYS_INPUT_ANGLES(self));
1128 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1129 + v_right * PHYS_INPUT_MOVEVALUES(self).y;
1130 // add remaining speed as Z component
1131 float maxairspd = PHYS_MAXAIRSPEED * max(1, maxspd_mod);
1132 // fix speedhacks :P
1133 wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
1134 // add the unused velocity as up component
1137 // if (self.BUTTON_JUMP)
1138 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1140 // it is now normalized, so...
1141 float a_side = autocvar_g_jetpack_acceleration_side;
1142 float a_up = autocvar_g_jetpack_acceleration_up;
1143 float a_add = autocvar_g_jetpack_antigravity * autocvar_sv_gravity;
1145 wishvel_x *= a_side;
1146 wishvel_y *= a_side;
1151 //////////////////////////////////////////////////////////////////////////////////////
1152 // finding the maximum over all vectors of above form
1153 // with wishvel having an absolute value of 1
1154 //////////////////////////////////////////////////////////////////////////////////////
1155 // we're finding the maximum over
1156 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1157 // for z in the range from -1 to 1
1158 //////////////////////////////////////////////////////////////////////////////////////
1159 // maximum is EITHER attained at the single extreme point:
1160 float a_diff = a_side * a_side - a_up * a_up;
1164 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1165 if (f > -1 && f < 1) // can it be attained?
1167 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1168 //print("middle\n");
1171 // OR attained at z = 1:
1172 f = (a_up + a_add) * (a_up + a_add);
1178 // OR attained at z = -1:
1179 f = (a_up - a_add) * (a_up - a_add);
1183 //print("bottom\n");
1186 //////////////////////////////////////////////////////////////////////////////////////
1188 //print("best possible acceleration: ", ftos(best), "\n");
1191 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / autocvar_g_jetpack_maxspeed_side, 1);
1192 if (wishvel_z - autocvar_sv_gravity > 0)
1193 fz = bound(0, 1 - self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1195 fz = bound(0, 1 + self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1198 fvel = vlen(wishvel);
1201 wishvel_z = (wishvel_z - autocvar_sv_gravity) * fz + autocvar_sv_gravity;
1203 fvel = min(1, vlen(wishvel) / best);
1204 if (autocvar_g_jetpack_fuel && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1205 f = min(1, self.ammo_fuel / (autocvar_g_jetpack_fuel * PHYS_INPUT_TIMELENGTH * fvel));
1209 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1211 if (f > 0 && wishvel != '0 0 0')
1213 self.velocity = self.velocity + wishvel * f * PHYS_INPUT_TIMELENGTH;
1214 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
1215 self.ammo_fuel -= autocvar_g_jetpack_fuel * PHYS_INPUT_TIMELENGTH * fvel * f;
1216 self.flags &= ~FL_ONGROUND;
1217 self.items |= IT_USING_JETPACK;
1219 // jetpack also inhibits health regeneration, but only for 1 second
1220 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1225 void PM_walk(float buttons_prev, float maxspd_mod)
1228 // we get here if we ran out of ammo
1229 if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
1230 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1233 makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1234 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1235 + v_right * PHYS_INPUT_MOVEVALUES(self).y;
1238 if (!(self.lastflags & FL_ONGROUND))
1240 if (autocvar_speedmeter)
1241 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1242 if (self.lastground < time - 0.3)
1243 self.velocity *= (1 - autocvar_sv_friction_on_land);
1244 if (self.jumppadcount > 1)
1245 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1246 self.jumppadcount = 0;
1250 vector v = self.velocity;
1255 f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION * ((f < PHYS_STOPSPEED) ? (PHYS_STOPSPEED / f) : 1);
1259 Mathematical analysis time!
1261 Our goal is to invert this mess.
1263 For the two cases we get:
1264 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * (PHYS_STOPSPEED / v0) * PHYS_FRICTION)
1265 = v0 - PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION
1266 v0 = v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION
1268 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1269 v0 = v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1271 These cases would be chosen ONLY if:
1273 v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION < PHYS_STOPSPEED
1274 v < PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1276 v0 >= PHYS_STOPSPEED
1277 v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION) >= PHYS_STOPSPEED
1278 v >= PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
1283 vector wishdir = normalize(wishvel);
1284 float wishspeed = vlen(wishvel);
1285 wishspeed = min(wishspeed, PHYS_MAXSPEED(self) * maxspd_mod);
1286 if (IS_DUCKED(self))
1289 float addspeed = wishspeed - dotproduct(self.velocity, wishdir);
1292 float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
1293 self.velocity += accelspeed * wishdir;
1295 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1296 if (!(GAMEPLAYFIX_NOGRAVITYONGROUND))
1297 self.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1);
1298 if (self.velocity * self.velocity)
1299 CSQC_ClientMovement_Move();
1300 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1301 if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1302 self.velocity_z -= g * 0.5;
1304 if (time >= self.teleport_time)
1305 PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
1309 void PM_air(float buttons_prev, float maxspd_mod)
1312 // we get here if we ran out of ammo
1313 if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
1314 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1316 float maxairspd, airaccel;
1317 maxairspd = PHYS_MAXAIRSPEED * min(maxspd_mod, 1);
1318 airaccel = PHYS_AIRACCELERATE * min(maxspd_mod, 1);
1320 makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
1321 vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
1322 + v_right * PHYS_INPUT_MOVEVALUES(self).y;
1324 vector wishdir = normalize(wishvel);
1325 float wishspeed = vlen(wishvel);
1326 float wishspeed0 = min(wishspeed, PHYS_MAXSPEED(self) * maxspd_mod);
1327 wishspeed = min(wishspeed, maxairspd);
1328 if (IS_DUCKED(self))
1331 if (time >= self.teleport_time)
1333 if (pmove_waterjumptime <= 0)
1336 float airaccelqw = PHYS_AIRACCEL_QW(self);
1337 float accelerating = (self.velocity * wishdir > 0);
1338 float wishspeed2 = wishspeed;
1341 if (PHYS_AIRSTOPACCELERATE)
1343 vector curdir = normalize(vec2(self.velocity));
1344 airaccel += (PHYS_AIRSTOPACCELERATE*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1346 // note that for straight forward jumping:
1347 // step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
1348 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1350 // dv/dt = accel * maxspeed (when slow)
1351 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1352 // log dv/dt = logaccel + logmaxspeed (when slow)
1353 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1354 float strafity = IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), -90) + IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), +90); // if one is nonzero, other is always zero
1355 if (PHYS_MAXAIRSTRAFESPEED)
1356 wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED*maxspd_mod));
1357 if (PHYS_AIRSTRAFEACCELERATE)
1358 airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE*maxspd_mod);
1359 if (PHYS_AIRSTRAFEACCEL_QW(self))
1360 airaccelqw = copysign(1-GeomLerp(1-fabs(PHYS_AIRACCEL_QW(self)), strafity, 1-fabs(PHYS_AIRSTRAFEACCEL_QW(self))), ((strafity > 0.5) ? PHYS_AIRSTRAFEACCEL_QW(self) : PHYS_AIRACCEL_QW(self)));
1363 if (PHYS_WARSOWBUNNY_TURNACCEL && accelerating && PHYS_INPUT_MOVEVALUES(self).y == 0 && PHYS_INPUT_MOVEVALUES(self).x != 0)
1364 PM_AirAccelerate(wishdir, wishspeed);
1366 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(self), PHYS_AIRACCEL_SIDEWAYS_FRICTION / maxairspd, PHYS_AIRSPEEDLIMIT_NONQW(self));
1368 if (PHYS_AIRCONTROL)
1369 CPM_PM_Aircontrol(wishdir, wishspeed2);
1372 float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
1373 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1374 self.velocity_z -= g * 0.5;
1376 self.velocity_z -= g;
1377 CSQC_ClientMovement_Move();
1378 if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1379 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1380 self.velocity_z -= g * 0.5;
1384 // Copied from server/g_damage.qc, why is it even in there?
1385 float PM_is_flying()
1387 if (self.flags & FL_ONGROUND)
1389 if (self.waterlevel >= WATERLEVEL_SWIMMING)
1391 traceline(self.origin, self.origin - '0 0 48', MOVE_NORMAL, self);
1392 return trace_fraction >= 1;
1398 //Con_Printf(" %f", PHYS_INPUT_TIMELENGTH);
1399 if (!(PHYS_INPUT_BUTTONS(self) & 2)) // !jump
1400 UNSET_JUMP_HELD(self); // canjump = true
1401 pmove_waterjumptime -= PHYS_INPUT_TIMELENGTH;
1405 WarpZone_PlayerPhysics_FixVAngle();
1407 float maxspd_mod = 1;
1408 maxspd_mod *= PM_check_keepaway();
1409 maxspd_mod *= PHYS_HIGHSPEED;
1411 // fix physics stats for g_movement_highspeed
1412 // TODO maybe rather use maxairspeed? needs testing
1414 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
1415 if (autocvar_sv_airstrafeaccel_qw)
1416 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
1418 self.stat_sv_airstrafeaccel_qw = 0;
1419 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
1420 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
1421 self.stat_movement_highspeed = autocvar_g_movement_highspeed;
1424 if (self.PlayerPhysplug)
1425 if (self.PlayerPhysplug())
1429 PM_check_race_movetime();
1431 anticheat_physics();
1433 float buttons = PHYS_INPUT_BUTTONS(self);
1435 if (PM_check_specialcommand(buttons))
1440 if (buttons != self.buttons_old || PHYS_INPUT_MOVEVALUES(self) != self.movement_old || PHYS_INPUT_ANGLES(self) != self.v_angle_old)
1441 self.parm_idlesince = time;
1444 float buttons_prev = self.buttons_old;
1445 self.buttons_old = buttons;
1446 self.movement_old = PHYS_INPUT_MOVEVALUES(self);
1447 self.v_angle_old = PHYS_INPUT_ANGLES(self);
1449 PM_check_nickspam();
1453 if (IS_BOT_CLIENT(self))
1455 if (playerdemo_read())
1461 self.items &= ~IT_USING_JETPACK;
1463 if (IS_PLAYER(self))
1467 if (self.race_penalty)
1468 if (time > self.race_penalty)
1469 self.race_penalty = 0;
1472 float not_allowed_to_move = 0;
1474 if (self.race_penalty)
1475 not_allowed_to_move = 1;
1478 if (!autocvar_sv_ready_restart_after_countdown)
1479 if (time < game_starttime)
1480 not_allowed_to_move = 1;
1483 if (not_allowed_to_move)
1485 self.velocity = '0 0 0';
1486 self.movetype = MOVETYPE_NONE;
1488 self.disableclientprediction = 2;
1492 else if (self.disableclientprediction == 2)
1494 if (self.movetype == MOVETYPE_NONE)
1495 self.movetype = MOVETYPE_WALK;
1496 self.disableclientprediction = 0;
1502 if (self.movetype == MOVETYPE_NONE)
1507 // when we get here, disableclientprediction cannot be 2
1508 self.disableclientprediction = 0;
1509 if (time < self.ladder_time)
1510 self.disableclientprediction = 1;
1518 MUTATOR_CALLHOOK(PlayerPhysics);
1526 if (self.in_swamp) {
1527 maxspd_mod *= self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
1532 // conveyors: first fix velocity
1533 if (self.conveyor.state)
1534 self.velocity -= self.conveyor.movedir;
1538 if (!IS_PLAYER(self))
1540 maxspd_mod *= autocvar_sv_spectator_speed_multiplier;
1541 if (!self.spectatorspeed)
1542 self.spectatorspeed = maxspd_mod;
1543 if (self.impulse && self.impulse <= 19 || (self.impulse >= 200 && self.impulse <= 209) || (self.impulse >= 220 && self.impulse <= 229))
1545 if (self.lastclassname != "player")
1547 if (self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209))
1548 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
1549 else if (self.impulse == 11)
1550 self.spectatorspeed = maxspd_mod;
1551 else if (self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229))
1552 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
1553 else if (self.impulse >= 1 && self.impulse <= 9)
1554 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
1555 } // otherwise just clear
1558 maxspd_mod *= self.spectatorspeed;
1563 // if dead, behave differently
1569 if (!self.fixangle && !g_bugrigs)
1570 self.angles = '0 1 0' * PHYS_INPUT_ANGLES(self).y;
1574 if (self.flags & FL_ONGROUND)
1575 if (IS_PLAYER(self)) // no fall sounds for observers thank you very much
1579 if (self.waterlevel < WATERLEVEL_SWIMMING)
1580 if (time >= self.ladder_time)
1583 self.nextstep = time + 0.3 + random() * 0.1;
1584 trace_dphitq3surfaceflags = 0;
1585 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
1586 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
1588 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
1589 GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
1591 GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
1601 if (IS_PLAYER(self))
1605 if (self.flags & /* FL_WATERJUMP */ 2048)
1607 self.velocity_x = self.movedir_x;
1608 self.velocity_y = self.movedir_y;
1609 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
1611 self.flags &= ~/* FL_WATERJUMP */ 2048;
1612 self.teleport_time = 0;
1617 else if (g_bugrigs && IS_PLAYER(self))
1621 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
1624 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
1625 PM_swim(maxspd_mod);
1627 else if (time < self.ladder_time)
1628 PM_ladder(maxspd_mod);
1631 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!autocvar_g_jetpack_fuel || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO) && !self.frozen)
1632 PM_jetpack(maxspd_mod);
1638 // jump if on ground with jump button pressed but only if it has been
1639 // released at least once since the last jump
1640 if (PHYS_INPUT_BUTTONS(self) & 2)
1642 if (IS_ONGROUND(self) && (!IS_JUMP_HELD(self) || !cvar("cl_movement_track_canjump")))
1644 self.velocity_z += PHYS_JUMPVELOCITY;
1645 UNSET_ONGROUND(self);
1646 SET_JUMP_HELD(self); // canjump = false
1650 UNSET_JUMP_HELD(self); // canjump = true
1652 if (IS_ONGROUND(self))
1653 PM_walk(buttons_prev, maxspd_mod);
1655 PM_air(buttons_prev, maxspd_mod);
1659 if (!IS_OBSERVER(self))
1665 if (self.flags & FL_ONGROUND)
1666 self.lastground = time;
1669 // conveyors: then break velocity again
1670 if (self.conveyor.state)
1671 self.velocity += self.conveyor.movedir;
1674 self.lastflags = self.flags;
1675 self.lastclassname = self.classname;
1678 void CSQC_ClientMovement_PlayerMove_Frame()
1680 // if a move is more than 50ms, do it as two moves (matching qwsv)
1681 //Con_Printf("%i ", self.cmd.msec);
1682 if (PHYS_INPUT_TIMELENGTH > 0.0005)
1684 if (PHYS_INPUT_TIMELENGTH > 0.05)
1686 PHYS_INPUT_TIMELENGTH /= 2;
1692 // we REALLY need this handling to happen, even if the move is not executed
1693 if (!(PHYS_INPUT_BUTTONS(self) & 2)) // !jump
1694 UNSET_JUMP_HELD(self); // canjump = true
1697 #undef PHYS_INPUT_ANGLES
1698 #undef PHYS_INPUT_BUTTONS
1700 #undef PHYS_INPUT_TIMELENGTH
1702 #undef PHYS_INPUT_MOVEVALUES
1704 #undef GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE
1705 #undef GAMEPLAYFIX_NOGRAVITYONGROUND
1706 #undef GAMEPLAYFIX_Q2AIRACCELERATE
1713 #undef SET_JUMP_HELD
1714 #undef UNSET_JUMP_HELD
1718 #undef UNSET_ONGROUND
1720 #undef PHYS_ACCELERATE
1721 #undef PHYS_AIRACCEL_QW
1722 #undef PHYS_AIRACCEL_QW_STRETCHFACTOR
1723 #undef PHYS_AIRACCEL_SIDEWAYS_FRICTION
1724 #undef PHYS_AIRACCELERATE
1725 #undef PHYS_AIRCONTROL
1726 #undef PHYS_AIRCONTROL_PENALTY
1727 #undef PHYS_AIRCONTROL_POWER
1728 #undef PHYS_AIRSPEEDLIMIT_NONQW
1729 #undef PHYS_AIRSTOPACCELERATE
1730 #undef PHYS_AIRSTRAFEACCEL_QW
1731 #undef PHYS_AIRSTRAFEACCELERATE
1732 #undef PHYS_EDGEFRICTION
1733 #undef PHYS_ENTGRAVITY
1734 #undef PHYS_FRICTION
1736 #undef PHYS_HIGHSPEED
1737 #undef PHYS_JUMPVELOCITY
1738 #undef PHYS_MAXAIRSPEED
1739 #undef PHYS_MAXAIRSTRAFESPEED
1740 #undef PHYS_MAXSPEED
1741 #undef PHYS_STEPHEIGHT
1742 #undef PHYS_STOPSPEED
1743 #undef PHYS_WARSOWBUNNY_ACCEL
1744 #undef PHYS_WARSOWBUNNY_BACKTOSIDERATIO
1745 #undef PHYS_WARSOWBUNNY_AIRFORWARDACCEL
1746 #undef PHYS_WARSOWBUNNY_TOPSPEED
1747 #undef PHYS_WARSOWBUNNY_TURNACCEL
1751 void SV_PlayerPhysics(void)