Fix #9720: Delay start of GS/AI to after loading of savegame (#9745)

This commit is contained in:
Loïc Guilloux
2022-12-28 05:02:26 +01:00
committed by GitHub
parent f7e2b6ef12
commit fe30f66570
11 changed files with 166 additions and 100 deletions

View File

@@ -41,6 +41,7 @@
#include "../road_cmd.h"
#include "../ai/ai.hpp"
#include "../ai/ai_gui.hpp"
#include "../game/game.hpp"
#include "../town.h"
#include "../economy_base.h"
#include "../animated_tile_func.h"
@@ -302,7 +303,6 @@ static void InitializeWindowsAndCaches()
CheckTrainsLengths();
ShowNewGRFError();
ShowAIDebugWindowIfAIError();
/* Rebuild the smallmap list of owners. */
BuildOwnerLegend();
@@ -537,6 +537,22 @@ static inline bool MayHaveBridgeAbove(TileIndex t)
IsTileType(t, MP_WATER) || IsTileType(t, MP_TUNNELBRIDGE) || IsTileType(t, MP_OBJECT);
}
/**
* Start the scripts.
*/
static void StartScripts()
{
/* Start the GameScript. */
Game::StartNew();
/* Start the AIs. */
for (const Company *c : Company::Iterate()) {
if (Company::IsValidAiID(c->index)) AI::StartNew(c->index, false);
}
ShowAIDebugWindowIfAIError();
}
/**
* Perform a (large) amount of savegame conversion *magic* in order to
* load older savegames and to fill the caches for various purposes.
@@ -798,13 +814,6 @@ bool AfterLoadGame()
/* Update all vehicles */
AfterLoadVehicles(true);
/* Make sure there is an AI attached to an AI company */
{
for (const Company *c : Company::Iterate()) {
if (c->is_ai && c->ai_instance == nullptr) AI::StartNew(c->index);
}
}
/* make sure there is a town in the game */
if (_game_mode == GM_NORMAL && Town::GetNumItems() == 0) {
SetSaveLoadError(STR_ERROR_NO_TOWN_IN_SCENARIO);
@@ -3224,6 +3233,10 @@ bool AfterLoadGame()
ResetSignalHandlers();
AfterLoadLinkGraphs();
/* Start the scripts. This MUST happen after everything else. */
StartScripts();
return true;
}