summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ai/api/ai_road.cpp7
-rw-r--r--src/ai/api/ai_road.hpp9
2 files changed, 16 insertions, 0 deletions
diff --git a/src/ai/api/ai_road.cpp b/src/ai/api/ai_road.cpp
index f5489348f..6e75effb5 100644
--- a/src/ai/api/ai_road.cpp
+++ b/src/ai/api/ai_road.cpp
@@ -75,6 +75,7 @@
{
if (!::IsValidTile(t1)) return false;
if (!::IsValidTile(t2)) return false;
+ if (!IsRoadTypeAvailable(GetCurrentRoadType())) return false;
/* Tiles not neighbouring */
if ((abs((int)::TileX(t1) - (int)::TileX(t2)) + abs((int)::TileY(t1) - (int)::TileY(t2))) != 1) return false;
@@ -421,6 +422,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia
/* static */ int32 AIRoad::GetNeighbourRoadCount(TileIndex tile)
{
if (!::IsValidTile(tile)) return false;
+ if (!IsRoadTypeAvailable(GetCurrentRoadType())) return false;
::RoadTypes rts = ::RoadTypeToRoadTypes((::RoadType)GetCurrentRoadType());
int32 neighbour = 0;
@@ -461,6 +463,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia
EnforcePrecondition(false, ::IsValidTile(end));
EnforcePrecondition(false, ::TileX(start) == ::TileX(end) || ::TileY(start) == ::TileY(end));
EnforcePrecondition(false, !one_way || AIObject::GetRoadType() == ::ROADTYPE_ROAD);
+ EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
return AIObject::DoCommand(end, start, (::TileY(start) != ::TileY(end) ? 4 : 0) | (((start < end) == !full) ? 1 : 2) | (AIObject::GetRoadType() << 3) | ((one_way ? 1 : 0) << 5), CMD_BUILD_LONG_ROAD);
}
@@ -491,6 +494,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, ::IsValidTile(front));
EnforcePrecondition(false, ::TileX(tile) == ::TileX(front) || ::TileY(tile) == ::TileY(front));
+ EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
uint entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? 1 : 3) : (::TileX(tile) < ::TileX(front) ? 2 : 0);
@@ -505,6 +509,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia
EnforcePrecondition(false, ::TileX(tile) == ::TileX(front) || ::TileY(tile) == ::TileY(front));
EnforcePrecondition(false, station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id));
EnforcePrecondition(false, road_veh_type == ROADVEHTYPE_BUS || road_veh_type == ROADVEHTYPE_TRUCK);
+ EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
uint entrance_dir;
if (drive_through) {
@@ -536,6 +541,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia
EnforcePrecondition(false, ::IsValidTile(start));
EnforcePrecondition(false, ::IsValidTile(end));
EnforcePrecondition(false, ::TileX(start) == ::TileX(end) || ::TileY(start) == ::TileY(end));
+ EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
return AIObject::DoCommand(end, start, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (AIObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD);
}
@@ -545,6 +551,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia
EnforcePrecondition(false, ::IsValidTile(start));
EnforcePrecondition(false, ::IsValidTile(end));
EnforcePrecondition(false, ::TileX(start) == ::TileX(end) || ::TileY(start) == ::TileY(end));
+ EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
return AIObject::DoCommand(end, start, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 2 : 1) | (AIObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD);
}
diff --git a/src/ai/api/ai_road.hpp b/src/ai/api/ai_road.hpp
index 9f8474838..e65655e4a 100644
--- a/src/ai/api/ai_road.hpp
+++ b/src/ai/api/ai_road.hpp
@@ -134,6 +134,7 @@ public:
* center of the second tile.
* @param tile_from The source tile.
* @param tile_to The destination tile.
+ * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
* @pre AIMap::IsValidTile(tile_from).
* @pre AIMap::IsValidTile(tile_to).
* @pre 'tile_from' and 'tile_to' are directly neighbouring tiles.
@@ -197,6 +198,7 @@ public:
* Count how many neighbours are road.
* @param tile The tile to check on.
* @pre AIMap::IsValidTile(tile).
+ * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
* @return 0 means no neighbour road; max value is 4.
*/
static int32 GetNeighbourRoadCount(TileIndex tile);
@@ -237,6 +239,7 @@ public:
* @pre 'start' and 'end' are in a straight line, i.e.
* AIMap::GetTileX(start) == AIMap::GetTileX(end) or
* AIMap::GetTileY(start) == AIMap::GetTileY(end).
+ * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
* @exception AIError::ERR_ALREADY_BUILT
* @exception AIError::ERR_LAND_SLOPED_WRONG
* @exception AIError::ERR_AREA_NOT_CLEAR
@@ -284,6 +287,7 @@ public:
* @pre 'start' and 'end' are in a straight line, i.e.
* AIMap::GetTileX(start) == AIMap::GetTileX(end) or
* AIMap::GetTileY(start) == AIMap::GetTileY(end).
+ * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
* @exception AIError::ERR_ALREADY_BUILT
* @exception AIError::ERR_LAND_SLOPED_WRONG
* @exception AIError::ERR_AREA_NOT_CLEAR
@@ -328,6 +332,7 @@ public:
* @pre AIMap::IsValidTile(tile).
* @pre AIMap::IsValidTile(front).
* @pre 'tile' is not equal to 'front', but in a straight line of it.
+ * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
* @exception AIError::ERR_FLAT_LAND_REQUIRED
* @exception AIError::ERR_AREA_NOT_CLEAR
* @return Whether the road depot has been/can be build or not.
@@ -344,6 +349,7 @@ public:
* @pre AIMap::IsValidTile(front).
* @pre 'tile' is not equal to 'front', but in a straight line of it.
* @pre station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id).
+ * @pre GetCurrentRoadType() == ROADTYPE_ROAD.
* @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
* @exception AIError::ERR_AREA_NOT_CLEAR
* @exception AIError::ERR_FLAT_LAND_REQUIRED
@@ -367,6 +373,7 @@ public:
* @pre AIMap::IsValidTile(front).
* @pre 'tile' is not equal to 'front', but in a straight line of it.
* @pre station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id).
+ * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
* @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
* @exception AIError::ERR_AREA_NOT_CLEAR
* @exception AIError::ERR_FLAT_LAND_REQUIRED
@@ -389,6 +396,7 @@ public:
* @pre 'start' and 'end' are in a straight line, i.e.
* AIMap::GetTileX(start) == AIMap::GetTileX(end) or
* AIMap::GetTileY(start) == AIMap::GetTileY(end).
+ * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
* @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
* @exception AIError::ERR_VEHICLE_IN_THE_WAY
* @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS
@@ -406,6 +414,7 @@ public:
* @pre 'start' and 'end' are in a straight line, i.e.
* AIMap::GetTileX(start) == AIMap::GetTileX(end) or
* AIMap::GetTileY(start) == AIMap::GetTileY(end).
+ * @pre IsRoadTypeAvailable(GetCurrentRoadType()).
* @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
* @exception AIError::ERR_VEHICLE_IN_THE_WAY
* @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS