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