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_aircontrol_penalty;
20 float sv_warsowbunny_airforwardaccel;
21 float sv_warsowbunny_accel;
22 float sv_warsowbunny_topspeed;
23 float sv_warsowbunny_turnaccel;
24 float sv_warsowbunny_backtosideratio;
25 float sv_airspeedlimit_nonqw;
28 .entity ladder_entity;
30 .float swamp_slowdown;
34 .float spectatorspeed;
36 .float multijump_count;
37 .float multijump_ready;
38 .float prevjumpbutton;
40 .float prevtopspeed; // store the top speed during the last 0.25 seconds to make dodging at full speeds easier
41 .float prevtopspeed_time;
47 When you press the jump key
50 void PlayerJump (void)
58 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
59 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
63 mjumpheight = cvar("sv_jumpvelocity");
64 if (self.waterlevel >= WATERLEVEL_SWIMMING)
66 if (self.watertype == CONTENT_WATER)
67 self.velocity_z = 200;
68 else if (self.watertype == CONTENT_SLIME)
76 if (cvar("g_multijump"))
78 if (self.prevjumpbutton == FALSE && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair
79 self.multijump_ready = TRUE; // this is necessary to check that we released the jump button and pressed it again
81 self.multijump_ready = FALSE;
84 if(self.multijump_ready && self.multijump_count < cvar("g_multijump") && self.velocity_z > cvar("g_multijump_speed"))
86 if (cvar("g_multijump") > 0)
88 if (cvar("g_multijump_add") == 0) // in this case we make the z velocity == jumpvelocity
92 curspeed = vlen(self.velocity);
93 local vector wishvel, wishdir;
94 makevectors(self.v_angle);
95 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
96 wishdir = normalize(wishvel);
97 if(wishdir_x != 0 && wishdir_y != 0) // don't remove all speed if player isnt pressing any movement keys
99 self.velocity_x = wishdir_x * max(curspeed, self.prevtopspeed); // allow "dodging" at a multijump
100 self.velocity_y = wishdir_y * max(curspeed, self.prevtopspeed);
102 self.multijump_count += 1;
104 self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump
106 else if (!doublejump)
107 if (!(self.flags & FL_ONGROUND))
111 if (!(self.flags & FL_JUMPRELEASED))
114 if(self.health <= g_bloodloss)
119 if(self.runes & RUNE_SPEED)
121 if(self.runes & CURSE_SLOW)
122 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
124 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
126 else if(self.runes & CURSE_SLOW)
128 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
132 if(g_minstagib && (self.items & IT_INVINCIBLE))
134 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
137 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
138 // velocity bounds. Final velocity is bound between (jumpheight *
139 // min + jumpheight) and (jumpheight * max + jumpheight);
141 if(cvar_string("sv_jumpspeedcap_min") != "")
145 minjumpspeed = mjumpheight * cvar("sv_jumpspeedcap_min");
147 if (self.velocity_z < minjumpspeed)
148 mjumpheight += minjumpspeed - self.velocity_z;
151 if(cvar_string("sv_jumpspeedcap_max") != "")
153 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
154 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
156 if(!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && cvar("sv_jumpspeedcap_max_disable_on_ramps")))
160 maxjumpspeed = mjumpheight * cvar("sv_jumpspeedcap_max");
162 if (self.velocity_z > maxjumpspeed)
163 mjumpheight -= self.velocity_z - maxjumpspeed;
167 if(!(self.lastflags & FL_ONGROUND))
169 if(cvar("speedmeter"))
170 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
171 if(self.lastground < time - 0.3)
173 self.velocity_x *= (1 - cvar("sv_friction_on_land"));
174 self.velocity_y *= (1 - cvar("sv_friction_on_land"));
176 if(self.jumppadcount > 1)
177 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
178 self.jumppadcount = 0;
181 self.velocity_z = self.velocity_z + mjumpheight;
182 self.oldvelocity_z = self.velocity_z;
184 self.flags &~= FL_ONGROUND;
185 self.flags &~= FL_JUMPRELEASED;
188 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
190 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
193 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
195 self.restart_jump = -1; // restart jump anim next time
196 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
199 void CheckWaterJump()
201 local vector start, end;
203 // check for a jump-out-of-water
204 makevectors (self.angles);
206 start_z = start_z + 8;
208 normalize(v_forward);
209 end = start + v_forward*24;
210 traceline (start, end, TRUE, self);
211 if (trace_fraction < 1)
213 start_z = start_z + self.maxs_z - 8;
214 end = start + v_forward*24;
215 self.movedir = trace_plane_normal * -50;
216 traceline (start, end, TRUE, self);
217 if (trace_fraction == 1)
218 { // open at eye level
219 self.flags |= FL_WATERJUMP;
220 self.velocity_z = 225;
221 self.flags &~= FL_JUMPRELEASED;
222 self.teleport_time = time + 2; // safety net
228 float racecar_angle(float forward, float down)
230 float ret, angle_mult;
238 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
240 angle_mult = forward / (800 + forward);
243 return ret * angle_mult + 360 * (1 - angle_mult);
245 return ret * angle_mult;
248 void RaceCarPhysics()
250 // using this move type for "big rigs"
251 // the engine does not push the entity!
253 float accel, steer, f;
254 vector angles_save, rigvel;
256 angles_save = self.angles;
257 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
258 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
260 if(g_bugrigs_reverse_speeding)
264 // back accel is DIGITAL
265 // to prevent speedhack
275 makevectors(self.angles); // new forward direction!
277 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
279 float myspeed, upspeed, steerfactor, accelfactor;
281 myspeed = self.velocity * v_forward;
282 upspeed = self.velocity * v_up;
284 // responsiveness factor for steering and acceleration
285 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
286 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
288 if(myspeed < 0 && g_bugrigs_reverse_spinning)
289 steerfactor = -myspeed * g_bugrigs_steer;
291 steerfactor = -myspeed * f * g_bugrigs_steer;
293 if(myspeed < 0 && g_bugrigs_reverse_speeding)
294 accelfactor = g_bugrigs_accel;
296 accelfactor = f * g_bugrigs_accel;
297 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
303 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
307 if(!g_bugrigs_reverse_speeding)
308 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
315 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
319 if(g_bugrigs_reverse_stopping)
322 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
325 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
326 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
328 self.angles_y += steer * frametime * steerfactor; // apply steering
329 makevectors(self.angles); // new forward direction!
331 myspeed += accel * accelfactor * frametime;
333 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
337 myspeed = vlen(self.velocity);
339 // responsiveness factor for steering and acceleration
340 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
341 steerfactor = -myspeed * f;
342 self.angles_y += steer * frametime * steerfactor; // apply steering
344 rigvel = self.velocity;
345 makevectors(self.angles); // new forward direction!
348 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
349 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
350 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
351 //MAXIMA: solve(total_acceleration(v) = 0, v);
353 if(g_bugrigs_planar_movement)
355 vector rigvel_xy, neworigin, up;
358 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
362 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
365 mt = MOVE_NOMONSTERS;
367 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
368 up = trace_endpos - self.origin;
370 // BUG RIGS: align the move to the surface instead of doing collision testing
372 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
375 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
377 if(trace_fraction < 0.5)
380 neworigin = self.origin;
383 neworigin = trace_endpos;
385 if(trace_fraction < 1)
387 // now set angles_x so that the car points parallel to the surface
388 self.angles = vectoangles(
389 '1 0 0' * v_forward_x * trace_plane_normal_z
391 '0 1 0' * v_forward_y * trace_plane_normal_z
393 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
395 self.flags |= FL_ONGROUND;
399 // now set angles_x so that the car points forward, but is tilted in velocity direction
400 self.flags &~= FL_ONGROUND;
403 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
404 self.movetype = MOVETYPE_NOCLIP;
408 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
409 self.velocity = rigvel;
410 self.movetype = MOVETYPE_FLY;
414 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
415 if(trace_fraction != 1)
417 self.angles = vectoangles2(
418 '1 0 0' * v_forward_x * trace_plane_normal_z
420 '0 1 0' * v_forward_y * trace_plane_normal_z
422 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
430 vel_local_x = v_forward * self.velocity;
431 vel_local_y = v_right * self.velocity;
432 vel_local_z = v_up * self.velocity;
434 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
435 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
439 vector vf1, vu1, smoothangles;
440 makevectors(self.angles);
441 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
446 makevectors(angles_save);
447 vf1 = vf1 + v_forward * (1 - f);
448 vu1 = vu1 + v_up * (1 - f);
449 smoothangles = vectoangles2(vf1, vu1);
450 self.angles_x = -smoothangles_x;
451 self.angles_z = smoothangles_z;
454 float IsMoveInDirection(vector mv, float angle) // key mix factor
456 if(mv_x == 0 && mv_y == 0)
457 return 0; // avoid division by zero
458 angle -= RAD2DEG * atan2(mv_y, mv_x);
459 angle = remainder(angle, 360) / 45;
464 return 1 - fabs(angle);
467 float GeomLerp(float a, float lerp, float b)
483 return a * pow(fabs(b / a), lerp);
486 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
488 float zspeed, xyspeed, dot, k;
491 // this doesn't play well with analog input
492 if(self.movement_x == 0 || self.movement_y != 0)
493 return; // can't control movement if not moving forward or backward
496 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
501 k *= bound(0, wishspeed / sv_maxairspeed, 1);
503 zspeed = self.velocity_z;
505 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
507 dot = self.velocity * wishdir;
509 if(dot > 0) // we can't change direction while slowing down
511 k *= pow(dot, sv_aircontrol_power)*frametime;
512 xyspeed = max(0, xyspeed - sv_aircontrol_penalty * sqrt(max(0, 1 - dot*dot)) * k/32);
514 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
517 self.velocity = self.velocity * xyspeed;
518 self.velocity_z = zspeed;
521 float AdjustAirAccelQW(float accelqw, float factor)
523 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
526 // example config for alternate speed clamping:
527 // sv_airaccel_qw 0.8
528 // sv_airaccel_sideways_friction 0
529 // prvm_globalset server speedclamp_mode 1
531 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float sidefric, float speedlimit)
539 float vel_xy_current;
540 float vel_xy_backward, vel_xy_forward;
543 speedclamp = (accelqw < 0);
547 if(cvar("sv_gameplayfix_q2airaccelerate"))
548 wishspeed0 = wishspeed;
550 vel_straight = self.velocity * wishdir;
551 vel_z = self.velocity_z;
552 vel_xy = self.velocity - vel_z * '0 0 1';
553 vel_perpend = vel_xy - vel_straight * wishdir;
555 step = accel * frametime * wishspeed0;
557 vel_xy_current = vlen(vel_xy);
559 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
560 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
561 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
562 if(vel_xy_backward < 0)
563 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
565 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
567 if(sidefric < 0 && (vel_perpend*vel_perpend))
568 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
571 f = max(0, 1 + frametime * wishspeed * sidefric);
572 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
573 // this cannot be > 1
575 vel_perpend = vel_perpend * max(0, f);
578 fminimum = sqrt(fminimum);
579 vel_perpend = vel_perpend * max(fminimum, f);
583 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
585 vel_xy = vel_straight * wishdir + vel_perpend;
589 // ensure we don't get too fast or decelerate faster than we should
590 vel_xy_current = min(vlen(vel_xy), vel_xy_forward);
591 if(vel_xy_current > 0) // prevent division by zero
592 vel_xy = normalize(vel_xy) * vel_xy_current;
595 self.velocity = vel_xy + vel_z * '0 0 1';
598 void PM_AirAccelerate(vector wishdir, float wishspeed)
600 vector curvel, wishvel, acceldir, curdir;
601 float addspeed, accelspeed, curspeed, f;
607 curvel = self.velocity;
609 curspeed = vlen(curvel);
611 if(wishspeed > curspeed * 1.01)
613 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
617 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
618 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
620 wishvel = wishdir * wishspeed;
621 acceldir = wishvel - curvel;
622 addspeed = vlen(acceldir);
623 acceldir = normalize(acceldir);
625 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
627 if(sv_warsowbunny_backtosideratio < 1)
629 curdir = normalize(curvel);
630 dot = acceldir * curdir;
632 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
635 self.velocity += accelspeed * acceldir;
638 .vector movement_old;
641 .string lastclassname;
643 .float() PlayerPhysplug;
645 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
646 .float specialcommand_pos;
647 void SpecialCommand()
652 if(!CheatImpulse(99))
653 print("A hollow voice says \"Plugh\".\n");
657 float speedaward_speed;
658 string speedaward_holder;
659 void race_send_speedaward(float msg)
661 // send the best speed of the round
662 WriteByte(msg, SVC_TEMPENTITY);
663 WriteByte(msg, TE_CSQC_RACE);
664 WriteByte(msg, RACE_NET_SPEED_AWARD);
665 WriteInt24_t(msg, floor(speedaward_speed+0.5));
666 WriteString(msg, speedaward_holder);
669 float speedaward_alltimebest;
670 string speedaward_alltimebest_holder;
671 void race_send_speedaward_alltimebest(float msg)
673 // send the best speed
674 WriteByte(msg, SVC_TEMPENTITY);
675 WriteByte(msg, TE_CSQC_RACE);
676 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
677 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
678 WriteString(msg, speedaward_alltimebest_holder);
681 string GetMapname(void);
682 float speedaward_lastupdate;
683 float speedaward_lastsent;
684 void SV_PlayerPhysics()
686 local vector wishvel, wishdir, v;
687 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
690 float not_allowed_to_move;
693 // fix physics stats for g_movement_highspeed
694 self.stat_sv_airaccel_qw = AdjustAirAccelQW(sv_airaccel_qw, autocvar_g_movement_highspeed);
695 if(sv_airstrafeaccel_qw)
696 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(sv_airstrafeaccel_qw, autocvar_g_movement_highspeed);
698 self.stat_sv_airstrafeaccel_qw = 0;
699 self.stat_sv_airspeedlimit_nonqw = sv_airspeedlimit_nonqw * autocvar_g_movement_highspeed;
701 if(self.PlayerPhysplug)
702 if(self.PlayerPhysplug())
705 self.race_movetime_frac += frametime;
706 f = floor(self.race_movetime_frac);
707 self.race_movetime_frac -= f;
708 self.race_movetime_count += f;
709 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
713 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);
717 else if(buttons == 1)
719 else if(buttons == 2)
721 else if(buttons == 128)
723 else if(buttons == 256)
725 else if(buttons == 512)
727 else if(buttons == 1024)
732 if(c == substring(specialcommand, self.specialcommand_pos, 1))
734 self.specialcommand_pos += 1;
735 if(self.specialcommand_pos >= strlen(specialcommand))
737 self.specialcommand_pos = 0;
742 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
743 self.specialcommand_pos = 0;
745 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
747 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
748 self.parm_idlesince = time;
750 buttons_prev = self.buttons_old;
751 self.buttons_old = buttons;
752 self.movement_old = self.movement;
753 self.v_angle_old = self.v_angle;
755 if(time < self.nickspamtime)
756 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
758 // slight annoyance for nick change scripts
759 self.movement = -1 * self.movement;
760 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
762 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!
764 self.angles_x = random() * 360;
765 self.angles_y = random() * 360;
766 // at least I'm not forcing retardedview by also assigning to angles_z
771 if (self.punchangle != '0 0 0')
773 f = vlen(self.punchangle) - 10 * frametime;
775 self.punchangle = normalize(self.punchangle) * f;
777 self.punchangle = '0 0 0';
780 if (self.punchvector != '0 0 0')
782 f = vlen(self.punchvector) - 30 * frametime;
784 self.punchvector = normalize(self.punchvector) * f;
786 self.punchvector = '0 0 0';
789 if (clienttype(self) == CLIENTTYPE_BOT)
791 if(playerdemo_read())
796 MUTATOR_CALLHOOK(PlayerPhysics);
798 self.items &~= IT_USING_JETPACK;
800 if(self.classname == "player")
802 if(self.race_penalty)
803 if(time > self.race_penalty)
804 self.race_penalty = 0;
806 not_allowed_to_move = 0;
807 if(self.race_penalty)
808 not_allowed_to_move = 1;
809 if(!cvar("sv_ready_restart_after_countdown"))
810 if(time < game_starttime)
811 not_allowed_to_move = 1;
813 if(not_allowed_to_move)
815 self.velocity = '0 0 0';
816 self.movetype = MOVETYPE_NONE;
817 self.disableclientprediction = 2;
819 else if(self.disableclientprediction == 2)
821 if(self.movetype == MOVETYPE_NONE)
822 self.movetype = MOVETYPE_WALK;
823 self.disableclientprediction = 0;
827 if (self.movetype == MOVETYPE_NONE)
834 if(self.runes & RUNE_SPEED)
836 if(self.runes & CURSE_SLOW)
837 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
839 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
841 else if(self.runes & CURSE_SLOW)
843 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
847 if(g_minstagib && (self.items & IT_INVINCIBLE))
849 maxspd_mod = cvar("g_minstagib_speed_moverate");
852 if(g_nexball && self.ballcarried)
854 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
859 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
862 if(self.classname != "player")
864 maxspd_mod = cvar("sv_spectator_speed_multiplier");
865 if(!self.spectatorspeed)
866 self.spectatorspeed = maxspd_mod;
867 if(self.impulse && self.impulse <= 19)
869 if(self.lastclassname != "player")
871 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
872 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
873 else if(self.impulse == 11)
874 self.spectatorspeed = maxspd_mod;
875 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
876 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
877 else if(self.impulse >= 1 && self.impulse <= 9)
878 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
879 } // otherwise just clear
882 maxspd_mod = self.spectatorspeed;
885 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
886 if(self.speed != spd)
890 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
891 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
892 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
893 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
896 maxspd_mod *= swampspd_mod; // only one common speed modder please!
899 // if dead, behave differently
903 if (!self.fixangle && !g_bugrigs)
906 self.angles_y = self.v_angle_y;
910 if(self.flags & FL_ONGROUND)
915 if(self.waterlevel < WATERLEVEL_SWIMMING)
916 if(time >= self.ladder_time)
919 self.nextstep = time + 0.3 + random() * 0.1;
920 trace_dphitq3surfaceflags = 0;
921 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
922 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
924 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
925 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
927 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
935 if(self.classname == "player")
937 if(self.flags & FL_ONGROUND)
939 if (cvar("g_multijump") > 0)
940 self.multijump_count = 0;
942 self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller
945 if(vlen(self.velocity) >= self.prevtopspeed || time - self.prevtopspeed_time > 0.25)
947 self.prevtopspeed_time = time;
948 self.prevtopspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y);
951 if (self.BUTTON_JUMP)
954 self.flags |= FL_JUMPRELEASED;
956 if (self.waterlevel == WATERLEVEL_SWIMMING)
958 self.prevjumpbutton = self.BUTTON_JUMP;
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)
977 // noclipping or flying
978 self.flags &~= FL_ONGROUND;
980 self.velocity = self.velocity * (1 - frametime * 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 > sv_maxspeed*maxspd_mod)
988 wishspeed = sv_maxspeed*maxspd_mod;
989 if (time >= self.teleport_time)
990 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 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 > sv_maxspeed*maxspd_mod)
1006 wishspeed = sv_maxspeed*maxspd_mod;
1007 wishspeed = wishspeed * 0.7;
1010 self.velocity = self.velocity * (1 - frametime * sv_friction);
1012 // water acceleration
1013 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 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;
1020 self.velocity = self.velocity * (1 - frametime * sv_friction);
1021 makevectors(self.v_angle);
1022 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
1023 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
1025 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
1027 self.velocity_z = self.velocity_z + sv_gravity * frametime;
1028 if (self.ladder_entity.classname == "func_water")
1031 if (f > self.ladder_entity.speed)
1032 wishvel = wishvel * (self.ladder_entity.speed / f);
1034 self.watertype = self.ladder_entity.skin;
1035 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1036 if ((self.origin_z + self.view_ofs_z) < f)
1037 self.waterlevel = WATERLEVEL_SUBMERGED;
1038 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1039 self.waterlevel = WATERLEVEL_SWIMMING;
1040 else if ((self.origin_z + self.mins_z + 1) < f)
1041 self.waterlevel = WATERLEVEL_WETFEET;
1044 self.waterlevel = WATERLEVEL_NONE;
1045 self.watertype = CONTENT_EMPTY;
1049 wishdir = normalize(wishvel);
1050 wishspeed = vlen(wishvel);
1051 if (wishspeed > sv_maxspeed*maxspd_mod)
1052 wishspeed = sv_maxspeed*maxspd_mod;
1053 if (time >= self.teleport_time)
1055 // water acceleration
1056 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0, 0);
1059 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
1061 //makevectors(self.v_angle_y * '0 1 0');
1062 makevectors(self.v_angle);
1063 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1064 // add remaining speed as Z component
1065 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
1066 // fix speedhacks :P
1067 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
1068 // add the unused velocity as up component
1071 // if(self.BUTTON_JUMP)
1072 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1074 // it is now normalized, so...
1075 float a_side, a_up, a_add, a_diff;
1076 a_side = cvar("g_jetpack_acceleration_side");
1077 a_up = cvar("g_jetpack_acceleration_up");
1078 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
1080 wishvel_x *= a_side;
1081 wishvel_y *= a_side;
1087 //////////////////////////////////////////////////////////////////////////////////////
1088 // finding the maximum over all vectors of above form
1089 // with wishvel having an absolute value of 1
1090 //////////////////////////////////////////////////////////////////////////////////////
1091 // we're finding the maximum over
1092 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1093 // for z in the range from -1 to 1
1094 //////////////////////////////////////////////////////////////////////////////////////
1095 // maximum is EITHER attained at the single extreme point:
1096 a_diff = a_side * a_side - a_up * a_up;
1099 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1100 if(f > -1 && f < 1) // can it be attained?
1102 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1103 //print("middle\n");
1106 // OR attained at z = 1:
1107 f = (a_up + a_add) * (a_up + a_add);
1113 // OR attained at z = -1:
1114 f = (a_up - a_add) * (a_up - a_add);
1118 //print("bottom\n");
1121 //////////////////////////////////////////////////////////////////////////////////////
1123 //print("best possible acceleration: ", ftos(best), "\n");
1126 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
1127 if(wishvel_z - sv_gravity > 0)
1128 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1130 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1133 fvel = vlen(wishvel);
1136 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
1138 fvel = min(1, vlen(wishvel) / best);
1139 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1140 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
1144 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1146 if (f > 0 && wishvel != '0 0 0')
1148 self.velocity = self.velocity + wishvel * f * frametime;
1149 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1150 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
1151 self.flags &~= FL_ONGROUND;
1152 self.items |= IT_USING_JETPACK;
1154 // jetpack also inhibits health regeneration, but only for 1 second
1155 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1158 else if (self.flags & FL_ONGROUND)
1160 // we get here if we ran out of ammo
1161 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1162 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1165 makevectors(self.v_angle_y * '0 1 0');
1166 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1168 if(!(self.lastflags & FL_ONGROUND))
1170 if(cvar("speedmeter"))
1171 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1172 if(self.lastground < time - 0.3)
1173 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1174 if(self.jumppadcount > 1)
1175 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1176 self.jumppadcount = 0;
1179 #ifdef LETS_TEST_FTEQCC
1180 if(self.velocity_x || self.velocity_y)
1198 if (f < sv_stopspeed)
1199 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
1201 f = 1 - frametime * sv_friction;
1203 self.velocity = self.velocity * f;
1205 self.velocity = '0 0 0';
1209 wishdir = normalize(wishvel);
1210 wishspeed = vlen(wishvel);
1211 if (wishspeed > sv_maxspeed*maxspd_mod)
1212 wishspeed = sv_maxspeed*maxspd_mod;
1214 wishspeed = wishspeed * 0.5;
1215 if (time >= self.teleport_time)
1216 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0, 0);
1221 // we get here if we ran out of ammo
1222 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1223 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1227 maxairspd = sv_maxairspeed*maxspd_mod;
1228 airaccel = sv_airaccelerate*maxspd_mod;
1232 maxairspd = sv_maxairspeed;
1233 airaccel = sv_airaccelerate;
1236 makevectors(self.v_angle_y * '0 1 0');
1237 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1239 wishdir = normalize(wishvel);
1240 wishspeed = wishspeed0 = vlen(wishvel);
1241 if (wishspeed0 > sv_maxspeed*maxspd_mod)
1242 wishspeed0 = sv_maxspeed*maxspd_mod;
1243 if (wishspeed > maxairspd)
1244 wishspeed = maxairspd;
1246 wishspeed = wishspeed * 0.5;
1247 if (time >= self.teleport_time)
1254 airaccelqw = self.stat_sv_airaccel_qw;
1255 accelerating = (self.velocity * wishdir > 0);
1256 wishspeed2 = wishspeed;
1259 if(sv_airstopaccelerate)
1262 curdir = self.velocity;
1264 curdir = normalize(curdir);
1265 airaccel = airaccel + (sv_airstopaccelerate*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1267 // note that for straight forward jumping:
1268 // step = accel * frametime * wishspeed0;
1269 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1271 // dv/dt = accel * maxspeed (when slow)
1272 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1273 // log dv/dt = logaccel + logmaxspeed (when slow)
1274 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1275 strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
1276 if(sv_maxairstrafespeed)
1277 wishspeed = min(wishspeed, GeomLerp(sv_maxairspeed*maxspd_mod, strafity, sv_maxairstrafespeed*maxspd_mod));
1278 if(sv_airstrafeaccelerate)
1279 airaccel = GeomLerp(airaccel, strafity, sv_airstrafeaccelerate*maxspd_mod);
1280 if(self.stat_sv_airstrafeaccel_qw)
1281 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));
1284 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1285 PM_AirAccelerate(wishdir, wishspeed);
1287 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw);
1290 CPM_PM_Aircontrol(wishdir, wishspeed2);
1294 if((g_cts || g_race) && self.classname != "observer") {
1295 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1296 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1297 speedaward_holder = self.netname;
1298 speedaward_lastupdate = time;
1300 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1306 race_send_speedaward(MSG_ALL);
1307 speedaward_lastsent = speedaward_speed;
1308 if (speedaward_speed > speedaward_alltimebest) {
1309 speedaward_alltimebest = speedaward_speed;
1310 speedaward_alltimebest_holder = speedaward_holder;
1311 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1312 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"), speedaward_alltimebest_holder);
1313 race_send_speedaward_alltimebest(MSG_ALL);
1318 if(self.flags & FL_ONGROUND)
1319 self.lastground = time;
1321 self.lastflags = self.flags;
1322 self.lastclassname = self.classname;