fix(butler): the cook's lost meat, the furnace that starved, the coal with nowhere to go

Three tester reports against the Bone Servant, all with the same shape:
the servant was doing what the code said and the code said the wrong
thing. Two vanilla methods were re-read off the IL rather than trusted.

RPC_RemoveDoneItem empties ONE slot per call - it finds the first Done
slot, spawns its item, clears it and returns - not every slot, as the
comment on PullOutput claimed. DoCollect also swept the ground BEFORE
pulling, so each visit collected the previous visit's item and dropped a
fresh one; since Plan() diverts to PlanDelivery the moment the payload is
non-empty, the servant then left for the chest and abandoned what it had
just pulled. A working hearth therefore always had exactly one cooked
meat lying beside it. Now it pulls first, in a loop bounded by a new
ButlerStation.OutputPulls - the slot count for a cooking station, 1
everywhere else, because the fermenter's Ready survives its own tap for
the length of the animation and a bare while(HasOutput) would spam
RPC_Tap.

PlanFuel sat last, behind PlanLoad, and FreeSlots goes back above zero
the instant a furnace eats one ore - so loading always had an answer and
refuelling never got a turn. The blast furnace burned down to nothing.
PlanFuel now runs ahead of PlanLoad, which cannot starve loading in
return because FuelWanted is 0 for a station with no work, and it scores
candidates by the walk the way PlanLoad does now that the choice matters.

PlanDelivery offers the load to the nearest station that will CONSUME it,
as material or as fuel, after the chest search fails and before dropping
it on the floor. UpdateSmelter only calls SpawnProcessed once the ore
queue empties, so the charcoal kiln releases its whole batch at once -
exactly the delivery a nearly full chest cannot absorb. The coal now
walks into the furnace beside it instead of onto the ground.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Ferdinando 2026-08-29 08:45:09 +02:00
commit 03c1006511
2 changed files with 124 additions and 21 deletions

View file

@ -155,6 +155,17 @@ namespace RacesOfValheim
/// pickup routine will find them.</summary>
public abstract void PullOutput(Vector3 at);
/// <summary>
/// How many times PullOutput is worth calling in a single visit, which is not the same question
/// as how much is finished.
///
/// One, everywhere except the hearth. The Fermenter is the reason this is not simply "keep
/// pulling while HasOutput": tapping does not clear Ready straight away - DelayedTap waits
/// m_tapDelay for the animation - so a loop on HasOutput would pull the same tap over and over
/// in one frame.
/// </summary>
public virtual int OutputPulls { get { return 1; } }
/// <summary>Seconds until something in here is ruined. float.MaxValue for the two families that
/// cannot spoil, which is what keeps the urgency comparison honest without special cases.</summary>
public virtual float SecondsToSpoil { get { return float.MaxValue; } }
@ -394,9 +405,14 @@ namespace RacesOfValheim
public override bool HasOutput { get { return Vanilla.Call(Vanilla.CookHaveDone, m_cooking, false); } }
/// <summary>
/// ONE per done slot, and the 1 is not a stylistic choice. RPC_RemoveDoneItem spawns the
/// item <c>amount</c> times PER SLOT (verified in the IL: the inner loop runs to the
/// argument), so passing anything above 1 would not collect faster - it would print money.
/// ONE CALL, ONE SLOT - and the 1 is the count, not the slot.
///
/// Read again off the IL after the cook was reported losing a meat per batch, because the
/// first reading of it was wrong in a way that mattered. RPC_RemoveDoneItem walks the slots,
/// finds the FIRST one that is Done, spawns its item <c>amount</c> times, clears that slot,
/// sends RPC_SetSlotVisual and RETURNS. It does not go on to the other slots. So the
/// argument is a multiplier - anything above 1 prints money - and a hearth with five cooked
/// slots needs five calls, which is what OutputPulls below is for.
/// </summary>
public override void PullOutput(Vector3 at)
{
@ -404,6 +420,10 @@ namespace RacesOfValheim
Nview.InvokeRPC("RPC_RemoveDoneItem", at, 1);
}
/// <summary>One call per slot, so a full hearth is emptied in one visit instead of one item
/// per errand. The loop that uses this stops on HasOutput anyway; this is only its bound.</summary>
public override int OutputPulls { get { return Mathf.Max(1, SlotCount); } }
/// <summary>
/// The clock this whole feature exists for. Done at m_cookTime, Burnt at 2x - so what is
/// left is 2*cookTime - cookedTime, and a slot already Done is the urgent one because its