summaryrefslogtreecommitdiff
path: root/src/clear_cmd.cpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2009-12-30 19:30:49 +0000
committeralberth <alberth@openttd.org>2009-12-30 19:30:49 +0000
commitd86dbabbc44a637f31c065771400d1ed4a3c6f5c (patch)
tree9a76115e862d90beb2a398a2d34c9fb8716d8297 /src/clear_cmd.cpp
parent84a7f6aa5bf2658a6bfce9342ea1466f7ba5cebc (diff)
downloadopenttd-d86dbabbc44a637f31c065771400d1ed4a3c6f5c.tar.xz
(svn r18670) -Fix [FS#3455]: Update all tiles when snowline height changes in larger steps than one tile.
Diffstat (limited to 'src/clear_cmd.cpp')
-rw-r--r--src/clear_cmd.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/clear_cmd.cpp b/src/clear_cmd.cpp
index 32f4a7f75..43f820d6b 100644
--- a/src/clear_cmd.cpp
+++ b/src/clear_cmd.cpp
@@ -156,30 +156,34 @@ void TileLoopClearHelper(TileIndex tile)
}
-/* convert into snowy tiles */
+/** Convert to or from snowy tiles. */
static void TileLoopClearAlps(TileIndex tile)
{
int k = GetTileZ(tile) - GetSnowLine() + TILE_HEIGHT;
- if (k < 0) { // well below the snow line
+ if (k < 0) {
+ /* Below the snow line, do nothing if no snow. */
if (!IsClearGround(tile, CLEAR_SNOW)) return;
- if (GetClearDensity(tile) == 0) SetClearGroundDensity(tile, CLEAR_GRASS, 3);
} else {
+ /* At or above the snow line, make snow tile if needed. */
if (!IsClearGround(tile, CLEAR_SNOW)) {
SetClearGroundDensity(tile, CLEAR_SNOW, 0);
- } else {
- uint density = min((uint)k / TILE_HEIGHT, 3);
-
- if (GetClearDensity(tile) < density) {
- AddClearDensity(tile, 1);
- } else if (GetClearDensity(tile) > density) {
- AddClearDensity(tile, -1);
- } else {
- return;
- }
+ MarkTileDirtyByTile(tile);
+ return;
}
}
-
+ /* Update snow density. */
+ uint curent_density = GetClearDensity(tile);
+ uint req_density = (k < 0) ? 0u : min((uint)k / TILE_HEIGHT, 3);
+
+ if (curent_density < req_density) {
+ AddClearDensity(tile, 1);
+ } else if (curent_density > req_density) {
+ AddClearDensity(tile, -1);
+ } else {
+ /* Density at the required level. */
+ if (k < 0) SetClearGroundDensity(tile, CLEAR_GRASS, 3);
+ }
MarkTileDirtyByTile(tile);
}