Merge cut-scenarios-smoke (verdict cut-scenarios-smoke.s2)

Scenarios.cs Tests list: kept WeaponFeel, Pursuit and Crossing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-11 23:28:05 +02:00
commit b6262467f0
13 changed files with 356 additions and 38 deletions

View file

@ -29,7 +29,7 @@ public sealed partial class RunStartTests
var products = PiratesProducts();
Assert.Equal(8, products.Length);
var hulls = _cache.GetAll<HullData>().ToArray();
var hulls = LoadoutGenerator.SoldHulls(_cache);
foreach (var product in products)
{
var design = _cache.Get(product.Design) as EquippableItemData;

View file

@ -248,13 +248,14 @@ public sealed class RestoredHullsTests
}
// The dock intro dereferences the ship's VelocityLimit unguarded (ActionGameManager), so every ship hull the catalog
// ships carries exactly one, with a top speed that is a finite positive number. After the retirement
// sells carries exactly one, with a top speed that is a finite positive number. After the retirement
// (ruling retire-longinusx) the shipped ship hulls are the Longinus and the Djinni.
[Fact]
public void EveryShippedShipHullHasATopSpeed()
{
using var cache = OpenCatalog();
var ships = cache.GetAll<HullData>().Where(h => h.HullType == HullType.Ship).OrderBy(h => h.Name, StringComparer.Ordinal).ToArray();
var sold = cache.GetAll<FactionProductData>().Select(product => product.Design.Key).ToHashSet();
var ships = cache.GetAll<HullData>().Where(h => h.HullType == HullType.Ship && sold.Contains(cache.RefOf(h).Key)).OrderBy(h => h.Name, StringComparer.Ordinal).ToArray();
Assert.Equal(new[] { "Djinni", "Longinus" }, ships.Select(h => h.Name));
foreach (var hull in ships)
{

View file

@ -353,7 +353,7 @@ public sealed partial class RunStartTests : IDisposable
[Fact]
public void GenerationOffersExactlyTheSoldGearSomeHullCanFit()
{
var hulls = _cache.GetAll<HullData>().ToArray();
var hulls = LoadoutGenerator.SoldHulls(_cache);
var sold = _cache.GetAll<FactionProductData>().Where(p => p.Manufacturer.IsSet()).Select(p => p.Design.Key).ToHashSet();
var generator = PreludeGenerator();
var wrong = _cache.GetAll<EquippableItemData>()
@ -366,7 +366,7 @@ public sealed partial class RunStartTests : IDisposable
"the Autocannon fits the turret's 8-cell Ballistic hardpoint, so it is offered");
}
// Gear no hull can fit is never offered; authoring a hull whose hardpoint takes it makes it offered.
// Gear no sold hull can fit is never offered; a product selling a hull whose hardpoint takes it makes it offered.
[Fact]
public void GearNoHullCanFitIsOfferedOnlyOnceAHullTakesIt()
{
@ -378,10 +378,15 @@ public sealed partial class RunStartTests : IDisposable
foreach (var cell in shape.AllCoordinates) shape[cell] = true;
var hardpointShape = new Shape(8, 8);
foreach (var cell in hardpointShape.AllCoordinates) hardpointShape[cell] = true;
_cache.Upsert(new HullData
var bigMount = new HullData
{
Name = "Big Mount", HullType = HullType.Ship, Shape = shape, Durability = 100, Mass = 1000, Price = 1,
Hardpoints = { new HardpointData { Type = HardpointType.Ballistic, Position = int2(0, 0), Shape = hardpointShape } }
};
_cache.Upsert(bigMount);
_cache.Upsert(new FactionProductData
{
Name = "Big Mount", Design = new CultRecordRef<CraftedItemData>(_cache.RefOf(bigMount).Key), Manufacturer = _cache.RefOf(_protagonist)
});
Assert.True(Offered(generator, huge), "a hull whose hardpoint takes it gives it a home");
}
@ -439,17 +444,17 @@ public sealed partial class RunStartTests : IDisposable
Assert.True(disagreements.Count == 0, string.Join("; ", disagreements.Take(10)) + $" ({disagreements.Count} in all)");
}
// The sold hardpoint gear that no hull fits even loosely today, stated so that authoring a hull that takes one
// shows up here as a changed list.
// The sold hardpoint gear the generator gives no home today: the production rule (LoadoutGenerator.HasHome over the hulls a
// product sells). The Smoke Test Hull, which no product sells, gives ChargeBlast SG and ChargeBlast+- no home; authoring a
// sold hull that takes one shows up here as a changed list.
[Fact]
public void TheSoldHardpointGearWithNoHomeToday()
{
var hulls = _cache.GetAll<HullData>().ToArray();
var sold = _cache.GetAll<FactionProductData>().Select(product => product.Design.Key).ToHashSet();
var hulls = LoadoutGenerator.SoldHulls(_cache);
var homeless = _cache.GetAll<EquippableItemData>()
.Where(design => sold.Contains(_cache.RefOf(design).Key) && design.Price > 0)
.Where(design => design.HardpointType != HardpointType.Tool && design.HardpointType != HardpointType.Hull)
.Where(design => !hulls.Any(hull => hull.Hardpoints.Any(hardpoint => hardpoint.Takes(design))))
.Where(design => !LoadoutGenerator.HasHome(design, hulls))
.Select(design => design.Name).OrderBy(name => name, StringComparer.Ordinal).ToArray();
Assert.Equal(new[] { "CShot RainbowLite Lazer", "ChargeBlast SG", "ChargeBlast+-", "OK Disperser" }, homeless);
}

View file

@ -477,8 +477,8 @@ public sealed partial class RunStartTests
}
}
// Arcs' geometry: the bow hull sits inside every one of the player's mount arcs, the stern hull outside all of them,
// and the turret is hostile.
// Arcs' geometry: the bow hull sits inside every one of the player's forward mount arcs, the stern hull outside all of
// them (the side mounts are ArcsFlanks'), the turret is hostile and the bare hulls are neutral.
[Fact]
public void ArcsGeometry()
{
@ -489,7 +489,7 @@ public sealed partial class RunStartTests
var turret = Assert.IsType<OrbitalEntity>(staged.Entities[2]);
Assert.Equal((Arcs.Bow, Arcs.Stern, Arcs.Turret), (bow.Position.xz, stern.Position.xz, turret.Position.xz));
var mounts = player.Equipment.Where(item => item.Behaviors.OfType<Weapon>().Any()).ToList();
var mounts = player.Equipment.Where(item => item.Behaviors.OfType<Weapon>().Any() && item.EquippableItem.Rotation == ItemRotation.None).ToList();
Assert.NotEmpty(mounts);
foreach (var mount in mounts)
{
@ -497,7 +497,7 @@ public sealed partial class RunStartTests
Assert.False(FireControl.InArc(mount, stern.Position - player.Position), $"{mount.Data.Name} bears on the stern hull");
}
Assert.True(player.IsHostileTo(turret) && turret.IsHostileTo(player), "the turret is hostile");
Assert.False(player.IsHostileTo(bow) || player.IsHostileTo(stern), "the bare hulls are neutral");
Assert.False(player.IsHostileTo(bow) || player.IsHostileTo(stern) || player.IsHostileTo(staged.Entities[3]) || player.IsHostileTo(staged.Entities[4]), "the bare hulls are neutral");
}
// Q3 (operator, 2026-09-30): a design no product sells is a scenario test design and nothing else. A test design

View file

@ -0,0 +1,93 @@
using System;
using System.IO;
using System.Linq;
using GameCult.Caching;
using GameCult.Caching.MessagePack;
using Xunit;
// AetherDb's smoke-hull command (aetheria-release, cut scenarios-smoke), run on a scratch copy of the shipped catalog
// with the Smoke Test Hull removed from it.
public sealed class SmokeHullCommandTests : IDisposable
{
private const string HullName = "Smoke Test Hull";
private readonly string _root = Path.Combine(Path.GetTempPath(), "smoke-hull-command-" + Guid.NewGuid().ToString("N"));
private string CatalogPath => Path.Combine(_root, "GameData", "Aetheria.cc");
public SmokeHullCommandTests()
{
Directory.CreateDirectory(Path.Combine(_root, "GameData"));
Directory.CreateDirectory(Path.Combine(_root, "Assets", "Resources"));
var shipped = AetherDb.FindRoot();
File.Copy(Path.Combine(shipped, "GameData", "Aetheria.cc"), CatalogPath);
File.Copy(Path.Combine(shipped, "Assets", "Resources", "Settings.asset"), Path.Combine(_root, "Assets", "Resources", "Settings.asset"));
using var cache = new CultCache(TestCatalog.Registry());
cache.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes);
foreach (var hull in cache.GetAll<HullData>().Where(h => h.Name == HullName).ToArray()) Assert.True(cache.Remove(cache.RefOf(hull).Key));
cache.FlushAsync().Wait();
}
public void Dispose() => Directory.Delete(_root, true);
private (HullData[] Hulls, HullData Longinus, EquippableItemData[] Fitted, int Products) Read()
{
var db = AetherDb.Open(root: _root);
try
{
var hulls = db.Cache.GetAll<HullData>().Where(h => h.Name == HullName).ToArray();
var keys = hulls.Select(h => db.Cache.RefOf(h).Key).ToArray();
var products = db.Cache.GetAll<FactionProductData>().Count(p => keys.Any(k => p.Design.Key.Equals(k)));
var fitted = new[] { "ChargeBlast SG", "Autocannon" }
.Select(name => db.Cache.GetAll<EquippableItemData>().Single(d => d.Name == name)).ToArray();
return (hulls, db.Cache.GetAll<HullData>().Single(h => h.Name == "Longinus"), fitted, products);
}
finally { db.Cache.Dispose(); }
}
[Fact]
public void A_dry_run_writes_nothing_and_apply_lands_one_productless_hull_once()
{
var before = File.ReadAllBytes(CatalogPath);
Assert.Empty(Read().Hulls);
Assert.Equal(0, Program.SmokeHullCatalog(apply: false, root: _root));
Assert.Equal(before, File.ReadAllBytes(CatalogPath));
Assert.Empty(Read().Hulls);
Assert.Equal(0, Program.SmokeHullCatalog(apply: true, root: _root));
var landed = File.ReadAllBytes(CatalogPath);
Assert.NotEqual(before, landed);
var (hulls, longinus, fitted, products) = Read();
var hull = Assert.Single(hulls);
Assert.Equal(0, products);
// The Longinus's own hardpoints survive (moved over by the margin the flank blocks need), and four are added: each takes
// the gear the scenarios fit to it.
Assert.Equal(longinus.Hardpoints.Count + 4, hull.Hardpoints.Count);
var added = hull.Hardpoints.Skip(longinus.Hardpoints.Count).ToArray();
var (chargeBlast, autocannon) = (fitted[0], fitted[1]);
Assert.Equal(longinus.Hardpoints.Select(h => (h.Type, h.Position.x + 2, h.Position.y, h.Rotation)),
hull.Hardpoints.Take(longinus.Hardpoints.Count).Select(h => (h.Type, h.Position.x, h.Position.y, h.Rotation)));
Assert.Single(added, h => h.Type == HardpointType.Energy && h.Rotation == ItemRotation.None && h.Takes(chargeBlast));
Assert.Single(added, h => h.Type == HardpointType.Ballistic && h.Rotation == ItemRotation.None && h.Takes(autocannon));
Assert.Single(added, h => h.Type == HardpointType.Ballistic && h.Rotation == ItemRotation.Clockwise && h.Takes(autocannon));
Assert.Single(added, h => h.Type == HardpointType.Energy && h.Rotation == ItemRotation.CounterClockwise && h.Takes(chargeBlast));
// Each is a full 2x2 block with the default firing arc (0 uses the game setting; the side mounts bear by it, never wider)
// and the Longinus-class armour the command writes.
Assert.All(added, hardpoint =>
{
Assert.Equal((2, 2, 0f, 20f), (hardpoint.Shape.Width, hardpoint.Shape.Height, hardpoint.FiringArc, hardpoint.Armor));
Assert.Equal(4, hardpoint.Shape.Coordinates.Length);
});
foreach (var hardpoint in added)
foreach (var cell in hardpoint.Shape.Coordinates)
Assert.True(hull.Shape[hardpoint.Position + cell], "a new hardpoint lies outside the hull's cells");
// A second apply finds the hull authored and writes nothing; so does a dry run.
Assert.Equal(0, Program.SmokeHullCatalog(apply: true, root: _root));
Assert.Equal(landed, File.ReadAllBytes(CatalogPath));
Assert.Equal(0, Program.SmokeHullCatalog(apply: false, root: _root));
Assert.Equal(landed, File.ReadAllBytes(CatalogPath));
Assert.Single(Read().Hulls);
}
}

View file

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
// aetheria-release, cut scenarios-smoke: what the Smoke Test Hull scenarios stage, read from the staged run and the
// shipped catalog's hull.
public sealed partial class RunStartTests
{
private static bool Bears(EquippedItem mount, Entity player, Entity target) => FireControl.InArc(mount, target.Position - player.Position);
private static List<EquippedItem> WeaponMounts(Entity ship) =>
ship.Equipment.Where(item => item.Behaviors.OfType<Weapon>().Any()).ToList();
// Weapon Feel: the player flies the Smoke Test Hull with ChargeBlast SG on the 2x2 Energy hardpoint, Autocannon
// on the 2x2 Ballistic hardpoint and a burst weapon; the bare hull ahead lies in every mount's arc.
[Fact]
public void WeaponFeelConditions()
{
var staged = Stage(Arena(false), new WeaponFeel());
var player = staged.Player;
player.GenerateWeaponGroups();
Assert.Equal("Smoke Test Hull", _items.GetData(player.EquippedHull.EquippableItem).Name);
EquippedItem Mount(string design) => Assert.Single(WeaponMounts(player), item => _items.GetData(item.EquippableItem).Name == design);
var charge = Mount("ChargeBlast SG");
var autocannon = Mount("Autocannon");
Assert.Equal((HardpointType.Energy, 2, 2), (charge.Hardpoint.Type, charge.Hardpoint.Shape.Width, charge.Hardpoint.Shape.Height));
Assert.Equal((HardpointType.Ballistic, 2, 2), (autocannon.Hardpoint.Type, autocannon.Hardpoint.Shape.Width, autocannon.Hardpoint.Shape.Height));
var mounts = WeaponMounts(player);
Assert.Contains(mounts, item => ((WeaponItemData)_items.GetData(item.EquippableItem)).WeaponModifiers.HasFlag(WeaponModifiers.RapidFire));
foreach (var mount in mounts)
{
Assert.Contains(player.WeaponGroups, group => group.items.Contains(mount));
Assert.True(Bears(mount, player, Assert.Single(staged.Entities)), $"{_items.GetData(mount.EquippableItem).Name} cannot bear on the hull ahead");
}
}
// Arcs' flanks: each side mount bears on its own flank's hull and on nothing else, the forward mounts bear on the
// bow and on neither flank, and the two side mounts sit in different weapon groups.
[Fact]
public void ArcsFlanks()
{
var staged = Stage(Arena(false), new Arcs());
var player = staged.Player;
player.GenerateWeaponGroups();
var (bow, stern, port, starboard) = (staged.Entities[0], staged.Entities[1], staged.Entities[3], staged.Entities[4]);
// The flank hulls lie abeam from the player's facing, read from the staged positions: within 5 degrees of the
// perpendicular, starboard on the right of the facing and port on the left.
var facing = player.Direction;
var right = CultMath.math.float2(facing.y, -facing.x);
float Abeam(Entity flank, CultMath.float2 side) => CultMath.math.dot(CultMath.math.normalize(flank.Position.xz - player.Position.xz), side);
var abeam = CultMath.math.cos(CultMath.math.radians(5f));
Assert.True(Abeam(starboard, right) >= abeam, "the starboard hull is not abeam to starboard");
Assert.True(Abeam(port, -right) >= abeam, "the port hull is not abeam to port");
var mounts = WeaponMounts(player);
var forward = mounts.Where(item => item.EquippableItem.Rotation == ItemRotation.None).ToList();
var starboardMounts = mounts.Where(item => item.EquippableItem.Rotation == ItemRotation.Clockwise).ToList();
var portMounts = mounts.Where(item => item.EquippableItem.Rotation == ItemRotation.CounterClockwise).ToList();
Assert.NotEmpty(forward);
Assert.NotEmpty(starboardMounts);
Assert.NotEmpty(portMounts);
foreach (var mount in starboardMounts)
{
Assert.True(Bears(mount, player, starboard), "a starboard mount cannot bear on the starboard hull");
Assert.False(Bears(mount, player, port) || Bears(mount, player, bow) || Bears(mount, player, stern), "a starboard mount bears off its flank");
}
foreach (var mount in portMounts)
{
Assert.True(Bears(mount, player, port), "a port mount cannot bear on the port hull");
Assert.False(Bears(mount, player, starboard) || Bears(mount, player, bow) || Bears(mount, player, stern), "a port mount bears off its flank");
}
foreach (var mount in forward)
{
Assert.True(Bears(mount, player, bow), "a forward mount cannot bear on the bow hull");
Assert.False(Bears(mount, player, port) || Bears(mount, player, starboard), "a forward mount bears on a flank");
}
int GroupOf(EquippedItem mount) => Array.FindIndex(player.WeaponGroups, group => group.items.Contains(mount));
var starboardGroups = starboardMounts.Select(GroupOf).ToList();
var portGroups = portMounts.Select(GroupOf).ToList();
Assert.DoesNotContain(-1, starboardGroups.Concat(portGroups));
Assert.Empty(starboardGroups.Intersect(portGroups));
}
}