Custom Scenarios, Mapgen and Spawn-points

What I’m hoping to achieve: to make a custom Scenario, which Spawns the character inside of a small, custom-built Shack either in, or preferably an Overmap tile or two away from a Swamp.

What I’ve actually done: I’ve successfully edited in a new Scenario and a new Start Location in their respective .json files, and I’ve gone in-game and, using the Scenario, successfully spawned in a Swamp, though not before an error stating that the game didn’t know where to put me.

After rooting through mapgen and overmap_terrain, for a few hours I couldn’t find anything that gave me an idea of how player spawning, and indeed building spawning is handled, so I’ve come here to try and get it figured out.

Could someone with a little more knowledge of how the mapgen works give me some pointers here?

You need to make the shack spawn somewhere first. Depending on RNG, some worlds will spawn without it anyway (scenarios don’t enforce the existence of a spawn point), so when it doesn’t spawn it may just mean you made the chance low.

You probably want to copy “cabin” structure. Look for it in both data/json/overmap jsons. You need to declare your shack in both of those files.
Then you will need to define how the shack looks in data/json/mapgen/ (create a new json for it, you’ll probably want to copy and edit bandit_cabin.json).

Once the shack is properly defined and you generate a new world after saving the changes to jsons, the scenario should be able to locate it using “allowed_locs”. Provided mapgen doesn’t decide not to generate it this time, as it can sometimes be crazy like that (I once got a world with zero science labs - on a science lab start).

As far as I can tell, there’s no way to make it spawn near swamp other than making it spawn on a swamp tile.

Thanks a lot Coolthulhu, I managed to figure it out and get it working pretty nicely. I’m going to enjoy playing around with this a fair bit more in the future.