summaryrefslogtreecommitdiff
path: root/src/ai/ai.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.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.hpp')
-rw-r--r--src/ai/ai.hpp102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/ai/ai.hpp b/src/ai/ai.hpp
new file mode 100644
index 000000000..bd1c2a907
--- /dev/null
+++ b/src/ai/ai.hpp
@@ -0,0 +1,102 @@
+/* $Id$ */
+
+/** @file ai.hpp Base functions for all AIs. */
+
+#ifndef AI_HPP
+#define AI_HPP
+
+#include "api/ai_event_types.hpp"
+
+#ifndef AI_CONFIG_HPP
+struct ltstr { bool operator()(const char *s1, const char *s2) const { return strcmp(s1, s2) < 0; } };
+#endif /* AI_CONFIG_HPP */
+typedef std::map<const char *, class AIInfo *, ltstr> AIInfoList;
+
+
+void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2);
+
+class AI {
+public:
+ /**
+ * Is it possible to start a new AI company?
+ * @return True if a new AI company can be started.
+ */
+ static bool CanStartNew();
+
+ /**
+ * Start a new AI company.
+ * @param company At which slot the AI company should start.
+ */
+ static void StartNew(CompanyID company);
+
+ /**
+ * Called every game-tick to let AIs do something.
+ */
+ static void GameLoop();
+
+ /**
+ * Get the current AI tick.
+ */
+ static uint GetTick();
+
+ /**
+ * Stop a company to be controlled by an AI.
+ * @param company The company from which the AI needs to detach.
+ * @pre !IsHumanCompany(company).
+ */
+ static void Stop(CompanyID company);
+
+ /**
+ * Kill any and all AIs we manage.
+ */
+ static void KillAll();
+
+ /**
+ * Initialize the AI system.
+ */
+ static void Initialize();
+
+ /**
+ * Uninitialize the AI system
+ * @param keepConfig Should we keep AIConfigs, or can we free that memory?
+ */
+ static void Uninitialize(bool keepConfig);
+
+ /**
+ * Reset all AIConfigs, and make them reload their AIInfo.
+ * If the AIInfo could no longer be found, an error is reported to the user.
+ */
+ static void ResetConfig();
+
+ /**
+ * Queue a new event for an AI.
+ */
+ static void NewEvent(CompanyID company, AIEvent *event);
+
+ /**
+ * Broadcast a new event to all active AIs.
+ */
+ static void BroadcastNewEvent(AIEvent *event, CompanyID skip_company = MAX_COMPANIES);
+
+ /**
+ * Save data from an AI to a savegame.
+ */
+ static void Save(CompanyID company);
+
+ /**
+ * Load data for an AI from a savegame.
+ */
+ static void Load(CompanyID company);
+
+ static char *GetConsoleList(char *p, const char *last);
+ static const AIInfoList *GetInfoList();
+ static AIInfo *GetCompanyInfo(const char *name);
+ static bool ImportLibrary(const char *library, const char *class_name, int version, HSQUIRRELVM vm);
+ static void Rescan();
+
+private:
+ static uint frame_counter;
+ static class AIScanner *ai_scanner;
+};
+
+#endif /* AI_HPP */