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