Simplest way to find vertical surfaces for placing schematic

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

Simplest way to find vertical surfaces for placing schematic

by texmex » Sun Nov 24, 2019 20:30

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: 3913
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine

Re: Simplest way to find vertical surfaces for placing schem

by Sokomine » Sun Nov 24, 2019 21:06

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: 1616
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: texmex

Re: Simplest way to find vertical surfaces for placing schem

by texmex » Sun Nov 24, 2019 21:11

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: 3913
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine

Re: Simplest way to find vertical surfaces for placing schem

by Sokomine » Sun Nov 24, 2019 21:29

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[i] 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[i] 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.
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 1 guest