Skip to content

Commit

Permalink
Merge pull request #1046 from myk002/myk_resident
Browse files Browse the repository at this point in the history
include residents in citizens list where applicable
  • Loading branch information
myk002 authored Mar 15, 2024
2 parents 72e3d34 + a6bf5c6 commit 2d94de9
Show file tree
Hide file tree
Showing 46 changed files with 129 additions and 720 deletions.
10 changes: 3 additions & 7 deletions adaptation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions allneeds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
75 changes: 1 addition & 74 deletions animal-control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 <value>``: Selects the unit with the specified id value provided.
``-race <value>``: Selects units which match the race value provided.
``-markedfor <action>``: Selects units which have been marked for the action provided.
Valid actions: ``slaughter``, ``gelding``
``-notmarkedfor <action>``: 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 <action>``: Marks selected animals for the action provided.
Valid actions: ``slaughter``, ``gelding``
- ``-unmarkfor <action>``: 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"
Expand Down Expand Up @@ -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
Expand Down
63 changes: 13 additions & 50 deletions armoks-blessing.lua
Original file line number Diff line number Diff line change
@@ -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
- ``<skill name>``
Set a specific skill, for all Dwarves, to legendary
example: ``armoks-blessing RANGED_COMBAT``
All Dwarves become a Legendary Archer
- ``<class name>``
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.")
Expand Down Expand Up @@ -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
Expand Down
41 changes: 5 additions & 36 deletions autonick.lua
Original file line number Diff line number Diff line change
@@ -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 [<options>]
autonick help
Options:
:``-h``, ``--help``:
Show this text.
:``-q``, ``--quiet``:
Do not report how many dwarves were given nicknames.
]====]

local options = {}

Expand All @@ -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
Expand All @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions build-now.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 4 additions & 33 deletions clear-webs.lua
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion combat-harden.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions deathcause.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 2d94de9

Please sign in to comment.