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: requires as a list (AND) and diverged: true (R-ALT-001, R-ALT-002; refs #946) (#960)

Eyal Golan9cd20d43b175
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 28a7d2e15..c0ea51e37 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,9 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
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.
+- Events: `requires` is a list whose entries must all hold, and an entry can say `diverged: true` (any option but
+ the historical one); the five events with a requirement move to the list form with the same meaning (R-ALT-001,
+ R-ALT-002; refs #946, #939).
- The 1948 unit roster gives 20 formations a sourced Hebrew name (`name_he`, agent-checked until #564's read); a
name'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 2m
diff --git a/content/events/jerusalem_ceasefire.yaml b/content/events/jerusalem_ceasefire.yaml
index 5d3421d58..24cf0943d 100644
--- a/content/events/jerusalem_ceasefire.yaml
+++ b/content/events/jerusalem_ceasefire.yaml
@@ -16,7 +16,7 @@ office: prime_minister
# 15 December, and the text states the signing.
from: 1948-11-30
to: 1948-12-16
-requires: { event: jerusalem_military_government, option: military_government }
+requires: [{ event: jerusalem_military_government, option: military_government }]
options:
- id: keep
text: Keep to the Jerusalem cease-fire
diff --git a/content/events/latrun_proposal.yaml b/content/events/latrun_proposal.yaml
index 5d2527017..7008931f9 100644
--- a/content/events/latrun_proposal.yaml
+++ b/content/events/latrun_proposal.yaml
@@ -15,7 +15,7 @@ office: prime_minister
# Only a player who complied with the second truce sees this card (it is about breaking the truce).
from: 1948-09-15
to: 1948-09-27
-requires: { event: second_truce, option: comply }
+requires: [{ event: second_truce, option: comply }]
options:
- id: accept_vote
text: Accept the cabinet's vote and keep the truce
diff --git a/content/events/rhodes_talks.yaml b/content/events/rhodes_talks.yaml
index 1ad55b759..4ebb0f454 100644
--- a/content/events/rhodes_talks.yaml
+++ b/content/events/rhodes_talks.yaml
@@ -16,7 +16,7 @@ office: foreign_minister
# the delay (owner decision, 15 October 2026, #567; docs/superpowers/specs/2026-10-14-event-timing-monthly.md).
from: 1949-01-09
to: 1949-01-13
-requires: { event: operation_horev, option: launch }
+requires: [{ event: operation_horev, option: launch }]
options:
- id: send_delegation
text: Send a delegation to Rhodes
diff --git a/content/events/sinai_withdrawal.yaml b/content/events/sinai_withdrawal.yaml
index 12a70ba0e..3880b6dc9 100644
--- a/content/events/sinai_withdrawal.yaml
+++ b/content/events/sinai_withdrawal.yaml
@@ -21,7 +21,7 @@ office: prime_minister
# 15 January, and the text states the withdrawal.
from: 1949-01-02
to: 1949-01-16
-requires: { event: operation_horev, option: launch }
+requires: [{ event: operation_horev, option: launch }]
options:
- id: withdraw
text: Keep the forces behind the Negev frontier
diff --git a/content/events/ten_days.yaml b/content/events/ten_days.yaml
index 4f045401c..226d72d44 100644
--- a/content/events/ten_days.yaml
+++ b/content/events/ten_days.yaml
@@ -21,7 +21,7 @@ office: defense_minister
# accepted the first truce sees this card (its text is about the truce ending).
from: 1948-07-10
to: 1948-07-18
-requires: { event: first_truce, option: accept }
+requires: [{ event: first_truce, option: accept }]
options:
- id: central_front
text: Keep the main effort in the centre with Operation Dani, toward the Jerusalem road
diff --git a/content/schema/event.schema.json b/content/schema/event.schema.json
index 840f01922..284b6d653 100644
--- a/content/schema/event.schema.json
+++ b/content/schema/event.schema.json
@@ -7,7 +7,18 @@
"required": ["id", "title", "text", "from", "options", "sources"],
"definitions": {
"date": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$", "description": "A day, YYYY-MM-DD." },
- "id": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$", "description": "Lowercase letters, digits and underscores, starting with a letter." }
+ "id": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$", "description": "Lowercase letters, digits and underscores, starting with a letter." },
+ "requirement": {
+ "type": "object",
+ "additionalProperties": false,
+ "required": ["event"],
+ "description": "One precondition (R-ALT-001): the event was resolved with this option, or, with diverged: true, with any option but its historical one (R-ALT-002). Give option or diverged, not both.",
+ "properties": {
+ "event": { "$ref": "#/definitions/id" },
+ "option": { "$ref": "#/definitions/id" },
+ "diverged": { "type": "boolean" }
+ }
+ }
},
"properties": {
"id": { "$ref": "#/definitions/id", "description": "Unique across all events." },
@@ -32,15 +43,7 @@
}
}
},
- "requires": {
- "type": "object",
- "additionalProperties": false,
- "required": ["event", "option"],
- "properties": {
- "event": { "$ref": "#/definitions/id" },
- "option": { "$ref": "#/definitions/id" }
- }
- },
+ "requires": { "type": "array", "minItems": 1, "items": { "$ref": "#/definitions/requirement" }, "description": "Every entry must hold (R-ALT-001)." },
"options": {
"type": "array",
"minItems": 1,
diff --git a/docs/WRITING_EVENTS.md b/docs/WRITING_EVENTS.md
index 566356557..9ebbfdd83 100644
--- a/docs/WRITING_EVENTS.md
+++ b/docs/WRITING_EVENTS.md
@@ -37,7 +37,7 @@ schema too, or that test fails. Keep the comment when you copy a file.
| `from` | yes | First day of the window, `YYYY-MM-DD`. |
| `to` | no | Day the window ends (exclusive). Must be after `from`. Leave it out for an open window. |
| `conditions` | no | Indicator bounds that must hold when it fires. See below. |
-| `requires` | no | Fires only after another event was resolved with a given option. See below. |
+| `requires` | no | Fires only after every listed requirement holds. See below. |
| `objective` | no | Makes the event the completion card of an objective in `objectives.yaml`, which must name this event as its `card`. It fires only once the objective is completed (GDD loop only), and has exactly one option. See `docs/gdd/objective-card.md`. |
| `options` | yes | One or more options. See below. |
| `sources` | no by the loader, yes by the rules | A list of `{ url, checked }`. See below. |
@@ -115,11 +115,20 @@ conditions:
### requires
```yaml
-requires: { event: other_event_id, option: other_option_id }
+requires: [{ event: other_event_id, option: other_option_id }]
```
-The event waits until `other_event_id` was resolved (chosen or delegated) with `other_option_id`. Both must exist, an
-event cannot require itself, and requirements cannot form a cycle.
+A list: the event waits until **every** entry holds (R-ALT-001). An entry holds when that event was resolved (chosen or
+delegated) with that option. An entry can instead say `diverged: true`:
+
+```yaml
+requires: [{ event: other_event_id, diverged: true }]
+```
+
+which holds when that event was resolved with any option except its historical one (R-ALT-002). The loader checks that
+every named event exists, that an entry gives an option or `diverged: true` (not both, not neither), that the option
+exists, that a `diverged` event has a historical option, that no event is named twice in one list, that an event does
+not require itself, and that requirements do not form a cycle.
### options
@@ -250,9 +259,13 @@ Errors are printed as `file: field: message`. These are the messages you are mos
| `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. |
| `must be a list` | A list field (such as `tags:`) written with no value. |
-| `an event cannot require itself` | `requires.event` is the event's own id. |
+| `an event cannot require itself` | `requires[n].event` is the event's own id. |
| `requirements form a cycle` | Event A needs B and B needs A, directly or through others. |
-| `unknown event '` | `requires.event` names an event that does not exist. |
+| `unknown event '` | `requires[n].event` names an event that does not exist. |
+| `needs an option or diverged: true` | A `requires` entry names neither an option nor `diverged: true`. |
+| `not both` | A `requires` entry names an option and `diverged: true`. |
+| `has no historical option, so it cannot diverge` | `diverged: true` on an event with no historical option. |
+| `is already required` | Two `requires` entries name the same event (they could never both hold, or one is redundant). |
A full message looks like this (an effect target misspelled `securty`):
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 238d578ef..6f5d7dfb8 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -175,3 +175,11 @@ 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, 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
+
+The alternate-timeline mechanism ([the plan](../superpowers/plans/2026-10-17-alternate-timelines.md); the owner's answers, 17 October 2026, #945).
+
+R-ALT-001: An event's `requires` is a list, and the event is eligible only when every entry holds. An entry `{ event, option }` holds when that event was resolved (chosen or delegated) with that option. A list names each event at most once.
+
+R-ALT-002: An entry `{ event, diverged: true }` holds when that event was resolved with any option except its historical one. An event with no historical option cannot diverge, and the loader refuses `diverged` on it.
diff --git a/sim/Statecraft.Sim.Tests/EventRequiresTests.cs b/sim/Statecraft.Sim.Tests/EventRequiresTests.cs
index 37dcaf877..c581cc9e3 100644
--- a/sim/Statecraft.Sim.Tests/EventRequiresTests.cs
+++ b/sim/Statecraft.Sim.Tests/EventRequiresTests.cs
@@ -2,7 +2,7 @@ using System;
using System.Collections.Generic;
using Statecraft.Sim;
-/// <summary>`requires: { event, option }`: an event is eligible only after another event was resolved with that option
+/// <summary>`requires: [{ event, option }, ...]`: an event is eligible only after every listed event was resolved with its option
/// (fix round 1, I2: a follow-up card must not contradict the player's earlier choice).</summary>
public class EventRequiresTests
{
@@ -24,7 +24,7 @@ id: follow
title: Follow-up
text: 'After going.'
from: 1948-06-01
-requires: { event: first, option: go }
+requires: [{ event: first, option: go }]
options:
- id: ok
text: Fine
@@ -43,10 +43,11 @@ options:
[Fact]
public void TheRequirementIsReadFromYaml()
{
- var e = Load(Follow).Events.Find(x => x.Id == "follow")!;
- Assert.Equal("first", e.Requires!.Event);
- Assert.Equal("go", e.Requires.Option);
- Assert.Null(Load(Follow).Events.Find(x => x.Id == "first")!.Requires);
+ var r = Assert.Single(Load(Follow).Events.Find(x => x.Id == "follow")!.Requires);
+ Assert.Equal("first", r.Event);
+ Assert.Equal("go", r.Option);
+ Assert.False(r.Diverged);
+ Assert.Empty(Load(Follow).Events.Find(x => x.Id == "first")!.Requires);
}
[Fact]
@@ -89,13 +90,13 @@ options:
}
[Theory]
- [InlineData("requires: { event: nope, option: go }", "events[follow].requires.event", "unknown event 'nope'")]
- [InlineData("requires: { event: first, option: nope }", "events[follow].requires.option", "event 'first' has no option 'nope'")]
- [InlineData("requires: { event: follow, option: ok }", "events[follow].requires.event", "an event cannot require itself")]
- [InlineData("requires: { event: '', option: go }", "events[follow].requires.event", "unknown event ''")]
+ [InlineData("requires: [{ event: nope, option: go }]", "events[follow].requires[0].event", "unknown event 'nope'")]
+ [InlineData("requires: [{ event: first, option: nope }]", "events[follow].requires[0].option", "event 'first' has no option 'nope'")]
+ [InlineData("requires: [{ event: follow, option: ok }]", "events[follow].requires[0].event", "an event cannot require itself")]
+ [InlineData("requires: [{ event: '', option: go }]", "events[follow].requires[0].event", "unknown event ''")]
public void ABrokenRequirementIsALoadErrorNamingTheFile(string line, string field, string message)
{
- var ex = Assert.Throws<ContentException>(() => Load(Follow.Replace("requires: { event: first, option: go }", line)));
+ var ex = Assert.Throws<ContentException>(() => Load(Follow.Replace("requires: [{ event: first, option: go }]", line)));
Assert.Equal("events/follow.yaml", ex.File);
Assert.Equal(field, ex.Field);
Assert.Contains(message, ex.Message);
@@ -119,7 +120,7 @@ id: {id}
title: {id}
text: 'Waits.'
from: 1948-06-01
-requires: {{ event: {other}, option: ok }}
+requires: [{{ event: {other}, option: ok }}]
options:
- id: ok
text: Fine
@@ -147,4 +148,130 @@ options:
}));
Assert.Equal(4, c.Events.Count);
}
+
+ const string Second = @"
+id: second
+title: Second
+text: 'Another choice.'
+from: 1948-06-01
+options:
+ - id: agree
+ text: Agree
+ historical: true
+ - id: decline
+ text: Decline
+";
+
+ const string Plain = @"
+id: plain
+title: Plain
+text: 'No record of what happened.'
+from: 1948-06-01
+options:
+ - id: one
+ text: One
+ - id: two
+ text: Two
+";
+
+ static Content LoadAll(string follow) => ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string>
+ {
+ ["first.yaml"] = First, ["second.yaml"] = Second, ["plain.yaml"] = Plain, ["follow.yaml"] = follow,
+ }));
+
+ /// <summary>Plays the two choices, then triggers once more and says whether the follow-up fired.</summary>
+ static bool FiresAfter(Content c, string first, string second)
+ {
+ var s = State(c);
+ var why = new List<Cause>();
+ EventSystem.Trigger(c, s, why);
+ Assert.Null(EventSystem.Choose(c, s, "first", first, why));
+ Assert.Null(EventSystem.Choose(c, s, "second", second, why));
+ EventSystem.Trigger(c, s, why);
+ return s.FiredEvents.Contains("follow");
+ }
+
+ // R-ALT-001
+ [Theory]
+ [InlineData("go", "decline", true)]
+ [InlineData("go", "agree", false)]
+ [InlineData("stay", "decline", false)]
+ public void EveryRequirementInTheListMustHold(string first, string second, bool fires)
+ {
+ var c = LoadAll(Follow.Replace("requires: [{ event: first, option: go }]",
+ "requires: [{ event: first, option: go }, { event: second, option: decline }]"));
+ Assert.Equal(fires, FiresAfter(c, first, second));
+ }
+
+ // R-ALT-002
+ [Theory]
+ [InlineData("go", false)]
+ [InlineData("stay", true)]
+ public void DivergedMeansAnyOptionButTheHistoricalOne(string first, bool fires)
+ {
+ var c = LoadAll(Follow.Replace("requires: [{ event: first, option: go }]", "requires: [{ event: first, diverged: true }]"));
+ Assert.Equal(fires, FiresAfter(c, first, "agree"));
+ }
+
+ // R-ALT-002
+ [Fact]
+ public void AnUnansweredEventHasNotDiverged()
+ {
+ var c = LoadAll(Follow);
+ var s = State(c);
+ Assert.False(Timeline.Diverged(c, s, "first"));
+ Assert.False(Timeline.Diverged(c, s, "plain"));
+ s.ChosenOptions["plain"] = "two";
+ Assert.False(Timeline.Diverged(c, s, "plain")); // no historical option: nothing to diverge from
+ s.ChosenOptions["first"] = "stay";
+ Assert.True(Timeline.Diverged(c, s, "first"));
+ }
+
+ // R-ALT-002
+ [Theory]
+ [InlineData("requires: [{ event: first }]", "events[follow].requires[0]", "needs an option or diverged: true")]
+ [InlineData("requires: [{ event: first, option: go, diverged: true }]", "events[follow].requires[0]", "an option or diverged: true, not both")]
+ [InlineData("requires: [{ event: plain, diverged: true }]", "events[follow].requires[0].diverged", "event 'plain' has no historical option")]
+ [InlineData("requires: [{ event: first, option: go }, { event: first, diverged: true }]", "events[follow].requires[1].event", "event 'first' is already required")]
+ [InlineData("requires: [{ event: first, option: go }, { event: first, option: stay }]", "events[follow].requires[1].event", "event 'first' is already required")]
+ public void ABadDivergedRequirementIsALoadError(string line, string field, string message)
+ {
+ var ex = Assert.Throws<ContentException>(() => LoadAll(Follow.Replace("requires: [{ event: first, option: go }]", line)));
+ Assert.Equal("events/follow.yaml", ex.File);
+ Assert.Equal(field, ex.Field);
+ Assert.Contains(message, ex.Message);
+ }
+
+ // R-ALT-002: a delegated answer diverges as a chosen one does (Q-ALT-11, decided).
+ [Fact]
+ public void ADelegatedAlternativeDivergesToo()
+ {
+ var c = LoadAll(Follow);
+ var s = State(c);
+ var why = new List<Cause>();
+ EventSystem.Trigger(c, s, why);
+ for (ulong seed = 0; seed < 200 && !Timeline.Diverged(c, s, "first"); seed++)
+ {
+ s = State(c);
+ s.RngState = seed;
+ EventSystem.Trigger(c, s, why);
+ EventSystem.Delegate(c, s, why); // soft and no office: a random pick half the time
+ }
+ Assert.Equal("stay", s.ChosenOptions["first"]);
+ Assert.True(Timeline.Diverged(c, s, "first"));
+ }
+
+ /// <summary>The cycle check walks every entry of the list, not only the first.</summary>
+ [Fact]
+ public void ACycleThroughASecondRequirementIsFound()
+ {
+ var a = "id: a\ntitle: a\ntext: x\nfrom: 1948-06-01\nrequires: [{ event: first, option: go }, { event: b, option: ok }]\noptions:\n - id: ok\n text: Ok\n";
+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(events: new Dictionary<string, string>
+ {
+ ["first.yaml"] = First, ["a.yaml"] = a, ["b.yaml"] = Requiring("b", "a"),
+ })));
+ Assert.Equal("events/a.yaml", ex.File);
+ Assert.Equal("events[a].requires", ex.Field);
+ Assert.Contains("requirements form a cycle: events/a.yaml -> events/b.yaml -> events/a.yaml", ex.Message);
+ }
}
diff --git a/sim/Statecraft.Sim.Tests/EventRulesGddTests.cs b/sim/Statecraft.Sim.Tests/EventRulesGddTests.cs
index faafcc207..d18508dc9 100644
--- a/sim/Statecraft.Sim.Tests/EventRulesGddTests.cs
+++ b/sim/Statecraft.Sim.Tests/EventRulesGddTests.cs
@@ -35,7 +35,7 @@ public class EventRulesGddTests
public void HardAnchorsAlwaysFire()
{
Assert.Equal(GameOverCodes.MvpEnded, Run[Run.Count - 1].GameOver);
- var plain = C.Events.Where(e => e.Anchor == "hard" && e.Requires == null && e.Conditions.Count == 0 && e.Objective == "").ToList();
+ var plain = C.Events.Where(e => e.Anchor == "hard" && e.Requires.Count == 0 && e.Conditions.Count == 0 && e.Objective == "").ToList();
Assert.NotEmpty(plain);
foreach (var e in plain)
{
diff --git a/sim/Statecraft.Sim.Tests/SchemaTests.cs b/sim/Statecraft.Sim.Tests/SchemaTests.cs
index 21389ee9b..04d02c047 100644
--- a/sim/Statecraft.Sim.Tests/SchemaTests.cs
+++ b/sim/Statecraft.Sim.Tests/SchemaTests.cs
@@ -191,7 +191,7 @@ public class SchemaTests
yield return new object[] { "people.schema.json", "/definitions/source", typeof(Source) };
yield return new object[] { "event.schema.json", "", typeof(GameEvent) };
yield return new object[] { "event.schema.json", "/properties/conditions/items", typeof(EventCondition) };
- yield return new object[] { "event.schema.json", "/properties/requires", typeof(EventRequirement) };
+ yield return new object[] { "event.schema.json", "/definitions/requirement", typeof(EventRequirement) };
yield return new object[] { "event.schema.json", "/properties/options/items", typeof(EventOption) };
yield return new object[] { "event.schema.json", "/properties/options/items/properties/effects/items", typeof(OptionEffect) };
yield return new object[] { "event.schema.json", "/properties/sources/items", typeof(Source) };
diff --git a/sim/Statecraft.Sim.Tests/WarEvents1948Tests.cs b/sim/Statecraft.Sim.Tests/WarEvents1948Tests.cs
index 6bb6abcd4..58c99eb89 100644
--- a/sim/Statecraft.Sim.Tests/WarEvents1948Tests.cs
+++ b/sim/Statecraft.Sim.Tests/WarEvents1948Tests.cs
@@ -86,8 +86,8 @@ public class WarEvents1948Tests
Assert.True(historical.Recommended);
Assert.Equal(row.Historical, e.Options[0].Id); // the smoke run and the event card press the first option
var chain = Chains.Where(x => x.Id == id).ToList();
- if (chain.Count == 0) Assert.Null(e.Requires);
- else { Assert.Equal(chain[0].Event, e.Requires!.Event); Assert.Equal(chain[0].Option, e.Requires.Option); }
+ if (chain.Count == 0) Assert.Empty(e.Requires);
+ else { var r = Assert.Single(e.Requires); Assert.Equal(chain[0].Event, r.Event); Assert.Equal(chain[0].Option, r.Option); }
}
[Theory]
diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.cs
index c3c37c863..d3e46ae77 100644
--- a/sim/Statecraft.Sim/Content.cs
+++ b/sim/Statecraft.Sim/Content.cs
@@ -691,8 +691,14 @@ namespace Statecraft.Sim
public sealed class EventCondition { public string Indicator { get; set; } = ""; public double? Min { get; set; } public double? Max { get; set; } }
- /// <summary>An event's precondition: <see cref="Event"/> must have been resolved with <see cref="Option"/>.</summary>
- public sealed class EventRequirement { public string Event { get; set; } = ""; public string Option { get; set; } = ""; }
+ /// <summary>One precondition of an event: <see cref="Event"/> was resolved with <see cref="Option"/>, or, with
+ /// <see cref="Diverged"/>, with any option but its historical one (R-ALT-001, R-ALT-002).</summary>
+ public sealed class EventRequirement
+ {
+ public string Event { get; set; } = "";
+ public string Option { get; set; } = "";
+ public bool Diverged { get; set; }
+ }
public sealed class OptionEffect { public string Target { get; set; } = ""; public double Delta { get; set; } }
@@ -741,8 +747,8 @@ namespace Statecraft.Sim
public DateTime From { get; set; }
public DateTime? To { get; set; }
public List<EventCondition> Conditions { get; set; } = new List<EventCondition>();
- /// <summary>Eligible only once this other event was resolved with this option (null: no requirement).</summary>
- public EventRequirement? Requires { get; set; }
+ /// <summary>Eligible only once every one of these holds (R-ALT-001). Empty: no requirement.</summary>
+ public List<EventRequirement> Requires { get; set; } = new List<EventRequirement>();
public List<EventOption> Options { get; set; } = new List<EventOption>();
public List<Source> Sources { get; set; } = new List<Source>();
public string Status { get; set; } = "draft";
diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.cs
index be4264d1f..1cc1f7be2 100644
--- a/sim/Statecraft.Sim/ContentLoader.cs
+++ b/sim/Statecraft.Sim/ContentLoader.cs
@@ -329,9 +329,10 @@ namespace Statecraft.Sim
// office the minister the event is delegated to
// from, to the window [from, to); it fires on the first turn that overlaps it
// conditions: [{ indicator, min, max }] indicator bounds that must hold when it fires
- // 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)
+ // requires: [{ event, option } | { event, diverged: true }, ...] fires only once every entry holds: that
+ // event was resolved (chosen or delegated) with that option, or with any option but
+ // 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 }] }]
// sources: [{ url, checked }], status
diff --git a/sim/Statecraft.Sim/EventRules.cs b/sim/Statecraft.Sim/EventRules.cs
index ce11e594d..bb5a4b6a4 100644
--- a/sim/Statecraft.Sim/EventRules.cs
+++ b/sim/Statecraft.Sim/EventRules.cs
@@ -56,13 +56,12 @@ namespace Statecraft.Sim
if (cond.Max.HasValue) { ContentLoader.Finite(e.File, F($"conditions.{cond.Indicator}.max"), cond.Max.Value); ContentLoader.Unit(e.File, F($"conditions.{cond.Indicator}.max"), cond.Max.Value); }
if (cond.Min > cond.Max) throw new ContentException(e.File, F($"conditions.{cond.Indicator}.min"), "must not exceed max");
}
- if (e.Requires != null)
+ for (int i = 0; i < e.Requires.Count; i++)
{
- if (e.Requires.Event == e.Id) throw new ContentException(e.File, F("requires.event"), "an event cannot require itself");
- var required = c.Events.FirstOrDefault(x => x.Id == e.Requires.Event)
- ?? throw new ContentException(e.File, F("requires.event"), $"unknown event '{e.Requires.Event}'");
- if (required.Options.All(o => o.Id != e.Requires.Option))
- throw new ContentException(e.File, F("requires.option"), $"event '{required.Id}' has no option '{e.Requires.Option}'");
+ CheckRequirement(c, e, $"requires[{i}]", e.Requires[i]);
+ // Two entries on one event can never both hold, or one makes the other redundant: either way it is a slip.
+ if (e.Requires.Take(i).Any(r => r.Event == e.Requires[i].Event))
+ throw new ContentException(e.File, F($"requires[{i}].event"), $"event '{e.Requires[i].Event}' is already required; give it one entry");
}
if (e.Options.Count == 0) throw new ContentException(e.File, F("options"), "at least one option required");
if (e.Options.Count(o => o.Historical) > 1) throw new ContentException(e.File, F("options"), "at most one option can be historical");
@@ -176,28 +175,52 @@ namespace Statecraft.Sim
}
}
+ /// <summary>R-ALT-001 and R-ALT-002: a requirement names an existing other event and either one of its options or
+ /// `diverged: true`, which needs that event to have a historical option.</summary>
+ internal static void CheckRequirement(Content c, GameEvent e, string at, EventRequirement r)
+ {
+ string F(string field) => $"events[{e.Id}].{at}{field}";
+ if (r.Event == e.Id) throw new ContentException(e.File, F(".event"), "an event cannot require itself");
+ var required = c.Events.FirstOrDefault(x => x.Id == r.Event)
+ ?? throw new ContentException(e.File, F(".event"), $"unknown event '{r.Event}'");
+ if (r.Diverged && r.Option != "") throw new ContentException(e.File, F(""), "give an option or diverged: true, not both");
+ if (!r.Diverged && r.Option == "") throw new ContentException(e.File, F(""), "needs an option or diverged: true");
+ if (r.Diverged && !required.Options.Any(o => o.Historical))
+ throw new ContentException(e.File, F(".diverged"), $"event '{required.Id}' has no historical option, so it cannot diverge");
+ if (!r.Diverged && required.Options.All(o => o.Id != r.Option))
+ throw new ContentException(e.File, F(".option"), $"event '{required.Id}' has no option '{r.Option}'");
+ }
+
/// <summary>Re-review N4: a cycle of `requires` (A needs B, B needs A, ...) could never fire. Called after every
- /// requirement's ids are known to exist; the error names the files around the cycle, starting from the first event
- /// (in load order) that lies on it.</summary>
+ /// requirement's ids are known to exist. It walks each list in order; the error names the files around the first
+ /// cycle found, starting from the first event (in load order) that lies on one.</summary>
static void CheckRequirementCycles(Content c)
{
var byId = c.Events.ToDictionary(e => e.Id);
foreach (var start in c.Events)
{
- var path = new List<GameEvent> { start };
- var seen = new HashSet<string> { start.Id };
- for (var e = start; e.Requires != null; )
- {
- e = byId[e.Requires.Event];
- path.Add(e);
- if (e.Id == start.Id)
- throw new ContentException(start.File, $"events[{start.Id}].requires",
- "requirements form a cycle: " + string.Join(" -> ", path.Select(x => x.File)));
- if (!seen.Add(e.Id)) break; // a cycle that does not pass through start; reported from its own member
- }
+ var cycle = CycleFrom(byId, start, start, new List<GameEvent> { start }, new HashSet<string> { start.Id });
+ if (cycle != null)
+ throw new ContentException(start.File, $"events[{start.Id}].requires",
+ "requirements form a cycle: " + string.Join(" -> ", cycle.Select(x => x.File)));
}
}
+ static List<GameEvent>? CycleFrom(Dictionary<string, GameEvent> byId, GameEvent start, GameEvent at, List<GameEvent> path, HashSet<string> seen)
+ {
+ foreach (var r in at.Requires)
+ {
+ var next = byId[r.Event];
+ if (next.Id == start.Id) return new List<GameEvent>(path) { next };
+ if (!seen.Add(next.Id)) continue; // already walked from start; a cycle not through start is reported from its own member
+ path.Add(next);
+ var found = CycleFrom(byId, start, next, path, seen);
+ if (found != null) return found;
+ path.RemoveAt(path.Count - 1);
+ }
+ return null;
+ }
+
static void CheckPlaceholders(Content c, GameEvent e, string field, string text, HashSet<string> offices)
{
if (Offices.Placeholder.Replace(text, "").IndexOfAny(new[] { '{', '}' }) >= 0)
diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.cs
index 5e74ac21d..04d4767f8 100644
--- a/sim/Statecraft.Sim/EventSystem.cs
+++ b/sim/Statecraft.Sim/EventSystem.cs
@@ -25,7 +25,7 @@ namespace Statecraft.Sim
var start = turnStart ?? s.Date;
var eligible = c.Events
.Where(e => !s.FiredEvents.Contains(e.Id) && e.From <= s.Date && (e.To == null || start < e.To.Value))
- .Where(e => e.Requires == null || (s.ChosenOptions.TryGetValue(e.Requires.Event, out var picked) && picked == e.Requires.Option))
+ .Where(e => Timeline.AllMet(c, s, e))
// R-OBJ-003: an objective's card waits for the objective. Only the GDD loop records one, so in the legacy loop it never fires.
.Where(e => e.Objective == "" || s.Objectives.ContainsKey(e.Objective))
// A late fire can come after a dated indicator's window has ended (chapters design 3.2): a condition on it is not met.
diff --git a/sim/Statecraft.Sim/Timeline.cs b/sim/Statecraft.Sim/Timeline.cs
new file mode 100644
index 000000000..788f36a8d
--- /dev/null
+++ b/sim/Statecraft.Sim/Timeline.cs
@@ -0,0 +1,32 @@
+using System.Linq;
+
+namespace Statecraft.Sim
+{
+ /// <summary>Where the player's course stands against the record. Every answer is derived from
+ /// <see cref="GameState.ChosenOptions"/> and the content, so nothing here is state
+ /// (docs/superpowers/plans/2026-10-17-alternate-timelines.md, A.4.1).</summary>
+ public static class Timeline
+ {
+ public static EventOption? HistoricalOption(GameEvent e) => e.Options.FirstOrDefault(o => o.Historical);
+
+ static GameEvent Get(Content c, string id) => c.Events.First(e => e.Id == id);
+
+ /// <summary>R-ALT-002: the event was resolved, it has a historical option, and the chosen option is another.</summary>
+ public static bool Diverged(Content c, GameState s, string eventId)
+ {
+ if (!s.ChosenOptions.TryGetValue(eventId, out var picked)) return false;
+ var historical = HistoricalOption(Get(c, eventId));
+ return historical != null && picked != historical.Id;
+ }
+
+ /// <summary>R-ALT-001 and R-ALT-002: one requirement holds.</summary>
+ public static bool Met(Content c, GameState s, EventRequirement r)
+ {
+ if (r.Diverged) return Diverged(c, s, r.Event);
+ return s.ChosenOptions.TryGetValue(r.Event, out var picked) && picked == r.Option;
+ }
+
+ /// <summary>R-ALT-001: every requirement of the event holds (true when it has none).</summary>
+ public static bool AllMet(Content c, GameState s, GameEvent e) => e.Requires.All(r => Met(c, s, r));
+ }
+}