Changeset - r10724:cec22216aab8
[Not reviewed]
master
0 3 0
truebrain - 15 years ago 2009-01-13 13:09:49
truebrain@openttd.org
(svn r15057) -Fix [NoAI]: clamp the values of a setting between the ones allowed by info.nut
3 files changed with 19 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_config.cpp
Show inline comments
 
@@ -85,13 +85,18 @@ int AIConfig::GetSetting(const char *nam
 
	return (*it).second;
 
}
 

	
 
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()) {
 
		(*it).second = value;
 
	} else {
 
		this->settings[strdup(name)] = value;
src/ai/ai_info.cpp
Show inline comments
 
@@ -292,12 +292,20 @@ SQInteger AIInfo::AddSetting(HSQUIRRELVM
 

	
 
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++) {
 
		if (strcmp((*it).name, name) != 0) continue;
 
		/* The default value depends on the difficulty level */
 
		switch ((_game_mode == GM_MENU) ? _settings_newgame.difficulty.diff_level : _settings_game.difficulty.diff_level) {
src/ai/ai_info.hpp
Show inline comments
 
@@ -124,12 +124,17 @@ public:
 
	/**
 
	 * Get the config list for this AI.
 
	 */
 
	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);
 

	
 
	/**
 
	 * Get the default value for a setting.
0 comments (0 inline, 0 general)