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: keep the navy's ships' hulls off the land at Haifa (Refs #3038) (#3039)

Eyal Golan99e52a97a19b
diff --git a/changelog.d/3038-haifa-ship.md b/changelog.d/3038-haifa-ship.md
new file mode 100644
index 000000000..489202285
--- /dev/null
+++ b/changelog.d/3038-haifa-ship.md
@@ -0,0 +1,4 @@
+### Fixed
+- The navy's ships at Haifa no longer stand on Mount Carmel (Refs #3038): a ship's spot was the centre of its sea hex, and
+ the hex west of Haifa, more than half sea, has its centre on the Carmel headland, so INS Haganah stood half on land. A
+ ship's whole drawn hull must now lie in the water; INS Haganah stands in Haifa Bay and INS Wedgwood off the cape.
diff --git a/docs/units.md b/docs/units.md
index 6c36e18e4..96d869e4e 100644
--- a/docs/units.md
+++ b/docs/units.md
@@ -423,7 +423,8 @@ A spot is clear when:
aircraft's centre, are on land and at least 700 m beyond every railway and road corridor drawn while a token
stands (a route opened after the last anchor's window, the 1949 rail link or the 1950 Tel Aviv–Netanya road, takes no
spot; #786);
-- a ship has a sea hex;
+- a ship has a sea hex, and its whole drawn hull (the corvette, 6.0 km by 0.96 km at its heading) lies in the drawn
+ water; a ship tries the hex centres, then the points inside its sea hexes, and is never compact (#3038);
- no other anchor whose window overlaps holds the hex.
**Own side.** The map holds no 1948 front line yet, and the one-hex limit alone does not keep a token on its own side:
diff --git a/unity/Assets/Scripts/Map/MapScene.cs b/unity/Assets/Scripts/Map/MapScene.cs
index 9fd051894..ca5efcddd 100644
--- a/unity/Assets/Scripts/Map/MapScene.cs
+++ b/unity/Assets/Scripts/Map/MapScene.cs
@@ -798,7 +798,7 @@ namespace Statecraft.Game.Map
var unitHexes = Hexes.hexes.Select(h => new Statecraft.Sim.MapHex { Q = h.q, R = h.r, Lon = h.lon, Lat = h.lat, ElevM = h.elev_m, Land = h.land, Biome = h.biome }).ToList();
UnitHexes = unitHexes;
var unitGround = new Units.UnitGround(SettlementFootprints, RouteCorridors, unitHexes,
- (lon, lat) => { var w = Frame.ToWorld(lon, lat, 0); return new Vector2(w.x, w.z); }, hexSizeM);
+ (lon, lat) => { var w = Frame.ToWorld(lon, lat, 0); return new Vector2(w.x, w.z); }, hexSizeM, Units.UnitLayer.Water(this));
var clearings = new List<(Vector2 centre, float radius)>();
var unitRings = new List<(Vector2 centre, float radius)>();
var datedRings = new List<(Vector2 centre, float radius, DateTime until)>();
diff --git a/unity/Assets/Scripts/Map/Units/UnitGround.cs b/unity/Assets/Scripts/Map/Units/UnitGround.cs
index ad469fdf8..b794b034d 100644
--- a/unity/Assets/Scripts/Map/Units/UnitGround.cs
+++ b/unity/Assets/Scripts/Map/Units/UnitGround.cs
@@ -31,12 +31,15 @@ namespace Statecraft.Game.Map.Units
readonly (List<Vector2> line, float half, Rect bounds)[] corridors;
readonly IReadOnlyList<MapHex> hexes;
readonly Vector2[] hexXZ;
+ readonly Func<float, float, bool>? water;
public readonly float HexSizeM;
+ /// <param name="water">(x, z): true where the drawn map is water (KitGround.Water over the map's terrain). With it, a
+ /// ship's whole drawn hull must lie in water (<see cref="HullInWater"/>); null: a ship needs only its sea hex.</param>
public UnitGround(IReadOnlyList<(Vector2 centre, float radius)> footprints, IReadOnlyList<(List<Vector2> line, float halfWidth)> routeCorridors,
- IReadOnlyList<MapHex> hexes, Func<double, double, Vector2> toXZ, float hexSizeM)
+ IReadOnlyList<MapHex> hexes, Func<double, double, Vector2> toXZ, float hexSizeM, Func<float, float, bool>? water = null)
{
- this.footprints = footprints; this.hexes = hexes; HexSizeM = hexSizeM;
+ this.footprints = footprints; this.hexes = hexes; HexSizeM = hexSizeM; this.water = water;
hexXZ = hexes.Select(h => toXZ(h.Lon, h.Lat)).ToArray();
corridors = routeCorridors.Where(c => c.line.Count > 0).Select(c =>
{
@@ -80,11 +83,12 @@ namespace Statecraft.Game.Map.Units
/// town (the full parked-aircraft span for air, the ring for other services), except an army token in
/// <paramref name="inTown"/> may enter the town its <paramref name="anchor"/> stands in (the kits then keep a clearing
/// for it there, never in a neighbouring town), and its figures (an army token's trio, a parked
- /// aircraft's centre) on land and off the railways and roads. A ship needs only the sea hex the placer already
- /// checked.</summary>
+ /// aircraft's centre) on land and off the railways and roads. A ship needs its sea hex (the placer checks it) and,
+ /// when this ground knows the water, its whole drawn hull in the water (issue #3038: INS Haganah stood on Mount
+ /// Carmel's headland at the centre of a hex that is more than half sea).</summary>
public bool Clear(string service, Vector2 centre, bool compact, bool inTown, Vector2 anchor)
{
- if (service == UnitData.Navy) return true;
+ if (service == UnitData.Navy) return water == null || HullInWater(centre, water);
float disc = ClearanceRadius(service, compact);
foreach (var (fc, fr) in footprints)
{
@@ -105,6 +109,35 @@ namespace Statecraft.Game.Map.Units
return true;
}
+ /// <summary>The drawn ship's length and beam on the map (m): UnitModels.Corvette's 63.4 m hull, 10.1 m across at its
+ /// waterline band (radius 5.0 m, widened 1.01), at <see cref="UnitShowcase.ShipScale"/>. Every navy token draws that
+ /// mesh (UnitLayer).</summary>
+ public const float ShipLengthM = 63.4f * UnitShowcase.ShipScale, ShipBeamM = 10.1f * UnitShowcase.ShipScale;
+
+ /// <summary>The spacing (m) of the hull's samples: under the heightmap's finer sample spacing (about 79 m east-west,
+ /// 210 m north-south), so no strip of land as wide as a sample slips between two of them.</summary>
+ public const float HullSampleM = 75f;
+
+ /// <summary>The points of the drawn hull's rectangle (<see cref="ShipLengthM"/> by <see cref="ShipBeamM"/>, its bow
+ /// turned <see cref="UnitShowcase.ShipHeadingDegrees"/> about the vertical as UnitLayer draws it, from +z towards +x),
+ /// at most <see cref="HullSampleM"/> apart along and across it, its edges and corners included.</summary>
+ public static IEnumerable<Vector2> HullPoints(Vector2 centre)
+ {
+ float a = UnitShowcase.ShipHeadingDegrees * Mathf.Deg2Rad;
+ var bow = new Vector2(Mathf.Sin(a), Mathf.Cos(a)); var side = new Vector2(bow.y, -bow.x);
+ int n = Mathf.CeilToInt(ShipLengthM / HullSampleM), m = Mathf.CeilToInt(ShipBeamM / HullSampleM);
+ for (int i = 0; i <= n; i++)
+ for (int j = 0; j <= m; j++)
+ yield return centre + bow * ShipLengthM * (i / (float)n - 0.5f) + side * ShipBeamM * (j / (float)m - 0.5f);
+ }
+
+ /// <summary>True when every point of the drawn hull (<see cref="HullPoints"/>) is water.</summary>
+ public static bool HullInWater(Vector2 centre, Func<float, float, bool> water)
+ {
+ foreach (var p in HullPoints(centre)) if (!water(p.x, p.y)) return false;
+ return true;
+ }
+
bool LandAt(Vector2 p)
{
int best = -1; float bestD = float.MaxValue;
diff --git a/unity/Assets/Scripts/Map/Units/UnitLayer.cs b/unity/Assets/Scripts/Map/Units/UnitLayer.cs
index c9a6eb857..17392fc77 100644
--- a/unity/Assets/Scripts/Map/Units/UnitLayer.cs
+++ b/unity/Assets/Scripts/Map/Units/UnitLayer.cs
@@ -676,9 +676,15 @@ namespace Statecraft.Game.Map.Units
Vector3 Centre(AnchorSpot s) => UnitShowcase.Ground(map, new Vector3((float)s.X, 0f, (float)s.Z));
- /// <summary>The ground the units are placed on (footprints, routes, land) for a built map.</summary>
+ /// <summary>The ground the units are placed on (footprints, routes, land, and the water a ship's hull must lie in) for a
+ /// built map.</summary>
public static UnitGround Ground(MapScene map, IReadOnlyList<MapHex> hexes) =>
- new UnitGround(map.SettlementFootprints, map.RouteCorridors, hexes, XZ(map), map.Hexes.hex_size_km * 1000f);
+ new UnitGround(map.SettlementFootprints, map.RouteCorridors, hexes, XZ(map), map.Hexes.hex_size_km * 1000f, Water(map));
+
+ /// <summary>The built map's drawn water (KitGround.Water over its terrain: the sea is the heightmap's 0 m), which a ship's
+ /// whole hull must lie in (issue #3038); null before the terrain is built.</summary>
+ public static Func<float, float, bool>? Water(MapScene map) =>
+ map.Terrain == null ? null : new Kits.KitGround(map.Terrain, map.Frame, map.Hexes, map.ElevMinM).Water;
static Func<double, double, Vector2> XZ(MapScene map) => (lon, lat) => { var w = map.Frame.ToWorld(lon, lat, 0); return new Vector2(w.x, w.z); };
diff --git a/unity/Assets/Scripts/Map/Units/UnitPlacer.cs b/unity/Assets/Scripts/Map/Units/UnitPlacer.cs
index 726a27d4a..5159ea3e7 100644
--- a/unity/Assets/Scripts/Map/Units/UnitPlacer.cs
+++ b/unity/Assets/Scripts/Map/Units/UnitPlacer.cs
@@ -48,6 +48,7 @@ namespace Statecraft.Game.Map.Units
/// (Majdal, the Egyptian rear base, whose nearest clear ground lies 3.5 km south-west of its point, west of Ni'ilya). It
/// runs last, so an anchor that found a spot in rounds 1-3 keeps it; a spot it finds holds its hex like any other.
/// Ranked as above (by distance to a `toward` point when the anchor has one).
+ /// A ship tries rounds 1 and 2 only, and its spot is never compact (it is drawn at its one size; issue #3038).
/// A spot must be land (sea for a ship), on a hex no other anchor with an overlapping window holds, and clear (the
/// caller's test: the ring off the settlement footprints except in round 3, the figures on land and off the railways
/// and roads). An anchor with no such spot is left out and reported. The map holds no 1948 front line yet: where the
@@ -104,6 +105,9 @@ namespace Statecraft.Game.Map.Units
AnchorSpot? best = null;
foreach (var round in new[] { 1, 2, 3, 4 })
{
+ // A ship tries its sea hexes' centres, then the points inside them (issue #3038: a centre can stand
+ // on a headland, and the hull must lie wholly in the water); never a town or the mesh.
+ if (sea && round > 2) break;
bool compact = round > 1, inTown = round == 3;
double bestD = double.MaxValue, bestDepth = double.MaxValue;
var points = round == 4 ? Mesh(centres, p, maxOffset)
@@ -125,10 +129,10 @@ namespace Statecraft.Game.Map.Units
// Ties go to the lower (q, r): the result never depends on the hex list's order.
if (depth == bestDepth && d == bestD && best != null && (h.Q, h.R).CompareTo((best.Value.Q, best.Value.R)) > 0) continue;
if (!clear(u.Service, x, z, compact, inTown, p.x, p.z)) continue;
- best = new AnchorSpot(h.Q, h.R, x, z, compact, inTown && overlap > 0); bestD = d; bestDepth = depth;
+ // A ship is drawn at its one size wherever it stands, so its spot is never compact.
+ best = new AnchorSpot(h.Q, h.R, x, z, compact && !sea, inTown && overlap > 0); bestD = d; bestDepth = depth;
}
if (best != null) break;
- if (sea) break; // a ship's sea hex is all its test; rounds 2 and 3 add nothing
}
if (best == null) { skipped?.Invoke(SkipMessage(u, a)); continue; }
held.Add((best.Value.Q, best.Value.R, from, to));
diff --git a/unity/Assets/Tests/EditMode/UnitPlacerSpeedTests.cs b/unity/Assets/Tests/EditMode/UnitPlacerSpeedTests.cs
index e4815967a..e4f4e8f3b 100644
--- a/unity/Assets/Tests/EditMode/UnitPlacerSpeedTests.cs
+++ b/unity/Assets/Tests/EditMode/UnitPlacerSpeedTests.cs
@@ -16,7 +16,9 @@ using static Statecraft.Game.Map.Units.UnitPlacer;
/// reference), for any ground: the spots decide where every unit token stands.</summary>
public class UnitPlacerSpeedTests
{
- /// <summary>UnitPlacer.PlaceAll, Candidates, Inside and Nearest as they were before issue #321's change, verbatim.</summary>
+ /// <summary>UnitPlacer.PlaceAll, Candidates, Inside and Nearest as they were before issue #321's change, verbatim, but
+ /// for the two marked lines of issue #3038 (a ship's rounds and its spot's size), which change the result and not the
+ /// speed.</summary>
static class Reference
{
public static Dictionary<UnitAnchor, AnchorSpot> PlaceAll(IReadOnlyList<UnitEntry> units, IReadOnlyList<MapHex> hexes, double hexSizeM,
@@ -45,6 +47,7 @@ public class UnitPlacerSpeedTests
AnchorSpot? best = null;
foreach (var round in new[] { 1, 2, 3 })
{
+ if (sea && round > 2) break; // since issue #3038 (not part of #321's change): a ship tries rounds 1 and 2
bool compact = round > 1, inTown = round == 3;
double bestD = double.MaxValue, bestDepth = double.MaxValue;
foreach (var (i, x, z) in Candidates(hexes, centres, hexSizeM, compact, a.Toward != null ? target : ((double, double)?)null))
@@ -63,10 +66,9 @@ public class UnitPlacerSpeedTests
// Ties go to the lower (q, r): the result never depends on the hex list's order.
if (depth == bestDepth && d == bestD && best != null && (h.Q, h.R).CompareTo((best.Value.Q, best.Value.R)) > 0) continue;
if (!clear(u.Service, x, z, compact, inTown, p.x, p.z)) continue;
- best = new AnchorSpot(h.Q, h.R, x, z, compact, inTown && overlap > 0); bestD = d; bestDepth = depth;
+ best = new AnchorSpot(h.Q, h.R, x, z, compact && !sea, inTown && overlap > 0); bestD = d; bestDepth = depth; // #3038: a ship is never compact
}
if (best != null) break;
- if (sea) break; // a ship's sea hex is all its test; rounds 2 and 3 add nothing
}
if (best == null) { skipped?.Invoke($"UNITS no clear spot within one hex of {a.Place} for {u.Id}"); continue; }
held.Add((best.Value.Q, best.Value.R, from, to));
diff --git a/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs b/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs
index 2ac7c3866..3c23bae60 100644
--- a/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs
+++ b/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs
@@ -441,6 +441,45 @@ public class UnitsInPlayTests
static Material Load(string name) => AssetDatabase.LoadAssetAtPath<Material>($"Assets/Materials/{name}.mat");
+ /// <summary>Issue #3038 (the owner, 10 November 2026: "one of the ships near haifa is half on the land"): a ship's spot was
+ /// only its sea hex's centre, and hex (5, 9), more than half sea, has its centre on Mount Carmel's headland (about 44 m up),
+ /// so INS Haganah stood across the cape. Every ship's drawn hull, the corvette mesh's own footprint (its bounds) at
+ /// UnitShowcase.ShipScale and ShipHeadingDegrees, now lies wholly in the drawn water, sampled every 25 m.</summary>
+ [Test]
+ public void EveryShipsDrawnHullLiesWhollyInWater()
+ {
+ var map = BuildMap();
+ try
+ {
+ var units = Units; // one parse: the layer's spots are keyed by these anchors (UnitAnchor has reference equality)
+ var layer = UnitLayer.Create(map, units, C.Hexes, still: true);
+ var ground = new Statecraft.Game.Map.Kits.KitGround(map.Terrain, map.Frame, map.Hexes, map.ElevMinM);
+ var mesh = UnitModels.Corvette("hull-test");
+ var size = mesh.bounds.size * UnitShowcase.ShipScale; var mid = mesh.bounds.center * UnitShowcase.ShipScale;
+ UnityEngine.Object.DestroyImmediate(mesh);
+ var turn = Quaternion.Euler(0f, UnitShowcase.ShipHeadingDegrees, 0f);
+ int ships = 0;
+ foreach (var u in units.Where(u => UnitRoster.OnMap(u) && u.Service == UnitData.Navy))
+ foreach (var a in u.Anchors)
+ {
+ Assert.IsTrue(layer.Spots.TryGetValue(a, out var s), $"{u.Id} {a.Place}: no spot");
+ ships++;
+ int n = Mathf.CeilToInt(size.z / 25f), m = Mathf.CeilToInt(size.x / 25f), wet = 0, dry = 0;
+ for (int i = 0; i <= n; i++)
+ for (int j = 0; j <= m; j++)
+ {
+ var local = new Vector3(mid.x + size.x * (j / (float)m - 0.5f), 0f, mid.z + size.z * (i / (float)n - 0.5f));
+ var p = new Vector3((float)s.X, 0f, (float)s.Z) + turn * local;
+ if (ground.Water(p.x, p.z)) wet++; else dry++;
+ }
+ TestContext.WriteLine($"{u.Id} {a.Place} at {s}: {dry} of {wet + dry} hull points on land");
+ Assert.AreEqual(0, dry, $"{u.Id} {a.Place} at {s}: its drawn hull stands on land");
+ }
+ Assert.AreEqual(2, ships, "INS Haganah and INS Wedgwood");
+ }
+ finally { UnityEngine.Object.DestroyImmediate(map.gameObject); }
+ }
+
/// <summary>Review I2 and M9: every anchor gets one spot, from the data alone, within one hex step of its sourced
/// place, clear of the towns' footprints and, for the figures, of the railways and roads by the full clearance; no two
/// anchors whose windows overlap share a hex. Each spot and its distance is logged.</summary>