From 04ea7b849ef23b43e307ae7b9eeba0f635e1d419 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 | 1 + docs/idle-crafting.rst | 8 ++++---- idle-crafting.lua | 29 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/changelog.txt b/changelog.txt index ff109f131..16703d73f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -72,6 +72,7 @@ Template for new versions: - `exterminate`: show descriptive names for the listed races in addition to their IDs - `exterminate`: show actual names for unique creatures such as forgotten beasts and titans - `fix/ownership`: now also checks and fixes room ownership links +- `idle-crafting`: also support making shell crafts for workshops with linked input stockpiles ## Documentation - `gui/embark-anywhere`: add information about how the game determines world tile pathability and instructions for bridging two landmasses diff --git a/docs/idle-crafting.rst b/docs/idle-crafting.rst index 5f99d24df..5d9c89318 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