From 9f63b9f65d212e4993755e7430654b25a31b6d77 Mon Sep 17 00:00:00 2001 From: Tyler Trahan Date: Mon, 13 May 2024 10:10:03 -0400 Subject: [PATCH] Fix #12594: Give descriptive error when company takeover fails due to vehicle limit (#12676) --- src/company_cmd.cpp | 6 +++--- src/company_func.h | 2 +- src/economy.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index fa4dc0e8ef..ec9d273857 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -668,12 +668,12 @@ void InitializeCompanies() } /** - * May company \a cbig buy company \a csmall? + * Can company \a cbig buy company \a csmall without exceeding vehicle limits? * @param cbig Company buying \a csmall. * @param csmall Company getting bought. * @return Return \c true if it is allowed. */ -bool MayCompanyTakeOver(CompanyID cbig, CompanyID csmall) +bool CheckTakeoverVehicleLimit(CompanyID cbig, CompanyID csmall) { const Company *c1 = Company::Get(cbig); const Company *c2 = Company::Get(csmall); @@ -725,7 +725,7 @@ static void HandleBankruptcyTakeover(Company *c) if (c2->bankrupt_asked == 0 && // Don't ask companies going bankrupt themselves !HasBit(c->bankrupt_asked, c2->index) && best_performance < c2->old_economy[1].performance_history && - MayCompanyTakeOver(c2->index, c->index)) { + CheckTakeoverVehicleLimit(c2->index, c->index)) { best_performance = c2->old_economy[1].performance_history; best = c2; } diff --git a/src/company_func.h b/src/company_func.h index 5d2d0df1dd..33885516c4 100644 --- a/src/company_func.h +++ b/src/company_func.h @@ -15,7 +15,7 @@ #include "gfx_type.h" #include "vehicle_type.h" -bool MayCompanyTakeOver(CompanyID cbig, CompanyID small); +bool CheckTakeoverVehicleLimit(CompanyID cbig, CompanyID small); void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner); static const int OWNED_BY_OWNER_IN_PARAMETERS_OFFSET = 2; ///< The index in the parameters for the owner information. void SetDParamsForOwnedBy(Owner owner, TileIndex tile); diff --git a/src/economy.cpp b/src/economy.cpp index bdb3cb06e0..04a1131d30 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -2066,8 +2066,8 @@ CommandCost CmdBuyCompany(DoCommandFlag flags, CompanyID target_company, bool ho /* Do not allow companies to take over themselves */ if (target_company == _current_company) return CMD_ERROR; - /* Disable taking over when not allowed. */ - if (!MayCompanyTakeOver(_current_company, target_company)) return CMD_ERROR; + /* Do not allow takeover if the resulting company would have too many vehicles. */ + if (!CheckTakeoverVehicleLimit(_current_company, target_company)) return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME); /* Get the cost here as the company is deleted in DoAcquireCompany. * For bankruptcy this amount is calculated when the offer was made;