New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Import real-world town data via JSON file #10409
base: master
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
For scenario creators this is a really great feature. :) Thanks to this, the scenario of the map of Poland, the Visegrad group (Poland, Czech Republic, Slovakia, Hungary) and Europe, which used to be also on the server, was created. The first scenario already had a lot of updates, including changes to industries sets and scripts, which required the map to be regenerated from scratch. Without this feature, it would hardly make sense. Here I would like to point out that a version of the game was used to generate the map (added the aforementioned McZapkie's repeatable map generation tools) which also allowed importing rivers, objects (stone and transmitters as borders) and enterprises - features that would be equally useful. I admit that although I helped a lot in refining these maps, I've never used this version of the game (needs to be compiled) and I don't know exactly how it works. I know that rivers and objects can be imported from an image file and all functions are only available from the console level so it's not very convenient for the average user.
I think definitely yes, but maybe it would be worth adding a new format?
In the case of the Map and the Scenario, it would be good if it was possible to export individual layers to graphic files (water, trees, etc.) or text files (cities, enterprises) The ability to use more layers could be added gradually. Although I write this as a theoretician, it seems to me that the most important thing is to define the framework of the basis on which all this could be based. For the future: When it comes to rivers and lakes, it took me over 30 hours to refine them on the Visegrad map. I think being able to save this layer, outside of cities, would be most helpful.
I'm not sure if it's worth changing it any more significantly - I wrote a bit more here #10287. :) |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
do { | ||
Command<CMD_EXPAND_TOWN>::Post(t->index, 0); | ||
if (tries-- == 0) break; | ||
} while (t->cache.population < town.population); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit weird .. only 500 tries? Why not 500 failures? Feels a bit random, 500.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not 500 tries? This is to expand the town to the target population specified by the player in the JSON file, so we need some way to break out of the do/while loop in case their target population is not reachable. (Which is extremely likely, since some players will inevitably try to match real-world city populations of 1M+, which doesn't work in OpenTTD...)
Alternate suggestions welcome. 馃槂
@@ -42,6 +42,7 @@ static const char * const _subdirs[] = { | |||
"save" PATHSEP "autosave" PATHSEP, | |||
"scenario" PATHSEP, | |||
"scenario" PATHSEP "heightmap" PATHSEP, | |||
"scenario" PATHSEP "towndata" PATHSEP, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as a FYI, if you want to be able to load heightmaps + towndata, they can't be in different folders. How the content system works, is that 1 content piece needs everything in a single folder.
But I also like your idea of having this for SE-only, that people need to load towndata on top of their scenario / heightmap. But just the headsup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks for noting this. Something to consider as we move forward with this and consider bundling town data with heightmaps or other info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not who this affects considerations, but I would think that town placement data is only useful for a specific heightmap. A scenario can be considered a heightmap and town data pre-combined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My rationale for doing towns and heightmaps separately instead of bundling them in a .tar or similar, is that the heightmap import often doesn't go perfectly the first try. The max height is wrong, or some coasts need cleanup, etc. Loading towns takes a lot of time, so it would be frustrating to force them to happen simultaniously.
For now, this format is for scenario creators, not a full "reproducible scenario" format for use by the average player.
That still doesn't answer the question of where to put the files. I guess we could always move them later.
87bbe0b
to
0cea5d4
Compare
5ed5625
to
a5c3662
Compare
@@ -42,6 +42,7 @@ static const char * const _subdirs[] = { | |||
"save" PATHSEP "autosave" PATHSEP, | |||
"scenario" PATHSEP, | |||
"scenario" PATHSEP "heightmap" PATHSEP, | |||
"scenario" PATHSEP "towndata" PATHSEP, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not who this affects considerations, but I would think that town placement data is only useful for a specific heightmap. A scenario can be considered a heightmap and town data pre-combined.
|
||
/* Add a trailing \0 to mark the end of the string */ | ||
text = ReallocT(text, filesize + 1); | ||
text[filesize] = '\0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure you should be able to read directly into a std::string (resized to filesize), instead of affing with C-style memory allocation and null-termination.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I just can't figure out how... 馃槙
Updated and rebased. There are still outstanding review comments which I need help with. |
Motivation / Problem
Creating real-world scenarios in Scenario Editor is slow and time-consuming.
Description
Read the documentation!
The Town Generation GUI in Scenario Editor now lets you load towns from a JSON file, each containing the town's name, location, target OpenTTD population, and whether it is marked as a city in the game.
The intended way of generating this information is in an image editor, with the accompanying heightmap and a labeled map aligned with each other in different layers. The pixel coordinates of the town become (with some easy conversion) the tile coordinates of the town in OpenTTD.
The benefits of this approach are:
This standardized format is an API which allows future tools to generate this data and feed it to OpenTTD.
You can download a sample heightmap and town data set from the .zip below. The heightmap is placed as usual in
OpenTTD\scenario\heightmap
and the town data goes inOpenTTD\scenario\towndata
(which should be created automatically).example_data.zip
To Do
For a later PR
Planned for separate PRs
A few notes on my future plans to head off concerns or scope creep suggestions. 馃槈
Questions
.tar
)? I want to consider compatibility with future data layers like trees and desert (not objects though, that's a manual-only tool). I would need help with this. 馃檪Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.