Skip to content

Commit

Permalink
Merge pull request #1310 from chdoc/idle-crafting-shell
Browse files Browse the repository at this point in the history
`idle-crafting`: also support making shell crafts
  • Loading branch information
myk002 committed Sep 28, 2024
2 parents 7b8addd + ee17b6e commit 919863f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions docs/idle-crafting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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).
29 changes: 29 additions & 0 deletions idle-crafting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 919863f

Please sign in to comment.