]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/ecs/systems/sv_physics.qc
Move PM_Main to ecs
[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         Physics_UpdateStats(this, PHYS_HIGHSPEED(this));
7 }
8
9 bool sys_phys_override(entity this)
10 {
11         int buttons = PHYS_INPUT_BUTTON_MASK(this);
12         if (PM_check_specialcommand(this, buttons)) return true;
13         if (this.PlayerPhysplug && this.PlayerPhysplug(this)) return true;
14         return false;
15 }
16
17 void sys_phys_monitor(entity this)
18 {
19         int buttons = PHYS_INPUT_BUTTON_MASK(this);
20         anticheat_physics(this);
21         if (sv_maxidle > 0) {
22                 if (buttons != this.buttons_old
23                     || this.movement != this.movement_old
24                     || this.v_angle != this.v_angle_old) this.parm_idlesince = time;
25         }
26         PM_check_nickspam(this);
27         PM_check_punch(this);
28 }
29
30 void sys_phys_ai(entity this)
31 {
32         if (!IS_BOT_CLIENT(this)) return;
33         if (playerdemo_read(this)) return;
34         bot_think(this);
35 }
36
37 void sys_phys_pregame_hold(entity this)
38 {
39         if (!IS_PLAYER(this)) return;
40         const bool allowed_to_move = (time >= game_starttime);
41         if (!allowed_to_move) {
42                 this.velocity = '0 0 0';
43                 this.movetype = MOVETYPE_NONE;
44                 this.disableclientprediction = 2;
45         } else if (this.disableclientprediction == 2) {
46                 if (this.movetype == MOVETYPE_NONE) this.movetype = MOVETYPE_WALK;
47                 this.disableclientprediction = 0;
48         }
49 }
50
51 void sys_phys_spectator_control(entity this)
52 {
53         float maxspeed_mod = autocvar_sv_spectator_speed_multiplier;
54         if (!this.spectatorspeed) this.spectatorspeed = maxspeed_mod;
55         if ((this.impulse >= 1 && this.impulse <= 19)
56             || (this.impulse >= 200 && this.impulse <= 209)
57             || (this.impulse >= 220 && this.impulse <= 229)
58            ) {
59                 if (this.lastclassname != STR_PLAYER) {
60                         if (this.impulse == 10
61                             || this.impulse == 15
62                             || this.impulse == 18
63                             || (this.impulse >= 200 && this.impulse <= 209)
64                            ) this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5);
65                         else if (this.impulse == 11) this.spectatorspeed = maxspeed_mod;
66                         else if (this.impulse == 12
67                             || this.impulse == 16
68                             || this.impulse == 19
69                             || (this.impulse >= 220 && this.impulse <= 229)
70                                 ) this.spectatorspeed = bound(1, this.spectatorspeed - 0.5, 5);
71                         else if (this.impulse >= 1 && this.impulse <= 9) this.spectatorspeed = 1 + 0.5 * (this.impulse - 1);
72                 }  // otherwise just clear
73                 this.impulse = 0;
74         }
75 }
76
77 void sys_phys_fixspeed(entity this, float maxspeed_mod)
78 {
79         float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod;
80         if (this.speed != spd) {
81                 this.speed = spd;
82                 string temps = ftos(spd);
83                 stuffcmd(this, strcat("cl_forwardspeed ", temps, "\n"));
84                 stuffcmd(this, strcat("cl_backspeed ", temps, "\n"));
85                 stuffcmd(this, strcat("cl_sidespeed ", temps, "\n"));
86                 stuffcmd(this, strcat("cl_upspeed ", temps, "\n"));
87         }
88
89         if (this.jumpspeedcap_min != autocvar_sv_jumpspeedcap_min) {
90                 this.jumpspeedcap_min = autocvar_sv_jumpspeedcap_min;
91                 stuffcmd(this, sprintf("\ncl_jumpspeedcap_min \"%s\"\n", autocvar_sv_jumpspeedcap_min));
92         }
93         if (this.jumpspeedcap_max != autocvar_sv_jumpspeedcap_max) {
94                 this.jumpspeedcap_max = autocvar_sv_jumpspeedcap_max;
95                 stuffcmd(this, sprintf("\ncl_jumpspeedcap_max \"%s\"\n", autocvar_sv_jumpspeedcap_max));
96         }
97 }