removebadthoughts: add --dry-run option
parent
b3b93f818d
commit
b5f5d1f85b
@ -1,27 +1,43 @@
|
|||||||
# remove bad thoughts for the selected unit or the whole fort
|
# remove bad thoughts for the selected unit or the whole fort
|
||||||
|
|
||||||
# with removebadthoughts -v, dump the bad thoughts types we removed
|
dry_run = $script_args.delete('--dry-run') || $script_args.delete('-n')
|
||||||
verbose = $script_args.delete('-v')
|
|
||||||
|
|
||||||
if u = df.unit_find(:selected)
|
$script_args << 'all' if dry_run and $script_args.empty?
|
||||||
targets = [u]
|
|
||||||
else
|
|
||||||
targets = df.unit_citizens
|
|
||||||
end
|
|
||||||
|
|
||||||
seenbad = Hash.new(0)
|
seenbad = Hash.new(0)
|
||||||
|
|
||||||
targets.each { |u|
|
clear_mind = lambda { |u|
|
||||||
u.status.recent_events.each { |e|
|
u.status.recent_events.each { |e|
|
||||||
next if DFHack::UnitThoughtType::Value[e.type].to_s[0, 1] != '-'
|
next if DFHack::UnitThoughtType::Value[e.type].to_s[0, 1] != '-'
|
||||||
seenbad[e.type] += 1
|
seenbad[e.type] += 1
|
||||||
e.age = 0x1000_0000
|
e.age = 0x1000_0000 unless dry_run
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if verbose
|
summary = lambda {
|
||||||
seenbad.sort_by { |k, v| v }.each { |k, v| puts " #{v} #{k}" }
|
seenbad.sort_by { |thought, cnt| cnt }.each { |thought, cnt|
|
||||||
end
|
puts " #{thought} #{cnt}"
|
||||||
|
}
|
||||||
|
count = seenbad.values.inject(0) { |sum, cnt| sum+cnt }
|
||||||
|
puts "Removed #{count} bad thought#{'s' if count != 1}." if count > 0 and not dry_run
|
||||||
|
}
|
||||||
|
|
||||||
count = seenbad.values.inject(0) { |s, v| s+v }
|
case $script_args[0]
|
||||||
puts "removed #{count} bad thought#{'s' if count != 1}"
|
when 'him'
|
||||||
|
if u = df.unit_find
|
||||||
|
clear_mind[u]
|
||||||
|
summary[]
|
||||||
|
else
|
||||||
|
puts 'Please select a dwarf ingame'
|
||||||
|
end
|
||||||
|
|
||||||
|
when 'all'
|
||||||
|
df.unit_citizens.each { |uu|
|
||||||
|
clear_mind[uu]
|
||||||
|
}
|
||||||
|
summary[]
|
||||||
|
|
||||||
|
else
|
||||||
|
puts "Usage: removebadthoughts [--dry-run] <him|all>"
|
||||||
|
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue