diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index 50c64f0..ac3dc22 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -12,7 +12,7 @@ bOffsetPlayerGamepadIds=False GameInstanceClass=/Script/Engine.GameInstance GameDefaultMap=/Game/MainMenu/MainMenuLevel.MainMenuLevel ServerDefaultMap=/Engine/Maps/Entry.Entry -GlobalDefaultGameMode=/Script/TurnBasedTutorial.MyGameMode +GlobalDefaultGameMode=/Script/Engine.GameMode GlobalDefaultServerGameMode=None [/Script/HardwareTargeting.HardwareTargetingSettings] diff --git a/Content/BP_MyGameMode.uasset b/Content/BP_MyGameMode.uasset new file mode 100644 index 0000000..f27bd1b Binary files /dev/null and b/Content/BP_MyGameMode.uasset differ diff --git a/Content/BattleField/BattleFieldMap.umap b/Content/BattleField/BattleFieldMap.umap index a8e5f1e..9b153aa 100644 Binary files a/Content/BattleField/BattleFieldMap.umap and b/Content/BattleField/BattleFieldMap.umap differ diff --git a/Source/TurnBasedTutorial/MyGameMode.cpp b/Source/TurnBasedTutorial/MyGameMode.cpp index d354852..9dc7afe 100644 --- a/Source/TurnBasedTutorial/MyGameMode.cpp +++ b/Source/TurnBasedTutorial/MyGameMode.cpp @@ -15,27 +15,30 @@ AMyGameMode::AMyGameMode() : Super() AActor* AMyGameMode::ChoosePlayerStart_Implementation(AController* Player) { UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart %d"), GetNumPlayers()); - InitializeSpawnPointsIfNeeded(); + InitializeSpawnPointsIfNeeded(Player); auto ptr = *SpawnPoints.Find(GetNumPlayers()); UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart end %d"), ptr->GetPlayerIndex()); return ptr; } -void AMyGameMode::InitializeSpawnPointsIfNeeded() +void AMyGameMode::InitializeSpawnPointsIfNeeded(AController* Player) { if (SpawnPoints.Num() != 0) { return; } - for (TActorIterator PlayerStartIterator(GetWorld()); PlayerStartIterator; ++PlayerStartIterator) { - UE_LOG(LogTemp, Warning, TEXT("PlayerStart iterator %d"), PlayerStartIterator->GetPlayerIndex()); - SpawnPoints.Add(PlayerStartIterator->GetPlayerIndex(), *PlayerStartIterator); + auto World = GetWorld(); + for (TActorIterator PlayerStartIterator(GetWorld()); PlayerStartIterator; ++PlayerStartIterator) + { + auto PlayerStart = *PlayerStartIterator; + UClass* PawnClass = GetDefaultPawnClassForController(Player); + APawn* PawnToFit = PawnClass ? PawnClass->GetDefaultObject() : nullptr; + FVector ActorLocation = PlayerStart->GetActorLocation(); + const FRotator ActorRotation = PlayerStart->GetActorRotation(); + if (!World->EncroachingBlockingGeometry(PawnToFit, ActorLocation, ActorRotation)) + { + SpawnPoints.Add(PlayerStartIterator->GetPlayerIndex(), *PlayerStartIterator); + UE_LOG(LogTemp, Warning, TEXT("PlayerStart unoccupied iterator %d"), PlayerStartIterator->GetPlayerIndex()); + } } - // TArray MyPlayerStartObjects; - // UGameplayStatics::GetAllActorsOfClass(GetWorld(), AMyPlayerStart::StaticClass(), MyPlayerStartObjects); - // for (const auto& PlayerStart : MyPlayerStartObjects) - // { - // SpawnPoints.Add(dynamic_cast(PlayerStart)->GetPlayerIndex(), - // dynamic_cast(PlayerStart)); - // } } diff --git a/Source/TurnBasedTutorial/MyGameMode.h b/Source/TurnBasedTutorial/MyGameMode.h index 9eafea1..a0bb877 100644 --- a/Source/TurnBasedTutorial/MyGameMode.h +++ b/Source/TurnBasedTutorial/MyGameMode.h @@ -20,10 +20,10 @@ class TURNBASEDTUTORIAL_API AMyGameMode : public AGameMode public: AMyGameMode(); - AActor* ChoosePlayerStart_Implementation(AController* Player); + virtual AActor* ChoosePlayerStart_Implementation(AController* Player) override; private: - void InitializeSpawnPointsIfNeeded(); + void InitializeSpawnPointsIfNeeded(AController *Player); TMap SpawnPoints; }; diff --git a/Source/TurnBasedTutorial/MyPawn.cpp b/Source/TurnBasedTutorial/MyPawn.cpp index 640053e..b250cbe 100644 --- a/Source/TurnBasedTutorial/MyPawn.cpp +++ b/Source/TurnBasedTutorial/MyPawn.cpp @@ -4,32 +4,32 @@ #include "MyPawn.h" -// Sets default values -AMyPawn::AMyPawn() -{ - // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. - PrimaryActorTick.bCanEverTick = true; - -} - -// Called when the game starts or when spawned -void AMyPawn::BeginPlay() -{ - Super::BeginPlay(); - -} - -// Called every frame -void AMyPawn::Tick(float DeltaTime) -{ - Super::Tick(DeltaTime); - -} - -// Called to bind functionality to input -void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) -{ - Super::SetupPlayerInputComponent(PlayerInputComponent); - -} - +// // Sets default values +// AMyPawn::AMyPawn() +// { +// // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. +// PrimaryActorTick.bCanEverTick = true; +// +// } +// +// // Called when the game starts or when spawned +// void AMyPawn::BeginPlay() +// { +// Super::BeginPlay(); +// +// } +// +// // Called every frame +// void AMyPawn::Tick(float DeltaTime) +// { +// Super::Tick(DeltaTime); +// +// } +// +// // Called to bind functionality to input +// void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) +// { +// Super::SetupPlayerInputComponent(PlayerInputComponent); +// +// } +// diff --git a/Source/TurnBasedTutorial/MyPawn.h b/Source/TurnBasedTutorial/MyPawn.h index 40953df..2049c14 100644 --- a/Source/TurnBasedTutorial/MyPawn.h +++ b/Source/TurnBasedTutorial/MyPawn.h @@ -11,21 +11,21 @@ class TURNBASEDTUTORIAL_API AMyPawn : public APawn { GENERATED_BODY() -public: - // Sets default values for this pawn's properties - AMyPawn(); - -protected: - // Called when the game starts or when spawned - virtual void BeginPlay() override; - -public: - // Called every frame - virtual void Tick(float DeltaTime) override; - - // Called to bind functionality to input - virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; - - +// public: +// // Sets default values for this pawn's properties +// AMyPawn(); +// +// protected: +// // Called when the game starts or when spawned +// virtual void BeginPlay() override; +// +// public: +// // Called every frame +// virtual void Tick(float DeltaTime) override; +// +// // Called to bind functionality to input +// virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; +// +// };