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: draw the player's transit camps as a ma'abara kit (refs #32) (#557)

Beri2debf767a4ea
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b3065a1ad..8425f9220 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -83,6 +83,12 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
it. It replaces the border skirt's flat tan slab and the sea past the map's edge. At 16:9 only the overview shows it (the
camera fit of #174 keeps it off screen wherever the view is no wider than the map: below about 106 km at 16:9, 53 km
at 32:9; a portrait window never shows it); one draw call, no shadow pass, no golden moves.
+- Map: a transit camp the player builds (from 1950) is drawn as a ma'abara instead of a marker box: rows of white and
+ khaki canvas tents with a few tin or canvas huts, a long communal hut and, in some camps, a water tower, on the
+ nearest free ground in its own hex (drawn as its box when the hex has none). Built when the camp is placed, not at map
+ build; the tent/hut share is a parameter for a staged look later. The camp looks worn: tents sag between their poles,
+ crease and lean, with dusty skirts, bleached roofs, patches and open door flaps; the tin huts are loose, rusting sheets,
+ some lifted or missing; washing lines and bundles stand between the tents. Presentation only (refs #32).
- GDD v0.1 Phase 1, training (refs #377), behind the `systems.loop` switch: `Train` sends a city's civilians without work
to basic training in a military camp (recruits, a count) or pioneer training in a Hakhshara (halutzim, movable units at
the city's hex), paid from the Treasury, with any shortfall borrowed as debt (owner decision, 15 October 2026);
diff --git a/unity/Assets/Scripts/Map/Kits/KitGround.cs b/unity/Assets/Scripts/Map/Kits/KitGround.cs
index db8aa4ee9..43d7e03bf 100644
--- a/unity/Assets/Scripts/Map/Kits/KitGround.cs
+++ b/unity/Assets/Scripts/Map/Kits/KitGround.cs
@@ -67,7 +67,7 @@ namespace Statecraft.Game.Map.Kits
public string Biome(float x, float z) => biome.TryGetValue(Hex(x, z), out var b) ? b : "sea";
- (int, int) Hex(float x, float z)
+ internal (int, int) Hex(float x, float z)
{
var (lon, lat) = Frame.ToLonLat(new Vector3(x, 0f, z));
return HexPicker.FromLonLat(lon, lat, bounds, hexSizeKm);
diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.Maabara.cs b/unity/Assets/Scripts/Map/Kits/SettlementKits.Maabara.cs
new file mode 100644
index 000000000..888188e9c
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.Maabara.cs
@@ -0,0 +1,508 @@
+#nullable enable
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace Statecraft.Game.Map.Kits
+{
+ /// <summary>The ma'abara kit (issue #32): the player's transit camps (MapActions.TransitCamp, from 1950) drawn as the camps
+ /// of 1950-51 looked, rows of white and khaki canvas tents (ridge and bell tents) on a regular grid with a few tin or
+ /// canvas huts, a long communal hut (showers, kitchen) and, in some, a water tower. Built by PlacementLayer when a camp is
+ /// placed, never at map build (the boot budget, #321). Seeded by the camp's id; presentation only, no sim state.</summary>
+ public static partial class SettlementKits
+ {
+ /// <summary>The share of a ma'abara's plots that hold a hut rather than a tent: 1950-51, mostly tents. A parameter so a
+ /// staged look (more huts as the camps aged) only has to pass another share.</summary>
+ public const float MaabaraHutShare = 0.2f;
+
+ /// <summary>The plot grid (columns along the rows, rows across), its pitch (real m, before the house scale) and the
+ /// radius of the lot each plot claims: the largest tent or hut (6.5 x 4.5) with a little to spare. The 1948 Haifa
+ /// transit-camp photographs (Nationaal Archief, Van de Poll) show tents 2-3 m apart along a row and 5-6 m lanes
+ /// between rows. The lot is the same whatever stands on it, so the hut share changes what a plot holds, never which
+ /// plots are used.</summary>
+ const int MaabaraCols = 5, MaabaraRows = 4;
+ const float MaabaraPitchU = 8f, MaabaraPitchV = 9f, MaabaraPlotR = 4f;
+
+ /// <summary>How far (house-scale metres) a ma'abara reaches from its centre: the communal hut past the last column
+ /// (30 along, 9 to a side) and the rows' half width, rounded up.</summary>
+ public const float MaabaraReach = 36f;
+
+ /// <summary>Test seam (internal; the tests see it through InternalsVisibleTo): false lets a ma'abara's plots stand on
+ /// the hex grid's edge marks and on steep ground, so a test can show those rules refuse a plot (review #557).</summary>
+ internal static bool MaabaraGroundRules = true;
+
+ /// <summary>Builds one ma'abara per entry of <paramref name="camps"/> (seed id, the centre of its hex in world x, z), in
+ /// order, on one lot list so no two overlap: a mesh in world space (null when no free ground was found in the camp's
+ /// own hex), the tents and huts it holds (the communal hut and the water tower not counted) and its centre.</summary>
+ public static List<(Mesh? mesh, int tents, int huts, Vector2 at)> Maabarot(IReadOnlyList<(string id, Vector2 at)> camps, KitGround ground,
+ float hutShare = MaabaraHutShare)
+ {
+ var lots = new Lots();
+ var result = new List<(Mesh?, int, int, Vector2)>();
+ foreach (var (id, at) in camps)
+ {
+ var km = new KitMesh();
+ var (tents, huts, c) = Maabara(id, at, ground, km, lots, hutShare);
+ result.Add((km.VertexCount > 0 ? km.ToMesh(id + "_kit") : null, tents, huts, c));
+ }
+ return result;
+ }
+
+ /// <summary>As Maabarot, also listing everything placed (<see cref="Placed"/>: "tent", "hut", "communal_hut",
+ /// "water_tower"), in placement order.</summary>
+ public static List<(Mesh? mesh, int tents, int huts, Vector2 at)> Maabarot(IReadOnlyList<(string id, Vector2 at)> camps, KitGround ground,
+ out List<Placed> placed, float hutShare = MaabaraHutShare)
+ {
+ census = placed = new List<Placed>();
+ try { return Maabarot(camps, ground, hutShare); }
+ finally { census = null; }
+ }
+
+ static (int tents, int huts, Vector2 at) Maabara(string id, Vector2 hexCentre, KitGround ground, KitMesh km, Lots lots, float hutShare)
+ {
+ float m = KitScale.Houses;
+ if (!MaabaraSpot(hexCentre, MaabaraReach * m, ground, lots, out var c)) return (0, 0, c);
+ var rnd = new KitRandom(id, 1);
+ float yaw = rnd.Range(0f, 90f), 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);
+ // As the Bedouin camps' tents (Encampments): off the routes and the units' clearings, the unit tokens, the hex
+ // grid's edge marks and steep ground. Each tent, hut, the communal hut and the water tower's spot stands in the
+ // camp's own hex, not only its centre (review #557): the rows reach about 1.6 km from the centre at the house
+ // scale, the communal hut about 3 km, against the hex's 4.33 km inradius.
+ // The whole disc of radius r, not only its centre (review #557, c9): r is at least the half-width of what stands
+ // there, so nothing overhangs the hex's edge (HexGrid.EdgeDistance: the drawn grid's own distance field).
+ var hex = ground.Hex(hexCentre.x, hexCentre.y);
+ bool InHex(Vector2 p, float r) => ground.Hex(p.x, p.y) == hex
+ && HexGrid.EdgeDistance(HexGrid.FromWorld(new Vector3(p.x, 0f, p.y), ground.TerrainOrigin, ground.Length), ground.HexSizeM) >= r;
+ bool Free(Vector2 p, float r) => ground.Inside(p.x, p.y) && InHex(p, r) && !ground.Water(p.x, p.y) && OffTowns(p, r, ground)
+ && !ground.OnRoute(p, r) && !ground.OnToken(p, r)
+ && (!MaabaraGroundRules || (!ground.OnGridMark(p, r) && ground.Slope(p.x, p.y, 600f) <= 0.12f)) && lots.Free(p, r, id, 0);
+ // Huts at an even spread over the plots (a golden-ratio sequence from a seeded phase), not a coin per plot: the
+ // camp shows the share asked for, not a lucky draw of it.
+ float phase = rnd.Value();
+ int tents = 0, huts = 0, plot = 0;
+ float plotR = MaabaraPlotR * m;
+ for (int j = 0; j < MaabaraRows; j++)
+ for (int i = 0; i < MaabaraCols; i++, plot++)
+ {
+ bool hut = Mathf.Repeat(phase + plot * 0.618034f, 1f) < hutShare;
+ // Wear (sag, creases, stains, washing) draws from its own stream per plot, so the layout stream above is
+ // the one the camp always had and the hut share still changes what a plot holds, never which plots.
+ var wear = new KitRandom(id, 100UL + (ulong)plot);
+ var p = At((i - (MaabaraCols - 1) * 0.5f) * MaabaraPitchU * m, (j - (MaabaraRows - 1) * 0.5f) * MaabaraPitchV * m)
+ + new Vector2(wear.Range(-0.4f, 0.4f), wear.Range(-0.4f, 0.4f)) * m; // pegged by eye: the grid reads, not ruled
+ float pyaw = yaw + rnd.Range(-3f, 3f); // pitched by hand: straight rows, not ruled ones
+ if (!Free(p, plotR)) continue;
+ lots.Add(new Lot { c = p, r = plotR, id = id, group = 0 });
+ if (hut)
+ {
+ // Corrugated tin (pale grey) or canvas on a wooden frame, under a low gable.
+ float w = rnd.Range(5.5f, 6.5f) * m, d = rnd.Range(3.8f, 4.5f) * m;
+ bool tin = rnd.Chance(0.6f);
+ var wall = tin ? Jitter(C(0.72f, 0.74f, 0.75f), ref rnd, 0.03f) : Jitter(C(0.70f, 0.64f, 0.50f), ref rnd, 0.05f);
+ var roof = tin ? Jitter(C(0.63f, 0.65f, 0.66f), ref rnd, 0.03f) : Jitter(C(0.58f, 0.53f, 0.42f), ref rnd, 0.05f);
+ if (tin) TinHut(km, p, pyaw, w, d, 2.2f, 0.7f, wall, roof, ground, m, ref wear, false);
+ else RidgeTent(km, p, pyaw, w, d, 2.2f, 0.7f, 0.12f, roof, ground, m, ref wear, false); // canvas on a frame sags less
+ Record(id, "hut", p, pyaw, w, d, 2.2f * m, wall);
+ huts++;
+ continue;
+ }
+ // Canvas, white, khaki or a weathered grey-olive (the 1948 Haifa photographs' tents are mostly dark): the
+ // army ridge tent (low walls under a peaked roof), or a round bell tent.
+ bool white = rnd.Chance(0.6f);
+ var canvas = white ? Jitter(C(0.88f, 0.86f, 0.79f), ref rnd, 0.04f) : Jitter(C(0.72f, 0.67f, 0.52f), ref rnd, 0.05f);
+ if (!white && wear.Chance(0.5f)) canvas = Jitter(C(0.58f, 0.57f, 0.47f), ref wear, 0.05f);
+ if (rnd.Chance(0.15f))
+ {
+ float r = rnd.Range(2.3f, 2.7f) * m;
+ BellTent(km, p, r, canvas, ground, m, ref wear);
+ float a2 = wear.Range(0f, 2f * Mathf.PI);
+ Belongings(km, p + new Vector2(Mathf.Cos(a2), Mathf.Sin(a2)) * (r + 0.5f * m), a2 * Mathf.Rad2Deg, ground, m, ref wear);
+ Record(id, "tent", p, 0f, 2f * r, 2f * r, 0.9f * m, canvas);
+ }
+ else
+ {
+ float w = rnd.Range(5f, 6f) * m, d = rnd.Range(3.6f, 4.2f) * m;
+ RidgeTent(km, p, pyaw, w, d, 1f, 1.6f, 0.3f, canvas, ground, m, ref wear, wear.Chance(0.45f));
+ float pa = pyaw * Mathf.Deg2Rad;
+ Vector2 Local(float u, float v) => p + new Vector2(u * Mathf.Cos(pa) - v * Mathf.Sin(pa), u * Mathf.Sin(pa) + v * Mathf.Cos(pa));
+ // Bundles, a crate or a jerrycan by the door (the +u end), and a washing line in front of some tents,
+ // strung along the row inside the plot's own lot (Haifa 1948: washing between the tents).
+ if (wear.Chance(0.6f)) Belongings(km, Local(0.5f * w + 0.45f * m, wear.Range(-0.7f, 0.7f) * m), pyaw, ground, m, ref wear);
+ if (wear.Chance(0.5f))
+ {
+ float v = (wear.Chance(0.5f) ? 1f : -1f) * (0.5f * d + 1.1f * m);
+ var a0 = Local(-1.7f * m, v); var b0 = Local(1.7f * m, v);
+ WashingLine(km, new Vector3(a0.x, ground.Y(a0.x, a0.y), a0.y), new Vector3(b0.x, ground.Y(b0.x, b0.y), b0.y), m, ref wear);
+ }
+ Record(id, "tent", p, pyaw, w, d, 1f * m, canvas);
+ }
+ tents++;
+ }
+ if (tents + huts == 0) return (0, 0, c);
+ // The communal hut past the last column, across the rows (a plot of the grid's own lattice: clear of its tents by
+ // construction).
+ var hall = At(((MaabaraCols - 1) * 0.5f * MaabaraPitchU + 14f) * m, 0f);
+ float hallR = 0.5f * Mathf.Sqrt(18f * 18f + 6f * 6f) * m;
+ if (Free(hall, hallR))
+ {
+ lots.Add(new Lot { c = hall, r = hallR, id = id, group = 0 });
+ var tin = Jitter(C(0.72f, 0.74f, 0.75f), ref rnd, 0.03f);
+ var hallWear = new KitRandom(id, 99);
+ TinHut(km, hall, yaw + 90f, 18f * m, 6f * m, 2.6f, 1f, tin, Jitter(C(0.63f, 0.65f, 0.66f), ref rnd, 0.03f), ground, m, ref hallWear, true);
+ Record(id, "communal_hut", hall, yaw + 90f, 18f * m, 6f * m, 2.6f * m, tin);
+ }
+ // A water tower at the other end in some camps (the moshavot's, SettlementKits.Landmarks.cs). Its spot moves up to
+ // 20 m (house scale) from the one asked for, so that whole reach must be off the towns. That shared path (Claim)
+ // tests water, lots and routes but not slope or grid marks, so the spot its Claim (4 m) will take is found first on
+ // a copy of the lots and must be Free as a tent's is (review #557).
+ var tower = At(-((MaabaraCols - 1) * 0.5f * MaabaraPitchU + 10f) * m, 0f);
+ if (rnd.Chance(0.5f) && OffTowns(tower, 20f * m, ground) && !ground.OnToken(tower, 20f * m))
+ {
+ var probe = new Lots();
+ foreach (var l in lots.List) probe.Add(l);
+ if (Claim(probe, tower, 4f * m, id, ground, out var spot) && Free(spot, 4f * m)) WaterTower(id, tower, ground, km, lots);
+ }
+ return (tents, huts, c);
+ }
+
+ // Wear (issue #32, the owner's "creases and breaks, like it really looked"): what the 1948 Haifa transit-camp
+ // photographs show and a box cannot. sRGB targets the canvas and tin weather towards: sun-bleach on the roofs, the
+ // dust a skirt drags in, rust, and the dark of an open door or a missing sheet. Alpha 0 = Facade.Plain.
+ static readonly Color32 Bleach = new Color32(242, 240, 226, 0), Dust = new Color32(128, 107, 82, 0),
+ Rust = new Color32(140, 84, 51, 0), Dark = new Color32(46, 41, 36, 0);
+
+ /// <summary>Washing on the lines: white, faded blue, dull red, grey and ochre.</summary>
+ static readonly Color32[] Laundry =
+ {
+ new Color32(235, 232, 222, 0), new Color32(115, 140, 173, 0), new Color32(168, 77, 64, 0), new Color32(153, 153, 148, 0),
+ new Color32(204, 173, 102, 0),
+ };
+
+ /// <summary>What stands by a door: a wooden crate, a cloth bundle, an olive jerrycan, a blanket roll.</summary>
+ static readonly Color32[] Things =
+ {
+ new Color32(140, 107, 71, 0), new Color32(166, 150, 120, 0), new Color32(89, 97, 64, 0), new Color32(120, 64, 56, 0),
+ };
+
+ /// <summary><paramref name="c"/> moved <paramref name="t"/> of the way to <paramref name="toward"/>, times
+ /// <paramref name="k"/>, alpha 0 (Facade.Plain).</summary>
+ static Color32 Weather(Color32 c, Color32 toward, float t, float k)
+ {
+ var x = Color32.Lerp(c, toward, t);
+ return new Color32((byte)Mathf.Min(255f, x.r * k), (byte)Mathf.Min(255f, x.g * k), (byte)Mathf.Min(255f, x.b * k), 0);
+ }
+
+ /// <summary>A quad turned to face away from <paramref name="inside"/>: sagging canvas has no fixed corner order, so the
+ /// winding is worked out rather than kept by hand.</summary>
+ static void FaceOut(KitMesh km, Vector3 a, Vector3 b, Vector3 c, Vector3 d, Vector3 inside, Color32 colour)
+ {
+ if (Vector3.Dot(Vector3.Cross(c - a, d - b), a + b + c + d - 4f * inside) < 0f) (b, d) = (d, b);
+ colour.a = 0;
+ km.Face(a, b, c, d, colour, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero);
+ }
+
+ /// <summary>A triangle turned to face away from <paramref name="inside"/>.</summary>
+ static void TriOut(KitMesh km, Vector3 a, Vector3 b, Vector3 c, Vector3 inside, Color32 colour)
+ {
+ if (Vector3.Dot(Vector3.Cross(b - a, c - a), a + b + c - 3f * inside) < 0f) (b, c) = (c, b);
+ colour.a = 0;
+ km.Triangle(a, b, c, colour);
+ }
+
+ /// <summary>A quad seen from both sides (washing, a door flap): two faces back to back. A collapsed edge (d = c) makes
+ /// it a triangle; Face takes its normal from the diagonals, so that stays finite.</summary>
+ static void TwoSided(KitMesh km, Vector3 a, Vector3 b, Vector3 c, Vector3 d, Color32 colour)
+ {
+ colour.a = 0;
+ km.Face(a, b, c, d, colour, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero);
+ km.Face(d, c, b, a, colour, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero);
+ }
+
+ /// <summary>A flat lid hidden inside a tent or hut, facing up, a little under its eaves. The sun's shadow pass culls
+ /// back faces and pushes every vertex out along its own normal (URP's normal bias, Kit.shader), so the seams between
+ /// the many small faces of sagging canvas or ribbed tin open into hairline cracks; through them the sun would
+ /// reach the ground behind the shelter as rows of bright dots in its shadow. The lid catches that light.</summary>
+ static void ShadowLid(KitMesh km, Vector3[] rim, Color32 colour)
+ {
+ var c = Vector3.zero;
+ foreach (var v in rim) c += v;
+ c /= rim.Length;
+ colour.a = 0;
+ for (int i = 0; i < rim.Length; i++)
+ {
+ Vector3 a = rim[i], b = rim[(i + 1) % rim.Length];
+ if (Vector3.Cross(b - c, a - c).y > 0f) km.Triangle(c, b, a, colour); else km.Triangle(c, a, b, colour);
+ }
+ }
+
+ /// <summary>A canvas ridge tent (or a canvas hut on a wooden frame): <paramref name="wallM"/> walls under a ridge
+ /// <paramref name="riseM"/> higher (real m, times the house scale <paramref name="m"/>), the ridge along w. Canvas is
+ /// never taut: the ridge sags <paramref name="sagM"/> between its three poles (which stand out as the peaks), the roof
+ /// panels droop mid-span, the walls fold in and out a little per column, the skirt is pegged out unevenly, and some
+ /// tents lean. Weathered in the vertex colour: bleached high on the roof, dusty along the skirt, now and then a
+ /// patch of other canvas. <paramref name="door"/> pins the +w end's flap open on the dark inside. Flat-shaded, so
+ /// every fold catches the sun on its own.</summary>
+ static void RidgeTent(KitMesh km, Vector2 p, float yaw, float w, float d, float wallM, float riseM, float sagM, Color32 canvas,
+ KitGround ground, float m, ref KitRandom wear, bool door)
+ {
+ const int N = 8, Span = 4; // columns along the ridge; a pole every Span columns (both ends and the middle)
+ var (bottom, top) = GroundSpan(p, yaw, w, d, ground, m);
+ float a = yaw * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);
+ float lean = wear.Chance(0.4f) ? wear.Range(-0.12f, 0.12f) : 0f; // across the ridge, per metre of height
+ Vector3 P(float u, float v, float y)
+ {
+ v += lean * Mathf.Max(0f, y - top);
+ return new Vector3(p.x + u * ca - v * sa, y, p.y + u * sa + v * ca);
+ }
+ float eave = top + wallM * m, ridge = eave + riseM * m, knee = top + 0.35f * m;
+ var R = new Vector3[N + 1];
+ Vector3[,] E = new Vector3[2, N + 1], Mi = new Vector3[2, N + 1], K = new Vector3[2, N + 1], B = new Vector3[2, N + 1];
+ for (int i = 0; i <= N; i++)
+ {
+ float u = (i / (float)N - 0.5f) * w, between = Mathf.Sin(Mathf.PI * (i % Span) / Span), sag = sagM * m * between;
+ R[i] = P(u, 0f, ridge - sag);
+ for (int s = 0; s < 2; s++)
+ {
+ float side = s == 0 ? -1f : 1f, crease = wear.Range(-0.08f, 0.08f) * m, flare = wear.Range(0.06f, 0.24f) * m;
+ float ey = eave - 0.4f * sag; // the wall tops sag with the ridge, less
+ E[s, i] = P(u, side * (0.5f * d + 0.5f * crease), ey);
+ K[s, i] = P(u, side * (0.5f * d + flare + crease), knee + wear.Range(-0.08f, 0.05f) * m);
+ B[s, i] = P(u, side * (0.5f * d + flare + crease), bottom);
+ Mi[s, i] = P(u, side * (0.25f * d + 0.6f * crease), 0.5f * (ey + ridge - sag) - sagM * m * (0.35f + 0.65f * between));
+ }
+ }
+ var inside = P(0f, 0f, top + 0.3f * wallM * m);
+ float lid = eave - 0.5f * sagM * m - 0.05f * m, lu = 0.5f * w - 0.1f * m, lv = 0.5f * d - 0.1f * m;
+ ShadowLid(km, new[] { P(-lu, -lv, lid), P(lu, -lv, lid), P(lu, lv, lid), P(-lu, lv, lid) }, Dark);
+ // Up to two patches (a roof cell each: side, column, lower or upper half) sewn from the other canvas.
+ int patchA = wear.Range(-2 * N, 4 * N), patchB = wear.Range(-2 * N, 4 * N);
+ var patch = Weather(canvas, canvas.r > 200 ? new Color32(160, 150, 115, 0) : Bleach, 0.5f, 1f);
+ for (int i = 0; i < N; i++)
+ {
+ float k = 1f + wear.Range(-0.05f, 0.05f);
+ for (int s = 0; s < 2; s++)
+ {
+ int cell = (s * N + i) * 2;
+ FaceOut(km, B[s, i], K[s, i], K[s, i + 1], B[s, i + 1], inside, Weather(canvas, Dust, 0.45f, 0.82f * k));
+ FaceOut(km, K[s, i], E[s, i], E[s, i + 1], K[s, i + 1], inside, Weather(canvas, Dust, 0.08f, k));
+ FaceOut(km, E[s, i], Mi[s, i], Mi[s, i + 1], E[s, i + 1], inside,
+ cell == patchA || cell == patchB ? patch : Weather(canvas, Bleach, 0.1f, k));
+ FaceOut(km, Mi[s, i], R[i], R[i + 1], Mi[s, i + 1], inside,
+ cell + 1 == patchA || cell + 1 == patchB ? patch : Weather(canvas, Bleach, 0.3f, k));
+ }
+ }
+ for (int e = 0; e < 2; e++)
+ {
+ int c = e * N;
+ FaceOut(km, B[0, c], K[0, c], K[1, c], B[1, c], inside, Weather(canvas, Dust, 0.45f, 0.8f));
+ FaceOut(km, K[0, c], E[0, c], E[1, c], K[1, c], inside, Weather(canvas, Dust, 0.08f, 0.97f));
+ // The end's gable follows the drooping roof edge: a fan from the middle of its foot.
+ var g = 0.5f * (E[0, c] + E[1, c]); var gc = Weather(canvas, Bleach, 0.15f, 0.97f);
+ TriOut(km, E[0, c], Mi[0, c], g, inside, gc); TriOut(km, Mi[0, c], R[c], g, inside, gc);
+ TriOut(km, R[c], Mi[1, c], g, inside, gc); TriOut(km, Mi[1, c], E[1, c], g, inside, gc);
+ }
+ if (door)
+ {
+ // The doorway, dark, and its flap swung out on the doorway's edge.
+ float u = 0.5f * w + 0.03f * m, dh = top + 0.7f * (wallM + riseM) * m, half = 0.45f * m;
+ TriOut(km, P(u, -half, top), P(u, 0f, dh), P(u, half, top), inside, Dark);
+ var flapEnd = P(u + 0.7f * m, half + 0.55f * m, top + 0.15f * m);
+ TwoSided(km, P(u, half, top), P(u, 0f, dh), flapEnd, flapEnd, Weather(canvas, Dust, 0.15f, 0.9f));
+ }
+ }
+
+ /// <summary>A round bell tent of radius <paramref name="r"/>: a short wall under a cone, the hem pulled out at the
+ /// pegs (scalloped), the cone sagging between its seams, the pole leaning the apex off centre, a dust band round the
+ /// foot, bleached on top; in some the door panel is open on the dark inside.</summary>
+ static void BellTent(KitMesh km, Vector2 p, float r, Color32 canvas, KitGround ground, float m, ref KitRandom wear)
+ {
+ const int S = 10;
+ var (bottom, top) = GroundSpan(p, 0f, 2f * r, 2f * r, ground, m);
+ float wall = top + 0.9f * m, turn = wear.Range(0f, 2f * Mathf.PI);
+ var lean = new Vector2(wear.Range(-0.3f, 0.3f), wear.Range(-0.3f, 0.3f)) * m;
+ var apex = new Vector3(p.x + lean.x, wall + 2.2f * m, p.y + lean.y);
+ var inside = new Vector3(p.x, top + 0.3f * m, p.y);
+ Vector3[] B = new Vector3[S], K = new Vector3[S], W = new Vector3[S], Mi = new Vector3[S];
+ for (int i = 0; i < S; i++)
+ {
+ float th = turn + 2f * Mathf.PI * i / S;
+ var dir = new Vector2(Mathf.Cos(th), Mathf.Sin(th));
+ var hem = p + dir * r * (1f + (i % 2 == 0 ? 0.1f : 0.02f) + wear.Range(0f, 0.05f)); // pulled out at the pegs
+ B[i] = new Vector3(hem.x, bottom, hem.y);
+ K[i] = new Vector3(hem.x, top + (0.3f + wear.Range(-0.06f, 0.04f)) * m, hem.y);
+ var wv = p + dir * r * (1f + wear.Range(-0.03f, 0.03f)) + lean * 0.25f;
+ W[i] = new Vector3(wv.x, wall, wv.y);
+ Mi[i] = Vector3.Lerp(W[i], apex, 0.5f) + Vector3.down * ((i % 2 == 1 ? 0.2f : 0.05f) * m); // seams at the pegs
+ }
+ var rim = new Vector3[S];
+ for (int i = 0; i < S; i++) rim[i] = Vector3.Lerp(new Vector3(p.x, wall, p.y), W[i], 0.92f) + Vector3.down * (0.1f * m);
+ ShadowLid(km, rim, Dark);
+ int doorAt = wear.Chance(0.4f) ? wear.Range(0, S) : -1, patchAt = wear.Chance(0.5f) ? wear.Range(0, S) : -1;
+ for (int i = 0; i < S; i++)
+ {
+ int j = (i + 1) % S;
+ float k = 1f + wear.Range(-0.05f, 0.05f);
+ FaceOut(km, B[i], K[i], K[j], B[j], inside, Weather(canvas, Dust, 0.45f, 0.82f * k));
+ FaceOut(km, K[i], W[i], W[j], K[j], inside, i == doorAt ? Dark : Weather(canvas, Dust, 0.1f, k));
+ FaceOut(km, W[i], Mi[i], Mi[j], W[j], inside, i == patchAt ? Weather(canvas, Dust, 0.35f, 0.9f) : Weather(canvas, Bleach, 0.1f, k));
+ TriOut(km, Mi[i], apex, Mi[j], inside, Weather(canvas, Bleach, 0.3f, k));
+ }
+ }
+
+ /// <summary>One sheet's colour: galvanised tin a shade lighter or darker, one in five rusting, now and then a newer,
+ /// brighter one.</summary>
+ static Color32 SheetColour(Color32 tin, ref KitRandom wear)
+ {
+ float k = 1f + wear.Range(-0.04f, 0.04f);
+ if (wear.Chance(0.2f)) return Weather(tin, Rust, wear.Range(0.25f, 0.6f), 0.94f * k);
+ return Weather(tin, tin, 0f, wear.Chance(0.1f) ? 1.12f : k);
+ }
+
+ /// <summary>A corrugated-tin hut (or the communal hut) <paramref name="w"/> x <paramref name="d"/> (w the longer),
+ /// walls and roof of separate 0.9 m sheets, each its own shade and some rusting. The roof's sheets carry one
+ /// corrugation each (two flanks lit differently: it reads as ribbing at the in-play zoom), and the roof shows its
+ /// years: a sheet missing (the dark inside), one lifted by the wind and askew, others laid crooked.
+ /// <paramref name="patched"/> (the communal hut) adds a run of boards nailed over the wall and a tar-paper patch
+ /// on the roof.</summary>
+ static void TinHut(KitMesh km, Vector2 p, float yaw, float w, float d, float wallM, float riseM, Color32 tin, Color32 roof,
+ KitGround ground, float m, ref KitRandom wear, bool patched)
+ {
+ var (bottom, top) = GroundSpan(p, yaw, w, d, ground, m);
+ float a = yaw * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);
+ Vector3 P(float u, float v, float y) => new Vector3(p.x + u * ca - v * sa, y, p.y + u * sa + v * ca);
+ float eave = top + wallM * m, ridge = eave + riseM * m, sheet = 0.9f * m;
+ var inside = P(0f, 0f, top + 0.5f * wallM * m);
+ var wood = new Color32(128, 102, 71, 0);
+ Vector2[] corners = { new Vector2(-0.5f * w, -0.5f * d), new Vector2(0.5f * w, -0.5f * d), new Vector2(0.5f * w, 0.5f * d), new Vector2(-0.5f * w, 0.5f * d) };
+ int boardsFrom = patched ? wear.Range(2, 8) : -99;
+ for (int e = 0; e < 4; e++)
+ {
+ var c0 = corners[e]; var c1 = corners[(e + 1) % 4];
+ int n = Mathf.Max(1, Mathf.RoundToInt((c1 - c0).magnitude / sheet));
+ for (int k = 0; k < n; k++)
+ {
+ var q0 = Vector2.Lerp(c0, c1, k / (float)n); var q1 = Vector2.Lerp(c0, c1, (k + 1) / (float)n);
+ var col = e == 0 && k >= boardsFrom && k < boardsFrom + 4 ? Weather(wood, wood, 0f, 1f + wear.Range(-0.08f, 0.08f)) : SheetColour(tin, ref wear);
+ FaceOut(km, P(q0.x, q0.y, bottom), P(q0.x, q0.y, eave), P(q1.x, q1.y, eave), P(q1.x, q1.y, bottom), inside, col);
+ }
+ }
+ for (int e = -1; e <= 1; e += 2)
+ TriOut(km, P(e * 0.5f * w, -0.5f * d, eave), P(e * 0.5f * w, 0f, ridge), P(e * 0.5f * w, 0.5f * d, eave), inside, Weather(tin, tin, 0f, 0.97f));
+ float hu = 0.5f * w - 0.05f * m, hv = 0.5f * d - 0.05f * m, hy = eave - 0.05f * m;
+ ShadowLid(km, new[] { P(-hu, -hv, hy), P(hu, -hv, hy), P(hu, hv, hy), P(-hu, hv, hy) }, Dark);
+ // The roof: sheets from the eaves (0.2 m overhang) to the ridge, 0.15 m past each gable.
+ float over = 0.2f * m, vEdge = 0.5f * d + over, yEdge = eave - riseM / (0.5f * d) * m * over, lo = -0.5f * w - 0.15f * m, len = w + 0.3f * m;
+ int ns = Mathf.Max(1, Mathf.RoundToInt(len / sheet));
+ float amp = 0.08f * m;
+ int tarFrom = patched ? wear.Range(0, Mathf.Max(1, ns - 4)) : -99;
+ for (int s = 0; s < 2; s++)
+ {
+ float side = s == 0 ? -1f : 1f;
+ for (int k = 0; k < ns; k++)
+ {
+ float u0 = lo + len * k / ns, u1 = lo + len * (k + 1) / ns, uc = 0.5f * (u0 + u1);
+ bool tar = s == 0 && k >= tarFrom && k < tarFrom + 4;
+ if (!tar && wear.Chance(0.05f)) // a sheet gone: the rafters' dark
+ {
+ FaceOut(km, P(u0, side * vEdge, yEdge), P(u0, 0f, ridge), P(u1, 0f, ridge), P(u1, side * vEdge, yEdge), inside, Dark);
+ continue;
+ }
+ float lift0 = 0f, lift1 = 0f, shift = 0f;
+ if (!tar && wear.Chance(0.12f)) // lifted by the wind at its lower edge, one corner more: dark under it
+ {
+ lift0 = wear.Range(0.15f, 0.4f) * m; lift1 = lift0 * wear.Range(0.2f, 0.8f);
+ FaceOut(km, P(u0, side * vEdge, yEdge), P(u0, 0f, ridge), P(u1, 0f, ridge), P(u1, side * vEdge, yEdge), inside, Dark);
+ }
+ else if (wear.Chance(0.2f)) shift = wear.Range(-0.12f, 0.12f) * m; // laid crooked
+ var col = tar ? Weather(Dark, Dark, 0f, 1.3f + wear.Range(-0.1f, 0.1f)) : SheetColour(roof, ref wear);
+ var up = Vector3.up;
+ var e0 = P(u0 + shift, side * vEdge, yEdge) + up * lift0; var e1 = P(u1 + shift, side * vEdge, yEdge) + up * lift1;
+ var ec = P(uc + shift, side * vEdge, yEdge) + up * (0.5f * (lift0 + lift1) + amp);
+ var t0 = P(u0 + 0.3f * shift, 0f, ridge); var t1 = P(u1 + 0.3f * shift, 0f, ridge); var tc = P(uc + 0.3f * shift, 0f, ridge) + up * amp;
+ FaceOut(km, e0, t0, tc, ec, inside, col);
+ FaceOut(km, ec, tc, t1, e1, inside, Weather(col, col, 0f, 0.88f)); // the rib's shaded flank
+ }
+ }
+ }
+
+ /// <summary>A washing line between two posts (ground points <paramref name="a"/>, <paramref name="b"/>), sagging, with
+ /// three to five pieces of washing in mixed colours hung along it.</summary>
+ static void WashingLine(KitMesh km, Vector3 a, Vector3 b, float m, ref KitRandom wear)
+ {
+ var wood = new Color32(110, 88, 62, 0);
+ float h = 2f * m, post = 0.06f * m, th = 0.05f * m;
+ km.Shaft(a + Vector3.down * (0.5f * m), a + Vector3.up * (h + 0.1f * m), post, post, wood, 4);
+ km.Shaft(b + Vector3.down * (0.5f * m), b + Vector3.up * (h + 0.1f * m), post, post, wood, 4);
+ Vector3 Line(float t) => Vector3.Lerp(a, b, t) + Vector3.up * (h - 0.25f * m * 4f * t * (1f - t));
+ var rope = new Color32(180, 175, 160, 0);
+ for (int k = 0; k < 2; k++)
+ {
+ Vector3 l0 = Line(0.5f * k), l1 = Line(0.5f * (k + 1));
+ TwoSided(km, l0, l0 + Vector3.up * th, l1 + Vector3.up * th, l1, rope);
+ }
+ var along = b - a; along.y = 0f; float length = along.magnitude; along /= Mathf.Max(length, 1e-3f);
+ var across = Vector3.Cross(Vector3.up, along);
+ int n = wear.Range(3, 6);
+ float at = wear.Range(0.06f, 0.15f);
+ for (int k = 0; k < n && at < 0.9f; k++)
+ {
+ float cw = wear.Range(0.5f, 0.95f) * m / length, ch = wear.Range(0.55f, 1f) * m;
+ Vector3 top0 = Line(at), top1 = Line(Mathf.Min(at + cw, 0.95f)), sway = across * (wear.Range(-0.05f, 0.05f) * m);
+ TwoSided(km, top0 + Vector3.down * ch + sway, top0, top1, top1 + Vector3.down * ch + sway,
+ Weather(Laundry[wear.Range(0, Laundry.Length)], Dust, wear.Range(0f, 0.15f), 1f));
+ at += cw + wear.Range(0.03f, 0.12f);
+ }
+ }
+
+ /// <summary>One to three small things by a door at <paramref name="at"/>: crates, bundles, a jerrycan.</summary>
+ static void Belongings(KitMesh km, Vector2 at, float yaw, KitGround ground, float m, ref KitRandom wear)
+ {
+ int n = wear.Range(1, 4);
+ for (int k = 0; k < n; k++)
+ {
+ var q = at + (k == 0 ? Vector2.zero : new Vector2(wear.Range(-0.35f, 0.35f), wear.Range(-0.35f, 0.35f)) * m);
+ float s = wear.Range(0.35f, 0.65f) * m, hgt = wear.Range(0.3f, 0.6f) * m, y = ground.Y(q.x, q.y);
+ var col = Weather(Things[wear.Range(0, Things.Length)], Dust, wear.Range(0f, 0.2f), 1f);
+ km.Box(q.x, q.y, yaw + wear.Range(-25f, 25f), s, s * wear.Range(0.6f, 1f), y - 0.2f * m, y, hgt, col, Weather(col, Bleach, 0.2f, 1f), Facade.Plain, m);
+ }
+ }
+
+ /// <summary>The camp's centre: the dry spot nearest <paramref name="want"/> (rings of half a reach) in the hex
+ /// <paramref name="want"/> stands in, whose inner half stays off every town's plots, that is gentle and whose whole
+ /// reach is clear of the unit tokens (Encampments' tests) and of the camps built before it. The player picks the hex,
+ /// so the camp stands in it, where selection and the info panel point (review #557). False when there is none: the
+ /// camp is then drawn as its box.</summary>
+ static bool MaabaraSpot(Vector2 want, float reach, KitGround ground, Lots lots, out Vector2 at)
+ {
+ // From any point of a hex the whole hex lies within two circumradii.
+ float step = reach * 0.5f, max = 2f * ground.HexSizeM;
+ var hex = ground.Hex(want.x, want.y);
+ for (int ring = 0; ring * step <= max; ring++)
+ {
+ int around = ring == 0 ? 1 : 6 * ring;
+ for (int k = 0; k < around; k++)
+ {
+ float a = 2f * Mathf.PI * k / around;
+ var p = want + new Vector2(Mathf.Cos(a), Mathf.Sin(a)) * (ring * step);
+ if (!ground.Inside(p.x, p.y) || ground.Hex(p.x, p.y) != hex || ground.Water(p.x, p.y) || !OffTowns(p, step, ground) || ground.Slope(p.x, p.y, 600f) > 0.12f
+ || ground.OnToken(p, reach) || !lots.Free(p, reach)) continue;
+ at = p; return true;
+ }
+ }
+ at = want; return false;
+ }
+
+ /// <summary>No kit footprint (a town's, a 1948 locality's or a Bedouin camp's, out to <see cref="PlotReach"/> of its
+ /// radius, where a town's plots end) reaches a disc of radius <paramref name="r"/> at <paramref name="p"/>. A linear
+ /// scan: some 350 footprints, and only when a camp is placed.</summary>
+ static bool OffTowns(Vector2 p, float r, KitGround ground)
+ {
+ foreach (var f in ground.Footprints)
+ {
+ float d = f.radius * PlotReach + r;
+ if ((p - f.centre).sqrMagnitude < d * d) return false;
+ }
+ return true;
+ }
+ }
+}
diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.Maabara.cs.meta b/unity/Assets/Scripts/Map/Kits/SettlementKits.Maabara.cs.meta
new file mode 100644
index 000000000..d60bd1108
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.Maabara.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: b29235a7647842e1884ece3d94bf7d6e
\ No newline at end of file
diff --git a/unity/Assets/Scripts/Map/MapScene.cs b/unity/Assets/Scripts/Map/MapScene.cs
index 526f663e9..b82ab6fee 100644
--- a/unity/Assets/Scripts/Map/MapScene.cs
+++ b/unity/Assets/Scripts/Map/MapScene.cs
@@ -25,6 +25,10 @@ namespace Statecraft.Game.Map
public HexFile Hexes { get; private set; }
public Terrain Terrain { get; private set; }
public Material MarkerMaterial => markerMaterial;
+ /// <summary>Kit.mat (null without the kits), for the transit camps' kits PlacementLayer builds when a camp is placed.</summary>
+ public Material KitMaterial => kitMaterial;
+ /// <summary>The heightmap's lowest elevation (m) as the last Build read it: a KitGround built after the map needs it.</summary>
+ public float ElevMinM { get; private set; }
/// <summary>The settlements the last Build placed (settlements_1948.yaml), for the UI's map labels and, through
/// SettlementsFor, the info panel's names. Read only: the markers, the kits, the labels and GameRoot share this one
/// list and its objects; nothing may write to them.</summary>
@@ -201,6 +205,10 @@ namespace Statecraft.Game.Map
/// Build or without the unit file.</summary>
public IReadOnlyList<(Vector2 centre, float radius)> UnitClearings { get; private set; } = new List<(Vector2, float)>();
+ /// <summary>The unit tokens that stand outside the towns (centre x, z; ring radius m), as the kits get them
+ /// (KitGround.Tokens): the transit camps PlacementLayer builds later keep off them too. Empty before Build.</summary>
+ public IReadOnlyList<(Vector2 centre, float radius)> UnitTokens { get; private set; } = new List<(Vector2, float)>();
+
/// <summary>The last Build's kit numbers (buildings, vertices, trees, build time), or null without kits.</summary>
public Kits.KitLayer.Stats KitStats { get; private set; }
@@ -236,6 +244,7 @@ namespace Statecraft.Game.Map
Clear();
kitColumns.Clear(); kitProbe = null;
var (meta, heights) = HeightmapLoader.Load(inputs.HeightmapJson, inputs.HeightmapR16z, MetaPath);
+ ElevMinM = meta.elev_min_m;
DiagLog.BootPhase("heightmap decoded");
Hexes = MapBuilder.LoadHexes(inputs.HexesJson, HexesPath);
DiagLog.BootPhase("hexes parsed");
@@ -344,6 +353,7 @@ namespace Statecraft.Game.Map
}
UnitClearings = clearings;
DiagLog.BootPhase("units placed"); // issue #321: the routes' corridors, the footprints and the unit spots
+ UnitTokens = unitRings;
if (kitsOn)
{
// ?kitscale=, ?housescale=, ?treescale= in the WebGL player: the same layout at another symbolic scale (city
diff --git a/unity/Assets/Scripts/Map/PlacementLayer.cs b/unity/Assets/Scripts/Map/PlacementLayer.cs
index 75c79a663..9b40ced63 100644
--- a/unity/Assets/Scripts/Map/PlacementLayer.cs
+++ b/unity/Assets/Scripts/Map/PlacementLayer.cs
@@ -1,13 +1,18 @@
#nullable enable
using System.Collections.Generic;
+using Statecraft.Game.Map.Kits;
using Statecraft.Sim;
using UnityEngine;
+using UnityEngine.Rendering;
namespace Statecraft.Game.Map
{
/// <summary>Draws the player's transit camps and housing projects as marker boxes on their hex centres (placeholder art
/// like the M2 settlement markers; per-era prefabs are M4). Uses the editor-made marker material with a per-kind
- /// colour through a MaterialPropertyBlock (no runtime Shader.Find). Render replaces what it drew before.</summary>
+ /// colour through a MaterialPropertyBlock (no runtime Shader.Find). Render replaces what it drew before.
+ /// With the map's kits built, a transit camp is drawn as a ma'abara kit instead (SettlementKits.Maabarot, issue #32),
+ /// built here when the camp is placed rather than at map build (the boot budget, #321); a camp that finds no free
+ /// ground keeps its box. With the "kits" toggle off every camp is its box again, as the settlements are (KitLayer).</summary>
public sealed class PlacementLayer : MonoBehaviour
{
static readonly Dictionary<string, (Color colour, float size)> Look = new Dictionary<string, (Color, float)>
@@ -17,19 +22,40 @@ namespace Statecraft.Game.Map
};
static readonly int BaseColor = Shader.PropertyToID("_BaseColor");
+ // The last Render's inputs and the "kits" toggle as it drew them: a flip of the toggle redraws (MapScene.KitsShown is
+ // polled, as the map labels poll it), so a camp is always drawn by its kit or its box, never by both or neither.
+ List<Placement>? lastPlacements; Content? lastContent; MapScene? lastMap; bool kitsShown;
+
+ void LateUpdate()
+ {
+ if (lastPlacements != null && lastContent != null && lastMap != null && lastMap.KitsShown != kitsShown)
+ Render(lastPlacements, lastContent, lastMap);
+ }
+
public void Render(IEnumerable<Placement> placements, Content content, MapScene map)
{
+ var cube = Resources.GetBuiltinResource<Mesh>("Cube.fbx");
for (int i = transform.childCount - 1; i >= 0; i--)
{
var old = transform.GetChild(i).gameObject;
- if (Application.isPlaying) { old.transform.SetParent(null); Destroy(old); } else DestroyImmediate(old);
+ // A camp's kit mesh is its own (the boxes share the built-in cube): it goes with its object.
+ var filter = old.GetComponent<MeshFilter>();
+ var own = filter != null && filter.sharedMesh != cube ? filter.sharedMesh : null;
+ if (Application.isPlaying) { old.transform.SetParent(null); Destroy(old); if (own != null) Destroy(own); }
+ else { DestroyImmediate(old); if (own != null) DestroyImmediate(own); }
}
- var cube = Resources.GetBuiltinResource<Mesh>("Cube.fbx");
+ var list = new List<Placement>(placements);
+ lastPlacements = list; lastContent = content; lastMap = map; kitsShown = map.KitsShown;
+ var holes = new List<(Vector2 centre, float radius)>();
+ var kits = kitsShown ? Camps(list, content, map, holes) : new HashSet<string>();
+ // The kit trees planted at map build are left out under a camp's kit while it stands (as under the unit figures,
+ // issue #249), at draw time; a camp drawn as its box, or gone, gives them back.
+ Units.UnitShowcase.HideTrees(map, "placements", holes);
var block = new MaterialPropertyBlock();
- foreach (var p in placements)
+ foreach (var p in list)
{
var hex = content.HexAt(p.Q, p.R);
- if (hex == null || !Look.TryGetValue(p.Action, out var look)) continue;
+ if (hex == null || !Look.TryGetValue(p.Action, out var look) || kits.Contains($"{p.Action}_{p.Q}_{p.R}")) continue;
var at = map.Frame.ToWorld(hex.Lon, hex.Lat, 0);
at.y = map.Terrain.SampleHeight(at) + map.Terrain.transform.position.y;
var box = new GameObject($"{p.Action}_{p.Q}_{p.R}");
@@ -42,5 +68,51 @@ namespace Statecraft.Game.Map
box.transform.localScale = new Vector3(look.size * 1.6f, look.size, look.size);
}
}
+
+ /// <summary>Draws every transit camp of <paramref name="list"/> as a ma'abara kit (one object each, named as its box
+ /// would be, drawn with Kit.mat); returns the names of those drawn and adds the ground each tent, hut, communal hut
+ /// and water tower stands on (the disc round it) to <paramref name="holes"/>.</summary>
+ HashSet<string> Camps(List<Placement> list, Content content, MapScene map, List<(Vector2 centre, float radius)> holes)
+ {
+ var camps = new List<(string id, Vector2 at)>();
+ foreach (var p in list)
+ {
+ var hex = p.Action == MapActions.TransitCamp ? content.HexAt(p.Q, p.R) : null;
+ if (hex == null) continue;
+ var w = map.Frame.ToWorld(hex.Lon, hex.Lat, 0);
+ camps.Add(($"{p.Action}_{p.Q}_{p.R}", new Vector2(w.x, w.z)));
+ }
+ var drawn = new HashSet<string>();
+ if (camps.Count == 0) return drawn;
+ var built = SettlementKits.Maabarot(camps, CampGround(map), out var placed);
+ foreach (var p in placed) holes.Add((p.C, 0.5f * new Vector2(p.W, p.D).magnitude));
+ for (int i = 0; i < camps.Count; i++)
+ {
+ var mesh = built[i].mesh;
+ if (mesh == null) continue;
+ var go = new GameObject(camps[i].id);
+ go.transform.SetParent(transform, false);
+ go.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); // the kit's vertices are in world space
+ go.AddComponent<MeshFilter>().sharedMesh = mesh;
+ var r = go.AddComponent<MeshRenderer>();
+ r.sharedMaterial = map.KitMaterial;
+ r.shadowCastingMode = ShadowCastingMode.On;
+ drawn.Add(camps[i].id);
+ }
+ return drawn;
+ }
+
+ /// <summary>The ground a camp is built on: the map's terrain with every kit's footprint (towns, 1948 localities,
+ /// Bedouin camps: MapScene.KitFootprints), the railways' and roads' corridors and the units' clearings and tokens (as
+ /// KitLayer.Build is given them), so a camp keeps off all of them.</summary>
+ internal static KitGround CampGround(MapScene map)
+ {
+ var ground = new KitGround(map.Terrain, map.Frame, map.Hexes, map.ElevMinM);
+ foreach (var f in map.KitFootprints) ground.Footprints.Add(f);
+ foreach (var (line, half) in map.RouteCorridors) ground.AddCorridor(line, half);
+ foreach (var c in map.UnitClearings) ground.AddCorridor(new List<Vector2> { c.centre, c.centre + Vector2.right }, c.radius);
+ ground.Tokens.AddRange(map.UnitTokens);
+ return ground;
+ }
}
}
diff --git a/unity/Assets/Tests/EditMode/KitTests.cs b/unity/Assets/Tests/EditMode/KitTests.cs
index 601aeffe8..69e61ffbc 100644
--- a/unity/Assets/Tests/EditMode/KitTests.cs
+++ b/unity/Assets/Tests/EditMode/KitTests.cs
@@ -541,6 +541,249 @@ public class KitTests
Assert.IsTrue(kits.All(r => r.enabled)); Assert.IsTrue(markers.All(r => !r.enabled));
}
+ /// <summary>A settlement's point on the ground plane (world x, z).</summary>
+ static Vector2 Spot(MapScene map, string id)
+ {
+ var s = map.Settlements.Single(x => x.Id == id); var w = map.Frame.ToWorld(s.Lon, s.Lat, 0);
+ return new Vector2(w.x, w.z);
+ }
+
+ /// <summary>Issue #32: a ma'abara of 1950-51 is mostly canvas tents with a few tin or canvas huts. The hut share is a
+ /// parameter (a staged look later), and it changes what stands on a plot, never which plots are used.</summary>
+ [Test]
+ public void AMaabaraIsMostlyTentsWithAFewHuts()
+ {
+ var map = OpenMap();
+ var g = PlacementLayer.CampGround(map);
+ var camp = new List<(string id, Vector2 at)> { ("transit_camp_revivim", Spot(map, "revivim")) };
+ var mixed = SettlementKits.Maabarot(camp, g)[0];
+ var tents = SettlementKits.Maabarot(camp, g, 0f)[0];
+ var huts = SettlementKits.Maabarot(camp, g, 1f)[0];
+ TestContext.WriteLine($"share {SettlementKits.MaabaraHutShare}: {mixed.tents} tents, {mixed.huts} huts, {mixed.mesh?.vertexCount} vertices");
+ Assert.IsNotNull(mixed.mesh, "the camp found free ground");
+ Assert.Greater(mixed.huts, 0, "a few huts"); Assert.Greater(mixed.tents, 2 * mixed.huts, "mostly tents");
+ Assert.AreEqual((mixed.tents + mixed.huts, 0), (tents.tents, tents.huts), "share 0: tents only, on the same plots");
+ Assert.AreEqual((0, mixed.tents + mixed.huts), (huts.tents, huts.huts), "share 1: huts only, on the same plots");
+ foreach (var k in new[] { mixed, tents, huts }) if (k.mesh != null) Object.DestroyImmediate(k.mesh);
+ }
+
+ /// <summary>Issue #32: ma'abarot are seeded (two builds, the same camps), stand on dry land clear of every town's plots,
+ /// the 1948 localities and the Bedouin camps, keep off the routes, and two camps asked for on the same ground keep
+ /// apart: a camp stands in its own hex (review #557), so the second finds none left there (the first camp's lots) and
+ /// is drawn as its box, as a camp on Tel Aviv's own point is, the city's plots covering its hex. No pairwise overlap
+ /// check between camps: a hex holds one placement (MapActions.Check), every structure stands in its camp's hex, and
+ /// on all 34 pairs of neighbouring settlement hexes the two camps never touched, built together (1 km apart at the
+ /// closest) or separately on their own lots (review #557), so such a check would compare nothing that could fail.</summary>
+ [Test]
+ public void MaabarotAreSeededAndStandOnFreeDryGround()
+ {
+ var map = OpenMap();
+ var camps = new List<(string id, Vector2 at)> { ("a", Spot(map, "revivim")), ("b", Spot(map, "revivim")), ("c", Spot(map, "tel_aviv")) };
+ var g = PlacementLayer.CampGround(map);
+ var first = SettlementKits.Maabarot(camps, g, out var placed);
+ var second = SettlementKits.Maabarot(camps, PlacementLayer.CampGround(map));
+ Assert.IsNull(first[1].mesh, "b: no ground left in Revivim's hex"); Assert.IsNull(second[1].mesh);
+ Assert.IsNull(first[2].mesh, "c: no ground in Tel Aviv's hex"); Assert.IsNull(second[2].mesh);
+ for (int i = 0; i < 1; i++)
+ {
+ Assert.IsNotNull(first[i].mesh, camps[i].id + ": found free ground");
+ Assert.AreEqual((first[i].tents, first[i].huts), (second[i].tents, second[i].huts), camps[i].id);
+ Assert.AreEqual(first[i].mesh!.vertexCount, second[i].mesh!.vertexCount, camps[i].id);
+ Assert.AreEqual(first[i].mesh!.bounds, second[i].mesh!.bounds, camps[i].id);
+ Assert.Greater(placed.Count(p => p.Id == camps[i].id && p.Kind == "tent"), 0, camps[i].id);
+ Assert.LessOrEqual(placed.Count(p => p.Id == camps[i].id && p.Kind == "communal_hut"), 1, camps[i].id);
+ }
+ foreach (var k in first.Concat(second)) if (k.mesh != null) Object.DestroyImmediate(k.mesh);
+ TestContext.WriteLine(string.Join(", ", camps.Select((c, i) => $"{c.id}: {first[i].tents} tents, {first[i].huts} huts")));
+ int wet = 0, inTown = 0, onRoute = 0;
+ foreach (var p in placed)
+ {
+ if (g.Water(p.C.x, p.C.y)) wet++;
+ if (g.InTown(p.C.x, p.C.y, SettlementKits.PlotReach)) inTown++;
+ if (g.OnRoute(p.C, 0f)) onRoute++;
+ }
+ Assert.AreEqual(0, wet, "a tent or hut in the water");
+ Assert.AreEqual(0, inTown, "a tent or hut on a town's, locality's or Bedouin camp's ground");
+ Assert.AreEqual(0, onRoute, "a tent or hut on a railway or road");
+ }
+
+ /// <summary>Issue #32: with the kits on, a transit camp is drawn as a ma'abara kit (Kit.mat, its own mesh) in place of its
+ /// marker box, built when the camp is placed; housing keeps its box, and the redraw frees the camp's mesh.</summary>
+ [Test]
+ public void ATransitCampIsDrawnAsAMaabaraWhenItIsPlaced()
+ {
+ var map = OpenMap();
+ var c = Statecraft.Sim.ContentLoader.Load(Statecraft.Game.Paths.Content);
+ var hex = c.SettlementHexes.Single(s => s.Id == "revivim");
+ var date = new System.DateTime(1950, 8, 26);
+ var layer = new GameObject("Placements").AddComponent<PlacementLayer>();
+ layer.Render(new[] { new Statecraft.Sim.Placement(Statecraft.Sim.MapActions.TransitCamp, hex.Q, hex.R, date) }, c, map);
+ Assert.AreEqual(1, layer.transform.childCount);
+ var camp = layer.transform.GetChild(0);
+ Assert.AreEqual($"{Statecraft.Sim.MapActions.TransitCamp}_{hex.Q}_{hex.R}", camp.name, "named as its box was");
+ Assert.AreSame(AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/Kit.mat"), camp.GetComponent<MeshRenderer>().sharedMaterial);
+ var mesh = camp.GetComponent<MeshFilter>().sharedMesh;
+ Assert.AreNotSame(Resources.GetBuiltinResource<Mesh>("Cube.fbx"), mesh, "a kit, not the marker box");
+ Assert.Greater(mesh.vertexCount, 300, "rows of tents");
+ layer.Render(new[] { new Statecraft.Sim.Placement(Statecraft.Sim.MapActions.Housing, hex.Q, hex.R, date) }, c, map);
+ Assert.IsTrue(mesh == null, "the camp's mesh goes with it");
+ Assert.AreEqual(1, layer.transform.childCount);
+ Assert.AreSame(map.MarkerMaterial, layer.transform.GetChild(0).GetComponent<MeshRenderer>().sharedMaterial, "housing keeps its box");
+ }
+
+ /// <summary>Review (issue #32): with the "kits" toggle off a transit camp is drawn as its marker box, as the settlements
+ /// are, and no camp kit is visible; switching the kits back on draws the ma'abara again.</summary>
+ [Test]
+ public void WithTheKitsOffATransitCampIsItsBox()
+ {
+ var map = OpenMap();
+ var c = Statecraft.Sim.ContentLoader.Load(Statecraft.Game.Paths.Content);
+ var hex = c.SettlementHexes.Single(s => s.Id == "revivim");
+ var camp = new[] { new Statecraft.Sim.Placement(Statecraft.Sim.MapActions.TransitCamp, hex.Q, hex.R, new System.DateTime(1950, 8, 26)) };
+ var layer = new GameObject("Placements").AddComponent<PlacementLayer>();
+ var kitMat = AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/Kit.mat");
+ VisualToggles.Set("kits", false);
+ layer.Render(camp, c, map);
+ Assert.AreEqual(1, layer.transform.childCount);
+ var box = layer.transform.GetChild(0);
+ Assert.AreSame(Resources.GetBuiltinResource<Mesh>("Cube.fbx"), box.GetComponent<MeshFilter>().sharedMesh, "the marker box");
+ Assert.AreSame(map.MarkerMaterial, box.GetComponent<MeshRenderer>().sharedMaterial);
+ Assert.IsFalse(layer.GetComponentsInChildren<MeshRenderer>().Any(r => r.enabled && r.sharedMaterial == kitMat), "no camp kit drawn");
+ VisualToggles.Set("kits", true);
+ layer.Render(camp, c, map);
+ Assert.AreSame(kitMat, layer.transform.GetChild(0).GetComponent<MeshRenderer>().sharedMaterial, "the kit again");
+ }
+
+ /// <summary>Review (issue #32): the trees planted at map build do not stand in a ma'abara built later. While the camp's kit
+ /// is drawn no tree drawn has its crown on the camp's ground (the disc round each tent, hut, communal hut and water
+ /// tower); housing in its place, or the kits off (the camp is its box), gives them back. Safed's camp lands among the
+ /// hill olives (it was Rosh Pinna's until main's units file left that hex no ground for a camp: see
+ /// AMaabaraKeepsOffTokensGridMarksAndSteepGround).</summary>
+ [Test]
+ public void NoTreeStandsInAMaabara()
+ {
+ var map = OpenMap();
+ var c = Statecraft.Sim.ContentLoader.Load(Statecraft.Game.Paths.Content);
+ var hex = c.SettlementHexes.Single(s => s.Id == "safed");
+ var date = new System.DateTime(1950, 8, 26);
+ var veg = map.GetComponentInChildren<VegetationLayer>(); Assert.IsNotNull(veg);
+ int before = veg.Drawable().Count();
+ var layer = new GameObject("Placements").AddComponent<PlacementLayer>();
+ var camp = new[] { new Statecraft.Sim.Placement(Statecraft.Sim.MapActions.TransitCamp, hex.Q, hex.R, date) };
+ layer.Render(camp, c, map);
+ Assert.AreSame(AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/Kit.mat"), layer.transform.GetChild(0).GetComponent<MeshRenderer>().sharedMaterial, "drawn as its kit");
+ var at = c.HexAt(hex.Q, hex.R)!; var w = map.Frame.ToWorld(at.Lon, at.Lat, 0);
+ var built = SettlementKits.Maabarot(new List<(string id, Vector2 at)> { (layer.transform.GetChild(0).name, new Vector2(w.x, w.z)) },
+ PlacementLayer.CampGround(map), out var placed)[0];
+ if (built.mesh != null) Object.DestroyImmediate(built.mesh);
+ int In(IEnumerable<(TreeKind kind, Matrix4x4 m)> trees) => trees.Count(t => placed.Any(p =>
+ (new Vector2(t.m.m03, t.m.m23) - p.C).magnitude < 0.5f * new Vector2(p.W, p.D).magnitude + VegetationLayer.CrownRadius(t.kind, t.m)));
+ int planted = In(veg.Planted());
+ TestContext.WriteLine($"{placed.Count} structures: {planted} trees planted on them, {veg.Hidden} hidden");
+ Assert.Greater(planted, 0, "the camp stands where trees were planted");
+ Assert.AreEqual(0, In(veg.Drawable()), "a tree drawn in the camp");
+ VisualToggles.Set("kits", false);
+ layer.Render(camp, c, map);
+ Assert.AreEqual(before, veg.Drawable().Count(), "the camp as its box gives the trees back");
+ VisualToggles.Set("kits", true);
+ layer.Render(camp, c, map);
+ Assert.AreEqual(0, In(veg.Drawable()));
+ layer.Render(new[] { new Statecraft.Sim.Placement(Statecraft.Sim.MapActions.Housing, hex.Q, hex.R, date) }, c, map);
+ Assert.AreEqual(before, veg.Drawable().Count(), "housing in the camp's place gives the trees back");
+ Assert.AreEqual(planted, In(veg.Drawable()));
+ }
+
+ /// <summary>Review (issue #32): a ma'abara keeps to the Bedouin camps' rules (Encampments): no tent, hut or water tower
+ /// on a unit token, on a hex edge's grid mark or on steep ground, so a token on the camp's own hex moves it off. Safed's
+ /// camp stands on hilly ground by a hex edge, where those rules refuse plots a build without them fills (review #557: on
+ /// flat Revivim the test passed with the rules removed). It was Rosh Pinna until main's units file placed Carmeli's
+ /// Operation Brosh token beside it (July 1948), whose ring leaves the camp no ground in that hex, so it is a box there.</summary>
+ [Test]
+ public void AMaabaraKeepsOffTokensGridMarksAndSteepGround()
+ {
+ var map = OpenMap();
+ var g = PlacementLayer.CampGround(map);
+ var at = Spot(map, "safed");
+ g.Tokens.Add((at, 300f));
+ var camp = new List<(string id, Vector2 at)> { ("transit_camp_safed", at) };
+ var built = SettlementKits.Maabarot(camp, g, out var placed)[0];
+ Assert.IsNotNull(built.mesh, "the camp found free ground");
+ Object.DestroyImmediate(built.mesh);
+ Assert.Greater(placed.Count, 0);
+ float lot = 4f * KitScale.Houses; // a plot's lot and the water tower's (SettlementKits.MaabaraPlotR, WaterTower)
+ foreach (var p in placed)
+ {
+ Assert.IsFalse(g.OnToken(p.C, 0f), p.Kind + " on a unit token");
+ if (p.Kind != "tent" && p.Kind != "hut" && p.Kind != "water_tower") continue;
+ Assert.IsFalse(g.OnGridMark(p.C, lot), p.Kind + " on a grid mark");
+ Assert.LessOrEqual(g.Slope(p.C.x, p.C.y, 600f), 0.12f, p.Kind + " on steep ground");
+ }
+ SettlementKits.MaabaraGroundRules = false;
+ try
+ {
+ var loose = SettlementKits.Maabarot(camp, g)[0];
+ if (loose.mesh != null) Object.DestroyImmediate(loose.mesh);
+ TestContext.WriteLine($"{built.tents + built.huts} plots with the rules, {loose.tents + loose.huts} without; "
+ + $"{placed.Count(p => p.Kind == "water_tower")} water tower");
+ Assert.Greater(loose.tents + loose.huts, built.tents + built.huts, "the grid-mark and slope rules refused a plot");
+ }
+ finally { SettlementKits.MaabaraGroundRules = true; }
+ }
+
+ /// <summary>Review #557: a camp stands in the hex the player built it on, where selection and the info panel point. Over
+ /// the settlement hexes each camp's centre and the whole footprint of every structure it places (tents, huts, the
+ /// communal hut, the water tower) map back to its own hex, or the camp has no kit and is drawn as its box. Its
+ /// tents, huts and water tower keep off the grid marks and steep ground (the water tower too: review #557, should-fix 3).</summary>
+ [Test]
+ public void AMaabaraStandsInItsOwnHex()
+ {
+ var map = OpenMap();
+ var c = Statecraft.Sim.ContentLoader.Load(Statecraft.Game.Paths.Content);
+ var g = PlacementLayer.CampGround(map);
+ float lot = 4f * KitScale.Houses; // a plot's lot and the water tower's (SettlementKits.MaabaraPlotR, WaterTower)
+ int kits = 0, towers = 0, structures = 0;
+ var boxes = new List<string>();
+ foreach (var hex in c.SettlementHexes)
+ {
+ var at = c.HexAt(hex.Q, hex.R)!; var w = map.Frame.ToWorld(at.Lon, at.Lat, 0);
+ var camp = new List<(string id, Vector2 at)> { ($"{Statecraft.Sim.MapActions.TransitCamp}_{hex.Q}_{hex.R}", new Vector2(w.x, w.z)) };
+ var built = SettlementKits.Maabarot(camp, g, out var placed)[0];
+ if (built.mesh == null) { boxes.Add(hex.Id); continue; }
+ kits++;
+ Object.DestroyImmediate(built.mesh);
+ (int, int) HexOf(Vector2 p)
+ {
+ var (lon, lat) = map.Frame.ToLonLat(new Vector3(p.x, 0f, p.y));
+ return HexPicker.FromLonLat(lon, lat, map.Hexes.bounds, map.Hexes.hex_size_km);
+ }
+ Assert.AreEqual((hex.Q, hex.R), HexOf(built.at), hex.Id + "'s camp");
+ // Every structure, not only the centre: at the house scale the rows reach about 1.6 km from it, the communal
+ // hut about 3 km and the water tower about 2.6 km, against the hex's 4.33 km inradius (review #557). And the
+ // whole of each, not only its centre (review #557, c9): the disc it claims (a plot's lot, which holds a tent or
+ // hut with its washing and belongings, and the water tower; the communal hut's half-diagonal), sampled every 30°.
+ foreach (var p in placed)
+ {
+ structures++;
+ Assert.AreEqual((hex.Q, hex.R), HexOf(p.C), $"{hex.Id}'s {p.Kind} at ({p.C.x:F0}, {p.C.y:F0}) stands in another hex");
+ float r = p.Kind == "communal_hut" ? 0.5f * new Vector2(p.W, p.D).magnitude : lot;
+ for (int k = 0; k < 12; k++)
+ {
+ var q = p.C + new Vector2(Mathf.Cos(k * Mathf.PI / 6f), Mathf.Sin(k * Mathf.PI / 6f)) * r;
+ Assert.AreEqual((hex.Q, hex.R), HexOf(q), $"{hex.Id}'s {p.Kind} at ({p.C.x:F0}, {p.C.y:F0}) reaches into another hex at {k * 30}°");
+ }
+ }
+ foreach (var p in placed.Where(p => p.Kind == "tent" || p.Kind == "hut" || p.Kind == "water_tower"))
+ {
+ if (p.Kind == "water_tower") towers++;
+ Assert.IsFalse(g.OnGridMark(p.C, lot), $"{hex.Id}'s {p.Kind} on a grid mark");
+ Assert.LessOrEqual(g.Slope(p.C.x, p.C.y, 600f), 0.12f, $"{hex.Id}'s {p.Kind} on steep ground");
+ }
+ }
+ TestContext.WriteLine($"{c.SettlementHexes.Count} settlement hexes: {kits} camps drawn as kits ({structures} structures, {towers} water towers), "
+ + $"{boxes.Count} as boxes ({string.Join(", ", boxes)})");
+ Assert.Greater(kits, 0, "some camp finds ground in its own hex");
+ }
+
/// <summary>Review I2: the populations come from content/map/settlement_population_1945.yaml through the map inputs.</summary>
[Test]
public void ThePopulationFileLoadsAndRejectsBadRows()