diff options
| author | jj | 2012-09-18 18:13:22 +0200 |
|---|---|---|
| committer | jj | 2012-09-18 18:13:22 +0200 |
| commit | b470abed904f31aa3c886ffc47e84d0f14322a58 (patch) | |
| tree | aacbeb29300953ed30b645633112f2b4e4d751f4 /plugins/ruby | |
| parent | cc4639aad033625a8390d4114e9f26193acd4477 (diff) | |
| download | dfhack-b470abed904f31aa3c886ffc47e84d0f14322a58.tar.gz dfhack-b470abed904f31aa3c886ffc47e84d0f14322a58.tar.bz2 dfhack-b470abed904f31aa3c886ffc47e84d0f14322a58.tar.xz | |
ruby: misc tweaks
Diffstat (limited to 'plugins/ruby')
| -rw-r--r-- | plugins/ruby/building.rb | 12 | ||||
| -rw-r--r-- | plugins/ruby/ruby-autogen-defs.rb | 3 | ||||
| -rw-r--r-- | plugins/ruby/ruby.rb | 8 | ||||
| -rw-r--r-- | plugins/ruby/unit.rb | 2 |
4 files changed, 17 insertions, 8 deletions
diff --git a/plugins/ruby/building.rb b/plugins/ruby/building.rb index 10c8fcd9..d88bbfc6 100644 --- a/plugins/ruby/building.rb +++ b/plugins/ruby/building.rb @@ -178,7 +178,17 @@ module DFHack # set building at position, with optional width/height def building_position(bld, pos, w=nil, h=nil) - x, y, z = (pos.respond_to?(:x) ? [pos.x, pos.y, pos.z] : pos) + if pos.respond_to?(:x1) + x, y, z = pos.x1, pos.y1, pos.z + w ||= pos.x2-pos.x1+1 if pos.respond_to?(:x2) + h ||= pos.y2-pos.y1+1 if pos.respond_to?(:y2) + elsif pos.respond_to?(:x) + x, y, z = pos.x, pos.y, pos.z + else + x, y, z = pos + end + w ||= pos.w if pos.respond_to?(:w) + h ||= pos.h if pos.respond_to?(:h) bld.x1 = x bld.y1 = y bld.z = z diff --git a/plugins/ruby/ruby-autogen-defs.rb b/plugins/ruby/ruby-autogen-defs.rb index 1ddf25a9..4614d178 100644 --- a/plugins/ruby/ruby-autogen-defs.rb +++ b/plugins/ruby/ruby-autogen-defs.rb @@ -124,8 +124,7 @@ module DFHack case h when Hash; h.each { |k, v| send("#{k}=", v) } when Array; names = _field_names ; raise 'bad size' if names.length != h.length ; names.zip(h).each { |n, a| send("#{n}=", a) } - when Compound; _field_names.each { |n| send("#{n}=", h.send(n)) } - else raise 'wut?' + else _field_names.each { |n| send("#{n}=", h.send(n)) } end end def _fields ; self.class._fields.to_a ; end diff --git a/plugins/ruby/ruby.rb b/plugins/ruby/ruby.rb index 8c2c9796..ef6af04e 100644 --- a/plugins/ruby/ruby.rb +++ b/plugins/ruby/ruby.rb @@ -25,11 +25,11 @@ end module DFHack class OnupdateCallback attr_accessor :callback, :timelimit, :minyear, :minyeartick - def initialize(cb, tl) + def initialize(cb, tl, initdelay=0) @callback = cb @ticklimit = tl @minyear = (tl ? df.cur_year : 0) - @minyeartick = (tl ? df.cur_year_tick : 0) + @minyeartick = (tl ? df.cur_year_tick+initdelay : 0) end # run callback if timedout @@ -61,9 +61,9 @@ module DFHack # register a callback to be called every gframe or more # ex: DFHack.onupdate_register { DFHack.world.units[0].counters.job_counter = 0 } - def onupdate_register(ticklimit=nil, &b) + def onupdate_register(ticklimit=nil, initialtickdelay=0, &b) @onupdate_list ||= [] - @onupdate_list << OnupdateCallback.new(b, ticklimit) + @onupdate_list << OnupdateCallback.new(b, ticklimit, initialtickdelay) DFHack.onupdate_active = true if onext = @onupdate_list.sort.first DFHack.onupdate_minyear = onext.minyear diff --git a/plugins/ruby/unit.rb b/plugins/ruby/unit.rb index f0eeb138..5289229a 100644 --- a/plugins/ruby/unit.rb +++ b/plugins/ruby/unit.rb @@ -49,7 +49,7 @@ module DFHack end def unit_iscitizen(u) - u.race == ui.race_id and u.civ_id == ui.civ_id and !u.flags1.dead and !u.flags1.merchant and + u.race == ui.race_id and u.civ_id == ui.civ_id and !u.flags1.dead and !u.flags1.merchant and !u.flags1.forest and !u.flags1.diplomat and !u.flags2.resident and !u.flags3.ghostly and !u.curse.add_tags1.OPPOSED_TO_LIFE and !u.curse.add_tags1.CRAZED and u.mood != :Berserk |
