コード例 #1
0
ファイル: sdk_player.cpp プロジェクト: 0xFEEDC0DE64/UltraGame
void CSDKPlayer::State_PreThink_OBSERVER_MODE()
{

	//Tony; if we're in eye, or chase, validate the target - if it's invalid, find a new one, or go back to roaming
	if (  m_iObserverMode == OBS_MODE_IN_EYE || m_iObserverMode == OBS_MODE_CHASE )
	{
		//Tony; if they're not on a spectating team use the cbaseplayer validation method.
		if ( GetTeamNumber() != TEAM_SPECTATOR )
			ValidateCurrentObserverTarget();
		else
		{
			if ( !IsValidObserverTarget( m_hObserverTarget.Get() ) )
			{
				// our target is not valid, try to find new target
				CBaseEntity * target = FindNextObserverTarget( false );
				if ( target )
				{
					// switch to new valid target
					SetObserverTarget( target );	
				}
				else
				{
					// let player roam around
					ForceObserverMode( OBS_MODE_ROAMING );
				}
			}
		}
	}
}
コード例 #2
0
ファイル: mom_player.cpp プロジェクト: Asunaya/game
CBaseEntity *CMomentumPlayer::FindNextObserverTarget(bool bReverse)
{
    int startIndex = GetNextObserverSearchStartPoint(bReverse);

    int	currentIndex = startIndex;
    int iDir = bReverse ? -1 : 1;

    do
    {
        CBaseEntity * nextTarget = UTIL_EntityByIndex(currentIndex);

        if (IsValidObserverTarget(nextTarget))
        {
            return nextTarget;	// found next valid player
        }

        currentIndex += iDir;

        // Loop through the entities
        if (currentIndex > gEntList.NumberOfEntities())
            currentIndex = 1;
        else if (currentIndex < 1)
            currentIndex = gEntList.NumberOfEntities();

    } while (currentIndex != startIndex);

    return nullptr;
}
コード例 #3
0
ファイル: sdk_player.cpp プロジェクト: 0xFEEDC0DE64/UltraGame
void CSDKPlayer::State_Enter_OBSERVER_MODE()
{
	// Always start a spectator session in roaming mode
	m_iObserverLastMode = OBS_MODE_ROAMING;

	if( m_hObserverTarget == NULL )
	{
		// find a new observer target
		CheckObserverSettings();
	}

	// Change our observer target to the nearest teammate
	CTeam *pTeam = GetGlobalTeam( GetTeamNumber() );

	CBasePlayer *pPlayer;
	Vector localOrigin = GetAbsOrigin();
	Vector targetOrigin;
	float flMinDist = FLT_MAX;
	float flDist;

	for ( int i=0;i<pTeam->GetNumPlayers();i++ )
	{
		pPlayer = pTeam->GetPlayer(i);

		if ( !pPlayer )
			continue;

		if ( !IsValidObserverTarget(pPlayer) )
			continue;

		targetOrigin = pPlayer->GetAbsOrigin();

		flDist = ( targetOrigin - localOrigin ).Length();

		if ( flDist < flMinDist )
		{
			m_hObserverTarget.Set( pPlayer );
			flMinDist = flDist;
		}
	}

	StartObserverMode( m_iObserverLastMode );
	PhysObjectSleep();
}