Station kinds: tests pin the log text, a null faction, and one-hop stand-ins; kind strings default to null

This commit is contained in:
soul 2026-10-22 20:38:26 +02:00
commit 0a468f24a8
2 changed files with 33 additions and 3 deletions

View file

@ -13,10 +13,10 @@ using Newtonsoft.Json;
public class StationKindData
{
[CultName, JsonProperty("name"), Key(0)]
public string Name = "";
public string Name;
[JsonProperty("description"), Key(1)]
public string Description = "";
public string Description;
// A faction with no model of this kind builds the stand-in's hull and the station stays this kind. Ignored once the
// faction offers a model of this kind.
@ -76,7 +76,7 @@ public static class StationKinds
// any maker).
public static CultRecordRef<StationKindData> HullKindFor(CultCache catalog, Faction faction, CultRecordRef<StationKindData> kind)
{
if (!kind.IsSet() || faction == null) return kind;
if (!kind.IsSet()) return kind;
if (OfferedStationHulls(catalog, faction).Any(hull => hull.Kind.Key.Equals(kind.Key))) return kind;
var standIn = catalog.Get(kind)?.StandIns.FirstOrDefault(entry => catalog.Get(entry.Faction) == faction);
return standIn != null && standIn.Kind.IsSet() ? standIn.Kind : kind;

View file

@ -176,6 +176,29 @@ public sealed class StationKindTests : IDisposable
CultRecordRef<Faction> faction = cache.Upsert(new Faction { Name = "F", ShortName = "F" });
Mint(cache, "Lonely", kind => kind.StandIns.Add(new StationKindStandIn { Faction = faction, Kind = Kind("nowhere") }));
}));
// A stand-in whose kind stands in for another faction only is one hop for this faction: Open accepts it.
SeedAndReopen(cache =>
{
CultRecordRef<Faction> mine = cache.Upsert(new Faction { Name = "F", ShortName = "F" });
CultRecordRef<Faction> other = cache.Upsert(new Faction { Name = "G", ShortName = "G" });
var third = Mint(cache, "Third");
var second = Mint(cache, "Second", kind => kind.StandIns.Add(new StationKindStandIn { Faction = other, Kind = third }));
Mint(cache, "First", kind => kind.StandIns.Add(new StationKindStandIn { Faction = mine, Kind = second }));
}, out var accepted);
AetheriaStores.Open(accepted).Dispose();
// Any one of the stand-in kind's entries for the same faction makes a second hop.
Assert.Contains("one hop", OpenRefusal(cache =>
{
CultRecordRef<Faction> mine = cache.Upsert(new Faction { Name = "F", ShortName = "F" });
CultRecordRef<Faction> other = cache.Upsert(new Faction { Name = "G", ShortName = "G" });
var third = Mint(cache, "Third");
var second = Mint(cache, "Second", kind =>
{
kind.StandIns.Add(new StationKindStandIn { Faction = other, Kind = third });
kind.StandIns.Add(new StationKindStandIn { Faction = mine, Kind = third });
});
Mint(cache, "First", kind => kind.StandIns.Add(new StationKindStandIn { Faction = mine, Kind = second }));
}));
Assert.Contains("one hop", OpenRefusal(cache =>
{
CultRecordRef<Faction> faction = cache.Upsert(new Faction { Name = "F", ShortName = "F" });
@ -261,6 +284,13 @@ public sealed class StationKindTests : IDisposable
var kind = StationKinds.Choose(world.Cache, world.Lucent, new CultRecordKey("site"), logged.Add);
Assert.Equal(Kind("shipyard").Key, kind.Key);
Assert.Single(logged);
Assert.Contains(world.Lucent.Name, logged[0]);
var anonymous = new List<string>();
StationKinds.Choose(world.Cache, null, new CultRecordKey("site"), anonymous.Add);
Assert.Contains("This galaxy", Assert.Single(anonymous));
world.StandIn("mining", world.Au, "shipyard");
Assert.Equal(Kind("mining").Key, StationKinds.HullKindFor(world.Cache, null, Kind("mining")).Key);
Assert.False(StationKinds.HullKindFor(world.Cache, world.Au, default).IsSet());
var pack = world.Generator(world.Lucent).GenerateStationLoadout(kind);
Assert.NotNull(pack);