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: map editor diagnostics adapters for corridors, anchors, targets and objectives (Refs #1721 slice A) (#2309)

Beri669d387f83b3
diff --git a/changelog.d/1721-map-editor-adapters.md b/changelog.d/1721-map-editor-adapters.md
new file mode 100644
index 000000000..1f998b7c7
--- /dev/null
+++ b/changelog.d/1721-map-editor-adapters.md
@@ -0,0 +1,6 @@
+- Map editor (gdd-0.3 authoring envelope, Refs #1721 slice A): given the loaded content, the editor's diagnostics now
+ check corridor segments, force anchors, settlement-control targets and objective bindings, in place of their "adapter
+ unavailable" rows. The overlay's location moves apply to the targets and objective sites; corridors and anchors are
+ checked against the map. A broken binding is a blocking row that names its record (for example `targets[<id>]`);
+ nothing is moved or rerouted to fix it. Regions, fields, facilities and the base manifest stay unavailable, so
+ canonical export stays refused.
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 9fe97bfdf..0b2676444 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -581,4 +581,4 @@ R-MEDIT-001: The versioned authoring envelope changes override fields only. It c
R-MEDIT-002: Only an explicit gdd-0.3 editor context accepts the versioned envelope. Version, ruleset, draft flag, base revision/digest and all edit lists are required; unknown properties, incomplete axial coordinates and duplicate edit identities are refused. Base revision and registry references are single-line tokens without whitespace or control characters. Serialization is invariant and ordered without mutating the candidate. The authoring envelope uses a separate schema; the legacy schema stays byte-identical. Legacy parsing/serialization, content, save/state bytes and goldens remain unchanged. Failed document replacement retains both the current candidate and rejected raw input; serialized source preserves edits and provenance through Undo and domain reload.
-R-MEDIT-003: Schema validity is not semantic validation. Missing region/field/facility/corridor/anchor/target/objective adapters and an unapproved base-manifest contract are named blocking diagnostics, even for an empty candidate. Base mismatch reports both identities. This infrastructure cannot canonical-save or export, and has no runtime reader or disk writer. Integrating domain validators, persistence, offsets and the headed editor is separate work.
+R-MEDIT-003: Schema validity is not semantic validation. Given the loaded content, corridor, force-anchor, target and objective bindings are checked against the map, with the overlay's location moves applied to targets and objective sites, and a broken one is a blocking `MAPEDIT_DEPENDENCY_BROKEN` row naming its record (Q58). Without content, those four stay unavailable. Missing region/field/facility adapters and an unapproved base-manifest contract are named blocking diagnostics, even for an empty candidate. Base mismatch reports both identities. This infrastructure cannot canonical-save or export, and has no runtime reader or disk writer. Integrating domain validators, persistence, offsets and the headed editor is separate work.
diff --git a/sim/Statecraft.Sim.Tests/MapOverridesTests.cs b/sim/Statecraft.Sim.Tests/MapOverridesTests.cs
index f1ab42439..52942758b 100644
--- a/sim/Statecraft.Sim.Tests/MapOverridesTests.cs
+++ b/sim/Statecraft.Sim.Tests/MapOverridesTests.cs
@@ -355,4 +355,131 @@ public class MapOverridesTests
Assert.Equal(MapOverrides.FileName, written.File);
}
+ // R-MEDIT-003, Q58 (#1721 slice A): with the loaded content the corridor, force-anchor, target and objective adapters run
+ // against the base map plus this overlay's location moves. A broken binding is a blocking row that names its record;
+ // nothing is repaired. All records below are SYNTHETIC fixtures, not historical data.
+ static Content DependencyFixture()
+ {
+ var c = new Content
+ {
+ Hexes = new List<MapHex>
+ {
+ new MapHex { Q = 0, R = 0, Land = true, Biome = "hills" }, new MapHex { Q = 1, R = 0, Land = true, Biome = "hills" },
+ new MapHex { Q = 2, R = 0, Land = true, Biome = "hills" }, new MapHex { Q = 3, R = 0, Land = false, Biome = "sea" },
+ },
+ };
+ c.SettlementHexes.Add(new SettlementHex { Id = "town_a", Q = 0, R = 0 });
+ c.SettlementTargets.Add(new SettlementTarget { Id = "town_a", Q = 0, R = 0 });
+ c.Sites.Add(new Site { Id = "site_a", Q = 2, R = 0, Kinds = new List<string> { Projects.YishuvKind } });
+ c.Corridors.Add(new CorridorDef { Id = "corridor_a", Kind = Corridors.Rail, Segments = new List<SegmentDef>
+ {
+ new SegmentDef { To = "fixture_one", Hexes = new List<List<int>> { new List<int> { 0, 0 }, new List<int> { 1, 0 } } },
+ new SegmentDef { To = "fixture_two", Hexes = new List<List<int>> { new List<int> { 2, 0 } } },
+ } });
+ c.StartingForces.Add(new StartingForce { Row = "unit_a", Anchor = "fixture_place", Q = 1, R = 0 });
+ c.Objectives.Add(new Objective { Id = "objective_a", CompletesWhen = new ObjectiveCondition { CorridorComplete = "corridor_a" } });
+ c.Objectives.Add(new Objective { Id = "objective_b", CompletesWhen = new ObjectiveCondition { SiteBuilt = "site_a" } });
+ return c;
+ }
+
+ static readonly string[] AdaptedKinds = { "corridors", "anchors", "targets", "objectives" };
+
+ static List<MapEditorDiagnostic> Broken(IEnumerable<MapEditorDiagnostic> rows) =>
+ rows.Where(x => x.Code == "MAPEDIT_DEPENDENCY_BROKEN").ToList();
+
+ static IReadOnlyList<MapEditorDiagnostic> DependencyDiagnostics(Content c, string locations = "[]")
+ {
+ var value = MapEditorOverlay.Parse(EditorFixture.Replace("draft: true", "draft: false")
+ .Replace("locations: [] }", "locations: " + locations + " }"), SaveGame.Gdd03Ruleset);
+ return value.Diagnostics("fixture-only", new string('a', 64), c);
+ }
+
+ [Fact]
+ public void AValidOverlayHasRealAdaptersForCorridorsAnchorsTargetsAndObjectives()
+ {
+ var diagnostics = DependencyDiagnostics(DependencyFixture());
+ Assert.DoesNotContain(diagnostics, x => AdaptedKinds.Contains(x.Field));
+ Assert.Empty(Broken(diagnostics));
+ // Post-MVP adapters and the base manifest stay unavailable, so export stays refused.
+ foreach (var field in new[] { "regions", "fields", "facilities", "base_manifest" })
+ Assert.Contains(diagnostics, x => x.Code == "MAPEDIT_DEPENDENCY_UNAVAILABLE" && x.Field == field);
+ // Without the content there is nothing to check against: the four rows stay unavailable, as before.
+ var bare = MapEditorOverlay.Parse(EditorFixture, SaveGame.Gdd03Ruleset).Diagnostics("fixture-only", new string('a', 64));
+ foreach (var field in AdaptedKinds) Assert.Contains(bare, x => x.Code == "MAPEDIT_DEPENDENCY_UNAVAILABLE" && x.Field == field);
+ }
+
+ [Fact]
+ public void ABrokenCorridorEndpointBlocksWithItsIdAndTheGeometryIsUnchanged()
+ {
+ var c = DependencyFixture();
+ c.Corridors[0].Segments[1].Hexes[0] = new List<int> { 3, 0 }; // the last segment now ends on a sea hex
+ var before = c.Corridors[0].Segments.Select(x => (x.To, string.Join(";", x.Hexes.Select(h => string.Join(",", h))))).ToList();
+ var row = Assert.Single(Broken(DependencyDiagnostics(c)));
+ Assert.Equal("corridors[corridor_a]", row.Field);
+ Assert.Contains("segment 2", row.Message);
+ Assert.Equal(before, c.Corridors[0].Segments.Select(x => (x.To, string.Join(";", x.Hexes.Select(h => string.Join(",", h))))).ToList());
+ Assert.Equal(MapOverrides.FileName, row.File);
+ Assert.NotEmpty(row.Action);
+ }
+
+ [Fact]
+ public void ACorridorHexNotNextToThePreviousOneBlocks()
+ {
+ var c = DependencyFixture();
+ c.Corridors[0].Segments[0].Hexes[1] = new List<int> { 2, 0 }; // skips q=1: a land hex, but two steps from q=0
+ var row = Assert.Single(Broken(DependencyDiagnostics(c)));
+ Assert.Equal("corridors[corridor_a]", row.Field);
+ Assert.Contains("is not next to q=0 r=0", row.Message);
+ }
+
+ [Fact]
+ public void ABrokenForceAnchorBlocksWithItsId()
+ {
+ var c = DependencyFixture();
+ c.StartingForces[0].Q = 9; // off the map
+ var row = Assert.Single(Broken(DependencyDiagnostics(c)));
+ Assert.Equal("anchors[unit_a]", row.Field);
+ Assert.Equal(9, c.StartingForces[0].Q);
+ }
+
+ [Fact]
+ public void ABrokenTargetBindingBlocksWithItsId()
+ {
+ var c = DependencyFixture();
+ // Moving the target's settlement leaves the target on the old hex: its binding breaks, the target does not move.
+ var value = MapEditorOverlay.Parse(EditorFixture.Replace("draft: true", "draft: false")
+ .Replace("locations: [] }", "locations: [{ id: town_a, hex: { q: 1, r: 0 } }] }"), SaveGame.Gdd03Ruleset);
+ var row = Assert.Single(Broken(value.Diagnostics("fixture-only", new string('a', 64), c)));
+ Assert.Equal("targets[town_a]", row.Field);
+ Assert.False(value.CanExport);
+ Assert.Equal((0, 0), (c.SettlementTargets[0].Q, c.SettlementTargets[0].R));
+ }
+
+ [Fact]
+ public void RamlasTargetIsBoundToANeighbourOfItsSettlement()
+ {
+ // The loader's one exception (TargetOnANeighbour): the target sits next to the settlement, not on it.
+ var c = DependencyFixture();
+ c.Hexes.Add(new MapHex { Q = 1, R = 1, Land = true, Biome = "hills" });
+ c.SettlementHexes.Add(new SettlementHex { Id = "ramla", Q = 1, R = 0 });
+ c.SettlementTargets.Add(new SettlementTarget { Id = "ramla", Q = 0, R = 0 });
+ Assert.Empty(Broken(DependencyDiagnostics(c)));
+ // Moved two steps away, the settlement is no longer next to its target: the binding breaks, the target stays.
+ var row = Assert.Single(Broken(DependencyDiagnostics(c, "[{ id: ramla, hex: { q: 1, r: 1 } }]")));
+ Assert.Equal("targets[ramla]", row.Field);
+ Assert.Equal((0, 0), (c.SettlementTargets[1].Q, c.SettlementTargets[1].R));
+ }
+
+ [Fact]
+ public void ABrokenObjectiveBindingBlocksWithItsId()
+ {
+ var c = DependencyFixture();
+ c.Objectives[0].CompletesWhen!.CorridorComplete = "unknown_corridor";
+ var row = Assert.Single(Broken(DependencyDiagnostics(c)));
+ Assert.Equal("objectives[objective_a]", row.Field);
+ Assert.Contains("unknown_corridor", row.Message);
+ // A settlement moved onto the objective's yishuv site breaks that objective's site binding as well.
+ var moved = Broken(DependencyDiagnostics(DependencyFixture(), "[{ id: town_a, hex: { q: 2, r: 0 } }]"));
+ Assert.Contains(moved, x => x.Field == "objectives[objective_b]" && x.Message.Contains("site_a"));
+ }
}
diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.cs
index 27690deb6..4562ffb2c 100644
--- a/sim/Statecraft.Sim/ContentLoader.cs
+++ b/sim/Statecraft.Sim/ContentLoader.cs
@@ -1880,7 +1880,7 @@ namespace Statecraft.Sim
/// <summary>Targets whose capture hex is a neighbour of their settlement's hex, not that hex (owner on #1796, 26 October
/// 2026, "Contested + move target"): at 4.4 km (#1183) Ramla shares (-4, 24) with Rehovot, so a unit on Rehovot's hex
/// would capture Ramla. Its target is the neighbour nearest Ramla's point, cited in settlement_targets.yaml.</summary>
- static readonly HashSet<string> TargetOnANeighbour = new HashSet<string>(StringComparer.Ordinal) { "ramla" };
+ internal static readonly HashSet<string> TargetOnANeighbour = new HashSet<string>(StringComparer.Ordinal) { "ramla" };
/// <summary>R-CTRL-001 (Q-TGT-1 (a)): every target is an arab_town row of settlements_1948.yaml on a land hex that is
/// its own hex in settlement_hexes.yaml (capture reads the target's hex, movement the settlement's), or for a
diff --git a/sim/Statecraft.Sim/MapOverrides.cs b/sim/Statecraft.Sim/MapOverrides.cs
index 4033a51ec..fcc9ca928 100644
--- a/sim/Statecraft.Sim/MapOverrides.cs
+++ b/sim/Statecraft.Sim/MapOverrides.cs
@@ -406,9 +406,15 @@ namespace Statecraft.Sim
return text.ToString();
}
- /// <summary>Infrastructure diagnostics only. Caller supplies current base identity; this is not Content.Hash.
- /// Missing domain adapters are explicit errors, even on an empty candidate. No automatic repair is performed.</summary>
- public IReadOnlyList<MapEditorDiagnostic> Diagnostics(string currentRevision, string currentDigest)
+ /// <summary>Infrastructure diagnostics. Caller supplies current base identity; this is not Content.Hash.
+ /// Missing domain adapters are explicit errors, even on an empty candidate. With the loaded <paramref name="content"/>
+ /// the corridor, force-anchor, target and objective bindings are checked, and each broken one is a blocking row naming
+ /// its record (Q58, #1721 slice A). This overlay's location moves apply to the target and objective-site checks only;
+ /// corridors and anchors are checked against the map alone, since no overlay edit changes them. No automatic repair is
+ /// performed: no corridor, anchor, target or site is moved or rerouted.</summary>
+ /// <param name="content">The base content loaded with no editor overlay applied. Omitted, the four adapters stay
+ /// unavailable.</param>
+ public IReadOnlyList<MapEditorDiagnostic> Diagnostics(string currentRevision, string currentDigest, Content? content = null)
{
var result = new List<MapEditorDiagnostic>();
if (BaseRevision != currentRevision || BaseDigest != currentDigest)
@@ -418,11 +424,76 @@ namespace Statecraft.Sim
if (Draft == true)
result.Add(new MapEditorDiagnostic("MAPEDIT_DRAFT", "draft", "draft input cannot be canonical content",
"Resolve all diagnostics before requesting canonical export."));
- foreach (var field in new[] { "regions", "fields", "facilities", "corridors", "anchors", "targets", "objectives", "base_manifest" })
+ var unavailable = content == null
+ ? new[] { "regions", "fields", "facilities", "corridors", "anchors", "targets", "objectives", "base_manifest" }
+ : new[] { "regions", "fields", "facilities", "base_manifest" }; // post-MVP adapters and the manifest contract
+ if (content != null) Dependencies(content, result);
+ foreach (var field in unavailable)
result.Add(new MapEditorDiagnostic("MAPEDIT_DEPENDENCY_UNAVAILABLE", field, "accepted validation adapter is not installed",
"Integrate the owning contract before canonical save or export."));
return result.OrderBy(x => x.Field, StringComparer.Ordinal).ThenBy(x => x.Code, StringComparer.Ordinal).ToList().AsReadOnly();
}
+
+ /// <summary>The bindings the sim's loader would refuse (ContentLoader ValidateCorridors, StartingForces.Read,
+ /// ValidateSettlementTargets, ValidateObjectiveConditions and ValidateSites' settlement rule), re-checked with this
+ /// overlay's location moves applied to the settlements. Reads <paramref name="c"/> only.</summary>
+ void Dependencies(Content c, List<MapEditorDiagnostic> result)
+ {
+ void Broken(string field, string message) => result.Add(new MapEditorDiagnostic("MAPEDIT_DEPENDENCY_BROKEN", field, message,
+ "Resolve the binding explicitly; the editor never reroutes a sourced line or moves an anchor, target or site."));
+ bool Land(int q, int r) => c.HexAt(q, r)?.Land == true;
+ var settlement = new Dictionary<string, (int Q, int R)>(StringComparer.Ordinal);
+ foreach (var h in c.SettlementHexes)
+ settlement[h.Id] = Overlay.TryLocation(h.Id, out var q, out var r) ? (q, r) : (h.Q, h.R);
+
+ foreach (var x in c.Corridors)
+ {
+ List<int>? prev = null;
+ for (int i = 0; i < x.Segments.Count; i++)
+ foreach (var h in x.Segments[i].Hexes)
+ {
+ var at = FormattableString.Invariant($"segment {i + 1} (to {x.Segments[i].To}) hex q={h[0]} r={h[1]}");
+ if (!Land(h[0], h[1])) Broken($"corridors[{x.Id}]", at + " is not a land hex of the map");
+ else if (prev != null && MapActions.Distance(prev[0], prev[1], h[0], h[1]) > 1)
+ Broken($"corridors[{x.Id}]", at + FormattableString.Invariant($" is not next to q={prev[0]} r={prev[1]}"));
+ prev = h;
+ }
+ }
+ foreach (var f in c.StartingForces)
+ {
+ if (!Land(f.Q, f.R))
+ Broken($"anchors[{f.Row}]", FormattableString.Invariant($"anchor {f.Anchor} hex q={f.Q} r={f.R} is not a land hex of the map"));
+ if (f.Script is (int sq, int sr) && !Land(sq, sr))
+ Broken($"anchors[{f.Row}]", FormattableString.Invariant($"scripted anchor hex q={sq} r={sr} is not a land hex of the map"));
+ }
+ foreach (var t in c.SettlementTargets)
+ {
+ var at = $"targets[{t.Id}]";
+ if (!Land(t.Q, t.R)) Broken(at, FormattableString.Invariant($"target hex q={t.Q} r={t.R} is not a land hex of the map"));
+ if (!settlement.TryGetValue(t.Id, out var s)) { Broken(at, $"settlement '{t.Id}' has no hex"); continue; }
+ var bound = ContentLoader.TargetOnANeighbour.Contains(t.Id)
+ ? Movement.Neighbours.Any(d => s.Q + d.Q == t.Q && s.R + d.R == t.R)
+ : s.Q == t.Q && s.R == t.R;
+ if (!bound)
+ Broken(at, FormattableString.Invariant($"target hex q={t.Q} r={t.R} no longer matches settlement {t.Id} at q={s.Q} r={s.R}"));
+ }
+ foreach (var o in c.Objectives)
+ {
+ var w = o.CompletesWhen;
+ if (w == null) continue;
+ var at = $"objectives[{o.Id}]";
+ if (w.CorridorComplete != "" && c.Corridors.All(x => x.Id != w.CorridorComplete))
+ Broken(at, $"unknown corridor '{w.CorridorComplete}'");
+ foreach (var id in w.SitesBuilt.Prepend(w.SiteBuilt).Where(x => x != ""))
+ {
+ var site = c.Sites.FirstOrDefault(x => x.Id == id);
+ if (site == null) { Broken(at, $"unknown site '{id}'"); continue; }
+ if (!Projects.IsYishuvSite(site)) Broken(at, $"site '{id}' cannot be built as a yishuv");
+ foreach (var kv in settlement.Where(kv => kv.Value == (site.Q, site.R)).OrderBy(kv => kv.Key, StringComparer.Ordinal))
+ Broken(at, FormattableString.Invariant($"site '{id}' hex q={site.Q} r={site.R} now holds the settlement {kv.Key}"));
+ }
+ }
+ }
}
public sealed class MapEditorHex