(svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
authorfrosch
Thu, 17 Jan 2008 17:13:47 +0000
changeset 8332 7226194fb681
parent 8331 5514b3a1d52c
child 8333 b01316b861c2
(svn r11898) -Fix: Update neighboured canals + signals when flooding non-flat tiles, too.
src/rail_cmd.cpp
src/water.h
src/water_cmd.cpp
--- a/src/rail_cmd.cpp	Thu Jan 17 16:55:13 2008 +0000
+++ b/src/rail_cmd.cpp	Thu Jan 17 17:13:47 2008 +0000
@@ -528,10 +528,12 @@
  * The function floods the lower halftile, if the tile has a halftile foundation.
  *
  * @param t The tile to flood.
+ * @return true if something was flooded.
  */
-void FloodHalftile(TileIndex t)
+bool FloodHalftile(TileIndex t)
 {
-	if (GetRailGroundType(t) == RAIL_GROUND_WATER) return;
+	bool flooded = false;
+	if (GetRailGroundType(t) == RAIL_GROUND_WATER) return flooded;
 
 	Slope tileh = GetTileSlope(t, NULL);
 	TrackBits rail_bits = GetTrackBits(t);
@@ -542,20 +544,23 @@
 		TrackBits to_remove = lower_track & rail_bits;
 		if (to_remove != 0) {
 			_current_player = OWNER_WATER;
-			if (CmdFailed(DoCommand(t, 0, FIND_FIRST_BIT(to_remove), DC_EXEC, CMD_REMOVE_SINGLE_RAIL))) return; // not yet floodable
+			if (CmdFailed(DoCommand(t, 0, FIND_FIRST_BIT(to_remove), DC_EXEC, CMD_REMOVE_SINGLE_RAIL))) return flooded; // not yet floodable
+			flooded = true;
 			rail_bits = rail_bits & ~to_remove;
 			if (rail_bits == 0) {
 				MakeShore(t);
 				MarkTileDirtyByTile(t);
-				return;
+				return flooded;
 			}
 		}
 
 		if (IsNonContinuousFoundation(GetRailFoundation(tileh, rail_bits))) {
+			flooded = true;
 			SetRailGroundType(t, RAIL_GROUND_WATER);
 			MarkTileDirtyByTile(t);
 		}
 	}
+	return flooded;
 }
 
 static const TileIndexDiffC _trackdelta[] = {
--- a/src/water.h	Thu Jan 17 16:55:13 2008 +0000
+++ b/src/water.h	Thu Jan 17 17:13:47 2008 +0000
@@ -10,6 +10,6 @@
 void DrawCanalWater(TileIndex tile);
 void MakeWaterOrCanalDependingOnOwner(TileIndex tile, Owner o);
 void MakeWaterOrCanalDependingOnSurroundings(TileIndex t, Owner o);
-void FloodHalftile(TileIndex t);
+bool FloodHalftile(TileIndex t);
 
 #endif /* WATER_H */
--- a/src/water_cmd.cpp	Thu Jan 17 16:55:13 2008 +0000
+++ b/src/water_cmd.cpp	Thu Jan 17 17:13:47 2008 +0000
@@ -605,6 +605,8 @@
 		return;
 	}
 
+	bool flooded = false; // Will be set to true, when something is flooded
+
 	/* Is any corner of the dest tile raised? (First two corners already checked above. */
 	if (TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[3]))) != 0 ||
 			TileHeight(TILE_ADD(tile, ToTileIndexDiff(offs[4]))) != 0) {
@@ -613,7 +615,7 @@
 			case MP_RAILWAY: {
 				if (!IsPlainRailTile(target)) break;
 
-				FloodHalftile(target);
+				flooded = FloodHalftile(target);
 
 				Vehicle *v = FindFloodableVehicleOnTile(target);
 				if (v != NULL) FloodVehicle(v);
@@ -625,6 +627,7 @@
 			case MP_TREES:
 				_current_player = OWNER_WATER;
 				if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
+					flooded = true;
 					MakeShore(target);
 					MarkTileDirtyByTile(target);
 				}
@@ -642,14 +645,17 @@
 
 		/* flood flat tile */
 		if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
+			flooded = true;
 			MakeWater(target);
 			MarkTileDirtyByTile(target);
-			/* Mark surrounding canal tiles dirty too to avoid glitches */
-			for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
-				MarkTileDirtyIfCanal(target + TileOffsByDir(dir));
-			}
 		}
+	}
 
+	if (flooded) {
+		/* Mark surrounding canal tiles dirty too to avoid glitches */
+		for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
+			MarkTileDirtyIfCanal(target + TileOffsByDir(dir));
+		}
 		/* update signals if needed */
 		UpdateSignalsInBuffer();
 	}