File diff r26089:2283e9229bb0 → r26090:5a592dbf1c28
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -415,21 +415,21 @@ CommandCost CmdBuildBridge(TileIndex end
 
	} else {
 
		/* Build a new bridge. */
 

	
 
		bool allow_on_slopes = (_settings_game.construction.build_on_slopes && transport_type != TRANSPORT_WATER);
 

	
 
		/* Try and clear the start landscape */
 
		CommandCost ret = DoCommand(tile_start, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile_start, 0, 0);
 
		if (ret.Failed()) return ret;
 
		cost = ret;
 

	
 
		if (terraform_cost_north.Failed() || (terraform_cost_north.GetCost() != 0 && !allow_on_slopes)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
		cost.AddCost(terraform_cost_north);
 

	
 
		/* Try and clear the end landscape */
 
		ret = DoCommand(tile_end, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile_end, 0, 0);
 
		if (ret.Failed()) return ret;
 
		cost.AddCost(ret);
 

	
 
		/* false - end tile slope check */
 
		if (terraform_cost_south.Failed() || (terraform_cost_south.GetCost() != 0 && !allow_on_slopes)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
		cost.AddCost(terraform_cost_south);
 
@@ -495,13 +495,13 @@ CommandCost CmdBuildBridge(TileIndex end
 
				case MP_CLEAR:
 
					break;
 

	
 
				default:
 
	not_valid_below:;
 
					/* try and clear the middle landscape */
 
					ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
					ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
					if (ret.Failed()) return ret;
 
					cost.AddCost(ret);
 
					break;
 
			}
 

	
 
			if (flags & DC_EXEC) {
 
@@ -669,13 +669,13 @@ CommandCost CmdBuildTunnel(TileIndex sta
 
	Slope start_tileh = GetTileSlope(start_tile, &start_z);
 
	DiagDirection direction = GetInclinedSlopeDirection(start_tileh);
 
	if (direction == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_SITE_UNSUITABLE_FOR_TUNNEL);
 

	
 
	if (HasTileWaterGround(start_tile)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
 

	
 
	CommandCost ret = DoCommand(start_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, start_tile, 0, 0);
 
	if (ret.Failed()) return ret;
 

	
 
	/* XXX - do NOT change 'ret' in the loop, as it is used as the price
 
	 * for the clearing of the entrance of the tunnel. Assigning it to
 
	 * cost before the loop will yield different costs depending on start-
 
	 * position, because of increased-cost-by-length: 'cost += cost >> 3' */
 
@@ -729,13 +729,13 @@ CommandCost CmdBuildTunnel(TileIndex sta
 

	
 
	if (tiles > _settings_game.construction.max_tunnel_length) return_cmd_error(STR_ERROR_TUNNEL_TOO_LONG);
 

	
 
	if (HasTileWaterGround(end_tile)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
 

	
 
	/* Clear the tile in any case */
 
	ret = DoCommand(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, end_tile, 0, 0);
 
	if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
 
	cost.AddCost(ret);
 

	
 
	/* slope of end tile must be complementary to the slope of the start tile */
 
	if (end_tileh != ComplementSlope(start_tileh)) {
 
		/* Mark the tile as already cleared for the terraform command.
 
@@ -761,13 +761,13 @@ CommandCost CmdBuildTunnel(TileIndex sta
 
		ClearedObjectArea *begin = _cleared_object_areas.data();
 
		assert(coa >= begin && coa < begin + _cleared_object_areas.size());
 
		size_t coa_index = coa - begin;
 
		assert(coa_index < UINT_MAX); // more than 2**32 cleared areas would be a bug in itself
 
		coa = nullptr;
 

	
 
		ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND);
 
		ret = DoCommand(flags, CMD_TERRAFORM_LAND, end_tile, end_tileh & start_tileh, 0);
 
		_cleared_object_areas[(uint)coa_index].first_tile = old_first_tile;
 
		if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
 
		cost.AddCost(ret);
 
	}
 
	cost.AddCost(_price[PR_BUILD_TUNNEL]);
 

	
 
@@ -1843,13 +1843,13 @@ static void ChangeTileOwner_TunnelBridge
 
	if (new_owner != INVALID_OWNER) {
 
		SetTileOwner(tile, new_owner);
 
	} else {
 
		if (tt == TRANSPORT_RAIL) {
 
			/* Since all of our vehicles have been removed, it is safe to remove the rail
 
			 * bridge / tunnel. */
 
			[[maybe_unused]] CommandCost ret = DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
 
			[[maybe_unused]] CommandCost ret = DoCommand(DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
			assert(ret.Succeeded());
 
		} else {
 
			/* In any other case, we can safely reassign the ownership to OWNER_NONE. */
 
			SetTileOwner(tile, OWNER_NONE);
 
		}
 
	}
 
@@ -2034,13 +2034,13 @@ static CommandCost TerraformTile_TunnelB
 
		}
 

	
 
		/* Surface slope is valid and remains unchanged? */
 
		if (res.Succeeded() && (z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
 
	}
 

	
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
}
 

	
 
extern const TileTypeProcs _tile_type_tunnelbridge_procs = {
 
	DrawTile_TunnelBridge,           // draw_tile_proc
 
	GetSlopePixelZ_TunnelBridge,     // get_slope_z_proc
 
	ClearTile_TunnelBridge,          // clear_tile_proc