From 39a407fa958b7d256ad94724c418b811b7dae82c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 17 Jul 2026 04:00:20 +0100 Subject: [PATCH] Exclude docked ships from combat --- Aetheria.State.Daemon.Smoke/Program.cs | 120 ++++++++++++++++++ .../AetheriaRuntimeDaemonOperations.cs | 28 +++- .../AetheriaRuntimeDaemonSimulation.cs | 22 +++- docs/aetheria-perfect-machine-map.md | 30 +++-- docs/original-game-migration-matrix.md | 2 +- 5 files changed, 185 insertions(+), 17 deletions(-) diff --git a/Aetheria.State.Daemon.Smoke/Program.cs b/Aetheria.State.Daemon.Smoke/Program.cs index a8a662dc1..76d9be160 100644 --- a/Aetheria.State.Daemon.Smoke/Program.cs +++ b/Aetheria.State.Daemon.Smoke/Program.cs @@ -170,6 +170,7 @@ internal sealed class AetheriaDaemonYmirSmokeChecks ProjectileContactCannotKill, MissingWorldPhysicsOwnerCannotAdvanceShips, DockingUsesRealBaysAndFossilUndockRules, + DockedEntitiesCannotAttackOrBeTargeted, RefitIsAtomicAndUsesTypedPlacement, CargoTransferUsesSpatialAtomicTransaction, DockedRefitSurfacePublishesGenericCommands, @@ -1167,6 +1168,26 @@ internal sealed class AetheriaDaemonYmirSmokeChecks } var actor = Entity(0, 0, "player"); + actor.WeaponGroups = [new[] { 0 }]; + actor.ActiveWeaponGroups = [true]; + actor.WeaponStates = [new AetheriaRuntimeWeaponStateCommit + { + OwnerKind = AetheriaRuntimeBehaviorStateProjector.EquipmentOwnerKind, + OwnerIndex = 0, + BehaviorIndex = 0, + BehaviorKind = AetheriaRuntimeBehaviorKinds.ChargedWeapon, + Firing = true, + TriggerPending = true, + BurstRemaining = 2, + Charging = true, + Charged = true, + Charge = 1, + ChargeHoldSeconds = 3, + ChargeRiskChecks = 2, + ChargeMalfunctionRisk = 0.5, + LockTargetEntityIndex = 4, + LockProgress = 1 + }]; var ineligible = DockTarget(1, 5, false); var outOfRange = DockTarget(2, 30, true); var firstEligible = DockTarget(3, 20, true); @@ -1200,6 +1221,27 @@ internal sealed class AetheriaDaemonYmirSmokeChecks "docking must not manufacture a bay assignment on an entity with no docking-bay equipment"); RequireEqual(-1, outOfRange.DockingBayAssignments.Single(), "a client scalar must not widen the daemon-owned fossil docking radius"); + var disarmed = actor.WeaponStates.Single(); + RequireEqual(0, actor.ActiveWeaponGroups.Count, + "docking must clear the daemon-owned held weapon-group latch"); + Require(!disarmed.Firing && !disarmed.TriggerPending && disarmed.BurstRemaining == 0 && + !disarmed.Charging && !disarmed.Charged && disarmed.Charge == 0 && + disarmed.LockTargetEntityIndex < 0 && disarmed.LockProgress == 0, + "docking must cancel every transient weapon lifecycle before the ship enters its bay"); + + var dockedFire = AetheriaRuntimeDaemonCommandDocument.Create( + AetheriaRuntimeDaemonCommandKinds.SetWeaponGroupActive, + "pilot", + selectionRun.RunId, + 1, + selectionRun.CurrentEntityKey); + dockedFire.CommandId = "docked-fire-forbidden"; + dockedFire.WeaponGroup = 0; + dockedFire.ScalarValue = 1; + var dockedFireResult = AetheriaRuntimeDaemonOperations.Execute(selectionRun, [dockedFire], context); + Require(dockedFireResult.RejectedCommandIds.Contains(dockedFire.CommandId) && + dockedFireResult.Intents.WeaponGroups.Count == 0 && actor.ActiveWeaponGroups.Count == 0, + "a docked actor must reject held-fire commands without rearming daemon state"); AetheriaRuntimeRunCheckpointCommit DockedRun( IReadOnlyList itemKeys, @@ -1320,6 +1362,84 @@ internal sealed class AetheriaDaemonYmirSmokeChecks "successful undocking must release the exact occupied bay"); } + private static void DockedEntitiesCannotAttackOrBeTargeted() + { + var weaponPayload = new AetheriaRuntimeBehaviorPayload( + 0, + AetheriaRuntimeBehaviorKinds.ConstantWeapon, + 0, + [ + new AetheriaRuntimeBehaviorField(2, PerformanceStat(10)), + new AetheriaRuntimeBehaviorField(6, PerformanceStat(200)), + new AetheriaRuntimeBehaviorField(9, PerformanceStat(0)), + new AetheriaRuntimeBehaviorField(10, PerformanceStat(0)), + new AetheriaRuntimeBehaviorField(11, PerformanceStat(0)), + new AetheriaRuntimeBehaviorField(13, Number(0)), + new AetheriaRuntimeBehaviorField(14, Number(1)), + new AetheriaRuntimeBehaviorField(17, Number(1)) + ]); + var weapon = CatalogItem("docked-combat-weapon", weaponPayload); + var catalog = new AetheriaRuntimeCatalogSnapshot([weapon], [], []); + + static AetheriaRuntimeEntitySnapshotCommit ArmedShip(int index, double x, string faction, string itemKey) + { + var ship = Entity(index, x, faction); + ship.WeaponGroups = [new[] { 0 }]; + ship.ActiveWeaponGroups = [true]; + ship.Equipment = [new AetheriaRuntimeLoadoutItemSlotCommit + { + Item = new AetheriaRuntimeLoadoutItemCommit + { ItemKey = itemKey, Quality = 1, Durability = 1, Enabled = true } + }]; + return ship; + } + + var dockedAttacker = ArmedShip(0, 0, "player", weapon.ItemKey); + dockedAttacker.TargetEntityIndex = 2; + var station = Entity(1, 0, "player"); + station.ChildEntityIndices = [0]; + station.DockingBayAssignments = [0]; + var exposedTarget = Entity(2, 50, "raider"); + var attackerRun = new AetheriaRuntimeRunCheckpointCommit + { + RunId = "docked-attacker-smoke", + CurrentZoneIndex = 0, + Zones = [new AetheriaRuntimeZoneSnapshotCommit + { ZoneIndex = 0, Entities = [dockedAttacker, station, exposedTarget] }] + }; + var forgedIntent = new AetheriaRuntimeDaemonIntentState(); + forgedIntent.WeaponGroups.Add(new AetheriaRuntimeDaemonWeaponGroupIntent + { ActorEntityKey = "zone.0.entity.0", WeaponGroup = 0, Fire = true, Active = true }); + AetheriaRuntimeDaemonSimulation.Step( + attackerRun, forgedIntent, 0.1, new AetheriaRuntimeDaemonSimulationSettings(), + NewPhysics(), catalog, 0, 0); + RequireEqual(0, attackerRun.ShotReceipts.Count, + "combat must subtract docked attackers even when stale state and a forged pulse both request fire"); + RequireNear(100, Stat(exposedTarget, "hull"), 0.000001, + "a docked child must not damage an exposed world entity"); + + var exposedAttacker = ArmedShip(0, 0, "player", weapon.ItemKey); + exposedAttacker.TargetEntityIndex = 1; + var dockedTarget = Entity(1, 50, "raider"); + var hostileStation = Entity(2, 50, "raider"); + hostileStation.ChildEntityIndices = [1]; + hostileStation.DockingBayAssignments = [1]; + var targetRun = new AetheriaRuntimeRunCheckpointCommit + { + RunId = "docked-target-smoke", + CurrentZoneIndex = 0, + Zones = [new AetheriaRuntimeZoneSnapshotCommit + { ZoneIndex = 0, Entities = [exposedAttacker, dockedTarget, hostileStation] }] + }; + AetheriaRuntimeDaemonSimulation.Step( + targetRun, new AetheriaRuntimeDaemonIntentState(), 0.1, + new AetheriaRuntimeDaemonSimulationSettings(), NewPhysics(), catalog, 0, 0); + RequireEqual(0, targetRun.ShotReceipts.Count, + "combat target lookup must subtract docked children from world participants"); + RequireNear(100, Stat(dockedTarget, "hull"), 0.000001, + "a docked child must not receive ordinary world combat damage through stale targeting"); + } + private static void RefitIsAtomicAndUsesTypedPlacement() { static AetheriaRuntimeCatalogItem ShapedItem( diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs index c71495da8..23ac23e84 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs @@ -1380,7 +1380,8 @@ namespace GameCult.Aetheria.State.Verse AetheriaRuntimeDaemonIntentState intents) { var actor = ResolveActorEntityKey(run, command); - if (!TryResolveEntity(run, actor, out _, out _, out var entity) || + if (!TryResolveEntity(run, actor, out var zoneIndex, out var entityIndex, out var entity) || + IsChildReferencedInZone(run, zoneIndex, entityIndex) || !HasWeaponGroup(entity, command.WeaponGroup)) { return false; @@ -1402,7 +1403,8 @@ namespace GameCult.Aetheria.State.Verse AetheriaRuntimeDaemonIntentState intents) { var actor = ResolveActorEntityKey(run, command); - if (!TryResolveEntity(run, actor, out _, out _, out var entity) || + if (!TryResolveEntity(run, actor, out var zoneIndex, out var entityIndex, out var entity) || + IsChildReferencedInZone(run, zoneIndex, entityIndex) || !HasWeaponGroup(entity, command.WeaponGroup)) { return false; @@ -1766,9 +1768,31 @@ namespace GameCult.Aetheria.State.Verse .ToArray(); assignments[bayIndex] = actorIndex; target.DockingBayAssignments = assignments.ToArray(); + DisarmWeapons(actor); return true; } + private static void DisarmWeapons(AetheriaRuntimeEntitySnapshotCommit entity) + { + entity.ActiveWeaponGroups = Array.Empty(); + foreach (var state in entity.WeaponStates ?? Array.Empty()) + { + if (state == null) + continue; + state.Firing = false; + state.TriggerPending = false; + state.BurstRemaining = 0; + state.Charging = false; + state.Charged = false; + state.Charge = 0; + state.ChargeHoldSeconds = 0; + state.ChargeRiskChecks = 0; + state.ChargeMalfunctionRisk = 0; + state.LockTargetEntityIndex = -1; + state.LockProgress = 0; + } + } + private static bool ApplyUndockState( AetheriaRuntimeRunCheckpointCommit run, string actorEntityKey, diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs index 3808b3f4e..2f702a751 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSimulation.cs @@ -496,10 +496,18 @@ namespace GameCult.Aetheria.State.Verse double simulationTimeSeconds, int simulationStepIndex) { - var byIndex = entities.ToDictionary(entity => entity.EntityIndex); + var dockedEntityIndices = (entities ?? Array.Empty()) + .Where(entity => entity != null) + .SelectMany(entity => (entity.ChildEntityIndices ?? Array.Empty()) + .Concat((entity.DockingBayAssignments ?? Array.Empty()).Where(index => index >= 0))) + .ToHashSet(); + var combatEntities = (entities ?? Array.Empty()) + .Where(entity => entity != null && !dockedEntityIndices.Contains(entity.EntityIndex)) + .ToArray(); + var byIndex = combatEntities.ToDictionary(entity => entity.EntityIndex); foreach (var entity in entities) RefreshShieldProjection(entity, catalog); - foreach (var attacker in entities) + foreach (var attacker in combatEntities) { var requestedWeapons = ResolveWeaponTriggers(zone, attacker, entities, intents, catalog); StepDeployableWeapons(run, zone, attacker, requestedWeapons, deltaSeconds, settings, catalog, frameId); @@ -633,7 +641,7 @@ namespace GameCult.Aetheria.State.Verse } } } - ResolveDeployableDetonations(run, zone, entities, frameId, simulationTimeSeconds, catalog, settings); + ResolveDeployableDetonations(run, zone, combatEntities, frameId, simulationTimeSeconds, catalog, settings); foreach (var entity in entities) { @@ -1680,12 +1688,20 @@ namespace GameCult.Aetheria.State.Verse target.TargetEntityIndex = -1; target.TractorPower = 0; target.TractorTargetPower = 0; + target.ActiveWeaponGroups = Array.Empty(); foreach (var state in target.WeaponStates ?? Array.Empty()) { state.Firing = false; + state.TriggerPending = false; + state.BurstRemaining = 0; state.Charging = false; state.Charged = false; + state.Charge = 0; + state.ChargeHoldSeconds = 0; + state.ChargeRiskChecks = 0; + state.ChargeMalfunctionRisk = 0; state.LockTargetEntityIndex = -1; + state.LockProgress = 0; } var pickups = (zone.DroppedPickups ?? Array.Empty()).ToList(); diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index 281d03407..cc3dee50d 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -2926,8 +2926,8 @@ restore follows the same rule: UI requests restoration, and the daemon owns instantiation, credits, dock assignment, current entity, and checkpoint. Docked current-ship selection follows the same rule: UI requests selection, and the daemon owns `CurrentEntity`, `DockingBay.DockedShip`, and checkpoint. Undocking -also owns a collision-free departure pose and clears inherited velocity before -the detached ship re-enters world physics. Loot pickup is contact-gated: the +preserves the fossil ship pose, velocity, and direction when the detached ship +re-enters world physics. Loot pickup is contact-gated: the tractor applies force to loose bodies, Ymir owns typed Begin contact facts, and the daemon alone interprets each persisted fact identity into capacity validation, cargo storage or rejection bounce, pickup removal, feedback, and @@ -3009,8 +3009,10 @@ Run-lifecycle ownership is deliberately narrower than a quest system: Docking ownership follows the fossil's entity and `ActionGameManager` path: -- Owner: daemon docking operations own bay selection, parentage, and the - dock/undock acceptance decision. +- Owner: daemon docking operations own bay selection, parentage, the + dock/undock acceptance decision, and the disarm transition into docked state; + daemon combat derives its participant set by subtracting docked child + identities. - Inputs: zone entity order, the 25-unit interaction radius, real docking-bay slots and assignments, occupied-bay cargo, installed Cockpit, Thruster-or-AetherDrive, and Reactor behaviors, and the ship's preserved @@ -3018,14 +3020,18 @@ Docking ownership follows the fossil's entity and `ActionGameManager` path: fields and spatial queries, but ship/station bodies share a non-colliding group because the fossil had no rigidbody entity collision response; pickup bodies remain independently collidable with ships. -- Outputs: exact parent/assignment mutation, docking intent, and an - authoritative rejection reason carried by the command fact and Eve receipt. +- Outputs: exact parent/assignment mutation, cleared held-group and transient + weapon state on dock, a world-combat participant set containing neither + docked attackers nor docked targets, docking intent, and an authoritative + rejection reason carried by the command fact and Eve receipt. - Derived state: camera target, subject visibility, movement suppression, menu copy, and effects derive from dock parentage plus the receipt. They do not decide whether docking happened. - Forbidden writers: Unity `TryDock`/`TryUndock`, camera transitions, client proximity, command-supplied failure text, and renderer-local component checks - cannot mutate or explain docking truth. + cannot mutate or explain docking truth. Stale input state, forged fire + intents, and installed turret controllers cannot make a docked child a combat + participant. - Shared paths: explicit Dock, DockNearest, contextual Interact, autonomous homecoming, reconnect, and purchased docked ships use the same assignment representation; explicit Undock and contextual Interact use the same @@ -3035,10 +3041,12 @@ Docking ownership follows the fossil's entity and `ActionGameManager` path: velocity, overwrite its direction during undock, or let invented generic circle radii make the authored center-distance rule unreachable. - Verification layer: operation tests cover every ordered rejection, bay cargo, - first-eligible selection, preserved pose/velocity/direction, exact receipt - reason, entity pass-through during home approach, and retained ship/pickup - contact collection; the live witness remains responsible for camera/effect - timing. + first-eligible selection, weapon disarm, docked fire-command rejection, + preserved pose/velocity/direction, exact receipt reason, entity pass-through + during home approach, and retained ship/pickup contact collection. Simulation + smoke proves both docked attacker and docked target subtraction despite stale + state and a forged pulse; the live witness remains responsible for + camera/effect timing. Docked refit ownership follows the fossil's `Entity.ItemFits`, `TryEquip`, and `TryUnequip` transaction: diff --git a/docs/original-game-migration-matrix.md b/docs/original-game-migration-matrix.md index 9c7a3cf76..d71f1eb16 100644 --- a/docs/original-game-migration-matrix.md +++ b/docs/original-game-migration-matrix.md @@ -27,7 +27,7 @@ validation proves contract shape, not wiring, exclusivity, lowering, or parity. | Weapons | ServerShared behaviors + Unity effects | daemon plus Ymir geometry/kinematics | action capability, weapon state, shot/damage receipts | effects/audio/HUD | instant and constant resource/timing lifecycles are daemon-owned; charged weapons accept one semantic request, spool without requiring a solution, hold at full charge, commit automatically when a solution appears, and perform deterministic once-per-second malfunction hazard checks after the authored safe hold interval with increasing persisted risk; generic Eve `weapon.state` exposes charge hold/risk and feedback exposes readiness, commit, refusal, and malfunction chronology; committed direct damage now enters the shared daemon armor-cell transaction | guided persistent payloads, visibility/wear, remaining impact-distribution parity, and Unity effect reconciliation | | Destruction/drops | hull death, 25% equipment rolls, unconditional cargo drops, 25-unit launch, 30-second pickups | daemon | destruction identity, death/drop events, typed pickups | provider-advertised destruction effect and pickups | owner-exists; wired; exclusive; projected: direct and deployable lethal damage commit one deterministic destruction transaction, clear live references, retain only a non-rendered identity tombstone, and emit exact pickups/events; the reserved client `DestroyEntity` command is rejected; Aetheria advertises its original big explosion as `effect.feedback.entity.destroyed`, lowered generically by EveUnity | equipment-destruction-before-hull parity and multiplayer reconnect chronology | | Tractor/scoop | analog tractor and physical timed pickups | daemon + Ymir | tractor power, pickup body and receipt | pickup world entity plus beam/interaction feedback | fossil 2/s power ramp and authored forward radius/traction/distance feed pickup bodies into the shared Ymir world; ship contact collects exactly once when capacity permits or applies the fossil 25-unit rejection kick; Aetheria maps pickup collision only against ship bodies, so stations and other world bodies cannot become cargo writers; 30s daemon lifetime; instant cargo teleport deleted; current-zone pickups occupy ordinary rows in the shared Eve entity SoA body with stable logical identity and provider-owned assets; `pilot.scoop` advertises a generic `button-hold.v1` scalar contract, the released client sends `1` on press and `0` on release through `SetTractorPower`, both receipts reconcile, and daemon power returns exactly to zero; the provider build removes the fossil's embedded tractor object from ship prefabs, and `beam.presentation` attaches the sole standalone effect to the SoA ship; released warm witnesses prove successful exactly-once Ymir collection and controlled-player `cargo-capacity` rejection with unchanged cargo | polish provider beam shape/attachment | -| Dock/undock | wormhole-first interact; first eligible bay; component prerequisites | daemon + Ymir placement | dock commands/context | camera/UI transition | daemon docking now preserves the fossil transaction: stable zone order selects the first entity with a real empty bay inside the fixed 25-unit XZ center radius; undock checks installed Cockpit, Thruster-or-AetherDrive, Reactor, then empty bay cargo in source order; rejection reasons survive committed command facts into generic Eve receipts; success removes parentage without moving, stopping, or rotating the ship. Ymir world entities retain gravity/query bodies but do not invent ship/station rigidbody collision response that would make the 25-unit rule unreachable; ship/pickup Begin contacts remain enabled. The live generic Unity witness also proves advertised actions, bay assignment, dock-parent SoA inclusion and sensor sharing, camera retargeting, controlled-subject hiding, movement suppression, and restoration on undock | reconnect, docked inventory/trade surfaces, and authored dock-camera blend/effect chronology | +| Dock/undock | wormhole-first interact; first eligible bay; component prerequisites | daemon + Ymir placement | dock commands/context | camera/UI transition | daemon docking now preserves the fossil transaction: stable zone order selects the first entity with a real empty bay inside the fixed 25-unit XZ center radius; undock checks installed Cockpit, Thruster-or-AetherDrive, Reactor, then empty bay cargo in source order; rejection reasons survive committed command facts into generic Eve receipts; success removes parentage without moving, stopping, or rotating the ship. Docking clears held-group and transient weapon state, docked actors reject later fire commands, and combat subtracts docked child identities from both attacker iteration and target lookup, so stale input, forged pulses, and turret controllers cannot fire through a bay. Ymir world entities retain gravity/query bodies but do not invent ship/station rigidbody collision response that would make the 25-unit rule unreachable; ship/pickup Begin contacts remain enabled. The live generic Unity witness also proves advertised actions, bay assignment, dock-parent SoA inclusion and sensor sharing, camera retargeting, controlled-subject hiding, movement suppression, and restoration on undock | reconnect, docked inventory/trade surfaces, and authored dock-camera blend/effect chronology | | Wormhole travel | `ActionGameManager.EnterWormhole` plus `Ship` enter/exit state | daemon fixed-step transition plus Ymir exclusion | current-entity transition state and feedback chronology | provider-selected generic transition lowering | command acceptance no longer moves an entity immediately; player interact, explicit travel, and agent routing derive the same canonical adjacent-zone wormhole and proximity gate, then persist four-second `entering`, authoritative transfer, four-second `exiting`, and one-frame `completed` phases. The daemon owns smootherstep XZ motion, the fossil 1000-unit visual-depth lever, deterministic 20-unit exit direction, 50-unit exit radius, target-adjacency discovery, and exactly-once start/transfer/completion events. Flight and every world-physics implementation receive no transitioning body; Ymir resumes on the tick after completion. Smoke serializes and rehydrates mid-entry and proves agents traverse multi-edge routes through the same command boundary | generic provider transition effect/camera lowering and live multi-zone pilot witness | | Inventory/equipment | `Entity.ItemFits`, `TryEquip`, `TryUnequip`, `EquippedCargoBay.ItemFits`/`TryStore`, inventory panels + ServerShared | daemon atomic inventory transactions | typed inventory/equipment state, commands, exact receipts | generic UI | generated cargo and docking bays now occupy their typed collections instead of masquerading as ordinary equipment; docked equip/reposition/store validates the complete destination on cloned state before committing either side, uses authored hull interior and hardpoint geometry, forces hardpoint rotation, rejects occupied cells and deployed ships, preserves exact item instance fields and weapon-group membership, routes bay categories with aligned content/assignment arrays, and refuses to unequip nonempty/occupied bays. Cargo transfer now uses the same plan-first rule with typed bay interiors, rotated item footprints, deterministic free-cell search, exact stack maxima, and no partial source/destination mutation on rejection; exact reasons reach generic Eve receipts | live generic refit controls, reconnect after accepted and rejected moves, commodity multi-stack chronology, and full fossil inventory feedback parity | | Trade | trade UI/economy | daemon | stock, quote, purchase/sale commands | generic UI | daemon derives station, stock row, catalog item, current price, quantity, credits, target capacity, and hull-vs-cargo result; purchases ignore client opinions about price and destination kind. Docked sales identify only the source stack and quantity: the daemon derives station, instance-sensitive value, payout, deterministic typed stock placement, and commits cargo/credits atomically; generic Eve advertises available buy and sell actions. The generic Unity live witness receives an authoritative purchase receipt while paused | live sale receipt witness, quote expiry, contested stock, and full trade surface parity |