Change map_gen_settings based on position

Place to get help with not working mods / modding interface.
pelocammelo
Burner Inserter
Burner Inserter
Posts: 6
Joined: Mon Apr 29, 2024 7:11 pm
Contact:

Change map_gen_settings based on position

Post by pelocammelo »

Hej everybody,

Im quite new to modding factorio, but Im trying. It would be great to have some input from the experts :D

The mod idea: I would like to generate different biomes on nauvis, each corresponding to the different planets in space age. I love spaceship logistic and the space age mod in general, but I thought it would be cool to do it all on nauvis with long distance trains connecting the different biomes.

I have found mods which allow something similar, but they mostly mix all resources so they are available everywhere on nauvis. I would like to have distinct biomes representing the different planets.

For the first version of the mod the easiest solution would be to simply check the y position of a chunk and use the map_gen_settings of different planets. It is not really biomes, but the results would be a planet with bands, not too different from earth: you go south to the equator and find a gleba belt (tropical zone) and after a vulcanus belt (desert/warm area) at the quator. Same going north, first a fulgora belts and then artic region of aquilo.

I tried coding control.lua something like this (just to see if it works):

script.on_event(defines.events.on_chunk_generated, function(event)
if event.position.y > 100 then
data.raw.planet.nauvis.map_gen_settings = data.raw.planet.fulgora.map_gen_settings
end
end)

Well, it didn't work :D I have the feeling that the event on_chunk_generated is activated after the chunk is generated, which is not ideal.

Anyone with some experience on map generation can give me advice? Do you think the general idea would work?

Cheers
Natha
Filter Inserter
Filter Inserter
Posts: 259
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: Change map_gen_settings based on position

Post by Natha »

You would need to create your own noise expressions for that
pelocammelo
Burner Inserter
Burner Inserter
Posts: 6
Joined: Mon Apr 29, 2024 7:11 pm
Contact:

Re: Change map_gen_settings based on position

Post by pelocammelo »

Alrigth, I looked into noise expressions and you are very right. So, I could add to nauvis all the entities from the other planets and use the probability_expression in the autoplace to be 0 unless the position is correct. But then the noise expression should be the default in the designated areas.
Natha
Filter Inserter
Filter Inserter
Posts: 259
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: Change map_gen_settings based on position

Post by Natha »

Just create one or more expressions that return 1 in a specific (circular) area and 0 everywhere else. Then multiply this with the entity/tile specific expression
pelocammelo
Burner Inserter
Burner Inserter
Posts: 6
Joined: Mon Apr 29, 2024 7:11 pm
Contact:

Re: Change map_gen_settings based on position

Post by pelocammelo »

Im trying to test a bit the idea and for now I just want to set the noise expression of anything on nauvis to 0 if x>0. I think once this work I would be able to extend it. Im taking all the expressions used on nauvis and then changing the noise expression associated with that name, however it is not really working. The code is in data-update.lua

data:extend{
{
type = "noise-expression",
name = "nauvis_biome_perimeter",
expression = "if(x >= 0, 0, 1)"
},
}

for _, expression in pairs(data.raw.planet.nauvis.map_gen_settings.property_expression_names) do
local base_noise = data.raw["noise-expression"][expression.name]["expression"]
data.raw["noise-expression"][expression.name]["expression"] = "(" .. base_noise .. ")*nauvis_biome_perimeter"
end

Any idea why it might not do anything? :D
pelocammelo
Burner Inserter
Burner Inserter
Posts: 6
Joined: Mon Apr 29, 2024 7:11 pm
Contact:

Re: Change map_gen_settings based on position

Post by pelocammelo »

Quick update, I finally manage to influence some of the noise expressions, the code is now:

data:extend{
{
type = "noise-function", -- takes two noise function in input and output their product
name = "noise_multiply",
parameters = {"noise_1", "noise_2"},
expression = "(noise_1)*(noise_2)"
},
{
type = "noise-expression",
name = "nauvis_belt",
expression = "if(y >= 100, 0, 1)"
},
}

for _, prototype in pairs(data.raw["tree"]) do
if prototype.autoplace then
local expression = prototype.autoplace.probability_expression
prototype.autoplace.probability_expression = "noise_multiply{noise_1 = nauvis_belt, noise_2 = "..expression.."}"
end
end

This changes the noise expression for all trees and I can limit the generation to specified areas, now at y>=100. Following the same reasoning I could limit all objects in data.raw["simple-entity"] and "resource". However, I would now like to distinguish between entities/resources from the different planets, so I can use a different noise expression for those.

Im thinking about using the "data.raw.planet.nauvis.map_gen_settings.autoplace_settings" as a list of prototypes to compare with the ones from data.raw["tree"/"resource"], but I don't think the prototypes in nauvis auto_settings match the prototypes in data.raw. Any ideas how could I solve this?

Cheers
Natha
Filter Inserter
Filter Inserter
Posts: 259
Joined: Sun Mar 15, 2015 1:48 pm
Contact:

Re: Change map_gen_settings based on position

Post by Natha »

pelocammelo wrote: Mon Feb 24, 2025 8:32 am but I don't think the prototypes in nauvis auto_settings match the prototypes in data.raw. Any ideas how could I solve this?
They do.
And why using your own noise_multiply function? it should work by simply multiplying the two operands in probabilty_expression
pelocammelo
Burner Inserter
Burner Inserter
Posts: 6
Joined: Mon Apr 29, 2024 7:11 pm
Contact:

Re: Change map_gen_settings based on position

Post by pelocammelo »

Yes, you are right, they do. Altough I can't find a direct relation between the trees in nauvis map_gen settings and the trees listed in data.raw["tree"]. But the rest of the prototypes have a corresponding prototype in data.raw.

Anyway, I made some progress, I actually managed to limit the autoplace of most nauvis prototypes to a specified region, and added the settings from the other planets, so that now the map generates with 5 belts, each corresponding to the different planets. Attached a picture of the result.

Next I will have to fix the elevation and cliffs, but I can't figure out which is the noise-expression used by nauvis, anybody has suggestion? adding a property_expression_name called elevation doesn't seem to help. I will post the full code after I fix it.
Attachments
Media.jpg
Media.jpg (559.62 KiB) Viewed 303 times
pelocammelo
Burner Inserter
Burner Inserter
Posts: 6
Joined: Mon Apr 29, 2024 7:11 pm
Contact:

Re: Change map_gen_settings based on position

Post by pelocammelo »

I did some progress, attached the mod file. There are some problems left to be fixed, mainly with the cliffs and the tile placements. For some reason some of the tiles won't work properly.

If anybody is interested in having a look and let me know any feedback is much appreciated :D
Attachments
test_0.1.0.zip
(4 KiB) Downloaded 16 times
Post Reply

Return to “Modding help”