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