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;
36 When you press the jump key
39 void PlayerJump (void)
43 mjumpheight = cvar("sv_jumpvelocity");
44 if (self.waterlevel >= WATERLEVEL_SWIMMING)
46 if (self.watertype == CONTENT_WATER)
47 self.velocity_z = 200;
48 else if (self.watertype == CONTENT_SLIME)
56 if (!(self.flags & FL_ONGROUND))
60 if (!(self.flags & FL_JUMPRELEASED))
63 if(self.health <= g_bloodloss)
68 if(self.runes & RUNE_SPEED)
70 if(self.runes & CURSE_SLOW)
71 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
73 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
75 else if(self.runes & CURSE_SLOW)
77 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
81 if(g_minstagib && (self.items & IT_INVINCIBLE))
83 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
86 if(cvar_string("sv_jumpspeedcap_min") != "")
87 self.velocity_z = max(cvar("sv_jumpvelocity") * cvar("sv_jumpspeedcap_min"), self.velocity_z);
88 if(cvar_string("sv_jumpspeedcap_max") != "") {
89 if(trace_fraction < 1 && trace_plane_normal_z < 0.98 && cvar("sv_jumpspeedcap_max_disable_on_ramps")) {
90 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
91 //print("Trace plane normal z: ", ftos(trace_plane_normal_z), ", disabling speed cap!\n");
94 self.velocity_z = min(cvar("sv_jumpvelocity") * cvar("sv_jumpspeedcap_max"), self.velocity_z) + trace_ent.velocity_z;
97 if(!(self.lastflags & FL_ONGROUND))
99 if(cvar("speedmeter"))
100 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
101 if(self.lastground < time - 0.3)
103 self.velocity_x *= (1 - cvar("sv_friction_on_land"));
104 self.velocity_y *= (1 - cvar("sv_friction_on_land"));
106 if(self.jumppadcount > 1)
107 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
108 self.jumppadcount = 0;
111 self.velocity_z = self.velocity_z + mjumpheight;
112 self.oldvelocity_z = self.velocity_z;
114 self.flags &~= FL_ONGROUND;
115 self.flags &~= FL_JUMPRELEASED;
118 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
120 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
123 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
125 self.restart_jump = -1; // restart jump anim next time
126 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
129 void CheckWaterJump()
131 local vector start, end;
133 // check for a jump-out-of-water
134 makevectors (self.angles);
136 start_z = start_z + 8;
138 normalize(v_forward);
139 end = start + v_forward*24;
140 traceline (start, end, TRUE, self);
141 if (trace_fraction < 1)
143 start_z = start_z + self.maxs_z - 8;
144 end = start + v_forward*24;
145 self.movedir = trace_plane_normal * -50;
146 traceline (start, end, TRUE, self);
147 if (trace_fraction == 1)
148 { // open at eye level
149 self.flags |= FL_WATERJUMP;
150 self.velocity_z = 225;
151 self.flags &~= FL_JUMPRELEASED;
152 self.teleport_time = time + 2; // safety net
158 float racecar_angle(float forward, float down)
160 float ret, angle_mult;
168 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
170 angle_mult = forward / (800 + forward);
173 return ret * angle_mult + 360 * (1 - angle_mult);
175 return ret * angle_mult;
178 void RaceCarPhysics()
180 // using this move type for "big rigs"
181 // the engine does not push the entity!
183 float accel, steer, f;
184 vector angles_save, rigvel;
186 angles_save = self.angles;
187 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
188 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
190 if(g_bugrigs_reverse_speeding)
194 // back accel is DIGITAL
195 // to prevent speedhack
205 makevectors(self.angles); // new forward direction!
207 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
209 float myspeed, upspeed, steerfactor, accelfactor;
211 myspeed = self.velocity * v_forward;
212 upspeed = self.velocity * v_up;
214 // responsiveness factor for steering and acceleration
215 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
216 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
218 if(myspeed < 0 && g_bugrigs_reverse_spinning)
219 steerfactor = -myspeed * g_bugrigs_steer;
221 steerfactor = -myspeed * f * g_bugrigs_steer;
223 if(myspeed < 0 && g_bugrigs_reverse_speeding)
224 accelfactor = g_bugrigs_accel;
226 accelfactor = f * g_bugrigs_accel;
227 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
233 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
237 if(!g_bugrigs_reverse_speeding)
238 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
245 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
249 if(g_bugrigs_reverse_stopping)
252 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
255 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
256 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
258 self.angles_y += steer * frametime * steerfactor; // apply steering
259 makevectors(self.angles); // new forward direction!
261 myspeed += accel * accelfactor * frametime;
263 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
267 myspeed = vlen(self.velocity);
269 // responsiveness factor for steering and acceleration
270 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
271 steerfactor = -myspeed * f;
272 self.angles_y += steer * frametime * steerfactor; // apply steering
274 rigvel = self.velocity;
275 makevectors(self.angles); // new forward direction!
278 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
279 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
280 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
281 //MAXIMA: solve(total_acceleration(v) = 0, v);
283 if(g_bugrigs_planar_movement)
285 vector rigvel_xy, neworigin, up;
288 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
292 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
295 mt = MOVE_NOMONSTERS;
297 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
298 up = trace_endpos - self.origin;
300 // BUG RIGS: align the move to the surface instead of doing collision testing
302 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
305 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
307 if(trace_fraction < 0.5)
310 neworigin = self.origin;
313 neworigin = trace_endpos;
315 if(trace_fraction < 1)
317 // now set angles_x so that the car points parallel to the surface
318 self.angles = vectoangles(
319 '1 0 0' * v_forward_x * trace_plane_normal_z
321 '0 1 0' * v_forward_y * trace_plane_normal_z
323 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
325 self.flags |= FL_ONGROUND;
329 // now set angles_x so that the car points forward, but is tilted in velocity direction
330 self.flags &~= FL_ONGROUND;
333 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
334 self.movetype = MOVETYPE_NOCLIP;
338 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
339 self.velocity = rigvel;
340 self.movetype = MOVETYPE_FLY;
344 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
345 if(trace_fraction != 1)
347 self.angles = vectoangles2(
348 '1 0 0' * v_forward_x * trace_plane_normal_z
350 '0 1 0' * v_forward_y * trace_plane_normal_z
352 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
360 vel_local_x = v_forward * self.velocity;
361 vel_local_y = v_right * self.velocity;
362 vel_local_z = v_up * self.velocity;
364 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
365 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
369 vector vf1, vu1, smoothangles;
370 makevectors(self.angles);
371 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
376 makevectors(angles_save);
377 vf1 = vf1 + v_forward * (1 - f);
378 vu1 = vu1 + v_up * (1 - f);
379 smoothangles = vectoangles2(vf1, vu1);
380 self.angles_x = -smoothangles_x;
381 self.angles_z = smoothangles_z;
384 float IsMoveInDirection(vector mv, float angle) // key mix factor
386 if(mv_x == 0 && mv_y == 0)
387 return 0; // avoid division by zero
388 angle = RAD2DEG * atan2(mv_y, mv_x);
389 angle = remainder(angle, 360) / 45;
394 return 1 - fabs(angle);
397 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
399 float zspeed, xyspeed, dot, k;
402 // this doesn't play well with analog input
403 if(self.movement_x == 0 || self.movement_y != 0)
404 return; // can't control movement if not moving forward or backward
407 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
412 k *= bound(0, wishspeed / sv_maxairspeed, 1);
414 zspeed = self.velocity_z;
416 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
418 dot = self.velocity * wishdir;
419 k *= sv_aircontrol*dot*dot*frametime;
421 if(dot > 0) // we can't change direction while slowing down
423 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
426 self.velocity = self.velocity * xyspeed;
427 self.velocity_z = zspeed;
430 // example config for alternate speed clamping:
431 // sv_airaccel_qw 0.8
432 // sv_airaccel_sideways_friction 0
433 // prvm_globalset server speedclamp_mode 1
435 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float sidefric)
443 float vel_xy_current;
444 float vel_xy_backward, vel_xy_forward;
447 speedclamp = (accelqw < 0);
451 if(cvar("sv_gameplayfix_q2airaccelerate"))
452 wishspeed0 = wishspeed;
454 vel_straight = self.velocity * wishdir;
455 vel_z = self.velocity_z;
456 vel_xy = self.velocity - vel_z * '0 0 1';
457 vel_perpend = vel_xy - vel_straight * wishdir;
459 step = accel * frametime * wishspeed0;
461 vel_xy_current = vlen(vel_xy);
462 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
463 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
464 if(vel_xy_backward < 0)
465 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
467 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
469 if(sidefric < 0 && (vel_perpend*vel_perpend))
470 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
473 f = max(0, 1 + frametime * wishspeed * sidefric);
474 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
475 // this cannot be > 1
477 vel_perpend = vel_perpend * max(0, f);
480 fminimum = sqrt(fminimum);
481 vel_perpend = vel_perpend * max(fminimum, f);
485 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
487 vel_xy = vel_straight * wishdir + vel_perpend;
491 // ensure we don't get too fast or decelerate faster than we should
492 vel_xy_current = min(vlen(vel_xy), vel_xy_forward);
493 if(vel_xy_current > 0) // prevent division by zero
494 vel_xy = normalize(vel_xy) * vel_xy_current;
497 self.velocity = vel_xy + vel_z * '0 0 1';
500 void PM_AirAccelerate(vector wishdir, float wishspeed)
502 vector curvel, wishvel, acceldir, curdir;
503 float addspeed, accelspeed, curspeed, f;
509 curvel = self.velocity;
511 curspeed = vlen(curvel);
513 if(wishspeed > curspeed * 1.01)
515 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
519 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
520 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
522 wishvel = wishdir * wishspeed;
523 acceldir = wishvel - curvel;
524 addspeed = vlen(acceldir);
525 acceldir = normalize(acceldir);
527 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
529 if(sv_warsowbunny_backtosideratio < 1)
531 curdir = normalize(curvel);
532 dot = acceldir * curdir;
534 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
537 self.velocity += accelspeed * acceldir;
540 .vector movement_old;
543 .string lastclassname;
545 void Nixnex_GiveCurrentWeapon();
546 .float() PlayerPhysplug;
548 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
549 .float specialcommand_pos;
550 void SpecialCommand()
555 if(!CheatImpulse(99))
556 print("A hollow voice says \"Plugh\".\n");
560 float speedaward_speed;
561 string speedaward_holder;
562 void race_send_speedaward(float msg)
564 // send the best speed of the round
565 WriteByte(msg, SVC_TEMPENTITY);
566 WriteByte(msg, TE_CSQC_RACE);
567 WriteByte(msg, RACE_NET_SPEED_AWARD);
568 WriteInt24_t(msg, floor(speedaward_speed+0.5));
569 WriteString(msg, speedaward_holder);
572 float speedaward_alltimebest;
573 string speedaward_alltimebest_holder;
574 void race_send_speedaward_alltimebest(float msg)
576 // send the best speed
577 WriteByte(msg, SVC_TEMPENTITY);
578 WriteByte(msg, TE_CSQC_RACE);
579 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
580 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
581 WriteString(msg, speedaward_alltimebest_holder);
584 string GetMapname(void);
585 float speedaward_lastupdate;
586 float speedaward_lastsent;
587 .float jumppadusetime;
588 void SV_PlayerPhysics()
590 local vector wishvel, wishdir, v;
591 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
594 float not_allowed_to_move;
597 if(self.PlayerPhysplug)
598 if(self.PlayerPhysplug())
601 self.race_movetime_frac += frametime;
602 f = floor(self.race_movetime_frac);
603 self.race_movetime_frac -= f;
604 self.race_movetime_count += f;
605 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
609 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);
613 else if(buttons == 1)
615 else if(buttons == 2)
617 else if(buttons == 128)
619 else if(buttons == 256)
621 else if(buttons == 512)
623 else if(buttons == 1024)
628 if(c == substring(specialcommand, self.specialcommand_pos, 1))
630 self.specialcommand_pos += 1;
631 if(self.specialcommand_pos >= strlen(specialcommand))
633 self.specialcommand_pos = 0;
638 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
639 self.specialcommand_pos = 0;
641 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
643 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
644 self.parm_idlesince = time;
646 buttons_prev = self.buttons_old;
647 self.buttons_old = buttons;
648 self.movement_old = self.movement;
649 self.v_angle_old = self.v_angle;
651 if(time < self.nickspamtime)
652 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
654 // slight annoyance for nick change scripts
655 self.movement = -1 * self.movement;
656 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
658 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!
660 self.angles_x = random() * 360;
661 self.angles_y = random() * 360;
662 // at least I'm not forcing retardedview by also assigning to angles_z
667 if (self.punchangle != '0 0 0')
669 f = vlen(self.punchangle) - 10 * frametime;
671 self.punchangle = normalize(self.punchangle) * f;
673 self.punchangle = '0 0 0';
676 if (self.punchvector != '0 0 0')
678 f = vlen(self.punchvector) - 30 * frametime;
680 self.punchvector = normalize(self.punchvector) * f;
682 self.punchvector = '0 0 0';
685 if (clienttype(self) == CLIENTTYPE_BOT)
687 if(playerdemo_read())
692 self.items &~= IT_USING_JETPACK;
694 if(self.classname == "player")
696 if(self.race_penalty)
697 if(time > self.race_penalty)
698 self.race_penalty = 0;
700 not_allowed_to_move = 0;
701 if(self.race_penalty)
702 not_allowed_to_move = 1;
703 if(!cvar("sv_ready_restart_after_countdown"))
704 if(time < game_starttime)
705 not_allowed_to_move = 1;
707 if(not_allowed_to_move)
709 self.velocity = '0 0 0';
710 self.movetype = MOVETYPE_NONE;
711 self.disableclientprediction = 2;
713 else if(self.disableclientprediction == 2)
715 if(self.movetype == MOVETYPE_NONE)
716 self.movetype = MOVETYPE_WALK;
717 self.disableclientprediction = 0;
721 if (self.movetype == MOVETYPE_NONE)
728 if(self.runes & RUNE_SPEED)
730 if(self.runes & CURSE_SLOW)
731 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
733 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
735 else if(self.runes & CURSE_SLOW)
737 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
741 if(g_minstagib && (self.items & IT_INVINCIBLE))
743 maxspd_mod = cvar("g_minstagib_speed_moverate");
746 if(g_nexball && self.ballcarried)
748 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
753 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
756 if(self.classname != "player")
758 maxspd_mod = cvar("sv_spectator_speed_multiplier");
759 if(!self.spectatorspeed)
760 self.spectatorspeed = maxspd_mod;
761 if(self.impulse && self.impulse <= 19)
763 if(self.lastclassname != "player")
765 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
766 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
767 else if(self.impulse == 11)
768 self.spectatorspeed = maxspd_mod;
769 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
770 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
771 else if(self.impulse >= 1 && self.impulse <= 9)
772 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
773 } // otherwise just clear
776 maxspd_mod = self.spectatorspeed;
779 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
780 if(self.speed != spd)
784 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
785 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
786 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
787 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
790 maxspd_mod *= swampspd_mod; // only one common speed modder please!
793 // if dead, behave differently
797 if (!self.fixangle && !g_bugrigs)
800 self.angles_y = self.v_angle_y;
804 if(self.flags & FL_ONGROUND)
809 if(self.waterlevel < WATERLEVEL_SWIMMING)
810 if(time >= self.ladder_time)
813 self.nextstep = time + 0.3 + random() * 0.1;
814 trace_dphitq3surfaceflags = 0;
815 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
816 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
818 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
819 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
821 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
829 if(self.classname == "player")
831 if(sv_doublejump && time - self.jumppadusetime > 2 * sys_frametime)
833 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
834 self.flags &~= FL_ONGROUND;
835 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
836 self.flags |= FL_ONGROUND;
839 if (self.BUTTON_JUMP)
842 self.flags |= FL_JUMPRELEASED;
844 if (self.waterlevel == WATERLEVEL_SWIMMING)
848 if (self.flags & FL_WATERJUMP )
850 self.velocity_x = self.movedir_x;
851 self.velocity_y = self.movedir_y;
852 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
854 self.flags &~= FL_WATERJUMP;
855 self.teleport_time = 0;
858 else if (g_bugrigs && self.classname == "player")
862 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
864 // noclipping or flying
865 self.flags &~= FL_ONGROUND;
867 self.velocity = self.velocity * (1 - frametime * sv_friction);
868 makevectors(self.v_angle);
869 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
870 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
872 wishdir = normalize(wishvel);
873 wishspeed = vlen(wishvel);
874 if (wishspeed > sv_maxspeed*maxspd_mod)
875 wishspeed = sv_maxspeed*maxspd_mod;
876 if (time >= self.teleport_time)
877 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
879 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
882 self.flags &~= FL_ONGROUND;
884 makevectors(self.v_angle);
885 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
886 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
887 if (wishvel == '0 0 0')
888 wishvel = '0 0 -60'; // drift towards bottom
890 wishdir = normalize(wishvel);
891 wishspeed = vlen(wishvel);
892 if (wishspeed > sv_maxspeed*maxspd_mod)
893 wishspeed = sv_maxspeed*maxspd_mod;
894 wishspeed = wishspeed * 0.7;
897 self.velocity = self.velocity * (1 - frametime * sv_friction);
899 // water acceleration
900 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
902 else if (time < self.ladder_time)
904 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
905 self.flags &~= FL_ONGROUND;
907 self.velocity = self.velocity * (1 - frametime * sv_friction);
908 makevectors(self.v_angle);
909 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
910 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
912 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
914 self.velocity_z = self.velocity_z + sv_gravity * frametime;
915 if (self.ladder_entity.classname == "func_water")
918 if (f > self.ladder_entity.speed)
919 wishvel = wishvel * (self.ladder_entity.speed / f);
921 self.watertype = self.ladder_entity.skin;
922 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
923 if ((self.origin_z + self.view_ofs_z) < f)
924 self.waterlevel = WATERLEVEL_SUBMERGED;
925 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
926 self.waterlevel = WATERLEVEL_SWIMMING;
927 else if ((self.origin_z + self.mins_z + 1) < f)
928 self.waterlevel = WATERLEVEL_WETFEET;
931 self.waterlevel = WATERLEVEL_NONE;
932 self.watertype = CONTENT_EMPTY;
936 wishdir = normalize(wishvel);
937 wishspeed = vlen(wishvel);
938 if (wishspeed > sv_maxspeed*maxspd_mod)
939 wishspeed = sv_maxspeed*maxspd_mod;
940 if (time >= self.teleport_time)
942 // water acceleration
943 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
946 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
948 //makevectors(self.v_angle_y * '0 1 0');
949 makevectors(self.v_angle);
950 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
951 // add remaining speed as Z component
952 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
954 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
955 // add the unused velocity as up component
958 // if(self.BUTTON_JUMP)
959 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
961 // it is now normalized, so...
962 float a_side, a_up, a_add, a_diff;
963 a_side = cvar("g_jetpack_acceleration_side");
964 a_up = cvar("g_jetpack_acceleration_up");
965 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
974 //////////////////////////////////////////////////////////////////////////////////////
975 // finding the maximum over all vectors of above form
976 // with wishvel having an absolute value of 1
977 //////////////////////////////////////////////////////////////////////////////////////
978 // we're finding the maximum over
979 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
980 // for z in the range from -1 to 1
981 //////////////////////////////////////////////////////////////////////////////////////
982 // maximum is EITHER attained at the single extreme point:
983 a_diff = a_side * a_side - a_up * a_up;
986 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
987 if(f > -1 && f < 1) // can it be attained?
989 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
993 // OR attained at z = 1:
994 f = (a_up + a_add) * (a_up + a_add);
1000 // OR attained at z = -1:
1001 f = (a_up - a_add) * (a_up - a_add);
1005 //print("bottom\n");
1008 //////////////////////////////////////////////////////////////////////////////////////
1010 //print("best possible acceleration: ", ftos(best), "\n");
1013 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
1014 if(wishvel_z - sv_gravity > 0)
1015 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1017 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1020 fvel = vlen(wishvel);
1023 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
1025 fvel = min(1, vlen(wishvel) / best);
1026 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1027 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
1031 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1033 if (f > 0 && wishvel != '0 0 0')
1035 self.velocity = self.velocity + wishvel * f * frametime;
1036 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1037 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
1038 self.flags &~= FL_ONGROUND;
1039 self.items |= IT_USING_JETPACK;
1041 // jetpack also inhibits health regeneration, but only for 1 second
1042 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1045 else if (self.flags & FL_ONGROUND)
1047 // we get here if we ran out of ammo
1048 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1049 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1052 makevectors(self.v_angle_y * '0 1 0');
1053 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1055 if(!(self.lastflags & FL_ONGROUND))
1057 if(cvar("speedmeter"))
1058 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1059 if(self.lastground < time - 0.3)
1060 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1061 if(self.jumppadcount > 1)
1062 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1063 self.jumppadcount = 0;
1066 #ifdef LETS_TEST_FTEQCC
1067 if(self.velocity_x || self.velocity_y)
1085 if (f < sv_stopspeed)
1086 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
1088 f = 1 - frametime * sv_friction;
1090 self.velocity = self.velocity * f;
1092 self.velocity = '0 0 0';
1096 wishdir = normalize(wishvel);
1097 wishspeed = vlen(wishvel);
1098 if (wishspeed > sv_maxspeed*maxspd_mod)
1099 wishspeed = sv_maxspeed*maxspd_mod;
1101 wishspeed = wishspeed * 0.5;
1102 if (time >= self.teleport_time)
1103 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
1108 // we get here if we ran out of ammo
1109 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1110 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1114 maxairspd = sv_maxairspeed*maxspd_mod;
1115 airaccel = sv_airaccelerate*maxspd_mod;
1119 maxairspd = sv_maxairspeed;
1120 airaccel = sv_airaccelerate;
1123 makevectors(self.v_angle_y * '0 1 0');
1124 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1126 wishdir = normalize(wishvel);
1127 wishspeed = wishspeed0 = vlen(wishvel);
1128 if (wishspeed0 > sv_maxspeed*maxspd_mod)
1129 wishspeed0 = sv_maxspeed*maxspd_mod;
1130 if (wishspeed > maxairspd)
1131 wishspeed = maxairspd;
1133 wishspeed = wishspeed * 0.5;
1134 if (time >= self.teleport_time)
1140 airaccelqw = sv_airaccel_qw;
1141 accelerating = (self.velocity * wishdir > 0);
1142 wishspeed2 = wishspeed;
1145 if(sv_airstopaccelerate)
1146 if(self.velocity * wishdir < 0)
1147 airaccel = sv_airstopaccelerate*maxspd_mod;
1148 // this doesn't play well with analog input, but can't r
1149 // fixed like the AirControl can. So, don't set the maxa
1150 // cvars when you want to support analog input.
1151 if(self.movement_x == 0 && self.movement_y != 0)
1153 if(sv_maxairstrafespeed)
1155 wishspeed = min(wishspeed, sv_maxairstrafespeed*maxspd_mod);
1156 if(sv_maxairstrafespeed < sv_maxairspeed)
1159 if(sv_airstrafeaccelerate)
1161 airaccel = sv_airstrafeaccelerate*maxspd_mod;
1162 if(sv_airstrafeaccelerate > sv_airaccelerate)
1168 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1169 PM_AirAccelerate(wishdir, wishspeed);
1171 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd);
1174 CPM_PM_Aircontrol(wishdir, wishspeed2);
1178 if((g_cts || g_race) && self.classname != "observer") {
1179 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1180 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1181 speedaward_holder = self.netname;
1182 speedaward_lastupdate = time;
1184 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1190 race_send_speedaward(MSG_ALL);
1191 speedaward_lastsent = speedaward_speed;
1192 if (speedaward_speed > speedaward_alltimebest) {
1193 speedaward_alltimebest = speedaward_speed;
1194 speedaward_alltimebest_holder = speedaward_holder;
1195 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1196 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"), speedaward_alltimebest_holder);
1197 race_send_speedaward_alltimebest(MSG_ALL);
1202 if(self.flags & FL_ONGROUND)
1203 self.lastground = time;
1205 self.lastflags = self.flags;
1206 self.lastclassname = self.classname;