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