summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2009-01-13 12:52:09 +0000
committertruebrain <truebrain@openttd.org>2009-01-13 12:52:09 +0000
commitf29941a043704b9a819703b3ab36a8a220a86095 (patch)
tree55112fb2f12aee8e993285a030451307178a87c1
parent53d28d24b5e959a0ed336de0479089e2be9bac56 (diff)
downloadopenttd-f29941a043704b9a819703b3ab36a8a220a86095.tar.xz
(svn r15056) -Add [NoAI]: when starting a game, give a random value to the setting marked with AICONFIG_RANDOM (Yexo)
-rw-r--r--src/ai/ai_config.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/ai/ai_config.cpp b/src/ai/ai_config.cpp
index 186d6d6e3..dc7a3e48d 100644
--- a/src/ai/ai_config.cpp
+++ b/src/ai/ai_config.cpp
@@ -5,6 +5,7 @@
#include "../stdafx.h"
#include "../openttd.h"
#include "../settings_type.h"
+#include "../core/random_func.hpp"
#include "ai.hpp"
#include "ai_config.hpp"
#include "ai_info.hpp"
@@ -20,6 +21,17 @@ void AIConfig::ChangeAI(const char *name, int version)
free((void*)(*it).first);
}
this->settings.clear();
+
+ if (_game_mode == GM_NORMAL && this->info != NULL) {
+ /* If we're in an existing game and the AI is changed, set all settings
+ * for the AI that have the random flag to a random value. */
+ for (AIConfigItemList::const_iterator it = this->info->GetConfigList()->begin(); it != this->info->GetConfigList()->end(); it++) {
+ if ((*it).flags & AICONFIG_RANDOM) {
+ this->SetSetting((*it).name, InteractiveRandomRange((*it).max_value - (*it).min_value) + (*it).min_value);
+ }
+ }
+ }
+
}
AIConfig::AIConfig(const AIConfig *config)