11 .float spectatorspeed;
13 .float multijump_count;
14 .float multijump_ready;
15 .float prevjumpbutton;
21 When you press the jump key
24 void PlayerJump (void)
26 if(self.freezetag_frozen)
27 return; // no jumping in freezetag when frozen
33 if (autocvar_sv_doublejump)
35 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
36 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
40 // we MUST clip velocity here!
42 f = self.velocity * trace_plane_normal;
44 self.velocity -= f * trace_plane_normal;
48 mjumpheight = autocvar_sv_jumpvelocity;
49 if (self.waterlevel >= WATERLEVEL_SWIMMING)
51 if (self.watertype == CONTENT_WATER)
52 self.velocity_z = 200;
53 else if (self.watertype == CONTENT_SLIME)
61 if (autocvar_g_multijump)
63 if (self.prevjumpbutton == FALSE && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair
64 self.multijump_ready = TRUE; // this is necessary to check that we released the jump button and pressed it again
66 self.multijump_ready = FALSE;
69 if(!doublejump && self.multijump_ready && self.multijump_count < autocvar_g_multijump && self.velocity_z > autocvar_g_multijump_speed)
71 // doublejump = FALSE; // checked above in the if
72 if (autocvar_g_multijump)
74 if (autocvar_g_multijump_add == 0) // in this case we make the z velocity == jumpvelocity
76 if (self.velocity_z < mjumpheight)
87 if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
90 vector wishvel, wishdir;
93 vlen(vec2(self.velocity)), // current xy speed
94 vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
96 makevectors(self.v_angle_y * '0 1 0');
97 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
98 wishdir = normalize(wishvel);
100 self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
101 self.velocity_y = wishdir_y * curspeed;
102 // keep velocity_z unchanged!
104 if (autocvar_g_multijump > 0)
105 self.multijump_count += 1;
108 self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump
112 if (!(self.flags & FL_ONGROUND))
115 if(self.cvar_cl_movement_track_canjump)
116 if (!(self.flags & FL_JUMPRELEASED))
119 if(self.health <= g_bloodloss)
122 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
123 // velocity bounds. Final velocity is bound between (jumpheight *
124 // min + jumpheight) and (jumpheight * max + jumpheight);
126 if(autocvar_sv_jumpspeedcap_min != "")
130 minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min);
132 if (self.velocity_z < minjumpspeed)
133 mjumpheight += minjumpspeed - self.velocity_z;
136 if(autocvar_sv_jumpspeedcap_max != "")
138 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
139 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
141 if(!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && autocvar_sv_jumpspeedcap_max_disable_on_ramps))
145 maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max);
147 if (self.velocity_z > maxjumpspeed)
148 mjumpheight -= self.velocity_z - maxjumpspeed;
152 if(!(self.lastflags & FL_ONGROUND))
154 if(autocvar_speedmeter)
155 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
156 if(self.lastground < time - 0.3)
158 self.velocity_x *= (1 - autocvar_sv_friction_on_land);
159 self.velocity_y *= (1 - autocvar_sv_friction_on_land);
161 if(self.jumppadcount > 1)
162 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
163 self.jumppadcount = 0;
166 self.velocity_z = self.velocity_z + mjumpheight;
167 self.oldvelocity_z = self.velocity_z;
169 self.flags &~= FL_ONGROUND;
170 self.flags &~= FL_JUMPRELEASED;
173 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
175 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
178 PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
180 self.restart_jump = -1; // restart jump anim next time
181 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
183 void CheckWaterJump()
185 local vector start, end;
187 // check for a jump-out-of-water
188 makevectors (self.angles);
190 start_z = start_z + 8;
192 normalize(v_forward);
193 end = start + v_forward*24;
194 traceline (start, end, TRUE, self);
195 if (trace_fraction < 1)
197 start_z = start_z + self.maxs_z - 8;
198 end = start + v_forward*24;
199 self.movedir = trace_plane_normal * -50;
200 traceline (start, end, TRUE, self);
201 if (trace_fraction == 1)
202 { // open at eye level
203 self.flags |= FL_WATERJUMP;
204 self.velocity_z = 225;
205 self.flags &~= FL_JUMPRELEASED;
206 self.teleport_time = time + 2; // safety net
211 void CheckPlayerJump()
213 if(self.flags & FL_ONGROUND)
215 if (autocvar_g_multijump > 0)
216 self.multijump_count = 0;
218 self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller
221 if (self.BUTTON_JUMP)
224 self.flags |= FL_JUMPRELEASED;
226 if (self.waterlevel == WATERLEVEL_SWIMMING)
228 self.prevjumpbutton = self.BUTTON_JUMP;
231 float racecar_angle(float forward, float down)
233 float ret, angle_mult;
241 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
243 angle_mult = forward / (800 + forward);
246 return ret * angle_mult + 360 * (1 - angle_mult);
248 return ret * angle_mult;
251 void RaceCarPhysics()
253 // using this move type for "big rigs"
254 // the engine does not push the entity!
256 float accel, steer, f, myspeed, steerfactor;
257 vector angles_save, rigvel;
259 angles_save = self.angles;
260 accel = bound(-1, self.movement_x / self.stat_sv_maxspeed, 1);
261 steer = bound(-1, self.movement_y / self.stat_sv_maxspeed, 1);
263 if(g_bugrigs_reverse_speeding)
267 // back accel is DIGITAL
268 // to prevent speedhack
278 makevectors(self.angles); // new forward direction!
280 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
282 float upspeed, accelfactor;
284 myspeed = self.velocity * v_forward;
285 upspeed = self.velocity * v_up;
287 // responsiveness factor for steering and acceleration
288 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
289 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
291 if(myspeed < 0 && g_bugrigs_reverse_spinning)
292 steerfactor = -myspeed * g_bugrigs_steer;
294 steerfactor = -myspeed * f * g_bugrigs_steer;
296 if(myspeed < 0 && g_bugrigs_reverse_speeding)
297 accelfactor = g_bugrigs_accel;
299 accelfactor = f * g_bugrigs_accel;
300 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
306 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
310 if(!g_bugrigs_reverse_speeding)
311 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
318 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
322 if(g_bugrigs_reverse_stopping)
325 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
328 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
329 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
331 self.angles_y += steer * frametime * steerfactor; // apply steering
332 makevectors(self.angles); // new forward direction!
334 myspeed += accel * accelfactor * frametime;
336 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
340 myspeed = vlen(self.velocity);
342 // responsiveness factor for steering and acceleration
343 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
344 steerfactor = -myspeed * f;
345 self.angles_y += steer * frametime * steerfactor; // apply steering
347 rigvel = self.velocity;
348 makevectors(self.angles); // new forward direction!
351 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
352 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
353 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
354 //MAXIMA: solve(total_acceleration(v) = 0, v);
356 if(g_bugrigs_planar_movement)
358 vector rigvel_xy, neworigin, up;
361 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
362 rigvel_xy = vec2(rigvel);
364 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
367 mt = MOVE_NOMONSTERS;
369 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
370 up = trace_endpos - self.origin;
372 // BUG RIGS: align the move to the surface instead of doing collision testing
374 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
377 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
379 if(trace_fraction < 0.5)
382 neworigin = self.origin;
385 neworigin = trace_endpos;
387 if(trace_fraction < 1)
389 // now set angles_x so that the car points parallel to the surface
390 self.angles = vectoangles(
391 '1 0 0' * v_forward_x * trace_plane_normal_z
393 '0 1 0' * v_forward_y * trace_plane_normal_z
395 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
397 self.flags |= FL_ONGROUND;
401 // now set angles_x so that the car points forward, but is tilted in velocity direction
402 self.flags &~= FL_ONGROUND;
405 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
406 self.movetype = MOVETYPE_NOCLIP;
410 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
411 self.velocity = rigvel;
412 self.movetype = MOVETYPE_FLY;
416 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
417 if(trace_fraction != 1)
419 self.angles = vectoangles2(
420 '1 0 0' * v_forward_x * trace_plane_normal_z
422 '0 1 0' * v_forward_y * trace_plane_normal_z
424 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
432 vel_local_x = v_forward * self.velocity;
433 vel_local_y = v_right * self.velocity;
434 vel_local_z = v_up * self.velocity;
436 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
437 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
441 vector vf1, vu1, smoothangles;
442 makevectors(self.angles);
443 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
448 makevectors(angles_save);
449 vf1 = vf1 + v_forward * (1 - f);
450 vu1 = vu1 + v_up * (1 - f);
451 smoothangles = vectoangles2(vf1, vu1);
452 self.angles_x = -smoothangles_x;
453 self.angles_z = smoothangles_z;
456 float IsMoveInDirection(vector mv, float angle) // key mix factor
458 if(mv_x == 0 && mv_y == 0)
459 return 0; // avoid division by zero
460 angle -= RAD2DEG * atan2(mv_y, mv_x);
461 angle = remainder(angle, 360) / 45;
466 return 1 - fabs(angle);
469 float GeomLerp(float a, float lerp, float b)
485 return a * pow(fabs(b / a), lerp);
488 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
490 float zspeed, xyspeed, dot, k;
493 // this doesn't play well with analog input
494 if(self.movement_x == 0 || self.movement_y != 0)
495 return; // can't control movement if not moving forward or backward
498 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
503 k *= bound(0, wishspeed / autocvar_sv_maxairspeed, 1);
505 zspeed = self.velocity_z;
507 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
509 dot = self.velocity * wishdir;
511 if(dot > 0) // we can't change direction while slowing down
513 k *= pow(dot, autocvar_sv_aircontrol_power)*frametime;
514 xyspeed = max(0, xyspeed - autocvar_sv_aircontrol_penalty * sqrt(max(0, 1 - dot*dot)) * k/32);
515 k *= autocvar_sv_aircontrol;
516 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
519 self.velocity = self.velocity * xyspeed;
520 self.velocity_z = zspeed;
523 float AdjustAirAccelQW(float accelqw, float factor)
525 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
528 // example config for alternate speed clamping:
529 // sv_airaccel_qw 0.8
530 // sv_airaccel_sideways_friction 0
531 // prvm_globalset server speedclamp_mode 1
533 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
541 float vel_xy_current;
542 float vel_xy_backward, vel_xy_forward;
545 if(stretchfactor > 0)
546 speedclamp = stretchfactor;
548 speedclamp = 1; // full clamping, no stretch
550 speedclamp = -1; // no clamping
555 if(autocvar_sv_gameplayfix_q2airaccelerate)
556 wishspeed0 = wishspeed;
558 vel_straight = self.velocity * wishdir;
559 vel_z = self.velocity_z;
560 vel_xy = vec2(self.velocity);
561 vel_perpend = vel_xy - vel_straight * wishdir;
563 step = accel * frametime * wishspeed0;
565 vel_xy_current = vlen(vel_xy);
567 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
568 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
569 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
570 if(vel_xy_backward < 0)
571 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
573 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
575 if(sidefric < 0 && (vel_perpend*vel_perpend))
576 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
579 f = max(0, 1 + frametime * wishspeed * sidefric);
580 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
581 // this cannot be > 1
583 vel_perpend = vel_perpend * max(0, f);
586 fminimum = sqrt(fminimum);
587 vel_perpend = vel_perpend * max(fminimum, f);
591 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
593 vel_xy = vel_straight * wishdir + vel_perpend;
597 float vel_xy_preclamp;
598 vel_xy_preclamp = vlen(vel_xy);
599 if(vel_xy_preclamp > 0) // prevent division by zero
601 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
602 if(vel_xy_current < vel_xy_preclamp)
603 vel_xy = vel_xy * (vel_xy_current / vel_xy_preclamp);
607 self.velocity = vel_xy + vel_z * '0 0 1';
610 void PM_AirAccelerate(vector wishdir, float wishspeed)
612 vector curvel, wishvel, acceldir, curdir;
613 float addspeed, accelspeed, curspeed, f;
619 curvel = self.velocity;
621 curspeed = vlen(curvel);
623 if(wishspeed > curspeed * 1.01)
625 wishspeed = min(wishspeed, curspeed + autocvar_sv_warsowbunny_airforwardaccel * self.stat_sv_maxspeed * frametime);
629 f = max(0, (autocvar_sv_warsowbunny_topspeed - curspeed) / (autocvar_sv_warsowbunny_topspeed - self.stat_sv_maxspeed));
630 wishspeed = max(curspeed, self.stat_sv_maxspeed) + autocvar_sv_warsowbunny_accel * f * self.stat_sv_maxspeed * frametime;
632 wishvel = wishdir * wishspeed;
633 acceldir = wishvel - curvel;
634 addspeed = vlen(acceldir);
635 acceldir = normalize(acceldir);
637 accelspeed = min(addspeed, autocvar_sv_warsowbunny_turnaccel * self.stat_sv_maxspeed * frametime);
639 if(autocvar_sv_warsowbunny_backtosideratio < 1)
641 curdir = normalize(curvel);
642 dot = acceldir * curdir;
644 acceldir = acceldir - (1 - autocvar_sv_warsowbunny_backtosideratio) * dot * curdir;
647 self.velocity += accelspeed * acceldir;
650 .vector movement_old;
653 .string lastclassname;
655 .float() PlayerPhysplug;
657 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
658 .float specialcommand_pos;
659 void SpecialCommand()
664 if(!CheatImpulse(99))
665 print("A hollow voice says \"Plugh\".\n");
669 float speedaward_speed;
670 string speedaward_holder;
671 string speedaward_uid;
672 void race_send_speedaward(float msg)
674 // send the best speed of the round
675 WriteByte(msg, SVC_TEMPENTITY);
676 WriteByte(msg, TE_CSQC_RACE);
677 WriteByte(msg, RACE_NET_SPEED_AWARD);
678 WriteInt24_t(msg, floor(speedaward_speed+0.5));
679 WriteString(msg, speedaward_holder);
682 float speedaward_alltimebest;
683 string speedaward_alltimebest_holder;
684 string speedaward_alltimebest_uid;
685 void race_send_speedaward_alltimebest(float msg)
687 // send the best speed
688 WriteByte(msg, SVC_TEMPENTITY);
689 WriteByte(msg, TE_CSQC_RACE);
690 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
691 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
692 WriteString(msg, speedaward_alltimebest_holder);
695 string GetMapname(void);
696 float speedaward_lastupdate;
697 float speedaward_lastsent;
698 void SV_PlayerPhysics()
700 local vector wishvel, wishdir, v;
701 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
704 float not_allowed_to_move;
707 WarpZone_PlayerPhysics_FixVAngle();
710 if(g_minstagib && (self.items & IT_INVINCIBLE))
711 maxspd_mod *= autocvar_g_minstagib_speed_highspeed;
714 maxspd_mod *= autocvar_g_nexball_basketball_carrier_highspeed;
716 maxspd_mod *= autocvar_g_keepaway_ballcarrier_highspeed;
720 if(self.runes & RUNE_SPEED)
722 if(self.runes & CURSE_SLOW)
723 maxspd_mod *= autocvar_g_balance_rune_speed_combo_highspeed;
725 maxspd_mod *= autocvar_g_balance_rune_speed_highspeed;
727 else if(self.runes & CURSE_SLOW)
729 maxspd_mod *= autocvar_g_balance_curse_slow_highspeed;
732 maxspd_mod *= autocvar_g_movement_highspeed;
734 // fix physics stats for g_movement_highspeed
735 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
736 if(autocvar_sv_airstrafeaccel_qw)
737 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
739 self.stat_sv_airstrafeaccel_qw = 0;
740 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
741 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
743 if(self.PlayerPhysplug)
744 if(self.PlayerPhysplug())
747 self.race_movetime_frac += frametime;
748 f = floor(self.race_movetime_frac);
749 self.race_movetime_frac -= f;
750 self.race_movetime_count += f;
751 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
755 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);
759 else if(buttons == 1)
761 else if(buttons == 2)
763 else if(buttons == 128)
765 else if(buttons == 256)
767 else if(buttons == 512)
769 else if(buttons == 1024)
774 if(c == substring(specialcommand, self.specialcommand_pos, 1))
776 self.specialcommand_pos += 1;
777 if(self.specialcommand_pos >= strlen(specialcommand))
779 self.specialcommand_pos = 0;
784 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
785 self.specialcommand_pos = 0;
787 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
789 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
790 self.parm_idlesince = time;
792 buttons_prev = self.buttons_old;
793 self.buttons_old = buttons;
794 self.movement_old = self.movement;
795 self.v_angle_old = self.v_angle;
797 if(time < self.nickspamtime)
798 if(self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
800 // slight annoyance for nick change scripts
801 self.movement = -1 * self.movement;
802 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
804 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!
806 self.angles_x = random() * 360;
807 self.angles_y = random() * 360;
808 // at least I'm not forcing retardedview by also assigning to angles_z
809 self.fixangle = TRUE;
813 if (self.punchangle != '0 0 0')
815 f = vlen(self.punchangle) - 10 * frametime;
817 self.punchangle = normalize(self.punchangle) * f;
819 self.punchangle = '0 0 0';
822 if (self.punchvector != '0 0 0')
824 f = vlen(self.punchvector) - 30 * frametime;
826 self.punchvector = normalize(self.punchvector) * f;
828 self.punchvector = '0 0 0';
831 if (clienttype(self) == CLIENTTYPE_BOT)
833 if(playerdemo_read())
838 self.items &~= IT_USING_JETPACK;
840 if(self.classname == "player")
842 if(self.race_penalty)
843 if(time > self.race_penalty)
844 self.race_penalty = 0;
846 not_allowed_to_move = 0;
847 if(self.race_penalty)
848 not_allowed_to_move = 1;
849 if(!autocvar_sv_ready_restart_after_countdown)
850 if(time < game_starttime)
851 not_allowed_to_move = 1;
853 if(not_allowed_to_move)
855 self.velocity = '0 0 0';
856 self.movetype = MOVETYPE_NONE;
857 self.disableclientprediction = 2;
859 else if(self.disableclientprediction == 2)
861 if(self.movetype == MOVETYPE_NONE)
862 self.movetype = MOVETYPE_WALK;
863 self.disableclientprediction = 0;
867 if (self.movetype == MOVETYPE_NONE)
870 // when we get here, disableclientprediction cannot be 2
871 self.disableclientprediction = 0;
872 if(time < self.ladder_time)
873 self.disableclientprediction = 1;
875 MUTATOR_CALLHOOK(PlayerPhysics);
881 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
884 if(self.classname != "player")
886 maxspd_mod = autocvar_sv_spectator_speed_multiplier;
887 if(!self.spectatorspeed)
888 self.spectatorspeed = maxspd_mod;
889 if(self.impulse && self.impulse <= 19)
891 if(self.lastclassname != "player")
893 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
894 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
895 else if(self.impulse == 11)
896 self.spectatorspeed = maxspd_mod;
897 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
898 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
899 else if(self.impulse >= 1 && self.impulse <= 9)
900 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
901 } // otherwise just clear
904 maxspd_mod = self.spectatorspeed;
907 spd = max(self.stat_sv_maxspeed, autocvar_sv_maxairspeed) * maxspd_mod * swampspd_mod;
908 if(self.speed != spd)
912 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
913 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
914 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
915 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
918 maxspd_mod *= swampspd_mod; // only one common speed modder please!
921 // if dead, behave differently
925 if (!self.fixangle && !g_bugrigs)
928 self.angles_y = self.v_angle_y;
932 if(self.flags & FL_ONGROUND)
933 if(self.classname == "player") // no fall sounds for observers thank you very much
938 if(self.waterlevel < WATERLEVEL_SWIMMING)
939 if(time >= self.ladder_time)
942 self.nextstep = time + 0.3 + random() * 0.1;
943 trace_dphitq3surfaceflags = 0;
944 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
945 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
947 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
948 GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
950 GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
958 if(self.classname == "player")
961 if (self.flags & FL_WATERJUMP )
963 self.velocity_x = self.movedir_x;
964 self.velocity_y = self.movedir_y;
965 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
967 self.flags &~= FL_WATERJUMP;
968 self.teleport_time = 0;
971 else if (g_bugrigs && self.classname == "player")
975 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
977 // noclipping or flying
978 self.flags &~= FL_ONGROUND;
980 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
981 makevectors(self.v_angle);
982 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
983 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
985 wishdir = normalize(wishvel);
986 wishspeed = vlen(wishvel);
987 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
988 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
989 if (time >= self.teleport_time)
990 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
992 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
995 self.flags &~= FL_ONGROUND;
997 makevectors(self.v_angle);
998 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
999 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
1000 if (wishvel == '0 0 0')
1001 wishvel = '0 0 -60'; // drift towards bottom
1003 wishdir = normalize(wishvel);
1004 wishspeed = vlen(wishvel);
1005 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1006 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1007 wishspeed = wishspeed * 0.7;
1010 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
1012 // water acceleration
1013 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1015 else if (time < self.ladder_time)
1017 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
1018 self.flags &~= FL_ONGROUND;
1021 g = autocvar_sv_gravity * frametime;
1024 if(autocvar_sv_gameplayfix_gravityunaffectedbyticrate)
1027 self.velocity_z += g;
1030 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
1031 makevectors(self.v_angle);
1032 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
1033 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
1034 self.velocity_z += g;
1035 if (self.ladder_entity.classname == "func_water")
1038 if (f > self.ladder_entity.speed)
1039 wishvel = wishvel * (self.ladder_entity.speed / f);
1041 self.watertype = self.ladder_entity.skin;
1042 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1043 if ((self.origin_z + self.view_ofs_z) < f)
1044 self.waterlevel = WATERLEVEL_SUBMERGED;
1045 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1046 self.waterlevel = WATERLEVEL_SWIMMING;
1047 else if ((self.origin_z + self.mins_z + 1) < f)
1048 self.waterlevel = WATERLEVEL_WETFEET;
1051 self.waterlevel = WATERLEVEL_NONE;
1052 self.watertype = CONTENT_EMPTY;
1056 wishdir = normalize(wishvel);
1057 wishspeed = vlen(wishvel);
1058 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1059 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1060 if (time >= self.teleport_time)
1062 // water acceleration
1063 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1066 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!autocvar_g_jetpack_fuel || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
1068 //makevectors(self.v_angle_y * '0 1 0');
1069 makevectors(self.v_angle);
1070 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1071 // add remaining speed as Z component
1072 maxairspd = autocvar_sv_maxairspeed*max(1, maxspd_mod);
1073 // fix speedhacks :P
1074 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
1075 // add the unused velocity as up component
1078 // if(self.BUTTON_JUMP)
1079 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1081 // it is now normalized, so...
1082 float a_side, a_up, a_add, a_diff;
1083 a_side = autocvar_g_jetpack_acceleration_side;
1084 a_up = autocvar_g_jetpack_acceleration_up;
1085 a_add = autocvar_g_jetpack_antigravity * autocvar_sv_gravity;
1087 wishvel_x *= a_side;
1088 wishvel_y *= a_side;
1094 //////////////////////////////////////////////////////////////////////////////////////
1095 // finding the maximum over all vectors of above form
1096 // with wishvel having an absolute value of 1
1097 //////////////////////////////////////////////////////////////////////////////////////
1098 // we're finding the maximum over
1099 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1100 // for z in the range from -1 to 1
1101 //////////////////////////////////////////////////////////////////////////////////////
1102 // maximum is EITHER attained at the single extreme point:
1103 a_diff = a_side * a_side - a_up * a_up;
1106 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1107 if(f > -1 && f < 1) // can it be attained?
1109 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1110 //print("middle\n");
1113 // OR attained at z = 1:
1114 f = (a_up + a_add) * (a_up + a_add);
1120 // OR attained at z = -1:
1121 f = (a_up - a_add) * (a_up - a_add);
1125 //print("bottom\n");
1128 //////////////////////////////////////////////////////////////////////////////////////
1130 //print("best possible acceleration: ", ftos(best), "\n");
1133 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / autocvar_g_jetpack_maxspeed_side, 1);
1134 if(wishvel_z - autocvar_sv_gravity > 0)
1135 fz = bound(0, 1 - self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1137 fz = bound(0, 1 + self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1140 fvel = vlen(wishvel);
1143 wishvel_z = (wishvel_z - autocvar_sv_gravity) * fz + autocvar_sv_gravity;
1145 fvel = min(1, vlen(wishvel) / best);
1146 if(autocvar_g_jetpack_fuel && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1147 f = min(1, self.ammo_fuel / (autocvar_g_jetpack_fuel * frametime * fvel));
1151 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1153 if (f > 0 && wishvel != '0 0 0')
1155 self.velocity = self.velocity + wishvel * f * frametime;
1156 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1157 self.ammo_fuel -= autocvar_g_jetpack_fuel * frametime * fvel * f;
1158 self.flags &~= FL_ONGROUND;
1159 self.items |= IT_USING_JETPACK;
1161 // jetpack also inhibits health regeneration, but only for 1 second
1162 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1165 else if (self.flags & FL_ONGROUND)
1167 // we get here if we ran out of ammo
1168 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1169 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1172 makevectors(self.v_angle_y * '0 1 0');
1173 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1175 if(!(self.lastflags & FL_ONGROUND))
1177 if(autocvar_speedmeter)
1178 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1179 if(self.lastground < time - 0.3)
1180 self.velocity = self.velocity * (1 - autocvar_sv_friction_on_land);
1181 if(self.jumppadcount > 1)
1182 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1183 self.jumppadcount = 0;
1186 #ifdef LETS_TEST_FTEQCC
1187 if(self.velocity_x || self.velocity_y)
1205 if (f < autocvar_sv_stopspeed)
1206 f = 1 - frametime * (autocvar_sv_stopspeed / f) * autocvar_sv_friction;
1208 f = 1 - frametime * autocvar_sv_friction;
1210 self.velocity = self.velocity * f;
1212 self.velocity = '0 0 0';
1216 wishdir = normalize(wishvel);
1217 wishspeed = vlen(wishvel);
1218 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1219 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1221 wishspeed = wishspeed * 0.5;
1222 if (time >= self.teleport_time)
1223 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1228 // we get here if we ran out of ammo
1229 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1230 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1234 maxairspd = autocvar_sv_maxairspeed*maxspd_mod;
1235 airaccel = autocvar_sv_airaccelerate*maxspd_mod;
1239 maxairspd = autocvar_sv_maxairspeed;
1240 airaccel = autocvar_sv_airaccelerate;
1243 makevectors(self.v_angle_y * '0 1 0');
1244 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1246 wishdir = normalize(wishvel);
1247 wishspeed = wishspeed0 = vlen(wishvel);
1248 if (wishspeed0 > self.stat_sv_maxspeed*maxspd_mod)
1249 wishspeed0 = self.stat_sv_maxspeed*maxspd_mod;
1250 if (wishspeed > maxairspd)
1251 wishspeed = maxairspd;
1253 wishspeed = wishspeed * 0.5;
1254 if (time >= self.teleport_time)
1261 airaccelqw = self.stat_sv_airaccel_qw;
1262 accelerating = (self.velocity * wishdir > 0);
1263 wishspeed2 = wishspeed;
1266 if(autocvar_sv_airstopaccelerate)
1269 curdir = self.velocity;
1271 curdir = normalize(curdir);
1272 airaccel = airaccel + (autocvar_sv_airstopaccelerate*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1274 // note that for straight forward jumping:
1275 // step = accel * frametime * wishspeed0;
1276 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1278 // dv/dt = accel * maxspeed (when slow)
1279 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1280 // log dv/dt = logaccel + logmaxspeed (when slow)
1281 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1282 strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
1283 if(autocvar_sv_maxairstrafespeed)
1284 wishspeed = min(wishspeed, GeomLerp(autocvar_sv_maxairspeed*maxspd_mod, strafity, autocvar_sv_maxairstrafespeed*maxspd_mod));
1285 if(autocvar_sv_airstrafeaccelerate)
1286 airaccel = GeomLerp(airaccel, strafity, autocvar_sv_airstrafeaccelerate*maxspd_mod);
1287 if(self.stat_sv_airstrafeaccel_qw)
1288 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));
1291 if(autocvar_sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1292 PM_AirAccelerate(wishdir, wishspeed);
1294 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, autocvar_sv_airaccel_qw_stretchfactor, autocvar_sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw);
1296 if(autocvar_sv_aircontrol)
1297 CPM_PM_Aircontrol(wishdir, wishspeed2);
1301 if((g_cts || g_race) && self.classname != "observer") {
1302 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1303 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1304 speedaward_holder = self.netname;
1305 speedaward_uid = self.crypto_idfp;
1306 speedaward_lastupdate = time;
1308 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1314 race_send_speedaward(MSG_ALL);
1315 speedaward_lastsent = speedaward_speed;
1316 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") {
1317 speedaward_alltimebest = speedaward_speed;
1318 speedaward_alltimebest_holder = speedaward_holder;
1319 speedaward_alltimebest_uid = speedaward_uid;
1320 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1321 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1322 race_send_speedaward_alltimebest(MSG_ALL);
1328 xyspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y);
1329 if(self.weapon == WEP_NEX && autocvar_g_balance_nex_charge && autocvar_g_balance_nex_charge_velocity_rate && xyspeed > autocvar_g_balance_nex_charge_minspeed)
1331 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1332 xyspeed = min(xyspeed, autocvar_g_balance_nex_charge_maxspeed);
1333 f = (xyspeed - autocvar_g_balance_nex_charge_minspeed) / (autocvar_g_balance_nex_charge_maxspeed - autocvar_g_balance_nex_charge_minspeed);
1334 // add the extra charge
1335 self.nex_charge = min(1, self.nex_charge + autocvar_g_balance_nex_charge_velocity_rate * f * frametime);
1338 if(self.flags & FL_ONGROUND)
1339 self.lastground = time;
1341 self.lastflags = self.flags;
1342 self.lastclassname = self.classname;