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 if(autocvar_cl_movement != 3)
126 PM_ClientMovement_Unstick(this);
129 if (PHYS_INPUT_BUTTON_CROUCH(this))
131 // wants to crouch, this always works
132 if (!IS_DUCKED(this)) SET_DUCKED(this);
136 // wants to stand, if currently crouching we need to check for a low ceiling first
139 tracebox(this.origin, PL_MIN, PL_MAX, this.origin, MOVE_NORMAL, this);
140 if (!trace_startsolid) UNSET_DUCKED(this);
145 vector origin1 = this.origin + '0 0 1';
146 vector origin2 = this.origin - '0 0 1';
148 if (ground && autocvar_cl_movement != 3)
150 tracebox(origin1, this.mins, this.maxs, origin2, MOVE_NORMAL, this);
151 if (trace_fraction < 1.0 && trace_plane_normal.z > 0.7)
155 // this code actually "predicts" an impact; so let's clip velocity first
156 this.velocity -= this.velocity * trace_plane_normal * trace_plane_normal;
159 UNSET_ONGROUND(this);
162 if(autocvar_cl_movement != 3)
164 // set watertype/waterlevel
165 origin1 = this.origin;
166 origin1.z += this.mins_z + 1;
167 this.waterlevel = WATERLEVEL_NONE;
169 int thepoint = pointcontents(origin1);
171 this.watertype = (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME);
175 this.waterlevel = WATERLEVEL_WETFEET;
176 origin1.z = this.origin.z + (this.mins.z + this.maxs.z) * 0.5;
177 thepoint = pointcontents(origin1);
178 if (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME)
180 this.waterlevel = WATERLEVEL_SWIMMING;
181 origin1.z = this.origin.z + 22;
182 thepoint = pointcontents(origin1);
183 if (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME)
184 this.waterlevel = WATERLEVEL_SUBMERGED;
189 if (IS_ONGROUND(this) || this.velocity.z <= 0 || PHYS_TELEPORT_TIME(this) <= 0)
190 PHYS_TELEPORT_TIME(this) = 0;
194 void PM_ClientMovement_Move(entity this)
198 PM_ClientMovement_UpdateStatus(this, false);
199 if(autocvar_cl_movement == 3)
206 vector currentorigin2;
208 vector primalvelocity;
210 vector trace1_endpos = '0 0 0';
211 vector trace2_endpos = '0 0 0';
212 vector trace3_endpos = '0 0 0';
213 float trace1_fraction = 0;
214 float trace2_fraction = 0;
215 float trace3_fraction = 0;
216 vector trace1_plane_normal = '0 0 0';
217 vector trace2_plane_normal = '0 0 0';
218 vector trace3_plane_normal = '0 0 0';
220 primalvelocity = this.velocity;
221 for(bump = 0, t = PHYS_INPUT_TIMELENGTH; bump < 8 && (this.velocity * this.velocity) > 0; bump++)
223 neworigin = this.origin + t * this.velocity;
224 tracebox(this.origin, this.mins, this.maxs, neworigin, MOVE_NORMAL, this);
225 trace1_endpos = trace_endpos;
226 trace1_fraction = trace_fraction;
227 trace1_plane_normal = trace_plane_normal;
228 if(trace1_fraction < 1 && trace1_plane_normal_z == 0)
230 // may be a step or wall, try stepping up
231 // first move forward at a higher level
232 currentorigin2 = this.origin;
233 currentorigin2_z += PHYS_STEPHEIGHT;
234 neworigin2 = neworigin;
235 neworigin2_z += PHYS_STEPHEIGHT;
236 tracebox(currentorigin2, this.mins, this.maxs, neworigin2, MOVE_NORMAL, this);
237 trace2_endpos = trace_endpos;
238 trace2_fraction = trace_fraction;
239 trace2_plane_normal = trace_plane_normal;
240 if(!trace_startsolid)
242 // then move down from there
243 currentorigin2 = trace2_endpos;
244 neworigin2 = trace2_endpos;
245 neworigin2_z = this.origin_z;
246 tracebox(currentorigin2, this.mins, this.maxs, neworigin2, MOVE_NORMAL, this);
247 trace3_endpos = trace_endpos;
248 trace3_fraction = trace_fraction;
249 trace3_plane_normal = trace_plane_normal;
250 // accept the new trace if it made some progress
251 if(fabs(trace3_endpos_x - trace1_endpos_x) >= 0.03125 || fabs(trace3_endpos_y - trace1_endpos_y) >= 0.03125)
253 trace1_endpos = trace2_endpos;
254 trace1_fraction = trace2_fraction;
255 trace1_plane_normal = trace2_plane_normal;
256 trace1_endpos = trace3_endpos;
261 // check if it moved at all
262 if(trace1_fraction >= 0.001)
263 setorigin(this, trace1_endpos);
265 // check if it moved all the way
266 if(trace1_fraction == 1)
269 // this is only really needed for nogravityonground combined with gravityunaffectedbyticrate
270 // <LordHavoc> I'm pretty sure I commented it out solely because it seemed redundant
271 // this got commented out in a change that supposedly makes the code match QW better
272 // so if this is broken, maybe put it in an if(cls.protocol != PROTOCOL_QUAKEWORLD) block
273 if(trace1_plane_normal_z > 0.7)
276 t -= t * trace1_fraction;
278 f = (this.velocity * trace1_plane_normal);
279 this.velocity = this.velocity + -f * trace1_plane_normal;
281 if(PHYS_TELEPORT_TIME(this) > 0)
282 this.velocity = primalvelocity;
286 void CPM_PM_Aircontrol(entity this, vector wishdir, float wishspeed)
288 float k = 32 * (2 * IsMoveInDirection(this.movement, 0) - 1);
292 k *= bound(0, wishspeed / PHYS_MAXAIRSPEED(this), 1);
294 float zspeed = this.velocity_z;
296 float xyspeed = vlen(this.velocity);
297 this.velocity = normalize(this.velocity);
299 float dot = this.velocity * wishdir;
301 if (dot > 0) // we can't change direction while slowing down
303 k *= pow(dot, PHYS_AIRCONTROL_POWER(this)) * PHYS_INPUT_TIMELENGTH;
304 xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY(this) * sqrt(max(0, 1 - dot*dot)) * k/32);
305 k *= PHYS_AIRCONTROL(this);
306 this.velocity = normalize(this.velocity * xyspeed + wishdir * k);
309 this.velocity = this.velocity * xyspeed;
310 this.velocity_z = zspeed;
313 float AdjustAirAccelQW(float accelqw, float factor)
315 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
318 // example config for alternate speed clamping:
319 // sv_airaccel_qw 0.8
320 // sv_airaccel_sideways_friction 0
321 // prvm_globalset server speedclamp_mode 1
323 void PM_Accelerate(entity this, vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
325 float speedclamp = stretchfactor > 0 ? stretchfactor
326 : accelqw < 0 ? 1 // full clamping, no stretch
329 accelqw = fabs(accelqw);
331 if (GAMEPLAYFIX_Q2AIRACCELERATE)
332 wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
334 float vel_straight = this.velocity * wishdir;
335 float vel_z = this.velocity_z;
336 vector vel_xy = vec2(this.velocity);
337 vector vel_perpend = vel_xy - vel_straight * wishdir;
339 float step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
341 float vel_xy_current = vlen(vel_xy);
343 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
344 float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
345 float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
346 vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
347 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
349 if (sidefric < 0 && (vel_perpend*vel_perpend))
350 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
352 float f = max(0, 1 + PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
353 float themin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
354 // assume: themin > 1
355 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
356 // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
357 // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
358 // obviously, this cannot be
363 themin = sqrt(themin);
364 vel_perpend *= max(themin, f);
368 vel_perpend *= max(0, 1 - PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
370 vel_xy = vel_straight * wishdir + vel_perpend;
374 float vel_xy_preclamp;
375 vel_xy_preclamp = vlen(vel_xy);
376 if (vel_xy_preclamp > 0) // prevent division by zero
378 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
379 if (vel_xy_current < vel_xy_preclamp)
380 vel_xy *= (vel_xy_current / vel_xy_preclamp);
384 this.velocity = vel_xy + vel_z * '0 0 1';
387 void PM_AirAccelerate(entity this, vector wishdir, float wishspeed)
392 vector curvel = this.velocity;
394 float curspeed = vlen(curvel);
396 if (wishspeed > curspeed * 1.01)
397 wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL(this) * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH);
400 float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED(this) - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED(this) - PHYS_MAXSPEED(this)));
401 wishspeed = max(curspeed, PHYS_MAXSPEED(this)) + PHYS_WARSOWBUNNY_ACCEL(this) * f * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH;
403 vector wishvel = wishdir * wishspeed;
404 vector acceldir = wishvel - curvel;
405 float addspeed = vlen(acceldir);
406 acceldir = normalize(acceldir);
408 float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL(this) * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH);
410 if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this) < 1)
412 vector curdir = normalize(curvel);
413 float dot = acceldir * curdir;
415 acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this)) * dot * curdir;
418 this.velocity += accelspeed * acceldir;
426 When you press the jump key
427 returns true if handled
430 bool PlayerJump(entity this)
432 if (PHYS_FROZEN(this))
433 return true; // no jumping in freezetag when frozen
436 if (this.player_blocked)
437 return true; // no jumping while blocked
440 bool doublejump = false;
441 float mjumpheight = PHYS_JUMPVELOCITY(this);
443 if (MUTATOR_CALLHOOK(PlayerJump, this, doublejump, mjumpheight))
446 doublejump = player_multijump;
447 mjumpheight = player_jumpheight;
449 if (this.waterlevel >= WATERLEVEL_SWIMMING)
451 this.velocity_z = PHYS_MAXSPEED(this) * 0.7;
456 if (!IS_ONGROUND(this))
457 return IS_JUMP_HELD(this);
459 bool track_jump = PHYS_CL_TRACK_CANJUMP(this);
460 if(PHYS_TRACK_CANJUMP(this))
464 if (IS_JUMP_HELD(this))
467 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
468 // velocity bounds. Final velocity is bound between (jumpheight *
469 // min + jumpheight) and (jumpheight * max + jumpheight);
471 if(PHYS_JUMPSPEEDCAP_MIN != "")
473 float minjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MIN);
475 if (this.velocity_z < minjumpspeed)
476 mjumpheight += minjumpspeed - this.velocity_z;
479 if(PHYS_JUMPSPEEDCAP_MAX != "")
481 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
482 tracebox(this.origin + '0 0 0.01', this.mins, this.maxs, this.origin - '0 0 0.01', MOVE_NORMAL, this);
484 if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS))
486 float maxjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MAX);
488 if (this.velocity_z > maxjumpspeed)
489 mjumpheight -= this.velocity_z - maxjumpspeed;
493 if (!WAS_ONGROUND(this))
496 if(autocvar_speedmeter)
497 LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n"));
499 if(this.lastground < time - 0.3)
501 this.velocity_x *= (1 - PHYS_FRICTION_ONLAND);
502 this.velocity_y *= (1 - PHYS_FRICTION_ONLAND);
505 if(this.jumppadcount > 1)
506 LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n"));
507 this.jumppadcount = 0;
511 this.velocity_z += mjumpheight;
513 UNSET_ONGROUND(this);
518 this.oldvelocity_z = this.velocity_z;
520 animdecide_setaction(this, ANIMACTION_JUMP, true);
522 if (autocvar_g_jump_grunt)
523 PlayerSound(this, playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
528 void CheckWaterJump(entity this)
530 // check for a jump-out-of-water
531 makevectors(this.v_angle);
532 vector start = this.origin;
535 normalize(v_forward);
536 vector end = start + v_forward*24;
537 traceline (start, end, true, this);
538 if (trace_fraction < 1)
540 start_z = start_z + this.maxs_z - 8;
541 end = start + v_forward*24;
542 this.movedir = trace_plane_normal * -50;
543 traceline(start, end, true, this);
544 if (trace_fraction == 1)
545 { // open at eye level
546 this.velocity_z = 225;
547 this.flags |= FL_WATERJUMP;
549 PHYS_TELEPORT_TIME(this) = time + 2; // safety net
556 #define JETPACK_JUMP(s) s.cvar_cl_jetpack_jump
558 float autocvar_cl_jetpack_jump;
559 #define JETPACK_JUMP(s) autocvar_cl_jetpack_jump
561 .float jetpack_stopped;
562 void CheckPlayerJump(entity this)
565 float was_flying = ITEMS_STAT(this) & IT_USING_JETPACK;
567 if (JETPACK_JUMP(this) < 2)
568 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
570 if(PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this))
572 float air_jump = !PlayerJump(this) || player_multijump; // PlayerJump() has important side effects
573 float activate = JETPACK_JUMP(this) && air_jump && PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this);
574 float has_fuel = !PHYS_JETPACK_FUEL || PHYS_AMMO_FUEL(this) || ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO;
576 if (!(ITEMS_STAT(this) & ITEM_Jetpack.m_itemid)) { }
577 else if (this.jetpack_stopped) { }
581 if (was_flying) // TODO: ran out of fuel message
582 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
584 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
586 this.jetpack_stopped = true;
587 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
589 else if (activate && !PHYS_FROZEN(this))
590 ITEMS_STAT(this) |= IT_USING_JETPACK;
594 this.jetpack_stopped = false;
595 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
597 if (!PHYS_INPUT_BUTTON_JUMP(this))
598 UNSET_JUMP_HELD(this);
600 if (this.waterlevel == WATERLEVEL_SWIMMING)
601 CheckWaterJump(this);
604 float racecar_angle(float forward, float down)
612 float ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
614 float angle_mult = forward / (800 + forward);
617 return ret * angle_mult + 360 * (1 - angle_mult);
619 return ret * angle_mult;
622 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
623 .float specialcommand_pos;
624 void SpecialCommand()
627 if (!CheatImpulse(99))
628 LOG_INFO("A hollow voice says \"Plugh\".\n");
632 float PM_check_specialcommand(entity this, float buttons)
638 else if (buttons == 1)
640 else if (buttons == 2)
642 else if (buttons == 128)
644 else if (buttons == 256)
646 else if (buttons == 512)
648 else if (buttons == 1024)
653 if (c == substring(specialcommand, this.specialcommand_pos, 1))
655 this.specialcommand_pos += 1;
656 if (this.specialcommand_pos >= strlen(specialcommand))
658 this.specialcommand_pos = 0;
663 else if (this.specialcommand_pos && (c != substring(specialcommand, this.specialcommand_pos - 1, 1)))
664 this.specialcommand_pos = 0;
669 void PM_check_nickspam(entity this)
672 if (time >= this.nickspamtime)
674 if (this.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
676 // slight annoyance for nick change scripts
677 this.movement = -1 * this.movement;
678 this.BUTTON_ATCK = this.BUTTON_JUMP = this.BUTTON_ATCK2 = this.BUTTON_ZOOM = this.BUTTON_CROUCH = this.BUTTON_HOOK = this.BUTTON_USE = 0;
680 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!
682 this.v_angle_x = random() * 360;
683 this.v_angle_y = random() * 360;
684 // at least I'm not forcing retardedview by also assigning to angles_z
685 this.fixangle = true;
691 void PM_check_punch(entity this)
694 if (this.punchangle != '0 0 0')
696 float f = vlen(this.punchangle) - 10 * PHYS_INPUT_TIMELENGTH;
698 this.punchangle = normalize(this.punchangle) * f;
700 this.punchangle = '0 0 0';
703 if (this.punchvector != '0 0 0')
705 float f = vlen(this.punchvector) - 30 * PHYS_INPUT_TIMELENGTH;
707 this.punchvector = normalize(this.punchvector) * f;
709 this.punchvector = '0 0 0';
714 // predict frozen movement, as frozen players CAN move in some cases
715 void PM_check_frozen(entity this)
717 if (!PHYS_FROZEN(this))
719 if (PHYS_DODGING_FROZEN
721 && IS_REAL_CLIENT(this)
725 this.movement_x = bound(-5, this.movement.x, 5);
726 this.movement_y = bound(-5, this.movement.y, 5);
727 this.movement_z = bound(-5, this.movement.z, 5);
730 this.movement = '0 0 0';
732 vector midpoint = ((this.absmin + this.absmax) * 0.5);
733 if (pointcontents(midpoint) == CONTENT_WATER)
735 this.velocity = this.velocity * 0.5;
737 if (pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
738 this.velocity_z = 200;
742 void PM_check_hitground(entity this)
745 if (!this.wasFlying) return;
746 this.wasFlying = false;
747 if (this.waterlevel >= WATERLEVEL_SWIMMING) return;
748 if (time < this.ladder_time) return;
749 if (this.hook) return;
750 this.nextstep = time + 0.3 + random() * 0.1;
751 trace_dphitq3surfaceflags = 0;
752 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
753 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return;
754 entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
757 GlobalSound(this, gs, CH_PLAYER, VOICETYPE_PLAYERSOUND);
761 void PM_Footsteps(entity this)
764 if (!g_footsteps) return;
765 if (IS_DUCKED(this)) return;
766 if (time >= this.lastground + 0.2) return;
767 if (vdist(this.velocity, <=, autocvar_sv_maxspeed * 0.6)) return;
768 if ((time > this.nextstep) || (time < (this.nextstep - 10.0)))
770 this.nextstep = time + 0.3 + random() * 0.1;
771 trace_dphitq3surfaceflags = 0;
772 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
773 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return;
774 entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
777 GlobalSound(this, gs, CH_PLAYER, VOICETYPE_PLAYERSOUND);
782 void PM_check_blocked(entity this)
785 if (!this.player_blocked)
787 this.movement = '0 0 0';
788 this.disableclientprediction = 1;
792 void PM_fly(entity this, float maxspd_mod)
794 // noclipping or flying
795 UNSET_ONGROUND(this);
797 this.velocity = this.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this));
798 makevectors(this.v_angle);
799 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
800 vector wishvel = v_forward * this.movement.x
801 + v_right * this.movement.y
802 + '0 0 1' * this.movement.z;
804 vector wishdir = normalize(wishvel);
805 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod);
806 if(time >= PHYS_TELEPORT_TIME(this))
807 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this) * maxspd_mod, 1, 0, 0, 0);
808 PM_ClientMovement_Move(this);
811 void PM_swim(entity this, float maxspd_mod)
814 UNSET_ONGROUND(this);
816 float jump = PHYS_INPUT_BUTTON_JUMP(this);
817 // water jump only in certain situations
818 // this mimics quakeworld code
819 if (jump && this.waterlevel == WATERLEVEL_SWIMMING && this.velocity_z >= -180)
821 vector yawangles = '0 1 0' * this.v_angle.y;
822 makevectors(yawangles);
823 vector forward = v_forward;
824 vector spot = this.origin + 24 * forward;
826 traceline(spot, spot, MOVE_NOMONSTERS, this);
827 if (trace_startsolid)
830 traceline(spot, spot, MOVE_NOMONSTERS, this);
831 if (!trace_startsolid)
833 this.velocity = forward * 50;
834 this.velocity_z = 310;
835 PHYS_TELEPORT_TIME(this) = 2;
836 UNSET_ONGROUND(this);
841 makevectors(this.v_angle);
842 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
843 vector wishvel = v_forward * this.movement.x
844 + v_right * this.movement.y
845 + '0 0 1' * this.movement.z;
846 if (wishvel == '0 0 0')
847 wishvel = '0 0 -60'; // drift towards bottom
849 vector wishdir = normalize(wishvel);
850 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod) * 0.7;
855 // if (pmove_waterjumptime <= 0) // TODO: use
858 float f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this);
859 f = min(max(0, f), 1);
862 f = wishspeed - this.velocity * wishdir;
865 float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, f);
866 this.velocity += accelspeed * wishdir;
869 // holding jump button swims upward slowly
873 if (this.watertype & CONTENT_LAVA)
874 this.velocity_z = 50;
875 else if (this.watertype & CONTENT_SLIME)
876 this.velocity_z = 80;
879 if (IS_NEXUIZ_DERIVED(gamemode))
881 this.velocity_z = 200;
884 this.velocity_z = 100;
889 // water acceleration
890 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this) * maxspd_mod, 1, 0, 0, 0);
891 PM_ClientMovement_Move(this);
894 void PM_ladder(entity this, float maxspd_mod)
896 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
897 UNSET_ONGROUND(this);
900 g = PHYS_GRAVITY(this) * PHYS_INPUT_TIMELENGTH;
901 if (PHYS_ENTGRAVITY(this))
902 g *= PHYS_ENTGRAVITY(this);
903 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
906 this.velocity_z += g;
909 this.velocity = this.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this));
910 makevectors(this.v_angle);
911 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
912 vector wishvel = v_forward * this.movement_x
913 + v_right * this.movement_y
914 + '0 0 1' * this.movement_z;
915 this.velocity_z += g;
916 if (this.ladder_entity.classname == "func_water")
918 float f = vlen(wishvel);
919 if (f > this.ladder_entity.speed)
920 wishvel *= (this.ladder_entity.speed / f);
922 this.watertype = this.ladder_entity.skin;
923 f = this.ladder_entity.origin_z + this.ladder_entity.maxs_z;
924 if ((this.origin_z + this.view_ofs_z) < f)
925 this.waterlevel = WATERLEVEL_SUBMERGED;
926 else if ((this.origin_z + (this.mins_z + this.maxs_z) * 0.5) < f)
927 this.waterlevel = WATERLEVEL_SWIMMING;
928 else if ((this.origin_z + this.mins_z + 1) < f)
929 this.waterlevel = WATERLEVEL_WETFEET;
932 this.waterlevel = WATERLEVEL_NONE;
933 this.watertype = CONTENT_EMPTY;
937 vector wishdir = normalize(wishvel);
938 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod);
939 if(time >= PHYS_TELEPORT_TIME(this))
940 // water acceleration
941 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this)*maxspd_mod, 1, 0, 0, 0);
942 PM_ClientMovement_Move(this);
945 void PM_jetpack(entity this, float maxspd_mod)
947 //makevectors(this.v_angle.y * '0 1 0');
948 makevectors(this.v_angle);
949 vector wishvel = v_forward * this.movement_x
950 + v_right * this.movement_y;
951 // add remaining speed as Z component
952 float maxairspd = PHYS_MAXAIRSPEED(this) * max(1, maxspd_mod);
954 wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
955 // add the unused velocity as up component
958 // if (this.BUTTON_JUMP)
959 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
961 // it is now normalized, so...
962 float a_side = PHYS_JETPACK_ACCEL_SIDE;
963 float a_up = PHYS_JETPACK_ACCEL_UP;
964 float a_add = PHYS_JETPACK_ANTIGRAVITY * PHYS_GRAVITY(this);
972 //////////////////////////////////////////////////////////////////////////////////////
973 // finding the maximum over all vectors of above form
974 // with wishvel having an absolute value of 1
975 //////////////////////////////////////////////////////////////////////////////////////
976 // we're finding the maximum over
977 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
978 // for z in the range from -1 to 1
979 //////////////////////////////////////////////////////////////////////////////////////
980 // maximum is EITHER attained at the single extreme point:
981 float a_diff = a_side * a_side - a_up * a_up;
985 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
986 if (f > -1 && f < 1) // can it be attained?
988 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
992 // OR attained at z = 1:
993 f = (a_up + a_add) * (a_up + a_add);
999 // OR attained at z = -1:
1000 f = (a_up - a_add) * (a_up - a_add);
1004 //print("bottom\n");
1007 //////////////////////////////////////////////////////////////////////////////////////
1009 //print("best possible acceleration: ", ftos(best), "\n");
1012 fxy = bound(0, 1 - (this.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE, 1);
1013 if (wishvel_z - PHYS_GRAVITY(this) > 0)
1014 fz = bound(0, 1 - this.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
1016 fz = bound(0, 1 + this.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
1019 fvel = vlen(wishvel);
1022 wishvel_z = (wishvel_z - PHYS_GRAVITY(this)) * fz + PHYS_GRAVITY(this);
1024 fvel = min(1, vlen(wishvel) / best);
1025 if (PHYS_JETPACK_FUEL && !(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO))
1026 f = min(1, PHYS_AMMO_FUEL(this) / (PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel));
1030 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1032 if (f > 0 && wishvel != '0 0 0')
1034 this.velocity = this.velocity + wishvel * f * PHYS_INPUT_TIMELENGTH;
1035 UNSET_ONGROUND(this);
1038 if (!(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO))
1039 this.ammo_fuel -= PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel * f;
1041 ITEMS_STAT(this) |= IT_USING_JETPACK;
1043 // jetpack also inhibits health regeneration, but only for 1 second
1044 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1049 float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH;
1050 if(autocvar_cl_movement != 3)
1052 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1053 this.velocity_z -= g * 0.5;
1055 this.velocity_z -= g;
1057 PM_ClientMovement_Move(this);
1058 if(autocvar_cl_movement != 3)
1060 if (!IS_ONGROUND(this) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1061 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1062 this.velocity_z -= g * 0.5;
1067 void PM_walk(entity this, float maxspd_mod)
1069 if (!WAS_ONGROUND(this))
1072 if (autocvar_speedmeter)
1073 LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n"));
1075 if (this.lastground < time - 0.3)
1076 this.velocity *= (1 - PHYS_FRICTION_ONLAND);
1078 if (this.jumppadcount > 1)
1079 LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n"));
1080 this.jumppadcount = 0;
1085 makevectors(this.v_angle.y * '0 1 0');
1086 const vector wishvel = v_forward * this.movement.x
1087 + v_right * this.movement.y;
1089 const vector wishdir = normalize(wishvel);
1090 float wishspeed = vlen(wishvel);
1091 wishspeed = min(wishspeed, PHYS_MAXSPEED(this) * maxspd_mod);
1092 if (IS_DUCKED(this)) wishspeed *= 0.5;
1094 // apply edge friction
1095 const float f2 = vlen2(vec2(this.velocity));
1098 trace_dphitq3surfaceflags = 0;
1099 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
1100 // TODO: apply edge friction
1101 // apply ground friction
1102 const int realfriction = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK)
1103 ? PHYS_FRICTION_SLICK
1104 : PHYS_FRICTION(this);
1107 f = 1 - PHYS_INPUT_TIMELENGTH * realfriction * ((f < PHYS_STOPSPEED(this)) ? (PHYS_STOPSPEED(this) / f) : 1);
1111 Mathematical analysis time!
1113 Our goal is to invert this mess.
1115 For the two cases we get:
1116 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * (PHYS_STOPSPEED(this) / v0) * PHYS_FRICTION(this))
1117 = v0 - PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this)
1118 v0 = v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this)
1120 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1121 v0 = v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1123 These cases would be chosen ONLY if:
1124 v0 < PHYS_STOPSPEED(this)
1125 v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this) < PHYS_STOPSPEED(this)
1126 v < PHYS_STOPSPEED(this) * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1128 v0 >= PHYS_STOPSPEED(this)
1129 v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this)) >= PHYS_STOPSPEED(this)
1130 v >= PHYS_STOPSPEED(this) * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1133 const float addspeed = wishspeed - this.velocity * wishdir;
1136 const float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
1137 this.velocity += accelspeed * wishdir;
1140 float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH;
1141 if(autocvar_cl_movement != 3)
1143 if (!(GAMEPLAYFIX_NOGRAVITYONGROUND))
1144 this.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1);
1146 if (vdist(this.velocity, >, 0))
1147 PM_ClientMovement_Move(this);
1148 if(autocvar_cl_movement != 3)
1150 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1151 if (!IS_ONGROUND(this) || !GAMEPLAYFIX_NOGRAVITYONGROUND)
1152 this.velocity_z -= g * 0.5;
1157 void PM_air(entity this, float buttons_prev, float maxspd_mod)
1159 makevectors(this.v_angle.y * '0 1 0');
1160 vector wishvel = v_forward * this.movement.x
1161 + v_right * this.movement.y;
1163 vector wishdir = normalize(wishvel);
1164 float wishspeed = vlen(wishvel);
1166 if(PHYS_TELEPORT_TIME(this) < time)
1168 float maxairspd = PHYS_MAXAIRSPEED(this) * min(maxspd_mod, 1);
1170 // apply air speed limit
1171 float airaccelqw = PHYS_AIRACCEL_QW(this);
1172 float wishspeed0 = wishspeed;
1173 wishspeed = min(wishspeed, maxairspd);
1174 if (IS_DUCKED(this))
1176 float airaccel = PHYS_AIRACCELERATE(this) * min(maxspd_mod, 1);
1178 float accelerating = (this.velocity * wishdir > 0);
1179 float wishspeed2 = wishspeed;
1182 if (PHYS_AIRSTOPACCELERATE(this))
1184 vector curdir = normalize(vec2(this.velocity));
1185 airaccel += (PHYS_AIRSTOPACCELERATE(this)*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1187 // note that for straight forward jumping:
1188 // step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
1189 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1191 // dv/dt = accel * maxspeed (when slow)
1192 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1193 // log dv/dt = logaccel + logmaxspeed (when slow)
1194 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1195 float strafity = IsMoveInDirection(this.movement, -90) + IsMoveInDirection(this.movement, +90); // if one is nonzero, other is always zero
1196 if (PHYS_MAXAIRSTRAFESPEED(this))
1197 wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED(this)*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED(this)*maxspd_mod));
1198 if (PHYS_AIRSTRAFEACCELERATE(this))
1199 airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE(this)*maxspd_mod);
1200 if (PHYS_AIRSTRAFEACCEL_QW(this))
1202 (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(this) : PHYS_AIRACCEL_QW(this)) >= 0) ? +1 : -1)
1204 (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(this)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(this))));
1207 if (PHYS_WARSOWBUNNY_TURNACCEL(this) && accelerating && this.movement.y == 0 && this.movement.x != 0)
1208 PM_AirAccelerate(this, wishdir, wishspeed2);
1210 PM_Accelerate(this, wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(this), PHYS_AIRACCEL_SIDEWAYS_FRICTION(this) / maxairspd, PHYS_AIRSPEEDLIMIT_NONQW(this));
1212 if (PHYS_AIRCONTROL(this))
1213 CPM_PM_Aircontrol(this, wishdir, wishspeed2);
1216 float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH;
1217 if(autocvar_cl_movement != 3)
1218 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1219 this.velocity_z -= g * 0.5;
1221 this.velocity_z -= g;
1223 PM_ClientMovement_Move(this);
1225 if(autocvar_cl_movement != 3)
1226 if (!IS_ONGROUND(this) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
1227 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
1228 this.velocity_z -= g * 0.5;
1232 // used for calculating airshots
1233 bool IsFlying(entity this)
1235 if(IS_ONGROUND(this))
1237 if(this.waterlevel >= WATERLEVEL_SWIMMING)
1239 traceline(this.origin, this.origin - '0 0 48', MOVE_NORMAL, this);
1240 if(trace_fraction < 1)
1245 void PM_Main(entity this)
1247 int buttons = PHYS_INPUT_BUTTON_MASK(this);
1249 this.items = getstati(STAT_ITEMS, 0, 24);
1251 this.movement = PHYS_INPUT_MOVEVALUES(this);
1253 vector oldv_angle = this.v_angle;
1254 vector oldangles = this.angles; // we need to save these, as they're abused by other code
1255 this.v_angle = PHYS_INPUT_ANGLES(this);
1256 this.angles = PHYS_WORLD_ANGLES(this);
1258 this.team = myteam + 1; // is this correct?
1259 if (!(PHYS_INPUT_BUTTON_JUMP(this))) // !jump
1260 UNSET_JUMP_HELD(this); // canjump = true
1261 PHYS_TELEPORT_TIME(this) -= PHYS_INPUT_TIMELENGTH;
1263 PM_ClientMovement_UpdateStatus(this, true);
1268 WarpZone_PlayerPhysics_FixVAngle();
1270 float maxspeed_mod = 1;
1271 maxspeed_mod *= PHYS_HIGHSPEED;
1274 Physics_UpdateStats(this, maxspeed_mod);
1276 if (this.PlayerPhysplug)
1277 if (this.PlayerPhysplug())
1282 anticheat_physics(this);
1285 if (PM_check_specialcommand(this, buttons))
1290 if (buttons != this.buttons_old || this.movement != this.movement_old || this.v_angle != this.v_angle_old)
1291 this.parm_idlesince = time;
1294 int buttons_prev = this.buttons_old;
1295 this.buttons_old = buttons;
1296 this.movement_old = this.movement;
1297 this.v_angle_old = this.v_angle;
1299 PM_check_nickspam(this);
1301 PM_check_punch(this);
1303 if (IS_BOT_CLIENT(this))
1305 if (playerdemo_read(this))
1307 WITH(entity, self, this, bot_think());
1312 if (IS_PLAYER(this))
1314 const bool allowed_to_move = (time >= game_starttime);
1315 if (!allowed_to_move)
1317 this.velocity = '0 0 0';
1318 this.movetype = MOVETYPE_NONE;
1319 this.disableclientprediction = 2;
1321 else if (this.disableclientprediction == 2)
1323 if (this.movetype == MOVETYPE_NONE)
1324 this.movetype = MOVETYPE_WALK;
1325 this.disableclientprediction = 0;
1331 if (this.movetype == MOVETYPE_NONE)
1334 // when we get here, disableclientprediction cannot be 2
1335 this.disableclientprediction = 0;
1338 viewloc_PlayerPhysics(this);
1340 PM_check_frozen(this);
1342 PM_check_blocked(this);
1347 maxspeed_mod *= this.swamp_slowdown; //cvar("g_balance_swamp_moverate");
1349 // conveyors: first fix velocity
1350 if (this.conveyor.state)
1351 this.velocity -= this.conveyor.movedir;
1353 MUTATOR_CALLHOOK(PlayerPhysics, this);
1356 if (!IS_PLAYER(this))
1358 maxspeed_mod = autocvar_sv_spectator_speed_multiplier;
1359 if (!this.spectatorspeed)
1360 this.spectatorspeed = maxspeed_mod;
1361 if (this.impulse && this.impulse <= 19 || (this.impulse >= 200 && this.impulse <= 209) || (this.impulse >= 220 && this.impulse <= 229))
1363 if (this.lastclassname != "player")
1365 if (this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209))
1366 this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5);
1367 else if (this.impulse == 11)
1368 this.spectatorspeed = maxspeed_mod;
1369 else if (this.impulse == 12 || this.impulse == 16 || this.impulse == 19 || (this.impulse >= 220 && this.impulse <= 229))
1370 this.spectatorspeed = bound(1, this.spectatorspeed - 0.5, 5);
1371 else if (this.impulse >= 1 && this.impulse <= 9)
1372 this.spectatorspeed = 1 + 0.5 * (this.impulse - 1);
1373 } // otherwise just clear
1376 maxspeed_mod = this.spectatorspeed;
1379 float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod;
1380 if(this.speed != spd)
1383 string temps = ftos(spd);
1384 stuffcmd(this, strcat("cl_forwardspeed ", temps, "\n"));
1385 stuffcmd(this, strcat("cl_backspeed ", temps, "\n"));
1386 stuffcmd(this, strcat("cl_sidespeed ", temps, "\n"));
1387 stuffcmd(this, strcat("cl_upspeed ", temps, "\n"));
1390 if(this.jumpspeedcap_min != autocvar_sv_jumpspeedcap_min)
1392 this.jumpspeedcap_min = autocvar_sv_jumpspeedcap_min;
1393 stuffcmd(this, sprintf("\ncl_jumpspeedcap_min \"%s\"\n", autocvar_sv_jumpspeedcap_min));
1395 if(this.jumpspeedcap_max != autocvar_sv_jumpspeedcap_max)
1397 this.jumpspeedcap_max = autocvar_sv_jumpspeedcap_max;
1398 stuffcmd(this, sprintf("\ncl_jumpspeedcap_max \"%s\"\n", autocvar_sv_jumpspeedcap_max));
1404 // handle water here
1405 vector midpoint = ((this.absmin + this.absmax) * 0.5);
1406 if(pointcontents(midpoint) == CONTENT_WATER)
1408 this.velocity = this.velocity * 0.5;
1411 //if(pointcontents(midpoint + '0 0 2') == CONTENT_WATER)
1412 //{ this.velocity_z = 70; }
1419 this.angles = '0 1 0' * this.v_angle.y;
1422 if (IS_PLAYER(this) && IS_ONGROUND(this))
1424 PM_check_hitground(this);
1431 if (IS_PLAYER(this))
1432 CheckPlayerJump(this);
1434 if (this.flags & FL_WATERJUMP)
1436 this.velocity_x = this.movedir.x;
1437 this.velocity_y = this.movedir.y;
1438 if (time > PHYS_TELEPORT_TIME(this) || this.waterlevel == WATERLEVEL_NONE)
1440 this.flags &= ~FL_WATERJUMP;
1441 PHYS_TELEPORT_TIME(this) = 0;
1445 else if (MUTATOR_CALLHOOK(PM_Physics, this, maxspeed_mod))
1449 else if (this.movetype == MOVETYPE_NOCLIP || this.movetype == MOVETYPE_FLY || this.movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this))
1451 else if (this.move_movetype == MOVETYPE_NOCLIP || this.move_movetype == MOVETYPE_FLY || this.move_movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this))
1453 PM_fly(this, maxspeed_mod);
1455 else if (this.waterlevel >= WATERLEVEL_SWIMMING)
1456 PM_swim(this, maxspeed_mod);
1458 else if (time < this.ladder_time)
1459 PM_ladder(this, maxspeed_mod);
1461 else if (ITEMS_STAT(this) & IT_USING_JETPACK)
1462 PM_jetpack(this, maxspeed_mod);
1464 else if (IS_ONGROUND(this))
1465 PM_walk(this, maxspeed_mod);
1468 PM_air(this, buttons_prev, maxspeed_mod);
1471 if (IS_ONGROUND(this))
1472 this.lastground = time;
1474 // conveyors: then break velocity again
1475 if(this.conveyor.state)
1476 this.velocity += this.conveyor.movedir;
1478 this.lastflags = this.flags;
1480 this.lastclassname = this.classname;
1483 this.v_angle = oldv_angle;
1484 this.angles = oldangles;
1489 void SV_PlayerPhysics()
1491 void CSQC_ClientMovement_PlayerMove_Frame(entity this)