diff --git a/src/cmd_helper.h b/src/cmd_helper.h --- a/src/cmd_helper.h +++ b/src/cmd_helper.h @@ -14,12 +14,13 @@ #include "core/enum_type.hpp" -template static inline T Extract(U v) +template static inline T Extract(U v) { /* Check if there are enough bits in v */ - assert_tcompile(N + EnumPropsT::num_bits <= sizeof(U) * 8); - assert_tcompile(EnumPropsT::end <= (1 << EnumPropsT::num_bits)); - return (T)GB(v, N, EnumPropsT::num_bits); + assert_tcompile(N == EnumPropsT::num_bits); + assert_tcompile(S + N <= sizeof(U) * 8); + assert_tcompile(EnumPropsT::end <= (1 << N)); + return (T)GB(v, S, N); } #endif diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -837,7 +837,7 @@ CommandCost CmdBuildTrainDepot(TileIndex Slope tileh = GetTileSlope(tile, NULL); - DiagDirection dir = Extract(p2); + DiagDirection dir = Extract(p2); /* Prohibit construction if * The tile is non-flat AND diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -464,7 +464,7 @@ CommandCost CmdBuildRoad(TileIndex tile, p2 = (town != NULL) ? town->index : (TownID)INVALID_TOWN; } - RoadBits pieces = Extract(p1); + RoadBits pieces = Extract(p1); /* do not allow building 'zero' road bits, code wouldn't handle it */ if (pieces == ROAD_NONE) return CMD_ERROR; @@ -729,7 +729,7 @@ CommandCost CmdBuildLongRoad(TileIndex s RoadType rt = (RoadType)GB(p2, 3, 2); if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR; - Axis axis = Extract(p2); + Axis axis = Extract(p2); /* Only drag in X or Y direction dictated by the direction variable */ if (axis == AXIS_X && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis if (axis == AXIS_Y && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis @@ -821,7 +821,7 @@ CommandCost CmdRemoveLongRoad(TileIndex RoadType rt = (RoadType)GB(p2, 3, 2); if (!IsValidRoadType(rt)) return CMD_ERROR; - Axis axis = Extract(p2); + Axis axis = Extract(p2); /* Only drag in X or Y direction dictated by the direction variable */ if (axis == AXIS_X && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis if (axis == AXIS_Y && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis @@ -886,7 +886,7 @@ CommandCost CmdRemoveLongRoad(TileIndex */ CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - DiagDirection dir = Extract(p1); + DiagDirection dir = Extract(p1); RoadType rt = (RoadType)GB(p1, 2, 2); if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR; diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1096,7 +1096,7 @@ CommandCost CmdBuildRailStation(TileInde { /* Unpack parameters */ RailType rt = (RailType)GB(p1, 0, 4); - Axis axis = Extract(p1); + Axis axis = Extract(p1); byte numtracks = GB(p1, 8, 8); byte plat_len = GB(p1, 16, 8); bool adjacent = HasBit(p1, 24); diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -104,7 +104,7 @@ static void MarkCanalsAndRiversAroundDir */ CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - Axis axis = Extract(p1); + Axis axis = Extract(p1); TileIndex tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));