Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Written by TOGoS for Factorio 0.17

Creating a map from custom settings

Sometimes it's useful to create a new game with map and/or map generator settings stored in a JSON file rather than going through the in-game map settings screen. One reason is that by editing the settings directly you can get settings outside the range normally available from the GUI.

To do this you'll need to be able to run Factorio from the command-line, a JSON file containing your map generator settings (if customizing them), and/or a JSON file containing map settings (again, if you want to customize them).

For example, let's make a map using these custom generator settings:

{
    "terrain_segmentation": 0.5,
    "water": "2",
    "width": 0,
    "height": 0,
    "starting_area": "normal",
    "peaceful_mode": false,
    "autoplace_controls":
    {
        "coal": {"frequency": 1, "size": 2, "richness": 0.5},
        "copper-ore": {"frequency": "low", "size": "normal", "richness": "high"},
        "crude-oil": {"frequency": "normal", "size": "normal", "richness": "normal"},
        "enemy-base": {"frequency": "normal", "size": "normal", "richness": "normal"},
        "iron-ore": {"frequency": "normal", "size": "normal", "richness": "normal"},
        "stone": {"frequency": "normal", "size": 0, "richness": "normal"},
        "uranium-ore": {"frequency": "normal", "size": "none", "richness": "normal"}
    },

    "cliff_settings":
    {
        "name": "cliff",                
        "cliff_elevation_0": 30,        
        "cliff_elevation_interval": 20, 
        "richness": 1                   
    },

    "property_expression_names":
    {
        "elevation": "0_16-elevation",
        "temperature": "35"
    },
    
    "seed": null
}

Note that this is the same format as MapGenSettings that are modifiable from Lua.

Everything in the file is optional. If unspecified, autoplace controls will default to "normal" (i.e. 1) frequency, size, and richness. Tile property generators will default to a NamedNoiseExpression with the same name as the property. If seed is unspecified, it will be random (though you can override whatever seed is in this file on the command-line to --create).

Creating custom saves

You can save that file anywhere you want, but to make the command shorter I'm going to put it in the save directory, which for me is C:/Users/TOGoS/AppData/Roaming/factorio/saves. I'll call it "stuff.map-gen-settings.json".

Now run Factorio with --create <path-to-save> to create a new save file, and passing --map-gen-settings <path-to-map-gen-settings-json-file> to indicate your generator settings. We'll also pass a --map-gen-seed to show that it can be done. This assumes a certain path to your Factorio executable; if you installed Factorio in a different place, adjust it.

C:
cd \Users\TOGoS\AppData\Roaming\factorio\saves
"C:\Program Files\Factorio\bin\x64\Factorio.exe" --create stuff-seed123.zip --map-gen-settings stuff.map-gen-settings.json --map-gen-seed 123

If all goes well you'll have a new save file, which you can load up in the game.

Generating map previews

If you want to play around with generator settings without having to launch the game, you can generate map previews with --generate-map-preview.

"C:\Program Files\Factorio\bin\x64\Factorio.exe" --generate-map-preview stuff-seed123.png --map-gen-settings stuff.map-gen-settings.json --map-gen-seed 123

--generate-map-preview allows you to generate previews of any size, at any scale, at any position on the map by indicating --map-preview-size <width-in-pixels>, --map-preview-scale <tiles-per-pixel>, and --map-preview-offset <x>,<y>, respectively. It can also do slope shading (I like to use --slope-shading=0.3) and reporting on estimated quantities of resources in the mapped area (e.g. --report-quantities=iron-ore,copper-ore. Run Factorio with --help for more information on those options.

@TOGoS

This comment has been minimized.

Copy link

commented Feb 15, 2019

The MapGenSettings listed above uses some 0.17 features:

  • Numeric sizes for terrain_segmentation, water, and some autoplace controls
  • Reference to the 0_16-elevation noise expression (in 0.16 it's just called "default-elevation")
  • Using "35" as a noise expression name

This example will work with 0.16:

{
    "terrain_segmentation": "low",
    "water": "very-high",
    "width": 0,
    "height": 0,
    "starting_area": "normal",
    "peaceful_mode": false,
    "autoplace_controls":
    {
        "coal": {"frequency": "normal", "size": "very-high", "richness": "very-low"},
        "copper-ore": {"frequency": "low", "size": "normal", "richness": "high"},
        "crude-oil": {"frequency": "normal", "size": "normal", "richness": "normal"},
        "enemy-base": {"frequency": "normal", "size": "normal", "richness": "normal"},
        "iron-ore": {"frequency": "normal", "size": "normal", "richness": "normal"},
        "stone": {"frequency": "normal", "size": "none", "richness": "normal"},
        "uranium-ore": {"frequency": "normal", "size": "none", "richness": "normal"}
    },

    "cliff_settings":
    {
        "name": "cliff",                
        "cliff_elevation_0": 30,        
        "cliff_elevation_interval": 20, 
        "richness": 1                   
    },

    "property_expression_names":
    {
        "elevation": "large-seas-elevation"
    },
    
    "seed": null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.