summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2019-07-01 10:37:59 +0200
committerNiels Martin Hansen <nielsm@indvikleren.dk>2019-07-06 21:04:43 +0200
commit81614f2378ec959312a71d49da1747c595b739c3 (patch)
tree2a704d5c7b3f6c5bfb5d1e41500f5c74e0015a07
parent9f81778836f8d7722d381d806a4c61efabf0425d (diff)
downloadopenttd-81614f2378ec959312a71d49da1747c595b739c3.tar.xz
Fix #7633: Allow zero-cost track conversion to succeed
-rw-r--r--src/rail_cmd.cpp7
-rw-r--r--src/road_cmd.cpp5
2 files changed, 10 insertions, 2 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index df862d4f2..1a4728c6c 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -1578,6 +1578,7 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
CommandCost cost(EXPENSES_CONSTRUCTION);
CommandCost error = CommandCost(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK); // by default, there is no track to convert.
+ bool found_convertible_track = false; // whether we actually did convert some track (see bug #7633)
TileIterator *iter = diagonal ? (TileIterator *)new DiagonalTileIterator(area_start, area_end) : new OrthogonalTileIterator(area_start, area_end);
for (; (tile = *iter) != INVALID_TILE; ++(*iter)) {
@@ -1673,6 +1674,7 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
InvalidateWindowData(WC_VEHICLE_DEPOT, tile);
InvalidateWindowData(WC_BUILD_VEHICLE, tile);
}
+ found_convertible_track = true;
cost.AddCost(RailConvertCost(type, totype));
break;
@@ -1684,6 +1686,7 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
YapfNotifyTrackLayoutChange(tile, RemoveFirstTrack(&tracks));
}
}
+ found_convertible_track = true;
cost.AddCost(RailConvertCost(type, totype) * CountBits(GetTrackBits(tile)));
break;
}
@@ -1746,6 +1749,7 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
}
}
+ found_convertible_track = true;
cost.AddCost((GetTunnelBridgeLength(tile, endtile) + 2) * RailConvertCost(type, totype));
break;
}
@@ -1756,6 +1760,7 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
YapfNotifyTrackLayoutChange(tile, track);
}
+ found_convertible_track = true;
cost.AddCost(RailConvertCost(type, totype));
break;
}
@@ -1773,7 +1778,7 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
}
delete iter;
- return (cost.GetCost() == 0) ? error : cost;
+ return found_convertible_track ? cost : error;
}
static CommandCost RemoveTrainDepot(TileIndex tile, DoCommandFlag flags)
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 87da8186c..4f5519c31 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -2345,6 +2345,7 @@ CommandCost CmdConvertRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
CommandCost cost(EXPENSES_CONSTRUCTION);
CommandCost error = CommandCost((rtt == RTT_TRAM) ? STR_ERROR_NO_SUITABLE_TRAMWAY : STR_ERROR_NO_SUITABLE_ROAD); // by default, there is no road to convert.
+ bool found_convertible_road = false; // whether we actually did convert any road/tram (see bug #7633)
TileIterator *iter = new OrthogonalTileIterator(area_start, area_end);
for (; (tile = *iter) != INVALID_TILE; ++(*iter)) {
@@ -2400,6 +2401,7 @@ CommandCost CmdConvertRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
}
uint num_pieces = CountBits(GetAnyRoadBits(tile, rtt));;
+ found_convertible_road = true;
cost.AddCost(num_pieces * RoadConvertCost(from_type, to_type));
if (flags & DC_EXEC) { // we can safely convert, too
@@ -2446,6 +2448,7 @@ CommandCost CmdConvertRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
/* There are 2 pieces on *every* tile of the bridge or tunnel */
uint num_pieces = (GetTunnelBridgeLength(tile, endtile) + 2) * 2;
+ found_convertible_road = true;
cost.AddCost(num_pieces * RoadConvertCost(from_type, to_type));
if (flags & DC_EXEC) {
@@ -2481,7 +2484,7 @@ CommandCost CmdConvertRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
}
delete iter;
- return (cost.GetCost() == 0) ? error : cost;
+ return found_convertible_road ? cost : error;
}