Loading

Revision differences

Old revision #ppvuydn55New revision #pxqgmohaf
2===================================================================  2===================================================================  
3--- src/landscape.cpp    (revision 27795)  3--- src/landscape.cpp    (revision 27795)  
4+++ src/landscape.cpp    (working copy)  4+++ src/landscape.cpp    (working copy)  
5@@ -1008,7 +1008,7 @@  5@@ -992,6 +992,32 @@
   6 }
   7 
   8 /**
   9+ * Check whether a river could (logically) flow into a lock.
   10+ * @param tile the middle tile of a lock.
   11+ * @return true iff the water can be flowing into a lock.
   12+ */
   13+static bool FlowsLock(TileIndex tile)
   14+{
   15+    DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile));
   16+    if (dir == INVALID_DIAGDIR) return false;
   17+
   18+    int delta = TileOffsByDiagDir(dir);
   19+
   20+    int height_tile;
   21+    if (DistanceFromEdge(tile - delta) <= 1 || !(GetTileSlope(tile - 2 * delta, &height_tile) == SLOPE_FLAT) && height_tile != 0 ||
   22+            DistanceFromEdge(tile - 2 * delta) <= 1 || !(GetTileSlope(tile - 2 * delta + TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT)), &height_tile) == SLOPE_FLAT) && height_tile != 0 ||
   23+            !(GetTileSlope(tile - 2 * delta + TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT)), &height_tile) == SLOPE_FLAT) && height_tile != 0 ||
   24+            DistanceFromEdge(tile - 2 * delta + TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT))) <= 1 || !(GetTileSlope(tile - 3 * delta + TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT)), &height_tile) == SLOPE_FLAT) && height_tile != 0 ||
   25+            !(GetTileSlope(tile - 3 * delta + TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT)), &height_tile) == SLOPE_FLAT) && height_tile != 0) return false;
   26+
   27+    if (DistanceFromEdge(tile + delta) <= 1 || !IsTileFlat(tile + delta + delta) ||
   28+            DistanceFromEdge(tile + delta + delta) <= 1 || !IsTileFlat(tile + delta + delta + TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT))) ||
   29+            !IsTileFlat(tile + delta + delta + TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT)))) return false;
   30+
   31+    return true;
   32+}
   33+
   34+/**
   35  * Check whether a river at begin could (logically) flow down to end.
   36  * @param begin The origin of the flow.
   37  * @param end The destination of the flow.
   38@@ -1008,9 +1034,9 @@
6   39   
7     return heightEnd <= heightBegin &&  40     return heightEnd <= heightBegin &&  
8             /* Slope either is inclined or flat; rivers don't support other slopes. */  41             /* Slope either is inclined or flat; rivers don't support other slopes. */  
9-            (slopeEnd == SLOPE_FLAT || IsInclinedSlope(slopeEnd)) &&  42-            (slopeEnd == SLOPE_FLAT || IsInclinedSlope(slopeEnd)) &&  
10+            (slopeEnd == SLOPE_FLAT || (IsInclinedSlope(slopeEnd) && DoCommand(end, 0, 0, CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_LOCK)), CMD_BUILD_LOCK).Succeeded())) &&  10+            (slopeEnd == SLOPE_FLAT || (IsInclinedSlope(slopeEnd) && FlowsLock(end))) &&
11             /* Slope continues, then it must be lower... or either end must be flat. */  44             /* Slope continues, then it must be lower... or either end must be flat. */  
12             ((slopeEnd == slopeBegin && heightEnd < heightBegin) || slopeEnd == SLOPE_FLAT || slopeBegin == SLOPE_FLAT);  45-            ((slopeEnd == slopeBegin && heightEnd < heightBegin) || slopeEnd == SLOPE_FLAT || slopeBegin == SLOPE_FLAT);
   46+            ((slopeEnd == slopeBegin && heightEnd < heightBegin) || slopeEnd == SLOPE_FLAT || (slopeBegin == SLOPE_FLAT && GetTileMaxZ(end) == heightBegin));
13 }  47 }  
14Index: src/water_cmd.cpp  48 
15===================================================================  49 /* AyStar callback for checking whether we reached our destination. */
16--- src/water_cmd.cpp    (revision 27795)  50@@ -1056,6 +1082,32 @@
17+++ src/water_cmd.cpp    (working copy)  51             MakeRiver(tile, Random());
18@@ -272,6 +272,8 @@  52             /* Remove desert directly around the river tile. */
19     if (!IsTileFlat(tile - delta)) {  53             CircularTileSearch(&tile, 5, RiverModifyDesertZone, NULL);
20         return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);  54+
   55+            /* Connect the water if a lock would be build on the inclined slope */
   56+            Slope slope = GetTileSlope(path->node.tile);
   57+            if (IsInclinedSlope(slope)) {
   58+                DiagDirection dir = GetInclinedSlopeDirection(slope);
   59+                int delta_mid = TileOffsByDiagDir(dir);
   60+                int delta     = TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT));
   61+                TileIndex tile_upper = path->node.tile + 2 * delta_mid;
   62+                TileIndex tile_upper_right = tile_upper + delta;
   63+                TileIndex tile_upper_right_far = tile_upper_right + delta_mid;
   64+                TileIndex tile_upper_left = tile_upper - delta;
   65+                TileIndex tile_upper_left_far = tile_upper_left + delta_mid;
   66+                TileIndex tile_lower = path->node.tile - 2 * delta_mid;
   67+                TileIndex tile_lower_right = tile_lower + delta;
   68+                TileIndex tile_lower_right_far = tile_lower_right - delta_mid;
   69+                TileIndex tile_lower_left = tile_lower - delta;
   70+                TileIndex tile_lower_left_far = tile_lower_left - delta_mid;
   71+                TileIndex tiles[] = {tile_upper, tile_upper_right, tile_upper_right_far, tile_upper_left, tile_upper_left_far, tile_lower, tile_lower_right, tile_lower_right_far, tile_lower_left, tile_lower_left_far};
   72+                for (int i = 0; i < lengthof(tiles); i++) {
   73+                    if (!IsWaterTile(tiles[i]) && IsTileFlat(tiles[i])) {
   74+                        MakeRiver(tiles[i], Random());
   75+                        /* Remove desert directly around the river tile. */
   76+                        CircularTileSearch(&tiles[i], 5, RiverModifyDesertZone, NULL);
   77+                    }
   78+                }
   79+            }
   80         }
21     }  81     }  
22+  22 }
23+    if (DistanceFromEdge(tile - delta) <= 1 || !IsTileFlat(tile - delta - delta)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);    
24     WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL;    
25     
26     /* upper tile */    
27@@ -284,6 +286,8 @@    
28     if (!IsTileFlat(tile + delta)) {    
29         return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);    
30     }    
31+    
32+    if (DistanceFromEdge(tile + delta) <= 1 || !IsTileFlat(tile + delta + delta)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);    
33     WaterClass wc_upper = IsWaterTile(tile + delta) ? GetWaterClass(tile + delta) : WATER_CLASS_CANAL;    
34     
35     if (IsBridgeAbove(tile) || IsBridgeAbove(tile - delta) || IsBridgeAbove(tile + delta)) {