diff --git a/docs/jgrpp-low-level-changes.md b/docs/jgrpp-low-level-changes.md index cfe90b4161..4dc6aa05b2 100644 --- a/docs/jgrpp-low-level-changes.md +++ b/docs/jgrpp-low-level-changes.md @@ -134,6 +134,7 @@ This document does not describe the player-visible changes/additions described i * [AI/GS script additions](docs/script-additions.html). * Add AI/GS method to get current day length. * Add GS method to create river tiles. +* Add AI/GS methods related to road and tram types. * Add workaround for performance issues when attempting to create a town when no town names are left. * Fixup a GS otherwise inconsistent with day length. diff --git a/docs/script-additions.html b/docs/script-additions.html index 28e5bb5a2c..a7e3f78e50 100644 --- a/docs/script-additions.html +++ b/docs/script-additions.html @@ -61,10 +61,39 @@

Additional Static Public Member Functions:

-
static bool BuildRiver (TileIndex tile)
+
static bool BuildRiver (TileIndex tile)
Builds a river on tile (subject to permissions/settings).
All other details are the same as BuildCanal.
+ +

Road: GSRoad Class and AIRoad Class

+
+

Additional Static Public Member Functions:

+
+
static bool HasRoadTramType(TileIndex tile, RoadTramTypes road_tram_type)
+
Check if a tile has the given road tram type.
+
+
+
static RoadType GetRoadType(TileIndex tile, RoadTramTypes road_tram_type)
+
Get the RoadType that is used on a tile.
+
+
+
static bool IsCatenaryRoadType(RoadType roadtype)
+
Checks whether the given road type uses a catenary.
+
+
+
static bool IsNonLevelCrossingRoadType(RoadType roadtype)
+
Checks whether the given road type disallows level crossings.
+
+
+
static bool IsNoTownHousesRoadType(RoadType roadtype)
+
Checks whether the given road type cannot be used by towns to build houses.
+
+
+
static bool IsTownBuildableRoadType(RoadType roadtype)
+
Checks whether the given road type is buildable by towns.
+
+
diff --git a/src/script/api/script_road.cpp b/src/script/api/script_road.cpp index 7cb7d554b5..afad3a3012 100644 --- a/src/script/api/script_road.cpp +++ b/src/script/api/script_road.cpp @@ -98,6 +98,22 @@ return ::GetAnyRoadBits(tile, ::GetRoadTramType((::RoadType)road_type), false) != ROAD_NONE; } +/* static */ bool ScriptRoad::HasRoadTramType(TileIndex tile, RoadTramTypes road_tram_type) +{ + 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; +} + +/* 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; + + return (RoadType)::GetRoadType(tile, (::RoadTramType)road_tram_type); +} + /* static */ bool ScriptRoad::AreRoadTilesConnected(TileIndex t1, TileIndex t2) { if (!::IsValidTile(t1)) return false; @@ -644,3 +660,31 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD return GetRoadTypeInfo((::RoadType)roadtype)->maintenance_multiplier; } + +/* static */ bool ScriptRoad::IsCatenaryRoadType(RoadType roadtype) +{ + if (!ScriptRoad::IsRoadTypeAvailable(roadtype)) return false; + + return HasBit(GetRoadTypeInfo((::RoadType)roadtype)->flags, ROTF_CATENARY); +} + +/* static */ bool ScriptRoad::IsNonLevelCrossingRoadType(RoadType roadtype) +{ + if (!ScriptRoad::IsRoadTypeAvailable(roadtype)) return false; + + return HasBit(GetRoadTypeInfo((::RoadType)roadtype)->flags, ROTF_NO_LEVEL_CROSSING); +} + +/* static */ bool ScriptRoad::IsNoTownHousesRoadType(RoadType roadtype) +{ + if (!ScriptRoad::IsRoadTypeAvailable(roadtype)) return false; + + return HasBit(GetRoadTypeInfo((::RoadType)roadtype)->flags, ROTF_NO_HOUSES); +} + +/* static */ bool ScriptRoad::IsTownBuildableRoadType(RoadType roadtype) +{ + if (!ScriptRoad::IsRoadTypeAvailable(roadtype)) return false; + + return HasBit(GetRoadTypeInfo((::RoadType)roadtype)->flags, ROTF_TOWN_BUILD) && !HasBit(GetRoadTypeInfo((::RoadType)roadtype)->extra_flags, RXTF_NO_TOWN_MODIFICATION); +} diff --git a/src/script/api/script_road.hpp b/src/script/api/script_road.hpp index 769c4a7728..f75764482c 100644 --- a/src/script/api/script_road.hpp +++ b/src/script/api/script_road.hpp @@ -194,14 +194,33 @@ public: /** * Check if a given tile has RoadType. + * Note that this function actually checks if the tile has the RoadTramTypes of the given RoadType. * @param tile The tile to check. * @param road_type The RoadType to check for. * @pre ScriptMap::IsValidTile(tile). * @pre IsRoadTypeAvailable(road_type). - * @return True if the tile contains a RoadType object. + * @return True if the tile contains the RoadTramTypes of the given RoadType. */ static bool HasRoadType(TileIndex tile, RoadType road_type); + /** + * Check if a tile has the given RoadTramType. + * @param tile The tile to check. + * @param road_type The RoadType to check for. + * @pre ScriptMap::IsValidTile(tile). + * @pre IsRoadTypeAvailable(road_type). + * @return True if the tile contains a RoadType object. + */ + static bool HasRoadTramType(TileIndex tile, RoadTramTypes road_tram_type); + + /** + * Get the RoadType that is used on a tile. + * @param tile The tile to check. + * @param RoadType The road/tram type to use. + * @return The RoadType that is used on the tile, or ROADTYPE_INVALID if not present. + */ + static RoadType GetRoadType(TileIndex tile, RoadTramTypes road_tram_type); + /** * Checks whether the given tiles are directly connected, i.e. whether * a road vehicle can travel from the center of the first tile to the @@ -571,6 +590,38 @@ public: */ static uint16 GetMaintenanceCostFactor(RoadType roadtype); + /** + * Checks whether the given road type uses a catenary. + * @param roadtype The road type to check. + * @pre IsRoadTypeAvailable(roadtype) + * @return Whether the given road type uses a catenary. + */ + static bool IsCatenaryRoadType(RoadType roadtype); + + /** + * Checks whether the given road type disallows level crossings. + * @param roadtype The road type to check. + * @pre IsRoadTypeAvailable(roadtype) + * @return Whether the given road type disallows level crossings. + */ + static bool IsNonLevelCrossingRoadType(RoadType roadtype); + + /** + * Checks whether the given road type cannot be used by towns to build houses. + * @param roadtype The road type to check. + * @pre IsRoadTypeAvailable(roadtype) + * @return Whether the given road type cannot be used by towns to build houses. + */ + static bool IsNoTownHousesRoadType(RoadType roadtype); + + /** + * Checks whether the given road type is buildable by towns. + * @param roadtype The road type to check. + * @pre IsRoadTypeAvailable(roadtype) + * @return Whether the given road type is buildable by towns. + */ + static bool IsTownBuildableRoadType(RoadType roadtype); + private: /**