Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable lag compensation for teammates #42

Merged
merged 1 commit into from
Aug 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions game/server/tf/tf_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ ConVar tf_halloween_giant_health_scale( "tf_halloween_giant_health_scale", "10",
ConVar tf_grapplinghook_los_force_detach_time( "tf_grapplinghook_los_force_detach_time", "1", FCVAR_CHEAT );
ConVar tf_powerup_max_charge_time( "tf_powerup_max_charge_time", "30", FCVAR_CHEAT );

ConVar tf_unlag_teammates( "tf_unlag_teammates", "1", FCVAR_NOTIFY, "Controls lag compensation for teammates. 0: Disable, 1: Enable, 2: Melee weapons only" );

extern ConVar tf_powerup_mode;
extern ConVar tf_mvm_buybacks_method;
extern ConVar tf_mvm_buybacks_per_wave;
Expand Down Expand Up @@ -19230,22 +19232,42 @@ bool CTFPlayer::WantsLagCompensationOnEntity( const CBasePlayer *pPlayer, const
}
}

if ( pPlayer->GetTeamNumber() == GetTeamNumber() && bIsMedic == false )
return false;

// check if teammates should be lag compensated
int iUnlagTeammates = 0;
if ( pPlayer->GetTeamNumber() == GetTeamNumber() )
{
iUnlagTeammates = tf_unlag_teammates.GetInt();

if ( iUnlagTeammates == 0 && bIsMedic == false )
return false;
}

// If this entity hasn't been transmitted to us and acked, then don't bother lag compensating it.
if ( pEntityTransmitBits && !pEntityTransmitBits->Get( pPlayer->entindex() ) )
return false;

const Vector &vMyOrigin = GetAbsOrigin();
const Vector &vHisOrigin = pPlayer->GetAbsOrigin();

float fDistance = vHisOrigin.DistTo( vMyOrigin );

// teammates are only lag compensated for melee attacks for tf_unlag_teammates 2
if ( iUnlagTeammates == 2 )
{
if ( fDistance > 512 )
return false;

CTFWeaponBaseMelee *pWeapon = dynamic_cast <CTFWeaponBaseMelee*>( GetActiveWeapon() );
if ( !pWeapon )
return false;
}

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

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

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