OpenTTD Source: src/openttd.cpp Source File

OpenTTD Source 15.0-beta1

openttd.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
12#include "blitter/factory.hpp"
13#include "sound/sound_driver.hpp"
14#include "music/music_driver.hpp"
15#include "video/video_driver.hpp"
16#include "mixer.h"
17
18#include "fontcache.h"
19#include "error.h"
20#include "error_func.h"
21#include "gui.h"
22
23#include "base_media_base.h"
24#include "saveload/saveload.h"
25#include "company_cmd.h"
26#include "company_func.h"
27#include "command_func.h"
28#include "news_func.h"
29#include "fios.h"
30#include "aircraft.h"
31#include "roadveh.h"
32#include "train.h"
33#include "ship.h"
34#include "console_func.h"
35#include "screenshot.h"
36#include "network/network.h"
37#include "network/network_func.h"
38#include "ai/ai.hpp"
39#include "ai/ai_config.hpp"
40#include "settings_func.h"
41#include "genworld.h"
42#include "progress.h"
43#include "strings_func.h"
44#include "vehicle_func.h"
45#include "gamelog.h"
46#include "animated_tile_func.h"
47#include "roadstop_base.h"
48#include "elrail_func.h"
49#include "rev.h"
50#include "highscore.h"
51#include "station_base.h"
52#include "crashlog.h"
53#include "engine_func.h"
54#include "core/random_func.hpp"
55#include "rail_gui.h"
56#include "road_gui.h"
57#include "core/backup_type.hpp"
58#include "hotkeys.h"
59#include "newgrf.h"
60#include "misc/getoptdata.h"
61#include "game/game.hpp"
62#include "game/game_config.hpp"
63#include "town.h"
64#include "subsidy_func.h"
65#include "gfx_layout.h"
66#include "viewport_func.h"
67#include "viewport_sprite_sorter.h"
68#include "framerate_type.h"
69#include "industry.h"
70#include "network/network_gui.h"
71#include "network/network_survey.h"
72#include "misc_cmd.h"
73#include "timer/timer.h"
74#include "timer/timer_game_calendar.h"
75#include "timer/timer_game_economy.h"
76#include "timer/timer_game_realtime.h"
77#include "timer/timer_game_tick.h"
78#include "social_integration.h"
79
80#include "linkgraph/linkgraphschedule.h"
81
82#include <system_error>
83
84#include "safeguards.h"
85
86#ifdef __EMSCRIPTEN__
87# include <emscripten.h>
88# include <emscripten/html5.h>
89#endif
90
91void CallLandscapeTick();
92void DoPaletteAnimations();
93void MusicLoop();
94void CallWindowGameTickEvent();
95bool HandleBootstrap();
96
97extern void CheckCaches();
98extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY);
99extern void OSOpenBrowser(const std::string &url);
100extern void ShowOSErrorBox(const char *buf, bool system);
101extern std::string _config_file;
102
103bool _save_config = false;
104bool _request_newgrf_scan = false;
105 NewGRFScanCallback *_request_newgrf_scan_callback = nullptr;
106
112 void UserErrorI(const std::string &str)
113{
114 ShowOSErrorBox(str.c_str(), false);
115 if (VideoDriver::GetInstance() != nullptr) VideoDriver::GetInstance()->Stop();
116
117#ifdef __EMSCRIPTEN__
118 emscripten_exit_pointerlock();
119 /* In effect, the game ends here. As emscripten_set_main_loop() caused
120 * the stack to be unwound, the code after MainLoop() in
121 * openttd_main() is never executed. */
122 EM_ASM(if (window["openttd_abort"]) openttd_abort());
123#endif
124
125 _exit(1);
126}
127
133 void FatalErrorI(const std::string &str)
134{
135 if (VideoDriver::GetInstance() == nullptr || VideoDriver::GetInstance()->HasGUI()) {
136 ShowOSErrorBox(str.c_str(), true);
137 }
138
139 /* Set the error message for the crash log and then invoke it. */
140 CrashLog::SetErrorMessage(str);
141 abort();
142}
143
147 static void ShowHelp()
148{
149 std::string str;
150 str.reserve(8192);
151
152 std::back_insert_iterator<std::string> output_iterator = std::back_inserter(str);
153 fmt::format_to(output_iterator, "OpenTTD {}\n", _openttd_revision);
154 str +=
155 "\n"
156 "\n"
157 "Command line options:\n"
158 " -v drv = Set video driver (see below)\n"
159 " -s drv = Set sound driver (see below)\n"
160 " -m drv = Set music driver (see below)\n"
161 " -b drv = Set the blitter to use (see below)\n"
162 " -r res = Set resolution (for instance 800x600)\n"
163 " -h = Display this help text\n"
164 " -t year = Set starting year\n"
165 " -d [[fac=]lvl[,...]]= Debug mode\n"
166 " -e = Start Editor\n"
167 " -g [savegame|scenario|heightmap] = Start new/savegame/scenario/heightmap immediately\n"
168 " -G seed = Set random seed\n"
169 " -n host[:port][#company]= Join network game\n"
170 " -p password = Password to join server\n"
171 " -D [host][:port] = Start dedicated server\n"
172#if !defined(_WIN32)
173 " -f = Fork into the background (dedicated only)\n"
174#endif
175 " -I graphics_set = Force the graphics set (see below)\n"
176 " -S sounds_set = Force the sounds set (see below)\n"
177 " -M music_set = Force the music set (see below)\n"
178 " -c config_file = Use 'config_file' instead of 'openttd.cfg'\n"
179 " -x = Never save configuration changes to disk\n"
180 " -X = Don't use global folders to search for files\n"
181 " -q savegame = Write some information about the savegame and exit\n"
182 " -Q = Don't scan for/load NewGRF files on startup\n"
183 " -QQ = Disable NewGRF scanning/loading entirely\n"
184 "\n";
185
186 /* List the graphics packs */
187 BaseGraphics::GetSetsList(output_iterator);
188
189 /* List the sounds packs */
190 BaseSounds::GetSetsList(output_iterator);
191
192 /* List the music packs */
193 BaseMusic::GetSetsList(output_iterator);
194
195 /* List the drivers */
196 DriverFactoryBase::GetDriversInfo(output_iterator);
197
198 /* List the blitters */
199 BlitterFactory::GetBlittersInfo(output_iterator);
200
201 /* List the debug facilities. */
202 DumpDebugFacilityNames(output_iterator);
203
204 /* We need to initialize the AI, so it finds the AIs */
205 AI::Initialize();
206 AI::GetConsoleList(output_iterator, true);
207 AI::Uninitialize(true);
208
209 /* We need to initialize the GameScript, so it finds the GSs */
210 Game::Initialize();
211 Game::GetConsoleList(output_iterator, true);
212 Game::Uninitialize(true);
213
214 /* ShowInfo put output to stderr, but version information should go
215 * to stdout; this is the only exception */
216#if !defined(_WIN32)
217 fmt::print("{}\n", str);
218#else
219 ShowInfoI(str);
220#endif
221}
222
223static void WriteSavegameInfo(const std::string &name)
224{
225 extern SaveLoadVersion _sl_version;
226 uint32_t last_ottd_rev = 0;
227 uint8_t ever_modified = 0;
228 bool removed_newgrfs = false;
229
230 _gamelog.Info(&last_ottd_rev, &ever_modified, &removed_newgrfs);
231
232 std::string message;
233 message.reserve(1024);
234 fmt::format_to(std::back_inserter(message), "Name: {}\n", name);
235 fmt::format_to(std::back_inserter(message), "Savegame ver: {}\n", _sl_version);
236 fmt::format_to(std::back_inserter(message), "NewGRF ver: 0x{:08X}\n", last_ottd_rev);
237 fmt::format_to(std::back_inserter(message), "Modified: {}\n", ever_modified);
238
239 if (removed_newgrfs) {
240 fmt::format_to(std::back_inserter(message), "NewGRFs have been removed\n");
241 }
242
243 message += "NewGRFs:\n";
244 if (_load_check_data.HasNewGrfs()) {
245 for (GRFConfig *c = _load_check_data.grfconfig; c != nullptr; c = c->next) {
246 fmt::format_to(std::back_inserter(message), "{:08X} {} {}\n", BSWAP32(c->ident.grfid),
247 FormatArrayAsHex(HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum), c->filename);
248 }
249 }
250
251 /* ShowInfo put output to stderr, but version information should go
252 * to stdout; this is the only exception */
253#if !defined(_WIN32)
254 fmt::print("{}\n", message);
255#else
256 ShowInfoI(message);
257#endif
258}
259
260
267 static void ParseResolution(Dimension *res, const char *s)
268{
269 const char *t = strchr(s, 'x');
270 if (t == nullptr) {
271 ShowInfo("Invalid resolution '{}'", s);
272 return;
273 }
274
275 res->width = std::max(std::strtoul(s, nullptr, 0), 64UL);
276 res->height = std::max(std::strtoul(t + 1, nullptr, 0), 64UL);
277}
278
279
284 static void ShutdownGame()
285{
286 IConsoleFree();
287
288 if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
289
290 SocialIntegration::Shutdown();
291 DriverFactoryBase::ShutdownDrivers();
292
293 UnInitWindowSystem();
294
295 /* stop the scripts */
296 AI::Uninitialize(false);
297 Game::Uninitialize(false);
298
299 /* Uninitialize variables that are allocated dynamically */
300 _gamelog.Reset();
301
302 LinkGraphSchedule::Clear();
303 PoolBase::Clean(PT_ALL);
304
305 /* No NewGRFs were loaded when it was still bootstrapping. */
306 if (_game_mode != GM_BOOTSTRAP) ResetNewGRFData();
307
308 UninitFontCache();
309}
310
315 static void LoadIntroGame(bool load_newgrfs = true)
316{
317 _game_mode = GM_MENU;
318
319 if (load_newgrfs) ResetGRFConfig(false);
320
321 /* Setup main window */
322 ResetWindowSystem();
323 SetupColoursAndInitialWindow();
324
325 /* Load the default opening screen savegame */
326 if (SaveOrLoad("opntitle.dat", SLO_LOAD, DFT_GAME_FILE, BASESET_DIR) != SL_OK) {
327 GenerateWorld(GWM_EMPTY, 64, 64); // if failed loading, make empty world.
328 SetLocalCompany(COMPANY_SPECTATOR);
329 } else {
330 SetLocalCompany(COMPANY_FIRST);
331 }
332
333 FixTitleGameZoom();
334 _pause_mode = PM_UNPAUSED;
335 _cursor.fix_at = false;
336
337 CheckForMissingGlyphs();
338
339 MusicLoop(); // ensure music is correct
340}
341
342void MakeNewgameSettingsLive()
343{
344 for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
345 if (_settings_game.ai_config[c] != nullptr) {
346 delete _settings_game.ai_config[c];
347 }
348 }
349 if (_settings_game.game_config != nullptr) {
350 delete _settings_game.game_config;
351 }
352
353 /* Copy newgame settings to active settings.
354 * Also initialise old settings needed for savegame conversion. */
355 _settings_game = _settings_newgame;
356 _old_vds = _settings_client.company.vehicle;
357
358 for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
359 _settings_game.ai_config[c] = nullptr;
360 if (_settings_newgame.ai_config[c] != nullptr) {
361 _settings_game.ai_config[c] = new AIConfig(_settings_newgame.ai_config[c]);
362 }
363 }
364 _settings_game.game_config = nullptr;
365 if (_settings_newgame.game_config != nullptr) {
366 _settings_game.game_config = new GameConfig(_settings_newgame.game_config);
367 }
368}
369
370void OpenBrowser(const std::string &url)
371{
372 /* Make sure we only accept urls that are sure to open a browser. */
373 if (url.starts_with("http://") || url.starts_with("https://")) {
374 OSOpenBrowser(url);
375 }
376}
377
379 struct AfterNewGRFScan : NewGRFScanCallback {
380 TimerGameCalendar::Year startyear = CalendarTime::INVALID_YEAR;
381 uint32_t generation_seed = GENERATE_NEW_SEED;
382 std::string dedicated_host;
383 uint16_t dedicated_port = 0;
384 std::string connection_string;
385 std::string join_server_password;
386 bool save_config = true;
387
391 AfterNewGRFScan()
392 {
393 /* Visual C++ 2015 fails compiling this line (AfterNewGRFScan::generation_seed undefined symbol)
394 * if it's placed outside a member function, directly in the struct body. */
395 static_assert(sizeof(generation_seed) == sizeof(_settings_game.game_creation.generation_seed));
396 }
397
398 void OnNewGRFsScanned() override
399 {
400 ResetGRFConfig(false);
401
402 TarScanner::DoScan(TarScanner::SCENARIO);
403
404 AI::Initialize();
405 Game::Initialize();
406
407 /* We want the new (correct) NewGRF count to survive the loading. */
408 uint last_newgrf_count = _settings_client.gui.last_newgrf_count;
409 LoadFromConfig();
410 _settings_client.gui.last_newgrf_count = last_newgrf_count;
411 /* Since the default for the palette might have changed due to
412 * reading the configuration file, recalculate that now. */
413 UpdateNewGRFConfigPalette();
414
415 Game::Uninitialize(true);
416 AI::Uninitialize(true);
417 LoadFromHighScore();
418 LoadHotkeysFromConfig();
419 WindowDesc::LoadFromConfig();
420
421 /* We have loaded the config, so we may possibly save it. */
422 _save_config = save_config;
423
424 /* restore saved music and effects volumes */
425 MusicDriver::GetInstance()->SetVolume(_settings_client.music.music_vol);
426 SetEffectVolume(_settings_client.music.effect_vol);
427
428 if (startyear != CalendarTime::INVALID_YEAR) IConsoleSetSetting("game_creation.starting_year", startyear.base());
429 _settings_newgame.game_creation.generation_seed = generation_seed;
430
431 if (!dedicated_host.empty()) {
432 _network_bind_list.clear();
433 _network_bind_list.emplace_back(dedicated_host);
434 }
435 if (dedicated_port != 0) _settings_client.network.server_port = dedicated_port;
436
437 /* initialize the ingame console */
438 IConsoleInit();
439 InitializeGUI();
440 IConsoleCmdExec("exec scripts/autoexec.scr 0");
441
442 /* Make sure _settings is filled with _settings_newgame if we switch to a game directly */
443 if (_switch_mode != SM_NONE) MakeNewgameSettingsLive();
444
445 if (_network_available && !connection_string.empty()) {
446 LoadIntroGame();
447 _switch_mode = SM_NONE;
448
449 NetworkClientConnectGame(connection_string, COMPANY_NEW_COMPANY, join_server_password);
450 }
451
452 /* After the scan we're not used anymore. */
453 delete this;
454 }
455};
456
457void PostMainLoop()
458{
459 WaitTillSaved();
460
461 /* only save config if we have to */
462 if (_save_config) {
463 SaveToConfig();
464 SaveHotkeysToConfig();
465 WindowDesc::SaveToConfig();
466 SaveToHighScore();
467 }
468
469 /* Reset windowing system, stop drivers, free used memory, ... */
470 ShutdownGame();
471}
472
473#if defined(UNIX)
474extern void DedicatedFork();
475#endif
476
482 static std::vector<OptionData> CreateOptions()
483{
484 std::vector<OptionData> options;
485 /* Options that require a parameter. */
486 for (char c : "GIMSbcmnpqrstv") options.push_back({ .type = ODF_HAS_VALUE, .id = c, .shortname = c });
487#if !defined(_WIN32)
488 options.push_back({ .type = ODF_HAS_VALUE, .id = 'f', .shortname = 'f' });
489#endif
490
491 /* Options with an optional parameter. */
492 for (char c : "Ddg") options.push_back({ .type = ODF_OPTIONAL_VALUE, .id = c, .shortname = c });
493
494 /* Options without a parameter. */
495 for (char c : "QXehx") options.push_back({ .type = ODF_NO_VALUE, .id = c, .shortname = c });
496 return options;
497}
498
504 int openttd_main(std::span<char * const> arguments)
505{
506 _game_session_stats.start_time = std::chrono::steady_clock::now();
507 _game_session_stats.savegame_size = std::nullopt;
508
509 std::string musicdriver;
510 std::string sounddriver;
511 std::string videodriver;
512 std::string blitter;
513 std::string graphics_set;
514 std::string sounds_set;
515 std::string music_set;
516 Dimension resolution = {0, 0};
517 std::unique_ptr<AfterNewGRFScan> scanner = std::make_unique<AfterNewGRFScan>();
518 bool dedicated = false;
519 bool only_local_path = false;
520
521 extern bool _dedicated_forks;
522 _dedicated_forks = false;
523
524 _game_mode = GM_MENU;
525 _switch_mode = SM_MENU;
526
527 auto options = CreateOptions();
528 GetOptData mgo(arguments.subspan(1), options);
529 int ret = 0;
530
531 int i;
532 while ((i = mgo.GetOpt()) != -1) {
533 switch (i) {
534 case 'I': graphics_set = mgo.opt; break;
535 case 'S': sounds_set = mgo.opt; break;
536 case 'M': music_set = mgo.opt; break;
537 case 'm': musicdriver = mgo.opt; break;
538 case 's': sounddriver = mgo.opt; break;
539 case 'v': videodriver = mgo.opt; break;
540 case 'b': blitter = mgo.opt; break;
541 case 'D':
542 musicdriver = "null";
543 sounddriver = "null";
544 videodriver = "dedicated";
545 blitter = "null";
546 dedicated = true;
547 SetDebugString("net=4", ShowInfoI);
548 if (mgo.opt != nullptr) {
549 scanner->dedicated_host = ParseFullConnectionString(mgo.opt, scanner->dedicated_port);
550 }
551 break;
552 case 'f': _dedicated_forks = true; break;
553 case 'n':
554 scanner->connection_string = mgo.opt; // host:port#company parameter
555 break;
556 case 'p':
557 scanner->join_server_password = mgo.opt;
558 break;
559 case 'r': ParseResolution(&resolution, mgo.opt); break;
560 case 't': scanner->startyear = atoi(mgo.opt); break;
561 case 'd': {
562#if defined(_WIN32)
563 CreateConsole();
564#endif
565 if (mgo.opt != nullptr) SetDebugString(mgo.opt, ShowInfoI);
566 break;
567 }
568 case 'e':
569 /* Allow for '-e' before or after '-g'. */
570 switch (_switch_mode) {
571 case SM_MENU: _switch_mode = SM_EDITOR; break;
572 case SM_LOAD_GAME: _switch_mode = SM_LOAD_SCENARIO; break;
573 case SM_START_HEIGHTMAP: _switch_mode = SM_LOAD_HEIGHTMAP; break;
574 default: break;
575 }
576 break;
577 case 'g':
578 if (mgo.opt != nullptr) {
579 _file_to_saveload.name = mgo.opt;
580
581 std::string extension = FS2OTTD(std::filesystem::path(OTTD2FS(_file_to_saveload.name)).extension());
582 auto [ft, _] = FiosGetSavegameListCallback(SLO_LOAD, _file_to_saveload.name, extension);
583 if (ft == FIOS_TYPE_INVALID) {
584 std::tie(ft, _) = FiosGetScenarioListCallback(SLO_LOAD, _file_to_saveload.name, extension);
585 }
586 if (ft == FIOS_TYPE_INVALID) {
587 std::tie(ft, _) = FiosGetHeightmapListCallback(SLO_LOAD, _file_to_saveload.name, extension);
588 }
589
590 /* Allow for '-e' before or after '-g'. */
591 switch (GetAbstractFileType(ft)) {
592 case FT_SAVEGAME: _switch_mode = (_switch_mode == SM_EDITOR ? SM_LOAD_SCENARIO : SM_LOAD_GAME); break;
593 case FT_SCENARIO: _switch_mode = (_switch_mode == SM_EDITOR ? SM_LOAD_SCENARIO : SM_LOAD_GAME); break;
594 case FT_HEIGHTMAP: _switch_mode = (_switch_mode == SM_EDITOR ? SM_LOAD_HEIGHTMAP : SM_START_HEIGHTMAP); break;
595 default: break;
596 }
597
598 _file_to_saveload.SetMode(SLO_LOAD, GetAbstractFileType(ft), GetDetailedFileType(ft));
599 break;
600 }
601
602 _switch_mode = SM_NEWGAME;
603 /* Give a random map if no seed has been given */
604 if (scanner->generation_seed == GENERATE_NEW_SEED) {
605 scanner->generation_seed = InteractiveRandom();
606 }
607 break;
608 case 'q': {
609 DeterminePaths(arguments[0], only_local_path);
610 if (StrEmpty(mgo.opt)) {
611 ret = 1;
612 return ret;
613 }
614
615 std::string extension = FS2OTTD(std::filesystem::path(OTTD2FS(mgo.opt)).extension());
616 auto [_, title] = FiosGetSavegameListCallback(SLO_LOAD, mgo.opt, extension);
617
618 _load_check_data.Clear();
619 SaveOrLoadResult res = SaveOrLoad(mgo.opt, SLO_CHECK, DFT_GAME_FILE, SAVE_DIR, false);
620 if (res != SL_OK || _load_check_data.HasErrors()) {
621 fmt::print(stderr, "Failed to open savegame\n");
622 if (_load_check_data.HasErrors()) {
623 InitializeLanguagePacks(); // A language pack is needed for GetString()
624 SetDParamStr(0, _load_check_data.error_msg);
625 fmt::print(stderr, "{}\n", GetString(_load_check_data.error));
626 }
627 return ret;
628 }
629
630 WriteSavegameInfo(title);
631 return ret;
632 }
633 case 'Q': {
634 extern int _skip_all_newgrf_scanning;
635 _skip_all_newgrf_scanning += 1;
636 break;
637 }
638 case 'G': scanner->generation_seed = std::strtoul(mgo.opt, nullptr, 10); break;
639 case 'c': _config_file = mgo.opt; break;
640 case 'x': scanner->save_config = false; break;
641 case 'X': only_local_path = true; break;
642 case 'h':
643 i = -2; // Force printing of help.
644 break;
645 }
646 if (i == -2) break;
647 }
648
649 if (i == -2 || !mgo.arguments.empty()) {
650 /* Either the user typed '-h', they made an error, or they added unrecognized command line arguments.
651 * In all cases, print the help, and exit.
652 *
653 * The next two functions are needed to list the graphics sets. We can't do them earlier
654 * because then we cannot show it on the debug console as that hasn't been configured yet. */
655 DeterminePaths(arguments[0], only_local_path);
656 TarScanner::DoScan(TarScanner::BASESET);
657 BaseGraphics::FindSets();
658 BaseSounds::FindSets();
659 BaseMusic::FindSets();
660 ShowHelp();
661 return ret;
662 }
663
664 DeterminePaths(arguments[0], only_local_path);
665 TarScanner::DoScan(TarScanner::BASESET);
666
667 if (dedicated) Debug(net, 3, "Starting dedicated server, version {}", _openttd_revision);
668 if (_dedicated_forks && !dedicated) _dedicated_forks = false;
669
670#if defined(UNIX)
671 /* We must fork here, or we'll end up without some resources we need (like sockets) */
672 if (_dedicated_forks) DedicatedFork();
673#endif
674
675 LoadFromConfig(true);
676
677 if (resolution.width != 0) _cur_resolution = resolution;
678
679 /* Limit width times height times bytes per pixel to fit a 32 bit
680 * integer, This way all internal drawing routines work correctly.
681 * A resolution that has one component as 0 is treated as a marker to
682 * auto-detect a good window size. */
683 _cur_resolution.width = std::min(_cur_resolution.width, UINT16_MAX / 2u);
684 _cur_resolution.height = std::min(_cur_resolution.height, UINT16_MAX / 2u);
685
686 /* Assume the cursor starts within the game as not all video drivers
687 * get an event that the cursor is within the window when it is opened.
688 * Saying the cursor is there makes no visible difference as it would
689 * just be out of the bounds of the window. */
690 _cursor.in_window = true;
691
692 /* enumerate language files */
693 InitializeLanguagePacks();
694
695 /* Initialize the font cache */
696 InitFontCache(false);
697
698 /* This must be done early, since functions use the SetWindowDirty* calls */
699 InitWindowSystem();
700
701 BaseGraphics::FindSets();
702 bool valid_graphics_set;
703 if (!graphics_set.empty()) {
704 valid_graphics_set = BaseGraphics::SetSetByName(graphics_set);
705 } else if (BaseGraphics::ini_data.shortname != 0) {
706 graphics_set = BaseGraphics::ini_data.name;
707 valid_graphics_set = BaseGraphics::SetSetByShortname(BaseGraphics::ini_data.shortname);
708 if (valid_graphics_set && !BaseGraphics::ini_data.extra_params.empty()) {
709 GRFConfig &extra_cfg = BaseGraphics::GetUsedSet()->GetOrCreateExtraConfig();
710 if (extra_cfg.IsCompatible(BaseGraphics::ini_data.extra_version)) {
711 extra_cfg.SetParams(BaseGraphics::ini_data.extra_params);
712 }
713 }
714 } else if (!BaseGraphics::ini_data.name.empty()) {
715 graphics_set = BaseGraphics::ini_data.name;
716 valid_graphics_set = BaseGraphics::SetSetByName(BaseGraphics::ini_data.name);
717 } else {
718 valid_graphics_set = true;
719 BaseGraphics::SetSet(nullptr); // ignore error, continue to bootstrap GUI
720 }
721 if (!valid_graphics_set) {
722 BaseGraphics::SetSet(nullptr);
723
724 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_GRAPHICS_NOT_FOUND);
725 msg.SetDParamStr(0, graphics_set);
726 ScheduleErrorMessage(msg);
727 }
728
729 /* Initialize game palette */
730 GfxInitPalettes();
731
732 Debug(misc, 1, "Loading blitter...");
733 if (blitter.empty() && !_ini_blitter.empty()) blitter = _ini_blitter;
734 _blitter_autodetected = blitter.empty();
735 /* Activate the initial blitter.
736 * This is only some initial guess, after NewGRFs have been loaded SwitchNewGRFBlitter may switch to a different one.
737 * - Never guess anything, if the user specified a blitter. (_blitter_autodetected)
738 * - Use 32bpp blitter if baseset or 8bpp-support settings says so.
739 * - Use 8bpp blitter otherwise.
740 */
741 if (!_blitter_autodetected ||
742 (_support8bpp != S8BPP_NONE && (BaseGraphics::GetUsedSet() == nullptr || BaseGraphics::GetUsedSet()->blitter == BLT_8BPP)) ||
743 BlitterFactory::SelectBlitter("32bpp-anim") == nullptr) {
744 if (BlitterFactory::SelectBlitter(blitter) == nullptr) {
745 blitter.empty() ?
746 UserError("Failed to autoprobe blitter") :
747 UserError("Failed to select requested blitter '{}'; does it exist?", blitter);
748 }
749 }
750
751 if (videodriver.empty() && !_ini_videodriver.empty()) videodriver = _ini_videodriver;
752 DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
753
754 InitializeSpriteSorter();
755
756 /* Initialize the zoom level of the screen to normal */
757 _screen.zoom = ZOOM_LVL_MIN;
758
759 /* The video driver is now selected, now initialise GUI zoom */
760 UpdateGUIZoom();
761
762 SocialIntegration::Initialize();
763 NetworkStartUp(); // initialize network-core
764
765 if (!HandleBootstrap()) {
766 ShutdownGame();
767 return ret;
768 }
769
770 VideoDriver::GetInstance()->ClaimMousePointer();
771
772 /* initialize screenshot formats */
773 InitializeScreenshotFormats();
774
775 BaseSounds::FindSets();
776 if (sounds_set.empty() && !BaseSounds::ini_set.empty()) sounds_set = BaseSounds::ini_set;
777 if (!BaseSounds::SetSetByName(sounds_set)) {
778 if (sounds_set.empty() || !BaseSounds::SetSet({})) {
779 UserError("Failed to find a sounds set. Please acquire a sounds set for OpenTTD. See section 1.4 of README.md.");
780 } else {
781 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_SOUNDS_NOT_FOUND);
782 msg.SetDParamStr(0, sounds_set);
783 ScheduleErrorMessage(msg);
784 }
785 }
786
787 BaseMusic::FindSets();
788 if (music_set.empty() && !BaseMusic::ini_set.empty()) music_set = BaseMusic::ini_set;
789 if (!BaseMusic::SetSetByName(music_set)) {
790 if (music_set.empty() || !BaseMusic::SetSet({})) {
791 UserError("Failed to find a music set. Please acquire a music set for OpenTTD. See section 1.4 of README.md.");
792 } else {
793 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_MUSIC_NOT_FOUND);
794 msg.SetDParamStr(0, music_set);
795 ScheduleErrorMessage(msg);
796 }
797 }
798
799 if (sounddriver.empty() && !_ini_sounddriver.empty()) sounddriver = _ini_sounddriver;
800 DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
801
802 if (musicdriver.empty() && !_ini_musicdriver.empty()) musicdriver = _ini_musicdriver;
803 DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
804
805 GenerateWorld(GWM_EMPTY, 64, 64); // Make the viewport initialization happy
806 LoadIntroGame(false);
807
808 /* ScanNewGRFFiles now has control over the scanner. */
809 RequestNewGRFScan(scanner.release());
810
811 VideoDriver::GetInstance()->MainLoop();
812
813 PostMainLoop();
814 return ret;
815}
816
817void HandleExitGameRequest()
818{
819 if (_game_mode == GM_MENU || _game_mode == GM_BOOTSTRAP) { // do not ask to quit on the main screen
820 _exit_game = true;
821 } else if (_settings_client.gui.autosave_on_exit) {
822 DoExitSave();
823 _survey.Transmit(NetworkSurveyHandler::Reason::EXIT, true);
824 _exit_game = true;
825 } else {
826 AskExitGame();
827 }
828}
829
833 static void OnStartScenario()
834{
835 /* Reset engine pool to simplify changing engine NewGRFs in scenario editor. */
836 EngineOverrideManager::ResetToCurrentNewGRFConfig();
837
838 /* Make sure all industries were built "this year", to avoid too early closures. (#9918) */
839 for (Industry *i : Industry::Iterate()) {
840 i->last_prod_year = TimerGameEconomy::year;
841 }
842}
843
848 static void OnStartGame(bool dedicated_server)
849{
850 /* Update the local company for a loaded game. It is either the first available company
851 * or in the case of a dedicated server, a spectator */
852 SetLocalCompany(dedicated_server ? COMPANY_SPECTATOR : GetFirstPlayableCompanyID());
853
854 NetworkOnGameStart();
855
856 /* Execute the game-start script */
857 IConsoleCmdExec("exec scripts/game_start.scr 0");
858}
859
860static void MakeNewGameDone()
861{
862 SettingsDisableElrail(_settings_game.vehicle.disable_elrails);
863
864 /* In a dedicated server, the server does not play */
865 if (!VideoDriver::GetInstance()->HasGUI()) {
866 OnStartGame(true);
867 if (_settings_client.gui.pause_on_newgame) Command<CMD_PAUSE>::Post(PM_PAUSED_NORMAL, true);
868 return;
869 }
870
871 /* Create a single company */
872 DoStartupNewCompany(false);
873
874 Company *c = Company::Get(COMPANY_FIRST);
875 c->settings = _settings_client.company;
876
877 /* Overwrite color from settings if needed
878 * COLOUR_END corresponds to Random colour */
879
880 if (_settings_client.gui.starting_colour != COLOUR_END) {
881 c->colour = _settings_client.gui.starting_colour;
882 ResetCompanyLivery(c);
883 _company_colours[c->index] = c->colour;
884 }
885
886 if (_settings_client.gui.starting_colour_secondary != COLOUR_END && HasBit(_loaded_newgrf_features.used_liveries, LS_DEFAULT)) {
887 Command<CMD_SET_COMPANY_COLOUR>::Post(LS_DEFAULT, false, _settings_client.gui.starting_colour_secondary);
888 }
889
890 OnStartGame(false);
891
892 InitializeRailGUI();
893 InitializeRoadGUI();
894
895 if (_settings_client.gui.pause_on_newgame) Command<CMD_PAUSE>::Post(PM_PAUSED_NORMAL, true);
896
897 CheckEngines();
898 CheckIndustries();
899 MarkWholeScreenDirty();
900}
901
902static void MakeNewGame(bool from_heightmap, bool reset_settings)
903{
904 _game_mode = GM_NORMAL;
905 if (!from_heightmap) {
906 /* "reload" command needs to know what mode we were in. */
907 _file_to_saveload.SetMode(SLO_INVALID, FT_INVALID, DFT_INVALID);
908 }
909
910 ResetGRFConfig(true);
911
912 GenerateWorldSetCallback(&MakeNewGameDone);
913 GenerateWorld(from_heightmap ? GWM_HEIGHTMAP : GWM_NEWGAME, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y, reset_settings);
914}
915
916static void MakeNewEditorWorldDone()
917{
918 SetLocalCompany(OWNER_NONE);
919}
920
921static void MakeNewEditorWorld()
922{
923 _game_mode = GM_EDITOR;
924 /* "reload" command needs to know what mode we were in. */
925 _file_to_saveload.SetMode(SLO_INVALID, FT_INVALID, DFT_INVALID);
926
927 ResetGRFConfig(true);
928
929 GenerateWorldSetCallback(&MakeNewEditorWorldDone);
930 GenerateWorld(GWM_EMPTY, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
931}
932
943 bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, std::shared_ptr<LoadFilter> lf = nullptr)
944{
945 assert(fop == SLO_LOAD);
946 assert(dft == DFT_GAME_FILE || (lf == nullptr && dft == DFT_OLD_GAME_FILE));
947 GameMode ogm = _game_mode;
948
949 _game_mode = newgm;
950
951 SaveOrLoadResult result = (lf == nullptr) ? SaveOrLoad(filename, fop, dft, subdir) : LoadWithFilter(lf);
952 if (result == SL_OK) return true;
953
954 if (_network_dedicated && ogm == GM_MENU) {
955 /*
956 * If we are a dedicated server *and* we just were in the menu, then we
957 * are loading the first savegame. If that fails, not starting the
958 * server is a better reaction than starting the server with a newly
959 * generated map as it is quite likely to be started from a script.
960 */
961 Debug(net, 0, "Loading requested map failed; closing server.");
962 _exit_game = true;
963 return false;
964 }
965
966 if (result != SL_REINIT) {
967 _game_mode = ogm;
968 return false;
969 }
970
971 if (_network_dedicated) {
972 /*
973 * If we are a dedicated server, have already loaded/started a game,
974 * and then loading the savegame fails in a manner that we need to
975 * reinitialize everything. We must not fall back into the menu mode
976 * with the intro game, as that is unjoinable by clients. So there is
977 * nothing else to do than start a new game, as it might have failed
978 * trying to reload the originally loaded savegame/scenario.
979 */
980 Debug(net, 0, "Loading game failed, so a new (random) game will be started");
981 MakeNewGame(false, true);
982 return false;
983 }
984
985 if (_network_server) {
986 /* We can't load the intro game as server, so disconnect first. */
987 NetworkDisconnect();
988 }
989
990 switch (ogm) {
991 default:
992 case GM_MENU: LoadIntroGame(); break;
993 case GM_EDITOR: MakeNewEditorWorld(); break;
994 }
995 return false;
996}
997
998static void UpdateSocialIntegration(GameMode game_mode)
999{
1000 switch (game_mode) {
1001 case GM_BOOTSTRAP:
1002 case GM_MENU:
1003 SocialIntegration::EventEnterMainMenu();
1004 break;
1005
1006 case GM_NORMAL:
1007 if (_networking) {
1008 SocialIntegration::EventEnterMultiplayer(Map::SizeX(), Map::SizeY());
1009 } else {
1010 SocialIntegration::EventEnterSingleplayer(Map::SizeX(), Map::SizeY());
1011 }
1012 break;
1013
1014 case GM_EDITOR:
1015 SocialIntegration::EventEnterScenarioEditor(Map::SizeX(), Map::SizeY());
1016 break;
1017 }
1018}
1019
1020void SwitchToMode(SwitchMode new_mode)
1021{
1022 /* If we are saving something, the network stays in its current state */
1023 if (new_mode != SM_SAVE_GAME) {
1024 /* If the network is active, make it not-active */
1025 if (_networking) {
1026 if (_network_server && (new_mode == SM_LOAD_GAME || new_mode == SM_NEWGAME || new_mode == SM_RESTARTGAME)) {
1027 NetworkReboot();
1028 } else {
1029 NetworkDisconnect();
1030 }
1031 }
1032
1033 /* If we are a server, we restart the server */
1034 if (_is_network_server) {
1035 /* But not if we are going to the menu */
1036 if (new_mode != SM_MENU) {
1037 /* check if we should reload the config */
1038 if (_settings_client.network.reload_cfg) {
1039 LoadFromConfig();
1040 MakeNewgameSettingsLive();
1041 ResetGRFConfig(false);
1042 }
1043 NetworkServerStart();
1044 } else {
1045 /* This client no longer wants to be a network-server */
1046 _is_network_server = false;
1047 }
1048 }
1049 }
1050
1051 /* Make sure all AI controllers are gone at quitting game */
1052 if (new_mode != SM_SAVE_GAME) AI::KillAll();
1053
1054 /* When we change mode, reset the autosave. */
1055 if (new_mode != SM_SAVE_GAME) ChangeAutosaveFrequency(true);
1056
1057 /* Transmit the survey if we were in normal-mode and not saving. It always means we leaving the current game. */
1058 if (_game_mode == GM_NORMAL && new_mode != SM_SAVE_GAME) _survey.Transmit(NetworkSurveyHandler::Reason::LEAVE);
1059
1060 /* Keep track when we last switch mode. Used for survey, to know how long someone was in a game. */
1061 if (new_mode != SM_SAVE_GAME) {
1062 _game_session_stats.start_time = std::chrono::steady_clock::now();
1063 _game_session_stats.savegame_size = std::nullopt;
1064 }
1065
1066 switch (new_mode) {
1067 case SM_EDITOR: // Switch to scenario editor
1068 MakeNewEditorWorld();
1069 GenerateSavegameId();
1070
1071 UpdateSocialIntegration(GM_EDITOR);
1072 break;
1073
1074 case SM_RELOADGAME: // Reload with what-ever started the game
1075 if (_file_to_saveload.abstract_ftype == FT_SAVEGAME || _file_to_saveload.abstract_ftype == FT_SCENARIO) {
1076 /* Reload current savegame/scenario */
1077 _switch_mode = _game_mode == GM_EDITOR ? SM_LOAD_SCENARIO : SM_LOAD_GAME;
1078 SwitchToMode(_switch_mode);
1079 break;
1080 } else if (_file_to_saveload.abstract_ftype == FT_HEIGHTMAP) {
1081 /* Restart current heightmap */
1082 _switch_mode = _game_mode == GM_EDITOR ? SM_LOAD_HEIGHTMAP : SM_RESTART_HEIGHTMAP;
1083 SwitchToMode(_switch_mode);
1084 break;
1085 }
1086
1087 MakeNewGame(false, new_mode == SM_NEWGAME);
1088 GenerateSavegameId();
1089
1090 UpdateSocialIntegration(GM_NORMAL);
1091 break;
1092
1093 case SM_RESTARTGAME: // Restart --> 'Random game' with current settings
1094 case SM_NEWGAME: // New Game --> 'Random game'
1095 MakeNewGame(false, new_mode == SM_NEWGAME);
1096 GenerateSavegameId();
1097
1098 UpdateSocialIntegration(GM_NORMAL);
1099 break;
1100
1101 case SM_LOAD_GAME: { // Load game, Play Scenario
1102 ResetGRFConfig(true);
1103 ResetWindowSystem();
1104
1105 if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_NORMAL, NO_DIRECTORY)) {
1106 ShowErrorMessage(GetSaveLoadErrorType(), GetSaveLoadErrorMessage(), WL_CRITICAL);
1107 } else {
1108 if (_file_to_saveload.abstract_ftype == FT_SCENARIO) {
1109 OnStartScenario();
1110 }
1111 OnStartGame(_network_dedicated);
1112 /* Decrease pause counter (was increased from opening load dialog) */
1113 Command<CMD_PAUSE>::Post(PM_PAUSED_SAVELOAD, false);
1114 }
1115
1116 UpdateSocialIntegration(GM_NORMAL);
1117 break;
1118 }
1119
1120 case SM_RESTART_HEIGHTMAP: // Load a heightmap and start a new game from it with current settings
1121 case SM_START_HEIGHTMAP: // Load a heightmap and start a new game from it
1122 MakeNewGame(true, new_mode == SM_START_HEIGHTMAP);
1123 GenerateSavegameId();
1124
1125 UpdateSocialIntegration(GM_NORMAL);
1126 break;
1127
1128 case SM_LOAD_HEIGHTMAP: // Load heightmap from scenario editor
1129 SetLocalCompany(OWNER_NONE);
1130
1131 _game_mode = GM_EDITOR;
1132
1133 GenerateWorld(GWM_HEIGHTMAP, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
1134 GenerateSavegameId();
1135 MarkWholeScreenDirty();
1136
1137 UpdateSocialIntegration(GM_EDITOR);
1138 break;
1139
1140 case SM_LOAD_SCENARIO: { // Load scenario from scenario editor
1141 if (SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_EDITOR, NO_DIRECTORY)) {
1142 SetLocalCompany(OWNER_NONE);
1143 GenerateSavegameId();
1144 _settings_newgame.game_creation.starting_year = TimerGameCalendar::year;
1145 /* Cancel the saveload pausing */
1146 Command<CMD_PAUSE>::Post(PM_PAUSED_SAVELOAD, false);
1147 } else {
1148 ShowErrorMessage(GetSaveLoadErrorType(), GetSaveLoadErrorMessage(), WL_CRITICAL);
1149 }
1150
1151 UpdateSocialIntegration(GM_EDITOR);
1152 break;
1153 }
1154
1155 case SM_JOIN_GAME: // Join a multiplayer game
1156 LoadIntroGame();
1157 NetworkClientJoinGame();
1158
1159 SocialIntegration::EventJoiningMultiplayer();
1160 break;
1161
1162 case SM_MENU: // Switch to game intro menu
1163 LoadIntroGame();
1164 if (BaseSounds::ini_set.empty() && BaseSounds::GetUsedSet()->fallback && SoundDriver::GetInstance()->HasOutput()) {
1165 ShowErrorMessage(STR_WARNING_FALLBACK_SOUNDSET, INVALID_STRING_ID, WL_CRITICAL);
1166 BaseSounds::ini_set = BaseSounds::GetUsedSet()->name;
1167 }
1168 if (_settings_client.network.participate_survey == PS_ASK) {
1169 /* No matter how often you go back to the main menu, only ask the first time. */
1170 static bool asked_once = false;
1171 if (!asked_once) {
1172 asked_once = true;
1173 ShowNetworkAskSurvey();
1174 }
1175 }
1176
1177 UpdateSocialIntegration(GM_MENU);
1178 break;
1179
1180 case SM_SAVE_GAME: // Save game.
1181 /* Make network saved games on pause compatible to singleplayer mode */
1182 if (SaveOrLoad(_file_to_saveload.name, SLO_SAVE, DFT_GAME_FILE, NO_DIRECTORY) != SL_OK) {
1183 ShowErrorMessage(GetSaveLoadErrorType(), GetSaveLoadErrorMessage(), WL_ERROR);
1184 } else {
1185 CloseWindowById(WC_SAVELOAD, 0);
1186 }
1187 break;
1188
1189 case SM_SAVE_HEIGHTMAP: // Save heightmap.
1190 MakeHeightmapScreenshot(_file_to_saveload.name.c_str());
1191 CloseWindowById(WC_SAVELOAD, 0);
1192 break;
1193
1194 case SM_GENRANDLAND: // Generate random land within scenario editor
1195 SetLocalCompany(OWNER_NONE);
1196 GenerateWorld(GWM_RANDOM, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
1197 /* XXX: set date */
1198 MarkWholeScreenDirty();
1199 break;
1200
1201 default: NOT_REACHED();
1202 }
1203}
1204
1205
1206
1212 void StateGameLoop()
1213{
1214 if (!_networking || _network_server) {
1215 StateGameLoop_LinkGraphPauseControl();
1216 }
1217
1218 /* Don't execute the state loop during pause or when modal windows are open. */
1219 if (_pause_mode != PM_UNPAUSED || HasModalProgress()) {
1220 PerformanceMeasurer::Paused(PFE_GAMELOOP);
1221 PerformanceMeasurer::Paused(PFE_GL_ECONOMY);
1222 PerformanceMeasurer::Paused(PFE_GL_TRAINS);
1223 PerformanceMeasurer::Paused(PFE_GL_ROADVEHS);
1224 PerformanceMeasurer::Paused(PFE_GL_SHIPS);
1225 PerformanceMeasurer::Paused(PFE_GL_AIRCRAFT);
1226 PerformanceMeasurer::Paused(PFE_GL_LANDSCAPE);
1227
1228 if (!HasModalProgress()) UpdateLandscapingLimits();
1229#ifndef DEBUG_DUMP_COMMANDS
1230 Game::GameLoop();
1231#endif
1232 return;
1233 }
1234
1235 PerformanceMeasurer framerate(PFE_GAMELOOP);
1236 PerformanceAccumulator::Reset(PFE_GL_LANDSCAPE);
1237
1238 Layouter::ReduceLineCache();
1239
1240 if (_game_mode == GM_EDITOR) {
1241 BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
1242 RunTileLoop();
1243 CallVehicleTicks();
1244 CallLandscapeTick();
1245 BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
1246 UpdateLandscapingLimits();
1247
1248 CallWindowGameTickEvent();
1249 NewsLoop();
1250 } else {
1251 if (_debug_desync_level > 2 && TimerGameEconomy::date_fract == 0 && (TimerGameEconomy::date.base() & 0x1F) == 0) {
1252 /* Save the desync savegame if needed. */
1253 std::string name = fmt::format("dmp_cmds_{:08x}_{:08x}.sav", _settings_game.game_creation.generation_seed, TimerGameEconomy::date);
1254 SaveOrLoad(name, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);
1255 }
1256
1257 CheckCaches();
1258
1259 /* All these actions has to be done from OWNER_NONE
1260 * for multiplayer compatibility */
1261 Backup<CompanyID> cur_company(_current_company, OWNER_NONE);
1262
1263 BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
1264 AnimateAnimatedTiles();
1265 if (TimerManager<TimerGameCalendar>::Elapsed(1)) {
1266 RunVehicleCalendarDayProc();
1267 }
1268 TimerManager<TimerGameEconomy>::Elapsed(1);
1269 TimerManager<TimerGameTick>::Elapsed(1);
1270 RunTileLoop();
1271 CallVehicleTicks();
1272 CallLandscapeTick();
1273 BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
1274
1275#ifndef DEBUG_DUMP_COMMANDS
1276 {
1277 PerformanceMeasurer script_framerate(PFE_ALLSCRIPTS);
1278 AI::GameLoop();
1279 Game::GameLoop();
1280 }
1281#endif
1282 UpdateLandscapingLimits();
1283
1284 CallWindowGameTickEvent();
1285 NewsLoop();
1286 cur_company.Restore();
1287 }
1288
1289 assert(IsLocalCompany());
1290}
1291
1293 static IntervalTimer<TimerGameRealtime> _autosave_interval({std::chrono::milliseconds::zero(), TimerGameRealtime::AUTOSAVE}, [](auto)
1294{
1295 /* We reset the command-during-pause mode here, so we don't continue
1296 * to make auto-saves when nothing more is changing. */
1297 _pause_mode &= ~PM_COMMAND_DURING_PAUSE;
1298
1299 _do_autosave = true;
1300 SetWindowDirty(WC_STATUS_BAR, 0);
1301
1302 static FiosNumberedSaveName _autosave_ctr("autosave");
1303 DoAutoOrNetsave(_autosave_ctr);
1304
1305 _do_autosave = false;
1306 SetWindowDirty(WC_STATUS_BAR, 0);
1307});
1308
1318 void ChangeAutosaveFrequency(bool reset)
1319{
1320 _autosave_interval.SetInterval({std::chrono::minutes(_settings_client.gui.autosave_interval), TimerGameRealtime::AUTOSAVE}, reset);
1321}
1322
1331 bool RequestNewGRFScan(NewGRFScanCallback *callback)
1332{
1333 if (_request_newgrf_scan) return false;
1334
1335 _request_newgrf_scan = true;
1336 _request_newgrf_scan_callback = callback;
1337 return true;
1338}
1339
1340void GameLoop()
1341{
1342 if (_game_mode == GM_BOOTSTRAP) {
1343 /* Check for UDP stuff */
1344 if (_network_available) NetworkBackgroundLoop();
1345 return;
1346 }
1347
1348 if (_request_newgrf_scan) {
1349 ScanNewGRFFiles(_request_newgrf_scan_callback);
1350 _request_newgrf_scan = false;
1351 _request_newgrf_scan_callback = nullptr;
1352 /* In case someone closed the game during our scan, don't do anything else. */
1353 if (_exit_game) return;
1354 }
1355
1356 ProcessAsyncSaveFinish();
1357
1358 if (_game_mode == GM_NORMAL) {
1359 static auto last_time = std::chrono::steady_clock::now();
1360 auto now = std::chrono::steady_clock::now();
1361 auto delta_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_time);
1362 if (delta_ms.count() != 0) {
1363 TimerManager<TimerGameRealtime>::Elapsed(delta_ms);
1364 last_time = now;
1365 }
1366 }
1367
1368 /* switch game mode? */
1369 if (_switch_mode != SM_NONE && !HasModalProgress()) {
1370 SwitchToMode(_switch_mode);
1371 _switch_mode = SM_NONE;
1372 if (_exit_game) return;
1373 }
1374
1375 IncreaseSpriteLRU();
1376
1377 /* Check for UDP stuff */
1378 if (_network_available) NetworkBackgroundLoop();
1379
1380 DebugSendRemoteMessages();
1381
1382 if (_networking && !HasModalProgress()) {
1383 /* Multiplayer */
1384 NetworkGameLoop();
1385 } else {
1386 if (_network_reconnect > 0 && --_network_reconnect == 0) {
1387 /* This means that we want to reconnect to the last host
1388 * We do this here, because it means that the network is really closed */
1389 NetworkClientConnectGame(_settings_client.network.last_joined, COMPANY_SPECTATOR);
1390 }
1391 /* Singleplayer */
1392 StateGameLoop();
1393 }
1394
1395 if (!_pause_mode && HasBit(_display_opt, DO_FULL_ANIMATION)) DoPaletteAnimations();
1396
1397 SoundDriver::GetInstance()->MainLoop();
1398 MusicLoop();
1399 SocialIntegration::RunCallbacks();
1400}
ai.hpp
Base functions for all AIs.
ai_config.hpp
AIConfig stores the configuration settings of every AI.
aircraft.h
Base for aircraft.
AnimateAnimatedTiles
void AnimateAnimatedTiles()
Animate all tiles in the animated tile list, i.e. call AnimateTile on them.
Definition animated_tile.cpp:75
animated_tile_func.h
Tile animation!
backup_type.hpp
Class for backupping variables and making sure they are restored later.
base_media_base.h
Generic functions for replacing base data (graphics, sounds).
BLT_8BPP
@ BLT_8BPP
Base set has 8 bpp sprites only.
Definition base_media_base.h:253
HasBit
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
BSWAP32
static uint32_t BSWAP32(uint32_t x)
Perform a 32 bits endianness bitswap on x.
Definition bitmath_func.hpp:364
AIConfig
Definition ai_config.hpp:16
AI::Uninitialize
static void Uninitialize(bool keepConfig)
Uninitialize the AI system.
Definition ai_core.cpp:179
AI::Initialize
static void Initialize()
Initialize the AI system.
Definition ai_core.cpp:165
AI::GetConsoleList
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Wrapper function for AIScanner::GetAIConsoleList.
Definition ai_core.cpp:296
AI::GameLoop
static void GameLoop()
Called every game-tick to let AIs do something.
Definition ai_core.cpp:74
AI::KillAll
static void KillAll()
Kill any and all AIs we manage.
Definition ai_core.cpp:155
BaseMedia< GraphicsSet >::GetUsedSet
static const GraphicsSet * GetUsedSet()
Return the used set.
Definition base_media_func.h:394
BaseMedia< GraphicsSet >::SetSetByShortname
static bool SetSetByShortname(uint32_t shortname)
Set the set to be used.
Definition base_media_func.h:278
BaseMedia< GraphicsSet >::GetSetsList
static void GetSetsList(std::back_insert_iterator< std::string > &output_iterator)
Returns a list with the sets.
Definition base_media_func.h:297
BaseMedia< GraphicsSet >::FindSets
static uint FindSets()
Do the scan for files.
Definition base_media_base.h:198
BaseMedia< GraphicsSet >::SetSetByName
static bool SetSetByName(const std::string &name)
Set the set to be used.
Definition base_media_func.h:258
BaseMedia< GraphicsSet >::SetSet
static bool SetSet(const GraphicsSet *set)
Set the set to be used.
Definition base_media_func.h:241
BaseMusic::ini_set
static std::string ini_set
The set as saved in the config file.
Definition base_media_base.h:350
BaseSounds::ini_set
static std::string ini_set
The set as saved in the config file.
Definition base_media_base.h:301
BlitterFactory::GetBlittersInfo
static void GetBlittersInfo(std::back_insert_iterator< std::string > &output_iterator)
Fill a buffer with information about the blitters.
Definition factory.hpp:149
BlitterFactory::SelectBlitter
static Blitter * SelectBlitter(const std::string_view name)
Find the requested blitter and return its class.
Definition factory.hpp:96
CrashLog::SetErrorMessage
static void SetErrorMessage(const std::string &message)
Sets a message for the error message handler.
Definition crashlog.cpp:327
DriverFactoryBase::ShutdownDrivers
static void ShutdownDrivers()
Shuts down all active drivers.
Definition driver.h:123
DriverFactoryBase::SelectDriver
static void SelectDriver(const std::string &name, Driver::Type type)
Find the requested driver and return its class.
Definition driver.cpp:88
DriverFactoryBase::GetDriversInfo
static void GetDriversInfo(std::back_insert_iterator< std::string > &output_iterator)
Build a human readable list of available drivers, grouped by type.
Definition driver.cpp:219
Driver::Stop
virtual void Stop()=0
Stop this driver.
Driver::DT_VIDEO
@ DT_VIDEO
A video driver.
Definition driver.h:42
Driver::DT_SOUND
@ DT_SOUND
A sound driver.
Definition driver.h:41
Driver::DT_MUSIC
@ DT_MUSIC
A music driver, needs to be before sound to properly shut down extmidi forked music players.
Definition driver.h:40
ErrorMessageData
The data of the error message.
Definition error.h:31
ErrorMessageData::SetDParamStr
void SetDParamStr(uint n, const char *str)
Set a rawstring parameter.
Definition error_gui.cpp:146
GameConfig
Definition game_config.hpp:15
Game::GameLoop
static void GameLoop()
Called every game-tick to let Game do something.
Definition game_core.cpp:31
Game::GetConsoleList
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Wrapper function for GameScanner::GetConsoleList.
Definition game_core.cpp:217
Game::Uninitialize
static void Uninitialize(bool keepConfig)
Uninitialize the Game system.
Definition game_core.cpp:102
Game::Initialize
static void Initialize()
Initialize the Game system.
Definition game_core.cpp:57
Gamelog::Info
void Info(uint32_t *last_ottd_rev, uint8_t *ever_modified, bool *removed_newgrfs)
Get some basic information from the given gamelog.
Definition gamelog.cpp:685
Gamelog::Reset
void Reset()
Resets and frees all memory allocated - used before loading or starting a new game.
Definition gamelog.cpp:94
IntervalTimer
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
IntervalTimer::SetInterval
void SetInterval(const TPeriod interval, bool reset=true)
Set a new interval for the timer.
Definition timer.h:99
Layouter::ReduceLineCache
static void ReduceLineCache()
Reduce the size of linecache if necessary to prevent infinite growth.
Definition gfx_layout.cpp:405
LinkGraphSchedule::Clear
static void Clear()
Clear all link graphs and jobs from the schedule.
Definition linkgraphschedule.cpp:121
MusicDriver::GetInstance
static MusicDriver * GetInstance()
Get the currently active instance of the music driver.
Definition music_driver.hpp:46
MusicDriver::SetVolume
virtual void SetVolume(uint8_t vol)=0
Set the volume, if possible.
NetworkSurveyHandler::Reason::EXIT
@ EXIT
User is exiting the application.
NetworkSurveyHandler::Reason::LEAVE
@ LEAVE
User is leaving the game (but not exiting the application).
NetworkSurveyHandler::Transmit
void Transmit(Reason reason, bool blocking=false)
Transmit the survey.
Definition network_survey.cpp:86
PerformanceAccumulator::Reset
static void Reset(PerformanceElement elem)
Store the previous accumulator value and reset for a new cycle of accumulating measurements.
Definition framerate_gui.cpp:328
PerformanceMeasurer
RAII class for measuring simple elements of performance.
Definition framerate_type.h:92
PerformanceMeasurer::Paused
static void Paused(PerformanceElement elem)
Indicate that a cycle of "pause" where no processing occurs.
Definition framerate_gui.cpp:298
SocialIntegration::EventEnterScenarioEditor
static void EventEnterScenarioEditor(uint map_width, uint map_height)
Event: user entered the Scenario Editor.
Definition social_integration.cpp:220
SocialIntegration::EventEnterSingleplayer
static void EventEnterSingleplayer(uint map_width, uint map_height)
Event: user entered a singleplayer game.
Definition social_integration.cpp:227
SocialIntegration::RunCallbacks
static void RunCallbacks()
Allow any social integration library to handle their own events.
Definition social_integration.cpp:194
SocialIntegration::EventEnterMultiplayer
static void EventEnterMultiplayer(uint map_width, uint map_height)
Event: user entered a multiplayer game.
Definition social_integration.cpp:234
SocialIntegration::Shutdown
static void Shutdown()
Shutdown the social integration system, and all social integration plugins that are loaded.
Definition social_integration.cpp:184
SocialIntegration::EventEnterMainMenu
static void EventEnterMainMenu()
Event: user entered the main menu.
Definition social_integration.cpp:213
SocialIntegration::EventJoiningMultiplayer
static void EventJoiningMultiplayer()
Event: user is joining a multiplayer game.
Definition social_integration.cpp:241
SocialIntegration::Initialize
static void Initialize()
Initialize the social integration system, loading any social integration plugins that are available.
Definition social_integration.cpp:160
SoundDriver::MainLoop
virtual void MainLoop()
Called once every tick.
Definition sound_driver.hpp:19
SoundDriver::GetInstance
static SoundDriver * GetInstance()
Get the currently active instance of the sound driver.
Definition sound_driver.hpp:35
TarScanner::DoScan
uint DoScan(Subdirectory sd)
Perform the scanning of a particular subdirectory.
Definition fileio.cpp:375
TarScanner::BASESET
@ BASESET
Scan for base sets.
Definition fileio_func.h:65
TarScanner::SCENARIO
@ SCENARIO
Scan for scenarios and heightmaps.
Definition fileio_func.h:68
TimerGameCalendar::year
static Year year
Current year, starting at 0.
Definition timer_game_calendar.h:31
TimerGameConst< struct Calendar >::INVALID_YEAR
static constexpr TimerGame< struct Calendar >::Year INVALID_YEAR
Representation of an invalid year.
Definition timer_game_common.h:192
TimerGameEconomy::date
static Date date
Current date in days (day counter).
Definition timer_game_economy.h:38
TimerGameEconomy::year
static Year year
Current year, starting at 0.
Definition timer_game_economy.h:36
TimerGameEconomy::date_fract
static DateFract date_fract
Fractional part of the day.
Definition timer_game_economy.h:39
TimerGameRealtime::AUTOSAVE
@ AUTOSAVE
Only run when not paused or there was a Command executed recently.
Definition timer_game_realtime.h:33
TimerManager
The TimerManager manages a single Timer-type.
Definition timer_manager.h:27
TimerManager::Elapsed
static bool Elapsed(TElapsed value)
Called when time for this timer elapsed.
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition video_driver.hpp:201
VideoDriver::MainLoop
virtual void MainLoop()=0
Perform the actual drawing.
command_func.h
Functions related to commands.
_company_colours
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
Definition company_cmd.cpp:54
ResetCompanyLivery
void ResetCompanyLivery(Company *c)
Reset the livery schemes to the company's primary colour.
Definition company_cmd.cpp:561
GetFirstPlayableCompanyID
CompanyID GetFirstPlayableCompanyID()
Get the index of the first available company.
Definition company_cmd.cpp:1337
UpdateLandscapingLimits
void UpdateLandscapingLimits()
Update the landscaping limits per company.
Definition company_cmd.cpp:318
SetLocalCompany
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...
Definition company_cmd.cpp:117
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:53
company_cmd.h
Command definitions related to companies.
company_func.h
Functions related to companies.
IsLocalCompany
bool IsLocalCompany()
Is the current company the local company?
Definition company_func.h:47
Owner
Owner
Enum for all companies/owners.
Definition company_type.h:18
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition company_type.h:30
COMPANY_SPECTATOR
@ COMPANY_SPECTATOR
The client is spectating.
Definition company_type.h:35
COMPANY_FIRST
@ COMPANY_FIRST
First company, same as owner.
Definition company_type.h:22
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition company_type.h:25
COMPANY_NEW_COMPANY
@ COMPANY_NEW_COMPANY
The client wants a new company.
Definition company_type.h:34
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition company_type.h:23
IConsoleCmdExec
void IConsoleCmdExec(const std::string &command_string, const uint recurse_count)
Execute a given command passed to us.
Definition console.cpp:291
console_func.h
Console functions used outside of the console code.
crashlog.h
Functions to be called to log a crash.
SetDebugString
void SetDebugString(const char *s, void(*error_func)(const std::string &))
Set debugging levels by parsing the text in s.
Definition debug.cpp:143
DumpDebugFacilityNames
void DumpDebugFacilityNames(std::back_insert_iterator< std::string > &output_iterator)
Dump the available debug facility names in the help text.
Definition debug.cpp:87
DebugSendRemoteMessages
void DebugSendRemoteMessages()
Send the queued Debug messages to either NetworkAdminConsole or IConsolePrint from the GameLoop threa...
Definition debug.cpp:240
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition debug.h:37
_ini_videodriver
std::string _ini_videodriver
The video driver a stored in the configuration file.
Definition driver.cpp:24
_ini_musicdriver
std::string _ini_musicdriver
The music driver a stored in the configuration file.
Definition driver.cpp:31
_cur_resolution
Dimension _cur_resolution
The current resolution.
Definition driver.cpp:26
_ini_sounddriver
std::string _ini_sounddriver
The sound driver a stored in the configuration file.
Definition driver.cpp:29
SettingsDisableElrail
void SettingsDisableElrail(int32_t new_value)
_settings_game.disable_elrail callback
Definition elrail.cpp:598
elrail_func.h
header file for electrified rail specific functions
CheckEngines
void CheckEngines()
Check for engines that have an appropriate availability.
Definition engine.cpp:1321
engine_func.h
Functions related to engines.
error.h
Functions related to errors.
ScheduleErrorMessage
void ScheduleErrorMessage(ErrorList &datas)
Schedule a list of errors.
Definition error_gui.cpp:452
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition error_gui.cpp:367
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition error.h:26
WL_CRITICAL
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition error.h:27
error_func.h
Error reporting related functions.
factory.hpp
Factory to 'query' all available blitters.
_blitter_autodetected
bool _blitter_autodetected
Was the blitter autodetected or specified by the user?
Definition driver.cpp:34
_ini_blitter
std::string _ini_blitter
The blitter as stored in the configuration file.
Definition driver.cpp:33
DeterminePaths
void DeterminePaths(const char *exe, bool only_local_path)
Acquire the base paths (personal dir and game data dir), fill all other paths (save dir,...
Definition fileio.cpp:878
GetDetailedFileType
DetailedFileType GetDetailedFileType(FiosType fios_type)
Extract the detailed file type from a FiosType.
Definition fileio_type.h:107
GetAbstractFileType
AbstractFileType GetAbstractFileType(FiosType fios_type)
Extract the abstract file type from a FiosType.
Definition fileio_type.h:97
FT_SCENARIO
@ FT_SCENARIO
old or new scenario
Definition fileio_type.h:19
FT_HEIGHTMAP
@ FT_HEIGHTMAP
heightmap file
Definition fileio_type.h:20
FT_SAVEGAME
@ FT_SAVEGAME
old or new savegame
Definition fileio_type.h:18
FT_INVALID
@ FT_INVALID
Invalid or unknown file type.
Definition fileio_type.h:23
SaveLoadOperation
SaveLoadOperation
Operation performed on the file.
Definition fileio_type.h:53
SLO_CHECK
@ SLO_CHECK
Load file for checking and/or preview.
Definition fileio_type.h:54
SLO_SAVE
@ SLO_SAVE
File is being saved.
Definition fileio_type.h:56
SLO_LOAD
@ SLO_LOAD
File is being loaded.
Definition fileio_type.h:55
SLO_INVALID
@ SLO_INVALID
Unknown file operation.
Definition fileio_type.h:58
DetailedFileType
DetailedFileType
Kinds of files in each AbstractFileType.
Definition fileio_type.h:29
DFT_GAME_FILE
@ DFT_GAME_FILE
Save game or scenario file.
Definition fileio_type.h:32
DFT_INVALID
@ DFT_INVALID
Unknown or invalid file.
Definition fileio_type.h:49
DFT_OLD_GAME_FILE
@ DFT_OLD_GAME_FILE
Old save game or scenario file.
Definition fileio_type.h:31
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition fileio_type.h:115
NO_DIRECTORY
@ NO_DIRECTORY
A path without any base directory.
Definition fileio_type.h:133
SAVE_DIR
@ SAVE_DIR
Base directory for all savegames.
Definition fileio_type.h:117
AUTOSAVE_DIR
@ AUTOSAVE_DIR
Subdirectory of save for autosaves.
Definition fileio_type.h:118
BASESET_DIR
@ BASESET_DIR
Subdirectory for all base data (base sets, intro game)
Definition fileio_type.h:123
FiosGetSavegameListCallback
std::tuple< FiosType, std::string > FiosGetSavegameListCallback(SaveLoadOperation fop, const std::string &file, const std::string_view ext)
Callback for FiosGetFileList.
Definition fios.cpp:413
FiosGetScenarioListCallback
std::tuple< FiosType, std::string > FiosGetScenarioListCallback(SaveLoadOperation fop, const std::string &file, const std::string_view ext)
Callback for FiosGetFileList.
Definition fios.cpp:462
fios.h
Declarations for savegames operations.
_load_check_data
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition fios_gui.cpp:41
InitFontCache
void InitFontCache(bool monospace)
(Re)initialize the font cache related things, i.e.
Definition fontcache.cpp:218
UninitFontCache
void UninitFontCache()
Free everything allocated w.r.t.
Definition fontcache.cpp:241
fontcache.h
Functions to read fonts from files and cache them.
framerate_type.h
Types for recording game performance data.
PFE_GAMELOOP
@ PFE_GAMELOOP
Speed of gameloop processing.
Definition framerate_type.h:49
PFE_GL_SHIPS
@ PFE_GL_SHIPS
Time spent processing ships.
Definition framerate_type.h:53
PFE_GL_AIRCRAFT
@ PFE_GL_AIRCRAFT
Time spent processing aircraft.
Definition framerate_type.h:54
PFE_GL_ECONOMY
@ PFE_GL_ECONOMY
Time spent processing cargo movement.
Definition framerate_type.h:50
PFE_GL_LANDSCAPE
@ PFE_GL_LANDSCAPE
Time spent processing other world features.
Definition framerate_type.h:55
PFE_GL_ROADVEHS
@ PFE_GL_ROADVEHS
Time spend processing road vehicles.
Definition framerate_type.h:52
PFE_GL_TRAINS
@ PFE_GL_TRAINS
Time spent processing trains.
Definition framerate_type.h:51
PFE_ALLSCRIPTS
@ PFE_ALLSCRIPTS
Sum of all GS/AI scripts.
Definition framerate_type.h:61
game.hpp
Base functions for all Games.
game_config.hpp
GameConfig stores the configuration settings of every Game.
_sl_version
SaveLoadVersion _sl_version
the major savegame version identifier
Definition saveload.cpp:63
_gamelog
Gamelog _gamelog
Gamelog instance.
Definition gamelog.cpp:31
gamelog.h
Functions to be called to log fundamental changes to the game.
GenerateWorldSetCallback
void GenerateWorldSetCallback(GWDoneProc *proc)
Set here the function, if any, that you want to be called when landscape generation is done.
Definition genworld.cpp:234
GenerateWorld
void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings)
Generate a world.
Definition genworld.cpp:286
genworld.h
Functions related to world/map generation.
GWM_HEIGHTMAP
@ GWM_HEIGHTMAP
Generate a newgame from a heightmap.
Definition genworld.h:31
GWM_EMPTY
@ GWM_EMPTY
Generate an empty map (sea-level)
Definition genworld.h:29
GWM_RANDOM
@ GWM_RANDOM
Generate a random map for SE.
Definition genworld.h:30
GWM_NEWGAME
@ GWM_NEWGAME
Generate a map for a new game.
Definition genworld.h:28
GENERATE_NEW_SEED
static const uint32_t GENERATE_NEW_SEED
Create a new random seed.
Definition genworld.h:24
getoptdata.h
Library for parsing command-line options.
ODF_OPTIONAL_VALUE
@ ODF_OPTIONAL_VALUE
An option with an optional value.
Definition getoptdata.h:17
ODF_NO_VALUE
@ ODF_NO_VALUE
A plain option (no value attached to it).
Definition getoptdata.h:15
ODF_HAS_VALUE
@ ODF_HAS_VALUE
An option with a value.
Definition getoptdata.h:16
_pause_mode
PauseMode _pause_mode
The current pause mode.
Definition gfx.cpp:50
_game_session_stats
GameSessionStats _game_session_stats
Statistics about the current session.
Definition gfx.cpp:51
UpdateGUIZoom
void UpdateGUIZoom()
Resolve GUI zoom level, if auto-suggestion is requested.
Definition gfx.cpp:1770
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition gfx.cpp:49
gfx_layout.h
Functions related to laying out the texts.
S8BPP_NONE
@ S8BPP_NONE
No support for 8bpp by OS or hardware, force 32bpp blitters.
Definition gfx_type.h:336
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1529
gui.h
GUI functions that shouldn't be here.
LoadFromHighScore
void LoadFromHighScore()
Initialize the highscore table to 0 and if any file exists, load in values.
Definition highscore.cpp:143
SaveToHighScore
void SaveToHighScore()
Save HighScore table to file.
Definition highscore.cpp:120
highscore.h
Declaration of functions and types defined in highscore.h and highscore_gui.h.
LoadHotkeysFromConfig
void LoadHotkeysFromConfig()
Load the hotkeys from the config file.
Definition hotkeys.cpp:340
SaveHotkeysToConfig
void SaveHotkeysToConfig()
Save the hotkeys to the config file.
Definition hotkeys.cpp:346
hotkeys.h
Hotkey related functions.
industry.h
Base of all industries.
CheckIndustries
void CheckIndustries()
Verify whether the generated industries are complete, and warn the user if not.
Definition industry_cmd.cpp:3085
RunTileLoop
void RunTileLoop()
Gradually iterate over all tiles on the map, calling their TileLoopProcs once every TILE_UPDATE_FREQU...
Definition landscape.cpp:769
StateGameLoop_LinkGraphPauseControl
void StateGameLoop_LinkGraphPauseControl()
Pause the game if in 2 TimerGameEconomy::date_fract ticks, we would do a join with the next link grap...
Definition linkgraphschedule.cpp:169
linkgraphschedule.h
Declaration of link graph schedule used for cargo distribution.
SetupColoursAndInitialWindow
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows.
Definition main_gui.cpp:546
GenerateSavegameId
void GenerateSavegameId()
Generate an unique savegame ID.
Definition misc.cpp:87
misc_cmd.h
Miscellaneous command definitions.
mixer.h
Functions to mix sound samples.
music_driver.hpp
Base for all music playback.
NetworkStartUp
void NetworkStartUp()
This tries to launch the network for a given OS.
Definition network.cpp:1283
_is_network_server
bool _is_network_server
Does this client wants to be a network-server?
Definition network.cpp:69
NetworkClientJoinGame
void NetworkClientJoinGame()
Actually perform the joining to the server.
Definition network.cpp:818
NetworkOnGameStart
void NetworkOnGameStart()
Perform tasks when the server is started.
Definition network.cpp:945
_network_available
bool _network_available
is network mode available?
Definition network.cpp:67
_network_reconnect
uint8_t _network_reconnect
Reconnect timeout.
Definition network.cpp:72
_networking
bool _networking
are we in networking mode?
Definition network.cpp:65
ParseFullConnectionString
std::string_view ParseFullConnectionString(const std::string &connection_string, uint16_t &port, CompanyID *company_id)
Converts a string to ip/port/company Format: IP:port::company.
Definition network.cpp:521
_network_dedicated
bool _network_dedicated
are we a dedicated server?
Definition network.cpp:68
NetworkDisconnect
void NetworkDisconnect(bool close_admins)
We want to disconnect from the host/clients.
Definition network.cpp:999
_network_server
bool _network_server
network-server is active
Definition network.cpp:66
NetworkBackgroundLoop
void NetworkBackgroundLoop()
We have to do some (simple) background stuff that runs normally, even when we are not in multiplayer.
Definition network.cpp:1080
_network_bind_list
StringList _network_bind_list
The addresses to bind on.
Definition network.cpp:73
NetworkClientConnectGame
bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const std::string &join_server_password)
Join a client to the server at with the given connection string.
Definition network.cpp:785
NetworkShutDown
void NetworkShutDown()
This shuts the network down.
Definition network.cpp:1301
network.h
Basic functions/variables used all over the place.
network_func.h
Network functions used by other parts of OpenTTD.
ShowNetworkAskSurvey
void ShowNetworkAskSurvey()
Show a modal confirmation window with "no" / "preview" / "yes" buttons.
Definition network_gui.cpp:2426
network_gui.h
GUIs related to networking.
network_survey.h
Part of the network protocol handling opt-in survey.
_loaded_newgrf_features
GRFLoadedFeatures _loaded_newgrf_features
Indicates which are the newgrf features currently loaded ingame.
Definition newgrf.cpp:84
ResetNewGRFData
void ResetNewGRFData()
Reset all NewGRF loaded data.
Definition newgrf.cpp:8827
newgrf.h
Base for the NewGRF implementation.
UpdateNewGRFConfigPalette
void UpdateNewGRFConfigPalette(int32_t)
Update the palettes of the graphics from the config file.
Definition newgrf_config.cpp:227
ResetGRFConfig
void ResetGRFConfig(bool defaults)
Reset the current GRF Config to either blank or newgame settings.
Definition newgrf_config.cpp:431
ScanNewGRFFiles
void ScanNewGRFFiles(NewGRFScanCallback *callback)
Scan for all NewGRFs.
Definition newgrf_config.cpp:652
_skip_all_newgrf_scanning
int _skip_all_newgrf_scanning
Set this flag to prevent any NewGRF scanning from being done.
Definition newgrf_config.cpp:505
GCF_COMPATIBLE
@ GCF_COMPATIBLE
GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches)
Definition newgrf_config.h:25
PSM_ENTER_GAMELOOP
@ PSM_ENTER_GAMELOOP
Enter the gameloop, changes will be permanent.
Definition newgrf_storage.h:21
PSM_LEAVE_GAMELOOP
@ PSM_LEAVE_GAMELOOP
Leave the gameloop, changes will be temporary.
Definition newgrf_storage.h:22
news_func.h
Functions related to news.
MusicLoop
void MusicLoop()
Check music playback status and start/stop/song-finished.
Definition music_gui.cpp:454
FatalErrorI
void FatalErrorI(const std::string &str)
Error handling for fatal non-user errors.
Definition openttd.cpp:133
OnStartScenario
static void OnStartScenario()
Triggers everything required to set up a saved scenario for a new game.
Definition openttd.cpp:833
openttd_main
int openttd_main(std::span< char *const > arguments)
Main entry point for this lovely game.
Definition openttd.cpp:504
ParseResolution
static void ParseResolution(Dimension *res, const char *s)
Extract the resolution from the given string and store it in the 'res' parameter.
Definition openttd.cpp:267
OnStartGame
static void OnStartGame(bool dedicated_server)
Triggers everything that should be triggered when starting a game.
Definition openttd.cpp:848
SafeLoad
bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, std::shared_ptr< LoadFilter > lf=nullptr)
Load the specified savegame but on error do different things.
Definition openttd.cpp:943
ChangeAutosaveFrequency
void ChangeAutosaveFrequency(bool reset)
Reset the interval of the autosave.
Definition openttd.cpp:1318
DoStartupNewCompany
Company * DoStartupNewCompany(bool is_ai, CompanyID company=INVALID_COMPANY)
Create a new company and sets all company variables default values.
Definition company_cmd.cpp:585
StateGameLoop
void StateGameLoop()
State controlling game loop.
Definition openttd.cpp:1212
UserErrorI
void UserErrorI(const std::string &str)
Error handling for fatal user errors.
Definition openttd.cpp:112
ShowHelp
static void ShowHelp()
Show the help message when someone passed a wrong parameter.
Definition openttd.cpp:147
RequestNewGRFScan
bool RequestNewGRFScan(NewGRFScanCallback *callback)
Request a new NewGRF scan.
Definition openttd.cpp:1331
ShutdownGame
static void ShutdownGame()
Uninitializes drivers, frees allocated memory, cleans pools, ... Generally, prepares the game for shu...
Definition openttd.cpp:284
LoadIntroGame
static void LoadIntroGame(bool load_newgrfs=true)
Load the introduction game.
Definition openttd.cpp:315
CreateOptions
static std::vector< OptionData > CreateOptions()
Create all the options that OpenTTD supports.
Definition openttd.cpp:482
CallWindowGameTickEvent
void CallWindowGameTickEvent()
Dispatch OnGameTick event over all windows.
Definition window.cpp:3248
CheckCaches
void CheckCaches()
Check the validity of some of the caches.
Definition cachecheck.cpp:36
_config_file
std::string _config_file
Configuration file of OpenTTD.
Definition settings.cpp:60
HandleBootstrap
bool HandleBootstrap()
Handle all procedures for bootstrapping OpenTTD without a base graphics set.
Definition bootstrap_gui.cpp:362
_autosave_interval
static IntervalTimer< TimerGameRealtime > _autosave_interval({std::chrono::milliseconds::zero(), TimerGameRealtime::AUTOSAVE}, [](auto) { _pause_mode &=~PM_COMMAND_DURING_PAUSE;_do_autosave=true;SetWindowDirty(WC_STATUS_BAR, 0);static FiosNumberedSaveName _autosave_ctr("autosave");DoAutoOrNetsave(_autosave_ctr);_do_autosave=false;SetWindowDirty(WC_STATUS_BAR, 0);})
Interval for regular autosaves.
SwitchMode
SwitchMode
Mode which defines what mode we're switching to.
Definition openttd.h:26
SM_START_HEIGHTMAP
@ SM_START_HEIGHTMAP
Load a heightmap and start a new game from it.
Definition openttd.h:38
SM_RESTART_HEIGHTMAP
@ SM_RESTART_HEIGHTMAP
Load a heightmap and start a new game from it with current settings.
Definition openttd.h:40
SM_LOAD_SCENARIO
@ SM_LOAD_SCENARIO
Load scenario from scenario editor.
Definition openttd.h:37
SM_GENRANDLAND
@ SM_GENRANDLAND
Generate random land within scenario editor.
Definition openttd.h:36
SM_JOIN_GAME
@ SM_JOIN_GAME
Join a network game.
Definition openttd.h:41
SM_MENU
@ SM_MENU
Switch to game intro menu.
Definition openttd.h:33
SM_RESTARTGAME
@ SM_RESTARTGAME
Restart --> 'Random game' with current settings.
Definition openttd.h:29
SM_RELOADGAME
@ SM_RELOADGAME
Reload the savegame / scenario / heightmap you started the game with.
Definition openttd.h:30
SM_SAVE_HEIGHTMAP
@ SM_SAVE_HEIGHTMAP
Save heightmap.
Definition openttd.h:35
SM_LOAD_HEIGHTMAP
@ SM_LOAD_HEIGHTMAP
Load heightmap from scenario editor.
Definition openttd.h:39
SM_SAVE_GAME
@ SM_SAVE_GAME
Save game.
Definition openttd.h:34
SM_LOAD_GAME
@ SM_LOAD_GAME
Load game, Play Scenario.
Definition openttd.h:32
SM_EDITOR
@ SM_EDITOR
Switch to scenario editor.
Definition openttd.h:31
SM_NEWGAME
@ SM_NEWGAME
New Game --> 'Random game'.
Definition openttd.h:28
PM_UNPAUSED
@ PM_UNPAUSED
A normal unpaused game.
Definition openttd.h:69
PM_PAUSED_NORMAL
@ PM_PAUSED_NORMAL
A game normally paused.
Definition openttd.h:70
PM_PAUSED_SAVELOAD
@ PM_PAUSED_SAVELOAD
A game paused for saving/loading.
Definition openttd.h:71
GameMode
GameMode
Mode which defines the state of the game.
Definition openttd.h:18
DO_FULL_ANIMATION
@ DO_FULL_ANIMATION
Perform palette animation.
Definition openttd.h:49
PT_ALL
@ PT_ALL
All pool types.
Definition pool_type.hpp:22
progress.h
Functions related to modal progress.
HasModalProgress
bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition progress.h:17
InitializeRailGUI
void InitializeRailGUI()
Resets the rail GUI - sets default railtype to build and resets the signal GUI.
Definition rail_gui.cpp:1996
rail_gui.h
Functions/types etc.
random_func.hpp
Pseudo random number generator.
rev.h
declaration of OTTD revision dependent variables
InitializeRoadGUI
void InitializeRoadGUI()
I really don't know why rail_gui.cpp has this too, shouldn't be included in the other one?
Definition road_gui.cpp:1722
road_gui.h
Functions/types related to the road GUIs.
roadstop_base.h
Base class for roadstops.
roadveh.h
Road vehicle states.
safeguards.h
A number of safeguards to prevent using unsafe methods.
ProcessAsyncSaveFinish
void ProcessAsyncSaveFinish()
Handle async save finishes.
Definition saveload.cpp:376
GetSaveLoadErrorMessage
StringID GetSaveLoadErrorMessage()
Return the description of the error.
Definition saveload.cpp:2842
LoadWithFilter
SaveOrLoadResult LoadWithFilter(std::shared_ptr< LoadFilter > reader)
Load the game using a (reader) filter.
Definition saveload.cpp:3108
_do_autosave
bool _do_autosave
are we doing an autosave at the moment?
Definition saveload.cpp:66
GetSaveLoadErrorType
StringID GetSaveLoadErrorType()
Return the appropriate initial string for an error depending on whether we are saving or loading.
Definition saveload.cpp:2836
SaveOrLoad
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.
Definition saveload.cpp:3128
DoAutoOrNetsave
void DoAutoOrNetsave(FiosNumberedSaveName &counter)
Create an autosave or netsave.
Definition saveload.cpp:3219
_file_to_saveload
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition saveload.cpp:60
DoExitSave
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
Definition saveload.cpp:3237
saveload.h
Functions/types related to saving and loading games.
SaveOrLoadResult
SaveOrLoadResult
Save or load result codes.
Definition saveload.h:403
SL_OK
@ SL_OK
completed successfully
Definition saveload.h:404
SL_REINIT
@ SL_REINIT
error that was caught in the middle of updating game state, need to clear it. (can only happen during...
Definition saveload.h:406
SaveLoadVersion
SaveLoadVersion
SaveLoad versions Previous savegame versions, the trunk revision where they were introduced and the r...
Definition saveload.h:30
MakeHeightmapScreenshot
bool MakeHeightmapScreenshot(const char *filename)
Make a heightmap of the current map.
Definition screenshot.cpp:811
InitializeScreenshotFormats
void InitializeScreenshotFormats()
Initialize screenshot format information on startup, with _screenshot_format_name filled from the loa...
Definition screenshot.cpp:560
screenshot.h
Functions to make screenshots.
LoadFromConfig
void LoadFromConfig(bool startup)
Load the values from the configuration files.
Definition settings.cpp:1354
SaveToConfig
void SaveToConfig()
Save the values to the configuration file.
Definition settings.cpp:1447
_old_vds
VehicleDefaultSettings _old_vds
Used for loading default vehicles settings from old savegames.
Definition settings.cpp:59
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:57
_settings_newgame
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition settings.cpp:58
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:56
settings_func.h
Functions related to setting/changing the settings.
ship.h
Base for ships.
social_integration.h
Interface definitions for game to report/respond to social integration.
sound_driver.hpp
Base for all sound drivers.
station_base.h
Base classes/functions for stations.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
FormatArrayAsHex
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
Definition string.cpp:81
StrEmpty
bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition string_func.h:57
CheckForMissingGlyphs
void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
Check whether the currently loaded language pack uses characters that the currently loaded font does ...
Definition strings.cpp:2291
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition strings.cpp:333
InitializeLanguagePacks
void InitializeLanguagePacks()
Make a list of the available language packs.
Definition strings.cpp:2136
SetDParamStr
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:371
strings_func.h
Functions related to OTTD's strings.
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition strings_type.h:17
AfterNewGRFScan
Callback structure of statements to be executed after the NewGRF scan.
Definition openttd.cpp:379
AfterNewGRFScan::dedicated_host
std::string dedicated_host
Hostname for the dedicated server.
Definition openttd.cpp:382
AfterNewGRFScan::startyear
TimerGameCalendar::Year startyear
The start year.
Definition openttd.cpp:380
AfterNewGRFScan::OnNewGRFsScanned
void OnNewGRFsScanned() override
Called whenever the NewGRF scan completed.
Definition openttd.cpp:398
AfterNewGRFScan::dedicated_port
uint16_t dedicated_port
Port for the dedicated server.
Definition openttd.cpp:383
AfterNewGRFScan::save_config
bool save_config
The save config setting.
Definition openttd.cpp:386
AfterNewGRFScan::connection_string
std::string connection_string
Information about the server to connect to.
Definition openttd.cpp:384
AfterNewGRFScan::generation_seed
uint32_t generation_seed
Seed for the new game.
Definition openttd.cpp:381
AfterNewGRFScan::join_server_password
std::string join_server_password
The password to join the server with.
Definition openttd.cpp:385
AfterNewGRFScan::AfterNewGRFScan
AfterNewGRFScan()
Create a new callback.
Definition openttd.cpp:391
Backup
Class to backup a specific variable and restore it later.
Definition backup_type.hpp:21
Backup::Restore
void Restore()
Restore the variable.
Definition backup_type.hpp:110
BaseGraphics::Ini::extra_version
uint32_t extra_version
version of the extra GRF
Definition base_media_base.h:286
BasePersistentStorageArray::SwitchMode
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...
Definition newgrf_storage.cpp:54
BaseSet::name
std::string name
The name of the base set.
Definition base_media_base.h:61
ClientSettings::company
CompanySettings company
default values for per-company settings
Definition settings_type.h:612
ClientSettings::music
MusicSettings music
settings related to music/sound
Definition settings_type.h:614
ClientSettings::network
NetworkSettings network
settings related to the network
Definition settings_type.h:611
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition settings_type.h:610
CommandHelper
Definition command_func.h:83
CompanyProperties::settings
CompanySettings settings
settings specific for each company
Definition company_base.h:122
CompanyProperties::colour
Colours colour
Company colour.
Definition company_base.h:87
CompanySettings::vehicle
VehicleDefaultSettings vehicle
default settings for vehicles
Definition settings_type.h:587
Company
Definition company_base.h:133
CursorVars::fix_at
bool fix_at
mouse is moving, but cursor is not (used for scrolling)
Definition gfx_type.h:128
CursorVars::in_window
bool in_window
mouse inside this window, determines drawing logic
Definition gfx_type.h:147
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:30
EngineOverrideManager::ResetToCurrentNewGRFConfig
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
Definition engine.cpp:585
FileToSaveLoad::abstract_ftype
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
Definition saveload.h:413
FileToSaveLoad::SetMode
void SetMode(FiosType ft)
Set the mode and file type of the file to save or load based on the type of file entry at the file sy...
Definition saveload.cpp:3288
FileToSaveLoad::detail_ftype
DetailedFileType detail_ftype
Concrete file type (PNG, BMP, old save, etc).
Definition saveload.h:412
FileToSaveLoad::file_op
SaveLoadOperation file_op
File operation to perform.
Definition saveload.h:411
FileToSaveLoad::name
std::string name
Name of the file.
Definition saveload.h:414
FiosNumberedSaveName
A savegame name automatically numbered.
Definition fios.h:130
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition newgrf_config.h:154
GRFConfig::IsCompatible
bool IsCompatible(uint32_t old_version) const
Return whether this NewGRF can replace an older version of the same NewGRF.
Definition newgrf_config.cpp:73
GRFLoadedFeatures::used_liveries
uint64_t used_liveries
Bitmask of LiveryScheme used by the defined engines.
Definition newgrf.h:177
GUISettings::last_newgrf_count
uint32_t last_newgrf_count
the numbers of NewGRFs we found during the last scan
Definition settings_type.h:200
GUISettings::starting_colour_secondary
Colours starting_colour_secondary
default secondary color scheme for the company to start a new game with
Definition settings_type.h:205
GUISettings::autosave_on_exit
bool autosave_on_exit
save an autosave when you quit the game, but do not ask "Do you really want to quit?...
Definition settings_type.h:171
GUISettings::pause_on_newgame
bool pause_on_newgame
whether to start new games paused or not
Definition settings_type.h:181
GUISettings::autosave_interval
uint32_t autosave_interval
how often should we do autosaves?
Definition settings_type.h:168
GUISettings::starting_colour
Colours starting_colour
default color scheme for the company to start a new game with
Definition settings_type.h:204
GameCreationSettings::map_x
uint8_t map_x
X size of map.
Definition settings_type.h:355
GameCreationSettings::map_y
uint8_t map_y
Y size of map.
Definition settings_type.h:356
GameCreationSettings::starting_year
TimerGameCalendar::Year starting_year
starting date
Definition settings_type.h:353
GameCreationSettings::generation_seed
uint32_t generation_seed
noise seed for world generation
Definition settings_type.h:352
GameSessionStats::start_time
std::chrono::steady_clock::time_point start_time
Time when the current game was started.
Definition openttd.h:56
GameSessionStats::savegame_size
std::optional< size_t > savegame_size
Size of the last saved savegame in bytes, or std::nullopt if not saved yet.
Definition openttd.h:58
GameSettings::ai_config
class AIConfig * ai_config[MAX_COMPANIES]
settings per company
Definition settings_type.h:597
GameSettings::game_config
class GameConfig * game_config
settings for gamescript
Definition settings_type.h:598
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition settings_type.h:593
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition settings_type.h:601
GetOptData
Data storage for parsing command line options.
Definition getoptdata.h:29
GetOptData::arguments
ArgumentSpan arguments
Remaining command line arguments.
Definition getoptdata.h:33
GetOptData::GetOpt
int GetOpt()
Find the next option.
Definition getoptdata.cpp:22
GetOptData::opt
const char * opt
Option value, if available (else nullptr).
Definition getoptdata.h:35
GraphicsSet::GetOrCreateExtraConfig
GRFConfig & GetOrCreateExtraConfig() const
Return configuration for the extra GRF, or lazily create it.
Definition gfxinit.cpp:370
Industry
Defines the internal data of a functional industry.
Definition industry.h:66
LoadCheckData::HasNewGrfs
bool HasNewGrfs()
Check whether the game uses any NewGrfs.
Definition fios.h:68
LoadCheckData::error_msg
std::string error_msg
Data to pass to SetDParamStr when displaying error.
Definition fios.h:36
LoadCheckData::error
StringID error
Error message from loading. INVALID_STRING_ID if no error.
Definition fios.h:35
LoadCheckData::grfconfig
GRFConfig * grfconfig
NewGrf configuration from save.
Definition fios.h:45
LoadCheckData::HasErrors
bool HasErrors()
Check whether loading the game resulted in errors.
Definition fios.h:59
LoadCheckData::Clear
void Clear()
Reset read data.
Definition fios_gui.cpp:49
Map::SizeY
static uint SizeY()
Get the size of the map along the Y.
Definition map_func.h:279
Map::SizeX
static debug_inline uint SizeX()
Get the size of the map along the X.
Definition map_func.h:270
MusicSettings::effect_vol
uint8_t effect_vol
The requested effects volume.
Definition settings_type.h:259
MusicSettings::music_vol
uint8_t music_vol
The requested music volume.
Definition settings_type.h:258
NetworkSettings::reload_cfg
bool reload_cfg
reload the config file before restarting
Definition settings_type.h:342
NetworkSettings::server_port
uint16_t server_port
port the server listens on
Definition settings_type.h:316
NetworkSettings::last_joined
std::string last_joined
Last joined server.
Definition settings_type.h:343
NetworkSettings::participate_survey
ParticipateSurvey participate_survey
Participate in the automated survey.
Definition settings_type.h:345
NewGRFScanCallback
Callback for NewGRF scanning.
Definition newgrf_config.h:217
PoolBase::Clean
static void Clean(PoolType)
Clean all pools of given type.
Definition pool_func.cpp:30
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:238
Pool::PoolItem<&_industry_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition pool_type.hpp:388
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition pool_type.hpp:339
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:150
VehicleSettings::disable_elrails
bool disable_elrails
when true, the elrails are disabled
Definition settings_type.h:498
WindowDesc::SaveToConfig
static void SaveToConfig()
Save all WindowDesc settings to _windows_file.
Definition window.cpp:177
WindowDesc::LoadFromConfig
static void LoadFromConfig()
Load all WindowDesc settings from _windows_file.
Definition window.cpp:155
subsidy_func.h
Functions related to subsidies.
timer.h
Definition of Interval and OneShot timers.
timer_game_calendar.h
Definition of the game-calendar-timer.
timer_game_economy.h
Definition of the game-economy-timer.
timer_game_realtime.h
Definition of the real time game-timer.
timer_game_tick.h
Definition of the tick-based game-timer.
town.h
Base of the town class.
train.h
Base for the train class.
_display_opt
uint8_t _display_opt
What do we want to draw/do?
Definition transparency_gui.cpp:26
RunVehicleCalendarDayProc
void RunVehicleCalendarDayProc()
Age all vehicles, spreading out the action using the current TimerGameCalendar::date_fract.
Definition vehicle.cpp:937
vehicle_func.h
Functions related to vehicles.
video_driver.hpp
Base of all video drivers.
InitializeSpriteSorter
void InitializeSpriteSorter()
Choose the "best" sprite sorter and set _vp_sprite_sorter.
Definition viewport.cpp:3530
viewport_func.h
Functions related to (drawing on) viewports.
viewport_sprite_sorter.h
Types related to sprite sorting.
OTTD2FS
std::wstring OTTD2FS(const std::string &name)
Convert from OpenTTD's encoding to a wide string.
Definition win32.cpp:354
FS2OTTD
std::string FS2OTTD(const std::wstring &name)
Convert to OpenTTD's encoding from a wide string.
Definition win32.cpp:337
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1140
ResetWindowSystem
void ResetWindowSystem()
Reset the windowing system, by means of shutting it down followed by re-initialization.
Definition window.cpp:1818
UnInitWindowSystem
void UnInitWindowSystem()
Close down the windowing system.
Definition window.cpp:1804
InitWindowSystem
void InitWindowSystem()
(re)initialize the windowing system
Definition window.cpp:1782
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition window.cpp:3101
WC_STATUS_BAR
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition window_type.h:64
WC_SAVELOAD
@ WC_SAVELOAD
Saveload window; Window numbers:
Definition window_type.h:144
ZOOM_LVL_MIN
@ ZOOM_LVL_MIN
Minimum zoom level.
Definition zoom_type.h:41