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