From b0edb330233e7a5ae0db9f079ad5db487eabcd20 Mon Sep 17 00:00:00 2001 From: jj Date: Wed, 11 Jul 2012 23:24:53 +0200 Subject: [PATCH 1/5] ruby: fix unit_idlers --- plugins/ruby/unit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ruby/unit.rb b/plugins/ruby/unit.rb index 04deee0e3..5b279d0d1 100644 --- a/plugins/ruby/unit.rb +++ b/plugins/ruby/unit.rb @@ -63,7 +63,7 @@ module DFHack # current_job includes eat/drink/sleep/pickupequip !u.job.current_job and # filter 'attend meeting' - u.meetings.length == 0 and + not u.specific_refs.find { |s| s.type == :ACTIVITY } and # filter soldiers (TODO check schedule) u.military.squad_index == -1 and # filter 'on break' From d8e55196c265e457ca47c5117be8abd493e907ac Mon Sep 17 00:00:00 2001 From: jj Date: Wed, 11 Jul 2012 23:25:55 +0200 Subject: [PATCH 2/5] ruby: better handling of errors in onupdate callbacks --- plugins/ruby/ruby.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/ruby/ruby.rb b/plugins/ruby/ruby.rb index 5ae63ebfe..8c2c97969 100644 --- a/plugins/ruby/ruby.rb +++ b/plugins/ruby/ruby.rb @@ -38,15 +38,17 @@ module DFHack @callback.call else if year > @minyear or (year == @minyear and yeartick >= @minyeartick) - @callback.call @minyear = year @minyeartick = yeartick + @ticklimit if @minyeartick > yearlen @minyear += 1 @minyeartick -= yearlen end + @callback.call end end + rescue + puts_err "onupdate cb #$!", $!.backtrace end def <=>(o) From 0615a27663adb72990abc9e3084b09df552a35bc Mon Sep 17 00:00:00 2001 From: jj Date: Thu, 12 Jul 2012 00:44:07 +0200 Subject: [PATCH 3/5] ruby: refix unit_idlers, make unit_find handle 'u'nitlist viewscreen --- plugins/ruby/unit.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/ruby/unit.rb b/plugins/ruby/unit.rb index 5b279d0d1..ebcf249da 100644 --- a/plugins/ruby/unit.rb +++ b/plugins/ruby/unit.rb @@ -6,9 +6,15 @@ module DFHack # with an argument that respond to x/y/z (eg cursor), find first unit at this position def unit_find(what=:selected, y=nil, z=nil) if what == :selected - if curview._rtti_classname == :viewscreen_itemst + case curview._rtti_classname + when :viewscreen_itemst ref = curview.entry_ref[curview.cursor_pos] ref.unit_tg if ref.kind_of?(GeneralRefUnit) + when :viewscreen_unitlistst + v = curview + # TODO fix xml to use enums everywhere + page = DFHack::ViewscreenUnitlistst_TPage.int(v.page) + v.units[page][v.cursor_pos[page]] else case ui.main.mode when :ViewUnits @@ -67,7 +73,7 @@ module DFHack # filter soldiers (TODO check schedule) u.military.squad_index == -1 and # filter 'on break' - !u.status.misc_traits.find { |t| id == :OnBreak } + not u.status.misc_traits.find { |t| t.id == :OnBreak } } end From c823f1273737a18bf0df9720c287c30bb9f5623c Mon Sep 17 00:00:00 2001 From: jj Date: Thu, 12 Jul 2012 14:35:49 +0200 Subject: [PATCH 4/5] add scripts/magmasource to generate an infinite magma source --- scripts/magmasource.rb | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 scripts/magmasource.rb diff --git a/scripts/magmasource.rb b/scripts/magmasource.rb new file mode 100644 index 000000000..14f517fd1 --- /dev/null +++ b/scripts/magmasource.rb @@ -0,0 +1,65 @@ +# create an infinite magma source at the cursor + +$magma_sources ||= [] +$magma_onupdate ||= nil + +case $script_args[0] +when 'here' + $magma_onupdate ||= df.onupdate_register(12) { + 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 DFHack::TiletypeShape::PassableFlow[tile.shape] + des = tile.designation + des.flow_size += 1 if des.flow_size < 7 + des.liquid_type = 1 + des.flow_forbid = true + + mf = tile.mapblock.flags + mf.update_liquid = true + mf.update_liquid_twice = true + + zf = df.world.map.z_level_flags[z] + zf.update = true + zf.update_twice = true + end + } + } + + if df.cursor.x != -30000 + if tile = df.map_tile_at(df.cursor) + if DFHack::TiletypeShape::PassableFlow[tile.shape] + $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 < Date: Thu, 12 Jul 2012 14:50:59 +0200 Subject: [PATCH 5/5] magmasource: add documentation --- README.rst | 24 ++++++++++++++++++++---- scripts/magmasource.rb | 7 ++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 9543e63a0..724fa1fa3 100644 --- a/README.rst +++ b/README.rst @@ -1377,8 +1377,6 @@ For exemple, to grow 40 plump helmet spawn: growcrops plump 40 -This is a ruby script and needs the ruby plugin. - removebadthoughts ================= @@ -1396,8 +1394,6 @@ you unpause. With the optional ``-v`` parameter, the script will dump the negative thoughts it removed. -This is a ruby script and needs the ruby plugin. - slayrace ======== @@ -1418,3 +1414,23 @@ after selecting the unit with the 'v' cursor: :: rb_eval df.unit_find.body.blood_count = 0 + +magmasource +=========== +Create an infinite magma source on a tile. + +This script registers a map tile as a magma source, and every 12 game ticks +that tile receives 1 new unit of flowing magma. + +Place the game cursor where you want to create the source (must be a +flow-passable tile, and not too high in the sky) and call +:: + magmasource here + +To add more than 1 unit everytime, call the command again. + +To delete one source, place the cursor over its tile and use ``delete-here``. +To remove all placed sources, call ``magmasource stop``. + +With no argument, this command shows an help message and list existing sources. + diff --git a/scripts/magmasource.rb b/scripts/magmasource.rb index 14f517fd1..8525d51e0 100644 --- a/scripts/magmasource.rb +++ b/scripts/magmasource.rb @@ -1,11 +1,11 @@ # create an infinite magma source at the cursor $magma_sources ||= [] -$magma_onupdate ||= nil case $script_args[0] when 'here' $magma_onupdate ||= df.onupdate_register(12) { + # called every 12 game ticks (100x a dwarf day) if $magma_sources.empty? df.onupdate_unregister($magma_onupdate) $magma_onupdate = nil @@ -52,14 +52,15 @@ when 'stop' else puts <