Feature/Fix: [GS] Add RoadTiles and GetOneWayInfo endpoints (#611)

Feature: [GS] Add RoadTiles and GetOneWayInfo endpoints
pull/615/head
Miika Kulmala 5 months ago committed by GitHub
parent 88670a230f
commit e47bfe47b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -104,6 +104,14 @@
<div class="code">static bool IsTownBuildableRoadType(RoadType roadtype)</div>
<div class="methodtext">Checks whether the given road type is buildable by towns.</div>
</div>
<div class="indent">
<div class="code">static RoadPieces GetRoadPieces(TileIndex tile, RoadTramTypes road_tram_type)</div>
<div class="methodtext">Get the RoadPieces that are on a tile.</div>
</div>
<div class="indent">
<div class="code">static OneWayInfo GetOneWayInfo(TileIndex tile)</div>
<div class="methodtext">Get info about the one-way state of a tile.</div>
</div>
</div>
<h3 id="company">Company: <a href="https://docs.openttd.org/gs-api/classGSCompany.html">GSCompany Class</a> and <a href="https://docs.openttd.org/ai-api/classAICompany.html">AICompany Class</a></h3>

@ -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)

@ -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.

Loading…
Cancel
Save