summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-02-04 20:17:15 +0000
committertron <tron@openttd.org>2005-02-04 20:17:15 +0000
commit981b6c1ecd91e994c97244de8a8f672b8df7e86c (patch)
tree930523bbbffbbca24de1c5d2bb12ad6428f5930e
parent033c392aca488c068d23f888f80e4c4120c12563 (diff)
downloadopenttd-981b6c1ecd91e994c97244de8a8f672b8df7e86c.tar.xz
(svn r1797) Clean up TileLoopClearHelper() a bit:
- if cascades -> switch - uint -> TileIndex - (uint)-1 -> INVALID_TILE - don't treat non-flags as flags
-rw-r--r--clear_cmd.c80
1 files changed, 55 insertions, 25 deletions
diff --git a/clear_cmd.c b/clear_cmd.c
index 4bac5c304..49889ecae 100644
--- a/clear_cmd.c
+++ b/clear_cmd.c
@@ -545,28 +545,48 @@ static void AnimateTile_Clear(uint tile)
/* unused */
}
-void TileLoopClearHelper(uint tile)
+void TileLoopClearHelper(TileIndex tile)
{
- byte img_1, img_2;
- static byte img_by_map5[8] = { 0,0,0,2, 1,1,0,0, };
- uint dirty = -1;
-
- img_1 = 0;
- if (IsTileType(tile, MP_CLEAR)) {
- img_1 = img_by_map5[(_map5[tile] & 0x1C) >> 2];
- } else if (IsTileType(tile, MP_TREES) && (_map2[tile] & 0x30) == 0x20) {
- img_1 = 1;
+ byte img_1;
+ byte img_2;
+ static byte img_by_map5[] = { 0, 0, 0, 2, 1, 1, 0, 0 };
+ TileIndex dirty = INVALID_TILE;
+
+ switch (GetTileType(tile)) {
+ case MP_CLEAR:
+ img_1 = img_by_map5[(_map5[tile] & 0x1C) >> 2];
+ break;
+
+ case MP_TREES:
+ if ((_map2[tile] & 0x30) == 0x20)
+ img_1 = 1;
+ else
+ img_1 = 0;
+
+ default:
+ img_1 = 0;
+ break;
}
- img_2 = 0;
- if (IsTileType(TILE_ADDXY(tile, 1, 0), MP_CLEAR)) {
- img_2 = img_by_map5[(_map5[TILE_ADDXY(tile, 1, 0)] & 0x1C) >> 2];
- } else if (IsTileType(TILE_ADDXY(tile, 1, 0), MP_TREES) && (_map2[TILE_ADDXY(tile, 1, 0)] & 0x30) == 0x20) {
- img_2 = 1;
+ switch (GetTileType(TILE_ADDXY(tile, 1, 0))) {
+ case MP_CLEAR:
+ img_2 = img_by_map5[(_map5[TILE_ADDXY(tile, 1, 0)] & 0x1C) >> 2];
+ break;
+
+ case MP_TREES:
+ if ((_map2[TILE_ADDXY(tile, 1, 0)] & 0x30) == 0x20)
+ img_2 = 1;
+ else
+ img_2 = 0;
+ break;
+
+ default:
+ img_2 = 0;
+ break;
}
- if (!(_map3_hi[tile] & 0xE0)) {
- if ( (img_1&2) != (img_2&2) ) {
+ if ((_map3_hi[tile] & 0xE0) == 0) {
+ if ((img_1 & 2) != (img_2 & 2)) {
_map3_hi[tile] |= 3 << 5;
dirty = tile;
}
@@ -577,15 +597,25 @@ void TileLoopClearHelper(uint tile)
}
}
- img_2 = 0;
- if (IsTileType(TILE_ADDXY(tile, 0, 1), MP_CLEAR)) {
- img_2 = img_by_map5[(_map5[TILE_ADDXY(tile, 0, 1)] & 0x1C) >> 2];
- } else if (IsTileType(TILE_ADDXY(tile, 0, 1), MP_TREES) && (_map2[TILE_ADDXY(tile, 0, 1)] & 0x30) == 0x20) {
- img_2 = 1;
+ switch (GetTileType(TILE_ADDXY(tile, 0, 1))) {
+ case MP_CLEAR:
+ img_2 = img_by_map5[(_map5[TILE_ADDXY(tile, 1, 0)] & 0x1C) >> 2];
+ break;
+
+ case MP_TREES:
+ if ((_map2[TILE_ADDXY(tile, 0, 1)] & 0x30) == 0x20)
+ img_2 = 1;
+ else
+ img_2 = 0;
+ break;
+
+ default:
+ img_2 = 0;
+ break;
}
- if (!(_map3_hi[tile] & 0x1C)) {
- if ( (img_1&2) != (img_2&2) ) {
+ if ((_map3_hi[tile] & 0x1C) == 0) {
+ if ((img_1 & 2) != (img_2 & 2)) {
_map3_hi[tile] |= 3 << 2;
dirty = tile;
}
@@ -596,7 +626,7 @@ void TileLoopClearHelper(uint tile)
}
}
- if (dirty != (uint) -1)
+ if (dirty != INVALID_TILE)
MarkTileDirtyByTile(dirty);
}