From 4cdfa22fb02d60f03afbe67d6d1763ac4a8c700c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 19 Sep 2026 04:41:13 +0200 Subject: [PATCH] Cut 8: EquippedItem.ConditionRatio -- how healthy a behaviour actually is Operator ask (2026-09-19): thruster particles only reflected thrust intent, so a cooked or starved thruster looked identical to a healthy one. EquippedItem.ConditionRatio (Entity.cs) resolves a stat's actual value against what the same item, same lot, same modifiers would produce with Heat/Durability/PowerSupply pinned to their identity (NominalContext) -- quality and lot are not part of "perfect", so a cheap item still reads 1 at full health. The nominal side bypasses the resolver's cache (which is keyed only by (owner, stat) and would otherwise collide with the real cached value) with one direct Evaluate call, a handful of flops. Thruster.Condition and AetherDrive.Condition expose that ratio against each behaviour's own governing stat (Thrust, Torque) for presentation to read next. Co-Authored-By: Claude Opus 5 --- .../ServerShared/Behaviors/AetherDrive.cs | 5 +++ .../ServerShared/Behaviors/Thruster.cs | 8 +++- Assets/Scripts/ServerShared/Entity.cs | 40 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/ServerShared/Behaviors/AetherDrive.cs b/Assets/Scripts/ServerShared/Behaviors/AetherDrive.cs index 5baf95eb8..72da7b29c 100644 --- a/Assets/Scripts/ServerShared/Behaviors/AetherDrive.cs +++ b/Assets/Scripts/ServerShared/Behaviors/AetherDrive.cs @@ -73,6 +73,11 @@ public class AetherDrive : Behavior, IPowerConsumer public AetherDriveData DriveData => _data; + // Cut 8 (operator ask 2026-09-19): the equivalent quantity to Thruster.Condition -- Torque is the stat that + // actually governs this behaviour's rotor spin-up (PowerRequest/Execute above both read it), so it is what + // "broken" means for a drive. 1f for the item-less ConsumableItemEffect case, same reasoning as Thruster. + public float Condition => Item?.ConditionRatio(_data.Torque) ?? 1f; + public float3 Axis { get => _axis; diff --git a/Assets/Scripts/ServerShared/Behaviors/Thruster.cs b/Assets/Scripts/ServerShared/Behaviors/Thruster.cs index 7236ed5de..f88315ed3 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Thruster.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Thruster.cs @@ -49,9 +49,15 @@ public class Thruster : Behavior, IAnalogBehavior, IPowerConsumer } private ThrusterData _data; - + private float _input; + // Cut 8 (operator ask 2026-09-19): presentation's read of "how healthy does this thruster actually look" -- + // Thrust is the stat that governs this behaviour's real output, so it is the equivalent quantity to condition + // against. 1f for the ConsumableItemEffect constructor's item-less case; that path has no durability, heat or + // power-supply state to be broken by, so it always reads perfect. + public float Condition => Item?.ConditionRatio(_data.Thrust) ?? 1f; + public Thruster(ThrusterData data, EquippedItem item) : base(data, item) { _data = data; diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index 8a051bc67..0d53c1020 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -1390,6 +1390,46 @@ public class EquippedItem : IStatContext public float ScaleModifier(PerformanceStat stat) => Entity.Resolver.ScaleModifier(this, stat); public float ConstantModifier(PerformanceStat stat) => Entity.Resolver.ConstantModifier(this, stat); + // Cut 8 (operator ask 2026-09-19): "multiply [emission] by actual performance so a broken thruster emits a + // puny flame." One ratio per (item, stat): this item's actually-resolved value against what the same item, + // same lot, same quality, same modifier stack would produce with every degradable term at its identity -- + // full durability, optimal temperature, full power supply. Quality and lot are deliberately NOT part of + // "perfect": NominalContext forwards Lot/ScaleModifier/ConstantModifier unchanged and only pins Heat, + // Durability, PowerSupply and ConsumableProgress to 1, so a cheap item's honestly-lower ceiling still reads + // 1 at full health -- it is not reported as damaged for being cheap. + // + // Cost: Evaluate(stat) is the same resolver-cached read every other caller already pays for (ยง above), so it + // is a dictionary hit here unless something already invalidated it this tick. The nominal side cannot reuse + // that cache -- the resolver's cache key is (owner, stat) alone, and owner is `this`, so resolving a second, + // different context under the same key would clobber the real cached value -- so it calls stat.Evaluate + // directly against NominalContext, bypassing the cache entirely. That is one pass over the stat's own Terms + // list (Thrust/Torque declare at most three: Quality, Heat or Durability, PowerSupply), each a pow() and a + // multiply, i.e. a handful of flops with no allocation (NominalContext is a readonly struct). Cheap enough to + // call once per thruster per frame, which is all presentation (ShipInstance.Update) does with it. + // No epsilon guard on a zero/near-zero nominal: math.min/max (CultMath's own DXIL-lowering semantics, + // math.cs) resolve a NaN operand to the OTHER operand, not to NaN, so saturate(0f/0f) -- the one way nominal + // degenerates to exactly 0 (a stat authored with Max <= 0 and no ScaleModifier/ConstantModifier moving it off + // that) -- is a real, tested 0f (ConditionIsZeroNotNaNWhenTheNominalValueItselfDegeneratesToZero), not NaN. A + // manual guard here would duplicate that behaviour rather than add any. + public float ConditionRatio(PerformanceStat stat) => saturate(Evaluate(stat) / stat.Evaluate(new NominalContext(this))); + + // Perfect-conditions view of this same item for ConditionRatio above. Everything but the three degradable + // factors is forwarded to the real item so a modifier stack or a cheap lot's lower Quality term still shapes + // "perfect" the same way it shapes "actual" -- only Heat/Durability/PowerSupply/ConsumableProgress are + // pinned to their identity (1), since those are exactly the terms condition is supposed to measure. + private readonly struct NominalContext : IStatContext + { + private readonly EquippedItem _item; + public NominalContext(EquippedItem item) => _item = item; + public Lot Lot => _item.Lot; + public float HeatFactor(float exponent) => 1f; + public float DurabilityFactor(float exponent) => 1f; + public float ConsumableProgressFactor(float exponent) => 1f; + public float PowerSupplyFactor(float exponent) => 1f; + public float ScaleModifier(PerformanceStat stat) => _item.ScaleModifier(stat); + public float ConstantModifier(PerformanceStat stat) => _item.ConstantModifier(stat); + } + public void AddHeat(float heat, bool ignoreThermalMass = false) { foreach(var hullCoord in InsetShape.Coordinates)