A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Events: food is an effect target (R-EFX-001/002) (#888)
agamrafaeli-instinct57949215e98b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 89aae648d..96fb4378f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,11 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB## [Unreleased]+### Added+- Event options can now move the national Food stock: `food` is an effect target in whole units, the loader+ validates it, and the sensitive-event no-gain rule covers it (R-EFX-001 and R-EFX-002; refs #729). The Arms+ target follows with its pool (#781).+### Fixed- The content loader now checks `name_he_review` on people rows the way it does for parties, governments,legislatures, offices and settlements: the flag is `agent-checked` or left out, and only beside a `name_he`diff --git a/content/schema/event.schema.json b/content/schema/event.schema.jsonindex d0b28790e..df6a4b25a 100644--- a/content/schema/event.schema.json+++ b/content/schema/event.schema.json@@ -60,7 +60,7 @@"additionalProperties": false,"required": ["target", "delta"],"properties": {- "target": { "type": "string", "minLength": 1 },+ "target": { "type": "string", "minLength": 1, "description": "An indicator id from model.yaml, or a special target: treasury or fx_reserves (game money), food (the national Food stock, whole units; the Arms target arrives with its pool, #781)." },"delta": { "type": "number" }}}diff --git a/docs/WRITING_EVENTS.md b/docs/WRITING_EVENTS.mdindex 1d4c8832f..f9cfae9fa 100644--- a/docs/WRITING_EVENTS.md+++ b/docs/WRITING_EVENTS.md@@ -75,7 +75,7 @@ Write plain description. Do not put words in anyone's mouth: no invented quotesTags are free-form, but these four are sensitive (checked without regard to case): `holocaust`, `terror`, `massacre`,`war-casualties`. An event with any of them:-- cannot give a positive delta to any resource in any option: `treasury`, `fx_reserves`, `food_supply`, `morale`+- cannot give a positive delta to any resource in any option: `treasury`, `fx_reserves`, `food`, `food_supply`, `morale`(standing for Social cohesion) or `intl_standing` (standing for International Support). The loader refuses: it wouldreward the atrocity. Owner decision of 15 October 2026 (Q-EFX-2, "Extend it"); until then the rule covered money only;- needs `status: sensitivity-reviewed` before any build is shared. That status is set by the maintainer, not by you.@@ -144,7 +144,12 @@ design choice and does not.- an indicator id from `content/model.yaml`: `morale`, `food_supply`, `housing`, `security`, `intl_standing`. Theselive between 0 and 1, so a delta of `0.03` is three points of the scale. Keep deltas small, as the example does;-- `treasury` or `fx_reserves`, in game money.+- `treasury` or `fx_reserves`, in game money;+- `food`, the national Food stock, in whole units (one unit is one population unit's food for a month). The delta+ rounds to whole units and the stock never drops below 0, so a larger cut than the stock takes what is there. The+ Arms stock becomes a target with its pool (#781). Note that the monthly import (R-FOOD-002) refills the stock to+ `cover_months` of the need unless the foreign-currency crisis is on, so outside a crisis a cut only matters if it+ leaves less than one month's need; a gain stays.`delta` must be a finite number. Any other target is an error. Policy ids (`rationing`, ...) are not effect targets;use `set_policy` for those.@@ -210,8 +215,8 @@ Errors are printed as `file: field: message`. These are the messages you are mos| `at least one option required` | `options` is empty. || `at most one option can be historical` | Two options have `historical: true`. || `hard anchor needs a historical option` | `anchor: hard` and no option is `historical`. |-| `unknown target` | An effect `target` is neither an indicator nor `treasury` or `fx_reserves`. |-| `sensitive events cannot reward` | A sensitive-tagged event with a positive `treasury`, `fx_reserves`, `food_supply`, `morale` or `intl_standing` delta. |+| `unknown target` | An effect `target` is neither an indicator nor `treasury`, `fx_reserves` or `food`. |+| `sensitive events cannot reward` | A sensitive-tagged event with a positive `treasury`, `fx_reserves`, `food`, `food_supply`, `morale` or `intl_standing` delta. || `must be 1-5` | `set_rung` outside 1 to 5. || `unknown policy` | `set_policy` names a policy that does not exist. || `unknown objective` | `objective` names an objective that is not in `objectives.yaml`. |diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex 2af09baf1..8711b3286 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -129,3 +129,7 @@ R-NAT-002: "Low social cohesion" (`low_cohesion`) is a situation on `morale`: onR-NAT-003: International Support is the 0 to 1 `intl_standing` indicator, shown as International support; event effects on `intl_standing` move it (Q-NAT-4).R-NAT-004: "Low international support" (`low_intl_support`) is a situation on `intl_standing` with the same bands and, likewise, no effect of its own (Q-NAT-3).++R-EFX-001: An option's effect may target an indicator id from `model.yaml`, `treasury` or `fx_reserves` (game money), or `food`, the national Food stock: the effect moves the stock by whole units (the delta rounds half away from zero) and the stock never drops below 0, so a cut larger than the stock applies only to what is there. Any other target is a load error naming file and field. The Arms stock becomes a target with its pool (#781).++R-EFX-002: An option of an event tagged `holocaust`, `terror`, `massacre` or `war-casualties` cannot raise `treasury`, `fx_reserves`, `food`, `food_supply`, `morale` or `intl_standing` (Q-EFX-2, decided 15 October 2026: the no-gain rule covers all five resources, with the legacy indicators standing for Food, Social cohesion and International Support; `food` is Food's own target, and Arms joins the rule with its pool, #781). A cost stays allowed. The rule for the Phase 6 `displacement` tag is Q-DEP-6 (open).diff --git a/scripts/new_event.py b/scripts/new_event.pyindex fd59e31a5..061d59392 100644--- a/scripts/new_event.py+++ b/scripts/new_event.py@@ -29,6 +29,8 @@ from: @FROM@- id: todo_option # lower_snake_case, like every idtext: TODO what the player doeseffects:+ # targets: an indicator id (morale, food_supply, ...), treasury or fx_reserves (game money),+ # or food (the national Food stock, in whole units); policies go in set_policy- { target: morale, delta: 0.0 }sources: [] # each { url: "https://...", checked: YYYY-MM-DD }status: draftdiff --git a/sim/Statecraft.Sim.Tests/EventTests.cs b/sim/Statecraft.Sim.Tests/EventTests.csindex f738da5fb..e18bcd50b 100644--- a/sim/Statecraft.Sim.Tests/EventTests.cs+++ b/sim/Statecraft.Sim.Tests/EventTests.cs@@ -75,6 +75,60 @@ options:Assert.Equal("That event is not waiting for a decision", EventSystem.Choose(c, s, "shortage", "ration", why));}+ /// <summary>R-EFX-001: a `food` effect moves the stock by whole units, rounding half away from zero, and the+ /// stock stays in 0..int.MaxValue even at the range edge.</summary>+ [Theory]+ [InlineData("7", 0, 7)]+ [InlineData("2.5", 100, 103)]+ [InlineData("-2.5", 100, 97)]+ [InlineData("2147483647", 100, 2147483647)]+ public void AnOptionCanMoveTheFoodStock(string delta, int start, int expected)+ {+ var ev = Shortage.Replace("target: fx_reserves\n delta: -10", "target: food\n delta: " + delta);+ var c = Load(new Dictionary<string, string> { ["shortage.yaml"] = ev });+ var s = State(c, new DateTime(1948, 6, 1)); s.Food = start; var why = new List<Cause>();+ EventSystem.Trigger(c, s, why);+ Assert.Null(EventSystem.Choose(c, s, "shortage", "import", why));+ Assert.Equal(expected, s.Food);+ Assert.Contains(why, w => w.Target == "food" && w.Delta == expected - start);+ }++ /// <summary>R-EFX-001: beyond the int range the loader refuses the delta, naming file and field (an out-of-range+ /// double-to-int cast is not the same on every runtime, docs/determinism.md).</summary>+ [Fact]+ public void AFoodDeltaBeyondTheIntRangeIsALoadError()+ {+ var ev = Shortage.Replace("target: fx_reserves\n delta: -10", "target: food\n delta: 3000000000");+ var ex = Assert.Throws<ContentException>(() => Load(new Dictionary<string, string> { ["shortage.yaml"] = ev }));+ Assert.Equal("events/shortage.yaml", ex.File);+ Assert.Equal("events[shortage].options[import].effects.food", ex.Field);+ Assert.Contains("food delta out of range", ex.Message);+ }++ [Fact]+ public void AFoodCutStopsAtAnEmptyStock()+ {+ var ev = Shortage.Replace("target: fx_reserves\n delta: -10", "target: food\n delta: -10");+ var c = Load(new Dictionary<string, string> { ["shortage.yaml"] = ev });+ var s = State(c, new DateTime(1948, 6, 1)); s.Food = 3; var why = new List<Cause>();+ EventSystem.Trigger(c, s, why);+ Assert.Null(EventSystem.Choose(c, s, "shortage", "import", why));+ Assert.Equal(0, s.Food);+ Assert.Contains(why, w => w.Target == "food" && w.Delta == -3);+ }++ /// <summary>R-EFX-001: any target that is not an indicator, `treasury`, `fx_reserves` or `food` is a load error+ /// naming file and field. `arms` pins the boundary: the Arms stock becomes a target with its pool (#781).</summary>+ [Fact]+ public void AnUnknownTargetNamesTheField()+ {+ var ev = Shortage.Replace("target: fx_reserves", "target: arms");+ var ex = Assert.Throws<ContentException>(() => Load(new Dictionary<string, string> { ["shortage.yaml"] = ev }));+ Assert.Equal("events/shortage.yaml", ex.File);+ Assert.Equal("events[shortage].options[import].effects.arms", ex.Field);+ Assert.Contains("unknown target", ex.Message);+ }+[Fact]public void EventIndicatorEffectPersistsThroughEffectsRebuilds(){@@ -443,12 +497,14 @@ options:["model.yaml"] = Fixture.Files["model.yaml"].Replace("indicators:\n", "indicators:\n - id: intl_standing\n base: 0.5\n name: International standing\n"),}, new Dictionary<string, string> { ["shortage.yaml"] = ev }));- /// <summary>Owner decision of 15 October 2026 on Q-EFX-2, "Extend it": a sensitive option may not raise any resource. The- /// legacy indicators stand for Food (food_supply), Social cohesion (morale) and International Support (intl_standing).</summary>+ /// <summary>R-EFX-002 (owner decision of 15 October 2026 on Q-EFX-2, "Extend it"): a sensitive option may not raise any+ /// resource. The legacy indicators stand for Food (food_supply), Social cohesion (morale) and International Support+ /// (intl_standing); `food` is Food's own target.</summary>[Theory][InlineData("food_supply")][InlineData("morale")][InlineData("intl_standing")]+ [InlineData("food")]public void SensitiveEventCannotRaiseFoodCohesionOrSupport(string target){var ex = Assert.Throws<ContentException>(() => LoadWithStanding(Sensitive("war-casualties", target, "0.02")));@@ -460,6 +516,8 @@ options:[Theory][InlineData("food_supply", "0")][InlineData("morale", "-0.02")]+ [InlineData("food", "0")]+ [InlineData("food", "-5")][InlineData("intl_standing", "-0.05")]public void SensitiveEventMayCostOrNotChangeFoodCohesionOrSupport(string target, string delta){diff --git a/sim/Statecraft.Sim.Tests/PlayerTextTests.cs b/sim/Statecraft.Sim.Tests/PlayerTextTests.csindex a24ef409b..c15353a68 100644--- a/sim/Statecraft.Sim.Tests/PlayerTextTests.cs+++ b/sim/Statecraft.Sim.Tests/PlayerTextTests.cs@@ -453,4 +453,22 @@ public class PlayerTextTests[Fact]public void EveryRealPortraitHasAFocalPoint() =>Assert.All(Real.People.Where(p => p.Portrait != null && p.Portrait.File != ""), p => Assert.InRange(p.Portrait!.FocusY ?? -1, 0.05, 0.95));++ /// <summary>R-EFX-001: whole-unit national stocks read in units, not percent.</summary>+ [Theory]+ [InlineData(7, "+7 units")]+ [InlineData(-3, "-3 units")]+ [InlineData(0, "0 units")]+ public void UnitsChangeRendersAWholeUnitStock(double change, string shown)+ {+ Assert.Equal(shown, PlayerText.UnitsChange(change));+ }++ [Fact]+ public void ChangeRendersTheFoodStockInUnits()+ {+ var c = ContentLoader.Load(RealContentTests.ContentRoot());+ Assert.Equal("Food +7 units", PlayerText.Change(c, Pools.FoodTarget, 7));+ }}+diff --git a/sim/Statecraft.Sim/EventRules.cs b/sim/Statecraft.Sim/EventRules.csindex 837defa23..f53b9931e 100644--- a/sim/Statecraft.Sim/EventRules.cs+++ b/sim/Statecraft.Sim/EventRules.cs@@ -9,12 +9,13 @@ namespace Statecraft.Simstatic class EventRules{public static readonly HashSet<string> SensitiveTags = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "holocaust", "terror", "massacre", "war-casualties" };- public static readonly HashSet<string> SpecialTargets = new HashSet<string> { "treasury", "fx_reserves" };+ public static readonly HashSet<string> SpecialTargets = new HashSet<string> { "treasury", "fx_reserves", Pools.FoodTarget };/// <summary>Targets a sensitive event's options may not raise (CONTENT_POLICY section 4: no mechanic rewards violence against/// civilians). Owner decision of 15 October 2026 on Q-EFX-2, "Extend it": every resource, not money alone. Until the/// GDD resources exist as targets the legacy indicators stand for them: Money (treasury, fx_reserves), Food- /// (food_supply), Social cohesion (morale) and International Support (intl_standing). Arms has no target yet.</summary>- public static readonly HashSet<string> NoGainTargets = new HashSet<string> { "treasury", "fx_reserves", "food_supply", "morale", "intl_standing" };+ /// (food_supply), Social cohesion (morale) and International Support (intl_standing). Food also has its own target+ /// (`food`, R-EFX-001); Arms has no target yet and joins the rule with its pool (#781).</summary>+ public static readonly HashSet<string> NoGainTargets = new HashSet<string> { "treasury", "fx_reserves", Pools.FoodTarget, "food_supply", "morale", "intl_standing" };public static void Validate(Content c, HashSet<string> offices, HashSet<string> indicators){@@ -86,6 +87,8 @@ namespace Statecraft.Simthrow new ContentException(e.File, F($"options[{o.Id}].effects.{fx.Target}"), "unknown target");Active(F($"options[{o.Id}].effects.{fx.Target}"), fx.Target);ContentLoader.Finite(e.File, F($"options[{o.Id}].effects.{fx.Target}.delta"), fx.Delta);+ if (fx.Target == Pools.FoodTarget && Math.Abs(fx.Delta) > int.MaxValue)+ throw new ContentException(e.File, F($"options[{o.Id}].effects.{fx.Target}"), "food delta out of range");if (sensitive && NoGainTargets.Contains(fx.Target) && fx.Delta > 0)throw new ContentException(e.File, F($"options[{o.Id}].effects.{fx.Target}"), $"sensitive events cannot reward {fx.Target}");}diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.csindex 7ed347985..d622f383c 100644--- a/sim/Statecraft.Sim/EventSystem.cs+++ b/sim/Statecraft.Sim/EventSystem.cs@@ -75,7 +75,17 @@ namespace Statecraft.Simelse s.Treasury += fx.Delta;continue;}- if (fx.Target == "fx_reserves") s.FxReserves += fx.Delta;+ if (fx.Target == Pools.FoodTarget)+ {+ // R-EFX-001: an event moves the national Food stock by whole units (the delta rounds half away+ // from zero, and the loader bounds it to the int range). The stock stays in 0..int.MaxValue,+ // computed in long so nothing wraps, and the cause carries the change that applied.+ var want = (long)Math.Round(fx.Delta, MidpointRounding.AwayFromZero);+ var applied = Math.Max(-(long)s.Food, Math.Min(want, (long)int.MaxValue - s.Food));+ s.Food = (int)(s.Food + applied);+ change = applied;+ }+ 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, $"{PlayerText.Change(c, fx.Target, change)} ({title})"));}diff --git a/sim/Statecraft.Sim/PlayerText.cs b/sim/Statecraft.Sim/PlayerText.csindex 12da85410..c9968c117 100644--- a/sim/Statecraft.Sim/PlayerText.cs+++ b/sim/Statecraft.Sim/PlayerText.cs@@ -119,8 +119,16 @@ namespace Statecraft.Simreturn Signed(r, "", Fixed(Math.Abs(r), decimals) + "%", signed: true);}+ /// <summary>"+5 units" for a change to a whole-unit national stock (the Food pool; R-EFX-001).</summary>+ public static string UnitsChange(double change)+ {+ var r = Math.Round(Finite(change, nameof(change)), 0, MidpointRounding.AwayFromZero);+ return Signed(r, "", Fixed(Math.Abs(r), 0) + " units", signed: true);+ }+/// <summary>"Morale +4.1%" or "Treasury -IL 2.0m": the name and the change, in the target's unit.</summary>public static string Change(Content c, string id, double change) =>- Target(c, id) + " " + (IsMoney(c, id) ? MoneyChange(c, id, change) : PercentChange(change));+ (id == Pools.FoodTarget ? "Food" : Target(c, id)) + " "+ + (id == Pools.FoodTarget ? UnitsChange(change) : IsMoney(c, id) ? MoneyChange(c, id, change) : PercentChange(change));}}diff --git a/sim/Statecraft.Sim/Pools.cs b/sim/Statecraft.Sim/Pools.csindex 2a0195e23..c4d0dfe83 100644--- a/sim/Statecraft.Sim/Pools.cs+++ b/sim/Statecraft.Sim/Pools.cs@@ -14,6 +14,9 @@ namespace Statecraft.Sim/// <summary>The indicator the Food stock feeds (model.yaml; the loader requires it in the GDD loop).</summary>public const string FoodIndicator = "food_supply";+ /// <summary>The event-effect target that moves the Food stock itself (R-EFX-001).</summary>+ public const string FoodTarget = "food";+/// <summary>R-FOOD-001: the stock starts at cover_months of the start's need, so food_supply starts at its level.</summary>public static void Init(Content c, GameState s){