dfhack/scripts/modtools/add-syndrome.lua

101 lines
2.3 KiB
Lua

--modtools/add-syndrome.lua
--author expwnent
--add syndromes to a target, or remove them
local syndromeUtil = require 'syndrome-util'
local utils = require 'utils'
validArgs = validArgs or utils.invert({
'help',
'syndrome',
'resetPolicy',
'erase',
'eraseOldest',
'eraseAll',
'target',
'skipImmunities'
})
local args = utils.processArgs({...}, validArgs)
if args.help then
2014-07-03 14:30:28 -06:00
print([[scripts/modtools/add-syndrome usage:
arguments:
-help
print this help message
-syndrome name
the name of the syndrome to operate on
examples:
"gila monster bite"
-resetPolicy policy
specify a policy of what to do if the unit already has an instance of the syndrome
examples:
NewInstance
default behavior: create a new instance of the syndrome
DoNothing
ResetDuration
AddDuration
-erase
instead of adding an instance of the syndrome, erase one
-eraseAll
erase every instance of the syndrome
-target id
the unit id of the target unit
examples:
0
28
-skipImmunities
add the syndrome to the target regardless of whether it is immune to the syndrome
]])
return
end
if args.resetPolicy then
args.resetPolicy = syndromeUtil.ResetPolicy[args.resetPolicy]
if not args.resetPolicy then
error ('Invalid reset policy.')
end
end
if not args.syndrome then
error 'Specify a syndrome name.'
end
local syndrome
for _,syn in ipairs(df.global.world.raws.syndromes.all) do
if syn.syn_name == args.syndrome then
syndrome = syn
break
end
end
if not syndrome then
error ('Invalid syndrome: ' .. args.syndrome)
end
args.syndrome = syndrome
if not args.target then
error 'Specify a target.'
end
local targ = df.unit.find(tonumber(args.target))
if not targ then
error ('Could not find target: ' .. args.target)
end
args.target = targ
if args.erase then
syndromeUtil.eraseSyndrome(args.target,args.syndrome.id,args.eraseOldest)
return
end
if args.eraseAll then
syndromeUtil.eraseSyndromes(args.target,args.syndrome.id)
return
end
if skipImmunities then
syndromeUtil.infectWithSyndrome(args.target,args.syndrome,args.resetPolicy)
else
syndromeUtil.infectWithSyndromeIfValidTarget(args.target,args.syndrome,args.resetPolicy)
end