summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cmd_helper.h9
-rw-r--r--src/rail_cmd.cpp2
-rw-r--r--src/road_cmd.cpp8
-rw-r--r--src/station_cmd.cpp2
-rw-r--r--src/water_cmd.cpp2
5 files changed, 12 insertions, 11 deletions
diff --git a/src/cmd_helper.h b/src/cmd_helper.h
index a034f1217..1530beedb 100644
--- a/src/cmd_helper.h
+++ b/src/cmd_helper.h
@@ -14,12 +14,13 @@
#include "core/enum_type.hpp"
-template<typename T, uint N, typename U> static inline T Extract(U v)
+template<typename T, uint S, uint N, typename U> static inline T Extract(U v)
{
/* Check if there are enough bits in v */
- assert_tcompile(N + EnumPropsT<T>::num_bits <= sizeof(U) * 8);
- assert_tcompile(EnumPropsT<T>::end <= (1 << EnumPropsT<T>::num_bits));
- return (T)GB(v, N, EnumPropsT<T>::num_bits);
+ assert_tcompile(N == EnumPropsT<T>::num_bits);
+ assert_tcompile(S + N <= sizeof(U) * 8);
+ assert_tcompile(EnumPropsT<T>::end <= (1 << N));
+ return (T)GB(v, S, N);
}
#endif
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index e0f85675c..f90be4125 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -837,7 +837,7 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, u
Slope tileh = GetTileSlope(tile, NULL);
- DiagDirection dir = Extract<DiagDirection, 0>(p2);
+ DiagDirection dir = Extract<DiagDirection, 0, 2>(p2);
/* Prohibit construction if
* The tile is non-flat AND
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index c97ac1b0a..8f3832dc6 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -464,7 +464,7 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
p2 = (town != NULL) ? town->index : (TownID)INVALID_TOWN;
}
- RoadBits pieces = Extract<RoadBits, 0>(p1);
+ RoadBits pieces = Extract<RoadBits, 0, 4>(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 start_tile, DoCommandFlag flags, uint32 p
RoadType rt = (RoadType)GB(p2, 3, 2);
if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
- Axis axis = Extract<Axis, 2>(p2);
+ Axis axis = Extract<Axis, 2, 1>(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 start_tile, DoCommandFlag flags, uint32
RoadType rt = (RoadType)GB(p2, 3, 2);
if (!IsValidRoadType(rt)) return CMD_ERROR;
- Axis axis = Extract<Axis, 2>(p2);
+ Axis axis = Extract<Axis, 2, 1>(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 start_tile, DoCommandFlag flags, uint32
*/
CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- DiagDirection dir = Extract<DiagDirection, 0>(p1);
+ DiagDirection dir = Extract<DiagDirection, 0, 2>(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
index a996ff5cd..060b66bf6 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1096,7 +1096,7 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
{
/* Unpack parameters */
RailType rt = (RailType)GB(p1, 0, 4);
- Axis axis = Extract<Axis, 4>(p1);
+ Axis axis = Extract<Axis, 4, 1>(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
index 1216fb213..4b80d0cd4 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -104,7 +104,7 @@ static void MarkCanalsAndRiversAroundDirty(TileIndex tile)
*/
CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- Axis axis = Extract<Axis, 0>(p1);
+ Axis axis = Extract<Axis, 0, 1>(p1);
TileIndex tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));