First draft of A* pathfinding implementation

This commit is contained in:
2022-01-16 18:33:43 +01:00
parent fc10cbfc3e
commit 180207f441
5 changed files with 114 additions and 53 deletions
+28 -11
View File
@@ -23,31 +23,48 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
float TileSize;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Config")
USceneComponent* SceneComponent;
UPROPERTY(BlueprintReadWrite, Category = "Config")
AAdventureMap* MapRef;
UFUNCTION(BlueprintCallable, Category = "debug")
FVector Corner(int32 i);
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "debug")
TArray<FVector> Corners;
UFUNCTION()
void FillCornersArray();
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "debug")
TArray<FVector> Corners;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Runtime")
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Coordinates")
int32 Q;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Runtime")
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Coordinates")
int32 R;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Runtime")
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Coordinates")
int32 Index;
UPROPERTY(BlueprintReadWrite, Category = "Runtime")
AAdventureMap* MapRef;
UFUNCTION(BlueprintCallable, Category = "Runtime")
UFUNCTION(BlueprintCallable, Category = "Coordinates")
int32 Distance(AHexTile* ToHex);
// Pathfinding
UPROPERTY(BlueprintReadWrite, Category = "Movement")
int32 MoveCost = 1;
UPROPERTY(VisibleInstanceOnly, Category = "Movement")
AHexTile* CameFrom;
UPROPERTY(VisibleInstanceOnly, Category = "Movement")
int32 CostSoFar = 0;
FORCEINLINE bool operator == (const AHexTile &Other)
{
if (this->Q == Other.Q && this->R == Other.R) { return true; }
else { return false; }
}
FORCEINLINE bool operator != (const AHexTile &Other)
{
if (this->Q == Other.Q && this->R == Other.R) { return false; }
else { return true; }
}
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
};