//========================================================= // Leader boid calls this to form a flock from surrounding boids //========================================================= void CFlockingFlyer :: FormFlock( void ) { if ( !InSquad() ) { // I am my own leader m_pSquadLeader = this; m_pSquadNext = NULL; int squadCount = 1; CBaseEntity *pEntity = NULL; while ((pEntity = UTIL_FindEntityInSphere( pEntity, pev->origin, AFLOCK_MAX_RECRUIT_RADIUS )) != NULL) { CBaseMonster *pRecruit = pEntity->MyMonsterPointer( ); if ( pRecruit && pRecruit != this && pRecruit->IsAlive() && !pRecruit->m_pCine ) { // Can we recruit this guy? if ( FClassnameIs ( pRecruit->pev, "monster_flyer" ) ) { squadCount++; SquadAdd( (CFlockingFlyer *)pRecruit ); } } } } SetThink( &CFlockingFlyer::IdleThink );// now that flock is formed, go to idle and wait for a player to come along. pev->nextthink = gpGlobals->time; }
//========================================================= // // SquadRecruit(), get some monsters of my classification and // link them as a group. returns the group size // //========================================================= int CSquadMonster :: SquadRecruit( int searchRadius, int maxMembers ) { int squadCount; int iMyClass = Classify();// cache this monster's class // Don't recruit if I'm already in a group if ( InSquad() ) return 0; if ( maxMembers < 2 ) return 0; // I am my own leader m_hSquadLeader = this; squadCount = 1; CBaseEntity *pEntity = NULL; if ( !FStringNull( pev->netname ) ) { // I have a netname, so unconditionally recruit everyone else with that name. pEntity = UTIL_FindEntityByString( pEntity, "netname", STRING( pev->netname ) ); while ( pEntity ) { CSquadMonster *pRecruit = pEntity->MySquadMonsterPointer(); if ( pRecruit ) { if ( !pRecruit->InSquad() && pRecruit->Classify() == iMyClass && pRecruit != this ) { // minimum protection here against user error.in worldcraft. if (!SquadAdd( pRecruit )) break; squadCount++; } } pEntity = UTIL_FindEntityByString( pEntity, "netname", STRING( pev->netname ) ); } } else { while ((pEntity = UTIL_FindEntityInSphere( pEntity, pev->origin, searchRadius )) != NULL) { CSquadMonster *pRecruit = pEntity->MySquadMonsterPointer( ); if ( pRecruit && pRecruit != this && pRecruit->IsAlive() && !pRecruit->m_pCine ) { // Can we recruit this guy? if ( !pRecruit->InSquad() && pRecruit->Classify() == iMyClass && ( (iMyClass != CLASS_ALIEN_MONSTER) || FStrEq(STRING(pev->classname), STRING(pRecruit->pev->classname))) && FStringNull( pRecruit->pev->netname ) ) { TraceResult tr; UTIL_TraceLine( pev->origin + pev->view_ofs, pRecruit->pev->origin + pev->view_ofs, ignore_monsters, pRecruit->edict(), &tr );// try to hit recruit with a traceline. if ( tr.flFraction == 1.0 ) { if (!SquadAdd( pRecruit )) break; squadCount++; } } } } } // no single member squads if (squadCount == 1) { m_hSquadLeader = NULL; } return squadCount; }