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: a parked aircraft keeps houses, trees and its badge off itself (Refs #2729) (#2751)

Eyal Golaneb4fbd1e3dac
diff --git a/changelog.d/2729.md b/changelog.d/2729.md
new file mode 100644
index 000000000..83c2ec830
--- /dev/null
+++ b/changelog.d/2729.md
@@ -0,0 +1,3 @@
+### Fixed
+
+- Keep houses and orchard trees clear of a parked 101 Squadron aircraft token, and keep its badge off its tail.
diff --git a/docs/units.md b/docs/units.md
index bbe60f795..dedbe2c91 100644
--- a/docs/units.md
+++ b/docs/units.md
@@ -412,7 +412,8 @@ The candidates are tried in four rounds:
round-4 spot holds its hex like any other; measured on the game map, no other anchor and no camp moved).
A spot is clear when:
-- the ring's disc stays off every settlement footprint (the kits' discs, times 1.1);
+- the ring's disc stays off every settlement footprint (the kits' discs, times 1.1); for an air anchor the disc is the
+ larger of that ring and the parked aircraft's span (4.7 km across, which does not compact), with no in-town exception;
- an army token's three figure spots (always three, so the spot does not change with the call-up), or a parked
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
@@ -447,6 +448,9 @@ and a unit the sim moves is placed without the control layer.
its two 1948 photographs. Every other brigade has the uniform default (bush hat, steel helmet, bush hat), from the 1948
photographs listed under "Sources".
- **Air:** the squadron flies the slice's loop over its base at security level 4 or 5 and stands parked below that.
+ A parked aircraft leaves a circular tree hole covering its drawn world-XZ footprint. Its camera-facing badge stays clear of the
+ aircraft's tail (the rear 40%) as the camera sees it, moving down, left or right on screen by the least that clears
+ it, never up, so it stays by the aircraft; a flying aircraft gets neither adjustment.
- **Navy:** a ship is the K-20 corvette model; Wedgwood was the same modified Flower class.
- **Badge:** each token has the promo's badge (`UnitBadge`): a dark rounded plate with an ivory glyph (two figures, an
aircraft or a ship). It is turned to face each camera as it renders. On an army token it sits above the flag's top, a little
diff --git a/unity/Assets/Scripts/Map/Kits/KitGround.cs b/unity/Assets/Scripts/Map/Kits/KitGround.cs
index 892984c8a..1bac5a10a 100644
--- a/unity/Assets/Scripts/Map/Kits/KitGround.cs
+++ b/unity/Assets/Scripts/Map/Kits/KitGround.cs
@@ -209,11 +209,11 @@ namespace Statecraft.Game.Map.Kits
return false;
}
- /// <summary>The unit tokens that stand outside every footprint (centre x, z; ring radius m; MapScene). The Bedouin camps,
+ /// <summary>The unit tokens that stand outside every footprint (centre x, z; footprint radius m; MapScene). The Bedouin camps,
/// the one kit placed where no footprint is, keep off them (units-in-play merge, review I5).</summary>
public readonly List<(Vector2 centre, float radius)> Tokens = new List<(Vector2, float)>();
- /// <summary>True when a disc of radius <paramref name="r"/> at <paramref name="p"/> reaches a unit token's ring.</summary>
+ /// <summary>True when a disc of radius <paramref name="r"/> at <paramref name="p"/> reaches a unit token's footprint.</summary>
public bool OnToken(Vector2 p, float r)
{
foreach (var (c, tr) in Tokens) if ((p - c).sqrMagnitude < (tr + r) * (tr + r)) return true;
diff --git a/unity/Assets/Scripts/Map/MapScene.cs b/unity/Assets/Scripts/Map/MapScene.cs
index b714ea262..69aab8fca 100644
--- a/unity/Assets/Scripts/Map/MapScene.cs
+++ b/unity/Assets/Scripts/Map/MapScene.cs
@@ -635,11 +635,12 @@ namespace Statecraft.Game.Map
? UnitEntries : Units.UnitData.ReadOrNone(yaml, warn);
/// <summary>Where the kits keep their buildings and trees off the units (centre x, z; radius m): the spot of a unit that
- /// stands in a town (UnitPlacer's last round, UnitGround.ClearingRadius), so no token stands in a building. Empty before
+ /// stands in a town (UnitPlacer's last round, UnitGround.ClearingRadius), so no token stands in a building. An air
+ /// anchor uses the parked fighter's footprint; every other service keeps the compact ring. Empty before
/// Build or without the unit file.</summary>
public IReadOnlyList<(Vector2 centre, float radius)> UnitClearings { get; private set; } = new List<(Vector2, float)>();
- /// <summary>The unit tokens that stand outside the towns (centre x, z; ring radius m), as the kits get them
+ /// <summary>The unit tokens that stand outside the towns (centre x, z; footprint radius m), as the kits get them
/// (KitGround.Tokens), with the day the token's window ends (its anchor's `to`, exclusive): the transit camps
/// PlacementLayer builds later keep off those still present on the camp's date (KitGround.DatedTokens). Empty before
/// Build.</summary>
@@ -807,11 +808,17 @@ namespace Statecraft.Game.Map
foreach (var kv in spots.OrderBy(k => k.Value.X).ThenBy(k => k.Value.Z))
{
var c = new Vector2((float)kv.Value.X, (float)kv.Value.Z);
- if (kv.Value.InTown && !clearings.Exists(x => x.centre == c)) clearings.Add((c, unitGround.ClearingRadius));
+ var service = unitData.First(u => u.Anchors.Contains(kv.Key)).Service;
+ if (kv.Value.InTown && !clearings.Exists(x => x.centre == c))
+ {
+ // Only an air anchor gets the parked fighter's span; army census clearings keep their compact radius.
+ clearings.Add((c, unitGround.ClearingRadius(service)));
+ }
else if (!kv.Value.InTown)
{
- unitRings.Add((c, unitGround.RingRadius(kv.Value.Compact)));
- datedRings.Add((c, unitGround.RingRadius(kv.Value.Compact), Units.UnitData.Day(kv.Key.To)));
+ float radius = unitGround.ClearanceRadius(service, kv.Value.Compact);
+ unitRings.Add((c, radius));
+ datedRings.Add((c, radius, Units.UnitData.Day(kv.Key.To)));
}
}
}
diff --git a/unity/Assets/Scripts/Map/Units/UnitGround.cs b/unity/Assets/Scripts/Map/Units/UnitGround.cs
index 1c3a07345..ad469fdf8 100644
--- a/unity/Assets/Scripts/Map/Units/UnitGround.cs
+++ b/unity/Assets/Scripts/Map/Units/UnitGround.cs
@@ -21,6 +21,11 @@ namespace Statecraft.Game.Map.Units
public const float FigureClearanceM = 700f;
/// <summary>A compact token (beside or in a town) draws its ring and trio at this share of the full size.</summary>
public const float CompactScale = 0.5f;
+ /// <summary>The radius a parked 101 Squadron fighter keeps clear at the approved aircraft scale: the Spitfire's
+ /// full-wing 11.23 m span at 420x, a conservative bound above the clipped wing of the LF Mk IXe the token shows
+ /// (about 10.2 m: every Spitfire flown to Israel in the war had it, Efrati p. 14; docs/units.md). Placement must not
+ /// depend on which authored mesh has arrived.</summary>
+ public const float ParkedAircraftClearanceM = 11.23f * UnitShowcase.AircraftScale * 0.5f;
readonly IReadOnlyList<(Vector2 centre, float radius)> footprints;
readonly (List<Vector2> line, float half, Rect bounds)[] corridors;
@@ -44,8 +49,15 @@ namespace Statecraft.Game.Map.Units
/// <summary>The ground ring's radius of a token (m).</summary>
public float RingRadius(bool compact) => UnitShowcase.RingRadius * HexSizeM * (compact ? CompactScale : 1f);
- /// <summary>The radius (m) the kits keep clear round a token that stands in a town: its compact ring.</summary>
- public float ClearingRadius => RingRadius(compact: true);
+ /// <summary>The radius (m) the kits keep clear round a token that stands in a town: the parked fighter's span for an
+ /// air anchor, and the existing compact ring for every other service.</summary>
+ public float ClearingRadius(string service) => service == UnitData.Air ? ParkedAircraftClearanceM : RingRadius(compact: true);
+
+ /// <summary>The footprint placement keeps clear of towns: an air token keeps clear by the larger of its ring and the
+ /// parked fighter's span (the span does not compact; the full ring stays where it is wider), every other service by
+ /// its ring.</summary>
+ public float ClearanceRadius(string service, bool compact) =>
+ service == UnitData.Air ? Math.Max(ParkedAircraftClearanceM, RingRadius(compact)) : RingRadius(compact);
/// <summary>The figures' ground points of an army token standing at <paramref name="centre"/>: always the full trio,
/// so a spot does not change with the call-up.</summary>
@@ -64,18 +76,21 @@ namespace Statecraft.Game.Map.Units
return worst;
}
- /// <summary>True when a token of <paramref name="service"/> may stand at <paramref name="centre"/>: its ring off every
- /// town, except, when <paramref name="inTown"/>, the town its anchor <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
+ /// <summary>True when a token of <paramref name="service"/> may stand at <paramref name="centre"/>: its footprint off every
+ /// 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>
public bool Clear(string service, Vector2 centre, bool compact, bool inTown, Vector2 anchor)
{
if (service == UnitData.Navy) return true;
- float disc = RingRadius(compact);
+ float disc = ClearanceRadius(service, compact);
foreach (var (fc, fr) in footprints)
{
- bool own = inTown && (fc - anchor).magnitude < fr * FootprintMargin;
+ // A town may make a kit clearing for an army token. An aircraft's whole parked footprint instead has to
+ // clear every town; it must not win round 3 merely because its compact token ring fits at the anchor.
+ bool own = service != UnitData.Air && inTown && (fc - anchor).magnitude < fr * FootprintMargin;
if (!own && fr * FootprintMargin + disc - (fc - centre).magnitude > 0f) return false;
}
var points = service == UnitData.Army ? FigurePoints(centre, compact) : new[] { centre };
diff --git a/unity/Assets/Scripts/Map/Units/UnitLayer.cs b/unity/Assets/Scripts/Map/Units/UnitLayer.cs
index 8a7d1c9e9..dbfe5a625 100644
--- a/unity/Assets/Scripts/Map/Units/UnitLayer.cs
+++ b/unity/Assets/Scripts/Map/Units/UnitLayer.cs
@@ -119,7 +119,8 @@ namespace Statecraft.Game.Map.Units
/// any view, the camera's yaw and steepness alike), its flag's pole from the middle (zero for none), the flag (null for
/// none) and the box of the token's pieces that neither turn nor move (null for a flying aircraft alone). In the order
/// of <see cref="badges"/> and <see cref="keepClear"/>.</summary>
- readonly List<(Vector3 home, float back, Vector3 pole, MeshFilter? flag, Bounds? standing)> badgeHomes = new List<(Vector3, float, Vector3, MeshFilter?, Bounds?)>();
+ readonly List<(Vector3 home, float back, Vector3 pole, MeshFilter? flag, Bounds? standing, bool parkedAircraft)> badgeHomes =
+ new List<(Vector3, float, Vector3, MeshFilter?, Bounds?, bool)>();
/// <summary>Each token's figures as laid out for camera yaw 0 (their place round the base's middle and their heading),
/// the base's middle and radius, the badge's lift over the highest figure and the figures' meshes (none for an aircraft
/// or a ship), in the order of <see cref="badges"/>. <see cref="FaceCamera"/> turns the figures and the flag's pole
@@ -133,6 +134,10 @@ namespace Statecraft.Game.Map.Units
/// <see cref="BadgeAsideM"/> to the side away from its flag's pole on screen (a compact token's pole cannot stand
/// further out than its base's edge).</summary>
public const float BadgeBackShare = 0.6f, BadgeAsideM = 400f, BadgeOverFlagM = 150f;
+ /// <summary>#2729: a parked aircraft's badge must not cover its tail, the rear <see cref="BadgeTailShare"/> of its
+ /// length, as the camera sees it. When it would, the badge moves on screen by the least of down, left or right that
+ /// clears the tail by <see cref="BadgeTailGapPixels"/>, never up, so it stays by the aircraft and under the HUD.</summary>
+ public const float BadgeTailShare = 0.4f, BadgeTailGapPixels = 4f;
readonly List<(Vector2 centre, float radius)> treeHoles = new List<(Vector2, float)>();
List<Bounds[]> keepClear = new List<Bounds[]>();
/// <summary>A slide moves the boxes in place, but the labels re-place only for a new list: FaceCamera then hands
@@ -269,7 +274,7 @@ namespace Statecraft.Game.Map.Units
void OnEnable() => RenderPipelineManager.beginCameraRendering += FaceBadges;
void OnDisable() => RenderPipelineManager.beginCameraRendering -= FaceBadges;
- /// <summary>The kit trees under the drawn figures, left out while the layer shows (issue #249).</summary>
+ /// <summary>The kit trees under drawn figure plinths and parked-aircraft footprints, left out while the layer shows.</summary>
public IReadOnlyList<(Vector2 centre, float radius)> TreeHoles => treeHoles;
void HideTrees() => UnitShowcase.HideTrees(map, ToggleName, gameObject.activeSelf ? treeHoles : (IReadOnlyList<(Vector2, float)>)Array.Empty<(Vector2, float)>());
@@ -321,7 +326,7 @@ namespace Statecraft.Game.Map.Units
// A moving token's root stands off the origin by its slide (UnitTokenMotion); its pieces are placed in the
// world here, so they take the same offset, and the boxes follow the token as drawn, not its destination.
var slide = b.parent.position;
- var (home, back, pole, flag, standing) = badgeHomes[i];
+ var (home, back, pole, flag, standing, parkedAircraft) = badgeHomes[i];
var (centre, radius, lift, figures, meshes) = trios[i];
if (turn && figures.Length > 0)
{
@@ -334,7 +339,7 @@ namespace Statecraft.Game.Map.Units
figure.SetPositionAndRotation(p + slide, Quaternion.Euler(0f, yaw + heading, 0f));
}
home.y = highest + lift; // the badge clears the highest figure, wherever the turn set it
- badgeHomes[i] = (home, back, pole, flag, standing);
+ badgeHomes[i] = (home, back, pole, flag, standing, parkedAircraft);
if (flag != null)
{
var foot = centre + turning * pole;
@@ -350,6 +355,22 @@ namespace Statecraft.Game.Map.Units
// stays where the full plate's is, clear of the flag and the figures; that move keeps the plate's depth.
float size = UnitBadge.SizeFor(Vector3.Dot(at - eye, forward), m11, orthographic);
at -= up * (0.5f * (UnitBadge.SizeM - size));
+ if (parkedAircraft && b.parent.Find("Aircraft") is Transform plane && TailScreenRect(plane, cam) is Rect tail)
+ for (int k = 0; k < 3; k++)
+ {
+ float half = 0.5f * size;
+ var plate = ScreenRect(cam, at - right * half - up * half, at - right * half + up * half,
+ at + right * half - up * half, at + right * half + up * half);
+ if (!plate.Overlaps(tail)) break;
+ var c = cam.WorldToScreenPoint(at);
+ float perUp = cam.WorldToScreenPoint(at + up).y - c.y, perRight = cam.WorldToScreenPoint(at + right).x - c.x;
+ if (perUp <= 1e-5f || perRight <= 1e-5f) break;
+ float down = plate.yMax - tail.yMin + BadgeTailGapPixels;
+ float left = plate.xMax - tail.xMin + BadgeTailGapPixels, rightward = tail.xMax - plate.xMin + BadgeTailGapPixels;
+ if (down <= left && down <= rightward) at -= up * (down / perUp);
+ else if (left <= rightward) at -= right * (left / perRight);
+ else at += right * (rightward / perRight);
+ }
b.SetPositionAndRotation(at, rotation);
b.localScale = Vector3.one * size;
var boxes = keepClear[i];
@@ -813,6 +834,11 @@ namespace Statecraft.Game.Map.Units
break;
case UnitData.Air:
BuildAircraft(go.transform, t, centre);
+ if (!t.Flying && StillBox(go.transform, null, Array.Empty<MeshFilter>()) is Bounds aircraft)
+ {
+ var flat = new Vector2(aircraft.center.x, aircraft.center.z);
+ treeHoles.Add((flat, new Vector2(aircraft.extents.x, aircraft.extents.z).magnitude));
+ }
top = UnitBadge.FigureHeightM * UnitShowcase.FigureScale;
break;
default:
@@ -838,7 +864,7 @@ namespace Statecraft.Game.Map.Units
var pole = flagT != null ? new Vector3(flagT.position.x - centre.x, 0f, flagT.position.z - centre.z) : Vector3.zero;
var meshes = figures.SelectMany(f => f.Item1.GetComponentsInChildren<MeshFilter>(true)).ToArray();
var standing = StillBox(go.transform, flag, meshes);
- badges.Add(badge.transform); badgeHomes.Add((home, back, pole, flag, standing));
+ badges.Add(badge.transform); badgeHomes.Add((home, back, pole, flag, standing, t.Unit.Service == UnitData.Air && !t.Flying));
trios.Add((centre, plinth, lift, figures, meshes));
AddRenderer(badge.transform, "Plate", MeshFor("badge-plate", UnitBadge.PlateMesh), badgePlate, 0f);
var hitFlash = AddRenderer(badge.transform, "HitFlash", MeshFor("badge-plate", UnitBadge.PlateMesh),
@@ -985,6 +1011,42 @@ namespace Statecraft.Game.Map.Units
return r;
}
+ /// <summary>The screen box of <paramref name="plane"/>'s tail, the rear <see cref="BadgeTailShare"/> of its meshes' box
+ /// along its own z axis (the way it faces), or null before any mesh has arrived.</summary>
+ static Rect? TailScreenRect(Transform plane, Camera cam)
+ {
+ Vector3 min = Vector3.positiveInfinity, max = Vector3.negativeInfinity;
+ foreach (var f in plane.GetComponentsInChildren<MeshFilter>(true))
+ {
+ if (f.sharedMesh == null) continue;
+ var bounds = f.sharedMesh.bounds;
+ for (int c = 0; c < 8; c++)
+ {
+ var p = plane.InverseTransformPoint(f.transform.TransformPoint(new Vector3((c & 1) == 0 ? bounds.min.x : bounds.max.x,
+ (c & 2) == 0 ? bounds.min.y : bounds.max.y, (c & 4) == 0 ? bounds.min.z : bounds.max.z)));
+ min = Vector3.Min(min, p); max = Vector3.Max(max, p);
+ }
+ }
+ if (min.x > max.x) return null;
+ max.z = Mathf.Lerp(min.z, max.z, BadgeTailShare);
+ var corners = new Vector3[8];
+ for (int c = 0; c < 8; c++)
+ corners[c] = plane.TransformPoint(new Vector3((c & 1) == 0 ? min.x : max.x, (c & 2) == 0 ? min.y : max.y, (c & 4) == 0 ? min.z : max.z));
+ return ScreenRect(cam, corners);
+ }
+
+ /// <summary>The screen box round <paramref name="points"/> as <paramref name="cam"/> projects them.</summary>
+ static Rect ScreenRect(Camera cam, params Vector3[] points)
+ {
+ float x0 = float.MaxValue, y0 = float.MaxValue, x1 = float.MinValue, y1 = float.MinValue;
+ foreach (var p in points)
+ {
+ var q = cam.WorldToScreenPoint(p);
+ x0 = Mathf.Min(x0, q.x); y0 = Mathf.Min(y0, q.y); x1 = Mathf.Max(x1, q.x); y1 = Mathf.Max(y1, q.y);
+ }
+ return Rect.MinMaxRect(x0, y0, x1, y1);
+ }
+
void BuildAircraft(Transform parent, UnitToken t, Vector3 baseCentre)
{
var plane = new GameObject("Aircraft");
diff --git a/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs b/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs
index 72033ba53..cc58b3cad 100644
--- a/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs
+++ b/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs
@@ -451,6 +451,7 @@ public class UnitsInPlayTests
var hexAt = C.Hexes.ToDictionary(h => (h.Q, h.R));
var anchors = units.Where(UnitRoster.OnMap).SelectMany(u => u.Anchors.Select(a => (u, a))).ToList();
var log = new List<string>();
+ int airChecked = 0;
foreach (var (u, a) in anchors)
{
var at = $"{u.Id} {a.Place}";
@@ -470,7 +471,12 @@ public class UnitsInPlayTests
}
else
{
- float disc = UnitShowcase.RingRadius * hex * (s.Compact ? UnitGround.CompactScale : 1f);
+ // #2729: an air token keeps clear by the larger of its ring and the parked aircraft's span; every other
+ // service by its ring, as before.
+ float disc = layer.PlacementGround.ClearanceRadius(u.Service, s.Compact);
+ // Review (#2751, fresh eyes): the expected clearance comes from the placement's own helper, so pin the air
+ // span independently of it: a parked aircraft keeps at least its full-wing span clear (ParkedSpanRadiusM).
+ if (u.Service == UnitData.Air) { airChecked++; Assert.GreaterOrEqual(disc, ParkedSpanRadiusM, $"{at}: the air clearance covers the parked span"); }
foreach (var (fc, fr) in map.SettlementFootprints)
Assert.GreaterOrEqual((fc - c).magnitude, fr * UnitGround.FootprintMargin + disc, $"{at}: the ring reaches a town's buildings");
}
@@ -487,6 +493,7 @@ public class UnitsInPlayTests
bool overlap = UnitData.Day(a.From) < UnitData.Day(b.To) && UnitData.Day(b.From) < UnitData.Day(a.To);
if (overlap) Assert.AreNotEqual((layer.Spots[a].Q, layer.Spots[a].R), (layer.Spots[b].Q, layer.Spots[b].R), $"{anchors[i].u.Id} and {anchors[j].u.Id} share a hex");
}
+ Assert.Greater(airChecked, 0, "an air anchor outside the towns was checked against the parked span");
Debug.Log("UNITS spots\n" + string.Join("\n", log));
// Review MF1: the anchors whose nearest clear spot was the other side's ground stand on their own side (Etzioni in
// West Jerusalem; Harel by Saris on the corridor road), and the 7th Brigade is anchored at Hulda, not Latrun.
@@ -543,7 +550,8 @@ public class UnitsInPlayTests
continue;
}
outside++;
- float ring = layer.PlacementGround.RingRadius(s.Compact);
+ float ring = layer.PlacementGround.ClearanceRadius(u.Service, s.Compact); // #2729: the span for a parked aircraft
+ if (u.Service == UnitData.Air) Assert.GreaterOrEqual(ring, ParkedSpanRadiusM, $"{at}: the air clearance covers the parked span");
foreach (var (fc, fr, id) in footprints)
{
float reach = fr * (id.StartsWith("camp:") ? 1f : UnitGround.FootprintMargin) + ring;
@@ -674,6 +682,188 @@ public class UnitsInPlayTests
return plinths.Any(f => (f.centre - at).sqrMagnitude < (f.radius + crown) * (f.radius + crown));
}
+ static Bounds MeshBounds(Transform root, bool local)
+ {
+ Bounds? all = null;
+ foreach (var f in root.GetComponentsInChildren<MeshFilter>(true))
+ {
+ if (f.sharedMesh == null || f.GetComponentInParent<UnitBadge>(true) != null) continue;
+ var b = f.sharedMesh.bounds;
+ for (int c = 0; c < 8; c++)
+ {
+ var p = f.transform.TransformPoint(new Vector3((c & 1) == 0 ? b.min.x : b.max.x,
+ (c & 2) == 0 ? b.min.y : b.max.y, (c & 4) == 0 ? b.min.z : b.max.z));
+ if (local) p = root.InverseTransformPoint(p);
+ if (all is Bounds a) { a.Encapsulate(p); all = a; } else all = new Bounds(p, Vector3.zero);
+ }
+ }
+ Assert.IsTrue(all.HasValue, root.name + " has mesh geometry");
+ return all!.Value;
+ }
+
+ static Rect ScreenRect(Camera cam, IEnumerable<Vector3> points)
+ {
+ float x0 = float.MaxValue, y0 = float.MaxValue, x1 = float.MinValue, y1 = float.MinValue;
+ foreach (var p in points)
+ {
+ var q = cam.WorldToScreenPoint(p);
+ x0 = Mathf.Min(x0, q.x); y0 = Mathf.Min(y0, q.y); x1 = Mathf.Max(x1, q.x); y1 = Mathf.Max(y1, q.y);
+ }
+ return Rect.MinMaxRect(x0, y0, x1, y1);
+ }
+
+ static IEnumerable<Vector3> Corners(Bounds b)
+ {
+ for (int c = 0; c < 8; c++)
+ yield return new Vector3((c & 1) == 0 ? b.min.x : b.max.x, (c & 2) == 0 ? b.min.y : b.max.y,
+ (c & 4) == 0 ? b.min.z : b.max.z);
+ }
+
+ static Transform Aircraft(MapScene map) => map.Terrain.transform.Find(UnitLayer.RootName).Find("Tokens/squadron_101/Aircraft");
+
+ /// <summary>Issue #2729 option 1: the parked fighter gets one circular tree hole centred on its renderer footprint's
+ /// world-XZ box and reaching all four corners. The planted-tree assertion makes the hide check bite.</summary>
+ [Test]
+ public void ParkedSquadronLeavesNoKitTreeUnderItsFootprint()
+ {
+ // Red-first prediction at ae4bfdaab: fails because the air branch adds no tree hole.
+ var map = BuildMapWithTrees();
+ try
+ {
+ var veg = map.GetComponentInChildren<Statecraft.Game.Map.Kits.VegetationLayer>(true);
+ var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);
+ layer.Show(SimBridgeGddTests.Legacy, StateAt(new DateTime(1948, 10, 20), 1, 0.8));
+ var aircraft = Aircraft(map); Assert.IsNull(aircraft.GetComponent<ShowcaseFlight>(), "security below 4 parks the aircraft");
+ var bounds = MeshBounds(aircraft, local: false);
+ var centre = new Vector2(bounds.center.x, bounds.center.z);
+ var holes = layer.TreeHoles.Where(h => (h.centre - centre).sqrMagnitude < 1f).ToList();
+ Assert.AreEqual(1, holes.Count, "the parked aircraft has exactly one renderer-sized tree hole");
+ foreach (var x in new[] { bounds.min.x, bounds.max.x })
+ foreach (var z in new[] { bounds.min.z, bounds.max.z })
+ Assert.LessOrEqual((new Vector2(x, z) - holes[0].centre).magnitude, holes[0].radius + 0.1f,
+ "every corner of the aircraft's world-XZ footprint is in its tree hole");
+ bool Intersects(Statecraft.Game.Map.Kits.TreeKind kind, Matrix4x4 m)
+ {
+ var p = m.GetColumn(3); float crown = Statecraft.Game.Map.Kits.VegetationLayer.CrownRadius(kind, m);
+ return (new Vector2(p.x, p.z) - holes[0].centre).magnitude < holes[0].radius + crown;
+ }
+ Assert.Greater(veg.Planted().Count(t => Intersects(t.kind, t.m)), 0, "some planted tree reaches the aircraft footprint");
+ Assert.IsFalse(veg.Drawable().Any(t => Intersects(t.kind, t.m)), "no drawn crown reaches the parked aircraft footprint");
+ }
+ finally { UnityEngine.Object.DestroyImmediate(map.gameObject); }
+ }
+
+ /// <summary>Issue #2729 option 1: the parked fighter's conservative footprint is the sourced 11.23 m span at 420x,
+ /// as a disc about its renderer centre; no planned town-model rectangle may meet that disc.</summary>
+ /// <summary>#2729: the parked fighter's clearance radius at the approved aircraft scale (the Spitfire's full-wing
+ /// 11.23 m span at UnitShowcase.AircraftScale, a conservative bound above the clipped LF Mk IXe's about 10.2 m, Efrati
+ /// p. 14), written here so the test builds before the fix too.</summary>
+ const float ParkedSpanRadiusM = 11.23f * UnitShowcase.AircraftScale * 0.5f;
+
+ [Test]
+ public void ParkedSquadronStandsClearOfTownBuildings()
+ {
+ // Red-first prediction at ae4bfdaab: fails at the compact Herzliya-area spot, whose clearing is only the token ring.
+ var map = BuildMapWithTrees();
+ try
+ {
+ var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);
+ layer.Show(SimBridgeGddTests.Legacy, StateAt(new DateTime(1948, 10, 20), 1, 0.8));
+ var aircraft = Aircraft(map); Assert.IsNull(aircraft.GetComponent<ShowcaseFlight>(), "security below 4 parks the aircraft");
+ var b = MeshBounds(aircraft, local: false); var flat = new Vector2(b.center.x, b.center.z);
+ var towns = map.GetComponentInChildren<Statecraft.Game.Map.Kits.TownModelLayer>(true);
+ int examined = 0;
+ foreach (var f in map.KitFootprints)
+ foreach (var house in towns.InstancesOf(f.id))
+ {
+ examined++;
+ var local = Quaternion.Euler(0f, -house.Yaw, 0f) * new Vector3(flat.x - house.C.x, 0f, flat.y - house.C.y);
+ var near = new Vector2(Mathf.Clamp(local.x, -0.5f * house.W, 0.5f * house.W),
+ Mathf.Clamp(local.z, -0.5f * house.D, 0.5f * house.D));
+ Assert.GreaterOrEqual((new Vector2(local.x, local.z) - near).magnitude, ParkedSpanRadiusM,
+ $"the parked fighter overlaps {f.id}'s {house.Model} at {house.C}");
+ }
+ Assert.Greater(examined, 0, "planned town houses were examined");
+ }
+ finally { UnityEngine.Object.DestroyImmediate(map.gameObject); }
+ }
+
+ /// <summary>Issue #2729: at the reported 12 km close view, the tail region is the rear 40% of the aircraft's local-Z
+ /// mesh box (the model contract faces +Z). Its projected rectangle must not meet the projected badge rectangle.</summary>
+ [Test]
+ public void ParkedAircraftBadgeDoesNotCoverItsTailRegion()
+ {
+ // Red-first prediction at ae4bfdaab: fails because the air badge remains at the token centre with no airframe offset.
+ var map = BuildMap(); var cam = Camera.main; var oldPosition = cam.transform.position; var oldRotation = cam.transform.rotation;
+ var oldTarget = cam.targetTexture; var target = new RenderTexture(1920, 1080, 0); cam.targetTexture = target;
+ try
+ {
+ var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);
+ layer.Show(SimBridgeGddTests.Legacy, StateAt(new DateTime(1948, 10, 20), 1, 0.8));
+ var aircraft = Aircraft(map); Assert.IsNull(aircraft.GetComponent<ShowcaseFlight>(), "security below 4 parks the aircraft");
+ var local = MeshBounds(aircraft, local: true);
+ local.max = new Vector3(local.max.x, local.max.y, Mathf.Lerp(local.min.z, local.max.z, 0.4f));
+ var tail = Corners(local).Select(aircraft.TransformPoint).ToList();
+ cam.transform.rotation = Quaternion.Euler(CameraRig.Pitch, 0f, 0f);
+ cam.transform.position = aircraft.position - cam.transform.forward * 12000f;
+ layer.FaceCamera(cam);
+ var badge = aircraft.parent.Find("Badge"); float half = badge.lossyScale.x * 0.5f;
+ var badgeRect = ScreenRect(cam, new[] { badge.position - cam.transform.right * half - cam.transform.up * half,
+ badge.position - cam.transform.right * half + cam.transform.up * half, badge.position + cam.transform.right * half - cam.transform.up * half,
+ badge.position + cam.transform.right * half + cam.transform.up * half });
+ Assert.IsFalse(badgeRect.Overlaps(ScreenRect(cam, tail)), "the badge does not cover the projected rear 40% of the parked fighter");
+ // #2729 captures: a badge pushed up past the whole aircraft went under the HUD (12 km) and onto a neighbour's plinth
+ // (31 km). On screen it now stays within one plate of the aircraft: no higher than one plate above its top (where an
+ // unmoved badge stands), and not beyond its sides.
+ var plane = ScreenRect(cam, Corners(MeshBounds(aircraft, local: true)).Select(aircraft.TransformPoint));
+ Assert.LessOrEqual(badgeRect.yMax, plane.yMax + badgeRect.height + 1f, "the badge is not pushed up past the parked aircraft");
+ Assert.IsTrue(badgeRect.center.x >= plane.xMin - badgeRect.width && badgeRect.center.x <= plane.xMax + badgeRect.width
+ && badgeRect.center.y >= plane.yMin - badgeRect.height, "the badge stays by the parked aircraft");
+ int token = layer.Tokens.ToList().FindIndex(p => p.Token.Unit.Id == "squadron_101");
+ Assert.AreEqual(badge.position, layer.KeepClear[token][0].center, "the names' keep-clear follows the offset badge");
+ }
+ finally
+ {
+ cam.targetTexture = oldTarget; cam.transform.SetPositionAndRotation(oldPosition, oldRotation);
+ UnityEngine.Object.DestroyImmediate(target); UnityEngine.Object.DestroyImmediate(map.gameObject);
+ }
+ }
+
+ /// <summary>Issue #2729 regression guard: a flying aircraft keeps no tree hole and its badge keeps the old centred home,
+ /// including the existing close-view size adjustment.</summary>
+ [Test]
+ public void FlyingAircraftTokenKeepsItsTreeAndBadgeBehaviour()
+ {
+ // Red-first prediction at ae4bfdaab: passes before the fix; it guards the required flying-token non-change and is
+ // intentionally not weakened.
+ var map = BuildMapWithTrees(); var cam = Camera.main; var oldPosition = cam.transform.position; var oldRotation = cam.transform.rotation;
+ var oldTarget = cam.targetTexture; var target = new RenderTexture(1920, 1080, 0); cam.targetTexture = target;
+ try
+ {
+ var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);
+ layer.Show(SimBridgeGddTests.Legacy, StateAt(new DateTime(1948, 10, 20), 5, 0.8));
+ var aircraft = Aircraft(map); Assert.IsNotNull(aircraft.GetComponent<ShowcaseFlight>(), "security 5 flies the aircraft");
+ var token = aircraft.parent; var badge = token.Find("Badge");
+ var spot = layer.Tokens.Single(p => p.Token.Unit.Id == "squadron_101").Spot;
+ var centre = UnitShowcase.Ground(map, new Vector3((float)spot.X, 0f, (float)spot.Z));
+ cam.transform.rotation = Quaternion.Euler(CameraRig.Pitch, 0f, 0f);
+ cam.transform.position = centre - cam.transform.forward * 12000f;
+ layer.FaceCamera(cam);
+ var home = centre + Vector3.up * (UnitBadge.FigureHeightM * UnitShowcase.FigureScale + UnitBadge.LiftM);
+ float size = UnitBadge.SizeFor(Vector3.Dot(home - cam.transform.position, cam.transform.forward), cam.projectionMatrix[1, 1], cam.orthographic);
+ var expected = home - cam.transform.up * (0.5f * (UnitBadge.SizeM - size));
+ Assert.Less((badge.position - expected).magnitude, 0.1f, "the flying badge retains its centred pre-#2729 position");
+ Assert.AreEqual(size, badge.lossyScale.x, 0.1f, "the flying badge retains its close-view size");
+ var airBounds = MeshBounds(aircraft, local: false); var airCentre = new Vector2(airBounds.center.x, airBounds.center.z);
+ Assert.IsFalse(layer.TreeHoles.Any(h => (h.centre - airCentre).sqrMagnitude < 1f), "a flying aircraft adds no tree hole");
+ }
+ finally
+ {
+ cam.targetTexture = oldTarget; cam.transform.SetPositionAndRotation(oldPosition, oldRotation);
+ UnityEngine.Object.DestroyImmediate(target); UnityEngine.Object.DestroyImmediate(map.gameObject);
+ }
+ }
+
/// <summary>Issue #249: on every date the units are checked on, no kit tree that is drawn has its crown within a shown
/// figure's boots (the boot radius plus the tree's crown radius), and some trees were in the way, so the check bites.</summary>
[Test]