OpenTTD

openttd.cpp
Go to the documentation of this file.
1 /* $Id: openttd.cpp 27732 2017-01-14 18:30:26Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #include "stdafx.h"
13
14 #include "blitter/factory.hpp"
15 #include "sound/sound_driver.hpp"
16 #include "music/music_driver.hpp"
17 #include "video/video_driver.hpp"
18
19 #include "fontcache.h"
20 #include "error.h"
21 #include "gui.h"
22
23 #include "base_media_base.h"
24 #include "saveload/saveload.h"
25 #include "company_func.h"
26 #include "command_func.h"
27 #include "news_func.h"
28 #include "fios.h"
29 #include "aircraft.h"
30 #include "roadveh.h"
31 #include "train.h"
32 #include "ship.h"
33 #include "console_func.h"
34 #include "screenshot.h"
35 #include "network/network.h"
36 #include "network/network_func.h"
37 #include "ai/ai.hpp"
38 #include "ai/ai_config.hpp"
39 #include "settings_func.h"
40 #include "genworld.h"
41 #include "progress.h"
42 #include "strings_func.h"
43 #include "date_func.h"
44 #include "vehicle_func.h"
45 #include "gamelog.h"
46 #include "animated_tile_func.h"
47 #include "roadstop_base.h"
48 #include "elrail_func.h"
49 #include "rev.h"
50 #include "highscore.h"
51 #include "station_base.h"
52 #include "crashlog.h"
53 #include "engine_func.h"
54 #include "core/random_func.hpp"
55 #include "rail_gui.h"
56 #include "core/backup_type.hpp"
57 #include "hotkeys.h"
58 #include "newgrf.h"
59 #include "misc/getoptdata.h"
60 #include "game/game.hpp"
61 #include "game/game_config.hpp"
62 #include "town.h"
63 #include "subsidy_func.h"
64 #include "gfx_layout.h"
65 #include "viewport_sprite_sorter.h"
66
67 #include "linkgraph/linkgraphschedule.h"
68
69 #include <stdarg.h>
70
71 #include "safeguards.h"
72
73 void CallLandscapeTick();
74 void IncreaseDate();
75 void DoPaletteAnimations();
76 void MusicLoop();
77 void ResetMusic();
78 void CallWindowTickEvent();
79 bool HandleBootstrap();
80
81 extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY);
82 extern void ShowOSErrorBox(const char *buf, bool system);
83 extern char *_config_file;
84
90 void CDECL usererror(const char *s, ...)
91 {
92 va_list va;
93 char buf[512];
94
95 va_start(va, s);
96 vseprintf(buf, lastof(buf), s, va);
97 va_end(va);
98
99 ShowOSErrorBox(buf, false);
100 if (VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop();
101
102 exit(1);
103 }
104
110 void CDECL error(const char *s, ...)
111 {
112 va_list va;
113 char buf[512];
114
115 va_start(va, s);
116 vseprintf(buf, lastof(buf), s, va);
117 va_end(va);
118
119 ShowOSErrorBox(buf, true);
120
121 /* Set the error message for the crash log and then invoke it. */
122 CrashLog::SetErrorMessage(buf);
123 abort();
124 }
125
130 void CDECL ShowInfoF(const char *str, ...)
131 {
132 va_list va;
133 char buf[1024];
134 va_start(va, str);
135 vseprintf(buf, lastof(buf), str, va);
136 va_end(va);
137 ShowInfo(buf);
138 }
139
143 static void ShowHelp()
144 {
145 char buf[8192];
146 char *p = buf;
147
148 p += seprintf(p, lastof(buf), "OpenTTD %s\n", _openttd_revision);
149 p = strecpy(p,
150 "\n"
151 "\n"
152 "Command line options:\n"
153 " -v drv = Set video driver (see below)\n"
154 " -s drv = Set sound driver (see below) (param bufsize,hz)\n"
155 " -m drv = Set music driver (see below)\n"
156 " -b drv = Set the blitter to use (see below)\n"
157 " -r res = Set resolution (for instance 800x600)\n"
158 " -h = Display this help text\n"
159 " -t year = Set starting year\n"
160 " -d [[fac=]lvl[,...]]= Debug mode\n"
161 " -e = Start Editor\n"
162 " -g [savegame] = Start new/save game immediately\n"
163 " -G seed = Set random seed\n"
164 #if defined(ENABLE_NETWORK)
165 " -n [ip:port#company]= Join network game\n"
166 " -p password = Password to join server\n"
167 " -P password = Password to join company\n"
168 " -D [ip][:port] = Start dedicated server\n"
169 " -l ip[:port] = Redirect DEBUG()\n"
170 #if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
171 " -f = Fork into the background (dedicated only)\n"
172 #endif
173 #endif /* ENABLE_NETWORK */
174 " -I graphics_set = Force the graphics set (see below)\n"
175 " -S sounds_set = Force the sounds set (see below)\n"
176 " -M music_set = Force the music set (see below)\n"
177 " -c config_file = Use 'config_file' instead of 'openttd.cfg'\n"
178 " -x = Do not automatically save to config file on exit\n"
179 " -q savegame = Write some information about the savegame and exit\n"
180 "\n",
181 lastof(buf)
182 );
183
184 /* List the graphics packs */
185 p = BaseGraphics::GetSetsList(p, lastof(buf));
186
187 /* List the sounds packs */
188 p = BaseSounds::GetSetsList(p, lastof(buf));
189
190 /* List the music packs */
191 p = BaseMusic::GetSetsList(p, lastof(buf));
192
193 /* List the drivers */
194 p = DriverFactoryBase::GetDriversInfo(p, lastof(buf));
195
196 /* List the blitters */
197 p = BlitterFactory::GetBlittersInfo(p, lastof(buf));
198
199 /* List the debug facilities. */
200 p = DumpDebugFacilityNames(p, lastof(buf));
201
202 /* We need to initialize the AI, so it finds the AIs */
203 AI::Initialize();
204 p = AI::GetConsoleList(p, lastof(buf), true);
205 AI::Uninitialize(true);
206
207 /* We need to initialize the GameScript, so it finds the GSs */
208 Game::Initialize();
209 p = Game::GetConsoleList(p, lastof(buf), true);
210 Game::Uninitialize(true);
211
212 /* ShowInfo put output to stderr, but version information should go
213 * to stdout; this is the only exception */
214 #if !defined(WIN32) && !defined(WIN64)
215 printf("%s\n", buf);
216 #else
217 ShowInfo(buf);
218 #endif
219 }
220
221 static void WriteSavegameInfo(const char *name)
222 {
223 extern uint16 _sl_version;
224 uint32 last_ottd_rev = 0;
225 byte ever_modified = 0;
226 bool removed_newgrfs = false;
227
228 GamelogInfo(_load_check_data.gamelog_action, _load_check_data.gamelog_actions, &last_ottd_rev, &ever_modified, &removed_newgrfs);
229
230 char buf[8192];
231 char *p = buf;
232 p += seprintf(p, lastof(buf), "Name: %s\n", name);
233 p += seprintf(p, lastof(buf), "Savegame ver: %d\n", _sl_version);
234 p += seprintf(p, lastof(buf), "NewGRF ver: 0x%08X\n", last_ottd_rev);
235 p += seprintf(p, lastof(buf), "Modified: %d\n", ever_modified);
236
237 if (removed_newgrfs) {
238 p += seprintf(p, lastof(buf), "NewGRFs have been removed\n");
239 }
240
241 p = strecpy(p, "NewGRFs:\n", lastof(buf));
242 if (_load_check_data.HasNewGrfs()) {
243 for (GRFConfig *c = _load_check_data.grfconfig; c != NULL; c = c->next) {
244 char md5sum[33];
245 md5sumToString(md5sum, lastof(md5sum), HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum);
246 p += seprintf(p, lastof(buf), "%08X %s %s\n", c->ident.grfid, md5sum, c->filename);
247 }
248 }
249
250 /* ShowInfo put output to stderr, but version information should go
251 * to stdout; this is the only exception */
252 #if !defined(WIN32) && !defined(WIN64)
253 printf("%s\n", buf);
254 #else
255 ShowInfo(buf);
256 #endif
257 }
258
259
266 static void ParseResolution(Dimension *res, const char *s)
267 {
268 const char *t = strchr(s, 'x');
269 if (t == NULL) {
270 ShowInfoF("Invalid resolution '%s'", s);
271 return;
272 }
273
274 res->width = max(strtoul(s, NULL, 0), 64UL);
275 res->height = max(strtoul(t + 1, NULL, 0), 64UL);
276 }
277
278
283 static void ShutdownGame()
284 {
285 IConsoleFree();
286
287 if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
288
289 DriverFactoryBase::ShutdownDrivers();
290
291 UnInitWindowSystem();
292
293 /* stop the scripts */
294 AI::Uninitialize(false);
295 Game::Uninitialize(false);
296
297 /* Uninitialize variables that are allocated dynamically */
298 GamelogReset();
299
300 #ifdef ENABLE_NETWORK
301 free(_config_file);
302 #endif
303
304 LinkGraphSchedule::Clear();
305 PoolBase::Clean(PT_ALL);
306
307 /* No NewGRFs were loaded when it was still bootstrapping. */
308 if (_game_mode != GM_BOOTSTRAP) ResetNewGRFData();
309
310 /* Close all and any open filehandles */
311 FioCloseAll();
312
313 UninitFreeType();
314 }
315
320 static void LoadIntroGame(bool load_newgrfs = true)
321 {
322 _game_mode = GM_MENU;
323
324 if (load_newgrfs) ResetGRFConfig(false);
325
326 /* Setup main window */
327 ResetWindowSystem();
328 SetupColoursAndInitialWindow();
329
330 /* Load the default opening screen savegame */
331 if (SaveOrLoad("opntitle.dat", SLO_LOAD, DFT_GAME_FILE, BASESET_DIR) != SL_OK) {
332 GenerateWorld(GWM_EMPTY, 64, 64); // if failed loading, make empty world.
333 WaitTillGeneratedWorld();
334 SetLocalCompany(COMPANY_SPECTATOR);
335 } else {
336 SetLocalCompany(COMPANY_FIRST);
337 }
338
339 _pause_mode = PM_UNPAUSED;
340 _cursor.fix_at = false;
341
342 CheckForMissingGlyphs();
343
344 /* Play main theme */
345 if (MusicDriver::GetInstance()->IsSongPlaying()) ResetMusic();
346 }
347
348 void MakeNewgameSettingsLive()
349 {
350 for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
351 if (_settings_game.ai_config[c] != NULL) {
352 delete _settings_game.ai_config[c];
353 }
354 }
355 if (_settings_game.game_config != NULL) {
356 delete _settings_game.game_config;
357 }
358
359 /* Copy newgame settings to active settings.
360 * Also initialise old settings needed for savegame conversion. */
361 _settings_game = _settings_newgame;
362 _old_vds = _settings_client.company.vehicle;
363
364 for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
365 _settings_game.ai_config[c] = NULL;
366 if (_settings_newgame.ai_config[c] != NULL) {
367 _settings_game.ai_config[c] = new AIConfig(_settings_newgame.ai_config[c]);
368 }
369 }
370 _settings_game.game_config = NULL;
371 if (_settings_newgame.game_config != NULL) {
372 _settings_game.game_config = new GameConfig(_settings_newgame.game_config);
373 }
374 }
375
376 void OpenBrowser(const char *url)
377 {
378 /* Make sure we only accept urls that are sure to open a browser. */
379 if (strstr(url, "http://") != url && strstr(url, "https://") != url) return;
380
381 extern void OSOpenBrowser(const char *url);
382 OSOpenBrowser(url);
383 }
384
386 struct AfterNewGRFScan : NewGRFScanCallback {
387 Year startyear;
388 uint generation_seed;
389 char *dedicated_host;
390 uint16 dedicated_port;
391 char *network_conn;
392 const char *join_server_password;
393 const char *join_company_password;
394 bool *save_config_ptr;
395 bool save_config;
396
402 AfterNewGRFScan(bool *save_config_ptr) :
403 startyear(INVALID_YEAR), generation_seed(GENERATE_NEW_SEED),
404 dedicated_host(NULL), dedicated_port(0), network_conn(NULL),
405 join_server_password(NULL), join_company_password(NULL),
406 save_config_ptr(save_config_ptr), save_config(true)
407 {
408 }
409
410 virtual void OnNewGRFsScanned()
411 {
412 ResetGRFConfig(false);
413
414 TarScanner::DoScan(TarScanner::SCENARIO);
415
416 AI::Initialize();
417 Game::Initialize();
418
419 /* We want the new (correct) NewGRF count to survive the loading. */
420 uint last_newgrf_count = _settings_client.gui.last_newgrf_count;
421 LoadFromConfig();
422 _settings_client.gui.last_newgrf_count = last_newgrf_count;
423 /* Since the default for the palette might have changed due to
424 * reading the configuration file, recalculate that now. */
425 UpdateNewGRFConfigPalette();
426
427 Game::Uninitialize(true);
428 AI::Uninitialize(true);
429 CheckConfig();
430 LoadFromHighScore();
431 LoadHotkeysFromConfig();
432 WindowDesc::LoadFromConfig();
433
434 /* We have loaded the config, so we may possibly save it. */
435 *save_config_ptr = save_config;
436
437 /* restore saved music volume */
438 MusicDriver::GetInstance()->SetVolume(_settings_client.music.music_vol);
439
440 if (startyear != INVALID_YEAR) _settings_newgame.game_creation.starting_year = startyear;
441 if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed;
442
443 #if defined(ENABLE_NETWORK)
444 if (dedicated_host != NULL) {
445 _network_bind_list.Clear();
446 *_network_bind_list.Append() = stredup(dedicated_host);
447 }
448 if (dedicated_port != 0) _settings_client.network.server_port = dedicated_port;
449 #endif /* ENABLE_NETWORK */
450
451 /* initialize the ingame console */
452 IConsoleInit();
453 InitializeGUI();
454 IConsoleCmdExec("exec scripts/autoexec.scr 0");
455
456 /* Make sure _settings is filled with _settings_newgame if we switch to a game directly */
457 if (_switch_mode != SM_NONE) MakeNewgameSettingsLive();
458
459 #ifdef ENABLE_NETWORK
460 if (_network_available && network_conn != NULL) {
461 const char *port = NULL;
462 const char *company = NULL;
463 uint16 rport = NETWORK_DEFAULT_PORT;
464 CompanyID join_as = COMPANY_NEW_COMPANY;
465
466 ParseConnectionString(&company, &port, network_conn);
467
468 if (company != NULL) {
469 join_as = (CompanyID)atoi(company);
470
471 if (join_as != COMPANY_SPECTATOR) {
472 join_as--;
473 if (join_as >= MAX_COMPANIES) {
474 delete this;
475 return;
476 }
477 }
478 }
479 if (port != NULL) rport = atoi(port);
480
481 LoadIntroGame();
482 _switch_mode = SM_NONE;
483 NetworkClientConnectGame(NetworkAddress(network_conn, rport), join_as, join_server_password, join_company_password);
484 }
485 #endif /* ENABLE_NETWORK */
486
487 /* After the scan we're not used anymore. */
488 delete this;
489 }
490 };
491
492 #if defined(UNIX) && !defined(__MORPHOS__)
493 extern void DedicatedFork();
494 #endif
495
497 static const OptionData _options[] = {
498 GETOPT_SHORT_VALUE('I'),
499 GETOPT_SHORT_VALUE('S'),
500 GETOPT_SHORT_VALUE('M'),
501 GETOPT_SHORT_VALUE('m'),
502 GETOPT_SHORT_VALUE('s'),
503 GETOPT_SHORT_VALUE('v'),
504 GETOPT_SHORT_VALUE('b'),
505 #if defined(ENABLE_NETWORK)
506 GETOPT_SHORT_OPTVAL('D'),
507 GETOPT_SHORT_OPTVAL('n'),
508 GETOPT_SHORT_VALUE('l'),
509 GETOPT_SHORT_VALUE('p'),
510 GETOPT_SHORT_VALUE('P'),
511 #if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
512 GETOPT_SHORT_NOVAL('f'),
513 #endif
514 #endif /* ENABLE_NETWORK */
515 GETOPT_SHORT_VALUE('r'),
516 GETOPT_SHORT_VALUE('t'),
517 GETOPT_SHORT_OPTVAL('d'),
518 GETOPT_SHORT_NOVAL('e'),
519 GETOPT_SHORT_OPTVAL('g'),
520 GETOPT_SHORT_VALUE('G'),
521 GETOPT_SHORT_VALUE('c'),
522 GETOPT_SHORT_NOVAL('x'),
523 GETOPT_SHORT_VALUE('q'),
524 GETOPT_SHORT_NOVAL('h'),
525 GETOPT_END()
526 };
527
534 int openttd_main(int argc, char *argv[])
535 {
536 char *musicdriver = NULL;
537 char *sounddriver = NULL;
538 char *videodriver = NULL;
539 char *blitter = NULL;
540 char *graphics_set = NULL;
541 char *sounds_set = NULL;
542 char *music_set = NULL;
543 Dimension resolution = {0, 0};
544 /* AfterNewGRFScan sets save_config to true after scanning completed. */
545 bool save_config = false;
546 AfterNewGRFScan *scanner = new AfterNewGRFScan(&save_config);
547 #if defined(ENABLE_NETWORK)
548 bool dedicated = false;
549 char *debuglog_conn = NULL;
550
551 extern bool _dedicated_forks;
552 _dedicated_forks = false;
553 #endif /* ENABLE_NETWORK */
554
555 _game_mode = GM_MENU;
556 _switch_mode = SM_MENU;
557 _config_file = NULL;
558
559 GetOptData mgo(argc - 1, argv + 1, _options);
560 int ret = 0;
561
562 int i;
563 while ((i = mgo.GetOpt()) != -1) {
564 switch (i) {
565 case 'I': free(graphics_set); graphics_set = stredup(mgo.opt); break;
566 case 'S': free(sounds_set); sounds_set = stredup(mgo.opt); break;
567 case 'M': free(music_set); music_set = stredup(mgo.opt); break;
568 case 'm': free(musicdriver); musicdriver = stredup(mgo.opt); break;
569 case 's': free(sounddriver); sounddriver = stredup(mgo.opt); break;
570 case 'v': free(videodriver); videodriver = stredup(mgo.opt); break;
571 case 'b': free(blitter); blitter = stredup(mgo.opt); break;
572 #if defined(ENABLE_NETWORK)
573 case 'D':
574 free(musicdriver);
575 free(sounddriver);
576 free(videodriver);
577 free(blitter);
578 musicdriver = stredup("null");
579 sounddriver = stredup("null");
580 videodriver = stredup("dedicated");
581 blitter = stredup("null");
582 dedicated = true;
583 SetDebugString("net=6");
584 if (mgo.opt != NULL) {
585 /* Use the existing method for parsing (openttd -n).
586 * However, we do ignore the #company part. */
587 const char *temp = NULL;
588 const char *port = NULL;
589 ParseConnectionString(&temp, &port, mgo.opt);
590 if (!StrEmpty(mgo.opt)) scanner->dedicated_host = mgo.opt;
591 if (port != NULL) scanner->dedicated_port = atoi(port);
592 }
593 break;
594 case 'f': _dedicated_forks = true; break;
595 case 'n':
596 scanner->network_conn = mgo.opt; // optional IP parameter, NULL if unset
597 break;
598 case 'l':
599 debuglog_conn = mgo.opt;
600 break;
601 case 'p':
602 scanner->join_server_password = mgo.opt;
603 break;
604 case 'P':
605 scanner->join_company_password = mgo.opt;
606 break;
607 #endif /* ENABLE_NETWORK */
608 case 'r': ParseResolution(&resolution, mgo.opt); break;
609 case 't': scanner->startyear = atoi(mgo.opt); break;
610 case 'd': {
611 #if defined(WIN32)
612 CreateConsole();
613 #endif
614 if (mgo.opt != NULL) SetDebugString(mgo.opt);
615 break;
616 }
617 case 'e': _switch_mode = (_switch_mode == SM_LOAD_GAME || _switch_mode == SM_LOAD_SCENARIO ? SM_LOAD_SCENARIO : SM_EDITOR); break;
618 case 'g':
619 if (mgo.opt != NULL) {
620 _file_to_saveload.SetName(mgo.opt);
621 bool is_scenario = _switch_mode == SM_EDITOR || _switch_mode == SM_LOAD_SCENARIO;
622 _switch_mode = is_scenario ? SM_LOAD_SCENARIO : SM_LOAD_GAME;
623 _file_to_saveload.SetMode(SLO_LOAD, is_scenario ? FT_SCENARIO : FT_SAVEGAME, DFT_GAME_FILE);
624
625 /* if the file doesn't exist or it is not a valid savegame, let the saveload code show an error */
626 const char *t = strrchr(_file_to_saveload.name, '.');
627 if (t != NULL) {
628 FiosType ft = FiosGetSavegameListCallback(SLO_LOAD, _file_to_saveload.name, t, NULL, NULL);
629 if (ft != FIOS_TYPE_INVALID) _file_to_saveload.SetMode(ft);
630 }
631
632 break;
633 }
634
635 _switch_mode = SM_NEWGAME;
636 /* Give a random map if no seed has been given */
637 if (scanner->generation_seed == GENERATE_NEW_SEED) {
638 scanner->generation_seed = InteractiveRandom();
639 }
640 break;
641 case 'q': {
642 DeterminePaths(argv[0]);
643 if (StrEmpty(mgo.opt)) {
644 ret = 1;
645 goto exit_noshutdown;
646 }
647
648 char title[80];
649 title[0] = '\0';
650 FiosGetSavegameListCallback(SLO_LOAD, mgo.opt, strrchr(mgo.opt, '.'), title, lastof(title));
651
652 _load_check_data.Clear();
653 SaveOrLoadResult res = SaveOrLoad(mgo.opt, SLO_CHECK, DFT_GAME_FILE, SAVE_DIR, false);
654 if (res != SL_OK || _load_check_data.HasErrors()) {
655 fprintf(stderr, "Failed to open savegame\n");
656 if (_load_check_data.HasErrors()) {
657 char buf[256];
658 SetDParamStr(0, _load_check_data.error_data);
659 GetString(buf, _load_check_data.error, lastof(buf));
660 fprintf(stderr, "%s\n", buf);
661 }
662 goto exit_noshutdown;
663 }
664
665 WriteSavegameInfo(title);
666
667 goto exit_noshutdown;
668 }
669 case 'G': scanner->generation_seed = atoi(mgo.opt); break;
670 case 'c': free(_config_file); _config_file = stredup(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
692 goto exit_noshutdown;
693 }
694
695 #if defined(WINCE) && defined(_DEBUG)
696 /* Switch on debug lvl 4 for WinCE if Debug release, as you can't give params, and you most likely do want this information */
697 SetDebugString("4");
698 #endif
699
700 DeterminePaths(argv[0]);
701 TarScanner::DoScan(TarScanner::BASESET);
702
703 #if defined(ENABLE_NETWORK)
704 if (dedicated) DEBUG(net, 0, "Starting dedicated version %s", _openttd_revision);
705 if (_dedicated_forks && !dedicated) _dedicated_forks = false;
706
707 #if defined(UNIX) && !defined(__MORPHOS__)
708 /* We must fork here, or we'll end up without some resources we need (like sockets) */
709 if (_dedicated_forks) DedicatedFork();
710 #endif
711 #endif
712
713 LoadFromConfig(true);
714
715 if (resolution.width != 0) _cur_resolution = resolution;
716
717 /*
718 * The width and height must be at least 1 pixel and width times
719 * height times bytes per pixel must still fit within a 32 bits
720 * integer, even for 32 bpp video modes. This way all internal
721 * drawing routines work correctly.
722 */
723 _cur_resolution.width = ClampU(_cur_resolution.width, 1, UINT16_MAX / 2);
724 _cur_resolution.height = ClampU(_cur_resolution.height, 1, UINT16_MAX / 2);
725
726 /* Assume the cursor starts within the game as not all video drivers
727 * get an event that the cursor is within the window when it is opened.
728 * Saying the cursor is there makes no visible difference as it would
729 * just be out of the bounds of the window. */
730 _cursor.in_window = true;
731
732 /* enumerate language files */
733 InitializeLanguagePacks();
734
735 /* Initialize the regular font for FreeType */
736 InitFreeType(false);
737
738 /* This must be done early, since functions use the SetWindowDirty* calls */
739 InitWindowSystem();
740
741 BaseGraphics::FindSets();
742 if (graphics_set == NULL && BaseGraphics::ini_set != NULL) graphics_set = stredup(BaseGraphics::ini_set);
743 if (!BaseGraphics::SetSet(graphics_set)) {
744 if (!StrEmpty(graphics_set)) {
745 BaseGraphics::SetSet(NULL);
746
747 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_GRAPHICS_NOT_FOUND);
748 msg.SetDParamStr(0, graphics_set);
749 ScheduleErrorMessage(msg);
750 }
751 }
752 free(graphics_set);
753
754 /* Initialize game palette */
755 GfxInitPalettes();
756
757 DEBUG(misc, 1, "Loading blitter...");
758 if (blitter == NULL && _ini_blitter != NULL) blitter = stredup(_ini_blitter);
759 _blitter_autodetected = StrEmpty(blitter);
760 /* Activate the initial blitter.
761 * This is only some initial guess, after NewGRFs have been loaded SwitchNewGRFBlitter may switch to a different one.
762 * - Never guess anything, if the user specified a blitter. (_blitter_autodetected)
763 * - Use 32bpp blitter if baseset or 8bpp-support settings says so.
764 * - Use 8bpp blitter otherwise.
765 */
766 if (!_blitter_autodetected ||
767 (_support8bpp != S8BPP_NONE && (BaseGraphics::GetUsedSet() == NULL || BaseGraphics::GetUsedSet()->blitter == BLT_8BPP)) ||
768 BlitterFactory::SelectBlitter("32bpp-anim") == NULL) {
769 if (BlitterFactory::SelectBlitter(blitter) == NULL) {
770 StrEmpty(blitter) ?
771 usererror("Failed to autoprobe blitter") :
772 usererror("Failed to select requested blitter '%s'; does it exist?", blitter);
773 }
774 }
775 free(blitter);
776
777 if (videodriver == NULL && _ini_videodriver != NULL) videodriver = stredup(_ini_videodriver);
778 DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
779 free(videodriver);
780
781 InitializeSpriteSorter();
782
783 /* Initialize the zoom level of the screen to normal */
784 _screen.zoom = ZOOM_LVL_NORMAL;
785
786 NetworkStartUp(); // initialize network-core
787
788 #if defined(ENABLE_NETWORK)
789 if (debuglog_conn != NULL && _network_available) {
790 const char *not_used = NULL;
791 const char *port = NULL;
792 uint16 rport;
793
794 rport = NETWORK_DEFAULT_DEBUGLOG_PORT;
795
796 ParseConnectionString(&not_used, &port, debuglog_conn);
797 if (port != NULL) rport = atoi(port);
798
799 NetworkStartDebugLog(NetworkAddress(debuglog_conn, rport));
800 }
801 #endif /* ENABLE_NETWORK */
802
803 if (!HandleBootstrap()) {
804 ShutdownGame();
805
806 goto exit_bootstrap;
807 }
808
809 VideoDriver::GetInstance()->ClaimMousePointer();
810
811 /* initialize screenshot formats */
812 InitializeScreenshotFormats();
813
814 BaseSounds::FindSets();
815 if (sounds_set == NULL && BaseSounds::ini_set != NULL) sounds_set = stredup(BaseSounds::ini_set);
816 if (!BaseSounds::SetSet(sounds_set)) {
817 if (StrEmpty(sounds_set) || !BaseSounds::SetSet(NULL)) {
818 usererror("Failed to find a sounds set. Please acquire a sounds set for OpenTTD. See section 4.1 of readme.txt.");
819 } else {
820 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_SOUNDS_NOT_FOUND);
821 msg.SetDParamStr(0, sounds_set);
822 ScheduleErrorMessage(msg);
823 }
824 }
825 free(sounds_set);
826
827 BaseMusic::FindSets();
828 if (music_set == NULL && BaseMusic::ini_set != NULL) music_set = stredup(BaseMusic::ini_set);
829 if (!BaseMusic::SetSet(music_set)) {
830 if (StrEmpty(music_set) || !BaseMusic::SetSet(NULL)) {
831 usererror("Failed to find a music set. Please acquire a music set for OpenTTD. See section 4.1 of readme.txt.");
832 } else {
833 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_MUSIC_NOT_FOUND);
834 msg.SetDParamStr(0, music_set);
835 ScheduleErrorMessage(msg);
836 }
837 }
838 free(music_set);
839
840 if (sounddriver == NULL && _ini_sounddriver != NULL) sounddriver = stredup(_ini_sounddriver);
841 DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
842 free(sounddriver);
843
844 if (musicdriver == NULL && _ini_musicdriver != NULL) musicdriver = stredup(_ini_musicdriver);
845 DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
846 free(musicdriver);
847
848 /* Take our initial lock on whatever we might want to do! */
849 _modal_progress_paint_mutex->BeginCritical();
850 _modal_progress_work_mutex->BeginCritical();
851
852 GenerateWorld(GWM_EMPTY, 64, 64); // Make the viewport initialization happy
853 WaitTillGeneratedWorld();
854
855 LoadIntroGame(false);
856
857 CheckForMissingGlyphs();
858
859 /* ScanNewGRFFiles now has control over the scanner. */
860 ScanNewGRFFiles(scanner);
861 scanner = NULL;
862
863 VideoDriver::GetInstance()->MainLoop();
864
865 WaitTillSaved();
866
867 /* only save config if we have to */
868 if (save_config) {
869 SaveToConfig();
870 SaveHotkeysToConfig();
871 WindowDesc::SaveToConfig();
872 SaveToHighScore();
873 }
874
875 /* Reset windowing system, stop drivers, free used memory, ... */
876 ShutdownGame();
877 goto exit_normal;
878
879 exit_noshutdown:
880 /* These three are normally freed before bootstrap. */
881 free(graphics_set);
882 free(videodriver);
883 free(blitter);
884
885 exit_bootstrap:
886 /* These are normally freed before exit, but after bootstrap. */
887 free(sounds_set);
888 free(music_set);
889 free(musicdriver);
890 free(sounddriver);
891
892 exit_normal:
893 free(BaseGraphics::ini_set);
894 free(BaseSounds::ini_set);
895 free(BaseMusic::ini_set);
896
897 free(_ini_musicdriver);
898 free(_ini_sounddriver);
899 free(_ini_videodriver);
900 free(_ini_blitter);
901
902 delete scanner;
903
904 #ifdef ENABLE_NETWORK
905 extern FILE *_log_fd;
906 if (_log_fd != NULL) {
907 fclose(_log_fd);
908 }
909 #endif /* ENABLE_NETWORK */
910
911 return ret;
912 }
913
914 void HandleExitGameRequest()
915 {
916 if (_game_mode == GM_MENU || _game_mode == GM_BOOTSTRAP) { // do not ask to quit on the main screen
917 _exit_game = true;
918 } else if (_settings_client.gui.autosave_on_exit) {
919 DoExitSave();
920 _exit_game = true;
921 } else {
922 AskExitGame();
923 }
924 }
925
926 static void MakeNewGameDone()
927 {
928 SettingsDisableElrail(_settings_game.vehicle.disable_elrails);
929
930 /* In a dedicated server, the server does not play */
931 if (!VideoDriver::GetInstance()->HasGUI()) {
932 SetLocalCompany(COMPANY_SPECTATOR);
933 if (_settings_client.gui.pause_on_newgame) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
934 IConsoleCmdExec("exec scripts/game_start.scr 0");
935 return;
936 }
937
938 /* Create a single company */
939 DoStartupNewCompany(false);
940
941 Company *c = Company::Get(COMPANY_FIRST);
942 c->settings = _settings_client.company;
943
944 IConsoleCmdExec("exec scripts/game_start.scr 0");
945
946 SetLocalCompany(COMPANY_FIRST);
947
948 InitializeRailGUI();
949
950 #ifdef ENABLE_NETWORK
951 /* We are the server, we start a new company (not dedicated),
952 * so set the default password *if* needed. */
953 if (_network_server && !StrEmpty(_settings_client.network.default_company_pass)) {
954 NetworkChangeCompanyPassword(_local_company, _settings_client.network.default_company_pass);
955 }
956 #endif /* ENABLE_NETWORK */
957
958 if (_settings_client.gui.pause_on_newgame) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
959
960 CheckEngines();
961 CheckIndustries();
962 MarkWholeScreenDirty();
963 }
964
965 static void MakeNewGame(bool from_heightmap, bool reset_settings)
966 {
967 _game_mode = GM_NORMAL;
968
969 ResetGRFConfig(true);
970
971 GenerateWorldSetCallback(&MakeNewGameDone);
972 GenerateWorld(from_heightmap ? GWM_HEIGHTMAP : GWM_NEWGAME, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y, reset_settings);
973 }
974
975 static void MakeNewEditorWorldDone()
976 {
977 SetLocalCompany(OWNER_NONE);
978 }
979
980 static void MakeNewEditorWorld()
981 {
982 _game_mode = GM_EDITOR;
983
984 ResetGRFConfig(true);
985
986 GenerateWorldSetCallback(&MakeNewEditorWorldDone);
987 GenerateWorld(GWM_EMPTY, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
988 }
989
1000 bool SafeLoad(const char *filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL)
1001 {
1002 assert(fop == SLO_LOAD);
1003 assert(dft == DFT_GAME_FILE || (lf == NULL && dft == DFT_OLD_GAME_FILE));
1004 GameMode ogm = _game_mode;
1005
1006 _game_mode = newgm;
1007
1008 switch (lf == NULL ? SaveOrLoad(filename, fop, dft, subdir) : LoadWithFilter(lf)) {
1009 case SL_OK: return true;
1010
1011 case SL_REINIT:
1012 #ifdef ENABLE_NETWORK
1013 if (_network_dedicated) {
1014 /*
1015 * We need to reinit a network map...
1016 * We can't simply load the intro game here as that game has many
1017 * special cases which make clients desync immediately. So we fall
1018 * back to just generating a new game with the current settings.
1019 */
1020 DEBUG(net, 0, "Loading game failed, so a new (random) game will be started!");
1021 MakeNewGame(false, true);
1022 return false;
1023 }
1024 if (_network_server) {
1025 /* We can't load the intro game as server, so disconnect first. */
1026 NetworkDisconnect();
1027 }
1028 #endif /* ENABLE_NETWORK */
1029
1030 switch (ogm) {
1031 default:
1032 case GM_MENU: LoadIntroGame(); break;
1033 case GM_EDITOR: MakeNewEditorWorld(); break;
1034 }
1035 return false;
1036
1037 default:
1038 _game_mode = ogm;
1039 return false;
1040 }
1041 }
1042
1043 void SwitchToMode(SwitchMode new_mode)
1044 {
1045 #ifdef ENABLE_NETWORK
1046 /* If we are saving something, the network stays in his current state */
1047 if (new_mode != SM_SAVE_GAME) {
1048 /* If the network is active, make it not-active */
1049 if (_networking) {
1050 if (_network_server && (new_mode == SM_LOAD_GAME || new_mode == SM_NEWGAME || new_mode == SM_RESTARTGAME)) {
1051 NetworkReboot();
1052 } else {
1053 NetworkDisconnect();
1054 }
1055 }
1056
1057 /* If we are a server, we restart the server */
1058 if (_is_network_server) {
1059 /* But not if we are going to the menu */
1060 if (new_mode != SM_MENU) {
1061 /* check if we should reload the config */
1062 if (_settings_client.network.reload_cfg) {
1063 LoadFromConfig();
1064 MakeNewgameSettingsLive();
1065 ResetGRFConfig(false);
1066 }
1067 NetworkServerStart();
1068 } else {
1069 /* This client no longer wants to be a network-server */
1070 _is_network_server = false;
1071 }
1072 }
1073 }
1074 #endif /* ENABLE_NETWORK */
1075 /* Make sure all AI controllers are gone at quitting game */
1076 if (new_mode != SM_SAVE_GAME) AI::KillAll();
1077
1078 switch (new_mode) {
1079 case SM_EDITOR: // Switch to scenario editor
1080 MakeNewEditorWorld();
1081 break;
1082
1083 case SM_RESTARTGAME: // Restart --> 'Random game' with current settings
1084 case SM_NEWGAME: // New Game --> 'Random game'
1085 #ifdef ENABLE_NETWORK
1086 if (_network_server) {
1087 seprintf(_network_game_info.map_name, lastof(_network_game_info.map_name), "Random Map");
1088 }
1089 #endif /* ENABLE_NETWORK */
1090 MakeNewGame(false, new_mode == SM_NEWGAME);
1091 break;
1092
1093 case SM_LOAD_GAME: { // Load game, Play Scenario
1094 ResetGRFConfig(true);
1095 ResetWindowSystem();
1096
1097 if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_NORMAL, NO_DIRECTORY)) {
1098 SetDParamStr(0, GetSaveLoadErrorString());
1099 ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
1100 } else {
1101 if (_file_to_saveload.abstract_ftype == FT_SCENARIO) {
1102 /* Reset engine pool to simplify changing engine NewGRFs in scenario editor. */
1103 EngineOverrideManager::ResetToCurrentNewGRFConfig();
1104 }
1105 /* Update the local company for a loaded game. It is either always
1106 * company #1 (eg 0) or in the case of a dedicated server a spectator */
1107 SetLocalCompany(_network_dedicated ? COMPANY_SPECTATOR : COMPANY_FIRST);
1108 /* Execute the game-start script */
1109 IConsoleCmdExec("exec scripts/game_start.scr 0");
1110 /* Decrease pause counter (was increased from opening load dialog) */
1111 DoCommandP(0, PM_PAUSED_SAVELOAD, 0, CMD_PAUSE);
1112 #ifdef ENABLE_NETWORK
1113 if (_network_server) {
1114 seprintf(_network_game_info.map_name, lastof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title);
1115 }
1116 #endif /* ENABLE_NETWORK */
1117 }
1118 break;
1119 }
1120
1121 case SM_START_HEIGHTMAP: // Load a heightmap and start a new game from it
1122 #ifdef ENABLE_NETWORK
1123 if (_network_server) {
1124 seprintf(_network_game_info.map_name, lastof(_network_game_info.map_name), "%s (Heightmap)", _file_to_saveload.title);
1125 }
1126 #endif /* ENABLE_NETWORK */
1127 MakeNewGame(true, true);
1128 break;
1129
1130 case SM_LOAD_HEIGHTMAP: // Load heightmap from scenario editor
1131 SetLocalCompany(OWNER_NONE);
1132
1133 GenerateWorld(GWM_HEIGHTMAP, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
1134 MarkWholeScreenDirty();
1135 break;
1136
1137 case SM_LOAD_SCENARIO: { // Load scenario from scenario editor
1138 if (SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_EDITOR, NO_DIRECTORY)) {
1139 SetLocalCompany(OWNER_NONE);
1140 _settings_newgame.game_creation.starting_year = _cur_year;
1141 /* Cancel the saveload pausing */
1142 DoCommandP(0, PM_PAUSED_SAVELOAD, 0, CMD_PAUSE);
1143 } else {
1144 SetDParamStr(0, GetSaveLoadErrorString());
1145 ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
1146 }
1147 break;
1148 }
1149
1150 case SM_MENU: // Switch to game intro menu
1151 LoadIntroGame();
1152 if (BaseSounds::ini_set == NULL && BaseSounds::GetUsedSet()->fallback) {
1153 ShowErrorMessage(STR_WARNING_FALLBACK_SOUNDSET, INVALID_STRING_ID, WL_CRITICAL);
1154 BaseSounds::ini_set = stredup(BaseSounds::GetUsedSet()->name);
1155 }
1156 break;
1157
1158 case SM_SAVE_GAME: // Save game.
1159 /* Make network saved games on pause compatible to singleplayer */
1160 if (SaveOrLoad(_file_to_saveload.name, SLO_SAVE, DFT_GAME_FILE, NO_DIRECTORY) != SL_OK) {
1161 SetDParamStr(0, GetSaveLoadErrorString());
1162 ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
1163 } else {
1164 DeleteWindowById(WC_SAVELOAD, 0);
1165 }
1166 break;
1167
1168 case SM_SAVE_HEIGHTMAP: // Save heightmap.
1169 MakeHeightmapScreenshot(_file_to_saveload.name);
1170 DeleteWindowById(WC_SAVELOAD, 0);
1171 break;
1172
1173 case SM_GENRANDLAND: // Generate random land within scenario editor
1174 SetLocalCompany(OWNER_NONE);
1175 GenerateWorld(GWM_RANDOM, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
1176 /* XXX: set date */
1177 MarkWholeScreenDirty();
1178 break;
1179
1180 default: NOT_REACHED();
1181 }
1182 }
1183
1184
1191 static void CheckCaches()
1192 {
1193 /* Return here so it is easy to add checks that are run
1194 * always to aid testing of caches. */
1195 if (_debug_desync_level <= 1) return;
1196
1197 /* Check the town caches. */
1198 SmallVector<TownCache, 4> old_town_caches;
1199 Town *t;
1200 FOR_ALL_TOWNS(t) {
1201 MemCpyT(old_town_caches.Append(), &t->cache);
1202 }
1203
1204 extern void RebuildTownCaches();
1205 RebuildTownCaches();
1206 RebuildSubsidisedSourceAndDestinationCache();
1207
1208 uint i = 0;
1209 FOR_ALL_TOWNS(t) {
1210 if (MemCmpT(old_town_caches.Get(i), &t->cache) != 0) {
1211 DEBUG(desync, 2, "town cache mismatch: town %i", (int)t->index);
1212 }
1213 i++;
1214 }
1215
1216 /* Check company infrastructure cache. */
1217 SmallVector<CompanyInfrastructure, 4> old_infrastructure;
1218 Company *c;
1219 FOR_ALL_COMPANIES(c) MemCpyT(old_infrastructure.Append(), &c->infrastructure);
1220
1221 extern void AfterLoadCompanyStats();
1222 AfterLoadCompanyStats();
1223
1224 i = 0;
1225 FOR_ALL_COMPANIES(c) {
1226 if (MemCmpT(old_infrastructure.Get(i), &c->infrastructure) != 0) {
1227 DEBUG(desync, 2, "infrastructure cache mismatch: company %i", (int)c->index);
1228 }
1229 i++;
1230 }
1231
1232 /* Strict checking of the road stop cache entries */
1233 const RoadStop *rs;
1234 FOR_ALL_ROADSTOPS(rs) {
1235 if (IsStandardRoadStopTile(rs->xy)) continue;
1236
1237 assert(rs->GetEntry(DIAGDIR_NE) != rs->GetEntry(DIAGDIR_NW));
1238 rs->GetEntry(DIAGDIR_NE)->CheckIntegrity(rs);
1239 rs->GetEntry(DIAGDIR_NW)->CheckIntegrity(rs);
1240 }
1241
1242 Vehicle *v;
1243 FOR_ALL_VEHICLES(v) {
1244 extern void FillNewGRFVehicleCache(const Vehicle *v);
1245 if (v != v->First() || v->vehstatus & VS_CRASHED || !v->IsPrimaryVehicle()) continue;
1246
1247 uint length = 0;
1248 for (const Vehicle *u = v; u != NULL; u = u->Next()) length++;
1249
1250 NewGRFCache *grf_cache = CallocT<NewGRFCache>(length);
1251 VehicleCache *veh_cache = CallocT<VehicleCache>(length);
1252 GroundVehicleCache *gro_cache = CallocT<GroundVehicleCache>(length);
1253 TrainCache *tra_cache = CallocT<TrainCache>(length);
1254
1255 length = 0;
1256 for (const Vehicle *u = v; u != NULL; u = u->Next()) {
1257 FillNewGRFVehicleCache(u);
1258 grf_cache[length] = u->grf_cache;
1259 veh_cache[length] = u->vcache;
1260 switch (u->type) {
1261 case VEH_TRAIN:
1262 gro_cache[length] = Train::From(u)->gcache;
1263 tra_cache[length] = Train::From(u)->tcache;
1264 break;
1265 case VEH_ROAD:
1266 gro_cache[length] = RoadVehicle::From(u)->gcache;
1267 break;
1268 default:
1269 break;
1270 }
1271 length++;
1272 }
1273
1274 switch (v->type) {
1275 case VEH_TRAIN: Train::From(v)->ConsistChanged(CCF_TRACK); break;
1276 case VEH_ROAD: RoadVehUpdateCache(RoadVehicle::From(v)); break;
1277 case VEH_AIRCRAFT: UpdateAircraftCache(Aircraft::From(v)); break;
1278 case VEH_SHIP: Ship::From(v)->UpdateCache(); break;
1279 default: break;
1280 }
1281
1282 length = 0;
1283 for (const Vehicle *u = v; u != NULL; u = u->Next()) {
1284 FillNewGRFVehicleCache(u);
1285 if (memcmp(&grf_cache[length], &u->grf_cache, sizeof(NewGRFCache)) != 0) {
1286 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);
1287 }
1288 if (memcmp(&veh_cache[length], &u->vcache, sizeof(VehicleCache)) != 0) {
1289 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);
1290 }
1291 switch (u->type) {
1292 case VEH_TRAIN:
1293 if (memcmp(&gro_cache[length], &Train::From(u)->gcache, sizeof(GroundVehicleCache)) != 0) {
1294 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);
1295 }
1296 if (memcmp(&tra_cache[length], &Train::From(u)->tcache, sizeof(TrainCache)) != 0) {
1297 DEBUG(desync, 2, "train cache mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length);
1298 }
1299 break;
1300 case VEH_ROAD:
1301 if (memcmp(&gro_cache[length], &RoadVehicle::From(u)->gcache, sizeof(GroundVehicleCache)) != 0) {
1302 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);
1303 }
1304 break;
1305 default:
1306 break;
1307 }
1308 length++;
1309 }
1310
1311 free(grf_cache);
1312 free(veh_cache);
1313 free(gro_cache);
1314 free(tra_cache);
1315 }
1316
1317 /* Check whether the caches are still valid */
1318 FOR_ALL_VEHICLES(v) {
1319 byte buff[sizeof(VehicleCargoList)];
1320 memcpy(buff, &v->cargo, sizeof(VehicleCargoList));
1321 v->cargo.InvalidateCache();
1322 assert(memcmp(&v->cargo, buff, sizeof(VehicleCargoList)) == 0);
1323 }
1324
1325 Station *st;
1326 FOR_ALL_STATIONS(st) {
1327 for (CargoID c = 0; c < NUM_CARGO; c++) {
1328 byte buff[sizeof(StationCargoList)];
1329 memcpy(buff, &st->goods[c].cargo, sizeof(StationCargoList));
1330 st->goods[c].cargo.InvalidateCache();
1331 assert(memcmp(&st->goods[c].cargo, buff, sizeof(StationCargoList)) == 0);
1332 }
1333 }
1334 }
1335
1341 void StateGameLoop()
1342 {
1343 /* don't execute the state loop during pause */
1344 if (_pause_mode != PM_UNPAUSED) {
1345 UpdateLandscapingLimits();
1346 #ifndef DEBUG_DUMP_COMMANDS
1347 Game::GameLoop();
1348 #endif
1349 CallWindowTickEvent();
1350 return;
1351 }
1352 if (HasModalProgress()) return;
1353
1354 Layouter::ReduceLineCache();
1355
1356 if (_game_mode == GM_EDITOR) {
1357 BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
1358 RunTileLoop();
1359 CallVehicleTicks();
1360 CallLandscapeTick();
1361 BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
1362 UpdateLandscapingLimits();
1363
1364 CallWindowTickEvent();
1365 NewsLoop();
1366 } else {
1367 if (_debug_desync_level > 2 && _date_fract == 0 && (_date & 0x1F) == 0) {
1368 /* Save the desync savegame if needed. */
1369 char name[MAX_PATH];
1370 seprintf(name, lastof(name), "dmp_cmds_%08x_%08x.sav", _settings_game.game_creation.generation_seed, _date);
1371 SaveOrLoad(name, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);
1372 }
1373
1374 CheckCaches();
1375
1376 /* All these actions has to be done from OWNER_NONE
1377 * for multiplayer compatibility */
1378 Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE);
1379
1380 BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
1381 AnimateAnimatedTiles();
1382 IncreaseDate();
1383 RunTileLoop();
1384 CallVehicleTicks();
1385 CallLandscapeTick();
1386 BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
1387
1388 #ifndef DEBUG_DUMP_COMMANDS
1389 AI::GameLoop();
1390 Game::GameLoop();
1391 #endif
1392 UpdateLandscapingLimits();
1393
1394 CallWindowTickEvent();
1395 NewsLoop();
1396 cur_company.Restore();
1397 }
1398
1399 assert(IsLocalCompany());
1400 }
1401
1406 static void DoAutosave()
1407 {
1408 char buf[MAX_PATH];
1409
1410 #if defined(PSP)
1411 /* Autosaving in networking is too time expensive for the PSP */
1412 if (_networking) return;
1413 #endif /* PSP */
1414
1415 if (_settings_client.gui.keep_all_autosave) {
1416 GenerateDefaultSaveName(buf, lastof(buf));
1417 strecat(buf, ".sav", lastof(buf));
1418 } else {
1419 static int _autosave_ctr = 0;
1420
1421 /* generate a savegame name and number according to _settings_client.gui.max_num_autosaves */
1422 seprintf(buf, lastof(buf), "autosave%d.sav", _autosave_ctr);
1423
1424 if (++_autosave_ctr >= _settings_client.gui.max_num_autosaves) _autosave_ctr = 0;
1425 }
1426
1427 DEBUG(sl, 2, "Autosaving to '%s'", buf);
1428 if (SaveOrLoad(buf, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR) != SL_OK) {
1429 ShowErrorMessage(STR_ERROR_AUTOSAVE_FAILED, INVALID_STRING_ID, WL_ERROR);
1430 }
1431 }
1432
1433 void GameLoop()
1434 {
1435 if (_game_mode == GM_BOOTSTRAP) {
1436 #ifdef ENABLE_NETWORK
1437 /* Check for UDP stuff */
1438 if (_network_available) NetworkBackgroundLoop();
1439 #endif
1440 InputLoop();
1441 return;
1442 }
1443
1444 ProcessAsyncSaveFinish();
1445
1446 /* autosave game? */
1447 if (_do_autosave) {
1448 DoAutosave();
1449 _do_autosave = false;
1450 SetWindowDirty(WC_STATUS_BAR, 0);
1451 }
1452
1453 /* switch game mode? */
1454 if (_switch_mode != SM_NONE && !HasModalProgress()) {
1455 SwitchToMode(_switch_mode);
1456 _switch_mode = SM_NONE;
1457 }
1458
1459 IncreaseSpriteLRU();
1460 InteractiveRandom();
1461
1462 extern int _caret_timer;
1463 _caret_timer += 3;
1464 CursorTick();
1465
1466 #ifdef ENABLE_NETWORK
1467 /* Check for UDP stuff */
1468 if (_network_available) NetworkBackgroundLoop();
1469
1470 if (_networking && !HasModalProgress()) {
1471 /* Multiplayer */
1472 NetworkGameLoop();
1473 } else {
1474 if (_network_reconnect > 0 && --_network_reconnect == 0) {
1475 /* This means that we want to reconnect to the last host
1476 * We do this here, because it means that the network is really closed */
1477 NetworkClientConnectGame(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port), COMPANY_SPECTATOR);
1478 }
1479 /* Singleplayer */
1480 StateGameLoop();
1481 }
1482
1483 /* Check chat messages roughly once a second. */
1484 static uint check_message = 0;
1485 if (++check_message > 1000 / MILLISECONDS_PER_TICK) {
1486 check_message = 0;
1487 NetworkChatMessageLoop();
1488 }
1489 #else
1490 StateGameLoop();
1491 #endif /* ENABLE_NETWORK */
1492
1493 if (!_pause_mode && HasBit(_display_opt, DO_FULL_ANIMATION)) DoPaletteAnimations();
1494
1495 if (!_pause_mode || _game_mode == GM_EDITOR || _settings_game.construction.command_pause_level > CMDPL_NO_CONSTRUCTION) MoveAllTextEffects();
1496
1497 InputLoop();
1498
1499 SoundDriver::GetInstance()->MainLoop();
1500 MusicLoop();
1501 }
VehicleSettings::disable_elrails
bool disable_elrails
when true, the elrails are disabled
Definition: settings_type.h:454
FiosType
FiosType
Elements of a file system that are recognized.
Definition: fileio_type.h:69
SetupColoursAndInitialWindow
void SetupColoursAndInitialWindow()
Initialise the default colours (remaps and the likes), and load the main windows. ...
Definition: main_gui.cpp:549
strings_func.h
Functions related to OTTD&#39;s strings.
UpdateLandscapingLimits
void UpdateLandscapingLimits()
Update the landscaping limits per company.
Definition: company_cmd.cpp:265
_ini_videodriver
char * _ini_videodriver
The video driver a stored in the configuration file.
Definition: driver.cpp:21
roadveh.h
Road vehicle states.
PT_ALL
All pool types.
Definition: pool_type.hpp:25
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:552
NewGRFCache
Cached often queried (NewGRF) values.
Definition: vehicle_base.h:67
IsLocalCompany
static bool IsLocalCompany()
Is the current company the local company?
Definition: company_func.h:45
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:309
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:77
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:2089
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:474
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:56
video_driver.hpp
Base of all video drivers.
InitializeScreenshotFormats
void InitializeScreenshotFormats()
Initialize screenshot format information on startup, with _screenshot_format_name filled from the loa...
Definition: screenshot.cpp:587
GETOPT_SHORT_OPTVAL
#define GETOPT_SHORT_OPTVAL(shortname)
Short option with optional value.
Definition: getoptdata.h:106
CheckEngines
void CheckEngines()
Check for engines that have an appropriate availability.
Definition: engine.cpp:1126
TarScanner::BASESET
Scan for base sets.
Definition: fileio_func.h:101
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:533
_blitter_autodetected
bool _blitter_autodetected
Was the blitter autodetected or specified by the user?
Definition: driver.cpp:32
FiosGetSavegameListCallback
FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last)
Callback for FiosGetFileList.
Definition: fios.cpp:460
SoundDriver::MainLoop
virtual void MainLoop()
Called once every tick.
Definition: sound_driver.hpp:21
HandleBootstrap
bool HandleBootstrap()
Handle all procedures for bootstrapping OpenTTD without a base graphics set.
Definition: bootstrap_gui.cpp:215
PM_PAUSED_NORMAL
A game normally paused.
Definition: openttd.h:59
_log_fd
FILE * _log_fd
File to reroute output of a forked OpenTTD to.
Definition: dedicated.cpp:17
PM_UNPAUSED
A normal unpaused game.
Definition: openttd.h:58
GETOPT_SHORT_VALUE
#define GETOPT_SHORT_VALUE(shortname)
Short option with value.
Definition: getoptdata.h:99
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3120
MemCmpT
static int MemCmpT(const T *ptr1, const T *ptr2, size_t num=1)
Type-safe version of memcmp().
Definition: mem_func.hpp:65
openttd_main
int openttd_main(int argc, char *argv[])
Main entry point for this lovely game.
Definition: openttd.cpp:534
strecat
static char * strecat(char *dst, const char *src, const char *last)
Appends characters from one string to another.
Definition: depend.cpp:99
ErrorMessageData::SetDParamStr
void SetDParamStr(uint n, const char *str)
Set a rawstring parameter.
Definition: error_gui.cpp:158
roadstop_base.h
Base class for roadstops.
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:110
GUISettings::keep_all_autosave
bool keep_all_autosave
name the autosave in a different way
Definition: settings_type.h:106
NetworkSettings::last_port
uint16 last_port
port of the last joined server
Definition: settings_type.h:268
SM_LOAD_HEIGHTMAP
Load heightmap from scenario editor.
Definition: openttd.h:38
GETOPT_SHORT_NOVAL
#define GETOPT_SHORT_NOVAL(shortname)
Short option without value.
Definition: getoptdata.h:93
GenerateDefaultSaveName
void GenerateDefaultSaveName(char *buf, const char *last)
Fill the buffer with the default name for a savegame or screenshot.
Definition: saveload.cpp:2885
Game::GameLoop
static void GameLoop()
Called every game-tick to let Game do something.
Definition: game_core.cpp:32
WC_SAVELOAD
Saveload window; Window numbers:
Definition: window_type.h:139
game_config.hpp
GameConfig stores the configuration settings of every Game.
_display_opt
byte _display_opt
What do we want to draw/do?
Definition: transparency_gui.cpp:28
AfterLoadCompanyStats
void AfterLoadCompanyStats()
Rebuilding of company statistics after loading a savegame.
Definition: company_sl.cpp:96
StationCargoList
CargoList that is used for stations.
Definition: cargopacket.h:463
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
LoadCheckData::gamelog_action
struct LoggedAction * gamelog_action
Gamelog actions.
Definition: fios.h:41
SM_MENU
Switch to game intro menu.
Definition: openttd.h:32
FileToSaveLoad::SetName
void SetName(const char *name)
Set the name of the file.
Definition: saveload.cpp:2948
BaseMedia< GraphicsSet >::FindSets
static uint FindSets()
Do the scan for files.
Definition: base_media_base.h:196
hotkeys.h
Hotkey related functions.
date_func.h
Functions related to dates.
GWM_NEWGAME
Generate a map for a new game.
Definition: genworld.h:29
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:398
SM_LOAD_GAME
Load game, Play Scenario.
Definition: openttd.h:31
_options
static const OptionData _options[]
Options of OpenTTD.
Definition: openttd.cpp:497
train.h
Base for the train class.
GUISettings::pause_on_newgame
bool pause_on_newgame
whether to start new games paused or not
Definition: settings_type.h:117
_sl_version
uint16 _sl_version
the major savegame version identifier
Definition: saveload.cpp:275
AfterNewGRFScan::save_config_ptr
bool * save_config_ptr
The pointer to the save config setting.
Definition: openttd.cpp:394
AI::GetConsoleList
static char * GetConsoleList(char *p, const char *last, bool newest_only=false)
Wrapper function for AIScanner::GetAIConsoleList.
Definition: ai_core.cpp:317
gamelog.h
Functions to be called to log possibly unsafe game events.
base_media_base.h
Generic functions for replacing base data (graphics, sounds).
_file_to_saveload
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition: saveload.cpp:272
InitWindowSystem
void InitWindowSystem()
(re)initialize the windowing system
Definition: window.cpp:1869
Game::Uninitialize
static void Uninitialize(bool keepConfig)
Uninitialize the Game system.
Definition: game_core.cpp:90
RoadStop::xy
TileIndex xy
Position on the map.
Definition: roadstop_base.h:69
RebuildTownCaches
void RebuildTownCaches()
Rebuild all the cached variables of towns.
Definition: town_sl.cpp:27
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:50
vehicle_func.h
Functions related to vehicles.
md5sumToString
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Definition: string.cpp:416
DriverFactoryBase::ShutdownDrivers
static void ShutdownDrivers()
Shuts down all active drivers.
Definition: driver.h:115
FileToSaveLoad::title
char title[255]
Internal name of the game.
Definition: saveload.h:31
ClientSettings::music
MusicSettings music
settings related to music/sound
Definition: settings_type.h:565
sound_driver.hpp
Base for all sound drivers.
AI::Initialize
static void Initialize()
Initialize the AI system.
Definition: ai_core.cpp:160
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:212
LoadCheckData::grfconfig
GRFConfig * grfconfig
NewGrf configuration from save.
Definition: fios.h:38
FioCloseAll
void FioCloseAll()
Close all slotted open files.
Definition: fileio.cpp:213
INVALID_YEAR
static const Year INVALID_YEAR
Representation of an invalid year.
Definition: date_type.h:109
NetworkAddress
Wrapper for (un)resolved network addresses; there&#39;s no reason to transform a numeric IP to a string a...
Definition: address.h:31
GWM_HEIGHTMAP
Generate a newgame from a heightmap.
Definition: genworld.h:32
GENERATE_NEW_SEED
static const uint GENERATE_NEW_SEED
Create a new random seed.
Definition: genworld.h:25
PoolBase::Clean
static void Clean(PoolType)
Clean all pools of given type.
Definition: pool_func.cpp:32
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
NetworkStartUp
void NetworkStartUp()
This tries to launch the network for a given OS.
Definition: network.cpp:1070
DIAGDIR_NE
Northeast, upper right on your monitor.
Definition: direction_type.h:82
VehicleCache
Cached often queried values common to all vehicles.
Definition: vehicle_base.h:122
_cur_resolution
Dimension _cur_resolution
The current resolution.
Definition: driver.cpp:24
AfterNewGRFScan::dedicated_port
uint16 dedicated_port
Port for the dedicated server.
Definition: openttd.cpp:390
OptionData
Data of an option.
Definition: getoptdata.h:24
DoExitSave
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
Definition: saveload.cpp:2875
aircraft.h
Base for aircraft.
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:50
COMPANY_SPECTATOR
The client is spectating.
Definition: company_type.h:37
COMPANY_NEW_COMPANY
The client wants a new company.
Definition: company_type.h:36
SmallVector
Simple vector template class.
Definition: smallvec_type.hpp:29
genworld.h
Functions related to world/map generation.
DriverFactoryBase::GetDriversInfo
static char * GetDriversInfo(char *p, const char *last)
Build a human readable list of available drivers, grouped by type.
Definition: driver.cpp:191
screenshot.h
Functions to make screenshots.
UpdateNewGRFConfigPalette
bool UpdateNewGRFConfigPalette(int32 p1)
Update the palettes of the graphics from the config file.
Definition: newgrf_config.cpp:330
NetworkSettings::reload_cfg
bool reload_cfg
reload the config file before restarting
Definition: settings_type.h:266
BaseMedia< GraphicsSet >::SetSet
static bool SetSet(const char *name)
Set the set to be used.
Definition: base_media_func.h:234
IsStandardRoadStopTile
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
Definition: station_map.h:224
SaveToConfig
void SaveToConfig()
Save the values to the configuration file.
Definition: settings.cpp:1730
BLT_8BPP
Base set has 8 bpp sprites only.
Definition: base_media_base.h:245
Year
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:20
GameCreationSettings::map_x
uint8 map_x
X size of map.
Definition: settings_type.h:278
GoodsEntry::cargo
StationCargoList cargo
The cargo packets of cargo waiting in this station.
Definition: station_base.h:255
BASESET_DIR
Subdirectory for all base data (base sets, intro game)
Definition: fileio_type.h:118
max
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
GUISettings::last_newgrf_count
uint32 last_newgrf_count
the numbers of NewGRFs we found during the last scan
Definition: settings_type.h:136
gfx_layout.h
Functions related to laying out the texts.
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:317
GameConfig
Definition: game_config.hpp:17
_cur_year
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:26
GroundVehicleCache
Cached, frequently calculated values.
Definition: ground_vehicle.hpp:31
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1113
InputLoop
void InputLoop()
Regular call from the global game loop.
Definition: window.cpp:3029
Company::settings
CompanySettings settings
settings specific for each company
Definition: company_base.h:121
GetSaveLoadErrorString
const char * GetSaveLoadErrorString()
Get the string representation of the error message.
Definition: saveload.cpp:2496
Station::goods
GoodsEntry goods[NUM_CARGO]
Goods at this station.
Definition: station_base.h:472
SLO_SAVE
File is being saved.
Definition: fileio_type.h:52
GRFConfig::next
struct GRFConfig * next
NOSAVE: Next item in the linked list.
Definition: newgrf_config.h:178
rail_gui.h
Functions/types etc.
SLO_CHECK
Load file for checking and/or preview.
Definition: fileio_type.h:50
ClampU
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition: math_func.hpp:184
_network_available
bool _network_available
is network mode available?
Definition: network.cpp:58
TrainCache
Variables that are cached to improve performance and such.
Definition: train.h:72
_network_dedicated
bool _network_dedicated
are we a dedicated server?
Definition: network.cpp:59
SmallVector::Append
T * Append(uint to_add=1)
Append an item and return it.
Definition: smallvec_type.hpp:134
Backup
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:23
_local_company
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
Game::GetConsoleList
static char * GetConsoleList(char *p, const char *last, bool newest_only=false)
Wrapper function for GameScanner::GetConsoleList.
Definition: game_core.cpp:221
CheckCaches
static void CheckCaches()
Check the validity of some of the caches.
Definition: openttd.cpp:1191
_modal_progress_work_mutex
ThreadMutex * _modal_progress_work_mutex
Rights for the performing work.
Definition: progress.cpp:21
random_func.hpp
Pseudo random number generator.
GameCreationSettings::map_y
uint8 map_y
Y size of map.
Definition: settings_type.h:279
InitFreeType
void InitFreeType(bool monospace)
(Re)initialize the freetype related things, i.e.
Definition: fontcache.cpp:643
getoptdata.h
Library for parsing command-line options.
ProcessAsyncSaveFinish
void ProcessAsyncSaveFinish()
Handle async save finishes.
Definition: saveload.cpp:586
ShowInfoF
void CDECL ShowInfoF(const char *str,...)
Shows some information on the console/a popup box depending on the OS.
Definition: openttd.cpp:130
DFT_GAME_FILE
Save game or scenario file.
Definition: fileio_type.h:33
LoadFilter
Interface for filtering a savegame till it is loaded.
Definition: saveload_filter.h:16
FT_SAVEGAME
old or new savegame
Definition: fileio_type.h:20
FT_SCENARIO
old or new scenario
Definition: fileio_type.h:21
fontcache.h
Functions to read fonts from files and cache them.
WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition: error.h:26
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=NULL, uint textref_stack_size=0, const uint32 *textref_stack=NULL)
Display an error message in a window.
Definition: error_gui.cpp:378
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:279
_load_check_data
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition: fios_gui.cpp:39
VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
animated_tile_func.h
Tile animation!
NetworkChatMessageLoop
void NetworkChatMessageLoop()
Check if a message is expired.
Definition: network_chat_gui.cpp:180
BlitterFactory::GetBlittersInfo
static char * GetBlittersInfo(char *p, const char *last)
Fill a buffer with information about the blitters.
Definition: factory.hpp:158
AfterNewGRFScan
Callback structure of statements to be executed after the NewGRF scan.
Definition: openttd.cpp:386
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:778
ClientSettings::network
NetworkSettings network
settings related to the network
Definition: settings_type.h:562
VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:39
_is_network_server
bool _is_network_server
Does this client wants to be a network-server?
Definition: network.cpp:60
Ship::UpdateCache
void UpdateCache()
Update the caches of this ship.
Definition: ship_cmd.cpp:202
GamelogReset
void GamelogReset()
Resets and frees all memory allocated - used before loading or starting a new game.
Definition: gamelog.cpp:88
saveload.h
Functions/types related to saving and loading games.
Vehicle::IsPrimaryVehicle
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:434
GenerateWorld
void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings)
Generate a world.
Definition: genworld.cpp:298
Driver::DT_MUSIC
A music driver, needs to be before sound to properly shut down extmidi forked music players...
Definition: driver.h:43
error.h
Functions related to errors.
SM_START_HEIGHTMAP
Load a heightmap and start a new game from it.
Definition: openttd.h:37
_ini_blitter
char * _ini_blitter
The blitter as stored in the configuration file.
Definition: driver.cpp:31
Vehicle::unitnumber
UnitID unitnumber
unit number, for display purposes only
Definition: vehicle_base.h:291
MusicDriver::SetVolume
virtual void SetVolume(byte vol)=0
Set the volume, if possible.
SM_EDITOR
Switch to scenario editor.
Definition: openttd.h:30
_date_fract
DateFract _date_fract
Fractional part of the day.
Definition: date.cpp:29
AI::GameLoop
static void GameLoop()
Called every game-tick to let AIs do something.
Definition: ai_core.cpp:68
SaveOrLoadResult
SaveOrLoadResult
Save or load result codes.
Definition: saveload.h:19
ShowHelp
static void ShowHelp()
Show the help message when someone passed a wrong parameter.
Definition: openttd.cpp:143
UpdateAircraftCache
void UpdateAircraftCache(Aircraft *v, bool update_range=false)
Update cached values of an aircraft.
Definition: aircraft_cmd.cpp:576
Driver::Stop
virtual void Stop()=0
Stop this driver.
ClientSettings::company
CompanySettings company
default values for per-company settings
Definition: settings_type.h:563
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:153
_ini_sounddriver
char * _ini_sounddriver
The sound driver a stored in the configuration file.
Definition: driver.cpp:27
Train::ConsistChanged
void ConsistChanged(ConsistChangeFlags allowed_changes)
Recalculates the cached stuff of a train.
Definition: train_cmd.cpp:129
GameMode
GameMode
Mode which defines the state of the game.
Definition: openttd.h:18
DFT_OLD_GAME_FILE
Old save game or scenario file.
Definition: fileio_type.h:32
CompanySettings::vehicle
VehicleDefaultSettings vehicle
default settings for vehicles
Definition: settings_type.h:538
engine_func.h
Functions related to engines.
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:57
AI::Uninitialize
static void Uninitialize(bool keepConfig)
Uninitialize the AI system.
Definition: ai_core.cpp:174
BlitterFactory::SelectBlitter
static Blitter * SelectBlitter(const char *name)
Find the requested blitter and return his class.
Definition: factory.hpp:96
IConsoleCmdExec
void IConsoleCmdExec(const char *cmdstr)
Execute a given command passed to us.
Definition: console.cpp:409
settings_func.h
Functions related to setting/changing the settings.
NETWORK_DEFAULT_DEBUGLOG_PORT
static const uint16 NETWORK_DEFAULT_DEBUGLOG_PORT
The default port debug-log is sent to (TCP)
Definition: config.h:33
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:76
RoadStop::Entry::CheckIntegrity
void CheckIntegrity(const RoadStop *rs) const
Check the integrity of the data in this struct.
Definition: roadstop.cpp:382
progress.h
Functions related to modal progress.
NO_DIRECTORY
A path without any base directory.
Definition: fileio_type.h:127
AfterNewGRFScan::OnNewGRFsScanned
virtual void OnNewGRFsScanned()
Called whenever the NewGRF scan completed.
Definition: openttd.cpp:410
music_driver.hpp
Base for all music playback.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
PSM_ENTER_GAMELOOP
Enter the gameloop, changes will be permanent.
Definition: newgrf_storage.h:22
_config_file
char * _config_file
Configuration file of OpenTTD.
Definition: settings.cpp:80
LoadCheckData::Clear
void Clear()
Reset read data.
Definition: fios_gui.cpp:48
usererror
void CDECL usererror(const char *s,...)
Error handling for fatal user errors.
Definition: openttd.cpp:90
safeguards.h
A number of safeguards to prevent using unsafe methods.
StateGameLoop
void StateGameLoop()
State controlling game loop.
Definition: openttd.cpp:1341
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
linkgraphschedule.h
Declaration of link graph schedule used for cargo distribution.
_settings_newgame
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition: settings.cpp:78
COMPANY_FIRST
First company, same as owner.
Definition: company_type.h:24
AIConfig
Definition: ai_config.hpp:18
MILLISECONDS_PER_TICK
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
Definition: gfx_type.h:306
WindowDesc::SaveToConfig
static void SaveToConfig()
Save all WindowDesc settings to _windows_file.
Definition: window.cpp:162
_network_reconnect
uint8 _network_reconnect
Reconnect timeout.
Definition: network.cpp:66
FillNewGRFVehicleCache
void FillNewGRFVehicleCache(const Vehicle *v)
Fill the grf_cache of the given vehicle.
Definition: newgrf_engine.cpp:1282
TarScanner::SCENARIO
Scan for scenarios and heightmaps.
Definition: fileio_func.h:104
SAVE_DIR
Base directory for all savegames.
Definition: fileio_type.h:112
AUTOSAVE_DIR
Subdirectory of save for autosaves.
Definition: fileio_type.h:113
AfterNewGRFScan::join_server_password
const char * join_server_password
The password to join the server with.
Definition: openttd.cpp:392
VehicleCargoList::InvalidateCache
void InvalidateCache()
Invalidates the cached data and rebuild it.
Definition: cargopacket.cpp:542
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:126
AfterNewGRFScan::AfterNewGRFScan
AfterNewGRFScan(bool *save_config_ptr)
Create a new callback.
Definition: openttd.cpp:402
LoadFromConfig
void LoadFromConfig(bool minimal)
Load the values from the configuration files.
Definition: settings.cpp:1700
console_func.h
Console functions used outside of the console code.
LoadCheckData::error_data
char * error_data
Data to pass to SetDParamStr when displaying error.
Definition: fios.h:29
GETOPT_END
#define GETOPT_END()
Option terminator.
Definition: getoptdata.h:109
ScheduleErrorMessage
void ScheduleErrorMessage(const ErrorMessageData &data)
Schedule an error.
Definition: error_gui.cpp:440
DumpDebugFacilityNames
char * DumpDebugFacilityNames(char *buf, char *last)
Dump the available debug facility names in the help text.
Definition: debug.cpp:84
SafeLoad
bool SafeLoad(const char *filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf=NULL)
Load the specified savegame but on error do different things.
Definition: openttd.cpp:1000
Driver::DT_SOUND
A sound driver.
Definition: driver.h:44
ShutdownGame
static void ShutdownGame()
Unitializes drivers, frees allocated memory, cleans pools, ...
Definition: openttd.cpp:283
CursorVars::fix_at
bool fix_at
mouse is moving, but cursor is not (used for scrolling)
Definition: gfx_type.h:122
LoadWithFilter
SaveOrLoadResult LoadWithFilter(LoadFilter *reader)
Load the game using a (reader) filter.
Definition: saveload.cpp:2770
AfterNewGRFScan::join_company_password
const char * join_company_password
The password to join the company with.
Definition: openttd.cpp:393
LoadCheckData::HasErrors
bool HasErrors()
Check whether loading the game resulted in errors.
Definition: fios.h:62
OWNER_NONE
The tile has no ownership.
Definition: company_type.h:27
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:107
DIAGDIR_NW
Northwest.
Definition: direction_type.h:85
CheckIndustries
void CheckIndustries()
Verify whether the generated industries are complete, and warn the user if not.
Definition: industry_cmd.cpp:2752
GWM_EMPTY
Generate an empty map (sea-level)
Definition: genworld.h:30
MusicDriver::GetInstance
static MusicDriver * GetInstance()
Get the currently active instance of the music driver.
Definition: music_driver.hpp:46
GetOptData::opt
char * opt
Option value, if available (else NULL).
Definition: getoptdata.h:33
network.h
Basic functions/variables used all over the place.
SaveOrLoad
SaveOrLoadResult SaveOrLoad(const char *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:2790
NetworkShutDown
void NetworkShutDown()
This shuts the network down.
Definition: network.cpp:1091
DoCommandP
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:527
_network_game_info
NetworkServerGameInfo _network_game_info
Information about our game.
Definition: network.cpp:61
_pause_mode
PauseModeByte _pause_mode
The current pause mode.
Definition: gfx.cpp:48
VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
AfterNewGRFScan::save_config
bool save_config
The save config setting.
Definition: openttd.cpp:395
SLO_LOAD
File is being loaded.
Definition: fileio_type.h:51
InitializeLanguagePacks
void InitializeLanguagePacks()
Make a list of the available language packs.
Definition: strings.cpp:1944
_modal_progress_paint_mutex
ThreadMutex * _modal_progress_paint_mutex
Rights for the painting.
Definition: progress.cpp:23
LoadCheckData::error
StringID error
Error message from loading. INVALID_STRING_ID if no error.
Definition: fios.h:28
Vehicle::First
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:595
WaitTillGeneratedWorld
void WaitTillGeneratedWorld()
This will wait for the thread to finish up his work.
Definition: genworld.cpp:242
SaveLoadOperation
SaveLoadOperation
Operation performed on the file.
Definition: fileio_type.h:49
MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:25
CallWindowTickEvent
void CallWindowTickEvent()
Dispatch WE_TICK event over all windows.
Definition: window.cpp:3252
UnInitWindowSystem
void UnInitWindowSystem()
Close down the windowing system.
Definition: window.cpp:1890
GameSettings::game_config
class GameConfig * game_config
settings for gamescript
Definition: settings_type.h:549
SM_SAVE_GAME
Save game.
Definition: openttd.h:33
crashlog.h
Functions to be called to log a crash.
AfterNewGRFScan::dedicated_host
char * dedicated_host
Hostname for the dedicated server.
Definition: openttd.cpp:389
VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
TarScanner::DoScan
uint DoScan(Subdirectory sd)
Perform the scanning of a particular subdirectory.
Definition: fileio.cpp:646
CMDPL_NO_CONSTRUCTION
No construction actions may be executed.
Definition: command_type.h:416
MemCpyT
static void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
Definition: mem_func.hpp:25
ObjectSpec::name
StringID name
The name for this object.
Definition: newgrf_object.h:64
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:39
NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:66
Game::Initialize
static void Initialize()
Initialize the Game system.
Definition: game_core.cpp:50
NetworkServerGameInfo::map_name
char map_name[NETWORK_NAME_LENGTH]
Map which is played ["random" for a randomized map].
Definition: game.h:29
Company
Definition: company_base.h:110
NetworkSettings::server_port
uint16 server_port
port the server listens on
Definition: settings_type.h:243
Company::infrastructure
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:125
SoundDriver::GetInstance
static SoundDriver * GetInstance()
Get the currently active instance of the sound driver.
Definition: sound_driver.hpp:26
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:1137
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:223
NewGRFScanCallback
Callback for NewGRF scanning.
Definition: newgrf_config.h:208
MusicSettings::music_vol
byte music_vol
The requested music volume.
Definition: settings_type.h:187
IncreaseDate
void IncreaseDate()
Increases the tick counter, increases date and possibly calls procedures that have to be called daily...
Definition: date.cpp:275
LoadHotkeysFromConfig
void LoadHotkeysFromConfig()
Load the hotkeys from the config file.
Definition: hotkeys.cpp:330
company_func.h
Functions related to companies.
S8BPP_NONE
No support for 8bpp by OS or hardware, force 32bpp blitters.
Definition: gfx_type.h:317
NETWORK_DEFAULT_PORT
static const uint16 NETWORK_DEFAULT_PORT
The default port of the game server (TCP & UDP)
Definition: config.h:31
ErrorMessageData
The data of the error message.
Definition: error.h:30
PSM_LEAVE_GAMELOOP
Leave the gameloop, changes will be temporary.
Definition: newgrf_storage.h:23
GameCreationSettings::generation_seed
uint32 generation_seed
noise seed for world generation
Definition: settings_type.h:276
highscore.h
Declaration of functions and types defined in highscore.h and highscore_gui.h.
GetOptData
Data storage for parsing command line options.
Definition: getoptdata.h:32
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:561
EngineOverrideManager::ResetToCurrentNewGRFConfig
static bool ResetToCurrentNewGRFConfig()
Tries to reset the engine mapping to match the current NewGRF configuration.
Definition: engine.cpp:528
VehicleCargoList
CargoList that is used for vehicles.
Definition: cargopacket.h:283
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:1171
DoAutosave
static void DoAutosave()
Create an autosave.
Definition: openttd.cpp:1406
RoadVehUpdateCache
void RoadVehUpdateCache(RoadVehicle *v, bool same_length=false)
Update the cache of a road vehicle.
Definition: roadveh_cmd.cpp:216
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:59
DriverFactoryBase::SelectDriver
static void SelectDriver(const char *name, Driver::Type type)
Find the requested driver and return its class.
Definition: driver.cpp:88
ResetNewGRFData
void ResetNewGRFData()
Reset all NewGRF loaded data TODO.
Definition: newgrf.cpp:8073
fios.h
Declarations for savegames operations.
_current_company
CompanyByte _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
Vehicle::Next
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:582
ConstructionSettings::command_pause_level
uint8 command_pause_level
level/amount of commands that can&#39;t be executed while paused
Definition: settings_type.h:314
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:98
AI::KillAll
static void KillAll()
Kill any and all AIs we manage.
Definition: ai_core.cpp:149
WindowDesc::LoadFromConfig
static void LoadFromConfig()
Load all WindowDesc settings from _windows_file.
Definition: window.cpp:139
SM_RESTARTGAME
Restart –> &#39;Random game&#39; with current settings.
Definition: openttd.h:29
error
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:110
BaseMedia< GraphicsSet >::GetSetsList
static char * GetSetsList(char *p, const char *last)
Returns a list with the sets.
Definition: base_media_func.h:261
Vehicle::owner
OwnerByte owner
Which company owns the vehicle?
Definition: vehicle_base.h:273
ResetGRFConfig
void ResetGRFConfig(bool defaults)
Reset the current GRF Config to either blank or newgame settings.
Definition: newgrf_config.cpp:539
AfterNewGRFScan::network_conn
char * network_conn
Information about the server to connect to, or NULL.
Definition: openttd.cpp:391
RebuildSubsidisedSourceAndDestinationCache
void RebuildSubsidisedSourceAndDestinationCache()
Perform a full rebuild of the subsidies cache.
Definition: subsidy.cpp:133
LinkGraphSchedule::Clear
static void Clear()
Clear all link graphs and jobs from the schedule.
Definition: linkgraphschedule.cpp:97
VideoDriver::MainLoop
virtual void MainLoop()=0
Perform the actual drawing.
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: depend.cpp:68
_old_vds
VehicleDefaultSettings _old_vds
Used for loading default vehicles settings from old savegames.
Definition: settings.cpp:79
Town::cache
TownCache cache
Container for all cacheable data.
Definition: town.h:58
Town
Town data structure.
Definition: town.h:55
CursorVars::in_window
bool in_window
mouse inside this window, determines drawing logic
Definition: gfx_type.h:143
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:47
NetworkSettings::default_company_pass
char default_company_pass[NETWORK_PASSWORD_LENGTH]
default password for new companies in encrypted form
Definition: settings_type.h:253
LoadCheckData::gamelog_actions
uint gamelog_actions
Number of gamelog actions.
Definition: fios.h:42
RoadStop::GetEntry
const Entry * GetEntry(DiagDirection dir) const
Get the drive through road stop entry struct for the given direction.
Definition: roadstop_base.h:124
ScanNewGRFFiles
void ScanNewGRFFiles(NewGRFScanCallback *callback)
Scan for all NewGRFs.
Definition: newgrf_config.cpp:783
WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
Definition: window_type.h:59
game.hpp
Base functions for all Games.
command_func.h
Functions related to commands.
network_func.h
Network functions used by other parts of OpenTTD.
AfterNewGRFScan::generation_seed
uint generation_seed
Seed for the new game.
Definition: openttd.cpp:388
FileToSaveLoad::name
char name[MAX_PATH]
Name of the file.
Definition: saveload.h:30
_network_server
bool _network_server
network-server is active
Definition: network.cpp:57
FileToSaveLoad::file_op
SaveLoadOperation file_op
File operation to perform.
Definition: saveload.h:27
RoadStop
A Stop for a Road Vehicle.
Definition: roadstop_base.h:24
Layouter::ReduceLineCache
static void ReduceLineCache()
Reduce the size of linecache if necessary to prevent infinite growth.
Definition: gfx_layout.cpp:846
SaveHotkeysToConfig
void SaveHotkeysToConfig()
Save the hotkeys to the config file.
Definition: hotkeys.cpp:336
AutoFreeSmallVector::Clear
void Clear()
Remove all items from the list.
Definition: smallvec_type.hpp:380
UninitFreeType
void UninitFreeType()
Free everything allocated w.r.t.
Definition: fontcache.cpp:660
InitializeRailGUI
void InitializeRailGUI()
Resets the rail GUI - sets default railtype to build and resets the signal GUI.
Definition: rail_gui.cpp:1973
DO_FULL_ANIMATION
Perform palette animation.
Definition: openttd.h:46
LoadIntroGame
static void LoadIntroGame(bool load_newgrfs=true)
Load the introduction game.
Definition: openttd.cpp:320
GameSettings::ai_config
class AIConfig * ai_config[MAX_COMPANIES]
settings per company
Definition: settings_type.h:548
NetworkBackgroundLoop
void NetworkBackgroundLoop()
We have to do some (simple) background stuff that runs normally, even when we are not in multiplayer...
Definition: network.cpp:856
FileToSaveLoad::abstract_ftype
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
Definition: saveload.h:29
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:109
elrail_func.h
header file for electrified rail specific functions
Driver::DT_VIDEO
A video driver.
Definition: driver.h:45
GetOptData::GetOpt
int GetOpt()
Find the next option.
Definition: getoptdata.cpp:24
ship.h
Base for ships.
NetworkDisconnect
void NetworkDisconnect(bool blocking, bool close_admins)
We want to disconnect from the host/clients.
Definition: network.cpp:798
SM_LOAD_SCENARIO
Load scenario from scenario editor.
Definition: openttd.h:36
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:545
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:19
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:114
ParseResolution
static void ParseResolution(Dimension *res, const char *s)
Extract the resolution from the given string and store it in the &#39;res&#39; parameter. ...
Definition: openttd.cpp:266
NetworkSettings::last_host
char last_host[NETWORK_HOSTNAME_LENGTH]
IP address of the last joined server.
Definition: settings_type.h:267
rev.h
declaration of OTTD revision dependent variables
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:105
LoadCheckData::HasNewGrfs
bool HasNewGrfs()
Check whether the game uses any NewGrfs.
Definition: fios.h:71
SL_OK
completed successfully
Definition: saveload.h:20
InitializeSpriteSorter
void InitializeSpriteSorter()
Choose the "best" sprite sorter and set _vp_sprite_sorter.
Definition: viewport.cpp:3243
viewport_sprite_sorter.h
Types related to sprite sorting.
Backup::Restore
void Restore()
Restore the variable.
Definition: backup_type.hpp:114
ai.hpp
Base functions for all AIs.
FOR_ALL_VEHICLES
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
Definition: vehicle_base.h:986
_ini_musicdriver
char * _ini_musicdriver
The music driver a stored in the configuration file.
Definition: driver.cpp:29
town.h
Base of the town class.
SmallVector::Get
const T * Get(uint index) const
Get the pointer to item "number" (const)
Definition: smallvec_type.hpp:313
ZOOM_LVL_NORMAL
The normal zoom level.
Definition: zoom_type.h:24
RunTileLoop
void RunTileLoop()
Gradually iterate over all tiles on the map, calling their TileLoopProcs once every 256 ticks...
Definition: landscape.cpp:721
GCF_COMPATIBLE
GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches) ...
Definition: newgrf_config.h:27
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:544
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:2919
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
FileToSaveLoad::detail_ftype
DetailedFileType detail_ftype
Concrete file type (PNG, BMP, old save, etc).
Definition: saveload.h:28
SetDebugString
void SetDebugString(const char *s)
Set debugging levels by parsing the text in s.
Definition: debug.cpp:179
_network_bind_list
StringList _network_bind_list
The addresses to bind on.
Definition: network.cpp:67
PM_PAUSED_SAVELOAD
A game paused for saving/loading.
Definition: openttd.h:60
SM_GENRANDLAND
Generate random land within scenario editor.
Definition: openttd.h:35
ThreadMutex::BeginCritical
virtual void BeginCritical(bool allow_recursive=false)=0
Begin the critical section.
ai_config.hpp
AIConfig stores the configuration settings of every AI.
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:20
ResetWindowSystem
void ResetWindowSystem()
Reset the windowing system, by means of shutting it down followed by re-initialization.
Definition: window.cpp:1910
CargoList::InvalidateCache
void InvalidateCache()
Invalidates the cached data and rebuilds it.
Definition: cargopacket.cpp:204
GetOptData::numleft
int numleft
Number of arguments left in argv.
Definition: getoptdata.h:34
NetworkChangeCompanyPassword
const char * NetworkChangeCompanyPassword(CompanyID company_id, const char *password)
Change the company password of a given company.
Definition: network.cpp:174
gui.h
GUI functions that shouldn&#39;t be here.
news_func.h
Functions related to news.
SaveToHighScore
void SaveToHighScore()
Save HighScore table to file.
Definition: highscore.cpp:128
MakeHeightmapScreenshot
bool MakeHeightmapScreenshot(const char *filename)
Make a heightmap of the current map.
Definition: screenshot.cpp:800
station_base.h
Base classes/functions for stations.
WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:25
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
INVALID_COMPANY
An invalid company.
Definition: company_type.h:32
AfterNewGRFScan::startyear
Year startyear
The start year.
Definition: openttd.cpp:387
DetailedFileType
DetailedFileType
Kinds of files in each AbstractFileType.
Definition: fileio_type.h:30
BaseVehicle::type
VehicleTypeByte type
Type of vehicle.
Definition: vehicle_type.h:54
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:34
CCF_TRACK
Valid changes while vehicle is driving, and possibly changing tracks.
Definition: train.h:51
CrashLog::SetErrorMessage
static void SetErrorMessage(const char *message)
Sets a message for the error message handler.
Definition: crashlog.cpp:480
GWM_RANDOM
Generate a random map for SE.
Definition: genworld.h:31
_do_autosave
bool _do_autosave
are we doing an autosave at the moment?
Definition: saveload.cpp:278
GameCreationSettings::starting_year
Year starting_year
starting date
Definition: settings_type.h:277
AnimateAnimatedTiles
void AnimateAnimatedTiles()
Animate all tiles in the animated tile list, i.e. call AnimateTile on them.
Definition: animated_tile.cpp:72
backup_type.hpp
Class for backupping variables and making sure they are restored later.
Station
Station data structure.
Definition: station_base.h:446
factory.hpp
Factory to &#39;query&#39; all available blitters.
BaseMedia< GraphicsSet >::GetUsedSet
static const GraphicsSet * GetUsedSet()
Return the used set.
Definition: base_media_func.h:380
subsidy_func.h
Functions related to subsidies.
SM_NEWGAME
New Game –> &#39;Random game&#39;.
Definition: openttd.h:28
SwitchMode
SwitchMode
Mode which defines what mode we&#39;re switching to.
Definition: openttd.h:26
HasModalProgress
static bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition: progress.h:23
LoadFromHighScore
void LoadFromHighScore()
Initialize the highscore table to 0 and if any file exists, load in values.
Definition: highscore.cpp:156
SM_SAVE_HEIGHTMAP
Save heightmap.
Definition: openttd.h:34
GroundVehicle::gcache
GroundVehicleCache gcache
Cache of often calculated values.
Definition: ground_vehicle.hpp:82
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1461
VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
SettingsDisableElrail
bool SettingsDisableElrail(int32 p1)
_settings_game.disable_elrail callback
Definition: elrail.cpp:594
newgrf.h
Base for the NewGRF implementation.
BaseMedia< GraphicsSet >::ini_set
static const char * ini_set
The set as saved in the config file.
Definition: base_media_base.h:186
SL_REINIT
error that was caught in the middle of updating game state, need to clear it. (can only happen during...
Definition: saveload.h:22
CMD_PAUSE
pause the game
Definition: command_type.h:255