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 mjumpheight = autocvar_sv_jumpvelocity;
41 if (self.waterlevel >= WATERLEVEL_SWIMMING)
43 if (self.watertype == CONTENT_WATER)
44 self.velocity_z = 200;
45 else if (self.watertype == CONTENT_SLIME)
53 if (autocvar_g_multijump)
55 if (self.prevjumpbutton == FALSE && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair
56 self.multijump_ready = TRUE; // this is necessary to check that we released the jump button and pressed it again
58 self.multijump_ready = FALSE;
61 if(!doublejump && self.multijump_ready && self.multijump_count < autocvar_g_multijump && self.velocity_z > autocvar_g_multijump_speed)
63 // doublejump = FALSE; // checked above in the if
64 if (autocvar_g_multijump)
66 if (autocvar_g_multijump_add == 0) // in this case we make the z velocity == jumpvelocity
68 if (self.velocity_z < mjumpheight)
79 if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
82 vector wishvel, wishdir;
85 vlen(vec2(self.velocity)), // current xy speed
86 vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
88 makevectors(self.v_angle_y * '0 1 0');
89 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
90 wishdir = normalize(wishvel);
92 self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
93 self.velocity_y = wishdir_y * curspeed;
94 // keep velocity_z unchanged!
96 if (autocvar_g_multijump > 0)
97 self.multijump_count += 1;
100 self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump
104 if (!(self.flags & FL_ONGROUND))
108 if (!(self.flags & FL_JUMPRELEASED))
111 if(self.health <= g_bloodloss)
114 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
115 // velocity bounds. Final velocity is bound between (jumpheight *
116 // min + jumpheight) and (jumpheight * max + jumpheight);
118 if(autocvar_sv_jumpspeedcap_min != "")
122 minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min);
124 if (self.velocity_z < minjumpspeed)
125 mjumpheight += minjumpspeed - self.velocity_z;
128 if(autocvar_sv_jumpspeedcap_max != "")
130 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
131 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
133 if(!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && autocvar_sv_jumpspeedcap_max_disable_on_ramps))
137 maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max);
139 if (self.velocity_z > maxjumpspeed)
140 mjumpheight -= self.velocity_z - maxjumpspeed;
144 if(!(self.lastflags & FL_ONGROUND))
146 if(autocvar_speedmeter)
147 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
148 if(self.lastground < time - 0.3)
150 self.velocity_x *= (1 - autocvar_sv_friction_on_land);
151 self.velocity_y *= (1 - autocvar_sv_friction_on_land);
153 if(self.jumppadcount > 1)
154 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
155 self.jumppadcount = 0;
158 self.velocity_z = self.velocity_z + mjumpheight;
159 self.oldvelocity_z = self.velocity_z;
161 self.flags &~= FL_ONGROUND;
162 self.flags &~= FL_JUMPRELEASED;
165 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
167 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
170 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
172 self.restart_jump = -1; // restart jump anim next time
173 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
176 void CheckWaterJump()
178 local vector start, end;
180 // check for a jump-out-of-water
181 makevectors (self.angles);
183 start_z = start_z + 8;
185 normalize(v_forward);
186 end = start + v_forward*24;
187 traceline (start, end, TRUE, self);
188 if (trace_fraction < 1)
190 start_z = start_z + self.maxs_z - 8;
191 end = start + v_forward*24;
192 self.movedir = trace_plane_normal * -50;
193 traceline (start, end, TRUE, self);
194 if (trace_fraction == 1)
195 { // open at eye level
196 self.flags |= FL_WATERJUMP;
197 self.velocity_z = 225;
198 self.flags &~= FL_JUMPRELEASED;
199 self.teleport_time = time + 2; // safety net
205 float racecar_angle(float forward, float down)
207 float ret, angle_mult;
215 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
217 angle_mult = forward / (800 + forward);
220 return ret * angle_mult + 360 * (1 - angle_mult);
222 return ret * angle_mult;
225 void RaceCarPhysics()
227 // using this move type for "big rigs"
228 // the engine does not push the entity!
230 float accel, steer, f, myspeed, steerfactor;
231 vector angles_save, rigvel;
233 angles_save = self.angles;
234 accel = bound(-1, self.movement_x / self.stat_sv_maxspeed, 1);
235 steer = bound(-1, self.movement_y / self.stat_sv_maxspeed, 1);
237 if(g_bugrigs_reverse_speeding)
241 // back accel is DIGITAL
242 // to prevent speedhack
252 makevectors(self.angles); // new forward direction!
254 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
256 float upspeed, accelfactor;
258 myspeed = self.velocity * v_forward;
259 upspeed = self.velocity * v_up;
261 // responsiveness factor for steering and acceleration
262 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
263 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
265 if(myspeed < 0 && g_bugrigs_reverse_spinning)
266 steerfactor = -myspeed * g_bugrigs_steer;
268 steerfactor = -myspeed * f * g_bugrigs_steer;
270 if(myspeed < 0 && g_bugrigs_reverse_speeding)
271 accelfactor = g_bugrigs_accel;
273 accelfactor = f * g_bugrigs_accel;
274 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
280 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
284 if(!g_bugrigs_reverse_speeding)
285 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
292 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
296 if(g_bugrigs_reverse_stopping)
299 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
302 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
303 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
305 self.angles_y += steer * frametime * steerfactor; // apply steering
306 makevectors(self.angles); // new forward direction!
308 myspeed += accel * accelfactor * frametime;
310 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
314 myspeed = vlen(self.velocity);
316 // responsiveness factor for steering and acceleration
317 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
318 steerfactor = -myspeed * f;
319 self.angles_y += steer * frametime * steerfactor; // apply steering
321 rigvel = self.velocity;
322 makevectors(self.angles); // new forward direction!
325 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
326 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
327 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
328 //MAXIMA: solve(total_acceleration(v) = 0, v);
330 if(g_bugrigs_planar_movement)
332 vector rigvel_xy, neworigin, up;
335 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
336 rigvel_xy = vec2(rigvel);
338 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
341 mt = MOVE_NOMONSTERS;
343 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
344 up = trace_endpos - self.origin;
346 // BUG RIGS: align the move to the surface instead of doing collision testing
348 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
351 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
353 if(trace_fraction < 0.5)
356 neworigin = self.origin;
359 neworigin = trace_endpos;
361 if(trace_fraction < 1)
363 // now set angles_x so that the car points parallel to the surface
364 self.angles = vectoangles(
365 '1 0 0' * v_forward_x * trace_plane_normal_z
367 '0 1 0' * v_forward_y * trace_plane_normal_z
369 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
371 self.flags |= FL_ONGROUND;
375 // now set angles_x so that the car points forward, but is tilted in velocity direction
376 self.flags &~= FL_ONGROUND;
379 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
380 self.movetype = MOVETYPE_NOCLIP;
384 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
385 self.velocity = rigvel;
386 self.movetype = MOVETYPE_FLY;
390 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
391 if(trace_fraction != 1)
393 self.angles = vectoangles2(
394 '1 0 0' * v_forward_x * trace_plane_normal_z
396 '0 1 0' * v_forward_y * trace_plane_normal_z
398 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
406 vel_local_x = v_forward * self.velocity;
407 vel_local_y = v_right * self.velocity;
408 vel_local_z = v_up * self.velocity;
410 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
411 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
415 vector vf1, vu1, smoothangles;
416 makevectors(self.angles);
417 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
422 makevectors(angles_save);
423 vf1 = vf1 + v_forward * (1 - f);
424 vu1 = vu1 + v_up * (1 - f);
425 smoothangles = vectoangles2(vf1, vu1);
426 self.angles_x = -smoothangles_x;
427 self.angles_z = smoothangles_z;
430 float IsMoveInDirection(vector mv, float angle) // key mix factor
432 if(mv_x == 0 && mv_y == 0)
433 return 0; // avoid division by zero
434 angle -= RAD2DEG * atan2(mv_y, mv_x);
435 angle = remainder(angle, 360) / 45;
440 return 1 - fabs(angle);
443 float GeomLerp(float a, float lerp, float b)
459 return a * pow(fabs(b / a), lerp);
462 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
464 float zspeed, xyspeed, dot, k;
467 // this doesn't play well with analog input
468 if(self.movement_x == 0 || self.movement_y != 0)
469 return; // can't control movement if not moving forward or backward
472 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
477 k *= bound(0, wishspeed / autocvar_sv_maxairspeed, 1);
479 zspeed = self.velocity_z;
481 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
483 dot = self.velocity * wishdir;
485 if(dot > 0) // we can't change direction while slowing down
487 k *= pow(dot, autocvar_sv_aircontrol_power)*frametime;
488 xyspeed = max(0, xyspeed - autocvar_sv_aircontrol_penalty * sqrt(max(0, 1 - dot*dot)) * k/32);
489 k *= autocvar_sv_aircontrol;
490 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
493 self.velocity = self.velocity * xyspeed;
494 self.velocity_z = zspeed;
497 float AdjustAirAccelQW(float accelqw, float factor)
499 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
502 // example config for alternate speed clamping:
503 // sv_airaccel_qw 0.8
504 // sv_airaccel_sideways_friction 0
505 // prvm_globalset server speedclamp_mode 1
507 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
515 float vel_xy_current;
516 float vel_xy_backward, vel_xy_forward;
519 if(stretchfactor > 0)
520 speedclamp = stretchfactor;
522 speedclamp = 1; // full clamping, no stretch
524 speedclamp = -1; // no clamping
529 if(autocvar_sv_gameplayfix_q2airaccelerate)
530 wishspeed0 = wishspeed;
532 vel_straight = self.velocity * wishdir;
533 vel_z = self.velocity_z;
534 vel_xy = vec2(self.velocity);
535 vel_perpend = vel_xy - vel_straight * wishdir;
537 step = accel * frametime * wishspeed0;
539 vel_xy_current = vlen(vel_xy);
541 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
542 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
543 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
544 if(vel_xy_backward < 0)
545 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
547 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
549 if(sidefric < 0 && (vel_perpend*vel_perpend))
550 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
553 f = max(0, 1 + frametime * wishspeed * sidefric);
554 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
555 // this cannot be > 1
557 vel_perpend = vel_perpend * max(0, f);
560 fminimum = sqrt(fminimum);
561 vel_perpend = vel_perpend * max(fminimum, f);
565 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
567 vel_xy = vel_straight * wishdir + vel_perpend;
571 float vel_xy_preclamp;
572 vel_xy_preclamp = vlen(vel_xy);
573 if(vel_xy_preclamp > 0) // prevent division by zero
575 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
576 if(vel_xy_current < vel_xy_preclamp)
577 vel_xy = vel_xy * (vel_xy_current / vel_xy_preclamp);
581 self.velocity = vel_xy + vel_z * '0 0 1';
584 void PM_AirAccelerate(vector wishdir, float wishspeed)
586 vector curvel, wishvel, acceldir, curdir;
587 float addspeed, accelspeed, curspeed, f;
593 curvel = self.velocity;
595 curspeed = vlen(curvel);
597 if(wishspeed > curspeed * 1.01)
599 wishspeed = min(wishspeed, curspeed + autocvar_sv_warsowbunny_airforwardaccel * self.stat_sv_maxspeed * frametime);
603 f = max(0, (autocvar_sv_warsowbunny_topspeed - curspeed) / (autocvar_sv_warsowbunny_topspeed - self.stat_sv_maxspeed));
604 wishspeed = max(curspeed, self.stat_sv_maxspeed) + autocvar_sv_warsowbunny_accel * f * self.stat_sv_maxspeed * frametime;
606 wishvel = wishdir * wishspeed;
607 acceldir = wishvel - curvel;
608 addspeed = vlen(acceldir);
609 acceldir = normalize(acceldir);
611 accelspeed = min(addspeed, autocvar_sv_warsowbunny_turnaccel * self.stat_sv_maxspeed * frametime);
613 if(autocvar_sv_warsowbunny_backtosideratio < 1)
615 curdir = normalize(curvel);
616 dot = acceldir * curdir;
618 acceldir = acceldir - (1 - autocvar_sv_warsowbunny_backtosideratio) * dot * curdir;
621 self.velocity += accelspeed * acceldir;
624 .vector movement_old;
627 .string lastclassname;
629 .float() PlayerPhysplug;
631 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
632 .float specialcommand_pos;
633 void SpecialCommand()
638 if(!CheatImpulse(99))
639 print("A hollow voice says \"Plugh\".\n");
643 float speedaward_speed;
644 string speedaward_holder;
645 string speedaward_uid;
646 void race_send_speedaward(float msg)
648 // send the best speed of the round
649 WriteByte(msg, SVC_TEMPENTITY);
650 WriteByte(msg, TE_CSQC_RACE);
651 WriteByte(msg, RACE_NET_SPEED_AWARD);
652 WriteInt24_t(msg, floor(speedaward_speed+0.5));
653 WriteString(msg, speedaward_holder);
656 float speedaward_alltimebest;
657 string speedaward_alltimebest_holder;
658 string speedaward_alltimebest_uid;
659 void race_send_speedaward_alltimebest(float msg)
661 // send the best speed
662 WriteByte(msg, SVC_TEMPENTITY);
663 WriteByte(msg, TE_CSQC_RACE);
664 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
665 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
666 WriteString(msg, speedaward_alltimebest_holder);
669 string GetMapname(void);
670 float speedaward_lastupdate;
671 float speedaward_lastsent;
672 void SV_PlayerPhysics()
674 local vector wishvel, wishdir, v;
675 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
678 float not_allowed_to_move;
681 WarpZone_PlayerPhysics_FixVAngle();
684 if(g_minstagib && (self.items & IT_INVINCIBLE))
685 maxspd_mod *= autocvar_g_minstagib_speed_highspeed;
688 maxspd_mod *= autocvar_g_nexball_basketball_carrier_highspeed;
690 maxspd_mod *= autocvar_g_keepaway_ballcarrier_highspeed;
694 if(self.runes & RUNE_SPEED)
696 if(self.runes & CURSE_SLOW)
697 maxspd_mod *= autocvar_g_balance_rune_speed_combo_highspeed;
699 maxspd_mod *= autocvar_g_balance_rune_speed_highspeed;
701 else if(self.runes & CURSE_SLOW)
703 maxspd_mod *= autocvar_g_balance_curse_slow_highspeed;
706 maxspd_mod *= autocvar_g_movement_highspeed;
708 // fix physics stats for g_movement_highspeed
709 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
710 if(autocvar_sv_airstrafeaccel_qw)
711 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
713 self.stat_sv_airstrafeaccel_qw = 0;
714 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
715 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
717 if(self.PlayerPhysplug)
718 if(self.PlayerPhysplug())
721 self.race_movetime_frac += frametime;
722 f = floor(self.race_movetime_frac);
723 self.race_movetime_frac -= f;
724 self.race_movetime_count += f;
725 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
729 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);
733 else if(buttons == 1)
735 else if(buttons == 2)
737 else if(buttons == 128)
739 else if(buttons == 256)
741 else if(buttons == 512)
743 else if(buttons == 1024)
748 if(c == substring(specialcommand, self.specialcommand_pos, 1))
750 self.specialcommand_pos += 1;
751 if(self.specialcommand_pos >= strlen(specialcommand))
753 self.specialcommand_pos = 0;
758 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
759 self.specialcommand_pos = 0;
761 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
763 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
764 self.parm_idlesince = time;
766 buttons_prev = self.buttons_old;
767 self.buttons_old = buttons;
768 self.movement_old = self.movement;
769 self.v_angle_old = self.v_angle;
771 if(time < self.nickspamtime)
772 if(self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
774 // slight annoyance for nick change scripts
775 self.movement = -1 * self.movement;
776 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
778 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!
780 self.angles_x = random() * 360;
781 self.angles_y = random() * 360;
782 // at least I'm not forcing retardedview by also assigning to angles_z
783 self.fixangle = TRUE;
787 if (self.punchangle != '0 0 0')
789 f = vlen(self.punchangle) - 10 * frametime;
791 self.punchangle = normalize(self.punchangle) * f;
793 self.punchangle = '0 0 0';
796 if (self.punchvector != '0 0 0')
798 f = vlen(self.punchvector) - 30 * frametime;
800 self.punchvector = normalize(self.punchvector) * f;
802 self.punchvector = '0 0 0';
805 if (clienttype(self) == CLIENTTYPE_BOT)
807 if(playerdemo_read())
812 self.items &~= IT_USING_JETPACK;
814 if(self.classname == "player")
816 if(self.race_penalty)
817 if(time > self.race_penalty)
818 self.race_penalty = 0;
820 not_allowed_to_move = 0;
821 if(self.race_penalty)
822 not_allowed_to_move = 1;
823 if(!autocvar_sv_ready_restart_after_countdown)
824 if(time < game_starttime)
825 not_allowed_to_move = 1;
827 if(not_allowed_to_move)
829 self.velocity = '0 0 0';
830 self.movetype = MOVETYPE_NONE;
831 self.disableclientprediction = 2;
833 else if(self.disableclientprediction == 2)
835 if(self.movetype == MOVETYPE_NONE)
836 self.movetype = MOVETYPE_WALK;
837 self.disableclientprediction = 0;
841 if (self.movetype == MOVETYPE_NONE)
844 // when we get here, disableclientprediction cannot be 2
845 self.disableclientprediction = 0;
846 if(time < self.ladder_time)
847 self.disableclientprediction = 1;
849 MUTATOR_CALLHOOK(PlayerPhysics);
855 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
858 if(self.classname != "player")
860 maxspd_mod = autocvar_sv_spectator_speed_multiplier;
861 if(!self.spectatorspeed)
862 self.spectatorspeed = maxspd_mod;
863 if(self.impulse && self.impulse <= 19)
865 if(self.lastclassname != "player")
867 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
868 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
869 else if(self.impulse == 11)
870 self.spectatorspeed = maxspd_mod;
871 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
872 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
873 else if(self.impulse >= 1 && self.impulse <= 9)
874 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
875 } // otherwise just clear
878 maxspd_mod = self.spectatorspeed;
881 spd = max(self.stat_sv_maxspeed, autocvar_sv_maxairspeed) * maxspd_mod * swampspd_mod;
882 if(self.speed != spd)
886 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
887 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
888 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
889 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
892 maxspd_mod *= swampspd_mod; // only one common speed modder please!
895 // if dead, behave differently
899 if (!self.fixangle && !g_bugrigs)
902 self.angles_y = self.v_angle_y;
906 if(self.flags & FL_ONGROUND)
907 if(self.classname == "player") // no fall sounds for observers thank you very much
912 if(self.waterlevel < WATERLEVEL_SWIMMING)
913 if(time >= self.ladder_time)
916 self.nextstep = time + 0.3 + random() * 0.1;
917 trace_dphitq3surfaceflags = 0;
918 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
919 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
921 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
922 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
924 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
932 if(self.classname == "player")
934 if(self.flags & FL_ONGROUND)
936 if (autocvar_g_multijump > 0)
937 self.multijump_count = 0;
939 self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller
942 if (self.BUTTON_JUMP)
945 self.flags |= FL_JUMPRELEASED;
947 if (self.waterlevel == WATERLEVEL_SWIMMING)
949 self.prevjumpbutton = self.BUTTON_JUMP;
952 if (self.flags & FL_WATERJUMP )
954 self.velocity_x = self.movedir_x;
955 self.velocity_y = self.movedir_y;
956 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
958 self.flags &~= FL_WATERJUMP;
959 self.teleport_time = 0;
962 else if (g_bugrigs && self.classname == "player")
966 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
968 // noclipping or flying
969 self.flags &~= FL_ONGROUND;
971 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
972 makevectors(self.v_angle);
973 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
974 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
976 wishdir = normalize(wishvel);
977 wishspeed = vlen(wishvel);
978 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
979 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
980 if (time >= self.teleport_time)
981 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
983 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
986 self.flags &~= FL_ONGROUND;
988 makevectors(self.v_angle);
989 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
990 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
991 if (wishvel == '0 0 0')
992 wishvel = '0 0 -60'; // drift towards bottom
994 wishdir = normalize(wishvel);
995 wishspeed = vlen(wishvel);
996 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
997 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
998 wishspeed = wishspeed * 0.7;
1001 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
1003 // water acceleration
1004 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1006 else if (time < self.ladder_time)
1008 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
1009 self.flags &~= FL_ONGROUND;
1012 g = autocvar_sv_gravity * frametime;
1015 if(autocvar_sv_gameplayfix_gravityunaffectedbyticrate)
1018 self.velocity_z += g;
1021 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
1022 makevectors(self.v_angle);
1023 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
1024 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
1025 self.velocity_z += g;
1026 if (self.ladder_entity.classname == "func_water")
1029 if (f > self.ladder_entity.speed)
1030 wishvel = wishvel * (self.ladder_entity.speed / f);
1032 self.watertype = self.ladder_entity.skin;
1033 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1034 if ((self.origin_z + self.view_ofs_z) < f)
1035 self.waterlevel = WATERLEVEL_SUBMERGED;
1036 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1037 self.waterlevel = WATERLEVEL_SWIMMING;
1038 else if ((self.origin_z + self.mins_z + 1) < f)
1039 self.waterlevel = WATERLEVEL_WETFEET;
1042 self.waterlevel = WATERLEVEL_NONE;
1043 self.watertype = CONTENT_EMPTY;
1047 wishdir = normalize(wishvel);
1048 wishspeed = vlen(wishvel);
1049 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1050 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1051 if (time >= self.teleport_time)
1053 // water acceleration
1054 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1057 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!autocvar_g_jetpack_fuel || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
1059 //makevectors(self.v_angle_y * '0 1 0');
1060 makevectors(self.v_angle);
1061 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1062 // add remaining speed as Z component
1063 maxairspd = autocvar_sv_maxairspeed*max(1, maxspd_mod);
1064 // fix speedhacks :P
1065 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
1066 // add the unused velocity as up component
1069 // if(self.BUTTON_JUMP)
1070 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1072 // it is now normalized, so...
1073 float a_side, a_up, a_add, a_diff;
1074 a_side = autocvar_g_jetpack_acceleration_side;
1075 a_up = autocvar_g_jetpack_acceleration_up;
1076 a_add = autocvar_g_jetpack_antigravity * autocvar_sv_gravity;
1078 wishvel_x *= a_side;
1079 wishvel_y *= a_side;
1085 //////////////////////////////////////////////////////////////////////////////////////
1086 // finding the maximum over all vectors of above form
1087 // with wishvel having an absolute value of 1
1088 //////////////////////////////////////////////////////////////////////////////////////
1089 // we're finding the maximum over
1090 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1091 // for z in the range from -1 to 1
1092 //////////////////////////////////////////////////////////////////////////////////////
1093 // maximum is EITHER attained at the single extreme point:
1094 a_diff = a_side * a_side - a_up * a_up;
1097 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1098 if(f > -1 && f < 1) // can it be attained?
1100 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1101 //print("middle\n");
1104 // OR attained at z = 1:
1105 f = (a_up + a_add) * (a_up + a_add);
1111 // OR attained at z = -1:
1112 f = (a_up - a_add) * (a_up - a_add);
1116 //print("bottom\n");
1119 //////////////////////////////////////////////////////////////////////////////////////
1121 //print("best possible acceleration: ", ftos(best), "\n");
1124 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / autocvar_g_jetpack_maxspeed_side, 1);
1125 if(wishvel_z - autocvar_sv_gravity > 0)
1126 fz = bound(0, 1 - self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1128 fz = bound(0, 1 + self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1131 fvel = vlen(wishvel);
1134 wishvel_z = (wishvel_z - autocvar_sv_gravity) * fz + autocvar_sv_gravity;
1136 fvel = min(1, vlen(wishvel) / best);
1137 if(autocvar_g_jetpack_fuel && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1138 f = min(1, self.ammo_fuel / (autocvar_g_jetpack_fuel * frametime * fvel));
1142 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1144 if (f > 0 && wishvel != '0 0 0')
1146 self.velocity = self.velocity + wishvel * f * frametime;
1147 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1148 self.ammo_fuel -= autocvar_g_jetpack_fuel * frametime * fvel * f;
1149 self.flags &~= FL_ONGROUND;
1150 self.items |= IT_USING_JETPACK;
1152 // jetpack also inhibits health regeneration, but only for 1 second
1153 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1156 else if (self.flags & FL_ONGROUND)
1158 // we get here if we ran out of ammo
1159 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1160 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1163 makevectors(self.v_angle_y * '0 1 0');
1164 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1166 if(!(self.lastflags & FL_ONGROUND))
1168 if(autocvar_speedmeter)
1169 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1170 if(self.lastground < time - 0.3)
1171 self.velocity = self.velocity * (1 - autocvar_sv_friction_on_land);
1172 if(self.jumppadcount > 1)
1173 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1174 self.jumppadcount = 0;
1177 #ifdef LETS_TEST_FTEQCC
1178 if(self.velocity_x || self.velocity_y)
1196 if (f < autocvar_sv_stopspeed)
1197 f = 1 - frametime * (autocvar_sv_stopspeed / f) * autocvar_sv_friction;
1199 f = 1 - frametime * autocvar_sv_friction;
1201 self.velocity = self.velocity * f;
1203 self.velocity = '0 0 0';
1207 wishdir = normalize(wishvel);
1208 wishspeed = vlen(wishvel);
1209 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1210 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1212 wishspeed = wishspeed * 0.5;
1213 if (time >= self.teleport_time)
1214 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1219 // we get here if we ran out of ammo
1220 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1221 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1225 maxairspd = autocvar_sv_maxairspeed*maxspd_mod;
1226 airaccel = autocvar_sv_airaccelerate*maxspd_mod;
1230 maxairspd = autocvar_sv_maxairspeed;
1231 airaccel = autocvar_sv_airaccelerate;
1234 makevectors(self.v_angle_y * '0 1 0');
1235 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1237 wishdir = normalize(wishvel);
1238 wishspeed = wishspeed0 = vlen(wishvel);
1239 if (wishspeed0 > self.stat_sv_maxspeed*maxspd_mod)
1240 wishspeed0 = self.stat_sv_maxspeed*maxspd_mod;
1241 if (wishspeed > maxairspd)
1242 wishspeed = maxairspd;
1244 wishspeed = wishspeed * 0.5;
1245 if (time >= self.teleport_time)
1252 airaccelqw = self.stat_sv_airaccel_qw;
1253 accelerating = (self.velocity * wishdir > 0);
1254 wishspeed2 = wishspeed;
1257 if(autocvar_sv_airstopaccelerate)
1260 curdir = self.velocity;
1262 curdir = normalize(curdir);
1263 airaccel = airaccel + (autocvar_sv_airstopaccelerate*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1265 // note that for straight forward jumping:
1266 // step = accel * frametime * wishspeed0;
1267 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1269 // dv/dt = accel * maxspeed (when slow)
1270 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1271 // log dv/dt = logaccel + logmaxspeed (when slow)
1272 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1273 strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
1274 if(autocvar_sv_maxairstrafespeed)
1275 wishspeed = min(wishspeed, GeomLerp(autocvar_sv_maxairspeed*maxspd_mod, strafity, autocvar_sv_maxairstrafespeed*maxspd_mod));
1276 if(autocvar_sv_airstrafeaccelerate)
1277 airaccel = GeomLerp(airaccel, strafity, autocvar_sv_airstrafeaccelerate*maxspd_mod);
1278 if(self.stat_sv_airstrafeaccel_qw)
1279 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));
1282 if(autocvar_sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1283 PM_AirAccelerate(wishdir, wishspeed);
1285 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, autocvar_sv_airaccel_qw_stretchfactor, autocvar_sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw);
1287 if(autocvar_sv_aircontrol)
1288 CPM_PM_Aircontrol(wishdir, wishspeed2);
1292 if((g_cts || g_race) && self.classname != "observer") {
1293 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1294 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1295 speedaward_holder = self.netname;
1296 speedaward_uid = self.crypto_idfp;
1297 speedaward_lastupdate = time;
1299 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1305 race_send_speedaward(MSG_ALL);
1306 speedaward_lastsent = speedaward_speed;
1307 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") {
1308 speedaward_alltimebest = speedaward_speed;
1309 speedaward_alltimebest_holder = speedaward_holder;
1310 speedaward_alltimebest_uid = speedaward_uid;
1311 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1312 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1313 race_send_speedaward_alltimebest(MSG_ALL);
1319 xyspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y);
1320 if(self.weapon == WEP_NEX && autocvar_g_balance_nex_charge && autocvar_g_balance_nex_charge_velocity_rate && xyspeed > autocvar_g_balance_nex_charge_minspeed)
1322 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1323 xyspeed = min(xyspeed, autocvar_g_balance_nex_charge_maxspeed);
1324 f = (xyspeed - autocvar_g_balance_nex_charge_minspeed) / (autocvar_g_balance_nex_charge_maxspeed - autocvar_g_balance_nex_charge_minspeed);
1325 // add the extra charge
1326 self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_velocity_rate * f * frametime);
1329 if(self.flags & FL_ONGROUND)
1330 self.lastground = time;
1332 self.lastflags = self.flags;
1333 self.lastclassname = self.classname;