PlayerJump
When you press the jump key
+returns true if handled
=============
*/
-void PlayerJump (void)
+float PlayerJump (void)
{
if(self.frozen)
- return; // no jumping in freezetag when frozen
+ return true; // no jumping in freezetag when frozen
if(self.player_blocked)
- return; // no jumping while blocked
+ return true; // no jumping while blocked
- float doublejump = FALSE;
+ float doublejump = false;
float mjumpheight = autocvar_sv_jumpvelocity;
player_multijump = doublejump;
player_jumpheight = mjumpheight;
if(MUTATOR_CALLHOOK(PlayerJump))
- return;
+ return true;
doublejump = player_multijump;
mjumpheight = player_jumpheight;
if (autocvar_sv_doublejump)
{
tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
- if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
+ if (trace_fraction < 1 && trace_plane_normal.z > 0.7)
{
- doublejump = TRUE;
+ doublejump = true;
// we MUST clip velocity here!
float f;
if (self.waterlevel >= WATERLEVEL_SWIMMING)
{
self.velocity_z = self.stat_sv_maxspeed * 0.7;
- return;
+ return true;
}
if (!doublejump)
if (!(self.flags & FL_ONGROUND))
- return;
+ return !(self.flags & FL_JUMPRELEASED);
if(self.cvar_cl_movement_track_canjump)
if (!(self.flags & FL_JUMPRELEASED))
- return;
+ return true;
// sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
// velocity bounds. Final velocity is bound between (jumpheight *
minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min);
- if (self.velocity_z < minjumpspeed)
- mjumpheight += minjumpspeed - self.velocity_z;
+ if (self.velocity.z < minjumpspeed)
+ mjumpheight += minjumpspeed - self.velocity.z;
}
if(autocvar_sv_jumpspeedcap_max != "")
// don't do jump speedcaps on ramps to preserve old xonotic ramjump style
tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
- if(!(trace_fraction < 1 && trace_plane_normal_z < 0.98 && autocvar_sv_jumpspeedcap_max_disable_on_ramps))
+ if(!(trace_fraction < 1 && trace_plane_normal.z < 0.98 && autocvar_sv_jumpspeedcap_max_disable_on_ramps))
{
float maxjumpspeed;
maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max);
- if (self.velocity_z > maxjumpspeed)
- mjumpheight -= self.velocity_z - maxjumpspeed;
+ if (self.velocity.z > maxjumpspeed)
+ mjumpheight -= self.velocity.z - maxjumpspeed;
}
}
self.jumppadcount = 0;
}
- self.velocity_z = self.velocity_z + mjumpheight;
- self.oldvelocity_z = self.velocity_z;
+ self.velocity_z = self.velocity.z + mjumpheight;
+ self.oldvelocity_z = self.velocity.z;
self.flags &= ~FL_ONGROUND;
self.flags &= ~FL_JUMPRELEASED;
- animdecide_setaction(self, ANIMACTION_JUMP, TRUE);
+ animdecide_setaction(self, ANIMACTION_JUMP, true);
if(autocvar_g_jump_grunt)
PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
self.restart_jump = -1; // restart jump anim next time
// value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)
+ return true;
}
void CheckWaterJump()
{
// check for a jump-out-of-water
makevectors (self.angles);
start = self.origin;
- start_z = start_z + 8;
+ start_z = start.z + 8;
v_forward_z = 0;
normalize(v_forward);
end = start + v_forward*24;
- traceline (start, end, TRUE, self);
+ traceline (start, end, true, self);
if (trace_fraction < 1)
{ // solid at waist
- start_z = start_z + self.maxs_z - 8;
+ start_z = start.z + self.maxs.z - 8;
end = start + v_forward*24;
self.movedir = trace_plane_normal * -50;
- traceline (start, end, TRUE, self);
+ traceline (start, end, true, self);
if (trace_fraction == 1)
{ // open at eye level
self.flags |= FL_WATERJUMP;
}
}
}
+
+.float jetpack_stopped;
+// Hack: shouldn't need to know about this
+.float multijump_count;
void CheckPlayerJump()
{
- if (self.BUTTON_JUMP)
- PlayerJump ();
+ float was_flying = self.items & IT_USING_JETPACK;
+
+ if (self.cvar_cl_jetpack_jump < 2)
+ self.items &= ~IT_USING_JETPACK;
+
+ if (self.BUTTON_JUMP || self.BUTTON_JETPACK)
+ {
+ float air_jump = !PlayerJump() || self.multijump_count > 0; // PlayerJump() has important side effects
+ float activate = self.cvar_cl_jetpack_jump && air_jump && self.BUTTON_JUMP || self.BUTTON_JETPACK;
+ float has_fuel = !autocvar_g_jetpack_fuel || self.ammo_fuel || self.items & IT_UNLIMITED_WEAPON_AMMO;
+ if (!(self.items & IT_JETPACK)) { }
+ else if (self.jetpack_stopped) { }
+ else if (!has_fuel)
+ {
+ if (was_flying) // TODO: ran out of fuel message
+ Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL);
+ else if (activate)
+ Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL);
+ self.jetpack_stopped = true;
+ self.items &= ~IT_USING_JETPACK;
+ }
+ else if (activate && !self.frozen)
+ self.items |= IT_USING_JETPACK;
+ }
else
+ {
+ self.jetpack_stopped = false;
+ self.items &= ~IT_USING_JETPACK;
+ }
+ if (!self.BUTTON_JUMP)
self.flags |= FL_JUMPRELEASED;
if (self.waterlevel == WATERLEVEL_SWIMMING)
vector angles_save, rigvel;
angles_save = self.angles;
- accel = bound(-1, self.movement_x / self.stat_sv_maxspeed, 1);
- steer = bound(-1, self.movement_y / self.stat_sv_maxspeed, 1);
+ accel = bound(-1, self.movement.x / self.stat_sv_maxspeed, 1);
+ steer = bound(-1, self.movement.y / self.stat_sv_maxspeed, 1);
if(g_bugrigs_reverse_speeding)
{
vector rigvel_xy, neworigin, up;
float mt;
- rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
+ rigvel.z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
rigvel_xy = vec2(rigvel);
if(g_bugrigs_planar_movement_car_jumping)
tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * frametime, mt, self);
// align to surface
- tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * frametime, mt, self);
+ tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel.z * frametime, mt, self);
if(trace_fraction < 0.5)
{
{
// now set angles_x so that the car points parallel to the surface
self.angles = vectoangles(
- '1 0 0' * v_forward_x * trace_plane_normal_z
+ '1 0 0' * v_forward.x * trace_plane_normal.z
+
- '0 1 0' * v_forward_y * trace_plane_normal_z
+ '0 1 0' * v_forward.y * trace_plane_normal.z
+
- '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
+ '0 0 1' * -(v_forward.x * trace_plane_normal.x + v_forward.y * trace_plane_normal.y)
);
self.flags |= FL_ONGROUND;
}
}
else
{
- rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
+ rigvel.z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
self.velocity = rigvel;
self.movetype = MOVETYPE_FLY;
}
if(trace_fraction != 1)
{
self.angles = vectoangles2(
- '1 0 0' * v_forward_x * trace_plane_normal_z
+ '1 0 0' * v_forward.x * trace_plane_normal.z
+
- '0 1 0' * v_forward_y * trace_plane_normal_z
+ '0 1 0' * v_forward.y * trace_plane_normal.z
+
- '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
+ '0 0 1' * -(v_forward.x * trace_plane_normal.x + v_forward.y * trace_plane_normal.y),
trace_plane_normal
);
}
vel_local_y = v_right * self.velocity;
vel_local_z = v_up * self.velocity;
- self.angles_x = racecar_angle(vel_local_x, vel_local_z);
- self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
+ self.angles_x = racecar_angle(vel_local.x, vel_local.z);
+ self.angles_z = racecar_angle(-vel_local.y, vel_local.z);
}
// smooth the angles
vf1 = vf1 + v_forward * (1 - f);
vu1 = vu1 + v_up * (1 - f);
smoothangles = vectoangles2(vf1, vu1);
- self.angles_x = -smoothangles_x;
- self.angles_z = smoothangles_z;
+ self.angles_x = -smoothangles.x;
+ self.angles_z = smoothangles.z;
}
float IsMoveInDirection(vector mv, float angle) // key mix factor
{
if(mv_x == 0 && mv_y == 0)
return 0; // avoid division by zero
- angle -= RAD2DEG * atan2(mv_y, mv_x);
+ angle -= RAD2DEG * atan2(mv.y, mv.x);
angle = remainder(angle, 360) / 45;
if(angle > 1)
return 0;
#if 0
// this doesn't play well with analog input
- if(self.movement_x == 0 || self.movement_y != 0)
+ if(self.movement_x == 0 || self.movement.y != 0)
return; // can't control movement if not moving forward or backward
k = 32;
#else
k *= bound(0, wishspeed / autocvar_sv_maxairspeed, 1);
- zspeed = self.velocity_z;
+ zspeed = self.velocity.z;
self.velocity_z = 0;
xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
{
float vel_straight;
- float vel_z;
+ float velZ;
vector vel_perpend;
float step;
wishspeed0 = wishspeed;
vel_straight = self.velocity * wishdir;
- vel_z = self.velocity_z;
+ velZ = self.velocity.z;
vel_xy = vec2(self.velocity);
vel_perpend = vel_xy - vel_straight * wishdir;
}
}
- self.velocity = vel_xy + vel_z * '0 0 1';
+ self.velocity = vel_xy + velZ * '0 0 1';
}
void PM_AirAccelerate(vector wishdir, float wishspeed)
anticheat_physics();
- 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);
+ 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);
if(!buttons)
c = "x";
self.angles_x = random() * 360;
self.angles_y = random() * 360;
// at least I'm not forcing retardedview by also assigning to angles_z
- self.fixangle = TRUE;
+ self.fixangle = true;
}
}
bot_think();
}
- self.items &= ~IT_USING_JETPACK;
-
if(IS_PLAYER(self))
{
if(self.race_penalty)
not_allowed_to_move = 0;
if(self.race_penalty)
not_allowed_to_move = 1;
- if(!autocvar_sv_ready_restart_after_countdown)
if(time < game_starttime)
not_allowed_to_move = 1;
{
if(autocvar_sv_dodging_frozen && IS_REAL_CLIENT(self))
{
- self.movement_x = bound(-5, self.movement_x, 5);
- self.movement_y = bound(-5, self.movement_y, 5);
- self.movement_z = bound(-5, self.movement_z, 5);
+ self.movement_x = bound(-5, self.movement.x, 5);
+ self.movement_y = bound(-5, self.movement.y, 5);
+ self.movement_z = bound(-5, self.movement.z, 5);
}
else
self.movement = '0 0 0';
if (!self.fixangle && !g_bugrigs)
{
self.angles_x = 0;
- self.angles_y = self.v_angle_y;
+ self.angles_y = self.v_angle.y;
self.angles_z = 0;
}
if (self.flags & FL_WATERJUMP )
{
- self.velocity_x = self.movedir_x;
- self.velocity_y = self.movedir_y;
+ self.velocity_x = self.movedir.x;
+ self.velocity_y = self.movedir.y;
if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
{
self.flags &= ~FL_WATERJUMP;
self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
makevectors(self.v_angle);
//wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
- wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
+ wishvel = v_forward * self.movement.x + v_right * self.movement.y + '0 0 1' * self.movement.z;
// acceleration
wishdir = normalize(wishvel);
wishspeed = vlen(wishvel);
makevectors(self.v_angle);
//wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
- wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
+ wishvel = v_forward * self.movement.x + v_right * self.movement.y + '0 0 1' * self.movement.z;
if (wishvel == '0 0 0')
wishvel = '0 0 -60'; // drift towards bottom
self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
makevectors(self.v_angle);
//wishvel = v_forward * self.movement_x + v_right * self.movement_y + v_up * self.movement_z;
- wishvel = v_forward * self.movement_x + v_right * self.movement_y + '0 0 1' * self.movement_z;
+ wishvel = v_forward * self.movement.x + v_right * self.movement.y + '0 0 1' * self.movement.z;
self.velocity_z += g;
if (self.ladder_entity.classname == "func_water")
{
wishvel = wishvel * (self.ladder_entity.speed / f);
self.watertype = self.ladder_entity.skin;
- f = self.ladder_entity.origin_z + self.ladder_entity.maxs_z;
- if ((self.origin_z + self.view_ofs_z) < f)
+ f = self.ladder_entity.origin.z + self.ladder_entity.maxs.z;
+ if ((self.origin.z + self.view_ofs.z) < f)
self.waterlevel = WATERLEVEL_SUBMERGED;
- else if ((self.origin_z + (self.mins_z + self.maxs_z) * 0.5) < f)
+ else if ((self.origin.z + (self.mins.z + self.maxs.z) * 0.5) < f)
self.waterlevel = WATERLEVEL_SWIMMING;
- else if ((self.origin_z + self.mins_z + 1) < f)
+ else if ((self.origin.z + self.mins.z + 1) < f)
self.waterlevel = WATERLEVEL_WETFEET;
else
{
PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
}
}
- else if ((self.items & IT_JETPACK) && self.BUTTON_HOOK && (!autocvar_g_jetpack_fuel || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO) && !self.frozen)
+ else if (self.items & IT_USING_JETPACK)
{
//makevectors(self.v_angle_y * '0 1 0');
makevectors(self.v_angle);
- wishvel = v_forward * self.movement_x + v_right * self.movement_y;
+ wishvel = v_forward * self.movement.x + v_right * self.movement.y;
// add remaining speed as Z component
maxairspd = autocvar_sv_maxairspeed*max(1, maxspd_mod);
// fix speedhacks :P
a_up = autocvar_g_jetpack_acceleration_up;
a_add = autocvar_g_jetpack_antigravity * autocvar_sv_gravity;
- wishvel_x *= a_side;
- wishvel_y *= a_side;
- wishvel_z *= a_up;
- wishvel_z += a_add;
+ wishvel.x *= a_side;
+ wishvel.y *= a_side;
+ wishvel.z *= a_up;
+ wishvel.z += a_add;
float best;
best = 0;
//print("best possible acceleration: ", ftos(best), "\n");
float fxy, fz;
- fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / autocvar_g_jetpack_maxspeed_side, 1);
- if(wishvel_z - autocvar_sv_gravity > 0)
- fz = bound(0, 1 - self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
+ fxy = bound(0, 1 - (self.velocity * normalize(wishvel.x * '1 0 0' + wishvel.y * '0 1 0')) / autocvar_g_jetpack_maxspeed_side, 1);
+ if(wishvel.z - autocvar_sv_gravity > 0)
+ fz = bound(0, 1 - self.velocity.z / autocvar_g_jetpack_maxspeed_up, 1);
else
- fz = bound(0, 1 + self.velocity_z / autocvar_g_jetpack_maxspeed_up, 1);
+ fz = bound(0, 1 + self.velocity.z / autocvar_g_jetpack_maxspeed_up, 1);
- wishvel_x *= fxy;
- wishvel_y *= fxy;
- wishvel_z = (wishvel_z - autocvar_sv_gravity) * fz + autocvar_sv_gravity;
+ wishvel.x *= fxy;
+ wishvel.y *= fxy;
+ wishvel_z = (wishvel.z - autocvar_sv_gravity) * fz + autocvar_sv_gravity;
float fvel;
fvel = min(1, vlen(wishvel) / best);
{
// we get here if we ran out of ammo
if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
- sprint(self, "You don't have any fuel for the ^2Jetpack\n");
+ Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL);
// walking
- makevectors(self.v_angle_y * '0 1 0');
- wishvel = v_forward * self.movement_x + v_right * self.movement_y;
+ makevectors(self.v_angle.y * '0 1 0');
+ wishvel = v_forward * self.movement.x + v_right * self.movement.y;
if(!(self.lastflags & FL_ONGROUND))
{
float wishspeed0;
// we get here if we ran out of ammo
if((self.items & IT_JETPACK) && self.BUTTON_HOOK && !(buttons_prev & 32) && self.ammo_fuel < 0.01)
- sprint(self, "You don't have any fuel for the ^2Jetpack\n");
+ Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL);
if(maxspd_mod < 1)
{
airaccel = autocvar_sv_airaccelerate;
}
// airborn
- makevectors(self.v_angle_y * '0 1 0');
- wishvel = v_forward * self.movement_x + v_right * self.movement_y;
+ makevectors(self.v_angle.y * '0 1 0');
+ wishvel = v_forward * self.movement.x + v_right * self.movement.y;
// acceleration
wishdir = normalize(wishvel);
wishspeed = wishspeed0 = vlen(wishvel);
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));
// !CPM
- if(autocvar_sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement_x != 0)
+ if(autocvar_sv_warsowbunny_turnaccel && accelerating && self.movement_y == 0 && self.movement.x != 0)
PM_AirAccelerate(wishdir, wishspeed);
else
PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, autocvar_sv_airaccel_qw_stretchfactor, autocvar_sv_airaccel_sideways_friction / maxairspd, self.stat_sv_airspeedlimit_nonqw);
if((g_cts || g_race) && !IS_OBSERVER(self))
{
- if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
+ if(vlen(self.velocity - self.velocity.z * '0 0 1') > speedaward_speed)
{
- speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
+ speedaward_speed = vlen(self.velocity - self.velocity.z * '0 0 1');
speedaward_holder = self.netname;
speedaward_uid = self.crypto_idfp;
speedaward_lastupdate = time;
// WEAPONTODO
float xyspeed;
- xyspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y);
+ xyspeed = vlen('1 0 0' * self.velocity.x + '0 1 0' * self.velocity.y);
if(self.weapon == WEP_VORTEX && WEP_CVAR(vortex, charge) && WEP_CVAR(vortex, charge_velocity_rate) && xyspeed > WEP_CVAR(vortex, charge_minspeed))
{
// add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed