summaryrefslogtreecommitdiff
path: root/src/ai/ai_config.hpp
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2009-01-12 17:11:45 +0000
committertruebrain <truebrain@openttd.org>2009-01-12 17:11:45 +0000
commita3dd7506d377b1434f913bd65c019eed52b64b6e (patch)
treeced1a262eb143ad6e64ec02f4a4c89835c0c32fd /src/ai/ai_config.hpp
parent9294f9616866b9778c22076c19b5a32b4f85f788 (diff)
downloadopenttd-a3dd7506d377b1434f913bd65c019eed52b64b6e.tar.xz
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
NoAI is an API (a framework) to build your own AIs in. See: http://wiki.openttd.org/wiki/index.php/AI:Main_Page With many thanks to: - glx and Rubidium for their syncing, feedback and hard work - Yexo for his feedback, patches, and AIs which tested the system very deep - Morloth for his feedback and patches - TJIP for hosting a challenge which kept NoAI on track - All AI authors for testing our AI API, and all other people who helped in one way or another -Remove: all old AIs and their cheats/hacks
Diffstat (limited to 'src/ai/ai_config.hpp')
-rw-r--r--src/ai/ai_config.hpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/ai/ai_config.hpp b/src/ai/ai_config.hpp
new file mode 100644
index 000000000..c628a855f
--- /dev/null
+++ b/src/ai/ai_config.hpp
@@ -0,0 +1,91 @@
+/* $Id$ */
+
+/** @file ai_config.hpp AIConfig stores the configuration settings of every AI. */
+
+#ifndef AI_CONFIG_HPP
+#define AI_CONFIG_HPP
+
+#include <map>
+
+#ifndef AI_HPP
+struct ltstr { bool operator()(const char *s1, const char *s2) const { return strcmp(s1, s2) < 0; } };
+#endif /* AI_HPP */
+
+class AIConfig {
+private:
+ typedef std::map<const char *, int, ltstr> SettingValueList;
+
+public:
+ AIConfig() :
+ name(NULL),
+ info(NULL)
+ {}
+ AIConfig(const AIConfig *config);
+ ~AIConfig();
+
+ /**
+ * Set another AI to be loaded in this slot.
+ */
+ void ChangeAI(const char *name);
+
+ /**
+ * When ever the AI Scanner is reloaded, all infos become invalid. This
+ * function tells AIConfig about this.
+ * @return True if the reset was successfull, false if the AI was no longer
+ * found.
+ */
+ bool ResetInfo();
+
+ /**
+ * Get the AIInfo linked to this AIConfig.
+ */
+ class AIInfo *GetInfo();
+
+ /**
+ * Get the config of a company.
+ */
+ static AIConfig *GetConfig(CompanyID company, bool forceNewgameSetting = false);
+
+ /**
+ * Get the value of a setting for this config. It might fallback to his
+ * 'info' to find the default value (if not set or if not-custom difficulty
+ * level).
+ * @return The (default) value of the setting, or -1 if the setting was not
+ * found.
+ */
+ int GetSetting(const char *name);
+
+ /**
+ * Set the value of a setting for this config.
+ */
+ void SetSetting(const char *name, int value);
+
+ /**
+ * Is this config attached to an AI?
+ */
+ bool HasAI();
+
+ /**
+ * Get the name of the AI.
+ */
+ const char *GetName();
+
+ /**
+ * Convert a string which is stored in the config file or savegames to
+ * custom settings of this AI.
+ */
+ void StringToSettings(const char *value);
+
+ /**
+ * Convert the custom settings to a string that can be stored in the config
+ * file or savegames.
+ */
+ void SettingsToString(char *string, int size);
+
+private:
+ const char *name;
+ class AIInfo *info;
+ SettingValueList settings;
+};
+
+#endif /* AI_CONFIG_HPP */