7 float sv_airaccelerate;
11 float sv_airaccel_sideways_friction;
13 float sv_airstopaccelerate;
14 float sv_airstrafeaccelerate;
15 float sv_maxairstrafespeed;
17 float sv_warsowbunny_airforwardaccel;
18 float sv_warsowbunny_accel;
19 float sv_warsowbunny_topspeed;
20 float sv_warsowbunny_turnaccel;
21 float sv_warsowbunny_backtosideratio;
24 .entity ladder_entity;
26 .float swamp_slowdown;
30 .float spectatorspeed;
32 #define SHTEST_DELTA 10
33 #define SHTEST_THRESHOLD 1.1
35 .float shtest_accumulator;
36 .float doublejump_nextjumptime;
42 When you press the jump key
45 void PlayerJump (void)
49 mjumpheight = cvar("sv_jumpvelocity");
50 if (self.waterlevel >= WATERLEVEL_SWIMMING)
52 if (self.watertype == CONTENT_WATER)
53 self.velocity_z = 200;
54 else if (self.watertype == CONTENT_SLIME)
62 if (!(self.flags & FL_ONGROUND))
66 if (!(self.flags & FL_JUMPRELEASED))
69 if(self.health <= g_bloodloss)
73 if(time < self.doublejump_nextjumptime)
78 if(self.runes & RUNE_SPEED)
80 if(self.runes & CURSE_SLOW)
81 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
83 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
85 else if(self.runes & CURSE_SLOW)
87 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
91 if(g_minstagib && (self.items & IT_INVINCIBLE))
93 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
96 if(!(self.lastflags & FL_ONGROUND))
98 if(cvar("speedmeter"))
99 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
100 if(self.lastground < time - 0.3)
101 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
102 if(self.jumppadcount > 1)
103 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
104 self.jumppadcount = 0;
107 self.velocity_z = self.velocity_z + mjumpheight;
108 self.oldvelocity_z = self.velocity_z;
110 self.flags &~= FL_ONGROUND;
111 self.flags &~= FL_JUMPRELEASED;
114 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
116 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
119 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
123 // we're moving upwards at self.velocity_z
124 // only allow jumping after we got 3 units upwards
125 // so we for sure leave the FL_ONGROUND check
127 // but as this sucks because of factoring in gravity, we'll just do it
128 // for 4 units, and constant velocity
129 self.doublejump_nextjumptime = time + 4 / max(40, self.velocity_z); // max 0.1s blocking of jumps
132 self.restart_jump = -1; // restart jump anim next time
133 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
136 void CheckWaterJump()
138 local vector start, end;
140 // check for a jump-out-of-water
141 makevectors (self.angles);
143 start_z = start_z + 8;
145 normalize(v_forward);
146 end = start + v_forward*24;
147 traceline (start, end, TRUE, self);
148 if (trace_fraction < 1)
150 start_z = start_z + self.maxs_z - 8;
151 end = start + v_forward*24;
152 self.movedir = trace_plane_normal * -50;
153 traceline (start, end, TRUE, self);
154 if (trace_fraction == 1)
155 { // open at eye level
156 self.flags |= FL_WATERJUMP;
157 self.velocity_z = 225;
158 self.flags &~= FL_JUMPRELEASED;
159 self.teleport_time = time + 2; // safety net
165 float racecar_angle(float forward, float down)
167 float ret, angle_mult;
175 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
177 angle_mult = forward / (800 + forward);
180 return ret * angle_mult + 360 * (1 - angle_mult);
182 return ret * angle_mult;
185 void RaceCarPhysics()
187 // using this move type for "big rigs"
188 // the engine does not push the entity!
190 float accel, steer, f;
191 vector angles_save, rigvel;
193 angles_save = self.angles;
194 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
195 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
197 if(g_bugrigs_reverse_speeding)
201 // back accel is DIGITAL
202 // to prevent speedhack
212 makevectors(self.angles); // new forward direction!
214 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
216 float myspeed, upspeed, steerfactor, accelfactor;
218 myspeed = self.velocity * v_forward;
219 upspeed = self.velocity * v_up;
221 // responsiveness factor for steering and acceleration
222 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
223 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
225 if(myspeed < 0 && g_bugrigs_reverse_spinning)
226 steerfactor = -myspeed * g_bugrigs_steer;
228 steerfactor = -myspeed * f * g_bugrigs_steer;
230 if(myspeed < 0 && g_bugrigs_reverse_speeding)
231 accelfactor = g_bugrigs_accel;
233 accelfactor = f * g_bugrigs_accel;
234 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
240 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
244 if(!g_bugrigs_reverse_speeding)
245 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
252 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
256 if(g_bugrigs_reverse_stopping)
259 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
262 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
263 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
265 self.angles_y += steer * frametime * steerfactor; // apply steering
266 makevectors(self.angles); // new forward direction!
268 myspeed += accel * accelfactor * frametime;
270 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
274 myspeed = vlen(self.velocity);
276 // responsiveness factor for steering and acceleration
277 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
278 steerfactor = -myspeed * f;
279 self.angles_y += steer * frametime * steerfactor; // apply steering
281 rigvel = self.velocity;
282 makevectors(self.angles); // new forward direction!
285 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
286 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
287 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
288 //MAXIMA: solve(total_acceleration(v) = 0, v);
290 if(g_bugrigs_planar_movement)
292 vector rigvel_xy, neworigin, up;
295 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
299 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
302 mt = MOVE_NOMONSTERS;
304 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
305 up = trace_endpos - self.origin;
307 // BUG RIGS: align the move to the surface instead of doing collision testing
309 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
312 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
314 if(trace_fraction < 0.5)
317 neworigin = self.origin;
320 neworigin = trace_endpos;
322 if(trace_fraction < 1)
324 // now set angles_x so that the car points parallel to the surface
325 self.angles = vectoangles(
326 '1 0 0' * v_forward_x * trace_plane_normal_z
328 '0 1 0' * v_forward_y * trace_plane_normal_z
330 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
332 self.flags |= FL_ONGROUND;
336 // now set angles_x so that the car points forward, but is tilted in velocity direction
337 self.flags &~= FL_ONGROUND;
340 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
341 self.movetype = MOVETYPE_NOCLIP;
345 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
346 self.velocity = rigvel;
347 self.movetype = MOVETYPE_FLY;
351 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
352 if(trace_fraction != 1)
354 self.angles = vectoangles2(
355 '1 0 0' * v_forward_x * trace_plane_normal_z
357 '0 1 0' * v_forward_y * trace_plane_normal_z
359 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
367 vel_local_x = v_forward * self.velocity;
368 vel_local_y = v_right * self.velocity;
369 vel_local_z = v_up * self.velocity;
371 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
372 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
376 vector vf1, vu1, smoothangles;
377 makevectors(self.angles);
378 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
383 makevectors(angles_save);
384 vf1 = vf1 + v_forward * (1 - f);
385 vu1 = vu1 + v_up * (1 - f);
386 smoothangles = vectoangles2(vf1, vu1);
387 self.angles_x = -smoothangles_x;
388 self.angles_z = smoothangles_z;
391 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
393 float zspeed, xyspeed, dot, k;
395 if(self.movement_x == 0 || self.movement_y != 0)
396 return; // can't control movement if not moving forward or backward
398 zspeed = self.velocity_z;
400 xyspeed = vlen(self.velocity);
401 self.velocity = normalize(self.velocity);
403 dot = self.velocity * wishdir;
405 k *= sv_aircontrol*dot*dot*frametime;
407 if(dot > 0) // we can't change direction while slowing down
408 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
410 self.velocity = self.velocity * xyspeed;
411 self.velocity_z = zspeed;
414 void PM_Accelerate(vector wishdir, float wishspeed, float accel, float accelqw, float sidefric)
421 vel_straight = self.velocity * wishdir;
422 vel_z = self.velocity_z;
423 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
425 addspeed = wishspeed - vel_straight;
427 vel_straight = vel_straight + min(addspeed, accel * frametime * wishspeed) * accelqw;
429 vel_straight = vel_straight + min(wishspeed, accel * frametime * wishspeed) * (1 - accelqw);
431 vel_perpend = vel_perpend * (1 - frametime * wishspeed * sidefric);
433 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
436 void PM_AirAccelerate(vector wishdir, float wishspeed)
438 vector curvel, wishvel, acceldir, curdir;
439 float addspeed, accelspeed, curspeed, f;
445 curvel = self.velocity;
447 curspeed = vlen(curvel);
449 if(wishspeed > curspeed * 1.01)
451 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
455 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
456 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
458 wishvel = wishdir * wishspeed;
459 acceldir = wishvel - curvel;
460 addspeed = vlen(acceldir);
461 acceldir = normalize(acceldir);
463 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
465 if(sv_warsowbunny_backtosideratio < 1)
467 curdir = normalize(curvel);
468 dot = acceldir * curdir;
470 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
473 self.velocity += accelspeed * acceldir;
476 .vector movement_old;
479 .string lastclassname;
481 void Nixnex_GiveCurrentWeapon();
482 .float() PlayerPhysplug;
484 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
485 .float specialcommand_pos;
486 void SpecialCommand()
491 if(sv_cheats || self.maycheat)
494 print("A hollow voice says \"Plugh\".\n");
498 void SV_PlayerPhysics()
500 local vector wishvel, wishdir, v;
501 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, shtest_score, buttons;
504 float not_allowed_to_move;
509 // if record times matter
510 // ensure nothing EVIL is being done (i.e. strafebot)
511 // this hinders joystick users though
512 // but it still gives SOME analog control
513 // TODO implement this for engine cl_movement code too (basically, clipping to the four axes)
514 wishvel_x = fabs(self.movement_x);
515 wishvel_y = fabs(self.movement_y);
516 if(wishvel_x != 0 && wishvel_y != 0 && wishvel_x != wishvel_y)
519 wishspeed = vlen(wishvel);
520 if(wishvel_x >= 2 * wishvel_y)
523 if(self.movement_x > 0)
524 self.movement_x = wishspeed;
526 self.movement_x = -wishspeed;
529 else if(wishvel_y >= 2 * wishvel_x)
533 if(self.movement_y > 0)
534 self.movement_y = wishspeed;
536 self.movement_y = -wishspeed;
541 if(self.movement_x > 0)
542 self.movement_x = 0.70710678118654752440 * wishspeed;
544 self.movement_x = -0.70710678118654752440 * wishspeed;
545 if(self.movement_y > 0)
546 self.movement_y = 0.70710678118654752440 * wishspeed;
548 self.movement_y = -0.70710678118654752440 * wishspeed;
553 self.race_movetime_frac += frametime;
554 f = floor(self.race_movetime_frac);
555 self.race_movetime_frac -= f;
556 self.race_movetime_count += f;
557 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
559 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);
563 else if(buttons == 1)
565 else if(buttons == 2)
567 else if(buttons == 128)
569 else if(buttons == 256)
571 else if(buttons == 512)
573 else if(buttons == 1024)
578 if(c == substring(specialcommand, self.specialcommand_pos, 1))
580 self.specialcommand_pos += 1;
581 if(self.specialcommand_pos >= strlen(specialcommand))
583 self.specialcommand_pos = 0;
588 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
589 self.specialcommand_pos = 0;
591 if(self.PlayerPhysplug)
592 if(self.PlayerPhysplug())
595 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
597 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
598 self.parm_idlesince = time;
600 buttons_prev = self.buttons_old;
601 self.buttons_old = buttons;
602 self.movement_old = self.movement;
603 self.v_angle_old = self.v_angle;
605 if(time < self.nickspamtime)
606 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
608 // slight annoyance for nick change scripts
609 self.movement = -1 * self.movement;
610 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
612 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!
614 self.angles_x = random() * 360;
615 self.angles_y = random() * 360;
616 // at least I'm not forcing retardedview by also assigning to angles_z
621 if(time > self.shtest_next)
623 if(self.shtest_next > 0)
625 // self.shtest_accumulator:
626 // started at time - SHTEST_DELTA
627 // should be at SHTEST_DELTA
628 shtest_score = self.shtest_accumulator / (SHTEST_DELTA + time - self.shtest_next);
629 if(shtest_score > SHTEST_THRESHOLD)
630 print("TIME PARADOX: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
631 else if(cvar("developer_shtest"))
632 dprint("okay: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
634 self.shtest_next = time + SHTEST_DELTA;
635 self.shtest_accumulator = 0;
637 self.shtest_accumulator += frametime;
639 if (clienttype(self) == CLIENTTYPE_BOT)
642 self.items &~= IT_USING_JETPACK;
644 if(self.classname == "player")
646 if(self.race_penalty)
647 if(time > self.race_penalty)
648 self.race_penalty = 0;
650 not_allowed_to_move = 0;
651 if(self.race_penalty)
652 not_allowed_to_move = 1;
653 if(!cvar("sv_ready_restart_after_countdown"))
654 if(time < game_starttime)
655 not_allowed_to_move = 1;
657 if(not_allowed_to_move)
659 self.velocity = '0 0 0';
660 self.movetype = MOVETYPE_NONE;
661 self.disableclientprediction = 2;
663 else if(self.disableclientprediction == 2)
665 if(self.movetype == MOVETYPE_NONE)
666 self.movetype = MOVETYPE_WALK;
667 self.disableclientprediction = 0;
671 if (self.movetype == MOVETYPE_NONE)
674 if (self.punchangle != '0 0 0')
676 f = vlen(self.punchangle) - 10 * frametime;
678 self.punchangle = normalize(self.punchangle) * f;
680 self.punchangle = '0 0 0';
683 if (self.punchvector != '0 0 0')
685 f = vlen(self.punchvector) - 30 * frametime;
687 self.punchvector = normalize(self.punchvector) * f;
689 self.punchvector = '0 0 0';
696 if(self.runes & RUNE_SPEED)
698 if(self.runes & CURSE_SLOW)
699 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
701 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
703 else if(self.runes & CURSE_SLOW)
705 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
709 if(g_minstagib && (self.items & IT_INVINCIBLE))
711 maxspd_mod = cvar("g_minstagib_speed_moverate");
714 if(g_nexball && self.ballcarried)
716 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
721 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
724 if(self.classname != "player")
726 maxspd_mod = cvar("sv_spectator_speed_multiplier");
727 if(!self.spectatorspeed)
728 self.spectatorspeed = maxspd_mod;
729 if(self.impulse && self.impulse <= 19)
731 if(self.lastclassname != "player")
733 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
734 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
735 else if(self.impulse == 11)
736 self.spectatorspeed = maxspd_mod;
737 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
738 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
739 else if(self.impulse >= 1 && self.impulse <= 9)
740 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
741 } // otherwise just clear
744 maxspd_mod = self.spectatorspeed;
747 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
748 if(self.speed != spd)
752 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
753 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
754 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
755 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
758 maxspd_mod *= swampspd_mod; // only one common speed modder please!
761 // if dead, behave differently
765 if (!self.fixangle && !g_bugrigs)
768 self.angles_y = self.v_angle_y;
772 if(self.flags & FL_ONGROUND)
777 if(self.waterlevel < WATERLEVEL_SWIMMING)
778 if(time >= self.ladder_time)
781 self.nextstep = time + 0.3 + random() * 0.1;
782 trace_dphitq3surfaceflags = 0;
783 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
784 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
786 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
787 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
789 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
797 if(self.classname == "player")
801 self.flags &~= FL_ONGROUND;
802 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 1', MOVE_NORMAL, self);
803 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
804 self.flags |= FL_ONGROUND;
807 if (self.BUTTON_JUMP)
810 self.flags |= FL_JUMPRELEASED;
812 if (self.waterlevel == WATERLEVEL_SWIMMING)
816 if (self.flags & FL_WATERJUMP )
818 self.velocity_x = self.movedir_x;
819 self.velocity_y = self.movedir_y;
820 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
822 self.flags &~= FL_WATERJUMP;
823 self.teleport_time = 0;
826 else if (g_bugrigs && self.classname == "player")
830 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
832 // noclipping or flying
833 self.flags &~= FL_ONGROUND;
835 self.velocity = self.velocity * (1 - frametime * sv_friction);
836 makevectors(self.v_angle);
837 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
838 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
840 wishdir = normalize(wishvel);
841 wishspeed = vlen(wishvel);
842 if (wishspeed > sv_maxspeed*maxspd_mod)
843 wishspeed = sv_maxspeed*maxspd_mod;
844 if (time >= self.teleport_time)
845 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
847 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
850 self.flags &~= FL_ONGROUND;
852 makevectors(self.v_angle);
853 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
854 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
855 if (wishvel == '0 0 0')
856 wishvel = '0 0 -60'; // drift towards bottom
858 wishdir = normalize(wishvel);
859 wishspeed = vlen(wishvel);
860 if (wishspeed > sv_maxspeed*maxspd_mod)
861 wishspeed = sv_maxspeed*maxspd_mod;
862 wishspeed = wishspeed * 0.7;
865 self.velocity = self.velocity * (1 - frametime * sv_friction);
867 // water acceleration
868 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
870 else if (time < self.ladder_time)
872 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
873 self.flags &~= FL_ONGROUND;
875 self.velocity = self.velocity * (1 - frametime * sv_friction);
876 makevectors(self.v_angle);
877 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
878 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
880 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
882 self.velocity_z = self.velocity_z + sv_gravity * frametime;
883 if (self.ladder_entity.classname == "func_water")
886 if (f > self.ladder_entity.speed)
887 wishvel = wishvel * (self.ladder_entity.speed / f);
889 self.watertype = self.ladder_entity.skin;
890 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
891 if ((self.origin_z + self.view_ofs_z) < f)
892 self.waterlevel = WATERLEVEL_SUBMERGED;
893 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
894 self.waterlevel = WATERLEVEL_SWIMMING;
895 else if ((self.origin_z + self.mins_z + 1) < f)
896 self.waterlevel = WATERLEVEL_WETFEET;
899 self.waterlevel = WATERLEVEL_NONE;
900 self.watertype = CONTENT_EMPTY;
904 wishdir = normalize(wishvel);
905 wishspeed = vlen(wishvel);
906 if (wishspeed > sv_maxspeed*maxspd_mod)
907 wishspeed = sv_maxspeed*maxspd_mod;
908 if (time >= self.teleport_time)
910 // water acceleration
911 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
914 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
916 //makevectors(self.v_angle_y * '0 1 0');
917 makevectors(self.v_angle);
918 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
919 // add remaining speed as Z component
920 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
922 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
923 // add the unused velocity as up component
926 // if(self.BUTTON_JUMP)
927 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
929 // it is now normalized, so...
930 float a_side, a_up, a_add, a_diff;
931 a_side = cvar("g_jetpack_acceleration_side");
932 a_up = cvar("g_jetpack_acceleration_up");
933 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
942 //////////////////////////////////////////////////////////////////////////////////////
943 // finding the maximum over all vectors of above form
944 // with wishvel having an absolute value of 1
945 //////////////////////////////////////////////////////////////////////////////////////
946 // we're finding the maximum over
947 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
948 // for z in the range from -1 to 1
949 //////////////////////////////////////////////////////////////////////////////////////
950 // maximum is EITHER attained at the single extreme point:
951 a_diff = a_side * a_side - a_up * a_up;
954 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
955 if(f > -1 && f < 1) // can it be attained?
957 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
961 // OR attained at z = 1:
962 f = (a_up + a_add) * (a_up + a_add);
968 // OR attained at z = -1:
969 f = (a_up - a_add) * (a_up - a_add);
976 //////////////////////////////////////////////////////////////////////////////////////
978 //print("best possible acceleration: ", ftos(best), "\n");
981 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
982 if(wishvel_z - sv_gravity > 0)
983 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
985 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
988 fvel = vlen(wishvel);
991 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
993 fvel = min(1, vlen(wishvel) / best);
994 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
995 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
999 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1001 if (f > 0 && wishvel != '0 0 0')
1003 self.velocity = self.velocity + wishvel * f * frametime;
1004 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1005 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
1006 self.flags &~= FL_ONGROUND;
1007 self.items |= IT_USING_JETPACK;
1009 // jetpack also inhibits health regeneration, but only for 1 second
1010 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1013 else if (self.flags & FL_ONGROUND)
1015 // we get here if we ran out of ammo
1016 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1017 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1020 makevectors(self.v_angle_y * '0 1 0');
1021 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1023 if(!(self.lastflags & FL_ONGROUND))
1025 if(cvar("speedmeter"))
1026 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1027 if(self.lastground < time - 0.3)
1028 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1029 if(self.jumppadcount > 1)
1030 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1031 self.jumppadcount = 0;
1034 #ifdef LETS_TEST_FTEQCC
1035 if(self.velocity_x || self.velocity_y)
1053 if (f < sv_stopspeed)
1054 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
1056 f = 1 - frametime * sv_friction;
1058 self.velocity = self.velocity * f;
1060 self.velocity = '0 0 0';
1064 wishdir = normalize(wishvel);
1065 wishspeed = vlen(wishvel);
1066 if (wishspeed > sv_maxspeed*maxspd_mod)
1067 wishspeed = sv_maxspeed*maxspd_mod;
1069 wishspeed = wishspeed * 0.5;
1070 if (time >= self.teleport_time)
1071 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
1075 // we get here if we ran out of ammo
1076 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1077 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1081 maxairspd = sv_maxairspeed*maxspd_mod;
1082 airaccel = sv_airaccelerate*maxspd_mod;
1086 maxairspd = sv_maxairspeed;
1087 airaccel = sv_airaccelerate;
1090 makevectors(self.v_angle_y * '0 1 0');
1091 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1093 wishdir = normalize(wishvel);
1094 wishspeed = vlen(wishvel);
1095 if (wishspeed > maxairspd)
1096 wishspeed = maxairspd;
1098 wishspeed = wishspeed * 0.5;
1099 if (time >= self.teleport_time)
1105 airaccelqw = sv_airaccel_qw;
1106 accelerating = (self.velocity * wishdir > 0);
1107 wishspeed2 = wishspeed;
1110 if(sv_airstopaccelerate)
1111 if(self.velocity * wishdir < 0)
1112 airaccel = sv_airstopaccelerate*maxspd_mod;
1113 if(self.movement_x == 0 && self.movement_y != 0)
1115 if(sv_maxairstrafespeed)
1117 wishspeed = min(wishspeed, sv_maxairstrafespeed*maxspd_mod);
1118 if(sv_maxairstrafespeed < sv_maxairspeed)
1121 if(sv_airstrafeaccelerate)
1123 airaccel = sv_airstrafeaccelerate*maxspd_mod;
1124 if(sv_airstrafeaccelerate > sv_airaccelerate)
1130 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1131 PM_AirAccelerate(wishdir, wishspeed);
1133 PM_Accelerate(wishdir, wishspeed, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd);
1136 CPM_PM_Aircontrol(wishdir, wishspeed2);
1141 if(self.flags & FL_ONGROUND)
1142 self.lastground = time;
1144 self.lastflags = self.flags;
1145 self.lastclassname = self.classname;