]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/physics/player.qh
29c028f03267500aed3f84994ff0b524e14c6c7c
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / physics / player.qh
1 #pragma once
2
3 // Client/server mappings
4
5 #ifdef SVQC
6 // TODO: get rid of this random dumb include!
7         #include <common/state.qh>
8 #endif
9
10 .entity conveyor;
11
12 .float race_penalty;
13
14 .float gravity;
15 .float swamp_slowdown;
16 .float lastflags;
17 .float lastground;
18 .bool wasFlying;
19
20 .int buttons_old;
21 .vector movement_old;
22 .vector v_angle_old;
23 .string lastclassname;
24
25 .float(entity,float) PlayerPhysplug;
26 float AdjustAirAccelQW(float accelqw, float factor);
27
28 bool IsFlying(entity a);
29
30 #define PHYS_PL_MAX(s)                                          STAT(PL_MAX, s)
31 #define PHYS_PL_MIN(s)                                          STAT(PL_MIN, s)
32 #define PHYS_PL_CROUCH_MAX(s)                           STAT(PL_CROUCH_MAX, s)
33 #define PHYS_PL_CROUCH_MIN(s)                           STAT(PL_CROUCH_MIN, s)
34
35 #define PHYS_PL_VIEWOFS(s)                                      STAT(PL_VIEW_OFS, s)
36 #define PHYS_PL_CROUCH_VIEWOFS(s)                       STAT(PL_CROUCH_VIEW_OFS, s)
37
38 #define PHYS_VIEWHEIGHT(s)                                      STAT(VIEWHEIGHT, s)
39 #define PHYS_HEALTH(s)                                          STAT(HEALTH, s)
40
41 #define BUFFS_STAT(s)                       STAT(BUFFS, s)
42
43 #define PHYS_ACCELERATE(s)                  STAT(MOVEVARS_ACCELERATE, s)
44 #define PHYS_AIRACCELERATE(s)               STAT(MOVEVARS_AIRACCELERATE, s)
45 #define PHYS_AIRACCEL_QW(s)                 STAT(MOVEVARS_AIRACCEL_QW, s)
46 #define PHYS_AIRACCEL_QW_STRETCHFACTOR(s)   STAT(MOVEVARS_AIRACCEL_QW_STRETCHFACTOR, s)
47 #define PHYS_AIRACCEL_SIDEWAYS_FRICTION(s)  STAT(MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION, s)
48 #define PHYS_AIRCONTROL(s)                  STAT(MOVEVARS_AIRCONTROL, s)
49 #define PHYS_AIRCONTROL_PENALTY(s)          STAT(MOVEVARS_AIRCONTROL_PENALTY, s)
50 #define PHYS_AIRCONTROL_POWER(s)            STAT(MOVEVARS_AIRCONTROL_POWER, s)
51 #define PHYS_AIRCONTROL_BACKWARDS(s)        STAT(MOVEVARS_AIRCONTROL_BACKWARDS, s)
52 #define PHYS_AIRCONTROL_SIDEWARDS(s)        STAT(MOVEVARS_AIRCONTROL_SIDEWARDS, s)
53 #define PHYS_AIRSPEEDLIMIT_NONQW(s)         STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW, s)
54 #define PHYS_AIRSTOPACCELERATE(s)           STAT(MOVEVARS_AIRSTOPACCELERATE, s)
55 #define PHYS_AIRSTRAFEACCELERATE(s)         STAT(MOVEVARS_AIRSTRAFEACCELERATE, s)
56 #define PHYS_AIRSTRAFEACCEL_QW(s)           STAT(MOVEVARS_AIRSTRAFEACCEL_QW, s)
57
58 #define PHYS_AMMO_FUEL(s)                   STAT(FUEL, s)
59
60 #define PHYS_DODGING_FROZEN(s)              STAT(DODGING_FROZEN, s)
61
62 #define PHYS_FRICTION(s)                    STAT(MOVEVARS_FRICTION, s)
63 #define PHYS_FRICTION_ONLAND(s)             STAT(MOVEVARS_FRICTION_ONLAND, s)
64 #define PHYS_FRICTION_SLICK(s)              STAT(MOVEVARS_FRICTION_SLICK, s)
65
66 #define PHYS_FROZEN(s)                      STAT(FROZEN, s)
67
68 #define PHYS_HIGHSPEED(s)                   STAT(MOVEVARS_HIGHSPEED, s)
69
70 #define PHYS_JETPACK_ACCEL_SIDE(s)          STAT(JETPACK_ACCEL_SIDE, s)
71 #define PHYS_JETPACK_ACCEL_UP(s)            STAT(JETPACK_ACCEL_UP, s)
72 #define PHYS_JETPACK_ANTIGRAVITY(s)         STAT(JETPACK_ANTIGRAVITY, s)
73 #define PHYS_JETPACK_FUEL(s)                STAT(JETPACK_FUEL, s)
74 #define PHYS_JETPACK_MAXSPEED_SIDE(s)       STAT(JETPACK_MAXSPEED_SIDE, s)
75 #define PHYS_JETPACK_MAXSPEED_UP(s)         STAT(JETPACK_MAXSPEED_UP, s)
76 #define PHYS_JETPACK_REVERSE_THRUST(s)          STAT(JETPACK_REVERSE_THRUST, s)
77
78 #define PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS(s) STAT(MOVEVARS_JUMPSPEEDCAP_DISABLE_ONRAMPS)
79 #define PHYS_JUMPVELOCITY(s)                STAT(MOVEVARS_JUMPVELOCITY, s)
80 #define PHYS_JUMPVELOCITY_CROUCH(s)         STAT(MOVEVARS_JUMPVELOCITY_CROUCH, s)
81
82 #define PHYS_MAXAIRSPEED(s)                 STAT(MOVEVARS_MAXAIRSPEED, s)
83 #define PHYS_MAXAIRSTRAFESPEED(s)           STAT(MOVEVARS_MAXAIRSTRAFESPEED, s)
84 #define PHYS_MAXSPEED(s)                    STAT(MOVEVARS_MAXSPEED, s)
85
86 #define PHYS_STOPSPEED(s)                   STAT(MOVEVARS_STOPSPEED, s)
87
88 #define PHYS_TRACK_CANJUMP(s)               STAT(MOVEVARS_TRACK_CANJUMP, s)
89
90 #define PHYS_WARSOWBUNNY_ACCEL(s)           STAT(MOVEVARS_WARSOWBUNNY_ACCEL, s)
91 #define PHYS_WARSOWBUNNY_AIRFORWARDACCEL(s) STAT(MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL, s)
92 #define PHYS_WARSOWBUNNY_BACKTOSIDERATIO(s) STAT(MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO, s)
93 #define PHYS_WARSOWBUNNY_TOPSPEED(s)        STAT(MOVEVARS_WARSOWBUNNY_TOPSPEED, s)
94 #define PHYS_WARSOWBUNNY_TURNACCEL(s)       STAT(MOVEVARS_WARSOWBUNNY_TURNACCEL, s)
95
96 #define PHYS_SLICK_APPLYGRAVITY(s)              STAT(SLICK_APPLYGRAVITY)
97
98 #define PHYS_INPUT_BUTTON_ATCK(s)           PHYS_INPUT_BUTTON_BUTTON1(s)
99 #define PHYS_INPUT_BUTTON_JUMP(s)           PHYS_INPUT_BUTTON_BUTTON2(s)
100 #define PHYS_INPUT_BUTTON_ATCK2(s)          PHYS_INPUT_BUTTON_BUTTON3(s)
101 #define PHYS_INPUT_BUTTON_ZOOM(s)           PHYS_INPUT_BUTTON_BUTTON4(s)
102 #define PHYS_INPUT_BUTTON_CROUCH(s)         PHYS_INPUT_BUTTON_BUTTON5(s)
103 #define PHYS_INPUT_BUTTON_HOOK(s)           PHYS_INPUT_BUTTON_BUTTON6(s)
104 #define PHYS_INPUT_BUTTON_INFO(s)           PHYS_INPUT_BUTTON_BUTTON7(s)
105 #define PHYS_INPUT_BUTTON_DRAG(s)           PHYS_INPUT_BUTTON_BUTTON8(s)
106 #define PHYS_INPUT_BUTTON_USE(s)            PHYS_INPUT_BUTTON_BUTTON_USE(s)
107 #define PHYS_INPUT_BUTTON_CHAT(s)           PHYS_INPUT_BUTTON_BUTTON_CHAT(s)
108 #define PHYS_INPUT_BUTTON_PRYDON(s)         PHYS_INPUT_BUTTON_BUTTON_PRYDON(s)
109 #define PHYS_INPUT_BUTTON_ZOOMSCRIPT(s)     PHYS_INPUT_BUTTON_BUTTON9(s)
110 #define PHYS_INPUT_BUTTON_JETPACK(s)        PHYS_INPUT_BUTTON_BUTTON10(s)
111 #define PHYS_INPUT_BUTTON_DODGE(s)                      PHYS_INPUT_BUTTON_BUTTON11(s)
112 #define PHYS_INPUT_BUTTON_MINIGAME(s)           PHYS_INPUT_BUTTON_BUTTON14(s)
113
114 #ifdef CSQC
115 STATIC_INIT(PHYS_INPUT_BUTTON)
116 {
117         localcmd("alias +hook +button6\n");
118         localcmd("alias -hook -button6\n");
119
120         localcmd("alias +jetpack +button10\n");
121         localcmd("alias -jetpack -button10\n");
122
123         localcmd("alias +dodge +button11\n");
124         localcmd("alias -dodge -button11\n");
125 }
126 #endif
127
128 // if more buttons are needed, start using impulse bits as buttons
129
130 #define PHYS_INPUT_BUTTON_BACKWARD(s)       (PHYS_INPUT_MOVEVALUES(s).x < 0)
131 #define PHYS_INPUT_BUTTON_FORWARD(s)        (PHYS_INPUT_MOVEVALUES(s).x > 0)
132 #define PHYS_INPUT_BUTTON_LEFT(s)           (PHYS_INPUT_MOVEVALUES(s).y < 0)
133 #define PHYS_INPUT_BUTTON_RIGHT(s)          (PHYS_INPUT_MOVEVALUES(s).y > 0)
134
135 // used for special commands and idle checking, not from the engine
136 // TODO: cache
137 #define PHYS_INPUT_BUTTON_MASK(s) ( \
138           (1 <<  0) * PHYS_INPUT_BUTTON_ATCK(s) \
139         | (1 <<  1) * PHYS_INPUT_BUTTON_JUMP(s) \
140         | (1 <<  2) * PHYS_INPUT_BUTTON_ATCK2(s) \
141         | (1 <<  3) * PHYS_INPUT_BUTTON_ZOOM(s) \
142         | (1 <<  4) * PHYS_INPUT_BUTTON_CROUCH(s) \
143         | (1 <<  5) * PHYS_INPUT_BUTTON_HOOK(s) \
144         | (1 <<  6) * PHYS_INPUT_BUTTON_USE(s) \
145         | (1 <<  7) * PHYS_INPUT_BUTTON_BACKWARD(s) \
146         | (1 <<  8) * PHYS_INPUT_BUTTON_FORWARD(s) \
147         | (1 <<  9) * PHYS_INPUT_BUTTON_LEFT(s) \
148         | (1 << 10) * PHYS_INPUT_BUTTON_RIGHT(s) \
149         )
150
151 #define IS_JUMP_HELD(s)                     (!((s).flags & FL_JUMPRELEASED))
152 #define SET_JUMP_HELD(s)                    ((s).flags &= ~FL_JUMPRELEASED)
153 #define UNSET_JUMP_HELD(s)                  ((s).flags |= FL_JUMPRELEASED)
154
155 #define WAS_ONGROUND(s)                     boolean((s).lastflags & FL_ONGROUND)
156 #define WAS_ONSLICK(s)                      boolean((s).lastflags & FL_ONSLICK)
157
158 #define ITEMS_STAT(s)                       ((s).items)
159
160 .float teleport_time;
161 #define PHYS_TELEPORT_TIME(s)               ((s).teleport_time)
162
163 .float waterjump_time;
164 #define PHYS_WATERJUMP_TIME(s)               ((s).waterjump_time)
165
166 #ifdef CSQC
167
168         #define PHYS_FIXANGLE(s) ('0 0 0')
169
170         string autocvar_cl_jumpspeedcap_min;
171         string autocvar_cl_jumpspeedcap_max;
172
173         const int FL_WATERJUMP = 2048;  // player jumping out of water
174         const int FL_JUMPRELEASED = 4096;  // for jump debouncing
175
176         .float watertype;
177         .float waterlevel;
178         .int items;
179
180         .vector movement;
181
182         // angles of the player's view (as opposed to their model which uses `.vector angles;`) in degrees
183         // x is pitch: positive means down (unlike .angles)
184         // y is yaw: between -180 and 180, increases when turning left
185         // z is roll: positive means tilted clockwise, usually is 0
186         // when .fixangle is set, the player's view will change to the direction where the model is facing
187         // more info: https://gitlab.com/xonotic/xonotic-data.pk3dir/merge_requests/447#note_32816794
188         .vector v_angle;
189
190         .entity hook;
191
192 // TODO
193         #define IS_CLIENT(s)                        ((s).isplayermodel || (s) == csqcplayer)
194         #define IS_PLAYER(s)                        ((s).isplayermodel)
195         #define IS_NOT_A_CLIENT(s)                  (!(s).isplayermodel && (s) != csqcplayer)
196         #define isPushable(s)                       ((s).isplayermodel || (s).pushable || ((s).flags & FL_PROJECTILE))
197
198         //float player_multijump;
199         //float player_jumpheight;
200
201         #define PHYS_INPUT_ANGLES(s)                input_angles
202 // TODO
203         #define PHYS_WORLD_ANGLES(s)                input_angles
204
205         #define PHYS_INPUT_TIMELENGTH               input_timelength
206         #define PHYS_INPUT_FRAMETIME                serverdeltatime
207
208         #define PHYS_INPUT_MOVEVALUES(s)            input_movevalues
209         #define PHYS_CS(s)                          (s)
210
211         #define PHYS_INPUT_BUTTON_BUTTON1(s)        boolean(input_buttons & BIT(0))
212         #define PHYS_INPUT_BUTTON_BUTTON2(s)        boolean(input_buttons & BIT(1))
213         #define PHYS_INPUT_BUTTON_BUTTON3(s)        boolean(input_buttons & BIT(2))
214         #define PHYS_INPUT_BUTTON_BUTTON4(s)        boolean(input_buttons & BIT(3))
215         #define PHYS_INPUT_BUTTON_BUTTON5(s)        boolean(input_buttons & BIT(4))
216         #define PHYS_INPUT_BUTTON_BUTTON6(s)        boolean(input_buttons & BIT(5))
217         #define PHYS_INPUT_BUTTON_BUTTON7(s)        boolean(input_buttons & BIT(6))
218         #define PHYS_INPUT_BUTTON_BUTTON8(s)        boolean(input_buttons & BIT(7))
219         #define PHYS_INPUT_BUTTON_BUTTON_USE(s)     boolean(input_buttons & BIT(8))
220         #define PHYS_INPUT_BUTTON_BUTTON_CHAT(s)    boolean(input_buttons & BIT(9))
221         #define PHYS_INPUT_BUTTON_BUTTON_PRYDON(s)  boolean(input_buttons & BIT(10))
222         #define PHYS_INPUT_BUTTON_BUTTON9(s)        boolean(input_buttons & BIT(11))
223         #define PHYS_INPUT_BUTTON_BUTTON10(s)       boolean(input_buttons & BIT(12))
224         #define PHYS_INPUT_BUTTON_BUTTON11(s)       boolean(input_buttons & BIT(13))
225         #define PHYS_INPUT_BUTTON_BUTTON12(s)       boolean(input_buttons & BIT(14))
226         #define PHYS_INPUT_BUTTON_BUTTON13(s)       boolean(input_buttons & BIT(15))
227         #define PHYS_INPUT_BUTTON_BUTTON14(s)       boolean(input_buttons & BIT(16))
228         #define PHYS_INPUT_BUTTON_BUTTON15(s)       boolean(input_buttons & BIT(17))
229         #define PHYS_INPUT_BUTTON_BUTTON16(s)       boolean(input_buttons & BIT(18))
230
231         #define IS_DUCKED(s)                        (boolean((s).flags & FL_DUCKED))
232         #define SET_DUCKED(s)                       ((s).flags |= FL_DUCKED)
233         #define UNSET_DUCKED(s)                     ((s).flags &= ~FL_DUCKED)
234
235         #define PHYS_INVEHICLE(s)                                       (boolean(hud != HUD_NORMAL))
236
237         #define PHYS_JUMPSPEEDCAP_MIN               autocvar_cl_jumpspeedcap_min
238         #define PHYS_JUMPSPEEDCAP_MAX               autocvar_cl_jumpspeedcap_max
239
240         #define PHYS_CL_TRACK_CANJUMP(s)            STAT(MOVEVARS_CL_TRACK_CANJUMP, s)
241
242 #elif defined(SVQC)
243
244         #define PHYS_FIXANGLE(s) ((s).fixangle)
245
246         bool Physics_Valid(string thecvar);
247
248         void Physics_UpdateStats(entity this);
249
250         void PM_UpdateButtons(entity this, entity store);
251
252         /** Not real stats */
253         .string jumpspeedcap_min;
254         .string jumpspeedcap_max;
255
256         #define PHYS_INPUT_ANGLES(s)                ((s).v_angle)
257         #define PHYS_WORLD_ANGLES(s)                ((s).angles)
258
259         #define PHYS_INPUT_TIMELENGTH               frametime
260         #define PHYS_INPUT_FRAMETIME                sys_frametime
261
262         #define PHYS_INPUT_MOVEVALUES(s)            CS(s).movement
263         #define PHYS_CS(s)                          CS(s)
264
265         #define PHYS_INPUT_BUTTON_BUTTON1(s)        (CS(s).button0)
266         #define PHYS_INPUT_BUTTON_BUTTON2(s)        (CS(s).button2)
267         #define PHYS_INPUT_BUTTON_BUTTON3(s)        (CS(s).button3)
268         #define PHYS_INPUT_BUTTON_BUTTON4(s)        (CS(s).button4)
269         #define PHYS_INPUT_BUTTON_BUTTON5(s)        (CS(s).button5)
270         #define PHYS_INPUT_BUTTON_BUTTON6(s)        (CS(s).button6)
271         #define PHYS_INPUT_BUTTON_BUTTON7(s)        (CS(s).button7)
272         #define PHYS_INPUT_BUTTON_BUTTON8(s)        (CS(s).button8)
273         #define PHYS_INPUT_BUTTON_BUTTON_USE(s)     (CS(s).buttonuse)
274         #define PHYS_INPUT_BUTTON_BUTTON_CHAT(s)    (CS(s).buttonchat)
275         #define PHYS_INPUT_BUTTON_BUTTON_PRYDON(s)  (CS(s).cursor_active)
276         #define PHYS_INPUT_BUTTON_BUTTON9(s)        (CS(s).button9)
277         #define PHYS_INPUT_BUTTON_BUTTON10(s)       (CS(s).button10)
278         #define PHYS_INPUT_BUTTON_BUTTON11(s)       (CS(s).button11)
279         #define PHYS_INPUT_BUTTON_BUTTON12(s)       (CS(s).button12)
280         #define PHYS_INPUT_BUTTON_BUTTON13(s)       (CS(s).button13)
281         #define PHYS_INPUT_BUTTON_BUTTON14(s)       (CS(s).button14)
282         #define PHYS_INPUT_BUTTON_BUTTON15(s)       (CS(s).button15)
283         #define PHYS_INPUT_BUTTON_BUTTON16(s)       (CS(s).button16)
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_INVEHICLE(s)                                       (boolean((s).vehicle != NULL))
290
291         #define PHYS_JUMPSPEEDCAP_MIN               autocvar_sv_jumpspeedcap_min
292         #define PHYS_JUMPSPEEDCAP_MAX               autocvar_sv_jumpspeedcap_max
293
294         #define PHYS_CL_TRACK_CANJUMP(s)            (CS(s).cvar_cl_movement_track_canjump)
295
296 #endif
297
298 #ifdef SVQC
299 // FIXME/EXPLAINME: why? Mario: because
300 vector autocvar_sv_player_maxs = '16 16 45';
301 vector autocvar_sv_player_mins = '-16 -16 -24';
302 vector autocvar_sv_player_viewoffset = '0 0 35';
303 vector autocvar_sv_player_crouch_maxs = '16 16 25';
304 vector autocvar_sv_player_crouch_mins = '-16 -16 -24';
305 vector autocvar_sv_player_crouch_viewoffset = '0 0 20';
306 //vector autocvar_sv_player_headsize = '24 24 12';
307 #endif
308
309 REGISTER_NET_C2S(setpause)
310 #ifdef CSQC
311 void unpause_update()
312 {
313         static bool waspaused;
314         bool ispaused = PHYS_INPUT_BUTTON_CHAT(this);
315         if (ispaused == waspaused) return;
316         waspaused = ispaused;
317         // if (!serverispaused) return; // TODO: find out somehow
318         if (ispaused) return; // ignore setting pause, server will get those presses anyway, but it won't get releases
319         int channel = MSG_C2S;
320         WriteHeader(channel, setpause);
321         WriteByte(channel, ispaused);
322 }
323 #endif
324 #ifdef SVQC
325 NET_HANDLE(setpause, bool)
326 {
327         bool ispaused = boolean(ReadByte());
328         PHYS_INPUT_BUTTON_CHAT(sender) = ispaused;
329         return true;
330 }
331 #endif