Skip to content

new tool: Automatically milk and shear animals at nearby farmer's workshops #1491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2025

Conversation

chdoc
Copy link
Member

@chdoc chdoc commented Aug 16, 2025

This is intended as a replacement/alternative for automilk and autoshear. It solves the problem that the workorder based approach loses the connection to the specific animals, possibly queuing jobs at workshops on the other side of your fort.

Comment on lines +122 to +134
local function shearCreature(unit, workshop)
local job = ic.make_job()
job.job_type = df.job_type.ShearCreature
dfhack.job.addGeneralRef(job, df.general_ref_type.UNIT_SHEAREE, unit.id)
ic.assignToWorkshop(job, workshop)
end

local function milkCreature(unit, workshop)
local job = ic.make_job()
job.job_type = df.job_type.MilkCreature
dfhack.job.addGeneralRef(job, df.general_ref_type.UNIT_MILKEE, unit.id)
ic.assignToWorkshop(job, workshop)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this to me indicates that the functionality that's here being used from idle-crafting should at least be considered for being moved to a library

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are part of the functions that were recently merged into the library. I can fix this PR, but I can also do a follow up where I replace these functions in all the related tools.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A follow up is fine. This code is fine as it stands and I see no reason to delay merging it so we can include it in the next pre-release for UAT

Comment on lines +206 to +217
for _, job in ipairs(workshop.jobs) do
if state.milking and job.job_type == df.job_type.MilkCreature then
local milkee = dfhack.job.getGeneralRef(job, df.general_ref_type.UNIT_MILKEE)
if milkee then
unit_milking[milkee.unit_id] = true
end
elseif state.shearing and job.job_type == df.job_type.ShearCreature then
local shearee = dfhack.job.getGeneralRef(job, df.general_ref_type.UNIT_SHEAREE)
if shearee then
unit_shearing[shearee.unit_id] = true
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't help but notice that this code is somewhat repetitive

also this pattern appears likely to recur, may be worth abstracting to a library routine

Comment on lines +225 to +237
if state.shearing and canShearCreature(unit) and not unit_shearing[unit.id] then
local workshop = getAppropriateWorkshop(unit, farmer_shearing)
if workshop then
shearCreature(unit, workshop)
end
end

if state.milking and canMilkCreature(unit) and not unit_milking[unit.id] then
local workshop = getAppropriateWorkshop(unit, farmer_milking)
if workshop then
milkCreature(unit, workshop)
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with this - iterating over all workshops looking for a predicate or iterating over all units looking for a predicate both seem like things we should abstract

@ab9rf ab9rf merged commit 1c1bbe1 into DFHack:master Aug 17, 2025
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants