The dock call: HaulRun (order, leg, CanCall, Call), PilotCommand.Call, and an undocked hauler re-admitted piloted with its haul task derived in CreateAgent
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5bc57ae4fc
commit
579a96cb9e
4 changed files with 69 additions and 3 deletions
|
|
@ -1765,7 +1765,7 @@ public abstract class Entity
|
|||
return bay;
|
||||
}
|
||||
|
||||
public bool TryUndock(Ship ship)
|
||||
public bool TryUndock(Ship ship, bool piloted = false)
|
||||
{
|
||||
var bay = DockingBays.FirstOrDefault(x => x.DockedShip == ship);
|
||||
if (bay == null)
|
||||
|
|
@ -1779,7 +1779,7 @@ public abstract class Entity
|
|||
|
||||
bay.DockedShip = null;
|
||||
ship.RemoveParent();
|
||||
Zone.Admit(ship, piloted: false);
|
||||
Zone.Admit(ship, piloted);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
61
Assets/Scripts/ServerShared/HaulRun.cs
Normal file
61
Assets/Scripts/ServerShared/HaulRun.cs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Caching;
|
||||
|
||||
// The interim haul (aetheria-living-world:ruling:transit-depots-buy-for-onward-haul, demo-zenith-ore-depot): which ship carries for which
|
||||
// standing order (Entity.Haul), where it flies (the leg, derived from its hold every update), and the one dock call that moves goods:
|
||||
// the hauler docks (ruling docking-is-enclosed-bays), the From station's silo loads it or the To station takes its cargo through
|
||||
// StationServices.TryStorePart, and it undocks piloted. No payment moves: both ends are in one comms cell and no station holds an account
|
||||
// (ruling comms-cells-are-zones). The ship's task, orders and cargo are the ship's own; nothing here is stored.
|
||||
public static class HaulRun
|
||||
{
|
||||
public static HaulOrderData OrderOf(ItemManager items, CultRecordKey order) =>
|
||||
order.IsSet() ? items.ItemData.Get<HaulOrderData>(order) : null;
|
||||
|
||||
// The task a ship carrying a haul order starts on, derived at every admission; null for a ship with no order or whose order is gone.
|
||||
public static HaulingTask TaskOf(Ship ship) =>
|
||||
ship.Haul.Key.IsSet() && OrderOf(ship.ItemManager, ship.Haul.Key) != null ? new HaulingTask { Order = ship.Haul.Key } : null;
|
||||
|
||||
// The orbit to steer for: the To station's while the hold holds any good of the order, the From station's otherwise.
|
||||
public static CultRecordKey Leg(Ship ship, HaulOrderData order) =>
|
||||
Carried(ship, order).Any() ? order.To.Key : order.From.Key;
|
||||
|
||||
public static OrbitalEntity Station(Zone zone, CultRecordKey orbit) =>
|
||||
zone.Entities.OfType<OrbitalEntity>().FirstOrDefault(station => station.OrbitData.Equals(orbit));
|
||||
|
||||
// Whether a call at this station would move a unit: read-only, stored nowhere. At the From station the silo holds a good of the order the
|
||||
// hold has room for; at the To station the station wants a carried good and has room for a unit of it. Either needs a free docking bay.
|
||||
public static bool CanCall(Ship ship, OrbitalEntity station, HaulOrderData order)
|
||||
{
|
||||
if (station.DockingBays.All(bay => bay.DockedShip != null)) return false;
|
||||
var orbit = station.OrbitData;
|
||||
if (orbit.Equals(order.From.Key))
|
||||
return station.CargoBays.Where(bay => bay.Data is SiloData).SelectMany(bay => bay.Cargo.Keys).OfType<ICommodityStack>()
|
||||
.Any(stack => Goods(order).Contains(((ItemInstance) stack).Data.Key) && ship.CargoBays.Any(bay => bay.TryFindSpace(stack.Split(1))));
|
||||
if (orbit.Equals(order.To.Key))
|
||||
return Carried(ship, order).Any(stack => StationWants.Bays(station, ((ItemInstance) stack).Data.Key).Any(bay => bay.TryFindSpace(stack.Split(1))));
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
depot.TryUndock(ship, piloted: true);
|
||||
}
|
||||
|
||||
private static IReadOnlyCollection<CultRecordKey> Goods(HaulOrderData order) => order.Goods.Select(good => good.Key).ToArray();
|
||||
|
||||
private static IEnumerable<ICommodityStack> Carried(Ship ship, HaulOrderData order)
|
||||
{
|
||||
var goods = Goods(order);
|
||||
return ship.CargoBays.SelectMany(bay => bay.Cargo.Keys).OfType<ICommodityStack>().Where(stack => goods.Contains(((ItemInstance) stack).Data.Key)).ToArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -58,12 +58,15 @@ public sealed class PilotCommand
|
|||
internal TargetVerb TargetVerb;
|
||||
// The step's give verb: a Give, or a stop when its Receiver is null. The last one in a step wins.
|
||||
internal (Entity Receiver, ItemInstance Item, int Quantity)? GiveVerb;
|
||||
// The step's call on a station (HaulRun.Call): a one-shot a hauler's pilot commands.
|
||||
internal Entity CallVerb;
|
||||
internal int AimCycles;
|
||||
internal int ShutdownOverrideToggles, HeatsinkToggles, ShieldToggles, Pings;
|
||||
|
||||
public void Designate(TargetRef target) => Designations.Add(target);
|
||||
public void SelectItem(EquippedItem item) => Selections.Add(item);
|
||||
public void Hail(string message) => Hails.Add(message);
|
||||
public void Call(Entity station) => CallVerb = station;
|
||||
public void Use(ConsumableItemData consumable) => Uses.Add(consumable);
|
||||
public void Pull(ActivatedBehavior behavior) => Triggers.Add((behavior, true));
|
||||
public void Release(ActivatedBehavior behavior) => Triggers.Add((behavior, false));
|
||||
|
|
@ -120,6 +123,7 @@ public sealed class PilotCommand
|
|||
Iffs.Clear();
|
||||
TargetVerb = TargetVerb.None;
|
||||
GiveVerb = null;
|
||||
CallVerb = null;
|
||||
AimCycles = 0;
|
||||
ShutdownOverrideToggles = HeatsinkToggles = ShieldToggles = Pings = 0;
|
||||
}
|
||||
|
|
@ -161,6 +165,7 @@ public static class PilotApplier
|
|||
if (give.Receiver == null) CargoTransfer.End(entity, GiveEnd.Stopped);
|
||||
else if (!ReferenceEquals(give.Receiver, entity)) CargoTransfer.Begin(entity, new GiveOrder(give.Receiver, give.Item, give.Quantity));
|
||||
}
|
||||
if (command.CallVerb is Entity station && entity is Ship caller) HaulRun.Call(caller, station);
|
||||
if (command.Aim is float3 aim) entity.Aim = aim;
|
||||
foreach (var (behavior, pull) in command.Triggers)
|
||||
if (pull) behavior.Activate();
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ public class Zone
|
|||
_flights[key] = flight = new Flight(ship.Faction?.Doctrine, _itemManager.GameplaySettings);
|
||||
var id = NextAgentId();
|
||||
var agent = new Minion(ship, flight.Combatant) { Id = id };
|
||||
flight.Join(agent, stated ?? PatrolCircuit(id));
|
||||
flight.Join(agent, stated ?? (AgentTask) HaulRun.TaskOf(ship) ?? PatrolCircuit(id));
|
||||
return agent;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue