Changeset - r6403:52da6c863575
[Not reviewed]
master
0 1 0
truelight - 17 years ago 2007-03-31 12:19:22
truelight@openttd.org
(svn r9533) -Fix [FS#274]: when a company is removed (either via auto-clean, bankrupt, or take over), sell all the shares he has first, then sell the shares all people have on this company, and then remove the company.
1 file changed with 33 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -254,6 +254,39 @@ void ChangeOwnershipOfPlayerItems(Player
 
{
 
	Town *t;
 
	PlayerID old = _current_player;
 

	
 
	{
 
		Player *p;
 
		uint i;
 

	
 
		/* See if the old_player had shares in other companies */
 
		_current_player = old_player;
 
		FOR_ALL_PLAYERS(p) {
 
			for (i = 0; i < 4; i++) {
 
				if (p->share_owners[i] == old_player) {
 
					/* Sell his shares */
 
					int32 res = DoCommand(0, p->index, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
 
					/* Because we are in a DoCommand, we can't just execute an other one and
 
					 *  expect the money to be removed. We need to do it ourself! */
 
					SubtractMoneyFromPlayer(res);
 
				}
 
			}
 
		}
 

	
 
		/* Sell all the shares that people have on this company */
 
		p = GetPlayer(old_player);
 
		for (i = 0; i < 4; i++) {
 
			_current_player = p->share_owners[i];
 
			if (_current_player != PLAYER_SPECTATOR) {
 
				/* Sell the shares */
 
				int32 res = DoCommand(0, old_player, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
 
				/* Because we are in a DoCommand, we can't just execute an other one and
 
				 *  expect the money to be removed. We need to do it ourself! */
 
				SubtractMoneyFromPlayer(res);
 
			}
 
		}
 
	}
 

	
 
	_current_player = old_player;
 

	
 
	/* Temporarily increase the player's money, to be sure that
 
@@ -346,25 +379,6 @@ void ChangeOwnershipOfPlayerItems(Player
 
	/* Change color of existing windows */
 
	if (new_player != PLAYER_SPECTATOR) ChangeWindowOwner(old_player, new_player);
 

	
 
	{
 
		Player *p;
 
		uint i;
 

	
 
		/* Check for shares */
 
		FOR_ALL_PLAYERS(p) {
 
			for (i = 0; i < 4; i++) {
 
				/* 'Sell' the share if this player has any */
 
				if (p->share_owners[i] == _current_player) {
 
					p->share_owners[i] = PLAYER_SPECTATOR;
 
				}
 
			}
 
		}
 
		p = GetPlayer(_current_player);
 
		/* Sell all the shares that people have on this company */
 
		for (i = 0; i < 4; i++)
 
			p->share_owners[i] = PLAYER_SPECTATOR;
 
	}
 

	
 
	_current_player = old;
 

	
 
	MarkWholeScreenDirty();
0 comments (0 inline, 0 general)