3 void sys_phys_fix(entity this, float dt)
5 WarpZone_PlayerPhysics_FixVAngle(this);
6 STAT(MOVEVARS_HIGHSPEED, this) = autocvar_g_movement_highspeed;
7 MUTATOR_CALLHOOK(PlayerPhysics_UpdateStats, this); // do it BEFORE the function so we can modify highspeed!
8 Physics_UpdateStats(this, PHYS_HIGHSPEED(this));
11 bool sys_phys_override(entity this, float dt)
13 int buttons = PHYS_INPUT_BUTTON_MASK(this);
14 float idlesince = CS(this).parm_idlesince;
15 CS(this).parm_idlesince = time; // in the case that physics are overridden
16 if (PM_check_specialcommand(this, buttons)) { return true; }
17 if (this.PlayerPhysplug && this.PlayerPhysplug(this, dt)) { return true; }
18 CS(this).parm_idlesince = idlesince;
22 void sys_phys_monitor(entity this, float dt)
24 int buttons = PHYS_INPUT_BUTTON_MASK(this);
25 anticheat_physics(this);
27 if (buttons != CS(this).buttons_old
28 || CS(this).movement != CS(this).movement_old
29 || this.v_angle != this.v_angle_old) { CS(this).parm_idlesince = time; }
31 PM_check_nickspam(this);
32 PM_check_punch(this, dt);
34 CS(this).buttons_old = PHYS_INPUT_BUTTON_MASK(this);
37 void sys_phys_ai(entity this)
39 if (!IS_BOT_CLIENT(this)) { return; }
40 if (playerdemo_read(this)) { return; }
44 void sys_phys_pregame_hold(entity this)
46 if (!IS_PLAYER(this)) { return; }
47 const bool allowed_to_move = (time >= game_starttime && !game_stopped);
48 if (!allowed_to_move) {
49 this.velocity = '0 0 0';
50 set_movetype(this, MOVETYPE_NONE);
51 this.disableclientprediction = 2;
52 } else if (this.disableclientprediction == 2) {
53 if (this.move_movetype == MOVETYPE_NONE) { set_movetype(this, MOVETYPE_WALK); }
54 this.disableclientprediction = 0;
58 void sys_phys_spectator_control(entity this)
60 float maxspeed_mod = autocvar_sv_spectator_speed_multiplier;
61 if (!this.spectatorspeed) { this.spectatorspeed = maxspeed_mod; }
62 if ((CS(this).impulse >= 1 && CS(this).impulse <= 19)
63 || (CS(this).impulse >= 200 && CS(this).impulse <= 209)
64 || (CS(this).impulse >= 220 && CS(this).impulse <= 229)
66 if (this.lastclassname != STR_PLAYER) {
67 if (CS(this).impulse == 10
68 || CS(this).impulse == 15
69 || CS(this).impulse == 18
70 || (CS(this).impulse >= 200 && CS(this).impulse <= 209)
71 ) { this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5); } else if (CS(this).impulse == 11) {
72 this.spectatorspeed = maxspeed_mod;
73 } else if (CS(this).impulse == 12
74 || CS(this).impulse == 16
75 || CS(this).impulse == 19
76 || (CS(this).impulse >= 220 && CS(this).impulse <= 229)
78 this.spectatorspeed = bound(1, this.spectatorspeed - 0.5, 5);
79 } else if (CS(this).impulse >= 1 && CS(this).impulse <= 9) {
80 this.spectatorspeed = 1 + 0.5 * (CS(this).impulse - 1);
82 } // otherwise just clear
87 void sys_phys_fixspeed(entity this, float maxspeed_mod)
89 float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod;
90 if (this.speed != spd) {
92 string temps = ftos(spd);
93 stuffcmd(this, strcat("cl_forwardspeed ", temps, "\n"));
94 stuffcmd(this, strcat("cl_backspeed ", temps, "\n"));
95 stuffcmd(this, strcat("cl_sidespeed ", temps, "\n"));
96 stuffcmd(this, strcat("cl_upspeed ", temps, "\n"));
99 if (this.jumpspeedcap_min != autocvar_sv_jumpspeedcap_min) {
100 this.jumpspeedcap_min = autocvar_sv_jumpspeedcap_min;
101 stuffcmd(this, sprintf("\ncl_jumpspeedcap_min \"%s\"\n", autocvar_sv_jumpspeedcap_min));
103 if (this.jumpspeedcap_max != autocvar_sv_jumpspeedcap_max) {
104 this.jumpspeedcap_max = autocvar_sv_jumpspeedcap_max;
105 stuffcmd(this, sprintf("\ncl_jumpspeedcap_max \"%s\"\n", autocvar_sv_jumpspeedcap_max));
109 void sys_phys_land(entity this)
111 if (autocvar_speedmeter) {
112 LOG_TRACEF("landing velocity: %v (abs: %f)", this.velocity, vlen(this.velocity));
114 if (this.jumppadcount > 1) {
115 LOG_TRACEF("%dx jumppad combo", this.jumppadcount);
117 this.jumppadcount = 0;
120 STATIC_INIT(sys_phys)
122 entity listener = new_pure(sys_phys);
123 subscribe(listener, phys_land, sys_phys_land);