summaryrefslogtreecommitdiff
path: root/src/ai/api
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-09-01 12:57:04 +0000
committerrubidium <rubidium@openttd.org>2009-09-01 12:57:04 +0000
commit4c84db16361c17e6c3def857b400b9a974f90d44 (patch)
tree57d6185c490b3a04178e78f6bbcca714ac1b3824 /src/ai/api
parent4abf4602e7a0b624de9836b5a58d3d606612c2fa (diff)
downloadopenttd-4c84db16361c17e6c3def857b400b9a974f90d44.tar.xz
(svn r17345) -Fix [FS#2769]: one wasn't offered to take over bankrupt companies anymore; caused by the introduction NoAI, although NewAI had the same problem too.
Diffstat (limited to 'src/ai/api')
-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
6 files changed, 78 insertions, 0 deletions
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; }