Merge remote-tracking branch 'kmartin/master'
commit
adfb307942
@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
summary = lambda {
|
||||||
|
seenbad.sort_by { |thought, cnt| cnt }.each { |thought, cnt|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
if verbose
|
case $script_args[0]
|
||||||
seenbad.sort_by { |k, v| v }.each { |k, v| puts " #{v} #{k}" }
|
when 'him'
|
||||||
|
if u = df.unit_find
|
||||||
|
clear_mind[u]
|
||||||
|
summary[]
|
||||||
|
else
|
||||||
|
puts 'Please select a dwarf ingame'
|
||||||
end
|
end
|
||||||
|
|
||||||
count = seenbad.values.inject(0) { |s, v| s+v }
|
when 'all'
|
||||||
puts "removed #{count} bad thought#{'s' if count != 1}"
|
df.unit_citizens.each { |uu|
|
||||||
|
clear_mind[uu]
|
||||||
|
}
|
||||||
|
summary[]
|
||||||
|
|
||||||
|
else
|
||||||
|
puts "Usage: removebadthoughts [--dry-run] <him|all>"
|
||||||
|
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue