mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r19415) -Codechange: Forward CommandCost with an error back to the caller.
This commit is contained in:
parent
777123c228
commit
3b367ab708
|
@ -416,7 +416,7 @@ CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags,
|
|||
if (_docommand_recursive == 1 &&
|
||||
!(flags & DC_QUERY_COST) &&
|
||||
!(flags & DC_BANKRUPT) &&
|
||||
!CheckCompanyHasMoney(res)) {
|
||||
!CheckCompanyHasMoney(res)) { // CheckCompanyHasMoney() modifies 'res' to an error if it fails.
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -433,7 +433,7 @@ CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags,
|
|||
error:
|
||||
res.SetGlobalErrorMessage();
|
||||
_docommand_recursive--;
|
||||
return CMD_ERROR;
|
||||
return res;
|
||||
}
|
||||
|
||||
/* if toplevel, subtract the money. */
|
||||
|
|
|
@ -741,7 +741,7 @@ static CommandCost ValidateAutoDrag(Trackdir *trackdir, TileIndex start, TileInd
|
|||
*/
|
||||
static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
CommandCost ret, total_cost(EXPENSES_CONSTRUCTION);
|
||||
CommandCost total_cost(EXPENSES_CONSTRUCTION);
|
||||
Track track = (Track)GB(p2, 4, 3);
|
||||
bool remove = HasBit(p2, 7);
|
||||
RailType railtype = (RailType)GB(p2, 0, 4);
|
||||
|
@ -751,12 +751,14 @@ static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint3
|
|||
TileIndex end_tile = p1;
|
||||
Trackdir trackdir = TrackToTrackdir(track);
|
||||
|
||||
if (ValidateAutoDrag(&trackdir, tile, end_tile).Failed()) return CMD_ERROR;
|
||||
CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
|
||||
ret.SetGlobalErrorMessage();
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
if (flags & DC_EXEC) SndPlayTileFx(SND_20_SPLAT_2, tile);
|
||||
|
||||
for (;;) {
|
||||
ret = DoCommand(tile, railtype, TrackdirToTrack(trackdir), flags, remove ? CMD_REMOVE_SINGLE_RAIL : CMD_BUILD_SINGLE_RAIL);
|
||||
CommandCost ret = DoCommand(tile, railtype, TrackdirToTrack(trackdir), flags, remove ? CMD_REMOVE_SINGLE_RAIL : CMD_BUILD_SINGLE_RAIL);
|
||||
|
||||
if (ret.Failed()) {
|
||||
if (_error_message != STR_ERROR_ALREADY_BUILT && !remove) {
|
||||
|
@ -851,7 +853,7 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
|||
}
|
||||
|
||||
CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||
if (cost.Failed()) return CMD_ERROR;
|
||||
if (cost.Failed()) return cost;
|
||||
|
||||
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
|
||||
|
@ -1122,7 +1124,7 @@ static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal
|
|||
*/
|
||||
static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
CommandCost ret, total_cost(EXPENSES_CONSTRUCTION);
|
||||
CommandCost total_cost(EXPENSES_CONSTRUCTION);
|
||||
bool err = true;
|
||||
TileIndex start_tile = tile;
|
||||
|
||||
|
@ -1144,7 +1146,9 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin
|
|||
* since the original amount will be too dense (shorter tracks) */
|
||||
signal_density *= 2;
|
||||
|
||||
if (ValidateAutoDrag(&trackdir, tile, end_tile).Failed()) return CMD_ERROR;
|
||||
CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
|
||||
ret.SetGlobalErrorMessage();
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
track = TrackdirToTrack(trackdir); // trackdir might have changed, keep track in sync
|
||||
Trackdir start_trackdir = trackdir;
|
||||
|
@ -1198,7 +1202,7 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin
|
|||
if (HasBit(signal_dir, 0)) signals |= SignalAlongTrackdir(trackdir);
|
||||
if (HasBit(signal_dir, 1)) signals |= SignalAgainstTrackdir(trackdir);
|
||||
|
||||
ret = DoCommand(tile, p1, signals, flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS);
|
||||
CommandCost ret = DoCommand(tile, p1, signals, flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS);
|
||||
|
||||
/* Be user-friendly and try placing signals as much as possible */
|
||||
if (ret.Succeeded()) {
|
||||
|
@ -1606,7 +1610,7 @@ static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlag flags)
|
|||
while (tracks != TRACK_BIT_NONE) {
|
||||
Track track = RemoveFirstTrack(&tracks);
|
||||
CommandCost ret = DoCommand(tile, 0, track, flags, CMD_REMOVE_SINGLE_RAIL);
|
||||
if (ret.Failed()) return CMD_ERROR;
|
||||
if (ret.Failed()) return ret;
|
||||
cost.AddCost(ret);
|
||||
}
|
||||
|
||||
|
|
|
@ -904,7 +904,7 @@ CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
|
|||
}
|
||||
|
||||
CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||
if (cost.Failed()) return CMD_ERROR;
|
||||
if (cost.Failed()) return cost;
|
||||
|
||||
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
|
||||
|
|
|
@ -2383,7 +2383,9 @@ CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||
|
||||
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
|
||||
if (DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR).Failed()) return CMD_ERROR;
|
||||
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||
ret.SetGlobalErrorMessage();
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
TileIndex tile_cur = tile + TileOffsByDiagDir(direction);
|
||||
|
||||
|
@ -2396,7 +2398,9 @@ CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||
/* Get the water class of the water tile before it is cleared.*/
|
||||
WaterClass wc = GetWaterClass(tile_cur);
|
||||
|
||||
if (DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR).Failed()) return CMD_ERROR;
|
||||
ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||
ret.SetGlobalErrorMessage();
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
tile_cur += TileOffsByDiagDir(direction);
|
||||
if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) {
|
||||
|
|
|
@ -152,7 +152,7 @@ CommandCost CmdPurchaseLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
|||
}
|
||||
|
||||
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||
if (cost.Failed()) return CMD_ERROR;
|
||||
if (cost.Failed()) return cost;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
MakeOwnedLand(tile, _current_company);
|
||||
|
|
|
@ -126,9 +126,9 @@ CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
|
|||
WaterClass wc1 = GetWaterClass(tile);
|
||||
WaterClass wc2 = GetWaterClass(tile2);
|
||||
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||
if (ret.Failed()) return CMD_ERROR;
|
||||
if (ret.Failed()) return ret;
|
||||
ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||
if (ret.Failed()) return CMD_ERROR;
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
if (!Depot::CanAllocateItem()) return CMD_ERROR;
|
||||
|
||||
|
@ -204,14 +204,14 @@ static CommandCost DoBuildShiplift(TileIndex tile, DiagDirection dir, DoCommandF
|
|||
|
||||
/* middle tile */
|
||||
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||
if (ret.Failed()) return CMD_ERROR;
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
delta = TileOffsByDiagDir(dir);
|
||||
/* lower tile */
|
||||
WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL;
|
||||
|
||||
ret = DoCommand(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||
if (ret.Failed()) return CMD_ERROR;
|
||||
if (ret.Failed()) return ret;
|
||||
if (GetTileSlope(tile - delta, NULL) != SLOPE_FLAT) {
|
||||
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ static CommandCost DoBuildShiplift(TileIndex tile, DiagDirection dir, DoCommandF
|
|||
WaterClass wc_upper = IsWaterTile(tile + delta) ? GetWaterClass(tile + delta) : WATER_CLASS_CANAL;
|
||||
|
||||
ret = DoCommand(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||
if (ret.Failed()) return CMD_ERROR;
|
||||
if (ret.Failed()) return ret;
|
||||
if (GetTileSlope(tile + delta, NULL) != SLOPE_FLAT) {
|
||||
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue