diff --git a/tests/Aetheria.Shared.Tests/EmissionTests.cs b/tests/Aetheria.Shared.Tests/EmissionTests.cs index 1a721172a..1ff7e9fc5 100644 --- a/tests/Aetheria.Shared.Tests/EmissionTests.cs +++ b/tests/Aetheria.Shared.Tests/EmissionTests.cs @@ -291,7 +291,7 @@ public sealed partial class ContactRevealTests reader = new MessagePackReader(bytes); Assert.Equal(2, reader.ReadArrayHeader()); reader.Skip(); // the arm's union index - Assert.Equal(35, reader.ReadArrayHeader()); + Assert.Equal(37, reader.ReadArrayHeader()); // 35 and 36 are the weapon base's EffectiveRange and DamageAtMaxRange for (var slot = 0; slot < 34; slot++) reader.Skip(); Assert.Equal(3f, MessagePackSerializer.Deserialize(ref reader, EmissionWire).Min); Assert.Equal(3f, JObject.Parse(JsonConvert.SerializeObject(new LauncherData { InterceptFactor = Const(3) }))["interceptFactor"].ToObject().Min); diff --git a/tests/Aetheria.Shared.Tests/FireControlTests.cs b/tests/Aetheria.Shared.Tests/FireControlTests.cs index d05073c85..6044d1a23 100644 --- a/tests/Aetheria.Shared.Tests/FireControlTests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlTests.cs @@ -182,7 +182,7 @@ public sealed class FireControlTests : IDisposable } // A shooter with one in-range, in-arc gun, a detected target at `targetPosition`, and a Minion driving the shooter. - private (Ship shooter, Ship target, Zone zone) BuildCombatEncounter(float3 targetPosition, float projectileSpeed = 0f, bool twoTargetGuns = false) + private (Ship shooter, Ship target, Zone zone) BuildCombatEncounter(float3 targetPosition, float projectileSpeed = 0f, bool twoTargetGuns = false, float? effectiveRange = null) { var mounts = twoTargetGuns ? new[] { (ItemRotation.None, 0f), (ItemRotation.None, 0f) } : new[] { (ItemRotation.None, 0f) }; var (items, shooter, weapons) = BuildShipWithHardpoints(mounts); @@ -191,6 +191,7 @@ public sealed class FireControlTests : IDisposable weaponData.Cooldown = new PerformanceStat { Min = 1, Max = 1 }; weaponData.Range = new PerformanceStat { Min = 1000, Max = 1000 }; weaponData.MinRange = new PerformanceStat { Min = 0, Max = 0 }; + if (effectiveRange.HasValue) weaponData.EffectiveRange = new PerformanceStat { Min = effectiveRange.Value, Max = effectiveRange.Value }; weaponData.Velocity = new PerformanceStat { Min = projectileSpeed, Max = projectileSpeed }; var zone = shooter.Zone; @@ -375,17 +376,15 @@ public sealed class FireControlTests : IDisposable [Fact] public void TheAIHoldsAtItsEffectiveRange() { - var (shooter, _, zone) = BuildCombatEncounter(float3(0, 0, 10)); - var data = (InstantWeaponData) shooter.Weapons.Single().WeaponData; - data.EffectiveRange = new PerformanceStat { Min = 500, Max = 500 }; - data.DamageAtMaxRange = 0f; + var (shooter, _, zone) = BuildCombatEncounter(float3(0, 0, 10), effectiveRange: 500f); zone.Update(1f); // enters CombatState, which samples DPS over the evaluated stats + zone.Update(1f); var agent = zone.Agents.Single(); var state = typeof(Agent).GetField("_currentState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(agent); - Assert.IsType(state); + Assert.True(state is CombatState, $"the agent is in {state?.GetType().Name}"); var optimum = (float) typeof(CombatState).GetField("_optimumRange", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(state); - Assert.InRange(optimum, 500f - 1000f / 32f, 500f + 1000f / 32f); + Assert.True(optimum >= 500f - 1000f / 32f && optimum <= 500f + 1000f / 32f, $"optimum range {optimum}"); } // Ruling ew-claim-weapon-measure-ruled: no observer reads a target weapon's live state. Two unclaimed guns whose diff --git a/tools/AetherDb/Program.cs b/tools/AetherDb/Program.cs index 068e4110a..775513333 100644 --- a/tools/AetherDb/Program.cs +++ b/tools/AetherDb/Program.cs @@ -149,14 +149,14 @@ public static class Program // be authoring fiction. Fields the maps below do not mention keep generic quality; the report says why. private static readonly Dictionary BallisticWeaponRoles = new Dictionary { - ["Damage"] = "barrel", ["Range"] = "barrel", ["Velocity"] = "barrel", ["Penetration"] = "barrel", + ["Damage"] = "barrel", ["Range"] = "barrel", ["EffectiveRange"] = "barrel", ["Velocity"] = "barrel", ["Penetration"] = "barrel", ["Cooldown"] = "feed mechanism", ["Spread"] = "feed mechanism", ["Heat"] = "feed mechanism", ["Visibility"] = "feed mechanism", ["Energy"] = "feed mechanism", ["Count"] = "feed mechanism", }; private static readonly Dictionary EnergyWeaponRoles = new Dictionary { - ["Damage"] = "focusing array", ["Range"] = "focusing array", ["Velocity"] = "focusing array", + ["Damage"] = "focusing array", ["Range"] = "focusing array", ["EffectiveRange"] = "focusing array", ["Velocity"] = "focusing array", ["Penetration"] = "focusing array", ["DamageSpread"] = "focusing array", ["Energy"] = "power coupling", ["Heat"] = "power coupling", ["ChargeTime"] = "power coupling", ["ChargeEnergy"] = "power coupling", ["ChargeHeat"] = "power coupling", ["Cooldown"] = "power coupling", @@ -1077,6 +1077,10 @@ public static class Program var fraction = Option("--effective", .5f); var end = Option("--end", 0f); var db = AetherDb.Open(catalogWritable: apply); + // A record is rewritten only when what it would store differs from what is stored: that is what drops the retired + // key 7 from a record the command leaves otherwise unchanged, and what makes a second apply change no byte. + var persisted = CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(Path.Combine(db.Root, "GameData", "Aetheria.cc"))) + .Records.ToDictionary(r => r.Key, r => r.Payload); Console.WriteLine($"{"weapon",-28} {"behaviour",-20} {"range",9} {"effective",9} {"end",5}"); var changed = new List<(object Document, CultRecordKey Key)>(); @@ -1097,10 +1101,12 @@ public static class Program } Console.WriteLine($"{item.Name,-28} {weapon.GetType().Name,-20} {weapon.Range.Max,9:0.##} {(falls ? weapon.EffectiveRange.Max : float.PositiveInfinity),9:0.##} {weapon.DamageAtMaxRange,5:0.##}"); } - changed.Add((item, key)); + if (!persisted[key.Value].SequenceEqual(CultDocumentMessagePackSerialization.SerializeUntyped(item, item.GetType(), db.Cache.Registry))) + changed.Add((item, key)); } - Console.WriteLine($"\n{changed.Count} weapon records"); + Console.WriteLine($"\n{changed.Count} weapon records to rewrite"); + if (changed.Count == 0) return 0; if (!apply) { Console.WriteLine($"Dry run. Pass \"apply\" to land {changed.Count} records.");