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;
39 When you press the jump key
42 void PlayerJump (void)
46 mjumpheight = cvar("sv_jumpvelocity");
47 if (self.waterlevel >= WATERLEVEL_SWIMMING)
49 if (self.watertype == CONTENT_WATER)
50 self.velocity_z = 200;
51 else if (self.watertype == CONTENT_SLIME)
59 if (!(self.flags & FL_ONGROUND))
63 if (!(self.flags & FL_JUMPRELEASED))
66 if(self.health <= g_bloodloss)
70 if(time < self.doublejump_nextjumptime || !self.wasinair)
75 if(self.runes & RUNE_SPEED)
77 if(self.runes & CURSE_SLOW)
78 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
80 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
82 else if(self.runes & CURSE_SLOW)
84 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
88 if(g_minstagib && (self.items & IT_INVINCIBLE))
90 mjumpheight = mjumpheight * cvar("g_minstagib_speed_jumpheight");
93 if(cvar_string("sv_jumpspeedcap_min") != "")
94 self.velocity_z = max(cvar("sv_jumpvelocity") * cvar("sv_jumpspeedcap_min"), self.velocity_z);
95 if(cvar_string("sv_jumpspeedcap_max") != "")
96 self.velocity_z = min(cvar("sv_jumpvelocity") * cvar("sv_jumpspeedcap_max"), self.velocity_z);
98 if(!(self.lastflags & FL_ONGROUND))
100 if(cvar("speedmeter"))
101 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
102 if(self.lastground < time - 0.3)
104 self.velocity_x *= (1 - cvar("sv_friction_on_land"));
105 self.velocity_y *= (1 - cvar("sv_friction_on_land"));
107 if(self.jumppadcount > 1)
108 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
109 self.jumppadcount = 0;
112 self.velocity_z = self.velocity_z + mjumpheight;
113 self.oldvelocity_z = self.velocity_z;
115 self.flags &~= FL_ONGROUND;
116 self.flags &~= FL_JUMPRELEASED;
119 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
121 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
124 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
128 // we're moving upwards at self.velocity_z
129 // only allow jumping after we got 2 units upwards
130 // so we for sure leave the FL_ONGROUND check
132 // but as this sucks because of factoring in gravity, we'll just do it
133 // for 3 units, and constant velocity
134 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
136 self.doublejump_nextjumptime = time + 3 / max(30, self.velocity_z); // max 0.1s blocking of jumps, typically just one frame
137 //print(sprintf("blocking jumps for next %f seconds (vel: %f to %f)\n", self.doublejump_nextjumptime - time, self.velocity_z - mjumpheight, self.velocity_z));
141 self.restart_jump = -1; // restart jump anim next time
142 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
145 void CheckWaterJump()
147 local vector start, end;
149 // check for a jump-out-of-water
150 makevectors (self.angles);
152 start_z = start_z + 8;
154 normalize(v_forward);
155 end = start + v_forward*24;
156 traceline (start, end, TRUE, self);
157 if (trace_fraction < 1)
159 start_z = start_z + self.maxs_z - 8;
160 end = start + v_forward*24;
161 self.movedir = trace_plane_normal * -50;
162 traceline (start, end, TRUE, self);
163 if (trace_fraction == 1)
164 { // open at eye level
165 self.flags |= FL_WATERJUMP;
166 self.velocity_z = 225;
167 self.flags &~= FL_JUMPRELEASED;
168 self.teleport_time = time + 2; // safety net
174 float racecar_angle(float forward, float down)
176 float ret, angle_mult;
184 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
186 angle_mult = forward / (800 + forward);
189 return ret * angle_mult + 360 * (1 - angle_mult);
191 return ret * angle_mult;
194 void RaceCarPhysics()
196 // using this move type for "big rigs"
197 // the engine does not push the entity!
199 float accel, steer, f;
200 vector angles_save, rigvel;
202 angles_save = self.angles;
203 accel = bound(-1, self.movement_x / sv_maxspeed, 1);
204 steer = bound(-1, self.movement_y / sv_maxspeed, 1);
206 if(g_bugrigs_reverse_speeding)
210 // back accel is DIGITAL
211 // to prevent speedhack
221 makevectors(self.angles); // new forward direction!
223 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
225 float myspeed, upspeed, steerfactor, accelfactor;
227 myspeed = self.velocity * v_forward;
228 upspeed = self.velocity * v_up;
230 // responsiveness factor for steering and acceleration
231 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
232 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
234 if(myspeed < 0 && g_bugrigs_reverse_spinning)
235 steerfactor = -myspeed * g_bugrigs_steer;
237 steerfactor = -myspeed * f * g_bugrigs_steer;
239 if(myspeed < 0 && g_bugrigs_reverse_speeding)
240 accelfactor = g_bugrigs_accel;
242 accelfactor = f * g_bugrigs_accel;
243 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
249 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
253 if(!g_bugrigs_reverse_speeding)
254 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
261 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
265 if(g_bugrigs_reverse_stopping)
268 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
271 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
272 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
274 self.angles_y += steer * frametime * steerfactor; // apply steering
275 makevectors(self.angles); // new forward direction!
277 myspeed += accel * accelfactor * frametime;
279 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
283 myspeed = vlen(self.velocity);
285 // responsiveness factor for steering and acceleration
286 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
287 steerfactor = -myspeed * f;
288 self.angles_y += steer * frametime * steerfactor; // apply steering
290 rigvel = self.velocity;
291 makevectors(self.angles); // new forward direction!
294 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
295 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
296 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
297 //MAXIMA: solve(total_acceleration(v) = 0, v);
299 if(g_bugrigs_planar_movement)
301 vector rigvel_xy, neworigin, up;
304 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
308 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
311 mt = MOVE_NOMONSTERS;
313 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
314 up = trace_endpos - self.origin;
316 // BUG RIGS: align the move to the surface instead of doing collision testing
318 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
321 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
323 if(trace_fraction < 0.5)
326 neworigin = self.origin;
329 neworigin = trace_endpos;
331 if(trace_fraction < 1)
333 // now set angles_x so that the car points parallel to the surface
334 self.angles = vectoangles(
335 '1 0 0' * v_forward_x * trace_plane_normal_z
337 '0 1 0' * v_forward_y * trace_plane_normal_z
339 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
341 self.flags |= FL_ONGROUND;
345 // now set angles_x so that the car points forward, but is tilted in velocity direction
346 self.flags &~= FL_ONGROUND;
349 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
350 self.movetype = MOVETYPE_NOCLIP;
354 rigvel_z -= frametime * sv_gravity; // 4x gravity plays better
355 self.velocity = rigvel;
356 self.movetype = MOVETYPE_FLY;
360 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
361 if(trace_fraction != 1)
363 self.angles = vectoangles2(
364 '1 0 0' * v_forward_x * trace_plane_normal_z
366 '0 1 0' * v_forward_y * trace_plane_normal_z
368 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
376 vel_local_x = v_forward * self.velocity;
377 vel_local_y = v_right * self.velocity;
378 vel_local_z = v_up * self.velocity;
380 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
381 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
385 vector vf1, vu1, smoothangles;
386 makevectors(self.angles);
387 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
392 makevectors(angles_save);
393 vf1 = vf1 + v_forward * (1 - f);
394 vu1 = vu1 + v_up * (1 - f);
395 smoothangles = vectoangles2(vf1, vu1);
396 self.angles_x = -smoothangles_x;
397 self.angles_z = smoothangles_z;
400 float IsMoveInDirection(vector mv, float angle) // key mix factor
402 if(mv_x == 0 && mv_y == 0)
403 return 0; // avoid division by zero
404 angle = RAD2DEG * atan2(mv_y, mv_x);
405 angle = remainder(angle, 360) / 45;
410 return 1 - fabs(angle);
413 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
415 float zspeed, xyspeed, dot, k;
418 // this doesn't play well with analog input
419 if(self.movement_x == 0 || self.movement_y != 0)
420 return; // can't control movement if not moving forward or backward
423 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
428 k *= bound(0, wishspeed / sv_maxairspeed, 1);
430 zspeed = self.velocity_z;
432 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
434 dot = self.velocity * wishdir;
435 k *= sv_aircontrol*dot*dot*frametime;
437 if(dot > 0) // we can't change direction while slowing down
439 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
442 self.velocity = self.velocity * xyspeed;
443 self.velocity_z = zspeed;
446 // example config for alternate speed clamping:
447 // sv_airaccel_qw 0.8
448 // sv_airaccel_sideways_friction 0
449 // prvm_globalset server speedclamp_mode 1
451 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float sidefric)
459 float vel_xy_current;
460 float vel_xy_backward, vel_xy_forward;
463 speedclamp = (accelqw < 0);
467 if(cvar("sv_gameplayfix_q2airaccelerate"))
468 wishspeed0 = wishspeed;
470 vel_straight = self.velocity * wishdir;
471 vel_z = self.velocity_z;
472 vel_xy = self.velocity - vel_z * '0 0 1';
473 vel_perpend = vel_xy - vel_straight * wishdir;
475 step = accel * frametime * wishspeed0;
477 vel_xy_current = vlen(vel_xy);
478 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
479 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
480 if(vel_xy_backward < 0)
481 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
483 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
485 if(sidefric < 0 && (vel_perpend*vel_perpend))
486 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
489 f = (1 - frametime * wishspeed * sidefric);
490 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
492 vel_perpend = vel_perpend * f;
495 fminimum = sqrt(fminimum);
496 vel_perpend = vel_perpend * bound(fminimum, f, 1);
500 vel_perpend = vel_perpend * (1 - frametime * wishspeed * sidefric);
502 vel_xy = vel_straight * wishdir + vel_perpend;
506 // ensure we don't get too fast or decelerate faster than we should
507 vel_xy_current = min(vlen(vel_xy), vel_xy_forward);
508 if(vel_xy_current > 0) // prevent division by zero
509 vel_xy = normalize(vel_xy) * vel_xy_current;
512 self.velocity = vel_xy + vel_z * '0 0 1';
515 void PM_AirAccelerate(vector wishdir, float wishspeed)
517 vector curvel, wishvel, acceldir, curdir;
518 float addspeed, accelspeed, curspeed, f;
524 curvel = self.velocity;
526 curspeed = vlen(curvel);
528 if(wishspeed > curspeed * 1.01)
530 wishspeed = min(wishspeed, curspeed + sv_warsowbunny_airforwardaccel * sv_maxspeed * frametime);
534 f = max(0, (sv_warsowbunny_topspeed - curspeed) / (sv_warsowbunny_topspeed - sv_maxspeed));
535 wishspeed = max(curspeed, sv_maxspeed) + sv_warsowbunny_accel * f * sv_maxspeed * frametime;
537 wishvel = wishdir * wishspeed;
538 acceldir = wishvel - curvel;
539 addspeed = vlen(acceldir);
540 acceldir = normalize(acceldir);
542 accelspeed = min(addspeed, sv_warsowbunny_turnaccel * sv_maxspeed * frametime);
544 if(sv_warsowbunny_backtosideratio < 1)
546 curdir = normalize(curvel);
547 dot = acceldir * curdir;
549 acceldir = acceldir - (1 - sv_warsowbunny_backtosideratio) * dot * curdir;
552 self.velocity += accelspeed * acceldir;
555 .vector movement_old;
558 .string lastclassname;
560 void Nixnex_GiveCurrentWeapon();
561 .float() PlayerPhysplug;
563 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
564 .float specialcommand_pos;
565 void SpecialCommand()
570 if(!CheatImpulse(99))
571 print("A hollow voice says \"Plugh\".\n");
575 float speedaward_speed;
576 string speedaward_holder;
577 void race_send_speedaward(float msg)
579 // send the best speed of the round
580 WriteByte(msg, SVC_TEMPENTITY);
581 WriteByte(msg, TE_CSQC_RACE);
582 WriteByte(msg, RACE_NET_SPEED_AWARD);
583 WriteInt24_t(msg, floor(speedaward_speed+0.5));
584 WriteString(msg, speedaward_holder);
587 float speedaward_alltimebest;
588 string speedaward_alltimebest_holder;
589 void race_send_speedaward_alltimebest(float msg)
591 // send the best speed
592 WriteByte(msg, SVC_TEMPENTITY);
593 WriteByte(msg, TE_CSQC_RACE);
594 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
595 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
596 WriteString(msg, speedaward_alltimebest_holder);
599 string GetMapname(void);
600 float speedaward_lastupdate;
601 float speedaward_lastsent;
602 void SV_PlayerPhysics()
604 local vector wishvel, wishdir, v;
605 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
608 float not_allowed_to_move;
611 if(self.PlayerPhysplug)
612 if(self.PlayerPhysplug())
615 self.race_movetime_frac += frametime;
616 f = floor(self.race_movetime_frac);
617 self.race_movetime_frac -= f;
618 self.race_movetime_count += f;
619 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
623 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);
627 else if(buttons == 1)
629 else if(buttons == 2)
631 else if(buttons == 128)
633 else if(buttons == 256)
635 else if(buttons == 512)
637 else if(buttons == 1024)
642 if(c == substring(specialcommand, self.specialcommand_pos, 1))
644 self.specialcommand_pos += 1;
645 if(self.specialcommand_pos >= strlen(specialcommand))
647 self.specialcommand_pos = 0;
652 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
653 self.specialcommand_pos = 0;
655 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
657 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
658 self.parm_idlesince = time;
660 buttons_prev = self.buttons_old;
661 self.buttons_old = buttons;
662 self.movement_old = self.movement;
663 self.v_angle_old = self.v_angle;
665 if(time < self.nickspamtime)
666 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
668 // slight annoyance for nick change scripts
669 self.movement = -1 * self.movement;
670 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
672 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!
674 self.angles_x = random() * 360;
675 self.angles_y = random() * 360;
676 // at least I'm not forcing retardedview by also assigning to angles_z
681 if (self.punchangle != '0 0 0')
683 f = vlen(self.punchangle) - 10 * frametime;
685 self.punchangle = normalize(self.punchangle) * f;
687 self.punchangle = '0 0 0';
690 if (self.punchvector != '0 0 0')
692 f = vlen(self.punchvector) - 30 * frametime;
694 self.punchvector = normalize(self.punchvector) * f;
696 self.punchvector = '0 0 0';
699 if (clienttype(self) == CLIENTTYPE_BOT)
701 if(playerdemo_read())
706 self.items &~= IT_USING_JETPACK;
708 if(self.classname == "player")
710 if(self.race_penalty)
711 if(time > self.race_penalty)
712 self.race_penalty = 0;
714 not_allowed_to_move = 0;
715 if(self.race_penalty)
716 not_allowed_to_move = 1;
717 if(!cvar("sv_ready_restart_after_countdown"))
718 if(time < game_starttime)
719 not_allowed_to_move = 1;
721 if(not_allowed_to_move)
723 self.velocity = '0 0 0';
724 self.movetype = MOVETYPE_NONE;
725 self.disableclientprediction = 2;
727 else if(self.disableclientprediction == 2)
729 if(self.movetype == MOVETYPE_NONE)
730 self.movetype = MOVETYPE_WALK;
731 self.disableclientprediction = 0;
735 if (self.movetype == MOVETYPE_NONE)
742 if(self.runes & RUNE_SPEED)
744 if(self.runes & CURSE_SLOW)
745 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_combo_moverate");
747 maxspd_mod = maxspd_mod * cvar("g_balance_rune_speed_moverate");
749 else if(self.runes & CURSE_SLOW)
751 maxspd_mod = maxspd_mod * cvar("g_balance_curse_slow_moverate");
755 if(g_minstagib && (self.items & IT_INVINCIBLE))
757 maxspd_mod = cvar("g_minstagib_speed_moverate");
760 if(g_nexball && self.ballcarried)
762 maxspd_mod = cvar("g_nexball_basketball_carrier_speed");
767 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
770 if(self.classname != "player")
772 maxspd_mod = cvar("sv_spectator_speed_multiplier");
773 if(!self.spectatorspeed)
774 self.spectatorspeed = maxspd_mod;
775 if(self.impulse && self.impulse <= 19)
777 if(self.lastclassname != "player")
779 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
780 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
781 else if(self.impulse == 11)
782 self.spectatorspeed = maxspd_mod;
783 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
784 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
785 else if(self.impulse >= 1 && self.impulse <= 9)
786 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
787 } // otherwise just clear
790 maxspd_mod = self.spectatorspeed;
793 spd = max(sv_maxspeed, sv_maxairspeed) * maxspd_mod * swampspd_mod;
794 if(self.speed != spd)
798 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
799 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
800 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
801 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
804 maxspd_mod *= swampspd_mod; // only one common speed modder please!
807 // if dead, behave differently
811 if (!self.fixangle && !g_bugrigs)
814 self.angles_y = self.v_angle_y;
818 if(self.flags & FL_ONGROUND)
823 if(self.waterlevel < WATERLEVEL_SWIMMING)
824 if(time >= self.ladder_time)
827 self.nextstep = time + 0.3 + random() * 0.1;
828 trace_dphitq3surfaceflags = 0;
829 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
830 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
832 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
833 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
835 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
843 if(self.classname == "player")
847 self.flags &~= FL_ONGROUND;
848 tracebox(self.origin + '0 0 1', self.mins, self.maxs, self.origin - '0 0 1', MOVE_NORMAL, self);
849 if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
850 self.flags |= FL_ONGROUND;
853 if (self.BUTTON_JUMP)
856 self.flags |= FL_JUMPRELEASED;
859 self.wasinair = !(self.flags & FL_ONGROUND);
861 if (self.waterlevel == WATERLEVEL_SWIMMING)
865 if (self.flags & FL_WATERJUMP )
867 self.velocity_x = self.movedir_x;
868 self.velocity_y = self.movedir_y;
869 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
871 self.flags &~= FL_WATERJUMP;
872 self.teleport_time = 0;
875 else if (g_bugrigs && self.classname == "player")
879 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
881 // noclipping or flying
882 self.flags &~= FL_ONGROUND;
884 self.velocity = self.velocity * (1 - frametime * sv_friction);
885 makevectors(self.v_angle);
886 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
887 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
889 wishdir = normalize(wishvel);
890 wishspeed = vlen(wishvel);
891 if (wishspeed > sv_maxspeed*maxspd_mod)
892 wishspeed = sv_maxspeed*maxspd_mod;
893 if (time >= self.teleport_time)
894 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
896 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
899 self.flags &~= FL_ONGROUND;
901 makevectors(self.v_angle);
902 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
903 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
904 if (wishvel == '0 0 0')
905 wishvel = '0 0 -60'; // drift towards bottom
907 wishdir = normalize(wishvel);
908 wishspeed = vlen(wishvel);
909 if (wishspeed > sv_maxspeed*maxspd_mod)
910 wishspeed = sv_maxspeed*maxspd_mod;
911 wishspeed = wishspeed * 0.7;
914 self.velocity = self.velocity * (1 - frametime * sv_friction);
916 // water acceleration
917 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
919 else if (time < self.ladder_time)
921 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
922 self.flags &~= FL_ONGROUND;
924 self.velocity = self.velocity * (1 - frametime * sv_friction);
925 makevectors(self.v_angle);
926 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
927 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
929 self.velocity_z = self.velocity_z + self.gravity * sv_gravity * frametime;
931 self.velocity_z = self.velocity_z + sv_gravity * frametime;
932 if (self.ladder_entity.classname == "func_water")
935 if (f > self.ladder_entity.speed)
936 wishvel = wishvel * (self.ladder_entity.speed / f);
938 self.watertype = self.ladder_entity.skin;
939 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
940 if ((self.origin_z + self.view_ofs_z) < f)
941 self.waterlevel = WATERLEVEL_SUBMERGED;
942 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
943 self.waterlevel = WATERLEVEL_SWIMMING;
944 else if ((self.origin_z + self.mins_z + 1) < f)
945 self.waterlevel = WATERLEVEL_WETFEET;
948 self.waterlevel = WATERLEVEL_NONE;
949 self.watertype = CONTENT_EMPTY;
953 wishdir = normalize(wishvel);
954 wishspeed = vlen(wishvel);
955 if (wishspeed > sv_maxspeed*maxspd_mod)
956 wishspeed = sv_maxspeed*maxspd_mod;
957 if (time >= self.teleport_time)
959 // water acceleration
960 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
963 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
965 //makevectors(self.v_angle_y * '0 1 0');
966 makevectors(self.v_angle);
967 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
968 // add remaining speed as Z component
969 maxairspd = sv_maxairspeed*max(1, maxspd_mod);
971 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
972 // add the unused velocity as up component
975 // if(self.BUTTON_JUMP)
976 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
978 // it is now normalized, so...
979 float a_side, a_up, a_add, a_diff;
980 a_side = cvar("g_jetpack_acceleration_side");
981 a_up = cvar("g_jetpack_acceleration_up");
982 a_add = cvar("g_jetpack_antigravity") * sv_gravity;
991 //////////////////////////////////////////////////////////////////////////////////////
992 // finding the maximum over all vectors of above form
993 // with wishvel having an absolute value of 1
994 //////////////////////////////////////////////////////////////////////////////////////
995 // we're finding the maximum over
996 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
997 // for z in the range from -1 to 1
998 //////////////////////////////////////////////////////////////////////////////////////
999 // maximum is EITHER attained at the single extreme point:
1000 a_diff = a_side * a_side - a_up * a_up;
1003 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1004 if(f > -1 && f < 1) // can it be attained?
1006 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1007 //print("middle\n");
1010 // OR attained at z = 1:
1011 f = (a_up + a_add) * (a_up + a_add);
1017 // OR attained at z = -1:
1018 f = (a_up - a_add) * (a_up - a_add);
1022 //print("bottom\n");
1025 //////////////////////////////////////////////////////////////////////////////////////
1027 //print("best possible acceleration: ", ftos(best), "\n");
1030 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
1031 if(wishvel_z - sv_gravity > 0)
1032 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1034 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1037 fvel = vlen(wishvel);
1040 wishvel_z = (wishvel_z - sv_gravity) * fz + sv_gravity;
1042 fvel = min(1, vlen(wishvel) / best);
1043 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1044 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
1048 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1050 if (f > 0 && wishvel != '0 0 0')
1052 self.velocity = self.velocity + wishvel * f * frametime;
1053 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1054 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
1055 self.flags &~= FL_ONGROUND;
1056 self.items |= IT_USING_JETPACK;
1058 // jetpack also inhibits health regeneration, but only for 1 second
1059 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1062 else if (self.flags & FL_ONGROUND)
1064 // we get here if we ran out of ammo
1065 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1066 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1069 makevectors(self.v_angle_y * '0 1 0');
1070 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1072 if(!(self.lastflags & FL_ONGROUND))
1074 if(cvar("speedmeter"))
1075 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1076 if(self.lastground < time - 0.3)
1077 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1078 if(self.jumppadcount > 1)
1079 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1080 self.jumppadcount = 0;
1083 #ifdef LETS_TEST_FTEQCC
1084 if(self.velocity_x || self.velocity_y)
1102 if (f < sv_stopspeed)
1103 f = 1 - frametime * (sv_stopspeed / f) * sv_friction;
1105 f = 1 - frametime * sv_friction;
1107 self.velocity = self.velocity * f;
1109 self.velocity = '0 0 0';
1113 wishdir = normalize(wishvel);
1114 wishspeed = vlen(wishvel);
1115 if (wishspeed > sv_maxspeed*maxspd_mod)
1116 wishspeed = sv_maxspeed*maxspd_mod;
1118 wishspeed = wishspeed * 0.5;
1119 if (time >= self.teleport_time)
1120 PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0);
1125 // we get here if we ran out of ammo
1126 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1127 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1131 maxairspd = sv_maxairspeed*maxspd_mod;
1132 airaccel = sv_airaccelerate*maxspd_mod;
1136 maxairspd = sv_maxairspeed;
1137 airaccel = sv_airaccelerate;
1140 makevectors(self.v_angle_y * '0 1 0');
1141 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1143 wishdir = normalize(wishvel);
1144 wishspeed = wishspeed0 = vlen(wishvel);
1145 if (wishspeed0 > sv_maxspeed*maxspd_mod)
1146 wishspeed0 = sv_maxspeed*maxspd_mod;
1147 if (wishspeed > maxairspd)
1148 wishspeed = maxairspd;
1150 wishspeed = wishspeed * 0.5;
1151 if (time >= self.teleport_time)
1157 airaccelqw = sv_airaccel_qw;
1158 accelerating = (self.velocity * wishdir > 0);
1159 wishspeed2 = wishspeed;
1162 if(sv_airstopaccelerate)
1163 if(self.velocity * wishdir < 0)
1164 airaccel = sv_airstopaccelerate*maxspd_mod;
1165 // this doesn't play well with analog input, but can't r
1166 // fixed like the AirControl can. So, don't set the maxa
1167 // cvars when you want to support analog input.
1168 if(self.movement_x == 0 && self.movement_y != 0)
1170 if(sv_maxairstrafespeed)
1172 wishspeed = min(wishspeed, sv_maxairstrafespeed*maxspd_mod);
1173 if(sv_maxairstrafespeed < sv_maxairspeed)
1176 if(sv_airstrafeaccelerate)
1178 airaccel = sv_airstrafeaccelerate*maxspd_mod;
1179 if(sv_airstrafeaccelerate > sv_airaccelerate)
1185 if(sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1186 PM_AirAccelerate(wishdir, wishspeed);
1188 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, sv_airaccel_sideways_friction / maxairspd);
1191 CPM_PM_Aircontrol(wishdir, wishspeed2);
1195 if((g_cts || g_race) && self.classname != "observer") {
1196 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1197 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1198 speedaward_holder = self.netname;
1199 speedaward_lastupdate = time;
1201 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1207 race_send_speedaward(MSG_ALL);
1208 speedaward_lastsent = speedaward_speed;
1209 if (speedaward_speed > speedaward_alltimebest) {
1210 speedaward_alltimebest = speedaward_speed;
1211 speedaward_alltimebest_holder = speedaward_holder;
1212 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1213 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"), speedaward_alltimebest_holder);
1214 race_send_speedaward_alltimebest(MSG_ALL);
1219 if(self.flags & FL_ONGROUND)
1220 self.lastground = time;
1222 self.lastflags = self.flags;
1223 self.lastclassname = self.classname;