//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTriggerAreaCapture::BreakCapture( bool bNotEnoughPlayers )
{
	if( m_bCapturing )
	{
		// Remap team to get first game team = 1
		switch ( m_nCapturingTeam - FIRST_GAME_TEAM+1 )
		{
		case 1: 
			m_OnBreakTeam1.FireOutput( this, this );
			break;
		case 2: 
			m_OnBreakTeam2.FireOutput( this, this );
			break;
		default:
			Assert(0);
			break;
		}

		m_BreakOutput.FireOutput(this,this);

		m_bCapturing = false;
		m_nCapturingTeam = TEAM_UNASSIGNED;

		UpdateCappingTeam( TEAM_UNASSIGNED );

		if ( bNotEnoughPlayers )
		{
			IncrementCapAttemptNumber();
		}

		SetCapTimeRemaining( 0 );

		if( m_hPoint )
		{
			m_hPoint->CaptureEnd();
		}

		m_OnNumCappersChanged.Set( 0, this, this );

		// tell all touching players to stop racking up capture points
		CTeam *pTeam = GetGlobalTeam( m_nCapturingTeam );
		if ( pTeam )
		{
			for ( int i=0;i<pTeam->GetNumPlayers();i++ )
			{
				CBaseMultiplayerPlayer *pPlayer = ToBaseMultiplayerPlayer( pTeam->GetPlayer(i) );
				if ( pPlayer && IsTouching( pPlayer ) )
				{
					pPlayer->StopScoringEscortPoints();					
				}
			}
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTriggerAreaCapture::BreakCapture( bool bNotEnoughPlayers )
{
	if( m_bCapturing )
	{
		// Remap team to get first game team = 1
		switch ( m_nCapturingTeam - FIRST_GAME_TEAM+1 )
		{
		case 1: 
			m_OnBreakTeam1.FireOutput( this, this );
			break;
		case 2: 
			m_OnBreakTeam2.FireOutput( this, this );
			break;
		default:
			Assert(0);
			break;
		}

		m_BreakOutput.FireOutput(this,this);

		m_bCapturing = false;
		m_nCapturingTeam = TEAM_UNASSIGNED;

		UpdateCappingTeam( TEAM_UNASSIGNED );

		if ( bNotEnoughPlayers )
		{
			IncrementCapAttemptNumber();
		}

		SetCapTimeRemaining( 0 );

		if( m_hPoint )
		{
			m_hPoint->CaptureEnd();

			// The point reverted to it's previous owner.
			IGameEvent *event = gameeventmanager->CreateEvent( "teamplay_capture_broken" );
			if ( event )
			{
				event->SetInt( "cp", m_hPoint->GetPointIndex() );
				event->SetString( "cpname", m_hPoint->GetName() );
				event->SetFloat( "time_remaining", m_fTimeRemaining );
				gameeventmanager->FireEvent( event );
			}
		}

		SetNumCappers( 0 );

		// tell all touching players to stop racking up capture points
		CTeam *pTeam = GetGlobalTeam( m_nCapturingTeam );
		if ( pTeam )
		{
			for ( int i=0;i<pTeam->GetNumPlayers();i++ )
			{
				CBaseMultiplayerPlayer *pPlayer = ToBaseMultiplayerPlayer( pTeam->GetPlayer(i) );
				if ( pPlayer && IsTouching( pPlayer ) )
				{
					pPlayer->StopScoringEscortPoints();					
				}
			}
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTriggerAreaCapture::EndCapture( int team )
{
	IncrementCapAttemptNumber();

	// Remap team to get first game team = 1
	switch ( team - FIRST_GAME_TEAM+1 )
	{
	case 1: 
		m_OnCapTeam1.FireOutput( this, this );
		break;
	case 2: 
		m_OnCapTeam2.FireOutput( this, this );
		break;
	default:
		Assert(0);
		break;
	}

	m_CapOutput.FireOutput(this,this);

	int numcappers = 0;
	int cappingplayers[MAX_AREA_CAPPERS];

	GetNumCappingPlayers( team, numcappers, cappingplayers );

	// Handle this before we assign the new team as the owner of this area
	HandleRespawnTimeAdjustments( m_nOwningTeam, team );
		
	m_nOwningTeam = team;
	m_bCapturing = false;
	m_nCapturingTeam = TEAM_UNASSIGNED;
	SetCapTimeRemaining( 0 );

	//there may have been more than one capper, but only report this one.
	//he hasn't gotten points yet, and his name will go in the cap string if its needed
	//first capper gets name sent and points given by flag.
	//other cappers get points manually above, no name in message

	//send the player in the cap string
	if( m_hPoint )
	{
		OnEndCapture( m_nOwningTeam );

		UpdateOwningTeam();
		m_hPoint->SetOwner( m_nOwningTeam, true, numcappers, cappingplayers );
		m_hPoint->CaptureEnd();
	}

	SetNumCappers( 0 );

	// tell all touching players to stop racking up capture points
	CTeam *pTeam = GetGlobalTeam( m_nCapturingTeam );
	if ( pTeam )
	{
		for ( int i=0;i<pTeam->GetNumPlayers();i++ )
		{
			CBaseMultiplayerPlayer *pPlayer = ToBaseMultiplayerPlayer( pTeam->GetPlayer(i) );
			if ( pPlayer && IsTouching( pPlayer ) )
			{	
				pPlayer->StopScoringEscortPoints();					
			}
		}
	}

	// play any special cap sounds
	if ( TeamplayRoundBasedRules() )
	{
		TeamplayRoundBasedRules()->PlaySpecialCapSounds( m_nOwningTeam );
	}
}