|
@@ -534,15 +534,15 @@ static const OptionData _options[] = {
|
|
|
int openttd_main(int argc, char *argv[])
|
|
|
{
|
|
|
char *musicdriver = nullptr;
|
|
|
char *sounddriver = nullptr;
|
|
|
char *videodriver = nullptr;
|
|
|
char *blitter = nullptr;
|
|
|
char *graphics_set = nullptr;
|
|
|
char *sounds_set = nullptr;
|
|
|
char *music_set = nullptr;
|
|
|
std::string graphics_set;
|
|
|
std::string sounds_set;
|
|
|
std::string music_set;
|
|
|
Dimension resolution = {0, 0};
|
|
|
/* AfterNewGRFScan sets save_config to true after scanning completed. */
|
|
|
bool save_config = false;
|
|
|
AfterNewGRFScan *scanner = new AfterNewGRFScan(&save_config);
|
|
|
bool dedicated = false;
|
|
|
char *debuglog_conn = nullptr;
|
|
@@ -560,15 +560,15 @@ int openttd_main(int argc, char *argv[])
|
|
|
GetOptData mgo(argc - 1, argv + 1, _options);
|
|
|
int ret = 0;
|
|
|
|
|
|
int i;
|
|
|
while ((i = mgo.GetOpt()) != -1) {
|
|
|
switch (i) {
|
|
|
case 'I': free(graphics_set); graphics_set = stredup(mgo.opt); break;
|
|
|
case 'S': free(sounds_set); sounds_set = stredup(mgo.opt); break;
|
|
|
case 'M': free(music_set); music_set = stredup(mgo.opt); break;
|
|
|
case 'I': graphics_set = mgo.opt; break;
|
|
|
case 'S': sounds_set = mgo.opt; break;
|
|
|
case 'M': music_set = mgo.opt; break;
|
|
|
case 'm': free(musicdriver); musicdriver = stredup(mgo.opt); break;
|
|
|
case 's': free(sounddriver); sounddriver = stredup(mgo.opt); break;
|
|
|
case 'v': free(videodriver); videodriver = stredup(mgo.opt); break;
|
|
|
case 'b': free(blitter); blitter = stredup(mgo.opt); break;
|
|
|
case 'D':
|
|
|
free(musicdriver);
|
|
@@ -728,23 +728,22 @@ int openttd_main(int argc, char *argv[])
|
|
|
InitFreeType(false);
|
|
|
|
|
|
/* This must be done early, since functions use the SetWindowDirty* calls */
|
|
|
InitWindowSystem();
|
|
|
|
|
|
BaseGraphics::FindSets();
|
|
|
if (graphics_set == nullptr && BaseGraphics::ini_set != nullptr) graphics_set = stredup(BaseGraphics::ini_set);
|
|
|
if (graphics_set.empty() && !BaseGraphics::ini_set.empty()) graphics_set = BaseGraphics::ini_set;
|
|
|
if (!BaseGraphics::SetSet(graphics_set)) {
|
|
|
if (!StrEmpty(graphics_set)) {
|
|
|
BaseGraphics::SetSet(nullptr);
|
|
|
if (!graphics_set.empty()) {
|
|
|
BaseGraphics::SetSet({});
|
|
|
|
|
|
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_GRAPHICS_NOT_FOUND);
|
|
|
msg.SetDParamStr(0, graphics_set);
|
|
|
msg.SetDParamStr(0, graphics_set.c_str());
|
|
|
ScheduleErrorMessage(msg);
|
|
|
}
|
|
|
}
|
|
|
free(graphics_set);
|
|
|
|
|
|
/* Initialize game palette */
|
|
|
GfxInitPalettes();
|
|
|
|
|
|
DEBUG(misc, 1, "Loading blitter...");
|
|
|
if (blitter == nullptr && _ini_blitter != nullptr) blitter = stredup(_ini_blitter);
|
|
@@ -799,36 +798,34 @@ int openttd_main(int argc, char *argv[])
|
|
|
VideoDriver::GetInstance()->ClaimMousePointer();
|
|
|
|
|
|
/* initialize screenshot formats */
|
|
|
InitializeScreenshotFormats();
|
|
|
|
|
|
BaseSounds::FindSets();
|
|
|
if (sounds_set == nullptr && BaseSounds::ini_set != nullptr) sounds_set = stredup(BaseSounds::ini_set);
|
|
|
if (sounds_set.empty() && !BaseSounds::ini_set.empty()) sounds_set = BaseSounds::ini_set;
|
|
|
if (!BaseSounds::SetSet(sounds_set)) {
|
|
|
if (StrEmpty(sounds_set) || !BaseSounds::SetSet(nullptr)) {
|
|
|
if (sounds_set.empty() || !BaseSounds::SetSet({})) {
|
|
|
usererror("Failed to find a sounds set. Please acquire a sounds set for OpenTTD. See section 1.4 of README.md.");
|
|
|
} else {
|
|
|
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_SOUNDS_NOT_FOUND);
|
|
|
msg.SetDParamStr(0, sounds_set);
|
|
|
msg.SetDParamStr(0, sounds_set.c_str());
|
|
|
ScheduleErrorMessage(msg);
|
|
|
}
|
|
|
}
|
|
|
free(sounds_set);
|
|
|
|
|
|
BaseMusic::FindSets();
|
|
|
if (music_set == nullptr && BaseMusic::ini_set != nullptr) music_set = stredup(BaseMusic::ini_set);
|
|
|
if (music_set.empty() && !BaseMusic::ini_set.empty()) music_set = BaseMusic::ini_set;
|
|
|
if (!BaseMusic::SetSet(music_set)) {
|
|
|
if (StrEmpty(music_set) || !BaseMusic::SetSet(nullptr)) {
|
|
|
if (music_set.empty() || !BaseMusic::SetSet({})) {
|
|
|
usererror("Failed to find a music set. Please acquire a music set for OpenTTD. See section 1.4 of README.md.");
|
|
|
} else {
|
|
|
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_MUSIC_NOT_FOUND);
|
|
|
msg.SetDParamStr(0, music_set);
|
|
|
msg.SetDParamStr(0, music_set.c_str());
|
|
|
ScheduleErrorMessage(msg);
|
|
|
}
|
|
|
}
|
|
|
free(music_set);
|
|
|
|
|
|
if (sounddriver == nullptr && _ini_sounddriver != nullptr) sounddriver = stredup(_ini_sounddriver);
|
|
|
DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
|
|
|
free(sounddriver);
|
|
|
|
|
|
if (musicdriver == nullptr && _ini_musicdriver != nullptr) musicdriver = stredup(_ini_musicdriver);
|
|
@@ -872,28 +869,21 @@ int openttd_main(int argc, char *argv[])
|
|
|
/* Reset windowing system, stop drivers, free used memory, ... */
|
|
|
ShutdownGame();
|
|
|
goto exit_normal;
|
|
|
|
|
|
exit_noshutdown:
|
|
|
/* These three are normally freed before bootstrap. */
|
|
|
free(graphics_set);
|
|
|
free(videodriver);
|
|
|
free(blitter);
|
|
|
|
|
|
exit_bootstrap:
|
|
|
/* These are normally freed before exit, but after bootstrap. */
|
|
|
free(sounds_set);
|
|
|
free(music_set);
|
|
|
free(musicdriver);
|
|
|
free(sounddriver);
|
|
|
|
|
|
exit_normal:
|
|
|
free(BaseGraphics::ini_set);
|
|
|
free(BaseSounds::ini_set);
|
|
|
free(BaseMusic::ini_set);
|
|
|
|
|
|
free(_ini_musicdriver);
|
|
|
free(_ini_sounddriver);
|
|
|
free(_ini_videodriver);
|
|
|
free(_ini_blitter);
|
|
|
|
|
|
delete scanner;
|
|
@@ -1139,15 +1129,15 @@ void SwitchToMode(SwitchMode new_mode)
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SM_MENU: // Switch to game intro menu
|
|
|
LoadIntroGame();
|
|
|
if (BaseSounds::ini_set == nullptr && BaseSounds::GetUsedSet()->fallback) {
|
|
|
if (BaseSounds::ini_set.empty() && BaseSounds::GetUsedSet()->fallback) {
|
|
|
ShowErrorMessage(STR_WARNING_FALLBACK_SOUNDSET, INVALID_STRING_ID, WL_CRITICAL);
|
|
|
BaseSounds::ini_set = stredup(BaseSounds::GetUsedSet()->name);
|
|
|
BaseSounds::ini_set = BaseSounds::GetUsedSet()->name;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case SM_SAVE_GAME: // Save game.
|
|
|
/* Make network saved games on pause compatible to singleplayer */
|
|
|
if (SaveOrLoad(_file_to_saveload.name, SLO_SAVE, DFT_GAME_FILE, NO_DIRECTORY) != SL_OK) {
|