diff --git a/Assets/Scripts/ServerShared/Behaviors/Radiator.cs b/Assets/Scripts/ServerShared/Behaviors/Radiator.cs index d7a9a7c58..d09b5382a 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Radiator.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Radiator.cs @@ -90,8 +90,10 @@ public class Radiator : Behavior, IAlwaysUpdatedBehavior, IInitializableBehavior // plain Evaluate() read, so a PumpedHeat stat carrying a PowerSupply term already pumps less under a // partial grant -- waste heat below is unaffected by the curve, so a starved radiator falls behind and // the ship heats up, which is the reduced-performance failure the ruling asks for instead of the pump - // simply refusing to run. At true zero supply PumpedHeat itself resolves to 0 (pow(0, exponent) == 0), - // so "produces nothing" already falls out of the curve below without a special case here. + // simply refusing to run. F1 (docs/stats-and-power-cut.md, operator ruling 2026-09-19): PowerSupply is a + // multiplier PerformanceStat.Evaluate applies to the whole resolved value, not a term blended into the + // Min/Max interpolation, so at true zero supply PumpedHeat resolves to exactly 0 regardless of Min -- so + // "produces nothing" already falls out of Evaluate() without a special case here. var pumpedHeat = PumpedHeat * max(itemTemperature - _data.TemperatureFloor, 0); // Radiator temperature is below temperature floor, stop executing diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index 0d53c1020..53f4deb66 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -1371,9 +1371,11 @@ public class EquippedItem : IStatContext public float HeatFactor(float exponent) => pow(ThermalPerformance, ThermalExponent * exponent); public float DurabilityFactor(float exponent) => pow(DurabilityPerformance, DurabilityExponent * exponent); public float ConsumableProgressFactor(float exponent) => 1f; - // Cut 6 (docs/stats-and-power-cut.md): the brownout curve. A stat with a PowerSupply term degrades as this - // tick's grant falls below 1 and is exactly unchanged at full supply (pow(1, exponent) == 1 regardless of - // exponent) -- the operator's "a continuous consumer that degrades instead of stopping." PowerBus writes + // Cut 6 (docs/stats-and-power-cut.md), applied per F1 (operator ruling 2026-09-19): PerformanceStat.Evaluate + // multiplies this straight onto the resolved value rather than blending it into the Min/Max interpolation, so + // a stat with a PowerSupply term is exactly unchanged at full supply (pow(1, exponent) == 1 regardless of + // exponent) and exactly zero at zero supply (pow(0, exponent) == 0 for any exponent > 0), no matter what Min + // is -- "a continuous consumer that degrades instead of stopping" down to genuinely nothing. PowerBus writes // PowerSupply below; the resolver invalidates this source once per tick from the same write (PowerBus.cs // AllocateTiers), so this read is always this tick's own grant, never a stale one. public float PowerSupplyFactor(float exponent) => pow(PowerSupply, exponent); diff --git a/Assets/Scripts/ServerShared/ItemData.cs b/Assets/Scripts/ServerShared/ItemData.cs index 8f318d9d0..8dd1e79ae 100644 --- a/Assets/Scripts/ServerShared/ItemData.cs +++ b/Assets/Scripts/ServerShared/ItemData.cs @@ -587,9 +587,9 @@ public interface IStatContext // Progress through a consumable effect's duration, standing in for "condition" on a consumable the way heat // does for equipped gear. Only ConsumableItemEffect has one; every other context is the identity (1). float ConsumableProgressFactor(float exponent); - // Cut 6 (the power bus) wires this to a real brownout curve. Until then no catalog stat declares a - // PowerSupply term, and every context answers the identity so the enum member can exist now without a - // resolver to back it. + // Cut 6 (the power bus) wires this to the bus's grant ratio. F1 (docs/stats-and-power-cut.md, operator + // ruling 2026-09-19): this is not one of the terms blended into the Min/Max interpolation -- PerformanceStat + // applies it as a separate multiplier on the fully-resolved value, so zero supply always resolves to zero. float PowerSupplyFactor(float exponent); float ScaleModifier(PerformanceStat stat); float ConstantModifier(PerformanceStat stat); @@ -643,11 +643,28 @@ public class PerformanceStat // this cut, because pow(x, 0) == 1 regardless of x. Callers keep their own NaN handling: an unequipped read // throws with diagnostic detail, an equipped or consumable read falls back to Min. That disagreement is not // named as a defect, so it is not touched here. + // + // F1 (docs/stats-and-power-cut.md, operator ruling 2026-09-19): PowerSupply is not folded into the + // interpolation factor with every other source. Heat, Durability and Quality all describe "how worn/hot/well + // made is this part" -- a part that is still there, just less good at its job, so blending toward Min is + // right for them. Power is not a degradation of the part; it is whether the part is receiving anything to + // work with at all, so it multiplies the fully-interpolated, fully-modified value instead: a PowerSupply term + // still lives in this stat's own Terms list (it is still authored per stat, still censused, still refused on + // a request stat by ValidateNoPowerSupplyOnRequest below), it is just applied as a separate multiplier rather + // than contributing to `factor`. Consequences named in the ruling: PowerSupply == 0 makes the whole + // expression 0 regardless of Min (pow(0, exponent) == 0 for any exponent > 0), and a Min == Max stat still + // responds to a PowerSupply term because the multiplier no longer has to move a degenerate interpolation. public float Evaluate(IStatContext context) { var factor = 1f; + var powerMultiplier = 1f; foreach (var term in Terms) { + if (term.Source == StatSource.PowerSupply) + { + powerMultiplier *= context.PowerSupplyFactor(term.Exponent); + continue; + } factor *= term.Source switch { // F6 (docs/stats-and-power-cut.md Cut 2 Soul pass): nothing ever calls Resolver.InvalidateSource @@ -662,11 +679,10 @@ public class PerformanceStat StatSource.Heat => context.HeatFactor(term.Exponent), StatSource.Durability => context.DurabilityFactor(term.Exponent), StatSource.ConsumableProgress => context.ConsumableProgressFactor(term.Exponent), - StatSource.PowerSupply => context.PowerSupplyFactor(term.Exponent), _ => throw new ArgumentOutOfRangeException(nameof(term.Source), term.Source, $"Unknown StatSource on {Min}-{Max} stat") }; } - return lerp(Min, Max, factor) * context.ScaleModifier(this) + context.ConstantModifier(this); + return (lerp(Min, Max, factor) * context.ScaleModifier(this) + context.ConstantModifier(this)) * powerMultiplier; } } diff --git a/tests/Aetheria.Shared.Tests/PowerCurveTests.cs b/tests/Aetheria.Shared.Tests/PowerCurveTests.cs index 5141291a6..da67ff0e8 100644 --- a/tests/Aetheria.Shared.Tests/PowerCurveTests.cs +++ b/tests/Aetheria.Shared.Tests/PowerCurveTests.cs @@ -145,6 +145,48 @@ public sealed class PowerCurveTests : IDisposable Assert.Equal(100f, engine.Evaluate(curve), 3); } + // --- F1 (docs/stats-and-power-cut.md, operator ruling 2026-09-19): "power supply multiplies, it does not + // --- interpolate." Before this fix PowerSupply was one more term feeding PerformanceStat's Min/Max lerp, so + // --- zero supply bottomed out at Min, not 0 -- Soul measured a radiator still pumping 19-25% of full heat at + // --- zero power. Min here is 1000 (nonzero), so lerp(1000, 4000, pow(0, 2)) would read 1000 under the old + // --- code; the multiplier form must read exactly 0 regardless of Min. --- + [Fact] + public void APowerSupplyTermedStatWithNonzeroMinResolvesToExactlyZeroAtZeroSupply() + { + var curve = new PerformanceStat { Min = 1000, Max = 4000, Terms = { new StatTerm { Source = StatSource.PowerSupply, Exponent = 2 } } }; + using var cache = OpenCatalog(curve); + var ship = BuildShip(cache, reactorCharge: 0); // no generation, no stored charge -> demand of 100 is unmet + + ship.Update(1f); + + var engine = ship.Equipment.Single(e => e.Data.Name == "Engine"); + Assert.Equal(0f, engine.PowerSupply, 4); + Assert.Equal(0f, engine.Evaluate(curve), 3); // NOT 1000 (Min) -- the old lerp-based bug's exact number + } + + // --- The ruling's other named consequence: "a stat whose Min equals its Max still responds" -- three of Cut + // --- 7's eight authored terms were inert for exactly this reason, because lerp(x, x, anything) == x. The + // --- multiplier form has no interpolation to degenerate, so it must still move. --- + [Fact] + public void AMinEqualsMaxStatStillRespondsToItsPowerSupplyTerm() + { + var curve = new PerformanceStat { Min = 2500, Max = 2500, Terms = { new StatTerm { Source = StatSource.PowerSupply, Exponent = 1 } } }; + using var cacheStarved = OpenCatalog(curve); + var starved = BuildShip(cacheStarved, reactorCharge: 0); + starved.Update(1f); + var starvedEngine = starved.Equipment.Single(e => e.Data.Name == "Engine"); + + var curve2 = new PerformanceStat { Min = 2500, Max = 2500, Terms = { new StatTerm { Source = StatSource.PowerSupply, Exponent = 1 } } }; + using var cacheFed = OpenCatalog(curve2); + var fed = BuildShip(cacheFed, reactorCharge: 1000); + fed.Update(1f); + var fedEngine = fed.Equipment.Single(e => e.Data.Name == "Engine"); + + Assert.Equal(0f, starvedEngine.Evaluate(curve), 3); // was inert (always 2500) before this fix + Assert.Equal(2500f, fedEngine.Evaluate(curve2), 3); + Assert.NotEqual(fedEngine.Evaluate(curve2), starvedEngine.Evaluate(curve)); + } + // A small, deliberately fake context (StatResolverTests' own pattern) so the "no cost when undeclared" rule // is provable without any catalog, entity or item plumbing -- and so it can count exactly how many times the // resolver ever asked for the power-supply factor.