Can't Solve This Coding Problem

Hey guys! Been wracking my brain on this problem. I’m working on my procedural map generation.

My code is currently segmenting out a 1 tile layer around my grid marking the tiles red. Then I have another function to identify the corners of this layer marking them blue. You can see in the picture below that with the proc gen its possible to generate an “out cropping.” My code identifies all of the tiles in an outcropping as corners. The behavior I want is to cut straight through the outcropping (ignoring it) and storing the tiles of the outcropping into a dataset.

I’ve been wracking my brain with how to identify when this is occurring. Keep in mind the outcroppings will always be 2 tiles wide but can be any length. Can anyone figure this one out? I may just be too tired

Here’s the original code that identifies the entire outcropping as a corner.

TArray AGroundBuilder::CornerOrientation(TArray OuterTiles, TArray InnerTiles)
{
TArray OutCorners;
TSet OuterTileSet(OuterTiles);

for (const FIntPoint& Tile : OuterTiles)
{
    TArray<FIntPoint> Neighbors = {
        FIntPoint(Tile.X - 1, Tile.Y), 
        FIntPoint(Tile.X + 1, Tile.Y), 
        FIntPoint(Tile.X, Tile.Y - 1), 
        FIntPoint(Tile.X, Tile.Y + 1)
    };

    bool bHasLeft = OuterTileSet.Contains(Neighbors[0]);
    bool bHasRight = OuterTileSet.Contains(Neighbors[1]);
    bool bHasDown = OuterTileSet.Contains(Neighbors[2]);
    bool bHasUp = OuterTileSet.Contains(Neighbors[3]);

    if ((bHasLeft && bHasUp) || (bHasLeft && bHasDown) ||
        (bHasRight && bHasUp) || (bHasRight && bHasDown))
    {
        OutCorners.Add(Tile);
    }
}
UpdateTerrain(0, OutCorners, FLinearColor::Blue);
return OutCorners;

}

I think i would have to keep track of which direction my function is traveling through the tile layer and prioritize neighbors in that direction. then when a tile has 3 neighbors still prioritize same direction but store the direction its 3rd neighbor is in and when the next corner is hit travel in the opposite direction? In this scenario i dont know how to store the out cropping tiles.

here’s an actual picture of the behavior from the original post


Which scenario are you trying to achieve A or B?

Not sure if you want to identify the outer edge or the u-turn as corners (adding a different tile set like a tower in a wall or skip it and just identify the travel along a route in the wall.

My hero is back! Scenario A but I want to capture the 4 (or however many there are) outcropping tiles in a dataset to special handle.

I see you are still going strong with the strategy :slight_smile:

So these segments that are out of the bounds of the normal path would need to be stored in some way and processed?

Are they fields where a building would be placed? I’m sort of stumped as to why they are there. Is the player the one that is drawing the path and adding in the space or is it a byproduct of the procedural generation?

Personally I would add an identifier index for the tile piece while placing it.

Still going strong! The game is really starting to shape up. Been working on the visuals for a while now. The area I lined out here is the grid where players can place buildings, but this has nothing to do with building placement.

I’m now procedurally generating the visuals of the map. the outter red layer you are seeing is me just testing a class that will identify area with 2 different heights. the red layer will separate 2 areas of different heights and I will use the red area to populate cliffs, hillside meshs to blend the 2 heights together. those outcropping will need specialized meshs or to just be handled differently than the rest. In this image the blue lined out area will be lower and the flat green area will be higher and the red will be a hillside or cliffside mesh to blend the heights together.

P.S. It’s a product of the procedural generation

So something like this?


Maybe a wave function collapse could help with this

Built in unreal solution:

Maybe it might help without the need to reinvent the wheel :wink:

I am basically working with this methodology, but I need these outcroppings to have a specific look. which is why I need logic to achieve your example A in your first response. The only data I have to work with is the array of wrapping tiles and the array of inner (grid in this example) tiles.


Try maybe doing a neighbor count around the tile and see how many adjacent are on the same level.

The corner tiles have a 3. Depending on the direction of the adjacent tile (N,E,S,W) you can add in logic regarding the tile rotation of the corner.

Two adjacent 3 tiles would be an outlier.

This is a nice brain teaser. I tried to read all the things you guys wrote about but I’ve probably missed something. Anyway, here are my 2 cents:

You have 2 options in my opinion:

  1. Walk along the path (X) while checking 2 tiles on each side (?):
  |   
??X??
  |   

If you see a Red/Blue neighbor and a Green tile after - mark the tile you are on for “outcropping”. This however needs you to have a “direction” in order to make the walk along the Red/Blue tiles.

  1. Walk a 5x5 cross and check 2 tiles in each direction:
  ?   
  ?   
??X??
  ?   
  ?   

Doesn’t need direction (walks every single tile) and Green tiles on the X will be skipped easily. If on a Red/Blue tile and at any direction you see Red/Blue neighbor and a Green tile after - mark the tile you are on for “outcropping”. Much simpler to write.