11 .float spectatorspeed;
13 .float multijump_count;
14 .float multijump_ready;
15 .float prevjumpbutton;
21 When you press the jump key
24 void PlayerJump (void)
26 if(g_freezetag && self.freezetag_frozen)
27 return; // no jumping in freezetag when frozen
35 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
36 if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
40 mjumpheight = cvar("sv_jumpvelocity");
41 if (self.waterlevel >= WATERLEVEL_SWIMMING)
43 if (self.watertype == CONTENT_WATER)
44 self.velocity_z = 200;
45 else if (self.watertype == CONTENT_SLIME)
53 if (cvar("g_multijump"))
55 if (self.prevjumpbutton == FALSE && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair
56 self.multijump_ready = TRUE; // this is necessary to check that we released the jump button and pressed it again
58 self.multijump_ready = FALSE;
61 if(!doublejump && self.multijump_ready && self.multijump_count < cvar("g_multijump") && self.velocity_z > cvar("g_multijump_speed"))
63 // doublejump = FALSE; // checked above in the if
64 if (cvar("g_multijump") > 0)
66 if (cvar("g_multijump_add") == 0) // in this case we make the z velocity == jumpvelocity
68 if (self.velocity_z < mjumpheight)
79 if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
82 vector wishvel, wishdir;
85 vlen(vec2(self.velocity)), // current xy speed
86 vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
88 makevectors(self.v_angle_y * '0 1 0');
89 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
90 wishdir = normalize(wishvel);
92 self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
93 self.velocity_y = wishdir_y * curspeed;
94 // keep velocity_z unchanged!
96 self.multijump_count += 1;
99 self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump
103 if (!(self.flags & FL_ONGROUND))
107 if (!(self.flags & FL_JUMPRELEASED))
110 if(self.health <= g_bloodloss)
113 // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
114 // velocity bounds. Final velocity is bound between (jumpheight *
115 // min + jumpheight) and (jumpheight * max + jumpheight);
117 if(cvar_string("sv_jumpspeedcap_min") != "")
121 minjumpspeed = mjumpheight * cvar("sv_jumpspeedcap_min");
123 if (self.velocity_z < minjumpspeed)
124 mjumpheight += minjumpspeed - self.velocity_z;
127 if(cvar_string("sv_jumpspeedcap_max") != "")
129 // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
130 tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
132 if(!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && cvar("sv_jumpspeedcap_max_disable_on_ramps")))
136 maxjumpspeed = mjumpheight * cvar("sv_jumpspeedcap_max");
138 if (self.velocity_z > maxjumpspeed)
139 mjumpheight -= self.velocity_z - maxjumpspeed;
143 if(!(self.lastflags & FL_ONGROUND))
145 if(cvar("speedmeter"))
146 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
147 if(self.lastground < time - 0.3)
149 self.velocity_x *= (1 - cvar("sv_friction_on_land"));
150 self.velocity_y *= (1 - cvar("sv_friction_on_land"));
152 if(self.jumppadcount > 1)
153 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
154 self.jumppadcount = 0;
157 self.velocity_z = self.velocity_z + mjumpheight;
158 self.oldvelocity_z = self.velocity_z;
160 self.flags &~= FL_ONGROUND;
161 self.flags &~= FL_JUMPRELEASED;
164 setanim(self, self.anim_duckjump, FALSE, TRUE, TRUE);
166 setanim(self, self.anim_jump, FALSE, TRUE, TRUE);
169 PlayerSound(playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
171 self.restart_jump = -1; // restart jump anim next time
172 // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
175 void CheckWaterJump()
177 local vector start, end;
179 // check for a jump-out-of-water
180 makevectors (self.angles);
182 start_z = start_z + 8;
184 normalize(v_forward);
185 end = start + v_forward*24;
186 traceline (start, end, TRUE, self);
187 if (trace_fraction < 1)
189 start_z = start_z + self.maxs_z - 8;
190 end = start + v_forward*24;
191 self.movedir = trace_plane_normal * -50;
192 traceline (start, end, TRUE, self);
193 if (trace_fraction == 1)
194 { // open at eye level
195 self.flags |= FL_WATERJUMP;
196 self.velocity_z = 225;
197 self.flags &~= FL_JUMPRELEASED;
198 self.teleport_time = time + 2; // safety net
204 float racecar_angle(float forward, float down)
206 float ret, angle_mult;
214 ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
216 angle_mult = forward / (800 + forward);
219 return ret * angle_mult + 360 * (1 - angle_mult);
221 return ret * angle_mult;
224 void RaceCarPhysics()
226 // using this move type for "big rigs"
227 // the engine does not push the entity!
229 float accel, steer, f, myspeed, steerfactor;
230 vector angles_save, rigvel;
232 angles_save = self.angles;
233 accel = bound(-1, self.movement_x / self.stat_sv_maxspeed, 1);
234 steer = bound(-1, self.movement_y / self.stat_sv_maxspeed, 1);
236 if(g_bugrigs_reverse_speeding)
240 // back accel is DIGITAL
241 // to prevent speedhack
251 makevectors(self.angles); // new forward direction!
253 if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
255 float upspeed, accelfactor;
257 myspeed = self.velocity * v_forward;
258 upspeed = self.velocity * v_up;
260 // responsiveness factor for steering and acceleration
261 f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
262 //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
264 if(myspeed < 0 && g_bugrigs_reverse_spinning)
265 steerfactor = -myspeed * g_bugrigs_steer;
267 steerfactor = -myspeed * f * g_bugrigs_steer;
269 if(myspeed < 0 && g_bugrigs_reverse_speeding)
270 accelfactor = g_bugrigs_accel;
272 accelfactor = f * g_bugrigs_accel;
273 //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
279 myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
283 if(!g_bugrigs_reverse_speeding)
284 myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
291 myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
295 if(g_bugrigs_reverse_stopping)
298 myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
301 // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
302 //MAXIMA: friction(v) := g_bugrigs_friction_floor;
304 self.angles_y += steer * frametime * steerfactor; // apply steering
305 makevectors(self.angles); // new forward direction!
307 myspeed += accel * accelfactor * frametime;
309 rigvel = myspeed * v_forward + '0 0 1' * upspeed;
313 myspeed = vlen(self.velocity);
315 // responsiveness factor for steering and acceleration
316 f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
317 steerfactor = -myspeed * f;
318 self.angles_y += steer * frametime * steerfactor; // apply steering
320 rigvel = self.velocity;
321 makevectors(self.angles); // new forward direction!
324 rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
325 //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
326 //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
327 //MAXIMA: solve(total_acceleration(v) = 0, v);
329 if(g_bugrigs_planar_movement)
331 vector rigvel_xy, neworigin, up;
334 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
335 rigvel_xy = vec2(rigvel);
337 if(g_bugrigs_planar_movement_car_jumping && !g_touchexplode) // touchexplode is a better way to handle collisions
340 mt = MOVE_NOMONSTERS;
342 tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
343 up = trace_endpos - self.origin;
345 // BUG RIGS: align the move to the surface instead of doing collision testing
347 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
350 tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
352 if(trace_fraction < 0.5)
355 neworigin = self.origin;
358 neworigin = trace_endpos;
360 if(trace_fraction < 1)
362 // now set angles_x so that the car points parallel to the surface
363 self.angles = vectoangles(
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)
370 self.flags |= FL_ONGROUND;
374 // now set angles_x so that the car points forward, but is tilted in velocity direction
375 self.flags &~= FL_ONGROUND;
378 self.velocity = (neworigin - self.origin) * (1.0 / frametime);
379 self.movetype = MOVETYPE_NOCLIP;
383 rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
384 self.velocity = rigvel;
385 self.movetype = MOVETYPE_FLY;
389 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
390 if(trace_fraction != 1)
392 self.angles = vectoangles2(
393 '1 0 0' * v_forward_x * trace_plane_normal_z
395 '0 1 0' * v_forward_y * trace_plane_normal_z
397 '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
405 vel_local_x = v_forward * self.velocity;
406 vel_local_y = v_right * self.velocity;
407 vel_local_z = v_up * self.velocity;
409 self.angles_x = racecar_angle(vel_local_x, vel_local_z);
410 self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
414 vector vf1, vu1, smoothangles;
415 makevectors(self.angles);
416 f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
421 makevectors(angles_save);
422 vf1 = vf1 + v_forward * (1 - f);
423 vu1 = vu1 + v_up * (1 - f);
424 smoothangles = vectoangles2(vf1, vu1);
425 self.angles_x = -smoothangles_x;
426 self.angles_z = smoothangles_z;
429 float IsMoveInDirection(vector mv, float angle) // key mix factor
431 if(mv_x == 0 && mv_y == 0)
432 return 0; // avoid division by zero
433 angle -= RAD2DEG * atan2(mv_y, mv_x);
434 angle = remainder(angle, 360) / 45;
439 return 1 - fabs(angle);
442 float GeomLerp(float a, float lerp, float b)
458 return a * pow(fabs(b / a), lerp);
461 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
463 float zspeed, xyspeed, dot, k;
466 // this doesn't play well with analog input
467 if(self.movement_x == 0 || self.movement_y != 0)
468 return; // can't control movement if not moving forward or backward
471 k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
476 k *= bound(0, wishspeed / autocvar_sv_maxairspeed, 1);
478 zspeed = self.velocity_z;
480 xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
482 dot = self.velocity * wishdir;
484 if(dot > 0) // we can't change direction while slowing down
486 k *= pow(dot, autocvar_sv_aircontrol_power)*frametime;
487 xyspeed = max(0, xyspeed - autocvar_sv_aircontrol_penalty * sqrt(max(0, 1 - dot*dot)) * k/32);
488 k *= autocvar_sv_aircontrol;
489 self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
492 self.velocity = self.velocity * xyspeed;
493 self.velocity_z = zspeed;
496 float AdjustAirAccelQW(float accelqw, float factor)
498 return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
501 // example config for alternate speed clamping:
502 // sv_airaccel_qw 0.8
503 // sv_airaccel_sideways_friction 0
504 // prvm_globalset server speedclamp_mode 1
506 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float sidefric, float speedlimit)
514 float vel_xy_current;
515 float vel_xy_backward, vel_xy_forward;
518 speedclamp = (accelqw < 0);
522 if(cvar("sv_gameplayfix_q2airaccelerate"))
523 wishspeed0 = wishspeed;
525 vel_straight = self.velocity * wishdir;
526 vel_z = self.velocity_z;
527 vel_xy = vec2(self.velocity);
528 vel_perpend = vel_xy - vel_straight * wishdir;
530 step = accel * frametime * wishspeed0;
532 vel_xy_current = vlen(vel_xy);
534 accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
535 vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
536 vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
537 if(vel_xy_backward < 0)
538 vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
540 vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
542 if(sidefric < 0 && (vel_perpend*vel_perpend))
543 // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
546 f = max(0, 1 + frametime * wishspeed * sidefric);
547 fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
548 // this cannot be > 1
550 vel_perpend = vel_perpend * max(0, f);
553 fminimum = sqrt(fminimum);
554 vel_perpend = vel_perpend * max(fminimum, f);
558 vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
560 vel_xy = vel_straight * wishdir + vel_perpend;
564 // ensure we don't get too fast or decelerate faster than we should
565 vel_xy_current = min(vlen(vel_xy), vel_xy_forward);
566 if(vel_xy_current > 0) // prevent division by zero
567 vel_xy = normalize(vel_xy) * vel_xy_current;
570 self.velocity = vel_xy + vel_z * '0 0 1';
573 void PM_AirAccelerate(vector wishdir, float wishspeed)
575 vector curvel, wishvel, acceldir, curdir;
576 float addspeed, accelspeed, curspeed, f;
582 curvel = self.velocity;
584 curspeed = vlen(curvel);
586 if(wishspeed > curspeed * 1.01)
588 wishspeed = min(wishspeed, curspeed + autocvar_sv_warsowbunny_airforwardaccel * self.stat_sv_maxspeed * frametime);
592 f = max(0, (autocvar_sv_warsowbunny_topspeed - curspeed) / (autocvar_sv_warsowbunny_topspeed - self.stat_sv_maxspeed));
593 wishspeed = max(curspeed, self.stat_sv_maxspeed) + autocvar_sv_warsowbunny_accel * f * self.stat_sv_maxspeed * frametime;
595 wishvel = wishdir * wishspeed;
596 acceldir = wishvel - curvel;
597 addspeed = vlen(acceldir);
598 acceldir = normalize(acceldir);
600 accelspeed = min(addspeed, autocvar_sv_warsowbunny_turnaccel * self.stat_sv_maxspeed * frametime);
602 if(autocvar_sv_warsowbunny_backtosideratio < 1)
604 curdir = normalize(curvel);
605 dot = acceldir * curdir;
607 acceldir = acceldir - (1 - autocvar_sv_warsowbunny_backtosideratio) * dot * curdir;
610 self.velocity += accelspeed * acceldir;
613 .vector movement_old;
616 .string lastclassname;
618 .float() PlayerPhysplug;
620 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
621 .float specialcommand_pos;
622 void SpecialCommand()
627 if(!CheatImpulse(99))
628 print("A hollow voice says \"Plugh\".\n");
632 float speedaward_speed;
633 string speedaward_holder;
634 string speedaward_uid;
635 void race_send_speedaward(float msg)
637 // send the best speed of the round
638 WriteByte(msg, SVC_TEMPENTITY);
639 WriteByte(msg, TE_CSQC_RACE);
640 WriteByte(msg, RACE_NET_SPEED_AWARD);
641 WriteInt24_t(msg, floor(speedaward_speed+0.5));
642 WriteString(msg, speedaward_holder);
645 float speedaward_alltimebest;
646 string speedaward_alltimebest_holder;
647 string speedaward_alltimebest_uid;
648 void race_send_speedaward_alltimebest(float msg)
650 // send the best speed
651 WriteByte(msg, SVC_TEMPENTITY);
652 WriteByte(msg, TE_CSQC_RACE);
653 WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
654 WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
655 WriteString(msg, speedaward_alltimebest_holder);
658 string GetMapname(void);
659 float speedaward_lastupdate;
660 float speedaward_lastsent;
661 void SV_PlayerPhysics()
663 local vector wishvel, wishdir, v;
664 local float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
667 float not_allowed_to_move;
671 if(g_minstagib && (self.items & IT_INVINCIBLE))
672 maxspd_mod *= cvar("g_minstagib_speed_highspeed");
675 maxspd_mod *= cvar("g_nexball_basketball_carrier_highspeed");
677 maxspd_mod *= cvar("g_keepaway_ballcarrier_highspeed");
681 if(self.runes & RUNE_SPEED)
683 if(self.runes & CURSE_SLOW)
684 maxspd_mod *= cvar("g_balance_rune_speed_combo_highspeed");
686 maxspd_mod *= cvar("g_balance_rune_speed_highspeed");
688 else if(self.runes & CURSE_SLOW)
690 maxspd_mod *= cvar("g_balance_curse_slow_highspeed");
693 maxspd_mod *= autocvar_g_movement_highspeed;
695 // fix physics stats for g_movement_highspeed
696 self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
697 if(autocvar_sv_airstrafeaccel_qw)
698 self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
700 self.stat_sv_airstrafeaccel_qw = 0;
701 self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
702 self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
704 if(self.PlayerPhysplug)
705 if(self.PlayerPhysplug())
708 self.race_movetime_frac += frametime;
709 f = floor(self.race_movetime_frac);
710 self.race_movetime_frac -= f;
711 self.race_movetime_count += f;
712 self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
716 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);
720 else if(buttons == 1)
722 else if(buttons == 2)
724 else if(buttons == 128)
726 else if(buttons == 256)
728 else if(buttons == 512)
730 else if(buttons == 1024)
735 if(c == substring(specialcommand, self.specialcommand_pos, 1))
737 self.specialcommand_pos += 1;
738 if(self.specialcommand_pos >= strlen(specialcommand))
740 self.specialcommand_pos = 0;
745 else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
746 self.specialcommand_pos = 0;
748 if(!sv_maxidle_spectatorsareidle || self.movetype == MOVETYPE_WALK)
750 if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
751 self.parm_idlesince = time;
753 buttons_prev = self.buttons_old;
754 self.buttons_old = buttons;
755 self.movement_old = self.movement;
756 self.v_angle_old = self.v_angle;
758 if(time < self.nickspamtime)
759 if(self.nickspamcount >= cvar("g_nick_flood_penalty_yellow"))
761 // slight annoyance for nick change scripts
762 self.movement = -1 * self.movement;
763 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
765 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!
767 self.angles_x = random() * 360;
768 self.angles_y = random() * 360;
769 // at least I'm not forcing retardedview by also assigning to angles_z
774 if (self.punchangle != '0 0 0')
776 f = vlen(self.punchangle) - 10 * frametime;
778 self.punchangle = normalize(self.punchangle) * f;
780 self.punchangle = '0 0 0';
783 if (self.punchvector != '0 0 0')
785 f = vlen(self.punchvector) - 30 * frametime;
787 self.punchvector = normalize(self.punchvector) * f;
789 self.punchvector = '0 0 0';
792 if (clienttype(self) == CLIENTTYPE_BOT)
794 if(playerdemo_read())
799 MUTATOR_CALLHOOK(PlayerPhysics);
801 self.items &~= IT_USING_JETPACK;
803 if(self.classname == "player")
805 if(self.race_penalty)
806 if(time > self.race_penalty)
807 self.race_penalty = 0;
809 not_allowed_to_move = 0;
810 if(self.race_penalty)
811 not_allowed_to_move = 1;
812 if(!cvar("sv_ready_restart_after_countdown"))
813 if(time < game_starttime)
814 not_allowed_to_move = 1;
816 if(not_allowed_to_move)
818 self.velocity = '0 0 0';
819 self.movetype = MOVETYPE_NONE;
820 self.disableclientprediction = 2;
822 else if(self.disableclientprediction == 2)
824 if(self.movetype == MOVETYPE_NONE)
825 self.movetype = MOVETYPE_WALK;
826 self.disableclientprediction = 0;
830 if (self.movetype == MOVETYPE_NONE)
837 swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
840 if(self.classname != "player")
842 maxspd_mod = cvar("sv_spectator_speed_multiplier");
843 if(!self.spectatorspeed)
844 self.spectatorspeed = maxspd_mod;
845 if(self.impulse && self.impulse <= 19)
847 if(self.lastclassname != "player")
849 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
850 self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
851 else if(self.impulse == 11)
852 self.spectatorspeed = maxspd_mod;
853 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
854 self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
855 else if(self.impulse >= 1 && self.impulse <= 9)
856 self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
857 } // otherwise just clear
860 maxspd_mod = self.spectatorspeed;
863 spd = max(self.stat_sv_maxspeed, autocvar_sv_maxairspeed) * maxspd_mod * swampspd_mod;
864 if(self.speed != spd)
868 stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
869 stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
870 stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
871 stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
874 maxspd_mod *= swampspd_mod; // only one common speed modder please!
877 // if dead, behave differently
881 if (!self.fixangle && !g_bugrigs)
884 self.angles_y = self.v_angle_y;
888 if(self.flags & FL_ONGROUND)
893 if(self.waterlevel < WATERLEVEL_SWIMMING)
894 if(time >= self.ladder_time)
897 self.nextstep = time + 0.3 + random() * 0.1;
898 trace_dphitq3surfaceflags = 0;
899 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
900 if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)
902 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
903 GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
905 GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);
913 if(self.classname == "player")
915 if(self.flags & FL_ONGROUND)
917 if (cvar("g_multijump") > 0)
918 self.multijump_count = 0;
920 self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller
923 if (self.BUTTON_JUMP)
926 self.flags |= FL_JUMPRELEASED;
928 if (self.waterlevel == WATERLEVEL_SWIMMING)
930 self.prevjumpbutton = self.BUTTON_JUMP;
933 if (self.flags & FL_WATERJUMP )
935 self.velocity_x = self.movedir_x;
936 self.velocity_y = self.movedir_y;
937 if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
939 self.flags &~= FL_WATERJUMP;
940 self.teleport_time = 0;
943 else if (g_bugrigs && self.classname == "player")
947 else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY)
949 // noclipping or flying
950 self.flags &~= FL_ONGROUND;
952 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
953 makevectors(self.v_angle);
954 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
955 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
957 wishdir = normalize(wishvel);
958 wishspeed = vlen(wishvel);
959 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
960 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
961 if (time >= self.teleport_time)
962 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0);
964 else if (self.waterlevel >= WATERLEVEL_SWIMMING)
967 self.flags &~= FL_ONGROUND;
969 makevectors(self.v_angle);
970 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
971 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
972 if (wishvel == '0 0 0')
973 wishvel = '0 0 -60'; // drift towards bottom
975 wishdir = normalize(wishvel);
976 wishspeed = vlen(wishvel);
977 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
978 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
979 wishspeed = wishspeed * 0.7;
982 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
984 // water acceleration
985 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0);
987 else if (time < self.ladder_time)
989 // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
990 self.flags &~= FL_ONGROUND;
992 self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
993 makevectors(self.v_angle);
994 //wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
995 wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
997 self.velocity_z = self.velocity_z + self.gravity * autocvar_sv_gravity * frametime;
999 self.velocity_z = self.velocity_z + autocvar_sv_gravity * frametime;
1000 if (self.ladder_entity.classname == "func_water")
1003 if (f > self.ladder_entity.speed)
1004 wishvel = wishvel * (self.ladder_entity.speed / f);
1006 self.watertype = self.ladder_entity.skin;
1007 f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
1008 if ((self.origin_z + self.view_ofs_z) < f)
1009 self.waterlevel = WATERLEVEL_SUBMERGED;
1010 else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
1011 self.waterlevel = WATERLEVEL_SWIMMING;
1012 else if ((self.origin_z + self.mins_z + 1) < f)
1013 self.waterlevel = WATERLEVEL_WETFEET;
1016 self.waterlevel = WATERLEVEL_NONE;
1017 self.watertype = CONTENT_EMPTY;
1021 wishdir = normalize(wishvel);
1022 wishspeed = vlen(wishvel);
1023 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1024 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1025 if (time >= self.teleport_time)
1027 // water acceleration
1028 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0);
1031 else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO))
1033 //makevectors(self.v_angle_y * '0 1 0');
1034 makevectors(self.v_angle);
1035 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1036 // add remaining speed as Z component
1037 maxairspd = autocvar_sv_maxairspeed*max(1, maxspd_mod);
1038 // fix speedhacks :P
1039 wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
1040 // add the unused velocity as up component
1043 // if(self.BUTTON_JUMP)
1044 wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
1046 // it is now normalized, so...
1047 float a_side, a_up, a_add, a_diff;
1048 a_side = cvar("g_jetpack_acceleration_side");
1049 a_up = cvar("g_jetpack_acceleration_up");
1050 a_add = cvar("g_jetpack_antigravity") * autocvar_sv_gravity;
1052 wishvel_x *= a_side;
1053 wishvel_y *= a_side;
1059 //////////////////////////////////////////////////////////////////////////////////////
1060 // finding the maximum over all vectors of above form
1061 // with wishvel having an absolute value of 1
1062 //////////////////////////////////////////////////////////////////////////////////////
1063 // we're finding the maximum over
1064 // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
1065 // for z in the range from -1 to 1
1066 //////////////////////////////////////////////////////////////////////////////////////
1067 // maximum is EITHER attained at the single extreme point:
1068 a_diff = a_side * a_side - a_up * a_up;
1071 f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
1072 if(f > -1 && f < 1) // can it be attained?
1074 best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
1075 //print("middle\n");
1078 // OR attained at z = 1:
1079 f = (a_up + a_add) * (a_up + a_add);
1085 // OR attained at z = -1:
1086 f = (a_up - a_add) * (a_up - a_add);
1090 //print("bottom\n");
1093 //////////////////////////////////////////////////////////////////////////////////////
1095 //print("best possible acceleration: ", ftos(best), "\n");
1098 fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / cvar("g_jetpack_maxspeed_side"), 1);
1099 if(wishvel_z - autocvar_sv_gravity > 0)
1100 fz = bound(0, 1 - self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1102 fz = bound(0, 1 + self.velocity_z / cvar("g_jetpack_maxspeed_up"), 1);
1105 fvel = vlen(wishvel);
1108 wishvel_z = (wishvel_z - autocvar_sv_gravity) * fz + autocvar_sv_gravity;
1110 fvel = min(1, vlen(wishvel) / best);
1111 if(cvar("g_jetpack_fuel") && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
1112 f = min(1, self.ammo_fuel / (cvar("g_jetpack_fuel") * frametime * fvel));
1116 //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
1118 if (f > 0 && wishvel != '0 0 0')
1120 self.velocity = self.velocity + wishvel * f * frametime;
1121 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1122 self.ammo_fuel -= cvar("g_jetpack_fuel") * frametime * fvel * f;
1123 self.flags &~= FL_ONGROUND;
1124 self.items |= IT_USING_JETPACK;
1126 // jetpack also inhibits health regeneration, but only for 1 second
1127 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1130 else if (self.flags & FL_ONGROUND)
1132 // we get here if we ran out of ammo
1133 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1134 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1137 makevectors(self.v_angle_y * '0 1 0');
1138 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1140 if(!(self.lastflags & FL_ONGROUND))
1142 if(cvar("speedmeter"))
1143 dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
1144 if(self.lastground < time - 0.3)
1145 self.velocity = self.velocity * (1 - cvar("sv_friction_on_land"));
1146 if(self.jumppadcount > 1)
1147 dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
1148 self.jumppadcount = 0;
1151 #ifdef LETS_TEST_FTEQCC
1152 if(self.velocity_x || self.velocity_y)
1170 if (f < autocvar_sv_stopspeed)
1171 f = 1 - frametime * (autocvar_sv_stopspeed / f) * autocvar_sv_friction;
1173 f = 1 - frametime * autocvar_sv_friction;
1175 self.velocity = self.velocity * f;
1177 self.velocity = '0 0 0';
1181 wishdir = normalize(wishvel);
1182 wishspeed = vlen(wishvel);
1183 if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
1184 wishspeed = self.stat_sv_maxspeed*maxspd_mod;
1186 wishspeed = wishspeed * 0.5;
1187 if (time >= self.teleport_time)
1188 PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0);
1193 // we get here if we ran out of ammo
1194 if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32))
1195 sprint(self, "You don't have any fuel for the ^2Jetpack\n");
1199 maxairspd = autocvar_sv_maxairspeed*maxspd_mod;
1200 airaccel = autocvar_sv_airaccelerate*maxspd_mod;
1204 maxairspd = autocvar_sv_maxairspeed;
1205 airaccel = autocvar_sv_airaccelerate;
1208 makevectors(self.v_angle_y * '0 1 0');
1209 wishvel = v_forward * self.movement_x + v_right * self.movement_y;
1211 wishdir = normalize(wishvel);
1212 wishspeed = wishspeed0 = vlen(wishvel);
1213 if (wishspeed0 > self.stat_sv_maxspeed*maxspd_mod)
1214 wishspeed0 = self.stat_sv_maxspeed*maxspd_mod;
1215 if (wishspeed > maxairspd)
1216 wishspeed = maxairspd;
1218 wishspeed = wishspeed * 0.5;
1219 if (time >= self.teleport_time)
1226 airaccelqw = self.stat_sv_airaccel_qw;
1227 accelerating = (self.velocity * wishdir > 0);
1228 wishspeed2 = wishspeed;
1231 if(autocvar_sv_airstopaccelerate)
1234 curdir = self.velocity;
1236 curdir = normalize(curdir);
1237 airaccel = airaccel + (autocvar_sv_airstopaccelerate*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
1239 // note that for straight forward jumping:
1240 // step = accel * frametime * wishspeed0;
1241 // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
1243 // dv/dt = accel * maxspeed (when slow)
1244 // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
1245 // log dv/dt = logaccel + logmaxspeed (when slow)
1246 // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
1247 strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
1248 if(autocvar_sv_maxairstrafespeed)
1249 wishspeed = min(wishspeed, GeomLerp(autocvar_sv_maxairspeed*maxspd_mod, strafity, autocvar_sv_maxairstrafespeed*maxspd_mod));
1250 if(autocvar_sv_airstrafeaccelerate)
1251 airaccel = GeomLerp(airaccel, strafity, autocvar_sv_airstrafeaccelerate*maxspd_mod);
1252 if(self.stat_sv_airstrafeaccel_qw)
1253 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));
1256 if(autocvar_sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
1257 PM_AirAccelerate(wishdir, wishspeed);
1259 PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, autocvar_sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw);
1261 if(autocvar_sv_aircontrol)
1262 CPM_PM_Aircontrol(wishdir, wishspeed2);
1266 if((g_cts || g_race) && self.classname != "observer") {
1267 if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
1268 speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
1269 speedaward_holder = self.netname;
1270 speedaward_uid = self.crypto_idfp;
1271 speedaward_lastupdate = time;
1273 if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
1279 race_send_speedaward(MSG_ALL);
1280 speedaward_lastsent = speedaward_speed;
1281 if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") {
1282 speedaward_alltimebest = speedaward_speed;
1283 speedaward_alltimebest_holder = speedaward_holder;
1284 speedaward_alltimebest_uid = speedaward_uid;
1285 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
1286 db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
1287 race_send_speedaward_alltimebest(MSG_ALL);
1293 xyspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y);
1294 if(self.weapon == WEP_NEX && cvar("g_balance_nex_charge") && cvar("g_balance_nex_charge_velocity_rate") && xyspeed > cvar("g_balance_nex_charge_minspeed"))
1296 // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
1297 xyspeed = min(xyspeed, cvar("g_balance_nex_charge_maxspeed"));
1298 f = (xyspeed - cvar("g_balance_nex_charge_minspeed")) / (cvar("g_balance_nex_charge_maxspeed") - cvar("g_balance_nex_charge_minspeed"));
1299 // add the extra charge
1300 self.nex_charge = min(1, self.nex_charge + cvar("g_balance_nex_charge_velocity_rate") * f * frametime);
1303 if(self.flags & FL_ONGROUND)
1304 self.lastground = time;
1306 self.lastflags = self.flags;
1307 self.lastclassname = self.classname;