コード例 #1
0
bool CAI_OperatorBehavior::CanSeePositionEntity()
{
    CAI_BaseNPC *pOuter = GetOuter();

    Assert( m_hPositionEnt.Get() != NULL );

    // early out here.
    if( !pOuter->QuerySeeEntity(m_hPositionEnt) )
    {
        m_WatchSeeEntity.Stop();
        return false;
    }

    bool bSpotted = (pOuter->EyePosition().DistToSqr(m_hPositionEnt->GetAbsOrigin()) <= POSITION_ENT_ALWAYS_SEE_DIST);
    if ( !bSpotted )
    {
        bSpotted = ( pOuter->FInViewCone(m_hPositionEnt) && pOuter->FVisible(m_hPositionEnt) );
    }

    if (bSpotted )
    {
        // If we haven't seen it up until now, start a timer. If we have seen it, wait for the
        // timer to finish. This prevents edge cases where turning on the flashlight makes
        // NPC spot the position entity a frame before she spots an enemy.
        if ( !m_WatchSeeEntity.IsRunning() )
        {
            m_WatchSeeEntity.Start( 0.3,0.31 );
            return false;
        }

        if ( !m_WatchSeeEntity.Expired() )
            return false;

        return true;
    }

    m_WatchSeeEntity.Stop();
    return false;
}
コード例 #2
0
bool CAI_ScriptConditions::EvalActorSeeTarget( const EvalArgs_t &args )
{
	if( m_fActorSeeTarget == TRS_NONE )
	{
		// Don't care, so don't do any work.
		return true;
	}

	if ( args.pTarget )
	{
		if ( !args.pActor )
			return true;

		CAI_BaseNPC *pNPCActor = args.pActor->MyNPCPointer();

#ifdef HL2_EPISODIC
		// This is the code we want to have written for HL2, but HL2 shipped without the QuerySeeEntity() call. This #ifdef really wants to be
		// something like #ifndef HL2_RETAIL, since this change does want to be in any products that are built henceforth. (sjb)
		bool fSee = pNPCActor->FInViewCone( args.pTarget ) && pNPCActor->FVisible( args.pTarget ) && pNPCActor->QuerySeeEntity( args.pTarget );
#else
		bool fSee = pNPCActor->FInViewCone( args.pTarget ) && pNPCActor->FVisible( args.pTarget );
#endif//HL2_EPISODIC

		if( fSee )
		{
			if( m_fActorSeeTarget == TRS_TRUE )
			{
				return true;
			}

			return false;
		}
		else
		{
			if( m_fActorSeeTarget == TRS_FALSE )
			{
				return true;
			}

			return false;
		}
	}

	return true;
}