The haul state: a hauler flies HaulRun.Leg's orbit and commands the call within docking distance, and the haul task survives a fight like patrol

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-28 14:10:42 +01:00
commit e7f2203b53
4 changed files with 53 additions and 0 deletions

View file

@ -20,6 +20,14 @@ public class Minion : Agent
followState.AddTransition(patrolState, () => Task is PatrolOrbitsTask, Patrol);
followState.AddTransition(_rootState, () => !(Task is FollowTask));
// The hauler's task (HaulRun.TaskOf): the same switch as patrol's, ignoring the other task states each walk could reach.
var haulState = new HaulState(this);
_rootState.AddTransition(haulState, () => Task is HaulingTask);
haulState.AddTransition(followState, () => Task is FollowTask, null, true, _rootState);
haulState.AddTransition(_rootState, () => !(Task is HaulingTask), null, true, _rootState, followState);
followState.AddTransition(haulState, () => Task is HaulingTask);
patrolState.AddTransition(haulState, () => Task is HaulingTask, null, true, _rootState, followState);
var combatState = new CombatState(this);
_rootState.AddTransition(combatState,
() => View.TargetOf(Ship) != null, null, true, _rootState);

View file

@ -0,0 +1,23 @@
// A hauler's pilot: it flies to the orbit of HaulRun.Leg and, within docking distance of a station where the call would move a unit,
// commands the call (HaulRun.Call docks, moves the goods and undocks it, which gives it a fresh pilot on the same task). No field
// but its child: the leg is derived from the hold on every update, so a hand-emptied hold changes it at once.
public class HaulState : BaseState
{
public HaulState(Agent agent) : base(agent)
{
var move = new MoveToOrbitState(agent);
HaulOrderData Order() => _agent.Task is HaulingTask task ? HaulRun.OrderOf(_agent.ItemManager, task.Order) : null;
OrbitalEntity Station() => HaulRun.Station(_agent.Ship.Zone, move.Orbit);
bool Callable()
{
var order = Order();
var station = order == null ? null : Station();
return station != null && move.Distance < _agent.Settings.DockingDistance && HaulRun.CanCall(_agent.Ship, station, order);
}
Transitions.Add(new StateTransition(move, () => Order() != null, () => move.Orbit = HaulRun.Leg(_agent.Ship, Order())));
// A changed leg re-enters this state, which points the child at it; a callable station commands the call.
move.Transitions.Add(new StateTransition(this, () => Order() is HaulOrderData order && !HaulRun.Leg(_agent.Ship, order).Equals(move.Orbit), null));
move.Transitions.Add(new StateTransition(this, Callable, () => _agent.Ship.Command.Call(Station())));
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c8eaf78200fa454292cd86bdde3f4903
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3d0757eadcb14d11a9b559eb79cef9e6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: