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