Fixed a problem with syndromeUtil, renamed to syndrome-util, and made add-syndrome use proper conventions.

develop
expwnent 2014-07-03 15:18:00 -04:00
parent 85c81cc69f
commit e28a42b848
2 changed files with 87 additions and 78 deletions

@ -1,13 +1,13 @@
--syndrome.lua --lua/syndrome-util.lua
--author expwnent --author expwnent
--some utilities for adding syndromes to units --some utilities for adding syndromes to units
local _ENV = mkmodule("syndromeUtil") local _ENV = mkmodule("syndrome-util")
local utils = require("utils") local utils = require("utils")
function findUnitSyndrome(unit,syn_id) function findUnitSyndrome(unit,syn_id)
for index,syndrome in ipairs(unit.syndromes.active) do for index,syndrome in ipairs(unit.syndromes.active) do
if syndrome.type == syn_id then if syndrome['type'] == syn_id then
return syndrome return syndrome
end end
end end
@ -107,7 +107,7 @@ function isValidTarget(unit,syndrome)
local unitRaws = df.creature_raw.find(unit.race) local unitRaws = df.creature_raw.find(unit.race)
local casteRaws = unitRaws.caste[unit.caste] local casteRaws = unitRaws.caste[unit.caste]
local unitRaceName = unitRaws.creature_id local unitRaceName = unitRaws.creature_id
local casteName = casteRaws.caste_id local unitCasteName = casteRaws.caste_id
local unitClasses = casteRaws.creature_class local unitClasses = casteRaws.creature_class
for _,unitClass in ipairs(unitClasses) do for _,unitClass in ipairs(unitClasses) do
for _,syndromeClass in ipairs(syndrome.syn_affected_class) do for _,syndromeClass in ipairs(syndrome.syn_affected_class) do
@ -119,7 +119,7 @@ function isValidTarget(unit,syndrome)
for caste,creature in ipairs(syndrome.syn_affected_creature) do for caste,creature in ipairs(syndrome.syn_affected_creature) do
local affectedCreature = creature.value local affectedCreature = creature.value
local affectedCaste = syndrome.syn_affectedCaste[caste].value local affectedCaste = syndrome.syn_affectedCaste[caste].value
if affectedCreature == unitRaceName and (affectedCaste == casteName or affectedCaste == "ALL") then if affectedCreature == unitRaceName and (affectedCaste == unitCasteName or affectedCaste == "ALL") then
affected = true affected = true
end end
end end
@ -130,10 +130,10 @@ function isValidTarget(unit,syndrome)
end end
end end
end end
for caste,creature in ipairs(syndrome,syn_immune_creature) do for caste,creature in ipairs(syndrome.syn_immune_creature) do
local immuneCreature = creature.value local immuneCreature = creature.value
local immuneCaste = syndrome.syn_immune_caste[caste].value local immuneCaste = syndrome.syn_immune_caste[caste].value
if immuneCreature == unitRaceName and (immuneCaste == casteName or immuneCaste == "ALL") then if immuneCreature == unitRaceName and (immuneCaste == unitCasteName or immuneCaste == "ALL") then
affected = false affected = false
end end
end end

@ -1,85 +1,94 @@
--modtools/add-syndrome.lua
--author expwnent
--add syndromes to a target, or remove them
local syndromeUtil = require 'syndromeUtil' local syndromeUtil = require 'syndrome-util'
local utils = require 'utils' local utils = require 'utils'
mode = mode or utils.invert({ validArgs = validArgs or utils.invert({
'add', 'help',
'syndrome',
'resetPolicy',
'erase', 'erase',
'eraseAll' 'eraseOldest',
'eraseAll',
'target',
'skipImmunities'
}) })
local args = {...} local args = utils.processArgs({...}, validArgs)
local i = 1
local syndrome if args.help then
local resetPolicy = syndromeUtil.ResetPolicy.NewInstance
local currentMode = mode.add
local target
local skipImmunities = false
while i <= #args do
if args[i] == '-help' then
print('add-syndrome usage:') print('add-syndrome usage:')
print(' -help') print(' -help')
print(' print this help message') print(' print this help message')
print(' -syndrome [name]') print(' -syndrome [name]')
print(' select a syndrome by name') print(' select a syndrome by name')
print(' -resetPolicy DoNothing') print(' -resetPolicy {default = NewInstance}')
print(' DoNothing')
print(' if the target already has an instance of the syndrome, do nothing') print(' if the target already has an instance of the syndrome, do nothing')
print(' -resetPolicy ResetDuration') print(' ResetDuration')
print(' if the target already has an instance of the syndrome, reset the duration to maximum') print(' if the target already has an instance of the syndrome, reset the duration to maximum')
print(' -resetPolicy AddDuration') print(' AddDuration')
print(' if the target already has an instance of the syndrome, add the maximum duration to the time remaining') print(' if the target already has an instance of the syndrome, add the maximum duration to the time remaining')
print(' -resetPolicy NewInstance') print(' NewInstance')
print(' if the target already has an instance of the syndrome, add a new instance of the syndrome') print(' if the target already has an instance of the syndrome, add a new instance of the syndrome')
print(' -erase') print(' -erase')
print(' instead of adding a syndrome, erase one') print(' instead of adding a syndrome, erase one')
print(' -eraseAll') print(' -eraseAll')
print(' instead of adding a syndrome, erase every instance of it') print(' instead of adding a syndrome, erase every instance of it')
print(' -target [id]') print(' -target [id]')
print(' set the target unit for infection') print(' set the target unit for infection or uninfection')
print(' -skipImmunities') print(' -skipImmunities')
print(' don\'t check syn_class immune/affected stuff.') print(' don\'t check syn_class immune/affected stuff when adding the syndrome')
return return
elseif args[i] == '-syndrome' then end
local syn_name = args[i+1]
for _,syn in ipairs(df.global.world.raws.syndromes.all) do if args.resetPolicy then
if syn.syn_name == syn_name 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 syndrome = syn
break break
end end
end end
i = i+2 if not syndrome then
elseif args[i] == '-resetPolicy' then error ('Invalid syndrome: ' .. args.syndrome)
resetPolicy = syndromeUtil.ResetPolicy[args[i+1]] end
if not resetPolicy then args.syndrome = syndrome
qerror('Invalid arguments to add-syndrome.')
end if not args.target then
i = i+2 error 'Specify a target.'
elseif args[i] == '-erase' then end
currentMode = mode.erase local targ = df.unit.find(tonumber(args.target))
i = i+1 if not targ then
elseif args[i] == '-eraseAll' then error ('Could not find target: ' .. args.target)
currentMode = mode.eraseAll end
i = i+1 args.target = targ
elseif args[i] == '-add' then
currentMode = mode.add if args.erase then
i = i+1 syndromeUtil.eraseSyndrome(args.target,args.syndrome.id,args.eraseOldest)
elseif args[i] == '-target' then return
target = df.unit.find(tonumber(args[i+1])) end
if not target then
qerror('Invalid unit id argument to add-syndrome.') if args.eraseAll then
end syndromeUtil.eraseSyndromes(args.target,args.syndrome.id)
i = i+2 return
elseif args[i] == '-skipImmunities' then
skipImmunities = true
i = i+1
else
qerror('Invalid arguments to add-syndrome.')
end
end end
if skipImmunities then if skipImmunities then
syndromeUtil.infectWithSyndrome(target,syndrome,resetPolicy) syndromeUtil.infectWithSyndrome(args.target,args.syndrome,args.resetPolicy)
else else
syndromeUtil.infectWithSyndromeIfValidTarget(target,syndrome,resetPolicy) syndromeUtil.infectWithSyndromeIfValidTarget(args.target,args.syndrome,args.resetPolicy)
end end