summaryrefslogtreecommitdiff
path: root/src/water_cmd.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-11-24 08:45:04 +0000
committerrubidium <rubidium@openttd.org>2007-11-24 08:45:04 +0000
commitea072322fa099509b5e8aeb1d9c8be9f857dd972 (patch)
treecf761cfea846d41d39350cafe88182e83c852d93 /src/water_cmd.cpp
parentc8add525041eaf50020a12ce13fd63d86b6d26b8 (diff)
downloadopenttd-ea072322fa099509b5e8aeb1d9c8be9f857dd972.tar.xz
(svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
Diffstat (limited to 'src/water_cmd.cpp')
-rw-r--r--src/water_cmd.cpp40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index f91682449..92b33a837 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -55,6 +55,42 @@ static const SpriteID _water_shore_sprites[] = {
static Vehicle *FindFloodableVehicleOnTile(TileIndex tile);
static void FloodVehicle(Vehicle *v);
+/**
+ * Makes a tile canal or water depending on the surroundings.
+ * This as for example docks and shipdepots do not store
+ * whether the tile used to be canal or 'normal' water.
+ * @param t the tile to change.
+ * @param o the owner of the new tile.
+ */
+void MakeWaterOrCanalDependingOnSurroundings(TileIndex t, Owner o)
+{
+ assert(GetTileSlope(t, NULL) == SLOPE_FLAT);
+
+ /* Non-sealevel -> canal */
+ if (TileHeight(t) != 0) {
+ MakeCanal(t, o);
+ return;
+ }
+
+ bool has_water = false;
+ bool has_canal = false;
+
+ for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
+ TileIndex neighbour = TileAddByDiagDir(t, dir);
+ if (IsTileType(neighbour, MP_WATER)) {
+ has_water |= IsSea(neighbour) || IsCoast(neighbour);
+ has_canal |= IsCanal(neighbour);
+ }
+ }
+ if (has_canal || !has_water) {
+ MakeCanal(t, o);
+ } else {
+ MakeWater(t);
+ }
+ MarkTileDirtyByTile(t);
+}
+
+
/** Build a ship depot.
* @param tile tile where ship depot is built
* @param flags type of operation
@@ -178,8 +214,8 @@ static CommandCost RemoveShiplift(TileIndex tile, uint32 flags)
if (flags & DC_EXEC) {
DoClearSquare(tile);
- DoClearSquare(tile + delta);
- DoClearSquare(tile - delta);
+ MakeWaterOrCanalDependingOnSurroundings(tile + delta, _current_player);
+ MakeWaterOrCanalDependingOnSurroundings(tile - delta, _current_player);
}
return CommandCost(_price.clear_water * 2);