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 multijump_count;
33 .float multijump_delay;
34 .float multijump_ready;
40 When you press the jump key
43 void PlayerJump (void)
47 mjumpheight = cvar("sv_jumpvelocity");
48 if (self.waterlevel >= WATERLEVEL_SWIMMING)
50 if (self.watertype == CONTENT_WATER)
51 self.velocity_z = 200;
52 else if (self.watertype == CONTENT_SLIME)
60 if (cvar("g_multijump"))
62 if ((self.flags & FL_JUMPRELEASED) && !(self.flags & FL_ONGROUND))
63 self.multijump_ready = TRUE; // this is necessary to check that we released the jump button and pressed it again
64 else if (self.flags & FL_ONGROUND)
66 if (cvar("g_multijump") > 0)
67 self.multijump_count = 0;
69 self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller
70 self.multijump_ready = FALSE;
74 if(self.multijump_ready && time > self.multijump_delay && self.multijump_count < cvar("g_multijump") && self.velocity_z > cvar("g_multijump_speed"))
76 if (cvar("g_multijump") > 0)
77 self.multijump_count += 1;
78 self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump
80 else if (!(self.flags & FL_ONGROUND))
84 if (!(self.flags & FL_JUMPRELEASED))
87 if(self.health <= g_bloodloss)
92 if(self.runes & RUNE_SPEED)
94 if(self.runes & CURSE_SLOW)
95 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
97 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
99 else if(self.runes & CURSE_SLOW)
101 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
105 if(g_minstagib && (self.items & IT_INVINCIBLE))
107 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
110 if(cvar_string("sv_jumpspeedcap_min") != "")
111 self.velocity_z = max(cvar("sv_jumpvelocity") * cvar("sv_jumpspeedcap_min"), self.velocity_z);
112 if(cvar_string("sv_jumpspeedcap_max") != "") {
113 if(trace_fraction < 1 && trace_plane_normal_z < 0.98 && cvar("sv_jumpspeedcap_max_disable_on_ramps")) {
114 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
115 //print("Trace plane normal z: ", ftos(trace_plane_normal_z), ", disabling speed cap!\n");
118 self.velocity_z = min(cvar("sv_jumpvelocity") * cvar("sv_jumpspeedcap_max"), self.velocity_z) + trace_ent.velocity_z;
121 if(!(self.lastflags & FL_ONGROUND))
123 if(cvar("speedmeter"))
124 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
125 if(self.lastground < time - 0.3)
127 self.velocity_x *= (1 - cvar("sv_friction_on_land"));
128 self.velocity_y *= (1 - cvar("sv_friction_on_land"));
130 if(self.jumppadcount > 1)
131 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
132 self.jumppadcount = 0;
135 self.velocity_z = self.velocity_z + mjumpheight;
136 self.oldvelocity_z = self.velocity_z;
138 self.flags &~= FL_ONGROUND;
139 self.flags &~= FL_JUMPRELEASED;
141 if (cvar("g_multijump"))
142 self.multijump_delay = time + cvar("g_multijump_delay");
145 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
147 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
150 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
152 self.restart_jump = -1; // restart jump anim next time
153 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
156 void CheckWaterJump()
158 local vector start, end;
160 // check for a jump-out-of-water
161 makevectors (self.angles);
163 start_z = start_z + 8;
165 normalize(v_forward);
166 end = start + v_forward*24;
167 traceline (start, end, TRUE, self);
168 if (trace_fraction < 1)
170 start_z = start_z + self.maxs_z - 8;
171 end = start + v_forward*24;
172 self.movedir = trace_plane_normal * -50;
173 traceline (start, end, TRUE, self);
174 if (trace_fraction == 1)
175 { // open at eye level
176 self.flags |= FL_WATERJUMP;
177 self.velocity_z = 225;
178 self.flags &~= FL_JUMPRELEASED;
179 self.teleport_time = time + 2; // safety net
185 float racecar_angle(float forward, float down)
187 float ret, angle_mult;
195 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
197 angle_mult = forward / (800 + forward);
200 return ret * angle_mult + 360 * (1 - angle_mult);
202 return ret * angle_mult;
205 void RaceCarPhysics()
207 // using this move type for "big rigs"
208 // the engine does not push the entity!
210 float accel, steer, f;
211 vector angles_save, rigvel;
213 angles_save = self.angles;
214 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
215 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
217 if(g_bugrigs_reverse_speeding)
221 // back accel is DIGITAL
222 // to prevent speedhack
232 makevectors(self.angles); // new forward direction!
234 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
236 float myspeed, upspeed, steerfactor, accelfactor;
238 myspeed = self.velocity * v_forward;
239 upspeed = self.velocity * v_up;
241 // responsiveness factor for steering and acceleration
242 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
243 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
245 if(myspeed < 0 && g_bugrigs_reverse_spinning)
246 steerfactor = -myspeed * g_bugrigs_steer;
248 steerfactor = -myspeed * f * g_bugrigs_steer;
250 if(myspeed < 0 && g_bugrigs_reverse_speeding)
251 accelfactor = g_bugrigs_accel;
253 accelfactor = f * g_bugrigs_accel;
254 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
260 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
264 if(!g_bugrigs_reverse_speeding)
265 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
272 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
276 if(g_bugrigs_reverse_stopping)
279 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
282 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
283 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
285 self.angles_y += steer * frametime * steerfactor; // apply steering
286 makevectors(self.angles); // new forward direction!
288 myspeed += accel * accelfactor * frametime;
290 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
294 myspeed = vlen(self.velocity);
296 // responsiveness factor for steering and acceleration
297 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
298 steerfactor = -myspeed * f;
299 self.angles_y += steer * frametime * steerfactor; // apply steering
301 rigvel = self.velocity;
302 makevectors(self.angles); // new forward direction!
305 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
306 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
307 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
308 //MAXIMA: solve(total_acceleration(v) = 0, v);
310 if(g_bugrigs_planar_movement)
312 vector rigvel_xy, neworigin, up;
315 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
319 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
322 mt = MOVE_NOMONSTERS;
324 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
325 up = trace_endpos - self.origin;
327 // BUG RIGS: align the move to the surface instead of doing collision testing
329 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
332 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
334 if(trace_fraction < 0.5)
337 neworigin = self.origin;
340 neworigin = trace_endpos;
342 if(trace_fraction < 1)
344 // now set angles_x so that the car points parallel to the surface
345 self.angles = vectoangles(
346 '1 0 0' * v_forward_x * trace_plane_normal_z
348 '0 1 0' * v_forward_y * trace_plane_normal_z
350 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
352 self.flags |= FL_ONGROUND;
356 // now set angles_x so that the car points forward, but is tilted in velocity direction
357 self.flags &~= FL_ONGROUND;
360 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
361 self.movetype = MOVETYPE_NOCLIP;
365 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
366 self.velocity = rigvel;
367 self.movetype = MOVETYPE_FLY;
371 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
372 if(trace_fraction != 1)
374 self.angles = vectoangles2(
375 '1 0 0' * v_forward_x * trace_plane_normal_z
377 '0 1 0' * v_forward_y * trace_plane_normal_z
379 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
387 vel_local_x = v_forward * self.velocity;
388 vel_local_y = v_right * self.velocity;
389 vel_local_z = v_up * self.velocity;
391 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
392 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
396 vector vf1, vu1, smoothangles;
397 makevectors(self.angles);
398 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
403 makevectors(angles_save);
404 vf1 = vf1 + v_forward * (1 - f);
405 vu1 = vu1 + v_up * (1 - f);
406 smoothangles = vectoangles2(vf1, vu1);
407 self.angles_x = -smoothangles_x;
408 self.angles_z = smoothangles_z;
411 float IsMoveInDirection(vector mv, float angle) // key mix factor
413 if(mv_x == 0 && mv_y == 0)
414 return 0; // avoid division by zero
415 angle = RAD2DEG * atan2(mv_y, mv_x);
416 angle = remainder(angle, 360) / 45;
421 return 1 - fabs(angle);
424 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
426 float zspeed, xyspeed, dot, k;
429 // this doesn't play well with analog input
430 if(self.movement_x == 0 || self.movement_y != 0)
431 return; // can't control movement if not moving forward or backward
434 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
439 k *= bound(0, wishspeed / sv_maxairspeed, 1);
441 zspeed = self.velocity_z;
443 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
445 dot = self.velocity * wishdir;
446 k *= sv_aircontrol*dot*dot*frametime;
448 if(dot > 0) // we can't change direction while slowing down
450 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
453 self.velocity = self.velocity * xyspeed;
454 self.velocity_z = zspeed;
457 // example config for alternate speed clamping:
458 // sv_airaccel_qw 0.8
459 // sv_airaccel_sideways_friction 0
460 // prvm_globalset server speedclamp_mode 1
462 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float sidefric)
470 float vel_xy_current;
471 float vel_xy_backward, vel_xy_forward;
474 speedclamp = (accelqw < 0);
478 if(cvar("sv_gameplayfix_q2airaccelerate"))
479 wishspeed0 = wishspeed;
481 vel_straight = self.velocity * wishdir;
482 vel_z = self.velocity_z;
483 vel_xy = self.velocity - vel_z * '0 0 1';
484 vel_perpend = vel_xy - vel_straight * wishdir;
486 step = accel * frametime * wishspeed0;
488 vel_xy_current = vlen(vel_xy);
489 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
490 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
491 if(vel_xy_backward < 0)
492 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
494 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
496 if(sidefric < 0 && (vel_perpend*vel_perpend))
497 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
500 f = max(0, 1 + frametime * wishspeed * sidefric);
501 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
502 // this cannot be > 1
504 vel_perpend = vel_perpend * max(0, f);
507 fminimum = sqrt(fminimum);
508 vel_perpend = vel_perpend * max(fminimum, f);
512 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
514 vel_xy = vel_straight * wishdir + vel_perpend;
518 // ensure we don't get too fast or decelerate faster than we should
519 vel_xy_current = min(vlen(vel_xy), vel_xy_forward);
520 if(vel_xy_current > 0) // prevent division by zero
521 vel_xy = normalize(vel_xy) * vel_xy_current;
524 self.velocity = vel_xy + vel_z * '0 0 1';
527 void PM_AirAccelerate(vector wishdir, float wishspeed)
529 vector curvel, wishvel, acceldir, curdir;
530 float addspeed, accelspeed, curspeed, f;
536 curvel = self.velocity;
538 curspeed = vlen(curvel);
540 if(wishspeed > curspeed * 1.01)
542 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
546 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
547 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
549 wishvel = wishdir * wishspeed;
550 acceldir = wishvel - curvel;
551 addspeed = vlen(acceldir);
552 acceldir = normalize(acceldir);
554 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
556 if(sv_warsowbunny_backtosideratio < 1)
558 curdir = normalize(curvel);
559 dot = acceldir * curdir;
561 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
564 self.velocity += accelspeed * acceldir;
567 .vector movement_old;
570 .string lastclassname;
572 .float() PlayerPhysplug;
574 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
575 .float specialcommand_pos;
576 void SpecialCommand()
581 if(!CheatImpulse(99))
582 print("A hollow voice says \"Plugh\".\n");
586 float speedaward_speed;
587 string speedaward_holder;
588 void race_send_speedaward(float msg)
590 // send the best speed of the round
591 WriteByte(msg, SVC_TEMPENTITY);
592 WriteByte(msg, TE_CSQC_RACE);
593 WriteByte(msg, RACE_NET_SPEED_AWARD);
594 WriteInt24_t(msg, floor(speedaward_speed+0.5));
595 WriteString(msg, speedaward_holder);
598 float speedaward_alltimebest;
599 string speedaward_alltimebest_holder;
600 void race_send_speedaward_alltimebest(float msg)
602 // send the best speed
603 WriteByte(msg, SVC_TEMPENTITY);
604 WriteByte(msg, TE_CSQC_RACE);
605 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
606 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
607 WriteString(msg, speedaward_alltimebest_holder);
610 string GetMapname(void);
611 float speedaward_lastupdate;
612 float speedaward_lastsent;
613 .float jumppadusetime;
614 void SV_PlayerPhysics()
616 local vector wishvel, wishdir, v;
617 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
620 float not_allowed_to_move;
623 if(self.PlayerPhysplug)
624 if(self.PlayerPhysplug())
627 self.race_movetime_frac += frametime;
628 f = floor(self.race_movetime_frac);
629 self.race_movetime_frac -= f;
630 self.race_movetime_count += f;
631 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
635 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);
639 else if(buttons == 1)
641 else if(buttons == 2)
643 else if(buttons == 128)
645 else if(buttons == 256)
647 else if(buttons == 512)
649 else if(buttons == 1024)
654 if(c == substring(specialcommand, self.specialcommand_pos, 1))
656 self.specialcommand_pos += 1;
657 if(self.specialcommand_pos >= strlen(specialcommand))
659 self.specialcommand_pos = 0;
664 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
665 self.specialcommand_pos = 0;
667 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
669 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
670 self.parm_idlesince = time;
672 buttons_prev = self.buttons_old;
673 self.buttons_old = buttons;
674 self.movement_old = self.movement;
675 self.v_angle_old = self.v_angle;
677 if(time < self.nickspamtime)
678 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
680 // slight annoyance for nick change scripts
681 self.movement = -1 * self.movement;
682 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
684 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!
686 self.angles_x = random() * 360;
687 self.angles_y = random() * 360;
688 // at least I'm not forcing retardedview by also assigning to angles_z
693 if (self.punchangle != '0 0 0')
695 f = vlen(self.punchangle) - 10 * frametime;
697 self.punchangle = normalize(self.punchangle) * f;
699 self.punchangle = '0 0 0';
702 if (self.punchvector != '0 0 0')
704 f = vlen(self.punchvector) - 30 * frametime;
706 self.punchvector = normalize(self.punchvector) * f;
708 self.punchvector = '0 0 0';
711 if (clienttype(self) == CLIENTTYPE_BOT)
713 if(playerdemo_read())
718 self.items &~= IT_USING_JETPACK;
720 if(self.classname == "player")
722 if(self.race_penalty)
723 if(time > self.race_penalty)
724 self.race_penalty = 0;
726 not_allowed_to_move = 0;
727 if(self.race_penalty)
728 not_allowed_to_move = 1;
729 if(!cvar("sv_ready_restart_after_countdown"))
730 if(time < game_starttime)
731 not_allowed_to_move = 1;
733 if(not_allowed_to_move)
735 self.velocity = '0 0 0';
736 self.movetype = MOVETYPE_NONE;
737 self.disableclientprediction = 2;
739 else if(self.disableclientprediction == 2)
741 if(self.movetype == MOVETYPE_NONE)
742 self.movetype = MOVETYPE_WALK;
743 self.disableclientprediction = 0;
747 if (self.movetype == MOVETYPE_NONE)
754 if(self.runes & RUNE_SPEED)
756 if(self.runes & CURSE_SLOW)
757 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
759 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
761 else if(self.runes & CURSE_SLOW)
763 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
767 if(g_minstagib && (self.items & IT_INVINCIBLE))
769 maxspd_mod = cvar("g_minstagib_speed_moverate");
772 if(g_nexball && self.ballcarried)
774 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
779 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
782 if(self.classname != "player")
784 maxspd_mod = cvar("sv_spectator_speed_multiplier");
785 if(!self.spectatorspeed)
786 self.spectatorspeed = maxspd_mod;
787 if(self.impulse && self.impulse <= 19)
789 if(self.lastclassname != "player")
791 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
792 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
793 else if(self.impulse == 11)
794 self.spectatorspeed = maxspd_mod;
795 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
796 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
797 else if(self.impulse >= 1 && self.impulse <= 9)
798 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
799 } // otherwise just clear
802 maxspd_mod = self.spectatorspeed;
805 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
806 if(self.speed != spd)
810 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
811 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
812 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
813 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
816 maxspd_mod *= swampspd_mod; // only one common speed modder please!
819 // if dead, behave differently
823 if (!self.fixangle && !g_bugrigs)
826 self.angles_y = self.v_angle_y;
830 if(self.flags & FL_ONGROUND)
835 if(self.waterlevel < WATERLEVEL_SWIMMING)
836 if(time >= self.ladder_time)
839 self.nextstep = time + 0.3 + random() * 0.1;
840 trace_dphitq3surfaceflags = 0;
841 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
842 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
844 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
845 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
847 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
855 if(self.classname == "player")
857 if(sv_doublejump && time - self.jumppadusetime > 2 * sys_frametime)
859 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
860 self.flags &~= FL_ONGROUND;
861 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
862 self.flags |= FL_ONGROUND;
865 if (self.BUTTON_JUMP)
868 self.flags |= FL_JUMPRELEASED;
870 if (self.waterlevel == WATERLEVEL_SWIMMING)
874 if (self.flags & FL_WATERJUMP )
876 self.velocity_x = self.movedir_x;
877 self.velocity_y = self.movedir_y;
878 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
880 self.flags &~= FL_WATERJUMP;
881 self.teleport_time = 0;
884 else if (g_bugrigs && self.classname == "player")
888 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
890 // noclipping or flying
891 self.flags &~= FL_ONGROUND;
893 self.velocity = self.velocity * (1 - frametime * sv_friction);
894 makevectors(self.v_angle);
895 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
896 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
898 wishdir = normalize(wishvel);
899 wishspeed = vlen(wishvel);
900 if (wishspeed > sv_maxspeed*maxspd_mod)
901 wishspeed = sv_maxspeed*maxspd_mod;
902 if (time >= self.teleport_time)
903 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
905 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
908 self.flags &~= FL_ONGROUND;
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;
913 if (wishvel == '0 0 0')
914 wishvel = '0 0 -60'; // drift towards bottom
916 wishdir = normalize(wishvel);
917 wishspeed = vlen(wishvel);
918 if (wishspeed > sv_maxspeed*maxspd_mod)
919 wishspeed = sv_maxspeed*maxspd_mod;
920 wishspeed = wishspeed * 0.7;
923 self.velocity = self.velocity * (1 - frametime * sv_friction);
925 // water acceleration
926 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
928 else if (time < self.ladder_time)
930 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
931 self.flags &~= FL_ONGROUND;
933 self.velocity = self.velocity * (1 - frametime * sv_friction);
934 makevectors(self.v_angle);
935 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
936 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
938 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
940 self.velocity_z = self.velocity_z + sv_gravity * frametime;
941 if (self.ladder_entity.classname == "func_water")
944 if (f > self.ladder_entity.speed)
945 wishvel = wishvel * (self.ladder_entity.speed / f);
947 self.watertype = self.ladder_entity.skin;
948 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
949 if ((self.origin_z + self.view_ofs_z) < f)
950 self.waterlevel = WATERLEVEL_SUBMERGED;
951 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
952 self.waterlevel = WATERLEVEL_SWIMMING;
953 else if ((self.origin_z + self.mins_z + 1) < f)
954 self.waterlevel = WATERLEVEL_WETFEET;
957 self.waterlevel = WATERLEVEL_NONE;
958 self.watertype = CONTENT_EMPTY;
962 wishdir = normalize(wishvel);
963 wishspeed = vlen(wishvel);
964 if (wishspeed > sv_maxspeed*maxspd_mod)
965 wishspeed = sv_maxspeed*maxspd_mod;
966 if (time >= self.teleport_time)
968 // water acceleration
969 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
972 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
974 //makevectors(self.v_angle_y * '0 1 0');
975 makevectors(self.v_angle);
976 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
977 // add remaining speed as Z component
978 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
980 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
981 // add the unused velocity as up component
984 // if(self.BUTTON_JUMP)
985 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
987 // it is now normalized, so...
988 float a_side, a_up, a_add, a_diff;
989 a_side = cvar("g_jetpack_acceleration_side");
990 a_up = cvar("g_jetpack_acceleration_up");
991 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
1000 //////////////////////////////////////////////////////////////////////////////////////
1001 // finding the maximum over all vectors of above form
1002 // with wishvel having an absolute value of 1
1003 //////////////////////////////////////////////////////////////////////////////////////
1004 // we're finding the maximum over
1005 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1006 // for z in the range from -1 to 1
1007 //////////////////////////////////////////////////////////////////////////////////////
1008 // maximum is EITHER attained at the single extreme point:
1009 a_diff = a_side * a_side - a_up * a_up;
1012 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1013 if(f > -1 && f < 1) // can it be attained?
1015 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1016 //print("middle\n");
1019 // OR attained at z = 1:
1020 f = (a_up + a_add) * (a_up + a_add);
1026 // OR attained at z = -1:
1027 f = (a_up - a_add) * (a_up - a_add);
1031 //print("bottom\n");
1034 //////////////////////////////////////////////////////////////////////////////////////
1036 //print("best possible acceleration: ", ftos(best), "\n");
1039 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
1040 if(wishvel_z - sv_gravity > 0)
1041 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1043 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1046 fvel = vlen(wishvel);
1049 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
1051 fvel = min(1, vlen(wishvel) / best);
1052 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1053 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
1057 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1059 if (f > 0 && wishvel != '0 0 0')
1061 self.velocity = self.velocity + wishvel * f * frametime;
1062 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1063 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
1064 self.flags &~= FL_ONGROUND;
1065 self.items |= IT_USING_JETPACK;
1067 // jetpack also inhibits health regeneration, but only for 1 second
1068 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1071 else if (self.flags & FL_ONGROUND)
1073 // we get here if we ran out of ammo
1074 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1075 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1078 makevectors(self.v_angle_y * '0 1 0');
1079 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1081 if(!(self.lastflags & FL_ONGROUND))
1083 if(cvar("speedmeter"))
1084 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1085 if(self.lastground < time - 0.3)
1086 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1087 if(self.jumppadcount > 1)
1088 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1089 self.jumppadcount = 0;
1092 #ifdef LETS_TEST_FTEQCC
1093 if(self.velocity_x || self.velocity_y)
1111 if (f < sv_stopspeed)
1112 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
1114 f = 1 - frametime * sv_friction;
1116 self.velocity = self.velocity * f;
1118 self.velocity = '0 0 0';
1122 wishdir = normalize(wishvel);
1123 wishspeed = vlen(wishvel);
1124 if (wishspeed > sv_maxspeed*maxspd_mod)
1125 wishspeed = sv_maxspeed*maxspd_mod;
1127 wishspeed = wishspeed * 0.5;
1128 if (time >= self.teleport_time)
1129 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
1134 // we get here if we ran out of ammo
1135 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1136 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1140 maxairspd = sv_maxairspeed*maxspd_mod;
1141 airaccel = sv_airaccelerate*maxspd_mod;
1145 maxairspd = sv_maxairspeed;
1146 airaccel = sv_airaccelerate;
1149 makevectors(self.v_angle_y * '0 1 0');
1150 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1152 wishdir = normalize(wishvel);
1153 wishspeed = wishspeed0 = vlen(wishvel);
1154 if (wishspeed0 > sv_maxspeed*maxspd_mod)
1155 wishspeed0 = sv_maxspeed*maxspd_mod;
1156 if (wishspeed > maxairspd)
1157 wishspeed = maxairspd;
1159 wishspeed = wishspeed * 0.5;
1160 if (time >= self.teleport_time)
1166 airaccelqw = sv_airaccel_qw;
1167 accelerating = (self.velocity * wishdir > 0);
1168 wishspeed2 = wishspeed;
1171 if(sv_airstopaccelerate)
1172 if(self.velocity * wishdir < 0)
1173 airaccel = sv_airstopaccelerate*maxspd_mod;
1174 // this doesn't play well with analog input, but can't r
1175 // fixed like the AirControl can. So, don't set the maxa
1176 // cvars when you want to support analog input.
1177 if(self.movement_x == 0 && self.movement_y != 0)
1179 if(sv_maxairstrafespeed)
1181 wishspeed = min(wishspeed, sv_maxairstrafespeed*maxspd_mod);
1182 if(sv_maxairstrafespeed < sv_maxairspeed)
1185 if(sv_airstrafeaccelerate)
1187 airaccel = sv_airstrafeaccelerate*maxspd_mod;
1188 if(sv_airstrafeaccelerate > sv_airaccelerate)
1194 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1195 PM_AirAccelerate(wishdir, wishspeed);
1197 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd);
1200 CPM_PM_Aircontrol(wishdir, wishspeed2);
1204 if((g_cts || g_race) && self.classname != "observer") {
1205 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1206 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1207 speedaward_holder = self.netname;
1208 speedaward_lastupdate = time;
1210 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1216 race_send_speedaward(MSG_ALL);
1217 speedaward_lastsent = speedaward_speed;
1218 if (speedaward_speed > speedaward_alltimebest) {
1219 speedaward_alltimebest = speedaward_speed;
1220 speedaward_alltimebest_holder = speedaward_holder;
1221 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1222 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"), speedaward_alltimebest_holder);
1223 race_send_speedaward_alltimebest(MSG_ALL);
1228 if(self.flags & FL_ONGROUND)
1229 self.lastground = time;
1231 self.lastflags = self.flags;
1232 self.lastclassname = self.classname;