11 .float spectatorspeed;
13 .float multijump_count;
14 .float multijump_ready;
15 .float prevjumpbutton;
21 When you press the jump key
24 void PlayerJump (void)
26 if(self.freezetag_frozen)
27 return; // no jumping in freezetag when frozen
33 if (autocvar_sv_doublejump)
35 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
36 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
40 // we MUST clip velocity here!
42 f = self.velocity * trace_plane_normal;
44 self.velocity -= f * trace_plane_normal;
48 mjumpheight = autocvar_sv_jumpvelocity;
49 if (self.waterlevel >= WATERLEVEL_SWIMMING)
51 self.velocity_z = self.stat_sv_maxspeed * 0.7;
55 if (autocvar_g_multijump)
57 if (self.prevjumpbutton == FALSE && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair
58 self.multijump_ready = TRUE; // this is necessary to check that we released the jump button and pressed it again
60 self.multijump_ready = FALSE;
63 if(!doublejump && self.multijump_ready && self.multijump_count < autocvar_g_multijump && self.velocity_z > autocvar_g_multijump_speed)
65 // doublejump = FALSE; // checked above in the if
66 if (autocvar_g_multijump)
68 if (autocvar_g_multijump_add == 0) // in this case we make the z velocity == jumpvelocity
70 if (self.velocity_z < mjumpheight)
81 if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
84 vector wishvel, wishdir;
87 vlen(vec2(self.velocity)), // current xy speed
88 vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
90 makevectors(self.v_angle_y * '0 1 0');
91 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
92 wishdir = normalize(wishvel);
94 self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
95 self.velocity_y = wishdir_y * curspeed;
96 // keep velocity_z unchanged!
98 if (autocvar_g_multijump > 0)
99 self.multijump_count += 1;
102 self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump
106 if (!(self.flags & FL_ONGROUND))
109 if(self.cvar_cl_movement_track_canjump)
110 if (!(self.flags & FL_JUMPRELEASED))
113 if(self.health <= g_bloodloss)
116 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
117 // velocity bounds. Final velocity is bound between (jumpheight *
118 // min + jumpheight) and (jumpheight * max + jumpheight);
120 if(autocvar_sv_jumpspeedcap_min != "")
124 minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min);
126 if (self.velocity_z < minjumpspeed)
127 mjumpheight += minjumpspeed - self.velocity_z;
130 if(autocvar_sv_jumpspeedcap_max != "")
132 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
133 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
135 if(!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && autocvar_sv_jumpspeedcap_max_disable_on_ramps))
139 maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max);
141 if (self.velocity_z > maxjumpspeed)
142 mjumpheight -= self.velocity_z - maxjumpspeed;
146 if(!(self.lastflags & FL_ONGROUND))
148 if(autocvar_speedmeter)
149 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
150 if(self.lastground < time - 0.3)
152 self.velocity_x *= (1 - autocvar_sv_friction_on_land);
153 self.velocity_y *= (1 - autocvar_sv_friction_on_land);
155 if(self.jumppadcount > 1)
156 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
157 self.jumppadcount = 0;
160 self.velocity_z = self.velocity_z + mjumpheight;
161 self.oldvelocity_z = self.velocity_z;
163 self.flags &~= FL_ONGROUND;
164 self.flags &~= FL_JUMPRELEASED;
166 animdecide_setaction(self, ANIMACTION_JUMP, TRUE);
169 PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
171 self.restart_jump = -1; // restart jump anim next time
172 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
174 void CheckWaterJump()
178 // check for a jump-out-of-water
179 makevectors (self.angles);
181 start_z = start_z + 8;
183 normalize(v_forward);
184 end = start + v_forward*24;
185 traceline (start, end, TRUE, self);
186 if (trace_fraction < 1)
188 start_z = start_z + self.maxs_z - 8;
189 end = start + v_forward*24;
190 self.movedir = trace_plane_normal * -50;
191 traceline (start, end, TRUE, self);
192 if (trace_fraction == 1)
193 { // open at eye level
194 self.flags |= FL_WATERJUMP;
195 self.velocity_z = 225;
196 self.flags &~= FL_JUMPRELEASED;
197 self.teleport_time = time + 2; // safety net
202 void CheckPlayerJump()
204 if(self.flags & FL_ONGROUND)
206 if (autocvar_g_multijump > 0)
207 self.multijump_count = 0;
209 self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller
212 if (self.BUTTON_JUMP)
215 self.flags |= FL_JUMPRELEASED;
217 if (self.waterlevel == WATERLEVEL_SWIMMING)
219 self.prevjumpbutton = self.BUTTON_JUMP;
222 float racecar_angle(float forward, float down)
224 float ret, angle_mult;
232 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
234 angle_mult = forward / (800 + forward);
237 return ret * angle_mult + 360 * (1 - angle_mult);
239 return ret * angle_mult;
242 void RaceCarPhysics()
244 // using this move type for "big rigs"
245 // the engine does not push the entity!
247 float accel, steer, f, myspeed, steerfactor;
248 vector angles_save, rigvel;
250 angles_save = self.angles;
251 accel = bound(-1, self.movement_x / self.stat_sv_maxspeed, 1);
252 steer = bound(-1, self.movement_y / self.stat_sv_maxspeed, 1);
254 if(g_bugrigs_reverse_speeding)
258 // back accel is DIGITAL
259 // to prevent speedhack
269 makevectors(self.angles); // new forward direction!
271 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
273 float upspeed, accelfactor;
275 myspeed = self.velocity * v_forward;
276 upspeed = self.velocity * v_up;
278 // responsiveness factor for steering and acceleration
279 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
280 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
282 if(myspeed < 0 && g_bugrigs_reverse_spinning)
283 steerfactor = -myspeed * g_bugrigs_steer;
285 steerfactor = -myspeed * f * g_bugrigs_steer;
287 if(myspeed < 0 && g_bugrigs_reverse_speeding)
288 accelfactor = g_bugrigs_accel;
290 accelfactor = f * g_bugrigs_accel;
291 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
297 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
301 if(!g_bugrigs_reverse_speeding)
302 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
309 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
313 if(g_bugrigs_reverse_stopping)
316 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
319 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
320 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
322 self.angles_y += steer * frametime * steerfactor; // apply steering
323 makevectors(self.angles); // new forward direction!
325 myspeed += accel * accelfactor * frametime;
327 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
331 myspeed = vlen(self.velocity);
333 // responsiveness factor for steering and acceleration
334 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
335 steerfactor = -myspeed * f;
336 self.angles_y += steer * frametime * steerfactor; // apply steering
338 rigvel = self.velocity;
339 makevectors(self.angles); // new forward direction!
342 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
343 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
344 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
345 //MAXIMA: solve(total_acceleration(v) = 0, v);
347 if(g_bugrigs_planar_movement)
349 vector rigvel_xy, neworigin, up;
352 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
353 rigvel_xy = vec2(rigvel);
355 if(g_bugrigs_planar_movement_car_jumping)
358 mt = MOVE_NOMONSTERS;
360 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
361 up = trace_endpos - self.origin;
363 // BUG RIGS: align the move to the surface instead of doing collision testing
365 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
368 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
370 if(trace_fraction < 0.5)
373 neworigin = self.origin;
376 neworigin = trace_endpos;
378 if(trace_fraction < 1)
380 // now set angles_x so that the car points parallel to the surface
381 self.angles = vectoangles(
382 '1 0 0' * v_forward_x * trace_plane_normal_z
384 '0 1 0' * v_forward_y * trace_plane_normal_z
386 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
388 self.flags |= FL_ONGROUND;
392 // now set angles_x so that the car points forward, but is tilted in velocity direction
393 self.flags &~= FL_ONGROUND;
396 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
397 self.movetype = MOVETYPE_NOCLIP;
401 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
402 self.velocity = rigvel;
403 self.movetype = MOVETYPE_FLY;
407 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
408 if(trace_fraction != 1)
410 self.angles = vectoangles2(
411 '1 0 0' * v_forward_x * trace_plane_normal_z
413 '0 1 0' * v_forward_y * trace_plane_normal_z
415 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
423 vel_local_x = v_forward * self.velocity;
424 vel_local_y = v_right * self.velocity;
425 vel_local_z = v_up * self.velocity;
427 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
428 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
432 vector vf1, vu1, smoothangles;
433 makevectors(self.angles);
434 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
439 makevectors(angles_save);
440 vf1 = vf1 + v_forward * (1 - f);
441 vu1 = vu1 + v_up * (1 - f);
442 smoothangles = vectoangles2(vf1, vu1);
443 self.angles_x = -smoothangles_x;
444 self.angles_z = smoothangles_z;
447 float IsMoveInDirection(vector mv, float angle) // key mix factor
449 if(mv_x == 0 && mv_y == 0)
450 return 0; // avoid division by zero
451 angle -= RAD2DEG * atan2(mv_y, mv_x);
452 angle = remainder(angle, 360) / 45;
457 return 1 - fabs(angle);
460 float GeomLerp(float a, float lerp, float b)
476 return a * pow(fabs(b / a), lerp);
479 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
481 float zspeed, xyspeed, dot, k;
484 // this doesn't play well with analog input
485 if(self.movement_x == 0 || self.movement_y != 0)
486 return; // can't control movement if not moving forward or backward
489 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
494 k *= bound(0, wishspeed / autocvar_sv_maxairspeed, 1);
496 zspeed = self.velocity_z;
498 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
500 dot = self.velocity * wishdir;
502 if(dot > 0) // we can't change direction while slowing down
504 k *= pow(dot, autocvar_sv_aircontrol_power)*frametime;
505 xyspeed = max(0, xyspeed - autocvar_sv_aircontrol_penalty * sqrt(max(0, 1 - dot*dot)) * k/32);
506 k *= autocvar_sv_aircontrol;
507 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
510 self.velocity = self.velocity * xyspeed;
511 self.velocity_z = zspeed;
514 float AdjustAirAccelQW(float accelqw, float factor)
516 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
519 // example config for alternate speed clamping:
520 // sv_airaccel_qw 0.8
521 // sv_airaccel_sideways_friction 0
522 // prvm_globalset server speedclamp_mode 1
524 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
532 float vel_xy_current;
533 float vel_xy_backward, vel_xy_forward;
536 if(stretchfactor > 0)
537 speedclamp = stretchfactor;
539 speedclamp = 1; // full clamping, no stretch
541 speedclamp = -1; // no clamping
546 if(autocvar_sv_gameplayfix_q2airaccelerate)
547 wishspeed0 = wishspeed;
549 vel_straight = self.velocity * wishdir;
550 vel_z = self.velocity_z;
551 vel_xy = vec2(self.velocity);
552 vel_perpend = vel_xy - vel_straight * wishdir;
554 step = accel * frametime * wishspeed0;
556 vel_xy_current = vlen(vel_xy);
558 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
559 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
560 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
561 if(vel_xy_backward < 0)
562 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
564 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
566 if(sidefric < 0 && (vel_perpend*vel_perpend))
567 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
570 f = max(0, 1 + frametime * wishspeed * sidefric);
571 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
572 // this cannot be > 1
574 vel_perpend = vel_perpend * max(0, f);
577 fminimum = sqrt(fminimum);
578 vel_perpend = vel_perpend * max(fminimum, f);
582 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
584 vel_xy = vel_straight * wishdir + vel_perpend;
588 float vel_xy_preclamp;
589 vel_xy_preclamp = vlen(vel_xy);
590 if(vel_xy_preclamp > 0) // prevent division by zero
592 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
593 if(vel_xy_current < vel_xy_preclamp)
594 vel_xy = vel_xy * (vel_xy_current / vel_xy_preclamp);
598 self.velocity = vel_xy + vel_z * '0 0 1';
601 void PM_AirAccelerate(vector wishdir, float wishspeed)
603 vector curvel, wishvel, acceldir, curdir;
604 float addspeed, accelspeed, curspeed, f;
610 curvel = self.velocity;
612 curspeed = vlen(curvel);
614 if(wishspeed > curspeed * 1.01)
616 wishspeed = min(wishspeed, curspeed + autocvar_sv_warsowbunny_airforwardaccel * self.stat_sv_maxspeed * frametime);
620 f = max(0, (autocvar_sv_warsowbunny_topspeed - curspeed) / (autocvar_sv_warsowbunny_topspeed - self.stat_sv_maxspeed));
621 wishspeed = max(curspeed, self.stat_sv_maxspeed) + autocvar_sv_warsowbunny_accel * f * self.stat_sv_maxspeed * frametime;
623 wishvel = wishdir * wishspeed;
624 acceldir = wishvel - curvel;
625 addspeed = vlen(acceldir);
626 acceldir = normalize(acceldir);
628 accelspeed = min(addspeed, autocvar_sv_warsowbunny_turnaccel * self.stat_sv_maxspeed * frametime);
630 if(autocvar_sv_warsowbunny_backtosideratio < 1)
632 curdir = normalize(curvel);
633 dot = acceldir * curdir;
635 acceldir = acceldir - (1 - autocvar_sv_warsowbunny_backtosideratio) * dot * curdir;
638 self.velocity += accelspeed * acceldir;
641 .vector movement_old;
644 .string lastclassname;
646 .float() PlayerPhysplug;
648 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
649 .float specialcommand_pos;
650 void SpecialCommand()
655 if(!CheatImpulse(99))
656 print("A hollow voice says \"Plugh\".\n");
660 float speedaward_speed;
661 string speedaward_holder;
662 string speedaward_uid;
663 void race_send_speedaward(float msg)
665 // send the best speed of the round
666 WriteByte(msg, SVC_TEMPENTITY);
667 WriteByte(msg, TE_CSQC_RACE);
668 WriteByte(msg, RACE_NET_SPEED_AWARD);
669 WriteInt24_t(msg, floor(speedaward_speed+0.5));
670 WriteString(msg, speedaward_holder);
673 float speedaward_alltimebest;
674 string speedaward_alltimebest_holder;
675 string speedaward_alltimebest_uid;
676 void race_send_speedaward_alltimebest(float msg)
678 // send the best speed
679 WriteByte(msg, SVC_TEMPENTITY);
680 WriteByte(msg, TE_CSQC_RACE);
681 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
682 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
683 WriteString(msg, speedaward_alltimebest_holder);
686 string GetMapname(void);
687 float speedaward_lastupdate;
688 float speedaward_lastsent;
689 void SV_PlayerPhysics()
691 vector wishvel, wishdir, v;
692 float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
695 float not_allowed_to_move;
698 WarpZone_PlayerPhysics_FixVAngle();
703 maxspd_mod *= autocvar_g_nexball_basketball_carrier_highspeed;
705 maxspd_mod *= autocvar_g_keepaway_ballcarrier_highspeed;
707 maxspd_mod *= autocvar_g_movement_highspeed;
709 // fix physics stats for g_movement_highspeed
710 // TODO maybe rather use maxairspeed? needs testing
711 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
712 if(autocvar_sv_airstrafeaccel_qw)
713 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
715 self.stat_sv_airstrafeaccel_qw = 0;
716 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
717 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
719 if(self.PlayerPhysplug)
720 if(self.PlayerPhysplug())
723 self.race_movetime_frac += frametime;
724 f = floor(self.race_movetime_frac);
725 self.race_movetime_frac -= f;
726 self.race_movetime_count += f;
727 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
731 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);
735 else if(buttons == 1)
737 else if(buttons == 2)
739 else if(buttons == 128)
741 else if(buttons == 256)
743 else if(buttons == 512)
745 else if(buttons == 1024)
750 if(c == substring(specialcommand, self.specialcommand_pos, 1))
752 self.specialcommand_pos += 1;
753 if(self.specialcommand_pos >= strlen(specialcommand))
755 self.specialcommand_pos = 0;
760 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
761 self.specialcommand_pos = 0;
765 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
766 self.parm_idlesince = time;
768 buttons_prev = self.buttons_old;
769 self.buttons_old = buttons;
770 self.movement_old = self.movement;
771 self.v_angle_old = self.v_angle;
773 if(time < self.nickspamtime)
774 if(self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
776 // slight annoyance for nick change scripts
777 self.movement = -1 * self.movement;
778 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
780 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!
782 self.angles_x = random() * 360;
783 self.angles_y = random() * 360;
784 // at least I'm not forcing retardedview by also assigning to angles_z
785 self.fixangle = TRUE;
789 if (self.punchangle != '0 0 0')
791 f = vlen(self.punchangle) - 10 * frametime;
793 self.punchangle = normalize(self.punchangle) * f;
795 self.punchangle = '0 0 0';
798 if (self.punchvector != '0 0 0')
800 f = vlen(self.punchvector) - 30 * frametime;
802 self.punchvector = normalize(self.punchvector) * f;
804 self.punchvector = '0 0 0';
807 if (IS_BOT_CLIENT(self))
809 if(playerdemo_read())
814 self.items &~= IT_USING_JETPACK;
818 if(self.race_penalty)
819 if(time > self.race_penalty)
820 self.race_penalty = 0;
822 not_allowed_to_move = 0;
823 if(self.race_penalty)
824 not_allowed_to_move = 1;
825 if(!autocvar_sv_ready_restart_after_countdown)
826 if(time < game_starttime)
827 not_allowed_to_move = 1;
829 if(not_allowed_to_move)
831 self.velocity = '0 0 0';
832 self.movetype = MOVETYPE_NONE;
833 self.disableclientprediction = 2;
835 else if(self.disableclientprediction == 2)
837 if(self.movetype == MOVETYPE_NONE)
838 self.movetype = MOVETYPE_WALK;
839 self.disableclientprediction = 0;
843 if (self.movetype == MOVETYPE_NONE)
846 // when we get here, disableclientprediction cannot be 2
847 self.disableclientprediction = 0;
848 if(time < self.ladder_time)
849 self.disableclientprediction = 1;
851 MUTATOR_CALLHOOK(PlayerPhysics);
853 if(self.player_blocked)
855 self.movement = '0 0 0';
856 self.disableclientprediction = 1;
863 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
866 // conveyors: first fix velocity
867 if(self.conveyor.state)
868 self.velocity -= self.conveyor.movedir;
870 if not(IS_PLAYER(self))
872 maxspd_mod = autocvar_sv_spectator_speed_multiplier;
873 if(!self.spectatorspeed)
874 self.spectatorspeed = maxspd_mod;
875 if(self.impulse && self.impulse <= 19 || self.impulse >= 200 && self.impulse <= 209 || self.impulse >= 220 && self.impulse <= 229)
877 if(self.lastclassname != "player")
879 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || self.impulse >= 200 && self.impulse <= 209)
880 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
881 else if(self.impulse == 11)
882 self.spectatorspeed = maxspd_mod;
883 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || self.impulse >= 220 && self.impulse <= 229)
884 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
885 else if(self.impulse >= 1 && self.impulse <= 9)
886 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
887 } // otherwise just clear
890 maxspd_mod = self.spectatorspeed;
893 spd = max(self.stat_sv_maxspeed, autocvar_sv_maxairspeed) * maxspd_mod * swampspd_mod;
894 if(self.speed != spd)
898 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
899 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
900 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
901 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
904 maxspd_mod *= swampspd_mod; // only one common speed modder please!
907 // if dead, behave differently
911 if (!self.fixangle && !g_bugrigs)
914 self.angles_y = self.v_angle_y;
918 if(self.flags & FL_ONGROUND)
919 if(IS_PLAYER(self)) // no fall sounds for observers thank you very much
924 if(self.waterlevel < WATERLEVEL_SWIMMING)
925 if(time >= self.ladder_time)
928 self.nextstep = time + 0.3 + random() * 0.1;
929 trace_dphitq3surfaceflags = 0;
930 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
931 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
933 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
934 GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
936 GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
947 if (self.flags & FL_WATERJUMP )
949 self.velocity_x = self.movedir_x;
950 self.velocity_y = self.movedir_y;
951 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
953 self.flags &~= FL_WATERJUMP;
954 self.teleport_time = 0;
957 else if (g_bugrigs && IS_PLAYER(self))
961 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
963 // noclipping or flying
964 self.flags &~= FL_ONGROUND;
966 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
967 makevectors(self.v_angle);
968 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
969 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
971 wishdir = normalize(wishvel);
972 wishspeed = vlen(wishvel);
973 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
974 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
975 if (time >= self.teleport_time)
976 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
978 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
981 self.flags &~= FL_ONGROUND;
983 makevectors(self.v_angle);
984 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
985 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
986 if (wishvel == '0 0 0')
987 wishvel = '0 0 -60'; // drift towards bottom
989 wishdir = normalize(wishvel);
990 wishspeed = vlen(wishvel);
991 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
992 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
993 wishspeed = wishspeed * 0.7;
996 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
998 // water acceleration
999 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1001 else if (time < self.ladder_time)
1003 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
1004 self.flags &~= FL_ONGROUND;
1007 g = autocvar_sv_gravity * frametime;
1010 if(autocvar_sv_gameplayfix_gravityunaffectedbyticrate)
1013 self.velocity_z += g;
1016 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
1017 makevectors(self.v_angle);
1018 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
1019 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
1020 self.velocity_z += g;
1021 if (self.ladder_entity.classname == "func_water")
1024 if (f > self.ladder_entity.speed)
1025 wishvel = wishvel * (self.ladder_entity.speed / f);
1027 self.watertype = self.ladder_entity.skin;
1028 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1029 if ((self.origin_z + self.view_ofs_z) < f)
1030 self.waterlevel = WATERLEVEL_SUBMERGED;
1031 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1032 self.waterlevel = WATERLEVEL_SWIMMING;
1033 else if ((self.origin_z + self.mins_z + 1) < f)
1034 self.waterlevel = WATERLEVEL_WETFEET;
1037 self.waterlevel = WATERLEVEL_NONE;
1038 self.watertype = CONTENT_EMPTY;
1042 wishdir = normalize(wishvel);
1043 wishspeed = vlen(wishvel);
1044 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1045 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1046 if (time >= self.teleport_time)
1048 // water acceleration
1049 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1052 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)
1054 //makevectors(self.v_angle_y * '0 1 0');
1055 makevectors(self.v_angle);
1056 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1057 // add remaining speed as Z component
1058 maxairspd = autocvar_sv_maxairspeed*max(1, maxspd_mod);
1059 // fix speedhacks :P
1060 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
1061 // add the unused velocity as up component
1064 // if(self.BUTTON_JUMP)
1065 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1067 // it is now normalized, so...
1068 float a_side, a_up, a_add, a_diff;
1069 a_side = autocvar_g_jetpack_acceleration_side;
1070 a_up = autocvar_g_jetpack_acceleration_up;
1071 a_add = autocvar_g_jetpack_antigravity * autocvar_sv_gravity;
1073 wishvel_x *= a_side;
1074 wishvel_y *= a_side;
1080 //////////////////////////////////////////////////////////////////////////////////////
1081 // finding the maximum over all vectors of above form
1082 // with wishvel having an absolute value of 1
1083 //////////////////////////////////////////////////////////////////////////////////////
1084 // we're finding the maximum over
1085 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1086 // for z in the range from -1 to 1
1087 //////////////////////////////////////////////////////////////////////////////////////
1088 // maximum is EITHER attained at the single extreme point:
1089 a_diff = a_side * a_side - a_up * a_up;
1092 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1093 if(f > -1 && f < 1) // can it be attained?
1095 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1096 //print("middle\n");
1099 // OR attained at z = 1:
1100 f = (a_up + a_add) * (a_up + a_add);
1106 // OR attained at z = -1:
1107 f = (a_up - a_add) * (a_up - a_add);
1111 //print("bottom\n");
1114 //////////////////////////////////////////////////////////////////////////////////////
1116 //print("best possible acceleration: ", ftos(best), "\n");
1119 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / autocvar_g_jetpack_maxspeed_side, 1);
1120 if(wishvel_z - autocvar_sv_gravity > 0)
1121 fz = bound(0, 1 - self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1123 fz = bound(0, 1 + self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1126 fvel = vlen(wishvel);
1129 wishvel_z = (wishvel_z - autocvar_sv_gravity) * fz + autocvar_sv_gravity;
1131 fvel = min(1, vlen(wishvel) / best);
1132 if(autocvar_g_jetpack_fuel && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1133 f = min(1, self.ammo_fuel / (autocvar_g_jetpack_fuel * frametime * fvel));
1137 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1139 if (f > 0 && wishvel != '0 0 0')
1141 self.velocity = self.velocity + wishvel * f * frametime;
1142 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1143 self.ammo_fuel -= autocvar_g_jetpack_fuel * frametime * fvel * f;
1144 self.flags &~= FL_ONGROUND;
1145 self.items |= IT_USING_JETPACK;
1147 // jetpack also inhibits health regeneration, but only for 1 second
1148 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1151 else if (self.flags & FL_ONGROUND)
1153 // we get here if we ran out of ammo
1154 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
1155 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1158 makevectors(self.v_angle_y * '0 1 0');
1159 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1161 if(!(self.lastflags & FL_ONGROUND))
1163 if(autocvar_speedmeter)
1164 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1165 if(self.lastground < time - 0.3)
1166 self.velocity = self.velocity * (1 - autocvar_sv_friction_on_land);
1167 if(self.jumppadcount > 1)
1168 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1169 self.jumppadcount = 0;
1172 #ifdef LETS_TEST_FTEQCC
1173 if(self.velocity_x || self.velocity_y)
1191 if (f < autocvar_sv_stopspeed)
1192 f = 1 - frametime * (autocvar_sv_stopspeed / f) * autocvar_sv_friction;
1194 f = 1 - frametime * autocvar_sv_friction;
1196 self.velocity = self.velocity * f;
1198 self.velocity = '0 0 0';
1200 Mathematical analysis time!
1202 Our goal is to invert this mess.
1204 For the two cases we get:
1205 v = v0 * (1 - frametime * (autocvar_sv_stopspeed / v0) * autocvar_sv_friction)
1206 = v0 - frametime * autocvar_sv_stopspeed * autocvar_sv_friction
1207 v0 = v + frametime * autocvar_sv_stopspeed * autocvar_sv_friction
1209 v = v0 * (1 - frametime * autocvar_sv_friction)
1210 v0 = v / (1 - frametime * autocvar_sv_friction)
1212 These cases would be chosen ONLY if:
1213 v0 < autocvar_sv_stopspeed
1214 v + frametime * autocvar_sv_stopspeed * autocvar_sv_friction < autocvar_sv_stopspeed
1215 v < autocvar_sv_stopspeed * (1 - frametime * autocvar_sv_friction)
1217 v0 >= autocvar_sv_stopspeed
1218 v / (1 - frametime * autocvar_sv_friction) >= autocvar_sv_stopspeed
1219 v >= autocvar_sv_stopspeed * (1 - frametime * autocvar_sv_friction)
1224 wishdir = normalize(wishvel);
1225 wishspeed = vlen(wishvel);
1226 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1227 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1229 wishspeed = wishspeed * 0.5;
1230 if (time >= self.teleport_time)
1231 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1236 // we get here if we ran out of ammo
1237 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
1238 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1242 maxairspd = autocvar_sv_maxairspeed*maxspd_mod;
1243 airaccel = autocvar_sv_airaccelerate*maxspd_mod;
1247 maxairspd = autocvar_sv_maxairspeed;
1248 airaccel = autocvar_sv_airaccelerate;
1251 makevectors(self.v_angle_y * '0 1 0');
1252 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1254 wishdir = normalize(wishvel);
1255 wishspeed = wishspeed0 = vlen(wishvel);
1256 if (wishspeed0 > self.stat_sv_maxspeed*maxspd_mod)
1257 wishspeed0 = self.stat_sv_maxspeed*maxspd_mod;
1258 if (wishspeed > maxairspd)
1259 wishspeed = maxairspd;
1261 wishspeed = wishspeed * 0.5;
1262 if (time >= self.teleport_time)
1269 airaccelqw = self.stat_sv_airaccel_qw;
1270 accelerating = (self.velocity * wishdir > 0);
1271 wishspeed2 = wishspeed;
1274 if(autocvar_sv_airstopaccelerate)
1277 curdir = self.velocity;
1279 curdir = normalize(curdir);
1280 airaccel = airaccel + (autocvar_sv_airstopaccelerate*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1282 // note that for straight forward jumping:
1283 // step = accel * frametime * wishspeed0;
1284 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1286 // dv/dt = accel * maxspeed (when slow)
1287 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1288 // log dv/dt = logaccel + logmaxspeed (when slow)
1289 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1290 strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
1291 if(autocvar_sv_maxairstrafespeed)
1292 wishspeed = min(wishspeed, GeomLerp(autocvar_sv_maxairspeed*maxspd_mod, strafity, autocvar_sv_maxairstrafespeed*maxspd_mod));
1293 if(autocvar_sv_airstrafeaccelerate)
1294 airaccel = GeomLerp(airaccel, strafity, autocvar_sv_airstrafeaccelerate*maxspd_mod);
1295 if(self.stat_sv_airstrafeaccel_qw)
1296 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));
1299 if(autocvar_sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1300 PM_AirAccelerate(wishdir, wishspeed);
1302 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, autocvar_sv_airaccel_qw_stretchfactor, autocvar_sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw);
1304 if(autocvar_sv_aircontrol)
1305 CPM_PM_Aircontrol(wishdir, wishspeed2);
1309 if((g_cts || g_race) && !IS_OBSERVER(self)) {
1310 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1311 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1312 speedaward_holder = self.netname;
1313 speedaward_uid = self.crypto_idfp;
1314 speedaward_lastupdate = time;
1316 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1322 race_send_speedaward(MSG_ALL);
1323 speedaward_lastsent = speedaward_speed;
1324 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") {
1325 speedaward_alltimebest = speedaward_speed;
1326 speedaward_alltimebest_holder = speedaward_holder;
1327 speedaward_alltimebest_uid = speedaward_uid;
1328 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1329 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1330 race_send_speedaward_alltimebest(MSG_ALL);
1337 xyspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y);
1338 if(self.weapon == WEP_NEX && WEP_CVAR(nex, charge) && WEP_CVAR(nex, charge_velocity_rate) && xyspeed > WEP_CVAR(nex, charge_minspeed))
1340 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1341 xyspeed = min(xyspeed, WEP_CVAR(nex, charge_maxspeed));
1342 f = (xyspeed - WEP_CVAR(nex, charge_minspeed)) / (WEP_CVAR(nex, charge_maxspeed) - WEP_CVAR(nex, charge_minspeed));
1343 // add the extra charge
1344 self.nex_charge = min(1, self.nex_charge + WEP_CVAR(nex, charge_velocity_rate) * f * frametime);
1347 if(self.flags & FL_ONGROUND)
1348 self.lastground = time;
1350 // conveyors: then break velocity again
1351 if(self.conveyor.state)
1352 self.velocity += self.conveyor.movedir;
1354 self.lastflags = self.flags;
1355 self.lastclassname = self.classname;