Permalink
Browse files

make sabotaged sentries behave with friendly fire

fixes #327
  • Loading branch information...
Dexter Haslem
Dexter Haslem committed Oct 6, 2018
1 parent e9e030e commit 1290b80898b760106597a65379c614674eb94808
Showing with 24 additions and 6 deletions.
  1. +24 −6 game_shared/ff/ff_gamerules.cpp
@@ -2087,27 +2087,45 @@ bool CFFGameRules::FCanTakeDamage( CBaseEntity *pVictim, CBaseEntity *pAttacker
// if it's a buildable, then we use the buildable's owner to perform the team checks etc. -> Defrag
CBasePlayer *pBuildableOwner = NULL;
bool isFriendlyFireOn = friendlyfire.GetInt() != 0;
#ifdef GAME_DLL
// Special cases for sabotageable buildings
// Dexter 20181006: overhauled this section of code,
// it was a bit too sweeping, letting any sabotaged attackers or victims
// damage, or be damaged by anyone, regardless of friendly fire
// this fixes #327 , which was SG specific, but applied same
// treatment to detting dispensers
// If an SG is shooting its teammates then allow it to hurt them
if (pAttacker && pAttacker->Classify() == CLASS_SENTRYGUN)
{
CFFSentryGun *pSentry = dynamic_cast< CFFSentryGun* > (pAttacker);
if (pSentry && pSentry->IsMaliciouslySabotaged())
return true;
if ( pSentry && pSentry->IsMaliciouslySabotaged() )
{
bool victimIsSabTeammate = FFGameRules()->IsTeam1AlliedToTeam2(
pVictim->GetTeamNumber(),
pSentry->m_iSaboteurTeamNumber ) == GR_TEAMMATE;
return victimIsSabTeammate ? isFriendlyFireOn : true;
}
}
if ( pVictim && pVictim->Classify() == CLASS_SENTRYGUN )
{
CFFSentryGun *pSentry = dynamic_cast <CFFSentryGun *> (pVictim);
// Allow team to kill their own SG if it is sabotaged
if (pSentry && pSentry->IsSabotaged())
return true;
if ( pSentry && pSentry->IsSabotaged() )
{
bool attackerIsSabTeammate = FFGameRules()->IsTeam1AlliedToTeam2(
pAttacker->GetTeamNumber(),
pSentry->m_iSaboteurTeamNumber ) == GR_TEAMMATE;
// if it's not sabotaged then we need to get its owner and use it later on
return attackerIsSabTeammate ? isFriendlyFireOn : true;
}
// if it's not sabotaged then we need to get its owner and use it later on
pBuildableOwner = dynamic_cast< CBasePlayer* > ( pSentry->m_hOwner.Get() );
if( ! pBuildableOwner )
@@ -2159,7 +2177,7 @@ bool CFFGameRules::FCanTakeDamage( CBaseEntity *pVictim, CBaseEntity *pAttacker
// If friendly fire is off and I'm not attacking myself, then
// someone else on my team/an ally is attacking me - don't
// take damage
if (( friendlyfire.GetInt() == 0 ) && ( pVictim != pAttacker ))
if ( !isFriendlyFireOn && pVictim != pAttacker )
return false;
}

0 comments on commit 1290b80

Please sign in to comment.