(Untested!) Add a new system for spawning structures naturally, and use a separate function which returns a structure table based on the mapgen table. Notable changes are:

1 - A new mathod for spawning structures naturally. Instead of using the old ugly pattern & expensive code for spawning randomly and avoiding existing buildings, we now jigsaw structures using colums and rows. This results in a more uniform pattern and way less space loss between buildings.

2 - All the costly checks (determining building locations, checking for the trigger node, checking terrain roughness) are done in the function that generates the structure table before it's used. That means the hard work is done before spawning anything, rather than doing the dirty work with each structure instance.

This commit hasn't been tested and fixed / optimized yet, it is experimental! It likely breaks the structure system so use it at your own risk.