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;
46 When you press the jump key
49 void PlayerJump (void)
57 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
58 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
62 mjumpheight = cvar("sv_jumpvelocity");
63 if (self.waterlevel >= WATERLEVEL_SWIMMING)
65 if (self.watertype == CONTENT_WATER)
66 self.velocity_z = 200;
67 else if (self.watertype == CONTENT_SLIME)
75 if (cvar("g_multijump"))
77 if (self.prevjumpbutton == FALSE && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair
78 self.multijump_ready = TRUE; // this is necessary to check that we released the jump button and pressed it again
80 self.multijump_ready = FALSE;
83 if(!doublejump && self.multijump_ready && self.multijump_count < cvar("g_multijump") && self.velocity_z > cvar("g_multijump_speed"))
85 // doublejump = FALSE; // checked above in the if
86 if (cvar("g_multijump") > 0)
88 if (cvar("g_multijump_add") == 0) // in this case we make the z velocity == jumpvelocity
90 if (self.velocity_z < mjumpheight)
101 if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
104 vector wishvel, wishdir;
107 vlen(vec2(self.velocity)), // current xy speed
108 vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
110 makevectors(self.v_angle_y * '0 1 0');
111 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
112 wishdir = normalize(wishvel);
114 self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
115 self.velocity_y = wishdir_y * curspeed;
116 // keep velocity_z unchanged!
118 self.multijump_count += 1;
121 self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump
125 if (!(self.flags & FL_ONGROUND))
129 if (!(self.flags & FL_JUMPRELEASED))
132 if(self.health <= g_bloodloss)
137 if(self.runes & RUNE_SPEED)
139 if(self.runes & CURSE_SLOW)
140 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
142 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
144 else if(self.runes & CURSE_SLOW)
146 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
150 if(g_minstagib && (self.items & IT_INVINCIBLE))
152 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
155 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
156 // velocity bounds. Final velocity is bound between (jumpheight *
157 // min + jumpheight) and (jumpheight * max + jumpheight);
159 if(cvar_string("sv_jumpspeedcap_min") != "")
163 minjumpspeed = mjumpheight * cvar("sv_jumpspeedcap_min");
165 if (self.velocity_z < minjumpspeed)
166 mjumpheight += minjumpspeed - self.velocity_z;
169 if(cvar_string("sv_jumpspeedcap_max") != "")
171 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
172 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
174 if(!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && cvar("sv_jumpspeedcap_max_disable_on_ramps")))
178 maxjumpspeed = mjumpheight * cvar("sv_jumpspeedcap_max");
180 if (self.velocity_z > maxjumpspeed)
181 mjumpheight -= self.velocity_z - maxjumpspeed;
185 if(!(self.lastflags & FL_ONGROUND))
187 if(cvar("speedmeter"))
188 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
189 if(self.lastground < time - 0.3)
191 self.velocity_x *= (1 - cvar("sv_friction_on_land"));
192 self.velocity_y *= (1 - cvar("sv_friction_on_land"));
194 if(self.jumppadcount > 1)
195 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
196 self.jumppadcount = 0;
199 self.velocity_z = self.velocity_z + mjumpheight;
200 self.oldvelocity_z = self.velocity_z;
202 self.flags &~= FL_ONGROUND;
203 self.flags &~= FL_JUMPRELEASED;
206 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
208 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
211 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
213 self.restart_jump = -1; // restart jump anim next time
214 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
217 void CheckWaterJump()
219 local vector start, end;
221 // check for a jump-out-of-water
222 makevectors (self.angles);
224 start_z = start_z + 8;
226 normalize(v_forward);
227 end = start + v_forward*24;
228 traceline (start, end, TRUE, self);
229 if (trace_fraction < 1)
231 start_z = start_z + self.maxs_z - 8;
232 end = start + v_forward*24;
233 self.movedir = trace_plane_normal * -50;
234 traceline (start, end, TRUE, self);
235 if (trace_fraction == 1)
236 { // open at eye level
237 self.flags |= FL_WATERJUMP;
238 self.velocity_z = 225;
239 self.flags &~= FL_JUMPRELEASED;
240 self.teleport_time = time + 2; // safety net
246 float racecar_angle(float forward, float down)
248 float ret, angle_mult;
256 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
258 angle_mult = forward / (800 + forward);
261 return ret * angle_mult + 360 * (1 - angle_mult);
263 return ret * angle_mult;
266 void RaceCarPhysics()
268 // using this move type for "big rigs"
269 // the engine does not push the entity!
271 float accel, steer, f;
272 vector angles_save, rigvel;
274 angles_save = self.angles;
275 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
276 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
278 if(g_bugrigs_reverse_speeding)
282 // back accel is DIGITAL
283 // to prevent speedhack
293 makevectors(self.angles); // new forward direction!
295 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
297 float myspeed, upspeed, steerfactor, accelfactor;
299 myspeed = self.velocity * v_forward;
300 upspeed = self.velocity * v_up;
302 // responsiveness factor for steering and acceleration
303 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
304 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
306 if(myspeed < 0 && g_bugrigs_reverse_spinning)
307 steerfactor = -myspeed * g_bugrigs_steer;
309 steerfactor = -myspeed * f * g_bugrigs_steer;
311 if(myspeed < 0 && g_bugrigs_reverse_speeding)
312 accelfactor = g_bugrigs_accel;
314 accelfactor = f * g_bugrigs_accel;
315 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
321 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
325 if(!g_bugrigs_reverse_speeding)
326 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
333 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
337 if(g_bugrigs_reverse_stopping)
340 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
343 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
344 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
346 self.angles_y += steer * frametime * steerfactor; // apply steering
347 makevectors(self.angles); // new forward direction!
349 myspeed += accel * accelfactor * frametime;
351 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
355 myspeed = vlen(self.velocity);
357 // responsiveness factor for steering and acceleration
358 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
359 steerfactor = -myspeed * f;
360 self.angles_y += steer * frametime * steerfactor; // apply steering
362 rigvel = self.velocity;
363 makevectors(self.angles); // new forward direction!
366 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
367 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
368 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
369 //MAXIMA: solve(total_acceleration(v) = 0, v);
371 if(g_bugrigs_planar_movement)
373 vector rigvel_xy, neworigin, up;
376 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
377 rigvel_xy = vec2(rigvel);
379 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
382 mt = MOVE_NOMONSTERS;
384 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
385 up = trace_endpos - self.origin;
387 // BUG RIGS: align the move to the surface instead of doing collision testing
389 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
392 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
394 if(trace_fraction < 0.5)
397 neworigin = self.origin;
400 neworigin = trace_endpos;
402 if(trace_fraction < 1)
404 // now set angles_x so that the car points parallel to the surface
405 self.angles = vectoangles(
406 '1 0 0' * v_forward_x * trace_plane_normal_z
408 '0 1 0' * v_forward_y * trace_plane_normal_z
410 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
412 self.flags |= FL_ONGROUND;
416 // now set angles_x so that the car points forward, but is tilted in velocity direction
417 self.flags &~= FL_ONGROUND;
420 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
421 self.movetype = MOVETYPE_NOCLIP;
425 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
426 self.velocity = rigvel;
427 self.movetype = MOVETYPE_FLY;
431 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
432 if(trace_fraction != 1)
434 self.angles = vectoangles2(
435 '1 0 0' * v_forward_x * trace_plane_normal_z
437 '0 1 0' * v_forward_y * trace_plane_normal_z
439 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
447 vel_local_x = v_forward * self.velocity;
448 vel_local_y = v_right * self.velocity;
449 vel_local_z = v_up * self.velocity;
451 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
452 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
456 vector vf1, vu1, smoothangles;
457 makevectors(self.angles);
458 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
463 makevectors(angles_save);
464 vf1 = vf1 + v_forward * (1 - f);
465 vu1 = vu1 + v_up * (1 - f);
466 smoothangles = vectoangles2(vf1, vu1);
467 self.angles_x = -smoothangles_x;
468 self.angles_z = smoothangles_z;
471 float IsMoveInDirection(vector mv, float angle) // key mix factor
473 if(mv_x == 0 && mv_y == 0)
474 return 0; // avoid division by zero
475 angle -= RAD2DEG * atan2(mv_y, mv_x);
476 angle = remainder(angle, 360) / 45;
481 return 1 - fabs(angle);
484 float GeomLerp(float a, float lerp, float b)
500 return a * pow(fabs(b / a), lerp);
503 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
505 float zspeed, xyspeed, dot, k;
508 // this doesn't play well with analog input
509 if(self.movement_x == 0 || self.movement_y != 0)
510 return; // can't control movement if not moving forward or backward
513 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
518 k *= bound(0, wishspeed / sv_maxairspeed, 1);
520 zspeed = self.velocity_z;
522 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
524 dot = self.velocity * wishdir;
526 if(dot > 0) // we can't change direction while slowing down
528 k *= pow(dot, sv_aircontrol_power)*frametime;
529 xyspeed = max(0, xyspeed - sv_aircontrol_penalty * sqrt(max(0, 1 - dot*dot)) * k/32);
531 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
534 self.velocity = self.velocity * xyspeed;
535 self.velocity_z = zspeed;
538 float AdjustAirAccelQW(float accelqw, float factor)
540 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
543 // example config for alternate speed clamping:
544 // sv_airaccel_qw 0.8
545 // sv_airaccel_sideways_friction 0
546 // prvm_globalset server speedclamp_mode 1
548 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float sidefric, float speedlimit)
556 float vel_xy_current;
557 float vel_xy_backward, vel_xy_forward;
560 speedclamp = (accelqw < 0);
564 if(cvar("sv_gameplayfix_q2airaccelerate"))
565 wishspeed0 = wishspeed;
567 vel_straight = self.velocity * wishdir;
568 vel_z = self.velocity_z;
569 vel_xy = vec2(self.velocity);
570 vel_perpend = vel_xy - vel_straight * wishdir;
572 step = accel * frametime * wishspeed0;
574 vel_xy_current = vlen(vel_xy);
576 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
577 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
578 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
579 if(vel_xy_backward < 0)
580 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
582 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
584 if(sidefric < 0 && (vel_perpend*vel_perpend))
585 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
588 f = max(0, 1 + frametime * wishspeed * sidefric);
589 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
590 // this cannot be > 1
592 vel_perpend = vel_perpend * max(0, f);
595 fminimum = sqrt(fminimum);
596 vel_perpend = vel_perpend * max(fminimum, f);
600 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
602 vel_xy = vel_straight * wishdir + vel_perpend;
606 // ensure we don't get too fast or decelerate faster than we should
607 vel_xy_current = min(vlen(vel_xy), vel_xy_forward);
608 if(vel_xy_current > 0) // prevent division by zero
609 vel_xy = normalize(vel_xy) * vel_xy_current;
612 self.velocity = vel_xy + vel_z * '0 0 1';
615 void PM_AirAccelerate(vector wishdir, float wishspeed)
617 vector curvel, wishvel, acceldir, curdir;
618 float addspeed, accelspeed, curspeed, f;
624 curvel = self.velocity;
626 curspeed = vlen(curvel);
628 if(wishspeed > curspeed * 1.01)
630 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
634 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
635 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
637 wishvel = wishdir * wishspeed;
638 acceldir = wishvel - curvel;
639 addspeed = vlen(acceldir);
640 acceldir = normalize(acceldir);
642 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
644 if(sv_warsowbunny_backtosideratio < 1)
646 curdir = normalize(curvel);
647 dot = acceldir * curdir;
649 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
652 self.velocity += accelspeed * acceldir;
655 .vector movement_old;
658 .string lastclassname;
660 .float() PlayerPhysplug;
662 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
663 .float specialcommand_pos;
664 void SpecialCommand()
669 if(!CheatImpulse(99))
670 print("A hollow voice says \"Plugh\".\n");
674 float speedaward_speed;
675 string speedaward_holder;
676 void race_send_speedaward(float msg)
678 // send the best speed of the round
679 WriteByte(msg, SVC_TEMPENTITY);
680 WriteByte(msg, TE_CSQC_RACE);
681 WriteByte(msg, RACE_NET_SPEED_AWARD);
682 WriteInt24_t(msg, floor(speedaward_speed+0.5));
683 WriteString(msg, speedaward_holder);
686 float speedaward_alltimebest;
687 string speedaward_alltimebest_holder;
688 void race_send_speedaward_alltimebest(float msg)
690 // send the best speed
691 WriteByte(msg, SVC_TEMPENTITY);
692 WriteByte(msg, TE_CSQC_RACE);
693 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
694 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
695 WriteString(msg, speedaward_alltimebest_holder);
698 string GetMapname(void);
699 float speedaward_lastupdate;
700 float speedaward_lastsent;
701 void SV_PlayerPhysics()
703 local vector wishvel, wishdir, v;
704 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
707 float not_allowed_to_move;
710 // fix physics stats for g_movement_highspeed
711 self.stat_sv_airaccel_qw = AdjustAirAccelQW(sv_airaccel_qw, autocvar_g_movement_highspeed);
712 if(sv_airstrafeaccel_qw)
713 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(sv_airstrafeaccel_qw, autocvar_g_movement_highspeed);
715 self.stat_sv_airstrafeaccel_qw = 0;
716 self.stat_sv_airspeedlimit_nonqw = sv_airspeedlimit_nonqw * autocvar_g_movement_highspeed;
718 if(self.PlayerPhysplug)
719 if(self.PlayerPhysplug())
722 self.race_movetime_frac += frametime;
723 f = floor(self.race_movetime_frac);
724 self.race_movetime_frac -= f;
725 self.race_movetime_count += f;
726 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
730 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);
734 else if(buttons == 1)
736 else if(buttons == 2)
738 else if(buttons == 128)
740 else if(buttons == 256)
742 else if(buttons == 512)
744 else if(buttons == 1024)
749 if(c == substring(specialcommand, self.specialcommand_pos, 1))
751 self.specialcommand_pos += 1;
752 if(self.specialcommand_pos >= strlen(specialcommand))
754 self.specialcommand_pos = 0;
759 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
760 self.specialcommand_pos = 0;
762 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
764 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
765 self.parm_idlesince = time;
767 buttons_prev = self.buttons_old;
768 self.buttons_old = buttons;
769 self.movement_old = self.movement;
770 self.v_angle_old = self.v_angle;
772 if(time < self.nickspamtime)
773 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
775 // slight annoyance for nick change scripts
776 self.movement = -1 * self.movement;
777 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
779 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!
781 self.angles_x = random() * 360;
782 self.angles_y = random() * 360;
783 // at least I'm not forcing retardedview by also assigning to angles_z
788 if (self.punchangle != '0 0 0')
790 f = vlen(self.punchangle) - 10 * frametime;
792 self.punchangle = normalize(self.punchangle) * f;
794 self.punchangle = '0 0 0';
797 if (self.punchvector != '0 0 0')
799 f = vlen(self.punchvector) - 30 * frametime;
801 self.punchvector = normalize(self.punchvector) * f;
803 self.punchvector = '0 0 0';
806 if (clienttype(self) == CLIENTTYPE_BOT)
808 if(playerdemo_read())
813 MUTATOR_CALLHOOK(PlayerPhysics);
815 self.items &~= IT_USING_JETPACK;
817 if(self.classname == "player")
819 if(self.race_penalty)
820 if(time > self.race_penalty)
821 self.race_penalty = 0;
823 not_allowed_to_move = 0;
824 if(self.race_penalty)
825 not_allowed_to_move = 1;
826 if(!cvar("sv_ready_restart_after_countdown"))
827 if(time < game_starttime)
828 not_allowed_to_move = 1;
830 if(not_allowed_to_move)
832 self.velocity = '0 0 0';
833 self.movetype = MOVETYPE_NONE;
834 self.disableclientprediction = 2;
836 else if(self.disableclientprediction == 2)
838 if(self.movetype == MOVETYPE_NONE)
839 self.movetype = MOVETYPE_WALK;
840 self.disableclientprediction = 0;
844 if (self.movetype == MOVETYPE_NONE)
851 if(self.runes & RUNE_SPEED)
853 if(self.runes & CURSE_SLOW)
854 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
856 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
858 else if(self.runes & CURSE_SLOW)
860 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
864 if(g_minstagib && (self.items & IT_INVINCIBLE))
866 maxspd_mod = cvar("g_minstagib_speed_moverate");
869 if(g_nexball && self.ballcarried)
871 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
876 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
879 if(self.classname != "player")
881 maxspd_mod = cvar("sv_spectator_speed_multiplier");
882 if(!self.spectatorspeed)
883 self.spectatorspeed = maxspd_mod;
884 if(self.impulse && self.impulse <= 19)
886 if(self.lastclassname != "player")
888 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
889 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
890 else if(self.impulse == 11)
891 self.spectatorspeed = maxspd_mod;
892 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
893 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
894 else if(self.impulse >= 1 && self.impulse <= 9)
895 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
896 } // otherwise just clear
899 maxspd_mod = self.spectatorspeed;
902 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
903 if(self.speed != spd)
907 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
908 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
909 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
910 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
913 maxspd_mod *= swampspd_mod; // only one common speed modder please!
916 // if dead, behave differently
920 if (!self.fixangle && !g_bugrigs)
923 self.angles_y = self.v_angle_y;
927 if(self.flags & FL_ONGROUND)
932 if(self.waterlevel < WATERLEVEL_SWIMMING)
933 if(time >= self.ladder_time)
936 self.nextstep = time + 0.3 + random() * 0.1;
937 trace_dphitq3surfaceflags = 0;
938 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
939 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
941 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
942 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
944 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
952 if(self.classname == "player")
954 if(self.flags & FL_ONGROUND)
956 if (cvar("g_multijump") > 0)
957 self.multijump_count = 0;
959 self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller
962 if (self.BUTTON_JUMP)
965 self.flags |= FL_JUMPRELEASED;
967 if (self.waterlevel == WATERLEVEL_SWIMMING)
969 self.prevjumpbutton = self.BUTTON_JUMP;
972 if (self.flags & FL_WATERJUMP )
974 self.velocity_x = self.movedir_x;
975 self.velocity_y = self.movedir_y;
976 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
978 self.flags &~= FL_WATERJUMP;
979 self.teleport_time = 0;
982 else if (g_bugrigs && self.classname == "player")
986 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
988 // noclipping or flying
989 self.flags &~= FL_ONGROUND;
991 self.velocity = self.velocity * (1 - frametime * sv_friction);
992 makevectors(self.v_angle);
993 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
994 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
996 wishdir = normalize(wishvel);
997 wishspeed = vlen(wishvel);
998 if (wishspeed > sv_maxspeed*maxspd_mod)
999 wishspeed = sv_maxspeed*maxspd_mod;
1000 if (time >= self.teleport_time)
1001 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0, 0);
1003 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
1006 self.flags &~= FL_ONGROUND;
1008 makevectors(self.v_angle);
1009 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
1010 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
1011 if (wishvel == '0 0 0')
1012 wishvel = '0 0 -60'; // drift towards bottom
1014 wishdir = normalize(wishvel);
1015 wishspeed = vlen(wishvel);
1016 if (wishspeed > sv_maxspeed*maxspd_mod)
1017 wishspeed = sv_maxspeed*maxspd_mod;
1018 wishspeed = wishspeed * 0.7;
1021 self.velocity = self.velocity * (1 - frametime * sv_friction);
1023 // water acceleration
1024 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0, 0);
1026 else if (time < self.ladder_time)
1028 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
1029 self.flags &~= FL_ONGROUND;
1031 self.velocity = self.velocity * (1 - frametime * sv_friction);
1032 makevectors(self.v_angle);
1033 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
1034 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
1036 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
1038 self.velocity_z = self.velocity_z + sv_gravity * frametime;
1039 if (self.ladder_entity.classname == "func_water")
1042 if (f > self.ladder_entity.speed)
1043 wishvel = wishvel * (self.ladder_entity.speed / f);
1045 self.watertype = self.ladder_entity.skin;
1046 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1047 if ((self.origin_z + self.view_ofs_z) < f)
1048 self.waterlevel = WATERLEVEL_SUBMERGED;
1049 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1050 self.waterlevel = WATERLEVEL_SWIMMING;
1051 else if ((self.origin_z + self.mins_z + 1) < f)
1052 self.waterlevel = WATERLEVEL_WETFEET;
1055 self.waterlevel = WATERLEVEL_NONE;
1056 self.watertype = CONTENT_EMPTY;
1060 wishdir = normalize(wishvel);
1061 wishspeed = vlen(wishvel);
1062 if (wishspeed > sv_maxspeed*maxspd_mod)
1063 wishspeed = sv_maxspeed*maxspd_mod;
1064 if (time >= self.teleport_time)
1066 // water acceleration
1067 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0, 0);
1070 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
1072 //makevectors(self.v_angle_y * '0 1 0');
1073 makevectors(self.v_angle);
1074 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1075 // add remaining speed as Z component
1076 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
1077 // fix speedhacks :P
1078 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
1079 // add the unused velocity as up component
1082 // if(self.BUTTON_JUMP)
1083 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1085 // it is now normalized, so...
1086 float a_side, a_up, a_add, a_diff;
1087 a_side = cvar("g_jetpack_acceleration_side");
1088 a_up = cvar("g_jetpack_acceleration_up");
1089 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
1091 wishvel_x *= a_side;
1092 wishvel_y *= a_side;
1098 //////////////////////////////////////////////////////////////////////////////////////
1099 // finding the maximum over all vectors of above form
1100 // with wishvel having an absolute value of 1
1101 //////////////////////////////////////////////////////////////////////////////////////
1102 // we're finding the maximum over
1103 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1104 // for z in the range from -1 to 1
1105 //////////////////////////////////////////////////////////////////////////////////////
1106 // maximum is EITHER attained at the single extreme point:
1107 a_diff = a_side * a_side - a_up * a_up;
1110 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1111 if(f > -1 && f < 1) // can it be attained?
1113 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1114 //print("middle\n");
1117 // OR attained at z = 1:
1118 f = (a_up + a_add) * (a_up + a_add);
1124 // OR attained at z = -1:
1125 f = (a_up - a_add) * (a_up - a_add);
1129 //print("bottom\n");
1132 //////////////////////////////////////////////////////////////////////////////////////
1134 //print("best possible acceleration: ", ftos(best), "\n");
1137 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
1138 if(wishvel_z - sv_gravity > 0)
1139 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1141 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1144 fvel = vlen(wishvel);
1147 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
1149 fvel = min(1, vlen(wishvel) / best);
1150 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1151 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
1155 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1157 if (f > 0 && wishvel != '0 0 0')
1159 self.velocity = self.velocity + wishvel * f * frametime;
1160 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1161 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
1162 self.flags &~= FL_ONGROUND;
1163 self.items |= IT_USING_JETPACK;
1165 // jetpack also inhibits health regeneration, but only for 1 second
1166 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1169 else if (self.flags & FL_ONGROUND)
1171 // we get here if we ran out of ammo
1172 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1173 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1176 makevectors(self.v_angle_y * '0 1 0');
1177 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1179 if(!(self.lastflags & FL_ONGROUND))
1181 if(cvar("speedmeter"))
1182 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1183 if(self.lastground < time - 0.3)
1184 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1185 if(self.jumppadcount > 1)
1186 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1187 self.jumppadcount = 0;
1190 #ifdef LETS_TEST_FTEQCC
1191 if(self.velocity_x || self.velocity_y)
1209 if (f < sv_stopspeed)
1210 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
1212 f = 1 - frametime * sv_friction;
1214 self.velocity = self.velocity * f;
1216 self.velocity = '0 0 0';
1220 wishdir = normalize(wishvel);
1221 wishspeed = vlen(wishvel);
1222 if (wishspeed > sv_maxspeed*maxspd_mod)
1223 wishspeed = sv_maxspeed*maxspd_mod;
1225 wishspeed = wishspeed * 0.5;
1226 if (time >= self.teleport_time)
1227 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0, 0);
1232 // we get here if we ran out of ammo
1233 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1234 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1238 maxairspd = sv_maxairspeed*maxspd_mod;
1239 airaccel = sv_airaccelerate*maxspd_mod;
1243 maxairspd = sv_maxairspeed;
1244 airaccel = sv_airaccelerate;
1247 makevectors(self.v_angle_y * '0 1 0');
1248 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1250 wishdir = normalize(wishvel);
1251 wishspeed = wishspeed0 = vlen(wishvel);
1252 if (wishspeed0 > sv_maxspeed*maxspd_mod)
1253 wishspeed0 = sv_maxspeed*maxspd_mod;
1254 if (wishspeed > maxairspd)
1255 wishspeed = maxairspd;
1257 wishspeed = wishspeed * 0.5;
1258 if (time >= self.teleport_time)
1265 airaccelqw = self.stat_sv_airaccel_qw;
1266 accelerating = (self.velocity * wishdir > 0);
1267 wishspeed2 = wishspeed;
1270 if(sv_airstopaccelerate)
1273 curdir = self.velocity;
1275 curdir = normalize(curdir);
1276 airaccel = airaccel + (sv_airstopaccelerate*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1278 // note that for straight forward jumping:
1279 // step = accel * frametime * wishspeed0;
1280 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1282 // dv/dt = accel * maxspeed (when slow)
1283 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1284 // log dv/dt = logaccel + logmaxspeed (when slow)
1285 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1286 strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
1287 if(sv_maxairstrafespeed)
1288 wishspeed = min(wishspeed, GeomLerp(sv_maxairspeed*maxspd_mod, strafity, sv_maxairstrafespeed*maxspd_mod));
1289 if(sv_airstrafeaccelerate)
1290 airaccel = GeomLerp(airaccel, strafity, sv_airstrafeaccelerate*maxspd_mod);
1291 if(self.stat_sv_airstrafeaccel_qw)
1292 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));
1295 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1296 PM_AirAccelerate(wishdir, wishspeed);
1298 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw);
1301 CPM_PM_Aircontrol(wishdir, wishspeed2);
1305 if((g_cts || g_race) && self.classname != "observer") {
1306 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1307 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1308 speedaward_holder = self.netname;
1309 speedaward_lastupdate = time;
1311 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1317 race_send_speedaward(MSG_ALL);
1318 speedaward_lastsent = speedaward_speed;
1319 if (speedaward_speed > speedaward_alltimebest) {
1320 speedaward_alltimebest = speedaward_speed;
1321 speedaward_alltimebest_holder = speedaward_holder;
1322 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1323 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"), speedaward_alltimebest_holder);
1324 race_send_speedaward_alltimebest(MSG_ALL);
1330 xyspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y);
1331 if(self.weapon == WEP_NEX && cvar("g_balance_nex_charge") && cvar("g_balance_nex_charge_velocity_rate") && xyspeed > cvar("g_balance_nex_charge_minspeed"))
1333 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1334 xyspeed = min(xyspeed, cvar("g_balance_nex_charge_maxspeed"));
1335 f = (xyspeed - cvar("g_balance_nex_charge_minspeed")) / (cvar("g_balance_nex_charge_maxspeed") - cvar("g_balance_nex_charge_minspeed"));
1336 // add the extra charge
1337 self.nex_charge = min(1, self.nex_charge + cvar("g_balance_nex_charge_velocity_rate") * f * frametime);
1340 if(self.flags & FL_ONGROUND)
1341 self.lastground = time;
1343 self.lastflags = self.flags;
1344 self.lastclassname = self.classname;