OpenTTD Source 20250205-master-gfd85ab1e2c
genworld.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#include "stdafx.h"
11#include "landscape.h"
12#include "company_func.h"
13#include "town_cmd.h"
14#include "signs_cmd.h"
15#include "3rdparty/nlohmann/json.hpp"
16#include "strings_func.h"
17#include "genworld.h"
18#include "gfxinit.h"
19#include "window_func.h"
20#include "network/network.h"
21#include "heightmap.h"
22#include "viewport_func.h"
25#include "engine_func.h"
26#include "water.h"
28#include "tilehighlight_func.h"
29#include "saveload/saveload.h"
30#include "void_map.h"
31#include "town.h"
32#include "newgrf.h"
33#include "newgrf_house.h"
34#include "core/random_func.hpp"
35#include "core/backup_type.hpp"
36#include "progress.h"
37#include "error.h"
38#include "game/game.hpp"
40#include "newgrf_railtype.h"
41#include "newgrf_roadtype.h"
42#include "string_func.h"
43#include "thread.h"
44#include "tgp.h"
45
46#include "safeguards.h"
47
48
49void GenerateClearTile();
51void GenerateObjects();
52void GenerateTrees();
53
54void StartupEconomy();
55void StartupCompanies();
56void StartupDisasters();
57
58void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings);
59
67
70
72
76static void CleanupGeneration()
77{
78 _generating_world = false;
79
80 SetMouseCursorBusy(false);
81 SetModalProgress(false);
82 _gw.proc = nullptr;
83 _gw.abortp = nullptr;
84
88}
89
93static void _GenerateWorld()
94{
95 /* Make sure everything is done via OWNER_NONE. */
97
98 try {
99 _generating_world = true;
100 if (_network_dedicated) Debug(net, 3, "Generating map, please wait...");
101 /* Set the Random() seed to generation_seed so we produce the same map with the same seed */
104 SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0);
105 ScriptObject::InitializeRandomizers();
106
108
110 /* Must start economy early because of the costs. */
111 StartupEconomy();
112 if (!CheckTownRoadTypes()) {
114 return;
115 }
116
117 bool landscape_generated = false;
118
119 /* Don't generate landscape items when in the scenario editor. */
120 if (_gw.mode != GWM_EMPTY) {
121 landscape_generated = GenerateLandscape(_gw.mode);
122 }
123
124 if (!landscape_generated) {
126
127 /* Make sure the tiles at the north border are void tiles if needed. */
129 for (uint x = 0; x < Map::SizeX(); x++) MakeVoid(TileXY(x, 0));
130 for (uint y = 0; y < Map::SizeY(); y++) MakeVoid(TileXY(0, y));
131 }
132
133 /* Make the map the height of the setting */
135
136 ConvertGroundTilesIntoWaterTiles();
138
140 } else {
141 GenerateClearTile();
142
143 /* Only generate towns, tree and industries in newgame mode. */
144 if (_game_mode != GM_EDITOR) {
147 return;
148 }
150 GenerateObjects();
152 }
153 }
154
155 /* These are probably pointless when inside the scenario editor. */
161 StartupDisasters();
162 _generating_world = false;
163
164 /* No need to run the tile loop in the scenario editor. */
165 if (_gw.mode != GWM_EMPTY) {
166 uint i;
167
169 for (i = 0; i < 0x500; i++) {
170 RunTileLoop();
173 }
174
175 if (_game_mode != GM_EDITOR) {
177
178 if (Game::GetInstance() != nullptr) {
180 _generating_world = true;
181 for (i = 0; i < 2500; i++) {
184 if (Game::GetInstance()->IsSleeping()) break;
185 }
186 _generating_world = false;
187 }
188 }
189 }
190
192
194 _cur_company.Trash();
196 /* Show all vital windows again, because we have hidden them. */
197 if (_game_mode != GM_MENU) ShowVitalWindows();
198
200 /* Call any callback */
201 if (_gw.proc != nullptr) _gw.proc();
203
205
207
208 if (_network_dedicated) Debug(net, 3, "Map generated, starting game");
209 Debug(desync, 1, "new_map: {:08x}", _settings_game.game_creation.generation_seed);
210
211 if (_debug_desync_level > 0) {
212 std::string name = fmt::format("dmp_cmds_{:08x}_{:08x}.sav", _settings_game.game_creation.generation_seed, TimerGameEconomy::date);
214 }
215 } catch (AbortGenerateWorldSignal&) {
217
219 if (_cur_company.IsValid()) _cur_company.Restore();
220
221 if (_network_dedicated) {
222 /* Exit the game to prevent a return to main menu. */
223 Debug(net, 0, "Generating map failed; closing server");
224 _exit_game = true;
225 } else {
226 SwitchToMode(_switch_mode);
227 }
228 }
229}
230
237{
238 _gw.proc = proc;
239}
240
247{
248 _gw.abortp = proc;
249}
250
255{
256 _gw.abort = true;
257}
258
264{
265 return _gw.abort || _exit_game;
266}
267
272{
273 /* Clean up - in SE create an empty map, otherwise, go to intro menu */
274 _switch_mode = (_game_mode == GM_EDITOR) ? SM_EDITOR : SM_MENU;
275
276 if (_gw.abortp != nullptr) _gw.abortp();
277
279}
280
288void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings)
289{
290 if (HasModalProgress()) return;
291 _gw.mode = mode;
292 _gw.size_x = size_x;
293 _gw.size_y = size_y;
294 SetModalProgress(true);
295 _gw.abort = false;
296 _gw.abortp = nullptr;
298
299 /* This disables some commands and stuff */
301
302 InitializeGame(_gw.size_x, _gw.size_y, true, reset_settings);
304
306 uint estimated_height = 0;
307
308 if (_gw.mode == GWM_EMPTY && _game_mode != GM_MENU) {
310 } else if (_gw.mode == GWM_HEIGHTMAP) {
313 estimated_height = GetEstimationTGPMapHeight();
314 } else {
315 estimated_height = 0;
316 }
317
319 }
320
322
323 /* Load the right landscape stuff, and the NewGRFs! */
329
330 /* Re-init the windowing system */
332
333 /* Create toolbars */
335 SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0);
336
340
342
343 /* Centre the view on the map */
345
347}
348
351 TownID town_id;
352 std::string name;
354 bool is_city;
357};
358
365static bool TryFoundTownNearby(TileIndex tile, void *user_data)
366{
367 ExternalTownData &town = *static_cast<ExternalTownData *>(user_data);
368 std::tuple<CommandCost, Money, TownID> result = Command<CMD_FOUND_TOWN>::Do(DC_EXEC, tile, TSZ_SMALL, town.is_city, _settings_game.economy.town_layout, false, 0, town.name);
369
370 TownID id = std::get<TownID>(result);
371
372 /* Check if the command failed. */
373 if (id == INVALID_TOWN) return false;
374
375 /* The command succeeded, send the ID back through user_data. */
376 town.town_id = id;
377 return true;
378}
379
384{
385 /* Load the JSON file as a string initially. We'll parse it soon. */
386 size_t filesize;
387 auto f = FioFOpenFile(_file_to_saveload.name, "rb", HEIGHTMAP_DIR, &filesize);
388
389 if (!f.has_value()) {
390 ShowErrorMessage(STR_TOWN_DATA_ERROR_LOAD_FAILED, STR_TOWN_DATA_ERROR_JSON_FORMATTED_INCORRECTLY, WL_ERROR);
391 return;
392 }
393
394 std::string text(filesize, '\0');
395 size_t len = fread(text.data(), filesize, 1, *f);
396 f.reset();
397 if (len != 1) {
398 ShowErrorMessage(STR_TOWN_DATA_ERROR_LOAD_FAILED, STR_TOWN_DATA_ERROR_JSON_FORMATTED_INCORRECTLY, WL_ERROR);
399 return;
400 }
401
402 /* Now parse the JSON. */
403 nlohmann::json town_data;
404 try {
405 town_data = nlohmann::json::parse(text);
406 } catch (nlohmann::json::exception &) {
407 ShowErrorMessage(STR_TOWN_DATA_ERROR_LOAD_FAILED, STR_TOWN_DATA_ERROR_JSON_FORMATTED_INCORRECTLY, WL_ERROR);
408 return;
409 }
410
411 /* Check for JSON formatting errors with the array of towns. */
412 if (!town_data.is_array()) {
413 ShowErrorMessage(STR_TOWN_DATA_ERROR_LOAD_FAILED, STR_TOWN_DATA_ERROR_JSON_FORMATTED_INCORRECTLY, WL_ERROR);
414 return;
415 }
416
417 std::vector<std::pair<Town *, uint> > towns;
418 uint failed_towns = 0;
419
420 /* Iterate through towns and attempt to found them. */
421 for (auto &feature : town_data) {
422 ExternalTownData town;
423
424 /* Ensure JSON is formatted properly. */
425 if (!feature.is_object()) {
426 ShowErrorMessage(STR_TOWN_DATA_ERROR_LOAD_FAILED, STR_TOWN_DATA_ERROR_JSON_FORMATTED_INCORRECTLY, WL_ERROR);
427 return;
428 }
429
430 /* Check to ensure all fields exist and are of the correct type.
431 * If the town name is formatted wrong, all we can do is give a general warning. */
432 if (!feature.contains("name") || !feature.at("name").is_string()) {
433 ShowErrorMessage(STR_TOWN_DATA_ERROR_LOAD_FAILED, STR_TOWN_DATA_ERROR_JSON_FORMATTED_INCORRECTLY, WL_ERROR);
434 return;
435 }
436
437 /* If other fields are formatted wrong, we can actually inform the player which town is the problem. */
438 if (!feature.contains("population") || !feature.at("population").is_number() ||
439 !feature.contains("city") || !feature.at("city").is_boolean() ||
440 !feature.contains("x") || !feature.at("x").is_number() ||
441 !feature.contains("y") || !feature.at("y").is_number()) {
442 feature.at("name").get_to(town.name);
443 SetDParamStr(0, town.name);
444 ShowErrorMessage(STR_TOWN_DATA_ERROR_LOAD_FAILED, STR_TOWN_DATA_ERROR_TOWN_FORMATTED_INCORRECTLY, WL_ERROR);
445 return;
446 }
447
448 /* Set town properties. */
449 feature.at("name").get_to(town.name);
450 feature.at("population").get_to(town.population);
451 feature.at("city").get_to(town.is_city);
452
453 /* Set town coordinates. */
454 feature.at("x").get_to(town.x_proportion);
455 feature.at("y").get_to(town.y_proportion);
456
457 /* Check for improper coordinates and warn the player. */
458 if (town.x_proportion <= 0.0f || town.y_proportion <= 0.0f || town.x_proportion >= 1.0f || town.y_proportion >= 1.0f) {
459 SetDParamStr(0, town.name);
460 ShowErrorMessage(STR_TOWN_DATA_ERROR_LOAD_FAILED, STR_TOWN_DATA_ERROR_BAD_COORDINATE, WL_ERROR);
461 return;
462 }
463
464 /* Find the target tile for the town. */
465 TileIndex tile;
467 case HM_CLOCKWISE:
468 /* Tile coordinates align with what we expect. */
469 tile = TileXY(town.x_proportion * Map::MaxX(), town.y_proportion * Map::MaxY());
470 break;
472 /* Tile coordinates are rotated and must be adjusted. */
473 tile = TileXY((1 - town.y_proportion * Map::MaxX()), town.x_proportion * Map::MaxY());
474 break;
475 default: NOT_REACHED();
476 }
477
478 /* Try founding on the target tile, and if that doesn't work, find the nearest suitable tile up to 16 tiles away.
479 * The target might be on water, blocked somehow, or on a steep slope that can't be terraformed by the founding command. */
480 TileIndex search_tile = tile;
481 bool success = CircularTileSearch(&search_tile, 16, 0, 0, TryFoundTownNearby, &town);
482
483 /* If we still fail to found the town, we'll create a sign at the intended location and tell the player how many towns we failed to create in an error message.
484 * This allows the player to diagnose a heightmap misalignment, if towns end up in the sea, or place towns manually, if in rough terrain. */
485 if (!success) {
487 failed_towns++;
488 continue;
489 }
490
491 towns.emplace_back(std::make_pair(Town::Get(town.town_id), town.population));
492 }
493
494 /* If we couldn't found a town (or multiple), display a message to the player with the number of failed towns. */
495 if (failed_towns > 0) {
496 SetDParam(0, failed_towns);
497 ShowErrorMessage(STR_TOWN_DATA_ERROR_FAILED_TO_FOUND_TOWN, INVALID_STRING_ID, WL_WARNING);
498 }
499
500 /* Now that we've created the towns, let's grow them to their target populations. */
501 for (const auto &item : towns) {
502 Town *t = item.first;
503 uint population = item.second;
504
505 /* Grid towns can grow almost forever, but the town growth algorithm gets less and less efficient as it wanders roads randomly,
506 * so we set an arbitrary limit. With a flat map and a 3x3 grid layout this results in about 4900 houses, or 2800 houses with "Better roads." */
507 int try_limit = 1000;
508
509 /* If a town repeatedly fails to grow, continuing to try only wastes time. */
510 int fail_limit = 10;
511
512 /* Grow by a constant number of houses each time, instead of growth based on current town size.
513 * We want our try limit to apply in a predictable way, no matter the road layout and other geography. */
514 const int HOUSES_TO_GROW = 10;
515
516 do {
517 uint before = t->cache.num_houses;
518 Command<CMD_EXPAND_TOWN>::Post(t->index, HOUSES_TO_GROW);
519 if (t->cache.num_houses <= before) fail_limit--;
520 } while (fail_limit > 0 && try_limit-- > 0 && t->cache.population < population);
521 }
522}
Class for backupping variables and making sure they are restored later.
static void StartNew()
Start up a new GameScript.
Definition game_core.cpp:72
static class GameInstance * GetInstance()
Get the current active instance.
Definition game.hpp:101
static void GameLoop()
Called every game-tick to let Game do something.
Definition game_core.cpp:31
static Date date
Current date in days (day counter).
static TickCounter counter
Monotonic counter, in ticks, since start of game.
@ DC_EXEC
execute the given command
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
void SetLocalCompany(CompanyID new_company)
Sets the local company and updates the settings that are set on a per-company basis to reflect the co...
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
@ COMPANY_SPECTATOR
The client is spectating.
@ OWNER_NONE
The tile has no ownership.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition debug.h:37
void StartupEngines()
Start/initialise all our engines.
Definition engine.cpp:799
Functions related to engines.
Functions related to errors.
void UnshowCriticalError()
Unshow the critical error.
@ WL_WARNING
Other information.
Definition error.h:25
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition error.h:26
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
void ShowFirstError()
Show the first error of the queue.
std::optional< FileHandle > FioFOpenFile(const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
Definition fileio.cpp:243
@ SLO_SAVE
File is being saved.
Definition fileio_type.h:56
@ DFT_GAME_FILE
Save game or scenario file.
Definition fileio_type.h:32
@ HEIGHTMAP_DIR
Subdirectory of scenario for heightmaps.
@ AUTOSAVE_DIR
Subdirectory of save for autosaves.
Base functions for all Games.
The GameInstance tracks games.
bool _generating_world
Whether we are generating the map or not.
Definition genworld.cpp:69
void GenerateWorldSetCallback(GWDoneProc *proc)
Set here the function, if any, that you want to be called when landscape generation is done.
Definition genworld.cpp:236
void GenerateWorldSetAbortCallback(GWAbortProc *proc)
Set here the function, if any, that you want to be called when landscape generation is aborted.
Definition genworld.cpp:246
void HandleGeneratingWorldAbortion()
Really handle the abortion, i.e.
Definition genworld.cpp:271
GenWorldInfo _gw
Please only use this variable in genworld.h and genworld.cpp and nowhere else.
Definition genworld.cpp:66
void GenerateTrees()
Place new trees.
Definition tree_cmd.cpp:357
static void _GenerateWorld()
The internal, real, generate function.
Definition genworld.cpp:93
static bool TryFoundTownNearby(TileIndex tile, void *user_data)
Helper for CircularTileSearch to found a town on or near a given tile.
Definition genworld.cpp:365
void GenerateIndustries()
This function will create random industries during game creation.
static void CleanupGeneration()
Generation is done; show windows again and delete the progress window.
Definition genworld.cpp:76
void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings)
Generate a world.
Definition genworld.cpp:288
void AbortGeneratingWorld()
Initializes the abortion process.
Definition genworld.cpp:254
bool IsGeneratingWorldAborted()
Is the generation being aborted?
Definition genworld.cpp:263
void LoadTownData()
Load town data from _file_to_saveload, place towns at the appropriate locations, and expand them to t...
Definition genworld.cpp:383
void StartupCompanies()
Start of a new game.
Functions related to world/map generation.
void GWAbortProc()
Called when genworld is aborted.
Definition genworld.h:58
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
static const uint MAP_HEIGHT_LIMIT_AUTO_MINIMUM
When map height limit is auto, make this the lowest possible map height limit.
Definition genworld.h:54
@ LG_TERRAGENESIS
TerraGenesis Perlin landscape generator.
Definition genworld.h:22
void ShowGenerateWorldProgress()
Show the window where a user can follow the process of the map generation.
@ GWP_OBJECT
Generate objects (radio tower, light houses)
Definition genworld.h:79
@ GWP_MAP_INIT
Initialize/allocate the map, start economy.
Definition genworld.h:73
@ GWP_RUNSCRIPT
Runs the game script at most 2500 times, or when ever the script sleeps.
Definition genworld.h:83
@ GWP_GAME_START
Really prepare to start the game.
Definition genworld.h:84
@ GWP_GAME_INIT
Initialize the game.
Definition genworld.h:81
@ GWP_RUNTILELOOP
Runs the tile loop 1280 times to make snow etc.
Definition genworld.h:82
void GWDoneProc()
Procedure called when the genworld process finishes.
Definition genworld.h:57
static const uint MAP_HEIGHT_LIMIT_AUTO_CEILING_ROOM
When map height limit is auto, the map height limit will be the higest peak plus this value.
Definition genworld.h:55
static const uint32_t GENERATE_NEW_SEED
Create a new random seed.
Definition genworld.h:25
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
void PrepareGenerateWorldProgress()
Initializes the progress counters to the starting point.
GenWorldMode
Modes for GenerateWorld.
Definition genworld.h:28
@ GWM_HEIGHTMAP
Generate a newgame from a heightmap.
Definition genworld.h:32
@ GWM_EMPTY
Generate an empty map (sea-level)
Definition genworld.h:30
void SetMouseCursorBusy(bool busy)
Set or unset the ZZZ cursor.
Definition gfx.cpp:1670
void LoadStringWidthTable(bool monospace)
Initialize _stringwidth_table cache.
Definition gfx.cpp:1210
SwitchMode _switch_mode
The next mainloop command.
Definition gfx.cpp:49
void GfxLoadSprites()
Initialise and load all the sprites.
Definition gfxinit.cpp:336
Functions related to the graphics initialization.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1529
void FlatEmptyWorld(uint8_t tile_height)
Make an empty world where all tiles are of height 'tile_height'.
Functions related to creating heightmaps from files.
@ HM_CLOCKWISE
Rotate the map clockwise 45 degrees.
Definition heightmap.h:21
@ HM_COUNTER_CLOCKWISE
Rotate the map counter clockwise 45 degrees.
Definition heightmap.h:20
void RunTileLoop()
Gradually iterate over all tiles on the map, calling their TileLoopProcs once every TILE_UPDATE_FREQU...
bool GenerateLandscape(uint8_t mode)
Functions related to OTTD's landscape.
void ShowVitalWindows()
Show the vital in-game windows.
Definition main_gui.cpp:575
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows.
Definition main_gui.cpp:546
bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
Function performing a search around a center tile and going outward, thus in circle.
Definition map.cpp:244
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition map_func.h:373
bool _network_dedicated
are we a dedicated server?
Definition network.cpp:68
Basic functions/variables used all over the place.
Base for the NewGRF implementation.
void ShowNewGRFError()
Show the first NewGRF error we can find.
void InitializeBuildingCounts()
Initialise global building counts and all town building counts.
Functions related to NewGRF houses.
void SetCurrentRailTypeLabelList()
Populate railtype label list with current values.
NewGRF handling of rail types.
void SetCurrentRoadTypeLabelList()
Populate road type label list with current values.
NewGRF handling of road types.
@ PSM_ENTER_GAMELOOP
Enter the gameloop, changes will be permanent.
@ PSM_LEAVE_GAMELOOP
Leave the gameloop, changes will be temporary.
@ SM_MENU
Switch to game intro menu.
Definition openttd.h:33
@ SM_EDITOR
Switch to scenario editor.
Definition openttd.h:31
void SetModalProgress(bool state)
Set the modal progress state.
Definition progress.cpp:22
Functions related to modal progress.
bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition progress.h:17
Randomizer _random
Random used in the game state calculations.
Pseudo random number generator.
A number of safeguards to prevent using unsafe methods.
SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded)
Main Save or Load function where the high-level saveload functions are handled.
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition saveload.cpp:63
Functions/types related to saving and loading games.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:57
Command definitions related to signs.
Definition of base types and functions in a cross-platform compatible way.
Functions related to low-level strings.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition strings.cpp:104
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition strings.cpp:370
Functions related to OTTD's strings.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Class to backup a specific variable and restore it later.
bool IsValid() const
Checks whether the variable was already restored.
void Trash()
Trash the backup.
void Restore()
Restore the variable.
static void SwitchMode(PersistentStorageMode mode, bool ignore_prev_mode=false)
Clear temporary changes made since the last call to SwitchMode, and set whether subsequent changes sh...
bool freeform_edges
allow terraforming the tiles at the map edges
uint8_t map_height_limit
the maximum allowed heightlevel
TownLayout town_layout
select town layout,
Town data imported from JSON files and used to place towns.
Definition genworld.cpp:350
std::string name
The name of the town.
Definition genworld.cpp:352
bool is_city
Should it be created as a city in OpenTTD? If input is blank, defaults to false.
Definition genworld.cpp:354
uint population
The target population of the town when created in OpenTTD. If input is blank, defaults to 0.
Definition genworld.cpp:353
float x_proportion
The X coordinate of the town, as a proportion 0..1 of the maximum X coordinate.
Definition genworld.cpp:355
TownID town_id
The TownID of the town in OpenTTD. Not imported, but set during the founding proceess and stored here...
Definition genworld.cpp:351
float y_proportion
The Y coordinate of the town, as a proportion 0..1 of the maximum Y coordinate.
Definition genworld.cpp:356
std::string name
Name of the file.
Definition saveload.h:415
uint8_t snow_line_height
the configured snow line height (deduced from "snow_coverage")
uint8_t land_generator
the landscape generator
uint8_t se_flat_world_height
land height a flat world gets in SE
uint8_t heightmap_rotation
rotation director for the heightmap
uint32_t generation_seed
noise seed for world generation
uint8_t heightmap_height
highest mountain for heightmap (towards what it scales)
EconomySettings economy
settings to change the economy
ConstructionSettings construction
construction of things in-game
GameCreationSettings game_creation
settings used during the creation of a game (map)
Properties of current genworld process.
Definition genworld.h:61
GWDoneProc * proc
Proc that is called when done (can be nullptr)
Definition genworld.h:67
CompanyID lc
The local_company before generating.
Definition genworld.h:64
uint size_x
X-size of the map.
Definition genworld.h:65
uint size_y
Y-size of the map.
Definition genworld.h:66
bool abort
Whether to abort the thread ASAP.
Definition genworld.h:62
GWAbortProc * abortp
Proc that is called when aborting (can be nullptr)
Definition genworld.h:68
GenWorldMode mode
What mode are we making a world in.
Definition genworld.h:63
static uint SizeY()
Get the size of the map along the Y.
Definition map_func.h:279
static debug_inline uint SizeX()
Get the size of the map along the X.
Definition map_func.h:270
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition map_func.h:306
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition map_func.h:297
Tindex index
Index of this pool item.
static Titem * Get(size_t index)
Returns Titem with given index.
void SetSeed(uint32_t seed)
(Re)set the state of the random number generator.
uint32_t population
Current population of people.
Definition town.h:42
uint32_t num_houses
Amount of houses.
Definition town.h:41
Town data structure.
Definition town.h:52
TownCache cache
Container for all cacheable data.
Definition town.h:55
uint GetEstimationTGPMapHeight()
Get an overestimation of the highest peak TGP wants to generate.
Definition tgp.cpp:259
Functions for the Perlin noise enhanced map generator.
Base of all threads.
static const uint DEF_SNOWLINE_HEIGHT
Default snowline height.
Definition tile_type.h:33
static const uint MAX_MAP_HEIGHT_LIMIT
Upper bound of maximum allowed heightlevel (in the construction settings)
Definition tile_type.h:30
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void SetObjectToPlace(CursorID icon, PaletteID pal, HighLightStyle mode, WindowClass window_class, WindowNumber window_num)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
@ HT_NONE
default
Definition of the game-calendar-timer.
Definition of the tick-based game-timer.
Base of the town class.
bool CheckTownRoadTypes()
Check if towns are able to build road.
bool GenerateTowns(TownLayout layout)
Generate a number of towns with a given layout.
Command definitions related to towns.
@ TSZ_SMALL
Small town.
Definition town_type.h:22
Base of all video drivers.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to (drawing on) viewports.
Map accessors for void tiles.
void MakeVoid(Tile t)
Make a nice void tile ;)
Definition void_map.h:19
Functions related to water (management)
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1149
void ResetWindowSystem()
Reset the windowing system, by means of shutting it down followed by re-initialization.
Definition window.cpp:1815
void HideVitalWindows()
Close all always on-top windows to get an empty screen.
Definition window.cpp:3316
void CloseAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
Definition window.cpp:3278
Window functions not directly related to making/drawing windows.
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition window_type.h:53
@ WC_MODAL_PROGRESS
Progress report of landscape generation; Window numbers: