SourceSink: a habitation module's table is a sink, and a consumer good is judged as every good is (cut habitation-gear)
The consumer-good skip of the sink half is deleted; the test that pinned the skip becomes ModuleTableIsASink. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b4d4e94333
commit
40c335a200
2 changed files with 25 additions and 5 deletions
|
|
@ -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<EconomyFault> SourceSink(CultCache catalog)
|
||||
{
|
||||
var faults = new List<EconomyFault>();
|
||||
|
|
@ -304,6 +304,8 @@ public static class EconomyChecks
|
|||
var grounded = Depths(catalog, sells);
|
||||
var recipes = AllRecipes(catalog).ToList();
|
||||
var used = new HashSet<string>(recipes.SelectMany(p => p.Recipe.Inputs.Concat(p.Recipe.Upkeep)).Select(c => c.Commodity.Key.Value), StringComparer.Ordinal);
|
||||
used.UnionWith(catalog.GetAll<EquippableItemData>().Where(design => design.Behaviors != null).SelectMany(design => design.Behaviors.OfType<HabitationData>())
|
||||
.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."));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<string> 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]
|
||||
|
|
|
|||
Loading…
Reference in a new issue