Skip to content

Commit 7b30d55

Browse files
committed
remove-stress: fix -all for soul-less units, indentation, module support
1 parent 27ea437 commit 7b30d55

1 file changed

Lines changed: 31 additions & 18 deletions

File tree

remove-stress.lua

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-- Sets stress to negative one million
22
--By Putnam; http://www.bay12forums.com/smf/index.php?topic=139553.msg5820486#msg5820486
3+
--@module = true
34
local help = [====[
45
56
remove-stress
@@ -12,27 +13,39 @@ Applies to the selected unit, or use ``remove-stress -all`` to apply to all unit
1213

1314
local utils = require 'utils'
1415

15-
validArgs = validArgs or utils.invert({
16-
'help',
17-
'all'
16+
function removeStress(unit)
17+
if unit.status.current_soul then
18+
unit.status.current_soul.personality.stress_level = -1000000
19+
end
20+
end
21+
22+
validArgs = utils.invert({
23+
'help',
24+
'all'
1825
})
1926

20-
local args = utils.processArgs({...}, validArgs)
27+
function main(...)
28+
local args = utils.processArgs({...}, validArgs)
29+
30+
if args.help then
31+
print(help)
32+
return
33+
end
2134

22-
if args.help then
23-
print(help)
24-
return
35+
if args.all then
36+
for k,v in ipairs(df.global.world.units.active) do
37+
removeStress(v)
38+
end
39+
else
40+
local unit = dfhack.gui.getSelectedUnit()
41+
if unit then
42+
removeStress(unit)
43+
else
44+
error 'Invalid usage: No unit selected and -all argument not given.'
45+
end
46+
end
2547
end
2648

27-
if args.all then
28-
for k,v in ipairs(df.global.world.units.active) do
29-
v.status.current_soul.personality.stress_level=-1000000
30-
end
31-
else
32-
local unit = dfhack.gui.getSelectedUnit()
33-
if unit then
34-
unit.status.current_soul.personality.stress_level=-1000000
35-
else
36-
error 'Invalid usage: No unit selected and -all argument not given.'
37-
end
49+
if not dfhack_flags.module then
50+
main(...)
3851
end

0 commit comments

Comments
 (0)