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 if(!(self.lastflags & FL_ONGROUND))
97 if(cvar("speedmeter"))
98 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
99 if(self.lastground < time - 0.3)
100 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
101 if(self.jumppadcount > 1)
102 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
103 self.jumppadcount = 0;
106 self.velocity_z = self.velocity_z + mjumpheight;
107 self.oldvelocity_z = self.velocity_z;
109 self.flags &~= FL_ONGROUND;
110 self.flags &~= FL_JUMPRELEASED;
113 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
115 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
118 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
122 // we're moving upwards at self.velocity_z
123 // only allow jumping after we got 3 units upwards
124 // so we for sure leave the FL_ONGROUND check
126 // but as this sucks because of factoring in gravity, we'll just do it
127 // for 4 units, and constant velocity
128 self.doublejump_nextjumptime = time + 4 / max(40, self.velocity_z); // max 0.1s blocking of jumps
132 void CheckWaterJump()
134 local vector start, end;
136 // check for a jump-out-of-water
137 makevectors (self.angles);
139 start_z = start_z + 8;
141 normalize(v_forward);
142 end = start + v_forward*24;
143 traceline (start, end, TRUE, self);
144 if (trace_fraction < 1)
146 start_z = start_z + self.maxs_z - 8;
147 end = start + v_forward*24;
148 self.movedir = trace_plane_normal * -50;
149 traceline (start, end, TRUE, self);
150 if (trace_fraction == 1)
151 { // open at eye level
152 self.flags |= FL_WATERJUMP;
153 self.velocity_z = 225;
154 self.flags &~= FL_JUMPRELEASED;
155 self.teleport_time = time + 2; // safety net
161 float racecar_angle(float forward, float down)
163 float ret, angle_mult;
171 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
173 angle_mult = forward / (800 + forward);
176 return ret * angle_mult + 360 * (1 - angle_mult);
178 return ret * angle_mult;
181 void RaceCarPhysics()
183 // using this move type for "big rigs"
184 // the engine does not push the entity!
186 float accel, steer, f;
187 vector angles_save, rigvel;
189 angles_save = self.angles;
190 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
191 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
193 if(g_bugrigs_reverse_speeding)
197 // back accel is DIGITAL
198 // to prevent speedhack
208 makevectors(self.angles); // new forward direction!
210 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
212 float myspeed, upspeed, steerfactor, accelfactor;
214 myspeed = self.velocity * v_forward;
215 upspeed = self.velocity * v_up;
217 // responsiveness factor for steering and acceleration
218 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
219 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
221 if(myspeed < 0 && g_bugrigs_reverse_spinning)
222 steerfactor = -myspeed * g_bugrigs_steer;
224 steerfactor = -myspeed * f * g_bugrigs_steer;
226 if(myspeed < 0 && g_bugrigs_reverse_speeding)
227 accelfactor = g_bugrigs_accel;
229 accelfactor = f * g_bugrigs_accel;
230 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
236 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
240 if(!g_bugrigs_reverse_speeding)
241 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
248 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
252 if(g_bugrigs_reverse_stopping)
255 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
258 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
259 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
261 self.angles_y += steer * frametime * steerfactor; // apply steering
262 makevectors(self.angles); // new forward direction!
264 myspeed += accel * accelfactor * frametime;
266 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
270 myspeed = vlen(self.velocity);
272 // responsiveness factor for steering and acceleration
273 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
274 steerfactor = -myspeed * f;
275 self.angles_y += steer * frametime * steerfactor; // apply steering
277 rigvel = self.velocity;
278 makevectors(self.angles); // new forward direction!
281 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
282 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
283 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
284 //MAXIMA: solve(total_acceleration(v) = 0, v);
286 if(g_bugrigs_planar_movement)
288 vector rigvel_xy, neworigin, up;
291 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
295 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
298 mt = MOVE_NOMONSTERS;
300 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
301 up = trace_endpos - self.origin;
303 // BUG RIGS: align the move to the surface instead of doing collision testing
305 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
308 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
310 if(trace_fraction < 0.5)
313 neworigin = self.origin;
316 neworigin = trace_endpos;
318 if(trace_fraction < 1)
320 // now set angles_x so that the car points parallel to the surface
321 self.angles = vectoangles(
322 '1 0 0' * v_forward_x * trace_plane_normal_z
324 '0 1 0' * v_forward_y * trace_plane_normal_z
326 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
328 self.flags |= FL_ONGROUND;
332 // now set angles_x so that the car points forward, but is tilted in velocity direction
333 self.flags &~= FL_ONGROUND;
336 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
337 self.movetype = MOVETYPE_NOCLIP;
341 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
342 self.velocity = rigvel;
343 self.movetype = MOVETYPE_FLY;
347 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
348 if(trace_fraction != 1)
350 self.angles = vectoangles2(
351 '1 0 0' * v_forward_x * trace_plane_normal_z
353 '0 1 0' * v_forward_y * trace_plane_normal_z
355 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
363 vel_local_x = v_forward * self.velocity;
364 vel_local_y = v_right * self.velocity;
365 vel_local_z = v_up * self.velocity;
367 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
368 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
372 vector vf1, vu1, smoothangles;
373 makevectors(self.angles);
374 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
379 makevectors(angles_save);
380 vf1 = vf1 + v_forward * (1 - f);
381 vu1 = vu1 + v_up * (1 - f);
382 smoothangles = vectoangles2(vf1, vu1);
383 self.angles_x = -smoothangles_x;
384 self.angles_z = smoothangles_z;
387 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
389 float zspeed, xyspeed, dot, k;
391 if(self.movement_x == 0 || self.movement_y != 0)
392 return; // can't control movement if not moving forward or backward
394 zspeed = self.velocity_z;
396 xyspeed = vlen(self.velocity);
397 self.velocity = normalize(self.velocity);
399 dot = self.velocity * wishdir;
401 k *= sv_aircontrol*dot*dot*frametime;
403 if(dot > 0) // we can't change direction while slowing down
404 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
406 self.velocity = self.velocity * xyspeed;
407 self.velocity_z = zspeed;
410 void PM_Accelerate(vector wishdir, float wishspeed, float accel, float accelqw, float sidefric)
417 vel_straight = self.velocity * wishdir;
418 vel_z = self.velocity_z;
419 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
421 addspeed = wishspeed - vel_straight;
423 vel_straight = vel_straight + min(addspeed, accel * frametime * wishspeed) * accelqw;
425 vel_straight = vel_straight + min(wishspeed, accel * frametime * wishspeed) * (1 - accelqw);
427 vel_perpend = vel_perpend * (1 - frametime * wishspeed * sidefric);
429 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
432 void PM_AirAccelerate(vector wishdir, float wishspeed)
434 vector curvel, wishvel, acceldir, curdir;
435 float addspeed, accelspeed, curspeed, f;
441 curvel = self.velocity;
443 curspeed = vlen(curvel);
445 if(wishspeed > curspeed * 1.01)
447 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
451 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
452 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
454 wishvel = wishdir * wishspeed;
455 acceldir = wishvel - curvel;
456 addspeed = vlen(acceldir);
457 acceldir = normalize(acceldir);
459 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
461 if(sv_warsowbunny_backtosideratio < 1)
463 curdir = normalize(curvel);
464 dot = acceldir * curdir;
466 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
469 self.velocity += accelspeed * acceldir;
472 .vector movement_old;
475 .string lastclassname;
477 void Nixnex_GiveCurrentWeapon();
478 .float() PlayerPhysplug;
480 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
481 .float specialcommand_pos;
482 void SpecialCommand()
487 if(sv_cheats || self.maycheat)
490 print("A hollow voice says \"Plugh\".\n");
494 void SV_PlayerPhysics()
496 local vector wishvel, wishdir, v;
497 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, shtest_score, buttons;
500 float not_allowed_to_move;
505 // if record times matter
506 // ensure nothing EVIL is being done (i.e. strafebot)
507 // this hinders joystick users though
508 // but it still gives SOME analog control
509 // TODO implement this for engine cl_movement code too (basically, clipping to the four axes)
510 wishvel_x = fabs(self.movement_x);
511 wishvel_y = fabs(self.movement_y);
513 wishspeed = vlen(wishvel);
514 if(wishvel_x >= 2 * wishvel_y)
517 if(self.movement_x > 0)
518 self.movement_x = wishspeed;
520 self.movement_x = -wishspeed;
523 else if(wishvel_y >= 2 * wishvel_x)
527 if(self.movement_y > 0)
528 self.movement_y = wishspeed;
530 self.movement_y = -wishspeed;
535 if(self.movement_x > 0)
536 self.movement_x = 0.70710678118654752440 * wishspeed;
538 self.movement_x = -0.70710678118654752440 * wishspeed;
539 if(self.movement_y > 0)
540 self.movement_y = 0.70710678118654752440 * wishspeed;
542 self.movement_y = -0.70710678118654752440 * wishspeed;
546 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);
550 else if(buttons == 1)
552 else if(buttons == 2)
554 else if(buttons == 128)
556 else if(buttons == 256)
558 else if(buttons == 512)
560 else if(buttons == 1024)
565 if(c == substring(specialcommand, self.specialcommand_pos, 1))
567 self.specialcommand_pos += 1;
568 if(self.specialcommand_pos >= strlen(specialcommand))
570 self.specialcommand_pos = 0;
575 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
576 self.specialcommand_pos = 0;
578 if(self.PlayerPhysplug)
579 if(self.PlayerPhysplug())
582 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
584 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
585 self.parm_idlesince = time;
587 buttons_prev = self.buttons_old;
588 self.buttons_old = buttons;
589 self.movement_old = self.movement;
590 self.v_angle_old = self.v_angle;
592 if(time < self.nickspamtime)
593 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
595 // slight annoyance for nick change scripts
596 self.movement = -1 * self.movement;
597 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
599 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!
601 self.angles_x = random() * 360;
602 self.angles_y = random() * 360;
603 // at least I'm not forcing retardedview by also assigning to angles_z
608 if(time > self.shtest_next)
610 if(self.shtest_next > 0)
612 // self.shtest_accumulator:
613 // started at time - SHTEST_DELTA
614 // should be at SHTEST_DELTA
615 shtest_score = self.shtest_accumulator / (SHTEST_DELTA + time - self.shtest_next);
616 if(shtest_score > SHTEST_THRESHOLD)
617 print("TIME PARADOX: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
618 else if(cvar("developer_shtest"))
619 dprint("okay: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
621 self.shtest_next = time + SHTEST_DELTA;
622 self.shtest_accumulator = 0;
624 self.shtest_accumulator += frametime;
626 if (clienttype(self) == CLIENTTYPE_BOT)
629 self.items &~= IT_USING_JETPACK;
631 if(self.classname == "player")
633 if(self.race_penalty)
634 if(time > self.race_penalty)
635 self.race_penalty = 0;
637 not_allowed_to_move = 0;
638 if(self.race_penalty)
639 not_allowed_to_move = 1;
640 if(!cvar("sv_ready_restart_after_countdown"))
641 if(time < game_starttime)
642 not_allowed_to_move = 1;
644 if(not_allowed_to_move)
646 self.velocity = '0 0 0';
647 self.movetype = MOVETYPE_NONE;
648 self.disableclientprediction = 2;
650 else if(self.disableclientprediction == 2)
652 if(self.movetype == MOVETYPE_NONE)
653 self.movetype = MOVETYPE_WALK;
654 self.disableclientprediction = 0;
658 if (self.movetype == MOVETYPE_NONE)
661 if (self.punchangle != '0 0 0')
663 f = vlen(self.punchangle) - 10 * frametime;
665 self.punchangle = normalize(self.punchangle) * f;
667 self.punchangle = '0 0 0';
670 if (self.punchvector != '0 0 0')
672 f = vlen(self.punchvector) - 30 * frametime;
674 self.punchvector = normalize(self.punchvector) * f;
676 self.punchvector = '0 0 0';
683 if(self.runes & RUNE_SPEED)
685 if(self.runes & CURSE_SLOW)
686 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
688 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
690 else if(self.runes & CURSE_SLOW)
692 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
696 if(g_minstagib && (self.items & IT_INVINCIBLE))
698 maxspd_mod = cvar("g_minstagib_speed_moverate");
701 if(g_nexball && self.ballcarried)
703 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
708 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
711 if(self.classname != "player")
713 maxspd_mod = cvar("sv_spectator_speed_multiplier");
714 if(!self.spectatorspeed)
715 self.spectatorspeed = maxspd_mod;
716 if(self.impulse && self.impulse <= 19)
718 if(self.lastclassname != "player")
720 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
721 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
722 else if(self.impulse == 11)
723 self.spectatorspeed = maxspd_mod;
724 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
725 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
726 else if(self.impulse >= 1 && self.impulse <= 9)
727 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
728 } // otherwise just clear
731 maxspd_mod = self.spectatorspeed;
734 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
735 if(self.speed != spd)
739 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
740 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
741 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
742 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
745 maxspd_mod *= swampspd_mod; // only one common speed modder please!
748 // if dead, behave differently
752 if (!self.fixangle && !g_bugrigs)
755 self.angles_y = self.v_angle_y;
759 if(self.flags & FL_ONGROUND)
764 if(self.waterlevel < WATERLEVEL_SWIMMING)
765 if(time >= self.ladder_time)
768 self.nextstep = time + 0.3 + random() * 0.1;
769 trace_dphitq3surfaceflags = 0;
770 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
771 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
773 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
774 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
776 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
784 if(self.classname == "player")
788 self.flags &~= FL_ONGROUND;
789 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 1', MOVE_NORMAL, self);
790 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
791 self.flags |= FL_ONGROUND;
794 if (self.BUTTON_JUMP)
797 self.flags |= FL_JUMPRELEASED;
799 if (self.waterlevel == WATERLEVEL_SWIMMING)
803 if (self.flags & FL_WATERJUMP )
805 self.velocity_x = self.movedir_x;
806 self.velocity_y = self.movedir_y;
807 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
809 self.flags &~= FL_WATERJUMP;
810 self.teleport_time = 0;
813 else if (g_bugrigs && self.classname == "player")
817 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
819 // noclipping or flying
820 self.flags &~= FL_ONGROUND;
822 self.velocity = self.velocity * (1 - frametime * sv_friction);
823 makevectors(self.v_angle);
824 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
825 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
827 wishdir = normalize(wishvel);
828 wishspeed = vlen(wishvel);
829 if (wishspeed > sv_maxspeed*maxspd_mod)
830 wishspeed = sv_maxspeed*maxspd_mod;
831 if (time >= self.teleport_time)
832 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
834 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
837 self.flags &~= FL_ONGROUND;
839 makevectors(self.v_angle);
840 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
841 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
842 if (wishvel == '0 0 0')
843 wishvel = '0 0 -60'; // drift towards bottom
845 wishdir = normalize(wishvel);
846 wishspeed = vlen(wishvel);
847 if (wishspeed > sv_maxspeed*maxspd_mod)
848 wishspeed = sv_maxspeed*maxspd_mod;
849 wishspeed = wishspeed * 0.7;
852 self.velocity = self.velocity * (1 - frametime * sv_friction);
854 // water acceleration
855 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
857 else if (time < self.ladder_time)
859 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
860 self.flags &~= FL_ONGROUND;
862 self.velocity = self.velocity * (1 - frametime * sv_friction);
863 makevectors(self.v_angle);
864 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
865 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
867 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
869 self.velocity_z = self.velocity_z + sv_gravity * frametime;
870 if (self.ladder_entity.classname == "func_water")
873 if (f > self.ladder_entity.speed)
874 wishvel = wishvel * (self.ladder_entity.speed / f);
876 self.watertype = self.ladder_entity.skin;
877 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
878 if ((self.origin_z + self.view_ofs_z) < f)
879 self.waterlevel = WATERLEVEL_SUBMERGED;
880 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
881 self.waterlevel = WATERLEVEL_SWIMMING;
882 else if ((self.origin_z + self.mins_z + 1) < f)
883 self.waterlevel = WATERLEVEL_WETFEET;
886 self.waterlevel = WATERLEVEL_NONE;
887 self.watertype = CONTENT_EMPTY;
891 wishdir = normalize(wishvel);
892 wishspeed = vlen(wishvel);
893 if (wishspeed > sv_maxspeed*maxspd_mod)
894 wishspeed = sv_maxspeed*maxspd_mod;
895 if (time >= self.teleport_time)
897 // water acceleration
898 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
901 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
903 //makevectors(self.v_angle_y * '0 1 0');
904 makevectors(self.v_angle);
905 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
906 // add remaining speed as Z component
907 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
909 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
910 // add the unused velocity as up component
913 // if(self.BUTTON_JUMP)
914 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
916 // it is now normalized, so...
917 float a_side, a_up, a_add, a_diff;
918 a_side = cvar("g_jetpack_acceleration_side");
919 a_up = cvar("g_jetpack_acceleration_up");
920 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
929 //////////////////////////////////////////////////////////////////////////////////////
930 // finding the maximum over all vectors of above form
931 // with wishvel having an absolute value of 1
932 //////////////////////////////////////////////////////////////////////////////////////
933 // we're finding the maximum over
934 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
935 // for z in the range from -1 to 1
936 //////////////////////////////////////////////////////////////////////////////////////
937 // maximum is EITHER attained at the single extreme point:
938 a_diff = a_side * a_side - a_up * a_up;
941 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
942 if(f > -1 && f < 1) // can it be attained?
944 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
948 // OR attained at z = 1:
949 f = (a_up + a_add) * (a_up + a_add);
955 // OR attained at z = -1:
956 f = (a_up - a_add) * (a_up - a_add);
963 //////////////////////////////////////////////////////////////////////////////////////
965 //print("best possible acceleration: ", ftos(best), "\n");
968 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
969 if(wishvel_z - sv_gravity > 0)
970 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
972 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
975 fvel = vlen(wishvel);
978 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
980 fvel = min(1, vlen(wishvel) / best);
981 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
982 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
986 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
988 if (f > 0 && wishvel != '0 0 0')
990 self.velocity = self.velocity + wishvel * f * frametime;
991 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
992 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
993 self.flags &~= FL_ONGROUND;
994 self.items |= IT_USING_JETPACK;
996 // jetpack also inhibits health regeneration, but only for 1 second
997 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1000 else if (self.flags & FL_ONGROUND)
1002 // we get here if we ran out of ammo
1003 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1004 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1007 makevectors(self.v_angle_y * '0 1 0');
1008 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1010 if(!(self.lastflags & FL_ONGROUND))
1012 if(cvar("speedmeter"))
1013 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1014 if(self.lastground < time - 0.3)
1015 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1016 if(self.jumppadcount > 1)
1017 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1018 self.jumppadcount = 0;
1021 #ifdef LETS_TEST_FTEQCC
1022 if(self.velocity_x || self.velocity_y)
1040 if (f < sv_stopspeed)
1041 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
1043 f = 1 - frametime * sv_friction;
1045 self.velocity = self.velocity * f;
1047 self.velocity = '0 0 0';
1051 wishdir = normalize(wishvel);
1052 wishspeed = vlen(wishvel);
1053 if (wishspeed > sv_maxspeed*maxspd_mod)
1054 wishspeed = sv_maxspeed*maxspd_mod;
1056 wishspeed = wishspeed * 0.5;
1057 if (time >= self.teleport_time)
1058 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
1062 // we get here if we ran out of ammo
1063 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1064 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1068 maxairspd = sv_maxairspeed*maxspd_mod;
1069 airaccel = sv_airaccelerate*maxspd_mod;
1073 maxairspd = sv_maxairspeed;
1074 airaccel = sv_airaccelerate;
1077 makevectors(self.v_angle_y * '0 1 0');
1078 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1080 wishdir = normalize(wishvel);
1081 wishspeed = vlen(wishvel);
1082 if (wishspeed > maxairspd)
1083 wishspeed = maxairspd;
1085 wishspeed = wishspeed * 0.5;
1086 if (time >= self.teleport_time)
1092 airaccelqw = sv_airaccel_qw;
1093 accelerating = (self.velocity * wishdir > 0);
1094 wishspeed2 = wishspeed;
1097 if(sv_airstopaccelerate)
1098 if(self.velocity * wishdir < 0)
1099 airaccel = sv_airstopaccelerate*maxspd_mod;
1100 if(self.movement_x == 0 && self.movement_y != 0)
1102 if(sv_maxairstrafespeed)
1104 wishspeed = min(wishspeed, sv_maxairstrafespeed*maxspd_mod);
1105 if(sv_maxairstrafespeed < sv_maxairspeed)
1108 if(sv_airstrafeaccelerate)
1110 airaccel = sv_airstrafeaccelerate*maxspd_mod;
1111 if(sv_airstrafeaccelerate > sv_airaccelerate)
1117 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1118 PM_AirAccelerate(wishdir, wishspeed);
1120 PM_Accelerate(wishdir, wishspeed, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd);
1123 CPM_PM_Aircontrol(wishdir, wishspeed2);
1128 if(self.flags & FL_ONGROUND)
1129 self.lastground = time;
1131 self.lastflags = self.flags;
1132 self.lastclassname = self.classname;