Avoid dangling company purchase timeout when no clients connected to company
This commit is contained in:
@@ -684,6 +684,16 @@ static void HandleBankruptcyTakeover(Company *c)
|
|||||||
|
|
||||||
/* We're currently asking some company to buy 'us' */
|
/* We're currently asking some company to buy 'us' */
|
||||||
if (c->bankrupt_timeout != 0) {
|
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<CompanyID> 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;
|
c->bankrupt_timeout -= MAX_COMPANIES;
|
||||||
if (c->bankrupt_timeout > 0) return;
|
if (c->bankrupt_timeout > 0) return;
|
||||||
c->bankrupt_timeout = 0;
|
c->bankrupt_timeout = 0;
|
||||||
@@ -731,7 +741,7 @@ static void HandleBankruptcyTakeover(Company *c)
|
|||||||
} else if (!_networking || (_network_server && !NetworkCompanyHasClients(best->index))) {
|
} 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 */
|
/* This company can never accept the offer as there are no clients connected, decline the offer on the company's behalf */
|
||||||
Backup<CompanyID> cur_company(_current_company, best->index, FILE_LINE);
|
Backup<CompanyID> 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();
|
cur_company.Restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2891,7 +2891,7 @@ struct BuyCompanyWindow : Window {
|
|||||||
~BuyCompanyWindow()
|
~BuyCompanyWindow()
|
||||||
{
|
{
|
||||||
const Company *c = Company::GetIfValid((CompanyID)this->window_number);
|
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));
|
EnqueueDoCommandP(NewCommandContainerBasic(0, this->window_number, 0, CMD_DECLINE_BUY_COMPANY | CMD_NO_SHIFT_ESTIMATE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user