Mercurial > hg > openttd
changeset 8443:d4898778e081 draft
(svn r12013) -Fix: When modifying watered tiles, mark neighboured canals and rivers dirty in more cases.
author | frosch <frosch@openttd.org> |
---|---|
date | Tue, 29 Jan 2008 14:17:13 +0000 |
parents | 1a90922472a6 |
children | 370882fad6c6 |
files | src/water_cmd.cpp |
diffstat | 1 files changed, 38 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -70,6 +70,30 @@ }; /** + * Marks tile dirty if it is a canal or river tile. + * Called to avoid glitches when flooding tiles next to canal tile. + * + * @param tile tile to check + */ +static inline void MarkTileDirtyIfCanalOrRiver(TileIndex tile) +{ + if (IsTileType(tile, MP_WATER) && (IsCanal(tile) || IsRiver(tile))) MarkTileDirtyByTile(tile); +} + +/** + * Marks the tiles around a tile as dirty, if they are canals or rivers. + * + * @param tile The center of the tile where all other tiles are marked as dirty + * @ingroup dirty + */ +static void MarkCanalsAndRiversAroundDirty(TileIndex tile) +{ + for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) { + MarkTileDirtyIfCanalOrRiver(tile + TileOffsByDir(dir)); + } +} + +/** * Makes a tile canal or water depending on the surroundings. * This as for example docks and shipdepots do not store * whether the tile used to be canal or 'normal' water. @@ -231,6 +255,8 @@ MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile - delta); MarkTileDirtyByTile(tile + delta); + MarkCanalsAndRiversAroundDirty(tile - delta); + MarkCanalsAndRiversAroundDirty(tile + delta); } return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 22 >> 3); @@ -250,28 +276,13 @@ DoClearSquare(tile); MakeWaterOrCanalDependingOnSurroundings(tile + delta, _current_player); MakeWaterOrCanalDependingOnSurroundings(tile - delta, _current_player); + MarkCanalsAndRiversAroundDirty(tile - delta); + MarkCanalsAndRiversAroundDirty(tile + delta); } return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water * 2); } -/** - * Marks the tiles around a tile as dirty. - * - * This functions marks the tiles around a given tile as dirty for repaint. - * - * @param tile The center of the tile where all other tiles are marked as dirty - * @ingroup dirty - * @see TerraformAddDirtyTileAround - */ -static void MarkTilesAroundDirty(TileIndex tile) -{ - MarkTileDirtyByTile(TILE_ADDXY(tile, 0, 1)); - MarkTileDirtyByTile(TILE_ADDXY(tile, 0, -1)); - MarkTileDirtyByTile(TILE_ADDXY(tile, 1, 0)); - MarkTileDirtyByTile(TILE_ADDXY(tile, -1, 0)); -} - /** Builds a lock (ship-lift) * @param tile tile where to place the lock * @param flags type of operation @@ -345,7 +356,7 @@ MakeCanal(tile, _current_player, Random()); } MarkTileDirtyByTile(tile); - MarkTilesAroundDirty(tile); + MarkCanalsAndRiversAroundDirty(tile); } cost.AddCost(_price.clear_water); @@ -376,7 +387,10 @@ if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE && !CheckTileOwnership(tile)) return CMD_ERROR; - if (flags & DC_EXEC) DoClearSquare(tile); + if (flags & DC_EXEC) { + DoClearSquare(tile); + MarkCanalsAndRiversAroundDirty(tile); + } return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water); case WATER_TILE_COAST: { @@ -385,7 +399,10 @@ /* Make sure no vehicle is on the tile */ if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; - if (flags & DC_EXEC) DoClearSquare(tile); + if (flags & DC_EXEC) { + DoClearSquare(tile); + MarkCanalsAndRiversAroundDirty(tile); + } if (IsSlopeWithOneCornerRaised(slope)) { return CommandCost(EXPENSES_CONSTRUCTION, _price.clear_water); } else { @@ -678,17 +695,6 @@ /* not used */ } -/** - * Marks tile dirty if it is a canal tile. - * Called to avoid glitches when flooding tiles next to canal tile. - * - * @param tile tile to check - */ -static inline void MarkTileDirtyIfCanal(TileIndex tile) -{ - if (IsTileType(tile, MP_WATER) && IsCanal(tile)) MarkTileDirtyByTile(tile); -} - /** * Finds a vehicle to flood. @@ -904,9 +910,7 @@ if (flooded) { /* Mark surrounding canal tiles dirty too to avoid glitches */ - for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) { - MarkTileDirtyIfCanal(target + TileOffsByDir(dir)); - } + MarkCanalsAndRiversAroundDirty(target); /* update signals if needed */ UpdateSignalsInBuffer();