Port autonomous hauling to daemon task execution

This commit is contained in:
Meta Vens 2026-07-11 18:19:03 +01:00
commit be0738830a
10 changed files with 302 additions and 4 deletions

View file

@ -17,8 +17,135 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
AgentClaimsAndCompletesExploreTaskThroughCommands();
SchedulerAssignsHighestPriorityCompatibleTask();
AgentCompletesAttackTaskThroughTargetFireAndYmir();
AgentCompletesHaulTaskThroughMovementAndCargoCommands();
RejectedHaulTransferDoesNotAdvanceTask();
}
private static void RejectedHaulTransferDoesNotAdvanceTask()
{
var origin = Entity(0, 0, "workers");
origin.CargoContents = [Cargo(("ore", 2, 0, 0))];
var agent = Entity(1, 0, "workers");
agent.AgentTaskCapabilities = [AetheriaRuntimeAgentTaskTypes.Haul];
agent.CargoContents = Array.Empty<AetheriaRuntimeCargoBayLoadoutCommit>();
var destination = Entity(2, 20, "workers");
destination.CargoContents = [Cargo()];
var task = new AetheriaRuntimeAgentTaskCommit
{
TaskId = "rejected-haul",
CorporationKey = "workers",
TaskType = AetheriaRuntimeAgentTaskTypes.Haul,
Priority = 1,
ZoneIndex = 0,
OriginEntityIndex = 0,
TargetEntityIndex = 2,
ItemKey = "ore",
RequestedQuantity = 1,
CompletionRadius = 5,
Phase = "pickup"
};
var run = new AetheriaRuntimeRunCheckpointCommit
{
RunId = "rejected-haul-smoke",
Zones = [new AetheriaRuntimeZoneSnapshotCommit { ZoneIndex = 0, Entities = [origin, agent, destination] }],
AgentTasks = [task]
};
var planned = AetheriaRuntimeAgentScheduler.AssignAndPlan(run, 1);
var reduced = AetheriaRuntimeDaemonOperations.Execute(run, planned);
AetheriaRuntimeAgentScheduler.Reconcile(run, 1, reduced.AppliedCommandIds, reduced.RejectedCommandIds);
Require(reduced.RejectedCommandIds.Any(id => id.EndsWith(":pickup", StringComparison.Ordinal)),
"invalid pickup must be rejected by the normal cargo reducer");
RequireEqual("pickup", task.Phase, "rejected pickup must not advance the haul task");
RequireEqual(0, task.PendingQuantity, "rejected pickup must clear pending transfer state");
RequireEqual(2, CargoQuantity(origin, "ore"), "rejected pickup must leave origin cargo untouched");
}
private static void AgentCompletesHaulTaskThroughMovementAndCargoCommands()
{
var origin = Entity(0, 0, "workers");
origin.Kind = "station";
origin.CargoContents = [Cargo(("ore", 5, 2, 3))];
var agent = Entity(1, 0, "workers");
agent.AgentTaskCapabilities = [AetheriaRuntimeAgentTaskTypes.Haul];
agent.CargoContents = [Cargo()];
var destination = Entity(2, 50, "workers");
destination.Kind = "station";
destination.CargoContents = [Cargo()];
var run = new AetheriaRuntimeRunCheckpointCommit
{
RunId = "agent-haul-smoke",
CurrentZoneIndex = 0,
CurrentEntityKey = "zone.0.entity.1",
Zones = [new AetheriaRuntimeZoneSnapshotCommit { ZoneIndex = 0, Entities = [origin, agent, destination] }]
};
var issue = AetheriaRuntimeDaemonCommandDocument.Create(
AetheriaRuntimeDaemonCommandKinds.IssueAgentTask,
"commander-smoke",
"starbridge-smoke",
0,
"");
issue.CommandId = "issue-haul";
issue.AgentTask = new AetheriaRuntimeAgentTaskCommand
{
TaskId = "haul-ore",
CorporationKey = "workers",
TaskType = AetheriaRuntimeAgentTaskTypes.Haul,
Priority = 40,
ZoneIndex = 0,
OriginEntityIndex = 0,
TargetEntityIndex = 2,
ItemKey = "ore",
Quantity = 3,
CompletionRadius = 5
};
var sawPickup = false;
var sawDelivery = false;
for (var frame = 0; frame < 30; frame++)
{
var tick = AetheriaRuntimeDaemonTickRunner.Tick(
Path.Combine(Path.GetTempPath(), "aetheria-agent-haul-smoke.cc"),
run,
new AetheriaRuntimeDaemonTickOptions
{
FrameId = frame,
FixedDeltaSeconds = 0.1,
SimulationTimeSeconds = frame * 0.1,
ObservedCommands = frame == 0 ? [issue] : Array.Empty<AetheriaRuntimeDaemonCommandDocument>(),
ProjectilePhysics = AetheriaRuntimeProjectilePhysicsUnavailable.Instance,
BuildPublications = false
});
sawPickup |= tick.OperationResult.AppliedCommandIds.Any(id => id.EndsWith(":pickup", StringComparison.Ordinal));
sawDelivery |= tick.OperationResult.AppliedCommandIds.Any(id => id.EndsWith(":delivery", StringComparison.Ordinal));
if (string.Equals(run.AgentTasks.Single().Status, AetheriaRuntimeAgentTaskStatuses.Completed, StringComparison.Ordinal))
break;
}
Require(sawPickup && sawDelivery, "haul task must use accepted pickup and delivery cargo commands");
RequireEqual(AetheriaRuntimeAgentTaskStatuses.Completed, run.AgentTasks.Single().Status,
"haul task must complete only after accepted delivery");
RequireEqual(2, CargoQuantity(origin, "ore"), "origin must retain the unrequested stack quantity");
RequireEqual(3, CargoQuantity(destination, "ore"), "destination must receive exactly the requested quantity");
RequireEqual(0, CargoQuantity(agent, "ore"), "hauler must finish with no in-transit cargo");
}
private static AetheriaRuntimeCargoBayLoadoutCommit Cargo(params (string ItemKey, int Quantity, int X, int Y)[] items) => new()
{
Items = items.Select(item => new AetheriaRuntimeLoadoutItemSlotCommit
{
X = item.X,
Y = item.Y,
Item = new AetheriaRuntimeLoadoutItemCommit { ItemKey = item.ItemKey, Quantity = item.Quantity }
}).ToArray()
};
private static int CargoQuantity(AetheriaRuntimeEntitySnapshotCommit entity, string itemKey) =>
(entity.CargoContents ?? Array.Empty<AetheriaRuntimeCargoBayLoadoutCommit>())
.SelectMany(bay => bay.Items)
.Where(slot => string.Equals(slot.Item.ItemKey, itemKey, StringComparison.Ordinal))
.Sum(slot => slot.Item.Quantity);
private static void AgentCompletesAttackTaskThroughTargetFireAndYmir()
{
var agent = Entity(0, 0, "player");

View file

@ -47,6 +47,12 @@ namespace GameCult.Aetheria.State.Verse
[Key(11)] public int WeaponGroup { get; set; }
[Key(12)] public long AssignedFrameId { get; set; } = -1;
[Key(13)] public long CompletedFrameId { get; set; } = -1;
[Key(14)] public int OriginEntityIndex { get; set; } = -1;
[Key(15)] public string ItemKey { get; set; } = "";
[Key(16)] public int RequestedQuantity { get; set; }
[Key(17)] public int DeliveredQuantity { get; set; }
[Key(18)] public int PendingQuantity { get; set; }
[Key(19)] public string Phase { get; set; } = "";
}
[MessagePackObject]
@ -62,6 +68,9 @@ namespace GameCult.Aetheria.State.Verse
[Key(7)] public double TargetPositionZ { get; set; }
[Key(8)] public double CompletionRadius { get; set; } = 10;
[Key(9)] public int WeaponGroup { get; set; }
[Key(10)] public int OriginEntityIndex { get; set; } = -1;
[Key(11)] public string ItemKey { get; set; } = "";
[Key(12)] public int Quantity { get; set; }
}
public static class AetheriaRuntimeAgentScheduler
@ -80,6 +89,42 @@ namespace GameCult.Aetheria.State.Verse
return PlanAssignedTasks(run, frameId);
}
public static void Reconcile(
AetheriaRuntimeRunCheckpointCommit run,
long frameId,
IReadOnlyCollection<string> appliedCommandIds,
IReadOnlyCollection<string> rejectedCommandIds)
{
var applied = new HashSet<string>(appliedCommandIds ?? Array.Empty<string>(), StringComparer.Ordinal);
var rejected = new HashSet<string>(rejectedCommandIds ?? Array.Empty<string>(), StringComparer.Ordinal);
foreach (var task in (run?.AgentTasks ?? Array.Empty<AetheriaRuntimeAgentTaskCommit>())
.Where(task => task != null && string.Equals(task.TaskType, AetheriaRuntimeAgentTaskTypes.Haul, StringComparison.Ordinal)))
{
var pickupId = CommandId(task, frameId, "pickup");
var deliveryId = CommandId(task, frameId, "delivery");
if (applied.Contains(pickupId))
{
task.Phase = "delivery";
continue;
}
if (applied.Contains(deliveryId))
{
task.DeliveredQuantity += task.PendingQuantity;
task.PendingQuantity = 0;
task.Phase = task.DeliveredQuantity >= task.RequestedQuantity ? "complete" : "pickup";
if (string.Equals(task.Phase, "complete", StringComparison.Ordinal))
{
var agent = FindEntity(run, task.ZoneIndex, task.AssignedEntityIndex);
if (agent != null)
Complete(task, agent, frameId);
}
continue;
}
if (rejected.Contains(pickupId) || rejected.Contains(deliveryId))
task.PendingQuantity = 0;
}
}
private static void AssignQueuedTasks(AetheriaRuntimeRunCheckpointCommit run, long frameId)
{
var tasks = (run.AgentTasks ?? Array.Empty<AetheriaRuntimeAgentTaskCommit>()).Where(task => task != null).ToArray();
@ -128,6 +173,12 @@ namespace GameCult.Aetheria.State.Verse
if (agent == null || !agent.IsActive)
continue;
if (string.Equals(task.TaskType, AetheriaRuntimeAgentTaskTypes.Haul, StringComparison.Ordinal))
{
commands.AddRange(PlanHaul(run, zone!, task, agent, frameId));
continue;
}
var target = task.TargetEntityIndex < 0
? null
: zone!.Entities.FirstOrDefault(entity => entity != null && entity.EntityIndex == task.TargetEntityIndex);
@ -164,6 +215,68 @@ namespace GameCult.Aetheria.State.Verse
return commands;
}
private static IReadOnlyList<AetheriaRuntimeDaemonCommandDocument> PlanHaul(
AetheriaRuntimeRunCheckpointCommit run,
AetheriaRuntimeZoneSnapshotCommit zone,
AetheriaRuntimeAgentTaskCommit task,
AetheriaRuntimeEntitySnapshotCommit agent,
long frameId)
{
var pickup = !string.Equals(task.Phase, "delivery", StringComparison.Ordinal);
var endpointIndex = pickup ? task.OriginEntityIndex : task.TargetEntityIndex;
var endpoint = zone.Entities.FirstOrDefault(entity => entity != null && entity.EntityIndex == endpointIndex);
if (endpoint == null)
{
Fail(task, agent);
return Array.Empty<AetheriaRuntimeDaemonCommandDocument>();
}
var dx = endpoint.PositionX - agent.PositionX;
var dz = endpoint.PositionZ - agent.PositionZ;
var distance = Math.Sqrt(dx * dx + dz * dz);
if (distance > Math.Max(0.01, task.CompletionRadius))
return new[] { Movement(task, agent, frameId, dx, dz, 1) };
var source = pickup ? endpoint : agent;
var destination = pickup ? agent : endpoint;
var sourceSlot = (source.CargoContents ?? Array.Empty<AetheriaRuntimeCargoBayLoadoutCommit>())
.SelectMany((bay, bayIndex) => (bay?.Items ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotCommit>())
.Where(slot => string.Equals(slot?.Item?.ItemKey, task.ItemKey, StringComparison.Ordinal))
.Select(slot => (BayIndex: bayIndex, Slot: slot)))
.FirstOrDefault();
if (sourceSlot.Slot == null)
{
Fail(task, agent);
return Array.Empty<AetheriaRuntimeDaemonCommandDocument>();
}
var remaining = task.RequestedQuantity - task.DeliveredQuantity;
var quantity = Math.Min(remaining, Math.Max(1, sourceSlot.Slot.Item.Quantity));
task.PendingQuantity = quantity;
var transfer = Command(task, agent, frameId, AetheriaRuntimeDaemonCommandKinds.TransferCargoItem,
pickup ? "pickup" : "delivery", command =>
{
command.TextValue = task.ItemKey;
command.ScalarValue = quantity;
command.TargetEntityKey = EntityKey(run, task.ZoneIndex, destination.EntityIndex);
command.CargoTransfer = new AetheriaRuntimeCargoTransferCommand
{
OriginEntityKey = EntityKey(run, task.ZoneIndex, source.EntityIndex),
OriginCargoIndex = sourceSlot.BayIndex,
DestinationEntityKey = EntityKey(run, task.ZoneIndex, destination.EntityIndex),
DestinationCargoIndex = 0,
SourceX = sourceSlot.Slot.X,
SourceY = sourceSlot.Slot.Y,
Quantity = quantity
};
});
return new[]
{
Movement(task, agent, frameId, 0, 0, 0),
transfer
};
}
private static AetheriaRuntimeDaemonCommandDocument Movement(
AetheriaRuntimeAgentTaskCommit task,
AetheriaRuntimeEntitySnapshotCommit agent,
@ -191,7 +304,7 @@ namespace GameCult.Aetheria.State.Verse
{
var actor = $"zone.{task.ZoneIndex}.entity.{agent.EntityIndex}";
var command = AetheriaRuntimeDaemonCommandDocument.Create(kind, RuntimeId, "daemon-agent-scheduler", frameId, actor);
command.CommandId = string.Join(":", RuntimeId, task.TaskId, frameId.ToString(CultureInfo.InvariantCulture), phase);
command.CommandId = CommandId(task, frameId, phase);
configure(command);
return command;
}
@ -203,6 +316,24 @@ namespace GameCult.Aetheria.State.Verse
agent.AssignedAgentTaskId = "";
}
private static void Fail(AetheriaRuntimeAgentTaskCommit task, AetheriaRuntimeEntitySnapshotCommit agent)
{
task.Status = AetheriaRuntimeAgentTaskStatuses.Failed;
task.PendingQuantity = 0;
agent.AssignedAgentTaskId = "";
}
private static string CommandId(AetheriaRuntimeAgentTaskCommit task, long frameId, string phase) =>
string.Join(":", RuntimeId, task.TaskId, frameId.ToString(CultureInfo.InvariantCulture), phase);
private static AetheriaRuntimeEntitySnapshotCommit? FindEntity(
AetheriaRuntimeRunCheckpointCommit run,
int zoneIndex,
int entityIndex) =>
(run.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>())
.FirstOrDefault(zone => zone != null && zone.ZoneIndex == zoneIndex)
?.Entities?.FirstOrDefault(entity => entity != null && entity.EntityIndex == entityIndex);
private static void ReleaseInvalidAssignments(AetheriaRuntimeRunCheckpointCommit run)
{
var activeTaskIds = (run.AgentTasks ?? Array.Empty<AetheriaRuntimeAgentTaskCommit>())

View file

@ -843,6 +843,9 @@ namespace GameCult.Aetheria.State.Verse
[Key(8)]
public bool HasDestinationPosition { get; set; }
[Key(9)]
public int Quantity { get; set; }
}
[MessagePackObject]

View file

@ -182,6 +182,11 @@ namespace GameCult.Aetheria.State.Verse
("zoneIndex", task.ZoneIndex.ToString(CultureInfo.InvariantCulture)),
("assignedEntityIndex", task.AssignedEntityIndex.ToString(CultureInfo.InvariantCulture)),
("targetEntityIndex", task.TargetEntityIndex.ToString(CultureInfo.InvariantCulture)),
("originEntityIndex", task.OriginEntityIndex.ToString(CultureInfo.InvariantCulture)),
("itemKey", task.ItemKey),
("requestedQuantity", task.RequestedQuantity.ToString(CultureInfo.InvariantCulture)),
("deliveredQuantity", task.DeliveredQuantity.ToString(CultureInfo.InvariantCulture)),
("phase", task.Phase),
("targetPosition", string.Join(",", new[]
{
task.TargetPositionX.ToString("0.###", CultureInfo.InvariantCulture),

View file

@ -435,6 +435,7 @@ namespace GameCult.Aetheria.State.Verse
command.CargoTransfer.DestinationX = destinationX;
command.CargoTransfer.DestinationY = destinationY;
command.CargoTransfer.HasDestinationPosition = hasDestinationPosition;
command.CargoTransfer.Quantity = quantity;
return Send(command);
}

View file

@ -203,6 +203,12 @@ namespace GameCult.Aetheria.State.Verse
{
return false;
}
if (string.Equals(taskType, AetheriaRuntimeAgentTaskTypes.Haul, StringComparison.Ordinal) &&
(request.OriginEntityIndex < 0 || request.TargetEntityIndex < 0 ||
string.IsNullOrWhiteSpace(request.ItemKey) || request.Quantity <= 0))
{
return false;
}
run.AgentTasks = (run.AgentTasks ?? Array.Empty<AetheriaRuntimeAgentTaskCommit>())
.Concat(new[]
@ -219,6 +225,12 @@ namespace GameCult.Aetheria.State.Verse
TargetPositionZ = request.TargetPositionZ,
CompletionRadius = request.CompletionRadius > 0 ? request.CompletionRadius : 10,
WeaponGroup = request.WeaponGroup,
OriginEntityIndex = request.OriginEntityIndex,
ItemKey = request.ItemKey ?? "",
RequestedQuantity = request.Quantity,
Phase = string.Equals(taskType, AetheriaRuntimeAgentTaskTypes.Haul, StringComparison.Ordinal)
? "pickup"
: "",
Status = AetheriaRuntimeAgentTaskStatuses.Queued
}
})
@ -661,12 +673,16 @@ namespace GameCult.Aetheria.State.Verse
var sourceX = transfer.SourceX;
var sourceY = transfer.SourceY;
if (!TryRemoveCargoItem(
var quantity = transfer.Quantity > 0
? transfer.Quantity
: (int)Math.Round(command.ScalarValue);
if (!TryRemoveCargoItemQuantity(
originEntity,
originCargoIndex,
command.TextValue,
sourceX,
sourceY,
quantity,
out var slot))
{
return false;

View file

@ -507,7 +507,10 @@ public sealed class AetheriaRuntimeDaemonOperationsClient
TargetPositionX = ReadPayloadDouble(request, "targetPositionX", 0),
TargetPositionZ = ReadPayloadDouble(request, "targetPositionZ", 0),
CompletionRadius = ReadPayloadDouble(request, "completionRadius", 10),
WeaponGroup = (int)ReadPayloadDouble(request, "weaponGroup", 0)
WeaponGroup = (int)ReadPayloadDouble(request, "weaponGroup", 0),
OriginEntityIndex = (int)ReadPayloadDouble(request, "originEntityIndex", -1),
ItemKey = ReadPayloadString(request, "itemKey", ""),
Quantity = (int)ReadPayloadDouble(request, "quantity", 0)
}),
AetheriaRuntimeDaemonCommandKinds.CancelAgentTask => client.CancelAgentTask(
frame,

View file

@ -140,6 +140,11 @@ namespace GameCult.Aetheria.State.Verse
operationResult.Run,
agentCommands,
options.OperationContext);
AetheriaRuntimeAgentScheduler.Reconcile(
agentResult.Run,
options.FrameId,
agentResult.AppliedCommandIds,
agentResult.RejectedCommandIds);
operationResult = new AetheriaRuntimeDaemonOperationResult(
agentResult.Run,
operationResult.AppliedCommandIds.Concat(agentResult.AppliedCommandIds).ToArray(),

View file

@ -42,7 +42,7 @@ validation proves contract shape, not wiring, exclusivity, lowering, or parity.
| Starbridge | original/shared architecture intent | one daemon session | pilot + commander surfaces | Unity + Electron | commander task board and autonomous explore execution wired; Electron Eve lowering and split-target proof missing | commander orders plus four pilots and autonomous workers |
| Behavior engine | `ServerShared/Behaviors` composition | daemon | executable action/status projection | action bar and feedback | reference | every behavior family and modifier lifecycle |
| Sensors/visibility | decaying sources and observer information thresholds | daemon | contacts and ping events | indicators/maps | reference | threshold, decay, ping and classification timelines |
| AI/tasks | corporation task scheduler plus agent state machines | daemon | commander task board and shared semantic controls | Eve commander/pilot clients | explore and attack task execution wired through shared movement/target/fire commands; capability/priority assignment proven; remaining task families reference | original optimum-range control, mine/haul/tow/defend timelines, cancellation and reconnect |
| AI/tasks | corporation task scheduler plus agent state machines | daemon | commander task board and shared semantic controls | Eve commander/pilot clients | explore, attack, and same-zone haul execution wired through shared commands; capability/priority assignment and rejected-transfer behavior proven | original optimum-range control, cross-zone haul, mine/tow/defend timelines, cancellation and reconnect |
| Consumables | cargo-backed timed behavior containers | daemon | dynamic actions and active effects | action bar/schematic | reference | consume, stacking, duration and cleanup |
## Ownership Invariants

View file

@ -103,6 +103,13 @@ controller's ordinary `AssignTask` entry point. The daemon scheduler must retain
that queue/capability/priority/availability contract. Assignment state is
durable; task execution drives the same semantic controls used by players.
The historical hauling controller (`991d411c`) travels to the origin, docks,
loads up to available capacity and outstanding quantity, waits, travels to the
destination, docks, unloads, and repeats until the requested quantity is
delivered. Daemon task phases may advance only from accepted movement,
docking, and cargo-transfer results. A rejected transfer leaves both cargo and
task phase unchanged.
## Quality And Progression
Crafted items carry continuous quality. Quality changes performance, durability