|
|
@ -5,152 +5,159 @@
|
|
|
|
#include "MyPawn.h"
|
|
|
|
#include "MyPawn.h"
|
|
|
|
#include "MyGameState.h"
|
|
|
|
#include "MyGameState.h"
|
|
|
|
|
|
|
|
|
|
|
|
AMyGameMode::AMyGameMode() : Super()
|
|
|
|
AMyGameMode::AMyGameMode()
|
|
|
|
{
|
|
|
|
: Super() {
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("GameMode Constructor"));
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("GameMode Constructor"));
|
|
|
|
GameStateClass = AMyGameState::StaticClass();
|
|
|
|
GameStateClass = AMyGameState::StaticClass();
|
|
|
|
PlayerControllerClass = AMyPlayerController::StaticClass();
|
|
|
|
PlayerControllerClass = AMyPlayerController::StaticClass();
|
|
|
|
DefaultPawnClass = AMyPawn::StaticClass();
|
|
|
|
DefaultPawnClass = AMyPawn::StaticClass();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AMyGameMode::BeginPlay()
|
|
|
|
void AMyGameMode::BeginPlay() {
|
|
|
|
{
|
|
|
|
|
|
|
|
Super::BeginPlay();
|
|
|
|
Super::BeginPlay();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AMyGameMode::InitializeBattleField() const
|
|
|
|
void AMyGameMode::InitializeBattleField() const {
|
|
|
|
{
|
|
|
|
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("InitializeBattleField"));
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("InitializeBattleField"));
|
|
|
|
FVector Location(2000.0f, -1000.0f, 0.0f);
|
|
|
|
FVector Location(2000.0f, -1000.0f, 0.0f);
|
|
|
|
FRotator Rotation(0.0f, 180.0f, 0.0f);
|
|
|
|
FRotator Rotation(0.0f, 180.0f, 0.0f);
|
|
|
|
|
|
|
|
|
|
|
|
uint8 TrooperCount = 0;
|
|
|
|
uint8 TrooperCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; ++i)
|
|
|
|
TArray<const TCHAR *> bpPaths{
|
|
|
|
{
|
|
|
|
TEXT(
|
|
|
|
|
|
|
|
"Blueprint'/Game/Troopers/TrooperSkeletonMelee.TrooperSkeletonMelee_C'"
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
TEXT("Blueprint'/Game/Troopers/TrooperWizard.TrooperWizard_C'")
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
TArray<UClass *> LoadedBpAssets;
|
|
|
|
|
|
|
|
for (int i = 0; i < bpPaths.Num(); ++i) {
|
|
|
|
|
|
|
|
TSoftClassPtr<ATrooper> ActorBpClass = TSoftClassPtr<ATrooper>(
|
|
|
|
|
|
|
|
FSoftObjectPath(bpPaths[i])
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
LoadedBpAssets.Push(ActorBpClass.LoadSynchronous());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
FTransform SpawnLocationAndRotation(Rotation);
|
|
|
|
FTransform SpawnLocationAndRotation(Rotation);
|
|
|
|
SpawnLocationAndRotation.SetLocation(Location);
|
|
|
|
SpawnLocationAndRotation.SetLocation(Location);
|
|
|
|
AActor* Spawned = GetWorld()->SpawnActorDeferred<ATrooper>(ATrooper::StaticClass(), SpawnLocationAndRotation);
|
|
|
|
AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>(
|
|
|
|
dynamic_cast<ATrooper*>(Spawned)->Initialize(0, Location, TrooperCount++);
|
|
|
|
LoadedBpAssets[i % 2], SpawnLocationAndRotation);
|
|
|
|
|
|
|
|
dynamic_cast<ATrooper *>(Spawned)->Initialize(
|
|
|
|
|
|
|
|
0, Location, TrooperCount++);
|
|
|
|
Spawned->FinishSpawning(SpawnLocationAndRotation);
|
|
|
|
Spawned->FinishSpawning(SpawnLocationAndRotation);
|
|
|
|
|
|
|
|
Spawned->SetActorLocation(Location);
|
|
|
|
Location += {0.f, 500.f, 0.0f};
|
|
|
|
Location += {0.f, 500.f, 0.0f};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Location = {-2000.0f, -1000.0f, 0.0f};
|
|
|
|
Location = {-2000.0f, -1000.0f, 0.0f};
|
|
|
|
Rotation = {0.0f, 0.0f, 0.0f};
|
|
|
|
Rotation = {0.0f, 0.0f, 0.0f};
|
|
|
|
for (int i = 0; i < 5; ++i)
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
{
|
|
|
|
|
|
|
|
FTransform SpawnLocationAndRotation(Rotation);
|
|
|
|
FTransform SpawnLocationAndRotation(Rotation);
|
|
|
|
SpawnLocationAndRotation.SetLocation(Location);
|
|
|
|
SpawnLocationAndRotation.SetLocation(Location);
|
|
|
|
AActor* Spawned = GetWorld()->SpawnActorDeferred<ATrooper>(ATrooper::StaticClass(), SpawnLocationAndRotation);
|
|
|
|
AActor *Spawned = GetWorld()->SpawnActorDeferred<ATrooper>(
|
|
|
|
dynamic_cast<ATrooper*>(Spawned)->Initialize(1, Location, TrooperCount++);
|
|
|
|
LoadedBpAssets[i % 2], SpawnLocationAndRotation);
|
|
|
|
|
|
|
|
dynamic_cast<ATrooper *>(Spawned)->Initialize(
|
|
|
|
|
|
|
|
1, Location, TrooperCount++);
|
|
|
|
Spawned->FinishSpawning(SpawnLocationAndRotation);
|
|
|
|
Spawned->FinishSpawning(SpawnLocationAndRotation);
|
|
|
|
|
|
|
|
Spawned->SetActorLocation(Location);
|
|
|
|
Location += {0.f, 500.f, 0.0f};
|
|
|
|
Location += {0.f, 500.f, 0.0f};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AActor *AMyGameMode::ChoosePlayerStart_Implementation(AController *Player) {
|
|
|
|
AActor* AMyGameMode::ChoosePlayerStart_Implementation(AController* Player)
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart %d"),
|
|
|
|
{
|
|
|
|
GetNumPlayers());
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart %d"), GetNumPlayers());
|
|
|
|
|
|
|
|
InitializeSpawnPointsIfNeeded(Player);
|
|
|
|
InitializeSpawnPointsIfNeeded(Player);
|
|
|
|
const auto CurrentPlayerStart = *SpawnPoints.Find(GetNumPlayers());
|
|
|
|
const auto CurrentPlayerStart = *SpawnPoints.Find(GetNumPlayers());
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart end %d"), CurrentPlayerStart->GetPlayerIndex());
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart end %d"),
|
|
|
|
|
|
|
|
CurrentPlayerStart->GetPlayerIndex());
|
|
|
|
return CurrentPlayerStart;
|
|
|
|
return CurrentPlayerStart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AMyGameMode::InitializeSpawnPointsIfNeeded(AController* Player)
|
|
|
|
void AMyGameMode::InitializeSpawnPointsIfNeeded(AController *Player) {
|
|
|
|
{
|
|
|
|
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("InitializeSpawnPointsIfNeeded"));
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("InitializeSpawnPointsIfNeeded"));
|
|
|
|
if (SpawnPoints.Num() != 0)
|
|
|
|
if (SpawnPoints.Num() != 0) {
|
|
|
|
{
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("InitializeSpawnPointsIfNeeded Exit %d"),
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("InitializeSpawnPointsIfNeeded Exit %d"), SpawnPoints.Num());
|
|
|
|
SpawnPoints.Num());
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Rebuilding spawnpoints"));
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Rebuilding spawnpoints"));
|
|
|
|
const auto World = GetWorld();
|
|
|
|
const auto World = GetWorld();
|
|
|
|
for (TActorIterator<AMyPlayerStart> PlayerStartIterator(GetWorld()); PlayerStartIterator; ++PlayerStartIterator)
|
|
|
|
for (TActorIterator<AMyPlayerStart> PlayerStartIterator(GetWorld());
|
|
|
|
{
|
|
|
|
PlayerStartIterator; ++PlayerStartIterator) {
|
|
|
|
const auto PlayerStart = *PlayerStartIterator;
|
|
|
|
const auto PlayerStart = *PlayerStartIterator;
|
|
|
|
const UClass *PawnClass = GetDefaultPawnClassForController(Player);
|
|
|
|
const UClass *PawnClass = GetDefaultPawnClassForController(Player);
|
|
|
|
const APawn* PawnToFit = PawnClass ? PawnClass->GetDefaultObject<APawn>() : nullptr;
|
|
|
|
const APawn *PawnToFit = PawnClass
|
|
|
|
|
|
|
|
? PawnClass->GetDefaultObject<APawn>()
|
|
|
|
|
|
|
|
: nullptr;
|
|
|
|
const FVector ActorLocation = PlayerStart->GetActorLocation();
|
|
|
|
const FVector ActorLocation = PlayerStart->GetActorLocation();
|
|
|
|
const FRotator ActorRotation = PlayerStart->GetActorRotation();
|
|
|
|
const FRotator ActorRotation = PlayerStart->GetActorRotation();
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("PlayerStart iterator %d"), PlayerStartIterator->GetPlayerIndex());
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("PlayerStart iterator %d"),
|
|
|
|
if (!World->EncroachingBlockingGeometry(PawnToFit, ActorLocation, ActorRotation))
|
|
|
|
PlayerStartIterator->GetPlayerIndex());
|
|
|
|
{
|
|
|
|
if (!World->EncroachingBlockingGeometry(PawnToFit, ActorLocation,
|
|
|
|
SpawnPoints.Add(PlayerStartIterator->GetPlayerIndex(), *PlayerStartIterator);
|
|
|
|
ActorRotation)) {
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("PlayerStart unoccupied iterator %d"), PlayerStartIterator->GetPlayerIndex());
|
|
|
|
SpawnPoints.Add(PlayerStartIterator->GetPlayerIndex(),
|
|
|
|
|
|
|
|
*PlayerStartIterator);
|
|
|
|
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("PlayerStart unoccupied iterator %d"),
|
|
|
|
|
|
|
|
PlayerStartIterator->GetPlayerIndex());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AMyGameMode::PostLogin(APlayerController *NewPlayer) {
|
|
|
|
void AMyGameMode::PostLogin(APlayerController* NewPlayer)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Super::PostLogin(NewPlayer);
|
|
|
|
Super::PostLogin(NewPlayer);
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("PostLogin"));
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("PostLogin"));
|
|
|
|
const auto World = GetWorld();
|
|
|
|
// const auto World = GetWorld();
|
|
|
|
const auto CurrentNumberOfPlayers = GetNumPlayers();
|
|
|
|
const auto CurrentNumberOfPlayers = GetNumPlayers();
|
|
|
|
|
|
|
|
|
|
|
|
// 0-indexation
|
|
|
|
// 0-indexation
|
|
|
|
dynamic_cast<AMyPlayerController*>(NewPlayer)->SetPlayerIndex(CurrentNumberOfPlayers - 1);
|
|
|
|
dynamic_cast<AMyPlayerController *>(NewPlayer)->SetPlayerIndex(
|
|
|
|
|
|
|
|
CurrentNumberOfPlayers - 1);
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("%d"), CurrentNumberOfPlayers);
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("%d"), CurrentNumberOfPlayers);
|
|
|
|
if (CurrentNumberOfPlayers == 2)
|
|
|
|
if (CurrentNumberOfPlayers == 2) {
|
|
|
|
{
|
|
|
|
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Game Start"));
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Game Start"));
|
|
|
|
// start the game
|
|
|
|
// start the game
|
|
|
|
StartGame();
|
|
|
|
StartGame();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// delay the game
|
|
|
|
// delay the game
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Game Delay"));
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Game Delay"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AMyGameMode::StartGame()
|
|
|
|
void AMyGameMode::StartGame() {
|
|
|
|
{
|
|
|
|
|
|
|
|
InitializeBattleField();
|
|
|
|
InitializeBattleField();
|
|
|
|
PlayerInTurn()->StartTurn();
|
|
|
|
PlayerInTurn()->StartTurn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AMyPlayerController* AMyGameMode::PlayerInTurn() const
|
|
|
|
AMyPlayerController *AMyGameMode::PlayerInTurn() const {
|
|
|
|
{
|
|
|
|
|
|
|
|
return GetMyPlayerController(CurrentPlayerTurn);
|
|
|
|
return GetMyPlayerController(CurrentPlayerTurn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AMyPlayerController* AMyGameMode::PlayerNotInTurn() const
|
|
|
|
AMyPlayerController *AMyGameMode::PlayerNotInTurn() const {
|
|
|
|
{
|
|
|
|
uint8 PlayerControllerIndexNotInTurn;
|
|
|
|
uint8 PlayerControllerIndexNotInTurn = 0;
|
|
|
|
if (CurrentPlayerTurn == 0) {
|
|
|
|
if (CurrentPlayerTurn == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
PlayerControllerIndexNotInTurn = 1;
|
|
|
|
PlayerControllerIndexNotInTurn = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
PlayerControllerIndexNotInTurn = 0;
|
|
|
|
PlayerControllerIndexNotInTurn = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return GetMyPlayerController(PlayerControllerIndexNotInTurn);
|
|
|
|
return GetMyPlayerController(PlayerControllerIndexNotInTurn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AMyGameMode::CycleTurns()
|
|
|
|
void AMyGameMode::CycleTurns() {
|
|
|
|
{
|
|
|
|
|
|
|
|
PlayerInTurn()->EndTurn();
|
|
|
|
PlayerInTurn()->EndTurn();
|
|
|
|
if (CurrentPlayerTurn == 0)
|
|
|
|
if (CurrentPlayerTurn == 0) {
|
|
|
|
{
|
|
|
|
|
|
|
|
CurrentPlayerTurn = 1;
|
|
|
|
CurrentPlayerTurn = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CurrentPlayerTurn = 0;
|
|
|
|
CurrentPlayerTurn = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PlayerInTurn()->StartTurn();
|
|
|
|
PlayerInTurn()->StartTurn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AMyPlayerController* AMyGameMode::GetMyPlayerController(uint8 const PlayerIndex) const
|
|
|
|
AMyPlayerController *AMyGameMode::GetMyPlayerController(
|
|
|
|
{
|
|
|
|
uint8 const PlayerIndex) const {
|
|
|
|
return dynamic_cast<AMyPlayerController*>(UGameplayStatics::GetPlayerController(GetWorld(), PlayerIndex));
|
|
|
|
return dynamic_cast<AMyPlayerController *>(
|
|
|
|
|
|
|
|
UGameplayStatics::GetPlayerController(GetWorld(), PlayerIndex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|