summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/road_cmd.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index a2fde8984..0dd465871 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -725,9 +725,10 @@ CommandCost CmdBuildLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1,
RoadType rt = (RoadType)GB(p2, 3, 2);
if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
+ Axis axis = Extract<Axis, 2>(p2);
/* Only drag in X or Y direction dictated by the direction variable */
- if (!HasBit(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
- if (HasBit(p2, 2) && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
+ 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
/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */
if (start_tile > end_tile || (start_tile == end_tile && HasBit(p2, 0))) {
@@ -741,14 +742,14 @@ CommandCost CmdBuildLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1,
/* On the X-axis, we have to swap the initial bits, so they
* will be interpreted correctly in the GTTS. Futhermore
* when you just 'click' on one tile to build them. */
- if (HasBit(p2, 2) == (start_tile == end_tile && HasBit(p2, 0) == HasBit(p2, 1))) drd ^= DRD_BOTH;
+ if ((axis == AXIS_Y) == (start_tile == end_tile && HasBit(p2, 0) == HasBit(p2, 1))) drd ^= DRD_BOTH;
/* No disallowed direction bits have to be toggled */
if (!HasBit(p2, 5)) drd = DRD_NONE;
TileIndex tile = start_tile;
/* Start tile is the small number. */
for (;;) {
- RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
+ RoadBits bits = AxisToRoadBits(axis);
if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE;
if (tile == start_tile && HasBit(p2, 0)) bits &= ROAD_SE | ROAD_SW;
@@ -779,7 +780,7 @@ CommandCost CmdBuildLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1,
if (tile == end_tile) break;
- tile += HasBit(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
+ tile += (axis == AXIS_Y) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
}
return !had_success ? CMD_ERROR : cost;
@@ -807,9 +808,10 @@ CommandCost CmdRemoveLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1
RoadType rt = (RoadType)GB(p2, 3, 2);
if (!IsValidRoadType(rt)) return CMD_ERROR;
+ Axis axis = Extract<Axis, 2>(p2);
/* Only drag in X or Y direction dictated by the direction variable */
- if (!HasBit(p2, 2) && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis
- if (HasBit(p2, 2) && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis
+ 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
/* Swap start and ending tile, also the half-tile drag var (bit 0 and 1) */
if (start_tile > end_tile || (start_tile == end_tile && HasBit(p2, 0))) {
@@ -823,7 +825,7 @@ CommandCost CmdRemoveLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1
TileIndex tile = start_tile;
/* Start tile is the small number. */
for (;;) {
- RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
+ RoadBits bits = AxisToRoadBits(axis);
if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE;
if (tile == start_tile && HasBit(p2, 0)) bits &= ROAD_SE | ROAD_SW;
@@ -846,7 +848,7 @@ CommandCost CmdRemoveLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1
if (tile == end_tile) break;
- tile += HasBit(p2, 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
+ tile += (axis == AXIS_Y) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
}
return (cost.GetCost() == 0) ? CMD_ERROR : cost;