2 #include "triggers/include.qh"
7 #include "../server/miscfunctions.qh"
8 #include "triggers/trigger/viewloc.qh"
10 // client side physics
11 bool Physics_Valid(string thecvar)
13 return autocvar_g_physics_clientselect && strhasword(autocvar_g_physics_clientselect_options, thecvar);
16 float Physics_ClientOption(entity this, string option)
18 if(Physics_Valid(this.cvar_cl_physics))
20 string s = sprintf("g_physics_%s_%s", this.cvar_cl_physics, option);
21 if(cvar_type(s) & CVAR_TYPEFLAG_EXISTS)
24 if(autocvar_g_physics_clientselect && autocvar_g_physics_clientselect_default)
26 string s = sprintf("g_physics_%s_%s", autocvar_g_physics_clientselect_default, option);
27 if(cvar_type(s) & CVAR_TYPEFLAG_EXISTS)
30 return cvar(strcat("sv_", option));
33 void Physics_UpdateStats(entity this, float maxspd_mod)
35 STAT(MOVEVARS_AIRACCEL_QW, this) = AdjustAirAccelQW(Physics_ClientOption(this, "airaccel_qw"), maxspd_mod);
36 STAT(MOVEVARS_AIRSTRAFEACCEL_QW, this) = (Physics_ClientOption(this, "airstrafeaccel_qw"))
37 ? AdjustAirAccelQW(Physics_ClientOption(this, "airstrafeaccel_qw"), maxspd_mod)
39 STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW, this) = Physics_ClientOption(this, "airspeedlimit_nonqw") * maxspd_mod;
40 STAT(MOVEVARS_MAXSPEED, this) = Physics_ClientOption(this, "maxspeed") * maxspd_mod; // also slow walking
43 // fix some new settings
44 STAT(MOVEVARS_AIRACCEL_QW_STRETCHFACTOR, this) = Physics_ClientOption(this, "airaccel_qw_stretchfactor");
45 STAT(MOVEVARS_MAXAIRSTRAFESPEED, this) = Physics_ClientOption(this, "maxairstrafespeed");
46 STAT(MOVEVARS_MAXAIRSPEED, this) = Physics_ClientOption(this, "maxairspeed");
47 STAT(MOVEVARS_AIRSTRAFEACCELERATE, this) = Physics_ClientOption(this, "airstrafeaccelerate");
48 STAT(MOVEVARS_WARSOWBUNNY_TURNACCEL, this) = Physics_ClientOption(this, "warsowbunny_turnaccel");
49 STAT(MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION, this) = Physics_ClientOption(this, "airaccel_sideways_friction");
50 STAT(MOVEVARS_AIRCONTROL, this) = Physics_ClientOption(this, "aircontrol");
51 STAT(MOVEVARS_AIRCONTROL_POWER, this) = Physics_ClientOption(this, "aircontrol_power");
52 STAT(MOVEVARS_AIRCONTROL_PENALTY, this) = Physics_ClientOption(this, "aircontrol_penalty");
53 STAT(MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL, this) = Physics_ClientOption(this, "warsowbunny_airforwardaccel");
54 STAT(MOVEVARS_WARSOWBUNNY_TOPSPEED, this) = Physics_ClientOption(this, "warsowbunny_topspeed");
55 STAT(MOVEVARS_WARSOWBUNNY_ACCEL, this) = Physics_ClientOption(this, "warsowbunny_accel");
56 STAT(MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO, this) = Physics_ClientOption(this, "warsowbunny_backtosideratio");
57 STAT(MOVEVARS_FRICTION, this) = Physics_ClientOption(this, "friction");
58 STAT(MOVEVARS_ACCELERATE, this) = Physics_ClientOption(this, "accelerate");
59 STAT(MOVEVARS_STOPSPEED, this) = Physics_ClientOption(this, "stopspeed");
60 STAT(MOVEVARS_AIRACCELERATE, this) = Physics_ClientOption(this, "airaccelerate");
61 STAT(MOVEVARS_AIRSTOPACCELERATE, this) = Physics_ClientOption(this, "airstopaccelerate");
62 STAT(MOVEVARS_JUMPVELOCITY, this) = Physics_ClientOption(this, "jumpvelocity");
63 STAT(MOVEVARS_TRACK_CANJUMP, this) = Physics_ClientOption(this, "track_canjump");
67 float IsMoveInDirection(vector mv, float ang) // key mix factor
69 if (mv_x == 0 && mv_y == 0)
70 return 0; // avoid division by zero
71 ang -= RAD2DEG * atan2(mv_y, mv_x);
72 ang = remainder(ang, 360) / 45;
73 return ang > 1 ? 0 : ang < -1 ? 0 : 1 - fabs(ang);
76 float GeomLerp(float a, float lerp, float b)
78 return a == 0 ? (lerp < 1 ? 0 : b)
79 : b == 0 ? (lerp > 0 ? 0 : a)
80 : a * pow(fabs(b / a), lerp);
83 #define unstick_offsets(X) \
84 /* 1 no nudge (just return the original if this test passes) */ \
85 X(' 0.000 0.000 0.000') \
86 /* 6 simple nudges */ \
87 X(' 0.000 0.000 0.125') X('0.000 0.000 -0.125') \
88 X('-0.125 0.000 0.000') X('0.125 0.000 0.000') \
89 X(' 0.000 -0.125 0.000') X('0.000 0.125 0.000') \
90 /* 4 diagonal flat nudges */ \
91 X('-0.125 -0.125 0.000') X('0.125 -0.125 0.000') \
92 X('-0.125 0.125 0.000') X('0.125 0.125 0.000') \
93 /* 8 diagonal upward nudges */ \
94 X('-0.125 0.000 0.125') X('0.125 0.000 0.125') \
95 X(' 0.000 -0.125 0.125') X('0.000 0.125 0.125') \
96 X('-0.125 -0.125 0.125') X('0.125 -0.125 0.125') \
97 X('-0.125 0.125 0.125') X('0.125 0.125 0.125') \
98 /* 8 diagonal downward nudges */ \
99 X('-0.125 0.000 -0.125') X('0.125 0.000 -0.125') \
100 X(' 0.000 -0.125 -0.125') X('0.000 0.125 -0.125') \
101 X('-0.125 -0.125 -0.125') X('0.125 -0.125 -0.125') \
102 X('-0.125 0.125 -0.125') X('0.125 0.125 -0.125') \
105 void PM_ClientMovement_Unstick(entity this)
107 #define X(unstick_offset) \
109 vector neworigin = unstick_offset + this.origin; \
110 tracebox(neworigin, PL_CROUCH_MIN, PL_CROUCH_MAX, neworigin, MOVE_NORMAL, this); \
111 if (!trace_startsolid) \
113 setorigin(this, neworigin); \
121 void PM_ClientMovement_UpdateStatus(entity this, bool ground)
124 // make sure player is not stuck
125 PM_ClientMovement_Unstick(this);
128 if (PHYS_INPUT_BUTTON_CROUCH(this))
130 // wants to crouch, this always works
131 if (!IS_DUCKED(this)) SET_DUCKED(this);
135 // wants to stand, if currently crouching we need to check for a low ceiling first
138 tracebox(this.origin, PL_MIN, PL_MAX, this.origin, MOVE_NORMAL, this);
139 if (!trace_startsolid) UNSET_DUCKED(this);
144 vector origin1 = this.origin + '0 0 1';
145 vector origin2 = this.origin - '0 0 1';
147 if (ground && autocvar_cl_movement != 3)
149 tracebox(origin1, this.mins, this.maxs, origin2, MOVE_NORMAL, this);
150 if (trace_fraction < 1.0 && trace_plane_normal.z > 0.7)
154 // this code actually "predicts" an impact; so let's clip velocity first
155 this.velocity -= this.velocity * trace_plane_normal * trace_plane_normal;
158 UNSET_ONGROUND(this);
161 // set watertype/waterlevel
162 origin1 = this.origin;
163 origin1.z += this.mins_z + 1;
164 this.waterlevel = WATERLEVEL_NONE;
166 int thepoint = pointcontents(origin1);
168 this.watertype = (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME);
172 this.waterlevel = WATERLEVEL_WETFEET;
173 origin1.z = this.origin.z + (this.mins.z + this.maxs.z) * 0.5;
174 thepoint = pointcontents(origin1);
175 if (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME)
177 this.waterlevel = WATERLEVEL_SWIMMING;
178 origin1.z = this.origin.z + 22;
179 thepoint = pointcontents(origin1);
180 if (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME)
181 this.waterlevel = WATERLEVEL_SUBMERGED;
185 if (IS_ONGROUND(this) || this.velocity.z <= 0 || PHYS_TELEPORT_TIME(this) <= 0)
186 PHYS_TELEPORT_TIME(this) = 0;
190 void PM_ClientMovement_Move(entity this)
194 PM_ClientMovement_UpdateStatus(this, false);
195 if(autocvar_cl_movement == 3)
202 vector currentorigin2;
204 vector primalvelocity;
206 vector trace1_endpos = '0 0 0';
207 vector trace2_endpos = '0 0 0';
208 vector trace3_endpos = '0 0 0';
209 float trace1_fraction = 0;
210 float trace2_fraction = 0;
211 float trace3_fraction = 0;
212 vector trace1_plane_normal = '0 0 0';
213 vector trace2_plane_normal = '0 0 0';
214 vector trace3_plane_normal = '0 0 0';
216 primalvelocity = this.velocity;
217 for(bump = 0, t = PHYS_INPUT_TIMELENGTH; bump < 8 && (this.velocity * this.velocity) > 0; bump++)
219 neworigin = this.origin + t * this.velocity;
220 tracebox(this.origin, this.mins, this.maxs, neworigin, MOVE_NORMAL, this);
221 trace1_endpos = trace_endpos;
222 trace1_fraction = trace_fraction;
223 trace1_plane_normal = trace_plane_normal;
224 if(trace1_fraction < 1 && trace1_plane_normal_z == 0)
226 // may be a step or wall, try stepping up
227 // first move forward at a higher level
228 currentorigin2 = this.origin;
229 currentorigin2_z += PHYS_STEPHEIGHT;
230 neworigin2 = neworigin;
231 neworigin2_z += PHYS_STEPHEIGHT;
232 tracebox(currentorigin2, this.mins, this.maxs, neworigin2, MOVE_NORMAL, this);
233 trace2_endpos = trace_endpos;
234 trace2_fraction = trace_fraction;
235 trace2_plane_normal = trace_plane_normal;
236 if(!trace_startsolid)
238 // then move down from there
239 currentorigin2 = trace2_endpos;
240 neworigin2 = trace2_endpos;
241 neworigin2_z = this.origin_z;
242 tracebox(currentorigin2, this.mins, this.maxs, neworigin2, MOVE_NORMAL, this);
243 trace3_endpos = trace_endpos;
244 trace3_fraction = trace_fraction;
245 trace3_plane_normal = trace_plane_normal;
246 // accept the new trace if it made some progress
247 if(fabs(trace3_endpos_x - trace1_endpos_x) >= 0.03125 || fabs(trace3_endpos_y - trace1_endpos_y) >= 0.03125)
249 trace1_endpos = trace2_endpos;
250 trace1_fraction = trace2_fraction;
251 trace1_plane_normal = trace2_plane_normal;
252 trace1_endpos = trace3_endpos;
257 // check if it moved at all
258 if(trace1_fraction >= 0.001)
259 setorigin(this, trace1_endpos);
261 // check if it moved all the way
262 if(trace1_fraction == 1)
265 // this is only really needed for nogravityonground combined with gravityunaffectedbyticrate
266 // <LordHavoc> I'm pretty sure I commented it out solely because it seemed redundant
267 // this got commented out in a change that supposedly makes the code match QW better
268 // so if this is broken, maybe put it in an if(cls.protocol != PROTOCOL_QUAKEWORLD) block
269 if(trace1_plane_normal_z > 0.7)
272 t -= t * trace1_fraction;
274 f = (this.velocity * trace1_plane_normal);
275 this.velocity = this.velocity + -f * trace1_plane_normal;
277 if(PHYS_TELEPORT_TIME(this) > 0)
278 this.velocity = primalvelocity;
282 void CPM_PM_Aircontrol(entity this, vector wishdir, float wishspeed)
284 float k = 32 * (2 * IsMoveInDirection(this.movement, 0) - 1);
288 k *= bound(0, wishspeed / PHYS_MAXAIRSPEED(this), 1);
290 float zspeed = this.velocity_z;
292 float xyspeed = vlen(this.velocity);
293 this.velocity = normalize(this.velocity);
295 float dot = this.velocity * wishdir;
297 if (dot > 0) // we can't change direction while slowing down
299 k *= pow(dot, PHYS_AIRCONTROL_POWER(this)) * PHYS_INPUT_TIMELENGTH;
300 xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY(this) * sqrt(max(0, 1 - dot*dot)) * k/32);
301 k *= PHYS_AIRCONTROL(this);
302 this.velocity = normalize(this.velocity * xyspeed + wishdir * k);
305 this.velocity = this.velocity * xyspeed;
306 this.velocity_z = zspeed;
309 float AdjustAirAccelQW(float accelqw, float factor)
311 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
314 // example config for alternate speed clamping:
315 // sv_airaccel_qw 0.8
316 // sv_airaccel_sideways_friction 0
317 // prvm_globalset server speedclamp_mode 1
319 void PM_Accelerate(entity this, vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
321 float speedclamp = stretchfactor > 0 ? stretchfactor
322 : accelqw < 0 ? 1 // full clamping, no stretch
325 accelqw = fabs(accelqw);
327 if (GAMEPLAYFIX_Q2AIRACCELERATE)
328 wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
330 float vel_straight = this.velocity * wishdir;
331 float vel_z = this.velocity_z;
332 vector vel_xy = vec2(this.velocity);
333 vector vel_perpend = vel_xy - vel_straight * wishdir;
335 float step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
337 float vel_xy_current = vlen(vel_xy);
339 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
340 float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
341 float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
342 vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
343 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
345 if (sidefric < 0 && (vel_perpend*vel_perpend))
346 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
348 float f = max(0, 1 + PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
349 float themin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
350 // assume: themin > 1
351 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
352 // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
353 // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
354 // obviously, this cannot be
359 themin = sqrt(themin);
360 vel_perpend *= max(themin, f);
364 vel_perpend *= max(0, 1 - PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
366 vel_xy = vel_straight * wishdir + vel_perpend;
370 float vel_xy_preclamp;
371 vel_xy_preclamp = vlen(vel_xy);
372 if (vel_xy_preclamp > 0) // prevent division by zero
374 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
375 if (vel_xy_current < vel_xy_preclamp)
376 vel_xy *= (vel_xy_current / vel_xy_preclamp);
380 this.velocity = vel_xy + vel_z * '0 0 1';
383 void PM_AirAccelerate(entity this, vector wishdir, float wishspeed)
388 vector curvel = this.velocity;
390 float curspeed = vlen(curvel);
392 if (wishspeed > curspeed * 1.01)
393 wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL(this) * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH);
396 float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED(this) - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED(this) - PHYS_MAXSPEED(this)));
397 wishspeed = max(curspeed, PHYS_MAXSPEED(this)) + PHYS_WARSOWBUNNY_ACCEL(this) * f * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH;
399 vector wishvel = wishdir * wishspeed;
400 vector acceldir = wishvel - curvel;
401 float addspeed = vlen(acceldir);
402 acceldir = normalize(acceldir);
404 float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL(this) * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH);
406 if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this) < 1)
408 vector curdir = normalize(curvel);
409 float dot = acceldir * curdir;
411 acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this)) * dot * curdir;
414 this.velocity += accelspeed * acceldir;
422 When you press the jump key
423 returns true if handled
426 bool PlayerJump(entity this)
428 if (PHYS_FROZEN(this))
429 return true; // no jumping in freezetag when frozen
432 if (this.player_blocked)
433 return true; // no jumping while blocked
436 bool doublejump = false;
437 float mjumpheight = PHYS_JUMPVELOCITY(this);
439 if (MUTATOR_CALLHOOK(PlayerJump, this, doublejump, mjumpheight))
442 doublejump = player_multijump;
443 mjumpheight = player_jumpheight;
445 if (this.waterlevel >= WATERLEVEL_SWIMMING)
447 this.velocity_z = PHYS_MAXSPEED(this) * 0.7;
452 if (!IS_ONGROUND(this))
453 return IS_JUMP_HELD(this);
455 bool track_jump = PHYS_CL_TRACK_CANJUMP(this);
456 if(PHYS_TRACK_CANJUMP(this))
460 if (IS_JUMP_HELD(this))
463 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
464 // velocity bounds. Final velocity is bound between (jumpheight *
465 // min + jumpheight) and (jumpheight * max + jumpheight);
467 if(PHYS_JUMPSPEEDCAP_MIN != "")
469 float minjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MIN);
471 if (this.velocity_z < minjumpspeed)
472 mjumpheight += minjumpspeed - this.velocity_z;
475 if(PHYS_JUMPSPEEDCAP_MAX != "")
477 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
478 tracebox(this.origin + '0 0 0.01', this.mins, this.maxs, this.origin - '0 0 0.01', MOVE_NORMAL, this);
480 if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS))
482 float maxjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MAX);
484 if (this.velocity_z > maxjumpspeed)
485 mjumpheight -= this.velocity_z - maxjumpspeed;
489 if (!WAS_ONGROUND(this))
492 if(autocvar_speedmeter)
493 LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n"));
495 if(this.lastground < time - 0.3)
497 this.velocity_x *= (1 - PHYS_FRICTION_ONLAND);
498 this.velocity_y *= (1 - PHYS_FRICTION_ONLAND);
501 if(this.jumppadcount > 1)
502 LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n"));
503 this.jumppadcount = 0;
507 this.velocity_z += mjumpheight;
509 UNSET_ONGROUND(this);
514 this.oldvelocity_z = this.velocity_z;
516 animdecide_setaction(this, ANIMACTION_JUMP, true);
518 if (autocvar_g_jump_grunt)
519 WITH(entity, this, this, PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND));
524 void CheckWaterJump(entity this)
526 // check for a jump-out-of-water
527 makevectors(this.v_angle);
528 vector start = this.origin;
531 normalize(v_forward);
532 vector end = start + v_forward*24;
533 traceline (start, end, true, this);
534 if (trace_fraction < 1)
536 start_z = start_z + this.maxs_z - 8;
537 end = start + v_forward*24;
538 this.movedir = trace_plane_normal * -50;
539 traceline(start, end, true, this);
540 if (trace_fraction == 1)
541 { // open at eye level
542 this.velocity_z = 225;
543 this.flags |= FL_WATERJUMP;
545 PHYS_TELEPORT_TIME(this) = time + 2; // safety net
552 #define JETPACK_JUMP(s) s.cvar_cl_jetpack_jump
554 float autocvar_cl_jetpack_jump;
555 #define JETPACK_JUMP(s) autocvar_cl_jetpack_jump
557 .float jetpack_stopped;
558 void CheckPlayerJump(entity this)
561 float was_flying = ITEMS_STAT(this) & IT_USING_JETPACK;
563 if (JETPACK_JUMP(this) < 2)
564 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
566 if(PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this))
568 float air_jump = !PlayerJump(this) || player_multijump; // PlayerJump() has important side effects
569 float activate = JETPACK_JUMP(this) && air_jump && PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this);
570 float has_fuel = !PHYS_JETPACK_FUEL || PHYS_AMMO_FUEL(this) || ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO;
572 if (!(ITEMS_STAT(this) & ITEM_Jetpack.m_itemid)) { }
573 else if (this.jetpack_stopped) { }
577 if (was_flying) // TODO: ran out of fuel message
578 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
580 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
582 this.jetpack_stopped = true;
583 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
585 else if (activate && !PHYS_FROZEN(this))
586 ITEMS_STAT(this) |= IT_USING_JETPACK;
590 this.jetpack_stopped = false;
591 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
593 if (!PHYS_INPUT_BUTTON_JUMP(this))
594 UNSET_JUMP_HELD(this);
596 if (this.waterlevel == WATERLEVEL_SWIMMING)
597 CheckWaterJump(this);
600 float racecar_angle(float forward, float down)
608 float ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
610 float angle_mult = forward / (800 + forward);
613 return ret * angle_mult + 360 * (1 - angle_mult);
615 return ret * angle_mult;
618 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
619 .float specialcommand_pos;
620 void SpecialCommand()
623 if (!CheatImpulse(99))
624 LOG_INFO("A hollow voice says \"Plugh\".\n");
628 float PM_check_specialcommand(entity this, float buttons)
634 else if (buttons == 1)
636 else if (buttons == 2)
638 else if (buttons == 128)
640 else if (buttons == 256)
642 else if (buttons == 512)
644 else if (buttons == 1024)
649 if (c == substring(specialcommand, this.specialcommand_pos, 1))
651 this.specialcommand_pos += 1;
652 if (this.specialcommand_pos >= strlen(specialcommand))
654 this.specialcommand_pos = 0;
659 else if (this.specialcommand_pos && (c != substring(specialcommand, this.specialcommand_pos - 1, 1)))
660 this.specialcommand_pos = 0;
665 void PM_check_nickspam(entity this)
668 if (time >= this.nickspamtime)
670 if (this.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
672 // slight annoyance for nick change scripts
673 this.movement = -1 * this.movement;
674 this.BUTTON_ATCK = this.BUTTON_JUMP = this.BUTTON_ATCK2 = this.BUTTON_ZOOM = this.BUTTON_CROUCH = this.BUTTON_HOOK = this.BUTTON_USE = 0;
676 if (this.nickspamcount >= autocvar_g_nick_flood_penalty_red) // if you are persistent and the slight annoyance above does not stop you, I'll show you!
678 this.v_angle_x = random() * 360;
679 this.v_angle_y = random() * 360;
680 // at least I'm not forcing retardedview by also assigning to angles_z
681 this.fixangle = true;
687 void PM_check_punch(entity this)
690 if (this.punchangle != '0 0 0')
692 float f = vlen(this.punchangle) - 10 * PHYS_INPUT_TIMELENGTH;
694 this.punchangle = normalize(this.punchangle) * f;
696 this.punchangle = '0 0 0';
699 if (this.punchvector != '0 0 0')
701 float f = vlen(this.punchvector) - 30 * PHYS_INPUT_TIMELENGTH;
703 this.punchvector = normalize(this.punchvector) * f;
705 this.punchvector = '0 0 0';
710 // predict frozen movement, as frozen players CAN move in some cases
711 void PM_check_frozen(entity this)
713 if (!PHYS_FROZEN(this))
715 if (PHYS_DODGING_FROZEN
717 && IS_REAL_CLIENT(this)
721 this.movement_x = bound(-5, this.movement.x, 5);
722 this.movement_y = bound(-5, this.movement.y, 5);
723 this.movement_z = bound(-5, this.movement.z, 5);
726 this.movement = '0 0 0';
728 vector midpoint = ((this.absmin + this.absmax) * 0.5);
729 if (pointcontents(midpoint) == CONTENT_WATER)
731 this.velocity = this.velocity * 0.5;
733 if (pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
734 this.velocity_z = 200;
738 void PM_check_hitground(entity this)
741 if (!IS_PLAYER(this)) return; // no fall sounds for observers thank you very much
742 if (!IS_ONGROUND(this)) return;
743 if (!this.wasFlying) return;
744 this.wasFlying = false;
745 if (this.waterlevel >= WATERLEVEL_SWIMMING) return;
746 if (time < this.ladder_time) return;
747 if (this.hook) return;
748 this.nextstep = time + 0.3 + random() * 0.1;
749 trace_dphitq3surfaceflags = 0;
750 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
751 if ((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)) return;
752 entity fall = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS) ? GS_FALL_METAL : GS_FALL;
753 WITH(entity, self, this, GlobalSound(fall, CH_PLAYER, VOICETYPE_PLAYERSOUND));
757 void PM_check_blocked(entity this)
760 if (!this.player_blocked)
762 this.movement = '0 0 0';
763 this.disableclientprediction = 1;
767 void PM_fly(entity this, float maxspd_mod)
769 // noclipping or flying
770 UNSET_ONGROUND(this);
772 this.velocity = this.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this));
773 makevectors(this.v_angle);
774 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
775 vector wishvel = v_forward * this.movement.x
776 + v_right * this.movement.y
777 + '0 0 1' * this.movement.z;
779 vector wishdir = normalize(wishvel);
780 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod);
781 if(time >= PHYS_TELEPORT_TIME(this))
782 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this) * maxspd_mod, 1, 0, 0, 0);
783 PM_ClientMovement_Move(this);
786 void PM_swim(entity this, float maxspd_mod)
789 UNSET_ONGROUND(this);
791 float jump = PHYS_INPUT_BUTTON_JUMP(this);
792 // water jump only in certain situations
793 // this mimics quakeworld code
794 if (jump && this.waterlevel == WATERLEVEL_SWIMMING && this.velocity_z >= -180)
796 vector yawangles = '0 1 0' * this.v_angle.y;
797 makevectors(yawangles);
798 vector forward = v_forward;
799 vector spot = this.origin + 24 * forward;
801 traceline(spot, spot, MOVE_NOMONSTERS, this);
802 if (trace_startsolid)
805 traceline(spot, spot, MOVE_NOMONSTERS, this);
806 if (!trace_startsolid)
808 this.velocity = forward * 50;
809 this.velocity_z = 310;
810 PHYS_TELEPORT_TIME(this) = 2;
811 UNSET_ONGROUND(this);
816 makevectors(this.v_angle);
817 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
818 vector wishvel = v_forward * this.movement.x
819 + v_right * this.movement.y
820 + '0 0 1' * this.movement.z;
821 if (wishvel == '0 0 0')
822 wishvel = '0 0 -60'; // drift towards bottom
824 vector wishdir = normalize(wishvel);
825 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod) * 0.7;
830 // if (pmove_waterjumptime <= 0) // TODO: use
833 float f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this);
834 f = min(max(0, f), 1);
837 f = wishspeed - this.velocity * wishdir;
840 float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, f);
841 this.velocity += accelspeed * wishdir;
844 // holding jump button swims upward slowly
848 if (this.watertype & CONTENT_LAVA)
849 this.velocity_z = 50;
850 else if (this.watertype & CONTENT_SLIME)
851 this.velocity_z = 80;
854 if (IS_NEXUIZ_DERIVED(gamemode))
856 this.velocity_z = 200;
859 this.velocity_z = 100;
864 // water acceleration
865 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this) * maxspd_mod, 1, 0, 0, 0);
866 PM_ClientMovement_Move(this);
869 void PM_ladder(entity this, float maxspd_mod)
871 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
872 UNSET_ONGROUND(this);
875 g = PHYS_GRAVITY(this) * PHYS_INPUT_TIMELENGTH;
876 if (PHYS_ENTGRAVITY(this))
877 g *= PHYS_ENTGRAVITY(this);
878 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
881 this.velocity_z += g;
884 this.velocity = this.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this));
885 makevectors(this.v_angle);
886 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
887 vector wishvel = v_forward * this.movement_x
888 + v_right * this.movement_y
889 + '0 0 1' * this.movement_z;
890 this.velocity_z += g;
891 if (this.ladder_entity.classname == "func_water")
893 float f = vlen(wishvel);
894 if (f > this.ladder_entity.speed)
895 wishvel *= (this.ladder_entity.speed / f);
897 this.watertype = this.ladder_entity.skin;
898 f = this.ladder_entity.origin_z + this.ladder_entity.maxs_z;
899 if ((this.origin_z + this.view_ofs_z) < f)
900 this.waterlevel = WATERLEVEL_SUBMERGED;
901 else if ((this.origin_z + (this.mins_z + this.maxs_z) * 0.5) < f)
902 this.waterlevel = WATERLEVEL_SWIMMING;
903 else if ((this.origin_z + this.mins_z + 1) < f)
904 this.waterlevel = WATERLEVEL_WETFEET;
907 this.waterlevel = WATERLEVEL_NONE;
908 this.watertype = CONTENT_EMPTY;
912 vector wishdir = normalize(wishvel);
913 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod);
914 if(time >= PHYS_TELEPORT_TIME(this))
915 // water acceleration
916 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this)*maxspd_mod, 1, 0, 0, 0);
917 PM_ClientMovement_Move(this);
920 void PM_jetpack(entity this, float maxspd_mod)
922 //makevectors(this.v_angle.y * '0 1 0');
923 makevectors(this.v_angle);
924 vector wishvel = v_forward * this.movement_x
925 + v_right * this.movement_y;
926 // add remaining speed as Z component
927 float maxairspd = PHYS_MAXAIRSPEED(this) * max(1, maxspd_mod);
929 wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
930 // add the unused velocity as up component
933 // if (this.BUTTON_JUMP)
934 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
936 // it is now normalized, so...
937 float a_side = PHYS_JETPACK_ACCEL_SIDE;
938 float a_up = PHYS_JETPACK_ACCEL_UP;
939 float a_add = PHYS_JETPACK_ANTIGRAVITY * PHYS_GRAVITY(this);
947 //////////////////////////////////////////////////////////////////////////////////////
948 // finding the maximum over all vectors of above form
949 // with wishvel having an absolute value of 1
950 //////////////////////////////////////////////////////////////////////////////////////
951 // we're finding the maximum over
952 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
953 // for z in the range from -1 to 1
954 //////////////////////////////////////////////////////////////////////////////////////
955 // maximum is EITHER attained at the single extreme point:
956 float a_diff = a_side * a_side - a_up * a_up;
960 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
961 if (f > -1 && f < 1) // can it be attained?
963 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
967 // OR attained at z = 1:
968 f = (a_up + a_add) * (a_up + a_add);
974 // OR attained at z = -1:
975 f = (a_up - a_add) * (a_up - a_add);
982 //////////////////////////////////////////////////////////////////////////////////////
984 //print("best possible acceleration: ", ftos(best), "\n");
987 fxy = bound(0, 1 - (this.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE, 1);
988 if (wishvel_z - PHYS_GRAVITY(this) > 0)
989 fz = bound(0, 1 - this.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
991 fz = bound(0, 1 + this.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
994 fvel = vlen(wishvel);
997 wishvel_z = (wishvel_z - PHYS_GRAVITY(this)) * fz + PHYS_GRAVITY(this);
999 fvel = min(1, vlen(wishvel) / best);
1000 if (PHYS_JETPACK_FUEL && !(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO))
1001 f = min(1, PHYS_AMMO_FUEL(this) / (PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel));
1005 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1007 if (f > 0 && wishvel != '0 0 0')
1009 this.velocity = this.velocity + wishvel * f * PHYS_INPUT_TIMELENGTH;
1010 UNSET_ONGROUND(this);
1013 if (!(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO))
1014 this.ammo_fuel -= PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel * f;
1016 ITEMS_STAT(this) |= IT_USING_JETPACK;
1018 // jetpack also inhibits health regeneration, but only for 1 second
1019 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1024 float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH;
1025 if(autocvar_cl_movement != 3)
1027 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1028 this.velocity_z -= g * 0.5;
1030 this.velocity_z -= g;
1032 PM_ClientMovement_Move(this);
1033 if(autocvar_cl_movement != 3)
1035 if (!IS_ONGROUND(this) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1036 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1037 this.velocity_z -= g * 0.5;
1042 void PM_walk(entity this, float maxspd_mod)
1044 if (!WAS_ONGROUND(this))
1047 if (autocvar_speedmeter)
1048 LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n"));
1050 if (this.lastground < time - 0.3)
1051 this.velocity *= (1 - PHYS_FRICTION_ONLAND);
1053 if (this.jumppadcount > 1)
1054 LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n"));
1055 this.jumppadcount = 0;
1060 makevectors(this.v_angle.y * '0 1 0');
1061 const vector wishvel = v_forward * this.movement.x
1062 + v_right * this.movement.y;
1064 const vector wishdir = normalize(wishvel);
1065 float wishspeed = vlen(wishvel);
1066 wishspeed = min(wishspeed, PHYS_MAXSPEED(this) * maxspd_mod);
1067 if (IS_DUCKED(this)) wishspeed *= 0.5;
1069 // apply edge friction
1070 const float f2 = vlen2(vec2(this.velocity));
1073 trace_dphitq3surfaceflags = 0;
1074 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
1075 // TODO: apply edge friction
1076 // apply ground friction
1077 const int realfriction = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK)
1078 ? PHYS_FRICTION_SLICK
1079 : PHYS_FRICTION(this);
1082 f = 1 - PHYS_INPUT_TIMELENGTH * realfriction * ((f < PHYS_STOPSPEED(this)) ? (PHYS_STOPSPEED(this) / f) : 1);
1086 Mathematical analysis time!
1088 Our goal is to invert this mess.
1090 For the two cases we get:
1091 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * (PHYS_STOPSPEED(this) / v0) * PHYS_FRICTION(this))
1092 = v0 - PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this)
1093 v0 = v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this)
1095 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1096 v0 = v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1098 These cases would be chosen ONLY if:
1099 v0 < PHYS_STOPSPEED(this)
1100 v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this) < PHYS_STOPSPEED(this)
1101 v < PHYS_STOPSPEED(this) * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1103 v0 >= PHYS_STOPSPEED(this)
1104 v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this)) >= PHYS_STOPSPEED(this)
1105 v >= PHYS_STOPSPEED(this) * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1108 const float addspeed = wishspeed - this.velocity * wishdir;
1111 const float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
1112 this.velocity += accelspeed * wishdir;
1115 float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH;
1116 if(autocvar_cl_movement != 3)
1118 if (!(GAMEPLAYFIX_NOGRAVITYONGROUND))
1119 this.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1);
1121 if (vdist(this.velocity, >, 0))
1122 PM_ClientMovement_Move(this);
1123 if(autocvar_cl_movement != 3)
1125 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1126 if (!IS_ONGROUND(this) || !GAMEPLAYFIX_NOGRAVITYONGROUND)
1127 this.velocity_z -= g * 0.5;
1132 void PM_air(entity this, float buttons_prev, float maxspd_mod)
1134 makevectors(this.v_angle.y * '0 1 0');
1135 vector wishvel = v_forward * this.movement.x
1136 + v_right * this.movement.y;
1138 vector wishdir = normalize(wishvel);
1139 float wishspeed = vlen(wishvel);
1141 if(PHYS_TELEPORT_TIME(this) < time)
1143 float maxairspd = PHYS_MAXAIRSPEED(this) * min(maxspd_mod, 1);
1145 // apply air speed limit
1146 float airaccelqw = PHYS_AIRACCEL_QW(this);
1147 float wishspeed0 = wishspeed;
1148 wishspeed = min(wishspeed, maxairspd);
1149 if (IS_DUCKED(this))
1151 float airaccel = PHYS_AIRACCELERATE(this) * min(maxspd_mod, 1);
1153 float accelerating = (this.velocity * wishdir > 0);
1154 float wishspeed2 = wishspeed;
1157 if (PHYS_AIRSTOPACCELERATE(this))
1159 vector curdir = normalize(vec2(this.velocity));
1160 airaccel += (PHYS_AIRSTOPACCELERATE(this)*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1162 // note that for straight forward jumping:
1163 // step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
1164 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1166 // dv/dt = accel * maxspeed (when slow)
1167 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1168 // log dv/dt = logaccel + logmaxspeed (when slow)
1169 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1170 float strafity = IsMoveInDirection(this.movement, -90) + IsMoveInDirection(this.movement, +90); // if one is nonzero, other is always zero
1171 if (PHYS_MAXAIRSTRAFESPEED(this))
1172 wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED(this)*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED(this)*maxspd_mod));
1173 if (PHYS_AIRSTRAFEACCELERATE(this))
1174 airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE(this)*maxspd_mod);
1175 if (PHYS_AIRSTRAFEACCEL_QW(this))
1177 (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(this) : PHYS_AIRACCEL_QW(this)) >= 0) ? +1 : -1)
1179 (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(this)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(this))));
1182 if (PHYS_WARSOWBUNNY_TURNACCEL(this) && accelerating && this.movement.y == 0 && this.movement.x != 0)
1183 PM_AirAccelerate(this, wishdir, wishspeed2);
1185 PM_Accelerate(this, wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(this), PHYS_AIRACCEL_SIDEWAYS_FRICTION(this) / maxairspd, PHYS_AIRSPEEDLIMIT_NONQW(this));
1187 if (PHYS_AIRCONTROL(this))
1188 CPM_PM_Aircontrol(this, wishdir, wishspeed2);
1191 float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH;
1192 if(autocvar_cl_movement != 3)
1193 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1194 this.velocity_z -= g * 0.5;
1196 this.velocity_z -= g;
1198 PM_ClientMovement_Move(this);
1200 if(autocvar_cl_movement != 3)
1201 if (!IS_ONGROUND(this) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1202 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1203 this.velocity_z -= g * 0.5;
1207 // used for calculating airshots
1208 bool IsFlying(entity this)
1210 if(IS_ONGROUND(this))
1212 if(this.waterlevel >= WATERLEVEL_SWIMMING)
1214 traceline(this.origin, this.origin - '0 0 48', MOVE_NORMAL, this);
1215 if(trace_fraction < 1)
1220 void PM_Main(entity this)
1222 int buttons = PHYS_INPUT_BUTTON_MASK(this);
1224 this.items = getstati(STAT_ITEMS, 0, 24);
1226 this.movement = PHYS_INPUT_MOVEVALUES(this);
1228 vector oldv_angle = this.v_angle;
1229 vector oldangles = this.angles; // we need to save these, as they're abused by other code
1230 this.v_angle = PHYS_INPUT_ANGLES(this);
1231 this.angles = PHYS_WORLD_ANGLES(this);
1233 this.team = myteam + 1; // is this correct?
1234 if (!(PHYS_INPUT_BUTTON_JUMP(this))) // !jump
1235 UNSET_JUMP_HELD(this); // canjump = true
1236 PHYS_TELEPORT_TIME(this) -= PHYS_INPUT_TIMELENGTH;
1238 PM_ClientMovement_UpdateStatus(this, true);
1243 WarpZone_PlayerPhysics_FixVAngle();
1245 float maxspeed_mod = 1;
1246 maxspeed_mod *= PHYS_HIGHSPEED;
1249 Physics_UpdateStats(this, maxspeed_mod);
1251 if (this.PlayerPhysplug)
1252 if (this.PlayerPhysplug())
1257 anticheat_physics(this);
1260 if (PM_check_specialcommand(this, buttons))
1265 if (buttons != this.buttons_old || this.movement != this.movement_old || this.v_angle != this.v_angle_old)
1266 this.parm_idlesince = time;
1269 int buttons_prev = this.buttons_old;
1270 this.buttons_old = buttons;
1271 this.movement_old = this.movement;
1272 this.v_angle_old = this.v_angle;
1274 PM_check_nickspam(this);
1276 PM_check_punch(this);
1278 if (IS_BOT_CLIENT(this))
1280 if (playerdemo_read(this))
1282 WITH(entity, self, this, bot_think());
1287 if (IS_PLAYER(this))
1289 const bool allowed_to_move = (time >= game_starttime);
1290 if (!allowed_to_move)
1292 this.velocity = '0 0 0';
1293 this.movetype = MOVETYPE_NONE;
1294 this.disableclientprediction = 2;
1296 else if (this.disableclientprediction == 2)
1298 if (this.movetype == MOVETYPE_NONE)
1299 this.movetype = MOVETYPE_WALK;
1300 this.disableclientprediction = 0;
1306 if (this.movetype == MOVETYPE_NONE)
1309 // when we get here, disableclientprediction cannot be 2
1310 this.disableclientprediction = 0;
1313 viewloc_PlayerPhysics(this);
1315 PM_check_frozen(this);
1317 PM_check_blocked(this);
1322 maxspeed_mod *= this.swamp_slowdown; //cvar("g_balance_swamp_moverate");
1324 // conveyors: first fix velocity
1325 if (this.conveyor.state)
1326 this.velocity -= this.conveyor.movedir;
1328 MUTATOR_CALLHOOK(PlayerPhysics, this);
1331 if (!IS_PLAYER(this))
1333 maxspeed_mod = autocvar_sv_spectator_speed_multiplier;
1334 if (!this.spectatorspeed)
1335 this.spectatorspeed = maxspeed_mod;
1336 if (this.impulse && this.impulse <= 19 || (this.impulse >= 200 && this.impulse <= 209) || (this.impulse >= 220 && this.impulse <= 229))
1338 if (this.lastclassname != "player")
1340 if (this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209))
1341 this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5);
1342 else if (this.impulse == 11)
1343 this.spectatorspeed = maxspeed_mod;
1344 else if (this.impulse == 12 || this.impulse == 16 || this.impulse == 19 || (this.impulse >= 220 && this.impulse <= 229))
1345 this.spectatorspeed = bound(1, this.spectatorspeed - 0.5, 5);
1346 else if (this.impulse >= 1 && this.impulse <= 9)
1347 this.spectatorspeed = 1 + 0.5 * (this.impulse - 1);
1348 } // otherwise just clear
1351 maxspeed_mod = this.spectatorspeed;
1354 float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod;
1355 if(this.speed != spd)
1358 string temps = ftos(spd);
1359 stuffcmd(this, strcat("cl_forwardspeed ", temps, "\n"));
1360 stuffcmd(this, strcat("cl_backspeed ", temps, "\n"));
1361 stuffcmd(this, strcat("cl_sidespeed ", temps, "\n"));
1362 stuffcmd(this, strcat("cl_upspeed ", temps, "\n"));
1365 if(this.stat_jumpspeedcap_min != PHYS_JUMPSPEEDCAP_MIN)
1367 this.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MIN;
1368 stuffcmd(this, strcat("cl_jumpspeedcap_min ", PHYS_JUMPSPEEDCAP_MIN, "\n"));
1370 if(this.stat_jumpspeedcap_max != PHYS_JUMPSPEEDCAP_MAX)
1372 this.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MAX;
1373 stuffcmd(this, strcat("cl_jumpspeedcap_max ", PHYS_JUMPSPEEDCAP_MAX, "\n"));
1379 // handle water here
1380 vector midpoint = ((this.absmin + this.absmax) * 0.5);
1381 if(pointcontents(midpoint) == CONTENT_WATER)
1383 this.velocity = this.velocity * 0.5;
1386 //if(pointcontents(midpoint + '0 0 2') == CONTENT_WATER)
1387 //{ this.velocity_z = 70; }
1394 this.angles = '0 1 0' * this.v_angle.y;
1397 PM_check_hitground(this);
1402 if (IS_PLAYER(this))
1403 CheckPlayerJump(this);
1405 if (this.flags & FL_WATERJUMP)
1407 this.velocity_x = this.movedir.x;
1408 this.velocity_y = this.movedir.y;
1409 if (time > PHYS_TELEPORT_TIME(this) || this.waterlevel == WATERLEVEL_NONE)
1411 this.flags &= ~FL_WATERJUMP;
1412 PHYS_TELEPORT_TIME(this) = 0;
1416 else if (MUTATOR_CALLHOOK(PM_Physics, this, maxspeed_mod))
1420 else if (this.movetype == MOVETYPE_NOCLIP || this.movetype == MOVETYPE_FLY || this.movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this))
1422 else if (this.move_movetype == MOVETYPE_NOCLIP || this.move_movetype == MOVETYPE_FLY || this.move_movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this))
1424 PM_fly(this, maxspeed_mod);
1426 else if (this.waterlevel >= WATERLEVEL_SWIMMING)
1427 PM_swim(this, maxspeed_mod);
1429 else if (time < this.ladder_time)
1430 PM_ladder(this, maxspeed_mod);
1432 else if (ITEMS_STAT(this) & IT_USING_JETPACK)
1433 PM_jetpack(this, maxspeed_mod);
1435 else if (IS_ONGROUND(this))
1436 PM_walk(this, maxspeed_mod);
1439 PM_air(this, buttons_prev, maxspeed_mod);
1442 if (IS_ONGROUND(this))
1443 this.lastground = time;
1445 // conveyors: then break velocity again
1446 if(this.conveyor.state)
1447 this.velocity += this.conveyor.movedir;
1449 this.lastflags = this.flags;
1451 this.lastclassname = this.classname;
1454 this.v_angle = oldv_angle;
1455 this.angles = oldangles;
1460 void SV_PlayerPhysics()
1462 void CSQC_ClientMovement_PlayerMove_Frame(entity this)