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, float defaultval)
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)
33 void Physics_UpdateStats(entity this, float maxspd_mod)
35 STAT(MOVEVARS_AIRACCEL_QW, this) = AdjustAirAccelQW(Physics_ClientOption(this, "airaccel_qw", autocvar_sv_airaccel_qw), maxspd_mod);
36 STAT(MOVEVARS_AIRSTRAFEACCEL_QW, this) = (Physics_ClientOption(this, "airstrafeaccel_qw", autocvar_sv_airstrafeaccel_qw))
37 ? AdjustAirAccelQW(Physics_ClientOption(this, "airstrafeaccel_qw", autocvar_sv_airstrafeaccel_qw), maxspd_mod)
39 STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW, this) = Physics_ClientOption(this, "airspeedlimit_nonqw", autocvar_sv_airspeedlimit_nonqw) * maxspd_mod;
40 STAT(MOVEVARS_MAXSPEED, this) = Physics_ClientOption(this, "maxspeed", autocvar_sv_maxspeed) * maxspd_mod; // also slow walking
43 // fix some new settings
44 STAT(MOVEVARS_AIRACCEL_QW_STRETCHFACTOR, this) = Physics_ClientOption(this, "airaccel_qw_stretchfactor", autocvar_sv_airaccel_qw_stretchfactor);
45 STAT(MOVEVARS_MAXAIRSTRAFESPEED, this) = Physics_ClientOption(this, "maxairstrafespeed", autocvar_sv_maxairstrafespeed);
46 STAT(MOVEVARS_MAXAIRSPEED, this) = Physics_ClientOption(this, "maxairspeed", autocvar_sv_maxairspeed);
47 STAT(MOVEVARS_AIRSTRAFEACCELERATE, this) = Physics_ClientOption(this, "airstrafeaccelerate", autocvar_sv_airstrafeaccelerate);
48 STAT(MOVEVARS_WARSOWBUNNY_TURNACCEL, this) = Physics_ClientOption(this, "warsowbunny_turnaccel", autocvar_sv_warsowbunny_turnaccel);
49 STAT(MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION, this) = Physics_ClientOption(this, "airaccel_sideways_friction", autocvar_sv_airaccel_sideways_friction);
50 STAT(MOVEVARS_AIRCONTROL, this) = Physics_ClientOption(this, "aircontrol", autocvar_sv_aircontrol);
51 STAT(MOVEVARS_AIRCONTROL_POWER, this) = Physics_ClientOption(this, "aircontrol_power", autocvar_sv_aircontrol_power);
52 STAT(MOVEVARS_AIRCONTROL_PENALTY, this) = Physics_ClientOption(this, "aircontrol_penalty", autocvar_sv_aircontrol_penalty);
53 STAT(MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL, this) = Physics_ClientOption(this, "warsowbunny_airforwardaccel", autocvar_sv_warsowbunny_airforwardaccel);
54 STAT(MOVEVARS_WARSOWBUNNY_TOPSPEED, this) = Physics_ClientOption(this, "warsowbunny_topspeed", autocvar_sv_warsowbunny_topspeed);
55 STAT(MOVEVARS_WARSOWBUNNY_ACCEL, this) = Physics_ClientOption(this, "warsowbunny_accel", autocvar_sv_warsowbunny_accel);
56 STAT(MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO, this) = Physics_ClientOption(this, "warsowbunny_backtosideratio", autocvar_sv_warsowbunny_backtosideratio);
57 STAT(MOVEVARS_FRICTION, this) = Physics_ClientOption(this, "friction", autocvar_sv_friction);
58 STAT(MOVEVARS_ACCELERATE, this) = Physics_ClientOption(this, "accelerate", autocvar_sv_accelerate);
59 STAT(MOVEVARS_STOPSPEED, this) = Physics_ClientOption(this, "stopspeed", autocvar_sv_stopspeed);
60 STAT(MOVEVARS_AIRACCELERATE, this) = Physics_ClientOption(this, "airaccelerate", autocvar_sv_airaccelerate);
61 STAT(MOVEVARS_AIRSTOPACCELERATE, this) = Physics_ClientOption(this, "airstopaccelerate", autocvar_sv_airstopaccelerate);
62 STAT(MOVEVARS_JUMPVELOCITY, this) = Physics_ClientOption(this, "jumpvelocity", autocvar_sv_jumpvelocity);
63 STAT(MOVEVARS_TRACK_CANJUMP, this) = Physics_ClientOption(this, "track_canjump", autocvar_sv_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)
128 bool do_crouch = PHYS_INPUT_BUTTON_CROUCH(this);
129 if(this.hook && !wasfreed(this.hook))
131 if(this.waterlevel >= WATERLEVEL_SWIMMING)
133 if(hud != HUD_NORMAL)
135 if(STAT(FROZEN, this))
137 if((activeweapon == WEP_SHOCKWAVE || activeweapon == WEP_SHOTGUN) && viewmodel.animstate_startframe == viewmodel.anim_fire2_x && time < viewmodel.weapon_nextthink)
142 // wants to crouch, this always works
143 if (!IS_DUCKED(this)) SET_DUCKED(this);
147 // wants to stand, if currently crouching we need to check for a low ceiling first
150 tracebox(this.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), this.origin, MOVE_NORMAL, this);
151 if (!trace_startsolid) UNSET_DUCKED(this);
155 if (IS_ONGROUND(this) || this.velocity.z <= 0 || pmove_waterjumptime <= 0)
156 pmove_waterjumptime = 0;
160 void CPM_PM_Aircontrol(entity this, vector wishdir, float wishspeed)
162 float k = 32 * (2 * IsMoveInDirection(this.movement, 0) - 1);
166 k *= bound(0, wishspeed / PHYS_MAXAIRSPEED(this), 1);
168 float zspeed = this.velocity_z;
170 float xyspeed = vlen(this.velocity);
171 this.velocity = normalize(this.velocity);
173 float dot = this.velocity * wishdir;
175 if (dot > 0) // we can't change direction while slowing down
177 k *= pow(dot, PHYS_AIRCONTROL_POWER(this)) * PHYS_INPUT_TIMELENGTH;
178 xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY(this) * sqrt(max(0, 1 - dot*dot)) * k/32);
179 k *= PHYS_AIRCONTROL(this);
180 this.velocity = normalize(this.velocity * xyspeed + wishdir * k);
183 this.velocity = this.velocity * xyspeed;
184 this.velocity_z = zspeed;
187 float AdjustAirAccelQW(float accelqw, float factor)
189 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
192 // example config for alternate speed clamping:
193 // sv_airaccel_qw 0.8
194 // sv_airaccel_sideways_friction 0
195 // prvm_globalset server speedclamp_mode 1
197 void PM_Accelerate(entity this, vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
199 float speedclamp = stretchfactor > 0 ? stretchfactor
200 : accelqw < 0 ? 1 // full clamping, no stretch
203 accelqw = fabs(accelqw);
205 if (GAMEPLAYFIX_Q2AIRACCELERATE)
206 wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
208 float vel_straight = this.velocity * wishdir;
209 float vel_z = this.velocity_z;
210 vector vel_xy = vec2(this.velocity);
211 vector vel_perpend = vel_xy - vel_straight * wishdir;
213 float step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
215 float vel_xy_current = vlen(vel_xy);
217 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
218 float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
219 float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
220 vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
221 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
223 if (sidefric < 0 && (vel_perpend*vel_perpend))
224 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
226 float f = max(0, 1 + PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
227 float themin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
228 // assume: themin > 1
229 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
230 // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
231 // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
232 // obviously, this cannot be
237 themin = sqrt(themin);
238 vel_perpend *= max(themin, f);
242 vel_perpend *= max(0, 1 - PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
244 vel_xy = vel_straight * wishdir + vel_perpend;
248 float vel_xy_preclamp;
249 vel_xy_preclamp = vlen(vel_xy);
250 if (vel_xy_preclamp > 0) // prevent division by zero
252 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
253 if (vel_xy_current < vel_xy_preclamp)
254 vel_xy *= (vel_xy_current / vel_xy_preclamp);
258 this.velocity = vel_xy + vel_z * '0 0 1';
261 void PM_AirAccelerate(entity this, vector wishdir, float wishspeed)
266 vector curvel = this.velocity;
268 float curspeed = vlen(curvel);
270 if (wishspeed > curspeed * 1.01)
271 wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL(this) * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH);
274 float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED(this) - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED(this) - PHYS_MAXSPEED(this)));
275 wishspeed = max(curspeed, PHYS_MAXSPEED(this)) + PHYS_WARSOWBUNNY_ACCEL(this) * f * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH;
277 vector wishvel = wishdir * wishspeed;
278 vector acceldir = wishvel - curvel;
279 float addspeed = vlen(acceldir);
280 acceldir = normalize(acceldir);
282 float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL(this) * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH);
284 if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this) < 1)
286 vector curdir = normalize(curvel);
287 float dot = acceldir * curdir;
289 acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this)) * dot * curdir;
292 this.velocity += accelspeed * acceldir;
300 When you press the jump key
301 returns true if handled
304 bool PlayerJump(entity this)
306 if (PHYS_FROZEN(this))
307 return true; // no jumping in freezetag when frozen
310 if (this.player_blocked)
311 return true; // no jumping while blocked
314 bool doublejump = false;
315 float mjumpheight = PHYS_JUMPVELOCITY(this);
317 if (MUTATOR_CALLHOOK(PlayerJump, this, mjumpheight, doublejump))
320 mjumpheight = M_ARGV(1, float);
321 doublejump = M_ARGV(2, bool);
323 if (this.waterlevel >= WATERLEVEL_SWIMMING)
332 this.velocity_z = PHYS_MAXSPEED(this) * 0.7;
338 if (!IS_ONGROUND(this))
339 return IS_JUMP_HELD(this);
341 bool track_jump = PHYS_CL_TRACK_CANJUMP(this);
342 if(PHYS_TRACK_CANJUMP(this))
346 if (IS_JUMP_HELD(this))
349 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
350 // velocity bounds. Final velocity is bound between (jumpheight *
351 // min + jumpheight) and (jumpheight * max + jumpheight);
353 if(PHYS_JUMPSPEEDCAP_MIN != "")
355 float minjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MIN);
357 if (this.velocity_z < minjumpspeed)
358 mjumpheight += minjumpspeed - this.velocity_z;
361 if(PHYS_JUMPSPEEDCAP_MAX != "")
363 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
364 tracebox(this.origin + '0 0 0.01', this.mins, this.maxs, this.origin - '0 0 0.01', MOVE_NORMAL, this);
366 if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS(this)))
368 float maxjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MAX);
370 if (this.velocity_z > maxjumpspeed)
371 mjumpheight -= this.velocity_z - maxjumpspeed;
375 if (!WAS_ONGROUND(this))
378 if(autocvar_speedmeter)
379 LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n"));
381 if(this.lastground < time - 0.3)
383 float f = (1 - PHYS_FRICTION_ONLAND(this));
384 this.velocity_x *= f;
385 this.velocity_y *= f;
388 if(this.jumppadcount > 1)
389 LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n"));
390 this.jumppadcount = 0;
394 this.velocity_z += mjumpheight;
396 UNSET_ONGROUND(this);
401 this.oldvelocity_z = this.velocity_z;
403 animdecide_setaction(this, ANIMACTION_JUMP, true);
405 if (autocvar_g_jump_grunt)
406 PlayerSound(this, playersound_jump, CH_PLAYER, VOL_BASE, VOICETYPE_PLAYERSOUND);
411 void CheckWaterJump(entity this)
413 // check for a jump-out-of-water
414 makevectors(this.v_angle);
415 vector start = this.origin;
418 normalize(v_forward);
419 vector end = start + v_forward*24;
420 traceline (start, end, true, this);
421 if (trace_fraction < 1)
423 start_z = start_z + this.maxs_z - 8;
424 end = start + v_forward*24;
425 this.movedir = trace_plane_normal * -50;
426 traceline(start, end, true, this);
427 if (trace_fraction == 1)
428 { // open at eye level
429 this.velocity_z = 225;
430 this.flags |= FL_WATERJUMP;
433 PHYS_TELEPORT_TIME(this) = time + 2; // safety net
435 pmove_waterjumptime = 2;
443 #define JETPACK_JUMP(s) s.cvar_cl_jetpack_jump
445 float autocvar_cl_jetpack_jump;
446 #define JETPACK_JUMP(s) autocvar_cl_jetpack_jump
448 .float jetpack_stopped;
449 void CheckPlayerJump(entity this)
452 bool was_flying = boolean(ITEMS_STAT(this) & IT_USING_JETPACK);
454 if (JETPACK_JUMP(this) < 2)
455 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
457 if(PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this))
459 bool playerjump = PlayerJump(this); // required
461 bool air_jump = !playerjump || M_ARGV(2, bool);
462 bool activate = JETPACK_JUMP(this) && air_jump && PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this);
463 bool has_fuel = !PHYS_JETPACK_FUEL(this) || PHYS_AMMO_FUEL(this) || (ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO);
465 if (!(ITEMS_STAT(this) & ITEM_Jetpack.m_itemid)) { }
466 else if (this.jetpack_stopped) { }
470 if (was_flying) // TODO: ran out of fuel message
471 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
473 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
475 this.jetpack_stopped = true;
476 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
478 else if (activate && !PHYS_FROZEN(this))
479 ITEMS_STAT(this) |= IT_USING_JETPACK;
483 this.jetpack_stopped = false;
484 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
486 if (!PHYS_INPUT_BUTTON_JUMP(this))
487 UNSET_JUMP_HELD(this);
489 if (this.waterlevel == WATERLEVEL_SWIMMING)
490 CheckWaterJump(this);
493 float racecar_angle(float forward, float down)
501 float ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
503 float angle_mult = forward / (800 + forward);
506 return ret * angle_mult + 360 * (1 - angle_mult);
508 return ret * angle_mult;
511 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
512 .float specialcommand_pos;
513 void SpecialCommand(entity this)
516 if (!CheatImpulse(this, CHIMPULSE_GIVE_ALL.impulse))
517 LOG_INFO("A hollow voice says \"Plugh\".\n");
521 bool PM_check_specialcommand(entity this, int buttons)
527 else if (buttons == 1)
529 else if (buttons == 2)
531 else if (buttons == 128)
533 else if (buttons == 256)
535 else if (buttons == 512)
537 else if (buttons == 1024)
542 if (c == substring(specialcommand, this.specialcommand_pos, 1))
544 this.specialcommand_pos += 1;
545 if (this.specialcommand_pos >= strlen(specialcommand))
547 this.specialcommand_pos = 0;
548 SpecialCommand(this);
552 else if (this.specialcommand_pos && (c != substring(specialcommand, this.specialcommand_pos - 1, 1)))
553 this.specialcommand_pos = 0;
558 void PM_check_nickspam(entity this)
561 if (time >= this.nickspamtime)
563 if (this.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
565 // slight annoyance for nick change scripts
566 this.movement = -1 * this.movement;
567 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;
569 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!
571 this.v_angle_x = random() * 360;
572 this.v_angle_y = random() * 360;
573 // at least I'm not forcing retardedview by also assigning to angles_z
574 this.fixangle = true;
580 void PM_check_punch(entity this)
583 if (this.punchangle != '0 0 0')
585 float f = vlen(this.punchangle) - 10 * PHYS_INPUT_TIMELENGTH;
587 this.punchangle = normalize(this.punchangle) * f;
589 this.punchangle = '0 0 0';
592 if (this.punchvector != '0 0 0')
594 float f = vlen(this.punchvector) - 30 * PHYS_INPUT_TIMELENGTH;
596 this.punchvector = normalize(this.punchvector) * f;
598 this.punchvector = '0 0 0';
603 // predict frozen movement, as frozen players CAN move in some cases
604 void PM_check_frozen(entity this)
606 if (!PHYS_FROZEN(this))
608 if (PHYS_DODGING_FROZEN(this)
610 && IS_REAL_CLIENT(this)
614 this.movement_x = bound(-5, this.movement.x, 5);
615 this.movement_y = bound(-5, this.movement.y, 5);
616 this.movement_z = bound(-5, this.movement.z, 5);
619 this.movement = '0 0 0';
621 vector midpoint = ((this.absmin + this.absmax) * 0.5);
622 if (pointcontents(midpoint) == CONTENT_WATER)
624 this.velocity = this.velocity * 0.5;
626 if (pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
627 this.velocity_z = 200;
631 void PM_check_hitground(entity this)
634 if (!this.wasFlying) return;
635 this.wasFlying = false;
636 if (this.waterlevel >= WATERLEVEL_SWIMMING) return;
637 if (time < this.ladder_time) return;
638 if (this.hook) return;
639 this.nextstep = time + 0.3 + random() * 0.1;
640 trace_dphitq3surfaceflags = 0;
641 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
642 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return;
643 entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
646 float vol = ((IS_DUCKED(this)) ? VOL_MUFFLED : VOL_BASE);
647 GlobalSound(this, gs, CH_PLAYER, vol, VOICETYPE_PLAYERSOUND);
651 void PM_Footsteps(entity this)
654 if (!g_footsteps) return;
655 if (IS_DUCKED(this)) return;
656 if (time >= this.lastground + 0.2) return;
657 if (vdist(this.velocity, <=, autocvar_sv_maxspeed * 0.6)) return;
658 if ((time > this.nextstep) || (time < (this.nextstep - 10.0)))
660 this.nextstep = time + 0.3 + random() * 0.1;
661 trace_dphitq3surfaceflags = 0;
662 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
663 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return;
664 entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
667 GlobalSound(this, gs, CH_PLAYER, VOL_BASE, VOICETYPE_PLAYERSOUND);
672 void PM_check_blocked(entity this)
675 if (!this.player_blocked)
677 this.movement = '0 0 0';
678 this.disableclientprediction = 1;
682 void PM_fly(entity this, float maxspd_mod)
684 // noclipping or flying
685 UNSET_ONGROUND(this);
687 this.velocity = this.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this));
688 makevectors(this.v_angle);
689 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
690 vector wishvel = v_forward * this.movement.x
691 + v_right * this.movement.y
692 + '0 0 1' * this.movement.z;
694 vector wishdir = normalize(wishvel);
695 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod);
697 if(time >= PHYS_TELEPORT_TIME(this))
699 if(pmove_waterjumptime <= 0)
701 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this) * maxspd_mod, 1, 0, 0, 0);
704 void PM_swim(entity this, float maxspd_mod)
707 UNSET_ONGROUND(this);
709 float jump = PHYS_INPUT_BUTTON_JUMP(this);
710 // water jump only in certain situations
711 // this mimics quakeworld code
712 if (jump && this.waterlevel == WATERLEVEL_SWIMMING && this.velocity_z >= -180 && !this.viewloc)
714 vector yawangles = '0 1 0' * this.v_angle.y;
715 makevectors(yawangles);
716 vector forward = v_forward;
717 vector spot = this.origin + 24 * forward;
719 traceline(spot, spot, MOVE_NOMONSTERS, this);
720 if (trace_startsolid)
723 traceline(spot, spot, MOVE_NOMONSTERS, this);
724 if (!trace_startsolid)
726 this.velocity = forward * 50;
727 this.velocity_z = 310;
728 UNSET_ONGROUND(this);
733 makevectors(this.v_angle);
734 float wishdown = this.movement.z;
735 if(PHYS_INPUT_BUTTON_CROUCH(this))
736 wishdown = -PHYS_MAXSPEED(this);
737 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
738 vector wishvel = v_forward * this.movement.x
739 + v_right * this.movement.y
740 + '0 0 1' * wishdown;
742 wishvel.z = -160; // drift anyway
743 else if (wishvel == '0 0 0')
744 wishvel = '0 0 -60'; // drift towards bottom
746 vector wishdir = normalize(wishvel);
747 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod) * 0.7;
749 // if (pmove_waterjumptime <= 0) // TODO: use
752 float f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this);
753 f = min(max(0, f), 1);
756 f = wishspeed - this.velocity * wishdir;
759 float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, f);
760 this.velocity += accelspeed * wishdir;
763 // holding jump button swims upward slowly
764 if (jump && !this.viewloc)
767 if (this.watertype & CONTENT_LAVA)
768 this.velocity_z = 50;
769 else if (this.watertype & CONTENT_SLIME)
770 this.velocity_z = 80;
773 if (IS_NEXUIZ_DERIVED(gamemode))
775 if(this.waterlevel >= WATERLEVEL_SUBMERGED)
776 this.velocity_z = PHYS_MAXSPEED(this);
778 this.velocity_z = 200;
781 this.velocity_z = 100;
788 const float addspeed = wishspeed - this.velocity * wishdir;
791 const float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
792 this.velocity += accelspeed * wishdir;
797 // water acceleration
798 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this) * maxspd_mod, 1, 0, 0, 0);
803 void PM_ladder(entity this, float maxspd_mod)
805 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
806 UNSET_ONGROUND(this);
809 g = PHYS_GRAVITY(this) * PHYS_INPUT_TIMELENGTH;
810 if (PHYS_ENTGRAVITY(this))
811 g *= PHYS_ENTGRAVITY(this);
812 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
815 this.velocity_z += g;
818 this.velocity = this.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this));
819 makevectors(this.v_angle);
820 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
821 vector wishvel = v_forward * this.movement_x
822 + v_right * this.movement_y
823 + '0 0 1' * this.movement_z;
825 wishvel.z = this.oldmovement.x;
826 this.velocity_z += g;
827 if (this.ladder_entity.classname == "func_water")
829 float f = vlen(wishvel);
830 if (f > this.ladder_entity.speed)
831 wishvel *= (this.ladder_entity.speed / f);
833 this.watertype = this.ladder_entity.skin;
834 f = this.ladder_entity.origin_z + this.ladder_entity.maxs_z;
835 if ((this.origin_z + this.view_ofs_z) < f)
836 this.waterlevel = WATERLEVEL_SUBMERGED;
837 else if ((this.origin_z + (this.mins_z + this.maxs_z) * 0.5) < f)
838 this.waterlevel = WATERLEVEL_SWIMMING;
839 else if ((this.origin_z + this.mins_z + 1) < f)
840 this.waterlevel = WATERLEVEL_WETFEET;
843 this.waterlevel = WATERLEVEL_NONE;
844 this.watertype = CONTENT_EMPTY;
848 vector wishdir = normalize(wishvel);
849 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod);
851 if(time >= PHYS_TELEPORT_TIME(this))
853 if(pmove_waterjumptime <= 0)
855 // water acceleration
856 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this)*maxspd_mod, 1, 0, 0, 0);
859 void PM_jetpack(entity this, float maxspd_mod)
861 //makevectors(this.v_angle.y * '0 1 0');
862 makevectors(this.v_angle);
863 vector wishvel = v_forward * this.movement_x
864 + v_right * this.movement_y;
865 // add remaining speed as Z component
866 float maxairspd = PHYS_MAXAIRSPEED(this) * max(1, maxspd_mod);
868 wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
869 // add the unused velocity as up component
872 // if (PHYS_INPUT_BUTTON_JUMP(this))
873 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
875 // it is now normalized, so...
876 float a_side = PHYS_JETPACK_ACCEL_SIDE(this);
877 float a_up = PHYS_JETPACK_ACCEL_UP(this);
878 float a_add = PHYS_JETPACK_ANTIGRAVITY(this) * PHYS_GRAVITY(this);
880 if(PHYS_JETPACK_REVERSE_THRUST(this) && PHYS_INPUT_BUTTON_CROUCH(self)) { a_up = PHYS_JETPACK_REVERSE_THRUST(this); }
887 if(PHYS_JETPACK_REVERSE_THRUST(this) && PHYS_INPUT_BUTTON_CROUCH(self)) { wishvel_z *= -1; }
890 //////////////////////////////////////////////////////////////////////////////////////
891 // finding the maximum over all vectors of above form
892 // with wishvel having an absolute value of 1
893 //////////////////////////////////////////////////////////////////////////////////////
894 // we're finding the maximum over
895 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
896 // for z in the range from -1 to 1
897 //////////////////////////////////////////////////////////////////////////////////////
898 // maximum is EITHER attained at the single extreme point:
899 float a_diff = a_side * a_side - a_up * a_up;
903 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
904 if (f > -1 && f < 1) // can it be attained?
906 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
910 // OR attained at z = 1:
911 f = (a_up + a_add) * (a_up + a_add);
917 // OR attained at z = -1:
918 f = (a_up - a_add) * (a_up - a_add);
925 //////////////////////////////////////////////////////////////////////////////////////
927 //print("best possible acceleration: ", ftos(best), "\n");
930 fxy = bound(0, 1 - (this.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE(this), 1);
931 if (wishvel_z - PHYS_GRAVITY(this) > 0)
932 fz = bound(0, 1 - this.velocity_z / PHYS_JETPACK_MAXSPEED_UP(this), 1);
934 fz = bound(0, 1 + this.velocity_z / PHYS_JETPACK_MAXSPEED_UP(this), 1);
937 fvel = vlen(wishvel);
940 wishvel_z = (wishvel_z - PHYS_GRAVITY(this)) * fz + PHYS_GRAVITY(this);
942 fvel = min(1, vlen(wishvel) / best);
943 if (PHYS_JETPACK_FUEL(this) && !(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO))
944 f = min(1, PHYS_AMMO_FUEL(this) / (PHYS_JETPACK_FUEL(this) * PHYS_INPUT_TIMELENGTH * fvel));
948 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
950 if (f > 0 && wishvel != '0 0 0')
952 this.velocity = this.velocity + wishvel * f * PHYS_INPUT_TIMELENGTH;
953 UNSET_ONGROUND(this);
956 if (!(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO))
957 this.ammo_fuel -= PHYS_JETPACK_FUEL(this) * PHYS_INPUT_TIMELENGTH * fvel * f;
959 ITEMS_STAT(this) |= IT_USING_JETPACK;
961 // jetpack also inhibits health regeneration, but only for 1 second
962 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
967 void PM_walk(entity this, float maxspd_mod)
969 if (!WAS_ONGROUND(this))
972 if (autocvar_speedmeter)
973 LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n"));
975 if (this.lastground < time - 0.3)
976 this.velocity *= (1 - PHYS_FRICTION_ONLAND(this));
978 if (this.jumppadcount > 1)
979 LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n"));
980 this.jumppadcount = 0;
985 makevectors(this.v_angle.y * '0 1 0');
986 const vector wishvel = v_forward * this.movement.x
987 + v_right * this.movement.y;
989 const vector wishdir = normalize(wishvel);
990 float wishspeed = vlen(wishvel);
991 wishspeed = min(wishspeed, PHYS_MAXSPEED(this) * maxspd_mod);
992 if (IS_DUCKED(this)) wishspeed *= 0.5;
994 // apply edge friction
995 const float f2 = vlen2(vec2(this.velocity));
998 trace_dphitq3surfaceflags = 0;
999 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
1000 // TODO: apply edge friction
1001 // apply ground friction
1002 const int realfriction = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK)
1003 ? PHYS_FRICTION_SLICK(this)
1004 : PHYS_FRICTION(this);
1007 f = 1 - PHYS_INPUT_TIMELENGTH * realfriction * ((f < PHYS_STOPSPEED(this)) ? (PHYS_STOPSPEED(this) / f) : 1);
1011 Mathematical analysis time!
1013 Our goal is to invert this mess.
1015 For the two cases we get:
1016 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * (PHYS_STOPSPEED(this) / v0) * PHYS_FRICTION(this))
1017 = v0 - PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this)
1018 v0 = v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this)
1020 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1021 v0 = v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1023 These cases would be chosen ONLY if:
1024 v0 < PHYS_STOPSPEED(this)
1025 v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this) < PHYS_STOPSPEED(this)
1026 v < PHYS_STOPSPEED(this) * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1028 v0 >= PHYS_STOPSPEED(this)
1029 v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this)) >= PHYS_STOPSPEED(this)
1030 v >= PHYS_STOPSPEED(this) * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1033 const float addspeed = wishspeed - this.velocity * wishdir;
1036 const float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
1037 this.velocity += accelspeed * wishdir;
1041 void PM_air(entity this, float buttons_prev, float maxspd_mod)
1043 makevectors(this.v_angle.y * '0 1 0');
1044 vector wishvel = v_forward * this.movement.x
1045 + v_right * this.movement.y;
1047 vector wishdir = normalize(wishvel);
1048 float wishspeed = vlen(wishvel);
1051 if(time >= PHYS_TELEPORT_TIME(this))
1053 if(pmove_waterjumptime <= 0)
1056 float maxairspd = PHYS_MAXAIRSPEED(this) * min(maxspd_mod, 1);
1058 // apply air speed limit
1059 float airaccelqw = PHYS_AIRACCEL_QW(this);
1060 float wishspeed0 = wishspeed;
1061 wishspeed = min(wishspeed, maxairspd);
1062 if (IS_DUCKED(this))
1064 float airaccel = PHYS_AIRACCELERATE(this) * min(maxspd_mod, 1);
1066 float accelerating = (this.velocity * wishdir > 0);
1067 float wishspeed2 = wishspeed;
1070 if (PHYS_AIRSTOPACCELERATE(this))
1072 vector curdir = normalize(vec2(this.velocity));
1073 airaccel += (PHYS_AIRSTOPACCELERATE(this)*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1075 // note that for straight forward jumping:
1076 // step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
1077 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1079 // dv/dt = accel * maxspeed (when slow)
1080 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1081 // log dv/dt = logaccel + logmaxspeed (when slow)
1082 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1083 float strafity = IsMoveInDirection(this.movement, -90) + IsMoveInDirection(this.movement, +90); // if one is nonzero, other is always zero
1084 if (PHYS_MAXAIRSTRAFESPEED(this))
1085 wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED(this)*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED(this)*maxspd_mod));
1086 if (PHYS_AIRSTRAFEACCELERATE(this))
1087 airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE(this)*maxspd_mod);
1088 if (PHYS_AIRSTRAFEACCEL_QW(this))
1090 (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(this) : PHYS_AIRACCEL_QW(this)) >= 0) ? +1 : -1)
1092 (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(this)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(this))));
1095 if (PHYS_WARSOWBUNNY_TURNACCEL(this) && accelerating && this.movement.y == 0 && this.movement.x != 0)
1096 PM_AirAccelerate(this, wishdir, wishspeed2);
1098 float sidefric = maxairspd ? (PHYS_AIRACCEL_SIDEWAYS_FRICTION(this) / maxairspd) : 0;
1099 PM_Accelerate(this, wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(this), sidefric, PHYS_AIRSPEEDLIMIT_NONQW(this));
1102 if (PHYS_AIRCONTROL(this))
1103 CPM_PM_Aircontrol(this, wishdir, wishspeed2);
1107 // used for calculating airshots
1108 bool IsFlying(entity this)
1110 if(IS_ONGROUND(this))
1112 if(this.waterlevel >= WATERLEVEL_SWIMMING)
1114 traceline(this.origin, this.origin - '0 0 48', MOVE_NORMAL, this);
1115 if(trace_fraction < 1)
1120 void PM_Main(entity this)
1122 int buttons = PHYS_INPUT_BUTTON_MASK(this);
1124 this.items = STAT(ITEMS);
1126 this.movement = PHYS_INPUT_MOVEVALUES(this);
1128 this.spectatorspeed = STAT(SPECTATORSPEED);
1130 this.team = myteam + 1; // is this correct?
1131 if (!(PHYS_INPUT_BUTTON_JUMP(this))) // !jump
1132 UNSET_JUMP_HELD(this); // canjump = true
1133 pmove_waterjumptime -= PHYS_INPUT_TIMELENGTH;
1135 PM_ClientMovement_UpdateStatus(this);
1138 this.oldmovement = this.movement;
1142 WarpZone_PlayerPhysics_FixVAngle(this);
1144 float maxspeed_mod = 1;
1145 maxspeed_mod *= PHYS_HIGHSPEED(this);
1148 Physics_UpdateStats(this, maxspeed_mod);
1150 if (this.PlayerPhysplug)
1151 if (this.PlayerPhysplug(this))
1154 if(hud != HUD_NORMAL)
1155 return; // no vehicle prediction (yet)
1159 anticheat_physics(this);
1162 if (PM_check_specialcommand(this, buttons))
1167 if (buttons != this.buttons_old || this.movement != this.movement_old || this.v_angle != this.v_angle_old)
1168 this.parm_idlesince = time;
1171 int buttons_prev = this.buttons_old;
1172 this.buttons_old = buttons;
1173 this.movement_old = this.movement;
1174 this.v_angle_old = this.v_angle;
1176 PM_check_nickspam(this);
1178 PM_check_punch(this);
1180 if (IS_BOT_CLIENT(this))
1182 if (playerdemo_read(this))
1189 if (IS_PLAYER(this))
1191 const bool allowed_to_move = (time >= game_starttime);
1192 if (!allowed_to_move)
1194 this.velocity = '0 0 0';
1195 set_movetype(this, MOVETYPE_NONE);
1196 this.disableclientprediction = 2;
1198 else if (this.disableclientprediction == 2)
1200 if (this.move_movetype == MOVETYPE_NONE)
1201 set_movetype(this, MOVETYPE_WALK);
1202 this.disableclientprediction = 0;
1208 if (this.move_movetype == MOVETYPE_NONE)
1211 // when we get here, disableclientprediction cannot be 2
1212 this.disableclientprediction = (this.move_qcphysics) ? -1 : 0;
1215 viewloc_PlayerPhysics(this);
1217 PM_check_frozen(this);
1219 PM_check_blocked(this);
1224 maxspeed_mod *= this.swamp_slowdown; //cvar("g_balance_swamp_moverate");
1226 // conveyors: first fix velocity
1227 if (this.conveyor.state)
1228 this.velocity -= this.conveyor.movedir;
1230 MUTATOR_CALLHOOK(PlayerPhysics, this);
1232 if (!IS_PLAYER(this))
1235 maxspeed_mod = autocvar_sv_spectator_speed_multiplier;
1236 if (!this.spectatorspeed)
1237 this.spectatorspeed = maxspeed_mod;
1238 if (this.impulse && this.impulse <= 19 || (this.impulse >= 200 && this.impulse <= 209) || (this.impulse >= 220 && this.impulse <= 229))
1240 if (this.lastclassname != STR_PLAYER)
1242 if (this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209))
1243 this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5);
1244 else if (this.impulse == 11)
1245 this.spectatorspeed = maxspeed_mod;
1246 else if (this.impulse == 12 || this.impulse == 16 || this.impulse == 19 || (this.impulse >= 220 && this.impulse <= 229))
1247 this.spectatorspeed = bound(1, this.spectatorspeed - 0.5, 5);
1248 else if (this.impulse >= 1 && this.impulse <= 9)
1249 this.spectatorspeed = 1 + 0.5 * (this.impulse - 1);
1250 } // otherwise just clear
1254 maxspeed_mod = this.spectatorspeed;
1258 float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod;
1259 if(this.speed != spd)
1262 string temps = ftos(spd);
1263 stuffcmd(this, strcat("cl_forwardspeed ", temps, "\n"));
1264 stuffcmd(this, strcat("cl_backspeed ", temps, "\n"));
1265 stuffcmd(this, strcat("cl_sidespeed ", temps, "\n"));
1266 stuffcmd(this, strcat("cl_upspeed ", temps, "\n"));
1269 if(this.jumpspeedcap_min != autocvar_sv_jumpspeedcap_min)
1271 this.jumpspeedcap_min = autocvar_sv_jumpspeedcap_min;
1272 stuffcmd(this, sprintf("\ncl_jumpspeedcap_min \"%s\"\n", autocvar_sv_jumpspeedcap_min));
1274 if(this.jumpspeedcap_max != autocvar_sv_jumpspeedcap_max)
1276 this.jumpspeedcap_max = autocvar_sv_jumpspeedcap_max;
1277 stuffcmd(this, sprintf("\ncl_jumpspeedcap_max \"%s\"\n", autocvar_sv_jumpspeedcap_max));
1283 // handle water here
1284 vector midpoint = ((this.absmin + this.absmax) * 0.5);
1285 if(pointcontents(midpoint) == CONTENT_WATER)
1287 this.velocity = this.velocity * 0.5;
1290 //if(pointcontents(midpoint + '0 0 2') == CONTENT_WATER)
1291 //{ this.velocity_z = 70; }
1298 this.angles = '0 1 0' * this.v_angle.y;
1301 if (IS_PLAYER(this) && IS_ONGROUND(this))
1303 PM_check_hitground(this);
1312 if (IS_PLAYER(this))
1313 CheckPlayerJump(this);
1315 if (this.flags & FL_WATERJUMP)
1317 this.velocity_x = this.movedir.x;
1318 this.velocity_y = this.movedir.y;
1319 if (this.waterlevel == WATERLEVEL_NONE
1321 || pmove_waterjumptime <= 0
1323 || time > PHYS_TELEPORT_TIME(this)
1327 this.flags &= ~FL_WATERJUMP;
1329 pmove_waterjumptime = 0;
1331 PHYS_TELEPORT_TIME(this) = 0;
1336 else if (MUTATOR_CALLHOOK(PM_Physics, this, maxspeed_mod))
1340 else if (this.move_movetype == MOVETYPE_NOCLIP || this.move_movetype == MOVETYPE_FLY || this.move_movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this))
1342 else if (this.move_movetype == MOVETYPE_NOCLIP || this.move_movetype == MOVETYPE_FLY || this.move_movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this))
1344 PM_fly(this, maxspeed_mod);
1346 else if (this.waterlevel >= WATERLEVEL_SWIMMING)
1347 PM_swim(this, maxspeed_mod);
1349 else if (time < this.ladder_time)
1350 PM_ladder(this, maxspeed_mod);
1352 else if (ITEMS_STAT(this) & IT_USING_JETPACK)
1353 PM_jetpack(this, maxspeed_mod);
1355 else if (IS_ONGROUND(this))
1356 PM_walk(this, maxspeed_mod);
1359 PM_air(this, buttons_prev, maxspeed_mod);
1362 if (IS_ONGROUND(this))
1363 this.lastground = time;
1365 // conveyors: then break velocity again
1366 if(this.conveyor.state)
1367 this.velocity += this.conveyor.movedir;
1369 this.lastflags = this.flags;
1371 this.lastclassname = this.classname;
1375 void SV_PlayerPhysics(entity this)
1377 void CSQC_ClientMovement_PlayerMove_Frame(entity this)
1383 this.pm_frametime = frametime;