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