summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2011-12-29 20:10:06 +0000
committermichi_cc <michi_cc@openttd.org>2011-12-29 20:10:06 +0000
commit24d530b55dd98bd933aad8b66384594cf1bfb84b (patch)
treef72b7faae74ee308c77be5601c19e8917370749d
parent35b76bc8a9b761f8f584f725396d543a91b9dbd1 (diff)
downloadopenttd-24d530b55dd98bd933aad8b66384594cf1bfb84b.tar.xz
(svn r23686) -Fix [FS#4921] (r23413): Infrastructure count of canals/locks/ship depots wasn't updated properly when a company went into bankruptcy or was taken over.
-rw-r--r--src/water_cmd.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index 19d43de03..cab880926 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -1259,9 +1259,20 @@ static void ChangeTileOwner_Water(TileIndex tile, Owner old_owner, Owner new_own
if (!IsTileOwner(tile, old_owner)) return;
/* No need to dirty company windows here, we'll redraw the whole screen anyway. */
- if (IsCanal(tile)) Company::Get(old_owner)->infrastructure.water--;
+ if (IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE) Company::Get(old_owner)->infrastructure.water -= 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts.
if (new_owner != INVALID_OWNER) {
- if (IsCanal(tile)) Company::Get(new_owner)->infrastructure.water++;
+ if (IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE) Company::Get(new_owner)->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock has three parts.
+ /* Only subtract from the old owner here if the new owner is valid,
+ * otherwise we clear ship depots and canal water below. */
+ if (GetWaterClass(tile) == WATER_CLASS_CANAL) {
+ Company::Get(old_owner)->infrastructure.water--;
+ Company::Get(new_owner)->infrastructure.water++;
+ }
+ if (IsShipDepot(tile)) {
+ Company::Get(old_owner)->infrastructure.water -= LOCK_DEPOT_TILE_FACTOR;
+ Company::Get(new_owner)->infrastructure.water += LOCK_DEPOT_TILE_FACTOR;
+ }
+
SetTileOwner(tile, new_owner);
return;
}
@@ -1272,7 +1283,7 @@ static void ChangeTileOwner_Water(TileIndex tile, Owner old_owner, Owner new_own
/* Set owner of canals and locks ... and also canal under dock there was before.
* Check if the new owner after removing depot isn't OWNER_WATER. */
if (IsTileOwner(tile, old_owner)) {
- if (IsCanal(tile)) Company::Get(old_owner)->infrastructure.water--;
+ if (GetWaterClass(tile) == WATER_CLASS_CANAL) Company::Get(old_owner)->infrastructure.water--;
SetTileOwner(tile, OWNER_NONE);
}
}