//------------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------------
CBaseEntity* CScriptedTarget::FindEntity( void )
{
	// ---------------------------------------------------
	//	First try to find the entity by name
	// ---------------------------------------------------
	CBaseEntity *pEntity = gEntList.FindEntityByName( NULL, m_iszEntity );
	if (pEntity && pEntity->GetFlags() & FL_NPC)
	{
		CAI_BaseNPC* pNPC	= pEntity->MyNPCPointer();
		if (pNPC->DispatchInteraction( g_interactionScriptedTarget, NULL, this ))
		{
			return pEntity;
		}
	}

	// ---------------------------------------------------
	//	If that fails, assume we were given a classname
	//  and find nearest entity in radius of that class
	// ---------------------------------------------------
	float			flNearestDist	= MAX_COORD_RANGE;
	CBaseEntity*	pNearestEnt		= NULL;
	CBaseEntity*	pTestEnt		= NULL;

	for ( CEntitySphereQuery sphere( GetAbsOrigin(), m_flRadius ); ( pTestEnt = sphere.GetCurrentEntity() ) != NULL; sphere.NextEntity() )
	{
		if (pTestEnt->GetFlags() & FL_NPC)
		{
			if (FClassnameIs( pTestEnt, STRING(m_iszEntity)))
			{
				float flTestDist = (pTestEnt->GetAbsOrigin() - GetAbsOrigin()).Length();
				if (flTestDist < flNearestDist)
				{
					flNearestDist	= flTestDist;
					pNearestEnt		= pTestEnt;
				}
			}
		}
	}
	
	// UNDONE: If nearest fails, try next nearest
	if (pNearestEnt)
	{
		CAI_BaseNPC* pNPC	= pNearestEnt->MyNPCPointer();
		if (pNPC->DispatchInteraction( g_interactionScriptedTarget, NULL, this ))
		{
			return pNearestEnt;
		}
	}

	return NULL;
}
//------------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------------
void CScriptedTarget::TurnOff( void )
{
	SetThink( NULL );
	m_iDisabled		= true;

	// If I have a target entity, free him
	if (GetTarget())
	{
		CAI_BaseNPC* pNPC	= GetTarget()->MyNPCPointer();
		pNPC->DispatchInteraction( g_interactionScriptedTarget, NULL, NULL );
	}
}
Exemple #3
0
int	CAI_Squad::BroadcastInteraction( int interactionType, void *data, CBaseCombatCharacter *sender )
{
	//Must have a squad
	if ( m_SquadMembers.Count() == 0 )
		return false;

	//Broadcast to all members of the squad
	for ( int i = 0; i < m_SquadMembers.Count(); i++ )
	{
		CAI_BaseNPC *pMember = m_SquadMembers[i]->MyNPCPointer();
		
		//Validate and don't send again to the sender
		if ( ( pMember != NULL) && ( pMember != sender ) )
		{
			//Send it
			pMember->DispatchInteraction( interactionType, data, sender );
		}
	}

	return true;
}