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.

docs: add a guide to writing an event (#46)

eyalgolan82a8d0572928
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 76a138da8..111f11d01 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -49,6 +49,7 @@ Follow [docs/dev-setup.md](docs/dev-setup.md). In short:
## History and content rules
+- **Adding an event?** Follow [docs/WRITING_EVENTS.md](docs/WRITING_EVENTS.md): every field, what the loader rejects, and how to run the tests.
- **Every fact needs a source.** Every event, minister, office term, date and number in `content/` carries `sources:` with a URL and the date you checked it. A claim without a source can't be merged.
- **No invented quotes.** Paraphrase, and never put words in a real person's mouth.
- **Framing.** The project tells the story from the Israeli perspective. Contested narratives are not shown as parallel accounts.
diff --git a/README.he.md b/README.he.md
index 1ab4c39ac..a2a39c50c 100644
--- a/README.he.md
+++ b/README.he.md
@@ -69,7 +69,7 @@
## איך משתתפים
-מתכנתים, היסטוריונים, אמנים, מעצבי משחק, כותבים ומתרגמים: התחילו ב־[<span dir="ltr">CONTRIBUTING.md</span>](CONTRIBUTING.md) (באנגלית). אפשר לעבוד גם עם בינה מלאכותית, בתנאי שמצהירים על כך ושכל טענה היסטורית נבדקה מול מקור. אין הסכם CLA: תרומות נכנסות תחת הרישיונות של המאגר. מחפשים משימה ראשונה? ראו את הסינון [good first issue](https://github.com/eyalgolan/statecraft-israel/labels/good%20first%20issue), את [help wanted](https://github.com/eyalgolan/statecraft-israel/labels/help%20wanted) ואת [הבעיות הפתוחות](https://github.com/eyalgolan/statecraft-israel/issues).
+מתכנתים, היסטוריונים, אמנים, מעצבי משחק, כותבים ומתרגמים: התחילו ב־[<span dir="ltr">CONTRIBUTING.md</span>](CONTRIBUTING.md) (באנגלית). להוספת אירוע היסטורי ראו [<span dir="ltr">docs/WRITING_EVENTS.md</span>](docs/WRITING_EVENTS.md) (באנגלית). אפשר לעבוד גם עם בינה מלאכותית, בתנאי שמצהירים על כך ושכל טענה היסטורית נבדקה מול מקור. אין הסכם CLA: תרומות נכנסות תחת הרישיונות של המאגר. מחפשים משימה ראשונה? ראו את הסינון [good first issue](https://github.com/eyalgolan/statecraft-israel/labels/good%20first%20issue), את [help wanted](https://github.com/eyalgolan/statecraft-israel/labels/help%20wanted) ואת [הבעיות הפתוחות](https://github.com/eyalgolan/statecraft-israel/issues).
### עבודה עם סוכן בינה מלאכותית ב־Unity (<span dir="ltr">Unity-MCP</span>)
diff --git a/README.md b/README.md
index f4096fd9d..468704b21 100644
--- a/README.md
+++ b/README.md
@@ -105,6 +105,7 @@ Help is very welcome:
Before you start:
- Read [docs/dev-setup.md](docs/dev-setup.md).
- Run the tests listed in [CONTRIBUTING.md](CONTRIBUTING.md).
+- Adding a historical event? Read [docs/WRITING_EVENTS.md](docs/WRITING_EVENTS.md).
- Keep game rules in the sim, not in Unity.
- Working in Unity with an AI agent? Use the bundled Unity-MCP plugin in local Custom mode; the steps are in [CONTRIBUTING.md](CONTRIBUTING.md).
diff --git a/docs/WRITING_EVENTS.md b/docs/WRITING_EVENTS.md
new file mode 100644
index 000000000..e892ee7e2
--- /dev/null
+++ b/docs/WRITING_EVENTS.md
@@ -0,0 +1,248 @@
+# Writing an event
+
+An event is one YAML file in `content/events/`. The game shows it as a card with two or more options; each option
+moves some numbers. This guide takes you from an empty file to a passing test run. Everything here was checked
+against the loader (`sim/Statecraft.Sim/ContentLoader.cs`, `EventRules.cs`, `Content.cs`, `ReleaseGate.cs`); if the
+code and this page disagree, the code wins and the page has a bug (please open an issue).
+
+Read [docs/CONTENT_POLICY.md](CONTENT_POLICY.md) first. It is the contract for sources, quotes and sensitive
+topics. The worked example below is [content/events/hula_drainage.yaml](../content/events/hula_drainage.yaml).
+
+## The shortest path
+
+1. Find your sources and write down, for each fact, a URL and the date you opened it.
+2. Copy `hula_drainage.yaml` to `content/events/<your_id>.yaml` and edit it. The file name is free, but use the id.
+3. Run `dotnet test sim/Statecraft.sln` (see "Running the tests").
+4. Add a line to `CHANGELOG.md` under `## [Unreleased]`, and open a pull request.
+
+## Fields
+
+The loader is strict. An unknown key is an error, so a typo such as `titel:` fails loudly instead of being ignored.
+A key written with no value (`tags:`) is an error for lists.
+
+| Field | Required | What it is |
+|---|---|---|
+| `id` | yes | Unique across all events. Lowercase letters, digits and underscores, starting with a letter. |
+| `title` | yes | The card title. May contain office placeholders. |
+| `text` | yes | The card body. May contain office placeholders. |
+| `anchor` | no (default `soft`) | `hard` or `soft`. See below. |
+| `tags` | no | A list of free-form labels. Four are sensitive. See below. |
+| `office` | no | The office id of the minister the event goes to when the player does not answer it. |
+| `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. |
+| `options` | yes | One or more options. See below. |
+| `sources` | no by the loader, yes by the rules | A list of `{ url, checked }`. See below. |
+| `status` | no (default `draft`) | The review status. See below. |
+
+### id, title, text and placeholders
+
+Never type a real person's name into `title`, `text` or an option's `text`. Write an office id in braces, such as
+`{prime_minister}`, and the game replaces it with whoever holds that office on the day the event fires (and with the
+player's own appointment, if the player changed the cabinet). In the example, `{prime_minister} must decide.` becomes
+the name of the Prime Minister on the day. Office ids are in `content/offices.yaml`; who held them is in
+`content/people.yaml`.
+
+Rules the loader enforces:
+
+- Placeholders may use only lowercase letters, digits and underscores, and must name a real office.
+- Any other `{` or `}` is an error (no braces for emphasis).
+- The office must have a holder on **every day of the window** (`from` up to `to`). If the office is vacant for even
+ a day, or the window is open-ended and the last holder's term ends, loading fails and the message gives the date.
+- If the window has already closed when the event reaches the player (it can fire late), the names are filled in for
+ the last day of the window.
+
+Write plain description. Do not put words in anyone's mouth: no invented quotes
+([CONTENT_POLICY.md](CONTENT_POLICY.md), section 2).
+
+### anchor
+
+- `soft`: an event that may or may not fire. At most 3 non-hard events fire per turn (the earliest `from` first, then
+ by id), so a soft event can wait for a later turn inside its window.
+- `hard`: an event that must happen. Every eligible hard event fires. It needs one option marked `historical: true`;
+ in Historical mode, if the player leaves it unanswered it resolves to that option.
+
+### tags and the sensitive review
+
+Tags are free-form, but these four are sensitive (checked without regard to case): `holocaust`, `terror`, `massacre`,
+`war-casualties`. An event with any of them:
+
+- cannot give a positive `treasury` or `fx_reserves` delta in any option (the loader refuses: it would reward the
+ atrocity);
+- needs `status: sensitivity-reviewed` before any build is shared. That status is set by the maintainer, not by you.
+ Submit it as `fact-checked`. `Statecraft.Cli --release-gate`, the `-shareable` build and `tools/package_release.py`
+ refuse to release while any sensitive event is not `sensitivity-reviewed`, and a test requires every sensitive event
+ in `content/` to carry exactly that status once reviewed.
+
+The other tag used so far is `security`. It has no rule attached.
+
+### office
+
+The office id (for example `defense_minister`) of the minister who answers the event if the player does not. The
+minister picks the option marked `recommended` with a probability equal to their competence divided by 10, and
+otherwise picks at random. With no `office`, a middling competence of 5 is used. An unknown office is an error.
+
+### from and to
+
+The window is half-open: the event can fire from `from` up to, not including, `to`. It fires on the first turn that
+overlaps the window. A turn is a week, a month or a quarter, depending on the period, so a window shorter than a turn can still
+fire, late. Put a comment above `from` saying why you chose the date, as the example does. The loader only requires
+`from`, and that `to` is later than `from`.
+
+### conditions
+
+Optional bounds on indicators (`morale`, `food_supply`, `housing`, `security`, `intl_standing`, the ids in
+`content/model.yaml`), each a value from 0 to 1:
+
+```yaml
+conditions:
+ - { indicator: morale, max: 0.4 }
+```
+
+`min` and `max` are both optional, and `min` must not exceed `max`. Not every event needs this; the example has none.
+
+### requires
+
+```yaml
+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.
+
+### options
+
+Each option has:
+
+| Field | Required | What it is |
+|---|---|---|
+| `id` | yes | Unique within the event. Same shape as an event id. |
+| `text` | yes in practice | What the player reads on the button. May use placeholders. |
+| `historical` | no (default false) | `true` on the option that matches what really happened. At most one per event. |
+| `recommended` | no (default false) | The option a competent minister picks when the event is delegated. |
+| `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. |
+
+An event needs at least one option. `historical` is a statement of fact and needs a source; `recommended` is a game
+design choice and does not.
+
+### effects
+
+`target` is one of:
+
+- an indicator id from `content/model.yaml`: `morale`, `food_supply`, `housing`, `security`, `intl_standing`. These
+ live between 0 and 1, so a delta of `0.03` is three points of the scale. Keep deltas small, as the example does;
+- `treasury` or `fx_reserves`, in game money.
+
+`delta` must be a finite number. Any other target is an error. Policy ids (`rationing`, ...) are not effect targets;
+use `set_policy` for those.
+
+### sources
+
+```yaml
+sources:
+ - { url: "https://history.state.gov/historicaldocuments/frus1951v05/d288", checked: 2026-10-10 }
+```
+
+The loader reads `sources` but does not check it. The tests do: every event in `content/` must have at least one,
+each URL must start with `https://`, and `checked` must be on or after 2026-10-09 (the date of the content check).
+Use the day you actually opened the page. A source must support the claim it is attached to
+([CONTENT_POLICY.md](CONTENT_POLICY.md), section 2). Paraphrase; do not quote unless you give the quote verbatim.
+
+### status
+
+One of `draft`, `fact-checked`, `historian-reviewed`, `sensitivity-reviewed`; anything else is an error.
+
+- `draft`: a work in progress. A pull request for `content/` should not stay at this.
+- `fact-checked`: a person checked every claim against its sources. This is what you submit. The content tests
+ require `fact-checked` on every non-sensitive event in `content/`.
+- `historian-reviewed`: planned for M4, not a gate yet.
+- `sensitivity-reviewed`: set by the maintainer for events with a sensitive tag (see above).
+
+If AI helped draft the text, you still check every claim yourself before using `fact-checked`
+([CONTENT_POLICY.md](CONTENT_POLICY.md), section 2, rule 6).
+
+## What the loader rejects
+
+Errors are printed as `file: field: message`. These are the messages you are most likely to see:
+
+| Message contains | Cause |
+|---|---|
+| `Property 'x' not found on type 'Statecraft.Sim.GameEvent'` | A key the loader does not know (usually a typo). Not a field of the event. |
+| `must be lowercase letters, digits and underscores, starting with a letter` | An event or option `id` of the wrong shape (for example `Continue-Works`). |
+| `duplicate event id` | Another file already uses this `id`. |
+| `duplicate option id` | Two options share an `id`. |
+| `unknown anchor` | `anchor` is not `hard` or `soft`. |
+| `unknown status` | `status` is not one of the four values. |
+| `must be after from` | `to` is on or before `from`. |
+| `unknown office '` | `office` is not an office id. |
+| `unknown office placeholder` | `{something}` is not an office id. |
+| `stray '{' or '}' outside an {office_id} placeholder` | A brace that is not a placeholder. |
+| `has no holder on` | A placeholder office is vacant on a day inside the window. |
+| `unknown indicator` | A `conditions` entry names an indicator that does not exist. |
+| `at least one option required` | `options` is empty. |
+| `at most one option can be historical` | Two options have `historical: true`. |
+| `hard anchor needs a historical option` | `anchor: hard` and no option is `historical`. |
+| `unknown target` | An effect `target` is neither an indicator nor `treasury` or `fx_reserves`. |
+| `sensitive events cannot reward` | A sensitive-tagged event with a positive `treasury` or `fx_reserves` delta. |
+| `must be 1-5` | `set_rung` outside 1 to 5. |
+| `unknown policy` | `set_policy` names a policy that does not exist. |
+| `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. |
+| `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. |
+
+A full message looks like this (an effect target misspelled `securty`):
+
+```
+Content error: events/hula_drainage.yaml: events[hula_drainage].options[continue_works].effects.securty: unknown target
+```
+
+## Running the tests
+
+From the repository root, with the .NET SDK installed ([dev-setup.md](dev-setup.md)):
+
+```
+dotnet test sim/Statecraft.sln
+```
+
+This loads all of `content/`, so any error above shows up here, and it must finish with 0 warnings. To run only the
+checks on real content: `dotnet test sim/Statecraft.sln --filter RealContentTests`. To check the sensitive-review
+gate by hand:
+
+```
+dotnet run --project sim/Statecraft.Cli -- --release-gate
+```
+
+The Python checks (`uv run --with pytest==9.1.1 --with pyyaml==6.0.3 pytest scripts/oss/tests -q`, and
+`uv run scripts/oss/check_repo.py`) cover repository policy. They include a test that keeps this guide's field table
+in line with the loader.
+
+## A golden-hash change
+
+`docs/determinism.md` pins two hashes of complete playthroughs (the "golden runs", to 1950-01-01 and to 1952-01-01).
+They are computed from the real `content/`, so **an event whose window falls inside a golden run changes the hash**,
+and the determinism tests then fail with the old and new value. That is expected, not a bug in your event. An event
+that opens after 1952-01-01 does not move them.
+
+How to tell:
+
+- The failing test is `GoldenPlaythroughHashIsFixed` or `GoldenPlaythroughTo1952HashIsFixed` (in `DeterminismTests`),
+ it shows two 64-character hashes, and nothing else fails: your event moved the golden. Say so in your pull request, and do not edit the hash constants yourself.
+- If other tests fail, or a hash moves when you changed no event window, effect or option, that is a real problem;
+ fix it first.
+
+The maintainer rebaselines: they update `GoldenRun.cs`, `DeterminismTests.cs` and `docs/determinism.md` together, and add
+a row to its "Rebaseline history". Contributors do not.
+
+## Checklist
+
+- [ ] `id` unique and lowercase; `title` and `text` use `{office}` placeholders, no hard-coded names
+- [ ] `from` has a comment explaining the date; `to` is after it
+- [ ] every fact has a `https://` source with the day you checked it
+- [ ] at most one `historical` option; `hard` events have one
+- [ ] no invented quotes; sensitive tags only where they apply, `status: fact-checked`
+- [ ] `dotnet test sim/Statecraft.sln` passes
+- [ ] a line in `CHANGELOG.md`
diff --git a/scripts/oss/tests/test_writing_events.py b/scripts/oss/tests/test_writing_events.py
new file mode 100644
index 000000000..6705dc3be
--- /dev/null
+++ b/scripts/oss/tests/test_writing_events.py
@@ -0,0 +1,68 @@
+"""docs/WRITING_EVENTS.md must stay true to the loader: every field its tables list is a property the C# types
+accept, every property is listed, and every error message it quotes exists in the sim source."""
+import re
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[3]
+GUIDE = (ROOT / "docs/WRITING_EVENTS.md").read_text(encoding="utf-8")
+SIM = ROOT / "sim/Statecraft.Sim"
+
+
+def snake(name: str) -> str:
+ return re.sub(r"(?<!^)(?=[A-Z])", "_", name).lower()
+
+
+def yaml_keys(cls: str) -> set[str]:
+ """The keys the YAML loader accepts for a class: its public settable properties, minus [YamlIgnore] ones."""
+ src = (SIM / "Content.cs").read_text(encoding="utf-8")
+ body = re.search(rf"class {cls}\b.*?\n }}", src, re.S) or re.search(rf"class {cls}\b[^\n]*\{{.*?\}}\s*(?:\n|$)", src, re.S)
+ assert body, cls
+ keys = set()
+ for line in body.group(0).splitlines():
+ m = re.search(r"public [\w<>?, ]+ (\w+) \{ get; set; \}", line)
+ if m and "[YamlIgnore]" not in line:
+ keys.add(snake(m.group(1)))
+ return keys
+
+
+def table_keys(heading: str) -> set[str]:
+ """First-column `names` of the table that follows the heading, up to the next heading."""
+ section = GUIDE.split(heading, 1)[1]
+ section = re.split(r"\n#{2,3} ", section, maxsplit=1)[0]
+ return set(re.findall(r"^\| `(\w+)` \|", section, re.M))
+
+
+def test_event_field_table_matches_the_loader():
+ assert table_keys("\n## Fields") == yaml_keys("GameEvent")
+
+
+def test_option_field_table_matches_the_loader():
+ assert table_keys("\n### options") == yaml_keys("EventOption")
+
+
+def test_every_quoted_error_exists_in_the_sim_source():
+ section = GUIDE.split("\n## What the loader rejects", 1)[1].split("\n## ", 1)[0]
+ fragments = re.findall(r"^\| (.+?) \| .+ \|$", section, re.M)[1:]
+ fragments = [f for f in fragments if not f.startswith("---")]
+ assert len(fragments) > 15
+ source = "\n".join(p.read_text(encoding="utf-8") for p in SIM.glob("*.cs"))
+ for f in fragments:
+ # `Property 'x' not found...` comes from YamlDotNet, not from this repo's source
+ if f.startswith("`Property"):
+ continue
+ text = f.strip("`")
+ assert text in source, f"guide quotes an error the code does not contain: {text!r}"
+
+
+def test_status_values_match_the_loader():
+ src = (SIM / "ContentLoader.cs").read_text(encoding="utf-8")
+ values = re.search(r"Statuses = new HashSet<string> \{(.*?)\}", src, re.S).group(1)
+ for v in re.findall(r'"([\w-]+)"', values):
+ assert f"`{v}`" in GUIDE, v
+
+
+def test_sensitive_tags_match_the_release_gate():
+ src = (SIM / "EventRules.cs").read_text(encoding="utf-8")
+ tags = re.search(r"SensitiveTags = .*?\{(.*?)\};", src, re.S).group(1)
+ for t in re.findall(r'"([\w-]+)"', tags):
+ assert f"`{t}`" in GUIDE, t