Also cut the veolcity of predators, the closer they are to swallowing. Do it more...
[voretournament/voretournament.git] / data / qcsrc / server / cl_physics.qc
1 .float race_penalty;\r
2 .float restart_jump;\r
3 \r
4 float sv_accelerate;\r
5 float sv_friction;\r
6 float sv_maxspeed;\r
7 float sv_airaccelerate;\r
8 float sv_maxairspeed;\r
9 float sv_stopspeed;\r
10 float sv_gravity;\r
11 float sv_airaccel_sideways_friction;\r
12 float sv_airaccel_qw;\r
13 float sv_airstopaccelerate;\r
14 float sv_airstrafeaccelerate;\r
15 float sv_maxairstrafespeed;\r
16 float sv_aircontrol;\r
17 float sv_warsowbunny_airforwardaccel;\r
18 float sv_warsowbunny_accel;\r
19 float sv_warsowbunny_topspeed;\r
20 float sv_warsowbunny_turnaccel;\r
21 float sv_warsowbunny_backtosideratio;\r
22 \r
23 .float ladder_time;\r
24 .entity ladder_entity;\r
25 .float gravity;\r
26 .float swamp_slowdown;\r
27 .float lastflags;\r
28 .float lastground;\r
29 .float wasFlying;\r
30 .float spectatorspeed;\r
31 \r
32 .float multijump_count;\r
33 .float multijump_ready;\r
34 .float prevjumpbutton;\r
35 .float prevlastteleporttime;\r
36 \r
37 /*\r
38 =============\r
39 PlayerJump\r
40 \r
41 When you press the jump key\r
42 =============\r
43 */\r
44 void PlayerJump (void)\r
45 {\r
46         float mjumpheight;\r
47         float doublejump;\r
48 \r
49         doublejump = FALSE;\r
50         if (cvar("sv_doublejump"))\r
51         {\r
52                 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);\r
53                 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)\r
54                         doublejump = TRUE;\r
55         }\r
56 \r
57         mjumpheight = cvar("sv_jumpvelocity");\r
58         if(self.scale) // we are smaller or larger, so we jump lower or higher\r
59                 mjumpheight *= (1 - cvar("g_healthsize_movementfactor")) + cvar("g_healthsize_movementfactor") * self.scale;\r
60         if(self.swallow_progress_prey) // cut jumping based on swallow progress for prey\r
61                 mjumpheight *= 1 - (self.swallow_progress_prey * cvar("g_balance_vore_swallow_speed_cutspd_prey"));\r
62         if(self.swallow_progress_pred) // cut jumping based on swallow progress for preds\r
63                 mjumpheight *= 1 - (self.swallow_progress_pred * cvar("g_balance_vore_swallow_speed_cutspd_pred"));\r
64 \r
65         if (self.waterlevel >= WATERLEVEL_SWIMMING)\r
66         {\r
67                 if (self.watertype == CONTENT_WATER)\r
68                         self.velocity_z = 200;\r
69                 else if (self.watertype == CONTENT_SLIME)\r
70                         self.velocity_z = 80;\r
71                 else\r
72                         self.velocity_z = 50;\r
73 \r
74                 return;\r
75         }\r
76 \r
77         if (cvar("g_multijump"))\r
78         {\r
79                 if(self.prevlastteleporttime != self.lastteleporttime)\r
80                 {\r
81                         // if we teleported above the ground, require touching the ground again to multi-jump\r
82                         self.multijump_ready = FALSE;\r
83                         if(self.flags & FL_ONGROUND)\r
84                                 self.prevlastteleporttime = self.lastteleporttime;\r
85                 }\r
86                 else if (self.prevjumpbutton == FALSE && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair\r
87                         self.multijump_ready = TRUE;  // this is necessary to check that we released the jump button and pressed it again\r
88                 else\r
89                         self.multijump_ready = FALSE;\r
90         }\r
91 \r
92         if(!doublejump && self.multijump_ready && self.multijump_count < cvar("g_multijump") && self.velocity_z > cvar("g_multijump_speed"))\r
93         {\r
94                 // doublejump = FALSE; // checked above in the if\r
95                 if (cvar("g_multijump"))\r
96                 {\r
97                         if (cvar("g_multijump_add") == 0) // in this case we make the z velocity == jumpvelocity\r
98                         {\r
99                                 if (self.velocity_z < mjumpheight)\r
100                                 {\r
101                                         doublejump = TRUE;\r
102                                         self.velocity_z = 0;\r
103                                 }\r
104                         }\r
105                         else\r
106                                 doublejump = TRUE;\r
107 \r
108                         if(doublejump)\r
109                         {\r
110                                 if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys\r
111                                 {\r
112                                         float curspeed;\r
113                                         vector wishvel, wishdir;\r
114 \r
115                                         curspeed = max(\r
116                                                 vlen(vec2(self.velocity)), // current xy speed\r
117                                                 vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs\r
118                                         );\r
119                                         makevectors(self.v_angle_y * '0 1 0');\r
120                                         wishvel = v_forward * self.movement_x + v_right * self.movement_y;\r
121                                         wishdir = normalize(wishvel);\r
122 \r
123                                         self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump\r
124                                         self.velocity_y = wishdir_y * curspeed;\r
125                                         // keep velocity_z unchanged!\r
126                                 }\r
127                                 if (cvar("g_multijump") > 0)\r
128                                         self.multijump_count += 1;\r
129                         }\r
130                 }\r
131                 self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump\r
132         }\r
133 \r
134         if (!doublejump)\r
135                 if (!(self.flags & FL_ONGROUND))\r
136                         return;\r
137 \r
138         if(!sv_pogostick)\r
139                 if (!(self.flags & FL_JUMPRELEASED))\r
140                         return;\r
141 \r
142         if(self.health <= g_bloodloss)\r
143                 return;\r
144 \r
145         if(cvar_string("sv_jumpspeedcap_min") != "")\r
146                 self.velocity_z = max(cvar("sv_jumpvelocity") * cvar("sv_jumpspeedcap_min"), self.velocity_z);\r
147         if(cvar_string("sv_jumpspeedcap_max") != "") {\r
148                 if(trace_fraction < 1 && trace_plane_normal_z < 0.98 && cvar("sv_jumpspeedcap_max_disable_on_ramps")) {\r
149                         // don't do jump speedcaps on ramps to preserve old voretournament ramjump style\r
150                         //print("Trace plane normal z: ", ftos(trace_plane_normal_z), ", disabling speed cap!\n");\r
151                 }\r
152                 else\r
153                         self.velocity_z = min(cvar("sv_jumpvelocity") * cvar("sv_jumpspeedcap_max"), self.velocity_z) + trace_ent.velocity_z;\r
154         }\r
155 \r
156         if(!(self.lastflags & FL_ONGROUND))\r
157         {\r
158                 if(cvar("speedmeter"))\r
159                         dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));\r
160                 if(self.lastground < time - 0.3)\r
161                 {\r
162                         self.velocity_x *= (1 - cvar("sv_friction_on_land"));\r
163                         self.velocity_y *= (1 - cvar("sv_friction_on_land"));\r
164                 }\r
165                 if(self.jumppadcount > 1)\r
166                         dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));\r
167                 self.jumppadcount = 0;\r
168         }\r
169 \r
170         self.velocity_z = self.velocity_z + mjumpheight;\r
171         self.oldvelocity_z = self.velocity_z;\r
172 \r
173         self.flags &~= FL_ONGROUND;\r
174         self.flags &~= FL_JUMPRELEASED;\r
175 \r
176         if (self.crouch)\r
177                 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);\r
178         else\r
179                 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);\r
180 \r
181         if(g_jump_grunt)\r
182                 PlayerSound(self, playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);\r
183 \r
184         self.restart_jump = -1; // restart jump anim next time\r
185         // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)\r
186 }\r
187 \r
188 void CheckWaterJump()\r
189 {\r
190         local vector start, end;\r
191 \r
192 // check for a jump-out-of-water\r
193         makevectors (self.angles);\r
194         start = self.origin;\r
195         start_z = start_z + 8;\r
196         v_forward_z = 0;\r
197         normalize(v_forward);\r
198         end = start + v_forward*24;\r
199         traceline (start, end, TRUE, self);\r
200         if (trace_fraction < 1)\r
201         {       // solid at waist\r
202                 start_z = start_z + self.maxs_z - 8;\r
203                 end = start + v_forward*24;\r
204                 self.movedir = trace_plane_normal * -50;\r
205                 traceline (start, end, TRUE, self);\r
206                 if (trace_fraction == 1)\r
207                 {       // open at eye level\r
208                         self.flags |= FL_WATERJUMP;\r
209                         self.velocity_z = 225;\r
210                         self.flags &~= FL_JUMPRELEASED;\r
211                         self.teleport_time = time + 2;  // safety net\r
212                         return;\r
213                 }\r
214         }\r
215 };\r
216 \r
217 float racecar_angle(float forward, float down)\r
218 {\r
219         float ret, angle_mult;\r
220 \r
221         if(forward < 0)\r
222         {\r
223                 forward = -forward;\r
224                 down = -down;\r
225         }\r
226 \r
227         ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);\r
228 \r
229         angle_mult = forward / (800 + forward);\r
230 \r
231         if(ret > 180)\r
232                 return ret * angle_mult + 360 * (1 - angle_mult);\r
233         else\r
234                 return ret * angle_mult;\r
235 }\r
236 \r
237 void RaceCarPhysics()\r
238 {\r
239         // using this move type for "big rigs"\r
240         // the engine does not push the entity!\r
241 \r
242         float accel, steer, f;\r
243         vector angles_save, rigvel;\r
244 \r
245         angles_save = self.angles;\r
246         accel = bound(-1, self.movement_x / sv_maxspeed, 1);\r
247         steer = bound(-1, self.movement_y / sv_maxspeed, 1);\r
248 \r
249         if(g_bugrigs_reverse_speeding)\r
250         {\r
251                 if(accel < 0)\r
252                 {\r
253                         // back accel is DIGITAL\r
254                         // to prevent speedhack\r
255                         if(accel < -0.5)\r
256                                 accel = -1;\r
257                         else\r
258                                 accel = 0;\r
259                 }\r
260         }\r
261 \r
262         self.angles_x = 0;\r
263         self.angles_z = 0;\r
264         makevectors(self.angles); // new forward direction!\r
265 \r
266         if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)\r
267         {\r
268                 float myspeed, upspeed, steerfactor, accelfactor;\r
269 \r
270                 myspeed = self.velocity * v_forward;\r
271                 upspeed = self.velocity * v_up;\r
272 \r
273                 // responsiveness factor for steering and acceleration\r
274                 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));\r
275                 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);\r
276 \r
277                 if(myspeed < 0 && g_bugrigs_reverse_spinning)\r
278                         steerfactor = -myspeed * g_bugrigs_steer;\r
279                 else\r
280                         steerfactor = -myspeed * f * g_bugrigs_steer;\r
281 \r
282                 if(myspeed < 0 && g_bugrigs_reverse_speeding)\r
283                         accelfactor = g_bugrigs_accel;\r
284                 else\r
285                         accelfactor = f * g_bugrigs_accel;\r
286                 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;\r
287 \r
288                 if(accel < 0)\r
289                 {\r
290                         if(myspeed > 0)\r
291                         {\r
292                                 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));\r
293                         }\r
294                         else\r
295                         {\r
296                                 if(!g_bugrigs_reverse_speeding)\r
297                                         myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);\r
298                         }\r
299                 }\r
300                 else\r
301                 {\r
302                         if(myspeed >= 0)\r
303                         {\r
304                                 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);\r
305                         }\r
306                         else\r
307                         {\r
308                                 if(g_bugrigs_reverse_stopping)\r
309                                         myspeed = 0;\r
310                                 else\r
311                                         myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));\r
312                         }\r
313                 }\r
314                 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec\r
315                 //MAXIMA: friction(v) := g_bugrigs_friction_floor;\r
316 \r
317                 self.angles_y += steer * frametime * steerfactor; // apply steering\r
318                 makevectors(self.angles); // new forward direction!\r
319 \r
320                 myspeed += accel * accelfactor * frametime;\r
321 \r
322                 rigvel = myspeed * v_forward + '0 0 1' * upspeed;\r
323         }\r
324         else\r
325         {\r
326                 myspeed = vlen(self.velocity);\r
327 \r
328                 // responsiveness factor for steering and acceleration\r
329                 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));\r
330                 steerfactor = -myspeed * f;\r
331                 self.angles_y += steer * frametime * steerfactor; // apply steering\r
332 \r
333                 rigvel = self.velocity;\r
334                 makevectors(self.angles); // new forward direction!\r
335         }\r
336 \r
337         rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);\r
338         //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;\r
339         //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);\r
340         //MAXIMA: solve(total_acceleration(v) = 0, v);\r
341 \r
342         if(g_bugrigs_planar_movement)\r
343         {\r
344                 vector rigvel_xy, neworigin, up;\r
345                 float mt;\r
346 \r
347                 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better\r
348                 rigvel_xy = rigvel;\r
349                 rigvel_xy_z = 0;\r
350 \r
351                 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions\r
352                         mt = MOVE_NORMAL;\r
353                 else\r
354                         mt = MOVE_NOMONSTERS;\r
355 \r
356                 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);\r
357                 up = trace_endpos - self.origin;\r
358 \r
359                 // BUG RIGS: align the move to the surface instead of doing collision testing\r
360                 // can we move?\r
361                 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);\r
362 \r
363                 // align to surface\r
364                 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);\r
365 \r
366                 if(trace_fraction < 0.5)\r
367                 {\r
368                         trace_fraction = 1;\r
369                         neworigin = self.origin;\r
370                 }\r
371                 else\r
372                         neworigin = trace_endpos;\r
373 \r
374                 if(trace_fraction < 1)\r
375                 {\r
376                         // now set angles_x so that the car points parallel to the surface\r
377                         self.angles = vectoangles(\r
378                                         '1 0 0' * v_forward_x * trace_plane_normal_z\r
379                                         +\r
380                                         '0 1 0' * v_forward_y * trace_plane_normal_z\r
381                                         +\r
382                                         '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)\r
383                                         );\r
384                         self.flags |= FL_ONGROUND;\r
385                 }\r
386                 else\r
387                 {\r
388                         // now set angles_x so that the car points forward, but is tilted in velocity direction\r
389                         self.flags &~= FL_ONGROUND;\r
390                 }\r
391 \r
392                 self.velocity = (neworigin - self.origin) * (1.0 / frametime);\r
393                 self.movetype = MOVETYPE_NOCLIP;\r
394         }\r
395         else\r
396         {\r
397                 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better\r
398                 self.velocity = rigvel;\r
399                 self.movetype = MOVETYPE_FLY;\r
400         }\r
401 \r
402         trace_fraction = 1;\r
403         tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);\r
404         if(trace_fraction != 1)\r
405         {\r
406                 self.angles = vectoangles2(\r
407                                 '1 0 0' * v_forward_x * trace_plane_normal_z\r
408                                 +\r
409                                 '0 1 0' * v_forward_y * trace_plane_normal_z\r
410                                 +\r
411                                 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),\r
412                                 trace_plane_normal\r
413                                 );\r
414         }\r
415         else\r
416         {\r
417                 vector vel_local;\r
418 \r
419                 vel_local_x = v_forward * self.velocity;\r
420                 vel_local_y = v_right * self.velocity;\r
421                 vel_local_z = v_up * self.velocity;\r
422 \r
423                 self.angles_x = racecar_angle(vel_local_x, vel_local_z);\r
424                 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);\r
425         }\r
426 \r
427         // smooth the angles\r
428         vector vf1, vu1, smoothangles;\r
429         makevectors(self.angles);\r
430         f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);\r
431         if(f == 0)\r
432                 f = 1;\r
433         vf1 = v_forward * f;\r
434         vu1 = v_up * f;\r
435         makevectors(angles_save);\r
436         vf1 = vf1 + v_forward * (1 - f);\r
437         vu1 = vu1 + v_up * (1 - f);\r
438         smoothangles = vectoangles2(vf1, vu1);\r
439         self.angles_x = -smoothangles_x;\r
440         self.angles_z =  smoothangles_z;\r
441 }\r
442 \r
443 float IsMoveInDirection(vector mv, float angle) // key mix factor\r
444 {\r
445         if(mv_x == 0 && mv_y == 0)\r
446                 return 0; // avoid division by zero\r
447         angle = RAD2DEG * atan2(mv_y, mv_x);\r
448         angle = remainder(angle, 360) / 45;\r
449         if(angle >  1)\r
450                 return 0;\r
451         if(angle < -1)\r
452                 return 0;\r
453         return 1 - fabs(angle);\r
454 }\r
455 \r
456 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)\r
457 {\r
458         float zspeed, xyspeed, dot, k;\r
459 \r
460 #if 0\r
461         // this doesn't play well with analog input\r
462         if(self.movement_x == 0 || self.movement_y != 0)\r
463                 return; // can't control movement if not moving forward or backward\r
464         k = 32;\r
465 #else\r
466         k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);\r
467         if(k <= 0)\r
468                 return;\r
469 #endif\r
470 \r
471         k *= bound(0, wishspeed / sv_maxairspeed, 1);\r
472 \r
473         zspeed = self.velocity_z;\r
474         self.velocity_z = 0;\r
475         xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);\r
476 \r
477         dot = self.velocity * wishdir;\r
478         k *= sv_aircontrol*dot*dot*frametime;\r
479 \r
480         if(dot > 0) // we can't change direction while slowing down\r
481         {\r
482                 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);\r
483         }\r
484 \r
485         self.velocity = self.velocity * xyspeed;\r
486         self.velocity_z = zspeed;\r
487 }\r
488 \r
489 // example config for alternate speed clamping:\r
490 //   sv_airaccel_qw 0.8\r
491 //   sv_airaccel_sideways_friction 0\r
492 //   prvm_globalset server speedclamp_mode 1\r
493 //     (or 2)\r
494 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float sidefric)\r
495 {\r
496         float vel_straight;\r
497         float vel_z;\r
498         vector vel_perpend;\r
499         float step;\r
500 \r
501         vector vel_xy;\r
502         float vel_xy_current;\r
503         float vel_xy_backward, vel_xy_forward;\r
504         float speedclamp;\r
505 \r
506         speedclamp = (accelqw < 0);\r
507         if(speedclamp)\r
508                 accelqw = -accelqw;\r
509 \r
510         if(cvar("g_balance_vore_weight_gravity") > 0) // apply stomach weight\r
511                 wishspeed *= 1 - bound(0, self.stomach_load * cvar("g_balance_vore_weight_speed"), 1);\r
512         if(self.scale) // we are smaller or larger, so we run slower or faster\r
513                 wishspeed *= (1 - cvar("g_healthsize_movementfactor")) + cvar("g_healthsize_movementfactor") * self.scale; \r
514         if(self.swallow_progress_prey) // cut speed based on swallow progress for prey\r
515                 wishspeed *= 1 - (self.swallow_progress_prey * cvar("g_balance_vore_swallow_speed_cutspd_prey"));\r
516         if(self.swallow_progress_pred) // cut speed based on swallow progress for preds\r
517                 wishspeed *= 1 - (self.swallow_progress_pred * cvar("g_balance_vore_swallow_speed_cutspd_pred"));\r
518 \r
519         if(cvar("sv_gameplayfix_q2airaccelerate"))\r
520                 wishspeed0 = wishspeed;\r
521 \r
522         vel_straight = self.velocity * wishdir;\r
523         vel_z = self.velocity_z;\r
524         vel_xy = self.velocity - vel_z * '0 0 1';\r
525         vel_perpend = vel_xy - vel_straight * wishdir;\r
526 \r
527         step = accel * frametime * wishspeed0;\r
528 \r
529         vel_xy_current  = vlen(vel_xy);\r
530         vel_xy_forward  = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);\r
531         vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);\r
532         if(vel_xy_backward < 0)\r
533                 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards\r
534 \r
535         vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);\r
536 \r
537         if(sidefric < 0 && (vel_perpend*vel_perpend))\r
538                 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"\r
539         {\r
540                 float f, fminimum;\r
541                 f = max(0, 1 + frametime * wishspeed * sidefric);\r
542                 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);\r
543                 // this cannot be > 1\r
544                 if(fminimum <= 0)\r
545                         vel_perpend = vel_perpend * max(0, f);\r
546                 else\r
547                 {\r
548                         fminimum = sqrt(fminimum);\r
549                         vel_perpend = vel_perpend * max(fminimum, f);\r
550                 }\r
551         }\r
552         else\r
553                 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);\r
554         \r
555         vel_xy = vel_straight * wishdir + vel_perpend;\r
556         \r
557         if(speedclamp)\r
558         {\r
559                 // ensure we don't get too fast or decelerate faster than we should\r
560                 vel_xy_current = min(vlen(vel_xy), vel_xy_forward);\r
561                 if(vel_xy_current > 0) // prevent division by zero\r
562                         vel_xy = normalize(vel_xy) * vel_xy_current;\r
563         }\r
564 \r
565         self.velocity = vel_xy + vel_z * '0 0 1';\r
566 }\r
567 \r
568 void PM_AirAccelerate(vector wishdir, float wishspeed)\r
569 {\r
570         vector curvel, wishvel, acceldir, curdir;\r
571         float addspeed, accelspeed, curspeed, f;\r
572         float dot;\r
573 \r
574         if(wishspeed == 0)\r
575                 return;\r
576 \r
577         curvel = self.velocity;\r
578         curvel_z = 0;\r
579         curspeed = vlen(curvel);\r
580 \r
581         if(wishspeed > curspeed * 1.01)\r
582         {\r
583                 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);\r
584         }\r
585         else\r
586         {\r
587                 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));\r
588                 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;\r
589         }\r
590         wishvel = wishdir * wishspeed;\r
591         acceldir = wishvel - curvel;\r
592         addspeed = vlen(acceldir);\r
593         acceldir = normalize(acceldir);\r
594 \r
595         accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);\r
596 \r
597         if(sv_warsowbunny_backtosideratio < 1)\r
598         {\r
599                 curdir = normalize(curvel);\r
600                 dot = acceldir * curdir;\r
601                 if(dot < 0)\r
602                         acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;\r
603         }\r
604 \r
605         self.velocity += accelspeed * acceldir;\r
606 }\r
607 \r
608 .vector movement_old;\r
609 .float buttons_old;\r
610 .vector v_angle_old;\r
611 .string lastclassname;\r
612 \r
613 .float() PlayerPhysplug;\r
614 \r
615 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";\r
616 .float specialcommand_pos;\r
617 void SpecialCommand()\r
618 {\r
619 #ifdef TETRIS\r
620         TetrisImpulse();\r
621 #else\r
622         if(!CheatImpulse(99))\r
623                 print("A hollow voice says \"Plugh\".\n");\r
624 #endif\r
625 }\r
626 \r
627 float speedaward_speed;\r
628 string speedaward_holder;\r
629 void race_send_speedaward(float msg)\r
630 {\r
631         // send the best speed of the round\r
632         WriteByte(msg, SVC_TEMPENTITY);\r
633         WriteByte(msg, TE_CSQC_RACE);\r
634         WriteByte(msg, RACE_NET_SPEED_AWARD);\r
635         WriteInt24_t(msg, floor(speedaward_speed+0.5));\r
636         WriteString(msg, speedaward_holder);\r
637 }\r
638 \r
639 float speedaward_alltimebest;\r
640 string speedaward_alltimebest_holder;\r
641 void race_send_speedaward_alltimebest(float msg)\r
642 {\r
643         // send the best speed\r
644         WriteByte(msg, SVC_TEMPENTITY);\r
645         WriteByte(msg, TE_CSQC_RACE);\r
646         WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);\r
647         WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));\r
648         WriteString(msg, speedaward_alltimebest_holder);\r
649 }\r
650 \r
651 string GetMapname(void);\r
652 float speedaward_lastupdate;\r
653 float speedaward_lastsent;\r
654 .float jumppadusetime;\r
655 void SV_PlayerPhysics()\r
656 {\r
657         local vector wishvel, wishdir, v;\r
658         local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;\r
659         string temps;\r
660         float buttons_prev;\r
661         float not_allowed_to_move;\r
662         string c;\r
663 \r
664     if(self.PlayerPhysplug)\r
665         if(self.PlayerPhysplug())\r
666             return;\r
667 \r
668         self.race_movetime_frac += frametime;\r
669         f = floor(self.race_movetime_frac);\r
670         self.race_movetime_frac -= f;\r
671         self.race_movetime_count += f;\r
672         self.race_movetime = self.race_movetime_frac + self.race_movetime_count;\r
673 \r
674         anticheat_physics();\r
675 \r
676         buttons = self.BUTTON_ATCK + 2 * self.BUTTON_JUMP + 4 * self.BUTTON_ATCK2 + 8 * self.BUTTON_ZOOM + 16 * self.BUTTON_CROUCH + 32 * self.BUTTON_JETPACK + 64 * self.BUTTON_USE + 128 * (self.movement_x < 0) + 256 * (self.movement_x > 0) + 512 * (self.movement_y < 0) + 1024 * (self.movement_y > 0);\r
677 \r
678         if(!buttons)\r
679                 c = "x";\r
680         else if(buttons == 1)\r
681                 c = "1";\r
682         else if(buttons == 2)\r
683                 c = " ";\r
684         else if(buttons == 128)\r
685                 c = "s";\r
686         else if(buttons == 256)\r
687                 c = "w";\r
688         else if(buttons == 512)\r
689                 c = "a";\r
690         else if(buttons == 1024)\r
691                 c = "d";\r
692         else\r
693                 c = "?";\r
694 \r
695         if(c == substring(specialcommand, self.specialcommand_pos, 1))\r
696         {\r
697                 self.specialcommand_pos += 1;\r
698                 if(self.specialcommand_pos >= strlen(specialcommand))\r
699                 {\r
700                         self.specialcommand_pos = 0;\r
701                         SpecialCommand();\r
702                         return;\r
703                 }\r
704         }\r
705         else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))\r
706                 self.specialcommand_pos = 0;\r
707 \r
708         if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)\r
709         {\r
710                 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)\r
711                         self.parm_idlesince = time;\r
712         }\r
713         buttons_prev = self.buttons_old;\r
714         self.buttons_old = buttons;\r
715         self.movement_old = self.movement;\r
716         self.v_angle_old = self.v_angle;\r
717 \r
718         if(time < self.nickspamtime)\r
719         if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))\r
720         {\r
721                 // slight annoyance for nick change scripts\r
722                 self.movement = -1 * self.movement;\r
723                 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_JETPACK = self.BUTTON_USE = 0;\r
724 \r
725                 if(self.nickspamcount >= cvar("g_nick_flood_penalty_red")) // if you are persistent and the slight annoyance above does not stop you, I'll show you!\r
726                 {\r
727                         self.angles_x = random() * 360;\r
728                         self.angles_y = random() * 360;\r
729                         // at least I'm not forcing retardedview by also assigning to angles_z\r
730                         self.fixangle = 1;\r
731                 }\r
732         }\r
733 \r
734         if (self.punchangle != '0 0 0')\r
735         {\r
736                 f = vlen(self.punchangle) - 15 * frametime;\r
737                 if (f > 0)\r
738                         self.punchangle = normalize(self.punchangle) * f;\r
739                 else\r
740                         self.punchangle = '0 0 0';\r
741         }\r
742 \r
743         if (self.punchvector != '0 0 0')\r
744         {\r
745                 f = vlen(self.punchvector) - 30 * frametime;\r
746                 if (f > 0)\r
747                         self.punchvector = normalize(self.punchvector) * f;\r
748                 else\r
749                         self.punchvector = '0 0 0';\r
750         }\r
751 \r
752         if (clienttype(self) == CLIENTTYPE_BOT)\r
753         {\r
754                 if(playerdemo_read())\r
755                         return;\r
756                 bot_think();\r
757         }\r
758 \r
759         self.items &~= IT_USING_JETPACK;\r
760 \r
761         if(self.classname == "player")\r
762         {\r
763                 if(self.race_penalty)\r
764                         if(time > self.race_penalty)\r
765                                 self.race_penalty = 0;\r
766 \r
767                 not_allowed_to_move = 0;\r
768                 if(self.race_penalty)\r
769                         not_allowed_to_move = 1;\r
770                 if(!cvar("sv_ready_restart_after_countdown"))\r
771                 if(time < game_starttime)\r
772                         not_allowed_to_move = 1;\r
773 \r
774                 if(not_allowed_to_move)\r
775                 {\r
776                         self.velocity = '0 0 0';\r
777                         self.movetype = MOVETYPE_NONE;\r
778                         self.disableclientprediction = 2;\r
779                 }\r
780                 else if(self.disableclientprediction == 2)\r
781                 {\r
782                         if(self.movetype == MOVETYPE_NONE)\r
783                                 self.movetype = MOVETYPE_WALK;\r
784                         self.disableclientprediction = 0;\r
785                 }\r
786         }\r
787 \r
788         if(self.stat_eaten)\r
789                 return;\r
790 \r
791         if (self.movetype == MOVETYPE_NONE)\r
792                 return;\r
793 \r
794         maxspd_mod = 1;\r
795 \r
796         swampspd_mod = 1;\r
797         if(self.in_swamp) {\r
798                 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");\r
799         }\r
800 \r
801         if(self.classname != "player")\r
802         {\r
803                 maxspd_mod = cvar("sv_spectator_speed_multiplier");\r
804                 if(!self.spectatorspeed)\r
805                         self.spectatorspeed = maxspd_mod;\r
806                 if(self.impulse && self.impulse <= 19)\r
807                 {\r
808                         if(self.lastclassname != "player")\r
809                         {\r
810                                 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)\r
811                                         self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);\r
812                                 else if(self.impulse == 11)\r
813                                         self.spectatorspeed = maxspd_mod;\r
814                                 else if(self.impulse == 12 || self.impulse == 16  || self.impulse == 19)\r
815                                         self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);\r
816                                 else if(self.impulse >= 1 && self.impulse <= 9)\r
817                                         self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);\r
818                         } // otherwise just clear\r
819                         self.impulse = 0;\r
820                 }\r
821                 maxspd_mod = self.spectatorspeed;\r
822         }\r
823 \r
824         spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;\r
825         if(self.speed != spd)\r
826         {\r
827                 self.speed = spd;\r
828                 temps = ftos(spd);\r
829                 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));\r
830                 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));\r
831                 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));\r
832                 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));\r
833         }\r
834 \r
835         maxspd_mod *= swampspd_mod; // only one common speed modder please!\r
836         swampspd_mod = 1;\r
837 \r
838         // if dead, behave differently\r
839         if (self.deadflag)\r
840                 goto end;\r
841 \r
842         if (!self.fixangle && !g_bugrigs)\r
843         {\r
844                 self.angles_x = 0;\r
845                 self.angles_y = self.v_angle_y;\r
846                 self.angles_z = 0;\r
847         }\r
848 \r
849         if(self.flags & FL_ONGROUND)\r
850         if(self.wasFlying)\r
851         {\r
852                 self.wasFlying = 0;\r
853 \r
854                 if(self.waterlevel < WATERLEVEL_SWIMMING)\r
855                 if(time >= self.ladder_time)\r
856                 if not(self.grabber)\r
857                 {\r
858                         self.nextstep = time + 0.3 + random() * 0.1;\r
859                         trace_dphitq3surfaceflags = 0;\r
860                         tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);\r
861                         if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)\r
862                         {\r
863                                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)\r
864                                         GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);\r
865                                 else\r
866                                         GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);\r
867                         }\r
868                 }\r
869         }\r
870 \r
871         if(IsFlying(self))\r
872                 self.wasFlying = 1;\r
873 \r
874         if(self.classname == "player")\r
875         {\r
876                 if(self.flags & FL_ONGROUND)\r
877                 {\r
878                         if (cvar("g_multijump") > 0)\r
879                                 self.multijump_count = 0;\r
880                         else\r
881                                 self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller\r
882                 }\r
883 \r
884                 if (self.BUTTON_JUMP)\r
885                         PlayerJump ();\r
886                 else\r
887                         self.flags |= FL_JUMPRELEASED;\r
888 \r
889                 if (self.waterlevel == WATERLEVEL_SWIMMING)\r
890                         CheckWaterJump ();\r
891                 self.prevjumpbutton = self.BUTTON_JUMP;\r
892         }\r
893 \r
894         if (self.flags & FL_WATERJUMP )\r
895         {\r
896                 self.velocity_x = self.movedir_x;\r
897                 self.velocity_y = self.movedir_y;\r
898                 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)\r
899                 {\r
900                         self.flags &~= FL_WATERJUMP;\r
901                         self.teleport_time = 0;\r
902                 }\r
903         }\r
904         else if (g_bugrigs && self.classname == "player")\r
905         {\r
906                 RaceCarPhysics();\r
907         }\r
908         else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)\r
909         {\r
910                 // noclipping or flying\r
911                 self.flags &~= FL_ONGROUND;\r
912 \r
913                 self.velocity = self.velocity * (1 - frametime * sv_friction);\r
914                 makevectors(self.v_angle);\r
915                 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;\r
916                 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;\r
917                 // acceleration\r
918                 wishdir = normalize(wishvel);\r
919                 wishspeed = vlen(wishvel);\r
920                 if (wishspeed > sv_maxspeed*maxspd_mod)\r
921                         wishspeed = sv_maxspeed*maxspd_mod;\r
922                 if (time >= self.teleport_time)\r
923                         PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);\r
924         }\r
925         else if (self.waterlevel >= WATERLEVEL_SWIMMING)\r
926         {\r
927                 // swimming\r
928                 self.flags &~= FL_ONGROUND;\r
929 \r
930                 makevectors(self.v_angle);\r
931                 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;\r
932                 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;\r
933                 if (wishvel == '0 0 0')\r
934                         wishvel = '0 0 -60'; // drift towards bottom\r
935 \r
936                 wishdir = normalize(wishvel);\r
937                 wishspeed = vlen(wishvel);\r
938                 if (wishspeed > sv_maxspeed*maxspd_mod)\r
939                         wishspeed = sv_maxspeed*maxspd_mod;\r
940                 wishspeed = wishspeed * 0.7;\r
941 \r
942                 // water friction\r
943                 self.velocity = self.velocity * (1 - frametime * sv_friction);\r
944 \r
945                 // water acceleration\r
946                 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);\r
947         }\r
948         else if (time < self.ladder_time)\r
949         {\r
950                 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water\r
951                 self.flags &~= FL_ONGROUND;\r
952 \r
953                 self.velocity = self.velocity * (1 - frametime * sv_friction);\r
954                 makevectors(self.v_angle);\r
955                 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;\r
956                 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;\r
957                 if (self.gravity)\r
958                         self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;\r
959                 else\r
960                         self.velocity_z = self.velocity_z + sv_gravity * frametime;\r
961                 if (self.ladder_entity.classname == "func_water")\r
962                 {\r
963                         f = vlen(wishvel);\r
964                         if (f > self.ladder_entity.speed)\r
965                                 wishvel = wishvel * (self.ladder_entity.speed / f);\r
966 \r
967                         self.watertype = self.ladder_entity.skin;\r
968                         f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;\r
969                         if ((self.origin_z + self.view_ofs_z) < f)\r
970                                 self.waterlevel = WATERLEVEL_SUBMERGED;\r
971                         else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)\r
972                                 self.waterlevel = WATERLEVEL_SWIMMING;\r
973                         else if ((self.origin_z + self.mins_z + 1) < f)\r
974                                 self.waterlevel = WATERLEVEL_WETFEET;\r
975                         else\r
976                         {\r
977                                 self.waterlevel = WATERLEVEL_NONE;\r
978                                 self.watertype = CONTENT_EMPTY;\r
979                         }\r
980                 }\r
981                 // acceleration\r
982                 wishdir = normalize(wishvel);\r
983                 wishspeed = vlen(wishvel);\r
984                 if (wishspeed > sv_maxspeed*maxspd_mod)\r
985                         wishspeed = sv_maxspeed*maxspd_mod;\r
986                 if (time >= self.teleport_time)\r
987                 {\r
988                         // water acceleration\r
989                         PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);\r
990                 }\r
991         }\r
992         else if ((self.items & IT_JETPACK) && self.BUTTON_JETPACK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO) && !self.stat_eaten)\r
993         {\r
994                 //makevectors(self.v_angle_y * '0 1 0');\r
995                 makevectors(self.v_angle);\r
996                 wishvel = v_forward * self.movement_x + v_right * self.movement_y;\r
997                 // add remaining speed as Z component\r
998                 maxairspd = sv_maxairspeed*max(1, maxspd_mod);\r
999                 // fix speedhacks :P\r
1000                 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);\r
1001                 // add the unused velocity as up component\r
1002                 wishvel_z = 0;\r
1003 \r
1004                 // if(self.BUTTON_JUMP)\r
1005                         wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));\r
1006 \r
1007                 // it is now normalized, so...\r
1008                 float a_side, a_up, a_add, a_diff;\r
1009                 a_side = cvar("g_jetpack_acceleration_side");\r
1010                 a_up = cvar("g_jetpack_acceleration_up");\r
1011                 a_add = cvar("g_jetpack_antigravity") * sv_gravity;\r
1012 \r
1013                 wishvel_x *= a_side;\r
1014                 wishvel_y *= a_side;\r
1015                 wishvel_z *= a_up;\r
1016                 wishvel_z += a_add;\r
1017 \r
1018                 float best;\r
1019                 best = 0;\r
1020                 //////////////////////////////////////////////////////////////////////////////////////\r
1021                 // finding the maximum over all vectors of above form\r
1022                 // with wishvel having an absolute value of 1\r
1023                 //////////////////////////////////////////////////////////////////////////////////////\r
1024                 // we're finding the maximum over\r
1025                 //   f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;\r
1026                 // for z in the range from -1 to 1\r
1027                 //////////////////////////////////////////////////////////////////////////////////////\r
1028                 // maximum is EITHER attained at the single extreme point:\r
1029                 a_diff = a_side * a_side - a_up * a_up;\r
1030                 if(a_diff != 0)\r
1031                 {\r
1032                         f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)\r
1033                         if(f > -1 && f < 1) // can it be attained?\r
1034                         {\r
1035                                 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;\r
1036                                 //print("middle\n");\r
1037                         }\r
1038                 }\r
1039                 // OR attained at z = 1:\r
1040                 f = (a_up + a_add) * (a_up + a_add);\r
1041                 if(f > best)\r
1042                 {\r
1043                         best = f;\r
1044                         //print("top\n");\r
1045                 }\r
1046                 // OR attained at z = -1:\r
1047                 f = (a_up - a_add) * (a_up - a_add);\r
1048                 if(f > best)\r
1049                 {\r
1050                         best = f;\r
1051                         //print("bottom\n");\r
1052                 }\r
1053                 best = sqrt(best);\r
1054                 //////////////////////////////////////////////////////////////////////////////////////\r
1055 \r
1056                 //print("best possible acceleration: ", ftos(best), "\n");\r
1057 \r
1058                 float fxy, fz;\r
1059                 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);\r
1060                 if(wishvel_z - sv_gravity > 0)\r
1061                         fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);\r
1062                 else\r
1063                         fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);\r
1064 \r
1065                 float fvel;\r
1066                 fvel = vlen(wishvel);\r
1067                 wishvel_x *= fxy;\r
1068                 wishvel_y *= fxy;\r
1069                 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;\r
1070 \r
1071                 fvel = min(1, vlen(wishvel) / best);\r
1072                 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))\r
1073                         f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));\r
1074                 else\r
1075                         f = 1;\r
1076 \r
1077                 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");\r
1078 \r
1079                 if (f > 0 && wishvel != '0 0 0')\r
1080                 {\r
1081                         self.velocity = self.velocity + wishvel * f * frametime;\r
1082                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
1083                                 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;\r
1084                         self.flags &~= FL_ONGROUND;\r
1085                         self.items |= IT_USING_JETPACK;\r
1086 \r
1087                         // jetpack also inhibits health regeneration, but only for 1 second\r
1088                         self.pauseregenhealth_finished = max(self.pauseregenhealth_finished, time + cvar("g_balance_pause_fuel_regen"));\r
1089                 }\r
1090         }\r
1091         else if (self.flags & FL_ONGROUND)\r
1092         {\r
1093                 // we get here if we ran out of ammo\r
1094                 if((self.items & IT_JETPACK) && self.BUTTON_JETPACK && !(buttons_prev & 32) && !self.stat_eaten)\r
1095                         sprint(self, "You don't have any fuel for the ^2Jetpack\n");\r
1096 \r
1097                 // walking\r
1098                 makevectors(self.v_angle_y * '0 1 0');\r
1099                 wishvel = v_forward * self.movement_x + v_right * self.movement_y;\r
1100 \r
1101                 if(!(self.lastflags & FL_ONGROUND))\r
1102                 {\r
1103                         if(cvar("speedmeter"))\r
1104                                 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));\r
1105                         if(self.lastground < time - 0.3)\r
1106                                 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));\r
1107                         if(self.jumppadcount > 1)\r
1108                                 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));\r
1109                         self.jumppadcount = 0;\r
1110                 }\r
1111 \r
1112 #ifdef LETS_TEST_FTEQCC\r
1113                 if(self.velocity_x || self.velocity_y)\r
1114                 {\r
1115                         // good\r
1116                 }\r
1117                 else\r
1118                 {\r
1119                         if(self.velocity_x)\r
1120                                 checkclient();\r
1121                         if(self.velocity_y)\r
1122                                 checkclient();\r
1123                 }\r
1124 #endif\r
1125 \r
1126                 v = self.velocity;\r
1127                 v_z = 0;\r
1128                 f = vlen(v);\r
1129                 if(f > 0)\r
1130                 {\r
1131                         if (f < sv_stopspeed)\r
1132                                 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;\r
1133                         else\r
1134                                 f = 1 - frametime * sv_friction;\r
1135                         if (f > 0)\r
1136                                 self.velocity = self.velocity * f;\r
1137                         else\r
1138                                 self.velocity = '0 0 0';\r
1139                 }\r
1140 \r
1141                 // acceleration\r
1142                 wishdir = normalize(wishvel);\r
1143                 wishspeed = vlen(wishvel);\r
1144                 if (wishspeed > sv_maxspeed*maxspd_mod)\r
1145                         wishspeed = sv_maxspeed*maxspd_mod;\r
1146                 if (self.crouch)\r
1147                         wishspeed = wishspeed * 0.5;\r
1148                 if (time >= self.teleport_time)\r
1149                         PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);\r
1150         }\r
1151         else\r
1152         {\r
1153                 float wishspeed0;\r
1154                 // we get here if we ran out of ammo\r
1155                 if((self.items & IT_JETPACK) && self.BUTTON_JETPACK && !(buttons_prev & 32) && !self.stat_eaten)\r
1156                         sprint(self, "You don't have any fuel for the ^2Jetpack\n");\r
1157 \r
1158                 if(maxspd_mod < 1)\r
1159                 {\r
1160                         maxairspd = sv_maxairspeed*maxspd_mod;\r
1161                         airaccel = sv_airaccelerate*maxspd_mod;\r
1162                 }\r
1163                 else\r
1164                 {\r
1165                         maxairspd = sv_maxairspeed;\r
1166                         airaccel = sv_airaccelerate;\r
1167                 }\r
1168                 // airborn\r
1169                 makevectors(self.v_angle_y * '0 1 0');\r
1170                 wishvel = v_forward * self.movement_x + v_right * self.movement_y;\r
1171                 // acceleration\r
1172                 wishdir = normalize(wishvel);\r
1173                 wishspeed = wishspeed0 = vlen(wishvel);\r
1174                 if (wishspeed0 > sv_maxspeed*maxspd_mod)\r
1175                         wishspeed0 = sv_maxspeed*maxspd_mod;\r
1176                 if (wishspeed > maxairspd)\r
1177                         wishspeed = maxairspd;\r
1178                 if (self.crouch)\r
1179                         wishspeed = wishspeed * 0.5;\r
1180                 if (time >= self.teleport_time)\r
1181                 {\r
1182                         float accelerating;\r
1183                         float wishspeed2;\r
1184                         float airaccelqw;\r
1185 \r
1186                         airaccelqw = sv_airaccel_qw;\r
1187                         accelerating = (self.velocity * wishdir > 0);\r
1188                         wishspeed2 = wishspeed;\r
1189 \r
1190                         // CPM\r
1191                         if(sv_airstopaccelerate)\r
1192                                 if(self.velocity * wishdir < 0)\r
1193                                         airaccel = sv_airstopaccelerate*maxspd_mod;\r
1194                         // this doesn't play well with analog input, but can't r\r
1195                         // fixed like the AirControl can. So, don't set the maxa\r
1196                         // cvars when you want to support analog input.\r
1197                         if(self.movement_x == 0 && self.movement_y != 0)\r
1198                         {\r
1199                                 if(sv_maxairstrafespeed)\r
1200                                 {\r
1201                                         wishspeed = min(wishspeed, sv_maxairstrafespeed*maxspd_mod);\r
1202                                         if(sv_maxairstrafespeed < sv_maxairspeed)\r
1203                                                 airaccelqw = 1;\r
1204                                 }\r
1205                                 if(sv_airstrafeaccelerate)\r
1206                                 {\r
1207                                         airaccel = sv_airstrafeaccelerate*maxspd_mod;\r
1208                                         if(sv_airstrafeaccelerate > sv_airaccelerate)\r
1209                                                 airaccelqw = 1;\r
1210                                 }\r
1211                         }\r
1212                         // !CPM\r
1213 \r
1214                         if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)\r
1215                                 PM_AirAccelerate(wishdir, wishspeed);\r
1216                         else\r
1217                                 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd);\r
1218 \r
1219                         if(sv_aircontrol)\r
1220                                 CPM_PM_Aircontrol(wishdir, wishspeed2);\r
1221                 }\r
1222         }\r
1223 \r
1224         if((g_cts || g_race) && self.classname != "observer") {\r
1225                 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {\r
1226                         speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');\r
1227                         speedaward_holder = self.netname;\r
1228                         speedaward_lastupdate = time;\r
1229                 }\r
1230                 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {\r
1231                         string rr;\r
1232                         if(g_cts)\r
1233                                 rr = CTS_RECORD;\r
1234                         else\r
1235                                 rr = RACE_RECORD;\r
1236                         race_send_speedaward(MSG_ALL);\r
1237                         speedaward_lastsent = speedaward_speed;\r
1238                         if (speedaward_speed > speedaward_alltimebest) {\r
1239                                 speedaward_alltimebest = speedaward_speed;\r
1240                                 speedaward_alltimebest_holder = speedaward_holder;\r
1241                                 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));\r
1242                                 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"), speedaward_alltimebest_holder);\r
1243                                 race_send_speedaward_alltimebest(MSG_ALL);\r
1244                         }\r
1245                 }\r
1246         }\r
1247 \r
1248         if(vlen(self.velocity) > cvar("g_deathspeed"))\r
1249                 Damage(self, world, world, 100000, DEATH_KILL, self.origin, '0 0 0');\r
1250 \r
1251 :end\r
1252         if(self.flags & FL_ONGROUND)\r
1253                 self.lastground = time;\r
1254 \r
1255         self.lastflags = self.flags;\r
1256         self.lastclassname = self.classname;\r
1257 };\r