diff --git a/.changeset/shields.md b/.changeset/shields.md new file mode 100644 index 000000000..1bc06d016 --- /dev/null +++ b/.changeset/shields.md @@ -0,0 +1,5 @@ +--- +default: patch +--- + +Shields are on sale: a light 1x1 and a heavy 2x2 projector fit the Djinni's and the Nakovalnya's shield mounts and every starter ship's, and the Zenith's fourth radiator mount takes radiators again. diff --git a/GameData/Aetheria.cc b/GameData/Aetheria.cc index d2984a5da..406e6ae3a 100644 --- a/GameData/Aetheria.cc +++ b/GameData/Aetheria.cc @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d5793d085bb41d856ff79aa579d4bd00a2d337da38b2e7e953cc5a7337710ac8 -size 274284 +oid sha256:b7700cc0cae37765a81fd56b756554b8918e088fab415357f599ed4d66ab08e6 +size 277403 diff --git a/tests/Aetheria.Shared.Tests/HardpointFitTests.cs b/tests/Aetheria.Shared.Tests/HardpointFitTests.cs index 272276482..89d6af350 100644 --- a/tests/Aetheria.Shared.Tests/HardpointFitTests.cs +++ b/tests/Aetheria.Shared.Tests/HardpointFitTests.cs @@ -6,6 +6,14 @@ using Xunit; // design some product sells. Program.UnfillableHardpoints is the one census, over HardpointData.Takes, the one fit rule. public sealed class HardpointFitTests { + // Every hardpoint on every hull the game boots (shipped catalog plus GameData/Mods) takes a design some product sells. + [Fact] + public void EveryHardpointTheGameBootsTakesASoldDesign() + { + using var cache = RestoredHullsTests.OpenCatalog(); + Assert.Empty(Program.UnfillableHardpoints(cache)); + } + // The census is over the catalog the game boots, packages included: a package hull's mount is as fillable as a shipped one. [Fact] public void TheCensusReadsThePackagesTheGameBoots() diff --git a/tests/Aetheria.Shared.Tests/ShieldCatalogTests.cs b/tests/Aetheria.Shared.Tests/ShieldCatalogTests.cs new file mode 100644 index 000000000..de33ec69f --- /dev/null +++ b/tests/Aetheria.Shared.Tests/ShieldCatalogTests.cs @@ -0,0 +1,51 @@ +using System.Linq; +using GameCult.Caching; +using Xunit; + +// The shields the catalog sells (campaign aetheria-release, cut hardpoint-fit-1; rulings hardpoint-sizes-are-footprint-palette, +// catalog-grows-generic-designs-branded-products): a light 1x1 and a heavy 2x2 projector, each with a product a maker offers, and +// the fit they give the mounts the game boots. Prices and stats are starting knobs, so none is pinned here. +public sealed class ShieldCatalogTests +{ + private static GearData Design(CultCache cache, string name) => Assert.Single(cache.GetAll(), g => g.Name == name); + + private static FactionProductData[] Offered(CultCache cache, GearData design) => + cache.GetAll().Where(p => p.Design.Key.Equals(cache.RefOf(design).Key) && !p.NotOffered).ToArray(); + + [Theory] + [InlineData(ShieldCatalog.Light, 1)] + [InlineData(ShieldCatalog.Heavy, 2)] + public void EachProjectorIsAShieldOfItsFootprintWithAnOfferedProduct(string name, int size) + { + using var cache = RestoredHullsTests.OpenCatalog(); + var design = Design(cache, name); + Assert.Equal(HardpointType.Shield, design.Hardpoint); + Assert.Equal((size, size), (design.Shape.Width, design.Shape.Height)); + Assert.Equal(size * size, design.Shape.Coordinates.Length); + var shield = Assert.Single(design.Behaviors.OfType()); + Assert.True(shield.Capacity.Min > 0f && shield.Capacity.Max > 0f, "a shield with no capacity breaks on its first hit"); + Assert.NotEmpty(Offered(cache, design)); + } + + [Fact] + public void MegiddoSellsTheHeavyProjector() + { + using var cache = RestoredHullsTests.OpenCatalog(); + Assert.Contains(Offered(cache, Design(cache, ShieldCatalog.Heavy)), p => cache.Get(p.Manufacturer).ShortName == "Megiddo"); + } + + // Loose fit: the light projector serves a 1x1 shield mount, the heavy one fills every 2x2 shield mount of the booted hulls. + [Fact] + public void TheProjectorsFitTheMountsTheGameBoots() + { + using var cache = RestoredHullsTests.OpenCatalogWithFixtures(); + var light = Design(cache, ShieldCatalog.Light); + var heavy = Design(cache, ShieldCatalog.Heavy); + var mounts = cache.GetAll().SelectMany(h => h.Hardpoints).Where(m => m.Type == HardpointType.Shield).ToArray(); + Assert.Contains(mounts, m => m.Shape.Coordinates.Length == 1); + Assert.Contains(mounts, m => m.Shape.Coordinates.Length == 4); + Assert.All(mounts, m => Assert.True(m.Takes(light) || m.Takes(heavy))); + Assert.All(mounts.Where(m => m.Shape.Coordinates.Length == 1), m => Assert.True(m.Takes(light) && !m.Takes(heavy))); + Assert.All(mounts.Where(m => m.Shape.Coordinates.Length == 4), m => Assert.True(m.IsFilledBy(heavy) && m.Takes(light))); + } +} diff --git a/tests/Aetheria.Shared.Tests/WrenPackageTests.cs b/tests/Aetheria.Shared.Tests/WrenPackageTests.cs index 3395d7f32..7313858d0 100644 --- a/tests/Aetheria.Shared.Tests/WrenPackageTests.cs +++ b/tests/Aetheria.Shared.Tests/WrenPackageTests.cs @@ -50,8 +50,7 @@ public sealed class WrenPackageTests using var cache = RestoredHullsTests.OpenCatalogWithFixtures(); var designs = cache.GetAll().ToArray(); var bare = Wren(cache).Hardpoints.Where(hardpoint => !designs.Any(hardpoint.Takes)).Select(hardpoint => $"{hardpoint.Transform} ({hardpoint.Type})").ToArray(); - // No shield design fits a 1x1 yet (hardpoint-fit lists Djinni's 4-cell shield with none either); every other mount does. - Assert.Equal(new[] { "internal.shield (Shield)" }, bare); + Assert.Empty(bare); } [Fact] diff --git a/tools/AetherDb/Program.cs b/tools/AetherDb/Program.cs index 8d6cadb81..fd75530ac 100644 --- a/tools/AetherDb/Program.cs +++ b/tools/AetherDb/Program.cs @@ -25,6 +25,14 @@ public static class Program case "census": return Census(); case "station-fit": return StationFit(); case "hardpoint-fit": return HardpointFit(); + case "shield-catalog": + { + var apply = args.Contains("apply"); + using var db = AetherDb.Open(catalogWritable: apply); + var code = ShieldCatalog.Run(db.Cache, apply, Console.Out); + if (apply) db.Cache.FlushAsync().GetAwaiter().GetResult(); + return code; + } case "hardpoint-rotation": return HardpointRotationCommand.Run(args.Skip(1).ToArray()); case "loadout": return Loadout(args.Skip(1).ToArray()); case "loadout-commit": return LoadoutCommitCommand.Run(args.Skip(1).ToArray()); @@ -82,7 +90,7 @@ public static class Program case "auto-guns": return AutoGunsCatalog.Run(AetherDb.Open(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out); case "doctrine-catalog": return DoctrineCatalog.Run(AetherDb.Open(catalogWritable: args.Contains("apply")).Cache, args.Contains("apply"), Console.Out); default: - Console.WriteLine("commands: census, factions, station-fit, hardpoint-fit, hardpoint-rotation \"\" , [apply], loadout [seed], loadout-commit [,,,[@]]... [--group ,...]... [--replace] [--boss-of ], save, settings, settings-dump, dangling [clear ]... [apply], shield-migrate [apply], brownout-migrate [apply], roles-migrate [apply], firing-arc-migrate [apply], range-falloff [apply] [--effective ] [--end ], targeting-catalog [apply], targeting-catalog-6c [apply], targeting-catalog-6d [apply], ship-authoring create|inspect|validate|compose, mine-launcher [apply], smoke-hull [apply], smoke-rounds [apply], roles-backfill [apply], pd-gear [apply], consumables-first-set [apply], launch-suppressor [apply], pirates-faction [apply], verse-grammar [apply], generic-designs [apply], sensor-stat-set [apply], inspection-scanner [apply], minor-power-factions [apply], place-names [apply], product-lines weapons|minor-powers|gear|tiers [apply], doctrine-catalog [apply], auto-guns [apply], assembly-from-maker [apply], station-kinds [hull \"\" ] [apply], economy report|prices|author ... [apply]|balance"); + Console.WriteLine("commands: census, factions, station-fit, hardpoint-fit, hardpoint-rotation \"\" , [apply], loadout [seed], loadout-commit [,,,[@]]... [--group ,...]... [--replace] [--boss-of ], save, settings, settings-dump, dangling [clear ]... [apply], shield-migrate [apply], brownout-migrate [apply], roles-migrate [apply], firing-arc-migrate [apply], range-falloff [apply] [--effective ] [--end ], targeting-catalog [apply], targeting-catalog-6c [apply], targeting-catalog-6d [apply], ship-authoring create|inspect|validate|compose, mine-launcher [apply], smoke-hull [apply], smoke-rounds [apply], roles-backfill [apply], pd-gear [apply], consumables-first-set [apply], launch-suppressor [apply], pirates-faction [apply], verse-grammar [apply], generic-designs [apply], sensor-stat-set [apply], inspection-scanner [apply], minor-power-factions [apply], place-names [apply], product-lines weapons|minor-powers|gear|tiers [apply], doctrine-catalog [apply], auto-guns [apply], assembly-from-maker [apply], shield-catalog [apply], station-kinds [hull \"\" ] [apply], economy report|prices|author ... [apply]|balance"); return 1; } } @@ -256,6 +264,15 @@ public static class Program ["Heat"] = "injector", ["EnergyUsage"] = "injector", }; + // A shield's emitter sets how much of a hit it turns, the reservoir how much it can take, the regulator how it spends + // and recovers energy. + private static readonly Dictionary ShieldRoles = new Dictionary + { + ["Efficiency"] = "emitter", + ["Capacity"] = "reservoir", + ["EnergyUsage"] = "regulator", ["RefillDuration"] = "regulator", ["RestoreDuration"] = "regulator", + }; + private static readonly Dictionary HullShipRoles = new Dictionary { ["CrossSection"] = "plating", @@ -315,6 +332,7 @@ public static class Program "Radiator" => RadiatorRoles, "Reactor" => ReactorRoles, "Sensors" => SensorRoles, + "Shield" => ShieldRoles, "Thruster" => ThrusterRoles, _ when kind == "Hull/Ship" => HullShipRoles, "Tool" => ToolRolesByDesign.TryGetValue(item.Name, out var byName) ? byName : null, diff --git a/tools/AetherDb/ShieldCatalog.cs b/tools/AetherDb/ShieldCatalog.cs new file mode 100644 index 000000000..f93f30ca7 --- /dev/null +++ b/tools/AetherDb/ShieldCatalog.cs @@ -0,0 +1,157 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using GameCult.Caching; + +// Puts shields on sale (campaign aetheria-release, cut hardpoint-fit-1; rulings catalog-grows-generic-designs-branded-products, +// designs-are-tech-nodes, hardpoint-sizes-are-footprint-palette, gear-ladder-wide-by-rare-inputs): two generic Shield designs, +// a Light Shield Projector (1x1) and a Heavy Shield Projector (2x2), each sold by two makers. Loose fit lets the light one +// serve the starter's 1x1 mount and the heavy one fill the Djinni's and the Nakovalnya's 2x2 mounts. Every stat is one linear +// Quality term on its ShieldRoles role (Min at quality 0, Max at quality 1); prices and stats are starting knobs, sim-tuned later. +// Recipes wait on aetheria-living-world:follow_up:design-bills-of-materials. Every record is keyed by its name, so the same +// apply replays byte-identically at a merge. Dry run unless apply; a catalog that is neither untouched nor fully authored is refused. +public static class ShieldCatalog +{ + public const string Light = "Light Shield Projector"; + public const string Heavy = "Heavy Shield Projector"; + private const string Emitter = "emitter", Reservoir = "reservoir", Regulator = "regulator"; + + private sealed record Design(string Name, string Description, int Size, float Mass, float Durability, int Price, + (float Min, float Max) Efficiency, (float Min, float Max) EnergyUsage, (float Min, float Max) Capacity, + (float Min, float Max) RefillDuration, (float Min, float Max) RestoreDuration); + + private static readonly Design[] Designs = + { + new(Light, "A compact emitter and reservoir that wraps a hull in a field it spends energy to hold. Small enough for any mount.", + 1, 120f, 100f, 3000, (.05f, .15f), (8f, 4f), (60f, 180f), (8f, 4f), (24f, 12f)), + new(Heavy, "A broad-aperture projector with a deep reservoir: it soaks heavy fire, and takes its time coming back when overwhelmed.", + 2, 420f, 250f, 34000, (.05f, .2f), (8f, 3f), (180f, 520f), (12f, 5f), (34f, 16f)), + }; + + private static readonly (string Name, string Design, string Maker, string Description)[] Products = + { + ("Umbrella", Light, "AU", "Shade for one hull: a small field, held steadily, and no one aboard has to think about it."), + ("Awning", Light, "Aya", "Draws out over the bow like cloth on a pole. It will not stop a siege and was never meant to."), + ("Migdal", Heavy, "Megiddo", "The tower the fleet stands behind. Megiddo sells it as a promise and builds it to keep one."), + ("Redoubt", Heavy, "Zhestokost", "A wall of field, thrown up crudely and sold cheaply to those who expect to be shot at."), + }; + + // A record's key is derived from its name: the same table lands the same records every time it is applied. + private static CultRecordKey KeyOf(string name) => + new(new Guid(SHA256.HashData(Encoding.UTF8.GetBytes("shield-catalog:" + name)).AsSpan(0, 16)).ToString("N")); + + private static PerformanceStat Rolled((float Min, float Max) range, string role) => new PerformanceStat + { + Min = range.Min, + Max = range.Max, + Terms = new List { new StatTerm { Source = StatSource.Quality, Exponent = 1f, Role = role } }, + }; + + private static GearData Build(Design row) + { + var design = new GearData + { + Name = row.Name, + Description = row.Description, + Hardpoint = HardpointType.Shield, + Mass = row.Mass, + Price = row.Price, + Durability = row.Durability, + Shape = new Shape(row.Size, row.Size), + // Thermal fields from content-batch-one 4a. + SpecificHeat = 2f, + Conductivity = 4f, + ThermalResilience = 8f, + MinimumTemperature = 173.15f, + MaximumTemperature = 573.15f, + OptimalTemperature = 258.15f, + PlateauWidth = 84f, + Roles = new[] { Emitter, Reservoir, Regulator }.Select(r => new ItemRole { Name = r }).ToList(), + Behaviors = new List + { + new ShieldData + { + Efficiency = Rolled(row.Efficiency, Emitter), + EnergyUsage = Rolled(row.EnergyUsage, Regulator), + Capacity = Rolled(row.Capacity, Reservoir), + RefillDuration = Rolled(row.RefillDuration, Regulator), + RestoreDuration = Rolled(row.RestoreDuration, Regulator), + }, + }, + }; + for (var x = 0; x < row.Size; x++) + for (var y = 0; y < row.Size; y++) + design.Shape.Cells[x, y] = true; + return design; + } + + public static int Run(CultCache cache, bool apply, TextWriter output) + { + Faction Maker(string shortName) => + cache.GetAll().FirstOrDefault(f => f.ShortName == shortName) ?? throw new InvalidOperationException($"No faction with short name \"{shortName}\"."); + foreach (var product in Products) Maker(product.Maker); + + // Authored when every design and product is present under its key; untouched when none is; anything between needs a human. + var keys = Designs.Select(d => KeyOf(d.Name)).Concat(Products.Select(p => KeyOf(p.Name))).ToArray(); + var held = cache.GetAll().Select(d => cache.RefOf(d).Key) + .Concat(cache.GetAll().Select(p => cache.RefOf(p).Key)).ToHashSet(); + var present = keys.Count(held.Contains); + var names = Designs.Select(d => d.Name).Concat(Products.Select(p => p.Name)).ToHashSet(); + var strangers = cache.GetAll().Select(d => d.Name).Concat(cache.GetAll().Select(p => p.Name)) + .Count(names.Contains); + if (present == keys.Length) + { + output.WriteLine("The shield designs are already authored; nothing to do."); + return 0; + } + if (present != 0 || strangers != 0) + throw new InvalidOperationException("The shield designs are partly authored, or their names belong to other items; the catalog needs a human."); + + var designs = Designs.Select(d => (Row: d, Gear: Build(d))).ToArray(); + output.WriteLine("New designs:"); + foreach (var (_, gear) in designs) + { + var data = gear.Behaviors.OfType().Single(); + output.WriteLine($" {gear.Name} {gear.Shape.Width}x{gear.Shape.Height} {gear.Hardpoint} mass {gear.Mass:0.##} price {gear.Price} durability {gear.Durability:0.##} roles [{string.Join(", ", gear.Roles.Select(r => r.Name))}]"); + foreach (var (label, stat) in new[] { ("Efficiency", data.Efficiency), ("EnergyUsage", data.EnergyUsage), ("Capacity", data.Capacity), ("RefillDuration", data.RefillDuration), ("RestoreDuration", data.RestoreDuration) }) + output.WriteLine($" {label} {stat.Min:0.##}-{stat.Max:0.##} ({stat.Terms.Single().Role})"); + } + output.WriteLine("\nNew products:"); + foreach (var (name, design, maker, description) in Products) + { + var (mean, dev) = Program.MakerProfiles[maker]; + output.WriteLine($" {design} -> \"{name}\" by {maker}, mean {mean:0.##} dev {dev:0.##}: {description}"); + } + if (!apply) + { + output.WriteLine($"\nDry run. Pass \"apply\" to author {Designs.Length} designs and {Products.Length} products."); + return 0; + } + + foreach (var (_, gear) in designs) CultRecordRefs.Validate(gear); + // The batch lands onto the file as it is, expecting every key it authors to be absent (ProductLinesCommand's contract). + if (!cache.Commit(batch => + { + foreach (var key in keys) batch.Expect(key, null); + foreach (var (row, gear) in designs) batch.Upsert(typeof(GearData), gear, KeyOf(row.Name)); + foreach (var (name, design, maker, description) in Products) + { + var (mean, dev) = Program.MakerProfiles[maker]; + batch.Upsert(typeof(FactionProductData), new FactionProductData + { + Name = name, + Description = description, + Design = new CultRecordRef(KeyOf(design)), + Manufacturer = cache.RefOf(Maker(maker)), + Roles = new[] { Emitter, Reservoir, Regulator }.Select(r => new ProductRole { Role = r, Mean = mean, StandardDeviation = dev }).ToList(), + }, KeyOf(name)); + } + })) + throw new InvalidOperationException("The catalog changed while the shields were being authored; nothing was written. Run it again."); + output.WriteLine($"\nAuthored {Designs.Length} designs and {Products.Length} products in Aetheria.cc"); + return 0; + } +}