changeset 10726:d71a34151640 draft

(svn r15059) -Add [NoAI]: use 'start_date' from the AI configure to see when an AI should start next
author truebrain <truebrain@openttd.org>
date Tue, 13 Jan 2009 14:00:26 +0000
parents e959c7a4416d
children d01d37a999bb
files src/ai/ai.hpp src/ai/ai_core.cpp src/ai/ai_info.cpp src/company_cmd.cpp
diffstat 4 files changed, 41 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/ai/ai.hpp
+++ b/src/ai/ai.hpp
@@ -18,6 +18,15 @@
 class AI {
 public:
 	/**
+	 * The default months AIs start after eachother.
+	 */
+	enum StartNext {
+		START_NEXT_EASY   = 48,
+		START_NEXT_MEDIUM = 24,
+		START_NEXT_HARD   = 12,
+	};
+
+	/**
 	 * Is it possible to start a new AI company?
 	 * @return True if a new AI company can be started.
 	 */
@@ -88,6 +97,11 @@
 	 */
 	static void Load(CompanyID company, int version);
 
+	/**
+	 * Get the number of months before the next AI should start.
+	 */
+	static int GetStartNextTime();
+
 	static char *GetConsoleList(char *p, const char *last);
 	static const AIInfoList *GetInfoList();
 	static AIInfo *FindInfo(const char *name, int version);
--- a/src/ai/ai_core.cpp
+++ b/src/ai/ai_core.cpp
@@ -227,6 +227,28 @@
 	}
 }
 
+/* static */ int AI::GetStartNextTime()
+{
+	for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
+		if (IsValidCompanyID(c)) continue;
+
+		AIConfig *config = AIConfig::GetConfig(c);
+		if (config->HasAI()) return config->GetSetting("start_date");
+
+		/* No AI configured, so fall back to some defaults */
+		switch (_settings_game.difficulty.diff_level) {
+			case 0: return AI::START_NEXT_EASY;
+			case 1: return AI::START_NEXT_MEDIUM;
+			case 2: return AI::START_NEXT_HARD;
+			case 3: return AI::START_NEXT_MEDIUM;
+			default: NOT_REACHED();
+		}
+	}
+
+	/* Currently no AI can be started, check again in a year. */
+	return 12;
+}
+
 /* static */ char *AI::GetConsoleList(char *p, const char *last)
 {
 	return AI::ai_scanner->GetAIConsoleList(p, last);
--- a/src/ai/ai_info.cpp
+++ b/src/ai/ai_info.cpp
@@ -156,10 +156,10 @@
 	config.description = strdup("The amount of months after the start of the last AI, this AI will start (give or take).");
 	config.min_value = 0;
 	config.max_value = 120;
-	config.easy_value = 48;
-	config.medium_value = 24;
-	config.hard_value = 12;
-	config.custom_value = 24;
+	config.easy_value   = AI::START_NEXT_EASY;
+	config.medium_value = AI::START_NEXT_MEDIUM;
+	config.hard_value   = AI::START_NEXT_HARD;
+	config.custom_value = AI::START_NEXT_MEDIUM;
 	config.flags = AICONFIG_NONE;
 	info->config_list.push_back(config);
 
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -494,9 +494,7 @@
 		DoCommandP(0, 1, 0, CMD_COMPANY_CTRL);
 	}
 
-	/* The next AI starts like the difficulty setting said, with +2 month max */
-	_next_competitor_start = _settings_game.difficulty.competitor_start_time * 90 * DAY_TICKS + 1;
-	_next_competitor_start += _network_server ? InteractiveRandomRange(60 * DAY_TICKS) : RandomRange(60 * DAY_TICKS);
+	_next_competitor_start = AI::GetStartNextTime() * 30 * DAY_TICKS;
 }
 
 void InitializeCompanies()