PyObject *py_ue_controller_posses(ue_PyUObject * self, PyObject * args) {

	ue_py_check(self);

	PyObject *obj;
	if (!PyArg_ParseTuple(args, "O:posses", &obj)) {
		return NULL;
	}

	if (!self->ue_object->IsA<AController>()) {
		return PyErr_Format(PyExc_Exception, "uobject is not an APawn");
	}

	if (!ue_is_pyuobject(obj)) {
		return PyErr_Format(PyExc_Exception, "argument is not a UObject");
	}

	ue_PyUObject *py_obj = (ue_PyUObject *)obj;

	if (!py_obj->ue_object->IsA<APawn>()) {
		return PyErr_Format(PyExc_Exception, "argument is not a APAwn");
	}

	APawn *pawn = (APawn *)py_obj->ue_object;
	AController *controller = (AController *)self->ue_object;

	controller->Possess(pawn);

	Py_INCREF(Py_None);
	return Py_None;
}
AActor* USCarryObjectComponent::GetActorInView()
{
	APawn* PawnOwner = Cast<APawn>(GetOwner());
	AController* Controller = PawnOwner->Controller;
	if (Controller == nullptr)
	{
		return nullptr;
	}

	FVector CamLoc;
	FRotator CamRot;
	Controller->GetPlayerViewPoint(CamLoc, CamRot);

	const FVector TraceStart = CamLoc;
	const FVector Direction = CamRot.Vector();
	const FVector TraceEnd = TraceStart + (Direction * MaxPickupDistance);

	FCollisionQueryParams TraceParams(TEXT("TraceActor"), true, PawnOwner);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = false;
	TraceParams.bTraceComplex = false;

	FHitResult Hit(ForceInit);
	GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_Visibility, TraceParams);

	/* Check to see if we hit a staticmesh component that has physics simulation enabled */
	UStaticMeshComponent* MeshComp = Cast<UStaticMeshComponent>(Hit.GetComponent());
	if (MeshComp && MeshComp->IsSimulatingPhysics())
	{
		return Hit.GetActor();
	}

	return nullptr;
}
AActor* USCarryObjectComponent::GetActorInView()
{
	APawn* PawnOwner = Cast<APawn>(GetOwner());
	AController* Controller = PawnOwner->Controller;
	if (Controller == nullptr)
	{
		return nullptr;
	}

	FVector CamLoc;
	FRotator CamRot;
	Controller->GetPlayerViewPoint(CamLoc, CamRot);

	const FVector TraceStart = CamLoc;
	const FVector Direction = CamRot.Vector();
	const FVector TraceEnd = TraceStart + (Direction * MaxPickupDistance);

	FCollisionQueryParams TraceParams(TEXT("TraceActor"), true, PawnOwner);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = false;
	TraceParams.bTraceComplex = false;

	FHitResult Hit(ForceInit);
	GetWorld()->LineTraceSingle(Hit, TraceStart, TraceEnd, ECC_Visibility, TraceParams);

	//DrawDebugLine(GetWorld(), TraceStart, TraceEnd, FColor::Red, false, 1.0f);

	return Hit.GetActor();
}
Exemple #4
0
void ANimModGameState::RestartRound_Implementation()
{

	if (ISSERVER && RoundManager != nullptr)
	{
		RoundManager->RestartRound();
		//return;
	}

	ALevelScriptActor* LevelScript = GetWorld()->GetLevelScriptActor();
	if (LevelScript)
	{
		LevelScript->LevelReset();
	}

	if (ISSERVER)
	{
		//Reset the level
		for (FConstControllerIterator Iterator = GetWorld()->GetControllerIterator(); Iterator; ++Iterator)
		{
			AController* Controller = *Iterator;
			ANimModPlayerController* PlayerController = Cast<ANimModPlayerController>(Controller);
			if (PlayerController)
			{
				ANimModGameMode *gameMode = Cast<ANimModGameMode>(GetWorld()->GetAuthGameMode());
				gameMode->RestartPlayer(PlayerController);
				//PlayerController->ClientRestartRound();
				//PlayerController->ServerRestartPlayer();
			}
			else
				Controller->Reset();
		}
	}
}
void FBehaviorTreeDebugger::OnInstanceSelectedInDropdown(UBehaviorTreeComponent* SelectedInstance)
{
	if (SelectedInstance)
	{
		ClearDebuggerState();

		AController* OldController = TreeInstance.IsValid() ? Cast<AController>(TreeInstance->GetOwner()) : NULL;
		APawn* OldPawn = OldController != NULL ? OldController->GetPawn() : NULL;
		USelection* SelectedActors = GEditor->GetSelectedActors();
		if (SelectedActors && OldPawn)
		{
			SelectedActors->Deselect(OldPawn);
		}

		TreeInstance = SelectedInstance;

		if (SelectedActors && GEditor && SelectedInstance && SelectedInstance->GetOwner())
		{
			AController* TestController = Cast<AController>(SelectedInstance->GetOwner());
			APawn* Pawn = TestController != NULL ? TestController->GetPawn() : NULL;
			if (Pawn)
			{
				SelectedActors = GEditor->GetSelectedActors();
				SelectedActors->Select(Pawn);
				AGameplayDebuggingReplicator::OnSelectionChangedDelegate.Broadcast(Pawn);
			}
		}

		Refresh();
	}
}
const AActor* UAIPerceptionComponent::GetBodyActor() const
{
    AController* OwnerController = Cast<AController>(GetOuter());
    if (OwnerController != NULL)
    {
        return OwnerController->GetPawn();
    }

    return Cast<AActor>(GetOuter());
}
void ANimModPlayerState::UpdateTeamColors()
{
	AController* OwnerController = Cast<AController>(GetOwner());
	if (OwnerController != NULL)
	{
		ANimModCharacter* NimModCharacter = Cast<ANimModCharacter>(OwnerController->GetCharacter());
		if (NimModCharacter != NULL)
		{
			NimModCharacter->UpdateTeamColorsAllMIDs();
		}
	}
}
void ANavLinkProxy::NotifySmartLinkReached(UNavLinkCustomComponent* LinkComp, UPathFollowingComponent* PathComp, const FVector& DestPoint)
{
	AActor* PathOwner = PathComp->GetOwner();
	AController* ControllerOwner = Cast<AController>(PathOwner);
	if (ControllerOwner)
	{
		PathOwner = ControllerOwner->GetPawn();
	}

	ReceiveSmartLinkReached(PathOwner, DestPoint);
	OnSmartLinkReached.Broadcast(PathOwner, DestPoint);
}
Exemple #9
0
void ALPlayerState::UpdateTeamColors()
{
	AController* OwnerController = Cast<AController>(GetOwner());
	if (OwnerController != NULL)
	{
		ALabyrinthCharacter* LCharacter = Cast<ALabyrinthCharacter>(OwnerController->GetCharacter());
		if (LCharacter != NULL)
		{
			// Trigger the color update...
			//LCharacter->UpdateTeamColorsAllMIDs();
		}
	}
}
FString FBehaviorTreeDebugger::DescribeInstance(UBehaviorTreeComponent& InstanceToDescribe) const
{
	FString ActorDesc;
	if (InstanceToDescribe.GetOwner())
	{
		AController* TestController = Cast<AController>(InstanceToDescribe.GetOwner());
		ActorDesc = TestController ?
			TestController->GetName() :
			InstanceToDescribe.GetOwner()->GetActorLabel();
	}

	return ActorDesc;
}
void UPawnNoiseEmitterComponent::MakeNoise(AActor* NoiseMaker, float Loudness, const FVector& NoiseLocation)
{
	if (!NoiseMaker || Loudness <= 0.f)
	{
		return;
	}

	// Get the Pawn that owns us, either directly or through a possible Controller owner.
	AActor* Owner = GetOwner();
	APawn* PawnOwner = Cast<APawn>(Owner);
	if (PawnOwner == NULL)
	{
		AController* OwnerController = Cast<AController>(Owner);
		if (IsValid(OwnerController))
		{
			PawnOwner = OwnerController->GetPawn();
		}
	}

	// only emit sounds from pawns with controllers
	if (!IsValid(PawnOwner) || !PawnOwner->Controller)
	{
		return;
	}

	// Was this noise made locally by this pawn?
	if ( NoiseMaker == PawnOwner || ((PawnOwner->GetActorLocation() - NoiseLocation).SizeSquared() <= FMath::Square(PawnOwner->GetSimpleCollisionRadius())) )
	{
		// use loudest noise within NoiseLifetime
		// Do not reset volume to zero after time has elapsed; sensors detecting the sound can choose for themselves how long to care about sounds.
		const bool bNoiseExpired = (GetWorld()->GetTimeSeconds() - LastLocalNoiseTime) > NoiseLifetime;
		if (bNoiseExpired || Loudness >= LastLocalNoiseVolume)
		{
			LastLocalNoiseVolume = Loudness;
			LastLocalNoiseTime = GetWorld()->GetTimeSeconds();
		}
	}
	// noise is not local - use loudest in this period
	else
	{
		const bool bNoiseExpired = (GetWorld()->GetTimeSeconds() - LastRemoteNoiseTime) > NoiseLifetime;
		if (bNoiseExpired || Loudness >= LastRemoteNoiseVolume)
		{
			LastRemoteNoiseVolume = Loudness;
			LastRemoteNoisePosition = NoiseLocation;
			LastRemoteNoiseTime = GetWorld()->GetTimeSeconds();
		}
	}
}
PyObject *py_ue_controller_unposses(ue_PyUObject * self, PyObject * args) {

	ue_py_check(self);

	if (!self->ue_object->IsA<AController>()) {
		return PyErr_Format(PyExc_Exception, "uobject is not an APawn");
	}

	AController *controller = (AController *)self->ue_object;

	controller->UnPossess();

	Py_INCREF(Py_None);
	return Py_None;
}
Exemple #13
0
FExecStatus FCameraCommandHandler::SetCameraRotation(const TArray<FString>& Args)
{
	if (Args.Num() == 4) // ID, Pitch, Roll, Yaw
	{
		int32 CameraId = FCString::Atoi(*Args[0]); // TODO: Add support for multiple cameras
		float Pitch = FCString::Atof(*Args[1]), Yaw = FCString::Atof(*Args[2]), Roll = FCString::Atof(*Args[3]);
		FRotator Rotator = FRotator(Pitch, Yaw, Roll);
		APawn* Pawn = FUE4CVServer::Get().GetPawn();
		AController* Controller = Pawn->GetController();
		Controller->ClientSetRotation(Rotator); // Teleport action
		// SetActorRotation(Rotator);  // This is not working

		return FExecStatus::OK();
	}
	return FExecStatus::InvalidArgument;
}
Exemple #14
0
void UCheatManager::ViewPlayer( const FString& S )
{
	AController* Controller = NULL;
	for( FConstControllerIterator Iterator = GetWorld()->GetControllerIterator(); Iterator; ++Iterator )
	{
		Controller = *Iterator;
		if ( Controller->PlayerState && (FCString::Stricmp(*Controller->PlayerState->PlayerName, *S) == 0 ) )
		{
			break;
		}
	}

	if ( Controller && Controller->GetPawn() != NULL )
	{
		GetOuterAPlayerController()->ClientMessage(FText::Format(LOCTEXT("ViewPlayer", "Viewing from {0}"), FText::FromString(Controller->PlayerState->PlayerName)).ToString(), TEXT("Event"));
		GetOuterAPlayerController()->SetViewTarget(Controller->GetPawn());
	}
}
AActor * AHunterProjectile::FindHitActor()
{
	const FVector &thisLocation = GetActorLocation();

	UFlockingDataCache *cache = UFlockingDataCache::GetCacheChecked(this);
	
	ACharacter *playerCharacter = nullptr;
	for (FConstControllerIterator It = GetWorld()->GetControllerIterator(); It; ++It)
	{
		AController *controller = *It;
		APawn *otherPawn = controller->GetPawn();
		if (otherPawn == nullptr)
		{
			continue;
		}

		if (controller->IsA(APlayerController::StaticClass()))
		{
			playerCharacter = Cast<ACharacter>(controller->GetPawn());
		}
	}
	
	const TArray<FVector> &calfLocations = cache->GetTeamData(TEAM_CALVES)->m_locations;
	const TArray<FVector> &playerLocations = cache->GetLocationsPlayer();

	int32 targetCalf = FindHitActor(calfLocations, cache->GetTeamData(TEAM_CALVES)->m_agentRadius * 0.5f);
	AActor *targetActor = nullptr;
	if (targetCalf == INDEX_NONE)
	{
		int32 targetPlayer = FindHitActor(playerLocations, 0.5f * playerCharacter->GetCapsuleComponent()->GetScaledCapsuleRadius());
		if (targetPlayer != INDEX_NONE)
		{
			targetActor = playerCharacter;
		}
	}
	else
	{
		targetActor = cache->GetOrCreateTeamData(TEAM_CALVES).m_agents[targetCalf];
	}
	
	return targetActor;
}
void AAlessandroMalusaPawn::SpawnDefaultController()
{

	if (AIControllerClass != nullptr && AIControllerClass == AShipAIController::StaticClass())
	{
		FActorSpawnParameters SpawnInfo;
		SpawnInfo.Instigator = Instigator;
		SpawnInfo.bNoCollisionFail = true;
		SpawnInfo.OverrideLevel = GetLevel();

		AController * NewController = GetWorld()->SpawnActor<AShipAIController>(AIControllerClass, GetActorLocation(), GetActorRotation(), SpawnInfo);
	
		if (NewController != nullptr)
		{
			// if successful will result in setting this->Controller 
			// as part of possession mechanics
			NewController->Possess(this);
		}
	}
}
APawn* UPawnActionsComponent::CacheControlledPawn()
{
    if (ControlledPawn == NULL)
    {
        AActor* ActorOwner = GetOwner();
        if (ActorOwner)
        {
            ControlledPawn = Cast<APawn>(ActorOwner);
            if (ControlledPawn == NULL)
            {
                AController* Controller = Cast<AController>(ActorOwner);
                if (Controller != NULL)
                {
                    ControlledPawn = Controller->GetPawn();
                }
            }
        }
    }

    return ControlledPawn;
}
Exemple #18
0
void APawn::SpawnDefaultController()
{
	if ( Controller != NULL || GetNetMode() == NM_Client)
	{
		return;
	}
	if ( AIControllerClass != NULL )
	{
		FActorSpawnParameters SpawnInfo;
		SpawnInfo.Instigator = Instigator;
		SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
		SpawnInfo.OverrideLevel = GetLevel();
		SpawnInfo.ObjectFlags |= RF_Transient;	// We never want to save AI controllers into a map
		AController* NewController = GetWorld()->SpawnActor<AController>(AIControllerClass, GetActorLocation(), GetActorRotation(), SpawnInfo);
		if (NewController != NULL)
		{
			// if successful will result in setting this->Controller 
			// as part of possession mechanics
			NewController->Possess(this);
		}
	}
}
Exemple #19
0
FExecStatus FCameraCommandHandler::SetCameraPose(const TArray<FString>& Args)
{
  if (Args.Num() == 7) // ID, X, Y, Z, Pitch, Roll, Yaw
  {
    int32 CameraId = FCString::Atoi(*Args[0]); // TODO: Add support for multiple cameras
    float X = FCString::Atof(*Args[1]), Y = FCString::Atof(*Args[2]), Z = FCString::Atof(*Args[3]);
    FVector Location = FVector(X, Y, Z);
    float Pitch = FCString::Atof(*Args[4]), Yaw = FCString::Atof(*Args[5]), Roll = FCString::Atof(*Args[6]);
    FRotator Rotator = FRotator(Pitch, Yaw, Roll);

    APawn* Pawn = FUE4CVServer::Get().GetPawn();

    bool Sweep = false;
    bool Success = Pawn->SetActorLocation(Location, Sweep, NULL, ETeleportType::TeleportPhysics);

    AController* Controller = Pawn->GetController();
    Controller->ClientSetRotation(Rotator); // Teleport action
    // SetActorRotation(Rotator);  // This is not working

    return FExecStatus::OK();
  }
  return FExecStatus::InvalidArgument;
}
void AGameModeBase::ResetLevel()
{
	UE_LOG(LogGameMode, Log, TEXT("Reset %s"), *GetName());

	// Reset ALL controllers first
	for (FConstControllerIterator Iterator = GetWorld()->GetControllerIterator(); Iterator; ++Iterator)
	{
		AController* Controller = *Iterator;
		APlayerController* PlayerController = Cast<APlayerController>(Controller);
		if (PlayerController)
		{
			PlayerController->ClientReset();
		}
		Controller->Reset();
	}

	// Reset all actors (except controllers, the GameMode, and any other actors specified by ShouldReset())
	for (FActorIterator It(GetWorld()); It; ++It)
	{
		AActor* A = *It;
		if (A && !A->IsPendingKill() && A != this && !A->IsA<AController>() && ShouldReset(A))
		{
			A->Reset();
		}
	}

	// Reset the GameMode
	Reset();

	// Notify the level script that the level has been reset
	ALevelScriptActor* LevelScript = GetWorld()->GetLevelScriptActor();
	if (LevelScript)
	{
		LevelScript->LevelReset();
	}
}
Exemple #21
0
AActor* UWeaponComponent::PlotHitLine(float LineLength, AController* Instigator, TSubclassOf<UDamageType> DamageType, UGameplaySystemComponent* GameplaySystem)
{
	if (this->GetOwner() == nullptr)
		return nullptr;
	AController* OwnerAsController = dynamic_cast<AController*>(this->GetOwner());
	if (OwnerAsController == nullptr)
		return nullptr;
	if (OwnerAsController->GetPawn() == nullptr)
		return nullptr;

	FVector TraceStart = OwnerAsController->GetPawn()->GetActorLocation();
	FVector TraceEnd = OwnerAsController->GetPawn()->GetActorLocation();
	{
		FRotator Rotation = OwnerAsController->GetControlRotation();
		TraceEnd += Rotation.RotateVector(FVector(LineLength, 0, 0));
	}

	// Setup the trace query  
	FCollisionQueryParams TraceParams = FCollisionQueryParams();
	TraceParams.AddIgnoredActor(OwnerAsController->GetPawn());
	TraceParams.bTraceAsyncScene = true;
	FCollisionResponseParams CollisionParams = FCollisionResponseParams();

	FHitResult HitResult;
	if (this->GetWorld()->LineTraceSingleByChannel(HitResult, TraceStart, TraceEnd, ECC_GameTraceChannel1, TraceParams, CollisionParams))
	{
		if (GameplaySystem == nullptr)
			return nullptr;
		APawn* TargetAsPawn = dynamic_cast<APawn*>(HitResult.Actor.Get());
		if (TargetAsPawn)
		{
			TargetAsPawn->GetController()->TakeDamage(GameplaySystem->GetInfightAttackPoints(), FDamageEvent(DamageType), Instigator, Instigator->GetPawn());
		}
		return HitResult.GetActor();
	}
	else
	{
		return nullptr;
	}
}
void UPawnNoiseEmitterComponent::MakeNoise(AActor* NoiseMaker, float Loudness, const FVector& NoiseLocation)
{
    // @hack! this won't be needed once UPawnNoiseEmitterComponent gets moved to AIModule
    // there's no other way to easily and efficiently prevent infinite recursion when
    // bAIPerceptionSystemCompatibilityMode == true and UAISense_Hearing is not being used (yet)
    static bool bMakeNoiseLockHack = false;
    if (bMakeNoiseLockHack)
    {
        bMakeNoiseLockHack = false;
        return;
    }

    if (!NoiseMaker || Loudness <= 0.f)
    {
        return;
    }

    // Get the Pawn that owns us, either directly or through a possible Controller owner.
    AActor* Owner = GetOwner();
    APawn* PawnOwner = Cast<APawn>(Owner);
    if (PawnOwner == NULL)
    {
        AController* OwnerController = Cast<AController>(Owner);
        if (IsValid(OwnerController))
        {
            PawnOwner = OwnerController->GetPawn();
        }
    }

    // only emit sounds from pawns with controllers
    if (!PawnOwner || PawnOwner->IsPendingKill() || !PawnOwner->Controller)
    {
        return;
    }

    // Was this noise made locally by this pawn?
    if ( NoiseMaker == PawnOwner || ((PawnOwner->GetActorLocation() - NoiseLocation).SizeSquared() <= FMath::Square(PawnOwner->GetSimpleCollisionRadius())) )
    {
        // use loudest noise within NoiseLifetime
        // Do not reset volume to zero after time has elapsed; sensors detecting the sound can choose for themselves how long to care about sounds.
        const bool bNoiseExpired = (GetWorld()->GetTimeSeconds() - LastLocalNoiseTime) > NoiseLifetime;
        if (bNoiseExpired || Loudness >= LastLocalNoiseVolume)
        {
            LastLocalNoiseVolume = Loudness;
            LastLocalNoiseTime = GetWorld()->GetTimeSeconds();
        }
    }
    // noise is not local - use loudest in this period
    else
    {
        const bool bNoiseExpired = (GetWorld()->GetTimeSeconds() - LastRemoteNoiseTime) > NoiseLifetime;
        if (bNoiseExpired || Loudness >= LastRemoteNoiseVolume)
        {
            LastRemoteNoiseVolume = Loudness;
            LastRemoteNoisePosition = NoiseLocation;
            LastRemoteNoiseTime = GetWorld()->GetTimeSeconds();
        }
    }

    if (bAIPerceptionSystemCompatibilityMode)
    {
        bMakeNoiseLockHack = true;
        NoiseMaker->MakeNoise(Loudness, PawnOwner, NoiseLocation);
    }
}