//----------------------------------------------------------------------------- // Purpose: Finds the first entity by name within a radius // Input : pStartEntity - The entity to start from when doing the search. // szName - Entity name to search for. // vecSrc - Center of search radius. // flRadius - Search radius for classname search, 0 to search everywhere. // pSearchingEntity - The entity that is doing the search. // pActivator - The activator entity if this was called from an input // or Use handler, NULL otherwise. // Output : Returns a pointer to the found entity, NULL if none. //----------------------------------------------------------------------------- CBaseEntity *CGlobalEntityList::FindEntityByNameWithin( CBaseEntity *pStartEntity, const char *szName, const Vector &vecSrc, float flRadius, CBaseEntity *pSearchingEntity, CBaseEntity *pActivator, CBaseEntity *pCaller ) { // // Check for matching class names within the search radius. // CBaseEntity *pEntity = pStartEntity; float flMaxDist2 = flRadius * flRadius; if (flMaxDist2 == 0) { return gEntList.FindEntityByName( pEntity, szName, pSearchingEntity, pActivator, pCaller ); } while ((pEntity = gEntList.FindEntityByName( pEntity, szName, pSearchingEntity, pActivator, pCaller )) != NULL) { if ( !pEntity->edict() ) continue; float flDist2 = (pEntity->GetAbsOrigin() - vecSrc).LengthSqr(); if (flMaxDist2 > flDist2) { return pEntity; } } return NULL; }
//----------------------------------------------------------------------------- // Purpose: Finds the nearest entity by name within a radius // Input : szName - Entity name to search for. // vecSrc - Center of search radius. // flRadius - Search radius for classname search, 0 to search everywhere. // pSearchingEntity - The entity that is doing the search. // pActivator - The activator entity if this was called from an input // or Use handler, NULL otherwise. // Output : Returns a pointer to the found entity, NULL if none. //----------------------------------------------------------------------------- CBaseEntity *CGlobalEntityList::FindEntityByNameNearest( const char *szName, const Vector &vecSrc, float flRadius, CBaseEntity *pSearchingEntity, CBaseEntity *pActivator, CBaseEntity *pCaller ) { CBaseEntity *pEntity = NULL; // // Check for matching class names within the search radius. // float flMaxDist2 = flRadius * flRadius; if (flMaxDist2 == 0) { flMaxDist2 = MAX_TRACE_LENGTH * MAX_TRACE_LENGTH; } CBaseEntity *pSearch = NULL; while ((pSearch = gEntList.FindEntityByName( pSearch, szName, pSearchingEntity, pActivator, pCaller )) != NULL) { if ( !pSearch->edict() ) continue; float flDist2 = (pSearch->GetAbsOrigin() - vecSrc).LengthSqr(); if (flMaxDist2 > flDist2) { pEntity = pSearch; flMaxDist2 = flDist2; } } return pEntity; }
//----------------------------------------------------------------------------- // Purpose: Finds an entity by target name or class name. // Input : pStartEntity - The entity to start from when doing the search. // szName - Entity name to search for. Treated as a target name first, // then as an entity class name, ie "info_target". // vecSrc - Center of search radius. // flRadius - Search radius for classname search, 0 to search everywhere. // pSearchingEntity - The entity that is doing the search. // pActivator - The activator entity if this was called from an input // or Use handler, NULL otherwise. // Output : Returns a pointer to the found entity, NULL if none. //----------------------------------------------------------------------------- CBaseEntity *CGlobalEntityList::FindEntityGeneric( CBaseEntity *pStartEntity, const char *szName, CBaseEntity *pSearchingEntity, CBaseEntity *pActivator, CBaseEntity *pCaller ) { CBaseEntity *pEntity = NULL; pEntity = gEntList.FindEntityByName( pStartEntity, szName, pSearchingEntity, pActivator, pCaller ); if (!pEntity) { pEntity = gEntList.FindEntityByClassname( pStartEntity, szName ); } return pEntity; }
//----------------------------------------------------------------------------- // Purpose: Finds the first entity by name within a radius // Input : pStartEntity - The entity to start from when doing the search. // szName - Entity name to search for. // vecSrc - Center of search radius. // flRadius - Search radius for classname search, 0 to search everywhere. // pSearchingEntity - The entity that is doing the search. // pActivator - The activator entity if this was called from an input // or Use handler, NULL otherwise. // Output : Returns a pointer to the found entity, NULL if none. //----------------------------------------------------------------------------- CBaseEntity *CGlobalEntityList::FindEntityByNameWithin( CBaseEntity *pStartEntity, const char *szName, const Vector &vecSrc, float flRadius, CBaseEntity *pSearchingEntity, CBaseEntity *pActivator, CBaseEntity *pCaller, int brushPrecision ) { // // Check for matching class names within the search radius. // CBaseEntity *pEntity = pStartEntity; float flMaxDist2 = flRadius * flRadius; if (flMaxDist2 == 0) { return gEntList.FindEntityByName( pEntity, szName, pSearchingEntity, pActivator, pCaller ); } while ((pEntity = gEntList.FindEntityByName( pEntity, szName, pSearchingEntity, pActivator, pCaller )) != NULL) { if ( !pEntity->edict() ) continue; Vector origin; if ( pEntity->IsBSPModel() && pEntity->CollisionProp()) { if ( brushPrecision == BRUSHPRECISION_NEAREST ) pEntity->CollisionProp()->CalcNearestPoint(vecSrc,&origin); else origin = pEntity->CollisionProp()->GetCollisionOrigin(); } else origin = pEntity->GetAbsOrigin(); float flDist2 = (origin - vecSrc).LengthSqr(); if (flMaxDist2 > flDist2) { return pEntity; } } return NULL; }