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