-
Notifications
You must be signed in to change notification settings - Fork 218
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
Conversation
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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
This is intended as a replacement/alternative for
automilk
andautoshear
. 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.