diff --git a/Assets/Scripts/Editor/ShieldPanelCut3Verify.cs b/Assets/Scripts/Editor/ShieldPanelCut3Verify.cs index aa6f4b151..31348b11d 100644 --- a/Assets/Scripts/Editor/ShieldPanelCut3Verify.cs +++ b/Assets/Scripts/Editor/ShieldPanelCut3Verify.cs @@ -130,7 +130,7 @@ namespace Aetheria.EditorTools static AbsorbEvent Absorb(Vector3 worldPos, Vector3 worldDir, float energy = 5f, DamageType type = DamageType.Kinetic) - => new AbsorbEvent(worldPos.ToCultMath(), worldDir.ToCultMath(), energy, type); + => new AbsorbEvent(worldPos.ToCultMath(), worldDir.ToCultMath(), energy, type, AbsorbLayer.Shield); // ============================================================== // D17/D20: a panel struck in its own spawn frame must absorb that hit, not swallow it. diff --git a/Assets/Scripts/ServerShared/CapabilityEvents.cs b/Assets/Scripts/ServerShared/CapabilityEvents.cs index 9e3c26635..8ee9edc55 100644 --- a/Assets/Scripts/ServerShared/CapabilityEvents.cs +++ b/Assets/Scripts/ServerShared/CapabilityEvents.cs @@ -7,30 +7,35 @@ using UniRx; using CultMath; // Capability event contract (docs/headless-playground-cut.md fork L, operator ruling 2026-09-17): -// pickup, impact absorption, melee blade and propulsion are separate item capabilities. Simulation -// (not yet built -- this file only stands up the wire shape) will own each capability's rules and -// emit these events; any number of presentations (the field shield today, later an IFS shatter -// plane or an advected particle field) subscribe to the event kinds they visualize and decide -// nothing about the rule. This file has no engine dependency: it compiles into the headless -// Aetheria.Shared build (see Aetheria.Shared.csproj) with no publisher wired up yet. +// pickup, impact absorption, melee blade and propulsion are separate item capabilities. Simulation owns +// each capability's rules and emits these events (FireControl publishes Absorb; the others are not yet +// built); any number of presentations (the field shield today, later an IFS shatter plane or an advected +// particle field) subscribe to the event kinds they visualize and decide nothing about the rule. This file +// has no engine dependency: it compiles into the headless Aetheria.Shared build (see Aetheria.Shared.csproj). -// One absorbed impact: a hit landing on the item's shield/armor capability. DamageType rides along -// so presenters can vary visuals per type; the damage-type mask itself belongs to the absorb -// capability's own data and is out of scope for this cut (operator, 2026-09-17) -- this struct only -// carries the hit's existing type through, unfiltered. +// Which layer of the receiver took an absorbed impact. +public enum AbsorbLayer { Shield, Hull } + +// One absorbed impact on a shield or a hull, published once per receiver by FireControl on that entity's +// Entity.Capabilities. Position is a world point on the receiver's sim pose at the tick the impact lands (a +// presenter draws it with DrawAhead.Carried); Direction is the way the impact travels. DamageType rides along +// so presenters can vary visuals per type; the damage-type mask itself belongs to the absorb capability's own +// data and is out of scope (operator, 2026-09-17) -- this struct only carries the hit's existing type through. public readonly struct AbsorbEvent { public readonly float3 Position; public readonly float3 Direction; public readonly float Magnitude; public readonly DamageType DamageType; + public readonly AbsorbLayer Layer; - public AbsorbEvent(float3 position, float3 direction, float magnitude, DamageType damageType) + public AbsorbEvent(float3 position, float3 direction, float magnitude, DamageType damageType, AbsorbLayer layer) { Position = position; Direction = direction; Magnitude = magnitude; DamageType = damageType; + Layer = layer; } } @@ -101,10 +106,10 @@ public readonly struct ThrustEvent } } -// Per-entity (or per-item) source of capability events. One instance is owned by whatever will -// eventually decide these rules; today the FieldShieldTest scene stands in for that owner. Follows -// the Subject-per-event-kind idiom already used on Entity (IncomingHit, HullDamage, etc): each -// event kind gets its own stream, and a subscriber to one kind never sees another. +// Per-entity source of capability events: one instance per Entity (Entity.Capabilities), published by +// FireControl for Absorb; the FieldShieldTest scene keeps its own instance. Follows the Subject-per-event-kind +// idiom already used on Entity (IncomingHit, HullDamage, etc): each event kind gets its own stream, and a +// subscriber to one kind never sees another. public class CapabilityEvents { private readonly Subject _absorb = new Subject(); diff --git a/Assets/Scripts/ServerShared/DrawAhead.cs b/Assets/Scripts/ServerShared/DrawAhead.cs index 13da8aae9..076a2ff2e 100644 --- a/Assets/Scripts/ServerShared/DrawAhead.cs +++ b/Assets/Scripts/ServerShared/DrawAhead.cs @@ -57,14 +57,22 @@ public static class DrawAhead return drawn + (end - drawn) * steer; } - // The impact cell's centre on the target's drawn pose: the cell at the sim pose, drawn ahead by the target's last - // step velocity and turned by its last step turn for lead seconds, as Position and Rotation draw the entity. + // The impact cell's centre on the target's drawn pose. public static float3 Impact(Entity target, int2 cell, float lead) + { + var world = target.ToWorldPoint((float2) cell); + return Carried(target, float3(world.x, target.Position.y, world.y), lead); + } + + // A world point on the target's sim pose, moved and turned with the target for lead seconds exactly as Position and + // Rotation draw the entity: the one owner of where a point on a hull is drawn, for the drawn round's end and for + // impact presenters. + public static float3 Carried(Entity target, float3 simPoint, float lead) { var at = Position(target, lead); - var offset = target.ToWorldPoint((float2) cell) - target.Position.xz; + var offset = float2(simPoint.x - target.Position.x, simPoint.z - target.Position.z); var turned = mul(offset, CultMath.float2x2.Rotate(Turn(target, lead))); - return float3(at.x + turned.x, at.y, at.z + turned.y); + return float3(at.x + turned.x, at.y + (simPoint.y - target.Position.y), at.z + turned.y); } // Whether the drawn flight is over by time: only a published miss ends by the clock. A hit or burst ends on ShotResolved. diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index b12eb6c7f..91607eadc 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -173,6 +173,8 @@ public abstract class Entity VisibilitySources.Values.Where(s => s.Channel == channel).Sum(s => s.Strength); public Subject IncomingHit = new Subject(); + // One per entity, created with it, never replaced: FireControl publishes each landed impact on it (Absorb). + public readonly CapabilityEvents Capabilities = new CapabilityEvents(); public Subject<(int2 pos, float damage)> ArmorDamage = new Subject<(int2, float)>(); public Subject<(EquippedItem item, float damage)> ItemDamage = new Subject<(EquippedItem, float)>(); // public Subject ItemOffline = new Subject(); diff --git a/Assets/Scripts/ServerShared/Feedback.cs b/Assets/Scripts/ServerShared/Feedback.cs new file mode 100644 index 000000000..218028052 --- /dev/null +++ b/Assets/Scripts/ServerShared/Feedback.cs @@ -0,0 +1,40 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +using CultMath; +using static CultMath.math; + +// What an impact presenter renders, derived once. Engine-free and never called by ServerShared: FireControl +// publishes the fact (AbsorbEvent), this derives how it reads, and every presenter (visual, audio, camera) renders +// the same cue instead of computing its own. +public readonly struct ImpactCue +{ + public readonly AbsorbLayer Layer; + public readonly float3 Position; + public readonly float3 Direction; + public readonly float Intensity; + public readonly float Shake; + + public ImpactCue(AbsorbLayer layer, float3 position, float3 direction, float intensity, float shake) + { + Layer = layer; + Position = position; + Direction = direction; + Intensity = intensity; + Shake = shake; + } +} + +public static class Feedback +{ + // Intensity is the hit's share of what the receiver's hull can take, scaled by the presenter and saturated to + // 0..1; a receiver with no hull to measure against reads 0. Shake follows intensity for the player's own ship + // only, scaled by the player's ScreenShake preference. + public static ImpactCue Cue(AbsorbEvent e, float receiverMaxDurability, bool receiverIsPlayer, float shakePreference, float intensityScale) + { + var intensity = receiverMaxDurability > 0f ? saturate(e.Magnitude / receiverMaxDurability * intensityScale) : 0f; + var shake = receiverIsPlayer ? intensity * saturate(shakePreference) : 0f; + return new ImpactCue(e.Layer, e.Position, e.Direction, intensity, shake); + } +} diff --git a/Assets/Scripts/ServerShared/Feedback.cs.meta b/Assets/Scripts/ServerShared/Feedback.cs.meta new file mode 100644 index 000000000..65f57c0d9 --- /dev/null +++ b/Assets/Scripts/ServerShared/Feedback.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 51efa531176e4871835ae88104c92c85 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/ServerShared/FireControl.cs b/Assets/Scripts/ServerShared/FireControl.cs index 261e1a4f3..4076e1fa7 100644 --- a/Assets/Scripts/ServerShared/FireControl.cs +++ b/Assets/Scripts/ServerShared/FireControl.cs @@ -1163,6 +1163,8 @@ public static class FireControl if (shot.Outcome.Shielded) { + Publish(shot.Target, AbsorbLayer.Shield, ImpactPoint(shot.Target, shot.Outcome.Cell), + float3(shot.TravelDirection.x, 0, shot.TravelDirection.y), shot.Damage, shot.DamageType); shot.Target.Shield.TakeHit(shot.DamageType, shot.Damage); return; } @@ -1206,9 +1208,31 @@ public static class FireControl for (var li = 0; li < laneCount; li++) ArrayPool.Shared.Return(buffers[li]); + Publish(target, AbsorbLayer.Hull, ImpactPoint(target, shot.Outcome.Cell), + float3(shot.TravelDirection.x, 0, shot.TravelDirection.y), shot.Damage, shot.DamageType); target.DamageHull(hullDamage); } + // Where a landed direct hit meets the receiver: the impact cell's world point on its sim pose, at its height. + private static float3 ImpactPoint(Entity target, int2 cell) + { + var world = target.ToWorldPoint((float2) cell); + return float3(world.x, target.Position.y, world.y); + } + + // The one publisher of an absorbed impact: once per receiver, on its Capabilities, before the damage it reports. + private static void Publish(Entity receiver, AbsorbLayer layer, float3 position, float3 direction, float magnitude, DamageType damageType) => + receiver.Capabilities.PublishAbsorb(new AbsorbEvent(position, direction, magnitude, damageType, layer)); + + // A blast's impact on one entity: at the blast point (on the entity's height), travelling from the blast out through + // the entity's centre, or zero when they coincide. + private static void PublishBlast(Entity entity, float2 blast, AbsorbLayer layer, float magnitude, DamageType damageType) + { + var away = entity.Position.xz - blast; + var direction = lengthsq(away) > 0f ? normalize(away) : float2.zero; + Publish(entity, layer, float3(blast.x, entity.Position.y, blast.y), float3(direction.x, 0, direction.y), magnitude, damageType); + } + // Cut 12.4(b) (docs/fire-control-cut.md, "Where P is"): a contact or delayed blast needs a committed hit -- // on a miss nothing happens, exactly like a direct hit's own gate. IncomingHit fires once, for the host, // before the blast is handed to Detonate (which then treats the host like any other entity in the radius: @@ -1591,6 +1615,7 @@ public static class FireControl { if (shield.CanTakeHit(damageType, totalShare)) { + PublishBlast(entity, worldPlanar, AbsorbLayer.Shield, totalShare, damageType); shield.TakeHit(damageType, totalShare); continue; } @@ -1620,6 +1645,7 @@ public static class FireControl for (var i = 0; i < amounts.Length; i++) hullTotal += amounts[i]; } + PublishBlast(entity, worldPlanar, AbsorbLayer.Hull, totalShare, damageType); entity.DamageHull(hullTotal); } } diff --git a/Assets/Scripts/ServerShared/PlayerSettings.cs b/Assets/Scripts/ServerShared/PlayerSettings.cs index 2566dcf59..f46bbad22 100644 --- a/Assets/Scripts/ServerShared/PlayerSettings.cs +++ b/Assets/Scripts/ServerShared/PlayerSettings.cs @@ -64,6 +64,8 @@ public class PlayerGraphicsSettings { [Key(0)] public Quality NebulaQuality = Quality.Normal; [Key(1)] public bool ShowAsteroidsInMinimap; + // How hard the camera shakes when the player's ship takes an impact: 0 off, 1 full (Feedback.Cue). + [Key(2)] public float ScreenShake = 1f; } [MessagePackObject] diff --git a/Assets/Scripts/UI/FieldTester.cs b/Assets/Scripts/UI/FieldTester.cs index 0e955e3f5..de18a33e5 100644 --- a/Assets/Scripts/UI/FieldTester.cs +++ b/Assets/Scripts/UI/FieldTester.cs @@ -73,7 +73,7 @@ public class FieldTester : MonoBehaviour { var damageType = DamageTypeCycle[_nextDamageTypeIndex]; _nextDamageTypeIndex = (_nextDamageTypeIndex + 1) % DamageTypeCycle.Length; - _capabilityEvents.PublishAbsorb(new AbsorbEvent(hit.point.ToCultMath(), ray.direction.ToCultMath(), TestField.TestMagnitude, damageType)); + _capabilityEvents.PublishAbsorb(new AbsorbEvent(hit.point.ToCultMath(), ray.direction.ToCultMath(), TestField.TestMagnitude, damageType, AbsorbLayer.Shield)); }; } diff --git a/tests/Aetheria.Shared.Tests/CapabilityEventsTests.cs b/tests/Aetheria.Shared.Tests/CapabilityEventsTests.cs index b89a07637..9876e7ad8 100644 --- a/tests/Aetheria.Shared.Tests/CapabilityEventsTests.cs +++ b/tests/Aetheria.Shared.Tests/CapabilityEventsTests.cs @@ -25,7 +25,7 @@ public sealed class CapabilityEventsTests events.Melee.Subscribe(meleed.Add); events.Thrust.Subscribe(thrust.Add); - var absorbEvent = new AbsorbEvent(float3(1, 2, 3), float3(0, 0, 1), 5f, DamageType.Corrosive); + var absorbEvent = new AbsorbEvent(float3(1, 2, 3), float3(0, 0, 1), 5f, DamageType.Corrosive, AbsorbLayer.Hull); var grabEvent = new GrabEvent(7, GrabPhase.Started, float3(1, 0, 0), 1.5f); var meleeEvent = new MeleeEvent(float3(0, 0, 1), 10f, 90f, 0.5f); var thrustEvent = new ThrustEvent(float2(1, 0), 0.5f, float2(0.2f, -0.2f));