summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--economy.c42
-rw-r--r--openttd.c12
-rw-r--r--players.c1
3 files changed, 30 insertions, 25 deletions
diff --git a/economy.c b/economy.c
index 7eb6a7da5..9794adb29 100644
--- a/economy.c
+++ b/economy.c
@@ -244,6 +244,12 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
PlayerID old = _current_player;
_current_player = old_player;
+ /* Temporarily increase the player's money, to be sure that
+ * removing his/her property doesn't fail because of lack of money */
+ if (new_player == OWNER_SPECTATOR) {
+ GetPlayer(old_player)->money64 = ((uint64)-1)>>1; // jackpot ;p
+ }
+
if (new_player == OWNER_SPECTATOR) {
Subsidy *s;
@@ -255,25 +261,24 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
}
/* Take care of rating in towns */
- { Town *t;
- if (new_player != OWNER_SPECTATOR) {
- FOR_ALL_TOWNS(t) {
- /* If a player takes over, give the ratings to that player. */
- if (IsValidTown(t) && HASBIT(t->have_ratings, old_player)) {
- if (HASBIT(t->have_ratings, new_player)) {
- // use max of the two ratings.
- t->ratings[new_player] = max(t->ratings[new_player], t->ratings[old_player]);
- } else {
- SETBIT(t->have_ratings, new_player);
- t->ratings[new_player] = t->ratings[old_player];
- }
+ if (new_player != OWNER_SPECTATOR) {
+ Town *t;
+ FOR_ALL_TOWNS(t) {
+ /* If a player takes over, give the ratings to that player. */
+ if (IsValidTown(t) && HASBIT(t->have_ratings, old_player)) {
+ if (HASBIT(t->have_ratings, new_player)) {
+ // use max of the two ratings.
+ t->ratings[new_player] = max(t->ratings[new_player], t->ratings[old_player]);
+ } else {
+ SETBIT(t->have_ratings, new_player);
+ t->ratings[new_player] = t->ratings[old_player];
}
+ }
- /* Reset ratings for the town */
- if (IsValidTown(t)) {
- t->ratings[old_player] = 500;
- CLRBIT(t->have_ratings, old_player);
- }
+ /* Reset ratings for the town */
+ if (IsValidTown(t)) {
+ t->ratings[old_player] = 500;
+ CLRBIT(t->have_ratings, old_player);
}
}
}
@@ -435,8 +440,7 @@ static void PlayersCheckBankrupt(Player *p)
}
#endif /* ENABLE_NETWORK */
- // Convert everything the player owns to NO_OWNER
- p->money64 = p->player_money = 100000000;
+ /* Remove the player */
ChangeOwnershipOfPlayerItems(owner, OWNER_SPECTATOR);
// Register the player as not-active
p->is_active = false;
diff --git a/openttd.c b/openttd.c
index a711a29fa..99951ed92 100644
--- a/openttd.c
+++ b/openttd.c
@@ -771,16 +771,18 @@ void SwitchMode(int new_mode)
case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */
if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR)) {
- PlayerID i;
+ Player *p;
_opt_ptr = &_opt;
_local_player = OWNER_NONE;
_generating_world = true;
- // delete all players.
- for (i = 0; i != MAX_PLAYERS; i++) {
- ChangeOwnershipOfPlayerItems(i, OWNER_SPECTATOR);
- _players[i].is_active = false;
+ /* Delete all players */
+ FOR_ALL_PLAYERS(p) {
+ if (p->is_active) {
+ ChangeOwnershipOfPlayerItems(p->index, OWNER_SPECTATOR);
+ p->is_active = false;
+ }
}
_generating_world = false;
// delete all stations owned by a player
diff --git a/players.c b/players.c
index 9bf6f02ed..9276f9119 100644
--- a/players.c
+++ b/players.c
@@ -913,7 +913,6 @@ int32 CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
/* Remove the company */
ChangeOwnershipOfPlayerItems(p->index, OWNER_SPECTATOR);
- p->money64 = p->player_money = 100000000; // XXX - wtf?
p->is_active = false;
}
RemoveAllEngineReplacementForPlayer(p);