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: boats and a calmer open sea (refs #388) (#536)

Eyal Golan1187bcbe60c3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c886514e9..8b7b41a3e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -60,6 +60,7 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
text the direction of its own words (dates, money and names are still English, #55), and mirrors the layout: rows,
bars, the hemicycle, the option signs and End Turn's hourglass. English stays the default and has no visible switch.
A long Budget office name now wraps in its column, so no row is wider than the screen.
+- Map: boats and a calmer open sea (refs #388). Promo 03's white-sailed boats: 10 sailing boats off Jaffa, Tel Aviv, Bat Yam, Haifa, Acre and Gaza, and 7 craft moored in or off the harbours of Jaffa, Tel Aviv and Haifa (a small coastal steamer at anchor off Haifa), kept off the breakwaters and moles. Jaffa's 5 stub-sail hulls are gone and its houses are unchanged. At the gameplay zoom the open sea calms far from the shore (edge density 0.048 to 0.020; promo 0.012) and keeps broad light and dark swells, and #402's surf, shallows and near-coast chop are unchanged. At the overview a lighter teal shelf runs along the coast and tints the shallows' outer edge a little. The effects follow the camera's distance, not the pixel size, under a new `seacalm` toggle. Presentation only: no golden moves.
- Decision videos, phase 2 (#434 follow-up). On 11 decision cards an Illustration switch over the photograph plays a
short, silent AI-generated loop. It is labelled "AI-generated illustration" in place of the credit and carries a small
burned-in bilingual label. The photograph always shows first; nothing plays until the player asks, and the choice holds
diff --git a/docs/routes.md b/docs/routes.md
index 618b6f81a..ef9794960 100644
--- a/docs/routes.md
+++ b/docs/routes.md
@@ -2,6 +2,7 @@
The map draws the railways and main roads of 1948, each from its sourced date, after the promo (`promo/final/03-gameplay-1936.png`,
`02-map-diorama.png`, and the 0:21 close-up of `promo/demo/out/demo-16x9.mp4`). Civilian boats are out of scope (owner).
+On 2026-10-14 the owner reversed that for civilian boats ("Keep civilian boats"); they are map art in #536, not routes.
## Files
diff --git a/docs/units.md b/docs/units.md
index ef2e1fe22..f97140b2b 100644
--- a/docs/units.md
+++ b/docs/units.md
@@ -58,6 +58,8 @@ Not in the slice:
- **The mounted rider.** No 1948 IDF mounted unit was sourced for this slice. The promo's rider belongs to 1936, so it
waits for the Yishuv era (#49) and a source.
- **Civilian boats.** The owner ruled them out of scope; navy ships are units.
+ - 2026-10-14: the owner reversed this for civilian boats ("Keep civilian boats"); they are drawn as map art in #536.
+ Navy ships are still units.
## Units in play
diff --git a/docs/visual-v1.md b/docs/visual-v1.md
index 4da87b89f..61f4e3b7e 100644
--- a/docs/visual-v1.md
+++ b/docs/visual-v1.md
@@ -1299,7 +1299,8 @@ Review round 1 (staff review I1-I2, M1-M8) is folded in; the values below are th
- `MapCapture.SurfFrames` renders 60 gameplay03 frames on the web tier, consecutive at 60 fps or `-surfDt` seconds
apart.
- **Not done here.**
- - Boats: the owner wants no civilian boats; navy ships are units, on another track.
+ - Boats: the owner wants no civilian boats; navy ships are units, on another track. (Superseded by #536: see "Sea and
+ boats".)
- Harbour water and piers at Jaffa need geometry, which belongs to the settlement track.
- Issue #16 (the 1948 Dead Sea level, Lake Hula) is untouched.
@@ -1337,7 +1338,8 @@ Against the bars:
What still differs:
- The sea's spread is a third of promo 03's and half of promo 02's. Promo 03's dark tail is boat hulls and building
- shadows on the water, and its bright tail is glints and foam lace.
+ shadows on the water, and its bright tail is glints and foam lace. (The boats are superseded by #536: see "Sea and
+ boats".)
- gameplay03 contrast falls as the sea brightens (0.196 -> 0.174).
- gameplay03 warmth rises as the sea loses blue and gains a beach (0.077 -> 0.102 against the promo's 0.064).
@@ -1457,6 +1459,15 @@ Spread is luma p90 - p10.
| diorama02 palette distance | 0.563 | **0.534** | - | no worse |
| diorama02 warmth / saturation | 0.109 / 0.406 | 0.111 / 0.400 | 0.145 / 0.43 | [0.087, 0.145] / <= 0.48 |
+The gameplay03 floors above (detail >= 0.035, spread >= 0.15) are superseded by "Sea and boats" below (#388 and #536;
+the detail floor was the maintainer's call, the spread floor the owner's). Promo 03's own open sea measures 0.012 in
+edge density, so the far sea is now calmed on purpose. The floors are now:
+- detail >= 0.025 in #388's crop and >= 0.033 in the focus band, just under the branch's 0.029 and 0.037;
+- spread >= 0.09, under the branch's 0.096 and 0.104. The author proposed it and the reviewer recommended it; the owner
+ decided "Lower to 0.09" on 2026-10-14 (#536, "Changed acceptance criteria").
+
+They are kept so the sea cannot go flat. #388's "Done when" was updated to match.
+
diorama02's spread misses its target by 0.001. Strengthening the streaks barely moves it (0.25 to 0.32 added 0.003). A
stronger far ripple could close it, but the far ripple already runs at 84-100% at diorama02, at 2.3-3.7 px a swell cell.
More contrast at that sampling would push it towards aliasing, so it was not raised. In the editor (web tier) the same
@@ -1500,12 +1511,136 @@ The goldens and the smoke run are unchanged: `GOLDEN OK 1950 71e9904d...`, `GOLD
`SMOKE OK 5 turns 1948-06-19 d3fdd459...`. EditMode 747/747 on the merged head, with 0 `warning CS`.
Still different from the promo:
-- promo 03's sea has boats and building shadows in its dark tail (out of scope: no civilian boats);
+- promo 03's sea has boats and building shadows in its dark tail (out of scope here: no civilian boats; superseded by
+ #536, "Sea and boats");
- promo 02's sea sparkles finely at the overview, where ours is held back from aliasing;
- the open sea's turquoise near the coast reads a little paler against the brighter, textured open sea at diorama02. The
shallow-to-open gradient is unchanged (19 levels on both), and the turquoise thins slightly (g - r 43 to 40, 12-24 px
from the coast).
+### Sea and boats (branch `sea-boats`, refs #388)
+The gap audit of 2026-10-13 (`.superpowers/audit-2026-10-13/`) found three gaps against promo 03:
+- the open sea at gameplay03 4x busier than the promo's (edge density 0.048 against 0.012, in its open-sea crop at
+ 400 x 300);
+- the overview's sea flat;
+- 5 small wooden hulls with stub sails, where the promo has about 10 white-sailed boats and craft moored at Jaffa.
+
+#402 had raised the far sea's texture on purpose, so the calm applies only far from the shore and only at the gameplay
+zoom. There, #402's surf, shallows and near-coast chop are unchanged. Everything below is behind a new `seacalm` toggle,
+and the calm and swells are also behind `seatexture`.
+- **The zoom, not the pixel.** The calm and the swells fade out, and the overview's shelf fades in, with the water's
+ distance from the camera, not its pixel size, so a 1440p canvas or a device pixel ratio of 2 sees the same sea as
+ 1080p. The calm and swells go between 110 and 190 km, and the shelf comes in between 150 and 220 km. The gameplay
+ pose's water lies 50-90 km from the camera; the overview's (`CameraController.MaxDistance`, 250 km) lies 205-360 km
+ away.
+- **The calm** (`ScWaterShade`, `StatecraftMap.hlsl`).
+ - It runs from `ScCalmNearM` (3.6 km offshore, past the shallows, whose edge reaches at most 3.5 km, and past the
+ surf) to `ScCalmFarM` (8 km), on the open Mediterranean only, not the rift lakes.
+ - Across it the ripple eases to 30%, the mottle's fine octave to 30% and the glint to 40%, and the whitecaps go. The
+ coarse streaks grow 1.3x.
+- **Broad swells:** a 14 km gradient-noise brightness variation, +-0.25, on the same far sea and at the same zooms as the
+ calm, so the calmed water keeps promo 03's broad lighter and darker reaches. It is off at the overview, where its
+ cells would read as blotches.
+- **The overview's coastal shelf.** The sea within 12 km of the shore lightens towards a pale teal (0.36, 0.62, 0.66),
+ by 60% times how far past the shallows' gradient the water lies, fading to nothing at 12 km. That is promo 02's
+ lighter shelf. It tints the shallows' outer gradient a little at the overview and is not applied to the rift lakes.
+- **The boats** (`Kits/SeaCraft.cs`, one more mesh under the kits' root, drawn with Kit.mat, so the "kits" toggle covers
+ it):
+ - 10 under way, 2.4 to 7.5 km out: 3 off Jaffa, 2 off Tel Aviv, 1 off Bat Yam, 2 off Haifa, 1 off Acre and 1 off Gaza.
+ The Jaffa, Tel Aviv and Haifa points are the ones the kits build those ports at; the others are approximate shore
+ points chosen for placement.
+ - Two sailing rigs of the period: lateen-rigged feluccas and gaff cutters.
+ - 7 moored: 2 in Jaffa's basin inside its breakwater, 2 at Tel Aviv's mole (in its lee or at anchor south of it,
+ clear of the Jaffa label the gameplay pose shows north-west of it), and at Haifa 2 fishing boats by the quays and a small coastal steamer at anchor off the breakwater.
+ - No motor launches or modern craft.
+ - Each hull, plus a margin, lies in open sea and meets no breakwater or mole piece. The kits now record each piece as
+ a "breakwater" in the census. `SeaCraftTests.NoHullEverMeetsABreakwaterOrMole` sweeps five landmark scales and 16
+ draws each.
+ - Sizes are symbolic, like the buildings: a felucca is 34 landmark metres (2 km at the default scale), a quarter of a
+ hex across, about promo 03's share.
+ - Every boat heads east or west, give or take 35 degrees, so the north-looking gameplay camera sees its sails side-on.
+ - The sails are lit as cloth turned mostly to the sky (each face's normal tipped up by 0.7). Lit as flat plates, the
+ face the camera saw was often the one turned from the sun, and the sails read grey.
+ - `KitMesh.Triangle` gains an overload with an explicit normal for this. The old overload produces the same vertices
+ as before.
+- **Jaffa's old boats** are gone from `SettlementKits.Port`. Their random draws stay, so every later Jaffa house is drawn
+ from the same stream. In pinned-clock renders at 25 km against main:
+ - every pixel of the old town, the lighthouse and the clock tower is unchanged (0 of 371,200 differ);
+ - so is Tel Aviv with its port;
+ - the breakwater differs only on its 29 edge pixels where it meets the calmer sea; none inside it differs.
+
+Measured: WebGL `?shot` of main `58d7b5d8` (with #525's frame) against the branch rebased on it, with the audit's
+`measure.py` crops and #388's crop:
+
+| | main | branch | promo |
+|---|---|---|---|
+| gameplay03 open sea: edge density (audit crop) | 0.048 | **0.020** | 0.012 |
+| the same, sea only (x 0.02-0.22, clear of the boats) | 0.044 | **0.015** | |
+| gameplay03 open sea: luma contrast | 0.054 | 0.055 | 0.052 |
+| gameplay03 sea, #388 crop: detail / spread | 0.046 / 0.163 | 0.029 / 0.096 | 0.060 / 0.20 |
+| gameplay03 sea, focus band: detail / spread | 0.055 / 0.185 | 0.037 / 0.104 | 0.075 / 0.32 |
+| diorama02 sea pixels (inside the frame): luma std / p10-p90 | 0.100 / 0.279 | 0.099 / 0.279 | 0.086 / 0.11 (audit crop) |
+| gameplay03 / diorama02 palette distance | 0.35 / 0.58 | 0.36 / 0.58 | |
+| diorama02 warmth / saturation | 0.129 / 0.36 | 0.129 / 0.36 | 0.145 / 0.43 |
+
+- #525's frame now crops diorama02's sea to the coastal strip. The audit's overview crop holds the frame, and the strip's
+ own spread is already above promo 02's, so the "flat overview sea" gap is closed by the frame.
+- The coastal shelf moves diorama02's sea pixels by 1.7 levels on average (18% of them by more than 2). In the editor
+ test below, on the open water off the strip, it is 0.086 against main's 0.048.
+- **The same at any resolution.** These are pinned-clock editor renders at 1920 x 1080 and at 3840 x 2160 (a device pixel
+ ratio of 2, scaled back to 1080p to measure), comparing `seacalm` on and off:
+
+ | pose | 1080p | 2160p |
+ |---|---|---|
+ | gameplay03, open-sea edge density, off / on | 0.051 / 0.016 | 0.061 / 0.018 |
+ | gameplay03, share of sea pixels changed | 61% | 64% |
+ | diorama02, share of sea pixels changed / mean change | 18.4% / 1.68 levels | 18.4% / 1.68 levels |
+- Before the rebase (main `dc4b272`, no frame), the audit's overview crop measured contrast 0.030 on main and 0.031 on
+ the branch.
+
+- #388's crop detail falls under #402's 0.035 floor. That crop's promo figure counts the promo's boats and Jaffa, and
+ promo 03's open water alone measures 0.012, so the floor contradicted the target. The new floors are in "Sea round 2"
+ and #388. The near-shore texture is unchanged at the gameplay zoom.
+- The shelf itself: `SeaTests.TheOverviewSeaIsLighterAlongTheCoast`. At diorama02, water 5 km out is 0.086 lighter in
+ luma than water 25 km out; main measures 0.048, and the bound is 0.07.
+- `SeaTests.TheOpenSeaCalmsAwayFromTheShore`, at gameplay03's distance with the water's clock pinned: the fine texture
+ 20 km out against 2.2 km out is 0.23 on the branch and 0.89 on main (bound 0.6).
+- Three tests compare `seacalm` on and off, pixel for pixel. Each was run red against a mutated shader:
+
+ | test | what it checks | mutation | red |
+ |---|---|---|---|
+ | `TheGameplayZoomKeepsTheNearShoreSea` | gameplay03, 0.3-3.4 km out on nine rows: no change | `ScCalmNearM` 0 | 12/255 |
+ | | | the shelf at the gameplay zoom | 19/255 |
+ | `TheOverviewGetsNoCalmOrSwells` | diorama02, 15-40 km out: no change | no zoom fade | 13/255 |
+ | `TheShelfShowsAtTheOverview` | diorama02, 4-8 km out: changes by more than 3/255 (15/255 now) | | |
+- `SeaCraftTests` checks the boats:
+ - the count and the kinds;
+ - every hull and its margin in open sea, not a rift lake, with no two boats overlapping;
+ - the size against the hex;
+ - no hull meeting a breakwater or mole piece, over 1,337 boats from 5 scales x 16 draws;
+ - the seeding, and that the boats are drawn under the kits and toggled with them.
+- **The census's cost.** The kits now run with the census on, to read the ports and their works. The game towns' kits,
+ built 5 times each way, take a median of 11 ms without it and 12 ms with it.
+
+Frame time: `headed.py profile`, under the exclusive lock. The final round is main `58d7b5d8` first, then the branch, at a
+load of 4-6:
+
+| pose | `all` main / branch | `-seacalm` (branch) | `-water` main / branch | `none` main / branch | p95 `all` |
+|---|---|---|---|---|---|
+| gameplay03 | 3.35 / 3.62 | 3.47 | 3.51 / 3.16 | 2.64 / 2.50 | 5 / 5 |
+| diorama02 | 12.69 / 12.56 | 12.36 | 12.73 / 12.41 | 8.37 / 8.11 | 14 / 14 |
+
+- `seacalm` prices the calm, the swells and the shelf at about 0.15 ms at gameplay03 and 0.2 ms at diorama02.
+- `all` rises 0.27 ms at gameplay03, against spreads of 0.14 and 0.33 ms, and falls at diorama02.
+- p95 is unchanged.
+- Two earlier rounds, before the zoom-keyed fades and on a busier machine (load 5-27), gave gameplay03 `all` +0.35 ms
+ main first (spread 1.1-1.3 ms) and +0.97 ms branch first. In the branch-first round `-kits` and `-seatexture` rose
+ by as much as `all`.
+
+Boot (`headed.py boot --cpu 4 --runs 3`, one round each, before the rebase): map_build median 3389 ms on main and 3106
+on the branch, and `kits built` 828 against 785 ms in the last run. The branch is not slower: the boats' placement and
+one more mesh are not measurable against the run-to-run spread.
+
## Promo track: land use (issue #33, branch promo-land)
The flat mustard/olive ground becomes the promo's patchwork. `tools/land_bake.py` (no network, about 20 s, deterministic:
`test_the_committed_textures_are_the_bake` checks the committed PNGs against a fresh bake) decides where from real data
@@ -1676,7 +1811,7 @@ Each item below was ruled to the art track (controller, rank 10). None blocks la
0.39, and 0.08 at diorama02 against promo 02's 0.15. Its saturation p10/p90 is narrower too (0.43/0.55 against
0.29/0.58). The means match ("promo-sea", Measured). The causes:
- promo 03's dark tail is boat hulls and building shadows on the water. Boats are out of scope: navy ships are units,
- and there are no civilian boats (owner).
+ and there are no civilian boats (owner). Superseded by #536 ("Sea and boats").
- Its bright tail is foam lace and glints. The glint is held at 0.06 by the seam test (Task 7), and the surf is a
smooth band, not lace.
- diorama02's sea has a near-to-far gradient that ours keeps flat.
diff --git a/unity/Assets/Scripts/Map/Kits/KitLayer.cs b/unity/Assets/Scripts/Map/Kits/KitLayer.cs
index 74e8a1652..46e4dfef3 100644
--- a/unity/Assets/Scripts/Map/Kits/KitLayer.cs
+++ b/unity/Assets/Scripts/Map/Kits/KitLayer.cs
@@ -6,7 +6,8 @@ using UnityEngine.Rendering;
namespace Statecraft.Game.Map.Kits
{
/// <summary>Builds the art spike's procedural layer under a returned "Kits" root: one static mesh per settlement (its
- /// buildings, merged: one draw each, culled by its bounds) drawn with the editor-made Kit.mat, and the instanced trees
+ /// buildings, merged: one draw each, culled by its bounds) drawn with the editor-made Kit.mat, the boats
+ /// (<see cref="SeaCraft"/>, one more mesh with the same material), and the instanced trees
/// (<see cref="VegetationLayer"/>) drawn with Tree.mat. Meshes are owned by the map's MapRuntimeAssets, so a rebuild
/// frees them. Hides the marker boxes under <paramref name="markers"/> while the kits show. Registers the "kits" and
/// "trees" visual toggles, so the frame-time profile prices each ("kits" off shows the markers again). Fills
@@ -14,16 +15,16 @@ namespace Statecraft.Game.Map.Kits
/// 1948 localities' included.</summary>
public static class KitLayer
{
- public const string RootName = "Kits", VegetationName = "Vegetation";
+ public const string RootName = "Kits", VegetationName = "Vegetation", SeaCraftName = "SeaCraft";
public sealed class Stats
{
- public int Buildings, Vertices, Triangles, Trees, CorridorSegments, Localities, LocalityBuildings, Camps, Tents, Draws; public float BuildMs, PlantMs;
+ public int Buildings, Vertices, Triangles, Trees, CorridorSegments, Localities, LocalityBuildings, Camps, Tents, Draws, Boats; public float BuildMs, PlantMs;
/// <summary>Every footprint the build claimed (towns, localities, camps), in claim order (MapScene.KitFootprints).</summary>
public IReadOnlyList<(Vector2 centre, float radius, string id)> Footprints = System.Array.Empty<(Vector2, float, string)>();
public override string ToString() =>
$"KITS buildings={Buildings} vertices={Vertices} triangles={Triangles} trees={Trees} route_segments={CorridorSegments} build_ms={BuildMs:0} plant_ms={PlantMs:0} " +
- $"localities={Localities} locality_buildings={LocalityBuildings} camps={Camps} tents={Tents} draws={Draws}";
+ $"localities={Localities} locality_buildings={LocalityBuildings} camps={Camps} tents={Tents} boats={Boats} draws={Draws}";
}
public static GameObject Build(IReadOnlyList<Settlement> settlements, Terrain terrain, GeoFrame frame, HexFile hexes, float elevMinM,
@@ -49,7 +50,7 @@ namespace Statecraft.Game.Map.Kits
stats.CorridorSegments = ground.CorridorSegments;
if (tokens != null) ground.Tokens.AddRange(tokens);
var clock = System.Diagnostics.Stopwatch.StartNew();
- var built = SettlementKits.Build(settlements, localities, camps, ground, columns); // columns: the labels' kit footprints (issue #214)
+ var built = SettlementKits.Build(settlements, localities, camps, ground, out var placed, columns); // columns: the labels' kit footprints (issue #214)
foreach (var l in built.Claimed) ground.Lots.Add((l.centre, l.radius));
stats.Footprints = new List<(Vector2, float, string)>(ground.Footprints);
void Add(string name, Mesh mesh)
@@ -65,6 +66,15 @@ namespace Statecraft.Game.Map.Kits
}
foreach (var (s, mesh, n) in built.Towns) { Add(s.Id, mesh); stats.Buildings += n; }
foreach (var (name, mesh) in built.Tiles) Add(name, mesh);
+ // The boats (SeaCraft): off the coast and moored in the harbours the kits recorded.
+ var crafts = SeaCraft.Place(ground, placed);
+ if (crafts.Count > 0)
+ {
+ var km = new KitMesh();
+ SeaCraft.Draw(crafts, ground, km);
+ Add(SeaCraftName, km.ToMesh(SeaCraftName));
+ }
+ stats.Boats = crafts.Count;
stats.Localities = localities.Count; stats.LocalityBuildings = built.LocalityBuildings; stats.Camps = built.Camps; stats.Tents = built.Tents;
stats.Buildings += built.LocalityBuildings + built.Tents;
stats.BuildMs = (float)clock.Elapsed.TotalMilliseconds;
diff --git a/unity/Assets/Scripts/Map/Kits/KitMesh.cs b/unity/Assets/Scripts/Map/Kits/KitMesh.cs
index 27c4251e2..b2cb4c2fe 100644
--- a/unity/Assets/Scripts/Map/Kits/KitMesh.cs
+++ b/unity/Assets/Scripts/Map/Kits/KitMesh.cs
@@ -85,9 +85,13 @@ namespace Statecraft.Game.Map.Kits
}
/// <summary>A flat-shaded triangle, clockwise seen from its front.</summary>
- public void Triangle(Vector3 a, Vector3 b, Vector3 c, Color32 colour)
+ public void Triangle(Vector3 a, Vector3 b, Vector3 c, Color32 colour) => Triangle(a, b, c, colour, Vector3.Cross(b - a, c - a));
+
+ /// <summary>A triangle, clockwise seen from its front, lit as if it faced <paramref name="normal"/> (normalised here):
+ /// a boat's sail is lit as cloth that catches the sky, not as a flat plate turned from the sun (SeaCraft).</summary>
+ public void Triangle(Vector3 a, Vector3 b, Vector3 c, Color32 colour, Vector3 normal)
{
- var n = Vector3.Cross(b - a, c - a).normalized;
+ var n = normal.normalized;
int i = V(a, n, colour, Vector2.zero); V(b, n, colour, Vector2.zero); V(c, n, colour, Vector2.zero);
tri.Add(i); tri.Add(i + 1); tri.Add(i + 2);
}
diff --git a/unity/Assets/Scripts/Map/Kits/SeaCraft.cs b/unity/Assets/Scripts/Map/Kits/SeaCraft.cs
new file mode 100644
index 000000000..c0ba29298
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Kits/SeaCraft.cs
@@ -0,0 +1,346 @@
+#nullable enable
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace Statecraft.Game.Map.Kits
+{
+ /// <summary>The boats on the Mediterranean, as promo 03 draws them (refs #388): white-sailed craft under way off the coast
+ /// and craft moored in and off the harbours of Jaffa, Tel Aviv and Haifa. Craft of the period: lateen-rigged and
+ /// gaff-rigged sailing and fishing boats, and a small coastal steamer at anchor off Haifa's breakwater; no motor
+ /// launches or modern craft. Like the buildings, sizes are symbolic: a felucca is drawn about a quarter of a hex across
+ /// (2 km at the default scale), as the promo's boats are, so it reads at the gameplay zoom. One static mesh under the
+ /// kits' root, drawn with Kit.mat, so the "kits" toggle covers it. Seeded: the same map draws the same boats.</summary>
+ public static class SeaCraft
+ {
+ public enum Kind { Felucca, Cutter, Steamer, Moored }
+
+ /// <summary>One boat: its kind, centre (world x, z), heading (degrees, from +x towards +z), length (world m) and the
+ /// place it belongs to (a port's settlement id, or the coast it sails off).</summary>
+ public readonly struct Craft
+ {
+ public readonly Kind Kind; public readonly Vector2 At; public readonly float Yaw, Length; public readonly string Place;
+ public Craft(Kind kind, Vector2 at, float yaw, float length, string place) { Kind = kind; At = at; Yaw = yaw; Length = length; Place = place; }
+ public Vector2 Forward { get { float a = Yaw * Mathf.Deg2Rad; return new Vector2(Mathf.Cos(a), Mathf.Sin(a)); } }
+ }
+
+ /// <summary>Lengths in the kits' landmark metres (x KitScale.Landmarks): a felucca 34, a cutter 30, the steamer 46, a
+ /// moored boat 16; a felucca is about a quarter of a hex across at the default scale.</summary>
+ static float LengthOf(Kind k) => k switch { Kind.Felucca => 34f, Kind.Cutter => 30f, Kind.Steamer => 46f, _ => 16f } * KitScale.Landmarks;
+
+ /// <summary>The coasts the boats under way sail off: a point on the shore (lon, lat), the direction out to sea (world
+ /// x, z) and how many boats. Jaffa's, Tel Aviv's and Haifa's are the points the settlement kits build those ports at
+ /// (docs/visual-v1.md, "Towns round 2"); Bat Yam's, Acre's and Gaza's are approximate points on their shores, chosen
+ /// for placement only.</summary>
+ static readonly (string place, double lon, double lat, Vector2 seaward, int boats)[] Coasts =
+ {
+ ("jaffa", 34.7505056, 32.0534583, Vector2.left, 3),
+ ("tel_aviv", 34.7732528, 32.0964833, Vector2.left, 2),
+ ("bat_yam", 34.745, 32.020, Vector2.left, 1),
+ ("haifa", 35.00448, 32.820118, Vector2.up, 2),
+ ("acre", 35.0675, 32.9205, Vector2.left, 1),
+ ("gaza", 34.44, 31.52, Vector2.left, 1),
+ };
+
+ /// <summary>Where the boats are: the moored craft in and off each harbour the settlement kits recorded
+ /// (<paramref name="placed"/>'s "port" footprints), then those under way off <see cref="Coasts"/>, between
+ /// <see cref="OffshoreNearM"/> and <see cref="OffshoreM"/> out from the shore. Every hull stands in open sea, clear of
+ /// the harbour works (the "breakwater" pieces the kits record) and of every other boat. <paramref name="salt"/>
+ /// varies the draw (the tests sweep it); the map uses 0.</summary>
+ public static List<Craft> Place(KitGround ground, IReadOnlyList<SettlementKits.Placed> placed, ulong salt = 0)
+ {
+ var list = new List<Craft>();
+ var rnd = new KitRandom("sea_craft", salt);
+ float m = KitScale.Landmarks / 60f;
+ var ports = new List<SettlementKits.Placed>(); var works = new List<SettlementKits.Placed>();
+ foreach (var p in placed)
+ {
+ if (p.Kind == "port") ports.Add(p);
+ else if (p.Kind == "breakwater") works.Add(p);
+ }
+ foreach (var p in ports) Moor(p, ground, works, list, ref rnd);
+ foreach (var (place, lon, lat, seaward, boats) in Coasts)
+ {
+ var w = ground.Frame.ToWorld(lon, lat, 0); var at = new Vector2(w.x, w.z);
+ var shore = ground.Water(at.x, at.y) ? at : FirstWater(at, seaward, ground, 20000f);
+ if (!(shore is Vector2 s)) continue;
+ var along = new Vector2(-seaward.y, seaward.x);
+ int put = 0;
+ for (int tries = 0; tries < 60 && put < boats; tries++)
+ {
+ var kind = rnd.Value() < 0.6f ? Kind.Felucca : Kind.Cutter;
+ float L = LengthOf(kind);
+ var c = s + seaward * rnd.Range(OffshoreNearM, OffshoreM) * m + along * rnd.Range(-2.2f, 2.2f) * L;
+ var craft = new Craft(kind, c, Heading(ref rnd, 35f), L, place);
+ if (!Clear(craft, ground, works, list, 0.5f * L) || NearPort(c, ports, 0.8f * L)) continue;
+ list.Add(craft); put++;
+ }
+ }
+ return list;
+ }
+
+ /// <summary>East or west, give or take <paramref name="spread"/> degrees: the gameplay camera looks north, so the
+ /// boats show their sails side-on, as the promo's do. On this coast, running north-south, that is reaching out to sea
+ /// or back in, and moored craft lie stern-to the quays.</summary>
+ static float Heading(ref KitRandom rnd, float spread) => (rnd.Value() < 0.5f ? 0f : 180f) + rnd.Range(-spread, spread);
+
+ /// <summary>How far out the boats under way sail (world m at the default landmark scale, 60): from past the surf to the
+ /// edge of the gameplay pose's view of the coast.</summary>
+ const float OffshoreNearM = 2400f, OffshoreM = 7500f;
+
+ /// <summary>A harbour's water as the settlement kits record it: Jaffa's a circle (its breakwater's centre and radius,
+ /// SettlementKits.Port), Tel Aviv's and Haifa's a box (centre, width east-west, depth north-south). Returns how far
+ /// <paramref name="q"/> lies outside it (0 inside).</summary>
+ static float PortDistance(SettlementKits.Placed port, Vector2 q)
+ {
+ if (port.Id == "jaffa") return Mathf.Max(0f, (q - port.C).magnitude - port.W);
+ var d = new Vector2(Mathf.Max(0f, Mathf.Abs(q.x - port.C.x) - 0.5f * port.W), Mathf.Max(0f, Mathf.Abs(q.y - port.C.y) - 0.5f * port.D));
+ return d.magnitude;
+ }
+
+ static bool NearPort(Vector2 q, List<SettlementKits.Placed> ports, float margin)
+ {
+ foreach (var p in ports) if (PortDistance(p, q) < margin) return true;
+ return false;
+ }
+
+ /// <summary>Moored craft in a recorded harbour: in Jaffa's basin inside its curved breakwater, in Tel Aviv's lee of its
+ /// mole and along Haifa's quays, never touching a breakwater piece. Where the basin has no room at the boats' size,
+ /// they lie at anchor just off the harbour on its seaward side (Tel Aviv's south of its mole, clear of Jaffa's label
+ /// to the north-west); Haifa's coastal steamer always does.</summary>
+ static void Moor(SettlementKits.Placed port, KitGround ground, List<SettlementKits.Placed> works, List<Craft> list, ref KitRandom rnd)
+ {
+ int want = port.Id == "haifa" ? 3 : 2;
+ var seaward = port.Id == "haifa" ? Vector2.up : Vector2.left;
+ var along = new Vector2(-seaward.y, seaward.x);
+ float extent = port.Id == "jaffa" ? port.W : 0.5f * (seaward.x != 0f ? port.W : port.D);
+ int put = 0;
+ for (int tries = 0; tries < 120 && put < want; tries++)
+ {
+ var kind = port.Id == "haifa" && put == 0 ? Kind.Steamer : Kind.Moored;
+ float L = LengthOf(kind);
+ Vector2 c;
+ if (tries < 80 && kind == Kind.Moored)
+ {
+ if (port.Id == "jaffa")
+ {
+ // The basin: the breakwater's quarter circle runs from the shore south of the centre out west, so the
+ // water inside it lies south-west of the centre, within its radius.
+ float a = rnd.Range(190f, 260f) * Mathf.Deg2Rad, r = rnd.Range(0.25f, 0.75f) * port.W;
+ c = port.C + new Vector2(Mathf.Cos(a), Mathf.Sin(a)) * r;
+ }
+ else c = port.C + new Vector2(rnd.Range(-0.4f, 0.4f) * port.W, rnd.Range(-0.25f, 0.25f) * port.D);
+ }
+ else
+ {
+ // At anchor off the harbour. Tel Aviv's lie south of its mole (along is south there): at the gameplay pose
+ // the labels put Jaffa's name north-west of the mole, over the water there.
+ float t = port.Id == "tel_aviv" ? rnd.Range(0.3f, 1f) : rnd.Range(-1f, 1f);
+ c = port.C + seaward * (extent + rnd.Range(0.7f, 1.6f) * L) + along * t * extent;
+ }
+ var craft = new Craft(kind, c, Heading(ref rnd, 15f), L, port.Id);
+ if (!Clear(craft, ground, works, list, 0.1f * L)) continue;
+ list.Add(craft); put++;
+ }
+ }
+
+ static Vector2? FirstWater(Vector2 from, Vector2 dir, KitGround ground, float maxM)
+ {
+ for (float d = 0f; d <= maxM; d += 125f)
+ {
+ var p = from + dir * d;
+ if (ground.Water(p.x, p.y)) return p;
+ }
+ return null;
+ }
+
+ /// <summary>The hull's rectangle (its length by <see cref="Beam"/> of it, both grown by <paramref name="margin"/>):
+ /// its samples all lie in open sea (not a lake: the rift lakes are below sea level), it meets no harbour work
+ /// (<paramref name="works"/>, each piece's own rectangle), and its centre keeps clear of every boat already
+ /// placed.</summary>
+ static bool Clear(Craft c, KitGround ground, List<SettlementKits.Placed> works, List<Craft> list, float margin)
+ {
+ var f = c.Forward; var side = new Vector2(-f.y, f.x);
+ float half = 0.5f * c.Length + margin, beam = 0.5f * Beam * c.Length + margin;
+ for (int i = -2; i <= 2; i++)
+ for (int j = -1; j <= 1; j++)
+ {
+ var p = c.At + f * (half * i / 2f) + side * (beam * j);
+ if (!ground.Inside(p.x, p.y) || !ground.Water(p.x, p.y) || ground.ElevM(p.x, p.y) < -50f) return false;
+ }
+ foreach (var w in works)
+ if (Overlap(c.At, c.Yaw, half, beam, w.C, w.Yaw, 0.5f * w.W, 0.5f * w.D)) return false;
+ foreach (var o in list)
+ if ((o.At - c.At).magnitude < 0.6f * (o.Length + c.Length)) return false;
+ return true;
+ }
+
+ /// <summary>Whether two rectangles meet (centre, yaw in degrees, half-length along the yaw, half-width across it):
+ /// the separating-axis test on their four edge normals.</summary>
+ public static bool Overlap(Vector2 ca, float yawA, float ha, float wa, Vector2 cb, float yawB, float hb, float wb)
+ {
+ float a = yawA * Mathf.Deg2Rad, b = yawB * Mathf.Deg2Rad;
+ var ax = new Vector2(Mathf.Cos(a), Mathf.Sin(a)); var ay = new Vector2(-ax.y, ax.x);
+ var bx = new Vector2(Mathf.Cos(b), Mathf.Sin(b)); var by = new Vector2(-bx.y, bx.x);
+ var d = cb - ca;
+ foreach (var n in new[] { ax, ay, bx, by })
+ {
+ float ra = ha * Mathf.Abs(Vector2.Dot(ax, n)) + wa * Mathf.Abs(Vector2.Dot(ay, n));
+ float rb = hb * Mathf.Abs(Vector2.Dot(bx, n)) + wb * Mathf.Abs(Vector2.Dot(by, n));
+ if (Mathf.Abs(Vector2.Dot(d, n)) > ra + rb) return false;
+ }
+ return true;
+ }
+
+ // ---- The models ------------------------------------------------------------------------------------------------
+
+ /// <summary>Beam and freeboard as shares of the length.</summary>
+ const float Beam = 0.30f, Freeboard = 0.10f;
+
+ static Color32 C(float r, float g, float b) => new Color32((byte)(r * 255), (byte)(g * 255), (byte)(b * 255), (byte)Facade.Plain);
+
+ static readonly Color32 Sail = C(0.96f, 0.94f, 0.88f), Spar = C(0.30f, 0.23f, 0.16f), DeckColour = C(0.66f, 0.55f, 0.40f);
+ static readonly Color32[] HullColours = { C(0.30f, 0.20f, 0.13f), C(0.36f, 0.24f, 0.15f), C(0.16f, 0.26f, 0.30f), C(0.42f, 0.18f, 0.12f) };
+ static readonly Color32 Band = C(0.90f, 0.87f, 0.78f);
+
+ /// <summary>Draws every boat of <paramref name="crafts"/> into <paramref name="km"/>, its waterline at the sea's surface
+ /// under it.</summary>
+ public static void Draw(IReadOnlyList<Craft> crafts, KitGround ground, KitMesh km)
+ {
+ var rnd = new KitRandom("sea_craft_models");
+ foreach (var c in crafts)
+ {
+ float sea = ground.Y(c.At.x, c.At.y);
+ var hull = c.Kind == Kind.Steamer ? C(0.14f, 0.14f, 0.15f) : HullColours[(int)(rnd.Value() * HullColours.Length) % HullColours.Length];
+ float slim = c.Kind == Kind.Steamer ? 0.8f : 1f;
+ Hull(km, c, sea, hull, slim);
+ switch (c.Kind)
+ {
+ case Kind.Felucca: Felucca(km, c, sea, ref rnd); break;
+ case Kind.Cutter: Cutter(km, c, sea, ref rnd); break;
+ case Kind.Steamer: Steamer(km, c, sea); break;
+ default: Moored(km, c, sea); break;
+ }
+ }
+ }
+
+ /// <summary>A point in the boat's frame: <paramref name="x"/> along it (forward), <paramref name="z"/> across (to
+ /// port), <paramref name="y"/> up from the waterline; all in shares of its length.</summary>
+ static Vector3 P(Craft c, float sea, float x, float y, float z)
+ {
+ var f = c.Forward; var s = new Vector2(-f.y, f.x);
+ var q = c.At + f * (x * c.Length) + s * (z * c.Length);
+ return new Vector3(q.x, sea + y * c.Length, q.y);
+ }
+
+ /// <summary>A quad facing <paramref name="outward"/> (its winding chosen so the face's normal does).</summary>
+ static void Quad(KitMesh km, Vector3 a, Vector3 b, Vector3 c, Vector3 d, Color32 colour, Vector3 outward)
+ {
+ if (Vector3.Dot(Vector3.Cross(c - a, d - b), outward) >= 0f) km.Face(a, b, c, d, colour, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero);
+ else km.Face(d, c, b, a, colour, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero);
+ }
+
+ static void Tri(KitMesh km, Vector3 a, Vector3 b, Vector3 c, Color32 colour, Vector3 outward)
+ {
+ if (Vector3.Dot(Vector3.Cross(b - a, c - a), outward) >= 0f) km.Triangle(a, b, c, colour); else km.Triangle(a, c, b, colour);
+ }
+
+ /// <summary>A sail: both faces, each lit as if turned mostly to the sky (its own normal tipped up by
+ /// <see cref="SailLift"/>), so the cloth reads white from either side, as the promo's sunlit sails do; as a flat plate,
+ /// the face the camera saw was often the one turned from the sun, and read grey.</summary>
+ static void SailTri(KitMesh km, Vector3 a, Vector3 b, Vector3 c)
+ {
+ var n = Vector3.Cross(b - a, c - a);
+ if (n.sqrMagnitude < 1e-6f) return;
+ n.Normalize();
+ km.Triangle(a, b, c, Sail, n * (1f - SailLift) + Vector3.up * SailLift);
+ km.Triangle(a, c, b, Sail, -n * (1f - SailLift) + Vector3.up * SailLift);
+ }
+
+ const float SailLift = 0.7f;
+
+ /// <summary>The deck's half-outline from stern to bow: (along, half-width), shares of the length and beam.</summary>
+ static readonly Vector2[] Outline = { new(-0.5f, 0.40f), new(-0.28f, 0.50f), new(0.05f, 0.50f), new(0.30f, 0.36f), new(0.5f, 0f) };
+
+ /// <summary>A pointed hull: the deck at the freeboard, sides sloping in to a narrower, shorter waterline (a sheer band
+ /// of pale paint under the gunwale, the rest the hull's colour), a transom at the stern.</summary>
+ static void Hull(KitMesh km, Craft c, float sea, Color32 hull, float slim)
+ {
+ float B = Beam * slim, F = Freeboard * (c.Kind == Kind.Steamer ? 0.9f : 1f), band = F * 0.72f, below = -0.02f;
+ int n = Outline.Length;
+ Vector3 Deck(int i, int side, float y) => P(c, sea, Outline[i].x, y, side * Outline[i].y * B * 0.5f);
+ Vector3 Water(int i, int side) => P(c, sea, Outline[i].x * 0.9f, below, side * Outline[i].y * B * 0.5f * 0.7f);
+ var centre = P(c, sea, 0f, F, 0f);
+ for (int side = -1; side <= 1; side += 2)
+ for (int i = 0; i < n - 1; i++)
+ {
+ var mid = (P(c, sea, Outline[i].x, F, 0f) + P(c, sea, Outline[i + 1].x, F, 0f)) * 0.5f;
+ var outward = (Deck(i, side, F) + Deck(i + 1, side, F)) * 0.5f - mid; outward.y = 0f;
+ if (i == n - 2) outward += (P(c, sea, 1f, F, 0f) - centre).normalized * outward.magnitude;
+ // The pale sheer band, then the hull down to the waterline.
+ var a0 = Deck(i, side, F); var a1 = Deck(i + 1, side, F);
+ var b0 = Vector3.Lerp(Water(i, side), a0, band / (F - below)); var b1 = Vector3.Lerp(Water(i + 1, side), a1, band / (F - below));
+ Quad(km, a0, a1, b1, b0, Band, outward);
+ Quad(km, b0, b1, Water(i + 1, side), Water(i, side), hull, outward);
+ Tri(km, centre, Deck(i, side, F), Deck(i + 1, side, F), DeckColour, Vector3.up);
+ }
+ // The transom.
+ Quad(km, Deck(0, -1, F), Deck(0, 1, F), Water(0, 1), Water(0, -1), hull, P(c, sea, -1f, F, 0f) - centre);
+ }
+
+ static void Mast(KitMesh km, Vector3 foot, float h, float r) => km.Shaft(foot, foot + Vector3.up * h, r, r * 0.7f, Spar, 5);
+
+ /// <summary>A felucca: one mast stepped forward, a long yard slanting up aft, and the lateen sail under it, sheeted
+ /// out to one side (so the top-down camera sees its face, as the promo's do).</summary>
+ static void Felucca(KitMesh km, Craft c, float sea, ref KitRandom rnd)
+ {
+ float L = c.Length, side = rnd.Value() < 0.5f ? -1f : 1f, sheet = 0.16f * side;
+ Mast(km, P(c, sea, 0.14f, Freeboard, 0f), 0.62f * L, 0.010f * L);
+ var tack = P(c, sea, 0.42f, Freeboard + 0.05f, 0f);
+ var peak = P(c, sea, -0.40f, 1.00f, sheet * 0.6f);
+ var clew = P(c, sea, -0.30f, Freeboard + 0.08f, sheet);
+ km.Shaft(tack, peak, 0.006f * L, 0.004f * L, Spar, 4);
+ SailTri(km, tack, peak, clew);
+ }
+
+ /// <summary>A gaff cutter: a mast amidships, a four-sided mainsail on its gaff and boom aft of it and a jib forward,
+ /// both sheeted out to one side.</summary>
+ static void Cutter(KitMesh km, Craft c, float sea, ref KitRandom rnd)
+ {
+ float L = c.Length, side = rnd.Value() < 0.5f ? -1f : 1f, sheet = 0.14f * side;
+ var foot = P(c, sea, 0.06f, Freeboard, 0f);
+ Mast(km, foot, 0.95f * L, 0.011f * L);
+ var throat = P(c, sea, 0.06f, 0.78f, 0f); var tack = P(c, sea, 0.06f, Freeboard + 0.06f, 0f);
+ var peakG = P(c, sea, -0.30f, 0.98f, sheet * 0.8f); var clew = P(c, sea, -0.40f, Freeboard + 0.07f, sheet);
+ SailTri(km, tack, throat, peakG); SailTri(km, tack, peakG, clew);
+ var head = P(c, sea, 0.06f, 0.88f, 0f); var bow = P(c, sea, 0.52f, Freeboard + 0.04f, 0f);
+ var jibClew = P(c, sea, 0.10f, Freeboard + 0.06f, sheet * 0.7f);
+ SailTri(km, head, bow, jibClew);
+ }
+
+ /// <summary>A small coastal steamer: a white deckhouse amidships, a black funnel with a red band, and two short masts.</summary>
+ static void Steamer(KitMesh km, Craft c, float sea)
+ {
+ float L = c.Length, F = Freeboard * 0.9f;
+ var white = C(0.92f, 0.91f, 0.86f);
+ var mid = P(c, sea, -0.06f, F, 0f);
+ float yaw = c.Yaw;
+ km.Box(mid.x, mid.z, yaw, 0.34f * L, 0.17f * L, mid.y, mid.y, 0.07f * L, white, white, Facade.Plain, 1f);
+ var bridge = P(c, sea, 0.04f, F + 0.07f, 0f);
+ km.Box(bridge.x, bridge.z, yaw, 0.08f * L, 0.14f * L, bridge.y, bridge.y, 0.05f * L, white, white, Facade.Plain, 1f);
+ var funnel = P(c, sea, -0.10f, F + 0.07f, 0f);
+ km.Shaft(funnel, funnel + Vector3.up * 0.10f * L, 0.03f * L, 0.03f * L, C(0.12f, 0.11f, 0.11f), 8);
+ km.Shaft(funnel + Vector3.up * 0.10f * L, funnel + Vector3.up * 0.13f * L, 0.031f * L, 0.031f * L, C(0.62f, 0.16f, 0.12f), 8);
+ Mast(km, P(c, sea, 0.30f, F, 0f), 0.26f * L, 0.006f * L);
+ Mast(km, P(c, sea, -0.34f, F, 0f), 0.22f * L, 0.006f * L);
+ }
+
+ /// <summary>A moored fishing boat: its mast bare, the sail furled along the boom.</summary>
+ static void Moored(KitMesh km, Craft c, float sea)
+ {
+ float L = c.Length;
+ Mast(km, P(c, sea, 0.10f, Freeboard, 0f), 0.70f * L, 0.012f * L);
+ var boom = P(c, sea, -0.13f, Freeboard + 0.07f, 0f);
+ km.Box(boom.x, boom.z, c.Yaw, 0.46f * L, 0.045f * L, boom.y, boom.y, 0.04f * L, Sail, Sail, Facade.Plain, 1f);
+ }
+ }
+}
diff --git a/unity/Assets/Scripts/Map/Kits/SeaCraft.cs.meta b/unity/Assets/Scripts/Map/Kits/SeaCraft.cs.meta
new file mode 100644
index 000000000..b027c5b42
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Kits/SeaCraft.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: e0668cf2e5efd4e7d98a91a530e1bf8a
\ No newline at end of file
diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs b/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs
index 8e80d2247..ff9c75c36 100644
--- a/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs
+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs
@@ -69,7 +69,7 @@ namespace Statecraft.Game.Map.Kits
/// <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>
+ /// on the hilltop above the old port, and the port's breakwater.</summary>
static int Jaffa(Settlement s, Vector2 heart, KitGround ground, KitMesh km, Lots lots, ref KitRandom rnd)
{
float m = KitScale.Landmarks;
@@ -113,7 +113,7 @@ namespace Statecraft.Game.Map.Kits
}
/// <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>
+ /// lighthouse. Its boats are SeaCraft's.</summary>
static int Port(Vector2 shore, KitGround ground, KitMesh km, ref KitRandom rnd)
{
float m = KitScale.Landmarks;
@@ -130,23 +130,18 @@ namespace Statecraft.Game.Map.Kits
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);
+ Record("jaffa", "breakwater", mid, yaw, dir.magnitude * 1.08f, 5f * m, 2.2f * m, stone); // SeaCraft keeps its boats off it
prev = cur;
}
Record("jaffa", "port", c, 0f, r, r, 2.2f * m, stone);
- // Sailing boats in and off the harbour.
+ // The boats are SeaCraft's (#388). The random draws the old boats made here stay, so the stream every later
+ // Jaffa house is drawn from is unchanged.
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);
+ rnd.Range(0f, 360f); rnd.Range(9f, 14f);
boats++;
}
return 1;
@@ -322,6 +317,7 @@ namespace Statecraft.Game.Map.Kits
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);
+ Record(s.Id, "breakwater", mid, yaw, d.magnitude / k * 1.04f, 5f * m, 2.4f * m, stone); // SeaCraft keeps its boats off it
pieces++;
}
}
@@ -390,6 +386,7 @@ namespace Statecraft.Game.Map.Kits
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);
+ Record(s.Id, "breakwater", mid, yaw, d.magnitude / k * 1.04f, 4.5f * m, 2.2f * m, stone); // SeaCraft keeps its boats off it
pieces++;
}
}
diff --git a/unity/Assets/Scripts/Map/MapShaderGlobals.cs b/unity/Assets/Scripts/Map/MapShaderGlobals.cs
index 7fb6785a6..d9459b937 100644
--- a/unity/Assets/Scripts/Map/MapShaderGlobals.cs
+++ b/unity/Assets/Scripts/Map/MapShaderGlobals.cs
@@ -12,7 +12,7 @@ namespace Statecraft.Game.Map
Biome = Shader.PropertyToID("_ScBiomeTex"), Haze = Shader.PropertyToID("_ScHaze"), HazeWater = Shader.PropertyToID("_ScHazeWater"),
HazeRange = Shader.PropertyToID("_ScHazeRange"), WaterOn = Shader.PropertyToID("_ScWaterOn"), Grid = Shader.PropertyToID("_ScGrid"),
WaterTime = Shader.PropertyToID("_ScWaterTime"), LandOn = Shader.PropertyToID("_ScLandOn"),
- SeaTexture = Shader.PropertyToID("_ScSeaTexture");
+ SeaTexture = Shader.PropertyToID("_ScSeaTexture"), SeaCalm = Shader.PropertyToID("_ScSeaCalm");
/// <summary>Pins the water's clock (waves, surf) to the given seconds, or back to Unity's time with null: for tests and
/// frame captures that must render chosen moments (promo-sea review I2, M5).</summary>
@@ -67,6 +67,10 @@ namespace Statecraft.Game.Map
// the profile prices it and the seam test can pin it off.
Shader.SetGlobalFloat(SeaTexture, 1f);
assets.OnTeardown(VisualToggles.Register("seatexture", on => Shader.SetGlobalFloat(SeaTexture, on ? 1f : 0f)));
+ // Sea boats (#388, StatecraftMap.hlsl): the far sea's calm and broad swells at the gameplay zoom, and the coastal
+ // shelf at the overview; its own toggle, so the profile prices it and the tests can compare with it off.
+ Shader.SetGlobalFloat(SeaCalm, 1f);
+ assets.OnTeardown(VisualToggles.Register("seacalm", on => Shader.SetGlobalFloat(SeaCalm, on ? 1f : 0f)));
assets.OnTeardown(VisualToggles.Register("haze", on =>
{
Shader.SetGlobalVector(Haze, on ? haze : new Vector4(haze.x, haze.y, haze.z, 0f));
diff --git a/unity/Assets/Shaders/StatecraftMap.hlsl b/unity/Assets/Shaders/StatecraftMap.hlsl
index f76b93d54..82cd3aea0 100644
--- a/unity/Assets/Shaders/StatecraftMap.hlsl
+++ b/unity/Assets/Shaders/StatecraftMap.hlsl
@@ -127,6 +127,34 @@ float _ScSeaTexture; // 1 = on, 0 =
static const float ScMottleCellM = 2500.0, ScMottleGain = 0.32, ScMottleStretch = 3.0;
static const float ScRippleGain = 0.54, ScRippleScale = 5.0, ScRippleFarGain = 0.28, ScRippleFarScale = 4.0;
static const float ScFleckCellM = 120.0, ScFleckM = 18.0, ScFleckShare = 0.22;
+// Sea boats (#388, the 2026-10-13 gap audit): the open sea calms away from the shore at the gameplay zoom. At gameplay03
+// the far sea's fine texture (the ripple, the mottle's fine octave, the whitecaps and the glint) was 4x busier than promo
+// 03's open water (edge density 0.048 against 0.012), whose texture is the surf and the near-coast chop, with broad,
+// smooth swells beyond. All of it is behind the "seacalm" toggle (_ScSeaCalm), and the calm and swells also behind
+// "seatexture", on the open Mediterranean only (not the rift lakes).
+// - The zoom, not the pixel: the calm and the swells fade out, and the overview's shelf fades in, with the water's
+// distance from the camera (ScZoomFades), so a 1440p canvas or a device pixel ratio of 2 sees the same sea as 1080p.
+// The gameplay pose's water lies 50-90 km from the camera, the overview's (CameraController.MaxDistance, 250 km)
+// 205-360 km.
+// - The calm: from ScCalmNearM offshore (past the turquoise shallows, whose edge reaches at most 3.5 km, and the surf)
+// to ScCalmFarM, the ripple, the mottle's fine octave and the glint ease to their ScCalm* shares and the whitecaps go;
+// the coarse streaks grow by ScCalmCoarse. Inside ScCalmNearM, and at the overview, nothing changes: #402's surf,
+// shallows and near-coast chop stay as they were.
+// - Broad swells: a ScBroadCellM gradient-noise brightness variation, +-ScBroadGain, on the same far sea and zooms as the
+// calm: promo 03's open water lies in broad lighter and darker reaches. At the gameplay zoom a cell spans some 300
+// pixels; at the overview, where its cells read as blotches, it is off.
+// - The coastal shelf at the overview: the water within ScCoastRangeM of the shore lightens towards ScOverviewCoastSrgb
+// (by ScOverviewBand, times how far past the shallows' gradient it lies, fading to none at the range), so diorama02's
+// sea reads as promo 02's lighter shelf over the deep blue. It tints the shallows' outer gradient a little at the
+// overview; the gameplay zoom has none of it.
+float _ScSeaCalm; // 1 = on, 0 = off (the "seacalm" toggle)
+static const float ScCalmNearM = 3600.0, ScCalmFarM = 8000.0;
+static const float ScCalmRipple = 0.3, ScCalmFine = 0.3, ScCalmGlint = 0.4, ScCalmCoarse = 1.3;
+static const float ScBroadCellM = 14000.0, ScBroadGain = 0.25;
+static const float3 ScOverviewCoastSrgb = float3(0.36, 0.62, 0.66);
+static const float ScOverviewBand = 0.6;
+// Camera distances (m): the calm and swells fade out over (x, y), the shelf fades in over (z, w).
+static const float4 ScZoomFades = float4(110000.0, 190000.0, 150000.0, 220000.0);
// Antiderivative of tri(x)^2, tri(x) = 1 - |2 frac(x) - 1| (period 1, mean 1/3).
float ScTriSqIntegral(float x)
@@ -177,6 +205,11 @@ float3 ScWaterShade(float coast, float elevM, float3 positionWS, float2 mapM, fl
float fresh = step(elevM, -100.0) * (1.0 - salt);
c = lerp(c, SRGBToLinear(float3(0.45, 0.78, 0.78)), salt * 0.8);
c = lerp(c, SRGBToLinear(ScGalileeSrgb), fresh * 0.7);
+ // Sea boats (#388): the zoom (the water's distance from the camera, not its pixel size) and the overview's shelf.
+ float viewM = length(_WorldSpaceCameraPos - positionWS);
+ float gameplay = _ScSeaCalm * (1.0 - smoothstep(ScZoomFades.x, ScZoomFades.y, viewM));
+ float overview = _ScSeaCalm * smoothstep(ScZoomFades.z, ScZoomFades.w, viewM);
+ c = lerp(c, SRGBToLinear(ScOverviewCoastSrgb), overview * ScOverviewBand * (1.0 - deepT) * (1.0 - shallow) * (1.0 - salt) * (1.0 - fresh));
float time = ScWaterClock();
// The swell: a 700 m gradient-noise layer turned 0.6 rad. Bug B10: it was value noise differenced along the map's axes
@@ -212,6 +245,10 @@ float3 ScWaterShade(float coast, float elevM, float3 positionWS, float2 mapM, fl
// Sea round 2: 0.12 under a 40 m pixel (the gameplay zoom's sparkle), easing to Task 7's 0.06 by 60 m, so nothing
// changes from 60 m out (the seam test's 120 km view).
float glint = lerp(0.12, 0.06, smoothstep(40.0, 60.0, footprintM)) * (1.0 - smoothstep(60.0, 120.0, footprintM));
+ // Sea boats (#388): the calm, on the open sea (behind "seatexture" too) at the gameplay zoom, from ScCalmNearM out.
+ float farOut = smoothstep(ScCalmNearM, ScCalmFarM, offshoreM) * _ScSeaTexture * (1.0 - salt) * (1.0 - fresh);
+ float calm = farOut * gameplay;
+ glint *= lerp(1.0, ScCalmGlint, calm);
lit += pow(saturate(dot(reflect(-l, n), v)), 80.0) * glint * lc * shadow;
// The far sea's texture (sea round 2, above): on open sea water only.
@@ -220,21 +257,24 @@ float3 ScWaterShade(float coast, float elevM, float3 positionWS, float2 mapM, fl
float nearRipple = 1.0 - smoothstep(50.0, 90.0, footprintM);
float ripple = ScRippleGain * nearRipple * clamp(dot(n.xz, viewXZ) * ScRippleScale, -1.0, 1.0)
+ ScRippleFarGain * (1.0 - nearRipple) * (1.0 - smoothstep(250.0, 450.0, footprintM)) * clamp(dot(swellSlope, viewXZ) * ScRippleFarScale, -1.0, 1.0);
+ ripple *= lerp(1.0, ScCalmRipple, calm);
float ms, mc; sincos(0.3, ms, mc);
float2 mp = mapM / ScMottleCellM;
mp = float2(mc * mp.x - ms * mp.y, (ms * mp.x + mc * mp.y) * ScMottleStretch); // streaks along the wind
- float mottle = ScGradientNoiseD(mp + float2(0.002, 0.001) * time).x + 0.8 * ScGradientNoiseD(mp * 2.7 + float2(5.3, 1.7)).x;
+ float mottle = lerp(1.0, ScCalmCoarse, calm) * ScGradientNoiseD(mp + float2(0.002, 0.001) * time).x
+ + 0.8 * lerp(1.0, ScCalmFine, calm) * ScGradientNoiseD(mp * 2.7 + float2(5.3, 1.7)).x;
mottle = clamp(mottle / 1.1, -1.0, 1.0);
float offshore = smoothstep(0.0, shallowEdge, offshoreM); // 0 in the turquoise shallows, 1 past them
mottle *= offshore;
// The shallows keep promo 03's pale turquoise: the ripple runs at 40% there (at full it darkened the band at 25 km).
- lit *= 1.0 + open * (ripple * lerp(0.4, 1.0, offshore) + ScMottleGain * mottle);
+ float broad = ScGradientNoiseD(mapM / ScBroadCellM + float2(11.3, 4.1)).x * calm;
+ lit *= 1.0 + open * (ripple * lerp(0.4, 1.0, offshore) + ScMottleGain * mottle + ScBroadGain * broad);
float2 cell = floor(mapM / ScFleckCellM);
float2 at = (cell + 0.35 + 0.3 * float2(ScHash(cell + 3.7), ScHash(cell + 9.1))) * ScFleckCellM;
float reach = max(ScFleckM, 0.6 * footprintM);
float fleck = step(ScHash(cell + 17.1), ScFleckShare * saturate(mottle * 1.5)) * (ScFleckM * ScFleckM) / (reach * reach)
* (1.0 - smoothstep(0.5 * reach, reach, length(mapM - at)))
- * (1.0 - smoothstep(40.0, 80.0, footprintM)) * smoothstep(300.0, 900.0, offshoreM) * open;
+ * (1.0 - smoothstep(40.0, 80.0, footprintM)) * smoothstep(300.0, 900.0, offshoreM) * (1.0 - calm) * open;
// Surf: the swash line, then breakers (crests every ScBreakerSpacingM, rolling in: the phase grows with time towards
// the shore; box-filtered over ScBreakers' width) whose crests break up along the coast (a 300 m noise, faded to its mean once a
diff --git a/unity/Assets/Tests/EditMode/SeaCraftTests.cs b/unity/Assets/Tests/EditMode/SeaCraftTests.cs
new file mode 100644
index 000000000..1ff16573f
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/SeaCraftTests.cs
@@ -0,0 +1,125 @@
+#nullable enable
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game.Map;
+using Statecraft.Game.Map.Kits;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+
+/// <summary>The boats (SeaCraft, refs #388): promo 03's white-sailed craft off the coast and moored in and off the harbours
+/// of Jaffa, Tel Aviv and Haifa, craft of the period only, every hull in open sea and off the harbour works, seeded, and
+/// drawn under the kits' root.</summary>
+public class SeaCraftTests
+{
+ [TearDown]
+ public void Restore()
+ {
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ VisualToggles.Clear();
+ KitScale.Reset();
+ }
+
+ static MapScene OpenMap()
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var map = Object.FindFirstObjectByType<MapScene>(); map.Build();
+ return map;
+ }
+
+ static KitGround Ground(MapScene map) =>
+ new KitGround(map.Terrain, map.Frame, map.Hexes, HeightmapLoader.Load(Statecraft.Game.Paths.StreamingMap).meta.elev_min_m);
+
+ static System.Collections.Generic.List<SettlementKits.Placed> Census(MapScene map, KitGround g)
+ {
+ SettlementKits.Build(map.Settlements, new System.Collections.Generic.List<Settlement>(), new System.Collections.Generic.List<Localities.Area>(), g, out var placed);
+ return placed;
+ }
+
+ static System.Collections.Generic.List<SeaCraft.Craft> Place(MapScene map, KitGround g) => SeaCraft.Place(g, Census(map, g));
+
+ /// <summary>About ten boats under way (feluccas and cutters, never a steamer) off the coast, two or more moored in or off
+ /// each of the three harbours with Haifa's coastal steamer at anchor among them, every hull and its margin in open sea (not a rift lake),
+ /// no two boats overlapping, and promo 03's size: a sailing boat about a quarter of a hex across (0.15-0.5 allowed).</summary>
+ [Test]
+ public void TheBoatsSailOffTheCoastAndMoorInTheHarbours()
+ {
+ var map = OpenMap();
+ var g = Ground(map);
+ var crafts = Place(map, g);
+ var under = crafts.Where(c => c.Kind == SeaCraft.Kind.Felucca || c.Kind == SeaCraft.Kind.Cutter).ToList();
+ TestContext.WriteLine(string.Join("\n", crafts.Select(c => $"{c.Kind} {c.Place} at {c.At} yaw {c.Yaw:0} length {c.Length:0} m")));
+ Assert.That(under.Count, Is.InRange(9, 12), "about ten boats under way");
+ foreach (var port in new[] { "jaffa", "tel_aviv", "haifa" })
+ Assert.GreaterOrEqual(crafts.Count(c => c.Place == port && (c.Kind == SeaCraft.Kind.Moored || c.Kind == SeaCraft.Kind.Steamer)), 2, port + ": moored craft");
+ Assert.AreEqual(1, crafts.Count(c => c.Kind == SeaCraft.Kind.Steamer && c.Place == "haifa"), "one coastal steamer, at anchor off Haifa");
+ float hexAcross = Mathf.Sqrt(3f) * g.HexSizeM;
+ foreach (var c in under) Assert.That(c.Length / hexAcross, Is.InRange(0.15f, 0.5f), "a sailing boat at promo 03's size");
+ foreach (var c in crafts)
+ {
+ var f = c.Forward; var side = new Vector2(-f.y, f.x);
+ foreach (var p in new[] { c.At, c.At + f * 0.5f * c.Length, c.At - f * 0.5f * c.Length, c.At + side * 0.15f * c.Length, c.At - side * 0.15f * c.Length })
+ {
+ Assert.IsTrue(g.Water(p.x, p.y), $"{c.Kind} at {c.Place}: in the water");
+ Assert.Greater(g.ElevM(p.x, p.y), -50f, $"{c.Kind} at {c.Place}: on the sea, not a rift lake");
+ }
+ foreach (var o in crafts)
+ if (!o.Equals(c)) Assert.Greater((o.At - c.At).magnitude, 0.5f * (o.Length + c.Length), $"{c.Kind} at {c.Place} overlaps a {o.Kind}");
+ }
+ }
+
+ /// <summary>Review of #536: no hull ever meets a harbour work. At five landmark scales (30-120, the default 60 among
+ /// them) and 16 draws each (SeaCraft.Place's salt), no boat's rectangle (its length by 30% of it) overlaps a
+ /// breakwater or mole piece the kits recorded at Jaffa, Tel Aviv or Haifa; the kits record some at each.</summary>
+ [Test]
+ public void NoHullEverMeetsABreakwaterOrMole()
+ {
+ var map = OpenMap();
+ int checkedBoats = 0;
+ foreach (var scale in new[] { 30f, 45f, 60f, 90f, 120f })
+ {
+ KitScale.CityBlocks = scale;
+ var g = Ground(map);
+ var placed = Census(map, g);
+ var works = placed.Where(p => p.Kind == "breakwater").ToList();
+ foreach (var port in new[] { "jaffa", "tel_aviv", "haifa" })
+ Assert.Greater(works.Count(w => w.Id == port), 0, $"{port}: the kits record its harbour works at scale {scale}");
+ for (ulong salt = 0; salt < 16; salt++)
+ foreach (var c in SeaCraft.Place(g, placed, salt))
+ {
+ checkedBoats++;
+ foreach (var w in works)
+ Assert.IsFalse(SeaCraft.Overlap(c.At, c.Yaw, 0.5f * c.Length, 0.15f * c.Length, w.C, w.Yaw, 0.5f * w.W, 0.5f * w.D),
+ $"scale {scale}, draw {salt}: a {c.Kind} at {c.Place} ({c.At}) meets a {w.Id} breakwater piece at {w.C}");
+ }
+ }
+ TestContext.WriteLine($"{checkedBoats} boats checked against the harbour works");
+ Assert.Greater(checkedBoats, 500);
+ }
+
+ /// <summary>The rectangle test itself: crossing, touching and parted rectangles, turned and not.</summary>
+ [Test]
+ public void TheRectangleOverlapTestIsRight()
+ {
+ Assert.IsTrue(SeaCraft.Overlap(Vector2.zero, 0f, 10f, 2f, new Vector2(0f, 0f), 90f, 10f, 2f), "a cross");
+ Assert.IsFalse(SeaCraft.Overlap(Vector2.zero, 0f, 10f, 2f, new Vector2(0f, 5f), 0f, 10f, 2f), "parallel, apart");
+ Assert.IsFalse(SeaCraft.Overlap(Vector2.zero, 45f, 10f, 1f, new Vector2(9f, 0f), 45f, 10f, 1f), "turned, side by side");
+ Assert.IsTrue(SeaCraft.Overlap(Vector2.zero, 45f, 10f, 1f, new Vector2(7f, 7f), 45f, 10f, 1f), "turned, end to end");
+ Assert.IsFalse(SeaCraft.Overlap(Vector2.zero, 0f, 10f, 2f, new Vector2(13f, 13f), 45f, 4f, 1f), "a corner apart");
+ }
+
+ /// <summary>Seeded: the same map places the same boats. They are drawn as one mesh under the kits' root, the "kits"
+ /// toggle hides them with the towns, and the build logs their count.</summary>
+ [Test]
+ public void TheBoatsAreSeededAndDrawnWithTheKits()
+ {
+ var map = OpenMap();
+ var a = Place(map, Ground(map)); var b = Place(map, Ground(map));
+ Assert.AreEqual(a.Count, b.Count);
+ for (int i = 0; i < a.Count; i++) { Assert.AreEqual(a[i].At, b[i].At); Assert.AreEqual(a[i].Yaw, b[i].Yaw); Assert.AreEqual(a[i].Kind, b[i].Kind); }
+ var boats = map.transform.Find(KitLayer.RootName).Find(KitLayer.SeaCraftName).GetComponent<MeshRenderer>();
+ Assert.AreEqual(a.Count, map.KitStats!.Boats);
+ Assert.IsTrue(boats.enabled);
+ VisualToggles.Set("kits", false);
+ Assert.IsFalse(boats.enabled, "the kits toggle hides the boats");
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/SeaCraftTests.cs.meta b/unity/Assets/Tests/EditMode/SeaCraftTests.cs.meta
new file mode 100644
index 000000000..627227a28
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/SeaCraftTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 0ca9b18ff048545198e8f481dde9a527
\ No newline at end of file
diff --git a/unity/Assets/Tests/EditMode/SeaTests.cs b/unity/Assets/Tests/EditMode/SeaTests.cs
index fb7817c52..d236dc72b 100644
--- a/unity/Assets/Tests/EditMode/SeaTests.cs
+++ b/unity/Assets/Tests/EditMode/SeaTests.cs
@@ -434,6 +434,185 @@ public class SeaTests
finally { Object.DestroyImmediate(go); }
}
+ /// <summary>Sea boats (#388, the 2026-10-13 gap audit): at the gameplay zoom the open sea calms away from the shore,
+ /// while the water near it keeps #402's texture. Rendered at gameplay03's distance (60 km, about 46 m a pixel) with the
+ /// water's clock pinned and the grid off, on one coast-texture row south of Jaffa (31.95 N): the fine texture (the mean
+ /// change between neighbouring pixels' luma, over a 25 x 25 window) 20 km out must be under
+ /// <see cref="FarOverNearTexture"/> of that 2.2 km out (past the surf, in the shallows' outer edge). On main the far
+ /// sea was the busier (far / near 0.89: its ripple ran at full strength, against the shallows' 40-100%); calmed, 0.23.</summary>
+ [UnityTest]
+ public IEnumerator TheOpenSeaCalmsAwayFromTheShore()
+ {
+ var map = OpenMap();
+ yield return null;
+ VisualToggles.Set("grid", false);
+ MapShaderGlobals.PinWaterTime(100f);
+ var coast = new Texture2D(2, 2);
+ coast.LoadImage(File.ReadAllBytes(MapTexturePaths.Coast));
+ int row = Mathf.FloorToInt((31.95f - 29.45f) / (33.35f - 29.45f) * coast.height);
+ int col = Mathf.FloorToInt((34.95f - 34.2f) / (35.9f - 34.2f) * coast.width);
+ while (col > 0 && coast.GetPixel(col, row).r >= 0.5f) col--;
+ Object.DestroyImmediate(coast);
+ Vector3 At(float offshoreM)
+ {
+ // The shore texel's centre, then due west (world -x) out to sea.
+ var shore = map.Frame.ToWorld(34.2 + (col + 0.5) / 2048.0 * (35.9 - 34.2), 29.45 + (row + 0.5) / 2048.0 * (33.35 - 29.45), 0);
+ var w = shore + Vector3.left * offshoreM; w.y = map.Terrain.SampleHeight(w); return w;
+ }
+ Vector3 near = At(2200f), far = At(20000f);
+ var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();
+ rig.LookAt = (near + far) * 0.5f; rig.Distance = 60000f; rig.Yaw = 0; rig.TopInset = 0; rig.Apply();
+ var px = new Vector2[2];
+ var r = RenderSample.Render(cam, 1920, 1080, new[] { near, far }, px);
+ float Texture(Vector2 p)
+ {
+ double sum = 0; int n = 0;
+ for (int y = (int)p.y - 12; y <= (int)p.y + 12; y++)
+ for (int x = (int)p.x - 12; x <= (int)p.x + 12; x++)
+ {
+ float l = Luma(r.At(x, y));
+ sum += Mathf.Abs(Luma(r.At(x + 1, y)) - l) + Mathf.Abs(Luma(r.At(x, y + 1)) - l); n++;
+ }
+ return (float)(sum / n);
+ }
+ float tn = Texture(px[0]), tf = Texture(px[1]);
+ TestContext.WriteLine($"fine texture 2.2 km out {tn:0.0000} (at {px[0]}), 20 km out {tf:0.0000} (at {px[1]}): far / near {tf / tn:0.00}");
+ Assert.Greater(tn, 0.005f, "the sea near the shore keeps its texture");
+ Assert.Less(tf / tn, FarOverNearTexture, "the open sea far from the shore is calmer than near it");
+ }
+
+ /// <summary>Bound for TheOpenSeaCalmsAwayFromTheShore.</summary>
+ const float FarOverNearTexture = 0.6f;
+
+ /// <summary>Sea boats (#388): at the overview (diorama02's pose, 190-300 m pixels) the sea along the coast reads as a
+ /// wide, lighter teal shelf over the deep blue, as promo 02's does: on the row of TheOpenSeaCalmsAwayFromTheShore, the
+ /// water 5 km out is lighter than 25 km out by at least <see cref="OverviewShelfOverDeep"/> in luma (a mean over 5 x 5
+ /// pixels, the water's clock pinned, the grid off). Main measured 0.048 (the depth ramp alone), the band 0.086.</summary>
+ [UnityTest]
+ public IEnumerator TheOverviewSeaIsLighterAlongTheCoast()
+ {
+ var map = OpenMap();
+ yield return null;
+ VisualToggles.Set("grid", false);
+ MapShaderGlobals.PinWaterTime(100f);
+ var coast = new Texture2D(2, 2);
+ coast.LoadImage(File.ReadAllBytes(MapTexturePaths.Coast));
+ int row = Mathf.FloorToInt((31.95f - 29.45f) / (33.35f - 29.45f) * coast.height);
+ int col = Mathf.FloorToInt((34.95f - 34.2f) / (35.9f - 34.2f) * coast.width);
+ while (col > 0 && coast.GetPixel(col, row).r >= 0.5f) col--;
+ Object.DestroyImmediate(coast);
+ var shore = map.Frame.ToWorld(34.2 + (col + 0.5) / 2048.0 * (35.9 - 34.2), 29.45 + (row + 0.5) / 2048.0 * (33.35 - 29.45), 0);
+ Vector3 At(float offshoreM) { var w = shore + Vector3.left * offshoreM; w.y = map.Terrain.SampleHeight(w); return w; }
+ var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();
+ PromoPose.Diorama02.Apply(rig, map.Frame); rig.TopInset = 0; rig.Apply();
+ var px = new Vector2[2];
+ var r = RenderSample.Render(cam, 1920, 1080, new[] { At(5000f), At(25000f) }, px);
+ Color shelf = r.Mean((int)px[0].x, (int)px[0].y, 2), deep = r.Mean((int)px[1].x, (int)px[1].y, 2);
+ TestContext.WriteLine($"overview: 5 km out {shelf} (luma {Luma(shelf):0.000}, at {px[0]}), 25 km out {deep} (luma {Luma(deep):0.000}, at {px[1]})");
+ Assert.Greater(Luma(shelf), Luma(deep) + OverviewShelfOverDeep, "the coastal shelf is lighter than the deep sea at the overview");
+ }
+
+ /// <summary>Bound for TheOverviewSeaIsLighterAlongTheCoast.</summary>
+ const float OverviewShelfOverDeep = 0.07f;
+
+ /// <summary>World points on the water <paramref name="offshoreM"/> due west of the shore, on coast-texture rows from 31.6 to
+ /// 32.4 N every 0.1 degree (south of Gaza's latitude to north of Netanya's): the shore is each row's first water texel
+ /// walking west from 34.95 E.</summary>
+ static Vector3[] OffshorePoints(MapScene map, float[] offshoreM)
+ {
+ var coast = new Texture2D(2, 2);
+ coast.LoadImage(File.ReadAllBytes(MapTexturePaths.Coast));
+ var points = new System.Collections.Generic.List<Vector3>();
+ for (float lat = 31.6f; lat <= 32.41f; lat += 0.1f)
+ {
+ int row = Mathf.FloorToInt((lat - 29.45f) / (33.35f - 29.45f) * coast.height);
+ int col = Mathf.FloorToInt((34.95f - 34.2f) / (35.9f - 34.2f) * coast.width);
+ while (col > 0 && coast.GetPixel(col, row).r >= 0.5f) col--;
+ var shore = map.Frame.ToWorld(34.2 + (col + 0.5) / 2048.0 * (35.9 - 34.2), 29.45 + (row + 0.5) / 2048.0 * (33.35 - 29.45), 0);
+ foreach (var d in offshoreM) { var w = shore + Vector3.left * d; w.y = map.Terrain.SampleHeight(w); points.Add(w); }
+ }
+ Object.DestroyImmediate(coast);
+ return points.ToArray();
+ }
+
+ /// <summary>The largest channel change (0-255) over 3 x 3 pixels round each projected point between a render with the
+ /// "seacalm" toggle on and one with it off (the water's clock pinned, the grid and the tilt-shift off), at a pose and
+ /// a resolution.</summary>
+ static float SeaCalmChange(MapScene map, PromoPose pose, Vector3[] points, out int onScreen, int width = 1920, int height = 1080)
+ {
+ VisualToggles.Set("grid", false);
+ MapShaderGlobals.PinWaterTime(100f);
+ var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();
+ pose.Apply(rig, map.Frame); rig.TopInset = 0; rig.Apply();
+ var px = new Vector2[points.Length];
+ var on = RenderSample.Render(cam, width, height, points, px);
+ VisualToggles.Set("seacalm", false);
+ var off = RenderSample.Render(cam, width, height, points, px);
+ VisualToggles.Set("seacalm", true);
+ float worst = 0f; onScreen = 0;
+ foreach (var p in px)
+ {
+ if (p.x < 2 || p.y < 2 || p.x > width - 3 || p.y > height - 3) continue;
+ onScreen++;
+ for (int y = (int)p.y - 1; y <= (int)p.y + 1; y++)
+ for (int x = (int)p.x - 1; x <= (int)p.x + 1; x++)
+ {
+ Color a = on.At(x, y), b = off.At(x, y);
+ worst = Mathf.Max(worst, 255f * Mathf.Max(Mathf.Abs(a.r - b.r), Mathf.Max(Mathf.Abs(a.g - b.g), Mathf.Abs(a.b - b.b))));
+ }
+ }
+ return worst;
+ }
+
+ /// <summary>Review of #536: at the gameplay zoom nothing of the sea boats' sea changes the water within 3.4 km of the
+ /// shore, the surf, the shallows (whose edge reaches at most 3.5 km) and the near-coast chop: with "seacalm" on and off,
+ /// gameplay03 renders those points the same. Fails if the calm starts at the shore (ScCalmNearM 0) or if the overview's
+ /// shelf reaches the gameplay zoom.</summary>
+ [UnityTest]
+ public IEnumerator TheGameplayZoomKeepsTheNearShoreSea()
+ {
+ var map = OpenMap();
+ yield return null;
+ var points = OffshorePoints(map, new[] { 300f, 900f, 1600f, 2400f, 3000f, 3400f });
+ float worst = SeaCalmChange(map, PromoPose.Gameplay03, points, out int seen);
+ TestContext.WriteLine($"gameplay03: {seen} near-shore points on screen, largest change with seacalm off {worst:0.0}/255");
+ Assert.Greater(seen, 20, "enough of the near-shore points are on screen");
+ Assert.AreEqual(0f, worst, "the near-shore sea is unchanged at the gameplay zoom");
+ }
+
+ /// <summary>Review of #536: the overview gets no calm and no broad swells, at any resolution. Past the shelf's reach
+ /// (ScCoastRangeM, 12 km), 15-40 km out, diorama02 renders the open sea the same with "seacalm" on and off, at 1920 x 1080
+ /// and at 3840 x 2160 (a device pixel ratio of 2, where a pixel covers half the metres). Fails if the calm or the swells
+ /// lose their fade with the zoom, or fade with the pixel size instead (then the 2160p render calms).</summary>
+ [UnityTest]
+ public IEnumerator TheOverviewGetsNoCalmOrSwells()
+ {
+ var map = OpenMap();
+ yield return null;
+ var points = OffshorePoints(map, new[] { 15000f, 20000f, 25000f, 30000f, 40000f });
+ foreach (var (w, h) in new[] { (1920, 1080), (3840, 2160) })
+ {
+ float worst = SeaCalmChange(map, PromoPose.Diorama02, points, out int seen, w, h);
+ TestContext.WriteLine($"diorama02 at {w}x{h}: {seen} open-sea points on screen, largest change with seacalm off {worst:0.0}/255");
+ Assert.Greater(seen, 20, "enough of the open-sea points are on screen");
+ Assert.AreEqual(0f, worst, $"the overview's open sea is unchanged at {w}x{h}");
+ }
+ }
+
+ /// <summary>Review of #536: the coastal shelf is the overview's and only the overview's. At diorama02 the water 4-8 km out
+ /// changes with "seacalm" (the shelf is on there); TheGameplayZoomKeepsTheNearShoreSea checks the gameplay zoom has none
+ /// of it.</summary>
+ [UnityTest]
+ public IEnumerator TheShelfShowsAtTheOverview()
+ {
+ var map = OpenMap();
+ yield return null;
+ var points = OffshorePoints(map, new[] { 4000f, 6000f, 8000f });
+ float worst = SeaCalmChange(map, PromoPose.Diorama02, points, out int seen);
+ TestContext.WriteLine($"diorama02: {seen} shelf points on screen, largest change with seacalm off {worst:0.0}/255");
+ Assert.Greater(worst, 3f, "the shelf lightens the coastal water at the overview");
+ }
+
/// <summary>Rendered: the Dead Sea is pale turquoise, much lighter than the open Mediterranean.</summary>
[UnityTest]
public IEnumerator TheDeadSeaIsPalerThanTheOpenSea()