Changeset - r14814:3d4abc0944bc
[Not reviewed]
master
0 6 0
alberth - 14 years ago 2010-03-14 12:58:51
alberth@openttd.org
(svn r19415) -Codechange: Forward CommandCost with an error back to the caller.
6 files changed with 27 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/command.cpp
Show inline comments
 
@@ -416,7 +416,7 @@ CommandCost DoCommand(TileIndex tile, ui
 
		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, ui
 
error:
 
		res.SetGlobalErrorMessage();
 
		_docommand_recursive--;
 
		return CMD_ERROR;
 
		return res;
 
	}
 

	
 
	/* if toplevel, subtract the money. */
src/rail_cmd.cpp
Show inline comments
 
@@ -741,7 +741,7 @@ static CommandCost ValidateAutoDrag(Trac
 
 */
 
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(Ti
 
	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
 
	}
 

	
 
	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(TileInde
 
 */
 
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(
 
	 * 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(
 
			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(TileI
 
			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);
 
			}
 

	
src/road_cmd.cpp
Show inline comments
 
@@ -904,7 +904,7 @@ CommandCost CmdBuildRoadDepot(TileIndex 
 
	}
 

	
 
	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);
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -2383,7 +2383,9 @@ CommandCost CmdBuildDock(TileIndex tile,
 

	
 
	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,
 
	/* 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) {
src/unmovable_cmd.cpp
Show inline comments
 
@@ -152,7 +152,7 @@ CommandCost CmdPurchaseLandArea(TileInde
 
	}
 

	
 
	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);
src/water_cmd.cpp
Show inline comments
 
@@ -126,9 +126,9 @@ CommandCost CmdBuildShipDepot(TileIndex 
 
	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(TileI
 

	
 
	/* 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(TileI
 
	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);
 
	}
0 comments (0 inline, 0 general)