diff --git a/Aetheria.State.Daemon.Smoke/Program.cs b/Aetheria.State.Daemon.Smoke/Program.cs index e65204714..d6cb571f0 100644 --- a/Aetheria.State.Daemon.Smoke/Program.cs +++ b/Aetheria.State.Daemon.Smoke/Program.cs @@ -20,8 +20,96 @@ internal sealed class AetheriaDaemonYmirSmokeChecks AgentCompletesHaulTaskThroughMovementAndCargoCommands(); RejectedHaulTransferDoesNotAdvanceTask(); AgentPatrolsHistoricalOrbitCircuitThroughMovementCommands(); + TickReconcilesAndEvaluatesCatalogBehaviors(); } + private static void TickReconcilesAndEvaluatesCatalogBehaviors() + { + var entity = Entity(0, 0, "workers"); + entity.Equipment = + [ + new AetheriaRuntimeLoadoutItemSlotCommit + { + Item = new AetheriaRuntimeLoadoutItemCommit + { + ItemKey = "mining-tool", + Quality = 1, + Durability = 1, + Enabled = true + } + } + ]; + entity.BehaviorStates = Array.Empty(); + var payload = new AetheriaRuntimeBehaviorPayload( + 0, + "MiningTool", + 0, + [ + new AetheriaRuntimeBehaviorField(1, PerformanceStat(12)), + new AetheriaRuntimeBehaviorField(2, PerformanceStat(0.8)), + new AetheriaRuntimeBehaviorField(3, PerformanceStat(2)), + new AetheriaRuntimeBehaviorField(4, PerformanceStat(50)) + ]); + var catalog = new AetheriaRuntimeCatalogSnapshot( + [CatalogItem("mining-tool", payload)], + Array.Empty(), + Array.Empty()); + var run = new AetheriaRuntimeRunCheckpointCommit + { + RunId = "behavior-query-smoke", + CurrentZoneIndex = 0, + CurrentEntityKey = "zone.0.entity.0", + Zones = [new AetheriaRuntimeZoneSnapshotCommit { ZoneIndex = 0, Entities = [entity] }] + }; + + AetheriaRuntimeDaemonTickRunner.Tick( + Path.Combine(Path.GetTempPath(), "aetheria-behavior-query-smoke.cc"), + run, + new AetheriaRuntimeDaemonTickOptions + { + FrameId = 1, + FixedDeltaSeconds = 0, + Catalog = catalog, + BuildPublications = false + }); + + var behavior = AetheriaRuntimeEquippedBehaviorQueries.Find(entity, catalog, "MiningTool").Single(); + RequireEqual("MiningTool", behavior.State.BehaviorKind, + "tick must reconcile equipped catalog payloads into persistent behavior state"); + RequireNear(12, behavior.EvaluateStat(1), 0.000001, "behavior query must evaluate mining damage from catalog"); + RequireNear(50, behavior.EvaluateStat(4), 0.000001, "behavior query must evaluate mining range from catalog"); + } + + private static AetheriaRuntimeBehaviorValue PerformanceStat(double value) => new( + "performance-stat", + "", + 0, + false, + "", + "", + [Number(value), Number(value), Number(0), Number(0), Number(0)], + Array.Empty()); + + private static AetheriaRuntimeBehaviorValue Number(double value) => new( + "number", + "", + value, + false, + "", + "", + Array.Empty(), + Array.Empty()); + + private static AetheriaRuntimeCatalogItem CatalogItem(string itemKey, params AetheriaRuntimeBehaviorPayload[] payloads) => new( + itemKey, itemKey, "equipment", "", "", 0, 1, 1, 1, 1, + 1, 1, 1, Array.Empty(), + 0, 0, 0, Array.Empty(), + Array.Empty(), payloads, + "utility", "", payloads.Select(payload => payload.Kind).ToArray(), + 1, false, 0, 1, "", "", "", "", "", + 0, 1000, Array.Empty(), "", 1, 0, 0, 0, false, + 0, 0, "", Array.Empty(), Array.Empty(), "", ""); + private static void AgentPatrolsHistoricalOrbitCircuitThroughMovementCommands() { var agent = Entity(0, 0, "workers"); diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonTickRunner.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonTickRunner.cs index 5b38b4bb8..a1b6cd624 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonTickRunner.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonTickRunner.cs @@ -103,6 +103,7 @@ namespace GameCult.Aetheria.State.Verse run ??= new AetheriaRuntimeRunCheckpointCommit(); options ??= new AetheriaRuntimeDaemonTickOptions(); options.OperationContext ??= new AetheriaRuntimeDaemonOperationContext(); + EnsureBehaviorStates(run, options.Catalog); var observedCommands = (options.ObservedCommands ?? Array.Empty()) .Where(command => command != null) @@ -273,6 +274,20 @@ namespace GameCult.Aetheria.State.Verse editorSurface); } + private static void EnsureBehaviorStates( + AetheriaRuntimeRunCheckpointCommit run, + AetheriaRuntimeCatalogSnapshot? catalog) + { + if (catalog == null) + return; + foreach (var entity in (run.Zones ?? Array.Empty()) + .Where(zone => zone != null) + .SelectMany(zone => zone.Entities ?? Array.Empty())) + { + AetheriaRuntimeBehaviorStateProjector.EnsureEquipmentBehaviorStates(entity, catalog); + } + } + private static void StampZoneSimulationTime( AetheriaRuntimeRunCheckpointCommit run, double simulationTimeSeconds) diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEquippedBehaviorQueries.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEquippedBehaviorQueries.cs new file mode 100644 index 000000000..dbf3f893d --- /dev/null +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEquippedBehaviorQueries.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +#nullable enable + +namespace GameCult.Aetheria.State.Verse +{ + public sealed class AetheriaRuntimeEquippedBehavior + { + public AetheriaRuntimeEquippedBehavior( + int equipmentIndex, + int behaviorIndex, + AetheriaRuntimeLoadoutItemCommit item, + AetheriaRuntimeCatalogItem catalogItem, + AetheriaRuntimeBehaviorPayload payload, + AetheriaRuntimeBehaviorStateCommit state) + { + EquipmentIndex = equipmentIndex; + BehaviorIndex = behaviorIndex; + Item = item; + CatalogItem = catalogItem; + Payload = payload; + State = state; + } + + public int EquipmentIndex { get; } + public int BehaviorIndex { get; } + public AetheriaRuntimeLoadoutItemCommit Item { get; } + public AetheriaRuntimeCatalogItem CatalogItem { get; } + public AetheriaRuntimeBehaviorPayload Payload { get; } + public AetheriaRuntimeBehaviorStateCommit State { get; } + + public double EvaluateStat(int fieldKey, double thermalPerformance = 1.0) + { + var field = (Payload.Fields ?? Array.Empty()) + .FirstOrDefault(candidate => candidate != null && candidate.Key == fieldKey); + return AetheriaRuntimeDaemonItemStatQueries.EvaluatePerformanceStat( + field?.Value, + Item, + Math.Max(0, Math.Min(1, thermalPerformance))); + } + } + + public static class AetheriaRuntimeEquippedBehaviorQueries + { + public static IReadOnlyList Find( + AetheriaRuntimeEntitySnapshotCommit? entity, + AetheriaRuntimeCatalogSnapshot? catalog, + string behaviorKind) + { + if (entity == null || catalog == null || string.IsNullOrWhiteSpace(behaviorKind)) + return Array.Empty(); + + AetheriaRuntimeBehaviorStateProjector.EnsureEquipmentBehaviorStates(entity, catalog); + var states = (entity.BehaviorStates ?? Array.Empty()) + .Where(state => state != null && string.Equals(state.OwnerKind, AetheriaRuntimeBehaviorStateProjector.EquipmentOwnerKind, StringComparison.Ordinal)) + .ToDictionary(state => (state.OwnerIndex, state.BehaviorIndex)); + var found = new List(); + var equipment = entity.Equipment ?? Array.Empty(); + for (var equipmentIndex = 0; equipmentIndex < equipment.Count; equipmentIndex++) + { + var item = equipment[equipmentIndex]?.Item; + var catalogItem = catalog.FindItem(item?.ItemKey ?? ""); + if (item == null || catalogItem == null) + continue; + + var payloads = catalogItem.BehaviorPayloads ?? Array.Empty(); + for (var behaviorIndex = 0; behaviorIndex < payloads.Count; behaviorIndex++) + { + var payload = payloads[behaviorIndex]; + if (payload == null || + !AetheriaRuntimeBehaviorMetadataCatalog.IsKindOrDescendant(payload.Kind, behaviorKind) || + !states.TryGetValue((equipmentIndex, behaviorIndex), out var state)) + { + continue; + } + found.Add(new AetheriaRuntimeEquippedBehavior( + equipmentIndex, + behaviorIndex, + item, + catalogItem, + payload, + state)); + } + } + return found; + } + } +} diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEquippedBehaviorQueries.cs.meta b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEquippedBehaviorQueries.cs.meta new file mode 100644 index 000000000..0d33c7308 --- /dev/null +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEquippedBehaviorQueries.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 2b7af91c0bad4b87a6550e9e0217dad6 diff --git a/docs/original-game-migration-matrix.md b/docs/original-game-migration-matrix.md index 4bf4a4ae6..081bcd513 100644 --- a/docs/original-game-migration-matrix.md +++ b/docs/original-game-migration-matrix.md @@ -40,7 +40,7 @@ validation proves contract shape, not wiring, exclusivity, lowering, or parity. | 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 | 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 | +| Behavior engine | `ServerShared/Behaviors` composition | daemon | executable action/status projection | action bar and feedback | tick reconciles equipped catalog payloads into persistent behavior state; shared evaluated-stat query proven; execution families remain partial | every behavior family, ordering, resource transaction 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, attack, same-zone haul, and persistent orbit patrol wired through shared commands; capability/priority assignment and rejected-transfer behavior proven | original optimum-range control, cross-zone haul, mining, towing, survey-tool 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 |