Skip to content

Commit f55e678

Browse files
authored
Merge pull request #42 from wgetJane/unlag-teammates
enable lag compensation for teammates
2 parents 53953b4 + 237a88f commit f55e678

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

game/server/tf/tf_player.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ ConVar tf_halloween_giant_health_scale( "tf_halloween_giant_health_scale", "10",
258258
ConVar tf_grapplinghook_los_force_detach_time( "tf_grapplinghook_los_force_detach_time", "1", FCVAR_CHEAT );
259259
ConVar tf_powerup_max_charge_time( "tf_powerup_max_charge_time", "30", FCVAR_CHEAT );
260260

261+
ConVar tf_unlag_teammates( "tf_unlag_teammates", "1", FCVAR_NOTIFY, "Controls lag compensation for teammates. 0: Disable, 1: Enable, 2: Melee weapons only" );
262+
261263
extern ConVar tf_powerup_mode;
262264
extern ConVar tf_mvm_buybacks_method;
263265
extern ConVar tf_mvm_buybacks_per_wave;
@@ -19230,22 +19232,42 @@ bool CTFPlayer::WantsLagCompensationOnEntity( const CBasePlayer *pPlayer, const
1923019232
}
1923119233
}
1923219234

19233-
if ( pPlayer->GetTeamNumber() == GetTeamNumber() && bIsMedic == false )
19234-
return false;
19235-
19235+
// check if teammates should be lag compensated
19236+
int iUnlagTeammates = 0;
19237+
if ( pPlayer->GetTeamNumber() == GetTeamNumber() )
19238+
{
19239+
iUnlagTeammates = tf_unlag_teammates.GetInt();
19240+
19241+
if ( iUnlagTeammates == 0 && bIsMedic == false )
19242+
return false;
19243+
}
19244+
1923619245
// If this entity hasn't been transmitted to us and acked, then don't bother lag compensating it.
1923719246
if ( pEntityTransmitBits && !pEntityTransmitBits->Get( pPlayer->entindex() ) )
1923819247
return false;
1923919248

1924019249
const Vector &vMyOrigin = GetAbsOrigin();
1924119250
const Vector &vHisOrigin = pPlayer->GetAbsOrigin();
19251+
19252+
float fDistance = vHisOrigin.DistTo( vMyOrigin );
19253+
19254+
// teammates are only lag compensated for melee attacks for tf_unlag_teammates 2
19255+
if ( iUnlagTeammates == 2 )
19256+
{
19257+
if ( fDistance > 512 )
19258+
return false;
19259+
19260+
CTFWeaponBaseMelee *pWeapon = dynamic_cast <CTFWeaponBaseMelee*>( GetActiveWeapon() );
19261+
if ( !pWeapon )
19262+
return false;
19263+
}
1924219264

1924319265
// get max distance player could have moved within max lag compensation time,
1924419266
// multiply by 1.5 to to avoid "dead zones" (sqrt(2) would be the exact value)
1924519267
float maxDistance = 1.5 * pPlayer->MaxSpeed() * sv_maxunlag.GetFloat();
1924619268

1924719269
// If the player is within this distance, lag compensate them in case they're running past us.
19248-
if ( vHisOrigin.DistTo( vMyOrigin ) < maxDistance )
19270+
if ( fDistance < maxDistance )
1924919271
return true;
1925019272

1925119273
// If their origin is not within a 45 degree cone in front of us, no need to lag compensate.

0 commit comments

Comments
 (0)