diff options
author | truebrain <truebrain@openttd.org> | 2009-01-13 13:09:49 +0000 |
---|---|---|
committer | truebrain <truebrain@openttd.org> | 2009-01-13 13:09:49 +0000 |
commit | 07f2afa635c0ddfa491468cc3f8677cd0d869c6d (patch) | |
tree | 984f1ac1f9997c87150d3e97f6f8b3b2496a6632 | |
parent | 1bd286771592ac21575c840026b91f42003e0868 (diff) | |
download | openttd-07f2afa635c0ddfa491468cc3f8677cd0d869c6d.tar.xz |
(svn r15057) -Fix [NoAI]: clamp the values of a setting between the ones allowed by info.nut
-rw-r--r-- | src/ai/ai_config.cpp | 7 | ||||
-rw-r--r-- | src/ai/ai_info.cpp | 8 | ||||
-rw-r--r-- | src/ai/ai_info.hpp | 5 |
3 files changed, 19 insertions, 1 deletions
diff --git a/src/ai/ai_config.cpp b/src/ai/ai_config.cpp index dc7a3e48d..cc309b62f 100644 --- a/src/ai/ai_config.cpp +++ b/src/ai/ai_config.cpp @@ -88,7 +88,12 @@ int AIConfig::GetSetting(const char *name) void AIConfig::SetSetting(const char *name, int value) { /* You can only set ai specific settings if an AI is selected. */ - assert(strcmp(name, "start_date") == 0 || this->info != NULL); + assert(this->info != NULL); + + const AIConfigItem *config_item = this->info->GetConfigItem(name); + if (config_item == NULL) return; + + value = Clamp(value, config_item->min_value, config_item->max_value); SettingValueList::iterator it = this->settings.find(name); if (it != this->settings.end()) { diff --git a/src/ai/ai_info.cpp b/src/ai/ai_info.cpp index 9e439cce2..c68972c45 100644 --- a/src/ai/ai_info.cpp +++ b/src/ai/ai_info.cpp @@ -295,6 +295,14 @@ const AIConfigItemList *AIInfo::GetConfigList() return &this->config_list; } +const AIConfigItem *AIInfo::GetConfigItem(const char *name) +{ + for (AIConfigItemList::iterator it = this->config_list.begin(); it != this->config_list.end(); it++) { + if (strcmp((*it).name, name) == 0) return &(*it); + } + return NULL; +} + int AIInfo::GetSettingDefaultValue(const char *name) { for (AIConfigItemList::iterator it = this->config_list.begin(); it != this->config_list.end(); it++) { diff --git a/src/ai/ai_info.hpp b/src/ai/ai_info.hpp index 205e89b38..9d283966d 100644 --- a/src/ai/ai_info.hpp +++ b/src/ai/ai_info.hpp @@ -127,6 +127,11 @@ public: const AIConfigItemList *GetConfigList(); /** + * Get the description of a certain ai config option. + */ + const AIConfigItem *GetConfigItem(const char *name); + + /** * Set a setting. */ SQInteger AddSetting(HSQUIRRELVM vm); |