new tool: Automatically milk and shear animals at nearby farmer's workshops#1491
new tool: Automatically milk and shear animals at nearby farmer's workshops#1491ab9rf merged 1 commit intoDFHack:masterfrom
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.
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.
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.
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.
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.
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
automilkandautoshear. 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.