11 .float spectatorspeed;
17 When you press the jump key
20 void PlayerJump (void)
23 return; // no jumping in freezetag when frozen
25 float doublejump = FALSE;
27 player_multijump = doublejump;
28 if(MUTATOR_CALLHOOK(PlayerJump))
31 doublejump = player_multijump;
35 if (autocvar_sv_doublejump)
37 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
38 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
42 // we MUST clip velocity here!
44 f = self.velocity * trace_plane_normal;
46 self.velocity -= f * trace_plane_normal;
50 mjumpheight = autocvar_sv_jumpvelocity;
51 if (self.waterlevel >= WATERLEVEL_SWIMMING)
53 self.velocity_z = self.stat_sv_maxspeed * 0.7;
58 if (!(self.flags & FL_ONGROUND))
61 if(self.cvar_cl_movement_track_canjump)
62 if (!(self.flags & FL_JUMPRELEASED))
65 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
66 // velocity bounds. Final velocity is bound between (jumpheight *
67 // min + jumpheight) and (jumpheight * max + jumpheight);
69 if(autocvar_sv_jumpspeedcap_min != "")
73 minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min);
75 if (self.velocity_z < minjumpspeed)
76 mjumpheight += minjumpspeed - self.velocity_z;
79 if(autocvar_sv_jumpspeedcap_max != "")
81 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
82 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
84 if(!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && autocvar_sv_jumpspeedcap_max_disable_on_ramps))
88 maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max);
90 if (self.velocity_z > maxjumpspeed)
91 mjumpheight -= self.velocity_z - maxjumpspeed;
95 if(!(self.lastflags & FL_ONGROUND))
97 if(autocvar_speedmeter)
98 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
99 if(self.lastground < time - 0.3)
101 self.velocity_x *= (1 - autocvar_sv_friction_on_land);
102 self.velocity_y *= (1 - autocvar_sv_friction_on_land);
104 if(self.jumppadcount > 1)
105 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
106 self.jumppadcount = 0;
109 self.velocity_z = self.velocity_z + mjumpheight;
110 self.oldvelocity_z = self.velocity_z;
112 self.flags &= ~FL_ONGROUND;
113 self.flags &= ~FL_JUMPRELEASED;
115 animdecide_setaction(self, ANIMACTION_JUMP, TRUE);
117 if(autocvar_g_jump_grunt)
118 PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
120 self.restart_jump = -1; // restart jump anim next time
121 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
123 void CheckWaterJump()
127 // check for a jump-out-of-water
128 makevectors (self.angles);
130 start_z = start_z + 8;
132 normalize(v_forward);
133 end = start + v_forward*24;
134 traceline (start, end, TRUE, self);
135 if (trace_fraction < 1)
137 start_z = start_z + self.maxs_z - 8;
138 end = start + v_forward*24;
139 self.movedir = trace_plane_normal * -50;
140 traceline (start, end, TRUE, self);
141 if (trace_fraction == 1)
142 { // open at eye level
143 self.flags |= FL_WATERJUMP;
144 self.velocity_z = 225;
145 self.flags &= ~FL_JUMPRELEASED;
146 self.teleport_time = time + 2; // safety net
151 void CheckPlayerJump()
153 if (self.BUTTON_JUMP)
156 self.flags |= FL_JUMPRELEASED;
158 if (self.waterlevel == WATERLEVEL_SWIMMING)
162 float racecar_angle(float forward, float down)
164 float ret, angle_mult;
172 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
174 angle_mult = forward / (800 + forward);
177 return ret * angle_mult + 360 * (1 - angle_mult);
179 return ret * angle_mult;
182 void RaceCarPhysics()
184 // using this move type for "big rigs"
185 // the engine does not push the entity!
187 float accel, steer, f, myspeed, steerfactor;
188 vector angles_save, rigvel;
190 angles_save = self.angles;
191 accel = bound(-1, self.movement_x / self.stat_sv_maxspeed, 1);
192 steer = bound(-1, self.movement_y / self.stat_sv_maxspeed, 1);
194 if(g_bugrigs_reverse_speeding)
198 // back accel is DIGITAL
199 // to prevent speedhack
209 makevectors(self.angles); // new forward direction!
211 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
213 float upspeed, accelfactor;
215 myspeed = self.velocity * v_forward;
216 upspeed = self.velocity * v_up;
218 // responsiveness factor for steering and acceleration
219 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
220 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
222 if(myspeed < 0 && g_bugrigs_reverse_spinning)
223 steerfactor = -myspeed * g_bugrigs_steer;
225 steerfactor = -myspeed * f * g_bugrigs_steer;
227 if(myspeed < 0 && g_bugrigs_reverse_speeding)
228 accelfactor = g_bugrigs_accel;
230 accelfactor = f * g_bugrigs_accel;
231 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
237 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
241 if(!g_bugrigs_reverse_speeding)
242 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
249 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
253 if(g_bugrigs_reverse_stopping)
256 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
259 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
260 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
262 self.angles_y += steer * frametime * steerfactor; // apply steering
263 makevectors(self.angles); // new forward direction!
265 myspeed += accel * accelfactor * frametime;
267 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
271 myspeed = vlen(self.velocity);
273 // responsiveness factor for steering and acceleration
274 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
275 steerfactor = -myspeed * f;
276 self.angles_y += steer * frametime * steerfactor; // apply steering
278 rigvel = self.velocity;
279 makevectors(self.angles); // new forward direction!
282 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
283 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
284 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
285 //MAXIMA: solve(total_acceleration(v) = 0, v);
287 if(g_bugrigs_planar_movement)
289 vector rigvel_xy, neworigin, up;
292 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
293 rigvel_xy = vec2(rigvel);
295 if(g_bugrigs_planar_movement_car_jumping)
298 mt = MOVE_NOMONSTERS;
300 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
301 up = trace_endpos - self.origin;
303 // BUG RIGS: align the move to the surface instead of doing collision testing
305 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
308 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
310 if(trace_fraction < 0.5)
313 neworigin = self.origin;
316 neworigin = trace_endpos;
318 if(trace_fraction < 1)
320 // now set angles_x so that the car points parallel to the surface
321 self.angles = vectoangles(
322 '1 0 0' * v_forward_x * trace_plane_normal_z
324 '0 1 0' * v_forward_y * trace_plane_normal_z
326 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
328 self.flags |= FL_ONGROUND;
332 // now set angles_x so that the car points forward, but is tilted in velocity direction
333 self.flags &= ~FL_ONGROUND;
336 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
337 self.movetype = MOVETYPE_NOCLIP;
341 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
342 self.velocity = rigvel;
343 self.movetype = MOVETYPE_FLY;
347 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
348 if(trace_fraction != 1)
350 self.angles = vectoangles2(
351 '1 0 0' * v_forward_x * trace_plane_normal_z
353 '0 1 0' * v_forward_y * trace_plane_normal_z
355 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
363 vel_local_x = v_forward * self.velocity;
364 vel_local_y = v_right * self.velocity;
365 vel_local_z = v_up * self.velocity;
367 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
368 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
372 vector vf1, vu1, smoothangles;
373 makevectors(self.angles);
374 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
379 makevectors(angles_save);
380 vf1 = vf1 + v_forward * (1 - f);
381 vu1 = vu1 + v_up * (1 - f);
382 smoothangles = vectoangles2(vf1, vu1);
383 self.angles_x = -smoothangles_x;
384 self.angles_z = smoothangles_z;
387 float IsMoveInDirection(vector mv, float angle) // key mix factor
389 if(mv_x == 0 && mv_y == 0)
390 return 0; // avoid division by zero
391 angle -= RAD2DEG * atan2(mv_y, mv_x);
392 angle = remainder(angle, 360) / 45;
397 return 1 - fabs(angle);
400 float GeomLerp(float a, float lerp, float b)
416 return a * pow(fabs(b / a), lerp);
419 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
421 float zspeed, xyspeed, dot, k;
424 // this doesn't play well with analog input
425 if(self.movement_x == 0 || self.movement_y != 0)
426 return; // can't control movement if not moving forward or backward
429 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
434 k *= bound(0, wishspeed / autocvar_sv_maxairspeed, 1);
436 zspeed = self.velocity_z;
438 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
440 dot = self.velocity * wishdir;
442 if(dot > 0) // we can't change direction while slowing down
444 k *= pow(dot, autocvar_sv_aircontrol_power)*frametime;
445 xyspeed = max(0, xyspeed - autocvar_sv_aircontrol_penalty * sqrt(max(0, 1 - dot*dot)) * k/32);
446 k *= autocvar_sv_aircontrol;
447 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
450 self.velocity = self.velocity * xyspeed;
451 self.velocity_z = zspeed;
454 float AdjustAirAccelQW(float accelqw, float factor)
456 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
459 // example config for alternate speed clamping:
460 // sv_airaccel_qw 0.8
461 // sv_airaccel_sideways_friction 0
462 // prvm_globalset server speedclamp_mode 1
464 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
472 float vel_xy_current;
473 float vel_xy_backward, vel_xy_forward;
476 if(stretchfactor > 0)
477 speedclamp = stretchfactor;
479 speedclamp = 1; // full clamping, no stretch
481 speedclamp = -1; // no clamping
486 if(autocvar_sv_gameplayfix_q2airaccelerate)
487 wishspeed0 = wishspeed;
489 vel_straight = self.velocity * wishdir;
490 vel_z = self.velocity_z;
491 vel_xy = vec2(self.velocity);
492 vel_perpend = vel_xy - vel_straight * wishdir;
494 step = accel * frametime * wishspeed0;
496 vel_xy_current = vlen(vel_xy);
498 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
499 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
500 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
501 if(vel_xy_backward < 0)
502 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
504 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
506 if(sidefric < 0 && (vel_perpend*vel_perpend))
507 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
510 f = max(0, 1 + frametime * wishspeed * sidefric);
511 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
512 // this cannot be > 1
514 vel_perpend = vel_perpend * max(0, f);
517 fminimum = sqrt(fminimum);
518 vel_perpend = vel_perpend * max(fminimum, f);
522 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
524 vel_xy = vel_straight * wishdir + vel_perpend;
528 float vel_xy_preclamp;
529 vel_xy_preclamp = vlen(vel_xy);
530 if(vel_xy_preclamp > 0) // prevent division by zero
532 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
533 if(vel_xy_current < vel_xy_preclamp)
534 vel_xy = vel_xy * (vel_xy_current / vel_xy_preclamp);
538 self.velocity = vel_xy + vel_z * '0 0 1';
541 void PM_AirAccelerate(vector wishdir, float wishspeed)
543 vector curvel, wishvel, acceldir, curdir;
544 float addspeed, accelspeed, curspeed, f;
550 curvel = self.velocity;
552 curspeed = vlen(curvel);
554 if(wishspeed > curspeed * 1.01)
556 wishspeed = min(wishspeed, curspeed + autocvar_sv_warsowbunny_airforwardaccel * self.stat_sv_maxspeed * frametime);
560 f = max(0, (autocvar_sv_warsowbunny_topspeed - curspeed) / (autocvar_sv_warsowbunny_topspeed - self.stat_sv_maxspeed));
561 wishspeed = max(curspeed, self.stat_sv_maxspeed) + autocvar_sv_warsowbunny_accel * f * self.stat_sv_maxspeed * frametime;
563 wishvel = wishdir * wishspeed;
564 acceldir = wishvel - curvel;
565 addspeed = vlen(acceldir);
566 acceldir = normalize(acceldir);
568 accelspeed = min(addspeed, autocvar_sv_warsowbunny_turnaccel * self.stat_sv_maxspeed * frametime);
570 if(autocvar_sv_warsowbunny_backtosideratio < 1)
572 curdir = normalize(curvel);
573 dot = acceldir * curdir;
575 acceldir = acceldir - (1 - autocvar_sv_warsowbunny_backtosideratio) * dot * curdir;
578 self.velocity += accelspeed * acceldir;
581 .vector movement_old;
584 .string lastclassname;
586 .float() PlayerPhysplug;
588 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
589 .float specialcommand_pos;
590 void SpecialCommand()
595 if(!CheatImpulse(99))
596 print("A hollow voice says \"Plugh\".\n");
600 float speedaward_speed;
601 string speedaward_holder;
602 string speedaward_uid;
603 void race_send_speedaward(float msg)
605 // send the best speed of the round
606 WriteByte(msg, SVC_TEMPENTITY);
607 WriteByte(msg, TE_CSQC_RACE);
608 WriteByte(msg, RACE_NET_SPEED_AWARD);
609 WriteInt24_t(msg, floor(speedaward_speed+0.5));
610 WriteString(msg, speedaward_holder);
613 float speedaward_alltimebest;
614 string speedaward_alltimebest_holder;
615 string speedaward_alltimebest_uid;
616 void race_send_speedaward_alltimebest(float msg)
618 // send the best speed
619 WriteByte(msg, SVC_TEMPENTITY);
620 WriteByte(msg, TE_CSQC_RACE);
621 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
622 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
623 WriteString(msg, speedaward_alltimebest_holder);
626 string GetMapname(void);
627 float speedaward_lastupdate;
628 float speedaward_lastsent;
629 void SV_PlayerPhysics()
631 vector wishvel, wishdir, v;
632 float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
635 float not_allowed_to_move;
638 WarpZone_PlayerPhysics_FixVAngle();
643 maxspd_mod *= autocvar_g_nexball_basketball_carrier_highspeed;
645 maxspd_mod *= autocvar_g_keepaway_ballcarrier_highspeed;
647 maxspd_mod *= autocvar_g_movement_highspeed;
649 // fix physics stats for g_movement_highspeed
650 // TODO maybe rather use maxairspeed? needs testing
651 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
652 if(autocvar_sv_airstrafeaccel_qw)
653 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
655 self.stat_sv_airstrafeaccel_qw = 0;
656 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
657 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
659 if(self.PlayerPhysplug)
660 if(self.PlayerPhysplug())
663 self.race_movetime_frac += frametime;
664 f = floor(self.race_movetime_frac);
665 self.race_movetime_frac -= f;
666 self.race_movetime_count += f;
667 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
671 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);
675 else if(buttons == 1)
677 else if(buttons == 2)
679 else if(buttons == 128)
681 else if(buttons == 256)
683 else if(buttons == 512)
685 else if(buttons == 1024)
690 if(c == substring(specialcommand, self.specialcommand_pos, 1))
692 self.specialcommand_pos += 1;
693 if(self.specialcommand_pos >= strlen(specialcommand))
695 self.specialcommand_pos = 0;
700 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
701 self.specialcommand_pos = 0;
705 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
706 self.parm_idlesince = time;
708 buttons_prev = self.buttons_old;
709 self.buttons_old = buttons;
710 self.movement_old = self.movement;
711 self.v_angle_old = self.v_angle;
713 if(time < self.nickspamtime)
714 if(self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
716 // slight annoyance for nick change scripts
717 self.movement = -1 * self.movement;
718 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
720 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!
722 self.angles_x = random() * 360;
723 self.angles_y = random() * 360;
724 // at least I'm not forcing retardedview by also assigning to angles_z
725 self.fixangle = TRUE;
729 if (self.punchangle != '0 0 0')
731 f = vlen(self.punchangle) - 10 * frametime;
733 self.punchangle = normalize(self.punchangle) * f;
735 self.punchangle = '0 0 0';
738 if (self.punchvector != '0 0 0')
740 f = vlen(self.punchvector) - 30 * frametime;
742 self.punchvector = normalize(self.punchvector) * f;
744 self.punchvector = '0 0 0';
747 if (IS_BOT_CLIENT(self))
749 if(playerdemo_read())
754 self.items &= ~IT_USING_JETPACK;
758 if(self.race_penalty)
759 if(time > self.race_penalty)
760 self.race_penalty = 0;
762 not_allowed_to_move = 0;
763 if(self.race_penalty)
764 not_allowed_to_move = 1;
765 if(!autocvar_sv_ready_restart_after_countdown)
766 if(time < game_starttime)
767 not_allowed_to_move = 1;
769 if(not_allowed_to_move)
771 self.velocity = '0 0 0';
772 self.movetype = MOVETYPE_NONE;
773 self.disableclientprediction = 2;
775 else if(self.disableclientprediction == 2)
777 if(self.movetype == MOVETYPE_NONE)
778 self.movetype = MOVETYPE_WALK;
779 self.disableclientprediction = 0;
783 if (self.movetype == MOVETYPE_NONE)
786 // when we get here, disableclientprediction cannot be 2
787 self.disableclientprediction = 0;
788 if(time < self.ladder_time)
789 self.disableclientprediction = 1;
791 if(time < self.spider_slowness)
793 self.stat_sv_maxspeed *= 0.5; // half speed while slow from spider
794 self.stat_sv_airspeedlimit_nonqw *= 0.5;
799 if(autocvar_sv_dodging_frozen && IS_REAL_CLIENT(self))
801 self.movement_x = bound(-5, self.movement_x, 5);
802 self.movement_y = bound(-5, self.movement_y, 5);
803 self.movement_z = bound(-5, self.movement_z, 5);
806 self.movement = '0 0 0';
807 self.disableclientprediction = 1;
810 MUTATOR_CALLHOOK(PlayerPhysics);
812 if(self.player_blocked)
814 self.movement = '0 0 0';
815 self.disableclientprediction = 1;
822 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
825 // conveyors: first fix velocity
826 if(self.conveyor.state)
827 self.velocity -= self.conveyor.movedir;
829 if not(IS_PLAYER(self))
831 maxspd_mod = autocvar_sv_spectator_speed_multiplier;
832 if(!self.spectatorspeed)
833 self.spectatorspeed = maxspd_mod;
834 if(self.impulse && self.impulse <= 19 || (self.impulse >= 200 && self.impulse <= 209) || (self.impulse >= 220 && self.impulse <= 229))
836 if(self.lastclassname != "player")
838 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209))
839 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
840 else if(self.impulse == 11)
841 self.spectatorspeed = maxspd_mod;
842 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229))
843 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
844 else if(self.impulse >= 1 && self.impulse <= 9)
845 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
846 } // otherwise just clear
849 maxspd_mod = self.spectatorspeed;
852 spd = max(self.stat_sv_maxspeed, autocvar_sv_maxairspeed) * maxspd_mod * swampspd_mod;
853 if(self.speed != spd)
857 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
858 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
859 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
860 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
863 maxspd_mod *= swampspd_mod; // only one common speed modder please!
866 // if dead, behave differently
870 if (!self.fixangle && !g_bugrigs)
873 self.angles_y = self.v_angle_y;
877 if(self.flags & FL_ONGROUND)
878 if(IS_PLAYER(self)) // no fall sounds for observers thank you very much
883 if(self.waterlevel < WATERLEVEL_SWIMMING)
884 if(time >= self.ladder_time)
887 self.nextstep = time + 0.3 + random() * 0.1;
888 trace_dphitq3surfaceflags = 0;
889 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
890 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
892 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
893 GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
895 GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
906 if (self.flags & FL_WATERJUMP )
908 self.velocity_x = self.movedir_x;
909 self.velocity_y = self.movedir_y;
910 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
912 self.flags &= ~FL_WATERJUMP;
913 self.teleport_time = 0;
916 else if (g_bugrigs && IS_PLAYER(self))
920 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
922 // noclipping or flying
923 self.flags &= ~FL_ONGROUND;
925 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
926 makevectors(self.v_angle);
927 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
928 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
930 wishdir = normalize(wishvel);
931 wishspeed = vlen(wishvel);
932 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
933 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
934 if (time >= self.teleport_time)
935 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
937 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
940 self.flags &= ~FL_ONGROUND;
942 makevectors(self.v_angle);
943 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
944 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
945 if (wishvel == '0 0 0')
946 wishvel = '0 0 -60'; // drift towards bottom
948 wishdir = normalize(wishvel);
949 wishspeed = vlen(wishvel);
950 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
951 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
952 wishspeed = wishspeed * 0.7;
955 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
957 // water acceleration
958 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
960 else if (time < self.ladder_time)
962 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
963 self.flags &= ~FL_ONGROUND;
966 g = autocvar_sv_gravity * frametime;
969 if(autocvar_sv_gameplayfix_gravityunaffectedbyticrate)
972 self.velocity_z += g;
975 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
976 makevectors(self.v_angle);
977 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
978 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
979 self.velocity_z += g;
980 if (self.ladder_entity.classname == "func_water")
983 if (f > self.ladder_entity.speed)
984 wishvel = wishvel * (self.ladder_entity.speed / f);
986 self.watertype = self.ladder_entity.skin;
987 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
988 if ((self.origin_z + self.view_ofs_z) < f)
989 self.waterlevel = WATERLEVEL_SUBMERGED;
990 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
991 self.waterlevel = WATERLEVEL_SWIMMING;
992 else if ((self.origin_z + self.mins_z + 1) < f)
993 self.waterlevel = WATERLEVEL_WETFEET;
996 self.waterlevel = WATERLEVEL_NONE;
997 self.watertype = CONTENT_EMPTY;
1001 wishdir = normalize(wishvel);
1002 wishspeed = vlen(wishvel);
1003 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1004 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1005 if (time >= self.teleport_time)
1007 // water acceleration
1008 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1011 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.frozen)
1013 //makevectors(self.v_angle_y * '0 1 0');
1014 makevectors(self.v_angle);
1015 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1016 // add remaining speed as Z component
1017 maxairspd = autocvar_sv_maxairspeed*max(1, maxspd_mod);
1018 // fix speedhacks :P
1019 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
1020 // add the unused velocity as up component
1023 // if(self.BUTTON_JUMP)
1024 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1026 // it is now normalized, so...
1027 float a_side, a_up, a_add, a_diff;
1028 a_side = autocvar_g_jetpack_acceleration_side;
1029 a_up = autocvar_g_jetpack_acceleration_up;
1030 a_add = autocvar_g_jetpack_antigravity * autocvar_sv_gravity;
1032 wishvel_x *= a_side;
1033 wishvel_y *= a_side;
1039 //////////////////////////////////////////////////////////////////////////////////////
1040 // finding the maximum over all vectors of above form
1041 // with wishvel having an absolute value of 1
1042 //////////////////////////////////////////////////////////////////////////////////////
1043 // we're finding the maximum over
1044 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1045 // for z in the range from -1 to 1
1046 //////////////////////////////////////////////////////////////////////////////////////
1047 // maximum is EITHER attained at the single extreme point:
1048 a_diff = a_side * a_side - a_up * a_up;
1051 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1052 if(f > -1 && f < 1) // can it be attained?
1054 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1055 //print("middle\n");
1058 // OR attained at z = 1:
1059 f = (a_up + a_add) * (a_up + a_add);
1065 // OR attained at z = -1:
1066 f = (a_up - a_add) * (a_up - a_add);
1070 //print("bottom\n");
1073 //////////////////////////////////////////////////////////////////////////////////////
1075 //print("best possible acceleration: ", ftos(best), "\n");
1078 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / autocvar_g_jetpack_maxspeed_side, 1);
1079 if(wishvel_z - autocvar_sv_gravity > 0)
1080 fz = bound(0, 1 - self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1082 fz = bound(0, 1 + self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1085 fvel = vlen(wishvel);
1088 wishvel_z = (wishvel_z - autocvar_sv_gravity) * fz + autocvar_sv_gravity;
1090 fvel = min(1, vlen(wishvel) / best);
1091 if(autocvar_g_jetpack_fuel && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1092 f = min(1, self.ammo_fuel / (autocvar_g_jetpack_fuel * frametime * fvel));
1096 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1098 if (f > 0 && wishvel != '0 0 0')
1100 self.velocity = self.velocity + wishvel * f * frametime;
1101 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1102 self.ammo_fuel -= autocvar_g_jetpack_fuel * frametime * fvel * f;
1103 self.flags &= ~FL_ONGROUND;
1104 self.items |= IT_USING_JETPACK;
1106 // jetpack also inhibits health regeneration, but only for 1 second
1107 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1110 else if (self.flags & FL_ONGROUND)
1112 // we get here if we ran out of ammo
1113 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
1114 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1117 makevectors(self.v_angle_y * '0 1 0');
1118 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1120 if(!(self.lastflags & FL_ONGROUND))
1122 if(autocvar_speedmeter)
1123 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1124 if(self.lastground < time - 0.3)
1125 self.velocity = self.velocity * (1 - autocvar_sv_friction_on_land);
1126 if(self.jumppadcount > 1)
1127 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1128 self.jumppadcount = 0;
1131 #ifdef LETS_TEST_FTEQCC
1132 if(self.velocity_x || self.velocity_y)
1150 if (f < autocvar_sv_stopspeed)
1151 f = 1 - frametime * (autocvar_sv_stopspeed / f) * autocvar_sv_friction;
1153 f = 1 - frametime * autocvar_sv_friction;
1155 self.velocity = self.velocity * f;
1157 self.velocity = '0 0 0';
1159 Mathematical analysis time!
1161 Our goal is to invert this mess.
1163 For the two cases we get:
1164 v = v0 * (1 - frametime * (autocvar_sv_stopspeed / v0) * autocvar_sv_friction)
1165 = v0 - frametime * autocvar_sv_stopspeed * autocvar_sv_friction
1166 v0 = v + frametime * autocvar_sv_stopspeed * autocvar_sv_friction
1168 v = v0 * (1 - frametime * autocvar_sv_friction)
1169 v0 = v / (1 - frametime * autocvar_sv_friction)
1171 These cases would be chosen ONLY if:
1172 v0 < autocvar_sv_stopspeed
1173 v + frametime * autocvar_sv_stopspeed * autocvar_sv_friction < autocvar_sv_stopspeed
1174 v < autocvar_sv_stopspeed * (1 - frametime * autocvar_sv_friction)
1176 v0 >= autocvar_sv_stopspeed
1177 v / (1 - frametime * autocvar_sv_friction) >= autocvar_sv_stopspeed
1178 v >= autocvar_sv_stopspeed * (1 - frametime * autocvar_sv_friction)
1183 wishdir = normalize(wishvel);
1184 wishspeed = vlen(wishvel);
1185 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1186 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1188 wishspeed = wishspeed * 0.5;
1189 if (time >= self.teleport_time)
1190 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1195 // we get here if we ran out of ammo
1196 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
1197 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1201 maxairspd = autocvar_sv_maxairspeed*maxspd_mod;
1202 airaccel = autocvar_sv_airaccelerate*maxspd_mod;
1206 maxairspd = autocvar_sv_maxairspeed;
1207 airaccel = autocvar_sv_airaccelerate;
1210 makevectors(self.v_angle_y * '0 1 0');
1211 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1213 wishdir = normalize(wishvel);
1214 wishspeed = wishspeed0 = vlen(wishvel);
1215 if (wishspeed0 > self.stat_sv_maxspeed*maxspd_mod)
1216 wishspeed0 = self.stat_sv_maxspeed*maxspd_mod;
1217 if (wishspeed > maxairspd)
1218 wishspeed = maxairspd;
1220 wishspeed = wishspeed * 0.5;
1221 if (time >= self.teleport_time)
1228 airaccelqw = self.stat_sv_airaccel_qw;
1229 accelerating = (self.velocity * wishdir > 0);
1230 wishspeed2 = wishspeed;
1233 if(autocvar_sv_airstopaccelerate)
1236 curdir = self.velocity;
1238 curdir = normalize(curdir);
1239 airaccel = airaccel + (autocvar_sv_airstopaccelerate*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1241 // note that for straight forward jumping:
1242 // step = accel * frametime * wishspeed0;
1243 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1245 // dv/dt = accel * maxspeed (when slow)
1246 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1247 // log dv/dt = logaccel + logmaxspeed (when slow)
1248 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1249 strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
1250 if(autocvar_sv_maxairstrafespeed)
1251 wishspeed = min(wishspeed, GeomLerp(autocvar_sv_maxairspeed*maxspd_mod, strafity, autocvar_sv_maxairstrafespeed*maxspd_mod));
1252 if(autocvar_sv_airstrafeaccelerate)
1253 airaccel = GeomLerp(airaccel, strafity, autocvar_sv_airstrafeaccelerate*maxspd_mod);
1254 if(self.stat_sv_airstrafeaccel_qw)
1255 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));
1258 if(autocvar_sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1259 PM_AirAccelerate(wishdir, wishspeed);
1261 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, autocvar_sv_airaccel_qw_stretchfactor, autocvar_sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw);
1263 if(autocvar_sv_aircontrol)
1264 CPM_PM_Aircontrol(wishdir, wishspeed2);
1268 if((g_cts || g_race) && !IS_OBSERVER(self)) {
1269 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1270 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1271 speedaward_holder = self.netname;
1272 speedaward_uid = self.crypto_idfp;
1273 speedaward_lastupdate = time;
1275 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1281 race_send_speedaward(MSG_ALL);
1282 speedaward_lastsent = speedaward_speed;
1283 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") {
1284 speedaward_alltimebest = speedaward_speed;
1285 speedaward_alltimebest_holder = speedaward_holder;
1286 speedaward_alltimebest_uid = speedaward_uid;
1287 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1288 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1289 race_send_speedaward_alltimebest(MSG_ALL);
1295 xyspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y);
1296 if(self.weapon == WEP_NEX && autocvar_g_balance_nex_charge && autocvar_g_balance_nex_charge_velocity_rate && xyspeed > autocvar_g_balance_nex_charge_minspeed)
1298 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1299 xyspeed = min(xyspeed, autocvar_g_balance_nex_charge_maxspeed);
1300 f = (xyspeed - autocvar_g_balance_nex_charge_minspeed) / (autocvar_g_balance_nex_charge_maxspeed - autocvar_g_balance_nex_charge_minspeed);
1301 // add the extra charge
1302 self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_velocity_rate * f * frametime);
1305 if(self.flags & FL_ONGROUND)
1306 self.lastground = time;
1308 // conveyors: then break velocity again
1309 if(self.conveyor.state)
1310 self.velocity += self.conveyor.movedir;
1312 self.lastflags = self.flags;
1313 self.lastclassname = self.classname;