diff --git a/Assets/Scripts/ServerShared/Agents/Minion.cs b/Assets/Scripts/ServerShared/Agents/Minion.cs index c95b7cfbb..5f89892ef 100644 --- a/Assets/Scripts/ServerShared/Agents/Minion.cs +++ b/Assets/Scripts/ServerShared/Agents/Minion.cs @@ -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); diff --git a/Assets/Scripts/ServerShared/Agents/States/Haul.cs b/Assets/Scripts/ServerShared/Agents/States/Haul.cs new file mode 100644 index 000000000..30ff78b6d --- /dev/null +++ b/Assets/Scripts/ServerShared/Agents/States/Haul.cs @@ -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()))); + } +} diff --git a/Assets/Scripts/ServerShared/Agents/States/Haul.cs.meta b/Assets/Scripts/ServerShared/Agents/States/Haul.cs.meta new file mode 100644 index 000000000..434438a7a --- /dev/null +++ b/Assets/Scripts/ServerShared/Agents/States/Haul.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c8eaf78200fa454292cd86bdde3f4903 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/ServerShared/HaulRun.cs.meta b/Assets/Scripts/ServerShared/HaulRun.cs.meta new file mode 100644 index 000000000..44c9003d2 --- /dev/null +++ b/Assets/Scripts/ServerShared/HaulRun.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3d0757eadcb14d11a9b559eb79cef9e6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: