Changeset - r27756:c44abd4e455f
[Not reviewed]
master
0 1 0
Loïc Guilloux - 11 months ago 2023-07-29 10:31:33
glx22@users.noreply.github.com
Fix #11067, ed83c4b: Don't start competitors during map generation (#11069)
1 file changed with 8 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/company_cmd.cpp
Show inline comments
 
@@ -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<CMD_COMPANY_CTRL>::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<CMD_COMPANY_CTRL>::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;
 

	
0 comments (0 inline, 0 general)