2014-07-03 13:18:00 -06:00
|
|
|
--modtools/add-syndrome.lua
|
|
|
|
--author expwnent
|
2015-10-23 17:57:04 -06:00
|
|
|
--[[=begin
|
2014-06-27 03:47:52 -06:00
|
|
|
|
2015-10-23 17:57:04 -06:00
|
|
|
modtools/add-syndrome
|
|
|
|
=====================
|
|
|
|
This allows adding and removing syndromes from units.
|
|
|
|
|
|
|
|
=end]]
|
2014-07-03 13:18:00 -06:00
|
|
|
local syndromeUtil = require 'syndrome-util'
|
2014-06-27 03:47:52 -06:00
|
|
|
local utils = require 'utils'
|
|
|
|
|
2014-07-03 13:18:00 -06:00
|
|
|
validArgs = validArgs or utils.invert({
|
|
|
|
'help',
|
|
|
|
'syndrome',
|
|
|
|
'resetPolicy',
|
2014-06-27 03:47:52 -06:00
|
|
|
'erase',
|
2014-07-03 13:18:00 -06:00
|
|
|
'eraseOldest',
|
|
|
|
'eraseAll',
|
|
|
|
'target',
|
2014-11-14 21:33:49 -07:00
|
|
|
'skipImmunities',
|
|
|
|
'eraseClass'
|
2014-06-27 03:47:52 -06:00
|
|
|
})
|
|
|
|
|
2014-07-03 13:18:00 -06:00
|
|
|
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
|
2014-11-14 21:33:49 -07:00
|
|
|
-eraseClass SYN_CLASS
|
|
|
|
erase every instance of every syndrome with the given SYN_CLASS
|
2014-07-03 14:30:28 -06:00
|
|
|
-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
|
|
|
|
]])
|
2014-07-03 13:18:00 -06:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-11-14 21:33:49 -07:00
|
|
|
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.eraseClass then
|
|
|
|
local count = syndromeUtil.eraseSyndromeClass(args.target, args.eraseClass)
|
|
|
|
--print('deleted ' .. tostring(count) .. ' syndromes')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-07-03 13:18:00 -06:00
|
|
|
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
|
|
|
|
|
2014-06-27 03:47:52 -06:00
|
|
|
local syndrome
|
2014-07-03 13:18:00 -06:00
|
|
|
for _,syn in ipairs(df.global.world.raws.syndromes.all) do
|
|
|
|
if syn.syn_name == args.syndrome then
|
|
|
|
syndrome = syn
|
|
|
|
break
|
2014-06-27 03:47:52 -06:00
|
|
|
end
|
|
|
|
end
|
2014-07-03 13:18:00 -06:00
|
|
|
if not syndrome then
|
|
|
|
error ('Invalid syndrome: ' .. args.syndrome)
|
|
|
|
end
|
|
|
|
args.syndrome = syndrome
|
|
|
|
|
|
|
|
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
|
2014-06-27 03:47:52 -06:00
|
|
|
|
|
|
|
if skipImmunities then
|
2014-07-03 13:18:00 -06:00
|
|
|
syndromeUtil.infectWithSyndrome(args.target,args.syndrome,args.resetPolicy)
|
2014-06-27 03:47:52 -06:00
|
|
|
else
|
2014-07-03 13:18:00 -06:00
|
|
|
syndromeUtil.infectWithSyndromeIfValidTarget(args.target,args.syndrome,args.resetPolicy)
|
2014-06-27 03:47:52 -06:00
|
|
|
end
|
|
|
|
|