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: towns round 2, plot lattices and sourced 1948 landmarks (fixes #317, refs #31) (#339)

Eyal Golan5abd16919b8d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 17f27c066..b6a5fcdcd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -209,6 +209,16 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
- The game settlements Lod and Ramla show their 1948 names, Lydda and Ramle, as Village Statistics 1945 lists them
(owner ruling). Content only: the goldens and the smoke run are unchanged; saves made before load with the
"different game content" warning.
+- Map, towns round 2 (#31): the towns are laid out on rows of plots, dense in the core and thinning to the edge, instead
+ of random spots: the 25 towns draw 397 buildings where main drew 216, and no town draws fewer than on main (fixes #317: a small town
+ whose lattice places fewer than 6 houses is filled up with round 1's full-size houses on ground no other place uses;
+ the kits' water test counts a lake hex as water only at the lake's surface, so Tiberias builds on its shore again) (Jaffa 15 to 33, Lod and Ramla 5 to 11, Jerusalem
+ 70 to 110), with 55 landmarks instead of 27. Old Jaffa is packed small stone houses; Tel Aviv's white blocks are
+ taller in the core (promo ruling, at most eight storeys); Haifa has its lower town by the port and Hadar on the slope; Jerusalem has its stone
+ new city, its Arab quarters and a walled Old City; the large moshavot have a plastered centre. Sourced 1948 landmarks: Jerusalem's walls and gates, the
+ citadel, the Haram with the Dome of the Rock (lead dome, as before 1959) and Al-Aqsa; Haifa's port and German Colony;
+ Tel Aviv's port; Ramla's White Tower; Jaffa's lighthouse moved to the hill above the port. Map only: the goldens do not
+ move.
- Sharett's in-game portrait uses a CC0 Van de Poll photograph in place of the US-unverified GPO source (refs #30).
- Hebrew UI wording, still not enabled: a count-neutral pending-decisions line, "מנדטים" for Knesset seats, and
reworded attention and full-war labels (#193).
diff --git a/docs/visual-v1.md b/docs/visual-v1.md
index 7cc62043f..d916a9395 100644
--- a/docs/visual-v1.md
+++ b/docs/visual-v1.md
@@ -1679,6 +1679,296 @@ place carries on; Lydda and Ramle for the game settlements `lod` and `ramla`; Ne
- History: a first version scanned every lot and footprint linearly, taking 350 ms (kits) and 330 ms (trees) in the
editor. `DiscIndex` (a 4 km grid) brought that to about 30 ms each.
- Build: wasm +111,913 bytes and data +14,441, plus the localities file fetched at boot.
+## Towns round 2: dense, era-correct towns (branch `promo-towns-2`, issue #31)
+Question: why do Tel Aviv, Jaffa, Lod, Ramla, Rishon and Petah Tikva read as a sparse handful of boxes at gameplay03
+when promo 03 shows dense miniature towns, and what closes the gap within the frame-time and boot budgets?
+
+### Diagnosis (main `bdb5cd2`, measured before any change)
+Measured with `TownCensusTests.TheCensusIsLogged`. It builds the kits as `MapScene.Build` does, with the routes' and the
+units' clearings as corridors, and logs one `CENSUS` line per town. It reports:
+- **Buildings:** counted per town. Wings are a block's lower part.
+- **Cover:** the share of the town's own land under a building or landmark footprint. "Own land" is its footprint disc,
+ on land, in its cell. It is sampled every 100 m, over the whole disc and over its inner half radius ("core").
+- **Wall heights:** symbolic metres; one storey is 198 m at 60x and 330 m at 100x.
+- **Wall colours:** distinct sRGB colours at 4 bits per channel.
+
+The player logged `KITS buildings=261 vertices=10244 triangles=6892 trees=7283`.
+
+| town | footprint R | buildings (+wings) | landmarks | cover: all / core | wall height min / median / max | wall colours |
+|---|---|---|---|---|---|---|
+| Tel Aviv | 7.6 km | 43 (+11) | none | 24.7% / 24.9% | 396 / 594 / 1188 m | 7 |
+| Jaffa | 5.7 km | 16 | mosque, clock tower, church, lighthouse, breakwater | 42.6% / 14.6% | 330 / 660 / 990 m | 4 |
+| Haifa | 6.9 km | 34 (+10) | none | 17.8% / 23.7% | 396 / 594 / 990 m | 8 |
+| Jerusalem | 7.4 km | 70 | a generic mosque | 32.2% / 16.2% | 330 / 660 / 990 m | 8 |
+| Lod | 2.4 km | 5 | mosque | 13.6% / 11.8% | 330 / 330 / 660 m | 4 |
+| Ramla | 2.3 km | 5 | mosque | 19.5% / 27.6% | 330 m only | 3 |
+| Petah Tikva | 2.4 km | 3 | water tower | 10.5% / 7.0% | 330 / 330 / 660 m | 3 |
+| Rishon LeZion | 1.7 km | 2 | water tower | 9.5% / 2.7% | 330 m only | 2 |
+| all 25 | | 235 (+21) | 26 | | | |
+
+Jaffa's whole-disc cover is above its core cover because its cell is small (Tel Aviv's footprint takes its north) and
+four landmarks of up to 1 km sit in it.
+
+Causes, in order of weight:
+1. **Counts.** `TargetCount` was tuned at 25x and falls with the square of the scale. At the 60x / 100x ruling, every
+ town under about 30,000 people gets its floor of 6 buildings, and then places fewer: 1 to 5 in the moshavot, and 5 in
+ Lod and Ramla.
+2. **Placement.** Buildings went to random spots over the whole footprint (radius drawn as u^0.62), tried against
+ every lot. Each town had about 30 tries per building, and the footprint could stretch to 1.6 R.
+ - That spreads a town evenly at low cover, with no dense core and no street rows. Promo 03's towns are a solid core
+ with streets as the only gaps.
+ - The routes' corridors (300-680 m ribbons plus a 100 m margin) and the units' clearings then cut each disc further.
+3. **Old-town houses too big.** Old towns drew 7-14 m houses at 100x, so each was 0.7-1.4 km wide. Jaffa came out as 16
+ large blocks, not a packed old city.
+4. **Heights.** Tel Aviv's median block was 3 storeys and its tallest 6. Promo 03 shows 5-8. The owner's "promo over
+ era" ruling covers this.
+5. **Landmarks.** Only Jaffa had its own. Jerusalem had a generic mosque, and Haifa and Tel Aviv had none. Jaffa's
+ lighthouse stood at the breakwater's head; the real one (1865) stands on the hilltop above the old port.
+6. **Palette.** It is not the gap: each archetype's colours already match promo 03 (white and cream city, honey stone,
+ tan villages, terracotta roofs). Variety is limited by the counts.
+
+### Plan
+- **Plot lattices** replace the random tries (`SettlementKits.PlaceHouses`).
+ - Each town is laid out in rows of plots at its street grid's angle. Old towns and villages stagger alternate rows
+ and jitter each plot.
+ - Each plot is built with a probability that is near 1 in the core and falls towards the edge, to none at 1.1 R. That
+ is `UnitGround.FootprintMargin`: the units assume no building past it, and `PaintGround` tints the same disc.
+ - A plot by a road, or by another town's lot, tries a smaller building, then a small nudge within the plot, before it
+ stays empty.
+ - Plots are visited nearest the centre first. Each plot draws its random numbers whether or not it is built, so one
+ plot's fate never shifts another's.
+- **Building styles per quarter, at the ruled scales** (city blocks 60x, houses 100x).
+ - **Tel Aviv:** white International Style blocks with flat roofs (the White City, 1930s, Geddes plan 1925-29), some
+ stepped. Taller in the core under the promo ruling.
+ - **Jaffa and the old towns:** small stone houses (4.6-6.6 m real), packed, with domes and roof rooms. Some red tiled
+ roofs outside the core.
+ - **Haifa:** the lower town by the port in stone houses (below about 35 m elevation). Hadar HaCarmel up the slope in
+ white blocks.
+ - **Jerusalem:** stone-faced blocks in the new city to the west (Storrs' 1918 stone ordinance), a few with red roofs.
+ Arab-quarter houses round the other sides. Old-town houses within the walls.
+ - **Large moshavot** (Petah Tikva, Rehovot, Rishon LeZion, Hadera; 7,500+ people in 1945): a plastered two- and
+ three-storey centre inside red-roofed houses.
+ - **Arab towns and villages:** smaller stone houses (4.4-6.6 m) on a staggered lattice.
+- **Landmarks**, placed before any town's houses. Positions keep the real bearing from the settlement's point to the
+ landmark's sourced coordinate; distances and sizes are symbolic.
+ - **Jaffa:** the Mahmoudiya Mosque, the clock tower on the plaza east of it, St Peter's Church, the lighthouse on the
+ hill above the port (red and white bands), and the breakwater and boats.
+ - **Jerusalem:** Suleiman's walls round a symbolic square Old City with five gates, the citadel, the Haram platform,
+ the Dome of the Rock and Al-Aqsa.
+ - The Dome of the Rock is blue and white tiles with a dark lead dome: the gilded dome dates from the 1959-64
+ restoration, so it would be an anachronism in 1948.
+ - Al-Aqsa's dome is lead.
+ - **Haifa:** the 1933 port (main and lee breakwaters, quay sheds) and the German Colony: the Templer houses of 1868 in
+ stone with red roofs, in two rows along its north-south main street.
+ - **Tel Aviv:** its port (1936/1938) at its sourced coordinate.
+ - **Ramla:** the White Tower east of the town's heart.
+- **No anachronisms:**
+ - The Shrine of the Báb's dome (1953) is not drawn.
+ - Neither is the Dagon silo (1955), the gold Dome of the Rock, or any post-1948 tower.
+- **Performance:** one merged mesh per town as before, so the draw calls do not change. The lot index is promo-villages'
+ `DiscIndex`, ported byte for byte with its `KitGround` hunks so the two branches merge cleanly there. It also takes the
+ trees' lot test off its linear scan.
+- **Tests** (`TownCensusTests`):
+ - The towns are deterministic.
+ - Each city's landmarks are present.
+ - No building stands on a route or in the sea.
+ - Each of the four cities has a floor on its built cover.
+
+### Result (after merging the villages, #291)
+The census as the map now builds it: with the 1948 localities, whose landmarks claim their hearts before any town's
+houses (review M8). "Main" is `a3202ad`, with the villages and before towns round 2; same census, same corridors.
+
+| town | buildings, main → round 2 | cover all / core, main → round 2 | median wall height | landmarks, round 2 |
+|---|---|---|---|---|
+| Tel Aviv | 36 (+12 wings) → 43 (+11) | 18.4 / 19.7% → 17.4 / 18.5% | 396 → 792 m (2 → 4 storeys) | port, 3 hangar sheds |
+| Jaffa | 15 → 33 | 29.0 / 21.8% → 32.6 / 31.9% | 660 m | Mahmoudiya Mosque, clock tower, St Peter's, lighthouse on the hill, breakwater |
+| Haifa | 30 (+10) → 45 (+5) | 16.4 / 19.4% → 21.0 / 20.6% | 594 → 660 m | port (main and lee breakwaters, 4 quay sheds), German Colony (Templer houses in two rows) |
+| Jerusalem | 70 → 110 | 25.7 / 19.8% → 22.7 / 24.9% | 660 → 330 m | walls (a gap where a road crosses), 13 gates, citadel, Haram, Dome of the Rock, Al-Aqsa |
+| Lod / Ramla | 5 / 5 → 11 / 11 | | | mosque; Ramla also the White Tower |
+| Petah Tikva / Rehovot / Rishon | 2 / 3 / 2 → 8 / 5 / 3 | | | water tower |
+| all 25 | 216 → 365 (413 after the review: the small-town floor, #317) | | | 27 → 55 |
+
+Distinct wall colours: Haifa 7 → 16 (white blocks, the lower town's stone, the Templer houses), Jerusalem 8 → 14 (stone
+blocks, village houses, red-roofed villas), Jaffa 6 → 7, Tel Aviv 8 → 7.
+
+- **Tel Aviv's cover did not rise.** Before the merge, round 2 had 62 blocks and 30.0% / 25.6%.
+ - The villages' landmarks inside its 7.6 km disc (Sheikh Muwannis, Summeil, Jammasin, Ramat Gan, Bnei Brak and
+ others) now claim their spots first. The lattice loses every plot their mosque or water-tower lots reach.
+ - What changed there is the form: narrower (12-16 m real), taller blocks in rows on the Geddes grid, with a 700 m beach
+ strip in front. The close-up crops show the difference better than the cover does.
+ - Taking the villages' spots back would break the villages' rule that a village keeps its heart, so it is left for the
+ owner.
+- **Jerusalem's Old City is symbolic and squeezed by the roads.**
+ - It is 4 km across, about 4 times the real one. The drawn 1948 roads (300 m ribbons) meet by Jaffa Gate and loop
+ round the north and east, so at any readable size they cross inside the square, through gaps in the walls.
+ - Only one place in its south-east quadrant fits a platform clear of every route: 1.3 x 1.1 km, wider than long. Al-Aqsa
+ therefore stands in its south-east corner, not across its south end.
+ - The citadel is moved east off the drawn Hebron road.
+ - The houses inside the walls are capped at two storeys, and the Dome's walls and drum are 30x high, so the walls and
+ the Dome stand above the roofs.
+- **Readability and colour:**
+ - The grid stays readable: 78% of edge midpoints (69 of 89), against the 75% floor and main's 79%.
+ - The beach beside Tel Aviv reads as sand at 26 of 33 samples (79%, floor 75%).
+ - At gameplay03 (WebGL), the palette distance to promo 03 is 0.43 (main 0.44), warmth 0.068 (0.070) and saturation
+ 0.45 (0.45).
+- **Trees:** `Vegetation.Plant` now draws each tree's random numbers before its lot and route test. A town's new lots
+ remove only the trees they touch, instead of reshuffling every later grove.
+ - Two grade tests sample the selection ring against the land and could land on a crown. They now measure with the
+ trees off: the ring against the ground's graded colour, which is what they test.
+- **Frame time** (headless WebGL `?vprofile`, `machine_lock.py --exclusive --wait-unity`, main `a3202ad` against
+ `49bc88e`, two interleaved rounds each, 2026-10-12, load 3.6 at the start and 7.3 at the end):
+
+ | | gameplay03 all (p95) | gameplay03 all − none | diorama02 all (p95) | diorama02 all − none |
+ |---|---|---|---|---|
+ | main | 13.70 / 14.22 ms (15 / 16) | 3.00 / 3.45 ms | 18.07 / 18.71 ms (20 / 20) | 4.84 / 5.60 ms |
+ | round 2 | 14.15 / 13.97 ms (16 / 15) | 3.59 / 3.15 ms | 18.06 / 18.70 ms (21 / 21) | 5.54 / 5.53 ms |
+
+ - The kits stay one merged mesh per town: 63 draws, as on main. The triangles grow from 61,054 to 65,684.
+ - "-kits" draws the marker boxes instead, so the kits' own cost is within the noise (all − (-kits) is −0.6 / −1.1 ms
+ at gameplay03).
+ - Every budget holds: all − none is under 8 ms, and the p95 at gameplay03 is under 16.7 ms. The diorama02 p95 of 20-21
+ ms is main's too (the villages section).
+
+- **Boot** (`headed.py boot --runs 3`, three interleaved rounds per side, so 9 runs each; main `2b7212e` against this
+ branch's final head; `machine_lock.py --exclusive --wait-unity`, 2026-10-12).
+ - Other sessions loaded the machine (load average 6.5 rising to 25), so single runs reach 3.3 s at cpu 4. The medians
+ and the "kits built" phase are the fair comparison.
+
+ | | map_build median | `kits built` phase median | first_frame median |
+ |---|---|---|---|
+ | cpu 4, main | 2739 ms | 570 ms | 9494 ms |
+ | cpu 4, round 2 | 2679 ms | 563 ms | 8750 ms |
+ | cpu 1, main | 659 ms | 132 ms | 4029 ms |
+ | cpu 1, round 2 | 662 ms | 138 ms | 4020 ms |
+
+ - The towns add about nothing to the boot: the kit phase is 7 ms lighter at cpu 4 and 6 ms heavier at cpu 1.
+ - The lattice checks are cheap first, and only towns with water near them run the beach test.
+ - The earlier session on a quieter machine (main `a3202ad`, before those cuts) measured map_build 2668 → 2683 ms at
+ cpu 4 (6 runs each), with the cpu 1 kit phase 129 → 137 ms.
+ - The budget at cpu 4 is 2720 ms; #195 needs about 100 ms of it. Towns round 2 takes none.
+
+### Review (2026-10-12, on the merge with main `471c300`)
+- **Fixed on the branch:**
+ - The beach setback tested any water, so it also applied on the Sea of Galilee. It now tests the sea only (`Sea`: water
+ that is not a lake hex). Degania goes from 0 houses back to main's 1.
+ - Nahalal's ring ended at 0.88 of the radius, but its lattice's first ring of plots stands at 0.76 and 0.89, so it drew
+ no houses. The ring now runs out to the radius: 0 → 1 (main 1).
+ - Tel Aviv's blocks are capped at eight storeys, promo 03's tallest: the cap was ten. The tallest block is now 7
+ storeys (1,386 m) and the median is still 4.
+ - `TownCensusTests.SmallTownsKeepTheirHousesAndNoBlockOutgrowsThePromo` covers all three.
+- **Each test fails under a mutation:**
+ - Reverting the lake test, the ring and the cap fails the new test on all three counts.
+ - A per-build counter in the plot yaw fails `EveryBuildPlacesTheSameTowns`.
+ - Dropping the plots' route test fails `NoBuildingStandsOnARouteOrInTheSea` (268 placements).
+ - Thinning the core to 0.4 fails `TheCitiesCoverTheirGround`.
+- **Small-town floor (#317, fixed on the branch; reworked after the review of #339):**
+ - At 100x a plot is about 1 km, so a small town (1.3-2 km footprint radius) has about 7 plots, and the routes, the sea or
+ a neighbour's lots take most of them. On the first lattice Tiberias drew 0 houses (main 3), Netanya 1 (main 2) and
+ Beersheba 3 (main 5).
+ - **The lake was half the cause.** The kits' `KitGround.Water` counted every lake hex as water, and a lake hex also holds
+ its shore. Tiberias stands in one, 60-160 m above the Sea of Galilee (about -214 m), so it had no ground left.
+ - A point is now lake water only at or next to the lake's surface, in any hex that is not sea (a shore hex of another
+ biome holds some of the lake too). It uses the rule the drawn water uses
+ (`MapBuilder.LakeBelowM` and `LakeFlatM`, tools/terrain_bake.py): below -150 m and flat within 0.25 m over the
+ heightmap's 3 x 3 window, at the point or within one heightmap sample of it.
+ - The drawn shore (coast.png's distance, interpolated between texel centres) runs up to about a sample past the last
+ flat sample. A first version without that sample's margin put a cypress in the drawn Kinneret, and one that looked
+ only in lake hexes put a palm and a citrus tree in it by Ghuweir Abu Shusha.
+ - The test runs only in a lake's hexes and their neighbours, and each sample's flatness is cached: the rift's floor
+ is asked about thousands of times while the kits are built.
+ - Sea hexes keep their test. The Hula is not water in the heightmap's rule (its surface is about 70 m above sea
+ level), on main or here.
+ - `KitTests.TheLakeIsItsWaterNotItsWholeHex` checks that Tiberias's shore at 35.530 E, 32.7944 N (lake hex, -111 m)
+ is land and that the lake at 35.58 E, 32.80 N (-214.5 m) is water. Each half fails when the lake branch is made
+ always water, or never water.
+ - `KitTests.NothingStandsInALakesDrawnWater` decodes coast.png itself, the file the water shader samples. It checks
+ that no lot centre and no tree trunk in the rift (a lake hex, or ground below -150 m; 129 of them) lies under the
+ drawn water. It fails on the cypress without the sample's margin, and on the palm and the citrus tree with lake
+ hexes only.
+ - Tiberias's lattice now draws 4 houses on its shore, and the fallback a fifth, full-size, beside them.
+ - **The fallback.** A town whose lattice places fewer than 6 houses (round 1's floor, `SmallTownFloor`) is filled up
+ the way round 1 drew it.
+ - Each house is the archetype's full-size building, the size main drew, and keeps its whole footprint as its lot.
+ - It tries 240 spots (`ScatterTries`) from its own stream (`KitRandom(id, 3)`), nearest the town's sourced point
+ first. Every spot is tried at full size before any at 0.72; the half-size fit is never used. Every house keeps the
+ beach setback.
+ - `Build` runs the fallback after every place's own houses (towns, the 1948 localities) and the camps, so it takes
+ only ground no other place uses. `KitTests.TheSmallTownFloorMovesNoOtherPlace` checks this: every lot of every
+ place is the same, in the same order, with the fallback off and on.
+ - It fires in 15 towns (the moshavot and kibbutzim, Tiberias, Netanya, Beersheba and Acre) and adds 27 houses in 13
+ of them.
+ Acre and Yad Mordechai have no free ground left.
+ - Every town now draws at least main's count: Tiberias 5, Netanya 4, Beersheba 5, Rosh Pinna 2, Nahalal 3. The 25
+ towns draw 397.
+ - **Tests:**
+ - `SmallTownsKeepTheirHousesAndNoBlockOutgrowsThePromo` pins every town at main's count (`MainBuildings`).
+ - `TownCensusTests.NoTwoHousesOfATownOverlap` checks the footprints by separating axes. It fails (20 pairs) when the
+ fallback skips its own lattice's lots.
+ - The grid stays readable at 80% (71 of 89).
+ - **Perf, after the review's fixes** (WebGL, main `4abb64f` against the branch, `machine_lock.py --exclusive
+ --wait-unity`, two interleaved rounds, load 5-9, 2026-10-13):
+ - Frame time is equal. At gameplay03 `all` is 8.08 / 7.73 ms on main against 8.14 / 8.02 ms on the branch, and at
+ diorama02 19.43 / 19.50 against 18.90 / 19.42 ms. The p95s are equal, and there are 63 draws on both.
+ - Boot at cpu 4: the "kits built" phase is about 45 ms heavier, 691 / 709 ms on main against 743 / 750 ms.
+ - An attribution round (main, the branch, the branch with the fallback off, and the branch with the old whole-hex
+ lake rule) put about 10 ms of that on the fallback: 689 / 738 / 729 ms in the quieter round. The lake rule costs
+ nothing measurable. The rest is round 2's own placement against this main.
+ - The author's boot against `2b7212e` measured the kit phase within noise. The ~35 ms not explained here is not
+ attributed further.
+ - Perf, one interleaved round with the floor (`95710e7` against main `471c300`, exclusive lock, the machine loaded by
+ other sessions to load 15, so every number is high):
+ - Frame time at gameplay03 is 25.62 ms (main) against 25.24 ms (branch), and at diorama02 27.78 against 27.67 ms.
+ - Boot map_build median is 2982 against 3075 ms. The "kits built" phase is 746 against 686 ms.
+ - The editor's kit build_ms is 85-89 ms, with or without the floor.
+ - The floor adds no measurable cost; the boot difference is load. Still 63 draws.
+ - The label refresh is unchanged: `MapLabelTests.RefreshWhileTheCameraMovesIsCheapAndAllocationFree` measured 162-163 µs
+ with the floor and 171-180 µs without it, interleaved. The single 238 µs (fail) came in a full run at load 24.
+- **Still open, filed as issues:**
+ - #318: Tel Aviv's cover is held down by the localities' landmark lots.
+ - #319: the symbolic Old City has roads crossing inside its walls.
+- **Unchanged after the fixes:** the grid stays readable at 78% (69 of 89), and the beach beside Tel Aviv reads as sand at
+ 79% (26 of 33).
+- **Perf, re-measured by the review:** frame time is headless WebGL `?vprofile`; boot is `headed.py boot --runs 3 --cpu
+ 4`. Main `471c300` against the branch at `4a68d05`, each round under `machine_lock.py --exclusive --wait-unity`, in
+ interleaved order. A third round was cut short by a stop.
+
+ | | gameplay03 all (p95) | gameplay03 none | diorama02 all (p95) | diorama02 none | boot cpu 4: map_build / first_frame |
+ |---|---|---|---|---|---|
+ | main, round 1 (load 3.1) | 14.21 ms (16) | 10.72 ms | 19.47 ms (23) | 13.20 ms | 2584 / 8431 ms |
+ | branch, round 1 (load 7.5) | 15.40 ms (17) | 11.32 ms | 18.18 ms (21) | 13.06 ms | 2598 / 8369 ms |
+ | branch, round 2 (load 13.6) | 14.36 ms (16) | 11.01 ms | 17.80 ms (20) | 13.00 ms | 2619 / 8367 ms |
+ | main, round 2 (load 4.2) | 14.23 ms (16) | 11.03 ms | 17.81 ms (20) | 13.02 ms | 2595 / 8390 ms |
+
+ - Round 2 is equal within noise. In round 1, the branch's gameplay03 cost rises with its `none` row (+0.6 ms both),
+ that is, with the machine's load.
+ - Boot's map_build is 14-24 ms over main, within the runs' spread, under the 2720 ms budget at cpu 4.
+
+### Sources (checked 2026-10-12)
+- Tel Aviv:
+ - White City (1930s International Style, flat roofs; Geddes plan 1925-29): https://en.wikipedia.org/wiki/White_City,_Tel_Aviv
+ - Port of Tel Aviv (opened 1936, completed 1938, closed 1965; 32.0965 N, 34.7733 E): https://en.wikipedia.org/wiki/Port_of_Tel_Aviv
+- Jaffa:
+ - Clock Tower (1900-03, limestone, at the north end of Yefet Street): https://en.wikipedia.org/wiki/Jaffa_Clock_Tower
+ - Mahmoudiya Mosque (mostly 1812, the old town's north-east corner, its east gate on the clock-tower plaza; 32.0549 N,
+ 34.7555 E): https://en.wikipedia.org/wiki/Mahmoudiya_Mosque
+ - St Peter's Church (1888-94, on a hill near the shore, bell tower; 32.0548 N, 34.7521 E): https://en.wikipedia.org/wiki/St._Peter%27s_Church,_Jaffa
+ - Jaffa Light (1865, 10 m, red and white bands, on the hilltop above the old port; 32.0535 N, 34.7505 E): https://en.wikipedia.org/wiki/Jaffa_Light
+- Haifa:
+ - Port of Haifa (opened 31 October 1933; 32.8201 N, 35.0045 E): https://en.wikipedia.org/wiki/Port_of_Haifa
+ - German Colony (Templer colony of 1868; main street north-south down to the harbour; 32.8200 N, 34.9906 E): https://en.wikipedia.org/wiki/German_Colony,_Haifa
+ - Templer houses (stone, red roofs): https://en.wikipedia.org/wiki/Templers_(religious_believers)
+ - Shrine of the Báb (superstructure and dome completed 1953): https://en.wikipedia.org/wiki/Shrine_of_the_B%C3%A1b
+- Jerusalem:
+ - Walls (1537-41, 4,018 m, about 12 m high): https://en.wikipedia.org/wiki/Walls_of_Jerusalem
+ - Old City (0.9 km^2; 31.7767 N, 35.2342 E; the gates' sides): https://en.wikipedia.org/wiki/Old_City_of_Jerusalem
+ - Damascus Gate (the wall's north-west side): https://en.wikipedia.org/wiki/Damascus_Gate
+ - Tower of David (near Jaffa Gate; 31.7761 N, 35.2278 E): https://en.wikipedia.org/wiki/Tower_of_David
+ - Temple Mount (the Old City's eastern section, platform about 488 x 315 m; Al-Aqsa at its south end): https://en.wikipedia.org/wiki/Temple_Mount
+ - Dome of the Rock (blackened lead before 1959; Ottoman blue and white tiles): https://en.wikipedia.org/wiki/Dome_of_the_Rock
+ - Al-Aqsa Mosque (lead dome before 1969): https://en.wikipedia.org/wiki/Al-Aqsa_Mosque
+ - Jerusalem stone (Storrs' ordinance, 1918): https://en.wikipedia.org/wiki/Jerusalem_stone
+- Ramla:
+ - White Tower (square, five storeys, 27 m; rebuilt after the 1318 earthquake; 31.9275 N, 34.8661 E): https://en.wikipedia.org/wiki/White_Tower_(Ramla)
## Issue #195: the water and the border lookups out of the terrain's fragment shader
- **Why.** promo-sea (#138) put the water shading (`ScWaterShade`, the breakers' `fwidth`, the footprint) in the terrain
diff --git a/unity/Assets/Scripts/Map/Kits/KitGround.cs b/unity/Assets/Scripts/Map/Kits/KitGround.cs
index 3a3763061..821dfa86f 100644
--- a/unity/Assets/Scripts/Map/Kits/KitGround.cs
+++ b/unity/Assets/Scripts/Map/Kits/KitGround.cs
@@ -28,8 +28,18 @@ namespace Statecraft.Game.Map.Kits
seaLevelY = terrainY + (0f - elevMinM) * exaggeration;
bounds = hexes.bounds; hexSizeKm = hexes.hex_size_km; HexSizeM = hexes.hex_size_km * 1000f;
foreach (var h in hexes.hexes) biome[(h.q, h.r)] = h.biome;
+ // The lakes' hexes and their neighbours: where a lake's water can lie (a lake hex is at least 40% water, so the
+ // lake's edge stays within its hexes' neighbours; KitTests.NothingStandsInALakesDrawnWater checks the whole rift).
+ foreach (var h in hexes.hexes)
+ if (h.biome == "lake")
+ foreach (var (dq, dr) in new[] { (0, 0), (1, 0), (-1, 0), (0, 1), (0, -1), (1, -1), (-1, 1) })
+ lakeZone.Add((h.q + dq, h.r + dr));
+ int res = Mathf.Max(2, terrain.terrainData.heightmapResolution);
+ sampleX = frame.WidthM / (res - 1); sampleZ = frame.LengthM / (res - 1);
}
+ readonly float sampleX, sampleZ; // the heightmap's sample spacing (m): the lake test's 3 x 3 window
+
/// <summary>The terrain's world position (the hex grid's origin: HexGrid.ToWorld).</summary>
public Vector3 TerrainOrigin => terrain.transform.position;
public float Width => Frame.WidthM;
@@ -43,21 +53,63 @@ namespace Statecraft.Game.Map.Kits
/// <summary>Real metres above sea level at (x, z) (the heightmap's own elevation, before exaggeration).</summary>
public float ElevM(float x, float z) => (Y(x, z) - seaLevelY) / exaggeration;
- public string Biome(float x, float z)
+ public string Biome(float x, float z) => biome.TryGetValue(Hex(x, z), out var b) ? b : "sea";
+
+ (int, int) Hex(float x, float z)
{
var (lon, lat) = Frame.ToLonLat(new Vector3(x, 0f, z));
- return biome.TryGetValue(HexPicker.FromLonLat(lon, lat, bounds, hexSizeKm), out var b) ? b : "sea";
+ return HexPicker.FromLonLat(lon, lat, bounds, hexSizeKm);
}
- /// <summary>Open sea (the heightmap writes it as exactly 0 m: MapBuilder.SeaToleranceM), a lake hex, or off the map.</summary>
+ readonly HashSet<(int, int)> lakeZone = new HashSet<(int, int)>();
+
+ /// <summary>Open sea (the heightmap writes it as exactly 0 m: MapBuilder.SeaToleranceM), a lake's water, or off the
+ /// map. A lake is its water surface, not its hexes (#317): a lake hex also holds its shore (Tiberias stands in one,
+ /// 60-160 m above the Sea of Galilee), and counting all of it as water left Tiberias no ground to build on, while a
+ /// shore hex of another biome can hold some of the lake. The surface is told as the drawn water tells it
+ /// (MapBuilder.WaterMeshGrid, tools/terrain_bake.py): below <see cref="MapBuilder.LakeBelowM"/> and flat within
+ /// <see cref="MapBuilder.LakeFlatM"/> over the heightmap's 3 x 3 window, at the point or one sample from it.</summary>
public bool Water(float x, float z)
{
if (!Inside(x, z)) return true;
- if (Mathf.Abs(ElevM(x, z)) <= MapBuilder.SeaToleranceM + 0.5f) return true;
- var b = Biome(x, z);
- return b == "lake" || (b == "sea" && ElevM(x, z) < 2f);
+ float e = ElevM(x, z);
+ if (Mathf.Abs(e) <= MapBuilder.SeaToleranceM + 0.5f) return true;
+ // Only the rift lies this low (no sea hex does), and only a lake's hex or its neighbour holds lake water.
+ if (e < MapBuilder.LakeBelowM) return lakeZone.Contains(Hex(x, z)) && NearLakeSurface(x, z);
+ return e < 2f && Biome(x, z) == "sea";
+ }
+
+ /// <summary>The lake's flat surface lies at (x, z) or within one heightmap sample of it. The drawn shore (coast.png's
+ /// distance, interpolated between texel centres) runs up to about a sample past the last flat sample, so a tree or
+ /// house one sample short of the flat water would still stand in the drawn lake (a shore palm by Ghuweir Abu Shusha
+ /// did).</summary>
+ bool NearLakeSurface(float x, float z)
+ {
+ int gx = Mathf.RoundToInt(x / sampleX), gz = Mathf.RoundToInt(z / sampleZ);
+ for (int j = -1; j <= 1; j++)
+ for (int i = -1; i <= 1; i++)
+ if (LakeFlat(gx + i, gz + j)) return true;
+ return false;
}
+ /// <summary>Whether heightmap sample (gx, gz) is a lake's flat surface: below LakeBelowM, its 3 x 3 window within
+ /// LakeFlatM. Cached per sample (the rift's floor is asked about thousands of times while the kits are built).</summary>
+ bool LakeFlat(int gx, int gz)
+ {
+ long key = ((long)gx << 32) | (uint)gz;
+ if (lakeFlat.TryGetValue(key, out var flat)) return flat;
+ float lo = float.MaxValue, hi = float.MinValue;
+ for (int j = -1; j <= 1; j++)
+ for (int i = -1; i <= 1; i++)
+ {
+ float e = ElevM((gx + i) * sampleX, (gz + j) * sampleZ);
+ lo = Mathf.Min(lo, e); hi = Mathf.Max(hi, e);
+ }
+ return lakeFlat[key] = hi < MapBuilder.LakeBelowM && hi - lo <= MapBuilder.LakeFlatM;
+ }
+
+ readonly Dictionary<long, bool> lakeFlat = new Dictionary<long, bool>();
+
/// <summary>The steepest rise (real metres per real metre) between the four points of a w-wide square around (x, z).</summary>
public float Slope(float x, float z, float w)
{
diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs b/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs
new file mode 100644
index 000000000..82454e936
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs
@@ -0,0 +1,483 @@
+#nullable enable
+using UnityEngine;
+
+namespace Statecraft.Game.Map.Kits
+{
+ /// <summary>The settlements' landmarks, placed before any town's houses (docs/visual-v1.md, "Towns round 2", lists each
+ /// with its source). Positions keep the real bearing from the settlement's point to the landmark's sourced coordinate;
+ /// distances and sizes are symbolic, like the buildings.</summary>
+ public static partial class SettlementKits
+ {
+ /// <summary>A settlement's landmarks: the four cities' own (Jaffa, Jerusalem, Haifa, Tel Aviv) and Ramla's White
+ /// Tower, else its archetype's (an old town's or an Arab town's mosque, a moshava's water tower). Returns how many.</summary>
+ static int TownLandmarks(Settlement s, Vector2 centre, KitGround ground, KitMesh km, Lots lots, ref KitRandom rnd)
+ {
+ var arch = ArchetypeOf(s);
+ float R = FootprintRadiusM(s, ground.HexSizeM);
+ var heart = DryNear(centre, ground, R * 0.3f, ref rnd);
+ switch (s.Id)
+ {
+ case "jaffa": return Jaffa(s, heart, ground, km, lots, ref rnd);
+ case "jerusalem": return Jerusalem(s, ground, km, lots, ref rnd);
+ case "haifa": return Haifa(s, ground, km, lots, ref rnd);
+ case "tel_aviv": return TelAvivPort(s, ground, km, lots, ref rnd);
+ case "ramla":
+ return Mosque(s.Id, heart, ground, km, lots, ref rnd, 1f)
+ + WhiteTower(s.Id, heart + Bearing(ground, s, 34.86611, 31.92750) * 18f * KitScale.Landmarks, ground, km, lots);
+ }
+ switch (arch)
+ {
+ case Archetype.OldTown: return Mosque(s.Id, heart, ground, km, lots, ref rnd, 1.2f);
+ case Archetype.ArabTown: return Mosque(s.Id, heart, ground, km, lots, ref rnd, 1f);
+ case Archetype.Moshava: return WaterTower(s.Id, heart + new Vector2(R * 0.35f, -R * 0.2f), ground, km, lots);
+ default: return 0;
+ }
+ }
+
+ static Vector2 World(KitGround g, double lon, double lat) { var w = g.Frame.ToWorld(lon, lat, 0); return new Vector2(w.x, w.z); }
+
+ /// <summary>The unit vector from settlement <paramref name="s"/>'s point towards a sourced coordinate.</summary>
+ static Vector2 Bearing(KitGround g, Settlement s, double lon, double lat) => (World(g, lon, lat) - World(g, s.Lon, s.Lat)).normalized;
+
+ /// <summary>The step (m) of the shore and rectangle scans.</summary>
+ const float ScanStepM = 125f;
+
+ /// <summary>The first open-water point from <paramref name="from"/> along <paramref name="dir"/> (ScanStepM steps, up to
+ /// <paramref name="maxM"/>), or null.</summary>
+ static Vector2? ToSea(Vector2 from, Vector2 dir, KitGround ground, float maxM)
+ {
+ for (float d = 0f; d <= maxM; d += ScanStepM)
+ {
+ var p = from + dir * d;
+ if (ground.Water(p.x, p.y)) return p;
+ }
+ return null;
+ }
+
+ /// <summary>The first dry point from <paramref name="from"/> along <paramref name="dir"/>, or null.</summary>
+ static Vector2? ToLand(Vector2 from, Vector2 dir, KitGround ground, float maxM)
+ {
+ for (float d = 0f; d <= maxM; d += ScanStepM)
+ {
+ var p = from + dir * d;
+ if (ground.Inside(p.x, p.y) && !ground.Water(p.x, p.y)) return p;
+ }
+ return null;
+ }
+
+ // ---- Jaffa ----------------------------------------------------------------------------------------------------
+
+ /// <summary>Jaffa: the Mahmoudiya Mosque (1812) at the old town's north-east corner, the clock tower (1900-03) on the
+ /// plaza east of it, St Peter's Church (1888-94) on the hill near the shore, the lighthouse (1865, red and white bands)
+ /// on the hilltop above the old port, and the port's breakwater with its boats.</summary>
+ static int Jaffa(Settlement s, Vector2 heart, KitGround ground, KitMesh km, Lots lots, ref KitRandom rnd)
+ {
+ float m = KitScale.Landmarks;
+ int n = 0;
+ var mosqueWant = heart + Bearing(ground, s, 34.75548, 32.054917) * 22f * m;
+ n += Mosque(s.Id, mosqueWant, ground, km, lots, ref rnd, 1.2f);
+ var stone = C(0.86f, 0.76f, 0.57f);
+ // The clock tower stands on the plaza the mosque's east gate faces.
+ if (Claim(lots, mosqueWant + new Vector2(20f * m, 2f * m), 4.5f * m, s.Id, ground, out var p))
+ {
+ float y = ground.Y(p.x, p.y);
+ km.Box(p.x, p.y, 15f, 5f * m, 5f * m, y - 2f * m, y, 24f * m, stone, stone, Facade.Stone, m, roofed: true);
+ km.Box(p.x, p.y, 15f, 4f * m, 4f * m, y + 24f * m, y + 24f * m, 4f * m, C(0.90f, 0.82f, 0.64f), stone, Facade.Plain, m, roofed: true);
+ km.Pyramid(p.x, p.y, 15f, 4.4f * m, 4.4f * m, y + 28f * m, 3.5f * m, C(0.55f, 0.47f, 0.40f));
+ Record(s.Id, "clock_tower", p, 15f, 5f * m, 5f * m, 31.5f * m, stone);
+ n++;
+ }
+ if (Church(s.Id, heart + Bearing(ground, s, 34.752083, 32.054778) * 26f * m, ground, km, lots, 1f)) n++;
+ // The lighthouse on the hilltop above the old port: the last dry ground towards it, a little inland.
+ var dir = Bearing(ground, s, 34.7505056, 32.0534583);
+ var shore = ToSea(heart, dir, ground, 12000f);
+ if (shore is Vector2 sea)
+ {
+ var want = sea - dir * 5f * m;
+ if (Claim(lots, want, 2.6f * m, s.Id, ground, out var q))
+ {
+ float y = ground.Y(q.x, q.y);
+ var white = C(0.93f, 0.92f, 0.88f); var red = C(0.70f, 0.22f, 0.17f);
+ const int bands = 4; float bandH = 12f * m / bands;
+ for (int b = 0; b < bands; b++)
+ km.Shaft(new Vector3(q.x, y - (b == 0 ? 2f * m : 0f) + b * bandH, q.y), new Vector3(q.x, y + (b + 1) * bandH, q.y),
+ Mathf.Lerp(1.9f, 1.4f, b / (float)bands) * m, Mathf.Lerp(1.9f, 1.4f, (b + 1) / (float)bands) * m, b % 2 == 0 ? white : red, 10);
+ km.Shaft(new Vector3(q.x, y + 12f * m, q.y), new Vector3(q.x, y + 14.5f * m, q.y), 1.5f * m, 1.5f * m, C(0.30f, 0.32f, 0.30f), 10);
+ km.Cone(new Vector3(q.x, y + 14.5f * m, q.y), 1.8f * m, 2.2f * m, red, 10);
+ Record(s.Id, "lighthouse", q, 0f, 3.8f * m, 3.8f * m, 16.7f * m, white);
+ n++;
+ }
+ n += Port(sea, ground, km, ref rnd);
+ }
+ return n;
+ }
+
+ /// <summary>Jaffa's harbour, as promo 03 draws it: a stone breakwater curving out to sea from the shore below the
+ /// lighthouse, and a few sailing boats inside it.</summary>
+ static int Port(Vector2 shore, KitGround ground, KitMesh km, ref KitRandom rnd)
+ {
+ float m = KitScale.Landmarks;
+ float sea = ground.Y(shore.x, shore.y);
+ var stone = C(0.74f, 0.70f, 0.62f);
+ // A quarter-circle arm: out to the west, then north.
+ var c = shore + new Vector2(0f, 60f * m);
+ float r = 60f * m;
+ Vector2 prev = c + new Vector2(0f, -r);
+ for (int k = 1; k <= 9; k++)
+ {
+ float a = -Mathf.PI * 0.5f - k * (Mathf.PI * 0.5f / 9f);
+ var cur = c + new Vector2(Mathf.Cos(a), Mathf.Sin(a)) * r;
+ var mid = (prev + cur) * 0.5f; var dir = cur - prev;
+ float yaw = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
+ km.Box(mid.x, mid.y, yaw, dir.magnitude * 1.08f, 5f * m, sea - 2f * m, sea, 2.2f * m, stone, stone, Facade.Plain, m);
+ prev = cur;
+ }
+ Record("jaffa", "port", c, 0f, r, r, 2.2f * m, stone);
+ // Sailing boats in and off the harbour.
+ int boats = 0;
+ for (int i = 0; i < 12 && boats < 5; i++)
+ {
+ var b = c + new Vector2(rnd.Range(-1.6f, 0.2f) * r, rnd.Range(-1.4f, 0.4f) * r);
+ if (!ground.Water(b.x, b.y) || ground.Water(b.x + 40f * m, b.y) == false) continue;
+ float yaw = rnd.Range(0f, 360f), L = rnd.Range(9f, 14f) * m;
+ km.Box(b.x, b.y, yaw, L, L * 0.32f, sea - 1f * m, sea, 1.6f * m, C(0.42f, 0.30f, 0.20f), C(0.55f, 0.42f, 0.30f), Facade.Plain, m);
+ float a = yaw * Mathf.Deg2Rad; var fwd = new Vector3(Mathf.Cos(a), 0f, Mathf.Sin(a));
+ var mast = new Vector3(b.x, sea + 1.6f * m, b.y);
+ km.Shaft(mast, mast + Vector3.up * L * 0.9f, 0.18f * m, 0.12f * m, C(0.35f, 0.28f, 0.20f), 4);
+ var sail = C(0.95f, 0.93f, 0.86f);
+ var s0 = mast + Vector3.up * L * 0.85f; var s1 = mast + Vector3.up * 0.4f * m; var s2 = mast + fwd * (-L * 0.45f) + Vector3.up * 0.4f * m;
+ km.Triangle(s0, s1, s2, sail); km.Triangle(s0, s2, s1, sail);
+ boats++;
+ }
+ return 1;
+ }
+
+ // ---- Jerusalem ------------------------------------------------------------------------------------------------
+
+ /// <summary>The Old City's centre (its sourced coordinate) and the half side (m) of its symbolic walled square: 4 km
+ /// across, about 4 times the real Old City (0.9 km^2), so the walls hold the Haram and a quarter of stone houses at
+ /// the kits' scale. In metres, not scaled with the kits: the drawn 1948 roads fix where the Haram can stand
+ /// (docs/visual-v1.md, "Towns round 2"). Those roads ran round the real walls; at this size they cross inside the
+ /// square, through gaps in the walls.</summary>
+ static (Vector2 centre, float half) OldCity(KitGround g) => (World(g, 35.23417, 31.77667), 2000f);
+
+ /// <summary>How far inside the walls the Old City's houses keep (and outside them the new city's).</summary>
+ const float OldCityInset = 220f;
+
+ /// <summary>Jerusalem: Suleiman's walls (1537-41) round a symbolic square Old City with five gates (Jaffa Gate on the
+ /// west, Damascus Gate on the north wall's west side, Lions' Gate on the east, Zion and Dung Gates on the south) and a
+ /// gap wherever a 1948 road or the railway crosses the line, the citadel near Jaffa Gate, and the Haram al-Sharif in
+ /// the city's east: its platform, the Dome of the Rock (blue and white Ottoman tiles; its dome blackened lead until
+ /// the 1959-64 restoration) and the Al-Aqsa Mosque at the platform's south end (its dome lead). The rest of the
+ /// footprint is houses (PlaceHouses: the new city's stone blocks to the west, the Arab quarters round the other sides).</summary>
+ static int Jerusalem(Settlement s, KitGround ground, KitMesh km, Lots lots, ref KitRandom rnd)
+ {
+ var (oc, half) = OldCity(ground);
+ // Above the Old City's houses (one or two storeys inside the walls: PlaceHouses), so the circuit reads.
+ float wallT = 380f, wallH = 900f;
+ var stone = C(0.82f, 0.72f, 0.55f); var top = C(0.86f, 0.78f, 0.62f);
+ int n = 0;
+ // The Haram al-Sharif in the city's south-east (in the real city it fills the east side down to the south wall):
+ // its platform, the Dome of the Rock and Al-Aqsa, where the platform keeps clear of the drawn Jericho road. The
+ // roads leave no room for the real platform's north-south length, so it is wider than long and Al-Aqsa stands in
+ // its south-east corner rather than across its south end (docs/visual-v1.md, "Towns round 2").
+ float pw = 1300f, pl = 1100f;
+ var pc = oc + new Vector2(350f, -1200f);
+ var paving = C(0.86f, 0.82f, 0.72f);
+ if (RectClear(pc, pw, pl, ground) && lots.Free(pc, 0.5f * Mathf.Sqrt(pw * pw + pl * pl))) // first in the Old City
+ {
+ var (pb, pg) = GroundSpan(pc, 0f, pw, pl, ground, 1f);
+ km.Box(pc.x, pc.y, 0f, pw, pl, pb, pg, 80f, C(0.80f, 0.72f, 0.58f), paving, Facade.Plain, 10f);
+ // Its lots: discs over the platform, each clear of the routes (RectClear checked the whole platform).
+ for (float u = -pw * 0.5f + 150f; u < pw * 0.5f; u += 260f)
+ for (float v = -pl * 0.5f + 150f; v < pl * 0.5f; v += 260f)
+ {
+ var c = pc + new Vector2(u, v);
+ if (!ground.OnRoute(c, 190f)) lots.Add(new Lot { c = c, r = 190f, id = s.Id });
+ }
+ Record(s.Id, "haram", pc, 0f, pw, pl, 80f, paving);
+ n++;
+ float deck = pg + 80f;
+ // The Dome of the Rock in the platform's west (18x across: the 52 m octagon about 0.95 km; its walls and drum 30x
+ // high, so it rises over the Old City's roofs): marble below, blue and white tiles above, a tiled drum and the
+ // lead dome (dark: before the 1959-64 restoration).
+ float k = 18f, kv = 30f;
+ float rOct = 27f * k;
+ var dc = pc + new Vector2(-0.5f * pw + rOct + 30f, 0f);
+ var marble = C(0.88f, 0.86f, 0.80f); var tiles = C(0.36f, 0.50f, 0.64f); var lead = C(0.26f, 0.27f, 0.29f);
+ km.Shaft(new Vector3(dc.x, deck - 60f, dc.y), new Vector3(dc.x, deck + 5f * kv, dc.y), rOct, rOct, marble, 8);
+ km.Shaft(new Vector3(dc.x, deck + 5f * kv, dc.y), new Vector3(dc.x, deck + 11f * kv, dc.y), rOct, rOct, tiles, 8);
+ km.Cone(new Vector3(dc.x, deck + 11f * kv, dc.y), rOct, 2.5f * k, C(0.62f, 0.62f, 0.60f), 8);
+ km.Shaft(new Vector3(dc.x, deck + 11f * kv, dc.y), new Vector3(dc.x, deck + 19f * kv, dc.y), 11f * k, 11f * k, tiles, 16);
+ km.Dome(dc.x, dc.y, deck + 19f * kv, 11f * k, lead, 16, 6);
+ Record(s.Id, "dome_of_the_rock", dc, 0f, 2f * rOct, 2f * rOct, 19f * kv + 11f * k, tiles);
+ n++;
+ // Al-Aqsa in the platform's south-east corner: a hall running north-south (16x) and its lead dome.
+ float aw = 230f, al = 480f;
+ var ac = pc + new Vector2(0.5f * pw - 0.5f * aw - 40f, -0.5f * pl + 0.5f * al + 40f);
+ km.Box(ac.x, ac.y, 0f, aw, al, deck - 60f, deck, 300f, C(0.84f, 0.77f, 0.62f), C(0.70f, 0.70f, 0.68f), Facade.Stone, 16f);
+ km.Dome(ac.x, ac.y + 0.3f * al, deck + 280f, 0.45f * aw, C(0.55f, 0.56f, 0.57f), 12, 5);
+ Record(s.Id, "al_aqsa", ac, 0f, aw, al, 300f, C(0.84f, 0.77f, 0.62f));
+ n++;
+ }
+
+ // Gates: (side, position along it as a share of the half side). Sides: 0 north, 1 east, 2 south, 3 west.
+ var gates = new (int side, float at)[] { (3, 0.05f), (0, -0.15f), (1, 0.6f), (2, -0.45f), (2, -0.05f) };
+ const int pieces = 12;
+ float len = 2f * half / pieces, pieceR = 0.5f * Mathf.Sqrt(len * len + wallT * wallT); // a piece's half-diagonal
+ int built = 0;
+ for (int side = 0; side < 4; side++)
+ {
+ // Along each side from one corner to the next, clockwise from the north-west corner.
+ Vector2 a0 = side switch { 0 => new Vector2(-half, half), 1 => new Vector2(half, half), 2 => new Vector2(half, -half), _ => new Vector2(-half, -half) };
+ Vector2 dir = side switch { 0 => Vector2.right, 1 => Vector2.down, 2 => Vector2.left, _ => Vector2.up };
+ float yaw = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
+ var gap = new bool[pieces];
+ for (int i = 0; i < pieces; i++) gap[i] = ground.OnRoute(oc + a0 + dir * (len * (i + 0.5f)), pieceR); // a road's or the railway's gap
+ for (int i = 0; i < pieces; i++)
+ {
+ var mid = oc + a0 + dir * (len * (i + 0.5f));
+ if (gap[i]) continue;
+ var (bottom, gy) = GroundSpan(mid, yaw, len, wallT, ground, 1f);
+ km.Box(mid.x, mid.y, yaw, len * 1.01f, wallT, bottom, gy, wallH, stone, top, Facade.Plain, KitScale.Houses);
+ km.Box(mid.x, mid.y, yaw, len * 1.01f, wallT * 0.35f, gy + wallH, gy + wallH, 90f, top, top, Facade.Plain, KitScale.Houses); // the parapet
+ lots.Add(new Lot { c = mid, r = pieceR, id = s.Id });
+ built++;
+ // A gate tower where a road passes the wall line (a road entered by a gate), else a square tower at every
+ // other joint.
+ for (int end = 0; end < 2; end++)
+ {
+ int next = end == 0 ? i - 1 : i + 1;
+ bool byRoad = next >= 0 && next < pieces && gap[next];
+ if (!byRoad && !(end == 1 && i % 2 == 1 && i + 1 < pieces)) continue;
+ float tw = byRoad ? 600f : 480f, th = wallH + (byRoad ? 400f : 260f);
+ var t = oc + a0 + dir * (len * (i + end) + (byRoad ? (end == 0 ? 1f : -1f) * 0.5f * tw : 0f));
+ if (ground.OnRoute(t, 0.5f * tw + 10f)) continue; // the tower itself stays off the road
+ var (tb, ty) = GroundSpan(t, yaw, tw, tw, ground, 1f);
+ km.Box(t.x, t.y, yaw, tw, tw, tb, ty, th, stone, top, byRoad ? Facade.Stone : Facade.Plain, KitScale.Houses);
+ if (byRoad) Record(s.Id, "gate", t, yaw, tw, tw, th, stone);
+ }
+ }
+ foreach (var (gs, at) in gates)
+ {
+ if (gs != side) continue;
+ var gp = oc + a0 + dir * (half + at * half);
+ if (ground.OnRoute(gp, 330f)) continue;
+ var (gb, gy) = GroundSpan(gp, yaw, 650f, 420f, ground, 1f);
+ km.Box(gp.x, gp.y, yaw, 650f, 420f, gb, gy, wallH + 400f, stone, top, Facade.Stone, KitScale.Houses);
+ Record(s.Id, "gate", gp, yaw, 650f, 420f, wallH + 400f, stone);
+ }
+ }
+ if (built > 0) { Record(s.Id, "walls", oc, 0f, 2f * half, 2f * half, wallH, stone); n++; }
+
+ // The citadel (the Tower of David) by Jaffa Gate, with its minaret (20x): at its sourced spot (about 0.6 km west of
+ // the Old City's centre), moved east off the drawn Hebron road.
+ float m = 20f;
+ if (Claim(lots, oc + new Vector2(-450f, -150f), 10f * m, s.Id, ground, out var cp))
+ {
+ float y = ground.Y(cp.x, cp.y);
+ km.Box(cp.x, cp.y, 0f, 18f * m, 16f * m, y - 2f * m, y, 12f * m, stone, top, Facade.Stone, m);
+ km.Box(cp.x - 5f * m, cp.y + 4f * m, 0f, 7f * m, 7f * m, y + 12f * m - 1f, y + 12f * m, 6f * m, stone, top, Facade.Stone, m);
+ km.Shaft(new Vector3(cp.x + 6f * m, y, cp.y - 5f * m), new Vector3(cp.x + 6f * m, y + 30f * m, cp.y - 5f * m), 1.7f * m, 1.4f * m, stone, 8);
+ km.Cone(new Vector3(cp.x + 6f * m, y + 30f * m, cp.y - 5f * m), 1.6f * m, 3.5f * m, C(0.62f, 0.62f, 0.58f), 8);
+ Record(s.Id, "citadel", cp, 0f, 18f * m, 16f * m, 33.5f * m, stone);
+ n++;
+ }
+ return n;
+ }
+
+ /// <summary>True when a north-aligned w x l rectangle at <paramref name="c"/> keeps 60 m off every route corridor
+ /// (sampled every ScanStepM, edges included).</summary>
+ static bool RectClear(Vector2 c, float w, float l, KitGround ground)
+ {
+ int nx = Mathf.CeilToInt(w / ScanStepM), nz = Mathf.CeilToInt(l / ScanStepM);
+ for (int i = 0; i <= nx; i++)
+ for (int j = 0; j <= nz; j++)
+ if (ground.OnRoute(c + new Vector2(-0.5f * w + w * i / nx, -0.5f * l + l * j / nz), 60f)) return false;
+ return true;
+ }
+
+ // ---- Haifa ----------------------------------------------------------------------------------------------------
+
+ /// <summary>Haifa: the deep-water port (opened 1933) on the bay north of the town, a long main breakwater and a lee
+ /// breakwater with warehouse sheds along the quays, and the German Colony (the Templers' colony of 1868) west of the
+ /// centre: stone houses with red roofs in two rows along its main street, which runs north-south down to the harbour.</summary>
+ static int Haifa(Settlement s, KitGround ground, KitMesh km, Lots lots, ref KitRandom rnd)
+ {
+ float m = KitScale.Landmarks;
+ int n = 0;
+ var stone = C(0.74f, 0.70f, 0.62f);
+ var portPt = World(ground, 35.00448, 32.820118);
+ var shore = ToSea(portPt, Vector2.up, ground, 8000f);
+ if (shore is Vector2 sh)
+ {
+ float sea = ground.Y(sh.x, sh.y);
+ int pieces = 0;
+ void Arm(Vector2 from, Vector2 to)
+ {
+ var d = to - from; int k = Mathf.Max(1, Mathf.CeilToInt(d.magnitude / (8f * m)));
+ float yaw = Mathf.Atan2(d.y, d.x) * Mathf.Rad2Deg;
+ for (int i = 0; i < k; i++)
+ {
+ var mid = from + d * ((i + 0.5f) / k);
+ if (!ground.Water(mid.x, mid.y)) continue;
+ km.Box(mid.x, mid.y, yaw, d.magnitude / k * 1.04f, 5f * m, sea - 2f * m, sea, 2.4f * m, stone, stone, Facade.Plain, m);
+ pieces++;
+ }
+ }
+ // The main breakwater out from the shore west of the port and along the bay; the lee breakwater from the east.
+ var w0 = sh + new Vector2(-40f * m, 0f); var w1 = w0 + new Vector2(0f, 24f * m); var w2 = w1 + new Vector2(96f * m, 0f);
+ Arm(w0, w1); Arm(w1, w2);
+ var e0 = sh + new Vector2(70f * m, 0f); var e1 = e0 + new Vector2(0f, 16f * m); var e2 = e1 + new Vector2(-20f * m, 0f);
+ Arm(e0, e1); Arm(e1, e2);
+ if (pieces > 0) { Record(s.Id, "port", sh + new Vector2(30f * m, 12f * m), 0f, 140f * m, 24f * m, 2.4f * m, stone); n++; }
+ // Warehouse sheds on the quays: on the first dry ground south of the shore line.
+ var shed = C(0.80f, 0.76f, 0.68f);
+ for (int i = 0; i < 4; i++)
+ {
+ var along = sh + new Vector2((-25f + i * 20f) * m, 0f);
+ if (!(ToLand(along + new Vector2(0f, 10f * m), Vector2.down, ground, 4000f) is Vector2 land)) continue;
+ if (!Claim(lots, land + new Vector2(0f, -6f * m), 8f * m, s.Id, ground, out var q)) continue;
+ var (b, y) = GroundSpan(q, 0f, 15f * m, 6f * m, ground, m);
+ km.Box(q.x, q.y, 0f, 15f * m, 6f * m, b, y, 3.5f * m, shed, C(0.62f, 0.58f, 0.54f), Facade.Plain, m, roofed: true);
+ km.Gable(q.x, q.y, 0f, 15f * m, 6f * m, y + 3.5f * m, 1.6f * m, C(0.58f, 0.55f, 0.52f), shed);
+ Record(s.Id, "warehouse", q, 0f, 15f * m, 6f * m, 5.1f * m, shed);
+ n++;
+ }
+ }
+ // The German Colony: its avenue from the shore southwards, a row of Templer houses on each side.
+ var colony = World(ground, 34.99056, 32.82000);
+ var top = ToSea(colony, Vector2.up, ground, 8000f) ?? colony;
+ float hm = KitScale.Houses;
+ int houses = 0;
+ for (int i = 0; i < 4; i++)
+ for (int side = -1; side <= 1; side += 2)
+ {
+ var want = top + new Vector2(side * 8f * hm, -(9f + i * 13f) * hm);
+ var spec = Pick(Style.Templer, 0.5f, ref rnd, hm);
+ if (!Claim(lots, want, spec.lotR, s.Id, ground, out var q)) continue;
+ var drnd = new KitRandom(rnd.Next());
+ Emit(s.Id, Style.Templer, q, 90f, spec, 0.5f, ground, km, ref drnd);
+ houses++;
+ }
+ if (houses > 0) { Record(s.Id, "german_colony", top + new Vector2(0f, -28f * hm), 90f, 52f * hm, 16f * hm, 0f, C(0.72f, 0.31f, 0.20f)); n += houses; }
+ return n;
+ }
+
+ // ---- Tel Aviv -------------------------------------------------------------------------------------------------
+
+ /// <summary>Tel Aviv's port in the city's north-west (opened 1936, inaugurated at its full size in 1938; closed 1965):
+ /// a mole out to sea and hangar sheds on the shore behind it, at its sourced coordinate.</summary>
+ static int TelAvivPort(Settlement s, KitGround ground, KitMesh km, Lots lots, ref KitRandom rnd)
+ {
+ float m = KitScale.Landmarks;
+ var at = World(ground, 34.7732528, 32.0964833);
+ // The shore: west from the port's point to the sea, or east from it to land when the point lies in the water.
+ Vector2? shoreSea = ground.Water(at.x, at.y) ? at : ToSea(at, Vector2.left, ground, 6000f);
+ if (!(shoreSea is Vector2 sea)) return 0;
+ var land = ToLand(sea, Vector2.right, ground, 6000f);
+ if (!(land is Vector2 l)) return 0;
+ int n = 0;
+ float y = ground.Y(sea.x, sea.y);
+ var stone = C(0.74f, 0.70f, 0.62f);
+ int pieces = 0;
+ var p0 = sea; var p1 = sea + new Vector2(-24f * m, 0f); var p2 = p1 + new Vector2(0f, 18f * m);
+ foreach (var (a, b) in new[] { (p0, p1), (p1, p2) })
+ {
+ var d = b - a; int k = Mathf.Max(1, Mathf.CeilToInt(d.magnitude / (8f * m))); float yaw = Mathf.Atan2(d.y, d.x) * Mathf.Rad2Deg;
+ for (int i = 0; i < k; i++)
+ {
+ var mid = a + d * ((i + 0.5f) / k);
+ if (!ground.Water(mid.x, mid.y)) continue;
+ km.Box(mid.x, mid.y, yaw, d.magnitude / k * 1.04f, 4.5f * m, y - 2f * m, y, 2.2f * m, stone, stone, Facade.Plain, m);
+ pieces++;
+ }
+ }
+ if (pieces > 0) { Record(s.Id, "port", sea + new Vector2(-12f * m, 6f * m), 0f, 24f * m, 18f * m, 2.2f * m, stone); n++; }
+ var shed = C(0.82f, 0.79f, 0.72f);
+ for (int i = 0; i < 3; i++)
+ {
+ // Behind the beach strip (BeachSetbackM), so the sand stays open in front of them.
+ if (!Claim(lots, l + new Vector2(BeachSetbackM + 4f * m, (i - 1) * 17f * m), 8.5f * m, s.Id, ground, out var q)) continue;
+ var (bt, gy) = GroundSpan(q, 90f, 15f * m, 6f * m, ground, m);
+ km.Box(q.x, q.y, 90f, 15f * m, 6f * m, bt, gy, 3.2f * m, shed, C(0.62f, 0.58f, 0.54f), Facade.Plain, m, roofed: true);
+ km.Gable(q.x, q.y, 90f, 15f * m, 6f * m, gy + 3.2f * m, 1.8f * m, C(0.60f, 0.58f, 0.55f), shed);
+ Record(s.Id, "warehouse", q, 90f, 15f * m, 6f * m, 5f * m, shed);
+ n++;
+ }
+ return n;
+ }
+
+ // ---- Shared landmarks -----------------------------------------------------------------------------------------
+
+ /// <summary>Ramla's White Tower: the five-storey square minaret of the White Mosque (rebuilt after the 1318
+ /// earthquake; 27 m), east of the town's heart, at its sourced bearing.</summary>
+ static int WhiteTower(string owner, Vector2 want, KitGround ground, KitMesh km, Lots lots)
+ {
+ float m = KitScale.Landmarks;
+ if (!Claim(lots, want, 5f * m, owner, ground, out var p)) return 0;
+ float y = ground.Y(p.x, p.y), storey = 27f / 5f * m;
+ var stone = C(0.90f, 0.86f, 0.76f);
+ for (int i = 0; i < 5; i++)
+ {
+ float w = Mathf.Lerp(7f, 5.6f, i / 4f) * m;
+ km.Box(p.x, p.y, 0f, w, w, i == 0 ? y - 2f * m : y + i * storey - 1f, y + i * storey, storey, stone, stone, Facade.Stone, m);
+ }
+ km.Box(p.x, p.y, 0f, 3.2f * m, 3.2f * m, y + 27f * m - 1f, y + 27f * m, 2.6f * m, stone, stone, Facade.Plain, m, roofed: true);
+ km.Dome(p.x, p.y, y + 29.6f * m, 1.6f * m, C(0.80f, 0.78f, 0.72f));
+ Record(owner, "white_tower", p, 0f, 7f * m, 7f * m, 31f * m, stone);
+ return 1;
+ }
+
+ static int Mosque(string owner, Vector2 want, KitGround ground, KitMesh km, Lots lots, ref KitRandom rnd, float size)
+ {
+ float m = KitScale.Landmarks * size;
+ if (!Claim(lots, want, 11f * m, owner, ground, out var p)) return 0; // the lot covers the minaret too
+ float y = ground.Y(p.x, p.y);
+ var stone = Jitter(C(0.87f, 0.80f, 0.66f), ref rnd, 0.03f);
+ km.Box(p.x, p.y, 0f, 14f * m, 14f * m, y - 2f * m, y, 7f * m, stone, stone, Facade.Stone, KitScale.Landmarks);
+ km.Dome(p.x, p.y, y + 7f * m - 0.5f * m, 5.5f * m, C(0.80f, 0.80f, 0.76f));
+ float mx = p.x + 8.5f * m, mz = p.y - 6f * m;
+ float my = ground.Y(mx, mz);
+ km.Shaft(new Vector3(mx, my - 2f * m, mz), new Vector3(mx, my + 26f * m, mz), 1.6f * m, 1.35f * m, stone, 8);
+ km.Shaft(new Vector3(mx, my + 20f * m, mz), new Vector3(mx, my + 21f * m, mz), 2.1f * m, 2.1f * m, stone, 8); // the balcony
+ km.Cone(new Vector3(mx, my + 26f * m, mz), 1.5f * m, 4.5f * m, C(0.62f, 0.62f, 0.58f), 8);
+ Record(owner, "mosque", p, 0f, 14f * m, 14f * m, 30.5f * m, stone);
+ return 1;
+ }
+
+ /// <summary>A stone church with a gabled nave and a belfry topped by a pyramid roof; false, and nothing built, when no
+ /// free dry spot is near.</summary>
+ static bool Church(string owner, Vector2 want, KitGround ground, KitMesh km, Lots lots, float size)
+ {
+ float m = KitScale.Landmarks * size;
+ var stone = C(0.86f, 0.76f, 0.57f);
+ if (!Claim(lots, want, 10f * m, owner, ground, out var q)) return false;
+ float yq = ground.Y(q.x, q.y);
+ km.Box(q.x, q.y, 0f, 9f * m, 18f * m, yq - 2f * m, yq, 12f * m, stone, stone, Facade.Stone, m, roofed: true);
+ km.Box(q.x, q.y + 7f * m, 0f, 4.5f * m, 4.5f * m, yq + 12f * m, yq + 12f * m, 14f * m, stone, stone, Facade.Stone, m, roofed: true);
+ km.Pyramid(q.x, q.y + 7f * m, 0f, 4.8f * m, 4.8f * m, yq + 26f * m, 6f * m, C(0.60f, 0.52f, 0.44f));
+ km.Gable(q.x, q.y, 0f, 9f * m, 18f * m, yq + 12f * m, 4f * m, C(0.66f, 0.34f, 0.24f), stone);
+ Record(owner, "church", q, 0f, 9f * m, 18f * m, 32f * m, stone);
+ return true;
+ }
+
+ static int WaterTower(string owner, Vector2 want, KitGround ground, KitMesh km, Lots lots)
+ {
+ float m = KitScale.Houses;
+ if (!Claim(lots, want, 4f * m, owner, ground, out var p)) return 0;
+ float y = ground.Y(p.x, p.y);
+ var concrete = C(0.82f, 0.80f, 0.76f);
+ Record(owner, "water_tower", p, 0f, 6f * m, 6f * m, 14.7f * m, concrete);
+ for (int i = 0; i < 4; i++)
+ {
+ float a = Mathf.PI * 0.5f * i + 0.6f;
+ var b = new Vector3(p.x + Mathf.Cos(a) * 2.6f * m, y - 2f * m, p.y + Mathf.Sin(a) * 2.6f * m);
+ km.Shaft(b, new Vector3(p.x + Mathf.Cos(a) * 1.8f * m, y + 9f * m, p.y + Mathf.Sin(a) * 1.8f * m), 0.35f * m, 0.3f * m, concrete, 4);
+ }
+ km.Shaft(new Vector3(p.x, y + 9f * m, p.y), new Vector3(p.x, y + 13.5f * m, p.y), 3f * m, 3f * m, concrete, 10);
+ km.Cone(new Vector3(p.x, y + 13.5f * m, p.y), 3.1f * m, 1.2f * m, C(0.66f, 0.64f, 0.60f), 10);
+ return 1;
+ }
+ }
+}
diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs.meta b/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs.meta
new file mode 100644
index 000000000..b2481a834
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: c3d59b5d1820841dfa772d0b22573d5b
\ No newline at end of file
diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.cs b/unity/Assets/Scripts/Map/Kits/SettlementKits.cs
index 7017a41f6..e8b5807c2 100644
--- a/unity/Assets/Scripts/Map/Kits/SettlementKits.cs
+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.cs
@@ -11,13 +11,19 @@ namespace Statecraft.Game.Map.Kits
/// <see cref="KitScale"/> times their real size (per class), a town's footprint spread over neighbouring hexes in
/// proportion to its population, geography real (towns stay on land, at their sourced coordinates). Built at load time
/// from the settlement id's seed (<see cref="KitRandom"/>), so every load of a build draws the same towns; nothing here reads or
- /// writes the sim.</summary>
- public static class SettlementKits
+ /// writes the sim.
+ /// Towns round 2 (docs/visual-v1.md, "Towns round 2"): every town is laid out on plot lattices (streets of plots at the
+ /// town's grid angle; organic towns jittered), each plot built with a probability that falls from the core to the edge,
+ /// instead of random spots tried against every lot. The landmarks of the four cities live in SettlementKits.Landmarks.cs.</summary>
+ public static partial class SettlementKits
{
/// <summary>Settled population per hex of footprint: a town of this many people covers one hex (about 65 km^2).</summary>
public const float PeoplePerHex = 60000f;
/// <summary>The smallest footprint, in hexes, so a kibbutz of 240 still reads as a place at the gameplay zoom.</summary>
public const float MinHexes = 0.08f;
+ /// <summary>How far past its footprint radius a town's plots reach (UnitGround.FootprintMargin: the units assume no
+ /// building beyond it; PaintGround tints the same disc).</summary>
+ public const float PlotReach = 1.1f;
public static Archetype ArchetypeOf(Settlement s)
{
@@ -49,15 +55,46 @@ namespace Statecraft.Game.Map.Kits
Build(list, ground, out _);
/// <summary>As Build, also returning every claimed lot (centre, radius, owning settlement id): buildings and landmarks
- /// of all towns, none overlapping another (tests).</summary>
+ /// of all towns, none overlapping another (tests); and, when <paramref name="columns"/> is given, filling it with each
+ /// non-empty kit's columns by settlement id (KitMesh.Columns, read before the mesh's CPU copy is dropped).</summary>
public static List<(Settlement s, Mesh mesh, int buildings)> Build(IReadOnlyList<Settlement> list, KitGround ground,
- out List<(Vector2 centre, float radius, string id)> claimed, Dictionary<string, Bounds[]>? columns = null)
+ out List<(Vector2 centre, float radius, string id)> claimed, Dictionary<string, Bounds[]>? columns = null) =>
+ Build(list, ground, out claimed, out _, columns);
+
+ /// <summary>One thing a kit placed, for the tests' and the docs' town census: a building (<see cref="Placed.Kind"/>
+ /// "building", or "wing" for a block's lower part) or a landmark (its name: "mosque", "clock_tower", ...), with its
+ /// world footprint (centre, yaw in degrees, width and depth in m), its wall height (m) and wall colour.</summary>
+ public readonly struct Placed
{
- var all = Build(list, new List<Settlement>(), new List<Localities.Area>(), ground, columns);
+ public readonly string Id, Kind; public readonly Vector2 C; public readonly float Yaw, W, D, H; public readonly Color32 Wall;
+ public Placed(string id, string kind, Vector2 c, float yaw, float w, float d, float h, Color32 wall)
+ { Id = id; Kind = kind; C = c; Yaw = yaw; W = w; D = d; H = h; Wall = wall; }
+ /// <summary>Harbour works stand in the sea by design; everything else stands on land.</summary>
+ public bool InSea => Kind == "port" || Kind == "breakwater";
+ }
+
+ [System.ThreadStatic] static List<Placed>? census;
+ static void Record(string id, string kind, Vector2 c, float yaw, float w, float d, float h, Color32 wall) =>
+ census?.Add(new Placed(id, kind, c, yaw, w, d, h, wall));
+
+ /// <summary>As Build, also listing everything placed (<see cref="Placed"/>), in placement order.</summary>
+ public static List<(Settlement s, Mesh mesh, int buildings)> Build(IReadOnlyList<Settlement> list, KitGround ground,
+ out List<(Vector2 centre, float radius, string id)> claimed, out List<Placed> placed, Dictionary<string, Bounds[]>? columns = null)
+ {
+ var all = Build(list, new List<Settlement>(), new List<Localities.Area>(), ground, out placed, columns);
claimed = all.Claimed;
return all.Towns;
}
+ /// <summary>As the full Build, also listing everything placed (<see cref="Placed"/>), in placement order.</summary>
+ public static Result Build(IReadOnlyList<Settlement> towns, IReadOnlyList<Settlement> localities, IReadOnlyList<Localities.Area> camps,
+ KitGround ground, out List<Placed> placed, Dictionary<string, Bounds[]>? columns = null)
+ {
+ census = placed = new List<Placed>();
+ try { return Build(towns, localities, camps, ground, columns); }
+ finally { census = null; }
+ }
+
/// <summary>What <see cref="Build(IReadOnlyList{Settlement}, IReadOnlyList{Settlement}, IReadOnlyList{Localities.Area}, KitGround)"/>
/// made: one mesh per game settlement, and the 1948 localities and Bedouin camps merged into one mesh per
/// <see cref="TileM"/> tile (a few dozen draws for some three hundred places).</summary>
@@ -67,7 +104,7 @@ namespace Statecraft.Game.Map.Kits
public List<(string name, Mesh mesh)> Tiles = new List<(string, Mesh)>();
public List<(Vector2 centre, float radius, string id)> Claimed = new List<(Vector2, float, string)>();
public int LocalityBuildings, Camps, Tents;
- /// <summary>Landmarks each game settlement built (its archetype's: a mosque, a water tower, Jaffa's three).</summary>
+ /// <summary>Landmarks each game settlement built (SettlementKits.Landmarks.cs: a city's own, else its archetype's).</summary>
public Dictionary<string, int> TownLandmarks = new Dictionary<string, int>();
}
@@ -105,6 +142,7 @@ namespace Statecraft.Game.Map.Kits
var streams = new Dictionary<string, KitRandom>(); var landmarks = new Dictionary<string, int>();
var spans = new Dictionary<string, List<(KitMesh km, int from, int to)>>(); // each locality's vertices in its tile
var townMeshes = new Dictionary<string, KitMesh>();
+ var gameTowns = new List<(Settlement s, KitMesh km, int n, System.Func<int>? scatter)>();
// Landmarks first: every game settlement's (largest first), then every locality's, each at its heart, before any
// houses. A village at a city's edge (Jammasin by Tel Aviv) keeps its heart, and no village takes a game town's
// landmark spot (review M8).
@@ -115,7 +153,9 @@ namespace Statecraft.Game.Map.Kits
var rnd = new KitRandom(s.Id, 1);
var km = pass ? Tile(centres[s.Id]) : (townMeshes[s.Id] = new KitMesh());
int from = km.VertexCount;
- int n = BuildOne(s, centres[s.Id], ground, km, lots, Phase.Landmark, ref rnd, 0, null);
+ // A game settlement's own landmarks (towns round 2: TownLandmarks), a locality's its archetype's.
+ int n = pass ? BuildOne(s, centres[s.Id], ground, km, lots, Phase.Landmark, ref rnd, 0, null)
+ : TownLandmarks(s, centres[s.Id], ground, km, lots, ref rnd);
if (pass) { spans[s.Id] = new List<(KitMesh, int, int)> { (km, from, km.VertexCount) }; result.LocalityBuildings += n; }
else result.TownLandmarks[s.Id] = n;
landmarks[s.Id] = n; streams[s.Id] = rnd;
@@ -134,15 +174,22 @@ namespace Statecraft.Game.Map.Kits
continue;
}
var km = townMeshes[s.Id];
- int n = landmarks[s.Id] + BuildOne(s, centres[s.Id], ground, km, lots, Phase.Houses, ref rnd, landmarks[s.Id], merged);
- if (columns != null && km.VertexCount > 0) columns[s.Id] = km.Columns();
- result.Towns.Add((s, km.ToMesh(s.Id + "_kit"), n));
+ int n = landmarks[s.Id] + PlaceHouses(s, centres[s.Id], ground, km, lots, ref rnd, merged, out var scatter); // towns round 2: plot lattices
+ gameTowns.Add((s, km, n, scatter));
}
foreach (var area in camps)
{
var (c, t) = Encampments(area, ground, lots, Tile);
result.Camps += c; result.Tents += t;
}
+ // Last, the small towns' fallback houses (#317), largest place first: after every place's own houses and the camps,
+ // so they take only ground no other place builds on, and every other place draws as it would without them.
+ foreach (var (s, km, n, scatter) in gameTowns)
+ {
+ int total = n + (scatter?.Invoke() ?? 0);
+ if (columns != null && km.VertexCount > 0) columns[s.Id] = km.Columns();
+ result.Towns.Add((s, km.ToMesh(s.Id + "_kit"), total));
+ }
// A locality's columns, from its own vertices in its tile (read before ToMesh drops the CPU copy).
if (columns != null)
foreach (var kv in spans)
@@ -200,21 +247,36 @@ namespace Statecraft.Game.Map.Kits
}
}
- sealed class Lot { public Vector2 c; public float r; public string id = ""; }
+ /// <summary>A claimed lot: its disc, its town and, for a plot, its lattice (<see cref="group"/>; -1 for a landmark).
+ /// Plots of one lattice never overlap by construction, so they do not test each other's discs.</summary>
+ sealed class Lot { public Vector2 c; public float r; public string id = ""; public int group = -1; }
- /// <summary>The shared lot list, in claim order, with a grid index for the free-spot test.</summary>
+ /// <summary>The shared lot list, in claim order, with a grid index (DiscIndex, as KitGround's) for the free-spot test.</summary>
sealed class Lots
{
public readonly List<Lot> List = new List<Lot>();
readonly DiscIndex index = new DiscIndex(1f, KitGround.LotQueryM);
public void Add(Lot l) { List.Add(l); index.Add((l.c, l.r, l.id)); }
- public bool Free(Vector2 p, float r)
+
+ /// <summary>No lot within reach of a disc of radius r at p, except the plots of <paramref name="id"/>'s lattice
+ /// <paramref name="group"/> (pass group -1 to test against every lot).</summary>
+ public bool Free(Vector2 p, float r, string id = "", int group = -1)
{
- if (r > KitGround.LotQueryM) { foreach (var l in List) if ((l.c - p).sqrMagnitude < (l.r + r) * (l.r + r)) return false; return true; }
+ if (r > KitGround.LotQueryM)
+ {
+ foreach (var l in List) if (!Same(l, id, group) && (l.c - p).sqrMagnitude < (l.r + r) * (l.r + r)) return false;
+ return true;
+ }
var near = index.Near(p);
- for (int k = 0; k < near.Count; k++) { var (c, lr, _) = index[near[k]]; if ((c - p).sqrMagnitude < (lr + r) * (lr + r)) return false; }
+ for (int k = 0; k < near.Count; k++)
+ {
+ var l = List[near[k]];
+ if (!Same(l, id, group) && (l.c - p).sqrMagnitude < (l.r + r) * (l.r + r)) return false;
+ }
return true;
}
+
+ static bool Same(Lot l, string id, int group) => group >= 0 && l.group == group && l.id == id;
}
static bool FreeAt(Lots lots, Vector2 p, float r) => lots.Free(p, r);
@@ -238,11 +300,522 @@ namespace Statecraft.Game.Map.Kits
at = want; return false;
}
+ // ---- 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
+ {
+ /// <summary>Tel Aviv's and Hadar HaCarmel's International Style blocks: white plaster, flat roofs (60x).</summary>
+ WhiteBlock,
+ /// <summary>The plastered two- and three-storey centre of a large moshava (Petah Tikva, Rehovot) (60x).</summary>
+ TownBlock,
+ /// <summary>Jerusalem's new city: stone-faced blocks, Storrs' 1918 ordinance (60x).</summary>
+ StoneBlock,
+ /// <summary>An Ottoman old town's stone house: Jaffa, Acre, Gaza, Jerusalem within the walls, Haifa's lower town (100x).</summary>
+ OldHouse,
+ /// <summary>An Arab town's or village's stone or mud-brick house (100x).</summary>
+ Village,
+ /// <summary>A moshava's, kibbutz's or moshav's red-roofed house (100x).</summary>
+ Moshava,
+ /// <summary>A Templer house of Haifa's German Colony: stone, red roof (100x; placed along its avenue, not on a lattice).</summary>
+ Templer,
+ }
+
+ /// <summary>A plot lattice: rows of plots at its style's pitch (<see cref="Grid"/>), turned <see cref="Yaw"/> degrees;
+ /// <see cref="Group"/> tells a town's lattices apart (plots of one lattice never overlap, so they skip each other's lot test).</summary>
+ readonly struct Lattice
+ {
+ public readonly Style Style; public readonly float Yaw; public readonly int Group;
+ public Lattice(Style style, float yaw, int group) { Style = style; Yaw = yaw; Group = group; }
+ }
+
+ /// <summary>Plot pitch along and across the street (real m), jitter (share of the pitch), the symbolic scale, and
+ /// the share of plots built in the core (out to t0 of the radius), at the radius, and past it (falling to none at
+ /// <see cref="PlotReach"/>).</summary>
+ static (float pu, float pv, float jitter, float scale, float core, float t0, float edge) Grid(Style st) => st switch
+ {
+ Style.WhiteBlock => (18.5f, 13.5f, 0f, KitScale.CityBlocks, 1.00f, 0.60f, 0.70f),
+ Style.TownBlock => (20f, 16f, 0.03f, KitScale.CityBlocks, 1.00f, 0.30f, 0.80f),
+ Style.StoneBlock => (23f, 17.5f, 0.03f, KitScale.CityBlocks, 0.97f, 0.50f, 0.60f),
+ Style.OldHouse => (7.2f, 6.8f, 0.05f, KitScale.Houses, 1.00f, 0.60f, 0.75f),
+ Style.Village => (7.6f, 7.2f, 0.07f, KitScale.Houses, 1.00f, 0.50f, 0.60f),
+ _ => (11.5f, 9.8f, 0.04f, KitScale.Houses, 0.95f, 0.40f, 0.60f),
+ };
+
+ static float Density(Style st, float t)
+ {
+ var g = Grid(st);
+ if (t <= g.t0) return g.core;
+ if (t <= 1f) return Mathf.Lerp(g.core, g.edge, (t - g.t0) / (1f - g.t0));
+ return Mathf.Lerp(g.edge, 0f, (t - 1f) / (PlotReach - 1f));
+ }
+
+ /// <summary>The lattices a town is laid out on: one per archetype, two or three where a town has quarters of different
+ /// building (Jerusalem: the walled Old City, the stone new city, the Arab quarters and villages round it; Haifa: the
+ /// lower town by the port and Hadar on the slope; a large moshava's plastered centre).</summary>
+ static List<Lattice> Lattices(Settlement s, Archetype arch)
+ {
+ float yaw = GridYaw(s.Id);
+ switch (s.Id)
+ {
+ case "jerusalem": return new List<Lattice> { new Lattice(Style.OldHouse, 0f, 0), new Lattice(Style.StoneBlock, yaw, 1), new Lattice(Style.Village, yaw, 2) };
+ case "haifa": return new List<Lattice> { new Lattice(Style.WhiteBlock, yaw, 0), new Lattice(Style.OldHouse, yaw, 1) };
+ }
+ switch (arch)
+ {
+ case Archetype.WhiteCity: return new List<Lattice> { new Lattice(Style.WhiteBlock, yaw, 0) };
+ case Archetype.OldTown: return new List<Lattice> { new Lattice(Style.OldHouse, yaw, 0) };
+ case Archetype.ArabTown: return new List<Lattice> { new Lattice(Style.Village, yaw, 0) };
+ default:
+ return s.Type == "town" && KitPopulation.Of(s.Id) >= LargeMoshava
+ ? new List<Lattice> { new Lattice(Style.TownBlock, yaw, 0), new Lattice(Style.Moshava, yaw, 1) }
+ : new List<Lattice> { new Lattice(Style.Moshava, yaw, 0) };
+ }
+ }
+
+ /// <summary>A moshava of at least this many people (1945) gets a plastered town centre (Petah Tikva, Rehovot, Rishon
+ /// LeZion, Hadera).</summary>
+ const int LargeMoshava = 7500;
+
+ /// <summary>Whether lattice <paramref name="L"/> builds at <paramref name="p"/> (t: distance over the footprint radius).</summary>
+ static bool Allows(Settlement s, Lattice L, Vector2 p, float t, KitGround ground)
+ {
+ switch (s.Id)
+ {
+ case "jerusalem":
+ {
+ var (oc, half) = OldCity(ground);
+ var d = p - oc;
+ bool inside = Mathf.Abs(d.x) < half - OldCityInset && Mathf.Abs(d.y) < half - OldCityInset;
+ bool outside = Mathf.Abs(d.x) > half + OldCityInset || Mathf.Abs(d.y) > half + OldCityInset;
+ // West of the Old City: the Jewish new city (the city centre, Rehavia); north, east and south: the Arab
+ // quarters and villages. (The Old City's symbolic square covers the ground of its nearest neighbourhoods.)
+ bool west = d.x < -half * 0.6f;
+ return L.Style == Style.OldHouse ? inside : outside && (L.Style == Style.StoneBlock) == west;
+ }
+ case "haifa":
+ // The lower town by the bay (old Arab Haifa, below about 35 m) and Hadar HaCarmel up the slope.
+ return (L.Style == Style.OldHouse) == (ground.ElevM(p.x, p.y) < 35f);
+ case "nahalal":
+ // Nahalal's ring of farmsteads round the public buildings, out to the footprint's edge: its lattice's
+ // first ring of plots stands at 0.76 and 0.89 of the radius.
+ return t > 0.42f && t <= 1f;
+ }
+ if (L.Style == Style.TownBlock) return t < 0.42f;
+ if (L.Style == Style.Moshava && L.Group == 1) return t > 0.36f;
+ return true;
+ }
+
+ /// <summary>Places a town's houses on its lattices, nearest the centre first; returns how many. When the lattice
+ /// places fewer than <see cref="SmallTownFloor"/>, <paramref name="scatter"/> is the town's fallback (#317), which
+ /// Build runs after every other place's houses; else null.</summary>
+ static int PlaceHouses(Settlement s, Vector2 centre, KitGround ground, KitMesh km, Lots lots, ref KitRandom rnd, HashSet<string>? ignoreCellsOf,
+ out System.Func<int>? scatter)
+ {
+ var arch = ArchetypeOf(s);
+ float R = FootprintRadiusM(s, ground.HexSizeM), reach = R * PlotReach;
+ var lattices = Lattices(s, arch);
+
+ // A point belongs to the settlement whose footprint it is deepest inside (distance over radius), so Jaffa and Tel
+ // Aviv, or Lod and Ramla, meet along a seam instead of overlapping. The 1948 localities' cells (ignoreCellsOf) do
+ // not count: a game settlement keeps the ground it had before the villages came (their landmarks' lots still stand).
+ bool Mine(Vector2 p)
+ {
+ float mine = (p - centre).magnitude / R;
+ var fp = ground.Footprints;
+ var near = fp.Near(p);
+ for (int k = 0; k < near.Count; k++)
+ {
+ int i = near[k];
+ if (fp[i].id != s.Id && (ignoreCellsOf == null || !ignoreCellsOf.Contains(fp[i].id))
+ && (p - fp[i].centre).magnitude / fp[i].radius < mine) return false;
+ }
+ return true;
+ }
+
+ // Only a town with water near its footprint tests the beach setback per plot (eight samples each: the boot budget).
+ bool shore = WaterWithin(centre, reach + BeachSetbackM + 1000f, ground);
+ var plots = new List<(float d, int order, Vector2 p, int lattice)>();
+ for (int li = 0; li < lattices.Count; li++)
+ {
+ var g = Grid(lattices[li].Style);
+ float pu = g.pu * g.scale, pv = g.pv * g.scale, a = lattices[li].Yaw * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);
+ int nu = Mathf.CeilToInt(reach / pu) + 1, nv = Mathf.CeilToInt(reach / pv) + 1;
+ for (int j = -nv; j <= nv; j++)
+ for (int i = -nu; i <= nu; i++)
+ {
+ // Organic towns stagger alternate rows by half a plot: no straight cross streets.
+ float u = (i + (g.jitter > 0f && (j & 1) != 0 ? 0.5f : 0f)) * pu, v = j * pv;
+ var p = centre + new Vector2(u * ca - v * sa, u * sa + v * ca);
+ float d = (p - centre).magnitude;
+ if (d <= reach) plots.Add((d, plots.Count, p, li));
+ }
+ }
+ plots.Sort((x, y) => x.d != y.d ? x.d.CompareTo(y.d) : x.order.CompareTo(y.order));
+
+ // Whether lattice L's building fits at p: the full building, else a smaller one on the plot or nudged within it,
+ // so a plot by a road or a neighbour's lot keeps a smaller building instead of standing empty. A nudged, shrunk
+ // building still stays inside its plot, so it never reaches a neighbouring plot's building. group -1 tests
+ // against every lot, this town's plots included (the scatter below).
+ bool Fit(Lattice L, Vector2 p, float yaw, float t, Spec spec, int group, out Spec b, out Vector2 q)
+ {
+ var g = Grid(L.Style);
+ float a = L.Yaw * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);
+ bool hillTown = L.Style == Style.OldHouse || L.Style == Style.Village;
+ foreach (var (shrink, du, dv) in Fits)
+ {
+ b = Shrink(spec, shrink);
+ float u = du * g.pu * g.scale, v = dv * g.pv * g.scale;
+ q = p + new Vector2(u * ca - v * sa, u * sa + v * ca);
+ if ((du != 0f || dv != 0f) && (!ground.Inside(q.x, q.y) || !Mine(q) || !Allows(s, L, q, t, ground) || ground.Water(q.x, q.y))) continue;
+ if (!lots.Free(q, b.lotR, s.Id, group) || ground.OnRoute(q, b.lotR)) continue; // off the railways and roads too
+ if (ground.Slope(q.x, q.y, b.w) > (hillTown ? 0.6f : 0.35f)) continue;
+ if (CornerInWater(q, yaw, b.w, b.d, ground)) continue; // the whole footprint is dry
+ if (shore && L.Style != Style.OldHouse && NearSea(q, yaw, b.w + 2f * BeachSetbackM, b.d + 2f * BeachSetbackM, ground)) continue;
+ return true;
+ }
+ b = spec; q = p; return false;
+ }
+
+ int placed = 0;
+ foreach (var (d, _, p0, li) in plots)
+ {
+ var L = lattices[li]; var g = Grid(L.Style);
+ float t = d / R;
+ // Every plot draws the same numbers whether or not it is built, so one plot's fate never shifts another's.
+ bool build = rnd.Chance(Density(L.Style, t));
+ float ju = rnd.Range(-1f, 1f) * g.jitter * g.pu * g.scale, jv = rnd.Range(-1f, 1f) * g.jitter * g.pv * g.scale;
+ var spec = Pick(L.Style, t, ref rnd, g.scale);
+ // Inside Jerusalem's walls, one or two storeys: the walls and the Dome of the Rock stand above the roofs.
+ if (s.Id == "jerusalem" && L.Style == Style.OldHouse && spec.storeys > 2) { spec.storeys = 2; spec.h = 2f * 3.3f * g.scale; }
+ float yaw = L.Yaw + (g.jitter > 0f ? rnd.Range(-4f, 4f) : 0f);
+ ulong detail = rnd.Next();
+ if (!build) continue;
+ float a = L.Yaw * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);
+ var p = p0 + new Vector2(ju * ca - jv * sa, ju * sa + jv * ca);
+ // The cheap tests first (the boot budget): the cell and the quarter, then the terrain samples.
+ if (!ground.Inside(p.x, p.y) || !Mine(p) || !Allows(s, L, p, t, ground) || ground.Water(p.x, p.y)) continue;
+ if (!Fit(L, p, yaw, t, spec, L.Group, out var b, out var q)) continue;
+ lots.Add(new Lot { c = q, r = b.lotR, id = s.Id, group = L.Group });
+ var drnd = new KitRandom(detail);
+ Emit(s.Id, L.Style, q, yaw, b, t, ground, km, ref drnd);
+ placed++;
+ }
+
+ // A small town's floor (#317): at the houses' 100x scale a plot is about 1 km, so a footprint of 1.3-2 km radius
+ // holds only some 7 plots, and the routes, the sea or a neighbour's lots can take most of them.
+ // Below SmallTownFloor houses the town is filled up as round 1 drew it: its archetype's full-size building (the
+ // size main drew, never shrunk), on random spots over the footprint tried nearest the heart first, from its own
+ // stream (KitRandom(id, 3)). Build runs it after every place's own houses and the camps, so it takes only ground
+ // no other place builds on.
+ scatter = null;
+ if (placed < SmallTownFloor && SmallTownScatter)
+ {
+ int want = SmallTownFloor - placed;
+ scatter = () =>
+ {
+ var srnd = new KitRandom(s.Id, 3);
+ float m = KitScale.For(arch);
+ var spots = new List<(float r, int i, Vector2 p, float yaw, Spec b, ulong detail)>();
+ for (int i = 0; i < ScatterTries; i++)
+ {
+ float r = reach * Mathf.Sqrt(srnd.Value()), ang = srnd.Range(0f, 2f * Mathf.PI);
+ var b = Pick(arch, r / R, ref srnd, m);
+ b.lotR = 0.5f * Mathf.Sqrt(b.w * b.w + b.d * b.d); // the whole footprint, as a plot's (round 1's lot let a corner reach a road)
+ float yaw = arch == Archetype.Moshava || arch == Archetype.WhiteCity ? GridYaw(s.Id) + srnd.Range(-4f, 4f) : srnd.Range(0f, 90f);
+ spots.Add((r, i, centre + new Vector2(Mathf.Cos(ang), Mathf.Sin(ang)) * r, yaw, b, srnd.Next()));
+ }
+ spots.Sort((x, y) => x.r != y.r ? x.r.CompareTo(y.r) : x.i.CompareTo(y.i));
+ // The tests that do not depend on the house's size, once per spot (the boot budget): the cell, the water, the
+ // quarter's rule (Nahalal's ring).
+ var site = new bool[spots.Count];
+ for (int k = 0; k < spots.Count; k++)
+ {
+ var (r, _, p, _, _, _) = spots[k]; float t = r / R;
+ site[k] = ground.Inside(p.x, p.y) && Mine(p) && !ground.Water(p.x, p.y) && lattices.Exists(x => Allows(s, x, p, t, ground));
+ }
+ int added = 0;
+ bool hillTown = arch == Archetype.ArabTown || arch == Archetype.OldTown;
+ // Full size first over every spot; only then 0.72 size (never the half-size fit: Acre's stray beach house).
+ foreach (var shrink in new[] { 1f, 0.72f })
+ for (int k = 0; k < spots.Count && added < want; k++)
+ {
+ if (!site[k]) continue;
+ var (r, _, p, yaw, full, detail) = spots[k];
+ var b = Shrink(full, shrink);
+ if (!lots.Free(p, b.lotR) || ground.OnRoute(p, b.lotR)) continue;
+ if (ground.Slope(p.x, p.y, b.w) > (hillTown ? 0.6f : 0.35f)) continue;
+ if (CornerInWater(p, yaw, b.w, b.d, ground)) continue;
+ // Every fallback house keeps off the beach strip, an old town's too (Acre's stood alone on the sand).
+ if (shore && NearSea(p, yaw, b.w + 2f * BeachSetbackM, b.d + 2f * BeachSetbackM, ground)) continue;
+ lots.Add(new Lot { c = p, r = b.lotR, id = s.Id });
+ var drnd = new KitRandom(detail);
+ var wall = Emit(arch, p, yaw, b, ground, km, ref drnd);
+ Record(s.Id, "building", p, yaw, b.w, b.d, b.h, wall);
+ added++;
+ }
+ return added;
+ };
+ }
+ return placed;
+ }
+
+ /// <summary>The fewest houses a town keeps (#317): round 1's floor per town (TargetCount's minimum of 6). Fifteen of the
+ /// 25 towns' lattices fall short of it (the moshavot and kibbutzim, Tiberias, Netanya, Beersheba and Acre); their
+ /// fallback houses join the lattice's where free ground is left (13 of them).</summary>
+ const int SmallTownFloor = 6;
+ /// <summary>Random spots a small town's fallback tries before it settles for fewer than SmallTownFloor houses (round 1
+ /// tried about 30 per building).</summary>
+ const int ScatterTries = 240;
+ /// <summary>Whether the small towns' fallback runs (on; tests switch it off to show it moves no other place).</summary>
+ public static bool SmallTownScatter = true;
+
+ /// <summary>The fits a plot tries in turn: (size share, nudge along and across the street as a share of the pitch).</summary>
+ static readonly (float shrink, float du, float dv)[] Fits =
+ {
+ (1f, 0f, 0f), (0.72f, 0f, 0f), (0.72f, 0.15f, 0f), (0.72f, -0.15f, 0f), (0.72f, 0f, 0.15f), (0.72f, 0f, -0.15f), (0.5f, 0f, 0f),
+ };
+
+ static Spec Shrink(Spec b, float k) =>
+ k >= 1f ? b : new Spec { w = b.w * k, d = b.d * k, h = b.h, storeys = b.storeys, lotR = b.lotR * k };
+
+
+ /// <summary>How far (m) a new town's buildings keep back from the sea: the beach strip (promo-sea's ScBeachM, 650 m on
+ /// average) stays sand, with its palms, as in promo 03's Tel Aviv. The old towns (Jaffa, Acre, Gaza, Haifa's lower
+ /// town by the port) meet the water.</summary>
+ const float BeachSetbackM = 700f;
+
+ /// <summary>Water that is not a lake: the beach strip is the Mediterranean's. The Sea of Galilee's and the Hula's towns
+ /// (Tiberias, Degania) meet the water, as the old towns do.</summary>
+ static bool Sea(float x, float z, KitGround ground) => ground.Water(x, z) && !(ground.Inside(x, z) && ground.Biome(x, z) == "lake");
+
+ /// <summary>Any sea on 24 rays from <paramref name="c"/>, sampled every kilometre out to <paramref name="radius"/>: whether a
+ /// town's plots need the beach setback test at all.</summary>
+ static bool WaterWithin(Vector2 c, float radius, KitGround ground)
+ {
+ for (int i = 0; i < 24; i++)
+ {
+ float a = i * Mathf.PI / 12f;
+ var dir = new Vector2(Mathf.Cos(a), Mathf.Sin(a));
+ for (float d = 1000f; d <= radius; d += 1000f)
+ {
+ var p = c + dir * d;
+ if (Sea(p.x, p.y, ground)) return true;
+ }
+ }
+ return false;
+ }
+
+ /// <summary>Any sea (not a lake) at the corners or edge midpoints of a w x d rectangle at <paramref name="p"/>.</summary>
+ static bool NearSea(Vector2 p, float yawDeg, float w, float d, KitGround ground)
+ {
+ float a = yawDeg * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);
+ foreach (var (u, v) in new[] { (-0.5f * w, -0.5f * d), (0.5f * w, -0.5f * d), (-0.5f * w, 0.5f * d), (0.5f * w, 0.5f * d),
+ (0.5f * w, 0f), (-0.5f * w, 0f), (0f, 0.5f * d), (0f, -0.5f * d) })
+ if (Sea(p.x + u * ca - v * sa, p.y + u * sa + v * ca, ground)) return true;
+ return false;
+ }
+
+ static bool CornerInWater(Vector2 p, float yawDeg, float w, float d, KitGround ground)
+ {
+ float a = yawDeg * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);
+ for (int i = 0; i < 4; i++)
+ {
+ float u = ((i & 1) == 0 ? -0.5f : 0.5f) * w, v = ((i & 2) == 0 ? -0.5f : 0.5f) * d;
+ if (ground.Water(p.x + u * ca - v * sa, p.y + u * sa + v * ca)) return true;
+ }
+ return false;
+ }
+
+ /// <summary>The street grid's angle per town (Tel Aviv's Geddes plan runs about 20 degrees off north, parallel to the
+ /// 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; }
+
+ /// <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>
+ static Spec Pick(Style st, float t, ref KitRandom rnd, float m)
+ {
+ float w, d; int storeys;
+ switch (st)
+ {
+ case Style.WhiteBlock:
+ w = rnd.Range(12f, 16f); d = rnd.Range(9f, 11.5f);
+ // Taller near the centre, a few taller still: promo 03's five- to eight-storey skyline, above the real White
+ // City's three or four storeys (owner ruling 2026-10-10: where the promo departs from the era, the promo wins).
+ storeys = Mathf.RoundToInt(Mathf.Lerp(7f, 3f, Mathf.Clamp01(t)) + rnd.Range(-1.5f, 1.5f));
+ if (t < 0.5f && rnd.Chance(0.1f)) storeys = rnd.Range(7, 9);
+ storeys = Mathf.Clamp(storeys, 2, 8); // promo 03's tallest block is eight storeys; nothing reads as a later tower
+ break;
+ case Style.TownBlock:
+ w = rnd.Range(12f, 17f); d = rnd.Range(9f, 13f);
+ storeys = rnd.Chance(Mathf.Lerp(0.6f, 0.2f, t / 0.42f)) ? 3 : 2;
+ break;
+ case Style.StoneBlock:
+ w = rnd.Range(13f, 20f); d = rnd.Range(10f, 14.5f);
+ storeys = Mathf.Clamp(Mathf.RoundToInt(Mathf.Lerp(3.6f, 2f, Mathf.Clamp01(t)) + rnd.Range(-0.8f, 0.8f)), 2, 4);
+ break;
+ case Style.OldHouse:
+ w = rnd.Range(4.6f, 6.6f); d = rnd.Range(4.4f, 6.2f);
+ storeys = Mathf.Clamp(Mathf.RoundToInt(Mathf.Lerp(3.2f, 1.3f, Mathf.Clamp01(t)) + rnd.Range(-0.8f, 0.8f)), 1, 4);
+ break;
+ case Style.Village:
+ w = rnd.Range(4.4f, 6.6f); d = rnd.Range(4.2f, 6.0f);
+ storeys = rnd.Chance(Mathf.Lerp(0.45f, 0.1f, Mathf.Clamp01(t))) ? 2 : 1;
+ break;
+ case Style.Templer:
+ w = rnd.Range(8.5f, 10.5f); d = rnd.Range(7.5f, 9f);
+ storeys = 2;
+ break;
+ default:
+ w = rnd.Range(7.5f, 10f); d = rnd.Range(6f, 7.8f);
+ storeys = rnd.Chance(0.15f) ? 2 : 1;
+ break;
+ }
+ return new Spec { w = w * m, d = d * m, h = storeys * 3.3f * m, storeys = storeys, lotR = 0.5f * Mathf.Sqrt(w * w + d * d) * m };
+ }
+
+ // sRGB palettes (promo 03: white and cream city, honey stone Jaffa, tan villages, terracotta roofs).
+ static Color32 C(float r, float g, float b) => new Color32((byte)(r * 255), (byte)(g * 255), (byte)(b * 255), 255);
+ static Color32 Jitter(Color32 c, ref KitRandom rnd, float amount)
+ {
+ float k = 1f + rnd.Range(-amount, amount), warm = rnd.Range(-amount, amount) * 0.5f;
+ return C(Mathf.Clamp01(c.r / 255f * k * (1 + warm)), Mathf.Clamp01(c.g / 255f * k), Mathf.Clamp01(c.b / 255f * k * (1 - warm)));
+ }
+
+ /// <summary>Draws one plot's building and records it in the census.</summary>
+ static void Emit(string id, Style st, Vector2 p, float yaw, Spec b, float t, KitGround ground, KitMesh km, ref KitRandom rnd)
+ {
+ float m = Grid(st).scale;
+ var (bottom, top) = GroundSpan(p, yaw, b.w, b.d, ground, m);
+ float storey = 3.3f * m;
+ switch (st)
+ {
+ case Style.WhiteBlock:
+ case Style.TownBlock:
+ {
+ var wall = rnd.Chance(st == Style.TownBlock ? 0.3f : 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);
+ // A third of the blocks step down at one end: a lower wing within the plot (L and stepped massing).
+ if (b.storeys >= 3 && rnd.Chance(0.33f))
+ {
+ float a = yaw * Mathf.Deg2Rad, share = rnd.Range(0.58f, 0.72f), side = rnd.Chance(0.5f) ? 1f : -1f;
+ float w1 = b.w * share, w2 = b.w - w1, d2 = b.d * rnd.Range(0.7f, 1f), h2 = b.h - storey * rnd.Range(1, 3);
+ 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);
+ 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);
+ Record(id, "building", p, yaw, b.w, b.d, b.h, wall);
+ }
+ // A stair tower or roof room on many Bauhaus blocks.
+ if (rnd.Chance(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);
+ }
+ break;
+ }
+ case Style.StoneBlock:
+ {
+ 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);
+ 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);
+ Record(id, "building", p, yaw, b.w, b.d, b.h, wall);
+ break;
+ }
+ case Style.OldHouse:
+ {
+ var wall = Jitter(C(0.83f, 0.72f, 0.54f), ref rnd, 0.06f);
+ var roof = Jitter(C(0.86f, 0.77f, 0.60f), ref rnd, 0.05f);
+ // Outside the core, some Ottoman-era houses have red tiled roofs (Jaffa's Ajami, Haifa's lower town).
+ bool tiled = rnd.Chance(t > 0.6f ? 0.14f : 0.03f);
+ km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, b.h, wall, roof, Facade.Stone, m, roofed: tiled);
+ if (tiled) km.Pyramid(p.x, p.y, yaw, b.w * 1.04f, b.d * 1.04f, top + b.h, 2.2f * m, Jitter(C(0.70f, 0.33f, 0.22f), ref rnd, 0.06f));
+ else if (rnd.Chance(0.22f)) km.Dome(p.x, p.y, top + b.h - 1f, Mathf.Min(b.w, b.d) * 0.33f, Jitter(C(0.88f, 0.84f, 0.76f), ref rnd, 0.05f));
+ else if (b.storeys >= 2 && rnd.Chance(0.3f)) // a roof room on the flat roof
+ km.Box(p.x + b.w * 0.2f, p.y - b.d * 0.15f, yaw, b.w * 0.45f, b.d * 0.5f, top + b.h - 2f, top + b.h, storey * 0.9f, wall, roof, Facade.Stone, m);
+ Record(id, "building", p, yaw, b.w, b.d, b.h, wall);
+ break;
+ }
+ case Style.Village:
+ {
+ var wall = Jitter(C(0.80f, 0.70f, 0.53f), ref rnd, 0.07f);
+ var roof = Jitter(C(0.84f, 0.75f, 0.59f), ref rnd, 0.06f);
+ km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, b.h, wall, roof, Facade.Village, m);
+ if (rnd.Chance(0.10f)) km.Dome(p.x, p.y, top + b.h - 1f, Mathf.Min(b.w, b.d) * 0.3f, roof);
+ Record(id, "building", p, yaw, b.w, b.d, b.h, wall);
+ break;
+ }
+ case Style.Templer:
+ {
+ var wall = Jitter(C(0.86f, 0.79f, 0.66f), ref rnd, 0.04f);
+ var roof = Jitter(C(0.72f, 0.31f, 0.20f), ref rnd, 0.06f);
+ km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, b.h, wall, roof, Facade.Stone, m, roofed: true);
+ km.Gable(p.x, p.y, yaw, b.w, b.d, top + b.h, Mathf.Min(b.w, b.d) * 0.55f, roof, wall);
+ Record(id, "building", p, yaw, b.w, b.d, b.h, wall);
+ break;
+ }
+ default:
+ {
+ var wall = Jitter(C(0.92f, 0.89f, 0.82f), ref rnd, 0.04f);
+ var roof = Jitter(C(0.74f, 0.31f, 0.20f), ref rnd, 0.08f);
+ km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, b.h, wall, roof, Facade.Village, m, roofed: true);
+ km.Gable(p.x, p.y, yaw, b.w, b.d, top + b.h, Mathf.Min(b.w, b.d) * 0.42f, roof, wall);
+ Record(id, "building", p, yaw, b.w, b.d, b.h, wall);
+ break;
+ }
+ }
+ }
+
+ /// <summary>Wall bottom (sunk 2 m below the lowest corner, so a house on a slope stands on a plinth, not on air) and the
+ /// ground level the walls rise from (the highest corner, so the slope never buries a storey).</summary>
+ static (float bottom, float ground) GroundSpan(Vector2 p, float yawDeg, float w, float d, KitGround ground, float m)
+ {
+ float a = yawDeg * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);
+ float lo = float.MaxValue, hi = float.MinValue;
+ for (int i = 0; i < 5; i++)
+ {
+ float u = i == 4 ? 0 : ((i & 1) == 0 ? -0.5f : 0.5f) * w, v = i == 4 ? 0 : ((i & 2) == 0 ? -0.5f : 0.5f) * d;
+ float y = ground.Y(p.x + u * ca - v * sa, p.y + u * sa + v * ca);
+ lo = Mathf.Min(lo, y); hi = Mathf.Max(hi, y);
+ }
+ return (lo - 2f * m, hi);
+ }
+
+ static Vector2 DryNear(Vector2 c, KitGround ground, float within, ref KitRandom rnd)
+ {
+ if (ground.Inside(c.x, c.y) && !ground.Water(c.x, c.y)) return c;
+ for (int i = 0; i < 64; i++)
+ {
+ float a = rnd.Range(0f, 2f * Mathf.PI), r = within * (i + 1) / 64f;
+ var p = c + new Vector2(Mathf.Cos(a), Mathf.Sin(a)) * r;
+ if (ground.Inside(p.x, p.y) && !ground.Water(p.x, p.y)) return p;
+ }
+ return c;
+ }
+
+ // ---- The 1948 localities (promo-villages) ---------------------------------------------------------------------
+
/// <summary>Which part of a settlement BuildOne places: only its landmark (the first passes: every game settlement's,
/// then every locality's, claims its heart before any houses), or only its houses (continuing the same random stream,
/// so a place draws as it would in one pass).</summary>
enum Phase { Landmark, Houses }
+ /// <summary>A 1948 locality's landmark or houses (promo-villages): random spots over its disc, its archetype's buildings,
+ /// clear of the grid's edge midpoints. The 25 game settlements use TownLandmarks and PlaceHouses (towns round 2).</summary>
static int BuildOne(Settlement s, Vector2 centre, KitGround ground, KitMesh km, Lots lots, Phase phase, ref KitRandom rnd, int landmarksBefore,
HashSet<string>? ignoreCellsOf)
{
@@ -318,7 +891,7 @@ namespace Statecraft.Game.Map.Kits
+ WaterTower(s.Id, heart + new Vector2(R * 0.35f, 0f), ground, km, lots);
switch (arch)
{
- case Archetype.OldTown: return OldTownLandmarks(s, heart, ground, km, lots, ref rnd);
+ case Archetype.OldTown: return Mosque(s.Id, heart, ground, km, lots, ref rnd, 1.2f); // no locality is an old town today
case Archetype.ArabTown:
float size = s.Type == "village" ? 0.8f : 1f;
switch (Localities.LandmarkOf(s.Id) ?? Landmark.Mosque)
@@ -346,12 +919,7 @@ namespace Statecraft.Game.Map.Kits
return Mathf.Clamp(Mathf.RoundToInt(area * share / lot), 6, 900);
}
- /// <summary>The street grid's angle per town (Tel Aviv's Geddes plan runs about 20 degrees off north, parallel to the
- /// 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; }
-
+ /// <summary>A locality's building, by archetype (promo-villages).</summary>
static Spec Pick(Archetype arch, float t, ref KitRandom rnd, float m)
{
float w, d; int storeys;
@@ -387,15 +955,9 @@ namespace Statecraft.Game.Map.Kits
};
}
- // sRGB palettes (promo 03: white and cream city, honey stone Jaffa, tan villages, terracotta roofs).
- static Color32 C(float r, float g, float b) => new Color32((byte)(r * 255), (byte)(g * 255), (byte)(b * 255), 255);
- static Color32 Jitter(Color32 c, ref KitRandom rnd, float amount)
- {
- float k = 1f + rnd.Range(-amount, amount), warm = rnd.Range(-amount, amount) * 0.5f;
- return C(Mathf.Clamp01(c.r / 255f * k * (1 + warm)), Mathf.Clamp01(c.g / 255f * k), Mathf.Clamp01(c.b / 255f * k * (1 - warm)));
- }
-
- static void Emit(Archetype arch, Vector2 p, float yaw, Spec b, KitGround ground, KitMesh km, ref KitRandom rnd)
+ /// <summary>Draws a locality's building (promo-villages).</summary>
+ /// <returns>The wall colour (the census records it for a town's fallback houses, #317).</returns>
+ static Color32 Emit(Archetype arch, Vector2 p, float yaw, Spec b, KitGround ground, KitMesh km, ref KitRandom rnd)
{
float m = KitScale.For(arch);
var (bottom, top) = GroundSpan(p, yaw, b.w, b.d, ground, m);
@@ -422,7 +984,7 @@ namespace Statecraft.Game.Map.Kits
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);
}
- break;
+ return wall;
}
case Archetype.OldTown:
{
@@ -431,7 +993,7 @@ namespace Statecraft.Game.Map.Kits
km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, b.h, wall, roof, Facade.Stone, m);
if (rnd.Chance(0.22f)) km.Dome(p.x, p.y, top + b.h - 1f, Mathf.Min(b.w, b.d) * 0.33f, Jitter(C(0.88f, 0.84f, 0.76f), ref rnd, 0.05f));
else if (rnd.Chance(0.03f)) km.Pyramid(p.x, p.y, yaw, b.w * 1.04f, b.d * 1.04f, top + b.h, 2.2f * m, Jitter(C(0.70f, 0.33f, 0.22f), ref rnd, 0.06f));
- break;
+ return wall;
}
case Archetype.ArabTown:
{
@@ -439,7 +1001,7 @@ namespace Statecraft.Game.Map.Kits
var roof = Jitter(C(0.84f, 0.75f, 0.59f), ref rnd, 0.06f);
km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, b.h, wall, roof, Facade.Village, m);
if (rnd.Chance(0.10f)) km.Dome(p.x, p.y, top + b.h - 1f, Mathf.Min(b.w, b.d) * 0.3f, roof);
- break;
+ return wall;
}
default:
{
@@ -447,137 +1009,11 @@ namespace Statecraft.Game.Map.Kits
var roof = Jitter(C(0.74f, 0.31f, 0.20f), ref rnd, 0.08f);
km.Box(p.x, p.y, yaw, b.w, b.d, bottom, top, b.h, wall, roof, Facade.Village, m, roofed: true);
km.Gable(p.x, p.y, yaw, b.w, b.d, top + b.h, Mathf.Min(b.w, b.d) * 0.42f, roof, wall);
- break;
+ return wall;
}
}
}
- /// <summary>Wall bottom (sunk 2 m below the lowest corner, so a house on a slope stands on a plinth, not on air) and the
- /// ground level the walls rise from (the highest corner, so the slope never buries a storey).</summary>
- static (float bottom, float ground) GroundSpan(Vector2 p, float yawDeg, float w, float d, KitGround ground, float m)
- {
- float a = yawDeg * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);
- float lo = float.MaxValue, hi = float.MinValue;
- for (int i = 0; i < 5; i++)
- {
- float u = i == 4 ? 0 : ((i & 1) == 0 ? -0.5f : 0.5f) * w, v = i == 4 ? 0 : ((i & 2) == 0 ? -0.5f : 0.5f) * d;
- float y = ground.Y(p.x + u * ca - v * sa, p.y + u * sa + v * ca);
- lo = Mathf.Min(lo, y); hi = Mathf.Max(hi, y);
- }
- return (lo - 2f * m, hi);
- }
-
- static Vector2 DryNear(Vector2 c, KitGround ground, float within, ref KitRandom rnd)
- {
- if (ground.Inside(c.x, c.y) && !ground.Water(c.x, c.y)) return c;
- for (int i = 0; i < 64; i++)
- {
- float a = rnd.Range(0f, 2f * Mathf.PI), r = within * (i + 1) / 64f;
- var p = c + new Vector2(Mathf.Cos(a), Mathf.Sin(a)) * r;
- if (ground.Inside(p.x, p.y) && !ground.Water(p.x, p.y)) return p;
- }
- return c;
- }
-
- /// <summary>Jaffa: the clock tower (1903-06) by the old town's gate, the Mahmoudiya mosque's minaret and dome, and a
- /// church belfry above the harbour; the other old towns get a mosque.</summary>
- static int OldTownLandmarks(Settlement s, Vector2 heart, KitGround ground, KitMesh km, Lots lots, ref KitRandom rnd)
- {
- float m = KitScale.Landmarks;
- int n = Mosque(s.Id, heart + new Vector2(-5f * m, 6f * m), ground, km, lots, ref rnd, 1.2f);
- if (s.Id == "jaffa")
- {
- var stone = C(0.86f, 0.76f, 0.57f);
- if (!Claim(lots, heart + new Vector2(14f * m, 4f * m), 4.5f * m, s.Id, ground, out var p)) return n;
- float y = ground.Y(p.x, p.y);
- km.Box(p.x, p.y, 15f, 5f * m, 5f * m, y - 2f * m, y, 24f * m, stone, stone, Facade.Stone, m, roofed: true);
- km.Box(p.x, p.y, 15f, 4f * m, 4f * m, y + 24f * m, y + 24f * m, 4f * m, C(0.90f, 0.82f, 0.64f), stone, Facade.Plain, m, roofed: true);
- km.Pyramid(p.x, p.y, 15f, 4.4f * m, 4.4f * m, y + 28f * m, 3.5f * m, C(0.55f, 0.47f, 0.40f));
- n++;
- if (!Church(s.Id, heart + new Vector2(-10f * m, -12f * m), ground, km, lots, 1f)) return n;
- n += 1 + Port(heart, ground, km, ref rnd);
- }
- return n;
- }
-
- /// <summary>Jaffa's harbour, as promo 03 draws it: a stone breakwater curving out to sea from the shore west of the
- /// old town, a lighthouse at its head, and a few sailing boats inside it.</summary>
- static int Port(Vector2 heart, KitGround ground, KitMesh km, ref KitRandom rnd)
- {
- float m = KitScale.Landmarks;
- var shore = heart;
- for (int i = 0; i < 120 && !ground.Water(shore.x, shore.y); i++) shore.x -= 50f;
- if (!ground.Water(shore.x, shore.y)) return 0;
- float sea = ground.Y(shore.x, shore.y);
- var stone = C(0.74f, 0.70f, 0.62f);
- // A quarter-circle arm: out to the west, then north.
- var c = shore + new Vector2(0f, 60f * m);
- float r = 60f * m;
- Vector2 prev = c + new Vector2(0f, -r);
- for (int k = 1; k <= 9; k++)
- {
- float a = -Mathf.PI * 0.5f - k * (Mathf.PI * 0.5f / 9f);
- var cur = c + new Vector2(Mathf.Cos(a), Mathf.Sin(a)) * r;
- var mid = (prev + cur) * 0.5f; var dir = cur - prev;
- float yaw = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
- km.Box(mid.x, mid.y, yaw, dir.magnitude * 1.08f, 5f * m, sea - 2f * m, sea, 2.2f * m, stone, stone, Facade.Plain, m);
- prev = cur;
- }
- // The lighthouse at the arm's head.
- var white = C(0.93f, 0.92f, 0.88f);
- km.Shaft(new Vector3(prev.x, sea, prev.y), new Vector3(prev.x, sea + 16f * m, prev.y), 2.0f * m, 1.5f * m, white, 10);
- km.Shaft(new Vector3(prev.x, sea + 16f * m, prev.y), new Vector3(prev.x, sea + 19f * m, prev.y), 1.6f * m, 1.6f * m, C(0.30f, 0.32f, 0.30f), 10);
- km.Cone(new Vector3(prev.x, sea + 19f * m, prev.y), 1.9f * m, 2.4f * m, C(0.68f, 0.24f, 0.18f), 10);
- // Sailing boats in and off the harbour.
- int boats = 0;
- for (int i = 0; i < 12 && boats < 5; i++)
- {
- var b = c + new Vector2(rnd.Range(-1.6f, 0.2f) * r, rnd.Range(-1.4f, 0.4f) * r);
- if (!ground.Water(b.x, b.y) || ground.Water(b.x + 40f * m, b.y) == false) continue;
- float yaw = rnd.Range(0f, 360f), L = rnd.Range(9f, 14f) * m;
- km.Box(b.x, b.y, yaw, L, L * 0.32f, sea - 1f * m, sea, 1.6f * m, C(0.42f, 0.30f, 0.20f), C(0.55f, 0.42f, 0.30f), Facade.Plain, m);
- float a = yaw * Mathf.Deg2Rad; var fwd = new Vector3(Mathf.Cos(a), 0f, Mathf.Sin(a));
- var mast = new Vector3(b.x, sea + 1.6f * m, b.y);
- km.Shaft(mast, mast + Vector3.up * L * 0.9f, 0.18f * m, 0.12f * m, C(0.35f, 0.28f, 0.20f), 4);
- var sail = C(0.95f, 0.93f, 0.86f);
- var s0 = mast + Vector3.up * L * 0.85f; var s1 = mast + Vector3.up * 0.4f * m; var s2 = mast + fwd * (-L * 0.45f) + Vector3.up * 0.4f * m;
- km.Triangle(s0, s1, s2, sail); km.Triangle(s0, s2, s1, sail);
- boats++;
- }
- return 1;
- }
-
- static int Mosque(string owner, Vector2 want, KitGround ground, KitMesh km, Lots lots, ref KitRandom rnd, float size)
- {
- float m = KitScale.Landmarks * size;
- if (!Claim(lots, want, 11f * m, owner, ground, out var p)) return 0; // the lot covers the minaret too
- float y = ground.Y(p.x, p.y);
- var stone = Jitter(C(0.87f, 0.80f, 0.66f), ref rnd, 0.03f);
- km.Box(p.x, p.y, 0f, 14f * m, 14f * m, y - 2f * m, y, 7f * m, stone, stone, Facade.Stone, KitScale.Landmarks);
- km.Dome(p.x, p.y, y + 7f * m - 0.5f * m, 5.5f * m, C(0.80f, 0.80f, 0.76f));
- float mx = p.x + 8.5f * m, mz = p.y - 6f * m;
- float my = ground.Y(mx, mz);
- km.Shaft(new Vector3(mx, my - 2f * m, mz), new Vector3(mx, my + 26f * m, mz), 1.6f * m, 1.35f * m, stone, 8);
- km.Shaft(new Vector3(mx, my + 20f * m, mz), new Vector3(mx, my + 21f * m, mz), 2.1f * m, 2.1f * m, stone, 8); // the balcony
- km.Cone(new Vector3(mx, my + 26f * m, mz), 1.5f * m, 4.5f * m, C(0.62f, 0.62f, 0.58f), 8);
- return 1;
- }
-
- /// <summary>A stone church with a gabled nave and a belfry topped by a pyramid roof (Jaffa's above its harbour, and the
- /// Christian-majority 1948 localities' at their heart); false, and nothing built, when no free dry spot is near.</summary>
- static bool Church(string owner, Vector2 want, KitGround ground, KitMesh km, Lots lots, float size)
- {
- float m = KitScale.Landmarks * size;
- var stone = C(0.86f, 0.76f, 0.57f);
- if (!Claim(lots, want, 10f * m, owner, ground, out var q)) return false;
- float yq = ground.Y(q.x, q.y);
- km.Box(q.x, q.y, 0f, 9f * m, 18f * m, yq - 2f * m, yq, 12f * m, stone, stone, Facade.Stone, m, roofed: true);
- km.Box(q.x, q.y + 7f * m, 0f, 4.5f * m, 4.5f * m, yq + 12f * m, yq + 12f * m, 14f * m, stone, stone, Facade.Stone, m, roofed: true);
- km.Pyramid(q.x, q.y + 7f * m, 0f, 4.8f * m, 4.8f * m, yq + 26f * m, 6f * m, C(0.60f, 0.52f, 0.44f));
- km.Gable(q.x, q.y, 0f, 9f * m, 18f * m, yq + 12f * m, 4f * m, C(0.66f, 0.34f, 0.24f), stone);
- return true;
- }
-
/// <summary>A sub-district's Bedouin camps (owner ruling 2026-10-11: a light scatter sized by the sourced total, no named
/// points): each camp, seeded by the sub-district and its number, takes a random spot in one of the area's hexes that
/// is dry, gentle and outside every town's footprint, and pitches two to four black goat-hair tents in a loose row
@@ -635,23 +1071,6 @@ namespace Statecraft.Game.Map.Kits
}
return (camps, tents);
}
-
- static int WaterTower(string owner, Vector2 want, KitGround ground, KitMesh km, Lots lots)
- {
- float m = KitScale.Houses;
- if (!Claim(lots, want, 4f * m, owner, ground, out var p)) return 0;
- float y = ground.Y(p.x, p.y);
- var concrete = C(0.82f, 0.80f, 0.76f);
- for (int i = 0; i < 4; i++)
- {
- float a = Mathf.PI * 0.5f * i + 0.6f;
- var b = new Vector3(p.x + Mathf.Cos(a) * 2.6f * m, y - 2f * m, p.y + Mathf.Sin(a) * 2.6f * m);
- km.Shaft(b, new Vector3(p.x + Mathf.Cos(a) * 1.8f * m, y + 9f * m, p.y + Mathf.Sin(a) * 1.8f * m), 0.35f * m, 0.3f * m, concrete, 4);
- }
- km.Shaft(new Vector3(p.x, y + 9f * m, p.y), new Vector3(p.x, y + 13.5f * m, p.y), 3f * m, 3f * m, concrete, 10);
- km.Cone(new Vector3(p.x, y + 13.5f * m, p.y), 3.1f * m, 1.2f * m, C(0.66f, 0.64f, 0.60f), 10);
- return 1;
- }
}
/// <summary>The symbolic scale per class (owner ruling 2026-10-11, superseding the 10-25x ruling: match promo 03's
diff --git a/unity/Assets/Scripts/Map/Kits/Vegetation.cs b/unity/Assets/Scripts/Map/Kits/Vegetation.cs
index f7b98b9b1..1a23e3718 100644
--- a/unity/Assets/Scripts/Map/Kits/Vegetation.cs
+++ b/unity/Assets/Scripts/Map/Kits/Vegetation.cs
@@ -96,15 +96,18 @@ namespace Statecraft.Game.Map.Kits
float ks = s / KitScale.CountReference;
void Add(TreeKind k, float x, float z, ref KitRandom rnd, float size = 1f, float yawDeg = float.NaN)
{
+ // The tree's own numbers first, whether it stands or not: a tree left out for a lot or a route then never
+ // shifts the trees drawn after it (towns round 2: a town's new lots no longer reshuffle every grove).
+ var scale = s * size * rnd.Range(0.85f, 1.15f);
+ float spin = rnd.Range(0f, 360f), stretch = rnd.Range(0.9f, 1.1f);
// No crown reaches into a building's or landmark's lot (integration bug B9: palms through Tel Aviv's roofs,
// grove rows through blocks).
// Nor into a railway's or road's corridor (the routes run through the groves otherwise).
float crown = CrownRadiusM(k) * s * size * 1.15f;
if (ground.OnLot(x, z, crown) || ground.OnRoute(new Vector2(x, z), crown)) return;
float y = ground.Y(x, z);
- var scale = s * size * rnd.Range(0.85f, 1.15f);
- float yaw = float.IsNaN(yawDeg) ? rnd.Range(0f, 360f) : yawDeg;
- trees.Add((k, Matrix4x4.TRS(new Vector3(x, y, z), Quaternion.Euler(0, yaw, 0), new Vector3(scale, scale * rnd.Range(0.9f, 1.1f), scale))));
+ float yaw = float.IsNaN(yawDeg) ? spin : yawDeg;
+ trees.Add((k, Matrix4x4.TRS(new Vector3(x, y, z), Quaternion.Euler(0, yaw, 0), new Vector3(scale, scale * stretch, scale))));
}
// Citrus groves round the coastal-plain towns: rectangular blocks of rows, each grove on its own angle.
diff --git a/unity/Assets/Tests/EditMode/GradeTests.cs b/unity/Assets/Tests/EditMode/GradeTests.cs
index f0438b02a..52bce3890 100644
--- a/unity/Assets/Tests/EditMode/GradeTests.cs
+++ b/unity/Assets/Tests/EditMode/GradeTests.cs
@@ -95,6 +95,10 @@ public class GradeTests
yield return null;
var cam = Camera.main;
VisualToggles.Set("tiltshift", false); // the band is a thin line: measured sharp, as LightingTests measures detail
+ // The ring against the land's graded colour, not against a grove: a row of crowns (100x trees, far taller than the
+ // band's 30 m clearance) can stand on the sampled edge, and where a row ends moves whenever a town's lots change
+ // which trees stand (towns round 2).
+ VisualToggles.Set("trees", false);
foreach (var pose in PromoPose.All)
{
pose.Apply(rig, map.Frame); rig.TopInset = 0f; rig.Apply();
@@ -124,6 +128,7 @@ public class GradeTests
yield return null;
var cam = Camera.main;
VisualToggles.Set("tiltshift", false); // the band is a thin line: measured sharp
+ VisualToggles.Set("trees", false); // the ring against the land, not a grove (TheSelectedHexStillStandsOutOnGradedLand)
PromoPose.Gameplay03.Apply(rig, map.Frame); rig.TopInset = 0f; rig.Apply();
var (band, land) = SelectNear(map, 34.86, 32.00);
var sea = map.Frame.ToWorld(34.66, 32.00, 0); sea.y = map.Terrain.SampleHeight(sea);
diff --git a/unity/Assets/Tests/EditMode/KitTests.cs b/unity/Assets/Tests/EditMode/KitTests.cs
index efaac4c65..e4aed4109 100644
--- a/unity/Assets/Tests/EditMode/KitTests.cs
+++ b/unity/Assets/Tests/EditMode/KitTests.cs
@@ -321,6 +321,100 @@ public class KitTests
}
}
+ /// <summary>#317: a lake hex is not all water. Tiberias's shore (35.530 E, 32.7944 N, about 114 m below sea level) lies in
+ /// a lake hex but 100 m above the Sea of Galilee's surface (about -214 m), and it is land; the open lake (35.58 E, 32.80
+ /// N) is water. The lake's water is told as tools/terrain_bake.py tells it for the drawn water.</summary>
+ [Test]
+ public void TheLakeIsItsWaterNotItsWholeHex()
+ {
+ var map = OpenMap();
+ var g = Ground(map);
+ var shore = map.Frame.ToWorld(35.530, 32.7944, 0); var lake = map.Frame.ToWorld(35.58, 32.80, 0);
+ TestContext.WriteLine($"shore: {g.Biome(shore.x, shore.z)} {g.ElevM(shore.x, shore.z):0.0} m; lake: {g.Biome(lake.x, lake.z)} {g.ElevM(lake.x, lake.z):0.0} m");
+ Assert.AreEqual("lake", g.Biome(shore.x, shore.z), "the shore point lies in a lake hex");
+ Assert.Greater(g.ElevM(shore.x, shore.z), g.ElevM(lake.x, lake.z) + 50f, "the shore point stands well above the lake");
+ Assert.IsFalse(g.Water(shore.x, shore.z), "Tiberias's shore in the lake hex is land");
+ Assert.AreEqual("lake", g.Biome(lake.x, lake.z));
+ Assert.IsTrue(g.Water(lake.x, lake.z), "the Sea of Galilee is water");
+ }
+
+ /// <summary>#317: nothing stands in a lake's drawn water. Read from coast.png itself (the file the water shader samples,
+ /// decoded here because the import is not CPU-readable): no tree trunk and no building's or landmark's lot centre in the
+ /// rift (a lake hex, or ground below MapBuilder.LakeBelowM) lies where the drawn water covers the ground (coast below
+ /// 0.5). A first version of the lake test put a palm in the Kinneret by Ghuweir Abu Shusha, in a shore hex of another
+ /// biome.</summary>
+ [Test]
+ public void NothingStandsInALakesDrawnWater()
+ {
+ var map = OpenMap();
+ var coast = new Texture2D(2, 2);
+ try
+ {
+ Assert.IsTrue(coast.LoadImage(System.IO.File.ReadAllBytes(System.IO.Path.Combine(Application.dataPath, "Textures/Map/coast.png"))));
+ var g = Ground(map);
+ foreach (var (line, half) in Corridors(map)) g.AddCorridor(line, half);
+ var doc = LoadLocalities(map);
+ var locs = doc.Places.Select(p => p.Settlement).ToList();
+ var built = SettlementKits.Build(map.Settlements, locs, doc.Encampments, g);
+ foreach (var k in built.Towns) Object.DestroyImmediate(k.mesh);
+ foreach (var t in built.Tiles) Object.DestroyImmediate(t.mesh);
+ foreach (var l in built.Claimed) g.Lots.Add((l.centre, l.radius));
+ var trees = Vegetation.Plant(map.Settlements.Concat(locs).ToList(), g);
+ bool Wet(float x, float z) => coast.GetPixelBilinear(x / g.Width, z / g.Length).r < 0.5f;
+ var bad = new List<string>();
+ int checkedN = 0;
+ bool Rift(float x, float z) => g.Biome(x, z) == "lake" || g.ElevM(x, z) < MapBuilder.LakeBelowM;
+ foreach (var l in built.Claimed)
+ if (Rift(l.centre.x, l.centre.y)) { checkedN++; if (Wet(l.centre.x, l.centre.y)) bad.Add($"{l.id} lot at {l.centre}"); }
+ foreach (var (kind, m) in trees)
+ {
+ Vector3 p = m.GetColumn(3);
+ if (!Rift(p.x, p.z)) continue;
+ checkedN++;
+ if (Wet(p.x, p.z)) bad.Add($"{kind} tree at ({p.x:0}, {p.z:0})");
+ }
+ TestContext.WriteLine($"{checkedN} lots and trees in the rift checked against the drawn water");
+ CollectionAssert.IsEmpty(bad.Take(20), $"{bad.Count} in the drawn water");
+ Assert.Greater(checkedN, 20, "the rift's shores hold lots and trees");
+ }
+ finally { Object.DestroyImmediate(coast); }
+ }
+
+ /// <summary>#317, review of #339 (F2): the small towns' fallback houses take only ground no other place builds on. With
+ /// the fallback on, every lot every place claims (the towns', the 1948 localities' and the camps') is the same, in the
+ /// same order, as with it off; the fallback's lots only follow them, and each belongs to a game town.</summary>
+ [Test]
+ public void TheSmallTownFloorMovesNoOtherPlace()
+ {
+ var map = OpenMap();
+ var doc = LoadLocalities(map);
+ var locs = doc.Places.Select(p => p.Settlement).ToList();
+ var corridors = Corridors(map);
+ SettlementKits.Result Once(bool scatter)
+ {
+ SettlementKits.SmallTownScatter = scatter;
+ try
+ {
+ var g = Ground(map);
+ foreach (var (line, half) in corridors) g.AddCorridor(line, half);
+ var r = SettlementKits.Build(map.Settlements, locs, doc.Encampments, g);
+ foreach (var k in r.Towns) Object.DestroyImmediate(k.mesh);
+ foreach (var t in r.Tiles) Object.DestroyImmediate(t.mesh);
+ return r;
+ }
+ finally { SettlementKits.SmallTownScatter = true; }
+ }
+ var off = Once(false); var on = Once(true);
+ Assert.Greater(on.Claimed.Count, off.Claimed.Count, "the fallback placed houses");
+ for (int i = 0; i < off.Claimed.Count; i++)
+ Assert.AreEqual(off.Claimed[i], on.Claimed[i], $"lot #{i} ({off.Claimed[i].id}) moved with the fallback on");
+ var towns = new HashSet<string>(map.Settlements.Select(s => s.Id));
+ var extra = on.Claimed.Skip(off.Claimed.Count).Select(l => l.id).ToList();
+ CollectionAssert.IsEmpty(extra.Where(id => !towns.Contains(id)).ToList(), "a fallback lot owned by a place that is not a game town");
+ Assert.AreEqual((off.Camps, off.Tents, off.LocalityBuildings), (on.Camps, on.Tents, on.LocalityBuildings));
+ TestContext.WriteLine($"{extra.Count} fallback houses in {extra.Distinct().Count()} towns: {string.Join(" ", extra.Distinct())}");
+ }
+
/// <summary>The boot reads the baked runtime form (tools/localities_bake.py; pytest fails a stale bake). It yields the same
/// rows as the sourced YAML: ids, 1948 and today's names (English and Hebrew), coordinates, type, landmark, the mixed
/// flag, population and how many sources each row cites; and the same camp areas.</summary>
diff --git a/unity/Assets/Tests/EditMode/TownCensusTests.cs b/unity/Assets/Tests/EditMode/TownCensusTests.cs
new file mode 100644
index 000000000..fa8951bd3
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/TownCensusTests.cs
@@ -0,0 +1,278 @@
+#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>Towns round 2 (docs/visual-v1.md, "Towns round 2"): a census of what each town's kit places (buildings,
+/// landmarks, the share of its land the buildings cover, heights and wall colours), logged as one CENSUS line per town.</summary>
+public class TownCensusTests
+{
+ [TearDown]
+ public void Restore()
+ {
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ VisualToggles.Clear();
+ KitScale.Reset();
+ }
+
+ internal sealed class Row
+ {
+ public string Id = ""; public int Buildings, Wings; public List<string> Landmarks = new List<string>();
+ public float Radius, Coverage, CoreCoverage; public int LandCells, CoreCells;
+ public float HMin, HMedian, HMax, HSpread; public int Colours; public Color MeanWall;
+ public override string ToString() =>
+ $"CENSUS {Id} R={Radius:0} buildings={Buildings} wings={Wings} landmarks={Landmarks.Count}[{string.Join(",", Landmarks)}] " +
+ $"coverage={Coverage:P1} core={CoreCoverage:P1} land_cells={LandCells} h_min={HMin:0} h_med={HMedian:0} h_max={HMax:0} " +
+ $"h_cv={HSpread:0.00} colours={Colours} wall=({MeanWall.r:0.00},{MeanWall.g:0.00},{MeanWall.b:0.00})";
+ }
+
+ /// <summary>The census of one build: per town, from SettlementKits.Build's list of what it placed. Coverage is the
+ /// share of the town's own land (its footprint disc, on land, in its cell: the cells the kit may build in) under a
+ /// building's or landmark's footprint, sampled every <paramref name="cellM"/> m; "core" is the inner half radius.</summary>
+ internal static List<Row> Census(MapScene map, out List<SettlementKits.Placed> placed, float cellM = 100f) => Census(map, out placed, out _, cellM);
+
+ internal static List<Row> Census(MapScene map, out List<SettlementKits.Placed> placed, out KitGround g, float cellM = 100f)
+ {
+ g = new KitGround(map.Terrain, map.Frame, map.Hexes, HeightmapLoader.Load(Statecraft.Game.Paths.StreamingMap).meta.elev_min_m);
+ // The corridors MapScene.Build gives the kits: the routes and the units' clearings.
+ foreach (var c in map.RouteCorridors) g.AddCorridor(c.line, c.halfWidth);
+ foreach (var c in map.UnitClearings) g.AddCorridor(new List<Vector2> { c.centre, c.centre + Vector2.right }, c.radius);
+ // With the 1948 localities, as the map builds them (their landmarks claim their hearts before any town's houses).
+ var localities = map.Localities.Select(p => p.Settlement).ToList();
+ var built = SettlementKits.Build(map.Settlements, localities, new List<Localities.Area>(), g, out placed);
+ foreach (var k in built.Towns) Object.DestroyImmediate(k.mesh);
+ foreach (var t in built.Tiles) Object.DestroyImmediate(t.mesh);
+ var rows = new List<Row>();
+ var towns = new HashSet<string>(map.Settlements.Select(t => t.Id));
+ foreach (var s in map.Settlements)
+ {
+ var w = map.Frame.ToWorld(s.Lon, s.Lat, 0); var centre = new Vector2(w.x, w.z);
+ float R = SettlementKits.FootprintRadiusM(s, g.HexSizeM);
+ var mine = placed.Where(p => p.Id == s.Id && !Aggregate(p.Kind) && !p.InSea).ToList();
+ var row = new Row { Id = s.Id, Radius = R, Buildings = mine.Count(p => p.Kind == "building"), Wings = mine.Count(p => p.Kind == "wing") };
+ row.Landmarks = placed.Where(p => p.Id == s.Id && p.Kind != "building" && p.Kind != "wing").Select(p => p.Kind).ToList();
+ int n = Mathf.CeilToInt(R / cellM);
+ int covered = 0, coreCovered = 0;
+ for (int j = -n; j <= n; j++)
+ for (int i = -n; i <= n; i++)
+ {
+ var p = centre + new Vector2(i, j) * cellM;
+ float d = (p - centre).magnitude / R;
+ if (d > 1f || g.Water(p.x, p.y)) continue;
+ bool own = true;
+ // Its cell among the game settlements (a town's houses ignore the 1948 localities' cells).
+ foreach (var f in g.Footprints) if (f.id != s.Id && towns.Contains(f.id) && (p - f.centre).magnitude / f.radius < d) { own = false; break; }
+ if (!own) continue;
+ bool hit = mine.Any(b => Inside(p, b));
+ row.LandCells++; if (hit) covered++;
+ if (d <= 0.5f) { row.CoreCells++; if (hit) coreCovered++; }
+ }
+ row.Coverage = covered / (float)Mathf.Max(1, row.LandCells);
+ row.CoreCoverage = coreCovered / (float)Mathf.Max(1, row.CoreCells);
+ var hs = mine.Where(p => p.Kind == "building").Select(p => p.H).OrderBy(h => h).ToList();
+ if (hs.Count > 0)
+ {
+ row.HMin = hs[0]; row.HMax = hs[hs.Count - 1]; row.HMedian = hs[hs.Count / 2];
+ float mean = hs.Average(); row.HSpread = Mathf.Sqrt(hs.Average(h => (h - mean) * (h - mean))) / mean;
+ var walls = mine.Where(p => p.Kind == "building").Select(p => p.Wall).ToList();
+ row.Colours = walls.Select(c => (c.r >> 4, c.g >> 4, c.b >> 4)).Distinct().Count();
+ row.MeanWall = new Color((float)walls.Average(c => c.r) / 255f, (float)walls.Average(c => c.g) / 255f, (float)walls.Average(c => c.b) / 255f);
+ }
+ rows.Add(row);
+ }
+ return rows;
+ }
+
+ /// <summary>A census entry that names a group (the Old City's walls, the German Colony) rather than one footprint.</summary>
+ static bool Aggregate(string kind) => kind == "walls" || kind == "german_colony";
+
+ static bool Inside(Vector2 p, SettlementKits.Placed b)
+ {
+ float a = b.Yaw * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);
+ var d = p - b.C;
+ float u = d.x * ca + d.y * sa, v = -d.x * sa + d.y * ca;
+ return Mathf.Abs(u) <= b.W * 0.5f && Mathf.Abs(v) <= b.D * 0.5f;
+ }
+
+ static MapScene OpenMap()
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var map = Object.FindFirstObjectByType<MapScene>(); map.Build();
+ return map;
+ }
+
+ [Test]
+ public void TheCensusIsLogged()
+ {
+ var map = OpenMap();
+ var rows = Census(map, out var placed);
+ foreach (var r in rows) { TestContext.WriteLine(r); Debug.Log(r); }
+ Debug.Log($"CENSUS total buildings={rows.Sum(r => r.Buildings)} landmarks={rows.Sum(r => r.Landmarks.Count)} placed={placed.Count} {map.KitStats}");
+ Assert.AreEqual(map.Settlements.Count, rows.Count);
+ }
+
+ /// <summary>The same map draws the same towns: every placement, in order, with its size.</summary>
+ [Test]
+ public void EveryBuildPlacesTheSameTowns()
+ {
+ var map = OpenMap();
+ Census(map, out var a); Census(map, out var b);
+ Assert.AreEqual(a.Count, b.Count);
+ for (int i = 0; i < a.Count; i++)
+ {
+ Assert.AreEqual(a[i].Id, b[i].Id, $"#{i}"); Assert.AreEqual(a[i].Kind, b[i].Kind, $"#{i}");
+ Assert.AreEqual(a[i].C, b[i].C, $"#{i} {a[i].Id}"); Assert.AreEqual(a[i].W, b[i].W); Assert.AreEqual(a[i].D, b[i].D); Assert.AreEqual(a[i].H, b[i].H);
+ }
+ }
+
+ /// <summary>Each city's landmarks are built (docs/visual-v1.md, "Towns round 2"); every other Arab or old town has its
+ /// mosque, and every moshava, kibbutz and moshav its water tower.</summary>
+ [Test]
+ public void EveryTownHasItsLandmarks()
+ {
+ var map = OpenMap();
+ Census(map, out var placed);
+ var want = new Dictionary<string, string[]>
+ {
+ ["tel_aviv"] = new[] { "port", "warehouse" },
+ ["jaffa"] = new[] { "mosque", "clock_tower", "church", "lighthouse", "port" },
+ ["haifa"] = new[] { "port", "warehouse", "german_colony" },
+ ["jerusalem"] = new[] { "walls", "gate", "citadel", "haram", "dome_of_the_rock", "al_aqsa" },
+ ["ramla"] = new[] { "mosque", "white_tower" },
+ };
+ var missing = new List<string>();
+ foreach (var s in map.Settlements)
+ {
+ var kinds = new HashSet<string>(placed.Where(p => p.Id == s.Id).Select(p => p.Kind));
+ var expect = want.TryGetValue(s.Id, out var w) ? w
+ : SettlementKits.ArchetypeOf(s) == Archetype.Moshava ? new[] { "water_tower" }
+ : SettlementKits.ArchetypeOf(s) == Archetype.WhiteCity ? new string[0] : new[] { "mosque" };
+ foreach (var k in expect) if (!kinds.Contains(k)) missing.Add($"{s.Id}: {k}");
+ }
+ CollectionAssert.IsEmpty(missing, "landmarks left out");
+ Assert.GreaterOrEqual(placed.Count(p => p.Id == "jerusalem" && p.Kind == "gate"), 3, "most of the Old City's gates stand");
+ }
+
+ /// <summary>No building or landmark stands on a railway or a road (their corridors, RouteLayer.Corridors, and the units'
+ /// clearings), and none stands in the sea: a building's centre and four corners are dry. Only harbour works (the
+ /// breakwaters) stand in the water.</summary>
+ [Test]
+ public void NoBuildingStandsOnARouteOrInTheSea()
+ {
+ var map = OpenMap();
+ Census(map, out var placed, out var g);
+ var bad = new List<string>();
+ foreach (var p in placed)
+ {
+ if (p.InSea || Aggregate(p.Kind)) continue;
+ bool building = p.Kind == "building" || p.Kind == "wing";
+ float reach = building ? 0.5f * Mathf.Sqrt(p.W * p.W + p.D * p.D) : 0.5f * Mathf.Min(p.W, p.D);
+ if (p.Kind == "wing") reach = 0.5f * Mathf.Min(p.W, p.D); // inside its block's plot, which was checked whole
+ if (g.OnRoute(p.C, reach)) bad.Add($"{p.Id} {p.Kind} on a route at {p.C}");
+ if (g.Water(p.C.x, p.C.y)) bad.Add($"{p.Id} {p.Kind} in the sea at {p.C}");
+ if (!building) continue;
+ float a = p.Yaw * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);
+ for (int i = 0; i < 4; i++)
+ {
+ float u = ((i & 1) == 0 ? -0.5f : 0.5f) * p.W, v = ((i & 2) == 0 ? -0.5f : 0.5f) * p.D;
+ if (g.Water(p.C.x + u * ca - v * sa, p.C.y + u * sa + v * ca)) { bad.Add($"{p.Id} {p.Kind} corner in the sea at {p.C}"); break; }
+ }
+ }
+ TestContext.WriteLine($"{placed.Count} placements checked");
+ CollectionAssert.IsEmpty(bad.Take(20), $"{bad.Count} placements on a route or in the sea");
+ }
+
+ /// <summary>Every town's houses on main before towns round 2 (main a3202ad, with the 1948 localities: this census), the
+ /// floor no town may fall below (#317). Wings are not counted.</summary>
+ internal static readonly Dictionary<string, int> MainBuildings = new Dictionary<string, int>
+ {
+ ["acre"] = 2, ["beersheba"] = 5, ["degania_alef"] = 1, ["ein_harod"] = 1, ["gaza"] = 15, ["hadera"] = 1, ["haifa"] = 30,
+ ["hanita"] = 2, ["jaffa"] = 15, ["jerusalem"] = 70, ["lod"] = 5, ["nahalal"] = 1, ["nazareth"] = 5, ["netanya"] = 2,
+ ["petah_tikva"] = 2, ["ramla"] = 5, ["rehovot"] = 3, ["revivim"] = 3, ["rishon_lezion"] = 2, ["rosh_pinna"] = 0,
+ ["safed"] = 5, ["tel_aviv"] = 36, ["tiberias"] = 3, ["yad_mordechai"] = 0, ["zikhron_yaakov"] = 2,
+ };
+
+ /// <summary>Review of towns round 2. No town draws fewer houses than main did (#317: on the 100x lattice a small town
+ /// has some 7 plots; Tiberias drew 0 against main's 3, Netanya 1 against 2, Beersheba 3 against 5, until the small-town
+ /// floor). The beach setback is the Mediterranean's (Degania on the Sea of Galilee), and Nahalal's ring reaches its
+ /// lattice's first ring of plots. No block stands taller than promo 03's tallest, eight storeys (60x: 1,584 m).</summary>
+ [Test]
+ public void SmallTownsKeepTheirHousesAndNoBlockOutgrowsThePromo()
+ {
+ var map = OpenMap();
+ var rows = Census(map, out var placed).ToDictionary(r => r.Id);
+ var bad = new List<string>();
+ CollectionAssert.AreEquivalent(MainBuildings.Keys, rows.Keys, "the floor lists every game town");
+ foreach (var kv in MainBuildings)
+ {
+ TestContext.WriteLine(rows[kv.Key]);
+ if (rows[kv.Key].Buildings < kv.Value) bad.Add($"{kv.Key}: {rows[kv.Key].Buildings} houses, main {kv.Value}");
+ }
+ foreach (var id in new[] { "tiberias", "rosh_pinna" })
+ if (rows[id].Buildings < 1) bad.Add(id + " builds no house");
+ float tallest = placed.Where(p => p.Kind == "building").Max(p => p.H);
+ if (tallest > 8f * 3.3f * KitScale.CityBlocks + 1f) bad.Add($"a block {tallest:0} m tall, over eight storeys");
+ CollectionAssert.IsEmpty(bad);
+ }
+
+ /// <summary>No two buildings of one town overlap (review of #339, F1: the small-town fallback tests every lot, #317).
+ /// Separating axes on the footprints, 1 m tolerance. Wings are left out: a wing shares its block's plot.</summary>
+ [Test]
+ public void NoTwoHousesOfATownOverlap()
+ {
+ var map = OpenMap();
+ Census(map, out var placed);
+ var b = placed.Where(p => p.Kind == "building").ToList();
+ var bad = new List<string>();
+ for (int i = 0; i < b.Count; i++)
+ for (int j = i + 1; j < b.Count; j++)
+ if (b[i].Id == b[j].Id && Overlap(b[i], b[j])) bad.Add($"{b[i].Id} at {b[i].C} and {b[j].C}");
+ TestContext.WriteLine($"{b.Count} buildings checked");
+ CollectionAssert.IsEmpty(bad.Take(20), $"{bad.Count} overlapping pairs");
+ }
+
+ static bool Overlap(SettlementKits.Placed a, SettlementKits.Placed b)
+ {
+ foreach (var yaw in new[] { a.Yaw, b.Yaw })
+ foreach (var ax in new[] { 0f, 90f })
+ {
+ float t = (yaw + ax) * Mathf.Deg2Rad; var n = new Vector2(Mathf.Cos(t), Mathf.Sin(t));
+ float Half(SettlementKits.Placed p)
+ {
+ float r = (p.Yaw - yaw - ax) * Mathf.Deg2Rad;
+ return 0.5f * (p.W * Mathf.Abs(Mathf.Cos(r)) + p.D * Mathf.Abs(Mathf.Sin(r)));
+ }
+ if (Mathf.Abs(Vector2.Dot(a.C - b.C, n)) >= Half(a) + Half(b) - 1f) return false;
+ }
+ return true;
+ }
+
+ /// <summary>The floors of the four cities' buildings and built cover (share of the town's own land under a building or
+ /// landmark, whole footprint and inner half radius). Towns round 2 measured them with the 1948 localities (docs/visual-v1.md,
+ /// "Towns round 2"): Tel Aviv 43 / 17.4% / 18.5%, Jaffa 33 / 32.6% / 31.9%, Haifa 45 / 21.0% / 20.6%, Jerusalem 110 /
+ /// 22.7% / 24.9%; main before it had 36, 15, 30 and 70 buildings. The building floors sit above main's counts, so a change
+ /// that thins a city back to round 1's sparse handful fails here; the cover floors are about 10% under the measure.</summary>
+ internal static readonly Dictionary<string, (int buildings, float all, float core)> Floors = new Dictionary<string, (int, float, float)>
+ {
+ ["tel_aviv"] = (40, 0.155f, 0.165f), ["jaffa"] = (28, 0.29f, 0.285f), ["haifa"] = (40, 0.19f, 0.185f), ["jerusalem"] = (95, 0.20f, 0.22f),
+ };
+
+ [Test]
+ public void TheCitiesCoverTheirGround()
+ {
+ var map = OpenMap();
+ var rows = Census(map, out _).ToDictionary(r => r.Id);
+ foreach (var kv in Floors)
+ {
+ var r = rows[kv.Key];
+ TestContext.WriteLine(r);
+ Assert.GreaterOrEqual(r.Buildings, kv.Value.buildings, kv.Key + ": buildings");
+ Assert.GreaterOrEqual(r.Coverage, kv.Value.all, kv.Key + ": built cover of the footprint");
+ Assert.GreaterOrEqual(r.CoreCoverage, kv.Value.core, kv.Key + ": built cover of the inner half");
+ }
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/TownCensusTests.cs.meta b/unity/Assets/Tests/EditMode/TownCensusTests.cs.meta
new file mode 100644
index 000000000..03e486cb5
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/TownCensusTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 0dc22b1318ba245bda72c4b091f8e68a
\ No newline at end of file