//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CObjectBuffStation::BoostObjectThink( void )
{
	// Set next boost object think time.
	SetNextThink( gpGlobals->curtime + BUFF_STATION_BOOST_OBJECT_THINK_INTERVAL, 
		          BUFF_STATION_BOOST_OBJECT_THINK_CONTEXT );

	// If we're emped, placing, or building, we're not ready to powerup
	if ( IsPlacing() || IsBuilding() || HasPowerup( POWERUP_EMP ) )
		return;

	float flMaxRangeSq = obj_buff_station_obj_range.GetFloat();
	flMaxRangeSq *= flMaxRangeSq;

	// Boost objects.
	for ( int iObject = m_nObjectCount; --iObject >= 0; )
	{
		CBaseObject *pObject = m_hObjects[iObject].Get();
		if ( !pObject || !InSameTeam( pObject ) )
		{
			DetachObjectByIndex( iObject );
			continue;
		}

		// Check for out of range.
		float flDistSq = GetAbsOrigin().DistToSqr( pObject->GetAbsOrigin() ); 
		if ( flDistSq > flMaxRangeSq )
		{
			DetachObjectByIndex( iObject );
			continue;
		}

		// Don't powerup it until it's finished building
		if ( pObject->IsPlacing() || pObject->IsBuilding() )
			continue;

		// Boost it
		if ( !pObject->AttemptToPowerup( POWERUP_BOOST, BUFF_STATION_BOOST_OBJECT_THINK_INTERVAL, 0, 
			                                  this, &m_aObjectAttachInfo[iObject].m_DamageModifier ) )
		{
			m_aObjectAttachInfo[iObject].m_DamageModifier.RemoveModifier();
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: Detach the object from the "Buff Station."
//-----------------------------------------------------------------------------
void CObjectBuffStation::DetachObject( CBaseObject *pObject )
{
	for ( int iObject = 0; iObject < m_nObjectCount; ++iObject )
	{
		if ( m_hObjects[iObject].Get() == pObject )
		{
			DetachObjectByIndex( iObject );
			return;
		}
	}
}
void CObjectBuffStation::OnGoInactive( void )
{
	BaseClass::OnGoInactive();

	// Detach all players.
	for ( int iPlayer = 0; iPlayer < BUFF_STATION_MAX_PLAYERS; iPlayer++ )
	{
		CBaseTFPlayer *pPlayer = m_hPlayers[iPlayer].Get();
		if ( pPlayer )
			ClientPrint( pPlayer, HUD_PRINTCENTER, "Lost power to Buff Station!" );

		DetachPlayerByIndex( iPlayer );
	}

	// Detach all objects.
	for ( int iObject = m_nObjectCount - 1; iObject >= 0; --iObject )
		DetachObjectByIndex( iObject );
}
//-----------------------------------------------------------------------------
// Purpose: Remove this object from it's team and mark it for deletion.
//-----------------------------------------------------------------------------
void CObjectBuffStation::DestroyObject( void )
{
	// Detach all players.
	for ( int iPlayer = 0; iPlayer < BUFF_STATION_MAX_PLAYERS; iPlayer++ )
		DetachPlayerByIndex( iPlayer );

	// Detach all objects.
	for( int iObject = m_nObjectCount - 1; iObject >= 0; --iObject )
		DetachObjectByIndex( iObject );

	// Inform all other buff stations on this team to attempt to power object (cover for this one).
	if ( GetTFTeam() )
		GetTFTeam()->UpdateBuffStations( this, NULL, false );

	// We shouldn't get any more messages
	g_pNotify->ClearEntity( this );
	BaseClass::DestroyObject();
}