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 = TRUE; // restart jump anim next time
135 void CheckWaterJump()
137 local vector start, end;
139 // check for a jump-out-of-water
140 makevectors (self.angles);
142 start_z = start_z + 8;
144 normalize(v_forward);
145 end = start + v_forward*24;
146 traceline (start, end, TRUE, self);
147 if (trace_fraction < 1)
149 start_z = start_z + self.maxs_z - 8;
150 end = start + v_forward*24;
151 self.movedir = trace_plane_normal * -50;
152 traceline (start, end, TRUE, self);
153 if (trace_fraction == 1)
154 { // open at eye level
155 self.flags |= FL_WATERJUMP;
156 self.velocity_z = 225;
157 self.flags &~= FL_JUMPRELEASED;
158 self.teleport_time = time + 2; // safety net
164 float racecar_angle(float forward, float down)
166 float ret, angle_mult;
174 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
176 angle_mult = forward / (800 + forward);
179 return ret * angle_mult + 360 * (1 - angle_mult);
181 return ret * angle_mult;
184 void RaceCarPhysics()
186 // using this move type for "big rigs"
187 // the engine does not push the entity!
189 float accel, steer, f;
190 vector angles_save, rigvel;
192 angles_save = self.angles;
193 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
194 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
196 if(g_bugrigs_reverse_speeding)
200 // back accel is DIGITAL
201 // to prevent speedhack
211 makevectors(self.angles); // new forward direction!
213 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
215 float myspeed, upspeed, steerfactor, accelfactor;
217 myspeed = self.velocity * v_forward;
218 upspeed = self.velocity * v_up;
220 // responsiveness factor for steering and acceleration
221 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
222 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
224 if(myspeed < 0 && g_bugrigs_reverse_spinning)
225 steerfactor = -myspeed * g_bugrigs_steer;
227 steerfactor = -myspeed * f * g_bugrigs_steer;
229 if(myspeed < 0 && g_bugrigs_reverse_speeding)
230 accelfactor = g_bugrigs_accel;
232 accelfactor = f * g_bugrigs_accel;
233 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
239 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
243 if(!g_bugrigs_reverse_speeding)
244 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
251 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
255 if(g_bugrigs_reverse_stopping)
258 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
261 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
262 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
264 self.angles_y += steer * frametime * steerfactor; // apply steering
265 makevectors(self.angles); // new forward direction!
267 myspeed += accel * accelfactor * frametime;
269 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
273 myspeed = vlen(self.velocity);
275 // responsiveness factor for steering and acceleration
276 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
277 steerfactor = -myspeed * f;
278 self.angles_y += steer * frametime * steerfactor; // apply steering
280 rigvel = self.velocity;
281 makevectors(self.angles); // new forward direction!
284 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
285 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
286 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
287 //MAXIMA: solve(total_acceleration(v) = 0, v);
289 if(g_bugrigs_planar_movement)
291 vector rigvel_xy, neworigin, up;
294 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
298 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
301 mt = MOVE_NOMONSTERS;
303 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
304 up = trace_endpos - self.origin;
306 // BUG RIGS: align the move to the surface instead of doing collision testing
308 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
311 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
313 if(trace_fraction < 0.5)
316 neworigin = self.origin;
319 neworigin = trace_endpos;
321 if(trace_fraction < 1)
323 // now set angles_x so that the car points parallel to the surface
324 self.angles = vectoangles(
325 '1 0 0' * v_forward_x * trace_plane_normal_z
327 '0 1 0' * v_forward_y * trace_plane_normal_z
329 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
331 self.flags |= FL_ONGROUND;
335 // now set angles_x so that the car points forward, but is tilted in velocity direction
336 self.flags &~= FL_ONGROUND;
339 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
340 self.movetype = MOVETYPE_NOCLIP;
344 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
345 self.velocity = rigvel;
346 self.movetype = MOVETYPE_FLY;
350 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
351 if(trace_fraction != 1)
353 self.angles = vectoangles2(
354 '1 0 0' * v_forward_x * trace_plane_normal_z
356 '0 1 0' * v_forward_y * trace_plane_normal_z
358 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
366 vel_local_x = v_forward * self.velocity;
367 vel_local_y = v_right * self.velocity;
368 vel_local_z = v_up * self.velocity;
370 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
371 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
375 vector vf1, vu1, smoothangles;
376 makevectors(self.angles);
377 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
382 makevectors(angles_save);
383 vf1 = vf1 + v_forward * (1 - f);
384 vu1 = vu1 + v_up * (1 - f);
385 smoothangles = vectoangles2(vf1, vu1);
386 self.angles_x = -smoothangles_x;
387 self.angles_z = smoothangles_z;
390 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
392 float zspeed, xyspeed, dot, k;
394 if(self.movement_x == 0 || self.movement_y != 0)
395 return; // can't control movement if not moving forward or backward
397 zspeed = self.velocity_z;
399 xyspeed = vlen(self.velocity);
400 self.velocity = normalize(self.velocity);
402 dot = self.velocity * wishdir;
404 k *= sv_aircontrol*dot*dot*frametime;
406 if(dot > 0) // we can't change direction while slowing down
407 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
409 self.velocity = self.velocity * xyspeed;
410 self.velocity_z = zspeed;
413 void PM_Accelerate(vector wishdir, float wishspeed, float accel, float accelqw, float sidefric)
420 vel_straight = self.velocity * wishdir;
421 vel_z = self.velocity_z;
422 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
424 addspeed = wishspeed - vel_straight;
426 vel_straight = vel_straight + min(addspeed, accel * frametime * wishspeed) * accelqw;
428 vel_straight = vel_straight + min(wishspeed, accel * frametime * wishspeed) * (1 - accelqw);
430 vel_perpend = vel_perpend * (1 - frametime * wishspeed * sidefric);
432 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
435 void PM_AirAccelerate(vector wishdir, float wishspeed)
437 vector curvel, wishvel, acceldir, curdir;
438 float addspeed, accelspeed, curspeed, f;
444 curvel = self.velocity;
446 curspeed = vlen(curvel);
448 if(wishspeed > curspeed * 1.01)
450 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
454 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
455 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
457 wishvel = wishdir * wishspeed;
458 acceldir = wishvel - curvel;
459 addspeed = vlen(acceldir);
460 acceldir = normalize(acceldir);
462 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
464 if(sv_warsowbunny_backtosideratio < 1)
466 curdir = normalize(curvel);
467 dot = acceldir * curdir;
469 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
472 self.velocity += accelspeed * acceldir;
475 .vector movement_old;
478 .string lastclassname;
480 void Nixnex_GiveCurrentWeapon();
481 .float() PlayerPhysplug;
483 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
484 .float specialcommand_pos;
485 void SpecialCommand()
490 if(sv_cheats || self.maycheat)
493 print("A hollow voice says \"Plugh\".\n");
497 void SV_PlayerPhysics()
499 local vector wishvel, wishdir, v;
500 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, shtest_score, buttons;
503 float not_allowed_to_move;
508 // if record times matter
509 // ensure nothing EVIL is being done (i.e. strafebot)
510 // this hinders joystick users though
511 // but it still gives SOME analog control
512 // TODO implement this for engine cl_movement code too (basically, clipping to the four axes)
513 wishvel_x = fabs(self.movement_x);
514 wishvel_y = fabs(self.movement_y);
515 if(wishvel_x != 0 && wishvel_y != 0 && wishvel_x != wishvel_y)
518 wishspeed = vlen(wishvel);
519 if(wishvel_x >= 2 * wishvel_y)
522 if(self.movement_x > 0)
523 self.movement_x = wishspeed;
525 self.movement_x = -wishspeed;
528 else if(wishvel_y >= 2 * wishvel_x)
532 if(self.movement_y > 0)
533 self.movement_y = wishspeed;
535 self.movement_y = -wishspeed;
540 if(self.movement_x > 0)
541 self.movement_x = 0.70710678118654752440 * wishspeed;
543 self.movement_x = -0.70710678118654752440 * wishspeed;
544 if(self.movement_y > 0)
545 self.movement_y = 0.70710678118654752440 * wishspeed;
547 self.movement_y = -0.70710678118654752440 * wishspeed;
552 self.race_movetime_frac += frametime;
553 f = floor(self.race_movetime_frac);
554 self.race_movetime_frac -= f;
555 self.race_movetime_count += f;
556 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
558 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);
562 else if(buttons == 1)
564 else if(buttons == 2)
566 else if(buttons == 128)
568 else if(buttons == 256)
570 else if(buttons == 512)
572 else if(buttons == 1024)
577 if(c == substring(specialcommand, self.specialcommand_pos, 1))
579 self.specialcommand_pos += 1;
580 if(self.specialcommand_pos >= strlen(specialcommand))
582 self.specialcommand_pos = 0;
587 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
588 self.specialcommand_pos = 0;
590 if(self.PlayerPhysplug)
591 if(self.PlayerPhysplug())
594 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
596 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
597 self.parm_idlesince = time;
599 buttons_prev = self.buttons_old;
600 self.buttons_old = buttons;
601 self.movement_old = self.movement;
602 self.v_angle_old = self.v_angle;
604 if(time < self.nickspamtime)
605 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
607 // slight annoyance for nick change scripts
608 self.movement = -1 * self.movement;
609 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
611 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!
613 self.angles_x = random() * 360;
614 self.angles_y = random() * 360;
615 // at least I'm not forcing retardedview by also assigning to angles_z
620 if(time > self.shtest_next)
622 if(self.shtest_next > 0)
624 // self.shtest_accumulator:
625 // started at time - SHTEST_DELTA
626 // should be at SHTEST_DELTA
627 shtest_score = self.shtest_accumulator / (SHTEST_DELTA + time - self.shtest_next);
628 if(shtest_score > SHTEST_THRESHOLD)
629 print("TIME PARADOX: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
630 else if(cvar("developer_shtest"))
631 dprint("okay: shtest for ", self.netname, " said ", ftos(shtest_score), "\n");
633 self.shtest_next = time + SHTEST_DELTA;
634 self.shtest_accumulator = 0;
636 self.shtest_accumulator += frametime;
638 if (clienttype(self) == CLIENTTYPE_BOT)
641 self.items &~= IT_USING_JETPACK;
643 if(self.classname == "player")
645 if(self.race_penalty)
646 if(time > self.race_penalty)
647 self.race_penalty = 0;
649 not_allowed_to_move = 0;
650 if(self.race_penalty)
651 not_allowed_to_move = 1;
652 if(!cvar("sv_ready_restart_after_countdown"))
653 if(time < game_starttime)
654 not_allowed_to_move = 1;
656 if(not_allowed_to_move)
658 self.velocity = '0 0 0';
659 self.movetype = MOVETYPE_NONE;
660 self.disableclientprediction = 2;
662 else if(self.disableclientprediction == 2)
664 if(self.movetype == MOVETYPE_NONE)
665 self.movetype = MOVETYPE_WALK;
666 self.disableclientprediction = 0;
670 if (self.movetype == MOVETYPE_NONE)
673 if (self.punchangle != '0 0 0')
675 f = vlen(self.punchangle) - 10 * frametime;
677 self.punchangle = normalize(self.punchangle) * f;
679 self.punchangle = '0 0 0';
682 if (self.punchvector != '0 0 0')
684 f = vlen(self.punchvector) - 30 * frametime;
686 self.punchvector = normalize(self.punchvector) * f;
688 self.punchvector = '0 0 0';
695 if(self.runes & RUNE_SPEED)
697 if(self.runes & CURSE_SLOW)
698 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
700 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
702 else if(self.runes & CURSE_SLOW)
704 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
708 if(g_minstagib && (self.items & IT_INVINCIBLE))
710 maxspd_mod = cvar("g_minstagib_speed_moverate");
713 if(g_nexball && self.ballcarried)
715 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
720 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
723 if(self.classname != "player")
725 maxspd_mod = cvar("sv_spectator_speed_multiplier");
726 if(!self.spectatorspeed)
727 self.spectatorspeed = maxspd_mod;
728 if(self.impulse && self.impulse <= 19)
730 if(self.lastclassname != "player")
732 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
733 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
734 else if(self.impulse == 11)
735 self.spectatorspeed = maxspd_mod;
736 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
737 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
738 else if(self.impulse >= 1 && self.impulse <= 9)
739 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
740 } // otherwise just clear
743 maxspd_mod = self.spectatorspeed;
746 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
747 if(self.speed != spd)
751 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
752 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
753 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
754 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
757 maxspd_mod *= swampspd_mod; // only one common speed modder please!
760 // if dead, behave differently
764 if (!self.fixangle && !g_bugrigs)
767 self.angles_y = self.v_angle_y;
771 if(self.flags & FL_ONGROUND)
776 if(self.waterlevel < WATERLEVEL_SWIMMING)
777 if(time >= self.ladder_time)
780 self.nextstep = time + 0.3 + random() * 0.1;
781 trace_dphitq3surfaceflags = 0;
782 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
783 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
785 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
786 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
788 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
796 if(self.classname == "player")
800 self.flags &~= FL_ONGROUND;
801 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 1', MOVE_NORMAL, self);
802 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
803 self.flags |= FL_ONGROUND;
806 if (self.BUTTON_JUMP)
809 self.flags |= FL_JUMPRELEASED;
811 if (self.waterlevel == WATERLEVEL_SWIMMING)
815 if (self.flags & FL_WATERJUMP )
817 self.velocity_x = self.movedir_x;
818 self.velocity_y = self.movedir_y;
819 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
821 self.flags &~= FL_WATERJUMP;
822 self.teleport_time = 0;
825 else if (g_bugrigs && self.classname == "player")
829 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
831 // noclipping or flying
832 self.flags &~= FL_ONGROUND;
834 self.velocity = self.velocity * (1 - frametime * sv_friction);
835 makevectors(self.v_angle);
836 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
837 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
839 wishdir = normalize(wishvel);
840 wishspeed = vlen(wishvel);
841 if (wishspeed > sv_maxspeed*maxspd_mod)
842 wishspeed = sv_maxspeed*maxspd_mod;
843 if (time >= self.teleport_time)
844 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
846 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
849 self.flags &~= FL_ONGROUND;
851 makevectors(self.v_angle);
852 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
853 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
854 if (wishvel == '0 0 0')
855 wishvel = '0 0 -60'; // drift towards bottom
857 wishdir = normalize(wishvel);
858 wishspeed = vlen(wishvel);
859 if (wishspeed > sv_maxspeed*maxspd_mod)
860 wishspeed = sv_maxspeed*maxspd_mod;
861 wishspeed = wishspeed * 0.7;
864 self.velocity = self.velocity * (1 - frametime * sv_friction);
866 // water acceleration
867 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
869 else if (time < self.ladder_time)
871 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
872 self.flags &~= FL_ONGROUND;
874 self.velocity = self.velocity * (1 - frametime * sv_friction);
875 makevectors(self.v_angle);
876 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
877 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
879 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
881 self.velocity_z = self.velocity_z + sv_gravity * frametime;
882 if (self.ladder_entity.classname == "func_water")
885 if (f > self.ladder_entity.speed)
886 wishvel = wishvel * (self.ladder_entity.speed / f);
888 self.watertype = self.ladder_entity.skin;
889 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
890 if ((self.origin_z + self.view_ofs_z) < f)
891 self.waterlevel = WATERLEVEL_SUBMERGED;
892 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
893 self.waterlevel = WATERLEVEL_SWIMMING;
894 else if ((self.origin_z + self.mins_z + 1) < f)
895 self.waterlevel = WATERLEVEL_WETFEET;
898 self.waterlevel = WATERLEVEL_NONE;
899 self.watertype = CONTENT_EMPTY;
903 wishdir = normalize(wishvel);
904 wishspeed = vlen(wishvel);
905 if (wishspeed > sv_maxspeed*maxspd_mod)
906 wishspeed = sv_maxspeed*maxspd_mod;
907 if (time >= self.teleport_time)
909 // water acceleration
910 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
913 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
915 //makevectors(self.v_angle_y * '0 1 0');
916 makevectors(self.v_angle);
917 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
918 // add remaining speed as Z component
919 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
921 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
922 // add the unused velocity as up component
925 // if(self.BUTTON_JUMP)
926 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
928 // it is now normalized, so...
929 float a_side, a_up, a_add, a_diff;
930 a_side = cvar("g_jetpack_acceleration_side");
931 a_up = cvar("g_jetpack_acceleration_up");
932 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
941 //////////////////////////////////////////////////////////////////////////////////////
942 // finding the maximum over all vectors of above form
943 // with wishvel having an absolute value of 1
944 //////////////////////////////////////////////////////////////////////////////////////
945 // we're finding the maximum over
946 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
947 // for z in the range from -1 to 1
948 //////////////////////////////////////////////////////////////////////////////////////
949 // maximum is EITHER attained at the single extreme point:
950 a_diff = a_side * a_side - a_up * a_up;
953 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
954 if(f > -1 && f < 1) // can it be attained?
956 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
960 // OR attained at z = 1:
961 f = (a_up + a_add) * (a_up + a_add);
967 // OR attained at z = -1:
968 f = (a_up - a_add) * (a_up - a_add);
975 //////////////////////////////////////////////////////////////////////////////////////
977 //print("best possible acceleration: ", ftos(best), "\n");
980 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
981 if(wishvel_z - sv_gravity > 0)
982 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
984 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
987 fvel = vlen(wishvel);
990 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
992 fvel = min(1, vlen(wishvel) / best);
993 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
994 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
998 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1000 if (f > 0 && wishvel != '0 0 0')
1002 self.velocity = self.velocity + wishvel * f * frametime;
1003 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1004 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
1005 self.flags &~= FL_ONGROUND;
1006 self.items |= IT_USING_JETPACK;
1008 // jetpack also inhibits health regeneration, but only for 1 second
1009 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1012 else if (self.flags & FL_ONGROUND)
1014 // we get here if we ran out of ammo
1015 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1016 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1019 makevectors(self.v_angle_y * '0 1 0');
1020 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1022 if(!(self.lastflags & FL_ONGROUND))
1024 if(cvar("speedmeter"))
1025 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1026 if(self.lastground < time - 0.3)
1027 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1028 if(self.jumppadcount > 1)
1029 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1030 self.jumppadcount = 0;
1033 #ifdef LETS_TEST_FTEQCC
1034 if(self.velocity_x || self.velocity_y)
1052 if (f < sv_stopspeed)
1053 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
1055 f = 1 - frametime * sv_friction;
1057 self.velocity = self.velocity * f;
1059 self.velocity = '0 0 0';
1063 wishdir = normalize(wishvel);
1064 wishspeed = vlen(wishvel);
1065 if (wishspeed > sv_maxspeed*maxspd_mod)
1066 wishspeed = sv_maxspeed*maxspd_mod;
1068 wishspeed = wishspeed * 0.5;
1069 if (time >= self.teleport_time)
1070 PM_Accelerate(wishdir, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
1074 // we get here if we ran out of ammo
1075 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1076 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1080 maxairspd = sv_maxairspeed*maxspd_mod;
1081 airaccel = sv_airaccelerate*maxspd_mod;
1085 maxairspd = sv_maxairspeed;
1086 airaccel = sv_airaccelerate;
1089 makevectors(self.v_angle_y * '0 1 0');
1090 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1092 wishdir = normalize(wishvel);
1093 wishspeed = vlen(wishvel);
1094 if (wishspeed > maxairspd)
1095 wishspeed = maxairspd;
1097 wishspeed = wishspeed * 0.5;
1098 if (time >= self.teleport_time)
1104 airaccelqw = sv_airaccel_qw;
1105 accelerating = (self.velocity * wishdir > 0);
1106 wishspeed2 = wishspeed;
1109 if(sv_airstopaccelerate)
1110 if(self.velocity * wishdir < 0)
1111 airaccel = sv_airstopaccelerate*maxspd_mod;
1112 if(self.movement_x == 0 && self.movement_y != 0)
1114 if(sv_maxairstrafespeed)
1116 wishspeed = min(wishspeed, sv_maxairstrafespeed*maxspd_mod);
1117 if(sv_maxairstrafespeed < sv_maxairspeed)
1120 if(sv_airstrafeaccelerate)
1122 airaccel = sv_airstrafeaccelerate*maxspd_mod;
1123 if(sv_airstrafeaccelerate > sv_airaccelerate)
1129 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1130 PM_AirAccelerate(wishdir, wishspeed);
1132 PM_Accelerate(wishdir, wishspeed, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd);
1135 CPM_PM_Aircontrol(wishdir, wishspeed2);
1140 if(self.flags & FL_ONGROUND)
1141 self.lastground = time;
1143 self.lastflags = self.flags;
1144 self.lastclassname = self.classname;