Fix #10331: Starting new company during load must happen after AI start. (#10332)

This situation occurs when loading a savegame in single-player which only
has AI companies.
This commit is contained in:
PeterN 2023-01-08 18:09:38 +00:00 committed by GitHub
parent 7460fdb298
commit c18a171028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 13 deletions

View File

@ -828,18 +828,6 @@ bool AfterLoadGame()
* version. It didn't show up before r12070. */
if (IsSavegameVersionBefore(SLV_87)) UpdateVoidTiles();
/* If Load Scenario / New (Scenario) Game is used,
* a company does not exist yet. So create one here.
* 1 exception: network-games. Those can have 0 companies
* But this exception is not true for non-dedicated network servers! */
if (!_networking || (_networking && _network_server && !_network_dedicated)) {
CompanyID first_human_company = GetFirstPlayableCompanyID();
if (!Company::IsValidID(first_human_company)) {
Company *c = DoStartupNewCompany(false, first_human_company);
c->settings = _settings_client.company;
}
}
/* Fix the cache for cargo payments. */
for (CargoPayment *cp : CargoPayment::Iterate()) {
cp->front->cargo_payment = cp;
@ -3232,9 +3220,22 @@ bool AfterLoadGame()
AfterLoadLinkGraphs();
/* Start the scripts. This MUST happen after everything else. */
/* Start the scripts. This MUST happen after everything else except
* starting a new company. */
StartScripts();
/* If Load Scenario / New (Scenario) Game is used,
* a company does not exist yet. So create one here.
* 1 exception: network-games. Those can have 0 companies
* But this exception is not true for non-dedicated network servers! */
if (!_networking || (_networking && _network_server && !_network_dedicated)) {
CompanyID first_human_company = GetFirstPlayableCompanyID();
if (!Company::IsValidID(first_human_company)) {
Company *c = DoStartupNewCompany(false, first_human_company);
c->settings = _settings_client.company;
}
}
return true;
}