Skip to content

Commit 2bd6edf

Browse files
committed
use the more robust item removal method
instead of just marking for garbage collection directly
1 parent 32bf2af commit 2bd6edf

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

deteriorate.lua

+1-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ local function deteriorate(opts, get_item_vectors_fn, is_valid_fn, increment_wea
109109
for _,item in ipairs(v) do
110110
if is_valid_fn(opts, item) and increment_wear_fn(item)
111111
and not item.flags.garbage_collect then
112-
item.flags.garbage_collect = true
113-
item.flags.hidden = true
112+
dfhack.items.remove(item)
114113
count = count + 1
115114
end
116115
end

devel/nuke-items.lua

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ local count = 0
44

55
for _,v in ipairs(df.global.world.items.all) do
66
if not (v.flags.in_building or v.flags.construction or v.flags.in_job
7-
or dfhack.items.getGeneralRef(v,df.general_ref_type.UNIT_HOLDER)) then
7+
or dfhack.items.getGeneralRef(v,df.general_ref_type.UNIT_HOLDER)) then
88
count = count + 1
9-
v.flags.forbid = true
10-
v.flags.garbage_collect = true
9+
dfhack.items.remove(v)
1110
end
1211
end
1312

full-heal.lua

+1-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ function heal(unit, resurrect, keep_corpse)
8383
for i = #corpses-1,0,-1 do
8484
local corpse = corpses[i] --as:df.item_body_component
8585
if corpse.unit_id == unit.id then
86-
corpse.flags.garbage_collect = true
87-
corpse.flags.forbid = true
88-
corpse.flags.hidden = true
86+
dfhack.items.remove(corpse)
8987
end
9088
end
9189
end

gui/autodump.lua

+6-5
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ function Autodump:do_destroy()
350350
print(('destroying %d items'):format(#items))
351351
for _,item in ipairs(items) do
352352
table.insert(self.destroyed_items, {item=item, flags=copyall(item.flags)})
353-
item.flags.garbage_collect = true
354353
item.flags.forbid = true
355354
item.flags.hidden = true
356355
end
@@ -363,7 +362,6 @@ function Autodump:undo_destroy()
363362
print(('undestroying %d items'):format(#self.destroyed_items))
364363
for _,item_spec in ipairs(self.destroyed_items) do
365364
local item = item_spec.item
366-
item.flags.garbage_collect = false
367365
item.flags.forbid = item_spec.flags.forbid
368366
item.flags.hidden = item_spec.flags.hidden
369367
end
@@ -384,16 +382,19 @@ AutodumpScreen.ATTRS {
384382
}
385383

386384
function AutodumpScreen:init()
387-
local window = Autodump{}
385+
self.window = Autodump{}
388386
self:addviews{
389-
window,
387+
self.window,
390388
widgets.DimensionsTooltip{
391-
get_anchor_pos_fn=function() return window.mark end,
389+
get_anchor_pos_fn=function() return self.window.mark end,
392390
},
393391
}
394392
end
395393

396394
function AutodumpScreen:onDismiss()
395+
for _,item_spec in ipairs(self.window.destroyed_items) do
396+
dfhack.items.remove(item_spec.item)
397+
end
397398
view = nil
398399
end
399400

modtools/invader-item-destroyer.lua

+1-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ eventful.onUnitDeath.invaderItemDestroyer = function(unitId)
8484
if item.pos.z ~= unit.pos.z then
8585
return
8686
end
87-
item.flags.garbage_collect = true
88-
item.flags.forbid = true
89-
item.flags.hidden = true
87+
dfhack.items.remove(item)
9088
end
9189

9290
for _,item in ipairs(unit.inventory) do

0 commit comments

Comments
 (0)