1 #ifndef COMMON_PHYSICS_H
2 #define COMMON_PHYSICS_H
4 // Client/server mappings
13 .float swamp_slowdown;
18 .float spectatorspeed = _STAT(SPECTATORSPEED);
20 .float spectatorspeed;
26 .string lastclassname;
28 .float(entity) PlayerPhysplug;
29 float AdjustAirAccelQW(float accelqw, float factor);
31 bool IsFlying(entity a);
33 #define BUFFS_STAT(s) STAT(BUFFS, s)
35 #define GAMEPLAYFIX_DOWNTRACEONGROUND(s) STAT(GAMEPLAYFIX_DOWNTRACEONGROUND, s)
36 #define GAMEPLAYFIX_EASIERWATERJUMP(s) STAT(GAMEPLAYFIX_EASIERWATERJUMP, s)
37 #define GAMEPLAYFIX_STEPDOWN(s) STAT(GAMEPLAYFIX_STEPDOWN, s)
38 #define GAMEPLAYFIX_STEPMULTIPLETIMES(s) STAT(GAMEPLAYFIX_STEPMULTIPLETIMES, s)
39 #define GAMEPLAYFIX_UNSTICKPLAYERS(s) STAT(GAMEPLAYFIX_UNSTICKPLAYERS, s)
40 #define GAMEPLAYFIX_WATERTRANSITION(s) STAT(GAMEPLAYFIX_WATERTRANSITION, s)
42 #define PHYS_ACCELERATE(s) STAT(MOVEVARS_ACCELERATE, s)
43 #define PHYS_AIRACCELERATE(s) STAT(MOVEVARS_AIRACCELERATE, s)
44 #define PHYS_AIRACCEL_QW(s) STAT(MOVEVARS_AIRACCEL_QW, s)
45 #define PHYS_AIRACCEL_QW_STRETCHFACTOR(s) STAT(MOVEVARS_AIRACCEL_QW_STRETCHFACTOR, s)
46 #define PHYS_AIRACCEL_SIDEWAYS_FRICTION(s) STAT(MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION, s)
47 #define PHYS_AIRCONTROL(s) STAT(MOVEVARS_AIRCONTROL, s)
48 #define PHYS_AIRCONTROL_PENALTY(s) STAT(MOVEVARS_AIRCONTROL_PENALTY, s)
49 #define PHYS_AIRCONTROL_POWER(s) STAT(MOVEVARS_AIRCONTROL_POWER, s)
50 #define PHYS_AIRSPEEDLIMIT_NONQW(s) STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW, s)
51 #define PHYS_AIRSTOPACCELERATE(s) STAT(MOVEVARS_AIRSTOPACCELERATE, s)
52 #define PHYS_AIRSTRAFEACCELERATE(s) STAT(MOVEVARS_AIRSTRAFEACCELERATE, s)
53 #define PHYS_AIRSTRAFEACCEL_QW(s) STAT(MOVEVARS_AIRSTRAFEACCEL_QW, s)
55 #define PHYS_AMMO_FUEL(s) STAT(FUEL, s)
57 #define PHYS_DODGING_FROZEN(s) STAT(DODGING_FROZEN, s)
59 #define PHYS_FRICTION(s) STAT(MOVEVARS_FRICTION, s)
60 #define PHYS_FRICTION_ONLAND(s) STAT(MOVEVARS_FRICTION_ONLAND, s)
61 #define PHYS_FRICTION_SLICK(s) STAT(MOVEVARS_FRICTION_SLICK, s)
63 #define PHYS_FROZEN(s) STAT(FROZEN, s)
65 #define PHYS_HIGHSPEED(s) STAT(MOVEVARS_HIGHSPEED, s)
67 #define PHYS_JETPACK_ACCEL_SIDE(s) STAT(JETPACK_ACCEL_SIDE, s)
68 #define PHYS_JETPACK_ACCEL_UP(s) STAT(JETPACK_ACCEL_UP, s)
69 #define PHYS_JETPACK_ANTIGRAVITY(s) STAT(JETPACK_ANTIGRAVITY, s)
70 #define PHYS_JETPACK_FUEL(s) STAT(JETPACK_FUEL, s)
71 #define PHYS_JETPACK_MAXSPEED_SIDE(s) STAT(JETPACK_MAXSPEED_SIDE, s)
72 #define PHYS_JETPACK_MAXSPEED_UP(s) STAT(JETPACK_MAXSPEED_UP, s)
73 #define PHYS_JETPACK_REVERSE_THRUST(s) STAT(JETPACK_REVERSE_THRUST, s)
75 #define PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS(s) STAT(MOVEVARS_JUMPSPEEDCAP_DISABLE_ONRAMPS, s)
76 #define PHYS_JUMPSTEP(s) STAT(MOVEVARS_JUMPSTEP, s)
77 #define PHYS_JUMPVELOCITY(s) STAT(MOVEVARS_JUMPVELOCITY, s)
79 #define PHYS_MAXAIRSPEED(s) STAT(MOVEVARS_MAXAIRSPEED, s)
80 #define PHYS_MAXAIRSTRAFESPEED(s) STAT(MOVEVARS_MAXAIRSTRAFESPEED, s)
81 #define PHYS_MAXSPEED(s) STAT(MOVEVARS_MAXSPEED, s)
83 #define PHYS_NOSTEP(s) STAT(NOSTEP, s)
84 #define PHYS_STEPHEIGHT(s) STAT(MOVEVARS_STEPHEIGHT, s)
86 #define PHYS_STOPSPEED(s) STAT(MOVEVARS_STOPSPEED, s)
88 #define PHYS_TRACK_CANJUMP(s) STAT(MOVEVARS_TRACK_CANJUMP, s)
90 #define PHYS_WALLFRICTION(s) STAT(MOVEVARS_WALLFRICTION, s)
92 #define PHYS_WARSOWBUNNY_ACCEL(s) STAT(MOVEVARS_WARSOWBUNNY_ACCEL, s)
93 #define PHYS_WARSOWBUNNY_AIRFORWARDACCEL(s) STAT(MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL, s)
94 #define PHYS_WARSOWBUNNY_BACKTOSIDERATIO(s) STAT(MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO, s)
95 #define PHYS_WARSOWBUNNY_TOPSPEED(s) STAT(MOVEVARS_WARSOWBUNNY_TOPSPEED, s)
96 #define PHYS_WARSOWBUNNY_TURNACCEL(s) STAT(MOVEVARS_WARSOWBUNNY_TURNACCEL, s)
98 #define UPWARD_VELOCITY_CLEARS_ONGROUND(s) STAT(GAMEPLAYFIX_UPVELOCITYCLEARSONGROUND, s)
100 #define PHYS_INPUT_BUTTON_ATCK(s) PHYS_INPUT_BUTTON_BUTTON1(s)
101 #define PHYS_INPUT_BUTTON_JUMP(s) PHYS_INPUT_BUTTON_BUTTON2(s)
102 #define PHYS_INPUT_BUTTON_ATCK2(s) PHYS_INPUT_BUTTON_BUTTON3(s)
103 #define PHYS_INPUT_BUTTON_ZOOM(s) PHYS_INPUT_BUTTON_BUTTON4(s)
104 #define PHYS_INPUT_BUTTON_CROUCH(s) PHYS_INPUT_BUTTON_BUTTON5(s)
105 #define PHYS_INPUT_BUTTON_HOOK(s) PHYS_INPUT_BUTTON_BUTTON6(s)
108 STATIC_INIT(PHYS_INPUT_BUTTON_HOOK)
110 localcmd("alias +hook +button6\n");
111 localcmd("alias -hook -button6\n");
115 #define PHYS_INPUT_BUTTON_INFO(s) PHYS_INPUT_BUTTON_BUTTON7(s)
116 #define PHYS_INPUT_BUTTON_DRAG(s) PHYS_INPUT_BUTTON_BUTTON8(s)
117 #define PHYS_INPUT_BUTTON_USE(s) PHYS_INPUT_BUTTON_BUTTON_USE(s)
118 #define PHYS_INPUT_BUTTON_CHAT(s) PHYS_INPUT_BUTTON_BUTTON_CHAT(s)
119 #define PHYS_INPUT_BUTTON_PRYDON(s) PHYS_INPUT_BUTTON_BUTTON_PRYDON(s)
120 #define PHYS_INPUT_BUTTON_ZOOMSCRIPT(s) PHYS_INPUT_BUTTON_BUTTON9(s)
121 #define PHYS_INPUT_BUTTON_JETPACK(s) PHYS_INPUT_BUTTON_BUTTON10(s)
124 STATIC_INIT(PHYS_INPUT_BUTTON_JETPACK)
126 localcmd("alias +jetpack +button10\n");
127 localcmd("alias -jetpack -button10\n");
131 // if more buttons are needed, start using impulse bits as buttons
133 #define PHYS_INPUT_BUTTON_BACKWARD(s) (PHYS_INPUT_MOVEVALUES(s).x < 0)
134 #define PHYS_INPUT_BUTTON_FORWARD(s) (PHYS_INPUT_MOVEVALUES(s).x > 0)
135 #define PHYS_INPUT_BUTTON_LEFT(s) (PHYS_INPUT_MOVEVALUES(s).y < 0)
136 #define PHYS_INPUT_BUTTON_RIGHT(s) (PHYS_INPUT_MOVEVALUES(s).y > 0)
138 // used for special commands and idle checking, not from the engine
140 #define PHYS_INPUT_BUTTON_MASK(s) ( \
141 (1 << 0) * PHYS_INPUT_BUTTON_ATCK(s) \
142 | (1 << 1) * PHYS_INPUT_BUTTON_JUMP(s) \
143 | (1 << 2) * PHYS_INPUT_BUTTON_ATCK2(s) \
144 | (1 << 3) * PHYS_INPUT_BUTTON_ZOOM(s) \
145 | (1 << 4) * PHYS_INPUT_BUTTON_CROUCH(s) \
146 | (1 << 5) * PHYS_INPUT_BUTTON_HOOK(s) \
147 | (1 << 6) * PHYS_INPUT_BUTTON_USE(s) \
148 | (1 << 7) * PHYS_INPUT_BUTTON_BACKWARD(s) \
149 | (1 << 8) * PHYS_INPUT_BUTTON_FORWARD(s) \
150 | (1 << 9) * PHYS_INPUT_BUTTON_LEFT(s) \
151 | (1 << 10) * PHYS_INPUT_BUTTON_RIGHT(s) \
154 #define IS_JUMP_HELD(s) (!((s).flags & FL_JUMPRELEASED))
155 #define SET_JUMP_HELD(s) ((s).flags &= ~FL_JUMPRELEASED)
156 #define UNSET_JUMP_HELD(s) ((s).flags |= FL_JUMPRELEASED)
158 #define WAS_ONGROUND(s) boolean((s).lastflags & FL_ONGROUND)
160 #define ITEMS_STAT(s) ((s).items)
162 .float teleport_time;
166 string autocvar_cl_jumpspeedcap_min;
167 string autocvar_cl_jumpspeedcap_max;
169 noref float pmove_waterjumptime;
171 const int FL_WATERJUMP = 2048; // player jumping out of water
172 const int FL_JUMPRELEASED = 4096; // for jump debouncing
184 #define IS_CLIENT(s) ((s).isplayermodel)
185 #define IS_PLAYER(s) ((s).isplayermodel)
186 #define IS_NOT_A_CLIENT(s) (!(s).isplayermodel)
187 #define isPushable(s) ((s).isplayermodel || (s).pushable || ((s).flags & FL_PROJECTILE))
189 //float player_multijump;
190 //float player_jumpheight;
192 #define PHYS_GRAVITY(s) STAT(MOVEVARS_GRAVITY, s)
194 #define PHYS_TELEPORT_TIME(s) ((s).teleport_time)
196 #define TICRATE ticrate
198 #define PHYS_INPUT_ANGLES(s) input_angles
200 #define PHYS_WORLD_ANGLES(s) input_angles
202 #define PHYS_INPUT_TIMELENGTH input_timelength
203 #define PHYS_INPUT_FRAMETIME serverdeltatime
205 #define PHYS_INPUT_MOVEVALUES(s) input_movevalues
207 #define PHYS_INPUT_BUTTON_BUTTON1(s) boolean(input_buttons & BIT(0))
208 #define PHYS_INPUT_BUTTON_BUTTON2(s) boolean(input_buttons & BIT(1))
209 #define PHYS_INPUT_BUTTON_BUTTON3(s) boolean(input_buttons & BIT(2))
210 #define PHYS_INPUT_BUTTON_BUTTON4(s) boolean(input_buttons & BIT(3))
211 #define PHYS_INPUT_BUTTON_BUTTON5(s) boolean(input_buttons & BIT(4))
212 #define PHYS_INPUT_BUTTON_BUTTON6(s) boolean(input_buttons & BIT(5))
213 #define PHYS_INPUT_BUTTON_BUTTON7(s) boolean(input_buttons & BIT(6))
214 #define PHYS_INPUT_BUTTON_BUTTON8(s) boolean(input_buttons & BIT(7))
215 #define PHYS_INPUT_BUTTON_BUTTON_USE(s) boolean(input_buttons & BIT(8))
216 #define PHYS_INPUT_BUTTON_BUTTON_CHAT(s) boolean(input_buttons & BIT(9))
217 #define PHYS_INPUT_BUTTON_BUTTON_PRYDON(s) boolean(input_buttons & BIT(10))
218 #define PHYS_INPUT_BUTTON_BUTTON9(s) boolean(input_buttons & BIT(11))
219 #define PHYS_INPUT_BUTTON_BUTTON10(s) boolean(input_buttons & BIT(12))
220 #define PHYS_INPUT_BUTTON_BUTTON11(s) boolean(input_buttons & BIT(13))
221 #define PHYS_INPUT_BUTTON_BUTTON12(s) boolean(input_buttons & BIT(14))
222 #define PHYS_INPUT_BUTTON_BUTTON13(s) boolean(input_buttons & BIT(15))
223 #define PHYS_INPUT_BUTTON_BUTTON14(s) boolean(input_buttons & BIT(16))
224 #define PHYS_INPUT_BUTTON_BUTTON15(s) boolean(input_buttons & BIT(17))
225 #define PHYS_INPUT_BUTTON_BUTTON16(s) boolean(input_buttons & BIT(18))
227 #define GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE (boolean(moveflags & MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE))
228 #define GAMEPLAYFIX_NOGRAVITYONGROUND (boolean(moveflags & MOVEFLAG_NOGRAVITYONGROUND))
229 #define GAMEPLAYFIX_Q2AIRACCELERATE (boolean(moveflags & MOVEFLAG_Q2AIRACCELERATE))
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)
235 #define PHYS_JUMPSPEEDCAP_MIN autocvar_cl_jumpspeedcap_min
236 #define PHYS_JUMPSPEEDCAP_MAX autocvar_cl_jumpspeedcap_max
238 #define PHYS_CL_TRACK_CANJUMP(s) STAT(MOVEVARS_CL_TRACK_CANJUMP, s)
239 // FIXME: 0 doesn't mean zero gravity
240 #define PHYS_ENTGRAVITY(s) STAT(MOVEVARS_ENTGRAVITY, s)
244 bool Physics_Valid(string thecvar);
246 .float stat_sv_airspeedlimit_nonqw = _STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW);
247 .float stat_sv_maxspeed = _STAT(MOVEVARS_MAXSPEED);
249 /** Not real stats */
250 .string jumpspeedcap_min;
251 .string jumpspeedcap_max;
253 #define PHYS_TELEPORT_TIME(s) ((s).teleport_time)
255 #define PHYS_GRAVITY(s) autocvar_sv_gravity
257 #define TICRATE sys_frametime
259 #define PHYS_INPUT_ANGLES(s) ((s).v_angle)
260 #define PHYS_WORLD_ANGLES(s) ((s).angles)
262 #define PHYS_INPUT_TIMELENGTH frametime
263 #define PHYS_INPUT_FRAMETIME sys_frametime
265 #define PHYS_INPUT_MOVEVALUES(s) ((s).movement)
267 #define PHYS_INPUT_BUTTON_BUTTON1(s) ((s).button0)
268 #define PHYS_INPUT_BUTTON_BUTTON2(s) ((s).button2)
269 #define PHYS_INPUT_BUTTON_BUTTON3(s) ((s).button3)
270 #define PHYS_INPUT_BUTTON_BUTTON4(s) ((s).button4)
271 #define PHYS_INPUT_BUTTON_BUTTON5(s) ((s).button5)
272 #define PHYS_INPUT_BUTTON_BUTTON6(s) ((s).button6)
273 #define PHYS_INPUT_BUTTON_BUTTON7(s) ((s).button7)
274 #define PHYS_INPUT_BUTTON_BUTTON8(s) ((s).button8)
275 #define PHYS_INPUT_BUTTON_BUTTON_USE(s) ((s).buttonuse)
276 #define PHYS_INPUT_BUTTON_BUTTON_CHAT(s) ((s).buttonchat)
277 #define PHYS_INPUT_BUTTON_BUTTON_PRYDON(s) ((s).cursor_active)
278 #define PHYS_INPUT_BUTTON_BUTTON9(s) ((s).button9)
279 #define PHYS_INPUT_BUTTON_BUTTON10(s) ((s).button10)
280 #define PHYS_INPUT_BUTTON_BUTTON11(s) ((s).button11)
281 #define PHYS_INPUT_BUTTON_BUTTON12(s) ((s).button12)
282 #define PHYS_INPUT_BUTTON_BUTTON13(s) ((s).button13)
283 #define PHYS_INPUT_BUTTON_BUTTON14(s) ((s).button14)
284 #define PHYS_INPUT_BUTTON_BUTTON15(s) ((s).button15)
285 #define PHYS_INPUT_BUTTON_BUTTON16(s) ((s).button16)
287 #define GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE autocvar_sv_gameplayfix_gravityunaffectedbyticrate
288 #define GAMEPLAYFIX_NOGRAVITYONGROUND autocvar_sv_gameplayfix_nogravityonground
289 #define GAMEPLAYFIX_Q2AIRACCELERATE autocvar_sv_gameplayfix_q2airaccelerate
291 #define IS_DUCKED(s) ((s).crouch)
292 #define SET_DUCKED(s) ((s).crouch = true)
293 #define UNSET_DUCKED(s) ((s).crouch = false)
295 #define PHYS_JUMPSPEEDCAP_MIN autocvar_sv_jumpspeedcap_min
296 #define PHYS_JUMPSPEEDCAP_MAX autocvar_sv_jumpspeedcap_max
298 #define PHYS_CL_TRACK_CANJUMP(s) ((s).cvar_cl_movement_track_canjump)
299 #define PHYS_ENTGRAVITY(s) ((s).gravity)
303 REGISTER_NET_C2S(setpause)
305 void unpause_update()
307 static bool waspaused;
308 bool ispaused = PHYS_INPUT_BUTTON_CHAT(this);
309 if (ispaused == waspaused) return;
310 waspaused = ispaused;
311 // if (!serverispaused) return; // TODO: find out somehow
312 if (ispaused) return; // ignore setting pause, server will get those presses anyway, but it won't get releases
313 int channel = MSG_C2S;
314 WriteHeader(channel, setpause);
315 WriteByte(channel, ispaused);
319 NET_HANDLE(setpause, bool)
321 bool ispaused = boolean(ReadByte());
322 PHYS_INPUT_BUTTON_CHAT(sender) = ispaused;