From 87544eff0c7191a261a0d3a13a77d734ad8f1490 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 6 May 2025 20:36:42 +0100 Subject: [PATCH] Codechange: Use DiagDirections to collect rail fence data. --- src/rail_cmd.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 4ccbcea55a..35ed96ade6 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -2664,7 +2664,7 @@ static void TileLoop_Track(TileIndex tile) TrackBits rail = GetTrackBits(tile); Owner owner = GetTileOwner(tile); - uint8_t fences = 0; + DiagDirections fences{}; for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) { static const TrackBits dir_to_trackbits[DIAGDIR_END] = {TRACK_BIT_3WAY_NE, TRACK_BIT_3WAY_SE, TRACK_BIT_3WAY_SW, TRACK_BIT_3WAY_NW}; @@ -2677,22 +2677,22 @@ static void TileLoop_Track(TileIndex tile) /* Show fences if it's a house, industry, object, road, tunnelbridge or not owned by us. */ if (!IsValidTile(tile2) || IsTileType(tile2, MP_HOUSE) || IsTileType(tile2, MP_INDUSTRY) || IsTileType(tile2, MP_ROAD) || (IsTileType(tile2, MP_OBJECT) && !IsObjectType(tile2, OBJECT_OWNED_LAND)) || IsTileType(tile2, MP_TUNNELBRIDGE) || !IsTileOwner(tile2, owner)) { - fences |= 1 << d; + fences.Set(d); } } - switch (fences) { - case 0: break; - case (1 << DIAGDIR_NE): new_ground = RAIL_GROUND_FENCE_NE; break; - case (1 << DIAGDIR_SE): new_ground = RAIL_GROUND_FENCE_SE; break; - case (1 << DIAGDIR_SW): new_ground = RAIL_GROUND_FENCE_SW; break; - case (1 << DIAGDIR_NW): new_ground = RAIL_GROUND_FENCE_NW; break; - case (1 << DIAGDIR_NE) | (1 << DIAGDIR_SW): new_ground = RAIL_GROUND_FENCE_NESW; break; - case (1 << DIAGDIR_SE) | (1 << DIAGDIR_NW): new_ground = RAIL_GROUND_FENCE_SENW; break; - case (1 << DIAGDIR_NE) | (1 << DIAGDIR_SE): new_ground = RAIL_GROUND_FENCE_VERT1; break; - case (1 << DIAGDIR_NE) | (1 << DIAGDIR_NW): new_ground = RAIL_GROUND_FENCE_HORIZ2; break; - case (1 << DIAGDIR_SE) | (1 << DIAGDIR_SW): new_ground = RAIL_GROUND_FENCE_HORIZ1; break; - case (1 << DIAGDIR_SW) | (1 << DIAGDIR_NW): new_ground = RAIL_GROUND_FENCE_VERT2; break; + switch (fences.base()) { + case DiagDirections{}.base(): break; + case DiagDirections{DIAGDIR_NE}.base(): new_ground = RAIL_GROUND_FENCE_NE; break; + case DiagDirections{DIAGDIR_SE}.base(): new_ground = RAIL_GROUND_FENCE_SE; break; + case DiagDirections{DIAGDIR_SW}.base(): new_ground = RAIL_GROUND_FENCE_SW; break; + case DiagDirections{DIAGDIR_NW}.base(): new_ground = RAIL_GROUND_FENCE_NW; break; + case DiagDirections{DIAGDIR_NE, DIAGDIR_SW}.base(): new_ground = RAIL_GROUND_FENCE_NESW; break; + case DiagDirections{DIAGDIR_SE, DIAGDIR_NW}.base(): new_ground = RAIL_GROUND_FENCE_SENW; break; + case DiagDirections{DIAGDIR_NE, DIAGDIR_SE}.base(): new_ground = RAIL_GROUND_FENCE_VERT1; break; + case DiagDirections{DIAGDIR_NE, DIAGDIR_NW}.base(): new_ground = RAIL_GROUND_FENCE_HORIZ2; break; + case DiagDirections{DIAGDIR_SE, DIAGDIR_SW}.base(): new_ground = RAIL_GROUND_FENCE_HORIZ1; break; + case DiagDirections{DIAGDIR_SW, DIAGDIR_NW}.base(): new_ground = RAIL_GROUND_FENCE_VERT2; break; default: NOT_REACHED(); } }