Changeset - r14820:8fe480e5b953
[Not reviewed]
master
0 1 0
alberth - 15 years ago 2010-03-14 16:42:55
alberth@openttd.org
(svn r19421) -Codechange: Remove explicit use of _error_message from CmdConvertRail().
1 file changed with 10 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/rail_cmd.cpp
Show inline comments
 
@@ -1384,13 +1384,12 @@ static Vehicle *UpdateTrainPowerProc(Veh
 
 * @param p2 new railtype to convert to
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	RailType totype = (RailType)p2;
 

	
 
	if (!ValParamRailtype(totype)) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	uint ex = TileX(tile);
 
@@ -1399,14 +1398,14 @@ CommandCost CmdConvertRail(TileIndex til
 
	uint sy = TileY(p1);
 

	
 
	/* make sure sx,sy are smaller than ex,ey */
 
	if (ex < sx) Swap(ex, sx);
 
	if (ey < sy) Swap(ey, sy);
 

	
 
	_error_message = STR_ERROR_NO_SUITABLE_RAILROAD_TRACK; // by default, there is no track to convert
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	CommandCost error = CommandCost(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK); // by default, there is no track to convert.
 
	for (uint x = sx; x <= ex; ++x) {
 
		for (uint y = sy; y <= ey; ++y) {
 
			TileIndex tile = TileXY(x, y);
 
			TileType tt = GetTileType(tile);
 

	
 
			/* Check if there is any track on tile */
 
@@ -1431,25 +1430,25 @@ CommandCost CmdConvertRail(TileIndex til
 
			/* Converting to the same type or converting 'hidden' elrail -> rail */
 
			if (type == totype || (_settings_game.vehicle.disable_elrails && totype == RAILTYPE_RAIL && type == RAILTYPE_ELECTRIC)) continue;
 

	
 
			/* Trying to convert other's rail */
 
			CommandCost ret = CheckTileOwnership(tile);
 
			if (ret.Failed()) {
 
				ret.SetGlobalErrorMessage();
 
				error = ret;
 
				continue;
 
			}
 

	
 
			SmallVector<Train *, 2> vehicles_affected;
 

	
 
			/* Vehicle on the tile when not converting Rail <-> ElRail
 
			 * Tunnels and bridges have special check later */
 
			if (tt != MP_TUNNELBRIDGE) {
 
				if (!IsCompatibleRail(type, totype)) {
 
					CommandCost ret = EnsureNoVehicleOnGround(tile);
 
					if (ret.Failed()) {
 
						ret.SetGlobalErrorMessage();
 
						error = ret;
 
						continue;
 
					}
 
				}
 
				if (flags & DC_EXEC) { // we can safely convert, too
 
					TrackBits reserved = GetReservedTrackbits(tile);
 
					Track     track;
 
@@ -1505,14 +1504,16 @@ CommandCost CmdConvertRail(TileIndex til
 
					if (endtile < tile && TileX(endtile) >= sx && TileX(endtile) <= ex &&
 
							TileY(endtile) >= sy && TileY(endtile) <= ey) continue;
 

	
 
					/* When not coverting rail <-> el. rail, any vehicle cannot be in tunnel/bridge */
 
					if (!IsCompatibleRail(GetRailType(tile), totype)) {
 
						CommandCost ret = TunnelBridgeIsFree(tile, endtile);
 
						ret.SetGlobalErrorMessage();
 
						if (ret.Failed()) continue;
 
						if (ret.Failed()) {
 
							error = ret;
 
							continue;
 
						}
 
					}
 

	
 
					if (flags & DC_EXEC) {
 
						Track track = DiagDirToDiagTrack(GetTunnelBridgeDirection(tile));
 
						if (HasTunnelBridgeReservation(tile)) {
 
							Train *v = GetTrainForReservation(tile, track);
 
@@ -1557,13 +1558,14 @@ CommandCost CmdConvertRail(TileIndex til
 
			for (uint i = 0; i < vehicles_affected.Length(); ++i) {
 
				TryPathReserve(vehicles_affected[i], true);
 
			}
 
		}
 
	}
 

	
 
	return (cost.GetCost() == 0) ? CMD_ERROR : cost;
 
	error.SetGlobalErrorMessage();
 
	return (cost.GetCost() == 0) ? error : cost;
 
}
 

	
 
static CommandCost RemoveTrainDepot(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (_current_company != OWNER_WATER) {
 
		CommandCost ret = CheckTileOwnership(tile);
0 comments (0 inline, 0 general)