1
0
Fork 0

(svn r19421) -Codechange: Remove explicit use of _error_message from CmdConvertRail().

release/1.1
alberth 2010-03-14 16:42:55 +00:00
parent 05e549ccdc
commit 6eb0816c70
1 changed files with 10 additions and 8 deletions

View File

@ -1387,7 +1387,6 @@ static Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data)
*/ */
CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{ {
CommandCost cost(EXPENSES_CONSTRUCTION);
RailType totype = (RailType)p2; RailType totype = (RailType)p2;
if (!ValParamRailtype(totype)) return CMD_ERROR; if (!ValParamRailtype(totype)) return CMD_ERROR;
@ -1402,8 +1401,8 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
if (ex < sx) Swap(ex, sx); if (ex < sx) Swap(ex, sx);
if (ey < sy) Swap(ey, sy); 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 x = sx; x <= ex; ++x) {
for (uint y = sy; y <= ey; ++y) { for (uint y = sy; y <= ey; ++y) {
TileIndex tile = TileXY(x, y); TileIndex tile = TileXY(x, y);
@ -1434,7 +1433,7 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
/* Trying to convert other's rail */ /* Trying to convert other's rail */
CommandCost ret = CheckTileOwnership(tile); CommandCost ret = CheckTileOwnership(tile);
if (ret.Failed()) { if (ret.Failed()) {
ret.SetGlobalErrorMessage(); error = ret;
continue; continue;
} }
@ -1446,7 +1445,7 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
if (!IsCompatibleRail(type, totype)) { if (!IsCompatibleRail(type, totype)) {
CommandCost ret = EnsureNoVehicleOnGround(tile); CommandCost ret = EnsureNoVehicleOnGround(tile);
if (ret.Failed()) { if (ret.Failed()) {
ret.SetGlobalErrorMessage(); error = ret;
continue; continue;
} }
} }
@ -1508,8 +1507,10 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
/* When not coverting rail <-> el. rail, any vehicle cannot be in tunnel/bridge */ /* When not coverting rail <-> el. rail, any vehicle cannot be in tunnel/bridge */
if (!IsCompatibleRail(GetRailType(tile), totype)) { if (!IsCompatibleRail(GetRailType(tile), totype)) {
CommandCost ret = TunnelBridgeIsFree(tile, endtile); CommandCost ret = TunnelBridgeIsFree(tile, endtile);
ret.SetGlobalErrorMessage(); if (ret.Failed()) {
if (ret.Failed()) continue; error = ret;
continue;
}
} }
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
@ -1560,7 +1561,8 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
} }
} }
return (cost.GetCost() == 0) ? CMD_ERROR : cost; error.SetGlobalErrorMessage();
return (cost.GetCost() == 0) ? error : cost;
} }
static CommandCost RemoveTrainDepot(TileIndex tile, DoCommandFlag flags) static CommandCost RemoveTrainDepot(TileIndex tile, DoCommandFlag flags)