summaryrefslogtreecommitdiff
path: root/src/economy.cpp
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2007-03-31 12:19:22 +0000
committertruelight <truelight@openttd.org>2007-03-31 12:19:22 +0000
commit32c3ba66043cbac01ad2687d3d7b025e1db1f048 (patch)
tree27d6ad0591d67176698c0ef1849cc220e09093b6 /src/economy.cpp
parent9c88baee675fd1e7c64f1bfd48a45bf4b7d6c246 (diff)
downloadopenttd-32c3ba66043cbac01ad2687d3d7b025e1db1f048.tar.xz
(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.
Diffstat (limited to 'src/economy.cpp')
-rw-r--r--src/economy.cpp52
1 files changed, 33 insertions, 19 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index aaeced6f7..24eab5466 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();