From 30bcabf172852465128f04f1c0b9a32344a92a41 Mon Sep 17 00:00:00 2001 From: soul Date: Thu, 22 Oct 2026 04:31:47 +0200 Subject: [PATCH] Command seam fixes: pin Combat's release of a pulled lock, its commanded-aim pricing, and the order and count of same-step presses Co-Authored-By: Claude Opus 5.5 --- .../PilotSeamPlayerTests.cs | 90 +++++++++++++++++++ tests/Aetheria.Shared.Tests/PilotSeamTests.cs | 82 +++++++++++++++++ 2 files changed, 172 insertions(+) diff --git a/tests/Aetheria.Shared.Tests/PilotSeamPlayerTests.cs b/tests/Aetheria.Shared.Tests/PilotSeamPlayerTests.cs index 3c97f7fc9..3dc5777f4 100644 --- a/tests/Aetheria.Shared.Tests/PilotSeamPlayerTests.cs +++ b/tests/Aetheria.Shared.Tests/PilotSeamPlayerTests.cs @@ -131,6 +131,96 @@ public sealed partial class RunStartTests Assert.Equal(once.Mount, east.ResolvedAim.Mount); } + private void SeamReveal(Ship east, Ship west, out EquippedItem first, out EquippedItem second) + { + first = SeamGun(west).Item; + var one = first; + second = west.Weapons.Select(w => w.Item).First(i => i != one && i.Data.Name == one.Data.Name); + east.RecordReveal(west, first, SignatureChannel.Emission, west.ClaimOf(first)); + east.RecordReveal(west, second, SignatureChannel.Emission, west.ClaimOf(second)); + } + + private static void SeamAimEqual(AimTarget expected, AimTarget actual) + { + Assert.Equal(expected.Item, actual.Item); + Assert.Equal(expected.Mount, actual.Mount); + } + + private static bool SeamAimDiffers(AimTarget a, AimTarget b) => a.Item != b.Item || a.Mount != b.Mount; + + // Every aim-cycle press in a step cycles: two presses step the aim twice, as two direct cycles did. + [Fact] + public void CycleAimCountsEveryPress() + { + var (arena, east, west, _) = PlayerSeamTrio(); + SeamReveal(east, west, out var first, out _); + east.SetTarget(new TargetRef(west)); + Assert.True(east.TrySelectTargetItem(first)); + east.CycleAim(); + var once = east.ResolvedAim; + east.CycleAim(); + var twice = east.ResolvedAim; + Assert.True(SeamAimDiffers(once, twice), "fixture: a second cycle moves the aim on"); + + Assert.True(east.TrySelectTargetItem(first)); + east.Command.CycleAim(); + east.Command.CycleAim(); + arena.Update(SeamDt); + SeamAimEqual(twice, east.ResolvedAim); + } + + // Presses in one step apply in a fixed order, whatever order they came in: the designation, then the verb (answered + // from the designated target), then the item selection, then the aim cycles (stepping from the verb's target and the + // selected item). Each case is checked against both orders by direct calls, and fails if the two orders agree. + [Fact] + public void SameStepPressesApplyDesignationVerbSelectionCycle() + { + var (arena, east, west, third) = PlayerSeamTrio(); + SeamReveal(east, west, out var first, out _); + void Reset(Entity target) + { + east.SetTarget(target == null ? TargetRef.None : new TargetRef(target)); + Assert.True(east.TrySelectTargetItem(null)); + } + + // Next steps on from the designated west (to third), not from nothing (to west). + Reset(null); + east.Command.Verb(TargetVerb.Next); + east.Command.Designate(new TargetRef(west)); + arena.Update(SeamDt); + Assert.Same(third, east.Target.Value.Entity); + + // The cycle steps the aim on the target the verb chose. + Reset(null); + east.TargetNext(); + east.CycleAim(); + var verbThenCycle = east.ResolvedAim; + Reset(null); + east.CycleAim(); + east.TargetNext(); + Assert.True(SeamAimDiffers(verbThenCycle, east.ResolvedAim), "fixture: the verb and the cycle do not commute"); + Reset(null); + east.Command.CycleAim(); + east.Command.Verb(TargetVerb.Next); + arena.Update(SeamDt); + SeamAimEqual(verbThenCycle, east.ResolvedAim); + + // The cycle steps on from the selected item. + Reset(west); + Assert.True(east.TrySelectTargetItem(first)); + east.CycleAim(); + var selectThenCycle = east.ResolvedAim; + Reset(west); + east.CycleAim(); + Assert.True(east.TrySelectTargetItem(first)); + Assert.True(SeamAimDiffers(selectThenCycle, east.ResolvedAim), "fixture: the selection and the cycle do not commute"); + Reset(west); + east.Command.CycleAim(); + east.Command.SelectItem(first); + arena.Update(SeamDt); + SeamAimEqual(selectThenCycle, east.ResolvedAim); + } + // A trigger that counts its edges: a semi-auto fires once per Activate. private sealed class SeamTrigger : IActivatedBehavior { diff --git a/tests/Aetheria.Shared.Tests/PilotSeamTests.cs b/tests/Aetheria.Shared.Tests/PilotSeamTests.cs index 3caf0dacc..3bfeb9f42 100644 --- a/tests/Aetheria.Shared.Tests/PilotSeamTests.cs +++ b/tests/Aetheria.Shared.Tests/PilotSeamTests.cs @@ -335,6 +335,88 @@ public sealed partial class RunStartTests foreach (var launcher in ready) Assert.True(east.Command.Pulls(launcher), $"{launcher.Item.Data.Name} is pulled"); } + // Combat lets go of a lock it pulled this step (beside the groups) when the chosen group's own decision refuses it. An + // unfused lock is priced on its hit probability, which no shot clears at MinHitProbability 2, and it was never firing, + // so only the pending pull (Command.Pulls) tells Combat to release it. Breaks if Combat's release guard reads Firing + // alone (Combat.cs). + [Fact] + public void CombatReleasesALockItPulledButWillNotFire() + { + var (arena, east, west) = SeamPair(true); + east.SetIff(west, true); + west.SetIff(east, true); + var agent = arena.Agents.Single(a => a.Ship == east); + var locks = east.Weapons.OfType().ToArray(); + Assert.NotEmpty(locks); + agent.Doctrine.MinHitProbability = 2; // no unfused shot clears it + var step = 0; + for (; step < 3000 && !(SeamState(agent) is CombatState && locks.Any(l => l.IsLocked)); step++) arena.Update(SeamDt); + var launcher = locks.FirstOrDefault(l => l.IsLocked); + Assert.True(launcher != null, $"locked by step {step}"); + var gunRange = east.Weapons.Where(w => !(w is LockWeapon)).Max(w => w.Range); + var distance = launcher.MinRange + 20; + Assert.True(distance < gunRange, $"fixture: the guns reach past the launcher's minimum range ({launcher.MinRange} vs {gunRange})"); + west.Position = east.Position + distance * normalize(float3(east.Aim.x, 0, east.Aim.z)); + east.Update(SeamDt); + Assert.IsType(SeamState(agent)); + Assert.True(launcher.CanFire && !launcher.Firing, $"fixture: ready and idle (range {east.TargetRange}, lock {launcher.Lock})"); + + // Unfused, and in every group, so the chosen group decides it too. + var data = Assert.IsAssignableFrom(launcher.Item.Data); + var radius = data.BlastRadius; + try + { + data.BlastRadius = 0; + foreach (var group in east.WeaponGroups) + if (!group.weapons.Contains(launcher)) group.weapons.Add(launcher); + + agent.Update(SeamDt); + + var mine = east.Command.Triggers.Where(t => ReferenceEquals(t.Behavior, launcher)).Select(t => t.Pull).ToArray(); + Assert.True(mine.Contains(true), $"Combat pulls the ready lock: [{string.Join(",", mine)}]"); + Assert.False(east.Command.Pulls(launcher), $"and lets go of it when the group's decision refuses it: [{string.Join(",", mine)}]"); + } + finally + { + data.BlastRadius = radius; + } + } + + // Combat prices each shot on the aim it commands this step, not the applied aim (last step's). With the applied aim + // cleared and MinHitProbability between the two prices, the gun's one trigger follows the commanded price. Breaks if + // Combat drops its aim from FireControl.AgentFires (Combat.cs). + [Fact] + public void CombatPricesFireOnTheCommandedAim() + { + var (arena, east, west) = SeamPair(true); + east.SetIff(west, true); + west.SetIff(east, true); + var agent = arena.Agents.Single(a => a.Ship == east); + for (var step = 0; step < 900 && !(SeamState(agent) is CombatState); step++) arena.Update(SeamDt); + Assert.IsType(SeamState(agent)); + var revealed = SeamGun(west).Item; + east.EntityInfoGathered[west] = 1; + east.RecordReveal(west, revealed, SignatureChannel.Emission, west.ClaimOf(revealed)); + + agent.Update(SeamDt); // learn the item Combat aims at + var commanded = east.Command.Selections.LastOrDefault(); + Assert.NotNull(commanded); + east.Command.ClearOneShots(); + Assert.True(east.TrySelectTargetItem(null)); + var gun = SeamGun(east); + var pCommanded = FireControl.HitProbability(gun, east, west, AimTarget.OfItem(commanded)); + var pApplied = FireControl.HitProbability(gun, east, west); + Assert.True(abs(pCommanded - pApplied) > 1e-4f, $"fixture: the two aims price apart ({pCommanded} vs {pApplied})"); + agent.Doctrine.MinHitProbability = (pCommanded + pApplied) / 2; + var fires = pCommanded > pApplied; + if (!fires) gun.Activate(); // held, so Combat must let go of it + + agent.Update(SeamDt); + + var (_, pull) = Assert.Single(east.Command.Triggers.Where(t => ReferenceEquals(t.Behavior, gun))); + Assert.Equal(fires, pull); + } + // Pulls answers the pilot's last trigger for that behaviour this step, and nothing commanded is no pull. [Fact] public void PullsReadsTheLastTriggerForThatBehaviour()