A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: GDD Phase 7 PR 2 first slice, event grants of units and city capacity and job slots (D-H2, refs #806) (#959)
Berif5fa19eb46f7
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 587674546..25581c999 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]### Added+- Event options in the GDD loop can grant units and change a city's housing capacity or job slots: `grant_units`+ adds free units at the military camp or a named city, `city_effects` moves one field by whole units, both+ apply after the numeric effects and show in the option's effect list, the loader refuses an unknown target, and a+ sensitive event may carry no grant or gain (R-EFX-003 to R-EFX-006; refs #806). No event uses them yet.- The 1948 unit roster gives 20 formations a sourced Hebrew name (`name_he`, agent-checked until #564's read); aname's source does not count toward `wikipedia_only` (refs #902).- Pioneers can build a training camp: `PioneerWork(unit, build_camp, site)` at a camp site takes 6 turns and IL 2mdiff --git a/content/schema/event.schema.json b/content/schema/event.schema.jsonindex df6a4b25a..840f01922 100644--- a/content/schema/event.schema.json+++ b/content/schema/event.schema.json@@ -66,7 +66,35 @@}},"set_rung": { "type": "integer" },- "set_policy": { "type": "object", "additionalProperties": { "type": "number", "minimum": 0, "maximum": 1 }, "description": "Policy id to a level in [0, 1]." }+ "set_policy": { "type": "object", "additionalProperties": { "type": "number", "minimum": 0, "maximum": 1 }, "description": "Policy id to a level in [0, 1]." },+ "grant_units": {+ "type": "array",+ "description": "R-EFX-003 (GDD loop only): free units of a unit_types.yaml type of kind unit, at a cities.yaml id, or with no at at the city that has the military camp (a site is refused until sites carry a date, R-EFX-006). Not on a sensitive event (R-EFX-005).",+ "items": {+ "type": "object",+ "additionalProperties": false,+ "required": ["type", "n"],+ "properties": {+ "type": { "type": "string", "minLength": 1 },+ "n": { "type": "integer", "minimum": 1 },+ "at": { "type": "string" }+ }+ }+ },+ "city_effects": {+ "type": "array",+ "description": "R-EFX-004 (GDD loop only): a whole-unit change to one city's housing_capacity or job_slots. A sensitive event may only cut (R-EFX-005).",+ "items": {+ "type": "object",+ "additionalProperties": false,+ "required": ["city", "field", "delta"],+ "properties": {+ "city": { "type": "string", "minLength": 1 },+ "field": { "enum": ["housing_capacity", "job_slots"] },+ "delta": { "type": "integer", "not": { "const": 0 } }+ }+ }+ }}}},diff --git a/docs/WRITING_EVENTS.md b/docs/WRITING_EVENTS.mdindex f9cfae9fa..566356557 100644--- a/docs/WRITING_EVENTS.md+++ b/docs/WRITING_EVENTS.md@@ -134,6 +134,8 @@ Each option has:| `effects` | no | A list of `{ target, delta }`. || `set_rung` | no | Sets the security rung, 1 to 5. || `set_policy` | no | A map of policy id to a level from 0 to 1. |+| `grant_units` | no | GDD loop only. A list of `{ type, n, at }`: see "grant_units and city_effects". |+| `city_effects` | no | GDD loop only. A list of `{ city, field, delta }`: see "grant_units and city_effects". |An event needs at least one option. `historical` is a statement of fact and needs a source; `recommended` is a gamedesign choice and does not.@@ -154,6 +156,21 @@ design choice and does not.`delta` must be a finite number. Any other target is an error. Policy ids (`rationing`, ...) are not effect targets;use `set_policy` for those.+### grant_units and city_effects++These act on the GDD records, so only content whose `eras.yaml` sets `systems.loop: gdd` may use them. They apply after+`effects`, grants first, each list in its own order (R-EFX-006).++- `grant_units: [{ type: halutz, n: 2, at: tel_aviv }]` adds `n` units of a `unit_types.yaml` type of kind `unit`. A+ grant is free: put what the deal cost in `effects`. Leave out `at` and the units stand at the city with the military+ camp; set it to a `cities.yaml` id to place them there (R-EFX-003). A `sites.yaml` id is refused until sites carry a+ date, because a target must exist on the event's date (R-EFX-006).+- `city_effects: [{ city: haifa, field: housing_capacity, delta: 5 }]` changes one city's `housing_capacity` or+ `job_slots` by a whole, non-zero number. Capacity never drops below 0 and job slots never below the city's employed+ (R-EFX-004).++An event with a sensitive tag may carry no grant and no positive `city_effects` delta; a cut is allowed (R-EFX-005).+### sources```yaml@@ -219,6 +236,16 @@ Errors are printed as `file: field: message`. These are the messages you are mos| `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. |+| `needs the GDD loop` | `grant_units` or `city_effects` in content that runs the legacy loop. |+| `unknown unit type` | A grant's `type` is not in `unit_types.yaml`. |+| `is not a unit type` | A grant's `type` is a population type. |+| `must be at least 1` | A grant's `n` is 0 or negative. |+| `sites cannot be grant targets` | A grant's `at` names a site. |+| `no single city has the military camp` | A grant leaves out `at` when no single city has the camp. |+| `unknown city` | A grant's `at` or a `city_effects` entry names no city. |+| `unknown field` | A `city_effects` field other than `housing_capacity` or `job_slots`. |+| `must not be 0` | A `city_effects` delta of 0. |+| `sensitive events cannot reward units` | A sensitive-tagged event with a grant. A positive `city_effects` delta gives the same message with the field's name. || `unknown objective` | `objective` names an objective that is not in `objectives.yaml`. || `has another card` | `objective` names an objective whose `card` is a different event. || `an objective's card has exactly one option` | An objective's card has more than one option. |diff --git a/docs/gdd/ministers-events-end.md b/docs/gdd/ministers-events-end.mdindex 86f26fd00..49102e51d 100644--- a/docs/gdd/ministers-events-end.md+++ b/docs/gdd/ministers-events-end.md@@ -7,11 +7,12 @@ As a player of the MVP, I want the game to run its events and my chosen minister## Rules- The MVP runs 44 turns (monthly), from 15 May 1948 to 15 January 1952: D-B1 fixes the start and the monthly grid [S2], and the owner ended the MVP on 15 January 1952, keeping the 15th grid with no adjusted turn (D-E5, decided 15 October 2026 [S2]). The GDD text still says "approximately 48 turns" [S1]; the owner settled 44 turns [S2].-- Objective cards and scoring belong to the first phase (#379, `objectives-and-score.md`; D-B2, D-B6 [S2]) and are not restated here. This section covers only what the final phase adds: every card complete, the end screen (D-H4, open), defeat (D-B5, decided 15 October 2026 [S2]), the events (D-H1, decided 17 October 2026 [S5]; D-H2, open) and the ministers (D-H3, open) [S2].+- Objective cards and scoring belong to the first phase (#379, `objectives-and-score.md`; D-B2, D-B6 [S2]) and are not restated here. This section covers only what the final phase adds: every card complete, the end screen (D-H4, open), defeat (D-B5, decided 15 October 2026 [S2]), the events (D-H1 and D-H2, decided 17 October 2026 [S5]) and the ministers (D-H3, open) [S2].- Defeat: not all objectives are required to finish. The game is lost when Money and Food are exhausted for several turns in a row or on a war loss, and coalition collapse is off in the MVP (D-B5, decided 15 October 2026 [S2]). The defeat is built in this phase, with the counter set then (`Q-GOV-2`, decided 15 October 2026 [S4]). A war loss is enemy units holding the hex of one of the player's cities at turn end (`Q-WAR-5`, decided 15 October 2026 [S4]); what "Money exhausted" means now that borrowing is allowed stays open.- The war-survival objective completes on the last armistice event, the Syria-Israel agreement of 20 July 1949 (D-B2 [S2]; [S3]). The four signings were Egypt on 24 February 1949, Lebanon on 23 March 1949, Jordan on 3 April 1949 and Syria on 20 July 1949 [S3].- The existing cabinet and Attention stay (D-C5 [S2]). Minister roles, candidates and effects are D-H3, open [S2].- Events (D-H1): the owner took the recommendations for `Q-EVT-1` to `Q-EVT-4` on 17 October 2026 [S5]. Windows, hard anchors and a cap of three soft events a turn stay; an unanswered event is delegated to its office's holder; no effect is delayed; the card shows every effect of every option from the sim (`R-EVT-001` to `R-EVT-005`, `docs/rules/mvp.md`). An early armistice's place ahead of the other soft events comes with `front_quiet`, in the war-objective PR of the military phase (#752).+- Event effects (D-H2): the owner took the recommendations for `Q-HFX-1` to `Q-HFX-3` on 17 October 2026 [S5]. An option can grant units, free, at the military camp or a named city (a site once sites carry a date), and change a city's housing capacity or job slots; a sensitive option gains nothing from them; each is checked at load (`R-EFX-003` to `R-EFX-006`, `docs/rules/mvp.md`). Housing condition and project unlock come with the records they act on (#734, #735).## Data touched@@ -27,7 +28,7 @@ As a player of the MVP, I want the game to run its events and my chosen minister## Out of scope-- Event effect targets (D-H2) and minister roles and effects (D-H3): open.+- Minister roles and effects (D-H3): open.- The objectives panel UI and the score's presentation in Phase 1.- The exact completion conditions of each objective (GDD "MVP completion rules" [S1]): open.- Objective 1's bonus for capturing enemy soldiers lands at the prisoners' return (the plan, section 4.3 [S2]): Phase 5/6.diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex 527b56ecc..a722510a9 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -144,6 +144,16 @@ R-EFX-001: An option's effect may target an indicator id from `model.yaml`, `treR-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).+D-H2 in the GDD loop (GDD Phase 7 PR 2, #806). The owner took the plan's recommendations for Q-HFX-1 to Q-HFX-3 on 17 October 2026 (#784): grants of units, a city's housing capacity, condition and job slots, and project unlock, each validated at load; a grant is free and stands at the military camp or at the site the event names (in this slice, a city the event names: a site waits until sites carry a date, R-EFX-006); the no-reward rule covers them. This first slice builds unit grants and the housing capacity and job slots; condition and project unlock come with the records they act on (#734, #735).++R-EFX-003: An option's `grant_units` entry `{ type, n, at }` adds `n` (at least 1) units of a `unit_types.yaml` type of kind `unit`, free, taking the next ids in turn. They stand at the settlement hex of the city `at` names or, with no `at`, at the settlement hex of the one city whose `facilities` include `military_camp` (Q-HFX-2). With no such single city, `at` is required. A site is not yet a target (R-EFX-006).++R-EFX-004: An option's `city_effects` entry `{ city, field, delta }` changes only that city's `housing_capacity` or `job_slots`, by a whole, non-zero `delta`. Housing capacity never drops below 0, and job slots never drop below the city's employed, so a larger cut applies only to what is free. Capacity may fall below the city's civilians, as overcrowding already can. The cause carries the change that applied.++R-EFX-005: An option of an event tagged `holocaust`, `terror`, `massacre` or `war-casualties` carries no unit grant and no `city_effects` gain (Q-HFX-3; extends R-EFX-002). A cut stays allowed.++R-EFX-006: The structured effects apply after the numeric effects, grants first and then city effects, each in the option's list order. A target that does not exist on the date (an unbuilt site, a city not yet in the game) is refused at load with file and field, never skipped at run time; so is an unknown type, city or field. Every `cities.yaml` city is in the game from the first turn. A site has no window and starts unbuilt, so a site id as `at` is refused until sites carry a date. The legacy loop, which has no cities or units, refuses them. The preview (R-EVT-005) lists them in the same order.+## EventsD-H1 in the GDD loop (GDD Phase 7 PR 1, #805). The owner took the plan's recommendations for Q-EVT-1 to Q-EVT-4 on 17 October 2026 (#784). As the plan's Decided rows record them (`docs/superpowers/plans/2026-10-15-gdd-phase-7.md`), that keeps windows, hard anchors and the cap of 3 soft events a turn, keeps delegation, adds no delayed effects in the MVP, and shows every effect of every option from the sim's preview. These rules state what the code already does; no behaviour changed.@@ -156,4 +166,4 @@ R-EVT-003: An event the player leaves unanswered at End Turn is delegated to itsR-EVT-004: An option's effects apply when it is chosen or delegated, on that turn, and never later; an option has no delayed form, and the loader refuses an unknown key such as `delay` (Q-EVT-3).-R-EVT-005: One sim helper, `EventSystem.OptionEffects`, lists every effect of an option in the order choosing it applies them: the numeric effects, the policies it sets (by id), then the security level, each with the option's own amount (Q-EVT-4). The event card will show this list (GDD Phase 7 PR 8), so no number will be computed in Unity.+R-EVT-005: One sim helper, `EventSystem.OptionEffects`, lists every effect of an option in the order choosing it applies them: the numeric effects, the unit grants and city effects (R-EFX-006), the policies it sets (by id), then the security level, each with the option's own amount (Q-EVT-4). The event card will show this list (GDD Phase 7 PR 8), so no number will be computed in Unity.diff --git a/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs b/sim/Statecraft.Sim.Tests/StructuredEffectTests.csnew file mode 100644index 000000000..4b29de30c--- /dev/null+++ b/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs@@ -0,0 +1,231 @@+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++/// <summary>Event effects on units and cities (D-H2; GDD Phase 7 PR 2, #806). The owner took the plan's recommendations for+/// Q-HFX-1 to Q-HFX-3 on 17 October 2026 (#784): grants of units, city housing capacity, condition and job slots, and+/// project unlock, each validated at load; a grant is free and stands at the military camp or at the site the event+/// names (here a city it names); a sensitive option gains nothing from them (R-EFX-005). This first slice builds the kinds whose records are on+/// main: unit grants and a city's housing capacity and job slots. Condition (#734), project unlock (#735) and site targets+/// (once a site carries a date, R-EFX-006) follow.</summary>+public class StructuredEffectTests+{+ const string Arms = @"+id: arms+title: Arms arrive+text: A shipment arrives.+from: 1948-05-15+{TAGS}options:+ - id: accept+ text: Accept+ historical: true+ effects:+ - target: fx_reserves+ delta: -10+{STRUCTURED} - id: refuse+ text: Refuse+";++ const string Grants = @" grant_units:+ - { type: halutz, n: 2 }+ - { type: halutz, n: 1, at: town_b }+ city_effects:+ - { city: town_a, field: housing_capacity, delta: 3 }+ - { city: town_a, field: job_slots, delta: -100 }+";++ static string Event(string structured, string tags = "") =>+ Arms.Replace("{STRUCTURED}", structured).Replace("{TAGS}", tags == "" ? "" : "tags: [" + tags + "]\n");++ // A second town on its own hex, so a grant's `at` lands somewhere other than the camp city. Fixture values, not history.+ static Content Load(string ev, string facilities = "[military_camp, hakhshara]") =>+ ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>+ {+ ["map/settlement_hexes.yaml"] = "settlements:\n - { id: town_a, q: 1, r: 0 }\n - { id: town_b, q: 2, r: 1 }\n",+ ["map/settlements_1948.yaml"] = Fixture.Files["map/settlements_1948.yaml"]+ + " - { id: town_b, name: Town B, lon: 34.42, lat: 33.28, type: town, founded: 1900, pre_modern: false }\n",+ ["cities.yaml"] = "cities:\n" + Fixture.City("town_a", 12, 8, 10, 6, facilities) + Fixture.City("town_b", 5, 2, 2, 1),+ }), new Dictionary<string, string> { ["arms.yaml"] = ev }));++ static ContentException Refused(string structured, string tags = "") =>+ Assert.Throws<ContentException>(() => Load(Event(structured, tags)));++ static (int Q, int R) TownHex(Content c) { var h = c.SettlementHexes.First(x => x.Id == "town_a"); return (h.Q, h.R); }++ // R-EFX-003: a grant adds exactly its units, free, taking the next ids in turn: with no `at` they stand at the city with+ // the military camp, with `at` at the named city. Nothing else of the units changes.+ [Fact]+ public void AGrantAddsExactlyItsUnits()+ {+ var c = Load(Event(Grants));+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ Assert.Equal(new[] { "arms" }, s.PendingEvents);+ var before = s.Clone();+ var why = new List<Cause>();+ Assert.Null(EventSystem.Choose(c, s, "arms", "accept", why));++ var added = s.Units.Values.Where(u => !before.Units.ContainsKey(u.Id)).OrderBy(u => u.Id).ToList();+ Assert.Equal(new[] { before.NextId, before.NextId + 1, before.NextId + 2 }, added.Select(u => u.Id));+ Assert.Equal(before.NextId + 3, s.NextId);+ Assert.All(added, u => { Assert.Equal("halutz", u.Type); Assert.Equal(0, u.Service); });+ var town = TownHex(c);+ Assert.Equal(new[] { town, town, (2, 1) }, added.Select(u => (u.Q, u.R)));+ foreach (var u in before.Units.Values) Assert.Equal(u.Canonical(), s.Units[u.Id].Canonical());+ // Free (Q-HFX-2): the only Money that moves is the option's own numeric effect.+ Assert.Equal(before.Treasury, s.Treasury);+ Assert.Equal(before.FxReserves - 10, s.FxReserves);+ }++ // R-EFX-004: a city effect changes only the field it names. Housing capacity never drops below 0; job slots never drop+ // below the city's employed, so a cut larger than that applies only to the free slots, and the cause carries what applied.+ [Fact]+ public void ACityEffectChangesOnlyItsField()+ {+ var c = Load(Event(Grants));+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ var x = s.Cities["town_a"];+ var why = new List<Cause>();+ Assert.Null(EventSystem.Choose(c, s, "arms", "accept", why));+ var y = s.Cities["town_a"];+ Assert.Equal(x.HousingCapacity + 3, y.HousingCapacity);+ Assert.Equal(x.Employed, y.JobSlots);+ Assert.Equal((x.Civilians, x.Employed, x.Refugees, x.Recruits), (y.Civilians, y.Employed, y.Refugees, y.Recruits));+ Assert.Contains(why, w => w.System == "events" && w.Target == "town_a.housing_capacity" && w.Delta == 3);+ Assert.Contains(why, w => w.System == "events" && w.Target == "town_a.job_slots" && w.Delta == x.Employed - x.JobSlots);+ }++ // R-EFX-006: the structured effects apply after the numeric ones, in the option's list order (grants, then city effects).+ [Fact]+ public void TheyApplyAfterTheNumericEffectsInListOrder()+ {+ var c = Load(Event(Grants));+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ var why = new List<Cause>();+ Assert.Null(EventSystem.Choose(c, s, "arms", "accept", why));+ Assert.Equal(new[] { "fx_reserves", "halutz", "halutz", "town_a.housing_capacity", "town_a.job_slots" },+ why.Where(w => w.System == "events" && w.Target != "arms").Select(w => w.Target));+ }++ // R-EFX-006: a target that does not exist on the event's date is refused at load, naming file and field, never skipped+ // at run time. A site has no window yet and starts unbuilt, so a site target is refused until sites carry a date.+ [Theory]+ [InlineData(" grant_units:\n - { type: tank, n: 1 }\n", "grant_units[0].type", "unknown unit type")]+ [InlineData(" grant_units:\n - { type: recruit, n: 1 }\n", "grant_units[0].type", "not a unit")]+ [InlineData(" grant_units:\n - { type: halutz, n: 0 }\n", "grant_units[0].n", "at least 1")]+ [InlineData(" grant_units:\n - { type: halutz, n: -2 }\n", "grant_units[0].n", "at least 1")]+ [InlineData(" grant_units:\n - { type: halutz, n: 1, at: nowhere }\n", "grant_units[0].at", "unknown city")]+ [InlineData(" grant_units:\n - { type: halutz, n: 1, at: site_a }\n", "grant_units[0].at", "sites cannot be grant targets")]+ [InlineData(" city_effects:\n - { city: nowhere, field: job_slots, delta: 1 }\n", "city_effects[0].city", "unknown city")]+ [InlineData(" city_effects:\n - { city: town_a, field: condition, delta: 1 }\n", "city_effects[0].field", "housing_capacity or job_slots")]+ [InlineData(" city_effects:\n - { city: town_a, field: job_slots, delta: 0 }\n", "city_effects[0].delta", "must not be 0")]+ public void TheLoaderRefusesAnUnknownTarget(string structured, string field, string message)+ {+ var ex = Refused(structured);+ Assert.Equal("events/arms.yaml", ex.File);+ Assert.Equal("events[arms].options[accept]." + field, ex.Field);+ Assert.Contains(message, ex.Message);+ }++ // R-EFX-003: with no `at`, the grant needs the one city that has the military camp; otherwise the option must name one.+ [Fact]+ public void AGrantWithNoPlaceNeedsTheMilitaryCamp()+ {+ var ex = Assert.Throws<ContentException>(() => Load(Event(Grants), "[hakhshara]"));+ Assert.Equal("events[arms].options[accept].grant_units[0].at", ex.Field);+ Assert.Contains("military camp", ex.Message);+ }++ // R-EFX-005: an option of a sensitive event carries no grant and no capacity or slot gain; a cut stays allowed.+ [Theory]+ [InlineData(" grant_units:\n - { type: halutz, n: 1 }\n", "grant_units[0]")]+ [InlineData(" city_effects:\n - { city: town_a, field: housing_capacity, delta: 1 }\n", "city_effects[0]")]+ [InlineData(" city_effects:\n - { city: town_a, field: job_slots, delta: 2 }\n", "city_effects[0]")]+ public void ASensitiveOptionGrantsNothing(string structured, string field)+ {+ var ex = Refused(structured, "war-casualties");+ Assert.Equal("events[arms].options[accept]." + field, ex.Field);+ Assert.Contains("sensitive events cannot reward", ex.Message);+ }++ // R-EFX-005: a sensitive option may still cut a city's capacity or slots.+ [Fact]+ public void ASensitiveOptionMayCut()+ {+ Assert.Single(Load(Event(" city_effects:\n - { city: town_a, field: job_slots, delta: -1 }\n", "terror")).Events);+ Assert.Single(Load(Event(" city_effects:\n - { city: town_a, field: housing_capacity, delta: -1 }\n", "war-casualties")).Events);+ }++ // R-EFX-004: housing capacity never drops below 0; the cause carries the cut that applied.+ [Fact]+ public void HousingCapacityStopsAtZero()+ {+ var c = Load(Event(" city_effects:\n - { city: town_a, field: housing_capacity, delta: -1000 }\n"));+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ var old = s.Cities["town_a"].HousingCapacity;+ var why = new List<Cause>();+ Assert.Null(EventSystem.Choose(c, s, "arms", "accept", why));+ Assert.Equal(0, s.Cities["town_a"].HousingCapacity);+ Assert.Contains(why, w => w.Target == "town_a.housing_capacity" && w.Delta == -old);+ }++ // Structured effects act on GDD records, so the legacy loop (no cities, no units) refuses them at load.+ [Fact]+ public void TheLegacyLoopRefusesThem()+ {+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string> { ["arms.yaml"] = Event(Grants) })));+ Assert.Equal("events[arms].options[accept].grant_units", ex.Field);+ Assert.Contains("GDD loop", ex.Message);+ }++ // R-EVT-003 with R-EFX-003: a delegated option applies the same structured effects as a chosen one.+ [Fact]+ public void DelegationAppliesThemToo()+ {+ var c = Load(Event(Grants).Replace("from: 1948-05-15", "anchor: hard\nfrom: 1948-05-15"));+ var chosen = Simulation.NewGame(c, 1, Mode.Historical);+ var baseline = chosen.Clone();+ var delegated = chosen.Clone();+ Assert.Null(EventSystem.Choose(c, chosen, "arms", "accept", new List<Cause>()));+ EventSystem.Delegate(c, delegated, new List<Cause>()); // Historical mode: a hard anchor takes its historical option+ Assert.Equal("accept", delegated.ChosenOptions["arms"]);+ Assert.Equal(baseline.NextId + 3, delegated.NextId); // the grants applied, not merely the same nothing+ Assert.Equal(baseline.Units.Count + 3, delegated.Units.Count);+ Assert.Equal(chosen.Hash(), delegated.Hash());+ }++ // R-EVT-005: the preview lists the structured effects after the numeric ones, in words, in the order they apply.+ [Fact]+ public void ThePreviewListsThem()+ {+ var c = Load(Event(Grants));+ var s = Simulation.NewGame(c, 1, Mode.Historical);+ var lines = EventSystem.OptionEffects(c, s, c.Events.Single().Options[0]);+ Assert.Equal(new[] { "fx_reserves", "halutz", "halutz", "town_a.housing_capacity", "town_a.job_slots" }, lines.Select(l => l.Target));+ Assert.Equal(new[] { -10.0, 2, 1, 3, -100 }, lines.Select(l => l.Delta));+ Assert.Equal("2 halutz units at Town A", lines[1].Message);+ Assert.Equal("1 halutz unit at Town B", lines[2].Message);+ Assert.Equal("Town A: housing capacity +3", lines[3].Message);+ Assert.Equal("Town A: job slots -100", lines[4].Message);+ }++ // A game with a granted unit replays from its save to the same hash.+ [Fact]+ public void ASaveWithAGrantedUnitReplays()+ {+ var c = Load(Event(Grants));+ var g = GameSession.New(c, 7, Mode.Historical);+ g.Step(new Command[] { new ChooseEventOption("arms", "accept") });+ g.Step(new Command[0]);+ Assert.Contains(g.State.Units.Values, u => u.Q == 2 && u.R == 1);+ var loaded = GameSession.Load(c, g.Save.Write(), out var warnings);+ Assert.Empty(warnings);+ // Field by field first, so a persistence bug says what broke; then the hash.+ Assert.Equal(g.State.Units.Values.OrderBy(u => u.Id).Select(u => (u.Id, u.Type, u.Q, u.R)),+ loaded.State.Units.Values.OrderBy(u => u.Id).Select(u => (u.Id, u.Type, u.Q, u.R)));+ Assert.Equal(g.State.NextId, loaded.State.NextId);+ Assert.Equal((g.State.Cities["town_a"].HousingCapacity, g.State.Cities["town_a"].JobSlots),+ (loaded.State.Cities["town_a"].HousingCapacity, loaded.State.Cities["town_a"].JobSlots));+ Assert.Equal(g.State.Hash(), loaded.State.Hash());+ }+}diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.csindex 03561a9d6..4b5fae20b 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -700,6 +700,28 @@ namespace Statecraft.Simpublic int? SetRung { get; set; }/// <summary>Policies this option sets, by id, to a level in [0, 1].</summary>public Dictionary<string, double> SetPolicy { get; set; } = new Dictionary<string, double>();+ /// <summary>R-EFX-003: units this option grants, free, in list order (D-H2, Q-HFX-2).</summary>+ public List<UnitGrant> GrantUnits { get; set; } = new List<UnitGrant>();+ /// <summary>R-EFX-004: changes to a city's housing capacity or job slots, in list order (D-H2, Q-HFX-1).</summary>+ public List<CityEffect> CityEffects { get; set; } = new List<CityEffect>();+ }++ /// <summary>An option's grant of <see cref="N"/> units of a unit_types.yaml type of kind unit (R-EFX-003). They stand at+ /// <see cref="At"/>, a cities.yaml id, or, when it is empty, at the city that has the military camp. A site is refused+ /// until sites carry a date (R-EFX-006).</summary>+ public sealed class UnitGrant+ {+ public string Type { get; set; } = "";+ public int N { get; set; }+ public string At { get; set; } = "";+ }++ /// <summary>An option's change to one field of a city: housing_capacity or job_slots, by whole units (R-EFX-004).</summary>+ public sealed class CityEffect+ {+ public string City { get; set; } = "";+ public string Field { get; set; } = "";+ public int Delta { get; set; }}public sealed class GameEventdiff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex 4d6c8e21a..502f42357 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -332,7 +332,8 @@ namespace Statecraft.Sim// requires: { event, option } fires only once that other event was resolved (chosen or delegated)// with that option; both ids must exist, an event cannot require itself and// requirements cannot form a cycle (EventRules)- // options: [{ id, text, historical, recommended, effects: [{ target, delta }], set_rung, set_policy }]+ // options: [{ id, text, historical, recommended, effects: [{ target, delta }], set_rung, set_policy,+ // grant_units: [{ type, n, at }], city_effects: [{ city, field, delta }] }]// sources: [{ url, checked }], status// objective the objective (objectives.yaml) whose completion card this is: it fires only once// that objective is recorded, and has exactly one option@@ -356,6 +357,7 @@ namespace Statecraft.Simc.Sites = Read<SitesFile>(readFile, "sites.yaml").Sites; // sourced facts (Phase 1 PR 5)ValidateGdd(c, settlementIds);}+ EventRules.ValidateStructured(c); // R-EFX-006: after the GDD records it names are readc.BuildWindows();c.Hash = HashOf(read);return c;diff --git a/sim/Statecraft.Sim/EventRules.cs b/sim/Statecraft.Sim/EventRules.csindex f53b9931e..ce11e594d 100644--- a/sim/Statecraft.Sim/EventRules.cs+++ b/sim/Statecraft.Sim/EventRules.cs@@ -98,6 +98,52 @@ namespace Statecraft.SimCheckObjectives(c);}+ /// <summary>The options' structured effects (D-H2): R-EFX-006 refuses a target that does not exist at load, so Resolve+ /// never skips one; R-EFX-005 refuses any gain from them on a sensitive event, as R-EFX-002 does for the resources.+ /// Called once the GDD files (cities, unit types, sites) are read, so after <see cref="Validate"/>.</summary>+ public static void ValidateStructured(Content c)+ {+ foreach (var e in c.Events)+ foreach (var o in e.Options)+ CheckStructured(c, e, o, e.Tags.Any(SensitiveTags.Contains), field => $"events[{e.Id}].{field}");+ }++ static void CheckStructured(Content c, GameEvent e, EventOption o, bool sensitive, Func<string, string> F)+ {+ if (o.GrantUnits.Count + o.CityEffects.Count == 0) return;+ // They act on the GDD records (cities.yaml, unit_types.yaml, sites.yaml), which the legacy loop does not load.+ if (!c.IsGdd)+ throw new ContentException(e.File, F($"options[{o.Id}].{(o.GrantUnits.Count > 0 ? "grant_units" : "city_effects")}"), "needs the GDD loop (eras.yaml systems.loop: gdd)");+ for (int i = 0; i < o.GrantUnits.Count; i++)+ {+ var g = o.GrantUnits[i];+ string G(string field) => F(FormattableString.Invariant($"options[{o.Id}].grant_units[{i}]{field}"));+ if (sensitive) throw new ContentException(e.File, G(""), "sensitive events cannot reward units");+ var type = c.UnitTypes.FirstOrDefault(t => t.Id == g.Type)+ ?? throw new ContentException(e.File, G(".type"), $"unknown unit type '{g.Type}'");+ if (type.Kind != "unit") throw new ContentException(e.File, G(".type"), $"'{g.Type}' is not a unit type (kind {type.Kind})");+ if (g.N < 1) throw new ContentException(e.File, G(".n"), "must be at least 1");+ if (g.At == "" && c.Cities.Count(x => x.Facilities.Contains(EventSystem.MilitaryCamp)) != 1)+ throw new ContentException(e.File, G(".at"), "required: no single city has the military camp, so name a city");+ // R-EFX-006: a target must exist on the event's date. Every cities.yaml city is in the game from the first+ // turn; a site has no window and starts unbuilt, so it cannot be checked against a date yet.+ if (g.At != "" && c.Cities.All(x => x.Id != g.At))+ throw new ContentException(e.File, G(".at"), c.Sites.Any(x => x.Id == g.At)+ ? $"'{g.At}' is a site: sites cannot be grant targets until they carry a date (R-EFX-006)"+ : $"unknown city '{g.At}'");+ }+ for (int i = 0; i < o.CityEffects.Count; i++)+ {+ var x = o.CityEffects[i];+ string X(string field) => F(FormattableString.Invariant($"options[{o.Id}].city_effects[{i}]{field}"));+ if (c.Cities.All(k => k.Id != x.City)) throw new ContentException(e.File, X(".city"), $"unknown city '{x.City}'");+ if (x.Field != EventSystem.HousingField && x.Field != EventSystem.JobsField)+ throw new ContentException(e.File, X(".field"), $"unknown field '{x.Field}' (housing_capacity or job_slots)");+ if (x.Delta == 0) throw new ContentException(e.File, X(".delta"), "must not be 0");+ if (sensitive && x.Delta > 0) throw new ContentException(e.File, X(""), $"sensitive events cannot reward {x.Field}");+ }+ }+/// <summary>Objectives and their cards name each other (R-OBJ-003): an event's `objective` names an objective whose/// `card` is that event, and an objective's card exists, names it back and has exactly one option (the card reports a/// result; there is nothing to choose).</summary>diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.csindex 642262553..5e74ac21d 100644--- a/sim/Statecraft.Sim/EventSystem.cs+++ b/sim/Statecraft.Sim/EventSystem.cs@@ -7,6 +7,8 @@ namespace Statecraft.Simpublic static class EventSystem{public const int MaxSoftEventsPerTurn = 3;+ /// <summary>The facility a grant with no `at` stands at (Q-HFX-2) and the city fields an option may change (R-EFX-004).</summary>+ public const string MilitaryCamp = "military_camp", HousingField = "housing_capacity", JobsField = "job_slots";static GameEvent Get(Content c, string id) => c.Events.First(e => e.Id == id);@@ -88,6 +90,25 @@ namespace Statecraft.Simelse change = EffectsSystem.Shift(c, s, fx.Target, fx.Delta);why.Add(new Cause("events", fx.Target, change, $"{PlayerText.Change(c, fx.Target, change)} ({title})"));}+ // R-EFX-006: the structured effects after the numeric ones, in list order. The loader has checked every target.+ foreach (var g in o.GrantUnits)+ {+ // R-EFX-003 (Q-HFX-2): free; the deal's cost is the option's numeric effects. The units take the next ids.+ var (place, q, r) = GrantPlace(c, g);+ for (int i = 0; i < g.N; i++) { var id = s.NextId++; s.Units.Add(id, new Unit(id, g.Type, q, r)); }+ why.Add(new Cause("events", g.Type, g.N, $"{Granted(g, place)} ({title})"));+ }+ foreach (var x in o.CityEffects)+ {+ // R-EFX-004: only the named field changes. Housing capacity stays at 0 or more; job slots never fall below the+ // city's employed, so a cut takes only free slots. The cause carries the change that applied.+ var city = s.Cities[x.City];+ var housing = x.Field == HousingField ? Math.Max(0, city.HousingCapacity + x.Delta) : city.HousingCapacity;+ var jobs = x.Field == JobsField ? Math.Max(city.Employed, city.JobSlots + x.Delta) : city.JobSlots;+ s.Cities[x.City] = new City(city.Id, housing, jobs, city.Civilians, city.Employed, city.Refugees, city.Recruits);+ var applied = housing - city.HousingCapacity + jobs - city.JobSlots;+ why.Add(new Cause("events", x.City + "." + x.Field, applied, $"{CityChange(c, x.City, x.Field, applied)} ({title})"));+ }foreach (var kv in o.SetPolicy.Where(k => s.Policies.ContainsKey(k.Key)).OrderBy(k => k.Key, StringComparer.Ordinal)){s.Policies[kv.Key] = kv.Value;@@ -100,14 +121,31 @@ namespace Statecraft.Sim/// effect on a target that no longer exists reaches nothing.</summary>static bool Reaches(GameState s, string target) => EventRules.SpecialTargets.Contains(target) || s.Indicators.ContainsKey(target);+ /// <summary>Where a grant stands (R-EFX-003, Q-HFX-2): the named city's settlement hex, or with no `at` the settlement+ /// hex of the one city with the military camp (the loader checks each exists).</summary>+ static (string Name, int Q, int R) GrantPlace(Content c, UnitGrant g)+ {+ var city = g.At != "" ? g.At : c.Cities.Single(x => x.Facilities.Contains(MilitaryCamp)).Id;+ var hex = c.SettlementHexes.First(h => h.Id == city); // every settlement has one (ValidateMap)+ return (PlayerText.Settlement(c, city), hex.Q, hex.R);+ }++ static string Granted(UnitGrant g, string place) =>+ FormattableString.Invariant($"{g.N} {g.Type} unit{(g.N == 1 ? "" : "s")} at {place}");++ static string CityChange(Content c, string city, string field, int delta) =>+ FormattableString.Invariant($"{PlayerText.Settlement(c, city)}: {field.Replace('_', ' ')} {(delta > 0 ? "+" : "")}{delta}");+/// <summary>R-EVT-005: every effect of an option, in the order choosing it applies them (Resolve): the numeric- /// effects, the policies it sets (by id), then the security level. Each amount is the option's own; Resolve may- /// apply less where an indicator meets its bound or the Food stock its floor, and rounds Food to whole units. The+ /// effects, the unit grants and city effects (R-EFX-006), the policies it sets (by id), then the security level.+ /// Each amount is the option's own; Resolve may apply less where an indicator meets its bound or the Food stock its floor, and rounds Food to whole units. The/// event card will read this list (Q-EVT-4, owner 17 October 2026; Phase 7 PR 8), so no number is computed in Unity.</summary>public static List<Cause> OptionEffects(Content c, GameState s, EventOption o){var lines = o.Effects.Where(fx => Reaches(s, fx.Target)).Select(fx => new Cause("events", fx.Target, fx.Delta, PlayerText.Change(c, fx.Target, fx.Delta))).ToList();+ lines.AddRange(o.GrantUnits.Select(g => new Cause("events", g.Type, g.N, Granted(g, GrantPlace(c, g).Name))));+ lines.AddRange(o.CityEffects.Select(x => new Cause("events", x.City + "." + x.Field, x.Delta, CityChange(c, x.City, x.Field, x.Delta))));lines.AddRange(o.SetPolicy.Where(k => s.Policies.ContainsKey(k.Key)).OrderBy(k => k.Key, StringComparer.Ordinal).Select(k => new Cause("events", k.Key, k.Value, $"{PlayerText.Target(c, k.Key)} set to {PlayerText.Percent(k.Value)}")));if (o.SetRung.HasValue) lines.Add(new Cause("events", "rung", o.SetRung.Value, FormattableString.Invariant($"Security level set to {o.SetRung.Value}")));