Merge branch 'master' of https://github.com/jjyg/dfhack
commit
dd268d43d9
@ -1,58 +1,39 @@
|
|||||||
class AutoUnsuspend
|
class AutoUnsuspend
|
||||||
|
attr_accessor :running
|
||||||
|
|
||||||
def initialize
|
def process
|
||||||
end
|
count = 0
|
||||||
|
df.world.job_list.each { |job|
|
||||||
def process
|
if job.job_type == :ConstructBuilding and job.flags.suspend and df.map_tile_at(job).designation.flow_size <= 1
|
||||||
return false unless @running
|
job.flags.suspend = false
|
||||||
joblist = df.world.job_list.next
|
count += 1
|
||||||
count = 0
|
end
|
||||||
|
}
|
||||||
|
if count > 0
|
||||||
|
puts "Unsuspended #{count} job(s)."
|
||||||
|
df.process_jobs = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
while joblist
|
def start
|
||||||
job = joblist.item
|
@running = true
|
||||||
joblist = joblist.next
|
@onupdate = df.onupdate_register('autounsuspend', 5) { process if @running }
|
||||||
|
end
|
||||||
if job.job_type == :ConstructBuilding
|
|
||||||
if (job.flags.suspend)
|
|
||||||
item = job.items[0].item
|
|
||||||
job.flags.suspend = false
|
|
||||||
count += 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
puts "Unsuspended #{count} job(s)." unless count == 0
|
def stop
|
||||||
|
@running = false
|
||||||
end
|
df.onupdate_unregister(@onupdate)
|
||||||
|
end
|
||||||
def start
|
end
|
||||||
@onupdate = df.onupdate_register('autounsuspend', 5) { process }
|
|
||||||
@running = true
|
|
||||||
end
|
|
||||||
|
|
||||||
def stop
|
|
||||||
df.onupdate_unregister(@onupdate)
|
|
||||||
@running = false
|
|
||||||
end
|
|
||||||
|
|
||||||
def status
|
|
||||||
@running ? 'Running.' : 'Stopped.'
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
case $script_args[0]
|
case $script_args[0]
|
||||||
when 'start'
|
when 'start'
|
||||||
$AutoUnsuspend = AutoUnsuspend.new unless $AutoUnsuspend
|
$AutoUnsuspend ||= AutoUnsuspend.new
|
||||||
$AutoUnsuspend.start
|
$AutoUnsuspend.start
|
||||||
|
|
||||||
when 'end', 'stop'
|
when 'end', 'stop'
|
||||||
$AutoUnsuspend.stop
|
$AutoUnsuspend.stop
|
||||||
|
|
||||||
else
|
else
|
||||||
if $AutoUnsuspend
|
puts $AutoUnsuspend && $AutoUnsuspend.running ? 'Running.' : 'Stopped.'
|
||||||
puts $AutoUnsuspend.status
|
|
||||||
else
|
|
||||||
puts 'Not loaded.'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue