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