Changeset - r26748:90d55b3e0b5c
[Not reviewed]
master
0 1 0
Tyler Trahan - 17 months ago 2023-01-14 13:20:19
tyler@tylertrahan.com
Fix: Various Wide River issues (#10348)
1 file changed with 16 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/landscape.cpp
Show inline comments
 
@@ -1084,25 +1084,25 @@ static bool MakeLake(TileIndex tile, voi
 
 */
 
static bool RiverMakeWider(TileIndex tile, void *data)
 
{
 
	/* Don't expand into void tiles. */
 
	if (!IsValidTile(tile)) return false;
 

	
 
	/* If the tile is already sea or river, don't expand. */
 
	if (IsWaterTile(tile)) return false;
 

	
 
	/* If the tile is at height 0 after terraforming but the ocean hasn't flooded yet, don't build river. */
 
	if (GetTileMaxZ(tile) == 0) return false;
 

	
 
	TileIndex origin_tile = *(TileIndex *)data;;
 
	TileIndex origin_tile = *(TileIndex *)data;
 
	Slope cur_slope = GetTileSlope(tile);
 
	Slope desired_slope = GetTileSlope(origin_tile); // Initialize matching the origin tile as a shortcut if no terraforming is needed.
 

	
 
	/* Never flow uphill. */
 
	if (GetTileMaxZ(tile) > GetTileMaxZ(origin_tile)) return false;
 

	
 
	/* If the new tile can't hold a river tile, try terraforming. */
 
	if (!IsTileFlat(tile) && !IsInclinedSlope(cur_slope)) {
 
		/* Don't try to terraform steep slopes. */
 
		if (IsSteepSlope(cur_slope)) return false;
 

	
 
		bool flat_river_found = false;
 
@@ -1122,25 +1122,25 @@ static bool RiverMakeWider(TileIndex til
 
			if (IsWaterTile(other_tile) && IsRiver(other_tile)) {
 
				/* If the adjacent river tile flows downhill, we need to check where we are relative to the slope. */
 
				if (IsInclinedSlope(other_slope) && GetTileMaxZ(tile) == GetTileMaxZ(other_tile)) {
 
					/* Check for a parallel slope. If we don't find one, we're above or below the slope instead. */
 
					if (GetInclinedSlopeDirection(other_slope) == ChangeDiagDir(d, DIAGDIRDIFF_90RIGHT) ||
 
							GetInclinedSlopeDirection(other_slope) == ChangeDiagDir(d, DIAGDIRDIFF_90LEFT)) {
 
						desired_slope = other_slope;
 
						sloped_river_found = true;
 
						break;
 
					}
 
				}
 
				/* If we find an adjacent river tile, remember it. We'll terraform to match it later if we don't find a slope. */
 
				if (IsTileFlat(tile)) flat_river_found = true;
 
				if (IsTileFlat(other_tile)) flat_river_found = true;
 
			}
 
		}
 
		/* We didn't find either an inclined or flat river, so we're climbing the wrong slope. Bail out. */
 
		if (!sloped_river_found && !flat_river_found) return false;
 

	
 
		/* We didn't find an inclined river, but there is a flat river. */
 
		if (!sloped_river_found && flat_river_found) desired_slope = SLOPE_FLAT;
 

	
 
		/* Now that we know the desired slope, it's time to terraform! */
 

	
 
		/* If the river is flat and the adjacent tile has one corner lowered, we want to raise it. */
 
		if (desired_slope == SLOPE_FLAT && IsSlopeWithThreeCornersRaised(cur_slope)) {
 
@@ -1194,42 +1194,52 @@ static bool RiverMakeWider(TileIndex til
 
		/* Don't look outside the map. */
 
		if (!IsValidTile(upstream_tile) || !IsValidTile(downstream_tile)) return false;
 

	
 
		/* Downstream might be new ocean created by our terraforming, and it hasn't flooded yet. */
 
		bool downstream_is_ocean = GetTileZ(downstream_tile) == 0 && (GetTileSlope(downstream_tile) == SLOPE_FLAT || IsSlopeWithOneCornerRaised(GetTileSlope(downstream_tile)));
 

	
 
		/* If downstream is dry, flat, and not ocean, try making it a river tile. */
 
		if (!IsWaterTile(downstream_tile) && !downstream_is_ocean) {
 
			/* If the tile upstream isn't flat, don't bother. */
 
			if (GetTileSlope(downstream_tile) != SLOPE_FLAT) return false;
 

	
 
			MakeRiver(downstream_tile, Random());
 
			MarkTileDirtyByTile(downstream_tile);
 

	
 
			/* Remove desert directly around the river tile. */
 
			TileIndex cur_tile = downstream_tile;
 
			CircularTileSearch(&cur_tile, RIVER_OFFSET_DESERT_DISTANCE, RiverModifyDesertZone, nullptr);
 
		}
 

	
 
		/* If upstream is dry and flat, try making it a river tile. */
 
		if (!IsWaterTile(upstream_tile)) {
 
			/* If the tile upstream isn't flat, don't bother. */
 
			if (GetTileSlope(upstream_tile) != SLOPE_FLAT) return false;
 

	
 
			MakeRiver(upstream_tile, Random());
 
			MarkTileDirtyByTile(upstream_tile);
 

	
 
			/* Remove desert directly around the river tile. */
 
			TileIndex cur_tile = upstream_tile;
 
			CircularTileSearch(&cur_tile, RIVER_OFFSET_DESERT_DISTANCE, RiverModifyDesertZone, nullptr);
 
		}
 
	}
 

	
 
	/* If the tile slope matches the desired slope, add a river tile. */
 
	if (cur_slope == desired_slope) {
 
		MakeRiver(tile, Random());
 
		MarkTileDirtyByTile(tile);
 

	
 
		/* Remove desert directly around the river tile. */
 
		TileIndex cur_tile = tile;
 
		MarkTileDirtyByTile(cur_tile);
 
		CircularTileSearch(&cur_tile, RIVER_OFFSET_DESERT_DISTANCE, RiverModifyDesertZone, nullptr);
 
	}
 

	
 
	/* Always return false to keep searching. */
 
	return false;
 
}
 

	
 
/**
 
 * Check whether a river at begin could (logically) flow down to end.
 
 * @param begin The origin of the flow.
 
 * @param end The destination of the flow.
 
 * @return True iff the water can be flowing down.
 
@@ -1485,24 +1495,27 @@ static void CreateRivers()
 
	}
 

	
 
	/* Try to create short rivers. */
 
	for (; wells != 0; wells--) {
 
		IncreaseGeneratingWorldProgress(GWP_RIVER);
 
		for (int tries = 0; tries < 128; tries++) {
 
			TileIndex t = RandomTile();
 
			if (!CircularTileSearch(&t, 8, FindSpring, nullptr)) continue;
 
			if (std::get<0>(FlowRiver(t, t, _settings_game.game_creation.min_river_length))) break;
 
		}
 
	}
 

	
 
	/* Widening rivers may have left some tiles requiring to be watered. */
 
	ConvertGroundTilesIntoWaterTiles();
 

	
 
	/* Run tile loop to update the ground density. */
 
	for (uint i = 0; i != 256; i++) {
 
		if (i % 64 == 0) IncreaseGeneratingWorldProgress(GWP_RIVER);
 
		RunTileLoop();
 
	}
 
}
 

	
 
/**
 
 * Calculate what height would be needed to cover N% of the landmass.
 
 *
 
 * The function allows both snow and desert/tropic line to be calculated. It
 
 * tries to find the closests height which covers N% of the landmass; it can
0 comments (0 inline, 0 general)