Changeset - r24316:fdd14cd985bb
[Not reviewed]
master
0 1 0
TrevorShelton - 4 years ago 2020-06-28 08:55:57
54145769+TrevorShelton@users.noreply.github.com
Change #8162: Conversion of Town Road, Impr. Error

This changes the error when you attempt to convert a road owned by a town to another road, specifying that it's owned by the town rather than simply being incompatible. As the original poster of the issue pointed out, these seemed to be the only occurences of the incompatible road string, so now it's unused, but they would be left untouched in case of future use or since changing it to a different error would do the work of removing it then. If requested, it likely wouldn't be too difficult to remove the string entirely.
1 file changed with 4 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/road_cmd.cpp
Show inline comments
 
@@ -2378,95 +2378,97 @@ CommandCost CmdConvertRoad(TileIndex til
 
			default: continue;
 
		}
 

	
 
		/* Trying to convert other's road */
 
		Owner owner = GetRoadOwner(tile, rtt);
 
		if (!CanConvertUnownedRoadType(owner, rtt)) {
 
			CommandCost ret = CheckOwnership(owner, tile);
 
			if (ret.Failed()) {
 
				error = ret;
 
				continue;
 
			}
 
		}
 

	
 
		/* Vehicle on the tile when not converting normal <-> powered
 
		 * Tunnels and bridges have special check later */
 
		if (tt != MP_TUNNELBRIDGE) {
 
			if (!HasPowerOnRoad(from_type, to_type)) {
 
				CommandCost ret = EnsureNoVehicleOnGround(tile);
 
				if (ret.Failed()) {
 
					error = ret;
 
					continue;
 
				}
 

	
 
				if (rtt == RTT_ROAD && owner == OWNER_TOWN) {
 
					error.MakeError(STR_ERROR_INCOMPATIBLE_ROAD);
 
					error.MakeError(STR_ERROR_OWNED_BY);
 
					GetNameOfOwner(OWNER_TOWN, tile);
 
					continue;
 
				}
 
			}
 

	
 
			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
 
				/* Update the company infrastructure counters. */
 
				if (!IsRoadStopTile(tile) && owner == _current_company) {
 
					ConvertRoadTypeOwner(tile, num_pieces, owner, from_type, to_type);
 
				}
 

	
 
				/* Perform the conversion */
 
				SetRoadType(tile, rtt, to_type);
 
				MarkTileDirtyByTile(tile);
 

	
 
				/* update power of train on this tile */
 
				FindVehicleOnPos(tile, &affected_rvs, &UpdateRoadVehPowerProc);
 

	
 
				if (IsRoadDepotTile(tile)) {
 
					/* Update build vehicle window related to this depot */
 
					InvalidateWindowData(WC_VEHICLE_DEPOT, tile);
 
					InvalidateWindowData(WC_BUILD_VEHICLE, tile);
 
				}
 
			}
 
		} else {
 
			TileIndex endtile = GetOtherTunnelBridgeEnd(tile);
 

	
 
			/* If both ends of tunnel/bridge are in the range, do not try to convert twice -
 
			 * it would cause assert because of different test and exec runs */
 
			if (endtile < tile) {
 
				if (OrthogonalTileArea(area_start, area_end).Contains(endtile)) continue;
 
			}
 

	
 
			/* When not converting rail <-> el. rail, any vehicle cannot be in tunnel/bridge */
 
			if (!HasPowerOnRoad(from_type, to_type)) {
 
				CommandCost ret = TunnelBridgeIsFree(tile, endtile);
 
				if (ret.Failed()) {
 
					error = ret;
 
					continue;
 
				}
 

	
 
				if (rtt == RTT_ROAD && owner == OWNER_TOWN) {
 
					error.MakeError(STR_ERROR_INCOMPATIBLE_ROAD);
 
					error.MakeError(STR_ERROR_OWNED_BY);
 
					GetNameOfOwner(OWNER_TOWN, tile);
 
					continue;
 
				}
 
			}
 

	
 
			/* 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) {
 
				/* Update the company infrastructure counters. */
 
				if (owner == _current_company) {
 
					ConvertRoadTypeOwner(tile, num_pieces, owner, from_type, to_type);
 
					ConvertRoadTypeOwner(endtile, num_pieces, owner, from_type, to_type);
 
					SetTunnelBridgeOwner(tile, endtile, _current_company);
 
				}
 

	
 
				/* Perform the conversion */
 
				SetRoadType(tile,    rtt, to_type);
 
				SetRoadType(endtile, rtt, to_type);
 

	
 
				FindVehicleOnPos(tile, &affected_rvs, &UpdateRoadVehPowerProc);
 
				FindVehicleOnPos(endtile, &affected_rvs, &UpdateRoadVehPowerProc);
 

	
0 comments (0 inline, 0 general)