bool CBaseCombatCharacter::IsAbleToSee( CBaseCombatCharacter *pBCC, FieldOfViewCheckType checkFOV ) { Vector vecEyePosition, vecOtherEyePosition; ComputeSeeTestPosition( &vecEyePosition, this ); ComputeSeeTestPosition( &vecOtherEyePosition, pBCC ); #ifdef GAME_DLL Vector vecEyeToTarget; VectorSubtract( vecOtherEyePosition, vecEyePosition, vecEyeToTarget ); float flDistToOther = VectorNormalize( vecEyeToTarget ); // Test this every time; it's cheap. // We can't see because they are too far in the fog if ( IsHiddenByFog( flDistToOther ) ) return false; #endif // Check if we have a cached-off visibility int iCache = s_CombatCharVisCache.LookupVisibility( this, pBCC ); VisCacheResult_t nResult = s_CombatCharVisCache.HasVisibility( iCache ); // Compute symmetric visibility if ( nResult == VISCACHE_UNKNOWN ) { bool bThisCanSeeOther = false, bOtherCanSeeThis = false; if ( ComputeLOS( vecEyePosition, vecOtherEyePosition ) ) { bThisCanSeeOther = true, bOtherCanSeeThis = true; } s_CombatCharVisCache.RegisterVisibility( iCache, bThisCanSeeOther, bOtherCanSeeThis ); nResult = bThisCanSeeOther ? VISCACHE_IS_VISIBLE : VISCACHE_IS_NOT_VISIBLE; } if ( nResult == VISCACHE_IS_VISIBLE ) return ( checkFOV != USE_FOV || IsInFieldOfView( pBCC ) ); return false; }
bool CBaseCombatCharacter::IsAbleToSee( CBaseCombatCharacter *pBCC, FieldOfViewCheckType checkFOV ) { Vector vecEyePosition, vecOtherEyePosition; ComputeSeeTestPosition( &vecEyePosition, this ); ComputeSeeTestPosition( &vecOtherEyePosition, pBCC ); #ifdef GAME_DLL Vector vecEyeToTarget; VectorSubtract( vecOtherEyePosition, vecEyePosition, vecEyeToTarget ); float flDistToOther = VectorNormalize( vecEyeToTarget ); // Test this every time; it's cheap. // We can't see because they are too far in the fog if ( IsHiddenByFog( flDistToOther ) ) return false; #ifdef TERROR // Check this every time also, it's cheap; check to see if the enemy is in an obscured area. bool bIsInNavObscureRange = ( flDistToOther > NavObscureRange.GetFloat() ); if ( bIsInNavObscureRange ) { TerrorNavArea *pOtherNavArea = static_cast< TerrorNavArea* >( pBCC->GetLastKnownArea() ); if ( !pOtherNavArea || pOtherNavArea->HasSpawnAttributes( TerrorNavArea::SPAWN_OBSCURED ) ) return false; } #endif // TERROR #endif // Check if we have a cached-off visibility int iCache = s_CombatCharVisCache.LookupVisibility( this, pBCC ); VisCacheResult_t nResult = s_CombatCharVisCache.HasVisibility( iCache ); // Compute symmetric visibility if ( nResult == VISCACHE_UNKNOWN ) { bool bThisCanSeeOther = false, bOtherCanSeeThis = false; if ( ComputeLOS( vecEyePosition, vecOtherEyePosition ) ) { #if defined(GAME_DLL) && defined(TERROR) if ( !bIsInNavObscureRange ) { bThisCanSeeOther = true, bOtherCanSeeThis = true; } else { bThisCanSeeOther = !ComputeTargetIsInDarkness( vecEyePosition, pBCC->GetLastKnownArea(), vecOtherEyePosition ); bOtherCanSeeThis = !ComputeTargetIsInDarkness( vecOtherEyePosition, GetLastKnownArea(), vecEyePosition ); } #else bThisCanSeeOther = true, bOtherCanSeeThis = true; #endif } s_CombatCharVisCache.RegisterVisibility( iCache, bThisCanSeeOther, bOtherCanSeeThis ); nResult = bThisCanSeeOther ? VISCACHE_IS_VISIBLE : VISCACHE_IS_NOT_VISIBLE; } if ( nResult == VISCACHE_IS_VISIBLE ) return ( checkFOV != USE_FOV || IsInFieldOfView( pBCC ) ); return false; }