73 void CallLandscapeTick();
75 void DoPaletteAnimations();
82 extern void ShowOSErrorBox(
const char *buf,
bool system);
99 ShowOSErrorBox(buf,
false);
110 void CDECL
error(
const char *s, ...)
119 ShowOSErrorBox(buf,
true);
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"
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"
214 #if !defined(WIN32) && !defined(WIN64)
221 static void WriteSavegameInfo(
const char *
name)
224 uint32 last_ottd_rev = 0;
225 byte ever_modified = 0;
226 bool removed_newgrfs =
false;
234 p +=
seprintf(p,
lastof(buf),
"NewGRF ver: 0x%08X\n", last_ottd_rev);
237 if (removed_newgrfs) {
246 p +=
seprintf(p,
lastof(buf),
"%08X %s %s\n", c->ident.grfid, md5sum, c->filename);
252 #if !defined(WIN32) && !defined(WIN64)
268 const char *t = strchr(s,
'x');
274 res->width =
max(strtoul(s, NULL, 0), 64UL);
275 res->height =
max(strtoul(t + 1, NULL, 0), 64UL);
300 #ifdef ENABLE_NETWORK
322 _game_mode = GM_MENU;
349 void MakeNewgameSettingsLive()
377 void OpenBrowser(
const char *url)
380 if (strstr(url,
"http://") != url && strstr(url,
"https://") != url)
return;
382 extern void OSOpenBrowser(
const char *url);
407 save_config_ptr(save_config_ptr),
save_config(true)
444 #if defined(ENABLE_NETWORK)
460 #ifdef ENABLE_NETWORK
462 const char *port = NULL;
463 const char *company = NULL;
469 if (company != NULL) {
474 if (join_as >= MAX_COMPANIES) {
480 if (port != NULL) rport = atoi(port);
493 #if defined(UNIX) && !defined(__MORPHOS__)
494 extern void DedicatedFork();
506 #if defined(ENABLE_NETWORK)
512 #if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
537 char *musicdriver = NULL;
538 char *sounddriver = NULL;
539 char *videodriver = NULL;
540 char *blitter = NULL;
541 char *graphics_set = NULL;
542 char *sounds_set = NULL;
543 char *music_set = NULL;
546 bool save_config =
false;
548 #if defined(ENABLE_NETWORK)
549 bool dedicated =
false;
550 char *debuglog_conn = NULL;
552 extern bool _dedicated_forks;
553 _dedicated_forks =
false;
556 _game_mode = GM_MENU;
564 while ((i = mgo.
GetOpt()) != -1) {
566 case 'I':
free(graphics_set); graphics_set =
stredup(mgo.
opt);
break;
569 case 'm':
free(musicdriver); musicdriver =
stredup(mgo.
opt);
break;
570 case 's':
free(sounddriver); sounddriver =
stredup(mgo.
opt);
break;
571 case 'v':
free(videodriver); videodriver =
stredup(mgo.
opt);
break;
573 #if defined(ENABLE_NETWORK)
581 videodriver =
stredup(
"dedicated");
585 if (mgo.
opt != NULL) {
588 const char *temp = NULL;
589 const char *port = NULL;
595 case 'f': _dedicated_forks =
true;
break;
600 debuglog_conn = mgo.
opt;
620 if (mgo.
opt != NULL) {
626 const char *t = strrchr(_file_to_saveload.
name,
'.');
629 if (ft != FIOS_TYPE_INVALID) SetFiosType(ft);
645 goto exit_noshutdown;
655 fprintf(stderr,
"Failed to open savegame\n");
660 fprintf(stderr,
"%s\n", buf);
662 goto exit_noshutdown;
665 WriteSavegameInfo(title);
667 goto exit_noshutdown;
679 if (i == -2 || mgo.
numleft > 0) {
692 goto exit_noshutdown;
695 #if defined(WINCE) && defined(_DEBUG)
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;
707 #if defined(UNIX) && !defined(__MORPHOS__)
709 if (_dedicated_forks) DedicatedFork();
747 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_GRAPHICS_NOT_FOUND);
757 DEBUG(misc, 1,
"Loading blitter...");
771 usererror(
"Failed to autoprobe blitter") :
772 usererror(
"Failed to select requested blitter '%s'; does it exist?", blitter);
788 #if defined(ENABLE_NETWORK)
790 const char *not_used = NULL;
791 const char *port = NULL;
797 if (port != NULL) rport = atoi(port);
818 usererror(
"Failed to find a sounds set. Please acquire a sounds set for OpenTTD. See section 4.1 of readme.txt.");
820 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_SOUNDS_NOT_FOUND);
831 usererror(
"Failed to find a music set. Please acquire a music set for OpenTTD. See section 4.1 of readme.txt.");
833 ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_MUSIC_NOT_FOUND);
904 #ifdef ENABLE_NETWORK
906 if (_log_fd != NULL) {
914 void HandleExitGameRequest()
916 if (_game_mode == GM_MENU || _game_mode == GM_BOOTSTRAP) {
926 static void MakeNewGameDone()
950 #ifdef ENABLE_NETWORK
965 static void MakeNewGame(
bool from_heightmap,
bool reset_settings)
967 _game_mode = GM_NORMAL;
975 static void MakeNewEditorWorldDone()
980 static void MakeNewEditorWorld()
982 _game_mode = GM_EDITOR;
1008 case SL_OK:
return true;
1011 #ifdef ENABLE_NETWORK
1019 DEBUG(net, 0,
"Loading game failed, so a new (random) game will be started!");
1020 MakeNewGame(
false,
true);
1032 case GM_EDITOR: MakeNewEditorWorld();
break;
1044 #ifdef ENABLE_NETWORK
1063 MakeNewgameSettingsLive();
1066 NetworkServerStart();
1079 MakeNewEditorWorld();
1084 #ifdef ENABLE_NETWORK
1111 #ifdef ENABLE_NETWORK
1121 #ifdef ENABLE_NETWORK
1126 MakeNewGame(
true,
true);
1179 default: NOT_REACHED();
1194 if (_debug_desync_level <= 1)
return;
1210 DEBUG(desync, 2,
"town cache mismatch: town %i", (
int)t->
index);
1224 FOR_ALL_COMPANIES(c) {
1226 DEBUG(desync, 2,
"infrastructure cache mismatch: company %i", (
int)c->
index);
1233 FOR_ALL_ROADSTOPS(rs) {
1247 for (
const Vehicle *u = v; u != NULL; u = u->
Next()) length++;
1249 NewGRFCache *grf_cache = CallocT<NewGRFCache>(length);
1250 VehicleCache *veh_cache = CallocT<VehicleCache>(length);
1252 TrainCache *tra_cache = CallocT<TrainCache>(length);
1255 for (
const Vehicle *u = v; u != NULL; u = u->
Next()) {
1257 grf_cache[length] = u->grf_cache;
1258 veh_cache[length] = u->vcache;
1282 for (
const Vehicle *u = v; u != NULL; u = u->
Next()) {
1284 if (memcmp(&grf_cache[length], &u->grf_cache,
sizeof(
NewGRFCache)) != 0) {
1285 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 if (memcmp(&veh_cache[length], &u->vcache,
sizeof(
VehicleCache)) != 0) {
1288 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);
1293 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);
1296 DEBUG(desync, 2,
"train cache mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->
index, (
int)v->
owner, v->
unitnumber, length);
1301 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);
1325 FOR_ALL_STATIONS(st) {
1345 #ifndef DEBUG_DUMP_COMMANDS
1355 if (_game_mode == GM_EDITOR) {
1359 CallLandscapeTick();
1368 char name[MAX_PATH];
1384 CallLandscapeTick();
1387 #ifndef DEBUG_DUMP_COMMANDS
1418 static int _autosave_ctr = 0;
1426 DEBUG(sl, 2,
"Autosaving to '%s'", buf);
1434 if (_game_mode == GM_BOOTSTRAP) {
1435 #ifdef ENABLE_NETWORK
1458 IncreaseSpriteLRU();
1459 InteractiveRandom();
1461 extern int _caret_timer;
1465 #ifdef ENABLE_NETWORK
1483 static uint check_message = 0;