Пример #1
0
/*
================
idSecurityCamera::Think
================
*/
void idSecurityCamera::Think( void ) {
	float pct;
	float travel;
	if( thinkFlags & TH_THINK ) {
		if( g_showEntityInfo.GetBool() ) {
			DrawFov();
		}
		if( health <= 0 ) {
			BecomeInactive( TH_THINK );
			return;
		}
	}
	// run physics
	RunPhysics();
	if( thinkFlags & TH_THINK ) {
		if( CanSeePlayer() ) {
			if( alertMode == SCANNING ) {
				float	sightTime;
				SetAlertMode( ALERT );
				stopSweeping = gameLocal.time;
				if( sweeping ) {
					CancelEvents( &EV_SecurityCam_Pause );
				} else {
					CancelEvents( &EV_SecurityCam_ReverseSweep );
				}
				sweeping = false;
				StopSound( SND_CHANNEL_ANY, false );
				StartSound( "snd_sight", SND_CHANNEL_BODY, 0, false, NULL );
				sightTime = spawnArgs.GetFloat( "sightTime", "5" );
				PostEventSec( &EV_SecurityCam_Alert, sightTime );
			}
		} else {
			if( alertMode == ALERT ) {
				float	sightResume;
				SetAlertMode( LOSINGINTEREST );
				CancelEvents( &EV_SecurityCam_Alert );
				sightResume = spawnArgs.GetFloat( "sightResume", "1.5" );
				PostEventSec( &EV_SecurityCam_ContinueSweep, sightResume );
			}
			if( sweeping ) {
				idAngles a = GetPhysics()->GetAxis().ToAngles();
				pct = ( gameLocal.time - sweepStart ) / ( sweepEnd - sweepStart );
				travel = pct * sweepAngle;
				if( negativeSweep ) {
					a.yaw = angle + travel;
				} else {
					a.yaw = angle - travel;
				}
				SetAngles( a );
			}
		}
	}
	Present();
}
void UBTService_SearchPlayer::TickNode(UBehaviorTreeComponent &OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
	if (!OwnerComp.GetBlackboardComponent())
	{
		GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, "Failed to get Blackboard Component");
		return;
	}

	OwnerComp.GetBlackboardComponent()->SetValueAsObject("Player", (UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)));

	if (OwnerComp.GetBlackboardComponent()->GetValueAsEnum("State") == static_cast<uint8>(EState::ES_Combat))
	{
		APawn* Player = (UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
		ALivingEntity* Enemy = nullptr;
		
		AEnemyController* EnemyController = Cast<AEnemyController>(OwnerComp.GetOwner());
		if (EnemyController)
		{
			Enemy = Cast<ALivingEntity>(EnemyController->GetPawn());
		}

		if (Player && Enemy)
		{
			if (!CanSeePlayer(Enemy, Player))
			{
				OwnerComp.GetBlackboardComponent()->SetValueAsEnum("State", static_cast<uint8>(EState::ES_Walking));
			}
			else
			{
				EnemyController->UpdateMemoryMarker(Player->GetActorLocation());
			}
		}
		else
		{
			GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, "Error whilst casting");
		}
	}
}