11 .float spectatorspeed;
17 When you press the jump key
20 void PlayerJump (void)
22 float doublejump = FALSE;
24 player_multijump = doublejump;
25 if(MUTATOR_CALLHOOK(PlayerJump))
28 doublejump = player_multijump;
32 if (autocvar_sv_doublejump)
34 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
35 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
39 // we MUST clip velocity here!
41 f = self.velocity * trace_plane_normal;
43 self.velocity -= f * trace_plane_normal;
47 mjumpheight = autocvar_sv_jumpvelocity;
48 if (self.waterlevel >= WATERLEVEL_SWIMMING)
50 self.velocity_z = self.stat_sv_maxspeed * 0.7;
55 if (!(self.flags & FL_ONGROUND))
58 if(self.cvar_cl_movement_track_canjump)
59 if (!(self.flags & FL_JUMPRELEASED))
62 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
63 // velocity bounds. Final velocity is bound between (jumpheight *
64 // min + jumpheight) and (jumpheight * max + jumpheight);
66 if(autocvar_sv_jumpspeedcap_min != "")
70 minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min);
72 if (self.velocity_z < minjumpspeed)
73 mjumpheight += minjumpspeed - self.velocity_z;
76 if(autocvar_sv_jumpspeedcap_max != "")
78 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
79 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
81 if(!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && autocvar_sv_jumpspeedcap_max_disable_on_ramps))
85 maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max);
87 if (self.velocity_z > maxjumpspeed)
88 mjumpheight -= self.velocity_z - maxjumpspeed;
92 if(!(self.lastflags & FL_ONGROUND))
94 if(autocvar_speedmeter)
95 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
96 if(self.lastground < time - 0.3)
98 self.velocity_x *= (1 - autocvar_sv_friction_on_land);
99 self.velocity_y *= (1 - autocvar_sv_friction_on_land);
101 if(self.jumppadcount > 1)
102 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
103 self.jumppadcount = 0;
106 self.velocity_z = self.velocity_z + mjumpheight;
107 self.oldvelocity_z = self.velocity_z;
109 self.flags &= ~FL_ONGROUND;
110 self.flags &= ~FL_JUMPRELEASED;
112 animdecide_setaction(self, ANIMACTION_JUMP, TRUE);
114 if(autocvar_g_jump_grunt)
115 PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
117 self.restart_jump = -1; // restart jump anim next time
118 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
120 void CheckWaterJump()
124 // check for a jump-out-of-water
125 makevectors (self.angles);
127 start_z = start_z + 8;
129 normalize(v_forward);
130 end = start + v_forward*24;
131 traceline (start, end, TRUE, self);
132 if (trace_fraction < 1)
134 start_z = start_z + self.maxs_z - 8;
135 end = start + v_forward*24;
136 self.movedir = trace_plane_normal * -50;
137 traceline (start, end, TRUE, self);
138 if (trace_fraction == 1)
139 { // open at eye level
140 self.flags |= FL_WATERJUMP;
141 self.velocity_z = 225;
142 self.flags &= ~FL_JUMPRELEASED;
143 self.teleport_time = time + 2; // safety net
148 void CheckPlayerJump()
150 if (self.BUTTON_JUMP)
153 self.flags |= FL_JUMPRELEASED;
155 if (self.waterlevel == WATERLEVEL_SWIMMING)
159 float racecar_angle(float forward, float down)
161 float ret, angle_mult;
169 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
171 angle_mult = forward / (800 + forward);
174 return ret * angle_mult + 360 * (1 - angle_mult);
176 return ret * angle_mult;
179 void RaceCarPhysics()
181 // using this move type for "big rigs"
182 // the engine does not push the entity!
184 float accel, steer, f, myspeed, steerfactor;
185 vector angles_save, rigvel;
187 angles_save = self.angles;
188 accel = bound(-1, self.movement_x / self.stat_sv_maxspeed, 1);
189 steer = bound(-1, self.movement_y / self.stat_sv_maxspeed, 1);
191 if(g_bugrigs_reverse_speeding)
195 // back accel is DIGITAL
196 // to prevent speedhack
206 makevectors(self.angles); // new forward direction!
208 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
210 float upspeed, accelfactor;
212 myspeed = self.velocity * v_forward;
213 upspeed = self.velocity * v_up;
215 // responsiveness factor for steering and acceleration
216 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
217 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
219 if(myspeed < 0 && g_bugrigs_reverse_spinning)
220 steerfactor = -myspeed * g_bugrigs_steer;
222 steerfactor = -myspeed * f * g_bugrigs_steer;
224 if(myspeed < 0 && g_bugrigs_reverse_speeding)
225 accelfactor = g_bugrigs_accel;
227 accelfactor = f * g_bugrigs_accel;
228 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
234 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
238 if(!g_bugrigs_reverse_speeding)
239 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
246 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
250 if(g_bugrigs_reverse_stopping)
253 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
256 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
257 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
259 self.angles_y += steer * frametime * steerfactor; // apply steering
260 makevectors(self.angles); // new forward direction!
262 myspeed += accel * accelfactor * frametime;
264 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
268 myspeed = vlen(self.velocity);
270 // responsiveness factor for steering and acceleration
271 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
272 steerfactor = -myspeed * f;
273 self.angles_y += steer * frametime * steerfactor; // apply steering
275 rigvel = self.velocity;
276 makevectors(self.angles); // new forward direction!
279 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
280 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
281 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
282 //MAXIMA: solve(total_acceleration(v) = 0, v);
284 if(g_bugrigs_planar_movement)
286 vector rigvel_xy, neworigin, up;
289 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
290 rigvel_xy = vec2(rigvel);
292 if(g_bugrigs_planar_movement_car_jumping)
295 mt = MOVE_NOMONSTERS;
297 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
298 up = trace_endpos - self.origin;
300 // BUG RIGS: align the move to the surface instead of doing collision testing
302 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
305 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
307 if(trace_fraction < 0.5)
310 neworigin = self.origin;
313 neworigin = trace_endpos;
315 if(trace_fraction < 1)
317 // now set angles_x so that the car points parallel to the surface
318 self.angles = vectoangles(
319 '1 0 0' * v_forward_x * trace_plane_normal_z
321 '0 1 0' * v_forward_y * trace_plane_normal_z
323 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
325 self.flags |= FL_ONGROUND;
329 // now set angles_x so that the car points forward, but is tilted in velocity direction
330 self.flags &= ~FL_ONGROUND;
333 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
334 self.movetype = MOVETYPE_NOCLIP;
338 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
339 self.velocity = rigvel;
340 self.movetype = MOVETYPE_FLY;
344 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
345 if(trace_fraction != 1)
347 self.angles = vectoangles2(
348 '1 0 0' * v_forward_x * trace_plane_normal_z
350 '0 1 0' * v_forward_y * trace_plane_normal_z
352 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
360 vel_local_x = v_forward * self.velocity;
361 vel_local_y = v_right * self.velocity;
362 vel_local_z = v_up * self.velocity;
364 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
365 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
369 vector vf1, vu1, smoothangles;
370 makevectors(self.angles);
371 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
376 makevectors(angles_save);
377 vf1 = vf1 + v_forward * (1 - f);
378 vu1 = vu1 + v_up * (1 - f);
379 smoothangles = vectoangles2(vf1, vu1);
380 self.angles_x = -smoothangles_x;
381 self.angles_z = smoothangles_z;
384 float IsMoveInDirection(vector mv, float angle) // key mix factor
386 if(mv_x == 0 && mv_y == 0)
387 return 0; // avoid division by zero
388 angle -= RAD2DEG * atan2(mv_y, mv_x);
389 angle = remainder(angle, 360) / 45;
394 return 1 - fabs(angle);
397 float GeomLerp(float a, float lerp, float b)
413 return a * pow(fabs(b / a), lerp);
416 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
418 float zspeed, xyspeed, dot, k;
421 // this doesn't play well with analog input
422 if(self.movement_x == 0 || self.movement_y != 0)
423 return; // can't control movement if not moving forward or backward
426 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
431 k *= bound(0, wishspeed / autocvar_sv_maxairspeed, 1);
433 zspeed = self.velocity_z;
435 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
437 dot = self.velocity * wishdir;
439 if(dot > 0) // we can't change direction while slowing down
441 k *= pow(dot, autocvar_sv_aircontrol_power)*frametime;
442 xyspeed = max(0, xyspeed - autocvar_sv_aircontrol_penalty * sqrt(max(0, 1 - dot*dot)) * k/32);
443 k *= autocvar_sv_aircontrol;
444 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
447 self.velocity = self.velocity * xyspeed;
448 self.velocity_z = zspeed;
451 float AdjustAirAccelQW(float accelqw, float factor)
453 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
456 // example config for alternate speed clamping:
457 // sv_airaccel_qw 0.8
458 // sv_airaccel_sideways_friction 0
459 // prvm_globalset server speedclamp_mode 1
461 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
469 float vel_xy_current;
470 float vel_xy_backward, vel_xy_forward;
473 if(stretchfactor > 0)
474 speedclamp = stretchfactor;
476 speedclamp = 1; // full clamping, no stretch
478 speedclamp = -1; // no clamping
483 if(autocvar_sv_gameplayfix_q2airaccelerate)
484 wishspeed0 = wishspeed;
486 vel_straight = self.velocity * wishdir;
487 vel_z = self.velocity_z;
488 vel_xy = vec2(self.velocity);
489 vel_perpend = vel_xy - vel_straight * wishdir;
491 step = accel * frametime * wishspeed0;
493 vel_xy_current = vlen(vel_xy);
495 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
496 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
497 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
498 if(vel_xy_backward < 0)
499 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
501 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
503 if(sidefric < 0 && (vel_perpend*vel_perpend))
504 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
507 f = max(0, 1 + frametime * wishspeed * sidefric);
508 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
509 // this cannot be > 1
511 vel_perpend = vel_perpend * max(0, f);
514 fminimum = sqrt(fminimum);
515 vel_perpend = vel_perpend * max(fminimum, f);
519 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
521 vel_xy = vel_straight * wishdir + vel_perpend;
525 float vel_xy_preclamp;
526 vel_xy_preclamp = vlen(vel_xy);
527 if(vel_xy_preclamp > 0) // prevent division by zero
529 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
530 if(vel_xy_current < vel_xy_preclamp)
531 vel_xy = vel_xy * (vel_xy_current / vel_xy_preclamp);
535 self.velocity = vel_xy + vel_z * '0 0 1';
538 void PM_AirAccelerate(vector wishdir, float wishspeed)
540 vector curvel, wishvel, acceldir, curdir;
541 float addspeed, accelspeed, curspeed, f;
547 curvel = self.velocity;
549 curspeed = vlen(curvel);
551 if(wishspeed > curspeed * 1.01)
553 wishspeed = min(wishspeed, curspeed + autocvar_sv_warsowbunny_airforwardaccel * self.stat_sv_maxspeed * frametime);
557 f = max(0, (autocvar_sv_warsowbunny_topspeed - curspeed) / (autocvar_sv_warsowbunny_topspeed - self.stat_sv_maxspeed));
558 wishspeed = max(curspeed, self.stat_sv_maxspeed) + autocvar_sv_warsowbunny_accel * f * self.stat_sv_maxspeed * frametime;
560 wishvel = wishdir * wishspeed;
561 acceldir = wishvel - curvel;
562 addspeed = vlen(acceldir);
563 acceldir = normalize(acceldir);
565 accelspeed = min(addspeed, autocvar_sv_warsowbunny_turnaccel * self.stat_sv_maxspeed * frametime);
567 if(autocvar_sv_warsowbunny_backtosideratio < 1)
569 curdir = normalize(curvel);
570 dot = acceldir * curdir;
572 acceldir = acceldir - (1 - autocvar_sv_warsowbunny_backtosideratio) * dot * curdir;
575 self.velocity += accelspeed * acceldir;
578 .vector movement_old;
581 .string lastclassname;
583 .float() PlayerPhysplug;
585 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
586 .float specialcommand_pos;
587 void SpecialCommand()
592 if(!CheatImpulse(99))
593 print("A hollow voice says \"Plugh\".\n");
597 float speedaward_speed;
598 string speedaward_holder;
599 string speedaward_uid;
600 void race_send_speedaward(float msg)
602 // send the best speed of the round
603 WriteByte(msg, SVC_TEMPENTITY);
604 WriteByte(msg, TE_CSQC_RACE);
605 WriteByte(msg, RACE_NET_SPEED_AWARD);
606 WriteInt24_t(msg, floor(speedaward_speed+0.5));
607 WriteString(msg, speedaward_holder);
610 float speedaward_alltimebest;
611 string speedaward_alltimebest_holder;
612 string speedaward_alltimebest_uid;
613 void race_send_speedaward_alltimebest(float msg)
615 // send the best speed
616 WriteByte(msg, SVC_TEMPENTITY);
617 WriteByte(msg, TE_CSQC_RACE);
618 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
619 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
620 WriteString(msg, speedaward_alltimebest_holder);
623 string GetMapname(void);
624 float speedaward_lastupdate;
625 float speedaward_lastsent;
626 void SV_PlayerPhysics()
628 vector wishvel, wishdir, v;
629 float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
632 float not_allowed_to_move;
635 WarpZone_PlayerPhysics_FixVAngle();
640 maxspd_mod *= autocvar_g_nexball_basketball_carrier_highspeed;
642 maxspd_mod *= autocvar_g_keepaway_ballcarrier_highspeed;
644 maxspd_mod *= autocvar_g_movement_highspeed;
646 // fix physics stats for g_movement_highspeed
647 // TODO maybe rather use maxairspeed? needs testing
648 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
649 if(autocvar_sv_airstrafeaccel_qw)
650 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
652 self.stat_sv_airstrafeaccel_qw = 0;
653 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
654 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
656 if(self.PlayerPhysplug)
657 if(self.PlayerPhysplug())
660 self.race_movetime_frac += frametime;
661 f = floor(self.race_movetime_frac);
662 self.race_movetime_frac -= f;
663 self.race_movetime_count += f;
664 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
668 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);
672 else if(buttons == 1)
674 else if(buttons == 2)
676 else if(buttons == 128)
678 else if(buttons == 256)
680 else if(buttons == 512)
682 else if(buttons == 1024)
687 if(c == substring(specialcommand, self.specialcommand_pos, 1))
689 self.specialcommand_pos += 1;
690 if(self.specialcommand_pos >= strlen(specialcommand))
692 self.specialcommand_pos = 0;
697 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
698 self.specialcommand_pos = 0;
702 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
703 self.parm_idlesince = time;
705 buttons_prev = self.buttons_old;
706 self.buttons_old = buttons;
707 self.movement_old = self.movement;
708 self.v_angle_old = self.v_angle;
710 if(time < self.nickspamtime)
711 if(self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
713 // slight annoyance for nick change scripts
714 self.movement = -1 * self.movement;
715 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
717 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!
719 self.angles_x = random() * 360;
720 self.angles_y = random() * 360;
721 // at least I'm not forcing retardedview by also assigning to angles_z
722 self.fixangle = TRUE;
726 if (self.punchangle != '0 0 0')
728 f = vlen(self.punchangle) - 10 * frametime;
730 self.punchangle = normalize(self.punchangle) * f;
732 self.punchangle = '0 0 0';
735 if (self.punchvector != '0 0 0')
737 f = vlen(self.punchvector) - 30 * frametime;
739 self.punchvector = normalize(self.punchvector) * f;
741 self.punchvector = '0 0 0';
744 if (IS_BOT_CLIENT(self))
746 if(playerdemo_read())
751 self.items &= ~IT_USING_JETPACK;
755 if(self.race_penalty)
756 if(time > self.race_penalty)
757 self.race_penalty = 0;
759 not_allowed_to_move = 0;
760 if(self.race_penalty)
761 not_allowed_to_move = 1;
762 if(!autocvar_sv_ready_restart_after_countdown)
763 if(time < game_starttime)
764 not_allowed_to_move = 1;
766 if(not_allowed_to_move)
768 self.velocity = '0 0 0';
769 self.movetype = MOVETYPE_NONE;
770 self.disableclientprediction = 2;
772 else if(self.disableclientprediction == 2)
774 if(self.movetype == MOVETYPE_NONE)
775 self.movetype = MOVETYPE_WALK;
776 self.disableclientprediction = 0;
780 if (self.movetype == MOVETYPE_NONE)
783 // when we get here, disableclientprediction cannot be 2
784 self.disableclientprediction = 0;
785 if(time < self.ladder_time)
786 self.disableclientprediction = 1;
788 MUTATOR_CALLHOOK(PlayerPhysics);
790 if(self.player_blocked)
792 self.movement = '0 0 0';
793 self.disableclientprediction = 1;
800 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
803 // conveyors: first fix velocity
804 if(self.conveyor.state)
805 self.velocity -= self.conveyor.movedir;
807 if (!IS_PLAYER(self))
809 maxspd_mod = autocvar_sv_spectator_speed_multiplier;
810 if(!self.spectatorspeed)
811 self.spectatorspeed = maxspd_mod;
812 if(self.impulse && self.impulse <= 19 || (self.impulse >= 200 && self.impulse <= 209) || (self.impulse >= 220 && self.impulse <= 229))
814 if(self.lastclassname != "player")
816 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209))
817 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
818 else if(self.impulse == 11)
819 self.spectatorspeed = maxspd_mod;
820 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229))
821 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
822 else if(self.impulse >= 1 && self.impulse <= 9)
823 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
824 } // otherwise just clear
827 maxspd_mod = self.spectatorspeed;
830 spd = max(self.stat_sv_maxspeed, autocvar_sv_maxairspeed) * maxspd_mod * swampspd_mod;
831 if(self.speed != spd)
835 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
836 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
837 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
838 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
841 maxspd_mod *= swampspd_mod; // only one common speed modder please!
844 // if dead, behave differently
848 if (!self.fixangle && !g_bugrigs)
851 self.angles_y = self.v_angle_y;
855 if(self.flags & FL_ONGROUND)
856 if(IS_PLAYER(self)) // no fall sounds for observers thank you very much
861 if(self.waterlevel < WATERLEVEL_SWIMMING)
862 if(time >= self.ladder_time)
865 self.nextstep = time + 0.3 + random() * 0.1;
866 trace_dphitq3surfaceflags = 0;
867 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
868 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
870 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
871 GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
873 GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
884 if (self.flags & FL_WATERJUMP )
886 self.velocity_x = self.movedir_x;
887 self.velocity_y = self.movedir_y;
888 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
890 self.flags &= ~FL_WATERJUMP;
891 self.teleport_time = 0;
894 else if (g_bugrigs && IS_PLAYER(self))
898 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
900 // noclipping or flying
901 self.flags &= ~FL_ONGROUND;
903 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
904 makevectors(self.v_angle);
905 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
906 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
908 wishdir = normalize(wishvel);
909 wishspeed = vlen(wishvel);
910 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
911 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
912 if (time >= self.teleport_time)
913 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
915 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
918 self.flags &= ~FL_ONGROUND;
920 makevectors(self.v_angle);
921 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
922 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
923 if (wishvel == '0 0 0')
924 wishvel = '0 0 -60'; // drift towards bottom
926 wishdir = normalize(wishvel);
927 wishspeed = vlen(wishvel);
928 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
929 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
930 wishspeed = wishspeed * 0.7;
933 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
935 // water acceleration
936 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
938 else if (time < self.ladder_time)
940 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
941 self.flags &= ~FL_ONGROUND;
944 g = autocvar_sv_gravity * frametime;
947 if(autocvar_sv_gameplayfix_gravityunaffectedbyticrate)
950 self.velocity_z += g;
953 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
954 makevectors(self.v_angle);
955 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
956 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
957 self.velocity_z += g;
958 if (self.ladder_entity.classname == "func_water")
961 if (f > self.ladder_entity.speed)
962 wishvel = wishvel * (self.ladder_entity.speed / f);
964 self.watertype = self.ladder_entity.skin;
965 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
966 if ((self.origin_z + self.view_ofs_z) < f)
967 self.waterlevel = WATERLEVEL_SUBMERGED;
968 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
969 self.waterlevel = WATERLEVEL_SWIMMING;
970 else if ((self.origin_z + self.mins_z + 1) < f)
971 self.waterlevel = WATERLEVEL_WETFEET;
974 self.waterlevel = WATERLEVEL_NONE;
975 self.watertype = CONTENT_EMPTY;
979 wishdir = normalize(wishvel);
980 wishspeed = vlen(wishvel);
981 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
982 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
983 if (time >= self.teleport_time)
985 // water acceleration
986 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
989 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)
991 //makevectors(self.v_angle_y * '0 1 0');
992 makevectors(self.v_angle);
993 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
994 // add remaining speed as Z component
995 maxairspd = autocvar_sv_maxairspeed*max(1, maxspd_mod);
997 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
998 // add the unused velocity as up component
1001 // if(self.BUTTON_JUMP)
1002 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1004 // it is now normalized, so...
1005 float a_side, a_up, a_add, a_diff;
1006 a_side = autocvar_g_jetpack_acceleration_side;
1007 a_up = autocvar_g_jetpack_acceleration_up;
1008 a_add = autocvar_g_jetpack_antigravity * autocvar_sv_gravity;
1010 wishvel_x *= a_side;
1011 wishvel_y *= a_side;
1017 //////////////////////////////////////////////////////////////////////////////////////
1018 // finding the maximum over all vectors of above form
1019 // with wishvel having an absolute value of 1
1020 //////////////////////////////////////////////////////////////////////////////////////
1021 // we're finding the maximum over
1022 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1023 // for z in the range from -1 to 1
1024 //////////////////////////////////////////////////////////////////////////////////////
1025 // maximum is EITHER attained at the single extreme point:
1026 a_diff = a_side * a_side - a_up * a_up;
1029 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1030 if(f > -1 && f < 1) // can it be attained?
1032 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1033 //print("middle\n");
1036 // OR attained at z = 1:
1037 f = (a_up + a_add) * (a_up + a_add);
1043 // OR attained at z = -1:
1044 f = (a_up - a_add) * (a_up - a_add);
1048 //print("bottom\n");
1051 //////////////////////////////////////////////////////////////////////////////////////
1053 //print("best possible acceleration: ", ftos(best), "\n");
1056 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / autocvar_g_jetpack_maxspeed_side, 1);
1057 if(wishvel_z - autocvar_sv_gravity > 0)
1058 fz = bound(0, 1 - self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1060 fz = bound(0, 1 + self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1063 fvel = vlen(wishvel);
1066 wishvel_z = (wishvel_z - autocvar_sv_gravity) * fz + autocvar_sv_gravity;
1068 fvel = min(1, vlen(wishvel) / best);
1069 if(autocvar_g_jetpack_fuel && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1070 f = min(1, self.ammo_fuel / (autocvar_g_jetpack_fuel * frametime * fvel));
1074 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1076 if (f > 0 && wishvel != '0 0 0')
1078 self.velocity = self.velocity + wishvel * f * frametime;
1079 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
1080 self.ammo_fuel -= autocvar_g_jetpack_fuel * frametime * fvel * f;
1081 self.flags &= ~FL_ONGROUND;
1082 self.items |= IT_USING_JETPACK;
1084 // jetpack also inhibits health regeneration, but only for 1 second
1085 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1088 else if (self.flags & FL_ONGROUND)
1090 // we get here if we ran out of ammo
1091 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
1092 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1095 makevectors(self.v_angle_y * '0 1 0');
1096 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1098 if(!(self.lastflags & FL_ONGROUND))
1100 if(autocvar_speedmeter)
1101 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1102 if(self.lastground < time - 0.3)
1103 self.velocity = self.velocity * (1 - autocvar_sv_friction_on_land);
1104 if(self.jumppadcount > 1)
1105 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1106 self.jumppadcount = 0;
1109 #ifdef LETS_TEST_FTEQCC
1110 if(self.velocity_x || self.velocity_y)
1128 if (f < autocvar_sv_stopspeed)
1129 f = 1 - frametime * (autocvar_sv_stopspeed / f) * autocvar_sv_friction;
1131 f = 1 - frametime * autocvar_sv_friction;
1133 self.velocity = self.velocity * f;
1135 self.velocity = '0 0 0';
1137 Mathematical analysis time!
1139 Our goal is to invert this mess.
1141 For the two cases we get:
1142 v = v0 * (1 - frametime * (autocvar_sv_stopspeed / v0) * autocvar_sv_friction)
1143 = v0 - frametime * autocvar_sv_stopspeed * autocvar_sv_friction
1144 v0 = v + frametime * autocvar_sv_stopspeed * autocvar_sv_friction
1146 v = v0 * (1 - frametime * autocvar_sv_friction)
1147 v0 = v / (1 - frametime * autocvar_sv_friction)
1149 These cases would be chosen ONLY if:
1150 v0 < autocvar_sv_stopspeed
1151 v + frametime * autocvar_sv_stopspeed * autocvar_sv_friction < autocvar_sv_stopspeed
1152 v < autocvar_sv_stopspeed * (1 - frametime * autocvar_sv_friction)
1154 v0 >= autocvar_sv_stopspeed
1155 v / (1 - frametime * autocvar_sv_friction) >= autocvar_sv_stopspeed
1156 v >= autocvar_sv_stopspeed * (1 - frametime * autocvar_sv_friction)
1161 wishdir = normalize(wishvel);
1162 wishspeed = vlen(wishvel);
1163 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1164 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1166 wishspeed = wishspeed * 0.5;
1167 if (time >= self.teleport_time)
1168 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1173 // we get here if we ran out of ammo
1174 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
1175 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1179 maxairspd = autocvar_sv_maxairspeed*maxspd_mod;
1180 airaccel = autocvar_sv_airaccelerate*maxspd_mod;
1184 maxairspd = autocvar_sv_maxairspeed;
1185 airaccel = autocvar_sv_airaccelerate;
1188 makevectors(self.v_angle_y * '0 1 0');
1189 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1191 wishdir = normalize(wishvel);
1192 wishspeed = wishspeed0 = vlen(wishvel);
1193 if (wishspeed0 > self.stat_sv_maxspeed*maxspd_mod)
1194 wishspeed0 = self.stat_sv_maxspeed*maxspd_mod;
1195 if (wishspeed > maxairspd)
1196 wishspeed = maxairspd;
1198 wishspeed = wishspeed * 0.5;
1199 if (time >= self.teleport_time)
1206 airaccelqw = self.stat_sv_airaccel_qw;
1207 accelerating = (self.velocity * wishdir > 0);
1208 wishspeed2 = wishspeed;
1211 if(autocvar_sv_airstopaccelerate)
1214 curdir = self.velocity;
1216 curdir = normalize(curdir);
1217 airaccel = airaccel + (autocvar_sv_airstopaccelerate*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1219 // note that for straight forward jumping:
1220 // step = accel * frametime * wishspeed0;
1221 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1223 // dv/dt = accel * maxspeed (when slow)
1224 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1225 // log dv/dt = logaccel + logmaxspeed (when slow)
1226 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1227 strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
1228 if(autocvar_sv_maxairstrafespeed)
1229 wishspeed = min(wishspeed, GeomLerp(autocvar_sv_maxairspeed*maxspd_mod, strafity, autocvar_sv_maxairstrafespeed*maxspd_mod));
1230 if(autocvar_sv_airstrafeaccelerate)
1231 airaccel = GeomLerp(airaccel, strafity, autocvar_sv_airstrafeaccelerate*maxspd_mod);
1232 if(self.stat_sv_airstrafeaccel_qw)
1233 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));
1236 if(autocvar_sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1237 PM_AirAccelerate(wishdir, wishspeed);
1239 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, autocvar_sv_airaccel_qw_stretchfactor, autocvar_sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw);
1241 if(autocvar_sv_aircontrol)
1242 CPM_PM_Aircontrol(wishdir, wishspeed2);
1246 if((g_cts || g_race) && !IS_OBSERVER(self)) {
1247 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1248 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1249 speedaward_holder = self.netname;
1250 speedaward_uid = self.crypto_idfp;
1251 speedaward_lastupdate = time;
1253 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1259 race_send_speedaward(MSG_ALL);
1260 speedaward_lastsent = speedaward_speed;
1261 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") {
1262 speedaward_alltimebest = speedaward_speed;
1263 speedaward_alltimebest_holder = speedaward_holder;
1264 speedaward_alltimebest_uid = speedaward_uid;
1265 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1266 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1267 race_send_speedaward_alltimebest(MSG_ALL);
1273 xyspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y);
1274 if(self.weapon == WEP_NEX && autocvar_g_balance_nex_charge && autocvar_g_balance_nex_charge_velocity_rate && xyspeed > autocvar_g_balance_nex_charge_minspeed)
1276 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1277 xyspeed = min(xyspeed, autocvar_g_balance_nex_charge_maxspeed);
1278 f = (xyspeed - autocvar_g_balance_nex_charge_minspeed) / (autocvar_g_balance_nex_charge_maxspeed - autocvar_g_balance_nex_charge_minspeed);
1279 // add the extra charge
1280 self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_velocity_rate * f * frametime);
1283 if(self.flags & FL_ONGROUND)
1284 self.lastground = time;
1286 // conveyors: then break velocity again
1287 if(self.conveyor.state)
1288 self.velocity += self.conveyor.movedir;
1290 self.lastflags = self.flags;
1291 self.lastclassname = self.classname;