A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Map: a loose scatter of single olives and scrub over the hills (refs #34) (#502)
Eyal Golan72bd85e24203
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 27961a25b..9b967d8fe 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -217,6 +217,10 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIBunchanged (#390). Presentation only (#458).- The `mvp-slice` golden is re-pinned (`0451920a` to `f6931e24`): the slice now has its city and the GDD turn, and thereference player fills the jobs (GDD Phase 1 PR 3, refs #376). The legacy goldens do not move.+- The hills carry a loose, uneven scatter of single olives and low scrub between the olive clumps, like promo 03's hills+ (refs #34): over the wet hill country where the land use is garrigue and terraces, outside the groves, the towns'+ footprints and the hex-edge midpoints. The olives already planted stay where they are; the map has about 20,000 trees+ instead of 8,400.- The trees are warm olive-brown instead of bright green, like the groves in promo 03 (refs #34): citrus groves, olivecrowns, palms and cypresses. Only the leaf colours change; the fruit, meshes and frame cost are the same.- Map: settlement quick wins (refs #31). The White City's blocks are lime white, with a solid-parapet balcony on eachdiff --git a/unity/Assets/Scripts/Map/Kits/KitGround.cs b/unity/Assets/Scripts/Map/Kits/KitGround.csindex 821dfa86f..db8aa4ee9 100644--- a/unity/Assets/Scripts/Map/Kits/KitGround.cs+++ b/unity/Assets/Scripts/Map/Kits/KitGround.cs@@ -34,6 +34,18 @@ namespace Statecraft.Game.Map.Kitsif (h.biome == "lake")foreach (var (dq, dr) in new[] { (0, 0), (1, 0), (-1, 0), (0, 1), (0, -1), (1, -1), (-1, 1) })lakeZone.Add((h.q + dq, h.r + dr));+ foreach (var h in hexes.hexes)+ {+ bool wetMountain = false;+ if (h.biome == "mountains")+ foreach (var (dq, dr) in Neighbours)+ wetMountain |= biome.TryGetValue((h.q + dq, h.r + dr), out var b) && b == "hills";+ if (h.biome != "hills" && !wetMountain) continue;+ hillCountry.Add((h.q, h.r));+ var c = frame.ToWorld(h.lon, h.lat, 0f);+ hillMin = Vector2.Min(hillMin, new Vector2(c.x, c.z) - Vector2.one * HexSizeM);+ hillMax = Vector2.Max(hillMax, new Vector2(c.x, c.z) + Vector2.one * HexSizeM);+ }int res = Mathf.Max(2, terrain.terrainData.heightmapResolution);sampleX = frame.WidthM / (res - 1); sampleZ = frame.LengthM / (res - 1);}@@ -62,6 +74,18 @@ namespace Statecraft.Game.Map.Kits}readonly HashSet<(int, int)> lakeZone = new HashSet<(int, int)>();+ readonly HashSet<(int, int)> hillCountry = new HashSet<(int, int)>();+ static readonly (int, int)[] Neighbours = { (1, 0), (1, -1), (0, -1), (-1, 0), (-1, 1), (0, 1) }; // axial (tools/hexgrid.py)++ /// <summary>Whether (x, z) lies in the wet hill country, where the land-use bake paints garrigue, terraces and scrub+ /// (tools/land_bake.py: "wet", 250-600 mm of rain): a "hills" hex (at least 200 mm, below 700 m: tools/hexgrid.py) or+ /// a "mountains" hex beside one (the Judean and Galilee heights). The mountains of the Negev, Sinai and Edom border+ /// only desert and stay bare. Hexes carry no rainfall, so this is the neighbour rule; against the CHELSA rain of the+ /// 130 mountain hexes up to 950 m it takes 36 of the 40 with 250 mm or more and 5 of the 90 drier ones.</summary>+ public bool HillCountry(float x, float z) => hillCountry.Contains(Hex(x, z));+ /// <summary>A world rectangle (x, z) that holds all of the hill country.</summary>+ public Rect HillCountryBounds => hillMax.x < hillMin.x ? Rect.zero : Rect.MinMaxRect(hillMin.x, hillMin.y, hillMax.x, hillMax.y);+ Vector2 hillMin = Vector2.positiveInfinity, hillMax = Vector2.negativeInfinity;/// <summary>Open sea (the heightmap writes it as exactly 0 m: MapBuilder.SeaToleranceM), a lake's water, or off the/// map. A lake is its water surface, not its hexes (#317): a lake hex also holds its shore (Tiberias stands in one,diff --git a/unity/Assets/Scripts/Map/Kits/Vegetation.cs b/unity/Assets/Scripts/Map/Kits/Vegetation.csindex 4354367a3..93d2af59d 100644--- a/unity/Assets/Scripts/Map/Kits/Vegetation.cs+++ b/unity/Assets/Scripts/Map/Kits/Vegetation.cs@@ -72,6 +72,12 @@ namespace Statecraft.Game.Map.KitsTreeKind.Palm => 4.6f, _ => 1.2f,};+ /// <summary>The hills' scatter (Plant): one try per cell this wide (m), kept at about this share (a broad noise+ /// takes it from 0.4 to 1.6 times), this share of it low scrub (a small, squat olive), the rest single olives.</summary>+ public const float ScatterCellM = 800f, ScatterShare = 0.85f, ScrubShare = 0.35f;+ /// <summary>The widest crown (m) the grove index is asked about (its query reach past a grove's disc).</summary>+ const float ScatterKeepM = 1500f;+/// <summary>Real metres between the trees of a grove's rows.</summary>public const float GroveStepM = 4.9f;@@ -94,7 +100,7 @@ namespace Statecraft.Game.Map.Kits// Counts fall with the square of the tree scale (k = 1 at the default), so a larger tree covers the same ground// with fewer instances instead of burying the towns.float ks = s / KitScale.CountReference;- void Add(TreeKind k, float x, float z, ref KitRandom rnd, float size = 1f, float yawDeg = float.NaN)+ void Add(TreeKind k, float x, float z, ref KitRandom rnd, float size = 1f, float yawDeg = float.NaN, float squash = 1f){// The tree's own numbers first, whether it stands or not: a tree left out for a lot or a route then never// shifts the trees drawn after it (towns round 2: a town's new lots no longer reshuffle every grove).@@ -107,10 +113,12 @@ namespace Statecraft.Game.Map.Kitsif (ground.OnLot(x, z, crown) || ground.OnRoute(new Vector2(x, z), crown)) return;float y = ground.Y(x, z);float yaw = float.IsNaN(yawDeg) ? spin : yawDeg;- trees.Add((k, Matrix4x4.TRS(new Vector3(x, y, z), Quaternion.Euler(0, yaw, 0), new Vector3(scale, scale * stretch, scale))));+ trees.Add((k, Matrix4x4.TRS(new Vector3(x, y, z), Quaternion.Euler(0, yaw, 0), new Vector3(scale, scale * stretch * squash, scale))));}- // Citrus groves round the coastal-plain towns: rectangular blocks of rows, each grove on its own angle.+ // Citrus groves round the coastal-plain towns: rectangular blocks of rows, each grove on its own angle. Each grove's+ // disc (centre; half its diagonal plus a patch's crown) is kept, so the hills' scatter below stays out of it.+ var groveDiscs = new DiscIndex(1f, ScatterKeepM);foreach (var st in settlements){var c3 = ground.Frame.ToWorld(st.Lon, st.Lat, 0); var c = new Vector2(c3.x, c3.z);@@ -132,6 +140,7 @@ namespace Statecraft.Game.Map.Kits// Grove sizes grow with the square root of the tree scale, so a bigger tree means fewer, not only larger, rows.float grow = Mathf.Sqrt(s / KitScale.CountReference);float w = rnd.Range(1300f, 3000f) * grow, d = rnd.Range(900f, 2000f) * grow, step = 2f * GroveStepM * s; // one 2 x 2 patch per step+ groveDiscs.Add((gc, 0.5f * Mathf.Sqrt(w * w + d * d) + CrownRadiusM(TreeKind.CitrusPatch) * s * 1.15f)); // to its edge rows' crowns// A ragged block: each row stops at its own length, and some groves lose a corner (an L shape).bool notch = rnd.Chance(0.3f); float nu = rnd.Range(0.1f, 0.3f) * w, nv = rnd.Range(0.1f, 0.3f) * d;for (float v = -d / 2; v <= d / 2; v += step)@@ -190,6 +199,43 @@ namespace Statecraft.Game.Map.Kits}}+ // The hills' loose scatter between the olive clumps (promo 03's hills, and the demo video at 23 s): single olives+ // and low scrub over the wet hill country, where the land-use bake paints garrigue, terraces and scrub+ // (tools/land_bake.py: wild ground above 80 m, none on the steep faces the shader draws as rock). One try per+ // ScatterCellM cell, anywhere in it, kept at a share that a broad noise makes uneven (no clumps, no rows). Each+ // cell draws from its own stream, seeded by its place in the grid, so the olives above never move, a tree left out+ // for a town or a route never shifts another, and only the cells over the hill country are visited.+ {+ ulong seed = KitRandom.Fnv1a("hill-scatter");+ var hills = ground.HillCountryBounds;+ int i0 = Mathf.Max(0, Mathf.FloorToInt(hills.xMin / ScatterCellM)), i1 = Mathf.Min(Mathf.CeilToInt(ground.Width / ScatterCellM), Mathf.CeilToInt(hills.xMax / ScatterCellM));+ int j0 = Mathf.Max(0, Mathf.FloorToInt(hills.yMin / ScatterCellM)), j1 = Mathf.Min(Mathf.CeilToInt(ground.Length / ScatterCellM), Mathf.CeilToInt(hills.yMax / ScatterCellM));+ for (int j = j0; j < j1; j++)+ for (int i = i0; i < i1; i++)+ {+ var rnd = new KitRandom(new KitRandom(seed ^ ((ulong)j << 32 | (uint)i)).Next());+ float x = (i + 0.5f) * ScatterCellM, z = (j + 0.5f) * ScatterCellM;+ float px = x + rnd.Range(-0.5f, 0.5f) * ScatterCellM, pz = z + rnd.Range(-0.5f, 0.5f) * ScatterCellM;+ float uneven = 0.4f + 1.2f * Mathf.PerlinNoise(px / 23000f + 3.7f, pz / 23000f + 1.9f);+ if (!rnd.Chance(ScatterShare * uneven)) continue;+ bool scrub = rnd.Chance(ScrubShare);+ float size = scrub ? rnd.Range(0.5f, 0.7f) : rnd.Range(0.9f, 1.2f);+ float e = ground.ElevM(px, pz);+ if (e < 120f || e > 950f || !ground.HillCountry(px, pz) || ground.Water(px, pz) || ground.Slope(px, pz, 600f) > 0.37f) continue;+ var p = new Vector2(px, pz); float crown = CrownRadiusM(TreeKind.Olive) * s * size * 1.15f;+ // No crown reaches into a town's or village's footprint (the footprint index finds a disc up to 1.7 of its+ // radius away: a crown wider than 0.7 of a footprint's radius is still kept off its lots by Add) or a grove.+ if (Reaches(ground.Footprints, p, crown) || Reaches(groveDiscs, p, crown) || ground.OnGridMark(p, crown)) continue;+ Add(TreeKind.Olive, px, pz, ref rnd, size, float.NaN, scrub ? 0.7f : 1f);+ }+ static bool Reaches(DiscIndex discs, Vector2 p, float r)+ {+ var near = discs.Near(p);+ for (int k = 0; k < near.Count; k++) { var (c, dr, _) = discs[near[k]]; if ((p - c).sqrMagnitude < (dr + r) * (dr + r)) return true; }+ return false;+ }+ }+// Palms by the shore of the coastal towns and in their streets; cypress windbreaks by villages and moshavot.foreach (var st in settlements){diff --git a/unity/Assets/Tests/EditMode/KitTests.cs b/unity/Assets/Tests/EditMode/KitTests.csindex e4aed4109..36887db63 100644--- a/unity/Assets/Tests/EditMode/KitTests.cs+++ b/unity/Assets/Tests/EditMode/KitTests.cs@@ -586,6 +586,68 @@ public class KitTestsAssert.AreEqual(0, inTown, "patch trees inside a town");}+ /// <summary>Issue #34, vegetation round 2: promo 03's hills carry a loose scatter of single olives and low scrub between+ /// the olive clumps. Over the wet hill country (KitGround.HillCountry, 120-950 m) the map as built has at least+ /// <see cref="HillCrownsPer100Km2"/> olive crowns per 100 km², about <see cref="Vegetation.ScrubShare"/> of the scatter+ /// low scrub (a squat olive); no scrub crown reaches a town's or village's footprint or a grove's tree; and the scrub is+ /// spread loosely, neither clumped nor in rows: the Clark-Evans ratio of its nearest-neighbour distances (1 for random+ /// points, under 1 clumped, about 2 on a grid) stays within <see cref="ScrubSpread"/>.</summary>+ [Test]+ public void TheHillsCarryALooseScatterOfOlivesAndScrub()+ {+ var map = OpenMap();+ var g = Ground(map);+ var veg = map.GetComponentInChildren<VegetationLayer>(); Assert.IsNotNull(veg);+ bool Hill(float x, float z) { float e = g.ElevM(x, z); return e >= 120f && e <= 950f && g.HillCountry(x, z); }+ int hillKm2 = 0;+ for (float z = 500f; z < g.Length; z += 1000f) for (float x = 500f; x < g.Width; x += 1000f) if (Hill(x, z)) hillKm2++;+ var olives = veg.Planted().Where(t => t.kind == TreeKind.Olive).Select(t => t.m).Where(m => Hill(m.m03, m.m23)).ToList();+ static bool Squat(Matrix4x4 m) => ((Vector3)m.GetColumn(1)).magnitude < 0.8f * ((Vector3)m.GetColumn(0)).magnitude;+ var scrubM = olives.Where(Squat).ToList();+ var scrub = scrubM.Select(m => new Vector2(m.m03, m.m23)).ToList();+ float per100 = olives.Count * 100f / hillKm2;+ // Nearest neighbours, footprints and grove trees through a 5 km grid.+ static Dictionary<(int, int), List<Vector2>> Grid(IEnumerable<Vector2> ps)+ {+ var d = new Dictionary<(int, int), List<Vector2>>();+ foreach (var p in ps) { var k = (Mathf.FloorToInt(p.x / 5000f), Mathf.FloorToInt(p.y / 5000f)); if (!d.TryGetValue(k, out var l)) d[k] = l = new List<Vector2>(); l.Add(p); }+ return d;+ }+ static IEnumerable<Vector2> Near(Dictionary<(int, int), List<Vector2>> d, Vector2 p)+ {+ int cx = Mathf.FloorToInt(p.x / 5000f), cz = Mathf.FloorToInt(p.y / 5000f);+ for (int dz = -1; dz <= 1; dz++) for (int dx = -1; dx <= 1; dx++) if (d.TryGetValue((cx + dx, cz + dz), out var l)) foreach (var q in l) yield return q;+ }+ var scrubGrid = Grid(scrub);+ double nn = 0; int nnCount = 0;+ foreach (var p in scrub)+ {+ float best = float.MaxValue;+ foreach (var q in Near(scrubGrid, p)) if (q != p) best = Mathf.Min(best, (q - p).magnitude);+ if (best < 5000f) { nn += best; nnCount++; }+ }+ float spread = nnCount == 0 ? 0f : (float)(nn / nnCount) / (0.5f * Mathf.Sqrt(hillKm2 * 1e6f / Mathf.Max(1, scrub.Count)));+ // A crown is its kind's real crown times the instance's scale (NoTreeGrowsThroughABuildingOrLandmark).+ static float Crown(TreeKind k, Matrix4x4 m) => Vegetation.CrownRadiusM(k) * ((Vector3)m.GetColumn(0)).magnitude;+ int inTown = scrubM.Count(m => map.KitFootprints.Any(f => (new Vector2(m.m03, m.m23) - f.centre).magnitude < f.radius + Crown(TreeKind.Olive, m)));+ var groveTrees = veg.Planted().Where(t => t.kind == TreeKind.Citrus || t.kind == TreeKind.CitrusPatch).ToList();+ var groveGrid = Grid(groveTrees.Select(t => new Vector2(t.m.m03, t.m.m23)));+ float groveCrownMax = groveTrees.Count == 0 ? 0f : groveTrees.Max(t => Crown(t.kind, t.m));+ int inGrove = scrubM.Count(m => { var p = new Vector2(m.m03, m.m23); return Near(groveGrid, p).Any(q => (q - p).magnitude < Crown(TreeKind.Olive, m) + groveCrownMax); });+ TestContext.WriteLine($"hill country {hillKm2} km²: {olives.Count} olives ({per100:0.0} per 100 km²), {scrub.Count} of them scrub; " ++ $"scrub spread (Clark-Evans) {spread:0.00}; trees {veg.Count}; scrub reaching a footprint {inTown}, a grove tree {inGrove}");+ Assert.GreaterOrEqual(per100, HillCrownsPer100Km2, "olive crowns over the hill country");+ Assert.Greater(scrub.Count, 0.25f * olives.Count * Vegetation.ScrubShare, "low scrub among them");+ Assert.That(spread, Is.InRange(ScrubSpread.x, ScrubSpread.y), "the scrub is spread loosely, not clumped or in rows");+ Assert.AreEqual(0, inTown, "scrub reaching a town's or village's footprint");+ Assert.AreEqual(0, inGrove, "scrub reaching a grove's tree");+ }++ /// <remarks>Measured 2026-10-14 over 11,285 km² of hill country: main 3,480 olives (30.8 per 100 km²), no scrub; with the+ /// scatter 15,165 (134.4), 4,234 of them scrub, Clark-Evans 1.08.</remarks>+ public const float HillCrownsPer100Km2 = 120f;+ public static readonly Vector2 ScrubSpread = new Vector2(0.8f, 1.3f);+/// <summary>The WebGL checkpoint drew every palm black: a frond's tip quad collapsed to a point, its edge-based normal was/// zero and normalize(0) is NaN on WebGL 2 (the tilt-shift then smeared it into black blocks). No part may have one.</summary>[Test]diff --git a/unity/Assets/Tests/EditMode/TerrainShaderTests.cs b/unity/Assets/Tests/EditMode/TerrainShaderTests.csindex deeabf977..1b90292e3 100644--- a/unity/Assets/Tests/EditMode/TerrainShaderTests.cs+++ b/unity/Assets/Tests/EditMode/TerrainShaderTests.cs@@ -158,11 +158,14 @@ public class TerrainShaderTests/// frame's luma spread: this view takes in the Dead Sea (about 7% of the frame), whose land-to-sea step is about a/// quarter to a third of the frame's variance and shrinks as the AO darkens the land, cancelling the relief's gain/// (LumaStd measured 0.0830 -> 0.0827 while the gradient rose 13%).- /// Terrain.mat is changed in memory only and restored.</summary>+ /// Terrain.mat is changed in memory only and restored. The trees are off: their crowns add the same detail to both+ /// renders and dilute the bakes' share (2026-10-14: 10.0% with main's trees, 6.9% with the hills' scatter of #34, 12.3%+ /// without trees).</summary>[UnityTest]public IEnumerator TheBakesCarveTheRelief(){var map = OpenMap();+ VisualToggles.Set("trees", false);yield return null;var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();rig.LookAt = map.Frame.ToWorld(35.25, 31.70, 0); rig.Distance = 45000f; rig.Yaw = 0; rig.TopInset = 0; rig.Apply();