develop
commit
df6355a092
@ -0,0 +1,10 @@
|
||||
# list indexes in world.item.other[] where current selected item appears
|
||||
|
||||
tg = df.item_find
|
||||
raise 'select an item' if not tg
|
||||
|
||||
o = df.world.items.other
|
||||
# discard ANY/BAD
|
||||
o._indexenum::ENUM.sort.transpose[1][1..-2].each { |k|
|
||||
puts k if o[k].find { |i| i == tg }
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
# unforbid all items
|
||||
|
||||
df.world.items.all.each { |i| i.flags.forbid = false }
|
@ -0,0 +1,84 @@
|
||||
# scan the map for ore veins
|
||||
|
||||
target_ore = $script_args[0]
|
||||
|
||||
def find_all_ore_veins
|
||||
puts 'scanning map...'
|
||||
$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 <<EOS
|
||||
Scan the map to find one random tile of unmined ore.
|
||||
It will center the game view on that tile and mark it for digging.
|
||||
Only works with metal ores.
|
||||
|
||||
Usage:
|
||||
locate_ore list list all existing vein materials (including mined ones)
|
||||
locate_ore hematite find one tile of unmined hematite ore
|
||||
locate_ore iron find one tile of unmined ore you can smelt into iron
|
||||
EOS
|
||||
|
||||
elsif target_ore and mats = $ore_veins.keys.find_all { |k|
|
||||
ino = df.world.raws.inorganics[k]
|
||||
ino.id =~ /#{target_ore}/i or ino.metal_ore.mat_index.find { |m|
|
||||
df.world.raws.inorganics[m].id =~ /#{target_ore}/i
|
||||
}
|
||||
} and not mats.empty?
|
||||
pos = nil
|
||||
dxs = (0..15).sort_by { rand }
|
||||
dys = (0..15).sort_by { rand }
|
||||
if found_mat = mats.sort_by { rand }.find { |mat|
|
||||
$ore_veins[mat].sort_by { rand }.find { |bx, by, bz|
|
||||
dys.find { |dy|
|
||||
dxs.find { |dx|
|
||||
tile = df.map_tile_at(bx+dx, by+dy, bz)
|
||||
if tile.tilemat == :MINERAL and tile.designation.dig == :No and tile.shape == :WALL and
|
||||
tile.mat_index_vein == mat and
|
||||
# ignore map borders
|
||||
bx+dx > 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
|
@ -1,56 +0,0 @@
|
||||
# create an infinite magma source at the cursor
|
||||
|
||||
$magma_sources ||= []
|
||||
|
||||
case $script_args[0]
|
||||
when 'here'
|
||||
$magma_onupdate ||= df.onupdate_register('magmasource', 12) {
|
||||
# called every 12 game ticks (100x a dwarf day)
|
||||
if $magma_sources.empty?
|
||||
df.onupdate_unregister($magma_onupdate)
|
||||
$magma_onupdate = nil
|
||||
end
|
||||
|
||||
$magma_sources.each { |x, y, z|
|
||||
if tile = df.map_tile_at(x, y, z) and tile.shape_passableflow
|
||||
des = tile.designation
|
||||
tile.spawn_magma(des.flow_size + 1) if des.flow_size < 7
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
if df.cursor.x != -30000
|
||||
if tile = df.map_tile_at(df.cursor)
|
||||
if tile.shape_passableflow
|
||||
$magma_sources << [df.cursor.x, df.cursor.y, df.cursor.z]
|
||||
else
|
||||
puts "Impassable tile: I'm afraid I can't do that, Dave"
|
||||
end
|
||||
else
|
||||
puts "Unallocated map block - build something here first"
|
||||
end
|
||||
else
|
||||
puts "Please put the game cursor where you want a magma source"
|
||||
end
|
||||
|
||||
when 'delete-here'
|
||||
$magma_sources.delete [df.cursor.x, df.cursor.y, df.cursor.z]
|
||||
|
||||
when 'stop'
|
||||
$magma_sources.clear
|
||||
|
||||
else
|
||||
puts <<EOS
|
||||
Creates a new infinite magma source at the cursor.
|
||||
|
||||
Arguments:
|
||||
here - create a new source at the current cursor position
|
||||
(call multiple times for higher flow)
|
||||
delete-here - delete the source under the cursor
|
||||
stop - delete all created magma sources
|
||||
EOS
|
||||
|
||||
if $magma_sources.first
|
||||
puts '', 'Current magma sources:', $magma_sources.map { |s| " #{s.inspect}" }
|
||||
end
|
||||
end
|
@ -0,0 +1,4 @@
|
||||
# run many dfhack commands separated by ;
|
||||
# ex: multicmd locate-ore IRON ; digv ; digcircle 16
|
||||
|
||||
$script_args.join(' ').split(/\s*;\s*/).each { |cmd| df.dfhack_run cmd }
|
@ -0,0 +1,83 @@
|
||||
# create an infinite magma/water source/drain at the cursor
|
||||
|
||||
$sources ||= []
|
||||
|
||||
cur_source = {
|
||||
:liquid => 'water',
|
||||
:amount => 7,
|
||||
:pos => [df.cursor.x, df.cursor.y, df.cursor.z]
|
||||
}
|
||||
cmd = 'help'
|
||||
|
||||
$script_args.each { |a|
|
||||
case a.downcase
|
||||
when 'water', 'magma'
|
||||
cur_source[:liquid] = a.downcase
|
||||
when /^\d+$/
|
||||
cur_source[:amount] = a.to_i
|
||||
when 'add', 'del', 'delete', 'clear', 'help', 'list'
|
||||
cmd = a.downcase
|
||||
else
|
||||
puts "source: unhandled argument #{a}"
|
||||
end
|
||||
}
|
||||
|
||||
case cmd
|
||||
when 'add'
|
||||
$sources_onupdate ||= df.onupdate_register('sources', 12) {
|
||||
# called every 12 game ticks (100x a dwarf day)
|
||||
$sources.each { |s|
|
||||
if tile = df.map_tile_at(*s[:pos]) and tile.shape_passableflow
|
||||
# XXX does not check current liquid_type
|
||||
des = tile.designation
|
||||
cur = des.flow_size
|
||||
if cur != s[:amount]
|
||||
tile.spawn_liquid((cur > s[:amount] ? cur-1 : cur+1), s[:liquid] == 'magma')
|
||||
end
|
||||
end
|
||||
}
|
||||
if $sources.empty?
|
||||
df.onupdate_unregister($sources_onupdate)
|
||||
$sources_onupdate = nil
|
||||
end
|
||||
}
|
||||
|
||||
if cur_source[:pos][0] >= 0
|
||||
if tile = df.map_tile_at(*cur_source[:pos])
|
||||
if tile.shape_passableflow
|
||||
$sources << cur_source
|
||||
else
|
||||
puts "Impassable tile: I'm afraid I can't do that, Dave"
|
||||
end
|
||||
else
|
||||
puts "Unallocated map block - build something here first"
|
||||
end
|
||||
else
|
||||
puts "Please put the game cursor where you want a source"
|
||||
end
|
||||
|
||||
when 'del', 'delete'
|
||||
$sources.delete_if { |s| s[:pos] == cur_source[:pos] }
|
||||
|
||||
when 'clear'
|
||||
$sources.clear
|
||||
|
||||
when 'list'
|
||||
puts "Source list:", $sources.map { |s|
|
||||
" #{s[:pos].inspect} #{s[:liquid]} #{s[:amount]}"
|
||||
}
|
||||
puts "Current cursor pos: #{[df.cursor.x, df.cursor.y, df.cursor.z].inspect}" if df.cursor.x >= 0
|
||||
|
||||
else
|
||||
puts <<EOS
|
||||
Creates a new infinite liquid source at the cursor.
|
||||
|
||||
Examples:
|
||||
source add water - create a water source under cursor
|
||||
source add water 0 - create a water drain
|
||||
source add magma 5 - create a magma source, up to 5/7 deep
|
||||
source delete - delete source under cursor
|
||||
source clear - remove all sources
|
||||
source list
|
||||
EOS
|
||||
end
|
Loading…
Reference in New Issue