Simplest way to find vertical surfaces for placing schematic

Post Reply
User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Simplest way to find vertical surfaces for placing schematic

by texmex » Post

I need a way to find large, flat, vertical surfaces to insert schematics on and into. How would I go about such a thing in a simple fashion? Is there perhaps a ready-made library out there that I can use for detection?

I imagine that the code would first need to identify the surface but send back not only the position but the direction it faces as well.

Sokomine
Member
Posts: 4290
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: Simplest way to find vertical surfaces for placing schem

by Sokomine » Post

My basic_houses mod does that. It's basically just a house generator (procedurally place the nodes so that a house comes into beeing) plus detection of flat land. It uses handle_schematics.find_flat_land_get_candidates_fast(..) for locating a random spot that is flat for sizex * sizez nodes at least. ships_on_mapgen works similar - except that it looks for flat land on water (swimming ships) and at the bed of the sea (sunken ships).

[Edit] All this requires a working heightmap; so it only works with mapgens that supply one.
A list of my mods can be found here.

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: Simplest way to find vertical surfaces for placing schem

by texmex » Post

Thank you for your answer (I do plan on using find_flat_land_get_candidates_fast!), but you've seem to missed that in this case I need to find vertical surfaces, not horizontal. =)

Sokomine
Member
Posts: 4290
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: Simplest way to find vertical surfaces for placing schem

by Sokomine » Post

Ups! Vertical...that's indeed diffrent. Best play a bit with the heightmap and get used to how it can be accessed and what it contains. But in general, it's not much diffrent. You can use a similar approach: Iterate over the heightmap, check if it's high enough for your purpose at that given point and in the given direction, and if so count upwards until it is no longer the case.

heightmap[i-1] vs. heightmap vs. heightmap[i+1]: three nodes in a row in x direction (as long as i is not chunksize). Similarily, heightmap[i-chunksize] vs. heightmap vs. heightmap[i+chunksize] gives you three nodes in z direction. If the height diffrence is sufficient, your schematic might fit there. If it has a depth of more than 0 or 1, you'll probably have to extend the algorithm a bit and check that there's enough space.
A list of my mods can be found here.

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests