(svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
authorfrosch
Tue, 29 Jan 2008 14:17:13 +0000
changeset 8939 9d51d72e7e3d
parent 8938 79bcde6bbe6c
child 8940 968e465c7328
(svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
src/water_cmd.cpp
--- a/src/water_cmd.cpp	Tue Jan 29 14:02:18 2008 +0000
+++ b/src/water_cmd.cpp	Tue Jan 29 14:17:13 2008 +0000
@@ -70,6 +70,30 @@
 };
 
 /**
+ * Marks tile dirty if it is a canal or river tile.
+ * Called to avoid glitches when flooding tiles next to canal tile.
+ *
+ * @param tile tile to check
+ */
+static inline void MarkTileDirtyIfCanalOrRiver(TileIndex tile)
+{
+	if (IsTileType(tile, MP_WATER) && (IsCanal(tile) || IsRiver(tile))) MarkTileDirtyByTile(tile);
+}
+
+/**
+ * Marks the tiles around a tile as dirty, if they are canals or rivers.
+ *
+ * @param tile The center of the tile where all other tiles are marked as dirty
+ * @ingroup dirty
+ */
+static void MarkCanalsAndRiversAroundDirty(TileIndex tile)
+{
+	for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
+		MarkTileDirtyIfCanalOrRiver(tile + TileOffsByDir(dir));
+	}
+}
+
+/**
  * 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.
@@ -231,6 +255,8 @@
 		MarkTileDirtyByTile(tile);
 		MarkTileDirtyByTile(tile - delta);
 		MarkTileDirtyByTile(tile + delta);
+		MarkCanalsAndRiversAroundDirty(tile - delta);
+		MarkCanalsAndRiversAroundDirty(tile + delta);
 	}
 
 	return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 22 >> 3);
@@ -250,28 +276,13 @@
 		DoClearSquare(tile);
 		MakeWaterOrCanalDependingOnSurroundings(tile + delta, _current_player);
 		MakeWaterOrCanalDependingOnSurroundings(tile - delta, _current_player);
+		MarkCanalsAndRiversAroundDirty(tile - delta);
+		MarkCanalsAndRiversAroundDirty(tile + delta);
 	}
 
 	return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 2);
 }
 
-/**
- * Marks the tiles around a tile as dirty.
- *
- * This functions marks the tiles around a given tile as dirty for repaint.
- *
- * @param tile The center of the tile where all other tiles are marked as dirty
- * @ingroup dirty
- * @see TerraformAddDirtyTileAround
- */
-static void MarkTilesAroundDirty(TileIndex tile)
-{
-	MarkTileDirtyByTile(TILE_ADDXY(tile, 0, 1));
-	MarkTileDirtyByTile(TILE_ADDXY(tile, 0, -1));
-	MarkTileDirtyByTile(TILE_ADDXY(tile, 1, 0));
-	MarkTileDirtyByTile(TILE_ADDXY(tile, -1, 0));
-}
-
 /** Builds a lock (ship-lift)
  * @param tile tile where to place the lock
  * @param flags type of operation
@@ -345,7 +356,7 @@
 				MakeCanal(tile, _current_player, Random());
 			}
 			MarkTileDirtyByTile(tile);
-			MarkTilesAroundDirty(tile);
+			MarkCanalsAndRiversAroundDirty(tile);
 		}
 
 		cost.AddCost(_price.clear_water);
@@ -376,7 +387,10 @@
 
 			if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE && !CheckTileOwnership(tile)) return CMD_ERROR;
 
-			if (flags & DC_EXEC) DoClearSquare(tile);
+			if (flags & DC_EXEC) {
+				DoClearSquare(tile);
+				MarkCanalsAndRiversAroundDirty(tile);
+			}
 			return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water);
 
 		case WATER_TILE_COAST: {
@@ -385,7 +399,10 @@
 			/* Make sure no vehicle is on the tile */
 			if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
-			if (flags & DC_EXEC) DoClearSquare(tile);
+			if (flags & DC_EXEC) {
+				DoClearSquare(tile);
+				MarkCanalsAndRiversAroundDirty(tile);
+			}
 			if (IsSlopeWithOneCornerRaised(slope)) {
 				return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water);
 			} else {
@@ -678,17 +695,6 @@
 	/* not used */
 }
 
-/**
- * Marks tile dirty if it is a canal tile.
- * Called to avoid glitches when flooding tiles next to canal tile.
- *
- * @param tile tile to check
- */
-static inline void MarkTileDirtyIfCanal(TileIndex tile)
-{
-	if (IsTileType(tile, MP_WATER) && IsCanal(tile)) MarkTileDirtyByTile(tile);
-}
-
 
 /**
  * Finds a vehicle to flood.
@@ -904,9 +910,7 @@
 
 	if (flooded) {
 		/* Mark surrounding canal tiles dirty too to avoid glitches */
-		for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
-			MarkTileDirtyIfCanal(target + TileOffsByDir(dir));
-		}
+		MarkCanalsAndRiversAroundDirty(target);
 
 		/* update signals if needed */
 		UpdateSignalsInBuffer();