From 9f5e49eaad356d7166dfd00aff1d6666f053523c Mon Sep 17 00:00:00 2001 From: michi_cc Date: Mon, 2 Aug 2010 18:47:03 +0000 Subject: (svn r20315) -Codechange: Replace magic numbers by named constants. --- src/rail_gui.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index a5c7bc01b..bdfd2fddd 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -110,24 +110,31 @@ static void PlaceRail_AutoRail(TileIndex tile) /** * Try to add an additional rail-track at the entrance of a depot * @param tile Tile to use for adding the rail-track - * @param extra Track to add + * @param dir Direction to check for already present tracks + * @param track Track to add * @see CcRailDepot() */ -static void PlaceExtraDepotRail(TileIndex tile, uint16 extra) +static void PlaceExtraDepotRail(TileIndex tile, DiagDirection dir, Track track) { if (GetRailTileType(tile) != RAIL_TILE_NORMAL) return; - if ((GetTrackBits(tile) & GB(extra, 8, 8)) == 0) return; + if ((GetTrackBits(tile) & DiagdirReachesTracks(dir)) == 0) return; - DoCommandP(tile, _cur_railtype, extra & 0xFF, CMD_BUILD_SINGLE_RAIL); + DoCommandP(tile, _cur_railtype, track, CMD_BUILD_SINGLE_RAIL); } /** Additional pieces of track to add at the entrance of a depot. */ -static const uint16 _place_depot_extra[12] = { - 0x0604, 0x2102, 0x1202, 0x0505, // First additional track for directions 0..3 - 0x2400, 0x2801, 0x1800, 0x1401, // Second additional track - 0x2203, 0x0904, 0x0A05, 0x1103, // Third additional track +static const Track _place_depot_extra_track[12] = { + TRACK_LEFT, TRACK_UPPER, TRACK_UPPER, TRACK_RIGHT, // First additional track for directions 0..3 + TRACK_X, TRACK_Y, TRACK_X, TRACK_Y, // Second additional track + TRACK_LOWER, TRACK_LEFT, TRACK_RIGHT, TRACK_LOWER, // Third additional track }; +/** Direction to check for existing track pieces. */ +static const DiagDirection _place_depot_extra_dir[12] = { + DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE, DIAGDIR_SW, + DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE, DIAGDIR_SE, + DIAGDIR_NW, DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_NE, +}; void CcRailDepot(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2) { @@ -141,9 +148,9 @@ void CcRailDepot(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2 tile += TileOffsByDiagDir(dir); if (IsTileType(tile, MP_RAILWAY)) { - PlaceExtraDepotRail(tile, _place_depot_extra[dir]); - PlaceExtraDepotRail(tile, _place_depot_extra[dir + 4]); - PlaceExtraDepotRail(tile, _place_depot_extra[dir + 8]); + PlaceExtraDepotRail(tile, _place_depot_extra_dir[dir], _place_depot_extra_track[dir]); + PlaceExtraDepotRail(tile, _place_depot_extra_dir[dir + 4], _place_depot_extra_track[dir + 4]); + PlaceExtraDepotRail(tile, _place_depot_extra_dir[dir + 8], _place_depot_extra_track[dir + 8]); } } -- cgit v1.2.3-70-g09d2