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.

fix(sim): a hard-anchor event must have a historical option

eyalgolanfb142e69b10b
diff --git a/sim/Statecraft.Sim.Tests/EventTests.cs b/sim/Statecraft.Sim.Tests/EventTests.cs
index bc4226619..ee21cd7e0 100644
--- a/sim/Statecraft.Sim.Tests/EventTests.cs
+++ b/sim/Statecraft.Sim.Tests/EventTests.cs
@@ -253,6 +253,24 @@ options:
Assert.Equal("events[shortage].options[import].effects.treasury", ex.Field);
}
+ [Fact]
+ public void HardAnchorNeedsAHistoricalOption()
+ {
+ var bad = Shortage.Replace("office: finance_minister", "anchor: hard\noffice: finance_minister")
+ .Replace(" historical: true\n", "");
+ var ex = Assert.Throws<ContentException>(() => Load(new Dictionary<string, string> { ["shortage.yaml"] = bad }));
+ Assert.Equal("events/shortage.yaml", ex.File);
+ Assert.Equal("events[shortage].options", ex.Field);
+ Assert.Contains("hard anchor needs a historical option", ex.Message);
+ }
+
+ [Fact]
+ public void HardAnchorWithAHistoricalOptionLoads()
+ {
+ var ok = Shortage.Replace("office: finance_minister", "anchor: hard\noffice: finance_minister");
+ Assert.Equal("hard", Load(new Dictionary<string, string> { ["shortage.yaml"] = ok }).Events.Single().Anchor);
+ }
+
[Fact]
public void PlaceholderMustBeAnOffice()
{
diff --git a/sim/Statecraft.Sim/EventRules.cs b/sim/Statecraft.Sim/EventRules.cs
index 63aead27e..ccd37d1d8 100644
--- a/sim/Statecraft.Sim/EventRules.cs
+++ b/sim/Statecraft.Sim/EventRules.cs
@@ -25,6 +25,7 @@ namespace Statecraft.Sim
if (!indicators.Contains(cond.Indicator)) throw new ContentException(e.File, F($"conditions.{cond.Indicator}"), "unknown indicator");
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");
+ if (e.Anchor == "hard" && !e.Options.Any(o => o.Historical)) throw new ContentException(e.File, F("options"), "hard anchor needs a historical option");
bool sensitive = e.Tags.Any(SensitiveTags.Contains);
var optionIds = new HashSet<string>();
foreach (var o in e.Options)