summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ai/ai_instance.cpp1
-rw-r--r--src/game/game_instance.cpp1
-rw-r--r--src/script/api/ai/ai_event_types.hpp.sq16
-rw-r--r--src/script/api/game/game_event_types.hpp.sq16
-rw-r--r--src/script/api/script_event_types.hpp42
-rw-r--r--src/script/api/template/template_event_types.hpp.sq9
6 files changed, 85 insertions, 0 deletions
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index b1eb25b5a..b1988d2c0 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -128,6 +128,7 @@ void AIInstance::RegisterAPI()
SQAIEventCompanyInTrouble_Register(this->engine);
SQAIEventCompanyMerger_Register(this->engine);
SQAIEventCompanyNew_Register(this->engine);
+ SQAIEventCompanyTown_Register(this->engine);
SQAIEventController_Register(this->engine);
SQAIEventDisasterZeppelinerCleared_Register(this->engine);
SQAIEventDisasterZeppelinerCrashed_Register(this->engine);
diff --git a/src/game/game_instance.cpp b/src/game/game_instance.cpp
index 59091e449..4cdd33c97 100644
--- a/src/game/game_instance.cpp
+++ b/src/game/game_instance.cpp
@@ -126,6 +126,7 @@ void GameInstance::RegisterAPI()
SQGSEventCompanyInTrouble_Register(this->engine);
SQGSEventCompanyMerger_Register(this->engine);
SQGSEventCompanyNew_Register(this->engine);
+ SQGSEventCompanyTown_Register(this->engine);
SQGSEventController_Register(this->engine);
SQGSEventGoalQuestionAnswer_Register(this->engine);
SQGSEventIndustryClose_Register(this->engine);
diff --git a/src/script/api/ai/ai_event_types.hpp.sq b/src/script/api/ai/ai_event_types.hpp.sq
index bb46ed724..d40ab240a 100644
--- a/src/script/api/ai/ai_event_types.hpp.sq
+++ b/src/script/api/ai/ai_event_types.hpp.sq
@@ -361,3 +361,19 @@ void SQAIEventAircraftDestTooFar_Register(Squirrel *engine)
SQAIEventAircraftDestTooFar.PostRegister(engine);
}
+
+
+template <> const char *GetClassName<ScriptEventCompanyTown, ST_AI>() { return "AIEventCompanyTown"; }
+
+void SQAIEventCompanyTown_Register(Squirrel *engine)
+{
+ DefSQClass<ScriptEventCompanyTown, ST_AI> SQAIEventCompanyTown("AIEventCompanyTown");
+ SQAIEventCompanyTown.PreRegister(engine, "AIEvent");
+
+ SQAIEventCompanyTown.DefSQStaticMethod(engine, &ScriptEventCompanyTown::Convert, "Convert", 2, ".x");
+
+ SQAIEventCompanyTown.DefSQMethod(engine, &ScriptEventCompanyTown::GetCompanyID, "GetCompanyID", 1, "x");
+ SQAIEventCompanyTown.DefSQMethod(engine, &ScriptEventCompanyTown::GetTownID, "GetTownID", 1, "x");
+
+ SQAIEventCompanyTown.PostRegister(engine);
+}
diff --git a/src/script/api/game/game_event_types.hpp.sq b/src/script/api/game/game_event_types.hpp.sq
index 727e90bb1..6faacba44 100644
--- a/src/script/api/game/game_event_types.hpp.sq
+++ b/src/script/api/game/game_event_types.hpp.sq
@@ -266,3 +266,19 @@ void SQGSEventGoalQuestionAnswer_Register(Squirrel *engine)
SQGSEventGoalQuestionAnswer.PostRegister(engine);
}
+
+
+template <> const char *GetClassName<ScriptEventCompanyTown, ST_GS>() { return "GSEventCompanyTown"; }
+
+void SQGSEventCompanyTown_Register(Squirrel *engine)
+{
+ DefSQClass<ScriptEventCompanyTown, ST_GS> SQGSEventCompanyTown("GSEventCompanyTown");
+ SQGSEventCompanyTown.PreRegister(engine, "GSEvent");
+
+ SQGSEventCompanyTown.DefSQStaticMethod(engine, &ScriptEventCompanyTown::Convert, "Convert", 2, ".x");
+
+ SQGSEventCompanyTown.DefSQMethod(engine, &ScriptEventCompanyTown::GetCompanyID, "GetCompanyID", 1, "x");
+ SQGSEventCompanyTown.DefSQMethod(engine, &ScriptEventCompanyTown::GetTownID, "GetTownID", 1, "x");
+
+ SQGSEventCompanyTown.PostRegister(engine);
+}
diff --git a/src/script/api/script_event_types.hpp b/src/script/api/script_event_types.hpp
index d5a97bbdd..e416c6f04 100644
--- a/src/script/api/script_event_types.hpp
+++ b/src/script/api/script_event_types.hpp
@@ -980,5 +980,47 @@ private:
ScriptGoal::QuestionButton button; ///< The button he pressed.
};
+/**
+ * Base class for events involving a town and a company.
+ * @api ai game
+ */
+class ScriptEventCompanyTown : public ScriptEvent {
+public:
+ /**
+ * @param event The eventtype.
+ * @param company The company.
+ * @param town The town.
+ */
+ ScriptEventCompanyTown(ScriptEventType event, ScriptCompany::CompanyID company, TownID town) :
+ ScriptEvent(event),
+ company(company),
+ town(town)
+ {}
+
+ /**
+ * Convert an ScriptEvent to the real instance.
+ * @param instance The instance to convert.
+ * @return The converted instance.
+ */
+ static ScriptEventCompanyTown *Convert(ScriptEvent *instance) { return (ScriptEventCompanyTown *)instance; }
+
+ /**
+ * Get the CompanyID of the company.
+ * @return The CompanyID of the company involved into the event.
+ */
+ ScriptCompany::CompanyID GetCompanyID() { return this->company; }
+
+ /**
+ * Get the TownID of the town.
+ * @return The TownID of the town involved into the event.
+ */
+ TownID GetTownID() { return this->town; }
+
+private:
+ ScriptCompany::CompanyID company; ///< The company involved into the event.
+ TownID town; ///< The town involved into the event.
+};
+
+
#endif /* SCRIPT_EVENT_TYPES_HPP */
diff --git a/src/script/api/template/template_event_types.hpp.sq b/src/script/api/template/template_event_types.hpp.sq
index e03e7df3d..ae045a092 100644
--- a/src/script/api/template/template_event_types.hpp.sq
+++ b/src/script/api/template/template_event_types.hpp.sq
@@ -239,3 +239,12 @@ namespace SQConvert {
template <> inline const ScriptEventGoalQuestionAnswer &GetParam(ForceType<const ScriptEventGoalQuestionAnswer &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptEventGoalQuestionAnswer *)instance; }
template <> inline int Return<ScriptEventGoalQuestionAnswer *>(HSQUIRRELVM vm, ScriptEventGoalQuestionAnswer *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "EventGoalQuestionAnswer", res, NULL, DefSQDestructorCallback<ScriptEventGoalQuestionAnswer>, true); return 1; }
} // namespace SQConvert
+
+namespace SQConvert {
+ /* Allow ScriptEventCompanyTown to be used as Squirrel parameter */
+ template <> inline ScriptEventCompanyTown *GetParam(ForceType<ScriptEventCompanyTown *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptEventCompanyTown *)instance; }
+ template <> inline ScriptEventCompanyTown &GetParam(ForceType<ScriptEventCompanyTown &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptEventCompanyTown *)instance; }
+ template <> inline const ScriptEventCompanyTown *GetParam(ForceType<const ScriptEventCompanyTown *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptEventCompanyTown *)instance; }
+ template <> inline const ScriptEventCompanyTown &GetParam(ForceType<const ScriptEventCompanyTown &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptEventCompanyTown *)instance; }
+ template <> inline int Return<ScriptEventCompanyTown *>(HSQUIRRELVM vm, ScriptEventCompanyTown *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "EventCompanyTown", res, NULL, DefSQDestructorCallback<ScriptEventCompanyTown>, true); return 1; }
+} // namespace SQConvert