]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/ecs/systems/sv_physics.qc
4973a182973a0f002b77691a8f93ba8133da09da
[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, float dt)
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, dt)) { return true; }
14         return false;
15 }
16
17 void sys_phys_monitor(entity this, float dt)
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, dt);
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 && !gameover);
41         if (!allowed_to_move) {
42                 this.velocity = '0 0 0';
43                 set_movetype(this, MOVETYPE_NONE);
44                 this.disableclientprediction = 2;
45         } else if (this.disableclientprediction == 2) {
46                 if (this.move_movetype == MOVETYPE_NONE) { set_movetype(this, 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); } else if (this.impulse == 11) {
65                                 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                                   ) {
71                                 this.spectatorspeed = bound(1, this.spectatorspeed - 0.5, 5);
72                         } else if (this.impulse >= 1 && this.impulse <= 9) {
73                                 this.spectatorspeed = 1 + 0.5 * (this.impulse - 1);
74                         }
75                 }  // otherwise just clear
76                 this.impulse = 0;
77         }
78 }
79
80 void sys_phys_fixspeed(entity this, float maxspeed_mod)
81 {
82         float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod;
83         if (this.speed != spd) {
84                 this.speed = spd;
85                 string temps = ftos(spd);
86                 stuffcmd(this, strcat("cl_forwardspeed ", temps, "\n"));
87                 stuffcmd(this, strcat("cl_backspeed ", temps, "\n"));
88                 stuffcmd(this, strcat("cl_sidespeed ", temps, "\n"));
89                 stuffcmd(this, strcat("cl_upspeed ", temps, "\n"));
90         }
91
92         if (this.jumpspeedcap_min != autocvar_sv_jumpspeedcap_min) {
93                 this.jumpspeedcap_min = autocvar_sv_jumpspeedcap_min;
94                 stuffcmd(this, sprintf("\ncl_jumpspeedcap_min \"%s\"\n", autocvar_sv_jumpspeedcap_min));
95         }
96         if (this.jumpspeedcap_max != autocvar_sv_jumpspeedcap_max) {
97                 this.jumpspeedcap_max = autocvar_sv_jumpspeedcap_max;
98                 stuffcmd(this, sprintf("\ncl_jumpspeedcap_max \"%s\"\n", autocvar_sv_jumpspeedcap_max));
99         }
100 }
101
102 void sys_phys_land(entity this)
103 {
104         if (autocvar_speedmeter) {
105                 LOG_TRACEF("landing velocity: %v (abs: %f)", this.velocity, vlen(this.velocity));
106         }
107         if (this.jumppadcount > 1) {
108                 LOG_TRACEF("%dx jumppad combo", this.jumppadcount);
109         }
110         this.jumppadcount = 0;
111 }
112
113 STATIC_INIT(sys_phys)
114 {
115         entity listener = new_pure(sys_phys);
116         subscribe(listener, phys_land, sys_phys_land);
117 }