]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/ecs/systems/sv_physics.qc
Port buttons_old to ClientState
[xonotic/xonotic-data.pk3dir.git] / qcsrc / ecs / systems / sv_physics.qc
1 #include "physics.qh"
2
3 void sys_phys_fix(entity this, float dt)
4 {
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));
9 }
10
11 bool sys_phys_override(entity this, float dt)
12 {
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;
19         return false;
20 }
21
22 void sys_phys_monitor(entity this, float dt)
23 {
24         int buttons = PHYS_INPUT_BUTTON_MASK(this);
25         anticheat_physics(this);
26         if (sv_maxidle > 0) {
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; }
30         }
31         PM_check_nickspam(this);
32         PM_check_punch(this, dt);
33
34         CS(this).buttons_old = PHYS_INPUT_BUTTON_MASK(this);
35 }
36
37 void sys_phys_ai(entity this)
38 {
39         if (!IS_BOT_CLIENT(this)) { return; }
40         if (playerdemo_read(this)) { return; }
41         bot_think(this);
42 }
43
44 void sys_phys_pregame_hold(entity this)
45 {
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;
55         }
56 }
57
58 void sys_phys_spectator_control(entity this)
59 {
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)
65            ) {
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)
77                                   ) {
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);
81                         }
82                 }  // otherwise just clear
83                 CS(this).impulse = 0;
84         }
85 }
86
87 void sys_phys_fixspeed(entity this, float maxspeed_mod)
88 {
89         float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod;
90         if (this.speed != spd) {
91                 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"));
97         }
98
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));
102         }
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));
106         }
107 }
108
109 void sys_phys_land(entity this)
110 {
111         if (autocvar_speedmeter) {
112                 LOG_TRACEF("landing velocity: %v (abs: %f)", this.velocity, vlen(this.velocity));
113         }
114         if (this.jumppadcount > 1) {
115                 LOG_TRACEF("%dx jumppad combo", this.jumppadcount);
116         }
117         this.jumppadcount = 0;
118 }
119
120 STATIC_INIT(sys_phys)
121 {
122         entity listener = new_pure(sys_phys);
123         subscribe(listener, phys_land, sys_phys_land);
124 }