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(self.cvar_cl_movement_track_canjump)
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;
172 animdecide_setaction(self, ANIMACTION_JUMP, TRUE);
175 PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
177 self.restart_jump = -1; // restart jump anim next time
178 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
180 void CheckWaterJump()
184 // check for a jump-out-of-water
185 makevectors (self.angles);
187 start_z = start_z + 8;
189 normalize(v_forward);
190 end = start + v_forward*24;
191 traceline (start, end, TRUE, self);
192 if (trace_fraction < 1)
194 start_z = start_z + self.maxs_z - 8;
195 end = start + v_forward*24;
196 self.movedir = trace_plane_normal * -50;
197 traceline (start, end, TRUE, self);
198 if (trace_fraction == 1)
199 { // open at eye level
200 self.flags |= FL_WATERJUMP;
201 self.velocity_z = 225;
202 self.flags &~= FL_JUMPRELEASED;
203 self.teleport_time = time + 2; // safety net
208 void CheckPlayerJump()
210 if(self.flags & FL_ONGROUND)
212 if (autocvar_g_multijump > 0)
213 self.multijump_count = 0;
215 self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller
218 if (self.BUTTON_JUMP)
221 self.flags |= FL_JUMPRELEASED;
223 if (self.waterlevel == WATERLEVEL_SWIMMING)
225 self.prevjumpbutton = self.BUTTON_JUMP;
228 float racecar_angle(float forward, float down)
230 float ret, angle_mult;
238 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
240 angle_mult = forward / (800 + forward);
243 return ret * angle_mult + 360 * (1 - angle_mult);
245 return ret * angle_mult;
248 void RaceCarPhysics()
250 // using this move type for "big rigs"
251 // the engine does not push the entity!
253 float accel, steer, f, myspeed, steerfactor;
254 vector angles_save, rigvel;
256 angles_save = self.angles;
257 accel = bound(-1, self.movement_x / self.stat_sv_maxspeed, 1);
258 steer = bound(-1, self.movement_y / self.stat_sv_maxspeed, 1);
260 if(g_bugrigs_reverse_speeding)
264 // back accel is DIGITAL
265 // to prevent speedhack
275 makevectors(self.angles); // new forward direction!
277 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
279 float upspeed, accelfactor;
281 myspeed = self.velocity * v_forward;
282 upspeed = self.velocity * v_up;
284 // responsiveness factor for steering and acceleration
285 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
286 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
288 if(myspeed < 0 && g_bugrigs_reverse_spinning)
289 steerfactor = -myspeed * g_bugrigs_steer;
291 steerfactor = -myspeed * f * g_bugrigs_steer;
293 if(myspeed < 0 && g_bugrigs_reverse_speeding)
294 accelfactor = g_bugrigs_accel;
296 accelfactor = f * g_bugrigs_accel;
297 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
303 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
307 if(!g_bugrigs_reverse_speeding)
308 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
315 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
319 if(g_bugrigs_reverse_stopping)
322 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
325 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
326 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
328 self.angles_y += steer * frametime * steerfactor; // apply steering
329 makevectors(self.angles); // new forward direction!
331 myspeed += accel * accelfactor * frametime;
333 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
337 myspeed = vlen(self.velocity);
339 // responsiveness factor for steering and acceleration
340 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
341 steerfactor = -myspeed * f;
342 self.angles_y += steer * frametime * steerfactor; // apply steering
344 rigvel = self.velocity;
345 makevectors(self.angles); // new forward direction!
348 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
349 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
350 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
351 //MAXIMA: solve(total_acceleration(v) = 0, v);
353 if(g_bugrigs_planar_movement)
355 vector rigvel_xy, neworigin, up;
358 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
359 rigvel_xy = vec2(rigvel);
361 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
364 mt = MOVE_NOMONSTERS;
366 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
367 up = trace_endpos - self.origin;
369 // BUG RIGS: align the move to the surface instead of doing collision testing
371 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
374 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
376 if(trace_fraction < 0.5)
379 neworigin = self.origin;
382 neworigin = trace_endpos;
384 if(trace_fraction < 1)
386 // now set angles_x so that the car points parallel to the surface
387 self.angles = vectoangles(
388 '1 0 0' * v_forward_x * trace_plane_normal_z
390 '0 1 0' * v_forward_y * trace_plane_normal_z
392 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
394 self.flags |= FL_ONGROUND;
398 // now set angles_x so that the car points forward, but is tilted in velocity direction
399 self.flags &~= FL_ONGROUND;
402 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
403 self.movetype = MOVETYPE_NOCLIP;
407 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
408 self.velocity = rigvel;
409 self.movetype = MOVETYPE_FLY;
413 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
414 if(trace_fraction != 1)
416 self.angles = vectoangles2(
417 '1 0 0' * v_forward_x * trace_plane_normal_z
419 '0 1 0' * v_forward_y * trace_plane_normal_z
421 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
429 vel_local_x = v_forward * self.velocity;
430 vel_local_y = v_right * self.velocity;
431 vel_local_z = v_up * self.velocity;
433 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
434 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
438 vector vf1, vu1, smoothangles;
439 makevectors(self.angles);
440 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
445 makevectors(angles_save);
446 vf1 = vf1 + v_forward * (1 - f);
447 vu1 = vu1 + v_up * (1 - f);
448 smoothangles = vectoangles2(vf1, vu1);
449 self.angles_x = -smoothangles_x;
450 self.angles_z = smoothangles_z;
453 float IsMoveInDirection(vector mv, float angle) // key mix factor
455 if(mv_x == 0 && mv_y == 0)
456 return 0; // avoid division by zero
457 angle -= RAD2DEG * atan2(mv_y, mv_x);
458 angle = remainder(angle, 360) / 45;
463 return 1 - fabs(angle);
466 float GeomLerp(float a, float lerp, float b)
482 return a * pow(fabs(b / a), lerp);
485 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
487 float zspeed, xyspeed, dot, k;
490 // this doesn't play well with analog input
491 if(self.movement_x == 0 || self.movement_y != 0)
492 return; // can't control movement if not moving forward or backward
495 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
500 k *= bound(0, wishspeed / autocvar_sv_maxairspeed, 1);
502 zspeed = self.velocity_z;
504 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
506 dot = self.velocity * wishdir;
508 if(dot > 0) // we can't change direction while slowing down
510 k *= pow(dot, autocvar_sv_aircontrol_power)*frametime;
511 xyspeed = max(0, xyspeed - autocvar_sv_aircontrol_penalty * sqrt(max(0, 1 - dot*dot)) * k/32);
512 k *= autocvar_sv_aircontrol;
513 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
516 self.velocity = self.velocity * xyspeed;
517 self.velocity_z = zspeed;
520 float AdjustAirAccelQW(float accelqw, float factor)
522 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
525 // example config for alternate speed clamping:
526 // sv_airaccel_qw 0.8
527 // sv_airaccel_sideways_friction 0
528 // prvm_globalset server speedclamp_mode 1
530 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
538 float vel_xy_current;
539 float vel_xy_backward, vel_xy_forward;
542 if(stretchfactor > 0)
543 speedclamp = stretchfactor;
545 speedclamp = 1; // full clamping, no stretch
547 speedclamp = -1; // no clamping
552 if(autocvar_sv_gameplayfix_q2airaccelerate)
553 wishspeed0 = wishspeed;
555 vel_straight = self.velocity * wishdir;
556 vel_z = self.velocity_z;
557 vel_xy = vec2(self.velocity);
558 vel_perpend = vel_xy - vel_straight * wishdir;
560 step = accel * frametime * wishspeed0;
562 vel_xy_current = vlen(vel_xy);
564 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
565 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
566 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
567 if(vel_xy_backward < 0)
568 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
570 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
572 if(sidefric < 0 && (vel_perpend*vel_perpend))
573 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
576 f = max(0, 1 + frametime * wishspeed * sidefric);
577 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
578 // this cannot be > 1
580 vel_perpend = vel_perpend * max(0, f);
583 fminimum = sqrt(fminimum);
584 vel_perpend = vel_perpend * max(fminimum, f);
588 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
590 vel_xy = vel_straight * wishdir + vel_perpend;
594 float vel_xy_preclamp;
595 vel_xy_preclamp = vlen(vel_xy);
596 if(vel_xy_preclamp > 0) // prevent division by zero
598 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
599 if(vel_xy_current < vel_xy_preclamp)
600 vel_xy = vel_xy * (vel_xy_current / vel_xy_preclamp);
604 self.velocity = vel_xy + vel_z * '0 0 1';
607 void PM_AirAccelerate(vector wishdir, float wishspeed)
609 vector curvel, wishvel, acceldir, curdir;
610 float addspeed, accelspeed, curspeed, f;
616 curvel = self.velocity;
618 curspeed = vlen(curvel);
620 if(wishspeed > curspeed * 1.01)
622 wishspeed = min(wishspeed, curspeed + autocvar_sv_warsowbunny_airforwardaccel * self.stat_sv_maxspeed * frametime);
626 f = max(0, (autocvar_sv_warsowbunny_topspeed - curspeed) / (autocvar_sv_warsowbunny_topspeed - self.stat_sv_maxspeed));
627 wishspeed = max(curspeed, self.stat_sv_maxspeed) + autocvar_sv_warsowbunny_accel * f * self.stat_sv_maxspeed * frametime;
629 wishvel = wishdir * wishspeed;
630 acceldir = wishvel - curvel;
631 addspeed = vlen(acceldir);
632 acceldir = normalize(acceldir);
634 accelspeed = min(addspeed, autocvar_sv_warsowbunny_turnaccel * self.stat_sv_maxspeed * frametime);
636 if(autocvar_sv_warsowbunny_backtosideratio < 1)
638 curdir = normalize(curvel);
639 dot = acceldir * curdir;
641 acceldir = acceldir - (1 - autocvar_sv_warsowbunny_backtosideratio) * dot * curdir;
644 self.velocity += accelspeed * acceldir;
647 .vector movement_old;
650 .string lastclassname;
652 .float() PlayerPhysplug;
654 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
655 .float specialcommand_pos;
656 void SpecialCommand()
661 if(!CheatImpulse(99))
662 print("A hollow voice says \"Plugh\".\n");
666 float speedaward_speed;
667 string speedaward_holder;
668 string speedaward_uid;
669 void race_send_speedaward(float msg)
671 // send the best speed of the round
672 WriteByte(msg, SVC_TEMPENTITY);
673 WriteByte(msg, TE_CSQC_RACE);
674 WriteByte(msg, RACE_NET_SPEED_AWARD);
675 WriteInt24_t(msg, floor(speedaward_speed+0.5));
676 WriteString(msg, speedaward_holder);
679 float speedaward_alltimebest;
680 string speedaward_alltimebest_holder;
681 string speedaward_alltimebest_uid;
682 void race_send_speedaward_alltimebest(float msg)
684 // send the best speed
685 WriteByte(msg, SVC_TEMPENTITY);
686 WriteByte(msg, TE_CSQC_RACE);
687 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
688 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
689 WriteString(msg, speedaward_alltimebest_holder);
692 string GetMapname(void);
693 float speedaward_lastupdate;
694 float speedaward_lastsent;
695 void SV_PlayerPhysics()
697 vector wishvel, wishdir, v;
698 float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
701 float not_allowed_to_move;
704 WarpZone_PlayerPhysics_FixVAngle();
707 if(g_minstagib && (self.items & IT_INVINCIBLE))
708 maxspd_mod *= autocvar_g_minstagib_speed_highspeed;
711 maxspd_mod *= autocvar_g_nexball_basketball_carrier_highspeed;
713 maxspd_mod *= autocvar_g_keepaway_ballcarrier_highspeed;
717 if(self.runes & RUNE_SPEED)
719 if(self.runes & CURSE_SLOW)
720 maxspd_mod *= autocvar_g_balance_rune_speed_combo_highspeed;
722 maxspd_mod *= autocvar_g_balance_rune_speed_highspeed;
724 else if(self.runes & CURSE_SLOW)
726 maxspd_mod *= autocvar_g_balance_curse_slow_highspeed;
729 maxspd_mod *= autocvar_g_movement_highspeed;
731 // fix physics stats for g_movement_highspeed
732 // TODO maybe rather use maxairspeed? needs testing
733 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
734 if(autocvar_sv_airstrafeaccel_qw)
735 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
737 self.stat_sv_airstrafeaccel_qw = 0;
738 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
739 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
741 if(self.PlayerPhysplug)
742 if(self.PlayerPhysplug())
745 self.race_movetime_frac += frametime;
746 f = floor(self.race_movetime_frac);
747 self.race_movetime_frac -= f;
748 self.race_movetime_count += f;
749 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
753 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);
757 else if(buttons == 1)
759 else if(buttons == 2)
761 else if(buttons == 128)
763 else if(buttons == 256)
765 else if(buttons == 512)
767 else if(buttons == 1024)
772 if(c == substring(specialcommand, self.specialcommand_pos, 1))
774 self.specialcommand_pos += 1;
775 if(self.specialcommand_pos >= strlen(specialcommand))
777 self.specialcommand_pos = 0;
782 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
783 self.specialcommand_pos = 0;
785 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
787 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
788 self.parm_idlesince = time;
790 buttons_prev = self.buttons_old;
791 self.buttons_old = buttons;
792 self.movement_old = self.movement;
793 self.v_angle_old = self.v_angle;
795 if(time < self.nickspamtime)
796 if(self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
798 // slight annoyance for nick change scripts
799 self.movement = -1 * self.movement;
800 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
802 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!
804 self.angles_x = random() * 360;
805 self.angles_y = random() * 360;
806 // at least I'm not forcing retardedview by also assigning to angles_z
807 self.fixangle = TRUE;
811 if (self.punchangle != '0 0 0')
813 f = vlen(self.punchangle) - 10 * frametime;
815 self.punchangle = normalize(self.punchangle) * f;
817 self.punchangle = '0 0 0';
820 if (self.punchvector != '0 0 0')
822 f = vlen(self.punchvector) - 30 * frametime;
824 self.punchvector = normalize(self.punchvector) * f;
826 self.punchvector = '0 0 0';
829 if (IS_BOT_CLIENT(self))
831 if(playerdemo_read())
836 self.items &~= IT_USING_JETPACK;
840 if(self.race_penalty)
841 if(time > self.race_penalty)
842 self.race_penalty = 0;
844 not_allowed_to_move = 0;
845 if(self.race_penalty)
846 not_allowed_to_move = 1;
847 if(!autocvar_sv_ready_restart_after_countdown)
848 if(time < game_starttime)
849 not_allowed_to_move = 1;
851 if(not_allowed_to_move)
853 self.velocity = '0 0 0';
854 self.movetype = MOVETYPE_NONE;
855 self.disableclientprediction = 2;
857 else if(self.disableclientprediction == 2)
859 if(self.movetype == MOVETYPE_NONE)
860 self.movetype = MOVETYPE_WALK;
861 self.disableclientprediction = 0;
865 if (self.movetype == MOVETYPE_NONE)
868 // when we get here, disableclientprediction cannot be 2
869 self.disableclientprediction = 0;
870 if(time < self.ladder_time)
871 self.disableclientprediction = 1;
873 MUTATOR_CALLHOOK(PlayerPhysics);
875 if(self.player_blocked)
877 self.movement = '0 0 0';
878 self.disableclientprediction = 1;
885 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
888 // conveyors: first fix velocity
889 if(self.conveyor.state)
890 self.velocity -= self.conveyor.movedir;
892 if not(IS_PLAYER(self))
894 maxspd_mod = autocvar_sv_spectator_speed_multiplier;
895 if(!self.spectatorspeed)
896 self.spectatorspeed = maxspd_mod;
897 if(self.impulse && self.impulse <= 19 || self.impulse >= 200 && self.impulse <= 209 || self.impulse >= 220 && self.impulse <= 229)
899 if(self.lastclassname != "player")
901 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || self.impulse >= 200 && self.impulse <= 209)
902 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
903 else if(self.impulse == 11)
904 self.spectatorspeed = maxspd_mod;
905 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || self.impulse >= 220 && self.impulse <= 229)
906 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
907 else if(self.impulse >= 1 && self.impulse <= 9)
908 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
909 } // otherwise just clear
912 maxspd_mod = self.spectatorspeed;
915 spd = max(self.stat_sv_maxspeed, autocvar_sv_maxairspeed) * maxspd_mod * swampspd_mod;
916 if(self.speed != spd)
920 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
921 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
922 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
923 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
926 maxspd_mod *= swampspd_mod; // only one common speed modder please!
929 // if dead, behave differently
933 if (!self.fixangle && !g_bugrigs)
936 self.angles_y = self.v_angle_y;
940 if(self.flags & FL_ONGROUND)
941 if(IS_PLAYER(self)) // no fall sounds for observers thank you very much
946 if(self.waterlevel < WATERLEVEL_SWIMMING)
947 if(time >= self.ladder_time)
950 self.nextstep = time + 0.3 + random() * 0.1;
951 trace_dphitq3surfaceflags = 0;
952 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
953 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
955 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
956 GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
958 GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
969 if (self.flags & FL_WATERJUMP )
971 self.velocity_x = self.movedir_x;
972 self.velocity_y = self.movedir_y;
973 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
975 self.flags &~= FL_WATERJUMP;
976 self.teleport_time = 0;
979 else if (g_bugrigs && IS_PLAYER(self))
983 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
985 // noclipping or flying
986 self.flags &~= FL_ONGROUND;
988 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
989 makevectors(self.v_angle);
990 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
991 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
993 wishdir = normalize(wishvel);
994 wishspeed = vlen(wishvel);
995 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
996 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
997 if (time >= self.teleport_time)
998 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1000 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
1003 self.flags &~= FL_ONGROUND;
1005 makevectors(self.v_angle);
1006 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
1007 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
1008 if (wishvel == '0 0 0')
1009 wishvel = '0 0 -60'; // drift towards bottom
1011 wishdir = normalize(wishvel);
1012 wishspeed = vlen(wishvel);
1013 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1014 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1015 wishspeed = wishspeed * 0.7;
1018 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
1020 // water acceleration
1021 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1023 else if (time < self.ladder_time)
1025 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
1026 self.flags &~= FL_ONGROUND;
1029 g = autocvar_sv_gravity * frametime;
1032 if(autocvar_sv_gameplayfix_gravityunaffectedbyticrate)
1035 self.velocity_z += g;
1038 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
1039 makevectors(self.v_angle);
1040 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
1041 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
1042 self.velocity_z += g;
1043 if (self.ladder_entity.classname == "func_water")
1046 if (f > self.ladder_entity.speed)
1047 wishvel = wishvel * (self.ladder_entity.speed / f);
1049 self.watertype = self.ladder_entity.skin;
1050 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1051 if ((self.origin_z + self.view_ofs_z) < f)
1052 self.waterlevel = WATERLEVEL_SUBMERGED;
1053 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1054 self.waterlevel = WATERLEVEL_SWIMMING;
1055 else if ((self.origin_z + self.mins_z + 1) < f)
1056 self.waterlevel = WATERLEVEL_WETFEET;
1059 self.waterlevel = WATERLEVEL_NONE;
1060 self.watertype = CONTENT_EMPTY;
1064 wishdir = normalize(wishvel);
1065 wishspeed = vlen(wishvel);
1066 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1067 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1068 if (time >= self.teleport_time)
1070 // water acceleration
1071 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1074 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)
1076 //makevectors(self.v_angle_y * '0 1 0');
1077 makevectors(self.v_angle);
1078 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1079 // add remaining speed as Z component
1080 maxairspd = autocvar_sv_maxairspeed*max(1, maxspd_mod);
1081 // fix speedhacks :P
1082 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
1083 // add the unused velocity as up component
1086 // if(self.BUTTON_JUMP)
1087 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1089 // it is now normalized, so...
1090 float a_side, a_up, a_add, a_diff;
1091 a_side = autocvar_g_jetpack_acceleration_side;
1092 a_up = autocvar_g_jetpack_acceleration_up;
1093 a_add = autocvar_g_jetpack_antigravity * autocvar_sv_gravity;
1095 wishvel_x *= a_side;
1096 wishvel_y *= a_side;
1102 //////////////////////////////////////////////////////////////////////////////////////
1103 // finding the maximum over all vectors of above form
1104 // with wishvel having an absolute value of 1
1105 //////////////////////////////////////////////////////////////////////////////////////
1106 // we're finding the maximum over
1107 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1108 // for z in the range from -1 to 1
1109 //////////////////////////////////////////////////////////////////////////////////////
1110 // maximum is EITHER attained at the single extreme point:
1111 a_diff = a_side * a_side - a_up * a_up;
1114 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1115 if(f > -1 && f < 1) // can it be attained?
1117 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1118 //print("middle\n");
1121 // OR attained at z = 1:
1122 f = (a_up + a_add) * (a_up + a_add);
1128 // OR attained at z = -1:
1129 f = (a_up - a_add) * (a_up - a_add);
1133 //print("bottom\n");
1136 //////////////////////////////////////////////////////////////////////////////////////
1138 //print("best possible acceleration: ", ftos(best), "\n");
1141 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / autocvar_g_jetpack_maxspeed_side, 1);
1142 if(wishvel_z - autocvar_sv_gravity > 0)
1143 fz = bound(0, 1 - self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1145 fz = bound(0, 1 + self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1148 fvel = vlen(wishvel);
1151 wishvel_z = (wishvel_z - autocvar_sv_gravity) * fz + autocvar_sv_gravity;
1153 fvel = min(1, vlen(wishvel) / best);
1154 if(autocvar_g_jetpack_fuel && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1155 f = min(1, self.ammo_fuel / (autocvar_g_jetpack_fuel * frametime * fvel));
1159 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1161 if (f > 0 && wishvel != '0 0 0')
1163 self.velocity = self.velocity + wishvel * f * frametime;
1164 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1165 self.ammo_fuel -= autocvar_g_jetpack_fuel * frametime * fvel * f;
1166 self.flags &~= FL_ONGROUND;
1167 self.items |= IT_USING_JETPACK;
1169 // jetpack also inhibits health regeneration, but only for 1 second
1170 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1173 else if (self.flags & FL_ONGROUND)
1175 // we get here if we ran out of ammo
1176 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
1177 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1180 makevectors(self.v_angle_y * '0 1 0');
1181 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1183 if(!(self.lastflags & FL_ONGROUND))
1185 if(autocvar_speedmeter)
1186 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1187 if(self.lastground < time - 0.3)
1188 self.velocity = self.velocity * (1 - autocvar_sv_friction_on_land);
1189 if(self.jumppadcount > 1)
1190 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1191 self.jumppadcount = 0;
1194 #ifdef LETS_TEST_FTEQCC
1195 if(self.velocity_x || self.velocity_y)
1213 if (f < autocvar_sv_stopspeed)
1214 f = 1 - frametime * (autocvar_sv_stopspeed / f) * autocvar_sv_friction;
1216 f = 1 - frametime * autocvar_sv_friction;
1218 self.velocity = self.velocity * f;
1220 self.velocity = '0 0 0';
1222 Mathematical analysis time!
1224 Our goal is to invert this mess.
1226 For the two cases we get:
1227 v = v0 * (1 - frametime * (autocvar_sv_stopspeed / v0) * autocvar_sv_friction)
1228 = v0 - frametime * autocvar_sv_stopspeed * autocvar_sv_friction
1229 v0 = v + frametime * autocvar_sv_stopspeed * autocvar_sv_friction
1231 v = v0 * (1 - frametime * autocvar_sv_friction)
1232 v0 = v / (1 - frametime * autocvar_sv_friction)
1234 These cases would be chosen ONLY if:
1235 v0 < autocvar_sv_stopspeed
1236 v + frametime * autocvar_sv_stopspeed * autocvar_sv_friction < autocvar_sv_stopspeed
1237 v < autocvar_sv_stopspeed * (1 - frametime * autocvar_sv_friction)
1239 v0 >= autocvar_sv_stopspeed
1240 v / (1 - frametime * autocvar_sv_friction) >= autocvar_sv_stopspeed
1241 v >= autocvar_sv_stopspeed * (1 - frametime * autocvar_sv_friction)
1246 wishdir = normalize(wishvel);
1247 wishspeed = vlen(wishvel);
1248 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1249 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1251 wishspeed = wishspeed * 0.5;
1252 if (time >= self.teleport_time)
1253 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1258 // we get here if we ran out of ammo
1259 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
1260 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1264 maxairspd = autocvar_sv_maxairspeed*maxspd_mod;
1265 airaccel = autocvar_sv_airaccelerate*maxspd_mod;
1269 maxairspd = autocvar_sv_maxairspeed;
1270 airaccel = autocvar_sv_airaccelerate;
1273 makevectors(self.v_angle_y * '0 1 0');
1274 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1276 wishdir = normalize(wishvel);
1277 wishspeed = wishspeed0 = vlen(wishvel);
1278 if (wishspeed0 > self.stat_sv_maxspeed*maxspd_mod)
1279 wishspeed0 = self.stat_sv_maxspeed*maxspd_mod;
1280 if (wishspeed > maxairspd)
1281 wishspeed = maxairspd;
1283 wishspeed = wishspeed * 0.5;
1284 if (time >= self.teleport_time)
1291 airaccelqw = self.stat_sv_airaccel_qw;
1292 accelerating = (self.velocity * wishdir > 0);
1293 wishspeed2 = wishspeed;
1296 if(autocvar_sv_airstopaccelerate)
1299 curdir = self.velocity;
1301 curdir = normalize(curdir);
1302 airaccel = airaccel + (autocvar_sv_airstopaccelerate*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1304 // note that for straight forward jumping:
1305 // step = accel * frametime * wishspeed0;
1306 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1308 // dv/dt = accel * maxspeed (when slow)
1309 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1310 // log dv/dt = logaccel + logmaxspeed (when slow)
1311 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1312 strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
1313 if(autocvar_sv_maxairstrafespeed)
1314 wishspeed = min(wishspeed, GeomLerp(autocvar_sv_maxairspeed*maxspd_mod, strafity, autocvar_sv_maxairstrafespeed*maxspd_mod));
1315 if(autocvar_sv_airstrafeaccelerate)
1316 airaccel = GeomLerp(airaccel, strafity, autocvar_sv_airstrafeaccelerate*maxspd_mod);
1317 if(self.stat_sv_airstrafeaccel_qw)
1318 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));
1321 if(autocvar_sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1322 PM_AirAccelerate(wishdir, wishspeed);
1324 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, autocvar_sv_airaccel_qw_stretchfactor, autocvar_sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw);
1326 if(autocvar_sv_aircontrol)
1327 CPM_PM_Aircontrol(wishdir, wishspeed2);
1331 if((g_cts || g_race) && !IS_OBSERVER(self)) {
1332 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1333 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1334 speedaward_holder = self.netname;
1335 speedaward_uid = self.crypto_idfp;
1336 speedaward_lastupdate = time;
1338 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1344 race_send_speedaward(MSG_ALL);
1345 speedaward_lastsent = speedaward_speed;
1346 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") {
1347 speedaward_alltimebest = speedaward_speed;
1348 speedaward_alltimebest_holder = speedaward_holder;
1349 speedaward_alltimebest_uid = speedaward_uid;
1350 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1351 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1352 race_send_speedaward_alltimebest(MSG_ALL);
1358 xyspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y);
1359 if(self.weapon == WEP_NEX && autocvar_g_balance_nex_charge && autocvar_g_balance_nex_charge_velocity_rate && xyspeed > autocvar_g_balance_nex_charge_minspeed)
1361 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1362 xyspeed = min(xyspeed, autocvar_g_balance_nex_charge_maxspeed);
1363 f = (xyspeed - autocvar_g_balance_nex_charge_minspeed) / (autocvar_g_balance_nex_charge_maxspeed - autocvar_g_balance_nex_charge_minspeed);
1364 // add the extra charge
1365 self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_velocity_rate * f * frametime);
1368 if(self.flags & FL_ONGROUND)
1369 self.lastground = time;
1371 // conveyors: then break velocity again
1372 if(self.conveyor.state)
1373 self.velocity += self.conveyor.movedir;
1375 self.lastflags = self.flags;
1376 self.lastclassname = self.classname;