OpenTTD Source 20261112-master-gbcbec5e63f
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
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"
24#include "engine_func.h"
25#include "water.h"
26#include "tilehighlight_func.h"
28#include "void_map.h"
29#include "town.h"
30#include "newgrf.h"
31#include "newgrf_house.h"
32#include "core/random_func.hpp"
33#include "core/backup_type.hpp"
34#include "progress.h"
35#include "error.h"
36#include "game/game.hpp"
38#include "newgrf_railtype.h"
39#include "newgrf_roadtype.h"
40#include "tgp.h"
41
42#include "table/strings.h"
43
44#include "safeguards.h"
45
46
49void GenerateObjects();
50void GenerateTrees();
51
52void StartupEconomy();
53void StartupCompanies();
54void StartupDisasters();
55
56void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings);
57
60 static inline bool abort;
61 static inline GenWorldMode mode;
62 static inline CompanyID lc;
63 static inline uint size_x;
64 static inline uint size_y;
65 static inline GWDoneProc *proc;
66 static inline GWAbortProc *abortp;
67};
68
71
73
77static void CleanupGeneration()
78{
79 _generating_world = false;
80
81 SetMouseCursorBusy(false);
82 SetModalProgress(false);
83 GenWorldInfo::proc = nullptr;
84 GenWorldInfo::abortp = nullptr;
85
86 CloseWindowByClass(WindowClass::ModalProgress);
89}
90
94static void _GenerateWorld()
95{
96 /* Make sure everything is done via OWNER_NONE. */
98
99 try {
100 _generating_world = true;
101 if (_network_dedicated) Debug(Facility::Net, Severity::Notice, "Generating map, please wait...");
102 /* Set the Random() seed to generation_seed so we produce the same map with the same seed */
103 _random.SetSeed(_settings_game.game_creation.generation_seed);
105 SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, HT_NONE, WindowClass::MainWindow, 0);
106 ScriptObject::InitializeRandomizers();
107
109
111 /* Must start economy early because of the costs. */
112 StartupEconomy();
113 if (!CheckTownRoadTypes()) {
115 return;
116 }
117
118 bool landscape_generated = false;
119
120 /* Don't generate landscape items when in the scenario editor. */
122 landscape_generated = GenerateLandscape(GenWorldInfo::mode);
123 }
124
125 if (!landscape_generated) {
127
128 /* Make sure the tiles at the north border are void tiles if needed. */
129 if (_settings_game.construction.freeform_edges) {
130 for (uint x = 0; x < Map::SizeX(); x++) MakeVoid(TileXY(x, 0));
131 for (uint y = 0; y < Map::SizeY(); y++) MakeVoid(TileXY(0, y));
132 }
133
134 /* Make the map the height of the setting */
135 if (_game_mode != GameMode::Menu) FlatEmptyWorld(_settings_game.game_creation.se_flat_world_height);
136
137 ConvertGroundTilesIntoWaterTiles();
138 Map::CountLandTiles();
140
141 _settings_game.game_creation.snow_line_height = DEF_SNOWLINE_HEIGHT;
142 } else {
144 Map::CountLandTiles();
145
146 /* Only generate towns, tree and industries in newgame mode. */
147 if (_game_mode != GameMode::Editor) {
148 if (!GenerateTowns(_settings_game.economy.town_layout)) {
150 return;
151 }
155 }
156 }
157
158 /* These are probably pointless when inside the scenario editor. */
165 _generating_world = false;
166
168
169 /* No need to run the tile loop in the scenario editor. */
171 uint i;
172
174 for (i = 0; i < 0x500; i++) {
175 RunTileLoop();
178 }
179
180 if (_game_mode != GameMode::Editor) {
181 if (Game::GetInstance() != nullptr) {
183 _generating_world = true;
184 for (i = 0; i < 2500; i++) {
187 if (Game::GetInstance()->IsSleeping()) break;
188 }
189 _generating_world = false;
190 }
191 }
192 }
193
195
197 cur_company.Trash();
199 /* Show all vital windows again, because we have hidden them. */
200 if (_game_mode != GameMode::Menu) ShowVitalWindows();
201
203 /* Call any callback */
204 if (GenWorldInfo::proc != nullptr) GenWorldInfo::proc();
206
208
210
211 if (_network_dedicated) Debug(Facility::Net, Severity::Notice, "Map generated, starting game");
212 Debug(Facility::Desync, Severity::Error, "new_map: {:08x}", _settings_game.game_creation.generation_seed);
213
215 std::string name = fmt::format("dmp_cmds_{:08x}_{:08x}.sav", _settings_game.game_creation.generation_seed, TimerGameEconomy::date);
217 }
218 } catch (AbortGenerateWorldSignal&) {
220
222 if (cur_company.IsValid()) cur_company.Restore();
223
224 if (_network_dedicated) {
225 /* Exit the game to prevent a return to main menu. */
226 Debug(Facility::Net, Severity::Critical, "Generating map failed; closing server");
227 _exit_game = true;
228 } else {
229 SwitchToMode(_switch_mode);
230 }
231 }
232}
233
243
253
258{
259 GenWorldInfo::abort = true;
260}
261
267{
268 return GenWorldInfo::abort || _exit_game;
269}
270
275{
276 /* Clean up - in SE create an empty map, otherwise, go to intro menu */
278
280
282}
283
291void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings)
292{
293 if (HasModalProgress()) return;
294 GenWorldInfo::mode = mode;
295 GenWorldInfo::size_x = size_x;
296 GenWorldInfo::size_y = size_y;
297 SetModalProgress(true);
298 GenWorldInfo::abort = false;
299 GenWorldInfo::abortp = nullptr;
301
302 /* This disables some commands and stuff */
304
305 InitializeGame(GenWorldInfo::size_x, GenWorldInfo::size_y, true, reset_settings);
307
308 if (_settings_game.construction.map_height_limit == 0 || GenWorldInfo::mode == GWM_HEIGHTMAP) {
309 uint estimated_height = 0;
310
311 if (GenWorldInfo::mode == GWM_EMPTY && _game_mode != GameMode::Menu) {
312 estimated_height = _settings_game.game_creation.se_flat_world_height;
313 } else if (GenWorldInfo::mode == GWM_HEIGHTMAP) {
314 estimated_height = _settings_game.game_creation.heightmap_height;
315 } else if (_settings_game.game_creation.land_generator == LG_TERRAGENESIS) {
316 estimated_height = GetEstimationTGPMapHeight();
317 } else {
318 estimated_height = 0;
319 }
320
322 }
323
324 if (_settings_game.game_creation.generation_seed == GENERATE_NEW_SEED) _settings_game.game_creation.generation_seed = InteractiveRandom();
325
326 /* Load the right landscape stuff, and the NewGRFs! */
332
333 /* Re-init the windowing system */
335
336 /* Create toolbars */
338 SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, HT_NONE, WindowClass::MainWindow, 0);
339
343
345
346 /* Centre the view on the map */
348
350}
351
359
366static TileIndex TranslateCoordinates(float x, float y)
367{
368 if (x <= 0.0f || y <= 0.0f || x >= 1.0f || y >= 1.0f) return INVALID_TILE;
369
370 /* Determine the target tile.. */
371 switch (_settings_game.game_creation.heightmap_rotation) {
372 case HM_CLOCKWISE:
373 /* Tile coordinates align with what we expect. */
374 return TileXY(x * Map::MaxX(), y * Map::MaxY());
375
377 /* Tile coordinates are rotated and must be adjusted. */
378 return TileXY((1 - y) * Map::MaxX(), x * Map::MaxY());
379
380 default:
381 NOT_REACHED();
382 }
383}
384
390static std::vector<ParsedTown> ParseTownData(std::string_view text)
391{
392 /* Now parse the JSON. */
393 nlohmann::json town_data;
394 try {
395 town_data = nlohmann::json::parse(text);
396 } catch (nlohmann::json::exception &) {
397 ShowErrorMessage(GetEncodedString(STR_TOWN_DATA_ERROR_LOAD_FAILED), GetEncodedString(STR_TOWN_DATA_ERROR_JSON_FORMATTED_INCORRECTLY), WarningLevel::Error);
398 return {};
399 }
400
401 /* Check for JSON formatting errors with the array of towns. */
402 if (!town_data.is_array()) {
403 ShowErrorMessage(GetEncodedString(STR_TOWN_DATA_ERROR_LOAD_FAILED), GetEncodedString(STR_TOWN_DATA_ERROR_JSON_FORMATTED_INCORRECTLY), WarningLevel::Error);
404 return {};
405 }
406
407 std::vector<ParsedTown> towns;
408
409 /* Iterate through towns and attempt to found them. */
410 for (auto &feature : town_data) {
411 ParsedTown &town = towns.emplace_back();
412
413 /* Ensure JSON is formatted properly. */
414 if (!feature.is_object()) {
415 ShowErrorMessage(GetEncodedString(STR_TOWN_DATA_ERROR_LOAD_FAILED), GetEncodedString(STR_TOWN_DATA_ERROR_JSON_FORMATTED_INCORRECTLY), WarningLevel::Error);
416 return {};
417 }
418
419 /* Check to ensure all fields exist and are of the correct type.
420 * If the town name is formatted wrong, all we can do is give a general warning. */
421 if (!feature.contains("name") || !feature.at("name").is_string()) {
422 ShowErrorMessage(GetEncodedString(STR_TOWN_DATA_ERROR_LOAD_FAILED), GetEncodedString(STR_TOWN_DATA_ERROR_JSON_FORMATTED_INCORRECTLY), WarningLevel::Error);
423 return {};
424 }
425
426 feature.at("name").get_to(town.name);
427
428 /* If other fields are formatted wrong, we can actually inform the player which town is the problem. */
429 if (!feature.contains("population") || !feature.at("population").is_number() ||
430 !feature.contains("city") || !feature.at("city").is_boolean() ||
431 !feature.contains("x") || !feature.at("x").is_number() ||
432 !feature.contains("y") || !feature.at("y").is_number()) {
433 ShowErrorMessage(GetEncodedString(STR_TOWN_DATA_ERROR_LOAD_FAILED), GetEncodedString(STR_TOWN_DATA_ERROR_TOWN_FORMATTED_INCORRECTLY, town.name), WarningLevel::Error);
434 return {};
435 }
436
437 /* Set town properties. */
438 feature.at("population").get_to(town.population);
439 feature.at("city").get_to(town.is_city);
440
441 /* Find the target tile for the town. */
442 town.target_tile = TranslateCoordinates(feature.at("x").get<float>(), feature.at("y").get<float>());
443 if (town.target_tile == INVALID_TILE) {
444 ShowErrorMessage(GetEncodedString(STR_TOWN_DATA_ERROR_LOAD_FAILED), GetEncodedString(STR_TOWN_DATA_ERROR_BAD_COORDINATE, town.name), WarningLevel::Error);
445 return {};
446 }
447 }
448
449 return towns;
450}
451
456{
457 /* Load the JSON file as a string initially. We'll parse it soon. */
458 size_t filesize;
459 auto f = FioFOpenFile(_file_to_saveload.name, "rb", Subdirectory::Heightmap, &filesize);
460
461 if (!f.has_value()) {
462 ShowErrorMessage(GetEncodedString(STR_TOWN_DATA_ERROR_LOAD_FAILED),
463 GetEncodedString(STR_TOWN_DATA_ERROR_JSON_FORMATTED_INCORRECTLY), WarningLevel::Error);
464 return;
465 }
466
467 std::string text(filesize, '\0');
468 size_t len = fread(text.data(), filesize, 1, *f);
469 f.reset();
470 if (len != 1) {
471 ShowErrorMessage(GetEncodedString(STR_TOWN_DATA_ERROR_LOAD_FAILED),
472 GetEncodedString(STR_TOWN_DATA_ERROR_JSON_FORMATTED_INCORRECTLY), WarningLevel::Error);
473 return;
474 }
475
476 std::vector<ParsedTown> town_data = ParseTownData(text);
477 if (town_data.empty()) return;
478
479 std::vector<std::pair<const Town *, uint> > towns;
480 uint failed_towns = 0;
481
482 AutoRestoreBackup old_generating_world(_generating_world, true);
483 bool road_pending = UpdateNearestTownForRoadTiles(true);
484
485 for (auto &town : town_data) {
486 const Town *t = TryGenerateNamedTownAroundTile(town.target_tile, TownSize::Small, town.is_city, _settings_game.economy.town_layout, town.name);
487
488 /* 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.
489 * This allows the player to diagnose a heightmap misalignment, if towns end up in the sea, or place towns manually, if in rough terrain. */
490 if (t == nullptr) {
491 Command<Commands::PlaceSign>::Post(town.target_tile, town.name);
492 failed_towns++;
493 continue;
494 }
495
496 towns.emplace_back(t, town.population);
497 }
498
499 /* If we couldn't found a town (or multiple), display a message to the player with the number of failed towns. */
500 if (failed_towns > 0) {
501 ShowErrorMessage(GetEncodedString(STR_TOWN_DATA_ERROR_FAILED_TO_FOUND_TOWN, failed_towns), {}, WarningLevel::Warning);
502 }
503
504 /* Now that we've created the towns, let's grow them to their target populations. */
505 for (const auto &[t, population] : towns) {
506 /* Grid towns can grow almost forever, but the town growth algorithm gets less and less efficient as it wanders roads randomly,
507 * 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." */
508 int try_limit = 1000;
509
510 /* If a town repeatedly fails to grow, continuing to try only wastes time. */
511 int fail_limit = 10;
512
513 /* Grow by a constant number of houses each time, instead of growth based on current town size.
514 * We want our try limit to apply in a predictable way, no matter the road layout and other geography. */
515 const int HOUSES_TO_GROW = 10;
516
517 do {
518 uint before = t->cache.num_houses;
519 Command<Commands::ExpandTown>::Post(t->index, HOUSES_TO_GROW, {TownExpandMode::Buildings, TownExpandMode::Roads});
520 if (t->cache.num_houses <= before) fail_limit--;
521 } while (fail_limit > 0 && try_limit-- > 0 && t->cache.population < population);
522 }
523
524 if (road_pending) UpdateNearestTownForRoadTiles(false);
525}
Class for backupping variables and making sure they are restored later.
static void StartNew()
Start up a new GameScript.
Definition game_core.cpp:70
static class GameInstance * GetInstance()
Get the current active instance.
Definition game.hpp:108
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.
void SetLocalCompany(CompanyID new_company, bool switching_game)
Sets the local company and updates the settings that are set on a per-company basis to reflect the co...
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
static constexpr Owner OWNER_NONE
The tile has no ownership.
bool IsVisibleSeverity(Facility facility, Severity severity)
Test if debug severity is visible for the given facility.
Definition debug.h:24
#define Debug(facility, severity, format_string,...)
Output a line of debugging information.
Definition debug.h:36
@ Desync
Desync message facility.
Definition debug_type.h:41
@ Net
Net message facility.
Definition debug_type.h:33
@ Notice
Notice.
Definition debug_type.h:18
@ Critical
Critical, user should know about this.
Definition debug_type.h:15
@ Error
Error, but we are recovering.
Definition debug_type.h:16
void StartupEngines()
Start/initialise all our engines.
Definition engine.cpp:838
Functions related to engines.
Functions related to errors.
void UnshowCriticalError()
Unshow the critical error.
@ Warning
Other information.
Definition error.h:23
@ Error
Errors (eg. saving/loading failed).
Definition error.h:24
void ShowErrorMessage(EncodedString &&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(std::string_view filename, std::string_view mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
Definition fileio.cpp:248
@ Save
File is being saved.
Definition fileio_type.h:54
@ GameFile
Save game or scenario file.
Definition fileio_type.h:30
@ Autosave
Subdirectory of save for autosaves.
Definition fileio_type.h:90
@ Heightmap
Subdirectory of scenario for heightmaps.
Definition fileio_type.h:92
Base functions for all Games.
The GameInstance tracks games.
bool _generating_world
Whether we are generating the map or not.
Definition genworld.cpp:70
void GenerateWorldSetCallback(GWDoneProc *proc)
Set here the function, if any, that you want to be called when landscape generation is done.
Definition genworld.cpp:239
void GenerateWorldSetAbortCallback(GWAbortProc *proc)
Set here the function, if any, that you want to be called when landscape generation is aborted.
Definition genworld.cpp:249
void HandleGeneratingWorldAbortion()
Really handle the abortion, i.e.
Definition genworld.cpp:274
void GenerateTrees()
Place new trees.
Definition tree_cmd.cpp:482
void GenerateObjects()
Generate objects, including lighthouses, transmitters, and any NewGRF objects.
static void _GenerateWorld()
The internal, real, generate function.
Definition genworld.cpp:94
static std::vector< ParsedTown > ParseTownData(std::string_view text)
Parse town data from json text.
Definition genworld.cpp:390
void GenerateIndustries()
This function will create random industries during game creation.
static TileIndex TranslateCoordinates(float x, float y)
Translation coordates from a proportions to TileIndex.
Definition genworld.cpp:366
static void CleanupGeneration()
Generation is done; show windows again and delete the progress window.
Definition genworld.cpp:77
void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings)
Generate a world.
Definition genworld.cpp:291
void AbortGeneratingWorld()
Initializes the abortion process.
Definition genworld.cpp:257
bool IsGeneratingWorldAborted()
Is the generation being aborted?
Definition genworld.cpp:266
void StartupDisasters()
Starts up disasters.
void LoadTownData()
Load town data from _file_to_saveload, place towns at the appropriate locations, and expand them to t...
Definition genworld.cpp:455
void StartupCompanies()
Start of a new game.
void GenerateClearTile()
Generate rough and rocky features on clear tiles.
Functions related to world/map generation.
void GWAbortProc()
Called when genworld is aborted.
Definition genworld.h:54
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:50
@ LG_TERRAGENESIS
TerraGenesis Perlin landscape generator.
Definition genworld.h:20
void ShowGenerateWorldProgress()
Show the window where a user can follow the process of the map generation.
@ GameStart
Really prepare to start the game.
Definition genworld.h:70
@ GameScript
Runs the game script at most 2500 times, or when ever the script sleeps.
Definition genworld.h:69
@ Init
Initialize/allocate the map, start economy.
Definition genworld.h:58
@ Objects
Generate objects (radio tower, light houses).
Definition genworld.h:65
@ GameInit
Initialize the game.
Definition genworld.h:67
@ RunTileLoop
Runs the tile loop 1280 times to make snow etc.
Definition genworld.h:68
void GWDoneProc()
Procedure called when the genworld process finishes.
Definition genworld.h:53
static const uint MAP_HEIGHT_LIMIT_AUTO_CEILING_ROOM
When map height limit is auto, the map height limit will be the highest peak plus this value.
Definition genworld.h:51
static const uint32_t GENERATE_NEW_SEED
Create a new random seed.
Definition genworld.h:23
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:26
@ GWM_HEIGHTMAP
Generate a newgame from a heightmap.
Definition genworld.h:30
@ GWM_EMPTY
Generate an empty map (sea-level).
Definition genworld.h:28
void LoadStringWidthTable(FontSizes fontsizes)
Initialize _stringwidth_table cache for the specified font sizes.
Definition gfx.cpp:1255
void SetMouseCursorBusy(bool busy)
Set or unset the ZZZ cursor.
Definition gfx.cpp:1689
SwitchMode _switch_mode
The next mainloop command.
Definition gfx.cpp:45
void GfxLoadSprites()
Initialise and load all the sprites.
Definition gfxinit.cpp:335
Functions related to the graphics initialization.
static const CursorID SPR_CURSOR_ZZZ
Definition sprites.h:1569
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1548
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:578
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows.
Definition main_gui.cpp:549
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition map_func.h:376
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
bool _network_dedicated
are we a dedicated server?
Definition network.cpp:66
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.
@ Editor
In the scenario editor.
Definition openttd.h:21
@ Menu
In the main menu.
Definition openttd.h:19
@ Editor
Switch to scenario editor.
Definition openttd.h:31
@ Menu
Switch to game intro menu.
Definition openttd.h:33
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.
bool UpdateNearestTownForRoadTiles(bool invalidate)
Updates cached nearest town for all road tiles.
A number of safeguards to prevent using unsafe methods.
SaveLoadResult SaveOrLoad(std::string_view 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:81
Functions related to saving and loading games.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
Command definitions related to signs.
Definition of base types and functions in a cross-platform compatible way.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:89
Functions related to OTTD's strings.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
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...
Properties of current genworld process.
Definition genworld.cpp:59
static GWDoneProc * proc
Proc that is called when done (can be nullptr).
Definition genworld.cpp:65
static CompanyID lc
The local_company before generating.
Definition genworld.cpp:62
static uint size_x
X-size of the map.
Definition genworld.cpp:63
static uint size_y
Y-size of the map.
Definition genworld.cpp:64
static bool abort
Whether to abort the thread ASAP.
Definition genworld.cpp:60
static GWAbortProc * abortp
Proc that is called when aborting (can be nullptr).
Definition genworld.cpp:66
static GenWorldMode mode
What mode are we making a world in.
Definition genworld.cpp:61
static uint SizeX()
Get the size of the map along the X.
Definition map_func.h:262
static uint SizeY()
Get the size of the map along the Y.
Definition map_func.h:271
static uint MaxY()
Gets the maximum Y coordinate within the map, including TileType::Void.
Definition map_func.h:298
static uint MaxX()
Gets the maximum X coordinate within the map, including TileType::Void.
Definition map_func.h:289
Parsed town data.
Definition genworld.cpp:353
uint population
The target population of the town when created in OpenTTD. If input is blank, defaults to 0.
Definition genworld.cpp:355
std::string name
The name of the town.
Definition genworld.cpp:354
TileIndex target_tile
The target tile of the town.
Definition genworld.cpp:357
bool is_city
Should it be created as a city in OpenTTD? If input is blank, defaults to false.
Definition genworld.cpp:356
Town data structure.
Definition town.h:64
uint GetEstimationTGPMapHeight()
Get an overestimation of the highest peak TGP wants to generate.
Definition tgp.cpp:271
Functions for the Perlin noise enhanced map generator.
static constexpr uint DEF_SNOWLINE_HEIGHT
Default snowline height.
Definition tile_type.h:33
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
static constexpr 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 tick-based game-timer.
Base of the town class.
bool GenerateTowns(TownLayout layout, std::optional< uint > number=std::nullopt)
Generate a number of towns with a given layout.
Town * TryGenerateNamedTownAroundTile(TileIndex target_tile, TownSize size, bool city, TownLayout layout, std::string_view name)
Try to generate a named town around a tile.
bool CheckTownRoadTypes()
Check if towns are able to build road.
Definition town_cmd.cpp:983
Command definitions related to towns.
@ Small
Small town.
Definition town_type.h:22
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:1255
void ResetWindowSystem()
Reset the windowing system, by means of shutting it down followed by re-initialization.
Definition window.cpp:1941
void HideVitalWindows()
Close all always on-top windows to get an empty screen.
Definition window.cpp:3477
void CloseAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
Definition window.cpp:3439
Window functions not directly related to making/drawing windows.