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
Nothing yet!
- removebadthoughts: add --dry-run option
DFHack v0.34.11-r2

@ -1632,16 +1632,18 @@ removebadthoughts
This script remove negative thoughts from your dwarves. Very useful against
tantrum spirals.
With a selected unit in 'v' mode, will clear this unit's mind, otherwise
clear all your fort's units minds.
The script can target a single creature, when used with the ``him`` argument,
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,
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
it removed.
Internals: the thoughts are set to be very old, so that the game remove them
quickly after you unpause.
slayrace
@ -1650,7 +1652,7 @@ Kills any unit of a given race.
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``
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
# with removebadthoughts -v, dump the bad thoughts types we removed
verbose = $script_args.delete('-v')
dry_run = $script_args.delete('--dry-run') || $script_args.delete('-n')
if u = df.unit_find(:selected)
targets = [u]
else
targets = df.unit_citizens
end
$script_args << 'all' if dry_run and $script_args.empty?
seenbad = Hash.new(0)
targets.each { |u|
clear_mind = lambda { |u|
u.status.recent_events.each { |e|
next if DFHack::UnitThoughtType::Value[e.type].to_s[0, 1] != '-'
seenbad[e.type] += 1
e.age = 0x1000_0000
e.age = 0x1000_0000 unless dry_run
}
}
if verbose
seenbad.sort_by { |k, v| v }.each { |k, v| puts " #{v} #{k}" }
end
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
}
case $script_args[0]
when 'him'
if u = df.unit_find
clear_mind[u]
summary[]
else
puts 'Please select a dwarf ingame'
end
count = seenbad.values.inject(0) { |s, v| s+v }
puts "removed #{count} bad thought#{'s' if count != 1}"
when 'all'
df.unit_citizens.each { |uu|
clear_mind[uu]
}
summary[]
else
puts "Usage: removebadthoughts [--dry-run] <him|all>"
end