From 3d82629da90a6a845a0290f6f1d7280e034dbd07 Mon Sep 17 00:00:00 2001 From: jj Date: Tue, 16 Apr 2013 22:35:41 +0200 Subject: [PATCH] rename magmasource to source, add water+drain capabilities --- NEWS | 1 + Readme.rst | 33 +++++++++++------ scripts/magmasource.rb | 56 ---------------------------- scripts/source.rb | 83 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 68 deletions(-) delete mode 100644 scripts/magmasource.rb create mode 100644 scripts/source.rb diff --git a/NEWS b/NEWS index b7e9eead0..609b73a1c 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ DFHack future - exterminate: renamed from slayrace, add help message, add butcher mode - autoSyndrome: disable by default - ruby: add df.dfhack_run "somecommand" + - magmasource: rename to source, allow water/magma sources/drains DFHack v0.34.11-r3 diff --git a/Readme.rst b/Readme.rst index 657e51132..d528b525a 100644 --- a/Readme.rst +++ b/Readme.rst @@ -1890,9 +1890,10 @@ such as vampires, it also sets animal.vanish_countdown to 2. An alternate mode is selected by adding a 2nd argument to the command, ``magma``. In this case, a column of 7/7 magma is generated on top of the targets until they die (Warning: do not call on magma-safe creatures. Also, -using this mode for birds is not recommanded.) +using this mode on birds is not recommanded.) -Will target any unit on a revealed tile of the map, including ambushers. +Will target any unit on a revealed tile of the map, including ambushers, +but ignore caged/chained creatures. Ex:: @@ -1907,24 +1908,32 @@ To purify all elves on the map with fire (may have side-effects):: exterminate elve magma -magmasource -=========== -Create an infinite magma source on a tile. +source +====== +Create an infinite magma or water source or drain 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. +This script registers a map tile as a liquid source, and every 12 game ticks +that tile receives or remove 1 new unit of flow based on the configuration. 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 + source add [magma|water] [0-7] + +The number argument is the target liquid level (0 = drain, 7 = source). -To add more than 1 unit everytime, call the command again. +To add more than 1 unit everytime, call the command again on the same spot. -To delete one source, place the cursor over its tile and use ``delete-here``. -To remove all placed sources, call ``magmasource stop``. +To delete one source, place the cursor over its tile and use ``delete``. +To remove all existing sources, call ``source clear``. + +The ``list`` argument shows all existing sources. + +Ex:: -With no argument, this command shows an help message and list existing sources. + source add water - water source + source add magma 7 - magma source + source add water 0 - water drain masspit ======= diff --git a/scripts/magmasource.rb b/scripts/magmasource.rb deleted file mode 100644 index c20199c2a..000000000 --- a/scripts/magmasource.rb +++ /dev/null @@ -1,56 +0,0 @@ -# create an infinite magma source at the cursor - -$magma_sources ||= [] - -case $script_args[0] -when 'here' - $magma_onupdate ||= df.onupdate_register('magmasource', 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 tile.shape_passableflow - des = tile.designation - tile.spawn_magma(des.flow_size + 1) if des.flow_size < 7 - end - } - } - - if df.cursor.x != -30000 - if tile = df.map_tile_at(df.cursor) - if tile.shape_passableflow - $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 < 'water', + :amount => 7, + :pos => [df.cursor.x, df.cursor.y, df.cursor.z] +} +cmd = 'help' + +$script_args.each { |a| + case a.downcase + when 'water', 'magma' + cur_source[:liquid] = a.downcase + when /^\d+$/ + cur_source[:amount] = a.to_i + when 'add', 'del', 'delete', 'clear', 'help', 'list' + cmd = a.downcase + else + puts "source: unhandled argument #{a}" + end +} + +case cmd +when 'add' + $sources_onupdate ||= df.onupdate_register('sources', 12) { + # called every 12 game ticks (100x a dwarf day) + $sources.each { |s| + if tile = df.map_tile_at(*s[:pos]) and tile.shape_passableflow + # XXX does not check current liquid_type + des = tile.designation + cur = des.flow_size + if cur != s[:amount] + tile.spawn_liquid((cur > s[:amount] ? cur-1 : cur+1), s[:liquid] == 'magma') + end + end + } + if $sources.empty? + df.onupdate_unregister($sources_onupdate) + $sources_onupdate = nil + end + } + + if cur_source[:pos][0] >= 0 + if tile = df.map_tile_at(*cur_source[:pos]) + if tile.shape_passableflow + $sources << cur_source + 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 source" + end + +when 'del', 'delete' + $sources.delete_if { |s| s[:pos] == cur_source[:pos] } + +when 'clear' + $sources.clear + +when 'list' + puts "Source list:", $sources.map { |s| + " #{s[:pos].inspect} #{s[:liquid]} #{s[:amount]}" + } + puts "Current cursor pos: #{[df.cursor.x, df.cursor.y, df.cursor.z].inspect}" if df.cursor.x >= 0 + +else + puts <