AActor* ASGameMode::ChoosePlayerStart(AController* Player) { TArray<APlayerStart*> PreferredSpawns; TArray<APlayerStart*> FallbackSpawns; for (int32 i = 0; i < PlayerStarts.Num(); i++) { APlayerStart* TestStart = PlayerStarts[i]; if (IsSpawnpointAllowed(TestStart, Player)) { if (IsSpawnpointPreferred(TestStart, Player)) { PreferredSpawns.Add(TestStart); } else { FallbackSpawns.Add(TestStart); } } } APlayerStart* BestStart = nullptr; if (PreferredSpawns.Num() > 0) { BestStart = PreferredSpawns[FMath::RandHelper(PreferredSpawns.Num())]; } else if (FallbackSpawns.Num() > 0) { BestStart = FallbackSpawns[FMath::RandHelper(FallbackSpawns.Num())]; } return BestStart ? BestStart : Super::ChoosePlayerStart(Player); }
AActor* AShooterGameMode::ChoosePlayerStart_Implementation(AController* Player) { TArray<APlayerStart*> PreferredSpawns; TArray<APlayerStart*> FallbackSpawns; APlayerStart* BestStart = NULL; for (TActorIterator<APlayerStart> It(GetWorld()); It; ++It) { APlayerStart* TestSpawn = *It; if (TestSpawn->IsA<APlayerStartPIE>()) { // Always prefer the first "Play from Here" PlayerStart, if we find one while in PIE mode BestStart = TestSpawn; break; } else { if (IsSpawnpointAllowed(TestSpawn, Player)) { if (IsSpawnpointPreferred(TestSpawn, Player)) { PreferredSpawns.Add(TestSpawn); } else { FallbackSpawns.Add(TestSpawn); } } } } if (BestStart == NULL) { if (PreferredSpawns.Num() > 0) { BestStart = PreferredSpawns[FMath::RandHelper(PreferredSpawns.Num())]; } else if (FallbackSpawns.Num() > 0) { BestStart = FallbackSpawns[FMath::RandHelper(FallbackSpawns.Num())]; } } return BestStart ? BestStart : Super::ChoosePlayerStart_Implementation(Player); }
AActor* ALabyrinthGameMode::ChoosePlayerStart(AController* Player) { TArray<APlayerStart*> PreferredSpawns; TArray<APlayerStart*> FallbackSpawns; APlayerStart* BestStart = NULL; for (int32 i = 0; i < PlayerStarts.Num(); i++) { APlayerStart* TestSpawn = PlayerStarts[i]; if (Cast<APlayerStartPIE>(TestSpawn) != NULL) { // Always prefer the first "Play from here PlayerStar // in the PIE mode BestStart = TestSpawn; break; } else if (TestSpawn != NULL) { if (IsSpawnpointAllowed(TestSpawn, Player)) { if (IsSpawnpointPreferred(TestSpawn, Player)) { PreferredSpawns.Add(TestSpawn); } else { FallbackSpawns.Add(TestSpawn); } } } } if (BestStart == NULL) { if (PreferredSpawns.Num() > 0) { BestStart = PreferredSpawns[FMath::RandHelper(PreferredSpawns.Num())]; } else if (FallbackSpawns.Num() > 0) { BestStart = FallbackSpawns[FMath::RandHelper(FallbackSpawns.Num())]; } } return BestStart ? BestStart : Super::ChoosePlayerStart(Player); }
AActor* ASGameMode::ChoosePlayerStart_Implementation(AController* Player) { TArray<APlayerStart*> PreferredSpawns; TArray<APlayerStart*> FallbackSpawns; /* Get all playerstart objects in level */ TArray<AActor*> PlayerStarts; UGameplayStatics::GetAllActorsOfClass(this, APlayerStart::StaticClass(), PlayerStarts); /* Split the player starts into two arrays for preferred and fallback spawns */ for (int32 i = 0; i < PlayerStarts.Num(); i++) { APlayerStart* TestStart = Cast<APlayerStart>(PlayerStarts[i]); if (TestStart && IsSpawnpointAllowed(TestStart, Player)) { if (IsSpawnpointPreferred(TestStart, Player)) { PreferredSpawns.Add(TestStart); } else { FallbackSpawns.Add(TestStart); } } } /* Pick a random spawnpoint from the filtered spawn points */ APlayerStart* BestStart = nullptr; if (PreferredSpawns.Num() > 0) { BestStart = PreferredSpawns[FMath::RandHelper(PreferredSpawns.Num())]; } else if (FallbackSpawns.Num() > 0) { BestStart = FallbackSpawns[FMath::RandHelper(FallbackSpawns.Num())]; } /* If we failed to find any (so BestStart is nullptr) fall back to the base code */ return BestStart ? BestStart : Super::ChoosePlayerStart_Implementation(Player); }