Loading

Paste #ppazmhk0d

  1. /** Start new competitor companies if possible. */
  2. void MaybeStartNewCompany()
  3. {
  4.     /* Count number of total existing companies. */
  5.     uint current_companies = (uint)Company::GetNumItems();
  6.  
  7.     /* Count number of existing AI only companies. */
  8.     uint current_ais = 0;
  9.     Company *c;
  10.     FOR_ALL_COMPANIES(c) {
  11.         if (c->is_ai) current_ais++;
  12.     }
  13.  
  14.     uint max_network_companies = _networking ? _settings_client.network.max_companies : MAX_COMPANIES;
  15.  
  16.     /* Compute number of AI companies to start. */
  17.     uint ais_to_start = 0;
  18.     for (CompanyID cid = COMPANY_FIRST; cid < MAX_COMPANIES && current_companies < max_network_companies && current_ais < (uint)_settings_game.difficulty.max_no_competitors; cid++) {
  19.         if (!Company::IsValidID(cid)) {
  20.             /* Check if the next AI is also scheduled to start immediately. */
  21.             if (AIConfig::GetConfig(cid, AIConfig::SSS_FORCE_GAME)->GetSetting("start_date") == 0) {
  22.                 ais_to_start++;
  23.                 current_companies++;
  24.                 current_ais++;
  25.             } else {
  26.                 break;
  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.     }
  36. }

Version history

Revision # Author Created at
pefzfn0mf Anonymous 05 Apr 2019, 23:56:46 UTC Diff

Comments