unreal/AdventureMap.h

108 lines
3.7 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Containers/Map.h"
#include "HexVector.h"
#include "AdventureMap.generated.h"
class AHexTile;
class AMapObject;
class AAdventurePlayerController;
UCLASS()
class FRAY_API AAdventureMap : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AAdventureMap();
UPROPERTY()
UWorld* World;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
TSubclassOf<AHexTile> BaseTileClass;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
int32 GridSize = 60;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
int32 TileSize = 100;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
AAdventurePlayerController* PCRef;
UFUNCTION(BlueprintCallable, Category = "Generation")
void MakeGrid();
UPROPERTY(BlueprintReadOnly, Category = "Generation")
bool bHexGridReady;
UPROPERTY(BlueprintReadOnly, Category = "Generation")
TArray<AHexTile*> Grid;
UFUNCTION(BlueprintCallable, Category = "Utility")
int32 GridIndex(int32 q, int32 r);
UFUNCTION(BlueprintCallable, Category = "Utility")
AHexTile* RandomHex();
// Cardinal direction vectors
UPROPERTY(BlueprintReadOnly, VisibleAnywhere) //diag
FHexVector N = FHexVector(1, -2); //
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
FHexVector NNE = FHexVector(1, -1);
UPROPERTY(BlueprintReadOnly, VisibleAnywhere) //diag
FHexVector ENE = FHexVector(2, -1); //
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
FHexVector E = FHexVector(1, 0);
UPROPERTY(BlueprintReadOnly, VisibleAnywhere) //diag
FHexVector ESE = FHexVector(1, 1); //
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
FHexVector SSE = FHexVector(0, 1);
UPROPERTY(BlueprintReadOnly, VisibleAnywhere) //diag
FHexVector S = FHexVector(-1, 2); //
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
FHexVector SSW = FHexVector(-1, 1);
UPROPERTY(BlueprintReadOnly, VisibleAnywhere) //diag
FHexVector WSW = FHexVector(-2, 1); //
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
FHexVector W = FHexVector(-1, 0);
UPROPERTY(BlueprintReadOnly, VisibleAnywhere) //diag
FHexVector WNW = FHexVector(-1, -1); //
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
FHexVector NNW = FHexVector(0, -1);
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
TArray<FHexVector> NeighborUnitVectors;
UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
TArray<FHexVector> DiagonalUnitVectors;
UFUNCTION(BlueprintCallable, Category = "Utility")
FHexVector UnitDiagFromUnitNB(FHexVector InVecA, FHexVector InVecB);
UFUNCTION(BlueprintCallable, Category = "Utility")
bool DiagIsReachable(AHexTile* InStart, FHexVector InDiagUnitVec);
UFUNCTION(BlueprintCallable, Category = "Runtime")
TArray<AHexTile*> Neighbors(AHexTile* OfHex, bool bFreeOnly);
UFUNCTION(BlueprintCallable, Category = "Runtime")
TArray<AHexTile*> FreeDiagonals(AHexTile* OfHex);
UFUNCTION(BlueprintCallable, Category = "Runtime")
TSet<AHexTile*> BreadthFirstSearch(AHexTile* Start, int32 Radius);
UFUNCTION(BlueprintCallable, Category = "Runtime")
TArray<AHexTile*> FindPathAStar(AHexTile* Start, AHexTile* Goal, bool bDiags);
UFUNCTION(BlueprintCallable, Category = "Runtime")
TArray<AHexTile*> ShortcutAStar(TArray<AHexTile*> Path);
// considering a MapObjectManager class or moving pathfinding & search to PlayerController
UPROPERTY(BlueprintReadWrite, EditAnywhere)
TMap<AHexTile*, AMapObject*> MapObjects;
UPROPERTY(BlueprintReadOnly)
TMap<int32, AMapObject*> MapObjectsByID;
UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
int32 IncID = -1;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
};