Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Map: roof geometry for the far kit buildings (parapets, set-back top storeys, roof tanks) (#2371)

Eyal Golandca38b735322
diff --git a/changelog.d/3d-kit-geometry.md b/changelog.d/3d-kit-geometry.md
new file mode 100644
index 000000000..e719f2422
--- /dev/null
+++ b/changelog.d/3d-kit-geometry.md
@@ -0,0 +1,6 @@
+- The map's far-off kit buildings have more geometry on their roofs: the flat roofs of Haifa's Hadar and the cities'
+ other white blocks, of Jerusalem's stone blocks and of the old towns' houses get a parapet, and so do about half the
+ flat-roofed houses of the Arab towns and villages (the plastered blocks of the moshava towns' centres keep a bare
+ roof); some of Tel Aviv's taller blocks set their top storey back from the street, and some White City stair heads
+ carry a water tank. Each building's detail comes from its own position,
+ so no building moves; up close Tal Heuberger's models still replace them.
diff --git a/unity/Assets/Scripts/Map/Kits/KitMesh.cs b/unity/Assets/Scripts/Map/Kits/KitMesh.cs
index bfdf8ab86..ffb823f39 100644
--- a/unity/Assets/Scripts/Map/Kits/KitMesh.cs
+++ b/unity/Assets/Scripts/Map/Kits/KitMesh.cs
@@ -262,9 +262,10 @@ namespace Statecraft.Game.Map.Kits
/// (<paramref name="x"/>, <paramref name="z"/>), <paramref name="w"/> wide along its own x after a yaw of
/// <paramref name="yawDeg"/>, <paramref name="d"/> deep; walls from <paramref name="bottom"/> (sunk into the slope) to
/// <paramref name="ground"/> + <paramref name="h"/>. <paramref name="metresPerReal"/> turns world metres into real
- /// metres for the facade uv (the symbolic scale).</summary>
+ /// metres for the facade uv (the symbolic scale). With <paramref name="parapet"/> above 0 and a flat roof, a plastered
+ /// rim stands round the roof's edge (Parapet).</summary>
public void Box(float x, float z, float yawDeg, float w, float d, float bottom, float ground, float h, Color32 wall, Color32 roof,
- Facade facade, float metresPerReal, bool roofed = false)
+ Facade facade, float metresPerReal, bool roofed = false, float parapet = 0f, float parapetThickness = 0f)
{
var c = Corners(x, z, yawDeg, w, d);
float top = ground + h;
@@ -282,9 +283,34 @@ namespace Statecraft.Game.Map.Kits
var r = roof; r.a = 0;
Face(new Vector3(c[0].x, top, c[0].y), new Vector3(c[3].x, top, c[3].y), new Vector3(c[2].x, top, c[2].y), new Vector3(c[1].x, top, c[1].y), r,
Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero);
+ if (parapet > 0f && 2f * parapetThickness < Mathf.Min(w, d)) Parapet(c, Corners(x, z, yawDeg, w - 2f * parapetThickness, d - 2f * parapetThickness), top, parapet, wall);
}
}
+ /// <summary>A flat roof's parapet: a rim <paramref name="height"/> high on the roof
+ /// at <paramref name="roofY"/>, between the footprint's corners <paramref name="outer"/> and the inner corners
+ /// <paramref name="inner"/> (both as Corners gives them). Its outer face continues the wall upwards but is Plain (no
+ /// window rows), so it reads as a light band at the roof's edge; its inner face looks onto the roof; its top is one
+ /// ring of 8 vertices. 40 vertices in all.</summary>
+ void Parapet(Vector2[] outer, Vector2[] inner, float roofY, float height, Color32 colour)
+ {
+ colour.a = (byte)Facade.Plain;
+ float y = roofY + height;
+ Vector3 P(Vector2 q, float h) => new Vector3(q.x, h, q.y);
+ for (int i = 0; i < 4; i++)
+ {
+ int j = (i + 1) % 4;
+ // Outside (as Box's walls), then inside: the same edge reversed, so it faces the roof.
+ Face(P(outer[i], roofY), P(outer[i], y), P(outer[j], y), P(outer[j], roofY), colour, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero);
+ Face(P(inner[j], roofY), P(inner[j], y), P(inner[i], y), P(inner[i], roofY), colour, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero);
+ }
+ int o = pos.Count;
+ for (int i = 0; i < 4; i++) V(P(outer[i], y), Vector3.up, colour, Vector2.zero);
+ for (int i = 0; i < 4; i++) V(P(inner[i], y), Vector3.up, colour, Vector2.zero);
+ // Clockwise seen from above, as the roof (outer i, inner i, inner i+1, outer i+1).
+ for (int i = 0; i < 4; i++) { int j = (i + 1) % 4; Quad(o + i, o + 4 + i, o + 4 + j, o + j); }
+ }
+
/// <summary>A gable roof on a w x d box whose walls end at <paramref name="eaves"/>: the ridge runs along the longer
/// side, <paramref name="rise"/> above the eaves, with a small overhang.</summary>
public void Gable(float x, float z, float yawDeg, float w, float d, float eaves, float rise, Color32 roof, Color32 gableWall)
diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.TelAviv.cs b/unity/Assets/Scripts/Map/Kits/SettlementKits.TelAviv.cs
index 58770dcd7..65dc4f803 100644
--- a/unity/Assets/Scripts/Map/Kits/SettlementKits.TelAviv.cs
+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.TelAviv.cs
@@ -47,7 +47,8 @@ namespace Statecraft.Game.Map.Kits
/// <summary>Draws one Tel Aviv block and records it in the census: warm cream plaster (#658; a few a slightly yellower cream), ribbon windows
/// along both long sides (Ribbons), a balcony band on every upper storey (WhiteBlockDetail), some on pilotis, some stepped, and a
- /// flat roof terrace behind a parapet with its stair head.</summary>
+ /// flat roof terrace behind a parapet with its stair head; with RoofDetail, some set their top storey back from the street
+ /// and some stair heads carry a water tank.</summary>
static void TelAvivBlock(string id, Vector2 p, float yaw, Spec b, float bottom, float top, KitMesh km, ref KitRandom rnd)
{
float m = KitScale.CityBlocks, storey = 3.3f * m, a = yaw * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);
@@ -70,34 +71,81 @@ namespace Statecraft.Game.Map.Kits
RoofParapet(km, c2, yaw, w2, d2, top + h2, wall, m);
Record(id, "wing", c2, yaw, w2, d2, h2, wall);
}
+ // Roof detail (SettlementKits.RoofDetail), from the block's own stream: some taller blocks set their top storey back
+ // from the street (the main block then ends a storey lower, its roof the top storey's terrace).
+ var detail = DetailAt(p, 53);
+ bool setback = RoofDetail && b.storeys >= SetbackMinStoreys && detail.Chance(SetbackShare);
+ float body = setback ? h - storey : h;
if (pilotis)
{
// The ground storey stands back under the block, in the block's shadow; the block above starts one storey up.
var shade = C(wall.r / 255f * 0.62f, wall.g / 255f * 0.62f, wall.b / 255f * 0.64f);
km.Box(c.x, c.y, yaw, w * 0.72f, b.d * 0.6f, bottom, top, storey, shade, shade, Facade.Plain, m, roofed: true);
- km.Box(c.x, c.y, yaw, w, b.d, top + storey - 0.3f * m, top + storey, h - storey, wall, terrace, Facade.WhiteCity, m);
- Ribbons(km, c, yaw, w, b.d, top + storey, h - storey, m);
+ km.Box(c.x, c.y, yaw, w, b.d, top + storey - 0.3f * m, top + storey, body - storey, wall, terrace, Facade.WhiteCity, m);
+ Ribbons(km, c, yaw, w, b.d, top + storey, body - storey, m);
}
else
{
- km.Box(c.x, c.y, yaw, w, b.d, bottom, top, h, wall, terrace, Facade.WhiteCity, m);
- Ribbons(km, c, yaw, w, b.d, top, h, m);
+ km.Box(c.x, c.y, yaw, w, b.d, bottom, top, body, wall, terrace, Facade.WhiteCity, m);
+ Ribbons(km, c, yaw, w, b.d, top, body, m);
}
- WhiteBlockDetail(km, c, du, b.lotR, yaw, w, b.d, top, h, wall, terrace, m, ref rnd);
- RoofParapet(km, c, yaw, w, b.d, top + h, wall, m);
- // The stair head and the shared laundry room on the terrace.
+ WhiteBlockDetail(km, c, du, b.lotR, yaw, w, b.d, top, body, wall, terrace, m, ref rnd);
+ RoofParapet(km, c, yaw, w, b.d, top + body, wall, m);
+ // The set-back top storey: back from the street side (-v, WhiteBlockDetail's) by SetbackMinM to SetbackMaxM, and in from the other
+ // three sides by SetbackInsetM, clear of the parapet; pw x pd at (du + pu, pv) in the block's frame (TelAvivRoofLayout).
+ float back = 0f, topShare = 1f, shift = 0f;
+ if (setback) { back = detail.Range(SetbackMinM, SetbackMaxM); topShare = detail.Range(0.6f, 0.85f); shift = detail.Range(-0.5f, 0.5f); }
+ // The stair head (on the top storey's roof on a set-back block: pw >= 0.6 w and pd >= 0.65 d keep it inside) and
+ // the shared laundry room on the terrace (none beside a set-back top storey, which is the roof's room). Both draw
+ // their numbers either way, so the town's stream is unchanged.
float rw = w * rnd.Range(0.2f, 0.3f), rd = b.d * rnd.Range(0.3f, 0.42f);
- var r1 = At(du + rnd.Range(-0.2f, 0.2f) * w, rnd.Range(-0.15f, 0.15f) * b.d);
+ float fu = rnd.Range(-0.2f, 0.2f), fv = rnd.Range(-0.15f, 0.15f);
+ var (pw, pd, pu, pv, su, sv) = TelAvivRoofLayout(w, b.d, m, setback, back, topShare, shift, fu, fv);
+ if (setback)
+ {
+ var pc = At(du + pu, pv);
+ km.Box(pc.x, pc.y, yaw, pw, pd, top + body - 0.3f * m, top + body, storey, wall, terrace, Facade.WhiteCity, m);
+ Ribbons(km, pc, yaw, pw, pd, top + body, storey, m);
+ }
+ var r1 = At(du + su, sv);
km.Box(r1.x, r1.y, yaw, rw, rd, top + h - 2f, top + h, 2.8f * m, wall, terrace, Facade.Plain, m);
+ if (RoofDetail && detail.Chance(RoofTankShare)) RoofTank(km, r1, yaw, rw, rd, top + h + 2.8f * m, m);
if (rnd.Chance(0.4f))
{
float lw = w * rnd.Range(0.14f, 0.2f), ld = b.d * rnd.Range(0.22f, 0.3f);
var r2 = At(du + (rnd.Chance(0.5f) ? 1f : -1f) * (0.5f * w - 0.6f * lw), rnd.Range(-0.2f, 0.2f) * b.d);
- km.Box(r2.x, r2.y, yaw, lw, ld, top + h - 2f, top + h, 2.4f * m, wall, terrace, Facade.Plain, m);
+ if (!setback) km.Box(r2.x, r2.y, yaw, lw, ld, top + h - 2f, top + h, 2.4f * m, wall, terrace, Facade.Plain, m);
}
Record(id, "building", p, yaw, b.w, b.d, b.h, wall);
}
+ /// <summary>The set-back top storey: on blocks of at least SetbackMinStoreys storeys, a SetbackShare of them; set back
+ /// SetbackMinM to SetbackMaxM (real m) from the street and SetbackInsetM from the other sides.</summary>
+ const int SetbackMinStoreys = 5;
+ const float SetbackShare = 0.45f, SetbackMinM = 2.5f, SetbackMaxM = 3.5f, SetbackInsetM = 0.5f;
+ /// <summary>The least depth share a set-back top storey keeps: the stair head (half its depth up to 0.21 d, set off up
+ /// to 0.15 pd) stays on it while pd >= 0.6 d. A shrunk block (Fits' 0.72 and 0.5) is too shallow for the full set-back.</summary>
+ const float SetbackMinDepthShare = 0.65f;
+
+ /// <summary>A Tel Aviv block's roof layout in its main block's frame (u along the street from its centre, v across), for a
+ /// <paramref name="w"/> x <paramref name="d"/> main block: the top storey's pw x pd at (pu, pv) (the whole roof unless
+ /// <paramref name="setback"/>) and the stair head's centre (su, sv). <paramref name="backM"/> (real m), <paramref name="share"/>
+ /// and <paramref name="shift"/> are the set-back's draws, <paramref name="fu"/> and <paramref name="fv"/> the stair head's.
+ /// The set-back is capped so pd >= SetbackMinDepthShare d; pw >= 0.6 w holds as drawn (share >= 0.6, and w - 2 inset >= 0.6 w
+ /// for any w of 2.5 real m or more, every block's).</summary>
+ internal static (float pw, float pd, float pu, float pv, float su, float sv) TelAvivRoofLayout(float w, float d, float m, bool setback,
+ float backM, float share, float shift, float fu, float fv)
+ {
+ float pw = w, pd = d, pu = 0f, pv = 0f;
+ if (setback)
+ {
+ float inset = SetbackInsetM * m, back = Mathf.Min(backM * m, Mathf.Max(0f, (1f - SetbackMinDepthShare) * d - inset));
+ pw = Mathf.Min(w * share, w - 2f * inset); pd = d - back - inset;
+ pu = shift * (w - 2f * inset - pw); pv = 0.5f * (back - inset);
+ }
+ return (pw, pd, pu, pv, pu + fu * pw, pv + fv * pd);
+ }
+
/// <summary>Glass of the ribbon windows: near black, as promo 03's deep-set windows read.</summary>
static readonly Color32 RibbonGlass = new Color32(38, 42, 48, 0);
diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.cs b/unity/Assets/Scripts/Map/Kits/SettlementKits.cs
index 33dc19aba..231b4d418 100644
--- a/unity/Assets/Scripts/Map/Kits/SettlementKits.cs
+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.cs
@@ -434,8 +434,8 @@ namespace Statecraft.Game.Map.Kits
// ---- Plots ----------------------------------------------------------------------------------------------------
/// <summary>The kinds of building a plot lattice lays out. Real sizes (m, before the symbolic scale) and storeys are
- /// in <see cref="Pick"/>; lattice pitch, density and scale in <see cref="Grid"/>.</summary>
- enum Style
+ /// in <see cref="Pick"/>; lattice pitch, density and scale in <see cref="Grid"/>. Internal for the tests (KitRoofContainmentTests).</summary>
+ internal enum Style
{
/// <summary>Hadar HaCarmel's International Style blocks: white plaster, flat roofs (60x).</summary>
WhiteBlock,
@@ -826,7 +826,8 @@ namespace Statecraft.Game.Map.Kits
/// shore; the others get a seeded angle).</summary>
static float GridYaw(string id) => id == "tel_aviv" ? 20f : id == "haifa" ? 35f : new KitRandom(id, 7).Range(0f, 90f);
- struct Spec { public float w, d, h, lotR; public int storeys; public KibbutzPart part; }
+ /// <summary>A building's footprint, height, storeys and lot (internal for the tests: KitRoofContainmentTests).</summary>
+ internal struct Spec { public float w, d, h, lotR; public int storeys; public KibbutzPart part; }
/// <summary>A plot's building: real size and storeys by style and by t (0 at the heart, 1 at the footprint's edge),
/// times the scale <paramref name="m"/>. Every size fits its lattice's plot with a street to spare.</summary>
@@ -901,8 +902,8 @@ namespace Statecraft.Game.Map.Kits
km.CutEnd(cut);
}
- /// <summary>A plot's kit parts and its census record.</summary>
- static void EmitParts(string id, Style st, Vector2 p, float yaw, Spec b, float t, KitGround ground, KitMesh km, float bottom, float top, float m,
+ /// <summary>A plot's kit parts and its census record (internal for the tests: KitRoofContainmentTests).</summary>
+ internal static void EmitParts(string id, Style st, Vector2 p, float yaw, Spec b, float t, KitGround ground, KitMesh km, float bottom, float top, float m,
ref KitRandom rnd)
{
float storey = 3.3f * m;
@@ -921,6 +922,11 @@ namespace Statecraft.Game.Map.Kits
var roof = white ? Jitter(C(0.90f, 0.89f, 0.86f), ref rnd, 0.03f) : Jitter(C(0.80f, 0.78f, 0.74f), ref rnd, 0.05f);
// A third of the blocks step down at one end: a lower wing within the plot (L and stepped massing).
bool stepped = b.storeys >= 3 && rnd.Chance(0.33f);
+ // The white blocks (Haifa's Hadar): a roof parapet of Tel Aviv's size (RoofParapet's; Box's rim costs half its vertices).
+ var detail = DetailAt(p, 47);
+ float parapet = white && RoofDetail ? WhiteParapetM * m : 0f, parapetT = WhiteParapetThicknessM * m;
+ // The roof the stair head stands on: the whole block's, or on a stepped block its upper part's (c1, w1 wide).
+ Vector2 roofC = p; float roofW = b.w;
if (stepped)
{
float a = yaw * Mathf.Deg2Rad, share = rnd.Range(0.58f, 0.72f), side = rnd.Chance(0.5f) ? 1f : -1f;
@@ -928,23 +934,29 @@ namespace Statecraft.Game.Map.Kits
float u1 = side * (b.w - w1) * 0.5f, u2 = -side * (b.w - w2) * 0.5f, v2 = (b.d - d2) * 0.5f;
var c1 = p + new Vector2(u1 * Mathf.Cos(a), u1 * Mathf.Sin(a));
var c2 = p + new Vector2(u2 * Mathf.Cos(a) - v2 * Mathf.Sin(a), u2 * Mathf.Sin(a) + v2 * Mathf.Cos(a));
- km.Box(c1.x, c1.y, yaw, w1, b.d, bottom, top, b.h, wall, roof, Facade.WhiteCity, m);
- km.Box(c2.x, c2.y, yaw, w2 * 1.01f, d2, bottom, top, h2, wall, roof, Facade.WhiteCity, m);
+ roofC = c1; roofW = w1;
+ km.Box(c1.x, c1.y, yaw, w1, b.d, bottom, top, b.h, wall, roof, Facade.WhiteCity, m, parapet: parapet, parapetThickness: parapetT);
+ km.Box(c2.x, c2.y, yaw, w2 * 1.01f, d2, bottom, top, h2, wall, roof, Facade.WhiteCity, m, parapet: parapet, parapetThickness: parapetT);
if (white) WhiteBlockDetail(km, c1, u1, b.lotR, yaw, w1, b.d, top, b.h, wall, roof, m, ref rnd);
Record(id, "building", p, yaw, b.w, b.d, b.h, wall);
Record(id, "wing", c2, yaw, w2, d2, h2, wall);
}
else
{
- km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, b.h, wall, roof, Facade.WhiteCity, m);
+ km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, b.h, wall, roof, Facade.WhiteCity, m, parapet: parapet, parapetThickness: parapetT);
if (white) WhiteBlockDetail(km, p, 0f, b.lotR, yaw, b.w, b.d, top, b.h, wall, roof, m, ref rnd);
Record(id, "building", p, yaw, b.w, b.d, b.h, wall);
}
- // A stair tower or roof room on many Bauhaus blocks (the White City's roofs: most have one).
+ // A stair tower or roof room on many Bauhaus blocks (the White City's roofs: most have one), on the upper
+ // roof and set off along and across the block (its yaw), so it stays inside that roof's parapet
+ // (KitRoofContainmentTests). The same four draws as ever, in the same order.
if (rnd.Chance(white ? 0.8f : 0.5f))
{
- float rw = b.w * rnd.Range(0.22f, 0.36f), rd = b.d * rnd.Range(0.3f, 0.45f);
- km.Box(p.x + b.w * rnd.Range(-0.15f, 0.15f), p.y + b.d * rnd.Range(-0.12f, 0.12f), yaw, rw, rd, top + b.h - 2f, top + b.h, 2.8f * m, wall, roof, Facade.Plain, m);
+ float rw = roofW * rnd.Range(0.22f, 0.36f), rd = b.d * rnd.Range(0.3f, 0.45f);
+ float su = roofW * rnd.Range(-0.15f, 0.15f), sv = b.d * rnd.Range(-0.12f, 0.12f), ya = yaw * Mathf.Deg2Rad;
+ var s = roofC + new Vector2(su * Mathf.Cos(ya) - sv * Mathf.Sin(ya), su * Mathf.Sin(ya) + sv * Mathf.Cos(ya));
+ km.Box(s.x, s.y, yaw, rw, rd, top + b.h - 2f, top + b.h, 2.8f * m, wall, roof, Facade.Plain, m);
+ if (white && RoofDetail && detail.Chance(RoofTankShare)) RoofTank(km, s, yaw, rw, rd, top + b.h + 2.8f * m, m);
}
// Many White City roofs carry a second room (the shared laundry room beside the stair head), at the
// block's other end, inside its footprint (not on a stepped block, whose ends differ in height).
@@ -962,7 +974,10 @@ namespace Statecraft.Game.Map.Kits
var wall = Jitter(C(0.86f, 0.79f, 0.64f), ref rnd, 0.05f);
var roof = Jitter(C(0.82f, 0.77f, 0.66f), ref rnd, 0.04f);
bool tiled = rnd.Chance(0.15f); // the red-roofed villas of the new city's garden suburbs
- km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, b.h, wall, roof, Facade.Stone, m, roofed: tiled);
+ // A flat roof's parapet, its height the block's own (DetailAt).
+ float parapet = RoofDetail ? DetailAt(p, 43).Range(StoneParapetMinM, StoneParapetMaxM) * m : 0f;
+ km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, b.h, wall, roof, Facade.Stone, m, roofed: tiled, parapet: parapet,
+ parapetThickness: StoneParapetThicknessM * m);
if (tiled) km.Pyramid(p.x, p.y, yaw, b.w * 1.04f, b.d * 1.04f, top + b.h, 2.6f * m, Jitter(C(0.70f, 0.33f, 0.22f), ref rnd, 0.06f));
else if (rnd.Chance(0.35f))
km.Box(p.x, p.y, yaw, b.w * 0.3f, b.d * 0.35f, top + b.h - 2f, top + b.h, 2.6f * m, wall, roof, Facade.Plain, m);
@@ -1054,12 +1069,47 @@ namespace Statecraft.Game.Map.Kits
/// <summary>Grey-buff limestone, lime-plastered roofs and the plain's mud brick (sRGB).</summary>
static readonly Color32 LimeRoof = C(0.86f, 0.83f, 0.77f), MudBrick = C(0.78f, 0.69f, 0.56f);
+ // ---- Roof detail (owner, 3 November 2026, "do it": the kit buildings get real geometry nearer promo 03's) ------------
+ // Flat roofs get a parapet; some of Tel Aviv's taller blocks set their top storey back from the street; some stair
+ // heads carry a water tank. All of it stands inside the building's footprint, inside its CutStart/CutEnd span (so the
+ // close mesh leaves it out with the building), and draws from the building's own stream (DetailAt), so no plot, lot,
+ // colour or census entry moves.
+
+ /// <summary>Whether the kit buildings draw their roof detail (on; tests switch it off to measure what it costs in
+ /// vertices and to show it moves nothing else).</summary>
+ internal static bool RoofDetail = true;
+
+ /// <summary>A building's own detail stream: seeded by its plot's centre (rounded to the world metre) and a salt, never
+ /// by the town's stream, so drawing it changes no other number. The same map draws the same detail on every build.</summary>
+ static KitRandom DetailAt(Vector2 p, ulong salt) =>
+ new KitRandom(((ulong)(uint)Mathf.RoundToInt(p.x) << 32 | (uint)Mathf.RoundToInt(p.y)) ^ (salt * 0x9E3779B97F4A7C15UL));
+
+ /// <summary>Parapet sizes (real m): the White City's (Tel Aviv's RoofParapet's), a town's stone house's or block's
+ /// (a height range), and a village house's low rim; and the share of village houses with one.</summary>
+ const float WhiteParapetM = 1.0f, WhiteParapetThicknessM = 0.35f;
+ const float StoneParapetMinM = 0.6f, StoneParapetMaxM = 1.0f, StoneParapetThicknessM = 0.3f;
+ const float VillageParapetMinM = 0.35f, VillageParapetMaxM = 0.65f, VillageParapetThicknessM = 0.25f, VillageParapetShare = 0.5f;
+ /// <summary>The share of White City stair heads with a water tank on their roof.</summary>
+ const float RoofTankShare = 0.4f;
+ /// <summary>A roof water tank's side cap and height (real m), and its grey (sRGB).</summary>
+ const float RoofTankM = 2.4f, RoofTankHeightM = 1.6f;
+ static readonly Color32 RoofTankGrey = C(0.66f, 0.66f, 0.64f);
+
+ /// <summary>A water tank on a <paramref name="w"/> x <paramref name="d"/> stair head at <paramref name="c"/> whose roof
+ /// is at <paramref name="roofY"/>: a square tank, at most RoofTankM a side and inside the stair head's roof.</summary>
+ static void RoofTank(KitMesh km, Vector2 c, float yaw, float w, float d, float roofY, float m)
+ {
+ float s = Mathf.Min(RoofTankM * m, 0.6f * Mathf.Min(w, d));
+ km.Box(c.x, c.y, yaw, s, s, roofY - 0.1f * m, roofY, RoofTankHeightM * m, RoofTankGrey, RoofTankGrey, Facade.Plain, m);
+ }
+
/// <summary>A limestone wall colour, from grey to buff (exactly two draws, as one Jitter: the villages' streams rely on it).</summary>
static Color32 StoneWall(ref KitRandom rnd) => Jitter(C(0.77f, 0.70f, 0.60f), ref rnd, 0.07f);
/// <summary>A stone or mud-brick house of <paramref name="b"/>'s footprint: of two storeys or more, most step back, the top
/// storey a smaller block on one corner of the lower roof (the lower roof its terrace); a one-storey house often has a
- /// roof room (an upper room). <paramref name="dome"/> puts a low dome on the topmost roof. All of it stands
+ /// roof room (an upper room). <paramref name="dome"/> puts a low dome on the topmost roof; otherwise, with RoofDetail, that
+ /// roof may get a parapet (every town house's, half the village houses'). All of it stands
/// inside the footprint, so the lot is unchanged.</summary>
static void StoneHouse(KitMesh km, Vector2 p, float yaw, Spec b, float bottom, float top, Color32 wall, Color32 roof, Facade facade,
float m, bool dome, ref KitRandom rnd)
@@ -1070,18 +1120,29 @@ namespace Statecraft.Game.Map.Kits
float uw = b.w * rnd.Range(0.5f, 0.75f), ud = b.d * rnd.Range(0.5f, 0.75f);
float su = rnd.Chance(0.5f) ? 1f : -1f, sv = rnd.Chance(0.5f) ? 1f : -1f;
var uc = At(su * 0.5f * (b.w - uw), sv * 0.5f * (b.d - ud));
+ // The topmost flat roof's parapet (none under a dome): every town house's, half the village houses'; its height
+ // the house's own, from its own stream (DetailAt), so rnd draws what it always has.
+ var detail = DetailAt(p, 41);
+ bool village = facade == Facade.Village;
+ float parapet = RoofDetail && !dome && (!village || detail.Chance(VillageParapetShare))
+ ? (village ? detail.Range(VillageParapetMinM, VillageParapetMaxM) : detail.Range(StoneParapetMinM, StoneParapetMaxM)) * m : 0f;
+ float parapetT = (village ? VillageParapetThicknessM : StoneParapetThicknessM) * m;
if (b.storeys >= 2 && rnd.Chance(0.75f))
{
float low = b.h - storey;
km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, low, wall, roof, facade, m);
- km.Box(uc.x, uc.y, yaw, uw, ud, top + low - 0.3f * m, top + low, storey, wall, roof, facade, m);
+ km.Box(uc.x, uc.y, yaw, uw, ud, top + low - 0.3f * m, top + low, storey, wall, roof, facade, m, parapet: parapet, parapetThickness: parapetT);
if (dome) km.Dome(uc.x, uc.y, top + b.h - 0.2f * m, Mathf.Min(uw, ud) * 0.4f, roof, rise: 0.6f);
return;
}
- km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, b.h, wall, roof, facade, m);
+ // A roof room (none under a dome) is the topmost roof, so the parapet goes on it: on the main roof the room's walls
+ // would stand through the rim. The same roll as ever (only without a dome), drawn before the main block, which draws none.
+ bool room = !dome && rnd.Chance(0.35f);
+ km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, b.h, wall, roof, facade, m, parapet: room ? 0f : parapet, parapetThickness: parapetT);
if (dome) km.Dome(p.x, p.y, top + b.h - 0.2f * m, Mathf.Min(b.w, b.d) * 0.33f, roof, rise: 0.6f);
- else if (rnd.Chance(0.35f)) // a roof room
- km.Box(uc.x, uc.y, yaw, uw * 0.8f, ud * 0.8f, top + b.h - 0.3f * m, top + b.h, storey * 0.85f, wall, roof, facade, m);
+ else if (room)
+ km.Box(uc.x, uc.y, yaw, uw * 0.8f, ud * 0.8f, top + b.h - 0.3f * m, top + b.h, storey * 0.85f, wall, roof, facade, m,
+ parapet: parapet, parapetThickness: parapetT);
}
/// <summary>Haifa's Hadar wall plaster (sRGB; Tel Aviv's is TelAvivPlaster, #658): lime white, a touch cool, so the warm
@@ -1364,7 +1425,8 @@ namespace Statecraft.Game.Map.Kits
return wall;
}
- static Color32 EmitParts(Archetype arch, Vector2 p, float yaw, Spec b, KitGround ground, KitMesh km, float bottom, float top, float m, ref KitRandom rnd)
+ /// <summary>A locality's kit parts (internal for the tests: KitRoofContainmentTests).</summary>
+ internal static Color32 EmitParts(Archetype arch, Vector2 p, float yaw, Spec b, KitGround ground, KitMesh km, float bottom, float top, float m, ref KitRandom rnd)
{
switch (arch)
{
@@ -1372,7 +1434,8 @@ namespace Statecraft.Game.Map.Kits
{
var wall = rnd.Chance(0.12f) ? Jitter(C(0.90f, 0.84f, 0.72f), ref rnd, 0.04f) : Jitter(C(0.94f, 0.92f, 0.87f), ref rnd, 0.035f);
var roof = Jitter(C(0.80f, 0.78f, 0.74f), ref rnd, 0.05f);
- km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, b.h, wall, roof, Facade.WhiteCity, m);
+ km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, b.h, wall, roof, Facade.WhiteCity, m,
+ parapet: RoofDetail ? WhiteParapetM * m : 0f, parapetThickness: WhiteParapetThicknessM * m);
// Some blocks are L-shaped: a lower wing at one end, back from the street.
if (rnd.Chance(0.3f))
{
@@ -1383,11 +1446,14 @@ namespace Statecraft.Game.Map.Kits
if (!ground.Water(wc.x, wc.y))
km.Box(wc.x, wc.y, yaw, ww, wd, bottom, top, Mathf.Max(2f * 3.3f * m, b.h - 3.3f * m), wall, roof, Facade.WhiteCity, m);
}
- // A stair tower or roof room on many Bauhaus blocks, and a parapet's shadow line.
+ // A stair tower or roof room on many Bauhaus blocks, and a parapet's shadow line: set off along and across
+ // the block (its yaw), so it stays inside the roof's parapet (KitRoofContainmentTests). The same draws in order.
if (rnd.Chance(0.55f))
{
- float rw = b.w * rnd.Range(0.25f, 0.4f), rd = b.d * rnd.Range(0.3f, 0.45f);
- km.Box(p.x + b.w * rnd.Range(-0.2f, 0.2f), p.y + b.d * rnd.Range(-0.15f, 0.15f), yaw, rw, rd, top + b.h - 2f, top + b.h, 2.8f * m, wall, roof, Facade.Plain, m);
+ float rw = b.w * rnd.Range(0.25f, 0.4f), rd = b.d * rnd.Range(0.3f, 0.45f), a = yaw * Mathf.Deg2Rad;
+ float su = b.w * rnd.Range(-0.2f, 0.2f), sv = b.d * rnd.Range(-0.15f, 0.15f);
+ km.Box(p.x + su * Mathf.Cos(a) - sv * Mathf.Sin(a), p.y + su * Mathf.Sin(a) + sv * Mathf.Cos(a), yaw, rw, rd, top + b.h - 2f, top + b.h,
+ 2.8f * m, wall, roof, Facade.Plain, m);
}
return wall;
}
diff --git a/unity/Assets/Tests/EditMode/KitRoofContainmentTests.cs b/unity/Assets/Tests/EditMode/KitRoofContainmentTests.cs
new file mode 100644
index 000000000..4d3fac767
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/KitRoofContainmentTests.cs
@@ -0,0 +1,222 @@
+#nullable enable
+using System.Collections.Generic;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game.Map;
+using Statecraft.Game.Map.Kits;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+
+/// <summary>PR #2371's review (3 November 2026): what stands on a kit roof stays inside that roof's parapet. Each test draws
+/// one building at a time (SettlementKits.EmitParts) over its Spec's real width and depth range (Pick's: both ends of each and
+/// the middle), Fits' sizes 1, 0.72 and 0.5, the yaws 0, 90 and 45 degrees and 40 seeds, and reads the parapet's inner edge
+/// off the mesh itself: the rim's top is a level of vertices just above the roof whose positions, in the building's own frame,
+/// take exactly four values along it and four across (outer and inner edge each side). Each test also logs the town stream's
+/// draws per building (ROOF_RNG), so a change to the roof code can show it draws what it drew before.</summary>
+public class KitRoofContainmentTests
+{
+ [TearDown]
+ public void Restore()
+ {
+ SettlementKits.RoofDetail = true;
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ VisualToggles.Clear();
+ KitScale.Reset();
+ }
+
+ const float Storey = 3.3f;
+ /// <summary>The highest parapet any building draws (real m: the White City's and a town house's top, 1.0).</summary>
+ const float MaxParapet = 1.0f;
+ /// <summary>Anything higher than this above its roof (real m) stands on the roof: a stair head (2.8), its tank or a roof
+ /// room (0.85 storey); a White City laundry room (2.4), a dome (at most about 2.2) and the parapets stay below it.</summary>
+ const float StandsOn = 2.5f;
+ static readonly float[] Shrinks = { 1f, 0.72f, 0.5f };
+ static readonly float[] Yaws = { 0f, 90f, 45f };
+ const int Seeds = 40;
+
+ delegate void Emit(KitMesh km, Vector2 p, float yaw, SettlementKits.Spec b, ref KitRandom rnd);
+
+ /// <summary>A kind of building: its Spec ranges (real m, Pick's), storeys, scale and how it is drawn.</summary>
+ sealed class Kind
+ {
+ public string Name = ""; public float W0, W1, D0, D1, M; public int[] Storeys = { 1 }; public Emit Draw = null!;
+ }
+
+ static KitGround Ground()
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var map = Object.FindFirstObjectByType<MapScene>(); map.Build();
+ return new KitGround(map.Terrain, map.Frame, map.Hexes, HeightmapLoader.Load(Statecraft.Game.Paths.StreamingMap).meta.elev_min_m);
+ }
+
+ static Emit Lattice(SettlementKits.Style st, KitGround g, float m) =>
+ (KitMesh km, Vector2 p, float yaw, SettlementKits.Spec b, ref KitRandom rnd) =>
+ SettlementKits.EmitParts("test", st, p, yaw, b, 0.3f, g, km, -2f, 0f, m, ref rnd);
+
+ static Emit Locality(Archetype a, KitGround g, float m) =>
+ (KitMesh km, Vector2 p, float yaw, SettlementKits.Spec b, ref KitRandom rnd) =>
+ SettlementKits.EmitParts(a, p, yaw, b, g, km, -2f, 0f, m, ref rnd);
+
+ /// <summary>One building drawn for every size, yaw and seed, with its roof at y = b.h (the ground at 0).</summary>
+ static IEnumerable<(string spec, float m, float roofY, List<Vector3> v, Vector2 p, float yaw, int draws)> Sweep(Kind k)
+ {
+ foreach (var (wr, dr) in new[] { (0f, 0f), (0f, 1f), (1f, 0f), (1f, 1f), (0.5f, 0.5f) })
+ foreach (float shrink in Shrinks)
+ foreach (int storeys in k.Storeys)
+ foreach (float yaw in Yaws)
+ for (int seed = 0; seed < Seeds; seed++)
+ {
+ float w = Mathf.Lerp(k.W0, k.W1, wr) * shrink, d = Mathf.Lerp(k.D0, k.D1, dr) * shrink, m = k.M;
+ var b = new SettlementKits.Spec
+ {
+ w = w * m, d = d * m, h = storeys * Storey * m, storeys = storeys, lotR = 0.75f * Mathf.Sqrt(w * w + d * d) * m,
+ };
+ // Each seed its own plot (the detail streams are seeded by the plot's position), a few hundred metres apart.
+ var p = new Vector2(1000f + 311f * seed, 1000f + 173f * seed);
+ var rnd = new KitRandom($"{k.Name}/{seed}"); var before = rnd;
+ var km = new KitMesh();
+ k.Draw(km, p, yaw, b, ref rnd);
+ var v = new List<Vector3>(); km.Positions(0, km.VertexCount, v);
+ yield return ($"{k.Name} {w:0.##} x {d:0.##} m, {storeys} storeys, yaw {yaw}, seed {seed}", m, b.h, v, p, yaw, Draws(before, rnd));
+ }
+ }
+
+ /// <summary>How many numbers the stream drew between <paramref name="before"/> and <paramref name="after"/>: every draw
+ /// (Value, Range, Chance, Bell's two) is one Next, so the count is exact.</summary>
+ static int Draws(KitRandom before, KitRandom after)
+ {
+ ulong target = after.Next();
+ for (int k = 0; k < 4096; k++) { var probe = before; if (probe.Next() == target) return k; before.Next(); }
+ return -1;
+ }
+
+ /// <summary>(u, v): <paramref name="q"/> in the frame of a building at <paramref name="p"/> turned <paramref name="yaw"/>
+ /// degrees (as KitMesh.Corners lays a footprint out).</summary>
+ static Vector2 Local(Vector3 q, Vector2 p, float yaw)
+ {
+ float a = yaw * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a), dx = q.x - p.x, dz = q.z - p.y;
+ return new Vector2(dx * ca + dz * sa, -dx * sa + dz * ca);
+ }
+
+ static List<float> Distinct(IEnumerable<float> xs, float eps)
+ {
+ var o = new List<float>();
+ foreach (var x in xs.OrderBy(x => x)) if (o.Count == 0 || x - o[o.Count - 1] > eps) o.Add(x);
+ return o;
+ }
+
+ /// <summary>The inner edge (u0, u1, v0, v1, in the building's frame) of the parapet whose top lies above
+ /// <paramref name="y0"/> and no higher than <paramref name="y1"/>, or null without one.</summary>
+ static (float u0, float u1, float v0, float v1)? Rim(List<Vector3> v, Vector2 p, float yaw, float y0, float y1, float eps)
+ {
+ var levels = Distinct(v.Where(q => q.y > y0 + eps && q.y <= y1 + eps).Select(q => q.y), eps);
+ foreach (float y in levels)
+ {
+ var at = v.Where(q => Mathf.Abs(q.y - y) <= eps).Select(q => Local(q, p, yaw)).ToList();
+ var us = Distinct(at.Select(l => l.x), eps); var vs = Distinct(at.Select(l => l.y), eps);
+ if (us.Count == 4 && vs.Count == 4) return (us[1], us[2], vs[1], vs[2]);
+ }
+ return null;
+ }
+
+ static bool Inside(Vector2 l, (float u0, float u1, float v0, float v1) r, float eps) =>
+ l.x >= r.u0 - eps && l.x <= r.u1 + eps && l.y >= r.v0 - eps && l.y <= r.v1 + eps;
+
+ static void Log(string what, List<int> draws) =>
+ TestContext.WriteLine($"ROOF_RNG {what}: {draws.Count} buildings, {draws.Sum()} draws, per-building digest " +
+ $"{draws.Aggregate(14695981039346656037UL, (h, n) => (h ^ (ulong)(uint)n) * 1099511628211UL):X16}");
+
+ /// <summary>Every stair head (and the water tank on it) of a White City block, Haifa's Hadar's (WhiteBlock, stepped or
+ /// not) and a city's fallback block's, stands inside the parapet's inner edge of the roof it stands on.</summary>
+ [Test]
+ public void EveryStairHeadAndTankStandsInsideItsRoofsParapet()
+ {
+ var g = Ground();
+ float cm = KitScale.CityBlocks;
+ var kinds = new[]
+ {
+ new Kind { Name = "WhiteBlock", W0 = 12f, W1 = 16f, D0 = 9f, D1 = 11.5f, M = cm, Storeys = new[] { 3, 6 },
+ Draw = Lattice(SettlementKits.Style.WhiteBlock, g, cm) },
+ new Kind { Name = "WhiteCity fallback", W0 = 15f, W1 = 26f, D0 = 11f, D1 = 18f, M = cm, Storeys = new[] { 2, 4 },
+ Draw = Locality(Archetype.WhiteCity, g, cm) },
+ };
+ var bad = new List<string>();
+ foreach (var k in kinds)
+ {
+ int heads = 0; var draws = new List<int>();
+ foreach (var (spec, m, roofY, v, p, yaw, n) in Sweep(k))
+ {
+ draws.Add(n);
+ float eps = 0.01f * m;
+ var rim = Rim(v, p, yaw, roofY, roofY + MaxParapet * m, eps);
+ if (rim == null) { bad.Add(spec + ": no parapet on the roof"); continue; }
+ var on = v.Where(q => q.y > roofY + StandsOn * m).ToList();
+ if (on.Count == 0) continue;
+ heads++;
+ var outside = on.Select(q => Local(q, p, yaw)).Where(l => !Inside(l, rim.Value, eps)).ToList();
+ if (outside.Count > 0)
+ {
+ var worst = outside[0];
+ bad.Add($"{spec}: stair head at ({worst.x / m:0.00}, {worst.y / m:0.00}) m, parapet inside u {rim.Value.u0 / m:0.00}..{rim.Value.u1 / m:0.00}, v {rim.Value.v0 / m:0.00}..{rim.Value.v1 / m:0.00}");
+ }
+ }
+ TestContext.WriteLine($"ROOF_CONTAIN {k.Name}: {draws.Count} blocks, {heads} stair heads checked");
+ Log(k.Name, draws);
+ Assert.Greater(heads, 0, k.Name + ": stair heads swept");
+ }
+ TestContext.WriteLine($"ROOF_CONTAIN stair heads or tanks outside the parapet's inner edge: {bad.Count}");
+ foreach (var s in bad.Take(12)) TestContext.WriteLine(" " + s);
+ Assert.IsEmpty(bad, "stair heads or tanks outside their roof's parapet");
+ }
+
+ /// <summary>A stone or mud-brick house's roof room (StoneHouse: the old towns', the Arab towns' and villages') never cuts
+ /// a parapet: a roof with a room has no rim the room's walls stand through, and the rim goes on the room, the topmost
+ /// roof (a town house always has one there unless it is domed).</summary>
+ [Test]
+ public void NoRoofRoomCutsTheRim()
+ {
+ var g = Ground();
+ float hm = KitScale.Houses;
+ var kinds = new[]
+ {
+ new Kind { Name = "OldHouse", W0 = 4.6f, W1 = 6.6f, D0 = 4.4f, D1 = 6.2f, M = hm, Storeys = new[] { 1, 2 },
+ Draw = Lattice(SettlementKits.Style.OldHouse, g, hm) },
+ new Kind { Name = "Village", W0 = 3.8f, W1 = 5.4f, D0 = 3.6f, D1 = 5.0f, M = hm, Storeys = new[] { 1, 2 },
+ Draw = Lattice(SettlementKits.Style.Village, g, hm) },
+ new Kind { Name = "OldTown fallback", W0 = 7f, W1 = 14f, D0 = 7f, D1 = 12f, M = hm, Storeys = new[] { 1, 2 },
+ Draw = Locality(Archetype.OldTown, g, hm) },
+ new Kind { Name = "ArabTown fallback", W0 = 6.5f, W1 = 12f, D0 = 6f, D1 = 10f, M = hm, Storeys = new[] { 1, 2 },
+ Draw = Locality(Archetype.ArabTown, g, hm) },
+ };
+ var bad = new List<string>();
+ int townRoomsWithRim = 0;
+ foreach (var k in kinds)
+ {
+ int rooms = 0, underRim = 0, ownRim = 0; var draws = new List<int>();
+ foreach (var (spec, m, roofY, v, p, yaw, n) in Sweep(k))
+ {
+ draws.Add(n);
+ float eps = 0.01f * m, roomTop = roofY + 0.85f * Storey * m;
+ var on = v.Where(q => q.y > roofY + StandsOn * m).ToList();
+ if (on.Count == 0) continue;
+ rooms++;
+ var rim = Rim(v, p, yaw, roofY, roofY + MaxParapet * m, eps);
+ if (rim != null)
+ {
+ underRim++;
+ if (on.Any(q => !Inside(Local(q, p, yaw), rim.Value, eps)))
+ bad.Add($"{spec}: the roof room stands through the parapet (inner edge u {rim.Value.u0 / m:0.00}..{rim.Value.u1 / m:0.00}, v {rim.Value.v0 / m:0.00}..{rim.Value.v1 / m:0.00} m)");
+ }
+ if (Rim(v, p, yaw, roomTop, roomTop + MaxParapet * m, eps) != null) ownRim++;
+ }
+ if (k.Name == "OldHouse") townRoomsWithRim = ownRim;
+ TestContext.WriteLine($"ROOF_CONTAIN {k.Name}: {draws.Count} houses, {rooms} roof rooms, {underRim} on a roof with a parapet, {ownRim} with their own parapet");
+ Log(k.Name, draws);
+ Assert.Greater(rooms, 0, k.Name + ": roof rooms swept");
+ }
+ TestContext.WriteLine($"ROOF_CONTAIN roof rooms through a parapet: {bad.Count}");
+ foreach (var s in bad.Take(12)) TestContext.WriteLine(" " + s);
+ Assert.IsEmpty(bad, "roof rooms through a parapet");
+ Assert.Greater(townRoomsWithRim, 0, "an old town house's roof room carries the parapet");
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/KitRoofContainmentTests.cs.meta b/unity/Assets/Tests/EditMode/KitRoofContainmentTests.cs.meta
new file mode 100644
index 000000000..d8214dd69
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/KitRoofContainmentTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: eab26b206d6045a0bb660a2d1c0b95c4
\ No newline at end of file
diff --git a/unity/Assets/Tests/EditMode/KitRoofDetailTests.cs b/unity/Assets/Tests/EditMode/KitRoofDetailTests.cs
new file mode 100644
index 000000000..0ce043c64
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/KitRoofDetailTests.cs
@@ -0,0 +1,144 @@
+#nullable enable
+using System.Collections.Generic;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game.Map;
+using Statecraft.Game.Map.Kits;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+
+/// <summary>The kit buildings' roof detail (owner, 3 November 2026: the kit buildings get real geometry, nearer promo 03's
+/// model quality; SettlementKits.RoofDetail): roof parapets, Tel Aviv's set-back top storeys and the stair heads' water
+/// tanks. The detail moves no building, stays inside each building's close-mesh cut, and keeps the far map's vertices
+/// under <see cref="MaxGrowth"/> times the map without it.</summary>
+public class KitRoofDetailTests
+{
+ [TearDown]
+ public void Restore()
+ {
+ SettlementKits.RoofDetail = true;
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ VisualToggles.Clear();
+ KitScale.Reset();
+ }
+
+ /// <summary>The most the roof detail may multiply the far kit's vertices by (towns and locality tiles together).</summary>
+ const float MaxGrowth = 2f;
+
+ /// <summary>The towns the PR reports (the White City twice, the old towns twice, and Lod's village-style lattice), each of
+ /// which must gain detail.</summary>
+ static readonly string[] Reported = { "tel_aviv", "haifa", "jaffa", "jerusalem", "lod" };
+
+ static MapScene OpenMap()
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var map = Object.FindFirstObjectByType<MapScene>(); map.Build();
+ return map;
+ }
+
+ /// <summary>The kits as TownCensusTests.Census builds them (the routes' and units' corridors, the 1948 localities).</summary>
+ static SettlementKits.Result Build(MapScene map, out List<SettlementKits.Placed> placed)
+ {
+ var g = new KitGround(map.Terrain, map.Frame, map.Hexes, HeightmapLoader.Load(Statecraft.Game.Paths.StreamingMap).meta.elev_min_m);
+ foreach (var c in map.KitRouteCorridors) 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);
+ return SettlementKits.Build(map.Settlements, map.Localities.Select(p => p.Settlement).ToList(), new List<Localities.Area>(), g, out placed);
+ }
+
+ static void Destroy(SettlementKits.Result r)
+ {
+ foreach (var t in r.Towns) Object.DestroyImmediate(t.mesh);
+ foreach (var t in r.Tiles) Object.DestroyImmediate(t.mesh);
+ foreach (var m in r.Close.Values) Object.DestroyImmediate(m);
+ }
+
+ [Test]
+ public void RoofDetailMovesNothingStaysInsideItsBuildingsAndKeepsTheBudget()
+ {
+ var map = OpenMap();
+ SettlementKits.RoofDetail = false;
+ SettlementKits.Result off; List<SettlementKits.Placed> offPlaced;
+ try { off = Build(map, out offPlaced); }
+ finally { SettlementKits.RoofDetail = true; }
+ SettlementKits.Result? on = null;
+ try
+ {
+ on = Build(map, out var onPlaced);
+ // It draws from each building's own stream: every building, landmark and palm is where, as large and as coloured
+ // as without it.
+ Assert.AreEqual(offPlaced.Count, onPlaced.Count, "census entries");
+ for (int i = 0; i < offPlaced.Count; i++)
+ {
+ SettlementKits.Placed a = offPlaced[i], b = onPlaced[i];
+ Assert.IsTrue(a.Id == b.Id && a.Kind == b.Kind && a.C == b.C && a.Yaw == b.Yaw && a.W == b.W && a.D == b.D && a.H == b.H &&
+ a.Wall.Equals(b.Wall), $"census entry {i} ({a.Id} {a.Kind}) moved");
+ }
+ // It lies inside each building's CutStart/CutEnd span: the close meshes (the kit without its buildings) are unchanged.
+ CollectionAssert.AreEquivalent(off.Close.Keys, on.Close.Keys, "close meshes");
+ foreach (var kv in off.Close) Assert.AreEqual(kv.Value.vertexCount, on.Close[kv.Key].vertexCount, kv.Key + "'s close mesh");
+
+ var offTowns = off.Towns.ToDictionary(t => t.s.Id, t => t.mesh.vertexCount);
+ var onTowns = on.Towns.ToDictionary(t => t.s.Id, t => t.mesh.vertexCount);
+ foreach (var kv in offTowns) Assert.GreaterOrEqual(onTowns[kv.Key], kv.Value, kv.Key);
+ foreach (var id in Reported)
+ {
+ TestContext.WriteLine($"ROOF_DETAIL {id} vertices {offTowns[id]} -> {onTowns[id]} (x{onTowns[id] / (float)offTowns[id]:0.00})");
+ Assert.Greater(onTowns[id], offTowns[id], id + " gains roof detail");
+ }
+ int offTiles = off.Tiles.Sum(t => t.mesh.vertexCount), onTiles = on.Tiles.Sum(t => t.mesh.vertexCount);
+ int offAll = offTowns.Values.Sum() + offTiles, onAll = onTowns.Values.Sum() + onTiles;
+ TestContext.WriteLine($"ROOF_DETAIL localities (tiles) vertices {offTiles} -> {onTiles} (x{onTiles / (float)offTiles:0.00})");
+ TestContext.WriteLine($"ROOF_DETAIL far map vertices {offAll} -> {onAll} (x{onAll / (float)offAll:0.00})");
+ // What the towns' streams drew, for comparing two versions of the roof code: every census entry's place, size and
+ // colour (a later building's numbers move if an earlier one draws more or fewer), and the close meshes' vertices.
+ ulong census = 14695981039346656037UL;
+ void Mix(int x) => census = (census ^ (uint)x) * 1099511628211UL;
+ foreach (var e in onPlaced)
+ {
+ Mix((int)KitRandom.Fnv1a(e.Id)); Mix((int)KitRandom.Fnv1a(e.Kind));
+ foreach (float f in new[] { e.C.x, e.C.y, e.Yaw, e.W, e.D, e.H }) Mix(System.BitConverter.SingleToInt32Bits(f));
+ Mix(e.Wall.r | e.Wall.g << 8 | e.Wall.b << 16 | e.Wall.a << 24);
+ }
+ TestContext.WriteLine($"ROOF_DETAIL census {onPlaced.Count} entries, digest {census:X16}; close meshes {on.Close.Count}, " +
+ $"{on.Close.Values.Sum(c => c.vertexCount)} vertices");
+ Assert.Greater(onTiles, offTiles, "the villages gain roof detail");
+ Assert.LessOrEqual(onAll, MaxGrowth * offAll, "the far map's vertices");
+ }
+ finally { Destroy(off); if (on != null) Destroy(on); }
+ }
+
+ /// <summary>On every set-back Tel Aviv block the stair head stands on the top storey's roof: a sweep of the real specs
+ /// (SettlementKits.TelAviv.cs: block 21-24 x 13-15 m, a stepped block's main part 0.6-0.72 of its width; Fits' sizes 1,
+ /// 0.72 and 0.5) and of every draw's range ends (set-back 2.5-3.5 m, width share 0.6-0.85, shift +-0.5; stair head
+ /// 0.2-0.3 w x 0.3-0.42 d, set off +-0.2 pw and +-0.15 pd). Each draw enters the stair head's reach linearly, so its range
+ /// ends bound it; the sizes and set-backs take five steps, as the set-back's cap bends there.</summary>
+ [Test]
+ public void SetBackStairHeadStandsOnTheTopStorey()
+ {
+ float m = KitScale.DefaultCityBlocks, eps = 1e-3f * m;
+ float[] Steps(float a, float b) => new[] { a, a + 0.25f * (b - a), a + 0.5f * (b - a), a + 0.75f * (b - a), b };
+ float[] ends = { 0f, 1f };
+ int n = 0;
+ foreach (float k in new[] { 1f, 0.72f, 0.5f })
+ foreach (float bw in new[] { 21f, 24f })
+ foreach (float part in new[] { 1f, 0.6f, 0.72f })
+ foreach (float bd in Steps(13f, 15f))
+ foreach (float backM in Steps(2.5f, 3.5f))
+ foreach (float s in ends) foreach (float sh in ends) foreach (float u in ends) foreach (float v in ends)
+ foreach (float rwS in ends) foreach (float rdS in ends)
+ {
+ float w = bw * part * k * m, d = bd * k * m;
+ float share = Mathf.Lerp(0.6f, 0.85f, s), shift = Mathf.Lerp(-0.5f, 0.5f, sh), fu = Mathf.Lerp(-0.2f, 0.2f, u), fv = Mathf.Lerp(-0.15f, 0.15f, v);
+ float rw = w * Mathf.Lerp(0.2f, 0.3f, rwS), rd = d * Mathf.Lerp(0.3f, 0.42f, rdS);
+ var (pw, pd, pu, pv, su, sv) = SettlementKits.TelAvivRoofLayout(w, d, m, true, backM, share, shift, fu, fv);
+ string spec = $"block {bw * part * k:0.##} x {bd * k:0.##} m, set-back {backM:0.##} m: top storey {pw / m:0.##} x {pd / m:0.##} m";
+ Assert.LessOrEqual(Mathf.Abs(su - pu) + 0.5f * rw, 0.5f * pw + eps, spec + ", stair head past its side");
+ Assert.LessOrEqual(Mathf.Abs(sv - pv) + 0.5f * rd, 0.5f * pd + eps, spec + ", stair head past its front or back");
+ // And the top storey stands on the main block's roof.
+ Assert.LessOrEqual(Mathf.Abs(pu) + 0.5f * pw, 0.5f * w + eps, spec + ", top storey past the block's side");
+ Assert.LessOrEqual(Mathf.Abs(pv) + 0.5f * pd, 0.5f * d + eps, spec + ", top storey past the block's front or back");
+ n++;
+ }
+ Assert.Greater(n, 0, "specs swept");
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/KitRoofDetailTests.cs.meta b/unity/Assets/Tests/EditMode/KitRoofDetailTests.cs.meta
new file mode 100644
index 000000000..3927bba58
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/KitRoofDetailTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 9efed722369340bfa2a60c3389d55134
\ No newline at end of file