2 #include "../mapobjects/_mod.qh"
3 #include "../viewloc.qh"
7 #include <server/client.qh>
8 #include <common/mapobjects/defs.qh>
9 #include "../mapobjects/trigger/viewloc.qh"
11 // client side physics
12 bool Physics_Valid(string thecvar)
14 return thecvar != "" && thecvar && thecvar != "default" && strhasword(autocvar_g_physics_clientselect_options, thecvar);
17 float Physics_ClientOption(entity this, string option, float defaultval)
19 if(!autocvar_g_physics_clientselect)
22 if(IS_REAL_CLIENT(this) && Physics_Valid(CS(this).cvar_cl_physics))
24 string s = strcat("g_physics_", CS(this).cvar_cl_physics, "_", option);
25 if(cvar_type(s) & CVAR_TYPEFLAG_EXISTS)
28 if(autocvar_g_physics_clientselect_default && autocvar_g_physics_clientselect_default != "" && autocvar_g_physics_clientselect_default != "default")
30 // NOTE: not using Physics_Valid here, so the default can be forced to something normally unavailable
31 string s = strcat("g_physics_", autocvar_g_physics_clientselect_default, "_", option);
32 if(cvar_type(s) & CVAR_TYPEFLAG_EXISTS)
38 void Physics_UpdateStats(entity this)
40 // update this first, as it's used on all stats (wouldn't want to update them all manually from a mutator hook now, would we?)
41 STAT(MOVEVARS_HIGHSPEED, this) = autocvar_g_movement_highspeed;
43 MUTATOR_CALLHOOK(PlayerPhysics_UpdateStats, this);
44 float maxspd_mod = PHYS_HIGHSPEED(this) * ((this.swampslug.active == ACTIVE_ACTIVE) ? this.swampslug.swamp_slowdown : 1);
45 STAT(MOVEVARS_MAXSPEED, this) = Physics_ClientOption(this, "maxspeed", autocvar_sv_maxspeed) * maxspd_mod; // also slow walking
46 if (autocvar_g_movement_highspeed_q3_compat) {
47 STAT(MOVEVARS_AIRACCEL_QW, this) = Physics_ClientOption(this, "airaccel_qw", autocvar_sv_airaccel_qw);
48 STAT(MOVEVARS_AIRSTRAFEACCEL_QW, this) = Physics_ClientOption(this, "airstrafeaccel_qw", autocvar_sv_airstrafeaccel_qw);
49 STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW, this) = Physics_ClientOption(this, "airspeedlimit_nonqw", autocvar_sv_airspeedlimit_nonqw);
51 STAT(MOVEVARS_AIRACCEL_QW, this) = AdjustAirAccelQW(Physics_ClientOption(this, "airaccel_qw", autocvar_sv_airaccel_qw), maxspd_mod);
52 STAT(MOVEVARS_AIRSTRAFEACCEL_QW, this) = (Physics_ClientOption(this, "airstrafeaccel_qw", autocvar_sv_airstrafeaccel_qw))
53 ? AdjustAirAccelQW(Physics_ClientOption(this, "airstrafeaccel_qw", autocvar_sv_airstrafeaccel_qw), maxspd_mod)
55 STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW, this) = Physics_ClientOption(this, "airspeedlimit_nonqw", autocvar_sv_airspeedlimit_nonqw) * maxspd_mod;
57 bool q3dfcompat = autocvar_sv_q3defragcompat && autocvar_sv_q3defragcompat_changehitbox; // NOTE: these hitboxes are off by 1 due to engine differences
58 STAT(PL_MIN, this) = (q3dfcompat) ? '-15 -15 -20' : autocvar_sv_player_mins;
59 STAT(PL_MAX, this) = (q3dfcompat) ? '15 15 36' : autocvar_sv_player_maxs;
60 STAT(PL_VIEW_OFS, this) = (q3dfcompat) ? '0 0 30' : autocvar_sv_player_viewoffset;
61 STAT(PL_CROUCH_MIN, this) = (q3dfcompat) ? '-15 -15 -20' : autocvar_sv_player_crouch_mins;
62 STAT(PL_CROUCH_MAX, this) = (q3dfcompat) ? '15 15 20' : autocvar_sv_player_crouch_maxs;
63 STAT(PL_CROUCH_VIEW_OFS, this) = (q3dfcompat) ? '0 0 16' : autocvar_sv_player_crouch_viewoffset;
66 // fix some new settings
67 STAT(MOVEVARS_AIRACCEL_QW_STRETCHFACTOR, this) = Physics_ClientOption(this, "airaccel_qw_stretchfactor", autocvar_sv_airaccel_qw_stretchfactor);
68 STAT(MOVEVARS_MAXAIRSTRAFESPEED, this) = Physics_ClientOption(this, "maxairstrafespeed", autocvar_sv_maxairstrafespeed);
69 if (autocvar_g_movement_highspeed_q3_compat) {
70 STAT(MOVEVARS_MAXAIRSPEED, this) = Physics_ClientOption(this, "maxairspeed", autocvar_sv_maxairspeed) * maxspd_mod;
72 STAT(MOVEVARS_MAXAIRSPEED, this) = Physics_ClientOption(this, "maxairspeed", autocvar_sv_maxairspeed);
75 STAT(MOVEVARS_AIRSTRAFEACCELERATE, this) = Physics_ClientOption(this, "airstrafeaccelerate", autocvar_sv_airstrafeaccelerate);
76 STAT(MOVEVARS_WARSOWBUNNY_TURNACCEL, this) = Physics_ClientOption(this, "warsowbunny_turnaccel", autocvar_sv_warsowbunny_turnaccel);
77 STAT(MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION, this) = Physics_ClientOption(this, "airaccel_sideways_friction", autocvar_sv_airaccel_sideways_friction);
78 STAT(MOVEVARS_AIRCONTROL, this) = Physics_ClientOption(this, "aircontrol", autocvar_sv_aircontrol);
79 STAT(MOVEVARS_AIRCONTROL_POWER, this) = Physics_ClientOption(this, "aircontrol_power", autocvar_sv_aircontrol_power);
80 STAT(MOVEVARS_AIRCONTROL_BACKWARDS, this) = Physics_ClientOption(this, "aircontrol_backwards", autocvar_sv_aircontrol_backwards);
81 STAT(MOVEVARS_AIRCONTROL_SIDEWARDS, this) = Physics_ClientOption(this, "aircontrol_sidewards", autocvar_sv_aircontrol_sidewards);
82 STAT(MOVEVARS_AIRCONTROL_PENALTY, this) = Physics_ClientOption(this, "aircontrol_penalty", autocvar_sv_aircontrol_penalty);
83 STAT(MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL, this) = Physics_ClientOption(this, "warsowbunny_airforwardaccel", autocvar_sv_warsowbunny_airforwardaccel);
84 STAT(MOVEVARS_WARSOWBUNNY_TOPSPEED, this) = Physics_ClientOption(this, "warsowbunny_topspeed", autocvar_sv_warsowbunny_topspeed);
85 STAT(MOVEVARS_WARSOWBUNNY_ACCEL, this) = Physics_ClientOption(this, "warsowbunny_accel", autocvar_sv_warsowbunny_accel);
86 STAT(MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO, this) = Physics_ClientOption(this, "warsowbunny_backtosideratio", autocvar_sv_warsowbunny_backtosideratio);
87 STAT(MOVEVARS_FRICTION, this) = Physics_ClientOption(this, "friction", autocvar_sv_friction);
88 STAT(MOVEVARS_ACCELERATE, this) = Physics_ClientOption(this, "accelerate", autocvar_sv_accelerate);
89 STAT(MOVEVARS_STOPSPEED, this) = Physics_ClientOption(this, "stopspeed", autocvar_sv_stopspeed);
90 STAT(MOVEVARS_AIRACCELERATE, this) = Physics_ClientOption(this, "airaccelerate", autocvar_sv_airaccelerate);
91 STAT(MOVEVARS_AIRSTOPACCELERATE, this) = Physics_ClientOption(this, "airstopaccelerate", autocvar_sv_airstopaccelerate);
92 STAT(MOVEVARS_JUMPVELOCITY, this) = Physics_ClientOption(this, "jumpvelocity", autocvar_sv_jumpvelocity);
93 STAT(MOVEVARS_JUMPVELOCITY_CROUCH, this) = Physics_ClientOption(this, "jumpvelocity_crouch", autocvar_sv_jumpvelocity_crouch);
94 STAT(MOVEVARS_TRACK_CANJUMP, this) = Physics_ClientOption(this, "track_canjump", autocvar_sv_track_canjump);
96 MUTATOR_CALLHOOK(PlayerPhysics_PostUpdateStats, this, maxspd_mod);
100 float IsMoveInDirection(vector mv, float ang) // key mix factor
102 if (mv_x == 0 && mv_y == 0)
103 return 0; // avoid division by zero
104 ang -= RAD2DEG * atan2(mv_y, mv_x);
105 ang = remainder(ang, 360) / 45;
106 return ang > 1 ? 0 : ang < -1 ? 0 : 1 - fabs(ang);
109 float GeomLerp(float a, float _lerp, float b)
111 return a == 0 ? (_lerp < 1 ? 0 : b)
112 : b == 0 ? (_lerp > 0 ? 0 : a)
113 : a * (fabs(b / a) ** _lerp);
116 void PM_ClientMovement_UpdateStatus(entity this)
121 bool have_hook = false;
122 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
125 entity wepent = viewmodels[slot];
127 .entity weaponentity = weaponentities[slot];
128 entity wepent = this.(weaponentity);
130 if(wepent.hook && !wasfreed(wepent.hook))
136 bool do_crouch = PHYS_INPUT_BUTTON_CROUCH(this);
137 if(this.viewloc && !(this.viewloc.spawnflags & VIEWLOC_FREEMOVE) && PHYS_CS(this).movement.x < 0)
141 //} else if (this.waterlevel >= WATERLEVEL_SWIMMING) {
143 } else if (PHYS_INVEHICLE(this)) {
145 } else if (STAT(FROZEN, this) || IS_DEAD(this)) {
149 MUTATOR_CALLHOOK(PlayerCanCrouch, this, do_crouch);
150 do_crouch = M_ARGV(1, bool);
153 if (!IS_DUCKED(this)) {
155 this.view_ofs = STAT(PL_CROUCH_VIEW_OFS, this);
156 setsize(this, STAT(PL_CROUCH_MIN, this), STAT(PL_CROUCH_MAX, this));
157 // setanim(this, this.anim_duck, false, true, true); // this anim is BROKEN anyway
159 } else if (IS_DUCKED(this)) {
160 tracebox(this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), this.origin, false, this);
161 if (!trace_startsolid) {
163 this.view_ofs = STAT(PL_VIEW_OFS, this);
164 setsize(this, STAT(PL_MIN, this), STAT(PL_MAX, this));
168 _Movetype_CheckWater(this); // needs to be run on the client, might as well use the latest on the server too!
171 void CPM_PM_Aircontrol(entity this, float dt, vector wishdir, float wishspeed)
173 float movity = IsMoveInDirection(PHYS_CS(this).movement, 0);
174 if(PHYS_AIRCONTROL_BACKWARDS(this))
175 movity += IsMoveInDirection(PHYS_CS(this).movement, 180);
176 if(PHYS_AIRCONTROL_SIDEWARDS(this))
178 movity += IsMoveInDirection(PHYS_CS(this).movement, 90);
179 movity += IsMoveInDirection(PHYS_CS(this).movement, -90);
182 float k = 32 * (2 * movity - 1);
186 k *= bound(0, wishspeed / PHYS_MAXAIRSPEED(this), 1);
188 float zspeed = this.velocity_z;
190 float xyspeed = vlen(this.velocity);
191 this.velocity = normalize(this.velocity);
193 float dot = this.velocity * wishdir;
195 if (dot > 0) // we can't change direction while slowing down
197 k *= (dot ** PHYS_AIRCONTROL_POWER(this)) * dt;
198 xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY(this) * sqrt(max(0, 1 - dot*dot)) * k/32);
199 k *= PHYS_AIRCONTROL(this);
200 this.velocity = normalize(this.velocity * xyspeed + wishdir * k);
203 this.velocity = this.velocity * xyspeed;
204 this.velocity_z = zspeed;
207 float AdjustAirAccelQW(float accelqw, float factor)
209 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
212 // example config for alternate speed clamping:
213 // sv_airaccel_qw 0.8
214 // sv_airaccel_sideways_friction 0
215 // prvm_globalset server speedclamp_mode 1
217 void PM_Accelerate(entity this, float dt, vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
219 float speedclamp = stretchfactor > 0 ? stretchfactor
220 : accelqw < 0 ? 1 // full clamping, no stretch
223 accelqw = fabs(accelqw);
225 if (GAMEPLAYFIX_Q2AIRACCELERATE)
226 wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
228 float vel_straight = this.velocity * wishdir;
229 float vel_z = this.velocity_z;
230 vector vel_xy = vec2(this.velocity);
231 vector vel_perpend = vel_xy - vel_straight * wishdir;
233 float step = accel * dt * wishspeed0;
235 float vel_xy_current = vlen(vel_xy);
237 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
238 float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
239 float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
240 vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
241 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
243 if (sidefric < 0 && (vel_perpend*vel_perpend))
244 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
246 float f = max(0, 1 + dt * wishspeed * sidefric);
247 float themin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
248 // assume: themin > 1
249 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
250 // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
251 // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
252 // obviously, this cannot be
257 themin = sqrt(themin);
258 vel_perpend *= max(themin, f);
262 vel_perpend *= max(0, 1 - dt * wishspeed * sidefric);
264 vel_xy = vel_straight * wishdir + vel_perpend;
268 float vel_xy_preclamp;
269 vel_xy_preclamp = vlen(vel_xy);
270 if (vel_xy_preclamp > 0) // prevent division by zero
272 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
273 if (vel_xy_current < vel_xy_preclamp)
274 vel_xy *= (vel_xy_current / vel_xy_preclamp);
278 this.velocity = vel_xy + vel_z * '0 0 1';
281 void PM_AirAccelerate(entity this, float dt, vector wishdir, float wishspeed)
286 vector curvel = this.velocity;
288 float curspeed = vlen(curvel);
290 if (wishspeed > curspeed * 1.01)
291 wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL(this) * PHYS_MAXSPEED(this) * dt);
294 float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED(this) - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED(this) - PHYS_MAXSPEED(this)));
295 wishspeed = max(curspeed, PHYS_MAXSPEED(this)) + PHYS_WARSOWBUNNY_ACCEL(this) * f * PHYS_MAXSPEED(this) * dt;
297 vector wishvel = wishdir * wishspeed;
298 vector acceldir = wishvel - curvel;
299 float addspeed = vlen(acceldir);
300 acceldir = normalize(acceldir);
302 float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL(this) * PHYS_MAXSPEED(this) * dt);
304 if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this) < 1)
306 vector curdir = normalize(curvel);
307 float dot = acceldir * curdir;
309 acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this)) * dot * curdir;
312 this.velocity += accelspeed * acceldir;
320 When you press the jump key
321 returns true if handled
324 bool PlayerJump(entity this)
326 if (PHYS_FROZEN(this))
327 return true; // no jumping in freezetag when frozen
329 if(PHYS_INPUT_BUTTON_CHAT(this) || PHYS_INPUT_BUTTON_MINIGAME(this))
330 return true; // no jumping while typing
333 if (this.player_blocked)
334 return true; // no jumping while blocked
337 bool doublejump = false;
338 float mjumpheight = ((PHYS_JUMPVELOCITY_CROUCH(this) && IS_DUCKED(this)) ? PHYS_JUMPVELOCITY_CROUCH(this) : PHYS_JUMPVELOCITY(this));
339 bool track_jump = PHYS_CL_TRACK_CANJUMP(this);
341 if (MUTATOR_CALLHOOK(PlayerJump, this, mjumpheight, doublejump))
344 mjumpheight = M_ARGV(1, float);
345 doublejump = M_ARGV(2, bool);
347 if (this.waterlevel >= WATERLEVEL_SWIMMING)
357 this.velocity_z = PHYS_MAXSPEED(this) * 0.7;
363 if (!IS_ONGROUND(this))
364 return IS_JUMP_HELD(this);
366 if(PHYS_TRACK_CANJUMP(this))
370 if (IS_JUMP_HELD(this))
373 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
374 // velocity bounds. Final velocity is bound between (jumpheight *
375 // min + jumpheight) and (jumpheight * max + jumpheight);
377 if(PHYS_JUMPSPEEDCAP_MIN != "")
379 float minjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MIN);
381 if (this.velocity_z < minjumpspeed)
382 mjumpheight += minjumpspeed - this.velocity_z;
385 if(PHYS_JUMPSPEEDCAP_MAX != "")
387 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
388 tracebox(this.origin + '0 0 0.01', this.mins, this.maxs, this.origin - '0 0 0.01', MOVE_NORMAL, this);
390 if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS(this)))
392 float maxjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MAX);
394 if (this.velocity_z > maxjumpspeed)
395 mjumpheight -= this.velocity_z - maxjumpspeed;
399 if (!WAS_ONGROUND(this) && !WAS_ONSLICK(this))
402 if(autocvar_speedmeter)
403 LOG_TRACE("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")");
405 if(this.lastground < time - 0.3)
407 float f = (1 - PHYS_FRICTION_ONLAND(this));
408 this.velocity_x *= f;
409 this.velocity_y *= f;
412 if(this.jumppadcount > 1)
413 LOG_TRACE(ftos(this.jumppadcount), "x jumppad combo");
414 this.jumppadcount = 0;
418 this.velocity_z += mjumpheight;
420 UNSET_ONGROUND(this);
425 animdecide_setaction(this, ANIMACTION_JUMP, true);
427 if (autocvar_g_jump_grunt)
428 PlayerSound(this, playersound_jump, CH_PLAYER, VOL_BASE, VOICETYPE_PLAYERSOUND);
433 void CheckWaterJump(entity this)
435 // check for a jump-out-of-water
436 makevectors(this.v_angle);
437 vector start = this.origin;
440 normalize(v_forward);
441 vector end = start + v_forward*24;
442 traceline (start, end, true, this);
443 if (trace_fraction < 1)
445 start_z = start_z + this.maxs_z - 8;
446 end = start + v_forward*24;
447 this.movedir = trace_plane_normal * -50;
448 traceline(start, end, true, this);
449 if (trace_fraction == 1)
450 { // open at eye level
451 this.velocity_z = 225;
452 this.flags |= FL_WATERJUMP;
460 #define JETPACK_JUMP(s) CS(s).cvar_cl_jetpack_jump
462 float autocvar_cl_jetpack_jump;
463 #define JETPACK_JUMP(s) autocvar_cl_jetpack_jump
465 .float jetpack_stopped;
466 void CheckPlayerJump(entity this)
469 bool was_flying = boolean(ITEMS_STAT(this) & IT_USING_JETPACK);
471 if (JETPACK_JUMP(this) < 2)
472 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
474 if(PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this))
476 bool playerjump = PlayerJump(this); // required
478 bool air_jump = !playerjump || M_ARGV(2, bool);
479 bool activate = (JETPACK_JUMP(this) && air_jump && PHYS_INPUT_BUTTON_JUMP(this)) || PHYS_INPUT_BUTTON_JETPACK(this);
480 bool has_fuel = !PHYS_JETPACK_FUEL(this) || PHYS_AMMO_FUEL(this) || (ITEMS_STAT(this) & IT_UNLIMITED_AMMO);
482 if (!(ITEMS_STAT(this) & ITEM_Jetpack.m_itemid)) { }
483 else if (this.jetpack_stopped) { }
487 if (was_flying) // TODO: ran out of fuel message
488 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
490 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
492 this.jetpack_stopped = true;
493 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
495 else if (activate && !PHYS_FROZEN(this))
496 ITEMS_STAT(this) |= IT_USING_JETPACK;
500 this.jetpack_stopped = false;
501 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
503 if (!PHYS_INPUT_BUTTON_JUMP(this))
504 UNSET_JUMP_HELD(this);
506 if (this.waterlevel == WATERLEVEL_SWIMMING)
507 CheckWaterJump(this);
511 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
512 .float specialcommand_pos;
513 void SpecialCommand(entity this)
515 if(autocvar_sv_cheats || this.maycheat)
517 if (!CheatImpulse(this, CHIMPULSE_GIVE_ALL.impulse))
518 LOG_INFO("A hollow voice says \"Plugh\".");
521 STAT(MOVEVARS_SPECIALCOMMAND, this) = true;
525 bool PM_check_specialcommand(entity this, int buttons)
531 else if (buttons == 1)
533 else if (buttons == 2)
535 else if (buttons == 128)
537 else if (buttons == 256)
539 else if (buttons == 512)
541 else if (buttons == 1024)
546 if (c == substring(specialcommand, CS(this).specialcommand_pos, 1))
548 CS(this).specialcommand_pos += 1;
549 if (CS(this).specialcommand_pos >= strlen(specialcommand))
551 CS(this).specialcommand_pos = 0;
552 SpecialCommand(this);
556 else if (CS(this).specialcommand_pos && (c != substring(specialcommand, CS(this).specialcommand_pos - 1, 1)))
557 CS(this).specialcommand_pos = 0;
562 void PM_check_nickspam(entity this)
565 if (time >= this.nickspamtime)
567 if (this.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
569 // slight annoyance for nick change scripts
570 PHYS_CS(this).movement = -1 * PHYS_CS(this).movement;
571 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;
573 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!
575 this.v_angle_x = random() * 360;
576 this.v_angle_y = random() * 360;
577 // at least I'm not forcing retardedview by also assigning to angles_z
578 this.fixangle = true;
584 void PM_check_punch(entity this, float dt)
587 if (this.punchangle != '0 0 0')
589 float f = vlen(this.punchangle) - 10 * dt;
591 this.punchangle = normalize(this.punchangle) * f;
593 this.punchangle = '0 0 0';
596 if (this.punchvector != '0 0 0')
598 float f = vlen(this.punchvector) - 30 * dt;
600 this.punchvector = normalize(this.punchvector) * f;
602 this.punchvector = '0 0 0';
607 // predict frozen movement, as frozen players CAN move in some cases
608 void PM_check_frozen(entity this)
610 if (!PHYS_FROZEN(this))
612 if (PHYS_DODGING_FROZEN(this) && IS_CLIENT(this))
614 // bind movement to a very slow speed so dodging can use .movement for directional calculations
615 PHYS_CS(this).movement_x = bound(-2, PHYS_CS(this).movement.x, 2);
616 PHYS_CS(this).movement_y = bound(-2, PHYS_CS(this).movement.y, 2);
617 PHYS_CS(this).movement_z = bound(-2, PHYS_CS(this).movement.z, 2);
620 PHYS_CS(this).movement = '0 0 0';
623 void PM_check_hitground(entity this)
626 if (!this.wasFlying) return;
627 this.wasFlying = false;
628 if (this.waterlevel >= WATERLEVEL_SWIMMING) return;
629 if (this.ladder_entity) return;
630 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
632 .entity weaponentity = weaponentities[slot];
633 if(this.(weaponentity).hook)
636 this.nextstep = time + 0.3 + random() * 0.1;
637 trace_dphitq3surfaceflags = 0;
638 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
639 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return;
640 entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
643 float vol = ((IS_DUCKED(this)) ? VOL_MUFFLED : VOL_BASE);
644 GlobalSound(this, gs, CH_PLAYER, vol, VOICETYPE_PLAYERSOUND);
648 void PM_Footsteps(entity this)
651 if (!autocvar_g_footsteps) return;
652 if (IS_DUCKED(this)) return;
653 if (time >= this.lastground + 0.2) return;
654 if (vdist(this.velocity, <=, autocvar_sv_maxspeed * 0.6)) return;
655 if ((time > this.nextstep) || (time < (this.nextstep - 10.0)))
657 this.nextstep = time + 0.3 + random() * 0.1;
658 trace_dphitq3surfaceflags = 0;
659 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
660 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return;
661 entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
664 GlobalSound(this, gs, CH_PLAYER, VOL_BASE, VOICETYPE_PLAYERSOUND);
669 void PM_check_slick(entity this)
671 if(!IS_ONGROUND(this))
674 trace_dphitq3surfaceflags = 0;
675 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
676 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK)
682 void PM_check_blocked(entity this)
684 if(PHYS_INPUT_BUTTON_CHAT(this) || PHYS_INPUT_BUTTON_MINIGAME(this))
685 PHYS_CS(this).movement = '0 0 0';
687 if (!this.player_blocked)
689 PHYS_CS(this).movement = '0 0 0';
690 this.disableclientprediction = 1;
694 void PM_jetpack(entity this, float maxspd_mod, float dt)
696 //makevectors(this.v_angle.y * '0 1 0');
697 makevectors(this.v_angle);
698 vector wishvel = v_forward * PHYS_CS(this).movement_x
699 + v_right * PHYS_CS(this).movement_y;
700 // add remaining speed as Z component
701 float maxairspd = PHYS_MAXAIRSPEED(this) * max(1, maxspd_mod);
703 wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
704 // add the unused velocity as up component
707 // if (PHYS_INPUT_BUTTON_JUMP(this))
708 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
710 // it is now normalized, so...
711 float a_side = PHYS_JETPACK_ACCEL_SIDE(this);
712 float a_up = PHYS_JETPACK_ACCEL_UP(this);
713 float a_add = PHYS_JETPACK_ANTIGRAVITY(this) * PHYS_GRAVITY(this);
715 if(PHYS_JETPACK_REVERSE_THRUST(this) && PHYS_INPUT_BUTTON_CROUCH(this)) { a_up = PHYS_JETPACK_REVERSE_THRUST(this); }
722 if(PHYS_JETPACK_REVERSE_THRUST(this) && PHYS_INPUT_BUTTON_CROUCH(this)) { wishvel_z *= -1; }
725 //////////////////////////////////////////////////////////////////////////////////////
726 // finding the maximum over all vectors of above form
727 // with wishvel having an absolute value of 1
728 //////////////////////////////////////////////////////////////////////////////////////
729 // we're finding the maximum over
730 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
731 // for z in the range from -1 to 1
732 //////////////////////////////////////////////////////////////////////////////////////
733 // maximum is EITHER attained at the single extreme point:
734 float a_diff = a_side * a_side - a_up * a_up;
738 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
739 if (f > -1 && f < 1) // can it be attained?
741 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
745 // OR attained at z = 1:
746 f = (a_up + a_add) * (a_up + a_add);
752 // OR attained at z = -1:
753 f = (a_up - a_add) * (a_up - a_add);
760 //////////////////////////////////////////////////////////////////////////////////////
762 //print("best possible acceleration: ", ftos(best), "\n");
765 fxy = bound(0, 1 - (this.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE(this), 1);
766 if (wishvel_z - PHYS_GRAVITY(this) > 0)
767 fz = bound(0, 1 - this.velocity_z / PHYS_JETPACK_MAXSPEED_UP(this), 1);
769 fz = bound(0, 1 + this.velocity_z / PHYS_JETPACK_MAXSPEED_UP(this), 1);
772 fvel = vlen(wishvel);
775 wishvel_z = (wishvel_z - PHYS_GRAVITY(this)) * fz + PHYS_GRAVITY(this);
777 fvel = min(1, vlen(wishvel) / best);
778 if (PHYS_JETPACK_FUEL(this) && !(ITEMS_STAT(this) & IT_UNLIMITED_AMMO))
779 f = min(1, PHYS_AMMO_FUEL(this) / (PHYS_JETPACK_FUEL(this) * dt * fvel));
783 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
785 if (f > 0 && wishvel != '0 0 0')
787 this.velocity = this.velocity + wishvel * f * dt;
788 UNSET_ONGROUND(this);
791 if (!(ITEMS_STAT(this) & IT_UNLIMITED_AMMO))
792 TakeResource(this, RES_FUEL, PHYS_JETPACK_FUEL(this) * dt * fvel * f);
794 ITEMS_STAT(this) |= IT_USING_JETPACK;
796 // jetpack also inhibits health regeneration, but only for 1 second
797 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
802 // used for calculating airshots
803 bool IsFlying(entity this)
805 if(IS_ONGROUND(this))
807 if(this.waterlevel >= WATERLEVEL_SWIMMING)
809 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 24', MOVE_NORMAL, this);
810 //traceline(this.origin, this.origin - '0 0 48', MOVE_NORMAL, this);
811 if(trace_fraction < 1)
817 void sys_phys_update(entity this, float dt);
819 void SV_PlayerPhysics(entity this)
821 void CSQC_ClientMovement_PlayerMove_Frame(entity this)
825 // needs to be called before physics are run!
826 if(IS_REAL_CLIENT(this))
827 PM_UpdateButtons(this, CS(this));
830 sys_phys_update(this, PHYS_INPUT_TIMELENGTH);
833 CS(this).pm_frametime = frametime;
835 if((ITEMS_STAT(this) & IT_USING_JETPACK) && !IS_DEAD(this) && !intermission)
836 this.csqcmodel_modelflags |= MF_ROCKET;
838 this.csqcmodel_modelflags &= ~MF_ROCKET;