Tile Generation Understanding

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Sauerkraut
Inserter
Inserter
Posts: 42
Joined: Fri Jul 17, 2015 3:37 pm
Contact:

Tile Generation Understanding

Post by Sauerkraut »

Hello Everyone.

I'm currently working on a mod that adds some "biomes" to the world generation. Now I know that there are no real biomes in Factorio but noise-layers instead. However, what I do not understand is how moisture and temperature are involved.

I did quite some research in the API and on the wiki, but couldn't quite figure out how it works. So, first off I want to present you what I think I do understand (correct me here, if I'm wrong):
  • Every terrain type has how noise layer. This is effectively a randomly generated (?) 2D-function with the coordinates on the map as input and a value as output. As drawing 2D is hard, I drew what I expect to be a 1D noise-layer (don't hate muh paint skillz):
    1.png
    1.png (6.8 KiB) Viewed 896 times
  • With multiple terrain types come multiple noise-layers:
    2.png
    2.png (10.51 KiB) Viewed 896 times
  • For each coordinate, the terrain with the highest noise-layer-value is picked and generated:
    3.png
    3.png (7.24 KiB) Viewed 896 times
So far, so good, but as I'm doing my research I stumble upon some strange mentionings of "moisture" and "temperature". I do some digging on what exactly this is and how it affects map generation, here is what i found out:
  • There are noise-layers defined in core\prototypes for moisture and temperature (also for some other things, such as elevation).
  • This line of code sets some range for a given terrain type in the tiles.lua:

    Code: Select all

        autoplace = autoplace_settings("grass", {{{35, 0.8}, {0, 0.4}}}),
    
  • In autoplace_utils these values are explained as

    Code: Select all

    -- Rectangles is a table of rectangle specifications:
    --  {{max_temp, max_water}, {min_temp, min_water}, influence}
    -- temperatures range from 35 to -25 (°C), water from 0 to 1.
    -- Influence is optional and has default value of default_influence or 1.
    
  • On the wiki I found this page: https://wiki.factorio.com/index.php?tit ... laceSheets. I am not sure how up-to-date this is, but it strangely contains biomes and snow tiles, wich I've never heard of (and couldn't find in the game files)
  • I created some "snow" tiles (with dummy textures) that had autoplace_settings according to this picture:
    Image
  • I quickly created a few sandbox games and used the chart command to reveal large areas of the map, but i didn't encounter any of the new tiles. I did this 4 times and revealed from -2500 to 2500. I might have been extremely unlucky, but i highly doubt that. To check that i didn't mess up some coding I did the same thing, but changed the rectangle to -25,0 : 35,1 and I had lots of red dummy textures everywhere.
Now here are the things I don't understand:

- How does moisture and temperature affect wich tiles are picked? I assume there is a generated moisture and temperature value for each tile on the map and if a type of terrain does not fit into these ranges it's noise-layer will be ignored? However, if that is true I do not understand how multiple terrains with different moistur/temperature requirements can share the same noise-layer.
- Are all temperature and moisture values equally possible, or are extreme temperatures really unlikely? That could explain why I could not find any snow.
- A lot of ranges are not covered by any terrain type. If you look at the picture above, what terrain is generated at a moisture of .8 and a temperature of -10°?

Thanks for reading all of this, I hope your answers will also be helpful to other modders, not just to me.

---
On a side note: I found a deprecated decleration in base\prototypes\entity\demo-trees.lua. In line 2 local biomes is declared as autoplace_utils.biomes. This however does not exist and is therefor nil. local biomes is never called. Should I do a bug report about it, or is this enough?

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Tile Generation Understanding

Post by aubergine18 »

I've no idea how temperature and water work, I was hoping to use them for one of my mods but after some testing (I made a sensor mod for EvoGUI that outputs tile info) I couldn't see any obvious correlation between temperature, moisture, etc., and the resulting tile produced by the map generator. Even altitude seemed abstract when looking at the generated tiles.

As for the deprecated thing you found, yes report it, always good to improve cleanliness of code.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

Post Reply

Return to “Modding help”