OpenTTD Source: src/openttd.cpp Source File

OpenTTD Source 13.2.1

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 "gui.h"
21
22 #include "base_media_base.h"
23 #include "saveload/saveload.h"
24 #include "company_func.h"
25 #include "command_func.h"
26 #include "news_func.h"
27 #include "fios.h"
28 #include "aircraft.h"
29 #include "roadveh.h"
30 #include "train.h"
31 #include "ship.h"
32 #include "console_func.h"
33 #include "screenshot.h"
34 #include "network/network.h"
35 #include "network/network_func.h"
36 #include "ai/ai.hpp"
37 #include "ai/ai_config.hpp"
38 #include "settings_func.h"
39 #include "genworld.h"
40 #include "progress.h"
41 #include "strings_func.h"
42 #include "date_func.h"
43 #include "vehicle_func.h"
44 #include "gamelog.h"
45 #include "animated_tile_func.h"
46 #include "roadstop_base.h"
47 #include "elrail_func.h"
48 #include "rev.h"
49 #include "highscore.h"
50 #include "station_base.h"
51 #include "crashlog.h"
52 #include "engine_func.h"
53 #include "core/random_func.hpp"
54 #include "rail_gui.h"
55 #include "road_gui.h"
56 #include "core/backup_type.hpp"
57 #include "hotkeys.h"
58 #include "newgrf.h"
59 #include "misc/getoptdata.h"
60 #include "game/game.hpp"
61 #include "game/game_config.hpp"
62 #include "town.h"
63 #include "subsidy_func.h"
64 #include "gfx_layout.h"
65 #include "viewport_func.h"
66 #include "viewport_sprite_sorter.h"
67 #include "framerate_type.h"
68 #include "industry.h"
69 #include "network/network_gui.h"
70 #include "misc_cmd.h"
71
72 #include "linkgraph/linkgraphschedule.h"
73
74 #include <stdarg.h>
75 #include <system_error>
76
77 #include "safeguards.h"
78
79 #ifdef __EMSCRIPTEN__
80 # include <emscripten.h>
81 # include <emscripten/html5.h>
82 #endif
83
84 void CallLandscapeTick();
85 void IncreaseDate();
86 void DoPaletteAnimations();
87 void MusicLoop();
88 void ResetMusic();
89 void CallWindowGameTickEvent();
90 bool HandleBootstrap();
91
92 extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY);
93 extern void ShowOSErrorBox(const char *buf, bool system);
94 extern std::string _config_file;
95
96 bool _save_config = false;
97 bool _request_newgrf_scan = false;
98 NewGRFScanCallback *_request_newgrf_scan_callback = nullptr;
99
105 void CDECL usererror(const char *s, ...)
106 {
107 va_list va;
108 char buf[512];
109
110 va_start(va, s);
111 vseprintf(buf, lastof(buf), s, va);
112 va_end(va);
113
114 ShowOSErrorBox(buf, 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_syncfs"]) openttd_syncfs());
123 EM_ASM(if (window["openttd_abort"]) openttd_abort());
124 #endif
125
126 exit(1);
127 }
128
134 void CDECL error(const char *s, ...)
135 {
136 va_list va;
137 char buf[2048];
138
139 va_start(va, s);
140 vseprintf(buf, lastof(buf), s, va);
141 va_end(va);
142
143 if (VideoDriver::GetInstance() == nullptr || VideoDriver::GetInstance()->HasGUI()) {
144 ShowOSErrorBox(buf, true);
145 }
146
147 /* Set the error message for the crash log and then invoke it. */
148 CrashLog::SetErrorMessage(buf);
149 abort();
150 }
151
156 void CDECL ShowInfoF(const char *str, ...)
157 {
158 va_list va;
159 char buf[1024];
160 va_start(va, str);
161 vseprintf(buf, lastof(buf), str, va);
162 va_end(va);
163 ShowInfo(buf);
164 }
165
169 static void ShowHelp()
170 {
171 char buf[8192];
172 char *p = buf;
173
174 p += seprintf(p, lastof(buf), "OpenTTD %s\n", _openttd_revision);
175 p = strecpy(p,
176 "\n"
177 "\n"
178 "Command line options:\n"
179 " -v drv = Set video driver (see below)\n"
180 " -s drv = Set sound driver (see below)\n"
181 " -m drv = Set music driver (see below)\n"
182 " -b drv = Set the blitter to use (see below)\n"
183 " -r res = Set resolution (for instance 800x600)\n"
184 " -h = Display this help text\n"
185 " -t year = Set starting year\n"
186 " -d [[fac=]lvl[,...]]= Debug mode\n"
187 " -e = Start Editor\n"
188 " -g [savegame] = Start new/save game immediately\n"
189 " -G seed = Set random seed\n"
190 " -n [ip:port#company]= Join network game\n"
191 " -p password = Password to join server\n"
192 " -P password = Password to join company\n"
193 " -D [ip][:port] = Start dedicated server\n"
194 " -l ip[:port] = Redirect Debug()\n"
195 #if !defined(_WIN32)
196 " -f = Fork into the background (dedicated only)\n"
197 #endif
198 " -I graphics_set = Force the graphics set (see below)\n"
199 " -S sounds_set = Force the sounds set (see below)\n"
200 " -M music_set = Force the music set (see below)\n"
201 " -c config_file = Use 'config_file' instead of 'openttd.cfg'\n"
202 " -x = Never save configuration changes to disk\n"
203 " -X = Don't use global folders to search for files\n"
204 " -q savegame = Write some information about the savegame and exit\n"
205 " -Q = Don't scan for/load NewGRF files on startup\n"
206 " -QQ = Disable NewGRF scanning/loading entirely\n"
207 "\n",
208 lastof(buf)
209 );
210
211 /* List the graphics packs */
212 p = BaseGraphics::GetSetsList(p, lastof(buf));
213
214 /* List the sounds packs */
215 p = BaseSounds::GetSetsList(p, lastof(buf));
216
217 /* List the music packs */
218 p = BaseMusic::GetSetsList(p, lastof(buf));
219
220 /* List the drivers */
221 p = DriverFactoryBase::GetDriversInfo(p, lastof(buf));
222
223 /* List the blitters */
224 p = BlitterFactory::GetBlittersInfo(p, lastof(buf));
225
226 /* List the debug facilities. */
227 p = DumpDebugFacilityNames(p, lastof(buf));
228
229 /* We need to initialize the AI, so it finds the AIs */
230 AI::Initialize();
231 const std::string ai_list = AI::GetConsoleList(true);
232 p = strecpy(p, ai_list.c_str(), lastof(buf));
233 AI::Uninitialize(true);
234
235 /* We need to initialize the GameScript, so it finds the GSs */
236 Game::Initialize();
237 const std::string game_list = Game::GetConsoleList(true);
238 p = strecpy(p, game_list.c_str(), lastof(buf));
239 Game::Uninitialize(true);
240
241 /* ShowInfo put output to stderr, but version information should go
242 * to stdout; this is the only exception */
243 #if !defined(_WIN32)
244 printf("%s\n", buf);
245 #else
246 ShowInfo(buf);
247 #endif
248 }
249
250 static void WriteSavegameInfo(const char *name)
251 {
252 extern SaveLoadVersion _sl_version;
253 uint32 last_ottd_rev = 0;
254 byte ever_modified = 0;
255 bool removed_newgrfs = false;
256
257 GamelogInfo(_load_check_data.gamelog_action, _load_check_data.gamelog_actions, &last_ottd_rev, &ever_modified, &removed_newgrfs);
258
259 char buf[8192];
260 char *p = buf;
261 p += seprintf(p, lastof(buf), "Name: %s\n", name);
262 p += seprintf(p, lastof(buf), "Savegame ver: %d\n", _sl_version);
263 p += seprintf(p, lastof(buf), "NewGRF ver: 0x%08X\n", last_ottd_rev);
264 p += seprintf(p, lastof(buf), "Modified: %d\n", ever_modified);
265
266 if (removed_newgrfs) {
267 p += seprintf(p, lastof(buf), "NewGRFs have been removed\n");
268 }
269
270 p = strecpy(p, "NewGRFs:\n", lastof(buf));
271 if (_load_check_data.HasNewGrfs()) {
272 for (GRFConfig *c = _load_check_data.grfconfig; c != nullptr; c = c->next) {
273 char md5sum[33];
274 md5sumToString(md5sum, lastof(md5sum), HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum);
275 p += seprintf(p, lastof(buf), "%08X %s %s\n", c->ident.grfid, md5sum, c->filename);
276 }
277 }
278
279 /* ShowInfo put output to stderr, but version information should go
280 * to stdout; this is the only exception */
281 #if !defined(_WIN32)
282 printf("%s\n", buf);
283 #else
284 ShowInfo(buf);
285 #endif
286 }
287
288
295 static void ParseResolution(Dimension *res, const char *s)
296 {
297 const char *t = strchr(s, 'x');
298 if (t == nullptr) {
299 ShowInfoF("Invalid resolution '%s'", s);
300 return;
301 }
302
303 res->width = std::max(strtoul(s, nullptr, 0), 64UL);
304 res->height = std::max(strtoul(t + 1, nullptr, 0), 64UL);
305 }
306
307
312 static void ShutdownGame()
313 {
314 IConsoleFree();
315
316 if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
317
318 DriverFactoryBase::ShutdownDrivers();
319
320 UnInitWindowSystem();
321
322 /* stop the scripts */
323 AI::Uninitialize(false);
324 Game::Uninitialize(false);
325
326 /* Uninitialize variables that are allocated dynamically */
327 GamelogReset();
328
329 LinkGraphSchedule::Clear();
330 PoolBase::Clean(PT_ALL);
331
332 /* No NewGRFs were loaded when it was still bootstrapping. */
333 if (_game_mode != GM_BOOTSTRAP) ResetNewGRFData();
334
335 UninitFontCache();
336 }
337
342 static void LoadIntroGame(bool load_newgrfs = true)
343 {
344 _game_mode = GM_MENU;
345
346 if (load_newgrfs) ResetGRFConfig(false);
347
348 /* Setup main window */
349 ResetWindowSystem();
350 SetupColoursAndInitialWindow();
351
352 /* Load the default opening screen savegame */
353 if (SaveOrLoad("opntitle.dat", SLO_LOAD, DFT_GAME_FILE, BASESET_DIR) != SL_OK) {
354 GenerateWorld(GWM_EMPTY, 64, 64); // if failed loading, make empty world.
355 SetLocalCompany(COMPANY_SPECTATOR);
356 } else {
357 SetLocalCompany(COMPANY_FIRST);
358 }
359
360 FixTitleGameZoom();
361 _pause_mode = PM_UNPAUSED;
362 _cursor.fix_at = false;
363
364 CheckForMissingGlyphs();
365
366 MusicLoop(); // ensure music is correct
367 }
368
369 void MakeNewgameSettingsLive()
370 {
371 for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
372 if (_settings_game.ai_config[c] != nullptr) {
373 delete _settings_game.ai_config[c];
374 }
375 }
376 if (_settings_game.game_config != nullptr) {
377 delete _settings_game.game_config;
378 }
379
380 /* Copy newgame settings to active settings.
381 * Also initialise old settings needed for savegame conversion. */
382 _settings_game = _settings_newgame;
383 _old_vds = _settings_client.company.vehicle;
384
385 for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
386 _settings_game.ai_config[c] = nullptr;
387 if (_settings_newgame.ai_config[c] != nullptr) {
388 _settings_game.ai_config[c] = new AIConfig(_settings_newgame.ai_config[c]);
389 if (!AIConfig::GetConfig(c, AIConfig::SSS_FORCE_GAME)->HasScript()) {
390 AIConfig::GetConfig(c, AIConfig::SSS_FORCE_GAME)->Change(nullptr);
391 }
392 }
393 }
394 _settings_game.game_config = nullptr;
395 if (_settings_newgame.game_config != nullptr) {
396 _settings_game.game_config = new GameConfig(_settings_newgame.game_config);
397 }
398 }
399
400 void OpenBrowser(const char *url)
401 {
402 /* Make sure we only accept urls that are sure to open a browser. */
403 if (strstr(url, "http://") != url && strstr(url, "https://") != url) return;
404
405 extern void OSOpenBrowser(const char *url);
406 OSOpenBrowser(url);
407 }
408
410 struct AfterNewGRFScan : NewGRFScanCallback {
411 Year startyear = INVALID_YEAR;
412 uint32 generation_seed = GENERATE_NEW_SEED;
413 std::string dedicated_host;
414 uint16 dedicated_port = 0;
415 std::string connection_string;
416 std::string join_server_password;
417 std::string join_company_password;
418 bool save_config = true;
419
423 AfterNewGRFScan()
424 {
425 /* Visual C++ 2015 fails compiling this line (AfterNewGRFScan::generation_seed undefined symbol)
426 * if it's placed outside a member function, directly in the struct body. */
427 static_assert(sizeof(generation_seed) == sizeof(_settings_game.game_creation.generation_seed));
428 }
429
430 virtual void OnNewGRFsScanned()
431 {
432 ResetGRFConfig(false);
433
434 TarScanner::DoScan(TarScanner::SCENARIO);
435
436 AI::Initialize();
437 Game::Initialize();
438
439 /* We want the new (correct) NewGRF count to survive the loading. */
440 uint last_newgrf_count = _settings_client.gui.last_newgrf_count;
441 LoadFromConfig();
442 _settings_client.gui.last_newgrf_count = last_newgrf_count;
443 /* Since the default for the palette might have changed due to
444 * reading the configuration file, recalculate that now. */
445 UpdateNewGRFConfigPalette();
446
447 Game::Uninitialize(true);
448 AI::Uninitialize(true);
449 LoadFromHighScore();
450 LoadHotkeysFromConfig();
451 WindowDesc::LoadFromConfig();
452
453 /* We have loaded the config, so we may possibly save it. */
454 _save_config = save_config;
455
456 /* restore saved music and effects volumes */
457 MusicDriver::GetInstance()->SetVolume(_settings_client.music.music_vol);
458 SetEffectVolume(_settings_client.music.effect_vol);
459
460 if (startyear != INVALID_YEAR) IConsoleSetSetting("game_creation.starting_year", startyear);
461 if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed;
462
463 if (!dedicated_host.empty()) {
464 _network_bind_list.clear();
465 _network_bind_list.emplace_back(dedicated_host);
466 }
467 if (dedicated_port != 0) _settings_client.network.server_port = dedicated_port;
468
469 /* initialize the ingame console */
470 IConsoleInit();
471 InitializeGUI();
472 IConsoleCmdExec("exec scripts/autoexec.scr 0");
473
474 /* Make sure _settings is filled with _settings_newgame if we switch to a game directly */
475 if (_switch_mode != SM_NONE) MakeNewgameSettingsLive();
476
477 if (_network_available && !connection_string.empty()) {
478 LoadIntroGame();
479 _switch_mode = SM_NONE;
480
481 NetworkClientConnectGame(connection_string, COMPANY_NEW_COMPANY, join_server_password, join_company_password);
482 }
483
484 /* After the scan we're not used anymore. */
485 delete this;
486 }
487 };
488
489 #if defined(UNIX)
490 extern void DedicatedFork();
491 #endif
492
494 static const OptionData _options[] = {
495 GETOPT_SHORT_VALUE('I'),
496 GETOPT_SHORT_VALUE('S'),
497 GETOPT_SHORT_VALUE('M'),
498 GETOPT_SHORT_VALUE('m'),
499 GETOPT_SHORT_VALUE('s'),
500 GETOPT_SHORT_VALUE('v'),
501 GETOPT_SHORT_VALUE('b'),
502 GETOPT_SHORT_OPTVAL('D'),
503 GETOPT_SHORT_OPTVAL('n'),
504 GETOPT_SHORT_VALUE('l'),
505 GETOPT_SHORT_VALUE('p'),
506 GETOPT_SHORT_VALUE('P'),
507 #if !defined(_WIN32)
508 GETOPT_SHORT_NOVAL('f'),
509 #endif
510 GETOPT_SHORT_VALUE('r'),
511 GETOPT_SHORT_VALUE('t'),
512 GETOPT_SHORT_OPTVAL('d'),
513 GETOPT_SHORT_NOVAL('e'),
514 GETOPT_SHORT_OPTVAL('g'),
515 GETOPT_SHORT_VALUE('G'),
516 GETOPT_SHORT_VALUE('c'),
517 GETOPT_SHORT_NOVAL('x'),
518 GETOPT_SHORT_NOVAL('X'),
519 GETOPT_SHORT_VALUE('q'),
520 GETOPT_SHORT_NOVAL('h'),
521 GETOPT_SHORT_NOVAL('Q'),
522 GETOPT_END()
523 };
524
531 int openttd_main(int argc, char *argv[])
532 {
533 std::string musicdriver;
534 std::string sounddriver;
535 std::string videodriver;
536 std::string blitter;
537 std::string graphics_set;
538 std::string sounds_set;
539 std::string music_set;
540 Dimension resolution = {0, 0};
541 std::unique_ptr<AfterNewGRFScan> scanner(new AfterNewGRFScan());
542 bool dedicated = false;
543 char *debuglog_conn = nullptr;
544 bool only_local_path = false;
545
546 extern bool _dedicated_forks;
547 _dedicated_forks = false;
548
549 _game_mode = GM_MENU;
550 _switch_mode = SM_MENU;
551
552 GetOptData mgo(argc - 1, argv + 1, _options);
553 int ret = 0;
554
555 int i;
556 while ((i = mgo.GetOpt()) != -1) {
557 switch (i) {
558 case 'I': graphics_set = mgo.opt; break;
559 case 'S': sounds_set = mgo.opt; break;
560 case 'M': music_set = mgo.opt; break;
561 case 'm': musicdriver = mgo.opt; break;
562 case 's': sounddriver = mgo.opt; break;
563 case 'v': videodriver = mgo.opt; break;
564 case 'b': blitter = mgo.opt; break;
565 case 'D':
566 musicdriver = "null";
567 sounddriver = "null";
568 videodriver = "dedicated";
569 blitter = "null";
570 dedicated = true;
571 SetDebugString("net=4", ShowInfo);
572 if (mgo.opt != nullptr) {
573 scanner->dedicated_host = ParseFullConnectionString(mgo.opt, scanner->dedicated_port);
574 }
575 break;
576 case 'f': _dedicated_forks = true; break;
577 case 'n':
578 scanner->connection_string = mgo.opt; // optional IP:port#company parameter
579 break;
580 case 'l':
581 debuglog_conn = mgo.opt;
582 break;
583 case 'p':
584 scanner->join_server_password = mgo.opt;
585 break;
586 case 'P':
587 scanner->join_company_password = mgo.opt;
588 break;
589 case 'r': ParseResolution(&resolution, mgo.opt); break;
590 case 't': scanner->startyear = atoi(mgo.opt); break;
591 case 'd': {
592 #if defined(_WIN32)
593 CreateConsole();
594 #endif
595 if (mgo.opt != nullptr) SetDebugString(mgo.opt, ShowInfo);
596 break;
597 }
598 case 'e': _switch_mode = (_switch_mode == SM_LOAD_GAME || _switch_mode == SM_LOAD_SCENARIO ? SM_LOAD_SCENARIO : SM_EDITOR); break;
599 case 'g':
600 if (mgo.opt != nullptr) {
601 _file_to_saveload.SetName(mgo.opt);
602 bool is_scenario = _switch_mode == SM_EDITOR || _switch_mode == SM_LOAD_SCENARIO;
603 _switch_mode = is_scenario ? SM_LOAD_SCENARIO : SM_LOAD_GAME;
604 _file_to_saveload.SetMode(SLO_LOAD, is_scenario ? FT_SCENARIO : FT_SAVEGAME, DFT_GAME_FILE);
605
606 /* if the file doesn't exist or it is not a valid savegame, let the saveload code show an error */
607 auto t = _file_to_saveload.name.find_last_of('.');
608 if (t != std::string::npos) {
609 FiosType ft = FiosGetSavegameListCallback(SLO_LOAD, _file_to_saveload.name, _file_to_saveload.name.substr(t).c_str(), nullptr, nullptr);
610 if (ft != FIOS_TYPE_INVALID) _file_to_saveload.SetMode(ft);
611 }
612
613 break;
614 }
615
616 _switch_mode = SM_NEWGAME;
617 /* Give a random map if no seed has been given */
618 if (scanner->generation_seed == GENERATE_NEW_SEED) {
619 scanner->generation_seed = InteractiveRandom();
620 }
621 break;
622 case 'q': {
623 DeterminePaths(argv[0], only_local_path);
624 if (StrEmpty(mgo.opt)) {
625 ret = 1;
626 return ret;
627 }
628
629 char title[80];
630 title[0] = '\0';
631 FiosGetSavegameListCallback(SLO_LOAD, mgo.opt, strrchr(mgo.opt, '.'), title, lastof(title));
632
633 _load_check_data.Clear();
634 SaveOrLoadResult res = SaveOrLoad(mgo.opt, SLO_CHECK, DFT_GAME_FILE, SAVE_DIR, false);
635 if (res != SL_OK || _load_check_data.HasErrors()) {
636 fprintf(stderr, "Failed to open savegame\n");
637 if (_load_check_data.HasErrors()) {
638 InitializeLanguagePacks(); // A language pack is needed for GetString()
639 char buf[256];
640 SetDParamStr(0, _load_check_data.error_data);
641 GetString(buf, _load_check_data.error, lastof(buf));
642 fprintf(stderr, "%s\n", buf);
643 }
644 return ret;
645 }
646
647 WriteSavegameInfo(title);
648 return ret;
649 }
650 case 'Q': {
651 extern int _skip_all_newgrf_scanning;
652 _skip_all_newgrf_scanning += 1;
653 break;
654 }
655 case 'G': scanner->generation_seed = strtoul(mgo.opt, nullptr, 10); break;
656 case 'c': _config_file = mgo.opt; break;
657 case 'x': scanner->save_config = false; break;
658 case 'X': only_local_path = true; break;
659 case 'h':
660 i = -2; // Force printing of help.
661 break;
662 }
663 if (i == -2) break;
664 }
665
666 if (i == -2 || mgo.numleft > 0) {
667 /* Either the user typed '-h', they made an error, or they added unrecognized command line arguments.
668 * In all cases, print the help, and exit.
669 *
670 * The next two functions are needed to list the graphics sets. We can't do them earlier
671 * because then we cannot show it on the debug console as that hasn't been configured yet. */
672 DeterminePaths(argv[0], only_local_path);
673 TarScanner::DoScan(TarScanner::BASESET);
674 BaseGraphics::FindSets();
675 BaseSounds::FindSets();
676 BaseMusic::FindSets();
677 ShowHelp();
678 return ret;
679 }
680
681 DeterminePaths(argv[0], only_local_path);
682 TarScanner::DoScan(TarScanner::BASESET);
683
684 if (dedicated) Debug(net, 3, "Starting dedicated server, version {}", _openttd_revision);
685 if (_dedicated_forks && !dedicated) _dedicated_forks = false;
686
687 #if defined(UNIX)
688 /* We must fork here, or we'll end up without some resources we need (like sockets) */
689 if (_dedicated_forks) DedicatedFork();
690 #endif
691
692 LoadFromConfig(true);
693
694 if (resolution.width != 0) _cur_resolution = resolution;
695
696 /* Limit width times height times bytes per pixel to fit a 32 bit
697 * integer, This way all internal drawing routines work correctly.
698 * A resolution that has one component as 0 is treated as a marker to
699 * auto-detect a good window size. */
700 _cur_resolution.width = std::min(_cur_resolution.width, UINT16_MAX / 2u);
701 _cur_resolution.height = std::min(_cur_resolution.height, UINT16_MAX / 2u);
702
703 /* Assume the cursor starts within the game as not all video drivers
704 * get an event that the cursor is within the window when it is opened.
705 * Saying the cursor is there makes no visible difference as it would
706 * just be out of the bounds of the window. */
707 _cursor.in_window = true;
708
709 /* enumerate language files */
710 InitializeLanguagePacks();
711
712 /* Initialize the font cache */
713 InitFontCache(false);
714
715 /* This must be done early, since functions use the SetWindowDirty* calls */
716 InitWindowSystem();
717
718 BaseGraphics::FindSets();
719 if (graphics_set.empty() && !BaseGraphics::ini_set.empty()) graphics_set = BaseGraphics::ini_set;
720 if (!BaseGraphics::SetSet(graphics_set)) {
721 if (!graphics_set.empty()) {
722 BaseGraphics::SetSet({});
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
730 /* Initialize game palette */
731 GfxInitPalettes();
732
733 Debug(misc, 1, "Loading blitter...");
734 if (blitter.empty() && !_ini_blitter.empty()) blitter = _ini_blitter;
735 _blitter_autodetected = blitter.empty();
736 /* Activate the initial blitter.
737 * This is only some initial guess, after NewGRFs have been loaded SwitchNewGRFBlitter may switch to a different one.
738 * - Never guess anything, if the user specified a blitter. (_blitter_autodetected)
739 * - Use 32bpp blitter if baseset or 8bpp-support settings says so.
740 * - Use 8bpp blitter otherwise.
741 */
742 if (!_blitter_autodetected ||
743 (_support8bpp != S8BPP_NONE && (BaseGraphics::GetUsedSet() == nullptr || BaseGraphics::GetUsedSet()->blitter == BLT_8BPP)) ||
744 BlitterFactory::SelectBlitter("32bpp-anim") == nullptr) {
745 if (BlitterFactory::SelectBlitter(blitter) == nullptr) {
746 blitter.empty() ?
747 usererror("Failed to autoprobe blitter") :
748 usererror("Failed to select requested blitter '%s'; does it exist?", blitter.c_str());
749 }
750 }
751
752 if (videodriver.empty() && !_ini_videodriver.empty()) videodriver = _ini_videodriver;
753 DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
754
755 InitializeSpriteSorter();
756
757 /* Initialize the zoom level of the screen to normal */
758 _screen.zoom = ZOOM_LVL_NORMAL;
759
760 /* The video driver is now selected, now initialise GUI zoom */
761 AdjustGUIZoom(false);
762
763 NetworkStartUp(); // initialize network-core
764
765 if (debuglog_conn != nullptr && _network_available) {
766 NetworkStartDebugLog(debuglog_conn);
767 }
768
769 if (!HandleBootstrap()) {
770 ShutdownGame();
771 return ret;
772 }
773
774 VideoDriver::GetInstance()->ClaimMousePointer();
775
776 /* initialize screenshot formats */
777 InitializeScreenshotFormats();
778
779 BaseSounds::FindSets();
780 if (sounds_set.empty() && !BaseSounds::ini_set.empty()) sounds_set = BaseSounds::ini_set;
781 if (!BaseSounds::SetSet(sounds_set)) {
782 if (sounds_set.empty() || !BaseSounds::SetSet({})) {
783 usererror("Failed to find a sounds set. Please acquire a sounds set for OpenTTD. See section 1.4 of README.md.");
784 } else {
785 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_SOUNDS_NOT_FOUND);
786 msg.SetDParamStr(0, sounds_set);
787 ScheduleErrorMessage(msg);
788 }
789 }
790
791 BaseMusic::FindSets();
792 if (music_set.empty() && !BaseMusic::ini_set.empty()) music_set = BaseMusic::ini_set;
793 if (!BaseMusic::SetSet(music_set)) {
794 if (music_set.empty() || !BaseMusic::SetSet({})) {
795 usererror("Failed to find a music set. Please acquire a music set for OpenTTD. See section 1.4 of README.md.");
796 } else {
797 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_MUSIC_NOT_FOUND);
798 msg.SetDParamStr(0, music_set);
799 ScheduleErrorMessage(msg);
800 }
801 }
802
803 if (sounddriver.empty() && !_ini_sounddriver.empty()) sounddriver = _ini_sounddriver;
804 DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
805
806 if (musicdriver.empty() && !_ini_musicdriver.empty()) musicdriver = _ini_musicdriver;
807 DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
808
809 GenerateWorld(GWM_EMPTY, 64, 64); // Make the viewport initialization happy
810 LoadIntroGame(false);
811
812 CheckForMissingGlyphs();
813
814 /* ScanNewGRFFiles now has control over the scanner. */
815 RequestNewGRFScan(scanner.release());
816
817 VideoDriver::GetInstance()->MainLoop();
818
819 WaitTillSaved();
820
821 /* only save config if we have to */
822 if (_save_config) {
823 SaveToConfig();
824 SaveHotkeysToConfig();
825 WindowDesc::SaveToConfig();
826 SaveToHighScore();
827 }
828
829 /* Reset windowing system, stop drivers, free used memory, ... */
830 ShutdownGame();
831 return ret;
832 }
833
834 void HandleExitGameRequest()
835 {
836 if (_game_mode == GM_MENU || _game_mode == GM_BOOTSTRAP) { // do not ask to quit on the main screen
837 _exit_game = true;
838 } else if (_settings_client.gui.autosave_on_exit) {
839 DoExitSave();
840 _exit_game = true;
841 } else {
842 AskExitGame();
843 }
844 }
845
849 static void OnStartScenario()
850 {
851 /* Reset engine pool to simplify changing engine NewGRFs in scenario editor. */
852 EngineOverrideManager::ResetToCurrentNewGRFConfig();
853
854 /* Make sure all industries were built "this year", to avoid too early closures. (#9918) */
855 for (Industry *i : Industry::Iterate()) {
856 i->last_prod_year = _cur_year;
857 }
858 }
859
864 static void OnStartGame(bool dedicated_server)
865 {
866 /* Update the local company for a loaded game. It is either the first available company
867 * or in the case of a dedicated server, a spectator */
868 SetLocalCompany(dedicated_server ? COMPANY_SPECTATOR : GetFirstPlayableCompanyID());
869
870 /* Update the static game info to set the values from the new game. */
871 NetworkServerUpdateGameInfo();
872 /* Execute the game-start script */
873 IConsoleCmdExec("exec scripts/game_start.scr 0");
874 }
875
876 static void MakeNewGameDone()
877 {
878 SettingsDisableElrail(_settings_game.vehicle.disable_elrails);
879
880 /* In a dedicated server, the server does not play */
881 if (!VideoDriver::GetInstance()->HasGUI()) {
882 OnStartGame(true);
883 if (_settings_client.gui.pause_on_newgame) Command<CMD_PAUSE>::Post(PM_PAUSED_NORMAL, true);
884 return;
885 }
886
887 /* Create a single company */
888 DoStartupNewCompany(false);
889
890 Company *c = Company::Get(COMPANY_FIRST);
891 c->settings = _settings_client.company;
892
893 /* Overwrite color from settings if needed
894 * COLOUR_END corresponds to Random colour */
895 if (_settings_client.gui.starting_colour != COLOUR_END) {
896 c->colour = _settings_client.gui.starting_colour;
897 ResetCompanyLivery(c);
898 _company_colours[c->index] = (Colours)c->colour;
899 }
900
901 OnStartGame(false);
902
903 InitializeRailGUI();
904 InitializeRoadGUI();
905
906 /* We are the server, we start a new company (not dedicated),
907 * so set the default password *if* needed. */
908 if (_network_server && !_settings_client.network.default_company_pass.empty()) {
909 NetworkChangeCompanyPassword(_local_company, _settings_client.network.default_company_pass);
910 }
911
912 if (_settings_client.gui.pause_on_newgame) Command<CMD_PAUSE>::Post(PM_PAUSED_NORMAL, true);
913
914 CheckEngines();
915 CheckIndustries();
916 MarkWholeScreenDirty();
917
918 if (_network_server && !_network_dedicated) ShowClientList();
919 }
920
921 static void MakeNewGame(bool from_heightmap, bool reset_settings)
922 {
923 _game_mode = GM_NORMAL;
924 if (!from_heightmap) {
925 /* "reload" command needs to know what mode we were in. */
926 _file_to_saveload.SetMode(SLO_INVALID, FT_INVALID, DFT_INVALID);
927 }
928
929 ResetGRFConfig(true);
930
931 GenerateWorldSetCallback(&MakeNewGameDone);
932 GenerateWorld(from_heightmap ? GWM_HEIGHTMAP : GWM_NEWGAME, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y, reset_settings);
933 }
934
935 static void MakeNewEditorWorldDone()
936 {
937 SetLocalCompany(OWNER_NONE);
938 }
939
940 static void MakeNewEditorWorld()
941 {
942 _game_mode = GM_EDITOR;
943 /* "reload" command needs to know what mode we were in. */
944 _file_to_saveload.SetMode(SLO_INVALID, FT_INVALID, DFT_INVALID);
945
946 ResetGRFConfig(true);
947
948 GenerateWorldSetCallback(&MakeNewEditorWorldDone);
949 GenerateWorld(GWM_EMPTY, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
950 }
951
962 bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = nullptr)
963 {
964 assert(fop == SLO_LOAD);
965 assert(dft == DFT_GAME_FILE || (lf == nullptr && dft == DFT_OLD_GAME_FILE));
966 GameMode ogm = _game_mode;
967
968 _game_mode = newgm;
969
970 SaveOrLoadResult result = (lf == nullptr) ? SaveOrLoad(filename, fop, dft, subdir) : LoadWithFilter(lf);
971 if (result == SL_OK) return true;
972
973 if (_network_dedicated && ogm == GM_MENU) {
974 /*
975 * If we are a dedicated server *and* we just were in the menu, then we
976 * are loading the first savegame. If that fails, not starting the
977 * server is a better reaction than starting the server with a newly
978 * generated map as it is quite likely to be started from a script.
979 */
980 Debug(net, 0, "Loading requested map failed; closing server.");
981 _exit_game = true;
982 return false;
983 }
984
985 if (result != SL_REINIT) {
986 _game_mode = ogm;
987 return false;
988 }
989
990 if (_network_dedicated) {
991 /*
992 * If we are a dedicated server, have already loaded/started a game,
993 * and then loading the savegame fails in a manner that we need to
994 * reinitialize everything. We must not fall back into the menu mode
995 * with the intro game, as that is unjoinable by clients. So there is
996 * nothing else to do than start a new game, as it might have failed
997 * trying to reload the originally loaded savegame/scenario.
998 */
999 Debug(net, 0, "Loading game failed, so a new (random) game will be started");
1000 MakeNewGame(false, true);
1001 return false;
1002 }
1003
1004 if (_network_server) {
1005 /* We can't load the intro game as server, so disconnect first. */
1006 NetworkDisconnect();
1007 }
1008
1009 switch (ogm) {
1010 default:
1011 case GM_MENU: LoadIntroGame(); break;
1012 case GM_EDITOR: MakeNewEditorWorld(); break;
1013 }
1014 return false;
1015 }
1016
1017 void SwitchToMode(SwitchMode new_mode)
1018 {
1019 /* If we are saving something, the network stays in its current state */
1020 if (new_mode != SM_SAVE_GAME) {
1021 /* If the network is active, make it not-active */
1022 if (_networking) {
1023 if (_network_server && (new_mode == SM_LOAD_GAME || new_mode == SM_NEWGAME || new_mode == SM_RESTARTGAME)) {
1024 NetworkReboot();
1025 } else {
1026 NetworkDisconnect();
1027 }
1028 }
1029
1030 /* If we are a server, we restart the server */
1031 if (_is_network_server) {
1032 /* But not if we are going to the menu */
1033 if (new_mode != SM_MENU) {
1034 /* check if we should reload the config */
1035 if (_settings_client.network.reload_cfg) {
1036 LoadFromConfig();
1037 MakeNewgameSettingsLive();
1038 ResetGRFConfig(false);
1039 }
1040 NetworkServerStart();
1041 } else {
1042 /* This client no longer wants to be a network-server */
1043 _is_network_server = false;
1044 }
1045 }
1046 }
1047
1048 /* Make sure all AI controllers are gone at quitting game */
1049 if (new_mode != SM_SAVE_GAME) AI::KillAll();
1050
1051 switch (new_mode) {
1052 case SM_EDITOR: // Switch to scenario editor
1053 MakeNewEditorWorld();
1054 break;
1055
1056 case SM_RELOADGAME: // Reload with what-ever started the game
1057 if (_file_to_saveload.abstract_ftype == FT_SAVEGAME || _file_to_saveload.abstract_ftype == FT_SCENARIO) {
1058 /* Reload current savegame/scenario */
1059 _switch_mode = _game_mode == GM_EDITOR ? SM_LOAD_SCENARIO : SM_LOAD_GAME;
1060 SwitchToMode(_switch_mode);
1061 break;
1062 } else if (_file_to_saveload.abstract_ftype == FT_HEIGHTMAP) {
1063 /* Restart current heightmap */
1064 _switch_mode = _game_mode == GM_EDITOR ? SM_LOAD_HEIGHTMAP : SM_RESTART_HEIGHTMAP;
1065 SwitchToMode(_switch_mode);
1066 break;
1067 }
1068
1069 MakeNewGame(false, new_mode == SM_NEWGAME);
1070 break;
1071
1072 case SM_RESTARTGAME: // Restart --> 'Random game' with current settings
1073 case SM_NEWGAME: // New Game --> 'Random game'
1074 MakeNewGame(false, new_mode == SM_NEWGAME);
1075 break;
1076
1077 case SM_LOAD_GAME: { // Load game, Play Scenario
1078 ResetGRFConfig(true);
1079 ResetWindowSystem();
1080
1081 if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_NORMAL, NO_DIRECTORY)) {
1082 SetDParamStr(0, GetSaveLoadErrorString());
1083 ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
1084 } else {
1085 if (_file_to_saveload.abstract_ftype == FT_SCENARIO) {
1086 OnStartScenario();
1087 }
1088 OnStartGame(_network_dedicated);
1089 /* Decrease pause counter (was increased from opening load dialog) */
1090 Command<CMD_PAUSE>::Post(PM_PAUSED_SAVELOAD, false);
1091 }
1092 break;
1093 }
1094
1095 case SM_RESTART_HEIGHTMAP: // Load a heightmap and start a new game from it with current settings
1096 case SM_START_HEIGHTMAP: // Load a heightmap and start a new game from it
1097 MakeNewGame(true, new_mode == SM_START_HEIGHTMAP);
1098 break;
1099
1100 case SM_LOAD_HEIGHTMAP: // Load heightmap from scenario editor
1101 SetLocalCompany(OWNER_NONE);
1102
1103 GenerateWorld(GWM_HEIGHTMAP, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
1104 MarkWholeScreenDirty();
1105 break;
1106
1107 case SM_LOAD_SCENARIO: { // Load scenario from scenario editor
1108 if (SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_EDITOR, NO_DIRECTORY)) {
1109 SetLocalCompany(OWNER_NONE);
1110 _settings_newgame.game_creation.starting_year = _cur_year;
1111 /* Cancel the saveload pausing */
1112 Command<CMD_PAUSE>::Post(PM_PAUSED_SAVELOAD, false);
1113 } else {
1114 SetDParamStr(0, GetSaveLoadErrorString());
1115 ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
1116 }
1117 break;
1118 }
1119
1120 case SM_JOIN_GAME: // Join a multiplayer game
1121 LoadIntroGame();
1122 NetworkClientJoinGame();
1123 break;
1124
1125 case SM_MENU: // Switch to game intro menu
1126 LoadIntroGame();
1127 if (BaseSounds::ini_set.empty() && BaseSounds::GetUsedSet()->fallback && SoundDriver::GetInstance()->HasOutput()) {
1128 ShowErrorMessage(STR_WARNING_FALLBACK_SOUNDSET, INVALID_STRING_ID, WL_CRITICAL);
1129 BaseSounds::ini_set = BaseSounds::GetUsedSet()->name;
1130 }
1131 break;
1132
1133 case SM_SAVE_GAME: // Save game.
1134 /* Make network saved games on pause compatible to singleplayer mode */
1135 if (SaveOrLoad(_file_to_saveload.name, SLO_SAVE, DFT_GAME_FILE, NO_DIRECTORY) != SL_OK) {
1136 SetDParamStr(0, GetSaveLoadErrorString());
1137 ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
1138 } else {
1139 CloseWindowById(WC_SAVELOAD, 0);
1140 }
1141 break;
1142
1143 case SM_SAVE_HEIGHTMAP: // Save heightmap.
1144 MakeHeightmapScreenshot(_file_to_saveload.name.c_str());
1145 CloseWindowById(WC_SAVELOAD, 0);
1146 break;
1147
1148 case SM_GENRANDLAND: // Generate random land within scenario editor
1149 SetLocalCompany(OWNER_NONE);
1150 GenerateWorld(GWM_RANDOM, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
1151 /* XXX: set date */
1152 MarkWholeScreenDirty();
1153 break;
1154
1155 default: NOT_REACHED();
1156 }
1157 }
1158
1159
1166 static void CheckCaches()
1167 {
1168 /* Return here so it is easy to add checks that are run
1169 * always to aid testing of caches. */
1170 if (_debug_desync_level <= 1) return;
1171
1172 /* Check the town caches. */
1173 std::vector<TownCache> old_town_caches;
1174 for (const Town *t : Town::Iterate()) {
1175 old_town_caches.push_back(t->cache);
1176 }
1177
1178 extern void RebuildTownCaches();
1179 RebuildTownCaches();
1180 RebuildSubsidisedSourceAndDestinationCache();
1181
1182 uint i = 0;
1183 for (Town *t : Town::Iterate()) {
1184 if (MemCmpT(old_town_caches.data() + i, &t->cache) != 0) {
1185 Debug(desync, 2, "town cache mismatch: town {}", t->index);
1186 }
1187 i++;
1188 }
1189
1190 /* Check company infrastructure cache. */
1191 std::vector<CompanyInfrastructure> old_infrastructure;
1192 for (const Company *c : Company::Iterate()) old_infrastructure.push_back(c->infrastructure);
1193
1194 extern void AfterLoadCompanyStats();
1195 AfterLoadCompanyStats();
1196
1197 i = 0;
1198 for (const Company *c : Company::Iterate()) {
1199 if (MemCmpT(old_infrastructure.data() + i, &c->infrastructure) != 0) {
1200 Debug(desync, 2, "infrastructure cache mismatch: company {}", c->index);
1201 }
1202 i++;
1203 }
1204
1205 /* Strict checking of the road stop cache entries */
1206 for (const RoadStop *rs : RoadStop::Iterate()) {
1207 if (IsStandardRoadStopTile(rs->xy)) continue;
1208
1209 assert(rs->GetEntry(DIAGDIR_NE) != rs->GetEntry(DIAGDIR_NW));
1210 rs->GetEntry(DIAGDIR_NE)->CheckIntegrity(rs);
1211 rs->GetEntry(DIAGDIR_NW)->CheckIntegrity(rs);
1212 }
1213
1214 for (Vehicle *v : Vehicle::Iterate()) {
1215 extern void FillNewGRFVehicleCache(const Vehicle *v);
1216 if (v != v->First() || v->vehstatus & VS_CRASHED || !v->IsPrimaryVehicle()) continue;
1217
1218 uint length = 0;
1219 for (const Vehicle *u = v; u != nullptr; u = u->Next()) length++;
1220
1221 NewGRFCache *grf_cache = CallocT<NewGRFCache>(length);
1222 VehicleCache *veh_cache = CallocT<VehicleCache>(length);
1223 GroundVehicleCache *gro_cache = CallocT<GroundVehicleCache>(length);
1224 TrainCache *tra_cache = CallocT<TrainCache>(length);
1225
1226 length = 0;
1227 for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
1228 FillNewGRFVehicleCache(u);
1229 grf_cache[length] = u->grf_cache;
1230 veh_cache[length] = u->vcache;
1231 switch (u->type) {
1232 case VEH_TRAIN:
1233 gro_cache[length] = Train::From(u)->gcache;
1234 tra_cache[length] = Train::From(u)->tcache;
1235 break;
1236 case VEH_ROAD:
1237 gro_cache[length] = RoadVehicle::From(u)->gcache;
1238 break;
1239 default:
1240 break;
1241 }
1242 length++;
1243 }
1244
1245 switch (v->type) {
1246 case VEH_TRAIN: Train::From(v)->ConsistChanged(CCF_TRACK); break;
1247 case VEH_ROAD: RoadVehUpdateCache(RoadVehicle::From(v)); break;
1248 case VEH_AIRCRAFT: UpdateAircraftCache(Aircraft::From(v)); break;
1249 case VEH_SHIP: Ship::From(v)->UpdateCache(); break;
1250 default: break;
1251 }
1252
1253 length = 0;
1254 for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
1255 FillNewGRFVehicleCache(u);
1256 if (memcmp(&grf_cache[length], &u->grf_cache, sizeof(NewGRFCache)) != 0) {
1257 Debug(desync, 2, "newgrf cache mismatch: type {}, vehicle {}, company {}, unit number {}, wagon {}", v->type, v->index, v->owner, v->unitnumber, length);
1258 }
1259 if (memcmp(&veh_cache[length], &u->vcache, sizeof(VehicleCache)) != 0) {
1260 Debug(desync, 2, "vehicle cache mismatch: type {}, vehicle {}, company {}, unit number {}, wagon {}", v->type, v->index, v->owner, v->unitnumber, length);
1261 }
1262 switch (u->type) {
1263 case VEH_TRAIN:
1264 if (memcmp(&gro_cache[length], &Train::From(u)->gcache, sizeof(GroundVehicleCache)) != 0) {
1265 Debug(desync, 2, "train ground vehicle cache mismatch: vehicle {}, company {}, unit number {}, wagon {}", v->index, v->owner, v->unitnumber, length);
1266 }
1267 if (memcmp(&tra_cache[length], &Train::From(u)->tcache, sizeof(TrainCache)) != 0) {
1268 Debug(desync, 2, "train cache mismatch: vehicle {}, company {}, unit number {}, wagon {}", v->index, v->owner, v->unitnumber, length);
1269 }
1270 break;
1271 case VEH_ROAD:
1272 if (memcmp(&gro_cache[length], &RoadVehicle::From(u)->gcache, sizeof(GroundVehicleCache)) != 0) {
1273 Debug(desync, 2, "road vehicle ground vehicle cache mismatch: vehicle {}, company {}, unit number {}, wagon {}", v->index, v->owner, v->unitnumber, length);
1274 }
1275 break;
1276 default:
1277 break;
1278 }
1279 length++;
1280 }
1281
1282 free(grf_cache);
1283 free(veh_cache);
1284 free(gro_cache);
1285 free(tra_cache);
1286 }
1287
1288 /* Check whether the caches are still valid */
1289 for (Vehicle *v : Vehicle::Iterate()) {
1290 byte buff[sizeof(VehicleCargoList)];
1291 memcpy(buff, &v->cargo, sizeof(VehicleCargoList));
1292 v->cargo.InvalidateCache();
1293 assert(memcmp(&v->cargo, buff, sizeof(VehicleCargoList)) == 0);
1294 }
1295
1296 /* Backup stations_near */
1297 std::vector<StationList> old_town_stations_near;
1298 for (Town *t : Town::Iterate()) old_town_stations_near.push_back(t->stations_near);
1299
1300 std::vector<StationList> old_industry_stations_near;
1301 for (Industry *ind : Industry::Iterate()) old_industry_stations_near.push_back(ind->stations_near);
1302
1303 for (Station *st : Station::Iterate()) {
1304 for (CargoID c = 0; c < NUM_CARGO; c++) {
1305 byte buff[sizeof(StationCargoList)];
1306 memcpy(buff, &st->goods[c].cargo, sizeof(StationCargoList));
1307 st->goods[c].cargo.InvalidateCache();
1308 assert(memcmp(&st->goods[c].cargo, buff, sizeof(StationCargoList)) == 0);
1309 }
1310
1311 /* Check docking tiles */
1312 TileArea ta;
1313 std::map<TileIndex, bool> docking_tiles;
1314 for (TileIndex tile : st->docking_station) {
1315 ta.Add(tile);
1316 docking_tiles[tile] = IsDockingTile(tile);
1317 }
1318 UpdateStationDockingTiles(st);
1319 if (ta.tile != st->docking_station.tile || ta.w != st->docking_station.w || ta.h != st->docking_station.h) {
1320 Debug(desync, 2, "station docking mismatch: station {}, company {}", st->index, st->owner);
1321 }
1322 for (TileIndex tile : ta) {
1323 if (docking_tiles[tile] != IsDockingTile(tile)) {
1324 Debug(desync, 2, "docking tile mismatch: tile {}", tile);
1325 }
1326 }
1327
1328 /* Check industries_near */
1329 IndustryList industries_near = st->industries_near;
1330 st->RecomputeCatchment();
1331 if (st->industries_near != industries_near) {
1332 Debug(desync, 2, "station industries near mismatch: station {}", st->index);
1333 }
1334 }
1335
1336 /* Check stations_near */
1337 i = 0;
1338 for (Town *t : Town::Iterate()) {
1339 if (t->stations_near != old_town_stations_near[i]) {
1340 Debug(desync, 2, "town stations near mismatch: town {}", t->index);
1341 }
1342 i++;
1343 }
1344 i = 0;
1345 for (Industry *ind : Industry::Iterate()) {
1346 if (ind->stations_near != old_industry_stations_near[i]) {
1347 Debug(desync, 2, "industry stations near mismatch: industry {}", ind->index);
1348 }
1349 i++;
1350 }
1351 }
1352
1358 void StateGameLoop()
1359 {
1360 if (!_networking || _network_server) {
1361 StateGameLoop_LinkGraphPauseControl();
1362 }
1363
1364 /* Don't execute the state loop during pause or when modal windows are open. */
1365 if (_pause_mode != PM_UNPAUSED || HasModalProgress()) {
1366 PerformanceMeasurer::Paused(PFE_GAMELOOP);
1367 PerformanceMeasurer::Paused(PFE_GL_ECONOMY);
1368 PerformanceMeasurer::Paused(PFE_GL_TRAINS);
1369 PerformanceMeasurer::Paused(PFE_GL_ROADVEHS);
1370 PerformanceMeasurer::Paused(PFE_GL_SHIPS);
1371 PerformanceMeasurer::Paused(PFE_GL_AIRCRAFT);
1372 PerformanceMeasurer::Paused(PFE_GL_LANDSCAPE);
1373
1374 if (!HasModalProgress()) UpdateLandscapingLimits();
1375 #ifndef DEBUG_DUMP_COMMANDS
1376 Game::GameLoop();
1377 #endif
1378 return;
1379 }
1380
1381 PerformanceMeasurer framerate(PFE_GAMELOOP);
1382 PerformanceAccumulator::Reset(PFE_GL_LANDSCAPE);
1383
1384 Layouter::ReduceLineCache();
1385
1386 if (_game_mode == GM_EDITOR) {
1387 BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
1388 RunTileLoop();
1389 CallVehicleTicks();
1390 CallLandscapeTick();
1391 BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
1392 UpdateLandscapingLimits();
1393
1394 CallWindowGameTickEvent();
1395 NewsLoop();
1396 } else {
1397 if (_debug_desync_level > 2 && _date_fract == 0 && (_date & 0x1F) == 0) {
1398 /* Save the desync savegame if needed. */
1399 char name[MAX_PATH];
1400 seprintf(name, lastof(name), "dmp_cmds_%08x_%08x.sav", _settings_game.game_creation.generation_seed, _date);
1401 SaveOrLoad(name, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);
1402 }
1403
1404 CheckCaches();
1405
1406 /* All these actions has to be done from OWNER_NONE
1407 * for multiplayer compatibility */
1408 Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
1409
1410 BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
1411 AnimateAnimatedTiles();
1412 IncreaseDate();
1413 RunTileLoop();
1414 CallVehicleTicks();
1415 CallLandscapeTick();
1416 BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
1417
1418 #ifndef DEBUG_DUMP_COMMANDS
1419 {
1420 PerformanceMeasurer framerate(PFE_ALLSCRIPTS);
1421 AI::GameLoop();
1422 Game::GameLoop();
1423 }
1424 #endif
1425 UpdateLandscapingLimits();
1426
1427 CallWindowGameTickEvent();
1428 NewsLoop();
1429 cur_company.Restore();
1430 }
1431
1432 assert(IsLocalCompany());
1433 }
1434
1439 static void DoAutosave()
1440 {
1441 static FiosNumberedSaveName _autosave_ctr("autosave");
1442 DoAutoOrNetsave(_autosave_ctr);
1443 }
1444
1453 bool RequestNewGRFScan(NewGRFScanCallback *callback)
1454 {
1455 if (_request_newgrf_scan) return false;
1456
1457 _request_newgrf_scan = true;
1458 _request_newgrf_scan_callback = callback;
1459 return true;
1460 }
1461
1462 void GameLoop()
1463 {
1464 if (_game_mode == GM_BOOTSTRAP) {
1465 /* Check for UDP stuff */
1466 if (_network_available) NetworkBackgroundLoop();
1467 return;
1468 }
1469
1470 if (_request_newgrf_scan) {
1471 ScanNewGRFFiles(_request_newgrf_scan_callback);
1472 _request_newgrf_scan = false;
1473 _request_newgrf_scan_callback = nullptr;
1474 /* In case someone closed the game during our scan, don't do anything else. */
1475 if (_exit_game) return;
1476 }
1477
1478 ProcessAsyncSaveFinish();
1479
1480 /* autosave game? */
1481 if (_do_autosave) {
1482 DoAutosave();
1483 _do_autosave = false;
1484 SetWindowDirty(WC_STATUS_BAR, 0);
1485 }
1486
1487 /* switch game mode? */
1488 if (_switch_mode != SM_NONE && !HasModalProgress()) {
1489 SwitchToMode(_switch_mode);
1490 _switch_mode = SM_NONE;
1491 }
1492
1493 IncreaseSpriteLRU();
1494
1495 /* Check for UDP stuff */
1496 if (_network_available) NetworkBackgroundLoop();
1497
1498 DebugSendRemoteMessages();
1499
1500 if (_networking && !HasModalProgress()) {
1501 /* Multiplayer */
1502 NetworkGameLoop();
1503 } else {
1504 if (_network_reconnect > 0 && --_network_reconnect == 0) {
1505 /* This means that we want to reconnect to the last host
1506 * We do this here, because it means that the network is really closed */
1507 NetworkClientConnectGame(_settings_client.network.last_joined, COMPANY_SPECTATOR);
1508 }
1509 /* Singleplayer */
1510 StateGameLoop();
1511 }
1512
1513 if (!_pause_mode && HasBit(_display_opt, DO_FULL_ANIMATION)) DoPaletteAnimations();
1514
1515 SoundDriver::GetInstance()->MainLoop();
1516 MusicLoop();
1517 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
game.hpp
AI::Uninitialize
static void Uninitialize(bool keepConfig)
Uninitialize the AI system.
Definition: ai_core.cpp:177
WC_SAVELOAD
@ WC_SAVELOAD
Saveload window; Window numbers:
Definition: window_type.h:137
openttd_main
int openttd_main(int argc, char *argv[])
Main entry point for this lovely game.
Definition: openttd.cpp:531
AfterNewGRFScan::save_config
bool save_config
The save config setting.
Definition: openttd.cpp:418
LinkGraphSchedule::Clear
static void Clear()
Clear all link graphs and jobs from the schedule.
Definition: linkgraphschedule.cpp:121
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:966
DriverFactoryBase::ShutdownDrivers
static void ShutdownDrivers()
Shuts down all active drivers.
Definition: driver.h:125
SwitchMode
SwitchMode
Mode which defines what mode we're switching to.
Definition: openttd.h:25
CheckEngines
void CheckEngines()
Check for engines that have an appropriate availability.
Definition: engine.cpp:1235
GameCreationSettings::generation_seed
uint32 generation_seed
noise seed for world generation
Definition: settings_type.h:312
factory.hpp
AIConfig
Definition: ai_config.hpp:16
EngineOverrideManager::ResetToCurrentNewGRFConfig
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
Definition: engine.cpp:519
GameSettings::ai_config
class AIConfig * ai_config[MAX_COMPANIES]
settings per company
Definition: settings_type.h:591
FT_SCENARIO
@ FT_SCENARIO
old or new scenario
Definition: fileio_type.h:19
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
SAVE_DIR
@ SAVE_DIR
Base directory for all savegames.
Definition: fileio_type.h:110
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3156
SM_START_HEIGHTMAP
@ SM_START_HEIGHTMAP
Load a heightmap and start a new game from it.
Definition: openttd.h:37
usererror
void CDECL usererror(const char *s,...)
Error handling for fatal user errors.
Definition: openttd.cpp:105
train.h
SM_LOAD_GAME
@ SM_LOAD_GAME
Load game, Play Scenario.
Definition: openttd.h:31
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
command_func.h
ErrorMessageData::SetDParamStr
void SetDParamStr(uint n, const char *str)
Set a rawstring parameter.
Definition: error_gui.cpp:161
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:543
GameCreationSettings::map_y
uint8 map_y
Y size of map.
Definition: settings_type.h:316
DoExitSave
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
Definition: saveload.cpp:3344
AfterNewGRFScan::join_server_password
std::string join_server_password
The password to join the server with.
Definition: openttd.cpp:416
LoadCheckData::gamelog_action
struct LoggedAction * gamelog_action
Gamelog actions.
Definition: fios.h:46
_config_file
std::string _config_file
Configuration file of OpenTTD.
Definition: settings.cpp:57
Backup
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:21
NetworkSettings::server_port
uint16 server_port
port the server listens on
Definition: settings_type.h:282
Vehicle::Next
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:610
_cur_year
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:26
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:140
BLT_8BPP
@ BLT_8BPP
Base set has 8 bpp sprites only.
Definition: base_media_base.h:243
CheckIndustries
void CheckIndustries()
Verify whether the generated industries are complete, and warn the user if not.
Definition: industry_cmd.cpp:2988
Station
Station data structure.
Definition: station_base.h:454
SafeLoad
bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf=nullptr)
Load the specified savegame but on error do different things.
Definition: openttd.cpp:962
BASESET_DIR
@ BASESET_DIR
Subdirectory for all base data (base sets, intro game)
Definition: fileio_type.h:116
TarScanner::DoScan
uint DoScan(Subdirectory sd)
Perform the scanning of a particular subdirectory.
Definition: fileio.cpp:410
elrail_func.h
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:3234
MusicDriver::SetVolume
virtual void SetVolume(byte vol)=0
Set the volume, if possible.
SoundDriver::MainLoop
virtual void MainLoop()
Called once every tick.
Definition: sound_driver.hpp:19
_date_fract
DateFract _date_fract
Fractional part of the day.
Definition: date.cpp:29
SM_EDITOR
@ SM_EDITOR
Switch to scenario editor.
Definition: openttd.h:30
NetworkSettings::default_company_pass
std::string default_company_pass
default password for new companies in encrypted form
Definition: settings_type.h:293
_network_server
bool _network_server
network-server is active
Definition: network.cpp:59
BaseSet::name
std::string name
The name of the base set.
Definition: base_media_base.h:61
SaveLoadOperation
SaveLoadOperation
Operation performed on the file.
Definition: fileio_type.h:47
FileToSaveLoad::name
std::string name
Name of the file.
Definition: saveload.h:363
UpdateNewGRFConfigPalette
void UpdateNewGRFConfigPalette(int32 new_value)
Update the palettes of the graphics from the config file.
Definition: newgrf_config.cpp:287
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:332
SaveToConfig
void SaveToConfig()
Save the values to the configuration file.
Definition: settings.cpp:1260
_load_check_data
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition: fios_gui.cpp:39
InitWindowSystem
void InitWindowSystem()
(re)initialize the windowing system
Definition: window.cpp:1840
_old_vds
VehicleDefaultSettings _old_vds
Used for loading default vehicles settings from old savegames.
Definition: settings.cpp:56
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
Game::GetConsoleList
static std::string GetConsoleList(bool newest_only=false)
Wrapper function for GameScanner::GetConsoleList.
Definition: game_core.cpp:222
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:219
_skip_all_newgrf_scanning
int _skip_all_newgrf_scanning
Set this flag to prevent any NewGRF scanning from being done.
Definition: newgrf_config.cpp:580
PFE_GL_ROADVEHS
@ PFE_GL_ROADVEHS
Time spend processing road vehicles.
Definition: framerate_type.h:52
BlitterFactory::SelectBlitter
static Blitter * SelectBlitter(const std::string &name)
Find the requested blitter and return its class.
Definition: factory.hpp:98
SLO_CHECK
@ SLO_CHECK
Load file for checking and/or preview.
Definition: fileio_type.h:48
misc_cmd.h
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
ship.h
PerformanceMeasurer
RAII class for measuring simple elements of performance.
Definition: framerate_type.h:92
_do_autosave
bool _do_autosave
are we doing an autosave at the moment?
Definition: saveload.cpp:69
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
CompanySettings::vehicle
VehicleDefaultSettings vehicle
default settings for vehicles
Definition: settings_type.h:581
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:103
UnInitWindowSystem
void UnInitWindowSystem()
Close down the windowing system.
Definition: window.cpp:1859
DFT_GAME_FILE
@ DFT_GAME_FILE
Save game or scenario file.
Definition: fileio_type.h:31
GameSettings::game_config
class GameConfig * game_config
settings for gamescript
Definition: settings_type.h:592
LoadCheckData::grfconfig
GRFConfig * grfconfig
NewGrf configuration from save.
Definition: fios.h:43
StationCargoList
CargoList that is used for stations.
Definition: cargopacket.h:449
FileToSaveLoad::SetName
void SetName(const char *name)
Set the name of the file.
Definition: saveload.cpp:3416
IsStandardRoadStopTile
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
Definition: station_map.h:223
INVALID_YEAR
static const Year INVALID_YEAR
Representation of an invalid year.
Definition: date_type.h:110
HandleBootstrap
bool HandleBootstrap()
Handle all procedures for bootstrapping OpenTTD without a base graphics set.
Definition: bootstrap_gui.cpp:285
Year
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:18
RequestNewGRFScan
bool RequestNewGRFScan(NewGRFScanCallback *callback)
Request a new NewGRF scan.
Definition: openttd.cpp:1453
saveload.h
aircraft.h
base_media_base.h
AUTOSAVE_DIR
@ AUTOSAVE_DIR
Subdirectory of save for autosaves.
Definition: fileio_type.h:111
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
_network_bind_list
StringList _network_bind_list
The addresses to bind on.
Definition: network.cpp:67
NetworkBackgroundLoop
void NetworkBackgroundLoop()
We have to do some (simple) background stuff that runs normally, even when we are not in multiplayer.
Definition: network.cpp:1023
LoadFromHighScore
void LoadFromHighScore()
Initialize the highscore table to 0 and if any file exists, load in values.
Definition: highscore.cpp:152
town.h
OrthogonalTileArea::Add
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
Definition: tilearea.cpp:43
LoadCheckData::HasErrors
bool HasErrors()
Check whether loading the game resulted in errors.
Definition: fios.h:67
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition: direction_type.h:82
Company::infrastructure
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:130
network_gui.h
_display_opt
byte _display_opt
What do we want to draw/do?
Definition: transparency_gui.cpp:26
BaseMedia< GraphicsSet >::GetSetsList
static char * GetSetsList(char *p, const char *last)
Returns a list with the sets.
Definition: base_media_func.h:255
SetDebugString
void SetDebugString(const char *s, void(*error_func)(const char *))
Set debugging levels by parsing the text in s.
Definition: debug.cpp:164
LoadWithFilter
SaveOrLoadResult LoadWithFilter(LoadFilter *reader)
Load the game using a (reader) filter.
Definition: saveload.cpp:3214
GETOPT_SHORT_NOVAL
#define GETOPT_SHORT_NOVAL(shortname)
Short option without value.
Definition: getoptdata.h:91
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
Industry
Defines the internal data of a functional industry.
Definition: industry.h:66
AfterNewGRFScan::AfterNewGRFScan
AfterNewGRFScan()
Create a new callback.
Definition: openttd.cpp:423
Vehicle::IsPrimaryVehicle
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:460
SM_LOAD_SCENARIO
@ SM_LOAD_SCENARIO
Load scenario from scenario editor.
Definition: openttd.h:36
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:288
gamelog.h
fios.h
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
IsLocalCompany
static bool IsLocalCompany()
Is the current company the local company?
Definition: company_func.h:43
CheckCaches
static void CheckCaches()
Check the validity of some of the caches.
Definition: openttd.cpp:1166
GENERATE_NEW_SEED
static const uint32 GENERATE_NEW_SEED
Create a new random seed.
Definition: genworld.h:24
genworld.h
MakeHeightmapScreenshot
bool MakeHeightmapScreenshot(const char *filename)
Make a heightmap of the current map.
Definition: screenshot.cpp:848
InitializeScreenshotFormats
void InitializeScreenshotFormats()
Initialize screenshot format information on startup, with _screenshot_format_name filled from the loa...
Definition: screenshot.cpp:585
PFE_GL_LANDSCAPE
@ PFE_GL_LANDSCAPE
Time spent processing other world features.
Definition: framerate_type.h:55
GCF_COMPATIBLE
@ GCF_COMPATIBLE
GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches)
Definition: newgrf_config.h:26
_ini_musicdriver
std::string _ini_musicdriver
The music driver a stored in the configuration file.
Definition: driver.cpp:37
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Definition: error_gui.cpp:377
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:587
SpecializedStation< Station, false >::Iterate
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
Definition: base_station_base.h:269
ai.hpp
PFE_GL_TRAINS
@ PFE_GL_TRAINS
Time spent processing trains.
Definition: framerate_type.h:51
UninitFontCache
void UninitFontCache()
Free everything allocated w.r.t.
Definition: fontcache.cpp:152
NetworkChangeCompanyPassword
std::string NetworkChangeCompanyPassword(CompanyID company_id, std::string password)
Change the company password of a given company.
Definition: network.cpp:157
VehicleCargoList
CargoList that is used for vehicles.
Definition: cargopacket.h:269
screenshot.h
RebuildTownCaches
void RebuildTownCaches()
Rebuild all the cached variables of towns.
Definition: town_sl.cpp:30
GETOPT_SHORT_OPTVAL
#define GETOPT_SHORT_OPTVAL(shortname)
Short option with optional value.
Definition: getoptdata.h:104
PM_UNPAUSED
@ PM_UNPAUSED
A normal unpaused game.
Definition: openttd.h:61
Ship::UpdateCache
void UpdateCache()
Update the caches of this ship.
Definition: ship_cmd.cpp:203
BaseMedia< GraphicsSet >::ini_set
static std::string ini_set
The set as saved in the config file.
Definition: base_media_base.h:179
AdjustGUIZoom
bool AdjustGUIZoom(bool automatic)
Resolve GUI zoom level and adjust GUI to new zoom, if auto-suggestion is requested.
Definition: gfx.cpp:2023
COMPANY_FIRST
@ COMPANY_FIRST
First company, same as owner.
Definition: company_type.h:22
DO_FULL_ANIMATION
@ DO_FULL_ANIMATION
Perform palette animation.
Definition: openttd.h:48
NetworkClientJoinGame
void NetworkClientJoinGame()
Actually perform the joining to the server.
Definition: network.cpp:796
FileToSaveLoad::abstract_ftype
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
Definition: saveload.h:362
_company_colours
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
Definition: company_cmd.cpp:48
OnStartGame
static void OnStartGame(bool dedicated_server)
Triggers everything that should be triggered when starting a game.
Definition: openttd.cpp:864
COMPANY_NEW_COMPANY
@ COMPANY_NEW_COMPANY
The client wants a new company.
Definition: company_type.h:34
SLO_LOAD
@ SLO_LOAD
File is being loaded.
Definition: fileio_type.h:49
GroundVehicleCache
Cached, frequently calculated values.
Definition: ground_vehicle.hpp:29
DumpDebugFacilityNames
char * DumpDebugFacilityNames(char *buf, char *last)
Dump the available debug facility names in the help text.
Definition: debug.cpp:93
AfterNewGRFScan::generation_seed
uint32 generation_seed
Seed for the new game.
Definition: openttd.cpp:412
CompanyProperties::colour
byte colour
Company colour.
Definition: company_base.h:71
GWM_HEIGHTMAP
@ GWM_HEIGHTMAP
Generate a newgame from a heightmap.
Definition: genworld.h:31
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
NetworkSettings::last_joined
std::string last_joined
Last joined server.
Definition: settings_type.h:305
SLO_SAVE
@ SLO_SAVE
File is being saved.
Definition: fileio_type.h:50
settings_func.h
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:155
PM_PAUSED_SAVELOAD
@ PM_PAUSED_SAVELOAD
A game paused for saving/loading.
Definition: openttd.h:63
MusicDriver::GetInstance
static MusicDriver * GetInstance()
Get the currently active instance of the music driver.
Definition: music_driver.hpp:46
SM_NEWGAME
@ SM_NEWGAME
New Game --> 'Random game'.
Definition: openttd.h:27
DriverFactoryBase::GetDriversInfo
static char * GetDriversInfo(char *p, const char *last)
Build a human readable list of available drivers, grouped by type.
Definition: driver.cpp:230
GUISettings::starting_colour
byte starting_colour
default color scheme for the company to start a new game with
Definition: settings_type.h:173
S8BPP_NONE
@ S8BPP_NONE
No support for 8bpp by OS or hardware, force 32bpp blitters.
Definition: gfx_type.h:327
roadstop_base.h
AfterNewGRFScan::startyear
Year startyear
The start year.
Definition: openttd.cpp:411
SM_SAVE_HEIGHTMAP
@ SM_SAVE_HEIGHTMAP
Save heightmap.
Definition: openttd.h:34
LoadCheckData::error_data
char * error_data
Data to pass to SetDParamStr when displaying error.
Definition: fios.h:34
LoadCheckData::gamelog_actions
uint gamelog_actions
Number of gamelog actions.
Definition: fios.h:47
highscore.h
GetSaveLoadErrorString
const char * GetSaveLoadErrorString()
Get the string representation of the error message.
Definition: saveload.cpp:2944
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:41
GWM_RANDOM
@ GWM_RANDOM
Generate a random map for SE.
Definition: genworld.h:30
CrashLog::SetErrorMessage
static void SetErrorMessage(const char *message)
Sets a message for the error message handler.
Definition: crashlog.cpp:517
GameConfig
Definition: game_config.hpp:15
OrthogonalTileArea::w
uint16 w
The width of the area.
Definition: tilearea_type.h:20
ShowHelp
static void ShowHelp()
Show the help message when someone passed a wrong parameter.
Definition: openttd.cpp:169
PFE_GL_SHIPS
@ PFE_GL_SHIPS
Time spent processing ships.
Definition: framerate_type.h:53
GETOPT_END
#define GETOPT_END()
Option terminator.
Definition: getoptdata.h:107
InitFontCache
void InitFontCache(bool monospace)
(Re)initialize the font cache related things, i.e.
Definition: fontcache.cpp:128
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:295
GUISettings::pause_on_newgame
bool pause_on_newgame
whether to start new games paused or not
Definition: settings_type.h:150
AIConfig::GetConfig
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: ai_config.cpp:45
AfterLoadCompanyStats
void AfterLoadCompanyStats()
Rebuilding of company statistics after loading a savegame.
Definition: company_sl.cpp:96
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:355
OnStartScenario
static void OnStartScenario()
Triggers everything required to set up a saved scenario for a new game.
Definition: openttd.cpp:849
GroundVehicle::gcache
GroundVehicleCache gcache
Cache of often calculated values.
Definition: ground_vehicle.hpp:80
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
_pause_mode
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:50
road_gui.h
AI::Initialize
static void Initialize()
Initialize the AI system.
Definition: ai_core.cpp:163
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
CompanyProperties::settings
CompanySettings settings
settings specific for each company
Definition: company_base.h:106
PSM_ENTER_GAMELOOP
@ PSM_ENTER_GAMELOOP
Enter the gameloop, changes will be permanent.
Definition: newgrf_storage.h:20
ShutdownGame
static void ShutdownGame()
Uninitializes drivers, frees allocated memory, cleans pools, ...
Definition: openttd.cpp:312
DoAutosave
static void DoAutosave()
Create an autosave.
Definition: openttd.cpp:1439
VehicleCache
Cached often queried values common to all vehicles.
Definition: vehicle_base.h:124
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
industry.h
safeguards.h
NetworkDisconnect
void NetworkDisconnect(bool blocking, bool close_admins)
We want to disconnect from the host/clients.
Definition: network.cpp:946
music_driver.hpp
SaveHotkeysToConfig
void SaveHotkeysToConfig()
Save the hotkeys to the config file.
Definition: hotkeys.cpp:363
CursorVars::fix_at
bool fix_at
mouse is moving, but cursor is not (used for scrolling)
Definition: gfx_type.h:120
PoolBase::Clean
static void Clean(PoolType)
Clean all pools of given type.
Definition: pool_func.cpp:30
FT_INVALID
@ FT_INVALID
Invalid or unknown file type.
Definition: fileio_type.h:22
NetworkShutDown
void NetworkShutDown()
This shuts the network down.
Definition: network.cpp:1277
SaveLoadVersion
SaveLoadVersion
SaveLoad versions Previous savegame versions, the trunk revision where they were introduced and the r...
Definition: saveload.h:34
Game::Uninitialize
static void Uninitialize(bool keepConfig)
Uninitialize the Game system.
Definition: game_core.cpp:102
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:67
ParseFullConnectionString
std::string_view ParseFullConnectionString(const std::string &connection_string, uint16 &port, CompanyID *company_id)
Converts a string to ip/port/company Format: IP:port::company.
Definition: network.cpp:507
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:58
GetOptData::opt
char * opt
Option value, if available (else nullptr).
Definition: getoptdata.h:31
gfx_layout.h
ScanNewGRFFiles
void ScanNewGRFFiles(NewGRFScanCallback *callback)
Scan for all NewGRFs.
Definition: newgrf_config.cpp:727
ErrorMessageData
The data of the error message.
Definition: error.h:29
DFT_OLD_GAME_FILE
@ DFT_OLD_GAME_FILE
Old save game or scenario file.
Definition: fileio_type.h:30
vseprintf
int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap)
Safer implementation of vsnprintf; same as vsnprintf except:
Definition: string.cpp:62
error.h
PFE_GL_AIRCRAFT
@ PFE_GL_AIRCRAFT
Time spent processing aircraft.
Definition: framerate_type.h:54
DoAutoOrNetsave
void DoAutoOrNetsave(FiosNumberedSaveName &counter)
Create an autosave or netsave.
Definition: saveload.cpp:3325
_network_reconnect
uint8 _network_reconnect
Reconnect timeout.
Definition: network.cpp:66
_network_dedicated
bool _network_dedicated
are we a dedicated server?
Definition: network.cpp:61
AI::GameLoop
static void GameLoop()
Called every game-tick to let AIs do something.
Definition: ai_core.cpp:69
WindowDesc::SaveToConfig
static void SaveToConfig()
Save all WindowDesc settings to _windows_file.
Definition: window.cpp:175
date_func.h
linkgraphschedule.h
stdafx.h
FT_SAVEGAME
@ FT_SAVEGAME
old or new savegame
Definition: fileio_type.h:18
GameMode
GameMode
Mode which defines the state of the game.
Definition: openttd.h:17
SM_GENRANDLAND
@ SM_GENRANDLAND
Generate random land within scenario editor.
Definition: openttd.h:35
SM_SAVE_GAME
@ SM_SAVE_GAME
Save game.
Definition: openttd.h:33
OptionData
Data of an option.
Definition: getoptdata.h:22
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:202
GetOptData
Data storage for parsing command line options.
Definition: getoptdata.h:30
viewport_func.h
PerformanceMeasurer::Paused
static void Paused(PerformanceElement elem)
Indicate that a cycle of "pause" where no processing occurs.
Definition: framerate_gui.cpp:297
LoadCheckData::error
StringID error
Error message from loading. INVALID_STRING_ID if no error.
Definition: fios.h:33
animated_tile_func.h
Layouter::ReduceLineCache
static void ReduceLineCache()
Reduce the size of linecache if necessary to prevent infinite growth.
Definition: gfx_layout.cpp:920
PT_ALL
@ PT_ALL
All pool types.
Definition: pool_type.hpp:23
AfterNewGRFScan::join_company_password
std::string join_company_password
The password to join the company with.
Definition: openttd.cpp:417
OrthogonalTileArea::h
uint16 h
The height of the area.
Definition: tilearea_type.h:21
ObjectSpec::name
StringID name
The name for this object.
Definition: newgrf_object.h:64
UpdateAircraftCache
void UpdateAircraftCache(Aircraft *v, bool update_range=false)
Update cached values of an aircraft.
Definition: aircraft_cmd.cpp:590
SM_LOAD_HEIGHTMAP
@ SM_LOAD_HEIGHTMAP
Load heightmap from scenario editor.
Definition: openttd.h:38
sound_driver.hpp
IncreaseDate
void IncreaseDate()
Increases the tick counter, increases date and possibly calls procedures that have to be called daily...
Definition: date.cpp:270
_blitter_autodetected
bool _blitter_autodetected
Was the blitter autodetected or specified by the user?
Definition: driver.cpp:40
DFT_INVALID
@ DFT_INVALID
Unknown or invalid file.
Definition: fileio_type.h:43
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:49
rail_gui.h
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
vehicle_func.h
rev.h
Game::GameLoop
static void GameLoop()
Called every game-tick to let Game do something.
Definition: game_core.cpp:31
station_base.h
Driver::DT_SOUND
@ DT_SOUND
A sound driver.
Definition: driver.h:43
TarScanner::SCENARIO
@ SCENARIO
Scan for scenarios and heightmaps.
Definition: fileio_func.h:70
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:386
strings_func.h
Vehicle::First
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:623
PFE_GAMELOOP
@ PFE_GAMELOOP
Speed of gameloop processing.
Definition: framerate_type.h:49
FiosNumberedSaveName
A savegame name automatically numbered.
Definition: fios.h:131
AI::KillAll
static void KillAll()
Kill any and all AIs we manage.
Definition: ai_core.cpp:153
DetailedFileType
DetailedFileType
Kinds of files in each AbstractFileType.
Definition: fileio_type.h:28
LoadCheckData::Clear
void Clear()
Reset read data.
Definition: fios_gui.cpp:48
RoadVehUpdateCache
void RoadVehUpdateCache(RoadVehicle *v, bool same_length=false)
Update the cache of a road vehicle.
Definition: roadveh_cmd.cpp:217
PFE_GL_ECONOMY
@ PFE_GL_ECONOMY
Time spent processing cargo movement.
Definition: framerate_type.h:50
subsidy_func.h
SaveToHighScore
void SaveToHighScore()
Save HighScore table to file.
Definition: highscore.cpp:124
RebuildSubsidisedSourceAndDestinationCache
void RebuildSubsidisedSourceAndDestinationCache()
Perform a full rebuild of the subsidies cache.
Definition: subsidy.cpp:132
FillNewGRFVehicleCache
void FillNewGRFVehicleCache(const Vehicle *v)
Fill the grf_cache of the given vehicle.
Definition: newgrf_engine.cpp:1381
Backup::Restore
void Restore()
Restore the variable.
Definition: backup_type.hpp:112
AfterNewGRFScan::dedicated_port
uint16 dedicated_port
Port for the dedicated server.
Definition: openttd.cpp:414
_ini_blitter
std::string _ini_blitter
The blitter as stored in the configuration file.
Definition: driver.cpp:39
FiosGetSavegameListCallback
FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const std::string &file, const char *ext, char *title, const char *last)
Callback for FiosGetFileList.
Definition: fios.cpp:465
GameCreationSettings::map_x
uint8 map_x
X size of map.
Definition: settings_type.h:315
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1183
Train::ConsistChanged
void ConsistChanged(ConsistChangeFlags allowed_changes)
Recalculates the cached stuff of a train.
Definition: train_cmd.cpp:108
video_driver.hpp
NO_DIRECTORY
@ NO_DIRECTORY
A path without any base directory.
Definition: fileio_type.h:125
COMPANY_SPECTATOR
@ COMPANY_SPECTATOR
The client is spectating.
Definition: company_type.h:35
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
Driver::DT_VIDEO
@ DT_VIDEO
A video driver.
Definition: driver.h:44
framerate_type.h
_file_to_saveload
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition: saveload.cpp:63
GRFConfig::next
struct GRFConfig * next
NOSAVE: Next item in the linked list.
Definition: newgrf_config.h:183
_ini_sounddriver
std::string _ini_sounddriver
The sound driver a stored in the configuration file.
Definition: driver.cpp:35
ScheduleErrorMessage
void ScheduleErrorMessage(const ErrorMessageData &data)
Schedule an error.
Definition: error_gui.cpp:451
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
PM_PAUSED_NORMAL
@ PM_PAUSED_NORMAL
A game normally paused.
Definition: openttd.h:62
_options
static const OptionData _options[]
Options of OpenTTD.
Definition: openttd.cpp:494
GWM_EMPTY
@ GWM_EMPTY
Generate an empty map (sea-level)
Definition: genworld.h:29
newgrf.h
SM_RESTART_HEIGHTMAP
@ SM_RESTART_HEIGHTMAP
Load a heightmap and start a new game from it with current settings.
Definition: openttd.h:39
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
BaseMedia< GraphicsSet >::FindSets
static uint FindSets()
Do the scan for files.
Definition: base_media_base.h:189
PFE_ALLSCRIPTS
@ PFE_ALLSCRIPTS
Sum of all GS/AI scripts.
Definition: framerate_type.h:61
VehicleSettings::disable_elrails
bool disable_elrails
when true, the elrails are disabled
Definition: settings_type.h:494
GetFirstPlayableCompanyID
CompanyID GetFirstPlayableCompanyID()
Get the index of the first available company.
Definition: company_cmd.cpp:1226
progress.h
ShowInfoF
void CDECL ShowInfoF(const char *str,...)
Shows some information on the console/a popup box depending on the OS.
Definition: openttd.cpp:156
DebugSendRemoteMessages
void DebugSendRemoteMessages()
Send the queued Debug messages to either NetworkAdminConsole or IConsolePrint from the GameLoop threa...
Definition: debug.cpp:270
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:554
CallWindowGameTickEvent
void CallWindowGameTickEvent()
Dispatch OnGameTick event over all windows.
Definition: window.cpp:3283
FT_HEIGHTMAP
@ FT_HEIGHTMAP
heightmap file
Definition: fileio_type.h:20
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:108
ResetNewGRFData
void ResetNewGRFData()
Reset all NewGRF loaded data.
Definition: newgrf.cpp:8635
GameCreationSettings::starting_year
Year starting_year
starting date
Definition: settings_type.h:313
Vehicle::unitnumber
UnitID unitnumber
unit number, for display purposes only
Definition: vehicle_base.h:305
SaveOrLoadResult
SaveOrLoadResult
Save or load result codes.
Definition: saveload.h:352
company_func.h
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:24
GamelogReset
void GamelogReset()
Resets and frees all memory allocated - used before loading or starting a new game.
Definition: gamelog.cpp:115
SM_RELOADGAME
@ SM_RELOADGAME
Reload the savegame / scenario / heightmap you started the game with.
Definition: openttd.h:29
FiosType
FiosType
Elements of a file system that are recognized.
Definition: fileio_type.h:67
SM_MENU
@ SM_MENU
Switch to game intro menu.
Definition: openttd.h:32
AnimateAnimatedTiles
void AnimateAnimatedTiles()
Animate all tiles in the animated tile list, i.e. call AnimateTile on them.
Definition: animated_tile.cpp:50
GWM_NEWGAME
@ GWM_NEWGAME
Generate a map for a new game.
Definition: genworld.h:28
GetOptData::GetOpt
int GetOpt()
Find the next option.
Definition: getoptdata.cpp:22
DriverFactoryBase::SelectDriver
static void SelectDriver(const std::string &name, Driver::Type type)
Find the requested driver and return its class.
Definition: driver.cpp:94
error
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:134
AfterNewGRFScan
Callback structure of statements to be executed after the NewGRF scan.
Definition: openttd.cpp:410
network.h
MusicLoop
void MusicLoop()
Check music playback status and start/stop/song-finished.
Definition: music_gui.cpp:424
IsDockingTile
static bool IsDockingTile(TileIndex t)
Checks whether the tile is marked as a dockling tile.
Definition: water_map.h:376
CommandHelper
Definition: command_func.h:94
NetworkClientConnectGame
bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const std::string &join_server_password, const std::string &join_company_password)
Join a client to the server at with the given connection string.
Definition: network.cpp:764
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:2158
SLO_INVALID
@ SLO_INVALID
Unknown file operation.
Definition: fileio_type.h:52
AI::GetConsoleList
static std::string GetConsoleList(bool newest_only=false)
Wrapper function for AIScanner::GetAIConsoleList.
Definition: ai_core.cpp:305
Debug
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
NewGRFScanCallback
Callback for NewGRF scanning.
Definition: newgrf_config.h:213
LoadFilter
Interface for filtering a savegame till it is loaded.
Definition: saveload_filter.h:14
Town
Town data structure.
Definition: town.h:50
TrainCache
Variables that are cached to improve performance and such.
Definition: train.h:72
MusicSettings::effect_vol
byte effect_vol
The requested effects volume.
Definition: settings_type.h:227
WindowDesc::LoadFromConfig
static void LoadFromConfig()
Load all WindowDesc settings from _windows_file.
Definition: window.cpp:153
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1767
ClientSettings::network
NetworkSettings network
settings related to the network
Definition: settings_type.h:605
random_func.hpp
LoadHotkeysFromConfig
void LoadHotkeysFromConfig()
Load the hotkeys from the config file.
Definition: hotkeys.cpp:357
VideoDriver::MainLoop
virtual void MainLoop()=0
Perform the actual drawing.
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1191
TarScanner::BASESET
@ BASESET
Scan for base sets.
Definition: fileio_func.h:67
GenerateWorld
void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings)
Generate a world.
Definition: genworld.cpp:271
SoundDriver::GetInstance
static SoundDriver * GetInstance()
Get the currently active instance of the sound driver.
Definition: sound_driver.hpp:35
PSM_LEAVE_GAMELOOP
@ PSM_LEAVE_GAMELOOP
Leave the gameloop, changes will be temporary.
Definition: newgrf_storage.h:21
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
crashlog.h
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:55
fontcache.h
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:327
IConsoleCmdExec
void IConsoleCmdExec(const char *cmdstr, const uint recurse_count)
Execute a given command passed to us.
Definition: console.cpp:303
ScriptConfig::Change
void Change(const char *name, int version=-1, bool force_exact_match=false, bool is_random=false)
Set another Script to be loaded in this slot.
Definition: script_config.cpp:19
ProcessAsyncSaveFinish
void ProcessAsyncSaveFinish()
Handle async save finishes.
Definition: saveload.cpp:409
InitializeRailGUI
void InitializeRailGUI()
Resets the rail GUI - sets default railtype to build and resets the signal GUI.
Definition: rail_gui.cpp:2225
ResetWindowSystem
void ResetWindowSystem()
Reset the windowing system, by means of shutting it down followed by re-initialization.
Definition: window.cpp:1873
gui.h
LoadIntroGame
static void LoadIntroGame(bool load_newgrfs=true)
Load the introduction game.
Definition: openttd.cpp:342
ZOOM_LVL_NORMAL
@ ZOOM_LVL_NORMAL
The normal zoom level.
Definition: zoom_type.h:22
AfterNewGRFScan::connection_string
std::string connection_string
Information about the server to connect to.
Definition: openttd.cpp:415
ClientSettings::company
CompanySettings company
default values for per-company settings
Definition: settings_type.h:606
GUISettings::last_newgrf_count
uint32 last_newgrf_count
the numbers of NewGRFs we found during the last scan
Definition: settings_type.h:169
CCF_TRACK
@ CCF_TRACK
Valid changes while vehicle is driving, and possibly changing tracks.
Definition: train.h:48
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:595
LoadCheckData::HasNewGrfs
bool HasNewGrfs()
Check whether the game uses any NewGrfs.
Definition: fios.h:76
getoptdata.h
md5sumToString
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Definition: string.cpp:572
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
FileToSaveLoad::detail_ftype
DetailedFileType detail_ftype
Concrete file type (PNG, BMP, old save, etc).
Definition: saveload.h:361
ResetGRFConfig
void ResetGRFConfig(bool defaults)
Reset the current GRF Config to either blank or newgame settings.
Definition: newgrf_config.cpp:495
BaseMedia< GraphicsSet >::GetUsedSet
static const GraphicsSet * GetUsedSet()
Return the used set.
Definition: base_media_func.h:357
WC_STATUS_BAR
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition: window_type.h:57
RoadStop
A Stop for a Road Vehicle.
Definition: roadstop_base.h:22
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
StateGameLoop
void StateGameLoop()
State controlling game loop.
Definition: openttd.cpp:1358
NetworkStartUp
void NetworkStartUp()
This tries to launch the network for a given OS.
Definition: network.cpp:1257
HasModalProgress
static bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition: progress.h:17
InitializeSpriteSorter
void InitializeSpriteSorter()
Choose the "best" sprite sorter and set _vp_sprite_sorter.
Definition: viewport.cpp:3466
viewport_sprite_sorter.h
Driver::DT_MUSIC
@ DT_MUSIC
A music driver, needs to be before sound to properly shut down extmidi forked music players.
Definition: driver.h:42
console_func.h
AfterNewGRFScan::dedicated_host
std::string dedicated_host
Hostname for the dedicated server.
Definition: openttd.cpp:413
_network_available
bool _network_available
is network mode available?
Definition: network.cpp:60
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:113
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:1263
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:470
MemCmpT
static int MemCmpT(const T *ptr1, const T *ptr2, size_t num=1)
Type-safe version of memcmp().
Definition: mem_func.hpp:63
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:3387
NetworkSettings::reload_cfg
bool reload_cfg
reload the config file before restarting
Definition: settings_type.h:304
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition: direction_type.h:79
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
GETOPT_SHORT_VALUE
#define GETOPT_SHORT_VALUE(shortname)
Short option with value.
Definition: getoptdata.h:97
Company
Definition: company_base.h:117
game_config.hpp
SM_JOIN_GAME
@ SM_JOIN_GAME
Join a network game.
Definition: openttd.h:40
Driver::Stop
virtual void Stop()=0
Stop this driver.
ScriptConfig::SSS_FORCE_GAME
@ SSS_FORCE_GAME
Get the Script config from the current game.
Definition: script_config.hpp:110
CursorVars::in_window
bool in_window
mouse inside this window, determines drawing logic
Definition: gfx_type.h:141
ClientSettings::music
MusicSettings music
settings related to music/sound
Definition: settings_type.h:608
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
SL_OK
@ SL_OK
completed successfully
Definition: saveload.h:353
NetworkServerUpdateGameInfo
void NetworkServerUpdateGameInfo()
Update the server's NetworkServerGameInfo due to changes in settings.
Definition: network_server.cpp:1885
LoadFromConfig
void LoadFromConfig(bool startup)
Load the values from the configuration files.
Definition: settings.cpp:1208
MusicSettings::music_vol
byte music_vol
The requested music volume.
Definition: settings_type.h:226
_sl_version
SaveLoadVersion _sl_version
the major savegame version identifier
Definition: saveload.cpp:66
UpdateLandscapingLimits
void UpdateLandscapingLimits()
Update the landscaping limits per company.
Definition: company_cmd.cpp:271
_cur_resolution
Dimension _cur_resolution
The current resolution.
Definition: driver.cpp:32
network_func.h
_is_network_server
bool _is_network_server
Does this client wants to be a network-server?
Definition: network.cpp:62
GetOptData::numleft
int numleft
Number of arguments left in argv.
Definition: getoptdata.h:32
GamelogInfo
void GamelogInfo(LoggedAction *gamelog_action, uint gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs)
Get some basic information from the given gamelog.
Definition: gamelog.cpp:806
_ini_videodriver
std::string _ini_videodriver
The video driver a stored in the configuration file.
Definition: driver.cpp:30
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:297
BlitterFactory::GetBlittersInfo
static char * GetBlittersInfo(char *p, const char *last)
Fill a buffer with information about the blitters.
Definition: factory.hpp:152
_settings_newgame
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition: settings.cpp:55
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
ResetCompanyLivery
void ResetCompanyLivery(Company *c)
Reset the livery schemes to the company's primary colour.
Definition: company_cmd.cpp:519
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:604
WL_CRITICAL
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition: error.h:25
InitializeLanguagePacks
void InitializeLanguagePacks()
Make a list of the available language packs.
Definition: strings.cpp:2002
NewGRFCache
Cached often queried (NewGRF) values.
Definition: vehicle_base.h:69
SetupColoursAndInitialWindow
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows.
Definition: main_gui.cpp:538
mixer.h
SettingsDisableElrail
void SettingsDisableElrail(int32 new_value)
_settings_game.disable_elrail callback
Definition: elrail.cpp:596
FileToSaveLoad::file_op
SaveLoadOperation file_op
File operation to perform.
Definition: saveload.h:360
ai_config.hpp
engine_func.h
StateGameLoop_LinkGraphPauseControl
void StateGameLoop_LinkGraphPauseControl()
Pause the game if in 2 _date_fract ticks, we would do a join with the next link graph job,...
Definition: linkgraphschedule.cpp:172
news_func.h
hotkeys.h
roadveh.h
AfterNewGRFScan::OnNewGRFsScanned
virtual void OnNewGRFsScanned()
Called whenever the NewGRF scan completed.
Definition: openttd.cpp:430
RunTileLoop
void RunTileLoop()
Gradually iterate over all tiles on the map, calling their TileLoopProcs once every 256 ticks.
Definition: landscape.cpp:807
SM_RESTARTGAME
@ SM_RESTARTGAME
Restart --> 'Random game' with current settings.
Definition: openttd.h:28
BaseMedia< GraphicsSet >::SetSet
static bool SetSet(const std::string &name)
Set the set to be used.
Definition: base_media_func.h:228
backup_type.hpp
Game::Initialize
static void Initialize()
Initialize the Game system.
Definition: game_core.cpp:57