Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

script for debugging items being assigned to multiple squads #902

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions devel/equipment-conflicts.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
--[[

This script analyzes uniforms of squad members and reports items that are
claimed by more than one squad member.

--]]
Comment on lines +1 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already in the docs and doesn't need to be repeated here


local assignments = {}

-- TODO: gather the item assignments we would like to remove.
-- TOTHINK: just removing them from the uniform and pick-up tables is insufficient.
-- conflicting items just get added back.
-- local release = {}

local function addToNestedTable(outer_table, outer_key, value)
if outer_table[outer_key] then
table.insert(outer_table[outer_key],value)
else
outer_table[outer_key] = { value }
end
end
Comment on lines +15 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can replace with table.insert(ensure_key(outer_table, outer_key), value)


-- analyze uniforms of squad members
for _, unit in pairs(dfhack.units.getCitizens(true)) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functionally the same, but semantically, this is an ipairs

local squad_id = unit.military.squad_id
if 0 <= squad_id then
for _, item_id in ipairs(unit.military.uniforms[unit.military.cur_uniform]) do
addToNestedTable(assignments,item_id,unit.id)
end
end
end

-- check for and report conflicts
for item_id,unit_ids in pairs(assignments) do
if #unit_ids > 1 then
local item = df.item.find(item_id)
if item then
local holder = dfhack.items.getHolderUnit(item)
local found = false
print(dfhack.items.getDescription(item, 0, true),'(',item_id,') claimed by:')
for _,unit_id in pairs(unit_ids) do
local unit = df.unit.find(unit_id)
if unit then
dfhack.print(
' ', dfhack.TranslateName(unit.name),'in',
dfhack.military.getSquadName(unit.military.squad_id)
)
if holder and unit.id == holder.id then
found = true
print (' (equipped)')
else
print()
-- addToNestedTable(release,unit.id,item_id)
end
end
end
if not found then
if holder then
print(' carried by', dfhack.TranslateName(holder.name))
else
print(' no current holder')
end
end
print()
else
error('assigned item does not exist')
end
end
end
17 changes: 17 additions & 0 deletions docs/devel/equipment-conflicts.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
devel/equipment-conflicts
=========================

.. dfhack-tool::
:summary: Tool for debugging equipment conflicts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:summary: Tool for debugging equipment conflicts
:summary: Tool for debugging equipment conflicts.

:tags: dev

This script analyzes uniforms of squad members and reports items that are
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't "uniforms" the templates, and not the actual worn items?

claimed by more than one squad member as well as the current holder of the item
(if any).

Usage
-----

::

devel/equipment-conflicts