OpenTTD Source: src/openttd.cpp Source File

OpenTTD Source 1.11.0-RC1

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