]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/ecs/systems/physics.qc
Move PM_Main to ecs
[xonotic/xonotic-data.pk3dir.git] / qcsrc / ecs / systems / physics.qc
1 #include "physics.qh"
2 #include "input.qh"
3
4 .int disableclientprediction;
5
6 void sys_phys_update(entity this, float dt)
7 {
8         sys_in_update(this, dt);
9
10         sys_phys_fix(this, dt);
11         if (sys_phys_override(this)) return;
12         sys_phys_monitor(this);
13
14         int buttons_prev = this.buttons_old;
15         this.buttons_old = PHYS_INPUT_BUTTON_MASK(this);
16         this.movement_old = this.movement;
17         this.v_angle_old = this.v_angle;
18
19         sys_phys_ai(this);
20
21         sys_phys_pregame_hold(this);
22
23         if (IS_SVQC) {
24                 if (PHYS_MOVETYPE(this) == MOVETYPE_NONE) return;
25
26                 // when we get here, disableclientprediction cannot be 2
27                 this.disableclientprediction = 0;
28         }
29
30         viewloc_PlayerPhysics(this);
31
32         PM_check_frozen(this);
33
34         PM_check_blocked(this);
35
36         float maxspeed_mod = (!this.in_swamp) ? 1 : this.swamp_slowdown; // cvar("g_balance_swamp_moverate");
37
38 // conveyors: first fix velocity
39         if (this.conveyor.state) this.velocity -= this.conveyor.movedir;
40
41         MUTATOR_CALLHOOK(PlayerPhysics, this);
42
43         if (!IS_PLAYER(this)) {
44                 sys_phys_spectator_control(this);
45                 maxspeed_mod = this.spectatorspeed;
46         }
47         sys_phys_fixspeed(this, maxspeed_mod);
48
49         if (IS_DEAD(this)) {
50                 // handle water here
51                 vector midpoint = ((this.absmin + this.absmax) * 0.5);
52                 if (pointcontents(midpoint) == CONTENT_WATER) {
53                         this.velocity = this.velocity * 0.5;
54
55                         // do we want this?
56                         // if(pointcontents(midpoint + '0 0 2') == CONTENT_WATER)
57                         // { this.velocity_z = 70; }
58                 }
59                 goto end;
60         }
61
62         if (IS_SVQC && !PHYS_FIXANGLE(this)) this.angles = '0 1 0' * this.v_angle.y;
63
64         if (IS_PLAYER(this)) {
65                 if (IS_ONGROUND(this)) {
66                         PM_check_hitground(this);
67                         PM_Footsteps(this);
68                 } else if (IsFlying(this)) {
69                         this.wasFlying = true;
70                 }
71                 CheckPlayerJump(this);
72         }
73
74         if (this.flags & FL_WATERJUMP) {
75                 this.velocity_x = this.movedir.x;
76                 this.velocity_y = this.movedir.y;
77                 if (time > PHYS_TELEPORT_TIME(this)
78                     || this.waterlevel == WATERLEVEL_NONE
79                     || PHYS_WATERJUMP_TIME(this) <= 0
80                    ) {
81                         this.flags &= ~FL_WATERJUMP;
82                         PHYS_TELEPORT_TIME(this) = 0;
83                         PHYS_WATERJUMP_TIME(this) = 0;
84                 }
85         } else if (MUTATOR_CALLHOOK(PM_Physics, this, maxspeed_mod)) {
86                 // handled
87         } else if (PHYS_MOVETYPE(this) == MOVETYPE_NOCLIP
88             || PHYS_MOVETYPE(this) == MOVETYPE_FLY
89             || PHYS_MOVETYPE(this) == MOVETYPE_FLY_WORLDONLY
90             || MUTATOR_CALLHOOK(IsFlying, this)) {
91                 PM_fly(this, maxspeed_mod);
92         } else if (this.waterlevel >= WATERLEVEL_SWIMMING) {
93                 PM_swim(this, maxspeed_mod);
94         } else if (time < this.ladder_time) {
95                 PM_ladder(this, maxspeed_mod);
96         } else if (ITEMS_STAT(this) & IT_USING_JETPACK) {
97                 PM_jetpack(this, maxspeed_mod);
98         } else if (IS_ONGROUND(this)) {
99                 PM_walk(this, maxspeed_mod);
100         } else {
101                 PM_air(this, buttons_prev, maxspeed_mod);
102         }
103
104         LABEL(end)
105         if (IS_ONGROUND(this)) this.lastground = time;
106
107 // conveyors: then break velocity again
108         if (this.conveyor.state) this.velocity += this.conveyor.movedir;
109
110         this.lastflags = this.flags;
111
112         this.lastclassname = this.classname;
113 }