diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index ea47886166..da0bd9c548 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -730,7 +730,7 @@ static void HandleBankruptcyTakeover(Company *c) c->bankrupt_timeout = TAKE_OVER_TIMEOUT; - AI::NewEvent(best->index, new ScriptEventCompanyAskMerger(c->index, c->bankrupt_value)); + ScriptTrigger::NewEvent(best->index, best->index, c->index, c->bankrupt_value); if (IsInteractiveCompany(best->index)) { ShowBuyCompanyDialog(c->index, false); } diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index 3f6806dfd8..78650ab9fc 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -36,6 +36,7 @@ * \li GSEventDisasterZeppelinerCleared * \li GSEventAircraftDestTooFar * \li GSEventVehicleAutoReplaced + * \li GSEventCompanyAskMerger * * Other changes: * \li GSBridge::GetBridgeID renamed to GSBridge::GetBridgeType diff --git a/src/script/api/script_event_types.cpp b/src/script/api/script_event_types.cpp index 541e124e38..24893bc1d6 100644 --- a/src/script/api/script_event_types.cpp +++ b/src/script/api/script_event_types.cpp @@ -113,6 +113,7 @@ bool ScriptEventEnginePreview::AcceptPreview() bool ScriptEventCompanyAskMerger::AcceptMerger() { EnforceCompanyModeValid(false); + EnforcePrecondition(false, ScriptObject::GetCompany() == ScriptCompany::FromScriptCompanyID(this->buyer)); return ScriptObject::Command::Do(ScriptCompany::FromScriptCompanyID(this->owner), false); } diff --git a/src/script/api/script_event_types.hpp b/src/script/api/script_event_types.hpp index fdc548d591..f44dd74fe0 100644 --- a/src/script/api/script_event_types.hpp +++ b/src/script/api/script_event_types.hpp @@ -439,17 +439,19 @@ private: /** * Event Company Ask Merger, indicating a company can be bought (cheaply) by you. - * @api ai + * @api ai game */ class ScriptEventCompanyAskMerger : public ScriptEvent { public: #ifndef DOXYGEN_API /** + * @param buyer The company that can buy. * @param owner The company that can be bought. * @param value The value/costs of buying the company. */ - ScriptEventCompanyAskMerger(Owner owner, Money value) : + ScriptEventCompanyAskMerger(Owner buyer, Owner owner, Money value) : ScriptEvent(ET_COMPANY_ASK_MERGER), + buyer(ScriptCompany::ToScriptCompanyID(buyer)), owner(ScriptCompany::ToScriptCompanyID(owner)), value(value) {} @@ -462,6 +464,14 @@ public: */ static ScriptEventCompanyAskMerger *Convert(ScriptEvent *instance) { return (ScriptEventCompanyAskMerger *)instance; } + /** + * Get the CompanyID of the company that can purchase the other. + * @return The CompanyID of the company that can purchase. + * @note If the company is bought this will become invalid. + * @api -ai + */ + ScriptCompany::CompanyID GetBuyerID() { return this->buyer; } + /** * Get the CompanyID of the company that can be bought. * @return The CompanyID of the company that can be bought. @@ -483,8 +493,9 @@ public: bool AcceptMerger(); private: + ScriptCompany::CompanyID buyer; ///< The company that is buying. ScriptCompany::CompanyID owner; ///< The company that is in trouble. - Money value; ///< The value of the company, i.e. the amount you would pay. + Money value; ///< The value of the company in trouble, i.e. the amount the buyer would pay. }; /**