Disable any non-basic logic.

pull/5/head
eyakm1 2 years ago
parent 6f5376e01d
commit 29c31b81af

@ -4,41 +4,38 @@
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
AMyGameMode::AMyGameMode() : Super() { AMyGameMode::AMyGameMode() : Super()
UE_LOG(LogTemp, Warning, TEXT("GameMode Constructor")); {
GameStateClass = AMyGameState::StaticClass(); UE_LOG(LogTemp, Warning, TEXT("GameMode Constructor"));
PlayerControllerClass = AMyPlayerController::StaticClass(); GameStateClass = AMyGameState::StaticClass();
DefaultPawnClass = AMyPawn::StaticClass(); PlayerControllerClass = AMyPlayerController::StaticClass();
DefaultPawnClass = AMyPawn::StaticClass();
} }
AActor *AMyGameMode::ChoosePlayerStart_Implementation(AController *Player) { AActor* AMyGameMode::ChoosePlayerStart_Implementation(AController* Player)
UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart %d"), GetNumPlayers()); {
InitializeSpawnPointsIfNeeded(); UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart %d"), GetNumPlayers());
auto ptr = *SpawnPoints.Find(GetNumPlayers()); InitializeSpawnPointsIfNeeded();
UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart end %d"), ptr->GetPlayerIndex()); auto ptr = *SpawnPoints.Find(GetNumPlayers());
return ptr; UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart end %d"), ptr->GetPlayerIndex());
return ptr;
} }
void AMyGameMode::InitializeSpawnPointsIfNeeded() { void AMyGameMode::InitializeSpawnPointsIfNeeded()
if (SpawnPoints.Num() != 0) { {
return; if (SpawnPoints.Num() != 0)
} {
for (TActorIterator <AMyPlayerStart> PlayerStartIterator(GetWorld()); PlayerStartIterator; ++PlayerStartIterator) { return;
UE_LOG(LogTemp, Warning, TEXT("PlayerStart iterator %d"), PlayerStartIterator->GetPlayerIndex()); }
SpawnPoints.Add(PlayerStartIterator->GetPlayerIndex(), *PlayerStartIterator); for (TActorIterator <AMyPlayerStart> PlayerStartIterator(GetWorld()); PlayerStartIterator; ++PlayerStartIterator) {
} UE_LOG(LogTemp, Warning, TEXT("PlayerStart iterator %d"), PlayerStartIterator->GetPlayerIndex());
} SpawnPoints.Add(PlayerStartIterator->GetPlayerIndex(), *PlayerStartIterator);
}
void AMyGameMode::BeginPlay() { // TArray<AActor*> MyPlayerStartObjects;
Super::BeginPlay(); // UGameplayStatics::GetAllActorsOfClass(GetWorld(), AMyPlayerStart::StaticClass(), MyPlayerStartObjects);
} // for (const auto& PlayerStart : MyPlayerStartObjects)
// {
void AMyGameMode::StartGame() { // SpawnPoints.Add(dynamic_cast<AMyPlayerStart*>(PlayerStart)->GetPlayerIndex(),
GetPlayerController()->StartTurn(); // dynamic_cast<AMyPlayerStart*>(PlayerStart));
} // }
AMyPlayerController *AMyGameMode::GetPlayerController() {
return dynamic_cast<AMyPlayerController *>(
UGameplayStatics::GetPlayerController(GetWorld(), 0)
);
} }

@ -12,7 +12,6 @@
#include "MyGameMode.generated.h" #include "MyGameMode.generated.h"
UCLASS() UCLASS()
class TURNBASEDTUTORIAL_API AMyGameMode : public AGameMode class TURNBASEDTUTORIAL_API AMyGameMode : public AGameMode
{ {
@ -21,15 +20,10 @@ class TURNBASEDTUTORIAL_API AMyGameMode : public AGameMode
public: public:
AMyGameMode(); AMyGameMode();
void BeginPlay() override; AActor* ChoosePlayerStart_Implementation(AController* Player);
AActor *ChoosePlayerStart_Implementation(AController * Player);
private: private:
void StartGame(); void InitializeSpawnPointsIfNeeded();
void InitializeSpawnPointsIfNeeded();
AMyPlayerController *GetPlayerController();
TMap<uint8, AMyPlayerStart*> SpawnPoints; TMap<uint8, AMyPlayerStart*> SpawnPoints;
}; };

@ -2,62 +2,62 @@
#include "MyPlayerController.h" #include "MyPlayerController.h"
AMyPlayerController::AMyPlayerController() : Super(), IsMyTurn(false), SelectedTrooper(nullptr) { // AMyPlayerController::AMyPlayerController() : Super(), IsMyTurn(false), SelectedTrooper(nullptr) {
UE_LOG(LogTemp, Warning, TEXT("Player controller created")); // UE_LOG(LogTemp, Warning, TEXT("Player controller created"));
} // }
//
void AMyPlayerController::SetupInputComponent() { // void AMyPlayerController::SetupInputComponent() {
Super::SetupInputComponent(); // Super::SetupInputComponent();
InputComponent->BindAction("MyAction", IE_Pressed, this, // InputComponent->BindAction("MyAction", IE_Pressed, this,
&AMyPlayerController::OnLeftMouseClick); // &AMyPlayerController::OnLeftMouseClick);
} // }
//
void AMyPlayerController::StartTurn() { // void AMyPlayerController::StartTurn() {
IsMyTurn = true; // IsMyTurn = true;
UE_LOG(LogTemp, Warning, TEXT("Your turn")); // UE_LOG(LogTemp, Warning, TEXT("Your turn"));
} // }
//
void AMyPlayerController::EndTurn() { // void AMyPlayerController::EndTurn() {
IsMyTurn = false; // IsMyTurn = false;
UE_LOG(LogTemp, Warning, TEXT("Not your turn")); // UE_LOG(LogTemp, Warning, TEXT("Not your turn"));
} // }
//
void AMyPlayerController::SetTrooperIsMoving(bool isMoving) { // void AMyPlayerController::SetTrooperIsMoving(bool isMoving) {
IsThereTrooperMoving = isMoving; // IsThereTrooperMoving = isMoving;
} // }
//
void AMyPlayerController::OnLeftMouseClick() { // void AMyPlayerController::OnLeftMouseClick() {
if (IsThereTrooperMoving) { // if (IsThereTrooperMoving) {
return; // return;
} // }
UE_LOG(LogTemp, Warning, TEXT("Mouse clicked")); // UE_LOG(LogTemp, Warning, TEXT("Mouse clicked"));
FHitResult HitResult; // FHitResult HitResult;
bool IsHitResult = GetHitResultUnderCursorByChannel(TraceTypeQuery1, false, HitResult); // bool IsHitResult = GetHitResultUnderCursorByChannel(TraceTypeQuery1, false, HitResult);
if (IsHitResult) { // if (IsHitResult) {
AActor *actor = HitResult.Actor.Get(); // AActor *actor = HitResult.Actor.Get();
if (actor->ActorHasTag(FName("Trooper"))) { // if (actor->ActorHasTag(FName("Trooper"))) {
ATrooper* trooper = dynamic_cast<ATrooper*>(actor); // ATrooper* trooper = dynamic_cast<ATrooper*>(actor);
if (trooper != nullptr && trooper != SelectedTrooper) { // if (trooper != nullptr && trooper != SelectedTrooper) {
if (trooper->IsOnPlayersSide()) { // if (trooper->IsOnPlayersSide()) {
UE_LOG(LogTemp, Warning, TEXT("Hitted trooper id: %d, on our side"), // UE_LOG(LogTemp, Warning, TEXT("Hitted trooper id: %d, on our side"),
trooper->GetId()); // trooper->GetId());
SelectedTrooper = trooper; // SelectedTrooper = trooper;
} // }
else { // else {
UE_LOG(LogTemp, Warning, TEXT("Hitted trooper id: %d, enemy"), // UE_LOG(LogTemp, Warning, TEXT("Hitted trooper id: %d, enemy"),
trooper->GetId()); // trooper->GetId());
UE_LOG(LogTemp, Warning, TEXT("Trooper #%d hit enemy trooper #%d"), // UE_LOG(LogTemp, Warning, TEXT("Trooper #%d hit enemy trooper #%d"),
SelectedTrooper->GetId(), trooper->GetId()); // SelectedTrooper->GetId(), trooper->GetId());
} // }
} // }
} // }
else if (actor->ActorHasTag(FName("Floor"))) { // else if (actor->ActorHasTag(FName("Floor"))) {
UE_LOG(LogTemp, Warning, TEXT("Hitted floor: %f, %f, %f"), HitResult.Location.X, // UE_LOG(LogTemp, Warning, TEXT("Hitted floor: %f, %f, %f"), HitResult.Location.X,
HitResult.Location.Y, HitResult.Location.Z); // HitResult.Location.Y, HitResult.Location.Z);
if (SelectedTrooper != nullptr) { // if (SelectedTrooper != nullptr) {
SelectedTrooper->MoveTrooper(HitResult.Location); // SelectedTrooper->MoveTrooper(HitResult.Location);
IsThereTrooperMoving = true; // IsThereTrooperMoving = true;
} // }
} // }
} // }
} // }

@ -15,23 +15,23 @@ class TURNBASEDTUTORIAL_API AMyPlayerController : public APlayerController
GENERATED_BODY() GENERATED_BODY()
public: public:
AMyPlayerController(); // AMyPlayerController();
//
void StartTurn(); // void StartTurn();
//
void EndTurn(); // void EndTurn();
//
virtual void SetupInputComponent() override; // virtual void SetupInputComponent() override;
//
void SetTrooperIsMoving(bool isMoving); // void SetTrooperIsMoving(bool isMoving);
private: private:
bool IsMyTurn; // bool IsMyTurn;
//
bool IsThereTrooperMoving = false; // bool IsThereTrooperMoving = false;
//
ATrooper* SelectedTrooper; // ATrooper* SelectedTrooper;
//
void OnLeftMouseClick(); // void OnLeftMouseClick();
}; };

@ -3,8 +3,7 @@
#include "MyPlayerStart.h" #include "MyPlayerStart.h"
uint8 AMyPlayerStart::GetPlayerIndex() const { uint8 AMyPlayerStart::GetPlayerIndex() const
return PlayerIndex; {
return PlayerIndex;
} }

@ -26,22 +26,22 @@ void ATrooper::BeginPlay()
} }
void ATrooper::Tick(float deltaTime) { void ATrooper::Tick(float deltaTime) {
if (IsMoving) { // if (IsMoving) {
FVector vector = (MoveToVector - Position); // FVector vector = (MoveToVector - Position);
vector.Normalize(); // vector.Normalize();
vector *= (Speed * deltaTime); // vector *= (Speed * deltaTime);
if (vector.Size() >= (MoveToVector - Position).Size()) { // if (vector.Size() >= (MoveToVector - Position).Size()) {
Position = MoveToVector; // Position = MoveToVector;
IsMoving = false; // IsMoving = false;
dynamic_cast<AMyPlayerController*>( // dynamic_cast<AMyPlayerController*>(
UGameplayStatics::GetPlayerController(GetWorld(), 0) // UGameplayStatics::GetPlayerController(GetWorld(), 0)
)->SetTrooperIsMoving(false); // )->SetTrooperIsMoving(false);
} // }
else { // else {
Position += vector; // Position += vector;
} // }
SetActorLocation(Position); // SetActorLocation(Position);
} // }
} }
void ATrooper::MoveTrooper(FVector newPos) { void ATrooper::MoveTrooper(FVector newPos) {

@ -1,6 +1,6 @@
{ {
"FileVersion": 3, "FileVersion": 3,
"EngineAssociation": "{B4FE6467-4579-3D84-B22A-558A3D607596}", "EngineAssociation": "4.27",
"Category": "", "Category": "",
"Description": "", "Description": "",
"Modules": [ "Modules": [

Loading…
Cancel
Save