From 85c7af6d053a42f8b7ba1bf574c13cdc590de2ff Mon Sep 17 00:00:00 2001 From: kanym Date: Sat, 31 Oct 2026 02:10:32 +0100 Subject: [PATCH] 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. --- JotunnModStub/Alfar/AlfarDroneAI.cs | 51 ++++++++++++++++++++------- JotunnModStub/Butler/BoneServantAI.cs | 28 ++++++++++----- 2 files changed, 57 insertions(+), 22 deletions(-) diff --git a/JotunnModStub/Alfar/AlfarDroneAI.cs b/JotunnModStub/Alfar/AlfarDroneAI.cs index 40bf69b..0d3a83e 100644 --- a/JotunnModStub/Alfar/AlfarDroneAI.cs +++ b/JotunnModStub/Alfar/AlfarDroneAI.cs @@ -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(); } /// @@ -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(); diff --git a/JotunnModStub/Butler/BoneServantAI.cs b/JotunnModStub/Butler/BoneServantAI.cs index 073d718..2c165db 100644 --- a/JotunnModStub/Butler/BoneServantAI.cs +++ b/JotunnModStub/Butler/BoneServantAI.cs @@ -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(); } /// @@ -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 {