A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Map editor step 1: content/map/overrides.yaml, its schema, loader and checks, applied last (refs #1009) (#1099)
Eyal Golan10d8aa0cb4ce
diff --git a/ASSETS.yaml b/ASSETS.yamlindex 72f9e5abe..fa05b2996 100644--- a/ASSETS.yaml+++ b/ASSETS.yaml@@ -234,6 +234,10 @@ rules:source: "The GDD v0.2 must-have map locations (#1008, docs/locations.md): coordinates from each place's Wikidata item (CC0, property P625), names, identities and Hebrew names from English and Hebrew Wikipedia (CC BY-SA 4.0), Jerusalem's 15 May 1948 control from the Knesset's 'Liberation of Jerusalem' page and en.wiki Operation Pitchfork, Sha'ar HaAliyah's opening from R. D. Seidelman's BGU thesis abstract (facts only, no text copied beyond short quotes in comments); hexes from tools/hexgrid.py; per-row sources and check dates in the file"status: verifiednote: "Every row is status draft until a person checks each fact (CONTENT_POLICY section 2, rule 6); the Hebrew names are agent-checked (#564). The East Jerusalem / Old City starting control is sensitive and waits for the owner's review."+ - glob: "content/map/overrides.yaml"+ licence: CC-BY-SA-4.0+ source: "The map editor's override file (#1009; owner rulings of 18 October 2026): this project's own authored edits (terrain, dated control, location hexes), applied after the generated map data. Ships empty; no facts and no third-party data"+ status: verified# --- Baked map textures (derived from the heightmap) ---- glob: "unity/Assets/Textures/Map/landuse.png"licence: CC-BY-SA-4.0diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 814ffb760..fa48434ae 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -34,6 +34,11 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIBC-54 at Lod Airport from July 1949 to September 1950, during Operation Magic Carpet. They stream after the first frame,keep clear of the surf, the harbour works, the other boats and the labels, and a model that does not stream is left out(#669).+- The map editor's override file (#1009 step 1): `content/map/overrides.yaml`, shipped empty, with its schema, loader and+ checks. Applied after the generated map data, so regenerating keeps it: a land hex's terrain, one period of a hex's+ control (owner, "One period at a time") and a settlement's or map location's hex (its id, names and sources stay). The+ sim applies terrain and location moves, the map draws them and applies control. Bad input fails the load naming the file+ and field. Nothing moves and no golden changes; the content hash does (the file is new content).- The military unit record (GDD Phase 5 PR 2): a unit can hold a side, a strength and a standing order with its target,each written into the state hash only when set, so a halutz hashes as before and no golden moves. `unit_types.yaml`gains Israel's `veteran_soldier` (infantry), `artillery` and `armoured_car` (armour) with a `side` and a `class`; thediff --git a/content/map/overrides.yaml b/content/map/overrides.yamlnew file mode 100644index 000000000..35ae077aa--- /dev/null+++ b/content/map/overrides.yaml@@ -0,0 +1,4 @@+# yaml-language-server: $schema=../schema/map-overrides.schema.json+terrain: []+control: []+locations: []diff --git a/content/schema/map-overrides.schema.json b/content/schema/map-overrides.schema.jsonnew file mode 100644index 000000000..9f1c6c686--- /dev/null+++ b/content/schema/map-overrides.schema.json@@ -0,0 +1,46 @@+{+ "$schema": "http://json-schema.org/draft-07/schema#",+ "title": "content/map/overrides.yaml",+ "description": "The map editor's overrides (#1009), applied after the generated map data. terrain: a land hex's biome (one of the land biomes in map/hexes.json). control: one period (an id in map/control_hexes_1948_49.yaml) of one hex, set to one of that file's codes. locations: a settlement's (map/settlements_1948.yaml) or map location's (map/locations_1948.yaml) land hex; its sourced coordinates stay in its own file.",+ "type": "object",+ "additionalProperties": false,+ "required": ["terrain", "control", "locations"],+ "definitions": {+ "hex": {+ "type": "object",+ "additionalProperties": false,+ "required": ["q", "r"],+ "properties": { "q": { "type": "integer" }, "r": { "type": "integer" } }+ }+ },+ "properties": {+ "terrain": {+ "type": "array",+ "items": {+ "type": "object", "additionalProperties": false, "required": ["hex", "value"],+ "properties": { "hex": { "$ref": "#/definitions/hex" }, "value": { "type": "string", "minLength": 1 } }+ }+ },+ "control": {+ "type": "array",+ "items": {+ "type": "object", "additionalProperties": false, "required": ["hex", "period", "value"],+ "properties": {+ "hex": { "$ref": "#/definitions/hex" },+ "period": { "type": "string", "minLength": 1 },+ "value": { "type": "string", "minLength": 1 }+ }+ }+ },+ "locations": {+ "type": "array",+ "items": {+ "type": "object", "additionalProperties": false, "required": ["id", "hex"],+ "properties": {+ "id": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$" },+ "hex": { "$ref": "#/definitions/hex" }+ }+ }+ }+ }+}diff --git a/sim/Statecraft.Sim.Tests/MapOverridesTests.cs b/sim/Statecraft.Sim.Tests/MapOverridesTests.csnew file mode 100644index 000000000..f52102fc6--- /dev/null+++ b/sim/Statecraft.Sim.Tests/MapOverridesTests.cs@@ -0,0 +1,134 @@+using System.Collections.Generic;+using System.IO;+using System.Linq;+using Statecraft.Sim;++/// <summary>content/map/overrides.yaml, the map editor's override layer (#1009 step 1; owner rulings of 18 October 2026).</summary>+public class MapOverridesTests+{+ const string Empty = "terrain: []\ncontrol: []\nlocations: []\n";++ static readonly List<MapHex> Hexes = new List<MapHex>+ {+ new MapHex { Q = 1, R = 2, Land = true, Biome = "hills" },+ new MapHex { Q = 2, R = 2, Land = true, Biome = "desert" },+ new MapHex { Q = 3, R = 2, Land = false, Biome = "sea" },+ };++ static MapOverrides Checked(string yaml)+ {+ var o = MapOverrides.Parse(yaml);+ o.ValidateMap(Hexes, new[] { "town_a", "fort_a" });+ o.ValidateControl(new[] { (1, 2), (2, 2) }, new[] { "opening", "truce1" }, new[] { "I", "E", "c", "-" });+ return o;+ }++ [Fact]+ public void TheShippedFileIsEmptySoNothingMoves()+ {+ var o = MapOverrides.Parse(File.ReadAllText(Path.Combine(RealContentTests.ContentRoot(), MapOverrides.FileName)));+ Assert.Empty(o.Terrain); Assert.Empty(o.Control); Assert.Empty(o.Locations);+ }++ [Theory]+ [InlineData(null)]+ [InlineData("")]+ public void AMissingFileHasNoOverrides(string? yaml)+ {+ var o = MapOverrides.Parse(yaml);+ Assert.Empty(o.Terrain); Assert.Empty(o.Control); Assert.Empty(o.Locations);+ }++ [Fact]+ public void AValidFileChecks()+ {+ var o = Checked("terrain:\n - { hex: { q: 1, r: 2 }, value: desert }\ncontrol:\n - { hex: { q: 1, r: 2 }, period: truce1, value: E }\n"+ + " - { hex: { q: 1, r: 2 }, period: opening, value: '-' }\nlocations:\n - { id: fort_a, hex: { q: 2, r: 2 } }\n");+ Assert.True(o.TryLocation("fort_a", out var q, out var r));+ Assert.Equal((2, 2), (q, r));+ Assert.False(o.TryLocation("town_a", out _, out _));+ }++ [Fact]+ public void AControlOverrideReplacesOnePeriodOfOneHexAndNothingElse()+ {+ var o = Checked("terrain: []\ncontrol:\n - { hex: { q: 1, r: 2 }, period: truce1, value: E }\nlocations: []\n");+ var periods = new[] { "opening", "truce1" };+ Assert.Equal("IE", o.ApplyControl(1, 2, periods, "II"));+ Assert.Equal("cc", o.ApplyControl(2, 2, periods, "cc")); // another hex keeps its history+ }++ [Theory]+ [InlineData("control: []\nlocations: []\n", "terrain", "must be a list")]+ [InlineData("terrain: []\ncontrol: []\nlocations: []\nnotes: x\n", "line 4", "")]+ [InlineData("terrain:\n - { value: hills }\ncontrol: []\nlocations: []\n", "terrain[0].hex", "required")]+ [InlineData("terrain:\n - { hex: { q: 1, r: 2 }, value: hills }\n - { hex: { q: 1, r: 2 }, value: desert }\ncontrol: []\nlocations: []\n", "terrain[1].hex", "a second override")]+ [InlineData("terrain: []\ncontrol:\n - { hex: { q: 1, r: 2 }, period: opening, value: I }\n - { hex: { q: 1, r: 2 }, period: opening, value: E }\nlocations: []\n", "control[1].period", "a second override")]+ [InlineData("terrain: []\ncontrol: []\nlocations:\n - { id: town_a, hex: { q: 1, r: 2 } }\n - { id: town_a, hex: { q: 2, r: 2 } }\n", "locations[1].id", "a second override")]+ [InlineData("terrain:\n - { hex: { q: 9, r: 9 }, value: hills }\ncontrol: []\nlocations: []\n", "terrain[0].hex", "unknown hex q=9 r=9")]+ [InlineData("terrain:\n - { hex: { q: 3, r: 2 }, value: hills }\ncontrol: []\nlocations: []\n", "terrain[0].hex", "not a land hex")]+ [InlineData("terrain:\n - { hex: { q: 1, r: 2 }, value: tundra }\ncontrol: []\nlocations: []\n", "terrain[0].value", "unknown terrain value 'tundra'")]+ [InlineData("terrain:\n - { hex: { q: 1, r: 2 }, value: sea }\ncontrol: []\nlocations: []\n", "terrain[0].value", "unknown terrain value 'sea'")]+ [InlineData("terrain: []\ncontrol: []\nlocations:\n - { id: nowhere, hex: { q: 1, r: 2 } }\n", "locations[0].id", "unknown location id 'nowhere'")]+ [InlineData("terrain: []\ncontrol: []\nlocations:\n - { id: town_a, hex: { q: 9, r: 9 } }\n", "locations[0].hex", "unknown hex q=9 r=9")]+ [InlineData("terrain: []\ncontrol: []\nlocations:\n - { id: town_a, hex: { q: 3, r: 2 } }\n", "locations[0].hex", "not a land hex")]+ [InlineData("terrain: []\ncontrol:\n - { hex: { q: 9, r: 9 }, period: opening, value: I }\nlocations: []\n", "control[0].hex", "unknown hex q=9 r=9")]+ [InlineData("terrain: []\ncontrol:\n - { hex: { q: 1, r: 2 }, period: later, value: I }\nlocations: []\n", "control[0].period", "unknown period 'later'")]+ [InlineData("terrain: []\ncontrol:\n - { hex: { q: 1, r: 2 }, period: opening, value: Z }\nlocations: []\n", "control[0].value", "unknown control value 'Z'")]+ public void InvalidInputNamesTheFileAndField(string yaml, string field, string message)+ {+ var ex = Assert.Throws<ContentException>(() => Checked(yaml));+ Assert.Equal(MapOverrides.FileName, ex.File);+ Assert.Equal(field, ex.Field);+ Assert.Contains(message, ex.Message);+ }++ // Through the content loader: the sim applies terrain and location overrides last, so every caller (the CLI, the+ // goldens, the game) sees the same map.++ [Fact]+ public void TheLoaderAppliesTerrainAndLocationOverrides()+ {+ var c = ContentLoader.Load(Fixture.Write(new Dictionary<string, string>+ {+ [MapOverrides.FileName] = "terrain:\n - { hex: { q: 3, r: 1 }, value: hills }\ncontrol: []\nlocations:\n - { id: town_a, hex: { q: 2, r: 1 } }\n",+ }));+ Assert.Equal("hills", c.HexAt(3, 1)!.Biome);+ Assert.Equal("coastal_plain", c.HexAt(1, 0)!.Biome); // every other hex as generated+ var s = c.SettlementHexes.Single(h => h.Id == "town_a");+ Assert.Equal((2, 1), (s.Q, s.R));+ var l = c.MapLocations.Single(x => x.Id == "town_a");+ Assert.Equal((2, 1), (l.Q, l.R));+ Assert.Equal((34.29, 33.35), (l.Lon, l.Lat)); // the sourced coordinates stay+ }++ [Fact]+ public void WithoutTheFileTheLoaderMovesNothing()+ {+ var c = ContentLoader.Load(Fixture.Write());+ Assert.Equal("desert", c.HexAt(3, 1)!.Biome);+ var s = c.SettlementHexes.Single(h => h.Id == "town_a");+ Assert.Equal((1, 0), (s.Q, s.R));+ }++ [Fact]+ public void TheLoaderRejectsAnUnknownLocationNamingTheOverrideFile()+ {+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string>+ {+ [MapOverrides.FileName] = "terrain: []\ncontrol: []\nlocations:\n - { id: nowhere, hex: { q: 2, r: 1 } }\n",+ })));+ Assert.Equal(MapOverrides.FileName, ex.File);+ Assert.Equal("locations[0].id", ex.Field);+ }++ [Fact]+ public void TheEmptyFileIsInTheContentHashAndChangesNothingElse()+ {+ var without = ContentLoader.Load(Fixture.Write());+ var with = ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { [MapOverrides.FileName] = Empty }));+ Assert.NotEqual(without.Hash, with.Hash);+ Assert.Equal(without.Hexes.Select(h => h.Biome), with.Hexes.Select(h => h.Biome));+ Assert.Equal(without.SettlementHexes.Select(h => (h.Id, h.Q, h.R)), with.SettlementHexes.Select(h => (h.Id, h.Q, h.R)));+ }+}diff --git a/sim/Statecraft.Sim.Tests/SchemaTests.cs b/sim/Statecraft.Sim.Tests/SchemaTests.csindex 8334e4062..9016ffc45 100644--- a/sim/Statecraft.Sim.Tests/SchemaTests.cs+++ b/sim/Statecraft.Sim.Tests/SchemaTests.cs@@ -145,6 +145,7 @@ public class SchemaTestsyield return new object[] { "people.yaml", "people.schema.json" };yield return new object[] { "offices.yaml", "offices.schema.json" };yield return new object[] { "parties.yaml", "parties.schema.json" };+ yield return new object[] { "map/overrides.yaml", "map-overrides.schema.json" };foreach (var f in Directory.GetFiles(Path.Combine(Root, "events"), "*.yaml").OrderBy(f => f, StringComparer.Ordinal))yield return new object[] { "events/" + Path.GetFileName(f), "event.schema.json" };}@@ -189,6 +190,11 @@ public class SchemaTestsyield return new object[] { "people.schema.json", "/definitions/person/properties/portrait", typeof(Portrait) };yield return new object[] { "people.schema.json", "/definitions/person/properties/offices/items", typeof(OfficeTerm) };yield return new object[] { "people.schema.json", "/definitions/source", typeof(Source) };+ yield return new object[] { "map-overrides.schema.json", "", typeof(MapOverrides) };+ yield return new object[] { "map-overrides.schema.json", "/definitions/hex", typeof(MapHexRef) };+ yield return new object[] { "map-overrides.schema.json", "/properties/terrain/items", typeof(TerrainOverride) };+ yield return new object[] { "map-overrides.schema.json", "/properties/control/items", typeof(ControlOverride) };+ yield return new object[] { "map-overrides.schema.json", "/properties/locations/items", typeof(LocationOverride) };yield return new object[] { "event.schema.json", "", typeof(GameEvent) };yield return new object[] { "event.schema.json", "/properties/conditions/items", typeof(EventCondition) };yield return new object[] { "event.schema.json", "/definitions/requirement", typeof(EventRequirement) };diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex d54af4da3..ed3b63ca2 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -361,6 +361,7 @@ namespace Statecraft.Simc.Objectives = ReadOptional<ObjectivesFile>(readFile, ObjectivesFileName)?.Objectives.OrderBy(o => o.Id, StringComparer.Ordinal).ToList() ?? new List<Objective>();Validate(c, settlementIds);+ ApplyMapOverrides(readFile, c, settlementIds); // after the map's own checks, before the GDD records that read itif (c.IsGdd){// GDD v0.1 city data (Phase 1 PR 3), read once eras.yaml is known to be valid. Only the GDD loop reads it, so@@ -377,6 +378,20 @@ namespace Statecraft.Simreturn c;}+ /// <summary>The map editor's overrides (#1009), applied last, once the generated map inputs have been read and+ /// checked: terrain and location moves here, so every caller of the sim sees them; control in the map, the only+ /// reader of the control file. The file is optional (no file, no overrides) and is in the content hash.</summary>+ static void ApplyMapOverrides(Func<string, string?> readFile, Content c, List<string> settlementIds)+ {+ string? text;+ try { text = readFile(MapOverrides.FileName); }+ catch (IOException e) { throw new ContentException(MapOverrides.FileName, "(file)", e.Message); }+ catch (UnauthorizedAccessException e) { throw new ContentException(MapOverrides.FileName, "(file)", e.Message); }+ var overrides = MapOverrides.Parse(text);+ overrides.ValidateMap(c.Hexes, settlementIds.Concat(c.MapLocations.Select(l => l.Id)));+ overrides.ApplyTo(c);+ }+/// <summary>SHA-256 over "path\nlength\ntext" for each file, CRLF normalised to LF (a Windows checkout hashes alike).</summary>static string HashOf(List<(string rel, string text)> files){diff --git a/sim/Statecraft.Sim/MapOverrides.cs b/sim/Statecraft.Sim/MapOverrides.csnew file mode 100644index 000000000..84ebe096d--- /dev/null+++ b/sim/Statecraft.Sim/MapOverrides.cs@@ -0,0 +1,192 @@+using System;+using System.Collections.Generic;+using System.Linq;+using YamlDotNet.Core;+using YamlDotNet.Serialization;+using YamlDotNet.Serialization.NamingConventions;++namespace Statecraft.Sim+{+ public sealed class MapHexRef+ {+ public int Q { get; set; }+ public int R { get; set; }+ }++ public sealed class TerrainOverride+ {+ public MapHexRef Hex { get; set; } = null!;+ public string Value { get; set; } = "";+ }++ public sealed class ControlOverride+ {+ public MapHexRef Hex { get; set; } = null!;+ public string Period { get; set; } = "";+ public string Value { get; set; } = "";+ }++ public sealed class LocationOverride+ {+ public string Id { get; set; } = "";+ public MapHexRef Hex { get; set; } = null!;+ }++ /// <summary>content/map/overrides.yaml: the map editor's authored changes (#1009; owner rulings of 18 October 2026),+ /// applied after every generated map input so that rerunning a generator keeps them. A terrain override sets a land+ /// hex's biome; a control override replaces one period's code of one hex in the map's control file (Control1948) and nothing+ /// else ("one period at a time"); a location override moves a game settlement (settlements_1948.yaml) or a map+ /// location (locations_1948.yaml) to another land hex, keeping its id, names, sourced coordinates and sources. The sim+ /// checks and applies terrain and locations (ContentLoader); the map, which alone reads the control file, checks and+ /// applies control (Unity's MapScene).</summary>+ public sealed class MapOverrides+ {+ public const string FileName = "map/overrides.yaml";+ public List<TerrainOverride> Terrain { get; set; } = null!;+ public List<ControlOverride> Control { get; set; } = null!;+ public List<LocationOverride> Locations { get; set; } = null!;++ static readonly IDeserializer Yaml = new DeserializerBuilder()+ .WithNamingConvention(UnderscoredNamingConvention.Instance)+ .WithDuplicateKeyChecking().Build();++ /// <summary>Parses the file and checks its shape: the three lists, a hex on every entry and no target twice. A+ /// missing or blank file (null, "") has no overrides. Throws ContentException naming the file and field.</summary>+ public static MapOverrides Parse(string? yaml, string file = FileName)+ {+ if (string.IsNullOrWhiteSpace(yaml)) return new MapOverrides+ {+ Terrain = new List<TerrainOverride>(), Control = new List<ControlOverride>(), Locations = new List<LocationOverride>()+ };+ MapOverrides result;+ try { result = Yaml.Deserialize<MapOverrides>(yaml) ?? throw new ContentException(file, "(file)", "empty file"); }+ catch (YamlException e) { throw new ContentException(file, $"line {e.Start.Line}", e.InnerException?.Message ?? e.Message); }+ if (result.Terrain == null) throw new ContentException(file, "terrain", "must be a list");+ if (result.Control == null) throw new ContentException(file, "control", "must be a list");+ if (result.Locations == null) throw new ContentException(file, "locations", "must be a list");++ var terrain = new HashSet<(int, int)>();+ for (int i = 0; i < result.Terrain.Count; i++)+ {+ var at = FormattableString.Invariant($"terrain[{i}]");+ var x = result.Terrain[i] ?? throw new ContentException(file, at, "must be an object");+ Required(file, at, x.Hex);+ if (x.Value == null) x.Value = "";+ if (!terrain.Add((x.Hex.Q, x.Hex.R))) throw new ContentException(file, at + ".hex", "a second override of this hex's terrain");+ }+ var control = new HashSet<(int, int, string)>();+ for (int i = 0; i < result.Control.Count; i++)+ {+ var at = FormattableString.Invariant($"control[{i}]");+ var x = result.Control[i] ?? throw new ContentException(file, at, "must be an object");+ Required(file, at, x.Hex);+ if (x.Period == null) x.Period = "";+ if (x.Value == null) x.Value = "";+ if (!control.Add((x.Hex.Q, x.Hex.R, x.Period))) throw new ContentException(file, at + ".period", "a second override of this hex's control in this period");+ }+ var locations = new HashSet<string>(StringComparer.Ordinal);+ for (int i = 0; i < result.Locations.Count; i++)+ {+ var at = FormattableString.Invariant($"locations[{i}]");+ var x = result.Locations[i] ?? throw new ContentException(file, at, "must be an object");+ Required(file, at, x.Hex);+ if (x.Id == null) x.Id = "";+ if (!locations.Add(x.Id)) throw new ContentException(file, at + ".id", "a second override of this location");+ }+ return result;+ }++ static void Required(string file, string at, MapHexRef? hex)+ {+ if (hex == null) throw new ContentException(file, at + ".hex", "required");+ }++ /// <summary>Checks terrain and location overrides against the map: a terrain override names a land hex of+ /// <paramref name="hexes"/> and one of its land biomes; a location override names a known location id and a land+ /// hex. With no <paramref name="locationIds"/> (the map, which has no roster of the map locations) the ids are not+ /// checked; the content loader checks them. Throws ContentException naming the file and field.</summary>+ public void ValidateMap(IReadOnlyCollection<MapHex> hexes, IEnumerable<string>? locationIds, string file = FileName)+ {+ var byHex = new Dictionary<(int, int), MapHex>();+ foreach (var h in hexes) byHex[(h.Q, h.R)] = h;+ var landBiomes = new SortedSet<string>(hexes.Where(h => h.Land).Select(h => h.Biome), StringComparer.Ordinal);+ var known = locationIds == null ? null : new HashSet<string>(locationIds, StringComparer.Ordinal);+ for (int i = 0; i < Terrain.Count; i++)+ {+ var x = Terrain[i]; var at = FormattableString.Invariant($"terrain[{i}]");+ LandHex(file, at + ".hex", x.Hex, byHex);+ if (!landBiomes.Contains(x.Value))+ throw new ContentException(file, at + ".value", $"unknown terrain value '{x.Value}' ({string.Join(", ", landBiomes)})");+ }+ for (int i = 0; i < Locations.Count; i++)+ {+ var x = Locations[i]; var at = FormattableString.Invariant($"locations[{i}]");+ if (known != null && !known.Contains(x.Id)) throw new ContentException(file, at + ".id", $"unknown location id '{x.Id}'");+ LandHex(file, at + ".hex", x.Hex, byHex);+ }+ }++ static void LandHex(string file, string field, MapHexRef hex, Dictionary<(int, int), MapHex> byHex)+ {+ if (!byHex.TryGetValue((hex.Q, hex.R), out var h))+ throw new ContentException(file, field, FormattableString.Invariant($"unknown hex q={hex.Q} r={hex.R}"));+ if (!h.Land) throw new ContentException(file, field, FormattableString.Invariant($"hex q={hex.Q} r={hex.R} is not a land hex"));+ }++ /// <summary>Checks control overrides against the control file: a hex it has, one of its period ids and one of its+ /// codes. Throws ContentException naming the file and field.</summary>+ public void ValidateControl(IEnumerable<(int q, int r)> controlHexes, IEnumerable<string> periods, IEnumerable<string> codes,+ string file = FileName)+ {+ var hexes = new HashSet<(int, int)>(controlHexes);+ var knownPeriods = new HashSet<string>(periods, StringComparer.Ordinal);+ var knownCodes = new HashSet<string>(codes, StringComparer.Ordinal);+ for (int i = 0; i < Control.Count; i++)+ {+ var x = Control[i]; var at = FormattableString.Invariant($"control[{i}]");+ if (!hexes.Contains((x.Hex.Q, x.Hex.R)))+ throw new ContentException(file, at + ".hex", FormattableString.Invariant($"unknown hex q={x.Hex.Q} r={x.Hex.R} (not in the control file)"));+ if (!knownPeriods.Contains(x.Period)) throw new ContentException(file, at + ".period", $"unknown period '{x.Period}'");+ if (!knownCodes.Contains(x.Value)) throw new ContentException(file, at + ".value", $"unknown control value '{x.Value}'");+ }+ }++ /// <summary>The overridden hex of location <paramref name="id"/>, if it has one.</summary>+ public bool TryLocation(string id, out int q, out int r)+ {+ var x = Locations.FirstOrDefault(v => v.Id == id);+ q = x?.Hex.Q ?? 0; r = x?.Hex.R ?? 0;+ return x != null;+ }++ /// <summary>Hex (<paramref name="q"/>, <paramref name="r"/>)'s control codes, one per period of+ /// <paramref name="periodIds"/>, with this file's control overrides for that hex: each replaces the one code of its+ /// period and nothing else (owner, 18 October 2026: "One period at a time"). After ValidateControl.</summary>+ public string ApplyControl(int q, int r, IReadOnlyList<string> periodIds, string codes)+ {+ if (codes.Length != periodIds.Count)+ throw new ArgumentException(FormattableString.Invariant($"{codes.Length} codes for {periodIds.Count} periods"), nameof(codes));+ var chars = codes.ToCharArray();+ foreach (var x in Control)+ if (x.Hex.Q == q && x.Hex.R == r)+ {+ int i = -1;+ for (int k = 0; k < periodIds.Count; k++) if (periodIds[k] == x.Period) { i = k; break; }+ if (i < 0) throw new ArgumentException($"unknown period '{x.Period}' (ValidateControl first)", nameof(periodIds));+ chars[i] = x.Value[0];+ }+ return new string(chars);+ }++ /// <summary>Applies the terrain and location overrides to loaded content (after ValidateMap): the hexes' biomes, the+ /// game settlements' hexes and the map locations' hexes. Sourced coordinates are left as they are.</summary>+ public void ApplyTo(Content c)+ {+ foreach (var x in Terrain) c.HexAt(x.Hex.Q, x.Hex.R)!.Biome = x.Value;+ foreach (var s in c.SettlementHexes)+ if (TryLocation(s.Id, out var q, out var r)) { s.Q = q; s.R = r; }+ foreach (var l in c.MapLocations)+ if (TryLocation(l.Id, out var q, out var r)) { l.Q = q; l.R = r; }+ }+ }+}diff --git a/unity/Assets/Scripts/Boot/GameInputs.cs b/unity/Assets/Scripts/Boot/GameInputs.csindex 8e2344289..277e0728d 100644--- a/unity/Assets/Scripts/Boot/GameInputs.cs+++ b/unity/Assets/Scripts/Boot/GameInputs.cs@@ -13,6 +13,8 @@ namespace Statecraft.Game.Bootpublic sealed class MapInputs{public string HeightmapJson = "", HexesJson = "", SettlementsYaml = "";+ /// <summary>content/map/overrides.yaml, the map editor's overrides (#1009); "" when the file is missing (no overrides).</summary>+ public string OverridesYaml = "";/// <summary>content/map/subdistrict_hexes_1948.yaml: the 1948 sub-districts the map outlines (display only).</summary>public string RegionsYaml = "";/// <summary>The baked runtime forms of the region files the map reads at boot (tools/regions_bake.py; issue #321;@@ -57,6 +59,7 @@ namespace Statecraft.Game.BootHeightmapR16z = File.ReadAllBytes(Path.Combine(mapDir, HeightmapCodec.FileName)),HexesJson = File.ReadAllText(Path.Combine(contentDir, "map", "hexes.json")),SettlementsYaml = File.ReadAllText(Path.Combine(contentDir, "map", SettlementPlacer.DefaultFileName)),+ OverridesYaml = ReadIfExists(Path.Combine(contentDir, MapOverrides.FileName)),RegionsYaml = File.ReadAllText(Path.Combine(contentDir, "map", Subdistricts1948.FileName)),RoutesYaml = ReadIfExists(Path.Combine(contentDir, "map", Statecraft.Game.Map.Routes.RoutePaths.DefaultFileName)),RoutesTsv = ReadIfExists(Path.Combine(contentDir, "map", Statecraft.Game.Map.Routes.RoutePaths.RuntimeFileName)),@@ -98,6 +101,7 @@ namespace Statecraft.Game.Boot{HeightmapJson = heightmapJson, HeightmapR16z = r16z,HexesJson = texts["map/hexes.json"], SettlementsYaml = texts["map/" + SettlementPlacer.DefaultFileName],+ OverridesYaml = texts.TryGetValue(MapOverrides.FileName, out var overrides) ? overrides : "",RegionsYaml = texts["map/" + Subdistricts1948.FileName],RoutesYaml = texts.TryGetValue("map/" + Statecraft.Game.Map.Routes.RoutePaths.DefaultFileName, out var routes) ? routes : "",RoutesTsv = texts.TryGetValue("map/" + Statecraft.Game.Map.Routes.RoutePaths.RuntimeFileName, out var routesTsv) ? routesTsv : "",diff --git a/unity/Assets/Scripts/Map/Control1948.cs b/unity/Assets/Scripts/Map/Control1948.csindex 08eb57c38..5a9ea8893 100644--- a/unity/Assets/Scripts/Map/Control1948.cs+++ b/unity/Assets/Scripts/Map/Control1948.cs@@ -111,6 +111,18 @@ namespace Statecraft.Game.Map/// so the bands run along the frontier and nothing is drawn beyond it, as for the sub-districts.</summary>public void SetOutside(IEnumerable<(int q, int r)> hexes) { outside = hexes.ToList(); Array.Clear(layers, 0, layers.Length); }+ /// <summary>The map editor's control overrides (content/map/overrides.yaml, #1009), applied after the file's codes:+ /// each changes one period of one hex and nothing else ("One period at a time", owner, 18 October 2026). Throws+ /// ContentException naming the override file and field for a hex, period or code this file does not have.</summary>+ public void ApplyOverrides(Statecraft.Sim.MapOverrides overrides)+ {+ var ids = Periods.Select(p => p.Id).ToList();+ overrides.ValidateControl(codes.Keys, ids, CodeOf.Keys.Select(c => c.ToString()));+ foreach (var hex in overrides.Control.Select(x => (q: x.Hex.Q, r: x.Hex.R)).Distinct().ToList())+ codes[hex] = overrides.ApplyControl(hex.q, hex.r, ids, codes[hex]);+ Array.Clear(layers, 0, layers.Length);+ }+/// <summary>The layer drawn on <paramref name="date"/> (null before the first period), built once per period: Israel/// primary, the other side secondary, contested, no-man's land and demilitarized zones neutral, no colour left out (no/// band, and it stops its neighbours' bands: the edge of the sourced data is not a front line).</summary>diff --git a/unity/Assets/Scripts/Map/MapScene.cs b/unity/Assets/Scripts/Map/MapScene.csindex a711998d1..4d388baaa 100644--- a/unity/Assets/Scripts/Map/MapScene.cs+++ b/unity/Assets/Scripts/Map/MapScene.cs@@ -54,9 +54,21 @@ namespace Statecraft.Game.Map/// <summary>The game date the routes were last shown at (RouteLayer.ShowAt), so a rebuild draws them as at that date;/// null before the game has set one (the routes then show as at the game's start).</summary>public DateTime? RouteDate { get; set; }- /// <summary>Who held which hex on a date (content/map/control_hexes_1948_49.yaml), as GameRoot read it for the borders,- /// or null before it has: the road vehicles (issue #725) stand only on ground Israel held. Display only.</summary>+ /// <summary>Who held which hex on a date (content/map/control_hexes_1948_49.yaml with the map editor's control+ /// overrides), as Build read it, or null without the file: GameRoot draws the borders from it, and the road vehicles+ /// (issue #725) stand only on ground Israel held. Display only.</summary>public Control1948 Control { get; set; }+ /// <summary>The map editor's overrides as the last Build applied them (content/map/overrides.yaml, #1009).</summary>+ public Statecraft.Sim.MapOverrides Overrides { get; private set; } = Statecraft.Sim.MapOverrides.Parse(null);++ /// <summary>Where a named location is drawn: its sourced point (<paramref name="lon"/>, <paramref name="lat"/>), or the+ /// centre of the hex the map editor moved it to (Overrides), so its label and its logical hex agree.</summary>+ public (double lon, double lat) LocationPoint(string id, double lon, double lat)+ {+ if (Hexes == null || !Overrides.TryLocation(id, out var q, out var r)) return (lon, lat);+ foreach (var h in Hexes.hexes) if (h.q == q && h.r == r) return (h.lon, h.lat);+ return (lon, lat);+ }/// <summary>The selected hex's outline: a child of the terrain (so a rebuild destroys it).</summary>public const string SelectionName = "HexSelection";@@ -265,6 +277,19 @@ namespace Statecraft.Game.MapDiagLog.BootPhase("hexes parsed");var list = SettlementPlacer.Parse(inputs.SettlementsYaml, (meta.lon0, meta.lon1, meta.lat0, meta.lat1), SettlementsPath);Settlements = list; settlementsYamlRead = inputs.SettlementsYaml;+ // The map editor's overrides (content/map/overrides.yaml, #1009) go on last, over the generated hexes, settlements+ // and control, so a rerun of a generator keeps them; everything drawn below reads the result. The sim applies the+ // same terrain and location overrides to its content (ContentLoader), which also checks the location ids.+ Overrides = Statecraft.Sim.MapOverrides.Parse(inputs.OverridesYaml);+ Overrides.ValidateMap(Hexes.hexes.Select(h => new Statecraft.Sim.MapHex { Q = h.q, R = h.r, Land = h.land, Biome = h.biome }).ToList(), null);+ var hexAt = Hexes.hexes.ToDictionary(h => (h.q, h.r));+ foreach (var terrain in Overrides.Terrain) hexAt[(terrain.Hex.Q, terrain.Hex.R)].biome = terrain.Value;+ foreach (var moved in list)+ if (Overrides.TryLocation(moved.Id, out var hq, out var hr)) { moved.Lon = hexAt[(hq, hr)].lon; moved.Lat = hexAt[(hq, hr)].lat; }+ Control = string.IsNullOrWhiteSpace(inputs.ControlYaml) ? null+ : Control1948.ReadRuntimeOrYaml(inputs.ControlTsv, inputs.ControlYaml, Debug.LogWarning);+ if (Control != null) Control.ApplyOverrides(Overrides);+ else Overrides.ValidateControl(Array.Empty<(int, int)>(), Array.Empty<string>(), Array.Empty<string>()); // no control file: any control override is an errorbool kitsOn = kitMaterial != null && treeMaterial != null;var localities = new Kits.Localities.Doc();if (kitsOn)diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex 008c1a1e2..6360e9835 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -260,9 +260,8 @@ namespace Statecraft.Game.UI// From their runtime forms when they match the YAML (issue #321: boot time), the sub-districts as the map read them.var regions = new MapRegions(map.SubdistrictsFor(inputs.Map.RegionsTsv, inputs.Map.RegionsYaml, Debug.LogWarning),string.IsNullOrWhiteSpace(inputs.Map.ArmisticeYaml) ? null : Armistice1949.ReadRuntimeOrYaml(inputs.Map.ArmisticeTsv, inputs.Map.ArmisticeYaml, Debug.LogWarning),- string.IsNullOrWhiteSpace(inputs.Map.ControlYaml) ? null : Control1948.ReadRuntimeOrYaml(inputs.Map.ControlTsv, inputs.Map.ControlYaml, Debug.LogWarning));+ map.Control); // the map's read, with the map editor's control overrides (#1009); the road vehicles use it too (#725)Regions = regions;- map.Control = regions.Control; // the road vehicles stand only where Israel held the ground (#725)var layerLabel = root.Q<Label>("map-layer");Action onDate = () =>{diff --git a/unity/Assets/Scripts/UI/MapLabelsPresenter.cs b/unity/Assets/Scripts/UI/MapLabelsPresenter.csindex d303500e1..9d9a6446e 100644--- a/unity/Assets/Scripts/UI/MapLabelsPresenter.cs+++ b/unity/Assets/Scripts/UI/MapLabelsPresenter.cs@@ -253,7 +253,8 @@ namespace Statecraft.Game.UIforeach (var loc in locations){if (settlementIds.Contains(loc.Id)) continue;- var s = new Settlement { Id = loc.Id, Name = loc.Name, NameHe = loc.NameHe, Type = LabelType(loc.Kind), Lon = loc.Lon, Lat = loc.Lat };+ var (lon, lat) = map.LocationPoint(loc.Id, loc.Lon, loc.Lat); // a map-editor move (#1009) labels the new hex+ var s = new Settlement { Id = loc.Id, Name = loc.Name, NameHe = loc.NameHe, Type = LabelType(loc.Kind), Lon = lon, Lat = lat };var slot = new VisualElement { name = "slot-" + s.Id, pickingMode = PickingMode.Ignore };slot.AddToClassList(SlotClass);var label = new Label(LocationName(loc, hebrew)) { name = "label-" + s.Id, pickingMode = PickingMode.Ignore };diff --git a/unity/Assets/Tests/EditMode/ControlTests.cs b/unity/Assets/Tests/EditMode/ControlTests.csindex 200e72563..178f0f272 100644--- a/unity/Assets/Tests/EditMode/ControlTests.cs+++ b/unity/Assets/Tests/EditMode/ControlTests.cs@@ -102,6 +102,43 @@ public class ControlTestsAssert.AreEqual(Control1948.Side.Israel, m.Control.At(nazareth.q, nazareth.r, Truce2).side);}+ /// <summary>#1009 step 1: the map applies content/map/overrides.yaml last. A control override changes one period of one+ /// hex ("One period at a time", owner, 18 October 2026), a terrain override the hex's biome, and a location override+ /// moves the settlement's marker to the new hex's centre.</summary>+ [Test]+ public void TheMapAppliesTheOverrideFileLast()+ {+ var nazareth = HexOf(35.3033, 32.7019);+ var inputs = GameInputs.MapFromDisk(Paths.Content, Paths.StreamingMap);+ var target = JsonUtility.FromJson<HexFile>(inputs.HexesJson).hexes.Single(h => h.q == 7 && h.r == 7);+ Assert.IsTrue(target.land);+ var biome = target.biome == "desert" ? "hills" : "desert";+ inputs.OverridesYaml = $"terrain:\n - {{ hex: {{ q: 7, r: 7 }}, value: {biome} }}\n"+ + $"control:\n - {{ hex: {{ q: {nazareth.q}, r: {nazareth.r} }}, period: truce1, value: I }}\n"+ + "locations:\n - { id: acre, hex: { q: 7, r: 7 } }\n";+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);+ var map = Object.FindFirstObjectByType<MapScene>();+ map.Build(inputs);+ Assert.AreEqual(Control1948.Side.Israel, map.Control!.At(nazareth.q, nazareth.r, Truce1).side, "the overridden period");+ Assert.AreEqual(Control1948.Side.Arab, map.Control.At(nazareth.q, nazareth.r, Start).side, "the period before, as the history has it");+ Assert.AreEqual(Control1948.Side.Contested, map.Control.At(nazareth.q, nazareth.r, TenDays).side, "the period after, as the history has it");+ Assert.AreEqual(biome, map.Hexes.hexes.Single(h => h.q == 7 && h.r == 7).biome);+ var acre = map.Settlements.Single(x => x.Id == "acre");+ Assert.AreEqual((target.lon, target.lat), (acre.Lon, acre.Lat), "the marker stands on the new hex");+ Assert.AreEqual((target.lon, target.lat), map.LocationPoint("acre", 0, 0));+ Assert.AreEqual((1.0, 2.0), map.LocationPoint("haifa", 1, 2), "a location the file does not move keeps its point");+ }++ [Test]+ public void AControlOverrideOfAPeriodTheFileDoesNotHaveFailsNamingTheOverrideField()+ {+ var c = Control1948.Parse(ControlText);+ var o = MapOverrides.Parse("terrain: []\ncontrol:\n - { hex: { q: 7, r: 6 }, period: later, value: I }\nlocations: []\n");+ var e = Assert.Throws<ContentException>(() => c.ApplyOverrides(o));+ Assert.AreEqual(MapOverrides.FileName, e!.File);+ Assert.AreEqual("control[0].period", e.Field);+ }+// Settlement hexes (content/map/settlement_hexes.yaml, tools/settlement_hexes.py)static readonly (int q, int r) AcreHex = (7, 6), JerusalemHex = (0, 23), GazaHex = (-11, 27), YadMordechaiHex = (-9, 26);diff --git a/unity/Assets/Tests/EditMode/RoadVehiclesTests.cs b/unity/Assets/Tests/EditMode/RoadVehiclesTests.csindex 5057d31ab..1e8d98f7c 100644--- a/unity/Assets/Tests/EditMode/RoadVehiclesTests.cs+++ b/unity/Assets/Tests/EditMode/RoadVehiclesTests.cs@@ -59,11 +59,12 @@ public class RoadVehiclesTestsstatic GameObject Prefab(string id) => AssetDatabase.LoadAssetAtPath<GameObject>(CollectionCatalog.PrefabPath(id, CollectionDetail.Near));- /// <summary>A built map with the control layer (as GameRoot gives it), its routes rebuilt at <paramref name="date"/>.</summary>+ /// <summary>A built map with the control layer (as the map reads it; without <paramref name="control"/>, none), its routes+ /// rebuilt at <paramref name="date"/>.</summary>(MapScene map, RoadVehicles layer) Build(DateTime date, RouteLayer.TrainMode train = RouteLayer.TrainMode.None, bool control = true){var map = RouteTests.BuildMap();- if (control) map.Control = Control();+ map.Control = control ? Control() : null;Object.DestroyImmediate(RouteTests.RoutesRoot(map).gameObject);asked.Clear(); trainAsked.Clear(); // the map's own build asked too; that layer is goneRouteLayer.Build(map.Terrain, map.Frame, Routes(), train, date, map: map);