reaction-trigger now uses standard args.

develop
expwnent 2014-06-30 04:29:42 -04:00
parent c2890173d0
commit 801d521093
1 changed files with 25 additions and 64 deletions

@ -4,6 +4,7 @@
local eventful = require 'plugins.eventful' local eventful = require 'plugins.eventful'
local syndromeUtil = require 'syndromeUtil' local syndromeUtil = require 'syndromeUtil'
local utils = require 'utils'
reactionHooks = reactionHooks or {} reactionHooks = reactionHooks or {}
@ -93,8 +94,8 @@ eventful.onJobCompleted.reactionTrigger = function(job)
local function doAction(action) local function doAction(action)
local didSomething local didSomething
if action.args then if action.command then
local processed = processCommand(job, worker, worker, building, action.args) local processed = processCommand(job, worker, worker, building, action.command)
print(dfhack.run_command(table.unpack(processed))) print(dfhack.run_command(table.unpack(processed)))
end end
if action.syndrome then if action.syndrome then
@ -116,8 +117,8 @@ eventful.onJobCompleted.reactionTrigger = function(job)
elseif unit.pos.y < building.y1 or unit.pos.y > building.y2 then elseif unit.pos.y < building.y1 or unit.pos.y > building.y2 then
return false return false
else else
if action.args then if action.command then
processCommand(job, worker, unit, building, action.args) processCommand(job, worker, unit, building, action.command)
end end
if action.syndrome then if action.syndrome then
didSomething = syndrome.infectWithSyndromeIfValidTarget(unit,action.syndrome,action.resetPolicy) or didSomething didSomething = syndrome.infectWithSyndromeIfValidTarget(unit,action.syndrome,action.resetPolicy) or didSomething
@ -138,74 +139,34 @@ eventful.onJobCompleted.reactionTrigger = function(job)
doAction(action) doAction(action)
end end
end end
eventful.enableEvent(eventful.eventType.JOB_COMPLETED,0) eventful.enableEvent(eventful.eventType.JOB_COMPLETED,0)
local args = {...} local args = utils.processArgs(...)
local i=1 if args.clear then
local reactionName reactionHooks = {}
local action = {}
action.workerOnly = true
action.allowMultipleTargets = false
--action.args = {}
--action.syndrome, action.resetPolicy, action.workerOnly, action.allowMultipleTargets, action.args
while i <= #args do
if action.args then
table.insert(action.args, args[i])
i = i+1
else
if args[i] == '-clear' then
reactionHooks = {}
i = i+1
elseif args[i] == '-reactionName' then
reactionName = args[i+1]
i = i+2
elseif args[i] == '-syndrome' then
if action.syndrome then
error('only one syndrome at a time permitted')
end
for _,syndrome in ipairs(df.global.world.raws.syndromes.all) do
if syndrome.syn_name == args[i+1] then
action.syndrome = syndrome
break
end
end
if not action.syndrome then
error('could not find syndrome ' .. args[i+1])
end
i = i+2
elseif args[i] == '-workerOnly' then
action.workerOnly = args[i+1] == 'true'
i = i+2
elseif args[i] == '-allowMultipleTargets' then
action.allowMultipleTargets = args[i+1] == 'true'
i = i+2
elseif args[i] == '-command' then
action.args = {}
i = i+1
elseif args[i] == '-resetPolicy' then
action.resetPolicy = syndromeUtil.ResetPolicy[args[i+1]]
if not action.resetPolicy then
error('invalid reset policy: ' .. args[i+1])
end
i = i+2
else
error('invalid arguments')
end
end
end end
if not reactionName then if not args.reactionName then
return return
end end
if action.args then if not reactionHooks[args.reactionName] then
print(action.args) reactionHooks[args.reactionName] = {}
printall(action.args)
end end
if not reactionHooks[reactionName] then if args.syndrome then
reactionHooks[reactionName] = {} local foundIt
for _,syndrome in ipairs(df.global.world.raws.syndromes.all) do
if syndrome.syn_name == args.syndrome then
args.syndrome = syndrome
foundIt = true
break
end
end
if not foundIt then
error('Could not find syndrome ' .. args.syndrome)
end
end end
table.insert(reactionHooks[reactionName], action)
table.insert(reactionHooks[args.reactionName], args)