From 36b7771fab7892e5ed74ef39ee8438657e84904c Mon Sep 17 00:00:00 2001 From: SilasD Date: Fri, 18 Jul 2025 04:24:29 -0700 Subject: [PATCH 1/4] entomb.lua Implement a function that creates a job to haul an item to a coffin. Only the function has been created; the program's UI has not been updated. --- entomb.lua | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/entomb.lua b/entomb.lua index 88483d460..8d4db1433 100644 --- a/entomb.lua +++ b/entomb.lua @@ -1,5 +1,6 @@ -- Entomb corpse items of any dead unit. --@module = true +local utils = require('utils') -- Get unit from selected corpse or corpse piece item. function GetUnitFromCorpse(item) @@ -109,6 +110,51 @@ function PutInCoffin(coffin, item) end end +function HaulToCoffin(tomb, coffin, item) + if not tomb or not coffin or not item then return end + + if dfhack.items.getHolderBuilding(item) == coffin and item.flags.in_building == true then +print("DEBUG: item is already properly interred, skipping", tomb.id, dfhack.buildings.getName(tomb), +coffin.id, dfhack.buildings.getName(coffin), item.id, dfhack.items.getReadableDescription(item)) + return -- already interred in this coffin, skip + end + + -- TODO Consider what should happen when certain item.flags are set, particularly .forbid and .dump. + -- TODO Consider copy-paste-modify scripts/internal/caravan/pedestal.lua::is_displayable_item() + + -- Remove current job from item to allow it to be moved to the tomb. + if item.flags.in_job then + local inJob = dfhack.items.getSpecificRef(item, df.specific_ref_type.JOB) + local job = inJob and inJob.data.job or nil + if job + and job.job_type == df.job_type.PlaceItemInTomb + and dfhack.job.getGeneralRef(job, df.general_ref_type.BUILDING_HOLDER) ~= nil + and dfhack.job.getGeneralRef(job, df.general_ref_type.BUILDING_HOLDER).building_id == tomb.id + then +print("DEBUG: desired job already exists, skipping", tomb.id, dfhack.buildings.getName(tomb), +coffin.id, dfhack.buildings.getName(coffin), item.id, dfhack.items.getReadableDescription(item), job.id) + return -- desired job already exists, skip + end + if job then +print("DEBUG: removing current job from this item", item.id, dfhack.items.getReadableDescription(item), +job.id, df.job_type[job.job_type]) + dfhack.job.removeJob(job) + end + end + + local pos = utils.getBuildingCenter(coffin) + + local job = df.job:new() + job.job_type = df.job_type.PlaceItemInTomb + job.pos = pos + + dfhack.job.attachJobItem(job, item, df.job_role_type.Hauled, -1, -1) + dfhack.job.addGeneralRef(job, df.general_ref_type.BUILDING_HOLDER, tomb.id) + tomb.jobs:insert('#', job) + + dfhack.job.linkIntoWorld(job, true) +end + local function GetCoffin(tomb) local coffin if tomb.type == df.civzone_type.Tomb then @@ -149,7 +195,8 @@ function AssignToTomb(unit, tomb, forceBurial) if coffin then for _, item_id in ipairs(corpseParts) do local item = df.item.find(item_id) - PutInCoffin(coffin, item) + -- PutInCoffin(coffin, item) + HaulToCoffin(tomb, coffin, item) end print('Corpse items have been teleported into a coffin.') else From b359cbaa4c7ea3b62da9ccea24ca3fdf6e025581 Mon Sep 17 00:00:00 2001 From: SilasD Date: Sat, 19 Jul 2025 10:31:32 -0700 Subject: [PATCH 2/4] entomb.lua Very Important Bugfix completely assign unit to tomb. --- entomb.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/entomb.lua b/entomb.lua index 8d4db1433..f5e1895d5 100644 --- a/entomb.lua +++ b/entomb.lua @@ -189,6 +189,7 @@ function AssignToTomb(unit, tomb, forceBurial) print(string.format(strNoCorpse, strUnitName)) else tomb.assigned_unit_id = unit.id + tomb.assigned_unit = unit print(string.format(strBurial, strUnitName, strTomb)) if forceBurial then local coffin = GetCoffin(tomb) From 6a185fd92433b03c8e912597b3fdc9814f6c92ee Mon Sep 17 00:00:00 2001 From: SilasD Date: Sat, 19 Jul 2025 21:09:30 -0700 Subject: [PATCH 3/4] entomb.lua Update the unit's owned buildings with the newly-assigned tomb. --- entomb.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/entomb.lua b/entomb.lua index f5e1895d5..0f0e08428 100644 --- a/entomb.lua +++ b/entomb.lua @@ -190,6 +190,9 @@ function AssignToTomb(unit, tomb, forceBurial) else tomb.assigned_unit_id = unit.id tomb.assigned_unit = unit + if not utils.linear_index(unit.owned_buildings, tomb) then + unit.owned_buildings:insert('#', tomb) + end print(string.format(strBurial, strUnitName, strTomb)) if forceBurial then local coffin = GetCoffin(tomb) From a2f45484b58a7ada57e3c7ea3f436424a873b744 Mon Sep 17 00:00:00 2001 From: SilasD Date: Wed, 23 Jul 2025 11:20:39 -0700 Subject: [PATCH 4/4] Undo commit b359cbaa4c7ea3b62da9ccea24ca3fdf6e025581 entomb.lua Very Important Bugfix completely assign unit to tomb. Because this field was removed in DF 0.51.11. --- entomb.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/entomb.lua b/entomb.lua index 0f0e08428..182981042 100644 --- a/entomb.lua +++ b/entomb.lua @@ -189,7 +189,6 @@ function AssignToTomb(unit, tomb, forceBurial) print(string.format(strNoCorpse, strUnitName)) else tomb.assigned_unit_id = unit.id - tomb.assigned_unit = unit if not utils.linear_index(unit.owned_buildings, tomb) then unit.owned_buildings:insert('#', tomb) end