11 .float spectatorspeed;
13 .float multijump_count;
14 .float multijump_ready;
15 .float prevjumpbutton;
21 When you press the jump key
24 void PlayerJump (void)
26 if(self.freezetag_frozen)
27 return; // no jumping in freezetag when frozen
33 if (autocvar_sv_doublejump)
35 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
36 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
40 // we MUST clip velocity here!
42 f = self.velocity * trace_plane_normal;
44 self.velocity -= f * trace_plane_normal;
48 mjumpheight = autocvar_sv_jumpvelocity;
49 if (self.waterlevel >= WATERLEVEL_SWIMMING)
51 if (self.watertype == CONTENT_WATER)
52 self.velocity_z = 200;
53 else if (self.watertype == CONTENT_SLIME)
61 if (autocvar_g_multijump)
63 if (self.prevjumpbutton == FALSE && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair
64 self.multijump_ready = TRUE; // this is necessary to check that we released the jump button and pressed it again
66 self.multijump_ready = FALSE;
69 if(!doublejump && self.multijump_ready && self.multijump_count < autocvar_g_multijump && self.velocity_z > autocvar_g_multijump_speed)
71 // doublejump = FALSE; // checked above in the if
72 if (autocvar_g_multijump)
74 if (autocvar_g_multijump_add == 0) // in this case we make the z velocity == jumpvelocity
76 if (self.velocity_z < mjumpheight)
87 if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
90 vector wishvel, wishdir;
93 vlen(vec2(self.velocity)), // current xy speed
94 vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
96 makevectors(self.v_angle_y * '0 1 0');
97 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
98 wishdir = normalize(wishvel);
100 self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
101 self.velocity_y = wishdir_y * curspeed;
102 // keep velocity_z unchanged!
104 if (autocvar_g_multijump > 0)
105 self.multijump_count += 1;
108 self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump
112 if (!(self.flags & FL_ONGROUND))
115 if(!sv_pogostick || self.cvar_cl_nopogostick)
116 if (!(self.flags & FL_JUMPRELEASED))
119 if(self.health <= g_bloodloss)
122 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
123 // velocity bounds. Final velocity is bound between (jumpheight *
124 // min + jumpheight) and (jumpheight * max + jumpheight);
126 if(autocvar_sv_jumpspeedcap_min != "")
130 minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min);
132 if (self.velocity_z < minjumpspeed)
133 mjumpheight += minjumpspeed - self.velocity_z;
136 if(autocvar_sv_jumpspeedcap_max != "")
138 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
139 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
141 if(!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && autocvar_sv_jumpspeedcap_max_disable_on_ramps))
145 maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max);
147 if (self.velocity_z > maxjumpspeed)
148 mjumpheight -= self.velocity_z - maxjumpspeed;
152 if(!(self.lastflags & FL_ONGROUND))
154 if(autocvar_speedmeter)
155 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
156 if(self.lastground < time - 0.3)
158 self.velocity_x *= (1 - autocvar_sv_friction_on_land);
159 self.velocity_y *= (1 - autocvar_sv_friction_on_land);
161 if(self.jumppadcount > 1)
162 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
163 self.jumppadcount = 0;
166 self.velocity_z = self.velocity_z + mjumpheight;
167 self.oldvelocity_z = self.velocity_z;
169 self.flags &~= FL_ONGROUND;
170 self.flags &~= FL_JUMPRELEASED;
173 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
175 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
178 PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
180 self.restart_jump = -1; // restart jump anim next time
181 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
184 void CheckWaterJump()
186 local vector start, end;
188 // check for a jump-out-of-water
189 makevectors (self.angles);
191 start_z = start_z + 8;
193 normalize(v_forward);
194 end = start + v_forward*24;
195 traceline (start, end, TRUE, self);
196 if (trace_fraction < 1)
198 start_z = start_z + self.maxs_z - 8;
199 end = start + v_forward*24;
200 self.movedir = trace_plane_normal * -50;
201 traceline (start, end, TRUE, self);
202 if (trace_fraction == 1)
203 { // open at eye level
204 self.flags |= FL_WATERJUMP;
205 self.velocity_z = 225;
206 self.flags &~= FL_JUMPRELEASED;
207 self.teleport_time = time + 2; // safety net
213 float racecar_angle(float forward, float down)
215 float ret, angle_mult;
223 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
225 angle_mult = forward / (800 + forward);
228 return ret * angle_mult + 360 * (1 - angle_mult);
230 return ret * angle_mult;
233 void RaceCarPhysics()
235 // using this move type for "big rigs"
236 // the engine does not push the entity!
238 float accel, steer, f, myspeed, steerfactor;
239 vector angles_save, rigvel;
241 angles_save = self.angles;
242 accel = bound(-1, self.movement_x / self.stat_sv_maxspeed, 1);
243 steer = bound(-1, self.movement_y / self.stat_sv_maxspeed, 1);
245 if(g_bugrigs_reverse_speeding)
249 // back accel is DIGITAL
250 // to prevent speedhack
260 makevectors(self.angles); // new forward direction!
262 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
264 float upspeed, accelfactor;
266 myspeed = self.velocity * v_forward;
267 upspeed = self.velocity * v_up;
269 // responsiveness factor for steering and acceleration
270 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
271 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
273 if(myspeed < 0 && g_bugrigs_reverse_spinning)
274 steerfactor = -myspeed * g_bugrigs_steer;
276 steerfactor = -myspeed * f * g_bugrigs_steer;
278 if(myspeed < 0 && g_bugrigs_reverse_speeding)
279 accelfactor = g_bugrigs_accel;
281 accelfactor = f * g_bugrigs_accel;
282 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
288 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
292 if(!g_bugrigs_reverse_speeding)
293 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
300 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
304 if(g_bugrigs_reverse_stopping)
307 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
310 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
311 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
313 self.angles_y += steer * frametime * steerfactor; // apply steering
314 makevectors(self.angles); // new forward direction!
316 myspeed += accel * accelfactor * frametime;
318 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
322 myspeed = vlen(self.velocity);
324 // responsiveness factor for steering and acceleration
325 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
326 steerfactor = -myspeed * f;
327 self.angles_y += steer * frametime * steerfactor; // apply steering
329 rigvel = self.velocity;
330 makevectors(self.angles); // new forward direction!
333 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
334 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
335 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
336 //MAXIMA: solve(total_acceleration(v) = 0, v);
338 if(g_bugrigs_planar_movement)
340 vector rigvel_xy, neworigin, up;
343 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
344 rigvel_xy = vec2(rigvel);
346 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
349 mt = MOVE_NOMONSTERS;
351 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
352 up = trace_endpos - self.origin;
354 // BUG RIGS: align the move to the surface instead of doing collision testing
356 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
359 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
361 if(trace_fraction < 0.5)
364 neworigin = self.origin;
367 neworigin = trace_endpos;
369 if(trace_fraction < 1)
371 // now set angles_x so that the car points parallel to the surface
372 self.angles = vectoangles(
373 '1 0 0' * v_forward_x * trace_plane_normal_z
375 '0 1 0' * v_forward_y * trace_plane_normal_z
377 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
379 self.flags |= FL_ONGROUND;
383 // now set angles_x so that the car points forward, but is tilted in velocity direction
384 self.flags &~= FL_ONGROUND;
387 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
388 self.movetype = MOVETYPE_NOCLIP;
392 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
393 self.velocity = rigvel;
394 self.movetype = MOVETYPE_FLY;
398 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
399 if(trace_fraction != 1)
401 self.angles = vectoangles2(
402 '1 0 0' * v_forward_x * trace_plane_normal_z
404 '0 1 0' * v_forward_y * trace_plane_normal_z
406 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
414 vel_local_x = v_forward * self.velocity;
415 vel_local_y = v_right * self.velocity;
416 vel_local_z = v_up * self.velocity;
418 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
419 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
423 vector vf1, vu1, smoothangles;
424 makevectors(self.angles);
425 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
430 makevectors(angles_save);
431 vf1 = vf1 + v_forward * (1 - f);
432 vu1 = vu1 + v_up * (1 - f);
433 smoothangles = vectoangles2(vf1, vu1);
434 self.angles_x = -smoothangles_x;
435 self.angles_z = smoothangles_z;
438 float IsMoveInDirection(vector mv, float angle) // key mix factor
440 if(mv_x == 0 && mv_y == 0)
441 return 0; // avoid division by zero
442 angle -= RAD2DEG * atan2(mv_y, mv_x);
443 angle = remainder(angle, 360) / 45;
448 return 1 - fabs(angle);
451 float GeomLerp(float a, float lerp, float b)
467 return a * pow(fabs(b / a), lerp);
470 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
472 float zspeed, xyspeed, dot, k;
475 // this doesn't play well with analog input
476 if(self.movement_x == 0 || self.movement_y != 0)
477 return; // can't control movement if not moving forward or backward
480 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
485 k *= bound(0, wishspeed / autocvar_sv_maxairspeed, 1);
487 zspeed = self.velocity_z;
489 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
491 dot = self.velocity * wishdir;
493 if(dot > 0) // we can't change direction while slowing down
495 k *= pow(dot, autocvar_sv_aircontrol_power)*frametime;
496 xyspeed = max(0, xyspeed - autocvar_sv_aircontrol_penalty * sqrt(max(0, 1 - dot*dot)) * k/32);
497 k *= autocvar_sv_aircontrol;
498 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
501 self.velocity = self.velocity * xyspeed;
502 self.velocity_z = zspeed;
505 float AdjustAirAccelQW(float accelqw, float factor)
507 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
510 // example config for alternate speed clamping:
511 // sv_airaccel_qw 0.8
512 // sv_airaccel_sideways_friction 0
513 // prvm_globalset server speedclamp_mode 1
515 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
523 float vel_xy_current;
524 float vel_xy_backward, vel_xy_forward;
527 if(stretchfactor > 0)
528 speedclamp = stretchfactor;
530 speedclamp = 1; // full clamping, no stretch
532 speedclamp = -1; // no clamping
537 if(autocvar_sv_gameplayfix_q2airaccelerate)
538 wishspeed0 = wishspeed;
540 vel_straight = self.velocity * wishdir;
541 vel_z = self.velocity_z;
542 vel_xy = vec2(self.velocity);
543 vel_perpend = vel_xy - vel_straight * wishdir;
545 step = accel * frametime * wishspeed0;
547 vel_xy_current = vlen(vel_xy);
549 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
550 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
551 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
552 if(vel_xy_backward < 0)
553 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
555 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
557 if(sidefric < 0 && (vel_perpend*vel_perpend))
558 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
561 f = max(0, 1 + frametime * wishspeed * sidefric);
562 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
563 // this cannot be > 1
565 vel_perpend = vel_perpend * max(0, f);
568 fminimum = sqrt(fminimum);
569 vel_perpend = vel_perpend * max(fminimum, f);
573 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
575 vel_xy = vel_straight * wishdir + vel_perpend;
579 float vel_xy_preclamp;
580 vel_xy_preclamp = vlen(vel_xy);
581 if(vel_xy_preclamp > 0) // prevent division by zero
583 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
584 if(vel_xy_current < vel_xy_preclamp)
585 vel_xy = vel_xy * (vel_xy_current / vel_xy_preclamp);
589 self.velocity = vel_xy + vel_z * '0 0 1';
592 void PM_AirAccelerate(vector wishdir, float wishspeed)
594 vector curvel, wishvel, acceldir, curdir;
595 float addspeed, accelspeed, curspeed, f;
601 curvel = self.velocity;
603 curspeed = vlen(curvel);
605 if(wishspeed > curspeed * 1.01)
607 wishspeed = min(wishspeed, curspeed + autocvar_sv_warsowbunny_airforwardaccel * self.stat_sv_maxspeed * frametime);
611 f = max(0, (autocvar_sv_warsowbunny_topspeed - curspeed) / (autocvar_sv_warsowbunny_topspeed - self.stat_sv_maxspeed));
612 wishspeed = max(curspeed, self.stat_sv_maxspeed) + autocvar_sv_warsowbunny_accel * f * self.stat_sv_maxspeed * frametime;
614 wishvel = wishdir * wishspeed;
615 acceldir = wishvel - curvel;
616 addspeed = vlen(acceldir);
617 acceldir = normalize(acceldir);
619 accelspeed = min(addspeed, autocvar_sv_warsowbunny_turnaccel * self.stat_sv_maxspeed * frametime);
621 if(autocvar_sv_warsowbunny_backtosideratio < 1)
623 curdir = normalize(curvel);
624 dot = acceldir * curdir;
626 acceldir = acceldir - (1 - autocvar_sv_warsowbunny_backtosideratio) * dot * curdir;
629 self.velocity += accelspeed * acceldir;
632 .vector movement_old;
635 .string lastclassname;
637 .float() PlayerPhysplug;
639 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
640 .float specialcommand_pos;
641 void SpecialCommand()
646 if(!CheatImpulse(99))
647 print("A hollow voice says \"Plugh\".\n");
651 float speedaward_speed;
652 string speedaward_holder;
653 string speedaward_uid;
654 void race_send_speedaward(float msg)
656 // send the best speed of the round
657 WriteByte(msg, SVC_TEMPENTITY);
658 WriteByte(msg, TE_CSQC_RACE);
659 WriteByte(msg, RACE_NET_SPEED_AWARD);
660 WriteInt24_t(msg, floor(speedaward_speed+0.5));
661 WriteString(msg, speedaward_holder);
664 float speedaward_alltimebest;
665 string speedaward_alltimebest_holder;
666 string speedaward_alltimebest_uid;
667 void race_send_speedaward_alltimebest(float msg)
669 // send the best speed
670 WriteByte(msg, SVC_TEMPENTITY);
671 WriteByte(msg, TE_CSQC_RACE);
672 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
673 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
674 WriteString(msg, speedaward_alltimebest_holder);
677 string GetMapname(void);
678 float speedaward_lastupdate;
679 float speedaward_lastsent;
680 void SV_PlayerPhysics()
682 local vector wishvel, wishdir, v;
683 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
686 float not_allowed_to_move;
689 WarpZone_PlayerPhysics_FixVAngle();
692 if(g_minstagib && (self.items & IT_INVINCIBLE))
693 maxspd_mod *= autocvar_g_minstagib_speed_highspeed;
696 maxspd_mod *= autocvar_g_nexball_basketball_carrier_highspeed;
698 maxspd_mod *= autocvar_g_keepaway_ballcarrier_highspeed;
702 if(self.runes & RUNE_SPEED)
704 if(self.runes & CURSE_SLOW)
705 maxspd_mod *= autocvar_g_balance_rune_speed_combo_highspeed;
707 maxspd_mod *= autocvar_g_balance_rune_speed_highspeed;
709 else if(self.runes & CURSE_SLOW)
711 maxspd_mod *= autocvar_g_balance_curse_slow_highspeed;
714 maxspd_mod *= autocvar_g_movement_highspeed;
716 // fix physics stats for g_movement_highspeed
717 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
718 if(autocvar_sv_airstrafeaccel_qw)
719 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
721 self.stat_sv_airstrafeaccel_qw = 0;
722 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
723 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
725 if(self.PlayerPhysplug)
726 if(self.PlayerPhysplug())
729 self.race_movetime_frac += frametime;
730 f = floor(self.race_movetime_frac);
731 self.race_movetime_frac -= f;
732 self.race_movetime_count += f;
733 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
737 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);
741 else if(buttons == 1)
743 else if(buttons == 2)
745 else if(buttons == 128)
747 else if(buttons == 256)
749 else if(buttons == 512)
751 else if(buttons == 1024)
756 if(c == substring(specialcommand, self.specialcommand_pos, 1))
758 self.specialcommand_pos += 1;
759 if(self.specialcommand_pos >= strlen(specialcommand))
761 self.specialcommand_pos = 0;
766 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
767 self.specialcommand_pos = 0;
769 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
771 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
772 self.parm_idlesince = time;
774 buttons_prev = self.buttons_old;
775 self.buttons_old = buttons;
776 self.movement_old = self.movement;
777 self.v_angle_old = self.v_angle;
779 if(time < self.nickspamtime)
780 if(self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
782 // slight annoyance for nick change scripts
783 self.movement = -1 * self.movement;
784 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
786 if(self.nickspamcount >= autocvar_g_nick_flood_penalty_red) // if you are persistent and the slight annoyance above does not stop you, I'll show you!
788 self.angles_x = random() * 360;
789 self.angles_y = random() * 360;
790 // at least I'm not forcing retardedview by also assigning to angles_z
791 self.fixangle = TRUE;
795 if (self.punchangle != '0 0 0')
797 f = vlen(self.punchangle) - 10 * frametime;
799 self.punchangle = normalize(self.punchangle) * f;
801 self.punchangle = '0 0 0';
804 if (self.punchvector != '0 0 0')
806 f = vlen(self.punchvector) - 30 * frametime;
808 self.punchvector = normalize(self.punchvector) * f;
810 self.punchvector = '0 0 0';
813 if (clienttype(self) == CLIENTTYPE_BOT)
815 if(playerdemo_read())
820 self.items &~= IT_USING_JETPACK;
822 if(self.classname == "player")
824 if(self.race_penalty)
825 if(time > self.race_penalty)
826 self.race_penalty = 0;
828 not_allowed_to_move = 0;
829 if(self.race_penalty)
830 not_allowed_to_move = 1;
831 if(!autocvar_sv_ready_restart_after_countdown)
832 if(time < game_starttime)
833 not_allowed_to_move = 1;
835 if(not_allowed_to_move)
837 self.velocity = '0 0 0';
838 self.movetype = MOVETYPE_NONE;
839 self.disableclientprediction = 2;
841 else if(self.disableclientprediction == 2)
843 if(self.movetype == MOVETYPE_NONE)
844 self.movetype = MOVETYPE_WALK;
845 self.disableclientprediction = 0;
849 if (self.movetype == MOVETYPE_NONE)
852 // when we get here, disableclientprediction cannot be 2
853 self.disableclientprediction = 0;
854 if(time < self.ladder_time)
855 self.disableclientprediction = 1;
857 MUTATOR_CALLHOOK(PlayerPhysics);
863 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
866 if(self.classname != "player")
868 maxspd_mod = autocvar_sv_spectator_speed_multiplier;
869 if(!self.spectatorspeed)
870 self.spectatorspeed = maxspd_mod;
871 if(self.impulse && self.impulse <= 19)
873 if(self.lastclassname != "player")
875 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
876 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
877 else if(self.impulse == 11)
878 self.spectatorspeed = maxspd_mod;
879 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
880 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
881 else if(self.impulse >= 1 && self.impulse <= 9)
882 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
883 } // otherwise just clear
886 maxspd_mod = self.spectatorspeed;
889 spd = max(self.stat_sv_maxspeed, autocvar_sv_maxairspeed) * maxspd_mod * swampspd_mod;
890 if(self.speed != spd)
894 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
895 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
896 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
897 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
900 maxspd_mod *= swampspd_mod; // only one common speed modder please!
903 // if dead, behave differently
907 if (!self.fixangle && !g_bugrigs)
910 self.angles_y = self.v_angle_y;
914 if(self.flags & FL_ONGROUND)
915 if(self.classname == "player") // no fall sounds for observers thank you very much
920 if(self.waterlevel < WATERLEVEL_SWIMMING)
921 if(time >= self.ladder_time)
924 self.nextstep = time + 0.3 + random() * 0.1;
925 trace_dphitq3surfaceflags = 0;
926 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
927 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
929 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
930 GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
932 GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
940 if(self.classname == "player")
942 if(self.flags & FL_ONGROUND)
944 if (autocvar_g_multijump > 0)
945 self.multijump_count = 0;
947 self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller
950 if (self.BUTTON_JUMP)
953 self.flags |= FL_JUMPRELEASED;
955 if (self.waterlevel == WATERLEVEL_SWIMMING)
957 self.prevjumpbutton = self.BUTTON_JUMP;
960 if (self.flags & FL_WATERJUMP )
962 self.velocity_x = self.movedir_x;
963 self.velocity_y = self.movedir_y;
964 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
966 self.flags &~= FL_WATERJUMP;
967 self.teleport_time = 0;
970 else if (g_bugrigs && self.classname == "player")
974 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
976 // noclipping or flying
977 self.flags &~= FL_ONGROUND;
979 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
980 makevectors(self.v_angle);
981 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
982 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
984 wishdir = normalize(wishvel);
985 wishspeed = vlen(wishvel);
986 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
987 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
988 if (time >= self.teleport_time)
989 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
991 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
994 self.flags &~= FL_ONGROUND;
996 makevectors(self.v_angle);
997 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
998 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
999 if (wishvel == '0 0 0')
1000 wishvel = '0 0 -60'; // drift towards bottom
1002 wishdir = normalize(wishvel);
1003 wishspeed = vlen(wishvel);
1004 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1005 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1006 wishspeed = wishspeed * 0.7;
1009 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
1011 // water acceleration
1012 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1014 else if (time < self.ladder_time)
1016 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
1017 self.flags &~= FL_ONGROUND;
1020 g = autocvar_sv_gravity * frametime;
1023 if(autocvar_sv_gameplayfix_gravityunaffectedbyticrate)
1026 self.velocity_z += g;
1029 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
1030 makevectors(self.v_angle);
1031 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
1032 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
1033 self.velocity_z += g;
1034 if (self.ladder_entity.classname == "func_water")
1037 if (f > self.ladder_entity.speed)
1038 wishvel = wishvel * (self.ladder_entity.speed / f);
1040 self.watertype = self.ladder_entity.skin;
1041 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1042 if ((self.origin_z + self.view_ofs_z) < f)
1043 self.waterlevel = WATERLEVEL_SUBMERGED;
1044 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1045 self.waterlevel = WATERLEVEL_SWIMMING;
1046 else if ((self.origin_z + self.mins_z + 1) < f)
1047 self.waterlevel = WATERLEVEL_WETFEET;
1050 self.waterlevel = WATERLEVEL_NONE;
1051 self.watertype = CONTENT_EMPTY;
1055 wishdir = normalize(wishvel);
1056 wishspeed = vlen(wishvel);
1057 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1058 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1059 if (time >= self.teleport_time)
1061 // water acceleration
1062 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1065 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!autocvar_g_jetpack_fuel || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
1067 //makevectors(self.v_angle_y * '0 1 0');
1068 makevectors(self.v_angle);
1069 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1070 // add remaining speed as Z component
1071 maxairspd = autocvar_sv_maxairspeed*max(1, maxspd_mod);
1072 // fix speedhacks :P
1073 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
1074 // add the unused velocity as up component
1077 // if(self.BUTTON_JUMP)
1078 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1080 // it is now normalized, so...
1081 float a_side, a_up, a_add, a_diff;
1082 a_side = autocvar_g_jetpack_acceleration_side;
1083 a_up = autocvar_g_jetpack_acceleration_up;
1084 a_add = autocvar_g_jetpack_antigravity * autocvar_sv_gravity;
1086 wishvel_x *= a_side;
1087 wishvel_y *= a_side;
1093 //////////////////////////////////////////////////////////////////////////////////////
1094 // finding the maximum over all vectors of above form
1095 // with wishvel having an absolute value of 1
1096 //////////////////////////////////////////////////////////////////////////////////////
1097 // we're finding the maximum over
1098 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1099 // for z in the range from -1 to 1
1100 //////////////////////////////////////////////////////////////////////////////////////
1101 // maximum is EITHER attained at the single extreme point:
1102 a_diff = a_side * a_side - a_up * a_up;
1105 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1106 if(f > -1 && f < 1) // can it be attained?
1108 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1109 //print("middle\n");
1112 // OR attained at z = 1:
1113 f = (a_up + a_add) * (a_up + a_add);
1119 // OR attained at z = -1:
1120 f = (a_up - a_add) * (a_up - a_add);
1124 //print("bottom\n");
1127 //////////////////////////////////////////////////////////////////////////////////////
1129 //print("best possible acceleration: ", ftos(best), "\n");
1132 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / autocvar_g_jetpack_maxspeed_side, 1);
1133 if(wishvel_z - autocvar_sv_gravity > 0)
1134 fz = bound(0, 1 - self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1136 fz = bound(0, 1 + self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1139 fvel = vlen(wishvel);
1142 wishvel_z = (wishvel_z - autocvar_sv_gravity) * fz + autocvar_sv_gravity;
1144 fvel = min(1, vlen(wishvel) / best);
1145 if(autocvar_g_jetpack_fuel && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1146 f = min(1, self.ammo_fuel / (autocvar_g_jetpack_fuel * frametime * fvel));
1150 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1152 if (f > 0 && wishvel != '0 0 0')
1154 self.velocity = self.velocity + wishvel * f * frametime;
1155 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1156 self.ammo_fuel -= autocvar_g_jetpack_fuel * frametime * fvel * f;
1157 self.flags &~= FL_ONGROUND;
1158 self.items |= IT_USING_JETPACK;
1160 // jetpack also inhibits health regeneration, but only for 1 second
1161 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1164 else if (self.flags & FL_ONGROUND)
1166 // we get here if we ran out of ammo
1167 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1168 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1171 makevectors(self.v_angle_y * '0 1 0');
1172 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1174 if(!(self.lastflags & FL_ONGROUND))
1176 if(autocvar_speedmeter)
1177 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1178 if(self.lastground < time - 0.3)
1179 self.velocity = self.velocity * (1 - autocvar_sv_friction_on_land);
1180 if(self.jumppadcount > 1)
1181 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1182 self.jumppadcount = 0;
1185 #ifdef LETS_TEST_FTEQCC
1186 if(self.velocity_x || self.velocity_y)
1204 if (f < autocvar_sv_stopspeed)
1205 f = 1 - frametime * (autocvar_sv_stopspeed / f) * autocvar_sv_friction;
1207 f = 1 - frametime * autocvar_sv_friction;
1209 self.velocity = self.velocity * f;
1211 self.velocity = '0 0 0';
1215 wishdir = normalize(wishvel);
1216 wishspeed = vlen(wishvel);
1217 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1218 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1220 wishspeed = wishspeed * 0.5;
1221 if (time >= self.teleport_time)
1222 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1227 // we get here if we ran out of ammo
1228 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1229 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1233 maxairspd = autocvar_sv_maxairspeed*maxspd_mod;
1234 airaccel = autocvar_sv_airaccelerate*maxspd_mod;
1238 maxairspd = autocvar_sv_maxairspeed;
1239 airaccel = autocvar_sv_airaccelerate;
1242 makevectors(self.v_angle_y * '0 1 0');
1243 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1245 wishdir = normalize(wishvel);
1246 wishspeed = wishspeed0 = vlen(wishvel);
1247 if (wishspeed0 > self.stat_sv_maxspeed*maxspd_mod)
1248 wishspeed0 = self.stat_sv_maxspeed*maxspd_mod;
1249 if (wishspeed > maxairspd)
1250 wishspeed = maxairspd;
1252 wishspeed = wishspeed * 0.5;
1253 if (time >= self.teleport_time)
1260 airaccelqw = self.stat_sv_airaccel_qw;
1261 accelerating = (self.velocity * wishdir > 0);
1262 wishspeed2 = wishspeed;
1265 if(autocvar_sv_airstopaccelerate)
1268 curdir = self.velocity;
1270 curdir = normalize(curdir);
1271 airaccel = airaccel + (autocvar_sv_airstopaccelerate*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1273 // note that for straight forward jumping:
1274 // step = accel * frametime * wishspeed0;
1275 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1277 // dv/dt = accel * maxspeed (when slow)
1278 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1279 // log dv/dt = logaccel + logmaxspeed (when slow)
1280 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1281 strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
1282 if(autocvar_sv_maxairstrafespeed)
1283 wishspeed = min(wishspeed, GeomLerp(autocvar_sv_maxairspeed*maxspd_mod, strafity, autocvar_sv_maxairstrafespeed*maxspd_mod));
1284 if(autocvar_sv_airstrafeaccelerate)
1285 airaccel = GeomLerp(airaccel, strafity, autocvar_sv_airstrafeaccelerate*maxspd_mod);
1286 if(self.stat_sv_airstrafeaccel_qw)
1287 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));
1290 if(autocvar_sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1291 PM_AirAccelerate(wishdir, wishspeed);
1293 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, autocvar_sv_airaccel_qw_stretchfactor, autocvar_sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw);
1295 if(autocvar_sv_aircontrol)
1296 CPM_PM_Aircontrol(wishdir, wishspeed2);
1300 if((g_cts || g_race) && self.classname != "observer") {
1301 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1302 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1303 speedaward_holder = self.netname;
1304 speedaward_uid = self.crypto_idfp;
1305 speedaward_lastupdate = time;
1307 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1313 race_send_speedaward(MSG_ALL);
1314 speedaward_lastsent = speedaward_speed;
1315 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") {
1316 speedaward_alltimebest = speedaward_speed;
1317 speedaward_alltimebest_holder = speedaward_holder;
1318 speedaward_alltimebest_uid = speedaward_uid;
1319 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1320 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1321 race_send_speedaward_alltimebest(MSG_ALL);
1327 xyspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y);
1328 if(self.weapon == WEP_NEX && autocvar_g_balance_nex_charge && autocvar_g_balance_nex_charge_velocity_rate && xyspeed > autocvar_g_balance_nex_charge_minspeed)
1330 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1331 xyspeed = min(xyspeed, autocvar_g_balance_nex_charge_maxspeed);
1332 f = (xyspeed - autocvar_g_balance_nex_charge_minspeed) / (autocvar_g_balance_nex_charge_maxspeed - autocvar_g_balance_nex_charge_minspeed);
1333 // add the extra charge
1334 self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_velocity_rate * f * frametime);
1337 if(self.flags & FL_ONGROUND)
1338 self.lastground = time;
1340 self.lastflags = self.flags;
1341 self.lastclassname = self.classname;