17 | @@ -311,7 +311,7 @@
| | |
---|
18 | this->vscroll = this->GetScrollbar(WID_AIS_SCROLLBAR);
| | |
---|
19 | this->FinishInitNested(slot); // Initializes 'this->line_height' as side effect.
| | |
---|
20 |
| | |
---|
21 | - this->SetWidgetDisabledState(WID_AIS_RESET, _game_mode != GM_MENU && Company::IsValidID(this->slot));
| | |
---|
22 | + this->SetWidgetDisabledState(WID_AIS_RESET, _game_mode != GM_MENU && Company::IsValidAiID(this->slot) && !Company::Get(this->slot)->ai_instance->IsDead());
| | |
---|
23 |
| | |
---|
24 | this->vscroll->SetCount((int)this->visible_settings.size());
| | |
---|
25 | }
| | |
---|
26 | @@ -375,7 +375,7 @@
| | |
---|
27 | for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) {
| | |
---|
28 | const ScriptConfigItem &config_item = **it;
| | |
---|
29 | int current_value = config->GetSetting((config_item).name);
| | |
---|
30 | - bool editable = _game_mode == GM_MENU || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot)) || (config_item.flags & SCRIPTCONFIG_INGAME) != 0;
| | |
---|
31 | + bool editable = _game_mode == GM_MENU || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot)) || ((((config_item.flags & SCRIPTCONFIG_INGAME) != 0) || ((this->slot != OWNER_DEITY) && Company::IsValidAiID(this->slot) && Company::Get(this->slot)->ai_instance->IsDead())));
| | |
---|
32 |
| | |
---|
33 | StringID str;
| | |
---|
34 | TextColour colour;
| | |
---|
35 | @@ -438,7 +438,7 @@
| | |
---|
36 | VisibleSettingsList::const_iterator it = this->visible_settings.begin();
| | |
---|
37 | for (int i = 0; i < num; i++) it++;
| | |
---|
38 | const ScriptConfigItem config_item = **it;
| | |
---|
39 | - if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
| | |
---|
40 | + if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && ((config_item.flags & SCRIPTCONFIG_INGAME) == 0) && Company::IsValidAiID(this->slot) && !Company::Get(this->slot)->ai_instance->IsDead()) return;
| | |
---|
41 |
| | |
---|
42 | if (this->clicked_row != num) {
| | |
---|
43 | DeleteChildWindows(WC_QUERY_STRING);
| | |
---|
44 | @@ -519,7 +519,7 @@
| | |
---|
45 | break;
| | |
---|
46 |
| | |
---|
47 | case WID_AIS_RESET:
| | |
---|
48 | - if (_game_mode == GM_MENU || !Company::IsValidID(this->slot)) {
| | |
---|
49 | + if (_game_mode == GM_MENU || !Company::IsValidID(this->slot) || (this->slot != OWNER_DEITY && Company::IsValidAiID(this->slot) && Company::Get(this->slot)->ai_instance->IsDead())) {
| | |
---|
50 | this->ai_config->ResetSettings();
| | |
---|
51 | this->SetDirty();
| | |
---|
52 | }
| | |
---|
53 | @@ -532,7 +532,7 @@
| | |
---|
54 | if (StrEmpty(str)) return;
| | |
---|
55 | ScriptConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
| | |
---|
56 | for (int i = 0; i < this->clicked_row; i++) it++;
| | |
---|
57 | - if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (it->flags & SCRIPTCONFIG_INGAME) == 0) return;
| | |
---|
58 | + if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && ((it->flags & SCRIPTCONFIG_INGAME) == 0) && Company::IsValidAiID(this->slot) && !Company::Get(this->slot)->ai_instance->IsDead()) return;
| | |
---|
59 | int32 value = atoi(str);
| | |
---|
60 | this->ai_config->SetSetting((*it).name, value);
| | |
---|
61 | this->SetDirty();
| | |
---|
62 | @@ -543,7 +543,7 @@
| | |
---|
63 | assert(this->clicked_dropdown);
| | |
---|
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) || Company::IsValidID(this->slot)) && ((it->flags & SCRIPTCONFIG_INGAME) == 0) && Company::IsValidAiID(this->slot) && !Company::Get(this->slot)->ai_instance->IsDead()) return;
| | |
---|
68 | this->ai_config->SetSetting((*it).name, index);
| | |
---|
69 | this->SetDirty();
| | |
---|
70 | }
| | |
---|
99 | }
| 99 | } |
---|
100 |
| | |
---|
101 | @@ -779,11 +793,11 @@
| | |
---|
102 | if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL || Game::GetInstance() != NULL;
| | |
---|
103 |
| | |
---|
104 | if (_game_mode != GM_NORMAL) {
| | |
---|
105 | - return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors;
| | |
---|
106 | + return slot >= 0 && slot <= MAX_COMPANIES - 1;
| | |
---|
107 | }
| | |
---|
108 | - if (Company::IsValidID(slot) || slot < 0) return false;
| | |
---|
109 | + if (Company::IsValidHumanID(slot) || slot < 0) return false;
| | |
---|
110 |
| | |
---|
111 | - int max_slot = GetGameSettings().difficulty.max_no_competitors;
| | |
---|
112 | + int max_slot = MAX_COMPANIES;
| | |
---|
113 | for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
| | |
---|
114 | if (Company::IsValidHumanID(cid)) max_slot++;
| | |
---|
115 | }
| | |
---|
116 | @@ -802,7 +816,7 @@
| | |
---|
117 | }
| | |
---|
118 |
| | |
---|
119 | DrawString(r.left + 10, r.right - 10, r.top + WD_MATRIX_TOP, text,
| | |
---|
120 | - (this->selected_slot == OWNER_DEITY) ? TC_WHITE : (IsEditable(OWNER_DEITY) ? TC_ORANGE : TC_SILVER));
| | |
---|
121 | + (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));
| | |
---|
122 |
| | |
---|
123 | break;
| | |
---|
124 | }
| | |
---|
125 | @@ -812,7 +826,7 @@
| | |
---|
126 | for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
| | |
---|
127 | StringID text;
| | |
---|
128 |
| | |
---|
129 | - if ((_game_mode != GM_NORMAL && i == 0) || (_game_mode == GM_NORMAL && Company::IsValidHumanID(i))) {
| | |
---|
130 | + if (_game_mode == GM_NORMAL && Company::IsValidHumanID(i)) {
| | |
---|
131 | text = STR_AI_CONFIG_HUMAN_PLAYER;
| | |
---|
132 | } else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != NULL) {
| | |
---|
133 | SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName());
| | |
---|
134 | @@ -821,7 +835,7 @@
| | |
---|
135 | text = STR_AI_CONFIG_RANDOM_AI;
| | |
---|
136 | }
| | |
---|
137 | DrawString(r.left + 10, r.right - 10, y + WD_MATRIX_TOP, text,
| | |
---|
138 | - (this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER));
| | |
---|
139 | + (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));
| | |
---|
140 | y += this->line_height;
| | |
---|
141 | }
| | |
---|
142 | break;
| | |
---|
143 | @@ -837,6 +851,12 @@
| | |
---|
144 | ShowScriptTextfileWindow((TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot);
| | |
---|
145 | return;
| | |
---|
146 | }
| | |
---|
147 | + bool is_orange_slot = IsEditable((CompanyID)(this->selected_slot)) && !Company::IsValidID(this->selected_slot);
| | |
---|
148 | + bool is_red_slot = IsEditable((CompanyID)(this->selected_slot)) && Company::IsValidID(this->selected_slot) && Company::IsValidAiID(this->selected_slot) && Company::Get(this->selected_slot)->ai_instance->IsDead();
| | |
---|
149 | + bool is_orange_slot_above = IsEditable((CompanyID)(this->selected_slot - 1)) && !Company::IsValidID(this->selected_slot - 1);
| | |
---|
150 | + bool is_orange_slot_below = IsEditable((CompanyID)(this->selected_slot + 1)) && !Company::IsValidID(this->selected_slot + 1);
| | |
---|
151 | + bool is_red_slot_above = IsEditable((CompanyID)(this->selected_slot - 1)) && Company::IsValidID(this->selected_slot - 1) && Company::IsValidAiID(this->selected_slot - 1) && Company::Get(this->selected_slot - 1)->ai_instance->IsDead();
| | |
---|
152 | + bool is_red_slot_below = IsEditable((CompanyID)(this->selected_slot + 1)) && Company::IsValidID(this->selected_slot + 1) && Company::IsValidAiID(this->selected_slot + 1) && Company::Get(this->selected_slot + 1)->ai_instance->IsDead();
| | |
---|
153 |
| | |
---|
154 | switch (widget) {
| | |
---|
155 | case WID_AIC_DECREASE:
| | |
---|
156 | @@ -845,7 +865,7 @@
| | |
---|
157 | if (widget == WID_AIC_DECREASE) {
| | |
---|
158 | new_value = max(0, GetGameSettings().difficulty.max_no_competitors - 1);
| | |
---|
159 | } else {
| | |
---|
160 | - new_value = min(MAX_COMPANIES - 1, GetGameSettings().difficulty.max_no_competitors + 1);
| | |
---|
161 | + new_value = min(MAX_COMPANIES, GetGameSettings().difficulty.max_no_competitors + 1);
| | |
---|
162 | }
| | |
---|
163 | IConsoleSetSetting("difficulty.max_no_competitors", new_value);
| | |
---|
164 | this->InvalidateData();
| | |
---|
165 | @@ -867,7 +887,7 @@
| | |
---|
166 | }
| | |
---|
167 |
| | |
---|
168 | case WID_AIC_MOVE_UP:
| | |
---|
169 | - if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) {
| | |
---|
170 | + if ((is_orange_slot || is_red_slot) && (is_orange_slot_above || is_red_slot_above)) {
| | |
---|
171 | Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]);
| | |
---|
172 | this->selected_slot--;
| | |
---|
173 | this->vscroll->ScrollTowards(this->selected_slot);
| | |
---|
174 | @@ -876,7 +896,7 @@
| | |
---|
175 | break;
| | |
---|
176 |
| | |
---|
177 | case WID_AIC_MOVE_DOWN:
| | |
---|
178 | - if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1))) {
| | |
---|
179 | + if ((is_orange_slot || is_red_slot) && (is_orange_slot_below || is_red_slot_below)) {
| | |
---|
180 | Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]);
| | |
---|
181 | this->selected_slot++;
| | |
---|
182 | this->vscroll->ScrollTowards(this->selected_slot);
| | |
---|
183 | @@ -921,15 +941,23 @@
| | |
---|
184 |
| | |
---|
185 | if (!gui_scope) return;
| | |
---|
186 |
| | |
---|
187 | + bool is_gs_slot = this->selected_slot == OWNER_DEITY;
| | |
---|
188 | + bool invalid_slot = this->selected_slot == INVALID_COMPANY;
| | |
---|
189 | + bool is_green_slot = IsEditable((CompanyID)(this->selected_slot)) && Company::IsValidID(this->selected_slot) && Company::IsValidAiID(this->selected_slot) && !Company::Get(this->selected_slot)->ai_instance->IsDead();
| | |
---|
190 | + bool is_silver_slot_above = !IsEditable((CompanyID)(this->selected_slot - 1));
| | |
---|
191 | + bool is_silver_slot_below = !IsEditable((CompanyID)(this->selected_slot + 1));
| | |
---|
192 | + bool is_green_slot_above = IsEditable((CompanyID)(this->selected_slot - 1)) && Company::IsValidID(this->selected_slot - 1) && Company::IsValidAiID(this->selected_slot - 1) && !Company::Get(this->selected_slot - 1)->ai_instance->IsDead();
| | |
---|
193 | + bool is_green_slot_below = IsEditable((CompanyID)(this->selected_slot + 1)) && Company::IsValidID(this->selected_slot + 1) && Company::IsValidAiID(this->selected_slot + 1) && !Company::Get(this->selected_slot + 1)->ai_instance->IsDead();
| | |
---|
194 | +
| | |
---|
195 | this->SetWidgetDisabledState(WID_AIC_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0);
| | |
---|
196 | - this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
| | |
---|
197 | - this->SetWidgetDisabledState(WID_AIC_CHANGE, (this->selected_slot == OWNER_DEITY && _game_mode == GM_NORMAL) || this->selected_slot == INVALID_COMPANY);
| | |
---|
198 | - this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot)->GetConfigList()->size() == 0);
| | |
---|
199 | - this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1)));
| | |
---|
200 | - this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1)));
| | |
---|
201 | + this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES);
| | |
---|
202 | + this->SetWidgetDisabledState(WID_AIC_CHANGE, _game_mode == GM_NORMAL && (is_gs_slot || is_green_slot) || invalid_slot);
| | |
---|
203 | + this->SetWidgetDisabledState(WID_AIC_CONFIGURE, invalid_slot || GetConfig(this->selected_slot)->GetConfigList()->size() == 0);
| | |
---|
204 | + this->SetWidgetDisabledState(WID_AIC_MOVE_UP, is_gs_slot || invalid_slot || is_green_slot || is_silver_slot_above || is_green_slot_above);
| | |
---|
205 | + this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, is_gs_slot || invalid_slot || is_green_slot || is_silver_slot_below || is_green_slot_below);
| | |
---|
206 |
| | |
---|
207 | for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
| | |
---|
208 | - this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == NULL));
| | |
---|
209 | + this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, invalid_slot || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == NULL));
| | |
---|
210 | }
| | |
---|
211 | }
| | |
---|
212 | };
| | |
---|
213 | Index: src/ai/ai_instance.cpp
| | |
---|
214 | ===================================================================
| | |
---|
215 | --- src/ai/ai_instance.cpp (revision 27549)
| | |
---|
216 | +++ src/ai/ai_instance.cpp (working copy)
| | |
---|
217 | @@ -81,6 +81,7 @@
| | |
---|
218 |
| | |
---|
219 | #include "../company_base.h"
| | |
---|
220 | #include "../company_func.h"
| | |
---|
221 | +#include "../window_func.h"
| | |
---|
222 |
| | |
---|
223 | #include "../safeguards.h"
| | |
---|
224 |
| | |
---|
225 | @@ -214,6 +215,7 @@
| | |
---|
226 | ScriptInstance::Died();
| | |
---|
227 |
| | |
---|
228 | ShowAIDebugWindow(_current_company);
| | |
---|
229 | + InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_AI);
| | |
---|
230 |
| | |
---|
231 | const AIInfo *info = AIConfig::GetConfig(_current_company, AIConfig::SSS_FORCE_GAME)->GetInfo();
| | |
---|
232 | if (info != NULL) {
| | |
---|
233 | Index: src/game/game_instance.cpp
| | |
---|
234 | ===================================================================
| | |
---|
235 | --- src/game/game_instance.cpp (revision 27549)
| | |
---|
236 | +++ src/game/game_instance.cpp (working copy)
| | |
---|
237 | @@ -85,6 +85,8 @@
| | |
---|
238 | #include "../script/api/game/game_waypointlist.hpp.sq"
| | |
---|
239 | #include "../script/api/game/game_window.hpp.sq"
| | |
---|
240 |
| | |
---|
241 | +#include "../window_func.h"
| | |
---|
242 | +
| | |
---|
243 | #include "../safeguards.h"
| | |
---|
244 |
| | |
---|
245 |
| | |
---|
246 | @@ -232,6 +234,7 @@
| | |
---|
247 | ScriptInstance::Died();
| | |
---|
248 |
| | |
---|
249 | ShowAIDebugWindow(OWNER_DEITY);
| | |
---|
250 | + InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_AI);
| | |
---|
251 |
| | |
---|
252 | const GameInfo *info = Game::GetInfo();
| | |
---|
253 | if (info != NULL) {
| | |
---|
254 | Index: src/lang/english.txt
| | |
---|
255 | ===================================================================
| | |
---|
256 | --- src/lang/english.txt (revision 27549)
| | |
---|
257 | +++ src/lang/english.txt (working copy)
| | |
---|
258 | @@ -3982,7 +3982,7 @@
| | |
---|
259 | STR_AI_CONFIG_CAPTION :{WHITE}AI/Game Script Configuration
| | |
---|
260 | STR_AI_CONFIG_GAMELIST_TOOLTIP :{BLACK}The Game Script that will be loaded in the next game
| | |
---|
261 | STR_AI_CONFIG_AILIST_TOOLTIP :{BLACK}The AIs that will be loaded in the next game
| | |
---|
262 | -STR_AI_CONFIG_HUMAN_PLAYER :Human player
| | |
---|
263 | +STR_AI_CONFIG_HUMAN_PLAYER :Human Company
| | |
---|
264 | STR_AI_CONFIG_RANDOM_AI :Random AI
| | |
---|
265 | STR_AI_CONFIG_NONE :(none)
| | |
---|
266 |
| | |
---|
267 | Index: src/table/settings.ini
| | |
---|
268 | ===================================================================
| | |
---|
269 | --- src/table/settings.ini (revision 27549)
| | |
---|
270 | +++ src/table/settings.ini (working copy)
| | |
---|
271 | @@ -103,7 +103,7 @@
| | |
---|
272 | from = 97
| | |
---|
273 | def = 0
| | |
---|
274 | min = 0
| | |
---|
275 | -max = MAX_COMPANIES - 1
| | |
---|
276 | +max = MAX_COMPANIES
| | |
---|
277 | interval = 1
| | |
---|
278 | proc = MaxNoAIsChange
| | |
---|
279 | cat = SC_BASIC | | |
---|