/* AyStar callback when an route has been found. */
static void River_FoundEndNode(AyStar *aystar, OpenListNode *current)
{
for (PathNode *path = ¤t->path; path != NULL; path = path->parent) {
TileIndex tile = path->node.tile;
TileIndex t = tile;
if (!IsWaterTile(tile)) {
MakeRiver(tile, Random());
/* Remove desert directly around the river tile. */
CircularTileSearch(&t, 5, RiverModifyDesertZone, NULL);
}
Slope slope = GetTileSlope(tile);
DiagDirection dir = GetInclinedSlopeDirection(slope);
if (IsInclinedSlope(slope)) {
int delta = TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT));
if (IsValidTile(tile + delta) && !IsWaterTile(tile + delta) && GetTileSlope(tile + delta) == slope) {
MakeRiver(tile + delta, Random());
t = path->node.tile + delta;
/* Remove desert directly around the river tile. */
CircularTileSearch(&t, 5, RiverModifyDesertZone, NULL);
}
if (IsValidTile(tile - delta) && !IsWaterTile(tile - delta) && GetTileSlope(tile - delta) == slope) {
MakeRiver(tile - delta, Random());
t = path->node.tile + delta;
/* Remove desert directly around the river tile. */
CircularTileSearch(&t, 5, RiverModifyDesertZone, NULL);
}
int delta_mid = TileOffsByDiagDir(dir);
TileIndex tile_upper = path->node.tile + 2 * delta_mid;
TileIndex tile_upper_right = tile_upper + delta;
TileIndex tile_upper_left = tile_upper - delta;
TileIndex tile_lower = path->node.tile - 2 * delta_mid;
TileIndex tile_lower_right = tile_lower + delta;
TileIndex tile_lower_left = tile_lower - delta;
TileIndex tiles[] = { tile_upper, tile_upper_right, tile_upper_left, tile_lower, tile_lower_right, tile_lower_left, };
for (int i = 0; i < lengthof(tiles); i++) {
if (!IsWaterTile(tiles[i]) && IsTileFlat(tiles[i])) {
MakeRiver(tiles[i], Random());
/* Remove desert directly around the river tile. */
CircularTileSearch(&tiles[i], 5, RiverModifyDesertZone, NULL);
}
}
}
for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
t = path->node.tile + TileOffsByDiagDir(d);
if (IsValidTile(t) && !IsWaterTile(t) && IsTileFlat(t)) {
MakeRiver(t, Random());
/* Remove desert directly around the river tile. */
CircularTileSearch(&t, 5, RiverModifyDesertZone, NULL);
}
}
}
}