removebadthoughts: add --dry-run option

develop
jj 2012-10-10 19:42:36 +02:00
parent b3b93f818d
commit b5f5d1f85b
3 changed files with 40 additions and 21 deletions

@ -1,6 +1,7 @@
DFHack future DFHack future
Nothing yet! Nothing yet!
- removebadthoughts: add --dry-run option
DFHack v0.34.11-r2 DFHack v0.34.11-r2

@ -1632,16 +1632,18 @@ removebadthoughts
This script remove negative thoughts from your dwarves. Very useful against This script remove negative thoughts from your dwarves. Very useful against
tantrum spirals. tantrum spirals.
With a selected unit in 'v' mode, will clear this unit's mind, otherwise The script can target a single creature, when used with the ``him`` argument,
clear all your fort's units minds. or the whole fort population, with ``all``.
To show every bad thought present without actually removing them, run the
script with the ``-n`` or ``--dry-run`` argument. This can give a quick
hint on what bothers your dwarves the most.
Individual dwarf happiness may not increase right after this command is run, Individual dwarf happiness may not increase right after this command is run,
but in the short term your dwarves will get much more joyful. but in the short term your dwarves will get much more joyful.
The thoughts are set to be very old, and the game will remove them soon when
you unpause.
With the optional ``-v`` parameter, the script will dump the negative thoughts Internals: the thoughts are set to be very old, so that the game remove them
it removed. quickly after you unpause.
slayrace slayrace
@ -1650,7 +1652,7 @@ Kills any unit of a given race.
With no argument, lists the available races. With no argument, lists the available races.
With the special argument 'him', targets only the selected creature. With the special argument ``him``, targets only the selected creature.
Any non-dead non-caged unit of the specified race gets its ``blood_count`` Any non-dead non-caged unit of the specified race gets its ``blood_count``
set to 0, which means immediate death at the next game tick. For creatures set to 0, which means immediate death at the next game tick. For creatures

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