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