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.spawnflags & WEP_TYPE_MELEE_PRI) && viewmodel.animstate_startframe == viewmodel.anim_fire1_x && time < viewmodel.weapon_nextthink)
139 if((activeweapon.spawnflags & WEP_TYPE_MELEE_SEC) && viewmodel.animstate_startframe == viewmodel.anim_fire2_x && time < viewmodel.weapon_nextthink)
144 // wants to crouch, this always works
145 if (!IS_DUCKED(this)) SET_DUCKED(this);
149 // wants to stand, if currently crouching we need to check for a low ceiling first
152 tracebox(this.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), this.origin, MOVE_NORMAL, this);
153 if (!trace_startsolid) UNSET_DUCKED(this);
157 if (IS_ONGROUND(this) || this.velocity.z <= 0 || pmove_waterjumptime <= 0)
158 pmove_waterjumptime = 0;
162 void CPM_PM_Aircontrol(entity this, vector wishdir, float wishspeed)
164 float k = 32 * (2 * IsMoveInDirection(this.movement, 0) - 1);
168 k *= bound(0, wishspeed / PHYS_MAXAIRSPEED(this), 1);
170 float zspeed = this.velocity_z;
172 float xyspeed = vlen(this.velocity);
173 this.velocity = normalize(this.velocity);
175 float dot = this.velocity * wishdir;
177 if (dot > 0) // we can't change direction while slowing down
179 k *= pow(dot, PHYS_AIRCONTROL_POWER(this)) * PHYS_INPUT_TIMELENGTH;
180 xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY(this) * sqrt(max(0, 1 - dot*dot)) * k/32);
181 k *= PHYS_AIRCONTROL(this);
182 this.velocity = normalize(this.velocity * xyspeed + wishdir * k);
185 this.velocity = this.velocity * xyspeed;
186 this.velocity_z = zspeed;
189 float AdjustAirAccelQW(float accelqw, float factor)
191 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
194 // example config for alternate speed clamping:
195 // sv_airaccel_qw 0.8
196 // sv_airaccel_sideways_friction 0
197 // prvm_globalset server speedclamp_mode 1
199 void PM_Accelerate(entity this, vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
201 float speedclamp = stretchfactor > 0 ? stretchfactor
202 : accelqw < 0 ? 1 // full clamping, no stretch
205 accelqw = fabs(accelqw);
207 if (GAMEPLAYFIX_Q2AIRACCELERATE)
208 wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
210 float vel_straight = this.velocity * wishdir;
211 float vel_z = this.velocity_z;
212 vector vel_xy = vec2(this.velocity);
213 vector vel_perpend = vel_xy - vel_straight * wishdir;
215 float step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
217 float vel_xy_current = vlen(vel_xy);
219 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
220 float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
221 float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
222 vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
223 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
225 if (sidefric < 0 && (vel_perpend*vel_perpend))
226 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
228 float f = max(0, 1 + PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
229 float themin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
230 // assume: themin > 1
231 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
232 // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
233 // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
234 // obviously, this cannot be
239 themin = sqrt(themin);
240 vel_perpend *= max(themin, f);
244 vel_perpend *= max(0, 1 - PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
246 vel_xy = vel_straight * wishdir + vel_perpend;
250 float vel_xy_preclamp;
251 vel_xy_preclamp = vlen(vel_xy);
252 if (vel_xy_preclamp > 0) // prevent division by zero
254 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
255 if (vel_xy_current < vel_xy_preclamp)
256 vel_xy *= (vel_xy_current / vel_xy_preclamp);
260 this.velocity = vel_xy + vel_z * '0 0 1';
263 void PM_AirAccelerate(entity this, vector wishdir, float wishspeed)
268 vector curvel = this.velocity;
270 float curspeed = vlen(curvel);
272 if (wishspeed > curspeed * 1.01)
273 wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL(this) * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH);
276 float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED(this) - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED(this) - PHYS_MAXSPEED(this)));
277 wishspeed = max(curspeed, PHYS_MAXSPEED(this)) + PHYS_WARSOWBUNNY_ACCEL(this) * f * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH;
279 vector wishvel = wishdir * wishspeed;
280 vector acceldir = wishvel - curvel;
281 float addspeed = vlen(acceldir);
282 acceldir = normalize(acceldir);
284 float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL(this) * PHYS_MAXSPEED(this) * PHYS_INPUT_TIMELENGTH);
286 if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this) < 1)
288 vector curdir = normalize(curvel);
289 float dot = acceldir * curdir;
291 acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this)) * dot * curdir;
294 this.velocity += accelspeed * acceldir;
302 When you press the jump key
303 returns true if handled
306 bool PlayerJump(entity this)
308 if (PHYS_FROZEN(this))
309 return true; // no jumping in freezetag when frozen
312 if (this.player_blocked)
313 return true; // no jumping while blocked
316 bool doublejump = false;
317 float mjumpheight = PHYS_JUMPVELOCITY(this);
319 if (MUTATOR_CALLHOOK(PlayerJump, this, mjumpheight, doublejump))
322 mjumpheight = M_ARGV(1, float);
323 doublejump = M_ARGV(2, bool);
325 if (this.waterlevel >= WATERLEVEL_SWIMMING)
334 this.velocity_z = PHYS_MAXSPEED(this) * 0.7;
340 if (!IS_ONGROUND(this))
341 return IS_JUMP_HELD(this);
343 bool track_jump = PHYS_CL_TRACK_CANJUMP(this);
344 if(PHYS_TRACK_CANJUMP(this))
348 if (IS_JUMP_HELD(this))
351 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
352 // velocity bounds. Final velocity is bound between (jumpheight *
353 // min + jumpheight) and (jumpheight * max + jumpheight);
355 if(PHYS_JUMPSPEEDCAP_MIN != "")
357 float minjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MIN);
359 if (this.velocity_z < minjumpspeed)
360 mjumpheight += minjumpspeed - this.velocity_z;
363 if(PHYS_JUMPSPEEDCAP_MAX != "")
365 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
366 tracebox(this.origin + '0 0 0.01', this.mins, this.maxs, this.origin - '0 0 0.01', MOVE_NORMAL, this);
368 if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS(this)))
370 float maxjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MAX);
372 if (this.velocity_z > maxjumpspeed)
373 mjumpheight -= this.velocity_z - maxjumpspeed;
377 if (!WAS_ONGROUND(this))
380 if(autocvar_speedmeter)
381 LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n"));
383 if(this.lastground < time - 0.3)
385 float f = (1 - PHYS_FRICTION_ONLAND(this));
386 this.velocity_x *= f;
387 this.velocity_y *= f;
390 if(this.jumppadcount > 1)
391 LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n"));
392 this.jumppadcount = 0;
396 this.velocity_z += mjumpheight;
398 UNSET_ONGROUND(this);
403 this.oldvelocity_z = this.velocity_z;
405 animdecide_setaction(this, ANIMACTION_JUMP, true);
407 if (autocvar_g_jump_grunt)
408 PlayerSound(this, playersound_jump, CH_PLAYER, VOL_BASE, VOICETYPE_PLAYERSOUND);
413 void CheckWaterJump(entity this)
415 // check for a jump-out-of-water
416 makevectors(this.v_angle);
417 vector start = this.origin;
420 normalize(v_forward);
421 vector end = start + v_forward*24;
422 traceline (start, end, true, this);
423 if (trace_fraction < 1)
425 start_z = start_z + this.maxs_z - 8;
426 end = start + v_forward*24;
427 this.movedir = trace_plane_normal * -50;
428 traceline(start, end, true, this);
429 if (trace_fraction == 1)
430 { // open at eye level
431 this.velocity_z = 225;
432 this.flags |= FL_WATERJUMP;
435 PHYS_TELEPORT_TIME(this) = time + 2; // safety net
437 pmove_waterjumptime = 2;
445 #define JETPACK_JUMP(s) s.cvar_cl_jetpack_jump
447 float autocvar_cl_jetpack_jump;
448 #define JETPACK_JUMP(s) autocvar_cl_jetpack_jump
450 .float jetpack_stopped;
451 void CheckPlayerJump(entity this)
454 bool was_flying = boolean(ITEMS_STAT(this) & IT_USING_JETPACK);
456 if (JETPACK_JUMP(this) < 2)
457 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
459 if(PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this))
461 bool playerjump = PlayerJump(this); // required
463 bool air_jump = !playerjump || M_ARGV(2, bool);
464 bool activate = JETPACK_JUMP(this) && air_jump && PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this);
465 bool has_fuel = !PHYS_JETPACK_FUEL(this) || PHYS_AMMO_FUEL(this) || (ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO);
467 if (!(ITEMS_STAT(this) & ITEM_Jetpack.m_itemid)) { }
468 else if (this.jetpack_stopped) { }
472 if (was_flying) // TODO: ran out of fuel message
473 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
475 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
477 this.jetpack_stopped = true;
478 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
480 else if (activate && !PHYS_FROZEN(this))
481 ITEMS_STAT(this) |= IT_USING_JETPACK;
485 this.jetpack_stopped = false;
486 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
488 if (!PHYS_INPUT_BUTTON_JUMP(this))
489 UNSET_JUMP_HELD(this);
491 if (this.waterlevel == WATERLEVEL_SWIMMING)
492 CheckWaterJump(this);
495 float racecar_angle(float forward, float down)
503 float ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
505 float angle_mult = forward / (800 + forward);
508 return ret * angle_mult + 360 * (1 - angle_mult);
510 return ret * angle_mult;
513 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
514 .float specialcommand_pos;
515 void SpecialCommand(entity this)
518 if (!CheatImpulse(this, CHIMPULSE_GIVE_ALL.impulse))
519 LOG_INFO("A hollow voice says \"Plugh\".\n");
523 bool PM_check_specialcommand(entity this, int buttons)
529 else if (buttons == 1)
531 else if (buttons == 2)
533 else if (buttons == 128)
535 else if (buttons == 256)
537 else if (buttons == 512)
539 else if (buttons == 1024)
544 if (c == substring(specialcommand, this.specialcommand_pos, 1))
546 this.specialcommand_pos += 1;
547 if (this.specialcommand_pos >= strlen(specialcommand))
549 this.specialcommand_pos = 0;
550 SpecialCommand(this);
554 else if (this.specialcommand_pos && (c != substring(specialcommand, this.specialcommand_pos - 1, 1)))
555 this.specialcommand_pos = 0;
560 void PM_check_nickspam(entity this)
563 if (time >= this.nickspamtime)
565 if (this.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
567 // slight annoyance for nick change scripts
568 this.movement = -1 * this.movement;
569 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;
571 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!
573 this.v_angle_x = random() * 360;
574 this.v_angle_y = random() * 360;
575 // at least I'm not forcing retardedview by also assigning to angles_z
576 this.fixangle = true;
582 void PM_check_punch(entity this)
585 if (this.punchangle != '0 0 0')
587 float f = vlen(this.punchangle) - 10 * PHYS_INPUT_TIMELENGTH;
589 this.punchangle = normalize(this.punchangle) * f;
591 this.punchangle = '0 0 0';
594 if (this.punchvector != '0 0 0')
596 float f = vlen(this.punchvector) - 30 * PHYS_INPUT_TIMELENGTH;
598 this.punchvector = normalize(this.punchvector) * f;
600 this.punchvector = '0 0 0';
605 // predict frozen movement, as frozen players CAN move in some cases
606 void PM_check_frozen(entity this)
608 if (!PHYS_FROZEN(this))
610 if (PHYS_DODGING_FROZEN(this)
612 && IS_REAL_CLIENT(this)
616 this.movement_x = bound(-5, this.movement.x, 5);
617 this.movement_y = bound(-5, this.movement.y, 5);
618 this.movement_z = bound(-5, this.movement.z, 5);
621 this.movement = '0 0 0';
623 vector midpoint = ((this.absmin + this.absmax) * 0.5);
624 if (pointcontents(midpoint) == CONTENT_WATER)
626 this.velocity = this.velocity * 0.5;
628 if (pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
629 this.velocity_z = 200;
633 void PM_check_hitground(entity this)
636 if (!this.wasFlying) return;
637 this.wasFlying = false;
638 if (this.waterlevel >= WATERLEVEL_SWIMMING) return;
639 if (time < this.ladder_time) return;
640 if (this.hook) return;
641 this.nextstep = time + 0.3 + random() * 0.1;
642 trace_dphitq3surfaceflags = 0;
643 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
644 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return;
645 entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
648 float vol = ((IS_DUCKED(this)) ? VOL_MUFFLED : VOL_BASE);
649 GlobalSound(this, gs, CH_PLAYER, vol, VOICETYPE_PLAYERSOUND);
653 void PM_Footsteps(entity this)
656 if (!g_footsteps) return;
657 if (IS_DUCKED(this)) return;
658 if (time >= this.lastground + 0.2) return;
659 if (vdist(this.velocity, <=, autocvar_sv_maxspeed * 0.6)) return;
660 if ((time > this.nextstep) || (time < (this.nextstep - 10.0)))
662 this.nextstep = time + 0.3 + random() * 0.1;
663 trace_dphitq3surfaceflags = 0;
664 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
665 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return;
666 entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
669 GlobalSound(this, gs, CH_PLAYER, VOL_BASE, VOICETYPE_PLAYERSOUND);
674 void PM_check_blocked(entity this)
677 if (!this.player_blocked)
679 this.movement = '0 0 0';
680 this.disableclientprediction = 1;
684 void PM_fly(entity this, float maxspd_mod)
686 // noclipping or flying
687 UNSET_ONGROUND(this);
689 this.velocity = this.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this));
690 makevectors(this.v_angle);
691 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
692 vector wishvel = v_forward * this.movement.x
693 + v_right * this.movement.y
694 + '0 0 1' * this.movement.z;
696 vector wishdir = normalize(wishvel);
697 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod);
699 if(time >= PHYS_TELEPORT_TIME(this))
701 if(pmove_waterjumptime <= 0)
703 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this) * maxspd_mod, 1, 0, 0, 0);
706 void PM_swim(entity this, float maxspd_mod)
709 UNSET_ONGROUND(this);
711 float jump = PHYS_INPUT_BUTTON_JUMP(this);
712 // water jump only in certain situations
713 // this mimics quakeworld code
714 if (jump && this.waterlevel == WATERLEVEL_SWIMMING && this.velocity_z >= -180 && !this.viewloc)
716 vector yawangles = '0 1 0' * this.v_angle.y;
717 makevectors(yawangles);
718 vector forward = v_forward;
719 vector spot = this.origin + 24 * forward;
721 traceline(spot, spot, MOVE_NOMONSTERS, this);
722 if (trace_startsolid)
725 traceline(spot, spot, MOVE_NOMONSTERS, this);
726 if (!trace_startsolid)
728 this.velocity = forward * 50;
729 this.velocity_z = 310;
730 UNSET_ONGROUND(this);
735 makevectors(this.v_angle);
736 float wishdown = this.movement.z;
737 if(PHYS_INPUT_BUTTON_CROUCH(this))
738 wishdown = -PHYS_MAXSPEED(this);
739 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
740 vector wishvel = v_forward * this.movement.x
741 + v_right * this.movement.y
742 + '0 0 1' * wishdown;
744 wishvel.z = -160; // drift anyway
745 else if (wishvel == '0 0 0')
746 wishvel = '0 0 -60'; // drift towards bottom
748 vector wishdir = normalize(wishvel);
749 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod) * 0.7;
751 // if (pmove_waterjumptime <= 0) // TODO: use
754 float f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this);
755 f = min(max(0, f), 1);
758 f = wishspeed - this.velocity * wishdir;
761 float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, f);
762 this.velocity += accelspeed * wishdir;
765 // holding jump button swims upward slowly
766 if (jump && !this.viewloc)
769 if (this.watertype & CONTENT_LAVA)
770 this.velocity_z = 50;
771 else if (this.watertype & CONTENT_SLIME)
772 this.velocity_z = 80;
775 if (IS_NEXUIZ_DERIVED(gamemode))
777 if(this.waterlevel >= WATERLEVEL_SUBMERGED)
778 this.velocity_z = PHYS_MAXSPEED(this);
780 this.velocity_z = 200;
783 this.velocity_z = 100;
790 const float addspeed = wishspeed - this.velocity * wishdir;
793 const float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
794 this.velocity += accelspeed * wishdir;
799 // water acceleration
800 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this) * maxspd_mod, 1, 0, 0, 0);
805 void PM_ladder(entity this, float maxspd_mod)
807 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
808 UNSET_ONGROUND(this);
811 g = PHYS_GRAVITY(this) * PHYS_INPUT_TIMELENGTH;
812 if (PHYS_ENTGRAVITY(this))
813 g *= PHYS_ENTGRAVITY(this);
814 if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
817 this.velocity_z += g;
820 this.velocity = this.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this));
821 makevectors(this.v_angle);
822 //wishvel = v_forward * this.movement.x + v_right * this.movement.y + v_up * this.movement.z;
823 vector wishvel = v_forward * this.movement_x
824 + v_right * this.movement_y
825 + '0 0 1' * this.movement_z;
827 wishvel.z = this.oldmovement.x;
828 this.velocity_z += g;
829 if (this.ladder_entity.classname == "func_water")
831 float f = vlen(wishvel);
832 if (f > this.ladder_entity.speed)
833 wishvel *= (this.ladder_entity.speed / f);
835 this.watertype = this.ladder_entity.skin;
836 f = this.ladder_entity.origin_z + this.ladder_entity.maxs_z;
837 if ((this.origin_z + this.view_ofs_z) < f)
838 this.waterlevel = WATERLEVEL_SUBMERGED;
839 else if ((this.origin_z + (this.mins_z + this.maxs_z) * 0.5) < f)
840 this.waterlevel = WATERLEVEL_SWIMMING;
841 else if ((this.origin_z + this.mins_z + 1) < f)
842 this.waterlevel = WATERLEVEL_WETFEET;
845 this.waterlevel = WATERLEVEL_NONE;
846 this.watertype = CONTENT_EMPTY;
850 vector wishdir = normalize(wishvel);
851 float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod);
853 if(time >= PHYS_TELEPORT_TIME(this))
855 if(pmove_waterjumptime <= 0)
857 // water acceleration
858 PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this)*maxspd_mod, 1, 0, 0, 0);
861 void PM_jetpack(entity this, float maxspd_mod)
863 //makevectors(this.v_angle.y * '0 1 0');
864 makevectors(this.v_angle);
865 vector wishvel = v_forward * this.movement_x
866 + v_right * this.movement_y;
867 // add remaining speed as Z component
868 float maxairspd = PHYS_MAXAIRSPEED(this) * max(1, maxspd_mod);
870 wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
871 // add the unused velocity as up component
874 // if (PHYS_INPUT_BUTTON_JUMP(this))
875 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
877 // it is now normalized, so...
878 float a_side = PHYS_JETPACK_ACCEL_SIDE(this);
879 float a_up = PHYS_JETPACK_ACCEL_UP(this);
880 float a_add = PHYS_JETPACK_ANTIGRAVITY(this) * PHYS_GRAVITY(this);
882 if(PHYS_JETPACK_REVERSE_THRUST(this) && PHYS_INPUT_BUTTON_CROUCH(self)) { a_up = PHYS_JETPACK_REVERSE_THRUST(this); }
889 if(PHYS_JETPACK_REVERSE_THRUST(this) && PHYS_INPUT_BUTTON_CROUCH(self)) { wishvel_z *= -1; }
892 //////////////////////////////////////////////////////////////////////////////////////
893 // finding the maximum over all vectors of above form
894 // with wishvel having an absolute value of 1
895 //////////////////////////////////////////////////////////////////////////////////////
896 // we're finding the maximum over
897 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
898 // for z in the range from -1 to 1
899 //////////////////////////////////////////////////////////////////////////////////////
900 // maximum is EITHER attained at the single extreme point:
901 float a_diff = a_side * a_side - a_up * a_up;
905 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
906 if (f > -1 && f < 1) // can it be attained?
908 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
912 // OR attained at z = 1:
913 f = (a_up + a_add) * (a_up + a_add);
919 // OR attained at z = -1:
920 f = (a_up - a_add) * (a_up - a_add);
927 //////////////////////////////////////////////////////////////////////////////////////
929 //print("best possible acceleration: ", ftos(best), "\n");
932 fxy = bound(0, 1 - (this.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE(this), 1);
933 if (wishvel_z - PHYS_GRAVITY(this) > 0)
934 fz = bound(0, 1 - this.velocity_z / PHYS_JETPACK_MAXSPEED_UP(this), 1);
936 fz = bound(0, 1 + this.velocity_z / PHYS_JETPACK_MAXSPEED_UP(this), 1);
939 fvel = vlen(wishvel);
942 wishvel_z = (wishvel_z - PHYS_GRAVITY(this)) * fz + PHYS_GRAVITY(this);
944 fvel = min(1, vlen(wishvel) / best);
945 if (PHYS_JETPACK_FUEL(this) && !(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO))
946 f = min(1, PHYS_AMMO_FUEL(this) / (PHYS_JETPACK_FUEL(this) * PHYS_INPUT_TIMELENGTH * fvel));
950 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
952 if (f > 0 && wishvel != '0 0 0')
954 this.velocity = this.velocity + wishvel * f * PHYS_INPUT_TIMELENGTH;
955 UNSET_ONGROUND(this);
958 if (!(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO))
959 this.ammo_fuel -= PHYS_JETPACK_FUEL(this) * PHYS_INPUT_TIMELENGTH * fvel * f;
961 ITEMS_STAT(this) |= IT_USING_JETPACK;
963 // jetpack also inhibits health regeneration, but only for 1 second
964 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
969 void PM_walk(entity this, float maxspd_mod)
971 if (!WAS_ONGROUND(this))
974 if (autocvar_speedmeter)
975 LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n"));
977 if (this.lastground < time - 0.3)
978 this.velocity *= (1 - PHYS_FRICTION_ONLAND(this));
980 if (this.jumppadcount > 1)
981 LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n"));
982 this.jumppadcount = 0;
987 makevectors(this.v_angle.y * '0 1 0');
988 const vector wishvel = v_forward * this.movement.x
989 + v_right * this.movement.y;
991 const vector wishdir = normalize(wishvel);
992 float wishspeed = vlen(wishvel);
993 wishspeed = min(wishspeed, PHYS_MAXSPEED(this) * maxspd_mod);
994 if (IS_DUCKED(this)) wishspeed *= 0.5;
996 // apply edge friction
997 const float f2 = vlen2(vec2(this.velocity));
1000 trace_dphitq3surfaceflags = 0;
1001 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
1002 // TODO: apply edge friction
1003 // apply ground friction
1004 const int realfriction = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK)
1005 ? PHYS_FRICTION_SLICK(this)
1006 : PHYS_FRICTION(this);
1009 f = 1 - PHYS_INPUT_TIMELENGTH * realfriction * ((f < PHYS_STOPSPEED(this)) ? (PHYS_STOPSPEED(this) / f) : 1);
1013 Mathematical analysis time!
1015 Our goal is to invert this mess.
1017 For the two cases we get:
1018 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * (PHYS_STOPSPEED(this) / v0) * PHYS_FRICTION(this))
1019 = v0 - PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this)
1020 v0 = v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this)
1022 v = v0 * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1023 v0 = v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1025 These cases would be chosen ONLY if:
1026 v0 < PHYS_STOPSPEED(this)
1027 v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED(this) * PHYS_FRICTION(this) < PHYS_STOPSPEED(this)
1028 v < PHYS_STOPSPEED(this) * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1030 v0 >= PHYS_STOPSPEED(this)
1031 v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this)) >= PHYS_STOPSPEED(this)
1032 v >= PHYS_STOPSPEED(this) * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION(this))
1035 const float addspeed = wishspeed - this.velocity * wishdir;
1038 const float accelspeed = min(PHYS_ACCELERATE(this) * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
1039 this.velocity += accelspeed * wishdir;
1043 void PM_air(entity this, float buttons_prev, float maxspd_mod)
1045 makevectors(this.v_angle.y * '0 1 0');
1046 vector wishvel = v_forward * this.movement.x
1047 + v_right * this.movement.y;
1049 vector wishdir = normalize(wishvel);
1050 float wishspeed = vlen(wishvel);
1053 if(time >= PHYS_TELEPORT_TIME(this))
1055 if(pmove_waterjumptime <= 0)
1058 float maxairspd = PHYS_MAXAIRSPEED(this) * min(maxspd_mod, 1);
1060 // apply air speed limit
1061 float airaccelqw = PHYS_AIRACCEL_QW(this);
1062 float wishspeed0 = wishspeed;
1063 wishspeed = min(wishspeed, maxairspd);
1064 if (IS_DUCKED(this))
1066 float airaccel = PHYS_AIRACCELERATE(this) * min(maxspd_mod, 1);
1068 float accelerating = (this.velocity * wishdir > 0);
1069 float wishspeed2 = wishspeed;
1072 if (PHYS_AIRSTOPACCELERATE(this))
1074 vector curdir = normalize(vec2(this.velocity));
1075 airaccel += (PHYS_AIRSTOPACCELERATE(this)*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1077 // note that for straight forward jumping:
1078 // step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
1079 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1081 // dv/dt = accel * maxspeed (when slow)
1082 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1083 // log dv/dt = logaccel + logmaxspeed (when slow)
1084 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1085 float strafity = IsMoveInDirection(this.movement, -90) + IsMoveInDirection(this.movement, +90); // if one is nonzero, other is always zero
1086 if (PHYS_MAXAIRSTRAFESPEED(this))
1087 wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED(this)*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED(this)*maxspd_mod));
1088 if (PHYS_AIRSTRAFEACCELERATE(this))
1089 airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE(this)*maxspd_mod);
1090 if (PHYS_AIRSTRAFEACCEL_QW(this))
1092 (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(this) : PHYS_AIRACCEL_QW(this)) >= 0) ? +1 : -1)
1094 (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(this)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(this))));
1097 if (PHYS_WARSOWBUNNY_TURNACCEL(this) && accelerating && this.movement.y == 0 && this.movement.x != 0)
1098 PM_AirAccelerate(this, wishdir, wishspeed2);
1100 float sidefric = maxairspd ? (PHYS_AIRACCEL_SIDEWAYS_FRICTION(this) / maxairspd) : 0;
1101 PM_Accelerate(this, wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(this), sidefric, PHYS_AIRSPEEDLIMIT_NONQW(this));
1104 if (PHYS_AIRCONTROL(this))
1105 CPM_PM_Aircontrol(this, wishdir, wishspeed2);
1109 // used for calculating airshots
1110 bool IsFlying(entity this)
1112 if(IS_ONGROUND(this))
1114 if(this.waterlevel >= WATERLEVEL_SWIMMING)
1116 traceline(this.origin, this.origin - '0 0 48', MOVE_NORMAL, this);
1117 if(trace_fraction < 1)
1122 void PM_Main(entity this)
1124 int buttons = PHYS_INPUT_BUTTON_MASK(this);
1126 this.items = STAT(ITEMS);
1128 this.movement = PHYS_INPUT_MOVEVALUES(this);
1130 this.spectatorspeed = STAT(SPECTATORSPEED);
1132 this.team = myteam + 1; // is this correct?
1133 if (!(PHYS_INPUT_BUTTON_JUMP(this))) // !jump
1134 UNSET_JUMP_HELD(this); // canjump = true
1135 pmove_waterjumptime -= PHYS_INPUT_TIMELENGTH;
1137 PM_ClientMovement_UpdateStatus(this);
1140 this.oldmovement = this.movement;
1144 WarpZone_PlayerPhysics_FixVAngle(this);
1146 float maxspeed_mod = 1;
1147 maxspeed_mod *= PHYS_HIGHSPEED(this);
1150 Physics_UpdateStats(this, maxspeed_mod);
1152 if (this.PlayerPhysplug)
1153 if (this.PlayerPhysplug(this))
1156 if(hud != HUD_NORMAL)
1157 return; // no vehicle prediction (yet)
1161 anticheat_physics(this);
1164 if (PM_check_specialcommand(this, buttons))
1169 if (buttons != this.buttons_old || this.movement != this.movement_old || this.v_angle != this.v_angle_old)
1170 this.parm_idlesince = time;
1173 int buttons_prev = this.buttons_old;
1174 this.buttons_old = buttons;
1175 this.movement_old = this.movement;
1176 this.v_angle_old = this.v_angle;
1178 PM_check_nickspam(this);
1180 PM_check_punch(this);
1182 if (IS_BOT_CLIENT(this))
1184 if (playerdemo_read(this))
1191 if (IS_PLAYER(this))
1193 const bool allowed_to_move = (time >= game_starttime);
1194 if (!allowed_to_move)
1196 this.velocity = '0 0 0';
1197 set_movetype(this, MOVETYPE_NONE);
1198 this.disableclientprediction = 2;
1200 else if (this.disableclientprediction == 2)
1202 if (this.move_movetype == MOVETYPE_NONE)
1203 set_movetype(this, MOVETYPE_WALK);
1204 this.disableclientprediction = 0;
1210 if (this.move_movetype == MOVETYPE_NONE)
1213 // when we get here, disableclientprediction cannot be 2
1214 this.disableclientprediction = (this.move_qcphysics) ? -1 : 0;
1217 viewloc_PlayerPhysics(this);
1219 PM_check_frozen(this);
1221 PM_check_blocked(this);
1226 maxspeed_mod *= this.swamp_slowdown; //cvar("g_balance_swamp_moverate");
1228 // conveyors: first fix velocity
1229 if (this.conveyor.state)
1230 this.velocity -= this.conveyor.movedir;
1232 MUTATOR_CALLHOOK(PlayerPhysics, this);
1234 if (!IS_PLAYER(this))
1237 maxspeed_mod = autocvar_sv_spectator_speed_multiplier;
1238 if (!this.spectatorspeed)
1239 this.spectatorspeed = maxspeed_mod;
1240 if (this.impulse && this.impulse <= 19 || (this.impulse >= 200 && this.impulse <= 209) || (this.impulse >= 220 && this.impulse <= 229))
1242 if (this.lastclassname != STR_PLAYER)
1244 if (this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209))
1245 this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5);
1246 else if (this.impulse == 11)
1247 this.spectatorspeed = maxspeed_mod;
1248 else if (this.impulse == 12 || this.impulse == 16 || this.impulse == 19 || (this.impulse >= 220 && this.impulse <= 229))
1249 this.spectatorspeed = bound(1, this.spectatorspeed - 0.5, 5);
1250 else if (this.impulse >= 1 && this.impulse <= 9)
1251 this.spectatorspeed = 1 + 0.5 * (this.impulse - 1);
1252 } // otherwise just clear
1256 maxspeed_mod = this.spectatorspeed;
1260 float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod;
1261 if(this.speed != spd)
1264 string temps = ftos(spd);
1265 stuffcmd(this, strcat("cl_forwardspeed ", temps, "\n"));
1266 stuffcmd(this, strcat("cl_backspeed ", temps, "\n"));
1267 stuffcmd(this, strcat("cl_sidespeed ", temps, "\n"));
1268 stuffcmd(this, strcat("cl_upspeed ", temps, "\n"));
1271 if(this.jumpspeedcap_min != autocvar_sv_jumpspeedcap_min)
1273 this.jumpspeedcap_min = autocvar_sv_jumpspeedcap_min;
1274 stuffcmd(this, sprintf("\ncl_jumpspeedcap_min \"%s\"\n", autocvar_sv_jumpspeedcap_min));
1276 if(this.jumpspeedcap_max != autocvar_sv_jumpspeedcap_max)
1278 this.jumpspeedcap_max = autocvar_sv_jumpspeedcap_max;
1279 stuffcmd(this, sprintf("\ncl_jumpspeedcap_max \"%s\"\n", autocvar_sv_jumpspeedcap_max));
1285 // handle water here
1286 vector midpoint = ((this.absmin + this.absmax) * 0.5);
1287 if(pointcontents(midpoint) == CONTENT_WATER)
1289 this.velocity = this.velocity * 0.5;
1292 //if(pointcontents(midpoint + '0 0 2') == CONTENT_WATER)
1293 //{ this.velocity_z = 70; }
1300 this.angles = '0 1 0' * this.v_angle.y;
1303 if (IS_PLAYER(this) && IS_ONGROUND(this))
1305 PM_check_hitground(this);
1314 if (IS_PLAYER(this))
1315 CheckPlayerJump(this);
1317 if (this.flags & FL_WATERJUMP)
1319 this.velocity_x = this.movedir.x;
1320 this.velocity_y = this.movedir.y;
1321 if (this.waterlevel == WATERLEVEL_NONE
1323 || pmove_waterjumptime <= 0
1325 || time > PHYS_TELEPORT_TIME(this)
1329 this.flags &= ~FL_WATERJUMP;
1331 pmove_waterjumptime = 0;
1333 PHYS_TELEPORT_TIME(this) = 0;
1338 else if (MUTATOR_CALLHOOK(PM_Physics, this, maxspeed_mod))
1342 else if (this.move_movetype == MOVETYPE_NOCLIP || this.move_movetype == MOVETYPE_FLY || this.move_movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this))
1344 else if (this.move_movetype == MOVETYPE_NOCLIP || this.move_movetype == MOVETYPE_FLY || this.move_movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this))
1346 PM_fly(this, maxspeed_mod);
1348 else if (this.waterlevel >= WATERLEVEL_SWIMMING)
1349 PM_swim(this, maxspeed_mod);
1351 else if (time < this.ladder_time)
1352 PM_ladder(this, maxspeed_mod);
1354 else if (ITEMS_STAT(this) & IT_USING_JETPACK)
1355 PM_jetpack(this, maxspeed_mod);
1357 else if (IS_ONGROUND(this))
1358 PM_walk(this, maxspeed_mod);
1361 PM_air(this, buttons_prev, maxspeed_mod);
1364 if (IS_ONGROUND(this))
1365 this.lastground = time;
1367 // conveyors: then break velocity again
1368 if(this.conveyor.state)
1369 this.velocity += this.conveyor.movedir;
1371 this.lastflags = this.flags;
1373 this.lastclassname = this.classname;
1377 void SV_PlayerPhysics(entity this)
1379 void CSQC_ClientMovement_PlayerMove_Frame(entity this)
1385 this.pm_frametime = frametime;