Skip to content

Commit fb3f2d1

Browse files
committed
Refactor item description logging in uniform-unstick
1 parent cdf3ebb commit fb3f2d1

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

uniform-unstick.lua

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ local validArgs = utils.invert({
1616
-- Functions
1717

1818
local function item_description(item)
19-
return dfhack.df2console(dfhack.items.getDescription(item, 0, true))
19+
return "item #" .. item.id .. " '" .. dfhack.df2console(dfhack.items.getDescription(item, 0, true)) .. "'"
2020
end
2121

2222
local function get_item_pos(item)
@@ -166,11 +166,10 @@ local function process(unit, args, need_newline)
166166
for u_id, item in pairs(assigned_items) do
167167
if not worn_items[u_id] then
168168
if not silent then
169-
need_newline = print_line(unit_name .. " is missing an assigned item, object #" .. u_id .. " '" ..
170-
item_description(item) .. "'", need_newline)
169+
need_newline = print_line(unit_name .. " is missing an assigned item, " .. item_description(item), need_newline)
171170
end
172171
if dfhack.items.getGeneralRef(item, df.general_ref_type.UNIT_HOLDER) then
173-
need_newline = print_line(unit_name .. " cannot equip item: another unit has a claim on object #" .. u_id .. " '" .. item_description(item) .. "'", need_newline)
172+
need_newline = print_line(unit_name .. " cannot equip item: another unit has a claim on " .. item_description(item), need_newline)
174173
if args.free then
175174
print(" Removing from uniform")
176175
assigned_items[u_id] = nil
@@ -204,9 +203,9 @@ local function process(unit, args, need_newline)
204203
if assigned_items[u_id] == nil and u_id ~= squad_position.equipment.quiver and u_id ~= squad_position.equipment.backpack and u_id ~= squad_position.equipment.flask then
205204
local item = df.item.find(u_id)
206205
if item ~= nil then
207-
need_newline = print_line(unit_name .. " has an improperly assigned item, item # " .. u_id .. " '" .. item_description(item) .. "'; removing it")
206+
need_newline = print_line(unit_name .. " has an improperly assigned item, " .. item_description(item) .. '; removing it')
208207
else
209-
need_newline = print_line(unit_name .. " has a nonexistent item assigned, item # " .. u_id .. "; removing it")
208+
need_newline = print_line(unit_name .. " has a nonexistent item assigned, item # " .. u_id .. '; removing it')
210209
end
211210
squad_position.equipment.assigned_items:erase(i)
212211
end
@@ -240,9 +239,7 @@ local function process(unit, args, need_newline)
240239
for w_id, item in pairs(worn_items) do
241240
if assigned_items[w_id] == nil then -- don't drop uniform pieces (including shields, weapons for hands)
242241
if uncovered[worn_parts[w_id]] then
243-
need_newline = print_line(unit_name ..
244-
" potentially has object #" ..
245-
w_id .. " '" .. item_description(item) .. "' blocking a missing uniform item.", need_newline)
242+
need_newline = print_line(unit_name .. " potentially has " .. item_description(item) .. " blocking a missing uniform item.", need_newline)
246243
if args.drop then
247244
to_drop[w_id] = item
248245
end
@@ -261,12 +258,12 @@ local function do_drop(item_list)
261258
for id, item in pairs(item_list) do
262259
local pos = get_item_pos(item)
263260
if not pos then
264-
dfhack.printerr("Could not find drop location for item #" .. id .. " " .. item_description(item))
261+
dfhack.printerr("Could not find drop location for " .. item_description(item))
265262
else
266263
if dfhack.items.moveToGround(item, pos) then
267-
print("Dropped item #" .. id .. " '" .. item_description(item) .. "'")
264+
print("Dropped " .. item_description(item))
268265
else
269-
dfhack.printerr("Could not drop object #" .. id .. " " .. item_description(item))
266+
dfhack.printerr("Could not drop " .. item_description(item))
270267
end
271268
end
272269
end

0 commit comments

Comments
 (0)