A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: content/eras.yaml, Content.EraAt and the end of the last era (fixes #56) (#243)
Guy Shoham901d827eb53c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 745618820..12ecf7871 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,11 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB## [Unreleased]### Added+- `content/eras.yaml` with the `founding` era (15 May 1948 to 1 January 1957), a `Content.EraAt(date)` lookup, and the end+ of the last era: the turn that reaches it ends on it (a turn that would leave under 14 days is lengthened to it), the+ game ends with the stable code `era_ended` and the text "The chapter has ended", and later orders are refused. The+ rejection text for a finished game now shows the reason, not its code. The Why panel shows the end under a new+ "Chapter" group. The golden hashes do not change (#56).- Region borders in the promo look (promo-borders): two-tone outlines along hex edges (a blue band with a white innerstripe, a red-orange band with a cream one), drawn inside each region by the terrain shader from one texel per hex, witha "borders" visual toggle. Visual only. No invented boundaries: the first real data is the 1948 sub-districts (below);diff --git a/content/eras.yaml b/content/eras.yamlnew file mode 100644index 000000000..9b87316f5--- /dev/null+++ b/content/eras.yaml@@ -0,0 +1,9 @@+# The chapters of the game, in order. Eras are contiguous: each era's `from` is the previous era's `to`. A window is+# half-open, like every other window: `to` is the first day after the era. Reaching the last era's `to` ends the game.+# Design decision D3 (docs/superpowers/specs/2026-10-10-chapters-architecture-design.md): the founding era runs from+# the start of play to 1 January 1957, the spec's "Q2 1948 to Q4 1956". These are game-design dates, not historical facts.+eras:+ - id: founding+ name: The Founding+ from: 1948-05-15 # = rules.yaml start+ to: 1957-01-01diff --git a/sim/Statecraft.Sim.Tests/EraTests.cs b/sim/Statecraft.Sim.Tests/EraTests.csnew file mode 100644index 000000000..d8e247ea3--- /dev/null+++ b/sim/Statecraft.Sim.Tests/EraTests.cs@@ -0,0 +1,236 @@+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++/// <summary>eras.yaml (#56): load-time checks, the era lookup, the boundary turn and the end of the last era.</summary>+public class EraTests+{+ static readonly DateTime Start = new DateTime(1948, 5, 15);+ static readonly DateTime End = new DateTime(1957, 1, 1);++ static ContentException BadEras(string yaml) =>+ Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["eras.yaml"] = yaml })));++ static string Eras(params string[] entries) => "eras:\n" + string.Join("\n", entries) + "\n";+ static string Era(string id, string from, string to, string name = "A Name") =>+ $" - id: {id}\n name: {name}\n from: {from}\n to: {to}";++ [Fact]+ public void RealContentHasTheFoundingEra()+ {+ var c = ContentLoader.Load(RealContentTests.ContentRoot());+ var era = Assert.Single(c.Eras);+ Assert.Equal("founding", era.Id);+ Assert.Equal(c.Rules.Start, era.From);+ Assert.Equal(End, era.To);+ }++ [Fact]+ public void EraAtIsHalfOpenAndNullOutsideTheRange()+ {+ var c = ContentLoader.Load(RealContentTests.ContentRoot());+ Assert.Null(c.EraAt(Start.AddDays(-1)));+ Assert.Equal("founding", c.EraAt(Start)!.Id);+ Assert.Equal("founding", c.EraAt(End.AddDays(-1))!.Id);+ Assert.Null(c.EraAt(End));+ }++ [Fact]+ public void EveryRealEventWindowLiesInsideTheErasRange()+ {+ var c = ContentLoader.Load(RealContentTests.ContentRoot());+ var (first, last) = (c.Eras.First().From, c.Eras.Last().To);+ foreach (var e in c.Events)+ {+ Assert.True(e.From >= first, $"{e.File}: from {e.From:yyyy-MM-dd} is before the first era starts ({first:yyyy-MM-dd})");+ Assert.True((e.To ?? last) <= last, $"{e.File}: to {e.To:yyyy-MM-dd} is after the last era ends ({last:yyyy-MM-dd})");+ }+ }++ [Fact]+ public void TwoContiguousErasLoadAndEachDateHasOneEra()+ {+ var yaml = Eras(Era("a", "1948-05-15", "1950-01-01"), Era("b", "1950-01-01", "1957-01-01"));+ var c = ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["eras.yaml"] = yaml }));+ Assert.Equal("a", c.EraAt(new DateTime(1949, 12, 31))!.Id);+ Assert.Equal("b", c.EraAt(new DateTime(1950, 1, 1))!.Id);+ }++ [Fact]+ public void OverlappingErasAreALoadError()+ {+ var ex = BadEras(Eras(Era("a", "1948-05-15", "1950-06-01"), Era("b", "1950-01-01", "1957-01-01")));+ Assert.Equal("eras.yaml", ex.File);+ Assert.Equal("eras[b].from", ex.Field);+ Assert.Contains("overlaps a", ex.Message);+ }++ [Fact]+ public void AGapBetweenErasIsALoadError()+ {+ var ex = BadEras(Eras(Era("a", "1948-05-15", "1950-01-01"), Era("b", "1950-02-01", "1957-01-01")));+ Assert.Equal("eras.yaml", ex.File);+ Assert.Equal("eras[b].from", ex.Field);+ Assert.Contains("gap after a", ex.Message);+ }++ [Theory]+ [InlineData("1948-05-15")] // empty range+ [InlineData("1948-05-14")] // ends before it starts+ public void AnEmptyRangeIsALoadError(string to)+ {+ var ex = BadEras(Eras(Era("a", "1948-05-15", to)));+ Assert.Equal("eras[a].to", ex.Field);+ Assert.Contains("must be after from", ex.Message);+ }++ [Theory]+ [InlineData("from")]+ [InlineData("to")]+ public void AMissingDateIsALoadError(string field)+ {+ var era = field == "from" ? " - id: a\n name: A Name\n to: 1957-01-01" : " - id: a\n name: A Name\n from: 1948-05-15";+ var ex = BadEras(Eras(era));+ Assert.Equal("eras.yaml", ex.File);+ Assert.Equal("eras[a]." + field, ex.Field);+ Assert.Contains("required", ex.Message);+ }++ [Theory]+ [InlineData("1957-13-01")]+ [InlineData("soon")]+ public void ABadDateIsALoadError(string to)+ {+ var ex = BadEras(Eras(Era("a", "1948-05-15", to)));+ Assert.Equal("eras.yaml", ex.File);+ }++ [Fact]+ public void ADuplicateEraIdIsALoadError()+ {+ var ex = BadEras(Eras(Era("a", "1948-05-15", "1950-01-01"), Era("a", "1950-01-01", "1957-01-01")));+ Assert.Equal("eras.yaml", ex.File);+ Assert.Equal("eras[a].id", ex.Field);+ Assert.Contains("duplicate", ex.Message);+ }++ [Fact]+ public void TheFirstEraMustStartOnTheGameStart()+ {+ var ex = BadEras(Eras(Era("a", "1948-05-16", "1957-01-01")));+ Assert.Equal("eras[a].from", ex.Field);+ Assert.Contains("rules.yaml", ex.Message);+ }++ [Fact]+ public void AnEraNeedsAName()+ {+ var ex = BadEras(Eras(Era("a", "1948-05-15", "1957-01-01", name: "''")));+ Assert.Equal("eras[a].name", ex.Field);+ }++ [Fact]+ public void NoErasIsALoadError()+ {+ var ex = BadEras("eras: []\n");+ Assert.Equal("eras", ex.Field);+ }++ [Fact]+ public void AnUnknownFieldIsALoadError() =>+ BadEras(Eras(Era("a", "1948-05-15", "1957-01-01") + "\n systems: {}"));++ // --- the boundary turn (spec 4.1) and the end of the last era (spec 4.5)++ static Content EndingOn(string to) =>+ ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["eras.yaml"] = Eras(Era("founding", "1948-05-15", to)) }));++ static GameState PlayToTheEnd(Content c, out List<DateTime> dates)+ {+ var s = Simulation.NewGame(c, 1948, Mode.Historical);+ dates = new List<DateTime> { s.Date };+ for (int i = 0; i < 100 && s.GameOver == null; i++)+ {+ s = Simulation.Step(c, s, new Command[0]).State;+ dates.Add(s.Date);+ }+ return s;+ }++ [Fact]+ public void ReachingTheLastErasEndSetsTheCodeOnThatDate()+ {+ var c = EndingOn("1948-07-03"); // the weekly grid from 15 May lands on 3 July+ var s = PlayToTheEnd(c, out var dates);+ Assert.Equal(GameOverCodes.EraEnded, s.GameOver);+ Assert.Equal(new DateTime(1948, 7, 3), s.Date);+ Assert.Equal(new DateTime(1948, 7, 3), dates.Last());+ }++ [Fact]+ public void ATurnThatWouldCrossTheEndIsAdjustedToLandOnIt()+ {+ var c = EndingOn("1948-07-01"); // the grid is 5, 12, 19, 26 June, 3 July: the last turn would cross 1 July+ var s = PlayToTheEnd(c, out var dates);+ Assert.Equal(new DateTime(1948, 7, 1), s.Date);+ Assert.DoesNotContain(new DateTime(1948, 7, 3), dates);+ }++ [Fact]+ public void ATurnThatWouldLeaveUnder14DaysIsLengthenedInstead()+ {+ var c = EndingOn("1948-07-01");+ PlayToTheEnd(c, out var dates);+ // The turn after 19 June would be 12 days, under 14, so the turn from 12 June runs to 1 July (19 days).+ Assert.Equal(new DateTime(1948, 6, 12), dates[^2]);+ Assert.Equal(new DateTime(1948, 7, 1), dates[^1]);+ Assert.All(dates.Zip(dates.Skip(1), (a, b) => (b - a).Days), d => Assert.InRange(d, 7, 21));+ }++ [Fact]+ public void TheEndReasonShowsNoIdAndNoIsoDate()+ {+ var c = EndingOn("1948-07-03");+ var s = Simulation.NewGame(c, 1948, Mode.Historical);+ StepResult r = null!;+ while (s.GameOver == null) { r = Simulation.Step(c, s, new Command[0]); s = r.State; }+ var text = r.Why.Single(w => w.System == "era").Message;+ Assert.Equal("The chapter has ended", text);+ Assert.DoesNotContain("era_ended", text);+ Assert.DoesNotMatch(@"\d{4}-\d{2}-\d{2}", text);+ var refused = Simulation.Step(c, s, new Command[] { new SetMobilization(0.5) }).Rejected.Single();+ Assert.DoesNotContain("era_ended", refused.Reason);+ Assert.DoesNotMatch(@"\d{4}-\d{2}-\d{2}", refused.Reason);+ }++ [Fact]+ public void CommandsAfterTheEndAreRefusedAndTheStateDoesNotMove()+ {+ var c = EndingOn("1948-07-03");+ var s = PlayToTheEnd(c, out _);+ var after = Simulation.Step(c, s, new Command[] { new SetMobilization(0.5) });+ Assert.Single(after.Rejected);+ Assert.Equal(s.Date, after.State.Date);+ Assert.Equal(s.Hash(), after.State.Hash());+ }++ [Fact]+ public void AnAdjustedTurnCountsItsRealWeeksOnTheCeasefireClock()+ {+ // Rung 5 from the start; the clock starts at ceasefire_weeks (4 in the fixture) and runs 1 week per weekly turn.+ // Ending on 1 July makes the last turn 19 days: 19 / 7 = 2 whole weeks.+ var c = EndingOn("1948-07-01");+ var s = Simulation.NewGame(c, 1948, Mode.Historical);+ var weeklyTurns = 0;+ var before = s.CeasefireWeeksLeft;+ while (s.GameOver == null && s.Rung == 5)+ {+ var next = Simulation.Step(c, s, new Command[0]).State;+ var days = (next.Date - s.Date).Days;+ if (next.Rung == 5) Assert.Equal(Math.Max(0, s.CeasefireWeeksLeft - (days == 7 ? 1 : days / 7)), next.CeasefireWeeksLeft);+ s = next; weeklyTurns++;+ }+ Assert.True(weeklyTurns > 0 && before > 0);+ }+}diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.csindex 8b4264682..6e0960811 100644--- a/sim/Statecraft.Sim.Tests/Fixture.cs+++ b/sim/Statecraft.Sim.Tests/Fixture.cs@@ -15,6 +15,13 @@ offices:title: Minister of Defense- id: finance_ministertitle: Minister of Finance+",+ ["eras.yaml"] = @"+eras:+ - id: founding+ name: The Founding+ from: 1948-05-15+ to: 1957-01-01",["parties.yaml"] = @"parties:diff --git a/sim/Statecraft.Sim.Tests/SimTests.cs b/sim/Statecraft.Sim.Tests/SimTests.csindex 423e3e6a3..8553ad662 100644--- a/sim/Statecraft.Sim.Tests/SimTests.cs+++ b/sim/Statecraft.Sim.Tests/SimTests.cs@@ -73,7 +73,7 @@ public class SimTests{var s0 = Simulation.NewGame(C, 42, Mode.Historical); s0.GameOver = "coalition_collapse";var r = Simulation.Step(C, s0, new Command[] { new SecurityOrder(-1) });- Assert.Equal("The game is over: coalition_collapse", r.Rejected[0].Reason);+ Assert.Equal("The game is over: The coalition collapsed", r.Rejected[0].Reason);Assert.Equal(s0.Hash(), r.State.Hash());}diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.csindex 7f52455ab..72b670765 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -1,5 +1,6 @@using System;using System.Collections.Generic;+using System.Linq;using YamlDotNet.Serialization;namespace Statecraft.Sim@@ -22,6 +23,16 @@ namespace Statecraft.Simpublic bool ExistsOn(DateTime date) => (!From.HasValue || date >= From.Value) && (!Until.HasValue || date < Until.Value);}+ /// <summary>A chapter of the game: the half-open range [From, To). Eras are contiguous; the last era's To ends the game.</summary>+ public sealed class Era+ {+ public string Id { get; set; } = "";+ /// <summary>The chapter name the player sees.</summary>+ public string Name { get; set; } = "";+ public DateTime From { get; set; }+ public DateTime To { get; set; }+ }+public sealed class Party { public string Id { get; set; } = ""; public string Name { get; set; } = ""; }public sealed class OfficeTerm@@ -287,6 +298,10 @@ namespace Statecraft.Simpublic List<Person> People = new List<Person>();public List<Legislature> Legislatures = new List<Legislature>();public List<Government> Governments = new List<Government>();+ /// <summary>The eras in order (eras.yaml).</summary>+ public List<Era> Eras = new List<Era>();+ /// <summary>The era that contains <paramref name="date"/> (From inclusive, To exclusive), or null outside every era.</summary>+ public Era? EraAt(DateTime date) => Eras.FirstOrDefault(e => date >= e.From && date < e.To);public List<Indicator> Indicators = new List<Indicator>();public List<Policy> Policies = new List<Policy>();public List<Effect> Effects = new List<Effect>();diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex 1579022ea..27df0cb0b 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -16,6 +16,7 @@ namespace Statecraft.Simsealed class PartiesFile { public List<Party> Parties { get; set; } = new List<Party>(); }sealed class PeopleFile { public List<Person> People { get; set; } = new List<Person>(); }sealed class LegislaturesFile { public List<Legislature> Legislatures { get; set; } = new List<Legislature>(); }+ sealed class ErasFile { public List<Era> Eras { get; set; } = new List<Era>(); }sealed class GovernmentsFile { public List<Government> Governments { get; set; } = new List<Government>(); }sealed class ModelFile{@@ -158,6 +159,7 @@ namespace Statecraft.Simc.People = Read<PeopleFile>(readFile, "people.yaml").People;c.Legislatures = Read<LegislaturesFile>(readFile, "legislatures.yaml").Legislatures;c.Governments = Read<GovernmentsFile>(readFile, "governments.yaml").Governments;+ c.Eras = Read<ErasFile>(readFile, "eras.yaml").Eras;var m = Read<ModelFile>(readFile, "model.yaml");c.Indicators = m.Indicators; c.Policies = m.Policies; c.Effects = m.Effects;c.Situations = m.Situations; c.VoterGroups = m.VoterGroups; c.Actors = m.Actors; c.Money = m.Money;@@ -297,6 +299,8 @@ namespace Statecraft.SimUnique("people.yaml", "people", c.People.Select(p => p.Id));Unique("legislatures.yaml", "legislatures", c.Legislatures.Select(l => l.Id));Unique("governments.yaml", "governments", c.Governments.Select(g => g.Id));+ Unique("eras.yaml", "eras", c.Eras.Select(e => e.Id));+ ValidateEras(c);Unique("model.yaml", "indicators", c.Indicators.Select(i => i.Id));Unique("model.yaml", "policies", c.Policies.Select(p => p.Id));Unique("model.yaml", "effects", c.Effects.Select(e => e.Id));@@ -544,6 +548,32 @@ namespace Statecraft.SimEventRules.Validate(c, offices, indicators);}+ /// <summary>One or more eras, each with a name and a non-empty range; the first starts on rules.yaml start and+ /// each starts where the one before ended, so every date in range is in exactly one era.</summary>+ static void ValidateEras(Content c)+ {+ if (c.Eras.Count == 0) throw new ContentException("eras.yaml", "eras", "at least one era is required");+ for (int i = 0; i < c.Eras.Count; i++)+ {+ var e = c.Eras[i];+ var at = $"eras[{e.Id}]";+ Named("eras.yaml", at + ".name", e.Name);+ if (e.To == default) throw new ContentException("eras.yaml", at + ".to", "required (the first day after the era)");+ Period("eras.yaml", at, e.From, e.To);+ if (i == 0)+ {+ if (c.Rules.Start != default && e.From != c.Rules.Start) // a missing start is rules.yaml's own error+ throw new ContentException("eras.yaml", at + ".from", FormattableString.Invariant($"must equal start in rules.yaml ({c.Rules.Start:yyyy-MM-dd})"));+ continue;+ }+ var prev = c.Eras[i - 1];+ if (e.From < prev.To)+ throw new ContentException("eras.yaml", at + ".from", FormattableString.Invariant($"overlaps {prev.Id} (ends {prev.To:yyyy-MM-dd})"));+ if (e.From > prev.To)+ throw new ContentException("eras.yaml", at + ".from", FormattableString.Invariant($"leaves a gap after {prev.Id}: must equal its end ({prev.To:yyyy-MM-dd})"));+ }+ }+static void ValidateMap(Content c, List<string> settlementIds){if (c.Hexes.Count == 0) throw new ContentException(HexesFile, "hexes", "no hexes");diff --git a/sim/Statecraft.Sim/GameState.cs b/sim/Statecraft.Sim/GameState.csindex 391962a4d..4cdf4ac9e 100644--- a/sim/Statecraft.Sim/GameState.cs+++ b/sim/Statecraft.Sim/GameState.cs@@ -7,6 +7,14 @@ using System.Text;namespace Statecraft.Sim{+ /// <summary>The stable codes <see cref="GameState.GameOver"/> can hold (they are in the state hash).</summary>+ public static class GameOverCodes+ {+ /// <summary>The last era's end was reached (eras.yaml).</summary>+ public const string EraEnded = "era_ended";+ public const string CoalitionCollapse = "coalition_collapse";+ }+public enum Mode { Historical, Open }/// <summary>All mutable game data. Systems never share references between states: Step works on Clone().</summary>@@ -45,6 +53,7 @@ namespace Statecraft.Sim/// acceptance, so replacing a camp with housing cannot reopen the per-turn cap; a new date starts from zero.</summary>public DateTime MapActionsTurnDate;public int MapActionsThisTurn;+ /// <summary>Why the game ended, as one of the <see cref="GameOverCodes"/>; null while it is on. Never display it: use PlayerText.GameOver.</summary>public string? GameOver;public double TotalPopulation => Population.Values.Sum();diff --git a/sim/Statecraft.Sim/PlayerText.cs b/sim/Statecraft.Sim/PlayerText.csindex 7d35a5183..a0e01c88c 100644--- a/sim/Statecraft.Sim/PlayerText.cs+++ b/sim/Statecraft.Sim/PlayerText.cs@@ -14,6 +14,15 @@ namespace Statecraft.Sim/// <summary>The money the sim tracks; model.yaml money names each one.</summary>public static readonly string[] MoneyIds = { "treasury", "debt", "fx_reserves" };+ /// <summary>The player-facing reason for a <see cref="GameState.GameOver"/> code (see <see cref="GameOverCodes"/>):+ /// tests and goldens compare the code, the player reads this.</summary>+ public static string GameOver(string code) => code switch+ {+ GameOverCodes.EraEnded => "The chapter has ended",+ GameOverCodes.CoalitionCollapse => "The coalition collapsed",+ _ => throw Unknown("game over reason", code),+ };+/// <summary>"15 May 1948".</summary>public static string Date(DateTime d) => d.ToString("d MMMM yyyy", CultureInfo.InvariantCulture);diff --git a/sim/Statecraft.Sim/PoliticsSystem.cs b/sim/Statecraft.Sim/PoliticsSystem.csindex 55d1771b3..e90d826c5 100644--- a/sim/Statecraft.Sim/PoliticsSystem.cs+++ b/sim/Statecraft.Sim/PoliticsSystem.cs@@ -39,7 +39,7 @@ namespace Statecraft.Simwhy.Add(new Cause("politics", "coalition_stability", s.CoalitionStability - old, $"coalition stability {PlayerText.PercentChange(s.CoalitionStability - old)} (public approval)"));if (s.CoalitionStability < CollapseBelow && s.GameOver == null){- s.GameOver = "coalition_collapse";+ s.GameOver = GameOverCodes.CoalitionCollapse;why.Add(new Cause("politics", "game_over", 0, "The coalition collapsed. Your premiership is over."));}}diff --git a/sim/Statecraft.Sim/SecuritySystem.cs b/sim/Statecraft.Sim/SecuritySystem.csindex a51d06bf9..f5f7274c3 100644--- a/sim/Statecraft.Sim/SecuritySystem.cs+++ b/sim/Statecraft.Sim/SecuritySystem.cs@@ -61,10 +61,14 @@ namespace Statecraft.Sim}}- public static void Apply(Content c, GameState s, TurnLength len, List<Cause> why)+ public static void Apply(Content c, GameState s, TurnLength len, List<Cause> why) => Apply(c, s, Weeks(len), why);++ /// <summary>Counts the ceasefire clock down by <paramref name="weeks"/> (a whole turn's weeks, or the whole weeks of+ /// an adjusted turn at an era's end) while the country is at full war.</summary>+ public static void Apply(Content c, GameState s, int weeks, List<Cause> why){if (s.Rung != 5) return;- s.CeasefireWeeksLeft = Math.Max(0, s.CeasefireWeeksLeft - Weeks(len));+ s.CeasefireWeeksLeft = Math.Max(0, s.CeasefireWeeksLeft - weeks);if (s.CeasefireWeeksLeft == 0){why.Add(new Cause("security", "ceasefire", 0, "UN ceasefire imposed: full war ends")); // the rung cause SetRung adds carries the -2diff --git a/sim/Statecraft.Sim/SimTime.cs b/sim/Statecraft.Sim/SimTime.csindex 85a773398..70714e612 100644--- a/sim/Statecraft.Sim/SimTime.cs+++ b/sim/Statecraft.Sim/SimTime.cs@@ -13,6 +13,16 @@ namespace Statecraft.Sim_ => date.AddDays(7),};+ /// <summary>The end of the turn that starts on <paramref name="date"/> when the era ends on <paramref name="boundary"/>+ /// (spec 4.1). A turn that would reach or pass the boundary ends on it. A turn that would leave under 14 days+ /// before it is lengthened to end on it, so the player never gets a turn of a few days with a full turn of+ /// attention. Any other turn is the normal one.</summary>+ public static DateTime AdvanceTo(DateTime date, TurnLength len, DateTime boundary)+ {+ var next = Advance(date, len);+ return next >= boundary || (boundary - next).TotalDays < 14 ? boundary : next;+ }+/// <summary>Share of a year one turn represents (used to scale yearly rates).</summary>public static double YearFraction(TurnLength len) => len switch{diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.csindex 17c9ced7a..760660705 100644--- a/sim/Statecraft.Sim/Simulation.cs+++ b/sim/Statecraft.Sim/Simulation.cs@@ -38,7 +38,7 @@ namespace Statecraft.Simvar rejected = new List<Rejection>();if (s.GameOver != null){- foreach (var cmd in commands) rejected.Add(new Rejection(cmd, $"The game is over: {s.GameOver}"));+ foreach (var cmd in commands) rejected.Add(new Rejection(cmd, $"The game is over: {PlayerText.GameOver(s.GameOver)}"));return new StepResult(s, why, rejected);}@@ -53,17 +53,27 @@ namespace Statecraft.SimEventSystem.Delegate(c, s, why);var len = SecuritySystem.TurnLengthFor(s.Rung);- var next = SimTime.Advance(s.Date, len);- var yf = SimTime.YearFraction(len);+ // The last era's end is a boundary: the turn that reaches it ends on it, with that turn's real days (spec 4.1, 4.5).+ var end = c.Eras[c.Eras.Count - 1].To;+ var next = SimTime.AdvanceTo(s.Date, len, end);+ var adjusted = next != SimTime.Advance(s.Date, len);+ var days = (next - s.Date).Days;+ var yf = adjusted ? days / 365.0 : SimTime.YearFraction(len);EffectsSystem.Apply(c, s, why);PopulationSystem.Apply(c, s, next, yf, why);EconomySystem.Apply(c, s, yf, why);PoliticsSystem.UpdateStability(c, s, yf, why);- SecuritySystem.Apply(c, s, len, why);+ if (adjusted) SecuritySystem.Apply(c, s, days / 7, why); // whole weeks of the adjusted turn+ else SecuritySystem.Apply(c, s, len, why);PoliticsSystem.ReportChanges(c, s.Date, next, why);var turnStart = s.Date;s.Date = next;s.Turn++;+ if (s.GameOver == null && s.Date >= end)+ {+ s.GameOver = GameOverCodes.EraEnded; // the legacy report (#19) will come before this once it exists+ why.Add(new Cause("era", "era_ended", 0, PlayerText.GameOver(s.GameOver)));+ }Cabinet.ExpireOnGovernmentChange(c, s, why);AttentionSystem.Refill(c, s);if (s.GameOver == null) EventSystem.Trigger(c, s, why, turnStart); // a game that just ended raises no new eventsdiff --git a/unity/Assets/Scripts/UI/WhyPresenter.cs b/unity/Assets/Scripts/UI/WhyPresenter.csindex 36b6b6e57..6fac1bee2 100644--- a/unity/Assets/Scripts/UI/WhyPresenter.cs+++ b/unity/Assets/Scripts/UI/WhyPresenter.cs@@ -9,7 +9,7 @@ namespace Statecraft.Game.UI/// that produced it, in a fixed order (what was decided first, then its consequences).</summary>public sealed class WhyPresenter : System.IDisposable{- public static readonly string[] Order = { "events", "politics", "cabinet", "security", "economy", "population", "map", "policy", "effects", "situations" };+ public static readonly string[] Order = { "era", "events", "politics", "cabinet", "security", "economy", "population", "map", "policy", "effects", "situations" };readonly VisualElement screen; readonly SimBridge bridge; readonly UiText text;public WhyPresenter(VisualElement root, SimBridge bridge, UiText text)diff --git a/unity/Assets/Tests/EditMode/BudgetScreenTests.cs b/unity/Assets/Tests/EditMode/BudgetScreenTests.csindex 315dd0dfd..2ca19337f 100644--- a/unity/Assets/Tests/EditMode/BudgetScreenTests.cs+++ b/unity/Assets/Tests/EditMode/BudgetScreenTests.cs@@ -221,12 +221,16 @@ public class BudgetScreenTests[Test]public void AVacantMinistryReadsVacant(){- var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ // No budgeted ministry falls vacant in the historical run before the founding era ends (1 January 1957); the first+ // is Agriculture in May 1961. So this test plays on past the end, on its own copy of the content.+ var c = ContentLoader.Load(Paths.Content);+ c.Eras[c.Eras.Count - 1].To = new System.DateTime(1990, 1, 1);+ var g = GameSession.New(c, GoldenRun.Seed, Mode.Historical);Seat vacant = null;for (int i = 0; i < 400 && g.State.GameOver == null && vacant == null; i++){- vacant = Cabinet.Lineup(C, g.State).FirstOrDefault(x => x.Holder == null && g.State.Budget.ContainsKey(x.Office.Id));- if (vacant == null) g.Step(HistoricalAI.Commands(C, g.State));+ vacant = Cabinet.Lineup(c, g.State).FirstOrDefault(x => x.Holder == null && g.State.Budget.ContainsKey(x.Office.Id));+ if (vacant == null) g.Step(HistoricalAI.Commands(c, g.State));}Assert.IsNotNull(vacant, "the historical game has a vacant budgeted ministry to test with");using var ui = new UiTestKit();diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 48499858a..3cb2a1bb8 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -45,6 +45,7 @@ budget.queued: "Submitted: takes effect at End Turn"budget.unsaved: "Changed: submit to put it to the vote"why.turn: "{0} to {1}"why.empty: "Nothing has happened yet: end the turn to see its causes."+why.era: "Chapter"why.events: "Events"why.politics: "Politics"why.cabinet: "Cabinet"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex cf3c98efd..9ea87263e 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -50,6 +50,7 @@ budget.queued: "הוגש: ייכנס לתוקף בסיום התור"budget.unsaved: "שונה: יש להגיש כדי להעמיד להצבעה"why.turn: "מ־{0} עד {1}"why.empty: "עדיין לא קרה דבר: יש לסיים את התור כדי לראות את הסיבות."+why.era: "פרק"why.events: "אירועים"why.politics: "פוליטיקה"why.cabinet: "ממשלה"