From 219b99c8d7a0e78aff1bda59d46b77f2ab5cb9cf Mon Sep 17 00:00:00 2001 From: Maximilian Fajnberg Date: Thu, 13 Jan 2022 16:34:06 +0100 Subject: [PATCH] Neighbors function draft; refactoring --- AdventureCameraPawn.cpp | 2 +- AdventureCharacter.cpp | 3 +-- AdventureMap.cpp | 26 ++++++++++++++++++++++++++ AdventureMap.h | 2 ++ HexTile.cpp | 8 +------- HexTile.h | 7 +++---- 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/AdventureCameraPawn.cpp b/AdventureCameraPawn.cpp index 6f7502e..f3b206f 100644 --- a/AdventureCameraPawn.cpp +++ b/AdventureCameraPawn.cpp @@ -20,7 +20,7 @@ AAdventureCameraPawn::AAdventureCameraPawn() ESASize = .01; BaseScrollSpeed = 16; - ScrollAccelleration = BaseScrollSpeed * 2.2; + ScrollAccelleration = BaseScrollSpeed * 2.4; ESAMaxBoundSlope = 1 / (1 - (1-ESASize)); ESAMaxBoundIntercept = 1 - ESAMaxBoundSlope; diff --git a/AdventureCharacter.cpp b/AdventureCharacter.cpp index ca9180f..10b1877 100644 --- a/AdventureCharacter.cpp +++ b/AdventureCharacter.cpp @@ -34,10 +34,9 @@ void AAdventureCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInput } -void AAdventureCharacter::AStarFindPath(AHexTile*) +void AAdventureCharacter::AStarFindPath(AHexTile* Goal) { std::priority_queue Frontier; TMap CameFrom; TMap CostSoFar; - } \ No newline at end of file diff --git a/AdventureMap.cpp b/AdventureMap.cpp index 182f4b3..87dda7e 100644 --- a/AdventureMap.cpp +++ b/AdventureMap.cpp @@ -92,3 +92,29 @@ AHexTile* AAdventureMap::RandomHex() } return Grid[RandHex]; } + +TArray AAdventureMap::Neighbors(AHexTile* OfHex) +{ + TArray Neighbors; + int32 Index; + + Index = GridIndex(OfHex->Q + 1 , OfHex->R + 0 ); + if (Index < Grid.Num() && Index >= 0) { Neighbors.Add(Grid[Index]); } + + Index = GridIndex(OfHex->Q + 1 , OfHex->R - 1 ); + if (Index < Grid.Num() && Index >= 0) { Neighbors.Add(Grid[Index]); } + + Index = GridIndex(OfHex->Q + 0 , OfHex->R - 1 ); + if (Index < Grid.Num() && Index >= 0) { Neighbors.Add(Grid[Index]); } + + Index = GridIndex(OfHex->Q - 1 , OfHex->R + 0 ); + if (Index < Grid.Num() && Index >= 0) { Neighbors.Add(Grid[Index]); } + + Index = GridIndex(OfHex->Q - 1 , OfHex->R + 1 ); + if (Index < Grid.Num() && Index >= 0) { Neighbors.Add(Grid[Index]); } + + Index = GridIndex(OfHex->Q + 0 , OfHex->R + 1 ); + if (Index < Grid.Num() && Index >= 0) { Neighbors.Add(Grid[Index]); } + + return Neighbors; // currently wrapping from corner to corner --> rectify this with a manhattan distance check +} diff --git a/AdventureMap.h b/AdventureMap.h index 22715e6..0bc220b 100644 --- a/AdventureMap.h +++ b/AdventureMap.h @@ -38,6 +38,8 @@ public: int32 GridIndex(int32 q, int32 r); UFUNCTION(BlueprintCallable) AHexTile* RandomHex(); + UFUNCTION(BlueprintCallable) + TArray Neighbors(AHexTile* OfHexTile); // Player spawn section UPROPERTY(VisibleAnywhere, BlueprintReadWrite) diff --git a/HexTile.cpp b/HexTile.cpp index 0f7a3ef..749e95e 100644 --- a/HexTile.cpp +++ b/HexTile.cpp @@ -3,7 +3,7 @@ #include "HexTile.h" #include "AdventurePlayerController.h" - +#include "AdventureMap.h" #include "Kismet/KismetMathLibrary.h" // Sets default values @@ -39,9 +39,3 @@ void AHexTile::FillCornersArray() Corners.Emplace(Corner(i + 1)); } } - -TArray AHexTile::Neighbors(AHexTile* OfHexTile) -{ - return TArray(); -} - diff --git a/HexTile.h b/HexTile.h index 73c4a8d..948c7cd 100644 --- a/HexTile.h +++ b/HexTile.h @@ -9,7 +9,7 @@ class USceneComponent; class UStaticMeshComponent; - +class AAdventureMap; class AAdventurePlayerController; UCLASS() @@ -40,9 +40,8 @@ public: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Runtime") int32 Index; - UFUNCTION(BlueprintCallable) - TArray Neighbors(AHexTile* OfHexTile); - + UPROPERTY(BlueprintReadWrite, Category = "Runtime") + AAdventureMap* MapRef; protected: // Called when the game starts or when spawned virtual void BeginPlay() override;