summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-04-26 14:20:39 +0000
committersmatz <smatz@openttd.org>2008-04-26 14:20:39 +0000
commit9e1b8b69e32e3ea7fd3ec60f7cbb07f034a4beb3 (patch)
tree552e5b87688c9123491223f82f196003cd3a9d05 /src
parent805e1db332d3a746a7ce453f62b83d4442078a0b (diff)
downloadopenttd-9e1b8b69e32e3ea7fd3ec60f7cbb07f034a4beb3.tar.xz
(svn r12906) -Fix: vehicle groups, engine replacement rules and player/company names were not properly reset/freed after bankrupt (before new player start)
Diffstat (limited to 'src')
-rw-r--r--src/economy.cpp14
-rw-r--r--src/players.cpp5
2 files changed, 16 insertions, 3 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index 380a000ba..2c7369b4e 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -44,6 +44,7 @@
#include "rail_map.h"
#include "signal_func.h"
#include "gfx_func.h"
+#include "autoreplace_func.h"
#include "table/strings.h"
#include "table/sprites.h"
@@ -454,6 +455,19 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
UpdateSignalsInBuffer();
}
+ /* In all cases clear replace engine rules.
+ * Even if it was copied, it could interfere with new owner's rules */
+ RemoveAllEngineReplacementForPlayer(GetPlayer(old_player));
+
+ if (new_player == PLAYER_SPECTATOR) {
+ RemoveAllGroupsForPlayer(old_player);
+ } else {
+ Group *g;
+ FOR_ALL_GROUPS(g) {
+ if (g->owner == old_player) g->owner = new_player;
+ }
+ }
+
/* Change color of existing windows */
if (new_player != PLAYER_SPECTATOR) ChangeWindowOwner(old_player, new_player);
diff --git a/src/players.cpp b/src/players.cpp
index 8fafc2bb8..fc90dc2fb 100644
--- a/src/players.cpp
+++ b/src/players.cpp
@@ -461,6 +461,8 @@ static Player *AllocatePlayer()
/* Find a free slot */
FOR_ALL_PLAYERS(p) {
if (!p->is_active) {
+ free(p->name);
+ free(p->president_name);
PlayerID i = p->index;
memset(p, 0, sizeof(Player));
memset(&_players_ai[i], 0, sizeof(PlayerAI));
@@ -918,9 +920,6 @@ CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
p->is_active = false;
}
- RemoveAllEngineReplacementForPlayer(p);
- RemoveAllGroupsForPlayer(p->index);
-
} break;
case 3: { /* Merge a company (#1) into another company (#2), elimination company #1 */