// use default physics
set sv_friction_on_land 0
+set sv_friction_slick 0.5
set sv_player_viewoffset "0 0 35" "view offset of the player model"
set sv_player_mins "-16 -16 -24" "playermodel mins"
sv_warsowbunny_topspeed 925
sv_warsowbunny_backtosideratio 0.8
sv_friction_on_land 0
+sv_friction_slick 0.5
sv_doublejump 0
sv_jumpspeedcap_min ""
sv_jumpspeedcap_max ""
sv_warsowbunny_topspeed 925
sv_warsowbunny_backtosideratio 0.8
sv_friction_on_land 0
+sv_friction_slick 0.5
sv_doublejump 0
sv_jumpspeedcap_min ""
sv_jumpspeedcap_max ""
sv_warsowbunny_topspeed 925
sv_warsowbunny_backtosideratio 0.8
sv_friction_on_land 0
+sv_friction_slick 0.5
sv_doublejump 0
sv_jumpspeedcap_min ""
sv_jumpspeedcap_max ""
sv_warsowbunny_topspeed 925
sv_warsowbunny_backtosideratio 0.8
sv_friction_on_land 0
+sv_friction_slick 0.5
sv_doublejump 1
sv_jumpspeedcap_min 0
sv_jumpspeedcap_max 0.5
sv_warsowbunny_topspeed 925
sv_warsowbunny_backtosideratio 0.8
sv_friction_on_land 0
+sv_friction_slick 0.5
sv_doublejump 0
sv_jumpspeedcap_min ""
sv_jumpspeedcap_max ""
// --------------------------------------------------------------------------
// BEGIN OPTIONAL CSQC FUNCTIONS
+void trigger_touch_generic(void() touchfunc)
+{
+ entity e;
+ for(e = findradius((self.absmin + self.absmax) * 0.5, vlen(self.absmax - self.absmin) * 0.5 + 1); e; e = e.chain)
+ if(e.isplayermodel)
+ {
+ vector emin = e.absmin, emax = e.absmax;
+ if(self.solid == SOLID_BSP)
+ {
+ emin -= '1 1 1';
+ emax += '1 1 1';
+ }
+ if(boxesoverlap(emin, emax, self.absmin, self.absmax)) // quick
+ if(WarpZoneLib_BoxTouchesBrush(emin, emax, self, e)) // accurate
+ {
+ other = e;
+ touchfunc();
+ }
+ }
+}
+
void Ent_RemoveEntCS()
{
entcs_receiver[self.sv_entnum] = world;
void Ent_RadarLink();
void Ent_Init();
void Ent_ScoresInfo();
+void ent_func_ladder();
+void ent_trigger_push();
+void ent_target_push();
+void ent_conveyor();
void CSQC_Ent_Update(float bIsNewEntity)
{
float t;
case ENT_CLIENT_SPAWNEVENT: Ent_ReadSpawnEvent(bIsNewEntity); break;
case ENT_CLIENT_NOTIFICATION: Read_Notification(bIsNewEntity); break;
case ENT_CLIENT_HEALING_ORB: ent_healer(); break;
+ case ENT_CLIENT_LADDER: ent_func_ladder(); break;
+ case ENT_CLIENT_TRIGGER_PUSH: ent_trigger_push(); break;
+ case ENT_CLIENT_TARGET_PUSH: ent_target_push(); break;
+ case ENT_CLIENT_CONVEYOR: ent_conveyor(); break;
default:
//error(strcat(_("unknown entity type in CSQC_Ent_Update: %d\n"), self.enttype));
var float autocvar_crosshair_rpc_alpha = 1;
var float autocvar_crosshair_rpc_size = 1;
float autocvar_cl_nade_timer;
+float autocvar_speedmeter;
float hud;
float view_quality;
float framecount;
+
+.float jumppadcount;
+// WARNING: this kills the trace globals
+float WarpZoneLib_ExactTrigger_Touch();
+#define EXACTTRIGGER_TOUCH if(WarpZoneLib_ExactTrigger_Touch()) return
+
entity players;
entity teams;
var float team_count; // real teams
-const float MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE = 4;
#define GRAVITY_UNAFFECTED_BY_TICRATE (getstati(STAT_MOVEFLAGS) & MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE)
.entity move_groundentity; // FIXME add move_groundnetworkentity?
void Movetype_Physics_NoMatchServer();
const float MOVETYPE_NONE = 0;
-const float MOVETYPE_ANGLENOCLIP = 1;
+const float MOVETYPE_ANGLENOCLIP = 1;
const float MOVETYPE_ANGLECLIP = 2;
const float MOVETYPE_WALK = 3;
const float MOVETYPE_STEP = 4;
const float MOVETYPE_NOCLIP = 8;
const float MOVETYPE_FLYMISSILE = 9;
const float MOVETYPE_BOUNCE = 10;
-const float MOVETYPE_BOUNCEMISSILE = 11; // Like bounce but doesn't lose speed on bouncing
-const float MOVETYPE_FOLLOW = 12;
-const float MOVETYPE_FAKEPUSH = 13;
-const float MOVETYPE_FLY_WORLDONLY = 33;
+const float MOVETYPE_BOUNCEMISSILE = 11; // Like bounce but doesn't lose speed on bouncing
+const float MOVETYPE_FOLLOW = 12;
+const float MOVETYPE_FAKEPUSH = 13;
+const float MOVETYPE_FLY_WORLDONLY = 33;
-const float FL_ITEM = 256;
-const float FL_ONGROUND = 512;
+const float FL_ITEM = 256;
+const float FL_ONGROUND = 512;
+
+const float MOVEFLAG_Q2AIRACCELERATE = 1;
+const float MOVEFLAG_NOGRAVITYONGROUND = 2;
+const float MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE = 4;
+#define moveflags (getstati(STAT_MOVEFLAGS))
\ No newline at end of file
../common/monsters/monsters.qc
+../common/physics.qh
+../server/mutators/mutator_dodging.qc
+../server/mutators/mutator_multijump.qc
+../server/t_halflife.qc
+../server/t_jumppads.qc
+../server/t_plats.qc
+
../common/nades.qc
../common/buffs.qc
+../common/physics.qc
../warpzonelib/anglestransform.qc
../warpzonelib/mathlib.qc
const float ENT_CLIENT_TURRET = 40;
const float ENT_CLIENT_AUXILIARYXHAIR = 50;
const float ENT_CLIENT_VEHICLE = 60;
+const float ENT_CLIENT_LADDER = 61;
+const float ENT_CLIENT_TRIGGER_PUSH = 62;
+const float ENT_CLIENT_TARGET_PUSH = 63;
+const float ENT_CLIENT_CONVEYOR = 64;
const float ENT_CLIENT_HEALING_ORB = 80;
//#define CSQCMODEL_SUPPORT_GETTAGINFO_BEFORE_DRAW
// server decides crouching, this lags, but so be it
-#define CSQCMODEL_SERVERSIDE_CROUCH
+//#define CSQCMODEL_SERVERSIDE_CROUCH
// a hack for Xonotic
#ifdef CSQC
--- /dev/null
+.float race_penalty;
+
+.float gravity;
+.float swamp_slowdown;
+.float lastflags;
+.float lastground;
+.float wasFlying;
+.float spectatorspeed;
+
+.vector movement_old;
+.float buttons_old;
+.vector v_angle_old;
+.string lastclassname;
+
+.float() PlayerPhysplug;
+float AdjustAirAccelQW(float accelqw, float factor);
+
+#ifdef CSQC
+
+.float watertype;
+
+#elif defined(SVQC)
+.float stat_sv_airaccel_qw;
+.float stat_sv_airstrafeaccel_qw;
+.float stat_sv_airspeedlimit_nonqw;
+.float stat_sv_maxspeed;
+.float stat_movement_highspeed;
+
+.float stat_sv_friction_on_land;
+.float stat_sv_friction_slick;
+
+.float stat_doublejump;
+
+.float stat_jumpspeedcap_min;
+.float stat_jumpspeedcap_max;
+.float stat_jumpspeedcap_disable_onramps;
+
+.float stat_jetpack_accel_side;
+.float stat_jetpack_accel_up;
+.float stat_jetpack_antigravity;
+.float stat_jetpack_fuel;
+.float stat_jetpack_maxspeed_up;
+.float stat_jetpack_maxspeed_side;
+
+void Physics_AddStats()
+{
+ // g_movementspeed hack
+ addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
+ addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
+ addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
+ addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
+ addstat(STAT_MOVEVARS_HIGHSPEED, AS_FLOAT, stat_movement_highspeed);
+
+ // jet pack
+ addstat(STAT_JETPACK_ACCEL_SIDE, AS_FLOAT, stat_jetpack_accel_side);
+ addstat(STAT_JETPACK_ACCEL_UP, AS_FLOAT, stat_jetpack_accel_up);
+ addstat(STAT_JETPACK_ANTIGRAVITY, AS_FLOAT, stat_jetpack_antigravity);
+ addstat(STAT_JETPACK_FUEL, AS_FLOAT, stat_jetpack_fuel);
+ addstat(STAT_JETPACK_MAXSPEED_UP, AS_FLOAT, stat_jetpack_maxspeed_up);
+ addstat(STAT_JETPACK_MAXSPEED_SIDE, AS_FLOAT, stat_jetpack_maxspeed_side);
+
+ // hack to fix track_canjump
+ addstat(STAT_MOVEVARS_TRACK_CANJUMP, AS_INT, cvar_cl_movement_track_canjump);
+
+ // double jump
+ addstat(STAT_DOUBLEJUMP, AS_INT, stat_doublejump);
+
+ // jump speed caps
+ addstat(STAT_MOVEVARS_JUMPSPEEDCAP_MIN, AS_FLOAT, stat_jumpspeedcap_min);
+ addstat(STAT_MOVEVARS_JUMPSPEEDCAP_MIN, AS_FLOAT, stat_jumpspeedcap_min);
+ addstat(STAT_MOVEVARS_JUMPSPEEDCAP_DISABLE_ONRAMPS, AS_INT, stat_jumpspeedcap_disable_onramps);
+
+ // hacks
+ addstat(STAT_MOVEVARS_FRICTION_ONLAND, AS_FLOAT, stat_sv_friction_on_land);
+ addstat(STAT_MOVEVARS_FRICTION_SLICK, AS_FLOAT, stat_sv_friction_slick);
+}
+
+void Physics_UpdateStats(float maxspd_mod)
+{
+ self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
+ if (autocvar_sv_airstrafeaccel_qw)
+ self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
+ else
+ self.stat_sv_airstrafeaccel_qw = 0;
+ self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
+ self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
+ self.stat_movement_highspeed = PHYS_HIGHSPEED; // TODO: remove this!
+
+ self.stat_doublejump = PHYS_DOUBLEJUMP;
+
+ self.stat_jetpack_antigravity = PHYS_JETPACK_ANTIGRAVITY;
+ self.stat_jetpack_accel_up = PHYS_JETPACK_ACCEL_UP;
+ self.stat_jetpack_accel_side = PHYS_JETPACK_ACCEL_SIDE;
+ self.stat_jetpack_maxspeed_side = PHYS_JETPACK_MAXSPEED_SIDE;
+ self.stat_jetpack_maxspeed_up = PHYS_JETPACK_MAXSPEED_UP;
+ self.stat_jetpack_fuel = PHYS_JETPACK_FUEL;
+
+ self.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MIN;
+ self.stat_jumpspeedcap_max = PHYS_JUMPSPEEDCAP_MAX;
+ self.stat_jumpspeedcap_disable_onramps = PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS;
+
+ self.stat_sv_friction_on_land = PHYS_FRICTION_ONLAND;
+ self.stat_sv_friction_slick = PHYS_FRICTION_SLICK;
+}
+#endif
+
+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 = remainder(angle, 360) / 45;
+ return angle > 1 ? 0 : angle < -1 ? 0 : 1 - fabs(angle);
+}
+
+float GeomLerp(float a, float lerp, float b)
+{
+ return a == 0 ? (lerp < 1 ? 0 : b)
+ : b == 0 ? (lerp > 0 ? 0 : a)
+ : a * pow(fabs(b / a), lerp);
+}
+
+noref float pmove_waterjumptime;
+
+const float unstick_count = 27;
+vector unstick_offsets[unstick_count] =
+{
+// 1 no nudge (just return the original if this test passes)
+ '0.000 0.000 0.000',
+// 6 simple nudges
+ ' 0.000 0.000 0.125', '0.000 0.000 -0.125',
+ '-0.125 0.000 0.000', '0.125 0.000 0.000',
+ ' 0.000 -0.125 0.000', '0.000 0.125 0.000',
+// 4 diagonal flat nudges
+ '-0.125 -0.125 0.000', '0.125 -0.125 0.000',
+ '-0.125 0.125 0.000', '0.125 0.125 0.000',
+// 8 diagonal upward nudges
+ '-0.125 0.000 0.125', '0.125 0.000 0.125',
+ ' 0.000 -0.125 0.125', '0.000 0.125 0.125',
+ '-0.125 -0.125 0.125', '0.125 -0.125 0.125',
+ '-0.125 0.125 0.125', '0.125 0.125 0.125',
+// 8 diagonal downward nudges
+ '-0.125 0.000 -0.125', '0.125 0.000 -0.125',
+ ' 0.000 -0.125 -0.125', '0.000 0.125 -0.125',
+ '-0.125 -0.125 -0.125', '0.125 -0.125 -0.125',
+ '-0.125 0.125 -0.125', '0.125 0.125 -0.125',
+};
+
+void PM_ClientMovement_Unstick()
+{
+ float i;
+ for (i = 0; i < unstick_count; i++)
+ {
+ vector neworigin = unstick_offsets[i] + self.origin;
+ tracebox(neworigin, PL_CROUCH_MIN, PL_CROUCH_MAX, neworigin, MOVE_NORMAL, self);
+ if (!trace_startsolid)
+ {
+ self.origin = neworigin;
+ return;// true;
+ }
+ }
+}
+
+void PM_ClientMovement_UpdateStatus()
+{
+ // make sure player is not stuck
+ PM_ClientMovement_Unstick();
+
+ // set crouched
+ if (PHYS_INPUT_BUTTON_CROUCH(self))
+ {
+ // wants to crouch, this always works..
+ if (!IS_DUCKED(self))
+ SET_DUCKED(self);
+ }
+ else
+ {
+ // wants to stand, if currently crouching we need to check for a
+ // low ceiling first
+ if (IS_DUCKED(self))
+ {
+ tracebox(self.origin, PL_MIN, PL_MAX, self.origin, MOVE_NORMAL, self);
+ if (!trace_startsolid)
+ UNSET_DUCKED(self);
+ }
+ }
+
+ // set onground
+ vector origin1 = self.origin + '0 0 1';
+ vector origin2 = self.origin - '0 0 1';
+
+ tracebox(origin1, self.mins, self.maxs, origin2, MOVE_NORMAL, self);
+ if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
+ {
+ SET_ONGROUND(self);
+
+ // this code actually "predicts" an impact; so let's clip velocity first
+ float f = self.velocity * trace_plane_normal;
+ if (f < 0) // only if moving downwards actually
+ self.velocity -= f * trace_plane_normal;
+ }
+ else
+ UNSET_ONGROUND(self);
+
+ // set watertype/waterlevel
+ origin1 = self.origin;
+ origin1_z += self.mins_z + 1;
+ self.waterlevel = WATERLEVEL_NONE;
+
+ self.watertype = (pointcontents(origin1) == CONTENT_WATER);
+
+ if(self.watertype)
+ {
+ self.waterlevel = WATERLEVEL_WETFEET;
+ origin1_z = self.origin_z + (self.mins_z + self.maxs_z) * 0.5;
+ if(pointcontents(origin1) == CONTENT_WATER)
+ {
+ self.waterlevel = WATERLEVEL_SWIMMING;
+ origin1_z = self.origin_z + 22;
+ if(pointcontents(origin1) == CONTENT_WATER)
+ self.waterlevel = WATERLEVEL_SUBMERGED;
+ }
+ }
+
+ if(IS_ONGROUND(self) || self.velocity_z <= 0 || pmove_waterjumptime <= 0)
+ pmove_waterjumptime = 0;
+}
+
+void PM_ClientMovement_Move()
+{
+#ifdef CSQC
+ float t = PHYS_INPUT_TIMELENGTH;
+ vector primalvelocity = self.velocity;
+ PM_ClientMovement_UpdateStatus();
+ float bump = 0;
+ for (bump = 0; bump < 8 && self.velocity * self.velocity > 0; bump++)
+ {
+ vector neworigin = self.origin + t * self.velocity;
+ tracebox(self.origin, self.mins, self.maxs, neworigin, MOVE_NORMAL, self);
+ float old_trace1_fraction = trace_fraction;
+ vector old_trace1_endpos = trace_endpos;
+ vector old_trace1_plane_normal = trace_plane_normal;
+ if (trace_fraction < 1 && trace_plane_normal_z == 0)
+ {
+ // may be a step or wall, try stepping up
+ // first move forward at a higher level
+ vector currentorigin2 = self.origin;
+ currentorigin2_z += PHYS_STEPHEIGHT;
+ vector neworigin2 = neworigin;
+ neworigin2_z = self.origin_z + PHYS_STEPHEIGHT;
+ tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
+ if (!trace_startsolid)
+ {
+ // then move down from there
+ currentorigin2 = trace_endpos;
+ neworigin2 = trace_endpos;
+ neworigin2_z = self.origin_z;
+ float old_trace2_fraction = trace_fraction;
+ vector old_trace2_plane_normal = trace_plane_normal;
+ tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
+ // accept the new trace if it made some progress
+ if (fabs(trace_endpos_x - old_trace1_endpos_x) >= 0.03125 || fabs(trace_endpos_y - old_trace1_endpos_y) >= 0.03125)
+ {
+ trace_fraction = old_trace2_fraction;
+ trace_endpos = trace_endpos;
+ trace_plane_normal = old_trace2_plane_normal;
+ }
+ else
+ {
+ trace_fraction = old_trace1_fraction;
+ trace_endpos = old_trace1_endpos;
+ trace_plane_normal = old_trace1_plane_normal;
+ }
+ }
+ }
+
+ // check if it moved at all
+ if (trace_fraction >= 0.001)
+ self.origin = trace_endpos;
+
+ // check if it moved all the way
+ if (trace_fraction == 1)
+ break;
+
+ // this is only really needed for nogravityonground combined with gravityunaffectedbyticrate
+ // <LordHavoc> I'm pretty sure I commented it out solely because it seemed redundant
+ // this got commented out in a change that supposedly makes the code match QW better
+ // so if this is broken, maybe put it in an if (cls.protocol != PROTOCOL_QUAKEWORLD) block
+ if (trace_plane_normal_z > 0.7)
+ SET_ONGROUND(self);
+
+ t -= t * trace_fraction;
+
+ float f = self.velocity * trace_plane_normal;
+ self.velocity -= f * trace_plane_normal;
+ }
+ if (pmove_waterjumptime > 0)
+ self.velocity = primalvelocity;
+#endif
+}
+
+void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
+{
+ float k = 32 * (2 * IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), 0) - 1);
+ if (k <= 0)
+ return;
+
+ k *= bound(0, wishspeed / PHYS_MAXAIRSPEED, 1);
+
+ float zspeed = self.velocity_z;
+ self.velocity_z = 0;
+ float xyspeed = vlen(self.velocity);
+ self.velocity = normalize(self.velocity);
+
+ float dot = self.velocity * wishdir;
+
+ if (dot > 0) // we can't change direction while slowing down
+ {
+ k *= pow(dot, PHYS_AIRCONTROL_POWER)*PHYS_INPUT_TIMELENGTH;
+ xyspeed = max(0, xyspeed - PHYS_AIRCONTROL_PENALTY * sqrt(max(0, 1 - dot*dot)) * k/32);
+ k *= PHYS_AIRCONTROL;
+ self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
+ }
+
+ self.velocity = self.velocity * xyspeed;
+ self.velocity_z = zspeed;
+}
+
+float AdjustAirAccelQW(float accelqw, float factor)
+{
+ return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
+}
+
+// example config for alternate speed clamping:
+// sv_airaccel_qw 0.8
+// sv_airaccel_sideways_friction 0
+// prvm_globalset server speedclamp_mode 1
+// (or 2)
+void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
+{
+ float speedclamp = stretchfactor > 0 ? stretchfactor
+ : accelqw < 0 ? 1 // full clamping, no stretch
+ : -1; // no clamping
+
+ accelqw = fabs(accelqw);
+
+ if (GAMEPLAYFIX_Q2AIRACCELERATE)
+ wishspeed0 = wishspeed; // don't need to emulate this Q1 bug
+
+ float vel_straight = self.velocity * wishdir;
+ float vel_z = self.velocity_z;
+ vector vel_xy = vec2(self.velocity);
+ vector vel_perpend = vel_xy - vel_straight * wishdir;
+
+ float step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
+
+ float vel_xy_current = vlen(vel_xy);
+ if (speedlimit)
+ accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
+ float vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
+ float vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
+ vel_xy_backward = max(0, vel_xy_backward); // not that it REALLY occurs that this would cause wrong behaviour afterwards
+ vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
+
+ if (sidefric < 0 && (vel_perpend*vel_perpend))
+ // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
+ {
+ float f = max(0, 1 + PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
+ float fmin = (vel_xy_backward * vel_xy_backward - vel_straight * vel_straight) / (vel_perpend * vel_perpend);
+ // assume: fmin > 1
+ // vel_xy_backward*vel_xy_backward - vel_straight*vel_straight > vel_perpend*vel_perpend
+ // vel_xy_backward*vel_xy_backward > vel_straight*vel_straight + vel_perpend*vel_perpend
+ // vel_xy_backward*vel_xy_backward > vel_xy * vel_xy
+ // obviously, this cannot be
+ if (fmin <= 0)
+ vel_perpend *= f;
+ else
+ {
+ fmin = sqrt(fmin);
+ vel_perpend *= max(fmin, f);
+ }
+ }
+ else
+ vel_perpend *= max(0, 1 - PHYS_INPUT_TIMELENGTH * wishspeed * sidefric);
+
+ vel_xy = vel_straight * wishdir + vel_perpend;
+
+ if (speedclamp >= 0)
+ {
+ float vel_xy_preclamp;
+ vel_xy_preclamp = vlen(vel_xy);
+ if (vel_xy_preclamp > 0) // prevent division by zero
+ {
+ vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
+ if (vel_xy_current < vel_xy_preclamp)
+ vel_xy *= (vel_xy_current / vel_xy_preclamp);
+ }
+ }
+
+ self.velocity = vel_xy + vel_z * '0 0 1';
+}
+
+void PM_AirAccelerate(vector wishdir, float wishspeed)
+{
+ if (wishspeed == 0)
+ return;
+
+ vector curvel = self.velocity;
+ curvel_z = 0;
+ float curspeed = vlen(curvel);
+
+ if (wishspeed > curspeed * 1.01)
+ wishspeed = min(wishspeed, curspeed + PHYS_WARSOWBUNNY_AIRFORWARDACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH);
+ else
+ {
+ float f = max(0, (PHYS_WARSOWBUNNY_TOPSPEED - curspeed) / (PHYS_WARSOWBUNNY_TOPSPEED - PHYS_MAXSPEED(self)));
+ wishspeed = max(curspeed, PHYS_MAXSPEED(self)) + PHYS_WARSOWBUNNY_ACCEL * f * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH;
+ }
+ vector wishvel = wishdir * wishspeed;
+ vector acceldir = wishvel - curvel;
+ float addspeed = vlen(acceldir);
+ acceldir = normalize(acceldir);
+
+ float accelspeed = min(addspeed, PHYS_WARSOWBUNNY_TURNACCEL * PHYS_MAXSPEED(self) * PHYS_INPUT_TIMELENGTH);
+
+ if (PHYS_WARSOWBUNNY_BACKTOSIDERATIO < 1)
+ {
+ vector curdir = normalize(curvel);
+ float dot = acceldir * curdir;
+ if (dot < 0)
+ acceldir -= (1 - PHYS_WARSOWBUNNY_BACKTOSIDERATIO) * dot * curdir;
+ }
+
+ self.velocity += accelspeed * acceldir;
+}
+
+
+/*
+=============
+PlayerJump
+
+When you press the jump key
+returns TRUE if handled
+=============
+*/
+float PlayerJump (void)
+{
+ if (PHYS_FROZEN(self))
+ return TRUE; // no jumping in freezetag when frozen
+
+#ifdef SVQC
+ if (self.player_blocked)
+ return TRUE; // no jumping while blocked
+#endif
+
+ float doublejump = FALSE;
+ float mjumpheight = PHYS_JUMPVELOCITY;
+
+ player_multijump = doublejump;
+ player_jumpheight = mjumpheight;
+#ifdef SVQC
+ if (MUTATOR_CALLHOOK(PlayerJump))
+#elif defined(CSQC)
+ if(PM_multijump_checkjump())
+#endif
+ return TRUE;
+
+ doublejump = player_multijump;
+ mjumpheight = player_jumpheight;
+
+ if (PHYS_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)
+ {
+ doublejump = TRUE;
+
+ // we MUST clip velocity here!
+ float f;
+ f = self.velocity * trace_plane_normal;
+ if (f < 0)
+ self.velocity -= f * trace_plane_normal;
+ }
+ }
+
+ if (self.waterlevel >= WATERLEVEL_SWIMMING)
+ {
+ self.velocity_z = PHYS_MAXSPEED(self) * 0.7;
+ return TRUE;
+ }
+
+ if (!doublejump)
+ if (!IS_ONGROUND(self))
+ return IS_JUMP_HELD(self);
+
+ if (PHYS_TRACK_CANJUMP(self))
+ if (IS_JUMP_HELD(self))
+ return TRUE;
+
+ // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
+ // velocity bounds. Final velocity is bound between (jumpheight *
+ // min + jumpheight) and (jumpheight * max + jumpheight);
+
+ if(PHYS_JUMPSPEEDCAP_MIN)
+ {
+ float minjumpspeed = mjumpheight * PHYS_JUMPSPEEDCAP_MIN;
+
+ if (self.velocity_z < minjumpspeed)
+ mjumpheight += minjumpspeed - self.velocity_z;
+ }
+
+ if(PHYS_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 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS))
+ {
+ float maxjumpspeed = mjumpheight * PHYS_JUMPSPEEDCAP_MAX;
+
+ if (self.velocity_z > maxjumpspeed)
+ mjumpheight -= self.velocity_z - maxjumpspeed;
+ }
+ }
+
+ if (!WAS_ONGROUND(self))
+ {
+ if(autocvar_speedmeter)
+ dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
+ if(self.lastground < time - 0.3)
+ {
+ self.velocity_x *= (1 - PHYS_FRICTION_ONLAND);
+ self.velocity_y *= (1 - PHYS_FRICTION_ONLAND);
+ }
+ if(self.jumppadcount > 1)
+ dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
+ self.jumppadcount = 0;
+ }
+
+ self.velocity_z += mjumpheight;
+
+ UNSET_ONGROUND(self);
+ SET_JUMP_HELD(self);
+
+#ifdef SVQC
+
+ self.oldvelocity_z = self.velocity_z;
+
+ animdecide_setaction(self, ANIMACTION_JUMP, TRUE);
+
+ if (autocvar_g_jump_grunt)
+ PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
+#endif
+ return TRUE;
+}
+
+void CheckWaterJump()
+{
+// check for a jump-out-of-water
+ makevectors(PHYS_INPUT_ANGLES(self));
+ vector start = self.origin;
+ start_z += 8;
+ v_forward_z = 0;
+ normalize(v_forward);
+ vector end = start + v_forward*24;
+ traceline (start, end, TRUE, self);
+ if (trace_fraction < 1)
+ { // solid at waist
+ start_z = start_z + self.maxs_z - 8;
+ end = start + v_forward*24;
+ self.movedir = trace_plane_normal * -50;
+ traceline(start, end, TRUE, self);
+ if (trace_fraction == 1)
+ { // open at eye level
+ self.velocity_z = 225;
+#ifdef SVQC
+ self.flags |= FL_WATERJUMP;
+ SET_JUMP_HELD(self);
+ self.teleport_time = time + 2; // safety net
+#endif
+ }
+ }
+}
+
+
+#ifdef SVQC
+ #define JETPACK_JUMP(s) s.cvar_cl_jetpack_jump
+#elif defined(CSQC)
+ float autocvar_cl_jetpack_jump;
+ #define JETPACK_JUMP(s) autocvar_cl_jetpack_jump
+#endif
+.float jetpack_stopped;
+// Hack: shouldn't need to know about this
+.float multijump_count;
+void CheckPlayerJump()
+{
+#ifdef SVQC
+ float was_flying = ITEMS(self) & IT_USING_JETPACK;
+#endif
+ if (JETPACK_JUMP(self) < 2)
+#ifdef SVQC
+ ITEMS(self) &= ~IT_USING_JETPACK;
+#endif
+
+ if(PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_JETPACK(self))
+ {
+#ifdef SVQC
+ float air_jump = !PlayerJump() || self.multijump_count > 0; // PlayerJump() has important side effects
+ float activate = JETPACK_JUMP(self) && air_jump && PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_JETPACK(self);
+ float has_fuel = !autocvar_g_jetpack_fuel || self.ammo_fuel || ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO;
+#else
+ PlayerJump(); // Client only
+ float has_fuel = TRUE; // TODO
+#endif
+ if (!(ITEMS(self) & IT_JETPACK)) { }
+ else if (self.jetpack_stopped) { }
+ else if (!has_fuel)
+ {
+#ifdef SVQC
+ 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);
+#endif
+ self.jetpack_stopped = TRUE;
+#ifdef SVQC
+ ITEMS(self) &= ~IT_USING_JETPACK;
+#endif
+ }
+#ifdef SVQC
+ else if (activate && !PHYS_FROZEN(self))
+ ITEMS(self) |= IT_USING_JETPACK;
+#endif
+ }
+ else
+ {
+ self.jetpack_stopped = FALSE;
+#ifdef SVQC
+ ITEMS(self) &= ~IT_USING_JETPACK;
+#endif
+ }
+ if (!PHYS_INPUT_BUTTON_JUMP(self))
+ UNSET_JUMP_HELD(self);
+
+ if (self.waterlevel == WATERLEVEL_SWIMMING)
+ CheckWaterJump();
+}
+
+float racecar_angle(float forward, float down)
+{
+ if (forward < 0)
+ {
+ forward = -forward;
+ down = -down;
+ }
+
+ float ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
+
+ float angle_mult = forward / (800 + forward);
+
+ if (ret > 180)
+ return ret * angle_mult + 360 * (1 - angle_mult);
+ else
+ return ret * angle_mult;
+}
+
+void RaceCarPhysics()
+{
+#ifdef SVQC
+ // using this move type for "big rigs"
+ // the engine does not push the entity!
+
+ vector rigvel;
+
+ vector angles_save = self.angles;
+ float accel = bound(-1, PHYS_INPUT_MOVEVALUES(self).x / PHYS_MAXSPEED(self), 1);
+ float steer = bound(-1, PHYS_INPUT_MOVEVALUES(self).y / PHYS_MAXSPEED(self), 1);
+
+ if (g_bugrigs_reverse_speeding)
+ {
+ if (accel < 0)
+ {
+ // back accel is DIGITAL
+ // to prevent speedhack
+ if (accel < -0.5)
+ accel = -1;
+ else
+ accel = 0;
+ }
+ }
+
+ self.angles_x = 0;
+ self.angles_z = 0;
+ makevectors(self.angles); // new forward direction!
+
+ if (IS_ONGROUND(self) || g_bugrigs_air_steering)
+ {
+ float myspeed = self.velocity * v_forward;
+ float upspeed = self.velocity * v_up;
+
+ // responsiveness factor for steering and acceleration
+ float f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
+ //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
+
+ float steerfactor;
+ if (myspeed < 0 && g_bugrigs_reverse_spinning)
+ steerfactor = -myspeed * g_bugrigs_steer;
+ else
+ steerfactor = -myspeed * f * g_bugrigs_steer;
+
+ float accelfactor;
+ if (myspeed < 0 && g_bugrigs_reverse_speeding)
+ accelfactor = g_bugrigs_accel;
+ else
+ accelfactor = f * g_bugrigs_accel;
+ //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
+
+ if (accel < 0)
+ {
+ if (myspeed > 0)
+ {
+ myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
+ }
+ else
+ {
+ if (!g_bugrigs_reverse_speeding)
+ myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
+ }
+ }
+ else
+ {
+ if (myspeed >= 0)
+ {
+ myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
+ }
+ else
+ {
+ if (g_bugrigs_reverse_stopping)
+ myspeed = 0;
+ else
+ myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
+ }
+ }
+ // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
+ //MAXIMA: friction(v) := g_bugrigs_friction_floor;
+
+ self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
+ makevectors(self.angles); // new forward direction!
+
+ myspeed += accel * accelfactor * PHYS_INPUT_TIMELENGTH;
+
+ rigvel = myspeed * v_forward + '0 0 1' * upspeed;
+ }
+ else
+ {
+ float myspeed = vlen(self.velocity);
+
+ // responsiveness factor for steering and acceleration
+ float f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
+ float steerfactor = -myspeed * f;
+ self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
+
+ rigvel = self.velocity;
+ makevectors(self.angles); // new forward direction!
+ }
+
+ rigvel *= max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * PHYS_INPUT_TIMELENGTH);
+ //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
+ //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
+ //MAXIMA: solve(total_acceleration(v) = 0, v);
+
+ if (g_bugrigs_planar_movement)
+ {
+ vector rigvel_xy, neworigin, up;
+ float mt;
+
+ rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
+ rigvel_xy = vec2(rigvel);
+
+ if (g_bugrigs_planar_movement_car_jumping)
+ mt = MOVE_NORMAL;
+ else
+ mt = MOVE_NOMONSTERS;
+
+ tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
+ up = trace_endpos - self.origin;
+
+ // BUG RIGS: align the move to the surface instead of doing collision testing
+ // can we move?
+ tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * PHYS_INPUT_TIMELENGTH, mt, self);
+
+ // align to surface
+ tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * PHYS_INPUT_TIMELENGTH, mt, self);
+
+ if (trace_fraction < 0.5)
+ {
+ trace_fraction = 1;
+ neworigin = self.origin;
+ }
+ else
+ neworigin = trace_endpos;
+
+ if (trace_fraction < 1)
+ {
+ // 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
+ +
+ '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)
+ );
+ SET_ONGROUND(self);
+ }
+ else
+ {
+ // now set angles_x so that the car points forward, but is tilted in velocity direction
+ UNSET_ONGROUND(self);
+ }
+
+ self.velocity = (neworigin - self.origin) * (1.0 / PHYS_INPUT_TIMELENGTH);
+ self.movetype = MOVETYPE_NOCLIP;
+ }
+ else
+ {
+ rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
+ self.velocity = rigvel;
+ self.movetype = MOVETYPE_FLY;
+ }
+
+ trace_fraction = 1;
+ tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
+ if (trace_fraction != 1)
+ {
+ self.angles = vectoangles2(
+ '1 0 0' * v_forward_x * 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),
+ trace_plane_normal
+ );
+ }
+ else
+ {
+ vector vel_local;
+
+ vel_local_x = v_forward * self.velocity;
+ 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);
+ }
+
+ // smooth the angles
+ vector vf1, vu1, smoothangles;
+ makevectors(self.angles);
+ float f = bound(0, PHYS_INPUT_TIMELENGTH * g_bugrigs_angle_smoothing, 1);
+ if (f == 0)
+ f = 1;
+ vf1 = v_forward * f;
+ vu1 = v_up * f;
+ makevectors(angles_save);
+ 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;
+#endif
+}
+
+string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
+.float specialcommand_pos;
+void SpecialCommand()
+{
+#ifdef SVQC
+#ifdef TETRIS
+ TetrisImpulse();
+#else
+ if (!CheatImpulse(99))
+ print("A hollow voice says \"Plugh\".\n");
+#endif
+#endif
+}
+
+#ifdef SVQC
+float speedaward_speed;
+string speedaward_holder;
+string speedaward_uid;
+#endif
+void race_send_speedaward(float msg)
+{
+#ifdef SVQC
+ // send the best speed of the round
+ WriteByte(msg, SVC_TEMPENTITY);
+ WriteByte(msg, TE_CSQC_RACE);
+ WriteByte(msg, RACE_NET_SPEED_AWARD);
+ WriteInt24_t(msg, floor(speedaward_speed+0.5));
+ WriteString(msg, speedaward_holder);
+#endif
+}
+
+#ifdef SVQC
+float speedaward_alltimebest;
+string speedaward_alltimebest_holder;
+string speedaward_alltimebest_uid;
+#endif
+void race_send_speedaward_alltimebest(float msg)
+{
+#ifdef SVQC
+ // send the best speed
+ WriteByte(msg, SVC_TEMPENTITY);
+ WriteByte(msg, TE_CSQC_RACE);
+ WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
+ WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
+ WriteString(msg, speedaward_alltimebest_holder);
+#endif
+}
+
+float PM_check_keepaway(void)
+{
+#ifdef SVQC
+ return (self.ballcarried && g_keepaway) ? autocvar_g_keepaway_ballcarrier_highspeed : 1;
+#else
+ return 1;
+#endif
+}
+
+void PM_check_race_movetime(void)
+{
+#ifdef SVQC
+ self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
+ float f = floor(self.race_movetime_frac);
+ self.race_movetime_frac -= f;
+ self.race_movetime_count += f;
+ self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
+#endif
+}
+
+float PM_check_specialcommand(float buttons)
+{
+#ifdef SVQC
+ string c;
+ if (!buttons)
+ c = "x";
+ else if (buttons == 1)
+ c = "1";
+ else if (buttons == 2)
+ c = " ";
+ else if (buttons == 128)
+ c = "s";
+ else if (buttons == 256)
+ c = "w";
+ else if (buttons == 512)
+ c = "a";
+ else if (buttons == 1024)
+ c = "d";
+ else
+ c = "?";
+
+ if (c == substring(specialcommand, self.specialcommand_pos, 1))
+ {
+ self.specialcommand_pos += 1;
+ if (self.specialcommand_pos >= strlen(specialcommand))
+ {
+ self.specialcommand_pos = 0;
+ SpecialCommand();
+ return TRUE;
+ }
+ }
+ else if (self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
+ self.specialcommand_pos = 0;
+#endif
+ return FALSE;
+}
+
+void PM_check_nickspam(void)
+{
+#ifdef SVQC
+ if (time >= self.nickspamtime)
+ return;
+ if (self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
+ {
+ // slight annoyance for nick change scripts
+ PHYS_INPUT_MOVEVALUES(self) = -1 * PHYS_INPUT_MOVEVALUES(self);
+ self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
+
+ 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!
+ {
+ PHYS_INPUT_ANGLES(self)_x = random() * 360;
+ PHYS_INPUT_ANGLES(self)_y = random() * 360;
+ // at least I'm not forcing retardedview by also assigning to angles_z
+ self.fixangle = TRUE;
+ }
+ }
+#endif
+}
+
+void PM_check_punch()
+{
+#ifdef SVQC
+ if (self.punchangle != '0 0 0')
+ {
+ float f = vlen(self.punchangle) - 10 * PHYS_INPUT_TIMELENGTH;
+ if (f > 0)
+ self.punchangle = normalize(self.punchangle) * f;
+ else
+ self.punchangle = '0 0 0';
+ }
+
+ if (self.punchvector != '0 0 0')
+ {
+ float f = vlen(self.punchvector) - 30 * PHYS_INPUT_TIMELENGTH;
+ if (f > 0)
+ self.punchvector = normalize(self.punchvector) * f;
+ else
+ self.punchvector = '0 0 0';
+ }
+#endif
+}
+
+void PM_check_spider(void)
+{
+#ifdef SVQC
+ if (time >= self.spider_slowness)
+ return;
+ PHYS_MAXSPEED(self) *= 0.5; // half speed while slow from spider
+ self.stat_sv_airspeedlimit_nonqw *= 0.5;
+#endif
+}
+
+// predict frozen movement, as frozen players CAN move in some cases
+void PM_check_frozen(void)
+{
+ if (!PHYS_FROZEN(self))
+ return;
+ if (PHYS_DODGING_FROZEN
+#ifdef SVQC
+ && IS_REAL_CLIENT(self)
+#endif
+ )
+ {
+ PHYS_INPUT_MOVEVALUES(self)_x = bound(-5, PHYS_INPUT_MOVEVALUES(self).x, 5);
+ PHYS_INPUT_MOVEVALUES(self)_y = bound(-5, PHYS_INPUT_MOVEVALUES(self).y, 5);
+ PHYS_INPUT_MOVEVALUES(self)_z = bound(-5, PHYS_INPUT_MOVEVALUES(self).z, 5);
+ }
+ else
+ PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
+
+ vector midpoint = ((self.absmin + self.absmax) * 0.5);
+ if (pointcontents(midpoint) == CONTENT_WATER)
+ {
+ self.velocity = self.velocity * 0.5;
+
+ if (pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
+ self.velocity_z = 200;
+ }
+}
+
+void PM_check_blocked(void)
+{
+#ifdef SVQC
+ if (!self.player_blocked)
+ return;
+ PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
+ self.disableclientprediction = 1;
+#endif
+}
+
+#ifdef SVQC
+float speedaward_lastsent;
+float speedaward_lastupdate;
+string GetMapname(void);
+#endif
+void PM_check_race(void)
+{
+#ifdef SVQC
+ if not(g_cts || g_race)
+ return;
+ if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
+ {
+ speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
+ speedaward_holder = self.netname;
+ speedaward_uid = self.crypto_idfp;
+ speedaward_lastupdate = time;
+ }
+ if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
+ {
+ string rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
+ race_send_speedaward(MSG_ALL);
+ speedaward_lastsent = speedaward_speed;
+ if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
+ {
+ speedaward_alltimebest = speedaward_speed;
+ speedaward_alltimebest_holder = speedaward_holder;
+ speedaward_alltimebest_uid = speedaward_uid;
+ db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
+ db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
+ race_send_speedaward_alltimebest(MSG_ALL);
+ }
+ }
+#endif
+}
+
+void PM_check_vortex(void)
+{
+#ifdef SVQC
+ // WEAPONTODO
+ float xyspeed = vlen(vec2(self.velocity));
+ 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
+ xyspeed = min(xyspeed, WEP_CVAR(vortex, charge_maxspeed));
+ float f = (xyspeed - WEP_CVAR(vortex, charge_minspeed)) / (WEP_CVAR(vortex, charge_maxspeed) - WEP_CVAR(vortex, charge_minspeed));
+ // add the extra charge
+ self.vortex_charge = min(1, self.vortex_charge + WEP_CVAR(vortex, charge_velocity_rate) * f * PHYS_INPUT_TIMELENGTH);
+ }
+#endif
+}
+
+void PM_fly(float maxspd_mod)
+{
+ // noclipping or flying
+ UNSET_ONGROUND(self);
+
+ self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
+ makevectors(PHYS_INPUT_ANGLES(self));
+ //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
+ vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
+ + v_right * PHYS_INPUT_MOVEVALUES(self).y
+ + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
+ // acceleration
+ vector wishdir = normalize(wishvel);
+ float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod);
+ if (time >= self.teleport_time)
+ PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
+}
+
+void PM_swim(float maxspd_mod)
+{
+ // swimming
+ UNSET_ONGROUND(self);
+
+ float jump = PHYS_INPUT_BUTTON_JUMP(self);
+ // water jump only in certain situations
+ // this mimics quakeworld code
+ if (jump && self.waterlevel == WATERLEVEL_SWIMMING && self.velocity_z >= -180)
+ {
+ vector yawangles = '0 1 0' * PHYS_INPUT_ANGLES(self).y;
+ makevectors(yawangles);
+ vector forward = v_forward;
+ vector spot = self.origin + 24 * forward;
+ spot_z += 8;
+ traceline(spot, spot, MOVE_NOMONSTERS, self);
+ if (trace_startsolid)
+ {
+ spot_z += 24;
+ traceline(spot, spot, MOVE_NOMONSTERS, self);
+ if (!trace_startsolid)
+ {
+ self.velocity = forward * 50;
+ self.velocity_z = 310;
+ pmove_waterjumptime = 2;
+ UNSET_ONGROUND(self);
+ SET_JUMP_HELD(self);
+ }
+ }
+ }
+ makevectors(PHYS_INPUT_ANGLES(self));
+ //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
+ vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
+ + v_right * PHYS_INPUT_MOVEVALUES(self).y
+ + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
+ if (wishvel == '0 0 0')
+ wishvel = '0 0 -60'; // drift towards bottom
+
+ vector wishdir = normalize(wishvel);
+ float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod) * 0.7;
+
+ if (IS_DUCKED(self))
+ wishspeed *= 0.5;
+
+// if (pmove_waterjumptime <= 0) // TODO: use
+ {
+ // water friction
+ float f = 1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION;
+ f = min(max(0, f), 1);
+ self.velocity *= f;
+
+ f = wishspeed - self.velocity * wishdir;
+ if (f > 0)
+ {
+ float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, f);
+ self.velocity += accelspeed * wishdir;
+ }
+
+ // holding jump button swims upward slowly
+ if (jump)
+ {
+#if 0
+ if (self.watertype & CONTENT_LAVA)
+ self.velocity_z = 50;
+ else if (self.watertype & CONTENT_SLIME)
+ self.velocity_z = 80;
+ else
+ {
+ if (IS_NEXUIZ_DERIVED(gamemode))
+#endif
+ self.velocity_z = 200;
+#if 0
+ else
+ self.velocity_z = 100;
+ }
+#endif
+ }
+ }
+ PM_ClientMovement_Move();
+ // water acceleration
+ PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
+}
+
+void PM_ladder(float maxspd_mod)
+{
+ // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
+ UNSET_ONGROUND(self);
+
+ float g;
+ g = PHYS_GRAVITY * PHYS_INPUT_TIMELENGTH;
+ if (PHYS_ENTGRAVITY(self))
+ g *= PHYS_ENTGRAVITY(self);
+ if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
+ {
+ g *= 0.5;
+ self.velocity_z += g;
+ }
+
+ self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
+ makevectors(PHYS_INPUT_ANGLES(self));
+ //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
+ vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self)_x
+ + v_right * PHYS_INPUT_MOVEVALUES(self)_y
+ + '0 0 1' * PHYS_INPUT_MOVEVALUES(self)_z;
+ self.velocity_z += g;
+ if (self.ladder_entity.classname == "func_water")
+ {
+ float f = vlen(wishvel);
+ if (f > self.ladder_entity.speed)
+ 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)
+ self.waterlevel = WATERLEVEL_SUBMERGED;
+ 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)
+ self.waterlevel = WATERLEVEL_WETFEET;
+ else
+ {
+ self.waterlevel = WATERLEVEL_NONE;
+ self.watertype = CONTENT_EMPTY;
+ }
+ }
+ // acceleration
+ vector wishdir = normalize(wishvel);
+ float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod);
+ PM_ClientMovement_Move();
+#ifdef SVQC
+ if (time >= self.teleport_time)
+#endif
+ // water acceleration
+ PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE*maxspd_mod, 1, 0, 0, 0);
+}
+
+void PM_check_jumppad()
+{
+#ifdef CSQC
+ entity oldself = self;
+
+ for(self = world; (self = find(self, classname, "jumppad")); )
+ trigger_push_draw();
+
+ self = oldself;
+#endif
+}
+
+void PM_jetpack(float maxspd_mod)
+{
+ //makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
+ makevectors(PHYS_INPUT_ANGLES(self));
+ vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self)_x
+ + v_right * PHYS_INPUT_MOVEVALUES(self)_y;
+ // add remaining speed as Z component
+ float maxairspd = PHYS_MAXAIRSPEED * max(1, maxspd_mod);
+ // fix speedhacks :P
+ wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
+ // add the unused velocity as up component
+ wishvel_z = 0;
+
+ // if (self.BUTTON_JUMP)
+ wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
+
+ // it is now normalized, so...
+ float a_side = PHYS_JETPACK_ACCEL_SIDE;
+ float a_up = PHYS_JETPACK_ACCEL_UP;
+ float a_add = PHYS_JETPACK_ANTIGRAVITY * PHYS_GRAVITY;
+
+ wishvel_x *= a_side;
+ wishvel_y *= a_side;
+ wishvel_z *= a_up;
+ wishvel_z += a_add;
+
+ float best = 0;
+ //////////////////////////////////////////////////////////////////////////////////////
+ // finding the maximum over all vectors of above form
+ // with wishvel having an absolute value of 1
+ //////////////////////////////////////////////////////////////////////////////////////
+ // we're finding the maximum over
+ // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
+ // for z in the range from -1 to 1
+ //////////////////////////////////////////////////////////////////////////////////////
+ // maximum is EITHER attained at the single extreme point:
+ float a_diff = a_side * a_side - a_up * a_up;
+ float f;
+ if (a_diff != 0)
+ {
+ f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
+ if (f > -1 && f < 1) // can it be attained?
+ {
+ best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
+ //print("middle\n");
+ }
+ }
+ // OR attained at z = 1:
+ f = (a_up + a_add) * (a_up + a_add);
+ if (f > best)
+ {
+ best = f;
+ //print("top\n");
+ }
+ // OR attained at z = -1:
+ f = (a_up - a_add) * (a_up - a_add);
+ if (f > best)
+ {
+ best = f;
+ //print("bottom\n");
+ }
+ best = sqrt(best);
+ //////////////////////////////////////////////////////////////////////////////////////
+
+ //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')) / PHYS_JETPACK_MAXSPEED_SIDE, 1);
+ if (wishvel_z - PHYS_GRAVITY > 0)
+ fz = bound(0, 1 - self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
+ else
+ fz = bound(0, 1 + self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
+
+ float fvel;
+ fvel = vlen(wishvel);
+ wishvel_x *= fxy;
+ wishvel_y *= fxy;
+ wishvel_z = (wishvel_z - PHYS_GRAVITY) * fz + PHYS_GRAVITY;
+
+ fvel = min(1, vlen(wishvel) / best);
+ if (PHYS_JETPACK_FUEL && !(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO))
+ f = min(1, PHYS_AMMO_FUEL(self) / (PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel));
+ else
+ f = 1;
+
+ //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
+
+ if (f > 0 && wishvel != '0 0 0')
+ {
+ self.velocity = self.velocity + wishvel * f * PHYS_INPUT_TIMELENGTH;
+ UNSET_ONGROUND(self);
+
+#ifdef SVQC
+ if (!(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO))
+ self.ammo_fuel -= PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel * f;
+
+ ITEMS(self) |= IT_USING_JETPACK;
+
+ // jetpack also inhibits health regeneration, but only for 1 second
+ self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
+#endif
+ }
+
+#ifdef CSQC
+ float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
+ if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
+ self.velocity_z -= g * 0.5;
+ else
+ self.velocity_z -= g;
+ PM_ClientMovement_Move();
+ if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
+ if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
+ self.velocity_z -= g * 0.5;
+#endif
+}
+#ifdef SVQC
+void SV_WalkMove ()
+{
+ // if PHYS_INPUT_TIMELENGTH is 0 (due to client sending the same timestamp twice),
+ // don't move
+ if (PHYS_INPUT_TIMELENGTH <= 0)
+ return;
+
+// if (autocvar_sv_gameplayfix_unstickplayers)
+// SV_CheckStuck (self);
+
+// applygravity = !SV_CheckWater(self) && self.movetype == MOVETYPE_WALK && !(self.flags & FL_WATERJUMP);
+
+// hitsupercontentsmask = SV_GenericHitSuperContentsMask(self);
+
+// SV_CheckVelocity(self);
+
+ // do a regular slide move unless it looks like you ran into a step
+// float oldonground = self.flags & FL_ONGROUND;
+
+ vector start_origin = self.origin;
+ vector start_velocity = self.velocity;
+
+ float clip = 0;
+// clip = SV_FlyMove (self, PHYS_INPUT_TIMELENGTH, applygravity, NULL, hitsupercontentsmask, sv_gameplayfix_stepmultipletimes.integer ? sv_stepheight.value : 0);
+
+// if(sv_gameplayfix_downtracesupportsongroundflag.integer)
+// if(!(clip & 1))
+ {
+ // only try this if there was no floor in the way in the trace (no,
+ // this check seems to be not REALLY necessary, because if clip & 1,
+ // our trace will hit that thing too)
+ vector upmove = self.origin;
+ upmove_z++;
+ vector downmove = self.origin;
+ upmove_z--;
+ float type;
+ if (self.movetype == MOVETYPE_FLYMISSILE)
+ type = MOVE_MISSILE;
+ else if (self.movetype == MOVETYPE_FLY_WORLDONLY)
+ type = MOVE_WORLDONLY;
+ else if (self.solid == SOLID_TRIGGER || self.solid == SOLID_NOT)
+ type = MOVE_NOMONSTERS; // only clip against bmodels
+ else
+ type = MOVE_NORMAL;
+ vector entmins = self.mins;
+ vector entmaxs = self.maxs;
+ tracebox(upmove, entmins, entmaxs, downmove, type, self);
+ if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
+ clip |= 1; // but we HAVE found a floor
+ }
+
+ // if the move did not hit the ground at any point, we're not on ground
+// if(!(clip & 1))
+// self.flags = self.flags & ~FL_ONGROUND;
+
+// SV_CheckVelocity(self);
+// SV_LinkEdict(self);
+// SV_LinkEdict_TouchAreaGrid(self);
+
+ if(clip & 8) // teleport
+ return;
+
+ if (self.flags & FL_WATERJUMP)
+ return;
+
+// if (autocvar_sv_nostep)
+// return;
+
+ vector originalmove_origin = self.origin;
+ vector originalmove_velocity = self.velocity;
+ float originalmove_flags = self.flags;
+ entity originalmove_groundentity = self.groundentity;
+
+ // if move didn't block on a step, return
+ if (clip & 2)
+ {
+ // if move was not trying to move into the step, return
+ if (fabs(start_velocity_x) < 0.03125 && fabs(start_velocity_y) < 0.03125)
+ return;
+
+ if (self.movetype != MOVETYPE_FLY)
+ {
+ // return if gibbed by a trigger
+ if (self.movetype != MOVETYPE_WALK)
+ return;
+
+ // return if attempting to jump while airborn (unless sv_jumpstep)
+// if (!autocvar_sv_jumpstep)
+// if (!oldonground && PRVM_serveredictfloat(self, waterlevel) == 0)
+// return;
+ }
+
+ // try moving up and forward to go up a step
+ // back to start pos
+ self.origin = start_origin;
+ self.velocity = start_velocity;
+
+ // move up
+ vector upmove = '0 0 0';
+ upmove_z = autocvar_sv_stepheight;
+// if(!SV_PushEntity(&trace, self, upmove, true))
+// {
+// // we got teleported when upstepping... must abort the move
+// return;
+// }
+
+ // move forward
+ self.velocity_z = 0;
+// clip = SV_FlyMove (self, PHYS_INPUT_TIMELENGTH, applygravity, stepnormal, hitsupercontentsmask, 0);
+ self.velocity_z += start_velocity_z;
+// if(clip & 8)
+// {
+// // we got teleported when upstepping... must abort the move
+// // note that z velocity handling may not be what QC expects here, but we cannot help it
+// return;
+// }
+
+// SV_CheckVelocity(self);
+// SV_LinkEdict(self);
+// SV_LinkEdict_TouchAreaGrid(self);
+
+ // check for stuckness, possibly due to the limited precision of floats
+ // in the clipping hulls
+ if (clip
+ && fabs(originalmove_origin_y - self.origin_y < 0.03125)
+ && fabs(originalmove_origin_x - self.origin_x < 0.03125))
+ {
+ //Con_Printf("wall\n");
+ // stepping up didn't make any progress, revert to original move
+ self.origin = originalmove_origin;
+ self.velocity = originalmove_velocity;
+ self.flags = originalmove_flags;
+ self.groundentity = originalmove_groundentity;
+ return;
+ }
+
+ //Con_Printf("step - ");
+
+ // extra friction based on view angle
+// if (clip & 2 && sv_wallfriction.integer)
+// SV_WallFriction (self, stepnormal);
+ }
+ // don't do the down move if stepdown is disabled, moving upward, not in water, or the move started offground or ended onground
+// else if (!autocvar_sv_gameplayfix_stepdown || self.waterlevel >= 3 || start_velocity_z >= (1.0 / 32.0) || !oldonground || (self.flags & FL_ONGROUND))
+// return;
+
+ // move down
+ vector downmove = '0 0 0';
+ downmove_z = -autocvar_sv_stepheight + start_velocity_z*PHYS_INPUT_TIMELENGTH;
+// if(!SV_PushEntity (&downtrace, self, downmove, true))
+// {
+// // we got teleported when downstepping... must abort the move
+// return;
+// }
+
+ if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
+ {
+ // this has been disabled so that you can't jump when you are stepping
+ // up while already jumping (also known as the Quake2 double jump bug)
+ }
+ else
+ {
+ //Con_Printf("slope\n");
+ // if the push down didn't end up on good ground, use the move without
+ // the step up. This happens near wall / slope combinations, and can
+ // cause the player to hop up higher on a slope too steep to climb
+ self.origin = originalmove_origin;
+ self.velocity = originalmove_velocity;
+ self.flags = originalmove_flags;
+ self.groundentity = originalmove_groundentity;
+ }
+
+// SV_CheckVelocity(self);
+// SV_LinkEdict(self);
+// SV_LinkEdict_TouchAreaGrid(self);
+}
+#endif
+void PM_walk(float buttons_prev, float maxspd_mod)
+{
+ if (!WAS_ONGROUND(self))
+ {
+ if (autocvar_speedmeter)
+ dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
+ if (self.lastground < time - 0.3)
+ self.velocity *= (1 - PHYS_FRICTION_ONLAND);
+ if (self.jumppadcount > 1)
+ dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
+ self.jumppadcount = 0;
+ }
+ // walking
+ makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
+ vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
+ + v_right * PHYS_INPUT_MOVEVALUES(self).y;
+ // acceleration
+ vector wishdir = normalize(wishvel);
+ float wishspeed = vlen(wishvel);
+
+ wishspeed = min(wishspeed, PHYS_MAXSPEED(self) * maxspd_mod);
+ if (IS_DUCKED(self))
+ wishspeed *= 0.5;
+
+ // apply edge friction
+ float f = vlen(vec2(self.velocity));
+ if (f > 0)
+ {
+ float realfriction;
+ trace_dphitq3surfaceflags = 0;
+ tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
+ // TODO: apply edge friction
+ // apply ground friction
+ if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK)
+ realfriction = PHYS_FRICTION_SLICK;
+ else
+ realfriction = PHYS_FRICTION;
+
+ f = 1 - PHYS_INPUT_TIMELENGTH * realfriction * ((f < PHYS_STOPSPEED) ? (PHYS_STOPSPEED / f) : 1);
+ f = max(0, f);
+ self.velocity *= f;
+ /*
+ Mathematical analysis time!
+
+ Our goal is to invert this mess.
+
+ For the two cases we get:
+ v = v0 * (1 - PHYS_INPUT_TIMELENGTH * (PHYS_STOPSPEED / v0) * PHYS_FRICTION)
+ = v0 - PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION
+ v0 = v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION
+ and
+ v = v0 * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
+ v0 = v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
+
+ These cases would be chosen ONLY if:
+ v0 < PHYS_STOPSPEED
+ v + PHYS_INPUT_TIMELENGTH * PHYS_STOPSPEED * PHYS_FRICTION < PHYS_STOPSPEED
+ v < PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
+ and, respectively:
+ v0 >= PHYS_STOPSPEED
+ v / (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION) >= PHYS_STOPSPEED
+ v >= PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
+ */
+ }
+ float addspeed = wishspeed - self.velocity * wishdir;
+ if (addspeed > 0)
+ {
+ float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
+ self.velocity += accelspeed * wishdir;
+ }
+ float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
+ if (!(GAMEPLAYFIX_NOGRAVITYONGROUND))
+ self.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1);
+ if (self.velocity * self.velocity)
+ PM_ClientMovement_Move();
+ if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
+ if (!IS_ONGROUND(self) || !GAMEPLAYFIX_NOGRAVITYONGROUND)
+ self.velocity_z -= g * 0.5;
+}
+
+void PM_air(float buttons_prev, float maxspd_mod)
+{
+ makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
+ vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
+ + v_right * PHYS_INPUT_MOVEVALUES(self).y;
+ // acceleration
+ vector wishdir = normalize(wishvel);
+ float wishspeed = vlen(wishvel);
+
+#ifdef SVQC
+ if (time >= self.teleport_time)
+#else
+ if (pmove_waterjumptime <= 0)
+#endif
+ {
+ float maxairspd = PHYS_MAXAIRSPEED * min(maxspd_mod, 1);
+
+ // apply air speed limit
+ float airaccelqw = PHYS_AIRACCEL_QW(self);
+ float wishspeed0 = wishspeed;
+ wishspeed = min(wishspeed, maxairspd);
+ if (IS_DUCKED(self))
+ wishspeed *= 0.5;
+ float airaccel = PHYS_AIRACCELERATE * min(maxspd_mod, 1);
+
+ float accelerating = (self.velocity * wishdir > 0);
+ float wishspeed2 = wishspeed;
+
+ // CPM: air control
+ if (PHYS_AIRSTOPACCELERATE)
+ {
+ vector curdir = normalize(vec2(self.velocity));
+ airaccel += (PHYS_AIRSTOPACCELERATE*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
+ }
+ // note that for straight forward jumping:
+ // step = accel * PHYS_INPUT_TIMELENGTH * wishspeed0;
+ // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
+ // -->
+ // dv/dt = accel * maxspeed (when slow)
+ // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
+ // log dv/dt = logaccel + logmaxspeed (when slow)
+ // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
+ float strafity = IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), -90) + IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), +90); // if one is nonzero, other is always zero
+ if (PHYS_MAXAIRSTRAFESPEED)
+ wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED*maxspd_mod));
+ if (PHYS_AIRSTRAFEACCELERATE)
+ airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE*maxspd_mod);
+ if (PHYS_AIRSTRAFEACCEL_QW(self))
+ airaccelqw =
+ (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(self) : PHYS_AIRACCEL_QW(self)) >= 0) ? +1 : -1)
+ *
+ (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(self)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(self))));
+ // !CPM
+
+ if (PHYS_WARSOWBUNNY_TURNACCEL && accelerating && PHYS_INPUT_MOVEVALUES(self).y == 0 && PHYS_INPUT_MOVEVALUES(self).x != 0)
+ PM_AirAccelerate(wishdir, wishspeed2);
+ else
+ PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(self), PHYS_AIRACCEL_SIDEWAYS_FRICTION / maxairspd, PHYS_AIRSPEEDLIMIT_NONQW(self));
+
+ if (PHYS_AIRCONTROL)
+ CPM_PM_Aircontrol(wishdir, wishspeed2);
+ }
+ float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
+ if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
+ self.velocity_z -= g * 0.5;
+ else
+ self.velocity_z -= g;
+ PM_ClientMovement_Move();
+ if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
+ if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
+ self.velocity_z -= g * 0.5;
+}
+
+// used for calculating airshots
+float PM_is_flying()
+{
+ if (IS_ONGROUND(self))
+ return 0;
+ if (self.waterlevel >= WATERLEVEL_SWIMMING)
+ return 0;
+ traceline(self.origin, self.origin - '0 0 48', MOVE_NORMAL, self);
+ return trace_fraction >= 1;
+}
+
+void PM_Main()
+{
+ float buttons = PHYS_INPUT_BUTTON_MASK(self);
+#ifdef CSQC
+ self.team = myteam + 1; // is this correct?
+ if (!(PHYS_INPUT_BUTTON_JUMP(self))) // !jump
+ UNSET_JUMP_HELD(self); // canjump = true
+ pmove_waterjumptime -= PHYS_INPUT_TIMELENGTH;
+#endif
+ PM_ClientMovement_UpdateStatus();
+
+#ifdef SVQC
+ WarpZone_PlayerPhysics_FixVAngle();
+#endif
+ float maxspeed_mod = 1;
+ maxspeed_mod *= PM_check_keepaway();
+ maxspeed_mod *= PHYS_HIGHSPEED;
+
+#ifdef SVQC
+ Physics_UpdateStats(maxspeed_mod);
+
+ if (self.PlayerPhysplug)
+ if (self.PlayerPhysplug())
+ return;
+#endif
+
+ PM_check_race_movetime();
+#ifdef SVQC
+ anticheat_physics();
+#endif
+
+ if (PM_check_specialcommand(buttons))
+ return;
+#ifdef SVQC
+ if (sv_maxidle > 0)
+ {
+ if (buttons != self.buttons_old || PHYS_INPUT_MOVEVALUES(self) != self.movement_old || PHYS_INPUT_ANGLES(self) != self.v_angle_old)
+ self.parm_idlesince = time;
+ }
+#endif
+ float buttons_prev = self.buttons_old;
+ self.buttons_old = buttons;
+ self.movement_old = PHYS_INPUT_MOVEVALUES(self);
+ self.v_angle_old = PHYS_INPUT_ANGLES(self);
+
+ PM_check_nickspam();
+
+ PM_check_punch();
+#ifdef SVQC
+ if (IS_BOT_CLIENT(self))
+ {
+ if (playerdemo_read())
+ return;
+ bot_think();
+ }
+
+ if (IS_PLAYER(self))
+#endif
+ {
+#ifdef SVQC
+ if (self.race_penalty)
+ if (time > self.race_penalty)
+ self.race_penalty = 0;
+#endif
+
+ float not_allowed_to_move = 0;
+#ifdef SVQC
+ if (self.race_penalty)
+ not_allowed_to_move = 1;
+#endif
+#ifdef SVQC
+ if (!autocvar_sv_ready_restart_after_countdown)
+ if (time < game_starttime)
+ not_allowed_to_move = 1;
+#endif
+
+ if (not_allowed_to_move)
+ {
+ self.velocity = '0 0 0';
+ self.movetype = MOVETYPE_NONE;
+#ifdef SVQC
+ self.disableclientprediction = 2;
+#endif
+ }
+#ifdef SVQC
+ else if (self.disableclientprediction == 2)
+ {
+ if (self.movetype == MOVETYPE_NONE)
+ self.movetype = MOVETYPE_WALK;
+ self.disableclientprediction = 0;
+ }
+#endif
+ }
+
+#ifdef SVQC
+ if (self.movetype == MOVETYPE_NONE)
+ return;
+
+ // when we get here, disableclientprediction cannot be 2
+ self.disableclientprediction = 0;
+#endif
+
+ PM_check_spider();
+
+ PM_check_frozen();
+
+ PM_check_blocked();
+
+ maxspeed_mod = 1;
+
+#ifdef SVQC
+ if (self.in_swamp) {
+ maxspeed_mod *= self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
+ }
+#endif
+
+ // conveyors: first fix velocity
+ if (self.conveyor.state)
+ self.velocity -= self.conveyor.movedir;
+
+#ifdef SVQC
+ MUTATOR_CALLHOOK(PlayerPhysics);
+#endif
+#ifdef CSQC
+ PM_multijump();
+#endif
+
+// float forcedodge = 1;
+// if(forcedodge) {
+//#ifdef CSQC
+// PM_dodging_checkpressedkeys();
+//#endif
+// PM_dodging();
+// PM_ClientMovement_Move();
+// return;
+// }
+
+#ifdef SVQC
+ if (!IS_PLAYER(self))
+ {
+ maxspeed_mod *= autocvar_sv_spectator_speed_multiplier;
+ if (!self.spectatorspeed)
+ self.spectatorspeed = maxspeed_mod;
+ if (self.impulse && self.impulse <= 19 || (self.impulse >= 200 && self.impulse <= 209) || (self.impulse >= 220 && self.impulse <= 229))
+ {
+ if (self.lastclassname != "player")
+ {
+ if (self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209))
+ self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
+ else if (self.impulse == 11)
+ self.spectatorspeed = maxspeed_mod;
+ else if (self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229))
+ self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
+ else if (self.impulse >= 1 && self.impulse <= 9)
+ self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
+ } // otherwise just clear
+ self.impulse = 0;
+ }
+ maxspeed_mod *= self.spectatorspeed;
+ }
+#endif
+
+#ifdef SVQC
+ // if dead, behave differently
+ // in CSQC, physics don't handle dead player
+ if (self.deadflag)
+ goto end;
+#endif
+
+#ifdef SVQC
+ if (!self.fixangle && !g_bugrigs)
+ self.angles = '0 1 0' * PHYS_INPUT_ANGLES(self).y;
+#endif
+
+#ifdef SVQC
+ if (IS_ONGROUND(self))
+ if (IS_PLAYER(self)) // no fall sounds for observers thank you very much
+ if (self.wasFlying)
+ {
+ self.wasFlying = 0;
+ if (self.waterlevel < WATERLEVEL_SWIMMING)
+ if (time >= self.ladder_time)
+ if (!self.hook)
+ {
+ self.nextstep = time + 0.3 + random() * 0.1;
+ trace_dphitq3surfaceflags = 0;
+ tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
+ if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
+ {
+ if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
+ GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
+ else
+ GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
+ }
+ }
+ }
+#endif
+
+ if (PM_is_flying())
+ self.wasFlying = 1;
+
+#ifdef SVQC
+ if (IS_PLAYER(self))
+#endif
+ CheckPlayerJump();
+
+ PM_check_jumppad();
+
+ if (self.flags & /* FL_WATERJUMP */ 2048)
+ {
+ 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 */ 2048;
+ self.teleport_time = 0;
+ }
+ }
+
+#ifdef SVQC
+ else if (g_bugrigs && IS_PLAYER(self))
+ RaceCarPhysics();
+#endif
+
+ else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
+ PM_fly(maxspeed_mod);
+
+ else if (self.waterlevel >= WATERLEVEL_SWIMMING)
+ PM_swim(maxspeed_mod);
+
+ else if (time < self.ladder_time)
+ PM_ladder(maxspeed_mod);
+
+ else if (ITEMS(self) & IT_USING_JETPACK)
+ PM_jetpack(maxspeed_mod);
+
+ else
+ {
+ if (IS_ONGROUND(self))
+ PM_walk(buttons_prev, maxspeed_mod);
+ else
+ PM_air(buttons_prev, maxspeed_mod);
+ }
+
+#ifdef SVQC
+ if (!IS_OBSERVER(self))
+ PM_check_race();
+#endif
+ PM_check_vortex();
+
+:end
+ if (IS_ONGROUND(self))
+ self.lastground = time;
+
+ // conveyors: then break velocity again
+ if (self.conveyor.state)
+ self.velocity += self.conveyor.movedir;
+
+#ifdef SVQC
+ self.lastflags = self.flags;
+#elif defined(CSQC)
+ self.lastflags = self.pmove_flags;
+#endif
+
+ self.lastclassname = self.classname;
+}
+
+#ifdef SVQC
+void SV_PlayerPhysics(void)
+#elif defined(CSQC)
+void CSQC_ClientMovement_PlayerMove_Frame(void)
+#endif
+{
+ PM_Main();
+}
\ No newline at end of file
--- /dev/null
+// Client/server mappings
+
+.entity conveyor;
+
+#ifdef CSQC
+
+ float player_multijump;
+ float player_jumpheight;
+
+ #define PHYS_INPUT_ANGLES(s) input_angles
+// TODO
+ #define PHYS_WORLD_ANGLES(s) input_angles
+
+ #define PHYS_INPUT_TIMELENGTH input_timelength
+ #define PHYS_INPUT_FRAMETIME serverdeltatime
+
+ #define PHYS_INPUT_MOVEVALUES(s) input_movevalues
+
+ #define PHYS_INPUT_BUTTON_MASK(s) (input_buttons | 128 * (input_movevalues_x < 0) | 256 * (input_movevalues_x > 0) | 512 * (input_movevalues_y < 0) | 1024 * (input_movevalues_y > 0))
+ #define PHYS_INPUT_BUTTON_ATCK(s) !!(input_buttons & 1)
+ #define PHYS_INPUT_BUTTON_JUMP(s) !!(input_buttons & 2)
+ #define PHYS_INPUT_BUTTON_ATCK2(s) !!(input_buttons & 4)
+ #define PHYS_INPUT_BUTTON_ZOOM(s) !!(input_buttons & 8)
+ #define PHYS_INPUT_BUTTON_CROUCH(s) !!(input_buttons & 16)
+ #define PHYS_INPUT_BUTTON_HOOK(s) !!(input_buttons & 32)
+ #define PHYS_INPUT_BUTTON_USE(s) !!(input_buttons & 64)
+ #define PHYS_INPUT_BUTTON_BACKWARD(s) !!(input_buttons & 128)
+ #define PHYS_INPUT_BUTTON_FORWARD(s) !!(input_buttons & 256)
+ #define PHYS_INPUT_BUTTON_LEFT(s) !!(input_buttons & 512)
+ #define PHYS_INPUT_BUTTON_RIGHT(s) !!(input_buttons & 1024)
+ #define PHYS_INPUT_BUTTON_JETPACK(s) !!(input_buttons & 2048)
+
+ #define PHYS_DEAD(s) s.csqcmodel_isdead
+
+ #define GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE !!(moveflags & MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE)
+ #define GAMEPLAYFIX_NOGRAVITYONGROUND cvar("sv_gameplayfix_nogravityonground")
+ #define GAMEPLAYFIX_Q2AIRACCELERATE cvar("sv_gameplayfix_q2airaccelerate")
+
+ #define IS_DUCKED(s) !!(s.pmove_flags & PMF_DUCKED)
+ #define SET_DUCKED(s) s.pmove_flags |= PMF_DUCKED
+ #define UNSET_DUCKED(s) s.pmove_flags &= ~PMF_DUCKED
+
+ #define IS_JUMP_HELD(s) !!(s.pmove_flags & PMF_JUMP_HELD)
+ #define SET_JUMP_HELD(s) s.pmove_flags |= PMF_JUMP_HELD
+ #define UNSET_JUMP_HELD(s) s.pmove_flags &= ~PMF_JUMP_HELD
+
+ #define IS_ONGROUND(s) !!(s.pmove_flags & PMF_ONGROUND)
+ #define SET_ONGROUND(s) s.pmove_flags |= PMF_ONGROUND
+ #define UNSET_ONGROUND(s) s.pmove_flags &= ~PMF_ONGROUND
+
+ #define WAS_ONGROUND(s) !!(s.lastflags & PMF_ONGROUND)
+
+ #define ITEMS(s) getstati(STAT_ITEMS, 0, 24)
+
+ #define PHYS_AMMO_FUEL(s) getstati(STAT_FUEL)
+
+ #define PHYS_FROZEN(s) getstati(STAT_FROZEN)
+
+ #define PHYS_DOUBLEJUMP getstati(STAT_DOUBLEJUMP)
+
+ #define PHYS_JUMPSPEEDCAP_MIN getstatf(STAT_MOVEVARS_JUMPSPEEDCAP_MIN)
+ #define PHYS_JUMPSPEEDCAP_MAX getstatf(STAT_MOVEVARS_JUMPSPEEDCAP_MAX)
+ #define PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS getstati(STAT_MOVEVARS_JUMPSPEEDCAP_DISABLE_ONRAMPS)
+
+ #define PHYS_TRACK_CANJUMP(s) getstati(STAT_MOVEVARS_TRACK_CANJUMP)
+ #define PHYS_ACCELERATE getstatf(STAT_MOVEVARS_ACCELERATE)
+ #define PHYS_AIRACCEL_QW(s) getstatf(STAT_MOVEVARS_AIRACCEL_QW)
+ #define PHYS_AIRACCEL_QW_STRETCHFACTOR(s) getstatf(STAT_MOVEVARS_AIRACCEL_QW_STRETCHFACTOR)
+ #define PHYS_AIRACCEL_SIDEWAYS_FRICTION getstatf(STAT_MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION)
+ #define PHYS_AIRACCELERATE getstatf(STAT_MOVEVARS_AIRACCELERATE)
+ #define PHYS_AIRCONTROL getstatf(STAT_MOVEVARS_AIRCONTROL)
+ #define PHYS_AIRCONTROL_PENALTY getstatf(STAT_MOVEVARS_AIRCONTROL_PENALTY)
+ #define PHYS_AIRCONTROL_POWER getstatf(STAT_MOVEVARS_AIRCONTROL_POWER)
+ #define PHYS_AIRSPEEDLIMIT_NONQW(s) getstatf(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW)
+ #define PHYS_AIRSTOPACCELERATE getstatf(STAT_MOVEVARS_AIRSTOPACCELERATE)
+ #define PHYS_AIRSTRAFEACCEL_QW(s) getstatf(STAT_MOVEVARS_AIRSTRAFEACCEL_QW)
+ #define PHYS_AIRSTRAFEACCELERATE getstatf(STAT_MOVEVARS_AIRSTRAFEACCELERATE)
+ #define PHYS_ENTGRAVITY(s) getstatf(STAT_MOVEVARS_ENTGRAVITY)
+ #define PHYS_FRICTION getstatf(STAT_MOVEVARS_FRICTION)
+ #define PHYS_FRICTION_SLICK getstatf(STAT_MOVEVARS_FRICTION_SLICK)
+ #define PHYS_FRICTION_ONLAND getstatf(STAT_MOVEVARS_FRICTION_ONLAND)
+ #define PHYS_GRAVITY getstatf(STAT_MOVEVARS_GRAVITY)
+ #define PHYS_HIGHSPEED getstatf(STAT_MOVEVARS_HIGHSPEED)
+ #define PHYS_JUMPVELOCITY getstatf(STAT_MOVEVARS_JUMPVELOCITY)
+ #define PHYS_MAXAIRSPEED getstatf(STAT_MOVEVARS_MAXAIRSPEED)
+ #define PHYS_MAXAIRSTRAFESPEED getstatf(STAT_MOVEVARS_MAXAIRSTRAFESPEED)
+ #define PHYS_MAXSPEED(s) getstatf(STAT_MOVEVARS_MAXSPEED)
+ #define PHYS_STEPHEIGHT getstatf(STAT_MOVEVARS_STEPHEIGHT)
+ #define PHYS_STOPSPEED getstatf(STAT_MOVEVARS_STOPSPEED)
+ #define PHYS_WARSOWBUNNY_ACCEL getstatf(STAT_MOVEVARS_WARSOWBUNNY_ACCEL)
+ #define PHYS_WARSOWBUNNY_BACKTOSIDERATIO getstatf(STAT_MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO)
+ #define PHYS_WARSOWBUNNY_AIRFORWARDACCEL getstatf(STAT_MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL)
+ #define PHYS_WARSOWBUNNY_TOPSPEED getstatf(STAT_MOVEVARS_WARSOWBUNNY_TOPSPEED)
+ #define PHYS_WARSOWBUNNY_TURNACCEL getstatf(STAT_MOVEVARS_WARSOWBUNNY_TURNACCEL)
+
+ #define PHYS_JETPACK_ACCEL_UP getstatf(STAT_JETPACK_ACCEL_UP)
+ #define PHYS_JETPACK_ACCEL_SIDE getstatf(STAT_JETPACK_ACCEL_SIDE)
+ #define PHYS_JETPACK_ANTIGRAVITY getstatf(STAT_JETPACK_ANTIGRAVITY)
+ #define PHYS_JETPACK_FUEL getstatf(STAT_JETPACK_FUEL)
+ #define PHYS_JETPACK_MAXSPEED_UP getstatf(STAT_JETPACK_MAXSPEED_UP)
+ #define PHYS_JETPACK_MAXSPEED_SIDE getstatf(STAT_JETPACK_MAXSPEED_SIDE)
+
+ #define PHYS_DODGING_FROZEN getstati(STAT_DODGING_FROZEN)
+
+#elif defined(SVQC)
+
+ #define PHYS_INPUT_ANGLES(s) s.v_angle
+ #define PHYS_WORLD_ANGLES(s) s.angles
+
+ #define PHYS_INPUT_TIMELENGTH frametime
+ #define PHYS_INPUT_FRAMETIME sys_frametime
+
+ #define PHYS_INPUT_MOVEVALUES(s) s.movement
+ // TODO: cache
+ #define PHYS_INPUT_BUTTON_MASK(s) (s.BUTTON_ATCK | 2 * s.BUTTON_JUMP | 4 * s.BUTTON_ATCK2 | 8 * s.BUTTON_ZOOM | 16 * s.BUTTON_CROUCH | 32 * s.BUTTON_HOOK | 64 * s.BUTTON_USE | 128 * (s.movement_x < 0) | 256 * (s.movement_x > 0) | 512 * (s.movement_y < 0) | 1024 * (s.movement_y > 0))
+ #define PHYS_INPUT_BUTTON_ATCK(s) s.BUTTON_ATCK
+ #define PHYS_INPUT_BUTTON_JUMP(s) s.BUTTON_JUMP
+ #define PHYS_INPUT_BUTTON_ATCK2(s) s.BUTTON_ATCK2
+ #define PHYS_INPUT_BUTTON_ZOOM(s) s.BUTTON_ZOOM
+ #define PHYS_INPUT_BUTTON_CROUCH(s) s.BUTTON_CROUCH
+ #define PHYS_INPUT_BUTTON_HOOK(s) s.BUTTON_HOOK
+ #define PHYS_INPUT_BUTTON_USE(s) s.BUTTON_USE
+ #define PHYS_INPUT_BUTTON_BACKWARD(s) (s.movement_x < 0)
+ #define PHYS_INPUT_BUTTON_FORWARD(s) (s.movement_x > 0)
+ #define PHYS_INPUT_BUTTON_LEFT(s) (s.movement_y < 0)
+ #define PHYS_INPUT_BUTTON_RIGHT(s) (s.movement_y > 0)
+ #define PHYS_INPUT_BUTTON_JETPACK(s) s.BUTTON_JETPACK
+
+ #define PHYS_DEAD(s) s.deadflag != DEAD_NO
+
+ #define GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE autocvar_sv_gameplayfix_gravityunaffectedbyticrate
+ #define GAMEPLAYFIX_NOGRAVITYONGROUND cvar("sv_gameplayfix_nogravityonground")
+ #define GAMEPLAYFIX_Q2AIRACCELERATE autocvar_sv_gameplayfix_q2airaccelerate
+
+ #define IS_DUCKED(s) s.crouch
+ #define SET_DUCKED(s) s.crouch = TRUE
+ #define UNSET_DUCKED(s) s.crouch = FALSE
+
+ #define IS_JUMP_HELD(s) !(s.flags & FL_JUMPRELEASED)
+ #define SET_JUMP_HELD(s) s.flags &= ~FL_JUMPRELEASED
+ #define UNSET_JUMP_HELD(s) s.flags |= FL_JUMPRELEASED
+
+ #define IS_ONGROUND(s) !!(self.flags & FL_ONGROUND)
+ #define SET_ONGROUND(s) s.flags |= FL_ONGROUND
+ #define UNSET_ONGROUND(s) s.flags &= ~FL_ONGROUND
+
+ #define WAS_ONGROUND(s) !!((s).lastflags & FL_ONGROUND)
+
+ #define ITEMS(s) s.items
+
+ #define PHYS_AMMO_FUEL(s) s.ammo_fuel
+
+ #define PHYS_FROZEN(s) s.frozen
+
+ #define PHYS_DOUBLEJUMP autocvar_sv_doublejump
+
+ #define PHYS_JUMPSPEEDCAP_MIN autocvar_sv_jumpspeedcap_min
+ #define PHYS_JUMPSPEEDCAP_MAX autocvar_sv_jumpspeedcap_max
+ #define PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS autocvar_sv_jumpspeedcap_max_disable_on_ramps
+
+ #define PHYS_TRACK_CANJUMP(s) s.cvar_cl_movement_track_canjump
+ #define PHYS_ACCELERATE autocvar_sv_accelerate
+ #define PHYS_AIRACCEL_QW(s) s.stat_sv_airaccel_qw
+ #define PHYS_AIRACCEL_QW_STRETCHFACTOR(s) autocvar_sv_airaccel_qw_stretchfactor
+ #define PHYS_AIRACCEL_SIDEWAYS_FRICTION autocvar_sv_airaccel_sideways_friction
+ #define PHYS_AIRACCELERATE autocvar_sv_airaccelerate
+ #define PHYS_AIRCONTROL autocvar_sv_aircontrol
+ #define PHYS_AIRCONTROL_PENALTY autocvar_sv_aircontrol_penalty
+ #define PHYS_AIRCONTROL_POWER autocvar_sv_aircontrol_power
+ #define PHYS_AIRSPEEDLIMIT_NONQW(s) s.stat_sv_airspeedlimit_nonqw
+ #define PHYS_AIRSTOPACCELERATE autocvar_sv_airstopaccelerate
+ #define PHYS_AIRSTRAFEACCEL_QW(s) s.stat_sv_airstrafeaccel_qw
+ #define PHYS_AIRSTRAFEACCELERATE autocvar_sv_airstrafeaccelerate
+ #define PHYS_ENTGRAVITY(s) s.gravity
+ #define PHYS_FRICTION autocvar_sv_friction
+ #define PHYS_FRICTION_SLICK autocvar_sv_friction_slick
+ #define PHYS_FRICTION_ONLAND autocvar_sv_friction_on_land
+ #define PHYS_GRAVITY autocvar_sv_gravity
+ #define PHYS_HIGHSPEED autocvar_g_movement_highspeed
+ #define PHYS_JUMPVELOCITY autocvar_sv_jumpvelocity
+ #define PHYS_MAXAIRSPEED autocvar_sv_maxairspeed
+ #define PHYS_MAXAIRSTRAFESPEED autocvar_sv_maxairstrafespeed
+ #define PHYS_MAXSPEED(s) s.stat_sv_maxspeed
+ #define PHYS_STEPHEIGHT autocvar_sv_stepheight
+ #define PHYS_STOPSPEED autocvar_sv_stopspeed
+ #define PHYS_WARSOWBUNNY_ACCEL autocvar_sv_warsowbunny_accel
+ #define PHYS_WARSOWBUNNY_BACKTOSIDERATIO autocvar_sv_warsowbunny_backtosideratio
+ #define PHYS_WARSOWBUNNY_AIRFORWARDACCEL autocvar_sv_warsowbunny_airforwardaccel
+ #define PHYS_WARSOWBUNNY_TOPSPEED autocvar_sv_warsowbunny_topspeed
+ #define PHYS_WARSOWBUNNY_TURNACCEL autocvar_sv_warsowbunny_turnaccel
+
+ #define PHYS_JETPACK_ACCEL_UP autocvar_g_jetpack_acceleration_up
+ #define PHYS_JETPACK_ACCEL_SIDE autocvar_g_jetpack_acceleration_side
+ #define PHYS_JETPACK_ANTIGRAVITY autocvar_g_jetpack_antigravity
+ #define PHYS_JETPACK_FUEL autocvar_g_jetpack_fuel
+ #define PHYS_JETPACK_MAXSPEED_UP autocvar_g_jetpack_maxspeed_up
+ #define PHYS_JETPACK_MAXSPEED_SIDE autocvar_g_jetpack_maxspeed_side
+
+ #define PHYS_DODGING_FROZEN autocvar_sv_dodging_frozen
+
+#endif
\ No newline at end of file
// 188 empty?
// 189 empty?
// 190 empty?
-// 191 empty?
-// 192 empty?
-// 193 empty?
-// 194 empty?
-// 195 empty?
-// 196 empty?
-// 197 empty?
-// 198 empty?
-// 199 empty?
-// 200 empty?
-// 201 empty?
-// 202 empty?
-// 203 empty?
-// 204 empty?
-// 205 empty?
-// 206 empty?
-// 207 empty?
-// 208 empty?
-// 209 empty?
-// 210 empty?
-// 211 empty?
-// 212 empty?
-// 213 empty?
-// 214 empty?
-// 215 empty?
-// 216 empty?
-// 217 empty?
-// 218 empty?
-// 219 empty?
+const float STAT_MOVEVARS_FRICTION_SLICK = 191;
+const float STAT_MOVEVARS_FRICTION_ONLAND = 192;
+const float STAT_MOVEVARS_JUMPSPEEDCAP_DISABLE_ONRAMPS = 193;
+const float STAT_MOVEVARS_JUMPSPEEDCAP_MAX = 194;
+const float STAT_MOVEVARS_JUMPSPEEDCAP_MIN = 195;
+const float STAT_DOUBLEJUMP = 196;
+const float STAT_MOVEVARS_TRACK_CANJUMP = 197;
+const float STAT_MULTIJUMP_ADD = 198;
+const float STAT_MULTIJUMP_SPEED = 199;
+const float STAT_MULTIJUMP = 200;
+const float STAT_DODGING_TIMEOUT = 201;
+const float STAT_DODGING_WALL = 202;
+const float STAT_DODGING_UP_SPEED = 203;
+const float STAT_DODGING_RAMP_TIME = 204;
+const float STAT_DODGING_HEIGHT_THRESHOLD = 205;
+const float STAT_DODGING_DISTANCE_THRESHOLD = 206;
+const float STAT_DODGING_HORIZ_SPEED = 207;
+const float STAT_DODGING_DELAY = 208;
+const float STAT_DODGING_FROZEN_NO_DOUBLETAP = 209;
+const float STAT_DODGING_HORIZ_SPEED_FROZEN = 210;
+const float STAT_DODGING = 211;
+const float STAT_DODGING_FROZEN = 212;
+const float STAT_JETPACK_MAXSPEED_UP = 213;
+const float STAT_JETPACK_MAXSPEED_SIDE = 214;
+const float STAT_JETPACK_FUEL = 215;
+const float STAT_JETPACK_ANTIGRAVITY = 216;
+const float STAT_JETPACK_ACCEL_SIDE = 217;
+const float STAT_JETPACK_ACCEL_UP = 218;
+const float STAT_MOVEVARS_HIGHSPEED = 219;
const float STAT_MOVEVARS_AIRACCEL_QW_STRETCHFACTOR = 220;
const float STAT_MOVEVARS_AIRCONTROL_PENALTY = 221;
const float STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW = 222;
*/
var float autocvar_cl_movement_errorcompensation = 0;
+var float autocvar_cl_movement = 2; // testing purposes
// engine stuff
#define REFDEFFLAG_TELEPORTED 1
csqcplayer_status = CSQCPLAYERSTATUS_PREDICTED;
}
+void CSQC_ClientMovement_PlayerMove_Frame();
+
+void CSQCPlayer_Physics(void)
+{
+ switch(autocvar_cl_movement)
+ {
+ case 1: runstandardplayerphysics(self); break;
+ case 2: CSQC_ClientMovement_PlayerMove_Frame(); break;
+ }
+}
+
void CSQCPlayer_PredictTo(float endframe, float apply_error)
{
CSQCPlayer_Unpredict();
{
if (!getinputstate(csqcplayer_moveframe))
break;
- runstandardplayerphysics(self);
+ CSQCPlayer_Physics();
CSQCPlayer_SetMinsMaxs();
csqcplayer_moveframe++;
}
float( float b, ... ) max = #95;
float(float minimum, float val, float maximum) bound = #96;
float(float f, float f) pow = #97;
+entity(entity start, .entity fld, entity match) findentity = #98;
entity(entity start, .float fld, float match) findfloat = #98;
float(string s) checkextension = #99;
// FrikaC and Telejano range #100-#199
float autocvar_sv_eventlog_files_timestamps;
float autocvar_sv_friction;
float autocvar_sv_friction_on_land;
+var float autocvar_sv_friction_slick = 0.5;
float autocvar_sv_gameplayfix_q2airaccelerate;
float autocvar_sv_gentle;
#define autocvar_sv_gravity cvar("sv_gravity")
string autocvar_sv_intermission_cdtrack;
-string autocvar_sv_jumpspeedcap_max;
+float autocvar_sv_jumpspeedcap_max;
float autocvar_sv_jumpspeedcap_max_disable_on_ramps;
-string autocvar_sv_jumpspeedcap_min;
+float autocvar_sv_jumpspeedcap_min;
float autocvar_sv_jumpvelocity;
float autocvar_sv_logscores_bots;
float autocvar_sv_logscores_console;
void GetPressedKeys(void) {
MUTATOR_CALLHOOK(GetPressedKeys);
- if (self.movement_x > 0) // get if movement keys are pressed
- { // forward key pressed
- self.pressedkeys |= KEY_FORWARD;
- self.pressedkeys &= ~KEY_BACKWARD;
- }
- else if (self.movement_x < 0)
- { // backward key pressed
- self.pressedkeys |= KEY_BACKWARD;
- self.pressedkeys &= ~KEY_FORWARD;
- }
- else
- { // no x input
- self.pressedkeys &= ~KEY_FORWARD;
- self.pressedkeys &= ~KEY_BACKWARD;
- }
-
- if (self.movement_y > 0)
- { // right key pressed
- self.pressedkeys |= KEY_RIGHT;
- self.pressedkeys &= ~KEY_LEFT;
- }
- else if (self.movement_y < 0)
- { // left key pressed
- self.pressedkeys |= KEY_LEFT;
- self.pressedkeys &= ~KEY_RIGHT;
- }
- else
- { // no y input
- self.pressedkeys &= ~KEY_RIGHT;
- self.pressedkeys &= ~KEY_LEFT;
- }
-
- if (self.BUTTON_JUMP) // get if jump and crouch keys are pressed
- self.pressedkeys |= KEY_JUMP;
- else
- self.pressedkeys &= ~KEY_JUMP;
- if (self.BUTTON_CROUCH)
- self.pressedkeys |= KEY_CROUCH;
- else
- self.pressedkeys &= ~KEY_CROUCH;
-
- if (self.BUTTON_ATCK)
- self.pressedkeys |= KEY_ATCK;
- else
- self.pressedkeys &= ~KEY_ATCK;
- if (self.BUTTON_ATCK2)
- self.pressedkeys |= KEY_ATCK2;
- else
- self.pressedkeys &= ~KEY_ATCK2;
+ #define X(var,bit,flag) (flag ? var |= bit : var &= ~bit)
+ X(self.pressedkeys, KEY_FORWARD, PHYS_INPUT_MOVEVALUES(self)_x > 0);
+ X(self.pressedkeys, KEY_BACKWARD, PHYS_INPUT_MOVEVALUES(self)_x < 0);
+ X(self.pressedkeys, KEY_RIGHT, PHYS_INPUT_MOVEVALUES(self)_y > 0);
+ X(self.pressedkeys, KEY_LEFT, PHYS_INPUT_MOVEVALUES(self)_y < 0);
+
+ X(self.pressedkeys, KEY_JUMP, PHYS_INPUT_BUTTON_JUMP(self));
+ X(self.pressedkeys, KEY_CROUCH, PHYS_INPUT_BUTTON_CROUCH(self));
+ X(self.pressedkeys, KEY_ATCK, PHYS_INPUT_BUTTON_ATCK(self));
+ X(self.pressedkeys, KEY_ATCK2, PHYS_INPUT_BUTTON_ATCK2(self));
+ #undef X
}
/*
+++ /dev/null
-.float race_penalty;
-.float restart_jump;
-
-.float ladder_time;
-.entity ladder_entity;
-.float gravity;
-.float swamp_slowdown;
-.float lastflags;
-.float lastground;
-.float wasFlying;
-.float spectatorspeed;
-
-/*
-=============
-PlayerJump
-
-When you press the jump key
-returns TRUE if handled
-=============
-*/
-float PlayerJump (void)
-{
- if(self.frozen)
- return TRUE; // no jumping in freezetag when frozen
-
- if(self.player_blocked)
- return TRUE; // no jumping while blocked
-
- float doublejump = FALSE;
- float mjumpheight = autocvar_sv_jumpvelocity;
-
- player_multijump = doublejump;
- player_jumpheight = mjumpheight;
- if(MUTATOR_CALLHOOK(PlayerJump))
- 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)
- {
- doublejump = TRUE;
-
- // we MUST clip velocity here!
- float f;
- f = self.velocity * trace_plane_normal;
- if(f < 0)
- self.velocity -= f * trace_plane_normal;
- }
- }
-
- if (self.waterlevel >= WATERLEVEL_SWIMMING)
- {
- self.velocity_z = self.stat_sv_maxspeed * 0.7;
- return TRUE;
- }
-
- if (!doublejump)
- if (!(self.flags & FL_ONGROUND))
- return !(self.flags & FL_JUMPRELEASED);
-
- if(self.cvar_cl_movement_track_canjump)
- if (!(self.flags & FL_JUMPRELEASED))
- return TRUE;
-
- // sv_jumpspeedcap_min/sv_jumpspeedcap_max act as baseline
- // velocity bounds. Final velocity is bound between (jumpheight *
- // min + jumpheight) and (jumpheight * max + jumpheight);
-
- if(autocvar_sv_jumpspeedcap_min != "")
- {
- float minjumpspeed;
-
- minjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_min);
-
- 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))
- {
- float maxjumpspeed;
-
- maxjumpspeed = mjumpheight * stof(autocvar_sv_jumpspeedcap_max);
-
- if (self.velocity_z > maxjumpspeed)
- mjumpheight -= self.velocity_z - maxjumpspeed;
- }
- }
-
- if(!(self.lastflags & FL_ONGROUND))
- {
- if(autocvar_speedmeter)
- dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
- if(self.lastground < time - 0.3)
- {
- self.velocity_x *= (1 - autocvar_sv_friction_on_land);
- self.velocity_y *= (1 - autocvar_sv_friction_on_land);
- }
- if(self.jumppadcount > 1)
- dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
- self.jumppadcount = 0;
- }
-
- 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);
-
- 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()
-{
- vector start, end;
-
-// check for a jump-out-of-water
- makevectors (self.angles);
- start = self.origin;
- start_z = start_z + 8;
- v_forward_z = 0;
- normalize(v_forward);
- end = start + v_forward*24;
- traceline (start, end, TRUE, self);
- if (trace_fraction < 1)
- { // solid at waist
- start_z = start_z + self.maxs_z - 8;
- end = start + v_forward*24;
- self.movedir = trace_plane_normal * -50;
- traceline (start, end, TRUE, self);
- if (trace_fraction == 1)
- { // open at eye level
- self.flags |= FL_WATERJUMP;
- self.velocity_z = 225;
- self.flags &= ~FL_JUMPRELEASED;
- self.teleport_time = time + 2; // safety net
- return;
- }
- }
-}
-
-.float jetpack_stopped;
-// Hack: shouldn't need to know about this
-.float multijump_count;
-void CheckPlayerJump()
-{
- 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)
- CheckWaterJump ();
-}
-
-float racecar_angle(float forward, float down)
-{
- float ret, angle_mult;
-
- if(forward < 0)
- {
- forward = -forward;
- down = -down;
- }
-
- ret = vectoyaw('0 1 0' * down + '1 0 0' * forward);
-
- angle_mult = forward / (800 + forward);
-
- if(ret > 180)
- return ret * angle_mult + 360 * (1 - angle_mult);
- else
- return ret * angle_mult;
-}
-
-void RaceCarPhysics()
-{
- // using this move type for "big rigs"
- // the engine does not push the entity!
-
- float accel, steer, f, myspeed, steerfactor;
- 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);
-
- if(g_bugrigs_reverse_speeding)
- {
- if(accel < 0)
- {
- // back accel is DIGITAL
- // to prevent speedhack
- if(accel < -0.5)
- accel = -1;
- else
- accel = 0;
- }
- }
-
- self.angles_x = 0;
- self.angles_z = 0;
- makevectors(self.angles); // new forward direction!
-
- if(self.flags & FL_ONGROUND || g_bugrigs_air_steering)
- {
- float upspeed, accelfactor;
-
- myspeed = self.velocity * v_forward;
- upspeed = self.velocity * v_up;
-
- // responsiveness factor for steering and acceleration
- f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
- //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
-
- if(myspeed < 0 && g_bugrigs_reverse_spinning)
- steerfactor = -myspeed * g_bugrigs_steer;
- else
- steerfactor = -myspeed * f * g_bugrigs_steer;
-
- if(myspeed < 0 && g_bugrigs_reverse_speeding)
- accelfactor = g_bugrigs_accel;
- else
- accelfactor = f * g_bugrigs_accel;
- //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
-
- if(accel < 0)
- {
- if(myspeed > 0)
- {
- myspeed = max(0, myspeed - frametime * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
- }
- else
- {
- if(!g_bugrigs_reverse_speeding)
- myspeed = min(0, myspeed + frametime * g_bugrigs_friction_floor);
- }
- }
- else
- {
- if(myspeed >= 0)
- {
- myspeed = max(0, myspeed - frametime * g_bugrigs_friction_floor);
- }
- else
- {
- if(g_bugrigs_reverse_stopping)
- myspeed = 0;
- else
- myspeed = min(0, myspeed + frametime * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
- }
- }
- // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
- //MAXIMA: friction(v) := g_bugrigs_friction_floor;
-
- self.angles_y += steer * frametime * steerfactor; // apply steering
- makevectors(self.angles); // new forward direction!
-
- myspeed += accel * accelfactor * frametime;
-
- rigvel = myspeed * v_forward + '0 0 1' * upspeed;
- }
- else
- {
- myspeed = vlen(self.velocity);
-
- // responsiveness factor for steering and acceleration
- f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
- steerfactor = -myspeed * f;
- self.angles_y += steer * frametime * steerfactor; // apply steering
-
- rigvel = self.velocity;
- makevectors(self.angles); // new forward direction!
- }
-
- rigvel = rigvel * max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * frametime);
- //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
- //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
- //MAXIMA: solve(total_acceleration(v) = 0, v);
-
- if(g_bugrigs_planar_movement)
- {
- vector rigvel_xy, neworigin, up;
- float mt;
-
- rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
- rigvel_xy = vec2(rigvel);
-
- if(g_bugrigs_planar_movement_car_jumping)
- mt = MOVE_NORMAL;
- else
- mt = MOVE_NOMONSTERS;
-
- tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
- up = trace_endpos - self.origin;
-
- // BUG RIGS: align the move to the surface instead of doing collision testing
- // can we move?
- 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);
-
- if(trace_fraction < 0.5)
- {
- trace_fraction = 1;
- neworigin = self.origin;
- }
- else
- neworigin = trace_endpos;
-
- if(trace_fraction < 1)
- {
- // 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
- +
- '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)
- );
- self.flags |= FL_ONGROUND;
- }
- else
- {
- // now set angles_x so that the car points forward, but is tilted in velocity direction
- self.flags &= ~FL_ONGROUND;
- }
-
- self.velocity = (neworigin - self.origin) * (1.0 / frametime);
- self.movetype = MOVETYPE_NOCLIP;
- }
- else
- {
- rigvel_z -= frametime * autocvar_sv_gravity; // 4x gravity plays better
- self.velocity = rigvel;
- self.movetype = MOVETYPE_FLY;
- }
-
- trace_fraction = 1;
- tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
- if(trace_fraction != 1)
- {
- self.angles = vectoangles2(
- '1 0 0' * v_forward_x * 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),
- trace_plane_normal
- );
- }
- else
- {
- vector vel_local;
-
- vel_local_x = v_forward * self.velocity;
- 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);
- }
-
- // smooth the angles
- vector vf1, vu1, smoothangles;
- makevectors(self.angles);
- f = bound(0, frametime * g_bugrigs_angle_smoothing, 1);
- if(f == 0)
- f = 1;
- vf1 = v_forward * f;
- vu1 = v_up * f;
- makevectors(angles_save);
- 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;
-}
-
-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 = remainder(angle, 360) / 45;
- if(angle > 1)
- return 0;
- if(angle < -1)
- return 0;
- return 1 - fabs(angle);
-}
-
-float GeomLerp(float a, float lerp, float b)
-{
- if(a == 0)
- {
- if(lerp < 1)
- return 0;
- else
- return b;
- }
- if(b == 0)
- {
- if(lerp > 0)
- return 0;
- else
- return a;
- }
- return a * pow(fabs(b / a), lerp);
-}
-
-void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
-{
- float zspeed, xyspeed, dot, k;
-
-#if 0
- // this doesn't play well with analog input
- if(self.movement_x == 0 || self.movement_y != 0)
- return; // can't control movement if not moving forward or backward
- k = 32;
-#else
- k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
- if(k <= 0)
- return;
-#endif
-
- k *= bound(0, wishspeed / autocvar_sv_maxairspeed, 1);
-
- zspeed = self.velocity_z;
- self.velocity_z = 0;
- xyspeed = vlen(self.velocity); self.velocity = normalize(self.velocity);
-
- dot = self.velocity * wishdir;
-
- if(dot > 0) // we can't change direction while slowing down
- {
- k *= pow(dot, autocvar_sv_aircontrol_power)*frametime;
- xyspeed = max(0, xyspeed - autocvar_sv_aircontrol_penalty * sqrt(max(0, 1 - dot*dot)) * k/32);
- k *= autocvar_sv_aircontrol;
- self.velocity = normalize(self.velocity * xyspeed + wishdir * k);
- }
-
- self.velocity = self.velocity * xyspeed;
- self.velocity_z = zspeed;
-}
-
-float AdjustAirAccelQW(float accelqw, float factor)
-{
- return copysign(bound(0.000001, 1 - (1 - fabs(accelqw)) * factor, 1), accelqw);
-}
-
-// example config for alternate speed clamping:
-// sv_airaccel_qw 0.8
-// sv_airaccel_sideways_friction 0
-// prvm_globalset server speedclamp_mode 1
-// (or 2)
-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;
- vector vel_perpend;
- float step;
-
- vector vel_xy;
- float vel_xy_current;
- float vel_xy_backward, vel_xy_forward;
- float speedclamp;
-
- if(stretchfactor > 0)
- speedclamp = stretchfactor;
- else if(accelqw < 0)
- speedclamp = 1; // full clamping, no stretch
- else
- speedclamp = -1; // no clamping
-
- if(accelqw < 0)
- accelqw = -accelqw;
-
- if(autocvar_sv_gameplayfix_q2airaccelerate)
- wishspeed0 = wishspeed;
-
- vel_straight = self.velocity * wishdir;
- vel_z = self.velocity_z;
- vel_xy = vec2(self.velocity);
- vel_perpend = vel_xy - vel_straight * wishdir;
-
- step = accel * frametime * wishspeed0;
-
- vel_xy_current = vlen(vel_xy);
- if(speedlimit)
- accelqw = AdjustAirAccelQW(accelqw, (speedlimit - bound(wishspeed, vel_xy_current, speedlimit)) / max(1, speedlimit - wishspeed));
- vel_xy_forward = vel_xy_current + bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
- vel_xy_backward = vel_xy_current - bound(0, wishspeed + vel_xy_current, step) * accelqw - step * (1 - accelqw);
- if(vel_xy_backward < 0)
- vel_xy_backward = 0; // not that it REALLY occurs that this would cause wrong behaviour afterwards
-
- vel_straight = vel_straight + bound(0, wishspeed - vel_straight, step) * accelqw + step * (1 - accelqw);
-
- if(sidefric < 0 && (vel_perpend*vel_perpend))
- // negative: only apply so much sideways friction to stay below the speed you could get by "braking"
- {
- float f, fminimum;
- f = max(0, 1 + frametime * wishspeed * sidefric);
- fminimum = (vel_xy_backward*vel_xy_backward - vel_straight*vel_straight) / (vel_perpend*vel_perpend);
- // this cannot be > 1
- if(fminimum <= 0)
- vel_perpend = vel_perpend * max(0, f);
- else
- {
- fminimum = sqrt(fminimum);
- vel_perpend = vel_perpend * max(fminimum, f);
- }
- }
- else
- vel_perpend = vel_perpend * max(0, 1 - frametime * wishspeed * sidefric);
-
- vel_xy = vel_straight * wishdir + vel_perpend;
-
- if(speedclamp >= 0)
- {
- float vel_xy_preclamp;
- vel_xy_preclamp = vlen(vel_xy);
- if(vel_xy_preclamp > 0) // prevent division by zero
- {
- vel_xy_current += (vel_xy_forward - vel_xy_current) * speedclamp;
- if(vel_xy_current < vel_xy_preclamp)
- vel_xy = vel_xy * (vel_xy_current / vel_xy_preclamp);
- }
- }
-
- self.velocity = vel_xy + vel_z * '0 0 1';
-}
-
-void PM_AirAccelerate(vector wishdir, float wishspeed)
-{
- vector curvel, wishvel, acceldir, curdir;
- float addspeed, accelspeed, curspeed, f;
- float dot;
-
- if(wishspeed == 0)
- return;
-
- curvel = self.velocity;
- curvel_z = 0;
- curspeed = vlen(curvel);
-
- if(wishspeed > curspeed * 1.01)
- {
- wishspeed = min(wishspeed, curspeed + autocvar_sv_warsowbunny_airforwardaccel * self.stat_sv_maxspeed * frametime);
- }
- else
- {
- f = max(0, (autocvar_sv_warsowbunny_topspeed - curspeed) / (autocvar_sv_warsowbunny_topspeed - self.stat_sv_maxspeed));
- wishspeed = max(curspeed, self.stat_sv_maxspeed) + autocvar_sv_warsowbunny_accel * f * self.stat_sv_maxspeed * frametime;
- }
- wishvel = wishdir * wishspeed;
- acceldir = wishvel - curvel;
- addspeed = vlen(acceldir);
- acceldir = normalize(acceldir);
-
- accelspeed = min(addspeed, autocvar_sv_warsowbunny_turnaccel * self.stat_sv_maxspeed * frametime);
-
- if(autocvar_sv_warsowbunny_backtosideratio < 1)
- {
- curdir = normalize(curvel);
- dot = acceldir * curdir;
- if(dot < 0)
- acceldir = acceldir - (1 - autocvar_sv_warsowbunny_backtosideratio) * dot * curdir;
- }
-
- self.velocity += accelspeed * acceldir;
-}
-
-.vector movement_old;
-.float buttons_old;
-.vector v_angle_old;
-.string lastclassname;
-
-.float() PlayerPhysplug;
-
-string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
-.float specialcommand_pos;
-void SpecialCommand()
-{
-#ifdef TETRIS
- TetrisImpulse();
-#else
- if(!CheatImpulse(99))
- print("A hollow voice says \"Plugh\".\n");
-#endif
-}
-
-float speedaward_speed;
-string speedaward_holder;
-string speedaward_uid;
-void race_send_speedaward(float msg)
-{
- // send the best speed of the round
- WriteByte(msg, SVC_TEMPENTITY);
- WriteByte(msg, TE_CSQC_RACE);
- WriteByte(msg, RACE_NET_SPEED_AWARD);
- WriteInt24_t(msg, floor(speedaward_speed+0.5));
- WriteString(msg, speedaward_holder);
-}
-
-float speedaward_alltimebest;
-string speedaward_alltimebest_holder;
-string speedaward_alltimebest_uid;
-void race_send_speedaward_alltimebest(float msg)
-{
- // send the best speed
- WriteByte(msg, SVC_TEMPENTITY);
- WriteByte(msg, TE_CSQC_RACE);
- WriteByte(msg, RACE_NET_SPEED_AWARD_BEST);
- WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
- WriteString(msg, speedaward_alltimebest_holder);
-}
-
-string GetMapname(void);
-float speedaward_lastupdate;
-float speedaward_lastsent;
-void SV_PlayerPhysics()
-{
- vector wishvel, wishdir, v;
- float wishspeed, f, maxspd_mod, spd, maxairspd, airaccel, swampspd_mod, buttons;
- string temps;
- float buttons_prev;
- float not_allowed_to_move;
- string c;
-
- WarpZone_PlayerPhysics_FixVAngle();
-
- maxspd_mod = 1;
- if(self.ballcarried)
- if(g_keepaway)
- maxspd_mod *= autocvar_g_keepaway_ballcarrier_highspeed;
-
- maxspd_mod *= autocvar_g_movement_highspeed;
-
- // fix physics stats for g_movement_highspeed
- // TODO maybe rather use maxairspeed? needs testing
- self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
- if(autocvar_sv_airstrafeaccel_qw)
- self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
- else
- self.stat_sv_airstrafeaccel_qw = 0;
- self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
- self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
-
- if(self.PlayerPhysplug)
- if(self.PlayerPhysplug())
- return;
-
- self.race_movetime_frac += frametime;
- f = floor(self.race_movetime_frac);
- self.race_movetime_frac -= f;
- self.race_movetime_count += f;
- self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
-
- 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);
-
- if(!buttons)
- c = "x";
- else if(buttons == 1)
- c = "1";
- else if(buttons == 2)
- c = " ";
- else if(buttons == 128)
- c = "s";
- else if(buttons == 256)
- c = "w";
- else if(buttons == 512)
- c = "a";
- else if(buttons == 1024)
- c = "d";
- else
- c = "?";
-
- if(c == substring(specialcommand, self.specialcommand_pos, 1))
- {
- self.specialcommand_pos += 1;
- if(self.specialcommand_pos >= strlen(specialcommand))
- {
- self.specialcommand_pos = 0;
- SpecialCommand();
- return;
- }
- }
- else if(self.specialcommand_pos && (c != substring(specialcommand, self.specialcommand_pos - 1, 1)))
- self.specialcommand_pos = 0;
-
- if(sv_maxidle > 0)
- {
- if(buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
- self.parm_idlesince = time;
- }
- buttons_prev = self.buttons_old;
- self.buttons_old = buttons;
- self.movement_old = self.movement;
- self.v_angle_old = self.v_angle;
-
- if(time < self.nickspamtime)
- if(self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
- {
- // slight annoyance for nick change scripts
- self.movement = -1 * self.movement;
- self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
-
- 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!
- {
- 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;
- }
- }
-
- if (self.punchangle != '0 0 0')
- {
- f = vlen(self.punchangle) - 10 * frametime;
- if (f > 0)
- self.punchangle = normalize(self.punchangle) * f;
- else
- self.punchangle = '0 0 0';
- }
-
- if (self.punchvector != '0 0 0')
- {
- f = vlen(self.punchvector) - 30 * frametime;
- if (f > 0)
- self.punchvector = normalize(self.punchvector) * f;
- else
- self.punchvector = '0 0 0';
- }
-
- if (IS_BOT_CLIENT(self))
- {
- if(playerdemo_read())
- return;
- bot_think();
- }
-
- if(IS_PLAYER(self))
- {
- if(self.race_penalty)
- if(time > self.race_penalty)
- self.race_penalty = 0;
-
- 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(not_allowed_to_move)
- {
- self.velocity = '0 0 0';
- self.movetype = MOVETYPE_NONE;
- self.disableclientprediction = 2;
- }
- else if(self.disableclientprediction == 2)
- {
- if(self.movetype == MOVETYPE_NONE)
- self.movetype = MOVETYPE_WALK;
- self.disableclientprediction = 0;
- }
- }
-
- if (self.movetype == MOVETYPE_NONE)
- return;
-
- // when we get here, disableclientprediction cannot be 2
- self.disableclientprediction = 0;
- if(time < self.ladder_time)
- self.disableclientprediction = 1;
-
- if(time < self.spider_slowness)
- {
- self.stat_sv_maxspeed *= 0.5; // half speed while slow from spider
- self.stat_sv_airspeedlimit_nonqw *= 0.5;
- }
-
- if(self.frozen)
- {
- 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);
- }
- else
- self.movement = '0 0 0';
- self.disableclientprediction = 1;
-
- vector midpoint = ((self.absmin + self.absmax) * 0.5);
- if(pointcontents(midpoint) == CONTENT_WATER)
- {
- self.velocity = self.velocity * 0.5;
-
- if(pointcontents(midpoint + '0 0 16') == CONTENT_WATER)
- { self.velocity_z = 200; }
- }
- }
-
- MUTATOR_CALLHOOK(PlayerPhysics);
-
- if(self.player_blocked)
- {
- self.movement = '0 0 0';
- self.disableclientprediction = 1;
- }
-
- maxspd_mod = 1;
-
- swampspd_mod = 1;
- if(self.in_swamp) {
- swampspd_mod = self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
- }
-
- // conveyors: first fix velocity
- if(self.conveyor.state)
- self.velocity -= self.conveyor.movedir;
-
- if (!IS_PLAYER(self))
- {
- maxspd_mod = autocvar_sv_spectator_speed_multiplier;
- if(!self.spectatorspeed)
- self.spectatorspeed = maxspd_mod;
- if(self.impulse && self.impulse <= 19 || (self.impulse >= 200 && self.impulse <= 209) || (self.impulse >= 220 && self.impulse <= 229))
- {
- if(self.lastclassname != "player")
- {
- if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209))
- self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
- else if(self.impulse == 11)
- self.spectatorspeed = maxspd_mod;
- else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229))
- self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
- else if(self.impulse >= 1 && self.impulse <= 9)
- self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
- } // otherwise just clear
- self.impulse = 0;
- }
- maxspd_mod = self.spectatorspeed;
- }
-
- spd = max(self.stat_sv_maxspeed, autocvar_sv_maxairspeed) * maxspd_mod * swampspd_mod;
- if(self.speed != spd)
- {
- self.speed = spd;
- temps = ftos(spd);
- stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
- stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
- stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
- stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
- }
-
- maxspd_mod *= swampspd_mod; // only one common speed modder please!
- swampspd_mod = 1;
-
- // if dead, behave differently
- if (self.deadflag)
- goto end;
-
- if (!self.fixangle && !g_bugrigs)
- {
- self.angles_x = 0;
- self.angles_y = self.v_angle_y;
- self.angles_z = 0;
- }
-
- if(self.flags & FL_ONGROUND)
- if(IS_PLAYER(self)) // no fall sounds for observers thank you very much
- if(self.wasFlying)
- {
- self.wasFlying = 0;
-
- if(self.waterlevel < WATERLEVEL_SWIMMING)
- if(time >= self.ladder_time)
- if (!self.hook)
- {
- self.nextstep = time + 0.3 + random() * 0.1;
- trace_dphitq3surfaceflags = 0;
- tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
- if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
- {
- if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
- GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
- else
- GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
- }
- }
- }
-
- if(IsFlying(self))
- self.wasFlying = 1;
-
- if(IS_PLAYER(self))
- CheckPlayerJump();
-
- if (self.flags & FL_WATERJUMP )
- {
- 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.teleport_time = 0;
- }
- }
- else if (g_bugrigs && IS_PLAYER(self))
- {
- RaceCarPhysics();
- }
- else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
- {
- // noclipping or flying
- self.flags &= ~FL_ONGROUND;
-
- 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;
- // acceleration
- wishdir = normalize(wishvel);
- wishspeed = vlen(wishvel);
- if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
- wishspeed = self.stat_sv_maxspeed*maxspd_mod;
- if (time >= self.teleport_time)
- PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
- }
- else if (self.waterlevel >= WATERLEVEL_SWIMMING)
- {
- // swimming
- self.flags &= ~FL_ONGROUND;
-
- 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;
- if (wishvel == '0 0 0')
- wishvel = '0 0 -60'; // drift towards bottom
-
- wishdir = normalize(wishvel);
- wishspeed = vlen(wishvel);
- if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
- wishspeed = self.stat_sv_maxspeed*maxspd_mod;
- wishspeed = wishspeed * 0.7;
-
- // water friction
- self.velocity = self.velocity * (1 - frametime * autocvar_sv_friction);
-
- // water acceleration
- PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
- }
- else if (time < self.ladder_time)
- {
- // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
- self.flags &= ~FL_ONGROUND;
-
- float g;
- g = autocvar_sv_gravity * frametime;
- if(self.gravity)
- g *= self.gravity;
- if(autocvar_sv_gameplayfix_gravityunaffectedbyticrate)
- {
- g *= 0.5;
- self.velocity_z += g;
- }
-
- 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;
- self.velocity_z += g;
- if (self.ladder_entity.classname == "func_water")
- {
- f = vlen(wishvel);
- if (f > self.ladder_entity.speed)
- 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)
- self.waterlevel = WATERLEVEL_SUBMERGED;
- 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)
- self.waterlevel = WATERLEVEL_WETFEET;
- else
- {
- self.waterlevel = WATERLEVEL_NONE;
- self.watertype = CONTENT_EMPTY;
- }
- }
- // acceleration
- wishdir = normalize(wishvel);
- wishspeed = vlen(wishvel);
- if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
- wishspeed = self.stat_sv_maxspeed*maxspd_mod;
- if (time >= self.teleport_time)
- {
- // water acceleration
- PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
- }
- }
- 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;
- // add remaining speed as Z component
- maxairspd = autocvar_sv_maxairspeed*max(1, maxspd_mod);
- // fix speedhacks :P
- wishvel = normalize(wishvel) * min(vlen(wishvel) / maxairspd, 1);
- // add the unused velocity as up component
- wishvel_z = 0;
-
- // if(self.BUTTON_JUMP)
- wishvel_z = sqrt(max(0, 1 - wishvel * wishvel));
-
- // it is now normalized, so...
- float a_side, a_up, a_add, a_diff;
- a_side = autocvar_g_jetpack_acceleration_side;
- 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;
-
- float best;
- best = 0;
- //////////////////////////////////////////////////////////////////////////////////////
- // finding the maximum over all vectors of above form
- // with wishvel having an absolute value of 1
- //////////////////////////////////////////////////////////////////////////////////////
- // we're finding the maximum over
- // f(a_side, a_up, a_add, z) := a_side * (1 - z^2) + (a_add + a_up * z)^2;
- // for z in the range from -1 to 1
- //////////////////////////////////////////////////////////////////////////////////////
- // maximum is EITHER attained at the single extreme point:
- a_diff = a_side * a_side - a_up * a_up;
- if(a_diff != 0)
- {
- f = a_add * a_up / a_diff; // this is the zero of diff(f(a_side, a_up, a_add, z), z)
- if(f > -1 && f < 1) // can it be attained?
- {
- best = (a_diff + a_add * a_add) * (a_diff + a_up * a_up) / a_diff;
- //print("middle\n");
- }
- }
- // OR attained at z = 1:
- f = (a_up + a_add) * (a_up + a_add);
- if(f > best)
- {
- best = f;
- //print("top\n");
- }
- // OR attained at z = -1:
- f = (a_up - a_add) * (a_up - a_add);
- if(f > best)
- {
- best = f;
- //print("bottom\n");
- }
- best = sqrt(best);
- //////////////////////////////////////////////////////////////////////////////////////
-
- //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);
- else
- 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;
-
- float fvel;
- fvel = min(1, vlen(wishvel) / best);
- if(autocvar_g_jetpack_fuel && !(self.items & IT_UNLIMITED_WEAPON_AMMO))
- f = min(1, self.ammo_fuel / (autocvar_g_jetpack_fuel * frametime * fvel));
- else
- f = 1;
-
- //print("this acceleration: ", ftos(vlen(wishvel) * f), "\n");
-
- if (f > 0 && wishvel != '0 0 0')
- {
- self.velocity = self.velocity + wishvel * f * frametime;
- if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
- self.ammo_fuel -= autocvar_g_jetpack_fuel * frametime * fvel * f;
- self.flags &= ~FL_ONGROUND;
- self.items |= IT_USING_JETPACK;
-
- // jetpack also inhibits health regeneration, but only for 1 second
- self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
- }
- }
- else if (self.flags & FL_ONGROUND)
- {
- // 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)
- 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;
-
- if(!(self.lastflags & FL_ONGROUND))
- {
- if(autocvar_speedmeter)
- dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
- if(self.lastground < time - 0.3)
- self.velocity = self.velocity * (1 - autocvar_sv_friction_on_land);
- if(self.jumppadcount > 1)
- dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
- self.jumppadcount = 0;
- }
-
- v = self.velocity;
- v_z = 0;
- f = vlen(v);
- if(f > 0)
- {
- if (f < autocvar_sv_stopspeed)
- f = 1 - frametime * (autocvar_sv_stopspeed / f) * autocvar_sv_friction;
- else
- f = 1 - frametime * autocvar_sv_friction;
- if (f > 0)
- self.velocity = self.velocity * f;
- else
- self.velocity = '0 0 0';
- /*
- Mathematical analysis time!
-
- Our goal is to invert this mess.
-
- For the two cases we get:
- v = v0 * (1 - frametime * (autocvar_sv_stopspeed / v0) * autocvar_sv_friction)
- = v0 - frametime * autocvar_sv_stopspeed * autocvar_sv_friction
- v0 = v + frametime * autocvar_sv_stopspeed * autocvar_sv_friction
- and
- v = v0 * (1 - frametime * autocvar_sv_friction)
- v0 = v / (1 - frametime * autocvar_sv_friction)
-
- These cases would be chosen ONLY if:
- v0 < autocvar_sv_stopspeed
- v + frametime * autocvar_sv_stopspeed * autocvar_sv_friction < autocvar_sv_stopspeed
- v < autocvar_sv_stopspeed * (1 - frametime * autocvar_sv_friction)
- and, respectively:
- v0 >= autocvar_sv_stopspeed
- v / (1 - frametime * autocvar_sv_friction) >= autocvar_sv_stopspeed
- v >= autocvar_sv_stopspeed * (1 - frametime * autocvar_sv_friction)
- */
- }
-
- // acceleration
- wishdir = normalize(wishvel);
- wishspeed = vlen(wishvel);
- if (wishspeed > self.stat_sv_maxspeed*maxspd_mod)
- wishspeed = self.stat_sv_maxspeed*maxspd_mod;
- if (self.crouch)
- wishspeed = wishspeed * 0.5;
- if (time >= self.teleport_time)
- PM_Accelerate(wishdir, wishspeed, wishspeed, autocvar_sv_accelerate*maxspd_mod, 1, 0, 0, 0);
- }
- else
- {
- 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)
- Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL);
-
- if(maxspd_mod < 1)
- {
- maxairspd = autocvar_sv_maxairspeed*maxspd_mod;
- airaccel = autocvar_sv_airaccelerate*maxspd_mod;
- }
- else
- {
- maxairspd = autocvar_sv_maxairspeed;
- airaccel = autocvar_sv_airaccelerate;
- }
- // airborn
- 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);
- if (wishspeed0 > self.stat_sv_maxspeed*maxspd_mod)
- wishspeed0 = self.stat_sv_maxspeed*maxspd_mod;
- if (wishspeed > maxairspd)
- wishspeed = maxairspd;
- if (self.crouch)
- wishspeed = wishspeed * 0.5;
- if (time >= self.teleport_time)
- {
- float accelerating;
- float wishspeed2;
- float airaccelqw;
- float strafity;
-
- airaccelqw = self.stat_sv_airaccel_qw;
- accelerating = (self.velocity * wishdir > 0);
- wishspeed2 = wishspeed;
-
- // CPM
- if(autocvar_sv_airstopaccelerate)
- {
- vector curdir;
- curdir = self.velocity;
- curdir_z = 0;
- curdir = normalize(curdir);
- airaccel = airaccel + (autocvar_sv_airstopaccelerate*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
- }
- // note that for straight forward jumping:
- // step = accel * frametime * wishspeed0;
- // accel = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);
- // -->
- // dv/dt = accel * maxspeed (when slow)
- // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
- // log dv/dt = logaccel + logmaxspeed (when slow)
- // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
- strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
- if(autocvar_sv_maxairstrafespeed)
- wishspeed = min(wishspeed, GeomLerp(autocvar_sv_maxairspeed*maxspd_mod, strafity, autocvar_sv_maxairstrafespeed*maxspd_mod));
- if(autocvar_sv_airstrafeaccelerate)
- airaccel = GeomLerp(airaccel, strafity, autocvar_sv_airstrafeaccelerate*maxspd_mod);
- if(self.stat_sv_airstrafeaccel_qw)
- 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)
- 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(autocvar_sv_aircontrol)
- CPM_PM_Aircontrol(wishdir, wishspeed2);
- }
- }
-
- if((g_cts || g_race) && !IS_OBSERVER(self))
- {
- if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
- {
- speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
- speedaward_holder = self.netname;
- speedaward_uid = self.crypto_idfp;
- speedaward_lastupdate = time;
- }
- if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
- {
- string rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
- race_send_speedaward(MSG_ALL);
- speedaward_lastsent = speedaward_speed;
- if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
- {
- speedaward_alltimebest = speedaward_speed;
- speedaward_alltimebest_holder = speedaward_holder;
- speedaward_alltimebest_uid = speedaward_uid;
- db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
- db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
- race_send_speedaward_alltimebest(MSG_ALL);
- }
- }
- }
-
- // WEAPONTODO
- float xyspeed;
- 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
- xyspeed = min(xyspeed, WEP_CVAR(vortex, charge_maxspeed));
- f = (xyspeed - WEP_CVAR(vortex, charge_minspeed)) / (WEP_CVAR(vortex, charge_maxspeed) - WEP_CVAR(vortex, charge_minspeed));
- // add the extra charge
- self.vortex_charge = min(1, self.vortex_charge + WEP_CVAR(vortex, charge_velocity_rate) * f * frametime);
- }
-:end
- if(self.flags & FL_ONGROUND)
- self.lastground = time;
-
- // conveyors: then break velocity again
- if(self.conveyor.state)
- self.velocity += self.conveyor.movedir;
-
- self.lastflags = self.flags;
- self.lastclassname = self.classname;
-}
.float stat_game_starttime;
.float stat_round_starttime;
-.float stat_sv_airaccel_qw;
-.float stat_sv_airstrafeaccel_qw;
-.float stat_sv_airspeedlimit_nonqw;
-.float stat_sv_maxspeed;
-
void W_Porto_Remove (entity p);
.float projectiledeathtype;
typedef vector(entity player, entity spot, vector current) spawn_evalfunc_t;
.spawn_evalfunc_t spawn_evalfunc;
-.entity conveyor;
-
string modname;
.float missile_flags;
void ClientInit_Spawn();
void WeaponStats_Init();
void WeaponStats_Shutdown();
+void Physics_AddStats();
void spawnfunc_worldspawn (void)
{
float fd, l, i, j, n;
addstat(STAT_FROZEN, AS_INT, frozen);
addstat(STAT_REVIVE_PROGRESS, AS_FLOAT, revive_progress);
- // g_movementspeed hack
- addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
- addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
- addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
- addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
+ // physics
+ Physics_AddStats();
// secrets
addstat(STAT_SECRETS_TOTAL, AS_FLOAT, stat_secrets_total);
return f;
}
-#define move_out_of_solid(e) WarpZoneLib_MoveOutOfSolid(e)
-
const string STR_PLAYER = "player";
const string STR_SPECTATOR = "spectator";
const string STR_OBSERVER = "observer";
+#ifdef CSQC
+ #define PHYS_DODGING_FRAMETIME (1 / (frametime <= 0 ? 60 : frametime))
+ #define PHYS_DODGING getstati(STAT_DODGING)
+ #define PHYS_DODGING_DELAY getstatf(STAT_DODGING_DELAY)
+ #define PHYS_DODGING_TIMEOUT(s) getstatf(STAT_DODGING_TIMEOUT)
+ #define PHYS_DODGING_HORIZ_SPEED_FROZEN getstatf(STAT_DODGING_HORIZ_SPEED_FROZEN)
+ #define PHYS_DODGING_FROZEN_NODOUBLETAP getstati(STAT_DODGING_FROZEN_NO_DOUBLETAP)
+ #define PHYS_DODGING_HORIZ_SPEED getstatf(STAT_DODGING_HORIZ_SPEED)
+ #define PHYS_DODGING_PRESSED_KEYS(s) s.pressedkeys
+ #define PHYS_DODGING_HEIGHT_THRESHOLD getstatf(STAT_DODGING_HEIGHT_THRESHOLD)
+ #define PHYS_DODGING_DISTANCE_THRESHOLD getstatf(STAT_DODGING_DISTANCE_THRESHOLD)
+ #define PHYS_DODGING_RAMP_TIME getstatf(STAT_DODGING_RAMP_TIME)
+ #define PHYS_DODGING_UP_SPEED getstatf(STAT_DODGING_UP_SPEED)
+ #define PHYS_DODGING_WALL getstatf(STAT_DODGING_WALL)
+#elif defined(SVQC)
+ #define PHYS_DODGING_FRAMETIME sys_frametime
+ #define PHYS_DODGING g_dodging
+ #define PHYS_DODGING_DELAY autocvar_sv_dodging_delay
+ #define PHYS_DODGING_TIMEOUT(s) s.cvar_cl_dodging_timeout
+ #define PHYS_DODGING_HORIZ_SPEED_FROZEN autocvar_sv_dodging_horiz_speed_frozen
+ #define PHYS_DODGING_FROZEN_NODOUBLETAP autocvar_sv_dodging_frozen_doubletap
+ #define PHYS_DODGING_HORIZ_SPEED autocvar_sv_dodging_horiz_speed
+ #define PHYS_DODGING_PRESSED_KEYS(s) s.pressedkeys
+ #define PHYS_DODGING_HEIGHT_THRESHOLD autocvar_sv_dodging_height_threshold
+ #define PHYS_DODGING_DISTANCE_THRESHOLD autocvar_sv_dodging_wall_distance_threshold
+ #define PHYS_DODGING_RAMP_TIME autocvar_sv_dodging_ramp_time
+ #define PHYS_DODGING_UP_SPEED autocvar_sv_dodging_up_speed
+ #define PHYS_DODGING_WALL autocvar_sv_dodging_wall_dodging
+#endif
+
+#ifdef SVQC
.float cvar_cl_dodging_timeout;
+.float stat_dodging;
+.float stat_dodging_delay;
+.float stat_dodging_horiz_speed_frozen;
+.float stat_dodging_frozen_nodoubletap;
+.float stat_dodging_frozen;
+.float stat_dodging_horiz_speed;
+.float stat_dodging_height_threshold;
+.float stat_dodging_distance_threshold;
+.float stat_dodging_ramp_time;
+.float stat_dodging_up_speed;
+.float stat_dodging_wall;
+
+#endif
+
+// set to 1 to indicate dodging has started.. reset by physics hook after dodge has been done..
+.float dodging_action;
+
+// the jump part of the dodge cannot be ramped
+.float dodging_single_action;
+
// these are used to store the last key press time for each of the keys..
.float last_FORWARD_KEY_time;
// until it's 0.
.float dodging_velocity_gain;
-MUTATOR_HOOKFUNCTION(dodging_GetCvars) {
- GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_dodging_timeout, "cl_dodging_timeout");
- return 0;
+#ifdef CSQC
+.float pressedkeys;
+
+#elif defined(SVQC)
+
+void dodging_UpdateStats()
+{
+ self.stat_dodging = PHYS_DODGING;
+ self.stat_dodging_delay = PHYS_DODGING_DELAY;
+ self.stat_dodging_horiz_speed_frozen = PHYS_DODGING_HORIZ_SPEED_FROZEN;
+ self.stat_dodging_frozen = PHYS_DODGING_FROZEN;
+ self.stat_dodging_frozen_nodoubletap = PHYS_DODGING_FROZEN_NODOUBLETAP;
+ self.stat_dodging_height_threshold = PHYS_DODGING_HEIGHT_THRESHOLD;
+ self.stat_dodging_distance_threshold = PHYS_DODGING_DISTANCE_THRESHOLD;
+ self.stat_dodging_ramp_time = PHYS_DODGING_RAMP_TIME;
+ self.stat_dodging_up_speed = PHYS_DODGING_UP_SPEED;
+ self.stat_dodging_wall = PHYS_DODGING_WALL;
}
-MUTATOR_HOOKFUNCTION(dodging_PlayerPhysics) {
- // print("dodging_PlayerPhysics\n");
+void dodging_Initialize()
+{
+ addstat(STAT_DODGING, AS_INT, stat_dodging);
+ addstat(STAT_DODGING_DELAY, AS_FLOAT, stat_dodging_delay);
+ addstat(STAT_DODGING_TIMEOUT, AS_FLOAT, cvar_cl_dodging_timeout); // we stat this, so it is updated on the client when updated on server (otherwise, chaos)
+ addstat(STAT_DODGING_FROZEN_NO_DOUBLETAP, AS_INT, stat_dodging_frozen_nodoubletap);
+ addstat(STAT_DODGING_HORIZ_SPEED_FROZEN, AS_FLOAT, stat_dodging_horiz_speed_frozen);
+ addstat(STAT_DODGING_FROZEN, AS_INT, stat_dodging_frozen);
+ addstat(STAT_DODGING_HORIZ_SPEED, AS_FLOAT, stat_dodging_horiz_speed);
+ addstat(STAT_DODGING_HEIGHT_THRESHOLD, AS_FLOAT, stat_dodging_height_threshold);
+ addstat(STAT_DODGING_DISTANCE_THRESHOLD, AS_FLOAT, stat_dodging_distance_threshold);
+ addstat(STAT_DODGING_RAMP_TIME, AS_FLOAT, stat_dodging_ramp_time);
+ addstat(STAT_DODGING_UP_SPEED, AS_FLOAT, stat_dodging_up_speed);
+ addstat(STAT_DODGING_WALL, AS_FLOAT, stat_dodging_wall);
+}
- float common_factor;
- float new_velocity_gain;
- float velocity_difference;
- float clean_up_and_do_nothing;
- float horiz_speed = autocvar_sv_dodging_horiz_speed;
+#endif
- if(self.frozen)
- horiz_speed = autocvar_sv_dodging_horiz_speed_frozen;
+// returns 1 if the player is close to a wall
+float check_close_to_wall(float threshold)
+{
+ if (PHYS_DODGING_WALL == 0) { return FALSE; }
+
+ #define X(OFFSET) \
+ tracebox(self.origin, self.mins, self.maxs, self.origin + OFFSET, TRUE, self); \
+ if (trace_fraction < 1 && vlen (self.origin - trace_endpos) < threshold) \
+ return TRUE;
+ X(1000*v_right);
+ X(-1000*v_right);
+ X(1000*v_forward);
+ X(-1000*v_forward);
+ #undef X
+
+ return FALSE;
+}
- if (self.deadflag != DEAD_NO)
- return 0;
+float check_close_to_ground(float threshold)
+{
+ return IS_ONGROUND(self) ? TRUE : FALSE;
+}
- new_velocity_gain = 0;
- clean_up_and_do_nothing = 0;
+float PM_dodging_checkpressedkeys()
+{
+ if(!PHYS_DODGING)
+ return FALSE;
- if (g_dodging == 0)
- clean_up_and_do_nothing = 1;
+ float frozen_dodging = (PHYS_FROZEN(self) && PHYS_DODGING_FROZEN);
+ float frozen_no_doubletap = (frozen_dodging && !PHYS_DODGING_FROZEN_NODOUBLETAP);
+
+ // first check if the last dodge is far enough back in time so we can dodge again
+ if ((time - self.last_dodging_time) < PHYS_DODGING_DELAY)
+ return FALSE;
+
+ makevectors(PHYS_WORLD_ANGLES(self));
+
+ if (check_close_to_ground(PHYS_DODGING_HEIGHT_THRESHOLD) != 1
+ && check_close_to_wall(PHYS_DODGING_DISTANCE_THRESHOLD) != 1)
+ return TRUE;
+
+ float tap_direction_x = 0;
+ float tap_direction_y = 0;
+ float dodge_detected = 0;
+
+ #define X(COND,BTN,RESULT) \
+ if (PHYS_INPUT_MOVEVALUES(self)_##COND) \
+ /* is this a state change? */ \
+ if(!(PHYS_DODGING_PRESSED_KEYS(self) & KEY_##BTN) || frozen_no_doubletap) { \
+ tap_direction_##RESULT; \
+ if ((time - self.last_##BTN##_KEY_time) < PHYS_DODGING_TIMEOUT(self)) \
+ dodge_detected = 1; \
+ self.last_##BTN##_KEY_time = time; \
+ }
+ X(x < 0, BACKWARD, x--);
+ X(x > 0, FORWARD, x++);
+ X(y < 0, LEFT, y--);
+ X(y > 0, RIGHT, y++);
+ #undef X
+
+ if (dodge_detected == 1)
+ {
+ self.last_dodging_time = time;
+
+ self.dodging_action = 1;
+ self.dodging_single_action = 1;
+
+ self.dodging_velocity_gain = PHYS_DODGING_HORIZ_SPEED;
+
+ self.dodging_direction_x = tap_direction_x;
+ self.dodging_direction_y = tap_direction_y;
+
+ // normalize the dodging_direction vector.. (unlike UT99) XD
+ float length = self.dodging_direction_x * self.dodging_direction_x
+ + self.dodging_direction_y * self.dodging_direction_y;
+ length = sqrt(length);
+
+ self.dodging_direction_x = self.dodging_direction_x * 1.0 / length;
+ self.dodging_direction_y = self.dodging_direction_y * 1.0 / length;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void PM_dodging()
+{
+ if (!PHYS_DODGING)
+ return;
+
+#ifdef SVQC
+ dodging_UpdateStats();
+#endif
+
+ if (PHYS_DEAD(self))
+ return;
// when swimming, no dodging allowed..
if (self.waterlevel >= WATERLEVEL_SWIMMING)
- clean_up_and_do_nothing = 1;
-
- if (clean_up_and_do_nothing != 0) {
+ {
self.dodging_action = 0;
self.dodging_direction_x = 0;
self.dodging_direction_y = 0;
- return 0;
+ return;
}
// make sure v_up, v_right and v_forward are sane
- makevectors(self.angles);
+ makevectors(PHYS_WORLD_ANGLES(self));
// if we have e.g. 0.5 sec ramptime and a frametime of 0.25, then the ramp code
// will be called ramp_time/frametime times = 2 times. so, we need to
// add 0.5 * the total speed each frame until the dodge action is done..
- common_factor = sys_frametime / autocvar_sv_dodging_ramp_time;
+ float common_factor = PHYS_DODGING_FRAMETIME / PHYS_DODGING_RAMP_TIME;
// if ramp time is smaller than frametime we get problems ;D
- if (common_factor > 1)
- common_factor = 1;
+ common_factor = min(common_factor, 1);
- new_velocity_gain = self.dodging_velocity_gain - (common_factor * horiz_speed);
- if (new_velocity_gain < 0)
- new_velocity_gain = 0;
+ float horiz_speed = PHYS_FROZEN(self) ? PHYS_DODGING_HORIZ_SPEED_FROZEN : PHYS_DODGING_HORIZ_SPEED;
+ float new_velocity_gain = self.dodging_velocity_gain - (common_factor * horiz_speed);
+ new_velocity_gain = max(0, new_velocity_gain);
- velocity_difference = self.dodging_velocity_gain - new_velocity_gain;
+ float velocity_difference = self.dodging_velocity_gain - new_velocity_gain;
// ramp up dodging speed by adding some velocity each frame.. TODO: do it! :D
- if (self.dodging_action == 1) {
+ if (self.dodging_action == 1)
+ {
//disable jump key during dodge accel phase
- if (self.movement_z > 0) self.movement_z = 0;
+ if(PHYS_INPUT_MOVEVALUES(self)_z > 0) { PHYS_INPUT_MOVEVALUES(self)_z = 0; }
- self.velocity =
- self.velocity
- + ((self.dodging_direction_y * velocity_difference) * v_right)
- + ((self.dodging_direction_x * velocity_difference) * v_forward);
+ self.velocity += ((self.dodging_direction_y * velocity_difference) * v_right)
+ + ((self.dodging_direction_x * velocity_difference) * v_forward);
self.dodging_velocity_gain = self.dodging_velocity_gain - velocity_difference;
}
// the up part of the dodge is a single shot action
- if (self.dodging_single_action == 1) {
- self.flags &= ~FL_ONGROUND;
+ if (self.dodging_single_action == 1)
+ {
+ UNSET_ONGROUND(self);
- self.velocity =
- self.velocity
- + (autocvar_sv_dodging_up_speed * v_up);
+ self.velocity += PHYS_DODGING_UP_SPEED * v_up;
+#ifdef SVQC
if (autocvar_sv_dodging_sound == 1)
PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
animdecide_setaction(self, ANIMACTION_JUMP, TRUE);
+#endif
self.dodging_single_action = 0;
}
// are we done with the dodging ramp yet?
- if((self.dodging_action == 1) && ((time - self.last_dodging_time) > autocvar_sv_dodging_ramp_time))
+ if((self.dodging_action == 1) && ((time - self.last_dodging_time) > PHYS_DODGING_RAMP_TIME))
{
// reset state so next dodge can be done correctly
self.dodging_action = 0;
self.dodging_direction_x = 0;
self.dodging_direction_y = 0;
}
-
- return 0;
}
+#ifdef SVQC
-// returns 1 if the player is close to a wall
-float check_close_to_wall(float threshold) {
- if (autocvar_sv_dodging_wall_dodging == 0)
- return 0;
-
- vector trace_start;
- vector trace_end;
-
- trace_start = self.origin;
-
- trace_end = self.origin + (1000*v_right);
- tracebox(trace_start, self.mins, self.maxs, trace_end, TRUE, self);
- if (trace_fraction < 1 && vlen (self.origin - trace_endpos) < threshold)
- return 1;
-
- trace_end = self.origin - (1000*v_right);
- tracebox(trace_start, self.mins, self.maxs, trace_end, TRUE, self);
- if (trace_fraction < 1 && vlen (self.origin - trace_endpos) < threshold)
- return 1;
-
- trace_end = self.origin + (1000*v_forward);
- tracebox(trace_start, self.mins, self.maxs, trace_end, TRUE, self);
- if (trace_fraction < 1 && vlen (self.origin - trace_endpos) < threshold)
- return 1;
-
- trace_end = self.origin - (1000*v_forward);
- tracebox(trace_start, self.mins, self.maxs, trace_end, TRUE, self);
- if (trace_fraction < 1 && vlen (self.origin - trace_endpos) < threshold)
- return 1;
-
- return 0;
-}
-
-float check_close_to_ground(float threshold) {
- if (self.flags & FL_ONGROUND)
- return 1;
-
- return 0;
+MUTATOR_HOOKFUNCTION(dodging_GetCvars)
+{
+ GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_dodging_timeout, "cl_dodging_timeout");
+ return FALSE;
}
-
-MUTATOR_HOOKFUNCTION(dodging_GetPressedKeys) {
+MUTATOR_HOOKFUNCTION(dodging_PlayerPhysics)
+{
// print("dodging_PlayerPhysics\n");
+ PM_dodging();
- float length;
- float tap_direction_x;
- float tap_direction_y;
-
- tap_direction_x = 0;
- tap_direction_y = 0;
-
- float frozen_dodging, frozen_no_doubletap;
- frozen_dodging = (self.frozen && autocvar_sv_dodging_frozen);
- frozen_no_doubletap = (frozen_dodging && !autocvar_sv_dodging_frozen_doubletap);
-
- float dodge_detected;
- if (g_dodging == 0)
- return 0;
-
- dodge_detected = 0;
-
- // first check if the last dodge is far enough back in time so we can dodge again
- if ((time - self.last_dodging_time) < autocvar_sv_dodging_delay)
- return 0;
-
- if (check_close_to_ground(autocvar_sv_dodging_height_threshold) != 1
- && check_close_to_wall(autocvar_sv_dodging_wall_distance_threshold) != 1)
- return 0;
-
- if (self.movement_x > 0) {
- // is this a state change?
- if (!(self.pressedkeys & KEY_FORWARD) || frozen_no_doubletap) {
- if ((time - self.last_FORWARD_KEY_time) < self.cvar_cl_dodging_timeout) {
- tap_direction_x = 1.0;
- dodge_detected = 1;
- }
- self.last_FORWARD_KEY_time = time;
- }
- }
-
- if (self.movement_x < 0) {
- // is this a state change?
- if (!(self.pressedkeys & KEY_BACKWARD) || frozen_no_doubletap) {
- tap_direction_x = -1.0;
- if ((time - self.last_BACKWARD_KEY_time) < self.cvar_cl_dodging_timeout) {
- dodge_detected = 1;
- }
- self.last_BACKWARD_KEY_time = time;
- }
- }
-
- if (self.movement_y > 0) {
- // is this a state change?
- if (!(self.pressedkeys & KEY_RIGHT) || frozen_no_doubletap) {
- tap_direction_y = 1.0;
- if ((time - self.last_RIGHT_KEY_time) < self.cvar_cl_dodging_timeout) {
- dodge_detected = 1;
- }
- self.last_RIGHT_KEY_time = time;
- }
- }
-
- if (self.movement_y < 0) {
- // is this a state change?
- if (!(self.pressedkeys & KEY_LEFT) || frozen_no_doubletap) {
- tap_direction_y = -1.0;
- if ((time - self.last_LEFT_KEY_time) < self.cvar_cl_dodging_timeout) {
- dodge_detected = 1;
- }
- self.last_LEFT_KEY_time = time;
- }
- }
-
- if (dodge_detected == 1) {
- self.last_dodging_time = time;
-
- self.dodging_action = 1;
- self.dodging_single_action = 1;
-
- self.dodging_velocity_gain = autocvar_sv_dodging_horiz_speed;
-
- self.dodging_direction_x = tap_direction_x;
- self.dodging_direction_y = tap_direction_y;
-
- // normalize the dodging_direction vector.. (unlike UT99) XD
- length = self.dodging_direction_x * self.dodging_direction_x;
- length = length + self.dodging_direction_y * self.dodging_direction_y;
- length = sqrt(length);
+ return FALSE;
+}
- self.dodging_direction_x = self.dodging_direction_x * 1.0/length;
- self.dodging_direction_y = self.dodging_direction_y * 1.0/length;
- }
+MUTATOR_HOOKFUNCTION(dodging_GetPressedKeys)
+{
+ PM_dodging_checkpressedkeys();
- return 0;
+ return FALSE;
}
MUTATOR_DEFINITION(mutator_dodging)
// this just turns on the cvar.
MUTATOR_ONADD
{
- g_dodging = 1;
+ g_dodging = cvar("g_dodging");
+ dodging_Initialize();
}
// this just turns off the cvar.
g_dodging = 0;
}
- MUTATOR_ONREMOVE
- {
- }
-
- return 0;
+ return FALSE;
}
+#endif
float g_dodging;
-
-// set to 1 to indicate dodging has started.. reset by physics hook after dodge has been done..
-.float dodging_action;
-
-// the jump part of the dodge cannot be ramped
-.float dodging_single_action;
.float multijump_count;
.float multijump_ready;
-MUTATOR_HOOKFUNCTION(multijump_PlayerPhysics)
+#ifdef CSQC
+
+#define PHYS_MULTIJUMP getstati(STAT_MULTIJUMP)
+#define PHYS_MULTIJUMP_SPEED getstatf(STAT_MULTIJUMP_SPEED)
+#define PHYS_MULTIJUMP_ADD getstati(STAT_MULTIJUMP_ADD)
+
+#elif defined(SVQC)
+
+#define PHYS_MULTIJUMP autocvar_g_multijump
+#define PHYS_MULTIJUMP_SPEED autocvar_g_multijump_speed
+#define PHYS_MULTIJUMP_ADD autocvar_g_multijump_add
+
+
+.float stat_multijump;
+.float stat_multijump_speed;
+.float stat_multijump_add;
+
+void multijump_UpdateStats()
{
- if(self.flags & FL_ONGROUND)
- self.multijump_count = 0;
+ self.stat_multijump = PHYS_MULTIJUMP;
+ self.stat_multijump_speed = PHYS_MULTIJUMP_SPEED;
+ self.stat_multijump_add = PHYS_MULTIJUMP_ADD;
+}
- return FALSE;
+void multijump_AddStats()
+{
+ addstat(STAT_MULTIJUMP, AS_INT, stat_multijump);
+ addstat(STAT_MULTIJUMP_SPEED, AS_FLOAT, stat_multijump_speed);
+ addstat(STAT_MULTIJUMP_ADD, AS_INT, stat_multijump_add);
}
-MUTATOR_HOOKFUNCTION(multijump_PlayerJump)
+#endif
+
+void PM_multijump()
{
- if (self.flags & FL_JUMPRELEASED && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair
+ if(!PHYS_MULTIJUMP) { return; }
+
+ if(IS_ONGROUND(self))
+ {
+ self.multijump_count = 0;
+ }
+}
+
+float PM_multijump_checkjump()
+{
+ if(!PHYS_MULTIJUMP) { return FALSE; }
+
+ if (!IS_JUMP_HELD(self) && !IS_ONGROUND(self)) // jump button pressed this frame and we are in midair
self.multijump_ready = TRUE; // this is necessary to check that we released the jump button and pressed it again
else
self.multijump_ready = FALSE;
- if(!player_multijump && self.multijump_ready && (autocvar_g_multijump == -1 || self.multijump_count < autocvar_g_multijump) && self.velocity_z > autocvar_g_multijump_speed)
+ if(!player_multijump && self.multijump_ready && (self.multijump_count < PHYS_MULTIJUMP || PHYS_MULTIJUMP == -1) && self.velocity_z > PHYS_MULTIJUMP_SPEED)
{
- if (autocvar_g_multijump)
+ if (PHYS_MULTIJUMP)
{
- if (autocvar_g_multijump_add == 0) // in this case we make the z velocity == jumpvelocity
+ if (!PHYS_MULTIJUMP_ADD) // in this case we make the z velocity == jumpvelocity
{
- if (self.velocity_z < autocvar_sv_jumpvelocity)
+ if (self.velocity_z < PHYS_JUMPVELOCITY)
{
player_multijump = TRUE;
self.velocity_z = 0;
if(player_multijump)
{
- if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys
+ if(PHYS_INPUT_MOVEVALUES(self)_x != 0 || PHYS_INPUT_MOVEVALUES(self)_y != 0) // don't remove all speed if player isnt pressing any movement keys
{
float curspeed;
vector wishvel, wishdir;
+#ifdef SVQC
curspeed = max(
vlen(vec2(self.velocity)), // current xy speed
vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs
);
- makevectors(self.v_angle_y * '0 1 0');
- wishvel = v_forward * self.movement_x + v_right * self.movement_y;
+#elif defined(CSQC)
+ curspeed = vlen(vec2(self.velocity));
+#endif
+
+ makevectors(PHYS_INPUT_ANGLES(self)_y * '0 1 0');
+ wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self)_x + v_right * PHYS_INPUT_MOVEVALUES(self)_y;
wishdir = normalize(wishvel);
self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump
return FALSE;
}
+#ifdef SVQC
+MUTATOR_HOOKFUNCTION(multijump_PlayerPhysics)
+{
+ multijump_UpdateStats();
+ PM_multijump();
+
+ return FALSE;
+}
+
+MUTATOR_HOOKFUNCTION(multijump_PlayerJump)
+{
+ return PM_multijump_checkjump();
+}
+
MUTATOR_HOOKFUNCTION(multijump_BuildMutatorsString)
{
ret_string = strcat(ret_string, ":multijump");
MUTATOR_HOOK(BuildMutatorsString, multijump_BuildMutatorsString, CBC_ORDER_ANY);
MUTATOR_HOOK(BuildMutatorsPrettyString, multijump_BuildMutatorsPrettyString, CBC_ORDER_ANY);
+ MUTATOR_ONADD
+ {
+ multijump_AddStats();
+ }
+
return FALSE;
}
+#endif
teamplay.qc
-cl_physics.qc
+../common/physics.qh
+../common/physics.qc
// tZork's libs
movelib.qc
+.float ladder_time;
+.entity ladder_entity;
+#ifdef SVQC
.float roomtype;
.float radius;
.float pitch;
void spawnfunc_env_sound() {}
void spawnfunc_light_spot() {}
void spawnfunc_func_healthcharger() {}
-
+#endif
void func_ladder_touch()
{
+#ifdef SVQC
if (!other.iscreature)
return;
if (other.vehicle_flags & VHF_ISVEHICLE)
return;
+#endif
+#ifdef CSQC
+ if(other.classname != "csqcmodel")
+ return;
+#endif
EXACTTRIGGER_TOUCH;
other.ladder_entity = self;
}
+#ifdef SVQC
+float func_ladder_send(entity to, float sf)
+{
+ WriteByte(MSG_ENTITY, ENT_CLIENT_LADDER);
+
+ WriteString(MSG_ENTITY, self.classname);
+ WriteByte(MSG_ENTITY, self.warpzone_isboxy);
+ WriteByte(MSG_ENTITY, self.skin);
+ WriteByte(MSG_ENTITY, self.speed);
+ WriteByte(MSG_ENTITY, self.scale);
+ WriteCoord(MSG_ENTITY, self.origin_x);
+ WriteCoord(MSG_ENTITY, self.origin_y);
+ WriteCoord(MSG_ENTITY, self.origin_z);
+
+ WriteCoord(MSG_ENTITY, self.mins_x);
+ WriteCoord(MSG_ENTITY, self.mins_y);
+ WriteCoord(MSG_ENTITY, self.mins_z);
+ WriteCoord(MSG_ENTITY, self.maxs_x);
+ WriteCoord(MSG_ENTITY, self.maxs_y);
+ WriteCoord(MSG_ENTITY, self.maxs_z);
+
+ WriteCoord(MSG_ENTITY, self.movedir_x);
+ WriteCoord(MSG_ENTITY, self.movedir_y);
+ WriteCoord(MSG_ENTITY, self.movedir_z);
+
+ WriteCoord(MSG_ENTITY, self.angles_x);
+ WriteCoord(MSG_ENTITY, self.angles_y);
+ WriteCoord(MSG_ENTITY, self.angles_z);
+
+ return TRUE;
+}
+
+void func_ladder_link()
+{
+ Net_LinkEntity(self, FALSE, 0, func_ladder_send);
+}
+
void spawnfunc_func_ladder()
{
EXACTTRIGGER_INIT;
self.touch = func_ladder_touch;
+
+ func_ladder_link();
}
void spawnfunc_func_water()
{
EXACTTRIGGER_INIT;
self.touch = func_ladder_touch;
+
+ func_ladder_link();
}
+#elif defined(CSQC)
+.float speed;
+
+void func_ladder_draw()
+{
+ float dt = time - self.move_time;
+ self.move_time = time;
+ if(dt <= 0) { return; }
+
+ trigger_touch_generic(func_ladder_touch);
+}
+
+void ent_func_ladder()
+{
+ self.classname = strzone(ReadString());
+ self.warpzone_isboxy = ReadByte();
+ self.skin = ReadByte();
+ self.speed = ReadByte();
+ self.scale = ReadByte();
+ self.origin_x = ReadCoord();
+ self.origin_y = ReadCoord();
+ self.origin_z = ReadCoord();
+ setorigin(self, self.origin);
+ self.mins_x = ReadCoord();
+ self.mins_y = ReadCoord();
+ self.mins_z = ReadCoord();
+ self.maxs_x = ReadCoord();
+ self.maxs_y = ReadCoord();
+ self.maxs_z = ReadCoord();
+ setsize(self, self.mins, self.maxs);
+ self.movedir_x = ReadCoord();
+ self.movedir_y = ReadCoord();
+ self.movedir_z = ReadCoord();
+ self.angles_x = ReadCoord();
+ self.angles_y = ReadCoord();
+ self.angles_z = ReadCoord();
+
+ self.solid = SOLID_TRIGGER;
+ self.draw = func_ladder_draw;
+ self.drawmask = MASK_NORMAL;
+ self.move_time = time;
+}
+#endif
-const float PUSH_ONCE = 1;
-const float PUSH_SILENT = 2;
+.float height;
+
+#ifdef CSQC
+.float active;
+.string target;
+.string targetname;
+#define ACTIVE_NOT 0
+#define ACTIVE_ACTIVE 1
+#define ACTIVE_IDLE 2
+#define ACTIVE_BUSY 2
+#define ACTIVE_TOGGLE 3
+#endif
+
+#ifdef SVQC
+
+const float PUSH_ONCE = 1;
+const float PUSH_SILENT = 2;
.float pushltime;
.float istypefrag;
-.float height;
void() SUB_UseTargets;
-float trigger_push_calculatevelocity_flighttime;
-
void trigger_push_use()
{
if(teamplay)
+ {
self.team = activator.team;
+ self.SendFlags |= 2;
+ }
}
+#endif
+
+float trigger_push_calculatevelocity_flighttime;
/*
trigger_push_calculatevelocity
torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
- grav = autocvar_sv_gravity;
- if(other.gravity)
- grav *= other.gravity;
+ grav = PHYS_GRAVITY;
+ if(PHYS_ENTGRAVITY(other))
+ grav *= PHYS_ENTGRAVITY(other);
zdist = torg_z - org_z;
sdist = vlen(torg - org - zdist * '0 0 1');
if (self.active == ACTIVE_NOT)
return;
+#ifdef SVQC
if (!isPushable(other))
return;
+#endif
if(self.team)
- if(((self.spawnflags & 4) == 0) == (self.team != other.team))
+ if(((self.spawnflags & 4) == 0) == (DIFF_TEAM(self, other)))
return;
EXACTTRIGGER_TOUCH;
other.velocity = self.movedir;
}
- other.flags &= ~FL_ONGROUND;
+ UNSET_ONGROUND(other);
+#ifdef SVQC
if (IS_PLAYER(other))
{
// reset tracking of oldvelocity for impact damage (sudden velocity changes)
sound (other, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
self.pushltime = time + 0.2;
}
+
if(IS_REAL_CLIENT(other) || IS_BOT_CLIENT(other))
{
float i;
self.think = SUB_Remove;
self.nextthink = time;
}
+#endif
}
.vector dest;
+#ifdef SVQC
+void trigger_push_link();
+void trigger_push_updatelink();
+#endif
void trigger_push_findtarget()
{
- entity e, t;
+ entity t;
vector org;
// first calculate a typical start point for the jump
if (self.target)
{
- float n;
- n = 0;
+ float n = 0;
for(t = world; (t = find(t, targetname, self.target)); )
{
++n;
- e = spawn();
+#ifdef SVQC
+ entity e = spawn();
setorigin(e, org);
setsize(e, PL_MIN, PL_MAX);
e.velocity = trigger_push_calculatevelocity(org, t, self.height);
if(e.movetype == MOVETYPE_NONE)
waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
remove(e);
+#endif
}
- if(n == 0)
+ if(!n)
{
// no dest!
+#ifdef SVQC
objerror ("Jumppad with nonexistant target");
+#endif
return;
}
else if(n == 1)
self.enemy = world;
}
}
+#ifdef SVQC
else
{
- e = spawn();
+ entity e = spawn();
setorigin(e, org);
setsize(e, PL_MIN, PL_MAX);
e.velocity = self.movedir;
waypoint_spawnforteleporter(self, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
remove(e);
}
+
+ trigger_push_link();
+ defer(0.1, trigger_push_updatelink);
+#endif
}
+#ifdef SVQC
+float trigger_push_send(entity to, float sf)
+{
+ WriteByte(MSG_ENTITY, ENT_CLIENT_TRIGGER_PUSH);
+ WriteByte(MSG_ENTITY, sf);
+
+ if(sf & 1)
+ {
+ WriteString(MSG_ENTITY, self.target);
+ WriteByte(MSG_ENTITY, self.team);
+ WriteInt24_t(MSG_ENTITY, self.spawnflags);
+ WriteByte(MSG_ENTITY, self.active);
+ WriteByte(MSG_ENTITY, self.warpzone_isboxy);
+ WriteByte(MSG_ENTITY, self.height);
+ WriteByte(MSG_ENTITY, self.scale);
+ WriteCoord(MSG_ENTITY, self.origin_x);
+ WriteCoord(MSG_ENTITY, self.origin_y);
+ WriteCoord(MSG_ENTITY, self.origin_z);
+
+ WriteCoord(MSG_ENTITY, self.mins_x);
+ WriteCoord(MSG_ENTITY, self.mins_y);
+ WriteCoord(MSG_ENTITY, self.mins_z);
+ WriteCoord(MSG_ENTITY, self.maxs_x);
+ WriteCoord(MSG_ENTITY, self.maxs_y);
+ WriteCoord(MSG_ENTITY, self.maxs_z);
+
+ WriteCoord(MSG_ENTITY, self.movedir_x);
+ WriteCoord(MSG_ENTITY, self.movedir_y);
+ WriteCoord(MSG_ENTITY, self.movedir_z);
+
+ WriteCoord(MSG_ENTITY, self.angles_x);
+ WriteCoord(MSG_ENTITY, self.angles_y);
+ WriteCoord(MSG_ENTITY, self.angles_z);
+ }
+
+ if(sf & 2)
+ {
+ WriteByte(MSG_ENTITY, self.team);
+ WriteByte(MSG_ENTITY, self.active);
+ }
+
+ return TRUE;
+}
+
+void trigger_push_updatelink()
+{
+ self.SendFlags |= 1;
+}
+
+void trigger_push_link()
+{
+ Net_LinkEntity(self, FALSE, 0, trigger_push_send);
+}
+#endif
+#ifdef SVQC
/*
* ENTITY PARAMETERS:
*
InitializeEntity(self, trigger_push_findtarget, INITPRIO_FINDTARGET);
}
-void spawnfunc_target_push() {}
-void spawnfunc_info_notnull() {}
-void spawnfunc_target_position() {}
+
+float target_push_send(entity to, float sf)
+{
+ WriteByte(MSG_ENTITY, ENT_CLIENT_TARGET_PUSH);
+
+ WriteByte(MSG_ENTITY, self.cnt);
+ WriteString(MSG_ENTITY, self.targetname);
+ WriteCoord(MSG_ENTITY, self.origin_x);
+ WriteCoord(MSG_ENTITY, self.origin_y);
+ WriteCoord(MSG_ENTITY, self.origin_z);
+
+ return TRUE;
+}
+
+void target_push_link()
+{
+ Net_LinkEntity(self, FALSE, 0, target_push_send);
+ self.SendFlags |= 1; // update
+}
+
+void spawnfunc_target_push() { target_push_link(); }
+void spawnfunc_info_notnull() { target_push_link(); }
+void spawnfunc_target_position() { target_push_link(); }
+
+#endif
+
+#ifdef CSQC
+void trigger_push_draw()
+{
+ float dt = time - self.move_time;
+ self.move_time = time;
+ if(dt <= 0) { return; }
+
+ trigger_touch_generic(trigger_push_touch);
+}
+
+void ent_trigger_push()
+{
+ float sf = ReadByte();
+
+ if(sf & 1)
+ {
+ self.classname = "jumppad";
+ self.target = strzone(ReadString());
+ float mytm = ReadByte(); if(mytm) { self.team = mytm - 1; }
+ self.spawnflags = ReadInt24_t();
+ self.active = ReadByte();
+ self.warpzone_isboxy = ReadByte();
+ self.height = ReadByte();
+ self.scale = ReadByte();
+ self.origin_x = ReadCoord();
+ self.origin_y = ReadCoord();
+ self.origin_z = ReadCoord();
+ setorigin(self, self.origin);
+ self.mins_x = ReadCoord();
+ self.mins_y = ReadCoord();
+ self.mins_z = ReadCoord();
+ self.maxs_x = ReadCoord();
+ self.maxs_y = ReadCoord();
+ self.maxs_z = ReadCoord();
+ setsize(self, self.mins, self.maxs);
+ self.movedir_x = ReadCoord();
+ self.movedir_y = ReadCoord();
+ self.movedir_z = ReadCoord();
+ self.angles_x = ReadCoord();
+ self.angles_y = ReadCoord();
+ self.angles_z = ReadCoord();
+
+ self.solid = SOLID_TRIGGER;
+ //self.draw = trigger_push_draw;
+ self.drawmask = MASK_ENGINE;
+ self.move_time = time;
+ //self.touch = trigger_push_touch;
+ trigger_push_findtarget();
+ }
+
+ if(sf & 2)
+ {
+ self.team = ReadByte();
+ self.active = ReadByte();
+ }
+}
+
+void ent_target_push()
+{
+ self.classname = "push_target";
+ self.cnt = ReadByte();
+ self.targetname = strzone(ReadString());
+ self.origin_x = ReadCoord();
+ self.origin_y = ReadCoord();
+ self.origin_z = ReadCoord();
+ setorigin(self, self.origin);
+
+ self.drawmask = MASK_ENGINE;
+}
+#endif
+#ifdef SVQC
+
.float dmgtime2;
void generic_plat_blocked()
{
InitializeEntity(self, func_vectormamamam_findtarget, INITPRIO_FINDTARGET);
}
+#endif
+
void conveyor_think()
{
+#ifdef CSQC
+ float dt = time - self.move_time;
+ self.move_time = time;
+ if(dt <= 0) { return; }
+#endif
entity e;
// set myself as current conveyor where possible
{
for(e = findradius((self.absmin + self.absmax) * 0.5, vlen(self.absmax - self.absmin) * 0.5 + 1); e; e = e.chain)
if(!e.conveyor.state)
+#ifdef SVQC
if(isPushable(e))
+#elif defined(CSQC)
+ if(e.isplayermodel)
+#endif
{
vector emin = e.absmin;
vector emax = e.absmax;
for(e = world; (e = findentity(e, conveyor, self)); )
{
+#ifdef SVQC
if(IS_CLIENT(e)) // doing it via velocity has quite some advantages
continue; // done in SV_PlayerPhysics
+#elif defined(CSQC)
+ if(e.isplayermodel)
+ continue;
+#endif
- setorigin(e, e.origin + self.movedir * sys_frametime);
+ setorigin(e, e.origin + self.movedir * PHYS_INPUT_FRAMETIME);
move_out_of_solid(e);
+#ifdef SVQC
UpdateCSQCProjectile(e);
+#endif
/*
// stupid conveyor code
tracebox(e.origin, e.mins, e.maxs, e.origin + self.movedir * sys_frametime, MOVE_NORMAL, e);
}
}
+#ifdef SVQC
self.nextthink = time;
+#endif
}
+#ifdef SVQC
+
void conveyor_use()
{
self.state = !self.state;
+
+ self.SendFlags |= 2;
}
void conveyor_reset()
{
self.state = (self.spawnflags & 1);
+
+ self.SendFlags |= 2;
+}
+
+float conveyor_send(entity to, float sf)
+{
+ WriteByte(MSG_ENTITY, ENT_CLIENT_CONVEYOR);
+ WriteByte(MSG_ENTITY, sf);
+
+ if(sf & 1)
+ {
+ WriteByte(MSG_ENTITY, self.warpzone_isboxy);
+ WriteCoord(MSG_ENTITY, self.origin_x);
+ WriteCoord(MSG_ENTITY, self.origin_y);
+ WriteCoord(MSG_ENTITY, self.origin_z);
+
+ WriteCoord(MSG_ENTITY, self.mins_x);
+ WriteCoord(MSG_ENTITY, self.mins_y);
+ WriteCoord(MSG_ENTITY, self.mins_z);
+ WriteCoord(MSG_ENTITY, self.maxs_x);
+ WriteCoord(MSG_ENTITY, self.maxs_y);
+ WriteCoord(MSG_ENTITY, self.maxs_z);
+
+ WriteCoord(MSG_ENTITY, self.movedir_x);
+ WriteCoord(MSG_ENTITY, self.movedir_y);
+ WriteCoord(MSG_ENTITY, self.movedir_z);
+
+ WriteByte(MSG_ENTITY, self.speed);
+ WriteByte(MSG_ENTITY, self.state);
+
+ WriteString(MSG_ENTITY, self.targetname);
+ WriteString(MSG_ENTITY, self.target);
+ }
+
+ if(sf & 2)
+ WriteByte(MSG_ENTITY, self.state);
+
+ return TRUE;
}
void conveyor_init()
}
else
self.state = 1;
+
+ Net_LinkEntity(self, 0, FALSE, conveyor_send);
+
+ self.SendFlags |= 1;
}
void spawnfunc_trigger_conveyor()
self.movetype = MOVETYPE_NONE;
conveyor_init();
}
+
+#elif defined(CSQC)
+
+void conveyor_init()
+{
+ self.draw = conveyor_think;
+ self.drawmask = MASK_NORMAL;
+
+ self.movetype = MOVETYPE_NONE;
+ self.model = "";
+ self.solid = SOLID_TRIGGER;
+ self.move_origin = self.origin;
+ self.move_time = time;
+}
+
+void ent_conveyor()
+{
+ float sf = ReadByte();
+
+ if(sf & 1)
+ {
+ self.warpzone_isboxy = ReadByte();
+ self.origin_x = ReadCoord();
+ self.origin_y = ReadCoord();
+ self.origin_z = ReadCoord();
+ setorigin(self, self.origin);
+
+ self.mins_x = ReadCoord();
+ self.mins_y = ReadCoord();
+ self.mins_z = ReadCoord();
+ self.maxs_x = ReadCoord();
+ self.maxs_y = ReadCoord();
+ self.maxs_z = ReadCoord();
+ setsize(self, self.mins, self.maxs);
+
+ self.movedir_x = ReadCoord();
+ self.movedir_y = ReadCoord();
+ self.movedir_z = ReadCoord();
+
+ self.speed = ReadByte();
+ self.state = ReadByte();
+
+ self.targetname = strzone(ReadString());
+ self.target = strzone(ReadString());
+
+ conveyor_init();
+ }
+
+ if(sf & 2)
+ self.state = ReadByte();
+}
+
+#endif
WarpZone_RefSys_Copy(e, me);
return e;
}
+
+float WarpZoneLib_ExactTrigger_Touch()
+{
+ return !WarpZoneLib_BoxTouchesBrush(other.absmin, other.absmax, self, other);
+}
+
+
+void WarpZoneLib_MoveOutOfSolid_Expand(entity e, vector by)
+{
+ float eps = 0.0625;
+ tracebox(e.origin, e.mins - '1 1 1' * eps, e.maxs + '1 1 1' * eps, e.origin + by, MOVE_WORLDONLY, e);
+ if (trace_startsolid)
+ return;
+ if (trace_fraction < 1)
+ {
+ // hit something
+ // adjust origin in the other direction...
+ setorigin(e,e.origin - by * (1 - trace_fraction));
+ }
+}
+
+float WarpZoneLib_MoveOutOfSolid(entity e)
+{
+ vector o, m0, m1;
+
+ o = e.origin;
+ traceline(o, o, MOVE_WORLDONLY, e);
+ if (trace_startsolid)
+ return FALSE;
+
+ tracebox(o, e.mins, e.maxs, o, MOVE_WORLDONLY, e);
+ if (!trace_startsolid)
+ return TRUE;
+
+ m0 = e.mins;
+ m1 = e.maxs;
+ e.mins = '0 0 0';
+ e.maxs = '0 0 0';
+ WarpZoneLib_MoveOutOfSolid_Expand(e, '1 0 0' * m0_x);
+ e.mins_x = m0_x;
+ WarpZoneLib_MoveOutOfSolid_Expand(e, '1 0 0' * m1_x);
+ e.maxs_x = m1_x;
+ WarpZoneLib_MoveOutOfSolid_Expand(e, '0 1 0' * m0_y);
+ e.mins_y = m0_y;
+ WarpZoneLib_MoveOutOfSolid_Expand(e, '0 1 0' * m1_y);
+ e.maxs_y = m1_y;
+ WarpZoneLib_MoveOutOfSolid_Expand(e, '0 0 1' * m0_z);
+ e.mins_z = m0_z;
+ WarpZoneLib_MoveOutOfSolid_Expand(e, '0 0 1' * m1_z);
+ e.maxs_z = m1_z;
+ setorigin(e, e.origin);
+
+ tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_WORLDONLY, e);
+ if (trace_startsolid)
+ {
+ setorigin(e, o);
+ return FALSE;
+ }
+
+ return TRUE;
+}
#ifndef BITXOR_ASSIGN
# define BITXOR_ASSIGN(a,b) ((a) = ((a) | (b)) - ((a) & (b)))
#endif
+
+float WarpZoneLib_MoveOutOfSolid(entity e);
+#define move_out_of_solid(e) WarpZoneLib_MoveOutOfSolid(e)
-void WarpZoneLib_MoveOutOfSolid_Expand(entity e, vector by)
-{
- float eps = 0.0625;
- tracebox(e.origin, e.mins - '1 1 1' * eps, e.maxs + '1 1 1' * eps, e.origin + by, MOVE_WORLDONLY, e);
- if (trace_startsolid)
- return;
- if (trace_fraction < 1)
- {
- // hit something
- // adjust origin in the other direction...
- setorigin(e,e.origin - by * (1 - trace_fraction));
- }
-}
-
-float WarpZoneLib_MoveOutOfSolid(entity e)
-{
- vector o, m0, m1;
-
- o = e.origin;
- traceline(o, o, MOVE_WORLDONLY, e);
- if (trace_startsolid)
- return FALSE;
-
- tracebox(o, e.mins, e.maxs, o, MOVE_WORLDONLY, e);
- if (!trace_startsolid)
- return TRUE;
-
- m0 = e.mins;
- m1 = e.maxs;
- e.mins = '0 0 0';
- e.maxs = '0 0 0';
- WarpZoneLib_MoveOutOfSolid_Expand(e, '1 0 0' * m0_x);
- e.mins_x = m0_x;
- WarpZoneLib_MoveOutOfSolid_Expand(e, '1 0 0' * m1_x);
- e.maxs_x = m1_x;
- WarpZoneLib_MoveOutOfSolid_Expand(e, '0 1 0' * m0_y);
- e.mins_y = m0_y;
- WarpZoneLib_MoveOutOfSolid_Expand(e, '0 1 0' * m1_y);
- e.maxs_y = m1_y;
- WarpZoneLib_MoveOutOfSolid_Expand(e, '0 0 1' * m0_z);
- e.mins_z = m0_z;
- WarpZoneLib_MoveOutOfSolid_Expand(e, '0 0 1' * m1_z);
- e.maxs_z = m1_z;
- setorigin(e, e.origin);
-
- tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_WORLDONLY, e);
- if (trace_startsolid)
- {
- setorigin(e, o);
- return FALSE;
- }
-
- return TRUE;
-}
-
-float WarpZoneLib_ExactTrigger_Touch()
-{
- return !WarpZoneLib_BoxTouchesBrush(other.absmin, other.absmax, self, other);
-}
-
void WarpZoneLib_ExactTrigger_Init()
{
vector mi, ma;