MovementArrow functionality; StarFog implemented; Refactoring
This commit is contained in:
+14
-4
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "AdventureMap.h"
|
||||
#include "HexTile.h"
|
||||
#include "StarFog.h"
|
||||
#include "AdventurePlayerController.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Algo/Reverse.h"
|
||||
@@ -10,8 +11,8 @@
|
||||
// Sets default values
|
||||
AAdventureMap::AAdventureMap()
|
||||
{
|
||||
FHexVector NBs[] = { NNE, E, SSE, SSW, W, NNW };
|
||||
NeighborUnitVectors.Append(NBs, UE_ARRAY_COUNT(NBs));
|
||||
FHexVector NBs[] = { E, SSE, SSW, W, NNW, NNE };
|
||||
UnitVectors.Append(NBs, UE_ARRAY_COUNT(NBs));
|
||||
FHexVector DNBs[] = { N, ENE, ESE, S, WSW, WNW };
|
||||
DiagonalUnitVectors.Append(DNBs, UE_ARRAY_COUNT(DNBs));
|
||||
}
|
||||
@@ -25,6 +26,11 @@ void AAdventureMap::BeginPlay()
|
||||
if (IsValid(BaseTileClass)) {
|
||||
MakeGrid();
|
||||
}
|
||||
for (auto& Tile : Grid) {
|
||||
AStarFog* Fog = World->SpawnActor<AStarFog>(BaseFogClass, Tile->GetActorTransform());
|
||||
Fog->CoveredHex = Tile;
|
||||
Tile->CoveringFog = Fog;
|
||||
}
|
||||
}
|
||||
|
||||
// Called once on Begin Play
|
||||
@@ -69,6 +75,9 @@ int32 AAdventureMap::GridIndex(int32 qAxial, int32 rAxial)
|
||||
|
||||
AHexTile* AAdventureMap::RandomHex()
|
||||
{
|
||||
//debug
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Picking A Random Hex"));
|
||||
|
||||
int32 RandHex = FMath::RandRange(0, GridSize*GridSize-1);
|
||||
return Grid[RandHex];
|
||||
}
|
||||
@@ -76,7 +85,7 @@ AHexTile* AAdventureMap::RandomHex()
|
||||
TArray<AHexTile*> AAdventureMap::Neighbors(AHexTile* OfHex, bool bFreeOnly = false)
|
||||
{
|
||||
TArray<AHexTile*> Results;
|
||||
for (auto& V : NeighborUnitVectors) {
|
||||
for (auto& V : UnitVectors) {
|
||||
int32 I = GridIndex(OfHex->Q + V.Q, OfHex->R + V.R);
|
||||
if (Grid.IsValidIndex(I)) {
|
||||
AHexTile* H = Grid[I];
|
||||
@@ -180,13 +189,14 @@ TArray<AHexTile*> AAdventureMap::FindPathAStar(AHexTile* Start, AHexTile* Goal,
|
||||
}
|
||||
Algo::Reverse(Path);
|
||||
|
||||
if (bDiags) {
|
||||
if (bDiags) { // DO NOT USE
|
||||
Path = ShortcutAStar(Path);
|
||||
}
|
||||
return Path;
|
||||
}
|
||||
|
||||
// very bro-sciency approach to pathfinding for diagonal Hex-movement
|
||||
// DO NOT USE
|
||||
TArray<AHexTile*> AAdventureMap::ShortcutAStar(TArray<AHexTile*> Path)
|
||||
{
|
||||
TArray<AHexTile*> Shortcut;
|
||||
|
||||
Reference in New Issue
Block a user