2 #include "../mapobjects/_mod.qh"
3 #include "../viewloc.qh"
7 #include <server/miscfunctions.qh>
8 #include "../mapobjects/trigger/viewloc.qh"
10 // client side physics
11 bool Physics_Valid(string thecvar)
13 return thecvar != "" && thecvar && thecvar != "default" && strhasword(autocvar_g_physics_clientselect_options, thecvar);
16 float Physics_ClientOption(entity this, string option, float defaultval)
18 if(!autocvar_g_physics_clientselect)
21 if(IS_REAL_CLIENT(this) && Physics_Valid(CS(this).cvar_cl_physics))
23 string s = strcat("g_physics_", CS(this).cvar_cl_physics, "_", option);
24 if(cvar_type(s) & CVAR_TYPEFLAG_EXISTS)
27 if(autocvar_g_physics_clientselect_default && autocvar_g_physics_clientselect_default != "" && autocvar_g_physics_clientselect_default != "default")
29 // NOTE: not using Physics_Valid here, so the default can be forced to something normally unavailable
30 string s = strcat("g_physics_", autocvar_g_physics_clientselect_default, "_", option);
31 if(cvar_type(s) & CVAR_TYPEFLAG_EXISTS)
37 void Physics_UpdateStats(entity this)
39 // 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?)
40 STAT(MOVEVARS_HIGHSPEED, this) = autocvar_g_movement_highspeed;
42 MUTATOR_CALLHOOK(PlayerPhysics_UpdateStats, this);
43 float maxspd_mod = PHYS_HIGHSPEED(this) * ((this.swampslug.active) ? this.swampslug.swamp_slowdown : 1);
44 STAT(MOVEVARS_MAXSPEED, this) = Physics_ClientOption(this, "maxspeed", autocvar_sv_maxspeed) * maxspd_mod; // also slow walking
45 if (autocvar_g_movement_highspeed_q3_compat) {
46 STAT(MOVEVARS_AIRACCEL_QW, this) = Physics_ClientOption(this, "airaccel_qw", autocvar_sv_airaccel_qw);
47 STAT(MOVEVARS_AIRSTRAFEACCEL_QW, this) = Physics_ClientOption(this, "airstrafeaccel_qw", autocvar_sv_airstrafeaccel_qw);
48 STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW, this) = Physics_ClientOption(this, "airspeedlimit_nonqw", autocvar_sv_airspeedlimit_nonqw);
50 STAT(MOVEVARS_AIRACCEL_QW, this) = AdjustAirAccelQW(Physics_ClientOption(this, "airaccel_qw", autocvar_sv_airaccel_qw), maxspd_mod);
51 STAT(MOVEVARS_AIRSTRAFEACCEL_QW, this) = (Physics_ClientOption(this, "airstrafeaccel_qw", autocvar_sv_airstrafeaccel_qw))
52 ? AdjustAirAccelQW(Physics_ClientOption(this, "airstrafeaccel_qw", autocvar_sv_airstrafeaccel_qw), maxspd_mod)
54 STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW, this) = Physics_ClientOption(this, "airspeedlimit_nonqw", autocvar_sv_airspeedlimit_nonqw) * maxspd_mod;
56 bool q3dfcompat = autocvar_sv_q3defragcompat && autocvar_sv_q3defragcompat_changehitbox; // NOTE: these hitboxes are off by 1 due to engine differences
57 STAT(PL_MIN, this) = (q3dfcompat) ? '-15 -15 -20' : autocvar_sv_player_mins;
58 STAT(PL_MAX, this) = (q3dfcompat) ? '15 15 36' : autocvar_sv_player_maxs;
59 STAT(PL_VIEW_OFS, this) = (q3dfcompat) ? '0 0 30' : autocvar_sv_player_viewoffset;
60 STAT(PL_CROUCH_MIN, this) = (q3dfcompat) ? '-15 -15 -20' : autocvar_sv_player_crouch_mins;
61 STAT(PL_CROUCH_MAX, this) = (q3dfcompat) ? '15 15 20' : autocvar_sv_player_crouch_maxs;
62 STAT(PL_CROUCH_VIEW_OFS, this) = (q3dfcompat) ? '0 0 16' : autocvar_sv_player_crouch_viewoffset;
65 // fix some new settings
66 STAT(MOVEVARS_AIRACCEL_QW_STRETCHFACTOR, this) = Physics_ClientOption(this, "airaccel_qw_stretchfactor", autocvar_sv_airaccel_qw_stretchfactor);
67 STAT(MOVEVARS_MAXAIRSTRAFESPEED, this) = Physics_ClientOption(this, "maxairstrafespeed", autocvar_sv_maxairstrafespeed);
68 if (autocvar_g_movement_highspeed_q3_compat) {
69 STAT(MOVEVARS_MAXAIRSPEED, this) = Physics_ClientOption(this, "maxairspeed", autocvar_sv_maxairspeed) * maxspd_mod;
71 STAT(MOVEVARS_MAXAIRSPEED, this) = Physics_ClientOption(this, "maxairspeed", autocvar_sv_maxairspeed);
74 STAT(MOVEVARS_AIRSTRAFEACCELERATE, this) = Physics_ClientOption(this, "airstrafeaccelerate", autocvar_sv_airstrafeaccelerate);
75 STAT(MOVEVARS_WARSOWBUNNY_TURNACCEL, this) = Physics_ClientOption(this, "warsowbunny_turnaccel", autocvar_sv_warsowbunny_turnaccel);
76 STAT(MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION, this) = Physics_ClientOption(this, "airaccel_sideways_friction", autocvar_sv_airaccel_sideways_friction);
77 STAT(MOVEVARS_AIRCONTROL, this) = Physics_ClientOption(this, "aircontrol", autocvar_sv_aircontrol);
78 STAT(MOVEVARS_AIRCONTROL_POWER, this) = Physics_ClientOption(this, "aircontrol_power", autocvar_sv_aircontrol_power);
79 STAT(MOVEVARS_AIRCONTROL_BACKWARDS, this) = Physics_ClientOption(this, "aircontrol_backwards", autocvar_sv_aircontrol_backwards);
80 STAT(MOVEVARS_AIRCONTROL_SIDEWARDS, this) = Physics_ClientOption(this, "aircontrol_sidewards", autocvar_sv_aircontrol_sidewards);
81 STAT(MOVEVARS_AIRCONTROL_PENALTY, this) = Physics_ClientOption(this, "aircontrol_penalty", autocvar_sv_aircontrol_penalty);
82 STAT(MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL, this) = Physics_ClientOption(this, "warsowbunny_airforwardaccel", autocvar_sv_warsowbunny_airforwardaccel);
83 STAT(MOVEVARS_WARSOWBUNNY_TOPSPEED, this) = Physics_ClientOption(this, "warsowbunny_topspeed", autocvar_sv_warsowbunny_topspeed);
84 STAT(MOVEVARS_WARSOWBUNNY_ACCEL, this) = Physics_ClientOption(this, "warsowbunny_accel", autocvar_sv_warsowbunny_accel);
85 STAT(MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO, this) = Physics_ClientOption(this, "warsowbunny_backtosideratio", autocvar_sv_warsowbunny_backtosideratio);
86 STAT(MOVEVARS_FRICTION, this) = Physics_ClientOption(this, "friction", autocvar_sv_friction);
87 STAT(MOVEVARS_ACCELERATE, this) = Physics_ClientOption(this, "accelerate", autocvar_sv_accelerate);
88 STAT(MOVEVARS_STOPSPEED, this) = Physics_ClientOption(this, "stopspeed", autocvar_sv_stopspeed);
89 STAT(MOVEVARS_AIRACCELERATE, this) = Physics_ClientOption(this, "airaccelerate", autocvar_sv_airaccelerate);
90 STAT(MOVEVARS_AIRSTOPACCELERATE, this) = Physics_ClientOption(this, "airstopaccelerate", autocvar_sv_airstopaccelerate);
91 STAT(MOVEVARS_JUMPVELOCITY, this) = Physics_ClientOption(this, "jumpvelocity", autocvar_sv_jumpvelocity);
92 STAT(MOVEVARS_JUMPVELOCITY_CROUCH, this) = Physics_ClientOption(this, "jumpvelocity_crouch", autocvar_sv_jumpvelocity_crouch);
93 STAT(MOVEVARS_TRACK_CANJUMP, this) = Physics_ClientOption(this, "track_canjump", autocvar_sv_track_canjump);
95 MUTATOR_CALLHOOK(PlayerPhysics_PostUpdateStats, this, maxspd_mod);
99 float IsMoveInDirection(vector mv, float ang) // key mix factor
101 if (mv_x == 0 && mv_y == 0)
102 return 0; // avoid division by zero
103 ang -= RAD2DEG * atan2(mv_y, mv_x);
104 ang = remainder(ang, 360) / 45;
105 return ang > 1 ? 0 : ang < -1 ? 0 : 1 - fabs(ang);
108 float GeomLerp(float a, float _lerp, float b)
110 return a == 0 ? (_lerp < 1 ? 0 : b)
111 : b == 0 ? (_lerp > 0 ? 0 : a)
112 : a * (fabs(b / a) ** _lerp);
115 void PM_ClientMovement_UpdateStatus(entity this)
120 bool have_hook = false;
121 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
124 entity wepent = viewmodels[slot];
126 .entity weaponentity = weaponentities[slot];
127 entity wepent = this.(weaponentity);
129 if(wepent.hook && !wasfreed(wepent.hook))
135 bool do_crouch = PHYS_INPUT_BUTTON_CROUCH(this);
136 if(this.viewloc && !(this.viewloc.spawnflags & VIEWLOC_FREEMOVE) && PHYS_CS(this).movement.x < 0)
140 //} else if (this.waterlevel >= WATERLEVEL_SWIMMING) {
142 } else if (PHYS_INVEHICLE(this)) {
144 } else if (STAT(FROZEN, this) || IS_DEAD(this)) {
148 MUTATOR_CALLHOOK(PlayerCanCrouch, this, do_crouch);
149 do_crouch = M_ARGV(1, bool);
152 if (!IS_DUCKED(this)) {
154 this.view_ofs = STAT(PL_CROUCH_VIEW_OFS, this);
155 setsize(this, STAT(PL_CROUCH_MIN, this), STAT(PL_CROUCH_MAX, this));
156 // setanim(this, this.anim_duck, false, true, true); // this anim is BROKEN anyway
158 } else if (IS_DUCKED(this)) {
159 tracebox(this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), this.origin, false, this);
160 if (!trace_startsolid) {
162 this.view_ofs = STAT(PL_VIEW_OFS, this);
163 setsize(this, STAT(PL_MIN, this), STAT(PL_MAX, this));
167 _Movetype_CheckWater(this); // needs to be run on the client, might as well use the latest on the server too!
170 void CPM_PM_Aircontrol(entity this, float dt, vector wishdir, float wishspeed)
172 float movity = IsMoveInDirection(PHYS_CS(this).movement, 0);
173 if(PHYS_AIRCONTROL_BACKWARDS(this))
174 movity += IsMoveInDirection(PHYS_CS(this).movement, 180);
175 if(PHYS_AIRCONTROL_SIDEWARDS(this))
177 movity += IsMoveInDirection(PHYS_CS(this).movement, 90);
178 movity += IsMoveInDirection(PHYS_CS(this).movement, -90);
181 float k = 32 * (2 * movity - 1);
185 k *= bound(0, wishspeed / PHYS_MAXAIRSPEED(this), 1);
187 float zspeed = this.velocity_z;
189 float xyspeed = vlen(this.velocity);
190 this.velocity = normalize(this.velocity);
192 float dot = this.velocity * wishdir;
194 if (dot > 0) // we can't change direction while slowing down
196 k *= (dot ** PHYS_AIRCONTROL_POWER(this)) * dt;
197 xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY(this) * sqrt(max(0, 1 - dot*dot)) * k/32);
198 k *= PHYS_AIRCONTROL(this);
199 this.velocity = normalize(this.velocity * xyspeed + wishdir * k);
202 this.velocity = this.velocity * xyspeed;
203 this.velocity_z = zspeed;
206 float AdjustAirAccelQW(float accelqw, float factor)
208 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
211 // example config for alternate speed clamping:
212 // sv_airaccel_qw 0.8
213 // sv_airaccel_sideways_friction 0
214 // prvm_globalset server speedclamp_mode 1
216 void PM_Accelerate(entity this, float dt, vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
218 float speedclamp = stretchfactor > 0 ? stretchfactor
219 : accelqw < 0 ? 1 // full clamping, no stretch
222 accelqw = fabs(accelqw);
224 if (GAMEPLAYFIX_Q2AIRACCELERATE)
225 wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
227 float vel_straight = this.velocity * wishdir;
228 float vel_z = this.velocity_z;
229 vector vel_xy = vec2(this.velocity);
230 vector vel_perpend = vel_xy - vel_straight * wishdir;
232 float step = accel * dt * wishspeed0;
234 float vel_xy_current = vlen(vel_xy);
236 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
237 float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
238 float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
239 vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
240 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
242 if (sidefric < 0 && (vel_perpend*vel_perpend))
243 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
245 float f = max(0, 1 + dt * wishspeed * sidefric);
246 float themin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
247 // assume: themin > 1
248 // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
249 // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
250 // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
251 // obviously, this cannot be
256 themin = sqrt(themin);
257 vel_perpend *= max(themin, f);
261 vel_perpend *= max(0, 1 - dt * wishspeed * sidefric);
263 vel_xy = vel_straight * wishdir + vel_perpend;
267 float vel_xy_preclamp;
268 vel_xy_preclamp = vlen(vel_xy);
269 if (vel_xy_preclamp > 0) // prevent division by zero
271 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
272 if (vel_xy_current < vel_xy_preclamp)
273 vel_xy *= (vel_xy_current / vel_xy_preclamp);
277 this.velocity = vel_xy + vel_z * '0 0 1';
280 void PM_AirAccelerate(entity this, float dt, vector wishdir, float wishspeed)
285 vector curvel = this.velocity;
287 float curspeed = vlen(curvel);
289 if (wishspeed > curspeed * 1.01)
290 wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL(this) * PHYS_MAXSPEED(this) * dt);
293 float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED(this) - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED(this) - PHYS_MAXSPEED(this)));
294 wishspeed = max(curspeed, PHYS_MAXSPEED(this)) + PHYS_WARSOWBUNNY_ACCEL(this) * f * PHYS_MAXSPEED(this) * dt;
296 vector wishvel = wishdir * wishspeed;
297 vector acceldir = wishvel - curvel;
298 float addspeed = vlen(acceldir);
299 acceldir = normalize(acceldir);
301 float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL(this) * PHYS_MAXSPEED(this) * dt);
303 if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this) < 1)
305 vector curdir = normalize(curvel);
306 float dot = acceldir * curdir;
308 acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO(this)) * dot * curdir;
311 this.velocity += accelspeed * acceldir;
319 When you press the jump key
320 returns true if handled
323 bool PlayerJump(entity this)
325 if (PHYS_FROZEN(this))
326 return true; // no jumping in freezetag when frozen
328 if(PHYS_INPUT_BUTTON_CHAT(this) || PHYS_INPUT_BUTTON_MINIGAME(this))
329 return true; // no jumping while typing
332 if (this.player_blocked)
333 return true; // no jumping while blocked
336 bool doublejump = false;
337 float mjumpheight = ((PHYS_JUMPVELOCITY_CROUCH(this) && IS_DUCKED(this)) ? PHYS_JUMPVELOCITY_CROUCH(this) : PHYS_JUMPVELOCITY(this));
338 bool track_jump = PHYS_CL_TRACK_CANJUMP(this);
340 if (MUTATOR_CALLHOOK(PlayerJump, this, mjumpheight, doublejump))
343 mjumpheight = M_ARGV(1, float);
344 doublejump = M_ARGV(2, bool);
346 if (this.waterlevel >= WATERLEVEL_SWIMMING)
356 this.velocity_z = PHYS_MAXSPEED(this) * 0.7;
362 if (!IS_ONGROUND(this))
363 return IS_JUMP_HELD(this);
365 if(PHYS_TRACK_CANJUMP(this))
369 if (IS_JUMP_HELD(this))
372 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
373 // velocity bounds. Final velocity is bound between (jumpheight *
374 // min + jumpheight) and (jumpheight * max + jumpheight);
376 if(PHYS_JUMPSPEEDCAP_MIN != "")
378 float minjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MIN);
380 if (this.velocity_z < minjumpspeed)
381 mjumpheight += minjumpspeed - this.velocity_z;
384 if(PHYS_JUMPSPEEDCAP_MAX != "")
386 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
387 tracebox(this.origin + '0 0 0.01', this.mins, this.maxs, this.origin - '0 0 0.01', MOVE_NORMAL, this);
389 if (!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS(this)))
391 float maxjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MAX);
393 if (this.velocity_z > maxjumpspeed)
394 mjumpheight -= this.velocity_z - maxjumpspeed;
398 if (!WAS_ONGROUND(this) && !WAS_ONSLICK(this))
401 if(autocvar_speedmeter)
402 LOG_TRACE("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")");
404 if(this.lastground < time - 0.3)
406 float f = (1 - PHYS_FRICTION_ONLAND(this));
407 this.velocity_x *= f;
408 this.velocity_y *= f;
411 if(this.jumppadcount > 1)
412 LOG_TRACE(ftos(this.jumppadcount), "x jumppad combo");
413 this.jumppadcount = 0;
417 this.velocity_z += mjumpheight;
419 UNSET_ONGROUND(this);
425 this.oldvelocity_z = this.velocity_z;
427 animdecide_setaction(this, ANIMACTION_JUMP, true);
429 if (autocvar_g_jump_grunt)
430 PlayerSound(this, playersound_jump, CH_PLAYER, VOL_BASE, VOICETYPE_PLAYERSOUND);
435 void CheckWaterJump(entity this)
437 // check for a jump-out-of-water
438 makevectors(this.v_angle);
439 vector start = this.origin;
442 normalize(v_forward);
443 vector end = start + v_forward*24;
444 traceline (start, end, true, this);
445 if (trace_fraction < 1)
447 start_z = start_z + this.maxs_z - 8;
448 end = start + v_forward*24;
449 this.movedir = trace_plane_normal * -50;
450 traceline(start, end, true, this);
451 if (trace_fraction == 1)
452 { // open at eye level
453 this.velocity_z = 225;
454 this.flags |= FL_WATERJUMP;
462 #define JETPACK_JUMP(s) CS(s).cvar_cl_jetpack_jump
464 float autocvar_cl_jetpack_jump;
465 #define JETPACK_JUMP(s) autocvar_cl_jetpack_jump
467 .float jetpack_stopped;
468 void CheckPlayerJump(entity this)
471 bool was_flying = boolean(ITEMS_STAT(this) & IT_USING_JETPACK);
473 if (JETPACK_JUMP(this) < 2)
474 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
476 if(PHYS_INPUT_BUTTON_JUMP(this) || PHYS_INPUT_BUTTON_JETPACK(this))
478 bool playerjump = PlayerJump(this); // required
480 bool air_jump = !playerjump || M_ARGV(2, bool);
481 bool activate = (JETPACK_JUMP(this) && air_jump && PHYS_INPUT_BUTTON_JUMP(this)) || PHYS_INPUT_BUTTON_JETPACK(this);
482 bool has_fuel = !PHYS_JETPACK_FUEL(this) || PHYS_AMMO_FUEL(this) || (ITEMS_STAT(this) & IT_UNLIMITED_AMMO);
484 if (!(ITEMS_STAT(this) & ITEM_Jetpack.m_itemid)) { }
485 else if (this.jetpack_stopped) { }
489 if (was_flying) // TODO: ran out of fuel message
490 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
492 Send_Notification(NOTIF_ONE, this, MSG_INFO, INFO_JETPACK_NOFUEL);
494 this.jetpack_stopped = true;
495 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
497 else if (activate && !PHYS_FROZEN(this))
498 ITEMS_STAT(this) |= IT_USING_JETPACK;
502 this.jetpack_stopped = false;
503 ITEMS_STAT(this) &= ~IT_USING_JETPACK;
505 if (!PHYS_INPUT_BUTTON_JUMP(this))
506 UNSET_JUMP_HELD(this);
508 if (this.waterlevel == WATERLEVEL_SWIMMING)
509 CheckWaterJump(this);
513 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
514 .float specialcommand_pos;
515 void SpecialCommand(entity this)
517 if(autocvar_sv_cheats || this.maycheat)
519 if (!CheatImpulse(this, CHIMPULSE_GIVE_ALL.impulse))
520 LOG_INFO("A hollow voice says \"Plugh\".");
523 STAT(MOVEVARS_SPECIALCOMMAND, this) = true;
527 bool PM_check_specialcommand(entity this, int buttons)
533 else if (buttons == 1)
535 else if (buttons == 2)
537 else if (buttons == 128)
539 else if (buttons == 256)
541 else if (buttons == 512)
543 else if (buttons == 1024)
548 if (c == substring(specialcommand, CS(this).specialcommand_pos, 1))
550 CS(this).specialcommand_pos += 1;
551 if (CS(this).specialcommand_pos >= strlen(specialcommand))
553 CS(this).specialcommand_pos = 0;
554 SpecialCommand(this);
558 else if (CS(this).specialcommand_pos && (c != substring(specialcommand, CS(this).specialcommand_pos - 1, 1)))
559 CS(this).specialcommand_pos = 0;
564 void PM_check_nickspam(entity this)
567 if (time >= this.nickspamtime)
569 if (this.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
571 // slight annoyance for nick change scripts
572 PHYS_CS(this).movement = -1 * PHYS_CS(this).movement;
573 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;
575 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!
577 this.v_angle_x = random() * 360;
578 this.v_angle_y = random() * 360;
579 // at least I'm not forcing retardedview by also assigning to angles_z
580 this.fixangle = true;
586 void PM_check_punch(entity this, float dt)
589 if (this.punchangle != '0 0 0')
591 float f = vlen(this.punchangle) - 10 * dt;
593 this.punchangle = normalize(this.punchangle) * f;
595 this.punchangle = '0 0 0';
598 if (this.punchvector != '0 0 0')
600 float f = vlen(this.punchvector) - 30 * dt;
602 this.punchvector = normalize(this.punchvector) * f;
604 this.punchvector = '0 0 0';
609 // predict frozen movement, as frozen players CAN move in some cases
610 void PM_check_frozen(entity this)
612 if (!PHYS_FROZEN(this))
614 if (PHYS_DODGING_FROZEN(this) && IS_CLIENT(this))
616 // bind movement to a very slow speed so dodging can use .movement for directional calculations
617 PHYS_CS(this).movement_x = bound(-2, PHYS_CS(this).movement.x, 2);
618 PHYS_CS(this).movement_y = bound(-2, PHYS_CS(this).movement.y, 2);
619 PHYS_CS(this).movement_z = bound(-2, PHYS_CS(this).movement.z, 2);
622 PHYS_CS(this).movement = '0 0 0';
625 void PM_check_hitground(entity this)
628 if (!this.wasFlying) return;
629 this.wasFlying = false;
630 if (this.waterlevel >= WATERLEVEL_SWIMMING) return;
631 if (time < this.ladder_time) return;
632 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
634 .entity weaponentity = weaponentities[slot];
635 if(this.(weaponentity).hook)
638 this.nextstep = time + 0.3 + random() * 0.1;
639 trace_dphitq3surfaceflags = 0;
640 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
641 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return;
642 entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
645 float vol = ((IS_DUCKED(this)) ? VOL_MUFFLED : VOL_BASE);
646 GlobalSound(this, gs, CH_PLAYER, vol, VOICETYPE_PLAYERSOUND);
650 void PM_Footsteps(entity this)
653 if (!g_footsteps) return;
654 if (IS_DUCKED(this)) return;
655 if (time >= this.lastground + 0.2) return;
656 if (vdist(this.velocity, <=, autocvar_sv_maxspeed * 0.6)) return;
657 if ((time > this.nextstep) || (time < (this.nextstep - 10.0)))
659 this.nextstep = time + 0.3 + random() * 0.1;
660 trace_dphitq3surfaceflags = 0;
661 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
662 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return;
663 entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
666 GlobalSound(this, gs, CH_PLAYER, VOL_BASE, VOICETYPE_PLAYERSOUND);
671 void PM_check_slick(entity this)
673 if(!IS_ONGROUND(this))
676 trace_dphitq3surfaceflags = 0;
677 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
678 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK)
684 void PM_check_blocked(entity this)
686 if(PHYS_INPUT_BUTTON_CHAT(this) || PHYS_INPUT_BUTTON_MINIGAME(this))
687 PHYS_CS(this).movement = '0 0 0';
689 if (!this.player_blocked)
691 PHYS_CS(this).movement = '0 0 0';
692 this.disableclientprediction = 1;
696 void PM_jetpack(entity this, float maxspd_mod, float dt)
698 //makevectors(this.v_angle.y * '0 1 0');
699 makevectors(this.v_angle);
700 vector wishvel = v_forward * PHYS_CS(this).movement_x
701 + v_right * PHYS_CS(this).movement_y;
702 // add remaining speed as Z component
703 float maxairspd = PHYS_MAXAIRSPEED(this) * max(1, maxspd_mod);
705 wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
706 // add the unused velocity as up component
709 // if (PHYS_INPUT_BUTTON_JUMP(this))
710 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
712 // it is now normalized, so...
713 float a_side = PHYS_JETPACK_ACCEL_SIDE(this);
714 float a_up = PHYS_JETPACK_ACCEL_UP(this);
715 float a_add = PHYS_JETPACK_ANTIGRAVITY(this) * PHYS_GRAVITY(this);
717 if(PHYS_JETPACK_REVERSE_THRUST(this) && PHYS_INPUT_BUTTON_CROUCH(this)) { a_up = PHYS_JETPACK_REVERSE_THRUST(this); }
724 if(PHYS_JETPACK_REVERSE_THRUST(this) && PHYS_INPUT_BUTTON_CROUCH(this)) { wishvel_z *= -1; }
727 //////////////////////////////////////////////////////////////////////////////////////
728 // finding the maximum over all vectors of above form
729 // with wishvel having an absolute value of 1
730 //////////////////////////////////////////////////////////////////////////////////////
731 // we're finding the maximum over
732 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
733 // for z in the range from -1 to 1
734 //////////////////////////////////////////////////////////////////////////////////////
735 // maximum is EITHER attained at the single extreme point:
736 float a_diff = a_side * a_side - a_up * a_up;
740 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
741 if (f > -1 && f < 1) // can it be attained?
743 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
747 // OR attained at z = 1:
748 f = (a_up + a_add) * (a_up + a_add);
754 // OR attained at z = -1:
755 f = (a_up - a_add) * (a_up - a_add);
762 //////////////////////////////////////////////////////////////////////////////////////
764 //print("best possible acceleration: ", ftos(best), "\n");
767 fxy = bound(0, 1 - (this.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE(this), 1);
768 if (wishvel_z - PHYS_GRAVITY(this) > 0)
769 fz = bound(0, 1 - this.velocity_z / PHYS_JETPACK_MAXSPEED_UP(this), 1);
771 fz = bound(0, 1 + this.velocity_z / PHYS_JETPACK_MAXSPEED_UP(this), 1);
774 fvel = vlen(wishvel);
777 wishvel_z = (wishvel_z - PHYS_GRAVITY(this)) * fz + PHYS_GRAVITY(this);
779 fvel = min(1, vlen(wishvel) / best);
780 if (PHYS_JETPACK_FUEL(this) && !(ITEMS_STAT(this) & IT_UNLIMITED_AMMO))
781 f = min(1, PHYS_AMMO_FUEL(this) / (PHYS_JETPACK_FUEL(this) * dt * fvel));
785 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
787 if (f > 0 && wishvel != '0 0 0')
789 this.velocity = this.velocity + wishvel * f * dt;
790 UNSET_ONGROUND(this);
793 if (!(ITEMS_STAT(this) & IT_UNLIMITED_AMMO))
794 TakeResource(this, RES_FUEL, PHYS_JETPACK_FUEL(this) * dt * fvel * f);
796 ITEMS_STAT(this) |= IT_USING_JETPACK;
798 // jetpack also inhibits health regeneration, but only for 1 second
799 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
804 // used for calculating airshots
805 bool IsFlying(entity this)
807 if(IS_ONGROUND(this))
809 if(this.waterlevel >= WATERLEVEL_SWIMMING)
811 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 24', MOVE_NORMAL, this);
812 //traceline(this.origin, this.origin - '0 0 48', MOVE_NORMAL, this);
813 if(trace_fraction < 1)
819 void sys_phys_update(entity this, float dt);
821 void SV_PlayerPhysics(entity this)
823 void CSQC_ClientMovement_PlayerMove_Frame(entity this)
827 // needs to be called before physics are run!
828 if(IS_REAL_CLIENT(this))
829 PM_UpdateButtons(this, CS(this));
832 sys_phys_update(this, PHYS_INPUT_TIMELENGTH);
835 CS(this).pm_frametime = frametime;
837 if((ITEMS_STAT(this) & IT_USING_JETPACK) && !IS_DEAD(this) && !intermission)
838 this.csqcmodel_modelflags |= MF_ROCKET;
840 this.csqcmodel_modelflags &= ~MF_ROCKET;