diff --git a/Assets/Scripts/ServerShared/EconomyChecks.cs b/Assets/Scripts/ServerShared/EconomyChecks.cs index 13b72d1c3..78b2d391d 100644 --- a/Assets/Scripts/ServerShared/EconomyChecks.cs +++ b/Assets/Scripts/ServerShared/EconomyChecks.cs @@ -294,8 +294,8 @@ public static class EconomyChecks .Select(weapon => weapon.AmmoType.Key.Value), StringComparer.Ordinal); // Every commodity has a source (a grounded chain, or a gate that sells it) and a sink (a recipe takes it or a role it fills, a role - // some design (offered, or made by a recipe) names, a weapon some offered design carries draws it, or a gate that buys it). A consumer good's sink is judged once needs - // tables exist. + // some design (offered, or made by a recipe) names, a weapon some offered design carries draws it, a habitation module of any + // design names it in its table, or a gate that buys it). A consumer good is judged as every good is: it has a sink only when a module table names it. public static List SourceSink(CultCache catalog) { var faults = new List(); @@ -304,6 +304,8 @@ public static class EconomyChecks var grounded = Depths(catalog, sells); var recipes = AllRecipes(catalog).ToList(); var used = new HashSet(recipes.SelectMany(p => p.Recipe.Inputs.Concat(p.Recipe.Upkeep)).Select(c => c.Commodity.Key.Value), StringComparer.Ordinal); + used.UnionWith(catalog.GetAll().Where(design => design.Behaviors != null).SelectMany(design => design.Behaviors.OfType()) + .SelectMany(habitation => habitation.Table).Where(row => row.Commodity.IsSet()).Select(row => row.Commodity.Key.Value)); var rolesNamed = DesignRoles(catalog); rolesNamed.UnionWith(recipes.SelectMany(p => Recipes.RoleInputsOf(catalog, p.Recipe)).Select(r => r.Name)); foreach (var (key, recipe) in recipes) @@ -313,7 +315,6 @@ public static class EconomyChecks var outputKey = recipe.Output.Key.Value; if (!grounded.TryGetValue(outputKey, out var depth) || depth == null) faults.Add(new EconomyFault(LSource, key, $"'{output.Name}' has no source: no chain of recipes reaches raw goods and no gate sells it.")); - if (Recipes.IsConsumerGood(catalog, recipe)) continue; if (!used.Contains(outputKey) && !recipe.Fills.Any(rolesNamed.Contains) && !drawn.Contains(outputKey) && !buys.Contains(outputKey)) faults.Add(new EconomyFault(LSource, key, $"'{output.Name}' has no sink: no recipe takes it or a role it fills, no design names a role it fills, no weapon draws it, no gate buys it.")); } diff --git a/tests/Aetheria.Shared.Tests/EconomyChecksTests.cs b/tests/Aetheria.Shared.Tests/EconomyChecksTests.cs index ae367846b..15ac1d044 100644 --- a/tests/Aetheria.Shared.Tests/EconomyChecksTests.cs +++ b/tests/Aetheria.Shared.Tests/EconomyChecksTests.cs @@ -229,11 +229,30 @@ public sealed class EconomyChecksTests } [Fact] - public void SourceSinkLeavesAConsumerGoodWithoutASink() + public void ModuleTableIsASink() { + // A consumer good is judged as every good is (ruling installed-gear-decides-what-a-station-buys): it has a sink only while + // some design's habitation table names it, offered or not. using var f = EconomyFixture.Healthy(); f.Good("kettle", roles: new[] { ("Plate", 1) }); - Assert.Empty(EconomyChecks.SourceSink(f.Cache)); + var key = new CultRecordKey("gear:quarters"); + var kettle = EconomyFixture.Item(EconomyFixture.Key("kettle")); + IEnumerable NoSink() => EconomyChecks.SourceSink(f.Cache).Where(x => x.Message.Contains("no sink")).Select(x => x.Record); + Assert.Equal(new[] { "recipe:commodity:kettle" }, NoSink()); + + f.Cache.Upsert(typeof(GearData), new GearData + { + Name = "Quarters", Hardpoint = HardpointType.Tool, Shape = new Shape(), Price = 1, + Behaviors = { new HabitationData { Capacity = 5, Table = { new HabitationRow { Commodity = kettle, PerOccupantHour = 1 } } } } + }, key); + Assert.Empty(NoSink()); + + f.Cache.Upsert(typeof(GearData), new GearData + { + Name = "Quarters", Hardpoint = HardpointType.Tool, Shape = new Shape(), Price = 1, + Behaviors = { new HabitationData { Capacity = 5 } } + }, key); + Assert.Equal(new[] { "recipe:commodity:kettle" }, NoSink()); } [Fact]