So, as a challenge to myself, I decided I'd tackle making automated circles in DF on Ubuntu linux.
At this point, I have a little system set up that asks for a radius, and a number of layers, then automatically draws a cylinder with whatever designation you have selected.
So... at this point, the only other thing I have planned to add is drawing spheres... maybe I'll get to it... we'll see.
Anyhow, here's what you'll need:
my script (included below)
xte (included in Ubuntu... not sure otherwise)
xbindkeys (in the repositories)
xbindkeys RC file (included below)
bc (command line calculator... again, included with Ubuntu)
some understanding of the command line
got all that? okay. here's how you set it all up:
copy the scirpt, put it in your home directory and name it query.sh. Make sure it's marked as executable
copy the xbindkeys RC file to your home directory, name the file .xbindkeysrc
open a terminal and run: xbindkeys (it will run, and return to the command line. Don't worry, it starts a daemon)
open up a DF game, and put the cursor where you'd like your shiny new circle
select the designation tool you'd like to use (don't hit enter, just make sure you have the right designator selected)
hit 'F12'... you will be queried for input
select 'cylinder' (or however I spelled it... :p)
once you've entered the radius and number of layers, sit back and wait! (don't touch anything... It'll push the input to whatever the active window is... could cause FUN)
Enjoy! Please let me know if you have any questions!!
So.... next, here is the .xbindkeysrc file:
# bind F12 press to run the query script for dwarf fortress circle generation
"/home/ben/query.sh"
m:0x0 + c:96
and here is the query.sh file:
#!/bin/bash
dig_start () { `xte 'key d' 'key d'`; }
dig_end () { `xte 'key Escape' 'key Escape'`; }
dig ()
{
`xte 'key Return'`
`xte 'key Return'`
}
tick_left () { `xte 'key Left'`; }
tick_right () { `xte 'key Right'`; }
tick_up () { `xte 'key Up'`; }
tick_down () { `xte 'key Down'`; }
jump_left () { `xte 'keydown Shift_L' 'key Left' 'keyup Shift_L'`; }
jump_right () { `xte 'keydown Shift_L' 'key Right' 'keyup Shift_L'`; }
jump_up () { `xte 'keydown Shift_L' 'key Up' 'keyup Shift_L'`; }
jump_down () { `xte 'keydown Shift_L' 'key Down' 'keyup Shift_L'`; }
layer_down () { `xte 'str >'`; }
layer_up () { `xte 'str <'`; }
move_left ()
{
MOVE=$1
while [ $MOVE -gt 0 ]; do
if [ $MOVE -ge 10 ]; then
jump_left
MOVE=$(( $MOVE - 10 ))
else
tick_left
MOVE=$(( $MOVE - 1 ))
fi
done
}
move_right ()
{
MOVE=$1
while [ $MOVE -gt 0 ]; do
if [ $MOVE -ge 10 ]; then
jump_right
MOVE=$(( $MOVE - 10 ))
else
tick_right
MOVE=$(( $MOVE - 1 ))
fi
done
}
move_up ()
{
MOVE=$1
echo $MOVE
while [ $MOVE -gt 0 ]; do
if [ $MOVE -ge 10 ]; then
jump_up
MOVE=$(( $MOVE - 10 ))
else
tick_up
MOVE=$(( $MOVE - 1 ))
fi
done
}
move_down ()
{
MOVE=$1
while [ $MOVE -gt 0 ]; do
if [ $MOVE -ge 10 ]; then
jump_down
MOVE=$(( $MOVE - 10 ))
else
tick_down
MOVE=$(( $MOVE - 1 ))
fi
done
}
TYPE="null"
if `zenity --question --text="Sphere or Cylinder?" --ok-label="Sphere" --cancel-label="Cylinder"`
then
TYPE="0"
else
TYPE="1"
fi
RADIUS=`zenity --entry --text="Enter Radius"`
if [ $TYPE = "1" ]; then
LAYERS=`zenity --entry --text="How many Z-layers?"`
fi
echo $TYPE
echo $RADIUS
echo $LAYERS
# current position of the cursor
X_POS=$RADIUS
Y_POS=$RADIUS
# select the DIG designation menu
#dig_start
#cursor is center of circle, so move up rad, left rad
move_up $RADIUS
move_left $RADIUS
# loop over z layers
while [ $LAYERS -gt 0 ]; do
echo "Layer: $LAYERS, Y: $Y_POS, X: $X_POS"
# loop over Y lines
while [ $Y_POS -ge $(( -1 * $RADIUS )) ]; do
# loop over X positions
while [ $X_POS -ge $(( -1 * $RADIUS)) ]; do
# calc distance from center
DIST=`echo "sqrt($X_POS*$X_POS + $Y_POS*$Y_POS+1)" | bc`
# if distance < rad
if [ $DIST -le $RADIUS ];
then
dig
fi
#advance one position
tick_right
X_POS=$(( $X_POS - 1 ))
done
# reset colum and move down one row
tick_down
move_left $((2*RADIUS+1))
echo ""
Y_POS=$(( $Y_POS - 1 ))
X_POS=$(( $RADIUS ))
done
# reset to first row and move down one layer
if [ $LAYERS -ne 1 ]
then
layer_down
fi
move_up $((2*RADIUS+1))
Y_POS=$RADIUS
LAYERS=$(( $LAYERS - 1 ))
done
# recenter the cursor
move_down $RADIUS
move_right $RADIUS