fix: drones no longer freeze with a load after a slow trip or a fight

Plan() returned early for a delivery and kept the deadline of the job
before it, so a delivery that started late timed out on its first tick,
was planned again with the same stale deadline, and looped every frame.
snakey's log shows 10790 deposit_station timeouts in a row: the drone
hung by the kiln with the wood, and a fight mid-trip did the same.

Every job now gets a fresh clock. A station that is in the penalty box
is not asked again for a delivery; the Alfar drone takes the load back
to the chest it came from, so fuel stays in the Eldividarkista. The
Butler's servant had the same early return and gets the same fix.
This commit is contained in:
kanym 2026-10-31 02:10:32 +01:00
commit 85c7af6d05
2 changed files with 57 additions and 22 deletions

View file

@ -448,15 +448,31 @@ namespace RacesOfValheim
CheckIdleKiln();
// A harvest is in progress: wait for the drops to land, then gather them and replant.
Job job;
if (m_farmSpot != null)
{
m_job = Time.time < m_farmReadyAt
job = Time.time < m_farmReadyAt
? new Job { Kind = "wait", Point = transform.position, Label = "Waiting" }
: new Job { Kind = "farm_finish", Point = m_farmSpot.Value, Label = "Gathering" };
return;
}
// A delivery is a job like any other and gets its own clock. It used to return early here
// and inherit the load's deadline: a slow trip, or a fight on the way, left it already late,
// so it timed out on the first tick, was planned again, timed out again, every frame - the
// drone froze with wood in hand next to the kiln (10790 timeouts in one player's log).
else if (m_payload.Count > 0) job = PlanDelivery(anchor.Value);
else job = PlanWork(anchor.Value);
if (m_payload.Count > 0) { m_job = PlanDelivery(anchor.Value); return; }
if (job != null && (m_job == null || m_job.Kind != job.Kind || m_job.Target != job.Target))
{
m_jobDeadline = Time.time + JobTimeout;
}
if (m_job != null && !ReferenceEquals(m_job, job)) Release(m_job.Claim);
if (job != null) Claim(job.Claim);
m_job = job;
}
private Job PlanWork(Vector3 anchor)
{
// The forge has no clock: a smelter holds its ore indefinitely and puts its own output on
// the floor, so PlanRescue would ask a question whose answer is always no. The smith is a
@ -472,15 +488,7 @@ namespace RacesOfValheim
// base: repairs, the fields, and last the tidying of the entry chest.
Job job = PlanRescue();
job = job ?? PlanCollect() ?? PlanFuel() ?? PlanLoad();
job = job ?? PlanRepair(anchor.Value) ?? PlanFarm(anchor.Value) ?? PlanSort();
if (job != null && (m_job == null || m_job.Kind != job.Kind || m_job.Target != job.Target))
{
m_jobDeadline = Time.time + JobTimeout;
}
if (m_job != null && !ReferenceEquals(m_job, job)) Release(m_job.Claim);
if (job != null) Claim(job.Claim);
m_job = job;
return job ?? PlanRepair(anchor) ?? PlanFarm(anchor) ?? PlanSort();
}
/// <summary>
@ -770,8 +778,11 @@ namespace RacesOfValheim
// coal, so gating the delivery on free slots sent the servant back to the chest with
// the coal it had just fetched - and then PlanFuel sent it out for the same coal again,
// forever. AcceptsAnything already asks the right question of both doors.
// A station it could not reach is in the penalty box: asking it again straight away
// is the same failed trip.
bool unreachable = IsPenalised(target);
ButlerStation station = StationById(target);
if (station != null && station.Alive && station.Operable && AcceptsAnything(station))
if (station != null && station.Alive && station.Operable && AcceptsAnything(station) && !unreachable)
{
return new Job
{
@ -784,6 +795,20 @@ namespace RacesOfValheim
// The station is gone, full or cold. The goods are ours to put back, not to hold.
m_nview.GetZDO().Set(KeyTarget, ZDOID.None);
// Out of reach, the load goes back where it came from: the Eldividarkista's wood stays
// fuel instead of landing in the entry chest and being sorted away into storage.
Container source = unreachable ? ContainerById(m_nview.GetZDO().GetZDOID(KeySource)) : null;
if (source != null && !IsMarkedOff(source) && !IsPenalised(ZdoOf(source)) && HasRoomFor(source))
{
return new Job
{
Kind = "deposit",
Target = ZdoOf(source),
Point = source.transform.position,
Label = "Storing " + Describe(),
};
}
}
Container chest = ChestForProduct();

View file

@ -363,8 +363,22 @@ namespace RacesOfValheim
Scan(anchor.Value);
ExpirePenalties();
if (m_payload.Count > 0) { m_job = PlanDelivery(anchor.Value); return; }
// A delivery gets its own clock like any other job. Returning early here left it with the
// load's deadline: a slow trip, or a fight on the way, made it late before it started, and
// it timed out and was planned again on every tick, frozen with the goods in hand.
Job job;
if (m_payload.Count > 0) job = PlanDelivery(anchor.Value);
else job = PlanWork();
if (job != null && (m_job == null || m_job.Kind != job.Kind || m_job.Target != job.Target))
{
m_jobDeadline = Time.time + JobTimeout;
}
m_job = job;
}
private Job PlanWork()
{
// The forge has no clock: a smelter holds its ore indefinitely and puts its own output on
// the floor, so PlanRescue would ask a question whose answer is always no. The smith is a
// four-state machine and the cook is a five-state one, and that is the whole of the
@ -376,13 +390,7 @@ namespace RacesOfValheim
// in return, because FuelWanted is zero for a station with no work: an empty furnace asks
// for no coal, gets filled, and only then becomes worth stoking.
Job job = m_family == ButlerFamily.Kitchen ? PlanRescue() : null;
job = job ?? PlanCollect() ?? PlanFuel() ?? PlanLoad();
if (job != null && (m_job == null || m_job.Kind != job.Kind || m_job.Target != job.Target))
{
m_jobDeadline = Time.time + JobTimeout;
}
m_job = job;
return job ?? PlanCollect() ?? PlanFuel() ?? PlanLoad();
}
/// <summary>
@ -634,8 +642,10 @@ namespace RacesOfValheim
// coal, so gating the delivery on free slots sent the servant back to the chest with
// the coal it had just fetched - and then PlanFuel sent it out for the same coal again,
// forever. AcceptsAnything already asks the right question of both doors.
// A station it could not reach is in the penalty box: asking it again straight away
// is the same failed trip.
ButlerStation station = StationById(target);
if (station != null && station.Alive && station.Operable && AcceptsAnything(station))
if (station != null && station.Alive && station.Operable && AcceptsAnything(station) && !IsPenalised(target))
{
return new Job
{