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)
126 // make sure player is not stuck
127 if(autocvar_cl_movement != 3)
128 PM_ClientMovement_Unstick(this);
131 if (PHYS_INPUT_BUTTON_CROUCH(this))
133 // wants to crouch, this always works
134 if (!IS_DUCKED(this)) SET_DUCKED(this);
138 // wants to stand, if currently crouching we need to check for a low ceiling first
141 tracebox(this.origin, PL_MIN, PL_MAX, this.origin, MOVE_NORMAL, this);
142 if (!trace_startsolid) UNSET_DUCKED(this);
147 vector origin1 = this.origin + '0 0 1';
148 vector origin2 = this.origin - '0 0 1';
150 if (ground && autocvar_cl_movement != 3)
152 tracebox(origin1, this.mins, this.maxs, origin2, MOVE_NORMAL, this);
153 if (trace_fraction < 1.0 && trace_plane_normal.z > 0.7)
157 // this code actually "predicts" an impact; so let's clip velocity first
158 this.velocity -= this.velocity * trace_plane_normal * trace_plane_normal;
161 UNSET_ONGROUND(this);
164 if(autocvar_cl_movement != 3)
166 // set watertype/waterlevel
167 origin1 = this.origin;
168 origin1.z += this.mins_z + 1;
169 this.waterlevel = WATERLEVEL_NONE;
171 int thepoint = pointcontents(origin1);
173 this.watertype = (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME);
177 this.waterlevel = WATERLEVEL_WETFEET;
178 origin1.z = this.origin.z + (this.mins.z + this.maxs.z) * 0.5;
179 thepoint = pointcontents(origin1);
180 if (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME)
182 this.waterlevel = WATERLEVEL_SWIMMING;
183 origin1.z = this.origin.z + 22;
184 thepoint = pointcontents(origin1);
185 if (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME)
186 this.waterlevel = WATERLEVEL_SUBMERGED;
191 if (IS_ONGROUND(this) || this.velocity.z <= 0 || pmove_waterjumptime <= 0)
192 pmove_waterjumptime = 0;
196 void PM_ClientMovement_Move(entity this)
200 PM_ClientMovement_UpdateStatus(this, false);
201 if(autocvar_cl_movement == 3)
208 vector currentorigin2;
210 vector primalvelocity;
212 vector trace1_endpos = '0 0 0';
213 vector trace2_endpos = '0 0 0';
214 vector trace3_endpos = '0 0 0';
215 float trace1_fraction = 0;
216 float trace2_fraction = 0;
217 float trace3_fraction = 0;
218 vector trace1_plane_normal = '0 0 0';
219 vector trace2_plane_normal = '0 0 0';
220 vector trace3_plane_normal = '0 0 0';
222 primalvelocity = this.velocity;
223 for(bump = 0, t = PHYS_INPUT_TIMELENGTH; bump < 8 && (this.velocity * this.velocity) > 0; bump++)
225 neworigin = this.origin + t * this.velocity;
226 tracebox(this.origin, this.mins, this.maxs, neworigin, MOVE_NORMAL, this);
227 trace1_endpos = trace_endpos;
228 trace1_fraction = trace_fraction;
229 trace1_plane_normal = trace_plane_normal;
230 if(trace1_fraction < 1 && trace1_plane_normal_z == 0)
232 // may be a step or wall, try stepping up
233 // first move forward at a higher level
234 currentorigin2 = this.origin;
235 currentorigin2_z += PHYS_STEPHEIGHT;
236 neworigin2 = neworigin;
237 neworigin2_z += PHYS_STEPHEIGHT;
238 tracebox(currentorigin2, this.mins, this.maxs, neworigin2, MOVE_NORMAL, this);
239 trace2_endpos = trace_endpos;
240 trace2_fraction = trace_fraction;
241 trace2_plane_normal = trace_plane_normal;
242 if(!trace_startsolid)
244 // then move down from there
245 currentorigin2 = trace2_endpos;
246 neworigin2 = trace2_endpos;
247 neworigin2_z = this.origin_z;
248 tracebox(currentorigin2, this.mins, this.maxs, neworigin2, MOVE_NORMAL, this);
249 trace3_endpos = trace_endpos;
250 trace3_fraction = trace_fraction;
251 trace3_plane_normal = trace_plane_normal;
252 // accept the new trace if it made some progress
253 if(fabs(trace3_endpos_x - trace1_endpos_x) >= 0.03125 || fabs(trace3_endpos_y - trace1_endpos_y) >= 0.03125)
255 trace1_endpos = trace2_endpos;
256 trace1_fraction = trace2_fraction;
257 trace1_plane_normal = trace2_plane_normal;
258 trace1_endpos = trace3_endpos;
263 // check if it moved at all
264 if(trace1_fraction >= 0.001)
265 setorigin(this, trace1_endpos);
267 // check if it moved all the way
268 if(trace1_fraction == 1)
271 // this is only really needed for nogravityonground combined with gravityunaffectedbyticrate
272 // <LordHavoc> I'm pretty sure I commented it out solely because it seemed redundant
273 // this got commented out in a change that supposedly makes the code match QW better
274 // so if this is broken, maybe put it in an if(cls.protocol != PROTOCOL_QUAKEWORLD) block
275 if(trace1_plane_normal_z > 0.7)
278 t -= t * trace1_fraction;
280 f = (this.velocity * trace1_plane_normal);
281 this.velocity = this.velocity + -f * trace1_plane_normal;
283 if(PHYS_TELEPORT_TIME(this) > 0)
284 this.velocity = primalvelocity;
288 void CPM_PM_Aircontrol(entity this, vector wishdir, float wishspeed)
290 float k = 32 * (2 * IsMoveInDirection(this.movement, 0) - 1);
294 k *= bound(0, wishspeed / PHYS_MAXAIRSPEED(this), 1);
296 float zspeed = this.velocity_z;
298 float xyspeed = vlen(this.velocity);
299 this.velocity = normalize(this.velocity);
301 float dot = this.velocity * wishdir;
303 if (dot > 0) // we can't change direction while slowing down
305 k *= pow(dot, PHYS_AIRCONTROL_POWER(this)) * PHYS_INPUT_TIMELENGTH;
306 xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY(this) * sqrt(max(0, 1 - dot*dot)) * k/32);
307 k *= PHYS_AIRCONTROL(this);
308 this.velocity = normalize(this.velocity * xyspeed + wishdir * k);
311 this.velocity = this.velocity * xyspeed;
312 this.velocity_z = zspeed;
315 float AdjustAirAccelQW(float accelqw, float factor)
317 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
320 // example config for alternate speed clamping:
321 // sv_airaccel_qw 0.8
322 // sv_airaccel_sideways_friction 0
323 // prvm_globalset server speedclamp_mode 1
325 void PM_Accelerate(entity this, vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
327 float speedclamp = stretchfactor > 0 ? stretchfactor
328 : accelqw < 0 ? 1 // full clamping, no stretch
331 accelqw = fabs(accelqw);
333 if (GAMEPLAYFIX_Q2AIRACCELERATE)
334 wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
336 float vel_straight = this.velocity * wishdir;
337 float vel_z = this.velocity_z;
338 vector vel_xy = vec2(this.velocity);
339 vector vel_perpend = vel_xy - vel_straight * wishdir;
341 float step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
343 float vel_xy_current = vlen(vel_xy);
345 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
346 float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
347 float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
348 vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
349 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
351 if (sidefric < 0 && (vel_perpend*vel_perpend))
352 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
354 float f = max(0, 1 + PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
355 float themin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
356 // assume: themin > 1
357 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
358 // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
359 // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
360 // obviously, this cannot be
365 themin = sqrt(themin);
366 vel_perpend *= max(themin, f);
370 vel_perpend *= max(0, 1 - PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
372 vel_xy = vel_straight * wishdir + vel_perpend;
376 float vel_xy_preclamp;
377 vel_xy_preclamp = vlen(vel_xy);
378 if (vel_xy_preclamp > 0) // prevent division by zero
380 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
381 if (vel_xy_current < vel_xy_preclamp)
382 vel_xy *= (vel_xy_current / vel_xy_preclamp);
386 this.velocity = vel_xy + vel_z * '0 0 1';
389 void PM_AirAccelerate(entity this, vector wishdir, float wishspeed)
394 vector curvel = this.velocity;
396 float curspeed = vlen(curvel);
398 if (wishspeed > curspeed * 1.01)
399 wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL(this) * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH);
402 float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED(this) - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED(this) - PHYS_MAXSPEED(this)));
403 wishspeed = max(curspeed, PHYS_MAXSPEED(this)) + PHYS_WARSOWBUNNY_ACCEL(this) * f * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH;
405 vector wishvel = wishdir * wishspeed;
406 vector acceldir = wishvel - curvel;
407 float addspeed = vlen(acceldir);
408 acceldir = normalize(acceldir);
410 float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL(this) * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH);
412 if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this) < 1)
414 vector curdir = normalize(curvel);
415 float dot = acceldir * curdir;
417 acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this)) * dot * curdir;
420 this.velocity += accelspeed * acceldir;
428 When you press the jump key
429 returns true if handled
432 bool PlayerJump(entity this)
434 if (PHYS_FROZEN(this))
435 return true; // no jumping in freezetag when frozen
438 if (this.player_blocked)
439 return true; // no jumping while blocked
442 bool doublejump = false;
443 float mjumpheight = PHYS_JUMPVELOCITY(this);
445 if (MUTATOR_CALLHOOK(PlayerJump, this, doublejump, mjumpheight))
448 doublejump = player_multijump;
449 mjumpheight = player_jumpheight;
451 if (this.waterlevel >= WATERLEVEL_SWIMMING)
460 this.velocity_z = PHYS_MAXSPEED(this) * 0.7;
466 if (!IS_ONGROUND(this))
467 return IS_JUMP_HELD(this);
469 bool track_jump = PHYS_CL_TRACK_CANJUMP(this);
470 if(PHYS_TRACK_CANJUMP(this))
474 if (IS_JUMP_HELD(this))
477 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
478 // velocity bounds. Final velocity is bound between (jumpheight *
479 // min + jumpheight) and (jumpheight * max + jumpheight);
481 if(PHYS_JUMPSPEEDCAP_MIN != "")
483 float minjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MIN);
485 if (this.velocity_z < minjumpspeed)
486 mjumpheight += minjumpspeed - this.velocity_z;
489 if(PHYS_JUMPSPEEDCAP_MAX != "")
491 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
492 tracebox(this.origin + '0 0 0.01', this.mins, this.maxs, this.origin - '0 0 0.01', MOVE_NORMAL, this);
494 if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS))
496 float maxjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MAX);
498 if (this.velocity_z > maxjumpspeed)
499 mjumpheight -= this.velocity_z - maxjumpspeed;
503 if (!WAS_ONGROUND(this))
506 if(autocvar_speedmeter)
507 LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n"));
509 if(this.lastground < time - 0.3)
511 this.velocity_x *= (1 - PHYS_FRICTION_ONLAND);
512 this.velocity_y *= (1 - PHYS_FRICTION_ONLAND);
515 if(this.jumppadcount > 1)
516 LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n"));
517 this.jumppadcount = 0;
521 this.velocity_z += mjumpheight;
523 UNSET_ONGROUND(this);
528 this.oldvelocity_z = this.velocity_z;
530 animdecide_setaction(this, ANIMACTION_JUMP, true);
532 if (autocvar_g_jump_grunt)
533 PlayerSound(this, playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
538 void CheckWaterJump(entity this)
540 // check for a jump-out-of-water
541 makevectors(this.v_angle);
542 vector start = this.origin;
545 normalize(v_forward);
546 vector end = start + v_forward*24;
547 traceline (start, end, true, this);
548 if (trace_fraction < 1)
550 start_z = start_z + this.maxs_z - 8;
551 end = start + v_forward*24;
552 this.movedir = trace_plane_normal * -50;
553 traceline(start, end, true, this);
554 if (trace_fraction == 1)
555 { // open at eye level
556 this.velocity_z = 225;
557 this.flags |= FL_WATERJUMP;
560 PHYS_TELEPORT_TIME(this) = time + 2; // safety net
562 pmove_waterjumptime = time + 2;
570 #define JETPACK_JUMP(s) s.cvar_cl_jetpack_jump
572 float autocvar_cl_jetpack_jump;
573 #define JETPACK_JUMP(s) autocvar_cl_jetpack_jump
575 .float jetpack_stopped;
576 void CheckPlayerJump(entity this)
579 float was_flying = ITEMS_STAT(this) & IT_USING_JETPACK;
581 if (JETPACK_JUMP(this) < 2)
582 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
584 if(PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this))
586 float air_jump = !PlayerJump(this) || player_multijump; // PlayerJump() has important side effects
587 float activate = JETPACK_JUMP(this) && air_jump && PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this);
588 float has_fuel = !PHYS_JETPACK_FUEL || PHYS_AMMO_FUEL(this) || ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO;
590 if (!(ITEMS_STAT(this) & ITEM_Jetpack.m_itemid)) { }
591 else if (this.jetpack_stopped) { }
595 if (was_flying) // TODO: ran out of fuel message
596 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
598 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
600 this.jetpack_stopped = true;
601 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
603 else if (activate && !PHYS_FROZEN(this))
604 ITEMS_STAT(this) |= IT_USING_JETPACK;
608 this.jetpack_stopped = false;
609 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
611 if (!PHYS_INPUT_BUTTON_JUMP(this))
612 UNSET_JUMP_HELD(this);
614 if (this.waterlevel == WATERLEVEL_SWIMMING)
615 CheckWaterJump(this);
618 float racecar_angle(float forward, float down)
626 float ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
628 float angle_mult = forward / (800 + forward);
631 return ret * angle_mult + 360 * (1 - angle_mult);
633 return ret * angle_mult;
636 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
637 .float specialcommand_pos;
638 void SpecialCommand()
641 if (!CheatImpulse(CHIMPULSE_GIVE_ALL.impulse))
642 LOG_INFO("A hollow voice says \"Plugh\".\n");
646 float PM_check_specialcommand(entity this, float buttons)
652 else if (buttons == 1)
654 else if (buttons == 2)
656 else if (buttons == 128)
658 else if (buttons == 256)
660 else if (buttons == 512)
662 else if (buttons == 1024)
667 if (c == substring(specialcommand, this.specialcommand_pos, 1))
669 this.specialcommand_pos += 1;
670 if (this.specialcommand_pos >= strlen(specialcommand))
672 this.specialcommand_pos = 0;
677 else if (this.specialcommand_pos && (c != substring(specialcommand, this.specialcommand_pos - 1, 1)))
678 this.specialcommand_pos = 0;
683 void PM_check_nickspam(entity this)
686 if (time >= this.nickspamtime)
688 if (this.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
690 // slight annoyance for nick change scripts
691 this.movement = -1 * this.movement;
692 this.BUTTON_ATCK = this.BUTTON_JUMP = this.BUTTON_ATCK2 = this.BUTTON_ZOOM = this.BUTTON_CROUCH = this.BUTTON_HOOK = this.BUTTON_USE = 0;
694 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!
696 this.v_angle_x = random() * 360;
697 this.v_angle_y = random() * 360;
698 // at least I'm not forcing retardedview by also assigning to angles_z
699 this.fixangle = true;
705 void PM_check_punch(entity this)
708 if (this.punchangle != '0 0 0')
710 float f = vlen(this.punchangle) - 10 * PHYS_INPUT_TIMELENGTH;
712 this.punchangle = normalize(this.punchangle) * f;
714 this.punchangle = '0 0 0';
717 if (this.punchvector != '0 0 0')
719 float f = vlen(this.punchvector) - 30 * PHYS_INPUT_TIMELENGTH;
721 this.punchvector = normalize(this.punchvector) * f;
723 this.punchvector = '0 0 0';
728 // predict frozen movement, as frozen players CAN move in some cases
729 void PM_check_frozen(entity this)
731 if (!PHYS_FROZEN(this))
733 if (PHYS_DODGING_FROZEN
735 && IS_REAL_CLIENT(this)
739 this.movement_x = bound(-5, this.movement.x, 5);
740 this.movement_y = bound(-5, this.movement.y, 5);
741 this.movement_z = bound(-5, this.movement.z, 5);
744 this.movement = '0 0 0';
746 vector midpoint = ((this.absmin + this.absmax) * 0.5);
747 if (pointcontents(midpoint) == CONTENT_WATER)
749 this.velocity = this.velocity * 0.5;
751 if (pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
752 this.velocity_z = 200;
756 void PM_check_hitground(entity this)
759 if (!this.wasFlying) return;
760 this.wasFlying = false;
761 if (this.waterlevel >= WATERLEVEL_SWIMMING) return;
762 if (time < this.ladder_time) return;
763 if (this.hook) return;
764 this.nextstep = time + 0.3 + random() * 0.1;
765 trace_dphitq3surfaceflags = 0;
766 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
767 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return;
768 entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
771 GlobalSound(this, gs, CH_PLAYER, VOICETYPE_PLAYERSOUND);
775 void PM_Footsteps(entity this)
778 if (!g_footsteps) return;
779 if (IS_DUCKED(this)) return;
780 if (time >= this.lastground + 0.2) return;
781 if (vdist(this.velocity, <=, autocvar_sv_maxspeed * 0.6)) return;
782 if ((time > this.nextstep) || (time < (this.nextstep - 10.0)))
784 this.nextstep = time + 0.3 + random() * 0.1;
785 trace_dphitq3surfaceflags = 0;
786 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
787 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return;
788 entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
791 GlobalSound(this, gs, CH_PLAYER, VOICETYPE_PLAYERSOUND);
796 void PM_check_blocked(entity this)
799 if (!this.player_blocked)
801 this.movement = '0 0 0';
802 this.disableclientprediction = 1;
806 void PM_fly(entity this, float maxspd_mod)
808 // noclipping or flying
809 UNSET_ONGROUND(this);
811 this.velocity = this.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this));
812 makevectors(this.v_angle);
813 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
814 vector wishvel = v_forward * this.movement.x
815 + v_right * this.movement.y
816 + '0 0 1' * this.movement.z;
818 vector wishdir = normalize(wishvel);
819 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod);
821 if(time >= PHYS_TELEPORT_TIME(this))
823 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this) * maxspd_mod, 1, 0, 0, 0);
824 PM_ClientMovement_Move(this);
827 void PM_swim(entity this, float maxspd_mod)
830 UNSET_ONGROUND(this);
832 float jump = PHYS_INPUT_BUTTON_JUMP(this);
833 // water jump only in certain situations
834 // this mimics quakeworld code
835 if (jump && this.waterlevel == WATERLEVEL_SWIMMING && this.velocity_z >= -180 && !this.viewloc)
837 vector yawangles = '0 1 0' * this.v_angle.y;
838 makevectors(yawangles);
839 vector forward = v_forward;
840 vector spot = this.origin + 24 * forward;
842 traceline(spot, spot, MOVE_NOMONSTERS, this);
843 if (trace_startsolid)
846 traceline(spot, spot, MOVE_NOMONSTERS, this);
847 if (!trace_startsolid)
849 this.velocity = forward * 50;
850 this.velocity_z = 310;
852 pmove_waterjumptime = 2;
854 UNSET_ONGROUND(this);
859 makevectors(this.v_angle);
860 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
861 vector wishvel = v_forward * this.movement.x
862 + v_right * this.movement.y
863 + '0 0 1' * this.movement.z;
865 wishvel.z = -160; // drift anyway
866 else if (wishvel == '0 0 0')
867 wishvel = '0 0 -60'; // drift towards bottom
870 vector wishdir = normalize(wishvel);
871 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod) * 0.7;
876 // if (pmove_waterjumptime <= 0) // TODO: use
879 float f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this);
880 f = min(max(0, f), 1);
883 f = wishspeed - this.velocity * wishdir;
886 float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, f);
887 this.velocity += accelspeed * wishdir;
890 // holding jump button swims upward slowly
891 if (jump && !this.viewloc)
894 if (this.watertype & CONTENT_LAVA)
895 this.velocity_z = 50;
896 else if (this.watertype & CONTENT_SLIME)
897 this.velocity_z = 80;
900 if (IS_NEXUIZ_DERIVED(gamemode))
902 this.velocity_z = 200;
905 this.velocity_z = 100;
912 const float addspeed = wishspeed - this.velocity * wishdir;
915 const float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
916 this.velocity += accelspeed * wishdir;
921 // water acceleration
922 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this) * maxspd_mod, 1, 0, 0, 0);
923 PM_ClientMovement_Move(this);
928 void PM_ladder(entity this, float maxspd_mod)
930 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
931 UNSET_ONGROUND(this);
934 g = PHYS_GRAVITY(this) * PHYS_INPUT_TIMELENGTH;
935 if (PHYS_ENTGRAVITY(this))
936 g *= PHYS_ENTGRAVITY(this);
937 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
940 this.velocity_z += g;
943 this.velocity = this.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this));
944 makevectors(this.v_angle);
945 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
946 vector wishvel = v_forward * this.movement_x
947 + v_right * this.movement_y
948 + '0 0 1' * this.movement_z;
950 wishvel.z = this.oldmovement.x;
951 this.velocity_z += g;
952 if (this.ladder_entity.classname == "func_water")
954 float f = vlen(wishvel);
955 if (f > this.ladder_entity.speed)
956 wishvel *= (this.ladder_entity.speed / f);
958 this.watertype = this.ladder_entity.skin;
959 f = this.ladder_entity.origin_z + this.ladder_entity.maxs_z;
960 if ((this.origin_z + this.view_ofs_z) < f)
961 this.waterlevel = WATERLEVEL_SUBMERGED;
962 else if ((this.origin_z + (this.mins_z + this.maxs_z) * 0.5) < f)
963 this.waterlevel = WATERLEVEL_SWIMMING;
964 else if ((this.origin_z + this.mins_z + 1) < f)
965 this.waterlevel = WATERLEVEL_WETFEET;
968 this.waterlevel = WATERLEVEL_NONE;
969 this.watertype = CONTENT_EMPTY;
973 vector wishdir = normalize(wishvel);
974 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod);
975 if(time >= PHYS_TELEPORT_TIME(this))
976 // water acceleration
977 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this)*maxspd_mod, 1, 0, 0, 0);
978 PM_ClientMovement_Move(this);
981 void PM_jetpack(entity this, float maxspd_mod)
983 //makevectors(this.v_angle.y * '0 1 0');
984 makevectors(this.v_angle);
985 vector wishvel = v_forward * this.movement_x
986 + v_right * this.movement_y;
987 // add remaining speed as Z component
988 float maxairspd = PHYS_MAXAIRSPEED(this) * max(1, maxspd_mod);
990 wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
991 // add the unused velocity as up component
994 // if (this.BUTTON_JUMP)
995 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
997 // it is now normalized, so...
998 float a_side = PHYS_JETPACK_ACCEL_SIDE;
999 float a_up = PHYS_JETPACK_ACCEL_UP;
1000 float a_add = PHYS_JETPACK_ANTIGRAVITY * PHYS_GRAVITY(this);
1002 wishvel_x *= a_side;
1003 wishvel_y *= a_side;
1008 //////////////////////////////////////////////////////////////////////////////////////
1009 // finding the maximum over all vectors of above form
1010 // with wishvel having an absolute value of 1
1011 //////////////////////////////////////////////////////////////////////////////////////
1012 // we're finding the maximum over
1013 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1014 // for z in the range from -1 to 1
1015 //////////////////////////////////////////////////////////////////////////////////////
1016 // maximum is EITHER attained at the single extreme point:
1017 float a_diff = a_side * a_side - a_up * a_up;
1021 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1022 if (f > -1 && f < 1) // can it be attained?
1024 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1025 //print("middle\n");
1028 // OR attained at z = 1:
1029 f = (a_up + a_add) * (a_up + a_add);
1035 // OR attained at z = -1:
1036 f = (a_up - a_add) * (a_up - a_add);
1040 //print("bottom\n");
1043 //////////////////////////////////////////////////////////////////////////////////////
1045 //print("best possible acceleration: ", ftos(best), "\n");
1048 fxy = bound(0, 1 - (this.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE, 1);
1049 if (wishvel_z - PHYS_GRAVITY(this) > 0)
1050 fz = bound(0, 1 - this.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
1052 fz = bound(0, 1 + this.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
1055 fvel = vlen(wishvel);
1058 wishvel_z = (wishvel_z - PHYS_GRAVITY(this)) * fz + PHYS_GRAVITY(this);
1060 fvel = min(1, vlen(wishvel) / best);
1061 if (PHYS_JETPACK_FUEL && !(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO))
1062 f = min(1, PHYS_AMMO_FUEL(this) / (PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel));
1066 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1068 if (f > 0 && wishvel != '0 0 0')
1070 this.velocity = this.velocity + wishvel * f * PHYS_INPUT_TIMELENGTH;
1071 UNSET_ONGROUND(this);
1074 if (!(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO))
1075 this.ammo_fuel -= PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel * f;
1077 ITEMS_STAT(this) |= IT_USING_JETPACK;
1079 // jetpack also inhibits health regeneration, but only for 1 second
1080 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1085 float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH;
1086 if(autocvar_cl_movement != 3)
1088 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1089 this.velocity_z -= g * 0.5;
1091 this.velocity_z -= g;
1093 PM_ClientMovement_Move(this);
1094 if(autocvar_cl_movement != 3)
1096 if (!IS_ONGROUND(this) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1097 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1098 this.velocity_z -= g * 0.5;
1103 void PM_walk(entity this, float maxspd_mod)
1105 if (!WAS_ONGROUND(this))
1108 if (autocvar_speedmeter)
1109 LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n"));
1111 if (this.lastground < time - 0.3)
1112 this.velocity *= (1 - PHYS_FRICTION_ONLAND);
1114 if (this.jumppadcount > 1)
1115 LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n"));
1116 this.jumppadcount = 0;
1121 makevectors(this.v_angle.y * '0 1 0');
1122 const vector wishvel = v_forward * this.movement.x
1123 + v_right * this.movement.y;
1125 const vector wishdir = normalize(wishvel);
1126 float wishspeed = vlen(wishvel);
1127 wishspeed = min(wishspeed, PHYS_MAXSPEED(this) * maxspd_mod);
1128 if (IS_DUCKED(this)) wishspeed *= 0.5;
1130 // apply edge friction
1131 const float f2 = vlen2(vec2(this.velocity));
1134 trace_dphitq3surfaceflags = 0;
1135 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
1136 // TODO: apply edge friction
1137 // apply ground friction
1138 const int realfriction = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK)
1139 ? PHYS_FRICTION_SLICK
1140 : PHYS_FRICTION(this);
1143 f = 1 - PHYS_INPUT_TIMELENGTH * realfriction * ((f < PHYS_STOPSPEED(this)) ? (PHYS_STOPSPEED(this) / f) : 1);
1147 Mathematical analysis time!
1149 Our goal is to invert this mess.
1151 For the two cases we get:
1152 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * (PHYS_STOPSPEED(this) / v0) * PHYS_FRICTION(this))
1153 = v0 - PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this)
1154 v0 = v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this)
1156 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1157 v0 = v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1159 These cases would be chosen ONLY if:
1160 v0 < PHYS_STOPSPEED(this)
1161 v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this) < PHYS_STOPSPEED(this)
1162 v < PHYS_STOPSPEED(this) * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1164 v0 >= PHYS_STOPSPEED(this)
1165 v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this)) >= PHYS_STOPSPEED(this)
1166 v >= PHYS_STOPSPEED(this) * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1169 const float addspeed = wishspeed - this.velocity * wishdir;
1172 const float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
1173 this.velocity += accelspeed * wishdir;
1176 float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH;
1177 if(autocvar_cl_movement != 3)
1179 if (!(GAMEPLAYFIX_NOGRAVITYONGROUND))
1180 this.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1);
1182 if (vdist(this.velocity, >, 0))
1183 PM_ClientMovement_Move(this);
1184 if(autocvar_cl_movement != 3)
1186 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1187 if (!IS_ONGROUND(this) || !GAMEPLAYFIX_NOGRAVITYONGROUND)
1188 this.velocity_z -= g * 0.5;
1193 void PM_air(entity this, float buttons_prev, float maxspd_mod)
1195 makevectors(this.v_angle.y * '0 1 0');
1196 vector wishvel = v_forward * this.movement.x
1197 + v_right * this.movement.y;
1199 vector wishdir = normalize(wishvel);
1200 float wishspeed = vlen(wishvel);
1203 if(time >= PHYS_TELEPORT_TIME(this))
1205 if(pmove_waterjumptime <= 0)
1208 float maxairspd = PHYS_MAXAIRSPEED(this) * min(maxspd_mod, 1);
1210 // apply air speed limit
1211 float airaccelqw = PHYS_AIRACCEL_QW(this);
1212 float wishspeed0 = wishspeed;
1213 wishspeed = min(wishspeed, maxairspd);
1214 if (IS_DUCKED(this))
1216 float airaccel = PHYS_AIRACCELERATE(this) * min(maxspd_mod, 1);
1218 float accelerating = (this.velocity * wishdir > 0);
1219 float wishspeed2 = wishspeed;
1222 if (PHYS_AIRSTOPACCELERATE(this))
1224 vector curdir = normalize(vec2(this.velocity));
1225 airaccel += (PHYS_AIRSTOPACCELERATE(this)*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1227 // note that for straight forward jumping:
1228 // step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
1229 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1231 // dv/dt = accel * maxspeed (when slow)
1232 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1233 // log dv/dt = logaccel + logmaxspeed (when slow)
1234 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1235 float strafity = IsMoveInDirection(this.movement, -90) + IsMoveInDirection(this.movement, +90); // if one is nonzero, other is always zero
1236 if (PHYS_MAXAIRSTRAFESPEED(this))
1237 wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED(this)*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED(this)*maxspd_mod));
1238 if (PHYS_AIRSTRAFEACCELERATE(this))
1239 airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE(this)*maxspd_mod);
1240 if (PHYS_AIRSTRAFEACCEL_QW(this))
1242 (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(this) : PHYS_AIRACCEL_QW(this)) >= 0) ? +1 : -1)
1244 (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(this)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(this))));
1247 if (PHYS_WARSOWBUNNY_TURNACCEL(this) && accelerating && this.movement.y == 0 && this.movement.x != 0)
1248 PM_AirAccelerate(this, wishdir, wishspeed2);
1250 PM_Accelerate(this, wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(this), PHYS_AIRACCEL_SIDEWAYS_FRICTION(this) / maxairspd, PHYS_AIRSPEEDLIMIT_NONQW(this));
1252 if (PHYS_AIRCONTROL(this))
1253 CPM_PM_Aircontrol(this, wishdir, wishspeed2);
1256 float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH;
1257 if(autocvar_cl_movement != 3)
1258 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1259 this.velocity_z -= g * 0.5;
1261 this.velocity_z -= g;
1263 PM_ClientMovement_Move(this);
1265 if(autocvar_cl_movement != 3)
1266 if (!IS_ONGROUND(this) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1267 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1268 this.velocity_z -= g * 0.5;
1272 // used for calculating airshots
1273 bool IsFlying(entity this)
1275 if(IS_ONGROUND(this))
1277 if(this.waterlevel >= WATERLEVEL_SWIMMING)
1279 traceline(this.origin, this.origin - '0 0 48', MOVE_NORMAL, this);
1280 if(trace_fraction < 1)
1285 void PM_Main(entity this)
1287 int buttons = PHYS_INPUT_BUTTON_MASK(this);
1289 this.items = STAT(ITEMS);
1291 this.movement = PHYS_INPUT_MOVEVALUES(this);
1293 this.spectatorspeed = STAT(SPECTATORSPEED);
1295 vector oldv_angle = this.v_angle;
1296 vector oldangles = this.angles; // we need to save these, as they're abused by other code
1297 this.v_angle = PHYS_INPUT_ANGLES(this);
1298 this.angles = PHYS_WORLD_ANGLES(this);
1300 this.team = myteam + 1; // is this correct?
1301 if (!(PHYS_INPUT_BUTTON_JUMP(this))) // !jump
1302 UNSET_JUMP_HELD(this); // canjump = true
1303 pmove_waterjumptime -= PHYS_INPUT_TIMELENGTH;
1305 PM_ClientMovement_UpdateStatus(this, true);
1308 this.oldmovement = this.movement;
1312 WarpZone_PlayerPhysics_FixVAngle();
1314 float maxspeed_mod = 1;
1315 maxspeed_mod *= PHYS_HIGHSPEED;
1318 Physics_UpdateStats(this, maxspeed_mod);
1320 if (this.PlayerPhysplug)
1321 if (this.PlayerPhysplug())
1326 anticheat_physics(this);
1329 if (PM_check_specialcommand(this, buttons))
1334 if (buttons != this.buttons_old || this.movement != this.movement_old || this.v_angle != this.v_angle_old)
1335 this.parm_idlesince = time;
1338 int buttons_prev = this.buttons_old;
1339 this.buttons_old = buttons;
1340 this.movement_old = this.movement;
1341 this.v_angle_old = this.v_angle;
1343 PM_check_nickspam(this);
1345 PM_check_punch(this);
1347 if (IS_BOT_CLIENT(this))
1349 if (playerdemo_read(this))
1351 WITH(entity, self, this, bot_think());
1356 if (IS_PLAYER(this))
1358 const bool allowed_to_move = (time >= game_starttime);
1359 if (!allowed_to_move)
1361 this.velocity = '0 0 0';
1362 this.movetype = MOVETYPE_NONE;
1363 this.disableclientprediction = 2;
1365 else if (this.disableclientprediction == 2)
1367 if (this.movetype == MOVETYPE_NONE)
1368 this.movetype = MOVETYPE_WALK;
1369 this.disableclientprediction = 0;
1375 if (this.movetype == MOVETYPE_NONE)
1378 // when we get here, disableclientprediction cannot be 2
1379 this.disableclientprediction = 0;
1382 viewloc_PlayerPhysics(this);
1384 PM_check_frozen(this);
1386 PM_check_blocked(this);
1391 maxspeed_mod *= this.swamp_slowdown; //cvar("g_balance_swamp_moverate");
1393 // conveyors: first fix velocity
1394 if (this.conveyor.state)
1395 this.velocity -= this.conveyor.movedir;
1397 MUTATOR_CALLHOOK(PlayerPhysics, this);
1399 if (!IS_PLAYER(this))
1402 maxspeed_mod = autocvar_sv_spectator_speed_multiplier;
1403 if (!this.spectatorspeed)
1404 this.spectatorspeed = maxspeed_mod;
1405 if (this.impulse && this.impulse <= 19 || (this.impulse >= 200 && this.impulse <= 209) || (this.impulse >= 220 && this.impulse <= 229))
1407 if (this.lastclassname != "player")
1409 if (this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209))
1410 this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5);
1411 else if (this.impulse == 11)
1412 this.spectatorspeed = maxspeed_mod;
1413 else if (this.impulse == 12 || this.impulse == 16 || this.impulse == 19 || (this.impulse >= 220 && this.impulse <= 229))
1414 this.spectatorspeed = bound(1, this.spectatorspeed - 0.5, 5);
1415 else if (this.impulse >= 1 && this.impulse <= 9)
1416 this.spectatorspeed = 1 + 0.5 * (this.impulse - 1);
1417 } // otherwise just clear
1421 maxspeed_mod = this.spectatorspeed;
1425 float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod;
1426 if(this.speed != spd)
1429 string temps = ftos(spd);
1430 stuffcmd(this, strcat("cl_forwardspeed ", temps, "\n"));
1431 stuffcmd(this, strcat("cl_backspeed ", temps, "\n"));
1432 stuffcmd(this, strcat("cl_sidespeed ", temps, "\n"));
1433 stuffcmd(this, strcat("cl_upspeed ", temps, "\n"));
1436 if(this.jumpspeedcap_min != autocvar_sv_jumpspeedcap_min)
1438 this.jumpspeedcap_min = autocvar_sv_jumpspeedcap_min;
1439 stuffcmd(this, sprintf("\ncl_jumpspeedcap_min \"%s\"\n", autocvar_sv_jumpspeedcap_min));
1441 if(this.jumpspeedcap_max != autocvar_sv_jumpspeedcap_max)
1443 this.jumpspeedcap_max = autocvar_sv_jumpspeedcap_max;
1444 stuffcmd(this, sprintf("\ncl_jumpspeedcap_max \"%s\"\n", autocvar_sv_jumpspeedcap_max));
1450 // handle water here
1451 vector midpoint = ((this.absmin + this.absmax) * 0.5);
1452 if(pointcontents(midpoint) == CONTENT_WATER)
1454 this.velocity = this.velocity * 0.5;
1457 //if(pointcontents(midpoint + '0 0 2') == CONTENT_WATER)
1458 //{ this.velocity_z = 70; }
1465 this.angles = '0 1 0' * this.v_angle.y;
1468 if (IS_PLAYER(this) && IS_ONGROUND(this))
1470 PM_check_hitground(this);
1477 if (IS_PLAYER(this))
1478 CheckPlayerJump(this);
1480 if (this.flags & FL_WATERJUMP)
1482 this.velocity_x = this.movedir.x;
1483 this.velocity_y = this.movedir.y;
1484 if (time > PHYS_TELEPORT_TIME(this) || this.waterlevel == WATERLEVEL_NONE)
1486 this.flags &= ~FL_WATERJUMP;
1487 PHYS_TELEPORT_TIME(this) = 0;
1491 else if (MUTATOR_CALLHOOK(PM_Physics, this, maxspeed_mod))
1495 else if (this.movetype == MOVETYPE_NOCLIP || this.movetype == MOVETYPE_FLY || this.movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this))
1497 else if (this.move_movetype == MOVETYPE_NOCLIP || this.move_movetype == MOVETYPE_FLY || this.move_movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this))
1499 PM_fly(this, maxspeed_mod);
1501 else if (this.waterlevel >= WATERLEVEL_SWIMMING)
1502 PM_swim(this, maxspeed_mod);
1504 else if (time < this.ladder_time)
1505 PM_ladder(this, maxspeed_mod);
1507 else if (ITEMS_STAT(this) & IT_USING_JETPACK)
1508 PM_jetpack(this, maxspeed_mod);
1510 else if (IS_ONGROUND(this))
1511 PM_walk(this, maxspeed_mod);
1514 PM_air(this, buttons_prev, maxspeed_mod);
1517 if (IS_ONGROUND(this))
1518 this.lastground = time;
1520 // conveyors: then break velocity again
1521 if(this.conveyor.state)
1522 this.velocity += this.conveyor.movedir;
1524 this.lastflags = this.flags;
1526 this.lastclassname = this.classname;
1529 this.v_angle = oldv_angle;
1530 this.angles = oldangles;
1535 void SV_PlayerPhysics()
1537 void CSQC_ClientMovement_PlayerMove_Frame(entity this)