# scan the map for ore veins target_ore = $script_args[0] def find_all_ore_veins $ore_veins = {} seen_mat = {} df.each_map_block { |block| block.block_events.grep(DFHack::BlockSquareEventMineralst).each { |vein| mat_index = vein.inorganic_mat if not seen_mat[mat_index] or $ore_veins[mat_index] seen_mat[mat_index] = true if df.world.raws.inorganics[mat_index].flags[:METAL_ORE] $ore_veins[mat_index] ||= [] $ore_veins[mat_index] << [block.map_pos.x, block.map_pos.y, block.map_pos.z] end end } } df.onstatechange_register_once { |st| if st == :MAP_LOADED $ore_veins = nil # invalidate veins cache true end } $ore_veins end $ore_veins ||= find_all_ore_veins if not target_ore or target_ore == 'help' puts < 0 and bx+dx < df.world.map.x_count-1 and by+dy > 0 and by+dy < df.world.map.y_count-1 pos = [bx+dx, by+dy, bz] end } } } } df.center_viewscreen(*pos) df.map_tile_at(*pos).dig puts "Here is some #{df.world.raws.inorganics[found_mat].id}" else puts "Cannot find unmined #{mats.map { |mat| df.world.raws.inorganics[mat].id }.join(', ')}" end else puts "Available ores:", $ore_veins.sort_by { |mat, pos| pos.length }.map { |mat, pos| ore = df.world.raws.inorganics[mat] metals = ore.metal_ore.mat_index.map { |m| df.world.raws.inorganics[m] } ' ' + ore.id.downcase + ' (' + metals.map { |m| m.id.downcase }.join(', ') + ')' } end