From 9bd98c68c3dbba89cc5ed2d159a91c6f46be12ae Mon Sep 17 00:00:00 2001 From: kanym Date: Sat, 31 Oct 2026 01:58:40 +0100 Subject: [PATCH 1/3] debug: F8 shows why a drone feeds a station or not, and what holds its fight For the nearest worker drone F8 now lists the Eldividarkista and its wood, every station in the radius (operable, free slots, takes wood, penalty, claim, fuel, what a load would bring), and stations just past the edge with the distance. Each drone also reports the 12 m enemy sweep and how long the fight linger has left. --- JotunnModStub/Alfar/AlfarDroneAI.cs | 67 ++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/JotunnModStub/Alfar/AlfarDroneAI.cs b/JotunnModStub/Alfar/AlfarDroneAI.cs index 4cb5f86..40bf69b 100644 --- a/JotunnModStub/Alfar/AlfarDroneAI.cs +++ b/JotunnModStub/Alfar/AlfarDroneAI.cs @@ -1664,10 +1664,22 @@ namespace RacesOfValheim lines.Add($"[RoV drone] {distance:0}m: '{drone.Status}' job {(drone.m_job != null ? drone.m_job.Kind : "none")} " + $"carry {drone.PayloadCount()} fight {drone.m_fighting} vanilla target {targetText} " + $"alerted {drone.m_ai.IsAlerted()} flying {drone.m_character.IsFlying()} owner {drone.m_nview.IsOwner()}"); + + // The other half of what holds a fight: the 12 m sweep, and how long the linger has left. + Character near = BaseAI.FindClosestEnemy(drone.m_character, drone.transform.position, FightRange); + string nearText = near != null + ? $"{Utils.GetPrefabName(near.gameObject)} {Vector3.Distance(near.transform.position, drone.transform.position):0}m" + : "none"; + lines.Add($"[RoV drone] fight left {Mathf.Max(0f, drone.m_fightUntil - Time.time):0.0}s, " + + $"closest enemy {nearText}, in reach {(target != null && drone.InFightReach(target))}"); } if (nearest == null) lines.Add("[RoV drone] no worker drone within 60m"); - else lines.AddRange(nearest.SortReport()); + else + { + lines.AddRange(nearest.SortReport()); + lines.AddRange(nearest.StationReport()); + } foreach (string line in lines) { @@ -1676,6 +1688,59 @@ namespace RacesOfValheim } } + /// Why a station is (or is not) fed: what the last scan saw, the wood chest, and every + /// smelter, hearth or fermenter within the radius - and the ones just past it, by how much. + private IEnumerable StationReport() + { + Vector3? anchor = Anchor; + if (anchor == null) { yield return "[RoV station] no anchor"; yield break; } + + float radius = AlfarNexusConfig.NexusRadius.Value + m_radiusBonus; + yield return $"[RoV station] anchor {Vector3.Distance(transform.position, anchor.Value):0}m from drone, " + + $"radius {radius:0}, scanned {Time.time - m_scannedAt:0}s ago, {m_stations.Count} stations, {m_chests.Count} chests"; + + if (m_wood == null) yield return "[RoV station] no Eldividarkista in range (or it is open, or holds the sigil)"; + else + { + var wood = new List(); + Inventory inventory = m_wood.GetInventory(); + if (inventory != null) + { + foreach (ItemDrop.ItemData item in inventory.GetAllItems()) + { + wood.Add(item.m_dropPrefab != null ? $"{item.m_dropPrefab.name}x{item.m_stack}" : $"{item.m_shared.m_name}(no prefab)"); + } + } + yield return $"[RoV station] Eldividarkista {Vector3.Distance(m_wood.transform.position, anchor.Value):0}m from anchor, " + + $"open {m_wood.IsInUse()}, penalty {IsPenalised(ZdoOf(m_wood))}, holds [{string.Join(", ", wood.ToArray())}]"; + } + + foreach (ButlerStation station in m_stations) + { + if (!station.Alive) { yield return "[RoV station] (a station that is gone)"; continue; } + + Container chest; + string material = FindMaterialFor(station, out chest); + string from = material == null ? "nothing" : $"{material} from {(chest == m_wood ? "Eldividarkista" : "entry")}"; + yield return $"[RoV station] {Utils.GetPrefabName(station.Behaviour.gameObject)} " + + $"{Vector3.Distance(station.Position, anchor.Value):0}m: operable {station.Operable} free {station.FreeSlots} " + + $"work {station.HasWork} wood {station.Accepts("Wood")} penalty {IsPenalised(station.Id)} " + + $"claimed {ClaimedByOther(station.Id)} fuel {station.FuelPrefab ?? "-"}/{station.FuelWanted} | load: {from}"; + } + + // A station the scan cannot see because it stands past the edge. + List pieces = AllPiecesField != null ? AllPiecesField.GetValue(null) as List : null; + if (pieces == null) yield break; + foreach (Piece piece in pieces) + { + if (piece == null) continue; + float distance = Vector3.Distance(piece.transform.position, anchor.Value); + if (distance <= radius || distance > radius + 15f) continue; + if (ButlerStation.From(piece.gameObject) == null) continue; + yield return $"[RoV station] {Utils.GetPrefabName(piece.gameObject)} {distance:0}m: OUTSIDE the radius by {distance - radius:0.0}m"; + } + } + private IEnumerable SortReport() { if (m_entry == null) { yield return "[RoV sort] no entry chest in range"; yield break; } From 85c7af6d053a42f8b7ba1bf574c13cdc590de2ff Mon Sep 17 00:00:00 2001 From: kanym Date: Sat, 31 Oct 2026 02:10:32 +0100 Subject: [PATCH 2/3] 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 { From 038d827991adcc58a800c9a43e20fec2d2f656a5 Mon Sep 17 00:00:00 2001 From: kanym Date: Sat, 31 Oct 2026 02:37:00 +0100 Subject: [PATCH 3/3] fix: drones fly beside a station instead of into it A flyer's goal is lifted to m_flyAltitudeMin over the ground under the point, and under a charcoal kiln's origin that is inside the dome. The drone never came within reach, timed out on the collect job and put the kiln in the penalty box, so no wood was loaded for three minutes at a time (snakey's second log: penalty True, 'Could not reach collect'). Station jobs now aim a metre past the station's colliders on the side the drone comes from. Loading and the drop sweep still use the station's own position. --- JotunnModStub/Alfar/AlfarDroneAI.cs | 40 ++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/JotunnModStub/Alfar/AlfarDroneAI.cs b/JotunnModStub/Alfar/AlfarDroneAI.cs index 0d3a83e..b319ceb 100644 --- a/JotunnModStub/Alfar/AlfarDroneAI.cs +++ b/JotunnModStub/Alfar/AlfarDroneAI.cs @@ -617,7 +617,7 @@ namespace RacesOfValheim Kind = "collect", Target = best.Id, Claim = best.Id, - Point = best.Position, + Point = ApproachPoint(best), Hurry = true, Label = "Saving the food", }; @@ -648,7 +648,7 @@ namespace RacesOfValheim Kind = "collect", Target = best.Id, Claim = best.Id, - Point = best.Position, + Point = ApproachPoint(best), Label = "Collecting", }; } @@ -788,7 +788,7 @@ namespace RacesOfValheim { Kind = "deposit_station", Target = target, - Point = station.Position, + Point = ApproachPoint(station), Label = "Loading " + Describe(), }; } @@ -841,7 +841,7 @@ namespace RacesOfValheim { Kind = "deposit_station", Target = consumer.Id, - Point = consumer.Position, + Point = ApproachPoint(consumer), Label = "Loading " + Describe(), }; } @@ -1798,6 +1798,38 @@ namespace RacesOfValheim } } + /// + /// Where the drone flies to serve a station: beside it, a metre past its colliders on the side + /// the drone comes from. Vanilla lifts a flyer's goal to m_flyAltitudeMin over the ground under + /// it (BaseAI.MoveTo, IL), and under a charcoal kiln's origin that is inside the dome: the drone + /// pressed against the stone, never came within ArriveDistance, and the kiln went into the + /// penalty box (snakey's log, "Could not reach collect target"). Beside it is open air, and it + /// stays under a roof indoors, where aiming over the top would not. The loading and the sweep + /// still work from the station's own position. + /// + private Vector3 ApproachPoint(ButlerStation station) + { + Vector3 centre = station.Position; + bool any = false; + Bounds bounds = new Bounds(centre, Vector3.zero); + foreach (Collider collider in station.Behaviour.GetComponentsInChildren()) + { + if (collider == null || !collider.enabled || collider.isTrigger) continue; + if (any) bounds.Encapsulate(collider.bounds); + else { bounds = collider.bounds; any = true; } + } + if (!any) return centre; + + Vector3 away = transform.position - bounds.center; + away.y = 0f; + if (away.sqrMagnitude < 0.01f) away = station.Transform.forward; + float reach = Mathf.Max(bounds.extents.x, bounds.extents.z) + 1f; + + Vector3 point = bounds.center + away.normalized * reach; + point.y = centre.y; + return point; + } + private bool MoveToPoint(float dt, Vector3 point, float distance, bool run) { if (m_ai == null || MoveToMethod == null) return true; // cannot walk: act in place