From 266ab49dc633375e259e7a711b564e33f4ba25a6 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 11 Jul 2026 18:05:19 +0100 Subject: [PATCH] Restore daemon corporation task scheduling --- .../aetheria-rts-generated-bindings.ts | 16 +- Aetheria.State.Daemon.Smoke/Program.cs | 116 ++++++++++ .../Runtime/AetheriaRuntimeAgentTasks.cs | 217 ++++++++++++++++++ .../Runtime/AetheriaRuntimeAgentTasks.cs.meta | 2 + .../Runtime/AetheriaRuntimeDaemonDocuments.cs | 7 +- ...AetheriaRuntimeDaemonGameSurfaceBuilder.cs | 53 +++++ .../AetheriaRuntimeDaemonOperationClient.cs | 23 ++ .../AetheriaRuntimeDaemonOperations.cs | 71 ++++++ .../AetheriaRuntimeDaemonOperationsClient.cs | 28 +++ .../AetheriaRuntimeDaemonTickRunner.cs | 13 ++ .../AetheriaRuntimeSnapshotDocuments.cs | 10 + .../AetheriaRuntimeVerseAuthorityPolicy.cs | 3 + docs/original-game-migration-matrix.md | 4 +- docs/original-game-simulation-spec.md | 16 +- 14 files changed, 570 insertions(+), 9 deletions(-) create mode 100644 Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAgentTasks.cs create mode 100644 Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAgentTasks.cs.meta diff --git a/Aetheria.Rts.Web/Electron/aetheria-rts-generated-bindings.ts b/Aetheria.Rts.Web/Electron/aetheria-rts-generated-bindings.ts index e442757a3..c4c7b9292 100644 --- a/Aetheria.Rts.Web/Electron/aetheria-rts-generated-bindings.ts +++ b/Aetheria.Rts.Web/Electron/aetheria-rts-generated-bindings.ts @@ -71,6 +71,8 @@ export const AetheriaRuntimeDaemonCommandKinds = { setHeatsinksEnabled: 37, setShutdownPerformance: 38, toggleShieldEnabled: 39, + issueAgentTask: 40, + cancelAgentTask: 41, } as const; export const AetheriaRuntimeEveCommandKinds = { @@ -165,7 +167,8 @@ export type AetheriaRuntimeDaemonCommandDocumentSlot = | "storeItem" | "authorRuntimeId" | "subjectKey" - | "claimKind"; + | "claimKind" + | "agentTask"; export const aetheriaRuntimeDaemonCommandDocumentSlots: Record = { schema: 0, @@ -197,6 +200,7 @@ export const aetheriaRuntimeDaemonCommandDocumentSlots: Record = { runId: 0, @@ -964,6 +969,7 @@ export const aetheriaRuntimeRunCheckpointCommitSlots: Record = { entityIndex: 0, @@ -1082,6 +1090,8 @@ export const aetheriaRuntimeEntitySnapshotCommitSlots: Record new() + { + TaskId = id, + CorporationKey = "workers", + TaskType = AetheriaRuntimeAgentTaskTypes.Explore, + Priority = priority, + ZoneIndex = 0, + TargetPositionX = 100, + CompletionRadius = 5 + }; + + private static void AgentClaimsAndCompletesExploreTaskThroughCommands() + { + var agent = Entity(0, 0, "workers"); + agent.AgentTaskCapabilities = [AetheriaRuntimeAgentTaskTypes.Explore]; + var run = new AetheriaRuntimeRunCheckpointCommit + { + RunId = "agent-task-smoke", + CurrentZoneIndex = 0, + CurrentEntityKey = "zone.0.entity.0", + Zones = [new AetheriaRuntimeZoneSnapshotCommit { ZoneIndex = 0, Entities = [agent] }] + }; + var issue = AetheriaRuntimeDaemonCommandDocument.Create( + AetheriaRuntimeDaemonCommandKinds.IssueAgentTask, + "commander-smoke", + "starbridge-smoke", + 0, + ""); + issue.CommandId = "issue-explore"; + issue.AgentTask = new AetheriaRuntimeAgentTaskCommand + { + TaskId = "explore-east", + CorporationKey = "workers", + TaskType = AetheriaRuntimeAgentTaskTypes.Explore, + Priority = 50, + ZoneIndex = 0, + TargetPositionX = 50, + TargetPositionZ = 0, + CompletionRadius = 5 + }; + var completed = false; + for (var frame = 0; frame <= 20; frame++) + { + var tick = AetheriaRuntimeDaemonTickRunner.Tick( + Path.Combine(Path.GetTempPath(), "aetheria-agent-task-smoke.cc"), + run, + new AetheriaRuntimeDaemonTickOptions + { + FrameId = frame, + FixedDeltaSeconds = 0.1, + SimulationTimeSeconds = frame * 0.1, + ObservedCommands = frame == 0 ? [issue] : Array.Empty(), + ProjectilePhysics = AetheriaRuntimeProjectilePhysicsUnavailable.Instance, + BuildPublications = false + }); + if (frame == 0) + { + Require(tick.OperationResult.AppliedCommandIds.Contains("issue-explore"), + "commander task command must enter the normal tick reducer"); + Require(tick.OperationResult.AppliedCommandIds.Any(id => id.Contains(":explore-east:0:move", StringComparison.Ordinal)), + "agent movement must return through the same command receipts"); + } + completed = string.Equals(run.AgentTasks.Single().Status, AetheriaRuntimeAgentTaskStatuses.Completed, StringComparison.Ordinal); + if (completed) + break; + } + + Require(completed, "agent must complete an explore task without direct position mutation"); + Require(string.IsNullOrWhiteSpace(agent.AssignedAgentTaskId), "completed task must release the agent"); + Require(agent.PositionX >= 45, "agent must reach the task through repeated movement commands"); + + var frameDocument = new AetheriaRuntimeDaemonFrameDocument { FrameId = 21, Run = run }; + var commander = AetheriaRuntimeDaemonGameSurfaceBuilder.BuildCommander( + frameDocument, + new AetheriaRuntimeDaemonHealthDocument(), + AetheriaRuntimeDaemonCommandBoundaryDocument.Create("agent-task-smoke")); + var taskNode = Flatten(commander.Surface.Root) + .Single(component => string.Equals(component.Id, "aetheria.starbridge.commander.tasks.explore_east", StringComparison.Ordinal)); + RequireEqual(AetheriaRuntimeAgentTaskStatuses.Completed, taskNode.Props["status"], + "commander Eve surface must publish authoritative task status"); + Require(commander.Commands.Any(command => string.Equals(command.Command, "aetheria.daemon.issue_agent_task", StringComparison.Ordinal)), + "commander Eve surface must advertise task issue command"); } private static void MultipleActorsUseTheSameMovementLever() @@ -224,6 +332,14 @@ internal sealed class AetheriaDaemonYmirSmokeChecks private static double GridValue(AetheriaRuntimeEntitySnapshotCommit entity, string name, int index) => entity.StatGrids.Single(grid => string.Equals(grid.Name, name, StringComparison.OrdinalIgnoreCase)).Values[index]; + private static IEnumerable Flatten(AetheriaRuntimeSurfaceComponent root) + { + yield return root; + foreach (var child in root.Children) + foreach (var descendant in Flatten(child)) + yield return descendant; + } + private static double Stat(AetheriaRuntimeEntitySnapshotCommit entity, string name) => entity.StatGrids.Single(grid => string.Equals(grid.Name, name, StringComparison.OrdinalIgnoreCase)).Values[0]; diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAgentTasks.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAgentTasks.cs new file mode 100644 index 000000000..79c449083 --- /dev/null +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAgentTasks.cs @@ -0,0 +1,217 @@ +using MessagePack; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; + +#nullable enable + +namespace GameCult.Aetheria.State.Verse +{ + public static class AetheriaRuntimeAgentTaskTypes + { + public const string Mine = "mine"; + public const string Haul = "haul"; + public const string Tow = "tow"; + public const string Defend = "defend"; + public const string Attack = "attack"; + public const string Explore = "explore"; + + public static readonly IReadOnlyList All = + new[] { Mine, Haul, Tow, Defend, Attack, Explore }; + } + + public static class AetheriaRuntimeAgentTaskStatuses + { + public const string Queued = "queued"; + public const string Assigned = "assigned"; + public const string Completed = "completed"; + public const string Cancelled = "cancelled"; + public const string Failed = "failed"; + } + + [MessagePackObject] + public sealed class AetheriaRuntimeAgentTaskCommit + { + [Key(0)] public string TaskId { get; set; } = ""; + [Key(1)] public string CorporationKey { get; set; } = ""; + [Key(2)] public string TaskType { get; set; } = ""; + [Key(3)] public int Priority { get; set; } + [Key(4)] public int ZoneIndex { get; set; } = -1; + [Key(5)] public string Status { get; set; } = AetheriaRuntimeAgentTaskStatuses.Queued; + [Key(6)] public int AssignedEntityIndex { get; set; } = -1; + [Key(7)] public int TargetEntityIndex { get; set; } = -1; + [Key(8)] public double TargetPositionX { get; set; } + [Key(9)] public double TargetPositionZ { get; set; } + [Key(10)] public double CompletionRadius { get; set; } = 10; + [Key(11)] public int WeaponGroup { get; set; } + [Key(12)] public long AssignedFrameId { get; set; } = -1; + [Key(13)] public long CompletedFrameId { get; set; } = -1; + } + + [MessagePackObject] + public sealed class AetheriaRuntimeAgentTaskCommand + { + [Key(0)] public string TaskId { get; set; } = ""; + [Key(1)] public string CorporationKey { get; set; } = ""; + [Key(2)] public string TaskType { get; set; } = ""; + [Key(3)] public int Priority { get; set; } + [Key(4)] public int ZoneIndex { get; set; } = -1; + [Key(5)] public int TargetEntityIndex { get; set; } = -1; + [Key(6)] public double TargetPositionX { get; set; } + [Key(7)] public double TargetPositionZ { get; set; } + [Key(8)] public double CompletionRadius { get; set; } = 10; + [Key(9)] public int WeaponGroup { get; set; } + } + + public static class AetheriaRuntimeAgentScheduler + { + public const string RuntimeId = "aetheria.daemon.agent-scheduler"; + + public static IReadOnlyList AssignAndPlan( + AetheriaRuntimeRunCheckpointCommit run, + long frameId) + { + if (run == null) + return Array.Empty(); + + ReleaseInvalidAssignments(run); + AssignQueuedTasks(run, frameId); + return PlanAssignedTasks(run, frameId); + } + + private static void AssignQueuedTasks(AetheriaRuntimeRunCheckpointCommit run, long frameId) + { + var tasks = (run.AgentTasks ?? Array.Empty()).Where(task => task != null).ToArray(); + var entities = (run.Zones ?? Array.Empty()) + .Where(zone => zone != null) + .SelectMany(zone => (zone.Entities ?? Array.Empty()) + .Where(entity => entity != null) + .Select(entity => (zone.ZoneIndex, Entity: entity))) + .ToArray(); + + foreach (var corporation in tasks + .Where(task => string.Equals(task.Status, AetheriaRuntimeAgentTaskStatuses.Queued, StringComparison.Ordinal)) + .GroupBy(task => task.CorporationKey ?? "", StringComparer.Ordinal)) + foreach (var typeAndZone in corporation.GroupBy(task => (TaskType: task.TaskType ?? "", task.ZoneIndex))) + { + var available = entities + .Where(pair => pair.Entity.IsActive && string.IsNullOrWhiteSpace(pair.Entity.AssignedAgentTaskId)) + .Where(pair => string.Equals(pair.Entity.FactionKey ?? "", corporation.Key, StringComparison.Ordinal)) + .Where(pair => pair.ZoneIndex == typeAndZone.Key.ZoneIndex) + .Where(pair => (pair.Entity.AgentTaskCapabilities ?? Array.Empty()).Contains(typeAndZone.Key.TaskType, StringComparer.Ordinal)) + .OrderBy(pair => pair.ZoneIndex) + .ThenBy(pair => pair.Entity.EntityIndex) + .ToArray(); + var orderedTasks = typeAndZone.OrderByDescending(task => task.Priority).ThenBy(task => task.TaskId, StringComparer.Ordinal); + foreach (var assignment in orderedTasks.Zip(available, (task, agent) => (task, agent))) + { + assignment.task.Status = AetheriaRuntimeAgentTaskStatuses.Assigned; + assignment.task.AssignedEntityIndex = assignment.agent.Entity.EntityIndex; + assignment.task.AssignedFrameId = frameId; + assignment.agent.Entity.AssignedAgentTaskId = assignment.task.TaskId; + } + } + } + + private static IReadOnlyList PlanAssignedTasks( + AetheriaRuntimeRunCheckpointCommit run, + long frameId) + { + var commands = new List(); + foreach (var task in (run.AgentTasks ?? Array.Empty()) + .Where(task => task != null && string.Equals(task.Status, AetheriaRuntimeAgentTaskStatuses.Assigned, StringComparison.Ordinal))) + { + var zone = (run.Zones ?? Array.Empty()) + .FirstOrDefault(candidate => candidate != null && candidate.ZoneIndex == task.ZoneIndex); + var agent = zone?.Entities?.FirstOrDefault(entity => entity != null && entity.EntityIndex == task.AssignedEntityIndex); + if (agent == null || !agent.IsActive) + continue; + + var target = task.TargetEntityIndex < 0 + ? null + : zone!.Entities.FirstOrDefault(entity => entity != null && entity.EntityIndex == task.TargetEntityIndex); + var targetX = target?.PositionX ?? task.TargetPositionX; + var targetZ = target?.PositionZ ?? task.TargetPositionZ; + var dx = targetX - agent.PositionX; + var dz = targetZ - agent.PositionZ; + var distance = Math.Sqrt(dx * dx + dz * dz); + if (distance <= Math.Max(0.01, task.CompletionRadius) && + !string.Equals(task.TaskType, AetheriaRuntimeAgentTaskTypes.Attack, StringComparison.Ordinal)) + { + Complete(task, agent, frameId); + commands.Add(Movement(task, agent, frameId, 0, 0, 0)); + continue; + } + + var magnitude = distance <= 0.0001 ? 0 : 1; + commands.Add(Movement(task, agent, frameId, dx, dz, magnitude)); + if (string.Equals(task.TaskType, AetheriaRuntimeAgentTaskTypes.Attack, StringComparison.Ordinal) && target != null) + { + commands.Add(Command(task, agent, frameId, AetheriaRuntimeDaemonCommandKinds.SetTarget, "target", command => + command.TargetEntityKey = EntityKey(run, task.ZoneIndex, target.EntityIndex))); + commands.Add(Command(task, agent, frameId, AetheriaRuntimeDaemonCommandKinds.FireWeaponGroup, "fire", command => + command.WeaponGroup = Math.Max(0, task.WeaponGroup))); + } + } + return commands; + } + + private static AetheriaRuntimeDaemonCommandDocument Movement( + AetheriaRuntimeAgentTaskCommit task, + AetheriaRuntimeEntitySnapshotCommit agent, + long frameId, + double dx, + double dz, + double magnitude) + { + return Command(task, agent, frameId, AetheriaRuntimeDaemonCommandKinds.SetMoveVector, "move", command => + { + var length = Math.Sqrt(dx * dx + dz * dz); + command.DirectionX = length <= 0.0001 ? 0 : dx / length; + command.DirectionY = length <= 0.0001 ? 0 : dz / length; + command.ScalarValue = magnitude; + }); + } + + private static AetheriaRuntimeDaemonCommandDocument Command( + AetheriaRuntimeAgentTaskCommit task, + AetheriaRuntimeEntitySnapshotCommit agent, + long frameId, + AetheriaRuntimeDaemonCommandKinds kind, + string phase, + Action configure) + { + 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); + configure(command); + return command; + } + + private static void Complete(AetheriaRuntimeAgentTaskCommit task, AetheriaRuntimeEntitySnapshotCommit agent, long frameId) + { + task.Status = AetheriaRuntimeAgentTaskStatuses.Completed; + task.CompletedFrameId = frameId; + agent.AssignedAgentTaskId = ""; + } + + private static void ReleaseInvalidAssignments(AetheriaRuntimeRunCheckpointCommit run) + { + var activeTaskIds = (run.AgentTasks ?? Array.Empty()) + .Where(task => task != null && string.Equals(task.Status, AetheriaRuntimeAgentTaskStatuses.Assigned, StringComparison.Ordinal)) + .Select(task => task.TaskId) + .ToHashSet(StringComparer.Ordinal); + foreach (var entity in (run.Zones ?? Array.Empty()) + .Where(zone => zone != null) + .SelectMany(zone => zone.Entities ?? Array.Empty())) + { + if (!string.IsNullOrWhiteSpace(entity.AssignedAgentTaskId) && !activeTaskIds.Contains(entity.AssignedAgentTaskId)) + entity.AssignedAgentTaskId = ""; + } + } + + private static string EntityKey(AetheriaRuntimeRunCheckpointCommit run, int zoneIndex, int entityIndex) => + AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(run.RunId, zoneIndex, entityIndex); + } +} diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAgentTasks.cs.meta b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAgentTasks.cs.meta new file mode 100644 index 000000000..8179dbfc3 --- /dev/null +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAgentTasks.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: f9ad0b6b39cf40bf951dd16f17502991 diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonDocuments.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonDocuments.cs index 4b5bd1e51..25ffcc6e5 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonDocuments.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonDocuments.cs @@ -192,7 +192,9 @@ namespace GameCult.Aetheria.State.Verse SetOverrideShutdown, SetHeatsinksEnabled, SetShutdownPerformance, - ToggleShieldEnabled + ToggleShieldEnabled, + IssueAgentTask, + CancelAgentTask } [CultDocument("gamecult.aetheria.daemon_provider_advertisement", "gamecult.aetheria.daemon_provider_advertisement.v1")] @@ -661,6 +663,9 @@ namespace GameCult.Aetheria.State.Verse [Key(29)] public string ClaimKind { get; set; } = ""; + [Key(30)] + public AetheriaRuntimeAgentTaskCommand AgentTask { get; set; } = new AetheriaRuntimeAgentTaskCommand(); + public static AetheriaRuntimeDaemonCommandDocument Create( AetheriaRuntimeDaemonCommandKinds kind, string clientId, diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs index 9d74ce3e4..1f939118f 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs @@ -133,6 +133,7 @@ namespace GameCult.Aetheria.State.Verse var root = SurfaceRoot( "aetheria.starbridge.commander.root", StrategicWorldSurface("aetheria.starbridge.commander.world", run, zone), + BuildAgentTaskBoard(run), BuildStarbridgeStationStockCard(starbridge), BuildStarbridgeWaveForecastCard(starbridge), BuildStarbridgeRuntimeRolesCard(starbridge)); @@ -153,9 +154,61 @@ namespace GameCult.Aetheria.State.Verse AetheriaRuntimeDaemonSurfaceCommandCatalog.CommandName(entry.Kind), AetheriaRuntimeDaemonSurfaceCommandCatalog.Label(entry.Kind), "cultmesh")) + .Concat(new[] + { + new AetheriaRuntimeSurfaceCommandTemplate("aetheria.daemon.issue_agent_task", "Issue Task", "cultmesh"), + new AetheriaRuntimeSurfaceCommandTemplate("aetheria.daemon.cancel_agent_task", "Cancel Task", "cultmesh") + }) .ToArray()); } + private static AetheriaRuntimeSurfaceComponent BuildAgentTaskBoard(AetheriaRuntimeRunCheckpointCommit run) + { + var tasks = (run.AgentTasks ?? Array.Empty()) + .Where(task => task != null) + .OrderBy(task => TaskStatusOrder(task.Status)) + .ThenByDescending(task => task.Priority) + .ThenBy(task => task.TaskId, StringComparer.Ordinal) + .Select(task => Node( + $"aetheria.starbridge.commander.tasks.{SurfaceToken(task.TaskId)}", + "list.item", + new[] + { + ("label", task.TaskType), + ("taskId", task.TaskId), + ("corporation", task.CorporationKey), + ("status", task.Status), + ("priority", task.Priority.ToString(CultureInfo.InvariantCulture)), + ("zoneIndex", task.ZoneIndex.ToString(CultureInfo.InvariantCulture)), + ("assignedEntityIndex", task.AssignedEntityIndex.ToString(CultureInfo.InvariantCulture)), + ("targetEntityIndex", task.TargetEntityIndex.ToString(CultureInfo.InvariantCulture)), + ("targetPosition", string.Join(",", new[] + { + task.TargetPositionX.ToString("0.###", CultureInfo.InvariantCulture), + task.TargetPositionZ.ToString("0.###", CultureInfo.InvariantCulture) + })), + ("cancelCommand", "aetheria.daemon.cancel_agent_task") + })) + .ToArray(); + return Node( + "aetheria.starbridge.commander.tasks", + "list", + new[] + { + ("title", "Orders"), + ("issueCommand", "aetheria.daemon.issue_agent_task"), + ("taskTypes", string.Join(",", AetheriaRuntimeAgentTaskTypes.All)) + }, + tasks); + } + + private static int TaskStatusOrder(string status) => + string.Equals(status, AetheriaRuntimeAgentTaskStatuses.Assigned, StringComparison.Ordinal) ? 0 : + string.Equals(status, AetheriaRuntimeAgentTaskStatuses.Queued, StringComparison.Ordinal) ? 1 : 2; + + private static string SurfaceToken(string value) => new string( + (value ?? "").Select(character => char.IsLetterOrDigit(character) ? character : '_').ToArray()); + private static AetheriaRuntimeSurfaceComponent StrategicWorldSurface( string id, AetheriaRuntimeRunCheckpointCommit run, diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationClient.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationClient.cs index 9d029407a..d3e464ef6 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationClient.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationClient.cs @@ -571,5 +571,28 @@ namespace GameCult.Aetheria.State.Verse command.StoreItem.HasDestinationPosition = hasDestinationPosition; return Send(command); } + + internal AetheriaRuntimeDaemonCommandEnvelope IssueAgentTask( + AetheriaRuntimeDaemonFrameDocument? frame, + AetheriaRuntimeAgentTaskCommand task) + { + task ??= new AetheriaRuntimeAgentTaskCommand(); + var command = Create(AetheriaRuntimeDaemonCommandKinds.IssueAgentTask, frame); + command.AgentTask = task; + command.SubjectKey = string.IsNullOrWhiteSpace(task.CorporationKey) + ? "aetheria.tasks" + : $"aetheria.tasks.{task.CorporationKey}"; + return Send(command); + } + + internal AetheriaRuntimeDaemonCommandEnvelope CancelAgentTask( + AetheriaRuntimeDaemonFrameDocument? frame, + string taskId) + { + var command = Create(AetheriaRuntimeDaemonCommandKinds.CancelAgentTask, frame); + command.AgentTask.TaskId = taskId ?? ""; + command.SubjectKey = "aetheria.tasks"; + return Send(command); + } } } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs index f2e917563..9243b8169 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs @@ -176,11 +176,82 @@ namespace GameCult.Aetheria.State.Verse return ApplyEnterWormholeIntent(run, command, context.Intents); case AetheriaRuntimeDaemonCommandKinds.TowToStation: return ApplyTowToStationIntent(run, command, context.Intents); + case AetheriaRuntimeDaemonCommandKinds.IssueAgentTask: + return ApplyIssueAgentTask(run, command); + case AetheriaRuntimeDaemonCommandKinds.CancelAgentTask: + return ApplyCancelAgentTask(run, command); default: return false; } } + private static bool ApplyIssueAgentTask( + AetheriaRuntimeRunCheckpointCommit run, + AetheriaRuntimeDaemonCommandDocument command) + { + var request = command.AgentTask ?? new AetheriaRuntimeAgentTaskCommand(); + var taskId = string.IsNullOrWhiteSpace(request.TaskId) ? command.CommandId : request.TaskId; + var taskType = (request.TaskType ?? "").Trim().ToLowerInvariant(); + if (string.IsNullOrWhiteSpace(taskId) || + string.IsNullOrWhiteSpace(request.CorporationKey) || + !AetheriaRuntimeAgentTaskTypes.All.Contains(taskType, StringComparer.Ordinal) || + request.ZoneIndex < 0 || + !(run.Zones ?? Array.Empty()).Any(zone => + zone != null && zone.ZoneIndex == request.ZoneIndex) || + (run.AgentTasks ?? Array.Empty()).Any(task => + task != null && string.Equals(task.TaskId, taskId, StringComparison.Ordinal))) + { + return false; + } + + run.AgentTasks = (run.AgentTasks ?? Array.Empty()) + .Concat(new[] + { + new AetheriaRuntimeAgentTaskCommit + { + TaskId = taskId, + CorporationKey = request.CorporationKey ?? "", + TaskType = taskType, + Priority = request.Priority, + ZoneIndex = request.ZoneIndex, + TargetEntityIndex = request.TargetEntityIndex, + TargetPositionX = request.TargetPositionX, + TargetPositionZ = request.TargetPositionZ, + CompletionRadius = request.CompletionRadius > 0 ? request.CompletionRadius : 10, + WeaponGroup = request.WeaponGroup, + Status = AetheriaRuntimeAgentTaskStatuses.Queued + } + }) + .ToArray(); + return true; + } + + private static bool ApplyCancelAgentTask( + AetheriaRuntimeRunCheckpointCommit run, + AetheriaRuntimeDaemonCommandDocument command) + { + var taskId = command.AgentTask?.TaskId ?? command.TextValue ?? ""; + var task = (run.AgentTasks ?? Array.Empty()) + .FirstOrDefault(candidate => candidate != null && string.Equals(candidate.TaskId, taskId, StringComparison.Ordinal)); + if (task == null || + string.Equals(task.Status, AetheriaRuntimeAgentTaskStatuses.Completed, StringComparison.Ordinal) || + string.Equals(task.Status, AetheriaRuntimeAgentTaskStatuses.Cancelled, StringComparison.Ordinal)) + { + return false; + } + + foreach (var entity in (run.Zones ?? Array.Empty()) + .Where(zone => zone != null) + .SelectMany(zone => zone.Entities ?? Array.Empty())) + { + if (string.Equals(entity.AssignedAgentTaskId, task.TaskId, StringComparison.Ordinal)) + entity.AssignedAgentTaskId = ""; + } + task.Status = AetheriaRuntimeAgentTaskStatuses.Cancelled; + task.AssignedEntityIndex = -1; + return true; + } + private static bool ApplySetTarget( AetheriaRuntimeRunCheckpointCommit run, AetheriaRuntimeDaemonCommandDocument command) diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationsClient.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationsClient.cs index ffef72f75..bdda67f92 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationsClient.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationsClient.cs @@ -92,6 +92,16 @@ public sealed class AetheriaRuntimeDaemonOperationsClient return Submit((client, frame) => client.SetMoveVector(frame, directionX, directionY, scalarValue)); } + public AetheriaRuntimeDaemonCommandEnvelope IssueAgentTask(AetheriaRuntimeAgentTaskCommand task) + { + return Submit((client, frame) => client.IssueAgentTask(frame, task)); + } + + public AetheriaRuntimeDaemonCommandEnvelope CancelAgentTask(string taskId) + { + return Submit((client, frame) => client.CancelAgentTask(frame, taskId)); + } + public CultMeshOperationReceipt SetLookDirection(double directionX, double directionY, double directionZ) { return Send((client, frame) => client.SetLookDirection(frame, directionX, directionY, directionZ)); @@ -484,6 +494,24 @@ public sealed class AetheriaRuntimeDaemonOperationsClient AetheriaRuntimeDaemonCommandKinds.SetTarget => client.SetTarget( frame, ReadPayloadString(request, "targetEntityId", ReadPayloadString(request, "entityId", ""))), + AetheriaRuntimeDaemonCommandKinds.IssueAgentTask => client.IssueAgentTask( + frame, + new AetheriaRuntimeAgentTaskCommand + { + TaskId = ReadPayloadString(request, "taskId", ""), + CorporationKey = ReadPayloadString(request, "corporation", ""), + TaskType = ReadPayloadString(request, "taskType", ""), + Priority = (int)ReadPayloadDouble(request, "priority", 0), + ZoneIndex = (int)ReadPayloadDouble(request, "zoneIndex", -1), + TargetEntityIndex = (int)ReadPayloadDouble(request, "targetEntityIndex", -1), + TargetPositionX = ReadPayloadDouble(request, "targetPositionX", 0), + TargetPositionZ = ReadPayloadDouble(request, "targetPositionZ", 0), + CompletionRadius = ReadPayloadDouble(request, "completionRadius", 10), + WeaponGroup = (int)ReadPayloadDouble(request, "weaponGroup", 0) + }), + AetheriaRuntimeDaemonCommandKinds.CancelAgentTask => client.CancelAgentTask( + frame, + ReadPayloadString(request, "taskId", "")), _ => AetheriaRuntimeDaemonSurfaceCommandCatalog.TrySubmitArgumentless( client, frame, diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonTickRunner.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonTickRunner.cs index 66d24d04c..983f54e4e 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonTickRunner.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonTickRunner.cs @@ -133,6 +133,19 @@ namespace GameCult.Aetheria.State.Verse .ToArray(), operationResult.Intents); } + var agentCommands = AetheriaRuntimeAgentScheduler.AssignAndPlan(operationResult.Run, options.FrameId); + if (agentCommands.Count > 0) + { + var agentResult = AetheriaRuntimeDaemonOperations.Execute( + operationResult.Run, + agentCommands, + options.OperationContext); + operationResult = new AetheriaRuntimeDaemonOperationResult( + agentResult.Run, + operationResult.AppliedCommandIds.Concat(agentResult.AppliedCommandIds).ToArray(), + operationResult.RejectedCommandIds.Concat(agentResult.RejectedCommandIds).ToArray(), + agentResult.Intents); + } AetheriaRuntimeDaemonSimulation.Step( operationResult.Run, operationResult.Intents, diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs index 5c412401b..820709890 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeSnapshotDocuments.cs @@ -195,6 +195,10 @@ namespace GameCult.Aetheria.State.Verse [Key(11)] public int Credits { get; set; } + [Key(12)] + public IReadOnlyList AgentTasks { get; set; } = + Array.Empty(); + public AetheriaRuntimeLoadoutTemplateCommit CreateLoadoutTemplate(string entityKey) { return TryParseEntityKey(entityKey, out var zoneIndex, out var entityIndex) @@ -899,6 +903,12 @@ namespace GameCult.Aetheria.State.Verse [Key(37)] public double ShutdownPerformance { get; set; } + + [Key(38)] + public IReadOnlyList AgentTaskCapabilities { get; set; } = Array.Empty(); + + [Key(39)] + public string AssignedAgentTaskId { get; set; } = ""; } [MessagePackObject] diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseAuthorityPolicy.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseAuthorityPolicy.cs index dc691c882..7eb640a7d 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseAuthorityPolicy.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeVerseAuthorityPolicy.cs @@ -309,6 +309,9 @@ namespace GameCult.Aetheria.State.Verse return AetheriaRuntimeClaimKinds.Metadata; case AetheriaRuntimeDaemonCommandKinds.DestroyEntity: return AetheriaRuntimeClaimKinds.System; + case AetheriaRuntimeDaemonCommandKinds.IssueAgentTask: + case AetheriaRuntimeDaemonCommandKinds.CancelAgentTask: + return AetheriaRuntimeClaimKinds.Ai; case AetheriaRuntimeDaemonCommandKinds.Interact: case AetheriaRuntimeDaemonCommandKinds.SetDockedCurrentShip: return AetheriaRuntimeClaimKinds.Interaction; diff --git a/docs/original-game-migration-matrix.md b/docs/original-game-migration-matrix.md index fac16139f..263a1bdd0 100644 --- a/docs/original-game-migration-matrix.md +++ b/docs/original-game-migration-matrix.md @@ -39,10 +39,10 @@ validation proves contract shape, not wiring, exclusivity, lowering, or parity. | Assets | `Assets/Resources` | Aetheria provider | asset catalog + CultMesh CDN | runtime cache/load | wired; basic lowering; not live-proven remotely | cold/warm remote-only live load and cache proof | | Save/resume | original persistence paths | daemon/CultCache | published current state | clients rehydrate | owner-exists; not parity-proven | mid-loop restart | | Terminus loop | original game composition | daemon/Ymir/Eve | pilot surface | Aetheria.Unity | incomplete; no scenario proof | fly/fire/loot/dock/trade | -| Starbridge | original/shared architecture intent | one daemon session | pilot + commander surfaces | Unity + Electron | incomplete; split-target proof missing | commander plus four pilots | +| 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 | agent state/task framework | daemon | observable intent/state only | no decision authority | reference | combat range control and civilian tasks | +| AI/tasks | corporation task scheduler plus agent state machines | daemon | commander task board and shared semantic controls | Eve commander/pilot clients | explore task queue, capability/priority assignment, and shared-command execution wired; remaining task families reference | combat range control, mine/haul/tow/defend/attack 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 diff --git a/docs/original-game-simulation-spec.md b/docs/original-game-simulation-spec.md index 0f0f037aa..64fb7a24e 100644 --- a/docs/original-game-simulation-spec.md +++ b/docs/original-game-simulation-spec.md @@ -94,6 +94,15 @@ towing, survey, and wandering. AI reads the same contacts, behavior graph, physics, and command primitives as players. It does not use privileged damage or movement shortcuts. +The original corporation scheduler is preserved in commit `ab8aa5fb`, +`ServerShared/GameContext.cs`. For each corporation it filters unreserved +tasks, groups them by task type, discards groups with no compatible available +controller, orders jobs by descending priority, zips them with compatible +controllers, flattens the assignments, reserves each task, and calls the +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. + ## Quality And Progression Crafted items carry continuous quality. Quality changes performance, durability @@ -107,9 +116,10 @@ contacts, impulses, projectile trajectories, and spatial placement candidates. The daemon owns equipment interpretation, accepted controls, resource costs, damage meaning, lifecycle, inventory, and persistence. -The current Aetheria-local `AetheriaRuntimeYmirProjectilePhysics` does not call -standalone `Ymir.Core`; it is migration scaffolding, not completion of this -boundary. +Daemon projectile integration and contact detection now call standalone +`Ymir.Core`. Ship flight, gravity, tractor interaction, docking placement, and +the remaining Unity query bridge still need to enter that same world before +the boundary is complete. ## Simulation Pipeline