2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 17:11:33 +02:00
|
|
|
/** @file openttd.cpp Functions related to starting OpenTTD. */
|
2007-03-21 16:19:33 +01:00
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
#include "stdafx.h"
|
2008-03-31 09:03:35 +02:00
|
|
|
|
|
|
|
#include "blitter/factory.hpp"
|
|
|
|
#include "sound/sound_driver.hpp"
|
|
|
|
#include "music/music_driver.hpp"
|
|
|
|
#include "video/video_driver.hpp"
|
2022-11-07 22:26:03 +01:00
|
|
|
#include "mixer.h"
|
2008-03-31 09:03:35 +02:00
|
|
|
|
|
|
|
#include "fontcache.h"
|
2011-12-10 14:54:10 +01:00
|
|
|
#include "error.h"
|
2023-04-19 22:47:36 +02:00
|
|
|
#include "error_func.h"
|
2004-08-09 19:04:08 +02:00
|
|
|
#include "gui.h"
|
2008-03-31 09:03:35 +02:00
|
|
|
|
2009-08-09 18:54:03 +02:00
|
|
|
#include "base_media_base.h"
|
2009-01-04 16:32:25 +01:00
|
|
|
#include "saveload/saveload.h"
|
2023-06-24 22:50:04 +02:00
|
|
|
#include "company_cmd.h"
|
2008-09-30 22:51:04 +02:00
|
|
|
#include "company_func.h"
|
2007-12-21 22:50:46 +01:00
|
|
|
#include "command_func.h"
|
2008-03-28 09:53:36 +01:00
|
|
|
#include "news_func.h"
|
2007-12-28 04:14:55 +01:00
|
|
|
#include "fios.h"
|
2007-03-02 13:01:24 +01:00
|
|
|
#include "aircraft.h"
|
2009-05-22 22:18:45 +02:00
|
|
|
#include "roadveh.h"
|
2009-05-23 00:22:46 +02:00
|
|
|
#include "train.h"
|
2010-11-27 22:11:37 +01:00
|
|
|
#include "ship.h"
|
2008-05-24 12:15:06 +02:00
|
|
|
#include "console_func.h"
|
2004-11-15 20:25:59 +01:00
|
|
|
#include "screenshot.h"
|
2007-01-02 18:34:03 +01:00
|
|
|
#include "network/network.h"
|
2008-05-30 20:20:26 +02:00
|
|
|
#include "network/network_func.h"
|
2009-01-12 18:11:45 +01:00
|
|
|
#include "ai/ai.hpp"
|
|
|
|
#include "ai/ai_config.hpp"
|
2008-01-07 01:19:09 +01:00
|
|
|
#include "settings_func.h"
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 12:00:30 +02:00
|
|
|
#include "genworld.h"
|
2011-08-21 14:48:46 +02:00
|
|
|
#include "progress.h"
|
2007-12-21 20:49:27 +01:00
|
|
|
#include "strings_func.h"
|
2007-12-27 14:35:39 +01:00
|
|
|
#include "vehicle_func.h"
|
2008-06-03 20:35:58 +02:00
|
|
|
#include "gamelog.h"
|
2008-04-20 10:22:59 +02:00
|
|
|
#include "animated_tile_func.h"
|
2009-06-23 23:44:48 +02:00
|
|
|
#include "roadstop_base.h"
|
2008-05-08 18:48:29 +02:00
|
|
|
#include "elrail_func.h"
|
2008-05-04 23:53:36 +02:00
|
|
|
#include "rev.h"
|
2009-01-03 19:44:20 +01:00
|
|
|
#include "highscore.h"
|
2009-10-20 14:20:53 +02:00
|
|
|
#include "station_base.h"
|
2009-09-07 13:10:49 +02:00
|
|
|
#include "crashlog.h"
|
2010-01-15 17:41:15 +01:00
|
|
|
#include "engine_func.h"
|
|
|
|
#include "core/random_func.hpp"
|
2010-05-18 03:10:23 +02:00
|
|
|
#include "rail_gui.h"
|
2019-04-06 08:46:15 +02:00
|
|
|
#include "road_gui.h"
|
2010-05-31 22:22:57 +02:00
|
|
|
#include "core/backup_type.hpp"
|
2010-07-03 15:28:15 +02:00
|
|
|
#include "hotkeys.h"
|
2010-09-06 20:20:07 +02:00
|
|
|
#include "newgrf.h"
|
2011-02-18 21:14:30 +01:00
|
|
|
#include "misc/getoptdata.h"
|
2011-12-19 21:50:54 +01:00
|
|
|
#include "game/game.hpp"
|
2011-12-19 21:55:56 +01:00
|
|
|
#include "game/game_config.hpp"
|
2012-04-25 23:06:31 +02:00
|
|
|
#include "town.h"
|
2012-08-18 13:38:06 +02:00
|
|
|
#include "subsidy_func.h"
|
2013-07-06 21:00:33 +02:00
|
|
|
#include "gfx_layout.h"
|
2019-04-23 22:55:27 +02:00
|
|
|
#include "viewport_func.h"
|
2014-01-02 17:48:16 +01:00
|
|
|
#include "viewport_sprite_sorter.h"
|
2018-07-19 21:17:07 +02:00
|
|
|
#include "framerate_type.h"
|
2020-05-12 01:19:52 +02:00
|
|
|
#include "industry.h"
|
2021-08-15 00:17:10 +02:00
|
|
|
#include "network/network_gui.h"
|
2023-04-25 19:43:45 +02:00
|
|
|
#include "network/network_survey.h"
|
2021-10-31 19:39:09 +01:00
|
|
|
#include "misc_cmd.h"
|
2023-04-13 17:16:48 +02:00
|
|
|
#include "timer/timer.h"
|
|
|
|
#include "timer/timer_game_calendar.h"
|
2024-01-22 15:04:34 +01:00
|
|
|
#include "timer/timer_game_economy.h"
|
2023-04-27 17:21:29 +02:00
|
|
|
#include "timer/timer_game_realtime.h"
|
2023-04-16 20:14:22 +02:00
|
|
|
#include "timer/timer_game_tick.h"
|
2024-01-22 20:22:45 +01:00
|
|
|
#include "social_integration.h"
|
2006-12-27 13:38:02 +01:00
|
|
|
|
2013-06-09 14:58:37 +02:00
|
|
|
#include "linkgraph/linkgraphschedule.h"
|
|
|
|
|
2019-03-11 00:45:39 +01:00
|
|
|
#include <system_error>
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2014-04-23 22:13:33 +02:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2020-12-05 21:57:47 +01:00
|
|
|
#ifdef __EMSCRIPTEN__
|
|
|
|
# include <emscripten.h>
|
|
|
|
# include <emscripten/html5.h>
|
|
|
|
#endif
|
|
|
|
|
2007-03-07 12:47:46 +01:00
|
|
|
void CallLandscapeTick();
|
|
|
|
void DoPaletteAnimations();
|
|
|
|
void MusicLoop();
|
2018-05-04 22:29:22 +02:00
|
|
|
void CallWindowGameTickEvent();
|
2011-11-17 22:17:17 +01:00
|
|
|
bool HandleBootstrap();
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2024-04-16 16:49:08 +02:00
|
|
|
extern void CheckCaches();
|
2009-08-28 17:23:11 +02:00
|
|
|
extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY);
|
2023-11-29 01:17:05 +01:00
|
|
|
extern void OSOpenBrowser(const std::string &url);
|
2008-06-05 22:54:52 +02:00
|
|
|
extern void ShowOSErrorBox(const char *buf, bool system);
|
2020-12-06 21:11:42 +01:00
|
|
|
extern std::string _config_file;
|
2020-12-13 16:56:33 +01:00
|
|
|
|
|
|
|
bool _save_config = false;
|
2021-03-09 14:53:51 +01:00
|
|
|
bool _request_newgrf_scan = false;
|
|
|
|
NewGRFScanCallback *_request_newgrf_scan_callback = nullptr;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-04-29 20:19:29 +02:00
|
|
|
/**
|
2008-06-05 22:54:52 +02:00
|
|
|
* Error handling for fatal user errors.
|
2023-04-19 22:47:36 +02:00
|
|
|
* @param str the string to print.
|
2008-06-05 22:54:52 +02:00
|
|
|
* @note Does NEVER return.
|
|
|
|
*/
|
2023-04-19 22:47:36 +02:00
|
|
|
void UserErrorI(const std::string &str)
|
2008-06-05 22:54:52 +02:00
|
|
|
{
|
2023-04-19 22:47:36 +02:00
|
|
|
ShowOSErrorBox(str.c_str(), false);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (VideoDriver::GetInstance() != nullptr) VideoDriver::GetInstance()->Stop();
|
2008-06-05 22:54:52 +02:00
|
|
|
|
2020-12-05 21:57:47 +01:00
|
|
|
#ifdef __EMSCRIPTEN__
|
|
|
|
emscripten_exit_pointerlock();
|
|
|
|
/* In effect, the game ends here. As emscripten_set_main_loop() caused
|
|
|
|
* the stack to be unwound, the code after MainLoop() in
|
|
|
|
* openttd_main() is never executed. */
|
|
|
|
EM_ASM(if (window["openttd_abort"]) openttd_abort());
|
|
|
|
#endif
|
|
|
|
|
2023-10-28 17:08:08 +02:00
|
|
|
_exit(1);
|
2008-06-05 22:54:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Error handling for fatal non-user errors.
|
2023-04-19 22:47:36 +02:00
|
|
|
* @param str the string to print.
|
2008-04-29 20:19:29 +02:00
|
|
|
* @note Does NEVER return.
|
|
|
|
*/
|
2023-04-19 22:47:36 +02:00
|
|
|
void FatalErrorI(const std::string &str)
|
2005-11-14 20:48:04 +01:00
|
|
|
{
|
2019-04-10 23:07:06 +02:00
|
|
|
if (VideoDriver::GetInstance() == nullptr || VideoDriver::GetInstance()->HasGUI()) {
|
2023-04-19 22:47:36 +02:00
|
|
|
ShowOSErrorBox(str.c_str(), true);
|
2019-01-30 22:28:07 +01:00
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-09-07 13:10:49 +02:00
|
|
|
/* Set the error message for the crash log and then invoke it. */
|
2023-04-19 22:47:36 +02:00
|
|
|
CrashLog::SetErrorMessage(str);
|
2009-09-07 13:10:49 +02:00
|
|
|
abort();
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2008-04-29 20:19:29 +02:00
|
|
|
/**
|
|
|
|
* Show the help message when someone passed a wrong parameter.
|
|
|
|
*/
|
|
|
|
static void ShowHelp()
|
|
|
|
{
|
2023-05-19 23:22:30 +02:00
|
|
|
std::string str;
|
|
|
|
str.reserve(8192);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2023-05-19 23:22:30 +02:00
|
|
|
std::back_insert_iterator<std::string> output_iterator = std::back_inserter(str);
|
|
|
|
fmt::format_to(output_iterator, "OpenTTD {}\n", _openttd_revision);
|
|
|
|
str +=
|
2006-01-06 23:52:31 +01:00
|
|
|
"\n"
|
|
|
|
"\n"
|
2004-08-09 19:04:08 +02:00
|
|
|
"Command line options:\n"
|
2004-12-04 18:54:56 +01:00
|
|
|
" -v drv = Set video driver (see below)\n"
|
2022-11-05 15:42:20 +01:00
|
|
|
" -s drv = Set sound driver (see below)\n"
|
2004-12-04 18:54:56 +01:00
|
|
|
" -m drv = Set music driver (see below)\n"
|
2007-06-11 13:50:49 +02:00
|
|
|
" -b drv = Set the blitter to use (see below)\n"
|
2004-12-04 18:54:56 +01:00
|
|
|
" -r res = Set resolution (for instance 800x600)\n"
|
|
|
|
" -h = Display this help text\n"
|
2006-08-15 16:52:17 +02:00
|
|
|
" -t year = Set starting year\n"
|
2005-03-06 17:08:19 +01:00
|
|
|
" -d [[fac=]lvl[,...]]= Debug mode\n"
|
2004-12-04 18:54:56 +01:00
|
|
|
" -e = Start Editor\n"
|
2024-01-22 23:35:25 +01:00
|
|
|
" -g [savegame|scenario|heightmap] = Start new/savegame/scenario/heightmap immediately\n"
|
2004-12-04 18:54:56 +01:00
|
|
|
" -G seed = Set random seed\n"
|
2023-07-25 22:27:23 +02:00
|
|
|
" -n host[:port][#company]= Join network game\n"
|
2009-06-10 21:00:34 +02:00
|
|
|
" -p password = Password to join server\n"
|
2023-07-25 22:27:23 +02:00
|
|
|
" -D [host][:port] = Start dedicated server\n"
|
2019-03-04 19:21:13 +01:00
|
|
|
#if !defined(_WIN32)
|
2004-12-18 15:19:21 +01:00
|
|
|
" -f = Fork into the background (dedicated only)\n"
|
2006-06-27 23:25:53 +02:00
|
|
|
#endif
|
2008-08-24 10:41:38 +02:00
|
|
|
" -I graphics_set = Force the graphics set (see below)\n"
|
2009-08-09 21:50:44 +02:00
|
|
|
" -S sounds_set = Force the sounds set (see below)\n"
|
2009-12-22 22:40:29 +01:00
|
|
|
" -M music_set = Force the music set (see below)\n"
|
2006-01-06 23:52:31 +01:00
|
|
|
" -c config_file = Use 'config_file' instead of 'openttd.cfg'\n"
|
2020-12-13 16:28:06 +01:00
|
|
|
" -x = Never save configuration changes to disk\n"
|
2021-06-10 23:13:34 +02:00
|
|
|
" -X = Don't use global folders to search for files\n"
|
2011-10-30 14:47:45 +01:00
|
|
|
" -q savegame = Write some information about the savegame and exit\n"
|
2022-05-06 10:35:47 +02:00
|
|
|
" -Q = Don't scan for/load NewGRF files on startup\n"
|
|
|
|
" -QQ = Disable NewGRF scanning/loading entirely\n"
|
2023-05-19 23:22:30 +02:00
|
|
|
"\n";
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-08-24 10:41:38 +02:00
|
|
|
/* List the graphics packs */
|
2023-05-19 23:22:30 +02:00
|
|
|
BaseGraphics::GetSetsList(output_iterator);
|
2008-08-24 10:41:38 +02:00
|
|
|
|
2009-08-09 21:50:44 +02:00
|
|
|
/* List the sounds packs */
|
2023-05-19 23:22:30 +02:00
|
|
|
BaseSounds::GetSetsList(output_iterator);
|
2009-08-09 21:50:44 +02:00
|
|
|
|
2009-12-22 22:40:29 +01:00
|
|
|
/* List the music packs */
|
2023-05-19 23:22:30 +02:00
|
|
|
BaseMusic::GetSetsList(output_iterator);
|
2009-12-22 22:40:29 +01:00
|
|
|
|
2007-07-05 14:23:54 +02:00
|
|
|
/* List the drivers */
|
2023-05-19 23:22:30 +02:00
|
|
|
DriverFactoryBase::GetDriversInfo(output_iterator);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2007-06-11 13:50:49 +02:00
|
|
|
/* List the blitters */
|
2023-05-19 23:22:30 +02:00
|
|
|
BlitterFactory::GetBlittersInfo(output_iterator);
|
2007-06-11 13:50:49 +02:00
|
|
|
|
2012-04-07 22:55:55 +02:00
|
|
|
/* List the debug facilities. */
|
2023-05-19 23:22:30 +02:00
|
|
|
DumpDebugFacilityNames(output_iterator);
|
2012-04-07 22:55:55 +02:00
|
|
|
|
2009-01-12 18:11:45 +01:00
|
|
|
/* We need to initialize the AI, so it finds the AIs */
|
|
|
|
AI::Initialize();
|
2023-05-19 23:22:30 +02:00
|
|
|
AI::GetConsoleList(output_iterator, true);
|
2009-01-12 18:11:45 +01:00
|
|
|
AI::Uninitialize(true);
|
|
|
|
|
2011-12-19 21:55:56 +01:00
|
|
|
/* We need to initialize the GameScript, so it finds the GSs */
|
|
|
|
Game::Initialize();
|
2023-05-19 23:22:30 +02:00
|
|
|
Game::GetConsoleList(output_iterator, true);
|
2011-12-19 21:55:56 +01:00
|
|
|
Game::Uninitialize(true);
|
|
|
|
|
2007-01-18 15:08:56 +01:00
|
|
|
/* ShowInfo put output to stderr, but version information should go
|
|
|
|
* to stdout; this is the only exception */
|
2018-12-09 02:28:14 +01:00
|
|
|
#if !defined(_WIN32)
|
2023-05-21 08:04:33 +02:00
|
|
|
fmt::print("{}\n", str);
|
2007-01-18 15:08:56 +01:00
|
|
|
#else
|
2023-05-19 23:22:30 +02:00
|
|
|
ShowInfoI(str);
|
2007-01-18 15:08:56 +01:00
|
|
|
#endif
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2023-05-25 17:50:44 +02:00
|
|
|
static void WriteSavegameInfo(const std::string &name)
|
2011-10-30 14:47:45 +01:00
|
|
|
{
|
2019-01-29 01:56:28 +01:00
|
|
|
extern SaveLoadVersion _sl_version;
|
2023-05-08 19:01:06 +02:00
|
|
|
uint32_t last_ottd_rev = 0;
|
2024-03-16 23:59:32 +01:00
|
|
|
uint8_t ever_modified = 0;
|
2011-10-30 14:47:45 +01:00
|
|
|
bool removed_newgrfs = false;
|
|
|
|
|
2023-05-01 19:14:31 +02:00
|
|
|
_gamelog.Info(&last_ottd_rev, &ever_modified, &removed_newgrfs);
|
2011-10-30 14:47:45 +01:00
|
|
|
|
2023-04-27 20:57:46 +02:00
|
|
|
std::string message;
|
|
|
|
message.reserve(1024);
|
|
|
|
fmt::format_to(std::back_inserter(message), "Name: {}\n", name);
|
|
|
|
fmt::format_to(std::back_inserter(message), "Savegame ver: {}\n", _sl_version);
|
|
|
|
fmt::format_to(std::back_inserter(message), "NewGRF ver: 0x{:08X}\n", last_ottd_rev);
|
|
|
|
fmt::format_to(std::back_inserter(message), "Modified: {}\n", ever_modified);
|
2011-10-30 14:47:45 +01:00
|
|
|
|
|
|
|
if (removed_newgrfs) {
|
2023-04-27 20:57:46 +02:00
|
|
|
fmt::format_to(std::back_inserter(message), "NewGRFs have been removed\n");
|
2011-10-30 14:47:45 +01:00
|
|
|
}
|
|
|
|
|
2023-04-27 20:57:46 +02:00
|
|
|
message += "NewGRFs:\n";
|
2011-10-30 14:47:45 +01:00
|
|
|
if (_load_check_data.HasNewGrfs()) {
|
2019-04-10 23:07:06 +02:00
|
|
|
for (GRFConfig *c = _load_check_data.grfconfig; c != nullptr; c = c->next) {
|
2024-03-29 23:26:24 +01:00
|
|
|
fmt::format_to(std::back_inserter(message), "{:08X} {} {}\n", BSWAP32(c->ident.grfid),
|
2023-05-18 22:41:42 +02:00
|
|
|
FormatArrayAsHex(HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum), c->filename);
|
2011-10-30 14:47:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ShowInfo put output to stderr, but version information should go
|
|
|
|
* to stdout; this is the only exception */
|
2018-12-09 02:28:14 +01:00
|
|
|
#if !defined(_WIN32)
|
2023-05-25 17:50:44 +02:00
|
|
|
fmt::print("{}\n", message);
|
2011-10-30 14:47:45 +01:00
|
|
|
#else
|
2023-04-27 20:57:46 +02:00
|
|
|
ShowInfoI(message);
|
2011-10-30 14:47:45 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-04-29 20:19:29 +02:00
|
|
|
/**
|
|
|
|
* Extract the resolution from the given string and store
|
|
|
|
* it in the 'res' parameter.
|
|
|
|
* @param res variable to store the resolution in.
|
|
|
|
* @param s the string to decompose.
|
|
|
|
*/
|
2008-06-16 21:38:41 +02:00
|
|
|
static void ParseResolution(Dimension *res, const char *s)
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
2007-01-10 19:56:51 +01:00
|
|
|
const char *t = strchr(s, 'x');
|
2019-04-10 23:07:06 +02:00
|
|
|
if (t == nullptr) {
|
2023-04-18 19:41:29 +02:00
|
|
|
ShowInfo("Invalid resolution '{}'", s);
|
2004-08-09 19:04:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-26 13:56:14 +02:00
|
|
|
res->width = std::max(std::strtoul(s, nullptr, 0), 64UL);
|
|
|
|
res->height = std::max(std::strtoul(t + 1, nullptr, 0), 64UL);
|
2004-09-10 21:02:27 +02:00
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2007-01-14 18:17:30 +01:00
|
|
|
|
2010-08-01 21:22:34 +02:00
|
|
|
/**
|
2019-01-17 23:01:07 +01:00
|
|
|
* Uninitializes drivers, frees allocated memory, cleans pools, ...
|
2008-05-09 01:26:17 +02:00
|
|
|
* Generally, prepares the game for shutting down
|
|
|
|
*/
|
|
|
|
static void ShutdownGame()
|
2005-01-06 23:31:58 +01:00
|
|
|
{
|
2008-05-09 01:26:17 +02:00
|
|
|
IConsoleFree();
|
|
|
|
|
|
|
|
if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
|
|
|
|
|
2024-01-22 20:22:45 +01:00
|
|
|
SocialIntegration::Shutdown();
|
2008-05-09 01:26:17 +02:00
|
|
|
DriverFactoryBase::ShutdownDrivers();
|
|
|
|
|
2007-01-14 18:17:30 +01:00
|
|
|
UnInitWindowSystem();
|
|
|
|
|
2011-12-19 21:50:54 +01:00
|
|
|
/* stop the scripts */
|
2009-05-14 20:09:50 +02:00
|
|
|
AI::Uninitialize(false);
|
2011-12-19 21:55:56 +01:00
|
|
|
Game::Uninitialize(false);
|
2009-05-14 20:09:50 +02:00
|
|
|
|
2007-01-14 18:17:30 +01:00
|
|
|
/* Uninitialize variables that are allocated dynamically */
|
2023-05-01 19:14:31 +02:00
|
|
|
_gamelog.Reset();
|
2005-02-01 19:32:01 +01:00
|
|
|
|
2013-06-09 14:58:37 +02:00
|
|
|
LinkGraphSchedule::Clear();
|
2011-02-20 00:05:47 +01:00
|
|
|
PoolBase::Clean(PT_ALL);
|
2011-02-19 19:25:24 +01:00
|
|
|
|
2011-11-17 22:17:17 +01:00
|
|
|
/* No NewGRFs were loaded when it was still bootstrapping. */
|
|
|
|
if (_game_mode != GM_BOOTSTRAP) ResetNewGRFData();
|
2011-02-19 19:55:10 +01:00
|
|
|
|
2022-09-15 19:21:27 +02:00
|
|
|
UninitFontCache();
|
2005-03-09 20:48:20 +01:00
|
|
|
}
|
2005-01-06 23:31:58 +01:00
|
|
|
|
2011-08-21 14:52:24 +02:00
|
|
|
/**
|
|
|
|
* Load the introduction game.
|
|
|
|
* @param load_newgrfs Whether to load the NewGRFs or not.
|
|
|
|
*/
|
|
|
|
static void LoadIntroGame(bool load_newgrfs = true)
|
2004-12-04 18:54:56 +01:00
|
|
|
{
|
|
|
|
_game_mode = GM_MENU;
|
2007-04-05 09:49:04 +02:00
|
|
|
|
2011-08-21 14:52:24 +02:00
|
|
|
if (load_newgrfs) ResetGRFConfig(false);
|
2004-12-04 18:54:56 +01:00
|
|
|
|
2007-03-21 16:19:33 +01:00
|
|
|
/* Setup main window */
|
2005-03-09 20:48:20 +01:00
|
|
|
ResetWindowSystem();
|
2009-02-09 03:57:15 +01:00
|
|
|
SetupColoursAndInitialWindow();
|
2004-12-04 18:54:56 +01:00
|
|
|
|
2007-06-17 17:48:57 +02:00
|
|
|
/* Load the default opening screen savegame */
|
2016-09-04 18:06:50 +02:00
|
|
|
if (SaveOrLoad("opntitle.dat", SLO_LOAD, DFT_GAME_FILE, BASESET_DIR) != SL_OK) {
|
2010-01-17 23:59:24 +01:00
|
|
|
GenerateWorld(GWM_EMPTY, 64, 64); // if failed loading, make empty world.
|
2008-09-30 22:39:50 +02:00
|
|
|
SetLocalCompany(COMPANY_SPECTATOR);
|
2008-09-16 01:50:12 +02:00
|
|
|
} else {
|
2008-09-30 22:39:50 +02:00
|
|
|
SetLocalCompany(COMPANY_FIRST);
|
2005-01-07 09:07:24 +01:00
|
|
|
}
|
2004-12-04 18:54:56 +01:00
|
|
|
|
2019-04-23 22:55:27 +02:00
|
|
|
FixTitleGameZoom();
|
2009-05-06 17:06:57 +02:00
|
|
|
_pause_mode = PM_UNPAUSED;
|
2006-08-21 16:59:23 +02:00
|
|
|
_cursor.fix_at = false;
|
2004-12-04 18:54:56 +01:00
|
|
|
|
2011-11-20 12:52:11 +01:00
|
|
|
CheckForMissingGlyphs();
|
2007-12-16 19:38:19 +01:00
|
|
|
|
2018-06-24 20:06:05 +02:00
|
|
|
MusicLoop(); // ensure music is correct
|
2004-12-04 18:54:56 +01:00
|
|
|
}
|
|
|
|
|
2009-01-12 18:11:45 +01:00
|
|
|
void MakeNewgameSettingsLive()
|
|
|
|
{
|
|
|
|
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
2019-04-10 23:07:06 +02:00
|
|
|
if (_settings_game.ai_config[c] != nullptr) {
|
2009-01-12 18:11:45 +01:00
|
|
|
delete _settings_game.ai_config[c];
|
|
|
|
}
|
|
|
|
}
|
2019-04-10 23:07:06 +02:00
|
|
|
if (_settings_game.game_config != nullptr) {
|
2011-12-19 21:55:56 +01:00
|
|
|
delete _settings_game.game_config;
|
|
|
|
}
|
2009-01-12 18:11:45 +01:00
|
|
|
|
2011-07-03 12:59:25 +02:00
|
|
|
/* Copy newgame settings to active settings.
|
|
|
|
* Also initialise old settings needed for savegame conversion. */
|
2009-01-12 18:11:45 +01:00
|
|
|
_settings_game = _settings_newgame;
|
2011-07-03 12:59:25 +02:00
|
|
|
_old_vds = _settings_client.company.vehicle;
|
2009-01-12 18:11:45 +01:00
|
|
|
|
|
|
|
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
2019-04-10 23:07:06 +02:00
|
|
|
_settings_game.ai_config[c] = nullptr;
|
|
|
|
if (_settings_newgame.ai_config[c] != nullptr) {
|
2009-01-12 18:11:45 +01:00
|
|
|
_settings_game.ai_config[c] = new AIConfig(_settings_newgame.ai_config[c]);
|
|
|
|
}
|
|
|
|
}
|
2019-04-10 23:07:06 +02:00
|
|
|
_settings_game.game_config = nullptr;
|
|
|
|
if (_settings_newgame.game_config != nullptr) {
|
2011-12-19 21:55:56 +01:00
|
|
|
_settings_game.game_config = new GameConfig(_settings_newgame.game_config);
|
|
|
|
}
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2023-11-29 01:17:05 +01:00
|
|
|
void OpenBrowser(const std::string &url)
|
2011-12-11 12:47:08 +01:00
|
|
|
{
|
|
|
|
/* Make sure we only accept urls that are sure to open a browser. */
|
2024-01-17 06:30:44 +01:00
|
|
|
if (url.starts_with("http://") || url.starts_with("https://")) {
|
2023-04-28 18:25:35 +02:00
|
|
|
OSOpenBrowser(url);
|
|
|
|
}
|
2011-12-11 12:47:08 +01:00
|
|
|
}
|
|
|
|
|
2011-08-21 14:50:47 +02:00
|
|
|
/** Callback structure of statements to be executed after the NewGRF scan. */
|
|
|
|
struct AfterNewGRFScan : NewGRFScanCallback {
|
2023-08-16 15:43:31 +02:00
|
|
|
TimerGameCalendar::Year startyear = CalendarTime::INVALID_YEAR; ///< The start year.
|
2023-05-08 19:01:06 +02:00
|
|
|
uint32_t generation_seed = GENERATE_NEW_SEED; ///< Seed for the new game.
|
2021-05-02 09:18:56 +02:00
|
|
|
std::string dedicated_host; ///< Hostname for the dedicated server.
|
2023-05-08 19:01:06 +02:00
|
|
|
uint16_t dedicated_port = 0; ///< Port for the dedicated server.
|
2021-05-02 09:18:56 +02:00
|
|
|
std::string connection_string; ///< Information about the server to connect to
|
|
|
|
std::string join_server_password; ///< The password to join the server with.
|
|
|
|
bool save_config = true; ///< The save config setting.
|
2011-08-21 14:50:47 +02:00
|
|
|
|
2011-11-14 22:42:54 +01:00
|
|
|
/**
|
|
|
|
* Create a new callback.
|
|
|
|
*/
|
2021-05-02 09:18:56 +02:00
|
|
|
AfterNewGRFScan()
|
2011-08-21 14:50:47 +02:00
|
|
|
{
|
2018-10-27 08:17:40 +02:00
|
|
|
/* Visual C++ 2015 fails compiling this line (AfterNewGRFScan::generation_seed undefined symbol)
|
|
|
|
* if it's placed outside a member function, directly in the struct body. */
|
2020-12-27 11:44:22 +01:00
|
|
|
static_assert(sizeof(generation_seed) == sizeof(_settings_game.game_creation.generation_seed));
|
2011-08-21 14:50:47 +02:00
|
|
|
}
|
|
|
|
|
2023-04-13 08:23:18 +02:00
|
|
|
void OnNewGRFsScanned() override
|
2011-08-21 14:50:47 +02:00
|
|
|
{
|
|
|
|
ResetGRFConfig(false);
|
|
|
|
|
2011-11-14 22:42:54 +01:00
|
|
|
TarScanner::DoScan(TarScanner::SCENARIO);
|
|
|
|
|
|
|
|
AI::Initialize();
|
2011-12-19 21:55:56 +01:00
|
|
|
Game::Initialize();
|
2011-11-14 22:42:54 +01:00
|
|
|
|
|
|
|
/* We want the new (correct) NewGRF count to survive the loading. */
|
|
|
|
uint last_newgrf_count = _settings_client.gui.last_newgrf_count;
|
|
|
|
LoadFromConfig();
|
|
|
|
_settings_client.gui.last_newgrf_count = last_newgrf_count;
|
2011-12-04 12:18:43 +01:00
|
|
|
/* Since the default for the palette might have changed due to
|
|
|
|
* reading the configuration file, recalculate that now. */
|
|
|
|
UpdateNewGRFConfigPalette();
|
2011-11-14 22:42:54 +01:00
|
|
|
|
2011-12-19 21:55:56 +01:00
|
|
|
Game::Uninitialize(true);
|
2011-11-14 22:42:54 +01:00
|
|
|
AI::Uninitialize(true);
|
2011-08-24 19:04:18 +02:00
|
|
|
LoadFromHighScore();
|
|
|
|
LoadHotkeysFromConfig();
|
2013-05-26 21:27:22 +02:00
|
|
|
WindowDesc::LoadFromConfig();
|
2011-08-24 19:04:18 +02:00
|
|
|
|
2011-11-14 22:42:54 +01:00
|
|
|
/* We have loaded the config, so we may possibly save it. */
|
2020-12-13 16:28:06 +01:00
|
|
|
_save_config = save_config;
|
2011-11-14 22:42:54 +01:00
|
|
|
|
2022-11-07 22:26:03 +01:00
|
|
|
/* restore saved music and effects volumes */
|
2014-04-28 23:06:51 +02:00
|
|
|
MusicDriver::GetInstance()->SetVolume(_settings_client.music.music_vol);
|
2022-11-07 22:26:03 +01:00
|
|
|
SetEffectVolume(_settings_client.music.effect_vol);
|
2011-11-14 22:42:54 +01:00
|
|
|
|
2023-11-06 21:29:35 +01:00
|
|
|
if (startyear != CalendarTime::INVALID_YEAR) IConsoleSetSetting("game_creation.starting_year", startyear.base());
|
2024-01-30 18:02:35 +01:00
|
|
|
_settings_newgame.game_creation.generation_seed = generation_seed;
|
2011-08-24 19:04:18 +02:00
|
|
|
|
2021-05-04 19:32:37 +02:00
|
|
|
if (!dedicated_host.empty()) {
|
2019-04-02 21:31:33 +02:00
|
|
|
_network_bind_list.clear();
|
|
|
|
_network_bind_list.emplace_back(dedicated_host);
|
2011-08-24 19:04:18 +02:00
|
|
|
}
|
|
|
|
if (dedicated_port != 0) _settings_client.network.server_port = dedicated_port;
|
|
|
|
|
2011-08-21 14:50:47 +02:00
|
|
|
/* initialize the ingame console */
|
|
|
|
IConsoleInit();
|
|
|
|
InitializeGUI();
|
|
|
|
IConsoleCmdExec("exec scripts/autoexec.scr 0");
|
|
|
|
|
|
|
|
/* Make sure _settings is filled with _settings_newgame if we switch to a game directly */
|
|
|
|
if (_switch_mode != SM_NONE) MakeNewgameSettingsLive();
|
|
|
|
|
2021-05-02 09:18:56 +02:00
|
|
|
if (_network_available && !connection_string.empty()) {
|
2011-08-21 14:50:47 +02:00
|
|
|
LoadIntroGame();
|
|
|
|
_switch_mode = SM_NONE;
|
2021-04-29 12:09:03 +02:00
|
|
|
|
2024-03-23 19:19:12 +01:00
|
|
|
NetworkClientConnectGame(connection_string, COMPANY_NEW_COMPANY, join_server_password);
|
2011-08-21 14:50:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* After the scan we're not used anymore. */
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-08-31 11:10:11 +02:00
|
|
|
void PostMainLoop()
|
|
|
|
{
|
|
|
|
WaitTillSaved();
|
|
|
|
|
|
|
|
/* only save config if we have to */
|
|
|
|
if (_save_config) {
|
|
|
|
SaveToConfig();
|
|
|
|
SaveHotkeysToConfig();
|
|
|
|
WindowDesc::SaveToConfig();
|
|
|
|
SaveToHighScore();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset windowing system, stop drivers, free used memory, ... */
|
|
|
|
ShutdownGame();
|
|
|
|
}
|
|
|
|
|
2019-03-04 19:21:13 +01:00
|
|
|
#if defined(UNIX)
|
2007-03-07 12:47:46 +01:00
|
|
|
extern void DedicatedFork();
|
2005-08-06 16:58:06 +02:00
|
|
|
#endif
|
2004-12-18 15:19:21 +01:00
|
|
|
|
2024-04-10 21:49:39 +02:00
|
|
|
/**
|
|
|
|
* Create all the options that OpenTTD supports. Each option is
|
|
|
|
* always a single character with no, an optional or a required value.
|
|
|
|
* @return The available options.
|
|
|
|
*/
|
|
|
|
static std::vector<OptionData> CreateOptions()
|
|
|
|
{
|
|
|
|
std::vector<OptionData> options;
|
|
|
|
/* Options that require a parameter. */
|
2024-03-23 19:19:12 +01:00
|
|
|
for (char c : "GIMSbcmnpqrstv") options.push_back({ .type = ODF_HAS_VALUE, .id = c, .shortname = c });
|
2019-03-04 19:21:13 +01:00
|
|
|
#if !defined(_WIN32)
|
2024-04-10 21:49:39 +02:00
|
|
|
options.push_back({ .type = ODF_HAS_VALUE, .id = 'f', .shortname = 'f' });
|
2011-02-18 21:28:25 +01:00
|
|
|
#endif
|
2024-04-10 21:49:39 +02:00
|
|
|
|
|
|
|
/* Options with an optional parameter. */
|
|
|
|
for (char c : "Ddg") options.push_back({ .type = ODF_OPTIONAL_VALUE, .id = c, .shortname = c });
|
|
|
|
|
|
|
|
/* Options without a parameter. */
|
|
|
|
for (char c : "QXehx") options.push_back({ .type = ODF_NO_VALUE, .id = c, .shortname = c });
|
|
|
|
return options;
|
|
|
|
}
|
2011-02-18 21:28:25 +01:00
|
|
|
|
2013-06-28 23:11:35 +02:00
|
|
|
/**
|
|
|
|
* Main entry point for this lovely game.
|
2024-04-11 13:25:40 +02:00
|
|
|
* @param arguments The command line arguments passed to the application.
|
2013-06-28 23:11:35 +02:00
|
|
|
* @return 0 when there is no error.
|
|
|
|
*/
|
2024-04-11 13:25:40 +02:00
|
|
|
int openttd_main(std::span<char * const> arguments)
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
2024-03-16 08:58:56 +01:00
|
|
|
_game_session_stats.start_time = std::chrono::steady_clock::now();
|
|
|
|
_game_session_stats.savegame_size = std::nullopt;
|
2024-02-27 02:41:59 +01:00
|
|
|
|
2020-05-17 23:32:08 +02:00
|
|
|
std::string musicdriver;
|
|
|
|
std::string sounddriver;
|
|
|
|
std::string videodriver;
|
|
|
|
std::string blitter;
|
2020-05-17 23:32:06 +02:00
|
|
|
std::string graphics_set;
|
|
|
|
std::string sounds_set;
|
|
|
|
std::string music_set;
|
2008-06-16 21:38:41 +02:00
|
|
|
Dimension resolution = {0, 0};
|
2024-04-20 12:20:49 +02:00
|
|
|
std::unique_ptr<AfterNewGRFScan> scanner = std::make_unique<AfterNewGRFScan>();
|
2006-02-21 18:29:53 +01:00
|
|
|
bool dedicated = false;
|
2021-06-10 23:13:34 +02:00
|
|
|
bool only_local_path = false;
|
2010-07-19 19:46:53 +02:00
|
|
|
|
|
|
|
extern bool _dedicated_forks;
|
|
|
|
_dedicated_forks = false;
|
2005-02-23 10:13:12 +01:00
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
_game_mode = GM_MENU;
|
|
|
|
_switch_mode = SM_MENU;
|
|
|
|
|
2024-04-10 21:49:39 +02:00
|
|
|
auto options = CreateOptions();
|
2024-04-11 13:25:40 +02:00
|
|
|
GetOptData mgo(arguments.subspan(1), options);
|
2013-11-24 16:21:38 +01:00
|
|
|
int ret = 0;
|
2007-01-10 19:56:51 +01:00
|
|
|
|
2011-02-18 21:28:25 +01:00
|
|
|
int i;
|
2011-02-18 21:14:30 +01:00
|
|
|
while ((i = mgo.GetOpt()) != -1) {
|
2006-02-01 07:32:03 +01:00
|
|
|
switch (i) {
|
2020-05-17 23:32:06 +02:00
|
|
|
case 'I': graphics_set = mgo.opt; break;
|
|
|
|
case 'S': sounds_set = mgo.opt; break;
|
|
|
|
case 'M': music_set = mgo.opt; break;
|
2020-05-17 23:32:08 +02:00
|
|
|
case 'm': musicdriver = mgo.opt; break;
|
|
|
|
case 's': sounddriver = mgo.opt; break;
|
|
|
|
case 'v': videodriver = mgo.opt; break;
|
|
|
|
case 'b': blitter = mgo.opt; break;
|
2006-02-21 18:29:53 +01:00
|
|
|
case 'D':
|
2020-05-17 23:32:08 +02:00
|
|
|
musicdriver = "null";
|
|
|
|
sounddriver = "null";
|
|
|
|
videodriver = "dedicated";
|
|
|
|
blitter = "null";
|
2006-02-21 18:29:53 +01:00
|
|
|
dedicated = true;
|
2023-04-18 19:41:29 +02:00
|
|
|
SetDebugString("net=4", ShowInfoI);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (mgo.opt != nullptr) {
|
2021-05-04 19:32:37 +02:00
|
|
|
scanner->dedicated_host = ParseFullConnectionString(mgo.opt, scanner->dedicated_port);
|
2007-01-03 19:29:15 +01:00
|
|
|
}
|
2006-02-21 18:29:53 +01:00
|
|
|
break;
|
|
|
|
case 'f': _dedicated_forks = true; break;
|
|
|
|
case 'n':
|
2023-07-25 22:27:23 +02:00
|
|
|
scanner->connection_string = mgo.opt; // host:port#company parameter
|
2006-02-21 18:29:53 +01:00
|
|
|
break;
|
2009-06-10 21:00:34 +02:00
|
|
|
case 'p':
|
2011-08-24 19:04:18 +02:00
|
|
|
scanner->join_server_password = mgo.opt;
|
2009-06-10 21:00:34 +02:00
|
|
|
break;
|
2008-06-16 21:38:41 +02:00
|
|
|
case 'r': ParseResolution(&resolution, mgo.opt); break;
|
2011-08-24 19:04:18 +02:00
|
|
|
case 't': scanner->startyear = atoi(mgo.opt); break;
|
2004-08-09 19:04:08 +02:00
|
|
|
case 'd': {
|
2018-12-09 02:28:14 +01:00
|
|
|
#if defined(_WIN32)
|
2004-08-09 19:04:08 +02:00
|
|
|
CreateConsole();
|
|
|
|
#endif
|
2023-04-18 19:41:29 +02:00
|
|
|
if (mgo.opt != nullptr) SetDebugString(mgo.opt, ShowInfoI);
|
2010-08-01 20:53:30 +02:00
|
|
|
break;
|
|
|
|
}
|
2024-01-22 23:35:25 +01:00
|
|
|
case 'e':
|
|
|
|
/* Allow for '-e' before or after '-g'. */
|
|
|
|
switch (_switch_mode) {
|
|
|
|
case SM_MENU: _switch_mode = SM_EDITOR; break;
|
|
|
|
case SM_LOAD_GAME: _switch_mode = SM_LOAD_SCENARIO; break;
|
|
|
|
case SM_START_HEIGHTMAP: _switch_mode = SM_LOAD_HEIGHTMAP; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
2004-09-10 21:02:27 +02:00
|
|
|
case 'g':
|
2019-04-10 23:07:06 +02:00
|
|
|
if (mgo.opt != nullptr) {
|
2023-04-16 21:44:53 +02:00
|
|
|
_file_to_saveload.name = mgo.opt;
|
2024-01-22 23:35:25 +01:00
|
|
|
|
|
|
|
std::string extension = std::filesystem::path(_file_to_saveload.name).extension().string();
|
|
|
|
auto [ft, _] = FiosGetSavegameListCallback(SLO_LOAD, _file_to_saveload.name, extension);
|
|
|
|
if (ft == FIOS_TYPE_INVALID) {
|
|
|
|
std::tie(ft, _) = FiosGetScenarioListCallback(SLO_LOAD, _file_to_saveload.name, extension);
|
|
|
|
}
|
|
|
|
if (ft == FIOS_TYPE_INVALID) {
|
|
|
|
std::tie(ft, _) = FiosGetHeightmapListCallback(SLO_LOAD, _file_to_saveload.name, extension);
|
2008-07-28 17:31:11 +02:00
|
|
|
}
|
|
|
|
|
2024-01-22 23:35:25 +01:00
|
|
|
/* Allow for '-e' before or after '-g'. */
|
|
|
|
switch (GetAbstractFileType(ft)) {
|
|
|
|
case FT_SAVEGAME: _switch_mode = (_switch_mode == SM_EDITOR ? SM_LOAD_SCENARIO : SM_LOAD_GAME); break;
|
|
|
|
case FT_SCENARIO: _switch_mode = (_switch_mode == SM_EDITOR ? SM_LOAD_SCENARIO : SM_LOAD_GAME); break;
|
|
|
|
case FT_HEIGHTMAP: _switch_mode = (_switch_mode == SM_EDITOR ? SM_LOAD_HEIGHTMAP : SM_START_HEIGHTMAP); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_file_to_saveload.SetMode(SLO_LOAD, GetAbstractFileType(ft), GetDetailedFileType(ft));
|
2008-07-28 17:31:11 +02:00
|
|
|
break;
|
2006-06-27 23:25:53 +02:00
|
|
|
}
|
2008-07-28 17:31:11 +02:00
|
|
|
|
|
|
|
_switch_mode = SM_NEWGAME;
|
2008-09-28 00:19:34 +02:00
|
|
|
/* Give a random map if no seed has been given */
|
2011-08-24 19:04:18 +02:00
|
|
|
if (scanner->generation_seed == GENERATE_NEW_SEED) {
|
|
|
|
scanner->generation_seed = InteractiveRandom();
|
2008-09-28 00:19:34 +02:00
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
break;
|
2011-10-30 14:47:45 +01:00
|
|
|
case 'q': {
|
2024-04-11 13:25:40 +02:00
|
|
|
DeterminePaths(arguments[0], only_local_path);
|
2013-11-24 16:21:38 +01:00
|
|
|
if (StrEmpty(mgo.opt)) {
|
|
|
|
ret = 1;
|
2020-05-17 23:32:10 +02:00
|
|
|
return ret;
|
2013-11-24 16:21:38 +01:00
|
|
|
}
|
|
|
|
|
2024-04-04 15:39:15 +02:00
|
|
|
std::string extension = std::filesystem::path(_file_to_saveload.name).extension().string();
|
|
|
|
auto [_, title] = FiosGetSavegameListCallback(SLO_LOAD, mgo.opt, extension);
|
2011-10-30 14:47:45 +01:00
|
|
|
|
|
|
|
_load_check_data.Clear();
|
2016-09-04 18:06:50 +02:00
|
|
|
SaveOrLoadResult res = SaveOrLoad(mgo.opt, SLO_CHECK, DFT_GAME_FILE, SAVE_DIR, false);
|
2011-10-30 14:47:45 +01:00
|
|
|
if (res != SL_OK || _load_check_data.HasErrors()) {
|
2023-05-21 08:13:28 +02:00
|
|
|
fmt::print(stderr, "Failed to open savegame\n");
|
2011-10-30 14:47:45 +01:00
|
|
|
if (_load_check_data.HasErrors()) {
|
2021-07-16 18:10:43 +02:00
|
|
|
InitializeLanguagePacks(); // A language pack is needed for GetString()
|
2023-04-30 21:46:49 +02:00
|
|
|
SetDParamStr(0, _load_check_data.error_msg);
|
2023-05-21 08:13:28 +02:00
|
|
|
fmt::print(stderr, "{}\n", GetString(_load_check_data.error));
|
2011-10-30 14:47:45 +01:00
|
|
|
}
|
2020-05-17 23:32:10 +02:00
|
|
|
return ret;
|
2011-10-30 14:47:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
WriteSavegameInfo(title);
|
2020-05-17 23:32:10 +02:00
|
|
|
return ret;
|
2011-10-30 14:47:45 +01:00
|
|
|
}
|
2022-05-06 10:35:47 +02:00
|
|
|
case 'Q': {
|
|
|
|
extern int _skip_all_newgrf_scanning;
|
|
|
|
_skip_all_newgrf_scanning += 1;
|
|
|
|
break;
|
|
|
|
}
|
2023-04-26 13:56:14 +02:00
|
|
|
case 'G': scanner->generation_seed = std::strtoul(mgo.opt, nullptr, 10); break;
|
2020-12-06 21:11:42 +01:00
|
|
|
case 'c': _config_file = mgo.opt; break;
|
2011-11-14 22:42:54 +01:00
|
|
|
case 'x': scanner->save_config = false; break;
|
2021-06-10 23:13:34 +02:00
|
|
|
case 'X': only_local_path = true; break;
|
2005-07-09 00:25:24 +02:00
|
|
|
case 'h':
|
2011-02-18 21:28:25 +01:00
|
|
|
i = -2; // Force printing of help.
|
|
|
|
break;
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
2011-02-18 21:28:25 +01:00
|
|
|
if (i == -2) break;
|
|
|
|
}
|
|
|
|
|
2024-04-10 22:21:56 +02:00
|
|
|
if (i == -2 || !mgo.arguments.empty()) {
|
2021-05-08 12:02:30 +02:00
|
|
|
/* Either the user typed '-h', they made an error, or they added unrecognized command line arguments.
|
2011-02-18 21:28:25 +01:00
|
|
|
* In all cases, print the help, and exit.
|
|
|
|
*
|
|
|
|
* The next two functions are needed to list the graphics sets. We can't do them earlier
|
|
|
|
* because then we cannot show it on the debug console as that hasn't been configured yet. */
|
2024-04-11 13:25:40 +02:00
|
|
|
DeterminePaths(arguments[0], only_local_path);
|
2011-11-14 22:40:39 +01:00
|
|
|
TarScanner::DoScan(TarScanner::BASESET);
|
2011-02-18 21:28:25 +01:00
|
|
|
BaseGraphics::FindSets();
|
|
|
|
BaseSounds::FindSets();
|
|
|
|
BaseMusic::FindSets();
|
|
|
|
ShowHelp();
|
2020-05-17 23:32:10 +02:00
|
|
|
return ret;
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2024-04-11 13:25:40 +02:00
|
|
|
DeterminePaths(arguments[0], only_local_path);
|
2011-11-14 22:42:54 +01:00
|
|
|
TarScanner::DoScan(TarScanner::BASESET);
|
2004-12-18 15:19:21 +01:00
|
|
|
|
2021-06-12 09:10:17 +02:00
|
|
|
if (dedicated) Debug(net, 3, "Starting dedicated server, version {}", _openttd_revision);
|
2011-08-24 19:04:18 +02:00
|
|
|
if (_dedicated_forks && !dedicated) _dedicated_forks = false;
|
|
|
|
|
2019-03-04 19:21:13 +01:00
|
|
|
#if defined(UNIX)
|
2007-03-21 16:19:33 +01:00
|
|
|
/* We must fork here, or we'll end up without some resources we need (like sockets) */
|
2010-07-19 17:44:49 +02:00
|
|
|
if (_dedicated_forks) DedicatedFork();
|
2004-12-18 15:19:21 +01:00
|
|
|
#endif
|
|
|
|
|
2011-11-14 22:42:54 +01:00
|
|
|
LoadFromConfig(true);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2011-11-14 22:42:54 +01:00
|
|
|
if (resolution.width != 0) _cur_resolution = resolution;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2021-01-14 21:53:06 +01:00
|
|
|
/* Limit width times height times bytes per pixel to fit a 32 bit
|
|
|
|
* integer, This way all internal drawing routines work correctly.
|
|
|
|
* A resolution that has one component as 0 is treated as a marker to
|
|
|
|
* auto-detect a good window size. */
|
|
|
|
_cur_resolution.width = std::min(_cur_resolution.width, UINT16_MAX / 2u);
|
|
|
|
_cur_resolution.height = std::min(_cur_resolution.height, UINT16_MAX / 2u);
|
2007-06-13 16:57:42 +02:00
|
|
|
|
2011-11-06 10:37:26 +01:00
|
|
|
/* Assume the cursor starts within the game as not all video drivers
|
|
|
|
* get an event that the cursor is within the window when it is opened.
|
|
|
|
* Saying the cursor is there makes no visible difference as it would
|
|
|
|
* just be out of the bounds of the window. */
|
|
|
|
_cursor.in_window = true;
|
|
|
|
|
2007-03-21 16:19:33 +01:00
|
|
|
/* enumerate language files */
|
2004-08-09 19:04:08 +02:00
|
|
|
InitializeLanguagePacks();
|
|
|
|
|
2022-09-15 19:21:27 +02:00
|
|
|
/* Initialize the font cache */
|
|
|
|
InitFontCache(false);
|
2006-11-16 23:05:33 +01:00
|
|
|
|
2009-09-13 21:15:59 +02:00
|
|
|
/* This must be done early, since functions use the SetWindowDirty* calls */
|
2004-08-25 12:17:39 +02:00
|
|
|
InitWindowSystem();
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2011-11-17 22:21:45 +01:00
|
|
|
BaseGraphics::FindSets();
|
2023-10-02 13:29:32 +02:00
|
|
|
bool valid_graphics_set;
|
|
|
|
if (!graphics_set.empty()) {
|
2023-10-02 14:17:32 +02:00
|
|
|
valid_graphics_set = BaseGraphics::SetSetByName(graphics_set);
|
|
|
|
} else if (BaseGraphics::ini_data.shortname != 0) {
|
|
|
|
graphics_set = BaseGraphics::ini_data.name;
|
|
|
|
valid_graphics_set = BaseGraphics::SetSetByShortname(BaseGraphics::ini_data.shortname);
|
2023-10-02 14:37:43 +02:00
|
|
|
if (valid_graphics_set && !BaseGraphics::ini_data.extra_params.empty()) {
|
|
|
|
GRFConfig &extra_cfg = BaseGraphics::GetUsedSet()->GetOrCreateExtraConfig();
|
|
|
|
if (extra_cfg.IsCompatible(BaseGraphics::ini_data.extra_version)) {
|
|
|
|
extra_cfg.SetParams(BaseGraphics::ini_data.extra_params);
|
|
|
|
}
|
|
|
|
}
|
2023-10-02 13:29:32 +02:00
|
|
|
} else if (!BaseGraphics::ini_data.name.empty()) {
|
|
|
|
graphics_set = BaseGraphics::ini_data.name;
|
2023-10-02 14:17:32 +02:00
|
|
|
valid_graphics_set = BaseGraphics::SetSetByName(BaseGraphics::ini_data.name);
|
2023-10-02 13:29:32 +02:00
|
|
|
} else {
|
|
|
|
valid_graphics_set = true;
|
|
|
|
BaseGraphics::SetSet(nullptr); // ignore error, continue to bootstrap GUI
|
|
|
|
}
|
|
|
|
if (!valid_graphics_set) {
|
|
|
|
BaseGraphics::SetSet(nullptr);
|
|
|
|
|
|
|
|
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_GRAPHICS_NOT_FOUND);
|
|
|
|
msg.SetDParamStr(0, graphics_set);
|
|
|
|
ScheduleErrorMessage(msg);
|
2008-08-24 10:41:38 +02:00
|
|
|
}
|
|
|
|
|
2006-11-28 15:32:24 +01:00
|
|
|
/* Initialize game palette */
|
|
|
|
GfxInitPalettes();
|
|
|
|
|
2021-06-12 09:10:17 +02:00
|
|
|
Debug(misc, 1, "Loading blitter...");
|
2020-05-17 23:32:08 +02:00
|
|
|
if (blitter.empty() && !_ini_blitter.empty()) blitter = _ini_blitter;
|
|
|
|
_blitter_autodetected = blitter.empty();
|
2014-04-27 14:15:14 +02:00
|
|
|
/* Activate the initial blitter.
|
|
|
|
* This is only some initial guess, after NewGRFs have been loaded SwitchNewGRFBlitter may switch to a different one.
|
|
|
|
* - Never guess anything, if the user specified a blitter. (_blitter_autodetected)
|
|
|
|
* - Use 32bpp blitter if baseset or 8bpp-support settings says so.
|
|
|
|
* - Use 8bpp blitter otherwise.
|
|
|
|
*/
|
|
|
|
if (!_blitter_autodetected ||
|
2019-04-10 23:07:06 +02:00
|
|
|
(_support8bpp != S8BPP_NONE && (BaseGraphics::GetUsedSet() == nullptr || BaseGraphics::GetUsedSet()->blitter == BLT_8BPP)) ||
|
|
|
|
BlitterFactory::SelectBlitter("32bpp-anim") == nullptr) {
|
|
|
|
if (BlitterFactory::SelectBlitter(blitter) == nullptr) {
|
2020-05-17 23:32:08 +02:00
|
|
|
blitter.empty() ?
|
2023-04-19 22:47:36 +02:00
|
|
|
UserError("Failed to autoprobe blitter") :
|
2023-06-15 19:15:08 +02:00
|
|
|
UserError("Failed to select requested blitter '{}'; does it exist?", blitter);
|
2011-10-04 23:35:47 +02:00
|
|
|
}
|
2010-07-24 12:14:39 +02:00
|
|
|
}
|
2007-07-05 14:23:54 +02:00
|
|
|
|
2020-05-17 23:32:08 +02:00
|
|
|
if (videodriver.empty() && !_ini_videodriver.empty()) videodriver = _ini_videodriver;
|
2014-04-28 23:06:51 +02:00
|
|
|
DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
|
2007-07-05 14:23:54 +02:00
|
|
|
|
2014-01-02 17:48:16 +01:00
|
|
|
InitializeSpriteSorter();
|
|
|
|
|
2007-05-20 01:52:04 +02:00
|
|
|
/* Initialize the zoom level of the screen to normal */
|
2024-04-04 19:49:37 +02:00
|
|
|
_screen.zoom = ZOOM_LVL_MIN;
|
2021-04-20 12:49:20 +02:00
|
|
|
|
|
|
|
/* The video driver is now selected, now initialise GUI zoom */
|
|
|
|
AdjustGUIZoom(false);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2024-01-22 20:22:45 +01:00
|
|
|
SocialIntegration::Initialize();
|
2011-11-17 22:17:17 +01:00
|
|
|
NetworkStartUp(); // initialize network-core
|
|
|
|
|
2013-11-24 17:21:19 +01:00
|
|
|
if (!HandleBootstrap()) {
|
|
|
|
ShutdownGame();
|
2020-05-17 23:32:10 +02:00
|
|
|
return ret;
|
2013-11-24 17:21:19 +01:00
|
|
|
}
|
2011-11-17 22:21:45 +01:00
|
|
|
|
2014-04-28 23:06:51 +02:00
|
|
|
VideoDriver::GetInstance()->ClaimMousePointer();
|
2011-11-17 22:21:45 +01:00
|
|
|
|
|
|
|
/* initialize screenshot formats */
|
|
|
|
InitializeScreenshotFormats();
|
|
|
|
|
|
|
|
BaseSounds::FindSets();
|
2020-05-17 23:32:06 +02:00
|
|
|
if (sounds_set.empty() && !BaseSounds::ini_set.empty()) sounds_set = BaseSounds::ini_set;
|
2023-10-02 14:17:32 +02:00
|
|
|
if (!BaseSounds::SetSetByName(sounds_set)) {
|
2020-05-17 23:32:06 +02:00
|
|
|
if (sounds_set.empty() || !BaseSounds::SetSet({})) {
|
2023-04-19 22:47:36 +02:00
|
|
|
UserError("Failed to find a sounds set. Please acquire a sounds set for OpenTTD. See section 1.4 of README.md.");
|
2012-07-08 20:41:50 +02:00
|
|
|
} else {
|
|
|
|
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_SOUNDS_NOT_FOUND);
|
2021-05-30 11:40:54 +02:00
|
|
|
msg.SetDParamStr(0, sounds_set);
|
2012-07-08 20:41:50 +02:00
|
|
|
ScheduleErrorMessage(msg);
|
|
|
|
}
|
2011-11-17 22:21:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BaseMusic::FindSets();
|
2020-05-17 23:32:06 +02:00
|
|
|
if (music_set.empty() && !BaseMusic::ini_set.empty()) music_set = BaseMusic::ini_set;
|
2023-10-02 14:17:32 +02:00
|
|
|
if (!BaseMusic::SetSetByName(music_set)) {
|
2020-05-17 23:32:06 +02:00
|
|
|
if (music_set.empty() || !BaseMusic::SetSet({})) {
|
2023-04-19 22:47:36 +02:00
|
|
|
UserError("Failed to find a music set. Please acquire a music set for OpenTTD. See section 1.4 of README.md.");
|
2012-07-08 20:41:50 +02:00
|
|
|
} else {
|
|
|
|
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_MUSIC_NOT_FOUND);
|
2021-05-30 11:40:54 +02:00
|
|
|
msg.SetDParamStr(0, music_set);
|
2012-07-08 20:41:50 +02:00
|
|
|
ScheduleErrorMessage(msg);
|
|
|
|
}
|
2011-11-17 22:21:45 +01:00
|
|
|
}
|
|
|
|
|
2020-05-17 23:32:08 +02:00
|
|
|
if (sounddriver.empty() && !_ini_sounddriver.empty()) sounddriver = _ini_sounddriver;
|
2014-04-28 23:06:51 +02:00
|
|
|
DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
|
2011-11-17 22:21:45 +01:00
|
|
|
|
2020-05-17 23:32:08 +02:00
|
|
|
if (musicdriver.empty() && !_ini_musicdriver.empty()) musicdriver = _ini_musicdriver;
|
2014-04-28 23:06:51 +02:00
|
|
|
DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
|
2011-11-17 22:21:45 +01:00
|
|
|
|
2010-01-17 23:59:24 +01:00
|
|
|
GenerateWorld(GWM_EMPTY, 64, 64); // Make the viewport initialization happy
|
2011-08-21 14:52:24 +02:00
|
|
|
LoadIntroGame(false);
|
|
|
|
|
2013-11-25 10:12:49 +01:00
|
|
|
/* ScanNewGRFFiles now has control over the scanner. */
|
2021-03-09 14:53:51 +01:00
|
|
|
RequestNewGRFScan(scanner.release());
|
2004-12-04 18:54:56 +01:00
|
|
|
|
2014-04-28 23:06:51 +02:00
|
|
|
VideoDriver::GetInstance()->MainLoop();
|
2004-08-25 12:17:39 +02:00
|
|
|
|
2023-08-31 11:10:11 +02:00
|
|
|
PostMainLoop();
|
2013-11-24 16:21:38 +01:00
|
|
|
return ret;
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2007-03-07 12:47:46 +01:00
|
|
|
void HandleExitGameRequest()
|
2006-09-04 19:30:30 +02:00
|
|
|
{
|
2011-11-17 22:17:17 +01:00
|
|
|
if (_game_mode == GM_MENU || _game_mode == GM_BOOTSTRAP) { // do not ask to quit on the main screen
|
2006-09-04 19:30:30 +02:00
|
|
|
_exit_game = true;
|
2008-05-29 17:13:28 +02:00
|
|
|
} else if (_settings_client.gui.autosave_on_exit) {
|
2006-09-04 19:30:30 +02:00
|
|
|
DoExitSave();
|
2023-04-25 19:43:45 +02:00
|
|
|
_survey.Transmit(NetworkSurveyHandler::Reason::EXIT, true);
|
2006-09-04 19:30:30 +02:00
|
|
|
_exit_game = true;
|
|
|
|
} else {
|
|
|
|
AskExitGame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-09 21:32:31 +02:00
|
|
|
/**
|
|
|
|
* Triggers everything required to set up a saved scenario for a new game.
|
|
|
|
*/
|
|
|
|
static void OnStartScenario()
|
|
|
|
{
|
|
|
|
/* Reset engine pool to simplify changing engine NewGRFs in scenario editor. */
|
|
|
|
EngineOverrideManager::ResetToCurrentNewGRFConfig();
|
2022-06-09 21:36:55 +02:00
|
|
|
|
|
|
|
/* Make sure all industries were built "this year", to avoid too early closures. (#9918) */
|
|
|
|
for (Industry *i : Industry::Iterate()) {
|
2024-01-22 15:04:34 +01:00
|
|
|
i->last_prod_year = TimerGameEconomy::year;
|
2022-06-09 21:36:55 +02:00
|
|
|
}
|
2022-06-09 21:32:31 +02:00
|
|
|
}
|
|
|
|
|
2021-05-05 19:21:12 +02:00
|
|
|
/**
|
|
|
|
* Triggers everything that should be triggered when starting a game.
|
|
|
|
* @param dedicated_server Whether this is a dedicated server or not.
|
|
|
|
*/
|
|
|
|
static void OnStartGame(bool dedicated_server)
|
|
|
|
{
|
2022-01-20 00:46:51 +01:00
|
|
|
/* Update the local company for a loaded game. It is either the first available company
|
|
|
|
* or in the case of a dedicated server, a spectator */
|
|
|
|
SetLocalCompany(dedicated_server ? COMPANY_SPECTATOR : GetFirstPlayableCompanyID());
|
2021-05-05 19:21:12 +02:00
|
|
|
|
2024-05-05 19:53:21 +02:00
|
|
|
NetworkOnGameStart();
|
|
|
|
|
2021-05-05 19:21:12 +02:00
|
|
|
/* Execute the game-start script */
|
|
|
|
IConsoleCmdExec("exec scripts/game_start.scr 0");
|
|
|
|
}
|
|
|
|
|
2007-03-07 12:47:46 +01:00
|
|
|
static void MakeNewGameDone()
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
2008-07-03 20:00:36 +02:00
|
|
|
SettingsDisableElrail(_settings_game.vehicle.disable_elrails);
|
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 12:00:30 +02:00
|
|
|
/* In a dedicated server, the server does not play */
|
2014-04-28 23:06:51 +02:00
|
|
|
if (!VideoDriver::GetInstance()->HasGUI()) {
|
2021-05-05 19:21:12 +02:00
|
|
|
OnStartGame(true);
|
2021-11-23 01:05:58 +01:00
|
|
|
if (_settings_client.gui.pause_on_newgame) Command<CMD_PAUSE>::Post(PM_PAUSED_NORMAL, true);
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 12:00:30 +02:00
|
|
|
return;
|
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-09-30 22:39:50 +02:00
|
|
|
/* Create a single company */
|
|
|
|
DoStartupNewCompany(false);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-05-17 01:34:14 +02:00
|
|
|
Company *c = Company::Get(COMPANY_FIRST);
|
2009-05-16 01:55:06 +02:00
|
|
|
c->settings = _settings_client.company;
|
2009-05-13 00:32:22 +02:00
|
|
|
|
2019-01-10 10:45:38 +01:00
|
|
|
/* Overwrite color from settings if needed
|
|
|
|
* COLOUR_END corresponds to Random colour */
|
2023-06-24 22:50:04 +02:00
|
|
|
|
2019-01-10 10:45:38 +01:00
|
|
|
if (_settings_client.gui.starting_colour != COLOUR_END) {
|
|
|
|
c->colour = _settings_client.gui.starting_colour;
|
|
|
|
ResetCompanyLivery(c);
|
2024-01-21 14:23:04 +01:00
|
|
|
_company_colours[c->index] = c->colour;
|
2019-01-10 10:45:38 +01:00
|
|
|
}
|
|
|
|
|
2023-06-24 22:50:04 +02:00
|
|
|
if (_settings_client.gui.starting_colour_secondary != COLOUR_END && HasBit(_loaded_newgrf_features.used_liveries, LS_DEFAULT)) {
|
2024-01-21 14:23:04 +01:00
|
|
|
Command<CMD_SET_COMPANY_COLOUR>::Post(LS_DEFAULT, false, _settings_client.gui.starting_colour_secondary);
|
2023-06-24 22:50:04 +02:00
|
|
|
}
|
|
|
|
|
2021-05-05 19:21:12 +02:00
|
|
|
OnStartGame(false);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-04-03 23:54:31 +02:00
|
|
|
InitializeRailGUI();
|
2019-04-06 08:46:15 +02:00
|
|
|
InitializeRoadGUI();
|
2006-11-17 20:31:44 +01:00
|
|
|
|
2021-11-23 01:05:58 +01:00
|
|
|
if (_settings_client.gui.pause_on_newgame) Command<CMD_PAUSE>::Post(PM_PAUSED_NORMAL, true);
|
2010-06-05 17:22:46 +02:00
|
|
|
|
2013-07-02 20:57:26 +02:00
|
|
|
CheckEngines();
|
2014-08-13 21:31:45 +02:00
|
|
|
CheckIndustries();
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 12:00:30 +02:00
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-08-07 00:00:32 +02:00
|
|
|
static void MakeNewGame(bool from_heightmap, bool reset_settings)
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 12:00:30 +02:00
|
|
|
{
|
|
|
|
_game_mode = GM_NORMAL;
|
2021-01-08 16:21:54 +01:00
|
|
|
if (!from_heightmap) {
|
|
|
|
/* "reload" command needs to know what mode we were in. */
|
|
|
|
_file_to_saveload.SetMode(SLO_INVALID, FT_INVALID, DFT_INVALID);
|
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2006-12-10 13:12:26 +01:00
|
|
|
ResetGRFConfig(true);
|
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 12:00:30 +02:00
|
|
|
GenerateWorldSetCallback(&MakeNewGameDone);
|
2010-01-17 23:59:24 +01:00
|
|
|
GenerateWorld(from_heightmap ? GWM_HEIGHTMAP : GWM_NEWGAME, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y, reset_settings);
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 12:00:30 +02:00
|
|
|
}
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2007-03-07 12:47:46 +01:00
|
|
|
static void MakeNewEditorWorldDone()
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 12:00:30 +02:00
|
|
|
{
|
2008-09-30 22:39:50 +02:00
|
|
|
SetLocalCompany(OWNER_NONE);
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2007-03-07 12:47:46 +01:00
|
|
|
static void MakeNewEditorWorld()
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
|
|
|
_game_mode = GM_EDITOR;
|
2021-01-08 16:21:54 +01:00
|
|
|
/* "reload" command needs to know what mode we were in. */
|
|
|
|
_file_to_saveload.SetMode(SLO_INVALID, FT_INVALID, DFT_INVALID);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2006-12-10 13:12:26 +01:00
|
|
|
ResetGRFConfig(true);
|
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 12:00:30 +02:00
|
|
|
GenerateWorldSetCallback(&MakeNewEditorWorldDone);
|
2010-01-17 23:59:24 +01:00
|
|
|
GenerateWorld(GWM_EMPTY, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2010-06-30 22:20:15 +02:00
|
|
|
/**
|
|
|
|
* Load the specified savegame but on error do different things.
|
|
|
|
* If loading fails due to corrupt savegame, bad version, etc. go back to
|
|
|
|
* a previous correct state. In the menu for example load the intro game again.
|
2010-12-05 15:43:10 +01:00
|
|
|
* @param filename file to be loaded
|
2018-10-28 03:17:36 +01:00
|
|
|
* @param fop mode of loading, always SLO_LOAD
|
|
|
|
* @param newgm switch to this mode of loading fails due to some unknown error
|
2010-06-30 22:20:15 +02:00
|
|
|
* @param subdir default directory to look for filename, set to 0 if not needed
|
2019-04-10 23:07:06 +02:00
|
|
|
* @param lf Load filter to use, if nullptr: use filename + subdir.
|
2010-06-30 22:20:15 +02:00
|
|
|
*/
|
2024-02-02 18:13:38 +01:00
|
|
|
bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, std::shared_ptr<LoadFilter> lf = nullptr)
|
2010-06-30 22:20:15 +02:00
|
|
|
{
|
2016-09-04 18:06:50 +02:00
|
|
|
assert(fop == SLO_LOAD);
|
2019-04-10 23:07:06 +02:00
|
|
|
assert(dft == DFT_GAME_FILE || (lf == nullptr && dft == DFT_OLD_GAME_FILE));
|
2010-06-30 22:20:15 +02:00
|
|
|
GameMode ogm = _game_mode;
|
|
|
|
|
|
|
|
_game_mode = newgm;
|
2010-12-05 15:43:10 +01:00
|
|
|
|
2023-03-15 20:59:58 +01:00
|
|
|
SaveOrLoadResult result = (lf == nullptr) ? SaveOrLoad(filename, fop, dft, subdir) : LoadWithFilter(lf);
|
|
|
|
if (result == SL_OK) return true;
|
|
|
|
|
|
|
|
if (_network_dedicated && ogm == GM_MENU) {
|
|
|
|
/*
|
|
|
|
* If we are a dedicated server *and* we just were in the menu, then we
|
|
|
|
* are loading the first savegame. If that fails, not starting the
|
|
|
|
* server is a better reaction than starting the server with a newly
|
|
|
|
* generated map as it is quite likely to be started from a script.
|
|
|
|
*/
|
|
|
|
Debug(net, 0, "Loading requested map failed; closing server.");
|
|
|
|
_exit_game = true;
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-30 23:38:51 +02:00
|
|
|
|
2023-03-15 20:59:58 +01:00
|
|
|
if (result != SL_REINIT) {
|
|
|
|
_game_mode = ogm;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_network_dedicated) {
|
|
|
|
/*
|
|
|
|
* If we are a dedicated server, have already loaded/started a game,
|
|
|
|
* and then loading the savegame fails in a manner that we need to
|
|
|
|
* reinitialize everything. We must not fall back into the menu mode
|
|
|
|
* with the intro game, as that is unjoinable by clients. So there is
|
|
|
|
* nothing else to do than start a new game, as it might have failed
|
|
|
|
* trying to reload the originally loaded savegame/scenario.
|
|
|
|
*/
|
|
|
|
Debug(net, 0, "Loading game failed, so a new (random) game will be started");
|
|
|
|
MakeNewGame(false, true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_network_server) {
|
|
|
|
/* We can't load the intro game as server, so disconnect first. */
|
|
|
|
NetworkDisconnect();
|
|
|
|
}
|
2010-06-30 22:20:15 +02:00
|
|
|
|
2023-03-15 20:59:58 +01:00
|
|
|
switch (ogm) {
|
2010-06-30 22:20:15 +02:00
|
|
|
default:
|
2023-03-15 20:59:58 +01:00
|
|
|
case GM_MENU: LoadIntroGame(); break;
|
|
|
|
case GM_EDITOR: MakeNewEditorWorld(); break;
|
2010-06-30 22:20:15 +02:00
|
|
|
}
|
2023-03-15 20:59:58 +01:00
|
|
|
return false;
|
2010-06-30 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
2024-01-22 20:22:45 +01:00
|
|
|
static void UpdateSocialIntegration(GameMode game_mode)
|
|
|
|
{
|
|
|
|
switch (game_mode) {
|
|
|
|
case GM_BOOTSTRAP:
|
|
|
|
case GM_MENU:
|
|
|
|
SocialIntegration::EventEnterMainMenu();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GM_NORMAL:
|
|
|
|
if (_networking) {
|
|
|
|
SocialIntegration::EventEnterMultiplayer(Map::SizeX(), Map::SizeY());
|
|
|
|
} else {
|
|
|
|
SocialIntegration::EventEnterSingleplayer(Map::SizeX(), Map::SizeY());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GM_EDITOR:
|
|
|
|
SocialIntegration::EventEnterScenarioEditor(Map::SizeX(), Map::SizeY());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-25 01:45:52 +01:00
|
|
|
void SwitchToMode(SwitchMode new_mode)
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
2021-05-09 19:02:17 +02:00
|
|
|
/* If we are saving something, the network stays in its current state */
|
2011-05-28 15:55:34 +02:00
|
|
|
if (new_mode != SM_SAVE_GAME) {
|
2007-03-21 16:19:33 +01:00
|
|
|
/* If the network is active, make it not-active */
|
2004-12-04 18:54:56 +01:00
|
|
|
if (_networking) {
|
2024-02-03 15:48:54 +01:00
|
|
|
if (_network_server && (new_mode == SM_LOAD_GAME || new_mode == SM_NEWGAME || new_mode == SM_RESTARTGAME)) {
|
2004-12-04 18:54:56 +01:00
|
|
|
NetworkReboot();
|
|
|
|
} else {
|
|
|
|
NetworkDisconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-21 16:19:33 +01:00
|
|
|
/* If we are a server, we restart the server */
|
2004-12-04 18:54:56 +01:00
|
|
|
if (_is_network_server) {
|
2007-03-21 16:19:33 +01:00
|
|
|
/* But not if we are going to the menu */
|
2004-12-04 18:54:56 +01:00
|
|
|
if (new_mode != SM_MENU) {
|
2008-01-13 02:39:22 +01:00
|
|
|
/* check if we should reload the config */
|
2008-05-29 22:21:28 +02:00
|
|
|
if (_settings_client.network.reload_cfg) {
|
2008-01-13 02:39:22 +01:00
|
|
|
LoadFromConfig();
|
2009-01-12 18:11:45 +01:00
|
|
|
MakeNewgameSettingsLive();
|
2008-01-13 02:39:22 +01:00
|
|
|
ResetGRFConfig(false);
|
|
|
|
}
|
2004-12-04 18:54:56 +01:00
|
|
|
NetworkServerStart();
|
|
|
|
} else {
|
2007-03-21 16:19:33 +01:00
|
|
|
/* This client no longer wants to be a network-server */
|
2004-12-04 18:54:56 +01:00
|
|
|
_is_network_server = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Remove: ENABLE_NETWORK switch
This switch has been a pain for years. Often disabling broke
compilation, as no developer compiles OpenTTD without, neither do
any of our official binaries.
Additionaly, it has grown so hugely in our codebase, that it
clearly shows that the current solution was a poor one. 350+
instances of "#ifdef ENABLE_NETWORK" were in the code, of which
only ~30 in the networking code itself. The rest were all around
the code to do the right thing, from GUI to NewGRF.
A more proper solution would be to stub all the functions, and
make sure the rest of the code can simply assume network is
available. This was also partially done, and most variables were
correct if networking was disabled. Despite that, often the #ifdefs
were still used.
With the recent removal of DOS, there is also no platform anymore
which we support where networking isn't working out-of-the-box.
All in all, it is time to remove the ENABLE_NETWORK switch. No
replacement is planned, but if you feel we really need this option,
we welcome any Pull Request which implements this in a way that
doesn't crawl through the code like this diff shows we used to.
2019-03-20 17:01:13 +01:00
|
|
|
|
2013-01-08 23:46:42 +01:00
|
|
|
/* Make sure all AI controllers are gone at quitting game */
|
2011-05-28 15:55:34 +02:00
|
|
|
if (new_mode != SM_SAVE_GAME) AI::KillAll();
|
2004-12-04 18:54:56 +01:00
|
|
|
|
2023-04-27 17:21:29 +02:00
|
|
|
/* When we change mode, reset the autosave. */
|
|
|
|
if (new_mode != SM_SAVE_GAME) ChangeAutosaveFrequency(true);
|
|
|
|
|
2023-04-25 19:43:45 +02:00
|
|
|
/* Transmit the survey if we were in normal-mode and not saving. It always means we leaving the current game. */
|
|
|
|
if (_game_mode == GM_NORMAL && new_mode != SM_SAVE_GAME) _survey.Transmit(NetworkSurveyHandler::Reason::LEAVE);
|
|
|
|
|
|
|
|
/* Keep track when we last switch mode. Used for survey, to know how long someone was in a game. */
|
2024-03-16 08:58:56 +01:00
|
|
|
if (new_mode != SM_SAVE_GAME) {
|
|
|
|
_game_session_stats.start_time = std::chrono::steady_clock::now();
|
|
|
|
_game_session_stats.savegame_size = std::nullopt;
|
|
|
|
}
|
2023-04-25 19:43:45 +02:00
|
|
|
|
2005-03-12 22:21:47 +01:00
|
|
|
switch (new_mode) {
|
2009-03-15 01:32:18 +01:00
|
|
|
case SM_EDITOR: // Switch to scenario editor
|
2008-04-29 20:19:29 +02:00
|
|
|
MakeNewEditorWorld();
|
2023-04-25 19:43:45 +02:00
|
|
|
GenerateSavegameId();
|
2024-01-22 20:22:45 +01:00
|
|
|
|
|
|
|
UpdateSocialIntegration(GM_EDITOR);
|
2008-04-29 20:19:29 +02:00
|
|
|
break;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2021-01-08 16:23:07 +01:00
|
|
|
case SM_RELOADGAME: // Reload with what-ever started the game
|
2019-03-05 05:04:39 +01:00
|
|
|
if (_file_to_saveload.abstract_ftype == FT_SAVEGAME || _file_to_saveload.abstract_ftype == FT_SCENARIO) {
|
2021-01-08 16:23:07 +01:00
|
|
|
/* Reload current savegame/scenario */
|
2019-03-05 05:04:39 +01:00
|
|
|
_switch_mode = _game_mode == GM_EDITOR ? SM_LOAD_SCENARIO : SM_LOAD_GAME;
|
|
|
|
SwitchToMode(_switch_mode);
|
|
|
|
break;
|
|
|
|
} else if (_file_to_saveload.abstract_ftype == FT_HEIGHTMAP) {
|
|
|
|
/* Restart current heightmap */
|
|
|
|
_switch_mode = _game_mode == GM_EDITOR ? SM_LOAD_HEIGHTMAP : SM_RESTART_HEIGHTMAP;
|
|
|
|
SwitchToMode(_switch_mode);
|
|
|
|
break;
|
|
|
|
}
|
2021-01-08 16:21:54 +01:00
|
|
|
|
|
|
|
MakeNewGame(false, new_mode == SM_NEWGAME);
|
2023-04-25 19:43:45 +02:00
|
|
|
GenerateSavegameId();
|
2024-01-22 20:22:45 +01:00
|
|
|
|
|
|
|
UpdateSocialIntegration(GM_NORMAL);
|
2021-01-08 16:21:54 +01:00
|
|
|
break;
|
2019-03-05 05:04:39 +01:00
|
|
|
|
2024-02-03 15:48:54 +01:00
|
|
|
case SM_RESTARTGAME: // Restart --> 'Random game' with current settings
|
2009-03-15 01:32:18 +01:00
|
|
|
case SM_NEWGAME: // New Game --> 'Random game'
|
2009-08-07 00:00:32 +02:00
|
|
|
MakeNewGame(false, new_mode == SM_NEWGAME);
|
2023-04-25 19:43:45 +02:00
|
|
|
GenerateSavegameId();
|
2024-01-22 20:22:45 +01:00
|
|
|
|
|
|
|
UpdateSocialIntegration(GM_NORMAL);
|
2008-04-29 20:19:29 +02:00
|
|
|
break;
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2011-05-28 15:55:34 +02:00
|
|
|
case SM_LOAD_GAME: { // Load game, Play Scenario
|
2008-04-29 20:19:29 +02:00
|
|
|
ResetGRFConfig(true);
|
|
|
|
ResetWindowSystem();
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2016-09-04 14:57:43 +02:00
|
|
|
if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_NORMAL, NO_DIRECTORY)) {
|
2024-04-01 18:57:03 +02:00
|
|
|
ShowErrorMessage(GetSaveLoadErrorType(), GetSaveLoadErrorMessage(), WL_CRITICAL);
|
2008-04-29 20:19:29 +02:00
|
|
|
} else {
|
2016-09-04 14:57:43 +02:00
|
|
|
if (_file_to_saveload.abstract_ftype == FT_SCENARIO) {
|
2022-06-09 21:32:31 +02:00
|
|
|
OnStartScenario();
|
2008-05-05 00:38:18 +02:00
|
|
|
}
|
2021-05-05 19:21:12 +02:00
|
|
|
OnStartGame(_network_dedicated);
|
2008-04-29 20:19:29 +02:00
|
|
|
/* Decrease pause counter (was increased from opening load dialog) */
|
2021-11-23 01:05:58 +01:00
|
|
|
Command<CMD_PAUSE>::Post(PM_PAUSED_SAVELOAD, false);
|
2008-04-29 20:19:29 +02:00
|
|
|
}
|
2024-01-22 20:22:45 +01:00
|
|
|
|
|
|
|
UpdateSocialIntegration(GM_NORMAL);
|
2008-04-29 20:19:29 +02:00
|
|
|
break;
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2019-03-05 05:04:39 +01:00
|
|
|
case SM_RESTART_HEIGHTMAP: // Load a heightmap and start a new game from it with current settings
|
2009-03-15 01:32:18 +01:00
|
|
|
case SM_START_HEIGHTMAP: // Load a heightmap and start a new game from it
|
2019-03-05 05:04:39 +01:00
|
|
|
MakeNewGame(true, new_mode == SM_START_HEIGHTMAP);
|
2023-04-25 19:43:45 +02:00
|
|
|
GenerateSavegameId();
|
2024-01-22 20:22:45 +01:00
|
|
|
|
|
|
|
UpdateSocialIntegration(GM_NORMAL);
|
2008-04-29 20:19:29 +02:00
|
|
|
break;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 12:00:30 +02:00
|
|
|
|
2009-03-15 01:32:18 +01:00
|
|
|
case SM_LOAD_HEIGHTMAP: // Load heightmap from scenario editor
|
2008-09-30 22:39:50 +02:00
|
|
|
SetLocalCompany(OWNER_NONE);
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 12:00:30 +02:00
|
|
|
|
2024-01-22 23:35:25 +01:00
|
|
|
_game_mode = GM_EDITOR;
|
|
|
|
|
2010-01-17 23:59:24 +01:00
|
|
|
GenerateWorld(GWM_HEIGHTMAP, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
|
2023-04-25 19:43:45 +02:00
|
|
|
GenerateSavegameId();
|
2008-04-29 20:19:29 +02:00
|
|
|
MarkWholeScreenDirty();
|
2024-01-22 20:22:45 +01:00
|
|
|
|
2024-01-22 22:28:00 +01:00
|
|
|
UpdateSocialIntegration(GM_EDITOR);
|
2008-04-29 20:19:29 +02:00
|
|
|
break;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 12:00:30 +02:00
|
|
|
|
2009-03-15 01:32:18 +01:00
|
|
|
case SM_LOAD_SCENARIO: { // Load scenario from scenario editor
|
2016-09-04 14:57:43 +02:00
|
|
|
if (SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_EDITOR, NO_DIRECTORY)) {
|
2008-09-30 22:39:50 +02:00
|
|
|
SetLocalCompany(OWNER_NONE);
|
2023-04-25 19:43:45 +02:00
|
|
|
GenerateSavegameId();
|
2023-04-24 17:56:01 +02:00
|
|
|
_settings_newgame.game_creation.starting_year = TimerGameCalendar::year;
|
2009-12-22 09:34:40 +01:00
|
|
|
/* Cancel the saveload pausing */
|
2021-11-23 01:05:58 +01:00
|
|
|
Command<CMD_PAUSE>::Post(PM_PAUSED_SAVELOAD, false);
|
2008-04-29 20:19:29 +02:00
|
|
|
} else {
|
2024-04-01 18:57:03 +02:00
|
|
|
ShowErrorMessage(GetSaveLoadErrorType(), GetSaveLoadErrorMessage(), WL_CRITICAL);
|
2008-04-29 20:19:29 +02:00
|
|
|
}
|
2024-01-22 20:22:45 +01:00
|
|
|
|
2024-01-22 22:28:00 +01:00
|
|
|
UpdateSocialIntegration(GM_EDITOR);
|
2008-04-29 20:19:29 +02:00
|
|
|
break;
|
2005-11-14 20:48:04 +01:00
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2021-05-01 14:41:25 +02:00
|
|
|
case SM_JOIN_GAME: // Join a multiplayer game
|
|
|
|
LoadIntroGame();
|
|
|
|
NetworkClientJoinGame();
|
2024-01-22 20:22:45 +01:00
|
|
|
|
|
|
|
SocialIntegration::EventJoiningMultiplayer();
|
2021-05-01 14:41:25 +02:00
|
|
|
break;
|
|
|
|
|
2009-03-15 01:32:18 +01:00
|
|
|
case SM_MENU: // Switch to game intro menu
|
2008-04-29 20:19:29 +02:00
|
|
|
LoadIntroGame();
|
2020-12-08 10:24:59 +01:00
|
|
|
if (BaseSounds::ini_set.empty() && BaseSounds::GetUsedSet()->fallback && SoundDriver::GetInstance()->HasOutput()) {
|
2010-02-24 15:46:15 +01:00
|
|
|
ShowErrorMessage(STR_WARNING_FALLBACK_SOUNDSET, INVALID_STRING_ID, WL_CRITICAL);
|
2020-05-17 23:32:06 +02:00
|
|
|
BaseSounds::ini_set = BaseSounds::GetUsedSet()->name;
|
2010-02-22 21:19:17 +01:00
|
|
|
}
|
2023-04-25 19:43:45 +02:00
|
|
|
if (_settings_client.network.participate_survey == PS_ASK) {
|
|
|
|
/* No matter how often you go back to the main menu, only ask the first time. */
|
|
|
|
static bool asked_once = false;
|
|
|
|
if (!asked_once) {
|
|
|
|
asked_once = true;
|
|
|
|
ShowNetworkAskSurvey();
|
|
|
|
}
|
|
|
|
}
|
2024-01-22 20:22:45 +01:00
|
|
|
|
|
|
|
UpdateSocialIntegration(GM_MENU);
|
2008-04-29 20:19:29 +02:00
|
|
|
break;
|
|
|
|
|
2011-05-28 15:55:34 +02:00
|
|
|
case SM_SAVE_GAME: // Save game.
|
2021-01-22 16:24:29 +01:00
|
|
|
/* Make network saved games on pause compatible to singleplayer mode */
|
2020-12-06 21:11:47 +01:00
|
|
|
if (SaveOrLoad(_file_to_saveload.name, SLO_SAVE, DFT_GAME_FILE, NO_DIRECTORY) != SL_OK) {
|
2024-04-01 18:57:03 +02:00
|
|
|
ShowErrorMessage(GetSaveLoadErrorType(), GetSaveLoadErrorMessage(), WL_ERROR);
|
2008-04-29 20:19:29 +02:00
|
|
|
} else {
|
2021-05-17 15:46:38 +02:00
|
|
|
CloseWindowById(WC_SAVELOAD, 0);
|
2008-04-29 20:19:29 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-05-28 15:55:34 +02:00
|
|
|
case SM_SAVE_HEIGHTMAP: // Save heightmap.
|
2020-12-06 21:11:45 +01:00
|
|
|
MakeHeightmapScreenshot(_file_to_saveload.name.c_str());
|
2021-05-17 15:46:38 +02:00
|
|
|
CloseWindowById(WC_SAVELOAD, 0);
|
2011-05-28 15:55:34 +02:00
|
|
|
break;
|
|
|
|
|
2009-03-15 01:32:18 +01:00
|
|
|
case SM_GENRANDLAND: // Generate random land within scenario editor
|
2008-09-30 22:39:50 +02:00
|
|
|
SetLocalCompany(OWNER_NONE);
|
2010-01-17 23:59:24 +01:00
|
|
|
GenerateWorld(GWM_RANDOM, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
|
2008-04-29 20:19:29 +02:00
|
|
|
/* XXX: set date */
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
break;
|
2009-02-25 01:45:52 +01:00
|
|
|
|
|
|
|
default: NOT_REACHED();
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-13 15:58:37 +01:00
|
|
|
|
2008-04-29 20:19:29 +02:00
|
|
|
/**
|
|
|
|
* State controlling game loop.
|
|
|
|
* The state must not be changed from anywhere but here.
|
|
|
|
* That check is enforced in DoCommand.
|
|
|
|
*/
|
2007-03-07 12:47:46 +01:00
|
|
|
void StateGameLoop()
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
2019-01-22 19:31:08 +01:00
|
|
|
if (!_networking || _network_server) {
|
|
|
|
StateGameLoop_LinkGraphPauseControl();
|
|
|
|
}
|
|
|
|
|
2021-03-09 20:26:01 +01:00
|
|
|
/* Don't execute the state loop during pause or when modal windows are open. */
|
|
|
|
if (_pause_mode != PM_UNPAUSED || HasModalProgress()) {
|
2018-07-19 21:17:07 +02:00
|
|
|
PerformanceMeasurer::Paused(PFE_GAMELOOP);
|
|
|
|
PerformanceMeasurer::Paused(PFE_GL_ECONOMY);
|
|
|
|
PerformanceMeasurer::Paused(PFE_GL_TRAINS);
|
|
|
|
PerformanceMeasurer::Paused(PFE_GL_ROADVEHS);
|
|
|
|
PerformanceMeasurer::Paused(PFE_GL_SHIPS);
|
|
|
|
PerformanceMeasurer::Paused(PFE_GL_AIRCRAFT);
|
|
|
|
PerformanceMeasurer::Paused(PFE_GL_LANDSCAPE);
|
|
|
|
|
2021-03-09 20:26:01 +01:00
|
|
|
if (!HasModalProgress()) UpdateLandscapingLimits();
|
2014-02-23 20:32:00 +01:00
|
|
|
#ifndef DEBUG_DUMP_COMMANDS
|
2011-12-19 21:50:54 +01:00
|
|
|
Game::GameLoop();
|
2014-02-23 20:32:00 +01:00
|
|
|
#endif
|
2008-01-01 23:34:00 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-07-19 21:17:07 +02:00
|
|
|
|
|
|
|
PerformanceMeasurer framerate(PFE_GAMELOOP);
|
|
|
|
PerformanceAccumulator::Reset(PFE_GL_LANDSCAPE);
|
2004-09-12 17:29:37 +02:00
|
|
|
|
2013-07-06 21:00:33 +02:00
|
|
|
Layouter::ReduceLineCache();
|
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
if (_game_mode == GM_EDITOR) {
|
2014-02-23 23:03:08 +01:00
|
|
|
BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
|
2004-08-09 19:04:08 +02:00
|
|
|
RunTileLoop();
|
|
|
|
CallVehicleTicks();
|
|
|
|
CallLandscapeTick();
|
2014-02-23 23:03:08 +01:00
|
|
|
BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
|
2011-01-04 23:50:09 +01:00
|
|
|
UpdateLandscapingLimits();
|
2008-01-15 19:51:46 +01:00
|
|
|
|
2018-05-04 22:29:22 +02:00
|
|
|
CallWindowGameTickEvent();
|
2004-08-09 19:04:08 +02:00
|
|
|
NewsLoop();
|
|
|
|
} else {
|
2024-01-22 15:04:34 +01:00
|
|
|
if (_debug_desync_level > 2 && TimerGameEconomy::date_fract == 0 && (TimerGameEconomy::date.base() & 0x1F) == 0) {
|
2010-04-09 18:01:48 +02:00
|
|
|
/* Save the desync savegame if needed. */
|
2024-01-29 22:58:22 +01:00
|
|
|
std::string name = fmt::format("dmp_cmds_{:08x}_{:08x}.sav", _settings_game.game_creation.generation_seed, TimerGameEconomy::date);
|
2016-09-04 18:06:50 +02:00
|
|
|
SaveOrLoad(name, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);
|
2010-04-09 18:01:48 +02:00
|
|
|
}
|
|
|
|
|
2010-04-21 14:55:33 +02:00
|
|
|
CheckCaches();
|
|
|
|
|
2007-03-21 16:19:33 +01:00
|
|
|
/* All these actions has to be done from OWNER_NONE
|
|
|
|
* for multiplayer compatibility */
|
2024-01-17 03:33:23 +01:00
|
|
|
Backup<CompanyID> cur_company(_current_company, OWNER_NONE);
|
2004-09-11 21:34:11 +02:00
|
|
|
|
2014-02-23 23:03:08 +01:00
|
|
|
BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
|
2004-08-09 19:04:08 +02:00
|
|
|
AnimateAnimatedTiles();
|
2024-01-24 00:33:54 +01:00
|
|
|
if (TimerManager<TimerGameCalendar>::Elapsed(1)) {
|
|
|
|
RunVehicleCalendarDayProc();
|
|
|
|
}
|
2024-01-22 15:04:34 +01:00
|
|
|
TimerManager<TimerGameEconomy>::Elapsed(1);
|
2023-04-16 20:14:22 +02:00
|
|
|
TimerManager<TimerGameTick>::Elapsed(1);
|
2004-08-09 19:04:08 +02:00
|
|
|
RunTileLoop();
|
|
|
|
CallVehicleTicks();
|
|
|
|
CallLandscapeTick();
|
2014-02-23 23:03:08 +01:00
|
|
|
BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2014-02-23 20:32:00 +01:00
|
|
|
#ifndef DEBUG_DUMP_COMMANDS
|
2019-02-04 01:26:55 +01:00
|
|
|
{
|
2023-01-28 20:06:51 +01:00
|
|
|
PerformanceMeasurer script_framerate(PFE_ALLSCRIPTS);
|
2019-02-04 01:26:55 +01:00
|
|
|
AI::GameLoop();
|
|
|
|
Game::GameLoop();
|
|
|
|
}
|
2014-02-23 20:32:00 +01:00
|
|
|
#endif
|
2011-01-04 23:50:09 +01:00
|
|
|
UpdateLandscapingLimits();
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2018-05-04 22:29:22 +02:00
|
|
|
CallWindowGameTickEvent();
|
2004-08-09 19:04:08 +02:00
|
|
|
NewsLoop();
|
2010-05-31 22:22:57 +02:00
|
|
|
cur_company.Restore();
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
2010-06-05 15:32:42 +02:00
|
|
|
|
2010-07-31 23:43:07 +02:00
|
|
|
assert(IsLocalCompany());
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2023-04-27 17:21:29 +02:00
|
|
|
/** Interval for regular autosaves. Initialized at zero to disable till settings are loaded. */
|
|
|
|
static IntervalTimer<TimerGameRealtime> _autosave_interval({std::chrono::milliseconds::zero(), TimerGameRealtime::AUTOSAVE}, [](auto)
|
2023-04-13 13:56:00 +02:00
|
|
|
{
|
2023-04-27 17:21:29 +02:00
|
|
|
/* We reset the command-during-pause mode here, so we don't continue
|
|
|
|
* to make auto-saves when nothing more is changing. */
|
|
|
|
_pause_mode &= ~PM_COMMAND_DURING_PAUSE;
|
2023-04-13 13:56:00 +02:00
|
|
|
|
|
|
|
_do_autosave = true;
|
|
|
|
SetWindowDirty(WC_STATUS_BAR, 0);
|
2023-04-27 17:21:29 +02:00
|
|
|
|
|
|
|
static FiosNumberedSaveName _autosave_ctr("autosave");
|
|
|
|
DoAutoOrNetsave(_autosave_ctr);
|
|
|
|
|
|
|
|
_do_autosave = false;
|
|
|
|
SetWindowDirty(WC_STATUS_BAR, 0);
|
2023-04-13 13:56:00 +02:00
|
|
|
});
|
|
|
|
|
2010-08-01 21:22:34 +02:00
|
|
|
/**
|
2023-04-27 17:21:29 +02:00
|
|
|
* Reset the interval of the autosave.
|
|
|
|
*
|
|
|
|
* If reset is not set, this does not set the elapsed time on the timer,
|
|
|
|
* so if the interval is smaller, it might result in an autosave being done
|
|
|
|
* immediately.
|
|
|
|
*
|
|
|
|
* @param reset Whether to reset the timer back to zero, or to continue.
|
2010-08-01 21:44:49 +02:00
|
|
|
*/
|
2023-04-27 17:21:29 +02:00
|
|
|
void ChangeAutosaveFrequency(bool reset)
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
2023-12-07 20:27:00 +01:00
|
|
|
_autosave_interval.SetInterval({std::chrono::minutes(_settings_client.gui.autosave_interval), TimerGameRealtime::AUTOSAVE}, reset);
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2021-03-09 14:53:51 +01:00
|
|
|
/**
|
|
|
|
* Request a new NewGRF scan. This will be executed on the next game-tick.
|
|
|
|
* This is mostly needed to ensure NewGRF scans (which are blocking) are
|
|
|
|
* done in the game-thread, and not in the draw-thread (which most often
|
|
|
|
* triggers this request).
|
|
|
|
* @param callback Optional callback to call when NewGRF scan is completed.
|
2021-04-12 20:53:04 +02:00
|
|
|
* @return True when the NewGRF scan was actually requested, false when the scan was already running.
|
2021-03-09 14:53:51 +01:00
|
|
|
*/
|
2021-04-12 20:53:04 +02:00
|
|
|
bool RequestNewGRFScan(NewGRFScanCallback *callback)
|
2021-03-09 14:53:51 +01:00
|
|
|
{
|
2021-04-12 20:53:04 +02:00
|
|
|
if (_request_newgrf_scan) return false;
|
|
|
|
|
2021-03-09 14:53:51 +01:00
|
|
|
_request_newgrf_scan = true;
|
|
|
|
_request_newgrf_scan_callback = callback;
|
2021-04-12 20:53:04 +02:00
|
|
|
return true;
|
2021-03-09 14:53:51 +01:00
|
|
|
}
|
|
|
|
|
2007-03-07 12:47:46 +01:00
|
|
|
void GameLoop()
|
2004-08-09 19:04:08 +02:00
|
|
|
{
|
2011-11-17 22:17:17 +01:00
|
|
|
if (_game_mode == GM_BOOTSTRAP) {
|
|
|
|
/* Check for UDP stuff */
|
2012-01-04 23:08:43 +01:00
|
|
|
if (_network_available) NetworkBackgroundLoop();
|
2011-11-17 22:17:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-09 14:53:51 +01:00
|
|
|
if (_request_newgrf_scan) {
|
|
|
|
ScanNewGRFFiles(_request_newgrf_scan_callback);
|
|
|
|
_request_newgrf_scan = false;
|
|
|
|
_request_newgrf_scan_callback = nullptr;
|
2021-03-09 15:21:57 +01:00
|
|
|
/* In case someone closed the game during our scan, don't do anything else. */
|
|
|
|
if (_exit_game) return;
|
2021-03-09 14:53:51 +01:00
|
|
|
}
|
|
|
|
|
2008-04-19 12:18:38 +02:00
|
|
|
ProcessAsyncSaveFinish();
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2023-04-27 17:21:29 +02:00
|
|
|
if (_game_mode == GM_NORMAL) {
|
|
|
|
static auto last_time = std::chrono::steady_clock::now();
|
|
|
|
auto now = std::chrono::steady_clock::now();
|
|
|
|
auto delta_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_time);
|
|
|
|
if (delta_ms.count() != 0) {
|
|
|
|
TimerManager<TimerGameRealtime>::Elapsed(delta_ms);
|
|
|
|
last_time = now;
|
|
|
|
}
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2007-03-21 16:19:33 +01:00
|
|
|
/* switch game mode? */
|
2011-08-21 14:52:24 +02:00
|
|
|
if (_switch_mode != SM_NONE && !HasModalProgress()) {
|
2009-02-25 01:45:52 +01:00
|
|
|
SwitchToMode(_switch_mode);
|
2004-08-09 19:04:08 +02:00
|
|
|
_switch_mode = SM_NONE;
|
2023-06-16 20:41:26 +02:00
|
|
|
if (_exit_game) return;
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IncreaseSpriteLRU();
|
|
|
|
|
2007-03-21 16:19:33 +01:00
|
|
|
/* Check for UDP stuff */
|
2012-01-04 23:08:43 +01:00
|
|
|
if (_network_available) NetworkBackgroundLoop();
|
2004-12-04 18:54:56 +01:00
|
|
|
|
2021-07-23 22:36:17 +02:00
|
|
|
DebugSendRemoteMessages();
|
|
|
|
|
2011-08-21 14:46:46 +02:00
|
|
|
if (_networking && !HasModalProgress()) {
|
2007-03-21 16:19:33 +01:00
|
|
|
/* Multiplayer */
|
2004-12-04 18:54:56 +01:00
|
|
|
NetworkGameLoop();
|
2004-08-09 19:04:08 +02:00
|
|
|
} else {
|
2004-12-04 18:54:56 +01:00
|
|
|
if (_network_reconnect > 0 && --_network_reconnect == 0) {
|
2007-03-21 16:19:33 +01:00
|
|
|
/* This means that we want to reconnect to the last host
|
|
|
|
* We do this here, because it means that the network is really closed */
|
2021-04-29 16:43:13 +02:00
|
|
|
NetworkClientConnectGame(_settings_client.network.last_joined, COMPANY_SPECTATOR);
|
2004-12-04 18:54:56 +01:00
|
|
|
}
|
2007-03-21 16:19:33 +01:00
|
|
|
/* Singleplayer */
|
2004-09-12 17:29:37 +02:00
|
|
|
StateGameLoop();
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|
|
|
|
|
2009-05-06 17:06:57 +02:00
|
|
|
if (!_pause_mode && HasBit(_display_opt, DO_FULL_ANIMATION)) DoPaletteAnimations();
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2014-04-28 23:06:51 +02:00
|
|
|
SoundDriver::GetInstance()->MainLoop();
|
2005-03-30 21:52:26 +02:00
|
|
|
MusicLoop();
|
2024-01-22 20:22:45 +01:00
|
|
|
SocialIntegration::RunCallbacks();
|
2004-08-09 19:04:08 +02:00
|
|
|
}
|