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.

Sim: pioneer work-XP producer on the ledger (Refs #1693) (#2421)

Beri2e4bf55bcf5b
diff --git a/changelog.d/1693-pioneer-work-xp.md b/changelog.d/1693-pioneer-work-xp.md
new file mode 100644
index 000000000..b173e02a1
--- /dev/null
+++ b/changelog.d/1693-pioneer-work-xp.md
@@ -0,0 +1,5 @@
+### Changed
+- Under the gdd-0.3 rules only, the sim's test fixture of the population ledger gives a pioneer one work-experience point
+ for each turn its site or corridor segment is being built, and makes it a veteran after 9 such turns, working at the
+ catalogue's pioneer rates (Refs #1693). Idle, travelling and training turns give none and keep what it has. The
+ ledger is not yet in the game; the game players play (gdd-0.1) is unchanged.
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 6bc2de285..f4813c5f8 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -202,9 +202,9 @@ R-SITE-003: Each turn, in ordinal site id order, every site being built has one
## Veteran pioneers
-R-VET-001: Under legacy/gdd-0.1, in step 5, after its site's or segment's progress (R-COR-002), a halutz unit whose site or corridor segment is being built gains one turn of service, the turn it is built included; an idle unit gains none. At `veteran_halutz_service` turns of service it becomes a `veteran_halutz` at the end of that turn, keeping its id, hex, service and project, and a cause says so. A veteran gains no more service. A unit's service is written into the state hash only when it is not 0 (D-D9; Q-VET-1, owner, 17 October 2026, #782). A halutz or veteran can return to civilian life and keep its service or its status (R-QUAL-003). In gdd-0.3 synthetic fixtures only, the pure profession helper proposes one actual-work XP increment for a received free civilian with a matching Work assignment and completed staffed-farming evidence regardless of output or advancement, or evidence of advancing an on-site pioneer project. Adopted sources at `605277dfa511dc512562ececeb273b8393b21d35`: `docs/gdd/training.md:17`, "Farmers earn work XP only on staffed farming turns. Pioneers earn it only while advancing an on-site pioneer project."; `docs/gdd/balance.md:70`, "Work XP counts actual qualifying turns, not output or work quantity." Multiple matching results count once per evaluation; zero pioneer advancement, wrong profession/target, generic work, travel, idle, teaching and courses give none. Both novice and trained farmer/pioneer become veteran at the Agreed catalogue `profession.work_to_veteran` threshold (currently 9). Craftsmen do not use this path. The caller must use one turn-start snapshot and commit at most once at turn end; turn scheduling, authoritative evidence production and cross-call deduplication remain held. No game-loop caller is added.
+R-VET-001: Under legacy/gdd-0.1, in step 5, after its site's or segment's progress (R-COR-002), a halutz unit whose site or corridor segment is being built gains one turn of service, the turn it is built included; an idle unit gains none. At `veteran_halutz_service` turns of service it becomes a `veteran_halutz` at the end of that turn, keeping its id, hex, service and project, and a cause says so. A veteran gains no more service. A unit's service is written into the state hash only when it is not 0 (D-D9; Q-VET-1, owner, 17 October 2026, #782). A halutz or veteran can return to civilian life and keep its service or its status (R-QUAL-003). In gdd-0.3 synthetic fixtures only, the pure profession helper proposes one actual-work XP increment for a received free civilian with a matching Work assignment and completed staffed-farming evidence regardless of output or advancement, or evidence of advancing an on-site pioneer project. Adopted sources at `605277dfa511dc512562ececeb273b8393b21d35`: `docs/gdd/training.md:17`, "Farmers earn work XP only on staffed farming turns. Pioneers earn it only while advancing an on-site pioneer project."; `docs/gdd/balance.md:70`, "Work XP counts actual qualifying turns, not output or work quantity." Multiple matching results count once per evaluation; zero pioneer advancement, wrong profession/target, generic work, travel, idle, teaching and courses give none. Both novice and trained farmer/pioneer become veteran at the Agreed catalogue `profession.work_to_veteran` threshold (currently 9). Craftsmen do not use this path. The caller must use one turn-start snapshot and commit at most once at turn end; turn scheduling, authoritative evidence production and cross-call deduplication remain held. No game-loop caller is added. The fixture-only pioneer producer (`Gdd03PioneerWorkFixture.ResolveTurnEnd`, #1693) is that caller for pioneers on initialized gdd-0.3 ledger fixtures: from one turn-start state and the pioneer projects being built that turn (yishuv sites and corridor segments alike; owner, 3 November 2026, #1693 answer 5), each pioneer record at Work on one of them gives advancement evidence and its result is committed once, in ascending id, into a new state, except that a veteran's work XP is not advanced (maintainer call, not a ruling, matching the legacy veteran that gains no more service; it still works at its rate); the turn-start state is unchanged, so resolving the same snapshot twice gives one tick. Records off the job (idle, travel, course, teaching) earn nothing and keep their tier and work XP (answer 4). MVP pioneers are course-trained (answer 2). Farmer evidence waits for #1694. It has no game-loop caller until #1689's integration slice.
-R-VET-002: Under legacy/gdd-0.1, a veteran's site or corridor segment being built has `veteran_progress` turns less to go each turn, against a halutz's 1; one with that many or fewer left is built that turn. A veteran does the same pioneer work as a halutz (R-SITE-001) (D-D9; Q-VET-2, owner, 17 October 2026, #782). In gdd-0.3 synthetic fixtures only, output quotes read the turn-start tier from Agreed catalogue `pioneer.work_rate` (novice/trained/veteran: 0.75/1/1.5) or `farmer.output` (2/3/5, multiples of `field_food_per_turn`, R-FIELD-002 (owner, 1 November 2026: "Main's base x 0.3's tiers (Recommended)"; #2112); the farmer quote here and in the synthetic field evaluator is that multiple, which equals Food only while `field_food_per_turn` is 1, and `Gdd03FieldRates.FoodPerTurn` converts it). Promotion returns a separate record for the next turn, preserving identity, assignment, placement, equipment and independent military history. No project progress or farming yield is applied by the helper; absent, Deferred or malformed values fail closed without legacy fallback.
+R-VET-002: Under legacy/gdd-0.1, a veteran's site or corridor segment being built has `veteran_progress` turns less to go each turn, against a halutz's 1; one with that many or fewer left is built that turn. A veteran does the same pioneer work as a halutz (R-SITE-001) (D-D9; Q-VET-2, owner, 17 October 2026, #782). In gdd-0.3 synthetic fixtures only, output quotes read the turn-start tier from Agreed catalogue `pioneer.work_rate` (novice/trained/veteran: 0.75/1/1.5) or `farmer.output` (2/3/5, multiples of `field_food_per_turn`, R-FIELD-002 (owner, 1 November 2026: "Main's base x 0.3's tiers (Recommended)"; #2112); the farmer quote here and in the synthetic field evaluator is that multiple, which equals Food only while `field_food_per_turn` is 1, and `Gdd03FieldRates.FoodPerTurn` converts it). Promotion returns a separate record for the next turn, preserving identity, assignment, placement, equipment and independent military history. No project progress or farming yield is applied by the helper; absent, Deferred or malformed values fail closed without legacy fallback. The #1693 pioneer producer quotes each record's work with this turn-start `pioneer.work_rate`, never `veteran_progress`, and returns the quote per target, summed over the records at Work on an advancing target, without applying it to any project.
### Return to civilian life and reassignment (#1511)
@@ -224,7 +224,7 @@ R-QUAL-006: A Train order (R-TRAIN-001) takes the city's unqualified civilians f
R-QUAL-007: Attention is that of the matching existing order (owner ruling 1): `return_craftsmen` and `reassign_craftsmen` cost what `assign_workers` does (0.5), and `reassign_pioneers` and the `return_civilian` unit order cost what a unit order does (0), all design values in `rules.yaml`. The qualified counts are written into the state hash only when not 0 (`,qcraftsmen=N,qhalutz=S:S,qveterans=N` after the other city fields), so a game without them hashes as before. The saves write `retcraft CITY N`, `regcraft CITY N`, `regpioneer CITY TRACK N` and `order UNIT return_civilian`; scenarios use `return_craftsmen`, `reassign_craftsmen`, `reassign_pioneers` and `unit_order` with `order: return_civilian`.
-R-QUAL-008: Region-independent gdd-0.3 fixture helpers only (coordinator decision, 26 Oct 2026, Q5): a matching farmer/pioneer course may propose trained tier while retaining actual-work XP, veteran tier and every other record field. Cross-profession qualification is refused without mutation. This transform does not decide course eligibility, completion or release. Tools quotes read only Agreed `profession.farmer_tools` / `profession.pioneer_tools` (currently 3 / 5); no acquisition, charge, credit, refund or paid-flag change occurs. All helpers are internal and require an initialized exact-gdd-0.3 fixture. Money policy, once-only acquisition, lock-in policy, craftsman progression and production integration remain held with their owners.
+R-QUAL-008: Region-independent gdd-0.3 fixture helpers only (coordinator decision, 26 Oct 2026, Q5): a matching farmer/pioneer course may propose trained tier while retaining actual-work XP, veteran tier and every other record field. Cross-profession qualification is refused without mutation. This transform does not decide course eligibility, completion or release. Tools quotes read only Agreed `profession.farmer_tools` / `profession.pioneer_tools` (currently 3 / 5); no acquisition, charge, credit, refund or paid-flag change occurs. All helpers are internal and require an initialized exact-gdd-0.3 fixture. Money policy, once-only acquisition, lock-in policy, craftsman progression and production integration remain held with their owners. Tools stay a quote: the owner ruled the one-time tools charge post-MVP (3 November 2026, #1693 answer 1).
R-SITE-004: Every designated site has one or more kinds from a fixed list: `yishuv`, `field`, `swamp`, `military_camp` and `hakhshara` (Phase 4, Q-FIELD-1, Q-SWAMP-1, Q-CAMP-3). A pioneer action is accepted only at a site of its kind; any other is refused with the state unchanged and the Attention refunded. A yishuv site has a founding date inside the MVP's years and no other kind has one. A camp site (`military_camp` or `hakhshara`) names a city of `cities.yaml`, the city it trains for (Q-CAMP-1), and no other kind names one. The loader refuses any other row, naming the file and field.
diff --git a/sim/Statecraft.Sim.Tests/Gdd03PioneerWorkFixtureTests.cs b/sim/Statecraft.Sim.Tests/Gdd03PioneerWorkFixtureTests.cs
new file mode 100644
index 000000000..69783ca79
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/Gdd03PioneerWorkFixtureTests.cs
@@ -0,0 +1,181 @@
+using Statecraft.Sim;
+
+/// <summary>#1693 pioneer slice: the fixture-only turn-end producer that turns pioneer project advancement into work XP on
+/// the population ledger (R-VET-001, R-VET-002). Synthetic fixtures plus the Historical fixture of #2323; no game-loop
+/// caller, so Simulation.NewGame, Projects.cs and Corridors.cs are untouched. Owner answers of 3 November 2026 on #1693:
+/// no tools charge in the MVP (1), course-trained pioneers only (2), tier and work XP kept dormant off the job (4), and
+/// a corridor segment counts as a pioneer project (5).</summary>
+public class Gdd03PioneerWorkFixtureTests
+{
+ static readonly PopulationLocation Here = new PopulationLocation("fixture");
+
+ static Content Catalogue()
+ {
+ var c = PopulationLedgerTests.Content();
+ c.Gdd03Balance = ContentLoader.Load(RealContentTests.ContentRoot()).Gdd03Balance;
+ return c;
+ }
+
+ // A course-trained pioneer (answer 2) at work on a target, with reception done and an independent military history.
+ static PopulationUnit Pioneer(string target, int xp = 0, CivilianTier tier = CivilianTier.Trained, int combatXp = 0)
+ => new PopulationUnit(0, PopulationStatus.FreeCivilian, 6, Here, new PopulationAssignment(PopulationAssignmentKind.Work, target),
+ CivilianProfession.Pioneer, tier, xp, "infantry", combatXp, PopulationEquipment.None);
+
+ // Record ids follow the row order: 0, 1, 2, ...
+ static GameState State(Content c, params PopulationUnit[] people) => PopulationLedger.CreateFixture(c,
+ new PopulationBindings(new[] { Here },
+ new[] {
+ new PopulationTarget("site-a", PopulationAssignmentKind.Work, "fixture"),
+ new PopulationTarget("segment-b", PopulationAssignmentKind.Work, "fixture"),
+ new PopulationTarget("road-t", PopulationAssignmentKind.Travel, "fixture"),
+ new PopulationTarget("course-c", PopulationAssignmentKind.Course, "fixture", 3) },
+ Array.Empty<string>(), new[] { "infantry" }),
+ people.Select((p, i) => new PopulationInventoryRow("synthetic", i, p)));
+
+ static PioneerWorkTurn Resolve(Content c, GameState s, params string[] advancing)
+ => Gdd03PioneerWorkFixture.ResolveTurnEnd(c, s, advancing);
+ static GameState Turns(Content c, GameState s, int n, params string[] advancing)
+ {
+ for (int i = 0; i < n; i++) s = Resolve(c, s, advancing).State;
+ return s;
+ }
+
+ // R-VET-001, answer 5: a site and a corridor segment that advance give one tick a turn; idle, travel, a farmer and a
+ // pioneer still in reception give none and add no work, and a turn whose project does not advance gives none. One turn-start snapshot resolved twice still gives one tick.
+ [Fact]
+ public void Gdd03PioneerGainsWorkXpOnlyOnTurnsItsProjectAdvances()
+ {
+ var c = Catalogue();
+ var idle = Pioneer("site-a").WithPlacement(PopulationStatus.FreeCivilian, Here, PopulationAssignment.Unassigned, null, null);
+ var travel = Pioneer("site-a").WithPlacement(PopulationStatus.CivilianInTransit, Here,
+ new PopulationAssignment(PopulationAssignmentKind.Travel, "road-t"), null, null);
+ var farmer = new PopulationUnit(0, PopulationStatus.FreeCivilian, 6, Here,
+ new PopulationAssignment(PopulationAssignmentKind.Work, "site-a"), CivilianProfession.Farmer, CivilianTier.Trained, 0,
+ "", 0, PopulationEquipment.None);
+ var start = State(c, Pioneer("site-a"), Pioneer("segment-b"), idle, travel, farmer, Pioneer("site-a").WithReception(0));
+ var before = start.Describe();
+
+ var first = Resolve(c, start, "site-a", "segment-b");
+ Assert.Equal(new[] { ("segment-b", 1m), ("site-a", 1m) }, first.WorkByTarget.Select(x => (x.Key, x.Value)));
+ var once = first.State;
+ var twice = Resolve(c, start, "site-a", "segment-b").State;
+ Assert.Equal(before, start.Describe());
+ Assert.Equal(once.Describe(), twice.Describe());
+ Assert.Equal(1, once.PopulationLedger.Get(0).WorkXp);
+
+ var s = Turns(c, start, 3, "site-a", "segment-b");
+ Assert.Equal(new[] { 3, 3, 0, 0, 0, 0 }, s.PopulationLedger.Units.Select(p => p.WorkXp));
+ s = Turns(c, s, 1); // no project advances this turn
+ Assert.Equal(new[] { 3, 3, 0, 0, 0, 0 }, s.PopulationLedger.Units.Select(p => p.WorkXp));
+ s = Turns(c, s, 1, "segment-b");
+ Assert.Equal(new[] { 3, 4, 0, 0, 0, 0 }, s.PopulationLedger.Units.Select(p => p.WorkXp));
+ }
+
+ // R-VET-001: veteran at profession.work_to_veteran (9) working turns, not the six service turns of gdd-0.1. The ninth
+ // turn's work is quoted at the turn-start tier; the record is veteran from the next turn, same id and project.
+ [Fact]
+ public void Gdd03PioneerBecomesVeteranAfterNineWorkingTurnsNotSix()
+ {
+ var c = Catalogue();
+ var start = State(c, Pioneer("site-a"));
+ var p = start.PopulationLedger.Get(0);
+ var s = Turns(c, start, 6, "site-a");
+ Assert.Equal(6, s.PopulationLedger.Get(0).WorkXp);
+ Assert.Equal(CivilianTier.Trained, s.PopulationLedger.Get(0).Tier);
+ s = Turns(c, s, 2, "site-a");
+ var ninth = Resolve(c, s, "site-a");
+ Assert.Equal(1m, ninth.WorkByTarget["site-a"]);
+ var vet = ninth.State.PopulationLedger.Get(0);
+ Assert.Equal(9, vet.WorkXp); Assert.Equal(CivilianTier.Veteran, vet.Tier);
+ Assert.Equal(p.Id, vet.Id); Assert.Equal(p.Assignment.Canonical(), vet.Assignment.Canonical());
+ Assert.Equal(1.5m, Resolve(c, ninth.State, "site-a").WorkByTarget["site-a"]);
+ }
+
+ // R-VET-002: the work quote reads pioneer.work_rate at the turn-start tier (trained 1, veteran 1.5), not
+ // veteran_progress 2. Only advancing targets are quoted.
+ [Fact]
+ public void Gdd03VeteranPioneerWorksAtCatalogueRateNotDoubleProgress()
+ {
+ var c = Catalogue();
+ var s = State(c, Pioneer("site-a"), Pioneer("site-a", 9, CivilianTier.Veteran), Pioneer("segment-b", 9, CivilianTier.Veteran));
+ var turn = Resolve(c, s, "site-a");
+ Assert.Equal(2.5m, turn.WorkByTarget["site-a"]);
+ // Catalogue rate only: no MVP path reaches a Novice pioneer today (MVP pioneers are course-trained, R-VET-001,
+ // owner answer 2 on #1693). Kept to pin the catalogue's novice row, not as an MVP route.
+ Assert.Equal(0.75m, Resolve(c, State(c, Pioneer("site-a", 0, CivilianTier.Novice)), "site-a").WorkByTarget["site-a"]);
+ Assert.False(turn.WorkByTarget.ContainsKey("segment-b"));
+ // Maintainer call, not a rule (no ruling covers it): a veteran's work XP stops at promotion, as a legacy veteran
+ // gains no more service (R-VET-001). The veteran still works at its 1.5 rate.
+ Assert.Equal(9, turn.State.PopulationLedger.Get(1).WorkXp);
+ Assert.Equal(CivilianTier.Veteran, turn.State.PopulationLedger.Get(1).Tier);
+ }
+
+ // R-QUAL-003, R-QUAL-005: a pioneer taken off the job and put back keeps its id and work XP, and earns none while idle.
+ [Fact]
+ public void Gdd03ReturnAndReassignKeepPioneerIdentityAndXp()
+ {
+ var c = Catalogue();
+ var s = Turns(c, State(c, Pioneer("site-a")), 4, "site-a");
+ s.PopulationLedger.ChangeAssignment(0, PopulationAssignment.Unassigned);
+ s = Turns(c, s, 1, "site-a");
+ Assert.Equal(4, s.PopulationLedger.Get(0).WorkXp);
+ s.PopulationLedger.ChangeAssignment(0, new PopulationAssignment(PopulationAssignmentKind.Work, "segment-b"));
+ Assert.Equal(4, s.PopulationLedger.Get(0).WorkXp); Assert.Equal(0, s.PopulationLedger.Get(0).Id);
+ s = Turns(c, s, 1, "segment-b");
+ Assert.Equal(5, s.PopulationLedger.Get(0).WorkXp);
+ }
+
+ // Answer 4: a record already in a course (set to Trainee/Course directly here) gets no work XP and keeps its tier and
+ // work XP; back at work it continues from the same count. Running a real Train order (R-QUAL-006) belongs to #1689's
+ // integration slice.
+ [Fact]
+ public void Gdd03PioneerInCourseGetsNoWorkXpAndKeepsTierAndXp()
+ {
+ var c = Catalogue();
+ var s = Turns(c, State(c, Pioneer("site-a")), 4, "site-a");
+ s.PopulationLedger.Transition(0, PopulationStatus.Trainee, Here, new PopulationAssignment(PopulationAssignmentKind.Course, "course-c"));
+ Assert.Empty(Resolve(c, s, "site-a", "course-c").WorkByTarget);
+ s = Turns(c, s, 2, "site-a", "course-c");
+ Assert.Equal(4, s.PopulationLedger.Get(0).WorkXp);
+ Assert.Equal(CivilianTier.Trained, s.PopulationLedger.Get(0).Tier);
+ Assert.Equal(CivilianProfession.Pioneer, s.PopulationLedger.Get(0).Profession);
+ s.PopulationLedger.Transition(0, PopulationStatus.FreeCivilian, Here, new PopulationAssignment(PopulationAssignmentKind.Work, "site-a"));
+ s = Turns(c, s, 1, "site-a");
+ Assert.Equal(5, s.PopulationLedger.Get(0).WorkXp);
+ }
+
+ // R-VET-001, R-UNIT-011: work promotion leaves combat XP and qualification as they were, and two records that differ
+ // only in combat XP gain the same work XP, keep the same tier and get the same work quote. No combat XP is advanced here.
+ [Fact]
+ public void Gdd03WorkPromotionKeepsCombatXpAndWorkIgnoresCombatXpLevel()
+ {
+ var c = Catalogue();
+ var s = Resolve(c, State(c, Pioneer("site-a", 8, combatXp: 7)), "site-a").State;
+ var vet = s.PopulationLedger.Get(0);
+ Assert.Equal(CivilianTier.Veteran, vet.Tier); Assert.Equal(7, vet.CombatXp); Assert.Equal("infantry", vet.Qualification);
+
+ var a = State(c, Pioneer("site-a", 3, combatXp: 0));
+ var b = State(c, Pioneer("site-a", 3, combatXp: 12));
+ var ta = Resolve(c, a, "site-a"); var tb = Resolve(c, b, "site-a");
+ Assert.Equal(ta.WorkByTarget["site-a"], tb.WorkByTarget["site-a"]);
+ Assert.Equal(4, ta.State.PopulationLedger.Get(0).WorkXp); Assert.Equal(CivilianTier.Trained, ta.State.PopulationLedger.Get(0).Tier);
+ Assert.Equal(4, tb.State.PopulationLedger.Get(0).WorkXp); Assert.Equal(12, tb.State.PopulationLedger.Get(0).CombatXp);
+ Assert.Equal(CivilianTier.Trained, tb.State.PopulationLedger.Get(0).Tier);
+ }
+
+ // R-POP-004 (#2323): the Historical ledger fixture has no pioneer at work, so the producer passes it through unchanged.
+ // A game without an initialized ledger (gdd-0.1) is refused, so the aggregate halutz path is never touched.
+ [Fact]
+ public void HistoricalFixturePassesThroughAndGdd01IsRefused()
+ {
+ var c = HistoricalPopulationTests.Real(true);
+ var s = HistoricalPopulation.LedgerFixture(c);
+ var turn = Gdd03PioneerWorkFixture.ResolveTurnEnd(c, s, c.PlayerRegions.Regions.Keys);
+ Assert.Equal(s.Describe(), turn.State.Describe());
+ Assert.Empty(turn.WorkByTarget);
+
+ var old = HistoricalPopulationTests.Real(false);
+ Assert.Throws<InvalidOperationException>(() =>
+ Gdd03PioneerWorkFixture.ResolveTurnEnd(old, Simulation.NewGame(old, 1, Mode.Historical), new[] { "site-a" }));
+ }
+}
diff --git a/sim/Statecraft.Sim.Tests/HistoricalPopulationTests.cs b/sim/Statecraft.Sim.Tests/HistoricalPopulationTests.cs
index 398e8241b..822f5d929 100644
--- a/sim/Statecraft.Sim.Tests/HistoricalPopulationTests.cs
+++ b/sim/Statecraft.Sim.Tests/HistoricalPopulationTests.cs
@@ -6,7 +6,7 @@ using Statecraft.Sim;
/// The inventory is not yet wired into Simulation.NewGame (see R-POP-004 and docs/population-ledger.md).</summary>
public class HistoricalPopulationTests
{
- static Content Real(bool modern)
+ internal static Content Real(bool modern)
{
var root = RealContentTests.ContentRoot();
return ContentLoader.Load(rel =>
diff --git a/sim/Statecraft.Sim/Gdd03PioneerWorkFixture.cs b/sim/Statecraft.Sim/Gdd03PioneerWorkFixture.cs
new file mode 100644
index 000000000..8f37a942e
--- /dev/null
+++ b/sim/Statecraft.Sim/Gdd03PioneerWorkFixture.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+
+namespace Statecraft.Sim
+{
+ /// <summary>One resolved pioneer turn: the end-of-turn fixture state and the pioneer work quoted per advancing target.
+ /// The quote is not applied to any project here; the future site/corridor integration owns that.</summary>
+ internal sealed class PioneerWorkTurn
+ {
+ internal GameState State { get; }
+ internal IReadOnlyDictionary<string, decimal> WorkByTarget { get; }
+ internal PioneerWorkTurn(GameState state, SortedDictionary<string, decimal> work)
+ {
+ State = state;
+ WorkByTarget = new ReadOnlyDictionary<string, decimal>(work);
+ }
+ }
+
+ /// <summary>#1693 pioneer slice: the turn-end producer R-VET-001 holds, on initialized gdd-0.3 ledger fixtures only.
+ /// No game-loop caller: an initialized ledger refuses the aggregate systems (R-POP-002), and the switch is #1689's last
+ /// slice. Farmer work XP follows #1694; the tools charge is post-MVP (owner, 3 November 2026, answer 1).</summary>
+ internal static class Gdd03PioneerWorkFixture
+ {
+ /// <summary>The caller supplies the turn-start state and the pioneer projects being built this turn, yishuv sites
+ /// and corridor segments alike (owner, 3 November 2026, answer 5). Each pioneer record at Work on one of them
+ /// gives completed-work evidence at its turn-start <c>pioneer.work_rate</c> (R-VET-002), and its
+ /// <see cref="CivilianProfessionRules.AfterWork"/> result is committed once into a copy, in ascending id. The
+ /// turn-start state is not changed, so resolving the same snapshot twice gives the same single tick (R-VET-001).
+ /// Idle, travel, course and teaching records give no evidence and keep their tier and work XP (answer 4). The
+ /// resolver reads any tier's catalogue rate, but no MVP path reaches a Novice pioneer today: MVP pioneers are
+ /// course-trained (answer 2).</summary>
+ internal static PioneerWorkTurn ResolveTurnEnd(Content content, GameState turnStart, IEnumerable<string> advancingProjects)
+ {
+ if (content == null) throw new ArgumentNullException(nameof(content));
+ if (turnStart == null) throw new ArgumentNullException(nameof(turnStart));
+ if (advancingProjects == null) throw new ArgumentNullException(nameof(advancingProjects));
+ if (!content.UsesPopulationLedger || !turnStart.UsesPopulationLedger || !turnStart.PopulationLedger.IsInitialized)
+ throw new InvalidOperationException("Pioneer work XP requires an initialized gdd-0.3 ledger fixture.");
+ var advancing = new HashSet<string>(StringComparer.Ordinal);
+ foreach (var id in advancingProjects)
+ if (string.IsNullOrWhiteSpace(id)) throw new ArgumentException("Advancing projects need explicit target ids.");
+ else advancing.Add(id);
+ turnStart.PopulationLedger.Reconcile();
+
+ var candidate = turnStart.Clone();
+ var work = new SortedDictionary<string, decimal>(StringComparer.Ordinal);
+ foreach (var p in turnStart.PopulationLedger.Units) // ascending id
+ {
+ if (p.Profession != CivilianProfession.Pioneer || p.Assignment.Kind != PopulationAssignmentKind.Work
+ || p.Assignment.Target == null || !advancing.Contains(p.Assignment.Target)) continue;
+ var target = p.Assignment.Target;
+ var quote = CivilianProfessionRules.OutputAtTurnStart(content, turnStart, p.Id);
+ var next = CivilianProfessionRules.AfterWork(content, turnStart, p.Id,
+ new[] { new CivilianWorkEvidence(p.Id, target, CivilianWorkKind.PioneerAdvancement, quote) });
+ // AfterWork returns the same record when it is not a working pioneer (e.g. reception not finished): no work.
+ if (ReferenceEquals(next, p)) continue;
+ work[target] = (work.TryGetValue(target, out var sum) ? sum : 0m) + quote;
+ // Maintainer call, not a rule (no ruling covers it): a veteran keeps working at its rate but its work XP
+ // stops at promotion, as a legacy veteran gains no more service (R-VET-001).
+ if (p.Tier != CivilianTier.Veteran) candidate.PopulationLedger.Replace(next);
+ }
+ candidate.PopulationLedger.Reconcile();
+ return new PioneerWorkTurn(candidate, work);
+ }
+ }
+}