File diff r28551:f762d05f819e → r28552:48eaa3286eee
src/openttd.cpp
Show inline comments
 
@@ -72,12 +72,13 @@
 
#include "misc_cmd.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_calendar.h"
 
#include "timer/timer_game_economy.h"
 
#include "timer/timer_game_realtime.h"
 
#include "timer/timer_game_tick.h"
 
#include "social_integration.h"
 

	
 
#include "linkgraph/linkgraphschedule.h"
 

	
 
#include <system_error>
 

	
 
#include "safeguards.h"
 
@@ -285,12 +286,13 @@ static void ParseResolution(Dimension *r
 
static void ShutdownGame()
 
{
 
	IConsoleFree();
 

	
 
	if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
 

	
 
	SocialIntegration::Shutdown();
 
	DriverFactoryBase::ShutdownDrivers();
 

	
 
	UnInitWindowSystem();
 

	
 
	/* stop the scripts */
 
	AI::Uninitialize(false);
 
@@ -749,12 +751,13 @@ int openttd_main(int argc, char *argv[])
 
	/* Initialize the zoom level of the screen to normal */
 
	_screen.zoom = ZOOM_LVL_NORMAL;
 

	
 
	/* The video driver is now selected, now initialise GUI zoom */
 
	AdjustGUIZoom(false);
 

	
 
	SocialIntegration::Initialize();
 
	NetworkStartUp(); // initialize network-core
 

	
 
	if (!HandleBootstrap()) {
 
		ShutdownGame();
 
		return ret;
 
	}
 
@@ -994,12 +997,34 @@ bool SafeLoad(const std::string &filenam
 
		case GM_MENU:   LoadIntroGame();      break;
 
		case GM_EDITOR: MakeNewEditorWorld(); break;
 
	}
 
	return false;
 
}
 

	
 
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;
 
	}
 
}
 

	
 
void SwitchToMode(SwitchMode new_mode)
 
{
 
	/* If we are saving something, the network stays in its current state */
 
	if (new_mode != SM_SAVE_GAME) {
 
		/* If the network is active, make it not-active */
 
		if (_networking) {
 
@@ -1041,12 +1066,14 @@ void SwitchToMode(SwitchMode new_mode)
 
	if (new_mode != SM_SAVE_GAME) _switch_mode_time = std::chrono::steady_clock::now();
 

	
 
	switch (new_mode) {
 
		case SM_EDITOR: // Switch to scenario editor
 
			MakeNewEditorWorld();
 
			GenerateSavegameId();
 

	
 
			UpdateSocialIntegration(GM_EDITOR);
 
			break;
 

	
 
		case SM_RELOADGAME: // Reload with what-ever started the game
 
			if (_file_to_saveload.abstract_ftype == FT_SAVEGAME || _file_to_saveload.abstract_ftype == FT_SCENARIO) {
 
				/* Reload current savegame/scenario */
 
				_switch_mode = _game_mode == GM_EDITOR ? SM_LOAD_SCENARIO : SM_LOAD_GAME;
 
@@ -1058,18 +1085,22 @@ void SwitchToMode(SwitchMode new_mode)
 
				SwitchToMode(_switch_mode);
 
				break;
 
			}
 

	
 
			MakeNewGame(false, new_mode == SM_NEWGAME);
 
			GenerateSavegameId();
 

	
 
			UpdateSocialIntegration(GM_NORMAL);
 
			break;
 

	
 
		case SM_RESTARTGAME: // Restart --> 'Random game' with current settings
 
		case SM_NEWGAME: // New Game --> 'Random game'
 
			MakeNewGame(false, new_mode == SM_NEWGAME);
 
			GenerateSavegameId();
 

	
 
			UpdateSocialIntegration(GM_NORMAL);
 
			break;
 

	
 
		case SM_LOAD_GAME: { // Load game, Play Scenario
 
			ResetGRFConfig(true);
 
			ResetWindowSystem();
 

	
 
@@ -1081,27 +1112,33 @@ void SwitchToMode(SwitchMode new_mode)
 
					OnStartScenario();
 
				}
 
				OnStartGame(_network_dedicated);
 
				/* Decrease pause counter (was increased from opening load dialog) */
 
				Command<CMD_PAUSE>::Post(PM_PAUSED_SAVELOAD, false);
 
			}
 

	
 
			UpdateSocialIntegration(GM_NORMAL);
 
			break;
 
		}
 

	
 
		case SM_RESTART_HEIGHTMAP: // Load a heightmap and start a new game from it with current settings
 
		case SM_START_HEIGHTMAP: // Load a heightmap and start a new game from it
 
			MakeNewGame(true, new_mode == SM_START_HEIGHTMAP);
 
			GenerateSavegameId();
 

	
 
			UpdateSocialIntegration(GM_NORMAL);
 
			break;
 

	
 
		case SM_LOAD_HEIGHTMAP: // Load heightmap from scenario editor
 
			SetLocalCompany(OWNER_NONE);
 

	
 
			GenerateWorld(GWM_HEIGHTMAP, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
 
			GenerateSavegameId();
 
			MarkWholeScreenDirty();
 

	
 
			UpdateSocialIntegration(GM_NORMAL);
 
			break;
 

	
 
		case SM_LOAD_SCENARIO: { // Load scenario from scenario editor
 
			if (SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_EDITOR, NO_DIRECTORY)) {
 
				SetLocalCompany(OWNER_NONE);
 
				GenerateSavegameId();
 
@@ -1109,18 +1146,22 @@ void SwitchToMode(SwitchMode new_mode)
 
				/* Cancel the saveload pausing */
 
				Command<CMD_PAUSE>::Post(PM_PAUSED_SAVELOAD, false);
 
			} else {
 
				SetDParamStr(0, GetSaveLoadErrorString());
 
				ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_CRITICAL);
 
			}
 

	
 
			UpdateSocialIntegration(GM_NORMAL);
 
			break;
 
		}
 

	
 
		case SM_JOIN_GAME: // Join a multiplayer game
 
			LoadIntroGame();
 
			NetworkClientJoinGame();
 

	
 
			SocialIntegration::EventJoiningMultiplayer();
 
			break;
 

	
 
		case SM_MENU: // Switch to game intro menu
 
			LoadIntroGame();
 
			if (BaseSounds::ini_set.empty() && BaseSounds::GetUsedSet()->fallback && SoundDriver::GetInstance()->HasOutput()) {
 
				ShowErrorMessage(STR_WARNING_FALLBACK_SOUNDSET, INVALID_STRING_ID, WL_CRITICAL);
 
@@ -1131,12 +1172,14 @@ void SwitchToMode(SwitchMode new_mode)
 
				static bool asked_once = false;
 
				if (!asked_once) {
 
					asked_once = true;
 
					ShowNetworkAskSurvey();
 
				}
 
			}
 

	
 
			UpdateSocialIntegration(GM_MENU);
 
			break;
 

	
 
		case SM_SAVE_GAME: // Save game.
 
			/* Make network saved games on pause compatible to singleplayer mode */
 
			if (SaveOrLoad(_file_to_saveload.name, SLO_SAVE, DFT_GAME_FILE, NO_DIRECTORY) != SL_OK) {
 
				SetDParamStr(0, GetSaveLoadErrorString());
 
@@ -1541,7 +1584,8 @@ void GameLoop()
 
	}
 

	
 
	if (!_pause_mode && HasBit(_display_opt, DO_FULL_ANIMATION)) DoPaletteAnimations();
 

	
 
	SoundDriver::GetInstance()->MainLoop();
 
	MusicLoop();
 
	SocialIntegration::RunCallbacks();
 
}