mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: refactor removal of desert around river tiles
This commit is contained in:
parent
20a9e13272
commit
96ec9908a0
|
@ -1064,11 +1064,7 @@ static bool MakeLake(TileIndex tile, void *user_data)
|
||||||
for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
|
for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
|
||||||
TileIndex t2 = tile + TileOffsByDiagDir(d);
|
TileIndex t2 = tile + TileOffsByDiagDir(d);
|
||||||
if (IsWaterTile(t2)) {
|
if (IsWaterTile(t2)) {
|
||||||
MakeRiver(tile, Random());
|
MakeRiverAndModifyDesertZoneAround(tile);
|
||||||
MarkTileDirtyByTile(tile);
|
|
||||||
/* Remove desert directly around the river tile. */
|
|
||||||
TileIndex t = tile;
|
|
||||||
CircularTileSearch(&t, RIVER_OFFSET_DESERT_DISTANCE, RiverModifyDesertZone, nullptr);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1202,12 +1198,7 @@ static bool RiverMakeWider(TileIndex tile, void *data)
|
||||||
/* If the tile upstream isn't flat, don't bother. */
|
/* If the tile upstream isn't flat, don't bother. */
|
||||||
if (GetTileSlope(downstream_tile) != SLOPE_FLAT) return false;
|
if (GetTileSlope(downstream_tile) != SLOPE_FLAT) return false;
|
||||||
|
|
||||||
MakeRiver(downstream_tile, Random());
|
MakeRiverAndModifyDesertZoneAround(downstream_tile);
|
||||||
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 upstream is dry and flat, try making it a river tile. */
|
||||||
|
@ -1215,23 +1206,13 @@ static bool RiverMakeWider(TileIndex tile, void *data)
|
||||||
/* If the tile upstream isn't flat, don't bother. */
|
/* If the tile upstream isn't flat, don't bother. */
|
||||||
if (GetTileSlope(upstream_tile) != SLOPE_FLAT) return false;
|
if (GetTileSlope(upstream_tile) != SLOPE_FLAT) return false;
|
||||||
|
|
||||||
MakeRiver(upstream_tile, Random());
|
MakeRiverAndModifyDesertZoneAround(upstream_tile);
|
||||||
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 the tile slope matches the desired slope, add a river tile. */
|
||||||
if (cur_slope == desired_slope) {
|
if (cur_slope == desired_slope) {
|
||||||
MakeRiver(tile, Random());
|
MakeRiverAndModifyDesertZoneAround(tile);
|
||||||
MarkTileDirtyByTile(tile);
|
|
||||||
|
|
||||||
/* Remove desert directly around the river tile. */
|
|
||||||
TileIndex cur_tile = tile;
|
|
||||||
CircularTileSearch(&cur_tile, RIVER_OFFSET_DESERT_DISTANCE, RiverModifyDesertZone, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Always return false to keep searching. */
|
/* Always return false to keep searching. */
|
||||||
|
@ -1310,10 +1291,7 @@ static void River_FoundEndNode(AyStar *aystar, OpenListNode *current)
|
||||||
for (PathNode *path = ¤t->path; path != nullptr; path = path->parent, cur_pos++) {
|
for (PathNode *path = ¤t->path; path != nullptr; path = path->parent, cur_pos++) {
|
||||||
TileIndex tile = path->node.tile;
|
TileIndex tile = path->node.tile;
|
||||||
if (!IsWaterTile(tile)) {
|
if (!IsWaterTile(tile)) {
|
||||||
MakeRiver(tile, Random());
|
MakeRiverAndModifyDesertZoneAround(tile);
|
||||||
MarkTileDirtyByTile(tile);
|
|
||||||
/* Remove desert directly around the river tile. */
|
|
||||||
CircularTileSearch(&tile, RIVER_OFFSET_DESERT_DISTANCE, RiverModifyDesertZone, nullptr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1453,11 +1431,7 @@ static std::tuple<bool, bool> FlowRiver(TileIndex spring, TileIndex begin, uint
|
||||||
/* We only want a lake if the river is long enough. */
|
/* We only want a lake if the river is long enough. */
|
||||||
DistanceManhattan(spring, lakeCenter) > min_river_length) {
|
DistanceManhattan(spring, lakeCenter) > min_river_length) {
|
||||||
end = lakeCenter;
|
end = lakeCenter;
|
||||||
MakeRiver(lakeCenter, Random());
|
MakeRiverAndModifyDesertZoneAround(lakeCenter);
|
||||||
MarkTileDirtyByTile(lakeCenter);
|
|
||||||
/* Remove desert directly around the river tile. */
|
|
||||||
CircularTileSearch(&lakeCenter, RIVER_OFFSET_DESERT_DISTANCE, RiverModifyDesertZone, nullptr);
|
|
||||||
lakeCenter = end;
|
|
||||||
uint range = RandomRange(8) + 3;
|
uint range = RandomRange(8) + 3;
|
||||||
CircularTileSearch(&lakeCenter, range, MakeLake, &height);
|
CircularTileSearch(&lakeCenter, range, MakeLake, &height);
|
||||||
/* Call the search a second time so artefacts from going circular in one direction get (mostly) hidden. */
|
/* Call the search a second time so artefacts from going circular in one direction get (mostly) hidden. */
|
||||||
|
|
|
@ -39,6 +39,7 @@ void MakeWaterKeepingClass(TileIndex tile, Owner o);
|
||||||
void CheckForDockingTile(TileIndex t);
|
void CheckForDockingTile(TileIndex t);
|
||||||
|
|
||||||
bool RiverModifyDesertZone(TileIndex tile, void *data);
|
bool RiverModifyDesertZone(TileIndex tile, void *data);
|
||||||
|
void MakeRiverAndModifyDesertZoneAround(TileIndex tile);
|
||||||
static const uint RIVER_OFFSET_DESERT_DISTANCE = 5; ///< Circular tile search radius to create non-desert around a river tile.
|
static const uint RIVER_OFFSET_DESERT_DISTANCE = 5; ///< Circular tile search radius to create non-desert around a river tile.
|
||||||
|
|
||||||
bool IsWateredTile(TileIndex tile, Direction from);
|
bool IsWateredTile(TileIndex tile, Direction from);
|
||||||
|
|
|
@ -427,6 +427,18 @@ bool RiverModifyDesertZone(TileIndex tile, void *)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a river tile and remove desert directly around it.
|
||||||
|
* @param tile The tile to change into river and create non-desert around
|
||||||
|
*/
|
||||||
|
void MakeRiverAndModifyDesertZoneAround(TileIndex tile) {
|
||||||
|
MakeRiver(tile, Random());
|
||||||
|
MarkTileDirtyByTile(tile);
|
||||||
|
|
||||||
|
/* Remove desert directly around the river tile. */
|
||||||
|
CircularTileSearch(&tile, RIVER_OFFSET_DESERT_DISTANCE, RiverModifyDesertZone, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a piece of canal.
|
* Build a piece of canal.
|
||||||
* @param flags type of operation
|
* @param flags type of operation
|
||||||
|
|
Loading…
Reference in New Issue