Changeset - r25638:746ccf302c92
[Not reviewed]
master
0 2 0
Patric Stout - 3 years ago 2021-06-10 22:18:20
truebrain@openttd.org
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.
2 files changed with 5 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/company_cmd.cpp
Show inline comments
 
@@ -67,7 +67,7 @@ Company::Company(uint16 name_1, bool is_
 
	this->clear_limit     = (uint32)_settings_game.construction.clear_frame_burst << 16;
 
	this->tree_limit      = (uint32)_settings_game.construction.tree_frame_burst << 16;
 

	
 
	for (uint j = 0; j < 4; j++) this->share_owners[j] = COMPANY_SPECTATOR;
 
	for (uint j = 0; j < 4; j++) this->share_owners[j] = INVALID_OWNER;
 
	InvalidateWindowData(WC_PERFORMANCE_DETAIL, 0, INVALID_COMPANY);
 
}
 

	
src/economy.cpp
Show inline comments
 
@@ -324,10 +324,12 @@ void ChangeOwnershipOfCompanyItems(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);
0 comments (0 inline, 0 general)