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