diff --git a/docs/script-additions.html b/docs/script-additions.html
index f22079d3e5..da2271b413 100644
--- a/docs/script-additions.html
+++ b/docs/script-additions.html
@@ -104,6 +104,14 @@
static bool IsTownBuildableRoadType(RoadType roadtype)
Checks whether the given road type is buildable by towns.
+
+
static RoadPieces GetRoadPieces(TileIndex tile, RoadTramTypes road_tram_type)
+
Get the RoadPieces that are on a tile.
+
+
+
static OneWayInfo GetOneWayInfo(TileIndex tile)
+
Get info about the one-way state of a tile.
+
diff --git a/src/script/api/script_road.cpp b/src/script/api/script_road.cpp
index 4077a4ca5e..1417cfb35f 100644
--- a/src/script/api/script_road.cpp
+++ b/src/script/api/script_road.cpp
@@ -96,6 +96,7 @@
{
if (!ScriptMap::IsValidTile(tile)) return false;
if (!IsRoadTypeAvailable(road_type)) return false;
+
return ::MayHaveRoad(tile) && HasBit(::GetPresentRoadTypes(tile), (::RoadType)road_type);
}
@@ -103,16 +104,41 @@
{
if (!ScriptMap::IsValidTile(tile)) return false;
if (road_tram_type != ROADTRAMTYPES_ROAD && road_tram_type != ROADTRAMTYPES_TRAM) return false;
- return ::GetAnyRoadBits(tile, (::RoadTramType)road_tram_type, false) != ROAD_NONE;
+
+ return ::GetAnyRoadBits(tile, (::RoadTramType)(road_tram_type >> 1), false) != ROAD_NONE;
+}
+
+/* static */ ScriptRoad::RoadPieces ScriptRoad::GetRoadPieces(TileIndex tile, RoadTramTypes road_tram_type)
+{
+ if (!ScriptMap::IsValidTile(tile)) return ROADPIECES_NONE;
+ if (road_tram_type != ROADTRAMTYPES_ROAD && road_tram_type != ROADTRAMTYPES_TRAM) return ROADPIECES_NONE;
+
+ return (ScriptRoad::RoadPieces)::GetAnyRoadBits(tile, (::RoadTramType)(road_tram_type >> 1), false);
+}
+
+/* static */ ScriptRoad::OneWayInfo ScriptRoad::GetOneWayInfo(TileIndex tile)
+{
+ if (!ScriptMap::IsValidTile(tile)) return ONEWAY_NONE;
+
+ DisallowedRoadDirections drd = DRD_NONE;
+ if (IsNormalRoadTile(tile)) drd = GetDisallowedRoadDirections(tile);
+ if (IsDriveThroughStopTile(tile)) drd = GetDriveThroughStopDisallowedRoadDirections(tile);
+ if (drd == DRD_NONE) return ONEWAY_NONE;
+
+ RoadBits rb = ::GetAnyRoadBits(tile, RTT_ROAD, false);
+ if (rb == ROAD_Y) return drd == DRD_NORTHBOUND ? ONEWAY_SOUTHEAST : ONEWAY_NORTHWEST;
+ if (rb == ROAD_X) return drd == DRD_NORTHBOUND ? ONEWAY_NORTHEAST : ONEWAY_SOUTHWEST;
+
+ return ONEWAY_NONE;
}
/* static */ ScriptRoad::RoadType ScriptRoad::GetRoadType(TileIndex tile, RoadTramTypes road_tram_type)
{
if (!ScriptMap::IsValidTile(tile)) return ROADTYPE_INVALID;
if (road_tram_type != ROADTRAMTYPES_ROAD && road_tram_type != ROADTRAMTYPES_TRAM) return ROADTYPE_INVALID;
- if (::GetAnyRoadBits(tile, (::RoadTramType)road_tram_type, false) == ROAD_NONE) return ROADTYPE_INVALID;
+ if (::GetAnyRoadBits(tile, (::RoadTramType)(road_tram_type >> 1), false) == ROAD_NONE) return ROADTYPE_INVALID;
- return (RoadType)::GetRoadType(tile, (::RoadTramType)road_tram_type);
+ return (RoadType)::GetRoadType(tile, (::RoadTramType)(road_tram_type >> 1));
}
/* static */ bool ScriptRoad::AreRoadTilesConnected(TileIndex t1, TileIndex t2)
diff --git a/src/script/api/script_road.hpp b/src/script/api/script_road.hpp
index fb215d333b..0c45b27606 100644
--- a/src/script/api/script_road.hpp
+++ b/src/script/api/script_road.hpp
@@ -85,6 +85,40 @@ public:
BT_TRUCK_STOP, ///< Build a truck stop
};
+ /**
+ * A bitmap of all the possible road pieces and combinations.
+ */
+ enum RoadPieces {
+ /* Note: these values represent part of the in-game RoadBits enum with added shorthands to T-junctions */
+ ROADPIECES_NONE = 0, ///< No road pieces
+ ROADPIECES_NW = ::ROAD_NW, ///< North-west part
+ ROADPIECES_SW = ::ROAD_SW, ///< South-west part
+ ROADPIECES_SE = ::ROAD_SE, ///< South-east part
+ ROADPIECES_NE = ::ROAD_NE, ///< North-east part
+ ROADPIECES_X = ::ROAD_X, ///< Full road along the x-axis (south-west + north-east)
+ ROADPIECES_Y = ::ROAD_Y, ///< Full road along the y-axis (north-west + south-east)
+ ROADPIECES_N = ::ROAD_N, ///< Road at the two northern edges (corner, north-west + north-east)
+ ROADPIECES_E = ::ROAD_E, ///< Road at the two eastern edges (corner, north-east + south-east)
+ ROADPIECES_S = ::ROAD_S, ///< Road at the two southern edges (corner, south-east + south-west)
+ ROADPIECES_W = ::ROAD_W, ///< Road at the two western edges (corner, south-west + north-west)
+ ROADPIECES_S_NW = ROADPIECES_S | ROADPIECES_NW, ///< T-junction, southern edges + north-west
+ ROADPIECES_W_NE = ROADPIECES_W | ROADPIECES_NE, ///< T-junction, western edges + north-east
+ ROADPIECES_N_SE = ROADPIECES_N | ROADPIECES_SE, ///< T-junction, northern edges + south-east
+ ROADPIECES_E_SW = ROADPIECES_E | ROADPIECES_SW, ///< T-junction, eastern edges + south-west
+ ROADPIECES_ALL = ::ROAD_ALL, ///< Full 4-way crossing
+ };
+
+ /**
+ * One-way info of the tile.
+ */
+ enum OneWayInfo {
+ ONEWAY_NONE = 0, ///< Not a one-way road.
+ ONEWAY_NORTHWEST, ///< One-way road from south-east to north-west.
+ ONEWAY_SOUTHWEST, ///< One-way road from north-east to south-west.
+ ONEWAY_SOUTHEAST, ///< One-way road from north-west to south-east.
+ ONEWAY_NORTHEAST, ///< One-way road from south-west to north-east.
+ };
+
/**
* Get the name of a road type.
* @param road_type The road type to get the name of.
@@ -215,6 +249,23 @@ public:
*/
static bool HasRoadTramType(TileIndex tile, RoadTramTypes road_tram_type);
+ /**
+ * Get the roadpieces that are on a tile.
+ * @param tile The tile to check.
+ * @param road_tram_type The road/tram type to use.
+ * @pre ScriptMap::IsValidTile(tile).
+ * @return The roadpieces that are on the tile.
+ */
+ static RoadPieces GetRoadPieces(TileIndex tile, RoadTramTypes road_tram_type);
+
+ /**
+ * Get info about the one-way state of a tile.
+ * @param tile The tile to check.
+ * @pre ScriptMap::IsValidTile(tile).
+ * @return The OneWayInfo of the tile.
+ */
+ static OneWayInfo GetOneWayInfo(TileIndex tile);
+
/**
* Get the RoadType that is used on a tile.
* @param tile The tile to check.