A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Objectives: show the card of an objective completed on the game's last turn (#2547)
Eyal Golane4bdaf572fee
diff --git a/changelog.d/2536-last-turn-objective-card.md b/changelog.d/2536-last-turn-objective-card.mdnew file mode 100644index 000000000..83c45d1db--- /dev/null+++ b/changelog.d/2536-last-turn-objective-card.md@@ -0,0 +1,5 @@+### Fixed+- An objective completed on the game's last turn (or on a defeat turn) now shows its card before the end screen, as on+ any other turn, and so does an objective card an earlier turn's card limit held back; the score is unchanged and no+ other event fires then (#2536).+- A finished game saved before this change loads and shows its ending card(s) (#2536).diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex 987a5ee32..d029dcad8 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -26,7 +26,7 @@ R-LOOP-001: `systems.loop` in eras.yaml is `legacy` (the default) or `gdd`, andR-LOOP-002: The GDD state (cities, units, the next unit id, completed objectives, the score) is written into the state hash only when it is set. With the legacy loop the hash text is unchanged, byte for byte.-R-LOOP-004: The GDD game ends on the rules key `mvp.end`, 15 January 1952 in the real content (owner, 15 October 2026, D-E5: "End on 15 Jan 1952"), after 44 monthly turns. The end is a boundary the last turn reaches, like the last era's end; the game is then over (`mvp_ended`) and raises no new event. It is the same in every era, after the start and before the last era's end (so the game ends as `mvp_ended`, not `era_ended`). The eras after it stay in the repository and load (G2).+R-LOOP-004: The GDD game ends on the rules key `mvp.end`, 15 January 1952 in the real content (owner, 15 October 2026, D-E5: "End on 15 Jan 1952"), after 44 monthly turns. The end is a boundary the last turn reaches, like the last era's end; the game is then over (`mvp_ended`) and raises no new event, except the card of an objective that turn recorded, or of an earlier one whose card has not fired yet (R-OBJ-003). It is the same in every era, after the start and before the last era's end (so the game ends as `mvp_ended`, not `era_ended`). The eras after it stay in the repository and load (G2).R-LOOP-005: Every balance number of the GDD loop (all of `cities.yaml` and `unit_types.yaml`, the rules' `mvp:` block, and the GDD orders' `attention_cost`) carries the tag `# DESIGN VALUE: owner-set balance, not a historical figure` and its decision row on its own line, and `DesignValuesTests` lists every one of them: a number missing from the list, or a listed one without the tag, fails. For the separately identified gdd-0.3 ruleset, the design catalogue is `content/gdd03-balance.yaml`, transcribed from #1668 `docs/gdd/balance.md` at 605277df: one key per source key (including project and biome rows), with Agreed, Default or Deferred basis and provenance; mixed rows label their parts separately. `DesignValuesTests` checks this inventory and the basis distinctions. Deferred `start.army` remains symbol `A`: the loader refuses any numeric guess or unapproved relabelling, pending #1717 and validation of the full 65-unit partition. The catalogue does not switch either existing loop or supply production defaults; legacy/gdd-0.1 keep the preceding tagged-value contract. The rows #2115 lists, which the owner ruled on after the transcription (30 October and 1 November 2026), hold the ruling's value and their note names the ruling and its date; of them, the Open-mode start rows (D2), the transit charge and port-queue penalty (post-MVP) and the declined unpaid-upkeep deterioration are Default, not Agreed. Other post-MVP rows that the inactive fixtures read as Agreed keep that label for now (#2115). See [the catalogue mapping](../gdd03-catalogue.md) for derived/mixed bases and the six owner rulings. Under gdd-0.3, Attention is absent: no pool, price or cost-map requirement; the older tagged Attention contract remains only legacy/gdd-0.1 (#1688, part 1). For gdd-0.3, current owner: [loop-switch](../gdd/loop-switch.md).@@ -408,7 +408,7 @@ R-OBJ-001: An objective (`objectives.yaml`) names its condition, `completes_whenR-OBJ-002: Recording a standalone objective adds `objective_points + min(objective_bonus_cap, objective_bonus_per_month * monthsEarly)` to the score, once. `monthsEarly` is `max(0, monthsFromHistory)`, and `monthsFromHistory` counts calendar months from the completion's month to the reference date's month, `(y2 - y1) * 12 + (m2 - m1)`: 0 in the same month ("on time, as in history"), negative when late (owner's card wording, #379, 14 October 2026). Late costs nothing. The owner set 100 points (D-B6) and +5 a month capped at +60 (D-B2) on 14 October 2026 (#456); they are balance values and stay tunable, as `rules.yaml` design values (R-LOOP-005). R-OBJ-006 says when a multipart objective receives the same base. The rules are those of the date the turn starts from (docs/determinism.md, "Rules per era"), so a turn that ends on the next era's first day scores with the era it started in.-R-OBJ-003: An event with `objective:` is that objective's card. It is eligible only once its objective is recorded, so it fires once, at the end of the turn the objective is completed in, and never in the legacy loop. A card has exactly one option, and an objective and its card name each other (the loader checks both). An unanswered card resolves to its option without drawing from the RNG.+R-OBJ-003: An event with `objective:` is that objective's card. It is eligible only once its objective is recorded, so it fires once, at the end of the turn the objective is completed in, and never in the legacy loop. That holds on the turn that ends the game too (the dated end of R-LOOP-004, or a defeat): its objective cards, and the card of any objective recorded earlier that the soft-event cap held back (R-EVT-001), fire then, without the cap, and no other event does; and Unity shows them before the end screen (owner, 4 November 2026, #2536: "Show the card (Recommended)"). Answering one there is no order and changes nothing: the score is the one step 11 recorded. A card has exactly one option, and an objective and its card name each other (the loader checks both). An unanswered card resolves to its option without drawing from the RNG.R-OBJ-004: An objective may instead name `completes_when: { absorbed: { population_at_least, overflow_at_most, employed_at_least } }` (D-B4; owner, 18 October 2026, #738, option (a)). It holds at step 11 once the Jewish population (`GameState.TotalPopulation`, the national count as step 11 reads it, before the turn's population step) is at or above `population_at_least`, and then the cities' overflow (R-HOUSE-002), summed, is at most `overflow_at_most` of their housed people (R-HOUSE-003), summed, and their employed, summed, are at least `employed_at_least` of their civilians and craftsmen, summed (as R-CITY-005 counts them; owner, 3 November 2026, #1714: "Both rulesets (Recommended)", so gdd-0.1 and gdd-0.3 alike). Refugees waiting do not count: each turn's arrivals (step 9) wait at step 11, after housing (step 8). The gate keeps the census start values (41% employed, no overflow) from completing it on the first turn. Sums are integers, compared with the decimal share, so city order cannot change the result. An objective names exactly one kind; all three keys are required (a missing key is never read as 0), the shares are from 0 to 1 and the population above 0 (the loader). Recorded and scored as R-OBJ-001 and R-OBJ-002 say; its card follows R-OBJ-003.@@ -558,7 +558,7 @@ R-EVT-005: One sim helper, `EventSystem.OptionEffects`, lists every effect of anR-EVT-006: Among the events eligible on a turn with the same `from` (and, for objective cards, the same place in `objectives.yaml`, R-OBJ-007), an event's `order` (default 0) decides before the id (ordinal): a lower order fires first, takes a soft slot first and is shown first. With every `order` 0 the order is R-EVT-002's. `degania_defence` has `order: 1`, so One Army (`idf_founding`) opens the game and the defence of Degania comes second on the same turn (owner, 24 October 2026, #1568: "One Army first").-R-EVT-007: An event with `deported: <target>` is Deport's follow-up card for that settlement target (GDD Phase 6 PR 9, #801; Q-CARD-1 (c), owner, 18 October 2026, #783). Besides R-EVT-001, it fires only once the target's record is depopulated, which only the player's Deport does (R-CTRL-018, R-CTRL-020), so it fires at the event step of the turn that Deport resolves and never after Raid or Occupy, and a Deport of another place does not fire it; only the GDD loop records settlements, so the legacy loop never fires one. It takes no soft slot (R-EVT-001's cap of 3 does not count it), so hard anchors or other cards on that turn never push it to a later one. On the turn that ends the game no event fires at all (R-EVT-001), so a Deport on that last turn raises no card; the end report lists that card instead, and the end screen shows its title and text after the objectives (owner, 2 November 2026, #2197: "Show on the end screen (Recommended)"). A card that fired is not listed again. It has exactly one option, and, like an objective's card, it resolves to that option without an RNG draw when left unanswered (R-EVT-003). The loader refuses one whose target is not in `settlement_targets.yaml`, whose target's residents fled (Deport is refused there, so the card could never fire), that lacks the `displacement` tag (so the release gate holds it, R-GATE-001), that has more than one option, a `to` (a closed window would miss a later Deport) or `prisoners`, that is not `soft`, that opens after the game's start, that waits for anything else (`conditions`, `requires`, `site`, `objective`, a `kind` other than historical, `variants`), or that is a second card for the same place. The shipped cards, `deport_acre` and `deport_nazareth`, are `sensitivity-reviewed` (owner, 2 November 2026, #2197: "Approve both cards"); Deport stays out of play (`mvp.deport_in_play: false`).+R-EVT-007: An event with `deported: <target>` is Deport's follow-up card for that settlement target (GDD Phase 6 PR 9, #801; Q-CARD-1 (c), owner, 18 October 2026, #783). Besides R-EVT-001, it fires only once the target's record is depopulated, which only the player's Deport does (R-CTRL-018, R-CTRL-020), so it fires at the event step of the turn that Deport resolves and never after Raid or Occupy, and a Deport of another place does not fire it; only the GDD loop records settlements, so the legacy loop never fires one. It takes no soft slot (R-EVT-001's cap of 3 does not count it), so hard anchors or other cards on that turn never push it to a later one. On the turn that ends the game no event fires but the unfired cards of recorded objectives (R-LOOP-004, R-OBJ-003), so a Deport on that last turn raises no card; the end report lists that card instead, and the end screen shows its title and text after the objectives (owner, 2 November 2026, #2197: "Show on the end screen (Recommended)"). A card that fired is not listed again. It has exactly one option, and, like an objective's card, it resolves to that option without an RNG draw when left unanswered (R-EVT-003). The loader refuses one whose target is not in `settlement_targets.yaml`, whose target's residents fled (Deport is refused there, so the card could never fire), that lacks the `displacement` tag (so the release gate holds it, R-GATE-001), that has more than one option, a `to` (a closed window would miss a later Deport) or `prisoners`, that is not `soft`, that opens after the game's start, that waits for anything else (`conditions`, `requires`, `site`, `objective`, a `kind` other than historical, `variants`), or that is a second card for the same place. The shipped cards, `deport_acre` and `deport_nazareth`, are `sensitivity-reviewed` (owner, 2 November 2026, #2197: "Approve both cards"); Deport stays out of play (`mvp.deport_in_play: false`).## Alternate timelinesdiff --git a/sim/Statecraft.Sim.Tests/LastTurnObjectiveCardTests.cs b/sim/Statecraft.Sim.Tests/LastTurnObjectiveCardTests.csnew file mode 100644index 000000000..62c7fdfb8--- /dev/null+++ b/sim/Statecraft.Sim.Tests/LastTurnObjectiveCardTests.cs@@ -0,0 +1,330 @@+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++/// <summary>#2536: an objective completed on the turn that ends the game still shows its card (R-OBJ-003, R-LOOP-004; the+/// owner's choice "Show the card (Recommended)", 4 November 2026). No other event fires on that turn, and the score is the+/// one step 11 records.</summary>+public class LastTurnObjectiveCardTests+{+ static readonly Content Real = ContentLoader.Load(RealContentTests.ContentRoot());++ /// <summary>The mvp-end run's state one turn before the game's end (GoldenRun.Orders, seed 1948, Historical mode).</summary>+ static GameState BeforeTheEnd(Content c, int turnsBefore = 1)+ {+ var run = new List<GameState> { Simulation.NewGame(c, GoldenRun.Seed, Mode.Historical) };+ for (var i = 0; i < 1000; i++)+ {+ var s = run[run.Count - 1];+ var next = Simulation.Step(c, s, GoldenRun.Orders(c, s)).State;+ if (next.GameOver != null) return run[run.Count - turnsBefore];+ run.Add(next);+ }+ throw new InvalidOperationException("the run never ended");+ }++ static GameState BeforeTheEnd() => BeforeTheEnd(Real);++ /// <summary>Every segment of the Haifa to Tel Aviv rail link built, so step 11 records the railway objective (R-OBJ-005)+ /// at the end of the next turn. The mvp-end run builds none of it.</summary>+ static void BuildRailway(GameState s)+ {+ var def = Real.Corridors.Single(x => x.Id == "tlv_haifa_rail");+ s.Corridors["tlv_haifa_rail"] = new CorridorWork(def.Id, def.Segments.Select(_ => new SegmentWork(null, 0, s.Date)).ToArray());+ }++ static int Points(StepResult r, string objective) =>+ (int)r.Why.Single(w => w.Key == CauseKeys.ObjectiveCompleted && w.Target == objective).Delta;++ // R-OBJ-003, R-LOOP-004: the objective completed on the final turn (the one ending 15 January 1952) shows its card on+ // that turn, and only its card: an event otherwise eligible then stays unfired. The score is step 11's.+ [Fact]+ public void AnObjectiveCompletedOnTheLastTurnShowsItsCard()+ {+ var before = BeforeTheEnd();+ Assert.False(before.Objectives.ContainsKey("railway"), "precondition: the mvp-end run does not complete the railway");+ BuildRailway(before);+ // The road done earlier (its card shown then), so the railway is the infrastructure objective's last part and pays+ // its base (R-OBJ-006): the run has already recorded the yishuvim.+ Assert.True(Objectives.Record(Real, before, Real.RulesAt(before.Date).Mvp!, "burma_road", before.Date, new List<Cause>()));+ before.FiredEvents.Add("burma_road_complete");+ // An event open on the last turn that nothing else holds back, made unfired so it would be eligible then.+ var other = Real.Events.First(e => e.Objective == "" && e.Site == "" && e.Prisoners == "" && e.Deported == ""+ && e.Requires.Count == 0 && e.Conditions.Count == 0 && e.From <= before.Date && (e.To == null || e.To.Value > before.Date));+ before.FiredEvents.Remove(other.Id);++ var last = Simulation.Step(Real, before, Array.Empty<Command>());+ var s = last.State;+ Assert.Equal(GameOverCodes.MvpEnded, s.GameOver);+ Assert.Equal(new DateTime(1952, 1, 15), s.Date);+ Assert.Equal(new DateTime(1952, 1, 15), s.Objectives["railway"]);+ Assert.Equal(new[] { "railway_complete" }, s.PendingEvents);+ Assert.Equal(new[] { "railway_complete" }, s.FiredEvents.Except(before.FiredEvents));+ Assert.DoesNotContain(other.Id, s.FiredEvents);+ Assert.Contains(last.Why, w => w.Key == CauseKeys.EventNew && w.Target == "railway_complete");+ Assert.True(Points(last, "railway") > 0, "the objective scores");+ Assert.Equal(before.Score + Points(last, "railway"), s.Score);+ Assert.Equal(s.Score, EndReport.For(Real, s).Score);+ }++ // R-OBJ-003, R-LOOP-004: ending objective cards are not subject to the ordinary three-soft-card cap.+ // Even otherwise eligible hard-anchor and Deport cards are excluded from the ending turn.+ // The content is loaded fresh here (not Real), since this test rewrites objectives and events in memory.+ [Fact]+ public void TheEndingTurnFiresEveryObjectiveCardUncappedAndNoOtherCategory()+ {+ var c = ContentLoader.Load(RealContentTests.ContentRoot());+ var before = BeforeTheEnd(c);+ before.PendingEvents.Clear();++ var cards = new List<GameEvent>();+ foreach (var objective in c.Objectives)+ {+ // Make every real objective newly complete in step 11 of this final turn.+ objective.CompletesWhen = new ObjectiveCondition+ {+ Absorbed = new AbsorbCondition+ {+ PopulationAtLeast = 0,+ OverflowAtMost = 1m,+ EmployedAtLeast = 0m,+ },+ };+ before.Objectives.Remove(objective.Id);++ var card = c.Events.Single(e => e.Id == objective.Card);+ card.From = before.Date;+ card.To = null;+ card.Anchor = "soft";+ card.Requires.Clear();+ card.Conditions.Clear();+ before.FiredEvents.Remove(card.Id);+ cards.Add(card);+ }++ Assert.True(cards.Count >= 4, "precondition: at least four soft objective cards exercise the normal cap");+ Assert.All(cards, card => Assert.Equal("soft", card.Anchor));++ var hard = new GameEvent+ {+ Id = "fixture_ending_hard",+ Title = "Eligible hard fixture",+ Anchor = "hard",+ From = before.Date,+ Options = new List<EventOption>+ {+ new EventOption { Id = "continue", Text = "Continue" },+ },+ };+ var deport = new GameEvent+ {+ Id = "fixture_ending_deport",+ Title = "Eligible Deport fixture",+ From = before.Date,+ Deported = "acre",+ Tags = new List<string> { "displacement" },+ Options = new List<EventOption>+ {+ new EventOption { Id = "continue", Text = "Continue" },+ },+ };+ c.Events.Add(hard);+ c.Events.Add(deport);+ before.Settlements["acre"] = new SettlementControl(since: before.Date, depopulated: true);++ // Prove both excluded cards satisfy the ordinary trigger, rather than merely asserting against ineligible fixtures.+ var ordinary = before.Clone();+ EventSystem.Trigger(c, ordinary, new List<Cause>(), before.Date);+ Assert.Contains(hard.Id, ordinary.FiredEvents);+ Assert.Contains(deport.Id, ordinary.FiredEvents);++ var last = Simulation.Step(c, before, Array.Empty<Command>());+ var s = last.State;+ var expected = cards.Select(card => card.Id).ToArray();++ Assert.Equal(GameOverCodes.MvpEnded, s.GameOver);+ Assert.All(c.Objectives, objective => Assert.Equal(s.Date, s.Objectives[objective.Id]));+ Assert.Equal(expected, s.PendingEvents);+ Assert.Equal(+ expected.OrderBy(id => id, StringComparer.Ordinal),+ s.FiredEvents.Except(before.FiredEvents));+ Assert.Equal(+ expected,+ last.Why.Where(w => w.Key == CauseKeys.EventNew).Select(w => w.Target));++ Assert.DoesNotContain(hard.Id, s.FiredEvents);+ Assert.DoesNotContain(hard.Id, s.PendingEvents);+ Assert.DoesNotContain(deport.Id, s.FiredEvents);+ Assert.DoesNotContain(deport.Id, s.PendingEvents);+ }++ // R-OBJ-003, R-EVT-001, R-LOOP-004: an objective recorded on the turn before the end whose card the soft-event cap held+ // back (all objective cards are soft, and a hard card takes a slot) shows on the ending turn: there is no later turn for+ // it to wait for. Only such cards fire then, uncapped. Fresh content: the test rewrites objectives and events in memory.+ [Fact]+ public void AnObjectiveCardTheCapHeldBackShowsOnTheEndingTurn()+ {+ var c = ContentLoader.Load(RealContentTests.ContentRoot());+ var twoBefore = BeforeTheEnd(c, turnsBefore: 2);+ twoBefore.PendingEvents.Clear();++ var cards = new List<GameEvent>();+ foreach (var objective in c.Objectives)+ {+ // Every real objective completes at step 11 of the turn before the end.+ objective.CompletesWhen = new ObjectiveCondition+ {+ Absorbed = new AbsorbCondition { PopulationAtLeast = 0, OverflowAtMost = 1m, EmployedAtLeast = 0m },+ };+ twoBefore.Objectives.Remove(objective.Id);+ var card = c.Events.Single(e => e.Id == objective.Card);+ card.From = twoBefore.Date;+ card.To = null;+ card.Anchor = "soft";+ card.Requires.Clear();+ card.Conditions.Clear();+ twoBefore.FiredEvents.Remove(card.Id);+ cards.Add(card);+ }+ // A hard card on that turn takes one of the three soft slots, as reparations_vote does on the 15 December 1951 turn.+ c.Events.Add(new GameEvent+ {+ Id = "fixture_penultimate_hard",+ Title = "Hard fixture",+ Anchor = "hard",+ From = twoBefore.Date,+ Options = new List<EventOption> { new EventOption { Id = "continue", Text = "Continue" } },+ });++ var penultimate = Simulation.Step(c, twoBefore, Array.Empty<Command>()).State;+ Assert.Null(penultimate.GameOver);+ Assert.Contains("fixture_penultimate_hard", penultimate.FiredEvents);+ Assert.All(c.Objectives, objective => Assert.Equal(penultimate.Date, penultimate.Objectives[objective.Id]));+ var heldBack = cards.Where(card => !penultimate.FiredEvents.Contains(card.Id)).Select(card => card.Id).ToArray();+ Assert.True(heldBack.Length >= 2, "precondition: the cap held back at least two objective cards on the turn before the end");++ // An event open on the last turn that nothing else holds back, made unfired so it would be eligible then.+ var other = c.Events.First(e => e.Objective == "" && e.Site == "" && e.Prisoners == "" && e.Deported == ""+ && e.Requires.Count == 0 && e.Conditions.Count == 0 && e.From <= penultimate.Date+ && (e.To == null || e.To.Value > penultimate.Date));+ penultimate.FiredEvents.Remove(other.Id);++ var last = Simulation.Step(c, penultimate, Array.Empty<Command>());+ var s = last.State;+ Assert.Equal(GameOverCodes.MvpEnded, s.GameOver);+ Assert.All(c.Objectives, objective => Assert.Equal(penultimate.Date, s.Objectives[objective.Id]));+ Assert.Equal(heldBack, s.PendingEvents);+ Assert.Equal(heldBack.OrderBy(id => id, StringComparer.Ordinal), s.FiredEvents.Except(penultimate.FiredEvents));+ Assert.Equal(heldBack, last.Why.Where(w => w.Key == CauseKeys.EventNew).Select(w => w.Target));+ Assert.DoesNotContain(other.Id, s.FiredEvents);+ Assert.Equal(penultimate.Score, s.Score);+ }++ // R-LOOP-004: a game ending with no objective completed on its last turn still raises no event on that turn.+ [Fact]+ public void TheLastTurnRaisesNoOtherEvent()+ {+ var before = BeforeTheEnd();+ var other = Real.Events.First(e => e.Objective == "" && e.Site == "" && e.Prisoners == "" && e.Deported == ""+ && e.Requires.Count == 0 && e.Conditions.Count == 0 && e.From <= before.Date && (e.To == null || e.To.Value > before.Date));+ before.FiredEvents.Remove(other.Id);+ var s = Simulation.Step(Real, before, Array.Empty<Command>()).State;+ Assert.Equal(GameOverCodes.MvpEnded, s.GameOver);+ Assert.Empty(s.PendingEvents);+ Assert.DoesNotContain(other.Id, s.FiredEvents);+ }++ // R-OBJ-003, R-LOOP-004: the same on a turn the economic defeat ends (R-END-002): the card shows, nothing else fires.+ [Fact]+ public void AnObjectiveCompletedOnAnEconomicDefeatTurnShowsItsCard()+ {+ var s = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);+ s = Simulation.Step(Real, s, GoldenRun.Orders(Real, s)).State;+ s.PendingEvents.Clear();+ var r = Real.RulesAt(s.Date).Mvp!;+ s.Debt = r.DebtCeiling!.Value * 100;+ s.Food = 0;+ s.FxReserves = -1e12;+ s.ActiveSituations.Add(EconomySystem.FxCrisis);+ s.ExhaustedTurns = r.DefeatTurns!.Value - 1;+ BuildRailway(s);+ var before = s.Clone();++ var last = Simulation.Step(Real, before, Array.Empty<Command>());+ Assert.Equal(GameOverCodes.DefeatEconomy, last.State.GameOver);+ Assert.True(last.State.Objectives.ContainsKey("railway"));+ Assert.Equal(new[] { "railway_complete" }, last.State.PendingEvents);+ Assert.Equal(new[] { "railway_complete" }, last.State.FiredEvents.Except(before.FiredEvents));+ Assert.Equal(before.Score + Points(last, "railway"), last.State.Score);+ }++ /// <summary>#2536: a one-turn game over fresh content that ends on its first turn's boundary with the railway recorded+ /// then, so its card is the ending card. Returns the save as the new rules write it, and the same save with the final+ /// hash the old rules wrote (the ending card neither fired nor pending).</summary>+ static (Content c, string newSave, string oldSave) FinishedWithAnEndingCard()+ {+ var c = ContentLoader.Load(RealContentTests.ContentRoot());+ var probe = Simulation.NewGame(c, GoldenRun.Seed, Mode.Historical);+ c.Rules.Mvp!.End = Simulation.TurnEnd(c, probe);+ var objective = c.Objectives.Single(o => o.Id == "railway");+ objective.CompletesWhen = new ObjectiveCondition+ {+ Absorbed = new AbsorbCondition { PopulationAtLeast = 0, OverflowAtMost = 1m, EmployedAtLeast = 0m },+ };+ var card = c.Events.Single(e => e.Id == objective.Card);+ card.From = probe.Date;+ card.To = null;+ card.Requires.Clear();+ card.Conditions.Clear();++ var g = GameSession.New(c, GoldenRun.Seed, Mode.Historical);+ g.Step(Array.Empty<Command>());+ Assert.Equal(GameOverCodes.MvpEnded, g.State.GameOver);+ Assert.Equal(new[] { "railway_complete" }, g.State.PendingEvents);+ var old = g.State.Clone();+ old.FiredEvents.Remove("railway_complete");+ old.PendingEvents.Clear();+ var newSave = g.Save.Write();+ var endLine = "end " + g.State.Hash();+ Assert.Contains(endLine + "\n", newSave);+ return (c, newSave, newSave.Replace(endLine, "end " + old.Hash()));+ }++ // #2536: a game finished before the ending turn fired objective cards replays with its ending card added. That is the+ // only difference, so it loads with no warning (no damaged-save error), over, with the card waiting to be shown.+ [Fact]+ public void AFinishedGameSavedBeforeTheChangeLoadsAndShowsItsEndingCard()+ {+ var (c, newSave, oldSave) = FinishedWithAnEndingCard();+ Assert.NotEqual(newSave, oldSave);+ var loaded = GameSession.Load(c, oldSave, out var warnings);+ Assert.Empty(warnings);+ Assert.Equal(GameOverCodes.MvpEnded, loaded.State.GameOver);+ Assert.Equal(new[] { "railway_complete" }, loaded.State.PendingEvents);+ Assert.Contains("railway_complete", loaded.State.FiredEvents);++ GameSession.Load(c, newSave, out var current); // and a save the new rules wrote loads as before+ Assert.Empty(current);+ }++ // #2536: only that difference is accepted. Any other final hash with the same content is still the damaged-save error.+ [Fact]+ public void AnyOtherReplayDifferenceIsStillRefused()+ {+ var (c, newSave, oldSave) = FinishedWithAnEndingCard();+ var wrong = newSave.Replace(newSave.Split('\n').Single(l => l.StartsWith("end ", StringComparison.Ordinal)), "end " + new string('b', 64));+ Assert.NotEqual(newSave, wrong);+ Assert.Throws<SaveException>(() => GameSession.Load(c, wrong, out _));+ }++ // #2536: with other content the same save gives only content_changed, not replay_differs.+ [Fact]+ public void WithOtherContentAFinishedOldSaveGivesOnlyContentChanged()+ {+ var (c, _, oldSave) = FinishedWithAnEndingCard();+ c.Hash = new string('c', 64);+ GameSession.Load(c, oldSave, out var warnings);+ Assert.Equal(new[] { GameSession.ContentChanged }, warnings);+ }+}diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.csindex f35bdd22f..dbff9e020 100644--- a/sim/Statecraft.Sim/EventSystem.cs+++ b/sim/Statecraft.Sim/EventSystem.cs@@ -19,8 +19,11 @@ namespace Statecraft.Sim/// events keep the usual order./// Late fire: an event whose window overlapped the turn just played can fire after its window has ended; its/// conditions are evaluated at the end of the turn, and its text is filled at the last in-window day- /// (<see cref="FillDate"/>).</summary>- public static void Trigger(Content c, GameState s, List<Cause> why, DateTime? turnStart = null)+ /// (<see cref="FillDate"/>).+ /// <para>With <paramref name="endingTurn"/> (the turn that ended the game, R-LOOP-004) only the unfired cards of recorded+ /// objectives fire (those that turn recorded, and any an earlier turn's soft-event cap held back), all of them, uncapped+ /// (R-OBJ-003; the owner's choice "Show the card (Recommended)", 4 November 2026, #2536); no other event does.</para></summary>+ public static void Trigger(Content c, GameState s, List<Cause> why, DateTime? turnStart = null, bool endingTurn = false){PopulationLedger.RefuseAggregate(s);var start = turnStart ?? s.Date;@@ -30,6 +33,7 @@ namespace Statecraft.Sim&& (s.FiredEvents.Contains(e.Id) || s.Date < e.From)).Select(e => e.Id));var eligible = c.Events.Where(e => (quiet.Contains(e.Id) || !s.FiredEvents.Contains(e.Id) && e.From <= s.Date) && (e.To == null || start < e.To.Value))+ .Where(e => !endingTurn || EndingCard(s, e)).Where(e => Timeline.AllMet(c, s, e))// R-OBJ-003: an objective's card waits for the objective. Only the GDD loop records one, so in the legacy loop it never fires..Where(e => e.Objective == "" || s.Objectives.ContainsKey(e.Objective))@@ -58,7 +62,7 @@ namespace Statecraft.Simbool Hard(GameEvent e) => e.Anchor == "hard" && !quiet.Contains(e.Id);var hardCount = eligible.Count(Hard);var chosen = new HashSet<string>(eligible.Where(e => Hard(e) || e.Deported != "")- .Concat(eligible.Where(e => !Hard(e) && e.Deported == "").Take(Math.Max(0, MaxSoftEventsPerTurn - hardCount))).Select(e => e.Id));+ .Concat(eligible.Where(e => !Hard(e) && e.Deported == "").Take(endingTurn ? int.MaxValue : Math.Max(0, MaxSoftEventsPerTurn - hardCount))).Select(e => e.Id));foreach (var e in eligible.Where(e => chosen.Contains(e.Id))){s.FiredEvents.Add(e.Id);@@ -67,6 +71,13 @@ namespace Statecraft.Sim}}+ /// <summary>Whether <paramref name="e"/> is a card of the turn that ended the game: the card of a recorded objective, in a+ /// game that is over (R-OBJ-003, R-LOOP-004; #2536). Not only the objectives that turn recorded: a card the soft-event+ /// cap held back on an earlier turn (R-EVT-001) has no later turn to wait for. Unfired ones are the only events that+ /// fire on that turn; Unity shows them before the end screen.</summary>+ public static bool EndingCard(GameState s, GameEvent e) =>+ s.GameOver != null && e.Objective != "" && s.Objectives.ContainsKey(e.Objective);+/// <summary>The date whose office holders an event's text names: the given date, or the last in-window day/// once the window has ended (load-time coverage guarantees a holder there).</summary>public static DateTime FillDate(GameEvent e, DateTime date) => e.To.HasValue && date >= e.To.Value ? e.To.Value.AddDays(-1) : date;diff --git a/sim/Statecraft.Sim/GameSession.cs b/sim/Statecraft.Sim/GameSession.csindex 553135d0c..1cc7b053f 100644--- a/sim/Statecraft.Sim/GameSession.cs+++ b/sim/Statecraft.Sim/GameSession.cs@@ -82,7 +82,8 @@ namespace Statecraft.Sim/// same but the replay ends on a different hash (a determinism bug). Content made with other content loads with a/// warning (spec section 7), and a second warning if the replay then differs from the saved game. The warnings are/// kinds (<see cref="ContentChanged"/>, <see cref="ReplayDiffers"/>), not display text: the UI says each in the- /// player's language, as it does SaveException.Code (#637).</summary>+ /// player's language, as it does SaveException.Code (#637). A finished game whose replay differs only by the ending+ /// turn's objective cards (#2536) is not a difference: it loads with no warning.</summary>public static GameSession Load(Content c, string saveText, out IReadOnlyList<string> warnings){if (c == null) throw new ArgumentNullException(nameof(c));@@ -100,7 +101,9 @@ namespace Statecraft.Simtry { foreach (var turn in saved.Turns) { session.Step(turn); turnNo++; } }catch (SaveException) { throw; }catch (Exception e) { throw new SaveException(FormattableString.Invariant($"turn {turnNo + 1}: {e.Message}"), e); }- if (session.State.Hash() != saved.FinalHash)+ // #2536: a game finished before the ending turn fired objective cards replays with those cards added, and only+ // them: the same game, so it loads as saved, with no warning, and shows its ending card(s).+ if (session.State.Hash() != saved.FinalHash && !OnlyEndingCardsAdded(c, session.State, saved.FinalHash)){if (saved.Version < 3 && saved.Ruleset == SaveGame.GddRuleset)throw new SaveException(0, "This save was made with an earlier version of the game's rules.", SaveException.OlderRules);@@ -118,5 +121,21 @@ namespace Statecraft.Simwarnings = list;return session;}++ /// <summary>#2536: whether <paramref name="s"/>, a replayed game, differs from the saved final state only by the ending+ /// turn's objective cards (EventSystem.EndingCard), which games finished before that change never fired. Before it,+ /// a finished game had nothing pending (Delegate resolves every card before a turn, and an ended game raised no+ /// event), so taking exactly the pending cards out of both the fired and the pending lists must give the saved hash.+ /// Narrow by design: the game is over, every pending event is an ending card, and the hash matches exactly.</summary>+ static bool OnlyEndingCardsAdded(Content c, GameState s, string savedHash)+ {+ if (s.GameOver == null || s.PendingEvents.Count == 0) return false;+ if (!s.PendingEvents.All(id => c.Events.FirstOrDefault(e => e.Id == id) is GameEvent e && EventSystem.EndingCard(s, e)))+ return false;+ var before = s.Clone();+ foreach (var id in s.PendingEvents) before.FiredEvents.Remove(id);+ before.PendingEvents.Clear();+ return before.Hash() == savedHash;+ }}}diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.csindex 8469baa65..65ebe6f41 100644--- a/sim/Statecraft.Sim/Simulation.cs+++ b/sim/Statecraft.Sim/Simulation.cs@@ -80,7 +80,9 @@ namespace Statecraft.SimContentWindows.Update(c, s, turnStart);Cabinet.ExpireOnGovernmentChange(c, s, why);if (c.UsesAttention) AttentionSystem.Refill(c, s);- if (s.GameOver == null) EventSystem.Trigger(c, s, why, turnStart); // a game that just ended raises no new events+ // A game that just ended raises no new events, but the unfired cards of recorded objectives (R-LOOP-004, R-OBJ-003;+ // the owner's choice "Show the card (Recommended)", 4 November 2026, #2536).+ EventSystem.Trigger(c, s, why, turnStart, endingTurn: s.GameOver != null);return new StepResult(s, why, rejected);}diff --git a/unity/Assets/Scripts/UI/EndScreenPresenter.cs b/unity/Assets/Scripts/UI/EndScreenPresenter.csindex fa8f21a1e..2f6d3ee4c 100644--- a/unity/Assets/Scripts/UI/EndScreenPresenter.cs+++ b/unity/Assets/Scripts/UI/EndScreenPresenter.cs@@ -25,7 +25,7 @@ namespace Statecraft.Game.UIreadonly VisualElement hudRoot, screen; readonly ScrollView rows; readonly SimBridge bridge; readonly UiText text;readonly Button close, newGame; readonly Action? pressNewGame;- readonly Action<IReadOnlyList<Rejection>> onTurn; readonly Action onChanged;+ readonly Action<IReadOnlyList<Rejection>> onTurn; readonly Action onChanged, onCardsSeen;readonly EventCallback<NavigationCancelEvent> onCancel;int closedAt = -1;@@ -54,13 +54,21 @@ namespace Statecraft.Game.UI// Guarded as TurnReportPresenter's handler is: TurnEnded's later handlers include the turn's autosave.onTurn = _ =>{- try { if (bridge.State.GameOver != null) Show(); }+ // #2536: an objective's card raised on the ending turn shows first; the screen follows its answer.+ try { if (bridge.State.GameOver != null && !bridge.EndingCardWaiting) Show(); }catch (Exception e) { UnityEngine.Debug.LogException(e); Hide(); }};bridge.TurnEnded += onTurn;+ onCardsSeen = () =>+ {+ try { Show(); }+ catch (Exception e) { UnityEngine.Debug.LogException(e); Hide(); }+ };+ bridge.EndingCardsSeen += onCardsSeen;onChanged = () => { if (bridge.State.GameOver == null) Hide(); }; // a new game (New Game's second press) is not overbridge.Changed += onChanged;- if (bridge.State.GameOver != null && show) Show(); else Hide(); // a loaded or rebuilt ended game opens on its end screen+ // A loaded or rebuilt ended game opens on its end screen, after any card of its ending turn still waiting (#2536).+ if (bridge.State.GameOver != null && show && !bridge.EndingCardWaiting) Show(); else Hide();}/// <summary>True while the end screen shows.</summary>@@ -164,6 +172,7 @@ namespace Statecraft.Game.UIpublic void Dispose(){bridge.TurnEnded -= onTurn;+ bridge.EndingCardsSeen -= onCardsSeen;bridge.Changed -= onChanged;close.clicked -= OnClose;newGame.clicked -= OnNewGame;diff --git a/unity/Assets/Scripts/UI/EventCardPresenter.cs b/unity/Assets/Scripts/UI/EventCardPresenter.csindex 7eb955698..b3797a6c9 100644--- a/unity/Assets/Scripts/UI/EventCardPresenter.cs+++ b/unity/Assets/Scripts/UI/EventCardPresenter.cs@@ -227,7 +227,7 @@ namespace Statecraft.Game.UI{var c = bridge.Content; var s = bridge.State;var pending = s.PendingEvents.Select(id => c.Events.First(e => e.Id == id)).ToList();- var open = pending.Where(e => bridge.QueuedLike(new ChooseEventOption(e.Id, "")) == null).ToList();+ var open = pending.Where(e => bridge.QueuedLike(new ChooseEventOption(e.Id, "")) == null && !bridge.EndingCardSeen(e.Id)).ToList();Shown = open.FirstOrDefault();if (Shown == null) { collapsedFor = null; openedFor = null; scrolledFor = null; }if (bridge.Session != session) { session = bridge.Session; collapsedFor = null; focusedFor = null; openedFor = null; scrolledFor = null; }@@ -241,8 +241,10 @@ namespace Statecraft.Game.UI// does. When the turn's Attention left cannot pay, every option would be refused (#1034, #1043): the options are// greyed out with their price, the card says End Turn hands it to its minister, and End Turn is highlighted.var answer = Shown == null ? null : new ChooseEventOption(Shown.Id, "");- var price = answer == null ? null : bridge.Price(answer);- var unpaid = answer != null && !bridge.CanPay(answer);+ // A card on the turn that ended the game (#2536) is answered on the spot (Choose): no order, so no price.+ var ending = Shown != null && bridge.IsEndingCard(Shown.Id);+ 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) { clip = null; clipAlt = null; ShowPhoto(null); return; }@@ -548,10 +550,13 @@ namespace Statecraft.Game.UI// The bridge raises Refused (the toast shows it) or Changed (the toast clears and Render shows the next event,// which takes the focus). Answered from the keyboard with no event left, the focus goes to End Turn (#41 M1),// unless a control outside the card took it meanwhile (the opening chain's Next, as it moves on, #1323).- bridge.Queue(new ChooseEventOption(e.Id, o.Id));+ // An objective's card on the turn that ended the game (R-OBJ-003, #2536) has one option and no turn left to run+ // it: the answer only marks it seen, and the end screen follows the last one (SimBridge.SeeEndingCard).+ if (bridge.IsEndingCard(e.Id)) bridge.SeeEndingCard(e.Id);+ else bridge.Queue(new ChooseEventOption(e.Id, o.Id));var focused = hudRoot.focusController?.focusedElement as VisualElement;bool kept = focused != null && focused.panel != null && !layer.Contains(focused);- if (Shown == null && presses.ByKeyboard && !kept) FocusReturn.To(hudRoot.Q<Button>("end-turn"));+ if (Shown == null && presses.ByKeyboard && !kept && bridge.State.GameOver == null) FocusReturn.To(hudRoot.Q<Button>("end-turn")); // ended: the end screen has it}}}diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex 45600ceca..1fdd11e40 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -301,6 +301,7 @@ namespace Statecraft.Game.UIowned.Add(new Undo(() => cameraController.SetFixedNorth(oldFixedNorth)));if (keep != null) foreach (var order in keep.Queued) bridge.Queue(order); // in their order: each was within the attention leftif (keep != null) foreach (var unit in keep.Skipped) bridge.Skip(unit); // this turn's skips too: no reload, no new turn+ if (keep != null) foreach (var id in keep.EndingCardsAnswered) bridge.SeeEndingCard(id); // and the ending turn's answered cards (#2536)if (Statecraft.HexTiles.HexTilesLook.Requested()) // opt-in hex-tile map (docs/hex-tiles/README.md); presentation only{Statecraft.HexTiles.HexTilesLook.Apply(map, true);diff --git a/unity/Assets/Scripts/UI/SimBridge.cs b/unity/Assets/Scripts/UI/SimBridge.csindex 0c74892e9..5d1529dfc 100644--- a/unity/Assets/Scripts/UI/SimBridge.cs+++ b/unity/Assets/Scripts/UI/SimBridge.cs@@ -16,6 +16,7 @@ namespace Statecraft.Game.UI{readonly List<Command> deferred = new List<Command>();readonly HashSet<int> skipped = new HashSet<int>();+ readonly HashSet<string> endingCardsSeen = new HashSet<string>(StringComparer.Ordinal);public GameSession Session { get; private set; }public Content Content => Session.Content;@@ -55,6 +56,31 @@ namespace Statecraft.Game.UIpublic event Action<string>? Refused;/// <summary>A validated order was refused specifically for Attention; presentation-only advice signal.</summary>public event Action? RefusedForAttention;+ /// <summary>Raised when the player has answered the last objective card of the turn that ended the game+ /// (<see cref="SeeEndingCard"/>): the end screen shows then (#2536).</summary>+ public event Action? EndingCardsSeen;++ /// <summary>The cards of the turn that ended the game the player has answered (#2536): Settings' language switch carries+ /// them to the rebuilt bridge, as it carries Skipped.</summary>+ public IReadOnlyCollection<string> EndingCardsAnswered => endingCardsSeen;+ /// <summary>True while a card of the turn that ended the game waits: the objective cards that turn raised (R-OBJ-003,+ /// R-LOOP-004; the owner's choice "Show the card (Recommended)", 4 November 2026) show before the end screen.</summary>+ public bool EndingCardWaiting => State.PendingEvents.Any(id => IsEndingCard(id) && !endingCardsSeen.Contains(id));+ /// <summary>Whether the waiting event is a card of the turn that ended the game (EventSystem.EndingCard).</summary>+ public bool IsEndingCard(string id) => EventSystem.EndingCard(State, Content.Events.First(e => e.Id == id));+ /// <summary>Whether the player has answered this card of the turn that ended the game.</summary>+ public bool EndingCardSeen(string id) => endingCardsSeen.Contains(id);++ /// <summary>Answers a card of the turn that ended the game (#2536). An ended game runs no more turns, so the answer is+ /// no order: the card is marked seen, and once none waits <see cref="EndingCardsSeen"/> is raised. An objective's card+ /// has one option and its score is already counted (R-OBJ-003), so nothing in the state changes. Does nothing for+ /// any other event, or one that is not waiting.</summary>+ public void SeeEndingCard(string id)+ {+ if (!State.PendingEvents.Contains(id) || !IsEndingCard(id) || !endingCardsSeen.Add(id)) return;+ Notify(Changed);+ if (!EndingCardWaiting) Notify(EndingCardsSeen);+ }readonly UiText text;readonly Func<GameSession, IReadOnlyList<Command>, StepResult> step;@@ -408,7 +434,7 @@ namespace Statecraft.Game.UI{Session = session ?? throw new ArgumentNullException(nameof(session));LastBatch = Array.Empty<Command>();- deferred.Clear(); skipped.Clear();+ deferred.Clear(); skipped.Clear(); endingCardsSeen.Clear();Notify(Changed);}}diff --git a/unity/Assets/Tests/EditMode/EndScreenTests.cs b/unity/Assets/Tests/EditMode/EndScreenTests.csindex 00b4f3f9b..bffa771a5 100644--- a/unity/Assets/Tests/EditMode/EndScreenTests.cs+++ b/unity/Assets/Tests/EditMode/EndScreenTests.cs@@ -90,6 +90,142 @@ public class EndScreenTestss.GameOver = GameOverCodes.MvpEnded;}+ /// <summary>The state the turn that ends the game leaves when it completes an objective (#2536; the sim's+ /// LastTurnObjectiveCardTests): on the last day, the railway recorded that day and its card waiting, nothing else waiting.</summary>+ static void EndedWithACard(GameState s)+ {+ var r = C.RulesAt(s.Date).Mvp!;+ s.PendingEvents.Clear();+ s.Date = C.End;+ Objectives.Record(C, s, r, "railway", s.Date, new List<Cause>());+ s.FiredEvents.Add("railway_complete");+ s.PendingEvents.Add("railway_complete");+ s.GameOver = GameOverCodes.MvpEnded;+ }++ // R-OBJ-003, R-LOOP-004 (#2536; the owner's choice "Show the card (Recommended)", 4 November 2026): the card of an+ // objective completed on the turn that ended the game shows before the end screen. Its one option is no order and changes+ // nothing; answering it opens the end screen, and the card does not come back when the screens are built again.+ [Test]+ public void AnObjectiveCardOfTheEndingTurnShowsBeforeTheEndScreen()+ {+ using var k = new Kit(En, EndedWithACard);+ using var card = new EventCardPresenter(k.Ui.Root, k.Bridge, En, null);+ Assert.IsTrue(k.Bridge.EndingCardWaiting);+ Assert.IsFalse(k.End.IsOpen, "the card comes first");+ Assert.AreEqual("railway_complete", card.Shown?.Id);+ var option = k.Ui.Q<Button>("option-continue");+ Assert.IsTrue(option.enabledSelf, "its one option can be pressed");+ Assert.AreEqual(C.Events.Single(e => e.Id == "railway_complete").Options.Single().Text, option.text, "with no Attention price");+ var hash = k.Bridge.State.Hash(); var score = k.Bridge.State.Score;++ UiTestKit.Press(option);+ Assert.IsNull(card.Shown, "answered, the card goes");+ Assert.IsFalse(k.Bridge.EndingCardWaiting);+ Assert.IsTrue(k.End.IsOpen, "and the end screen follows");+ Assert.IsEmpty(k.Bridge.Queued, "the answer is no order");+ Assert.AreEqual(hash, k.Bridge.State.Hash(), "and changes nothing in the game");+ Assert.AreEqual(score, k.Bridge.State.Score, "the score is the one the turn recorded");++ k.Rebuild(He); // the language switch: the same bridge, so the answered card stays answered+ Assert.IsTrue(k.End.IsOpen);+ card.Render();+ Assert.IsNull(card.Shown);+ }++ // R-OBJ-003, R-LOOP-004 (#2536): the real autosave/load path replays an ending objective card into a new bridge.+ // The loaded card still precedes the end screen and its UI answer opens the screen, in both shipped languages.+ [TestCase(false, TestName = "AnEndingObjectiveCardSurvivesAutosaveAndLoad_English")]+ [TestCase(true, TestName = "AnEndingObjectiveCardSurvivesAutosaveAndLoad_Hebrew")]+ public void AnEndingObjectiveCardSurvivesAutosaveAndLoad(bool hebrew)+ {+ var text = hebrew ? He : En;+ var c = ContentLoader.Load(Paths.Content); // a fresh copy: the fixture below rewrites it in memory, never C++ // A one-turn fixture over a fresh copy of the real content. The objective condition is already true, while its+ // card cannot fire until step 11 records it; ending the game at that turn's boundary makes it an ending card.+ var probe = Simulation.NewGame(c, GoldenRun.Seed, Mode.Historical);+ c.Rules.Mvp!.End = Simulation.TurnEnd(c, probe);+ var objective = c.Objectives.Single(o => o.Id == "railway");+ objective.CompletesWhen = new ObjectiveCondition+ {+ Absorbed = new AbsorbCondition+ {+ PopulationAtLeast = 0,+ OverflowAtMost = 1m,+ EmployedAtLeast = 0m,+ },+ };+ var objectiveCard = c.Events.Single(e => e.Id == objective.Card);+ objectiveCard.From = probe.Date;+ objectiveCard.To = null;+ objectiveCard.Requires.Clear();+ objectiveCard.Conditions.Clear();++ var dir = Path.Combine(Path.GetTempPath(), "statecraft-ending-load-" + System.Guid.NewGuid().ToString("N"));+ try+ {+ var store = new SaveStore(dir);+ var firstBridge = new SimBridge(GameSession.New(c, GoldenRun.Seed, Mode.Historical), text);+ using (GameStart.Autosave(firstBridge, store, text))+ {+ firstBridge.EndTurn();+ Assert.AreEqual(GameOverCodes.MvpEnded, firstBridge.State.GameOver);+ Assert.AreEqual(firstBridge.State.Date, firstBridge.State.Objectives[objective.Id],+ "step 11 recorded the objective on the ending date");+ CollectionAssert.AreEqual(new[] { objectiveCard.Id }, firstBridge.State.PendingEvents,+ "the autosaved final state leaves its ending card pending");+ }++ var savedHash = firstBridge.State.Hash();+ Assert.IsTrue(File.Exists(store.AutosavePath), "the real autosave path wrote the ending turn");++ var notes = new List<string>();+ var loadedSession = GameStart.Begin(c, store, () => 1UL, notes, text, out var resumed);+ Assert.IsTrue(resumed, "launch resumed the autosave");+ CollectionAssert.IsEmpty(notes);+ Assert.AreEqual(savedHash, loadedSession.State.Hash(), "the command log replayed the saved final state");++ var loadedBridge = new SimBridge(loadedSession, text);+ using var ui = new UiTestKit();+ using var card = new EventCardPresenter(ui.Root, loadedBridge, text, null);+ using var end = new EndScreenPresenter(ui.Root, loadedBridge, text, null);++ Assert.IsTrue(loadedBridge.EndingCardWaiting);+ Assert.AreEqual(objectiveCard.Id, card.Shown?.Id);+ Assert.IsFalse(end.IsOpen, "the loaded ending card comes before the end screen");++ var option = ui.Q<Button>("option-" + objectiveCard.Options.Single().Id);+ Assert.IsTrue(option.enabledSelf);+ Assert.IsNotEmpty(option.text);+ UiTestKit.Press(option);++ Assert.IsNull(card.Shown);+ Assert.IsFalse(loadedBridge.EndingCardWaiting);+ Assert.IsTrue(end.IsOpen, "answering the loaded card through its UI button opens the end screen");+ Assert.AreEqual(text["end.title"], ui.Q<Label>("end-screen-title").text);+ Assert.AreEqual(savedHash, loadedBridge.State.Hash(), "seeing the card changes no saved simulation state");+ }+ finally+ {+ try { if (Directory.Exists(dir)) Directory.Delete(dir, true); }+ catch (IOException) { }+ }+ }++ // #2536: SeeEndingCard answers only a waiting card of the ending turn; any other event stays as it was.+ [Test]+ public void OnlyAnEndingTurnCardCanBeAnsweredThatWay()+ {+ using var k = new Kit(En, Ended); // the absorb objective recorded a month early, not on the last day+ var waiting = k.Bridge.State.PendingEvents.ToList();+ Assert.IsFalse(k.Bridge.EndingCardWaiting);+ Assert.IsTrue(k.End.IsOpen, "an ended game with no card of its ending turn opens on its end screen");+ k.Bridge.SeeEndingCard("absorb_immigrants");+ foreach (var id in waiting) k.Bridge.SeeEndingCard(id);+ CollectionAssert.IsEmpty(k.Bridge.EndingCardsAnswered);+ }+[Test]public void OpensOnGameOverAndADefeatShowsItsCause(){