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 visual and label offsets, warn outside their hex (Refs #1721 slice B) (#2411)

Beri216d4ff0b25f
diff --git a/changelog.d/1721-map-editor-offsets.md b/changelog.d/1721-map-editor-offsets.md
new file mode 100644
index 000000000..bf771fe11
--- /dev/null
+++ b/changelog.d/1721-map-editor-offsets.md
@@ -0,0 +1,4 @@
+- Map editor (gdd-0.3 authoring envelope, Refs #1721 slice B): the envelope now carries visual and label offsets, each
+ a location's axial hex plus whole metres east and north of the hex centre (Q59). An offset whose point leaves its own
+ 4.4 km hex gives a warning naming the row, which does not block export (Q58); the point is kept as written. Offsets
+ inside their hex save and reload byte for byte.
diff --git a/content/schema/map-editor-overlay.schema.json b/content/schema/map-editor-overlay.schema.json
index f87274c50..66897cf83 100644
--- a/content/schema/map-editor-overlay.schema.json
+++ b/content/schema/map-editor-overlay.schema.json
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Isolated gdd-0.3 map authoring envelope",
- "description": "R-MEDIT-001/002/003: legacy format is unchanged. The explicit gdd-0.3 envelope is authoring infrastructure only, not runtime content or a validation receipt. Registry ids require owning validators; canonical export is blocked until those contracts are integrated. Offset units and base manifest remain deferred.",
+ "description": "R-MEDIT-001/002/003: legacy format is unchanged. The explicit gdd-0.3 envelope is authoring infrastructure only, not runtime content or a validation receipt. Registry ids require owning validators; canonical export is blocked until those contracts are integrated. Offsets are an axial hex plus whole metres east and north of its centre (Q59). The base manifest remains deferred.",
"definitions": {
"hex": {
"type": "object",
@@ -107,7 +107,8 @@
"overlay",
"workable",
"regions",
- "infrastructure"
+ "infrastructure",
+ "offsets"
],
"properties": {
"version": {
@@ -204,6 +205,42 @@
}
}
}
+ },
+ "offsets": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "additionalProperties": false,
+ "required": [
+ "id",
+ "kind",
+ "hex",
+ "east_m",
+ "north_m"
+ ],
+ "properties": {
+ "id": {
+ "type": "string",
+ "pattern": "^[a-z][a-z0-9_]*$"
+ },
+ "kind": {
+ "type": "string",
+ "enum": [
+ "visual",
+ "label"
+ ]
+ },
+ "hex": {
+ "$ref": "#/definitions/hex"
+ },
+ "east_m": {
+ "type": "integer"
+ },
+ "north_m": {
+ "type": "integer"
+ }
+ }
+ }
}
}
}
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 67f486e4a..41ed0a8ce 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -591,4 +591,6 @@ 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. 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.
+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 and the headed editor is separate work.
+
+R-MEDIT-004: A visual or label offset (#1721 slice B; owner, 1 November 2026, Q58 and Q59) is one `offsets` row per location id and kind (`visual` or `label`): the axial hex (q, r) plus whole metres east and north of that hex's centre. It is valid while the point stays inside its own hex, the map's 4.4 km pointy-top hex (`hex_size_km` in `content/map/hexes.json` is the circumradius; the boundary counts as inside). A point outside it gives a `MAPEDIT_OFFSET_OUTSIDE_HEX` warning that names the row (`offsets[<id>/<kind>]`) and is not blocking; every other diagnostic stays blocking. The point is kept as written: no offset, location or sourced geometry is moved to clear the warning. Offsets serialize ordered by id and kind, so save and reload give the same bytes.
diff --git a/sim/Statecraft.Sim.Tests/MapOverridesTests.cs b/sim/Statecraft.Sim.Tests/MapOverridesTests.cs
index 846914ccb..0d1385b07 100644
--- a/sim/Statecraft.Sim.Tests/MapOverridesTests.cs
+++ b/sim/Statecraft.Sim.Tests/MapOverridesTests.cs
@@ -153,7 +153,7 @@ public class MapOverridesTests
+ "base_revision: fixture-only\nbase_digest: "
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ "overlay: { terrain: [], control: [], locations: [] }\n"
- + "workable: []\nregions: []\ninfrastructure: []\n";
+ + "workable: []\nregions: []\ninfrastructure: []\noffsets: []\n";
[Fact]
public void EditorEnvelopeRoundTripsWithoutEnteringTheLegacyParser()
@@ -180,6 +180,13 @@ public class MapOverridesTests
[InlineData("workable: []", "workable: [{ hex: { q: 1 }, value: true }]", "MAPEDIT_SHAPE")]
[InlineData("regions: []", "regions: [{ hex: { q: 1, r: 2 }, region_id: '' }]", "MAPEDIT_SHAPE")]
[InlineData("infrastructure: []", "infrastructure: [{ id: fixture_only, hex: { q: 1, r: 2 }, kind: fixture_only, parent_id: fixture_only, capacity: 3 }]", "MAPEDIT_SHAPE")]
+ [InlineData("offsets: []\n", "", "MAPEDIT_SHAPE")]
+ [InlineData("offsets: []", "offsets: [{ id: town_a, kind: badge, hex: { q: 1, r: 2 }, east_m: 0, north_m: 0 }]", "MAPEDIT_SHAPE")]
+ [InlineData("offsets: []", "offsets: [{ id: Town, kind: label, hex: { q: 1, r: 2 }, east_m: 0, north_m: 0 }]", "MAPEDIT_SHAPE")]
+ [InlineData("offsets: []", "offsets: [{ id: town_a, kind: label, hex: { q: 1, r: 2 }, east_m: 0 }]", "MAPEDIT_SHAPE")]
+ [InlineData("offsets: []", "offsets: [{ id: town_a, kind: label, hex: { q: 1, r: 2 }, east_m: 1.5, north_m: 0 }]", "MAPEDIT_SHAPE")]
+ [InlineData("offsets: []", "offsets: [{ id: town_a, kind: label, hex: { q: 1 }, east_m: 0, north_m: 0 }]", "MAPEDIT_SHAPE")]
+ [InlineData("offsets: []", "offsets: [{ id: town_a, kind: label, hex: { q: 1, r: 2 }, east_m: 0, north_m: 0 }, { id: town_a, kind: label, hex: { q: 1, r: 2 }, east_m: 5, north_m: 5 }]", "MAPEDIT_DUPLICATE")]
public void EditorShapeRefusalsHaveNamedErrors(string old, string replacement, string code)
{
var error = Assert.Throws<ContentException>(() =>
@@ -560,4 +567,70 @@ public class MapOverridesTests
c.Objectives.Add(new Objective { Id = "objective_c" });
Assert.Empty(Broken(DependencyDiagnostics(c)));
}
+
+ // R-MEDIT-004, Q58/Q59 (#1721 slice B): a visual or label offset is the axial hex plus whole metres east and north of
+ // its centre, valid while the point stays inside that 4.4 km pointy-top hex. Leaving it only warns. SYNTHETIC fixtures.
+ static MapEditorOverlay WithOffsets(string offsets) => MapEditorOverlay.Parse(
+ EditorFixture.Replace("draft: true", "draft: false").Replace("offsets: []", "offsets: " + offsets), SaveGame.Gdd03Ruleset);
+
+ static List<MapEditorDiagnostic> OutsideHex(MapEditorOverlay value) => value.Diagnostics("fixture-only", new string('a', 64))
+ .Where(x => x.Code == "MAPEDIT_OFFSET_OUTSIDE_HEX").ToList();
+
+ [Theory]
+ [InlineData(0, 0)]
+ [InlineData(3810, 0)] // just inside the flat east side (inradius 3810.5 m)
+ [InlineData(-3810, 0)]
+ [InlineData(0, 4400)] // the north vertex
+ [InlineData(0, -4400)]
+ [InlineData(3000, 2000)]
+ public void AnOffsetInsideItsHexRoundTripsSaveAndReloadByteForByte(int east, int north)
+ {
+ var value = WithOffsets(System.FormattableString.Invariant(
+ $"[{{ id: town_b, kind: visual, hex: {{ q: 2, r: -1 }}, east_m: 7, north_m: -3 }}, {{ id: town_a, kind: label, hex: {{ q: 1, r: 2 }}, east_m: {east}, north_m: {north} }}]"));
+ Assert.Empty(OutsideHex(value));
+ var saved = MapEditorOverlay.Serialize(value);
+ Assert.Contains(System.FormattableString.Invariant(
+ $"offsets:\n - {{ id: 'town_a', kind: 'label', hex: {{ q: 1, r: 2 }}, east_m: {east}, north_m: {north} }}\n - {{ id: 'town_b', kind: 'visual', hex: {{ q: 2, r: -1 }}, east_m: 7, north_m: -3 }}\n"), saved);
+ Assert.Equal("town_b", value.Offsets[0].Id); // the caller's list is not reordered
+ var reloaded = MapEditorOverlay.Parse(saved, SaveGame.Gdd03Ruleset);
+ Assert.Equal(System.Text.Encoding.UTF8.GetBytes(saved), System.Text.Encoding.UTF8.GetBytes(MapEditorOverlay.Serialize(reloaded)));
+ var back = reloaded.Offsets.Single(x => x.Id == "town_a");
+ Assert.Equal(new int?[] { 1, 2, east, north }, new[] { back.Hex.Q, back.Hex.R, back.EastM, back.NorthM });
+ }
+
+ [Theory]
+ [InlineData(3811, 0)] // past the flat east side
+ [InlineData(-3811, 0)]
+ [InlineData(0, 4401)] // past the north vertex
+ [InlineData(3000, 3000)] // past a slanted side
+ [InlineData(-2000, -3500)]
+ public void AnOffsetOutsideItsHexWarnsAndDoesNotBlock(int east, int north)
+ {
+ var without = WithOffsets("[]").Diagnostics("fixture-only", new string('a', 64));
+ var value = WithOffsets(System.FormattableString.Invariant(
+ $"[{{ id: town_a, kind: label, hex: {{ q: 1, r: 2 }}, east_m: {east}, north_m: {north} }}]"));
+ var row = Assert.Single(OutsideHex(value));
+ Assert.Equal("offsets[town_a/label]", row.Field);
+ Assert.False(row.Blocking);
+ Assert.Contains(System.FormattableString.Invariant($"east_m={east} north_m={north}"), row.Message);
+ Assert.Contains("q=1 r=2", row.Message);
+ // The warning adds no blocking row: every other row is the same as for the overlay without the offset.
+ var rest = value.Diagnostics("fixture-only", new string('a', 64)).Where(x => x.Code != row.Code).ToList();
+ Assert.Equal(without.Select(x => (x.Code, x.Field, x.Blocking)), rest.Select(x => (x.Code, x.Field, x.Blocking)));
+ Assert.All(rest, x => Assert.True(x.Blocking));
+ // Nothing is repaired: the offset keeps its authored point.
+ Assert.Equal(new int?[] { east, north }, new[] { value.Offsets[0].EastM, value.Offsets[0].NorthM });
+ var back = MapEditorOverlay.Parse(MapEditorOverlay.Serialize(value), SaveGame.Gdd03Ruleset);
+ Assert.Equal(new int?[] { east, north }, new[] { back.Offsets[0].EastM, back.Offsets[0].NorthM });
+ }
+
+ // The offset check's hex is the map's hex: content/map/hexes.json gives the circumradius in km (pointy-top, #1796).
+ [Fact]
+ public void TheOffsetHexIsTheMapsHex()
+ {
+ var text = File.ReadAllText(Path.Combine(RealContentTests.ContentRoot(), "map", "hexes.json"));
+ var size = System.Text.RegularExpressions.Regex.Match(text, "\"hex_size_km\":([0-9.]+)").Groups[1].Value;
+ Assert.Equal(MapEditorOverlay.OffsetHexCircumradiusM, double.Parse(size, System.Globalization.CultureInfo.InvariantCulture) * 1000, 6);
+ Assert.Contains("\"layout\":\"pointy\"", text);
+ }
}
diff --git a/sim/Statecraft.Sim.Tests/SchemaTests.cs b/sim/Statecraft.Sim.Tests/SchemaTests.cs
index 959fdce3f..52cf498c6 100644
--- a/sim/Statecraft.Sim.Tests/SchemaTests.cs
+++ b/sim/Statecraft.Sim.Tests/SchemaTests.cs
@@ -354,7 +354,9 @@ people:
Regions = new List<MapEditorRegion> { new MapEditorRegion {
Hex = new MapEditorHex { Q = 1, R = -2 }, RegionId = "fixture'only" } },
Infrastructure = new List<MapEditorInfrastructure> { new MapEditorInfrastructure {
- Hex = new MapEditorHex { Q = 1, R = -2 }, Id = "fixture'only", Kind = "fixture'only", ParentId = "fixture'only" } }
+ Hex = new MapEditorHex { Q = 1, R = -2 }, Id = "fixture'only", Kind = "fixture'only", ParentId = "fixture'only" } },
+ Offsets = new List<MapEditorOffset> { new MapEditorOffset {
+ Id = "fixture_only", Kind = "label", Hex = new MapEditorHex { Q = 1, R = -2 }, EastM = 120, NorthM = -40 } }
};
value.Overlay = MapOverrides.Parse("terrain: [{ hex: { q: 1, r: -2 }, value: hills }]\n"
+ "control: [{ hex: { q: 1, r: -2 }, period: fixture_only, value: I }]\n"
@@ -393,6 +395,8 @@ people:
[InlineData("version: 'map-editor-0.3'", "version: future")]
[InlineData("ruleset: 'gdd-0.3'", "ruleset: legacy")]
[InlineData("draft: true", "unknown: true")]
+ [InlineData("kind: 'label'", "kind: 'badge'")]
+ [InlineData("north_m: -40", "north_m: -40.5")]
public void AuthoringSchemaRejectsWrongVersionRulesetAndMissingFields(string old, string replacement) =>
Assert.NotEmpty(Errors("map-editor-overlay.schema.json", SyntheticEditorEnvelope().Replace(old, replacement)));
diff --git a/sim/Statecraft.Sim/MapOverrides.cs b/sim/Statecraft.Sim/MapOverrides.cs
index fcc9ca928..7de4f34ce 100644
--- a/sim/Statecraft.Sim/MapOverrides.cs
+++ b/sim/Statecraft.Sim/MapOverrides.cs
@@ -257,6 +257,11 @@ namespace Statecraft.Sim
public List<MapEditorWorkable> Workable { get; set; } = null!;
public List<MapEditorRegion> Regions { get; set; } = null!;
public List<MapEditorInfrastructure> Infrastructure { get; set; } = null!;
+ public List<MapEditorOffset> Offsets { get; set; } = null!;
+
+ /// <summary>The hex an offset must stay inside: content/map/hexes.json's pointy-top hex, whose `hex_size_km` (4.4,
+ /// since #1796) is the circumradius, centre to corner. A test pins this to that file.</summary>
+ public const double OffsetHexCircumradiusM = 4400;
// R-MEDIT-003: no receipt or export until accepted dependency adapters and base-manifest contract exist.
[YamlIgnore] public bool CanExport => false;
@@ -319,7 +324,8 @@ namespace Statecraft.Sim
if (!IsToken(value.BaseRevision) || value.BaseDigest == null
|| value.BaseDigest.Length != 64 || value.BaseDigest.Any(c => !(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f')))
throw Error("MAPEDIT_BASE", "base", "a single-line revision token and lowercase SHA-256 base-input digest are required");
- if (value.Overlay == null || value.Workable == null || value.Regions == null || value.Infrastructure == null)
+ if (value.Overlay == null || value.Workable == null || value.Regions == null || value.Infrastructure == null
+ || value.Offsets == null)
throw Error("MAPEDIT_SHAPE", "(file)", "overlay and all edit lists are required");
// Reuse legacy duplicate/shape checks without changing their behavior or serialization.
try { MapOverrides.Serialize(value.Overlay); }
@@ -341,6 +347,16 @@ namespace Statecraft.Sim
Token(row.Id, "infrastructure.id"); Token(row.Kind, "infrastructure.kind");
Token(row.ParentId, "infrastructure.parent_id");
}
+ CheckRows(value.Offsets, "offsets", x => x.Id + "/" + x.Kind);
+ foreach (var row in value.Offsets)
+ {
+ if (row.Id == null || !System.Text.RegularExpressions.Regex.IsMatch(row.Id, "^[a-z][a-z0-9_]*$"))
+ throw Error("MAPEDIT_SHAPE", "offsets.id", "a stable location id is required");
+ if (row.Kind != "visual" && row.Kind != "label")
+ throw Error("MAPEDIT_SHAPE", "offsets.kind", "visual or label is required");
+ if (row.EastM == null || row.NorthM == null)
+ throw Error("MAPEDIT_SHAPE", "offsets", "whole metres east_m and north_m are required");
+ }
}
static ContentException Error(string code, string field, string message) =>
@@ -403,6 +419,9 @@ namespace Statecraft.Sim
x => "{ hex: " + Hex(x.Hex) + ", region_id: " + Quote(x.RegionId) + " }");
Rows(text, "infrastructure", copy.Infrastructure.OrderBy(x => x.Id, StringComparer.Ordinal),
x => "{ id: " + Quote(x.Id) + ", hex: " + Hex(x.Hex) + ", kind: " + Quote(x.Kind) + ", parent_id: " + Quote(x.ParentId) + " }");
+ Rows(text, "offsets", copy.Offsets.OrderBy(x => x.Id, StringComparer.Ordinal).ThenBy(x => x.Kind, StringComparer.Ordinal),
+ x => "{ id: " + Quote(x.Id) + ", kind: " + Quote(x.Kind) + ", hex: " + Hex(x.Hex)
+ + FormattableString.Invariant($", east_m: {x.EastM}, north_m: {x.NorthM} }}"));
return text.ToString();
}
@@ -428,12 +447,25 @@ namespace Statecraft.Sim
? 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);
+ // Q58/Q59: an offset that leaves its own hex only warns; the authored point is kept as written.
+ foreach (var o in Offsets.Where(o => !InsideHex(o.EastM!.Value, o.NorthM!.Value)))
+ result.Add(new MapEditorDiagnostic("MAPEDIT_OFFSET_OUTSIDE_HEX", $"offsets[{o.Id}/{o.Kind}]",
+ FormattableString.Invariant($"{o.Kind} offset east_m={o.EastM} north_m={o.NorthM} leaves its hex q={o.Hex.Q} r={o.Hex.R}"),
+ "Bring the offset back inside its hex; the location and its sourced point stay where they are.", blocking: false));
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>Pointy-top hex centred on the origin, north along a vertex: inside when within the flat east/west sides
+ /// (the inradius) and the four slanted sides. The boundary counts as inside.</summary>
+ static bool InsideHex(double east, double north)
+ {
+ double inradius = Math.Sqrt(3) / 2 * OffsetHexCircumradiusM, x = Math.Abs(east), y = Math.Abs(north);
+ return x <= inradius && x / 2 + y * Math.Sqrt(3) / 2 <= inradius;
+ }
+
/// <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>
@@ -519,6 +551,14 @@ namespace Statecraft.Sim
public string Kind { get; set; } = "";
public string ParentId { get; set; } = "";
}
+ /// <summary>A visual or label offset (Q59): the location's axial hex plus whole metres east and north of its centre.</summary>
+ public sealed class MapEditorOffset : MapEditorHexEdit
+ {
+ public string Id { get; set; } = "";
+ public string Kind { get; set; } = "";
+ public int? EastM { get; set; }
+ public int? NorthM { get; set; }
+ }
public sealed class MapEditorDiagnostic
{
public string Code { get; }
@@ -526,8 +566,10 @@ namespace Statecraft.Sim
public string Field { get; }
public string Message { get; }
public string Action { get; }
- public MapEditorDiagnostic(string code, string field, string message, string action)
- { Code = code; Field = field; Message = message; Action = action; }
+ /// <summary>False only for a warning, which does not block export (Q58: visual and label offsets only warn).</summary>
+ public bool Blocking { get; }
+ public MapEditorDiagnostic(string code, string field, string message, string action, bool blocking = true)
+ { Code = code; Field = field; Message = message; Action = action; Blocking = blocking; }
}
}
diff --git a/unity/Assets/Tests/EditMode/MapOverrideEditorTests.cs b/unity/Assets/Tests/EditMode/MapOverrideEditorTests.cs
index b39bd83e4..e286e47bc 100644
--- a/unity/Assets/Tests/EditMode/MapOverrideEditorTests.cs
+++ b/unity/Assets/Tests/EditMode/MapOverrideEditorTests.cs
@@ -235,7 +235,7 @@ public sealed class MapOverrideEditorTests
{
const string source = "version: map-editor-0.3\nruleset: gdd-0.3\ndraft: true\n"
+ "base_revision: fixture-only\nbase_digest: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
- + "overlay: { terrain: [], control: [], locations: [] }\nworkable: []\nregions: []\ninfrastructure: []\n";
+ + "overlay: { terrain: [], control: [], locations: [] }\nworkable: []\nregions: []\ninfrastructure: []\noffsets: []\n";
var document = ScriptableObject.CreateInstance<MapOverrideEditorDocument>();
try
{