Loading

max_no_competitors = 15 v

  1. Index: src/ai/ai_core.cpp
  2. ===================================================================
  3. --- src/ai/ai_core.cpp  (revision 27550)
  4. +++ src/ai/ai_core.cpp  (working copy)
  5. @@ -62,6 +62,7 @@
  6.     cur_company.Restore();
  7.  
  8.     InvalidateWindowData(WC_AI_DEBUG, 0, -1);
  9. +   DeleteWindowById(WC_AI_SETTINGS, company);
  10.     return;
  11.  }
  12.  
  13. Index: src/ai/ai_gui.cpp
  14. ===================================================================
  15. --- src/ai/ai_gui.cpp   (revision 27550)
  16. +++ src/ai/ai_gui.cpp   (working copy)
  17. @@ -177,7 +177,7 @@
  18.             GetConfig(slot)->Change((*it).second->GetName(), (*it).second->GetVersion());
  19.         }
  20.         InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_AI);
  21. -       InvalidateWindowClassesData(WC_AI_SETTINGS);
  22. +       DeleteWindowByClass(WC_AI_SETTINGS);
  23.         DeleteWindowByClass(WC_QUERY_STRING);
  24.     }
  25.  
  26. @@ -311,7 +311,7 @@
  27.         this->vscroll = this->GetScrollbar(WID_AIS_SCROLLBAR);
  28.         this->FinishInitNested(slot);  // Initializes 'this->line_height' as side effect.
  29.  
  30. -       this->SetWidgetDisabledState(WID_AIS_RESET, _game_mode != GM_MENU && Company::IsValidID(this->slot));
  31. +       this->SetWidgetDisabledState(WID_AIS_RESET, _game_mode == GM_NORMAL && (this->slot == OWNER_DEITY && !Game::GetInstance()->IsDead()) || (Company::IsValidAiID(this->slot) && !Company::Get(this->slot)->ai_instance->IsDead()));
  32.  
  33.         this->vscroll->SetCount((int)this->visible_settings.size());
  34.     }
  35. @@ -375,7 +375,7 @@
  36.         for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) {
  37.             const ScriptConfigItem &config_item = **it;
  38.             int current_value = config->GetSetting((config_item).name);
  39. -           bool editable = _game_mode == GM_MENU || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot)) || (config_item.flags & SCRIPTCONFIG_INGAME) != 0;
  40. +           bool editable = _game_mode != GM_NORMAL || (this->slot != OWNER_DEITY && (!Company::IsValidAiID(this->slot) || Company::Get(this->slot)->ai_instance->IsDead())) || (this->slot == OWNER_DEITY && Game::GetInstance()->IsDead()) || (config_item.flags & SCRIPTCONFIG_INGAME) != 0;
  41.  
  42.             StringID str;
  43.             TextColour colour;
  44. @@ -438,7 +438,7 @@
  45.                 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
  46.                 for (int i = 0; i < num; i++) it++;
  47.                 const ScriptConfigItem config_item = **it;
  48. -               if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
  49. +               if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY && !Game::GetInstance()->IsDead()) || (Company::IsValidAiID(this->slot) && !Company::Get(this->slot)->ai_instance->IsDead())) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
  50.  
  51.                 if (this->clicked_row != num) {
  52.                     DeleteChildWindows(WC_QUERY_STRING);
  53. @@ -519,7 +519,7 @@
  54.                 break;
  55.  
  56.             case WID_AIS_RESET:
  57. -               if (_game_mode == GM_MENU || !Company::IsValidID(this->slot)) {
  58. +               if (_game_mode != GM_NORMAL || (this->slot != OWNER_DEITY && (!Company::IsValidAiID(this->slot) || Company::Get(this->slot)->ai_instance->IsDead())) || (this->slot == OWNER_DEITY && Game::GetInstance()->IsDead())) {
  59.                     this->ai_config->ResetSettings();
  60.                     this->SetDirty();
  61.                 }
  62. @@ -532,7 +532,7 @@
  63.         if (StrEmpty(str)) return;
  64.         ScriptConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
  65.         for (int i = 0; i < this->clicked_row; i++) it++;
  66. -       if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (it->flags & SCRIPTCONFIG_INGAME) == 0) return;
  67. +       if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY && !Game::GetInstance()->IsDead()) || (Company::IsValidAiID(this->slot) && !Company::Get(this->slot)->ai_instance->IsDead())) && (it->flags & SCRIPTCONFIG_INGAME) == 0) return;
  68.         int32 value = atoi(str);
  69.         this->ai_config->SetSetting((*it).name, value);
  70.         this->SetDirty();
  71. @@ -543,7 +543,7 @@
  72.         assert(this->clicked_dropdown);
  73.         ScriptConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
  74.         for (int i = 0; i < this->clicked_row; i++) it++;
  75. -       if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (it->flags & SCRIPTCONFIG_INGAME) == 0) return;
  76. +       if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY && !Game::GetInstance()->IsDead()) || (Company::IsValidAiID(this->slot) && !Company::Get(this->slot)->ai_instance->IsDead())) && (it->flags & SCRIPTCONFIG_INGAME) == 0) return;
  77.         this->ai_config->SetSetting((*it).name, index);
  78.         this->SetDirty();
  79.     }
  80. @@ -779,11 +779,11 @@
  81.         if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL || Game::GetInstance() != NULL;
  82.  
  83.         if (_game_mode != GM_NORMAL) {
  84. -           return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors;
  85. +           return slot >= 0 && slot <= MAX_COMPANIES - 1;
  86.         }
  87. -       if (Company::IsValidID(slot) || slot < 0) return false;
  88. +       if (Company::IsValidHumanID(slot) || slot < 0) return false;
  89.  
  90. -       int max_slot = GetGameSettings().difficulty.max_no_competitors;
  91. +       int max_slot = MAX_COMPANIES;
  92.         for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
  93.             if (Company::IsValidHumanID(cid)) max_slot++;
  94.         }
  95. @@ -802,7 +802,7 @@
  96.                 }
  97.  
  98.                 DrawString(r.left + 10, r.right - 10, r.top + WD_MATRIX_TOP, text,
  99. -                       (this->selected_slot == OWNER_DEITY) ? TC_WHITE : (IsEditable(OWNER_DEITY) ? TC_ORANGE : TC_SILVER));
  100. +                       (this->selected_slot == OWNER_DEITY) ? TC_WHITE : (IsEditable(OWNER_DEITY) ? (_game_mode == GM_NORMAL) ? (Game::GetInstance()->IsDead()) ? TC_RED : TC_GREEN : TC_ORANGE : TC_SILVER));
  101.  
  102.                 break;
  103.             }
  104. @@ -812,7 +812,7 @@
  105.                 for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
  106.                     StringID text;
  107.  
  108. -                   if ((_game_mode != GM_NORMAL && i == 0) || (_game_mode == GM_NORMAL && Company::IsValidHumanID(i))) {
  109. +                   if (_game_mode == GM_NORMAL && Company::IsValidHumanID(i)) {
  110.                         text = STR_AI_CONFIG_HUMAN_PLAYER;
  111.                     } else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != NULL) {
  112.                         SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName());
  113. @@ -821,7 +821,7 @@
  114.                         text = STR_AI_CONFIG_RANDOM_AI;
  115.                     }
  116.                     DrawString(r.left + 10, r.right - 10, y + WD_MATRIX_TOP, text,
  117. -                           (this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER));
  118. +                           (this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? Company::IsValidAiID(i) ? Company::Get(i)->ai_instance->IsDead() ? TC_RED : TC_GREEN : TC_ORANGE : TC_SILVER));
  119.                     y += this->line_height;
  120.                 }
  121.                 break;
  122. @@ -838,6 +838,12 @@
  123.             return;
  124.         }
  125.  
  126. +       bool is_orange_slot = IsEditable(this->selected_slot) && !Company::IsValidAiID(this->selected_slot);
  127. +       bool is_red_slot = IsEditable(this->selected_slot) && Company::IsValidAiID(this->selected_slot) && Company::Get(this->selected_slot)->ai_instance->IsDead();
  128. +       bool is_orange_slot_above = IsEditable((CompanyID)(this->selected_slot - 1)) && !Company::IsValidAiID(this->selected_slot - 1);
  129. +       bool is_orange_slot_below = IsEditable((CompanyID)(this->selected_slot + 1)) && !Company::IsValidAiID(this->selected_slot + 1);
  130. +       bool is_red_slot_above = IsEditable((CompanyID)(this->selected_slot - 1)) && Company::IsValidAiID(this->selected_slot - 1) && Company::Get(this->selected_slot - 1)->ai_instance->IsDead();
  131. +       bool is_red_slot_below = IsEditable((CompanyID)(this->selected_slot + 1)) && Company::IsValidAiID(this->selected_slot + 1) && Company::Get(this->selected_slot + 1)->ai_instance->IsDead();
  132.         switch (widget) {
  133.             case WID_AIC_DECREASE:
  134.             case WID_AIC_INCREASE: {
  135. @@ -845,7 +851,7 @@
  136.                 if (widget == WID_AIC_DECREASE) {
  137.                     new_value = max(0, GetGameSettings().difficulty.max_no_competitors - 1);
  138.                 } else {
  139. -                   new_value = min(MAX_COMPANIES - 1, GetGameSettings().difficulty.max_no_competitors + 1);
  140. +                   new_value = min(MAX_COMPANIES, GetGameSettings().difficulty.max_no_competitors + 1);
  141.                 }
  142.                 IConsoleSetSetting("difficulty.max_no_competitors", new_value);
  143.                 this->InvalidateData();
  144. @@ -867,7 +873,7 @@
  145.             }
  146.  
  147.             case WID_AIC_MOVE_UP:
  148. -               if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) {
  149. +               if ((is_orange_slot || is_red_slot) && (is_orange_slot_above || is_red_slot_above)) {
  150.                     Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]);
  151.                     this->selected_slot--;
  152.                     this->vscroll->ScrollTowards(this->selected_slot);
  153. @@ -876,7 +882,7 @@
  154.                 break;
  155.  
  156.             case WID_AIC_MOVE_DOWN:
  157. -               if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1))) {
  158. +               if ((is_orange_slot || is_red_slot) && (is_orange_slot_below || is_red_slot_below)) {
  159.                     Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]);
  160.                     this->selected_slot++;
  161.                     this->vscroll->ScrollTowards(this->selected_slot);
  162. @@ -922,14 +928,32 @@
  163.         if (!gui_scope) return;
  164.  
  165.         this->SetWidgetDisabledState(WID_AIC_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0);
  166. -       this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
  167. -       this->SetWidgetDisabledState(WID_AIC_CHANGE, (this->selected_slot == OWNER_DEITY && _game_mode == GM_NORMAL) || this->selected_slot == INVALID_COMPANY);
  168. -       this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot)->GetConfigList()->size() == 0);
  169. -       this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1)));
  170. -       this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1)));
  171. +       this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES);
  172.  
  173. +       bool is_gs_slot = this->selected_slot == OWNER_DEITY;
  174. +       bool invalid_slot = this->selected_slot == INVALID_COMPANY;
  175. +       bool is_green_slot = Company::IsValidAiID(this->selected_slot) && !Company::Get(this->selected_slot)->ai_instance->IsDead();
  176. +       this->SetWidgetDisabledState(WID_AIC_CHANGE, invalid_slot || _game_mode == GM_NORMAL && (is_gs_slot || is_green_slot));
  177. +       this->SetWidgetDisabledState(WID_AIC_CONFIGURE, invalid_slot || GetConfig(this->selected_slot)->GetConfigList()->size() == 0);
  178. +
  179. +       /* Display either Settings or Configure button */
  180. +       NWidgetCore *configure_button = this->GetWidget<NWidgetCore>(WID_AIC_CONFIGURE);
  181. +       if (_game_mode == GM_NORMAL && !invalid_slot && (is_gs_slot && !Game::GetInstance()->IsDead() || is_green_slot)) {
  182. +           configure_button->SetDataTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP);
  183. +       } else {
  184. +           configure_button->SetDataTip(STR_AI_CONFIG_CONFIGURE, STR_AI_CONFIG_CONFIGURE_TOOLTIP);
  185. +       }
  186. +
  187. +       bool is_silver_slot_above = !IsEditable((CompanyID)(this->selected_slot - 1));
  188. +       bool is_green_slot_above = Company::IsValidAiID(this->selected_slot - 1) && !Company::Get(this->selected_slot - 1)->ai_instance->IsDead();
  189. +       this->SetWidgetDisabledState(WID_AIC_MOVE_UP, is_gs_slot || invalid_slot || is_green_slot || is_silver_slot_above || is_green_slot_above);
  190. +
  191. +       bool is_silver_slot_below = !IsEditable((CompanyID)(this->selected_slot + 1));
  192. +       bool is_green_slot_below = Company::IsValidAiID(this->selected_slot + 1) && !Company::Get(this->selected_slot + 1)->ai_instance->IsDead();
  193. +       this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, is_gs_slot || invalid_slot || is_green_slot || is_silver_slot_below || is_green_slot_below);
  194. +
  195.         for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
  196. -           this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == NULL));
  197. +           this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, invalid_slot || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == NULL));
  198.         }
  199.     }
  200.  };
  201. @@ -1375,6 +1399,15 @@
  202.         this->SetWidgetLoweredState(WID_AID_MATCH_CASE_BTN, this->case_sensitive_break_check);
  203.  
  204.         this->SetWidgetDisabledState(WID_AID_SETTINGS, ai_debug_company == INVALID_COMPANY);
  205. +
  206. +       /* Display either Settings or Configure button */
  207. +       NWidgetCore *settings_button = this->GetWidget<NWidgetCore>(WID_AID_SETTINGS);
  208. +       if (ai_debug_company == INVALID_COMPANY || (ai_debug_company == OWNER_DEITY && !Game::GetInstance()->IsDead() || Company::IsValidAiID(this->ai_debug_company) && !Company::Get(this->ai_debug_company)->ai_instance->IsDead())) {
  209. +           settings_button->SetDataTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP);
  210. +       } else {
  211. +           settings_button->SetDataTip(STR_AI_CONFIG_CONFIGURE, STR_AI_CONFIG_CONFIGURE_TOOLTIP);
  212. +       }
  213. +
  214.         this->SetWidgetDisabledState(WID_AID_RELOAD_TOGGLE, ai_debug_company == INVALID_COMPANY || ai_debug_company == OWNER_DEITY);
  215.         this->SetWidgetDisabledState(WID_AID_CONTINUE_BTN, ai_debug_company == INVALID_COMPANY ||
  216.                 (ai_debug_company == OWNER_DEITY ? !Game::IsPaused() : !AI::IsPaused(ai_debug_company)));
  217. Index: src/ai/ai_instance.cpp
  218. ===================================================================
  219. --- src/ai/ai_instance.cpp  (revision 27550)
  220. +++ src/ai/ai_instance.cpp  (working copy)
  221. @@ -81,6 +81,7 @@
  222.  
  223.  #include "../company_base.h"
  224.  #include "../company_func.h"
  225. +#include "../window_func.h"
  226.  
  227.  #include "../safeguards.h"
  228.  
  229. @@ -214,6 +215,7 @@
  230.     ScriptInstance::Died();
  231.  
  232.     ShowAIDebugWindow(_current_company);
  233. +   InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_AI);
  234.  
  235.     const AIInfo *info = AIConfig::GetConfig(_current_company, AIConfig::SSS_FORCE_GAME)->GetInfo();
  236.     if (info != NULL) {
  237. Index: src/game/game_instance.cpp
  238. ===================================================================
  239. --- src/game/game_instance.cpp  (revision 27550)
  240. +++ src/game/game_instance.cpp  (working copy)
  241. @@ -85,6 +85,8 @@
  242.  #include "../script/api/game/game_waypointlist.hpp.sq"
  243.  #include "../script/api/game/game_window.hpp.sq"
  244.  
  245. +#include "../window_func.h"
  246. +
  247.  #include "../safeguards.h"
  248.  
  249.  
  250. @@ -232,6 +234,7 @@
  251.     ScriptInstance::Died();
  252.  
  253.     ShowAIDebugWindow(OWNER_DEITY);
  254. +   InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_AI);
  255.  
  256.     const GameInfo *info = Game::GetInfo();
  257.     if (info != NULL) {
  258. Index: src/lang/english.txt
  259. ===================================================================
  260. --- src/lang/english.txt    (revision 27550)
  261. +++ src/lang/english.txt    (working copy)
  262. @@ -3979,10 +3979,10 @@
  263.  STR_ERROR_AI_DEBUG_SERVER_ONLY                                  :{YELLOW}AI/Game Script Debug window is only available for the server
  264.  
  265.  # AI configuration window
  266. -STR_AI_CONFIG_CAPTION                                           :{WHITE}AI/Game Script Configuration
  267. -STR_AI_CONFIG_GAMELIST_TOOLTIP                                  :{BLACK}The Game Script that will be loaded in the next game
  268. -STR_AI_CONFIG_AILIST_TOOLTIP                                    :{BLACK}The AIs that will be loaded in the next game
  269. -STR_AI_CONFIG_HUMAN_PLAYER                                      :Human player
  270. +STR_AI_CONFIG_CAPTION                                           :{WHITE}AI/Game Script Settings
  271. +STR_AI_CONFIG_GAMELIST_TOOLTIP                                  :{BLACK}The Game Script that is loaded or will be loaded in the next game
  272. +STR_AI_CONFIG_AILIST_TOOLTIP                                    :{BLACK}The AIs that are currently loaded or will be loaded next time they start on these Company IDs while in a game
  273. +STR_AI_CONFIG_HUMAN_PLAYER                                      :Human Company
  274.  STR_AI_CONFIG_RANDOM_AI                                         :Random AI
  275.  STR_AI_CONFIG_NONE                                              :(none)
  276.  
  277. Index: src/table/settings.ini
  278. ===================================================================
  279. --- src/table/settings.ini  (revision 27550)
  280. +++ src/table/settings.ini  (working copy)
  281. @@ -103,7 +103,7 @@
  282.  from     = 97
  283.  def      = 0
  284.  min      = 0
  285. -max      = MAX_COMPANIES - 1
  286. +max      = MAX_COMPANIES
  287.  interval = 1
  288.  proc     = MaxNoAIsChange
  289.  cat      = SC_BASIC

Comments