docs/importing_town_data.md
To aid players in scenario creation, OpenTTD's Scenario Editor can import town data from external JSON files. This enables players to use an image editing program to align town coordinates with a real-world heightmap using a map underlay, instead of guessing at the correct locations in Scenario Editor itself.
This town data consists of a JSON file storing an array of town data objects, each containing a name, location, target OpenTTD population, and whether it is marked as a city in the game.
This document describes the standard format for this JSON file and outlines a workflow for creating this data effectively.
There are three benefits to using an image editing program to create towns instead of the OpenTTD Scenario Editor.
Town data is a text file in the JSON format, with a list of towns, each containing a coordinate location and properties: name, population, and whether or not it should be a city in OpenTTD.
The format of this file is standardized for importing into OpenTTD and must be followed for OpenTTD to properly parse the data.
For use in OpenTTD, you will also need a matching heightmap of the terrain features, as a PNG.
The following code sample is complete and can be used in OpenTTD.
[]{}, with a comma after each town except for the last in the list."" with a colon : separating it from the property value."London", while all other property values 44910, true, etc., are not.[
{
"name": "London",
"population": 44910,
"city": true,
"x": 0.7998046875,
"y": 0.708984375
},
{
"name": "Canterbury",
"population": 217.16,
"city": false,
"x": 0.83251953125,
"y": 0.828125
}
]
726, 1638 in a 1024 px by 2048 px heightmap, so 726 / 1024 = 0.7998046875 and 1638 / 2048 = 0.708984375 gives the correct coordinates for OpenTTD.Using geodata to create a real-world location in OpenTTD is done in the Scenario Editor.
Load from file and choose the .json file containing town data. The default directory to search for town data is OpenTTD\scenario\heightmap.Sometimes it's not possible to place a town, such as when the heightmap is very rough and a flat tile can't be found with a 16-tile radius of the target tile. In such cases, a sign will be placed on the target tile with the name of the town. The player can then place the town manually or change the heightmap settings and try again. This fallback also helps debug errors with data creation, such as if towns end up in the ocean.
x / maximum_x and y / maximum_y, as described in "Town data values" above.OpenTTD\scenario\heightmap folder.