A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Map: Tal Heuberger's kit landmarks at the models' 24x up close, and plots' models off the grid (fixes #1032) (#1048)
Berif6df9c9efb9e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 00f71fcfe..af63118c1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -83,6 +83,13 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB- The Cabinet, Budget, Defence, Why, How to play and Settings screens each gain an X in the header that closesthem (the same close as Escape): a phone has no Escape key, and re-tapping the lit rail button was the only wayout (v0.1.1 playtest feedback).+- Up close the kit landmarks (mosques, churches, minarets, Jerusalem's walls, gates and towers, the Dome of the Rock,+ Jaffa's clock tower and lighthouse, Ramla's White Tower, Nahalal's hall, Revivim's walled lookout) stand at the+ models' world scale too, real size x 24 (`SettlementKits.ModelScale`), instead of the kits' 60x and 100x that towered+ over the houses; never bigger than far off, and Jerusalem's walls keep their circuit and shrink only in height and+ thickness. A plot's models no longer sit in a regular grid: seeded by the place and the plot, each is turned up to+ 10 degrees and moved within its cell, some cells stay empty and a long plot may get a street through it. Far off+ nothing changes. The rural life and special buildings take their 24x from the same constant (#1032).- Unit movement (GDD Phase 5 PR 5): `Move(unit, q, r)` moves a player unit at command time along the cheapest pathwithin the movement points it has left this turn, and `Movement.Reachable` and `Movement.Path` give the preview.Movement points per military type and a cost per land biome are owner-accepted design values (Q-MOVE-1, 19 October 2026); lake and sea arediff --git a/unity/Assets/Scripts/Map/Collection/RuralLife.cs b/unity/Assets/Scripts/Map/Collection/RuralLife.csindex 5d0f91282..0c21ffb2a 100644--- a/unity/Assets/Scripts/Map/Collection/RuralLife.cs+++ b/unity/Assets/Scripts/Map/Collection/RuralLife.cs@@ -2,7 +2,6 @@using System;using System.Collections.Generic;using System.Linq;-using Statecraft.Game.Map.Routes;using UnityEngine;using UnityEngine.Rendering;@@ -32,16 +31,10 @@ namespace Statecraft.Game.Map.Collection// Design values (#667): sparse scenery, not a population statement or simulation rule.public const int MaxAnchorsPerModel = 3;- /// <summary>The house the world scale is set by (m, real): the middle of the kit's default house, 7.5 to 10 m long.</summary>- public const float ReferenceHouseM = 8.5f;- /// <summary>The one world scale of the map's Tal Heuberger models up close (the owner on v0.1.1, 18 October 2026: the- /// buildings were "way bigger then the train"): the reference house is as long as the locomotive's car of the steam- /// train the map runs (ServiceTrain: Tal Heuberger's locomotive and tender at RouteTrain.Scale x ServiceTrain.ModelSize,- /// about 816 m, in ServiceTrain.Cars cars of about 204 m), so 204 / 8.5 = 24x real. The same rule as the #700- /// buildings' scale fix (branch map/town-models-world-scale, SettlementKits.ModelScale), so a tractor stands beside- /// a kibbutz house at their real proportion. (Tripo's meshes are all about one unit across, so one shared scale- /// would make a sheep as long as a tractor.)</summary>- public const float WorldScale = RouteTrain.ModelRealLengthM * RouteTrain.Scale * ServiceTrain.ModelSize / ServiceTrain.Cars / ReferenceHouseM;+ /// <summary>The one world scale of the map's Tal Heuberger models up close: <see cref="Kits.SettlementKits.ModelScale"/>+ /// (issue #1032), so a tractor stands beside a kibbutz house at their real proportion. (Tripo's meshes are all about+ /// one unit across, so one shared scale would make a sheep as long as a tractor.)</summary>+ public const float WorldScale = Kits.SettlementKits.ModelScale; // #1032: one shared constant/// <summary>Design values (#667), typical of each kind, not sourced measurements: the real long side (m), seen from/// above, each model stands for.</summary>public static float RealLengthM(string model) => model switchdiff --git a/unity/Assets/Scripts/Map/Collection/SpecialBuildingModels.cs b/unity/Assets/Scripts/Map/Collection/SpecialBuildingModels.csindex f98a5310e..5b236de39 100644--- a/unity/Assets/Scripts/Map/Collection/SpecialBuildingModels.cs+++ b/unity/Assets/Scripts/Map/Collection/SpecialBuildingModels.cs@@ -2,7 +2,6 @@using System;using System.Collections.Generic;using System.Linq;-using Statecraft.Game.Map.Routes;using UnityEngine;using UnityEngine.Rendering;@@ -18,14 +17,9 @@ namespace Statecraft.Game.Map.CollectionBarracks = "b18-military-barracks-v2", Workshop = "b21-artisan-workshop-v2",Factory = "b22-industrial-factory-v2";- /// <summary>The house the world scale is set by (m, real): the middle of the kit's default house, 7.5 to 10 m long.</summary>- public const float ReferenceHouseM = 8.5f;- /// <summary>The one world scale of Tal Heuberger's building models (the owner on v0.1.1, 18 October 2026: the buildings were- /// "way bigger then the train"): the reference house is as long as the locomotive's car of the steam train the map- /// runs (ServiceTrain: Tal Heuberger's locomotive and tender at RouteTrain.Scale x ServiceTrain.ModelSize, about 816 m, in- /// ServiceTrain.Cars cars of about 204 m), so 204 / 8.5 = 24x a building's real size. The same rule as the #700- /// buildings' scale fix (branch map/town-models-world-scale, SettlementKits.ModelScale).</summary>- public const float WorldScale = RouteTrain.ModelRealLengthM * RouteTrain.Scale * ServiceTrain.ModelSize / ServiceTrain.Cars / ReferenceHouseM;+ /// <summary>The one world scale of Tal Heuberger's building models: <see cref="Kits.SettlementKits.ModelScale"/> (issue+ /// #1032).</summary>+ public const float WorldScale = Kits.SettlementKits.ModelScale; // #1032: one shared constant/// <summary>Design values, not sourced measurements: the real long side (m) each model stands for, so that at/// <see cref="WorldScale"/> the fort, the barracks, the factory and the shikun block are each a few locomotive carsdiff --git a/unity/Assets/Scripts/Map/Kits/KitMesh.cs b/unity/Assets/Scripts/Map/Kits/KitMesh.csindex 479ffc694..8128f1ea8 100644--- a/unity/Assets/Scripts/Map/Kits/KitMesh.cs+++ b/unity/Assets/Scripts/Map/Kits/KitMesh.cs@@ -28,16 +28,46 @@ namespace Statecraft.Game.Map.Kitsreadonly List<(int v0, int v1, int i0, int i1)> cuts = new List<(int, int, int, int)>();KitMesh? plinths;- /// <summary>The plinths under this mesh's building models, drawn only with the models.</summary>+ /// <summary>The plinths under this mesh's building models, drawn only with the models (and, issue #1032, the+ /// landmarks' close copies, CloseCopy).</summary>internal KitMesh Plinths => plinths ??= new KitMesh();/// <summary>Marks the start of a building's parts (CutEnd marks its end): the close mesh leaves them out.</summary>internal (int v, int i) CutStart() => (pos.Count, tri.Count);internal void CutEnd((int v, int i) start) { if (pos.Count > start.v) cuts.Add((start.v, pos.Count, start.i, tri.Count)); }++ /// <summary>Issue #1032: the parts since <paramref name="start"/> (a landmark at a kit's symbolic scale) draw far off+ /// only (cut, as a building's), and up close a copy of them draws instead (with the plinths): shrunk about+ /// <paramref name="anchor"/>, on the ground by <paramref name="along"/> along the yaw <paramref name="yawDeg"/> and+ /// <paramref name="across"/> across it, and what stands above the anchor's level by <paramref name="up"/>; what is+ /// below keeps its depth, so the foundations stay in the slope. The facade uv stays in real metres, so the windows+ /// shrink with the walls. Returns the copy's bounds.</summary>+ internal Bounds CloseCopy((int v, int i) start, Vector3 anchor, float yawDeg, float along, float across, float up)+ {+ CutEnd(start);+ var to = Plinths;+ int off = to.pos.Count;+ float a = yawDeg * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);+ var b = new Bounds(anchor, Vector3.zero);+ for (int v = start.v; v < pos.Count; v++)+ {+ Vector3 p = pos[v] - anchor, n = nrm[v];+ // Into the yaw's frame (u along, w across), scaled, and back; a normal by the inverse scale.+ float u = (p.x * ca + p.z * sa) * along, w = (-p.x * sa + p.z * ca) * across;+ float nu = (n.x * ca + n.z * sa) / along, nw = (-n.x * sa + n.z * ca) / across;+ var q = anchor + new Vector3(u * ca - w * sa, p.y > 0f ? p.y * up : p.y, u * sa + w * ca);+ to.pos.Add(q); b.Encapsulate(q);+ to.nrm.Add(new Vector3(nu * ca - nw * sa, p.y > 0f ? n.y / up : n.y, nu * sa + nw * ca).normalized);+ to.col.Add(col[v]); to.uv.Add(uv[v]);+ }+ for (int i = start.i; i < tri.Count; i++) to.tri.Add(tri[i] - start.v + off);+ return b;+ }/// <summary>Buildings marked (a test aid).</summary>internal int Cuts => cuts.Count;- /// <summary>This mesh without its marked buildings, plus its plinths, or null when that is empty. A building's+ /// <summary>This mesh without its marked buildings, plus its plinths (and the landmarks' close copies, CloseCopy), or null+ /// when that is empty. A building's/// triangles only use its own vertices (every part appends its vertices and indexes only those), so the kept/// triangles are re-indexed and nothing else changes.</summary>internal Mesh? ToCloseMesh(string name)diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs b/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.csindex a77cb9b65..cad6330bd 100644--- a/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs@@ -38,6 +38,21 @@ namespace Statecraft.Game.Map.Kits}}+ /// <summary>Issue #1032 (follow-up to #1030): a kit landmark drawn since <paramref name="start"/> at the symbolic scale+ /// <paramref name="kitScale"/> stays as it is far off, and up close stands at the models' world scale+ /// (<see cref="ModelScale"/>, the locomotive's rule), shrunk about its spot <paramref name="at"/> on its ground level+ /// <paramref name="y"/> (KitMesh.CloseCopy), never grown: the Old City's Al-Aqsa and citadel keep the 16x and 20x they+ /// were fitted at. A wall's piece (<paramref name="keepLength"/>) keeps its length along <paramref name="yaw"/>, so the+ /// circuit stays closed round the symbolic Old City; only its thickness and height shrink. Recorded in+ /// <see cref="Result.CloseLandmarks"/>.</summary>+ static void AtWorldScale(string id, string kind, KitMesh km, (int v, int i) start, Vector2 at, float y, float kitScale, float yaw = 0f,+ bool keepLength = false)+ {+ float k = Mathf.Min(1f, ModelScale / kitScale);+ var b = km.CloseCopy(start, new Vector3(at.x, y, at.y), yaw, keepLength ? 1f : k, k, k);+ closeLandmarks?.Add(new Placed(id, kind, at, yaw, b.size.x, b.size.z, b.max.y - y, default, y));+ }+static Vector2 World(KitGround g, double lon, double lat) { var w = g.Frame.ToWorld(lon, lat, 0); return new Vector2(w.x, w.z); }/// <summary>The unit vector from settlement <paramref name="s"/>'s point towards a sourced coordinate.</summary>@@ -85,9 +100,11 @@ namespace Statecraft.Game.Map.Kitsif (Claim(lots, mosqueWant + new Vector2(20f * m, 2f * m), 4.5f * m, s.Id, ground, out var p)){float y = ground.Y(p.x, p.y);+ var start = km.CutStart();km.Box(p.x, p.y, 15f, 5f * m, 5f * m, y - 2f * m, y, 24f * m, stone, stone, Facade.Stone, m, roofed: true);km.Box(p.x, p.y, 15f, 4f * m, 4f * m, y + 24f * m, y + 24f * m, 4f * m, C(0.90f, 0.82f, 0.64f), stone, Facade.Plain, m, roofed: true);km.Pyramid(p.x, p.y, 15f, 4.4f * m, 4.4f * m, y + 28f * m, 3.5f * m, C(0.55f, 0.47f, 0.40f));+ AtWorldScale(s.Id, "clock_tower", km, start, p, y, m);Record(s.Id, "clock_tower", p, 15f, 5f * m, 5f * m, 31.5f * m, stone);n++;}@@ -101,6 +118,7 @@ namespace Statecraft.Game.Map.Kitsif (Claim(lots, want, 2.6f * m, s.Id, ground, out var q)){float y = ground.Y(q.x, q.y);+ var start = km.CutStart();var white = C(0.93f, 0.92f, 0.88f); var red = C(0.70f, 0.22f, 0.17f);const int bands = 4; float bandH = 12f * m / bands;for (int b = 0; b < bands; b++)@@ -108,6 +126,7 @@ namespace Statecraft.Game.Map.KitsMathf.Lerp(1.9f, 1.4f, b / (float)bands) * m, Mathf.Lerp(1.9f, 1.4f, (b + 1) / (float)bands) * m, b % 2 == 0 ? white : red, 10);km.Shaft(new Vector3(q.x, y + 12f * m, q.y), new Vector3(q.x, y + 14.5f * m, q.y), 1.5f * m, 1.5f * m, C(0.30f, 0.32f, 0.30f), 10);km.Cone(new Vector3(q.x, y + 14.5f * m, q.y), 1.8f * m, 2.2f * m, red, 10);+ AtWorldScale(s.Id, "lighthouse", km, start, q, y, m);Record(s.Id, "lighthouse", q, 0f, 3.8f * m, 3.8f * m, 16.7f * m, white);n++;}@@ -214,11 +233,13 @@ namespace Statecraft.Game.Map.Kitsfloat rOct = 27f * k;var dc = pc + new Vector2(-40f, 260f);var marble = C(0.88f, 0.86f, 0.80f); var tiles = C(0.36f, 0.50f, 0.64f); var lead = C(0.26f, 0.27f, 0.29f);+ var start = km.CutStart();km.Shaft(new Vector3(dc.x, deck - 60f, dc.y), new Vector3(dc.x, deck + 5f * kv, dc.y), rOct, rOct, marble, 8);km.Shaft(new Vector3(dc.x, deck + 5f * kv, dc.y), new Vector3(dc.x, deck + 11f * kv, dc.y), rOct, rOct, tiles, 8);km.Cone(new Vector3(dc.x, deck + 11f * kv, dc.y), rOct, 2.5f * k, C(0.62f, 0.62f, 0.60f), 8);km.Shaft(new Vector3(dc.x, deck + 11f * kv, dc.y), new Vector3(dc.x, deck + 19f * kv, dc.y), 11f * k, 11f * k, tiles, 16);km.Dome(dc.x, dc.y, deck + 19f * kv, 11f * k, lead, 16, 6);+ AtWorldScale(s.Id, "dome_of_the_rock", km, start, dc, deck, kv);Record(s.Id, "dome_of_the_rock", dc, 0f, 2f * rOct, 2f * rOct, 19f * kv + 11f * k, tiles);n++;// Al-Aqsa (the Qibli Mosque) "located on the south wall of the compound"@@ -226,8 +247,10 @@ namespace Statecraft.Game.Map.Kits// end (16x) and its lead dome.float aw = 700f, al = 360f;var ac = pc + new Vector2(0f, -0.5f * pl + 0.5f * al + 40f);+ start = km.CutStart();km.Box(ac.x, ac.y, 0f, aw, al, deck - 60f, deck, 300f, C(0.84f, 0.77f, 0.62f), C(0.70f, 0.70f, 0.68f), Facade.Stone, 16f);km.Dome(ac.x, ac.y + 0.3f * al, deck + 280f, 0.45f * aw, C(0.55f, 0.56f, 0.57f), 12, 5);+ AtWorldScale(s.Id, "al_aqsa", km, start, ac, deck, 16f);Record(s.Id, "al_aqsa", ac, 0f, aw, al, 300f, C(0.84f, 0.77f, 0.62f));n++;}@@ -264,8 +287,10 @@ namespace Statecraft.Game.Map.Kitsvar mid = oc + a0 + dir * (len * (i + 0.5f));if (gap[i]) continue;var (bottom, gy) = GroundSpan(mid, yaw, len, wallT, ground, 1f);+ var start = km.CutStart();km.Box(mid.x, mid.y, yaw, len * 1.01f, wallT, bottom, gy, wallH, stone, top, Facade.Plain, KitScale.Houses);km.Box(mid.x, mid.y, yaw, len * 1.01f, wallT * 0.35f, gy + wallH, gy + wallH, 90f, top, top, Facade.Plain, KitScale.Houses); // the parapet+ AtWorldScale(s.Id, "walls", km, start, mid, gy, KitScale.Houses, yaw, keepLength: true);lots.Add(new Lot { c = mid, r = pieceR, id = s.Id });built++;// A gate tower where a road passes the wall line (a road entered by a gate), else a square tower at every@@ -279,7 +304,9 @@ namespace Statecraft.Game.Map.Kitsvar t = oc + a0 + dir * (len * (i + end) + (byRoad ? (end == 0 ? 1f : -1f) * 0.5f * tw : 0f));if (ground.OnRoute(t, 0.5f * tw + 10f)) continue; // the tower itself stays off the roadvar (tb, ty) = GroundSpan(t, yaw, tw, tw, ground, 1f);+ var tower = km.CutStart();km.Box(t.x, t.y, yaw, tw, tw, tb, ty, th, stone, top, byRoad ? Facade.Stone : Facade.Plain, KitScale.Houses);+ AtWorldScale(s.Id, "wall_tower", km, tower, t, ty, KitScale.Houses);}}foreach (var (gs, at) in gates)@@ -300,7 +327,9 @@ namespace Statecraft.Game.Map.Kits}if (ground.OnRoute(gp, 330f)) continue;var (gb, gy) = GroundSpan(gp, yaw, 650f, 420f, ground, 1f);+ var start = km.CutStart();km.Box(gp.x, gp.y, yaw, 650f, 420f, gb, gy, wallH + 400f, stone, top, Facade.Stone, KitScale.Houses);+ AtWorldScale(s.Id, "gate", km, start, gp, gy, KitScale.Houses);Record(s.Id, "gate", gp, yaw, 650f, 420f, wallH + 400f, stone);}}@@ -312,10 +341,12 @@ namespace Statecraft.Game.Map.Kitsif (Claim(lots, oc + new Vector2(-450f, -150f), 10f * m, s.Id, ground, out var cp)){float y = ground.Y(cp.x, cp.y);+ var start = km.CutStart();km.Box(cp.x, cp.y, 0f, 18f * m, 16f * m, y - 2f * m, y, 12f * m, stone, top, Facade.Stone, m);km.Box(cp.x - 5f * m, cp.y + 4f * m, 0f, 7f * m, 7f * m, y + 12f * m - 1f, y + 12f * m, 6f * m, stone, top, Facade.Stone, m);km.Shaft(new Vector3(cp.x + 6f * m, y, cp.y - 5f * m), new Vector3(cp.x + 6f * m, y + 30f * m, cp.y - 5f * m), 1.7f * m, 1.4f * m, stone, 8);km.Cone(new Vector3(cp.x + 6f * m, y + 30f * m, cp.y - 5f * m), 1.6f * m, 3.5f * m, C(0.62f, 0.62f, 0.58f), 8);+ AtWorldScale(s.Id, "citadel", km, start, cp, y, m);Record(s.Id, "citadel", cp, 0f, 18f * m, 16f * m, 33.5f * m, stone);n++;}@@ -451,6 +482,7 @@ namespace Statecraft.Game.Map.Kitsif (!Claim(lots, want, 5f * m, owner, ground, out var p)) return 0;float y = ground.Y(p.x, p.y), storey = 27f / 5f * m;var stone = C(0.90f, 0.86f, 0.76f);+ var start = km.CutStart();for (int i = 0; i < 5; i++){float w = Mathf.Lerp(7f, 5.6f, i / 4f) * m;@@ -458,6 +490,7 @@ namespace Statecraft.Game.Map.Kits}km.Box(p.x, p.y, 0f, 3.2f * m, 3.2f * m, y + 27f * m - 1f, y + 27f * m, 2.6f * m, stone, stone, Facade.Plain, m, roofed: true);km.Dome(p.x, p.y, y + 29.6f * m, 1.6f * m, C(0.80f, 0.78f, 0.72f));+ AtWorldScale(owner, "white_tower", km, start, p, y, m);Record(owner, "white_tower", p, 0f, 7f * m, 7f * m, 31f * m, stone);return 1;}@@ -468,6 +501,7 @@ namespace Statecraft.Game.Map.Kitsif (!Claim(lots, want, 11f * m, owner, ground, out var p)) return 0; // the lot covers the minaret toofloat y = ground.Y(p.x, p.y);var stone = Jitter(C(0.87f, 0.80f, 0.66f), ref rnd, 0.03f);+ var start = km.CutStart();km.Box(p.x, p.y, 0f, 14f * m, 14f * m, y - 2f * m, y, 7f * m, stone, stone, Facade.Stone, KitScale.Landmarks);km.Dome(p.x, p.y, y + 7f * m - 0.5f * m, 5.5f * m, C(0.80f, 0.80f, 0.76f));float mx = p.x + 8.5f * m, mz = p.y - 6f * m;@@ -475,6 +509,7 @@ namespace Statecraft.Game.Map.Kitskm.Shaft(new Vector3(mx, my - 2f * m, mz), new Vector3(mx, my + 26f * m, mz), 1.6f * m, 1.35f * m, stone, 8);km.Shaft(new Vector3(mx, my + 20f * m, mz), new Vector3(mx, my + 21f * m, mz), 2.1f * m, 2.1f * m, stone, 8); // the balconykm.Cone(new Vector3(mx, my + 26f * m, mz), 1.5f * m, 4.5f * m, C(0.62f, 0.62f, 0.58f), 8);+ AtWorldScale(owner, "mosque", km, start, p, y, m);Record(owner, "mosque", p, 0f, 14f * m, 14f * m, 30.5f * m, stone);return 1;}@@ -493,11 +528,13 @@ namespace Statecraft.Game.Map.Kitsvar (bottom, top) = GroundSpan(p, yaw, w, d, ground, m);var stone = Jitter(C(0.84f, 0.77f, 0.63f), ref rnd, 0.04f);var roof = Jitter(LimeRoof, ref rnd, 0.03f);+ var start = km.CutStart();km.Box(p.x, p.y, yaw, w, d, bottom, top, 5.5f * m, stone, roof, Facade.Stone, m);float a = yaw * Mathf.Deg2Rad, u = 0.5f * w - 1.4f * m, v = -(0.5f * d - 1.4f * m);float mx = p.x + u * Mathf.Cos(a) - v * Mathf.Sin(a), mz = p.y + u * Mathf.Sin(a) + v * Mathf.Cos(a);km.Box(mx, mz, yaw, 2.8f * m, 2.8f * m, top + 5.5f * m - 0.3f * m, top + 5.5f * m, 7.9f * m, stone, roof, Facade.Plain, m);km.Box(mx, mz, yaw, 3.3f * m, 3.3f * m, top + 13.4f * m - 0.2f * m, top + 13.4f * m, 0.6f * m, stone, roof, Facade.Plain, m); // the balcony's parapet+ AtWorldScale(owner, "village_mosque", km, start, p, top, m);Record(owner, "village_mosque", p, yaw, w, d, 14f * m, stone);return 1;}@@ -510,10 +547,12 @@ namespace Statecraft.Game.Map.Kitsvar stone = C(0.86f, 0.76f, 0.57f);if (!Claim(lots, want, 10f * m, owner, ground, out var q)) return false;float yq = ground.Y(q.x, q.y);+ var start = km.CutStart();km.Box(q.x, q.y, 0f, 9f * m, 18f * m, yq - 2f * m, yq, 12f * m, stone, stone, Facade.Stone, m, roofed: true);km.Box(q.x, q.y + 7f * m, 0f, 4.5f * m, 4.5f * m, yq + 12f * m, yq + 12f * m, 14f * m, stone, stone, Facade.Stone, m, roofed: true);km.Pyramid(q.x, q.y + 7f * m, 0f, 4.8f * m, 4.8f * m, yq + 26f * m, 6f * m, C(0.60f, 0.52f, 0.44f));km.Gable(q.x, q.y, 0f, 9f * m, 18f * m, yq + 12f * m, 4f * m, C(0.66f, 0.34f, 0.24f), stone);+ AtWorldScale(owner, "church", km, start, q, yq, m);Record(owner, "church", q, 0f, 9f * m, 18f * m, 32f * m, stone);return true;}diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.Models.cs b/unity/Assets/Scripts/Map/Kits/SettlementKits.Models.csindex 8867663f4..e4a9f22fd 100644--- a/unity/Assets/Scripts/Map/Kits/SettlementKits.Models.cs+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.Models.cs@@ -10,7 +10,8 @@ namespace Statecraft.Game.Map.Kits/// <see cref="ModelScale"/>),/// standing on the plot's ground level with a stone plinth below it where the ground falls away. Far off the kit's/// own buildings draw, exactly as before; up close (TownModelLayer.CloseEnterM) the models draw instead, with each- /// town's close mesh (KitMesh.ToCloseMesh: its landmarks and palms without the kit buildings, plus the plinths). The+ /// town's close mesh (KitMesh.ToCloseMesh: its palms without the kit buildings, plus the plinths and, issue #1032, its+ /// landmarks at the world scale, KitMesh.CloseCopy). The/// layout, the lots and the census do not change.</summary>public static partial class SettlementKits{@@ -42,6 +43,7 @@ namespace Statecraft.Game.Map.Kits}[System.ThreadStatic] static List<ModelInstance>? models;+ [System.ThreadStatic] static List<Placed>? closeLandmarks;[System.ThreadStatic] static Dictionary<string, Settlement>? places;[System.ThreadStatic] static HashSet<string>? onceGiven;@@ -98,12 +100,17 @@ namespace Statecraft.Game.Map.Kitspublic const float PlotGapShare = 0.25f;/// <summary>The most models a plot holds along either of its sides.</summary>public const int MaxPerSide = 4;+ /// <summary>Issue #1032: the most a plot's model is turned off the plot's yaw (degrees).</summary>+ public const float MaxTurnDeg = 10f;+ /// <summary>Issue #1032: the share of a plot's cells left empty (never its first), and the chance a plot three or more+ /// cells long has a street through it (one line of cells left empty).</summary>+ const float EmptyShare = 0.15f, StreetChance = 0.5f;/// <summary>Fills a house's or block's plot with models at the world scale (<see cref="ModelScale"/>): the plot is the/// kit's building at the kit's symbolic scale, several times the building at the world scale, so it holds a grid of/// them (as many as fit along each side with <see cref="PlotGapShare"/> between them, at most/// <see cref="MaxPerSide"/> a side), each one of <paramref name="from"/> (TownModels.Pick at its own spot), turned- /// with the plot and centred on it, on the plot's ground level. A place's first house is its+ /// with the plot and laid out round its centre, on the plot's ground level; the grid is broken up (issue #1032, below). A place's first house is its/// <see cref="TownModels.Once"/> building, alone on its plot. One plinth stands under the group where the ground falls/// away.</summary>static void PlaceModel(string id, TownModel[] from, Vector2 p, float yaw, float w, float d, float h, float bottom, float top, KitMesh km,@@ -124,16 +131,45 @@ namespace Statecraft.Game.Map.Kitsint nu = once ? 1 : Mathf.Clamp(Mathf.FloorToInt((w + gap) / pu), 1, MaxPerSide);int nv = once ? 1 : Mathf.Clamp(Mathf.FloorToInt((d + gap) / pv), 1, MaxPerSide);float a = yaw * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);+ // Issue #1032: not a regular grid (it read as regular clusters). Seeded by the place and the plot, not the town's+ // stream, so the kit's layout and census stay: a plot three or more cells long may get a street through it, some+ // cells stay empty (never the first), and each model is turned up to MaxTurnDeg and moved within its cell, inside+ // the plot and a quarter gap clear of each inner side, so no two touch. One that cannot turn in its cell stands+ // square; one bigger than its plot stands at the cell's centre, as before.+ var rnd = new KitRandom(KitRandom.Fnv1a(id) ^ ((ulong)(uint)Mathf.RoundToInt(p.x) * 0x9E3779B97F4A7C15UL)+ ^ ((ulong)(uint)Mathf.RoundToInt(p.y) * 0xC2B2AE3D27D4EB4FUL) ^ 0x1032UL);+ int streetU = -1, streetV = -1;+ if (!once && Mathf.Max(nu, nv) >= 3 && rnd.Chance(StreetChance))+ {+ if (nu >= nv) streetU = rnd.Range(1, nu - 1); else streetV = rnd.Range(1, nv - 1);+ }for (int i = 0; i < nu; i++)for (int j = 0; j < nv; j++){- float u = (i - 0.5f * (nu - 1)) * pu, v = (j - 0.5f * (nv - 1)) * pv;+ bool firstCell = i == 0 && j == 0;+ if (!firstCell && (i == streetU || j == streetV || rnd.Chance(EmptyShare))) continue;+ float u0 = (i - 0.5f * (nu - 1)) * pu, v0 = (j - 0.5f * (nv - 1)) * pv;+ var model = firstCell ? first : TownModels.Pick(from, id, p + new Vector2(u0 * ca - v0 * sa, u0 * sa + v0 * ca), out flip);+ float turn = once ? 0f : rnd.Range(-MaxTurnDeg, MaxTurnDeg), du = rnd.Value(), dv = rnd.Value();+ // The cell: from the plot's edge on an outer side, a quarter gap inside the grid's line on an inner one.+ float loU = i == 0 ? -0.5f * w : u0 - 0.5f * pu + 0.25f * gap, hiU = i == nu - 1 ? 0.5f * w : u0 + 0.5f * pu - 0.25f * gap;+ float loV = j == 0 ? -0.5f * d : v0 - 0.5f * pv + 0.25f * gap, hiV = j == nv - 1 ? 0.5f * d : v0 + 0.5f * pv - 0.25f * gap;+ float u = u0, v = v0;+ for (int tries = 0; tries < 2; tries++, turn = 0f)+ {+ var probe = Fit(id, model, p, yaw + turn, w, d, h, top, exactHeight, flip, m);+ float t = turn * Mathf.Deg2Rad, ct = Mathf.Abs(Mathf.Cos(t)), st = Mathf.Abs(Mathf.Sin(t));+ float eu = 0.5f * (probe.W * ct + probe.D * st), ev = 0.5f * (probe.W * st + probe.D * ct);+ if (loU + eu > hiU - eu || loV + ev > hiV - ev) continue;+ u = Mathf.Lerp(loU + eu, hiU - eu, du); v = Mathf.Lerp(loV + ev, hiV - ev, dv);+ break;+ }var q = p + new Vector2(u * ca - v * sa, u * sa + v * ca);- var model = i == 0 && j == 0 ? first : TownModels.Pick(from, id, q, out flip);- models.Add(Fit(id, model, q, yaw, w, d, h, top, exactHeight, flip, m).OnPlot(p));+ models.Add(Fit(id, model, q, yaw + turn, w, d, h, top, exactHeight, flip, m).OnPlot(p));}if (top - bottom > PlinthRiseM * m)- km.Plinths.Box(p.x, p.y, yaw, nu * pu - gap, nv * pv - gap, bottom, top, 0f, TerraceStone, TerraceStone, Facade.Plain, m, roofed: true);+ km.Plinths.Box(p.x, p.y, yaw, Mathf.Max(w, nu * pu - gap), Mathf.Max(d, nv * pv - gap), bottom, top, // #1032: models may stand out to the plot edge+ 0f, TerraceStone, TerraceStone, Facade.Plain, m, roofed: true);}static void AddModel(string id, TownModel model, Vector2 p, float yaw, float w, float d, float h, float bottom, float top, KitMesh km,diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.Moshav.cs b/unity/Assets/Scripts/Map/Kits/SettlementKits.Moshav.csindex 91533621e..94e99d2d1 100644--- a/unity/Assets/Scripts/Map/Kits/SettlementKits.Moshav.cs+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.Moshav.cs@@ -35,8 +35,10 @@ namespace Statecraft.Game.Map.Kitsfloat yaw = RingYaw(p - heart);var (bottom, top) = GroundSpan(p, yaw, w, d, ground, m);var wall = C(0.91f, 0.86f, 0.75f); var roof = C(0.70f, 0.30f, 0.20f);+ var start = km.CutStart();km.Box(p.x, p.y, yaw, w, d, bottom, top, h, wall, roof, Facade.Village, m, roofed: true);km.Gable(p.x, p.y, yaw, w, d, top + h, d * 0.42f, roof, wall);+ AtWorldScale(owner, "public_building", km, start, p, top, m); // #1032Record(owner, "public_building", p, yaw, w, d, h, wall);return 1;}diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.Outpost.cs b/unity/Assets/Scripts/Map/Kits/SettlementKits.Outpost.csindex b161d1707..8e37cd78f 100644--- a/unity/Assets/Scripts/Map/Kits/SettlementKits.Outpost.cs+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.Outpost.cs@@ -23,7 +23,8 @@ namespace Statecraft.Game.Map.Kits/// <summary>A Negev lookout at <paramref name="heart"/>, on the settlement's grid angle: the walled yard with its gate,/// the lookout tower in one corner, the living quarters along the opposite side and the service buildings along a/// third, all flat-roofed. One lot for the whole yard; nothing is built when no free dry spot takes it. Returns how- /// many things were built (the yard, the tower and the four buildings, or 0).</summary>+ /// many things were built (the yard, the tower and the four buildings, or 0). Up close (issue #1032) the yard, its+ /// tower and its rooms are copied as one landmark at the models' scale, so they keep their places in the yard.</summary>static int NegevOutpostKit(Settlement s, Vector2 heart, KitGround ground, KitMesh km, Lots lots){float m = KitScale.Houses, side = OutpostSide * m, half = 0.5f * side;@@ -31,6 +32,7 @@ namespace Statecraft.Game.Map.Kitsfloat yaw = GridYaw(s.Id), a = yaw * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);Vector2 At(float u, float v) => c + new Vector2(u * ca - v * sa, u * sa + v * ca) * m;var stone = C(0.80f, 0.74f, 0.63f); var concrete = C(0.86f, 0.84f, 0.79f); var roof = C(0.72f, 0.70f, 0.66f);+ var start = km.CutStart();// The wall: four sides, the +v one broken by the gate (3 m wide, on the -u side of the middle).float h = 0.5f * OutpostSide, t = OutpostWallT;var pieces = new (float u, float v, float w, float d)[]@@ -71,6 +73,7 @@ namespace Statecraft.Game.Map.KitsRecord(s.Id, i == 0 ? "dining_hall" : "building", p, yaw, w * m, d * m, bh, concrete);if (i == 0) kibbutzHalls++;}+ AtWorldScale(s.Id, "outpost_yard", km, start, c, ground.Y(c.x, c.y), m); // #1032: the whole yard, as one landmarkreturn 2 + rooms.Length;}}diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.cs b/unity/Assets/Scripts/Map/Kits/SettlementKits.csindex 8c1498218..60540c8e0 100644--- a/unity/Assets/Scripts/Map/Kits/SettlementKits.cs+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.cs@@ -64,12 +64,14 @@ namespace Statecraft.Game.Map.Kits/// <summary>One thing a kit placed, for the tests' and the docs' town census: a building (<see cref="Placed.Kind"/>/// "building", or "wing" for a block's lower part), a street palm ("palm": its crown's square, its height) or a/// landmark (its name: "mosque", "clock_tower", ...), with its- /// world footprint (centre, yaw in degrees, width and depth in m), its wall height (m) and wall colour.</summary>+ /// world footprint (centre, yaw in degrees, width and depth in m), its wall height (m) and wall colour; a landmark's+ /// close copy (issue #1032, <see cref="Result.CloseLandmarks"/>) also its ground level <see cref="Y"/>, the+ /// level its height stands over.</summary>public readonly struct Placed{- public readonly string Id, Kind; public readonly Vector2 C; public readonly float Yaw, W, D, H; public readonly Color32 Wall;- public Placed(string id, string kind, Vector2 c, float yaw, float w, float d, float h, Color32 wall)- { Id = id; Kind = kind; C = c; Yaw = yaw; W = w; D = d; H = h; Wall = wall; }+ public readonly string Id, Kind; public readonly Vector2 C; public readonly float Yaw, W, D, H, Y; public readonly Color32 Wall;+ public Placed(string id, string kind, Vector2 c, float yaw, float w, float d, float h, Color32 wall, float y = 0f)+ { Id = id; Kind = kind; C = c; Yaw = yaw; W = w; D = d; H = h; Wall = wall; Y = y; }/// <summary>Harbour works stand in the sea by design; everything else stands on land.</summary>public bool InSea => Kind == "port" || Kind == "breakwater";}@@ -115,6 +117,10 @@ namespace Statecraft.Game.Map.Kits/// mesh without the buildings and with the models' plinths (KitMesh.ToCloseMesh), by the kit mesh's name; none/// where nothing would be left.</summary>public Dictionary<string, Mesh> Close = new Dictionary<string, Mesh>();+ /// <summary>Issue #1032: every kit landmark as the close mesh draws it, at the models' world scale+ /// (SettlementKits.AtWorldScale): its kind, its anchor, and its copy's box (width along x, depth along z, height+ /// over its ground level Y), in placement order.</summary>+ public List<Placed> CloseLandmarks = new List<Placed>();}/// <summary>Side of the square tiles the localities' and camps' buildings are merged into (the trees' tile size).</summary>@@ -128,11 +134,11 @@ namespace Statecraft.Game.Map.Kits{kibbutzHalls = farmSheds = 0;var result = new Result();- models = result.Models; places = new Dictionary<string, Settlement>(); onceGiven = new HashSet<string>();+ models = result.Models; closeLandmarks = result.CloseLandmarks; places = new Dictionary<string, Settlement>(); onceGiven = new HashSet<string>();foreach (var s in towns) places[s.Id] = s;foreach (var s in localities) places[s.Id] = s;try { return Build(towns, localities, camps, ground, columns, result); }- finally { models = null; places = null; onceGiven = null; }+ finally { models = null; closeLandmarks = null; places = null; onceGiven = null; }}static Result Build(IReadOnlyList<Settlement> towns, IReadOnlyList<Settlement> localities, IReadOnlyList<Localities.Area> camps,diff --git a/unity/Assets/Tests/EditMode/TownModelScaleTests.cs b/unity/Assets/Tests/EditMode/TownModelScaleTests.csindex b0a9406b5..d4b732ae5 100644--- a/unity/Assets/Tests/EditMode/TownModelScaleTests.cs+++ b/unity/Assets/Tests/EditMode/TownModelScaleTests.cs@@ -36,18 +36,22 @@ public class TownModelScaleTestsM.B04aStoneBalconies, M.B04bLoadingDoors, M.B07DiningHall, M.B23Winery, M.B24Barn, M.B32CargoShed,};- static List<SettlementKits.ModelInstance> Models(out MapScene map)+ static List<SettlementKits.ModelInstance> Models(out MapScene map) => Built(out map, out _).Models;++ /// <summary>The map's settlements built; their meshes destroyed, except the close meshes when <paramref name="keepClose"/>+ /// (the caller destroys those).</summary>+ static SettlementKits.Result Built(out MapScene map, out List<SettlementKits.Placed> placed, bool keepClose = false){EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);map = UnityEngine.Object.FindFirstObjectByType<MapScene>(); map.Build();var g = new KitGround(map.Terrain, map.Frame, map.Hexes, map.ElevMinM);foreach (var c in map.RouteCorridors) g.AddCorridor(c.line, c.halfWidth);foreach (var c in map.UnitClearings) g.AddCorridor(new List<Vector2> { c.centre, c.centre + Vector2.right }, c.radius);- var built = SettlementKits.Build(map.Settlements, map.Localities.Select(p => p.Settlement).ToList(), new List<Localities.Area>(), g, out _);+ var built = SettlementKits.Build(map.Settlements, map.Localities.Select(p => p.Settlement).ToList(), new List<Localities.Area>(), g, out placed);foreach (var k in built.Towns) UnityEngine.Object.DestroyImmediate(k.mesh);foreach (var t in built.Tiles) UnityEngine.Object.DestroyImmediate(t.mesh);- foreach (var c in built.Close.Values) UnityEngine.Object.DestroyImmediate(c);- return built.Models;+ if (!keepClose) foreach (var c in built.Close.Values) UnityEngine.Object.DestroyImmediate(c);+ return built;}/// <summary>A placed model's four ground corners (world x/z) and its height (m): its mesh-space box through its matrix.</summary>@@ -172,4 +176,160 @@ public class TownModelScaleTestsTestContext.WriteLine(byTowns.Count == 0 ? "no overlaps" : string.Join("; ", byTowns.OrderByDescending(kv => kv.Value).Select(kv => $"{kv.Key}: {kv.Value}")));CollectionAssert.IsEmpty(byTowns.Keys.Take(15), $"{byTowns.Values.Sum()} overlapping pairs between settlements");}++ /// <summary>Issue #1032: each kit landmark's real height (m), the tallest part the kit draws for it, read off the kit's+ /// own parts (SettlementKits.Landmarks.cs, .Moshav.cs, .Outpost.cs). The harbour works (low, in the sea), the Haram's+ /// platform (ground, sized in metres to hold the Old City's lots) and the palms (trees) are not buildings and keep the+ /// kit's size.</summary>+ static readonly Dictionary<string, float> LandmarkRealM = new Dictionary<string, float>+ {+ ["mosque"] = 30.5f, // the minaret's 26 m shaft and its 4.5 m cap+ ["village_mosque"] = 14f, // the hall's 5.5 m, the minaret's 7.9 m and its parapet+ ["church"] = 32f, // the nave's 12 m, the belfry's 14 m and its 6 m roof+ ["clock_tower"] = 31.5f,+ ["lighthouse"] = 16.7f,+ ["white_tower"] = 31.2f, // five storeys of 27 m, the lantern and its dome+ ["citadel"] = 33.5f, // the minaret and its cap+ ["dome_of_the_rock"] = 25.6f, // its walls and drum (19 m at 30x) and its dome (11 m at 18x): 768 m at 30x+ ["al_aqsa"] = 37.2f, // its hall and its dome, 595 m over the platform at 16x+ ["walls"] = 9.9f, // Suleiman's walls and their parapet at 100x+ ["wall_tower"] = 13f, // a tower by a gate (the others 11.6 m)+ ["gate"] = 13f,+ ["public_building"] = 6.8f, // Nahalal's hall: 1.3 storeys and its gable+ ["outpost_yard"] = 10.5f, // the lookout tower and its cap+ };++ /// <summary>Issue #1032 (follow-up to #1030): the kit landmarks (mosques, domes, church towers, walls, lighthouses, the+ /// Jaffa clock tower) drew up close at the kits' 60x and 100x, so they towered over the 24x house models. Up close every+ /// kit landmark stands at the models' rule, real height x <see cref="SettlementKits.ModelScale"/> (the locomotive's car+ /// over the reference house): between 0.45 and 1.15 of it. A landmark is never drawn bigger up close than far off, so+ /// the floor lets the ones fitted smaller keep their size: the Haram's Al-Aqsa and the citadel (16x and 20x, fitted to+ /// the symbolic Old City) and the village mosques at Tel Aviv's street crossings (#318, about 12x); a scale that+ /// collapsed by half fails. Above 1.15 is the kit's own scale coming back (a mosque's minaret stands on its own ground,+ /// a little above or below the hall's). Every landmark the census records has its close copy.</summary>+ [Test]+ public void EveryKitLandmarkStandsAtTheModelsScaleUpClose()+ {+ var built = Built(out _, out var placed);+ var close = built.CloseLandmarks;+ float scale = SettlementKits.ModelScale;+ Assert.AreEqual(LocoM / SettlementKits.ReferenceHouseM, scale, 0.01f, "the locomotive rule");+ var bad = new List<string>();+ foreach (var l in close)+ {+ if (!LandmarkRealM.TryGetValue(l.Kind, out var real)) { bad.Add($"{l.Id} {l.Kind}: no real height listed"); continue; }+ float k = l.H / (real * scale);+ if (k < 0.45f || k > 1.15f) bad.Add($"{l.Id} {l.Kind}: {l.H:0} m tall up close, {k:0.00} of {real} m x {scale:0}");+ }+ foreach (var kind in LandmarkRealM.Keys)+ {+ if (kind == "walls" || kind == "wall_tower") continue; // the census records the circuit once, the kit draws it in pieces+ int want = placed.Count(p => p.Kind == kind), got = close.Count(l => l.Kind == kind);+ if (want != got) bad.Add($"{kind}: {want} in the census, {got} up close");+ }+ TestContext.WriteLine(string.Join("; ", close.GroupBy(l => l.Kind).OrderBy(g => g.Key)+ .Select(g => $"{g.Key} x{g.Count()} {g.Max(l => l.H):0} m ({g.Max(l => l.H) / (LandmarkRealM.TryGetValue(g.Key, out var r) ? r : 1f):0.0}x)")));+ CollectionAssert.IsSubsetOf(LandmarkRealM.Keys, close.Select(l => l.Kind).Distinct().ToList(), "every kind of kit landmark is on the map");+ CollectionAssert.IsEmpty(bad.Take(15), $"{bad.Count} landmarks off the models' scale");+ }++ /// <summary>Issue #1032, the owner's review of #1048: the close mesh itself draws each kit landmark at the models' scale,+ /// not only its record. KitMesh.CloseCopy cuts the kit-scale landmark (CutEnd) and draws the shrunk copy instead; without+ /// the cut the 60x or 100x original stands in the close mesh beside its copy and towers over the 24x houses again. So+ /// round each close landmark's anchor no close-mesh vertex stands higher than its copy's top (its ground level Y plus+ /// its height H, 1 m for float rounding), or a neighbouring copy's whose circle meets it. The circle is the copy's+ /// smaller half side, so a neighbour's palm or plinth stays out; a wall piece's circle (its thickness, mid-length) holds+ /// no vertex and is skipped, its towers and gates are checked.</summary>+ [Test]+ public void TheCloseMeshDrawsEveryKitLandmarkAtItsCopysHeight()+ {+ var built = Built(out _, out _, keepClose: true);+ try+ {+ // Every close mesh's vertices, bucketed on a 200 m grid. The close meshes keep no CPU copy (UploadMeshData), so+ // their positions are read back from the vertex buffer.+ const float Cell = 200f;+ var grid = new Dictionary<(int, int), List<Vector3>>();+ foreach (var m in built.Close.Values)+ foreach (var v in Positions(m))+ {+ var key = (Mathf.FloorToInt(v.x / Cell), Mathf.FloorToInt(v.z / Cell));+ if (!grid.TryGetValue(key, out var l)) grid[key] = l = new List<Vector3>();+ l.Add(v);+ }+ var bad = new List<string>();+ int checkedSites = 0;+ foreach (var l in built.CloseLandmarks)+ {+ float r = 0.5f * Mathf.Min(l.W, l.D), top = float.MinValue;+ for (int x = Mathf.FloorToInt((l.C.x - r) / Cell); x <= Mathf.FloorToInt((l.C.x + r) / Cell); x++)+ for (int z = Mathf.FloorToInt((l.C.y - r) / Cell); z <= Mathf.FloorToInt((l.C.y + r) / Cell); z++)+ if (grid.TryGetValue((x, z), out var cell))+ foreach (var v in cell)+ if ((new Vector2(v.x, v.z) - l.C).sqrMagnitude <= r * r) top = Mathf.Max(top, v.y);+ if (top == float.MinValue) continue;+ checkedSites++;+ // A neighbouring copy whose circle meets this one (a gate beside its tower, on higher ground) may stand higher.+ float limit = built.CloseLandmarks.Where(o => (o.C - l.C).magnitude < r + 0.5f * Mathf.Min(o.W, o.D)).Max(o => o.Y + o.H);+ if (top > limit + 1f) bad.Add($"{l.Id} {l.Kind}: the close mesh stands {top - l.Y:0} m over its ground, its copy {l.H:0} m");+ }+ TestContext.WriteLine($"{checkedSites} of {built.CloseLandmarks.Count} landmark sites checked");+ Assert.Greater(checkedSites, built.CloseLandmarks.Count * 3 / 4, "most landmark sites have close-mesh vertices");+ CollectionAssert.IsEmpty(bad.Take(15), $"{bad.Count} landmarks drawn above their copy in the close mesh");+ }+ finally { foreach (var c in built.Close.Values) UnityEngine.Object.DestroyImmediate(c); }+ }++ /// <summary>A mesh's vertex positions, read back from its vertex buffer when it keeps no CPU copy.</summary>+ static Vector3[] Positions(Mesh m)+ {+ if (m.isReadable) return m.vertices;+ // The readback needs the editor's graphics device (not -nographics) and float32 x 3 positions (SetVertices).+ Assert.AreEqual(UnityEngine.Rendering.VertexAttributeFormat.Float32, m.GetVertexAttributeFormat(UnityEngine.Rendering.VertexAttribute.Position), m.name);+ Assert.AreEqual(3, m.GetVertexAttributeDimension(UnityEngine.Rendering.VertexAttribute.Position), m.name);+ int s = m.GetVertexAttributeStream(UnityEngine.Rendering.VertexAttribute.Position);+ int off = m.GetVertexAttributeOffset(UnityEngine.Rendering.VertexAttribute.Position) / 4, stride = m.GetVertexBufferStride(s) / 4;+ using var buf = m.GetVertexBuffer(s);+ var raw = new float[m.vertexCount * stride];+ buf.GetData(raw);+ var p = new Vector3[m.vertexCount];+ for (int i = 0; i < p.Length; i++) p[i] = new Vector3(raw[i * stride + off], raw[i * stride + off + 1], raw[i * stride + off + 2]);+ return p;+ }++ /// <summary>The products of two plot sides of 1 to <see cref="SettlementKits.MaxPerSide"/>: the counts a full grid holds.</summary>+ static readonly HashSet<int> GridCounts = new HashSet<int>(+ Enumerable.Range(1, SettlementKits.MaxPerSide).SelectMany(a => Enumerable.Range(1, SettlementKits.MaxPerSide).Select(b => a * b)));++ /// <summary>Issue #1032: a kit plot's models no longer sit in a regular grid (they read as regular clusters): each is+ /// turned a little off the plot (up to <see cref="SettlementKits.MaxTurnDeg"/>) and moved within its cell, the group is+ /// off the plot's centre, and some cells are left empty (a varied count, a street through the plot). Seeded: two builds+ /// place every model at the same matrix; and no two models of one plot overlap.</summary>+ [Test]+ public void APlotsModelsAreSeededAndNotARegularGrid()+ {+ var a = Models(out _); var b = Models(out _);+ Assert.AreEqual(a.Count, b.Count, "two builds place as many models");+ for (int i = 0; i < a.Count; i++)+ if (a[i].Model != b[i].Model || a[i].M != b[i].M) Assert.Fail($"model {i} ({a[i].Id} {a[i].Model}) differs between two builds");+ var plots = a.GroupBy(m => (m.Id, m.Plot)).Where(g => g.Count() > 1).Select(g => g.ToList()).ToList();+ Assert.Greater(plots.Count, 500);+ int turned = 0, offCentre = 0, uneven = 0;+ var bad = new List<string>();+ foreach (var g in plots)+ {+ var plot = g[0].Plot;+ if (g.Select(m => Mathf.Round(m.Yaw * 10f)).Distinct().Count() > 1) turned++;+ if ((g.Aggregate(Vector2.zero, (s, m) => s + m.C) / g.Count - plot).magnitude > 1f) offCentre++;+ if (!GridCounts.Contains(g.Count)) uneven++;+ for (int i = 0; i < g.Count; i++)+ for (int j = i + 1; j < g.Count; j++)+ if (Overlap(Box(g[i]).quad, Box(g[j]).quad, 1f)) bad.Add($"{g[i].Id} at {plot}: {g[i].Model} and {g[j].Model} overlap");+ }+ TestContext.WriteLine($"{plots.Count} plots with several models: {turned} turned, {offCentre} off centre, {uneven} with a count no grid holds");+ Assert.Greater(turned, plots.Count / 2, "the models are turned off their plot");+ Assert.Greater(offCentre, plots.Count / 2, "the groups are off their plot's centre");+ Assert.Greater(uneven, plots.Count / 10, "some cells are left empty");+ CollectionAssert.IsEmpty(bad.Take(15), $"{bad.Count} overlapping models within a plot");+ }}diff --git a/unity/Assets/Tests/EditMode/TownModelTests.cs b/unity/Assets/Tests/EditMode/TownModelTests.csindex 0bd5dac97..2cf55b001 100644--- a/unity/Assets/Tests/EditMode/TownModelTests.cs+++ b/unity/Assets/Tests/EditMode/TownModelTests.cs@@ -118,7 +118,7 @@ public class TownModelTests/// <summary>Every building the census records (and every water tower and port warehouse) is built of models on its plot:/// at the world scale (SettlementKits.ModelScale) a kit plot holds a grid of them (a water tower, a warehouse, a dining- /// hall and a place's one-off building one), each turned with the plot and inside its footprint; no other model is+ /// hall and a place's one-off building one), each turned with the plot (up to SettlementKits.MaxTurnDeg off it, #1032) and inside its footprint; no other model is/// placed.</summary>[Test]public void EveryPlacedBuildingIsOneModelOnItsPlot()@@ -144,7 +144,7 @@ public class TownModelTestsfloat a = p.Yaw * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);foreach (var mi in at){- if (Mathf.Abs(mi.Yaw - p.Yaw) > 0.01f) bad.Add($"{p.Id} {p.Kind} at {p.C}: turned off its plot");+ if (Mathf.Abs(Mathf.DeltaAngle(mi.Yaw, p.Yaw)) > SettlementKits.MaxTurnDeg + 0.01f) bad.Add($"{p.Id} {p.Kind} at {p.C}: turned off its plot"); // #1032: up to MaxTurnDegcorners.Clear(); mi.Corners(corners);foreach (var c in corners){