2 #include "../triggers/include.qh"
3 #include "../viewloc.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, STAT(PL_CROUCH_MIN, NULL), STAT(PL_CROUCH_MAX, NULL), neworigin, MOVE_NORMAL, this); \
111 if (!trace_startsolid) \
113 setorigin(this, neworigin); \
121 void PM_ClientMovement_UpdateStatus(entity this, bool ground)
126 // make sure player is not stuck
127 if(autocvar_cl_movement == 3)
128 PM_ClientMovement_Unstick(this);
131 bool do_crouch = PHYS_INPUT_BUTTON_CROUCH(this);
132 if(this.hook && !wasfreed(this.hook))
134 if(hud != HUD_NORMAL)
136 if(STAT(FROZEN, this))
138 if((activeweapon == WEP_SHOCKWAVE || activeweapon == WEP_SHOTGUN) && viewmodel.animstate_startframe == viewmodel.anim_fire2_x && time < viewmodel.weapon_nextthink)
143 // wants to crouch, this always works
144 if (!IS_DUCKED(this)) SET_DUCKED(this);
148 // wants to stand, if currently crouching we need to check for a low ceiling first
151 tracebox(this.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), this.origin, MOVE_NORMAL, this);
152 if (!trace_startsolid) UNSET_DUCKED(this);
157 vector origin1 = this.origin + '0 0 1';
158 vector origin2 = this.origin - '0 0 1';
160 if (ground && autocvar_cl_movement == 3)
162 tracebox(origin1, this.mins, this.maxs, origin2, MOVE_NORMAL, this);
163 if (trace_fraction < 1.0 && trace_plane_normal.z > 0.7)
167 // this code actually "predicts" an impact; so let's clip velocity first
168 this.velocity -= this.velocity * trace_plane_normal * trace_plane_normal;
171 UNSET_ONGROUND(this);
174 if(autocvar_cl_movement == 3)
176 // set watertype/waterlevel
177 origin1 = this.origin;
178 origin1.z += this.mins_z + 1;
179 this.waterlevel = WATERLEVEL_NONE;
181 int thepoint = pointcontents(origin1);
183 this.watertype = (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME);
187 this.waterlevel = WATERLEVEL_WETFEET;
188 origin1.z = this.origin.z + (this.mins.z + this.maxs.z) * 0.5;
189 thepoint = pointcontents(origin1);
190 if (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME)
192 this.waterlevel = WATERLEVEL_SWIMMING;
193 origin1.z = this.origin.z + 22;
194 thepoint = pointcontents(origin1);
195 if (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME)
196 this.waterlevel = WATERLEVEL_SUBMERGED;
201 if (IS_ONGROUND(this) || this.velocity.z <= 0 || pmove_waterjumptime <= 0)
202 pmove_waterjumptime = 0;
206 void PM_ClientMovement_Move(entity this)
210 PM_ClientMovement_UpdateStatus(this, false);
211 if(autocvar_cl_movement == 1)
218 vector currentorigin2;
220 vector primalvelocity;
222 vector trace1_endpos = '0 0 0';
223 vector trace2_endpos = '0 0 0';
224 vector trace3_endpos = '0 0 0';
225 float trace1_fraction = 0;
226 float trace2_fraction = 0;
227 float trace3_fraction = 0;
228 vector trace1_plane_normal = '0 0 0';
229 vector trace2_plane_normal = '0 0 0';
230 vector trace3_plane_normal = '0 0 0';
232 primalvelocity = this.velocity;
233 for(bump = 0, t = PHYS_INPUT_TIMELENGTH; bump < 8 && (this.velocity * this.velocity) > 0; bump++)
235 neworigin = this.origin + t * this.velocity;
236 tracebox(this.origin, this.mins, this.maxs, neworigin, MOVE_NORMAL, this);
237 trace1_endpos = trace_endpos;
238 trace1_fraction = trace_fraction;
239 trace1_plane_normal = trace_plane_normal;
240 if(trace1_fraction < 1 && trace1_plane_normal_z == 0)
242 // may be a step or wall, try stepping up
243 // first move forward at a higher level
244 currentorigin2 = this.origin;
245 currentorigin2_z += PHYS_STEPHEIGHT(this);
246 neworigin2 = neworigin;
247 neworigin2_z += PHYS_STEPHEIGHT(this);
248 tracebox(currentorigin2, this.mins, this.maxs, neworigin2, MOVE_NORMAL, this);
249 trace2_endpos = trace_endpos;
250 trace2_fraction = trace_fraction;
251 trace2_plane_normal = trace_plane_normal;
252 if(!trace_startsolid)
254 // then move down from there
255 currentorigin2 = trace2_endpos;
256 neworigin2 = trace2_endpos;
257 neworigin2_z = this.origin_z;
258 tracebox(currentorigin2, this.mins, this.maxs, neworigin2, MOVE_NORMAL, this);
259 trace3_endpos = trace_endpos;
260 trace3_fraction = trace_fraction;
261 trace3_plane_normal = trace_plane_normal;
262 // accept the new trace if it made some progress
263 if(fabs(trace3_endpos_x - trace1_endpos_x) >= 0.03125 || fabs(trace3_endpos_y - trace1_endpos_y) >= 0.03125)
265 trace1_endpos = trace2_endpos;
266 trace1_fraction = trace2_fraction;
267 trace1_plane_normal = trace2_plane_normal;
268 trace1_endpos = trace3_endpos;
273 // check if it moved at all
274 if(trace1_fraction >= 0.001)
275 setorigin(this, trace1_endpos);
277 // check if it moved all the way
278 if(trace1_fraction == 1)
281 // this is only really needed for nogravityonground combined with gravityunaffectedbyticrate
282 // <LordHavoc> I'm pretty sure I commented it out solely because it seemed redundant
283 // this got commented out in a change that supposedly makes the code match QW better
284 // so if this is broken, maybe put it in an if(cls.protocol != PROTOCOL_QUAKEWORLD) block
285 if(trace1_plane_normal_z > 0.7)
288 t -= t * trace1_fraction;
290 f = (this.velocity * trace1_plane_normal);
291 this.velocity = this.velocity + -f * trace1_plane_normal;
293 if(PHYS_TELEPORT_TIME(this) > 0)
294 this.velocity = primalvelocity;
298 void CPM_PM_Aircontrol(entity this, vector wishdir, float wishspeed)
300 float k = 32 * (2 * IsMoveInDirection(this.movement, 0) - 1);
304 k *= bound(0, wishspeed / PHYS_MAXAIRSPEED(this), 1);
306 float zspeed = this.velocity_z;
308 float xyspeed = vlen(this.velocity);
309 this.velocity = normalize(this.velocity);
311 float dot = this.velocity * wishdir;
313 if (dot > 0) // we can't change direction while slowing down
315 k *= pow(dot, PHYS_AIRCONTROL_POWER(this)) * PHYS_INPUT_TIMELENGTH;
316 xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY(this) * sqrt(max(0, 1 - dot*dot)) * k/32);
317 k *= PHYS_AIRCONTROL(this);
318 this.velocity = normalize(this.velocity * xyspeed + wishdir * k);
321 this.velocity = this.velocity * xyspeed;
322 this.velocity_z = zspeed;
325 float AdjustAirAccelQW(float accelqw, float factor)
327 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
330 // example config for alternate speed clamping:
331 // sv_airaccel_qw 0.8
332 // sv_airaccel_sideways_friction 0
333 // prvm_globalset server speedclamp_mode 1
335 void PM_Accelerate(entity this, vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
337 float speedclamp = stretchfactor > 0 ? stretchfactor
338 : accelqw < 0 ? 1 // full clamping, no stretch
341 accelqw = fabs(accelqw);
343 if (GAMEPLAYFIX_Q2AIRACCELERATE)
344 wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
346 float vel_straight = this.velocity * wishdir;
347 float vel_z = this.velocity_z;
348 vector vel_xy = vec2(this.velocity);
349 vector vel_perpend = vel_xy - vel_straight * wishdir;
351 float step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
353 float vel_xy_current = vlen(vel_xy);
355 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
356 float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
357 float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
358 vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
359 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
361 if (sidefric < 0 && (vel_perpend*vel_perpend))
362 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
364 float f = max(0, 1 + PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
365 float themin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
366 // assume: themin > 1
367 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
368 // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
369 // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
370 // obviously, this cannot be
375 themin = sqrt(themin);
376 vel_perpend *= max(themin, f);
380 vel_perpend *= max(0, 1 - PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
382 vel_xy = vel_straight * wishdir + vel_perpend;
386 float vel_xy_preclamp;
387 vel_xy_preclamp = vlen(vel_xy);
388 if (vel_xy_preclamp > 0) // prevent division by zero
390 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
391 if (vel_xy_current < vel_xy_preclamp)
392 vel_xy *= (vel_xy_current / vel_xy_preclamp);
396 this.velocity = vel_xy + vel_z * '0 0 1';
399 void PM_AirAccelerate(entity this, vector wishdir, float wishspeed)
404 vector curvel = this.velocity;
406 float curspeed = vlen(curvel);
408 if (wishspeed > curspeed * 1.01)
409 wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL(this) * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH);
412 float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED(this) - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED(this) - PHYS_MAXSPEED(this)));
413 wishspeed = max(curspeed, PHYS_MAXSPEED(this)) + PHYS_WARSOWBUNNY_ACCEL(this) * f * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH;
415 vector wishvel = wishdir * wishspeed;
416 vector acceldir = wishvel - curvel;
417 float addspeed = vlen(acceldir);
418 acceldir = normalize(acceldir);
420 float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL(this) * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH);
422 if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this) < 1)
424 vector curdir = normalize(curvel);
425 float dot = acceldir * curdir;
427 acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this)) * dot * curdir;
430 this.velocity += accelspeed * acceldir;
438 When you press the jump key
439 returns true if handled
442 bool PlayerJump(entity this)
444 if (PHYS_FROZEN(this))
445 return true; // no jumping in freezetag when frozen
448 if (this.player_blocked)
449 return true; // no jumping while blocked
452 bool doublejump = false;
453 float mjumpheight = PHYS_JUMPVELOCITY(this);
455 if (MUTATOR_CALLHOOK(PlayerJump, this, doublejump, mjumpheight))
458 doublejump = player_multijump;
459 mjumpheight = player_jumpheight;
461 if (this.waterlevel >= WATERLEVEL_SWIMMING)
470 this.velocity_z = PHYS_MAXSPEED(this) * 0.7;
476 if (!IS_ONGROUND(this))
477 return IS_JUMP_HELD(this);
479 bool track_jump = PHYS_CL_TRACK_CANJUMP(this);
480 if(PHYS_TRACK_CANJUMP(this))
484 if (IS_JUMP_HELD(this))
487 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
488 // velocity bounds. Final velocity is bound between (jumpheight *
489 // min + jumpheight) and (jumpheight * max + jumpheight);
491 if(PHYS_JUMPSPEEDCAP_MIN != "")
493 float minjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MIN);
495 if (this.velocity_z < minjumpspeed)
496 mjumpheight += minjumpspeed - this.velocity_z;
499 if(PHYS_JUMPSPEEDCAP_MAX != "")
501 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
502 tracebox(this.origin + '0 0 0.01', this.mins, this.maxs, this.origin - '0 0 0.01', MOVE_NORMAL, this);
504 if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS(this)))
506 float maxjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MAX);
508 if (this.velocity_z > maxjumpspeed)
509 mjumpheight -= this.velocity_z - maxjumpspeed;
513 if (!WAS_ONGROUND(this))
516 if(autocvar_speedmeter)
517 LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n"));
519 if(this.lastground < time - 0.3)
521 float f = (1 - PHYS_FRICTION_ONLAND(this));
522 this.velocity_x *= f;
523 this.velocity_y *= f;
526 if(this.jumppadcount > 1)
527 LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n"));
528 this.jumppadcount = 0;
532 this.velocity_z += mjumpheight;
534 UNSET_ONGROUND(this);
539 this.oldvelocity_z = this.velocity_z;
541 animdecide_setaction(this, ANIMACTION_JUMP, true);
543 if (autocvar_g_jump_grunt)
544 PlayerSound(this, playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
549 void CheckWaterJump(entity this)
551 // check for a jump-out-of-water
552 makevectors(this.v_angle);
553 vector start = this.origin;
556 normalize(v_forward);
557 vector end = start + v_forward*24;
558 traceline (start, end, true, this);
559 if (trace_fraction < 1)
561 start_z = start_z + this.maxs_z - 8;
562 end = start + v_forward*24;
563 this.movedir = trace_plane_normal * -50;
564 traceline(start, end, true, this);
565 if (trace_fraction == 1)
566 { // open at eye level
567 this.velocity_z = 225;
568 this.flags |= FL_WATERJUMP;
571 PHYS_TELEPORT_TIME(this) = time + 2; // safety net
573 pmove_waterjumptime = 2;
581 #define JETPACK_JUMP(s) s.cvar_cl_jetpack_jump
583 float autocvar_cl_jetpack_jump;
584 #define JETPACK_JUMP(s) autocvar_cl_jetpack_jump
586 .float jetpack_stopped;
587 void CheckPlayerJump(entity this)
590 float was_flying = ITEMS_STAT(this) & IT_USING_JETPACK;
592 if (JETPACK_JUMP(this) < 2)
593 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
595 if(PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this))
597 float air_jump = !PlayerJump(this) || player_multijump; // PlayerJump() has important side effects
598 float activate = JETPACK_JUMP(this) && air_jump && PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this);
599 float has_fuel = !PHYS_JETPACK_FUEL(this) || PHYS_AMMO_FUEL(this) || ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO;
601 if (!(ITEMS_STAT(this) & ITEM_Jetpack.m_itemid)) { }
602 else if (this.jetpack_stopped) { }
606 if (was_flying) // TODO: ran out of fuel message
607 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
609 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
611 this.jetpack_stopped = true;
612 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
614 else if (activate && !PHYS_FROZEN(this))
615 ITEMS_STAT(this) |= IT_USING_JETPACK;
619 this.jetpack_stopped = false;
620 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
622 if (!PHYS_INPUT_BUTTON_JUMP(this))
623 UNSET_JUMP_HELD(this);
625 if (this.waterlevel == WATERLEVEL_SWIMMING)
626 CheckWaterJump(this);
629 float racecar_angle(float forward, float down)
637 float ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
639 float angle_mult = forward / (800 + forward);
642 return ret * angle_mult + 360 * (1 - angle_mult);
644 return ret * angle_mult;
647 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
648 .float specialcommand_pos;
649 void SpecialCommand()
652 if (!CheatImpulse(CHIMPULSE_GIVE_ALL.impulse))
653 LOG_INFO("A hollow voice says \"Plugh\".\n");
657 float PM_check_specialcommand(entity this, float buttons)
663 else if (buttons == 1)
665 else if (buttons == 2)
667 else if (buttons == 128)
669 else if (buttons == 256)
671 else if (buttons == 512)
673 else if (buttons == 1024)
678 if (c == substring(specialcommand, this.specialcommand_pos, 1))
680 this.specialcommand_pos += 1;
681 if (this.specialcommand_pos >= strlen(specialcommand))
683 this.specialcommand_pos = 0;
688 else if (this.specialcommand_pos && (c != substring(specialcommand, this.specialcommand_pos - 1, 1)))
689 this.specialcommand_pos = 0;
694 void PM_check_nickspam(entity this)
697 if (time >= this.nickspamtime)
699 if (this.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
701 // slight annoyance for nick change scripts
702 this.movement = -1 * this.movement;
703 PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_JUMP(this) = PHYS_INPUT_BUTTON_ATCK2(this) = PHYS_INPUT_BUTTON_ZOOM(this) = PHYS_INPUT_BUTTON_CROUCH(this) = PHYS_INPUT_BUTTON_HOOK(this) = PHYS_INPUT_BUTTON_USE(this) = false;
705 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!
707 this.v_angle_x = random() * 360;
708 this.v_angle_y = random() * 360;
709 // at least I'm not forcing retardedview by also assigning to angles_z
710 this.fixangle = true;
716 void PM_check_punch(entity this)
719 if (this.punchangle != '0 0 0')
721 float f = vlen(this.punchangle) - 10 * PHYS_INPUT_TIMELENGTH;
723 this.punchangle = normalize(this.punchangle) * f;
725 this.punchangle = '0 0 0';
728 if (this.punchvector != '0 0 0')
730 float f = vlen(this.punchvector) - 30 * PHYS_INPUT_TIMELENGTH;
732 this.punchvector = normalize(this.punchvector) * f;
734 this.punchvector = '0 0 0';
739 // predict frozen movement, as frozen players CAN move in some cases
740 void PM_check_frozen(entity this)
742 if (!PHYS_FROZEN(this))
744 if (PHYS_DODGING_FROZEN(this)
746 && IS_REAL_CLIENT(this)
750 this.movement_x = bound(-5, this.movement.x, 5);
751 this.movement_y = bound(-5, this.movement.y, 5);
752 this.movement_z = bound(-5, this.movement.z, 5);
755 this.movement = '0 0 0';
757 vector midpoint = ((this.absmin + this.absmax) * 0.5);
758 if (pointcontents(midpoint) == CONTENT_WATER)
760 this.velocity = this.velocity * 0.5;
762 if (pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
763 this.velocity_z = 200;
767 void PM_check_hitground(entity this)
770 if (!this.wasFlying) return;
771 this.wasFlying = false;
772 if (this.waterlevel >= WATERLEVEL_SWIMMING) return;
773 if (time < this.ladder_time) return;
774 if (this.hook) return;
775 this.nextstep = time + 0.3 + random() * 0.1;
776 trace_dphitq3surfaceflags = 0;
777 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
778 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return;
779 entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
782 GlobalSound(this, gs, CH_PLAYER, VOICETYPE_PLAYERSOUND);
786 void PM_Footsteps(entity this)
789 if (!g_footsteps) return;
790 if (IS_DUCKED(this)) return;
791 if (time >= this.lastground + 0.2) return;
792 if (vdist(this.velocity, <=, autocvar_sv_maxspeed * 0.6)) return;
793 if ((time > this.nextstep) || (time < (this.nextstep - 10.0)))
795 this.nextstep = time + 0.3 + random() * 0.1;
796 trace_dphitq3surfaceflags = 0;
797 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
798 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return;
799 entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
802 GlobalSound(this, gs, CH_PLAYER, VOICETYPE_PLAYERSOUND);
807 void PM_check_blocked(entity this)
810 if (!this.player_blocked)
812 this.movement = '0 0 0';
813 this.disableclientprediction = 1;
817 void PM_fly(entity this, float maxspd_mod)
819 // noclipping or flying
820 UNSET_ONGROUND(this);
822 this.velocity = this.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this));
823 makevectors(this.v_angle);
824 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
825 vector wishvel = v_forward * this.movement.x
826 + v_right * this.movement.y
827 + '0 0 1' * this.movement.z;
829 vector wishdir = normalize(wishvel);
830 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod);
832 if(time >= PHYS_TELEPORT_TIME(this))
834 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this) * maxspd_mod, 1, 0, 0, 0);
835 PM_ClientMovement_Move(this);
838 void PM_swim(entity this, float maxspd_mod)
841 UNSET_ONGROUND(this);
843 float jump = PHYS_INPUT_BUTTON_JUMP(this);
844 // water jump only in certain situations
845 // this mimics quakeworld code
846 if (jump && this.waterlevel == WATERLEVEL_SWIMMING && this.velocity_z >= -180 && !this.viewloc)
848 vector yawangles = '0 1 0' * this.v_angle.y;
849 makevectors(yawangles);
850 vector forward = v_forward;
851 vector spot = this.origin + 24 * forward;
853 traceline(spot, spot, MOVE_NOMONSTERS, this);
854 if (trace_startsolid)
857 traceline(spot, spot, MOVE_NOMONSTERS, this);
858 if (!trace_startsolid)
860 this.velocity = forward * 50;
861 this.velocity_z = 310;
863 pmove_waterjumptime = 2;
865 UNSET_ONGROUND(this);
870 makevectors(this.v_angle);
871 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
872 vector wishvel = v_forward * this.movement.x
873 + v_right * this.movement.y
874 + '0 0 1' * this.movement.z;
876 wishvel.z = -160; // drift anyway
877 else if (wishvel == '0 0 0')
878 wishvel = '0 0 -60'; // drift towards bottom
881 vector wishdir = normalize(wishvel);
882 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod) * 0.7;
887 // if (pmove_waterjumptime <= 0) // TODO: use
890 float f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this);
891 f = min(max(0, f), 1);
894 f = wishspeed - this.velocity * wishdir;
897 float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, f);
898 this.velocity += accelspeed * wishdir;
901 // holding jump button swims upward slowly
902 if (jump && !this.viewloc)
905 if (this.watertype & CONTENT_LAVA)
906 this.velocity_z = 50;
907 else if (this.watertype & CONTENT_SLIME)
908 this.velocity_z = 80;
911 if (IS_NEXUIZ_DERIVED(gamemode))
913 this.velocity_z = 200;
916 this.velocity_z = 100;
923 const float addspeed = wishspeed - this.velocity * wishdir;
926 const float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
927 this.velocity += accelspeed * wishdir;
932 // water acceleration
933 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this) * maxspd_mod, 1, 0, 0, 0);
934 PM_ClientMovement_Move(this);
939 void PM_ladder(entity this, float maxspd_mod)
941 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
942 UNSET_ONGROUND(this);
945 g = PHYS_GRAVITY(this) * PHYS_INPUT_TIMELENGTH;
946 if (PHYS_ENTGRAVITY(this))
947 g *= PHYS_ENTGRAVITY(this);
948 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
951 this.velocity_z += g;
954 this.velocity = this.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this));
955 makevectors(this.v_angle);
956 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
957 vector wishvel = v_forward * this.movement_x
958 + v_right * this.movement_y
959 + '0 0 1' * this.movement_z;
961 wishvel.z = this.oldmovement.x;
962 this.velocity_z += g;
963 if (this.ladder_entity.classname == "func_water")
965 float f = vlen(wishvel);
966 if (f > this.ladder_entity.speed)
967 wishvel *= (this.ladder_entity.speed / f);
969 this.watertype = this.ladder_entity.skin;
970 f = this.ladder_entity.origin_z + this.ladder_entity.maxs_z;
971 if ((this.origin_z + this.view_ofs_z) < f)
972 this.waterlevel = WATERLEVEL_SUBMERGED;
973 else if ((this.origin_z + (this.mins_z + this.maxs_z) * 0.5) < f)
974 this.waterlevel = WATERLEVEL_SWIMMING;
975 else if ((this.origin_z + this.mins_z + 1) < f)
976 this.waterlevel = WATERLEVEL_WETFEET;
979 this.waterlevel = WATERLEVEL_NONE;
980 this.watertype = CONTENT_EMPTY;
984 vector wishdir = normalize(wishvel);
985 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod);
986 if(time >= PHYS_TELEPORT_TIME(this))
987 // water acceleration
988 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this)*maxspd_mod, 1, 0, 0, 0);
989 PM_ClientMovement_Move(this);
992 void PM_jetpack(entity this, float maxspd_mod)
994 //makevectors(this.v_angle.y * '0 1 0');
995 makevectors(this.v_angle);
996 vector wishvel = v_forward * this.movement_x
997 + v_right * this.movement_y;
998 // add remaining speed as Z component
999 float maxairspd = PHYS_MAXAIRSPEED(this) * max(1, maxspd_mod);
1000 // fix speedhacks :P
1001 wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
1002 // add the unused velocity as up component
1005 // if (PHYS_INPUT_BUTTON_JUMP(this))
1006 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1008 // it is now normalized, so...
1009 float a_side = PHYS_JETPACK_ACCEL_SIDE(this);
1010 float a_up = PHYS_JETPACK_ACCEL_UP(this);
1011 float a_add = PHYS_JETPACK_ANTIGRAVITY(this) * PHYS_GRAVITY(this);
1013 wishvel_x *= a_side;
1014 wishvel_y *= a_side;
1019 //////////////////////////////////////////////////////////////////////////////////////
1020 // finding the maximum over all vectors of above form
1021 // with wishvel having an absolute value of 1
1022 //////////////////////////////////////////////////////////////////////////////////////
1023 // we're finding the maximum over
1024 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1025 // for z in the range from -1 to 1
1026 //////////////////////////////////////////////////////////////////////////////////////
1027 // maximum is EITHER attained at the single extreme point:
1028 float a_diff = a_side * a_side - a_up * a_up;
1032 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1033 if (f > -1 && f < 1) // can it be attained?
1035 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1036 //print("middle\n");
1039 // OR attained at z = 1:
1040 f = (a_up + a_add) * (a_up + a_add);
1046 // OR attained at z = -1:
1047 f = (a_up - a_add) * (a_up - a_add);
1051 //print("bottom\n");
1054 //////////////////////////////////////////////////////////////////////////////////////
1056 //print("best possible acceleration: ", ftos(best), "\n");
1059 fxy = bound(0, 1 - (this.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE(this), 1);
1060 if (wishvel_z - PHYS_GRAVITY(this) > 0)
1061 fz = bound(0, 1 - this.velocity_z / PHYS_JETPACK_MAXSPEED_UP(this), 1);
1063 fz = bound(0, 1 + this.velocity_z / PHYS_JETPACK_MAXSPEED_UP(this), 1);
1066 fvel = vlen(wishvel);
1069 wishvel_z = (wishvel_z - PHYS_GRAVITY(this)) * fz + PHYS_GRAVITY(this);
1071 fvel = min(1, vlen(wishvel) / best);
1072 if (PHYS_JETPACK_FUEL(this) && !(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO))
1073 f = min(1, PHYS_AMMO_FUEL(this) / (PHYS_JETPACK_FUEL(this) * PHYS_INPUT_TIMELENGTH * fvel));
1077 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1079 if (f > 0 && wishvel != '0 0 0')
1081 this.velocity = this.velocity + wishvel * f * PHYS_INPUT_TIMELENGTH;
1082 UNSET_ONGROUND(this);
1085 if (!(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO))
1086 this.ammo_fuel -= PHYS_JETPACK_FUEL(this) * PHYS_INPUT_TIMELENGTH * fvel * f;
1088 ITEMS_STAT(this) |= IT_USING_JETPACK;
1090 // jetpack also inhibits health regeneration, but only for 1 second
1091 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1096 float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH;
1097 if(autocvar_cl_movement == 3)
1099 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1100 this.velocity_z -= g * 0.5;
1102 this.velocity_z -= g;
1104 PM_ClientMovement_Move(this);
1105 if(autocvar_cl_movement == 3)
1107 if (!IS_ONGROUND(this) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1108 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1109 this.velocity_z -= g * 0.5;
1114 void PM_walk(entity this, float maxspd_mod)
1116 if (!WAS_ONGROUND(this))
1119 if (autocvar_speedmeter)
1120 LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n"));
1122 if (this.lastground < time - 0.3)
1123 this.velocity *= (1 - PHYS_FRICTION_ONLAND(this));
1125 if (this.jumppadcount > 1)
1126 LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n"));
1127 this.jumppadcount = 0;
1132 makevectors(this.v_angle.y * '0 1 0');
1133 const vector wishvel = v_forward * this.movement.x
1134 + v_right * this.movement.y;
1136 const vector wishdir = normalize(wishvel);
1137 float wishspeed = vlen(wishvel);
1138 wishspeed = min(wishspeed, PHYS_MAXSPEED(this) * maxspd_mod);
1139 if (IS_DUCKED(this)) wishspeed *= 0.5;
1141 // apply edge friction
1142 const float f2 = vlen2(vec2(this.velocity));
1145 trace_dphitq3surfaceflags = 0;
1146 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
1147 // TODO: apply edge friction
1148 // apply ground friction
1149 const int realfriction = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK)
1150 ? PHYS_FRICTION_SLICK(this)
1151 : PHYS_FRICTION(this);
1154 f = 1 - PHYS_INPUT_TIMELENGTH * realfriction * ((f < PHYS_STOPSPEED(this)) ? (PHYS_STOPSPEED(this) / f) : 1);
1158 Mathematical analysis time!
1160 Our goal is to invert this mess.
1162 For the two cases we get:
1163 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * (PHYS_STOPSPEED(this) / v0) * PHYS_FRICTION(this))
1164 = v0 - PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this)
1165 v0 = v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this)
1167 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1168 v0 = v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1170 These cases would be chosen ONLY if:
1171 v0 < PHYS_STOPSPEED(this)
1172 v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this) < PHYS_STOPSPEED(this)
1173 v < PHYS_STOPSPEED(this) * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1175 v0 >= PHYS_STOPSPEED(this)
1176 v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this)) >= PHYS_STOPSPEED(this)
1177 v >= PHYS_STOPSPEED(this) * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1180 const float addspeed = wishspeed - this.velocity * wishdir;
1183 const float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
1184 this.velocity += accelspeed * wishdir;
1187 float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH;
1188 if(autocvar_cl_movement == 3)
1190 if (!(GAMEPLAYFIX_NOGRAVITYONGROUND))
1191 this.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1);
1193 if (vdist(this.velocity, >, 0))
1194 PM_ClientMovement_Move(this);
1195 if(autocvar_cl_movement == 3)
1197 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1198 if (!IS_ONGROUND(this) || !GAMEPLAYFIX_NOGRAVITYONGROUND)
1199 this.velocity_z -= g * 0.5;
1204 void PM_air(entity this, float buttons_prev, float maxspd_mod)
1206 makevectors(this.v_angle.y * '0 1 0');
1207 vector wishvel = v_forward * this.movement.x
1208 + v_right * this.movement.y;
1210 vector wishdir = normalize(wishvel);
1211 float wishspeed = vlen(wishvel);
1214 if(time >= PHYS_TELEPORT_TIME(this))
1216 if(pmove_waterjumptime <= 0)
1219 float maxairspd = PHYS_MAXAIRSPEED(this) * min(maxspd_mod, 1);
1221 // apply air speed limit
1222 float airaccelqw = PHYS_AIRACCEL_QW(this);
1223 float wishspeed0 = wishspeed;
1224 wishspeed = min(wishspeed, maxairspd);
1225 if (IS_DUCKED(this))
1227 float airaccel = PHYS_AIRACCELERATE(this) * min(maxspd_mod, 1);
1229 float accelerating = (this.velocity * wishdir > 0);
1230 float wishspeed2 = wishspeed;
1233 if (PHYS_AIRSTOPACCELERATE(this))
1235 vector curdir = normalize(vec2(this.velocity));
1236 airaccel += (PHYS_AIRSTOPACCELERATE(this)*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1238 // note that for straight forward jumping:
1239 // step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
1240 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1242 // dv/dt = accel * maxspeed (when slow)
1243 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1244 // log dv/dt = logaccel + logmaxspeed (when slow)
1245 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1246 float strafity = IsMoveInDirection(this.movement, -90) + IsMoveInDirection(this.movement, +90); // if one is nonzero, other is always zero
1247 if (PHYS_MAXAIRSTRAFESPEED(this))
1248 wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED(this)*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED(this)*maxspd_mod));
1249 if (PHYS_AIRSTRAFEACCELERATE(this))
1250 airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE(this)*maxspd_mod);
1251 if (PHYS_AIRSTRAFEACCEL_QW(this))
1253 (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(this) : PHYS_AIRACCEL_QW(this)) >= 0) ? +1 : -1)
1255 (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(this)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(this))));
1258 if (PHYS_WARSOWBUNNY_TURNACCEL(this) && accelerating && this.movement.y == 0 && this.movement.x != 0)
1259 PM_AirAccelerate(this, wishdir, wishspeed2);
1261 float sidefric = maxairspd ? (PHYS_AIRACCEL_SIDEWAYS_FRICTION(this) / maxairspd) : 0;
1262 PM_Accelerate(this, wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(this), sidefric, PHYS_AIRSPEEDLIMIT_NONQW(this));
1265 if (PHYS_AIRCONTROL(this))
1266 CPM_PM_Aircontrol(this, wishdir, wishspeed2);
1269 float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH;
1270 if(autocvar_cl_movement == 3)
1271 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1272 this.velocity_z -= g * 0.5;
1274 this.velocity_z -= g;
1276 PM_ClientMovement_Move(this);
1278 if(autocvar_cl_movement == 3)
1279 if (!IS_ONGROUND(this) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1280 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1281 this.velocity_z -= g * 0.5;
1285 // used for calculating airshots
1286 bool IsFlying(entity this)
1288 if(IS_ONGROUND(this))
1290 if(this.waterlevel >= WATERLEVEL_SWIMMING)
1292 traceline(this.origin, this.origin - '0 0 48', MOVE_NORMAL, this);
1293 if(trace_fraction < 1)
1299 float autocvar_slowmo;
1302 void PM_Main(entity this)
1304 int buttons = PHYS_INPUT_BUTTON_MASK(this);
1306 this.items = STAT(ITEMS);
1308 this.movement = PHYS_INPUT_MOVEVALUES(this);
1310 this.spectatorspeed = STAT(SPECTATORSPEED);
1312 vector oldv_angle = this.v_angle;
1313 vector oldangles = this.angles; // we need to save these, as they're abused by other code
1314 this.v_angle = PHYS_INPUT_ANGLES(this);
1315 this.angles = PHYS_WORLD_ANGLES(this);
1317 this.team = myteam + 1; // is this correct?
1318 if (!(PHYS_INPUT_BUTTON_JUMP(this))) // !jump
1319 UNSET_JUMP_HELD(this); // canjump = true
1320 pmove_waterjumptime -= PHYS_INPUT_TIMELENGTH;
1322 PM_ClientMovement_UpdateStatus(this, true);
1325 this.oldmovement = this.movement;
1329 WarpZone_PlayerPhysics_FixVAngle(this);
1331 float maxspeed_mod = 1;
1332 maxspeed_mod *= PHYS_HIGHSPEED(this);
1335 Physics_UpdateStats(this, maxspeed_mod);
1337 if (this.PlayerPhysplug)
1338 if (this.PlayerPhysplug(this))
1341 if(autocvar_slowmo != STAT(MOVEVARS_TIMESCALE))
1342 cvar_set("slowmo", ftos(STAT(MOVEVARS_TIMESCALE)));
1346 anticheat_physics(this);
1349 if (PM_check_specialcommand(this, buttons))
1354 if (buttons != this.buttons_old || this.movement != this.movement_old || this.v_angle != this.v_angle_old)
1355 this.parm_idlesince = time;
1358 int buttons_prev = this.buttons_old;
1359 this.buttons_old = buttons;
1360 this.movement_old = this.movement;
1361 this.v_angle_old = this.v_angle;
1363 PM_check_nickspam(this);
1365 PM_check_punch(this);
1367 if (IS_BOT_CLIENT(this))
1369 if (playerdemo_read(this))
1376 if (IS_PLAYER(this))
1378 const bool allowed_to_move = (time >= game_starttime);
1379 if (!allowed_to_move)
1381 this.velocity = '0 0 0';
1382 this.movetype = MOVETYPE_NONE;
1383 this.disableclientprediction = 2;
1385 else if (this.disableclientprediction == 2)
1387 if (this.movetype == MOVETYPE_NONE)
1388 this.movetype = MOVETYPE_WALK;
1389 this.disableclientprediction = 0;
1395 if (this.movetype == MOVETYPE_NONE)
1398 // when we get here, disableclientprediction cannot be 2
1399 this.disableclientprediction = 0;
1402 viewloc_PlayerPhysics(this);
1404 PM_check_frozen(this);
1406 PM_check_blocked(this);
1411 maxspeed_mod *= this.swamp_slowdown; //cvar("g_balance_swamp_moverate");
1413 // conveyors: first fix velocity
1414 if (this.conveyor.state)
1415 this.velocity -= this.conveyor.movedir;
1417 MUTATOR_CALLHOOK(PlayerPhysics, this);
1419 if (!IS_PLAYER(this))
1422 maxspeed_mod = autocvar_sv_spectator_speed_multiplier;
1423 if (!this.spectatorspeed)
1424 this.spectatorspeed = maxspeed_mod;
1425 if (this.impulse && this.impulse <= 19 || (this.impulse >= 200 && this.impulse <= 209) || (this.impulse >= 220 && this.impulse <= 229))
1427 if (this.lastclassname != STR_PLAYER)
1429 if (this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209))
1430 this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5);
1431 else if (this.impulse == 11)
1432 this.spectatorspeed = maxspeed_mod;
1433 else if (this.impulse == 12 || this.impulse == 16 || this.impulse == 19 || (this.impulse >= 220 && this.impulse <= 229))
1434 this.spectatorspeed = bound(1, this.spectatorspeed - 0.5, 5);
1435 else if (this.impulse >= 1 && this.impulse <= 9)
1436 this.spectatorspeed = 1 + 0.5 * (this.impulse - 1);
1437 } // otherwise just clear
1441 maxspeed_mod = this.spectatorspeed;
1445 float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod;
1446 if(this.speed != spd)
1449 string temps = ftos(spd);
1450 stuffcmd(this, strcat("cl_forwardspeed ", temps, "\n"));
1451 stuffcmd(this, strcat("cl_backspeed ", temps, "\n"));
1452 stuffcmd(this, strcat("cl_sidespeed ", temps, "\n"));
1453 stuffcmd(this, strcat("cl_upspeed ", temps, "\n"));
1456 if(this.jumpspeedcap_min != autocvar_sv_jumpspeedcap_min)
1458 this.jumpspeedcap_min = autocvar_sv_jumpspeedcap_min;
1459 stuffcmd(this, sprintf("\ncl_jumpspeedcap_min \"%s\"\n", autocvar_sv_jumpspeedcap_min));
1461 if(this.jumpspeedcap_max != autocvar_sv_jumpspeedcap_max)
1463 this.jumpspeedcap_max = autocvar_sv_jumpspeedcap_max;
1464 stuffcmd(this, sprintf("\ncl_jumpspeedcap_max \"%s\"\n", autocvar_sv_jumpspeedcap_max));
1470 // handle water here
1471 vector midpoint = ((this.absmin + this.absmax) * 0.5);
1472 if(pointcontents(midpoint) == CONTENT_WATER)
1474 this.velocity = this.velocity * 0.5;
1477 //if(pointcontents(midpoint + '0 0 2') == CONTENT_WATER)
1478 //{ this.velocity_z = 70; }
1485 this.angles = '0 1 0' * this.v_angle.y;
1488 if (IS_PLAYER(this) && IS_ONGROUND(this))
1490 PM_check_hitground(this);
1499 if (IS_PLAYER(this))
1500 CheckPlayerJump(this);
1502 if (this.flags & FL_WATERJUMP)
1504 this.velocity_x = this.movedir.x;
1505 this.velocity_y = this.movedir.y;
1506 if (time > PHYS_TELEPORT_TIME(this) || this.waterlevel == WATERLEVEL_NONE
1508 || pmove_waterjumptime <= 0
1512 this.flags &= ~FL_WATERJUMP;
1513 PHYS_TELEPORT_TIME(this) = 0;
1515 pmove_waterjumptime = 0;
1520 else if (MUTATOR_CALLHOOK(PM_Physics, this, maxspeed_mod))
1524 else if (this.movetype == MOVETYPE_NOCLIP || this.movetype == MOVETYPE_FLY || this.movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this))
1526 else if (this.move_movetype == MOVETYPE_NOCLIP || this.move_movetype == MOVETYPE_FLY || this.move_movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this))
1528 PM_fly(this, maxspeed_mod);
1530 else if (this.waterlevel >= WATERLEVEL_SWIMMING)
1531 PM_swim(this, maxspeed_mod);
1533 else if (time < this.ladder_time)
1534 PM_ladder(this, maxspeed_mod);
1536 else if (ITEMS_STAT(this) & IT_USING_JETPACK)
1537 PM_jetpack(this, maxspeed_mod);
1539 else if (IS_ONGROUND(this))
1540 PM_walk(this, maxspeed_mod);
1543 PM_air(this, buttons_prev, maxspeed_mod);
1546 if (IS_ONGROUND(this))
1547 this.lastground = time;
1549 // conveyors: then break velocity again
1550 if(this.conveyor.state)
1551 this.velocity += this.conveyor.movedir;
1553 this.lastflags = this.flags;
1555 this.lastclassname = this.classname;
1558 this.v_angle = oldv_angle;
1559 this.angles = oldangles;
1564 void SV_PlayerPhysics()
1566 void CSQC_ClientMovement_PlayerMove_Frame(entity this)