summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-12-29 23:44:39 +0000
committeryexo <yexo@openttd.org>2010-12-29 23:44:39 +0000
commit703ff560c19e2b21597e9ed25b3e394a2085702a (patch)
treec1d2b4b0197c9adfee798f7823534f91f4dddf2c /src/ai
parent5b25e620dd747d35b024d6d244be9fc7002e38b0 (diff)
downloadopenttd-703ff560c19e2b21597e9ed25b3e394a2085702a.tar.xz
(svn r21664) -Add: [NoAI] AIEventTownFounded
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/ai_instance.cpp1
-rw-r--r--src/ai/api/ai_event.hpp1
-rw-r--r--src/ai/api/ai_event.hpp.sq1
-rw-r--r--src/ai/api/ai_event_types.hpp33
-rw-r--r--src/ai/api/ai_event_types.hpp.sq21
5 files changed, 57 insertions, 0 deletions
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index 628a32e29..a2b980fb6 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -209,6 +209,7 @@ void AIInstance::RegisterAPI()
SQAIEventSubsidyExpired_Register(this->engine);
SQAIEventSubsidyOffer_Register(this->engine);
SQAIEventSubsidyOfferExpired_Register(this->engine);
+ SQAIEventTownFounded_Register(this->engine);
SQAIEventVehicleCrashed_Register(this->engine);
SQAIEventVehicleLost_Register(this->engine);
SQAIEventVehicleUnprofitable_Register(this->engine);
diff --git a/src/ai/api/ai_event.hpp b/src/ai/api/ai_event.hpp
index ed77d95b3..4b3b2cf94 100644
--- a/src/ai/api/ai_event.hpp
+++ b/src/ai/api/ai_event.hpp
@@ -50,6 +50,7 @@ public:
AI_ET_STATION_FIRST_VEHICLE,
AI_ET_DISASTER_ZEPPELINER_CRASHED,
AI_ET_DISASTER_ZEPPELINER_CLEARED,
+ AI_ET_TOWN_FOUNDED,
};
/**
diff --git a/src/ai/api/ai_event.hpp.sq b/src/ai/api/ai_event.hpp.sq
index b6756a8db..b97de98ed 100644
--- a/src/ai/api/ai_event.hpp.sq
+++ b/src/ai/api/ai_event.hpp.sq
@@ -52,6 +52,7 @@ void SQAIEvent_Register(Squirrel *engine)
SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_STATION_FIRST_VEHICLE, "AI_ET_STATION_FIRST_VEHICLE");
SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_DISASTER_ZEPPELINER_CRASHED, "AI_ET_DISASTER_ZEPPELINER_CRASHED");
SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_DISASTER_ZEPPELINER_CLEARED, "AI_ET_DISASTER_ZEPPELINER_CLEARED");
+ SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_TOWN_FOUNDED, "AI_ET_TOWN_FOUNDED");
SQAIEvent.DefSQMethod(engine, &AIEvent::GetEventType, "GetEventType", 1, "x");
diff --git a/src/ai/api/ai_event_types.hpp b/src/ai/api/ai_event_types.hpp
index da6b54983..acb36c77c 100644
--- a/src/ai/api/ai_event_types.hpp
+++ b/src/ai/api/ai_event_types.hpp
@@ -800,4 +800,37 @@ private:
StationID station;
};
+/**
+ * Event Town Founded, indicating a new town has been created.
+ */
+class AIEventTownFounded : public AIEvent {
+public:
+ /** Get the name of this class to identify it towards squirrel. */
+ static const char *GetClassName() { return "AIEventTownFounded"; }
+
+ /**
+ * @param town The town that was created.
+ */
+ AIEventTownFounded(TownID town) :
+ AIEvent(AI_ET_TOWN_FOUNDED),
+ town(town)
+ {}
+
+ /**
+ * Convert an AIEvent to the real instance.
+ * @param instance The instance to convert.
+ * @return The converted instance.
+ */
+ static AIEventTownFounded *Convert(AIEvent *instance) { return (AIEventTownFounded *)instance; }
+
+ /**
+ * Get the TownID of the town.
+ * @return The TownID of the town that was created.
+ */
+ TownID GetTownID() { return this->town; }
+
+private:
+ TownID town;
+};
+
#endif /* AI_EVENT_TYPES_HPP */
diff --git a/src/ai/api/ai_event_types.hpp.sq b/src/ai/api/ai_event_types.hpp.sq
index 188060c72..771a0778e 100644
--- a/src/ai/api/ai_event_types.hpp.sq
+++ b/src/ai/api/ai_event_types.hpp.sq
@@ -454,3 +454,24 @@ void SQAIEventDisasterZeppelinerCleared_Register(Squirrel *engine)
SQAIEventDisasterZeppelinerCleared.PostRegister(engine);
}
+
+namespace SQConvert {
+ /* Allow AIEventTownFounded to be used as Squirrel parameter */
+ template <> AIEventTownFounded *GetParam(ForceType<AIEventTownFounded *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIEventTownFounded *)instance; }
+ template <> AIEventTownFounded &GetParam(ForceType<AIEventTownFounded &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventTownFounded *)instance; }
+ template <> const AIEventTownFounded *GetParam(ForceType<const AIEventTownFounded *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIEventTownFounded *)instance; }
+ template <> const AIEventTownFounded &GetParam(ForceType<const AIEventTownFounded &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventTownFounded *)instance; }
+ template <> int Return<AIEventTownFounded *>(HSQUIRRELVM vm, AIEventTownFounded *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIEventTownFounded", res, NULL, DefSQDestructorCallback<AIEventTownFounded>); return 1; }
+} // namespace SQConvert
+
+void SQAIEventTownFounded_Register(Squirrel *engine)
+{
+ DefSQClass <AIEventTownFounded> SQAIEventTownFounded("AIEventTownFounded");
+ SQAIEventTownFounded.PreRegister(engine, "AIEvent");
+
+ SQAIEventTownFounded.DefSQStaticMethod(engine, &AIEventTownFounded::Convert, "Convert", 2, ".x");
+
+ SQAIEventTownFounded.DefSQMethod(engine, &AIEventTownFounded::GetTownID, "GetTownID", 1, "x");
+
+ SQAIEventTownFounded.PostRegister(engine);
+}