From a979d9cddadc72c7d93ea77673b2a8466fa85fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guilloux?= Date: Sat, 29 Jul 2023 12:31:33 +0200 Subject: [PATCH] Fix #11067, ed83c4b: Don't start competitors during map generation (#11069) --- src/company_cmd.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 362ec0521f..ff125b44ea 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -617,14 +617,6 @@ void StartupCompanies() { /* Ensure the timeout is aborted, so it doesn't fire based on information of the last game. */ _new_competitor_timeout.Abort(); - - /* If there is no delay till the start of the next competitor, start all competitors at the start of the game. */ - if (_settings_game.difficulty.competitors_interval == 0 && _game_mode != GM_MENU && AI::CanStartNew()) { - for (auto i = 0; i < _settings_game.difficulty.max_no_competitors; i++) { - if (_networking && Company::GetNumItems() >= _settings_client.network.max_companies) break; - Command::Post(CCA_NEW_AI, INVALID_COMPANY, CRR_NONE, INVALID_CLIENT_ID); - } - } } /** Initialize the pool of companies. */ @@ -726,9 +718,14 @@ void OnTick_Companies() if (_new_competitor_timeout.HasFired() && _game_mode != GM_MENU && AI::CanStartNew()) { int32_t timeout = _settings_game.difficulty.competitors_interval * 60 * TICKS_PER_SECOND; - /* If the interval is zero, check every ~10 minutes if a company went bankrupt and needs replacing. */ - if (timeout == 0) timeout = 10 * 60 * TICKS_PER_SECOND; - + /* If the interval is zero, start as many competitors as needed then check every ~10 minutes if a company went bankrupt and needs replacing. */ + if (timeout == 0) { + for (auto i = 0; i < _settings_game.difficulty.max_no_competitors; i++) { + if (_networking && Company::GetNumItems() >= _settings_client.network.max_companies) break; + Command::Post(CCA_NEW_AI, INVALID_COMPANY, CRR_NONE, INVALID_CLIENT_ID); + } + timeout = 10 * 60 * TICKS_PER_SECOND; + } /* Randomize a bit when the AI is actually going to start; ranges from 87.5% .. 112.5% of indicated value. */ timeout += ScriptObject::GetRandomizer(OWNER_NONE).Next(timeout / 4) - timeout / 8;