summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/ai_instance.cpp1
-rw-r--r--src/ai/api/ai_changelog.hpp1
-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.cpp5
-rw-r--r--src/ai/api/ai_event_types.hpp48
-rw-r--r--src/ai/api/ai_event_types.hpp.sq22
7 files changed, 79 insertions, 0 deletions
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index 2d5a01251..6d29aec95 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -186,6 +186,7 @@ void AIInstance::RegisterAPI()
SQAIEngineList_Register(this->engine);
SQAIError_Register(this->engine);
SQAIEvent_Register(this->engine);
+ SQAIEventCompanyAskMerger_Register(this->engine);
SQAIEventCompanyBankrupt_Register(this->engine);
SQAIEventCompanyInTrouble_Register(this->engine);
SQAIEventCompanyMerger_Register(this->engine);
diff --git a/src/ai/api/ai_changelog.hpp b/src/ai/api/ai_changelog.hpp
index c1c9e44be..6c14b7a2e 100644
--- a/src/ai/api/ai_changelog.hpp
+++ b/src/ai/api/ai_changelog.hpp
@@ -19,6 +19,7 @@
* API additions:
* \li AIBaseStation
* \li AIBuoyList
+ * \li AIEventCompanyAskMerger
* \li AIRail::RemoveRailWaypointTileRect
* \li AISubsidy::SubsidyParticipantType
* \li AISubsidy::GetSourceType
diff --git a/src/ai/api/ai_event.hpp b/src/ai/api/ai_event.hpp
index 25330a4cf..dd12dfbca 100644
--- a/src/ai/api/ai_event.hpp
+++ b/src/ai/api/ai_event.hpp
@@ -36,6 +36,7 @@ public:
AI_ET_ENGINE_PREVIEW,
AI_ET_COMPANY_NEW,
AI_ET_COMPANY_IN_TROUBLE,
+ AI_ET_COMPANY_ASK_MERGER,
AI_ET_COMPANY_MERGER,
AI_ET_COMPANY_BANKRUPT,
AI_ET_VEHICLE_CRASHED,
diff --git a/src/ai/api/ai_event.hpp.sq b/src/ai/api/ai_event.hpp.sq
index dd365c4bc..cc250961f 100644
--- a/src/ai/api/ai_event.hpp.sq
+++ b/src/ai/api/ai_event.hpp.sq
@@ -38,6 +38,7 @@ void SQAIEvent_Register(Squirrel *engine) {
SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_ENGINE_PREVIEW, "AI_ET_ENGINE_PREVIEW");
SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_COMPANY_NEW, "AI_ET_COMPANY_NEW");
SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_COMPANY_IN_TROUBLE, "AI_ET_COMPANY_IN_TROUBLE");
+ SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_COMPANY_ASK_MERGER, "AI_ET_COMPANY_ASK_MERGER");
SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_COMPANY_MERGER, "AI_ET_COMPANY_MERGER");
SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_COMPANY_BANKRUPT, "AI_ET_COMPANY_BANKRUPT");
SQAIEvent.DefSQConst(engine, AIEvent::AI_ET_VEHICLE_CRASHED, "AI_ET_VEHICLE_CRASHED");
diff --git a/src/ai/api/ai_event_types.cpp b/src/ai/api/ai_event_types.cpp
index 554112f87..5500d15cb 100644
--- a/src/ai/api/ai_event_types.cpp
+++ b/src/ai/api/ai_event_types.cpp
@@ -92,3 +92,8 @@ bool AIEventEnginePreview::AcceptPreview()
{
return AIObject::DoCommand(0, this->engine, 0, CMD_WANT_ENGINE_PREVIEW);
}
+
+bool AIEventCompanyAskMerger::AcceptMerger()
+{
+ return AIObject::DoCommand(0, this->owner, 0, CMD_BUY_COMPANY);
+}
diff --git a/src/ai/api/ai_event_types.hpp b/src/ai/api/ai_event_types.hpp
index 7c5112949..774df7c44 100644
--- a/src/ai/api/ai_event_types.hpp
+++ b/src/ai/api/ai_event_types.hpp
@@ -359,6 +359,54 @@ private:
};
/**
+ * Event Company Ask Merger, indicating a company can be bought (cheaply) by you.
+ */
+class AIEventCompanyAskMerger : public AIEvent {
+public:
+ static const char *GetClassName() { return "AIEventCompanyAskMerger"; }
+
+ /**
+ * @param owner The company that can be bough.
+ * @param value The value/costs of buying the company.
+ */
+ AIEventCompanyAskMerger(Owner owner, int32 value) :
+ AIEvent(AI_ET_COMPANY_MERGER),
+ owner((AICompany::CompanyID)owner),
+ value(value)
+ {}
+
+ /**
+ * Convert an AIEvent to the real instance.
+ * @param instance The instance to convert.
+ * @return The converted instance.
+ */
+ static AIEventCompanyAskMerger *Convert(AIEvent *instance) { return (AIEventCompanyAskMerger *)instance; }
+
+ /**
+ * Get the CompanyID of the company that can be bought.
+ * @return The CompanyID of the company that can be bought.
+ * @note If the company is bought this will become invalid.
+ */
+ AICompany::CompanyID GetCompanyID() { return this->owner; }
+
+ /**
+ * Get the value of the new company.
+ * @return The value of the new company.
+ */
+ int32 GetValue() { return this->value; }
+
+ /**
+ * Take over the company for this merger.
+ * @return true if the merger was a success.
+ */
+ bool AcceptMerger();
+
+private:
+ AICompany::CompanyID owner;
+ int32 value;
+};
+
+/**
* Event Company Merger, indicating a company has been bought by another
* company.
*/
diff --git a/src/ai/api/ai_event_types.hpp.sq b/src/ai/api/ai_event_types.hpp.sq
index f10bb9621..a0842231a 100644
--- a/src/ai/api/ai_event_types.hpp.sq
+++ b/src/ai/api/ai_event_types.hpp.sq
@@ -192,6 +192,28 @@ void SQAIEventCompanyInTrouble_Register(Squirrel *engine) {
}
namespace SQConvert {
+ /* Allow AIEventCompanyAskMerger to be used as Squirrel parameter */
+ template <> AIEventCompanyAskMerger *GetParam(ForceType<AIEventCompanyAskMerger *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIEventCompanyAskMerger *)instance; }
+ template <> AIEventCompanyAskMerger &GetParam(ForceType<AIEventCompanyAskMerger &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventCompanyAskMerger *)instance; }
+ template <> const AIEventCompanyAskMerger *GetParam(ForceType<const AIEventCompanyAskMerger *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIEventCompanyAskMerger *)instance; }
+ template <> const AIEventCompanyAskMerger &GetParam(ForceType<const AIEventCompanyAskMerger &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventCompanyAskMerger *)instance; }
+ template <> int Return<AIEventCompanyAskMerger *>(HSQUIRRELVM vm, AIEventCompanyAskMerger *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIEventCompanyAskMerger", res, NULL, DefSQDestructorCallback<AIEventCompanyAskMerger>); return 1; }
+}; // namespace SQConvert
+
+void SQAIEventCompanyAskMerger_Register(Squirrel *engine) {
+ DefSQClass <AIEventCompanyAskMerger> SQAIEventCompanyAskMerger("AIEventCompanyAskMerger");
+ SQAIEventCompanyAskMerger.PreRegister(engine, "AIEvent");
+
+ SQAIEventCompanyAskMerger.DefSQStaticMethod(engine, &AIEventCompanyAskMerger::Convert, "Convert", 2, ".x");
+
+ SQAIEventCompanyAskMerger.DefSQMethod(engine, &AIEventCompanyAskMerger::GetCompanyID, "GetCompanyID", 1, "x");
+ SQAIEventCompanyAskMerger.DefSQMethod(engine, &AIEventCompanyAskMerger::GetValue, "GetValue", 1, "x");
+ SQAIEventCompanyAskMerger.DefSQMethod(engine, &AIEventCompanyAskMerger::AcceptMerger, "AcceptMerger", 1, "x");
+
+ SQAIEventCompanyAskMerger.PostRegister(engine);
+}
+
+namespace SQConvert {
/* Allow AIEventCompanyMerger to be used as Squirrel parameter */
template <> AIEventCompanyMerger *GetParam(ForceType<AIEventCompanyMerger *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIEventCompanyMerger *)instance; }
template <> AIEventCompanyMerger &GetParam(ForceType<AIEventCompanyMerger &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventCompanyMerger *)instance; }