3 // Client/server mappings
6 // TODO: get rid of this random dumb include!
7 #include <common/state.qh>
15 .float swamp_slowdown;
20 .float spectatorspeed = _STAT(SPECTATORSPEED);
22 .float spectatorspeed;
27 .string lastclassname;
29 .float(entity,float) PlayerPhysplug;
30 float AdjustAirAccelQW(float accelqw, float factor);
32 bool IsFlying(entity a);
34 #define PHYS_PL_MAX(s) STAT(PL_MAX, s)
35 #define PHYS_PL_MIN(s) STAT(PL_MIN, s)
36 #define PHYS_PL_CROUCH_MAX(s) STAT(PL_CROUCH_MAX, s)
37 #define PHYS_PL_CROUCH_MIN(s) STAT(PL_CROUCH_MIN, s)
39 #define PHYS_PL_VIEWOFS(s) STAT(PL_VIEW_OFS, s)
40 #define PHYS_PL_CROUCH_VIEWOFS(s) STAT(PL_CROUCH_VIEW_OFS, s)
42 #define PHYS_VIEWHEIGHT(s) STAT(VIEWHEIGHT, s)
43 #define PHYS_HEALTH(s) STAT(HEALTH, s)
45 #define BUFFS_STAT(s) STAT(BUFFS, s)
47 #define PHYS_ACCELERATE(s) STAT(MOVEVARS_ACCELERATE, s)
48 #define PHYS_AIRACCELERATE(s) STAT(MOVEVARS_AIRACCELERATE, s)
49 #define PHYS_AIRACCEL_QW(s) STAT(MOVEVARS_AIRACCEL_QW, s)
50 #define PHYS_AIRACCEL_QW_STRETCHFACTOR(s) STAT(MOVEVARS_AIRACCEL_QW_STRETCHFACTOR, s)
51 #define PHYS_AIRACCEL_SIDEWAYS_FRICTION(s) STAT(MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION, s)
52 #define PHYS_AIRCONTROL(s) STAT(MOVEVARS_AIRCONTROL, s)
53 #define PHYS_AIRCONTROL_PENALTY(s) STAT(MOVEVARS_AIRCONTROL_PENALTY, s)
54 #define PHYS_AIRCONTROL_POWER(s) STAT(MOVEVARS_AIRCONTROL_POWER, s)
55 #define PHYS_AIRCONTROL_BACKWARDS(s) STAT(MOVEVARS_AIRCONTROL_BACKWARDS, s)
56 #define PHYS_AIRCONTROL_SIDEWARDS(s) STAT(MOVEVARS_AIRCONTROL_SIDEWARDS, s)
57 #define PHYS_AIRSPEEDLIMIT_NONQW(s) STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW, s)
58 #define PHYS_AIRSTOPACCELERATE(s) STAT(MOVEVARS_AIRSTOPACCELERATE, s)
59 #define PHYS_AIRSTRAFEACCELERATE(s) STAT(MOVEVARS_AIRSTRAFEACCELERATE, s)
60 #define PHYS_AIRSTRAFEACCEL_QW(s) STAT(MOVEVARS_AIRSTRAFEACCEL_QW, s)
62 #define PHYS_AMMO_FUEL(s) STAT(FUEL, s)
64 #define PHYS_DODGING_FROZEN(s) STAT(DODGING_FROZEN, s)
66 #define PHYS_FRICTION(s) STAT(MOVEVARS_FRICTION, s)
67 #define PHYS_FRICTION_ONLAND(s) STAT(MOVEVARS_FRICTION_ONLAND, s)
68 #define PHYS_FRICTION_SLICK(s) STAT(MOVEVARS_FRICTION_SLICK, s)
70 #define PHYS_FROZEN(s) STAT(FROZEN, s)
72 #define PHYS_HIGHSPEED(s) STAT(MOVEVARS_HIGHSPEED, s)
74 #define PHYS_JETPACK_ACCEL_SIDE(s) STAT(JETPACK_ACCEL_SIDE, s)
75 #define PHYS_JETPACK_ACCEL_UP(s) STAT(JETPACK_ACCEL_UP, s)
76 #define PHYS_JETPACK_ANTIGRAVITY(s) STAT(JETPACK_ANTIGRAVITY, s)
77 #define PHYS_JETPACK_FUEL(s) STAT(JETPACK_FUEL, s)
78 #define PHYS_JETPACK_MAXSPEED_SIDE(s) STAT(JETPACK_MAXSPEED_SIDE, s)
79 #define PHYS_JETPACK_MAXSPEED_UP(s) STAT(JETPACK_MAXSPEED_UP, s)
80 #define PHYS_JETPACK_REVERSE_THRUST(s) STAT(JETPACK_REVERSE_THRUST, s)
82 #define PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS(s) STAT(MOVEVARS_JUMPSPEEDCAP_DISABLE_ONRAMPS, NULL)
83 #define PHYS_JUMPVELOCITY(s) STAT(MOVEVARS_JUMPVELOCITY, s)
85 #define PHYS_MAXAIRSPEED(s) STAT(MOVEVARS_MAXAIRSPEED, s)
86 #define PHYS_MAXAIRSTRAFESPEED(s) STAT(MOVEVARS_MAXAIRSTRAFESPEED, s)
87 #define PHYS_MAXSPEED(s) STAT(MOVEVARS_MAXSPEED, s)
89 #define PHYS_STOPSPEED(s) STAT(MOVEVARS_STOPSPEED, s)
91 #define PHYS_TRACK_CANJUMP(s) STAT(MOVEVARS_TRACK_CANJUMP, s)
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)
99 #define PHYS_SLICK_APPLYGRAVITY(s) STAT(SLICK_APPLYGRAVITY, NULL)
101 #define PHYS_INPUT_BUTTON_ATCK(s) PHYS_INPUT_BUTTON_BUTTON1(s)
102 #define PHYS_INPUT_BUTTON_JUMP(s) PHYS_INPUT_BUTTON_BUTTON2(s)
103 #define PHYS_INPUT_BUTTON_ATCK2(s) PHYS_INPUT_BUTTON_BUTTON3(s)
104 #define PHYS_INPUT_BUTTON_ZOOM(s) PHYS_INPUT_BUTTON_BUTTON4(s)
105 #define PHYS_INPUT_BUTTON_CROUCH(s) PHYS_INPUT_BUTTON_BUTTON5(s)
106 #define PHYS_INPUT_BUTTON_HOOK(s) PHYS_INPUT_BUTTON_BUTTON6(s)
109 STATIC_INIT(PHYS_INPUT_BUTTON_HOOK)
111 localcmd("alias +hook +button6\n");
112 localcmd("alias -hook -button6\n");
116 #define PHYS_INPUT_BUTTON_INFO(s) PHYS_INPUT_BUTTON_BUTTON7(s)
117 #define PHYS_INPUT_BUTTON_DRAG(s) PHYS_INPUT_BUTTON_BUTTON8(s)
118 #define PHYS_INPUT_BUTTON_USE(s) PHYS_INPUT_BUTTON_BUTTON_USE(s)
119 #define PHYS_INPUT_BUTTON_CHAT(s) PHYS_INPUT_BUTTON_BUTTON_CHAT(s)
120 #define PHYS_INPUT_BUTTON_PRYDON(s) PHYS_INPUT_BUTTON_BUTTON_PRYDON(s)
121 #define PHYS_INPUT_BUTTON_ZOOMSCRIPT(s) PHYS_INPUT_BUTTON_BUTTON9(s)
122 #define PHYS_INPUT_BUTTON_JETPACK(s) PHYS_INPUT_BUTTON_BUTTON10(s)
123 #define PHYS_INPUT_BUTTON_DODGE(s) PHYS_INPUT_BUTTON_BUTTON11(s)
126 STATIC_INIT(PHYS_INPUT_BUTTON_JETPACK)
128 localcmd("alias +jetpack +button10\n");
129 localcmd("alias -jetpack -button10\n");
132 STATIC_INIT(PHYS_INPUT_BUTTON_DODGE)
134 localcmd("alias +dodge +button11\n");
135 localcmd("alias -dodge -button11\n");
139 // if more buttons are needed, start using impulse bits as buttons
141 #define PHYS_INPUT_BUTTON_BACKWARD(s) (PHYS_INPUT_MOVEVALUES(s).x < 0)
142 #define PHYS_INPUT_BUTTON_FORWARD(s) (PHYS_INPUT_MOVEVALUES(s).x > 0)
143 #define PHYS_INPUT_BUTTON_LEFT(s) (PHYS_INPUT_MOVEVALUES(s).y < 0)
144 #define PHYS_INPUT_BUTTON_RIGHT(s) (PHYS_INPUT_MOVEVALUES(s).y > 0)
146 // used for special commands and idle checking, not from the engine
148 #define PHYS_INPUT_BUTTON_MASK(s) ( \
149 (1 << 0) * PHYS_INPUT_BUTTON_ATCK(s) \
150 | (1 << 1) * PHYS_INPUT_BUTTON_JUMP(s) \
151 | (1 << 2) * PHYS_INPUT_BUTTON_ATCK2(s) \
152 | (1 << 3) * PHYS_INPUT_BUTTON_ZOOM(s) \
153 | (1 << 4) * PHYS_INPUT_BUTTON_CROUCH(s) \
154 | (1 << 5) * PHYS_INPUT_BUTTON_HOOK(s) \
155 | (1 << 6) * PHYS_INPUT_BUTTON_USE(s) \
156 | (1 << 7) * PHYS_INPUT_BUTTON_BACKWARD(s) \
157 | (1 << 8) * PHYS_INPUT_BUTTON_FORWARD(s) \
158 | (1 << 9) * PHYS_INPUT_BUTTON_LEFT(s) \
159 | (1 << 10) * PHYS_INPUT_BUTTON_RIGHT(s) \
162 #define IS_JUMP_HELD(s) (!((s).flags & FL_JUMPRELEASED))
163 #define SET_JUMP_HELD(s) ((s).flags &= ~FL_JUMPRELEASED)
164 #define UNSET_JUMP_HELD(s) ((s).flags |= FL_JUMPRELEASED)
166 #define WAS_ONGROUND(s) boolean((s).lastflags & FL_ONGROUND)
167 #define WAS_ONSLICK(s) boolean((s).lastflags & FL_ONSLICK)
169 #define ITEMS_STAT(s) ((s).items)
171 .float teleport_time;
172 #define PHYS_TELEPORT_TIME(s) ((s).teleport_time)
174 .float waterjump_time;
175 #define PHYS_WATERJUMP_TIME(s) ((s).waterjump_time)
179 #define PHYS_FIXANGLE(s) ('0 0 0')
181 string autocvar_cl_jumpspeedcap_min;
182 string autocvar_cl_jumpspeedcap_max;
184 const int FL_WATERJUMP = 2048; // player jumping out of water
185 const int FL_JUMPRELEASED = 4096; // for jump debouncing
197 #define IS_CLIENT(s) ((s).isplayermodel || (s) == csqcplayer)
198 #define IS_PLAYER(s) ((s).isplayermodel)
199 #define IS_NOT_A_CLIENT(s) (!(s).isplayermodel && (s) != csqcplayer)
200 #define isPushable(s) ((s).isplayermodel || (s).pushable || ((s).flags & FL_PROJECTILE))
202 //float player_multijump;
203 //float player_jumpheight;
205 #define PHYS_INPUT_ANGLES(s) input_angles
207 #define PHYS_WORLD_ANGLES(s) input_angles
209 #define PHYS_INPUT_TIMELENGTH input_timelength
210 #define PHYS_INPUT_FRAMETIME serverdeltatime
212 #define PHYS_INPUT_MOVEVALUES(s) input_movevalues
213 #define PHYS_CS(s) (s)
215 #define PHYS_INPUT_BUTTON_BUTTON1(s) boolean(input_buttons & BIT(0))
216 #define PHYS_INPUT_BUTTON_BUTTON2(s) boolean(input_buttons & BIT(1))
217 #define PHYS_INPUT_BUTTON_BUTTON3(s) boolean(input_buttons & BIT(2))
218 #define PHYS_INPUT_BUTTON_BUTTON4(s) boolean(input_buttons & BIT(3))
219 #define PHYS_INPUT_BUTTON_BUTTON5(s) boolean(input_buttons & BIT(4))
220 #define PHYS_INPUT_BUTTON_BUTTON6(s) boolean(input_buttons & BIT(5))
221 #define PHYS_INPUT_BUTTON_BUTTON7(s) boolean(input_buttons & BIT(6))
222 #define PHYS_INPUT_BUTTON_BUTTON8(s) boolean(input_buttons & BIT(7))
223 #define PHYS_INPUT_BUTTON_BUTTON_USE(s) boolean(input_buttons & BIT(8))
224 #define PHYS_INPUT_BUTTON_BUTTON_CHAT(s) boolean(input_buttons & BIT(9))
225 #define PHYS_INPUT_BUTTON_BUTTON_PRYDON(s) boolean(input_buttons & BIT(10))
226 #define PHYS_INPUT_BUTTON_BUTTON9(s) boolean(input_buttons & BIT(11))
227 #define PHYS_INPUT_BUTTON_BUTTON10(s) boolean(input_buttons & BIT(12))
228 #define PHYS_INPUT_BUTTON_BUTTON11(s) boolean(input_buttons & BIT(13))
229 #define PHYS_INPUT_BUTTON_BUTTON12(s) boolean(input_buttons & BIT(14))
230 #define PHYS_INPUT_BUTTON_BUTTON13(s) boolean(input_buttons & BIT(15))
231 #define PHYS_INPUT_BUTTON_BUTTON14(s) boolean(input_buttons & BIT(16))
232 #define PHYS_INPUT_BUTTON_BUTTON15(s) boolean(input_buttons & BIT(17))
233 #define PHYS_INPUT_BUTTON_BUTTON16(s) boolean(input_buttons & BIT(18))
235 #define IS_DUCKED(s) (boolean((s).flags & FL_DUCKED))
236 #define SET_DUCKED(s) ((s).flags |= FL_DUCKED)
237 #define UNSET_DUCKED(s) ((s).flags &= ~FL_DUCKED)
239 #define PHYS_JUMPSPEEDCAP_MIN autocvar_cl_jumpspeedcap_min
240 #define PHYS_JUMPSPEEDCAP_MAX autocvar_cl_jumpspeedcap_max
242 #define PHYS_CL_TRACK_CANJUMP(s) STAT(MOVEVARS_CL_TRACK_CANJUMP, s)
246 #define PHYS_FIXANGLE(s) ((s).fixangle)
248 bool Physics_Valid(string thecvar);
250 void Physics_UpdateStats(entity this);
252 void PM_UpdateButtons(entity this, entity store);
254 .float stat_sv_airspeedlimit_nonqw = _STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW);
255 .float stat_sv_maxspeed = _STAT(MOVEVARS_MAXSPEED);
257 /** Not real stats */
258 .string jumpspeedcap_min;
259 .string jumpspeedcap_max;
261 #define PHYS_INPUT_ANGLES(s) ((s).v_angle)
262 #define PHYS_WORLD_ANGLES(s) ((s).angles)
264 #define PHYS_INPUT_TIMELENGTH frametime
265 #define PHYS_INPUT_FRAMETIME sys_frametime
267 #define PHYS_INPUT_MOVEVALUES(s) CS(s).movement
268 #define PHYS_CS(s) CS(s)
270 #define PHYS_INPUT_BUTTON_BUTTON1(s) (CS(s).button0)
271 #define PHYS_INPUT_BUTTON_BUTTON2(s) (CS(s).button2)
272 #define PHYS_INPUT_BUTTON_BUTTON3(s) (CS(s).button3)
273 #define PHYS_INPUT_BUTTON_BUTTON4(s) (CS(s).button4)
274 #define PHYS_INPUT_BUTTON_BUTTON5(s) (CS(s).button5)
275 #define PHYS_INPUT_BUTTON_BUTTON6(s) (CS(s).button6)
276 #define PHYS_INPUT_BUTTON_BUTTON7(s) (CS(s).button7)
277 #define PHYS_INPUT_BUTTON_BUTTON8(s) (CS(s).button8)
278 #define PHYS_INPUT_BUTTON_BUTTON_USE(s) (CS(s).buttonuse)
279 #define PHYS_INPUT_BUTTON_BUTTON_CHAT(s) (CS(s).buttonchat)
280 #define PHYS_INPUT_BUTTON_BUTTON_PRYDON(s) (CS(s).cursor_active)
281 #define PHYS_INPUT_BUTTON_BUTTON9(s) (CS(s).button9)
282 #define PHYS_INPUT_BUTTON_BUTTON10(s) (CS(s).button10)
283 #define PHYS_INPUT_BUTTON_BUTTON11(s) (CS(s).button11)
284 #define PHYS_INPUT_BUTTON_BUTTON12(s) (CS(s).button12)
285 #define PHYS_INPUT_BUTTON_BUTTON13(s) (CS(s).button13)
286 #define PHYS_INPUT_BUTTON_BUTTON14(s) (CS(s).button14)
287 #define PHYS_INPUT_BUTTON_BUTTON15(s) (CS(s).button15)
288 #define PHYS_INPUT_BUTTON_BUTTON16(s) (CS(s).button16)
290 #define IS_DUCKED(s) ((s).crouch)
291 #define SET_DUCKED(s) ((s).crouch = true)
292 #define UNSET_DUCKED(s) ((s).crouch = false)
294 #define PHYS_JUMPSPEEDCAP_MIN autocvar_sv_jumpspeedcap_min
295 #define PHYS_JUMPSPEEDCAP_MAX autocvar_sv_jumpspeedcap_max
297 #define PHYS_CL_TRACK_CANJUMP(s) ((s).cvar_cl_movement_track_canjump)
302 // FIXME/EXPLAINME: why? Mario: because
303 vector autocvar_sv_player_maxs = '16 16 45';
304 vector autocvar_sv_player_mins = '-16 -16 -24';
305 vector autocvar_sv_player_viewoffset = '0 0 35';
306 vector autocvar_sv_player_crouch_maxs = '16 16 25';
307 vector autocvar_sv_player_crouch_mins = '-16 -16 -24';
308 vector autocvar_sv_player_crouch_viewoffset = '0 0 20';
309 //vector autocvar_sv_player_headsize = '24 24 12';
312 REGISTER_NET_C2S(setpause)
314 void unpause_update()
316 static bool waspaused;
317 bool ispaused = PHYS_INPUT_BUTTON_CHAT(this);
318 if (ispaused == waspaused) return;
319 waspaused = ispaused;
320 // if (!serverispaused) return; // TODO: find out somehow
321 if (ispaused) return; // ignore setting pause, server will get those presses anyway, but it won't get releases
322 int channel = MSG_C2S;
323 WriteHeader(channel, setpause);
324 WriteByte(channel, ispaused);
328 NET_HANDLE(setpause, bool)
330 bool ispaused = boolean(ReadByte());
331 PHYS_INPUT_BUTTON_CHAT(sender) = ispaused;