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 option can unlock a locked city project (R-EFX-008, Refs #806) (#1072)

Beria32347bdf95d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index adc23c3f8..3d9322e6b 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
+- An event option can unlock a city project (GDD Phase 7 PR 2, D-H2): a `projects.yaml` kind marked `locked: true` is
+ refused by StartProject until an option with `unlock_projects` naming it has applied. The loader refuses an unknown
+ kind or one that is not locked, and a sensitive option may not unlock (R-EFX-008, R-EFX-005; refs #806). No real
+ project is locked yet, so no golden moves.
- Standing orders (GDD Phase 5 PR 7): `UnitOrder(unit, fortify / hold)` gives one of the player's military units a
standing order that stays until the player changes it. Fortify is free, is set by the end of the turn it is given and
is lost when the unit leaves its hex (Q-HOLD-1); hold acts on the unit's own hex only and intercepts nothing (Q-HOLD-2).
@@ -203,6 +207,7 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
are labelled design values in `rules.yaml` `mvp:`. No minister in `people.yaml` is rated below 5 today, so the
goldens do not move (refs #107).
+
### Changed
- Hebrew vote text (`budget.no_vote`, `budget.vote_advisory`, `cabinet.legislature_advisory`) is reworded so it needs
no grammatical gender for the Knesset or the Provisional State Council, and legislatures get no gender field (owner,
diff --git a/content/schema/event.schema.json b/content/schema/event.schema.json
index ca6d990b4..1e42159e7 100644
--- a/content/schema/event.schema.json
+++ b/content/schema/event.schema.json
@@ -152,6 +152,11 @@
"else": { "properties": { "delta": { "type": "integer", "minimum": -2147483647, "maximum": 2147483647 } } }
}
},
+ "unlock_projects": {
+ "type": "array",
+ "description": "R-EFX-008 (GDD loop only): projects.yaml ids of locked kinds this option makes available to StartProject. A sensitive event may not unlock (R-EFX-005).",
+ "items": { "type": "string", "minLength": 1 }
+ },
"alternative": { "$ref": "#/definitions/alternative" }
}
}
diff --git a/docs/WRITING_EVENTS.md b/docs/WRITING_EVENTS.md
index ced3f1356..47f4d3fd0 100644
--- a/docs/WRITING_EVENTS.md
+++ b/docs/WRITING_EVENTS.md
@@ -219,6 +219,7 @@ Each option has:
| `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". |
+| `unlock_projects` | no | GDD loop only. A list of `projects.yaml` ids: see "grant_units and city_effects". |
| `alternative` | on every option that did not happen, in an event with a historical option | Who put it forward, on what record. See below. |
| `rejoin` | no | Consequence cards only. The id of the event whose road the card follows; choosing this option returns later cards to the recorded course (R-ALT-009). See "kind". |
@@ -267,7 +268,7 @@ 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).
+`effects`: grants, then city effects, then project unlocks, 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
@@ -279,7 +280,10 @@ These act on the GDD records, so only content whose `eras.yaml` sets `systems.lo
- `city_effects: [{ city: haifa, field: condition, delta: -0.1 }]` moves the city's housing condition (0 to 1,
R-HOUSE-001) by a non-zero number from -1 to 1. It stays from 0 to 1, so a cut larger than the condition stops at 0.
-An event with a sensitive tag may carry no grant and no positive `city_effects` delta; a cut is allowed (R-EFX-005).
+- `unlock_projects: [industry]` makes a `projects.yaml` kind marked `locked: true` available to StartProject for the rest
+ of the game (R-EFX-008). Naming a kind that is not locked is an error, since it would do nothing.
+
+An event with a sensitive tag may carry no grant, no positive `city_effects` delta and no unlock; a cut is allowed (R-EFX-005).
### sources
@@ -346,7 +350,7 @@ 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`, `arms`, `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. |
+| `needs the GDD loop` | `grant_units`, `city_effects` or `unlock_projects` 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. |
@@ -357,7 +361,9 @@ Errors are printed as `file: field: message`. These are the messages you are mos
| `must not be 0` | A `city_effects` delta of 0. |
| `must be a whole number` | A `housing_capacity` or `job_slots` delta with a fraction, or beyond the int range. |
| `must be a number from -1 to 1` | A `condition` delta outside -1 to 1. |
-| `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 city project` | An `unlock_projects` entry is not in `projects.yaml`. |
+| `is not locked` | An `unlock_projects` entry names a kind without `locked: true`. |
+| `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, and an unlock says `a project unlock`. |
| `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/rules/mvp.md b/docs/rules/mvp.md
index c470fb928..2bb6b0692 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -76,7 +76,7 @@ R-HOUSE-004: In the GDD loop the base of the national `housing` indicator is the
A city project is built in a city (GDD "Cities and construction"; Phase 3 PR 4, #735). The kinds are in `content/projects.yaml`, every number a design value (Q-PROJ-1, Q-PROJ-5, owner, 15 October 2026, #375: "Take all recommendations", with agent-proposed values the owner may override): permanent housing (`housing`), the transit camp (`transit_camp`, D-D3, Q-HOUSE-3) and `industry`. The legacy map actions still run beside them; refusing them in the GDD loop (R-PROJ-004) is a separate PR. Until then a map action does not check the city projects, so one can still be placed on a project's hex; R-PROJ-004 removes that path.
-R-PROJ-001: `StartProject(kind, city, q, r)` starts a city project of a `projects.yaml` kind for a city on hex (q, r). The Treasury pays the kind's cost at once and borrows what it lacks (Q-PROJ-1, Q-MONEY-3, "Allow borrowing"); the project takes the next id and the kind's turns, the turn of the order the first (D-A3). It needs no workers (Q-PROJ-3). It is refused, state and Attention unchanged, for an unknown kind or city; a transit camp without the `maabarot` policy at 0.5 or more (Q-HOUSE-3: the policy carries the camp's sourced date, and the map actions' 1 January 1950 window does not apply); a hex that is not land, is more than `map_action_max_distance` from the city's settlement hex, or holds a map-action placement or another city project, built or not (Q-PROJ-2); and once `map_actions_per_turn` projects were started this turn, counted nationally with the map actions (Q-PROJ-4). The legacy loop refuses it before charging Attention. Its Attention cost is `attention_cost.start_project` (1, Q-PROJ-5).
+R-PROJ-001: `StartProject(kind, city, q, r)` starts a city project of a `projects.yaml` kind for a city on hex (q, r). The Treasury pays the kind's cost at once and borrows what it lacks (Q-PROJ-1, Q-MONEY-3, "Allow borrowing"); the project takes the next id and the kind's turns, the turn of the order the first (D-A3). It needs no workers (Q-PROJ-3). It is refused, state and Attention unchanged, for an unknown kind or city; a locked kind that no event has unlocked (R-EFX-008); a transit camp without the `maabarot` policy at 0.5 or more (Q-HOUSE-3: the policy carries the camp's sourced date, and the map actions' 1 January 1950 window does not apply); a hex that is not land, is more than `map_action_max_distance` from the city's settlement hex, or holds a map-action placement or another city project, built or not (Q-PROJ-2); and once `map_actions_per_turn` projects were started this turn, counted nationally with the map actions (Q-PROJ-4). The legacy loop refuses it before charging Attention. Its Attention cost is `attention_cost.start_project` (1, Q-PROJ-5).
R-PROJ-002: `CancelProject(id)` removes a city project that is being built. The Money paid is not returned, and there are no people to return (D-A3, Q-PROJ-3). An unknown or built project is refused with the state unchanged. Its Attention cost is `attention_cost.cancel_project` (0.5, Q-PROJ-5).
@@ -242,17 +242,19 @@ R-EFX-002: An option of an event tagged `holocaust`, `terror`, `massacre` or `wa
R-EFX-007: An option of an event tagged `displacement` cannot raise Money (`treasury` or `fx_reserves`), Food (`food` or `food_supply`), Arms (`arms`), Social cohesion (`morale`), International Support (`intl_standing`) or score, with no exception (Q-DEP-6(a), owner ruling of 18 October 2026). Score is not an event-effect target yet and remains an unknown target under R-EFX-001; when that target exists, this rule covers it. The tag also receives R-EFX-005's ban on unit grants and positive city effects.
-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. The first slice built unit grants and the housing capacity and job slots; the second adds the housing condition (#855); project unlock comes with the records it acts on (#735).
+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. The first slice built unit grants and the housing capacity and job slots; the second adds the housing condition (#855); the third adds project unlock (R-EFX-008). The owner ruled on 19 October 2026 (#1095) that no current `projects.yaml` kind gets an additional lock, so none is locked.
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`, or its housing `condition` by a non-zero `delta` from -1 to 1. 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 condition stays from 0 to 1 (R-HOUSE-001). The other fields of the city, its condition included, do not change. The cause carries the change that applied.
-R-EFX-005: An option of an event carrying any sensitive tag (`holocaust`, `terror`, `massacre`, `war-casualties` or `displacement`) carries no unit grant and no `city_effects` gain, whether capacity, slots or condition (Q-HFX-3; extends R-EFX-002 and R-EFX-007). A cut stays allowed.
+R-EFX-005: An option of an event carrying any sensitive tag (`holocaust`, `terror`, `massacre`, `war-casualties` or `displacement`) carries no unit grant and no `city_effects` gain, whether capacity, slots or condition, and no project unlock (Q-HFX-3; extends R-EFX-002 and R-EFX-007). A cut stays allowed.
R-GATE-001: An event tagged `displacement` must have `status: sensitivity-reviewed` before a shareable build. The release gate lists every such event whose status is not reviewed and refuses the build (Q-GATE-1(c), owner ruling of 18 October 2026).
-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.
+R-EFX-006: The structured effects apply after the numeric effects, grants first, then city effects, then project unlocks, 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, field or project kind. 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.
+
+R-EFX-008: A `projects.yaml` kind may say `locked: true` (default false). `StartProject` refuses a locked kind, like the other R-PROJ-001 refusals, until an option whose `unlock_projects` lists it has applied; from then on it is an ordinary kind for the rest of the game. The unlocked kinds are game state, hashed as `unlocked[...]` only when one is unlocked (R-LOOP-002). The loader refuses an `unlock_projects` entry that names an unknown kind or one that is not locked, since it would do nothing.
## Events
@@ -266,7 +268,7 @@ R-EVT-003: An event the player leaves unanswered at End Turn is delegated to its
R-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 unit grants and city effects (R-EFX-006), the policies it sets (by id), then the security level, then the way back to the record (`rejoin`, R-ALT-009), 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, city effects and project unlocks (R-EFX-006), the policies it sets (by id), then the security level, then the way back to the record (`rejoin`, R-ALT-009), 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.
## Alternate timelines
diff --git a/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs b/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs
index f5a9eaf74..e85efffcf 100644
--- a/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs
+++ b/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs
@@ -7,8 +7,8 @@ using Statecraft.Sim;
/// 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; the second adds its housing condition (#855). Project unlock
-/// (#735) and site targets (once a site carries a date, R-EFX-006) follow.</summary>
+/// main: unit grants and a city's housing capacity and job slots; the second adds its housing condition (#855); the third
+/// project unlock (R-EFX-008). Site targets (once a site carries a date, R-EFX-006) follow.</summary>
public class StructuredEffectTests
{
const string Arms = @"
@@ -41,9 +41,10 @@ from: 1948-05-15
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]") =>
+ static Content Load(string ev, string facilities = "[military_camp, hakhshara]", string projects = Fixture.GddProjects) =>
ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>
{
+ ["projects.yaml"] = projects,
["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",
@@ -141,6 +142,8 @@ from: 1948-05-15
[InlineData(" city_effects:\n - { city: town_a, field: condition, delta: 1.5 }\n", "city_effects[0].delta", "from -1 to 1")]
[InlineData(" city_effects:\n - { city: town_a, field: condition, delta: -1.01 }\n", "city_effects[0].delta", "from -1 to 1")]
[InlineData(" city_effects:\n - { city: town_a, field: condition, delta: .nan }\n", "city_effects[0].delta", "from -1 to 1")]
+ [InlineData(" unlock_projects: [nowhere]\n", "unlock_projects[0]", "unknown city project")]
+ [InlineData(" unlock_projects: [housing]\n", "unlock_projects[0]", "is not locked")]
public void TheLoaderRefusesAnUnknownTarget(string structured, string field, string message)
{
var ex = Refused(structured);
@@ -164,6 +167,7 @@ from: 1948-05-15
[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]")]
[InlineData(" city_effects:\n - { city: town_a, field: condition, delta: 0.1 }\n", "city_effects[0]")]
+ [InlineData(" unlock_projects: [industry]\n", "unlock_projects[0]")]
public void ASensitiveOptionGrantsNothing(string structured, string field)
{
var ex = Refused(structured, "war-casualties");
@@ -226,6 +230,9 @@ from: 1948-05-15
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);
+ ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string> { ["arms.yaml"] = Event(UnlockIndustry) })));
+ Assert.Equal("events[arms].options[accept].unlock_projects", 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.
@@ -279,4 +286,65 @@ from: 1948-05-15
(loaded.State.Cities["town_a"].HousingCapacity, loaded.State.Cities["town_a"].JobSlots, loaded.State.Cities["town_b"].Condition));
Assert.Equal(g.State.Hash(), loaded.State.Hash());
}
+
+ // A fixture where the industry project starts locked. No real project is locked in content: which ones start locked is
+ // the owner's call (#806). Fixture values, not the game's.
+ static readonly string LockedIndustry = Fixture.GddProjects.Replace("job_slots: 3 }", "job_slots: 3, locked: true }");
+
+ const string UnlockIndustry = " unlock_projects: [industry]\n";
+
+ // R-EFX-006 and R-EFX-008: the unlock applies after the city effects, and naming a kind twice unlocks it once, with one cause.
+ [Fact]
+ public void AnUnlockAppliesAfterTheCityEffectsAndOnce()
+ {
+ var c = Load(Event(" city_effects:\n - { city: town_a, field: job_slots, delta: 1 }\n unlock_projects: [industry, industry]\n"), projects: LockedIndustry);
+ 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", "town_a.job_slots", "industry" },
+ why.Where(w => w.System == "events" && w.Target != "arms").Select(w => w.Target));
+ Assert.Equal(new[] { "industry" }, s.UnlockedProjects);
+ Assert.Equal(s.Hash(), s.Clone().Hash()); // Clone copies the unlocked kinds
+ Assert.Equal(s.UnlockedProjects, s.Clone().UnlockedProjects);
+ }
+
+ // R-EFX-008 with R-PROJ-001: a locked kind is refused by StartProject until an option that unlocks it is applied, and
+ // then allowed. The unlock applies after the grants and city effects (R-EFX-006), and the preview lists it (R-EVT-005).
+ [Fact]
+ public void ALockedProjectWaitsForItsUnlock()
+ {
+ var c = Load(Event(UnlockIndustry), projects: LockedIndustry);
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ Assert.Equal("An industry project is not available yet", Projects.CheckCity(c, s, "industry", "town_a", 1, 1));
+ Assert.Null(Projects.CheckCity(c, s, "housing", "town_a", 1, 1)); // an unlocked kind is not touched
+ var refused = GameSession.New(c, 1, Mode.Historical);
+ Assert.Single(refused.Step(new Command[] { new StartProject("industry", "town_a", 1, 1) }).Rejected);
+
+ var preview = EventSystem.OptionEffects(c, s, c.Events.Single().Options[0]);
+ Assert.Equal(new[] { "fx_reserves", "industry" }, preview.Select(l => l.Target));
+ Assert.Equal("An industry project can now be built", preview[1].Message);
+
+ var why = new List<Cause>();
+ Assert.Null(EventSystem.Choose(c, s, "arms", "accept", why));
+ Assert.Contains(why, w => w.System == "events" && w.Target == "industry" && w.Delta == 1);
+ Assert.Null(Projects.CheckCity(c, s, "industry", "town_a", 1, 1));
+ }
+
+ // R-EFX-008: the unlock is game state, so a save replays it to the same hash.
+ [Fact]
+ public void ASaveWithAnUnlockReplays()
+ {
+ var c = Load(Event(UnlockIndustry), projects: LockedIndustry);
+ var g = GameSession.New(c, 7, Mode.Historical);
+ g.Step(new Command[] { new ChooseEventOption("arms", "accept") });
+ Assert.Empty(g.Step(new Command[] { new StartProject("industry", "town_a", 1, 1) }).Rejected);
+ Assert.Contains(g.State.CityProjects.Values, p => p.Kind == "industry");
+ var loaded = GameSession.Load(c, g.Save.Write(), out var warnings);
+ Assert.Empty(warnings);
+ Assert.Equal(g.State.UnlockedProjects, loaded.State.UnlockedProjects);
+ Assert.Equal(g.State.Hash(), loaded.State.Hash());
+ var without = g.State.Clone();
+ without.UnlockedProjects.Clear();
+ Assert.NotEqual(without.Hash(), g.State.Hash()); // the unlock is hashed (R-LOOP-002: only when set)
+ }
}
diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.cs
index a36f350fa..982583797 100644
--- a/sim/Statecraft.Sim/Content.cs
+++ b/sim/Statecraft.Sim/Content.cs
@@ -619,6 +619,8 @@ namespace Statecraft.Sim
/// <summary>A city resource the city must have (cities.yaml `resources:`), or "" for none: a specialised industry such as
/// the winery, which needs vineyards (R-PROJ-005, D-D8).</summary>
public string Requires { get; set; } = "";
+ /// <summary>Whether StartProject refuses this kind until an event option unlocks it (R-EFX-008). Default false.</summary>
+ public bool Locked { get; set; }
}
/// <summary>A designated site (sites.yaml; docs/GDD.md "Pioneer work": building is allowed only at designated spots, and a
@@ -850,6 +852,8 @@ namespace Statecraft.Sim
public List<UnitGrant> GrantUnits { get; set; } = new List<UnitGrant>();
/// <summary>R-EFX-004: changes to a city's housing capacity, job slots or housing condition, in list order (D-H2, Q-HFX-1).</summary>
public List<CityEffect> CityEffects { get; set; } = new List<CityEffect>();
+ /// <summary>R-EFX-008: locked projects.yaml kinds this option makes available, in list order (D-H2, Q-HFX-1).</summary>
+ public List<string> UnlockProjects { get; set; } = new List<string>();
/// <summary>Who put this non-historical option forward, and on what record (R-ALT-003). Null when absent.</summary>
public OptionAlternative? Alternative { get; set; }
/// <summary>The event whose historical course this consequence option rejoins (R-ALT-009), or empty.</summary>
diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.cs
index d18dfe7cc..c76971924 100644
--- a/sim/Statecraft.Sim/ContentLoader.cs
+++ b/sim/Statecraft.Sim/ContentLoader.cs
@@ -344,7 +344,8 @@ namespace Statecraft.Sim
// its historical one (R-ALT-001, R-ALT-002); the 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,
- // grant_units: [{ type, n, at }], city_effects: [{ city, field, delta }] }]
+ // grant_units: [{ type, n, at }], city_effects: [{ city, field, delta }],
+ // unlock_projects: [<projects.yaml id of a locked kind>] }]
// 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
diff --git a/sim/Statecraft.Sim/EventRules.cs b/sim/Statecraft.Sim/EventRules.cs
index 314d42294..8424f30bc 100644
--- a/sim/Statecraft.Sim/EventRules.cs
+++ b/sim/Statecraft.Sim/EventRules.cs
@@ -114,10 +114,10 @@ namespace Statecraft.Sim
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 (o.GrantUnits.Count + o.CityEffects.Count + o.UnlockProjects.Count == 0) return;
+ // They act on the GDD records (cities.yaml, unit_types.yaml, sites.yaml, projects.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)");
+ throw new ContentException(e.File, F($"options[{o.Id}].{(o.GrantUnits.Count > 0 ? "grant_units" : o.CityEffects.Count > 0 ? "city_effects" : "unlock_projects")}"), "needs the GDD loop (eras.yaml systems.loop: gdd)");
for (int i = 0; i < o.GrantUnits.Count; i++)
{
var g = o.GrantUnits[i];
@@ -154,6 +154,16 @@ namespace Statecraft.Sim
throw new ContentException(e.File, X(".delta"), "must be a whole number in the int range");
if (sensitive && x.Delta > 0) throw new ContentException(e.File, X(""), $"sensitive events cannot reward {x.Field}");
}
+ for (int i = 0; i < o.UnlockProjects.Count; i++)
+ {
+ // R-EFX-008. Unlocking a kind that starts unlocked would do nothing, so it is a mistake, as an unknown kind is.
+ var kind = o.UnlockProjects[i];
+ var field = F(FormattableString.Invariant($"options[{o.Id}].unlock_projects[{i}]"));
+ if (sensitive) throw new ContentException(e.File, field, "sensitive events cannot reward a project unlock");
+ var k = c.ProjectKinds.FirstOrDefault(x => x.Id == kind)
+ ?? throw new ContentException(e.File, field, $"unknown city project '{kind}'");
+ if (!k.Locked) throw new ContentException(e.File, field, $"'{kind}' is not locked in projects.yaml");
+ }
}
/// <summary>Objectives and their cards name each other (R-OBJ-003): an event's `objective` names an objective whose
diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.cs
index f1a142ca6..e77d00af5 100644
--- a/sim/Statecraft.Sim/EventSystem.cs
+++ b/sim/Statecraft.Sim/EventSystem.cs
@@ -135,6 +135,9 @@ namespace Statecraft.Sim
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})"));
}
+ // R-EFX-008: after the city effects. A kind already unlocked stays so, with no second cause.
+ foreach (var kind in o.UnlockProjects)
+ if (s.UnlockedProjects.Add(kind)) why.Add(new Cause("events", kind, 1, $"{Unlocked(c, kind)} ({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;
@@ -159,6 +162,9 @@ namespace Statecraft.Sim
static string Granted(UnitGrant g, string place) =>
FormattableString.Invariant($"{g.N} {g.Type} unit{(g.N == 1 ? "" : "s")} at {place}");
+ static string Unlocked(Content c, string kind) =>
+ $"{PlayerText.Capitalised(c.ProjectKinds.First(k => k.Id == kind).Name)} can now be built";
+
static string CityChange(Content c, string city, string field, double delta) =>
field == ConditionField
? $"{PlayerText.Settlement(c, city)}: housing condition {PlayerText.PercentChange(delta)}"
@@ -174,6 +180,7 @@ namespace Statecraft.Sim
.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.UnlockProjects.Select(k => new Cause("events", k, 1, Unlocked(c, k))));
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}")));
diff --git a/sim/Statecraft.Sim/GameState.cs b/sim/Statecraft.Sim/GameState.cs
index be44f8757..80878eca8 100644
--- a/sim/Statecraft.Sim/GameState.cs
+++ b/sim/Statecraft.Sim/GameState.cs
@@ -70,6 +70,8 @@ namespace Statecraft.Sim
public SortedDictionary<string, SiteWork> Sites = new SortedDictionary<string, SiteWork>(StringComparer.Ordinal);
/// <summary>The city projects being built or built, by id (R-PROJ-001). A cancelled project leaves.</summary>
public SortedList<int, CityProject> CityProjects = new SortedList<int, CityProject>();
+ /// <summary>The locked projects.yaml kinds an event option has unlocked (R-EFX-008), by id (ordinal).</summary>
+ public SortedSet<string> UnlockedProjects = new SortedSet<string>(StringComparer.Ordinal);
/// <summary>The next id a new unit, training cohort or city project takes (they share it). Ids are never reused.</summary>
public int NextId;
/// <summary>The date each completed objective was completed, by objective id (ordinal).</summary>
@@ -112,6 +114,7 @@ namespace Statecraft.Sim
c.Cohorts = new SortedList<int, Cohort>(Cohorts);
c.Sites = new SortedDictionary<string, SiteWork>(Sites, StringComparer.Ordinal);
c.CityProjects = new SortedList<int, CityProject>(CityProjects);
+ c.UnlockedProjects = new SortedSet<string>(UnlockedProjects, StringComparer.Ordinal);
c.Objectives = new SortedDictionary<string, DateTime>(Objectives, StringComparer.Ordinal);
c.Settlements = new SortedDictionary<string, SettlementControl>(Settlements, StringComparer.Ordinal);
return c;
@@ -201,6 +204,7 @@ namespace Statecraft.Sim
if (Cohorts.Count > 0) Section("train", '[', ']', Cohorts.Values.Select(x => x.Canonical()));
if (Sites.Count > 0) Section("site", '{', '}', Sites.Values.Select(x => x.Canonical()));
if (CityProjects.Count > 0) Section("cproj", '[', ']', CityProjects.Values.Select(x => x.Canonical()));
+ if (UnlockedProjects.Count > 0) Section("unlocked", '[', ']', UnlockedProjects);
if (NextId != 0) { Sep(); Nl(); sb.Append("next=").Append(NextId.ToString(CultureInfo.InvariantCulture)); }
if (Objectives.Count > 0)
Section("obj", '{', '}', Objectives.Select(kv => kv.Key + "=" + kv.Value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)));
diff --git a/sim/Statecraft.Sim/Projects.cs b/sim/Statecraft.Sim/Projects.cs
index cbb80a5be..a0b35ed9c 100644
--- a/sim/Statecraft.Sim/Projects.cs
+++ b/sim/Statecraft.Sim/Projects.cs
@@ -206,6 +206,7 @@ namespace Statecraft.Sim
var k = c.ProjectKinds.FirstOrDefault(x => x.Id == kind);
if (k == null) return "There is no such city project";
if (!s.Cities.ContainsKey(city)) return "There is no such city";
+ if (k.Locked && !s.UnlockedProjects.Contains(kind)) return $"{PlayerText.Capitalised(k.Name)} is not available yet"; // R-EFX-008
if (kind == MapActions.TransitCamp && !(s.Policies.TryGetValue(MapActions.MaabarotPolicy, out var m) && m >= 0.5))
return "Transit camps need the ma'abarot policy";
// R-PROJ-005. A city founded in play is not in cities.yaml, so it has no resources.