]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/ecs/systems/sv_physics.qc
Merge branch 'martin-t/angles' into 'master'
[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);
7 }
8
9 bool sys_phys_override(entity this, float dt)
10 {
11         int buttons = PHYS_INPUT_BUTTON_MASK(this);
12         float idlesince = CS(this).parm_idlesince;
13         CS(this).parm_idlesince = time; // in the case that physics are overridden
14         if (PM_check_specialcommand(this, buttons)) { return true; }
15         if (this.PlayerPhysplug && this.PlayerPhysplug(this, dt)) { return true; }
16         CS(this).parm_idlesince = idlesince;
17         return false;
18 }
19
20 void sys_phys_monitor(entity this, float dt)
21 {
22         int buttons = PHYS_INPUT_BUTTON_MASK(this);
23         anticheat_physics(this);
24         if (sv_maxidle > 0) {
25                 if (buttons != CS(this).buttons_old
26                     || CS(this).movement != CS(this).movement_old
27                     || this.v_angle != CS(this).v_angle_old) { CS(this).parm_idlesince = time; }
28         }
29         PM_check_nickspam(this);
30         PM_check_punch(this, dt);
31 }
32
33 void sys_phys_ai(entity this)
34 {
35         if (!IS_BOT_CLIENT(this)) { return; }
36         if (playerdemo_read(this)) { return; }
37         bot_think(this);
38 }
39
40 void sys_phys_pregame_hold(entity this)
41 {
42         if (!IS_PLAYER(this)) { return; }
43         const bool allowed_to_move = (time >= game_starttime && !game_stopped);
44         if (!allowed_to_move) {
45                 this.velocity = '0 0 0';
46                 set_movetype(this, MOVETYPE_NONE);
47                 this.disableclientprediction = 2;
48         } else if (this.disableclientprediction == 2) {
49                 if (this.move_movetype == MOVETYPE_NONE) { set_movetype(this, MOVETYPE_WALK); }
50                 this.disableclientprediction = 0;
51         }
52 }
53
54 void sys_phys_spectator_control(entity this)
55 {
56         float maxspeed_mod = autocvar_sv_spectator_speed_multiplier;
57         if (!this.spectatorspeed) { this.spectatorspeed = maxspeed_mod; }
58         if ((CS(this).impulse >= 1 && CS(this).impulse <= 19)
59             || (CS(this).impulse >= 200 && CS(this).impulse <= 209)
60             || (CS(this).impulse >= 220 && CS(this).impulse <= 229)
61            ) {
62                 if (this.lastclassname != STR_PLAYER) {
63                         if (CS(this).impulse == 10
64                             || CS(this).impulse == 15
65                             || CS(this).impulse == 18
66                             || (CS(this).impulse >= 200 && CS(this).impulse <= 209)
67                            ) { this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5); } else if (CS(this).impulse == 11) {
68                                 this.spectatorspeed = maxspeed_mod;
69                         } else if (CS(this).impulse == 12
70                             || CS(this).impulse == 16
71                             || CS(this).impulse == 19
72                             || (CS(this).impulse >= 220 && CS(this).impulse <= 229)
73                                   ) {
74                                 this.spectatorspeed = bound(1, this.spectatorspeed - 0.5, 5);
75                         } else if (CS(this).impulse >= 1 && CS(this).impulse <= 9) {
76                                 this.spectatorspeed = 1 + 0.5 * (CS(this).impulse - 1);
77                         }
78                 }  // otherwise just clear
79                 CS(this).impulse = 0;
80         }
81 }
82
83 void sys_phys_fixspeed(entity this, float maxspeed_mod)
84 {
85         float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod;
86         if (this.speed != spd) {
87                 this.speed = spd;
88                 string temps = ftos(spd);
89                 stuffcmd(this, strcat("cl_forwardspeed ", temps, "\n"));
90                 stuffcmd(this, strcat("cl_backspeed ", temps, "\n"));
91                 stuffcmd(this, strcat("cl_sidespeed ", temps, "\n"));
92                 stuffcmd(this, strcat("cl_upspeed ", temps, "\n"));
93         }
94
95         if (this.jumpspeedcap_min != autocvar_sv_jumpspeedcap_min) {
96                 this.jumpspeedcap_min = autocvar_sv_jumpspeedcap_min;
97                 stuffcmd(this, sprintf("\ncl_jumpspeedcap_min \"%s\"\n", autocvar_sv_jumpspeedcap_min));
98         }
99         if (this.jumpspeedcap_max != autocvar_sv_jumpspeedcap_max) {
100                 this.jumpspeedcap_max = autocvar_sv_jumpspeedcap_max;
101                 stuffcmd(this, sprintf("\ncl_jumpspeedcap_max \"%s\"\n", autocvar_sv_jumpspeedcap_max));
102         }
103 }
104
105 void sys_phys_land(entity this)
106 {
107         if (autocvar_speedmeter) {
108                 LOG_TRACEF("landing velocity: %v (abs: %f)", this.velocity, vlen(this.velocity));
109         }
110         if (this.jumppadcount > 1) {
111                 LOG_TRACEF("%dx jumppad combo", this.jumppadcount);
112         }
113         this.jumppadcount = 0;
114 }
115
116 STATIC_INIT(sys_phys)
117 {
118         entity listener = new_pure(sys_phys);
119         subscribe(listener, phys_land, sys_phys_land);
120 }