storing 12 cardinal dir vectors; Diagonals function
This commit is contained in:
@ -10,6 +10,18 @@
|
||||
// Sets default values
|
||||
AAdventureMap::AAdventureMap()
|
||||
{
|
||||
NBVectors.Add(NNE);
|
||||
NBVectors.Add(E);
|
||||
NBVectors.Add(SSE);
|
||||
NBVectors.Add(SSW);
|
||||
NBVectors.Add(W);
|
||||
NBVectors.Add(NNW);
|
||||
NBVectorsDiag.Add(N);
|
||||
NBVectorsDiag.Add(ENE);
|
||||
NBVectorsDiag.Add(ESE);
|
||||
NBVectorsDiag.Add(S);
|
||||
NBVectorsDiag.Add(WSW);
|
||||
NBVectorsDiag.Add(WNW);
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
@ -17,8 +29,8 @@ void AAdventureMap::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
World = GetWorld();
|
||||
if (IsValid(BaseTileClass))
|
||||
{
|
||||
|
||||
if (IsValid(BaseTileClass)) {
|
||||
MakeGrid();
|
||||
}
|
||||
}
|
||||
@ -79,23 +91,46 @@ AHexTile* AAdventureMap::RandomHex()
|
||||
return Grid[RandHex];
|
||||
}
|
||||
|
||||
/*
|
||||
* Add two TArray<TPair<int32, int32>> members containing the Cardinal Directions
|
||||
(one for immediate neighbors, one for diagonals)
|
||||
{ fill them in AAdventureMap::AAdventureMap }
|
||||
|
||||
* This function instead returns
|
||||
TMap<bool bDiag, AHexTile* Neighbor>
|
||||
*/
|
||||
TArray<AHexTile*> AAdventureMap::Neighbors(AHexTile* OfHex)
|
||||
{
|
||||
TArray<AHexTile*> Neighbors;
|
||||
TArray<AHexTile*> Results;
|
||||
TArray<int32> Indeces;
|
||||
|
||||
Indeces.Add(GridIndex(OfHex->Q + NE.Key, OfHex->R + NE.Value));
|
||||
Indeces.Add(GridIndex(OfHex->Q + E.Key, OfHex->R + E.Value));
|
||||
Indeces.Add(GridIndex(OfHex->Q + SE.Key, OfHex->R + SE.Value));
|
||||
Indeces.Add(GridIndex(OfHex->Q + SW.Key, OfHex->R + SW.Value));
|
||||
Indeces.Add(GridIndex(OfHex->Q + W.Key, OfHex->R + W.Value));
|
||||
Indeces.Add(GridIndex(OfHex->Q + NW.Key, OfHex->R + NW.Value));
|
||||
|
||||
for (auto& I : Indeces) {
|
||||
if (Grid.IsValidIndex(I)) { if (OfHex->Distance(Grid[I]) == 1) { Neighbors.Add(Grid[I]); } }
|
||||
for (auto& Vec : NBVectors) {
|
||||
Indeces.Add(GridIndex(OfHex->Q + Vec.Key, OfHex->R + Vec.Value));
|
||||
}
|
||||
for (auto& Ind : Indeces) {
|
||||
if (Grid.IsValidIndex(Ind)) {
|
||||
if (OfHex->Distance(Grid[Ind]) == 1) {
|
||||
Results.Add(Grid[Ind]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Results;
|
||||
}
|
||||
|
||||
return Neighbors;
|
||||
TArray<AHexTile*> AAdventureMap::Diagonals(AHexTile* OfHex)
|
||||
{
|
||||
TArray<AHexTile*> Results;
|
||||
TArray<int32> Indeces;
|
||||
for (auto& Vec : NBVectorsDiag) {
|
||||
Indeces.Add(GridIndex(OfHex->Q + Vec.Key, OfHex->R + Vec.Value));
|
||||
}
|
||||
for (auto& Ind : Indeces) {
|
||||
if (Grid.IsValidIndex(Ind)) {
|
||||
if (OfHex->Distance(Grid[Ind]) == 2) {
|
||||
Results.Add(Grid[Ind]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Results;
|
||||
}
|
||||
|
||||
TArray<AHexTile*> AAdventureMap::BreadthFirstSearch(AHexTile* Start, int32 Radius)
|
||||
|
Reference in New Issue
Block a user