From fb116653c67bf68251bd983a6dc0d2a5b11aa336 Mon Sep 17 00:00:00 2001 From: truelight Date: Sat, 31 Mar 2007 12:19:22 +0000 Subject: [PATCH] (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. --- src/economy.cpp | 52 +++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/economy.cpp b/src/economy.cpp index aaeced6f79..24eab54661 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -254,6 +254,39 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_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(PlayerID old_player, PlayerID new_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();