summaryrefslogtreecommitdiff
path: root/src/ai/api/ai_event.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
commitc2406cd42d481a697602b430111a9e59af61660f (patch)
treeced1a262eb143ad6e64ec02f4a4c89835c0c32fd /src/ai/api/ai_event.hpp
parentec97e1fd0d6ca942805fa25d94007437bc0ed952 (diff)
downloadopenttd-c2406cd42d481a697602b430111a9e59af61660f.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/api/ai_event.hpp')
-rw-r--r--src/ai/api/ai_event.hpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/ai/api/ai_event.hpp b/src/ai/api/ai_event.hpp
new file mode 100644
index 000000000..a1304ec33
--- /dev/null
+++ b/src/ai/api/ai_event.hpp
@@ -0,0 +1,107 @@
+/* $Id$ */
+
+/** @file ai_event.hpp Everything to handle events from the game. */
+
+#ifndef AI_EVENT_HPP
+#define AI_EVENT_HPP
+
+#include "ai_object.hpp"
+
+/**
+ * Class that handles all event related functions.
+ * You can lookup the type, and than convert it to the real event-class.
+ * That way you can request more detailed information about the event.
+ */
+class AIEvent : public AIObject {
+public:
+ static const char *GetClassName() { return "AIEvent"; }
+
+ /**
+ * The type of event. Needed to lookup the detailed class.
+ */
+ enum AIEventType {
+ AI_ET_INVALID = 0,
+ AI_ET_TEST,
+ AI_ET_SUBSIDY_OFFER,
+ AI_ET_SUBSIDY_OFFER_EXPIRED,
+ AI_ET_SUBSIDY_AWARDED,
+ AI_ET_SUBSIDY_EXPIRED,
+ AI_ET_ENGINE_PREVIEW,
+ AI_ET_COMPANY_NEW,
+ AI_ET_COMPANY_IN_TROUBLE,
+ AI_ET_COMPANY_MERGER,
+ AI_ET_COMPANY_BANKRUPT,
+ AI_ET_VEHICLE_CRASHED,
+ AI_ET_VEHICLE_LOST,
+ AI_ET_VEHICLE_WAITING_IN_DEPOT,
+ AI_ET_VEHICLE_UNPROFITABLE,
+ AI_ET_INDUSTRY_OPEN,
+ AI_ET_INDUSTRY_CLOSE,
+ AI_ET_ENGINE_AVAILABLE,
+ AI_ET_STATION_FIRST_VEHICLE,
+ };
+
+ /**
+ * Constructor of AIEvent, to get the type of event.
+ */
+ AIEvent(AIEvent::AIEventType type) :
+ type(type)
+ {}
+
+ /**
+ * Get the event-type.
+ * @return The @c AIEventType.
+ */
+ AIEventType GetEventType() { return this->type; }
+
+protected:
+ /**
+ * The type of this event.
+ */
+ AIEventType type;
+};
+
+/**
+ * Class that handles all event related functions.
+ * @note it is not needed to create an instance of AIEvent to access it, as
+ * all members are static, and all data is stored AI-wide.
+ */
+class AIEventController : public AIObject {
+public:
+ /**
+ * The name of the class, needed by several sub-processes.
+ */
+ static const char *GetClassName() { return "AIEventController"; }
+
+ /**
+ * Check if there is an event waiting.
+ * @return true if there is an event on the stack.
+ */
+ static bool IsEventWaiting();
+
+ /**
+ * Get the next event.
+ * @return a class of the event-child issues.
+ */
+ static AIEvent *GetNextEvent();
+
+ /**
+ * Insert an event to the queue for the company.
+ * @param event The event to insert.
+ */
+ static void InsertEvent(AIEvent *event);
+
+ /**
+ * Free the event pointer.
+ * @note DO NOT CALL YOURSELF; leave it to the internal AI programming.
+ */
+ static void FreeEventPointer();
+
+private:
+ /**
+ * Create the event pointer.
+ */
+ static void CreateEventPointer();
+};
+
+#endif /* AI_EVENT_HPP */