Fly paces as the pilot does; Transfer ends a parked dive; a call that moves nothing ends Fly

Fly charges one dive (WormholeAnimationDuration) at each jump and returns the seconds left, so a crossing off screen takes about the
sim time it takes on screen (0.996 on a 2.1 km crossing; the old model read 0.4). HaulRun.Transfer, the one move between zones, ends any
wormhole animation parked on the ship (Ship.EndWormholeAnimation): a hauler mid-dive that Advance flies on no longer throws when its
new zone steps it. Call returns the units moved and Fly stops on a call that moved none (the To branch's space clause had no
assertion and a mutant of it spun Fly's step guard). An exit animation points into the zone. RegionClock's header reads once.
Tests pin the pace (Fly at half and at twice the speed, Advance flying absolute time), the stale dive, the To space clause, the leg
stream and its carry-back.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-30 00:25:18 +01:00
commit 56f8fce8e9
5 changed files with 196 additions and 60 deletions

View file

@ -47,17 +47,19 @@ public static class HaulRun
}
// Docks at the station, loads at the From station or delivers at the To station, and undocks piloted: a ship that cannot
// move a unit does not dock. The pilot's Call verb is the only caller (PilotApplier).
public static void Call(Ship ship, Entity station)
// move a unit does not dock. The pilot's Call verb and Fly are the callers. Returns the units moved.
public static int Call(Ship ship, Entity station)
{
var order = OrderOf(ship.ItemManager, ship.Haul.Key);
if (order == null || !(station is OrbitalEntity depot) || !CanCall(ship, depot, order) || depot.TryDock(ship) == null) return;
if (depot.OrbitData.Equals(order.From.Key)) StationServices.Load(depot, Goods(order), ship);
if (order == null || !(station is OrbitalEntity depot) || !CanCall(ship, depot, order) || depot.TryDock(ship) == null) return 0;
var moved = 0;
if (depot.OrbitData.Equals(order.From.Key)) moved = StationServices.Load(depot, Goods(order), ship);
else
foreach (var bay in ship.CargoBays.ToArray())
foreach (var stack in bay.Cargo.Keys.OfType<ICommodityStack>().Where(stack => Goods(order).Contains(((ItemInstance) stack).Data.Key)).ToArray())
StationServices.TryStorePart(bay, depot, stack);
moved += StationServices.TryStorePart(bay, depot, stack).Sold;
depot.TryUndock(ship, piloted: true);
return moved;
}
@ -97,18 +99,23 @@ public static class HaulRun
var into = hop.Contents;
from.Remove(ship);
ship.Deactivate();
ship.EndWormholeAnimation(); // a dive or exit parked on the ship by another path (the pilot's Jump) is over: nothing may finish it in the new zone
ship.Zone = into;
var at = into.WormholeTo(from.GalaxyZone);
ship.Position = float3(at.x, 0, at.y);
into.Admit(ship, piloted: true);
}
// An off-screen hauler flown `seconds` of sim time: straight at its waypoint at its hull's top speed (Agent.TopSpeedOf), the same
// speed its pilot flies on screen, then the one cargo move at a station (Call, when CanCall; otherwise it waits there) or the
// An off-screen hauler flown `seconds` of sim time, paced as the pilot paces it on screen: straight at its waypoint at its hull's top
// speed (Agent.TopSpeedOf) plus one dive (WormholeAnimationDuration) at each jump, charged to the seconds that remain. Measured on
// seeds 1 to 3 (18 on-screen first crossings, 150 s cap): 12 completed, 8 of them at 0.93 to 0.99 of top speed once the dive is taken
// off, the rest slower; 2 haulers were shot by Lucent Media patrols and 4 did not finish in the cap, held by gravity wells. Then the
// one cargo move at a station (Call, when CanCall; otherwise it waits there) or the
// jump at a wormhole. Position and velocity are its only writes besides Call and Jump. It stops when it waits, when a Call leaves it
// docked, or when it has jumped into a zone that is not being advanced (`advanced`: the player's zone, `current`, where it plays the
// exit animation and the full sim takes it over, or any zone outside the pass), whose next span flies it from there.
public static void Fly(Ship ship, double seconds, Zone current, ICollection<Zone> advanced)
// exit animation and the full sim takes it over, or any zone outside the pass), whose next span flies it from there. Returns the seconds
// left, below zero when the last dive was begun with less than a dive in hand (the jump is early, never late).
public static double Fly(Ship ship, double seconds, Zone current, ICollection<Zone> advanced)
{
var order = OrderOf(ship.ItemManager, ship.Haul.Key);
var speed = Agent.TopSpeedOf(ship);
@ -116,7 +123,7 @@ public static class HaulRun
{
var zone = ship.Zone;
var way = Waypoint(ship, order);
if (way == null) return;
if (way == null) return seconds;
var (orbit, hop) = way.Value;
var target = hop == null ? zone.GetOrbitPosition(orbit) : zone.WormholeTo(hop);
var offset = target - ship.Position.xz;
@ -126,7 +133,7 @@ public static class HaulRun
var direction = normalize(offset);
ship.Position.xz += direction * (float) (speed * seconds);
ship.Velocity = direction * speed;
return;
return seconds;
}
seconds -= distance / speed;
ship.Position.xz = target;
@ -134,21 +141,24 @@ public static class HaulRun
if (hop == null)
{
var station = Station(zone, orbit);
if (station == null || !CanCall(ship, station, order)) return;
Call(ship, station);
if (station == null || !CanCall(ship, station, order)) return seconds;
if (Call(ship, station) == 0) return seconds; // a call that moved nothing would repeat until the step guard
continue;
}
var origin = zone.GalaxyZone;
if (hop.Contents == null) return;
if (hop.Contents == null) return seconds;
Transfer(ship, hop);
seconds -= ship.ItemManager.GameplaySettings.WormholeAnimationDuration; // the pilot's dive, which a jump takes on screen
if (hop.Contents == current)
{
var gate = hop.Contents.WormholeTo(origin);
ship.ExitWormhole(gate, normalize(gate) * ship.ItemManager.GameplaySettings.WormholeExitVelocity);
ship.ExitWormhole(gate, -normalize(gate) * ship.ItemManager.GameplaySettings.WormholeExitVelocity); // into the zone, not out of it
}
if (!advanced.Contains(hop.Contents)) return;
if (!advanced.Contains(hop.Contents)) return seconds;
}
return seconds;
}
private static IReadOnlyCollection<CultRecordKey> Goods(HaulOrderData order) => order.Goods.Select(good => good.Key).ToArray();
private static IEnumerable<ICommodityStack> Carried(Ship ship, HaulOrderData order)

View file

@ -8,11 +8,11 @@ using System.Linq;
// What simulation time does to a run's region (ruling demo-chain-spans-the-region). The player's zone steps every game
// step; every other zone's facilities are advanced to the player's zone's time at each Span boundary, by the span they
// missed, and entering a zone settles it and records what the player saw of the zone left. It is a run's one driver:
// nothing else steps a zone in play, advances an off-screen zone, writes a visit or writes a sighting. Time has no stored
// missed, and its haulers fly that span (HaulRun.Fly); entering a zone settles it and records what the player saw of the zone left.
// It is a run's one driver: nothing else steps a zone in play, advances an off-screen zone, writes a visit or writes a sighting. Time
// has no stored state of its own: the player's zone's ExactTime is the region's time, an off-screen zone's span is that time minus its
// own, and both persist in ZonePack.Time. Off screen only facilities run and haulers fly (the tick conjures nothing, ruling
// economy-is-never-faked): thermal, combat and every other ship's flight are on-screen detail.
// economy-is-never-faked): thermal, flight and combat are on-screen detail.
public static class RegionClock
{
// Sim seconds between advances of the zones the player is not in. One advance per Span is about 2.3 ms on a 64-zone

View file

@ -58,6 +58,15 @@ public class Ship : Entity
// read it (the screen warp centres on it); it is the sim's own position, so it needs no copy elsewhere.
public float2 WormholePosition => _wormholePosition;
// Ends any wormhole animation and drops what waits on it: a ship moved between zones by another path is not still diving or
// emerging, and a handler parked on the dive must not run in the zone it was not parked for (HaulRun.Transfer is the caller).
public void EndWormholeAnimation()
{
_enteringWormhole = _exitingWormhole = false;
OnEnteredWormhole = null;
OnExitedWormhole = null;
}
public event Action OnExitedWormhole;
public event Action OnEnteredWormhole;