summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
-rw-r--r--src/town_cmd.cpp2
6 files changed, 59 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);
+}
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 9ab7eacda..32bb0df9f 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -47,6 +47,7 @@
#include "depot_base.h"
#include "object_map.h"
#include "object_base.h"
+#include "ai/ai.hpp"
#include "table/strings.h"
#include "table/town_land.h"
@@ -1605,6 +1606,7 @@ CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
SetDParam(1, t->index);
AddNewsItem(STR_NEWS_NEW_TOWN, NS_INDUSTRY_OPEN, NR_TILE, tile, NR_NONE, UINT32_MAX, cn);
+ AI::BroadcastNewEvent(new AIEventTownFounded(t->index));
}
}
return cost;