Loading

Paste #p3ywofais

  1. /* AyStar callback when an route has been found. */
  2. static void River_FoundEndNode(AyStar *aystar, OpenListNode *current)
  3. {
  4.     for (PathNode *path = &current->path; path != NULL; path = path->parent) {
  5.         TileIndex tile = path->node.tile;
  6.         TileIndex t = tile;
  7.         if (!IsWaterTile(tile)) {
  8.             MakeRiver(tile, Random());
  9.             /* Remove desert directly around the river tile. */
  10.             CircularTileSearch(&t, 5, RiverModifyDesertZone, NULL);
  11.         }
  12.  
  13.         Slope slope = GetTileSlope(tile);
  14.         DiagDirection dir = GetInclinedSlopeDirection(slope);
  15.         if (IsInclinedSlope(slope)) {
  16.             int delta = TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT));
  17.             if (IsValidTile(tile + delta) && !IsWaterTile(tile + delta) && GetTileSlope(tile + delta) == slope) {
  18.                 MakeRiver(tile + delta, Random());
  19.                 t = path->node.tile + delta;
  20.                 /* Remove desert directly around the river tile. */
  21.                 CircularTileSearch(&t, 5, RiverModifyDesertZone, NULL);
  22.             }
  23.             if (IsValidTile(tile - delta) && !IsWaterTile(tile - delta) && GetTileSlope(tile - delta) == slope) {
  24.                 MakeRiver(tile - delta, Random());
  25.                 t = path->node.tile + delta;
  26.                 /* Remove desert directly around the river tile. */
  27.                 CircularTileSearch(&t, 5, RiverModifyDesertZone, NULL);
  28.             }
  29.  
  30.             int delta_mid = TileOffsByDiagDir(dir);
  31.             TileIndex tile_upper = path->node.tile + 2 * delta_mid;
  32.             TileIndex tile_upper_right = tile_upper + delta;
  33.             TileIndex tile_upper_left = tile_upper - delta;
  34.             TileIndex tile_lower = path->node.tile - 2 * delta_mid;
  35.             TileIndex tile_lower_right = tile_lower + delta;
  36.             TileIndex tile_lower_left = tile_lower - delta;
  37.             TileIndex tiles[] = { tile_upper, tile_upper_right, tile_upper_left, tile_lower, tile_lower_right, tile_lower_left, };
  38.             for (int i = 0; i < lengthof(tiles); i++) {
  39.                 if (!IsWaterTile(tiles[i]) && IsTileFlat(tiles[i])) {
  40.                     MakeRiver(tiles[i], Random());
  41.                     /* Remove desert directly around the river tile. */
  42.                     CircularTileSearch(&tiles[i], 5, RiverModifyDesertZone, NULL);
  43.                 }
  44.             }
  45.         }
  46.  
  47.         for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
  48.             t = path->node.tile + TileOffsByDiagDir(d);
  49.             if (IsValidTile(t) && !IsWaterTile(t) && IsTileFlat(t)) {
  50.                 MakeRiver(t, Random());
  51.                 /* Remove desert directly around the river tile. */
  52.                 CircularTileSearch(&t, 5, RiverModifyDesertZone, NULL);
  53.             }
  54.         }
  55.     }
  56. }

Comments