Drafted Vision blocking functionality and respective MapRef->HelperFunctions
This commit is contained in:
parent
18af6a56be
commit
db89c0b8e6
@ -8,6 +8,7 @@
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Algo/Reverse.h"
|
||||
#include "Util/IndexPriorityQueue.h"
|
||||
#include <cmath.h>
|
||||
|
||||
// Sets default values
|
||||
AAdventureMap::AAdventureMap()
|
||||
@ -83,6 +84,33 @@ AHexTile* AAdventureMap::RandomHex()
|
||||
return Grid[RandHex];
|
||||
}
|
||||
|
||||
FHexVector AAdventureMap::AxialRound(float qf, float rf)
|
||||
{
|
||||
float sf = -qf - rf;
|
||||
|
||||
int32 q = round(qf);
|
||||
int32 r = round(rf);
|
||||
int32 s = round(sf);
|
||||
|
||||
float q_diff = abs(q - qf);
|
||||
float r_diff = abs(r - rf);
|
||||
float s_diff = abs(s - sf);
|
||||
|
||||
if (q_diff > r_diff && q_diff > s_diff)
|
||||
{ q = -r - s; }
|
||||
else if (r_diff > s_diff)
|
||||
{ r = -q - s; }
|
||||
else
|
||||
{ s = -q - r; }
|
||||
|
||||
return FHexVector(q, r);
|
||||
}
|
||||
|
||||
float AAdventureMap::LerpAxial(int32 a, int32 b, int32 t)
|
||||
{
|
||||
return float(a + (b - a) * t);
|
||||
}
|
||||
|
||||
TArray<AHexTile*> AAdventureMap::Neighbors(AHexTile* OfHex, bool bFreeOnly = false)
|
||||
{
|
||||
TArray<AHexTile*> Results;
|
||||
@ -143,6 +171,8 @@ TSet<AHexTile*> AAdventureMap::BreadthFirstSearch(AHexTile* Start, int32 Radius)
|
||||
return Results;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* // Faulty implementation which uses an actual PriorityQueue
|
||||
TArray<AHexTile*> AAdventureMap::FindPathAStar(AHexTile* Start, AHexTile* Goal, bool bDiags)
|
||||
{
|
||||
|
@ -80,11 +80,16 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "Utility")
|
||||
bool DiagIsReachable(AHexTile* InStart, FHexVector InDiagUnitVec);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Runtime")
|
||||
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")
|
||||
TArray<AHexTile*> Neighbors(AHexTile* OfHex, bool bFreeOnly);
|
||||
UFUNCTION(BlueprintCallable, Category = "Runtime")
|
||||
UFUNCTION(BlueprintCallable, Category = "Utility")
|
||||
TArray<AHexTile*> FreeDiagonals(AHexTile* OfHex);
|
||||
UFUNCTION(BlueprintCallable, Category = "Runtime")
|
||||
UFUNCTION(BlueprintCallable, Category = "Utility")
|
||||
TSet<AHexTile*> BreadthFirstSearch(AHexTile* Start, int32 Radius);
|
||||
UFUNCTION(BlueprintCallable, Category = "Runtime")
|
||||
TArray<AHexTile*> FindPathAStar(AHexTile* Start, AHexTile* Goal, bool bDiags);
|
||||
|
@ -55,15 +55,30 @@ void AAdventurePlayerController::LeftClick()
|
||||
else { return; }
|
||||
}
|
||||
|
||||
TArray<AHexTile*> AAdventurePlayerController::Vision(int32 Radius)
|
||||
{
|
||||
TArray<AHexTile*> Results;
|
||||
TSet<AHexTile*> Visible;
|
||||
Visible = MapRef->BreadthFirstSearch(CurrentHex, Radius);
|
||||
for (auto& Hex : Visible) {
|
||||
if (ExploredHexes.Contains(Hex)) { continue; }
|
||||
Results.Add(Hex);
|
||||
ExploredHexes.Add(Hex);
|
||||
TSet<AHexTile*> AAdventurePlayerController::Vision(int32 Radius)
|
||||
{
|
||||
TSet<AHexTile*> InRange = MapRef->BreadthFirstSearch(CurrentHex, Radius);
|
||||
TSet<AHexTile*> Results;
|
||||
|
||||
for (auto& Hex : InRange) {
|
||||
if (Hex->Distance(CurrentHex) == Radius)
|
||||
{
|
||||
AHexTile* Target;
|
||||
for (int32 i = 1; i <= Radius; i++)
|
||||
{
|
||||
float t = 1.0f / Radius * i;
|
||||
FHexVector Sample;
|
||||
|
||||
Sample = MapRef->AxialRound(MapRef->Lerp(CurrentHex->Q, Hex->Q, t), MapRef->Lerp(CurrentHex->R, Hex->R, t));
|
||||
AHexTile* SampleHex = MapRef->Grid[MapRef->GridIndex(Sample.Q, Sample.R)];
|
||||
|
||||
Results.Add(SampleHex);
|
||||
ExploredHexes.Add(Hex);
|
||||
|
||||
if (!SampleHex->bFree || ExploredHexes.Contains(SampleHex))
|
||||
{ break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
return Results;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
int32 VisionRadius = 6;
|
||||
UFUNCTION(BlueprintCallable)
|
||||
TArray<AHexTile*> Vision(int32 Radius);
|
||||
TSet<AHexTile*> Vision(int32 Radius);
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TSet<AHexTile*> ExploredHexes;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user