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