void MaybeStartNewCompany() {
uint current_companies = (uint)Company::GetNumItems();
/* Count number of existing AI only companies. */
uint current_ais = 0;
Company *c;
FOR_ALL_COMPANIES(c) {
if (c->is_ai) current_ais++;
}
uint max_network_companies = networking ? settings_client.network.max_companies : MAX_COMPANIES;
uint ais_to_start = 0;
for (CompanyID company_id = COMPANY_FIRST; company_id < MAX_COMPANIES && current_companies < max_network_companies && current_ais < _settings_game.difficulty.max_no_competitors; company_id++) {
if (Company::IsValidID(c))
continue;
if (AIConfig::GetConfig(company_id, AIConfig::SSS_FORCE_GAME)->GetSetting("start_date") != 0)
break;
ais_to_start++;
current_companies++;
current_ais++;
}
if (ais_to_start > 0) {
DoCommandP(0, CCA_NEW_AI | INVALID_COMPANY << 16, ais_to_start, CMD_COMPANY_CTRL);
}
}