I need a function that takes a path array (Basically, just a list of master tile indices to get from point A to point B) and removes all the tiles that are not at intersections. (Also removing dead-end tiles)
I’ve got another function that takes my array from BP and fills it with the list of tiles along the path. This works great. But I don’t need (or want) the intermediate tiles between the intersections as this list is strictly for navigation.
I have a function I had already created that makes a master list of all intersecting tiles which works just fine. I figured I could use the same logic in this function to create another array of tiles from a path array that it was fed, then copy that new list back to the source array, but I’m having a hard time getting this to work. The function is called okay, but I still have a full path array instead of a stripped down version.
These are the two functions that I have for the intersections. The first one builds a master list of intersecting tiles. And the second one is the function I’m trying to write to give me a path of only the intersection (or turning) tiles:
void ALabyrinth::FindAllIntersections()
{
for (int32 i = 0; i < Tiles.Num(); i++)
{
int32 da = Tiles*.directionsAvailable;
if ((da != NORTH) && (da != SOUTH) && (da != EAST) && (da != WEST) && (da != NORTH + SOUTH) && (da != EAST + WEST))
{
IntersectionArray.Add(i);
}
}
}
void ALabyrinth::RemoveNonIntersectionsInPath(TArray<int32> pathArray)
{
TArray<int32> newPathArray;
newPathArray.Empty();
for (int32 i = 0; i < pathArray.Num(); i++)
{
int32 da = Tiles[pathArray*].directionsAvailable;
if ((da != NORTH) && (da != SOUTH) && (da != EAST) && (da != WEST) && (da != NORTH + SOUTH) && (da != EAST + WEST))
{
newPathArray.Add(pathArray*);
}
}
pathArray = newPathArray;
}
I’m sure I’m doing something stupid here. But I figured I’d for-loop through the int32 array of path tiles, check the tile against my master tile list and get the directions available to that tile.
If it’s not a dead end, or a straight through tile, I’ll add it to a temporary array. Then, finally, copy that new array to the array that was passed to the function. But I’m left with the exact same array I had before I went into the function.
I’m sure I’m overlooking something so obvious that it’s screaming into my face, but right now I cannot figure it out. I’m not that great with working with arrays and BP/C++ interfacing together, so I’m sure that’s where my problem lies, but I’m stuck on this one. I’ve tried things so many different ways that I’m calling for another set of eyes to help me out.
Thanks!
P.S. Just for completeness, this is how I’m using the node in BP: