A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
feat(sim): a live month snapshot for a Historical ledger game (#1725 PR 7, Refs #1716) (#2970)
Eyal Golan8a9c2e5156f9
diff --git a/changelog.d/1725-pr7-month-snapshot.md b/changelog.d/1725-pr7-month-snapshot.mdnew file mode 100644index 000000000..69a814732--- /dev/null+++ b/changelog.d/1725-pr7-month-snapshot.md@@ -0,0 +1,4 @@+- GDD 0.3 starting population (Refs #1725, Refs #1716): the inactive dark start's Historical ledger can now give the+ month's frozen opening snapshot, its living records and its farmed fields, as the synthetic month the fixtures use,+ so Food, harvest and Industry income can later read one snapshot a turn. Building it changes nothing. No turn takes+ it yet, so there is no change in the game.diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex 226dbcc81..f8dda23f9 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -452,7 +452,7 @@ R-FOOD-001: Food is a national stock of whole units (`GameState.Food`); one unitR-FOOD-002: In step 7 the nation eats the turn's need from the stock as far as it goes: the stock stops at 0, and the rest is the unmet share, kept in the state with the need (Q-POOL-5, decided 15 October 2026). Then a monthly import brings the stock back to `cover_months` of the need, unless foreign currency is exhausted (the `fx_crisis` situation at the turn's start), when nothing is imported (Q-POOL-4, decided 15 October 2026). Imports are already paid for in foreign currency per head (`imports_per_capita_per_year`), so they are not charged again. In the GDD loop the crisis cuts the imports, not `food_supply` directly: `fx_crisis_food_per_year` acts in the legacy loop only.-For R-FOOD-001 and R-FOOD-002 under gdd-0.3 with an initialized population ledger (#2470), the need is the month's: one ration for each living own population id in the month's frozen opening snapshot (the #1716 synthetic month context, `OpeningPeople`), whatever its status or assignment (idle, at work, teaching, on a course, travelling, serving, in reception or held by the enemy), each id once and in any storage order, so a ledger change before step 7 (a combat loss, an arrival) does not move that month's need. The live ledger is reconciled first, so an invalid one moves no Food. The settlement after it is the one above: the stock stops at 0, `FoodNeed` and `FoodUnmet` record that need, and the import refills to `cover_months` of it unless the foreign-currency crisis is on. Counting changes no id, status or assignment. Legacy and gdd-0.1 keep the aggregate head count. Counting a captured own soldier is the owner's decision (5 November 2026, the recommended option, [recorded on #2678](https://github.com/eyalgolan/statecraft-israel/pull/2678#issuecomment-6652800885) as "Captured own-population records do eat the national ration"), the reading of `docs/gdd/balance.md` `population.food_per_turn` ("Food per own population unit, every status"); the ledger's head count (`TotalPeople`) already includes them. No turn reaches this yet: only synthetic fixtures create a month context, and without one an initialized ledger is refused (R-POP-002).+For R-FOOD-001 and R-FOOD-002 under gdd-0.3 with an initialized population ledger (#2470), the need is the month's: one ration for each living own population id in the month's frozen opening snapshot (the #1716 synthetic month context, `OpeningPeople`), whatever its status or assignment (idle, at work, teaching, on a course, travelling, serving, in reception or held by the enemy), each id once and in any storage order, so a ledger change before step 7 (a combat loss, an arrival) does not move that month's need. The live ledger is reconciled first, so an invalid one moves no Food. The settlement after it is the one above: the stock stops at 0, `FoodNeed` and `FoodUnmet` record that need, and the import refills to `cover_months` of it unless the foreign-currency crisis is on. Counting changes no id, status or assignment. Legacy and gdd-0.1 keep the aggregate head count. Counting a captured own soldier is the owner's decision (5 November 2026, the recommended option, [recorded on #2678](https://github.com/eyalgolan/statecraft-israel/pull/2678#issuecomment-6652800885) as "Captured own-population records do eat the national ration"), the reading of `docs/gdd/balance.md` `population.food_per_turn` ("Food per own population unit, every status"); the ledger's head count (`TotalPeople`) already includes them. A game with an initialized Historical ledger (the dark start) has a live month snapshot (#1725 PR 7, `Gdd03SyntheticMonthContext.CreateLive`): its opening people are the ledger's living own records, in id order, and its facility entries are the ledger's bound Work targets that are authored fields (`field/q,r`), in ordinal order, each available at the freeze with `field.slots` capacity; its month ordinal is the turn (`GameState.Turn`). It is built from the state as it stands, every check before anything is built, and writes nothing (the state hash and the ledger's canonical text are unchanged); a synthetic or Open ledger and an aggregate game are refused, as is a ledger with a Work, Course, Reception or Teaching target that is not a field. Owner, 8 November 2026, "One snapshot per turn (Recommended)": one month snapshot is taken at the start of the turn, after the player's orders, and harvest, Industry income and Food all read it. Owner, 8 November 2026, "Yes, recheck (Recommended)": a consumer rechecks an entry against the live state before using it, so the snapshot keeps each entry's id and opening record and its availability is only an upper bound. Given the live snapshot, this month path counts the same need as given a synthetic one of the same people (`LedgerMonthSnapshotTests`). No turn takes the snapshot yet: `TurnResolver.Resolve` still refuses an initialized ledger, so the change that runs a dark turn takes it at `Resolve`'s entry; without a month an initialized ledger is still refused (R-POP-002).R-FOOD-003: `food_supply` stays the 0 to 1 level the UI, the situations and the events read (Q-POOL-3, decided 15 October 2026), with a stock term inside its effect sum: `k_food * (stock - full) / full - unmet / need`, where `full` is `cover_months` of the last need. The term is exactly 0 at a full stock, `-k_food` when the stock is empty, and the unmet share lowers it further; rationing, the other effects and event shifts act on top as before, and the level's clamp to 0..1 bounds the result. The GDD loop requires the `food_supply` indicator. The term runs on a game with an initialized Historical ledger (the dark start, R-POP-002; #1704, #1725 PR 7) as in the aggregate game: it reads only the stock, the last need and the unmet share, never a record, and the need is already the ledger's (R-FOOD-001), so no ledger record changes; a synthetic or Open ledger is still refused (R-POP-002).@@ -605,7 +605,7 @@ These contracts cover #1689 steps 1–2 and the Historical start inventory (R-POR-POP-001: Only exact `gdd-0.3` enables the population-ledger capability, independently of the broad GDD loop and Attention (R-LOOP-002/005). An immutable own-population record has a dedicated nonnegative ordinal id. Synthetic fixture inventory is ordered by source key (ordinal string comparison), then within-source ordinal. Registered arrivals allocate monotonically; only explicit combat losses remove living ids. Sources remain registered after loss, and ids are never reused. Reconciliation checks the exact created-minus-lost id set against the living ledger, not just equal totals. Status/region counts include every matching record once. The gdd-0.3 scale of a synthetic or Open fixture reads one positive Agreed integer from `population.people_per_unit` in its catalogue (currently 10,000, Open mode's scale under D2); a Historical fixture reads `rules.yaml`'s `people_per_unit` for the start day (1,000), as R-UNIT-006 does (owner, 1 November 2026, D2: "Approve all six (Recommended)", "The Historical MVP keeps main's start: census cities at 1,000 people a unit (`R-CITY-007`)"; R-POP-004); rows with a `census/`, `units_1948/` or `field/` source key are the Historical start's and are refused in any other fixture. Old identities retain the common rules scale. Missing, fractional, nonpositive, overflowing or Deferred values have no fallback, in either source.-R-POP-002: A ledger record has exactly one typed status and assignment, validated location, home and captor references, whole reception-turn ticks capped by the catalogue requirement, civilian profession-specific tier and actual-work XP, separate military qualification/combat XP, and distinct issued civilian/military equipment and paid facts. Unknown references, unresolved teacher ids, incompatible statuses/assignments, inconsistent region/hex/facility bindings, invalid progress/tiers and duplicate issued-item ownership are refused before mutation. Moves and atomic status/location/assignment transitions retain identity/history. Capture retains home context without inventing a prison hex or refunding equipment. Ledger changes never touch resources, causes, RNG or Attention. Initialization is internal and fixture-only; initialized ledger fixtures refuse aggregate Simulation commands and turns. The dark start (#1725 PR 5) is the internal, fixture-only `Simulation.NewGame` overload that initializes the Historical ledger (R-POP-004) in place before `Pools.Init`: `Pools.Init` then reads the ledger's need, one ration for each living own population id (R-FOOD-001, #2470), after the ledger reconciles, and `StartingForces.Init` places the forces once each own starting formation's strength is its ledger soldiers, refusing otherwise. Both read only a ledger initialized with mode Historical, the dark start's; a synthetic or Open ledger is refused by both, as by the other aggregate systems, with the state unchanged. An aggregate system whose own rule says it runs on that Historical ledger (#1725 PR 7: civilian upkeep, R-MONEY-002, the first, and food_supply's stock term, R-FOOD-003; training, R-TRAIN-001 to R-TRAIN-004) also reads only that ledger; a synthetic or Open ledger is still refused by it. Prisoners.Take and Prisoners.Upkeep are such systems (#1710, R-POW-001, R-POW-002, R-POW-005): a capture turns the surrendered formation's serving records into captives with their captor and home, all or nothing, and records no loss. `EventSystem.Trigger` still refuses a ledger, so a dark start fires no opening event; the public `NewGame` is unchanged. The step-7 Food settlement given a month's synthetic context is another exception to that refusal: it reads its need from that month's frozen snapshot (R-FOOD-002, #2470). Old identities refuse ledger mutation. Prices, progression awards, return destinations, tool lock-in and captive-equipment outcomes remain with their owning issues. A craftsman's tier is novice, apprentice or expert (R-CRAFT-003); a farmer's or pioneer's is novice, trained or veteran.+R-POP-002: A ledger record has exactly one typed status and assignment, validated location, home and captor references, whole reception-turn ticks capped by the catalogue requirement, civilian profession-specific tier and actual-work XP, separate military qualification/combat XP, and distinct issued civilian/military equipment and paid facts. Unknown references, unresolved teacher ids, incompatible statuses/assignments, inconsistent region/hex/facility bindings, invalid progress/tiers and duplicate issued-item ownership are refused before mutation. Moves and atomic status/location/assignment transitions retain identity/history. Capture retains home context without inventing a prison hex or refunding equipment. Ledger changes never touch resources, causes, RNG or Attention. Initialization is internal and fixture-only; initialized ledger fixtures refuse aggregate Simulation commands and turns. The dark start (#1725 PR 5) is the internal, fixture-only `Simulation.NewGame` overload that initializes the Historical ledger (R-POP-004) in place before `Pools.Init`: `Pools.Init` then reads the ledger's need, one ration for each living own population id (R-FOOD-001, #2470), after the ledger reconciles, and `StartingForces.Init` places the forces once each own starting formation's strength is its ledger soldiers, refusing otherwise. Both read only a ledger initialized with mode Historical, the dark start's; a synthetic or Open ledger is refused by both, as by the other aggregate systems, with the state unchanged. An aggregate system whose own rule says it runs on that Historical ledger (#1725 PR 7: civilian upkeep, R-MONEY-002, the first, and food_supply's stock term, R-FOOD-003; training, R-TRAIN-001 to R-TRAIN-004) also reads only that ledger; a synthetic or Open ledger is still refused by it. Prisoners.Take and Prisoners.Upkeep are such systems (#1710, R-POW-001, R-POW-002, R-POW-005): a capture turns the surrendered formation's serving records into captives with their captor and home, all or nothing, and records no loss. `EventSystem.Trigger` still refuses a ledger, so a dark start fires no opening event; the public `NewGame` is unchanged. The step-7 Food settlement given a month's synthetic context is another exception to that refusal: it reads its need from that month's frozen snapshot (R-FOOD-002, #2470). The live month snapshot (`Gdd03SyntheticMonthContext.CreateLive`, #1725 PR 7; owner, 8 November 2026, "One snapshot per turn (Recommended)") reads only a ledger initialized with mode Historical and changes no record; a synthetic or Open ledger and an aggregate game are refused (R-FOOD-002). Old identities refuse ledger mutation. Prices, progression awards, return destinations, tool lock-in and captive-equipment outcomes remain with their owning issues. A craftsman's tier is novice, apprentice or expert (R-CRAFT-003); a farmer's or pioneer's is novice, trained or veteran.R-POP-003: Clone copies all ledger containers; immutable records and frozen bindings may be shared. The canonical writer emits a gdd-0.3-only section ordered by numeric population id, with fixed field order, stable machine tokens, invariant integer formatting and length-prefixed reference strings. It covers every record/assignment/equipment/reference field, binding, creation/loss provenance and allocator even after the last combat loss. Legacy/gdd-0.1 emit no ledger section or allocator marker. A location's optional city (a `regions.yaml` member location of its region that is a census city of `cities.yaml` or one of that region's field hosts, where R-POP-004 houses own people: a settlement hosts only F19 and F20, owner, 7 November 2026, #1689: "These two only (Recommended)"; any other, including a locality, a `sites.yaml` id or a map location, is refused when a fixture is created, naming the city and the region, R-POP-002) is written after its other fields as `|city=` with a length-prefixed id, only when set, as R-UNIT-002's `|home=` is, so a location without a city keeps its canonical text and hash. R-SAVE-001/002 still govern identity mismatch refusal and replay: no ledger snapshot or new command syntax is added in this foundation, and fixture injection is not replay evidence. Existing unpublished schema-4 draft hashes change; no migration promise is made.diff --git a/sim/Statecraft.Sim.Tests/LedgerMonthSnapshotTests.cs b/sim/Statecraft.Sim.Tests/LedgerMonthSnapshotTests.csnew file mode 100644index 000000000..9b70a52db--- /dev/null+++ b/sim/Statecraft.Sim.Tests/LedgerMonthSnapshotTests.cs@@ -0,0 +1,135 @@+using Statecraft.Sim;++/// <summary>#1725 PR 7 (#1716): the live month snapshot of a game with an initialized Historical ledger,+/// <c>Gdd03SyntheticMonthContext.CreateLive</c>. Owner, 8 November 2026, "One snapshot per turn (Recommended)": one month+/// snapshot is taken at the start of the turn, after the player's orders, and harvest, Industry income and Food all read+/// it. "Yes, recheck (Recommended)": a consumer rechecks an entry against the live state before using it, so the+/// snapshot keeps each entry's id and opening record. These tests build the snapshot only; no turn takes one yet.</summary>+public class LedgerMonthSnapshotTests+{+ static Content Gdd03() => HistoricalPopulationTests.Real(true);++ static GameState Dark(Content c) => Simulation.NewGame(c, 1, Mode.Historical, darkStart: true);++ static string Ledger(GameState s) => string.Join("\n", s.PopulationLedger.Canonical());++ // The synthetic month the field fixtures build for the same people: every authored field available, one slot each.+ static Gdd03SyntheticMonthContext Synthetic(Content c, GameState s) => Gdd03SyntheticMonthContext.CreateSynthetic(+ SaveGame.Gdd03Ruleset, s.Turn, s.PopulationLedger.Units,+ Gdd03FieldFixture.Fields(c).Select(f => new Gdd03SyntheticFacilitySnapshot(f.Id, true, 1)),+ Array.Empty<Gdd03SyntheticHousingSnapshot>(), Array.Empty<Gdd03SyntheticPendingEntry>());++ // #1716, R-FOOD-002 (#2470): the snapshot holds every living own record of the ledger once, in id order, with its+ // opening record; the facility entries are the ledger's bound field Work targets, in ordinal order, so each farmer+ // on a field is work-eligible (an upper bound: the consumer rechecks it).+ [Fact]+ public void TheSnapshotHoldsEveryLivingOwnRecordOnce()+ {+ var c = Gdd03();+ var s = Dark(c);+ var month = Gdd03SyntheticMonthContext.CreateLive(c, s);+ var units = s.PopulationLedger.Units;+ Assert.True(units.Count > 0);+ Assert.Equal(units.Select(u => u.Id), month.OpeningPeople.Select(p => p.Id));+ Assert.Equal(units, month.OpeningPeople);+ Assert.Equal(units.Count, Pools.Rations(month.OpeningPeople));+ Assert.Equal(s.Turn, month.MonthOrdinal);+ var fields = units.Where(u => u.Assignment.Kind == PopulationAssignmentKind.Work).Select(u => u.Assignment.Target!)+ .Distinct(StringComparer.Ordinal).OrderBy(x => x, StringComparer.Ordinal).ToList();+ Assert.NotEmpty(fields);+ Assert.All(fields, f => Assert.StartsWith("field/", f));+ Assert.Equal(fields, month.Facilities.Select(f => f.Id));+ Assert.All(month.Facilities, f => Assert.True(f.AvailableAtMonthFreeze && f.OpeningCapacity == 1));+ Assert.Equal(units.Where(u => u.Assignment.Kind == PopulationAssignmentKind.Work).Select(u => u.Id), month.WorkEligibleIds);+ Assert.Empty(month.CourseEligibleIds); Assert.Empty(month.ReceptionEligibleIds);+ Assert.Empty(month.Housing); Assert.Empty(month.PendingEntries);+ }++ // #2470: "a ledger change before step 7 (a combat loss, an arrival) does not move that month's need". The snapshot is+ // frozen: a later loss or arrival changes the live ledger, not the snapshot. "Yes, recheck (Recommended)": the lost+ // record's id is still in the snapshot, so a consumer can find it gone from the live ledger.+ [Fact]+ public void TheSnapshotIsFrozenAgainstALaterLossOrArrival()+ {+ var c = Gdd03();+ var s = LedgerArrivalsTests.Fixture(c);+ var month = Gdd03SyntheticMonthContext.CreateLive(c, s);+ var ids = month.OpeningPeople.Select(p => p.Id).ToList();+ var soldier = s.PopulationLedger.Units.First(u => u.Status == PopulationStatus.ActiveSoldier).Id;++ s.PopulationLedger.RegisterCombatLoss(soldier, "test/loss");+ var r = c.RulesAt(LedgerArrivalsTests.From).Mvp!;+ Cities.Arrive(c, s, r, LedgerArrivalsTests.To, new List<Cause>());++ Assert.True(LedgerArrivalsTests.Arrived(s).Count > 0);+ Assert.NotEqual(ids, s.PopulationLedger.Units.Select(u => u.Id));+ Assert.Equal(ids, month.OpeningPeople.Select(p => p.Id));+ Assert.Contains(month.OpeningPeople, p => p.Id == soldier);+ Assert.DoesNotContain(s.PopulationLedger.Units, u => u.Id == soldier);+ Assert.Equal(ids.Count, Pools.Rations(month.OpeningPeople));+ }++ // Read-only: building the snapshot changes neither the state's hash nor the ledger's canonical text.+ [Fact]+ public void BuildingTheSnapshotChangesNothing()+ {+ var c = Gdd03();+ var s = Dark(c);+ var hash = s.Hash(); var ledger = Ledger(s); var described = s.Describe();+ Gdd03SyntheticMonthContext.CreateLive(c, s);+ Assert.Equal(hash, s.Hash());+ Assert.Equal(ledger, Ledger(s));+ Assert.Equal(described, s.Describe());+ }++ // Determinism: two builds, and a build on a clone, are equal entry for entry.+ [Fact]+ public void TwoBuildsAreEqual()+ {+ var c = Gdd03();+ var s = Dark(c);+ var a = Gdd03SyntheticMonthContext.CreateLive(c, s);+ var b = Gdd03SyntheticMonthContext.CreateLive(c, s.Clone());+ Assert.Equal(a.MonthOrdinal, b.MonthOrdinal);+ Assert.Equal(a.OpeningPeople, b.OpeningPeople);+ Assert.Equal(a.Facilities.Select(f => (f.Id, f.AvailableAtMonthFreeze, f.OpeningCapacity)),+ b.Facilities.Select(f => (f.Id, f.AvailableAtMonthFreeze, f.OpeningCapacity)));+ Assert.Equal(a.WorkEligibleIds, b.WorkEligibleIds);+ }++ // R-POP-002: only an initialized Historical ledger has a live snapshot. An Open ledger, a synthetic one (no mode) and+ // an aggregate game are refused before anything is built, with the state unchanged.+ [Theory]+ [InlineData("open")] [InlineData("synthetic")] [InlineData("aggregate")]+ public void AnOpenSyntheticOrAggregateGameIsRefused(string kind)+ {+ var c = kind == "aggregate" ? Gdd03() : PopulationLedgerTests.Content();+ var s = kind == "aggregate" ? Simulation.NewGame(c, 1, Mode.Historical)+ : PopulationLedger.CreateFixture(c, PopulationLedgerTests.Bindings(),+ new[] { new PopulationInventoryRow("fixture", 0, PopulationLedgerTests.Person()) }, mode: kind == "open" ? Mode.Open : null);+ Assert.False(s.PopulationLedger.IsHistorical);+ var hash = s.Hash();+ Assert.Throws<NotSupportedException>(() => Gdd03SyntheticMonthContext.CreateLive(c, s));+ Assert.Equal(hash, s.Hash());+ }++ // R-FOOD-002 (#2470): Pools.Consume's month overload computes the same need, stock and causes given this live snapshot+ // as given the synthetic one of the same people.+ [Fact]+ public void ConsumeReadsTheLiveSnapshotAsTheSyntheticOne()+ {+ var c = Gdd03();+ var live = Dark(c); live.Food = 10;+ var synthetic = live.Clone();+ var r = c.RulesAt(live.Date).Mvp!;+ var liveWhy = new List<Cause>(); var syntheticWhy = new List<Cause>();++ Pools.Consume(c, live, r, Gdd03SyntheticMonthContext.CreateLive(c, live), liveWhy);+ Pools.Consume(c, synthetic, r, Synthetic(c, synthetic), syntheticWhy);++ Assert.Equal(live.PopulationLedger.Units.Count, live.FoodNeed);+ Assert.Equal((synthetic.Food, synthetic.FoodNeed, synthetic.FoodUnmet), (live.Food, live.FoodNeed, live.FoodUnmet));+ Assert.Equal(syntheticWhy.Select(x => (x.Key, x.Delta, x.Message)), liveWhy.Select(x => (x.Key, x.Delta, x.Message)));+ Assert.Equal(synthetic.Hash(), live.Hash());+ }+}diff --git a/sim/Statecraft.Sim/Gdd03SyntheticMonthContext.cs b/sim/Statecraft.Sim/Gdd03SyntheticMonthContext.csindex 02b1194e2..3fae2c01d 100644--- a/sim/Statecraft.Sim/Gdd03SyntheticMonthContext.cs+++ b/sim/Statecraft.Sim/Gdd03SyntheticMonthContext.cs@@ -5,7 +5,8 @@ using System.Linq;namespace Statecraft.Sim{- /// <summary>Synthetic #1716 contract, test fixtures only. Not a live-state adapter.+ /// <summary>Synthetic #1716 contract, built by test fixtures (<see cref="CreateSynthetic"/>) and, for a game with an+ /// initialized Historical ledger, by <see cref="CreateLive"/> (#1725 PR 7), which no turn calls yet./// GDD 605277df docs/gdd/loop-switch.md:17-39, except its pre-arrival residents: housing effects count residents after/// the step's arrivals (27M-15, owner, 1 November 2026), which an opening snapshot cannot hold, so it holds none./// Frozen eligibility is only an upper bound: future consumers must recheck survival,@@ -85,6 +86,35 @@ namespace Statecraft.Simpending.OrderBy(e => e.Key, StringComparer.Ordinal).ToArray());}+ /// <summary>#1725 PR 7 (#1716): the month's frozen opening snapshot of a game with an initialized Historical ledger.+ /// Owner, 8 November 2026, "One snapshot per turn (Recommended)": one month snapshot is taken at the start of the+ /// turn, after the player's orders, and harvest, Industry income and Food all read it. The opening people are the+ /// ledger's living own records (<see cref="PopulationLedger.Units"/>), in id order; the facility entries are the+ /// ledger's bound Work targets that are authored fields (Gdd03FieldFixture ids,+ /// field/q,r), in ordinal order, each available at the freeze with `field.slots`+ /// capacity. Owner, 8 November 2026, "Yes, recheck (Recommended)": that availability is only an upper bound, and a+ /// consumer rechecks an entry (its id and opening record are kept) against the live state before using it. The+ /// month ordinal is the turn (<see cref="GameState.Turn"/>). Every check comes before anything is built, and it+ /// writes nothing: the state, its hash and the ledger are unchanged. A synthetic or Open ledger, an aggregate game+ /// and any other content are refused (R-POP-002); so is a ledger with a Work, Course, Reception or Teaching target+ /// that is not a field, whose entry no ruling defines yet (<see cref="CreateSynthetic"/>'s inventory check).</summary>+ internal static Gdd03SyntheticMonthContext CreateLive(Content content, GameState state)+ {+ if (content == null) throw new ArgumentNullException(nameof(content));+ if (state == null) throw new ArgumentNullException(nameof(state));+ var ledger = state.PopulationLedger;+ if (!content.UsesPopulationLedger || !ledger.IsInitialized || !ledger.IsHistorical)+ throw new NotSupportedException("A live month snapshot needs an initialized Historical gdd-0.3 population ledger (R-POP-002).");+ ledger.Reconcile();+ var slots = Gdd03FieldRates.FromCatalogue(content.Gdd03Balance+ ?? throw new ContentException(Gdd03BalanceCatalogue.FileName, "values.field.slots", "required under gdd-0.3")).SlotsPerField;+ var authored = new HashSet<string>(Gdd03FieldFixture.Fields(content).Select(f => f.Id), StringComparer.Ordinal);+ var fields = ledger.Bindings.Targets.Where(t => t.Kind == PopulationAssignmentKind.Work && authored.Contains(t.Id))+ .Select(t => new Gdd03SyntheticFacilitySnapshot(t.Id, true, slots)).ToArray();+ return CreateSynthetic(SaveGame.Gdd03Ruleset, state.Turn, ledger.Units, fields,+ Array.Empty<Gdd03SyntheticHousingSnapshot>(), Array.Empty<Gdd03SyntheticPendingEntry>());+ }+static T[] Materialize<T>(IEnumerable<T> source) where T : class{if (source == null) throw new ArgumentNullException(nameof(source));diff --git a/sim/Statecraft.Sim/PopulationLedger.cs b/sim/Statecraft.Sim/PopulationLedger.csindex bb0a5db08..fd5b33934 100644--- a/sim/Statecraft.Sim/PopulationLedger.cs+++ b/sim/Statecraft.Sim/PopulationLedger.cs@@ -96,6 +96,8 @@ namespace Statecraft.Simnew PopulationBindings(locations, targets.Values.Concat(added), captors, qualifications);/// <summary>The bound target <paramref name="id"/>, or null.</summary>internal PopulationTarget? FindTarget(string id) => targets.TryGetValue(id, out var t) ? t : null;+ /// <summary>The bound assignment targets, in ordinal id order (#1725 PR 7, the live month snapshot reads them).</summary>+ internal IEnumerable<PopulationTarget> Targets => targets.Values;internal bool HasCaptor(string captor) => captors.Contains(captor);internal bool HasQualification(string qualification) => qualification == "" || qualifications.Contains(qualification);internal IEnumerable<string> Canonical()@@ -160,6 +162,8 @@ namespace Statecraft.Sim/// <summary>Initialized with mode Historical (the R-POP-004 start's scale). Not written to the canonical text: the/// scale it implies already is.</summary>internal bool IsHistorical { get; private set; }+ /// <summary>The ledger's frozen bindings; an uninitialized ledger is refused.</summary>+ internal PopulationBindings Bindings { get { RequireInitialized(); return bindings!; } }internal PopulationLedger(bool enabled) { this.enabled = enabled; }internal PopulationLedger Clone(){