//------------------------------------- // Purpose: Returns true if given entity is in the squad //------------------------------------- bool CAI_Squad::SquadIsMember( CBaseEntity *pMember ) { CAI_BaseNPC *pNPC = pMember->MyNPCPointer(); if ( pNPC && pNPC->GetSquad() == this ) return true; return false; }
//----------------------------------------------------------------------------- // Purpose: Attempt to govern how many squad members can target any given entity // Input : *pCaller - Entity assessing the target // *pEnemy - Entity being assessed // Output : Returns true if potential enemy passes this filter stage //----------------------------------------------------------------------------- bool CFilterEnemy::PassesMobbedFilter( CBaseEntity *pCaller, CBaseEntity *pEnemy ) { // Must be a valid candidate CAI_BaseNPC *pNPC = pCaller->MyNPCPointer(); if ( pNPC == NULL || pNPC->GetSquad() == NULL ) return true; // Make sure we're checking for this if ( m_nMaxSquadmatesPerEnemy <= 0 ) return true; AISquadIter_t iter; int nNumMatchingSquadmates = 0; // Look through our squad members to see how many of them are already mobbing this entity for ( CAI_BaseNPC *pSquadMember = pNPC->GetSquad()->GetFirstMember( &iter ); pSquadMember != NULL; pSquadMember = pNPC->GetSquad()->GetNextMember( &iter ) ) { // Disregard ourself if ( pSquadMember == pNPC ) continue; // If the enemies match, count it if ( pSquadMember->GetEnemy() == pEnemy ) { nNumMatchingSquadmates++; // If we're at or passed the max we stop if ( nNumMatchingSquadmates >= m_nMaxSquadmatesPerEnemy ) { // We wanted to find more than allowed and we did if ( m_bNegated ) return true; // We wanted to be less but we're not return false; } } } // We wanted to find more than the allowed amount but we didn't if ( m_bNegated ) return false; return true; }