Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

sim: an event's Treasury cost borrows what the Treasury lacks (R-MONEY-003) (#684)

Eyal Golanfa5df209aeb9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0affa8567..a9b18dd83 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,10 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
## [Unreleased]
### Changed
+- An event option's Treasury cost the Treasury cannot cover is now borrowed at once, like every other payment, with a cause
+ naming the event (refs #681, R-MONEY-003). Before, the Treasury went below 0 until the deficit step, which reported the
+ shortfall as "to cover the deficit". End-of-turn totals are unchanged and no golden moves. The top bar's Treasury is
+ still cash minus debt, so it reads negative once anything is borrowed.
- `bernadotte_assassination` says "about 250" Lehi members were arrested, not "about 200" (refs #516; owner, 15 October
2026): Ben-Gurion told the Provisional State Council 246 (184 + 62), and S/1315 gives 266 by 23 September (184 + 82).
Card text only: no golden moves, the content hash does, so an older save loads with the "different game content"
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index eec1737dd..b394f9d81 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -75,3 +75,9 @@ R-OBJ-001: An objective (`objectives.yaml`) names its condition, `completes_when
R-OBJ-002: Recording an objective adds `objective_points + min(objective_bonus_cap, objective_bonus_per_month * monthsEarly)` to the score, once. `monthsEarly` is `max(0, monthsFromHistory)`, and `monthsFromHistory` counts calendar months from the completion's month to the reference date's month, `(y2 - y1) * 12 + (m2 - m1)`: 0 in the same month ("on time, as in history"), negative when late (owner's card wording, #379, 14 October 2026). Late costs nothing. The owner set 100 points (D-B6) and +5 a month capped at +60 (D-B2) on 14 October 2026 (#456); they are balance values and stay tunable, as `rules.yaml` design values (R-LOOP-005). The rules are those of the date the turn starts from (docs/determinism.md, "Rules per era"), so a turn that ends on the next era's first day scores with the era it started in.
R-OBJ-003: An event with `objective:` is that objective's card. It is eligible only once its objective is recorded, so it fires once, at the end of the turn the objective is completed in, and never in the legacy loop. A card has exactly one option, and an objective and its card name each other (the loader checks both). An unanswered card resolves to its option without drawing from the RNG.
+
+## Money
+
+R-MONEY-003: A GDD cost above the Treasury is paid, and the shortfall moves to debt, as map actions do: the Treasury stops at 0, and a cause names what the shortfall was borrowed for (Q-MONEY-3, owner decision "Allow borrowing", 15 October 2026, for training and pioneer work; the Phase 2 plan applies it to every GDD cost). It covers the deficit, map actions, training (R-TRAIN-001), pioneer work (R-SITE-001) and an event option's Treasury cost.
+
+The top bar shows the net position, Treasury minus debt (`HudModel.From`), so it reads below 0 once anything is borrowed.
diff --git a/sim/Statecraft.Sim.Tests/TreasuryFloorTests.cs b/sim/Statecraft.Sim.Tests/TreasuryFloorTests.cs
new file mode 100644
index 000000000..ae4639598
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/TreasuryFloorTests.cs
@@ -0,0 +1,88 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Statecraft.Sim;
+
+/// <summary>R-MONEY-003: the Treasury never goes below 0; every payment it cannot cover is borrowed (T71, #681).</summary>
+public class TreasuryFloorTests
+{
+ static readonly Content Real = ContentLoader.Load(RealContentTests.ContentRoot());
+
+ // R-MONEY-003: the golden run (the reference player on the real GDD loop) never leaves a negative Treasury, though it
+ // borrows from the fourth monthly turn on. What goes below 0 is the net position (Treasury minus Debt) the top bar shows.
+ [Fact]
+ public void TheReferenceRunNeverLeavesANegativeTreasury()
+ {
+ var s = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);
+ int? firstDebt = null;
+ while (s.GameOver == null && s.Turn < 1000)
+ {
+ s = Simulation.Step(Real, s, GoldenRun.Orders(Real, s)).State;
+ Assert.True(s.Treasury >= 0, $"turn {s.Turn} ({s.Date:yyyy-MM-dd}): Treasury {s.Treasury}");
+ if (firstDebt == null && s.Debt > 0) firstDebt = s.Turn;
+ }
+ Assert.Equal(4, firstDebt); // 15 September 1948: the HUD's "-IL 1.5m" is 0 cash and IL 1.5m debt
+ }
+
+ // R-MONEY-003: an event's cost is a payment like any other. With IL 0.4m in the Treasury, the IL 1m claim on Germany
+ // pays 0.4 and borrows 0.6, named for the event; before T71 it left the Treasury at -0.6 until the deficit step.
+ [Fact]
+ public void AnEventCostTheTreasuryCannotCoverIsBorrowed()
+ {
+ var s = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);
+ s.PendingEvents.Clear();
+ s.PendingEvents.Add("reparations_claim");
+ s.Treasury = 0.4;
+ s.Debt = 3;
+ var why = new List<Cause>();
+ Assert.Null(EventSystem.Choose(Real, s, "reparations_claim", "claim", why));
+ Assert.Equal(0, s.Treasury);
+ Assert.Equal(3.6, s.Debt, 9);
+ Assert.Contains(why, x => x.System == "economy" && x.Target == "debt" && x.Message == "Borrowed IL 0.6m for A Claim on Germany");
+ }
+
+ // R-MONEY-003: the Why list reads the event's cost first, then what was borrowed for it.
+ [Fact]
+ public void AnEventCostIsReportedBeforeTheBorrowing()
+ {
+ var s = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);
+ s.PendingEvents.Clear();
+ s.PendingEvents.Add("reparations_claim");
+ s.Treasury = 0.4;
+ var why = new List<Cause>();
+ Assert.Null(EventSystem.Choose(Real, s, "reparations_claim", "claim", why));
+ var money = why.Where(x => x.Target == "treasury" || x.Target == "debt").Select(x => x.Message).ToList();
+ Assert.Equal(new[] { "Treasury -IL 1.0m (A Claim on Germany)", "Borrowed IL 0.6m for A Claim on Germany" }, money);
+ }
+
+ // R-MONEY-003: an event that brings money in adds it to the Treasury and borrows nothing, debt or no debt.
+ [Fact]
+ public void AnEventGainAddsToTheTreasuryAndBorrowsNothing()
+ {
+ var s = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);
+ s.PendingEvents.Clear();
+ s.PendingEvents.Add("maabarot_policy");
+ s.Treasury = 0.4;
+ s.Debt = 3;
+ var why = new List<Cause>();
+ Assert.Null(EventSystem.Choose(Real, s, "maabarot_policy", "maabarot", why));
+ Assert.Equal(2.4, s.Treasury, 9);
+ Assert.Equal(3, s.Debt);
+ Assert.DoesNotContain(why, x => x.Target == "debt");
+ }
+
+ // R-MONEY-003: an event cost the Treasury holds is paid from it, and nothing is borrowed.
+ [Fact]
+ public void AnEventCostTheTreasuryCoversBorrowsNothing()
+ {
+ var s = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);
+ s.PendingEvents.Clear();
+ s.PendingEvents.Add("reparations_claim");
+ s.Treasury = 5;
+ var why = new List<Cause>();
+ Assert.Null(EventSystem.Choose(Real, s, "reparations_claim", "claim", why));
+ Assert.Equal(4, s.Treasury, 9);
+ Assert.Equal(0, s.Debt);
+ Assert.DoesNotContain(why, x => x.Target == "debt");
+ }
+}
diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.cs
index 53074dd45..7ed347985 100644
--- a/sim/Statecraft.Sim/EventSystem.cs
+++ b/sim/Statecraft.Sim/EventSystem.cs
@@ -67,8 +67,15 @@ namespace Statecraft.Sim
foreach (var fx in o.Effects.Where(fx => EventRules.SpecialTargets.Contains(fx.Target) || s.Indicators.ContainsKey(fx.Target)))
{
var change = fx.Delta;
- if (fx.Target == "treasury") s.Treasury += fx.Delta;
- else if (fx.Target == "fx_reserves") s.FxReserves += fx.Delta;
+ if (fx.Target == "treasury")
+ {
+ // 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})"));
+ if (fx.Delta < 0) EconomySystem.PayOrBorrow(c, s, -fx.Delta, $"for {title}", why);
+ else s.Treasury += fx.Delta;
+ continue;
+ }
+ 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, $"{PlayerText.Change(c, fx.Target, change)} ({title})"));
}
diff --git a/unity/Assets/Tests/EditMode/HudTests.cs b/unity/Assets/Tests/EditMode/HudTests.cs
index 5605b22f3..2f2b42505 100644
--- a/unity/Assets/Tests/EditMode/HudTests.cs
+++ b/unity/Assets/Tests/EditMode/HudTests.cs
@@ -33,6 +33,21 @@ public class HudTests
Assert.AreEqual("", m.Treasury.Delta); // no previous turn yet
}
+ /// <summary>T71: the top bar's Treasury is the net position, cash minus debt (HudModel.From; M3 plan: "with deficits
+ /// borrowed, cash alone is always 0"). The sim keeps cash at 0 or above (R-MONEY-003), so a negative reading is debt,
+ /// not a negative Treasury: after four monthly turns with no orders, 0 cash and the debt read as minus the debt.</summary>
+ [Test]
+ public void TheTreasuryShowsCashMinusDebtSoBorrowingReadsNegative()
+ {
+ var bridge = NewBridge();
+ for (var i = 0; i < 4; i++) bridge.EndTurn();
+ Assert.AreEqual(0.0, bridge.State.Treasury); // R-MONEY-003: cash stops at 0
+ Assert.Greater(bridge.State.Debt, 0.0);
+ var m = HudModel.From(bridge, Text);
+ Assert.AreEqual(PlayerText.Money(C, "treasury", -bridge.State.Debt), m.Treasury.Value);
+ StringAssert.Contains("-IL", m.Treasury.Value);
+ }
+
// ---- The score (#380): only in the GDD loop, from GameState.Score ----
/// <summary>The real game: the GDD loop since the cutover (the ?mvp=1 slice is gone with MvpSlice).</summary>