range-falloff: rewrite only stale records; EffectiveRange joins the Range role; fixture fixes

EffectiveRange takes Range's role in the roles maps; the lock weapon's array
header grows to 37 with the weapon base's new keys; the AI test builds its
gun's effective range in the encounter fixture. Not yet verified.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-14 02:44:45 +02:00
commit 6025009b24
3 changed files with 17 additions and 12 deletions

View file

@ -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<PerformanceStat>(ref reader, EmissionWire).Min);
Assert.Equal(3f, JObject.Parse(JsonConvert.SerializeObject(new LauncherData { InterceptFactor = Const(3) }))["interceptFactor"].ToObject<PerformanceStat>().Min);

View file

@ -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<CombatState>(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

View file

@ -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<string, string> BallisticWeaponRoles = new Dictionary<string, string>
{
["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<string, string> EnergyWeaponRoles = new Dictionary<string, string>
{
["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.");