Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "../stdafx.h"
00013 #include "../settings_type.h"
00014 #include "ai.hpp"
00015 #include "ai_config.hpp"
00016 #include "ai_info.hpp"
00017
00019 ScriptConfigItem _start_date_config = {
00020 "start_date",
00021 "",
00022 AI::START_NEXT_MIN,
00023 AI::START_NEXT_MAX,
00024 AI::START_NEXT_MEDIUM,
00025 AI::START_NEXT_EASY,
00026 AI::START_NEXT_MEDIUM,
00027 AI::START_NEXT_HARD,
00028 AI::START_NEXT_DEVIATION,
00029 30,
00030 SCRIPTCONFIG_NONE,
00031 NULL,
00032 false
00033 };
00034
00035 AIConfig *AIConfig::GetConfig(CompanyID company, ScriptSettingSource source)
00036 {
00037 AIConfig **config;
00038 if (source == SSS_FORCE_NEWGAME || (source == SSS_DEFAULT && _game_mode == GM_MENU)) {
00039 config = &_settings_newgame.ai_config[company];
00040 } else {
00041 config = &_settings_game.ai_config[company];
00042 }
00043 if (*config == NULL) *config = new AIConfig();
00044 return *config;
00045 }
00046
00047 class AIInfo *AIConfig::GetInfo() const
00048 {
00049 return static_cast<class AIInfo *>(ScriptConfig::GetInfo());
00050 }
00051
00052 ScriptInfo *AIConfig::FindInfo(const char *name, int version, bool force_exact_match)
00053 {
00054 return static_cast<ScriptInfo *>(AI::FindInfo(name, version, force_exact_match));
00055 }
00056
00057 bool AIConfig::ResetInfo(bool force_exact_match)
00058 {
00059 this->info = (ScriptInfo *)AI::FindInfo(this->name, force_exact_match ? this->version : -1, force_exact_match);
00060 return this->info != NULL;
00061 }
00062
00063 void AIConfig::PushExtraConfigList()
00064 {
00065 this->config_list->push_back(_start_date_config);
00066 }
00067
00068 void AIConfig::ClearConfigList()
00069 {
00070
00071
00072 int start_date = this->GetSetting("start_date");
00073
00074 ScriptConfig::ClearConfigList();
00075
00076 this->SetSetting("start_date", start_date);
00077 }
00078
00079 int AIConfig::GetSetting(const char *name) const
00080 {
00081 if (this->info == NULL) {
00082 SettingValueList::const_iterator it = this->settings.find(name);
00083 if (it == this->settings.end() || GetGameSettings().difficulty.diff_level != 3) {
00084 assert(strcmp("start_date", name) == 0);
00085 switch (GetGameSettings().difficulty.diff_level) {
00086 case 0: return AI::START_NEXT_EASY;
00087 case 1: return AI::START_NEXT_MEDIUM;
00088 case 2: return AI::START_NEXT_HARD;
00089 case 3: return AI::START_NEXT_MEDIUM;
00090 default: NOT_REACHED();
00091 }
00092 }
00093
00094 return (*it).second;
00095 }
00096
00097 return ScriptConfig::GetSetting(name);
00098 }
00099
00100 void AIConfig::SetSetting(const char *name, int value)
00101 {
00102 if (this->info == NULL) {
00103 if (strcmp("start_date", name) != 0) return;
00104 value = Clamp(value, AI::START_NEXT_MIN, AI::START_NEXT_MAX);
00105
00106 SettingValueList::iterator it = this->settings.find(name);
00107 if (it != this->settings.end()) {
00108 (*it).second = value;
00109 } else {
00110 this->settings[strdup(name)] = value;
00111 }
00112
00113 return;
00114 }
00115
00116 ScriptConfig::SetSetting(name, value);
00117 }