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 self.velocity_z = self.stat_sv_maxspeed * 0.7;
55 if (autocvar_g_multijump)
57 if (self.prevjumpbutton == FALSE && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair
58 self.multijump_ready = TRUE; // this is necessary to check that we released the jump button and pressed it again
60 self.multijump_ready = FALSE;
63 if(!doublejump && self.multijump_ready && self.multijump_count < autocvar_g_multijump && self.velocity_z > autocvar_g_multijump_speed)
65 // doublejump = FALSE; // checked above in the if
66 if (autocvar_g_multijump)
68 if (autocvar_g_multijump_add == 0) // in this case we make the z velocity == jumpvelocity
70 if (self.velocity_z < mjumpheight)
81 if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
84 vector wishvel, wishdir;
87 vlen(vec2(self.velocity)), // current xy speed
88 vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
90 makevectors(self.v_angle_y * '0 1 0');
91 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
92 wishdir = normalize(wishvel);
94 self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
95 self.velocity_y = wishdir_y * curspeed;
96 // keep velocity_z unchanged!
98 if (autocvar_g_multijump > 0)
99 self.multijump_count += 1;
102 self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump
106 if (!(self.flags & FL_ONGROUND))
109 if(self.cvar_cl_movement_track_canjump)
110 if (!(self.flags & FL_JUMPRELEASED))
113 if(self.health <= g_bloodloss)
116 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
117 // velocity bounds. Final velocity is bound between (jumpheight *
118 // min + jumpheight) and (jumpheight * max + jumpheight);
120 if(autocvar_sv_jumpspeedcap_min != "")
124 minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min);
126 if (self.velocity_z < minjumpspeed)
127 mjumpheight += minjumpspeed - self.velocity_z;
130 if(autocvar_sv_jumpspeedcap_max != "")
132 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
133 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
135 if(!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && autocvar_sv_jumpspeedcap_max_disable_on_ramps))
139 maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max);
141 if (self.velocity_z > maxjumpspeed)
142 mjumpheight -= self.velocity_z - maxjumpspeed;
146 if(!(self.lastflags & FL_ONGROUND))
148 if(autocvar_speedmeter)
149 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
150 if(self.lastground < time - 0.3)
152 self.velocity_x *= (1 - autocvar_sv_friction_on_land);
153 self.velocity_y *= (1 - autocvar_sv_friction_on_land);
155 if(self.jumppadcount > 1)
156 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
157 self.jumppadcount = 0;
160 self.velocity_z = self.velocity_z + mjumpheight;
161 self.oldvelocity_z = self.velocity_z;
163 self.flags &~= FL_ONGROUND;
164 self.flags &~= FL_JUMPRELEASED;
166 animdecide_setaction(self, ANIMACTION_JUMP, TRUE);
169 PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
171 self.restart_jump = -1; // restart jump anim next time
172 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
174 void CheckWaterJump()
178 // check for a jump-out-of-water
179 makevectors (self.angles);
181 start_z = start_z + 8;
183 normalize(v_forward);
184 end = start + v_forward*24;
185 traceline (start, end, TRUE, self);
186 if (trace_fraction < 1)
188 start_z = start_z + self.maxs_z - 8;
189 end = start + v_forward*24;
190 self.movedir = trace_plane_normal * -50;
191 traceline (start, end, TRUE, self);
192 if (trace_fraction == 1)
193 { // open at eye level
194 self.flags |= FL_WATERJUMP;
195 self.velocity_z = 225;
196 self.flags &~= FL_JUMPRELEASED;
197 self.teleport_time = time + 2; // safety net
202 void CheckPlayerJump()
204 if(self.flags & FL_ONGROUND)
206 if (autocvar_g_multijump > 0)
207 self.multijump_count = 0;
209 self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller
212 if (self.BUTTON_JUMP)
215 self.flags |= FL_JUMPRELEASED;
217 if (self.waterlevel == WATERLEVEL_SWIMMING)
219 self.prevjumpbutton = self.BUTTON_JUMP;
222 float racecar_angle(float forward, float down)
224 float ret, angle_mult;
232 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
234 angle_mult = forward / (800 + forward);
237 return ret * angle_mult + 360 * (1 - angle_mult);
239 return ret * angle_mult;
242 void RaceCarPhysics()
244 // using this move type for "big rigs"
245 // the engine does not push the entity!
247 float accel, steer, f, myspeed, steerfactor;
248 vector angles_save, rigvel;
250 angles_save = self.angles;
251 accel = bound(-1, self.movement_x / self.stat_sv_maxspeed, 1);
252 steer = bound(-1, self.movement_y / self.stat_sv_maxspeed, 1);
254 if(g_bugrigs_reverse_speeding)
258 // back accel is DIGITAL
259 // to prevent speedhack
269 makevectors(self.angles); // new forward direction!
271 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
273 float upspeed, accelfactor;
275 myspeed = self.velocity * v_forward;
276 upspeed = self.velocity * v_up;
278 // responsiveness factor for steering and acceleration
279 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
280 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
282 if(myspeed < 0 && g_bugrigs_reverse_spinning)
283 steerfactor = -myspeed * g_bugrigs_steer;
285 steerfactor = -myspeed * f * g_bugrigs_steer;
287 if(myspeed < 0 && g_bugrigs_reverse_speeding)
288 accelfactor = g_bugrigs_accel;
290 accelfactor = f * g_bugrigs_accel;
291 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
297 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
301 if(!g_bugrigs_reverse_speeding)
302 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
309 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
313 if(g_bugrigs_reverse_stopping)
316 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
319 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
320 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
322 self.angles_y += steer * frametime * steerfactor; // apply steering
323 makevectors(self.angles); // new forward direction!
325 myspeed += accel * accelfactor * frametime;
327 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
331 myspeed = vlen(self.velocity);
333 // responsiveness factor for steering and acceleration
334 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
335 steerfactor = -myspeed * f;
336 self.angles_y += steer * frametime * steerfactor; // apply steering
338 rigvel = self.velocity;
339 makevectors(self.angles); // new forward direction!
342 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
343 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
344 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
345 //MAXIMA: solve(total_acceleration(v) = 0, v);
347 if(g_bugrigs_planar_movement)
349 vector rigvel_xy, neworigin, up;
352 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
353 rigvel_xy = vec2(rigvel);
355 if(g_bugrigs_planar_movement_car_jumping)
358 mt = MOVE_NOMONSTERS;
360 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
361 up = trace_endpos - self.origin;
363 // BUG RIGS: align the move to the surface instead of doing collision testing
365 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
368 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
370 if(trace_fraction < 0.5)
373 neworigin = self.origin;
376 neworigin = trace_endpos;
378 if(trace_fraction < 1)
380 // now set angles_x so that the car points parallel to the surface
381 self.angles = vectoangles(
382 '1 0 0' * v_forward_x * trace_plane_normal_z
384 '0 1 0' * v_forward_y * trace_plane_normal_z
386 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
388 self.flags |= FL_ONGROUND;
392 // now set angles_x so that the car points forward, but is tilted in velocity direction
393 self.flags &~= FL_ONGROUND;
396 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
397 self.movetype = MOVETYPE_NOCLIP;
401 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
402 self.velocity = rigvel;
403 self.movetype = MOVETYPE_FLY;
407 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
408 if(trace_fraction != 1)
410 self.angles = vectoangles2(
411 '1 0 0' * v_forward_x * trace_plane_normal_z
413 '0 1 0' * v_forward_y * trace_plane_normal_z
415 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
423 vel_local_x = v_forward * self.velocity;
424 vel_local_y = v_right * self.velocity;
425 vel_local_z = v_up * self.velocity;
427 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
428 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
432 vector vf1, vu1, smoothangles;
433 makevectors(self.angles);
434 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
439 makevectors(angles_save);
440 vf1 = vf1 + v_forward * (1 - f);
441 vu1 = vu1 + v_up * (1 - f);
442 smoothangles = vectoangles2(vf1, vu1);
443 self.angles_x = -smoothangles_x;
444 self.angles_z = smoothangles_z;
447 float IsMoveInDirection(vector mv, float angle) // key mix factor
449 if(mv_x == 0 && mv_y == 0)
450 return 0; // avoid division by zero
451 angle -= RAD2DEG * atan2(mv_y, mv_x);
452 angle = remainder(angle, 360) / 45;
457 return 1 - fabs(angle);
460 float GeomLerp(float a, float lerp, float b)
476 return a * pow(fabs(b / a), lerp);
479 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
481 float zspeed, xyspeed, dot, k;
484 // this doesn't play well with analog input
485 if(self.movement_x == 0 || self.movement_y != 0)
486 return; // can't control movement if not moving forward or backward
489 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
494 k *= bound(0, wishspeed / autocvar_sv_maxairspeed, 1);
496 zspeed = self.velocity_z;
498 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
500 dot = self.velocity * wishdir;
502 if(dot > 0) // we can't change direction while slowing down
504 k *= pow(dot, autocvar_sv_aircontrol_power)*frametime;
505 xyspeed = max(0, xyspeed - autocvar_sv_aircontrol_penalty * sqrt(max(0, 1 - dot*dot)) * k/32);
506 k *= autocvar_sv_aircontrol;
507 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
510 self.velocity = self.velocity * xyspeed;
511 self.velocity_z = zspeed;
514 float AdjustAirAccelQW(float accelqw, float factor)
516 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
519 // example config for alternate speed clamping:
520 // sv_airaccel_qw 0.8
521 // sv_airaccel_sideways_friction 0
522 // prvm_globalset server speedclamp_mode 1
524 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
532 float vel_xy_current;
533 float vel_xy_backward, vel_xy_forward;
536 if(stretchfactor > 0)
537 speedclamp = stretchfactor;
539 speedclamp = 1; // full clamping, no stretch
541 speedclamp = -1; // no clamping
546 if(autocvar_sv_gameplayfix_q2airaccelerate)
547 wishspeed0 = wishspeed;
549 vel_straight = self.velocity * wishdir;
550 vel_z = self.velocity_z;
551 vel_xy = vec2(self.velocity);
552 vel_perpend = vel_xy - vel_straight * wishdir;
554 step = accel * frametime * wishspeed0;
556 vel_xy_current = vlen(vel_xy);
558 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
559 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
560 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
561 if(vel_xy_backward < 0)
562 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
564 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
566 if(sidefric < 0 && (vel_perpend*vel_perpend))
567 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
570 f = max(0, 1 + frametime * wishspeed * sidefric);
571 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
572 // this cannot be > 1
574 vel_perpend = vel_perpend * max(0, f);
577 fminimum = sqrt(fminimum);
578 vel_perpend = vel_perpend * max(fminimum, f);
582 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
584 vel_xy = vel_straight * wishdir + vel_perpend;
588 float vel_xy_preclamp;
589 vel_xy_preclamp = vlen(vel_xy);
590 if(vel_xy_preclamp > 0) // prevent division by zero
592 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
593 if(vel_xy_current < vel_xy_preclamp)
594 vel_xy = vel_xy * (vel_xy_current / vel_xy_preclamp);
598 self.velocity = vel_xy + vel_z * '0 0 1';
601 void PM_AirAccelerate(vector wishdir, float wishspeed)
603 vector curvel, wishvel, acceldir, curdir;
604 float addspeed, accelspeed, curspeed, f;
610 curvel = self.velocity;
612 curspeed = vlen(curvel);
614 if(wishspeed > curspeed * 1.01)
616 wishspeed = min(wishspeed, curspeed + autocvar_sv_warsowbunny_airforwardaccel * self.stat_sv_maxspeed * frametime);
620 f = max(0, (autocvar_sv_warsowbunny_topspeed - curspeed) / (autocvar_sv_warsowbunny_topspeed - self.stat_sv_maxspeed));
621 wishspeed = max(curspeed, self.stat_sv_maxspeed) + autocvar_sv_warsowbunny_accel * f * self.stat_sv_maxspeed * frametime;
623 wishvel = wishdir * wishspeed;
624 acceldir = wishvel - curvel;
625 addspeed = vlen(acceldir);
626 acceldir = normalize(acceldir);
628 accelspeed = min(addspeed, autocvar_sv_warsowbunny_turnaccel * self.stat_sv_maxspeed * frametime);
630 if(autocvar_sv_warsowbunny_backtosideratio < 1)
632 curdir = normalize(curvel);
633 dot = acceldir * curdir;
635 acceldir = acceldir - (1 - autocvar_sv_warsowbunny_backtosideratio) * dot * curdir;
638 self.velocity += accelspeed * acceldir;
641 .vector movement_old;
644 .string lastclassname;
646 .float() PlayerPhysplug;
648 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
649 .float specialcommand_pos;
650 void SpecialCommand()
655 if(!CheatImpulse(99))
656 print("A hollow voice says \"Plugh\".\n");
660 float speedaward_speed;
661 string speedaward_holder;
662 string speedaward_uid;
663 void race_send_speedaward(float msg)
665 // send the best speed of the round
666 WriteByte(msg, SVC_TEMPENTITY);
667 WriteByte(msg, TE_CSQC_RACE);
668 WriteByte(msg, RACE_NET_SPEED_AWARD);
669 WriteInt24_t(msg, floor(speedaward_speed+0.5));
670 WriteString(msg, speedaward_holder);
673 float speedaward_alltimebest;
674 string speedaward_alltimebest_holder;
675 string speedaward_alltimebest_uid;
676 void race_send_speedaward_alltimebest(float msg)
678 // send the best speed
679 WriteByte(msg, SVC_TEMPENTITY);
680 WriteByte(msg, TE_CSQC_RACE);
681 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
682 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
683 WriteString(msg, speedaward_alltimebest_holder);
686 string GetMapname(void);
687 float speedaward_lastupdate;
688 float speedaward_lastsent;
689 void SV_PlayerPhysics()
691 vector wishvel, wishdir, v;
692 float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
695 float not_allowed_to_move;
698 WarpZone_PlayerPhysics_FixVAngle();
701 if(g_minstagib && (self.items & IT_INVINCIBLE))
702 maxspd_mod *= autocvar_g_minstagib_speed_highspeed;
705 maxspd_mod *= autocvar_g_nexball_basketball_carrier_highspeed;
707 maxspd_mod *= autocvar_g_keepaway_ballcarrier_highspeed;
709 maxspd_mod *= autocvar_g_movement_highspeed;
711 // fix physics stats for g_movement_highspeed
712 // TODO maybe rather use maxairspeed? needs testing
713 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
714 if(autocvar_sv_airstrafeaccel_qw)
715 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
717 self.stat_sv_airstrafeaccel_qw = 0;
718 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
719 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
721 if(self.PlayerPhysplug)
722 if(self.PlayerPhysplug())
725 self.race_movetime_frac += frametime;
726 f = floor(self.race_movetime_frac);
727 self.race_movetime_frac -= f;
728 self.race_movetime_count += f;
729 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
733 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);
737 else if(buttons == 1)
739 else if(buttons == 2)
741 else if(buttons == 128)
743 else if(buttons == 256)
745 else if(buttons == 512)
747 else if(buttons == 1024)
752 if(c == substring(specialcommand, self.specialcommand_pos, 1))
754 self.specialcommand_pos += 1;
755 if(self.specialcommand_pos >= strlen(specialcommand))
757 self.specialcommand_pos = 0;
762 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
763 self.specialcommand_pos = 0;
765 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
767 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
768 self.parm_idlesince = time;
770 buttons_prev = self.buttons_old;
771 self.buttons_old = buttons;
772 self.movement_old = self.movement;
773 self.v_angle_old = self.v_angle;
775 if(time < self.nickspamtime)
776 if(self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
778 // slight annoyance for nick change scripts
779 self.movement = -1 * self.movement;
780 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
782 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!
784 self.angles_x = random() * 360;
785 self.angles_y = random() * 360;
786 // at least I'm not forcing retardedview by also assigning to angles_z
787 self.fixangle = TRUE;
791 if (self.punchangle != '0 0 0')
793 f = vlen(self.punchangle) - 10 * frametime;
795 self.punchangle = normalize(self.punchangle) * f;
797 self.punchangle = '0 0 0';
800 if (self.punchvector != '0 0 0')
802 f = vlen(self.punchvector) - 30 * frametime;
804 self.punchvector = normalize(self.punchvector) * f;
806 self.punchvector = '0 0 0';
809 if (clienttype(self) == CLIENTTYPE_BOT)
811 if(playerdemo_read())
816 self.items &~= IT_USING_JETPACK;
818 if(self.classname == "player")
820 if(self.race_penalty)
821 if(time > self.race_penalty)
822 self.race_penalty = 0;
824 not_allowed_to_move = 0;
825 if(self.race_penalty)
826 not_allowed_to_move = 1;
827 if(!autocvar_sv_ready_restart_after_countdown)
828 if(time < game_starttime)
829 not_allowed_to_move = 1;
831 if(not_allowed_to_move)
833 self.velocity = '0 0 0';
834 self.movetype = MOVETYPE_NONE;
835 self.disableclientprediction = 2;
837 else if(self.disableclientprediction == 2)
839 if(self.movetype == MOVETYPE_NONE)
840 self.movetype = MOVETYPE_WALK;
841 self.disableclientprediction = 0;
845 if (self.movetype == MOVETYPE_NONE)
848 // when we get here, disableclientprediction cannot be 2
849 self.disableclientprediction = 0;
850 if(time < self.ladder_time)
851 self.disableclientprediction = 1;
853 MUTATOR_CALLHOOK(PlayerPhysics);
855 if(self.player_blocked)
857 self.movement = '0 0 0';
858 self.disableclientprediction = 1;
865 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
868 // conveyors: first fix velocity
869 if(self.conveyor.state)
870 self.velocity -= self.conveyor.movedir;
872 if(self.classname != "player")
874 maxspd_mod = autocvar_sv_spectator_speed_multiplier;
875 if(!self.spectatorspeed)
876 self.spectatorspeed = maxspd_mod;
877 if(self.impulse && self.impulse <= 19 || self.impulse >= 200 && self.impulse <= 209 || self.impulse >= 220 && self.impulse <= 229)
879 if(self.lastclassname != "player")
881 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || self.impulse >= 200 && self.impulse <= 209)
882 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
883 else if(self.impulse == 11)
884 self.spectatorspeed = maxspd_mod;
885 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || self.impulse >= 220 && self.impulse <= 229)
886 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
887 else if(self.impulse >= 1 && self.impulse <= 9)
888 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
889 } // otherwise just clear
892 maxspd_mod = self.spectatorspeed;
895 spd = max(self.stat_sv_maxspeed, autocvar_sv_maxairspeed) * maxspd_mod * swampspd_mod;
896 if(self.speed != spd)
900 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
901 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
902 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
903 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
906 maxspd_mod *= swampspd_mod; // only one common speed modder please!
909 // if dead, behave differently
913 if (!self.fixangle && !g_bugrigs)
916 self.angles_y = self.v_angle_y;
920 if(self.flags & FL_ONGROUND)
921 if(self.classname == "player") // no fall sounds for observers thank you very much
926 if(self.waterlevel < WATERLEVEL_SWIMMING)
927 if(time >= self.ladder_time)
930 self.nextstep = time + 0.3 + random() * 0.1;
931 trace_dphitq3surfaceflags = 0;
932 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
933 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
935 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
936 GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
938 GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
946 if(self.classname == "player")
949 if (self.flags & FL_WATERJUMP )
951 self.velocity_x = self.movedir_x;
952 self.velocity_y = self.movedir_y;
953 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
955 self.flags &~= FL_WATERJUMP;
956 self.teleport_time = 0;
959 else if (g_bugrigs && self.classname == "player")
963 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
965 // noclipping or flying
966 self.flags &~= FL_ONGROUND;
968 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
969 makevectors(self.v_angle);
970 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
971 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
973 wishdir = normalize(wishvel);
974 wishspeed = vlen(wishvel);
975 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
976 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
977 if (time >= self.teleport_time)
978 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
980 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
983 self.flags &~= FL_ONGROUND;
985 makevectors(self.v_angle);
986 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
987 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
988 if (wishvel == '0 0 0')
989 wishvel = '0 0 -60'; // drift towards bottom
991 wishdir = normalize(wishvel);
992 wishspeed = vlen(wishvel);
993 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
994 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
995 wishspeed = wishspeed * 0.7;
998 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
1000 // water acceleration
1001 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1003 else if (time < self.ladder_time)
1005 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
1006 self.flags &~= FL_ONGROUND;
1009 g = autocvar_sv_gravity * frametime;
1012 if(autocvar_sv_gameplayfix_gravityunaffectedbyticrate)
1015 self.velocity_z += g;
1018 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
1019 makevectors(self.v_angle);
1020 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
1021 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
1022 self.velocity_z += g;
1023 if (self.ladder_entity.classname == "func_water")
1026 if (f > self.ladder_entity.speed)
1027 wishvel = wishvel * (self.ladder_entity.speed / f);
1029 self.watertype = self.ladder_entity.skin;
1030 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1031 if ((self.origin_z + self.view_ofs_z) < f)
1032 self.waterlevel = WATERLEVEL_SUBMERGED;
1033 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1034 self.waterlevel = WATERLEVEL_SWIMMING;
1035 else if ((self.origin_z + self.mins_z + 1) < f)
1036 self.waterlevel = WATERLEVEL_WETFEET;
1039 self.waterlevel = WATERLEVEL_NONE;
1040 self.watertype = CONTENT_EMPTY;
1044 wishdir = normalize(wishvel);
1045 wishspeed = vlen(wishvel);
1046 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1047 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1048 if (time >= self.teleport_time)
1050 // water acceleration
1051 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1054 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!autocvar_g_jetpack_fuel || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO) && !self.freezetag_frozen)
1056 //makevectors(self.v_angle_y * '0 1 0');
1057 makevectors(self.v_angle);
1058 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1059 // add remaining speed as Z component
1060 maxairspd = autocvar_sv_maxairspeed*max(1, maxspd_mod);
1061 // fix speedhacks :P
1062 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
1063 // add the unused velocity as up component
1066 // if(self.BUTTON_JUMP)
1067 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1069 // it is now normalized, so...
1070 float a_side, a_up, a_add, a_diff;
1071 a_side = autocvar_g_jetpack_acceleration_side;
1072 a_up = autocvar_g_jetpack_acceleration_up;
1073 a_add = autocvar_g_jetpack_antigravity * autocvar_sv_gravity;
1075 wishvel_x *= a_side;
1076 wishvel_y *= a_side;
1082 //////////////////////////////////////////////////////////////////////////////////////
1083 // finding the maximum over all vectors of above form
1084 // with wishvel having an absolute value of 1
1085 //////////////////////////////////////////////////////////////////////////////////////
1086 // we're finding the maximum over
1087 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1088 // for z in the range from -1 to 1
1089 //////////////////////////////////////////////////////////////////////////////////////
1090 // maximum is EITHER attained at the single extreme point:
1091 a_diff = a_side * a_side - a_up * a_up;
1094 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1095 if(f > -1 && f < 1) // can it be attained?
1097 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1098 //print("middle\n");
1101 // OR attained at z = 1:
1102 f = (a_up + a_add) * (a_up + a_add);
1108 // OR attained at z = -1:
1109 f = (a_up - a_add) * (a_up - a_add);
1113 //print("bottom\n");
1116 //////////////////////////////////////////////////////////////////////////////////////
1118 //print("best possible acceleration: ", ftos(best), "\n");
1121 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / autocvar_g_jetpack_maxspeed_side, 1);
1122 if(wishvel_z - autocvar_sv_gravity > 0)
1123 fz = bound(0, 1 - self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1125 fz = bound(0, 1 + self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1128 fvel = vlen(wishvel);
1131 wishvel_z = (wishvel_z - autocvar_sv_gravity) * fz + autocvar_sv_gravity;
1133 fvel = min(1, vlen(wishvel) / best);
1134 if(autocvar_g_jetpack_fuel && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1135 f = min(1, self.ammo_fuel / (autocvar_g_jetpack_fuel * frametime * fvel));
1139 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1141 if (f > 0 && wishvel != '0 0 0')
1143 self.velocity = self.velocity + wishvel * f * frametime;
1144 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1145 self.ammo_fuel -= autocvar_g_jetpack_fuel * frametime * fvel * f;
1146 self.flags &~= FL_ONGROUND;
1147 self.items |= IT_USING_JETPACK;
1149 // jetpack also inhibits health regeneration, but only for 1 second
1150 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1153 else if (self.flags & FL_ONGROUND)
1155 // we get here if we ran out of ammo
1156 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
1157 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1160 makevectors(self.v_angle_y * '0 1 0');
1161 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1163 if(!(self.lastflags & FL_ONGROUND))
1165 if(autocvar_speedmeter)
1166 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1167 if(self.lastground < time - 0.3)
1168 self.velocity = self.velocity * (1 - autocvar_sv_friction_on_land);
1169 if(self.jumppadcount > 1)
1170 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1171 self.jumppadcount = 0;
1174 #ifdef LETS_TEST_FTEQCC
1175 if(self.velocity_x || self.velocity_y)
1193 if (f < autocvar_sv_stopspeed)
1194 f = 1 - frametime * (autocvar_sv_stopspeed / f) * autocvar_sv_friction;
1196 f = 1 - frametime * autocvar_sv_friction;
1198 self.velocity = self.velocity * f;
1200 self.velocity = '0 0 0';
1202 Mathematical analysis time!
1204 Our goal is to invert this mess.
1206 For the two cases we get:
1207 v = v0 * (1 - frametime * (autocvar_sv_stopspeed / v0) * autocvar_sv_friction)
1208 = v0 - frametime * autocvar_sv_stopspeed * autocvar_sv_friction
1209 v0 = v + frametime * autocvar_sv_stopspeed * autocvar_sv_friction
1211 v = v0 * (1 - frametime * autocvar_sv_friction)
1212 v0 = v / (1 - frametime * autocvar_sv_friction)
1214 These cases would be chosen ONLY if:
1215 v0 < autocvar_sv_stopspeed
1216 v + frametime * autocvar_sv_stopspeed * autocvar_sv_friction < autocvar_sv_stopspeed
1217 v < autocvar_sv_stopspeed * (1 - frametime * autocvar_sv_friction)
1219 v0 >= autocvar_sv_stopspeed
1220 v / (1 - frametime * autocvar_sv_friction) >= autocvar_sv_stopspeed
1221 v >= autocvar_sv_stopspeed * (1 - frametime * autocvar_sv_friction)
1226 wishdir = normalize(wishvel);
1227 wishspeed = vlen(wishvel);
1228 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1229 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1231 wishspeed = wishspeed * 0.5;
1232 if (time >= self.teleport_time)
1233 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1238 // we get here if we ran out of ammo
1239 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
1240 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1244 maxairspd = autocvar_sv_maxairspeed*maxspd_mod;
1245 airaccel = autocvar_sv_airaccelerate*maxspd_mod;
1249 maxairspd = autocvar_sv_maxairspeed;
1250 airaccel = autocvar_sv_airaccelerate;
1253 makevectors(self.v_angle_y * '0 1 0');
1254 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1256 wishdir = normalize(wishvel);
1257 wishspeed = wishspeed0 = vlen(wishvel);
1258 if (wishspeed0 > self.stat_sv_maxspeed*maxspd_mod)
1259 wishspeed0 = self.stat_sv_maxspeed*maxspd_mod;
1260 if (wishspeed > maxairspd)
1261 wishspeed = maxairspd;
1263 wishspeed = wishspeed * 0.5;
1264 if (time >= self.teleport_time)
1271 airaccelqw = self.stat_sv_airaccel_qw;
1272 accelerating = (self.velocity * wishdir > 0);
1273 wishspeed2 = wishspeed;
1276 if(autocvar_sv_airstopaccelerate)
1279 curdir = self.velocity;
1281 curdir = normalize(curdir);
1282 airaccel = airaccel + (autocvar_sv_airstopaccelerate*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1284 // note that for straight forward jumping:
1285 // step = accel * frametime * wishspeed0;
1286 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1288 // dv/dt = accel * maxspeed (when slow)
1289 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1290 // log dv/dt = logaccel + logmaxspeed (when slow)
1291 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1292 strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
1293 if(autocvar_sv_maxairstrafespeed)
1294 wishspeed = min(wishspeed, GeomLerp(autocvar_sv_maxairspeed*maxspd_mod, strafity, autocvar_sv_maxairstrafespeed*maxspd_mod));
1295 if(autocvar_sv_airstrafeaccelerate)
1296 airaccel = GeomLerp(airaccel, strafity, autocvar_sv_airstrafeaccelerate*maxspd_mod);
1297 if(self.stat_sv_airstrafeaccel_qw)
1298 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));
1301 if(autocvar_sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1302 PM_AirAccelerate(wishdir, wishspeed);
1304 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, autocvar_sv_airaccel_qw_stretchfactor, autocvar_sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw);
1306 if(autocvar_sv_aircontrol)
1307 CPM_PM_Aircontrol(wishdir, wishspeed2);
1311 if((g_cts || g_race) && self.classname != "observer") {
1312 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1313 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1314 speedaward_holder = self.netname;
1315 speedaward_uid = self.crypto_idfp;
1316 speedaward_lastupdate = time;
1318 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1324 race_send_speedaward(MSG_ALL);
1325 speedaward_lastsent = speedaward_speed;
1326 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") {
1327 speedaward_alltimebest = speedaward_speed;
1328 speedaward_alltimebest_holder = speedaward_holder;
1329 speedaward_alltimebest_uid = speedaward_uid;
1330 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1331 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1332 race_send_speedaward_alltimebest(MSG_ALL);
1338 xyspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y);
1339 if(self.weapon == WEP_NEX && autocvar_g_balance_nex_charge && autocvar_g_balance_nex_charge_velocity_rate && xyspeed > autocvar_g_balance_nex_charge_minspeed)
1341 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1342 xyspeed = min(xyspeed, autocvar_g_balance_nex_charge_maxspeed);
1343 f = (xyspeed - autocvar_g_balance_nex_charge_minspeed) / (autocvar_g_balance_nex_charge_maxspeed - autocvar_g_balance_nex_charge_minspeed);
1344 // add the extra charge
1345 self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_velocity_rate * f * frametime);
1348 if(self.flags & FL_ONGROUND)
1349 self.lastground = time;
1351 // conveyors: then break velocity again
1352 if(self.conveyor.state)
1353 self.velocity += self.conveyor.movedir;
1355 self.lastflags = self.flags;
1356 self.lastclassname = self.classname;