Skip to content

Commit

Permalink
idle-crafting: also support making shell crafts for workshops with …
Browse files Browse the repository at this point in the history
…linked input stockpiles
  • Loading branch information
chdoc committed Sep 27, 2024
1 parent 7b8addd commit 04ea7b8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 04ea7b8

Please sign in to comment.