autounsuspend: check water level, make df recheck jobs on unsuspend

develop
jj 2014-02-27 17:38:34 +01:00
parent 3cd0c3aad0
commit 2e680c4c2c
1 changed files with 26 additions and 45 deletions

@ -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