Script: Add ScriptRoad methods related to road types

pull/362/head
Jonathan G Rennison 2 years ago
parent dfc6e309d0
commit 579c71dd44

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

@ -61,10 +61,39 @@
<div class="indent">
<h4>Additional Static Public Member Functions:</h4>
<div class="indent">
<div class="code">static bool BuildRiver (TileIndex tile)</div>
<div class="code">static bool BuildRiver (TileIndex tile)</div>
<div class="methodtext">Builds a river on tile (subject to permissions/settings).</div>
<div class="methodtext">All other details are the same as BuildCanal.</div>
</div>
</div>
<h3>Road: <a href="https://docs.openttd.org/gs-api/classGSRoad.html">GSRoad Class</a> and <a href="https://docs.openttd.org/ai-api/classAIRoad.html">AIRoad Class</a></h3>
<div class="indent">
<h4>Additional Static Public Member Functions:</h4>
<div class="indent">
<div class="code">static bool HasRoadTramType(TileIndex tile, RoadTramTypes road_tram_type)</div>
<div class="methodtext">Check if a tile has the given road tram type.</div>
</div>
<div class="indent">
<div class="code">static RoadType GetRoadType(TileIndex tile, RoadTramTypes road_tram_type)</div>
<div class="methodtext">Get the RoadType that is used on a tile.</div>
</div>
<div class="indent">
<div class="code">static bool IsCatenaryRoadType(RoadType roadtype)</div>
<div class="methodtext">Checks whether the given road type uses a catenary.</div>
</div>
<div class="indent">
<div class="code">static bool IsNonLevelCrossingRoadType(RoadType roadtype)</div>
<div class="methodtext">Checks whether the given road type disallows level crossings.</div>
</div>
<div class="indent">
<div class="code">static bool IsNoTownHousesRoadType(RoadType roadtype)</div>
<div class="methodtext">Checks whether the given road type cannot be used by towns to build houses.</div>
</div>
<div class="indent">
<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>
</body>
</html>

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

@ -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:
/**

Loading…
Cancel
Save