From 038d827991adcc58a800c9a43e20fec2d2f656a5 Mon Sep 17 00:00:00 2001 From: kanym Date: Sat, 31 Oct 2026 02:37:00 +0100 Subject: [PATCH] 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