2022-01-11 11:07:17 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
|
|
|
#include "GameFramework/Actor.h"
|
2022-01-26 18:09:39 +01:00
|
|
|
#include "Containers/Map.h"
|
2022-01-28 21:58:04 +01:00
|
|
|
#include "HexVector.h"
|
2022-01-11 11:07:17 +01:00
|
|
|
#include "AdventureMap.generated.h"
|
|
|
|
|
|
|
|
class AHexTile;
|
2022-06-01 20:25:33 +02:00
|
|
|
class AStarFog;
|
2022-01-25 18:30:49 +01:00
|
|
|
class AMapObject;
|
2022-01-26 16:48:58 +01:00
|
|
|
class AAdventurePlayerController;
|
2022-01-11 11:07:17 +01:00
|
|
|
|
|
|
|
UCLASS()
|
|
|
|
class FRAY_API AAdventureMap : public AActor
|
|
|
|
{
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Sets default values for this actor's properties
|
|
|
|
AAdventureMap();
|
|
|
|
|
2022-01-28 21:58:04 +01:00
|
|
|
UPROPERTY()
|
|
|
|
UWorld* World;
|
2022-01-11 11:07:17 +01:00
|
|
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
|
|
|
TSubclassOf<AHexTile> BaseTileClass;
|
2022-06-01 20:25:33 +02:00
|
|
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
|
|
|
TSubclassOf<AStarFog> BaseFogClass;
|
2022-01-12 18:22:16 +01:00
|
|
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
2022-05-25 20:07:51 +02:00
|
|
|
int32 GridSize = 60;
|
2022-01-12 18:22:16 +01:00
|
|
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
2022-01-11 11:07:17 +01:00
|
|
|
int32 TileSize = 100;
|
2022-01-11 18:16:26 +01:00
|
|
|
|
2022-02-05 14:26:46 +01:00
|
|
|
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
|
|
|
|
AAdventurePlayerController* PCRef;
|
|
|
|
|
2022-01-12 18:22:16 +01:00
|
|
|
UFUNCTION(BlueprintCallable, Category = "Generation")
|
|
|
|
void MakeGrid();
|
2022-01-11 18:16:26 +01:00
|
|
|
UPROPERTY(BlueprintReadOnly, Category = "Generation")
|
|
|
|
bool bHexGridReady;
|
2022-01-25 18:30:49 +01:00
|
|
|
UPROPERTY(BlueprintReadOnly, Category = "Generation")
|
2022-01-11 11:07:17 +01:00
|
|
|
TArray<AHexTile*> Grid;
|
2022-01-12 18:22:16 +01:00
|
|
|
|
2022-01-28 21:58:04 +01:00
|
|
|
UFUNCTION(BlueprintCallable, Category = "Utility")
|
2022-01-11 11:07:17 +01:00
|
|
|
int32 GridIndex(int32 q, int32 r);
|
2022-01-28 21:58:04 +01:00
|
|
|
UFUNCTION(BlueprintCallable, Category = "Utility")
|
2022-01-12 18:22:16 +01:00
|
|
|
AHexTile* RandomHex();
|
2022-01-28 21:58:04 +01:00
|
|
|
|
|
|
|
// Cardinal direction vectors
|
|
|
|
UPROPERTY(BlueprintReadOnly, VisibleAnywhere) //diag
|
2022-02-03 01:11:06 +01:00
|
|
|
FHexVector N = FHexVector(1, -2); //
|
2022-01-28 21:58:04 +01:00
|
|
|
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
|
|
|
|
FHexVector NNE = FHexVector(1, -1);
|
|
|
|
UPROPERTY(BlueprintReadOnly, VisibleAnywhere) //diag
|
2022-02-03 01:11:06 +01:00
|
|
|
FHexVector ENE = FHexVector(2, -1); //
|
2022-01-28 21:58:04 +01:00
|
|
|
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
|
|
|
|
FHexVector E = FHexVector(1, 0);
|
|
|
|
UPROPERTY(BlueprintReadOnly, VisibleAnywhere) //diag
|
2022-02-03 01:11:06 +01:00
|
|
|
FHexVector ESE = FHexVector(1, 1); //
|
2022-01-28 21:58:04 +01:00
|
|
|
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
|
|
|
|
FHexVector SSE = FHexVector(0, 1);
|
|
|
|
UPROPERTY(BlueprintReadOnly, VisibleAnywhere) //diag
|
2022-02-03 01:11:06 +01:00
|
|
|
FHexVector S = FHexVector(-1, 2); //
|
2022-01-28 21:58:04 +01:00
|
|
|
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
|
|
|
|
FHexVector SSW = FHexVector(-1, 1);
|
|
|
|
UPROPERTY(BlueprintReadOnly, VisibleAnywhere) //diag
|
2022-02-03 01:11:06 +01:00
|
|
|
FHexVector WSW = FHexVector(-2, 1); //
|
2022-01-28 21:58:04 +01:00
|
|
|
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
|
|
|
|
FHexVector W = FHexVector(-1, 0);
|
|
|
|
UPROPERTY(BlueprintReadOnly, VisibleAnywhere) //diag
|
2022-02-03 01:11:06 +01:00
|
|
|
FHexVector WNW = FHexVector(-1, -1); //
|
2022-01-28 21:58:04 +01:00
|
|
|
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
|
|
|
|
FHexVector NNW = FHexVector(0, -1);
|
|
|
|
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
|
2022-06-01 20:25:33 +02:00
|
|
|
TArray<FHexVector> UnitVectors;
|
2022-01-28 21:58:04 +01:00
|
|
|
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
|
|
|
|
TArray<FHexVector> DiagonalUnitVectors;
|
2022-02-03 01:11:06 +01:00
|
|
|
UFUNCTION(BlueprintCallable, Category = "Utility")
|
|
|
|
FHexVector UnitDiagFromUnitNB(FHexVector InVecA, FHexVector InVecB);
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Utility")
|
|
|
|
bool DiagIsReachable(AHexTile* InStart, FHexVector InDiagUnitVec);
|
2022-01-28 21:58:04 +01:00
|
|
|
|
2022-06-18 01:17:26 +02:00
|
|
|
UFUNCTION(BlueprintCallable, Category = "Utility")
|
|
|
|
float LerpAxial(int32 a, int32 b, int32 t);
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Utility")
|
|
|
|
FHexVector AxialRound(float q, float r)
|
|
|
|
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Utility")
|
2022-01-28 21:58:04 +01:00
|
|
|
TArray<AHexTile*> Neighbors(AHexTile* OfHex, bool bFreeOnly);
|
2022-06-18 01:17:26 +02:00
|
|
|
UFUNCTION(BlueprintCallable, Category = "Utility")
|
2022-02-03 01:11:06 +01:00
|
|
|
TArray<AHexTile*> FreeDiagonals(AHexTile* OfHex);
|
2022-06-18 01:17:26 +02:00
|
|
|
UFUNCTION(BlueprintCallable, Category = "Utility")
|
2022-01-28 21:58:04 +01:00
|
|
|
TSet<AHexTile*> BreadthFirstSearch(AHexTile* Start, int32 Radius);
|
2022-01-18 20:09:37 +01:00
|
|
|
UFUNCTION(BlueprintCallable, Category = "Runtime")
|
2022-01-28 21:58:04 +01:00
|
|
|
TArray<AHexTile*> FindPathAStar(AHexTile* Start, AHexTile* Goal, bool bDiags);
|
2022-02-03 01:11:06 +01:00
|
|
|
UFUNCTION(BlueprintCallable, Category = "Runtime")
|
|
|
|
TArray<AHexTile*> ShortcutAStar(TArray<AHexTile*> Path);
|
|
|
|
|
2022-05-25 20:07:51 +02:00
|
|
|
|
2022-02-03 01:11:06 +01:00
|
|
|
// considering a MapObjectManager class or moving pathfinding & search to PlayerController
|
2022-01-18 20:09:37 +01:00
|
|
|
|
2022-01-28 21:58:04 +01:00
|
|
|
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
|
|
|
TMap<AHexTile*, AMapObject*> MapObjects;
|
|
|
|
UPROPERTY(BlueprintReadOnly)
|
|
|
|
TMap<int32, AMapObject*> MapObjectsByID;
|
|
|
|
UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
|
|
|
|
int32 IncID = -1;
|
2022-01-26 18:09:39 +01:00
|
|
|
|
2022-01-11 11:07:17 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Called when the game starts or when spawned
|
|
|
|
virtual void BeginPlay() override;
|
2022-01-16 18:33:43 +01:00
|
|
|
};
|
2022-06-08 11:39:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
// only used for an experimental implementation of A*
|
|
|
|
template <typename InElementType>
|
|
|
|
struct TPriorityQueueNode {
|
|
|
|
InElementType Element;
|
|
|
|
float Priority;
|
|
|
|
|
|
|
|
TPriorityQueueNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TPriorityQueueNode(InElementType InElement, float InPriority)
|
|
|
|
{
|
|
|
|
Element = InElement;
|
|
|
|
Priority = InPriority;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const TPriorityQueueNode<InElementType> Other) const
|
|
|
|
{
|
|
|
|
return Priority < Other.Priority;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <typename InElementType>
|
|
|
|
class TPriorityQueue {
|
|
|
|
public:
|
|
|
|
TPriorityQueue()
|
|
|
|
{
|
|
|
|
Array.Heapify();
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Always check if IsEmpty() before Pop-ing!
|
|
|
|
InElementType Pop()
|
|
|
|
{
|
|
|
|
TPriorityQueueNode<InElementType> Node;
|
|
|
|
Array.HeapPop(Node);
|
|
|
|
return Node.Element;
|
|
|
|
}
|
|
|
|
|
|
|
|
TPriorityQueueNode<InElementType> PopNode()
|
|
|
|
{
|
|
|
|
TPriorityQueueNode<InElementType> Node;
|
|
|
|
Array.HeapPop(Node);
|
|
|
|
return Node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Push(InElementType Element, float Priority)
|
|
|
|
{
|
|
|
|
Array.HeapPush(TPriorityQueueNode<InElementType>(Element, Priority));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsEmpty() const
|
|
|
|
{
|
|
|
|
return Array.Num() == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public: // make private later on
|
|
|
|
TArray<TPriorityQueueNode<InElementType>> Array;
|
|
|
|
};
|