diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 7f814a0889..4f51782d37 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -684,6 +684,16 @@ static void HandleBankruptcyTakeover(Company *c) /* We're currently asking some company to buy 'us' */ if (c->bankrupt_timeout != 0) { + if (!Company::IsValidID(c->bankrupt_last_asked)) { + c->bankrupt_timeout = 0; + return; + } + if (_network_server && Company::IsValidHumanID(c->bankrupt_last_asked) && !NetworkCompanyHasClients(c->bankrupt_last_asked)) { + /* This company can no longer accept the offer as there are no clients connected, decline the offer on the company's behalf */ + Backup cur_company(_current_company, c->bankrupt_last_asked, FILE_LINE); + DoCommandP(0, c->index, 0, CMD_DECLINE_BUY_COMPANY | CMD_NO_SHIFT_ESTIMATE); + cur_company.Restore(); + } c->bankrupt_timeout -= MAX_COMPANIES; if (c->bankrupt_timeout > 0) return; c->bankrupt_timeout = 0; @@ -731,7 +741,7 @@ static void HandleBankruptcyTakeover(Company *c) } else if (!_networking || (_network_server && !NetworkCompanyHasClients(best->index))) { /* This company can never accept the offer as there are no clients connected, decline the offer on the company's behalf */ Backup cur_company(_current_company, best->index, FILE_LINE); - DoCommandP(0, c->index, 0, CMD_DECLINE_BUY_COMPANY); + DoCommandP(0, c->index, 0, CMD_DECLINE_BUY_COMPANY | CMD_NO_SHIFT_ESTIMATE); cur_company.Restore(); } } diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 18e0c5f16b..e65090a336 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -2891,7 +2891,7 @@ struct BuyCompanyWindow : Window { ~BuyCompanyWindow() { const Company *c = Company::GetIfValid((CompanyID)this->window_number); - if (c != nullptr && HasBit(c->bankrupt_asked, this->owner)) { + if (c != nullptr && HasBit(c->bankrupt_asked, this->owner) && _current_company == this->owner) { EnqueueDoCommandP(NewCommandContainerBasic(0, this->window_number, 0, CMD_DECLINE_BUY_COMPANY | CMD_NO_SHIFT_ESTIMATE)); } }