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;
26 .entity ladder_entity;
28 .float swamp_slowdown;
32 .float spectatorspeed;
38 When you press the jump key
41 void PlayerJump (void)
45 mjumpheight = cvar("sv_jumpvelocity");
46 if (self.waterlevel >= WATERLEVEL_SWIMMING)
48 if (self.watertype == CONTENT_WATER)
49 self.velocity_z = 200;
50 else if (self.watertype == CONTENT_SLIME)
58 if (!(self.flags & FL_ONGROUND))
62 if (!(self.flags & FL_JUMPRELEASED))
65 if(self.health <= g_bloodloss)
70 if(self.runes & RUNE_SPEED)
72 if(self.runes & CURSE_SLOW)
73 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
75 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
77 else if(self.runes & CURSE_SLOW)
79 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
83 if(g_minstagib && (self.items & IT_INVINCIBLE))
85 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
88 if(cvar_string("sv_jumpspeedcap_min") != "")
89 self.velocity_z = max(cvar("sv_jumpvelocity") * cvar("sv_jumpspeedcap_min"), self.velocity_z);
90 if(cvar_string("sv_jumpspeedcap_max") != "") {
91 if(trace_fraction < 1 && trace_plane_normal_z < 0.98 && cvar("sv_jumpspeedcap_max_disable_on_ramps")) {
92 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
93 //print("Trace plane normal z: ", ftos(trace_plane_normal_z), ", disabling speed cap!\n");
96 self.velocity_z = min(cvar("sv_jumpvelocity") * cvar("sv_jumpspeedcap_max"), self.velocity_z) + trace_ent.velocity_z;
99 if(!(self.lastflags & FL_ONGROUND))
101 if(cvar("speedmeter"))
102 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
103 if(self.lastground < time - 0.3)
105 self.velocity_x *= (1 - cvar("sv_friction_on_land"));
106 self.velocity_y *= (1 - cvar("sv_friction_on_land"));
108 if(self.jumppadcount > 1)
109 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
110 self.jumppadcount = 0;
113 self.velocity_z = self.velocity_z + mjumpheight;
114 self.oldvelocity_z = self.velocity_z;
116 self.flags &~= FL_ONGROUND;
117 self.flags &~= FL_JUMPRELEASED;
120 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
122 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
125 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
127 self.restart_jump = -1; // restart jump anim next time
128 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
131 void CheckWaterJump()
133 local vector start, end;
135 // check for a jump-out-of-water
136 makevectors (self.angles);
138 start_z = start_z + 8;
140 normalize(v_forward);
141 end = start + v_forward*24;
142 traceline (start, end, TRUE, self);
143 if (trace_fraction < 1)
145 start_z = start_z + self.maxs_z - 8;
146 end = start + v_forward*24;
147 self.movedir = trace_plane_normal * -50;
148 traceline (start, end, TRUE, self);
149 if (trace_fraction == 1)
150 { // open at eye level
151 self.flags |= FL_WATERJUMP;
152 self.velocity_z = 225;
153 self.flags &~= FL_JUMPRELEASED;
154 self.teleport_time = time + 2; // safety net
160 float racecar_angle(float forward, float down)
162 float ret, angle_mult;
170 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
172 angle_mult = forward / (800 + forward);
175 return ret * angle_mult + 360 * (1 - angle_mult);
177 return ret * angle_mult;
180 void RaceCarPhysics()
182 // using this move type for "big rigs"
183 // the engine does not push the entity!
185 float accel, steer, f;
186 vector angles_save, rigvel;
188 angles_save = self.angles;
189 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
190 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
192 if(g_bugrigs_reverse_speeding)
196 // back accel is DIGITAL
197 // to prevent speedhack
207 makevectors(self.angles); // new forward direction!
209 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
211 float myspeed, upspeed, steerfactor, accelfactor;
213 myspeed = self.velocity * v_forward;
214 upspeed = self.velocity * v_up;
216 // responsiveness factor for steering and acceleration
217 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
218 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
220 if(myspeed < 0 && g_bugrigs_reverse_spinning)
221 steerfactor = -myspeed * g_bugrigs_steer;
223 steerfactor = -myspeed * f * g_bugrigs_steer;
225 if(myspeed < 0 && g_bugrigs_reverse_speeding)
226 accelfactor = g_bugrigs_accel;
228 accelfactor = f * g_bugrigs_accel;
229 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
235 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
239 if(!g_bugrigs_reverse_speeding)
240 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
247 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
251 if(g_bugrigs_reverse_stopping)
254 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
257 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
258 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
260 self.angles_y += steer * frametime * steerfactor; // apply steering
261 makevectors(self.angles); // new forward direction!
263 myspeed += accel * accelfactor * frametime;
265 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
269 myspeed = vlen(self.velocity);
271 // responsiveness factor for steering and acceleration
272 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
273 steerfactor = -myspeed * f;
274 self.angles_y += steer * frametime * steerfactor; // apply steering
276 rigvel = self.velocity;
277 makevectors(self.angles); // new forward direction!
280 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
281 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
282 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
283 //MAXIMA: solve(total_acceleration(v) = 0, v);
285 if(g_bugrigs_planar_movement)
287 vector rigvel_xy, neworigin, up;
290 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
294 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
297 mt = MOVE_NOMONSTERS;
299 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
300 up = trace_endpos - self.origin;
302 // BUG RIGS: align the move to the surface instead of doing collision testing
304 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
307 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
309 if(trace_fraction < 0.5)
312 neworigin = self.origin;
315 neworigin = trace_endpos;
317 if(trace_fraction < 1)
319 // now set angles_x so that the car points parallel to the surface
320 self.angles = vectoangles(
321 '1 0 0' * v_forward_x * trace_plane_normal_z
323 '0 1 0' * v_forward_y * trace_plane_normal_z
325 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
327 self.flags |= FL_ONGROUND;
331 // now set angles_x so that the car points forward, but is tilted in velocity direction
332 self.flags &~= FL_ONGROUND;
335 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
336 self.movetype = MOVETYPE_NOCLIP;
340 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
341 self.velocity = rigvel;
342 self.movetype = MOVETYPE_FLY;
346 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
347 if(trace_fraction != 1)
349 self.angles = vectoangles2(
350 '1 0 0' * v_forward_x * trace_plane_normal_z
352 '0 1 0' * v_forward_y * trace_plane_normal_z
354 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
362 vel_local_x = v_forward * self.velocity;
363 vel_local_y = v_right * self.velocity;
364 vel_local_z = v_up * self.velocity;
366 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
367 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
371 vector vf1, vu1, smoothangles;
372 makevectors(self.angles);
373 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
378 makevectors(angles_save);
379 vf1 = vf1 + v_forward * (1 - f);
380 vu1 = vu1 + v_up * (1 - f);
381 smoothangles = vectoangles2(vf1, vu1);
382 self.angles_x = -smoothangles_x;
383 self.angles_z = smoothangles_z;
386 float IsMoveInDirection(vector mv, float angle) // key mix factor
388 if(mv_x == 0 && mv_y == 0)
389 return 0; // avoid division by zero
390 angle -= RAD2DEG * atan2(mv_y, mv_x);
391 angle = remainder(angle, 360) / 45;
396 return 1 - fabs(angle);
399 float GeomLerp(float a, float lerp, float b)
415 return a * pow(fabs(b / a), lerp);
418 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
420 float zspeed, xyspeed, dot, k;
423 // this doesn't play well with analog input
424 if(self.movement_x == 0 || self.movement_y != 0)
425 return; // can't control movement if not moving forward or backward
428 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
433 k *= bound(0, wishspeed / sv_maxairspeed, 1);
435 zspeed = self.velocity_z;
437 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
439 dot = self.velocity * wishdir;
441 if(dot > 0) // we can't change direction while slowing down
443 k *= fabs(sv_aircontrol)*pow(dot, sv_aircontrol_power)*frametime;
444 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
447 self.velocity = self.velocity * xyspeed;
448 self.velocity_z = zspeed;
451 // example config for alternate speed clamping:
452 // sv_airaccel_qw 0.8
453 // sv_airaccel_sideways_friction 0
454 // prvm_globalset server speedclamp_mode 1
456 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float sidefric)
464 float vel_xy_current;
465 float vel_xy_backward, vel_xy_forward;
468 speedclamp = (accelqw < 0);
472 if(cvar("sv_gameplayfix_q2airaccelerate"))
473 wishspeed0 = wishspeed;
475 vel_straight = self.velocity * wishdir;
476 vel_z = self.velocity_z;
477 vel_xy = self.velocity - vel_z * '0 0 1';
478 vel_perpend = vel_xy - vel_straight * wishdir;
480 step = accel * frametime * wishspeed0;
482 vel_xy_current = vlen(vel_xy);
483 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
484 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
485 if(vel_xy_backward < 0)
486 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
488 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
490 if(sidefric < 0 && (vel_perpend*vel_perpend))
491 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
494 f = max(0, 1 + frametime * wishspeed * sidefric);
495 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
496 // this cannot be > 1
498 vel_perpend = vel_perpend * max(0, f);
501 fminimum = sqrt(fminimum);
502 vel_perpend = vel_perpend * max(fminimum, f);
506 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
508 vel_xy = vel_straight * wishdir + vel_perpend;
512 // ensure we don't get too fast or decelerate faster than we should
513 vel_xy_current = min(vlen(vel_xy), vel_xy_forward);
514 if(vel_xy_current > 0) // prevent division by zero
515 vel_xy = normalize(vel_xy) * vel_xy_current;
518 self.velocity = vel_xy + vel_z * '0 0 1';
521 void PM_AirAccelerate(vector wishdir, float wishspeed)
523 vector curvel, wishvel, acceldir, curdir;
524 float addspeed, accelspeed, curspeed, f;
530 curvel = self.velocity;
532 curspeed = vlen(curvel);
534 if(wishspeed > curspeed * 1.01)
536 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
540 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
541 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
543 wishvel = wishdir * wishspeed;
544 acceldir = wishvel - curvel;
545 addspeed = vlen(acceldir);
546 acceldir = normalize(acceldir);
548 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
550 if(sv_warsowbunny_backtosideratio < 1)
552 curdir = normalize(curvel);
553 dot = acceldir * curdir;
555 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
558 self.velocity += accelspeed * acceldir;
561 .vector movement_old;
564 .string lastclassname;
566 .float() PlayerPhysplug;
568 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
569 .float specialcommand_pos;
570 void SpecialCommand()
575 if(!CheatImpulse(99))
576 print("A hollow voice says \"Plugh\".\n");
580 float speedaward_speed;
581 string speedaward_holder;
582 void race_send_speedaward(float msg)
584 // send the best speed of the round
585 WriteByte(msg, SVC_TEMPENTITY);
586 WriteByte(msg, TE_CSQC_RACE);
587 WriteByte(msg, RACE_NET_SPEED_AWARD);
588 WriteInt24_t(msg, floor(speedaward_speed+0.5));
589 WriteString(msg, speedaward_holder);
592 float speedaward_alltimebest;
593 string speedaward_alltimebest_holder;
594 void race_send_speedaward_alltimebest(float msg)
596 // send the best speed
597 WriteByte(msg, SVC_TEMPENTITY);
598 WriteByte(msg, TE_CSQC_RACE);
599 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
600 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
601 WriteString(msg, speedaward_alltimebest_holder);
604 string GetMapname(void);
605 float speedaward_lastupdate;
606 float speedaward_lastsent;
607 .float jumppadusetime;
608 void SV_PlayerPhysics()
610 local vector wishvel, wishdir, v;
611 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
614 float not_allowed_to_move;
617 if(self.PlayerPhysplug)
618 if(self.PlayerPhysplug())
621 self.race_movetime_frac += frametime;
622 f = floor(self.race_movetime_frac);
623 self.race_movetime_frac -= f;
624 self.race_movetime_count += f;
625 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
629 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);
633 else if(buttons == 1)
635 else if(buttons == 2)
637 else if(buttons == 128)
639 else if(buttons == 256)
641 else if(buttons == 512)
643 else if(buttons == 1024)
648 if(c == substring(specialcommand, self.specialcommand_pos, 1))
650 self.specialcommand_pos += 1;
651 if(self.specialcommand_pos >= strlen(specialcommand))
653 self.specialcommand_pos = 0;
658 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
659 self.specialcommand_pos = 0;
661 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
663 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
664 self.parm_idlesince = time;
666 buttons_prev = self.buttons_old;
667 self.buttons_old = buttons;
668 self.movement_old = self.movement;
669 self.v_angle_old = self.v_angle;
671 if(time < self.nickspamtime)
672 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
674 // slight annoyance for nick change scripts
675 self.movement = -1 * self.movement;
676 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
678 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!
680 self.angles_x = random() * 360;
681 self.angles_y = random() * 360;
682 // at least I'm not forcing retardedview by also assigning to angles_z
687 if (self.punchangle != '0 0 0')
689 f = vlen(self.punchangle) - 10 * frametime;
691 self.punchangle = normalize(self.punchangle) * f;
693 self.punchangle = '0 0 0';
696 if (self.punchvector != '0 0 0')
698 f = vlen(self.punchvector) - 30 * frametime;
700 self.punchvector = normalize(self.punchvector) * f;
702 self.punchvector = '0 0 0';
705 if (clienttype(self) == CLIENTTYPE_BOT)
707 if(playerdemo_read())
712 MUTATOR_CALLHOOK(PlayerPhysics);
714 self.items &~= IT_USING_JETPACK;
716 if(self.classname == "player")
718 if(self.race_penalty)
719 if(time > self.race_penalty)
720 self.race_penalty = 0;
722 not_allowed_to_move = 0;
723 if(self.race_penalty)
724 not_allowed_to_move = 1;
725 if(!cvar("sv_ready_restart_after_countdown"))
726 if(time < game_starttime)
727 not_allowed_to_move = 1;
729 if(not_allowed_to_move)
731 self.velocity = '0 0 0';
732 self.movetype = MOVETYPE_NONE;
733 self.disableclientprediction = 2;
735 else if(self.disableclientprediction == 2)
737 if(self.movetype == MOVETYPE_NONE)
738 self.movetype = MOVETYPE_WALK;
739 self.disableclientprediction = 0;
743 if (self.movetype == MOVETYPE_NONE)
750 if(self.runes & RUNE_SPEED)
752 if(self.runes & CURSE_SLOW)
753 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
755 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
757 else if(self.runes & CURSE_SLOW)
759 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
763 if(g_minstagib && (self.items & IT_INVINCIBLE))
765 maxspd_mod = cvar("g_minstagib_speed_moverate");
768 if(g_nexball && self.ballcarried)
770 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
775 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
778 if(self.classname != "player")
780 maxspd_mod = cvar("sv_spectator_speed_multiplier");
781 if(!self.spectatorspeed)
782 self.spectatorspeed = maxspd_mod;
783 if(self.impulse && self.impulse <= 19)
785 if(self.lastclassname != "player")
787 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
788 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
789 else if(self.impulse == 11)
790 self.spectatorspeed = maxspd_mod;
791 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
792 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
793 else if(self.impulse >= 1 && self.impulse <= 9)
794 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
795 } // otherwise just clear
798 maxspd_mod = self.spectatorspeed;
801 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
802 if(self.speed != spd)
806 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
807 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
808 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
809 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
812 maxspd_mod *= swampspd_mod; // only one common speed modder please!
815 // if dead, behave differently
819 if (!self.fixangle && !g_bugrigs)
822 self.angles_y = self.v_angle_y;
826 if(self.flags & FL_ONGROUND)
831 if(self.waterlevel < WATERLEVEL_SWIMMING)
832 if(time >= self.ladder_time)
835 self.nextstep = time + 0.3 + random() * 0.1;
836 trace_dphitq3surfaceflags = 0;
837 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
838 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
840 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
841 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
843 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
851 if(self.classname == "player")
853 if(sv_doublejump && time - self.jumppadusetime > 2 * sys_frametime)
855 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
856 self.flags &~= FL_ONGROUND;
857 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
858 self.flags |= FL_ONGROUND;
861 if (self.BUTTON_JUMP)
864 self.flags |= FL_JUMPRELEASED;
866 if (self.waterlevel == WATERLEVEL_SWIMMING)
870 if (self.flags & FL_WATERJUMP )
872 self.velocity_x = self.movedir_x;
873 self.velocity_y = self.movedir_y;
874 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
876 self.flags &~= FL_WATERJUMP;
877 self.teleport_time = 0;
880 else if (g_bugrigs && self.classname == "player")
884 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
886 // noclipping or flying
887 self.flags &~= FL_ONGROUND;
889 self.velocity = self.velocity * (1 - frametime * sv_friction);
890 makevectors(self.v_angle);
891 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
892 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
894 wishdir = normalize(wishvel);
895 wishspeed = vlen(wishvel);
896 if (wishspeed > sv_maxspeed*maxspd_mod)
897 wishspeed = sv_maxspeed*maxspd_mod;
898 if (time >= self.teleport_time)
899 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
901 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
904 self.flags &~= FL_ONGROUND;
906 makevectors(self.v_angle);
907 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
908 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
909 if (wishvel == '0 0 0')
910 wishvel = '0 0 -60'; // drift towards bottom
912 wishdir = normalize(wishvel);
913 wishspeed = vlen(wishvel);
914 if (wishspeed > sv_maxspeed*maxspd_mod)
915 wishspeed = sv_maxspeed*maxspd_mod;
916 wishspeed = wishspeed * 0.7;
919 self.velocity = self.velocity * (1 - frametime * sv_friction);
921 // water acceleration
922 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
924 else if (time < self.ladder_time)
926 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
927 self.flags &~= FL_ONGROUND;
929 self.velocity = self.velocity * (1 - frametime * sv_friction);
930 makevectors(self.v_angle);
931 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
932 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
934 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
936 self.velocity_z = self.velocity_z + sv_gravity * frametime;
937 if (self.ladder_entity.classname == "func_water")
940 if (f > self.ladder_entity.speed)
941 wishvel = wishvel * (self.ladder_entity.speed / f);
943 self.watertype = self.ladder_entity.skin;
944 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
945 if ((self.origin_z + self.view_ofs_z) < f)
946 self.waterlevel = WATERLEVEL_SUBMERGED;
947 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
948 self.waterlevel = WATERLEVEL_SWIMMING;
949 else if ((self.origin_z + self.mins_z + 1) < f)
950 self.waterlevel = WATERLEVEL_WETFEET;
953 self.waterlevel = WATERLEVEL_NONE;
954 self.watertype = CONTENT_EMPTY;
958 wishdir = normalize(wishvel);
959 wishspeed = vlen(wishvel);
960 if (wishspeed > sv_maxspeed*maxspd_mod)
961 wishspeed = sv_maxspeed*maxspd_mod;
962 if (time >= self.teleport_time)
964 // water acceleration
965 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
968 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
970 //makevectors(self.v_angle_y * '0 1 0');
971 makevectors(self.v_angle);
972 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
973 // add remaining speed as Z component
974 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
976 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
977 // add the unused velocity as up component
980 // if(self.BUTTON_JUMP)
981 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
983 // it is now normalized, so...
984 float a_side, a_up, a_add, a_diff;
985 a_side = cvar("g_jetpack_acceleration_side");
986 a_up = cvar("g_jetpack_acceleration_up");
987 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
996 //////////////////////////////////////////////////////////////////////////////////////
997 // finding the maximum over all vectors of above form
998 // with wishvel having an absolute value of 1
999 //////////////////////////////////////////////////////////////////////////////////////
1000 // we're finding the maximum over
1001 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1002 // for z in the range from -1 to 1
1003 //////////////////////////////////////////////////////////////////////////////////////
1004 // maximum is EITHER attained at the single extreme point:
1005 a_diff = a_side * a_side - a_up * a_up;
1008 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1009 if(f > -1 && f < 1) // can it be attained?
1011 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1012 //print("middle\n");
1015 // OR attained at z = 1:
1016 f = (a_up + a_add) * (a_up + a_add);
1022 // OR attained at z = -1:
1023 f = (a_up - a_add) * (a_up - a_add);
1027 //print("bottom\n");
1030 //////////////////////////////////////////////////////////////////////////////////////
1032 //print("best possible acceleration: ", ftos(best), "\n");
1035 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
1036 if(wishvel_z - sv_gravity > 0)
1037 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1039 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1042 fvel = vlen(wishvel);
1045 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
1047 fvel = min(1, vlen(wishvel) / best);
1048 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1049 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
1053 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1055 if (f > 0 && wishvel != '0 0 0')
1057 self.velocity = self.velocity + wishvel * f * frametime;
1058 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1059 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
1060 self.flags &~= FL_ONGROUND;
1061 self.items |= IT_USING_JETPACK;
1063 // jetpack also inhibits health regeneration, but only for 1 second
1064 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1067 else if (self.flags & FL_ONGROUND)
1069 // we get here if we ran out of ammo
1070 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1071 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1074 makevectors(self.v_angle_y * '0 1 0');
1075 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1077 if(!(self.lastflags & FL_ONGROUND))
1079 if(cvar("speedmeter"))
1080 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1081 if(self.lastground < time - 0.3)
1082 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1083 if(self.jumppadcount > 1)
1084 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1085 self.jumppadcount = 0;
1088 #ifdef LETS_TEST_FTEQCC
1089 if(self.velocity_x || self.velocity_y)
1107 if (f < sv_stopspeed)
1108 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
1110 f = 1 - frametime * sv_friction;
1112 self.velocity = self.velocity * f;
1114 self.velocity = '0 0 0';
1118 wishdir = normalize(wishvel);
1119 wishspeed = vlen(wishvel);
1120 if (wishspeed > sv_maxspeed*maxspd_mod)
1121 wishspeed = sv_maxspeed*maxspd_mod;
1123 wishspeed = wishspeed * 0.5;
1124 if (time >= self.teleport_time)
1125 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
1130 // we get here if we ran out of ammo
1131 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1132 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1136 maxairspd = sv_maxairspeed*maxspd_mod;
1137 airaccel = sv_airaccelerate*maxspd_mod;
1141 maxairspd = sv_maxairspeed;
1142 airaccel = sv_airaccelerate;
1145 makevectors(self.v_angle_y * '0 1 0');
1146 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1148 wishdir = normalize(wishvel);
1149 wishspeed = wishspeed0 = vlen(wishvel);
1150 if (wishspeed0 > sv_maxspeed*maxspd_mod)
1151 wishspeed0 = sv_maxspeed*maxspd_mod;
1152 if (wishspeed > maxairspd)
1153 wishspeed = maxairspd;
1155 wishspeed = wishspeed * 0.5;
1156 if (time >= self.teleport_time)
1163 airaccelqw = sv_airaccel_qw;
1164 accelerating = (self.velocity * wishdir > 0);
1165 wishspeed2 = wishspeed;
1168 if(sv_airstopaccelerate)
1169 if(self.velocity * wishdir < 0)
1170 airaccel = sv_airstopaccelerate*maxspd_mod;
1171 // this doesn't play well with analog input, but can't r
1172 // fixed like the AirControl can. So, don't set the maxa
1173 // cvars when you want to support analog input.
1174 // note that for straight forward jumping:
1175 // step = accel * frametime * wishspeed0;
1176 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1178 // dv/dt = accel * maxspeed (when slow)
1179 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1180 // log dv/dt = logaccel + logmaxspeed (when slow)
1181 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1182 strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
1183 if(sv_maxairstrafespeed)
1184 wishspeed = min(wishspeed, GeomLerp(sv_maxairspeed*maxspd_mod, strafity, sv_maxairstrafespeed*maxspd_mod));
1185 if(sv_airstrafeaccelerate)
1186 airaccel = GeomLerp(airaccel, strafity, sv_airstrafeaccelerate*maxspd_mod);
1187 if(sv_airstrafeaccel_qw)
1188 airaccelqw = sign((strafity > 0.5) ? sv_airstrafeaccel_qw : sv_airaccel_qw) * (1-GeomLerp(1-fabs(sv_airaccel_qw), strafity, 1-fabs(sv_airstrafeaccel_qw)));
1191 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1192 PM_AirAccelerate(wishdir, wishspeed);
1194 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd);
1197 CPM_PM_Aircontrol(wishdir, wishspeed2);
1201 if((g_cts || g_race) && self.classname != "observer") {
1202 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1203 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1204 speedaward_holder = self.netname;
1205 speedaward_lastupdate = time;
1207 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1213 race_send_speedaward(MSG_ALL);
1214 speedaward_lastsent = speedaward_speed;
1215 if (speedaward_speed > speedaward_alltimebest) {
1216 speedaward_alltimebest = speedaward_speed;
1217 speedaward_alltimebest_holder = speedaward_holder;
1218 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1219 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"), speedaward_alltimebest_holder);
1220 race_send_speedaward_alltimebest(MSG_ALL);
1225 if(self.flags & FL_ONGROUND)
1226 self.lastground = time;
1228 self.lastflags = self.flags;
1229 self.lastclassname = self.classname;