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