//----------------------------------------------------------------------------- // Purpose: Returns true if the entity passes our filter, false if not. // Input : pEntity - Entity to test. //----------------------------------------------------------------------------- bool CFilterMultiple::PassesFilterImpl( CBaseEntity *pCaller, CBaseEntity *pEntity ) { // Test against each filter if (m_nFilterType == FILTER_AND) { for (int i=0;i<MAX_FILTERS;i++) { if (m_hFilter[i] != NULL) { CBaseFilter* pFilter = (CBaseFilter *)(m_hFilter[i].Get()); if (!pFilter->PassesFilter( pCaller, pEntity ) ) { return false; } } } return true; } else // m_nFilterType == FILTER_OR { for (int i=0;i<MAX_FILTERS;i++) { if (m_hFilter[i] != NULL) { CBaseFilter* pFilter = (CBaseFilter *)(m_hFilter[i].Get()); if (pFilter->PassesFilter( pCaller, pEntity ) ) { return true; } } } return false; } }
void CPointEntityFinder::FindByRandom( void ) { // TODO: optimize the case where there is no filter m_hEntity = NULL; CBaseFilter *pFilter = m_hFilter.Get(); CUtlVector<CBaseEntity *> ValidEnts; CBaseEntity *pEntity = gEntList.FirstEnt(); do // note all valid entities. { if ( pFilter && pFilter->PassesFilter( this, pEntity ) ) { ValidEnts.AddToTail( pEntity ); } pEntity = gEntList.NextEnt( pEntity ); } while ( pEntity ); // pick one at random if ( ValidEnts.Count() != 0 ) { m_hEntity = ValidEnts[ RandomInt( 0, ValidEnts.Count() - 1 )]; } }
bool CFuncVPhysicsClip::EntityPassesFilter( CBaseEntity *pOther ) { CBaseFilter* pFilter = (CBaseFilter*)(m_hFilter.Get()); if ( pFilter ) return pFilter->PassesFilter( this, pOther ); if ( pOther->GetMoveType() == MOVETYPE_VPHYSICS && pOther->VPhysicsGetObject()->IsMoveable() ) return true; return false; }
//----------------------------------------------------------------------------- // Purpose: Checks whether this microphone can hear a given sound, and at what // relative volume level. // Input : pSound - Sound to test. // flVolume - Returns with the relative sound volume from 0 - 1. // Output : Returns true if the sound could be heard at the sample point, false if not. //----------------------------------------------------------------------------- bool CEnvMicrophone::CanHearSound(CSound *pSound, float &flVolume) { flVolume = 0; if ( m_bDisabled ) { return false; } // Cull out sounds except from specific entities CBaseFilter *pFilter = m_hListenFilter.Get(); if ( pFilter ) { CBaseEntity *pSoundOwner = pSound->m_hOwner.Get(); if ( !pSoundOwner || !pFilter->PassesFilter( this, pSoundOwner ) ) { return false; } } float flDistance = (pSound->GetSoundOrigin() - m_hMeasureTarget->GetAbsOrigin()).Length(); if (flDistance == 0) { flVolume = 1.0; return true; } // Over our max range? if ( m_flMaxRange && flDistance > m_flMaxRange ) { return false; } if (flDistance <= pSound->Volume() * m_flSensitivity) { flVolume = 1 - (flDistance / (pSound->Volume() * m_flSensitivity)); flVolume = clamp(flVolume, 0, 1); return true; } return false; }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- bool CEnvBeam::PassesTouchFilters(CBaseEntity *pOther) { bool fPassedSoFar = false; // Touched some player or NPC! if( m_TouchType != touch_npc_only ) { if( pOther->IsPlayer() ) { fPassedSoFar = true; } } if( m_TouchType != touch_player_only ) { if( pOther->IsNPC() ) { fPassedSoFar = true; } } if( m_TouchType == touch_player_or_npc_or_physicsprop ) { if( pOther->m_iClassname == g_iszPhysicsPropClassname ) { fPassedSoFar = true; } } if( fPassedSoFar ) { CBaseFilter* pFilter = (CBaseFilter*)(m_hFilter.Get()); return (!pFilter) ? true : pFilter->PassesFilter( this, pOther ); } return false; }
//----------------------------------------------------------------------------- // Purpose: Return true if the microphone can hear the specified sound //----------------------------------------------------------------------------- bool CEnvMicrophone::CanHearSound( int entindex, soundlevel_t soundlevel, float &flVolume, const Vector *pOrigin ) { if ( m_bDisabled ) { flVolume = 0; return false; } if ( ( m_spawnflags & SF_MICROPHONE_IGNORE_NONATTENUATED ) && soundlevel == SNDLVL_NONE ) { return false; } // Sound might be coming from an origin or from an entity. CBaseEntity *pEntity = NULL; if ( entindex ) { pEntity = CBaseEntity::Instance( engine->PEntityOfEntIndex(entindex) ); } // Cull out sounds except from specific entities CBaseFilter *pFilter = m_hListenFilter.Get(); if ( pFilter ) { if ( !pEntity || !pFilter->PassesFilter( this, pEntity ) ) { flVolume = 0; return false; } } float flDistance = 0; if ( pOrigin ) { flDistance = pOrigin->DistTo( m_hMeasureTarget->GetAbsOrigin() ); } else if ( pEntity ) { flDistance = pEntity->WorldSpaceCenter().DistTo( m_hMeasureTarget->GetAbsOrigin() ); } // Over our max range? if ( m_flMaxRange && flDistance > m_flMaxRange ) { #ifdef DEBUG_MICROPHONE Msg("OUT OF RANGE.\n" ); #endif return false; } #ifdef DEBUG_MICROPHONE Msg(" flVolume %f ", flVolume ); #endif // Reduce the volume by the amount it fell to get to the microphone float gain = enginesound->GetDistGainFromSoundLevel( soundlevel, flDistance ); flVolume *= gain; #ifdef DEBUG_MICROPHONE Msg("dist %2f, soundlevel %d: gain %f", flDistance, (int)soundlevel, gain ); if ( !flVolume ) { Msg(" : REJECTED\n" ); } else { Msg(" : SENT\n" ); } #endif return ( flVolume > 0 ); }
bool CBaseDoor::PassesBlockTouchFilter(CBaseEntity *pOther) { CBaseFilter* pFilter = (CBaseFilter*)(m_hBlockFilter.Get()); return ( pFilter && pFilter->PassesFilter( this, pOther ) ); }
void CPointEntityFinder::FindByDistance( void ) { m_hEntity = NULL; CBaseFilter *pFilter = m_hFilter.Get(); // go through each entity and determine whether it's closer or farther from the current entity. Pick according to Method selected. float flBestDist = 0; CBaseEntity *pEntity = gEntList.FirstEnt(); while ( pEntity ) { if ( FStrEq( STRING( pEntity->m_iClassname ), "worldspawn" ) || FStrEq( STRING( pEntity->m_iClassname ), "soundent" ) || FStrEq( STRING( pEntity->m_iClassname ), "player_manager" ) || FStrEq( STRING( pEntity->m_iClassname ), "bodyque" ) || FStrEq( STRING( pEntity->m_iClassname ), "ai_network" ) || pEntity == this || ( pFilter && !( pFilter->PassesFilter( this, pEntity ) ) ) ) { pEntity = gEntList.NextEnt( pEntity ); continue; } // if we have a reference entity, use that, otherwise, check against 'this' Vector vecStart; if ( m_hReference ) { vecStart = m_hReference->GetAbsOrigin(); } else { vecStart = GetAbsOrigin(); } // init m_hEntity with a valid entity. if (m_hEntity == NULL ) { m_hEntity = pEntity; flBestDist = ( pEntity->GetAbsOrigin() - vecStart ).LengthSqr(); } float flNewDist = ( pEntity->GetAbsOrigin() - vecStart ).LengthSqr(); switch ( m_FindMethod ) { case ( ENT_FIND_METHOD_NEAREST ): if ( flNewDist < flBestDist ) { m_hEntity = pEntity; flBestDist = flNewDist; } break; case ( ENT_FIND_METHOD_FARTHEST ): if ( flNewDist > flBestDist ) { m_hEntity = pEntity; flBestDist = flNewDist; } break; default: Assert( false ); break; } pEntity = gEntList.NextEnt( pEntity ); } }