//----------------------------------------------------------------------------- // Purpose: // Input : *pActivator - // *pCaller - // useType - // value - //----------------------------------------------------------------------------- void CItem_AmmoCrate::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { CPlayer *pPlayer = ToBasePlayer( CEntity::Instance(pActivator) ); if ( pPlayer == NULL ) return; m_OnUsed.FireOutput( pActivator, this ); int iSequence = LookupSequence( "Open" ); // See if we're not opening already if ( GetSequence() != iSequence ) { Vector mins, maxs; trace_t tr; CollisionProp()->WorldSpaceAABB( &mins, &maxs ); Vector vOrigin = GetAbsOrigin(); vOrigin.z += ( maxs.z - mins.z ); mins = (mins - GetAbsOrigin()) * 0.2f; maxs = (maxs - GetAbsOrigin()) * 0.2f; mins.z = ( GetAbsOrigin().z - vOrigin.z ); UTIL_TraceHull( vOrigin, vOrigin, mins, maxs, MASK_SOLID, BaseEntity(), COLLISION_GROUP_NONE, &tr ); if ( tr.startsolid || tr.allsolid ) return; m_hActivator.Set(pPlayer->BaseEntity()); // Animate! ResetSequence( iSequence ); // Make sound CPASAttenuationFilter sndFilter( this, "AmmoCrate.Open" ); EmitSound( sndFilter, entindex(), "AmmoCrate.Open" ); // Start thinking to make it return SetThink( &CItem_AmmoCrate::CrateThink ); SetNextThink( gpGlobals->curtime + 0.1f ); } // Don't close again for two seconds m_flCloseTime = gpGlobals->curtime + AMMO_CRATE_CLOSE_DELAY; }
int CAI_Senses::LookForHighPriorityEntities( int iDistance ) { int nSeen = 0; if ( gpGlobals->curtime - m_TimeLastLookHighPriority > AI_HIGH_PRIORITY_SEARCH_TIME ) { m_TimeLastLookHighPriority = gpGlobals->curtime; BeginGather(); float distSq = ( iDistance * iDistance ); const Vector &origin = GetAbsOrigin(); // Players for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { CPlayer *pPlayer = UTIL_PlayerByIndex( i ); if ( pPlayer ) { if ( origin.DistToSqr(pPlayer->GetAbsOrigin()) < distSq && Look( pPlayer->BaseEntity() ) ) { nSeen++; } } } EndGather( nSeen, &m_SeenHighPriority ); } else { for ( int i = m_SeenHighPriority.Count() - 1; i >= 0; --i ) { if ( m_SeenHighPriority[i].Get() == NULL ) m_SeenHighPriority.FastRemove( i ); } nSeen = m_SeenHighPriority.Count(); } return nSeen; }