Skip to content

Commit 53953b4

Browse files
authored
Merge pull request #43 from wgetJane/melee-enemy-priority
prevent teammates from blocking melee attacks
2 parents af2d327 + a019527 commit 53953b4

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

game/shared/tf/tf_weaponbase_melee.cpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#endif
2525

2626
ConVar tf_weapon_criticals_melee( "tf_weapon_criticals_melee", "1", FCVAR_REPLICATED | FCVAR_NOTIFY, "Controls random crits for melee weapons. 0 - Melee weapons do not randomly crit. 1 - Melee weapons can randomly crit only if tf_weapon_criticals is also enabled. 2 - Melee weapons can always randomly crit regardless of the tf_weapon_criticals setting." );
27+
ConVar tf_melee_enemy_priority( "tf_melee_enemy_priority", "1", FCVAR_REPLICATED | FCVAR_NOTIFY, "Prevents teammates from blocking melee attacks." );
2728

2829
//=============================================================================
2930
//
@@ -479,8 +480,6 @@ bool CTFWeaponBaseMelee::DoSwingTraceInternal( trace_t &trace, bool bCleave, CUt
479480
}
480481
else
481482
{
482-
bool bSapperHit = false;
483-
484483
// if this weapon can damage sappers, do that trace first
485484
int iDmgSappers = 0;
486485
CALL_ATTRIB_HOOK_INT( iDmgSappers, set_dmg_apply_to_sapper );
@@ -501,51 +500,52 @@ bool CTFWeaponBaseMelee::DoSwingTraceInternal( trace_t &trace, bool bCleave, CUt
501500
CBaseObject *pObject = static_cast< CBaseObject* >( trace.m_pEnt );
502501
if ( pObject->HasSapper() )
503502
{
504-
bSapperHit = true;
503+
return true;
505504
}
506505
}
507506
}
508507

509-
if ( !bSapperHit )
508+
bool bEnemyPriority = tf_melee_enemy_priority.GetBool();
509+
bool bHullTrace = false;
510+
511+
if ( bEnemyPriority || bDontHitTeammates )
510512
{
511-
// See if we hit anything.
512-
if ( bDontHitTeammates )
513-
{
514-
UTIL_TraceLine( vecSwingStart, vecSwingEnd, MASK_SOLID, &ignoreTeammatesFilter, &trace );
515-
}
516-
else
513+
bHullTrace = false;
514+
UTIL_TraceLine( vecSwingStart, vecSwingEnd, MASK_SOLID, &ignoreTeammatesFilter, &trace );
515+
516+
if ( trace.fraction >= 1.0 )
517517
{
518-
CTraceFilterIgnoreFriendlyCombatItems filter( pPlayer, COLLISION_GROUP_NONE, pPlayer->GetTeamNumber() );
519-
UTIL_TraceLine( vecSwingStart, vecSwingEnd, MASK_SOLID, &filter, &trace );
518+
bHullTrace = true;
519+
UTIL_TraceHull( vecSwingStart, vecSwingEnd, vecSwingMins, vecSwingMaxs, MASK_SOLID, &ignoreTeammatesFilter, &trace );
520520
}
521+
}
522+
523+
if ( !bEnemyPriority || !bDontHitTeammates && ( trace.fraction >= 1.0 || !trace.m_pEnt->IsPlayer() ) )
524+
{
525+
bHullTrace = false;
526+
CTraceFilterIgnoreFriendlyCombatItems filter( pPlayer, COLLISION_GROUP_NONE, pPlayer->GetTeamNumber() );
527+
UTIL_TraceLine( vecSwingStart, vecSwingEnd, MASK_SOLID, &filter, &trace );
521528

522529
if ( trace.fraction >= 1.0 )
523530
{
524-
if ( bDontHitTeammates )
525-
{
526-
UTIL_TraceHull( vecSwingStart, vecSwingEnd, vecSwingMins, vecSwingMaxs, MASK_SOLID, &ignoreTeammatesFilter, &trace );
527-
}
528-
else
529-
{
530-
CTraceFilterIgnoreFriendlyCombatItems filter( pPlayer, COLLISION_GROUP_NONE, pPlayer->GetTeamNumber() );
531-
UTIL_TraceHull( vecSwingStart, vecSwingEnd, vecSwingMins, vecSwingMaxs, MASK_SOLID, &filter, &trace );
532-
}
533-
534-
if ( trace.fraction < 1.0 )
535-
{
536-
// Calculate the point of intersection of the line (or hull) and the object we hit
537-
// This is and approximation of the "best" intersection
538-
CBaseEntity *pHit = trace.m_pEnt;
539-
if ( !pHit || pHit->IsBSPModel() )
540-
{
541-
// Why duck hull min/max?
542-
FindHullIntersection( vecSwingStart, trace, VEC_DUCK_HULL_MIN, VEC_DUCK_HULL_MAX, pPlayer );
543-
}
531+
bHullTrace = true;
532+
UTIL_TraceHull( vecSwingStart, vecSwingEnd, vecSwingMins, vecSwingMaxs, MASK_SOLID, &filter, &trace );
533+
}
534+
}
544535

545-
// This is the point on the actual surface (the hull could have hit space)
546-
vecSwingEnd = trace.endpos;
547-
}
536+
if ( bHullTrace && trace.fraction < 1.0 )
537+
{
538+
// Calculate the point of intersection of the line (or hull) and the object we hit
539+
// This is and approximation of the "best" intersection
540+
CBaseEntity *pHit = trace.m_pEnt;
541+
if ( !pHit || pHit->IsBSPModel() )
542+
{
543+
// Why duck hull min/max?
544+
FindHullIntersection( vecSwingStart, trace, VEC_DUCK_HULL_MIN, VEC_DUCK_HULL_MAX, pPlayer );
548545
}
546+
547+
// This is the point on the actual surface (the hull could have hit space)
548+
vecSwingEnd = trace.endpos;
549549
}
550550

551551
return ( trace.fraction < 1.0f );

0 commit comments

Comments
 (0)