7 float sv_airaccelerate;
11 float sv_airaccel_sideways_friction;
13 float sv_airstopaccelerate;
14 float sv_airstrafeaccelerate;
15 float sv_maxairstrafespeed;
17 float sv_warsowbunny_airforwardaccel;
18 float sv_warsowbunny_accel;
19 float sv_warsowbunny_topspeed;
20 float sv_warsowbunny_turnaccel;
21 float sv_warsowbunny_backtosideratio;
24 .entity ladder_entity;
26 .float swamp_slowdown;
30 .float spectatorspeed;
32 .float doublejump_nextjumptime;
38 When you press the jump key
41 void PlayerJump (void)
45 mjumpheight = cvar("sv_jumpvelocity");
46 if (self.waterlevel >= WATERLEVEL_SWIMMING)
48 if (self.watertype == CONTENT_WATER)
49 self.velocity_z = 200;
50 else if (self.watertype == CONTENT_SLIME)
58 if (!(self.flags & FL_ONGROUND))
62 if (!(self.flags & FL_JUMPRELEASED))
65 if(self.health <= g_bloodloss)
69 if(time < self.doublejump_nextjumptime)
74 if(self.runes & RUNE_SPEED)
76 if(self.runes & CURSE_SLOW)
77 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
79 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
81 else if(self.runes & CURSE_SLOW)
83 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
87 if(g_minstagib && (self.items & IT_INVINCIBLE))
89 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
92 if(!(self.lastflags & FL_ONGROUND))
94 if(cvar("speedmeter"))
95 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
96 if(self.lastground < time - 0.3)
97 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
98 if(self.jumppadcount > 1)
99 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
100 self.jumppadcount = 0;
103 self.velocity_z = self.velocity_z + mjumpheight;
104 self.oldvelocity_z = self.velocity_z;
106 self.flags &~= FL_ONGROUND;
107 self.flags &~= FL_JUMPRELEASED;
110 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
112 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
115 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
119 // we're moving upwards at self.velocity_z
120 // only allow jumping after we got 2 units upwards
121 // so we for sure leave the FL_ONGROUND check
123 // but as this sucks because of factoring in gravity, we'll just do it
124 // for 3 units, and constant velocity
125 if(self.velocity_z >= mjumpheight * 0.5) // only do this when we won't INTENTIONALLY jump a second time... TODO make a better check for this
127 self.doublejump_nextjumptime = time + 3 / max(30, self.velocity_z); // max 0.1s blocking of jumps, typically just one frame
128 //print(sprintf("blocking jumps for next %f seconds (vel: %f to %f)\n", self.doublejump_nextjumptime - time, self.velocity_z - mjumpheight, self.velocity_z));
132 self.restart_jump = -1; // restart jump anim next time
133 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
136 void CheckWaterJump()
138 local vector start, end;
140 // check for a jump-out-of-water
141 makevectors (self.angles);
143 start_z = start_z + 8;
145 normalize(v_forward);
146 end = start + v_forward*24;
147 traceline (start, end, TRUE, self);
148 if (trace_fraction < 1)
150 start_z = start_z + self.maxs_z - 8;
151 end = start + v_forward*24;
152 self.movedir = trace_plane_normal * -50;
153 traceline (start, end, TRUE, self);
154 if (trace_fraction == 1)
155 { // open at eye level
156 self.flags |= FL_WATERJUMP;
157 self.velocity_z = 225;
158 self.flags &~= FL_JUMPRELEASED;
159 self.teleport_time = time + 2; // safety net
165 float racecar_angle(float forward, float down)
167 float ret, angle_mult;
175 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
177 angle_mult = forward / (800 + forward);
180 return ret * angle_mult + 360 * (1 - angle_mult);
182 return ret * angle_mult;
185 void RaceCarPhysics()
187 // using this move type for "big rigs"
188 // the engine does not push the entity!
190 float accel, steer, f;
191 vector angles_save, rigvel;
193 angles_save = self.angles;
194 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
195 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
197 if(g_bugrigs_reverse_speeding)
201 // back accel is DIGITAL
202 // to prevent speedhack
212 makevectors(self.angles); // new forward direction!
214 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
216 float myspeed, upspeed, steerfactor, accelfactor;
218 myspeed = self.velocity * v_forward;
219 upspeed = self.velocity * v_up;
221 // responsiveness factor for steering and acceleration
222 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
223 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
225 if(myspeed < 0 && g_bugrigs_reverse_spinning)
226 steerfactor = -myspeed * g_bugrigs_steer;
228 steerfactor = -myspeed * f * g_bugrigs_steer;
230 if(myspeed < 0 && g_bugrigs_reverse_speeding)
231 accelfactor = g_bugrigs_accel;
233 accelfactor = f * g_bugrigs_accel;
234 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
240 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
244 if(!g_bugrigs_reverse_speeding)
245 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
252 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
256 if(g_bugrigs_reverse_stopping)
259 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
262 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
263 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
265 self.angles_y += steer * frametime * steerfactor; // apply steering
266 makevectors(self.angles); // new forward direction!
268 myspeed += accel * accelfactor * frametime;
270 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
274 myspeed = vlen(self.velocity);
276 // responsiveness factor for steering and acceleration
277 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
278 steerfactor = -myspeed * f;
279 self.angles_y += steer * frametime * steerfactor; // apply steering
281 rigvel = self.velocity;
282 makevectors(self.angles); // new forward direction!
285 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
286 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
287 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
288 //MAXIMA: solve(total_acceleration(v) = 0, v);
290 if(g_bugrigs_planar_movement)
292 vector rigvel_xy, neworigin, up;
295 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
299 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
302 mt = MOVE_NOMONSTERS;
304 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
305 up = trace_endpos - self.origin;
307 // BUG RIGS: align the move to the surface instead of doing collision testing
309 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
312 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
314 if(trace_fraction < 0.5)
317 neworigin = self.origin;
320 neworigin = trace_endpos;
322 if(trace_fraction < 1)
324 // now set angles_x so that the car points parallel to the surface
325 self.angles = vectoangles(
326 '1 0 0' * v_forward_x * trace_plane_normal_z
328 '0 1 0' * v_forward_y * trace_plane_normal_z
330 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
332 self.flags |= FL_ONGROUND;
336 // now set angles_x so that the car points forward, but is tilted in velocity direction
337 self.flags &~= FL_ONGROUND;
340 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
341 self.movetype = MOVETYPE_NOCLIP;
345 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
346 self.velocity = rigvel;
347 self.movetype = MOVETYPE_FLY;
351 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
352 if(trace_fraction != 1)
354 self.angles = vectoangles2(
355 '1 0 0' * v_forward_x * trace_plane_normal_z
357 '0 1 0' * v_forward_y * trace_plane_normal_z
359 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
367 vel_local_x = v_forward * self.velocity;
368 vel_local_y = v_right * self.velocity;
369 vel_local_z = v_up * self.velocity;
371 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
372 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
376 vector vf1, vu1, smoothangles;
377 makevectors(self.angles);
378 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
383 makevectors(angles_save);
384 vf1 = vf1 + v_forward * (1 - f);
385 vu1 = vu1 + v_up * (1 - f);
386 smoothangles = vectoangles2(vf1, vu1);
387 self.angles_x = -smoothangles_x;
388 self.angles_z = smoothangles_z;
391 float IsMoveInDirection(vector mv, float angle) // key mix factor
393 if(mv_x == 0 && mv_y == 0)
394 return 0; // avoid division by zero
395 angle = RAD2DEG * atan2(mv_y, mv_x);
396 angle = remainder(angle, 360) / 45;
401 return 1 - fabs(angle);
404 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
406 float zspeed, xyspeed, dot, k;
409 // this doesn't play well with analog input
410 if(self.movement_x == 0 || self.movement_y != 0)
411 return; // can't control movement if not moving forward or backward
414 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
419 k *= bound(0, wishspeed / sv_maxairspeed, 1);
421 zspeed = self.velocity_z;
423 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
425 dot = self.velocity * wishdir;
426 k *= sv_aircontrol*dot*dot*frametime;
428 if(dot > 0) // we can't change direction while slowing down
430 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
433 self.velocity = self.velocity * xyspeed;
434 self.velocity_z = zspeed;
437 // example config for alternate speed clamping:
438 // sv_airaccel_qw 0.8
439 // sv_airaccel_sideways_friction 0
440 // prvm_globalset server speedclamp_mode 1
442 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float sidefric)
450 float vel_xy_current;
451 float vel_xy_backward, vel_xy_forward;
454 speedclamp = (accelqw < 0);
458 if(cvar("sv_gameplayfix_q2airaccelerate"))
459 wishspeed0 = wishspeed;
461 vel_straight = self.velocity * wishdir;
462 vel_z = self.velocity_z;
463 vel_xy = self.velocity - vel_z * '0 0 1';
464 vel_perpend = vel_xy - vel_straight * wishdir;
466 step = accel * frametime * wishspeed0;
468 vel_xy_current = vlen(vel_xy);
469 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
470 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
471 if(vel_xy_backward < 0)
472 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
474 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
476 if(sidefric < 0 && (vel_perpend*vel_perpend))
477 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
480 f = (1 - frametime * wishspeed * sidefric);
481 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
483 vel_perpend = vel_perpend * f;
486 fminimum = sqrt(fminimum);
487 vel_perpend = vel_perpend * bound(fminimum, f, 1);
491 vel_perpend = vel_perpend * (1 - frametime * wishspeed * sidefric);
493 vel_xy = vel_straight * wishdir + vel_perpend;
497 // ensure we don't get too fast or decelerate faster than we should
498 vel_xy_current = min(vlen(vel_xy), vel_xy_forward);
499 if(vel_xy_current > 0) // prevent division by zero
500 vel_xy = normalize(vel_xy) * vel_xy_current;
503 self.velocity = vel_xy + vel_z * '0 0 1';
506 void PM_AirAccelerate(vector wishdir, float wishspeed)
508 vector curvel, wishvel, acceldir, curdir;
509 float addspeed, accelspeed, curspeed, f;
515 curvel = self.velocity;
517 curspeed = vlen(curvel);
519 if(wishspeed > curspeed * 1.01)
521 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
525 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
526 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
528 wishvel = wishdir * wishspeed;
529 acceldir = wishvel - curvel;
530 addspeed = vlen(acceldir);
531 acceldir = normalize(acceldir);
533 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
535 if(sv_warsowbunny_backtosideratio < 1)
537 curdir = normalize(curvel);
538 dot = acceldir * curdir;
540 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
543 self.velocity += accelspeed * acceldir;
546 .vector movement_old;
549 .string lastclassname;
551 void Nixnex_GiveCurrentWeapon();
552 .float() PlayerPhysplug;
554 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
555 .float specialcommand_pos;
556 void SpecialCommand()
561 if(!CheatImpulse(99))
562 print("A hollow voice says \"Plugh\".\n");
566 float speedaward_speed;
567 string speedaward_holder;
568 void race_send_speedaward(float msg)
570 // send the best speed of the round
571 WriteByte(msg, SVC_TEMPENTITY);
572 WriteByte(msg, TE_CSQC_RACE);
573 WriteByte(msg, RACE_NET_SPEED_AWARD);
574 WriteInt24_t(msg, floor(speedaward_speed+0.5));
575 WriteString(msg, speedaward_holder);
578 float speedaward_alltimebest;
579 string speedaward_alltimebest_holder;
580 void race_send_speedaward_alltimebest(float msg)
582 // send the best speed
583 WriteByte(msg, SVC_TEMPENTITY);
584 WriteByte(msg, TE_CSQC_RACE);
585 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
586 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
587 WriteString(msg, speedaward_alltimebest_holder);
590 string GetMapname(void);
591 float speedaward_lastupdate;
592 float speedaward_lastsent;
593 void SV_PlayerPhysics()
595 local vector wishvel, wishdir, v;
596 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
599 float not_allowed_to_move;
602 if(self.PlayerPhysplug)
603 if(self.PlayerPhysplug())
606 self.race_movetime_frac += frametime;
607 f = floor(self.race_movetime_frac);
608 self.race_movetime_frac -= f;
609 self.race_movetime_count += f;
610 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
614 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);
618 else if(buttons == 1)
620 else if(buttons == 2)
622 else if(buttons == 128)
624 else if(buttons == 256)
626 else if(buttons == 512)
628 else if(buttons == 1024)
633 if(c == substring(specialcommand, self.specialcommand_pos, 1))
635 self.specialcommand_pos += 1;
636 if(self.specialcommand_pos >= strlen(specialcommand))
638 self.specialcommand_pos = 0;
643 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
644 self.specialcommand_pos = 0;
646 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
648 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
649 self.parm_idlesince = time;
651 buttons_prev = self.buttons_old;
652 self.buttons_old = buttons;
653 self.movement_old = self.movement;
654 self.v_angle_old = self.v_angle;
656 if(time < self.nickspamtime)
657 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
659 // slight annoyance for nick change scripts
660 self.movement = -1 * self.movement;
661 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
663 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!
665 self.angles_x = random() * 360;
666 self.angles_y = random() * 360;
667 // at least I'm not forcing retardedview by also assigning to angles_z
672 if (self.punchangle != '0 0 0')
674 f = vlen(self.punchangle) - 10 * frametime;
676 self.punchangle = normalize(self.punchangle) * f;
678 self.punchangle = '0 0 0';
681 if (self.punchvector != '0 0 0')
683 f = vlen(self.punchvector) - 30 * frametime;
685 self.punchvector = normalize(self.punchvector) * f;
687 self.punchvector = '0 0 0';
690 if (clienttype(self) == CLIENTTYPE_BOT)
692 if(playerdemo_read())
697 self.items &~= IT_USING_JETPACK;
699 if(self.classname == "player")
701 if(self.race_penalty)
702 if(time > self.race_penalty)
703 self.race_penalty = 0;
705 not_allowed_to_move = 0;
706 if(self.race_penalty)
707 not_allowed_to_move = 1;
708 if(!cvar("sv_ready_restart_after_countdown"))
709 if(time < game_starttime)
710 not_allowed_to_move = 1;
712 if(not_allowed_to_move)
714 self.velocity = '0 0 0';
715 self.movetype = MOVETYPE_NONE;
716 self.disableclientprediction = 2;
718 else if(self.disableclientprediction == 2)
720 if(self.movetype == MOVETYPE_NONE)
721 self.movetype = MOVETYPE_WALK;
722 self.disableclientprediction = 0;
726 if (self.movetype == MOVETYPE_NONE)
733 if(self.runes & RUNE_SPEED)
735 if(self.runes & CURSE_SLOW)
736 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
738 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
740 else if(self.runes & CURSE_SLOW)
742 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
746 if(g_minstagib && (self.items & IT_INVINCIBLE))
748 maxspd_mod = cvar("g_minstagib_speed_moverate");
751 if(g_nexball && self.ballcarried)
753 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
758 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
761 if(self.classname != "player")
763 maxspd_mod = cvar("sv_spectator_speed_multiplier");
764 if(!self.spectatorspeed)
765 self.spectatorspeed = maxspd_mod;
766 if(self.impulse && self.impulse <= 19)
768 if(self.lastclassname != "player")
770 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
771 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
772 else if(self.impulse == 11)
773 self.spectatorspeed = maxspd_mod;
774 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
775 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
776 else if(self.impulse >= 1 && self.impulse <= 9)
777 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
778 } // otherwise just clear
781 maxspd_mod = self.spectatorspeed;
784 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
785 if(self.speed != spd)
789 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
790 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
791 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
792 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
795 maxspd_mod *= swampspd_mod; // only one common speed modder please!
798 // if dead, behave differently
802 if (!self.fixangle && !g_bugrigs)
805 self.angles_y = self.v_angle_y;
809 if(self.flags & FL_ONGROUND)
814 if(self.waterlevel < WATERLEVEL_SWIMMING)
815 if(time >= self.ladder_time)
818 self.nextstep = time + 0.3 + random() * 0.1;
819 trace_dphitq3surfaceflags = 0;
820 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
821 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
823 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
824 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
826 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
834 if(self.classname == "player")
838 self.flags &~= FL_ONGROUND;
839 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 1', MOVE_NORMAL, self);
840 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
841 self.flags |= FL_ONGROUND;
844 if (self.BUTTON_JUMP)
847 self.flags |= FL_JUMPRELEASED;
849 if (self.waterlevel == WATERLEVEL_SWIMMING)
853 if (self.flags & FL_WATERJUMP )
855 self.velocity_x = self.movedir_x;
856 self.velocity_y = self.movedir_y;
857 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
859 self.flags &~= FL_WATERJUMP;
860 self.teleport_time = 0;
863 else if (g_bugrigs && self.classname == "player")
867 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
869 // noclipping or flying
870 self.flags &~= FL_ONGROUND;
872 self.velocity = self.velocity * (1 - frametime * sv_friction);
873 makevectors(self.v_angle);
874 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
875 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
877 wishdir = normalize(wishvel);
878 wishspeed = vlen(wishvel);
879 if (wishspeed > sv_maxspeed*maxspd_mod)
880 wishspeed = sv_maxspeed*maxspd_mod;
881 if (time >= self.teleport_time)
882 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
884 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
887 self.flags &~= FL_ONGROUND;
889 makevectors(self.v_angle);
890 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
891 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
892 if (wishvel == '0 0 0')
893 wishvel = '0 0 -60'; // drift towards bottom
895 wishdir = normalize(wishvel);
896 wishspeed = vlen(wishvel);
897 if (wishspeed > sv_maxspeed*maxspd_mod)
898 wishspeed = sv_maxspeed*maxspd_mod;
899 wishspeed = wishspeed * 0.7;
902 self.velocity = self.velocity * (1 - frametime * sv_friction);
904 // water acceleration
905 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
907 else if (time < self.ladder_time)
909 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
910 self.flags &~= FL_ONGROUND;
912 self.velocity = self.velocity * (1 - frametime * sv_friction);
913 makevectors(self.v_angle);
914 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
915 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
917 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
919 self.velocity_z = self.velocity_z + sv_gravity * frametime;
920 if (self.ladder_entity.classname == "func_water")
923 if (f > self.ladder_entity.speed)
924 wishvel = wishvel * (self.ladder_entity.speed / f);
926 self.watertype = self.ladder_entity.skin;
927 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
928 if ((self.origin_z + self.view_ofs_z) < f)
929 self.waterlevel = WATERLEVEL_SUBMERGED;
930 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
931 self.waterlevel = WATERLEVEL_SWIMMING;
932 else if ((self.origin_z + self.mins_z + 1) < f)
933 self.waterlevel = WATERLEVEL_WETFEET;
936 self.waterlevel = WATERLEVEL_NONE;
937 self.watertype = CONTENT_EMPTY;
941 wishdir = normalize(wishvel);
942 wishspeed = vlen(wishvel);
943 if (wishspeed > sv_maxspeed*maxspd_mod)
944 wishspeed = sv_maxspeed*maxspd_mod;
945 if (time >= self.teleport_time)
947 // water acceleration
948 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
951 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
953 //makevectors(self.v_angle_y * '0 1 0');
954 makevectors(self.v_angle);
955 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
956 // add remaining speed as Z component
957 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
959 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
960 // add the unused velocity as up component
963 // if(self.BUTTON_JUMP)
964 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
966 // it is now normalized, so...
967 float a_side, a_up, a_add, a_diff;
968 a_side = cvar("g_jetpack_acceleration_side");
969 a_up = cvar("g_jetpack_acceleration_up");
970 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
979 //////////////////////////////////////////////////////////////////////////////////////
980 // finding the maximum over all vectors of above form
981 // with wishvel having an absolute value of 1
982 //////////////////////////////////////////////////////////////////////////////////////
983 // we're finding the maximum over
984 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
985 // for z in the range from -1 to 1
986 //////////////////////////////////////////////////////////////////////////////////////
987 // maximum is EITHER attained at the single extreme point:
988 a_diff = a_side * a_side - a_up * a_up;
991 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
992 if(f > -1 && f < 1) // can it be attained?
994 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
998 // OR attained at z = 1:
999 f = (a_up + a_add) * (a_up + a_add);
1005 // OR attained at z = -1:
1006 f = (a_up - a_add) * (a_up - a_add);
1010 //print("bottom\n");
1013 //////////////////////////////////////////////////////////////////////////////////////
1015 //print("best possible acceleration: ", ftos(best), "\n");
1018 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
1019 if(wishvel_z - sv_gravity > 0)
1020 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1022 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1025 fvel = vlen(wishvel);
1028 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
1030 fvel = min(1, vlen(wishvel) / best);
1031 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1032 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
1036 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1038 if (f > 0 && wishvel != '0 0 0')
1040 self.velocity = self.velocity + wishvel * f * frametime;
1041 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1042 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
1043 self.flags &~= FL_ONGROUND;
1044 self.items |= IT_USING_JETPACK;
1046 // jetpack also inhibits health regeneration, but only for 1 second
1047 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1050 else if (self.flags & FL_ONGROUND)
1052 // we get here if we ran out of ammo
1053 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1054 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1057 makevectors(self.v_angle_y * '0 1 0');
1058 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1060 if(!(self.lastflags & FL_ONGROUND))
1062 if(cvar("speedmeter"))
1063 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1064 if(self.lastground < time - 0.3)
1065 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1066 if(self.jumppadcount > 1)
1067 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1068 self.jumppadcount = 0;
1071 #ifdef LETS_TEST_FTEQCC
1072 if(self.velocity_x || self.velocity_y)
1090 if (f < sv_stopspeed)
1091 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
1093 f = 1 - frametime * sv_friction;
1095 self.velocity = self.velocity * f;
1097 self.velocity = '0 0 0';
1101 wishdir = normalize(wishvel);
1102 wishspeed = vlen(wishvel);
1103 if (wishspeed > sv_maxspeed*maxspd_mod)
1104 wishspeed = sv_maxspeed*maxspd_mod;
1106 wishspeed = wishspeed * 0.5;
1107 if (time >= self.teleport_time)
1108 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
1113 // we get here if we ran out of ammo
1114 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1115 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1119 maxairspd = sv_maxairspeed*maxspd_mod;
1120 airaccel = sv_airaccelerate*maxspd_mod;
1124 maxairspd = sv_maxairspeed;
1125 airaccel = sv_airaccelerate;
1128 makevectors(self.v_angle_y * '0 1 0');
1129 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1131 wishdir = normalize(wishvel);
1132 wishspeed = wishspeed0 = vlen(wishvel);
1133 if (wishspeed0 > sv_maxspeed*maxspd_mod)
1134 wishspeed0 = sv_maxspeed*maxspd_mod;
1135 if (wishspeed > maxairspd)
1136 wishspeed = maxairspd;
1138 wishspeed = wishspeed * 0.5;
1139 if (time >= self.teleport_time)
1145 airaccelqw = sv_airaccel_qw;
1146 accelerating = (self.velocity * wishdir > 0);
1147 wishspeed2 = wishspeed;
1150 if(sv_airstopaccelerate)
1151 if(self.velocity * wishdir < 0)
1152 airaccel = sv_airstopaccelerate*maxspd_mod;
1153 // this doesn't play well with analog input, but can't r
1154 // fixed like the AirControl can. So, don't set the maxa
1155 // cvars when you want to support analog input.
1156 if(self.movement_x == 0 && self.movement_y != 0)
1158 if(sv_maxairstrafespeed)
1160 wishspeed = min(wishspeed, sv_maxairstrafespeed*maxspd_mod);
1161 if(sv_maxairstrafespeed < sv_maxairspeed)
1164 if(sv_airstrafeaccelerate)
1166 airaccel = sv_airstrafeaccelerate*maxspd_mod;
1167 if(sv_airstrafeaccelerate > sv_airaccelerate)
1173 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1174 PM_AirAccelerate(wishdir, wishspeed);
1176 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd);
1179 CPM_PM_Aircontrol(wishdir, wishspeed2);
1183 if((g_cts || g_race) && self.classname != "observer") {
1184 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1185 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1186 speedaward_holder = self.netname;
1187 speedaward_lastupdate = time;
1189 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1195 race_send_speedaward(MSG_ALL);
1196 speedaward_lastsent = speedaward_speed;
1197 if (speedaward_speed > speedaward_alltimebest) {
1198 speedaward_alltimebest = speedaward_speed;
1199 speedaward_alltimebest_holder = speedaward_holder;
1200 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1201 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"), speedaward_alltimebest_holder);
1202 race_send_speedaward_alltimebest(MSG_ALL);
1207 if(self.flags & FL_ONGROUND)
1208 self.lastground = time;
1210 self.lastflags = self.flags;
1211 self.lastclassname = self.classname;