--- a/src/ai/api/ai_controller.cpp Sun Jun 08 23:43:19 2008 +0000
+++ b/src/ai/api/ai_controller.cpp Sun Jun 08 23:56:52 2008 +0000
@@ -96,6 +96,8 @@
SQAIEventCompanyNew_Register(this->engine);
SQAIEventController_Register(this->engine);
SQAIEventEnginePreview_Register(this->engine);
+ SQAIEventIndustryClose_Register(this->engine);
+ SQAIEventIndustryOpen_Register(this->engine);
SQAIEventSubsidyAwarded_Register(this->engine);
SQAIEventSubsidyExpired_Register(this->engine);
SQAIEventSubsidyOffer_Register(this->engine);
--- a/src/ai/api/ai_event.hpp Sun Jun 08 23:43:19 2008 +0000
+++ b/src/ai/api/ai_event.hpp Sun Jun 08 23:56:52 2008 +0000
@@ -35,6 +35,8 @@
AI_ET_VEHICLE_LOST,
AI_ET_VEHICLE_WAITING_IN_DEPOT,
AI_ET_VEHICLE_UNPROFITABLE,
+ AI_ET_INDUSTRY_OPEN,
+ AI_ET_INDUSTRY_CLOSE,
};
/**
--- a/src/ai/api/ai_event.hpp.sq Sun Jun 08 23:43:19 2008 +0000
+++ b/src/ai/api/ai_event.hpp.sq Sun Jun 08 23:56:52 2008 +0000
@@ -36,6 +36,8 @@
SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_VEHICLE_LOST, "AI_ET_VEHICLE_LOST");
SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_VEHICLE_WAITING_IN_DEPOT, "AI_ET_VEHICLE_WAITING_IN_DEPOT");
SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_VEHICLE_UNPROFITABLE, "AI_ET_VEHICLE_UNPROFITABLE");
+ SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_INDUSTRY_OPEN, "AI_ET_INDUSTRY_OPEN");
+ SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_INDUSTRY_CLOSE, "AI_ET_INDUSTRY_CLOSE");
SQAIEvent.DefSQStaticMethod(engine, &AIEvent::GetClassName, "GetClassName", 1, "x");
--- a/src/ai/api/ai_event_types.hpp Sun Jun 08 23:43:19 2008 +0000
+++ b/src/ai/api/ai_event_types.hpp Sun Jun 08 23:56:52 2008 +0000
@@ -544,4 +544,68 @@
VehicleID vehicle_id;
};
+/**
+ * Event Industry Open, indicating a new industry has been created.
+ */
+class AIEventIndustryOpen : public AIEvent {
+public:
+ static const char *GetClassName() { return "AIEventIndustryOpen"; }
+
+ /**
+ * @param industry_id The new industry.
+ */
+ AIEventIndustryOpen(IndustryID industry_id) :
+ AIEvent(AI_ET_INDUSTRY_OPEN),
+ industry_id(industry_id)
+ {}
+
+ /**
+ * Convert an AIEvent to the real instance.
+ * @param instance The instance to convert.
+ * @return The converted instance.
+ */
+ static AIEventIndustryOpen *Convert(AIEvent *instance) { return (AIEventIndustryOpen *)instance; }
+
+ /**
+ * Get the IndustryID of the new industry.
+ * @return The IndustryID of the industry.
+ */
+ IndustryID GetIndustryID() { return industry_id; }
+
+private:
+ IndustryID industry_id;
+};
+
+/**
+ * Event Industry Close, indicating an industry is going to be closed.
+ */
+class AIEventIndustryClose : public AIEvent {
+public:
+ static const char *GetClassName() { return "AIEventIndustryClose"; }
+
+ /**
+ * @param industry_id The new industry.
+ */
+ AIEventIndustryClose(IndustryID industry_id) :
+ AIEvent(AI_ET_INDUSTRY_CLOSE),
+ industry_id(industry_id)
+ {}
+
+ /**
+ * Convert an AIEvent to the real instance.
+ * @param instance The instance to convert.
+ * @return The converted instance.
+ */
+ static AIEventIndustryClose *Convert(AIEvent *instance) { return (AIEventIndustryClose *)instance; }
+
+ /**
+ * Get the IndustryID of the closing industry.
+ * @return The IndustryID of the industry.
+ */
+ IndustryID GetIndustryID() { return industry_id; }
+
+private:
+ IndustryID industry_id;
+};
+
#endif /* AI_EVENT_TYPES_HPP */
--- a/src/ai/api/ai_event_types.hpp.sq Sun Jun 08 23:43:19 2008 +0000
+++ b/src/ai/api/ai_event_types.hpp.sq Sun Jun 08 23:56:52 2008 +0000
@@ -306,3 +306,45 @@
SQAIEventVehicleUnprofitable.PostRegister(engine);
}
+
+namespace SQConvert {
+ /* Allow AIEventIndustryOpen to be used as Squirrel parameter */
+ template <> AIEventIndustryOpen *GetParam(ForceType<AIEventIndustryOpen *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIEventIndustryOpen *)instance; }
+ template <> AIEventIndustryOpen &GetParam(ForceType<AIEventIndustryOpen &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventIndustryOpen *)instance; }
+ template <> const AIEventIndustryOpen *GetParam(ForceType<const AIEventIndustryOpen *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIEventIndustryOpen *)instance; }
+ template <> const AIEventIndustryOpen &GetParam(ForceType<const AIEventIndustryOpen &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventIndustryOpen *)instance; }
+ template <> int Return<AIEventIndustryOpen *>(HSQUIRRELVM vm, AIEventIndustryOpen *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIEventIndustryOpen", res, NULL, DefSQDestructorCallback<AIEventIndustryOpen>); return 1; }
+}; // namespace SQConvert
+
+void SQAIEventIndustryOpen_Register(Squirrel *engine) {
+ DefSQClass <AIEventIndustryOpen> SQAIEventIndustryOpen("AIEventIndustryOpen");
+ SQAIEventIndustryOpen.PreRegister(engine, "AIEvent");
+
+ SQAIEventIndustryOpen.DefSQStaticMethod(engine, &AIEventIndustryOpen::GetClassName, "GetClassName", 1, "x");
+ SQAIEventIndustryOpen.DefSQStaticMethod(engine, &AIEventIndustryOpen::Convert, "Convert", 2, "xx");
+
+ SQAIEventIndustryOpen.DefSQMethod(engine, &AIEventIndustryOpen::GetIndustryID, "GetIndustryID", 1, "x");
+
+ SQAIEventIndustryOpen.PostRegister(engine);
+}
+
+namespace SQConvert {
+ /* Allow AIEventIndustryClose to be used as Squirrel parameter */
+ template <> AIEventIndustryClose *GetParam(ForceType<AIEventIndustryClose *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIEventIndustryClose *)instance; }
+ template <> AIEventIndustryClose &GetParam(ForceType<AIEventIndustryClose &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventIndustryClose *)instance; }
+ template <> const AIEventIndustryClose *GetParam(ForceType<const AIEventIndustryClose *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIEventIndustryClose *)instance; }
+ template <> const AIEventIndustryClose &GetParam(ForceType<const AIEventIndustryClose &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventIndustryClose *)instance; }
+ template <> int Return<AIEventIndustryClose *>(HSQUIRRELVM vm, AIEventIndustryClose *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIEventIndustryClose", res, NULL, DefSQDestructorCallback<AIEventIndustryClose>); return 1; }
+}; // namespace SQConvert
+
+void SQAIEventIndustryClose_Register(Squirrel *engine) {
+ DefSQClass <AIEventIndustryClose> SQAIEventIndustryClose("AIEventIndustryClose");
+ SQAIEventIndustryClose.PreRegister(engine, "AIEvent");
+
+ SQAIEventIndustryClose.DefSQStaticMethod(engine, &AIEventIndustryClose::GetClassName, "GetClassName", 1, "x");
+ SQAIEventIndustryClose.DefSQStaticMethod(engine, &AIEventIndustryClose::Convert, "Convert", 2, "xx");
+
+ SQAIEventIndustryClose.DefSQMethod(engine, &AIEventIndustryClose::GetIndustryID, "GetIndustryID", 1, "x");
+
+ SQAIEventIndustryClose.PostRegister(engine);
+}
--- a/src/industry_cmd.cpp Sun Jun 08 23:43:19 2008 +0000
+++ b/src/industry_cmd.cpp Sun Jun 08 23:56:52 2008 +0000
@@ -40,6 +40,7 @@
#include "oldpool_func.h"
#include "animated_tile_func.h"
#include "effectvehicle_func.h"
+#include "ai/ai.h"
#include "table/strings.h"
#include "table/sprites.h"
@@ -1659,8 +1660,10 @@
} else {
SetDParam(1, ind->town->index);
}
- AddNewsItem(indspec->new_industry_text,
- NS_OPENCLOSE, ind->xy, 0);
+ AddNewsItem(indspec->new_industry_text, NS_OPENCLOSE, ind->xy, 0);
+ for (PlayerID p = PLAYER_FIRST; p < MAX_PLAYERS; p++) {
+ AI_Event(p, new AIEventIndustryOpen(ind->index));
+ }
break;
}
}
@@ -1878,8 +1881,10 @@
} else {
SetDParam(1, ind->town->index);
}
- AddNewsItem(ind_spc->new_industry_text,
- NS_OPENCLOSE, ind->xy, 0);
+ AddNewsItem(ind_spc->new_industry_text, NS_OPENCLOSE, ind->xy, 0);
+ for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
+ AI_Event(i, new AIEventIndustryOpen(ind->index));
+ }
}
/**
@@ -2195,6 +2200,9 @@
/* Compute news category */
if (closeit) {
ns = NS_OPENCLOSE;
+ for (PlayerID p = PLAYER_FIRST; p < MAX_PLAYERS; p++) {
+ AI_Event(p, new AIEventIndustryClose(i->index));
+ }
} else {
switch (WhoCanServiceIndustry(i)) {
case 0: ns = NS_INDUSTRY_NOBODY; break;