11 .float spectatorspeed;
17 When you press the jump key
18 returns TRUE if handled
21 float PlayerJump (void)
24 return TRUE; // no jumping in freezetag when frozen
26 if(self.player_blocked)
27 return TRUE; // no jumping while blocked
29 float doublejump = FALSE;
30 float mjumpheight = autocvar_sv_jumpvelocity;
32 player_multijump = doublejump;
33 player_jumpheight = mjumpheight;
34 if(MUTATOR_CALLHOOK(PlayerJump))
37 doublejump = player_multijump;
38 mjumpheight = player_jumpheight;
40 if (autocvar_sv_doublejump)
42 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
43 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
47 // we MUST clip velocity here!
49 f = self.velocity * trace_plane_normal;
51 self.velocity -= f * trace_plane_normal;
55 if (self.waterlevel >= WATERLEVEL_SWIMMING)
57 self.velocity_z = self.stat_sv_maxspeed * 0.7;
62 if (!(self.flags & FL_ONGROUND))
63 return !(self.flags & FL_JUMPRELEASED);
65 if(self.cvar_cl_movement_track_canjump)
66 if (!(self.flags & FL_JUMPRELEASED))
69 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
70 // velocity bounds. Final velocity is bound between (jumpheight *
71 // min + jumpheight) and (jumpheight * max + jumpheight);
73 if(autocvar_sv_jumpspeedcap_min != "")
77 minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min);
79 if (self.velocity_z < minjumpspeed)
80 mjumpheight += minjumpspeed - self.velocity_z;
83 if(autocvar_sv_jumpspeedcap_max != "")
85 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
86 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
88 if(!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && autocvar_sv_jumpspeedcap_max_disable_on_ramps))
92 maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max);
94 if (self.velocity_z > maxjumpspeed)
95 mjumpheight -= self.velocity_z - maxjumpspeed;
99 if(!(self.lastflags & FL_ONGROUND))
101 if(autocvar_speedmeter)
102 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
103 if(self.lastground < time - 0.3)
105 self.velocity_x *= (1 - autocvar_sv_friction_on_land);
106 self.velocity_y *= (1 - autocvar_sv_friction_on_land);
108 if(self.jumppadcount > 1)
109 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
110 self.jumppadcount = 0;
113 self.velocity_z = self.velocity_z + mjumpheight;
114 self.oldvelocity_z = self.velocity_z;
116 self.flags &= ~FL_ONGROUND;
117 self.flags &= ~FL_JUMPRELEASED;
119 animdecide_setaction(self, ANIMACTION_JUMP, TRUE);
121 if(autocvar_g_jump_grunt)
122 PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
124 self.restart_jump = -1; // restart jump anim next time
125 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
128 void CheckWaterJump()
132 // check for a jump-out-of-water
133 makevectors (self.angles);
135 start_z = start_z + 8;
137 normalize(v_forward);
138 end = start + v_forward*24;
139 traceline (start, end, TRUE, self);
140 if (trace_fraction < 1)
142 start_z = start_z + self.maxs_z - 8;
143 end = start + v_forward*24;
144 self.movedir = trace_plane_normal * -50;
145 traceline (start, end, TRUE, self);
146 if (trace_fraction == 1)
147 { // open at eye level
148 self.flags |= FL_WATERJUMP;
149 self.velocity_z = 225;
150 self.flags &= ~FL_JUMPRELEASED;
151 self.teleport_time = time + 2; // safety net
157 // Hack: shouldn't need to know about this
158 .float multijump_count;
159 void CheckPlayerJump()
161 if (self.BUTTON_JUMP)
163 if (!PlayerJump() || self.multijump_count > 0)
165 self.items |= IT_USING_JETPACK;
170 self.flags |= FL_JUMPRELEASED;
171 self.items &= ~IT_USING_JETPACK;
173 if (self.waterlevel == WATERLEVEL_SWIMMING)
177 float racecar_angle(float forward, float down)
179 float ret, angle_mult;
187 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
189 angle_mult = forward / (800 + forward);
192 return ret * angle_mult + 360 * (1 - angle_mult);
194 return ret * angle_mult;
197 void RaceCarPhysics()
199 // using this move type for "big rigs"
200 // the engine does not push the entity!
202 float accel, steer, f, myspeed, steerfactor;
203 vector angles_save, rigvel;
205 angles_save = self.angles;
206 accel = bound(-1, self.movement_x / self.stat_sv_maxspeed, 1);
207 steer = bound(-1, self.movement_y / self.stat_sv_maxspeed, 1);
209 if(g_bugrigs_reverse_speeding)
213 // back accel is DIGITAL
214 // to prevent speedhack
224 makevectors(self.angles); // new forward direction!
226 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
228 float upspeed, accelfactor;
230 myspeed = self.velocity * v_forward;
231 upspeed = self.velocity * v_up;
233 // responsiveness factor for steering and acceleration
234 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
235 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
237 if(myspeed < 0 && g_bugrigs_reverse_spinning)
238 steerfactor = -myspeed * g_bugrigs_steer;
240 steerfactor = -myspeed * f * g_bugrigs_steer;
242 if(myspeed < 0 && g_bugrigs_reverse_speeding)
243 accelfactor = g_bugrigs_accel;
245 accelfactor = f * g_bugrigs_accel;
246 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
252 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
256 if(!g_bugrigs_reverse_speeding)
257 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
264 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
268 if(g_bugrigs_reverse_stopping)
271 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
274 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
275 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
277 self.angles_y += steer * frametime * steerfactor; // apply steering
278 makevectors(self.angles); // new forward direction!
280 myspeed += accel * accelfactor * frametime;
282 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
286 myspeed = vlen(self.velocity);
288 // responsiveness factor for steering and acceleration
289 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
290 steerfactor = -myspeed * f;
291 self.angles_y += steer * frametime * steerfactor; // apply steering
293 rigvel = self.velocity;
294 makevectors(self.angles); // new forward direction!
297 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
298 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
299 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
300 //MAXIMA: solve(total_acceleration(v) = 0, v);
302 if(g_bugrigs_planar_movement)
304 vector rigvel_xy, neworigin, up;
307 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
308 rigvel_xy = vec2(rigvel);
310 if(g_bugrigs_planar_movement_car_jumping)
313 mt = MOVE_NOMONSTERS;
315 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
316 up = trace_endpos - self.origin;
318 // BUG RIGS: align the move to the surface instead of doing collision testing
320 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
323 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
325 if(trace_fraction < 0.5)
328 neworigin = self.origin;
331 neworigin = trace_endpos;
333 if(trace_fraction < 1)
335 // now set angles_x so that the car points parallel to the surface
336 self.angles = vectoangles(
337 '1 0 0' * v_forward_x * trace_plane_normal_z
339 '0 1 0' * v_forward_y * trace_plane_normal_z
341 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
343 self.flags |= FL_ONGROUND;
347 // now set angles_x so that the car points forward, but is tilted in velocity direction
348 self.flags &= ~FL_ONGROUND;
351 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
352 self.movetype = MOVETYPE_NOCLIP;
356 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
357 self.velocity = rigvel;
358 self.movetype = MOVETYPE_FLY;
362 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
363 if(trace_fraction != 1)
365 self.angles = vectoangles2(
366 '1 0 0' * v_forward_x * trace_plane_normal_z
368 '0 1 0' * v_forward_y * trace_plane_normal_z
370 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
378 vel_local_x = v_forward * self.velocity;
379 vel_local_y = v_right * self.velocity;
380 vel_local_z = v_up * self.velocity;
382 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
383 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
387 vector vf1, vu1, smoothangles;
388 makevectors(self.angles);
389 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
394 makevectors(angles_save);
395 vf1 = vf1 + v_forward * (1 - f);
396 vu1 = vu1 + v_up * (1 - f);
397 smoothangles = vectoangles2(vf1, vu1);
398 self.angles_x = -smoothangles_x;
399 self.angles_z = smoothangles_z;
402 float IsMoveInDirection(vector mv, float angle) // key mix factor
404 if(mv_x == 0 && mv_y == 0)
405 return 0; // avoid division by zero
406 angle -= RAD2DEG * atan2(mv_y, mv_x);
407 angle = remainder(angle, 360) / 45;
412 return 1 - fabs(angle);
415 float GeomLerp(float a, float lerp, float b)
431 return a * pow(fabs(b / a), lerp);
434 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
436 float zspeed, xyspeed, dot, k;
439 // this doesn't play well with analog input
440 if(self.movement_x == 0 || self.movement_y != 0)
441 return; // can't control movement if not moving forward or backward
444 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
449 k *= bound(0, wishspeed / autocvar_sv_maxairspeed, 1);
451 zspeed = self.velocity_z;
453 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
455 dot = self.velocity * wishdir;
457 if(dot > 0) // we can't change direction while slowing down
459 k *= pow(dot, autocvar_sv_aircontrol_power)*frametime;
460 xyspeed = max(0, xyspeed - autocvar_sv_aircontrol_penalty * sqrt(max(0, 1 - dot*dot)) * k/32);
461 k *= autocvar_sv_aircontrol;
462 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
465 self.velocity = self.velocity * xyspeed;
466 self.velocity_z = zspeed;
469 float AdjustAirAccelQW(float accelqw, float factor)
471 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
474 // example config for alternate speed clamping:
475 // sv_airaccel_qw 0.8
476 // sv_airaccel_sideways_friction 0
477 // prvm_globalset server speedclamp_mode 1
479 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
487 float vel_xy_current;
488 float vel_xy_backward, vel_xy_forward;
491 if(stretchfactor > 0)
492 speedclamp = stretchfactor;
494 speedclamp = 1; // full clamping, no stretch
496 speedclamp = -1; // no clamping
501 if(autocvar_sv_gameplayfix_q2airaccelerate)
502 wishspeed0 = wishspeed;
504 vel_straight = self.velocity * wishdir;
505 vel_z = self.velocity_z;
506 vel_xy = vec2(self.velocity);
507 vel_perpend = vel_xy - vel_straight * wishdir;
509 step = accel * frametime * wishspeed0;
511 vel_xy_current = vlen(vel_xy);
513 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
514 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
515 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
516 if(vel_xy_backward < 0)
517 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
519 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
521 if(sidefric < 0 && (vel_perpend*vel_perpend))
522 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
525 f = max(0, 1 + frametime * wishspeed * sidefric);
526 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
527 // this cannot be > 1
529 vel_perpend = vel_perpend * max(0, f);
532 fminimum = sqrt(fminimum);
533 vel_perpend = vel_perpend * max(fminimum, f);
537 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
539 vel_xy = vel_straight * wishdir + vel_perpend;
543 float vel_xy_preclamp;
544 vel_xy_preclamp = vlen(vel_xy);
545 if(vel_xy_preclamp > 0) // prevent division by zero
547 vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
548 if(vel_xy_current < vel_xy_preclamp)
549 vel_xy = vel_xy * (vel_xy_current / vel_xy_preclamp);
553 self.velocity = vel_xy + vel_z * '0 0 1';
556 void PM_AirAccelerate(vector wishdir, float wishspeed)
558 vector curvel, wishvel, acceldir, curdir;
559 float addspeed, accelspeed, curspeed, f;
565 curvel = self.velocity;
567 curspeed = vlen(curvel);
569 if(wishspeed > curspeed * 1.01)
571 wishspeed = min(wishspeed, curspeed + autocvar_sv_warsowbunny_airforwardaccel * self.stat_sv_maxspeed * frametime);
575 f = max(0, (autocvar_sv_warsowbunny_topspeed - curspeed) / (autocvar_sv_warsowbunny_topspeed - self.stat_sv_maxspeed));
576 wishspeed = max(curspeed, self.stat_sv_maxspeed) + autocvar_sv_warsowbunny_accel * f * self.stat_sv_maxspeed * frametime;
578 wishvel = wishdir * wishspeed;
579 acceldir = wishvel - curvel;
580 addspeed = vlen(acceldir);
581 acceldir = normalize(acceldir);
583 accelspeed = min(addspeed, autocvar_sv_warsowbunny_turnaccel * self.stat_sv_maxspeed * frametime);
585 if(autocvar_sv_warsowbunny_backtosideratio < 1)
587 curdir = normalize(curvel);
588 dot = acceldir * curdir;
590 acceldir = acceldir - (1 - autocvar_sv_warsowbunny_backtosideratio) * dot * curdir;
593 self.velocity += accelspeed * acceldir;
596 .vector movement_old;
599 .string lastclassname;
601 .float() PlayerPhysplug;
603 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
604 .float specialcommand_pos;
605 void SpecialCommand()
610 if(!CheatImpulse(99))
611 print("A hollow voice says \"Plugh\".\n");
615 float speedaward_speed;
616 string speedaward_holder;
617 string speedaward_uid;
618 void race_send_speedaward(float msg)
620 // send the best speed of the round
621 WriteByte(msg, SVC_TEMPENTITY);
622 WriteByte(msg, TE_CSQC_RACE);
623 WriteByte(msg, RACE_NET_SPEED_AWARD);
624 WriteInt24_t(msg, floor(speedaward_speed+0.5));
625 WriteString(msg, speedaward_holder);
628 float speedaward_alltimebest;
629 string speedaward_alltimebest_holder;
630 string speedaward_alltimebest_uid;
631 void race_send_speedaward_alltimebest(float msg)
633 // send the best speed
634 WriteByte(msg, SVC_TEMPENTITY);
635 WriteByte(msg, TE_CSQC_RACE);
636 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
637 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
638 WriteString(msg, speedaward_alltimebest_holder);
641 string GetMapname(void);
642 float speedaward_lastupdate;
643 float speedaward_lastsent;
644 void SV_PlayerPhysics()
646 vector wishvel, wishdir, v;
647 float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
650 float not_allowed_to_move;
653 WarpZone_PlayerPhysics_FixVAngle();
658 maxspd_mod *= autocvar_g_keepaway_ballcarrier_highspeed;
660 maxspd_mod *= autocvar_g_movement_highspeed;
662 // fix physics stats for g_movement_highspeed
663 // TODO maybe rather use maxairspeed? needs testing
664 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
665 if(autocvar_sv_airstrafeaccel_qw)
666 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
668 self.stat_sv_airstrafeaccel_qw = 0;
669 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
670 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
672 if(self.PlayerPhysplug)
673 if(self.PlayerPhysplug())
676 self.race_movetime_frac += frametime;
677 f = floor(self.race_movetime_frac);
678 self.race_movetime_frac -= f;
679 self.race_movetime_count += f;
680 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
684 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);
688 else if(buttons == 1)
690 else if(buttons == 2)
692 else if(buttons == 128)
694 else if(buttons == 256)
696 else if(buttons == 512)
698 else if(buttons == 1024)
703 if(c == substring(specialcommand, self.specialcommand_pos, 1))
705 self.specialcommand_pos += 1;
706 if(self.specialcommand_pos >= strlen(specialcommand))
708 self.specialcommand_pos = 0;
713 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
714 self.specialcommand_pos = 0;
718 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
719 self.parm_idlesince = time;
721 buttons_prev = self.buttons_old;
722 self.buttons_old = buttons;
723 self.movement_old = self.movement;
724 self.v_angle_old = self.v_angle;
726 if(time < self.nickspamtime)
727 if(self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
729 // slight annoyance for nick change scripts
730 self.movement = -1 * self.movement;
731 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
733 if(self.nickspamcount >= autocvar_g_nick_flood_penalty_red) // if you are persistent and the slight annoyance above does not stop you, I'll show you!
735 self.angles_x = random() * 360;
736 self.angles_y = random() * 360;
737 // at least I'm not forcing retardedview by also assigning to angles_z
738 self.fixangle = TRUE;
742 if (self.punchangle != '0 0 0')
744 f = vlen(self.punchangle) - 10 * frametime;
746 self.punchangle = normalize(self.punchangle) * f;
748 self.punchangle = '0 0 0';
751 if (self.punchvector != '0 0 0')
753 f = vlen(self.punchvector) - 30 * frametime;
755 self.punchvector = normalize(self.punchvector) * f;
757 self.punchvector = '0 0 0';
760 if (IS_BOT_CLIENT(self))
762 if(playerdemo_read())
767 self.items &= ~IT_USING_JETPACK;
771 if(self.race_penalty)
772 if(time > self.race_penalty)
773 self.race_penalty = 0;
775 not_allowed_to_move = 0;
776 if(self.race_penalty)
777 not_allowed_to_move = 1;
778 if(!autocvar_sv_ready_restart_after_countdown)
779 if(time < game_starttime)
780 not_allowed_to_move = 1;
782 if(not_allowed_to_move)
784 self.velocity = '0 0 0';
785 self.movetype = MOVETYPE_NONE;
786 self.disableclientprediction = 2;
788 else if(self.disableclientprediction == 2)
790 if(self.movetype == MOVETYPE_NONE)
791 self.movetype = MOVETYPE_WALK;
792 self.disableclientprediction = 0;
796 if (self.movetype == MOVETYPE_NONE)
799 // when we get here, disableclientprediction cannot be 2
800 self.disableclientprediction = 0;
801 if(time < self.ladder_time)
802 self.disableclientprediction = 1;
804 if(time < self.spider_slowness)
806 self.stat_sv_maxspeed *= 0.5; // half speed while slow from spider
807 self.stat_sv_airspeedlimit_nonqw *= 0.5;
812 if(autocvar_sv_dodging_frozen && IS_REAL_CLIENT(self))
814 self.movement_x = bound(-5, self.movement_x, 5);
815 self.movement_y = bound(-5, self.movement_y, 5);
816 self.movement_z = bound(-5, self.movement_z, 5);
819 self.movement = '0 0 0';
820 self.disableclientprediction = 1;
822 vector midpoint = ((self.absmin + self.absmax) * 0.5);
823 if(pointcontents(midpoint) == CONTENT_WATER)
825 self.velocity = self.velocity * 0.5;
827 if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
828 { self.velocity_z = 200; }
832 MUTATOR_CALLHOOK(PlayerPhysics);
834 if(self.player_blocked)
836 self.movement = '0 0 0';
837 self.disableclientprediction = 1;
844 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
847 // conveyors: first fix velocity
848 if(self.conveyor.state)
849 self.velocity -= self.conveyor.movedir;
851 if (!IS_PLAYER(self))
853 maxspd_mod = autocvar_sv_spectator_speed_multiplier;
854 if(!self.spectatorspeed)
855 self.spectatorspeed = maxspd_mod;
856 if(self.impulse && self.impulse <= 19 || (self.impulse >= 200 && self.impulse <= 209) || (self.impulse >= 220 && self.impulse <= 229))
858 if(self.lastclassname != "player")
860 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209))
861 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
862 else if(self.impulse == 11)
863 self.spectatorspeed = maxspd_mod;
864 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229))
865 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
866 else if(self.impulse >= 1 && self.impulse <= 9)
867 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
868 } // otherwise just clear
871 maxspd_mod = self.spectatorspeed;
874 spd = max(self.stat_sv_maxspeed, autocvar_sv_maxairspeed) * maxspd_mod * swampspd_mod;
875 if(self.speed != spd)
879 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
880 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
881 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
882 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
885 maxspd_mod *= swampspd_mod; // only one common speed modder please!
888 // if dead, behave differently
892 if (!self.fixangle && !g_bugrigs)
895 self.angles_y = self.v_angle_y;
899 if(self.flags & FL_ONGROUND)
900 if(IS_PLAYER(self)) // no fall sounds for observers thank you very much
905 if(self.waterlevel < WATERLEVEL_SWIMMING)
906 if(time >= self.ladder_time)
909 self.nextstep = time + 0.3 + random() * 0.1;
910 trace_dphitq3surfaceflags = 0;
911 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
912 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
914 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
915 GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
917 GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
928 if (self.flags & FL_WATERJUMP )
930 self.velocity_x = self.movedir_x;
931 self.velocity_y = self.movedir_y;
932 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
934 self.flags &= ~FL_WATERJUMP;
935 self.teleport_time = 0;
938 else if (g_bugrigs && IS_PLAYER(self))
942 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
944 // noclipping or flying
945 self.flags &= ~FL_ONGROUND;
947 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
948 makevectors(self.v_angle);
949 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
950 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
952 wishdir = normalize(wishvel);
953 wishspeed = vlen(wishvel);
954 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
955 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
956 if (time >= self.teleport_time)
957 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
959 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
962 self.flags &= ~FL_ONGROUND;
964 makevectors(self.v_angle);
965 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
966 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
967 if (wishvel == '0 0 0')
968 wishvel = '0 0 -60'; // drift towards bottom
970 wishdir = normalize(wishvel);
971 wishspeed = vlen(wishvel);
972 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
973 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
974 wishspeed = wishspeed * 0.7;
977 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
979 // water acceleration
980 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
982 else if (time < self.ladder_time)
984 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
985 self.flags &= ~FL_ONGROUND;
988 g = autocvar_sv_gravity * frametime;
991 if(autocvar_sv_gameplayfix_gravityunaffectedbyticrate)
994 self.velocity_z += g;
997 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
998 makevectors(self.v_angle);
999 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
1000 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
1001 self.velocity_z += g;
1002 if (self.ladder_entity.classname == "func_water")
1005 if (f > self.ladder_entity.speed)
1006 wishvel = wishvel * (self.ladder_entity.speed / f);
1008 self.watertype = self.ladder_entity.skin;
1009 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1010 if ((self.origin_z + self.view_ofs_z) < f)
1011 self.waterlevel = WATERLEVEL_SUBMERGED;
1012 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1013 self.waterlevel = WATERLEVEL_SWIMMING;
1014 else if ((self.origin_z + self.mins_z + 1) < f)
1015 self.waterlevel = WATERLEVEL_WETFEET;
1018 self.waterlevel = WATERLEVEL_NONE;
1019 self.watertype = CONTENT_EMPTY;
1023 wishdir = normalize(wishvel);
1024 wishspeed = vlen(wishvel);
1025 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1026 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1027 if (time >= self.teleport_time)
1029 // water acceleration
1030 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1033 else if ((self.items & IT_USING_JETPACK) && (!autocvar_g_jetpack_fuel || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO) && !self.frozen)
1035 //makevectors(self.v_angle_y * '0 1 0');
1036 makevectors(self.v_angle);
1037 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1038 // add remaining speed as Z component
1039 maxairspd = autocvar_sv_maxairspeed*max(1, maxspd_mod);
1040 // fix speedhacks :P
1041 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
1042 // add the unused velocity as up component
1045 // if(self.BUTTON_JUMP)
1046 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1048 // it is now normalized, so...
1049 float a_side, a_up, a_add, a_diff;
1050 a_side = autocvar_g_jetpack_acceleration_side;
1051 a_up = autocvar_g_jetpack_acceleration_up;
1052 a_add = autocvar_g_jetpack_antigravity * autocvar_sv_gravity;
1054 wishvel_x *= a_side;
1055 wishvel_y *= a_side;
1061 //////////////////////////////////////////////////////////////////////////////////////
1062 // finding the maximum over all vectors of above form
1063 // with wishvel having an absolute value of 1
1064 //////////////////////////////////////////////////////////////////////////////////////
1065 // we're finding the maximum over
1066 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1067 // for z in the range from -1 to 1
1068 //////////////////////////////////////////////////////////////////////////////////////
1069 // maximum is EITHER attained at the single extreme point:
1070 a_diff = a_side * a_side - a_up * a_up;
1073 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1074 if(f > -1 && f < 1) // can it be attained?
1076 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1077 //print("middle\n");
1080 // OR attained at z = 1:
1081 f = (a_up + a_add) * (a_up + a_add);
1087 // OR attained at z = -1:
1088 f = (a_up - a_add) * (a_up - a_add);
1092 //print("bottom\n");
1095 //////////////////////////////////////////////////////////////////////////////////////
1097 //print("best possible acceleration: ", ftos(best), "\n");
1100 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / autocvar_g_jetpack_maxspeed_side, 1);
1101 if(wishvel_z - autocvar_sv_gravity > 0)
1102 fz = bound(0, 1 - self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1104 fz = bound(0, 1 + self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
1108 wishvel_z = (wishvel_z - autocvar_sv_gravity) * fz + autocvar_sv_gravity;
1111 fvel = min(1, vlen(wishvel) / best);
1112 if(autocvar_g_jetpack_fuel && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1113 f = min(1, self.ammo_fuel / (autocvar_g_jetpack_fuel * frametime * fvel));
1117 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1119 if (f > 0 && wishvel != '0 0 0')
1121 self.velocity = self.velocity + wishvel * f * frametime;
1122 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
1123 self.ammo_fuel -= autocvar_g_jetpack_fuel * frametime * fvel * f;
1124 self.flags &= ~FL_ONGROUND;
1125 self.items |= IT_USING_JETPACK;
1127 // jetpack also inhibits health regeneration, but only for 1 second
1128 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
1131 else if (self.flags & FL_ONGROUND)
1133 // we get here if we ran out of ammo
1134 if((self.items & IT_USING_JETPACK) && !(buttons_prev & 2) && self.ammo_fuel < 0.01)
1135 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1138 makevectors(self.v_angle_y * '0 1 0');
1139 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1141 if(!(self.lastflags & FL_ONGROUND))
1143 if(autocvar_speedmeter)
1144 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1145 if(self.lastground < time - 0.3)
1146 self.velocity = self.velocity * (1 - autocvar_sv_friction_on_land);
1147 if(self.jumppadcount > 1)
1148 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1149 self.jumppadcount = 0;
1157 if (f < autocvar_sv_stopspeed)
1158 f = 1 - frametime * (autocvar_sv_stopspeed / f) * autocvar_sv_friction;
1160 f = 1 - frametime * autocvar_sv_friction;
1162 self.velocity = self.velocity * f;
1164 self.velocity = '0 0 0';
1166 Mathematical analysis time!
1168 Our goal is to invert this mess.
1170 For the two cases we get:
1171 v = v0 * (1 - frametime * (autocvar_sv_stopspeed / v0) * autocvar_sv_friction)
1172 = v0 - frametime * autocvar_sv_stopspeed * autocvar_sv_friction
1173 v0 = v + frametime * autocvar_sv_stopspeed * autocvar_sv_friction
1175 v = v0 * (1 - frametime * autocvar_sv_friction)
1176 v0 = v / (1 - frametime * autocvar_sv_friction)
1178 These cases would be chosen ONLY if:
1179 v0 < autocvar_sv_stopspeed
1180 v + frametime * autocvar_sv_stopspeed * autocvar_sv_friction < autocvar_sv_stopspeed
1181 v < autocvar_sv_stopspeed * (1 - frametime * autocvar_sv_friction)
1183 v0 >= autocvar_sv_stopspeed
1184 v / (1 - frametime * autocvar_sv_friction) >= autocvar_sv_stopspeed
1185 v >= autocvar_sv_stopspeed * (1 - frametime * autocvar_sv_friction)
1190 wishdir = normalize(wishvel);
1191 wishspeed = vlen(wishvel);
1192 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1193 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1195 wishspeed = wishspeed * 0.5;
1196 if (time >= self.teleport_time)
1197 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
1202 // we get here if we ran out of ammo
1203 if((self.items & IT_USING_JETPACK) && !(buttons_prev & 2) && self.ammo_fuel < 0.01)
1204 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1208 maxairspd = autocvar_sv_maxairspeed*maxspd_mod;
1209 airaccel = autocvar_sv_airaccelerate*maxspd_mod;
1213 maxairspd = autocvar_sv_maxairspeed;
1214 airaccel = autocvar_sv_airaccelerate;
1217 makevectors(self.v_angle_y * '0 1 0');
1218 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1220 wishdir = normalize(wishvel);
1221 wishspeed = wishspeed0 = vlen(wishvel);
1222 if (wishspeed0 > self.stat_sv_maxspeed*maxspd_mod)
1223 wishspeed0 = self.stat_sv_maxspeed*maxspd_mod;
1224 if (wishspeed > maxairspd)
1225 wishspeed = maxairspd;
1227 wishspeed = wishspeed * 0.5;
1228 if (time >= self.teleport_time)
1235 airaccelqw = self.stat_sv_airaccel_qw;
1236 accelerating = (self.velocity * wishdir > 0);
1237 wishspeed2 = wishspeed;
1240 if(autocvar_sv_airstopaccelerate)
1243 curdir = self.velocity;
1245 curdir = normalize(curdir);
1246 airaccel = airaccel + (autocvar_sv_airstopaccelerate*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1248 // note that for straight forward jumping:
1249 // step = accel * frametime * wishspeed0;
1250 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1252 // dv/dt = accel * maxspeed (when slow)
1253 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1254 // log dv/dt = logaccel + logmaxspeed (when slow)
1255 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1256 strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
1257 if(autocvar_sv_maxairstrafespeed)
1258 wishspeed = min(wishspeed, GeomLerp(autocvar_sv_maxairspeed*maxspd_mod, strafity, autocvar_sv_maxairstrafespeed*maxspd_mod));
1259 if(autocvar_sv_airstrafeaccelerate)
1260 airaccel = GeomLerp(airaccel, strafity, autocvar_sv_airstrafeaccelerate*maxspd_mod);
1261 if(self.stat_sv_airstrafeaccel_qw)
1262 airaccelqw = copysign(1-GeomLerp(1-fabs(self.stat_sv_airaccel_qw), strafity, 1-fabs(self.stat_sv_airstrafeaccel_qw)), ((strafity > 0.5) ? self.stat_sv_airstrafeaccel_qw : self.stat_sv_airaccel_qw));
1265 if(autocvar_sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1266 PM_AirAccelerate(wishdir, wishspeed);
1268 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, autocvar_sv_airaccel_qw_stretchfactor, autocvar_sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw);
1270 if(autocvar_sv_aircontrol)
1271 CPM_PM_Aircontrol(wishdir, wishspeed2);
1275 if((g_cts || g_race) && !IS_OBSERVER(self))
1277 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
1279 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1280 speedaward_holder = self.netname;
1281 speedaward_uid = self.crypto_idfp;
1282 speedaward_lastupdate = time;
1284 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
1286 string rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
1287 race_send_speedaward(MSG_ALL);
1288 speedaward_lastsent = speedaward_speed;
1289 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
1291 speedaward_alltimebest = speedaward_speed;
1292 speedaward_alltimebest_holder = speedaward_holder;
1293 speedaward_alltimebest_uid = speedaward_uid;
1294 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1295 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1296 race_send_speedaward_alltimebest(MSG_ALL);
1303 xyspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y);
1304 if(self.weapon == WEP_VORTEX && WEP_CVAR(vortex, charge) && WEP_CVAR(vortex, charge_velocity_rate) && xyspeed > WEP_CVAR(vortex, charge_minspeed))
1306 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1307 xyspeed = min(xyspeed, WEP_CVAR(vortex, charge_maxspeed));
1308 f = (xyspeed - WEP_CVAR(vortex, charge_minspeed)) / (WEP_CVAR(vortex, charge_maxspeed) - WEP_CVAR(vortex, charge_minspeed));
1309 // add the extra charge
1310 self.vortex_charge = min(1, self.vortex_charge + WEP_CVAR(vortex, charge_velocity_rate) * f * frametime);
1313 if(self.flags & FL_ONGROUND)
1314 self.lastground = time;
1316 // conveyors: then break velocity again
1317 if(self.conveyor.state)
1318 self.velocity += self.conveyor.movedir;
1320 self.lastflags = self.flags;
1321 self.lastclassname = self.classname;