max_no_competitors = 15 patch

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

max_no_competitors = 15 patch

Post by xarick »

Download last version there (v33) -> viewtopic.php?p=1194298#p1194298

List of current features for this patch (v33):

a) Maximum no. competitors cap have been raised from 14 to 15. This is useful for multiplayer and dedicated server games.

b) All slots are configurable and visible, regardless of the current value of Maximum no. competitors. This means they're all highlighted in orange text in the AI/Game Script Configuration/Settings window.
b.1) AI slots are identified with its respective Company ID number.
b.2) Status icons may be displayed next to each slot to reflect the current state of a script.
b.2.1) A Warning Sign indicates that a Human Company is, or will be in this slot and that this AI configuration won't be used.
b.2.2) Yellow indicates an eligible AI or GS that is yet to start.
b.2.3) Green indicates an AI or GS script in this slot that started and is alive.
b.2.4) Red indicates an AI or GS script in this slot that started but died.
b.2.5) No Yellow icons are displayed if the value of Maximum no. competitors doesn't allow more AIs to start, or if no GS is configured.
b.3) AIs that started as random are identifiable with a newspaper icon next to the first icon.

c) Note: While in the main menu, slot 1 may be configurable, but beware: when starting a single or multiplayer game, the first company is always human and will start on slot 1. Making slot 1 configurable from gui is especialy useful when setting AIs for multiplayer or dedicated server games.

d) While in a game, depending on the status, some slots in the AI/Game Script Settings window have these additional behaviours:
d.1) Warning sign - Permits AI slot movement up or down. Permits selection of another AI. Displays the "Configure" button. Permits changes to all AI parameters.
d.2) Yellow status - Permits AI slot movement up or down. Permits selection of another AI. Displays the "Configure" button. Permits changes to all AI parameters.
d.3) Green status - Disables AI slot movement up or down. Disables selection of another AI or GS. Displays the "Settings" button. Permits changes to some AI or GS parameters.
d.4) Red status - Disables AI slot movement up or down. Disables selection of another AI or GS. Displays the "Configure" button. Permits changes to all AI or GS parameters.
d.5) No status displayed - Permits AI slot movement up or down. Permits selection of another AI. Displays the "Configure" button. Permits changes to all AI parameters.

e) While a game is running, AIs can be started or stopped from the AI/Game Script Settings window. You may also alter their parameters if you so desire:
e.1) To stop an AI, select the AI from the list, then click Stop AI. Be aware that by doing so, you are removing the AI Company from the game.
e.2) If the current number of running AI companies is less than the maximum number of competitors, you may start an AI on any empty slot by selecting it and clicking Start AI.
e.3) If you are receiving a message telling that you can't start an AI, make sure you are allowing AI competitors in multiplayer games.

f) While hosting a server, AIs or GS are not going to be requested to save their data when a client attempts to join. But should you manually save the game or perform autosaves, AIs or GS are still going to be requested to save their data. This permits scripts that usually take too long to save to be useable while running a server for as long as no autosaves or manual saves are done during the session.

Screenshot valid for v30, v31, v32, v33
Image

Screenshot valid for v21, v22, v23, v24, v25, v26
Image

Screenshot valid for v15
Image

Screenshot valid for v14
Image

Screenshot valid for v10
Image

Screenshot valid for v4, v5, v6, v7
Image


Previous versions (v3, v2, v1):
[+] Spoiler
max_no_competitors = 15 v3 r27536.patch
(3.38 KiB) Downloaded 134 times

Code: Select all

Index: ai/ai_gui.cpp
===================================================================
--- ai/ai_gui.cpp	(revision 27536)
+++ ai/ai_gui.cpp	(working copy)
@@ -779,11 +779,11 @@
 		if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL || Game::GetInstance() != NULL;
 
 		if (_game_mode != GM_NORMAL) {
-			return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors;
+			return slot >= 0 && slot <= MAX_COMPANIES - 1;
 		}
-		if (Company::IsValidID(slot) || slot < 0) return false;
+		if (Company::IsValidHumanID(slot) || slot < 0) return false;
 
-		int max_slot = GetGameSettings().difficulty.max_no_competitors;
+		int max_slot = MAX_COMPANIES - 1;
 		for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
 			if (Company::IsValidHumanID(cid)) max_slot++;
 		}
@@ -812,7 +812,7 @@
 				for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
 					StringID text;
 
-					if ((_game_mode != GM_NORMAL && i == 0) || (_game_mode == GM_NORMAL && Company::IsValidHumanID(i))) {
+					if (_game_mode == GM_NORMAL && Company::IsValidHumanID(i)) {
 						text = STR_AI_CONFIG_HUMAN_PLAYER;
 					} else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != NULL) {
 						SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName());
@@ -821,7 +821,7 @@
 						text = STR_AI_CONFIG_RANDOM_AI;
 					}
 					DrawString(r.left + 10, r.right - 10, y + WD_MATRIX_TOP, text,
-							(this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER));
+							(this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? (Company::IsValidAiID(i)) ? TC_BLUE : TC_ORANGE : TC_SILVER));
 					y += this->line_height;
 				}
 				break;
@@ -845,7 +845,7 @@
 				if (widget == WID_AIC_DECREASE) {
 					new_value = max(0, GetGameSettings().difficulty.max_no_competitors - 1);
 				} else {
-					new_value = min(MAX_COMPANIES - 1, GetGameSettings().difficulty.max_no_competitors + 1);
+					new_value = min(MAX_COMPANIES, GetGameSettings().difficulty.max_no_competitors + 1);
 				}
 				IConsoleSetSetting("difficulty.max_no_competitors", new_value);
 				this->InvalidateData();
@@ -922,7 +922,7 @@
 		if (!gui_scope) return;
 
 		this->SetWidgetDisabledState(WID_AIC_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0);
-		this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
+		this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES);
 		this->SetWidgetDisabledState(WID_AIC_CHANGE, (this->selected_slot == OWNER_DEITY && _game_mode == GM_NORMAL) || this->selected_slot == INVALID_COMPANY);
 		this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot)->GetConfigList()->size() == 0);
 		this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1)));
Index: table/settings.ini
===================================================================
--- table/settings.ini	(revision 27536)
+++ table/settings.ini	(working copy)
@@ -103,7 +103,7 @@
 from     = 97
 def      = 0
 min      = 0
-max      = MAX_COMPANIES - 1
+max      = MAX_COMPANIES
 interval = 1
 proc     = MaxNoAIsChange
 cat      = SC_BASIC
This patch allows up to 15 AIs to be automatically started on dedicated servers by increasing the cap from 14 to 15. This setting can also be configured from the main menu.

v3 r27536:
- All 15 slots are configurable now, regardless of the current value of Maximum no. competitors. This means they're all highlighted as orange.
- During a game, AI slots that started are highlighted as blue, instead of silver. Human occupied slots are still in silver. All other slots are orange.
- In addition, blue slots can be altered from its current AI script to another. To start the newly selected AI, click Reload in the AI Debug window.

To do:
- Switching AI scripts while another is running is buggy, though. Parameters from the newly selected AI will be in conflict with the parameters from the previous AI. I'd like to improve on this.

max_no_competitors = 15 v2 r27536.patch
(2.99 KiB) Downloaded 139 times
v2 r27536:
- slot 1 may now be configurable from the main menu.
- Maximum no. competitors setting now affect the entire range of slots, from 1 to 15.
- I'm still not happy about the interaction between the max no. competitors setting. As an example, with this patch, if I set a max of 10 competitors, then start a single player or non-dedicated multiplayer game, the first slot will be immediately taken by a human, but only the first 10 slots were configured from the main menu. The game will still start 10 AI's, the 10th AI taking use of whatever configuration was in the locked 11th slot. Maybe I should just unlock the entire slots, independently of the max no of competitor value.
max_no_competitors = 15 v1 r27529.patch
(1.83 KiB) Downloaded 146 times
v1 r27529:
- I'd like to improve the gui window even further, though. It currently doesn't let configure the AI parameters for slot 1 because of the Human player.
Last edited by xarick on 20 Nov 2017 22:26, edited 68 times in total.
Formerly known as Samu
User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: max_no_competitors = 15 patch

Post by HackaLittleBit »

Is AI allowed to post in this Forum?
AI is taking over! :wink:
TrueSatan
Transport Coordinator
Transport Coordinator
Posts: 291
Joined: 16 Jul 2003 18:33

Re: max_no_competitors = 15 patch

Post by TrueSatan »

HackaLittleBit wrote:Is AI allowed to post in this Forum?
AI is taking over! :wink:
Haha Hack, it was not Skynet taking over it was OTTD-Net AI taking over.
Wonder how the Terminator will look like then... Transformers but loco style :D
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: max_no_competitors = 15 patch

Post by xarick »

Previous versions (v6, v5, v4):
[+] Spoiler
max_no_competitors = 15 v6 r27537.patch
(8.95 KiB) Downloaded 127 times
v6 r27537
This version attempts to uniform the behaviour and color rules for both AI and GS slots wherever possible.
- Green AI and GS slots can be selectable. The currently selected AI or GS script cannot be altered to another. The currently selected AI or GS script configuration can be opened and, if permitable by the script, its parameters may be altered.
- Red AI and GS slots can be selectable. The currently selected AI script can be altered to another, but the GS script cannot. The currently selected AI or GS script configuration can be opened. All AI parameters can be altered. Permitable GS parameters may be altered.
- The AI configuration window closes itself now whenever an AI company that makes use of that slot configuration starts.

max_no_competitors = 15 v5 r27537.patch
(3.92 KiB) Downloaded 128 times
v5 r27537
- Fixed the bug that prevented slot 15 to be edited once an AI died at company 15.
- While a game is running, the game script slot is highligthed in green or red, depending if it's still running or dead.

max_no_competitors = 15 v4 r27536.patch
(3.52 KiB) Downloaded 149 times
v4 r27536

Text coloring rules have changed in relation to those in v3:
- Red indicates a company slot started by an AI with its script currently dead. This slot can be edited while a game is running.
- Green indicates a company slot started by an AI with its script currently running. This slot can't be edited while a game is running.
- Silver indicates a company slot started by a Human player. This slot can't be edited while a game is running.
- Orange indicates a company slot that hasn't started. This slot can be edited while a game is running.

bug detected:
- When an AI script dies on slot 15, the slot doesn't become red, nor editable.
Last edited by xarick on 11 Apr 2016 18:40, edited 1 time in total.
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: max_no_competitors = 15 patch

Post by xarick »

max_no_competitors = 15 v7 r27537.patch
(13.05 KiB) Downloaded 147 times
[+] Spoiler

Code: Select all

Index: src/ai/ai_core.cpp
===================================================================
--- src/ai/ai_core.cpp	(revision 27537)
+++ src/ai/ai_core.cpp	(working copy)
@@ -62,6 +62,7 @@
 	cur_company.Restore();
 
 	InvalidateWindowData(WC_AI_DEBUG, 0, -1);
+	DeleteWindowById(WC_AI_SETTINGS, company);
 	return;
 }
 
Index: src/ai/ai_gui.cpp
===================================================================
--- src/ai/ai_gui.cpp	(revision 27537)
+++ src/ai/ai_gui.cpp	(working copy)
@@ -311,7 +311,7 @@
 		this->vscroll = this->GetScrollbar(WID_AIS_SCROLLBAR);
 		this->FinishInitNested(slot);  // Initializes 'this->line_height' as side effect.
 
-		this->SetWidgetDisabledState(WID_AIS_RESET, _game_mode != GM_MENU && Company::IsValidID(this->slot));
+		this->SetWidgetDisabledState(WID_AIS_RESET, _game_mode != GM_MENU && Company::IsValidAiID(this->slot) && !Company::Get(this->slot)->ai_instance->IsDead());
 
 		this->vscroll->SetCount((int)this->visible_settings.size());
 	}
@@ -375,7 +375,7 @@
 		for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) {
 			const ScriptConfigItem &config_item = **it;
 			int current_value = config->GetSetting((config_item).name);
-			bool editable = _game_mode == GM_MENU || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot)) || (config_item.flags & SCRIPTCONFIG_INGAME) != 0;
+			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())));
 
 			StringID str;
 			TextColour colour;
@@ -438,7 +438,7 @@
 				VisibleSettingsList::const_iterator it = this->visible_settings.begin();
 				for (int i = 0; i < num; i++) it++;
 				const ScriptConfigItem config_item = **it;
-				if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
+				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;
 
 				if (this->clicked_row != num) {
 					DeleteChildWindows(WC_QUERY_STRING);
@@ -519,7 +519,7 @@
 				break;
 
 			case WID_AIS_RESET:
-				if (_game_mode == GM_MENU || !Company::IsValidID(this->slot)) {
+				if (_game_mode == GM_MENU || !Company::IsValidID(this->slot) || (this->slot != OWNER_DEITY && Company::IsValidAiID(this->slot) && Company::Get(this->slot)->ai_instance->IsDead())) {
 					this->ai_config->ResetSettings();
 					this->SetDirty();
 				}
@@ -532,7 +532,7 @@
 		if (StrEmpty(str)) return;
 		ScriptConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
 		for (int i = 0; i < this->clicked_row; i++) it++;
-		if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (it->flags & SCRIPTCONFIG_INGAME) == 0) return;
+		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;
 		int32 value = atoi(str);
 		this->ai_config->SetSetting((*it).name, value);
 		this->SetDirty();
@@ -543,7 +543,7 @@
 		assert(this->clicked_dropdown);
 		ScriptConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
 		for (int i = 0; i < this->clicked_row; i++) it++;
-		if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (it->flags & SCRIPTCONFIG_INGAME) == 0) return;
+		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;
 		this->ai_config->SetSetting((*it).name, index);
 		this->SetDirty();
 	}
@@ -779,11 +779,11 @@
 		if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL || Game::GetInstance() != NULL;
 
 		if (_game_mode != GM_NORMAL) {
-			return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors;
+			return slot >= 0 && slot <= MAX_COMPANIES - 1;
 		}
-		if (Company::IsValidID(slot) || slot < 0) return false;
+		if (Company::IsValidHumanID(slot) || slot < 0) return false;
 
-		int max_slot = GetGameSettings().difficulty.max_no_competitors;
+		int max_slot = MAX_COMPANIES;
 		for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
 			if (Company::IsValidHumanID(cid)) max_slot++;
 		}
@@ -802,7 +802,7 @@
 				}
 
 				DrawString(r.left + 10, r.right - 10, r.top + WD_MATRIX_TOP, text,
-						(this->selected_slot == OWNER_DEITY) ? TC_WHITE : (IsEditable(OWNER_DEITY) ? TC_ORANGE : TC_SILVER));
+						(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));
 
 				break;
 			}
@@ -812,7 +812,7 @@
 				for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
 					StringID text;
 
-					if ((_game_mode != GM_NORMAL && i == 0) || (_game_mode == GM_NORMAL && Company::IsValidHumanID(i))) {
+					if (_game_mode == GM_NORMAL && Company::IsValidHumanID(i)) {
 						text = STR_AI_CONFIG_HUMAN_PLAYER;
 					} else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != NULL) {
 						SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName());
@@ -821,7 +821,7 @@
 						text = STR_AI_CONFIG_RANDOM_AI;
 					}
 					DrawString(r.left + 10, r.right - 10, y + WD_MATRIX_TOP, text,
-							(this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER));
+							(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));
 					y += this->line_height;
 				}
 				break;
@@ -837,6 +837,12 @@
 			ShowScriptTextfileWindow((TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot);
 			return;
 		}
+		bool is_orange_slot = IsEditable((CompanyID)(this->selected_slot)) && !Company::IsValidID(this->selected_slot);
+		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();
+		bool is_orange_slot_above = IsEditable((CompanyID)(this->selected_slot - 1)) && !Company::IsValidID(this->selected_slot - 1);
+		bool is_orange_slot_below = IsEditable((CompanyID)(this->selected_slot + 1)) && !Company::IsValidID(this->selected_slot + 1);
+		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();
+		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();
 
 		switch (widget) {
 			case WID_AIC_DECREASE:
@@ -845,7 +851,7 @@
 				if (widget == WID_AIC_DECREASE) {
 					new_value = max(0, GetGameSettings().difficulty.max_no_competitors - 1);
 				} else {
-					new_value = min(MAX_COMPANIES - 1, GetGameSettings().difficulty.max_no_competitors + 1);
+					new_value = min(MAX_COMPANIES, GetGameSettings().difficulty.max_no_competitors + 1);
 				}
 				IConsoleSetSetting("difficulty.max_no_competitors", new_value);
 				this->InvalidateData();
@@ -867,7 +873,7 @@
 			}
 
 			case WID_AIC_MOVE_UP:
-				if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) {
+				if ((is_orange_slot || is_red_slot) && (is_orange_slot_above || is_red_slot_above)) {
 					Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]);
 					this->selected_slot--;
 					this->vscroll->ScrollTowards(this->selected_slot);
@@ -876,7 +882,7 @@
 				break;
 
 			case WID_AIC_MOVE_DOWN:
-				if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1))) {
+				if ((is_orange_slot || is_red_slot) && (is_orange_slot_below || is_red_slot_below)) {
 					Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]);
 					this->selected_slot++;
 					this->vscroll->ScrollTowards(this->selected_slot);
@@ -921,15 +927,23 @@
 
 		if (!gui_scope) return;
 
+		bool is_gs_slot = this->selected_slot == OWNER_DEITY;
+		bool invalid_slot = this->selected_slot == INVALID_COMPANY;
+		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();
+		bool is_silver_slot_above = !IsEditable((CompanyID)(this->selected_slot - 1));
+		bool is_silver_slot_below = !IsEditable((CompanyID)(this->selected_slot + 1));
+		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();
+		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();
+
 		this->SetWidgetDisabledState(WID_AIC_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0);
-		this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
-		this->SetWidgetDisabledState(WID_AIC_CHANGE, (this->selected_slot == OWNER_DEITY && _game_mode == GM_NORMAL) || this->selected_slot == INVALID_COMPANY);
-		this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot)->GetConfigList()->size() == 0);
-		this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1)));
-		this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1)));
+		this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES);
+		this->SetWidgetDisabledState(WID_AIC_CHANGE, _game_mode == GM_NORMAL && (is_gs_slot || is_green_slot) || invalid_slot);
+		this->SetWidgetDisabledState(WID_AIC_CONFIGURE,	invalid_slot || GetConfig(this->selected_slot)->GetConfigList()->size() == 0);
+		this->SetWidgetDisabledState(WID_AIC_MOVE_UP, is_gs_slot || invalid_slot || is_green_slot || is_silver_slot_above || is_green_slot_above);
+		this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, is_gs_slot || invalid_slot || is_green_slot || is_silver_slot_below || is_green_slot_below);
 
 		for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
-			this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == NULL));
+			this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, invalid_slot || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == NULL));
 		}
 	}
 };
Index: src/ai/ai_instance.cpp
===================================================================
--- src/ai/ai_instance.cpp	(revision 27537)
+++ src/ai/ai_instance.cpp	(working copy)
@@ -81,6 +81,7 @@
 
 #include "../company_base.h"
 #include "../company_func.h"
+#include "../window_func.h"
 
 #include "../safeguards.h"
 
@@ -214,6 +215,7 @@
 	ScriptInstance::Died();
 
 	ShowAIDebugWindow(_current_company);
+	InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_AI);
 
 	const AIInfo *info = AIConfig::GetConfig(_current_company, AIConfig::SSS_FORCE_GAME)->GetInfo();
 	if (info != NULL) {
Index: src/game/game_instance.cpp
===================================================================
--- src/game/game_instance.cpp	(revision 27537)
+++ src/game/game_instance.cpp	(working copy)
@@ -85,6 +85,8 @@
 #include "../script/api/game/game_waypointlist.hpp.sq"
 #include "../script/api/game/game_window.hpp.sq"
 
+#include "../window_func.h"
+
 #include "../safeguards.h"
 
 
@@ -232,6 +234,7 @@
 	ScriptInstance::Died();
 
 	ShowAIDebugWindow(OWNER_DEITY);
+	InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_AI);
 
 	const GameInfo *info = Game::GetInfo();
 	if (info != NULL) {
Index: src/table/settings.ini
===================================================================
--- src/table/settings.ini	(revision 27537)
+++ src/table/settings.ini	(working copy)
@@ -103,7 +103,7 @@
 from     = 97
 def      = 0
 min      = 0
-max      = MAX_COMPANIES - 1
+max      = MAX_COMPANIES
 interval = 1
 proc     = MaxNoAIsChange
 cat      = SC_BASIC
v7 r27537
- Additional checks for moving AIs slots up and down were missing in the previous version. They have been implemented in this version.
- The listing of slots now properly refreshes itself when AIs and GS die.
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: max_no_competitors = 15 patch

Post by xarick »

Previous versions (v10, v9, v8):
[+] Spoiler
max_no_competitors = 15 v10 r27553.patch
(22.15 KiB) Downloaded 129 times
v10 r27553:
- Fixed a bug that would crash OpenTTD because slot 15 could be moved down from the configuration list and it shouldn't.
- All 15 slots are now displayed in the configuration list.
- "AI/Game Script Settings" in Main Menu renamed to "AI/Game Script Configuration".
- The toolbar Options dropdown now displays either "AI/Game script settings" while in a game, or "AI/Game script configuration" while not (scenario editor).
- "AI/Game Script Settings" window now displays either "AI/Game Script Settings" while in a game, or "AI/Game Script Configuration" while not (scenario editor or main menu).
- Attempt to simplify most booleans in the code for better readability.

To do:
- Remove the vertical scrollbar from the AI/GS Config list.
- Add Company #1-15 to the list of slots #1-15.
- Find a way to easily identify an AI that started as Random AI while in a game.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.



max_no_competitors = 15 v9 r27550.patch
(15.86 KiB) Downloaded 134 times
v9 r27550:

Some bugs have been found and fixed. Also, the behaviour rules for the GS scripts' Parameters have changed slightly in an attempt to further uniform AI and GS behaviours.
- The Parameters window now closes itself if it's open while accepting an AI/GS from the list of available AI/GS window. This prevents possible bugs that would allow OpenTTD to crash.
- The Reset button in the Parameters window now becomes disabled in a game when a GS is active but not dead.
- While in a game, all GS Parameters are now editable when a GS is active but dead, not just those that were permissible.
- Fixed various bugs that were allowing locked Parameters values to be changed when they should not while in a game (arrows, dropdown and text input).
- Fixed a bug that allowed the Reset button in the Parameters window to reset the values of locked GS Parameters while in a game.
- Fixed a bug in the AI/GS Script Settings window that prevented slot 1 to be switched with slot 2 while in main menu.
- The AI/GS Script Settings and the AI/GS Debug windows now display the Settings button instead of the Configure button, if the GS slot is selected and the GS is active but not dead.
- The AI/GS Debug window now displays the Settings button by default instead of the Configure button when nothing is selected.

To do:
- Find a way to easily identify an AI that started as Random AI while in a game.
- Add Company #1-15 to the list of slots #1-15.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.
- (maybe) List all 15 slots at once and if so, get rid of the scroll bar.

Bug found:
- While in-game, slot 15 can be moved down, causing a crash.

max_no_competitors = 15 v8 r27549.patch
(15.62 KiB) Downloaded 136 times
v8 r27549
This version offers no functionality changes, only improvements for string texts and code.
- "AI/Game Script Configuration" window renamed to "AI/Game Script Settings".
- "Configure" button in "AI/GS Script Settings" and "Settings" button in "AI/GS Debug" windows are now changed to display either "Configure" or "Settings", depending on the current state of the scripts and game mode.
- "Human player" slot renamed to "Human Company"
- "The Game Script that will be loaded in the next game" tooltip modified to "The Game Script that is loaded or will be loaded in the next game"
- "The AIs that will be loaded in the next game" tooltip modified to "The AIs that are currently loaded or will be loaded next time they start on these Company IDs while in a game"
- Attempt to simplify some booleans in the code.


To do:
- Simplify more booleans in the code.
- Find a way to easily identify an AI that started as Random AI while in a game.
- Add Company #1-15 to the list of slots #1-15.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.
- (maybe) List all 15 slots at once and if so, get rid of the scroll bar.
Last edited by xarick on 30 Apr 2016 23:14, edited 1 time in total.
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: max_no_competitors = 15 patch

Post by xarick »

Previous versions (v13, v12, v11):
[+] Spoiler
max_no_competitors = 15 v13 r27553.patch
(23.24 KiB) Downloaded 128 times
v13 r27533:
- Reverted all the changes from v12 and used another approach to deal with the string "STR_AI_CONFIG_CAPTION".

To do:
- Add Company #1-15 to the list of slots #1-15.
- Find a way to easily identify an AI that started as Random AI while in a game.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.

max_no_competitors = 15 v12 r27553.patch
(78.31 KiB) Downloaded 124 times
v12 r27553:
- Removed the annoying language warnings when building with MSVC by removing the string "STR_AI_CONFIG_CAPTION" from all language files, but English.txt.

To do:
- Add Company #1-15 to the list of slots #1-15.
- Find a way to easily identify an AI that started as Random AI while in a game.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.


max_no_competitors = 15 v11 r27553.patch
(23.55 KiB) Downloaded 147 times
v11 r27553:
- The View readme, Changelog and License windows now close themselves if they're open while accepting an AI/GS from the list of available AI/GS window. This prevents possible bugs that would allow OpenTTD to crash.
- Removed the vertical scrollbar from the AI/Game Script Configuration window.

To do:
- Add Company #1-15 to the list of slots #1-15.
- Find a way to easily identify an AI that started as Random AI while in a game.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.
Last edited by xarick on 06 May 2016 01:28, edited 1 time in total.
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: max_no_competitors = 15 patch

Post by xarick »

max_no_competitors = 15 v15 r27555.patch
(35.24 KiB) Downloaded 138 times
v15 r27555:
This version tries a different GUI approach for the AI/GS configuration/settings window with the use of image icons. The goal is an attempt to display the minimum text possible and use these icons to reflect the state of a script in a given configuration slot.
- Reverted a fix that was intending to correct the behaviour of the Configure button when the currenty selected Random AI is a Random AI while in the scenario editor. Currently it is not fixed as it was allowing new game configurations being altered outside of the main menu from within the scenario editor and not reverting them to their prior configuration when exiting the scenario editor.
- Added a text resize check for the "Select", "Select AI" or "Select Game Scipt" button in the AI/GS configuration/settings window. It was only checking the size of "Select" previously.
- Added a text resize check for the "Configure" or "Settings" button in the AI/GS configuration/settings window. It was only checking the size of "Configure" previously.
- Renamed "(Random AI)" to "(random)".

To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Fix the bugs related to Random AI being selected in a game and not Configurable, but becoming Configurable if it is changed to Random AI.
- Find a way to distinguish dead AIs that started as Random AIs from newly configured AI scripts for the same company id, especially if it's also Random AI, in the AI/GS Settings window.
- Find a way to avoid confusion with dead AIs that started as Random AIs in the AI Debug window after configuring another AI script via AI/GS Settings window.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.


Previous version (v14):
[+] Spoiler
max_no_competitors = 15 v14 r27553.patch
(28.86 KiB) Downloaded 131 times
v14 r27553:
This version adds some new features.
- Added Company # to the list of AIs in the AI/GS configuration/settings window.
- AIs that started as Random AIs in a game are now indicated in the AI/GS settings window.
- The Parameters window of an AI no longer closes itself when closing the AI/GS settings window while in a game.
- Fixed a bug with the Configure button being disabled when the currently selected AI is a Random AI while in the scenario editor.
- Removed code remnants of the vertical scrollbar.
- Added missing code for the AI/GS configuration window title caption.
- Renamed "Random AI" to "(Random AI)"

To do:
- Fix more bugs related to Random AI being selected in a game and not Configurable, but becoming Configurable if it is changed to Random AI.
- Find a way to distinguish dead AIs that started as Random AIs from newly configured AI scripts for the same company id, especially if it's also Random AI, in the AI/GS Settings window.
- Find a way to avoid confusion with dead AIs that started as Random AIs in the AI Debug window after configuring another AI script via AI/GS Settings window.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.
Last edited by xarick on 10 May 2016 20:04, edited 2 times in total.
Formerly known as Samu
User avatar
te_lanus
Transport Coordinator
Transport Coordinator
Posts: 326
Joined: 19 Jul 2012 18:04
Location: The Elizabeth Arkham Asylum for the Criminally Insane

Re: max_no_competitors = 15 patch

Post by te_lanus »

Very nice, wish there was a way to get two GS running at the same time, but from what I read is a pipe dream(and my programming skill was last useful in the bronze age).
User avatar
supermop
Tycoon
Tycoon
Posts: 1104
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: max_no_competitors = 15 patch

Post by supermop »

Dice.png
Dice.png (3.56 KiB) Viewed 9630 times
Here Is a quick 10px high pair of dice sprite you can use to show randomness. This could be used anywhere else the game wants to show something is being randomly selected. Hand drawn, GPL2. I can draw a 20 px high version if people want, but my approach is for stuff like this to prioritize clarity at the smallest size the icon will be displayed at the expense of blockiness at larger zoom.
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: max_no_competitors = 15 patch

Post by xarick »

Problem solved:
[+] Spoiler
I need help to solve this seemingly trivial problem. I've been on this for 3 days and couldn't find a solution so far.

The problem arises from this piece of code:

Code: Select all

	/**
	* Is the AI or GS config in the given slot eligible to start?
	* @param slot The slot to query.
	* @return True if and only if the given AI or GS Config slot can start.
	*/
	static bool IsEligible(CompanyID slot)
	{
		if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL && GameConfig::GetConfig()->GetInfo() != NULL;

		if (Company::IsValidID(slot) || slot < 0) return false;

		int max_slot = GetGameSettings().difficulty.max_no_competitors;
		for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
			if (Company::IsValidHumanID(cid)) max_slot++;
		}
		return slot < max_slot;
	}

I am using this function to display in the panel which slots are eligible to start an AI. If they are eligible to start, they will display in a yellow smile in the picture below. If they are not, they won't display the yellow smile.
Xarick Preto Transport, 1950-01-26.png
Xarick Preto Transport, 1950-01-26.png (56.09 KiB) Viewed 9378 times
The green smiles are AI companies that have already started. No matter the value I set to max_no_competitors, the green smiles will stay there, exactly as they are.

I also know that OpenTTD picks the lowest companyID available to start a company everytime it creates a company.

In this screenshot, I know that there's already 6 AI companies running (slots 3-7, 15), 3 Human companies represented by the warning sign (slots 1-2, 14) and 6 free slots (slots 8-13), and that I want a max_no_competitors to be 10. If the function were to be working correctly, it would display 4 yellow smiles, and would display them on the 4 first free slots. In the given example, they would be slots 8-11, but instead it displays 5 yellow smiles.

Slot 12 is in error, it shouldn't have a yellow smile, it should have returned false, because the for cycle in the code did not account for the AI that is present in slot 15. The total sum of green smiles + yellow smiles can't be higher than the max_no_competitors.


So I modified the function to this:

Code: Select all

	/**
	* Is the AI or GS config in the given slot eligible to start?
	* @param slot The slot to query.
	* @return True if and only if the given AI or GS Config slot can start.
	*/
	static bool IsEligible(CompanyID slot)
	{
		if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL && GameConfig::GetConfig()->GetInfo() != NULL;

		if (Company::IsValidID(slot) || slot < 0) return false;

		int total_ais = 0;
		for (CompanyID cid = COMPANY_FIRST; cid < MAX_COMPANIES; cid++) {
			if (Company::IsValidAiID(cid)) total_ais++;
		}

		int max_slot = GetGameSettings().difficulty.max_no_competitors;
		int counted_ais = 0;
		for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
			if (Company::IsValidHumanID(cid)) max_slot++;
			if (Company::IsValidAiID(cid)) counted_ais++;
		}
		int uncounted_ais = total_ais - counted_ais;

		return slot < max_slot - uncounted_ais;
	}
First, it knows the total number of AIs (total_ais) before computing max_slot, then while running the for cycle, it counts the number of AIs that have been accounted for (counted_ais) and then it calculates the number of AIs that this for cycle did not account for (uncounted_ais).

Now, when testing the slot that is being queried, it now also takes into account those AIs that haven't been accounted for. This is the result:
Xarick Preto Transport, 1950-01-26#1.png
Xarick Preto Transport, 1950-01-26#1.png (56.41 KiB) Viewed 9378 times
Everything looks correct now, right? But, there is yet another problem...

Suppose Company 2, which is a Human Company, is deleted, and that I set a max_no_competitors to 4 (or 5, or 6). This happens:
Xarick Preto Transport, 1950-01-26#2.png
Xarick Preto Transport, 1950-01-26#2.png (53.58 KiB) Viewed 9378 times
In the screenshot, I see that there's still 6 AIs running (green smiles). It is intended behaviour that changing the value of max_no_competitors to 4 won't kill off any currently running companies.

But what's not intended is that yellow smile at slot 2. If there are already 6 companies with AIs, I don't want slot 2 to be an eligible AI slot, until the number of total_ais (which is 6 in this example) drops below the value of max_no_competitors (which is 4).

And this is where I stand currently. I lost 3 days trying to figure a solution for this problem and still got nothing. Please help!
Last edited by xarick on 13 May 2016 19:26, edited 1 time in total.
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: max_no_competitors = 15 patch

Post by xarick »

Problem solved:
[+] Spoiler
To try to fix the 2nd problem, I made a change to the return line. The code is now as following:

Code: Select all

	/**
	* Is the AI or GS config in the given slot eligible to start?
	* @param slot The slot to query.
	* @return True if and only if the given AI or GS Config slot can start.
	*/
	static bool IsEligible(CompanyID slot)
	{
		if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL && GameConfig::GetConfig()->GetInfo() != NULL;

		if (Company::IsValidID(slot) || slot < 0) return false;

		int total_ais = 0;
		for (CompanyID cid = COMPANY_FIRST; cid < MAX_COMPANIES; cid++) {
			if (Company::IsValidAiID(cid)) total_ais++;
		}

		int max_slot = GetGameSettings().difficulty.max_no_competitors;
		int counted_ais = 0;
		for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
			if (Company::IsValidHumanID(cid)) max_slot++;
			if (Company::IsValidAiID(cid)) counted_ais++;
		}
		int uncounted_ais = total_ais - counted_ais;

		return slot < max_slot - uncounted_ais && total_ais < GetGameSettings().difficulty.max_no_competitors;
	}
It results in this:
Xarick Preto Transport, 1950-01-26#3.png
Xarick Preto Transport, 1950-01-26#3.png (52.96 KiB) Viewed 9359 times

It looks correct now, and it is working when max_no_competitors is 4, 5 and 6. But it's not over. There's yet a 3rd problem.

Suppose now that Company 1 is also deleted and that I want a max_no_competitors of 7. Here's what it happens:
screenshot#11.png
screenshot#11.png (53.49 KiB) Viewed 9359 times
Slots 1-2 become yellow. It is intended that slot 1 becomes eligible, but not slot 2. The sum of yellow smiles with green smiles must be below or equal to the value of max_no_competitors.

EDIT: PROBLEM SOLVED! Thx glx and Alberth. Here's what I've done:

Code: Select all

	/**
	* Is the AI or GS config in the given slot eligible to start?
	* @param slot The slot to query.
	* @return True if and only if the given AI or GS Config of this slot can start.
	*/
	static bool IsEligible(CompanyID slot)
	{
		if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL && GameConfig::GetConfig()->GetInfo() != NULL;

		if (Company::IsValidID(slot) || slot < 0) return false;

		int total_ais = 0;
		for (CompanyID cid = COMPANY_FIRST; cid < MAX_COMPANIES; cid++) {
			if (Company::IsValidAiID(cid)) total_ais++;
		}

		int slots_to_fill = max(GetGameSettings().difficulty.max_no_competitors - total_ais, 0);
		int empty_slot = 0;
		int max_fill = 0;
		for (CompanyID cid = COMPANY_FIRST; cid < MAX_COMPANIES && slots_to_fill > empty_slot; cid++) {
			if (!Company::IsValidID(cid)) empty_slot++;
			max_fill++;
		}

		return slot < max_fill;
	}
So far, these 3 problems are now solved. I've also tested some more different combinations and have yet to find one which would fail.
Previous version (v16):
[+] Spoiler
max_no_competitors = 15 v16 r27565.patch
(36.11 KiB) Downloaded 127 times
v16 r27565:
- Slots that aren't eligible to start an AI will no longer display a random AI icon next to it, if their configuration is a random AI.
- Fixed a bug related to eligible slots.
- Renamed a function in code to better reflect what it actually does.

To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Fix the bugs related to Random AI being selected in a game and not Configurable, but becoming Configurable if it is changed to Random AI.
- Find a way to distinguish dead AIs that started as Random AIs from newly configured AI scripts for the same company id, especially if it's also Random AI, in the AI/GS Settings window.
- Find a way to avoid confusion with dead AIs that started as Random AIs in the AI Debug window after configuring another AI script via AI/GS Settings window.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.
Last edited by xarick on 16 May 2016 00:33, edited 1 time in total.
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: max_no_competitors = 15 patch

Post by xarick »

Previous version (v19, v18, v17):
[+] Spoiler
max_no_competitors = 15 v19 r27569.patch
(41.2 KiB) Downloaded 116 times
v19 r27569:
- AIs and GSs are no longer requested to save their game when a client joins a server.

To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Find a way to distinguish dead AIs that started as Random AIs from newly configured AI scripts for the same company id, especially if it's also Random AI, in the AI/GS Settings window.
- Find a way to avoid confusion with dead AIs that started as Random AIs in the AI Debug window after configuring another AI script via AI/GS Settings window.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.

max_no_competitors = 15 v18 r27567.patch
(38.62 KiB) Downloaded 122 times
v18 r27567:
This patch consists of many bug fixes related to unconventional ways to configure AIs or GSs, like via Scenario Editor. It also adds a new feature.
- When selecting from a list of available AI scripts, a newspaper icon is displayed next to those that can be used as random. What this means is, should you prefer to let OpenTTD to randomly pick an AI to start, now you know which ones from the list of available AIs could be picked. It is merely informative and doesn't affect the choice in any way.
- When there's no Game Script running while in a game, its slot in the AI/Game Script Settings window can now be selected. Silver text is thus, eliminated, to further reinforce simplification.
- Fixed the checking conditions for the eligibility of a Game Script while in the different game modes (main menu, scenario editor, in-game).
- Fixed many checking conditions which were missing when in the AI/GS Parameters window, while in the Scenario Editor, related to clicking and displaying (reset button, increase/decrease buttons, on/off buttons, dropdown lists, text box queries).
- Additionaly added checking conditions which were missing when double clicking on slots in the AI/Game Script settings window. Their omission was allowing the Available AIs/GSs window to be accessed regardless of their current state.
- Fixed the checking conditions for the disableness state of the Select AI/Game Script button in the AI/Game Script Configuration/Settings window, in the different game modes (main menu, scenario editor, in-game).
- While in the Scenario Editor, the AI/Gamescript Parameters window no longer closes itself when closing the AI/Game Script Settings window.
- Reverted a change regarding the name of AI/Game Script Configuration/Settings window while in the Scenario Editor, to AI/Game Script Settings.
- Fixed a bug in the calculation of the height of the image icons that are displayed, and removed the need to calculate the size of certain icons that were sure to never be displayed.
- Fixed a bug which was allowing the Settings button of a Game Script without any configurable parameters to be clicked and accessed via AI/Game Script Debug window.
- Fixed the checking conditions for displaying either the Configure or the Settings button for both AI/Game Script Settings and AI/Game Script Debug windows, in the different game modes (main menu, scenario editor, in-game).

To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Find a way to distinguish dead AIs that started as Random AIs from newly configured AI scripts for the same company id, especially if it's also Random AI, in the AI/GS Settings window.
- Find a way to avoid confusion with dead AIs that started as Random AIs in the AI Debug window after configuring another AI script via AI/GS Settings window.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.

max_no_competitors = 15 v17 r27566.patch
(36.78 KiB) Downloaded 128 times
v17 r27566:
- Implemented a workaround to deal with random AI slots not being configurable. Though it isn't exactly addressing the real issue, it'll make these slots configurable.


To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Find a way to distinguish dead AIs that started as Random AIs from newly configured AI scripts for the same company id, especially if it's also Random AI, in the AI/GS Settings window.
- Find a way to avoid confusion with dead AIs that started as Random AIs in the AI Debug window after configuring another AI script via AI/GS Settings window.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.
Last edited by xarick on 22 May 2016 14:23, edited 1 time in total.
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: max_no_competitors = 15 patch

Post by xarick »

Previous versions (v22, v21, v20):
[+] Spoiler
max_no_competitors = 15 v22 r27582.patch
(50.98 KiB) Downloaded 119 times
v22 r27582:
- Implemented a fix that corrects the name of AIs that are started via startai command in the console when the parameter also included the version. Saving a game will thus, store the correct name of the AI from now on. Loading previous savegames that have stored the incorrect name will still fail to recognize the intended name of the AI.
- Fixed some unwanted automated coding style caused by Visual Studio.

To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Find a way to distinguish old configured dead AI script Parameters from newly selected AI script Parameters for the same company id, in the AI/Game Script Settings and/or AI/Game Script Debug windows.
- Get rid of unused string STR_AI_CONFIG_HUMAN_PLAYER.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.
- (maybe) Add a Start Now button or re-use Reload AI for the same functionality, in the AI/Game Script Settings window.
- (maybe) Add a savegame conversion to correct the name of AIs which have been incorrectly storing the wrong name if they were started via console with a version appended to the command parameter.

max_no_competitors = 15 v21 r27582.patch
(50.28 KiB) Downloaded 119 times
v21 r27582:
- Replaced the Close button in the AI/Game Script Configuration/Settings window with the Reload AI button, which offers the same functionality as the one found in AI/Game Script Debug window.
- The Configure/Settings and Reload AI buttons found in the AI/Game Script Debug window are hidden when the setting gui.ai_developer_tools is set to false.
- Fixed some unwanted automated coding style caused by Visual Studio.

To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Find a way to distinguish old configured dead AI script Parameters from newly selected AI script Parameters for the same company id, in the AI/Game Script Settings and/or AI/Game Script Debug windows.
- Get rid of unused string STR_AI_CONFIG_HUMAN_PLAYER.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.
- (maybe) Add a Start Now button or re-use Reload AI for the same functionality, in the AI/Game Script Settings window.

max_no_competitors = 15 v20 r27581.patch
(41.82 KiB) Downloaded 122 times
v20 r27581:
- Updated to r27581 to resolve a patching conflict with ai_gui.cpp

To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Find a way to distinguish dead AIs that started as Random AIs from newly configured AI scripts for the same company id, especially if it's also Random AI, in the AI/GS Settings window.
- Find a way to avoid confusion with dead AIs that started as Random AIs in the AI Debug window after configuring another AI script via AI/GS Settings window.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.
Last edited by xarick on 27 May 2016 00:08, edited 1 time in total.
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: max_no_competitors = 15 patch

Post by xarick »

Previous versions (v25, v24, v23):
[+] Spoiler
max_no_competitors = 15 v25 r27594.patch
(64.25 KiB) Downloaded 115 times
v25 r27594:
This version reworks on the functionality of the Reload AI button in the AI/Game Script Settings window.
- If there is an AI Company in the selected slot and it is alive, the button changes to Stop AI. Clicking it removes the AI Company and changes the button to Start AI.
- If there is an AI Company in the selected slot and it is dead, the button changes to Reload AI. Clicking it removes the AI Company, restarts the same AI script and changes the button to Stop AI.
- If there is no AI Company in the selected slot, the button changes to Start AI. Clicking it starts the selected AI script.
- If the current game is happening in multiplayer, and the current game settings don't allow AIs to start in multiplayer mode, an error message is displayed to tell about it, and won't allow AIs to be reloaded or started.
- Clicking Accept button in the Available AIs window now removes the dead AI Company from the slot that is being changed. This prevents confusion between the dead AI and the newly selected AI Parameters.
- When the setting gui.ai_developer_tools is set to false, switching from a Company to another in the AI/Game Script Debug window no longer closes the AI Parameters window.


To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Get rid of unused string STR_AI_CONFIG_HUMAN_PLAYER.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.

max_no_competitors = 15 v24 r27586.patch
(60.14 KiB) Downloaded 116 times
v24 r27586:
Further improved the workaround implemented in v23 to make OpenTTD search for available scripts more thoroughly for the cases of loading savegames with the script name stored with the version appended to it:
- It takes that into account when deciding which installed version of the script to load, and if necessary, it updates the name of the script should the version that is found isn't matching the version which created the savegame.
- In the cases where the saved version is higher than the versions installed, it no longer resorts to loading a randomly installed script. Instead, it will load the latest available version of the same script, and discards the saved data.


To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Find a way to distinguish old configured dead AI script Parameters from newly selected AI script Parameters for the same company id, in the AI/Game Script Settings and/or AI/Game Script Debug windows.
- Get rid of unused string STR_AI_CONFIG_HUMAN_PLAYER.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.
- (maybe) Add a Start Now button or re-use Reload AI for the same functionality, in the AI/Game Script Settings window.

max_no_competitors = 15 v23 r27582.patch
(52.91 KiB) Downloaded 121 times
v23 r27582:
- Reverted the fix implemented in v22, because it is possible that it's intended for savegames to store the name of the AI with the version appended to it. Instead, this patch tries to implement a workaround that allows OpenTTD to load savegames with the AI name stored in this manner so that the exact version of the script is loaded as the version it was started with when it was saved, instead of loading the most up to date and compatible version of the same script. The patch attempts to follow the documentation provided here: https://noai.openttd.org/docs/trunk/cla ... l#_details


To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Find a way to distinguish old configured dead AI script Parameters from newly selected AI script Parameters for the same company id, in the AI/Game Script Settings and/or AI/Game Script Debug windows.
- Get rid of unused string STR_AI_CONFIG_HUMAN_PLAYER.
- (maybe) Move configs with drag and drop on movable slots and if so, get rid of Move Up, Move Down buttons.
- (maybe) Add a Start Now button or re-use Reload AI for the same functionality, in the AI/Game Script Settings window.
Last edited by xarick on 01 Jun 2016 19:57, edited 1 time in total.
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: max_no_competitors = 15 patch

Post by xarick »

Previous versions (v28, v27, v26):
[+] Spoiler
max_no_competitors = 15 v28 r27597.patch
(65.29 KiB) Downloaded 119 times
v28 r27597:
- Fixed a bug that was allowing access to the Game Script Parameters window on Game Scripts without any configurable parameters by double clicking the Game Script slot.


To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Get rid of unused string STR_AI_CONFIG_HUMAN_PLAYER.
- (maybe) Copy Up or Copy Down configs from alive AI Companies.
- (maybe) Allow resetting of non-locked AI/GS Parameters while in a game.


max_no_competitors = 15 v27 r27597.patch
(65.03 KiB) Downloaded 117 times
v27 r27597:
This patch reverts some of the functionality added related to reloading AIs and interaction with dead AI Companies. These changes are needed to avoid unwanted/accidental removal of dead AIs while interacting with the slots.
- Reload AI functionality in the AI/Game Script Settings window has been removed. It is resorting to Stop AI instead for dead AI Companies.
- Reverted the change that required ai.ai_in_multiplayer setting to be true while in a multiplayer game when clicking Reload AI in the AI/Game Script Debug window.
- It is no longer possible to click on Select AI when the selected AI Company is dead. To unlock Select AI, click Stop AI first.
- Move Up and Move Down no longer swaps between dead AI Companies.
- Double clicking on slots opens either the Available AIs/Game Scripts window or the AI/Game Script Parameters window, depending on wether it started or not.


To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Get rid of unused string STR_AI_CONFIG_HUMAN_PLAYER.
- (maybe) Copy Up or Copy Down configs from alive AI Companies.
- (maybe) Allow resetting of non-locked AI/GS Parameters while in a game.


max_no_competitors = 15 v26 r27595.patch
(66.47 KiB) Downloaded 126 times
v26 r27595:
- Fixed a bug which was causing the arrows that modify the value Maximum no. competitors to have their enable or disable state in an incorrect state while on multiplayer games.
- Improved Move Up and Move Down behaviours. It now swaps with the first available free slot or an AI owned Company which script is dead. If it is swaping between dead AIs, their companies are also removed in the process.


To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Get rid of unused string STR_AI_CONFIG_HUMAN_PLAYER.
- (maybe) Copy Up or Copy Down configs from alive AI Companies.
Last edited by xarick on 04 Jun 2016 00:38, edited 1 time in total.
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: max_no_competitors = 15 patch

Post by xarick »

max_no_competitors = 15 v30 r27597.patch
(68.9 KiB) Downloaded 120 times
v30 r27597:
- Fixed a bug introduced in v29, related to the Reset button from the AI Parameters window. It was not disabled when this window was opened on a slot with an AI Company already started.
- The Available AIs window no longer closes itself when a Human Company starts on the slot which script is being changed.
- The random AI icon is no longer displayed for "(random)" scripts. This is valid for the AI/Game Script Configuration/Settings window and the Available AIs window.
- When a random AI company is bought out by another company, the AI/Game Script Settings window now properly reverts the slot name where it initially started, back to "(random)".


To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Get rid of unused string STR_AI_CONFIG_HUMAN_PLAYER.
- (maybe) Copy Up or Copy Down configs from alive AI Companies.
- (maybe) Allow resetting of non-locked AI/GS Parameters while in a game.


Previous version (v29):
[+] Spoiler
max_no_competitors = 15 v29 r27597.patch
(68.7 KiB) Downloaded 124 times
v29 r27597:
This version attempts to improve windows management and tries to close them only when necessary. Also, when random AI companies are removed or bankrupt, the slot names of where they initially started revert back to "(random)".
- When a random AI starts, its AI Parameters window is closed, instead of closing it everytime any AI starts.
- When a random AI company is removed, the View readme, Changelog or License windows is closed, without regards to how it was open. This needs to be done some other way, but for now it's done like this to avoid a possible OpenTTD crash related to random AI slots that don't have any of these windows.
- When clicking Accept from the list of Available AIs/Game Scripts, the AI/Game Script Parameters window will only close if the slot which is having its script changed is the same as that of this window, instead of closing it everytime the script is changed regardless of slot.
- The Reset button from the AI Parameters window now enables and disables itself properly when a non-random AI company starts or is removed.
- Clicking on Configure/Settings from the AI/Game Script Configuration/Settings window no longer closes the Available AIs/Game Scripts window.
- When in the Scenario Editor, the Configure/Settings from the AI/Game Script Settings window is no longer accessible if there are AI Companies and/or a Game Script instances present.
- Some other code improvements.


To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Get rid of unused string STR_AI_CONFIG_HUMAN_PLAYER.
- (maybe) Copy Up or Copy Down configs from alive AI Companies.
- (maybe) Allow resetting of non-locked AI/GS Parameters while in a game.
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: max_no_competitors = 15 patch

Post by xarick »

max_no_competitors = 15 v31 r27601.patch
(68.51 KiB) Downloaded 123 times
v31 r27601:
- Reverted a change that was causing hidden parameters in the AI/Game Script Parameters window not becoming visible or hidden when 'setting gui.ai_developer_tools' was set to 'true' or 'false', via console.
- Fixed a bug in the AI/Game Script Parameters window, which was causing Dropdown and Query Box based settings to apply the submitted values to hidden parameters.

To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Get rid of unused string STR_AI_CONFIG_HUMAN_PLAYER.
- (maybe) Copy Up or Copy Down configs from alive AI Companies.
- (maybe) Allow resetting of non-locked AI/GS Parameters while in a game.
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: max_no_competitors = 15 patch

Post by xarick »

max_no_competitors = 15 v32 r27816.patch
(68.18 KiB) Downloaded 102 times
v32 r27816:
- Updated to trunk r27816 to resolve a patching conflict that was occurring since trunk r27786.
- Also, trunk r27786 implements a better fix addressing the same bug that was reported on v31 and thus, v32 re-uses trunk's implementation instead.

To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Get rid of unused string STR_AI_CONFIG_HUMAN_PLAYER.
- (maybe) Copy Up or Copy Down configs from alive AI Companies.
- (maybe) Allow resetting of non-locked AI/GS Parameters while in a game.
Formerly known as Samu
xarick
Transport Coordinator
Transport Coordinator
Posts: 341
Joined: 26 Feb 2015 00:52

Re: max_no_competitors = 15 patch

Post by xarick »

max_no_competitors = 15 v33 r27931.patch
(68.17 KiB) Downloaded 99 times
v33 r27931
- Updated to trunk r27931 to resolve a patching conflict that was occurring since r27893.

To do:
- Use the Dice.png provived by Supermop reflecting a random ai script to replace the newspaper icon.
- Find a better icon reflecting the presence of a Human Company to replace the warning sign icon.
- Use the random ai icon in the AI/Debug window.
- Get rid of unused string STR_AI_CONFIG_HUMAN_PLAYER.
- (maybe) Copy Up or Copy Down configs from alive AI Companies.
- (maybe) Allow resetting of non-locked AI/GS Parameters while in a game.
Formerly known as Samu
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 12 guests