summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2009-01-13 14:00:26 +0000
committertruebrain <truebrain@openttd.org>2009-01-13 14:00:26 +0000
commitc3249d599fb4805b6c59e89c28c4d2720a7bcae0 (patch)
treefcc285a1912310512f00a09a911ee585210e5611 /src
parent405239758ecd3dad1d52322b2fea05ed350d15bb (diff)
downloadopenttd-c3249d599fb4805b6c59e89c28c4d2720a7bcae0.tar.xz
(svn r15059) -Add [NoAI]: use 'start_date' from the AI configure to see when an AI should start next
Diffstat (limited to 'src')
-rw-r--r--src/ai/ai.hpp14
-rw-r--r--src/ai/ai_core.cpp22
-rw-r--r--src/ai/ai_info.cpp8
-rw-r--r--src/company_cmd.cpp4
4 files changed, 41 insertions, 7 deletions
diff --git a/src/ai/ai.hpp b/src/ai/ai.hpp
index 0bf0a1991..214b9e119 100644
--- a/src/ai/ai.hpp
+++ b/src/ai/ai.hpp
@@ -18,6 +18,15 @@ void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2);
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 @@ public:
*/
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);
diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp
index 3d8fc7707..f5703e58d 100644
--- a/src/ai/ai_core.cpp
+++ b/src/ai/ai_core.cpp
@@ -227,6 +227,28 @@ void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2)
}
}
+/* 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);
diff --git a/src/ai/ai_info.cpp b/src/ai/ai_info.cpp
index c68972c45..2b076536e 100644
--- a/src/ai/ai_info.cpp
+++ b/src/ai/ai_info.cpp
@@ -156,10 +156,10 @@ void AIFileInfo::CheckMethods(SQInteger *res, const char *name)
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);
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index 4a27b512d..be18fb279 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -494,9 +494,7 @@ static void MaybeStartNewCompany()
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()