summaryrefslogtreecommitdiff
path: root/ai
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2005-11-23 15:08:29 +0000
committertruelight <truelight@openttd.org>2005-11-23 15:08:29 +0000
commit8733f49e883249117580bb8457266cde858f6bac (patch)
tree39b2634d00d2ef0c50327795368bd790f4a2d3af /ai
parentb8f8f3869d3e16aa914133c3ba2c4a66a94068bc (diff)
downloadopenttd-8733f49e883249117580bb8457266cde858f6bac.tar.xz
(svn r3232) -Add: implemented the event-system for AIs
-Add: added several hooks (event-callbacks) for road-related-stuff
Diffstat (limited to 'ai')
-rw-r--r--ai/ai.c5
-rw-r--r--ai/ai_event.h58
2 files changed, 63 insertions, 0 deletions
diff --git a/ai/ai.c b/ai/ai.c
index 764d06f94..e3fe2d307 100644
--- a/ai/ai.c
+++ b/ai/ai.c
@@ -9,6 +9,11 @@
#include "ai.h"
#include "default/default.h"
+/* Here we define the events */
+#define DEF_EVENTS
+#include "ai_event.h"
+#undef DEF_EVENTS
+
/**
* Dequeues commands put in the queue via AI_PutCommandInQueue.
*/
diff --git a/ai/ai_event.h b/ai/ai_event.h
new file mode 100644
index 000000000..7f96f71b8
--- /dev/null
+++ b/ai/ai_event.h
@@ -0,0 +1,58 @@
+#ifndef AI_EVENT
+#define AI_EVENT
+
+/* Make the ai_event macro set correctly */
+#ifdef GPMI
+# include <gpmi.h>
+# include "ai.h"
+
+/* This is how we call events (with safety-check) to GPMI */
+/* XXX -- This macro (vararg macro) isn't supported on old GCCs, but GPMI
+ * is using them too, so it isn't a real problem, yet */
+# define ai_event(player, params...) \
+ if (player < MAX_PLAYERS && _ai_player[player].module != NULL) \
+ gpmi_event(_ai_player[player].module, params)
+
+#else
+/* If GPMI isn't loaded, don't do a thing with the events (for now at least)
+ * Because old GCCs don't support vararg macros, and OTTD does support those
+ * GCCs, we need something tricky to ignore the events... and this is the solution :)
+ * Ugly, I know, but it works! */
+
+# ifdef DEF_EVENTS
+ void empty_function(PlayerID player, int event, ...) {}
+# else
+ extern void empty_function(PlayerID player, int event, ...);
+# endif
+# define ai_event empty_function
+
+#endif /* GPMI */
+
+/* To make our life a bit easier; you now only have to define new
+ * events here, and automaticly they work in OpenTTD without including
+ * the ottd_event package. Just because of some lovely macro-shit ;) */
+#ifdef DEF_EVENTS
+# define DEF_EVENTS
+# define INITIAL_SET = -1
+#else
+# define DEF_EVENTS extern
+# define INITIAL_SET
+#endif /* DEF_EVENTS */
+
+/* ------------ All available events -------------- */
+DEF_EVENTS int ottd_Event_BuildStation INITIAL_SET; // (station_index, station_tile)
+DEF_EVENTS int ottd_Event_BuildRoadStation INITIAL_SET; // (station_index, station_tile)
+
+DEF_EVENTS int ottd_Event_BuildDepot INITIAL_SET; // (depot_index, depot_tile)
+DEF_EVENTS int ottd_Event_BuildRoadDepot INITIAL_SET; // (depot_index, depot_tile)
+
+DEF_EVENTS int ottd_Event_BuildVehicle INITIAL_SET; // (vehicle_index, depot_tile)
+DEF_EVENTS int ottd_Event_BuildRoadVehicle INITIAL_SET; // (vehicle_index, depot_tile)
+
+DEF_EVENTS int ottd_Event_VehicleEnterDepot INITIAL_SET; // (vehicle_index, depot_tile)
+DEF_EVENTS int ottd_Event_RoadVehicleEnterDepot INITIAL_SET; // (vehicle_index, depot_tile)
+
+DEF_EVENTS int ottd_Event_GiveOrder INITIAL_SET; // (vehicle_index)
+/* ----------------- End of list ------------------ */
+
+#endif /* AI_EVENT */