(svn r15059) -Add [NoAI]: use 'start_date' from the AI configure to see when an AI should start next

This commit is contained in:
truebrain 2009-01-13 14:00:26 +00:00
parent 405239758e
commit c3249d599f
4 changed files with 41 additions and 7 deletions

View File

@ -17,6 +17,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);

View File

@ -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);

View File

@ -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);

View File

@ -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()