plan to implement pathfinding; minor fixes & refactorings
This commit is contained in:
parent
9021763ab7
commit
b5c9c661fe
@ -2,6 +2,8 @@
|
||||
|
||||
|
||||
#include "AdventureCharacter.h"
|
||||
#include "AdventureMap.h"
|
||||
#include "HexTile.h"
|
||||
|
||||
// Sets default values
|
||||
AAdventureCharacter::AAdventureCharacter()
|
||||
@ -32,3 +34,10 @@ void AAdventureCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInput
|
||||
|
||||
}
|
||||
|
||||
void AAdventureCharacter::AStarFindPath(AHexTile*)
|
||||
{
|
||||
std::priority_queue<int32> Frontier;
|
||||
TMap<AHexTile*, AHexTile*> CameFrom;
|
||||
TMap<AHexTile*, int32> CostSoFar;
|
||||
|
||||
}
|
@ -4,8 +4,13 @@
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Character.h"
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "AdventureCharacter.generated.h"
|
||||
|
||||
class AHexTile;
|
||||
|
||||
UCLASS()
|
||||
class FRAY_API AAdventureCharacter : public ACharacter
|
||||
{
|
||||
@ -15,6 +20,15 @@ public:
|
||||
// Sets default values for this character's properties
|
||||
AAdventureCharacter();
|
||||
|
||||
UPROPERTY(VisibleInstanceOnly, BlueprintReadWrite, Category = "Runtime")
|
||||
AHexTile* GridLocation;
|
||||
UPROPERTY(VisibleInstanceOnly, BlueprintReadWrite, Category = "Runtime")
|
||||
AHexTile* SelectedHex;
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Runtime")
|
||||
TArray<AHexTile*> MovementPath;
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void AStarFindPath(AHexTile* Goal);
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
@ -24,17 +24,6 @@ void AAdventureMap::BeginPlay()
|
||||
}
|
||||
}
|
||||
|
||||
// Every Hex Tile's index within the Grid Array can be derived from its Q and R coordinates
|
||||
int32 AAdventureMap::GridIndex(int32 qAxial, int32 rAxial)
|
||||
{
|
||||
/*
|
||||
* The Q axis is (i.e. columns are) oriented diagonally.
|
||||
* The Hex Grid has a rough square shape, hence the Q coordinates must be offset by -1 every other row.
|
||||
*/
|
||||
int32 column = qAxial + FMath::FloorToInt(rAxial / 2);
|
||||
return (rAxial * GridSize) + column;
|
||||
}
|
||||
|
||||
// Called once on Begin Play
|
||||
void AAdventureMap::MakeGrid()
|
||||
{
|
||||
@ -83,8 +72,23 @@ void AAdventureMap::MakeGrid()
|
||||
bHexGridReady = true;
|
||||
}
|
||||
|
||||
// Every Hex Tile's index within the Grid Array can be derived from its Q and R coordinates
|
||||
int32 AAdventureMap::GridIndex(int32 qAxial, int32 rAxial)
|
||||
{
|
||||
/*
|
||||
* The Q axis is (i.e. columns are) oriented diagonally.
|
||||
* The Hex Grid has a rough square shape, hence the Q coordinates must be offset by -1 every other row.
|
||||
*/
|
||||
int32 column = qAxial + FMath::FloorToInt(rAxial / 2);
|
||||
return (rAxial * GridSize) + column;
|
||||
}
|
||||
|
||||
AHexTile* AAdventureMap::RandomHex()
|
||||
{
|
||||
int32 RandHex = GridIndex(FMath::RandRange(0, GridSize), FMath::RandRange(0, GridSize));
|
||||
while (RandHex > Grid.Num())
|
||||
{
|
||||
RandHex = GridIndex(FMath::RandRange(0, GridSize), FMath::RandRange(0, GridSize));
|
||||
}
|
||||
return Grid[RandHex];
|
||||
}
|
||||
}
|
||||
|
@ -22,19 +22,22 @@ public:
|
||||
TSubclassOf<AHexTile> BaseTileClass;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||
TSubclassOf<ACharacter> BasePartyCharacterClass;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Config")
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||
int32 GridSize = 100; // squared is the number of Tiles
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Config")
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||
int32 TileSize = 100;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Generation")
|
||||
void MakeGrid();
|
||||
UPROPERTY(BlueprintReadOnly, Category = "Generation")
|
||||
bool bHexGridReady;
|
||||
|
||||
UPROPERTY(VisibleInstanceOnly, BlueprintReadWrite, Category = "Runtime")
|
||||
UPROPERTY(VisibleInstanceOnly, BlueprintReadWrite, Category = "Generation")
|
||||
TArray<AHexTile*> Grid;
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
int32 GridIndex(int32 q, int32 r);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
AHexTile* RandomHex();
|
||||
|
||||
// Player spawn section
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
|
||||
@ -42,15 +45,7 @@ public:
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
|
||||
AAdventureCharacter* PlayerCharacter;
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void MakeGrid();
|
||||
UFUNCTION(BlueprintCallable)
|
||||
AHexTile* RandomHex();
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
|
||||
|
||||
};
|
@ -14,8 +14,6 @@ AHexTile::AHexTile()
|
||||
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Scene"));
|
||||
|
||||
this->FillCornersArray();
|
||||
|
||||
// OnClicked.AddDynamic(this, )
|
||||
}
|
||||
|
||||
void AHexTile::BeginPlay()
|
||||
@ -42,3 +40,8 @@ void AHexTile::FillCornersArray()
|
||||
}
|
||||
}
|
||||
|
||||
TArray<AHexTile*> AHexTile::Neighbors(AHexTile* OfHexTile)
|
||||
{
|
||||
return TArray<AHexTile*>();
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FVector Corner(int32 i);
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Runtime")
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "debug")
|
||||
TArray<FVector> Corners;
|
||||
UFUNCTION()
|
||||
void FillCornersArray();
|
||||
@ -40,6 +40,9 @@ public:
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Runtime")
|
||||
int32 Index;
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
TArray<AHexTile*> Neighbors(AHexTile* OfHexTile);
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
Loading…
Reference in New Issue
Block a user