summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-02-22 19:52:13 +0000
committerrubidium <rubidium@openttd.org>2014-02-22 19:52:13 +0000
commit98539bd2c3c9805683f67a275c61972730a7c789 (patch)
treea8c45bcbcaf5ae2cc342c5c0be6e2ca35d782d53
parent90fef59f8010882e99cdf27e52af6e9695edfabb (diff)
downloadopenttd-98539bd2c3c9805683f67a275c61972730a7c789.tar.xz
(svn r26363) -Codechange [FS#5894]: make it clearer that drive through road stops need an Axis in CmdBuildRoadStop and the non drive through stops need a DiagDir
-rw-r--r--src/station_cmd.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index c253679d9..341681124 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1757,7 +1757,8 @@ static CommandCost FindJoiningRoadStop(StationID existing_stop, StationID statio
* bit 1: 0 For normal stops, 1 for drive-through.
* bit 2..3: The roadtypes.
* bit 5: Allow stations directly adjacent to other stations.
- * bit 6..7: Entrance direction (#DiagDirection).
+ * bit 6..7: Entrance direction (#DiagDirection) for normal stops.
+ * bit 6: #Axis of the road for drive-through stops.
* bit 16..31: Station ID to join (NEW_STATION if build new one).
* @param text Unused.
* @return The cost of this operation or an error.
@@ -1791,12 +1792,17 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
/* Trams only have drive through stops */
if (!is_drive_through && HasBit(rts, ROADTYPE_TRAM)) return CMD_ERROR;
- DiagDirection ddir = Extract<DiagDirection, 6, 2>(p2);
-
- /* Safeguard the parameters. */
- if (!IsValidDiagDirection(ddir)) return CMD_ERROR;
- /* If it is a drive-through stop, check for valid axis. */
- if (is_drive_through && !IsValidAxis((Axis)ddir)) return CMD_ERROR;
+ DiagDirection ddir;
+ Axis axis;
+ if (is_drive_through) {
+ /* By definition axis is valid, due to there being 2 axes and reading 1 bit. */
+ axis = Extract<Axis, 6, 1>(p2);
+ ddir = AxisToDiagDir(axis);
+ } else {
+ /* By definition ddir is valid, due to there being 4 diagonal directions and reading 2 bits. */
+ ddir = Extract<DiagDirection, 6, 2>(p2);
+ axis = DiagDirToAxis(ddir);
+ }
CommandCost ret = CheckIfAuthorityAllowsNewStation(tile, flags);
if (ret.Failed()) return ret;
@@ -1804,7 +1810,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
/* Total road stop cost. */
CommandCost cost(EXPENSES_CONSTRUCTION, roadstop_area.w * roadstop_area.h * _price[type ? PR_BUILD_STATION_TRUCK : PR_BUILD_STATION_BUS]);
StationID est = INVALID_STATION;
- ret = CheckFlatLandRoadStop(roadstop_area, flags, is_drive_through ? 5 << ddir : 1 << ddir, is_drive_through, type, DiagDirToAxis(ddir), &est, rts);
+ ret = CheckFlatLandRoadStop(roadstop_area, flags, is_drive_through ? 5 << axis : 1 << ddir, is_drive_through, type, axis, &est, rts);
if (ret.Failed()) return ret;
cost.AddCost(ret);
@@ -1858,7 +1864,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
}
}
- MakeDriveThroughRoadStop(cur_tile, st->owner, road_owner, tram_owner, st->index, rs_type, rts | cur_rts, DiagDirToAxis(ddir));
+ MakeDriveThroughRoadStop(cur_tile, st->owner, road_owner, tram_owner, st->index, rs_type, rts | cur_rts, axis);
road_stop->MakeDriveThrough();
} else {
/* Non-drive-through stop never overbuild and always count as two road bits. */