7 float sv_airaccelerate;
11 float sv_airaccel_sideways_friction;
13 float sv_airstopaccelerate;
14 float sv_airstrafeaccelerate;
15 float sv_maxairstrafespeed;
17 float sv_warsowbunny_airforwardaccel;
18 float sv_warsowbunny_accel;
19 float sv_warsowbunny_topspeed;
20 float sv_warsowbunny_turnaccel;
21 float sv_warsowbunny_backtosideratio;
24 .entity ladder_entity;
26 .float swamp_slowdown;
30 .float spectatorspeed;
36 When you press the jump key
39 void PlayerJump (void)
43 mjumpheight = cvar("sv_jumpvelocity");
44 if (self.waterlevel >= WATERLEVEL_SWIMMING)
46 if (self.watertype == CONTENT_WATER)
47 self.velocity_z = 200;
48 else if (self.watertype == CONTENT_SLIME)
56 if (!(self.flags & FL_ONGROUND))
60 if (!(self.flags & FL_JUMPRELEASED))
63 if(self.health <= g_bloodloss)
68 if(self.runes & RUNE_SPEED)
70 if(self.runes & CURSE_SLOW)
71 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
73 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
75 else if(self.runes & CURSE_SLOW)
77 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
81 if(g_minstagib && (self.items & IT_INVINCIBLE))
83 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
86 if(cvar_string("sv_jumpspeedcap_min") != "")
87 self.velocity_z = max(cvar("sv_jumpvelocity") * cvar("sv_jumpspeedcap_min"), self.velocity_z);
88 if(cvar_string("sv_jumpspeedcap_max") != "")
89 self.velocity_z = min(cvar("sv_jumpvelocity") * cvar("sv_jumpspeedcap_max"), self.velocity_z);
91 if(!(self.lastflags & FL_ONGROUND))
93 if(cvar("speedmeter"))
94 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
95 if(self.lastground < time - 0.3)
97 self.velocity_x *= (1 - cvar("sv_friction_on_land"));
98 self.velocity_y *= (1 - cvar("sv_friction_on_land"));
100 if(self.jumppadcount > 1)
101 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
102 self.jumppadcount = 0;
105 self.velocity_z = self.velocity_z + mjumpheight;
106 self.oldvelocity_z = self.velocity_z;
108 self.flags &~= FL_ONGROUND;
109 self.flags &~= FL_JUMPRELEASED;
112 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
114 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
117 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
119 self.restart_jump = -1; // restart jump anim next time
120 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
123 void CheckWaterJump()
125 local vector start, end;
127 // check for a jump-out-of-water
128 makevectors (self.angles);
130 start_z = start_z + 8;
132 normalize(v_forward);
133 end = start + v_forward*24;
134 traceline (start, end, TRUE, self);
135 if (trace_fraction < 1)
137 start_z = start_z + self.maxs_z - 8;
138 end = start + v_forward*24;
139 self.movedir = trace_plane_normal * -50;
140 traceline (start, end, TRUE, self);
141 if (trace_fraction == 1)
142 { // open at eye level
143 self.flags |= FL_WATERJUMP;
144 self.velocity_z = 225;
145 self.flags &~= FL_JUMPRELEASED;
146 self.teleport_time = time + 2; // safety net
152 float racecar_angle(float forward, float down)
154 float ret, angle_mult;
162 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
164 angle_mult = forward / (800 + forward);
167 return ret * angle_mult + 360 * (1 - angle_mult);
169 return ret * angle_mult;
172 void RaceCarPhysics()
174 // using this move type for "big rigs"
175 // the engine does not push the entity!
177 float accel, steer, f;
178 vector angles_save, rigvel;
180 angles_save = self.angles;
181 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
182 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
184 if(g_bugrigs_reverse_speeding)
188 // back accel is DIGITAL
189 // to prevent speedhack
199 makevectors(self.angles); // new forward direction!
201 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
203 float myspeed, upspeed, steerfactor, accelfactor;
205 myspeed = self.velocity * v_forward;
206 upspeed = self.velocity * v_up;
208 // responsiveness factor for steering and acceleration
209 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
210 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
212 if(myspeed < 0 && g_bugrigs_reverse_spinning)
213 steerfactor = -myspeed * g_bugrigs_steer;
215 steerfactor = -myspeed * f * g_bugrigs_steer;
217 if(myspeed < 0 && g_bugrigs_reverse_speeding)
218 accelfactor = g_bugrigs_accel;
220 accelfactor = f * g_bugrigs_accel;
221 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
227 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
231 if(!g_bugrigs_reverse_speeding)
232 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
239 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
243 if(g_bugrigs_reverse_stopping)
246 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
249 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
250 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
252 self.angles_y += steer * frametime * steerfactor; // apply steering
253 makevectors(self.angles); // new forward direction!
255 myspeed += accel * accelfactor * frametime;
257 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
261 myspeed = vlen(self.velocity);
263 // responsiveness factor for steering and acceleration
264 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
265 steerfactor = -myspeed * f;
266 self.angles_y += steer * frametime * steerfactor; // apply steering
268 rigvel = self.velocity;
269 makevectors(self.angles); // new forward direction!
272 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
273 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
274 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
275 //MAXIMA: solve(total_acceleration(v) = 0, v);
277 if(g_bugrigs_planar_movement)
279 vector rigvel_xy, neworigin, up;
282 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
286 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
289 mt = MOVE_NOMONSTERS;
291 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
292 up = trace_endpos - self.origin;
294 // BUG RIGS: align the move to the surface instead of doing collision testing
296 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
299 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
301 if(trace_fraction < 0.5)
304 neworigin = self.origin;
307 neworigin = trace_endpos;
309 if(trace_fraction < 1)
311 // now set angles_x so that the car points parallel to the surface
312 self.angles = vectoangles(
313 '1 0 0' * v_forward_x * trace_plane_normal_z
315 '0 1 0' * v_forward_y * trace_plane_normal_z
317 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
319 self.flags |= FL_ONGROUND;
323 // now set angles_x so that the car points forward, but is tilted in velocity direction
324 self.flags &~= FL_ONGROUND;
327 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
328 self.movetype = MOVETYPE_NOCLIP;
332 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
333 self.velocity = rigvel;
334 self.movetype = MOVETYPE_FLY;
338 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
339 if(trace_fraction != 1)
341 self.angles = vectoangles2(
342 '1 0 0' * v_forward_x * trace_plane_normal_z
344 '0 1 0' * v_forward_y * trace_plane_normal_z
346 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
354 vel_local_x = v_forward * self.velocity;
355 vel_local_y = v_right * self.velocity;
356 vel_local_z = v_up * self.velocity;
358 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
359 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
363 vector vf1, vu1, smoothangles;
364 makevectors(self.angles);
365 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
370 makevectors(angles_save);
371 vf1 = vf1 + v_forward * (1 - f);
372 vu1 = vu1 + v_up * (1 - f);
373 smoothangles = vectoangles2(vf1, vu1);
374 self.angles_x = -smoothangles_x;
375 self.angles_z = smoothangles_z;
378 float IsMoveInDirection(vector mv, float angle) // key mix factor
380 if(mv_x == 0 && mv_y == 0)
381 return 0; // avoid division by zero
382 angle = RAD2DEG * atan2(mv_y, mv_x);
383 angle = remainder(angle, 360) / 45;
388 return 1 - fabs(angle);
391 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
393 float zspeed, xyspeed, dot, k;
396 // this doesn't play well with analog input
397 if(self.movement_x == 0 || self.movement_y != 0)
398 return; // can't control movement if not moving forward or backward
401 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
406 k *= bound(0, wishspeed / sv_maxairspeed, 1);
408 zspeed = self.velocity_z;
410 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
412 dot = self.velocity * wishdir;
413 k *= sv_aircontrol*dot*dot*frametime;
415 if(dot > 0) // we can't change direction while slowing down
417 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
420 self.velocity = self.velocity * xyspeed;
421 self.velocity_z = zspeed;
424 // example config for alternate speed clamping:
425 // sv_airaccel_qw 0.8
426 // sv_airaccel_sideways_friction 0
427 // prvm_globalset server speedclamp_mode 1
429 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float sidefric)
437 float vel_xy_current;
438 float vel_xy_backward, vel_xy_forward;
441 speedclamp = (accelqw < 0);
445 if(cvar("sv_gameplayfix_q2airaccelerate"))
446 wishspeed0 = wishspeed;
448 vel_straight = self.velocity * wishdir;
449 vel_z = self.velocity_z;
450 vel_xy = self.velocity - vel_z * '0 0 1';
451 vel_perpend = vel_xy - vel_straight * wishdir;
453 step = accel * frametime * wishspeed0;
455 vel_xy_current = vlen(vel_xy);
456 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
457 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
458 if(vel_xy_backward < 0)
459 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
461 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
463 if(sidefric < 0 && (vel_perpend*vel_perpend))
464 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
467 f = (1 - frametime * wishspeed * sidefric);
468 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
470 vel_perpend = vel_perpend * f;
473 fminimum = sqrt(fminimum);
474 vel_perpend = vel_perpend * bound(fminimum, f, 1);
478 vel_perpend = vel_perpend * (1 - frametime * wishspeed * sidefric);
480 vel_xy = vel_straight * wishdir + vel_perpend;
484 // ensure we don't get too fast or decelerate faster than we should
485 vel_xy_current = min(vlen(vel_xy), vel_xy_forward);
486 if(vel_xy_current > 0) // prevent division by zero
487 vel_xy = normalize(vel_xy) * vel_xy_current;
490 self.velocity = vel_xy + vel_z * '0 0 1';
493 void PM_AirAccelerate(vector wishdir, float wishspeed)
495 vector curvel, wishvel, acceldir, curdir;
496 float addspeed, accelspeed, curspeed, f;
502 curvel = self.velocity;
504 curspeed = vlen(curvel);
506 if(wishspeed > curspeed * 1.01)
508 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
512 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
513 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
515 wishvel = wishdir * wishspeed;
516 acceldir = wishvel - curvel;
517 addspeed = vlen(acceldir);
518 acceldir = normalize(acceldir);
520 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
522 if(sv_warsowbunny_backtosideratio < 1)
524 curdir = normalize(curvel);
525 dot = acceldir * curdir;
527 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
530 self.velocity += accelspeed * acceldir;
533 .vector movement_old;
536 .string lastclassname;
538 void Nixnex_GiveCurrentWeapon();
539 .float() PlayerPhysplug;
541 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
542 .float specialcommand_pos;
543 void SpecialCommand()
548 if(!CheatImpulse(99))
549 print("A hollow voice says \"Plugh\".\n");
553 float speedaward_speed;
554 string speedaward_holder;
555 void race_send_speedaward(float msg)
557 // send the best speed of the round
558 WriteByte(msg, SVC_TEMPENTITY);
559 WriteByte(msg, TE_CSQC_RACE);
560 WriteByte(msg, RACE_NET_SPEED_AWARD);
561 WriteInt24_t(msg, floor(speedaward_speed+0.5));
562 WriteString(msg, speedaward_holder);
565 float speedaward_alltimebest;
566 string speedaward_alltimebest_holder;
567 void race_send_speedaward_alltimebest(float msg)
569 // send the best speed
570 WriteByte(msg, SVC_TEMPENTITY);
571 WriteByte(msg, TE_CSQC_RACE);
572 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
573 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
574 WriteString(msg, speedaward_alltimebest_holder);
577 string GetMapname(void);
578 float speedaward_lastupdate;
579 float speedaward_lastsent;
580 void SV_PlayerPhysics()
582 local vector wishvel, wishdir, v;
583 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
586 float not_allowed_to_move;
589 if(self.PlayerPhysplug)
590 if(self.PlayerPhysplug())
593 self.race_movetime_frac += frametime;
594 f = floor(self.race_movetime_frac);
595 self.race_movetime_frac -= f;
596 self.race_movetime_count += f;
597 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
601 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);
605 else if(buttons == 1)
607 else if(buttons == 2)
609 else if(buttons == 128)
611 else if(buttons == 256)
613 else if(buttons == 512)
615 else if(buttons == 1024)
620 if(c == substring(specialcommand, self.specialcommand_pos, 1))
622 self.specialcommand_pos += 1;
623 if(self.specialcommand_pos >= strlen(specialcommand))
625 self.specialcommand_pos = 0;
630 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
631 self.specialcommand_pos = 0;
633 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
635 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
636 self.parm_idlesince = time;
638 buttons_prev = self.buttons_old;
639 self.buttons_old = buttons;
640 self.movement_old = self.movement;
641 self.v_angle_old = self.v_angle;
643 if(time < self.nickspamtime)
644 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
646 // slight annoyance for nick change scripts
647 self.movement = -1 * self.movement;
648 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
650 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!
652 self.angles_x = random() * 360;
653 self.angles_y = random() * 360;
654 // at least I'm not forcing retardedview by also assigning to angles_z
659 if (self.punchangle != '0 0 0')
661 f = vlen(self.punchangle) - 10 * frametime;
663 self.punchangle = normalize(self.punchangle) * f;
665 self.punchangle = '0 0 0';
668 if (self.punchvector != '0 0 0')
670 f = vlen(self.punchvector) - 30 * frametime;
672 self.punchvector = normalize(self.punchvector) * f;
674 self.punchvector = '0 0 0';
677 if (clienttype(self) == CLIENTTYPE_BOT)
679 if(playerdemo_read())
684 self.items &~= IT_USING_JETPACK;
686 if(self.classname == "player")
688 if(self.race_penalty)
689 if(time > self.race_penalty)
690 self.race_penalty = 0;
692 not_allowed_to_move = 0;
693 if(self.race_penalty)
694 not_allowed_to_move = 1;
695 if(!cvar("sv_ready_restart_after_countdown"))
696 if(time < game_starttime)
697 not_allowed_to_move = 1;
699 if(not_allowed_to_move)
701 self.velocity = '0 0 0';
702 self.movetype = MOVETYPE_NONE;
703 self.disableclientprediction = 2;
705 else if(self.disableclientprediction == 2)
707 if(self.movetype == MOVETYPE_NONE)
708 self.movetype = MOVETYPE_WALK;
709 self.disableclientprediction = 0;
713 if (self.movetype == MOVETYPE_NONE)
720 if(self.runes & RUNE_SPEED)
722 if(self.runes & CURSE_SLOW)
723 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
725 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
727 else if(self.runes & CURSE_SLOW)
729 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
733 if(g_minstagib && (self.items & IT_INVINCIBLE))
735 maxspd_mod = cvar("g_minstagib_speed_moverate");
738 if(g_nexball && self.ballcarried)
740 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
745 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
748 if(self.classname != "player")
750 maxspd_mod = cvar("sv_spectator_speed_multiplier");
751 if(!self.spectatorspeed)
752 self.spectatorspeed = maxspd_mod;
753 if(self.impulse && self.impulse <= 19)
755 if(self.lastclassname != "player")
757 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
758 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
759 else if(self.impulse == 11)
760 self.spectatorspeed = maxspd_mod;
761 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
762 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
763 else if(self.impulse >= 1 && self.impulse <= 9)
764 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
765 } // otherwise just clear
768 maxspd_mod = self.spectatorspeed;
771 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
772 if(self.speed != spd)
776 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
777 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
778 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
779 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
782 maxspd_mod *= swampspd_mod; // only one common speed modder please!
785 // if dead, behave differently
789 if (!self.fixangle && !g_bugrigs)
792 self.angles_y = self.v_angle_y;
796 if(self.flags & FL_ONGROUND)
801 if(self.waterlevel < WATERLEVEL_SWIMMING)
802 if(time >= self.ladder_time)
805 self.nextstep = time + 0.3 + random() * 0.1;
806 trace_dphitq3surfaceflags = 0;
807 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
808 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
810 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
811 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
813 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
821 if(self.classname == "player")
825 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
826 if(trace_fraction < 1 && trace_plane_normal_z < 0.98 && cvar("sv_doublejump_disable_on_ramps")) {
827 // don't do doublejumps on ramps to preserve old nexuiz ramjump style
828 // print("Trace plane normal z: ", ftos(trace_plane_normal_z), ", disabling dj!\n");
830 else { // perform doublejump
831 self.flags &~= FL_ONGROUND;
832 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
833 self.flags |= FL_ONGROUND;
837 if (self.BUTTON_JUMP)
840 self.flags |= FL_JUMPRELEASED;
842 if (self.waterlevel == WATERLEVEL_SWIMMING)
846 if (self.flags & FL_WATERJUMP )
848 self.velocity_x = self.movedir_x;
849 self.velocity_y = self.movedir_y;
850 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
852 self.flags &~= FL_WATERJUMP;
853 self.teleport_time = 0;
856 else if (g_bugrigs && self.classname == "player")
860 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
862 // noclipping or flying
863 self.flags &~= FL_ONGROUND;
865 self.velocity = self.velocity * (1 - frametime * sv_friction);
866 makevectors(self.v_angle);
867 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
868 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
870 wishdir = normalize(wishvel);
871 wishspeed = vlen(wishvel);
872 if (wishspeed > sv_maxspeed*maxspd_mod)
873 wishspeed = sv_maxspeed*maxspd_mod;
874 if (time >= self.teleport_time)
875 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
877 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
880 self.flags &~= FL_ONGROUND;
882 makevectors(self.v_angle);
883 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
884 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
885 if (wishvel == '0 0 0')
886 wishvel = '0 0 -60'; // drift towards bottom
888 wishdir = normalize(wishvel);
889 wishspeed = vlen(wishvel);
890 if (wishspeed > sv_maxspeed*maxspd_mod)
891 wishspeed = sv_maxspeed*maxspd_mod;
892 wishspeed = wishspeed * 0.7;
895 self.velocity = self.velocity * (1 - frametime * sv_friction);
897 // water acceleration
898 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
900 else if (time < self.ladder_time)
902 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
903 self.flags &~= FL_ONGROUND;
905 self.velocity = self.velocity * (1 - frametime * sv_friction);
906 makevectors(self.v_angle);
907 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
908 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
910 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
912 self.velocity_z = self.velocity_z + sv_gravity * frametime;
913 if (self.ladder_entity.classname == "func_water")
916 if (f > self.ladder_entity.speed)
917 wishvel = wishvel * (self.ladder_entity.speed / f);
919 self.watertype = self.ladder_entity.skin;
920 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
921 if ((self.origin_z + self.view_ofs_z) < f)
922 self.waterlevel = WATERLEVEL_SUBMERGED;
923 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
924 self.waterlevel = WATERLEVEL_SWIMMING;
925 else if ((self.origin_z + self.mins_z + 1) < f)
926 self.waterlevel = WATERLEVEL_WETFEET;
929 self.waterlevel = WATERLEVEL_NONE;
930 self.watertype = CONTENT_EMPTY;
934 wishdir = normalize(wishvel);
935 wishspeed = vlen(wishvel);
936 if (wishspeed > sv_maxspeed*maxspd_mod)
937 wishspeed = sv_maxspeed*maxspd_mod;
938 if (time >= self.teleport_time)
940 // water acceleration
941 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
944 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
946 //makevectors(self.v_angle_y * '0 1 0');
947 makevectors(self.v_angle);
948 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
949 // add remaining speed as Z component
950 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
952 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
953 // add the unused velocity as up component
956 // if(self.BUTTON_JUMP)
957 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
959 // it is now normalized, so...
960 float a_side, a_up, a_add, a_diff;
961 a_side = cvar("g_jetpack_acceleration_side");
962 a_up = cvar("g_jetpack_acceleration_up");
963 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
972 //////////////////////////////////////////////////////////////////////////////////////
973 // finding the maximum over all vectors of above form
974 // with wishvel having an absolute value of 1
975 //////////////////////////////////////////////////////////////////////////////////////
976 // we're finding the maximum over
977 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
978 // for z in the range from -1 to 1
979 //////////////////////////////////////////////////////////////////////////////////////
980 // maximum is EITHER attained at the single extreme point:
981 a_diff = a_side * a_side - a_up * a_up;
984 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
985 if(f > -1 && f < 1) // can it be attained?
987 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
991 // OR attained at z = 1:
992 f = (a_up + a_add) * (a_up + a_add);
998 // OR attained at z = -1:
999 f = (a_up - a_add) * (a_up - a_add);
1003 //print("bottom\n");
1006 //////////////////////////////////////////////////////////////////////////////////////
1008 //print("best possible acceleration: ", ftos(best), "\n");
1011 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
1012 if(wishvel_z - sv_gravity > 0)
1013 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1015 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1018 fvel = vlen(wishvel);
1021 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
1023 fvel = min(1, vlen(wishvel) / best);
1024 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1025 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
1029 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1031 if (f > 0 && wishvel != '0 0 0')
1033 self.velocity = self.velocity + wishvel * f * frametime;
1034 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1035 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
1036 self.flags &~= FL_ONGROUND;
1037 self.items |= IT_USING_JETPACK;
1039 // jetpack also inhibits health regeneration, but only for 1 second
1040 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1043 else if (self.flags & FL_ONGROUND)
1045 // we get here if we ran out of ammo
1046 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1047 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1050 makevectors(self.v_angle_y * '0 1 0');
1051 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1053 if(!(self.lastflags & FL_ONGROUND))
1055 if(cvar("speedmeter"))
1056 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1057 if(self.lastground < time - 0.3)
1058 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1059 if(self.jumppadcount > 1)
1060 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1061 self.jumppadcount = 0;
1064 #ifdef LETS_TEST_FTEQCC
1065 if(self.velocity_x || self.velocity_y)
1083 if (f < sv_stopspeed)
1084 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
1086 f = 1 - frametime * sv_friction;
1088 self.velocity = self.velocity * f;
1090 self.velocity = '0 0 0';
1094 wishdir = normalize(wishvel);
1095 wishspeed = vlen(wishvel);
1096 if (wishspeed > sv_maxspeed*maxspd_mod)
1097 wishspeed = sv_maxspeed*maxspd_mod;
1099 wishspeed = wishspeed * 0.5;
1100 if (time >= self.teleport_time)
1101 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
1106 // we get here if we ran out of ammo
1107 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1108 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1112 maxairspd = sv_maxairspeed*maxspd_mod;
1113 airaccel = sv_airaccelerate*maxspd_mod;
1117 maxairspd = sv_maxairspeed;
1118 airaccel = sv_airaccelerate;
1121 makevectors(self.v_angle_y * '0 1 0');
1122 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1124 wishdir = normalize(wishvel);
1125 wishspeed = wishspeed0 = vlen(wishvel);
1126 if (wishspeed0 > sv_maxspeed*maxspd_mod)
1127 wishspeed0 = sv_maxspeed*maxspd_mod;
1128 if (wishspeed > maxairspd)
1129 wishspeed = maxairspd;
1131 wishspeed = wishspeed * 0.5;
1132 if (time >= self.teleport_time)
1138 airaccelqw = sv_airaccel_qw;
1139 accelerating = (self.velocity * wishdir > 0);
1140 wishspeed2 = wishspeed;
1143 if(sv_airstopaccelerate)
1144 if(self.velocity * wishdir < 0)
1145 airaccel = sv_airstopaccelerate*maxspd_mod;
1146 // this doesn't play well with analog input, but can't r
1147 // fixed like the AirControl can. So, don't set the maxa
1148 // cvars when you want to support analog input.
1149 if(self.movement_x == 0 && self.movement_y != 0)
1151 if(sv_maxairstrafespeed)
1153 wishspeed = min(wishspeed, sv_maxairstrafespeed*maxspd_mod);
1154 if(sv_maxairstrafespeed < sv_maxairspeed)
1157 if(sv_airstrafeaccelerate)
1159 airaccel = sv_airstrafeaccelerate*maxspd_mod;
1160 if(sv_airstrafeaccelerate > sv_airaccelerate)
1166 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1167 PM_AirAccelerate(wishdir, wishspeed);
1169 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd);
1172 CPM_PM_Aircontrol(wishdir, wishspeed2);
1176 if((g_cts || g_race) && self.classname != "observer") {
1177 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1178 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1179 speedaward_holder = self.netname;
1180 speedaward_lastupdate = time;
1182 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1188 race_send_speedaward(MSG_ALL);
1189 speedaward_lastsent = speedaward_speed;
1190 if (speedaward_speed > speedaward_alltimebest) {
1191 speedaward_alltimebest = speedaward_speed;
1192 speedaward_alltimebest_holder = speedaward_holder;
1193 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1194 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"), speedaward_alltimebest_holder);
1195 race_send_speedaward_alltimebest(MSG_ALL);
1200 if(self.flags & FL_ONGROUND)
1201 self.lastground = time;
1203 self.lastflags = self.flags;
1204 self.lastclassname = self.classname;