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 .float doublejump_nextjumptime;
38 When you press the jump key
41 void PlayerJump (void)
45 mjumpheight = cvar("sv_jumpvelocity");
46 if (self.waterlevel >= WATERLEVEL_SWIMMING)
48 if (self.watertype == CONTENT_WATER)
49 self.velocity_z = 200;
50 else if (self.watertype == CONTENT_SLIME)
58 if (!(self.flags & FL_ONGROUND))
62 if (!(self.flags & FL_JUMPRELEASED))
65 if(self.health <= g_bloodloss)
69 if(time < self.doublejump_nextjumptime)
74 if(self.runes & RUNE_SPEED)
76 if(self.runes & CURSE_SLOW)
77 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
79 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
81 else if(self.runes & CURSE_SLOW)
83 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
87 if(g_minstagib && (self.items & IT_INVINCIBLE))
89 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
92 if(!(self.lastflags & FL_ONGROUND))
94 if(cvar("speedmeter"))
95 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
96 if(self.lastground < time - 0.3)
97 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
98 if(self.jumppadcount > 1)
99 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
100 self.jumppadcount = 0;
103 self.velocity_z = self.velocity_z + mjumpheight;
104 self.oldvelocity_z = self.velocity_z;
106 self.flags &~= FL_ONGROUND;
107 self.flags &~= FL_JUMPRELEASED;
110 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
112 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
115 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
119 // we're moving upwards at self.velocity_z
120 // only allow jumping after we got 3 units upwards
121 // so we for sure leave the FL_ONGROUND check
123 // but as this sucks because of factoring in gravity, we'll just do it
124 // for 4 units, and constant velocity
125 self.doublejump_nextjumptime = time + 4 / max(40, self.velocity_z); // max 0.1s blocking of jumps
128 self.restart_jump = -1; // restart jump anim next time
129 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
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 wishspeed0, float accel, float accelqw, float sidefric)
418 if(cvar("sv_gameplayfix_q2airaccelerate"))
419 wishspeed0 = wishspeed;
421 savespeed = self.velocity * self.velocity;
423 vel_straight = self.velocity * wishdir;
424 vel_z = self.velocity_z;
425 vel_perpend = self.velocity - vel_straight * wishdir - vel_z * '0 0 1';
428 if(cvar("sv_gameplayfix_alternatespeedclamp"))
430 // 1. move as normal, but fake a forward move to get the maximum ALLOWED speed
432 vel_xy = sqrt(vel_straight * vel_straight + vel_perpend * vel_perpend);
433 addspeed = wishspeed - vel_xy;
435 vel_xy = vel_xy + min(addspeed, accel * frametime * wishspeed0) * accelqw;
437 vel_xy = vel_xy + accel * frametime * wishspeed0 * (1 - accelqw);
438 // 2. accelerate actually, using our acceleration factor and the max allowed forward speed we derived
439 // we may add at most a vector length of min(wishspeed, accel * frametime * wishspeed0)
440 // however, the absolute value must not exceed vel_xy
441 addspeed = accel * frametime * wishspeed0;
442 addspeed = bound(0, sqrt(vel_xy * vel_xy - vel_perpend * vel_perpend) - vel_straight, addspeed);
443 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
444 // this is how much we can add without exceeding vel_xy
445 vel_straight += addspeed;
450 addspeed = wishspeed - vel_straight;
452 vel_straight = vel_straight + min(addspeed, accel * frametime * wishspeed0) * accelqw;
454 vel_straight = vel_straight + accel * frametime * wishspeed0 * (1 - accelqw);
457 if(sidefric < 0 && (vel_perpend*vel_perpend))
460 f = (1 - frametime * wishspeed * sidefric);
461 fminimum = (savespeed - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
463 vel_perpend = vel_perpend * f;
465 vel_perpend = vel_perpend * min(1, max(fminimum, f));
468 vel_perpend = vel_perpend * (1 - frametime * wishspeed * sidefric);
470 self.velocity = vel_straight * wishdir + vel_z * '0 0 1' + vel_perpend;
473 void PM_AirAccelerate(vector wishdir, float wishspeed)
475 vector curvel, wishvel, acceldir, curdir;
476 float addspeed, accelspeed, curspeed, f;
482 curvel = self.velocity;
484 curspeed = vlen(curvel);
486 if(wishspeed > curspeed * 1.01)
488 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
492 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
493 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
495 wishvel = wishdir * wishspeed;
496 acceldir = wishvel - curvel;
497 addspeed = vlen(acceldir);
498 acceldir = normalize(acceldir);
500 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
502 if(sv_warsowbunny_backtosideratio < 1)
504 curdir = normalize(curvel);
505 dot = acceldir * curdir;
507 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
510 self.velocity += accelspeed * acceldir;
513 .vector movement_old;
516 .string lastclassname;
518 void Nixnex_GiveCurrentWeapon();
519 .float() PlayerPhysplug;
521 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
522 .float specialcommand_pos;
523 void SpecialCommand()
528 if(!CheatImpulse(99))
529 print("A hollow voice says \"Plugh\".\n");
533 float speedaward_speed;
534 string speedaward_holder;
535 void race_send_speedaward(float msg)
537 // send the best speed of the round
538 WriteByte(msg, SVC_TEMPENTITY);
539 WriteByte(msg, TE_CSQC_RACE);
540 WriteByte(msg, RACE_NET_SPEED_AWARD);
541 WriteShort(msg, floor(speedaward_speed+0.5));
542 WriteString(msg, speedaward_holder);
545 float speedaward_alltimebest;
546 string speedaward_alltimebest_holder;
547 void race_send_speedaward_alltimebest(float msg)
549 // send the best speed
550 WriteByte(msg, SVC_TEMPENTITY);
551 WriteByte(msg, TE_CSQC_RACE);
552 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
553 WriteShort(msg, floor(speedaward_alltimebest+0.5));
554 WriteString(msg, speedaward_alltimebest_holder);
557 string GetMapname(void);
558 float speedaward_lastupdate;
559 float speedaward_lastsent;
560 void SV_PlayerPhysics()
562 local vector wishvel, wishdir, v;
563 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
566 float not_allowed_to_move;
569 if(self.PlayerPhysplug)
570 if(self.PlayerPhysplug())
573 self.race_movetime_frac += frametime;
574 f = floor(self.race_movetime_frac);
575 self.race_movetime_frac -= f;
576 self.race_movetime_count += f;
577 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
581 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);
585 else if(buttons == 1)
587 else if(buttons == 2)
589 else if(buttons == 128)
591 else if(buttons == 256)
593 else if(buttons == 512)
595 else if(buttons == 1024)
600 if(c == substring(specialcommand, self.specialcommand_pos, 1))
602 self.specialcommand_pos += 1;
603 if(self.specialcommand_pos >= strlen(specialcommand))
605 self.specialcommand_pos = 0;
610 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
611 self.specialcommand_pos = 0;
613 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
615 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
616 self.parm_idlesince = time;
618 buttons_prev = self.buttons_old;
619 self.buttons_old = buttons;
620 self.movement_old = self.movement;
621 self.v_angle_old = self.v_angle;
623 if(time < self.nickspamtime)
624 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
626 // slight annoyance for nick change scripts
627 self.movement = -1 * self.movement;
628 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
630 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!
632 self.angles_x = random() * 360;
633 self.angles_y = random() * 360;
634 // at least I'm not forcing retardedview by also assigning to angles_z
639 if (self.punchangle != '0 0 0')
641 f = vlen(self.punchangle) - 10 * frametime;
643 self.punchangle = normalize(self.punchangle) * f;
645 self.punchangle = '0 0 0';
648 if (self.punchvector != '0 0 0')
650 f = vlen(self.punchvector) - 30 * frametime;
652 self.punchvector = normalize(self.punchvector) * f;
654 self.punchvector = '0 0 0';
657 if (clienttype(self) == CLIENTTYPE_BOT)
659 if(playerdemo_read())
664 self.items &~= IT_USING_JETPACK;
666 if(self.classname == "player")
668 if(self.race_penalty)
669 if(time > self.race_penalty)
670 self.race_penalty = 0;
672 not_allowed_to_move = 0;
673 if(self.race_penalty)
674 not_allowed_to_move = 1;
675 if(!cvar("sv_ready_restart_after_countdown"))
676 if(time < game_starttime)
677 not_allowed_to_move = 1;
679 if(not_allowed_to_move)
681 self.velocity = '0 0 0';
682 self.movetype = MOVETYPE_NONE;
683 self.disableclientprediction = 2;
685 else if(self.disableclientprediction == 2)
687 if(self.movetype == MOVETYPE_NONE)
688 self.movetype = MOVETYPE_WALK;
689 self.disableclientprediction = 0;
693 if (self.movetype == MOVETYPE_NONE)
700 if(self.runes & RUNE_SPEED)
702 if(self.runes & CURSE_SLOW)
703 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
705 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
707 else if(self.runes & CURSE_SLOW)
709 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
713 if(g_minstagib && (self.items & IT_INVINCIBLE))
715 maxspd_mod = cvar("g_minstagib_speed_moverate");
718 if(g_nexball && self.ballcarried)
720 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
725 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
728 if(self.classname != "player")
730 maxspd_mod = cvar("sv_spectator_speed_multiplier");
731 if(!self.spectatorspeed)
732 self.spectatorspeed = maxspd_mod;
733 if(self.impulse && self.impulse <= 19)
735 if(self.lastclassname != "player")
737 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
738 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
739 else if(self.impulse == 11)
740 self.spectatorspeed = maxspd_mod;
741 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
742 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
743 else if(self.impulse >= 1 && self.impulse <= 9)
744 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
745 } // otherwise just clear
748 maxspd_mod = self.spectatorspeed;
751 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
752 if(self.speed != spd)
756 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
757 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
758 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
759 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
762 maxspd_mod *= swampspd_mod; // only one common speed modder please!
765 // if dead, behave differently
769 if (!self.fixangle && !g_bugrigs)
772 self.angles_y = self.v_angle_y;
776 if(self.flags & FL_ONGROUND)
781 if(self.waterlevel < WATERLEVEL_SWIMMING)
782 if(time >= self.ladder_time)
785 self.nextstep = time + 0.3 + random() * 0.1;
786 trace_dphitq3surfaceflags = 0;
787 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
788 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
790 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
791 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
793 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
801 if(self.classname == "player")
805 self.flags &~= FL_ONGROUND;
806 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 1', MOVE_NORMAL, self);
807 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
808 self.flags |= FL_ONGROUND;
811 if (self.BUTTON_JUMP)
814 self.flags |= FL_JUMPRELEASED;
816 if (self.waterlevel == WATERLEVEL_SWIMMING)
820 if (self.flags & FL_WATERJUMP )
822 self.velocity_x = self.movedir_x;
823 self.velocity_y = self.movedir_y;
824 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
826 self.flags &~= FL_WATERJUMP;
827 self.teleport_time = 0;
830 else if (g_bugrigs && self.classname == "player")
834 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
836 // noclipping or flying
837 self.flags &~= FL_ONGROUND;
839 self.velocity = self.velocity * (1 - frametime * sv_friction);
840 makevectors(self.v_angle);
841 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
842 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
844 wishdir = normalize(wishvel);
845 wishspeed = vlen(wishvel);
846 if (wishspeed > sv_maxspeed*maxspd_mod)
847 wishspeed = sv_maxspeed*maxspd_mod;
848 if (time >= self.teleport_time)
849 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
851 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
854 self.flags &~= FL_ONGROUND;
856 makevectors(self.v_angle);
857 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
858 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
859 if (wishvel == '0 0 0')
860 wishvel = '0 0 -60'; // drift towards bottom
862 wishdir = normalize(wishvel);
863 wishspeed = vlen(wishvel);
864 if (wishspeed > sv_maxspeed*maxspd_mod)
865 wishspeed = sv_maxspeed*maxspd_mod;
866 wishspeed = wishspeed * 0.7;
869 self.velocity = self.velocity * (1 - frametime * sv_friction);
871 // water acceleration
872 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
874 else if (time < self.ladder_time)
876 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
877 self.flags &~= FL_ONGROUND;
879 self.velocity = self.velocity * (1 - frametime * sv_friction);
880 makevectors(self.v_angle);
881 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
882 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
884 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
886 self.velocity_z = self.velocity_z + sv_gravity * frametime;
887 if (self.ladder_entity.classname == "func_water")
890 if (f > self.ladder_entity.speed)
891 wishvel = wishvel * (self.ladder_entity.speed / f);
893 self.watertype = self.ladder_entity.skin;
894 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
895 if ((self.origin_z + self.view_ofs_z) < f)
896 self.waterlevel = WATERLEVEL_SUBMERGED;
897 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
898 self.waterlevel = WATERLEVEL_SWIMMING;
899 else if ((self.origin_z + self.mins_z + 1) < f)
900 self.waterlevel = WATERLEVEL_WETFEET;
903 self.waterlevel = WATERLEVEL_NONE;
904 self.watertype = CONTENT_EMPTY;
908 wishdir = normalize(wishvel);
909 wishspeed = vlen(wishvel);
910 if (wishspeed > sv_maxspeed*maxspd_mod)
911 wishspeed = sv_maxspeed*maxspd_mod;
912 if (time >= self.teleport_time)
914 // water acceleration
915 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
918 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
920 //makevectors(self.v_angle_y * '0 1 0');
921 makevectors(self.v_angle);
922 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
923 // add remaining speed as Z component
924 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
926 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
927 // add the unused velocity as up component
930 // if(self.BUTTON_JUMP)
931 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
933 // it is now normalized, so...
934 float a_side, a_up, a_add, a_diff;
935 a_side = cvar("g_jetpack_acceleration_side");
936 a_up = cvar("g_jetpack_acceleration_up");
937 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
946 //////////////////////////////////////////////////////////////////////////////////////
947 // finding the maximum over all vectors of above form
948 // with wishvel having an absolute value of 1
949 //////////////////////////////////////////////////////////////////////////////////////
950 // we're finding the maximum over
951 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
952 // for z in the range from -1 to 1
953 //////////////////////////////////////////////////////////////////////////////////////
954 // maximum is EITHER attained at the single extreme point:
955 a_diff = a_side * a_side - a_up * a_up;
958 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
959 if(f > -1 && f < 1) // can it be attained?
961 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
965 // OR attained at z = 1:
966 f = (a_up + a_add) * (a_up + a_add);
972 // OR attained at z = -1:
973 f = (a_up - a_add) * (a_up - a_add);
980 //////////////////////////////////////////////////////////////////////////////////////
982 //print("best possible acceleration: ", ftos(best), "\n");
985 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
986 if(wishvel_z - sv_gravity > 0)
987 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
989 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
992 fvel = vlen(wishvel);
995 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
997 fvel = min(1, vlen(wishvel) / best);
998 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
999 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
1003 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1005 if (f > 0 && wishvel != '0 0 0')
1007 self.velocity = self.velocity + wishvel * f * frametime;
1008 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1009 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
1010 self.flags &~= FL_ONGROUND;
1011 self.items |= IT_USING_JETPACK;
1013 // jetpack also inhibits health regeneration, but only for 1 second
1014 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1017 else if (self.flags & FL_ONGROUND)
1019 // we get here if we ran out of ammo
1020 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1021 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1024 makevectors(self.v_angle_y * '0 1 0');
1025 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1027 if(!(self.lastflags & FL_ONGROUND))
1029 if(cvar("speedmeter"))
1030 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1031 if(self.lastground < time - 0.3)
1032 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1033 if(self.jumppadcount > 1)
1034 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1035 self.jumppadcount = 0;
1038 #ifdef LETS_TEST_FTEQCC
1039 if(self.velocity_x || self.velocity_y)
1057 if (f < sv_stopspeed)
1058 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
1060 f = 1 - frametime * sv_friction;
1062 self.velocity = self.velocity * f;
1064 self.velocity = '0 0 0';
1068 wishdir = normalize(wishvel);
1069 wishspeed = vlen(wishvel);
1070 if (wishspeed > sv_maxspeed*maxspd_mod)
1071 wishspeed = sv_maxspeed*maxspd_mod;
1073 wishspeed = wishspeed * 0.5;
1074 if (time >= self.teleport_time)
1075 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
1080 // we get here if we ran out of ammo
1081 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1082 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1086 maxairspd = sv_maxairspeed*maxspd_mod;
1087 airaccel = sv_airaccelerate*maxspd_mod;
1091 maxairspd = sv_maxairspeed;
1092 airaccel = sv_airaccelerate;
1095 makevectors(self.v_angle_y * '0 1 0');
1096 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1098 wishdir = normalize(wishvel);
1099 wishspeed = wishspeed0 = vlen(wishvel);
1100 if (wishspeed0 > sv_maxspeed*maxspd_mod)
1101 wishspeed0 = sv_maxspeed*maxspd_mod;
1102 if (wishspeed > maxairspd)
1103 wishspeed = maxairspd;
1105 wishspeed = wishspeed * 0.5;
1106 if (time >= self.teleport_time)
1112 airaccelqw = sv_airaccel_qw;
1113 accelerating = (self.velocity * wishdir > 0);
1114 wishspeed2 = wishspeed;
1117 if(sv_airstopaccelerate)
1118 if(self.velocity * wishdir < 0)
1119 airaccel = sv_airstopaccelerate*maxspd_mod;
1120 if(self.movement_x == 0 && self.movement_y != 0)
1122 if(sv_maxairstrafespeed)
1124 wishspeed = min(wishspeed, sv_maxairstrafespeed*maxspd_mod);
1125 if(sv_maxairstrafespeed < sv_maxairspeed)
1128 if(sv_airstrafeaccelerate)
1130 airaccel = sv_airstrafeaccelerate*maxspd_mod;
1131 if(sv_airstrafeaccelerate > sv_airaccelerate)
1137 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1138 PM_AirAccelerate(wishdir, wishspeed);
1140 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd);
1143 CPM_PM_Aircontrol(wishdir, wishspeed2);
1147 if((g_cts || g_race) && self.classname != "observer") {
1148 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1149 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1150 speedaward_holder = self.netname;
1151 speedaward_lastupdate = time;
1153 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1159 race_send_speedaward(MSG_ALL);
1160 speedaward_lastsent = speedaward_speed;
1161 if (speedaward_speed > speedaward_alltimebest) {
1162 speedaward_alltimebest = speedaward_speed;
1163 speedaward_alltimebest_holder = speedaward_holder;
1164 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1165 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"), speedaward_alltimebest_holder);
1166 race_send_speedaward_alltimebest(MSG_ALL);
1171 if(self.flags & FL_ONGROUND)
1172 self.lastground = time;
1174 self.lastflags = self.flags;
1175 self.lastclassname = self.classname;