7 float sv_airaccelerate;
11 float sv_airaccel_sideways_friction;
13 float sv_airstopaccelerate;
14 float sv_airstrafeaccelerate;
15 float sv_maxairstrafespeed;
16 float sv_airstrafeaccel_qw;
18 float sv_aircontrol_power;
19 float sv_warsowbunny_airforwardaccel;
20 float sv_warsowbunny_accel;
21 float sv_warsowbunny_topspeed;
22 float sv_warsowbunny_turnaccel;
23 float sv_warsowbunny_backtosideratio;
24 float sv_airspeedlimit_nonqw;
27 .entity ladder_entity;
29 .float swamp_slowdown;
33 .float spectatorspeed;
39 When you press the jump key
42 void PlayerJump (void)
50 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
51 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
55 mjumpheight = cvar("sv_jumpvelocity");
56 if (self.waterlevel >= WATERLEVEL_SWIMMING)
58 if (self.watertype == CONTENT_WATER)
59 self.velocity_z = 200;
60 else if (self.watertype == CONTENT_SLIME)
69 if (!(self.flags & FL_ONGROUND))
73 if (!(self.flags & FL_JUMPRELEASED))
76 if(self.health <= g_bloodloss)
81 if(self.runes & RUNE_SPEED)
83 if(self.runes & CURSE_SLOW)
84 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
86 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
88 else if(self.runes & CURSE_SLOW)
90 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
94 if(g_minstagib && (self.items & IT_INVINCIBLE))
96 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
99 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
100 // velocity bounds. Final velocity is bound between (jumpheight *
101 // min + jumpheight) and (jumpheight * max + jumpheight);
103 if(cvar_string("sv_jumpspeedcap_min") != "")
107 minjumpspeed = mjumpheight * cvar("sv_jumpspeedcap_min");
109 if (self.velocity_z < minjumpspeed)
110 mjumpheight += minjumpspeed - self.velocity_z;
113 if(cvar_string("sv_jumpspeedcap_max") != "")
115 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
116 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
118 if(!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && cvar("sv_jumpspeedcap_max_disable_on_ramps")))
122 maxjumpspeed = mjumpheight * cvar("sv_jumpspeedcap_max");
124 if (self.velocity_z > maxjumpspeed)
125 mjumpheight -= self.velocity_z - maxjumpspeed;
129 if(!(self.lastflags & FL_ONGROUND))
131 if(cvar("speedmeter"))
132 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
133 if(self.lastground < time - 0.3)
135 self.velocity_x *= (1 - cvar("sv_friction_on_land"));
136 self.velocity_y *= (1 - cvar("sv_friction_on_land"));
138 if(self.jumppadcount > 1)
139 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
140 self.jumppadcount = 0;
143 self.velocity_z = self.velocity_z + mjumpheight;
144 self.oldvelocity_z = self.velocity_z;
146 self.flags &~= FL_ONGROUND;
147 self.flags &~= FL_JUMPRELEASED;
150 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
152 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
155 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
157 self.restart_jump = -1; // restart jump anim next time
158 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
161 void CheckWaterJump()
163 local vector start, end;
165 // check for a jump-out-of-water
166 makevectors (self.angles);
168 start_z = start_z + 8;
170 normalize(v_forward);
171 end = start + v_forward*24;
172 traceline (start, end, TRUE, self);
173 if (trace_fraction < 1)
175 start_z = start_z + self.maxs_z - 8;
176 end = start + v_forward*24;
177 self.movedir = trace_plane_normal * -50;
178 traceline (start, end, TRUE, self);
179 if (trace_fraction == 1)
180 { // open at eye level
181 self.flags |= FL_WATERJUMP;
182 self.velocity_z = 225;
183 self.flags &~= FL_JUMPRELEASED;
184 self.teleport_time = time + 2; // safety net
190 float racecar_angle(float forward, float down)
192 float ret, angle_mult;
200 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
202 angle_mult = forward / (800 + forward);
205 return ret * angle_mult + 360 * (1 - angle_mult);
207 return ret * angle_mult;
210 void RaceCarPhysics()
212 // using this move type for "big rigs"
213 // the engine does not push the entity!
215 float accel, steer, f;
216 vector angles_save, rigvel;
218 angles_save = self.angles;
219 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
220 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
222 if(g_bugrigs_reverse_speeding)
226 // back accel is DIGITAL
227 // to prevent speedhack
237 makevectors(self.angles); // new forward direction!
239 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
241 float myspeed, upspeed, steerfactor, accelfactor;
243 myspeed = self.velocity * v_forward;
244 upspeed = self.velocity * v_up;
246 // responsiveness factor for steering and acceleration
247 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
248 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
250 if(myspeed < 0 && g_bugrigs_reverse_spinning)
251 steerfactor = -myspeed * g_bugrigs_steer;
253 steerfactor = -myspeed * f * g_bugrigs_steer;
255 if(myspeed < 0 && g_bugrigs_reverse_speeding)
256 accelfactor = g_bugrigs_accel;
258 accelfactor = f * g_bugrigs_accel;
259 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
265 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
269 if(!g_bugrigs_reverse_speeding)
270 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
277 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
281 if(g_bugrigs_reverse_stopping)
284 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
287 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
288 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
290 self.angles_y += steer * frametime * steerfactor; // apply steering
291 makevectors(self.angles); // new forward direction!
293 myspeed += accel * accelfactor * frametime;
295 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
299 myspeed = vlen(self.velocity);
301 // responsiveness factor for steering and acceleration
302 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
303 steerfactor = -myspeed * f;
304 self.angles_y += steer * frametime * steerfactor; // apply steering
306 rigvel = self.velocity;
307 makevectors(self.angles); // new forward direction!
310 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
311 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
312 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
313 //MAXIMA: solve(total_acceleration(v) = 0, v);
315 if(g_bugrigs_planar_movement)
317 vector rigvel_xy, neworigin, up;
320 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
324 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
327 mt = MOVE_NOMONSTERS;
329 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
330 up = trace_endpos - self.origin;
332 // BUG RIGS: align the move to the surface instead of doing collision testing
334 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
337 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
339 if(trace_fraction < 0.5)
342 neworigin = self.origin;
345 neworigin = trace_endpos;
347 if(trace_fraction < 1)
349 // now set angles_x so that the car points parallel to the surface
350 self.angles = vectoangles(
351 '1 0 0' * v_forward_x * trace_plane_normal_z
353 '0 1 0' * v_forward_y * trace_plane_normal_z
355 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
357 self.flags |= FL_ONGROUND;
361 // now set angles_x so that the car points forward, but is tilted in velocity direction
362 self.flags &~= FL_ONGROUND;
365 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
366 self.movetype = MOVETYPE_NOCLIP;
370 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
371 self.velocity = rigvel;
372 self.movetype = MOVETYPE_FLY;
376 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
377 if(trace_fraction != 1)
379 self.angles = vectoangles2(
380 '1 0 0' * v_forward_x * trace_plane_normal_z
382 '0 1 0' * v_forward_y * trace_plane_normal_z
384 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
392 vel_local_x = v_forward * self.velocity;
393 vel_local_y = v_right * self.velocity;
394 vel_local_z = v_up * self.velocity;
396 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
397 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
401 vector vf1, vu1, smoothangles;
402 makevectors(self.angles);
403 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
408 makevectors(angles_save);
409 vf1 = vf1 + v_forward * (1 - f);
410 vu1 = vu1 + v_up * (1 - f);
411 smoothangles = vectoangles2(vf1, vu1);
412 self.angles_x = -smoothangles_x;
413 self.angles_z = smoothangles_z;
416 float IsMoveInDirection(vector mv, float angle) // key mix factor
418 if(mv_x == 0 && mv_y == 0)
419 return 0; // avoid division by zero
420 angle -= RAD2DEG * atan2(mv_y, mv_x);
421 angle = remainder(angle, 360) / 45;
426 return 1 - fabs(angle);
429 float GeomLerp(float a, float lerp, float b)
445 return a * pow(fabs(b / a), lerp);
448 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
450 float zspeed, xyspeed, dot, k;
453 // this doesn't play well with analog input
454 if(self.movement_x == 0 || self.movement_y != 0)
455 return; // can't control movement if not moving forward or backward
458 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
463 k *= bound(0, wishspeed / sv_maxairspeed, 1);
465 zspeed = self.velocity_z;
467 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
469 dot = self.velocity * wishdir;
471 if(dot > 0) // we can't change direction while slowing down
473 k *= fabs(sv_aircontrol)*pow(dot, sv_aircontrol_power)*frametime;
474 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
477 self.velocity = self.velocity * xyspeed;
478 self.velocity_z = zspeed;
481 float AdjustAirAccelQW(float accelqw, float factor)
483 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
486 // example config for alternate speed clamping:
487 // sv_airaccel_qw 0.8
488 // sv_airaccel_sideways_friction 0
489 // prvm_globalset server speedclamp_mode 1
491 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float sidefric, float speedlimit)
499 float vel_xy_current;
500 float vel_xy_backward, vel_xy_forward;
503 speedclamp = (accelqw < 0);
507 if(cvar("sv_gameplayfix_q2airaccelerate"))
508 wishspeed0 = wishspeed;
510 vel_straight = self.velocity * wishdir;
511 vel_z = self.velocity_z;
512 vel_xy = self.velocity - vel_z * '0 0 1';
513 vel_perpend = vel_xy - vel_straight * wishdir;
515 step = accel * frametime * wishspeed0;
517 vel_xy_current = vlen(vel_xy);
519 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
520 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
521 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
522 if(vel_xy_backward < 0)
523 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
525 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
527 if(sidefric < 0 && (vel_perpend*vel_perpend))
528 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
531 f = max(0, 1 + frametime * wishspeed * sidefric);
532 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
533 // this cannot be > 1
535 vel_perpend = vel_perpend * max(0, f);
538 fminimum = sqrt(fminimum);
539 vel_perpend = vel_perpend * max(fminimum, f);
543 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
545 vel_xy = vel_straight * wishdir + vel_perpend;
549 // ensure we don't get too fast or decelerate faster than we should
550 vel_xy_current = min(vlen(vel_xy), vel_xy_forward);
551 if(vel_xy_current > 0) // prevent division by zero
552 vel_xy = normalize(vel_xy) * vel_xy_current;
555 self.velocity = vel_xy + vel_z * '0 0 1';
558 void PM_AirAccelerate(vector wishdir, float wishspeed)
560 vector curvel, wishvel, acceldir, curdir;
561 float addspeed, accelspeed, curspeed, f;
567 curvel = self.velocity;
569 curspeed = vlen(curvel);
571 if(wishspeed > curspeed * 1.01)
573 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
577 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
578 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
580 wishvel = wishdir * wishspeed;
581 acceldir = wishvel - curvel;
582 addspeed = vlen(acceldir);
583 acceldir = normalize(acceldir);
585 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
587 if(sv_warsowbunny_backtosideratio < 1)
589 curdir = normalize(curvel);
590 dot = acceldir * curdir;
592 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
595 self.velocity += accelspeed * acceldir;
598 .vector movement_old;
601 .string lastclassname;
603 .float() PlayerPhysplug;
605 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
606 .float specialcommand_pos;
607 void SpecialCommand()
612 if(!CheatImpulse(99))
613 print("A hollow voice says \"Plugh\".\n");
617 float speedaward_speed;
618 string speedaward_holder;
619 void race_send_speedaward(float msg)
621 // send the best speed of the round
622 WriteByte(msg, SVC_TEMPENTITY);
623 WriteByte(msg, TE_CSQC_RACE);
624 WriteByte(msg, RACE_NET_SPEED_AWARD);
625 WriteInt24_t(msg, floor(speedaward_speed+0.5));
626 WriteString(msg, speedaward_holder);
629 float speedaward_alltimebest;
630 string speedaward_alltimebest_holder;
631 void race_send_speedaward_alltimebest(float msg)
633 // send the best speed
634 WriteByte(msg, SVC_TEMPENTITY);
635 WriteByte(msg, TE_CSQC_RACE);
636 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
637 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
638 WriteString(msg, speedaward_alltimebest_holder);
641 string GetMapname(void);
642 float speedaward_lastupdate;
643 float speedaward_lastsent;
644 void SV_PlayerPhysics()
646 local vector wishvel, wishdir, v;
647 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
650 float not_allowed_to_move;
653 // fix physics stats for g_movement_highspeed
654 self.stat_sv_airaccel_qw = AdjustAirAccelQW(sv_airaccel_qw, autocvar_g_movement_highspeed);
655 if(sv_airstrafeaccel_qw)
656 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(sv_airstrafeaccel_qw, autocvar_g_movement_highspeed);
658 self.stat_sv_airstrafeaccel_qw = 0;
659 self.stat_sv_airspeedlimit_nonqw = sv_airspeedlimit_nonqw * autocvar_g_movement_highspeed;
661 if(self.PlayerPhysplug)
662 if(self.PlayerPhysplug())
665 self.race_movetime_frac += frametime;
666 f = floor(self.race_movetime_frac);
667 self.race_movetime_frac -= f;
668 self.race_movetime_count += f;
669 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
673 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);
677 else if(buttons == 1)
679 else if(buttons == 2)
681 else if(buttons == 128)
683 else if(buttons == 256)
685 else if(buttons == 512)
687 else if(buttons == 1024)
692 if(c == substring(specialcommand, self.specialcommand_pos, 1))
694 self.specialcommand_pos += 1;
695 if(self.specialcommand_pos >= strlen(specialcommand))
697 self.specialcommand_pos = 0;
702 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
703 self.specialcommand_pos = 0;
705 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
707 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
708 self.parm_idlesince = time;
710 buttons_prev = self.buttons_old;
711 self.buttons_old = buttons;
712 self.movement_old = self.movement;
713 self.v_angle_old = self.v_angle;
715 if(time < self.nickspamtime)
716 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
718 // slight annoyance for nick change scripts
719 self.movement = -1 * self.movement;
720 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
722 if(self.nickspamcount >= cvar("g_nick_flood_penalty_red")) // if you are persistent and the slight annoyance above does not stop you, I'll show you!
724 self.angles_x = random() * 360;
725 self.angles_y = random() * 360;
726 // at least I'm not forcing retardedview by also assigning to angles_z
731 if (self.punchangle != '0 0 0')
733 f = vlen(self.punchangle) - 10 * frametime;
735 self.punchangle = normalize(self.punchangle) * f;
737 self.punchangle = '0 0 0';
740 if (self.punchvector != '0 0 0')
742 f = vlen(self.punchvector) - 30 * frametime;
744 self.punchvector = normalize(self.punchvector) * f;
746 self.punchvector = '0 0 0';
749 if (clienttype(self) == CLIENTTYPE_BOT)
751 if(playerdemo_read())
756 MUTATOR_CALLHOOK(PlayerPhysics);
758 self.items &~= IT_USING_JETPACK;
760 if(self.classname == "player")
762 if(self.race_penalty)
763 if(time > self.race_penalty)
764 self.race_penalty = 0;
766 not_allowed_to_move = 0;
767 if(self.race_penalty)
768 not_allowed_to_move = 1;
769 if(!cvar("sv_ready_restart_after_countdown"))
770 if(time < game_starttime)
771 not_allowed_to_move = 1;
773 if(not_allowed_to_move)
775 self.velocity = '0 0 0';
776 self.movetype = MOVETYPE_NONE;
777 self.disableclientprediction = 2;
779 else if(self.disableclientprediction == 2)
781 if(self.movetype == MOVETYPE_NONE)
782 self.movetype = MOVETYPE_WALK;
783 self.disableclientprediction = 0;
787 if (self.movetype == MOVETYPE_NONE)
794 if(self.runes & RUNE_SPEED)
796 if(self.runes & CURSE_SLOW)
797 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
799 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
801 else if(self.runes & CURSE_SLOW)
803 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
807 if(g_minstagib && (self.items & IT_INVINCIBLE))
809 maxspd_mod = cvar("g_minstagib_speed_moverate");
812 if(g_nexball && self.ballcarried)
814 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
819 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
822 if(self.classname != "player")
824 maxspd_mod = cvar("sv_spectator_speed_multiplier");
825 if(!self.spectatorspeed)
826 self.spectatorspeed = maxspd_mod;
827 if(self.impulse && self.impulse <= 19)
829 if(self.lastclassname != "player")
831 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
832 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
833 else if(self.impulse == 11)
834 self.spectatorspeed = maxspd_mod;
835 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
836 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
837 else if(self.impulse >= 1 && self.impulse <= 9)
838 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
839 } // otherwise just clear
842 maxspd_mod = self.spectatorspeed;
845 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
846 if(self.speed != spd)
850 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
851 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
852 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
853 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
856 maxspd_mod *= swampspd_mod; // only one common speed modder please!
859 // if dead, behave differently
863 if (!self.fixangle && !g_bugrigs)
866 self.angles_y = self.v_angle_y;
870 if(self.flags & FL_ONGROUND)
875 if(self.waterlevel < WATERLEVEL_SWIMMING)
876 if(time >= self.ladder_time)
879 self.nextstep = time + 0.3 + random() * 0.1;
880 trace_dphitq3surfaceflags = 0;
881 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
882 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
884 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
885 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
887 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
895 if(self.classname == "player")
897 if (self.BUTTON_JUMP)
900 self.flags |= FL_JUMPRELEASED;
902 if (self.waterlevel == WATERLEVEL_SWIMMING)
906 if (self.flags & FL_WATERJUMP )
908 self.velocity_x = self.movedir_x;
909 self.velocity_y = self.movedir_y;
910 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
912 self.flags &~= FL_WATERJUMP;
913 self.teleport_time = 0;
916 else if (g_bugrigs && self.classname == "player")
920 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
922 // noclipping or flying
923 self.flags &~= FL_ONGROUND;
925 self.velocity = self.velocity * (1 - frametime * sv_friction);
926 makevectors(self.v_angle);
927 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
928 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
930 wishdir = normalize(wishvel);
931 wishspeed = vlen(wishvel);
932 if (wishspeed > sv_maxspeed*maxspd_mod)
933 wishspeed = sv_maxspeed*maxspd_mod;
934 if (time >= self.teleport_time)
935 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0, 0);
937 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
940 self.flags &~= FL_ONGROUND;
942 makevectors(self.v_angle);
943 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
944 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
945 if (wishvel == '0 0 0')
946 wishvel = '0 0 -60'; // drift towards bottom
948 wishdir = normalize(wishvel);
949 wishspeed = vlen(wishvel);
950 if (wishspeed > sv_maxspeed*maxspd_mod)
951 wishspeed = sv_maxspeed*maxspd_mod;
952 wishspeed = wishspeed * 0.7;
955 self.velocity = self.velocity * (1 - frametime * sv_friction);
957 // water acceleration
958 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0, 0);
960 else if (time < self.ladder_time)
962 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
963 self.flags &~= FL_ONGROUND;
965 self.velocity = self.velocity * (1 - frametime * sv_friction);
966 makevectors(self.v_angle);
967 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
968 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
970 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
972 self.velocity_z = self.velocity_z + sv_gravity * frametime;
973 if (self.ladder_entity.classname == "func_water")
976 if (f > self.ladder_entity.speed)
977 wishvel = wishvel * (self.ladder_entity.speed / f);
979 self.watertype = self.ladder_entity.skin;
980 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
981 if ((self.origin_z + self.view_ofs_z) < f)
982 self.waterlevel = WATERLEVEL_SUBMERGED;
983 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
984 self.waterlevel = WATERLEVEL_SWIMMING;
985 else if ((self.origin_z + self.mins_z + 1) < f)
986 self.waterlevel = WATERLEVEL_WETFEET;
989 self.waterlevel = WATERLEVEL_NONE;
990 self.watertype = CONTENT_EMPTY;
994 wishdir = normalize(wishvel);
995 wishspeed = vlen(wishvel);
996 if (wishspeed > sv_maxspeed*maxspd_mod)
997 wishspeed = sv_maxspeed*maxspd_mod;
998 if (time >= self.teleport_time)
1000 // water acceleration
1001 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0, 0);
1004 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
1006 //makevectors(self.v_angle_y * '0 1 0');
1007 makevectors(self.v_angle);
1008 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1009 // add remaining speed as Z component
1010 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
1011 // fix speedhacks :P
1012 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
1013 // add the unused velocity as up component
1016 // if(self.BUTTON_JUMP)
1017 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1019 // it is now normalized, so...
1020 float a_side, a_up, a_add, a_diff;
1021 a_side = cvar("g_jetpack_acceleration_side");
1022 a_up = cvar("g_jetpack_acceleration_up");
1023 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
1025 wishvel_x *= a_side;
1026 wishvel_y *= a_side;
1032 //////////////////////////////////////////////////////////////////////////////////////
1033 // finding the maximum over all vectors of above form
1034 // with wishvel having an absolute value of 1
1035 //////////////////////////////////////////////////////////////////////////////////////
1036 // we're finding the maximum over
1037 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1038 // for z in the range from -1 to 1
1039 //////////////////////////////////////////////////////////////////////////////////////
1040 // maximum is EITHER attained at the single extreme point:
1041 a_diff = a_side * a_side - a_up * a_up;
1044 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1045 if(f > -1 && f < 1) // can it be attained?
1047 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1048 //print("middle\n");
1051 // OR attained at z = 1:
1052 f = (a_up + a_add) * (a_up + a_add);
1058 // OR attained at z = -1:
1059 f = (a_up - a_add) * (a_up - a_add);
1063 //print("bottom\n");
1066 //////////////////////////////////////////////////////////////////////////////////////
1068 //print("best possible acceleration: ", ftos(best), "\n");
1071 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
1072 if(wishvel_z - sv_gravity > 0)
1073 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1075 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1078 fvel = vlen(wishvel);
1081 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
1083 fvel = min(1, vlen(wishvel) / best);
1084 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1085 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
1089 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1091 if (f > 0 && wishvel != '0 0 0')
1093 self.velocity = self.velocity + wishvel * f * frametime;
1094 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1095 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
1096 self.flags &~= FL_ONGROUND;
1097 self.items |= IT_USING_JETPACK;
1099 // jetpack also inhibits health regeneration, but only for 1 second
1100 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1103 else if (self.flags & FL_ONGROUND)
1105 // we get here if we ran out of ammo
1106 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1107 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1110 makevectors(self.v_angle_y * '0 1 0');
1111 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1113 if(!(self.lastflags & FL_ONGROUND))
1115 if(cvar("speedmeter"))
1116 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1117 if(self.lastground < time - 0.3)
1118 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1119 if(self.jumppadcount > 1)
1120 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1121 self.jumppadcount = 0;
1124 #ifdef LETS_TEST_FTEQCC
1125 if(self.velocity_x || self.velocity_y)
1143 if (f < sv_stopspeed)
1144 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
1146 f = 1 - frametime * sv_friction;
1148 self.velocity = self.velocity * f;
1150 self.velocity = '0 0 0';
1154 wishdir = normalize(wishvel);
1155 wishspeed = vlen(wishvel);
1156 if (wishspeed > sv_maxspeed*maxspd_mod)
1157 wishspeed = sv_maxspeed*maxspd_mod;
1159 wishspeed = wishspeed * 0.5;
1160 if (time >= self.teleport_time)
1161 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0, 0);
1166 // we get here if we ran out of ammo
1167 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1168 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1172 maxairspd = sv_maxairspeed*maxspd_mod;
1173 airaccel = sv_airaccelerate*maxspd_mod;
1177 maxairspd = sv_maxairspeed;
1178 airaccel = sv_airaccelerate;
1181 makevectors(self.v_angle_y * '0 1 0');
1182 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1184 wishdir = normalize(wishvel);
1185 wishspeed = wishspeed0 = vlen(wishvel);
1186 if (wishspeed0 > sv_maxspeed*maxspd_mod)
1187 wishspeed0 = sv_maxspeed*maxspd_mod;
1188 if (wishspeed > maxairspd)
1189 wishspeed = maxairspd;
1191 wishspeed = wishspeed * 0.5;
1192 if (time >= self.teleport_time)
1199 airaccelqw = self.stat_sv_airaccel_qw;
1200 accelerating = (self.velocity * wishdir > 0);
1201 wishspeed2 = wishspeed;
1204 if(sv_airstopaccelerate)
1205 if(self.velocity * wishdir < 0)
1206 airaccel = sv_airstopaccelerate*maxspd_mod;
1207 // note that for straight forward jumping:
1208 // step = accel * frametime * wishspeed0;
1209 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1211 // dv/dt = accel * maxspeed (when slow)
1212 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1213 // log dv/dt = logaccel + logmaxspeed (when slow)
1214 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1215 strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
1216 if(sv_maxairstrafespeed)
1217 wishspeed = min(wishspeed, GeomLerp(sv_maxairspeed*maxspd_mod, strafity, sv_maxairstrafespeed*maxspd_mod));
1218 if(sv_airstrafeaccelerate)
1219 airaccel = GeomLerp(airaccel, strafity, sv_airstrafeaccelerate*maxspd_mod);
1220 if(self.stat_sv_airstrafeaccel_qw)
1221 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));
1224 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1225 PM_AirAccelerate(wishdir, wishspeed);
1227 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw);
1230 CPM_PM_Aircontrol(wishdir, wishspeed2);
1234 if((g_cts || g_race) && self.classname != "observer") {
1235 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1236 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1237 speedaward_holder = self.netname;
1238 speedaward_lastupdate = time;
1240 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1246 race_send_speedaward(MSG_ALL);
1247 speedaward_lastsent = speedaward_speed;
1248 if (speedaward_speed > speedaward_alltimebest) {
1249 speedaward_alltimebest = speedaward_speed;
1250 speedaward_alltimebest_holder = speedaward_holder;
1251 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1252 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"), speedaward_alltimebest_holder);
1253 race_send_speedaward_alltimebest(MSG_ALL);
1258 if(self.flags & FL_ONGROUND)
1259 self.lastground = time;
1261 self.lastflags = self.flags;
1262 self.lastclassname = self.classname;