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/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) diff --git a/plugins/ruby/unit.rb b/plugins/ruby/unit.rb index 04deee0e3..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 @@ -63,11 +69,11 @@ 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' - !u.status.misc_traits.find { |t| id == :OnBreak } + not u.status.misc_traits.find { |t| t.id == :OnBreak } } end diff --git a/scripts/magmasource.rb b/scripts/magmasource.rb new file mode 100644 index 000000000..8525d51e0 --- /dev/null +++ b/scripts/magmasource.rb @@ -0,0 +1,66 @@ +# create an infinite magma source at the cursor + +$magma_sources ||= [] + +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 + 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 <