4 float sv_airaccelerate;
8 float sv_airaccel_sideways_friction;
10 float sv_airstopaccelerate;
11 float sv_airstrafeaccelerate;
12 float sv_maxairstrafespeed;
14 float sv_warsowbunny_airforwardaccel;
15 float sv_warsowbunny_accel;
16 float sv_warsowbunny_topspeed;
17 float sv_warsowbunny_turnaccel;
18 float sv_warsowbunny_backtosideratio;
21 .entity ladder_entity;
23 .float swamp_slowdown;
27 .float spectatorspeed;
29 #define SHTEST_DELTA 10
30 #define SHTEST_THRESHOLD 1.1
32 .float shtest_accumulator;
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)
59 if (!(self.flags & FL_ONGROUND))
63 if (!(self.flags & FL_JUMPRELEASED))
66 if(self.health <= g_bloodloss)
71 if(self.runes & RUNE_SPEED)
73 if(self.runes & CURSE_SLOW)
74 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
76 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
78 else if(self.runes & CURSE_SLOW)
80 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
84 if(g_minstagib && (self.items & IT_INVINCIBLE))
86 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
89 self.velocity_z = self.velocity_z + mjumpheight;
90 self.oldvelocity_z = self.velocity_z;
92 self.flags &~= FL_ONGROUND;
93 self.flags &~= FL_JUMPRELEASED;
96 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
98 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
101 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
104 void CheckWaterJump()
106 local vector start, end;
108 // check for a jump-out-of-water
109 makevectors (self.angles);
111 start_z = start_z + 8;
113 normalize(v_forward);
114 end = start + v_forward*24;
115 traceline (start, end, TRUE, self);
116 if (trace_fraction < 1)
118 start_z = start_z + self.maxs_z - 8;
119 end = start + v_forward*24;
120 self.movedir = trace_plane_normal * -50;
121 traceline (start, end, TRUE, self);
122 if (trace_fraction == 1)
123 { // open at eye level
124 self.flags |= FL_WATERJUMP;
125 self.velocity_z = 225;
126 self.flags &~= FL_JUMPRELEASED;
127 self.teleport_time = time + 2; // safety net
133 float racecar_angle(float forward, float down)
135 float ret, angle_mult;
143 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
145 angle_mult = forward / (800 + forward);
148 return ret * angle_mult + 360 * (1 - angle_mult);
150 return ret * angle_mult;
153 void RaceCarPhysics()
155 // using this move type for "big rigs"
156 // the engine does not push the entity!
158 float accel, steer, f;
159 vector angles_save, rigvel;
161 angles_save = self.angles;
162 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
163 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
165 if(g_bugrigs_reverse_speeding)
169 // back accel is DIGITAL
170 // to prevent speedhack
180 makevectors(self.angles); // new forward direction!
182 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
184 float myspeed, upspeed, steerfactor, accelfactor;
186 myspeed = self.velocity * v_forward;
187 upspeed = self.velocity * v_up;
189 // responsiveness factor for steering and acceleration
190 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
191 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
193 if(myspeed < 0 && g_bugrigs_reverse_spinning)
194 steerfactor = -myspeed * g_bugrigs_steer;
196 steerfactor = -myspeed * f * g_bugrigs_steer;
198 if(myspeed < 0 && g_bugrigs_reverse_speeding)
199 accelfactor = g_bugrigs_accel;
201 accelfactor = f * g_bugrigs_accel;
202 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
208 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
212 if(!g_bugrigs_reverse_speeding)
213 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
220 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
224 if(g_bugrigs_reverse_stopping)
227 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
230 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
231 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
233 self.angles_y += steer * frametime * steerfactor; // apply steering
234 makevectors(self.angles); // new forward direction!
236 myspeed += accel * accelfactor * frametime;
238 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
242 myspeed = vlen(self.velocity);
244 // responsiveness factor for steering and acceleration
245 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
246 steerfactor = -myspeed * f;
247 self.angles_y += steer * frametime * steerfactor; // apply steering
249 rigvel = self.velocity;
250 makevectors(self.angles); // new forward direction!
253 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
254 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
255 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
256 //MAXIMA: solve(total_acceleration(v) = 0, v);
258 if(g_bugrigs_planar_movement)
260 vector rigvel_xy, neworigin, up;
263 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
267 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
270 mt = MOVE_NOMONSTERS;
272 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
273 up = trace_endpos - self.origin;
275 // BUG RIGS: align the move to the surface instead of doing collision testing
277 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
280 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
282 if(trace_fraction < 0.5)
285 neworigin = self.origin;
288 neworigin = trace_endpos;
290 if(trace_fraction < 1)
292 // now set angles_x so that the car points parallel to the surface
293 self.angles = vectoangles(
294 '1 0 0' * v_forward_x * trace_plane_normal_z
296 '0 1 0' * v_forward_y * trace_plane_normal_z
298 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
300 self.flags |= FL_ONGROUND;
304 // now set angles_x so that the car points forward, but is tilted in velocity direction
305 self.flags &~= FL_ONGROUND;
308 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
309 self.movetype = MOVETYPE_NOCLIP;
313 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
314 self.velocity = rigvel;
315 self.movetype = MOVETYPE_FLY;
319 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
320 if(trace_fraction != 1)
322 self.angles = vectoangles2(
323 '1 0 0' * v_forward_x * trace_plane_normal_z
325 '0 1 0' * v_forward_y * trace_plane_normal_z
327 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
335 vel_local_x = v_forward * self.velocity;
336 vel_local_y = v_right * self.velocity;
337 vel_local_z = v_up * self.velocity;
339 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
340 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
344 vector vf1, vu1, smoothangles;
345 makevectors(self.angles);
346 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
351 makevectors(angles_save);
352 vf1 = vf1 + v_forward * (1 - f);
353 vu1 = vu1 + v_up * (1 - f);
354 smoothangles = vectoangles2(vf1, vu1);
355 self.angles_x = -smoothangles_x;
356 self.angles_z = smoothangles_z;
359 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
361 float zspeed, xyspeed, dot, k;
363 if(self.movement_x == 0 || self.movement_y != 0)
364 return; // can't control movement if not moving forward or backward
366 zspeed = self.velocity_z;
368 xyspeed = vlen(self.velocity);
369 self.velocity = normalize(self.velocity);
371 dot = self.velocity * wishdir;
373 k *= sv_aircontrol*dot*dot*frametime;
375 if(dot > 0) // we can't change direction while slowing down
376 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
378 self.velocity = self.velocity * xyspeed;
379 self.velocity_z = zspeed;
382 void PM_Accelerate(vector wishdir, float wishspeed, float accel, float accelqw, float sidefric)
389 vel_straight = self.velocity * wishdir;
390 vel_z = self.velocity_z;
391 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
393 addspeed = wishspeed - vel_straight;
395 vel_straight = vel_straight + min(addspeed, accel * frametime * wishspeed) * accelqw;
397 vel_straight = vel_straight + min(wishspeed, accel * frametime * wishspeed) * (1 - accelqw);
399 vel_perpend = vel_perpend * (1 - frametime * wishspeed * sidefric);
401 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
404 void PM_AirAccelerate(vector wishdir, float wishspeed)
406 vector curvel, wishvel, acceldir, curdir;
407 float addspeed, accelspeed, curspeed, f;
413 curvel = self.velocity;
415 curspeed = vlen(curvel);
417 if(wishspeed > curspeed * 1.01)
419 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
423 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
424 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
426 wishvel = wishdir * wishspeed;
427 acceldir = wishvel - curvel;
428 addspeed = vlen(acceldir);
429 acceldir = normalize(acceldir);
431 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
433 if(sv_warsowbunny_backtosideratio < 1)
435 curdir = normalize(curvel);
436 dot = acceldir * curdir;
438 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
441 self.velocity += accelspeed * acceldir;
444 .vector movement_old;
447 .string lastclassname;
449 void Nixnex_GiveCurrentWeapon();
450 void SV_PlayerPhysics()
452 local vector wishvel, wishdir, v;
453 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, shtest_score, buttons;
457 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;
458 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
460 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
461 self.parm_idlesince = time;
463 buttons_prev = self.buttons_old;
464 self.buttons_old = buttons;
465 self.movement_old = self.movement;
466 self.v_angle_old = self.v_angle;
468 if(time < self.nickspamtime)
469 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
471 // slight annoyance for nick change scripts
472 self.movement = -1 * self.movement;
473 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
475 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!
477 self.angles_x = random() * 360;
478 self.angles_y = random() * 360;
479 // at least I'm not forcing retardedview by also assigning to angles_z
484 if(time > self.shtest_next)
486 if(self.shtest_next > 0)
488 // self.shtest_accumulator:
489 // started at time - SHTEST_DELTA
490 // should be at SHTEST_DELTA
491 shtest_score = self.shtest_accumulator / (SHTEST_DELTA + time - self.shtest_next);
492 if(shtest_score > SHTEST_THRESHOLD)
493 print("TIME PARADOX: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
494 else if(cvar("developer_shtest"))
495 dprint("okay: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
497 self.shtest_next = time + SHTEST_DELTA;
498 self.shtest_accumulator = 0;
500 self.shtest_accumulator += frametime;
502 if (clienttype(self) == CLIENTTYPE_BOT)
505 self.items &~= IT_USING_JETPACK;
507 if (self.movetype == MOVETYPE_NONE && self.disableclientprediction != 2)
510 if (self.punchangle != '0 0 0')
512 f = vlen(self.punchangle) - 10 * frametime;
514 self.punchangle = normalize(self.punchangle) * f;
516 self.punchangle = '0 0 0';
519 if (self.punchvector != '0 0 0')
521 f = vlen(self.punchvector) - 30 * frametime;
523 self.punchvector = normalize(self.punchvector) * f;
525 self.punchvector = '0 0 0';
532 if(self.runes & RUNE_SPEED)
534 if(self.runes & CURSE_SLOW)
535 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
537 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
539 else if(self.runes & CURSE_SLOW)
541 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
545 if(g_minstagib && (self.items & IT_INVINCIBLE))
547 maxspd_mod = cvar("g_minstagib_speed_moverate");
550 if(g_nexball && self.ballcarried)
552 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
557 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
560 if(self.classname != "player")
562 maxspd_mod = cvar("sv_spectator_speed_multiplier");
563 if(!self.spectatorspeed)
564 self.spectatorspeed = maxspd_mod;
565 if(self.impulse && self.impulse <= 19)
567 if(self.lastclassname != "player")
569 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
570 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
571 else if(self.impulse == 11)
572 self.spectatorspeed = maxspd_mod;
573 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
574 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
575 else if(self.impulse >= 1 && self.impulse <= 9)
576 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
577 } // otherwise just clear
580 maxspd_mod = self.spectatorspeed;
583 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
584 if(self.speed != spd)
588 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
589 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
590 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
591 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
594 maxspd_mod *= swampspd_mod; // only one common speed modder please!
597 // if dead, behave differently
601 if (!self.fixangle && !g_bugrigs)
604 self.angles_y = self.v_angle_y;
608 if(self.flags & FL_ONGROUND)
613 if(self.waterlevel < WATERLEVEL_SWIMMING)
614 if(time >= self.ladder_time)
617 self.nextstep = time + 0.3 + random() * 0.1;
618 trace_dphitq3surfaceflags = 0;
619 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
620 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
622 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
623 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
625 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
633 if(self.classname == "player")
637 self.flags &~= FL_ONGROUND;
638 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 2', MOVE_NORMAL, self);
639 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
640 self.flags |= FL_ONGROUND;
643 if (self.BUTTON_JUMP)
646 self.flags |= FL_JUMPRELEASED;
648 if (self.waterlevel == WATERLEVEL_SWIMMING)
652 if (self.flags & FL_WATERJUMP )
654 self.velocity_x = self.movedir_x;
655 self.velocity_y = self.movedir_y;
656 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
658 self.flags &~= FL_WATERJUMP;
659 self.teleport_time = 0;
662 else if (g_bugrigs && self.classname == "player")
666 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
668 // noclipping or flying
669 self.flags &~= FL_ONGROUND;
671 self.velocity = self.velocity * (1 - frametime * sv_friction);
672 makevectors(self.v_angle);
673 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
674 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
676 wishdir = normalize(wishvel);
677 wishspeed = vlen(wishvel);
678 if (wishspeed > sv_maxspeed*maxspd_mod)
679 wishspeed = sv_maxspeed*maxspd_mod;
680 if (time >= self.teleport_time)
681 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
683 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
686 self.flags &~= FL_ONGROUND;
688 makevectors(self.v_angle);
689 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
690 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
691 if (wishvel == '0 0 0')
692 wishvel = '0 0 -60'; // drift towards bottom
694 wishdir = normalize(wishvel);
695 wishspeed = vlen(wishvel);
696 if (wishspeed > sv_maxspeed*maxspd_mod)
697 wishspeed = sv_maxspeed*maxspd_mod;
698 wishspeed = wishspeed * 0.7;
701 self.velocity = self.velocity * (1 - frametime * sv_friction);
703 // water acceleration
704 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
706 else if (time < self.ladder_time)
708 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
709 self.flags &~= FL_ONGROUND;
711 self.velocity = self.velocity * (1 - frametime * sv_friction);
712 makevectors(self.v_angle);
713 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
714 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
716 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
718 self.velocity_z = self.velocity_z + sv_gravity * frametime;
719 if (self.ladder_entity.classname == "func_water")
722 if (f > self.ladder_entity.speed)
723 wishvel = wishvel * (self.ladder_entity.speed / f);
725 self.watertype = self.ladder_entity.skin;
726 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
727 if ((self.origin_z + self.view_ofs_z) < f)
728 self.waterlevel = WATERLEVEL_SUBMERGED;
729 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
730 self.waterlevel = WATERLEVEL_SWIMMING;
731 else if ((self.origin_z + self.mins_z + 1) < f)
732 self.waterlevel = WATERLEVEL_WETFEET;
735 self.waterlevel = WATERLEVEL_NONE;
736 self.watertype = CONTENT_EMPTY;
740 wishdir = normalize(wishvel);
741 wishspeed = vlen(wishvel);
742 if (wishspeed > sv_maxspeed*maxspd_mod)
743 wishspeed = sv_maxspeed*maxspd_mod;
744 if (time >= self.teleport_time)
746 // water acceleration
747 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
750 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
752 //makevectors(self.v_angle_y * '0 1 0');
753 makevectors(self.v_angle);
754 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
755 // add remaining speed as Z component
756 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
758 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
759 // add the unused velocity as up component
762 // if(self.BUTTON_JUMP)
763 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
765 // it is now normalized, so...
766 float a_side, a_up, a_add, a_diff;
767 a_side = cvar("g_jetpack_acceleration_side");
768 a_up = cvar("g_jetpack_acceleration_up");
769 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
778 //////////////////////////////////////////////////////////////////////////////////////
779 // finding the maximum over all vectors of above form
780 // with wishvel having an absolute value of 1
781 //////////////////////////////////////////////////////////////////////////////////////
782 // we're finding the maximum over
783 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
784 // for z in the range from -1 to 1
785 //////////////////////////////////////////////////////////////////////////////////////
786 // maximum is EITHER attained at the single extreme point:
787 a_diff = a_side * a_side - a_up * a_up;
790 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
791 if(f > -1 && f < 1) // can it be attained?
793 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
797 // OR attained at z = 1:
798 f = (a_up + a_add) * (a_up + a_add);
804 // OR attained at z = -1:
805 f = (a_up - a_add) * (a_up - a_add);
812 //////////////////////////////////////////////////////////////////////////////////////
814 //print("best possible acceleration: ", ftos(best), "\n");
817 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
818 if(wishvel_z - sv_gravity > 0)
819 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
821 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
824 fvel = vlen(wishvel);
827 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
829 fvel = min(1, vlen(wishvel) / best);
830 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
831 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
835 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
837 if (f > 0 && wishvel != '0 0 0')
839 self.velocity = self.velocity + wishvel * f * frametime;
840 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
841 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
842 self.flags &~= FL_ONGROUND;
843 self.items |= IT_USING_JETPACK;
845 // jetpack also inhibits health regeneration, but only for 1 second
846 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
849 else if (self.flags & FL_ONGROUND)
851 // we get here if we ran out of ammo
852 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
853 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
856 makevectors(self.v_angle_y * '0 1 0');
857 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
859 if(!(self.lastflags & FL_ONGROUND))
861 if(cvar("speedmeter"))
862 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
863 if(self.lastground < time - 0.3)
864 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
865 if(self.jumppadcount > 1)
866 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
867 self.jumppadcount = 0;
870 if (self.velocity_x || self.velocity_y)
871 if (!(self.flags & FL_JUMPRELEASED) || !self.BUTTON_JUMP)
876 if (f < sv_stopspeed)
877 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
879 f = 1 - frametime * sv_friction;
881 self.velocity = self.velocity * f;
883 self.velocity = '0 0 0';
886 wishdir = normalize(wishvel);
887 wishspeed = vlen(wishvel);
888 if (wishspeed > sv_maxspeed*maxspd_mod)
889 wishspeed = sv_maxspeed*maxspd_mod;
891 wishspeed = wishspeed * 0.5;
892 if (time >= self.teleport_time)
893 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
897 // we get here if we ran out of ammo
898 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
899 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
903 maxairspd = sv_maxairspeed*maxspd_mod;
904 airaccel = sv_airaccelerate*maxspd_mod;
908 maxairspd = sv_maxairspeed;
909 airaccel = sv_airaccelerate;
912 makevectors(self.v_angle_y * '0 1 0');
913 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
915 wishdir = normalize(wishvel);
916 wishspeed = vlen(wishvel);
917 if (wishspeed > maxairspd)
918 wishspeed = maxairspd;
920 wishspeed = wishspeed * 0.5;
921 if (time >= self.teleport_time)
923 if(sv_warsowbunny_turnaccel)
925 float accelerating, decelerating, aircontrol;
928 accelerating = (self.velocity * wishdir > 0);
929 decelerating = (self.velocity * wishdir < 0);
931 wishspeed2 = wishspeed;
933 if(accelerating && self.movement_y == 0 && self.movement_x != 0)
935 PM_AirAccelerate(wishdir, wishspeed);
939 if(sv_airstopaccelerate)
940 if(self.velocity * wishdir < 0)
941 airaccel = sv_airstopaccelerate;
942 if(self.movement_x == 0 && self.movement_y != 0)
944 if(sv_maxairstrafespeed)
945 wishspeed = min(wishspeed, sv_maxairstrafespeed);
946 if(sv_airstrafeaccelerate)
947 airaccel = sv_airstrafeaccelerate;
952 PM_Accelerate(wishdir, wishspeed, airaccel, sv_airaccel_qw, sv_airaccel_sideways_friction / maxairspd);
954 CPM_PM_Aircontrol(wishdir, wishspeed2);
960 if(sv_airstopaccelerate)
961 if(self.velocity * wishdir < 0)
962 airaccel = sv_airstopaccelerate;
963 if(self.movement_x == 0 && self.movement_y != 0)
965 if(sv_maxairstrafespeed)
966 wishspeed = min(wishspeed, sv_maxairstrafespeed);
967 if(sv_airstrafeaccelerate)
968 airaccel = sv_airstrafeaccelerate;
972 PM_Accelerate(wishdir, wishspeed, airaccel, sv_airaccel_qw, sv_airaccel_sideways_friction / maxairspd);
974 CPM_PM_Aircontrol(wishdir, wishspeed2);
980 if(self.flags & FL_ONGROUND)
981 self.lastground = time;
983 self.lastflags = self.flags;
984 self.lastclassname = self.classname;