ruby: tweak apis

develop
jj 2012-09-01 02:55:55 +02:00
parent ce608e4f6a
commit dcc9498dbc
2 changed files with 11 additions and 9 deletions

@ -46,6 +46,7 @@ module DFHack
raise "invalid building type #{type.inspect}" if not cls
bld = cls.cpp_new
bld.race = ui.race_id
subtype = WorkshopType.int(subtype) if subtype.kind_of?(::Symbol) and type == :Workshop
bld.setSubtype(subtype) if subtype != -1
bld.setCustomType(custom) if custom != -1
case type
@ -176,9 +177,10 @@ module DFHack
# set building at position, with optional width/height
def building_position(bld, pos, w=nil, h=nil)
bld.x1 = pos.x
bld.y1 = pos.y
bld.z = pos.z
x, y, z = (pos.respond_to?(:x) ? [pos.x, pos.y, pos.z] : pos)
bld.x1 = x
bld.y1 = y
bld.z = z
bld.x2 = bld.x1+w-1 if w
bld.y2 = bld.y1+h-1 if h
building_setsize(bld)

@ -51,7 +51,7 @@ module DFHack
end
SaplingToTreeAge = 120960
def cuttrees(material=nil, count_max=100)
def cuttrees(material=nil, count_max=100, quiet=false)
if !material
# list trees
cnt = Hash.new(0)
@ -62,7 +62,7 @@ module DFHack
}
cnt.sort_by { |mat, c| c }.each { |mat, c|
name = @raws_tree_name[mat]
puts " #{name} #{c}"
puts " #{name} #{c}" unless quiet
}
else
cnt = 0
@ -78,11 +78,11 @@ module DFHack
break if cnt == count_max
end
}
puts "Updated #{cnt} plant designations"
puts "Updated #{cnt} plant designations" unless quiet
end
end
def growtrees(material=nil, count_max=100)
def growtrees(material=nil, count_max=100, quiet=false)
if !material
# list plants
cnt = Hash.new(0)
@ -93,7 +93,7 @@ module DFHack
}
cnt.sort_by { |mat, c| c }.each { |mat, c|
name = @raws_tree_name[mat]
puts " #{name} #{c}"
puts " #{name} #{c}" unless quiet
}
else
cnt = 0
@ -104,7 +104,7 @@ module DFHack
cnt += 1
break if cnt == count_max
}
puts "Grown #{cnt} saplings"
puts "Grown #{cnt} saplings" unless quiet
end
end
end