6 float sv_airaccelerate;
10 float sv_airaccel_sideways_friction;
12 float sv_airstopaccelerate;
13 float sv_airstrafeaccelerate;
14 float sv_maxairstrafespeed;
16 float sv_warsowbunny_airforwardaccel;
17 float sv_warsowbunny_accel;
18 float sv_warsowbunny_topspeed;
19 float sv_warsowbunny_turnaccel;
20 float sv_warsowbunny_backtosideratio;
23 .entity ladder_entity;
25 .float swamp_slowdown;
29 .float spectatorspeed;
31 #define SHTEST_DELTA 10
32 #define SHTEST_THRESHOLD 1.1
34 .float shtest_accumulator;
35 .float doublejump_nextjumptime;
41 When you press the jump key
44 void PlayerJump (void)
48 mjumpheight = cvar("sv_jumpvelocity");
49 if (self.waterlevel >= WATERLEVEL_SWIMMING)
51 if (self.watertype == CONTENT_WATER)
52 self.velocity_z = 200;
53 else if (self.watertype == CONTENT_SLIME)
61 if (!(self.flags & FL_ONGROUND))
65 if (!(self.flags & FL_JUMPRELEASED))
68 if(self.health <= g_bloodloss)
72 if(time < self.doublejump_nextjumptime)
77 if(self.runes & RUNE_SPEED)
79 if(self.runes & CURSE_SLOW)
80 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
82 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
84 else if(self.runes & CURSE_SLOW)
86 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
90 if(g_minstagib && (self.items & IT_INVINCIBLE))
92 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
95 self.velocity_z = self.velocity_z + mjumpheight;
96 self.oldvelocity_z = self.velocity_z;
98 self.flags &~= FL_ONGROUND;
99 self.flags &~= FL_JUMPRELEASED;
102 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
104 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
107 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
111 // we're moving upwards at self.velocity_z
112 // only allow jumping after we got 3 units upwards
113 // so we for sure leave the FL_ONGROUND check
115 // but as this sucks because of factoring in gravity, we'll just do it
116 // for 4 units, and constant velocity
117 self.doublejump_nextjumptime = time + 4 / max(40, self.velocity_z); // max 0.1s blocking of jumps
121 void CheckWaterJump()
123 local vector start, end;
125 // check for a jump-out-of-water
126 makevectors (self.angles);
128 start_z = start_z + 8;
130 normalize(v_forward);
131 end = start + v_forward*24;
132 traceline (start, end, TRUE, self);
133 if (trace_fraction < 1)
135 start_z = start_z + self.maxs_z - 8;
136 end = start + v_forward*24;
137 self.movedir = trace_plane_normal * -50;
138 traceline (start, end, TRUE, self);
139 if (trace_fraction == 1)
140 { // open at eye level
141 self.flags |= FL_WATERJUMP;
142 self.velocity_z = 225;
143 self.flags &~= FL_JUMPRELEASED;
144 self.teleport_time = time + 2; // safety net
150 float racecar_angle(float forward, float down)
152 float ret, angle_mult;
160 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
162 angle_mult = forward / (800 + forward);
165 return ret * angle_mult + 360 * (1 - angle_mult);
167 return ret * angle_mult;
170 void RaceCarPhysics()
172 // using this move type for "big rigs"
173 // the engine does not push the entity!
175 float accel, steer, f;
176 vector angles_save, rigvel;
178 angles_save = self.angles;
179 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
180 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
182 if(g_bugrigs_reverse_speeding)
186 // back accel is DIGITAL
187 // to prevent speedhack
197 makevectors(self.angles); // new forward direction!
199 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
201 float myspeed, upspeed, steerfactor, accelfactor;
203 myspeed = self.velocity * v_forward;
204 upspeed = self.velocity * v_up;
206 // responsiveness factor for steering and acceleration
207 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
208 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
210 if(myspeed < 0 && g_bugrigs_reverse_spinning)
211 steerfactor = -myspeed * g_bugrigs_steer;
213 steerfactor = -myspeed * f * g_bugrigs_steer;
215 if(myspeed < 0 && g_bugrigs_reverse_speeding)
216 accelfactor = g_bugrigs_accel;
218 accelfactor = f * g_bugrigs_accel;
219 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
225 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
229 if(!g_bugrigs_reverse_speeding)
230 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
237 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
241 if(g_bugrigs_reverse_stopping)
244 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
247 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
248 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
250 self.angles_y += steer * frametime * steerfactor; // apply steering
251 makevectors(self.angles); // new forward direction!
253 myspeed += accel * accelfactor * frametime;
255 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
259 myspeed = vlen(self.velocity);
261 // responsiveness factor for steering and acceleration
262 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
263 steerfactor = -myspeed * f;
264 self.angles_y += steer * frametime * steerfactor; // apply steering
266 rigvel = self.velocity;
267 makevectors(self.angles); // new forward direction!
270 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
271 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
272 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
273 //MAXIMA: solve(total_acceleration(v) = 0, v);
275 if(g_bugrigs_planar_movement)
277 vector rigvel_xy, neworigin, up;
280 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
284 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
287 mt = MOVE_NOMONSTERS;
289 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
290 up = trace_endpos - self.origin;
292 // BUG RIGS: align the move to the surface instead of doing collision testing
294 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
297 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
299 if(trace_fraction < 0.5)
302 neworigin = self.origin;
305 neworigin = trace_endpos;
307 if(trace_fraction < 1)
309 // now set angles_x so that the car points parallel to the surface
310 self.angles = vectoangles(
311 '1 0 0' * v_forward_x * trace_plane_normal_z
313 '0 1 0' * v_forward_y * trace_plane_normal_z
315 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
317 self.flags |= FL_ONGROUND;
321 // now set angles_x so that the car points forward, but is tilted in velocity direction
322 self.flags &~= FL_ONGROUND;
325 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
326 self.movetype = MOVETYPE_NOCLIP;
330 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
331 self.velocity = rigvel;
332 self.movetype = MOVETYPE_FLY;
336 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
337 if(trace_fraction != 1)
339 self.angles = vectoangles2(
340 '1 0 0' * v_forward_x * trace_plane_normal_z
342 '0 1 0' * v_forward_y * trace_plane_normal_z
344 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
352 vel_local_x = v_forward * self.velocity;
353 vel_local_y = v_right * self.velocity;
354 vel_local_z = v_up * self.velocity;
356 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
357 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
361 vector vf1, vu1, smoothangles;
362 makevectors(self.angles);
363 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
368 makevectors(angles_save);
369 vf1 = vf1 + v_forward * (1 - f);
370 vu1 = vu1 + v_up * (1 - f);
371 smoothangles = vectoangles2(vf1, vu1);
372 self.angles_x = -smoothangles_x;
373 self.angles_z = smoothangles_z;
376 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
378 float zspeed, xyspeed, dot, k;
380 if(self.movement_x == 0 || self.movement_y != 0)
381 return; // can't control movement if not moving forward or backward
383 zspeed = self.velocity_z;
385 xyspeed = vlen(self.velocity);
386 self.velocity = normalize(self.velocity);
388 dot = self.velocity * wishdir;
390 k *= sv_aircontrol*dot*dot*frametime;
392 if(dot > 0) // we can't change direction while slowing down
393 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
395 self.velocity = self.velocity * xyspeed;
396 self.velocity_z = zspeed;
399 void PM_Accelerate(vector wishdir, float wishspeed, float accel, float accelqw, float sidefric)
406 vel_straight = self.velocity * wishdir;
407 vel_z = self.velocity_z;
408 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
410 addspeed = wishspeed - vel_straight;
412 vel_straight = vel_straight + min(addspeed, accel * frametime * wishspeed) * accelqw;
414 vel_straight = vel_straight + min(wishspeed, accel * frametime * wishspeed) * (1 - accelqw);
416 vel_perpend = vel_perpend * (1 - frametime * wishspeed * sidefric);
418 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
421 void PM_AirAccelerate(vector wishdir, float wishspeed)
423 vector curvel, wishvel, acceldir, curdir;
424 float addspeed, accelspeed, curspeed, f;
430 curvel = self.velocity;
432 curspeed = vlen(curvel);
434 if(wishspeed > curspeed * 1.01)
436 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
440 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
441 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
443 wishvel = wishdir * wishspeed;
444 acceldir = wishvel - curvel;
445 addspeed = vlen(acceldir);
446 acceldir = normalize(acceldir);
448 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
450 if(sv_warsowbunny_backtosideratio < 1)
452 curdir = normalize(curvel);
453 dot = acceldir * curdir;
455 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
458 self.velocity += accelspeed * acceldir;
461 .vector movement_old;
464 .string lastclassname;
466 void Nixnex_GiveCurrentWeapon();
467 .float() PlayerPhysplug;
468 void SV_PlayerPhysics()
470 local vector wishvel, wishdir, v;
471 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, shtest_score, buttons;
474 float not_allowed_to_move;
476 if(self.PlayerPhysplug)
477 if(self.PlayerPhysplug())
480 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;
481 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
483 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
484 self.parm_idlesince = time;
486 buttons_prev = self.buttons_old;
487 self.buttons_old = buttons;
488 self.movement_old = self.movement;
489 self.v_angle_old = self.v_angle;
491 if(time < self.nickspamtime)
492 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
494 // slight annoyance for nick change scripts
495 self.movement = -1 * self.movement;
496 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
498 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!
500 self.angles_x = random() * 360;
501 self.angles_y = random() * 360;
502 // at least I'm not forcing retardedview by also assigning to angles_z
507 if(time > self.shtest_next)
509 if(self.shtest_next > 0)
511 // self.shtest_accumulator:
512 // started at time - SHTEST_DELTA
513 // should be at SHTEST_DELTA
514 shtest_score = self.shtest_accumulator / (SHTEST_DELTA + time - self.shtest_next);
515 if(shtest_score > SHTEST_THRESHOLD)
516 print("TIME PARADOX: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
517 else if(cvar("developer_shtest"))
518 dprint("okay: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
520 self.shtest_next = time + SHTEST_DELTA;
521 self.shtest_accumulator = 0;
523 self.shtest_accumulator += frametime;
525 if (clienttype(self) == CLIENTTYPE_BOT)
528 self.items &~= IT_USING_JETPACK;
530 if(self.race_penalty)
531 if(time > self.race_penalty)
532 self.race_penalty = 0;
534 not_allowed_to_move = 0;
535 if(self.race_penalty)
536 not_allowed_to_move = 1;
537 if(!cvar("sv_ready_restart_after_countdown"))
538 if(time < game_starttime)
539 not_allowed_to_move = 1;
541 if(not_allowed_to_move)
543 self.velocity = '0 0 0';
544 self.movetype = MOVETYPE_NONE;
545 self.disableclientprediction = 2;
547 else if(self.disableclientprediction == 2)
549 if(self.movetype == MOVETYPE_NONE)
550 self.movetype = MOVETYPE_WALK;
551 self.disableclientprediction = 0;
554 if (self.movetype == MOVETYPE_NONE)
557 if (self.punchangle != '0 0 0')
559 f = vlen(self.punchangle) - 10 * frametime;
561 self.punchangle = normalize(self.punchangle) * f;
563 self.punchangle = '0 0 0';
566 if (self.punchvector != '0 0 0')
568 f = vlen(self.punchvector) - 30 * frametime;
570 self.punchvector = normalize(self.punchvector) * f;
572 self.punchvector = '0 0 0';
579 if(self.runes & RUNE_SPEED)
581 if(self.runes & CURSE_SLOW)
582 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
584 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
586 else if(self.runes & CURSE_SLOW)
588 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
592 if(g_minstagib && (self.items & IT_INVINCIBLE))
594 maxspd_mod = cvar("g_minstagib_speed_moverate");
597 if(g_nexball && self.ballcarried)
599 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
604 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
607 if(self.classname != "player")
609 maxspd_mod = cvar("sv_spectator_speed_multiplier");
610 if(!self.spectatorspeed)
611 self.spectatorspeed = maxspd_mod;
612 if(self.impulse && self.impulse <= 19)
614 if(self.lastclassname != "player")
616 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
617 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
618 else if(self.impulse == 11)
619 self.spectatorspeed = maxspd_mod;
620 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
621 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
622 else if(self.impulse >= 1 && self.impulse <= 9)
623 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
624 } // otherwise just clear
627 maxspd_mod = self.spectatorspeed;
630 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
631 if(self.speed != spd)
635 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
636 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
637 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
638 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
641 maxspd_mod *= swampspd_mod; // only one common speed modder please!
644 // if dead, behave differently
648 if (!self.fixangle && !g_bugrigs)
651 self.angles_y = self.v_angle_y;
655 if(self.flags & FL_ONGROUND)
660 if(self.waterlevel < WATERLEVEL_SWIMMING)
661 if(time >= self.ladder_time)
664 self.nextstep = time + 0.3 + random() * 0.1;
665 trace_dphitq3surfaceflags = 0;
666 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
667 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
669 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
670 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
672 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
680 if(self.classname == "player")
684 self.flags &~= FL_ONGROUND;
685 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 2', MOVE_NORMAL, self);
686 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
687 self.flags |= FL_ONGROUND;
690 if (self.BUTTON_JUMP)
693 self.flags |= FL_JUMPRELEASED;
695 if (self.waterlevel == WATERLEVEL_SWIMMING)
699 if (self.flags & FL_WATERJUMP )
701 self.velocity_x = self.movedir_x;
702 self.velocity_y = self.movedir_y;
703 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
705 self.flags &~= FL_WATERJUMP;
706 self.teleport_time = 0;
709 else if (g_bugrigs && self.classname == "player")
713 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
715 // noclipping or flying
716 self.flags &~= FL_ONGROUND;
718 self.velocity = self.velocity * (1 - frametime * sv_friction);
719 makevectors(self.v_angle);
720 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
721 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
723 wishdir = normalize(wishvel);
724 wishspeed = vlen(wishvel);
725 if (wishspeed > sv_maxspeed*maxspd_mod)
726 wishspeed = sv_maxspeed*maxspd_mod;
727 if (time >= self.teleport_time)
728 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
730 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
733 self.flags &~= FL_ONGROUND;
735 makevectors(self.v_angle);
736 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
737 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
738 if (wishvel == '0 0 0')
739 wishvel = '0 0 -60'; // drift towards bottom
741 wishdir = normalize(wishvel);
742 wishspeed = vlen(wishvel);
743 if (wishspeed > sv_maxspeed*maxspd_mod)
744 wishspeed = sv_maxspeed*maxspd_mod;
745 wishspeed = wishspeed * 0.7;
748 self.velocity = self.velocity * (1 - frametime * sv_friction);
750 // water acceleration
751 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
753 else if (time < self.ladder_time)
755 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
756 self.flags &~= FL_ONGROUND;
758 self.velocity = self.velocity * (1 - frametime * sv_friction);
759 makevectors(self.v_angle);
760 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
761 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
763 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
765 self.velocity_z = self.velocity_z + sv_gravity * frametime;
766 if (self.ladder_entity.classname == "func_water")
769 if (f > self.ladder_entity.speed)
770 wishvel = wishvel * (self.ladder_entity.speed / f);
772 self.watertype = self.ladder_entity.skin;
773 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
774 if ((self.origin_z + self.view_ofs_z) < f)
775 self.waterlevel = WATERLEVEL_SUBMERGED;
776 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
777 self.waterlevel = WATERLEVEL_SWIMMING;
778 else if ((self.origin_z + self.mins_z + 1) < f)
779 self.waterlevel = WATERLEVEL_WETFEET;
782 self.waterlevel = WATERLEVEL_NONE;
783 self.watertype = CONTENT_EMPTY;
787 wishdir = normalize(wishvel);
788 wishspeed = vlen(wishvel);
789 if (wishspeed > sv_maxspeed*maxspd_mod)
790 wishspeed = sv_maxspeed*maxspd_mod;
791 if (time >= self.teleport_time)
793 // water acceleration
794 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
797 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
799 //makevectors(self.v_angle_y * '0 1 0');
800 makevectors(self.v_angle);
801 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
802 // add remaining speed as Z component
803 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
805 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
806 // add the unused velocity as up component
809 // if(self.BUTTON_JUMP)
810 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
812 // it is now normalized, so...
813 float a_side, a_up, a_add, a_diff;
814 a_side = cvar("g_jetpack_acceleration_side");
815 a_up = cvar("g_jetpack_acceleration_up");
816 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
825 //////////////////////////////////////////////////////////////////////////////////////
826 // finding the maximum over all vectors of above form
827 // with wishvel having an absolute value of 1
828 //////////////////////////////////////////////////////////////////////////////////////
829 // we're finding the maximum over
830 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
831 // for z in the range from -1 to 1
832 //////////////////////////////////////////////////////////////////////////////////////
833 // maximum is EITHER attained at the single extreme point:
834 a_diff = a_side * a_side - a_up * a_up;
837 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
838 if(f > -1 && f < 1) // can it be attained?
840 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
844 // OR attained at z = 1:
845 f = (a_up + a_add) * (a_up + a_add);
851 // OR attained at z = -1:
852 f = (a_up - a_add) * (a_up - a_add);
859 //////////////////////////////////////////////////////////////////////////////////////
861 //print("best possible acceleration: ", ftos(best), "\n");
864 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
865 if(wishvel_z - sv_gravity > 0)
866 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
868 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
871 fvel = vlen(wishvel);
874 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
876 fvel = min(1, vlen(wishvel) / best);
877 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
878 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
882 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
884 if (f > 0 && wishvel != '0 0 0')
886 self.velocity = self.velocity + wishvel * f * frametime;
887 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
888 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
889 self.flags &~= FL_ONGROUND;
890 self.items |= IT_USING_JETPACK;
892 // jetpack also inhibits health regeneration, but only for 1 second
893 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
896 else if (self.flags & FL_ONGROUND)
898 // we get here if we ran out of ammo
899 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
900 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
903 makevectors(self.v_angle_y * '0 1 0');
904 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
906 if(!(self.lastflags & FL_ONGROUND))
908 if(cvar("speedmeter"))
909 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
910 if(self.lastground < time - 0.3)
911 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
912 if(self.jumppadcount > 1)
913 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
914 self.jumppadcount = 0;
917 if (self.velocity_x || self.velocity_y)
918 if (!(self.flags & FL_JUMPRELEASED) || !self.BUTTON_JUMP)
923 if (f < sv_stopspeed)
924 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
926 f = 1 - frametime * sv_friction;
928 self.velocity = self.velocity * f;
930 self.velocity = '0 0 0';
933 wishdir = normalize(wishvel);
934 wishspeed = vlen(wishvel);
935 if (wishspeed > sv_maxspeed*maxspd_mod)
936 wishspeed = sv_maxspeed*maxspd_mod;
938 wishspeed = wishspeed * 0.5;
939 if (time >= self.teleport_time)
940 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
944 // we get here if we ran out of ammo
945 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
946 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
950 maxairspd = sv_maxairspeed*maxspd_mod;
951 airaccel = sv_airaccelerate*maxspd_mod;
955 maxairspd = sv_maxairspeed;
956 airaccel = sv_airaccelerate;
959 makevectors(self.v_angle_y * '0 1 0');
960 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
962 wishdir = normalize(wishvel);
963 wishspeed = vlen(wishvel);
964 if (wishspeed > maxairspd)
965 wishspeed = maxairspd;
967 wishspeed = wishspeed * 0.5;
968 if (time >= self.teleport_time)
974 airaccelqw = sv_airaccel_qw;
975 accelerating = (self.velocity * wishdir > 0);
976 wishspeed2 = wishspeed;
979 if(sv_airstopaccelerate)
980 if(self.velocity * wishdir < 0)
981 airaccel = sv_airstopaccelerate*maxspd_mod;
982 if(self.movement_x == 0 && self.movement_y != 0)
984 if(sv_maxairstrafespeed)
986 wishspeed = min(wishspeed, sv_maxairstrafespeed*maxspd_mod);
987 if(sv_maxairstrafespeed < sv_maxairspeed)
990 if(sv_airstrafeaccelerate)
992 airaccel = sv_airstrafeaccelerate*maxspd_mod;
993 if(sv_airstrafeaccelerate > sv_airaccelerate)
999 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1000 PM_AirAccelerate(wishdir, wishspeed);
1002 PM_Accelerate(wishdir, wishspeed, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd);
1005 CPM_PM_Aircontrol(wishdir, wishspeed2);
1010 if(self.flags & FL_ONGROUND)
1011 self.lastground = time;
1013 self.lastflags = self.flags;
1014 self.lastclassname = self.classname;