summaryrefslogtreecommitdiff
path: root/src/openttd.cpp
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-05-05 19:21:12 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-05 21:01:23 +0200
commite7581fd42d9740ca68adfc2ec55edb49d51af237 (patch)
tree51c7a9c14c282e2105e3bf3d298528488eb896e4 /src/openttd.cpp
parent72bd62fd705c495d90f08adc964ff8d7f84c6cc1 (diff)
downloadopenttd-e7581fd42d9740ca68adfc2ec55edb49d51af237.tar.xz
Change: [Network] Update server's NetworkServerGameInfo only when needed
Split the updating in a "static" version that only needs to be called when a new map is loaded or some settings are changed, and a "dynamic" version that updates everything that changes regularly such as the current game date or the number of spectators.
Diffstat (limited to 'src/openttd.cpp')
-rw-r--r--src/openttd.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 234e3a419..d4c7da6e4 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -832,15 +832,30 @@ void HandleExitGameRequest()
}
}
+/**
+ * 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)
+{
+ /* Update the local company for a loaded game. It is either always
+ * company #1 (eg 0) or in the case of a dedicated server a spectator */
+ SetLocalCompany(dedicated_server ? COMPANY_SPECTATOR : COMPANY_FIRST);
+
+ /* Update the static game info to set the values from the new game. */
+ NetworkServerUpdateGameInfo();
+ /* Execute the game-start script */
+ IConsoleCmdExec("exec scripts/game_start.scr 0");
+}
+
static void MakeNewGameDone()
{
SettingsDisableElrail(_settings_game.vehicle.disable_elrails);
/* In a dedicated server, the server does not play */
if (!VideoDriver::GetInstance()->HasGUI()) {
- SetLocalCompany(COMPANY_SPECTATOR);
+ OnStartGame(true);
if (_settings_client.gui.pause_on_newgame) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
- IConsoleCmdExec("exec scripts/game_start.scr 0");
return;
}
@@ -858,9 +873,7 @@ static void MakeNewGameDone()
_company_colours[c->index] = (Colours)c->colour;
}
- IConsoleCmdExec("exec scripts/game_start.scr 0");
-
- SetLocalCompany(COMPANY_FIRST);
+ OnStartGame(false);
InitializeRailGUI();
InitializeRoadGUI();
@@ -1032,11 +1045,7 @@ void SwitchToMode(SwitchMode new_mode)
/* Reset engine pool to simplify changing engine NewGRFs in scenario editor. */
EngineOverrideManager::ResetToCurrentNewGRFConfig();
}
- /* Update the local company for a loaded game. It is either always
- * company #1 (eg 0) or in the case of a dedicated server a spectator */
- SetLocalCompany(_network_dedicated ? COMPANY_SPECTATOR : COMPANY_FIRST);
- /* Execute the game-start script */
- IConsoleCmdExec("exec scripts/game_start.scr 0");
+ OnStartGame(_network_dedicated);
/* Decrease pause counter (was increased from opening load dialog) */
DoCommandP(0, PM_PAUSED_SAVELOAD, 0, CMD_PAUSE);
}