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,32 @@
  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. +           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.         }
  81.     }
  82.  }

Version history

Revision # Author Created at
ppvuydn55 Anonymous 19 Mar 2017, 12:36:51 UTC Diff

Comments