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 if(self.velocity_z < cvar("sv_doublejump_speedcap") || !cvar("sv_doublejump_speedcap")) // try to "fix" the crazy stair jumps by limiting at which z-axis speeds you can perform a doublejump
104 self.velocity_z = self.velocity_z + mjumpheight;
106 self.oldvelocity_z = self.velocity_z;
108 self.flags &~= FL_ONGROUND;
109 self.flags &~= FL_JUMPRELEASED;
112 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
114 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
117 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
121 // we're moving upwards at self.velocity_z
122 // only allow jumping after we got 2 units upwards
123 // so we for sure leave the FL_ONGROUND check
125 // but as this sucks because of factoring in gravity, we'll just do it
126 // for 3 units, and constant velocity
127 if(self.velocity_z >= mjumpheight * 0.5) // only do this when we won't INTENTIONALLY jump a second time... TODO make a better check for this
129 self.doublejump_nextjumptime = time + 3 / max(30, self.velocity_z); // max 0.1s blocking of jumps, typically just one frame
130 //print(sprintf("blocking jumps for next %f seconds (vel: %f to %f)\n", self.doublejump_nextjumptime - time, self.velocity_z - mjumpheight, self.velocity_z));
134 self.restart_jump = -1; // restart jump anim next time
135 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
138 void CheckWaterJump()
140 local vector start, end;
142 // check for a jump-out-of-water
143 makevectors (self.angles);
145 start_z = start_z + 8;
147 normalize(v_forward);
148 end = start + v_forward*24;
149 traceline (start, end, TRUE, self);
150 if (trace_fraction < 1)
152 start_z = start_z + self.maxs_z - 8;
153 end = start + v_forward*24;
154 self.movedir = trace_plane_normal * -50;
155 traceline (start, end, TRUE, self);
156 if (trace_fraction == 1)
157 { // open at eye level
158 self.flags |= FL_WATERJUMP;
159 self.velocity_z = 225;
160 self.flags &~= FL_JUMPRELEASED;
161 self.teleport_time = time + 2; // safety net
167 float racecar_angle(float forward, float down)
169 float ret, angle_mult;
177 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
179 angle_mult = forward / (800 + forward);
182 return ret * angle_mult + 360 * (1 - angle_mult);
184 return ret * angle_mult;
187 void RaceCarPhysics()
189 // using this move type for "big rigs"
190 // the engine does not push the entity!
192 float accel, steer, f;
193 vector angles_save, rigvel;
195 angles_save = self.angles;
196 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
197 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
199 if(g_bugrigs_reverse_speeding)
203 // back accel is DIGITAL
204 // to prevent speedhack
214 makevectors(self.angles); // new forward direction!
216 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
218 float myspeed, upspeed, steerfactor, accelfactor;
220 myspeed = self.velocity * v_forward;
221 upspeed = self.velocity * v_up;
223 // responsiveness factor for steering and acceleration
224 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
225 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
227 if(myspeed < 0 && g_bugrigs_reverse_spinning)
228 steerfactor = -myspeed * g_bugrigs_steer;
230 steerfactor = -myspeed * f * g_bugrigs_steer;
232 if(myspeed < 0 && g_bugrigs_reverse_speeding)
233 accelfactor = g_bugrigs_accel;
235 accelfactor = f * g_bugrigs_accel;
236 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
242 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
246 if(!g_bugrigs_reverse_speeding)
247 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
254 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
258 if(g_bugrigs_reverse_stopping)
261 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
264 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
265 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
267 self.angles_y += steer * frametime * steerfactor; // apply steering
268 makevectors(self.angles); // new forward direction!
270 myspeed += accel * accelfactor * frametime;
272 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
276 myspeed = vlen(self.velocity);
278 // responsiveness factor for steering and acceleration
279 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
280 steerfactor = -myspeed * f;
281 self.angles_y += steer * frametime * steerfactor; // apply steering
283 rigvel = self.velocity;
284 makevectors(self.angles); // new forward direction!
287 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
288 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
289 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
290 //MAXIMA: solve(total_acceleration(v) = 0, v);
292 if(g_bugrigs_planar_movement)
294 vector rigvel_xy, neworigin, up;
297 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
301 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
304 mt = MOVE_NOMONSTERS;
306 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
307 up = trace_endpos - self.origin;
309 // BUG RIGS: align the move to the surface instead of doing collision testing
311 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
314 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
316 if(trace_fraction < 0.5)
319 neworigin = self.origin;
322 neworigin = trace_endpos;
324 if(trace_fraction < 1)
326 // now set angles_x so that the car points parallel to the surface
327 self.angles = vectoangles(
328 '1 0 0' * v_forward_x * trace_plane_normal_z
330 '0 1 0' * v_forward_y * trace_plane_normal_z
332 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
334 self.flags |= FL_ONGROUND;
338 // now set angles_x so that the car points forward, but is tilted in velocity direction
339 self.flags &~= FL_ONGROUND;
342 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
343 self.movetype = MOVETYPE_NOCLIP;
347 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
348 self.velocity = rigvel;
349 self.movetype = MOVETYPE_FLY;
353 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
354 if(trace_fraction != 1)
356 self.angles = vectoangles2(
357 '1 0 0' * v_forward_x * trace_plane_normal_z
359 '0 1 0' * v_forward_y * trace_plane_normal_z
361 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
369 vel_local_x = v_forward * self.velocity;
370 vel_local_y = v_right * self.velocity;
371 vel_local_z = v_up * self.velocity;
373 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
374 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
378 vector vf1, vu1, smoothangles;
379 makevectors(self.angles);
380 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
385 makevectors(angles_save);
386 vf1 = vf1 + v_forward * (1 - f);
387 vu1 = vu1 + v_up * (1 - f);
388 smoothangles = vectoangles2(vf1, vu1);
389 self.angles_x = -smoothangles_x;
390 self.angles_z = smoothangles_z;
393 float IsMoveInDirection(vector mv, float angle) // key mix factor
395 if(mv_x == 0 && mv_y == 0)
396 return 0; // avoid division by zero
397 angle = RAD2DEG * atan2(mv_y, mv_x);
398 angle = remainder(angle, 360) / 45;
403 return 1 - fabs(angle);
406 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
408 float zspeed, xyspeed, dot, k;
411 // this doesn't play well with analog input
412 if(self.movement_x == 0 || self.movement_y != 0)
413 return; // can't control movement if not moving forward or backward
416 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
421 k *= bound(0, wishspeed / sv_maxairspeed, 1);
423 zspeed = self.velocity_z;
425 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
427 dot = self.velocity * wishdir;
428 k *= sv_aircontrol*dot*dot*frametime;
430 if(dot > 0) // we can't change direction while slowing down
432 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
435 self.velocity = self.velocity * xyspeed;
436 self.velocity_z = zspeed;
439 // example config for alternate speed clamping:
440 // sv_airaccel_qw 0.8
441 // sv_airaccel_sideways_friction 0
442 // prvm_globalset server speedclamp_mode 1
444 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float sidefric)
452 float vel_xy_current;
453 float vel_xy_backward, vel_xy_forward;
456 speedclamp = (accelqw < 0);
460 if(cvar("sv_gameplayfix_q2airaccelerate"))
461 wishspeed0 = wishspeed;
463 vel_straight = self.velocity * wishdir;
464 vel_z = self.velocity_z;
465 vel_xy = self.velocity - vel_z * '0 0 1';
466 vel_perpend = vel_xy - vel_straight * wishdir;
468 step = accel * frametime * wishspeed0;
470 vel_xy_current = vlen(vel_xy);
471 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
472 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
473 if(vel_xy_backward < 0)
474 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
476 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
478 if(sidefric < 0 && (vel_perpend*vel_perpend))
479 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
482 f = (1 - frametime * wishspeed * sidefric);
483 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
485 vel_perpend = vel_perpend * f;
488 fminimum = sqrt(fminimum);
489 vel_perpend = vel_perpend * bound(fminimum, f, 1);
493 vel_perpend = vel_perpend * (1 - frametime * wishspeed * sidefric);
495 vel_xy = vel_straight * wishdir + vel_perpend;
499 // ensure we don't get too fast or decelerate faster than we should
500 vel_xy_current = min(vlen(vel_xy), vel_xy_forward);
501 if(vel_xy_current > 0) // prevent division by zero
502 vel_xy = normalize(vel_xy) * vel_xy_current;
505 self.velocity = vel_xy + vel_z * '0 0 1';
508 void PM_AirAccelerate(vector wishdir, float wishspeed)
510 vector curvel, wishvel, acceldir, curdir;
511 float addspeed, accelspeed, curspeed, f;
517 curvel = self.velocity;
519 curspeed = vlen(curvel);
521 if(wishspeed > curspeed * 1.01)
523 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
527 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
528 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
530 wishvel = wishdir * wishspeed;
531 acceldir = wishvel - curvel;
532 addspeed = vlen(acceldir);
533 acceldir = normalize(acceldir);
535 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
537 if(sv_warsowbunny_backtosideratio < 1)
539 curdir = normalize(curvel);
540 dot = acceldir * curdir;
542 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
545 self.velocity += accelspeed * acceldir;
548 .vector movement_old;
551 .string lastclassname;
553 void Nixnex_GiveCurrentWeapon();
554 .float() PlayerPhysplug;
556 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
557 .float specialcommand_pos;
558 void SpecialCommand()
563 if(!CheatImpulse(99))
564 print("A hollow voice says \"Plugh\".\n");
568 float speedaward_speed;
569 string speedaward_holder;
570 void race_send_speedaward(float msg)
572 // send the best speed of the round
573 WriteByte(msg, SVC_TEMPENTITY);
574 WriteByte(msg, TE_CSQC_RACE);
575 WriteByte(msg, RACE_NET_SPEED_AWARD);
576 WriteInt24_t(msg, floor(speedaward_speed+0.5));
577 WriteString(msg, speedaward_holder);
580 float speedaward_alltimebest;
581 string speedaward_alltimebest_holder;
582 void race_send_speedaward_alltimebest(float msg)
584 // send the best speed
585 WriteByte(msg, SVC_TEMPENTITY);
586 WriteByte(msg, TE_CSQC_RACE);
587 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
588 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
589 WriteString(msg, speedaward_alltimebest_holder);
592 string GetMapname(void);
593 float speedaward_lastupdate;
594 float speedaward_lastsent;
595 void SV_PlayerPhysics()
597 local vector wishvel, wishdir, v;
598 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
601 float not_allowed_to_move;
604 if(self.PlayerPhysplug)
605 if(self.PlayerPhysplug())
608 self.race_movetime_frac += frametime;
609 f = floor(self.race_movetime_frac);
610 self.race_movetime_frac -= f;
611 self.race_movetime_count += f;
612 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
616 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);
620 else if(buttons == 1)
622 else if(buttons == 2)
624 else if(buttons == 128)
626 else if(buttons == 256)
628 else if(buttons == 512)
630 else if(buttons == 1024)
635 if(c == substring(specialcommand, self.specialcommand_pos, 1))
637 self.specialcommand_pos += 1;
638 if(self.specialcommand_pos >= strlen(specialcommand))
640 self.specialcommand_pos = 0;
645 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
646 self.specialcommand_pos = 0;
648 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
650 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
651 self.parm_idlesince = time;
653 buttons_prev = self.buttons_old;
654 self.buttons_old = buttons;
655 self.movement_old = self.movement;
656 self.v_angle_old = self.v_angle;
658 if(time < self.nickspamtime)
659 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
661 // slight annoyance for nick change scripts
662 self.movement = -1 * self.movement;
663 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
665 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!
667 self.angles_x = random() * 360;
668 self.angles_y = random() * 360;
669 // at least I'm not forcing retardedview by also assigning to angles_z
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';
692 if (clienttype(self) == CLIENTTYPE_BOT)
694 if(playerdemo_read())
699 self.items &~= IT_USING_JETPACK;
701 if(self.classname == "player")
703 if(self.race_penalty)
704 if(time > self.race_penalty)
705 self.race_penalty = 0;
707 not_allowed_to_move = 0;
708 if(self.race_penalty)
709 not_allowed_to_move = 1;
710 if(!cvar("sv_ready_restart_after_countdown"))
711 if(time < game_starttime)
712 not_allowed_to_move = 1;
714 if(not_allowed_to_move)
716 self.velocity = '0 0 0';
717 self.movetype = MOVETYPE_NONE;
718 self.disableclientprediction = 2;
720 else if(self.disableclientprediction == 2)
722 if(self.movetype == MOVETYPE_NONE)
723 self.movetype = MOVETYPE_WALK;
724 self.disableclientprediction = 0;
728 if (self.movetype == MOVETYPE_NONE)
735 if(self.runes & RUNE_SPEED)
737 if(self.runes & CURSE_SLOW)
738 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
740 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
742 else if(self.runes & CURSE_SLOW)
744 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
748 if(g_minstagib && (self.items & IT_INVINCIBLE))
750 maxspd_mod = cvar("g_minstagib_speed_moverate");
753 if(g_nexball && self.ballcarried)
755 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
760 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
763 if(self.classname != "player")
765 maxspd_mod = cvar("sv_spectator_speed_multiplier");
766 if(!self.spectatorspeed)
767 self.spectatorspeed = maxspd_mod;
768 if(self.impulse && self.impulse <= 19)
770 if(self.lastclassname != "player")
772 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
773 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
774 else if(self.impulse == 11)
775 self.spectatorspeed = maxspd_mod;
776 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
777 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
778 else if(self.impulse >= 1 && self.impulse <= 9)
779 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
780 } // otherwise just clear
783 maxspd_mod = self.spectatorspeed;
786 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
787 if(self.speed != spd)
791 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
792 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
793 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
794 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
797 maxspd_mod *= swampspd_mod; // only one common speed modder please!
800 // if dead, behave differently
804 if (!self.fixangle && !g_bugrigs)
807 self.angles_y = self.v_angle_y;
811 if(self.flags & FL_ONGROUND)
816 if(self.waterlevel < WATERLEVEL_SWIMMING)
817 if(time >= self.ladder_time)
820 self.nextstep = time + 0.3 + random() * 0.1;
821 trace_dphitq3surfaceflags = 0;
822 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
823 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
825 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
826 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
828 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
836 if(self.classname == "player")
840 self.flags &~= FL_ONGROUND;
841 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 1', MOVE_NORMAL, self);
842 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
843 self.flags |= FL_ONGROUND;
846 if (self.BUTTON_JUMP)
849 self.flags |= FL_JUMPRELEASED;
851 if (self.waterlevel == WATERLEVEL_SWIMMING)
855 if (self.flags & FL_WATERJUMP )
857 self.velocity_x = self.movedir_x;
858 self.velocity_y = self.movedir_y;
859 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
861 self.flags &~= FL_WATERJUMP;
862 self.teleport_time = 0;
865 else if (g_bugrigs && self.classname == "player")
869 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
871 // noclipping or flying
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 wishdir = normalize(wishvel);
880 wishspeed = vlen(wishvel);
881 if (wishspeed > sv_maxspeed*maxspd_mod)
882 wishspeed = sv_maxspeed*maxspd_mod;
883 if (time >= self.teleport_time)
884 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
886 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
889 self.flags &~= FL_ONGROUND;
891 makevectors(self.v_angle);
892 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
893 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
894 if (wishvel == '0 0 0')
895 wishvel = '0 0 -60'; // drift towards bottom
897 wishdir = normalize(wishvel);
898 wishspeed = vlen(wishvel);
899 if (wishspeed > sv_maxspeed*maxspd_mod)
900 wishspeed = sv_maxspeed*maxspd_mod;
901 wishspeed = wishspeed * 0.7;
904 self.velocity = self.velocity * (1 - frametime * sv_friction);
906 // water acceleration
907 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
909 else if (time < self.ladder_time)
911 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
912 self.flags &~= FL_ONGROUND;
914 self.velocity = self.velocity * (1 - frametime * sv_friction);
915 makevectors(self.v_angle);
916 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
917 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
919 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
921 self.velocity_z = self.velocity_z + sv_gravity * frametime;
922 if (self.ladder_entity.classname == "func_water")
925 if (f > self.ladder_entity.speed)
926 wishvel = wishvel * (self.ladder_entity.speed / f);
928 self.watertype = self.ladder_entity.skin;
929 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
930 if ((self.origin_z + self.view_ofs_z) < f)
931 self.waterlevel = WATERLEVEL_SUBMERGED;
932 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
933 self.waterlevel = WATERLEVEL_SWIMMING;
934 else if ((self.origin_z + self.mins_z + 1) < f)
935 self.waterlevel = WATERLEVEL_WETFEET;
938 self.waterlevel = WATERLEVEL_NONE;
939 self.watertype = CONTENT_EMPTY;
943 wishdir = normalize(wishvel);
944 wishspeed = vlen(wishvel);
945 if (wishspeed > sv_maxspeed*maxspd_mod)
946 wishspeed = sv_maxspeed*maxspd_mod;
947 if (time >= self.teleport_time)
949 // water acceleration
950 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
953 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
955 //makevectors(self.v_angle_y * '0 1 0');
956 makevectors(self.v_angle);
957 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
958 // add remaining speed as Z component
959 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
961 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
962 // add the unused velocity as up component
965 // if(self.BUTTON_JUMP)
966 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
968 // it is now normalized, so...
969 float a_side, a_up, a_add, a_diff;
970 a_side = cvar("g_jetpack_acceleration_side");
971 a_up = cvar("g_jetpack_acceleration_up");
972 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
981 //////////////////////////////////////////////////////////////////////////////////////
982 // finding the maximum over all vectors of above form
983 // with wishvel having an absolute value of 1
984 //////////////////////////////////////////////////////////////////////////////////////
985 // we're finding the maximum over
986 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
987 // for z in the range from -1 to 1
988 //////////////////////////////////////////////////////////////////////////////////////
989 // maximum is EITHER attained at the single extreme point:
990 a_diff = a_side * a_side - a_up * a_up;
993 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
994 if(f > -1 && f < 1) // can it be attained?
996 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1000 // OR attained at z = 1:
1001 f = (a_up + a_add) * (a_up + a_add);
1007 // OR attained at z = -1:
1008 f = (a_up - a_add) * (a_up - a_add);
1012 //print("bottom\n");
1015 //////////////////////////////////////////////////////////////////////////////////////
1017 //print("best possible acceleration: ", ftos(best), "\n");
1020 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
1021 if(wishvel_z - sv_gravity > 0)
1022 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1024 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1027 fvel = vlen(wishvel);
1030 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
1032 fvel = min(1, vlen(wishvel) / best);
1033 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1034 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
1038 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1040 if (f > 0 && wishvel != '0 0 0')
1042 self.velocity = self.velocity + wishvel * f * frametime;
1043 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1044 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
1045 self.flags &~= FL_ONGROUND;
1046 self.items |= IT_USING_JETPACK;
1048 // jetpack also inhibits health regeneration, but only for 1 second
1049 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1052 else if (self.flags & FL_ONGROUND)
1054 // we get here if we ran out of ammo
1055 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1056 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1059 makevectors(self.v_angle_y * '0 1 0');
1060 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1062 if(!(self.lastflags & FL_ONGROUND))
1064 if(cvar("speedmeter"))
1065 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1066 if(self.lastground < time - 0.3)
1067 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1068 if(self.jumppadcount > 1)
1069 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1070 self.jumppadcount = 0;
1073 #ifdef LETS_TEST_FTEQCC
1074 if(self.velocity_x || self.velocity_y)
1092 if (f < sv_stopspeed)
1093 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
1095 f = 1 - frametime * sv_friction;
1097 self.velocity = self.velocity * f;
1099 self.velocity = '0 0 0';
1103 wishdir = normalize(wishvel);
1104 wishspeed = vlen(wishvel);
1105 if (wishspeed > sv_maxspeed*maxspd_mod)
1106 wishspeed = sv_maxspeed*maxspd_mod;
1108 wishspeed = wishspeed * 0.5;
1109 if (time >= self.teleport_time)
1110 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
1115 // we get here if we ran out of ammo
1116 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1117 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1121 maxairspd = sv_maxairspeed*maxspd_mod;
1122 airaccel = sv_airaccelerate*maxspd_mod;
1126 maxairspd = sv_maxairspeed;
1127 airaccel = sv_airaccelerate;
1130 makevectors(self.v_angle_y * '0 1 0');
1131 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1133 wishdir = normalize(wishvel);
1134 wishspeed = wishspeed0 = vlen(wishvel);
1135 if (wishspeed0 > sv_maxspeed*maxspd_mod)
1136 wishspeed0 = sv_maxspeed*maxspd_mod;
1137 if (wishspeed > maxairspd)
1138 wishspeed = maxairspd;
1140 wishspeed = wishspeed * 0.5;
1141 if (time >= self.teleport_time)
1147 airaccelqw = sv_airaccel_qw;
1148 accelerating = (self.velocity * wishdir > 0);
1149 wishspeed2 = wishspeed;
1152 if(sv_airstopaccelerate)
1153 if(self.velocity * wishdir < 0)
1154 airaccel = sv_airstopaccelerate*maxspd_mod;
1155 // this doesn't play well with analog input, but can't r
1156 // fixed like the AirControl can. So, don't set the maxa
1157 // cvars when you want to support analog input.
1158 if(self.movement_x == 0 && self.movement_y != 0)
1160 if(sv_maxairstrafespeed)
1162 wishspeed = min(wishspeed, sv_maxairstrafespeed*maxspd_mod);
1163 if(sv_maxairstrafespeed < sv_maxairspeed)
1166 if(sv_airstrafeaccelerate)
1168 airaccel = sv_airstrafeaccelerate*maxspd_mod;
1169 if(sv_airstrafeaccelerate > sv_airaccelerate)
1175 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1176 PM_AirAccelerate(wishdir, wishspeed);
1178 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd);
1181 CPM_PM_Aircontrol(wishdir, wishspeed2);
1185 if((g_cts || g_race) && self.classname != "observer") {
1186 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1187 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1188 speedaward_holder = self.netname;
1189 speedaward_lastupdate = time;
1191 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1197 race_send_speedaward(MSG_ALL);
1198 speedaward_lastsent = speedaward_speed;
1199 if (speedaward_speed > speedaward_alltimebest) {
1200 speedaward_alltimebest = speedaward_speed;
1201 speedaward_alltimebest_holder = speedaward_holder;
1202 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1203 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"), speedaward_alltimebest_holder);
1204 race_send_speedaward_alltimebest(MSG_ALL);
1209 if(self.flags & FL_ONGROUND)
1210 self.lastground = time;
1212 self.lastflags = self.flags;
1213 self.lastclassname = self.classname;