diff options
author | tron <tron@openttd.org> | 2006-02-06 09:18:04 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2006-02-06 09:18:04 +0000 |
commit | 453b30e387f8d8ab1839d96b0d1f9a8fea841292 (patch) | |
tree | 3a4002304d8204d11c37ba706d6ffbd2e5dfac1b /water_cmd.c | |
parent | 0755bbead0240f519c9d78bb88ef4629d5ab8fa5 (diff) | |
download | openttd-453b30e387f8d8ab1839d96b0d1f9a8fea841292.tar.xz |
(svn r3564) Several smaller changes:
- Don't treat non-booleans as booleans
- Reduce variable scope
- Bracing
- Use DeMorgan's law to make conditionals easier to read
- if cascade -> switch
- Replace some magic numbers by symbolic names
- Avoid assignments within other statements
Diffstat (limited to 'water_cmd.c')
-rw-r--r-- | water_cmd.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/water_cmd.c b/water_cmd.c index 8825714f2..2187f917d 100644 --- a/water_cmd.c +++ b/water_cmd.c @@ -375,20 +375,28 @@ void DrawCanalWater(TileIndex tile) if (!(wa & 8)) DrawGroundSprite(SPR_CANALS_BASE + 60); // right corner - if ((wa & 3) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 4); - else if ((wa & 3) == 3 && !IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 8); + switch (wa & 0x03) { + case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 4); break; + case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 8); break; + } // bottom corner - if ((wa & 6) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 5); - else if ((wa & 6) == 6 && !IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 9); + switch (wa & 0x06) { + case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 5); break; + case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 9); break; + } // left corner - if ((wa & 12) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 6); - else if ((wa & 12) == 12 && !IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 10); + switch (wa & 0x0C) { + case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 6); break; + case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 10); break; + } // upper corner - if ((wa & 9) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 7); - else if ((wa & 9) == 9 && !IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 11); + switch (wa & 0x09) { + case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 7); break; + case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 11); break; + } } typedef struct LocksDrawTileStruct { @@ -403,12 +411,10 @@ static void DrawWaterStuff(const TileInfo *ti, const WaterDrawTileStruct *wdts, uint32 palette, uint base ) { - uint32 image; - DrawGroundSprite(wdts++->image); for (; wdts->delta_x != 0x80; wdts++) { - image = wdts->image + base; + uint32 image = wdts->image + base; if (_display_opt & DO_TRANS_BUILDINGS) { MAKE_TRANSPARENT(image); } else { @@ -624,7 +630,6 @@ static void FloodVehicle(Vehicle *v) // called from tunnelbridge_cmd void TileLoop_Water(TileIndex tile) { - int i; static const TileIndexDiffC _tile_loop_offs_array[][5] = { // tile to mod shore? shore? {{-1, 0}, {0, 0}, {0, 1}, {-1, 0}, {-1, 1}}, @@ -635,6 +640,8 @@ void TileLoop_Water(TileIndex tile) if (IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1) && IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) { + uint i; + for (i = 0; i != lengthof(_tile_loop_offs_array); i++) { TileLoopWaterHelper(tile, _tile_loop_offs_array[i]); } |