summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/ai.hpp14
-rw-r--r--src/ai/ai_core.cpp22
-rw-r--r--src/ai/ai_info.cpp8
3 files changed, 40 insertions, 4 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);