diff options
author | Patric Stout <truebrain@openttd.org> | 2021-06-11 00:18:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-11 00:18:20 +0200 |
commit | ef25afd55ab868a4322d0c241b5c4898966ac919 (patch) | |
tree | d2741bdd0973cf374993fbf4d1a203aa9d79e519 /src/economy.cpp | |
parent | acb6348ba62337d7580397d8f858e4a0bd1b0cab (diff) | |
download | openttd-ef25afd55ab868a4322d0c241b5c4898966ac919.tar.xz |
Fix #9348, 4d74e51: don't try to sell shares of spectators (#9349)
"new_owner" can be INVALID_OWNER, and as INVALID_OWNER ==
COMPANY_SPECTATORS, we could end up trying to sell shares of
nobody.
Diffstat (limited to 'src/economy.cpp')
-rw-r--r-- | src/economy.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/economy.cpp b/src/economy.cpp index efea96806..7f14bed8a 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -324,10 +324,12 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) Backup<CompanyID> cur_company2(_current_company, FILE_LINE); const Company *c = Company::Get(old_owner); for (i = 0; i < 4; i++) { + if (c->share_owners[i] == INVALID_OWNER) continue; + if (c->bankrupt_value == 0 && c->share_owners[i] == new_owner) { /* You are the one buying the company; so don't sell the shares back to you. */ - Company::Get(new_owner)->share_owners[i] = COMPANY_SPECTATOR; - } else if (c->share_owners[i] != INVALID_OWNER) { + Company::Get(new_owner)->share_owners[i] = INVALID_OWNER; + } else { cur_company2.Change(c->share_owners[i]); /* Sell the shares */ CommandCost res = DoCommand(0, old_owner, 0, DC_EXEC | DC_BANKRUPT, CMD_SELL_SHARE_IN_COMPANY); |