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