diff --git a/Assets/Resources/Settings.asset b/Assets/Resources/Settings.asset index c3e8fb3a1..a899ee58b 100644 --- a/Assets/Resources/Settings.asset +++ b/Assets/Resources/Settings.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b004d902ecd9c1b98ff7e0b23215225cce987fd8572fb5f55c5f53fe08f6ccba -size 12530 +oid sha256:7d4f98ca0bfca9f5e43f00ee758cb7889b701e87b54eff2082b49439653464d6 +size 12439 diff --git a/Assets/Scripts/ServerShared/Agents/Agent.cs b/Assets/Scripts/ServerShared/Agents/Agent.cs index c906ce33b..238df3ce7 100644 --- a/Assets/Scripts/ServerShared/Agents/Agent.cs +++ b/Assets/Scripts/ServerShared/Agents/Agent.cs @@ -23,6 +23,9 @@ public class Agent private VelocityLimit _velocityLimit; public AgentTask Task { get; set; } + // Zone-scoped, from 1: the ordinal of this pilot's own dice, set by Zone.CreateAgent as it admits the pilot (0 for + // an agent built outside a zone's admission). + public uint Id { get; set; } public Ship Ship { get; } public ItemManager ItemManager { get; } public GameplaySettings Settings { get; } diff --git a/Assets/Scripts/ServerShared/Agents/Flight.cs b/Assets/Scripts/ServerShared/Agents/Flight.cs index b96250ad8..de3c8f0c0 100644 --- a/Assets/Scripts/ServerShared/Agents/Flight.cs +++ b/Assets/Scripts/ServerShared/Agents/Flight.cs @@ -25,7 +25,7 @@ public class Flight private class Member { public Agent Agent; - public PatrolOrbitsTask Patrol; + public AgentTask Baseline; } private readonly FactionDoctrine _doctrine; @@ -49,10 +49,11 @@ public class Flight public Phase PhaseOf(Entity track) => _tracks.TryGetValue(track, out var t) ? t.Phase : Phase.None; - public void Join(Agent agent, PatrolOrbitsTask circuit) + // The task a member holds when the flight has nothing to follow: its patrol circuit, or the task a scenario stated. + public void Join(Agent agent, AgentTask baseline) { - _members.Add(new Member { Agent = agent, Patrol = circuit }); - agent.Task = circuit; + _members.Add(new Member { Agent = agent, Baseline = baseline }); + agent.Task = baseline; } public void Leave(Agent agent) => _members.RemoveAll(m => m.Agent == agent); @@ -167,8 +168,8 @@ public class Flight if (!(member.Agent.Task is FollowTask current) || current.Anchor != anchor) member.Agent.Task = new FollowTask { Anchor = anchor, Standoff = Standoff(ship) }; } - else if (member.Agent.Task != member.Patrol) - member.Agent.Task = member.Patrol; + else if (member.Agent.Task != member.Baseline) + member.Agent.Task = member.Baseline; } private static void Aim(Ship ship, Entity target) diff --git a/Assets/Scripts/ServerShared/Agents/States/Combat.cs b/Assets/Scripts/ServerShared/Agents/States/Combat.cs index 8ed210567..499f631b0 100644 --- a/Assets/Scripts/ServerShared/Agents/States/Combat.cs +++ b/Assets/Scripts/ServerShared/Agents/States/Combat.cs @@ -173,7 +173,10 @@ public class CombatState : BaseState maxRange = weapon.Range; } - var offset = _agent.ItemManager.Random.NextFloat((maxRange - minRange) / DPS_SAMPLE_COUNT); + // The pilot's own dice, a pure function of the zone seed and its id: the same offset at every resample, and + // nothing that mints an item can move it. + var offset = SimulationDice.For(_agent.Ship.Zone.CombatSeed, SimulationDice.CombatSampleStream, _agent.Id) + .NextFloat((maxRange - minRange) / DPS_SAMPLE_COUNT); var optimumDPS = 0f; for (int i = 0; i < DPS_SAMPLE_COUNT; i++) { diff --git a/Assets/Scripts/ServerShared/Corporations.cs b/Assets/Scripts/ServerShared/Corporations.cs index c1e69fcca..2e18d7199 100644 --- a/Assets/Scripts/ServerShared/Corporations.cs +++ b/Assets/Scripts/ServerShared/Corporations.cs @@ -63,6 +63,13 @@ public class Faction // The faction's rules of engagement; null fights as FactionDoctrine.Default. [Inspectable, JsonProperty("doctrine"), Key(17)] public FactionDoctrine Doctrine; + + // The maker's final assembly: the distribution every lot of theirs draws its own quality from, and the hard ceiling on each + // of its roles (quality-lean-assembly-hard-ceiling). Null is not authored: a lot of theirs assembles at AssemblyDistribution's + // defaults. assembly-from-maker derives it once at the part mean plus a tolerance margin (quality-min-tolerance-binned-assembly); + // tune it in Studio after that. Key 16 is reserved for Relations and 18 for Livery. + [Inspectable, JsonProperty("assembly"), Key(19)] + public AssemblyDistribution Assembly; } [CultDocument("aetheria.namefile", "1"), Inspectable, MessagePackObject] diff --git a/Assets/Scripts/ServerShared/FactionProduct.cs b/Assets/Scripts/ServerShared/FactionProduct.cs index a0770304a..cdaed4f28 100644 --- a/Assets/Scripts/ServerShared/FactionProduct.cs +++ b/Assets/Scripts/ServerShared/FactionProduct.cs @@ -28,6 +28,11 @@ public class FactionProductData [Inspectable, JsonProperty("roles"), Key(5)] public List Roles = new List(); + + // This line's own final test (maker-design-tiers-allowed): a binned or premium line is a better assembly as well as better + // parts. Null assembles as its maker does. + [Inspectable, JsonProperty("assembly"), Key(6)] + public AssemblyDistribution Assembly; } // How good this product's part is in one of its design's roles: a pseudo-gaussian distribution whose mean is @@ -46,3 +51,15 @@ public class ProductRole [Inspectable, JsonProperty("standardDeviation"), Key(2)] public float StandardDeviation = .15f; } + +// How well a maker puts the thing together: the technology and quality control of final assembly. A lot's own quality is drawn +// from it, and it is the ceiling on every role the lot fills. Defaults are a middling maker. +[MessagePackObject, JsonObject(MemberSerialization.OptIn)] +public class AssemblyDistribution +{ + [Inspectable, JsonProperty("mean"), Key(0)] + public float Mean = .5f; + + [Inspectable, JsonProperty("standardDeviation"), Key(1)] + public float StandardDeviation = .15f; +} diff --git a/Assets/Scripts/ServerShared/ItemManager.cs b/Assets/Scripts/ServerShared/ItemManager.cs index 884179e4e..73e2c9592 100644 --- a/Assets/Scripts/ServerShared/ItemManager.cs +++ b/Assets/Scripts/ServerShared/ItemManager.cs @@ -117,31 +117,25 @@ public class ItemManager return (int) (GameplaySettings.QualityPriceModifier.Evaluate(GetLot(item).Quality) * data.Price); } - // The tier roll every mint applies, whether or not the lot fills roles. - public float RollQuality() - { - var quality = Random.NextFloat(); - var tier = GameplaySettings.Tiers[0]; - foreach (var t in GameplaySettings.Tiers) - { - if (t.Rarity > quality) - tier = t; - } + // Builds one of a manufacturer's branded products (quality-is-assembly-over-supply-chain): the unit's own quality is its + // final assembly, drawn from the product's assembly distribution, else its maker's, else AssemblyDistribution's defaults, + // and each of the design's roles is filled with a part whose quality is drawn from the product's distribution for it. + public int CreateLot(FactionProductData product) => Mint(product, null); - return tier.Quality; - } + // The same lot at a stated quality: the assembly and every role fill are that quality and nothing is drawn, so a staged + // fit does not ride the item stream (ScenarioStage.Fit). + public int CreateLot(FactionProductData product, float quality) => Mint(product, clamp(quality, .01f, 1)); - // Builds one of a manufacturer's branded products: the unit's own workmanship rolled as before, and each of - // the design's roles filled with a part whose quality is drawn from that manufacturer's distribution for it. - public int CreateLot(FactionProductData product) + private int Mint(FactionProductData product, float? stated) { var design = ItemData.Get(product.Design); + var assembly = product.Assembly ?? ItemData.Get(product.Manufacturer)?.Assembly ?? new AssemblyDistribution(); var lot = new Lot { Design = ItemData.RefOf(design), Origin = new Attributed { Faction = product.Manufacturer }, Product = ItemData.RefOf(product), - Quality = RollQuality(), + Quality = stated ?? clamp(Random.NextGaussian(assembly.Mean, assembly.StandardDeviation), .01f, 1), Roles = new List() }; if (design.Roles != null) @@ -151,7 +145,7 @@ public class ItemManager lot.Roles.Add(new RoleFill { Role = role.Name, - Quality = clamp(Random.NextGaussian(build.Mean, build.StandardDeviation), .01f, 1) + Quality = stated ?? clamp(Random.NextGaussian(build.Mean, build.StandardDeviation), .01f, 1) }); } diff --git a/Assets/Scripts/ServerShared/Loadout.cs b/Assets/Scripts/ServerShared/Loadout.cs index 7effbfe76..bf8a2ac47 100644 --- a/Assets/Scripts/ServerShared/Loadout.cs +++ b/Assets/Scripts/ServerShared/Loadout.cs @@ -108,18 +108,19 @@ public static class Loadouts // picks the entity: a ship hull builds a Ship, a turret hull an OrbitalEntity with no orbit, which stays where it is // put; a station hull is refused. The entity always gets exactly WeaponGroupCount groups; a loadout with fewer is // padded with empty groups. A failed materialization leaves any minted lots in the live ledger; they are not roots, - // so the next commit drops them. + // so the next commit drops them. A stated quality mints every lot of the fit at it, drawing nothing (a scenario states + // one for a fit its checks rest on). public static Entity Materialize(ItemManager itemManager, Zone liveZone, Loadout loadout, - Func choose, List failures) + Func choose, List failures, float? quality = null) { var cache = itemManager.ItemData; var reported = failures.Count; - var hullBuild = Resolve(itemManager, loadout.Hull, loadout.HullProduct, choose, "hull", failures); + var hullBuild = Resolve(itemManager, loadout.Hull, loadout.HullProduct, choose, "hull", failures, quality); var hullData = cache.Get(loadout.Hull); if (hullData is { HullType: HullType.Station }) failures.Add($"hull: {hullData.Name} is a station hull; a preset builds a ship or a turret"); - var slotBuilds = loadout.Slots.Select(slot => Resolve(itemManager, slot.Design, slot.Product, choose, Cell(slot), failures)).ToArray(); + var slotBuilds = loadout.Slots.Select(slot => Resolve(itemManager, slot.Design, slot.Product, choose, Cell(slot), failures, quality)).ToArray(); var groups = loadout.WeaponGroups ?? new int[0][]; var groupCount = itemManager.GameplaySettings.WeaponGroupCount; if (groups.Length > groupCount) failures.Add($"weapon groups: {groups.Length} groups, at most {groupCount}"); @@ -168,11 +169,11 @@ public static class Loadouts // How one design is built, or null with the failure listed; nothing is minted until the returned builder runs. A // pinned product is built as named, whatever choose says; it must be a product of the design. A design with no // product at all is outside the economy (docs/scenarios-cut.md, Q3: generation, stock and sale all go through - // products) and is built unbranded, with no maker, at UnbrandedQuality. Otherwise choose names the product, and + // products) and is built unbranded, with no maker, at UnbrandedQuality (a stated quality replaces it). Otherwise choose names the product, and // null (nothing available) or a product of another design is a failure. public static Func Resolve(ItemManager itemManager, CultRecordRef design, CultRecordRef product, Func choose, string where, - List failures) where T : CraftedItemData + List failures, float? quality = null) where T : CraftedItemData { var cache = itemManager.ItemData; var data = cache.Get(design); @@ -195,7 +196,7 @@ public static class Loadouts else { if (!cache.GetAll().Any(p => p.Design.Key.Equals(design.Key))) - return () => itemManager.CreateInstance(itemManager.CreateLot(data, default, UnbrandedQuality)); + return () => itemManager.CreateInstance(itemManager.CreateLot(data, default, quality ?? UnbrandedQuality)); made = choose(data); if (made == null) { @@ -209,7 +210,7 @@ public static class Loadouts failures.Add($"{where}: product {made.Name} is not a product of {data.Name}"); return null; } - return () => itemManager.CreateInstance(made); + return () => itemManager.CreateInstance(quality is { } q ? itemManager.CreateLot(made, q) : itemManager.CreateLot(made)); } private static string Cell(LoadoutSlot slot) => $"slot {slot.Position.x},{slot.Position.y}"; diff --git a/Assets/Scripts/ServerShared/Provenance.cs b/Assets/Scripts/ServerShared/Provenance.cs index 80e8e31f0..adf83c308 100644 --- a/Assets/Scripts/ServerShared/Provenance.cs +++ b/Assets/Scripts/ServerShared/Provenance.cs @@ -72,18 +72,20 @@ public class Lot // (console give, presets, extracted), which brand their maker only. [Key(4)] public CultRecordRef Product; - // The quality a stat reads for one of the design's roles. An unnamed role, a design without roles, and a lot - // minted before roles existed all fall back to the lot's own workmanship. + // The quality a stat reads for one of the design's roles: the part's, capped by the lot's own final assembly + // (quality-lean-assembly-hard-ceiling), so a part better than its assembly is worth the assembly. An unnamed role, a + // design without roles, and a lot minted before roles existed all fall back to the lot's own workmanship. public float QualityForRole(string role) { if (string.IsNullOrEmpty(role) || Roles == null) return Quality; foreach (var fill in Roles) - if (fill.Role == role) return fill.Quality; + if (fill.Role == role) return Math.Min(fill.Quality, Quality); return Quality; } } -// One filled slot: the design's role name and how good the part that went into it turned out to be. +// One filled slot: the design's role name and how good the part that went into it turned out to be. Stats read it through +// Lot.QualityForRole, capped by the lot's assembly; the raw value is kept for disassembly (named-components-after-demo). [MessagePackObject] public class RoleFill { diff --git a/Assets/Scripts/ServerShared/RunStart.cs b/Assets/Scripts/ServerShared/RunStart.cs index b330ad944..cce2ab977 100644 --- a/Assets/Scripts/ServerShared/RunStart.cs +++ b/Assets/Scripts/ServerShared/RunStart.cs @@ -53,7 +53,7 @@ public static class RunStart var hostile = placed.Stance == ScenarioStance.Hostile; placed.Entity.SetIff(player, hostile); player.SetIff(placed.Entity, hostile); - arena.Admit(placed.Entity, placed.Piloted); + arena.Admit(placed.Entity, placed.Piloted, placed.Task); } return new Staged { Player = player, Credits = stage.Credits, Entities = stage.Placed.Select(placed => placed.Entity).ToList() }; } diff --git a/Assets/Scripts/ServerShared/ScenarioStage.cs b/Assets/Scripts/ServerShared/ScenarioStage.cs index b32a4993c..c9531e60f 100644 --- a/Assets/Scripts/ServerShared/ScenarioStage.cs +++ b/Assets/Scripts/ServerShared/ScenarioStage.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using CultMath; +using GameCult.Caching; using static CultMath.math; using float2 = CultMath.float2; using float3 = CultMath.float3; @@ -48,11 +49,20 @@ public sealed class ScenarioStage public Entity Entity; public ScenarioStance Stance; public bool Piloted; + public AgentTask Task; } // A hull fitted slot by slot: each slot a design or a product, the hull cell it goes in, and its rotation. A name is // a design (open: the stage chooses its product) or a product (pinned: that brand). - public ScenarioFit Fit(string hull, params (string design, int2 cell, ItemRotation rotation)[] slots) + public ScenarioFit Fit(string hull, params (string design, int2 cell, ItemRotation rotation)[] slots) => + FitAt(hull, null, slots); + + // The same fit with every lot it mints (hull, slots, unbranded) at the stated quality, drawing nothing. A fit a scenario's + // checks rest on states its quality, so the check does not ride the item stream. + public ScenarioFit Fit(string hull, float quality, params (string design, int2 cell, ItemRotation rotation)[] slots) => + FitAt(hull, quality, slots); + + private ScenarioFit FitAt(string hull, float? quality, (string design, int2 cell, ItemRotation rotation)[] slots) { var where = $"fit {hull}"; var (hullData, hullProduct) = NamedOrProduct(hull, where); @@ -69,7 +79,7 @@ public sealed class ScenarioStage Product = product == null ? default : _items.ItemData.RefOf(product) }); } - return hullData != null && loadout.Slots.Count == slots.Length ? new ScenarioFit(loadout) : null; + return hullData != null && loadout.Slots.Count == slots.Length ? new ScenarioFit(loadout, quality) : null; } // A hull with nothing fitted. @@ -126,6 +136,18 @@ public sealed class ScenarioStage return entity; } + // The task a piloted entity starts on: it closes on the target and holds there (the flight's follow task, standoff + // nothing), in place of the patrol circuit the zone would draw for it. A check that rests on where a pilot goes states + // it here, so the pilot's course is the scenario's and not a draw. An entity that is not placed and piloted, or a + // target that is not placed, is a failure. + public void Approach(Entity entity, Entity target) + { + var placement = _placed.FirstOrDefault(p => ReferenceEquals(p.Entity, entity)); + if (placement == null || !placement.Piloted) { _failures.Add($"approach: {entity?.Name ?? "no entity"} is not a placed, piloted ship"); return; } + if (target == null) { _failures.Add("approach: no target to close on"); return; } + placement.Task = new FollowTask { Anchor = target, Standoff = 0f }; + } + // Items in the entity's first cargo bay, one per name. A name is an equippable or consumable design (open: the stage // chooses its product) or a product of one (pinned); a name that is neither is a failure. public void Cargo(Entity entity, params string[] names) @@ -154,7 +176,7 @@ public sealed class ScenarioStage else { var failures = new List(); - entity = Loadouts.Materialize(_items, Arena, fit.Loadout, _choose, failures); + entity = Loadouts.Materialize(_items, Arena, fit.Loadout, _choose, failures, fit.Quality); _failures.AddRange(failures.Select(failure => $"{where} ({fit.Loadout.Name}): {failure}")); if (entity == null) return null; } @@ -190,7 +212,13 @@ public sealed class ScenarioFit { internal readonly Loadout Loadout; internal readonly EntityPack Pack; + internal readonly float? Quality; + + internal ScenarioFit(Loadout loadout, float? quality = null) + { + Loadout = loadout; + Quality = quality; + } - internal ScenarioFit(Loadout loadout) => Loadout = loadout; internal ScenarioFit(EntityPack pack) => Pack = pack; } diff --git a/Assets/Scripts/ServerShared/Scenarios/Crossing.cs b/Assets/Scripts/ServerShared/Scenarios/Crossing.cs index c90859439..053de4f98 100644 --- a/Assets/Scripts/ServerShared/Scenarios/Crossing.cs +++ b/Assets/Scripts/ServerShared/Scenarios/Crossing.cs @@ -22,14 +22,19 @@ public sealed class Crossing : Scenario // The waiting Djinni sits inside the Lightning Projector's arc at 80% of its Range. public static readonly CultMath.float2 Origin = float2(724, 124); public static readonly CultMath.float2 CrosserAt = Origin + float2(-128, 45), CrosserFacing = float2(1, 0), CrosserVelocity = float2(50, 0); - public const float ProjectorRange = 1216f; // the Lightning Projector's Range in metres, 1216.4 as the fit stands settled at rest + // The fighter is staged at this quality, so its gear and the range below do not ride the item stream. + public const float StagedQuality = .6f; + // The Lightning Projector's Range in metres at the staged fit: 996.99 after the three seconds the test settles for + // (EvSettle); it falls toward 864 m as the projector heats. The fit as it stood at 0f5def17 (unstaged, its draws on the + // item stream) measured 1216.4. + public const float ProjectorRange = 997f; public static readonly CultMath.float2 Waiting = Origin + float2(0, ProjectorRange * .8f); public override Galaxy Generate(GalaxyStage stage) => stage.Prelude(DemoTerminus.Cast); public override void Stage(ScenarioStage stage) { - var fighter = stage.Fit("Longinus", + var fighter = stage.Fit("Longinus", StagedQuality, ("Cockpit 2x2", int2(2, 6), None), ("Large Drive", int2(1, 0), Reversed), ("Large Drive", int2(3, 0), Reversed), diff --git a/Assets/Scripts/ServerShared/Scenarios/FusedRounds.cs b/Assets/Scripts/ServerShared/Scenarios/FusedRounds.cs index db2e18b65..b2d70c98e 100644 --- a/Assets/Scripts/ServerShared/Scenarios/FusedRounds.cs +++ b/Assets/Scripts/ServerShared/Scenarios/FusedRounds.cs @@ -22,11 +22,14 @@ public sealed class FusedRounds : Scenario public static readonly CultMath.float2 Mid = float2(-200, 600), Ahead = float2(0, 300), Fragile = float2(80, 240), Close = float2(6.4f, 4f), Stern = float2(0, -400); + // The shooter is staged at this quality, so the damage its Cluster Cannon deals does not ride the item stream. + public const float StagedQuality = .6f; + public override Galaxy Generate(GalaxyStage stage) => stage.Prelude(DemoTerminus.Cast); public override void Stage(ScenarioStage stage) { - var shooter = stage.Fit("Smoke Test Hull", + var shooter = stage.Fit("Smoke Test Hull", StagedQuality, ("Cockpit 2x2", int2(4, 6), None), ("Large Drive", int2(3, 0), Reversed), ("Large Drive", int2(5, 0), Reversed), diff --git a/Assets/Scripts/ServerShared/Scenarios/LockOn.cs b/Assets/Scripts/ServerShared/Scenarios/LockOn.cs index 87fc14103..171b34688 100644 --- a/Assets/Scripts/ServerShared/Scenarios/LockOn.cs +++ b/Assets/Scripts/ServerShared/Scenarios/LockOn.cs @@ -12,17 +12,33 @@ public sealed class LockOn : Scenario // The hostile starts about 4000 m off, ahead and to port of the player, facing the player. At that range its passive // sensors hold no track of the player (the test asks the sim's own PassiveInfo against the detection threshold). The - // hostile closes, sees the player some fourteen seconds in and locks. Its flanking approach and the zone's pull carry it - // off the staged line (about 5 degrees by the lock on the merged tree), and the warning must point at where the hostile - // is at the lock, which the test checks against the live bearing. At Duel's 900 m (and at 600 m) it sees and locks - // within a second. + // hostile is ordered to close on the player, finds it and locks. The zone's pull carries it off the staged line, so the + // warning must point at where the hostile was when the paint was stamped, which the test checks against the poses of + // that tick. At Duel's 900 m (and at 600 m) it sees and locks within a second. public static readonly CultMath.float2 HostileAt = float2(-2000, 3450); + // The fit's lots are minted at this quality, the one Crossing and the other RunStart scenarios stage (the brief states no + // other), and the hostile's order is to close on the player, so the lock follows from the staged situation and not + // from item draws or the pilot's drawn circuit (ruling scenario-stages-hostile-task). + const float StagedQuality = .6f; + + private readonly CultMath.float2 _hostileAt; + private readonly float _quality; + + public LockOn() : this(HostileAt, StagedQuality) { } + + // The staged inputs, open to a test that moves each a little and asks that the scenario still hold. + internal LockOn(CultMath.float2 hostileAt, float quality) + { + _hostileAt = hostileAt; + _quality = quality; + } + public override Galaxy Generate(GalaxyStage stage) => stage.Prelude(DemoTerminus.Cast); public override void Stage(ScenarioStage stage) { - var fighter = stage.Fit("Longinus", + var fighter = stage.Fit("Longinus", _quality, ("Cockpit 2x2", int2(2, 6), None), ("Large Drive", int2(1, 0), Reversed), ("Large Drive", int2(3, 0), Reversed), @@ -40,7 +56,8 @@ public sealed class LockOn : Scenario ("Panopticon Prime", int2(1, 6), Clockwise), // Fire Control Array ("Store-All Plus", int2(2, 8), None)); // Cargo Bay - stage.Player(fighter, float2(0, 0), facing: float2(0, 1)); - stage.Place(fighter, HostileAt, facing: normalize(-HostileAt), stance: ScenarioStance.Hostile, piloted: true); + var player = stage.Player(fighter, float2(0, 0), facing: float2(0, 1)); + var hostile = stage.Place(fighter, _hostileAt, facing: normalize(-_hostileAt), stance: ScenarioStance.Hostile, piloted: true); + stage.Approach(hostile, player); } } diff --git a/Assets/Scripts/ServerShared/Settings.cs b/Assets/Scripts/ServerShared/Settings.cs index 00db76c68..b58f223d5 100644 --- a/Assets/Scripts/ServerShared/Settings.cs +++ b/Assets/Scripts/ServerShared/Settings.cs @@ -305,5 +305,4 @@ public class RarityTier public string Name; public float Quality; public float3 Color; - public float Rarity; } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/SimulationDice.cs b/Assets/Scripts/ServerShared/SimulationDice.cs index 94d8f8946..ce646d670 100644 --- a/Assets/Scripts/ServerShared/SimulationDice.cs +++ b/Assets/Scripts/ServerShared/SimulationDice.cs @@ -10,6 +10,10 @@ public static class SimulationDice { public const uint LootStream = 1; public const uint MineStream = 2; + // A pilot's own decisions, ordinal Agent.Id: its preferred engagement range and its patrol circuit. AI behaviour + // never rides ItemManager.Random, so minting items cannot change how a pilot fights. + public const uint CombatSampleStream = 3; + public const uint PatrolStream = 4; // 9.1 (docs/fire-control-cut.md): fmix32, MurmurHash3's 32-bit finalizer -- xor-shift, multiply, // xor-shift, multiply, xor-shift. Diffuses a structured seed (a zone seed XORed with a small, diff --git a/Assets/Scripts/ServerShared/Zone.cs b/Assets/Scripts/ServerShared/Zone.cs index bb8e9adfe..4db63be46 100644 --- a/Assets/Scripts/ServerShared/Zone.cs +++ b/Assets/Scripts/ServerShared/Zone.cs @@ -133,6 +133,10 @@ public class Zone // The death ordinal of the loot dice: the nth death in this zone rolls on SimulationDice.For(CombatSeed, LootStream, n). private uint _deaths; + // The zone-scoped agent ordinal, from 1, never reused: the key of a pilot's own dice. + private uint _lastAgentId; + public uint NextAgentId() => ++_lastAgentId; + // One death subscription per member entity: Admit creates it together with the membership, Remove disposes it // together with the membership, and nothing else touches either. private readonly Dictionary _deathWatches = new Dictionary(); @@ -275,13 +279,14 @@ public class Zone // turret all join through here. A piloted entity gets the zone's Minion; an unpiloted one gets no agent at all. // Only a ship can be piloted. The death watch is installed here, for every join, whichever caller admits it. // An entity that is already a member is refused: it would hold a second watch and a second agent. - public void Admit(Entity entity, bool piloted) + // A piloted entity starts on the zone's drawn patrol circuit unless the caller states its task (a scenario's approach). + public void Admit(Entity entity, bool piloted, AgentTask task = null) { if (_entities.Contains(entity)) throw new InvalidOperationException("entity: already a member of this zone"); _entities.Add(entity); _deathWatches.Add(entity, entity.Death.Subscribe(_ => { DropLoot(entity); Remove(entity); entity.Deactivate(); })); entity.Activate(); - if (piloted) Agents.Add(CreateAgent((Ship) entity)); + if (piloted) Agents.Add(CreateAgent((Ship) entity, task)); } // The one removal from this zone (death, dock, jump): membership and its death watch leave together. False, and @@ -296,18 +301,23 @@ public class Zone return true; } - private Agent CreateAgent(Ship ship) + private Agent CreateAgent(Ship ship, AgentTask stated) { var key = ship.Faction ?? Unaffiliated; if (!_flights.TryGetValue(key, out var flight)) _flights[key] = flight = new Flight(ship.Faction?.Doctrine, _itemManager.GameplaySettings); - var agent = new Minion(ship, flight.Combatant); - var task = new PatrolOrbitsTask(); - task.Circuit = Orbits.OrderBy(_ => _itemManager.Random.NextFloat()).Take(4).Select(x => x.Key).ToArray(); - flight.Join(agent, task); + var id = NextAgentId(); + var agent = new Minion(ship, flight.Combatant) { Id = id }; + flight.Join(agent, stated ?? PatrolCircuit(id)); return agent; } + private PatrolOrbitsTask PatrolCircuit(uint id) + { + var dice = SimulationDice.For(CombatSeed, SimulationDice.PatrolStream, id); + return new PatrolOrbitsTask { Circuit = Orbits.OrderBy(_ => dice.NextFloat()).Take(4).Select(x => x.Key).ToArray() }; + } + public ZonePack PackZone() { return new ZonePack diff --git a/GameData/Aetheria.cc b/GameData/Aetheria.cc index a53215eec..f0b68fb9e 100644 --- a/GameData/Aetheria.cc +++ b/GameData/Aetheria.cc @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a4ff0effc5b80bbd4edea4c9f3855555d622e6939edfb720d08c4603b61ebee9 -size 12760370 +oid sha256:2b18ff7f115236eda17252a4a3b01bd2490e684b1722f375b0750e3a70a958d4 +size 12761080 diff --git a/tests/Aetheria.Shared.Tests/AssemblyFromMakerCatalogTests.cs b/tests/Aetheria.Shared.Tests/AssemblyFromMakerCatalogTests.cs new file mode 100644 index 000000000..52746c225 --- /dev/null +++ b/tests/Aetheria.Shared.Tests/AssemblyFromMakerCatalogTests.cs @@ -0,0 +1,36 @@ +using System; +using System.Linq; +using System.Reflection; +using MessagePack; +using Xunit; + +// The shipped catalog carries each maker's seeded assembly, and the Faction format pins its wire positions +// (aetheria-release, cut assembly-from-maker). +public sealed class AssemblyFromMakerCatalogTests +{ + // Every maker of a roled product carries an Assembly the command seeded; no product overrides its maker's. + [Fact] + public void ShippedCatalogCarriesAssembly() + { + using var cache = RestoredHullsTests.OpenCatalog(); + var makers = cache.GetAll().Where(p => p.Roles.Count > 0).Select(p => p.Manufacturer.Key).Distinct().ToArray(); + Assert.Equal(15, makers.Length); + foreach (var key in makers) + { + var assembly = cache.Get(key).Assembly; + Assert.NotNull(assembly); + Assert.InRange(assembly.Mean, .01f, 1f); + } + + Assert.All(cache.GetAll(), p => Assert.Null(p.Assembly)); + } + + // 16 is reserved for Relations, 17 is Doctrine, 18 is reserved for Livery, 20 for the place-names pass. + [Fact] + public void AssemblyRidesItsWireKeys() + { + int KeyOf(Type type) => type.GetField("Assembly").GetCustomAttribute().IntKey.Value; + Assert.Equal(19, KeyOf(typeof(Faction))); + Assert.Equal(6, KeyOf(typeof(FactionProductData))); + } +} diff --git a/tests/Aetheria.Shared.Tests/AssemblyFromMakerCommandTests.cs b/tests/Aetheria.Shared.Tests/AssemblyFromMakerCommandTests.cs new file mode 100644 index 000000000..76ac5c865 --- /dev/null +++ b/tests/Aetheria.Shared.Tests/AssemblyFromMakerCommandTests.cs @@ -0,0 +1,137 @@ +using System; +using System.IO; +using System.Linq; +using GameCult.Caching; +using Xunit; + +// assembly-from-maker (aetheria-release, cut assembly-from-maker): each maker's unauthored assembly is seeded from the roles +// of the products it manufactures. +public sealed class AssemblyFromMakerCommandTests : IDisposable +{ + private readonly string _root = Path.Combine(Path.GetTempPath(), "aetheria-assembly-cmd-" + Guid.NewGuid().ToString("N")); + private string Catalog => Path.Combine(_root, "Aetheria.cc"); + + public AssemblyFromMakerCommandTests() => Directory.CreateDirectory(_root); + public void Dispose() => Directory.Delete(_root, true); + + private void Seed() + { + using var cache = AetheriaStores.Open(Catalog, catalogWritable: true); + cache.Upsert(new VerseGrammar { Revision = 1 }); + var maker = cache.Upsert(new Faction { Name = "Maker" }); + cache.Upsert(new Faction { Name = "Bystander" }); + var gear = cache.Upsert(new GearData { Name = "Lamp", Hardpoint = HardpointType.Sensors, Shape = new Shape(), Price = 10 }); + var design = new CultRecordRef(gear.Key); + // Two products, three roles: the mean is over roles (.2, .4, .9 -> .5), the deviation likewise (.1, .1, .4 -> .2). + cache.Upsert(new FactionProductData + { + Name = "A", Design = design, Manufacturer = maker, + Roles = { new ProductRole { Role = "x", Mean = .2f, StandardDeviation = .1f }, new ProductRole { Role = "y", Mean = .4f, StandardDeviation = .1f } } + }); + cache.Upsert(new FactionProductData + { + Name = "B", Design = design, Manufacturer = maker, + Roles = { new ProductRole { Role = "x", Mean = .9f, StandardDeviation = .4f } } + }); + // Figures that need two decimals: (.2 + .27 + .31) / 3 = .26 and (.11 + .17 + .2) / 3 = .16. + var fine = cache.Upsert(new Faction { Name = "Fine" }); + cache.Upsert(new FactionProductData + { + Name = "C", Design = design, Manufacturer = fine, + Roles = + { + new ProductRole { Role = "x", Mean = .2f, StandardDeviation = .11f }, + new ProductRole { Role = "y", Mean = .27f, StandardDeviation = .17f }, + new ProductRole { Role = "z", Mean = .31f, StandardDeviation = .2f } + } + }); + // A maker whose parts are near the top: the margin is capped at 1. And one whose assembly was already authored in Studio. + var top = cache.Upsert(new Faction { Name = "Top" }); + cache.Upsert(new FactionProductData + { + Name = "D", Design = design, Manufacturer = top, + Roles = { new ProductRole { Role = "x", Mean = .95f, StandardDeviation = .05f } } + }); + var tuned = cache.Upsert(new Faction { Name = "Tuned", Assembly = new AssemblyDistribution { Mean = .42f, StandardDeviation = .07f } }); + cache.Upsert(new FactionProductData + { + Name = "E", Design = design, Manufacturer = tuned, + Roles = { new ProductRole { Role = "x", Mean = .1f, StandardDeviation = .3f } } + }); + cache.FlushAsync().Wait(); + } + + private string Run(bool apply) + { + using var cache = AetheriaStores.Open(Catalog, catalogWritable: apply); + var output = new StringWriter(); + Assert.Equal(0, AssemblyFromMakerCommand.Run(cache, apply, output)); + cache.FlushAsync().Wait(); + return output.ToString(); + } + + private Faction Maker(string name) + { + using var cache = AetheriaStores.Open(Catalog); + return cache.GetAll().Single(f => f.Name == name); + } + + // The assembly is the part mean plus the tolerance margin and the deviation the parts' mean; the margin is capped at 1; a + // faction that makes no roled product stays unauthored. + [Fact] + public void DerivesPartMeanPlusMargin() + { + Seed(); + Run(apply: true); + Assert.Equal(.6f, Maker("Maker").Assembly.Mean, 3); + Assert.Equal(.2f, Maker("Maker").Assembly.StandardDeviation, 3); + Assert.Equal(.36f, Maker("Fine").Assembly.Mean, 3); + Assert.Equal(.16f, Maker("Fine").Assembly.StandardDeviation, 3); + Assert.Equal(1f, Maker("Top").Assembly.Mean, 3); + Assert.Equal(.05f, Maker("Top").Assembly.StandardDeviation, 3); + Assert.Null(Maker("Bystander").Assembly); + } + + // The rule is part mean plus the margin, capped at 1, rounded to 2 dp, at every part mean and not only at the catalog + // fixtures: a one-role product at each, then two products whose roles weigh by role count, and the deviation the plain + // mean of the roles' (not their maximum). + [Fact] + public void DeriveIsPartMeanPlusMarginAtEveryMean() + { + FactionProductData Product(params (float mean, float deviation)[] roles) => + new FactionProductData { Roles = roles.Select((r, i) => new ProductRole { Role = "r" + i, Mean = r.mean, StandardDeviation = r.deviation }).ToList() }; + + foreach (var mean in new[] { .02f, .05f, .12f, .2f, .31f, .38f, .44f, .57f, .63f, .71f, .79f, .86f, .9f, .93f, .99f }) + { + var derived = AssemblyFromMakerCommand.Derive(new[] { Product((mean, .13f)) }); + Assert.Equal(Math.Round(Math.Min(1, mean + AssemblyFromMakerCommand.Margin), 2), derived.Mean, 3); + Assert.Equal(.13f, derived.StandardDeviation, 3); + } + + // (.1 + .3 + .8) / 3 = .4 -> .5, and (.02 + .3 + .4) / 3 = .24. + var weighed = AssemblyFromMakerCommand.Derive(new[] { Product((.1f, .02f)), Product((.3f, .3f), (.8f, .4f)) }); + Assert.Equal(.5f, weighed.Mean, 3); + Assert.Equal(.24f, weighed.StandardDeviation, 3); + Assert.Null(AssemblyFromMakerCommand.Derive(new[] { Product() })); + } + + // A value tuned in Studio survives every replay, a dry run writes nothing, and a second apply has nothing to do. + [Fact] + public void AuthoredAssemblyIsKept() + { + Seed(); + var before = File.ReadAllBytes(Catalog); + Assert.Contains("Maker", Run(apply: false)); + Assert.Equal(before, File.ReadAllBytes(Catalog)); + + Run(apply: true); + Assert.Equal(.42f, Maker("Tuned").Assembly.Mean, 3); + Assert.Equal(.07f, Maker("Tuned").Assembly.StandardDeviation, 3); + using (var cache = AetheriaStores.Open(Catalog)) + Assert.All(cache.GetAll(), p => Assert.Null(p.Assembly)); + + var written = File.ReadAllBytes(Catalog); + Assert.Contains("No changes", Run(apply: true)); + Assert.Equal(written, File.ReadAllBytes(Catalog)); + } +} diff --git a/tests/Aetheria.Shared.Tests/AssemblyFromMakerTests.cs b/tests/Aetheria.Shared.Tests/AssemblyFromMakerTests.cs new file mode 100644 index 000000000..efc1e1b3a --- /dev/null +++ b/tests/Aetheria.Shared.Tests/AssemblyFromMakerTests.cs @@ -0,0 +1,207 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using GameCult.Caching; +using Xunit; + +// Assembly is the maker's (aetheria-release, cut assembly-from-maker; rulings quality-is-assembly-over-supply-chain, +// quality-lean-assembly-hard-ceiling): a branded lot's own quality is drawn from its manufacturer's assembly distribution, +// and every role a stat reads is min(part, assembly). Lots here come from CreateLot(product), the production mint. +public sealed class AssemblyFromMakerTests : IDisposable +{ + private readonly string _root = Path.Combine(Path.GetTempPath(), "aetheria-assembly-" + Guid.NewGuid().ToString("N")); + private readonly CultCache _cache; + private readonly ItemManager _items; + private readonly CultRecordRef _lens; + + public AssemblyFromMakerTests() + { + Directory.CreateDirectory(_root); + _cache = AetheriaStores.Open(Path.Combine(_root, "Aetheria.cc"), catalogWritable: true); + var gear = _cache.Upsert(new GearData + { + Name = "Lensed", Hardpoint = HardpointType.Sensors, Shape = new Shape(), Price = 10, + Roles = { new ItemRole { Name = "lens" } } + }); + _lens = new CultRecordRef(gear.Key); + _items = new ItemManager(_cache, new ProvenanceLedger(), RunSaveTests.TestSettings(), _ => { }); + } + + public void Dispose() + { + _cache.Dispose(); + Directory.Delete(_root, true); + } + + private FactionProductData Product(string name, Faction maker, float partMean, float partDeviation = 0) + { + var makerRef = maker == null ? default : _cache.Upsert(maker); + _cache.Upsert(new FactionProductData + { + Name = name, Design = _lens, Manufacturer = makerRef, + Roles = { new ProductRole { Role = "lens", Mean = partMean, StandardDeviation = partDeviation } } + }); + return _cache.GetAll().Single(p => p.Name == name); + } + + private static AssemblyDistribution A(float mean, float deviation) => new AssemblyDistribution { Mean = mean, StandardDeviation = deviation }; + + private float[] Mint(FactionProductData product, int count) => + Enumerable.Range(0, count).Select(_ => _items.Lots[_items.CreateLot(product)].Quality).ToArray(); + + // Two makers, assembly .3 and .8: each lot's own quality follows its manufacturer, not a product-blind roll. + [Fact] + public void LotQualityFollowsMaker() + { + var low = Product("Low", new Faction { Name = "Low Maker", Assembly = A(.3f, .02f) }, .5f); + var high = Product("High", new Faction { Name = "High Maker", Assembly = A(.8f, .02f) }, .5f); + var lows = Mint(low, 300); + var highs = Mint(high, 300); + Assert.InRange(lows.Average(), .27f, .33f); + Assert.InRange(highs.Average(), .77f, .83f); + Assert.True(lows.Max() < highs.Min(), "a lot read the other maker's band"); + } + + // Quality control is the maker's too: the same mean, a wide and a tight deviation, and the spread of their lots follows. + [Fact] + public void LotSpreadFollowsMakerDeviation() + { + var wide = Mint(Product("Wide", new Faction { Name = "Wide Maker", Assembly = A(.5f, .2f) }, .5f), 400); + var tight = Mint(Product("Tight", new Faction { Name = "Tight Maker", Assembly = A(.5f, .02f) }, .5f), 400); + double Spread(float[] lots) => Math.Sqrt(lots.Select(q => Math.Pow(q - lots.Average(), 2)).Average()); + Assert.InRange(Spread(wide), .15, .25); + Assert.InRange(Spread(tight), .01, .04); + } + + // A maker the catalog cannot resolve, and a maker whose Assembly is not authored, assemble at AssemblyDistribution's defaults. + [Fact] + public void UnauthoredAssemblyAssemblesAtDefaults() + { + var defaults = new AssemblyDistribution(); + Assert.InRange(Mint(Product("Orphan", null, .5f), 400).Average(), defaults.Mean - .03f, defaults.Mean + .03f); + Assert.InRange(Mint(Product("Blank", new Faction { Name = "Blank Maker" }, .5f), 400).Average(), defaults.Mean - .03f, defaults.Mean + .03f); + } + + // A line's own final test (maker-design-tiers-allowed): a product carrying an Assembly mints at it, and a sibling product + // of the same maker without one reads the maker's. + [Fact] + public void ProductAssemblyOverridesMaker() + { + var maker = new Faction { Name = "Binner", Assembly = A(.3f, .02f) }; + var plain = Product("Plain", maker, .5f); + var premium = Product("Premium", maker, .5f); + premium.Assembly = A(.85f, .02f); + Assert.InRange(Mint(premium, 300).Average(), .82f, .88f); + Assert.InRange(Mint(plain, 300).Average(), .27f, .33f); + } + + // A stated quality is every lot's and every fill's, clamped, and draws nothing from the item stream. + [Fact] + public void StatedQualityDrawsNothing() + { + var product = Product("Staged", new Faction { Name = "Staged Maker", Assembly = A(.3f, .2f) }, .5f, .2f); + var before = _items.Random; + var lot = _items.Lots[_items.CreateLot(product, .6f)]; + Assert.Equal(.6f, lot.Quality, 3); + Assert.Equal(.6f, lot.Roles.Single().Quality, 3); + Assert.Equal(before.NextFloat(), _items.Random.NextFloat()); + Assert.Equal(1f, _items.Lots[_items.CreateLot(product, 7f)].Quality, 3); + Assert.Equal(.01f, _items.Lots[_items.CreateLot(product, -1f)].Roles.Single().Quality, 3); + } + + // A drawn assembly stays a quality: a maker authored past either end mints lots at .01 or 1. + [Fact] + public void DrawnAssemblyIsClamped() + { + Assert.All(Mint(Product("Over", new Faction { Name = "Over Maker", Assembly = A(1.5f, 0) }, .5f), 20), q => Assert.Equal(1f, q, 3)); + Assert.All(Mint(Product("Under", new Faction { Name = "Under Maker", Assembly = A(-.5f, 0) }, .5f), 20), q => Assert.Equal(.01f, q, 3)); + } + + // A staged fit's slot is built by Loadouts.Resolve: a product at the stated quality, a design no maker sells at the stated + // quality instead of UnbrandedQuality, and both at their own draws without one. + [Fact] + public void ResolveMintsAtTheStatedQuality() + { + var failures = new List(); + Lot Built(CultRecordRef product, float? quality) => + _items.GetLot(Loadouts.Resolve(_items, _lens, product, _ => null, "lens", failures, quality)()); + var unbranded = Built(default, .6f); + Assert.Equal(.6f, unbranded.Quality, 3); + Assert.Equal(Loadouts.UnbrandedQuality, Built(default, null).Quality, 3); + + var made = Product("Made", new Faction { Name = "Made Maker", Assembly = A(.3f, .2f) }, .5f, .2f); + var branded = Built(_cache.RefOf(made), .6f); + Assert.Equal(.6f, branded.Quality, 3); + Assert.Equal(.6f, branded.Roles.Single().Quality, 3); + Assert.Empty(failures); + } + + // The ceiling at the mint: a part drawn at .9 in an assembly of .4 reads .4; a part at .2 in the same assembly reads .2. + [Fact] + public void RoleCappedByAssembly() + { + var maker = new Faction { Name = "Capped", Assembly = A(.4f, 0) }; + var over = _items.Lots[_items.CreateLot(Product("Over", maker, .9f))]; + var under = _items.Lots[_items.CreateLot(Product("Under", maker, .2f))]; + Assert.Equal(.4f, over.Quality, 3); + Assert.Equal(.4f, over.QualityForRole("lens"), 3); + Assert.Equal(.2f, under.QualityForRole("lens"), 3); + // The raw part is kept for disassembly (named-components-after-demo). + Assert.Equal(.9f, over.Roles.Single().Quality, 3); + } + + // The ceiling is the assembly itself at every height and to the last digit: a poor assembler (below any floor) still caps a + // good part at its own quality, a part just above the assembly reads the assembly and not its own, and a part at or below it + // keeps its own. + [Fact] + public void RoleCeilingHasNoFloorAndNoToleranceBand() + { + float Role(float assembly, float part) => + _items.Lots[_items.CreateLot(Product($"A{assembly}P{part}", new Faction { Name = $"Maker {assembly}/{part}", Assembly = A(assembly, 0) }, part))].QualityForRole("lens"); + Assert.Equal(.1f, Role(.1f, .9f), 3); + Assert.Equal(.02f, Role(.02f, .5f), 3); + Assert.Equal(.4f, Role(.4f, .41f), 3); + Assert.Equal(.4f, Role(.4f, .43f), 3); + Assert.Equal(.4f, Role(.4f, .4f), 3); + Assert.Equal(.39f, Role(.4f, .39f), 3); + } + + // The line's own final test replaces the maker's whole distribution, spread included: a maker of no spread and a product + // of a wide one mint a wide spread, and the reverse mints none. + [Fact] + public void ProductAssemblyOverridesMakersSpreadToo() + { + var steady = new Faction { Name = "Steady", Assembly = A(.5f, 0) }; + var wild = Product("Wild", steady, .5f); + wild.Assembly = A(.5f, .2f); + var wildLots = Mint(wild, 400); + Assert.InRange(Math.Sqrt(wildLots.Select(q => Math.Pow(q - wildLots.Average(), 2)).Average()), .15, .25); + + var loose = new Faction { Name = "Loose", Assembly = A(.5f, .2f) }; + var tight = Product("Tight", loose, .5f); + tight.Assembly = A(.5f, 0); + Assert.All(Mint(tight, 50), q => Assert.Equal(.5f, q, 3)); + } + + // The fallbacks still read the assembly: an unnamed role, an unrolled role, and a lot with no roles. + [Fact] + public void FallbacksReadTheAssembly() + { + var lot = new Lot { Quality = .4f, Roles = new List { new RoleFill { Role = "lens", Quality = .9f } } }; + Assert.Equal(.4f, lot.QualityForRole(null), 3); + Assert.Equal(.4f, lot.QualityForRole(""), 3); + Assert.Equal(.4f, lot.QualityForRole("ghost"), 3); + Assert.Equal(.4f, new Lot { Quality = .4f }.QualityForRole("lens"), 3); + } + + // A Quality term on a role with part .9 and assembly .4 evaluates as if quality were .4, on a real minted instance. + [Fact] + public void QualityTermReadsCeiling() + { + var maker = new Faction { Name = "Capped", Assembly = A(.4f, 0) }; + var instance = (EquippableItem) _items.CreateInstance(_items.CreateLot(Product("Over", maker, .9f))); + var stat = new PerformanceStat { Min = 0, Max = 1, Terms = { new StatTerm { Source = StatSource.Quality, Exponent = 1, Role = "lens" } } }; + Assert.Equal(.4f, _items.Evaluate(stat, instance), 3); + } +} diff --git a/tests/Aetheria.Shared.Tests/BrownoutTests.cs b/tests/Aetheria.Shared.Tests/BrownoutTests.cs index c901648e7..b48657e33 100644 --- a/tests/Aetheria.Shared.Tests/BrownoutTests.cs +++ b/tests/Aetheria.Shared.Tests/BrownoutTests.cs @@ -52,7 +52,7 @@ public sealed class BrownoutTests : IDisposable private static GameplaySettings Settings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; diff --git a/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs b/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs index 0a452491f..b50e0142d 100644 --- a/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs +++ b/tests/Aetheria.Shared.Tests/CatalogRoleTests.cs @@ -322,7 +322,7 @@ public sealed class CatalogRoleTests private sealed class DisciplineContext : IStatContext { public DisciplineContext(float discipline) => - Lot = new Lot { Quality = .123f, Roles = new List { new RoleFill { Role = "emission-discipline", Quality = discipline } } }; + Lot = new Lot { Quality = 1f, Roles = new List { new RoleFill { Role = "emission-discipline", Quality = discipline } } }; public Lot Lot { get; } public float HeatFactor(float exponent) => 1f; public float DurabilityFactor(float exponent) => 1f; diff --git a/tests/Aetheria.Shared.Tests/ConditionRatioTests.cs b/tests/Aetheria.Shared.Tests/ConditionRatioTests.cs index e294b942f..c3a5ddcde 100644 --- a/tests/Aetheria.Shared.Tests/ConditionRatioTests.cs +++ b/tests/Aetheria.Shared.Tests/ConditionRatioTests.cs @@ -27,7 +27,7 @@ public sealed class ConditionRatioTests : IDisposable private static GameplaySettings Settings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; diff --git a/tests/Aetheria.Shared.Tests/ConsumableAiTests.cs b/tests/Aetheria.Shared.Tests/ConsumableAiTests.cs index f86dc1e07..6ad889fda 100644 --- a/tests/Aetheria.Shared.Tests/ConsumableAiTests.cs +++ b/tests/Aetheria.Shared.Tests/ConsumableAiTests.cs @@ -323,6 +323,36 @@ public sealed class ConsumableAiTests : IDisposable Assert.Equal(overdrives, s.Active(s.Overdrive)); } + // The zone gives each pilot it admits its own ordinal, from 1 and never reused: the key of its own dice + // (SimulationDice.CombatSampleStream). Kills: Zone.CreateAgent not setting Agent.Id. + [Fact] + public void TheZoneGivesEachAdmittedPilotItsOwnId() + { + var s = Build(carryOverdrive: true); + var first = s.Zone.Agents.Single().Id; + Assert.True(first > 0, "an admitted pilot has an id"); + + Assert.True(s.Zone.Remove(s.Agent)); + s.Agent.Deactivate(); + s.Zone.Admit(s.Agent, piloted: true); + + Assert.True(s.Zone.Agents.Last(a => ReferenceEquals(a.Ship, s.Agent)).Id > first, "a re-admitted pilot is a new id"); + } + + // Admitting a pilot takes nothing from the item stream: its patrol circuit is its own draw, so how pilots are chosen never + // moves what is minted next. Kills: the circuit drawn from ItemManager.Random. + [Fact] + public void AdmittingAPilotDrawsNothingFromTheItemStream() + { + var s = Build(carryOverdrive: true); + Assert.True(s.Zone.Remove(s.Agent)); + s.Agent.Deactivate(); + var items = s.Agent.ItemManager; + var before = items.Random; + s.Zone.Admit(s.Agent, piloted: true); + Assert.Equal(before.NextFloat(), items.Random.NextFloat()); + } + // The production path for the optimum: a ship the zone admits as piloted derives it from its gun's live stats // before it needs it, and re-derives it when its loadout changes. The gun's effective range is 500 and the // heavy gun's is 800, so the optimum moves with the weapons it has now. diff --git a/tests/Aetheria.Shared.Tests/ConsumableSupplyTests.cs b/tests/Aetheria.Shared.Tests/ConsumableSupplyTests.cs index cd968e885..78cbf6f0f 100644 --- a/tests/Aetheria.Shared.Tests/ConsumableSupplyTests.cs +++ b/tests/Aetheria.Shared.Tests/ConsumableSupplyTests.cs @@ -334,14 +334,15 @@ public sealed class ConsumableSupplyTests : IDisposable .Concat(Enumerable.Range(0, 4).Select(_ => rig.Items.Random.NextFloat())).ToArray(); } - // What the plain catalog leaves in both generators' Random, measured on the tree before consumables existed - // (origin/master d4a27def, the same fixture and seeds), plus the one product draw each of the three generated - // ships makes for its tractor beam (loot-2): with that draw taken out the tree leaves the d4a27def values - // 0.85624266, 0.037778974, 0.7931649, 0.3596493, 0.17511952, 0.6642336, 0.31897342, 0.5977364. The gated and - // plain catalogs agreeing is not enough: a step that drew unconditionally would draw in both. This pins the value itself. + // What the plain catalog leaves in both generators' Random: the d4a27def measurement (before consumables existed, the + // same fixture and seeds) plus the one product draw each of the three generated ships makes for its tractor beam + // (loot-2), re-measured when a lot's assembly became a Gaussian draw from its maker (assembly-from-maker), which + // consumes the item stream differently from the tier roll it replaced; the generator's own stream (the first four + // values) is unchanged. The gated and plain catalogs agreeing is not enough: a step that drew unconditionally would + // draw in both. This pins the value itself. var beforeConsumables = new[] { - 0.3596493f, 0.03616327f, 0.8790466f, 0.16682059f, 0.5977364f, 0.08633745f, 0.2869571f, 0.6890472f + 0.3596493f, 0.03616327f, 0.8790466f, 0.16682059f, 0.55950844f, 0.87309176f, 0.7170387f, 0.8490041f }; var plainAfter = AfterGeneration(plain); Assert.Equal(beforeConsumables, plainAfter); diff --git a/tests/Aetheria.Shared.Tests/ConsumablesFirstSetTests.cs b/tests/Aetheria.Shared.Tests/ConsumablesFirstSetTests.cs index d43fb47be..300c2f9b9 100644 --- a/tests/Aetheria.Shared.Tests/ConsumablesFirstSetTests.cs +++ b/tests/Aetheria.Shared.Tests/ConsumablesFirstSetTests.cs @@ -146,7 +146,7 @@ public sealed class ConsumablesFirstSetTests var second = design.Roles[1].Name; var lot = Ship.ItemManager.Lots.Add(new Lot { - Design = Cache.RefOf(design), Origin = new Attributed(), Quality = .5f, + Design = Cache.RefOf(design), Origin = new Attributed(), Quality = 1f, Roles = new List { new RoleFill { Role = first, Quality = propellantOrNozzleQuality }, diff --git a/tests/Aetheria.Shared.Tests/ContactRevealTests.cs b/tests/Aetheria.Shared.Tests/ContactRevealTests.cs index 6ea4af3da..bdca8008f 100644 --- a/tests/Aetheria.Shared.Tests/ContactRevealTests.cs +++ b/tests/Aetheria.Shared.Tests/ContactRevealTests.cs @@ -176,7 +176,7 @@ public sealed partial class ContactRevealTests : IDisposable _items = new ItemManager(_openCache, ledger, new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, diff --git a/tests/Aetheria.Shared.Tests/ContactTests.cs b/tests/Aetheria.Shared.Tests/ContactTests.cs index bccd2a90d..adceb4b98 100644 --- a/tests/Aetheria.Shared.Tests/ContactTests.cs +++ b/tests/Aetheria.Shared.Tests/ContactTests.cs @@ -90,7 +90,7 @@ public sealed class ContactTests : IDisposable var settings = new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, FiringArc = 170, CommitHorizon = .5f, SchematicCellSize = 2f, ContactRestitution = restitution diff --git a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs index a55cf3e93..a21aa7f19 100644 --- a/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs +++ b/tests/Aetheria.Shared.Tests/CrossingScenarioTests.cs @@ -55,6 +55,7 @@ public sealed partial class RunStartTests var toWaiting = waiting.Position - player.Position; EvSettle(player); // a weapon's Range is read once the ship's stats have settled; the geometry above is as staged var range = projector.Behaviors.OfType().Single().Range; + Assert.InRange(range, Crossing.ProjectorRange - 1f, Crossing.ProjectorRange + 1f); // the constant the waiting place is 80% of Assert.True(FireControl.InArc(projector, toWaiting), "the waiting Djinni is inside the Lightning Projector's arc"); Assert.True(length(toWaiting) <= range, "the waiting Djinni is inside the Lightning Projector's Range"); Assert.True(length(toWaiting) > .75f * range, "the waiting Djinni is beyond three quarters of the Lightning Projector's Range"); diff --git a/tests/Aetheria.Shared.Tests/DrawnPoseTests.cs b/tests/Aetheria.Shared.Tests/DrawnPoseTests.cs index 9507d0783..ca0f6f00d 100644 --- a/tests/Aetheria.Shared.Tests/DrawnPoseTests.cs +++ b/tests/Aetheria.Shared.Tests/DrawnPoseTests.cs @@ -87,7 +87,7 @@ public sealed class DrawnPoseTests : IDisposable var items = new ItemManager(cache, ledger, new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), ShipLayerHeight = ShipLayerHeight, OrbitalLayerHeight = OrbitalLayerHeight, FloaterLayerHeight = FloaterLayerHeight }, _ => { }); diff --git a/tests/Aetheria.Shared.Tests/EmissionTests.cs b/tests/Aetheria.Shared.Tests/EmissionTests.cs index c6e2927b8..831f6f520 100644 --- a/tests/Aetheria.Shared.Tests/EmissionTests.cs +++ b/tests/Aetheria.Shared.Tests/EmissionTests.cs @@ -316,7 +316,7 @@ public sealed partial class ContactRevealTests } // A catalog-style sensor reads its intercept factor through the lot the ship equips it from: the lot's - // emission-discipline fill is the input (the workmanship is a decoy at .123), so a Sensor that read only the quiet or only + // emission-discipline fill is the input (the workmanship, at 1, is a decoy), so a Sensor that read only the quiet or only // the loud end, or the workmanship, reads the wrong number. The expectations are lerp(.5, 2, q^log2(3)): a middling part // reads 1, the Lucent mean (.2) reads about .62 and the Finch mean (.8) about 1.55. [Theory] @@ -325,7 +325,7 @@ public sealed partial class ContactRevealTests [InlineData(.8f, 1.5534f)] public void ASensorReadsItsInterceptFactorFromItsLotsEmissionDiscipline(float discipline, float expected) { - var lot = _items.CreateLot(_openCache.GetByName("Disciplined"), _maker, .123f); + var lot = _items.CreateLot(_openCache.GetByName("Disciplined"), _maker, 1f); _items.Lots[lot].Roles = new List { new RoleFill { Role = "emission-discipline", Quality = discipline } }; _preparedLots["Disciplined"] = lot; var ship = Add(float3(0, 0, 0), new[] { "Disciplined" }); @@ -345,7 +345,7 @@ public sealed partial class ContactRevealTests public void AnEmissionIsHeardWithinRangeOverTheLotsAlpha(bool ping, float distance, bool heard) { var design = ping ? "Disciplined" : "DisciplinedScanner"; - var lot = _items.CreateLot(_openCache.GetByName(design), _maker, .123f); + var lot = _items.CreateLot(_openCache.GetByName(design), _maker, 1f); _items.Lots[lot].Roles = new List { new RoleFill { Role = "emission-discipline", Quality = .2f } }; _preparedLots[design] = lot; var third = Add(float3(-distance, 0, 0), new[] { "Eye" }); diff --git a/tests/Aetheria.Shared.Tests/EvasionTermTests.cs b/tests/Aetheria.Shared.Tests/EvasionTermTests.cs index ffd99d16e..80f0a145f 100644 --- a/tests/Aetheria.Shared.Tests/EvasionTermTests.cs +++ b/tests/Aetheria.Shared.Tests/EvasionTermTests.cs @@ -22,6 +22,9 @@ public sealed partial class RunStartTests { private const float EvDt = 1f / 60f; + // The quality the hand-fitted ships are staged at, so their measured constants do not ride the item stream. + private const float EvStagedQuality = .6f; + // The Longinus's drive train, fitted by name: its cockpit and power and the generated Longinus's thrusters (two Large Drive // forward, two Rugged Drive on the flanks). private static readonly (string design, int2 cell, ItemRotation rotation)[] EvLonginusDrive = @@ -32,7 +35,7 @@ public sealed partial class RunStartTests }; // The Duel's guns on a Longinus: the drive train above, its Targeting Computer, and the Duel's guns, launchers and sensor. - private static ScenarioFit EvLonginus(ScenarioStage stage, string gun = "Cell Blaster", string second = null) => stage.Fit("Longinus", + private static ScenarioFit EvLonginus(ScenarioStage stage, string gun = "Cell Blaster", string second = null) => stage.Fit("Longinus", EvStagedQuality, EvLonginusDrive.Concat(new (string design, int2 cell, ItemRotation rotation)[] { ("Guided Missile Launcher", int2(0, 5), ItemRotation.None), ("Guided Missile Launcher", int2(5, 5), ItemRotation.None), (gun, int2(1, 8), ItemRotation.None), @@ -70,7 +73,7 @@ public sealed partial class RunStartTests { stage.Player(stage.Bare("Djinni"), float2(-50000, -50000)); djinni = stage.Place(EvDjinni(stage), float2(-10000, -30000), facing: float2(0, 1)) as Ship; - longinus = stage.Place(stage.Fit("Longinus", EvLonginusDrive), float2(-30000, -30000), facing: float2(0, 1)) as Ship; + longinus = stage.Place(stage.Fit("Longinus", EvStagedQuality, EvLonginusDrive), float2(-30000, -30000), facing: float2(0, 1)) as Ship; }); var (_, arena, _, failures) = Launch(scenario, Inputs(() => GalaxySeed)); Assert.True(failures.Count == 0, string.Join("; ", failures)); @@ -621,7 +624,7 @@ public sealed partial class RunStartTests // The target's fit, written out: the Djinni's own hardpoints filled with the Rugged Drive it is generated with, its // reactor, cockpit and radiators. What the evasion tests price is this ship's strafing, not whatever the generator // rolls for it from the galaxy. - private static ScenarioFit EvDjinni(ScenarioStage stage) => stage.Fit("Djinni", + private static ScenarioFit EvDjinni(ScenarioStage stage) => stage.Fit("Djinni", EvStagedQuality, ("Cockpit 2x2", int2(6, 3), ItemRotation.None), ("Compact Reactor", int2(6, 11), ItemRotation.None), ("Rugged Drive", int2(6, 0), ItemRotation.Reversed), ("Rugged Drive", int2(5, 1), ItemRotation.Reversed), ("Rugged Drive", int2(7, 1), ItemRotation.Reversed), ("Rugged Drive", int2(4, 4), ItemRotation.CounterClockwise), ("Rugged Drive", int2(4, 11), ItemRotation.CounterClockwise), diff --git a/tests/Aetheria.Shared.Tests/FireAuthorityTests.cs b/tests/Aetheria.Shared.Tests/FireAuthorityTests.cs index fb919c2ec..8323bd7a9 100644 --- a/tests/Aetheria.Shared.Tests/FireAuthorityTests.cs +++ b/tests/Aetheria.Shared.Tests/FireAuthorityTests.cs @@ -37,7 +37,7 @@ public sealed class FireAuthorityTests : IDisposable private static GameplaySettings TestSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, FiringArc = 170, diff --git a/tests/Aetheria.Shared.Tests/FireControlCut11Tests.cs b/tests/Aetheria.Shared.Tests/FireControlCut11Tests.cs index 5dc373390..9e9d74fce 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut11Tests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut11Tests.cs @@ -37,7 +37,7 @@ public sealed class FireControlCut11Tests : IDisposable private static GameplaySettings TestSettings(float schematicCellSize = 1f) => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, diff --git a/tests/Aetheria.Shared.Tests/FireControlCut123Tests.cs b/tests/Aetheria.Shared.Tests/FireControlCut123Tests.cs index 670b96490..7e49ec3c7 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut123Tests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut123Tests.cs @@ -39,7 +39,7 @@ public sealed class FireControlCut123Tests : IDisposable private static GameplaySettings TestSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, diff --git a/tests/Aetheria.Shared.Tests/FireControlCut124Tests.cs b/tests/Aetheria.Shared.Tests/FireControlCut124Tests.cs index 4bcd5b034..e6d8f5a0e 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut124Tests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut124Tests.cs @@ -41,7 +41,7 @@ public sealed partial class FireControlCut124Tests : IDisposable private static GameplaySettings TestSettings(float commitHorizon = .5f) => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, diff --git a/tests/Aetheria.Shared.Tests/FireControlCut12Tests.cs b/tests/Aetheria.Shared.Tests/FireControlCut12Tests.cs index 1c343c00b..adbcac5ef 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut12Tests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut12Tests.cs @@ -38,7 +38,7 @@ public sealed class FireControlCut12Tests : IDisposable private static GameplaySettings TestSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, diff --git a/tests/Aetheria.Shared.Tests/FireControlCut4Tests.cs b/tests/Aetheria.Shared.Tests/FireControlCut4Tests.cs index 469ebc75b..08ba48d0d 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut4Tests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut4Tests.cs @@ -39,7 +39,7 @@ public sealed class FireControlCut4Tests : IDisposable private static GameplaySettings TestSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, FiringArc = 170, diff --git a/tests/Aetheria.Shared.Tests/FireControlCut5Tests.cs b/tests/Aetheria.Shared.Tests/FireControlCut5Tests.cs index f9d12e330..1727a9829 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut5Tests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut5Tests.cs @@ -37,7 +37,7 @@ public sealed class FireControlCut5Tests : IDisposable private static GameplaySettings TestSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, diff --git a/tests/Aetheria.Shared.Tests/FireControlCut6Tests.cs b/tests/Aetheria.Shared.Tests/FireControlCut6Tests.cs index 1755cd7e3..03aab2e3f 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut6Tests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut6Tests.cs @@ -37,7 +37,7 @@ public sealed class FireControlCut6Tests : IDisposable private static GameplaySettings TestSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, diff --git a/tests/Aetheria.Shared.Tests/FireControlCut6cTests.cs b/tests/Aetheria.Shared.Tests/FireControlCut6cTests.cs index e04ee078b..5517c4121 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut6cTests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut6cTests.cs @@ -36,7 +36,7 @@ public sealed class FireControlCut6cTests : IDisposable private static GameplaySettings TestSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, diff --git a/tests/Aetheria.Shared.Tests/FireControlCut6dTests.cs b/tests/Aetheria.Shared.Tests/FireControlCut6dTests.cs index 828965836..9fdbde4a0 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut6dTests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut6dTests.cs @@ -38,7 +38,7 @@ public sealed class FireControlCut6dTests : IDisposable private static GameplaySettings TestSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, diff --git a/tests/Aetheria.Shared.Tests/FireControlCut7Tests.cs b/tests/Aetheria.Shared.Tests/FireControlCut7Tests.cs index 01bd840ee..4e0c4a91f 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut7Tests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut7Tests.cs @@ -40,7 +40,7 @@ public sealed class FireControlCut7Tests : IDisposable private static GameplaySettings TestSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .9f, @@ -210,7 +210,7 @@ public sealed class FireControlCut7Tests : IDisposable var settings = new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; var log = new List(); diff --git a/tests/Aetheria.Shared.Tests/FireControlCut8Tests.cs b/tests/Aetheria.Shared.Tests/FireControlCut8Tests.cs index d5ce6a28b..a0d767ab3 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut8Tests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut8Tests.cs @@ -36,7 +36,7 @@ public sealed class FireControlCut8Tests : IDisposable private static GameplaySettings TestSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, diff --git a/tests/Aetheria.Shared.Tests/FireControlCut9Tests.cs b/tests/Aetheria.Shared.Tests/FireControlCut9Tests.cs index cc63a9bc4..448cbb333 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut9Tests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut9Tests.cs @@ -39,7 +39,7 @@ public sealed class FireControlCut9Tests : IDisposable private static GameplaySettings TestSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, diff --git a/tests/Aetheria.Shared.Tests/FireControlPerWeaponTests.cs b/tests/Aetheria.Shared.Tests/FireControlPerWeaponTests.cs index 21cde60cb..bbd57c7ac 100644 --- a/tests/Aetheria.Shared.Tests/FireControlPerWeaponTests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlPerWeaponTests.cs @@ -39,7 +39,7 @@ public sealed class FireControlPerWeaponTests : IDisposable { OrbitalLayerHeight = orbitalLayerHeight, DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, @@ -780,6 +780,46 @@ public sealed class FireControlPerWeaponTests : IDisposable Assert.True(Optimum(1f) - Optimum(0f) > 100f); } + // The range-sample offset is the pilot's own draw (zone seed, its id), never the item stream's: the same pilot + // samples the same optimum however many items were minted before it spawned, and two pilots sample their own. + // Kills: the offset drawn from ItemManager.Random; the agent id dropped from the draw. + [Fact] + public void AnAgentsSampleOffsetIsItsOwnAndNotTheItemStreams() + { + var r = Build(range: 400f, decoy: true); + float Optimum(uint id, int itemsMintedFirst) + { + for (var i = 0; i < itemsMintedFirst; i++) r.Shooter.ItemManager.Random.NextFloat(); + var combat = new CombatState(new Minion(r.Shooter, new RoleDoctrine { RangeExponent = 1f, MinHitProbability = .2f }) { Id = id }); + combat.Update(0f); + return combat.OptimumRange; + } + + Assert.Equal(Optimum(3, 0), Optimum(3, 0)); + Assert.Equal(Optimum(3, 0), Optimum(3, 17)); + Assert.True(Enumerable.Range(1, 8).Select(i => Optimum((uint) i, 0)).Distinct().Count() > 1, + "pilots with different ids sample different offsets"); + + // Whose dice: each sampled range is the pilot's offset plus a whole step of the sample grid, so the optimum + // minus the offset from CombatSampleStream lands on the grid for every id; an offset from another stream + // (the loot dice, say) leaves a remainder. Kills: the offset drawn from another stream. + var min = r.Shooter.Weapons.Min(w => w.MinRange); + var step = (r.Shooter.Weapons.Max(w => w.Range) - min) / 32f; // Combat.DPS_SAMPLE_COUNT + foreach (var id in Enumerable.Range(1, 16).Select(i => (uint) i)) + { + var offset = SimulationDice.For(r.Zone.CombatSeed, SimulationDice.CombatSampleStream, id).NextFloat(step); + var cells = (Optimum(id, 0) - offset - min) / step; + Assert.True(MathF.Abs(cells - MathF.Round(cells)) < .01f, $"id {id}: optimum is {cells} steps from the pilot's own offset"); + } + + // The other direction: sampling the optimum takes nothing from the item stream, so how a pilot fights never moves + // what is minted next. Kills: an AI draw from ItemManager.Random. + var items = r.Shooter.ItemManager; + var before = items.Random; + Optimum(5, 0); + Assert.Equal(before.NextFloat(), items.Random.NextFloat()); + } + // A round refused on a Range that fell between the trigger and the round is still free: the burst is paid // (SingleAmmoBurst) at its first round that is not refused, judged with the Range that round flies with. // The trigger saw a stale Range of 100; the round's Range is 29.5, under the arming distance. The refusal diff --git a/tests/Aetheria.Shared.Tests/FireControlTests.cs b/tests/Aetheria.Shared.Tests/FireControlTests.cs index 68ab9a6db..b10a2fa18 100644 --- a/tests/Aetheria.Shared.Tests/FireControlTests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlTests.cs @@ -33,7 +33,7 @@ public sealed class FireControlTests : IDisposable { ShipLayerHeight = shipLayerHeight, DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .5f, FiringArc = 120 diff --git a/tests/Aetheria.Shared.Tests/FlightTests.cs b/tests/Aetheria.Shared.Tests/FlightTests.cs index 263f9a086..ba0a4dd82 100644 --- a/tests/Aetheria.Shared.Tests/FlightTests.cs +++ b/tests/Aetheria.Shared.Tests/FlightTests.cs @@ -919,7 +919,7 @@ public sealed class FlightTests : IDisposable var slots = MessagePack.MessagePackSerializer.Deserialize(MessagePack.MessagePackSerializer.Serialize(faction, CultDocumentMessagePackSerialization.OptionsFor(typeof(Faction).Assembly))); - Assert.Equal(18, slots.Length); + Assert.Equal(20, slots.Length); // 19 is Assembly Assert.Null(slots[16]); var doctrine = Assert.IsType(slots[17]); Assert.Equal(6f, Convert.ToSingle(doctrine[1])); diff --git a/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs b/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs index 3ca18c4aa..ac4f763c1 100644 --- a/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs +++ b/tests/Aetheria.Shared.Tests/FloatingBodyTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using CultMath; using GameCult.Caching; using Xunit; @@ -36,7 +37,7 @@ public sealed class FloatingBodyTests : IDisposable var settings = new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; var items = new ItemManager(cache, new ProvenanceLedger(), settings, _ => { }); @@ -138,6 +139,28 @@ public sealed class FloatingBodyTests : IDisposable Assert.Equal(1u, zero.state); } + // The stream is mixed into the seed, not added beside it: over many ordinals no two streams give the same first + // draw, and none of them tracks another's. + [Fact] + public void EveryStreamDrawsIndependentlyOfEveryOther() + { + uint[] streams = { SimulationDice.LootStream, SimulationDice.MineStream, SimulationDice.CombatSampleStream, SimulationDice.PatrolStream }; + const int count = 512; + var draws = streams.Select(s => Enumerable.Range(1, count).Select(n => SimulationDice.For(1234u, s, (uint) n).NextFloat()).ToArray()).ToArray(); + for (var a = 0; a < streams.Length; a++) + for (var b = a + 1; b < streams.Length; b++) + { + Assert.Equal(0, Enumerable.Range(0, count).Count(i => draws[a][i] == draws[b][i])); + var meanA = draws[a].Average(); + var meanB = draws[b].Average(); + var covariance = Enumerable.Range(0, count).Sum(i => (draws[a][i] - meanA) * (draws[b][i] - meanB)) / count; + var correlation = covariance / (StandardDeviation(draws[a], meanA) * StandardDeviation(draws[b], meanB)); + Assert.InRange(correlation, -.15f, .15f); // 512 independent draws: sigma ~ .044 + } + } + + private static float StandardDeviation(float[] xs, float mean) => MathF.Sqrt(xs.Sum(x => (x - mean) * (x - mean)) / xs.Length); + [Fact] public void NeighbouringZonesAndOrdinalsNeverShareADraw() { @@ -180,7 +203,7 @@ public sealed class FloatingBodyTests : IDisposable var settings = new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; var items = new ItemManager(cache, new ProvenanceLedger(), settings, _ => { }); diff --git a/tests/Aetheria.Shared.Tests/FlowFieldTests.cs b/tests/Aetheria.Shared.Tests/FlowFieldTests.cs index c5cb3b793..fefff55f4 100644 --- a/tests/Aetheria.Shared.Tests/FlowFieldTests.cs +++ b/tests/Aetheria.Shared.Tests/FlowFieldTests.cs @@ -25,7 +25,7 @@ public sealed class FlowFieldTests : IDisposable var settings = new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, FiringArc = 170, CommitHorizon = .5f, SchematicCellSize = 2f diff --git a/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs b/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs index 2b329ad5d..f21d78f79 100644 --- a/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs +++ b/tests/Aetheria.Shared.Tests/GravitySubtractTests.cs @@ -24,7 +24,7 @@ public sealed class GravitySubtractTests : IDisposable var settings = new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, FiringArc = 170, CommitHorizon = .5f, SchematicCellSize = 2f diff --git a/tests/Aetheria.Shared.Tests/HeatResponseTests.cs b/tests/Aetheria.Shared.Tests/HeatResponseTests.cs index 0f21e50d1..9711f91c1 100644 --- a/tests/Aetheria.Shared.Tests/HeatResponseTests.cs +++ b/tests/Aetheria.Shared.Tests/HeatResponseTests.cs @@ -20,7 +20,7 @@ public sealed class HeatResponseTests : IDisposable private GameplaySettings Settings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; diff --git a/tests/Aetheria.Shared.Tests/IffAndCombatTests.cs b/tests/Aetheria.Shared.Tests/IffAndCombatTests.cs index 0de789ff1..b2bd752ba 100644 --- a/tests/Aetheria.Shared.Tests/IffAndCombatTests.cs +++ b/tests/Aetheria.Shared.Tests/IffAndCombatTests.cs @@ -65,7 +65,7 @@ public sealed class IffAndCombatTests : IDisposable private static GameplaySettings TestSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .5f }; diff --git a/tests/Aetheria.Shared.Tests/InputCapacitorTests.cs b/tests/Aetheria.Shared.Tests/InputCapacitorTests.cs index 3a7b9e2d5..d7279380e 100644 --- a/tests/Aetheria.Shared.Tests/InputCapacitorTests.cs +++ b/tests/Aetheria.Shared.Tests/InputCapacitorTests.cs @@ -24,7 +24,7 @@ public sealed class InputCapacitorTests : IDisposable private static GameplaySettings Settings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; diff --git a/tests/Aetheria.Shared.Tests/InspectionScannerCatalogTests.cs b/tests/Aetheria.Shared.Tests/InspectionScannerCatalogTests.cs index 43d7fcce4..e9cb862fa 100644 --- a/tests/Aetheria.Shared.Tests/InspectionScannerCatalogTests.cs +++ b/tests/Aetheria.Shared.Tests/InspectionScannerCatalogTests.cs @@ -102,7 +102,7 @@ public sealed class InspectionScannerCatalogTests ledger.Lots[1] = new Lot { Origin = new Attributed(), Quality = .5f }; ledger.Lots[2] = new Lot { - Origin = new Attributed(), Quality = .5f, + Origin = new Attributed(), Quality = 1f, Roles = product.Roles.Select(r => new RoleFill { Role = r.Role, Quality = r.Mean }).ToList(), }; var items = new ItemManager(Cache, ledger, settings, _ => { }); diff --git a/tests/Aetheria.Shared.Tests/LaunchSuppressorCatalogTests.cs b/tests/Aetheria.Shared.Tests/LaunchSuppressorCatalogTests.cs index 096845380..d54f7c983 100644 --- a/tests/Aetheria.Shared.Tests/LaunchSuppressorCatalogTests.cs +++ b/tests/Aetheria.Shared.Tests/LaunchSuppressorCatalogTests.cs @@ -113,7 +113,7 @@ public sealed class LaunchSuppressorCatalogTests for (var i = 1; i <= suppressorLot; i++) ledger.Lots[i] = new Lot { Origin = new Attributed(), Quality = .5f }; ledger.Lots[suppressorLot] = new Lot { - Origin = new Attributed(), Quality = .5f, + Origin = new Attributed(), Quality = 1f, Roles = new List { new RoleFill { Role = "baffles", Quality = baffles }, new RoleFill { Role = "heat sink", Quality = sink } }, }; var items = new ItemManager(Cache, ledger, settings, _ => { }); diff --git a/tests/Aetheria.Shared.Tests/LayerTests.cs b/tests/Aetheria.Shared.Tests/LayerTests.cs index cb1bf4cf9..75d79d947 100644 --- a/tests/Aetheria.Shared.Tests/LayerTests.cs +++ b/tests/Aetheria.Shared.Tests/LayerTests.cs @@ -37,7 +37,7 @@ public sealed class LayerTests : IDisposable private static GameplaySettings Settings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), ShipLayerHeight = ShipHeight, OrbitalLayerHeight = OrbitalHeight, FloaterLayerHeight = FloaterHeight }; diff --git a/tests/Aetheria.Shared.Tests/LoadoutTests.cs b/tests/Aetheria.Shared.Tests/LoadoutTests.cs index f1ae47b5d..4efbd0b30 100644 --- a/tests/Aetheria.Shared.Tests/LoadoutTests.cs +++ b/tests/Aetheria.Shared.Tests/LoadoutTests.cs @@ -489,8 +489,8 @@ public sealed class LoadoutTests : IDisposable Assert.Equal(hardpointItems[0].item.Lot, hardpointItems[1].item.Lot); } - // A Lamp lot with Quality .2 and one role fill (lens .9): a stat reading that role gets .9, one reading none - // gets .2, and GetTier reads .2. + // A Lamp lot with Quality .2 and one role fill (lens .15, under the assembly): a stat reading that role gets .15, one + // reading none gets .2, and GetTier reads .2. [Fact] public void StatsReadTheLot() { @@ -500,8 +500,8 @@ public sealed class LoadoutTests : IDisposable // quality", since every lot would resolve to the only tier regardless of its own Quality. settings.Tiers = new[] { - new RarityTier { Name = "Common", Quality = .2f, Rarity = 0, Color = new float3(1, 1, 1) }, - new RarityTier { Name = "Rare", Quality = .5f, Rarity = 1, Color = new float3(1, 1, 1) } + new RarityTier { Name = "Common", Quality = .2f, Color = new float3(1, 1, 1) }, + new RarityTier { Name = "Rare", Quality = .5f, Color = new float3(1, 1, 1) } }; var items = new ItemManager(cache, new ProvenanceLedger(), settings, _ => { }); var lamp = cache.GetByName("Lamp"); @@ -510,7 +510,7 @@ public sealed class LoadoutTests : IDisposable Design = cache.RefOf(lamp), Origin = new Attributed(), Quality = .2f, - Roles = new List { new RoleFill { Role = "lens", Quality = .9f } } + Roles = new List { new RoleFill { Role = "lens", Quality = .15f } } }); var rareLot = items.Lots.Add(new Lot { @@ -524,7 +524,7 @@ public sealed class LoadoutTests : IDisposable var withRole = new PerformanceStat { Min = 0, Max = 1, Terms = { new StatTerm { Source = StatSource.Quality, Exponent = 1, Role = "lens" } } }; var noRole = new PerformanceStat { Min = 0, Max = 1, Terms = { new StatTerm { Source = StatSource.Quality, Exponent = 1 } } }; - Assert.Equal(.9f, items.Evaluate(withRole, instance), 3); + Assert.Equal(.15f, items.Evaluate(withRole, instance), 3); Assert.Equal(.2f, items.Evaluate(noRole, instance), 3); Assert.Equal(.2f, items.GetTier(instance).tier.Quality, 3); Assert.Equal(.5f, items.GetTier(rareInstance).tier.Quality, 3); diff --git a/tests/Aetheria.Shared.Tests/LockOnScenarioTests.cs b/tests/Aetheria.Shared.Tests/LockOnScenarioTests.cs index 0e326d7b0..603a6bea0 100644 --- a/tests/Aetheria.Shared.Tests/LockOnScenarioTests.cs +++ b/tests/Aetheria.Shared.Tests/LockOnScenarioTests.cs @@ -33,8 +33,25 @@ public sealed partial class RunStartTests var settled = hostile.PassiveInfo(player.Position.xz, player.Visibility); Assert.True(settled <= threshold, $"the hostile would settle at {settled} on the player, above the detection threshold {threshold}: staged inside its sight"); + var (lockedAt, bearingError, stagedDrift, strengths) = StepToLock(arena, player, hostile, toPlayer); + Assert.True(lockedAt >= 0, "the hostile never locked the player within 600 ticks of .1 s"); + Assert.True(bearingError <= StampedBearingLimit, $"the warning points at the hostile where it was when stamped, {bearingError} deg off (the hostile is {stagedDrift} deg off its staged line at the lock)"); + Assert.True(strengths.First() < strengths.Last(), $"the lock tightens: Strength went {strengths.First()} to {strengths.Last()}"); + } + + // Float error in the stamped pose and the normalizations, not a lag budget: the warning is exact for the tick it was stamped in. + const float StampedBearingLimit = .05f; + + // The paint is stamped from the poses at the end of one tick and published at the start of the next (an entity's inbox + // publishes a tick late, so the order of the entities does not matter), so the warning first read is measured against + // the poses of the tick before: where the hostile was when the paint was stamped, not where it is now. Steps up to 600 + // ticks of .1 s, and 40 past the lock. lockedAt is -1 when it never locks. + private static (int lockedAt, float bearingError, float stagedDrift, List strengths) StepToLock(Zone arena, Ship player, Entity hostile, CultMath.float2 toPlayer) + { + var hostileThen = hostile.Position.xz; + var playerThen = player.Position.xz; var lockedAt = -1; - var bearingDot = 0f; + var bearingError = 0f; var stagedDrift = 0f; var strengths = new List(); for (var tick = 0; tick < 600 && (lockedAt < 0 || tick < lockedAt + 40); tick++) @@ -45,16 +62,40 @@ public sealed partial class RunStartTests if (lockedAt < 0) { lockedAt = tick; - // The warning points at the hostile where it is at the lock; the hostile has left the staged line by then. - var live = normalize(hostile.Position.xz - player.Position.xz); - bearingDot = dot(normalize(paint.Bearing), live); - stagedDrift = degrees(acos(clamp(dot(live, -toPlayer), -1f, 1f))); + var stamped = normalize(hostileThen - playerThen); + bearingError = degrees(acos(clamp(dot(normalize(paint.Bearing), stamped), -1f, 1f))); + stagedDrift = degrees(acos(clamp(dot(stamped, -toPlayer), -1f, 1f))); } strengths.Add(paint.Strength); } + hostileThen = hostile.Position.xz; + playerThen = player.Position.xz; + } + return (lockedAt, bearingError, stagedDrift, strengths); + } + + // The staged inputs, each moved 1%: the lock and the warning's bearing still hold, so the scenario does not rest on the + // exact numbers it was written with. Kills: a pass geometry that only the staged numbers reach. + [Fact] + public void LockOnHoldsUnderOnePercentOfEachStagedInput() + { + var at = LockOn.HostileAt; + var variants = new (string what, LockOn scenario)[] + { + ("staged", new LockOn()), + ("x +1%", new LockOn(float2(at.x * 1.01f, at.y), .6f)), ("x -1%", new LockOn(float2(at.x * .99f, at.y), .6f)), + ("y +1%", new LockOn(float2(at.x, at.y * 1.01f), .6f)), ("y -1%", new LockOn(float2(at.x, at.y * .99f), .6f)), + ("quality +1%", new LockOn(at, .6f * 1.01f)), ("quality -1%", new LockOn(at, .6f * .99f)) + }; + foreach (var (what, scenario) in variants) + { + var (_, arena, staged, failures) = Launch(scenario, Inputs(() => GalaxySeed)); + Assert.True(failures.Count == 0, $"{what}: {string.Join("; ", failures)}"); + var hostile = Assert.Single(staged.Entities); + arena.Update(.1f); + var (lockedAt, bearingError, _, _) = StepToLock(arena, staged.Player, hostile, normalize(staged.Player.Position.xz - hostile.Position.xz)); + Assert.True(lockedAt >= 0, $"{what}: the hostile never locked the player within 600 ticks"); + Assert.True(bearingError <= StampedBearingLimit, $"{what}: the warning is {bearingError} deg off the pose it was stamped from"); } - Assert.True(lockedAt >= 0, "the hostile never locked the player within 600 ticks of .1 s"); - Assert.True(bearingDot >= cos(radians(.5f)), $"the warning points at the hostile where it is (the hostile is {stagedDrift} deg off its staged line at the lock)"); - Assert.True(strengths.First() < strengths.Last(), $"the lock tightens: Strength went {strengths.First()} to {strengths.Last()}"); } } diff --git a/tests/Aetheria.Shared.Tests/LockWarningTests.cs b/tests/Aetheria.Shared.Tests/LockWarningTests.cs index 18b068e63..1ed414bb6 100644 --- a/tests/Aetheria.Shared.Tests/LockWarningTests.cs +++ b/tests/Aetheria.Shared.Tests/LockWarningTests.cs @@ -43,7 +43,7 @@ public sealed class LockWarningTests : IDisposable _items = new ItemManager(_openCache, ledger, new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, diff --git a/tests/Aetheria.Shared.Tests/LootTests.cs b/tests/Aetheria.Shared.Tests/LootTests.cs index 4aef9ff25..f0b52f4ce 100644 --- a/tests/Aetheria.Shared.Tests/LootTests.cs +++ b/tests/Aetheria.Shared.Tests/LootTests.cs @@ -66,7 +66,7 @@ public sealed class LootTests : IDisposable var settings = new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, FiringArc = 170, CommitHorizon = .5f, SchematicCellSize = 1f, diff --git a/tests/Aetheria.Shared.Tests/MineTests.cs b/tests/Aetheria.Shared.Tests/MineTests.cs index ddb805206..a2deeb5cf 100644 --- a/tests/Aetheria.Shared.Tests/MineTests.cs +++ b/tests/Aetheria.Shared.Tests/MineTests.cs @@ -72,7 +72,7 @@ public sealed class MineTests : IDisposable var settings = new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, FiringArc = 170, CommitHorizon = .5f, SchematicCellSize = 2f, diff --git a/tests/Aetheria.Shared.Tests/MiningCut1Tests.cs b/tests/Aetheria.Shared.Tests/MiningCut1Tests.cs index c3700bd81..aa00d690e 100644 --- a/tests/Aetheria.Shared.Tests/MiningCut1Tests.cs +++ b/tests/Aetheria.Shared.Tests/MiningCut1Tests.cs @@ -27,7 +27,7 @@ public sealed class MiningCut1Tests : IDisposable private static GameplaySettings GameSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; diff --git a/tests/Aetheria.Shared.Tests/MiningCut2Tests.cs b/tests/Aetheria.Shared.Tests/MiningCut2Tests.cs index c05fc1f32..b484eed9f 100644 --- a/tests/Aetheria.Shared.Tests/MiningCut2Tests.cs +++ b/tests/Aetheria.Shared.Tests/MiningCut2Tests.cs @@ -31,7 +31,7 @@ public sealed class MiningCut2Tests : IDisposable private static GameplaySettings GameSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; diff --git a/tests/Aetheria.Shared.Tests/MiningCut3Tests.cs b/tests/Aetheria.Shared.Tests/MiningCut3Tests.cs index e77d6c89b..e0eefce59 100644 --- a/tests/Aetheria.Shared.Tests/MiningCut3Tests.cs +++ b/tests/Aetheria.Shared.Tests/MiningCut3Tests.cs @@ -37,7 +37,7 @@ public sealed partial class MiningCut3Tests : IDisposable private static GameplaySettings GameSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), // Settings.asset's own values for the three detection tunables. VisibilityDecay = .5f, diff --git a/tests/Aetheria.Shared.Tests/PaintModeTests.cs b/tests/Aetheria.Shared.Tests/PaintModeTests.cs index 44af2dae0..02fcf71e1 100644 --- a/tests/Aetheria.Shared.Tests/PaintModeTests.cs +++ b/tests/Aetheria.Shared.Tests/PaintModeTests.cs @@ -63,7 +63,7 @@ public sealed class PaintModeTests : IDisposable _items = new ItemManager(_openCache, ledger, new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, diff --git a/tests/Aetheria.Shared.Tests/PickupTests.cs b/tests/Aetheria.Shared.Tests/PickupTests.cs index af979eea5..316c8b7b8 100644 --- a/tests/Aetheria.Shared.Tests/PickupTests.cs +++ b/tests/Aetheria.Shared.Tests/PickupTests.cs @@ -71,7 +71,7 @@ public sealed class PickupTests : IDisposable var settings = new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, FiringArc = 170, CommitHorizon = .5f, SchematicCellSize = 1f, diff --git a/tests/Aetheria.Shared.Tests/PopulatedRadiusTests.cs b/tests/Aetheria.Shared.Tests/PopulatedRadiusTests.cs index 20d6793a0..a106b217e 100644 --- a/tests/Aetheria.Shared.Tests/PopulatedRadiusTests.cs +++ b/tests/Aetheria.Shared.Tests/PopulatedRadiusTests.cs @@ -64,7 +64,7 @@ public sealed class PopulatedRadiusTests : IDisposable var items = new ItemManager(cache, new ProvenanceLedger(), new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }, _ => { }); diff --git a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs index 6805bc82e..94100844a 100644 --- a/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs +++ b/tests/Aetheria.Shared.Tests/PotentialOwnerTests.cs @@ -28,7 +28,7 @@ public sealed class PotentialOwnerTests : IDisposable var settings = new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; _items = new ItemManager(_cache, new ProvenanceLedger(), settings, _ => { }); diff --git a/tests/Aetheria.Shared.Tests/PowerBusTests.cs b/tests/Aetheria.Shared.Tests/PowerBusTests.cs index 2ab76f599..f4277b6fd 100644 --- a/tests/Aetheria.Shared.Tests/PowerBusTests.cs +++ b/tests/Aetheria.Shared.Tests/PowerBusTests.cs @@ -27,7 +27,7 @@ public sealed class PowerBusTests : IDisposable private static GameplaySettings Settings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; diff --git a/tests/Aetheria.Shared.Tests/PowerCurveTests.cs b/tests/Aetheria.Shared.Tests/PowerCurveTests.cs index 4a747dcaf..38db0eec6 100644 --- a/tests/Aetheria.Shared.Tests/PowerCurveTests.cs +++ b/tests/Aetheria.Shared.Tests/PowerCurveTests.cs @@ -36,7 +36,7 @@ public sealed class PowerCurveTests : IDisposable private static GameplaySettings Settings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; diff --git a/tests/Aetheria.Shared.Tests/PowerTierTests.cs b/tests/Aetheria.Shared.Tests/PowerTierTests.cs index ecdbd4b2d..fc947ffb1 100644 --- a/tests/Aetheria.Shared.Tests/PowerTierTests.cs +++ b/tests/Aetheria.Shared.Tests/PowerTierTests.cs @@ -27,7 +27,7 @@ public sealed class PowerTierTests : IDisposable private static GameplaySettings Settings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; diff --git a/tests/Aetheria.Shared.Tests/RoleAuthoringTests.cs b/tests/Aetheria.Shared.Tests/RoleAuthoringTests.cs index 0a17e2732..2a61cbf86 100644 --- a/tests/Aetheria.Shared.Tests/RoleAuthoringTests.cs +++ b/tests/Aetheria.Shared.Tests/RoleAuthoringTests.cs @@ -20,7 +20,7 @@ public sealed class RoleAuthoringTests : IDisposable private GameplaySettings Settings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; @@ -84,7 +84,7 @@ public sealed class RoleAuthoringTests : IDisposable public void TwoProductsOfOneDesignWithDifferentRoleMeansResolveDifferentValues() { using var cache = AetheriaStores.Open(Catalog, catalogWritable: true); - var makerRef = cache.Upsert(new Faction { Name = "Maker", ShortName = "MKR" }); + var makerRef = cache.Upsert(new Faction { Name = "Maker", ShortName = "MKR", Assembly = new AssemblyDistribution { Mean = 1f, StandardDeviation = 0 } }); var lensGear = cache.Upsert(new GearData { Name = "Lensed", Hardpoint = HardpointType.Sensors, Shape = new Shape(), Price = 10, diff --git a/tests/Aetheria.Shared.Tests/RunSaveTests.cs b/tests/Aetheria.Shared.Tests/RunSaveTests.cs index d4196b0cb..3bd075724 100644 --- a/tests/Aetheria.Shared.Tests/RunSaveTests.cs +++ b/tests/Aetheria.Shared.Tests/RunSaveTests.cs @@ -693,7 +693,7 @@ public sealed class RunSaveTests : IDisposable internal static GameplaySettings TestSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; diff --git a/tests/Aetheria.Shared.Tests/ScenarioTests.cs b/tests/Aetheria.Shared.Tests/ScenarioTests.cs index 8e435d2f0..314132459 100644 --- a/tests/Aetheria.Shared.Tests/ScenarioTests.cs +++ b/tests/Aetheria.Shared.Tests/ScenarioTests.cs @@ -291,6 +291,80 @@ public sealed partial class RunStartTests Assert.Contains("No Such Gun", Assert.Single(failures)); } + // A pilot's patrol circuit is its own draw (zone seed, agent id), not the item stream's: two arenas that differ only + // in items minted before the pilot is admitted give it the same circuit. Kills: the circuit drawn from ItemManager.Random. + [Fact] + public void APilotsPatrolCircuitDoesNotRideTheItemStream() + { + Zone Arena(int itemsMintedFirst) + { + var (_, arena, _, failures) = Launch(new Scripted(false, stage => + { + stage.Player(stage.Bare("Djinni"), float2(0, 0)); + for (var i = 0; i < itemsMintedFirst; i++) stage.Place(stage.Generated("Longinus"), float2(900 + 40 * i, 0)); + stage.Place(stage.Generated("Longinus"), float2(300, 0), stance: ScenarioStance.Hostile, piloted: true); + })); + Assert.True(failures.Count == 0, string.Join("; ", failures)); + return arena; + } + CultRecordKey[] Circuit(Zone arena) => ((PatrolOrbitsTask) Assert.Single(arena.Agents).Task).Circuit; + + // The orbit keys are fresh per galaxy, so a circuit is compared by the place of each orbit among its zone's. + int[] Places(Zone arena) => Circuit(arena).Select(key => arena.Orbits.Keys.ToList().IndexOf(key)).ToArray(); + + var plain = Arena(0); + var disturbed = Arena(3); + Assert.True(plain.Orbits.Count > 4, "the zone has orbits to choose a circuit among"); + Assert.Equal(4, Places(plain).Length); + Assert.Equal(Places(plain), Places(disturbed)); + } + + // Each pilot's circuit is keyed by its own id: three pilots admitted into one zone do not all patrol the same orbits. + // Kills: the circuit keyed by a constant. + [Fact] + public void EachPilotsPatrolCircuitIsItsOwn() + { + var (_, arena, _, failures) = Launch(new Scripted(false, stage => + { + stage.Player(stage.Bare("Djinni"), float2(0, 0)); + for (var i = 0; i < 3; i++) + stage.Place(stage.Generated("Longinus"), float2(300 + 40 * i, 0), stance: ScenarioStance.Hostile, piloted: true); + })); + Assert.True(failures.Count == 0, string.Join("; ", failures)); + var circuits = arena.Agents.Select(agent => string.Join(",", ((PatrolOrbitsTask) agent.Task).Circuit.Select(key => arena.Orbits.Keys.ToList().IndexOf(key)))).ToArray(); + Assert.Equal(3, circuits.Length); + Assert.True(circuits.Distinct().Count() > 1, "every pilot patrols the same orbits: " + string.Join(" | ", circuits)); + } + + // A fit that states its quality mints every lot it builds at it, assembly and role fills alike; the same fit without one + // draws them from the item stream, so some lot comes out otherwise. A scenario's checks rest on the first. + [Fact] + public void StagedFitMintsAtItsQuality() + { + (string design, int2 cell, ItemRotation rotation)[] slots = + { + ("Cockpit 2x2", int2(2, 6), ItemRotation.None), ("Compact Reactor", int2(2, 4), ItemRotation.None), + ("Large Drive", int2(1, 0), ItemRotation.Reversed), ("Radiator", int2(2, 2), ItemRotation.CounterClockwise) + }; + var staged = Stage(Arena(true), new Scripted(true, stage => + { + stage.Player(stage.Bare("Djinni"), float2(0, 0)); + stage.Place(stage.Fit("Longinus", .6f, slots), float2(300, 0)); + stage.Place(stage.Fit("Longinus", slots), float2(-300, 0)); + })); + IEnumerable Lots(Entity entity) => + EntitySerializer.Items(EntitySerializer.Pack(entity)).OfType().Select(_items.GetLot).Prepend(_items.GetLot(entity.Hull)); + var stated = Lots(staged.Entities[0]).ToArray(); + var drawn = Lots(staged.Entities[1]).ToArray(); + Assert.True(stated.Length > slots.Length); + Assert.All(stated, lot => + { + Assert.Equal(.6f, lot.Quality, 3); + Assert.All(lot.Roles ?? new List(), fill => Assert.Equal(.6f, fill.Quality, 3)); + }); + Assert.Contains(drawn, lot => Math.Abs(lot.Quality - .6f) > .001f); + } + // A stance holds both ways between an entity and the player. A piloted entity has exactly one agent; an unpiloted // one has none, and nothing steers it. (It is not frozen: the zone's gravity still moves it, as it moves any ship, // so the rule is observed on its steering inputs.) diff --git a/tests/Aetheria.Shared.Tests/ShieldReserveTests.cs b/tests/Aetheria.Shared.Tests/ShieldReserveTests.cs index d84519034..3bd741e57 100644 --- a/tests/Aetheria.Shared.Tests/ShieldReserveTests.cs +++ b/tests/Aetheria.Shared.Tests/ShieldReserveTests.cs @@ -32,7 +32,7 @@ public sealed class ShieldReserveTests : IDisposable private static GameplaySettings Settings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; diff --git a/tests/Aetheria.Shared.Tests/SignatureTests.cs b/tests/Aetheria.Shared.Tests/SignatureTests.cs index f1289f58a..8468ac8dd 100644 --- a/tests/Aetheria.Shared.Tests/SignatureTests.cs +++ b/tests/Aetheria.Shared.Tests/SignatureTests.cs @@ -45,7 +45,7 @@ public sealed class SignatureTests : IDisposable private GameplaySettings Settings(float visibilityDecay) => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = .1f, TargetGearInfoThreshold = .8f, diff --git a/tests/Aetheria.Shared.Tests/StatResolverTests.cs b/tests/Aetheria.Shared.Tests/StatResolverTests.cs index aefb239c1..4469eb333 100644 --- a/tests/Aetheria.Shared.Tests/StatResolverTests.cs +++ b/tests/Aetheria.Shared.Tests/StatResolverTests.cs @@ -26,7 +26,7 @@ public sealed class StatResolverTests : IDisposable private static GameplaySettings Settings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; diff --git a/tests/Aetheria.Shared.Tests/TargetingSystemTests.cs b/tests/Aetheria.Shared.Tests/TargetingSystemTests.cs index 15fa14568..cd43cd789 100644 --- a/tests/Aetheria.Shared.Tests/TargetingSystemTests.cs +++ b/tests/Aetheria.Shared.Tests/TargetingSystemTests.cs @@ -34,7 +34,7 @@ public sealed class TargetingSystemTests : IDisposable private static GameplaySettings TestSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetGearInfoThreshold = .9f, UnaidedAccuracy = .1f, diff --git a/tests/Aetheria.Shared.Tests/ThrottleLockTests.cs b/tests/Aetheria.Shared.Tests/ThrottleLockTests.cs index 8511e371a..ca0f76a97 100644 --- a/tests/Aetheria.Shared.Tests/ThrottleLockTests.cs +++ b/tests/Aetheria.Shared.Tests/ThrottleLockTests.cs @@ -24,7 +24,7 @@ public sealed class ThrottleLockTests : IDisposable private static GameplaySettings Settings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TorqueMultiplier = 1f }; diff --git a/tests/Aetheria.Shared.Tests/VapourCloudTests.cs b/tests/Aetheria.Shared.Tests/VapourCloudTests.cs index 4b55ee97e..e4d57a1cf 100644 --- a/tests/Aetheria.Shared.Tests/VapourCloudTests.cs +++ b/tests/Aetheria.Shared.Tests/VapourCloudTests.cs @@ -61,7 +61,7 @@ public sealed class VapourCloudTests : IDisposable var settings = new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp(), TargetDetectionInfoThreshold = Threshold, TargetGearInfoThreshold = .8f, TargetInfoDecay = .5f, VisibilityDecay = 0f, diff --git a/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs b/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs index f02992ff5..dada889f0 100644 --- a/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs +++ b/tests/Aetheria.Shared.Tests/ZonePlacedAtBuildTests.cs @@ -32,7 +32,7 @@ public sealed class ZonePlacedAtBuildTests : IDisposable private static GameplaySettings GameSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; diff --git a/tests/Aetheria.Shared.Tests/ZoneWorlds.cs b/tests/Aetheria.Shared.Tests/ZoneWorlds.cs index d1eec2091..f2dd4ba72 100644 --- a/tests/Aetheria.Shared.Tests/ZoneWorlds.cs +++ b/tests/Aetheria.Shared.Tests/ZoneWorlds.cs @@ -27,7 +27,7 @@ internal sealed class ZoneWorlds : IDisposable private static GameplaySettings GameSettings() => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() }; diff --git a/tools/AetherDb/AssemblyFromMakerCommand.cs b/tools/AetherDb/AssemblyFromMakerCommand.cs new file mode 100644 index 000000000..23f2cf1e2 --- /dev/null +++ b/tools/AetherDb/AssemblyFromMakerCommand.cs @@ -0,0 +1,73 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using GameCult.Caching; + +// assembly-from-maker [apply] (aetheria-release, cut assembly-from-maker; rulings quality-lean-assembly-hard-ceiling, +// quality-min-tolerance-binned-assembly): seeds each maker's final assembly from the products it sells. A faction with no +// Assembly that manufactures at least one product with roles gets Mean = the mean of those products' role means plus Margin +// (a maker assembles a little above its parts, capped at 1) and StandardDeviation = the mean of their standard deviations, +// both rounded to 2 dp. It writes only an Assembly that is null, so a value tuned in Studio survives every replay, and it +// never writes a product's Assembly. The derivation reads the products, so it replays last, after every command that adds +// products or factions. Dry run unless apply. +public static class AssemblyFromMakerCommand +{ + // How far above its part mean a maker's final assembly sits: the tolerance margin of the ceiling. + public const float Margin = .1f; + + // The assembly a maker's roled products imply: the mean over every role of every product, so a product with more roles + // weighs more. Null when there is no role to average. + public static AssemblyDistribution Derive(IEnumerable products) + { + var roles = products.SelectMany(p => p.Roles ?? new List()).ToArray(); + if (roles.Length == 0) return null; + return new AssemblyDistribution + { + Mean = (float) Math.Round(Math.Min(1, roles.Average(r => r.Mean) + Margin), 2), + StandardDeviation = (float) Math.Round(roles.Average(r => r.StandardDeviation), 2) + }; + } + + public static int Run(CultCache cache, bool apply, TextWriter output) + { + var byMaker = cache.GetAll() + .GroupBy(p => p.Manufacturer.Key) + .Select(g => (Maker: g.Key, Derived: Derive(g))) + .Where(m => m.Derived != null) + .ToDictionary(m => m.Maker, m => m.Derived); + + var changed = new List(); + foreach (var faction in cache.GetAll().OrderBy(f => f.Name, StringComparer.Ordinal)) + { + if (faction.Assembly != null || !byMaker.TryGetValue(cache.RefOf(faction).Key, out var derived)) continue; + output.WriteLine($"{faction.Name}: assembly -> {derived.Mean:0.##}±{derived.StandardDeviation:0.##}"); + faction.Assembly = derived; + changed.Add(faction); + } + + if (changed.Count == 0) + { + output.WriteLine("No changes."); + return 0; + } + + if (!apply) + { + output.WriteLine($"\nDry run. Pass \"apply\" to write {changed.Count} factions."); + return 0; + } + + foreach (var faction in changed) CultRecordRefs.Validate(faction); + cache.Commit(batch => + { + foreach (var faction in changed) batch.Upsert(typeof(Faction), faction, cache.RefOf(faction).Key); + }); + output.WriteLine($"\nWrote {changed.Count} factions in Aetheria.cc"); + return 0; + } +} diff --git a/tools/AetherDb/Program.cs b/tools/AetherDb/Program.cs index 9d4fe5251..79a6d68fa 100644 --- a/tools/AetherDb/Program.cs +++ b/tools/AetherDb/Program.cs @@ -57,9 +57,10 @@ public static class Program case "inspection-scanner": return InspectionScannerCatalog(args.Contains("apply")); case "product-lines": return ProductLinesCommand.Run(args.Skip(1).ToArray()); case "minor-power-factions": return MinorPowerFactionsCommand.Run(args.Skip(1).ToArray()); + case "assembly-from-maker": return AssemblyFromMakerCommand.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, loadout [seed], 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, field-kinds [apply], 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], product-lines weapons|minor-powers|gear [apply], doctrine-catalog [apply]"); + Console.WriteLine("commands: census, factions, station-fit, hardpoint-fit, loadout [seed], 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, field-kinds [apply], 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], product-lines weapons|minor-powers|gear [apply], doctrine-catalog [apply], assembly-from-maker [apply]"); return 1; } } @@ -557,7 +558,7 @@ public static class Program Console.WriteLine($" zone radius curve {zones.ZoneRadius?.Minimum}-{zones.ZoneRadius?.Maximum} exponent {zones.ZoneRadius?.Exponent}"); Console.WriteLine($" sub zone count {zones.SubZoneCount?.Minimum}-{zones.SubZoneCount?.Maximum} exponent {zones.SubZoneCount?.Exponent}"); Console.WriteLine($"gameplay: weapon groups {gameplay.WeaponGroupCount}, shutdown performance {gameplay.DefaultEntitySettings?.ShutdownPerformance}"); - Console.WriteLine($" tiers: {string.Join(", ", (gameplay.Tiers ?? new RarityTier[0]).Select(t => $"{t.Name} q{t.Quality} r{t.Rarity}"))}"); + Console.WriteLine($" tiers: {string.Join(", ", (gameplay.Tiers ?? new RarityTier[0]).Select(t => $"{t.Name} q{t.Quality}"))}"); Console.WriteLine($" price modifier {gameplay.QualityPriceModifier?.Minimum}-{gameplay.QualityPriceModifier?.Maximum} exponent {gameplay.QualityPriceModifier?.Exponent}"); // Assert counts, not non-null: an empty array reads as populated and would make every number a fixture @@ -792,7 +793,7 @@ public static class Program var settings = new GameplaySettings { DefaultEntitySettings = new EntitySettings(), - Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, + Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Color = new float3(1, 1, 1) } }, QualityPriceModifier = new ExponentialLerp() };