0169011c0d844ea28f2cbc5b119897c88f2bf329
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / physics.qh
1 #ifndef COMMON_PHYSICS_H
2 #define COMMON_PHYSICS_H
3
4 // Client/server mappings
5
6 .entity conveyor;
7
8 .float race_penalty;
9
10 .float gravity;
11 .float swamp_slowdown;
12 .float lastflags;
13 .float lastground;
14 .float wasFlying;
15 .float spectatorspeed;
16
17 .vector movement_old;
18 .float buttons_old;
19 .vector v_angle_old;
20 .string lastclassname;
21
22 .float() PlayerPhysplug;
23 float AdjustAirAccelQW(float accelqw, float factor);
24
25 bool IsFlying(entity a);
26
27 #define BUFFS_STAT(s)                       STAT(BUFFS, s)
28
29 #define GAMEPLAYFIX_DOWNTRACEONGROUND       STAT(GAMEPLAYFIX_DOWNTRACEONGROUND, this)
30 #define GAMEPLAYFIX_EASIERWATERJUMP         STAT(GAMEPLAYFIX_EASIERWATERJUMP, this)
31 #define GAMEPLAYFIX_STEPDOWN                STAT(GAMEPLAYFIX_STEPDOWN, this)
32 #define GAMEPLAYFIX_STEPMULTIPLETIMES       STAT(GAMEPLAYFIX_STEPMULTIPLETIMES, this)
33 #define GAMEPLAYFIX_UNSTICKPLAYERS          STAT(GAMEPLAYFIX_UNSTICKPLAYERS, this)
34
35 #define PHYS_ACCELERATE(s)                  STAT(MOVEVARS_ACCELERATE, s)
36 #define PHYS_AIRACCELERATE(s)               STAT(MOVEVARS_AIRACCELERATE, s)
37 #define PHYS_AIRACCEL_QW(s)                 STAT(MOVEVARS_AIRACCEL_QW, s)
38 #define PHYS_AIRACCEL_QW_STRETCHFACTOR(s)   STAT(MOVEVARS_AIRACCEL_QW_STRETCHFACTOR, s)
39 #define PHYS_AIRACCEL_SIDEWAYS_FRICTION(s)  STAT(MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION, s)
40 #define PHYS_AIRCONTROL(s)                  STAT(MOVEVARS_AIRCONTROL, s)
41 #define PHYS_AIRCONTROL_PENALTY(s)          STAT(MOVEVARS_AIRCONTROL_PENALTY, s)
42 #define PHYS_AIRCONTROL_POWER(s)            STAT(MOVEVARS_AIRCONTROL_POWER, s)
43 #define PHYS_AIRSPEEDLIMIT_NONQW(s)         STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW, s)
44 #define PHYS_AIRSTOPACCELERATE(s)           STAT(MOVEVARS_AIRSTOPACCELERATE, s)
45 #define PHYS_AIRSTRAFEACCELERATE(s)         STAT(MOVEVARS_AIRSTRAFEACCELERATE, s)
46 #define PHYS_AIRSTRAFEACCEL_QW(s)           STAT(MOVEVARS_AIRSTRAFEACCEL_QW, s)
47
48 #define PHYS_AMMO_FUEL(s)                   STAT(FUEL, s)
49
50 #define PHYS_DODGING_FROZEN                                     STAT(DODGING_FROZEN, this)
51
52 #define PHYS_FRICTION(s)                    STAT(MOVEVARS_FRICTION, s)
53 #define PHYS_FRICTION_ONLAND                STAT(MOVEVARS_FRICTION_ONLAND, this)
54 #define PHYS_FRICTION_SLICK                 STAT(MOVEVARS_FRICTION_SLICK, this)
55
56 #define PHYS_FROZEN(s)                      STAT(FROZEN, s)
57
58 #define PHYS_HIGHSPEED                      STAT(MOVEVARS_HIGHSPEED, this)
59
60 #define PHYS_JETPACK_ACCEL_SIDE                         STAT(JETPACK_ACCEL_SIDE, this)
61 #define PHYS_JETPACK_ACCEL_UP                           STAT(JETPACK_ACCEL_UP, this)
62 #define PHYS_JETPACK_ANTIGRAVITY                        STAT(JETPACK_ANTIGRAVITY, this)
63 #define PHYS_JETPACK_FUEL                                       STAT(JETPACK_FUEL, this)
64 #define PHYS_JETPACK_MAXSPEED_SIDE                      STAT(JETPACK_MAXSPEED_SIDE, this)
65 #define PHYS_JETPACK_MAXSPEED_UP                        STAT(JETPACK_MAXSPEED_UP, this)
66
67 #define PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS   STAT(MOVEVARS_JUMPSPEEDCAP_DISABLE_ONRAMPS, this)
68 #define PHYS_JUMPSTEP                                           STAT(MOVEVARS_JUMPSTEP, this)
69 #define PHYS_JUMPVELOCITY(s)                STAT(MOVEVARS_JUMPVELOCITY, s)
70
71 #define PHYS_MAXAIRSPEED(s)                 STAT(MOVEVARS_MAXAIRSPEED, s)
72 #define PHYS_MAXAIRSTRAFESPEED(s)           STAT(MOVEVARS_MAXAIRSTRAFESPEED, s)
73 #define PHYS_MAXSPEED(s)                    STAT(MOVEVARS_MAXSPEED, s)
74
75 #define PHYS_NOSTEP                                                     STAT(NOSTEP, this)
76 #define PHYS_STEPHEIGHT                     STAT(MOVEVARS_STEPHEIGHT, this)
77
78 #define PHYS_STOPSPEED(s)                   STAT(MOVEVARS_STOPSPEED, s)
79
80 #define PHYS_TRACK_CANJUMP(s)               STAT(MOVEVARS_TRACK_CANJUMP, s)
81
82 #define PHYS_WALLFRICTION                                       STAT(MOVEVARS_WALLFRICTION, this)
83
84 #define PHYS_WARSOWBUNNY_ACCEL(s)           STAT(MOVEVARS_WARSOWBUNNY_ACCEL, s)
85 #define PHYS_WARSOWBUNNY_AIRFORWARDACCEL(s) STAT(MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL, s)
86 #define PHYS_WARSOWBUNNY_BACKTOSIDERATIO(s) STAT(MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO, s)
87 #define PHYS_WARSOWBUNNY_TOPSPEED(s)        STAT(MOVEVARS_WARSOWBUNNY_TOPSPEED, s)
88 #define PHYS_WARSOWBUNNY_TURNACCEL(s)       STAT(MOVEVARS_WARSOWBUNNY_TURNACCEL, s)
89
90 #define UPWARD_VELOCITY_CLEARS_ONGROUND     STAT(GAMEPLAYFIX_UPVELOCITYCLEARSONGROUND, this)
91
92 #ifdef CSQC
93
94         noref float pmove_waterjumptime;
95
96         const int FL_WATERJUMP = 2048;  // player jumping out of water
97         const int FL_JUMPRELEASED = 4096;       // for jump debouncing
98
99         .float watertype;
100         .float waterlevel;
101         .int items;
102
103         .vector movement;
104         .vector v_angle;
105
106 // TODO
107         #define IS_CLIENT(s)                                            (s).isplayermodel
108         #define IS_PLAYER(s)                                            (s).isplayermodel
109         #define isPushable(s)                                           (s).isplayermodel
110
111         //float player_multijump;
112         //float player_jumpheight;
113
114         #define PHYS_GRAVITY(s)                     STAT(MOVEVARS_GRAVITY, s)
115
116         #define PHYS_TELEPORT_TIME(s)                           pmove_waterjumptime
117
118         #define TICRATE ticrate
119
120         #define PHYS_INPUT_ANGLES(s)                            input_angles
121 // TODO
122         #define PHYS_WORLD_ANGLES(s)                            input_angles
123
124         #define PHYS_INPUT_TIMELENGTH                           input_timelength
125         #define PHYS_INPUT_FRAMETIME                            serverdeltatime
126
127         #define PHYS_INPUT_MOVEVALUES(s)                        input_movevalues
128
129         #define PHYS_INPUT_BUTTON_MASK(s)               (input_buttons | BIT(7) * (input_movevalues.x < 0) | BIT(8) * (input_movevalues.x > 0) | BIT(9) * (input_movevalues.y < 0) | BIT(10) * (input_movevalues.y > 0))
130         #define PHYS_INPUT_BUTTON_ATCK(s)                       boolean(input_buttons & BIT(0))
131         #define PHYS_INPUT_BUTTON_JUMP(s)                       boolean(input_buttons & BIT(1))
132         #define PHYS_INPUT_BUTTON_ATCK2(s)                      boolean(input_buttons & BIT(2))
133         #define PHYS_INPUT_BUTTON_ZOOM(s)                       boolean(input_buttons & BIT(3))
134         #define PHYS_INPUT_BUTTON_CROUCH(s)                     boolean(input_buttons & BIT(4))
135         #define PHYS_INPUT_BUTTON_HOOK(s)                       boolean(input_buttons & BIT(5))
136         #define PHYS_INPUT_BUTTON_USE(s)                        boolean(input_buttons & BIT(6))
137         #define PHYS_INPUT_BUTTON_BACKWARD(s)           boolean(input_buttons & BIT(7))
138         #define PHYS_INPUT_BUTTON_FORWARD(s)            boolean(input_buttons & BIT(8))
139         #define PHYS_INPUT_BUTTON_LEFT(s)                       boolean(input_buttons & BIT(9))
140         #define PHYS_INPUT_BUTTON_RIGHT(s)                      boolean(input_buttons & BIT(10))
141         #define PHYS_INPUT_BUTTON_JETPACK(s)            boolean(input_buttons & BIT(12))
142
143         #define PHYS_DEAD(s)                                            s.csqcmodel_isdead
144
145         #define GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE  (boolean(moveflags & MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE))
146         #define GAMEPLAYFIX_NOGRAVITYONGROUND                   (boolean(moveflags & MOVEFLAG_NOGRAVITYONGROUND))
147         #define GAMEPLAYFIX_Q2AIRACCELERATE                             (boolean(moveflags & MOVEFLAG_Q2AIRACCELERATE))
148
149         #define IS_DUCKED(s)                                            boolean(s.flags & FL_DUCKED)
150         #define SET_DUCKED(s)                                           s.flags |= FL_DUCKED
151         #define UNSET_DUCKED(s)                                         s.flags &= ~FL_DUCKED
152
153         #define IS_JUMP_HELD(s)                                         !(s.flags & FL_JUMPRELEASED)
154         #define SET_JUMP_HELD(s)                                        s.flags &= ~FL_JUMPRELEASED
155         #define UNSET_JUMP_HELD(s)                                      s.flags |= FL_JUMPRELEASED
156
157         #define IS_ONGROUND(s)                                          boolean(s.flags & FL_ONGROUND)
158         #define SET_ONGROUND(s)                                         s.flags |= FL_ONGROUND
159         #define UNSET_ONGROUND(s)                                       s.flags &= ~FL_ONGROUND
160
161         #define WAS_ONGROUND(s)                                         boolean(s.lastflags & FL_ONGROUND)
162
163         #define ITEMS_STAT(s)                                           (s).items
164
165         #define PHYS_JUMPSPEEDCAP_MIN                           cvar_string("cl_jumpspeedcap_min")
166         #define PHYS_JUMPSPEEDCAP_MAX                           cvar_string("cl_jumpspeedcap_max")
167
168         #define PHYS_CL_TRACK_CANJUMP(s)            STAT(MOVEVARS_CL_TRACK_CANJUMP, s)
169         // FIXME: 0 doesn't mean zero gravity
170         #define PHYS_ENTGRAVITY(s)                  STAT(MOVEVARS_ENTGRAVITY, s)
171
172 #elif defined(SVQC)
173
174         bool Physics_Valid(string thecvar);
175
176         .float stat_sv_airspeedlimit_nonqw = _STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW);
177         .float stat_sv_maxspeed = _STAT(MOVEVARS_MAXSPEED);
178
179         /** Not real stats */
180         .string stat_jumpspeedcap_min, stat_jumpspeedcap_max;
181
182         #define PHYS_TELEPORT_TIME(s)                           s.teleport_time
183
184         #define PHYS_GRAVITY(s)                     autocvar_sv_gravity
185
186         #define TICRATE sys_frametime
187
188         #define PHYS_INPUT_ANGLES(s)                            s.v_angle
189         #define PHYS_WORLD_ANGLES(s)                            s.angles
190
191         #define PHYS_INPUT_TIMELENGTH                           frametime
192         #define PHYS_INPUT_FRAMETIME                            sys_frametime
193
194         #define PHYS_INPUT_MOVEVALUES(s)                        s.movement
195         // TODO: cache
196         #define PHYS_INPUT_BUTTON_MASK(s)               (s.BUTTON_ATCK | 2 * s.BUTTON_JUMP | 4 * s.BUTTON_ATCK2 | 8 * s.BUTTON_ZOOM | 16 * s.BUTTON_CROUCH | 32 * s.BUTTON_HOOK | 64 * s.BUTTON_USE | 128 * (s.movement_x < 0) | 256 * (s.movement_x > 0) | 512 * (s.movement_y < 0) | 1024 * (s.movement_y > 0))
197         #define PHYS_INPUT_BUTTON_ATCK(s)                       s.BUTTON_ATCK
198         #define PHYS_INPUT_BUTTON_JUMP(s)                       s.BUTTON_JUMP
199         #define PHYS_INPUT_BUTTON_ATCK2(s)                      s.BUTTON_ATCK2
200         #define PHYS_INPUT_BUTTON_ZOOM(s)                       s.BUTTON_ZOOM
201         #define PHYS_INPUT_BUTTON_CROUCH(s)                     s.BUTTON_CROUCH
202         #define PHYS_INPUT_BUTTON_HOOK(s)                       s.BUTTON_HOOK
203         #define PHYS_INPUT_BUTTON_USE(s)                        s.BUTTON_USE
204         #define PHYS_INPUT_BUTTON_BACKWARD(s)           (s.movement_x < 0)
205         #define PHYS_INPUT_BUTTON_FORWARD(s)            (s.movement_x > 0)
206         #define PHYS_INPUT_BUTTON_LEFT(s)                       (s.movement_y < 0)
207         #define PHYS_INPUT_BUTTON_RIGHT(s)                      (s.movement_y > 0)
208         #define PHYS_INPUT_BUTTON_JETPACK(s)            s.BUTTON_JETPACK
209
210         #define PHYS_DEAD(s)                                            s.deadflag != DEAD_NO
211
212         #define GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE  autocvar_sv_gameplayfix_gravityunaffectedbyticrate
213         #define GAMEPLAYFIX_NOGRAVITYONGROUND                   autocvar_sv_gameplayfix_nogravityonground
214         #define GAMEPLAYFIX_Q2AIRACCELERATE                             autocvar_sv_gameplayfix_q2airaccelerate
215
216         #define IS_DUCKED(s)                                            s.crouch
217         #define SET_DUCKED(s)                                           s.crouch = true
218         #define UNSET_DUCKED(s)                                         s.crouch = false
219
220         #define IS_JUMP_HELD(s)                                         !(s.flags & FL_JUMPRELEASED)
221         #define SET_JUMP_HELD(s)                                        s.flags &= ~FL_JUMPRELEASED
222         #define UNSET_JUMP_HELD(s)                                      s.flags |= FL_JUMPRELEASED
223
224         #define IS_ONGROUND(s)                                          boolean(s.flags & FL_ONGROUND)
225         #define SET_ONGROUND(s)                                         s.flags |= FL_ONGROUND
226         #define UNSET_ONGROUND(s)                                       s.flags &= ~FL_ONGROUND
227
228         #define WAS_ONGROUND(s)                                         boolean((s).lastflags & FL_ONGROUND)
229
230         #define ITEMS_STAT(s)                                           s.items
231
232         #define PHYS_JUMPSPEEDCAP_MIN                           autocvar_sv_jumpspeedcap_min
233         #define PHYS_JUMPSPEEDCAP_MAX                           autocvar_sv_jumpspeedcap_max
234
235         #define PHYS_CL_TRACK_CANJUMP(s)                        s.cvar_cl_movement_track_canjump
236         #define PHYS_ENTGRAVITY(s)                                      s.gravity
237
238 #endif
239 #endif