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