From 23c761a41e6dd08f3c27ca6489ade1d3ba7fb5ab Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 14 Mar 2024 17:23:46 -0700 Subject: [PATCH 1/4] include residents in citizens list where applicable --- allneeds.lua | 4 ++-- combat-harden.lua | 2 +- docs/combat-harden.rst | 4 ++-- docs/fillneeds.rst | 2 +- fillneeds.lua | 2 +- fix/stuck-worship.lua | 2 +- gui/unit-syndromes.lua | 14 +------------- internal/notify/notifications.lua | 2 +- list-waves.lua | 2 +- uniform-unstick.lua | 2 +- warn-stranded.lua | 4 ++-- 11 files changed, 14 insertions(+), 26 deletions(-) diff --git a/allneeds.lua b/allneeds.lua index 441b38c063..f23ab95351 100644 --- a/allneeds.lua +++ b/allneeds.lua @@ -26,8 +26,8 @@ if units then print(('Summarizing needs for %s:'):format(dfhack.units.getReadableName(units))) units = {units} else - print('Summarizing needs for all (sane) citizens:') - units = dfhack.units.getCitizens(false) + print('Summarizing needs for all (sane) citizens and residents:') + units = dfhack.units.getCitizens() end print() diff --git a/combat-harden.lua b/combat-harden.lua index 435d7aab66..8010ae14b8 100644 --- a/combat-harden.lua +++ b/combat-harden.lua @@ -79,7 +79,7 @@ function main(args) qerror('--citizens requires fortress mode') end - for _, unit in ipairs(dfhack.units.getCitizens(false)) do + for _, unit in ipairs(dfhack.units.getCitizens()) do table.insert(unitsList, unit) end end diff --git a/docs/combat-harden.rst b/docs/combat-harden.rst index 24bf3078f6..78e01e9c68 100644 --- a/docs/combat-harden.rst +++ b/docs/combat-harden.rst @@ -28,8 +28,8 @@ Unit options ``--all`` All active units will be affected. ``--citizens`` - All citizens of your fort will be affected. Will do nothing in adventure - mode. + All citizens and residents of your fort will be affected. Will do nothing + in adventure mode. ``--unit `` The given unit will be affected. diff --git a/docs/fillneeds.rst b/docs/fillneeds.rst index b3d389a9f8..3eedaa1135 100644 --- a/docs/fillneeds.rst +++ b/docs/fillneeds.rst @@ -15,4 +15,4 @@ Usage ``fillneeds --unit `` Make the specified unit focused and unstressed. ``fillneeds --all`` - Make all units focused and unstressed. + Make all citizens and residents focused and unstressed. diff --git a/fillneeds.lua b/fillneeds.lua index a55890bbc1..6f3b001fef 100644 --- a/fillneeds.lua +++ b/fillneeds.lua @@ -14,7 +14,7 @@ function satisfyNeeds(unit) end if args.all then - for _, unit in ipairs(dfhack.units.getCitizens(true)) do + for _, unit in ipairs(dfhack.units.getCitizens()) do satisfyNeeds(unit) end else diff --git a/fix/stuck-worship.lua b/fix/stuck-worship.lua index 8ea05e707c..0781181f5f 100644 --- a/fix/stuck-worship.lua +++ b/fix/stuck-worship.lua @@ -79,7 +79,7 @@ local function get_prayer_targets(unit) end end -for _,unit in ipairs(dfhack.units.getCitizens(true)) do +for _,unit in ipairs(dfhack.units.getCitizens(false, true)) do local prayer_targets = get_prayer_targets(unit) if not unit.status.current_soul or not prayer_targets then goto next_unit diff --git a/gui/unit-syndromes.lua b/gui/unit-syndromes.lua index 9454a586c8..6807f59e4a 100644 --- a/gui/unit-syndromes.lua +++ b/gui/unit-syndromes.lua @@ -300,18 +300,6 @@ local function getUnitSyndromes(unit) return unit_syndromes end -local function getCitizens() - local units = {} - - for _, unit in pairs(df.global.world.units.active) do - if dfhack.units.isCitizen(unit) and dfhack.units.isDwarf(unit) then - table.insert(units, unit) - end - end - - return units -end - local function getLivestock() local units = {} @@ -382,7 +370,7 @@ function UnitSyndromes:init() view_id = 'category', frame = {t = 0, l = 0}, choices = { - { text = "Dwarves", get_choices = getCitizens }, + { text = "Dwarves", get_choices = curry(dfhack.units.getCitizens, false, true) }, { text = "Livestock", get_choices = getLivestock }, { text = "Wild animals", get_choices = getWildAnimals }, { text = "Hostile", get_choices = getHostiles }, diff --git a/internal/notify/notifications.lua b/internal/notify/notifications.lua index 7d5de25107..8aaec589a8 100644 --- a/internal/notify/notifications.lua +++ b/internal/notify/notifications.lua @@ -94,7 +94,7 @@ local function for_starving(fn, reverse) end local function for_moody(fn, reverse) - for_iter(dfhack.units.getCitizens(false), function(unit) + for_iter(dfhack.units.getCitizens(true), function(unit) local job = unit.job.current_job return job and df.job_type_class[df.job_type.attrs[job.job_type].type] == 'StrangeMood' end, fn, reverse) diff --git a/list-waves.lua b/list-waves.lua index 22785a99dd..99fe22c3af 100644 --- a/list-waves.lua +++ b/list-waves.lua @@ -78,7 +78,7 @@ local function getWave(dwf) end end -for _,v in ipairs(dfhack.units.getCitizens(false)) do +for _,v in ipairs(dfhack.units.getCitizens(true, true)) do getWave(v) end diff --git a/uniform-unstick.lua b/uniform-unstick.lua index e19e8a43bd..0b9806f018 100644 --- a/uniform-unstick.lua +++ b/uniform-unstick.lua @@ -264,7 +264,7 @@ local function main(args) if args.all then local need_newline = false - for _, unit in ipairs(dfhack.units.getCitizens(false)) do + for _, unit in ipairs(dfhack.units.getCitizens(true)) do do_drop(process(unit, args, need_newline)) need_newline = true end diff --git a/warn-stranded.lua b/warn-stranded.lua index df29d6306f..d1b1d00e73 100644 --- a/warn-stranded.lua +++ b/warn-stranded.lua @@ -62,7 +62,7 @@ function getStrandedGroups() local groupCount = 0 local unitsByWalkGroup, ignoredUnitsByWalkGroup = {}, {} - for _, unit in ipairs(dfhack.units.getCitizens(false)) do + for _, unit in ipairs(dfhack.units.getCitizens(true)) do local unitPos = xyz2pos(dfhack.units.getPosition(unit)) local walkGroup = getWalkGroup(unitPos) @@ -380,7 +380,7 @@ local function getStrandedGroupsWithIgnored(groupList, ignoredUnitsByWalkGroup, end local function findCitizen(unitId) - for _, citizen in ipairs(dfhack.units.getCitizens(true)) do + for _, citizen in ipairs(dfhack.units.getCitizens(true, true)) do if citizen.id == unitId then return citizen end end From 9ea143185e34b9163c44e7606ed56e735416db99 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 14 Mar 2024 18:40:21 -0700 Subject: [PATCH 2/4] use getCitizens and isResident as appropriate --- adaptation.lua | 10 +++------- autonick.lua | 41 +++++------------------------------------ build-now.lua | 6 ++---- do-job-now.lua | 22 +++------------------- docs/full-heal.rst | 2 +- docs/gaydar.rst | 4 ++-- emigration.lua | 1 - fix/loyaltycascade.lua | 10 +++++----- forget-dead-body.lua | 18 ++++-------------- full-heal.lua | 13 ++++--------- gaydar.lua | 30 +++--------------------------- gui/extended-status.lua | 36 +++++++++++------------------------- gui/family-affairs.lua | 41 +++++++---------------------------------- gui/teleport.lua | 5 ++++- max-wave.lua | 17 +---------------- rejuvenate.lua | 6 +----- siren.lua | 16 +++------------- superdwarf.lua | 6 ++---- 18 files changed, 61 insertions(+), 223 deletions(-) diff --git a/adaptation.lua b/adaptation.lua index 769f7d941a..c3641be9f6 100644 --- a/adaptation.lua +++ b/adaptation.lua @@ -23,10 +23,6 @@ local function usage(s) end local function set_adaptation_value(unit, v) - if not dfhack.units.isCitizen(unit) or not dfhack.units.isAlive(unit) then - return 0 - end - for _, t in ipairs(unit.status.misc_traits) do if t.id == df.misc_trait_type.CaveAdapt then if mode == 'show' then @@ -94,15 +90,15 @@ end if who == 'him' then local u = dfhack.gui.getSelectedUnit(true) - if u then + if u and (dfhack.units.isCitizen(u) or dfhack.units.isResident(u)) then set_adaptation_value(u, value) else - dfhack.printerr('Please select a dwarf ingame') + dfhack.printerr('Please select a citizen or resident ingame') end elseif who == 'all' then local num_set = 0 - for _, uu in ipairs(df.global.world.units.all) do + for _, uu in ipairs(dfhack.units.getCitizens()) do num_set = num_set + set_adaptation_value(uu, value) end diff --git a/autonick.lua b/autonick.lua index 2ea3cb4032..ee1cd01326 100644 --- a/autonick.lua +++ b/autonick.lua @@ -1,33 +1,4 @@ -- gives dwarves unique nicknames ---[====[ - -autonick -======== -Gives dwarves unique nicknames chosen randomly from ``dfhack-config/autonick.txt``. - -One nickname per line. -Empty lines, lines beginning with ``#`` and repeat entries are discarded. - -Dwarves with manually set nicknames are ignored. - -If there are fewer available nicknames than dwarves, the remaining -dwarves will go un-nicknamed. - -You may wish to use this script with the "repeat" command, e.g: -``repeat -name autonick -time 3 -timeUnits months -command [ autonick all ]`` - -Usage: - - autonick all [] - autonick help - -Options: - -:``-h``, ``--help``: - Show this text. -:``-q``, ``--quiet``: - Do not report how many dwarves were given nicknames. -]====] local options = {} @@ -48,9 +19,8 @@ end local seen = {} --check current nicknames -for _,unit in ipairs(df.global.world.units.active) do - if dfhack.units.isCitizen(unit) and - unit.name.nickname ~= "" then +for _,unit in ipairs(dfhack.units.getCitizens()) do + if unit.name.nickname ~= "" then seen[unit.name.nickname] = true end end @@ -70,16 +40,15 @@ end --assign names local count = 0 -for _,unit in ipairs(df.global.world.units.active) do +for _,unit in ipairs(dfhack.units.getCitizens()) do if (#names == 0) then if options.quiet ~= true then - print("no free names left in dfhack-config/autonick.txt") + print("not enough unique names in dfhack-config/autonick.txt") end break end --if there are any names left - if dfhack.units.isCitizen(unit) and - unit.name.nickname == "" then + if unit.name.nickname == "" then newnameIndex = math.random (#names) dfhack.units.setNickname(unit, names[newnameIndex]) table.remove(names, newnameIndex) diff --git a/build-now.lua b/build-now.lua index b99b64c17d..35ac7a6f6b 100644 --- a/build-now.lua +++ b/build-now.lua @@ -230,10 +230,8 @@ local function get_dump_pos(bld) if dump_pos then return dump_pos end - for _,unit in ipairs(df.global.world.units.active) do - if dfhack.units.isCitizen(unit) then - return unit.pos - end + for _,unit in ipairs(dfhack.units.getCitizens(true)) do + return unit.pos end -- fall back to position of first active unit return df.global.world.units.active[0].pos diff --git a/do-job-now.lua b/do-job-now.lua index c6994dc5f3..3a1ea578b4 100644 --- a/do-job-now.lua +++ b/do-job-now.lua @@ -1,27 +1,11 @@ -- makes a job involving current selection high priority -local function print_help() - print [====[ - -do-job-now -========== - -The script will try its best to find a job related to the selected entity -(which can be a job, dwarf, animal, item, building, plant or work order) and then -mark this job as high priority. There is no visual indicator, please look -at the dfhack console for output. If a work order is selected, every job -currently present job from this work order is affected, but not the future ones. - -For best experience add the following to your ``dfhack*.init``:: +local utils = require('utils') - keybinding add Alt-N do-job-now - -Also see ``do-job-now`` `tweak` and `prioritize`. -]====] +local function print_help() + print(dfhack.script_help()) end -local utils = require 'utils' - local function getUnitName(unit) local language_name = dfhack.units.getVisibleName(unit) if language_name.has_name then diff --git a/docs/full-heal.rst b/docs/full-heal.rst index 280fd8d43d..226761d0f9 100644 --- a/docs/full-heal.rst +++ b/docs/full-heal.rst @@ -22,7 +22,7 @@ Usage ``full-heal --all [-r] [--keep_corpse]`` Heal all units on the map, optionally resurrecting them if dead. ``full-heal --all_citizens [-r] [--keep_corpse]`` - Heal all fortress citizens on the map. Does not include pets. + Heal all fortress citizens and residents on the map. Does not include pets. ``full-heal --all_civ [-r] [--keep_corpse]`` Heal all units belonging to your parent civilization, including pets and visitors. diff --git a/docs/gaydar.rst b/docs/gaydar.rst index ee40541155..7a2375ea9f 100644 --- a/docs/gaydar.rst +++ b/docs/gaydar.rst @@ -21,7 +21,7 @@ Examples ``gaydar`` Show sexual orientation of the selected unit. ``gaydar --citizens --asexual`` - Identify asexual citizens. + Identify asexual citizens and residents. Target options -------------- @@ -29,7 +29,7 @@ Target options ``--all`` Selects every creature on the map. ``--citizens`` - Selects fort citizens. + Selects fort citizens and residents. ``--named`` Selects all named units on the map. diff --git a/emigration.lua b/emigration.lua index 1e9ece4991..26165e66f7 100644 --- a/emigration.lua +++ b/emigration.lua @@ -159,7 +159,6 @@ function canLeave(unit) not unit.flags1.chained and dfhack.units.getNoblePositions(unit) == nil and unit.military.squad_id == -1 and - dfhack.units.isSane(unit) and not dfhack.units.isBaby(unit) and not dfhack.units.isChild(unit) end diff --git a/fix/loyaltycascade.lua b/fix/loyaltycascade.lua index a943a5aa6d..557ab93e44 100644 --- a/fix/loyaltycascade.lua +++ b/fix/loyaltycascade.lua @@ -73,7 +73,7 @@ local function fixUnit(unit) end if fixed and unit.enemy.enemy_status_slot ~= -1 then - local status_cache = unit.enemy.enemy_status_cache + local status_cache = df.global.world.enemy_status_cache local status_slot = unit.enemy.enemy_status_slot unit.enemy.enemy_status_slot = -1 @@ -89,8 +89,8 @@ local function fixUnit(unit) -- TODO: what if there were status slots taken above status_slot? -- does everything need to be moved down by one? - if cache.next_slot > status_slot then - cache.next_slot = status_slot + if status_cache.next_slot > status_slot then + status_cache.next_slot = status_slot end end @@ -98,8 +98,8 @@ local function fixUnit(unit) end local count = 0 -for _, unit in pairs(df.global.world.units.all) do - if dfhack.units.isCitizen(unit) and fixUnit(unit) then +for _, unit in pairs(dfhack.units.getCitizens()) do + if fixUnit(unit) then count = count + 1 end end diff --git a/forget-dead-body.lua b/forget-dead-body.lua index 1166e75ef7..0275097321 100644 --- a/forget-dead-body.lua +++ b/forget-dead-body.lua @@ -1,14 +1,6 @@ -- Removes emotions associated with seeing a dead body --@ module = true -local help = [====[ - -forget-dead-body -================ -Removes emotions associated with seeing a dead body. - -]====] - local utils = require 'utils' local validArgs = utils.invert({ @@ -28,22 +20,20 @@ function main(...) local args = utils.processArgs({...}, validArgs) if args.help then - print(help) + print(dfhack.script_help()) return end if args.all then - for _, unit in ipairs(df.global.world.units.active) do - if dfhack.units.isCitizen(unit) then - forgetDeadBody(unit) - end + for _, unit in ipairs(dfhack.units.getCitizens()) do + forgetDeadBody(unit) end else local unit = dfhack.gui.getSelectedUnit() if unit then forgetDeadBody(unit) else - qerror('Invalid usage: No unit selected and -all argument not given.') + qerror('Invalid usage: No unit selected and --all argument not given.') end end end diff --git a/full-heal.lua b/full-heal.lua index 2dc71c3dca..e3cca8a28f 100644 --- a/full-heal.lua +++ b/full-heal.lua @@ -35,12 +35,6 @@ function isCitizen(unit) end end -function isFortCivMember(unit) - if unit.civ_id == df.global.plotinfo.civ_id then - return true - end -end - function addResurrectionEvent(histFigID) local event = df.history_event_hist_figure_revivedst:new() event.histfig = histFigID @@ -76,7 +70,7 @@ function heal(unit,resurrect,keep_corpse) addResurrectionEvent(hf.id) end - if dfhack.world.isFortressMode() and isFortCivMember(unit) then + if dfhack.world.isFortressMode() and dfhack.units.isOwnCiv(unit) then unit.flags2.resident = false -- appears to be set to true for dead citizens in a reclaimed fortress, which causes them to be marked as hostile when resurrected local deadCitizens = df.global.plotinfo.main.dead_citizens @@ -260,14 +254,15 @@ if args.all then heal(unit,args.r,args.keep_corpse) end elseif args.all_citizens then + -- can't use dfhack.units.getCitizens since we want dead ones too for _,unit in ipairs(df.global.world.units.active) do - if isCitizen(unit) then + if dfhack.units.isCitizen(unit) or dfhack.units.isResident(unit) then heal(unit,args.r,args.keep_corpse) end end elseif args.all_civ then for _,unit in ipairs(df.global.world.units.active) do - if isFortCivMember(unit) then + if dfhack.units.isOwnCiv(unit) then heal(unit,args.r,args.keep_corpse) end end diff --git a/gaydar.lua b/gaydar.lua index 21cc643b9d..bb110d7009 100644 --- a/gaydar.lua +++ b/gaydar.lua @@ -1,27 +1,5 @@ -- Shows the sexual orientation of units -local help = [====[ -gaydar -====== -Shows the sexual orientation of units, useful for social engineering or checking -the viability of livestock breeding programs. - -Targets: - -:-all: shows orientation of every creature -:-citizens: shows only orientation of citizens in fort mode -:-named: shows orientation of all named units on map -:(no target): shows orientation of the unit under the cursor - -Orientation filters: - -:-notStraight: only creatures who are not strictly straight -:-gayOnly: only creatures who are strictly gay -:-biOnly: only creatures who can get into romances with both sexes -:-straightOnly: only creatures who are strictly straight -:-asexualOnly: only creatures who are strictly asexual - -]====] local utils = require('utils') local validArgs = utils.invert({ @@ -40,7 +18,7 @@ local validArgs = utils.invert({ local args = utils.processArgs({...}, validArgs) if args.help then - print(help) + print(dfhack.script_help()) return end @@ -108,10 +86,8 @@ end local orientations={} --as:string[] if args.citizens then - for k,v in ipairs(df.global.world.units.active) do - if dfhack.units.isCitizen(v) then - table.insert(orientations,nameOrSpeciesAndNumber(v) .. determineorientation(v)) - end + for k,v in ipairs(dfhack.units.getCitizens()) do + table.insert(orientations,nameOrSpeciesAndNumber(v) .. determineorientation(v)) end elseif args.all then for k,v in ipairs(df.global.world.units.active) do diff --git a/gui/extended-status.lua b/gui/extended-status.lua index 2cd7c34113..6a0da0c3f9 100644 --- a/gui/extended-status.lua +++ b/gui/extended-status.lua @@ -1,17 +1,5 @@ -- Adds more z-status subpages --@ enable = true ---[====[ - -gui/extended-status -=================== -Adds more subpages to the ``z`` status screen. - -Usage:: - - gui/extended-status enable|disable|help|subpage_names - enable|disable gui/extended-status - -]====] gui = require 'gui' dialogs = require 'gui.dialogs' @@ -159,21 +147,19 @@ function bedroom_list:refresh() end end end - for _, u in pairs(world.units.active) do - if dfhack.units.isCitizen(u) then - add('units', u) - local has_bed = false - for _, b in pairs(u.owned_buildings) do - if df.building_bedst:is_instance(b) then - has_bed = true - end - end - if has_bed then - add('uwith', u) - else - add('uwithout', u) + for _, u in pairs(dfhack.units.getCitizens(true)) do + add('units', u) + local has_bed = false + for _, b in pairs(u.owned_buildings) do + if df.building_bedst:is_instance(b) then + has_bed = true end end + if has_bed then + add('uwith', u) + else + add('uwithout', u) + end end for _, bed in pairs(world.items.other.BED) do add('beds', bed) diff --git a/gui/family-affairs.lua b/gui/family-affairs.lua index b25d2de989..1dd08b8475 100644 --- a/gui/family-affairs.lua +++ b/gui/family-affairs.lua @@ -1,32 +1,5 @@ -- gui/family-affairs -- derived from v1.2 @ http://www.bay12forums.com/smf/index.php?topic=147779 -local helpstr = [====[ - -gui/family-affairs -================== -A user-friendly interface to view romantic relationships, -with the ability to add, remove, or otherwise change them at -your whim - fantastic for depressed dwarves with a dead spouse -(or matchmaking players...). - -The target/s must be alive, sane, and in fortress mode. - -.. image:: /docs/images/family-affairs.png - :align: center - -``gui/family-affairs [unitID]`` - shows GUI for the selected unit, or the specified unit ID - -``gui/family-affairs divorce [unitID]`` - removes all spouse and lover information from the unit - and it's partner, bypassing almost all checks. - -``gui/family-affairs [unitID] [unitID]`` - divorces the two specified units and their partners, - then arranges for the two units to marry, bypassing - almost all checks. Use with caution. - -]====] local dlg = require ('gui.dialogs') @@ -187,9 +160,8 @@ function ChooseNewSpouse (source) local choicelist = {} targetlist = {} - for k,v in pairs (df.global.world.units.active) do - if dfhack.units.isCitizen(v) - and v.race == source.race + for k,v in pairs (dfhack.units.getCitizens()) do + if v.race == source.race and v.sex ~= source.sex and v.relationship_ids.Spouse == -1 and v.relationship_ids.Lover == -1 @@ -250,10 +222,11 @@ end local args = {...} -if args[1] == "help" or args[1] == "?" then print(helpstr) return end +if args[1] == "help" or args[1] == "?" then print(dfhack.script_help()) return end if not dfhack.world.isFortressMode() then - print (helpstr) qerror ("invalid game mode") return + print(dfhack.script_help()) + qerror("invalid game mode") return end if args[1] == "divorce" and tonumber(args[2]) then @@ -278,13 +251,13 @@ if tonumber(args[1]) then end if selected then - if dfhack.units.isCitizen(selected) and dfhack.units.isSane(selected) then + if dfhack.units.isCitizen(selected) then MainDialog(selected) else qerror("You must select a sane fortress citizen.") return end else - print (helpstr) + print(dfhack.script_help()) qerror("Select a sane fortress dwarf") end diff --git a/gui/teleport.lua b/gui/teleport.lua index 8f9686da7b..5341fc5993 100644 --- a/gui/teleport.lua +++ b/gui/teleport.lua @@ -24,7 +24,9 @@ local function is_good_unit(include, unit) then return false end - if dfhack.units.isCitizen(unit) then return include.citizens end + if dfhack.units.isCitizen(unit) or dfhack.units.isResident(unit) then + return include.citizens + end local dangerous = dfhack.units.isDanger(unit) if not dangerous then return include.friendly end return include.hostile @@ -221,6 +223,7 @@ function Teleport:refresh_choices() for _, unit in ipairs(self.selected_units.list) do local suffix = '' if dfhack.units.isCitizen(unit) then suffix = ' (citizen)' + elseif dfhack.units.isResident(unit) then suffix = ' (resident)' elseif dfhack.units.isDanger(unit) then suffix = ' (hostile)' elseif dfhack.units.isMerchant(unit) or dfhack.units.isForest(unit) then suffix = ' (merchant)' diff --git a/max-wave.lua b/max-wave.lua index bb78e91304..56952c51e1 100644 --- a/max-wave.lua +++ b/max-wave.lua @@ -2,28 +2,13 @@ local args = {...} local wave_size = tonumber(args[1]) local max_pop = tonumber(args[2]) -local current_pop = 0 +local current_pop = #dfhack.units.getCitizens() if not wave_size then print(dfhack.script_help()) qerror('max-wave: wave_size required') end -local function isCitizen(unit) - return dfhack.units.isCitizen(unit) or - (dfhack.units.isOwnCiv(unit) and - dfhack.units.isAlive(unit) and - df.global.world.raws.creatures.all[unit.race].caste[unit.caste].flags.CAN_LEARN and - not (dfhack.units.isMerchant(unit) or dfhack.units.isForest(unit) or unit.flags1.diplomat or unit.flags2.visitor)) - end - ---One would think the game would track this value somewhere... -for k,v in ipairs(df.global.world.units.active) do - if isCitizen(v) then - current_pop = current_pop + 1 - end - end - local new_limit = current_pop + wave_size if max_pop and new_limit > max_pop then new_limit = max_pop end diff --git a/rejuvenate.lua b/rejuvenate.lua index 38eb181fa6..f6eb582673 100644 --- a/rejuvenate.lua +++ b/rejuvenate.lua @@ -33,11 +33,7 @@ function main(args) local current_year, newbirthyear local units = {} --as:df.unit[] if args.all then - for _, u in ipairs(df.global.world.units.all) do - if dfhack.units.isCitizen(u) then - table.insert(units, u) - end - end + units = dfhack.units.getCitizens() else table.insert(units, dfhack.gui.getSelectedUnit(true) or qerror("No unit under cursor! Aborting.")) end diff --git a/siren.lua b/siren.lua index 6a53f17a11..f3d9967b97 100644 --- a/siren.lua +++ b/siren.lua @@ -1,16 +1,6 @@ -- Wakes up the sleeping, ends parties ---[====[ -siren -===== -Wakes up sleeping units and stops parties, either everywhere or in the burrows -given as arguments. In return, adds bad thoughts about noise, tiredness and lack -of protection. The script is intended for emergencies, e.g. when a siege -appears, and all your military is partying. - -]====] - -local utils = require 'utils' +local utils = require('utils') local args = {...} local burrows = {} --as:df.burrow[] @@ -90,9 +80,9 @@ for _,v in ipairs(df.global.plotinfo.invasions.list) do end -- Stop rest -for _,v in ipairs(df.global.world.units.active) do +for _,v in ipairs(dfhack.units.getCitizens()) do local x,y,z = dfhack.units.getPosition(v) - if x and dfhack.units.isCitizen(v) and is_in_burrows(xyz2pos(x,y,z)) then + if x and is_in_burrows(xyz2pos(x,y,z)) then if not in_siege and v.military.squad_id < 0 then add_thought(v, df.emotion_type.Nervousness, df.unit_thought_type.LackProtection) end diff --git a/superdwarf.lua b/superdwarf.lua index eb3b3b0648..16f3cacffb 100644 --- a/superdwarf.lua +++ b/superdwarf.lua @@ -57,10 +57,8 @@ commands = { repeatUtil.scheduleEvery(timerId, 1, 'ticks', onTimer) end, all = function(arg) - for _, unit in pairs(df.global.world.units.active) do - if dfhack.units.isCitizen(unit) then - commands.add(unit) - end + for _, unit in pairs(dfhack.units.getCitizens()) do + commands.add(unit) end end, del = function(arg) From 68ca4e67a532d924d31d0d18bbb87d3feb0499f5 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 14 Mar 2024 18:45:05 -0700 Subject: [PATCH 3/4] get all citizens/residents; don't filter by race --- pref-adjust.lua | 45 ++++++--------------------------------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/pref-adjust.lua b/pref-adjust.lua index 9eae2aad34..a783c97094 100644 --- a/pref-adjust.lua +++ b/pref-adjust.lua @@ -1,34 +1,5 @@ -- Adjust all preferences of one or all dwarves in play -- by vjek ---[====[ - -pref-adjust -=========== -``pref-adjust all`` removes/changes preferences from all dwarves, and -``pref-adjust one`` which works for a single currently selected dwarf. -For either, the script inserts an 'ideal' set which is easy to satisfy: - - ... likes iron, steel, weapons, armor, shields/bucklers and plump helmets - for their rounded tops. When possible, she prefers to consume dwarven - wine, plump helmets, and prepared meals (quarry bush). She absolutely - detests trolls, buzzards, vultures and crundles. - -Additionally, ``pref-adjust goth`` will insert a less than ideal set, which -is quite challenging, for a single dwarf: - - ... likes dwarf skin, corpses, body parts, remains, coffins, the color - black, crosses, glumprongs for their living shadows and snow demons for - their horrifying features. When possible, she prefers to consume sewer - brew, gutter cruor and bloated tubers. She absolutely detests elves, - humans and dwarves. - -To see what values can be used with each type of preference, use -``pref-adjust list``. Optionally, a single dwarf or all dwarves can have -their preferences cleared manually with the use of ``pref-adjust clear`` -and ``pref-adjust clear_all``, respectively. Existing preferences are -automatically cleared, normally. - -]====] utils = require 'utils' pss_counter = pss_counter or 31415926 @@ -172,20 +143,16 @@ function clear_preferences(unit) end -- --------------------------------------------------------------------------- function clearpref_all_dwarves() - for _,unit in ipairs(df.global.world.units.active) do - if unit.race == df.global.plotinfo.race_id then - print("Clearing Preferences for "..unit_name_to_console(unit)) - clear_preferences(unit) - end + for _,unit in ipairs(dfhack.units.getCitizens()) do + print("Clearing Preferences for "..unit_name_to_console(unit)) + clear_preferences(unit) end end -- --------------------------------------------------------------------------- function adjust_all_dwarves(profile) - for _,unit in ipairs(df.global.world.units.active) do - if unit.race == df.global.plotinfo.race_id then - print("Adjusting "..unit_name_to_console(unit)) - brainwash_unit(unit,profile) - end + for _,unit in ipairs(dfhack.units.getCitizens()) do + print("Adjusting "..unit_name_to_console(unit)) + brainwash_unit(unit,profile) end end -- --------------------------------------------------------------------------- From a6bf5c68dbfb9198faeef8eec161d924cbe79726 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Thu, 14 Mar 2024 19:18:10 -0700 Subject: [PATCH 4/4] more citizen/resident check updates --- animal-control.lua | 75 +-------------------------- armoks-blessing.lua | 63 +++++----------------- clear-webs.lua | 37 ++----------- deathcause.lua | 13 +---- devel/all-bob.lua | 11 +--- docs/modtools/set-personality.rst | 2 +- fix/corrupt-jobs.lua | 2 +- fix/protect-nicks.lua | 2 +- fixnaked.lua | 11 +--- gui/masspit.lua | 2 +- gui/unit-syndromes.lua | 2 +- modtools/extra-gamelog.lua | 18 +------ modtools/set-belief.lua | 79 ++-------------------------- modtools/set-personality.lua | 86 ++----------------------------- prefchange.lua | 46 +++-------------- remove-stress.lua | 20 ++----- view-unit-reports.lua | 11 ---- 17 files changed, 48 insertions(+), 432 deletions(-) diff --git a/animal-control.lua b/animal-control.lua index f77f1c6b29..65c3364e81 100644 --- a/animal-control.lua +++ b/animal-control.lua @@ -19,79 +19,6 @@ local validArgs = utils.invert({ 'help', }) local args = utils.processArgs({...}, validArgs) -local help = [====[ - -animal-control -============== -Animal control is a script useful for deciding what animals to butcher and geld. - -While not as powerful as Dwarf Therapist in managing animals - in so far as -DT allows you to sort by various stats and flags - this script does provide -many options for filtering animals. Additionally you can mark animals for -slaughter or gelding, you can even do so enmasse if you so choose. - -Examples:: - - animal-control -race DOG - animal-control -race DOG -male -notgelded -showstats - animal-control -markfor gelding -id 1988 - animal-control -markfor slaughter -id 1988 - animal-control -gelded -markedfor slaughter -unmarkfor slaughter - -**Selection options:** - -These options are used to specify what animals you want or do not want to select. - -``-all``: Selects all units. - Note: cannot be used in conjunction with other - selection options. - -``-id ``: Selects the unit with the specified id value provided. - -``-race ``: Selects units which match the race value provided. - -``-markedfor ``: Selects units which have been marked for the action provided. - Valid actions: ``slaughter``, ``gelding`` - -``-notmarkedfor ``: Selects units which have not been marked for the action provided. - Valid actions: ``slaughter``, ``gelding`` - -``-gelded``: Selects units which have already been gelded. - -``-notgelded``: Selects units which have not been gelded. - -``-male``: Selects units which are male. - -``-female``: Selects units which are female. - -**Command options:** - -- ``-showstats``: Displays physical attributes of the selected animals. - -- ``-markfor ``: Marks selected animals for the action provided. - Valid actions: ``slaughter``, ``gelding`` - -- ``-unmarkfor ``: Unmarks selected animals for the action provided. - Valid actions: ``slaughter``, ``gelding`` - -**Other options:** - -- ``-help``: Displays this information - -**Column abbreviations** - -Due to space constraints, the names of some output columns are abbreviated -as follows: - -- ``str``: strength -- ``agi``: agility -- ``tgh``: toughness -- ``endur``: endurance -- ``recup``: recuperation -- ``disres``: disease resistance - -]====] - header_format = "%-20s %-9s %-9s %-5s %-22s %-8s %-25s" row_format = "%-20s %-9d %-9d %-5s %-22s %-8s %-25s" @@ -125,7 +52,7 @@ bcommands = (args.showstats or args.markfor or args.unmarkfor) bvalid = (args.all and not bfilters) or (not args.all and (bfilters or bcommands)) if args.help or not bvalid then - print(help) + print(dfhack.script_help()) else count=0 if args.showstats then diff --git a/armoks-blessing.lua b/armoks-blessing.lua index 7dc2c62a6e..69d240b8fe 100644 --- a/armoks-blessing.lua +++ b/armoks-blessing.lua @@ -1,43 +1,8 @@ -- Adjust all attributes of all dwarves to an ideal -- by vjek ---[====[ -armoks-blessing -=============== -Runs the equivalent of `rejuvenate`, `elevate-physical`, `elevate-mental`, and -`brainwash` on all dwarves currently on the map. This is an extreme change, -which sets every stat and trait to an ideal easy-to-satisfy preference. +local utils = require('utils') -Without providing arguments, only attributes, age, and personalities will be adjusted. -Adding arguments allows for skills or classes to be adjusted to legendary (maximum). - -Arguments: - -- ``list`` - Prints list of all skills - -- ``classes`` - Prints list of all classes - -- ``all`` - Set all skills, for all Dwarves, to legendary - -- ```` - Set a specific skill, for all Dwarves, to legendary - - example: ``armoks-blessing RANGED_COMBAT`` - - All Dwarves become a Legendary Archer - -- ```` - Set a specific class (group of skills), for all Dwarves, to legendary - - example: ``armoks-blessing Medical`` - - All Dwarves will have all medical related skills set to legendary - -]====] -local utils = require 'utils' function rejuvenate(unit) if unit==nil then print ("No unit available! Aborting with extreme prejudice.") @@ -278,20 +243,18 @@ function PrintSkillClassList() end -- --------------------------------------------------------------------------- function adjust_all_dwarves(skillname) - for _,v in ipairs(df.global.world.units.all) do - if v.race == df.global.plotinfo.race_id and v.status.current_soul then - print("Adjusting "..dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(v)))) - brainwash_unit(v) - elevate_attributes(v) - rejuvenate(v) - if skillname then - if df.job_skill_class[skillname] then - LegendaryByClass(skillname,v) - elseif skillname=="all" then - BreathOfArmok(v) - else - make_legendary(skillname,v) - end + for _,v in ipairs(dfhack.units.getCitizens()) do + print("Adjusting "..dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(v)))) + brainwash_unit(v) + elevate_attributes(v) + rejuvenate(v) + if skillname then + if df.job_skill_class[skillname] then + LegendaryByClass(skillname,v) + elseif skillname=="all" then + BreathOfArmok(v) + else + make_legendary(skillname,v) end end end diff --git a/clear-webs.lua b/clear-webs.lua index 37f1939da3..bab8086da5 100644 --- a/clear-webs.lua +++ b/clear-webs.lua @@ -1,36 +1,7 @@ -- Removes webs and frees webbed units. -- Author: Atomic Chicken -local usage = [====[ - -clear-webs -========== -This script removes all webs that are currently on the map, -and also frees any creatures who have been caught in one. - -Note that it does not affect sprayed webs until -they settle on the ground. - -Usable in both fortress and adventurer mode. - -Web removal and unit release happen together by default. -The following may be used to isolate one of these actions: - -Arguments:: - - -unitsOnly - Include this if you want to free all units from webs - without removing any webs - - -websOnly - Include this if you want to remove all webs - without freeing any units - -See also `fix/drop-webs`. - -]====] - -local utils = require 'utils' +local utils = require('utils') local validArgs = utils.invert({ 'unitsOnly', 'websOnly', @@ -39,12 +10,12 @@ local validArgs = utils.invert({ local args = utils.processArgs({...}, validArgs) if args.help then - print(usage) + print(dfhack.script_help()) return end if args.unitsOnly and args.websOnly then - qerror("You have specified both -unitsOnly and -websOnly. These cannot be used together.") + qerror("You have specified both --unitsOnly and --websOnly. These cannot be used together.") end local webCount = 0 @@ -57,7 +28,7 @@ end local unitCount = 0 if not args.websOnly then - for _, unit in ipairs(df.global.world.units.all) do + for _, unit in ipairs(df.global.world.units.active) do if unit.counters.webbed > 0 and not unit.flags2.killed and not unit.flags1.inactive then -- the webbed status is retained in death unitCount = unitCount + 1 unit.counters.webbed = 0 diff --git a/deathcause.lua b/deathcause.lua index 7939898597..955216b1c7 100644 --- a/deathcause.lua +++ b/deathcause.lua @@ -15,15 +15,6 @@ function getItemsAtPosition(pos_x, pos_y, pos_z, item_type) return items end --- Finds a unit with the given id or nil if no unit is found -function findUnit(unit_id) - if not unit_id or unit_id == -1 then - return nil - end - - return utils.binsearch(df.global.world.units.all, unit_id, 'id') -end - -- Find a histfig with the given id or nil if no unit is found function findHistFig(histfig_id) if not histfig_id or histfig_id == -1 then @@ -133,7 +124,7 @@ function getDeathEventForHistFig(histfig_id) end function displayDeathHistFig(histfig) - local histfig_unit = findUnit(histfig.unit_id) + local histfig_unit = df.unit.find(histfig.unit_id) if not histfig_unit then qerror(("Failed to retrieve unit for histfig [histfig_id: %d, histfig_unit_id: %d"):format( histfig.id, @@ -178,7 +169,7 @@ if not hist_figure_id then qerror("Failed to find hist_figure_id. This is not user error") elseif hist_figure_id == -1 then if not selected_unit then - selected_unit = findUnit(selected_item.unit_id) + selected_unit = df.unit.find(selected_item.unit_id) if not selected_unit then qerror("Not a historical figure, cannot find death info") end diff --git a/devel/all-bob.lua b/devel/all-bob.lua index ef4dc32d0a..59a7fe09d4 100644 --- a/devel/all-bob.lua +++ b/devel/all-bob.lua @@ -1,15 +1,6 @@ -- Changes the first name of all units to "Bob" --author expwnent --- ---[====[ -devel/all-bob -============= -Changes the first name of all units to "Bob". -Useful for testing `modtools/interaction-trigger` events. - -]====] - -for _,v in ipairs(df.global.world.units.all) do +for _,v in ipairs(df.global.world.units.active) do v.name.first_name = "Bob" end diff --git a/docs/modtools/set-personality.rst b/docs/modtools/set-personality.rst index 9c8d1d45fe..d661b82cb0 100644 --- a/docs/modtools/set-personality.rst +++ b/docs/modtools/set-personality.rst @@ -21,7 +21,7 @@ Target options -------------- ``--citizens`` - All (sane) citizens of your fort will be affected. Will do nothing in + All citizens and residents of your fort will be affected. Will do nothing in adventure mode. ``--unit `` The given unit will be affected. diff --git a/fix/corrupt-jobs.lua b/fix/corrupt-jobs.lua index de6eed2e7b..556e067aee 100644 --- a/fix/corrupt-jobs.lua +++ b/fix/corrupt-jobs.lua @@ -6,7 +6,7 @@ local GLOBAL_KEY = 'corrupt-jobs' function remove_bad_jobs() local count = 0 - for _, unit in ipairs(df.global.world.units.all) do + for _, unit in ipairs(df.global.world.units.active) do if unit.job.current_job and unit.job.current_job.id == -1 then unit.job.current_job = nil count = count + 1 diff --git a/fix/protect-nicks.lua b/fix/protect-nicks.lua index ed573c5b60..e5f89168ce 100644 --- a/fix/protect-nicks.lua +++ b/fix/protect-nicks.lua @@ -17,7 +17,7 @@ end -- Reassign all the units nicknames with "dfhack.units.setNickname" local function save_nicks() - for _,unit in pairs(df.global.world.units.active) do + for _,unit in ipairs(df.global.world.units.active) do dfhack.units.setNickname(unit, unit.name.nickname) end end diff --git a/fixnaked.lua b/fixnaked.lua index 725ab6f9c1..916d8f5ad3 100644 --- a/fixnaked.lua +++ b/fixnaked.lua @@ -1,18 +1,11 @@ --removes unhappy thoughts due to lack of clothing ---[====[ - -fixnaked -======== -Removes all unhappy thoughts due to lack of clothing. - -]====] function fixnaked() local total_fixed = 0 local total_removed = 0 -for fnUnitCount,fnUnit in ipairs(df.global.world.units.all) do - if fnUnit.race == df.global.plotinfo.race_id and fnUnit.status.current_soul then +for fnUnitCount,fnUnit in ipairs(dfhack.units.getCitizens()) do + if fnUnit.status.current_soul then local found = true local fixed = false while found do diff --git a/gui/masspit.lua b/gui/masspit.lua index f7d77176bb..cc83ee847e 100644 --- a/gui/masspit.lua +++ b/gui/masspit.lua @@ -160,7 +160,7 @@ function Masspit:setPit(_, choice) local choices = {} for _, unit_id in pairs(self.caged_units) do - local unit = utils.binsearch(df.global.world.units.all, unit_id, 'id') + local unit = df.unit.find(unit_id) local unit_name = unit.name.has_name and dfhack.TranslateName(unit.name) or dfhack.units.getRaceNameById(unit.race) -- Prevents duplicate units in assignments, which can cause crashes. diff --git a/gui/unit-syndromes.lua b/gui/unit-syndromes.lua index 6807f59e4a..8384638d2d 100644 --- a/gui/unit-syndromes.lua +++ b/gui/unit-syndromes.lua @@ -481,7 +481,7 @@ function UnitSyndromes:showUnits(index, choice) end function UnitSyndromes:showUnitSyndromes(index, choice) - local unit = utils.binsearch(df.global.world.units.all, choice.unit_id, 'id') + local unit = df.unit.find(choice.unit_id) local unit_syndromes = getUnitSyndromes(unit) local choices = {} diff --git a/modtools/extra-gamelog.lua b/modtools/extra-gamelog.lua index c2360758c8..343b5ef34a 100644 --- a/modtools/extra-gamelog.lua +++ b/modtools/extra-gamelog.lua @@ -1,17 +1,4 @@ -- Regularly writes extra info to gamelog.txt -local help = [====[ - -modtools/extra-gamelog -====================== -This script writes extra information to the gamelog. -This is useful for tools like :forums:`Soundsense <106497>`. - -Usage:: - - modtools/extra-gamelog enable - modtools/extra-gamelog disable - -]====] local msg = dfhack.gui.writeToGamelog @@ -64,7 +51,6 @@ function log_nobles() local expedition_leader = nil local mayor = nil local function check(unit) - if not dfhack.units.isCitizen(unit) then return end for _, pos in ipairs(dfhack.units.getNoblePositions(unit) or {}) do if pos.position.name[0] == "expedition leader" then expedition_leader = unit @@ -73,7 +59,7 @@ function log_nobles() end end end - for _, unit in ipairs(df.global.world.units.active) do + for _, unit in ipairs(dfhack.units.getCitizens()) do check(unit) end @@ -194,5 +180,5 @@ elseif args[1] == 'enable' then extra_gamelog_enabled = true event_loop() else - print(help) + print(dfhack.script_help()) end diff --git a/modtools/set-belief.lua b/modtools/set-belief.lua index fa16095eea..b0b3019218 100644 --- a/modtools/set-belief.lua +++ b/modtools/set-belief.lua @@ -6,75 +6,8 @@ > When using script functions, use numerical IDs for representing beliefs. > The random assignment is placeholder for now. I don't understand how they work ]] -local help = [====[ - -modtools/set-belief -=================== -Changes the beliefs (values) of units. -Requires a belief, modifier, and a target. - -Valid beliefs: - -:all: - Apply the edit to all the target's beliefs -:belief : - ID of the belief to edit. For example, 0 or LAW. - -Valid modifiers: - -:set <-50-50>: - Set belief to given strength. -:tier <1-7>: - Set belief to within the bounds of a strength tier: - - ===== ======== - Value Strength - ===== ======== - 1 Lowest - 2 Very Low - 3 Low - 4 Neutral - 5 High - 6 Very High - 7 Highest - ===== ======== - -:modify : - Modify current belief strength by given amount. - Negative values need a ``\`` before the negative symbol e.g. ``\-1`` -:step : - Modify current belief tier up/down by given amount. - Negative values need a ``\`` before the negative symbol e.g. ``\-1`` -:random: - Use the default probabilities to set the belief to a new random value. -:default: - Belief will be set to cultural default. - -Valid targets: - -:citizens: - All (sane) citizens of your fort will be affected. Will do nothing in adventure mode. -:unit : - The given unit will be affected. - -If no target is given, the provided unit can't be found, or no unit id is given with the unit -argument, the script will try and default to targeting the currently selected unit. - -Other arguments: - -:help: - Shows this help page. -:list: - Prints a list of all beliefs + their IDs. -:noneed: - By default, unit's needs will be recalculated to reflect new beliefs after every run. - Use this argument to disable that functionality. -:listunit: - Prints a list of all a unit's beliefs. Cultural defaults are marked with ``*``. - -]====] - -local utils = require 'utils' + +local utils = require('utils') local validArgs = utils.invert({ "all", @@ -352,7 +285,7 @@ function main(...) local setneed = dfhack.reqscript("modtools/set-need") if args.help then - print(help) + print(dfhack.script_help()) return end @@ -396,11 +329,7 @@ function main(...) qerror("-citizens argument only available in Fortress Mode.") end - for _, unit in pairs(df.global.world.units.active) do - if dfhack.units.isCitizen(unit) then - table.insert(unitsList, unit) - end - end + unitsList = dfhack.units.getCitizens(false, true) end -- Belief check diff --git a/modtools/set-personality.lua b/modtools/set-personality.lua index 12655b496a..c0136c56a5 100644 --- a/modtools/set-personality.lua +++ b/modtools/set-personality.lua @@ -5,78 +5,7 @@ > When using script functions, use numerical IDs for representing personality traits. ]] --- hey set-belief, can I copy your homework? --- sure, just change it up a bit so it doesn't look obvious you copied --- ok -local help = [====[ - -modtools/set-personality -======================== -Changes the personality of units. -Requires a trait, modifier, and a target. - -Valid traits: - -:all: - Apply the edit to all the target's traits -:trait : - ID of the trait to edit. For example, 0 or HATE_PROPENSITY. - -Valid modifiers: - -:set <0-100>: - Set trait to given strength. -:tier <1-7>: - Set trait to within the bounds of a strength tier. - - ===== ======== - Value Strength - ===== ======== - 1 Lowest - 2 Very Low - 3 Low - 4 Neutral - 5 High - 6 Very High - 7 Highest - ===== ======== - -:modify : - Modify current base trait strength by given amount. - Negative values need a ``\`` before the negative symbol e.g. ``\-1`` -:step : - Modify current trait tier up/down by given amount. - Negative values need a ``\`` before the negative symbol e.g. ``\-1`` -:random: - Set the trait to a new random value. -:average: - Sets trait to the creature's caste's average value (as defined in the PERSONALITY creature tokens). - -Valid targets: - -:citizens: - All (sane) citizens of your fort will be affected. Will do nothing in adventure mode. -:unit : - The given unit will be affected. - -If no target is given, the provided unit can't be found, or no unit id is given with the unit -argument, the script will try and default to targeting the currently selected unit. - -Other arguments: - -:help: - Shows this help page. -:list: - Prints a list of all facets + their IDs. -:noneed: - By default, unit's needs will be recalculated to reflect new traits after every run. - Use this argument to disable that functionality. -:listunit: - Prints a list of all a unit's personality traits, with their modified trait value in brackets. - -]====] - -local utils = require 'utils' +local utils = require('utils') local validArgs = utils.invert({ "all", @@ -330,7 +259,7 @@ function main(...) local setneed = dfhack.reqscript("modtools/set-need") if args.help then - print(help) + print(dfhack.script_help()) return end @@ -366,19 +295,12 @@ function main(...) table.insert(unitsList, unit) end elseif args.citizens then - -- Technically this will exclude insane citizens, but this is the - -- easiest thing that dfhack provides - -- Abort if not in Fort mode if not dfhack.world.isFortressMode() then - qerror("-citizens argument only available in Fortress Mode.") + qerror("--citizens argument only available in Fortress Mode.") end - for _, unit in pairs(df.global.world.units.active) do - if dfhack.units.isCitizen(unit) then - table.insert(unitsList, unit) - end - end + unitsList = dfhack.units.getCitizens(false, true) end -- Trait check diff --git a/prefchange.lua b/prefchange.lua index 96a836610a..826d1670bd 100644 --- a/prefchange.lua +++ b/prefchange.lua @@ -4,35 +4,7 @@ -- updated with print all and clear all functions on the 11th of April 2015 -- Praise Armok! ---[====[ - -prefchange -========== -Sets preferences for mooding to include a weapon type, equipment type, -and material. If you also wish to trigger a mood, see -`strangemood`. - -Valid options: - -:show: show preferences of all units -:c: clear preferences of selected unit -:all: clear preferences of all units -:axp: likes axes, breastplates, and steel -:has: likes hammers, mail shirts, and steel -:swb: likes short swords, high boots, and steel -:spb: likes spears, high boots, and steel -:mas: likes maces, shields, and steel -:xbh: likes crossbows, helms, and steel -:pig: likes picks, gauntlets, and steel -:log: likes long swords, gauntlets, and steel -:dap: likes daggers, greaves, and steel - -Feel free to adjust the values as you see fit, change the has steel to -platinum, change the axp axes to great axes, whatnot. - -]====] - -local utils = require 'utils' +local utils = require('utils') -- --------------------------------------------------------------------------- function axeplate() @@ -302,20 +274,16 @@ function clear_all(v) end -- --------------------------------------------------------------------------- function printpref_all_dwarves() - for _,v in ipairs(df.global.world.units.active) do - if v.race == df.global.plotinfo.race_id then - print("Showing Preferences for "..dfhack.TranslateName(dfhack.units.getVisibleName(v))) - print_all(v) - end + for _,v in ipairs(dfhack.units.getCitizens()) do + print("Showing Preferences for "..dfhack.TranslateName(dfhack.units.getVisibleName(v))) + print_all(v) end end -- --------------------------------------------------------------------------- function clearpref_all_dwarves() - for _,v in ipairs(df.global.world.units.active) do - if v.race == df.global.plotinfo.race_id then - print("Clearing Preferences for "..dfhack.TranslateName(dfhack.units.getVisibleName(v))) - clear_all(v) - end + for _,v in ipairs(dfhack.units.getCitizens()) do + print("Clearing Preferences for "..dfhack.TranslateName(dfhack.units.getVisibleName(v))) + clear_all(v) end end -- --------------------------------------------------------------------------- diff --git a/remove-stress.lua b/remove-stress.lua index e92ccb4b80..76bdee9dac 100644 --- a/remove-stress.lua +++ b/remove-stress.lua @@ -2,22 +2,8 @@ --By Putnam; http://www.bay12forums.com/smf/index.php?topic=139553.msg5820486#msg5820486 --edited by Bumber --@module = true -local help = [====[ -remove-stress -============= -Sets stress to -1,000,000; the normal range is 0 to 500,000 with very stable or -very stressed dwarves taking on negative or greater values respectively. -Applies to the selected unit, or use ``remove-stress -all`` to apply to all units. - -Using the argument ``-value 0`` will reduce stress to the value 0 instead of -1,000,000. -Negative values must be preceded by a backslash (\): ``-value \-10000``. -Note that this can only be used to *decrease* stress - it cannot be increased -with this argument. - -]====] - -local utils = require 'utils' +local utils = require('utils') function removeStress(unit,value) if unit.counters.soldier_mood > df.unit.T_counters.T_soldier_mood.Enraged then @@ -42,7 +28,7 @@ function main(...) local stress_value = -1000000 if args.help then - print(help) + print(dfhack.script_help()) return end @@ -55,7 +41,7 @@ function main(...) end if args.all then - for k,v in ipairs(df.global.world.units.active) do + for k,v in ipairs(dfhack.units.getCitizens()) do removeStress(v,stress_value) end else diff --git a/view-unit-reports.lua b/view-unit-reports.lua index e6ef103c5b..ece49be340 100644 --- a/view-unit-reports.lua +++ b/view-unit-reports.lua @@ -1,15 +1,4 @@ -- View combat reports for currently selected unit ---[====[ - -view-unit-reports -================= -Show combat reports for the current unit. - -Current unit is unit near cursor in 'v', selected in 'u' list, -unit/corpse/splatter at cursor in 'k'. And newest unit with race when -'k' at race-specific blood spatter. - -]====] local function get_combat_logs(unit) local output = {}