UTIL_EntitiesInBox

From Valve Developer Community
Jump to: navigation, search
Deutsch

UTIL_EntitiesInBox is a UTIL provided in the Source code for finding entities within a specified box. It takes an Entity List, Mins, Maxes, and flags, returning a count of entities, as well as a list of the entities.


Usage

//-----------------------------------------------------------------------------
// Purpose: Returns the number of entities in the box, plus an array of pointers to the entities.
//          
// Input  : CBaseEntity - *pList   | A pointer to an array, the function will store a pointer to the Entities it finds in this array.
// Input  : int - listMax     | Maximum number of entities to return
// Input  : Vector - &mins    | The mins of a box to check. World space coordinate.
// Input  : Vector - &maxs    | The maxs of a box to check. World space coordinate.
// Input  : int - flagmask    | 
// Output : *pList
// Output : int - Returns the amount of entities it finds
//-----------------------------------------------------------------------------
inline int UTIL_EntitiesInBox( CBaseEntity **pList, int listMax, const Vector &mins, const Vector &maxs, int flagMask )
//-----------------------------------------------------------------------------
// Purpose: Returns the number of entities in the box.
//          
// Input  : Vector - &mins    | The mins of a box to check. World space coordinate.
// Input  : Vector - &maxs    | The maxs of a box to check. World space coordinate.
// Input  : CFlaggedEntitiesEnum *pEnum    | TODO
// Output : int - Returns the amount of entities it finds
//-----------------------------------------------------------------------------
int  UTIL_EntitiesInBox( const Vector &mins, const Vector &maxs, CFlaggedEntitiesEnum *pEnum  );

flagmask is avaible in const.h, lines 97-132

Examples

//Create an array of CBaseEntity pointers
CBaseEntity*	pList[20];

//Put the pointers in the pList, and get how many entities there are
int count = UTIL_EntitiesInBox( pList, 20, spawnOrigin + NAI_Hull::Mins( HULL_MEDIUM ), spawnOrigin + NAI_Hull::Maxs( HULL_MEDIUM ), 0 );

//Iterate over all the possible targets
for ( int i = 0; i < count; i++ )
{
        //If the particular entity's movetype isn't MOVETYPE_VPHYSICS, skip the rest of this loop, and go to the next entity
	if ( pList[i]->GetMoveType() != MOVETYPE_VPHYSICS )
		continue;

	if ( PhysGetEntityMass( pList[i] ) > ANTLION_MAKER_BLOCKED_MASS )
	{
		bBlocked = true;
		iNumBlocked++;
		pBlocker = pList[i];

		if ( pTestHint == pNode )
		{
			bChosenHintBlocked = true;
		}

		break;
	}
}
//This uses the overloaded function, and only returns the number of entities.
CBaseEntity *entityList[64];
Vector range(ROLLERMINE_WAKEUP_DIST,ROLLERMINE_WAKEUP_DIST,64);
int boxCount = UTIL_EntitiesInBox( entityList, ARRAYSIZE(entityList), GetAbsOrigin()-range, GetAbsOrigin()+range, FL_NPC );