add script/digfort.rb

develop
jj 2012-09-07 22:47:44 +02:00
parent e09b98216f
commit 7b86f203c3
2 changed files with 60 additions and 0 deletions

@ -1446,3 +1446,25 @@ To remove all placed sources, call ``magmasource stop``.
With no argument, this command shows an help message and list existing sources.
digfort
=========
A script to designate an area for digging according to a plan in csv format.
This script, inspired from quickfort, can designate an area for digging.
Your plan should be stored in a .csv file like this:
::
# this is a comment
d;d;u;d;d;skip this tile;d
d;d;d;i
Available tile shapes are named after the 'dig' menu shortcuts:
``d`` for dig, ``u`` for upstairs, ``d`` downstairs, ``i`` updown,
``h`` channel, ``r`` upward ramp, ``x`` remove designation.
Unrecognized characters are ignored (eg the 'skip this tile' in the sample).
Empty lines and data after a ``#`` are ignored as comments.
To skip a row in your design, use a single ``;``.
The script takes the plan filename, starting from the root df folder.

@ -0,0 +1,38 @@
# designate an area for digging according to a plan in csv format
raise "usage: digfort <plan filename>" if not $script_args[0]
planfile = File.read($script_args[0])
if df.cursor.x == -30000
raise "place the game cursor to the top-left corner of the design"
end
tiles = planfile.lines.map { |l|
l.sub(/#.*/, '').split(';').map { |t| t.strip }
}
x = x0 = df.cursor.x
y = df.cursor.y
z = df.cursor.z
tiles.each { |line|
next if line.empty? or line == ['']
line.each { |tile|
t = df.map_tile_at(x, y, z)
s = t.shape_basic
case tile
when 'd'; t.dig(:Default) if s == :Wall
when 'u'; t.dig(:UpStair) if s == :Wall
when 'j'; t.dig(:DownStair) if s == :Wall or s == :Floor
when 'i'; t.dig(:UpDownStair) if s == :Wall
when 'h'; t.dig(:Channel) if s == :Wall or s == :Floor
when 'r'; t.dig(:Ramp) if s == :Wall
when 'x'; t.dig(:No)
end
x += 1
}
x = x0
y += 1
}
puts 'done'