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: the gdd-0.3 work producers skip a veteran before AfterWork (#2804 item 12) (#2865)

Beri7a4d5d4e37e9
diff --git a/changelog.d/2804-veteran-work-xp.md b/changelog.d/2804-veteran-work-xp.md
new file mode 100644
index 000000000..ffe9230bc
--- /dev/null
+++ b/changelog.d/2804-veteran-work-xp.md
@@ -0,0 +1,4 @@
+### Fixed
+
+- The gdd-0.3 pioneer and farmer work fixtures check for a veteran before they count its work XP, so a veteran at the
+ largest work XP the ledger allows keeps working at its rate instead of throwing (Refs #2804). No game-loop caller yet.
diff --git a/sim/Statecraft.Sim.Tests/Gdd03FieldFixtureTests.cs b/sim/Statecraft.Sim.Tests/Gdd03FieldFixtureTests.cs
index bf8d2da6c..d3e364a76 100644
--- a/sim/Statecraft.Sim.Tests/Gdd03FieldFixtureTests.cs
+++ b/sim/Statecraft.Sim.Tests/Gdd03FieldFixtureTests.cs
@@ -301,6 +301,26 @@ public class Gdd03FieldFixtureTests
Assert.Equal(5, f.Yield(r, WorkMonth(c, s, industry.Id), AllHeld(c)).Fields[V1]);
}
+ // R-VET-001 (#2804 item 12): the producer checks for a veteran before AfterWork, so a veteran farmer at int.MaxValue
+ // work XP (the ledger allows any nonnegative work XP) keeps its XP instead of overflowing, and its field still yields
+ // the veteran 5. TEST-ONLY SYNTHETIC work XP.
+ [Fact] public void AVeteranFarmerAtMaxWorkXpKeepsItsXp()
+ {
+ var c = Real(); var r = Rules(c);
+ var industry = new Gdd03FixtureSlot("synthetic-industry", Gdd03FixtureWork.Industry, 1, "winery");
+ var s = WorkState(c, industry, new PopulationUnit(0, PopulationStatus.FreeCivilian, c.RequirePopulationInteger("reception.turns"),
+ InValleys, PopulationAssignment.Unassigned, CivilianProfession.Farmer, CivilianTier.Veteran, int.MaxValue, "infantry", 4,
+ new PopulationEquipment(toolsId: "tools/0", toolsPaid: true)));
+ var f = new Gdd03FieldFixture(c, s, new[] { industry });
+ f.Staff(0, V1, israeliHeld: true);
+ var month = WorkMonth(c, s, industry.Id);
+ var before = s.Describe();
+ var next = Gdd03FieldFixture.ResolveWorkXp(c, s, month, AllHeld(c));
+ Assert.Equal((int.MaxValue, CivilianTier.Veteran), (next.PopulationLedger.Get(0).WorkXp, next.PopulationLedger.Get(0).Tier));
+ Assert.Equal(before, s.Describe());
+ Assert.Equal(5, f.Yield(r, month, AllHeld(c)).Fields[V1]);
+ }
+
// #2468 review: a snapshot with more working farmers on a field than its `field.slots` (1) is refused whole, as
// Yield refuses it, so no farmer is credited for a slot another farmer holds; the turn-start state is unchanged.
[Fact] public void AnOverOccupiedFieldMonthIsRefused()
diff --git a/sim/Statecraft.Sim.Tests/Gdd03PioneerWorkFixtureTests.cs b/sim/Statecraft.Sim.Tests/Gdd03PioneerWorkFixtureTests.cs
index 69783ca79..f406fd7b7 100644
--- a/sim/Statecraft.Sim.Tests/Gdd03PioneerWorkFixtureTests.cs
+++ b/sim/Statecraft.Sim.Tests/Gdd03PioneerWorkFixtureTests.cs
@@ -110,6 +110,22 @@ public class Gdd03PioneerWorkFixtureTests
Assert.Equal(CivilianTier.Veteran, turn.State.PopulationLedger.Get(1).Tier);
}
+ // R-VET-001 (#2804 item 12): the producer checks for a veteran before AfterWork, so a veteran at int.MaxValue work XP
+ // (the ledger allows any nonnegative work XP) works at its 1.5 rate and keeps its XP instead of overflowing. A veteran
+ // still in reception gives no work, as AfterWork's gate says for every tier. TEST-ONLY SYNTHETIC work XP.
+ [Fact]
+ public void Gdd03VeteranAtMaxWorkXpWorksAndKeepsItsXp()
+ {
+ var c = Catalogue();
+ var s = State(c, Pioneer("site-a", int.MaxValue, CivilianTier.Veteran),
+ Pioneer("segment-b", int.MaxValue, CivilianTier.Veteran).WithReception(0));
+ var before = s.Describe();
+ var turn = Resolve(c, s, "site-a", "segment-b");
+ Assert.Equal(new[] { ("site-a", 1.5m) }, turn.WorkByTarget.Select(x => (x.Key, x.Value)));
+ Assert.All(turn.State.PopulationLedger.Units, p => Assert.Equal((int.MaxValue, CivilianTier.Veteran), (p.WorkXp, p.Tier)));
+ Assert.Equal(before, s.Describe());
+ }
+
// 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()
diff --git a/sim/Statecraft.Sim/Gdd03FieldFixture.cs b/sim/Statecraft.Sim/Gdd03FieldFixture.cs
index 8c140eb88..703cfc6cd 100644
--- a/sim/Statecraft.Sim/Gdd03FieldFixture.cs
+++ b/sim/Statecraft.Sim/Gdd03FieldFixture.cs
@@ -164,11 +164,14 @@ namespace Statecraft.Sim
var field = p.Assignment.Target;
if (!working.Contains(p.Id) || p.Profession != CivilianProfession.Farmer || field == null
|| !fields.Contains(field) || !israeliHeldNow.Contains(field)) continue;
+ // The same maintainer call as the pioneer producer's, not a rule: a veteran's work XP stops at promotion,
+ // so a veteran is skipped before AfterWork, whose checked increment throws at int.MaxValue (#2804 item 12).
+ // Its Food is Yield's, which never reads work XP.
+ if (turnStart.PopulationLedger.Get(p.Id).Tier == CivilianTier.Veteran) continue;
// R-VET-001: staffed farming counts regardless of output, so the receipt carries no amount.
var next = CivilianProfessionRules.AfterWork(content, turnStart, p.Id,
new[] { new CivilianWorkEvidence(p.Id, field, CivilianWorkKind.StaffedFarming, 0m) });
- // The same maintainer call as the pioneer producer's, not a rule: a veteran's work XP stops at promotion.
- if (!ReferenceEquals(next, turnStart.PopulationLedger.Get(p.Id)) && turnStart.PopulationLedger.Get(p.Id).Tier != CivilianTier.Veteran)
+ if (!ReferenceEquals(next, turnStart.PopulationLedger.Get(p.Id)))
candidate.PopulationLedger.Replace(next);
}
candidate.PopulationLedger.Reconcile();
diff --git a/sim/Statecraft.Sim/Gdd03PioneerWorkFixture.cs b/sim/Statecraft.Sim/Gdd03PioneerWorkFixture.cs
index dcd8d3561..e70a2e37d 100644
--- a/sim/Statecraft.Sim/Gdd03PioneerWorkFixture.cs
+++ b/sim/Statecraft.Sim/Gdd03PioneerWorkFixture.cs
@@ -52,14 +52,24 @@ namespace Statecraft.Sim
|| 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);
+ // stops at promotion, as a legacy veteran gains no more service (R-VET-001). So a veteran never reaches
+ // AfterWork, whose checked increment throws at int.MaxValue work XP (#2804 item 12); it works when
+ // AfterWork's own gate would let it: a free civilian whose reception is done.
+ if (p.Tier == CivilianTier.Veteran)
+ {
+ if (p.Status != PopulationStatus.FreeCivilian
+ || p.ReceptionTicks != content.RequirePopulationInteger("reception.turns")) continue;
+ }
+ else
+ {
+ 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;
+ candidate.PopulationLedger.Replace(next);
+ }
+ work[target] = (work.TryGetValue(target, out var sum) ? sum : 0m) + quote;
}
candidate.PopulationLedger.Reconcile();
return new PioneerWorkTurn(candidate, work);