Loading

Paste #pkxkubyo7

  1. Index: src/ai/ai_core.cpp
  2. ===================================================================
  3. --- src/ai/ai_core.cpp  (revision 27551)
  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 27551)
  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. @@ -276,6 +276,19 @@
  27.  }
  28.  
  29.  /**
  30. +* Check whether the currently selected AI/GS is dead.
  31. +* @return true if dead.
  32. +*/
  33. +static bool IsDead(CompanyID slot)
  34. +{
  35. +   if (slot == OWNER_DEITY) {
  36. +       return Game::GetInstance() == NULL || Game::GetInstance()->IsDead();
  37. +   } else {
  38. +       return !Company::IsValidAiID(slot) || Company::Get(slot)->ai_instance->IsDead();
  39. +   }
  40. +}
  41. +
  42. +/**
  43.   * Window for settings the parameters of an AI.
  44.   */
  45.  struct AISettingsWindow : public Window {
  46. @@ -311,7 +324,7 @@
  47.         this->vscroll = this->GetScrollbar(WID_AIS_SCROLLBAR);
  48.         this->FinishInitNested(slot);  // Initializes 'this->line_height' as side effect.
  49.  
  50. -       this->SetWidgetDisabledState(WID_AIS_RESET, _game_mode != GM_MENU && Company::IsValidID(this->slot));
  51. +       this->SetWidgetDisabledState(WID_AIS_RESET, _game_mode == GM_NORMAL && !IsDead(this->slot));
  52.  
  53.         this->vscroll->SetCount((int)this->visible_settings.size());
  54.     }
  55. @@ -375,7 +388,7 @@
  56.         for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) {
  57.             const ScriptConfigItem &config_item = **it;
  58.             int current_value = config->GetSetting((config_item).name);
  59. -           bool editable = _game_mode == GM_MENU || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot)) || (config_item.flags & SCRIPTCONFIG_INGAME) != 0;
  60. +           bool editable = _game_mode != GM_NORMAL || IsDead(this->slot) || (config_item.flags & SCRIPTCONFIG_INGAME) != 0;
  61.  
  62.             StringID str;
  63.             TextColour colour;
  64. @@ -438,7 +451,7 @@
  65.                 VisibleSettingsList::const_iterator it = this->visible_settings.begin();
  66.                 for (int i = 0; i < num; i++) it++;
  67.                 const ScriptConfigItem config_item = **it;
  68. -               if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
  69. +               if (_game_mode == GM_NORMAL && !IsDead(this->slot) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
  70.  
  71.                 if (this->clicked_row != num) {
  72.                     DeleteChildWindows(WC_QUERY_STRING);
  73. @@ -519,7 +532,7 @@
  74.                 break;
  75.  
  76.             case WID_AIS_RESET:
  77. -               if (_game_mode == GM_MENU || !Company::IsValidID(this->slot)) {
  78. +               if (_game_mode != GM_NORMAL || IsDead(this->slot)) {
  79.                     this->ai_config->ResetSettings();
  80.                     this->SetDirty();
  81.                 }
  82. @@ -532,7 +545,7 @@
  83.         if (StrEmpty(str)) return;
  84.         ScriptConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
  85.         for (int i = 0; i < this->clicked_row; i++) it++;
  86. -       if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (it->flags & SCRIPTCONFIG_INGAME) == 0) return;
  87. +       if (_game_mode == GM_NORMAL && !IsDead(this->slot) && (it->flags & SCRIPTCONFIG_INGAME) == 0) return;
  88.         int32 value = atoi(str);
  89.         this->ai_config->SetSetting((*it).name, value);
  90.         this->SetDirty();
  91. @@ -543,7 +556,7 @@
  92.         assert(this->clicked_dropdown);
  93.         ScriptConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
  94.         for (int i = 0; i < this->clicked_row; i++) it++;
  95. -       if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (it->flags & SCRIPTCONFIG_INGAME) == 0) return;
  96. +       if (_game_mode == GM_NORMAL && !IsDead(this->slot) && (it->flags & SCRIPTCONFIG_INGAME) == 0) return;
  97.         this->ai_config->SetSetting((*it).name, index);
  98.         this->SetDirty();
  99.     }
  100. @@ -779,15 +792,11 @@
  101.         if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL || Game::GetInstance() != NULL;
  102.  
  103.         if (_game_mode != GM_NORMAL) {
  104. -           return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors;
  105. +           return slot >= 0 && slot < MAX_COMPANIES;
  106.         }
  107. -       if (Company::IsValidID(slot) || slot < 0) return false;
  108. +       if (Company::IsValidHumanID(slot) || slot < 0) return false;
  109.  
  110. -       int max_slot = GetGameSettings().difficulty.max_no_competitors;
  111. -       for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
  112. -           if (Company::IsValidHumanID(cid)) max_slot++;
  113. -       }
  114. -       return slot < max_slot;
  115. +       return slot < MAX_COMPANIES;
  116.     }
  117.  
  118.     virtual void DrawWidget(const Rect &r, int widget) const
  119. @@ -802,7 +811,7 @@
  120.                 }
  121.  
  122.                 DrawString(r.left + 10, r.right - 10, r.top + WD_MATRIX_TOP, text,
  123. -                       (this->selected_slot == OWNER_DEITY) ? TC_WHITE : (IsEditable(OWNER_DEITY) ? TC_ORANGE : TC_SILVER));
  124. +                       (this->selected_slot == OWNER_DEITY) ? TC_WHITE : (IsEditable(OWNER_DEITY) ? (_game_mode == GM_NORMAL) ? (IsDead(OWNER_DEITY)) ? TC_RED : TC_GREEN : TC_ORANGE : TC_SILVER));
  125.  
  126.                 break;
  127.             }
  128. @@ -812,7 +821,7 @@
  129.                 for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
  130.                     StringID text;
  131.  
  132. -                   if ((_game_mode != GM_NORMAL && i == 0) || (_game_mode == GM_NORMAL && Company::IsValidHumanID(i))) {
  133. +                   if (_game_mode == GM_NORMAL && Company::IsValidHumanID(i)) {
  134.                         text = STR_AI_CONFIG_HUMAN_PLAYER;
  135.                     } else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != NULL) {
  136.                         SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName());
  137. @@ -821,7 +830,7 @@
  138.                         text = STR_AI_CONFIG_RANDOM_AI;
  139.                     }
  140.                     DrawString(r.left + 10, r.right - 10, y + WD_MATRIX_TOP, text,
  141. -                           (this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER));
  142. +                           (this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? Company::IsValidAiID(i) ? IsDead((CompanyID)i) ? TC_RED : TC_GREEN : TC_ORANGE : TC_SILVER));
  143.                     y += this->line_height;
  144.                 }
  145.                 break;
  146. @@ -845,7 +854,7 @@
  147.                 if (widget == WID_AIC_DECREASE) {
  148.                     new_value = max(0, GetGameSettings().difficulty.max_no_competitors - 1);
  149.                 } else {
  150. -                   new_value = min(MAX_COMPANIES - 1, GetGameSettings().difficulty.max_no_competitors + 1);
  151. +                   new_value = min(MAX_COMPANIES, GetGameSettings().difficulty.max_no_competitors + 1);
  152.                 }
  153.                 IConsoleSetSetting("difficulty.max_no_competitors", new_value);
  154.                 this->InvalidateData();
  155. @@ -867,7 +876,7 @@
  156.             }
  157.  
  158.             case WID_AIC_MOVE_UP:
  159. -               if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) {
  160. +               if (IsEditable(this->selected_slot) && IsDead(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1)) && IsDead((CompanyID)(this->selected_slot - 1))) {
  161.                     Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]);
  162.                     this->selected_slot--;
  163.                     this->vscroll->ScrollTowards(this->selected_slot);
  164. @@ -876,7 +885,7 @@
  165.                 break;
  166.  
  167.             case WID_AIC_MOVE_DOWN:
  168. -               if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1))) {
  169. +               if (IsEditable(this->selected_slot) && IsDead(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1)) && IsDead((CompanyID)(this->selected_slot + 1))) {
  170.                     Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]);
  171.                     this->selected_slot++;
  172.                     this->vscroll->ScrollTowards(this->selected_slot);
  173. @@ -922,12 +931,21 @@
  174.         if (!gui_scope) return;
  175.  
  176.         this->SetWidgetDisabledState(WID_AIC_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0);
  177. -       this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
  178. -       this->SetWidgetDisabledState(WID_AIC_CHANGE, (this->selected_slot == OWNER_DEITY && _game_mode == GM_NORMAL) || this->selected_slot == INVALID_COMPANY);
  179. +       this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES);
  180. +       this->SetWidgetDisabledState(WID_AIC_CHANGE, this->selected_slot == INVALID_COMPANY || _game_mode == GM_NORMAL && (this->selected_slot == OWNER_DEITY || !IsDead(this->selected_slot)));
  181.         this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot)->GetConfigList()->size() == 0);
  182. -       this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1)));
  183. -       this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1)));
  184.  
  185. +       /* Display either Settings or Configure button */
  186. +       NWidgetCore *configure_button = this->GetWidget<NWidgetCore>(WID_AIC_CONFIGURE);
  187. +       if (_game_mode == GM_NORMAL && this->selected_slot != INVALID_COMPANY && !IsDead(this->selected_slot)) {
  188. +           configure_button->SetDataTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP);
  189. +       } else {
  190. +           configure_button->SetDataTip(STR_AI_CONFIG_CONFIGURE, STR_AI_CONFIG_CONFIGURE_TOOLTIP);
  191. +       }
  192. +
  193. +       this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == INVALID_COMPANY || this->selected_slot == OWNER_DEITY || !IsDead(this->selected_slot) || !IsEditable((CompanyID)(this->selected_slot - 1)) || !IsDead((CompanyID)(this->selected_slot - 1)));
  194. +       this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == INVALID_COMPANY || this->selected_slot == OWNER_DEITY || !IsDead(this->selected_slot) || !IsEditable((CompanyID)(this->selected_slot + 1)) || !IsDead((CompanyID)(this->selected_slot + 1)));
  195. +
  196.         for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
  197.             this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == NULL));
  198.         }
  199. @@ -991,19 +1009,6 @@
  200.     }
  201.  
  202.     /**
  203. -    * Check whether the currently selected AI/GS is dead.
  204. -    * @return true if dead.
  205. -    */
  206. -   bool IsDead() const
  207. -   {
  208. -       if (ai_debug_company == OWNER_DEITY) {
  209. -           GameInstance *game = Game::GetInstance();
  210. -           return game == NULL || game->IsDead();
  211. -       }
  212. -       return !Company::IsValidAiID(ai_debug_company) || Company::Get(ai_debug_company)->ai_instance->IsDead();
  213. -   }
  214. -
  215. -   /**
  216.      * Check whether a company is a valid AI company or GS.
  217.      * @param company Company to check for validity.
  218.      * @return true if company is valid for debugging.
  219. @@ -1276,7 +1281,7 @@
  220.  
  221.             case WID_AID_CONTINUE_BTN:
  222.                 /* Unpause current AI / game script and mark the corresponding script button dirty. */
  223. -               if (!this->IsDead()) {
  224. +               if (!IsDead(this->ai_debug_company)) {
  225.                     if (ai_debug_company == OWNER_DEITY) {
  226.                         Game::Unpause();
  227.                     } else {
  228. @@ -1336,7 +1341,7 @@
  229.                 this->break_string_filter.AddLine(log->lines[log->pos]);
  230.                 if (this->break_string_filter.GetState()) {
  231.                     /* Pause execution of script. */
  232. -                   if (!this->IsDead()) {
  233. +                   if (!IsDead(ai_debug_company)) {
  234.                         if (ai_debug_company == OWNER_DEITY) {
  235.                             Game::Pause();
  236.                         } else {
  237. @@ -1375,6 +1380,15 @@
  238.         this->SetWidgetLoweredState(WID_AID_MATCH_CASE_BTN, this->case_sensitive_break_check);
  239.  
  240.         this->SetWidgetDisabledState(WID_AID_SETTINGS, ai_debug_company == INVALID_COMPANY);
  241. +
  242. +       /* Display either Settings or Configure button */
  243. +       NWidgetCore *settings_button = this->GetWidget<NWidgetCore>(WID_AID_SETTINGS);
  244. +       if (ai_debug_company == INVALID_COMPANY || !IsDead(this->ai_debug_company)) {
  245. +           settings_button->SetDataTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP);
  246. +       } else {
  247. +           settings_button->SetDataTip(STR_AI_CONFIG_CONFIGURE, STR_AI_CONFIG_CONFIGURE_TOOLTIP);
  248. +       }
  249. +
  250.         this->SetWidgetDisabledState(WID_AID_RELOAD_TOGGLE, ai_debug_company == INVALID_COMPANY || ai_debug_company == OWNER_DEITY);
  251.         this->SetWidgetDisabledState(WID_AID_CONTINUE_BTN, ai_debug_company == INVALID_COMPANY ||
  252.                 (ai_debug_company == OWNER_DEITY ? !Game::IsPaused() : !AI::IsPaused(ai_debug_company)));
  253. Index: src/ai/ai_instance.cpp
  254. ===================================================================
  255. --- src/ai/ai_instance.cpp  (revision 27551)
  256. +++ src/ai/ai_instance.cpp  (working copy)
  257. @@ -81,6 +81,7 @@
  258.  
  259.  #include "../company_base.h"
  260.  #include "../company_func.h"
  261. +#include "../window_func.h"
  262.  
  263.  #include "../safeguards.h"
  264.  
  265. @@ -214,6 +215,7 @@
  266.     ScriptInstance::Died();
  267.  
  268.     ShowAIDebugWindow(_current_company);
  269. +   InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_AI);
  270.  
  271.     const AIInfo *info = AIConfig::GetConfig(_current_company, AIConfig::SSS_FORCE_GAME)->GetInfo();
  272.     if (info != NULL) {
  273. Index: src/game/game_instance.cpp
  274. ===================================================================
  275. --- src/game/game_instance.cpp  (revision 27551)
  276. +++ src/game/game_instance.cpp  (working copy)
  277. @@ -85,6 +85,8 @@
  278.  #include "../script/api/game/game_waypointlist.hpp.sq"
  279.  #include "../script/api/game/game_window.hpp.sq"
  280.  
  281. +#include "../window_func.h"
  282. +
  283.  #include "../safeguards.h"
  284.  
  285.  
  286. @@ -232,6 +234,7 @@
  287.     ScriptInstance::Died();
  288.  
  289.     ShowAIDebugWindow(OWNER_DEITY);
  290. +   InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_AI);
  291.  
  292.     const GameInfo *info = Game::GetInfo();
  293.     if (info != NULL) {
  294. Index: src/lang/english.txt
  295. ===================================================================
  296. --- src/lang/english.txt    (revision 27551)
  297. +++ src/lang/english.txt    (working copy)
  298. @@ -3979,10 +3979,10 @@
  299.  STR_ERROR_AI_DEBUG_SERVER_ONLY                                  :{YELLOW}AI/Game Script Debug window is only available for the server
  300.  
  301.  # AI configuration window
  302. -STR_AI_CONFIG_CAPTION                                           :{WHITE}AI/Game Script Configuration
  303. -STR_AI_CONFIG_GAMELIST_TOOLTIP                                  :{BLACK}The Game Script that will be loaded in the next game
  304. -STR_AI_CONFIG_AILIST_TOOLTIP                                    :{BLACK}The AIs that will be loaded in the next game
  305. -STR_AI_CONFIG_HUMAN_PLAYER                                      :Human player
  306. +STR_AI_CONFIG_CAPTION                                           :{WHITE}AI/Game Script Settings
  307. +STR_AI_CONFIG_GAMELIST_TOOLTIP                                  :{BLACK}The Game Script that is loaded or will be loaded in the next game
  308. +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
  309. +STR_AI_CONFIG_HUMAN_PLAYER                                      :Human Company
  310.  STR_AI_CONFIG_RANDOM_AI                                         :Random AI
  311.  STR_AI_CONFIG_NONE                                              :(none)
  312.  
  313. Index: src/table/settings.ini
  314. ===================================================================
  315. --- src/table/settings.ini  (revision 27551)
  316. +++ src/table/settings.ini  (working copy)
  317. @@ -103,7 +103,7 @@
  318.  from     = 97
  319.  def      = 0
  320.  min      = 0
  321. -max      = MAX_COMPANIES - 1
  322. +max      = MAX_COMPANIES
  323.  interval = 1
  324.  proc     = MaxNoAIsChange
  325.  cat      = SC_BASIC

Comments