From a7bd2e97ab5a1131fbc6d96b9a06d5b2497720d0 Mon Sep 17 00:00:00 2001 From: jj Date: Sun, 31 Mar 2013 16:12:42 +0200 Subject: [PATCH] add scripts/locate-ore --- NEWS | 1 + Readme.rst | 14 ++++++++ scripts/locate-ore.rb | 83 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 scripts/locate-ore.rb diff --git a/NEWS b/NEWS index 85bc33948..3b2059f05 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ DFHack future New scripts: - masspit: designate caged creatures in a zone for pitting + - locate_ore: scan the map for unmined ore veins Misc improvements: - exterminate: renamed from slayrace, add help message - autoSyndrome: disable by default diff --git a/Readme.rst b/Readme.rst index 793036a06..5832e111d 100644 --- a/Readme.rst +++ b/Readme.rst @@ -2065,6 +2065,20 @@ Exemples:: create-items bar CREATURE:CAT:SOAP create-items bar adamantine +locate-ore +========== +Scan the map for metal ores. + +Finds and designate for digging one tile of a specific metal ore. +Only works for native metal ores, does not handle reaction stuff (eg STEEL). + +When invoked with the ``list`` argument, lists metal ores available on the map. + +Exemples:: + locate-ore list + locate-ore hematite + locate-ore iron + soundsense-season ================= diff --git a/scripts/locate-ore.rb b/scripts/locate-ore.rb new file mode 100644 index 000000000..1c282f7d8 --- /dev/null +++ b/scripts/locate-ore.rb @@ -0,0 +1,83 @@ +# 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