From 0db0244d08e69eb36c0f31700c76b2de83fbc4ef Mon Sep 17 00:00:00 2001 From: expwnent Date: Fri, 27 Jun 2014 05:47:52 -0400 Subject: [PATCH] Added add-syndrome script to modtools and fixed syndromeUtil so it actually works. This should make it so that event hooks only have to be able to run scripts instead of run scripts and add syndromes. --- library/lua/syndromeUtil.lua | 9 ++-- library/lua/utils.lua | 8 +++ scripts/modtools/add-syndrome.lua | 85 +++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 scripts/modtools/add-syndrome.lua diff --git a/library/lua/syndromeUtil.lua b/library/lua/syndromeUtil.lua index 132172e46..f67ec5ba9 100644 --- a/library/lua/syndromeUtil.lua +++ b/library/lua/syndromeUtil.lua @@ -3,7 +3,7 @@ --some utilities for adding syndromes to units local _ENV = mkmodule("syndromeUtil") -local Utils = require("utils") +local utils = require("utils") function findUnitSyndrome(unit,syn_id) for index,syndrome in ipairs(unit.syndromes.active) do @@ -15,7 +15,7 @@ function findUnitSyndrome(unit,syn_id) end --usage: syndrome.ResetPolicy.DoNothing, syndrome.ResetPolicy.ResetDuration, etc -ResetPolicy = ResetPolicy or Utils.reverse({ +ResetPolicy = ResetPolicy or utils.invert({ "DoNothing", "ResetDuration", "AddDuration", @@ -64,13 +64,12 @@ function infectWithSyndrome(target,syndrome,resetPolicy) unitSyndrome.year_time = df.global.cur_year_tick unitSyndrome.ticks = 0 unitSyndrome.wound_id = -1 - unitSyndrome.flags.bits.active = 1 for k,v in ipairs(syndrome.ce) do local symptom = df.unit_syndrome.T_symptoms:new() symptom.quantity = 0 symptom.delay = 0 symptom.ticks = 0 - symptom.flags.bits.active = true + symptom.flags.active = true unitSyndrome.symptoms:insert("#",symptom) end target.syndromes.active:insert("#",unitSyndrome) @@ -142,7 +141,7 @@ function isValidTarget(unit,syndrome) end function infectWithSyndromeIfValidTarget(target,syndrome,resetPolicy) - if isValidTarget(unit,syndrome) then + if isValidTarget(target,syndrome) then infectWithSyndrome(target,syndrome,resetPolicy) return true else diff --git a/library/lua/utils.lua b/library/lua/utils.lua index caa682c75..be139633e 100644 --- a/library/lua/utils.lua +++ b/library/lua/utils.lua @@ -540,4 +540,12 @@ function check_number(text) return nv ~= nil, nv end +function invert(tab) + local result = {} + for k,v in pairs(tab) do + result[v]=k + end + return result +end + return _ENV \ No newline at end of file diff --git a/scripts/modtools/add-syndrome.lua b/scripts/modtools/add-syndrome.lua new file mode 100644 index 000000000..90a30b76d --- /dev/null +++ b/scripts/modtools/add-syndrome.lua @@ -0,0 +1,85 @@ + +local syndromeUtil = require 'syndromeUtil' +local utils = require 'utils' + +mode = mode or utils.invert({ + 'add', + 'erase', + 'eraseAll' +}) + +local args = {...} +local i = 1 +local syndrome +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(' -help') + print(' print this help message') + print(' -syndrome [name]') + print(' select a syndrome by name') + print(' -resetPolicy DoNothing') + print(' if the target already has an instance of the syndrome, do nothing') + print(' -resetPolicy ResetDuration') + print(' if the target already has an instance of the syndrome, reset the duration to maximum') + print(' -resetPolicy AddDuration') + print(' if the target already has an instance of the syndrome, add the maximum duration to the time remaining') + print(' -resetPolicy NewInstance') + print(' if the target already has an instance of the syndrome, add a new instance of the syndrome') + print(' -erase') + print(' instead of adding a syndrome, erase one') + print(' -eraseAll') + print(' instead of adding a syndrome, erase every instance of it') + print(' -target [id]') + print(' set the target unit for infection') + print(' -skipImmunities') + print(' don\'t check syn_class immune/affected stuff.') + return + elseif args[i] == '-syndrome' then + local syn_name = args[i+1] + for _,syn in ipairs(df.global.world.raws.syndromes.all) do + if syn.syn_name == syn_name then + syndrome = syn + break + end + end + i = i+2 + elseif args[i] == '-resetPolicy' then + resetPolicy = syndromeUtil.ResetPolicy[args[i+1]] + if not resetPolicy then + qerror('Invalid arguments to add-syndrome.') + end + i = i+2 + elseif args[i] == '-erase' then + currentMode = mode.erase + i = i+1 + elseif args[i] == '-eraseAll' then + currentMode = mode.eraseAll + i = i+1 + elseif args[i] == '-add' then + currentMode = mode.add + i = i+1 + elseif args[i] == '-target' then + target = df.unit.find(tonumber(args[i+1])) + if not target then + qerror('Invalid unit id argument to add-syndrome.') + end + i = i+2 + elseif args[i] == '-skipImmunities' then + skipImmunities = true + i = i+1 + else + qerror('Invalid arguments to add-syndrome.') + end +end + +if skipImmunities then + syndromeUtil.infectWithSyndrome(target,syndrome,resetPolicy) +else + syndromeUtil.infectWithSyndromeIfValidTarget(target,syndrome,resetPolicy) +end +