Loading

friendly river gen

  1. Index: src/landscape.cpp
  2. ===================================================================
  3. --- src/landscape.cpp   (revision 27795)
  4. +++ src/landscape.cpp   (working copy)
  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 @@
  39.  
  40.     return heightEnd <= heightBegin &&
  41.             /* Slope either is inclined or flat; rivers don't support other slopes. */
  42. -           (slopeEnd == SLOPE_FLAT || IsInclinedSlope(slopeEnd)) &&
  43. +           (slopeEnd == SLOPE_FLAT || (IsInclinedSlope(slopeEnd) && FlowsLock(end))) &&
  44.             /* Slope continues, then it must be lower... or either end must be 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));
  47.  }
  48.  
  49.  /* AyStar callback for checking whether we reached our destination. */
  50. @@ -1056,6 +1082,45 @@
  51.             MakeRiver(tile, Random());
  52.             /* Remove desert directly around the river tile. */
  53.             CircularTileSearch(&tile, 5, RiverModifyDesertZone, NULL);
  54. +
  55. +//         /* Connect the water if a lock would be build on the inclined slope */
  56. +//         int height_tile;
  57. +//         Slope slope = GetTileSlope(path->node.tile, &height_tile);
  58. +//         if (IsInclinedSlope(slope)) {
  59. +//             DiagDirection dir = GetInclinedSlopeDirection(slope);
  60. +//             int delta_mid = TileOffsByDiagDir(dir);
  61. +//             int delta     = TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT));
  62. +//             TileIndex tile_upper = path->node.tile + 2 * delta_mid;
  63. +//             TileIndex tile_upper_right = tile_upper + delta;
  64. +//             TileIndex tile_upper_right_far = tile_upper_right + delta_mid;
  65. +//             TileIndex tile_upper_left = tile_upper - delta;
  66. +//             TileIndex tile_upper_left_far = tile_upper_left + delta_mid;
  67. +//             TileIndex tile_lower = path->node.tile - 2 * delta_mid;
  68. +//             TileIndex tile_lower_right = tile_lower + delta;
  69. +//             TileIndex tile_lower_right_far = tile_lower_right - delta_mid;
  70. +//             TileIndex tile_lower_left = tile_lower - delta;
  71. +//             TileIndex tile_lower_left_far = tile_lower_left - delta_mid;
  72. +
  73. +//             int height_tile_delta;
  74. +//             TileIndex tiles_lower[] = {tile_lower, tile_lower_right, tile_lower_right_far, tile_lower_left, tile_lower_left_far};
  75. +//             for (int i = 0; i < lengthof(tiles_lower); i++) {
  76. +//                 if (!IsWaterTile(tiles_lower[i]) && (GetTileSlope(tiles_lower[i], &height_tile_delta) == SLOPE_FLAT) && height_tile_delta == height_tile) {
  77. +//                     MakeRiver(tiles_lower[i], Random());
  78. +//                     /* Remove desert directly around the river tile. */
  79. +//                     CircularTileSearch(&tiles_lower[i], 5, RiverModifyDesertZone, NULL);
  80. +//                 }
  81. +//             }
  82. +//
  83. +//             TileIndex tiles_upper[] = {tile_upper, tile_upper_right, tile_upper_right_far, tile_upper_left, tile_upper_left_far};
  84. +//             for (int i = 0; i < lengthof(tiles_upper); i++) {
  85. +//                 if (!IsWaterTile(tiles_upper[i]) && (GetTileSlope(tiles_upper[i], &height_tile_delta) == SLOPE_FLAT) && height_tile_delta == height_tile + 1) {
  86. +//                     MakeRiver(tiles_upper[i], Random());
  87. +//                     /* Remove desert directly around the river tile. */
  88. +//                     CircularTileSearch(&tiles_upper[i], 5, RiverModifyDesertZone, NULL);
  89. +//                 }
  90. +//             }
  91. +//         }
  92. +
  93.         }
  94.     }
  95.  }

Version history

Revision # Author Created at
pxqgmohaf Anonymous 20 Mar 2017, 15:52:10 UTC Diff
ppvuydn55 Anonymous 19 Mar 2017, 12:36:51 UTC Diff

Comments