changeset 14429:361ea03dee01 draft

(svn r18986) -Fix (r18803): Make building long roads fail for AIs if there is an obstacle in the way.
author terkhen <terkhen@openttd.org>
date Tue, 02 Feb 2010 21:25:01 +0000
parents f412a4431c2d
children c6edaac902aa
files src/ai/api/ai_road.cpp src/ai/api/ai_road.hpp src/road_cmd.cpp
diffstat 3 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/ai/api/ai_road.cpp
+++ b/src/ai/api/ai_road.cpp
@@ -471,7 +471,7 @@
 	EnforcePrecondition(false, !one_way || AIObject::GetRoadType() == ::ROADTYPE_ROAD);
 	EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
 
-	return AIObject::DoCommand(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (((start < end) == !full) ? 1 : 2) | (AIObject::GetRoadType() << 3) | ((one_way ? 1 : 0) << 5), CMD_BUILD_LONG_ROAD);
+	return AIObject::DoCommand(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (((start < end) == !full) ? 1 : 2) | (AIObject::GetRoadType() << 3) | ((one_way ? 1 : 0) << 5) | 1 << 6, CMD_BUILD_LONG_ROAD);
 }
 
 /* static */ bool AIRoad::BuildRoad(TileIndex start, TileIndex end)
--- a/src/ai/api/ai_road.hpp
+++ b/src/ai/api/ai_road.hpp
@@ -263,6 +263,7 @@
 	 * @exception AIRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS
 	 * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS
 	 * @exception AIError::ERR_VEHICLE_IN_THE_WAY
+	 * @note Construction will fail if an obstacle is found between the start and end tiles.
 	 * @return Whether the road has been/can be build or not.
 	 */
 	static bool BuildRoad(TileIndex start, TileIndex end);
@@ -289,6 +290,7 @@
 	 * @exception AIRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS
 	 * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS
 	 * @exception AIError::ERR_VEHICLE_IN_THE_WAY
+	 * @note Construction will fail if an obstacle is found between the start and end tiles.
 	 * @return Whether the road has been/can be build or not.
 	 */
 	static bool BuildOneWayRoad(TileIndex start, TileIndex end);
@@ -311,6 +313,7 @@
 	 * @exception AIRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS
 	 * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS
 	 * @exception AIError::ERR_VEHICLE_IN_THE_WAY
+	 * @note Construction will fail if an obstacle is found between the start and end tiles.
 	 * @return Whether the road has been/can be build or not.
 	 */
 	static bool BuildRoadFull(TileIndex start, TileIndex end);
@@ -338,6 +341,7 @@
 	 * @exception AIRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS
 	 * @exception AIRoad::ERR_ROAD_WORKS_IN_PROGRESS
 	 * @exception AIError::ERR_VEHICLE_IN_THE_WAY
+	 * @note Construction will fail if an obstacle is found between the start and end tiles.
 	 * @return Whether the road has been/can be build or not.
 	 */
 	static bool BuildOneWayRoadFull(TileIndex start, TileIndex end);
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -690,6 +690,7 @@
  * - p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
  * - p2 = (bit 3 + 4) - road type
  * - p2 = (bit 5) - set road direction
+ * - p2 = (bit 6) - 0 = build up to an obstacle, 1 = fail if an obstacle is found (used for AIs).
  * @param text unused
  * @return the cost of this operation or an error
  */
@@ -742,7 +743,10 @@
 		_error_message = INVALID_STRING_ID;
 		CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
 		if (ret.Failed()) {
-			if (_error_message != STR_ERROR_ALREADY_BUILT) break;
+			if (_error_message != STR_ERROR_ALREADY_BUILT) {
+				if (HasBit(p2, 6)) return CMD_ERROR;
+				break;
+			}
 		} else {
 			had_success = true;
 			/* Only pay for the upgrade on one side of the bridges and tunnels */