How to generate surface from planet but with custom map-gen

Place to get help with not working mods / modding interface.
anakhon
Manual Inserter
Manual Inserter
Posts: 2
Joined: Wed Apr 09, 2025 6:23 pm
Contact:

How to generate surface from planet but with custom map-gen

Post by anakhon »

Hello,

I'm trying to generate custom surfaces related to planets, to be able to randomize ore/enemy presence, etc, of the surface.
To do this, I basically create a surface using the planet mapgen with changes, then associate the surface with the planet (previous surface is deleted).
The goal is to keep the lightning, pressure, magnetism, pollution type, etc depending on the planet, while being able to randomize the map-gen for ore and ennemies

Code: Select all

--- example
local mapgen = game.planets['vulcanus'].prototype.map_gen_settings
mapgen.seed=12345
local surface = game.create_surface('[img=space-location.vulcanus] vulcanus-XX', mapgen)
game.planets['vulcanus'].associate_surface(surface)
Unfortunately, for Aquilo, since the planet has "entities_require_heating", the associate_surface method doesn't work.
I tried to generate the surface using LuaPlanet.generate_surface(), then changing the mapgen and deleting chunk to have something changed, but i didn't seem to work...

Code: Select all

--- this doesn't work ?
local surface = game.planets['aquilo'].create_surface()
surface.map_gen_settings.autoplace_controls.aquilo_crude_oil.frequency=10
surface.map_gen_settings.autoplace_controls.lithium_brine.frequency=10
surface.map_gen_settings.autoplace_controls.fluorine_vent.frequency=10
surface.map_gen_settings.seed=66666

for chunk in surface.get_chunks() do
    surface.delete_chunk({x = chunk.x, y = chunk.y})
end
Should I also use "regenerate_entity()" and "regenerate_decorative()" ? But this wouldn't add the missing tiles?

Maybe i'm not doing it the right way ?
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3750
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: How to generate surface from planet but with custom map-gen

Post by DaveMcW »

Can you do it in data.lua?

Code: Select all

data.raw['planet']['aquilo'].map_gen_settings.autoplace_controls.aquilo_crude_oil.frequency = 10
data.raw['planet']['aquilo'].map_gen_settings.autoplace_controls.lithium_brine.frequency = 10
data.raw['planet']['aquilo'].map_gen_settings.autoplace_controls.fluorine_vent.frequency = 10
anakhon
Manual Inserter
Manual Inserter
Posts: 2
Joined: Wed Apr 09, 2025 6:23 pm
Contact:

Re: How to generate surface from planet but with custom map-gen

Post by anakhon »

I could.

Doing it in the prototypes would be my last solution if I don't find a way to do it during runtime.
I wanted to have multiple aquilo profile, like "lots of resources, scarces, some missing, etc"). (mostly random generate with min/max, so each time it's "random").
FiveYellowMice
Manual Inserter
Manual Inserter
Posts: 4
Joined: Sat Sep 27, 2025 1:12 am
Contact:

Re: How to generate surface from planet but with custom map-gen

Post by FiveYellowMice »

Haven't tried it myself, but it seems that LuaSurface.map_gen_settings is a getter that returns a copy of what the engine uses, not a reference to an internal object (like what a LuaSurface is). So your code only modifies the copy you have just obtained, and immediately discards it, it never modifies the map gen settings being used by the engine. To do that, you need to save the table to a variable, change its fields, and set the entire table to LuaSurface.map_gen_settings. Like the example given in the documentation: https://lua-api.factorio.com/stable/con ... tings.html
Post Reply

Return to “Modding help”