SakeTami
Earendel
Earendel

patreon


Regenerate Terrain

Sometimes if you update the game to a new major version, update a mod, or change mods, it can change the rules that the game uses to generate terrain. When this happens the parts of your map that have already been generated don’t change, but new chunks that get generated will use the new rules and can be different. This can create hard lined broken edges in the terrain that don’t look great, but there can be gameplay downsides too, like pathways that don’t connect, or new required resources that didn’t spawn where they should.

The Regenerate Terrain mod tries to fix this by regenerating all the terrain for parts of the map that already exist. There’s a really easy way to do this, just delete the entire map and generate it again. There’s a downside to doing it that way though, like deleting your entire base. So there needs to be a better way.

The way I chose to do it is to search every chunk for player-built things, like machines, cars, the player, but also for things like rails. Any chunk without something player-built gets deleted and then it can be regenerated as needed by the normal processes. The chunks with player-built stuff need special treatment…

First I create a new surface with the same settings as the surface being regenerated, a parallel world. The chunks in the same positions as the ones with player-built stuff get generated and are a perfect representation of what should be under the player-built stuff (this part takes a while).

Then all the terrain features from the parallel world are copied over to the original world (this takes even longer). If there’s something in the way of a rock or tree being copied that’s fine, just don’t place it. If the original world has paving like concrete, then the regenerated tile gets placed underneath the paving. What’s even more awkward is when the regenerated tile is water and it needs to go under something like a rail line. Then I need to check if the water would destroy the rail, and if it would place landfill there instead.

That covers most of what’s needed to regenerate the terrain 99% of the time, but of course it's that last 1% that’s the killer. There are always corner cases like weird mod-to-mod interactions, special tile or entity buildability rules etc. Some of those cases are handled, but some aren’t and get so specific that it’s better for the player to try to fix in the editor.

There are side effects like enemies respawning, but then resources can respawn too so it’s not all bad.

Regenerate Terrain as one of the first mods I made. It wasn’t a priority for me to update it for Factorio 2.0, I wanted to focus on other things. I started trying to load some old saves recently and the broken map edges got annoying. Suddenly the priority of Regenerate Terrain went up, and... before you know it, it's updated:

https://mods.factorio.com/mod/regenerate-terrain

Regenerate Terrain

Comments

Mmmm. Space age was good, but cannot wait for SE + space age. Especially can’t wait to see how you blend the two. Will vitamelange stuff be melded into gleba? Or will it be it’s own separate planet? Will you keep old SE supply rockets as a separate kind of rocket? Or will you merge the functionality of the two? Cannot wait to find out!

Sidney Jackson

Out of curiosity, will it work alongside space age or as an alternative? Also, that screenshot is magnificent, I'm only just starting to realize just how difficult adding that must have been, considering how factorio renders things, only way I can think of doing it without recoding the rendering engine entirely would be to make multiple rendering passes, one per Z level

viperfan7

Why not just freeze the generation settings for the entire world if it has anything player-owned?

Andrew Romashkin

And before anyone asks, yes we're still updating SE for Factorio 2.0. It's a big very complicated mod so it's taking a while.

Earendel


More Creators