]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/physics/player.qh
bcc9f7329072d75d2870a88ff4b128bdc28a9ccb
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / physics / player.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 #ifdef SVQC
16 .float spectatorspeed = _STAT(SPECTATORSPEED);
17 #elif defined(CSQC)
18 .float spectatorspeed;
19 #endif
20
21 .vector movement_old;
22 .float buttons_old;
23 .vector v_angle_old;
24 .string lastclassname;
25
26 .float(entity) PlayerPhysplug;
27 float AdjustAirAccelQW(float accelqw, float factor);
28
29 bool IsFlying(entity a);
30
31 #define BUFFS_STAT(s)                       STAT(BUFFS, s)
32
33 #define GAMEPLAYFIX_DOWNTRACEONGROUND(s)    STAT(GAMEPLAYFIX_DOWNTRACEONGROUND, s)
34 #define GAMEPLAYFIX_EASIERWATERJUMP(s)      STAT(GAMEPLAYFIX_EASIERWATERJUMP, s)
35 #define GAMEPLAYFIX_STEPDOWN(s)             STAT(GAMEPLAYFIX_STEPDOWN, s)
36 #define GAMEPLAYFIX_STEPMULTIPLETIMES(s)    STAT(GAMEPLAYFIX_STEPMULTIPLETIMES, s)
37 #define GAMEPLAYFIX_UNSTICKPLAYERS(s)       STAT(GAMEPLAYFIX_UNSTICKPLAYERS, s)
38
39 #define PHYS_ACCELERATE(s)                  STAT(MOVEVARS_ACCELERATE, s)
40 #define PHYS_AIRACCELERATE(s)               STAT(MOVEVARS_AIRACCELERATE, s)
41 #define PHYS_AIRACCEL_QW(s)                 STAT(MOVEVARS_AIRACCEL_QW, s)
42 #define PHYS_AIRACCEL_QW_STRETCHFACTOR(s)   STAT(MOVEVARS_AIRACCEL_QW_STRETCHFACTOR, s)
43 #define PHYS_AIRACCEL_SIDEWAYS_FRICTION(s)  STAT(MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION, s)
44 #define PHYS_AIRCONTROL(s)                  STAT(MOVEVARS_AIRCONTROL, s)
45 #define PHYS_AIRCONTROL_PENALTY(s)          STAT(MOVEVARS_AIRCONTROL_PENALTY, s)
46 #define PHYS_AIRCONTROL_POWER(s)            STAT(MOVEVARS_AIRCONTROL_POWER, s)
47 #define PHYS_AIRSPEEDLIMIT_NONQW(s)         STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW, s)
48 #define PHYS_AIRSTOPACCELERATE(s)           STAT(MOVEVARS_AIRSTOPACCELERATE, s)
49 #define PHYS_AIRSTRAFEACCELERATE(s)         STAT(MOVEVARS_AIRSTRAFEACCELERATE, s)
50 #define PHYS_AIRSTRAFEACCEL_QW(s)           STAT(MOVEVARS_AIRSTRAFEACCEL_QW, s)
51
52 #define PHYS_AMMO_FUEL(s)                   STAT(FUEL, s)
53
54 #define PHYS_DODGING_FROZEN(s)              STAT(DODGING_FROZEN, s)
55
56 #define PHYS_FRICTION(s)                    STAT(MOVEVARS_FRICTION, s)
57 #define PHYS_FRICTION_ONLAND(s)             STAT(MOVEVARS_FRICTION_ONLAND, s)
58 #define PHYS_FRICTION_SLICK(s)              STAT(MOVEVARS_FRICTION_SLICK, s)
59
60 #define PHYS_FROZEN(s)                      STAT(FROZEN, s)
61
62 #define PHYS_HIGHSPEED(s)                   STAT(MOVEVARS_HIGHSPEED, s)
63
64 #define PHYS_JETPACK_ACCEL_SIDE(s)          STAT(JETPACK_ACCEL_SIDE, s)
65 #define PHYS_JETPACK_ACCEL_UP(s)            STAT(JETPACK_ACCEL_UP, s)
66 #define PHYS_JETPACK_ANTIGRAVITY(s)         STAT(JETPACK_ANTIGRAVITY, s)
67 #define PHYS_JETPACK_FUEL(s)                STAT(JETPACK_FUEL, s)
68 #define PHYS_JETPACK_MAXSPEED_SIDE(s)       STAT(JETPACK_MAXSPEED_SIDE, s)
69 #define PHYS_JETPACK_MAXSPEED_UP(s)         STAT(JETPACK_MAXSPEED_UP, s)
70
71 #define PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS(s) STAT(MOVEVARS_JUMPSPEEDCAP_DISABLE_ONRAMPS, s)
72 #define PHYS_JUMPSTEP(s)                    STAT(MOVEVARS_JUMPSTEP, s)
73 #define PHYS_JUMPVELOCITY(s)                STAT(MOVEVARS_JUMPVELOCITY, s)
74
75 #define PHYS_MAXAIRSPEED(s)                 STAT(MOVEVARS_MAXAIRSPEED, s)
76 #define PHYS_MAXAIRSTRAFESPEED(s)           STAT(MOVEVARS_MAXAIRSTRAFESPEED, s)
77 #define PHYS_MAXSPEED(s)                    STAT(MOVEVARS_MAXSPEED, s)
78
79 #define PHYS_NOSTEP(s)                      STAT(NOSTEP, s)
80 #define PHYS_STEPHEIGHT(s)                  STAT(MOVEVARS_STEPHEIGHT, s)
81
82 #define PHYS_STOPSPEED(s)                   STAT(MOVEVARS_STOPSPEED, s)
83
84 #define PHYS_TRACK_CANJUMP(s)               STAT(MOVEVARS_TRACK_CANJUMP, s)
85
86 #define PHYS_WALLFRICTION(s)                STAT(MOVEVARS_WALLFRICTION, s)
87
88 #define PHYS_WARSOWBUNNY_ACCEL(s)           STAT(MOVEVARS_WARSOWBUNNY_ACCEL, s)
89 #define PHYS_WARSOWBUNNY_AIRFORWARDACCEL(s) STAT(MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL, s)
90 #define PHYS_WARSOWBUNNY_BACKTOSIDERATIO(s) STAT(MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO, s)
91 #define PHYS_WARSOWBUNNY_TOPSPEED(s)        STAT(MOVEVARS_WARSOWBUNNY_TOPSPEED, s)
92 #define PHYS_WARSOWBUNNY_TURNACCEL(s)       STAT(MOVEVARS_WARSOWBUNNY_TURNACCEL, s)
93
94 #define UPWARD_VELOCITY_CLEARS_ONGROUND(s)  STAT(GAMEPLAYFIX_UPVELOCITYCLEARSONGROUND, s)
95
96 #define PHYS_INPUT_BUTTON_ATCK(s)           PHYS_INPUT_BUTTON_BUTTON1(s)
97 #define PHYS_INPUT_BUTTON_JUMP(s)           PHYS_INPUT_BUTTON_BUTTON2(s)
98 #define PHYS_INPUT_BUTTON_ATCK2(s)          PHYS_INPUT_BUTTON_BUTTON3(s)
99 #define PHYS_INPUT_BUTTON_ZOOM(s)           PHYS_INPUT_BUTTON_BUTTON4(s)
100 #define PHYS_INPUT_BUTTON_CROUCH(s)         PHYS_INPUT_BUTTON_BUTTON5(s)
101 #define PHYS_INPUT_BUTTON_HOOK(s)           PHYS_INPUT_BUTTON_BUTTON6(s)
102
103 #ifdef CSQC
104 STATIC_INIT(PHYS_INPUT_BUTTON_HOOK)
105 {
106         localcmd("alias +hook +button6\n");
107         localcmd("alias -hook -button6\n");
108 }
109 #endif
110
111 #define PHYS_INPUT_BUTTON_INFO(s)           PHYS_INPUT_BUTTON_BUTTON7(s)
112 #define PHYS_INPUT_BUTTON_DRAG(s)           PHYS_INPUT_BUTTON_BUTTON8(s)
113 #define PHYS_INPUT_BUTTON_USE(s)            PHYS_INPUT_BUTTON_BUTTON_USE(s)
114 #define PHYS_INPUT_BUTTON_CHAT(s)           PHYS_INPUT_BUTTON_BUTTON_CHAT(s)
115 #define PHYS_INPUT_BUTTON_PRYDON(s)         PHYS_INPUT_BUTTON_BUTTON_PRYDON(s)
116 #define PHYS_INPUT_BUTTON_ZOOMSCRIPT(s)     PHYS_INPUT_BUTTON_BUTTON9(s)
117 #define PHYS_INPUT_BUTTON_JETPACK(s)        PHYS_INPUT_BUTTON_BUTTON10(s)
118
119 #ifdef CSQC
120 STATIC_INIT(PHYS_INPUT_BUTTON_JETPACK)
121 {
122         localcmd("alias +jetpack +button10\n");
123     localcmd("alias -jetpack -button10\n");
124 }
125 #endif
126
127 // if more buttons are needed, start using impulse bits as buttons
128
129 #define PHYS_INPUT_BUTTON_BACKWARD(s)       (PHYS_INPUT_MOVEVALUES(s).x < 0)
130 #define PHYS_INPUT_BUTTON_FORWARD(s)        (PHYS_INPUT_MOVEVALUES(s).x > 0)
131 #define PHYS_INPUT_BUTTON_LEFT(s)           (PHYS_INPUT_MOVEVALUES(s).y < 0)
132 #define PHYS_INPUT_BUTTON_RIGHT(s)          (PHYS_INPUT_MOVEVALUES(s).y > 0)
133
134 // used for special commands and idle checking, not from the engine
135 // TODO: cache
136 #define PHYS_INPUT_BUTTON_MASK(s) ( \
137           (1 <<  0) * PHYS_INPUT_BUTTON_ATCK(s) \
138         | (1 <<  1) * PHYS_INPUT_BUTTON_JUMP(s) \
139         | (1 <<  2) * PHYS_INPUT_BUTTON_ATCK2(s) \
140         | (1 <<  3) * PHYS_INPUT_BUTTON_ZOOM(s) \
141         | (1 <<  4) * PHYS_INPUT_BUTTON_CROUCH(s) \
142         | (1 <<  5) * PHYS_INPUT_BUTTON_HOOK(s) \
143         | (1 <<  6) * PHYS_INPUT_BUTTON_USE(s) \
144         | (1 <<  7) * PHYS_INPUT_BUTTON_BACKWARD(s) \
145         | (1 <<  8) * PHYS_INPUT_BUTTON_FORWARD(s) \
146         | (1 <<  9) * PHYS_INPUT_BUTTON_LEFT(s) \
147         | (1 << 10) * PHYS_INPUT_BUTTON_RIGHT(s) \
148         )
149
150 #define IS_JUMP_HELD(s)                     (!((s).flags & FL_JUMPRELEASED))
151 #define SET_JUMP_HELD(s)                    ((s).flags &= ~FL_JUMPRELEASED)
152 #define UNSET_JUMP_HELD(s)                  ((s).flags |= FL_JUMPRELEASED)
153
154 #define WAS_ONGROUND(s)                     boolean((s).lastflags & FL_ONGROUND)
155
156 #define ITEMS_STAT(s)                       ((s).items)
157
158 .float teleport_time;
159
160 #ifdef CSQC
161
162         string autocvar_cl_jumpspeedcap_min;
163         string autocvar_cl_jumpspeedcap_max;
164
165         noref float pmove_waterjumptime;
166
167         const int FL_WATERJUMP = 2048;  // player jumping out of water
168         const int FL_JUMPRELEASED = 4096;  // for jump debouncing
169
170         .float watertype;
171         .float waterlevel;
172         .int items;
173
174         .vector movement;
175         .vector v_angle;
176
177 // TODO
178         #define IS_CLIENT(s)                        ((s).isplayermodel)
179         #define IS_PLAYER(s)                        ((s).isplayermodel)
180         #define IS_NOT_A_CLIENT(s)                  (!(s).isplayermodel)
181         #define isPushable(s)                       ((s).isplayermodel || (s).pushable || ((s).flags & FL_PROJECTILE))
182
183         //float player_multijump;
184         //float player_jumpheight;
185
186         #define PHYS_GRAVITY(s)                     STAT(MOVEVARS_GRAVITY, s)
187
188         #define PHYS_TELEPORT_TIME(s)               ((s).teleport_time)
189
190         #define TICRATE                             ticrate
191
192         #define PHYS_INPUT_ANGLES(s)                input_angles
193 // TODO
194         #define PHYS_WORLD_ANGLES(s)                input_angles
195
196         #define PHYS_INPUT_TIMELENGTH               input_timelength
197         #define PHYS_INPUT_FRAMETIME                serverdeltatime
198
199         #define PHYS_INPUT_MOVEVALUES(s)            input_movevalues
200
201         #define PHYS_INPUT_BUTTON_BUTTON1(s)        boolean(input_buttons & BIT(0))
202         #define PHYS_INPUT_BUTTON_BUTTON2(s)        boolean(input_buttons & BIT(1))
203         #define PHYS_INPUT_BUTTON_BUTTON3(s)        boolean(input_buttons & BIT(2))
204         #define PHYS_INPUT_BUTTON_BUTTON4(s)        boolean(input_buttons & BIT(3))
205         #define PHYS_INPUT_BUTTON_BUTTON5(s)        boolean(input_buttons & BIT(4))
206         #define PHYS_INPUT_BUTTON_BUTTON6(s)        boolean(input_buttons & BIT(5))
207         #define PHYS_INPUT_BUTTON_BUTTON7(s)        boolean(input_buttons & BIT(6))
208         #define PHYS_INPUT_BUTTON_BUTTON8(s)        boolean(input_buttons & BIT(7))
209         #define PHYS_INPUT_BUTTON_BUTTON_USE(s)     boolean(input_buttons & BIT(8))
210         #define PHYS_INPUT_BUTTON_BUTTON_CHAT(s)    boolean(input_buttons & BIT(9))
211         #define PHYS_INPUT_BUTTON_BUTTON_PRYDON(s)  boolean(input_buttons & BIT(10))
212         #define PHYS_INPUT_BUTTON_BUTTON9(s)        boolean(input_buttons & BIT(11))
213         #define PHYS_INPUT_BUTTON_BUTTON10(s)       boolean(input_buttons & BIT(12))
214         #define PHYS_INPUT_BUTTON_BUTTON11(s)       boolean(input_buttons & BIT(13))
215         #define PHYS_INPUT_BUTTON_BUTTON12(s)       boolean(input_buttons & BIT(14))
216         #define PHYS_INPUT_BUTTON_BUTTON13(s)       boolean(input_buttons & BIT(15))
217         #define PHYS_INPUT_BUTTON_BUTTON14(s)       boolean(input_buttons & BIT(16))
218         #define PHYS_INPUT_BUTTON_BUTTON15(s)       boolean(input_buttons & BIT(17))
219         #define PHYS_INPUT_BUTTON_BUTTON16(s)       boolean(input_buttons & BIT(18))
220
221         #define GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE  (boolean(moveflags & MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE))
222         #define GAMEPLAYFIX_NOGRAVITYONGROUND           (boolean(moveflags & MOVEFLAG_NOGRAVITYONGROUND))
223         #define GAMEPLAYFIX_Q2AIRACCELERATE             (boolean(moveflags & MOVEFLAG_Q2AIRACCELERATE))
224
225         #define IS_DUCKED(s)                        (boolean((s).flags & FL_DUCKED))
226         #define SET_DUCKED(s)                       ((s).flags |= FL_DUCKED)
227         #define UNSET_DUCKED(s)                     ((s).flags &= ~FL_DUCKED)
228
229         #define PHYS_JUMPSPEEDCAP_MIN               autocvar_cl_jumpspeedcap_min
230         #define PHYS_JUMPSPEEDCAP_MAX               autocvar_cl_jumpspeedcap_max
231
232         #define PHYS_CL_TRACK_CANJUMP(s)            STAT(MOVEVARS_CL_TRACK_CANJUMP, s)
233         // FIXME: 0 doesn't mean zero gravity
234         #define PHYS_ENTGRAVITY(s)                  STAT(MOVEVARS_ENTGRAVITY, s)
235
236 #elif defined(SVQC)
237
238         bool Physics_Valid(string thecvar);
239
240         .float stat_sv_airspeedlimit_nonqw = _STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW);
241         .float stat_sv_maxspeed = _STAT(MOVEVARS_MAXSPEED);
242
243         /** Not real stats */
244         .string jumpspeedcap_min;
245         .string jumpspeedcap_max;
246
247         #define PHYS_TELEPORT_TIME(s)               ((s).teleport_time)
248
249         #define PHYS_GRAVITY(s)                     autocvar_sv_gravity
250
251         #define TICRATE sys_frametime
252
253         #define PHYS_INPUT_ANGLES(s)                ((s).v_angle)
254         #define PHYS_WORLD_ANGLES(s)                ((s).angles)
255
256         #define PHYS_INPUT_TIMELENGTH               frametime
257         #define PHYS_INPUT_FRAMETIME                sys_frametime
258
259         #define PHYS_INPUT_MOVEVALUES(s)            ((s).movement)
260
261         #define PHYS_INPUT_BUTTON_BUTTON1(s)        ((s).button0)
262         #define PHYS_INPUT_BUTTON_BUTTON2(s)        ((s).button2)
263         #define PHYS_INPUT_BUTTON_BUTTON3(s)        ((s).button3)
264         #define PHYS_INPUT_BUTTON_BUTTON4(s)        ((s).button4)
265         #define PHYS_INPUT_BUTTON_BUTTON5(s)        ((s).button5)
266         #define PHYS_INPUT_BUTTON_BUTTON6(s)        ((s).button6)
267         #define PHYS_INPUT_BUTTON_BUTTON7(s)        ((s).button7)
268         #define PHYS_INPUT_BUTTON_BUTTON8(s)        ((s).button8)
269         #define PHYS_INPUT_BUTTON_BUTTON_USE(s)     ((s).buttonuse)
270         #define PHYS_INPUT_BUTTON_BUTTON_CHAT(s)    ((s).buttonchat)
271         #define PHYS_INPUT_BUTTON_BUTTON_PRYDON(s)  ((s).cursor_active)
272         #define PHYS_INPUT_BUTTON_BUTTON9(s)        ((s).button9)
273         #define PHYS_INPUT_BUTTON_BUTTON10(s)       ((s).button10)
274         #define PHYS_INPUT_BUTTON_BUTTON11(s)       ((s).button11)
275         #define PHYS_INPUT_BUTTON_BUTTON12(s)       ((s).button12)
276         #define PHYS_INPUT_BUTTON_BUTTON13(s)       ((s).button13)
277         #define PHYS_INPUT_BUTTON_BUTTON14(s)       ((s).button14)
278         #define PHYS_INPUT_BUTTON_BUTTON15(s)       ((s).button15)
279         #define PHYS_INPUT_BUTTON_BUTTON16(s)       ((s).button16)
280
281         #define GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE  autocvar_sv_gameplayfix_gravityunaffectedbyticrate
282         #define GAMEPLAYFIX_NOGRAVITYONGROUND           autocvar_sv_gameplayfix_nogravityonground
283         #define GAMEPLAYFIX_Q2AIRACCELERATE             autocvar_sv_gameplayfix_q2airaccelerate
284
285         #define IS_DUCKED(s)                        ((s).crouch)
286         #define SET_DUCKED(s)                       ((s).crouch = true)
287         #define UNSET_DUCKED(s)                     ((s).crouch = false)
288
289         #define PHYS_JUMPSPEEDCAP_MIN               autocvar_sv_jumpspeedcap_min
290         #define PHYS_JUMPSPEEDCAP_MAX               autocvar_sv_jumpspeedcap_max
291
292         #define PHYS_CL_TRACK_CANJUMP(s)            ((s).cvar_cl_movement_track_canjump)
293         #define PHYS_ENTGRAVITY(s)                  ((s).gravity)
294
295 #endif
296
297 REGISTER_NET_C2S(setpause)
298 #ifdef CSQC
299 void unpause_update()
300 {
301         static bool waspaused;
302         bool ispaused = PHYS_INPUT_BUTTON_CHAT(this);
303         if (ispaused == waspaused) return;
304         waspaused = ispaused;
305         // if (!serverispaused) return; // TODO: find out somehow
306         if (ispaused) return; // ignore setting pause, server will get those presses anyway, but it won't get releases
307         int channel = MSG_C2S;
308         WriteHeader(channel, setpause);
309         WriteByte(channel, ispaused);
310 }
311 #endif
312 #ifdef SVQC
313 NET_HANDLE(setpause, bool)
314 {
315         bool ispaused = boolean(ReadByte());
316         PHYS_INPUT_BUTTON_CHAT(sender) = ispaused;
317         return true;
318 }
319 #endif
320
321 #endif