Script: Add ScriptRoad methods related to road types
This commit is contained in:
@@ -134,6 +134,7 @@ This document does not describe the player-visible changes/additions described i
|
|||||||
* [AI/GS script additions](docs/script-additions.html).
|
* [AI/GS script additions](docs/script-additions.html).
|
||||||
* Add AI/GS method to get current day length.
|
* Add AI/GS method to get current day length.
|
||||||
* Add GS method to create river tiles.
|
* 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.
|
* 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.
|
* Fixup a GS otherwise inconsistent with day length.
|
||||||
|
|
||||||
|
@@ -66,5 +66,34 @@
|
|||||||
<div class="methodtext">All other details are the same as BuildCanal.</div>
|
<div class="methodtext">All other details are the same as BuildCanal.</div>
|
||||||
</div>
|
</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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -98,6 +98,22 @@
|
|||||||
return ::GetAnyRoadBits(tile, ::GetRoadTramType((::RoadType)road_type), false) != ROAD_NONE;
|
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)
|
/* static */ bool ScriptRoad::AreRoadTilesConnected(TileIndex t1, TileIndex t2)
|
||||||
{
|
{
|
||||||
if (!::IsValidTile(t1)) return false;
|
if (!::IsValidTile(t1)) return false;
|
||||||
@@ -644,3 +660,31 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD
|
|||||||
|
|
||||||
return GetRoadTypeInfo((::RoadType)roadtype)->maintenance_multiplier;
|
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,13 +194,32 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a given tile has RoadType.
|
* 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 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 tile The tile to check.
|
||||||
* @param road_type The RoadType to check for.
|
* @param road_type The RoadType to check for.
|
||||||
* @pre ScriptMap::IsValidTile(tile).
|
* @pre ScriptMap::IsValidTile(tile).
|
||||||
* @pre IsRoadTypeAvailable(road_type).
|
* @pre IsRoadTypeAvailable(road_type).
|
||||||
* @return True if the tile contains a RoadType object.
|
* @return True if the tile contains a RoadType object.
|
||||||
*/
|
*/
|
||||||
static bool HasRoadType(TileIndex tile, RoadType road_type);
|
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
|
* Checks whether the given tiles are directly connected, i.e. whether
|
||||||
@@ -571,6 +590,38 @@ public:
|
|||||||
*/
|
*/
|
||||||
static uint16 GetMaintenanceCostFactor(RoadType roadtype);
|
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:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user