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.

feat(sim): content schema, strict loader, reference validation

eyalgolanf255d1e0596d
diff --git a/sim/Statecraft.Sim.Tests/ContentLoaderTests.cs b/sim/Statecraft.Sim.Tests/ContentLoaderTests.cs
new file mode 100644
index 000000000..90e631089
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/ContentLoaderTests.cs
@@ -0,0 +1,82 @@
+using System.Collections.Generic;
+using Statecraft.Sim;
+
+public class ContentLoaderTests
+{
+ [Fact]
+ public void LoadsValidFixture()
+ {
+ var c = ContentLoader.Load(Fixture.Write());
+ Assert.Equal(2, c.Parties.Count);
+ Assert.Equal(2, c.People.Count);
+ Assert.Equal(10, c.Legislatures[1].Size);
+ Assert.Equal(2, c.Effects.Count);
+ Assert.Equal(5, c.Rules.StartRung);
+ }
+
+ [Fact]
+ public void UnknownPartyInSeatsNamesFileAndField()
+ {
+ var bad = Fixture.Files["legislatures.yaml"].Replace("beta: 6", "gamma: 6");
+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["legislatures.yaml"] = bad })));
+ Assert.Equal("legislatures.yaml", ex.File);
+ Assert.Equal("legislatures[house].seats.gamma", ex.Field);
+ }
+
+ [Fact]
+ public void SeatsMustSumToSize()
+ {
+ var bad = Fixture.Files["legislatures.yaml"].Replace("size: 10", "size: 11");
+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["legislatures.yaml"] = bad })));
+ Assert.Equal("legislatures[house].size", ex.Field);
+ }
+
+ [Fact]
+ public void UnknownYamlPropertyIsAnError()
+ {
+ var bad = Fixture.Files["parties.yaml"].Replace("name: Beta", "nmae: Beta");
+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["parties.yaml"] = bad })));
+ Assert.Equal("parties.yaml", ex.File);
+ }
+
+ [Fact]
+ public void EffectTargetMustBeAnIndicator()
+ {
+ var bad = Fixture.Files["model.yaml"].Replace("target: morale", "target: moral");
+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["model.yaml"] = bad })));
+ Assert.Equal("effects[rationing_morale].target", ex.Field);
+ }
+
+ [Fact]
+ public void PersonOfficeMustExist()
+ {
+ var bad = Fixture.Files["people.yaml"].Replace("office: finance_minister", "office: treasury_boss");
+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["people.yaml"] = bad })));
+ Assert.Equal("people[def_two].offices.treasury_boss", ex.Field);
+ }
+
+ [Fact]
+ public void OfficeTermEndingBeforeItStartsIsAnError()
+ {
+ var bad = Fixture.Files["people.yaml"].Replace("to: 1949-01-01", "to: 1947-01-01");
+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["people.yaml"] = bad })));
+ Assert.Equal("people.yaml", ex.File);
+ Assert.Equal("people[pm_one].offices.defense_minister", ex.Field);
+ }
+
+ [Theory]
+ [InlineData("offices.yaml", "id: finance_minister", "id: defense_minister", "offices[defense_minister].id")]
+ [InlineData("parties.yaml", "id: beta", "id: alpha", "parties[alpha].id")]
+ [InlineData("people.yaml", "id: def_two", "id: pm_one", "people[pm_one].id")]
+ [InlineData("legislatures.yaml", "id: house", "id: council", "legislatures[council].id")]
+ [InlineData("governments.yaml", "id: gov2", "id: gov1", "governments[gov1].id")]
+ [InlineData("model.yaml", "id: food_supply", "id: morale", "indicators[morale].id")]
+ [InlineData("model.yaml", "id: rationing\n default", "id: morale\n default", "policies[morale].id")]
+ public void DuplicateIdIsAnError(string file, string original, string duplicate, string field)
+ {
+ var bad = Fixture.Files[file].Replace(original, duplicate);
+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { [file] = bad })));
+ Assert.Equal(file, ex.File);
+ Assert.Equal(field, ex.Field);
+ }
+}
diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.cs
new file mode 100644
index 000000000..b51978b2c
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/Fixture.cs
@@ -0,0 +1,152 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+/// <summary>Writes a small, valid content set to a temp dir. Tests override single files to test errors.</summary>
+public static class Fixture
+{
+ public static readonly Dictionary<string, string> Files = new Dictionary<string, string>
+ {
+ ["offices.yaml"] = @"
+offices:
+ - id: prime_minister
+ title: Prime Minister
+ - id: defense_minister
+ title: Minister of Defense
+ - id: finance_minister
+ title: Minister of Finance
+",
+ ["parties.yaml"] = @"
+parties:
+ - id: alpha
+ name: Alpha
+ - id: beta
+ name: Beta
+",
+ ["people.yaml"] = @"
+people:
+ - id: pm_one
+ name: Pm One
+ living: false
+ competence: 8
+ loyalty: 9
+ offices:
+ - office: prime_minister
+ from: 1948-05-14
+ - office: defense_minister
+ from: 1948-05-14
+ to: 1949-01-01
+ - id: def_two
+ name: Def Two
+ living: false
+ competence: 4
+ loyalty: 5
+ offices:
+ - office: defense_minister
+ from: 1949-01-01
+ - office: finance_minister
+ from: 1948-05-14
+",
+ ["legislatures.yaml"] = @"
+legislatures:
+ - id: council
+ body: Council
+ from: 1948-05-14
+ to: 1949-02-14
+ size: 5
+ budget_approval: false
+ seats: { alpha: 3, beta: 2 }
+ - id: house
+ body: House
+ from: 1949-02-14
+ size: 10
+ budget_approval: true
+ seats: { alpha: 4, beta: 6 }
+",
+ ["governments.yaml"] = @"
+governments:
+ - id: gov1
+ name: Government One
+ from: 1948-05-14
+ to: 1949-03-10
+ coalition: [alpha]
+ - id: gov2
+ name: Government Two
+ from: 1949-03-10
+ coalition: [alpha, beta]
+",
+ ["model.yaml"] = @"
+indicators:
+ - id: morale
+ base: 0.5
+ - id: food_supply
+ base: 0.4
+policies:
+ - id: rationing
+ default: 0.0
+ office: finance_minister
+effects:
+ - id: rationing_food
+ source: rationing
+ target: food_supply
+ k: 0.4
+ inertia: 2
+ office: finance_minister
+ - id: rationing_morale
+ source: rationing
+ target: morale
+ k: -0.2
+ inertia: 1
+situations:
+ - id: hunger
+ indicator: food_supply
+ on_below: 0.3
+ off_above: 0.45
+voter_groups:
+ - id: everyone
+ weights: { morale: 1.0 }
+actors:
+ - id: usa
+ name: United States
+ standing: 0.5
+",
+ ["rules.yaml"] = @"
+start: 1948-05-15
+start_rung: 5
+attention_per_turn: 3
+attention_cost: { set_policy: 1, allocate_budget: 1, choose_event_option: 1, set_mobilization: 1, security_order: 1 }
+rung_attention_step: 0.25
+ceasefire_weeks: 4
+treasury_start: 100
+fx_start: 50
+tax_per_capita_per_year: 0.0004
+spending_per_capita_per_year: 0.0005
+exports_per_year: 20
+imports_per_capita_per_year: 0.0001
+mobilization_cost_per_year: 40
+natural_increase_per_year: 0.017
+initial_population: { veterans: 1000 }
+budget_start: { finance_minister: 1.0 }
+",
+ ["population.yaml"] = @"
+anchors: []
+",
+ ["aliyah.yaml"] = @"
+series:
+ - from: 1948-05-15
+ to: 1948-12-31
+ origins: { europe: 230, asia: 0 }
+",
+ };
+
+ public static string Write(Dictionary<string, string>? overrides = null, Dictionary<string, string>? events = null)
+ {
+ var dir = Path.Combine(Path.GetTempPath(), "statecraft-fixture-" + Guid.NewGuid().ToString("N"));
+ Directory.CreateDirectory(Path.Combine(dir, "events"));
+ foreach (var kv in Files)
+ File.WriteAllText(Path.Combine(dir, kv.Key), overrides != null && overrides.TryGetValue(kv.Key, out var o) ? o : kv.Value);
+ if (events != null)
+ foreach (var kv in events) File.WriteAllText(Path.Combine(dir, "events", kv.Key), kv.Value);
+ return dir;
+ }
+}
diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.cs
new file mode 100644
index 000000000..fea47a992
--- /dev/null
+++ b/sim/Statecraft.Sim/Content.cs
@@ -0,0 +1,190 @@
+using System;
+using System.Collections.Generic;
+
+namespace Statecraft.Sim
+{
+ // Plain data classes filled by YamlDotNet (UnderscoredNamingConvention: SeatsByParty <- seats_by_party).
+
+ public sealed class Source { public string Url { get; set; } = ""; public DateTime Checked { get; set; } }
+
+ public sealed class Office { public string Id { get; set; } = ""; public string Title { get; set; } = ""; }
+
+ public sealed class Party { public string Id { get; set; } = ""; public string Name { get; set; } = ""; }
+
+ public sealed class OfficeTerm
+ {
+ public string Office { get; set; } = "";
+ public DateTime From { get; set; }
+ public DateTime? To { get; set; }
+ public List<Source> Sources { get; set; } = new List<Source>();
+ }
+
+ public sealed class Portrait { public string File { get; set; } = ""; public string License { get; set; } = ""; public string Source { get; set; } = ""; }
+
+ public sealed class Person
+ {
+ public string Id { get; set; } = "";
+ public string Name { get; set; } = "";
+ public string NameHe { get; set; } = "";
+ public bool Living { get; set; }
+ public int Competence { get; set; }
+ public int Loyalty { get; set; }
+ public string Party { get; set; } = "";
+ public Portrait? Portrait { get; set; }
+ public List<OfficeTerm> Offices { get; set; } = new List<OfficeTerm>();
+ public string Status { get; set; } = "draft";
+ }
+
+ public sealed class Legislature
+ {
+ public string Id { get; set; } = "";
+ public string Body { get; set; } = "";
+ public DateTime From { get; set; }
+ public DateTime? To { get; set; }
+ public int Size { get; set; }
+ public bool BudgetApproval { get; set; }
+ public Dictionary<string, int> Seats { get; set; } = new Dictionary<string, int>();
+ public List<Source> Sources { get; set; } = new List<Source>();
+ public string Status { get; set; } = "draft";
+ }
+
+ public sealed class Government
+ {
+ public string Id { get; set; } = "";
+ public string Name { get; set; } = "";
+ public DateTime From { get; set; }
+ public DateTime? To { get; set; }
+ public List<string> Coalition { get; set; } = new List<string>();
+ public List<Source> Sources { get; set; } = new List<Source>();
+ public string Status { get; set; } = "draft";
+ }
+
+ public sealed class Indicator { public string Id { get; set; } = ""; public double Base { get; set; } }
+
+ public sealed class Policy
+ {
+ public string Id { get; set; } = "";
+ public double Default { get; set; }
+ public string Office { get; set; } = "";
+ }
+
+ /// <summary>Additive effect: its contribution to Target moves toward K * source value over Inertia turns.</summary>
+ public sealed class Effect
+ {
+ public string Id { get; set; } = "";
+ public string Source { get; set; } = "";
+ public string Target { get; set; } = "";
+ public double K { get; set; }
+ public int Inertia { get; set; } = 1;
+ public string Office { get; set; } = "";
+ }
+
+ /// <summary>Turns on past one threshold and off past another (hysteresis), so it does not flicker.</summary>
+ public sealed class Situation
+ {
+ public string Id { get; set; } = "";
+ public string Indicator { get; set; } = "";
+ public double? OnBelow { get; set; }
+ public double? OffAbove { get; set; }
+ public double? OnAbove { get; set; }
+ public double? OffBelow { get; set; }
+ }
+
+ public sealed class VoterGroup { public string Id { get; set; } = ""; public Dictionary<string, double> Weights { get; set; } = new Dictionary<string, double>(); }
+
+ public sealed class Actor { public string Id { get; set; } = ""; public string Name { get; set; } = ""; public double Standing { get; set; } }
+
+ public sealed class Rules
+ {
+ public DateTime Start { get; set; }
+ public int StartRung { get; set; } = 1;
+ public double AttentionPerTurn { get; set; }
+ public Dictionary<string, double> AttentionCost { get; set; } = new Dictionary<string, double>();
+ public double RungAttentionStep { get; set; }
+ public int CeasefireWeeks { get; set; }
+ public double TreasuryStart { get; set; }
+ public double FxStart { get; set; }
+ public double TaxPerCapitaPerYear { get; set; }
+ public double SpendingPerCapitaPerYear { get; set; }
+ public double ExportsPerYear { get; set; }
+ public double ImportsPerCapitaPerYear { get; set; }
+ public double MobilizationCostPerYear { get; set; }
+ public double NaturalIncreasePerYear { get; set; }
+ public Dictionary<string, double> InitialPopulation { get; set; } = new Dictionary<string, double>();
+ public Dictionary<string, double> BudgetStart { get; set; } = new Dictionary<string, double>();
+ }
+
+ public sealed class AliyahPeriod
+ {
+ public DateTime From { get; set; }
+ public DateTime To { get; set; }
+ public Dictionary<string, double> Origins { get; set; } = new Dictionary<string, double>();
+ public List<Source> Sources { get; set; } = new List<Source>();
+ public string Status { get; set; } = "draft";
+ }
+
+ public sealed class PopulationAnchor
+ {
+ public DateTime Date { get; set; }
+ public double Jews { get; set; }
+ public List<Source> Sources { get; set; } = new List<Source>();
+ public string Status { get; set; } = "draft";
+ }
+
+ public sealed class EventCondition { public string Indicator { get; set; } = ""; public double? Min { get; set; } public double? Max { get; set; } }
+
+ public sealed class OptionEffect { public string Target { get; set; } = ""; public double Delta { get; set; } }
+
+ public sealed class EventOption
+ {
+ public string Id { get; set; } = "";
+ public string Text { get; set; } = "";
+ public bool Historical { get; set; }
+ public bool Recommended { get; set; }
+ public List<OptionEffect> Effects { get; set; } = new List<OptionEffect>();
+ public int? SetRung { get; set; }
+ }
+
+ public sealed class GameEvent
+ {
+ public string Id { get; set; } = "";
+ public string Title { get; set; } = "";
+ public string Text { get; set; } = "";
+ public List<string> Tags { get; set; } = new List<string>();
+ public string Anchor { get; set; } = "soft";
+ public string Office { get; set; } = "";
+ public DateTime From { get; set; }
+ public DateTime? To { get; set; }
+ public List<EventCondition> Conditions { get; set; } = new List<EventCondition>();
+ public List<EventOption> Options { get; set; } = new List<EventOption>();
+ public List<Source> Sources { get; set; } = new List<Source>();
+ public string Status { get; set; } = "draft";
+ }
+
+ public sealed class Content
+ {
+ public List<Office> Offices = new List<Office>();
+ public List<Party> Parties = new List<Party>();
+ public List<Person> People = new List<Person>();
+ public List<Legislature> Legislatures = new List<Legislature>();
+ public List<Government> Governments = new List<Government>();
+ public List<Indicator> Indicators = new List<Indicator>();
+ public List<Policy> Policies = new List<Policy>();
+ public List<Effect> Effects = new List<Effect>();
+ public List<Situation> Situations = new List<Situation>();
+ public List<VoterGroup> VoterGroups = new List<VoterGroup>();
+ public List<Actor> Actors = new List<Actor>();
+ public Rules Rules = new Rules();
+ public List<AliyahPeriod> Aliyah = new List<AliyahPeriod>();
+ public List<PopulationAnchor> PopulationAnchors = new List<PopulationAnchor>();
+ public List<GameEvent> Events = new List<GameEvent>();
+ }
+
+ public sealed class ContentException : Exception
+ {
+ public string File { get; }
+ public string Field { get; }
+ public ContentException(string file, string field, string message) : base($"{file}: {field}: {message}")
+ { File = file; Field = field; }
+ }
+}
diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.cs
new file mode 100644
index 000000000..e21775e52
--- /dev/null
+++ b/sim/Statecraft.Sim/ContentLoader.cs
@@ -0,0 +1,132 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using YamlDotNet.Core;
+using YamlDotNet.Serialization;
+using YamlDotNet.Serialization.NamingConventions;
+
+namespace Statecraft.Sim
+{
+ public static class ContentLoader
+ {
+ sealed class OfficesFile { public List<Office> Offices { get; set; } = new List<Office>(); }
+ sealed class PartiesFile { public List<Party> Parties { get; set; } = new List<Party>(); }
+ sealed class PeopleFile { public List<Person> People { get; set; } = new List<Person>(); }
+ sealed class LegislaturesFile { public List<Legislature> Legislatures { get; set; } = new List<Legislature>(); }
+ sealed class GovernmentsFile { public List<Government> Governments { get; set; } = new List<Government>(); }
+ sealed class ModelFile
+ {
+ public List<Indicator> Indicators { get; set; } = new List<Indicator>();
+ public List<Policy> Policies { get; set; } = new List<Policy>();
+ public List<Effect> Effects { get; set; } = new List<Effect>();
+ public List<Situation> Situations { get; set; } = new List<Situation>();
+ public List<VoterGroup> VoterGroups { get; set; } = new List<VoterGroup>();
+ public List<Actor> Actors { get; set; } = new List<Actor>();
+ }
+ sealed class AliyahFile { public List<AliyahPeriod> Series { get; set; } = new List<AliyahPeriod>(); }
+ sealed class PopulationFile { public List<PopulationAnchor> Anchors { get; set; } = new List<PopulationAnchor>(); }
+
+ static readonly IDeserializer Yaml = new DeserializerBuilder()
+ .WithNamingConvention(UnderscoredNamingConvention.Instance)
+ .Build();
+
+ static T Read<T>(string root, string relPath)
+ {
+ var path = Path.Combine(root, relPath);
+ if (!File.Exists(path)) throw new ContentException(relPath, "(file)", "missing file");
+ try { return Yaml.Deserialize<T>(File.ReadAllText(path)) ?? throw new ContentException(relPath, "(file)", "empty file"); }
+ catch (YamlException e) { throw new ContentException(relPath, $"line {e.Start.Line}", e.InnerException?.Message ?? e.Message); }
+ }
+
+ public static Content Load(string contentRoot)
+ {
+ var c = new Content();
+ c.Offices = Read<OfficesFile>(contentRoot, "offices.yaml").Offices;
+ c.Parties = Read<PartiesFile>(contentRoot, "parties.yaml").Parties;
+ c.People = Read<PeopleFile>(contentRoot, "people.yaml").People;
+ c.Legislatures = Read<LegislaturesFile>(contentRoot, "legislatures.yaml").Legislatures;
+ c.Governments = Read<GovernmentsFile>(contentRoot, "governments.yaml").Governments;
+ var m = Read<ModelFile>(contentRoot, "model.yaml");
+ c.Indicators = m.Indicators; c.Policies = m.Policies; c.Effects = m.Effects;
+ c.Situations = m.Situations; c.VoterGroups = m.VoterGroups; c.Actors = m.Actors;
+ c.Rules = Read<Rules>(contentRoot, "rules.yaml");
+ c.Aliyah = Read<AliyahFile>(contentRoot, "aliyah.yaml").Series;
+ c.PopulationAnchors = Read<PopulationFile>(contentRoot, "population.yaml").Anchors;
+ var eventsDir = Path.Combine(contentRoot, "events");
+ if (Directory.Exists(eventsDir))
+ foreach (var f in Directory.GetFiles(eventsDir, "*.yaml").OrderBy(p => p, StringComparer.Ordinal))
+ c.Events.Add(Read<GameEvent>(contentRoot, Path.Combine("events", Path.GetFileName(f))));
+ Validate(c);
+ return c;
+ }
+
+ static void Unique(string file, string list, IEnumerable<string> ids)
+ {
+ var seen = new HashSet<string>();
+ foreach (var id in ids)
+ if (!seen.Add(id)) throw new ContentException(file, $"{list}[{id}].id", "duplicate id");
+ }
+
+ static void Validate(Content c)
+ {
+ var offices = new HashSet<string>(c.Offices.Select(o => o.Id));
+ var parties = new HashSet<string>(c.Parties.Select(p => p.Id));
+ var indicators = new HashSet<string>(c.Indicators.Select(i => i.Id));
+ var sources = new HashSet<string>(c.Policies.Select(p => p.Id).Concat(indicators));
+ Unique("offices.yaml", "offices", c.Offices.Select(o => o.Id));
+ Unique("parties.yaml", "parties", c.Parties.Select(p => p.Id));
+ Unique("people.yaml", "people", c.People.Select(p => p.Id));
+ Unique("legislatures.yaml", "legislatures", c.Legislatures.Select(l => l.Id));
+ Unique("governments.yaml", "governments", c.Governments.Select(g => g.Id));
+ Unique("model.yaml", "indicators", c.Indicators.Select(i => i.Id));
+ Unique("model.yaml", "policies", c.Policies.Select(p => p.Id));
+ Unique("model.yaml", "effects", c.Effects.Select(e => e.Id));
+ Unique("model.yaml", "situations", c.Situations.Select(s => s.Id));
+ Unique("model.yaml", "voter_groups", c.VoterGroups.Select(v => v.Id));
+ Unique("model.yaml", "actors", c.Actors.Select(a => a.Id));
+ foreach (var p in c.Policies)
+ if (indicators.Contains(p.Id)) throw new ContentException("model.yaml", $"policies[{p.Id}].id", "same id as an indicator (effect sources would be ambiguous)");
+
+ foreach (var p in c.People)
+ {
+ if (p.Party != "" && !parties.Contains(p.Party)) throw new ContentException("people.yaml", $"people[{p.Id}].party", $"unknown party '{p.Party}'");
+ foreach (var t in p.Offices)
+ {
+ if (!offices.Contains(t.Office)) throw new ContentException("people.yaml", $"people[{p.Id}].offices.{t.Office}", "unknown office");
+ if (t.To.HasValue && t.To.Value <= t.From) throw new ContentException("people.yaml", $"people[{p.Id}].offices.{t.Office}", $"term ends ({t.To:yyyy-MM-dd}) before it starts ({t.From:yyyy-MM-dd})");
+ }
+ }
+ foreach (var l in c.Legislatures)
+ {
+ foreach (var kv in l.Seats)
+ if (!parties.Contains(kv.Key)) throw new ContentException("legislatures.yaml", $"legislatures[{l.Id}].seats.{kv.Key}", "unknown party");
+ if (l.Seats.Values.Sum() != l.Size) throw new ContentException("legislatures.yaml", $"legislatures[{l.Id}].size", $"seats sum to {l.Seats.Values.Sum()}, size is {l.Size}");
+ }
+ foreach (var g in c.Governments)
+ foreach (var p in g.Coalition)
+ if (!parties.Contains(p)) throw new ContentException("governments.yaml", $"governments[{g.Id}].coalition.{p}", "unknown party");
+ foreach (var p in c.Policies)
+ if (!offices.Contains(p.Office)) throw new ContentException("model.yaml", $"policies[{p.Id}].office", $"unknown office '{p.Office}'");
+ foreach (var e in c.Effects)
+ {
+ if (!sources.Contains(e.Source)) throw new ContentException("model.yaml", $"effects[{e.Id}].source", $"unknown policy or indicator '{e.Source}'");
+ if (!indicators.Contains(e.Target)) throw new ContentException("model.yaml", $"effects[{e.Id}].target", $"unknown indicator '{e.Target}'");
+ if (e.Inertia < 1) throw new ContentException("model.yaml", $"effects[{e.Id}].inertia", "must be >= 1");
+ if (e.Office != "" && !offices.Contains(e.Office)) throw new ContentException("model.yaml", $"effects[{e.Id}].office", $"unknown office '{e.Office}'");
+ }
+ foreach (var s in c.Situations)
+ {
+ if (!indicators.Contains(s.Indicator)) throw new ContentException("model.yaml", $"situations[{s.Id}].indicator", $"unknown indicator '{s.Indicator}'");
+ bool below = s.OnBelow.HasValue && s.OffAbove.HasValue, above = s.OnAbove.HasValue && s.OffBelow.HasValue;
+ if (below == above) throw new ContentException("model.yaml", $"situations[{s.Id}]", "needs exactly one pair: on_below+off_above or on_above+off_below");
+ }
+ foreach (var v in c.VoterGroups)
+ foreach (var k in v.Weights.Keys)
+ if (!indicators.Contains(k)) throw new ContentException("model.yaml", $"voter_groups[{v.Id}].weights.{k}", "unknown indicator");
+ foreach (var k in c.Rules.BudgetStart.Keys)
+ if (!offices.Contains(k)) throw new ContentException("rules.yaml", $"budget_start.{k}", "unknown office");
+ EventRules.Validate(c, offices, indicators);
+ }
+ }
+}
diff --git a/sim/Statecraft.Sim/EventRules.cs b/sim/Statecraft.Sim/EventRules.cs
new file mode 100644
index 000000000..afe1de002
--- /dev/null
+++ b/sim/Statecraft.Sim/EventRules.cs
@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+
+namespace Statecraft.Sim
+{
+ /// <summary>Load-time checks for events. Extended in the events task.</summary>
+ static class EventRules
+ {
+ public static void Validate(Content c, HashSet<string> offices, HashSet<string> indicators) { }
+ }
+}