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_aircontrol_power;
18 float sv_warsowbunny_airforwardaccel;
19 float sv_warsowbunny_accel;
20 float sv_warsowbunny_topspeed;
21 float sv_warsowbunny_turnaccel;
22 float sv_warsowbunny_backtosideratio;
25 .entity ladder_entity;
27 .float swamp_slowdown;
31 .float spectatorspeed;
37 When you press the jump key
40 void PlayerJump (void)
44 mjumpheight = cvar("sv_jumpvelocity");
45 if (self.waterlevel >= WATERLEVEL_SWIMMING)
47 if (self.watertype == CONTENT_WATER)
48 self.velocity_z = 200;
49 else if (self.watertype == CONTENT_SLIME)
57 if (!(self.flags & FL_ONGROUND))
61 if (!(self.flags & FL_JUMPRELEASED))
64 if(self.health <= g_bloodloss)
69 if(self.runes & RUNE_SPEED)
71 if(self.runes & CURSE_SLOW)
72 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
74 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
76 else if(self.runes & CURSE_SLOW)
78 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
82 if(g_minstagib && (self.items & IT_INVINCIBLE))
84 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
87 if(cvar_string("sv_jumpspeedcap_min") != "")
88 self.velocity_z = max(cvar("sv_jumpvelocity") * cvar("sv_jumpspeedcap_min"), self.velocity_z);
89 if(cvar_string("sv_jumpspeedcap_max") != "") {
90 if(trace_fraction < 1 && trace_plane_normal_z < 0.98 && cvar("sv_jumpspeedcap_max_disable_on_ramps")) {
91 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
92 //print("Trace plane normal z: ", ftos(trace_plane_normal_z), ", disabling speed cap!\n");
95 self.velocity_z = min(cvar("sv_jumpvelocity") * cvar("sv_jumpspeedcap_max"), self.velocity_z) + trace_ent.velocity_z;
98 if(!(self.lastflags & FL_ONGROUND))
100 if(cvar("speedmeter"))
101 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
102 if(self.lastground < time - 0.3)
104 self.velocity_x *= (1 - cvar("sv_friction_on_land"));
105 self.velocity_y *= (1 - cvar("sv_friction_on_land"));
107 if(self.jumppadcount > 1)
108 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
109 self.jumppadcount = 0;
112 self.velocity_z = self.velocity_z + mjumpheight;
113 self.oldvelocity_z = self.velocity_z;
115 self.flags &~= FL_ONGROUND;
116 self.flags &~= FL_JUMPRELEASED;
119 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
121 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
124 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
126 self.restart_jump = -1; // restart jump anim next time
127 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
130 void CheckWaterJump()
132 local vector start, end;
134 // check for a jump-out-of-water
135 makevectors (self.angles);
137 start_z = start_z + 8;
139 normalize(v_forward);
140 end = start + v_forward*24;
141 traceline (start, end, TRUE, self);
142 if (trace_fraction < 1)
144 start_z = start_z + self.maxs_z - 8;
145 end = start + v_forward*24;
146 self.movedir = trace_plane_normal * -50;
147 traceline (start, end, TRUE, self);
148 if (trace_fraction == 1)
149 { // open at eye level
150 self.flags |= FL_WATERJUMP;
151 self.velocity_z = 225;
152 self.flags &~= FL_JUMPRELEASED;
153 self.teleport_time = time + 2; // safety net
159 float racecar_angle(float forward, float down)
161 float ret, angle_mult;
169 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
171 angle_mult = forward / (800 + forward);
174 return ret * angle_mult + 360 * (1 - angle_mult);
176 return ret * angle_mult;
179 void RaceCarPhysics()
181 // using this move type for "big rigs"
182 // the engine does not push the entity!
184 float accel, steer, f;
185 vector angles_save, rigvel;
187 angles_save = self.angles;
188 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
189 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
191 if(g_bugrigs_reverse_speeding)
195 // back accel is DIGITAL
196 // to prevent speedhack
206 makevectors(self.angles); // new forward direction!
208 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
210 float myspeed, upspeed, steerfactor, accelfactor;
212 myspeed = self.velocity * v_forward;
213 upspeed = self.velocity * v_up;
215 // responsiveness factor for steering and acceleration
216 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
217 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
219 if(myspeed < 0 && g_bugrigs_reverse_spinning)
220 steerfactor = -myspeed * g_bugrigs_steer;
222 steerfactor = -myspeed * f * g_bugrigs_steer;
224 if(myspeed < 0 && g_bugrigs_reverse_speeding)
225 accelfactor = g_bugrigs_accel;
227 accelfactor = f * g_bugrigs_accel;
228 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
234 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
238 if(!g_bugrigs_reverse_speeding)
239 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
246 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
250 if(g_bugrigs_reverse_stopping)
253 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
256 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
257 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
259 self.angles_y += steer * frametime * steerfactor; // apply steering
260 makevectors(self.angles); // new forward direction!
262 myspeed += accel * accelfactor * frametime;
264 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
268 myspeed = vlen(self.velocity);
270 // responsiveness factor for steering and acceleration
271 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
272 steerfactor = -myspeed * f;
273 self.angles_y += steer * frametime * steerfactor; // apply steering
275 rigvel = self.velocity;
276 makevectors(self.angles); // new forward direction!
279 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
280 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
281 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
282 //MAXIMA: solve(total_acceleration(v) = 0, v);
284 if(g_bugrigs_planar_movement)
286 vector rigvel_xy, neworigin, up;
289 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
293 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
296 mt = MOVE_NOMONSTERS;
298 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
299 up = trace_endpos - self.origin;
301 // BUG RIGS: align the move to the surface instead of doing collision testing
303 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
306 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
308 if(trace_fraction < 0.5)
311 neworigin = self.origin;
314 neworigin = trace_endpos;
316 if(trace_fraction < 1)
318 // now set angles_x so that the car points parallel to the surface
319 self.angles = vectoangles(
320 '1 0 0' * v_forward_x * trace_plane_normal_z
322 '0 1 0' * v_forward_y * trace_plane_normal_z
324 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
326 self.flags |= FL_ONGROUND;
330 // now set angles_x so that the car points forward, but is tilted in velocity direction
331 self.flags &~= FL_ONGROUND;
334 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
335 self.movetype = MOVETYPE_NOCLIP;
339 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
340 self.velocity = rigvel;
341 self.movetype = MOVETYPE_FLY;
345 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
346 if(trace_fraction != 1)
348 self.angles = vectoangles2(
349 '1 0 0' * v_forward_x * trace_plane_normal_z
351 '0 1 0' * v_forward_y * trace_plane_normal_z
353 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
361 vel_local_x = v_forward * self.velocity;
362 vel_local_y = v_right * self.velocity;
363 vel_local_z = v_up * self.velocity;
365 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
366 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
370 vector vf1, vu1, smoothangles;
371 makevectors(self.angles);
372 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
377 makevectors(angles_save);
378 vf1 = vf1 + v_forward * (1 - f);
379 vu1 = vu1 + v_up * (1 - f);
380 smoothangles = vectoangles2(vf1, vu1);
381 self.angles_x = -smoothangles_x;
382 self.angles_z = smoothangles_z;
385 float IsMoveInDirection(vector mv, float angle) // key mix factor
387 if(mv_x == 0 && mv_y == 0)
388 return 0; // avoid division by zero
389 angle = RAD2DEG * atan2(mv_y, mv_x);
390 angle = remainder(angle, 360) / 45;
395 return 1 - fabs(angle);
398 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
400 float zspeed, xyspeed, dot, k;
403 // this doesn't play well with analog input
404 if(self.movement_x == 0 || self.movement_y != 0)
405 return; // can't control movement if not moving forward or backward
408 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
413 k *= bound(0, wishspeed / sv_maxairspeed, 1);
415 zspeed = self.velocity_z;
417 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
419 dot = self.velocity * wishdir;
421 if(dot > 0) // we can't change direction while slowing down
423 k *= fabs(sv_aircontrol)*pow(dot, sv_aircontrol_power)*frametime;
424 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
427 self.velocity = self.velocity * xyspeed;
428 self.velocity_z = zspeed;
431 // example config for alternate speed clamping:
432 // sv_airaccel_qw 0.8
433 // sv_airaccel_sideways_friction 0
434 // prvm_globalset server speedclamp_mode 1
436 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float sidefric)
444 float vel_xy_current;
445 float vel_xy_backward, vel_xy_forward;
448 speedclamp = (accelqw < 0);
452 if(cvar("sv_gameplayfix_q2airaccelerate"))
453 wishspeed0 = wishspeed;
455 vel_straight = self.velocity * wishdir;
456 vel_z = self.velocity_z;
457 vel_xy = self.velocity - vel_z * '0 0 1';
458 vel_perpend = vel_xy - vel_straight * wishdir;
460 step = accel * frametime * wishspeed0;
462 vel_xy_current = vlen(vel_xy);
463 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
464 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
465 if(vel_xy_backward < 0)
466 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
468 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
470 if(sidefric < 0 && (vel_perpend*vel_perpend))
471 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
474 f = max(0, 1 + frametime * wishspeed * sidefric);
475 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
476 // this cannot be > 1
478 vel_perpend = vel_perpend * max(0, f);
481 fminimum = sqrt(fminimum);
482 vel_perpend = vel_perpend * max(fminimum, f);
486 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
488 vel_xy = vel_straight * wishdir + vel_perpend;
492 // ensure we don't get too fast or decelerate faster than we should
493 vel_xy_current = min(vlen(vel_xy), vel_xy_forward);
494 if(vel_xy_current > 0) // prevent division by zero
495 vel_xy = normalize(vel_xy) * vel_xy_current;
498 self.velocity = vel_xy + vel_z * '0 0 1';
501 void PM_AirAccelerate(vector wishdir, float wishspeed)
503 vector curvel, wishvel, acceldir, curdir;
504 float addspeed, accelspeed, curspeed, f;
510 curvel = self.velocity;
512 curspeed = vlen(curvel);
514 if(wishspeed > curspeed * 1.01)
516 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
520 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
521 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
523 wishvel = wishdir * wishspeed;
524 acceldir = wishvel - curvel;
525 addspeed = vlen(acceldir);
526 acceldir = normalize(acceldir);
528 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
530 if(sv_warsowbunny_backtosideratio < 1)
532 curdir = normalize(curvel);
533 dot = acceldir * curdir;
535 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
538 self.velocity += accelspeed * acceldir;
541 .vector movement_old;
544 .string lastclassname;
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 MUTATOR_CALLHOOK(PlayerPhysics);
694 self.items &~= IT_USING_JETPACK;
696 if(self.classname == "player")
698 if(self.race_penalty)
699 if(time > self.race_penalty)
700 self.race_penalty = 0;
702 not_allowed_to_move = 0;
703 if(self.race_penalty)
704 not_allowed_to_move = 1;
705 if(!cvar("sv_ready_restart_after_countdown"))
706 if(time < game_starttime)
707 not_allowed_to_move = 1;
709 if(not_allowed_to_move)
711 self.velocity = '0 0 0';
712 self.movetype = MOVETYPE_NONE;
713 self.disableclientprediction = 2;
715 else if(self.disableclientprediction == 2)
717 if(self.movetype == MOVETYPE_NONE)
718 self.movetype = MOVETYPE_WALK;
719 self.disableclientprediction = 0;
723 if (self.movetype == MOVETYPE_NONE)
730 if(self.runes & RUNE_SPEED)
732 if(self.runes & CURSE_SLOW)
733 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
735 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
737 else if(self.runes & CURSE_SLOW)
739 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
743 if(g_minstagib && (self.items & IT_INVINCIBLE))
745 maxspd_mod = cvar("g_minstagib_speed_moverate");
748 if(g_nexball && self.ballcarried)
750 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
755 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
758 if(self.classname != "player")
760 maxspd_mod = cvar("sv_spectator_speed_multiplier");
761 if(!self.spectatorspeed)
762 self.spectatorspeed = maxspd_mod;
763 if(self.impulse && self.impulse <= 19)
765 if(self.lastclassname != "player")
767 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
768 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
769 else if(self.impulse == 11)
770 self.spectatorspeed = maxspd_mod;
771 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
772 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
773 else if(self.impulse >= 1 && self.impulse <= 9)
774 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
775 } // otherwise just clear
778 maxspd_mod = self.spectatorspeed;
781 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
782 if(self.speed != spd)
786 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
787 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
788 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
789 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
792 maxspd_mod *= swampspd_mod; // only one common speed modder please!
795 // if dead, behave differently
799 if (!self.fixangle && !g_bugrigs)
802 self.angles_y = self.v_angle_y;
806 if(self.flags & FL_ONGROUND)
811 if(self.waterlevel < WATERLEVEL_SWIMMING)
812 if(time >= self.ladder_time)
815 self.nextstep = time + 0.3 + random() * 0.1;
816 trace_dphitq3surfaceflags = 0;
817 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
818 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
820 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
821 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
823 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
831 if(self.classname == "player")
833 if(sv_doublejump && time - self.jumppadusetime > 2 * sys_frametime)
835 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
836 self.flags &~= FL_ONGROUND;
837 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
838 self.flags |= FL_ONGROUND;
841 if (self.BUTTON_JUMP)
844 self.flags |= FL_JUMPRELEASED;
846 if (self.waterlevel == WATERLEVEL_SWIMMING)
850 if (self.flags & FL_WATERJUMP )
852 self.velocity_x = self.movedir_x;
853 self.velocity_y = self.movedir_y;
854 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
856 self.flags &~= FL_WATERJUMP;
857 self.teleport_time = 0;
860 else if (g_bugrigs && self.classname == "player")
864 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
866 // noclipping or flying
867 self.flags &~= FL_ONGROUND;
869 self.velocity = self.velocity * (1 - frametime * sv_friction);
870 makevectors(self.v_angle);
871 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
872 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
874 wishdir = normalize(wishvel);
875 wishspeed = vlen(wishvel);
876 if (wishspeed > sv_maxspeed*maxspd_mod)
877 wishspeed = sv_maxspeed*maxspd_mod;
878 if (time >= self.teleport_time)
879 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
881 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
884 self.flags &~= FL_ONGROUND;
886 makevectors(self.v_angle);
887 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
888 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
889 if (wishvel == '0 0 0')
890 wishvel = '0 0 -60'; // drift towards bottom
892 wishdir = normalize(wishvel);
893 wishspeed = vlen(wishvel);
894 if (wishspeed > sv_maxspeed*maxspd_mod)
895 wishspeed = sv_maxspeed*maxspd_mod;
896 wishspeed = wishspeed * 0.7;
899 self.velocity = self.velocity * (1 - frametime * sv_friction);
901 // water acceleration
902 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
904 else if (time < self.ladder_time)
906 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
907 self.flags &~= FL_ONGROUND;
909 self.velocity = self.velocity * (1 - frametime * sv_friction);
910 makevectors(self.v_angle);
911 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
912 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
914 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
916 self.velocity_z = self.velocity_z + sv_gravity * frametime;
917 if (self.ladder_entity.classname == "func_water")
920 if (f > self.ladder_entity.speed)
921 wishvel = wishvel * (self.ladder_entity.speed / f);
923 self.watertype = self.ladder_entity.skin;
924 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
925 if ((self.origin_z + self.view_ofs_z) < f)
926 self.waterlevel = WATERLEVEL_SUBMERGED;
927 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
928 self.waterlevel = WATERLEVEL_SWIMMING;
929 else if ((self.origin_z + self.mins_z + 1) < f)
930 self.waterlevel = WATERLEVEL_WETFEET;
933 self.waterlevel = WATERLEVEL_NONE;
934 self.watertype = CONTENT_EMPTY;
938 wishdir = normalize(wishvel);
939 wishspeed = vlen(wishvel);
940 if (wishspeed > sv_maxspeed*maxspd_mod)
941 wishspeed = sv_maxspeed*maxspd_mod;
942 if (time >= self.teleport_time)
944 // water acceleration
945 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
948 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
950 //makevectors(self.v_angle_y * '0 1 0');
951 makevectors(self.v_angle);
952 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
953 // add remaining speed as Z component
954 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
956 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
957 // add the unused velocity as up component
960 // if(self.BUTTON_JUMP)
961 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
963 // it is now normalized, so...
964 float a_side, a_up, a_add, a_diff;
965 a_side = cvar("g_jetpack_acceleration_side");
966 a_up = cvar("g_jetpack_acceleration_up");
967 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
976 //////////////////////////////////////////////////////////////////////////////////////
977 // finding the maximum over all vectors of above form
978 // with wishvel having an absolute value of 1
979 //////////////////////////////////////////////////////////////////////////////////////
980 // we're finding the maximum over
981 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
982 // for z in the range from -1 to 1
983 //////////////////////////////////////////////////////////////////////////////////////
984 // maximum is EITHER attained at the single extreme point:
985 a_diff = a_side * a_side - a_up * a_up;
988 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
989 if(f > -1 && f < 1) // can it be attained?
991 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
995 // OR attained at z = 1:
996 f = (a_up + a_add) * (a_up + a_add);
1002 // OR attained at z = -1:
1003 f = (a_up - a_add) * (a_up - a_add);
1007 //print("bottom\n");
1010 //////////////////////////////////////////////////////////////////////////////////////
1012 //print("best possible acceleration: ", ftos(best), "\n");
1015 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
1016 if(wishvel_z - sv_gravity > 0)
1017 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1019 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1022 fvel = vlen(wishvel);
1025 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
1027 fvel = min(1, vlen(wishvel) / best);
1028 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1029 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
1033 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1035 if (f > 0 && wishvel != '0 0 0')
1037 self.velocity = self.velocity + wishvel * f * frametime;
1038 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1039 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
1040 self.flags &~= FL_ONGROUND;
1041 self.items |= IT_USING_JETPACK;
1043 // jetpack also inhibits health regeneration, but only for 1 second
1044 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1047 else if (self.flags & FL_ONGROUND)
1049 // we get here if we ran out of ammo
1050 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1051 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1054 makevectors(self.v_angle_y * '0 1 0');
1055 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1057 if(!(self.lastflags & FL_ONGROUND))
1059 if(cvar("speedmeter"))
1060 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1061 if(self.lastground < time - 0.3)
1062 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1063 if(self.jumppadcount > 1)
1064 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1065 self.jumppadcount = 0;
1068 #ifdef LETS_TEST_FTEQCC
1069 if(self.velocity_x || self.velocity_y)
1087 if (f < sv_stopspeed)
1088 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
1090 f = 1 - frametime * sv_friction;
1092 self.velocity = self.velocity * f;
1094 self.velocity = '0 0 0';
1098 wishdir = normalize(wishvel);
1099 wishspeed = vlen(wishvel);
1100 if (wishspeed > sv_maxspeed*maxspd_mod)
1101 wishspeed = sv_maxspeed*maxspd_mod;
1103 wishspeed = wishspeed * 0.5;
1104 if (time >= self.teleport_time)
1105 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
1110 // we get here if we ran out of ammo
1111 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1112 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1116 maxairspd = sv_maxairspeed*maxspd_mod;
1117 airaccel = sv_airaccelerate*maxspd_mod;
1121 maxairspd = sv_maxairspeed;
1122 airaccel = sv_airaccelerate;
1125 makevectors(self.v_angle_y * '0 1 0');
1126 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1128 wishdir = normalize(wishvel);
1129 wishspeed = wishspeed0 = vlen(wishvel);
1130 if (wishspeed0 > sv_maxspeed*maxspd_mod)
1131 wishspeed0 = sv_maxspeed*maxspd_mod;
1132 if (wishspeed > maxairspd)
1133 wishspeed = maxairspd;
1135 wishspeed = wishspeed * 0.5;
1136 if (time >= self.teleport_time)
1142 airaccelqw = sv_airaccel_qw;
1143 accelerating = (self.velocity * wishdir > 0);
1144 wishspeed2 = wishspeed;
1147 if(sv_airstopaccelerate)
1148 if(self.velocity * wishdir < 0)
1149 airaccel = sv_airstopaccelerate*maxspd_mod;
1150 // this doesn't play well with analog input, but can't r
1151 // fixed like the AirControl can. So, don't set the maxa
1152 // cvars when you want to support analog input.
1153 if(self.movement_x == 0 && self.movement_y != 0)
1155 if(sv_maxairstrafespeed)
1157 wishspeed = min(wishspeed, sv_maxairstrafespeed*maxspd_mod);
1158 if(sv_maxairstrafespeed < sv_maxairspeed)
1161 if(sv_airstrafeaccelerate)
1163 airaccel = sv_airstrafeaccelerate*maxspd_mod;
1164 if(sv_airstrafeaccelerate > sv_airaccelerate)
1170 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1171 PM_AirAccelerate(wishdir, wishspeed);
1173 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd);
1176 CPM_PM_Aircontrol(wishdir, wishspeed2);
1180 if((g_cts || g_race) && self.classname != "observer") {
1181 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1182 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1183 speedaward_holder = self.netname;
1184 speedaward_lastupdate = time;
1186 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1192 race_send_speedaward(MSG_ALL);
1193 speedaward_lastsent = speedaward_speed;
1194 if (speedaward_speed > speedaward_alltimebest) {
1195 speedaward_alltimebest = speedaward_speed;
1196 speedaward_alltimebest_holder = speedaward_holder;
1197 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1198 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"), speedaward_alltimebest_holder);
1199 race_send_speedaward_alltimebest(MSG_ALL);
1204 if(self.flags & FL_ONGROUND)
1205 self.lastground = time;
1207 self.lastflags = self.flags;
1208 self.lastclassname = self.classname;