A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Money causes add up to the Money (net) change (Fixes #2199) (#2212)
Eyal Golanaa482690e09d
diff --git a/changelog.d/2199-money-causes.md b/changelog.d/2199-money-causes.mdnew file mode 100644index 000000000..aa5846051--- /dev/null+++ b/changelog.d/2199-money-causes.md@@ -0,0 +1,10 @@+### Fixed++- The turn report's Money line and the Money tip now list the cities' job income and the Money paid for Arms, training, projects,+ pioneer work, corridors, held soldiers and occupation, so the causes behind the Money (net) change add up to it. A loan is+ no longer listed as a Money cause: it adds as much to the debt as to the Treasury (Fixes #2199). The Why screen gains a+ Money line for each such cost, before its borrowing line. A map action's cost gets the same line (only the legacy loop+ builds map actions; the GDD game refuses them).+- The turn report's Money line and the Money tip still name the two largest causes, then one "other causes" line with the+ rest, so the lines shown add up to the Money (net) change. There is no such line when nothing is left over or the rest+ shows as IL 0.0m (#2212).diff --git a/sim/Statecraft.Sim.Tests/CauseKeysTests.cs b/sim/Statecraft.Sim.Tests/CauseKeysTests.csindex 003ee50c9..f2d5d4936 100644--- a/sim/Statecraft.Sim.Tests/CauseKeysTests.cs+++ b/sim/Statecraft.Sim.Tests/CauseKeysTests.cs@@ -148,16 +148,19 @@ public class CauseKeysTestspublic void CivilianUpkeepAndItsBorrowingAreKeyed(){var s = new GameState { Treasury = 0, Debt = 0 }; var why = new List<Cause>();- EconomySystem.PayOrBorrow(Fix, s, 3, "for civilian upkeep", why, CauseKeys.Purpose.CivilianUpkeep);+ EconomySystem.PayNamedOrBorrow(Fix, s, 3, "for civilian upkeep", why, CauseKeys.Purpose.CivilianUpkeep); // as PayCivilianUpkeepvar line = Assert.Single(why);Assert.Equal((CauseKeys.Borrowed, "Borrowed IL 3.0m for civilian upkeep"), (line.Key, line.Message));Assert.Equal(new[] { CauseKeys.Purpose.CivilianUpkeep }, line.Args);+ // #2199: PayOrBorrow names the whole cost as a Money line first, with the same purpose, then the borrowing.why.Clear();EconomySystem.PayOrBorrow(Fix, s, 3, "to build a housing project", why, CauseKeys.Purpose.Project, "housing");- line = Assert.Single(why);- Assert.Equal(CauseKeys.Borrowed, line.Key);- Assert.Equal(new[] { CauseKeys.Purpose.Project, "housing" }, line.Args);+ Assert.Equal(2, why.Count);+ Assert.Equal((CauseKeys.Paid, "treasury", -3.0), (why[0].Key, why[0].Target, why[0].Delta));+ Assert.Equal(new[] { CauseKeys.Purpose.Project, "housing" }, why[0].Args);+ Assert.Equal(CauseKeys.Borrowed, why[1].Key);+ Assert.Equal(new[] { CauseKeys.Purpose.Project, "housing" }, why[1].Args);}[Fact]diff --git a/sim/Statecraft.Sim.Tests/MoneyCausesTests.cs b/sim/Statecraft.Sim.Tests/MoneyCausesTests.csnew file mode 100644index 000000000..f4b5f09c8--- /dev/null+++ b/sim/Statecraft.Sim.Tests/MoneyCausesTests.cs@@ -0,0 +1,354 @@+using System;+using System.Collections.Generic;+using System.Globalization;+using System.Linq;+using Statecraft.Sim;++/// <summary>#2199: the causes of the Money (net) meter (Treasury minus Debt, the top bar, the turn report and the meter+/// tip) are the turn's lines that <see cref="EconomySystem.MovesMoney"/> picks, the filter the HUD uses. Together they add+/// up to the meter's change: the Treasury lines, job income, and each payment's whole cost (one line, borrowed share+/// included). A borrowing line (Target debt) is not one: it moves the Treasury and the Debt by the same amount.</summary>+public class MoneyCausesTests+{+ static readonly Content Real = ContentLoader.Load(RealContentTests.ContentRoot());++ /// <summary>The tolerance in IL millions. The sim adds the same amounts to the Treasury and the Debt as the causes carry,+ /// but in a different order and association (the Treasury starts at IL 20m and takes each term in turn; a payment takes+ /// the whole cost, then moves the shortfall to Debt), so exact equality does not hold: the gap is 2.7e-15 on the opening+ /// turn and 2.3e-13 with a purchase of 999 Arms (measured before this test bought 200 for #2203's debt ceiling), and every test here passes at 1e-12 (measured, #2199). 1e-9 leaves room above+ /// that rounding and is far below the smallest amount a line shows (IL 0.1m), so a missing or doubled line always fails.</summary>+ const double Tolerance = 1e-9;++ static void AssertAddsUp(GameState before, StepResult r, string what)+ {+ var lines = r.Why.Where(EconomySystem.MovesMoney).ToList();+ var sum = lines.Sum(w => w.Delta);+ var change = (r.State.Treasury - r.State.Debt) - (before.Treasury - before.Debt);+ string N(double v) => v.ToString("0.000###", CultureInfo.InvariantCulture);+ Assert.True(Math.Abs(sum - change) <= Tolerance,+ $"{what}: the Money causes add up to {N(sum)}, the change in Treasury minus Debt is {N(change)} (gap {N(change - sum)}); "+ + "unlisted: " + string.Join("; ", r.Why.Where(w => !EconomySystem.MovesMoney(w) && w.Message.Contains("IL")).Select(w => $"[{w.Key}] {w.Message}"))+ + " | listed: " + string.Join("; ", lines.Select(w => $"[{w.Key}] {N(w.Delta)}")));+ }++ static GameState Start() => Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);++ // R-CITY-002, R-MONEY-001: a turn with no orders: tax and spending, military upkeep and the cities' job income.+ [Fact]+ public void ATurnWithNoOrdersAddsUp()+ {+ var s = Start();+ for (int t = 1; t <= 6; t++)+ {+ var r = Simulation.Step(Real, s, Array.Empty<Command>());+ Assert.Empty(r.Rejected);+ AssertAddsUp(s, r, $"turn {t}");+ Assert.Contains(r.Why, w => w.Key == CauseKeys.WagesPaid && EconomySystem.MovesMoney(w));+ s = r.State;+ }+ }++ // R-ARMS-002, R-MONEY-003: Arms bought for more than the Treasury holds: part paid in cash, the rest borrowed. 200 Arms+ // cost IL 200m against the opening IL 20m, so IL 180m is borrowed, under the debt ceiling #2203 adds (IL 250m).+ [Fact]+ public void APurchasePaidPartlyInCashAndPartlyBorrowedAddsUp()+ {+ const int count = 200;+ var s = Start();+ Assert.True(count * Real.RulesAt(s.Date).Mvp!.ArmsPrice!.Value > s.Treasury, "the purchase costs more than the Treasury holds");+ var r = Simulation.Step(Real, s, new Command[] { new BuyArms(count) });+ Assert.Empty(r.Rejected);+ Assert.True(r.State.Debt > s.Debt, "the purchase borrows");+ AssertAddsUp(s, r, $"BuyArms({count})");+ // The whole cost is one Money line; the borrowing lines (the purchase's and the deficit's) are not Money causes.+ var paid = Assert.Single(r.Why, w => w.Key == CauseKeys.Paid);+ Assert.Equal(("treasury", -count * Real.RulesAt(s.Date).Mvp!.ArmsPrice!.Value, CauseKeys.Purpose.Arms), (paid.Target, paid.Delta, paid.Args[0]));+ Assert.Contains(r.Why, w => w.Key == CauseKeys.Borrowed && w.Args[0] == CauseKeys.Purpose.Arms);+ Assert.DoesNotContain(r.Why.Where(EconomySystem.MovesMoney), w => w.Target == "debt");+ }++ // R-TRAIN-001, R-MONEY-003: a training order paid from the Treasury.+ [Fact]+ public void ATrainingOrderAddsUp()+ {+ var s = Start();+ var r = Simulation.Step(Real, s, new Command[] { new Train("tel_aviv", "halutz", 2) });+ Assert.Empty(r.Rejected);+ AssertAddsUp(s, r, "Train(tel_aviv, halutz, 2)");+ }++ /// <summary>The real content never builds a map action: the GDD loop, which runs in every era, refuses them all+ /// (R-PROJ-004, MapActions.Check's gdd_loop reason). MapActions.Apply still runs in the legacy loop (D-E1), so these use+ /// the legacy fixture on a day its map actions are open, as EraSystemsTests does, and its housing hex.</summary>+ static readonly Content Legacy = ContentLoader.Load(Fixture.Write());++ static GameState MapActionDay()+ {+ var s = Simulation.NewGame(Legacy, 42, Mode.Historical);+ s.Date = new DateTime(1948, 6, 1); // the fixture's map_actions_from+ return s;+ }++ static readonly MapAction Housing = new MapAction(MapActions.Housing, 2, 0);++ // R-MONEY-001: a map action's cost is paid from the Treasury, so it is a Money line, before the build line.+ [Fact]+ public void AMapActionPaidInCashAddsUp()+ {+ Assert.Equal("Map actions are not part of this game: start a city project instead", MapActions.Check(Real, Start(), MapActions.Housing, 2, 0));+ var s = MapActionDay();+ s.Treasury = 100; // more than the cost, so nothing is borrowed for it+ AssertAddsUp(s, Simulation.Step(Legacy, s, Array.Empty<Command>()), "the same turn with no orders");+ var r = Simulation.Step(Legacy, s, new Command[] { Housing });+ Assert.Empty(r.Rejected);+ Assert.Contains(r.Why, w => w.Key == CauseKeys.MapBuilt);+ Assert.DoesNotContain(r.Why, w => w.Key == CauseKeys.MapBorrowed);+ AssertAddsUp(s, r, "MapAction(housing) in cash");+ var cost = Legacy.RulesAt(s.Date).MapActions[MapActions.Housing].Cost;+ var paid = Assert.Single(r.Why, w => w.Key == CauseKeys.Paid);+ Assert.Equal(("treasury", -cost, CauseKeys.Purpose.MapAction, MapActions.Housing), (paid.Target, paid.Delta, paid.Args[0], paid.Args[1]));+ }++ // R-MONEY-003: a map action with the Treasury short: its cost is one Money line, and the borrowing (MapBorrowed) is not.+ [Fact]+ public void AMapActionWithTheTreasuryShortAddsUp()+ {+ var s = MapActionDay();+ s.Treasury = 0;+ var r = Simulation.Step(Legacy, s, new Command[] { Housing });+ Assert.Empty(r.Rejected);+ AssertAddsUp(s, r, "MapAction(housing) borrowed");+ var borrowed = Assert.Single(r.Why, w => w.Key == CauseKeys.MapBorrowed);+ Assert.False(EconomySystem.MovesMoney(borrowed));+ var paid = Assert.Single(r.Why, w => w.Key == CauseKeys.Paid);+ var why = r.Why.ToList();+ Assert.True(why.IndexOf(paid) < why.IndexOf(borrowed), "the Money line comes before its borrowing, as PayOrBorrow orders them");+ }++ // R-MONEY-002, R-MONEY-003: civilian upkeep writes its own Money line (EconomySystem.PayCivilianUpkeep), so it borrows+ // through PayNamedOrBorrow and is counted once, paid in cash or borrowed. Every real rate is 0+ // (MoneyTests.TheMvpChargesNoCivilianUpkeep), so this uses the GDD fixture with a city upkeep, as MoneyTests does.+ [Theory]+ [InlineData(1.0, 100.0)] // paid in cash+ [InlineData(1000.0, 0.0)] // more than the Treasury holds after the turn's income: borrowed+ public void CivilianUpkeepIsOneMoneyLine(double upkeepPerYear, double treasury)+ {+ var files = Fixture.Gdd();+ files["rules.yaml"] = files["rules.yaml"].Replace("city_upkeep_per_year: 0", FormattableString.Invariant($"city_upkeep_per_year: {upkeepPerYear}"));+ var c = ContentLoader.Load(Fixture.Write(files));+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ s.Treasury = treasury;+ var r = Simulation.Step(c, s, Array.Empty<Command>());+ Assert.Empty(r.Rejected);+ AssertAddsUp(s, r, $"civilian upkeep {upkeepPerYear} a year, Treasury {treasury}");+ Assert.Single(r.Why, w => w.Key == CauseKeys.CivilianUpkeep);+ Assert.DoesNotContain(r.Why, w => w.Key == CauseKeys.Paid);+ Assert.Equal(treasury == 0, r.Why.Any(w => w.Key == CauseKeys.Borrowed && w.Args[0] == CauseKeys.Purpose.CivilianUpkeep));+ }++ // R-CTRL-018, R-MONEY-003: a Deport writes its own Money line (CauseKeys.DeportCost), so it is counted once. Deport is not+ // in play in the real content (mvp.deport_in_play: false), so this uses DeportTests' fixture, whose IL 121m cost borrows.+ [Fact]+ public void ADeportIsOneMoneyLine()+ {+ var c = DeportTests.Load();+ var s = DeportTests.Awaiting(c, DeportTests.Soldier(1, 1, 0));+ var r = Simulation.Step(c, s, new Command[] { new ResolveCapture("town_a", SettlementControl.Deport) });+ Assert.Empty(r.Rejected);+ AssertAddsUp(s, r, "Deport of town_a");+ Assert.Single(r.Why, w => w.Key == CauseKeys.DeportCost);+ Assert.DoesNotContain(r.Why, w => w.Key == CauseKeys.Paid);+ Assert.Contains(r.Why, w => w.Key == CauseKeys.Borrowed && w.Args[0] == CauseKeys.Purpose.Deport);+ }++ // R-MONEY-003: every turn of the reference player's game, with its orders, events, upkeep and borrowing.+ [Fact]+ public void EveryTurnOfTheReferenceRunAddsUp()+ {+ var s = Start();+ for (int t = 1; t < 1000 && s.GameOver == null; t++)+ {+ var r = Simulation.Step(Real, s, GoldenRun.Orders(Real, s));+ AssertAddsUp(s, r, $"turn {t} ({s.Date:yyyy-MM-dd})");+ s = r.State;+ }+ }++ /// <summary>#2212: the Money causes the turn report and the meter tip show, as HudModel.Causes picks them: the largest+ /// <paramref name="max"/> lines MovesMoney picks (not zero), the larger first, the sim's order breaking a tie.</summary>+ static List<Cause> Largest(IReadOnlyList<Cause> why, int max) =>+ why.Select((w, i) => (w, i)).Where(x => EconomySystem.MovesMoney(x.w) && x.w.Delta != 0)+ .OrderByDescending(x => Math.Abs(x.w.Delta)).ThenBy(x => x.i).Take(max).Select(x => x.w).ToList();++ /// <summary>The two lines shown, then the Other line when there is one (EconomySystem.OtherMoney).</summary>+ static List<Cause> Shown(Content c, IReadOnlyList<Cause> why)+ {+ var shown = Largest(why, 2);+ if (EconomySystem.OtherMoney(c, why, shown) is Cause other) shown.Add(other);+ return shown;+ }++ // #2212: with more Money causes than the two shown, one Other line holds the rest, so the lines shown add up to the+ // Money (net) change. The opening turn has tax and spending, military upkeep and several cities' job income.+ [Fact]+ public void TheTwoLargestAndOneOtherLineAddUpToTheChange()+ {+ var s = Start();+ var r = Simulation.Step(Real, s, Array.Empty<Command>());+ Assert.True(r.Why.Count(w => EconomySystem.MovesMoney(w) && w.Delta != 0) >= 3, "the opening turn has 3 or more Money causes");+ var largest = Largest(r.Why, 2);+ var other = EconomySystem.OtherMoney(Real, r.Why, largest);+ Assert.NotNull(other);+ var rest = r.Why.Where(w => EconomySystem.MovesMoney(w) && !largest.Contains(w)).Sum(w => w.Delta);+ Assert.Equal(("economy", "treasury", CauseKeys.MoneyOther, rest), (other!.System, other.Target, other.Key, other.Delta));+ Assert.Equal($"{PlayerText.Change(Real, "treasury", rest)} (other causes)", other.Message);+ Assert.DoesNotContain(other, r.Why); // the UI's line, never a line of the turn+ var change = (r.State.Treasury - r.State.Debt) - (s.Treasury - s.Debt);+ Assert.True(Math.Abs(largest.Sum(w => w.Delta) + other.Delta - change) <= Tolerance, "the two lines and Other add up to the change");+ }++ // #2212: no Other line when every Money cause is shown (two or fewer), or when the rest rounds to IL 0.0m as shown.+ [Theory]+ [InlineData(new double[0], false)]+ [InlineData(new[] { -3.0 }, false)]+ [InlineData(new[] { -3.0, 2.0 }, false)]+ [InlineData(new[] { -3.0, 2.0, 0.04 }, false)] // IL +0.0m as shown: left out+ [InlineData(new[] { -3.0, 2.0, -0.04 }, false)]+ [InlineData(new[] { -3.0, 2.0, 0.03, 0.01 }, false)]+ [InlineData(new[] { -3.0, 2.0, 0.05 }, true)] // IL +0.1m as shown+ [InlineData(new[] { -3.0, 2.0, 0.03, 0.03 }, true)]+ [InlineData(new[] { -3.0, 2.0, 1.0, -1.0 }, false)] // the rest cancels out+ public void NoOtherLineWhenNothingIsLeftOver(double[] deltas, bool expected)+ {+ var why = deltas.Select(d => new Cause("economy", "treasury", d, PlayerText.Change(Real, "treasury", d), key: CauseKeys.CivilianUpkeep))+ .Append(new Cause("economy", "debt", 5, "borrowed IL 5.0m to cover the deficit", key: CauseKeys.Borrowed)) // not a Money cause+ .ToList();+ var largest = Largest(why, 2);+ var other = EconomySystem.OtherMoney(Real, why, largest);+ Assert.Equal(expected, other != null);+ if (other != null) Assert.Equal(deltas.Sum() - largest.Sum(w => w.Delta), other.Delta, 12);+ }++ // #2212: on every turn of the reference run, the lines shown add up to the Money (net) change, but for a rest the+ // Other line leaves out because it shows as IL 0.0m (under IL 0.05m). At most 3 lines.+ [Fact]+ public void EveryTurnOfTheReferenceRunShowsLinesThatAddUp()+ {+ var s = Start(); var others = 0;+ for (int t = 1; t < 1000 && s.GameOver == null; t++)+ {+ var r = Simulation.Step(Real, s, GoldenRun.Orders(Real, s));+ var shown = Shown(Real, r.Why);+ Assert.True(shown.Count <= 3, $"turn {t}: {shown.Count} lines");+ var change = (r.State.Treasury - r.State.Debt) - (s.Treasury - s.Debt);+ var gap = Math.Abs(shown.Sum(w => w.Delta) - change);+ Assert.True(shown.Count == 3 ? gap <= Tolerance : gap < 0.05 + Tolerance, $"turn {t}: gap {gap}");+ if (shown.Count == 3) others++;+ s = r.State;+ }+ Assert.True(others > 0, "the reference run shows an Other line");+ }++ // #2212 review, H2: the paying purposes no other test here plays through Simulation.Step (the reference run pays for+ // training, yishuvim, plowing, city projects and an event; APurchase... pays for Arms; the map action, civilian upkeep+ // and Deport tests above). Each is played with the Treasury empty, so it borrows: its cost is exactly one Money line,+ // its caller writes no Treasury line of its own beside it, and the lines add up.+ [Theory]+ [InlineData(CauseKeys.Purpose.Corridor)]+ [InlineData(CauseKeys.Purpose.TrainingCamp)]+ [InlineData(CauseKeys.Purpose.Drain)]+ [InlineData(CauseKeys.Purpose.Prisoners)]+ [InlineData(CauseKeys.Purpose.Occupation)]+ public void EveryPayingPurposeAddsUpThroughStep(string purpose)+ {+ Content c; GameState s; Command[] orders;+ string Site(string id, string kind) => Fixture.GddSites + Fixture.GddSites.Replace("sites:\n", "").Replace("site_a", id).Replace("Site A", id)+ .Replace("q: 2", "q: 3").Replace("kinds: [yishuv]", $"kinds: [{kind}]").Replace(" founded: 1949-06-12\n", kind == "swamp" ? "" : " city: town_a\n"); // only a camp site names its city+ GameState WithHalutz(Content content, out int id)+ {+ var g = Simulation.NewGame(content, 1, Mode.Historical);+ id = g.NextId++;+ g.Units.Add(id, new Unit(id, "halutz", 1, 0));+ return g;+ }+ Content Gdd(string? sites = null) => ContentLoader.Load(Fixture.Write(Fixture.Gdd(sites == null ? null : new Dictionary<string, string>+ {+ ["cities.yaml"] = "\ncities:\n" + Fixture.City("town_a", 12, 8, 10, 6),+ ["sites.yaml"] = sites,+ })));+ switch (purpose)+ {+ case CauseKeys.Purpose.Corridor:+ c = Gdd(); s = WithHalutz(c, out var a); orders = new Command[] { new PioneerWork(a, Corridors.BuildRoad, "road_a:1") }; break;+ case CauseKeys.Purpose.TrainingCamp:+ c = Gdd(Site("camp_a", "military_camp")); s = WithHalutz(c, out var b); orders = new Command[] { new PioneerWork(b, Projects.BuildCamp, "camp_a") }; break;+ case CauseKeys.Purpose.Drain:+ c = Gdd(Site("marsh", "swamp")); s = WithHalutz(c, out var d); orders = new Command[] { new PioneerWork(d, Projects.DrySwamp, "marsh") }; break;+ case CauseKeys.Purpose.Prisoners:+ c = Gdd(); s = Simulation.NewGame(c, 1, Mode.Historical); s.SoldiersHeld["egypt"] = 2; orders = Array.Empty<Command>(); break;+ default:+ c = DeportTests.Load(); s = DeportTests.Awaiting(c, DeportTests.Soldier(1, 1, 0));+ orders = new Command[] { new ResolveCapture("town_a", SettlementControl.Occupy) }; break;+ }+ s.Treasury = 0;+ var r = Simulation.Step(c, s, orders);+ Assert.Empty(r.Rejected);+ AssertAddsUp(s, r, purpose);+ var paid = Assert.Single(r.Why, w => EconomySystem.MovesMoney(w) && w.Key == CauseKeys.Paid && w.Args[0] == purpose);+ Assert.True(paid.Delta < 0, $"{purpose}: the cost is paid");+ Assert.DoesNotContain(r.Why, w => EconomySystem.MovesMoney(w) && w.System != "economy" && w.System != "city" && w.System != "events");+ }++ // #2212 review, H1 and the suggested test 1: what the reference run pays and borrows for, so a test that "adds up on+ // every turn" is not vacuous. Measured at the #2212 head: 44 turns, none refused; Paid for training 1, yishuv 6,+ // project 5, plow 2; Borrowed for the deficit 41, yishuv 6, project 5, plow 2, an event 1. Every Debt line is a loan+ // (Borrowed or MapBorrowed), which moves the Treasury and the Debt alike; a future interest or relief line fails here.+ [Fact]+ public void TheReferenceRunExercisesTheMoneyPaths()+ {+ var s = Start(); int turns = 0;+ var paid = new HashSet<string>(); var borrowed = new HashSet<string>(); var keys = new HashSet<string>();+ for (int t = 1; t < 1000 && s.GameOver == null; t++)+ {+ var r = Simulation.Step(Real, s, GoldenRun.Orders(Real, s));+ Assert.Empty(r.Rejected);+ foreach (var w in r.Why)+ {+ if (w.Key == CauseKeys.Paid) paid.Add(w.Args[0]);+ if (w.Key == CauseKeys.Borrowed) borrowed.Add(w.Args[0]);+ if (EconomySystem.MovesMoney(w)) keys.Add(w.Key);+ if (w.Target == "debt") Assert.Contains(w.Key, new[] { CauseKeys.Borrowed, CauseKeys.MapBorrowed });+ }+ s = r.State; turns++;+ }+ Assert.True(turns >= 40, $"the run lasts {turns} turns");+ Assert.Subset(paid, new HashSet<string> { CauseKeys.Purpose.Training, CauseKeys.Purpose.Yishuv, CauseKeys.Purpose.Project, CauseKeys.Purpose.Plow });+ Assert.Subset(borrowed, new HashSet<string> { CauseKeys.Purpose.Deficit, CauseKeys.Purpose.Event, CauseKeys.Purpose.Yishuv });+ Assert.Subset(keys, new HashSet<string> { CauseKeys.MoneyFlows, CauseKeys.WagesPaid, CauseKeys.MilitaryUpkeep, CauseKeys.Paid, CauseKeys.EventAmount });+ }++ // #2212 review, H3 and the suggested test 3: costs paid at the debt ceiling (mvp.debt_ceiling, IL 250m). PayOrBorrow+ // has no cap: upkeep borrows past it, and the lines add up. A purchase up to the ceiling is paid; one past it is+ // refused once #2203 lands (Pools.BuyArms, before PayOrBorrow), and then writes no Money line. Either way a Paid+ // line exists only with its Treasury move, and the lines add up.+ [Theory]+ [InlineData(0)] // no orders: military upkeep and the deficit borrow past the ceiling+ [InlineData(1)] // borrows IL 1.0m, to exactly the ceiling+ [InlineData(2)] // borrows past it+ public void CostsPaidAtTheDebtCeilingAddUp(int arms)+ {+ var s = Start();+ var ceiling = Real.RulesAt(s.Date).Mvp!.DebtCeiling!.Value;+ Assert.Equal(1.0, Real.RulesAt(s.Date).Mvp!.ArmsPrice!.Value);+ s.Debt = ceiling - 1; s.Treasury = 0;+ var r = Simulation.Step(Real, s, arms == 0 ? Array.Empty<Command>() : new Command[] { new BuyArms(arms) });+ AssertAddsUp(s, r, $"BuyArms({arms}) at the ceiling");+ Assert.True(r.State.Debt > ceiling, "the turn's upkeep borrows past the ceiling: PayOrBorrow has no cap");+ var bought = r.Rejected.Count == 0 && arms > 0;+ if (arms == 1) Assert.True(bought, "a purchase to exactly the ceiling is paid");+ var lines = r.Why.Where(w => w.Key == CauseKeys.Paid).ToList();+ Assert.Equal(bought ? 1 : 0, lines.Count);+ if (bought) Assert.Equal((-(double)arms, CauseKeys.Purpose.Arms), (lines[0].Delta, lines[0].Args[0]));+ Assert.Equal(s.Arms + (bought ? arms : 0), r.State.Arms);+ }+}diff --git a/sim/Statecraft.Sim.Tests/ProjectsTests.cs b/sim/Statecraft.Sim.Tests/ProjectsTests.csindex 4eb87b2f3..410f1e2a5 100644--- a/sim/Statecraft.Sim.Tests/ProjectsTests.cs+++ b/sim/Statecraft.Sim.Tests/ProjectsTests.cs@@ -107,7 +107,9 @@ public class ProjectsTestsvar none = new List<Cause>();Assert.Null(Projects.Start(c, exact, other, Projects.BuildYishuv, "site_a", none));Assert.Equal((0.0, 3.0), (exact.Treasury, exact.Debt));- Assert.DoesNotContain(none, x => x.System == "economy");+ // Nothing borrowed; the cost's own Money line is the only economy line (#2199).+ var paid = Assert.Single(none, x => x.System == "economy");+ Assert.Equal((CauseKeys.Paid, "treasury", -1.5), (paid.Key, paid.Target, paid.Delta));}// R-SITE-001, R-SITE-002diff --git a/sim/Statecraft.Sim.Tests/RemainingCauseKeysTests.cs b/sim/Statecraft.Sim.Tests/RemainingCauseKeysTests.csindex b492bfb81..21630f5fd 100644--- a/sim/Statecraft.Sim.Tests/RemainingCauseKeysTests.cs+++ b/sim/Statecraft.Sim.Tests/RemainingCauseKeysTests.cs@@ -115,7 +115,7 @@ public class RemainingCauseKeysTestssites++;}}- Assert.Equal(104, sites);+ Assert.Equal(106, sites); // 106 since #2212: EconomySystem.OtherMoney's line (105 since #2199: PayOrBorrow's Paid line)}[Fact]diff --git a/sim/Statecraft.Sim/Cause.cs b/sim/Statecraft.Sim/Cause.csindex b07509913..7516e2f89 100644--- a/sim/Statecraft.Sim/Cause.cs+++ b/sim/Statecraft.Sim/Cause.cs@@ -47,6 +47,12 @@ namespace Statecraft.Simpublic const string FxFlows = "fx_flows";/// <summary>Delta borrowed into the debt. Args: what for (a <see cref="Purpose"/>), then that purpose's values.</summary>public const string Borrowed = "borrowed";+ /// <summary>Target (treasury) money moved by Delta, a cost paid through EconomySystem.PayOrBorrow, borrowed share+ /// included (#2199). Args: as <see cref="Borrowed"/>'s.</summary>+ public const string Paid = "paid";+ /// <summary>Target (treasury) money moved by Delta, the Money causes a list leaves out, summed: the UI's line, never one+ /// of a turn's (EconomySystem.OtherMoney, #2212). No args.</summary>+ public const string MoneyOther = "money_other";/// <summary>Target money moved by Delta, for civilian upkeep. No args.</summary>public const string CivilianUpkeep = "civilian_upkeep";public const string FxCrisisBegan = "fx_crisis_began", FxCrisisEased = "fx_crisis_eased";@@ -213,7 +219,8 @@ namespace Statecraft.Sim/// <summary>Args: none.</summary>public const string DepopulationSupport = "depopulation_support";- /// <summary>What a <see cref="Borrowed"/> line borrowed for (EconomySystem.PayOrBorrow's callers, and the deficit).</summary>+ /// <summary>What a <see cref="Borrowed"/> line borrowed for (EconomySystem.PayOrBorrow's callers, and the deficit), and+ /// what a <see cref="Paid"/> line paid for.</summary>public static class Purpose{public const string Deficit = "deficit", CivilianUpkeep = "civilian_upkeep", MilitaryUpkeep = "military_upkeep",@@ -221,19 +228,22 @@ namespace Statecraft.SimPlow = "plow", Drain = "drain", Yishuv = "yishuv", Deport = "deport", Occupation = "occupation";/// <summary>Args: the project kind's id.</summary>public const string Project = "project";+ /// <summary>A map action's cost (MapActions.Apply), a Paid line only: its borrowing is CauseKeys.MapBorrowed.+ /// Args: the map action's id.</summary>+ public const string MapAction = "map_action";/// <summary>Args: the event's id, its English title as shown, and "1" when its title_he names it (no variant title).</summary>public const string Event = "event";public static readonly IReadOnlyList<string> All = new[]{Deficit, CivilianUpkeep, MilitaryUpkeep, Corridor, Arms, Training, Prisoners, TrainingCamp, Plow, Drain, Yishuv,- Deport, Occupation, Project, Event,+ Deport, Occupation, Project, MapAction, Event,};}public static readonly IReadOnlyList<string> All = new[]{- MoneyFlows, FxFlows, Borrowed, CivilianUpkeep, FxCrisisBegan, FxCrisisEased, FxCrisisFood, Arrived, EffectChange,+ MoneyFlows, FxFlows, Borrowed, Paid, MoneyOther, CivilianUpkeep, FxCrisisBegan, FxCrisisEased, FxCrisisFood, Arrived, EffectChange,SituationBegan, SituationEnded, RungChanged, CallUpSet, CallUpRaised, CallUpLowered, Ceasefire,EventNew, EventChosen, EventDelegated, EventDelegatedPartial, EventAmount, EventStock, EventGrant, EventCity,EventUnlock, EventPolicy, EventSetRung, EventRejoin, MilitaryUpkeep,diff --git a/sim/Statecraft.Sim/EconomySystem.cs b/sim/Statecraft.Sim/EconomySystem.csindex c2f7e7cae..f859cbdcd 100644--- a/sim/Statecraft.Sim/EconomySystem.cs+++ b/sim/Statecraft.Sim/EconomySystem.cs@@ -23,6 +23,25 @@ namespace Statecraft.Simpublic TreasuryFlows(double tax, double spending, double mobilization) { Tax = tax; Spending = spending; Mobilization = mobilization; }}+ /// <summary>#2199: whether <paramref name="w"/> is a cause of the Money (net) change, Treasury minus Debt (the top bar's+ /// Money, R-MONEY-001), its Delta that change: a Treasury line, and a city's job income (R-CITY-002), whose Target is the+ /// city. A borrowing line (Target debt) is not one: it moves the Treasury and the Debt by the same amount, and the cost it+ /// borrowed for has its own Treasury line. The turn's lines it picks add up to the change (MoneyCausesTests); the turn+ /// report and the meter tip show the largest (HudModel.Causes).</summary>+ public static bool MovesMoney(Cause w) => w.Target == "treasury" || w.Key == CauseKeys.WagesPaid;++ /// <summary>#2212: the one Money line for the causes a list leaves out. The turn report and the meter tip show the+ /// largest Money causes (HudModel.Causes, at most HudModel.MaxCauses); this is the sum of the turn's other lines+ /// <see cref="MovesMoney"/> picks (<paramref name="why"/> minus <paramref name="shown"/>, by reference), so the lines+ /// shown add up to the Money (net) change. Null when nothing is left over or the rest shows as IL 0.0m+ /// (PlayerText.MoneyChange's rounding). The line is the UI's, never one of the turn's (StepResult.Why).</summary>+ public static Cause? OtherMoney(Content c, IEnumerable<Cause> why, IReadOnlyCollection<Cause> shown)+ {+ var rest = why.Where(w => MovesMoney(w) && !shown.Contains(w)).Sum(w => w.Delta);+ if (PlayerText.MoneyChange(c, "treasury", rest) == PlayerText.MoneyChange(c, "treasury", 0)) return null;+ return new Cause("economy", "treasury", rest, $"{PlayerText.Change(c, "treasury", rest)} (other causes)", key: CauseKeys.MoneyOther);+ }+public static TreasuryFlows Flows(Content c, GameState s, double yearFraction){PopulationLedger.RefuseAggregate(s);@@ -36,11 +55,26 @@ namespace Statecraft.Simpublic static double MobilizationCost(Content c, DateTime date, double level, double yearFraction = 1.0) => c.RulesAt(date).MobilizationCostPerYear * level * yearFraction;/// <summary>Pays <paramref name="cost"/> from the Treasury, borrowing what it lacks: the shortfall goes to Debt and the- /// Treasury stops at 0, as for map actions and the deficit. <paramref name="purpose"/> ends the cause ("for training").+ /// Treasury stops at 0, as for map actions and the deficit. <paramref name="purpose"/> ends the causes ("for training")./// The GDD orders pay through it (owner decision "Allow borrowing", 2026-10-15; R-TRAIN-001, R-SITE-001)./// <paramref name="purposeKey"/> (a CauseKeys.Purpose) and <paramref name="purposeArgs"/> say the same purpose for the- /// UI (CauseKeys.Borrowed, B1); <paramref name="purpose"/> stays the English Message.</summary>+ /// UI (CauseKeys.Paid and CauseKeys.Borrowed, B1); <paramref name="purpose"/> stays the English Message. The whole cost+ /// is a Money line first (CauseKeys.Paid, #2199), then any borrowing, as <see cref="PayNamedOrBorrow"/> writes it.</summary>public static void PayOrBorrow(Content c, GameState s, double cost, string purpose, List<Cause> why, string purposeKey, params string[] purposeArgs)+ {+ if (cost != 0) why.Add(Paid(c, cost, purpose, purposeKey, purposeArgs));+ PayNamedOrBorrow(c, s, cost, purpose, why, purposeKey, purposeArgs);+ }++ /// <summary>The Money line (CauseKeys.Paid) for <paramref name="cost"/> paid from the Treasury, as PayOrBorrow writes+ /// it. MapActions.Apply, which borrows for itself (CauseKeys.MapBorrowed), writes it too (#2199).</summary>+ public static Cause Paid(Content c, double cost, string purpose, string purposeKey, params string[] purposeArgs) =>+ new Cause("economy", "treasury", -cost, $"{PlayerText.Change(c, "treasury", -cost)} ({purpose})",+ key: CauseKeys.Paid, args: new[] { purposeKey }.Concat(purposeArgs).ToList());++ /// <summary><see cref="PayOrBorrow"/> for a cost its caller has already given its own Money line (civilian and military+ /// upkeep, a Deport, an event option's cost): only the borrowing line, if any.</summary>+ public static void PayNamedOrBorrow(Content c, GameState s, double cost, string purpose, List<Cause> why, string purposeKey, params string[] purposeArgs){s.Treasury -= cost;if (s.Treasury >= 0) return;@@ -56,7 +90,7 @@ namespace Statecraft.Simvar cost = Cities.AnnualUpkeep(c, s, r) * yearFraction;if (cost == 0) return;why.Add(new Cause("economy", "treasury", -cost, $"{PlayerText.Change(c, "treasury", -cost)} (civilian upkeep)", key: CauseKeys.CivilianUpkeep));- PayOrBorrow(c, s, cost, "for civilian upkeep", why, CauseKeys.Purpose.CivilianUpkeep);+ PayNamedOrBorrow(c, s, cost, "for civilian upkeep", why, CauseKeys.Purpose.CivilianUpkeep);}public static void Apply(Content c, GameState s, double yearFraction, List<Cause> why)diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.csindex 86e216540..f7b265c3f 100644--- a/sim/Statecraft.Sim/EventSystem.cs+++ b/sim/Statecraft.Sim/EventSystem.cs@@ -95,7 +95,7 @@ namespace Statecraft.Sim// R-MONEY-003: the cost first, then what was borrowed for it, as every other payment borrows.why.Add(new Cause("events", fx.Target, change, $"{PlayerText.Change(c, fx.Target, change)} ({title})",key: CauseKeys.EventAmount, args: Context(title, localizedTitle)));- if (delta < 0) EconomySystem.PayOrBorrow(c, s, -delta, $"for {title}", why, CauseKeys.Purpose.Event, eventId, title, titleHe ? "1" : "0");+ if (delta < 0) EconomySystem.PayNamedOrBorrow(c, s, -delta, $"for {title}", why, CauseKeys.Purpose.Event, eventId, title, titleHe ? "1" : "0");else s.Treasury += delta;continue;}diff --git a/sim/Statecraft.Sim/MapActions.cs b/sim/Statecraft.Sim/MapActions.csindex 18c2a65de..5a9d79c8b 100644--- a/sim/Statecraft.Sim/MapActions.cs+++ b/sim/Statecraft.Sim/MapActions.cs@@ -107,6 +107,8 @@ namespace Statecraft.Sims.MapActionsThisTurn++;s.Placements.RemoveAll(p => p.Q == q && p.R == r);s.Placements.Add(new Placement(action, q, r, s.Date));+ // #2199: the cost is a Money line, then any borrowing, in PayOrBorrow's order; the borrowing keeps its own key.+ if (rule.Cost != 0) why.Add(EconomySystem.Paid(c, rule.Cost, $"to build {PlayerText.MapAction(c, action)}", CauseKeys.Purpose.MapAction, action));s.Treasury -= rule.Cost;if (s.Treasury < 0){diff --git a/sim/Statecraft.Sim/Military.cs b/sim/Statecraft.Sim/Military.csindex d6fd7a60a..b248d5d08 100644--- a/sim/Statecraft.Sim/Military.cs+++ b/sim/Statecraft.Sim/Military.cs@@ -31,7 +31,7 @@ namespace Statecraft.Simvar cost = count * r.MilitaryUpkeepPerTurn!.Value;if (cost == 0) return;why.Add(new Cause("economy", "treasury", -cost, $"{PlayerText.Change(c, "treasury", -cost)} (military upkeep)", key: CauseKeys.MilitaryUpkeep));- EconomySystem.PayOrBorrow(c, s, cost, "for military upkeep", why, CauseKeys.Purpose.MilitaryUpkeep);+ EconomySystem.PayNamedOrBorrow(c, s, cost, "for military upkeep", why, CauseKeys.Purpose.MilitaryUpkeep);}}}diff --git a/sim/Statecraft.Sim/SettlementControl.cs b/sim/Statecraft.Sim/SettlementControl.csindex c5e179308..0724633c9 100644--- a/sim/Statecraft.Sim/SettlementControl.cs+++ b/sim/Statecraft.Sim/SettlementControl.cs@@ -298,7 +298,7 @@ namespace Statecraft.Sim}// Deport never pays (owner, 22 October 2026, #1327): its Money stays at or below Occupy's and Raid's.why.Add(new Cause("economy", "treasury", -r.DeportMoneyCost!.Value, $"{PlayerText.Change(c, "treasury", -r.DeportMoneyCost.Value)} (Deport of {name})", key: CauseKeys.DeportCost, args: new[] { id }));- EconomySystem.PayOrBorrow(c, s, r.DeportMoneyCost.Value, $"for the Deport of {name}", why, CauseKeys.Purpose.Deport, id);+ EconomySystem.PayNamedOrBorrow(c, s, r.DeportMoneyCost.Value, $"for the Deport of {name}", why, CauseKeys.Purpose.Deport, id);return null;}diff --git a/unity/Assets/Scripts/UI/CauseText.cs b/unity/Assets/Scripts/UI/CauseText.csindex 1366024e6..bc796b1a0 100644--- a/unity/Assets/Scripts/UI/CauseText.cs+++ b/unity/Assets/Scripts/UI/CauseText.cs@@ -28,11 +28,14 @@ namespace Statecraft.Game.UIreturn text.Format(key, Name(text, cause.Target), Change(c, cause.Target, cause.Delta),Money(c, cause.Target, cause.Args[0]), Money(c, cause.Target, cause.Args[1]), Money(c, cause.Target, cause.Args[2]));case CauseKeys.CivilianUpkeep:+ case CauseKeys.MoneyOther:case CauseKeys.MilitaryUpkeep:case CauseKeys.FxCrisisFood:return text.Format(key, Name(text, cause.Target), Change(c, cause.Target, cause.Delta));case CauseKeys.Borrowed:- return Borrowed(cause, c, text, namesHe);+ return Purposed(cause, c, text, namesHe, "why.cause.borrowed.", PlayerText.Money(c, cause.Target, cause.Delta));+ case CauseKeys.Paid:+ return Purposed(cause, c, text, namesHe, "why.cause.paid.", Name(text, cause.Target), Change(c, cause.Target, cause.Delta));case CauseKeys.FxCrisisBegan:case CauseKeys.FxCrisisEased:case CauseKeys.Ceasefire:@@ -294,25 +297,27 @@ namespace Statecraft.Game.UIreturn PlayerText.Capitalised(text.Format(key, values));}- /// <summary>A borrowing line, by its purpose (CauseKeys.Purpose): why.cause.borrowed.<purpose>, with what the+ /// <summary>A borrowing or paying line, by its purpose (CauseKeys.Purpose): <paramref name="prefix"/> + the purpose+ /// (why.cause.borrowed.<purpose>, why.cause.paid.<purpose>), with <paramref name="values"/> and then what the/// purpose names in the UI's language (a project kind, a settlement, an event's title).</summary>- static string Borrowed(Cause cause, Content c, UiText text, IReadOnlyDictionary<string, string>? namesHe)+ static string Purposed(Cause cause, Content c, UiText text, IReadOnlyDictionary<string, string>? namesHe, string prefix, params object[] values){- var key = "why.cause.borrowed." + cause.Args[0];- var amount = PlayerText.Money(c, cause.Target, cause.Delta);+ var key = prefix + cause.Args[0];switch (cause.Args[0]){case CauseKeys.Purpose.Project:- return text.Format(key, amount, ContentNames.Of(text, c.ProjectKinds.First(k => k.Id == cause.Args[1])));+ return text.Format(key, values.Append(ContentNames.Of(text, c.ProjectKinds.First(k => k.Id == cause.Args[1]))).ToArray());case CauseKeys.Purpose.Deport:case CauseKeys.Purpose.Occupation:- return text.Format(key, amount, ContentNames.Settlement(text, c, cause.Args[1], namesHe));+ return text.Format(key, values.Append(ContentNames.Settlement(text, c, cause.Args[1], namesHe)).ToArray());+ case CauseKeys.Purpose.MapAction:+ return text.Format(key, values.Append(text["info.map_action." + cause.Args[1]]).ToArray());case CauseKeys.Purpose.Event:// The title as the card shows it: title_he, unless a variant gives its own (English) title.var he = cause.Args[3] == "1" ? c.Events.First(e => e.Id == cause.Args[1]).TitleHe : "";- return text.Format(key, amount, he != "" && text["ui.lang"] == UiLanguage.Hebrew ? he : cause.Args[2]);+ return text.Format(key, values.Append(he != "" && text["ui.lang"] == UiLanguage.Hebrew ? he : cause.Args[2]).ToArray());default:- return text.Format(key, amount);+ return text.Format(key, values);}}diff --git a/unity/Assets/Scripts/UI/HudModel.cs b/unity/Assets/Scripts/UI/HudModel.csindex 410b36942..f8ee65f8b 100644--- a/unity/Assets/Scripts/UI/HudModel.cs+++ b/unity/Assets/Scripts/UI/HudModel.cs@@ -41,7 +41,8 @@ namespace Statecraft.Game.UI/// <summary>The top bar's meters, in its order (Game.uxml's "meters"), by the ids their elements are named after.</summary>public static readonly string[] MeterIds = { "treasury", "immigration", "security", "support", "cohesion", "standing", "fx" };- /// <summary>How many causes a meter's explanation names (#1037): the turn report and the bar's tip.</summary>+ /// <summary>How many causes a meter's explanation names (#1037): the turn report and the bar's tip. Money adds one+ /// Other line after them for the rest (#2212).</summary>public const int MaxCauses = 2;/// <summary>The meter named <paramref name="id"/> (one of <see cref="MeterIds"/>).</summary>@@ -56,16 +57,19 @@ namespace Statecraft.Game.UI/// (StepResult.Why) for the quantity the meter shows, each worded by <paramref name="line"/> (CauseText.Line: the/// player's language, B1), the largest change first (each meter's causes share its unit),/// the sim's order breaking a tie, at most <see cref="MaxCauses"/>. Nothing is computed or reworded here: a cause is- /// matched by its target, as <see cref="From"/> reads the state (Money: the Treasury and the debt; Immigration: the+ /// matched by its target, as <see cref="From"/> reads the state (Money: the sim's EconomySystem.MovesMoney, the lines+ /// that add up to the change in Treasury minus Debt, job income included and borrowing not, #2199; Immigration: the/// population system's arrivals; Social cohesion: morale; International support: intl_standing; Foreign currency:/// fx_reserves; Security: security). Public support is an average the sim computes from the indicators- /// (EffectsSystem.Approval) and no cause names it, so it has none.</summary>- public static IReadOnlyList<string> Causes(StepResult? turn, string meter, Func<Cause, string> line)+ /// (EffectsSystem.Approval) and no cause names it, so it has none. Money adds one line after them for the causes+ /// left out, summed by the sim (EconomySystem.OtherMoney, #2212), so its lines add up to the change; none when+ /// nothing is left over or the rest shows as IL 0.0m. <paramref name="c"/> is the game's content (its currency).</summary>+ public static IReadOnlyList<string> Causes(StepResult? turn, string meter, Content c, Func<Cause, string> line){if (turn == null) return Array.Empty<string>();Func<Cause, bool> match = meter switch{- "treasury" => w => w.Target == "treasury" || w.Target == "debt",+ "treasury" => w => EconomySystem.MovesMoney(w),"immigration" => w => w.System == "population","security" => w => w.Target == "security","cohesion" => w => w.Target == "morale",@@ -73,8 +77,10 @@ namespace Statecraft.Game.UI"fx" => w => w.Target == "fx_reserves",_ => w => false,};- return turn.Why.Select((w, i) => (w, i)).Where(x => match(x.w) && x.w.Delta != 0)- .OrderByDescending(x => Math.Abs(x.w.Delta)).ThenBy(x => x.i).Take(MaxCauses).Select(x => line(x.w)).ToList();+ var shown = turn.Why.Select((w, i) => (w, i)).Where(x => match(x.w) && x.w.Delta != 0)+ .OrderByDescending(x => Math.Abs(x.w.Delta)).ThenBy(x => x.i).Take(MaxCauses).Select(x => x.w).ToList();+ if (meter == "treasury" && EconomySystem.OtherMoney(c, turn.Why, shown) is Cause other) shown.Add(other);+ return shown.Select(line).ToList();}public static HudModel From(SimBridge b, UiText t)diff --git a/unity/Assets/Scripts/UI/MeterTip.cs b/unity/Assets/Scripts/UI/MeterTip.csindex cfa5f2b14..71e995f3c 100644--- a/unity/Assets/Scripts/UI/MeterTip.cs+++ b/unity/Assets/Scripts/UI/MeterTip.cs@@ -90,7 +90,7 @@ namespace Statecraft.Game.UI/// words, with the causes' heading when there are causes, and the causes, one a line (none when none).</summary>public (string words, IReadOnlyList<string> causes) Lines(VisualElement meter){- var causes = HudModel.Causes(bridge.Session.Last, meter.name.Substring("meter-".Length),+ var causes = HudModel.Causes(bridge.Session.Last, meter.name.Substring("meter-".Length), bridge.Content,w => CauseText.Line(w, bridge.Content, Array.Empty<Statecraft.Game.Map.Units.UnitEntry>(), text, TownNamesHe)); // no meter counts a unit linereturn causes.Count == 0 ? (meter.tooltip, causes) : (meter.tooltip + "\n" + text["hud.causes"], causes);}diff --git a/unity/Assets/Scripts/UI/TurnReportPresenter.cs b/unity/Assets/Scripts/UI/TurnReportPresenter.csindex b6ffc3fd2..d2aa4e34a 100644--- a/unity/Assets/Scripts/UI/TurnReportPresenter.cs+++ b/unity/Assets/Scripts/UI/TurnReportPresenter.cs@@ -109,7 +109,7 @@ namespace Statecraft.Game.UIif (id == "cohesion" && !m.ShowsCohesion) continue;var meter = m.For(id);if (meter.Delta.Length == 0) continue;- lines.Add(new Line(id, text.Format("report.line", text["hud.caption." + id], meter.Delta), HudModel.Causes(bridge.Session.Last, id,+ lines.Add(new Line(id, text.Format("report.line", text["hud.caption." + id], meter.Delta), HudModel.Causes(bridge.Session.Last, id, bridge.Content,w => CauseText.Line(w, bridge.Content, units ?? Array.Empty<UnitEntry>(), text, townNamesHe))));}lines.AddRange(StockLines(bridge, text, units, townNamesHe));diff --git a/unity/Assets/Tests/EditMode/CauseTextTests.cs b/unity/Assets/Tests/EditMode/CauseTextTests.csindex f314c158f..d7f50900d 100644--- a/unity/Assets/Tests/EditMode/CauseTextTests.cs+++ b/unity/Assets/Tests/EditMode/CauseTextTests.cs@@ -43,8 +43,8 @@ public class CauseTextTests{foreach (var id in HudModel.MeterIds){- var before = HudModel.Causes(turn, id, w => w.Message);- CollectionAssert.AreEqual(before, HudModel.Causes(turn, id, w => CauseText.Line(w, C, NoRows, en)), id);+ var before = HudModel.Causes(turn, id, C, w => w.Message);+ CollectionAssert.AreEqual(before, HudModel.Causes(turn, id, C, w => CauseText.Line(w, C, NoRows, en)), id);rows += before.Count;}foreach (var w in turn.Why.Where(w => CauseKeys.All.Contains(w.Key)))@@ -99,9 +99,11 @@ public class CauseTextTestss.ActiveSituations.Add("food_crisis"); s.Indicators["food_supply"] = 0.6;EffectsSystem.UpdateSituations(C, s, why);// Civilian upkeep: the real content's places cost nothing yet, so the line is the sim's own (EconomySystem.PayCivilianUpkeep),- // and the borrowing comes from PayOrBorrow with that purpose.+ // and the borrowing comes from PayNamedOrBorrow with that purpose.why.Add(new Cause("economy", "treasury", -2, PlayerText.Change(C, "treasury", -2) + " (civilian upkeep)", key: CauseKeys.CivilianUpkeep));- EconomySystem.PayOrBorrow(C, s, s.Treasury + 3, "for civilian upkeep", why, CauseKeys.Purpose.CivilianUpkeep);+ EconomySystem.PayNamedOrBorrow(C, s, s.Treasury + 3, "for civilian upkeep", why, CauseKeys.Purpose.CivilianUpkeep);+ // #2212: Money's Other line, the rest of the causes a list leaves out (here all of them: the IL -2.0m upkeep).+ why.Add(EconomySystem.OtherMoney(C, why, new Cause[0])!);s.ActiveSituations.Add(EconomySystem.FxCrisis); s.FxReserves = 1e6;EconomySystem.Apply(C, s, 0.25, why);s.ActiveSituations.Remove(EconomySystem.FxCrisis); s.FxReserves = -1e6;@@ -115,7 +117,7 @@ public class CauseTextTestsSecuritySystem.Apply(legacy, l, 1, why);var keys = why.Where(w => CauseKeys.All.Contains(w.Key)).Select(w => w.Key).Distinct().ToList();- foreach (var key in new[] { CauseKeys.CallUpSet, CauseKeys.SituationEnded, CauseKeys.CivilianUpkeep, CauseKeys.Borrowed,+ foreach (var key in new[] { CauseKeys.CallUpSet, CauseKeys.SituationEnded, CauseKeys.CivilianUpkeep, CauseKeys.Borrowed, CauseKeys.MoneyOther,CauseKeys.FxCrisisEased, CauseKeys.FxCrisisBegan, CauseKeys.FxCrisisFood, CauseKeys.Ceasefire })CollectionAssert.Contains(keys, key, "precondition");var en = En; var he = He;@@ -152,13 +154,15 @@ public class CauseTextTests(CauseKeys.Purpose.Occupation, $"for the occupation of {placeName}", new[] { place }),(CauseKeys.Purpose.Event, $"for {ev.Title}", new[] { ev.Id, ev.Title, "1" }),};- CollectionAssert.AreEquivalent(CauseKeys.Purpose.All.Where(p => p != CauseKeys.Purpose.Deficit), purposes.Select(p => p.Key), "every purpose");+ // A map action borrows with its own key (CauseKeys.MapBorrowed): its purpose names only its Paid line (#2199).+ CollectionAssert.AreEquivalent(CauseKeys.Purpose.All.Where(p => p != CauseKeys.Purpose.Deficit && p != CauseKeys.Purpose.MapAction),+ purposes.Select(p => p.Key), "every purpose");var en = En; var he = He;foreach (var (key, english, args) in purposes){var why = new List<Cause>();var s = Simulation.NewGame(C, GoldenRun.Seed, Mode.Historical);- EconomySystem.PayOrBorrow(C, s, s.Treasury + 3, english, why, key, args);+ EconomySystem.PayNamedOrBorrow(C, s, s.Treasury + 3, english, why, key, args); // the borrowing line alonevar line = why.Single();Assert.AreEqual(line.Message, CauseText.Line(line, C, NoRows, en), key);AssertHebrew(CauseText.Line(line, C, NoRows, he), key);@@ -169,6 +173,47 @@ public class CauseTextTestsargs: new[] { CauseKeys.Purpose.Project, housing.Id }), C, NoRows, he), "the project kind's Hebrew name");}+ /// <summary>#2199: PayOrBorrow's Money line (CauseKeys.Paid) for every purpose whose cost has no Money line of its own+ /// (the English purpose as each caller words it): English is the Message, Hebrew is Hebrew, and a project kind and a+ /// settlement are named in Hebrew. Civilian and military upkeep, a Deport and an event's cost write their own line and+ /// borrow through PayNamedOrBorrow, and the deficit borrows in EconomySystem.Apply, so none of them has a Paid line.</summary>+ [Test]+ public void EveryPaidPurposeIsWordedInBothLanguages()+ {+ var place = C.SettlementTargets[0].Id; var placeName = C.SettlementNames[place];+ var housing = C.ProjectKinds.First(k => k.Id == "housing");+ var purposes = new (string Key, string English, string[] Args)[]+ {+ (CauseKeys.Purpose.Corridor, "to build a corridor segment", new string[0]),+ (CauseKeys.Purpose.Arms, "for Arms", new string[0]),+ (CauseKeys.Purpose.Training, "for training", new string[0]),+ (CauseKeys.Purpose.Prisoners, "for our soldiers held by the enemy", new string[0]),+ (CauseKeys.Purpose.TrainingCamp, "to build a training camp", new string[0]),+ (CauseKeys.Purpose.Plow, "to plow fields", new string[0]),+ (CauseKeys.Purpose.Drain, "to drain a swamp", new string[0]),+ (CauseKeys.Purpose.Yishuv, "to build a yishuv", new string[0]),+ (CauseKeys.Purpose.Project, "to build " + housing.Name, new[] { housing.Id }),+ (CauseKeys.Purpose.Occupation, $"for the occupation of {placeName}", new[] { place }),+ (CauseKeys.Purpose.MapAction, "to build " + PlayerText.MapAction(C, MapActions.Housing), new[] { MapActions.Housing }), // as MapActions.Apply+ };+ CollectionAssert.AreEquivalent(CauseKeys.Purpose.All.Except(new[] { CauseKeys.Purpose.Deficit, CauseKeys.Purpose.CivilianUpkeep,+ CauseKeys.Purpose.MilitaryUpkeep, CauseKeys.Purpose.Deport, CauseKeys.Purpose.Event }), purposes.Select(p => p.Key), "every paying purpose");+ var en = En; var he = He;+ foreach (var (key, english, args) in purposes)+ {+ var why = new List<Cause>();+ var s = Simulation.NewGame(C, GoldenRun.Seed, Mode.Historical);+ EconomySystem.PayOrBorrow(C, s, s.Treasury + 3, english, why, key, args);+ var line = why.Single(w => w.Key == CauseKeys.Paid);+ Assert.AreEqual(line.Message, CauseText.Line(line, C, NoRows, en), key);+ AssertHebrew(CauseText.Line(line, C, NoRows, he), key);+ }+ StringAssert.Contains(housing.NameHe, CauseText.Line(new Cause("economy", "treasury", -3, "x", key: CauseKeys.Paid,+ args: new[] { CauseKeys.Purpose.Project, housing.Id }), C, NoRows, he), "the project kind's Hebrew name");+ StringAssert.Contains(he["info.map_action." + MapActions.Housing], CauseText.Line(new Cause("economy", "treasury", -3, "x", key: CauseKeys.Paid,+ args: new[] { CauseKeys.Purpose.MapAction, MapActions.Housing }), C, NoRows, he), "the map action's Hebrew name");+ }+/// <summary>A line with no key yet keeps the sim's English; a unit line is still UnitNames' (#1399).</summary>[Test]public void OtherLinesAreUnchanged()@@ -445,7 +490,7 @@ public class CauseTextTestsAssertHebrew(CauseText.Line(row, c, NoRows, he, names), row.Key);}CollectionAssert.AreEquivalent(CauseKeys.All.Except(new[] {- CauseKeys.MoneyFlows, CauseKeys.FxFlows, CauseKeys.Borrowed, CauseKeys.CivilianUpkeep,+ CauseKeys.MoneyFlows, CauseKeys.FxFlows, CauseKeys.Borrowed, CauseKeys.Paid, CauseKeys.MoneyOther, CauseKeys.CivilianUpkeep,CauseKeys.FxCrisisBegan, CauseKeys.FxCrisisEased, CauseKeys.FxCrisisFood, CauseKeys.Arrived,CauseKeys.EffectChange, CauseKeys.SituationBegan, CauseKeys.SituationEnded, CauseKeys.RungChanged,CauseKeys.CallUpSet, CauseKeys.CallUpRaised, CauseKeys.CallUpLowered, CauseKeys.Ceasefire,diff --git a/unity/Assets/Tests/EditMode/HudTests.cs b/unity/Assets/Tests/EditMode/HudTests.csindex 8b1749fde..d486c0da7 100644--- a/unity/Assets/Tests/EditMode/HudTests.cs+++ b/unity/Assets/Tests/EditMode/HudTests.cs@@ -17,6 +17,60 @@ public class HudTestsstatic UiText Text => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);static SimBridge NewBridge() => new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);+ /// <summary>#2199: the Money meter's causes are the sim's Money lines (EconomySystem.MovesMoney): a city's job income+ /// is one, though its Target is the city; a borrowing line (Target debt) is not, as it moves the Treasury and the Debt+ /// alike. The largest first, at most MaxCauses (#1037). After the real opening turn, job income is among them.</summary>+ [Test]+ public void MoneyCausesIncludeJobIncomeAndLeaveOutBorrowing()+ {+ var why = new List<Cause>+ {+ new Cause("economy", "treasury", -0.4, "Money IL -0.4m (military upkeep)", key: CauseKeys.MilitaryUpkeep),+ new Cause("city", "tel_aviv", 0.53, "Tel Aviv: jobs paid IL +0.5m", key: CauseKeys.WagesPaid),+ new Cause("economy", "debt", 9, "Borrowed IL 9.0m to cover the deficit", key: CauseKeys.Borrowed, args: new[] { CauseKeys.Purpose.Deficit }),+ };+ var turn = new StepResult(new GameState(), why, new Rejection[0]);+ CollectionAssert.AreEqual(new[] { "Tel Aviv: jobs paid IL +0.5m", "Money IL -0.4m (military upkeep)" },+ HudModel.Causes(turn, "treasury", C, w => w.Message));++ var b = NewBridge();+ b.EndTurn();+ CollectionAssert.Contains(HudModel.Causes(b.Session.Last, "treasury", C, w => w.Key), CauseKeys.WagesPaid, "the opening turn's job income");+ }++ /// <summary>#2212: Money shows its two largest causes (MaxCauses) and one Other line for the rest, summed by the sim+ /// (EconomySystem.OtherMoney), so the lines add up to the Money (net) change. No Other line with two causes or fewer,+ /// or when the rest shows as IL 0.0m; no other meter gets one. After the real opening turn the lines add up.</summary>+ [Test]+ public void MoneyShowsTheTwoLargestCausesAndOneOtherLineForTheRest()+ {+ Cause Money(double d, string what) => new Cause("economy", "treasury", d, PlayerText.Change(C, "treasury", d) + " (" + what + ")", key: CauseKeys.MilitaryUpkeep);+ var borrowing = new Cause("economy", "debt", 9, "Borrowed IL 9.0m to cover the deficit", key: CauseKeys.Borrowed, args: new[] { CauseKeys.Purpose.Deficit });+ IReadOnlyList<string> Lines(string meter, params Cause[] why) =>+ HudModel.Causes(new StepResult(new GameState(), why.Append(borrowing).ToList(), new Rejection[0]), meter, C, w => w.Message);++ var a = Money(-3, "a"); var b = Money(2, "b");+ CollectionAssert.AreEqual(new[] { "Money IL -3.0m (a)", "Money IL +2.0m (b)", "Money IL -0.3m (other causes)" },+ Lines("treasury", Money(0.1, "d"), a, Money(-0.4, "c"), b), "three or more causes: the two largest, then the rest");+ CollectionAssert.AreEqual(new[] { "Money IL -3.0m (a)", "Money IL +2.0m (b)" }, Lines("treasury", a, b), "two causes: no Other line");+ CollectionAssert.AreEqual(new[] { "Money IL -3.0m (a)" }, Lines("treasury", a), "one cause: no Other line");+ CollectionAssert.AreEqual(new[] { "Money IL -3.0m (a)", "Money IL +2.0m (b)" }, Lines("treasury", a, b, Money(0.04, "c")),+ "the rest shows as IL 0.0m: no Other line");+ CollectionAssert.AreEqual(new[] { "Money IL -3.0m (a)", "Money IL +2.0m (b)" }, Lines("treasury", a, b, Money(1, "c"), Money(-1, "d")),+ "the rest cancels out: no Other line");+ Cause Security(double d) => new Cause("events", "security", d, PlayerText.Change(C, "security", d));+ Assert.AreEqual(HudModel.MaxCauses, Lines("security", Security(0.03), Security(0.02), Security(0.01)).Count, "only Money gets an Other line");++ var bridge = NewBridge();+ bridge.EndTurn();+ var shown = new List<Cause>();+ HudModel.Causes(bridge.Session.Last, "treasury", C, w => { shown.Add(w); return w.Message; });+ Assert.AreEqual(HudModel.MaxCauses + 1, shown.Count, "the opening turn has more Money causes than MaxCauses");+ Assert.AreEqual(CauseKeys.MoneyOther, shown[shown.Count - 1].Key);+ var s = bridge.State; var prev = bridge.Session.Previous!;+ Assert.AreEqual((s.Treasury - s.Debt) - (prev.Treasury - prev.Debt), shown.Sum(w => w.Delta), 1e-9, "the lines add up to the Money (net) change");+ }+[Test]public void TheTopBarShowsTheOpeningOfTheGame(){diff --git a/unity/Assets/Tests/EditMode/MeterTipTests.cs b/unity/Assets/Tests/EditMode/MeterTipTests.csindex 8085bc324..9334573b3 100644--- a/unity/Assets/Tests/EditMode/MeterTipTests.cs+++ b/unity/Assets/Tests/EditMode/MeterTipTests.cs@@ -53,16 +53,18 @@ public class MeterTipTestsvar meter = root.Q("meter-" + id);Enter(meter);for (int i = 0; i < 3; i++) yield return null; // the tip is placed once its width is laid out- var causes = HudModel.Causes(bridge.Session.Last, id, w => CauseText.Line(w, bridge.Content, System.Array.Empty<Statecraft.Game.Map.Units.UnitEntry>(), text));+ var causes = HudModel.Causes(bridge.Session.Last, id, bridge.Content, w => CauseText.Line(w, bridge.Content, System.Array.Empty<Statecraft.Game.Map.Units.UnitEntry>(), text));if (!Shown(tip)) { problems.Add($"{at} {id}: hovering shows no tip"); continue; }if (Words(root) != meter.tooltip + "\n" + text["hud.causes"]) problems.Add($"{at} {id}: the tip's words are '{Words(root)}', not its tooltip and the causes' heading");if (CausesLine(root) != string.Join("\n", causes)) problems.Add($"{at} {id}: the tip's causes are '{CausesLine(root)}', not the sim's '{string.Join(" | ", causes)}'");if (UiDirection.RightToLeft(Words(root)) != hebrew) problems.Add($"{at} {id}: the words are not in the UI's language");// B1: a keyed line is in the UI's language (#55: lines with no key stay English). Since #1565 Security's// opening causes are One Army and Degania, two event lines with no key, so its causes stay English.- var keyed = HudModel.Causes(bridge.Session.Last, id, w => w.Key).Any(k => k != "");+ var keyed = HudModel.Causes(bridge.Session.Last, id, bridge.Content, w => w.Key).Any(k => k != "");if (UiDirection.HasRightToLeft(CausesLine(root)) != (hebrew && keyed)) problems.Add($"{at} {id}: the causes '{CausesLine(root)}' are not in the UI's language");if (causes.Count == 0) problems.Add($"{at} {id}: precondition: the opening turn has causes for it");+ // #2212: the opening turn has more Money causes than MaxCauses, so Money's tip ends with one Other line.+ if (id == "treasury" && causes.Count != HudModel.MaxCauses + 1) problems.Add($"{at} {id}: {causes.Count} causes, not the two largest and one Other line");Rect t = tip.worldBound, m = meter.worldBound, win = root.worldBound;if (t.xMin < win.xMin - 0.5f || t.xMax > win.xMax + 0.5f || t.yMax > win.yMax + 0.5f) problems.Add($"{at} {id}: the tip {t} leaves the window {win}");if (t.yMin < m.yMax) problems.Add($"{at} {id}: the tip {t} is not under its number {m}");diff --git a/unity/Assets/Tests/EditMode/TurnReportTests.cs b/unity/Assets/Tests/EditMode/TurnReportTests.csindex cc40d5c78..8a84d213e 100644--- a/unity/Assets/Tests/EditMode/TurnReportTests.cs+++ b/unity/Assets/Tests/EditMode/TurnReportTests.cs@@ -53,7 +53,9 @@ public class TurnReportTestsstatic List<string> Causes(UiTestKit ui, string meter) =>ui.Q<VisualElement>("turn-report-causes-" + meter).Query<Label>(className: "turn-report-cause").ToList().Select(l => l.text).ToList();- /// <summary>The main B1 occupation/deport borrowing keys use the real map names in report and meter paths too.+ /// <summary>The main B1 occupation/deport keys use the real map names in report and meter paths too: the cost's Money+ /// line (occupation: PayOrBorrow's Paid line; Deport: its own line, as SettlementControl writes it), and the borrowing+ /// line's own wording. Borrowing is not a Money cause (#2199), so the meter shows the cost's line./// This is only a formatter fixture: it does not enable or execute the disabled Deport command.</summary>[TestCase(CauseKeys.Purpose.Occupation)][TestCase(CauseKeys.Purpose.Deport)]@@ -70,8 +72,16 @@ public class TurnReportTestsvar why = new List<Cause>();var placeName = PlayerText.Settlement(C, city);var englishPurpose = purpose == CauseKeys.Purpose.Deport ? $"for the Deport of {placeName}" : $"for the occupation of {placeName}";- EconomySystem.PayOrBorrow(C, last.State, last.State.Treasury + 3, englishPurpose, why, purpose, city);- var cause = why.Single();+ var cost = last.State.Treasury + 3;+ if (purpose == CauseKeys.Purpose.Occupation)+ EconomySystem.PayOrBorrow(C, last.State, cost, englishPurpose, why, purpose, city);+ else+ {+ why.Add(new Cause("economy", "treasury", -cost, $"{PlayerText.Change(C, "treasury", -cost)} (Deport of {placeName})", key: CauseKeys.DeportCost, args: new[] { city }));+ EconomySystem.PayNamedOrBorrow(C, last.State, cost, englishPurpose, why, purpose, city);+ }+ Assert.AreEqual(2, why.Count, "the cost's Money line, then the borrowing");+ var cause = why[1];Assert.AreEqual(CauseKeys.Borrowed, cause.Key);// Existing TurnReportTests uses this setter for a precise report fixture; no simulation input or content is changed.typeof(GameSession).GetProperty(nameof(GameSession.Last))!.SetValue(k.Bridge.Session,@@ -116,12 +126,12 @@ public class TurnReportTestsvar heading = k.Ui.Q<Label>("turn-report-heading-" + id).text;Assert.AreEqual(En.Format("report.line", En["hud.caption." + id], k.Ui.Q<Label>(id + "-delta").text), heading, id);var causes = k.Ui.Root.Q("turn-report-causes-" + id);- var expected = HudModel.Causes(turn, id, w => CauseText.Line(w, C, System.Array.Empty<UnitEntry>(), En));+ var expected = HudModel.Causes(turn, id, C, w => CauseText.Line(w, C, System.Array.Empty<UnitEntry>(), En));if (expected.Count == 0) { Assert.IsNull(causes, id + ": no cause line without a cause"); continue; }var lines = Causes(k.Ui, id);CollectionAssert.AreEqual(expected, lines, id);- Assert.LessOrEqual(lines.Count, HudModel.MaxCauses, id);- foreach (var line in lines) Assert.IsTrue(messages.Contains(line), $"{id}: '{line}' is a cause of StepResult.Why, word for word");+ Assert.LessOrEqual(lines.Count, HudModel.MaxCauses + (id == "treasury" ? 1 : 0), id); // Money's Other line (#2212)+ foreach (var line in lines.Take(HudModel.MaxCauses)) Assert.IsTrue(messages.Contains(line), $"{id}: '{line}' is a cause of StepResult.Why, word for word");}// The fixed turn's own causes, the larger first and at most MaxCauses (2): Security moved by One Army and the// defence of Degania, the same size, in the order the cards came (R-EVT-006); the border villages' smaller effect@@ -129,6 +139,17 @@ public class TurnReportTestsvar security = Causes(k.Ui, "security");CollectionAssert.AreEqual(new[] { "Security +1.5% (One Army)", "Security +1.5% (The Defence of Degania)" }, security);StringAssert.StartsWith("Money ", Causes(k.Ui, "treasury")[0], "Money's main cause is the economy's line");+ // #2212: Money's two largest causes, then one Other line for the rest (EconomySystem.OtherMoney), so the lines add+ // up to the change the heading shows.+ var money = Causes(k.Ui, "treasury");+ var shown = new List<Cause>();+ HudModel.Causes(turn, "treasury", C, w => { shown.Add(w); return ""; });+ Assert.AreEqual(HudModel.MaxCauses + 1, money.Count, "the opening turn has more Money causes than the two shown");+ Assert.AreEqual(CauseKeys.MoneyOther, shown[shown.Count - 1].Key);+ Assert.AreEqual(shown[shown.Count - 1].Message, money[money.Count - 1]);+ StringAssert.EndsWith(" (other causes)", money[money.Count - 1]);+ var s = k.Bridge.State; var prev = k.Bridge.Session.Previous!;+ Assert.AreEqual((s.Treasury - s.Debt) - (prev.Treasury - prev.Debt), shown.Sum(w => w.Delta), 1e-9, "the lines add up to the Money (net) change");Assert.IsNull(k.Ui.Root.Q("turn-report-causes-support"), "no cause names Public support (an average of the indicators)");}@@ -282,12 +303,17 @@ public class TurnReportTests// In a right-to-left line the change keeps its sign in front ("+2%", not "2%+"): UiText.Format marks it (#543).StringAssert.Contains(UiText.LeftToRightMark + k.Ui.Q<Label>("security-delta").text + UiText.LeftToRightMark, heading);var causes = Causes(k.Ui, "security");- CollectionAssert.AreEqual(HudModel.Causes(k.Bridge.Session.Last, "security", w => CauseText.Line(w, C, System.Array.Empty<UnitEntry>(), He)), causes,+ CollectionAssert.AreEqual(HudModel.Causes(k.Bridge.Session.Last, "security", C, w => CauseText.Line(w, C, System.Array.Empty<UnitEntry>(), He)), causes,"the causes are the sim's, worded as on the Why screen");// B1: the treasury's tax-and-spending line is Hebrew (a line with no key yet, such as an event's, stays English).Assert.IsTrue(UiDirection.RightToLeft(Causes(k.Ui, "treasury")[0]), "the money line is in Hebrew");+ // #2212: Money's Other line too (why.cause.money_other).+ var money = Causes(k.Ui, "treasury");+ Assert.AreEqual(HudModel.MaxCauses + 1, money.Count, "the two largest Money causes and the Other line");+ Assert.IsTrue(UiDirection.RightToLeft(money[money.Count - 1]), "the Other line is in Hebrew");+ StringAssert.Contains("(סיבות אחרות)", money[money.Count - 1]);// B1: one label a cause, so a Hebrew line and a line still in English each take their own direction.- Assert.AreEqual(HudModel.Causes(k.Bridge.Session.Last, "security", w => w.Message).Count,+ Assert.AreEqual(HudModel.Causes(k.Bridge.Session.Last, "security", C, w => w.Message).Count,k.Q("turn-report-causes-security").Query<Label>(className: "turn-report-cause").ToList().Count);}diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 296fa0196..c81edaed5 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -401,6 +401,19 @@ why.cause.borrowed.project: "Borrowed {0} to build {1}"why.cause.borrowed.deport: "Borrowed {0} for the Deport of {1}"why.cause.borrowed.occupation: "Borrowed {0} for the occupation of {1}"why.cause.borrowed.event: "Borrowed {0} for {1}"+why.cause.paid.corridor: "{0} {1} (to build a corridor segment)"+why.cause.paid.arms: "{0} {1} (for Arms)"+why.cause.paid.training: "{0} {1} (for training)"+why.cause.paid.prisoners: "{0} {1} (for our soldiers held by the enemy)"+why.cause.paid.training_camp: "{0} {1} (to build a training camp)"+why.cause.paid.plow: "{0} {1} (to plow fields)"+why.cause.paid.drain: "{0} {1} (to drain a swamp)"+why.cause.paid.yishuv: "{0} {1} (to build a yishuv)"+why.cause.paid.project: "{0} {1} (to build {2})"+why.cause.paid.occupation: "{0} {1} (for the occupation of {2})"+why.cause.paid.map_action: "{0} {1} (to build {2})"+# #2212: Money's Other line in the turn report and the meter tip, the causes left out after the two largest, summed.+why.cause.money_other: "{0} {1} (other causes)"why.cause.fx_crisis_began: "Foreign currency reserves are exhausted"why.cause.fx_crisis_eased: "Foreign currency crisis eased"why.cause.fx_crisis_food: "{0} {1} (foreign currency crisis: food imports cut)"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex 401c22c8f..1b8d389e8 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -435,6 +435,24 @@ why.cause.borrowed.project: "הלוואה של {0} לבניית {1}"why.cause.borrowed.deport: "הלוואה של {0} לגירוש ({1})"why.cause.borrowed.occupation: "הלוואה של {0} לעלות ההחזקה ({1})"why.cause.borrowed.event: "הלוואה של {0} עבור {1}"+# #2199: the why.cause.paid.* lines below are agent-drafted Hebrew, not part of #1642's owner review above. Each reuses+# its why.cause.borrowed.* purpose phrase, except paid.occupation, which is newly worded. Native review pending (#564).+why.cause.paid.corridor: "{0}: שינוי {1} (לבניית קטע של כביש או מסילה)"+why.cause.paid.arms: "{0}: שינוי {1} (לרכישת נשק)"+why.cause.paid.training: "{0}: שינוי {1} (לאימון ולהכשרה)"+why.cause.paid.prisoners: "{0}: שינוי {1} (עבור חיילינו המוחזקים בידי האויב)"+why.cause.paid.training_camp: "{0}: שינוי {1} (להקמת מחנה אימונים)"+why.cause.paid.plow: "{0}: שינוי {1} (לחריש שדות)"+why.cause.paid.drain: "{0}: שינוי {1} (לייבוש ביצה)"+why.cause.paid.yishuv: "{0}: שינוי {1} (להקמת יישוב)"+why.cause.paid.project: "{0}: שינוי {1} (לבניית {2})"+why.cause.paid.occupation: "{0}: שינוי {1} (לעלות ההחזקה של {2})"+# A map action's cost (#2199); {2} is an info.map_action.* noun, as in why.cause.map_borrowed. Agent-drafted Hebrew;+# native review pending (#564).+why.cause.paid.map_action: "{0}: שינוי {1} (לבניית {2})"+# #2212: Money's Other line in the turn report and the meter tip, the causes left out after the two largest, summed.+# Agent-drafted Hebrew, not part of #1642's owner review; native review pending (#564).+why.cause.money_other: "{0}: שינוי {1} (סיבות אחרות)"why.cause.fx_crisis_began: "יתרות מטבע החוץ אזלו"why.cause.fx_crisis_eased: "הקלה במשבר מטבע החוץ"why.cause.fx_crisis_food: "{0}: שינוי {1} (משבר מטבע חוץ: קיצוץ ביבוא המזון)"