Extended lever.rb a bit

Added names to the lever list, and `lever pull` without any arguments now pulls the lever under the cursor.
develop
Michon van Dooren 2015-07-15 21:40:14 +02:00 committed by lethosor
parent a8bea3684a
commit 237ce2c539
1 changed files with 14 additions and 6 deletions

@ -32,7 +32,7 @@ def lever_descr(bld, idx=nil)
# lever description # lever description
descr = '' descr = ''
descr << "#{idx}: " if idx descr << "#{idx}: " if idx
descr << "lever ##{bld.id} @[#{bld.centerx}, #{bld.centery}, #{bld.z}] #{bld.state == 0 ? '\\' : '/'}" descr << "lever ##{bld.id} (#{bld.name}) @[#{bld.centerx}, #{bld.centery}, #{bld.z}] #{bld.state == 0 ? '\\' : '/'}"
bld.jobs.each { |j| bld.jobs.each { |j|
if j.job_type == :PullLever if j.job_type == :PullLever
flags = '' flags = ''
@ -82,10 +82,15 @@ case $script_args[0]
when 'pull' when 'pull'
cheat = $script_args.delete('--cheat') || $script_args.delete('--now') cheat = $script_args.delete('--cheat') || $script_args.delete('--now')
id = $script_args[1].to_i if $script_args[1].nil?
id = @lever_list[id] || id bld = df.building_find(:selected) if not bld
bld = df.building_find(id) raise 'no lever under cursor and no lever id given' if not bld
raise 'invalid lever id' if not bld else
id = $script_args[1].to_i
id = @lever_list[id] || id
bld = df.building_find(id)
raise 'invalid lever id' if not bld
end
if cheat if cheat
lever_pull_cheat(bld) lever_pull_cheat(bld)
@ -111,7 +116,10 @@ Lever control from the dfhack console
Usage: Usage:
lever list lever list
shows the list of levers in the fortress, with their id and links shows the list of levers in the fortress, with their id, name and links
lever pull
order the dwarves to pull the lever under the cursor
lever pull 42 lever pull 42
order the dwarves to pull lever 42 order the dwarves to pull lever 42