Loading

Revision differences

Old revision #pefzfn0mfNew revision #ppazmhk0d
1void MaybeStartNewCompany() {  1/** Start new competitor companies if possible. */
2    uint current_companies = (uint)Company::GetNumItems();  2void MaybeStartNewCompany()
   3{
   4    /* Count number of total existing companies. */
   5    uint current_companies = (uint)Company::GetNumItems();
3  6  
4    /* Count number of existing AI only companies. */  4    /* Count number of existing AI only companies. */
5    uint current_ais = 0;  5    uint current_ais = 0;
6    Company *c;  6    Company *c;
7    FOR_ALL_COMPANIES(c) {  7    FOR_ALL_COMPANIES(c) {
8        if (c->is_ai) current_ais++;  8        if (c->is_ai) current_ais++;
9    }  9    }
10  13  
11    uint max_network_companies = networking ? settings_client.network.max_companies : MAX_COMPANIES;  14    uint max_network_companies = _networking ? _settings_client.network.max_companies : MAX_COMPANIES;
12    uint ais_to_start = 0;  15
13    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++) {  16    /* Compute number of AI companies to start. */
14        if (Company::IsValidID(c))  17    uint ais_to_start = 0;
15            continue;  18    for (CompanyID cid = COMPANY_FIRST; cid < MAX_COMPANIES && current_companies < max_network_companies && current_ais < (uint)_settings_game.difficulty.max_no_competitors; cid++) {
16        if (AIConfig::GetConfig(company_id, AIConfig::SSS_FORCE_GAME)->GetSetting("start_date") != 0)  19        if (!Company::IsValidID(cid)) {
17            break;  20            /* Check if the next AI is also scheduled to start immediately. */
18        ais_to_start++;  21            if (AIConfig::GetConfig(cid, AIConfig::SSS_FORCE_GAME)->GetSetting("start_date") == 0) {
19        current_companies++;  22                ais_to_start++;
20        current_ais++;  23                current_companies++;
21    }  24                current_ais++;
22    if (ais_to_start > 0) {  25            } else {
23        DoCommandP(0, CCA_NEW_AI | INVALID_COMPANY << 16, ais_to_start, CMD_COMPANY_CTRL);  26                break;
24    }  27            }
   28        }
   29    }
   30
   31    if (ais_to_start > 0) {
   32        /* Send a command to all clients to start up new AI(s).
   33         * Works fine for Multiplayer and Singleplayer */
   34        DoCommandP(0, CCA_NEW_AI | INVALID_COMPANY << 16 | ais_to_start << 24, 0, CMD_COMPANY_CTRL);
   35    }
25} 36}