From dcc9498dbc9e7bf5c477af28659aac2aac58b525 Mon Sep 17 00:00:00 2001 From: jj Date: Sat, 1 Sep 2012 02:55:55 +0200 Subject: [PATCH] ruby: tweak apis --- plugins/ruby/building.rb | 8 +++++--- plugins/ruby/plant.rb | 12 ++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/ruby/building.rb b/plugins/ruby/building.rb index af152e198..cb435b9d5 100644 --- a/plugins/ruby/building.rb +++ b/plugins/ruby/building.rb @@ -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) diff --git a/plugins/ruby/plant.rb b/plugins/ruby/plant.rb index 5d6b9d724..2f5a1c7c4 100644 --- a/plugins/ruby/plant.rb +++ b/plugins/ruby/plant.rb @@ -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