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;
33 .float doublejump_nextjumptime;
39 When you press the jump key
42 void PlayerJump (void)
46 mjumpheight = cvar("sv_jumpvelocity");
47 if (self.waterlevel >= WATERLEVEL_SWIMMING)
49 if (self.watertype == CONTENT_WATER)
50 self.velocity_z = 200;
51 else if (self.watertype == CONTENT_SLIME)
59 if (!(self.flags & FL_ONGROUND))
63 if (!(self.flags & FL_JUMPRELEASED))
66 if(self.health <= g_bloodloss)
70 if(time < self.doublejump_nextjumptime)
75 if(self.runes & RUNE_SPEED)
77 if(self.runes & CURSE_SLOW)
78 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
80 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
82 else if(self.runes & CURSE_SLOW)
84 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
88 if(g_minstagib && (self.items & IT_INVINCIBLE))
90 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
93 self.velocity_z = self.velocity_z + mjumpheight;
94 self.oldvelocity_z = self.velocity_z;
96 self.flags &~= FL_ONGROUND;
97 self.flags &~= FL_JUMPRELEASED;
100 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
102 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
105 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
109 // we're moving upwards at self.velocity_z
110 // only allow jumping after we got 3 units upwards
111 // so we for sure leave the FL_ONGROUND check
113 // but as this sucks because of factoring in gravity, we'll just do it
114 // for 4 units, and constant velocity
115 self.doublejump_nextjumptime = time + 4 / max(40, self.velocity_z); // max 0.1s blocking of jumps
119 void CheckWaterJump()
121 local vector start, end;
123 // check for a jump-out-of-water
124 makevectors (self.angles);
126 start_z = start_z + 8;
128 normalize(v_forward);
129 end = start + v_forward*24;
130 traceline (start, end, TRUE, self);
131 if (trace_fraction < 1)
133 start_z = start_z + self.maxs_z - 8;
134 end = start + v_forward*24;
135 self.movedir = trace_plane_normal * -50;
136 traceline (start, end, TRUE, self);
137 if (trace_fraction == 1)
138 { // open at eye level
139 self.flags |= FL_WATERJUMP;
140 self.velocity_z = 225;
141 self.flags &~= FL_JUMPRELEASED;
142 self.teleport_time = time + 2; // safety net
148 float racecar_angle(float forward, float down)
150 float ret, angle_mult;
158 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
160 angle_mult = forward / (800 + forward);
163 return ret * angle_mult + 360 * (1 - angle_mult);
165 return ret * angle_mult;
168 void RaceCarPhysics()
170 // using this move type for "big rigs"
171 // the engine does not push the entity!
173 float accel, steer, f;
174 vector angles_save, rigvel;
176 angles_save = self.angles;
177 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
178 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
180 if(g_bugrigs_reverse_speeding)
184 // back accel is DIGITAL
185 // to prevent speedhack
195 makevectors(self.angles); // new forward direction!
197 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
199 float myspeed, upspeed, steerfactor, accelfactor;
201 myspeed = self.velocity * v_forward;
202 upspeed = self.velocity * v_up;
204 // responsiveness factor for steering and acceleration
205 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
206 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
208 if(myspeed < 0 && g_bugrigs_reverse_spinning)
209 steerfactor = -myspeed * g_bugrigs_steer;
211 steerfactor = -myspeed * f * g_bugrigs_steer;
213 if(myspeed < 0 && g_bugrigs_reverse_speeding)
214 accelfactor = g_bugrigs_accel;
216 accelfactor = f * g_bugrigs_accel;
217 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
223 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
227 if(!g_bugrigs_reverse_speeding)
228 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
235 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
239 if(g_bugrigs_reverse_stopping)
242 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
245 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
246 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
248 self.angles_y += steer * frametime * steerfactor; // apply steering
249 makevectors(self.angles); // new forward direction!
251 myspeed += accel * accelfactor * frametime;
253 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
257 myspeed = vlen(self.velocity);
259 // responsiveness factor for steering and acceleration
260 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
261 steerfactor = -myspeed * f;
262 self.angles_y += steer * frametime * steerfactor; // apply steering
264 rigvel = self.velocity;
265 makevectors(self.angles); // new forward direction!
268 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
269 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
270 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
271 //MAXIMA: solve(total_acceleration(v) = 0, v);
273 if(g_bugrigs_planar_movement)
275 vector rigvel_xy, neworigin, up;
278 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
282 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
285 mt = MOVE_NOMONSTERS;
287 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
288 up = trace_endpos - self.origin;
290 // BUG RIGS: align the move to the surface instead of doing collision testing
292 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
295 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
297 if(trace_fraction < 0.5)
300 neworigin = self.origin;
303 neworigin = trace_endpos;
305 if(trace_fraction < 1)
307 // now set angles_x so that the car points parallel to the surface
308 self.angles = vectoangles(
309 '1 0 0' * v_forward_x * trace_plane_normal_z
311 '0 1 0' * v_forward_y * trace_plane_normal_z
313 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
315 self.flags |= FL_ONGROUND;
319 // now set angles_x so that the car points forward, but is tilted in velocity direction
320 self.flags &~= FL_ONGROUND;
323 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
324 self.movetype = MOVETYPE_NOCLIP;
328 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
329 self.velocity = rigvel;
330 self.movetype = MOVETYPE_FLY;
334 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
335 if(trace_fraction != 1)
337 self.angles = vectoangles2(
338 '1 0 0' * v_forward_x * trace_plane_normal_z
340 '0 1 0' * v_forward_y * trace_plane_normal_z
342 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
350 vel_local_x = v_forward * self.velocity;
351 vel_local_y = v_right * self.velocity;
352 vel_local_z = v_up * self.velocity;
354 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
355 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
359 vector vf1, vu1, smoothangles;
360 makevectors(self.angles);
361 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
366 makevectors(angles_save);
367 vf1 = vf1 + v_forward * (1 - f);
368 vu1 = vu1 + v_up * (1 - f);
369 smoothangles = vectoangles2(vf1, vu1);
370 self.angles_x = -smoothangles_x;
371 self.angles_z = smoothangles_z;
374 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
376 float zspeed, xyspeed, dot, k;
378 if(self.movement_x == 0 || self.movement_y != 0)
379 return; // can't control movement if not moving forward or backward
381 zspeed = self.velocity_z;
383 xyspeed = vlen(self.velocity);
384 self.velocity = normalize(self.velocity);
386 dot = self.velocity * wishdir;
388 k *= sv_aircontrol*dot*dot*frametime;
390 if(dot > 0) // we can't change direction while slowing down
391 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
393 self.velocity = self.velocity * xyspeed;
394 self.velocity_z = zspeed;
397 void PM_Accelerate(vector wishdir, float wishspeed, float accel, float accelqw, float sidefric)
404 vel_straight = self.velocity * wishdir;
405 vel_z = self.velocity_z;
406 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
408 addspeed = wishspeed - vel_straight;
410 vel_straight = vel_straight + min(addspeed, accel * frametime * wishspeed) * accelqw;
412 vel_straight = vel_straight + min(wishspeed, accel * frametime * wishspeed) * (1 - accelqw);
414 vel_perpend = vel_perpend * (1 - frametime * wishspeed * sidefric);
416 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
419 void PM_AirAccelerate(vector wishdir, float wishspeed)
421 vector curvel, wishvel, acceldir, curdir;
422 float addspeed, accelspeed, curspeed, f;
428 curvel = self.velocity;
430 curspeed = vlen(curvel);
432 if(wishspeed > curspeed * 1.01)
434 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
438 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
439 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
441 wishvel = wishdir * wishspeed;
442 acceldir = wishvel - curvel;
443 addspeed = vlen(acceldir);
444 acceldir = normalize(acceldir);
446 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
448 if(sv_warsowbunny_backtosideratio < 1)
450 curdir = normalize(curvel);
451 dot = acceldir * curdir;
453 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
456 self.velocity += accelspeed * acceldir;
459 .vector movement_old;
462 .string lastclassname;
464 void Nixnex_GiveCurrentWeapon();
465 void SV_PlayerPhysics()
467 local vector wishvel, wishdir, v;
468 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, shtest_score, buttons;
472 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;
473 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
475 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
476 self.parm_idlesince = time;
478 buttons_prev = self.buttons_old;
479 self.buttons_old = buttons;
480 self.movement_old = self.movement;
481 self.v_angle_old = self.v_angle;
483 if(time < self.nickspamtime)
484 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
486 // slight annoyance for nick change scripts
487 self.movement = -1 * self.movement;
488 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
490 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!
492 self.angles_x = random() * 360;
493 self.angles_y = random() * 360;
494 // at least I'm not forcing retardedview by also assigning to angles_z
499 if(time > self.shtest_next)
501 if(self.shtest_next > 0)
503 // self.shtest_accumulator:
504 // started at time - SHTEST_DELTA
505 // should be at SHTEST_DELTA
506 shtest_score = self.shtest_accumulator / (SHTEST_DELTA + time - self.shtest_next);
507 if(shtest_score > SHTEST_THRESHOLD)
508 print("TIME PARADOX: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
509 else if(cvar("developer_shtest"))
510 dprint("okay: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
512 self.shtest_next = time + SHTEST_DELTA;
513 self.shtest_accumulator = 0;
515 self.shtest_accumulator += frametime;
517 if (clienttype(self) == CLIENTTYPE_BOT)
520 self.items &~= IT_USING_JETPACK;
522 if (self.movetype == MOVETYPE_NONE && self.disableclientprediction != 2)
525 if (self.punchangle != '0 0 0')
527 f = vlen(self.punchangle) - 10 * frametime;
529 self.punchangle = normalize(self.punchangle) * f;
531 self.punchangle = '0 0 0';
534 if (self.punchvector != '0 0 0')
536 f = vlen(self.punchvector) - 30 * frametime;
538 self.punchvector = normalize(self.punchvector) * f;
540 self.punchvector = '0 0 0';
547 if(self.runes & RUNE_SPEED)
549 if(self.runes & CURSE_SLOW)
550 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
552 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
554 else if(self.runes & CURSE_SLOW)
556 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
560 if(g_minstagib && (self.items & IT_INVINCIBLE))
562 maxspd_mod = cvar("g_minstagib_speed_moverate");
565 if(g_nexball && self.ballcarried)
567 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
572 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
575 if(self.classname != "player")
577 maxspd_mod = cvar("sv_spectator_speed_multiplier");
578 if(!self.spectatorspeed)
579 self.spectatorspeed = maxspd_mod;
580 if(self.impulse && self.impulse <= 19)
582 if(self.lastclassname != "player")
584 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
585 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
586 else if(self.impulse == 11)
587 self.spectatorspeed = maxspd_mod;
588 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
589 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
590 else if(self.impulse >= 1 && self.impulse <= 9)
591 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
592 } // otherwise just clear
595 maxspd_mod = self.spectatorspeed;
598 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
599 if(self.speed != spd)
603 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
604 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
605 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
606 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
609 maxspd_mod *= swampspd_mod; // only one common speed modder please!
612 // if dead, behave differently
616 if (!self.fixangle && !g_bugrigs)
619 self.angles_y = self.v_angle_y;
623 if(self.flags & FL_ONGROUND)
628 if(self.waterlevel < WATERLEVEL_SWIMMING)
629 if(time >= self.ladder_time)
632 self.nextstep = time + 0.3 + random() * 0.1;
633 trace_dphitq3surfaceflags = 0;
634 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
635 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
637 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
638 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
640 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
648 if(self.classname == "player")
652 self.flags &~= FL_ONGROUND;
653 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 2', MOVE_NORMAL, self);
654 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
655 self.flags |= FL_ONGROUND;
658 if (self.BUTTON_JUMP)
661 self.flags |= FL_JUMPRELEASED;
663 if (self.waterlevel == WATERLEVEL_SWIMMING)
667 if (self.flags & FL_WATERJUMP )
669 self.velocity_x = self.movedir_x;
670 self.velocity_y = self.movedir_y;
671 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
673 self.flags &~= FL_WATERJUMP;
674 self.teleport_time = 0;
677 else if (g_bugrigs && self.classname == "player")
681 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
683 // noclipping or flying
684 self.flags &~= FL_ONGROUND;
686 self.velocity = self.velocity * (1 - frametime * sv_friction);
687 makevectors(self.v_angle);
688 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
689 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
691 wishdir = normalize(wishvel);
692 wishspeed = vlen(wishvel);
693 if (wishspeed > sv_maxspeed*maxspd_mod)
694 wishspeed = sv_maxspeed*maxspd_mod;
695 if (time >= self.teleport_time)
696 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
698 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
701 self.flags &~= FL_ONGROUND;
703 makevectors(self.v_angle);
704 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
705 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
706 if (wishvel == '0 0 0')
707 wishvel = '0 0 -60'; // drift towards bottom
709 wishdir = normalize(wishvel);
710 wishspeed = vlen(wishvel);
711 if (wishspeed > sv_maxspeed*maxspd_mod)
712 wishspeed = sv_maxspeed*maxspd_mod;
713 wishspeed = wishspeed * 0.7;
716 self.velocity = self.velocity * (1 - frametime * sv_friction);
718 // water acceleration
719 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
721 else if (time < self.ladder_time)
723 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
724 self.flags &~= FL_ONGROUND;
726 self.velocity = self.velocity * (1 - frametime * sv_friction);
727 makevectors(self.v_angle);
728 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
729 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
731 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
733 self.velocity_z = self.velocity_z + sv_gravity * frametime;
734 if (self.ladder_entity.classname == "func_water")
737 if (f > self.ladder_entity.speed)
738 wishvel = wishvel * (self.ladder_entity.speed / f);
740 self.watertype = self.ladder_entity.skin;
741 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
742 if ((self.origin_z + self.view_ofs_z) < f)
743 self.waterlevel = WATERLEVEL_SUBMERGED;
744 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
745 self.waterlevel = WATERLEVEL_SWIMMING;
746 else if ((self.origin_z + self.mins_z + 1) < f)
747 self.waterlevel = WATERLEVEL_WETFEET;
750 self.waterlevel = WATERLEVEL_NONE;
751 self.watertype = CONTENT_EMPTY;
755 wishdir = normalize(wishvel);
756 wishspeed = vlen(wishvel);
757 if (wishspeed > sv_maxspeed*maxspd_mod)
758 wishspeed = sv_maxspeed*maxspd_mod;
759 if (time >= self.teleport_time)
761 // water acceleration
762 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
765 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
767 //makevectors(self.v_angle_y * '0 1 0');
768 makevectors(self.v_angle);
769 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
770 // add remaining speed as Z component
771 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
773 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
774 // add the unused velocity as up component
777 // if(self.BUTTON_JUMP)
778 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
780 // it is now normalized, so...
781 float a_side, a_up, a_add, a_diff;
782 a_side = cvar("g_jetpack_acceleration_side");
783 a_up = cvar("g_jetpack_acceleration_up");
784 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
793 //////////////////////////////////////////////////////////////////////////////////////
794 // finding the maximum over all vectors of above form
795 // with wishvel having an absolute value of 1
796 //////////////////////////////////////////////////////////////////////////////////////
797 // we're finding the maximum over
798 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
799 // for z in the range from -1 to 1
800 //////////////////////////////////////////////////////////////////////////////////////
801 // maximum is EITHER attained at the single extreme point:
802 a_diff = a_side * a_side - a_up * a_up;
805 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
806 if(f > -1 && f < 1) // can it be attained?
808 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
812 // OR attained at z = 1:
813 f = (a_up + a_add) * (a_up + a_add);
819 // OR attained at z = -1:
820 f = (a_up - a_add) * (a_up - a_add);
827 //////////////////////////////////////////////////////////////////////////////////////
829 //print("best possible acceleration: ", ftos(best), "\n");
832 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
833 if(wishvel_z - sv_gravity > 0)
834 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
836 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
839 fvel = vlen(wishvel);
842 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
844 fvel = min(1, vlen(wishvel) / best);
845 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
846 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
850 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
852 if (f > 0 && wishvel != '0 0 0')
854 self.velocity = self.velocity + wishvel * f * frametime;
855 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
856 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
857 self.flags &~= FL_ONGROUND;
858 self.items |= IT_USING_JETPACK;
860 // jetpack also inhibits health regeneration, but only for 1 second
861 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
864 else if (self.flags & FL_ONGROUND)
866 // we get here if we ran out of ammo
867 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
868 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
871 makevectors(self.v_angle_y * '0 1 0');
872 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
874 if(!(self.lastflags & FL_ONGROUND))
876 if(cvar("speedmeter"))
877 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
878 if(self.lastground < time - 0.3)
879 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
880 if(self.jumppadcount > 1)
881 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
882 self.jumppadcount = 0;
885 if (self.velocity_x || self.velocity_y)
886 if (!(self.flags & FL_JUMPRELEASED) || !self.BUTTON_JUMP)
891 if (f < sv_stopspeed)
892 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
894 f = 1 - frametime * sv_friction;
896 self.velocity = self.velocity * f;
898 self.velocity = '0 0 0';
901 wishdir = normalize(wishvel);
902 wishspeed = vlen(wishvel);
903 if (wishspeed > sv_maxspeed*maxspd_mod)
904 wishspeed = sv_maxspeed*maxspd_mod;
906 wishspeed = wishspeed * 0.5;
907 if (time >= self.teleport_time)
908 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
912 // we get here if we ran out of ammo
913 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
914 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
918 maxairspd = sv_maxairspeed*maxspd_mod;
919 airaccel = sv_airaccelerate*maxspd_mod;
923 maxairspd = sv_maxairspeed;
924 airaccel = sv_airaccelerate;
927 makevectors(self.v_angle_y * '0 1 0');
928 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
930 wishdir = normalize(wishvel);
931 wishspeed = vlen(wishvel);
932 if (wishspeed > maxairspd)
933 wishspeed = maxairspd;
935 wishspeed = wishspeed * 0.5;
936 if (time >= self.teleport_time)
941 accelerating = (self.velocity * wishdir > 0);
942 wishspeed2 = wishspeed;
945 if(sv_airstopaccelerate)
946 if(self.velocity * wishdir < 0)
947 airaccel = sv_airstopaccelerate;
948 if(self.movement_x == 0 && self.movement_y != 0)
950 if(sv_maxairstrafespeed)
951 wishspeed = min(wishspeed, sv_maxairstrafespeed);
952 if(sv_airstrafeaccelerate)
953 airaccel = sv_airstrafeaccelerate;
957 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
958 PM_AirAccelerate(wishdir, wishspeed);
960 PM_Accelerate(wishdir, wishspeed, airaccel, sv_airaccel_qw, sv_airaccel_sideways_friction / maxairspd);
963 CPM_PM_Aircontrol(wishdir, wishspeed2);
968 if(self.flags & FL_ONGROUND)
969 self.lastground = time;
971 self.lastflags = self.flags;
972 self.lastclassname = self.classname;