A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Map: the live-ownership overlay takes fresh region ids off the control layer (Fixes #2742) (#2847)
Beri8bf054e82d33
diff --git a/changelog.d/2742.md b/changelog.d/2742.mdnew file mode 100644index 000000000..885c9dd73--- /dev/null+++ b/changelog.d/2742.md@@ -0,0 +1,5 @@+### Fixed++- Map: when no side data is drawn (a build without the control file, or a date before its first period), a live+ settlement's colour no longer restyles the whole Acre or Beisan sub-district; only the settlement's hex changes. The+ shipped game always draws the control layer, so nothing changes on screen today (#2742).diff --git a/unity/Assets/Scripts/Map/MapRegions.cs b/unity/Assets/Scripts/Map/MapRegions.csindex a8bc7e5ad..be88622eb 100644--- a/unity/Assets/Scripts/Map/MapRegions.cs+++ b/unity/Assets/Scripts/Map/MapRegions.cs@@ -151,10 +151,16 @@ namespace Statecraft.Game.Mapif (liveComposed.TryGetValue(key, out var cached)) return cached;var hexes = historical.Hexes.ToDictionary(h => h, h => historical.RegionOf(h.q, h.r));var styles = hexes.Values.Distinct().ToDictionary(id => id, id => historical.StyleOf(id));- styles[Control1948.IsraelId] = BorderStyle.Primary;- styles[Control1948.ArabId] = BorderStyle.Secondary;+ // On a control layer ids 1 and 2 are the two sides, so a settlement joins its side's area with no outline. On any+ // other layer they are sub-districts (Acre, Beisan) and zones sit at ZoneIdBase and up: take fresh ids above the+ // highest one, else the overlay would restyle every hex of those regions (#2742).+ var onControl = Control != null && Control.PeriodOn(date) != null;+ var top = styles.Keys.DefaultIfEmpty(0).Max();+ int primaryId = onControl ? Control1948.IsraelId : top + 1, secondaryId = onControl ? Control1948.ArabId : top + 2;+ styles[primaryId] = BorderStyle.Primary;+ styles[secondaryId] = BorderStyle.Secondary;foreach (var x in overrides) if (hexes.ContainsKey((x.q, x.r)))- hexes[(x.q, x.r)] = x.player ? Control1948.IsraelId : Control1948.ArabId;+ hexes[(x.q, x.r)] = x.player ? primaryId : secondaryId;return liveComposed[key] = new RegionLayer(key, hexes, styles);}diff --git a/unity/Assets/Tests/EditMode/ControlTests.cs b/unity/Assets/Tests/EditMode/ControlTests.csindex 4ec522c7a..5cfac915b 100644--- a/unity/Assets/Tests/EditMode/ControlTests.cs+++ b/unity/Assets/Tests/EditMode/ControlTests.cs@@ -188,6 +188,25 @@ public class ControlTestsAssert.AreEqual(BorderStyle.Secondary, lost.StyleOf(lost.RegionOf(YadMordechaiHex.q, YadMordechaiHex.r)));}+ /// <summary>#2742: without the side data the dated layer is the sub-districts, where ids 1 and 2 are Acre and Beisan,+ /// not Israel and Arab. A lost settlement in Acre must restyle its own hex only, not every hex of Beisan.</summary>+ [Test]+ public void OnTheSubdistrictLayerTheLiveOverlayLeavesAcreAndBeisanAlone()+ {+ var m = new MapRegions(Subdistricts1948.Parse(SubText), Armistice1949.Parse(ArmText));+ var historical = m.LayerOn(Start)!;+ var acre = historical.RegionOf(AcreHex.q, AcreHex.r);+ Assert.AreEqual(1, acre, "Acre's id on the sub-district layer");+ var otherAcre = historical.Hexes.First(h => h != AcreHex && historical.RegionOf(h.q, h.r) == 1);+ var beisan = historical.Hexes.First(h => historical.RegionOf(h.q, h.r) == 2);++ var lost = m.LayerOn(Start, new[] { (AcreHex.q, AcreHex.r, false) })!;+ Assert.AreNotSame(historical, lost);+ Assert.AreEqual(BorderStyle.Secondary, lost.StyleOf(lost.RegionOf(AcreHex.q, AcreHex.r)), "the lost settlement's hex");+ Assert.AreEqual(historical.StyleOf(1), lost.StyleOf(lost.RegionOf(otherAcre.q, otherAcre.r)), "the rest of Acre");+ Assert.AreEqual(historical.StyleOf(2), lost.StyleOf(lost.RegionOf(beisan.q, beisan.r)), "Beisan");+ }+/// <summary>Kept for a side file whose first period starts later: before it the sub-districts are grey, never blue.</summary>[Test]public void BeforeAFirstPeriodTheSubdistrictsAreGreyNotBlue()