Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Enemy move playback: five follow-ups (return glide in the cap, report once, held card stops its clip, dead Finish, focus test) (Refs #3004) (#3065)

Eyal Golanbc153710d967
diff --git a/changelog.d/e21-3004-playback-followups.md b/changelog.d/e21-3004-playback-followups.md
new file mode 100644
index 000000000..38199b0b6
--- /dev/null
+++ b/changelog.d/e21-3004-playback-followups.md
@@ -0,0 +1,6 @@
+### Fixed
+
+- The enemy moves after End turn now take at most 12 seconds with the camera's glide back to your view included,
+ not 12 seconds before it (Refs #3004). While they play, a held decision card's AI illustration stops, and plays
+ again when the card comes back. End turn pressed again while they play, on a turn with nothing to play, opens the
+ turn report once, for the new turn, and marks the attacked hexes for that turn only.
diff --git a/unity/Assets/Scripts/UI/EnemyTurnPlayback.cs b/unity/Assets/Scripts/UI/EnemyTurnPlayback.cs
index 388f23235..bc80740c9 100644
--- a/unity/Assets/Scripts/UI/EnemyTurnPlayback.cs
+++ b/unity/Assets/Scripts/UI/EnemyTurnPlayback.cs
@@ -101,7 +101,7 @@ namespace Statecraft.Game.UI
bridge.Changed += onChanged;
}
- /// <summary>True while the beats play (from <see cref="Start"/> to the end, Skip or Finish).</summary>
+ /// <summary>True while the beats play (from <see cref="Start"/> to the end, or Skip).</summary>
public bool Active { get; private set; }
/// <summary>True from End turn until the playback starts: the tokens are held and the report waits.</summary>
public bool Pending => pending;
@@ -190,9 +190,6 @@ namespace Statecraft.Game.UI
return true;
}
- /// <summary>As <see cref="Skip"/>: End turn again, or the UI rebuilt (a language switch).</summary>
- public void Finish() => Skip();
-
/// <summary>Another game (New Game, a load): its tokens are drawn where they stand, and its camera is its own.</summary>
void Drop() => Stop();
diff --git a/unity/Assets/Scripts/UI/EventCardPresenter.cs b/unity/Assets/Scripts/UI/EventCardPresenter.cs
index f0adf08c0..44d0ceed9 100644
--- a/unity/Assets/Scripts/UI/EventCardPresenter.cs
+++ b/unity/Assets/Scripts/UI/EventCardPresenter.cs
@@ -287,7 +287,7 @@ namespace Statecraft.Game.UI
var price = answer == null || ending ? null : bridge.Price(answer);
var unpaid = answer != null && !ending && !bridge.CanPay(answer);
endTurn?.EnableInClassList(EndTurnWaitingClass, !hiddenInCapture && unpaid);
- if (Shown == null || Collapsed) video?.Stop();
+ if (Shown == null || Collapsed || heldForPlayback) video?.Stop(); // held (#3004): it plays again when the card is back
if (Shown == null) { clip = null; clipAlt = null; ShowPhoto(null); return; }
var e = Shown;
var date = EventSystem.FillDate(e, s.Date);
@@ -513,7 +513,7 @@ namespace Statecraft.Game.UI
/// of the photograph's credit; off, or when the clip fails, the photograph and its credit come back.</summary>
void ApplyIllustration()
{
- var offered = clip != null && PhotoAlt != null && !Collapsed;
+ var offered = clip != null && PhotoAlt != null && !Collapsed && !heldForPlayback;
illustrationSwitch.style.display = offered ? DisplayStyle.Flex : DisplayStyle.None;
if (offered && illustration)
{
diff --git a/unity/Assets/Scripts/UI/TurnReportPresenter.cs b/unity/Assets/Scripts/UI/TurnReportPresenter.cs
index 3621ce588..8b7989d12 100644
--- a/unity/Assets/Scripts/UI/TurnReportPresenter.cs
+++ b/unity/Assets/Scripts/UI/TurnReportPresenter.cs
@@ -139,6 +139,9 @@ namespace Statecraft.Game.UI
{
if (held || !wantsShow || nav.Current != null) return;
wantsShow = false;
+ // #3004: the hold can end inside End turn (End turn again mid-playback, on a turn with no moves to play), after
+ // the step and before TurnEnded: the report shown here is the new turn's, so TurnEnded finds it reported.
+ seen = bridge.Session.Last ?? seen;
try { Show(); }
catch (Exception e) { UnityEngine.Debug.LogException(e); Hide(); }
}
diff --git a/unity/Assets/Scripts/UI/UnitBeats.cs b/unity/Assets/Scripts/UI/UnitBeats.cs
index c41591e43..b9291a541 100644
--- a/unity/Assets/Scripts/UI/UnitBeats.cs
+++ b/unity/Assets/Scripts/UI/UnitBeats.cs
@@ -229,9 +229,12 @@ namespace Statecraft.Game.UI
return n;
}
- /// <summary>The pans and dwells at full pace (Q3), then, if the whole passes Cap, each pan and dwell shrunk by the
- /// same share of the way to its minimum, so the replay is exactly Cap long; the slides never shrink. With at most
- /// MaxBeats beats the minimums sum to well under Cap (8 x 1.05 s at the most), so the cap is always met.</summary>
+ /// <summary>The pans and dwells at full pace (Q3), then, if the whole passes Cap less the return glide, each pan and
+ /// dwell shrunk by the same share of the way to its minimum, so the beats are exactly that long; the slides never
+ /// shrink. The camera's glide back to the player's view after the last beat (EnemyTurnPlayback.Next) is at most PanMax
+ /// (CameraGlide.Seconds), so the whole playback, return included, stays within Cap (#3004). With at most MaxBeats
+ /// beats the minimums with their slides sum to at most Cap - PanMax (one kept attack beat, 1.05 s, and seven folded
+ /// beats that slide and fight, 1.45 s each), so the cap is always met.</summary>
static void Pace(List<UnitBeat> beats)
{
float slides = 0f, full = 0f, least = 0f;
@@ -246,8 +249,9 @@ namespace Statecraft.Game.UI
full += b.Pan + b.Dwell;
least += MinPan(b) + MinDwell(b);
}
- if (slides + full <= Timing.Cap || full <= least) return;
- float share = Math.Max(0f, (Timing.Cap - slides - least) / (full - least));
+ const float beatsCap = Timing.Cap - Timing.PanMax; // the return glide's longest is left for it
+ if (slides + full <= beatsCap || full <= least) return;
+ float share = Math.Max(0f, (beatsCap - slides - least) / (full - least));
foreach (var b in beats)
{
b.Pan = MinPan(b) + share * (b.Pan - MinPan(b));
diff --git a/unity/Assets/Tests/EditMode/DecisionCardTests.cs b/unity/Assets/Tests/EditMode/DecisionCardTests.cs
index c88ff8cb4..b52b806f9 100644
--- a/unity/Assets/Tests/EditMode/DecisionCardTests.cs
+++ b/unity/Assets/Tests/EditMode/DecisionCardTests.cs
@@ -300,6 +300,28 @@ public class DecisionCardTests
Assert.AreSame(r.CardElement, r.Focused, "with the keyboard focus");
}
+ /// <summary>#3004 item 5: the same, with no screen opened while the card is held, so the refocus when the hold ends is
+ /// tested on its own (HeldForPlayback's setter forgets the card was focused; the case above also passes through a
+ /// cover's close, which does that too).</summary>
+ [UnityTest]
+ public IEnumerator ACardHeldWithNoScreenOpenedComesBackWithTheFocus([Values(false, true)] bool hebrew)
+ {
+ using var r = new Rig(1920, 1080, "law_of_return", text: hebrew ? He : Text);
+ yield return Frames(4);
+ Assert.AreSame(r.CardElement, r.Focused, "precondition: the open card has the focus");
+ var endTurn = r.Root.Q<Button>("end-turn");
+ endTurn.Focus(); // End turn pressed from the keyboard
+ r.Card.HeldForPlayback = true;
+ yield return Frames(3);
+ Assert.IsFalse(r.Shows("event-card"), "precondition: held out of view");
+ endTurn.Focus();
+ Assert.AreSame(endTurn, r.Focused, "precondition");
+ r.Card.HeldForPlayback = false;
+ yield return Frames(3);
+ Assert.IsTrue(r.Shows("event-card"), "the moves ended: the card is back");
+ Assert.AreSame(r.CardElement, r.Focused, "with the keyboard focus");
+ }
+
[UnityTest]
public IEnumerator AnOpenEventDoesNotTakeTheFocusBack()
{
diff --git a/unity/Assets/Tests/EditMode/EnemyPlaybackUiTests.cs b/unity/Assets/Tests/EditMode/EnemyPlaybackUiTests.cs
index 6e9e0d926..c891c2cc3 100644
--- a/unity/Assets/Tests/EditMode/EnemyPlaybackUiTests.cs
+++ b/unity/Assets/Tests/EditMode/EnemyPlaybackUiTests.cs
@@ -300,6 +300,31 @@ public class EnemyPlaybackUiTests
Assert.AreEqual(1, held.Count(h => !h));
}
+ /// <summary>#3004 item 2: End turn pressed again while the moves play, on a turn with no moves to play (here the switch
+ /// is off, the same path: EnemyTurnPlayback.Stepped ends the old playback with the hold let go before the bridge raises
+ /// TurnEnded). The report opens once, for the new turn: Showing never fires with the previous turn.</summary>
+ [Test]
+ public void EndTurnMidPlaybackWithNoMovesToPlayShowsTheReportOnceForTheNewTurn()
+ {
+ var extra = Fakes.Move(911, 0, 0, 1, 0, side: "egypt"); // the first turn has a move to play, whatever the sim did
+ using var k = new Kit(En, (s, o) => { var r = s.EndTurn(o); return new StepResult(r.State, r.Why.Append(extra).ToArray(), r.Rejected); });
+ var shown = new List<StepResult?>();
+ k.Report.Showing += r => shown.Add(r);
+ k.Bridge.EndTurn();
+ var first = k.Bridge.Session.Last;
+ k.Playback.Tick(0.05f);
+ Assert.IsTrue(k.Playback.Active, "fixture: the first turn's moves play");
+ Assert.IsEmpty(shown, "precondition: the report waits for them");
+ k.On = false; // nothing plays for the next turn
+ k.Bridge.EndTurn();
+ var latest = k.Bridge.Session.Last;
+ Assert.AreNotSame(first, latest, "fixture: a second turn ran");
+ Assert.IsFalse(k.Playback.Active || k.Playback.Pending, "fixture: no moves play for it");
+ Assert.IsTrue(k.Report.IsOpen, "the report opens at once");
+ Assert.AreEqual(1, shown.Count, "once, not first for the previous turn and again for the new one");
+ Assert.AreSame(latest, shown[0], "for the new turn");
+ }
+
/// <summary>End turn pressed with a screen open (the top bar stays enabled under a side screen): End turn closes the
/// screen, as it did before the playback, so the moves play on the open map and the report opens when they end,
/// without waiting for the player to close a screen they never asked to keep (#2967 review 9 November, S1).</summary>
diff --git a/unity/Assets/Tests/EditMode/EnemyTurnPlaybackTests.cs b/unity/Assets/Tests/EditMode/EnemyTurnPlaybackTests.cs
index 1fedc5cf2..6440b63c2 100644
--- a/unity/Assets/Tests/EditMode/EnemyTurnPlaybackTests.cs
+++ b/unity/Assets/Tests/EditMode/EnemyTurnPlaybackTests.cs
@@ -423,4 +423,26 @@ public class EnemyTurnPlaybackTests
Assert.AreEqual(0, k.Camera.Settles);
CollectionAssert.AreEqual(new[] { 901, 902, 903 }, k.Map.Released.ToArray());
}
+
+ /// <summary>Q3 (owner, 2 November 2026): "a 12 s cap on the whole playback". The whole playback is the beats and the
+ /// camera's glide back to the player's view after them: an overlong turn (eight attacks far apart, each off screen, the
+ /// player's view far from the last one, so the return glide is the longest pan) ends within the cap.</summary>
+ [Test]
+ public void AnOverlongTurnEndsWithinTheCapReturnGlideIncluded()
+ {
+ var fights = Enumerable.Range(0, UnitBeats.Timing.MaxBeats)
+ .Select(i => Engagement(i * 30, 0, new[] { 921 + i }, new[] { 941 + i })).ToArray();
+ using var k = new Kit(Step(fights));
+ k.Bridge.EndTurn();
+ Assert.IsTrue(k.Playback.Active, "fixture: the moves play");
+ Assert.AreEqual(UnitBeats.Timing.MaxBeats, k.Playback.Count, "fixture: no fold");
+ const float dt = 0.001f;
+ int ticks = k.RunOut(dt, 40000);
+ // Each phase (a pan, an act, the return) ends on the tick that passes its length, so it may run a tick or two over
+ // (with the float sum of the ticks): at most 2 x MaxBeats + 1 phases, well under 0.1 s at this tick. The glide back
+ // is up to Timing.PanMax (0.8 s) long, so a cap that leaves it out fails by far more.
+ Assert.LessOrEqual(ticks * dt, UnitBeats.Timing.Cap + 0.1f,
+ "the beats and the glide back together stay within the cap");
+ Assert.Less(Vector3.Distance(new Vector3(-5000f, 0f, -5000f), k.Camera.LookAt), 1f, "fixture: the camera glided back");
+ }
}
diff --git a/unity/Assets/Tests/EditMode/EventVideoTests.cs b/unity/Assets/Tests/EditMode/EventVideoTests.cs
index 85630e154..cfe29750e 100644
--- a/unity/Assets/Tests/EditMode/EventVideoTests.cs
+++ b/unity/Assets/Tests/EditMode/EventVideoTests.cs
@@ -237,6 +237,27 @@ public class EventVideoTests
Assert.AreEqual("Illustration", r.Switch.text);
}
+ /// <summary>#3004 item 3: while End turn's enemy playback holds the card out of view (HeldForPlayback; owner, 8 November
+ /// 2026: "Hide it, bring back (Recommended)"), its AI clip stops; when the card comes back the clip plays again (from its
+ /// start), as the player left the switch.</summary>
+ [UnityTest]
+ public IEnumerator AHeldCardStopsItsIllustrationAndPlaysItAgainWhenItComesBack()
+ {
+ LogAssert.ignoreFailingMessages = true; // the edit-mode VideoPlayer may log while it prepares
+ using var r = new Rig("law_of_return", From(Rows));
+ yield return Frames(4);
+ Press(r.Switch);
+ yield return Frames(2);
+ Assert.IsTrue(r.Card.IllustrationShown, "precondition: the clip plays");
+ r.Card.HeldForPlayback = true;
+ yield return Frames(2);
+ Assert.IsFalse(r.Card.IllustrationShown, "held out of view: the clip is stopped");
+ r.Card.HeldForPlayback = false;
+ yield return Frames(2);
+ Assert.IsTrue(r.Card.IllustrationShown, "back in view: the clip plays again");
+ Assert.AreEqual("Photograph", r.Switch.text, "the switch is still on");
+ }
+
[UnityTest]
public IEnumerator TabReachesTheSwitchAfterTheOptionsAndHide()
{
diff --git a/unity/Assets/Tests/EditMode/UnitBeatsTests.cs b/unity/Assets/Tests/EditMode/UnitBeatsTests.cs
index 5a5be467a..010105c13 100644
--- a/unity/Assets/Tests/EditMode/UnitBeatsTests.cs
+++ b/unity/Assets/Tests/EditMode/UnitBeatsTests.cs
@@ -162,7 +162,7 @@ public class UnitBeatsTests
folded.Moves.Select(m => m.Unit).ToArray(), "every remaining unit, in the sim's order");
Assert.AreEqual(0f, folded.Pan, "a folded beat moves no camera");
CollectionAssert.AreEqual(Enumerable.Range(1, 20).ToArray(), Movers(beats).ToArray(), "each unit exactly once");
- Assert.LessOrEqual(UnitBeats.Total(beats), UnitBeats.Timing.Cap + 1e-4f);
+ Assert.LessOrEqual(UnitBeats.Total(beats), UnitBeats.Timing.Cap - UnitBeats.Timing.PanMax + 1e-4f, "the return glide fits in the cap too");
foreach (var b in beats)
{
if (!b.Folded) Assert.GreaterOrEqual(b.Pan, UnitBeats.Timing.MinPan - 1e-5f);
@@ -179,7 +179,10 @@ public class UnitBeatsTests
Assert.AreEqual(UnitBeats.Timing.MaxBeats, beats.Count, "fixture: no fold");
Assert.Greater(UnitBeats.Timing.MaxBeats * (UnitBeats.Timing.PanMax + UnitBeats.Timing.AttackMax), UnitBeats.Timing.Cap,
"fixture: at full pacing the turn would pass the cap");
- Assert.AreEqual(UnitBeats.Timing.Cap, UnitBeats.Total(beats), 1e-3f, "shrunk to the cap, no further");
+ // #3004 item 1: the return glide to the player's view (EnemyTurnPlayback.Next, CameraGlide.Seconds) is at most PanMax,
+ // so the beats fit in Cap - PanMax and the whole playback, return included, stays within the cap.
+ Assert.AreEqual(UnitBeats.Timing.Cap - UnitBeats.Timing.PanMax, UnitBeats.Total(beats), 1e-3f,
+ "shrunk to the cap less the return glide, no further");
foreach (var b in beats)
{
Assert.That(b.Pan, NUnit.Framework.Is.InRange(UnitBeats.Timing.MinPan, UnitBeats.Timing.PanMax));
@@ -235,7 +238,7 @@ public class UnitBeatsTests
Movers(beats).ToArray(), "side by side, each in the sim's order");
Assert.IsTrue(beats.All(b => b.Moves.All(m => r.Why.First(w => w.Key == WhyKeys.UnitMoved && w.Units[0].Id == m.Unit).Units[0].Side == b.Side)),
"no beat mixes sides");
- Assert.LessOrEqual(UnitBeats.Total(beats), UnitBeats.Timing.Cap + 1e-4f);
+ Assert.LessOrEqual(UnitBeats.Total(beats), UnitBeats.Timing.Cap - UnitBeats.Timing.PanMax + 1e-4f, "the return glide fits in the cap too");
var attacks = r.Why.Count(w => w.Key == WhyKeys.Engagement && w.EnemyOrder == Combat.Attack);
Assert.AreEqual(attacks, beats.Count(b => b.Kind == BeatKind.Attack && !b.Folded) + beats.Where(b => b.Folded).Sum(b => b.Engagements),
"every enemy engagement once");
@@ -288,6 +291,6 @@ public class UnitBeatsTests
CollectionAssert.AreEqual(Enumerable.Range(1, 22).ToArray(), Movers(beats).ToArray(), "each unit once, side by side");
var folded = beats.Where(b => b.Folded).Select(b => b.Side).ToArray();
CollectionAssert.AreEqual(new[] { "egypt", "syria", "iraq" }, folded, "one folded beat per side past the cut");
- Assert.LessOrEqual(UnitBeats.Total(beats), UnitBeats.Timing.Cap + 1e-4f);
+ Assert.LessOrEqual(UnitBeats.Total(beats), UnitBeats.Timing.Cap - UnitBeats.Timing.PanMax + 1e-4f, "the return glide fits in the cap too");
}
}