A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
fix(sim): Cause text uses content display names and the one date format
eyalgolan666a14f29e7e
diff --git a/content/aliyah.yaml b/content/aliyah.yamlindex 558945013..6595c2aa6 100644--- a/content/aliyah.yaml+++ b/content/aliyah.yaml@@ -1,4 +1,12 @@# Immigrants by continent of origin, CBS figures as tabulated by the Jewish Virtual Library.+# Display names of the origin groups (shown to the player; required). "unknown" is the CBS column for immigrants whose+# country of origin was not recorded.+regions:+ - { id: asia, name: Asia }+ - { id: africa, name: Africa }+ - { id: europe, name: Europe }+ - { id: america_oceania, name: the Americas and Oceania }+ - { id: unknown, name: country of origin not recorded }series:- from: 1948-05-15to: 1948-12-31diff --git a/content/model.yaml b/content/model.yamlindex 086092c46..7999bf27d 100644--- a/content/model.yaml+++ b/content/model.yaml@@ -1,28 +1,29 @@-# Game design values (not historical facts): indicators run 0..1.+# Game design values (not historical facts): indicators run 0..1. Every indicator, policy, effect and situation has a+# `name`: the display name Cause text shows the player (required; ids never reach the screen).indicators:- - { id: morale, base: 0.55 }- - { id: food_supply, base: 0.40 }- - { id: housing, base: 0.35 }- - { id: security, base: 0.30 }- - { id: intl_standing, base: 0.50 }+ - { id: morale, base: 0.55, name: Morale }+ - { id: food_supply, base: 0.40, name: Food supply }+ - { id: housing, base: 0.35, name: Housing }+ - { id: security, base: 0.30, name: Security }+ - { id: intl_standing, base: 0.50, name: International standing }policies:- - { id: rationing, default: 0.0, office: rationing_minister }- - { id: housing_construction, default: 0.3, office: labour_minister }- - { id: border_settlement, default: 0.2, office: agriculture_minister }+ - { id: rationing, default: 0.0, office: rationing_minister, name: Rationing }+ - { id: housing_construction, default: 0.3, office: labour_minister, name: Housing construction }+ - { id: border_settlement, default: 0.2, office: agriculture_minister, name: Border settlement }# 1 = transit camps (ma'abarot) where residents earn their own living replace the free-board immigrant camps.# Transit-camp map actions need it at 0.5 or above (MapActions). The event maabarot_policy sets it. Office: the Prime# Minister, who decided it with the Jewish Agency (and the Ministry of Immigration ends on 1951-10-08).- - { id: maabarot, default: 0.0, office: prime_minister }+ - { id: maabarot, default: 0.0, office: prime_minister, name: Transit camps (ma'abarot) }effects:- - { id: rationing_feeds, source: rationing, target: food_supply, k: 0.40, inertia: 2, office: rationing_minister }- - { id: rationing_grates, source: rationing, target: morale, k: -0.15, inertia: 1 }- - { id: building_houses, source: housing_construction, target: housing, k: 0.35, inertia: 4, office: labour_minister }- - { id: homes_lift_morale, source: housing, target: morale, k: 0.15, inertia: 2 }- - { id: border_villages_secure, source: border_settlement, target: security, k: 0.30, inertia: 4, office: agriculture_minister }- - { id: safety_lifts_morale, source: security, target: morale, k: 0.10, inertia: 2 }+ - { id: rationing_feeds, source: rationing, target: food_supply, k: 0.40, inertia: 2, office: rationing_minister, name: Rations share out food }+ - { id: rationing_grates, source: rationing, target: morale, k: -0.15, inertia: 1, name: Rationing wears on morale }+ - { id: building_houses, source: housing_construction, target: housing, k: 0.35, inertia: 4, office: labour_minister, name: New housing }+ - { id: homes_lift_morale, source: housing, target: morale, k: 0.15, inertia: 2, name: Homes lift morale }+ - { id: border_villages_secure, source: border_settlement, target: security, k: 0.30, inertia: 4, office: agriculture_minister, name: Border villages }+ - { id: safety_lifts_morale, source: security, target: morale, k: 0.10, inertia: 2, name: Safety lifts morale }situations:- - { id: food_crisis, indicator: food_supply, on_below: 0.30, off_above: 0.45 }- - { id: housing_crisis, indicator: housing, on_below: 0.25, off_above: 0.40 }+ - { id: food_crisis, indicator: food_supply, on_below: 0.30, off_above: 0.45, name: Food crisis }+ - { id: housing_crisis, indicator: housing, on_below: 0.25, off_above: 0.40, name: Housing crisis }voter_groups:- { id: veterans, weights: { morale: 0.6, security: 0.4 } }- { id: new_immigrants, weights: { housing: 0.5, food_supply: 0.5 } }diff --git a/sim/Statecraft.Sim.Tests/CabinetTests.cs b/sim/Statecraft.Sim.Tests/CabinetTests.csindex 958535081..ea49bc8f9 100644--- a/sim/Statecraft.Sim.Tests/CabinetTests.cs+++ b/sim/Statecraft.Sim.Tests/CabinetTests.cs@@ -78,7 +78,7 @@ public class CabinetTests[Theory][InlineData("prime_minister", "loyalist", "You are the Prime Minister: that office is not yours to fill")][InlineData("finance_minister", "outsider", "Out Sider's party (Beta) is not in the coalition")]- [InlineData("finance_minister", "gone", "Gone Early died on 1948-05-01")]+ [InlineData("finance_minister", "gone", "Gone Early died on 1 May 1948")][InlineData("finance_minister", "def_two", "Def Two already holds the office of Minister of Finance")][InlineData("finance_minister", "nobody", "Unknown person 'nobody'")][InlineData("treasurer", "loyalist", "Unknown office 'treasurer'")]@@ -165,7 +165,7 @@ public class CabinetTestspublic void AnAbolishedOfficeCannotBeFilled(){var s = new GameState { Date = new DateTime(1948, 12, 1) };- Assert.Equal("The office of Old Office was abolished on 1948-12-01", Cabinet.Check(Rich, s, "old_office", "loyalist"));+ Assert.Equal("The office of Old Office was abolished on 1 December 1948", Cabinet.Check(Rich, s, "old_office", "loyalist"));}/// <summary>Step refills attention at the end of the turn, so the spend is observed through what the same turn can still@@ -268,7 +268,7 @@ public class CabinetTestsvar c = ContentLoader.Load(RealContentTests.ContentRoot());var s = new GameState { Date = new DateTime(1951, 1, 1) };Assert.Equal("Golda Meir is not an IDF career officer", Cabinet.Check(c, s, "chief_of_staff", "golda_meir"));- Assert.Equal("The office of Minister of War Victims was abolished on 1951-10-08",+ Assert.Equal("The office of Minister of War Victims was abolished on 8 October 1951",Cabinet.Check(c, new GameState { Date = new DateTime(1951, 11, 1) }, "war_victims_minister", "maimon"));Assert.Equal("Aharon Zisling's party (Mapam) is not in the coalition", Cabinet.Check(c, s, "agriculture_minister", "zisling"));Assert.Equal("The President is elected by the Knesset, not appointed", Cabinet.Check(c, s, "president", "sharett"));@@ -276,6 +276,6 @@ public class CabinetTestsAssert.Equal("Chaim Weizmann is the President", Cabinet.Check(c, s, "finance_minister", "weizmann"));Assert.Equal("Yigael Yadin is the serving Chief of Staff", Cabinet.Check(c, s, "finance_minister", "yadin"));s.Date = new DateTime(1951, 6, 1);- Assert.Equal("David Remez died on 1951-05-19", Cabinet.Check(c, s, "transportation_minister", "remez"));+ Assert.Equal("David Remez died on 19 May 1951", Cabinet.Check(c, s, "transportation_minister", "remez"));}}diff --git a/sim/Statecraft.Sim.Tests/CultureTests.cs b/sim/Statecraft.Sim.Tests/CultureTests.csindex c67e34f97..15a3abb46 100644--- a/sim/Statecraft.Sim.Tests/CultureTests.cs+++ b/sim/Statecraft.Sim.Tests/CultureTests.cs@@ -60,7 +60,7 @@ options:{var expected = Run(CultureInfo.InvariantCulture);Assert.Contains(expected, m => m.Contains("9,160 immigrants")); // grouping is exercised- Assert.Contains(expected, m => m.Contains("elected 1949-01-25")); // calendar is exercised+ Assert.Contains(expected, m => m.Contains("elected 25 January 1949")); // calendar is exercisedAssert.Equal(expected, Run(new CultureInfo(culture)));}}diff --git a/sim/Statecraft.Sim.Tests/EconomyM3Tests.cs b/sim/Statecraft.Sim.Tests/EconomyM3Tests.csindex afe45ce9a..7f8739b6b 100644--- a/sim/Statecraft.Sim.Tests/EconomyM3Tests.cs+++ b/sim/Statecraft.Sim.Tests/EconomyM3Tests.cs@@ -41,7 +41,7 @@ public class EconomyM3TestsAssert.Contains(EconomySystem.FxCrisis, s.ActiveSituations);Assert.Equal(0.4 - 0.1, s.Indicators["food_supply"], 9);Assert.Equal(-0.1, s.IndicatorShifts["food_supply"], 9);- Assert.Contains(why, w => w.Target == "food_supply" && w.Message == "food_supply -0.100 (foreign currency crisis: food imports cut)");+ Assert.Contains(why, w => w.Target == "food_supply" && w.Message == "Food supply -0.100 (foreign currency crisis: food imports cut)");}[Fact]diff --git a/sim/Statecraft.Sim.Tests/EffectsTests.cs b/sim/Statecraft.Sim.Tests/EffectsTests.csindex f8b24b240..1445d2087 100644--- a/sim/Statecraft.Sim.Tests/EffectsTests.cs+++ b/sim/Statecraft.Sim.Tests/EffectsTests.cs@@ -38,7 +38,7 @@ public class EffectsTestsAssert.Equal(2, food.Count); // one truthful cause per turn the indicator movedAssert.Equal(0.14, food[0].Delta, 9);Assert.Equal(0.07, food[1].Delta, 9);- Assert.All(food, w => Assert.Contains("rationing_food", w.Message));+ Assert.All(food, w => Assert.Contains("Rations feed people", w.Message));}[Fact]@@ -46,7 +46,7 @@ public class EffectsTests{// Two effects on food_supply: one cause for the indicator, naming both, with the real change.var model = Fixture.Files["model.yaml"].Replace("situations:",- " - id: rationing_food2\n source: rationing\n target: food_supply\n k: 0.1\n inertia: 1\nsituations:");+ " - id: rationing_food2\n source: rationing\n target: food_supply\n k: 0.1\n inertia: 1\n name: More rations\nsituations:");var c = ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["model.yaml"] = model }));var s = new GameState { Date = new DateTime(1948, 6, 1) };EffectsSystem.Init(c, s);@@ -57,7 +57,7 @@ public class EffectsTestsAssert.Equal(0.64, s.Indicators["food_supply"], 9); // 0.4 + 0.14 + 0.1var cause = Assert.Single(why, w => w.System == "effects" && w.Target == "food_supply");Assert.Equal(s.Indicators["food_supply"] - before, cause.Delta, 12);- Assert.Equal("food_supply +0.240 (rationing_food, rationing_food2)", cause.Message);+ Assert.Equal("Food supply +0.240 (Rations feed people, More rations)", cause.Message);}[Fact]diff --git a/sim/Statecraft.Sim.Tests/EventTests.cs b/sim/Statecraft.Sim.Tests/EventTests.csindex 9bc163393..48c43cbcb 100644--- a/sim/Statecraft.Sim.Tests/EventTests.cs+++ b/sim/Statecraft.Sim.Tests/EventTests.cs@@ -524,7 +524,7 @@ options:var s = State(c, new DateTime(1948, 6, 1)); var why = new List<Cause>();EventSystem.Trigger(c, s, why);Assert.Null(EventSystem.Choose(c, s, "shortage", "import", why));- Assert.Contains(why, w => w.Message == "fx_reserves +0.00 (shortage/import)");+ Assert.Contains(why, w => w.Message == "Foreign currency reserves +0.00 (Bread lines)");Assert.DoesNotContain(why, w => w.Message.Contains("-+"));}diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.csindex 8303a722b..8793beaf8 100644--- a/sim/Statecraft.Sim.Tests/Fixture.cs+++ b/sim/Statecraft.Sim.Tests/Fixture.cs@@ -79,17 +79,22 @@ governments:indicators:- id: moralebase: 0.5+ name: Morale- id: food_supplybase: 0.4+ name: Food supply- id: housingbase: 0.3+ name: Housingpolicies:- id: rationingdefault: 0.0office: finance_minister+ name: Rationing- id: maabarotdefault: 0.0office: finance_minister+ name: Transit campseffects:- id: rationing_foodsource: rationing@@ -97,16 +102,19 @@ effects:k: 0.4inertia: 2office: finance_minister+ name: Rations feed people- id: rationing_moralesource: rationingtarget: moralek: -0.2inertia: 1+ name: Rationing wears on moralesituations:- id: hungerindicator: food_supplyon_below: 0.3off_above: 0.45+ name: Hungervoter_groups:- id: everyoneweights: { morale: 1.0 }@@ -166,6 +174,9 @@ settlements:- { id: town_a, name: Town A, lon: 34.29, lat: 33.35, type: town, founded: 1900, pre_modern: false }",["aliyah.yaml"] = @"+regions:+ - { id: europe, name: Europe }+ - { id: asia, name: Asia }series:- from: 1948-05-15to: 1948-12-31diff --git a/sim/Statecraft.Sim.Tests/MapActionTests.cs b/sim/Statecraft.Sim.Tests/MapActionTests.csindex 359d4accd..d2de8f533 100644--- a/sim/Statecraft.Sim.Tests/MapActionTests.cs+++ b/sim/Statecraft.Sim.Tests/MapActionTests.cs@@ -75,7 +75,7 @@ public class MapActionTests{var s = Ready();s.Date = new DateTime(1948, 5, 31);- Assert.Equal("Transit camps and housing projects can be placed from 1948-06-01", MapActions.Check(C, s, "housing", 2, 0));+ Assert.Equal("Transit camps and housing projects can be placed from 1 June 1948", MapActions.Check(C, s, "housing", 2, 0));}[Fact]@@ -207,6 +207,6 @@ public class MapActionTestsvar tlv = c.SettlementHexes.Single(x => x.Id == "tel_aviv");Assert.Null(MapActions.Check(c, s, "transit_camp", tlv.Q, tlv.R));var s1949 = GoldenRun.Play(c, new DateTime(1949, 6, 1));- Assert.Equal("Transit camps and housing projects can be placed from 1950-01-01", MapActions.Check(c, s1949, "housing", tlv.Q, tlv.R));+ Assert.Equal("Transit camps and housing projects can be placed from 1 January 1950", MapActions.Check(c, s1949, "housing", tlv.Q, tlv.R));}}diff --git a/sim/Statecraft.Sim.Tests/PlayerTextTests.cs b/sim/Statecraft.Sim.Tests/PlayerTextTests.csnew file mode 100644index 000000000..50c69b570--- /dev/null+++ b/sim/Statecraft.Sim.Tests/PlayerTextTests.cs@@ -0,0 +1,81 @@+using System;+using System.Collections.Generic;+using System.Linq;+using System.Text.RegularExpressions;+using Statecraft.Sim;++/// <summary>Player-facing text (spec: player-facing text): Cause messages and refusal reasons use display names from+/// content and the one date format, never content ids or ISO dates (playtest 1, items 4 and 5).</summary>+public class PlayerTextTests+{+ static readonly Regex SnakeId = new Regex("[a-z]+_[a-z]+");+ static readonly Regex IsoDate = new Regex(@"\d{4}-\d{2}-\d{2}");++ static List<string> HistoricalCauseMessages()+ {+ var c = ContentLoader.Load(RealContentTests.ContentRoot());+ var s = Simulation.NewGame(c, GoldenRun.Seed, Mode.Historical);+ var messages = new List<string>();+ for (int turn = 0; turn < 1000 && s.Date < GoldenRun.Until1952 && s.GameOver == null; turn++)+ {+ var r = Simulation.Step(c, s, HistoricalAI.Commands(c, s));+ messages.AddRange(r.Why.Select(w => w.Message));+ s = r.State;+ }+ return messages;+ }++ [Fact]+ public void NoCauseInTheHistoricalRunShowsAContentIdOrAnIsoDate()+ {+ var messages = HistoricalCauseMessages();+ Assert.NotEmpty(messages);+ var bad = messages.Where(m => SnakeId.IsMatch(m) || IsoDate.IsMatch(m)).Distinct().ToList();+ Assert.True(bad.Count == 0, "Cause text shows ids or ISO dates:\n" + string.Join("\n", bad.Take(40)));+ }++ [Fact]+ public void CausesNameRegionsEffectsAndEventsByTheirDisplayNames()+ {+ var messages = HistoricalCauseMessages();+ Assert.Contains(messages, m => m.EndsWith("immigrants arrived (the Americas and Oceania)", StringComparison.Ordinal));+ Assert.Contains(messages, m => m.EndsWith("immigrants arrived (country of origin not recorded)", StringComparison.Ordinal));+ Assert.Contains(messages, m => m.StartsWith("Morale ", StringComparison.Ordinal) && m.Contains("Homes lift morale"));+ Assert.Contains(messages, m => m.StartsWith("International standing +0.05 (Armistice with Egypt)", StringComparison.Ordinal));+ Assert.Contains(messages, m => m.Contains("elected 25 January 1949"));+ }++ [Fact]+ public void DatesUseTheDayMonthYearFormat()+ {+ Assert.Equal("15 May 1948", PlayerText.Date(new DateTime(1948, 5, 15)));+ Assert.Equal("1 January 1950", PlayerText.Date(new DateTime(1950, 1, 1)));+ Assert.Equal("May 1948", PlayerText.Month(new DateTime(1948, 5, 15)));+ }++ [Fact]+ public void TheMapActionStartDateIsShownInTheDayMonthYearFormat()+ {+ var c = ContentLoader.Load(RealContentTests.ContentRoot());+ var s = Simulation.NewGame(c, GoldenRun.Seed, Mode.Historical);+ var reason = MapActions.Check(c, s, MapActions.Housing, 0, 0);+ Assert.Equal("Transit camps and housing projects can be placed from 1 January 1950", reason);+ }++ /// <summary>Display names are required, non-empty text; an origin needs a named region (file and field named).</summary>+ [Theory]+ [InlineData("model.yaml", " name: Morale\n", "", "indicators[morale].name")]+ [InlineData("model.yaml", " name: Rationing\n", " name: ' '\n", "policies[rationing].name")]+ [InlineData("model.yaml", " name: Rations feed people\n", "", "effects[rationing_food].name")]+ [InlineData("model.yaml", " name: Hunger\n", "", "situations[hunger].name")]+ [InlineData("aliyah.yaml", " - { id: europe, name: Europe }\n", " - { id: europe }\n", "regions[europe].name")]+ [InlineData("aliyah.yaml", " - { id: europe, name: Europe }\n", " - { id: europe, name: '' }\n", "regions[europe].name")]+ [InlineData("aliyah.yaml", " - { id: asia, name: Asia }\n", "", "series[0].origins.asia")]+ [InlineData("aliyah.yaml", " - { id: asia, name: Asia }\n", " - { id: europe, name: Asia }\n", "regions[europe].id")]+ public void DisplayNamesAreRequired(string file, string from, string to, string field)+ {+ var ex = ValidationTests.Bad(file, from, to);+ Assert.Equal(file, ex.File);+ Assert.Equal(field, ex.Field);+ }+}diff --git a/sim/Statecraft.Sim.Tests/PopulationTests.cs b/sim/Statecraft.Sim.Tests/PopulationTests.csindex 8d4b5ce63..06586e2d9 100644--- a/sim/Statecraft.Sim.Tests/PopulationTests.cs+++ b/sim/Statecraft.Sim.Tests/PopulationTests.cs@@ -42,7 +42,7 @@ public class PopulationTestspublic void ArrivalsAcrossLeapDayAndYearEndSumToThePeriodTotal(){// 1951-12-10..1952-03-20 inclusive = 22 + 31 + 29 (leap year) + 20 = 102 days.- var aliyah = "series:\n - from: 1951-12-10\n to: 1952-03-20\n origins: { europe: 1000 }\n";+ var aliyah = "regions:\n - { id: europe, name: Europe }\nseries:\n - from: 1951-12-10\n to: 1952-03-20\n origins: { europe: 1000 }\n";var c = ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["aliyah.yaml"] = aliyah }));double sum = 0;for (var d = new DateTime(1951, 10, 1); d < new DateTime(1952, 7, 1); d = d.AddMonths(3))diff --git a/sim/Statecraft.Sim.Tests/SimTests.cs b/sim/Statecraft.Sim.Tests/SimTests.csindex 24796e491..1a6149fc1 100644--- a/sim/Statecraft.Sim.Tests/SimTests.cs+++ b/sim/Statecraft.Sim.Tests/SimTests.cs@@ -164,7 +164,7 @@ options:var r = Simulation.Step(C, s0, new Command[] { new SetPolicy("rationing", 0.5) });Assert.Empty(r.Rejected);Assert.Equal(0.5, r.State.Policies["rationing"]);- Assert.Contains(r.Why, w => w.System == "policy" && w.Message == "rationing set to 0.50");+ Assert.Contains(r.Why, w => w.System == "policy" && w.Message == "Rationing set to 0.50");}[Fact]@@ -210,7 +210,7 @@ options:var r = Simulation.Step(C, s0, new Command[] { cmd, cmd, cmd });Assert.Equal(new[] { "Not enough attention (need 1.0, have 0.0)" }, r.Rejected.Select(x => x.Reason));Assert.Equal(0.0, r.State.Policies["rationing"]);- Assert.Equal(2, r.Why.Count(w => w.System == "politics" && w.Target == "rationing" && w.Message == "House voted down rationing 0.90"));+ Assert.Equal(2, r.Why.Count(w => w.System == "politics" && w.Target == "rationing" && w.Message == "House voted down Rationing 0.90"));}[Theory]diff --git a/sim/Statecraft.Sim/Cabinet.cs b/sim/Statecraft.Sim/Cabinet.csindex 14c85e612..373de16ac 100644--- a/sim/Statecraft.Sim/Cabinet.cs+++ b/sim/Statecraft.Sim/Cabinet.cs@@ -71,13 +71,13 @@ namespace Statecraft.Simvar office = c.Offices.FirstOrDefault(o => o.Id == officeId);if (office == null) return $"Unknown office '{officeId}'";if (office.Until.HasValue && s.Date >= office.Until.Value)- return FormattableString.Invariant($"The office of {office.Title} was abolished on {office.Until:yyyy-MM-dd}");+ return $"The office of {office.Title} was abolished on {PlayerText.Date(office.Until.Value)}";if (officeId == "prime_minister") return "You are the Prime Minister: that office is not yours to fill";if (officeId == "president") return "The President is elected by the Knesset, not appointed";var person = c.People.FirstOrDefault(p => p.Id == personId);if (person == null) return $"Unknown person '{personId}'";if (person.Died.HasValue && s.Date >= person.Died.Value)- return FormattableString.Invariant($"{person.Name} died on {person.Died:yyyy-MM-dd}");+ return $"{person.Name} died on {PlayerText.Date(person.Died.Value)}";if (Holder(c, s, "president")?.Id == personId) return $"{person.Name} is the President";if (officeId != "chief_of_staff" && Holder(c, s, "chief_of_staff")?.Id == personId) return $"{person.Name} is the serving Chief of Staff";if (Holder(c, s, officeId)?.Id == personId) return $"{person.Name} already holds the office of {office.Title}";diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.csindex 0856bf8db..e2ffa9ed2 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -74,13 +74,21 @@ namespace Statecraft.Simpublic string Status { get; set; } = "draft";}- public sealed class Indicator { public string Id { get; set; } = ""; public double Base { get; set; } }+ public sealed class Indicator+ {+ public string Id { get; set; } = "";+ public double Base { get; set; }+ /// <summary>Display name shown to the player (Cause text); required.</summary>+ public string Name { get; set; } = "";+ }public sealed class Policy{public string Id { get; set; } = "";public double Default { get; set; }public string Office { get; set; } = "";+ /// <summary>Display name shown to the player (Cause text); required.</summary>+ public string Name { get; set; } = "";}/// <summary>Additive effect: its contribution to Target moves toward K * source value over Inertia turns.</summary>@@ -92,6 +100,8 @@ namespace Statecraft.Simpublic double K { get; set; }public int Inertia { get; set; } = 1;public string Office { get; set; } = "";+ /// <summary>Short display name shown to the player (Cause text); required.</summary>+ public string Name { get; set; } = "";}/// <summary>Turns on past one threshold and off past another (hysteresis), so it does not flicker.</summary>@@ -103,6 +113,8 @@ namespace Statecraft.Simpublic double? OffAbove { get; set; }public double? OnAbove { get; set; }public double? OffBelow { get; set; }+ /// <summary>Display name shown to the player (Cause text); required.</summary>+ public string Name { get; set; } = "";}public sealed class VoterGroup { public string Id { get; set; } = ""; public Dictionary<string, double> Weights { get; set; } = new Dictionary<string, double>(); }@@ -156,6 +168,14 @@ namespace Statecraft.Simpublic double Morale { get; set; }}+ /// <summary>An origin group of immigrants (aliyah.yaml regions): the key of AliyahPeriod.Origins.</summary>+ public sealed class Region+ {+ public string Id { get; set; } = "";+ /// <summary>Display name shown to the player (Cause text); required.</summary>+ public string Name { get; set; } = "";+ }+public sealed class AliyahPeriod{public DateTime From { get; set; }@@ -243,6 +263,8 @@ namespace Statecraft.Simpublic List<Actor> Actors = new List<Actor>();public Rules Rules = new Rules();public List<AliyahPeriod> Aliyah = new List<AliyahPeriod>();+ /// <summary>Origin groups of the aliyah series, with display names (aliyah.yaml regions).</summary>+ public List<Region> Regions = new List<Region>();public List<PopulationAnchor> PopulationAnchors = new List<PopulationAnchor>();public List<GameEvent> Events = new List<GameEvent>();List<MapHex> _hexes = new List<MapHex>();diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex 3632b3169..30e4e5e61 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -26,7 +26,11 @@ namespace Statecraft.Simpublic List<VoterGroup> VoterGroups { get; set; } = new List<VoterGroup>();public List<Actor> Actors { get; set; } = new List<Actor>();}- sealed class AliyahFile { public List<AliyahPeriod> Series { get; set; } = new List<AliyahPeriod>(); }+ sealed class AliyahFile+ {+ public List<Region> Regions { get; set; } = new List<Region>();+ public List<AliyahPeriod> Series { get; set; } = new List<AliyahPeriod>();+ }sealed class PopulationFile { public List<PopulationAnchor> Anchors { get; set; } = new List<PopulationAnchor>(); }sealed class HexBounds { public double Lon0 { get; set; } public double Lon1 { get; set; } public double Lat0 { get; set; } public double Lat1 { get; set; } }/// <summary>hexes.json is JSON, which YAML 1.2 reads as a flow mapping; every key the tool writes is declared.</summary>@@ -157,7 +161,8 @@ namespace Statecraft.Simc.Indicators = m.Indicators; c.Policies = m.Policies; c.Effects = m.Effects;c.Situations = m.Situations; c.VoterGroups = m.VoterGroups; c.Actors = m.Actors;c.Rules = Read<Rules>(readFile, "rules.yaml");- c.Aliyah = Read<AliyahFile>(readFile, "aliyah.yaml").Series;+ var aliyah = Read<AliyahFile>(readFile, "aliyah.yaml");+ c.Aliyah = aliyah.Series; c.Regions = aliyah.Regions;c.PopulationAnchors = Read<PopulationFile>(readFile, "population.yaml").Anchors;c.Hexes = Read<MapFile>(readFile, HexesFile).Hexes;c.SettlementHexes = Read<SettlementHexesFile>(readFile, SettlementHexesFileName).Settlements;@@ -215,6 +220,12 @@ namespace Statecraft.Simstatic readonly HashSet<string> Statuses = new HashSet<string> { "draft", "fact-checked", "historian-reviewed", "sensitivity-reviewed" };+ /// <summary>A display name: required, and not blank.</summary>+ static void Named(string file, string field, string name)+ {+ if (string.IsNullOrWhiteSpace(name)) throw new ContentException(file, field, "required (the name shown to the player)");+ }+internal static void Status(string file, string field, string status){if (!Statuses.Contains(status))@@ -277,6 +288,13 @@ namespace Statecraft.SimUnique("model.yaml", "situations", c.Situations.Select(s => s.Id));Unique("model.yaml", "voter_groups", c.VoterGroups.Select(v => v.Id));Unique("model.yaml", "actors", c.Actors.Select(a => a.Id));+ Unique("aliyah.yaml", "regions", c.Regions.Select(g => g.Id));+ // Display names (spec: player-facing text): Cause messages show these, never the ids.+ foreach (var i in c.Indicators) Named("model.yaml", $"indicators[{i.Id}].name", i.Name);+ foreach (var p in c.Policies) Named("model.yaml", $"policies[{p.Id}].name", p.Name);+ foreach (var e in c.Effects) Named("model.yaml", $"effects[{e.Id}].name", e.Name);+ foreach (var s in c.Situations) Named("model.yaml", $"situations[{s.Id}].name", s.Name);+ foreach (var g in c.Regions) Named("aliyah.yaml", $"regions[{g.Id}].name", g.Name);foreach (var p in c.Policies)if (indicators.Contains(p.Id)) throw new ContentException("model.yaml", $"policies[{p.Id}].id", "same id as an indicator (effect sources would be ambiguous)");@@ -441,7 +459,11 @@ namespace Statecraft.Simvar a = c.Aliyah[i]; var path = FormattableString.Invariant($"series[{i}]");if (a.From == default) throw new ContentException("aliyah.yaml", path + ".from", "required");if (a.To < a.From) throw new ContentException("aliyah.yaml", path + ".to", "required, on or after from (both dates are inclusive)");- foreach (var kv in a.Origins) Count("aliyah.yaml", $"{path}.origins.{kv.Key}", kv.Value);+ foreach (var kv in a.Origins)+ {+ if (c.Regions.All(g => g.Id != kv.Key)) throw new ContentException("aliyah.yaml", $"{path}.origins.{kv.Key}", $"unknown region '{kv.Key}' (add it to regions with a name)");+ Count("aliyah.yaml", $"{path}.origins.{kv.Key}", kv.Value);+ }}for (int i = 0; i < c.PopulationAnchors.Count; i++){diff --git a/sim/Statecraft.Sim/EconomySystem.cs b/sim/Statecraft.Sim/EconomySystem.csindex 0212e4a5c..7baaffaf9 100644--- a/sim/Statecraft.Sim/EconomySystem.cs+++ b/sim/Statecraft.Sim/EconomySystem.cs@@ -61,7 +61,7 @@ namespace Statecraft.Sim{var change = EffectsSystem.Shift(c, s, "food_supply", r.FxCrisisFoodPerYear * yearFraction);if (change != 0)- why.Add(new Cause("economy", "food_supply", change, FormattableString.Invariant($"food_supply {change:+0.000;-0.000;+0.000} (foreign currency crisis: food imports cut)")));+ why.Add(new Cause("economy", "food_supply", change, FormattableString.Invariant($"{PlayerText.Target(c, "food_supply")} {change:+0.000;-0.000;+0.000} (foreign currency crisis: food imports cut)")));}}diff --git a/sim/Statecraft.Sim/EffectsSystem.cs b/sim/Statecraft.Sim/EffectsSystem.csindex b178f79de..1e2a7c970 100644--- a/sim/Statecraft.Sim/EffectsSystem.cs+++ b/sim/Statecraft.Sim/EffectsSystem.cs@@ -55,9 +55,9 @@ namespace Statecraft.Sim{var delta = s.Indicators[i.Id] - before[i.Id];if (Math.Abs(delta) <= 1e-9) continue;- var ids = c.Effects.Where(e => e.Target == i.Id && moved.Contains(e.Id)).Select(e => e.Id).ToList();- var from = ids.Count > 0 ? $" ({string.Join(", ", ids)})" : "";- why.Add(new Cause("effects", i.Id, delta, FormattableString.Invariant($"{i.Id} {delta:+0.000;-0.000;+0.000}{from}")));+ var names = c.Effects.Where(e => e.Target == i.Id && moved.Contains(e.Id)).Select(e => e.Name).ToList();+ var from = names.Count > 0 ? $" ({string.Join(", ", names)})" : "";+ why.Add(new Cause("effects", i.Id, delta, FormattableString.Invariant($"{i.Name} {delta:+0.000;-0.000;+0.000}{from}")));}UpdateSituations(c, s, why);}@@ -91,8 +91,8 @@ namespace Statecraft.Simbool on = s.ActiveSituations.Contains(sit.Id);bool turnOn = sit.OnBelow.HasValue ? v < sit.OnBelow.Value : v > sit.OnAbove!.Value;bool turnOff = sit.OffAbove.HasValue ? v > sit.OffAbove.Value : v < sit.OffBelow!.Value;- if (!on && turnOn) { s.ActiveSituations.Add(sit.Id); why.Add(new Cause("situations", sit.Id, 1, FormattableString.Invariant($"{sit.Id} began ({sit.Indicator} = {v:0.00})"))); }- else if (on && turnOff) { s.ActiveSituations.Remove(sit.Id); why.Add(new Cause("situations", sit.Id, -1, FormattableString.Invariant($"{sit.Id} ended ({sit.Indicator} = {v:0.00})"))); }+ if (!on && turnOn) { s.ActiveSituations.Add(sit.Id); why.Add(new Cause("situations", sit.Id, 1, FormattableString.Invariant($"{sit.Name} began ({PlayerText.Target(c, sit.Indicator)} = {v:0.00})"))); }+ else if (on && turnOff) { s.ActiveSituations.Remove(sit.Id); why.Add(new Cause("situations", sit.Id, -1, FormattableString.Invariant($"{sit.Name} ended ({PlayerText.Target(c, sit.Indicator)} = {v:0.00})"))); }}}diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.csindex ac379b232..3ec009e7e 100644--- a/sim/Statecraft.Sim/EventSystem.cs+++ b/sim/Statecraft.Sim/EventSystem.cs@@ -56,6 +56,7 @@ namespace Statecraft.Sim{s.PendingEvents.Remove(eventId);var fillDate = FillDate(Get(c, eventId), s.Date);+ var title = Cabinet.Fill(c, s, Get(c, eventId).Title, fillDate);why.Add(new Cause("events", eventId, 0, $"{how}: {Cabinet.Fill(c, s, o.Text, fillDate)}"));foreach (var fx in o.Effects){@@ -63,12 +64,12 @@ namespace Statecraft.Simif (fx.Target == "treasury") s.Treasury += fx.Delta;else if (fx.Target == "fx_reserves") s.FxReserves += fx.Delta;else change = EffectsSystem.Shift(c, s, fx.Target, fx.Delta);- why.Add(new Cause("events", fx.Target, change, FormattableString.Invariant($"{fx.Target} {change:+0.00;-0.00;+0.00} ({eventId}/{o.Id})")));+ why.Add(new Cause("events", fx.Target, change, FormattableString.Invariant($"{PlayerText.Target(c, fx.Target)} {change:+0.00;-0.00;+0.00} ({title})")));}foreach (var kv in o.SetPolicy.OrderBy(k => k.Key, StringComparer.Ordinal)){s.Policies[kv.Key] = kv.Value;- why.Add(new Cause("events", kv.Key, kv.Value, FormattableString.Invariant($"{kv.Key} set to {kv.Value:0.00} ({eventId}/{o.Id})")));+ why.Add(new Cause("events", kv.Key, kv.Value, FormattableString.Invariant($"{PlayerText.Target(c, kv.Key)} set to {kv.Value:0.00} ({title})")));}if (o.SetRung.HasValue) SecuritySystem.SetRung(c, s, o.SetRung.Value, why);}diff --git a/sim/Statecraft.Sim/MapActions.cs b/sim/Statecraft.Sim/MapActions.csindex c8df76ab0..5f8d2845c 100644--- a/sim/Statecraft.Sim/MapActions.cs+++ b/sim/Statecraft.Sim/MapActions.cs@@ -44,7 +44,7 @@ namespace Statecraft.Simvar rule = c.Rules.MapActions.TryGetValue(action, out var x) ? x : null;if (rule == null) return $"Map action '{action}' is not available in this content";if (s.Date < c.Rules.MapActionsFrom)- return FormattableString.Invariant($"Transit camps and housing projects can be placed from {c.Rules.MapActionsFrom:yyyy-MM-dd}");+ return $"Transit camps and housing projects can be placed from {PlayerText.Date(c.Rules.MapActionsFrom)}";if (action == TransitCamp && !(s.Policies.TryGetValue(MaabarotPolicy, out var m) && m >= 0.5))return "Transit camps need the ma'abarot policy";var hex = c.HexAt(q, r);diff --git a/sim/Statecraft.Sim/PlayerText.cs b/sim/Statecraft.Sim/PlayerText.csnew file mode 100644index 000000000..7e6582c6f--- /dev/null+++ b/sim/Statecraft.Sim/PlayerText.cs@@ -0,0 +1,30 @@+using System;+using System.Globalization;+using System.Linq;++namespace Statecraft.Sim+{+ /// <summary>Player-facing wording shared by the sim (Cause text, refusal reasons) and the UI: the one date format+ /// ("15 May 1948") and the display names content gives its ids. No player-facing string shows a content id or an+ /// ISO date (spec: player-facing text).</summary>+ public static class PlayerText+ {+ /// <summary>"15 May 1948".</summary>+ public static string Date(DateTime d) => d.ToString("d MMMM yyyy", CultureInfo.InvariantCulture);++ /// <summary>"May 1948".</summary>+ public static string Month(DateTime d) => d.ToString("MMMM yyyy", CultureInfo.InvariantCulture);++ /// <summary>The display name of an aliyah origin group (aliyah.yaml regions).</summary>+ public static string Region(Content c, string id) => c.Regions.FirstOrDefault(r => r.Id == id)?.Name ?? id;++ /// <summary>The display name of what a cause changes: an indicator or policy (model.yaml names), the treasury or+ /// the foreign currency reserves.</summary>+ public static string Target(Content c, string id) => id switch+ {+ "treasury" => "Treasury",+ "fx_reserves" => "Foreign currency reserves",+ _ => c.Indicators.FirstOrDefault(i => i.Id == id)?.Name ?? c.Policies.FirstOrDefault(p => p.Id == id)?.Name ?? id,+ };+ }+}diff --git a/sim/Statecraft.Sim/PoliticsSystem.cs b/sim/Statecraft.Sim/PoliticsSystem.csindex 4a95ab1f5..7dfc7a6ba 100644--- a/sim/Statecraft.Sim/PoliticsSystem.cs+++ b/sim/Statecraft.Sim/PoliticsSystem.cs@@ -50,7 +50,7 @@ namespace Statecraft.Simif (l1 != null && l1 != l0){var (seats, size) = CoalitionSeats(c, to);- var elected = l1.Elected.HasValue ? FormattableString.Invariant($", elected {l1.Elected:yyyy-MM-dd}") : "";+ var elected = l1.Elected.HasValue ? $", elected {PlayerText.Date(l1.Elected.Value)}" : "";why.Add(new Cause("politics", l1.Id, 0, FormattableString.Invariant($"{l1.Body} convened ({l1.Size} seats{elected}); coalition holds {seats}/{size}")));}var g0 = Offices.Government(c, from); var g1 = Offices.Government(c, to);diff --git a/sim/Statecraft.Sim/PopulationSystem.cs b/sim/Statecraft.Sim/PopulationSystem.csindex 32c6e6afd..c52d32174 100644--- a/sim/Statecraft.Sim/PopulationSystem.cs+++ b/sim/Statecraft.Sim/PopulationSystem.cs@@ -34,7 +34,7 @@ namespace Statecraft.Simforeach (var kv in Arrivals(c, s.Date, to).OrderBy(k => k.Key, StringComparer.Ordinal)){s.Population[kv.Key] = (s.Population.TryGetValue(kv.Key, out var v) ? v : 0) + kv.Value;- if (kv.Value > 0) why.Add(new Cause("population", kv.Key, kv.Value, FormattableString.Invariant($"{kv.Value:N0} immigrants arrived from {kv.Key}")));+ if (kv.Value > 0) why.Add(new Cause("population", kv.Key, kv.Value, FormattableString.Invariant($"{kv.Value:N0} immigrants arrived ({PlayerText.Region(c, kv.Key)})")));}}}diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.csindex f67099a08..ffbeb5a2d 100644--- a/sim/Statecraft.Sim/Simulation.cs+++ b/sim/Statecraft.Sim/Simulation.cs@@ -84,11 +84,11 @@ namespace Statecraft.Simif (legislature == null) return "No legislature is sitting";if (!PassVote(c, s)){- why.Add(new Cause("politics", p.Policy, 0, FormattableString.Invariant($"{legislature.Body} voted down {p.Policy} {p.Level:0.00}")));+ why.Add(new Cause("politics", p.Policy, 0, FormattableString.Invariant($"{legislature.Body} voted down {PlayerText.Target(c, p.Policy)} {p.Level:0.00}")));return null;}s.Policies[p.Policy] = p.Level;- why.Add(new Cause("policy", p.Policy, p.Level, FormattableString.Invariant($"{p.Policy} set to {p.Level:0.00}")));+ why.Add(new Cause("policy", p.Policy, p.Level, FormattableString.Invariant($"{PlayerText.Target(c, p.Policy)} set to {p.Level:0.00}")));return null;case AllocateBudget b:{