Exemplo n.º 1
0
void CHLTVDirector::StartBestFixedCameraShot( bool bForce )
{
	float	flCameraRanking[MAX_NUM_CAMERAS];

	if ( m_nNumFixedCameras <= 0 )
		return;

	memset( flCameraRanking, 0, sizeof(flCameraRanking) );

	int firstIndex = FindFirstEvent( m_nBroadcastTick );

	int index = firstIndex;

	float flBestRank = -1.0f;
	int iBestCamera = -1;
	int iBestTarget = -1;

	// sum all ranking values for the cameras

	while( index != m_EventHistory.InvalidIndex() )
	{
		CGameEvent &dc = m_EventHistory[index];

		if ( dc.m_Tick >= m_nNextShotTick )
			break; 

		// search for camera ranking events
		if ( Q_strcmp( dc.m_Event->GetName(), "hltv_rank_camera") == 0 )
		{
			int index = dc.m_Event->GetInt("index"); 
			flCameraRanking[index] += dc.m_Event->GetFloat("rank" );

			// find best camera
			if ( flCameraRanking[index] > flBestRank )
			{
				iBestCamera = index;
				flBestRank = flCameraRanking[index];
				iBestTarget = dc.m_Event->GetInt("target"); 
			}
		}

		index = m_EventHistory.NextInorder( index );
	}

	if ( !bForce && flBestRank == 0 )
	{
		// if we are not forcing a fixed camera shot, switch to player chase came
		// if no camera shows any players
		StartBestPlayerCameraShot();
	}
	else if ( iBestCamera != -1 )
	{
		StartFixedCameraShot( iBestCamera, iBestTarget );
	}
}
Exemplo n.º 2
0
void CTFHLTVDirector::CreateShotFromEvent( CHLTVGameEvent *event )
{
    // show event at least for 2 more seconds after it occured
    const char *name = event->m_Event->GetName();

    int thera = RandomFloat()>0.5?20:-20;

    if ( !Q_strcmp( "teamplay_point_startcapture", name ) ||
            !Q_strcmp( "teamplay_point_captured", name ) ||
            !Q_strcmp( "teamplay_capture_blocked", name ) )
    {
        CBaseEntity *pCapturePoint = GetCapturePointByIndex( event->m_Event->GetInt( "cp" ) );

        int iCameraIndex = -1;
        float flClosest = 99999.9f;

        if ( pCapturePoint )
        {
            // Does it have an associated viewpoint?
            for ( int i = 0; i<m_nNumFixedCameras; i++ )
            {
                CBaseEntity *pCamera = m_pFixedCameras[ i ];

                if ( pCamera )
                {
                    byte pvs[MAX_MAP_CLUSTERS/8];
                    int clusterIndex = engine->GetClusterForOrigin( pCamera->GetAbsOrigin() );
                    engine->GetPVSForCluster( clusterIndex, sizeof(pvs), pvs );
                    bool bCameraInPVS = engine->CheckOriginInPVS( pCapturePoint->GetAbsOrigin(), pvs, sizeof( pvs ) );

                    if ( bCameraInPVS == true )
                    {
                        float flDistance = (pCapturePoint->GetAbsOrigin() - pCamera->GetAbsOrigin()).Length();
                        if ( flDistance <= flClosest )
                        {
                            iCameraIndex = i;
                            flClosest = flDistance;
                        }
                    }
                }
            }
        }

        CBasePlayer *pPlayer = NULL;

        if ( !Q_strcmp( "teamplay_point_captured", name ) )
        {
            const char *pszCappers = event->m_Event->GetString("cappers");
            int nLength = Q_strlen(pszCappers);

            if ( nLength > 0 )
            {
                int iRandomCapper = pszCappers[ RandomInt(0,nLength-1) ];
                pPlayer = UTIL_PlayerByIndex( iRandomCapper );
            }
        }
        else if ( !Q_strcmp( "teamplay_capture_blocked", name ) )
        {
            int iBlocker = event->m_Event->GetInt("blocker");
            pPlayer = UTIL_PlayerByIndex( iBlocker );
        }

        if ( pPlayer )
        {
            if ( iCameraIndex >= 0 && RandomFloat() > 0.66f )
            {
                StartFixedCameraShot( iCameraIndex, pPlayer->entindex() );
            }
            else if ( pCapturePoint )
            {
                StartChaseCameraShot( pPlayer->entindex(), pCapturePoint->entindex(), 96, 20, thera, false );
            }
            else
            {
                StartChaseCameraShot( pPlayer->entindex(), 0, 96, 20, 0, false );
            }
        }
        else if ( iCameraIndex >= 0 && pCapturePoint )
        {
            // no player known for this event
            StartFixedCameraShot( iCameraIndex, pCapturePoint->entindex() );
        }

        // shot 2 seconds after event
        m_nNextShotTick = min( m_nNextShotTick, (event->m_Tick+TIME_TO_TICKS(1.0)) );
    }
    else if ( !Q_strcmp( "object_destroyed", name ) )
    {
        CBasePlayer *attacker = UTIL_PlayerByUserId( event->m_Event->GetInt("attacker") );
        if ( attacker )
        {
            int iObjectIndex = event->m_Event->GetInt("index");
            StartChaseCameraShot( attacker->entindex(), iObjectIndex, 96, 20, thera, false );
        }
    }
    else if ( !Q_strcmp( "ctf_flag_captured", name ) )
    {
        CBasePlayer *capper = UTIL_PlayerByUserId( event->m_Event->GetInt("capper") );
        if ( capper )
        {
            StartChaseCameraShot( capper->entindex(), 0, 96, 20, 0, false );
        }
    }
    else if ( !Q_strcmp( "teamplay_flag_event", name ) )
    {
        StartChaseCameraShot( event->m_Event->GetInt("player"), 0, 96, 20, 0, false );
    }
    else
    {

        // let baseclass create a shot
        BaseClass::CreateShotFromEvent( event );
    }
}