From ee17b6eb9bed1879370d50e0b85a8fc2a8f8620d Mon Sep 17 00:00:00 2001 From: Christian Doczkal <20443222+chdoc@users.noreply.github.com> Date: Fri, 27 Sep 2024 17:19:44 +0200 Subject: [PATCH] `idle-crafting`: also support making shell crafts for workshops with linked input stockpiles --- changelog.txt | 2 ++ docs/idle-crafting.rst | 8 ++++---- idle-crafting.lua | 29 +++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/changelog.txt b/changelog.txt index ff109f131..07f2caeea 100644 --- a/changelog.txt +++ b/changelog.txt @@ -34,6 +34,8 @@ Template for new versions: ## Misc Improvements +- `idle-crafting`: also support making shell crafts for workshops with linked input stockpiles + ## Removed # 50.13-r5 diff --git a/docs/idle-crafting.rst b/docs/idle-crafting.rst index 5f99d24df..b0377a6a7 100644 --- a/docs/idle-crafting.rst +++ b/docs/idle-crafting.rst @@ -54,7 +54,7 @@ supported, with stonecrafting being the default option. Thus, to designate a workshop for bone carving, disable the stonecrafting labor while keeping the bone carving labor enabled. -For workshops with input stockpile links, the creation of totems and horn crafts -are supported as well. In this case, the choice of job is made randomly based on -the resources available in the input stockpiles (respecting the permitted -labors from the workshop profile). +For workshops with input stockpile links, the creation of totems, shell crafts, +and horn crafts are supported as well. In this case, the choice of job is made +randomly based on the resources available in the input stockpiles (respecting +the permitted labors from the workshop profile). diff --git a/idle-crafting.lua b/idle-crafting.lua index fd650c881..f78e66763 100644 --- a/idle-crafting.lua +++ b/idle-crafting.lua @@ -143,6 +143,31 @@ function makeBoneCraft(unit, workshop) return dfhack.job.addWorker(job, unit) end +---make shell crafts at specified workshop +---@param unit df.unit +---@param workshop df.building_workshopst +---@return boolean +function makeShellCraft(unit, workshop) + local job = make_job() + job.job_type = df.job_type.MakeCrafts + job.mat_type = -1 + job.material_category.shell = true + + local jitem = df.job_item:new() + jitem.item_type = df.item_type.NONE + jitem.mat_type = -1 + jitem.mat_index = -1 + jitem.quantity = 1 + jitem.vector_id = df.job_item_vector_id.ANY_REFUSE + jitem.flags1.unrotten = true + jitem.flags2.shell = true + jitem.flags2.body_part = true + job.job_items.elements:insert('#', jitem) + + assignToWorkshop(job, workshop) + return dfhack.job.addWorker(job, unit) +end + ---make rock crafts at specified workshop ---@param unit df.unit ---@param workshop df.building_workshopst @@ -177,6 +202,8 @@ local function categorize_craft(tab,item) tab['skull'] = (tab['skull'] or 0) + 1 elseif item.corpse_flags.horn then tab['horn'] = (tab['horn'] or 0) + item.material_amount.Horn + elseif item.corpse_flags.shell then + tab['shell'] = (tab['shell'] or 0) + 1 end elseif df.item_boulderst:is_instance(item) then tab['boulder'] = (tab['boulder'] or 0) + 1 @@ -310,11 +337,13 @@ function select_crafting_job(workshop) tab['bone'] = nil tab['skull'] = nil tab['horn'] = nil + tab['shell'] = nil end local material = weightedChoice(tab) if material == 'bone' then return makeBoneCraft elseif material == 'skull' then return makeTotem elseif material == 'horn' then return makeHornCrafts + elseif material == 'shell' then return makeShellCraft elseif material == 'boulder' then return makeRockCraft else return nil