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: the Egyptian Spitfire's propeller turns, it banks and casts a soft shadow, and it flies Egypt's flag (Refs #2014 #2238) (#2260)

Eyal Golan573b9d7ac6ff
diff --git a/.gitignore b/.gitignore
index e0606a5d5..8585af733 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,8 @@ promo/*.log
.worktrees/
tools/.cache/
__pycache__/
+# Unity writes a folder meta beside a Python cache folder under Assets; it is not an asset.
+__pycache__.meta
sim/**/bin/
sim/**/obj/
spikes/m0/build/
diff --git a/changelog.d/2260-spitfire-propeller.md b/changelog.d/2260-spitfire-propeller.md
new file mode 100644
index 000000000..779664d03
--- /dev/null
+++ b/changelog.d/2260-spitfire-propeller.md
@@ -0,0 +1,8 @@
+### Fixed
+- The Egyptian Spitfire now reads as flying and as Egyptian (owner's report of 2 November 2026): a blurred propeller
+ turns at its nose, it banks into the turns at the ends of its loop, a soft shadow lies on the ground below it where
+ the map's sun casts it, and a small Egyptian flag, the same flag the Egyptian units on the map fly, floats just
+ above its tail (owner's ruling: "Smaller flag, no pole"). The map labels keep clear of the whole box it flies
+ through, banked or not and with its flag, also after another model is unloaded (which used to shrink that box to
+ one pose). Presentation only; screenshots and editor renders hold the loop's start. The sim goldens did not move
+ (Refs #2014, #2238).
diff --git a/unity/Assets/Scripts/Map/Collection/SeaAirCollection.cs b/unity/Assets/Scripts/Map/Collection/SeaAirCollection.cs
index adf7356ca..84182b89a 100644
--- a/unity/Assets/Scripts/Map/Collection/SeaAirCollection.cs
+++ b/unity/Assets/Scripts/Map/Collection/SeaAirCollection.cs
@@ -19,7 +19,8 @@ namespace Statecraft.Game.Map.Collection
/// turn stands at one place, so it stands off Tel Aviv, where it ran aground and burned;</item>
/// <item>a C-54 at Lod (Lydda) Airport while Operation Magic Carpet's main airlift ran, from July 1949 to its last flights
/// into Lydda on 24 September 1950 (<see cref="C54From"/>, <see cref="C54To"/>);</item>
- /// <item>the Egyptian Spitfire flying a slow loop near the western board edge (about 30 km in) toward el-Arish and back (<see cref="SpitfireLoop"/>), from 15 May 1948 to 2 January 1949
+ /// <item>the Egyptian Spitfire flying a slow loop near the western board edge (about 30 km in) toward el-Arish and back (<see cref="SpitfireLoop"/>),
+ /// banked into its turns, its propeller turning, its shadow on the ground and a small Egyptian flag over its tail, from 15 May 1948 to 2 January 1949
/// (<see cref="SpitfireFrom"/>, <see cref="SpitfireTo"/>, #1932), never on a hex or an airfield.</item>
/// </list>
/// The boats lie on the open sea past the surf, where SeaCraft's own boats sail (SeaCraft.OffshoreNearM to OffshoreM out
@@ -164,6 +165,54 @@ namespace Statecraft.Game.Map.Collection
/// the session has run.</summary>
static float LoopAngle(float seconds) => 2f * Mathf.PI * Mathf.Repeat(seconds, SpitfireLoopSeconds) / SpitfireLoopSeconds;
+ /// <summary>The loop's curvature (1/m) <paramref name="seconds"/> into it: for x = a sin t, z = -b cos t,
+ /// ab / (a² cos² t + b² sin² t)^(3/2). Least on the passes (b / a², at 0 and half a period) and most at the turns at
+ /// the ends (a / b², a quarter and three quarters of a period in).</summary>
+ public static float LoopCurvature(float seconds)
+ {
+ float t = LoopAngle(seconds), a = SpitfireLoopHalfLengthM, b = SpitfireLoopHalfWidthM;
+ float c = Mathf.Cos(t), s = Mathf.Sin(t);
+ return a * b / Mathf.Pow(a * a * c * c + b * b * s * s, 1.5f);
+ }
+
+ /// <summary>DESIGN VALUE: the bank (degrees, into the turn) for a path's <paramref name="curvature"/> (1/m), so the
+ /// aircraft reads as flying round its loop (owner's report, 2 November 2026: "it doesnt look fliying"): none on a
+ /// straight or on this loop's passes (its least curvature, b / a²), the unit tokens' aircraft bank
+ /// (UnitShowcase.BankDegrees, 28 degrees) at its tightest turns (a / b²), and in between in proportion. A real
+ /// coordinated turn would bank by v² / (g r), which at the map's speeds and radii is past 80 degrees: a gentle,
+ /// readable bank is the aim, not that.</summary>
+ public static float BankFor(float curvature)
+ {
+ float a = SpitfireLoopHalfLengthM, b = SpitfireLoopHalfWidthM, least = b / (a * a), most = a / (b * b);
+ return Statecraft.Game.Map.Units.UnitShowcase.BankDegrees * Mathf.Clamp01((curvature - least) / (most - least));
+ }
+
+ /// <summary>The Spitfire's bank <paramref name="seconds"/> into its loop (degrees, its inner wing down):
+ /// <see cref="BankFor"/> the loop's curvature there.</summary>
+ public static float LoopBankDegrees(float seconds) => BankFor(LoopCurvature(seconds));
+
+ /// <summary>The Spitfire's parts beside its airframe: the propeller disc (a child of its mesh), and the object, next
+ /// to the aircraft in this layer, that holds its shadow and its flag (they do not bank or turn with it).</summary>
+ public const string SpitfirePropellerName = "Propeller", SpitfireMarksSuffix = "-marks", SpitfireShadowName = "Shadow", SpitfireFlagName = "Flag";
+
+ /// <summary>DESIGN VALUES for the propeller disc on the fused mesh, from the model's FBX vertices
+ /// (generated-1948-13-egyptian-spitfire.fbx, read 2 November 2026): the spinner's tip is the mesh's front-most point
+ /// (-y), on its centre line, 0.70 of the model's height up; the still blades stand 0.03-0.13 of its length behind the
+ /// front, reach about 0.11 of the span above and below the hub (one blade tip is the model's highest point) and up to
+ /// 0.18 of it sideways. The disc's centre stands <see cref="PropBehindNoseShare"/> of the mesh's length behind its
+ /// front, <see cref="PropRadiusShare"/> of its span in radius, its top at the mesh's top (its hub then 0.63 of the
+ /// height up, a little under the spinner's tip), so its box stays inside the airframe's (see Propeller). A wider disc
+ /// would rise over the model's top; so the still blades' outer parts still show past its rim.</summary>
+ public const float PropRadiusShare = 0.118f, PropBehindNoseShare = 0.065f;
+
+ /// <summary>The disc is two blurs, <see cref="PropLayer"/> of its radius in front of and behind its centre, so the blur
+ /// lies over the blades' roots whether the camera sees the aircraft from ahead or from behind.</summary>
+ public const float PropLayer = 0.3f;
+
+ /// <summary>DESIGN VALUE: the shadow's length and width over the aircraft's seen from above: a little larger, so its
+ /// soft rim (fading to nothing) leaves a dark core about the aircraft's size.</summary>
+ public const float ShadowShare = 1.1f;
+
/// <summary>A boat's spot: out from its coast's shore point (SeaCraft.Coasts) between SeaCraft.OffshoreNearM and
/// OffshoreM, at a seeded spread along the shore, the first whose hull passes SeaCraft.Clear against the harbour works
/// and every boat already placed. Null when none is.</summary>
@@ -249,13 +298,14 @@ namespace Statecraft.Game.Map.Collection
if (!originals.TryGetValue(key.id, out var list)) continue;
foreach (var go in list) if (go != null)
{
- removed.Add(go);
+ removed.Add(go); keepOf.Remove(go);
if (Application.isPlaying) { if (gameObject.activeInHierarchy) go.transform.SetParent(null); Destroy(go); } else DestroyImmediate(go);
}
originals.Remove(key.id); Placed.RemoveAll(p => p.Model == key.id);
}
- keepAll = originals.Values.SelectMany(list => list).Where(go => go != null)
- .Select(go => new[] { Bounds(go) }).ToList();
+ // Each drawn craft's own keep-clear boxes (the Spitfire's cover its whole loop, its flag included); the Spitfire's
+ // shadow and flag object has none.
+ keepAll = originals.Values.SelectMany(list => list).Where(go => go != null && keepOf.ContainsKey(go)).Select(go => keepOf[go]).ToList();
return removed;
}
IReadOnlyList<UnityEngine.Object> ClearForRetirement()
@@ -271,7 +321,7 @@ namespace Statecraft.Game.Map.Collection
var old = transform.GetChild(i).gameObject; if (residencyView != null) retired.Add(old);
if (Application.isPlaying) { if (gameObject.activeInHierarchy) old.transform.SetParent(null); Destroy(old); } else DestroyImmediate(old);
}
- Placed.Clear(); Missing.Clear(); keepAll = new List<Bounds[]>();
+ Placed.Clear(); Missing.Clear(); keepAll = new List<Bounds[]>(); keepOf.Clear();
originals.Clear();
if (map != null) Statecraft.Game.Map.Units.UnitShowcase.HideTrees(map, Name, Array.Empty<(Vector2, float)>());
}
@@ -311,6 +361,8 @@ namespace Statecraft.Game.Map.Collection
/// labels re-read it only when it changes.</summary>
public IReadOnlyList<Bounds[]> KeepClear => !isActiveAndEnabled ? (IReadOnlyList<Bounds[]>)Array.Empty<Bounds[]>() : keepAll;
List<Bounds[]> keepAll = new List<Bounds[]>();
+ readonly Dictionary<GameObject, Bounds[]> keepOf = new Dictionary<GameObject, Bounds[]>();
+ void Keep(GameObject go, Bounds box) { var boxes = new[] { box }; keepAll.Add(boxes); keepOf[go] = boxes; }
/// <summary>Shows the craft wanted as at <paramref name="date"/> (GameRoot calls it on every change, beside
/// TownLandmarks.ShowAt), redrawing only when the wanted set or the player's placements change.</summary>
@@ -366,7 +418,7 @@ namespace Statecraft.Game.Map.Collection
var go = Instantiate(prefab!, transform, false); go.name = w.Key;
if (!originals.TryGetValue(w.Model, out var owned)) originals[w.Model] = owned = new List<GameObject>();
owned.Add(go);
- if (w.Model == Spitfire) { Fly(go, prefab!, at.Value); continue; }
+ if (w.Model == Spitfire) { Fly(go, prefab!, at.Value, ground); continue; }
// The yaw goes on top of the prefab's own rotation: every Collection Far prefab's root carries the FBX axis
// conversion (-90 degrees about X), and setting the yaw alone lays a model on its side (#979).
go.transform.localRotation = prefab!.transform.localRotation;
@@ -380,7 +432,7 @@ namespace Statecraft.Game.Map.Collection
go.transform.position += new Vector3(pos.x - b.center.x, pos.y - b.min.y, pos.z - b.center.z);
foreach (var r in go.GetComponentsInChildren<Renderer>(true)) r.shadowCastingMode = ShadowCastingMode.On;
Placed.Add((w.Key, w.Model, pos));
- keepAll.Add(new[] { Bounds(go) });
+ Keep(go, Bounds(go));
}
// The kit trees under the C-54 are left out at draw time, as under the unit figures (VegetationLayer.Hide, #249).
var plane = Placed.Where(p => p.Model == C54).Select(p => (new Vector2(p.At.x, p.At.z), 0.5f * SizeOf(C54))).ToList();
@@ -392,11 +444,13 @@ namespace Statecraft.Game.Map.Collection
/// east, read off its top-down capture.</summary>
internal const float SpitfireNoseEastYaw = 90f;
- /// <summary>The Spitfire in level flight round its loop about <paramref name="at"/> (<see cref="SpitfireLoop"/>), wingspan
+ /// <summary>The Spitfire in flight round its loop about <paramref name="at"/> (<see cref="SpitfireLoop"/>), wingspan
/// at its map size, UnitShowcase.AltitudeM (4,200 m) above the highest ground under the loop (UnitShowcase.LoopFloor),
- /// where the unit tokens' aircraft fly (#2014). It is drawn at the loop's start, nose east; the labels keep clear of
- /// the whole box it flies through.</summary>
- void Fly(GameObject go, GameObject prefab, Vector2 at)
+ /// where the unit tokens' aircraft fly (#2014), banked into its turns, with its propeller turning, its shadow on the
+ /// ground and a small Egyptian flag over its tail (owner's report, 2 November 2026: "the gyptian plane's propelor isn't moving and it
+ /// doesnt look fliying, also it doesnt show its an egyptian unit"). It is drawn at the loop's start, nose east; the
+ /// labels keep clear of the whole box it and its flag fly through.</summary>
+ void Fly(GameObject go, GameObject prefab, Vector2 at, KitGround ground)
{
var level = Quaternion.Euler(0f, SpitfireNoseEastYaw, 0f) * prefab.transform.localRotation;
go.transform.localRotation = level;
@@ -406,15 +460,201 @@ namespace Statecraft.Game.Map.Collection
var centre = new Vector3(at.x, Statecraft.Game.Map.Units.UnitShowcase.LoopFloor(map!, new Vector3(at.x, 0f, at.y), SpitfireLoopHalfLengthM + size)
+ Statecraft.Game.Map.Units.UnitShowcase.AltitudeM, at.y);
go.transform.position = centre; b = Bounds(go);
- // Edit mode and screenshots hold the loop's start, as the train does (RouteLayer.ModeFor).
- go.AddComponent<SpitfireLoop>().Configure(centre, level, b.center - go.transform.position, !Application.isPlaying || VisualShots.Requested());
foreach (var r in go.GetComponentsInChildren<Renderer>(true)) r.shadowCastingMode = ShadowCastingMode.On;
+ // The shadow and the flag stand beside the aircraft in this layer, so they neither bank nor turn with it, and go
+ // with it (its model's originals) when its dates end.
+ var marks = new GameObject(go.name + SpitfireMarksSuffix);
+ marks.transform.SetParent(transform, false);
+ originals[Spitfire].Add(marks);
+ var loop = go.AddComponent<SpitfireLoop>();
+ var flag = Flag(marks.transform);
+ // The aircraft's half box at level, nose east: half its length, its height and its span.
+ var half = 0.5f * new Vector3(b.size.x, b.size.y, b.size.z);
+ loop.Attach(Propeller(go), Shadow(marks.transform), flag, map!.Terrain, 0.5f * ShadowShare * new Vector2(size, b.size.x), half, ground.SeaLevelY);
+ // Edit mode and screenshots hold the loop's start, as the train does (RouteLayer.ModeFor).
+ loop.Configure(centre, level, b.center - go.transform.position, !Application.isPlaying || VisualShots.Requested());
+ var cam = Camera.main;
+ if (flag != null && cam != null) Statecraft.Game.Map.Units.UnitFlagFacing.Face(flag, cam.transform.position);
Placed.Add((go.name, Spitfire, centre));
- // Seen from above, the aircraft at any heading lies within half its box's diagonal of its centre.
- float reach = 0.5f * new Vector2(b.size.x, b.size.z).magnitude + 1f;
- keepAll.Add(new[] { new Bounds(centre, new Vector3(2f * (SpitfireLoopHalfLengthM + reach), b.size.y + 2f, 2f * (SpitfireLoopHalfWidthM + reach))) });
+ // At any heading and bank the aircraft lies within half its box's diagonal of its centre; the flag floats over its
+ // tail, at most the steepest bank's box top over the centre (SpitfireLoop.TopOver), its cloth turning about its middle.
+ float reach = 0.5f * b.size.magnitude + 1f, up = reach, round = reach;
+ if (flag != null)
+ {
+ var f = flag.GetComponent<MeshFilter>().sharedMesh.bounds; float k = flag.lossyScale.y;
+ up = Mathf.Max(up, SpitfireLoop.TopOver(half, Statecraft.Game.Map.Units.UnitShowcase.BankDegrees) + SpitfireLoop.FlagClearM + 2f * f.extents.y * k + 1f);
+ round = Mathf.Max(round, half.x + new Vector2(f.extents.x, f.extents.z).magnitude * k + 1f);
+ }
+ var keep = new Bounds();
+ keep.SetMinMax(centre - new Vector3(SpitfireLoopHalfLengthM + round, reach, SpitfireLoopHalfWidthM + round),
+ centre + new Vector3(SpitfireLoopHalfLengthM + round, up, SpitfireLoopHalfWidthM + round));
+ Keep(go, keep);
+ }
+
+ /// <summary>The turning propeller (owner's report: "the gyptian plane's propelor isn't moving"; the model is one fused
+ /// mesh, so it cannot turn its own): a translucent disc of three blurred blades at the nose, a child of the aircraft's
+ /// mesh (<see cref="PropRadiusShare"/>, <see cref="PropBehindNoseShare"/>), turned by SpitfireLoop about the mesh's
+ /// y, the flight axis. The disc's renderer bounds are the square inside its circle, so at every angle its box lies
+ /// inside the airframe's (a turning square's box never leaves the circle, and the circle lies inside the mesh's box):
+ /// the aircraft's box does not change as it turns. The cost: the renderer's box is between 0.71 and 1 of the disc's reach,
+ /// so at a screen edge the disc can be culled a frame before the airframe beside it.</summary>
+ Transform Propeller(GameObject go)
+ {
+ var airframe = go.GetComponentInChildren<MeshFilter>();
+ var mesh = airframe.sharedMesh.bounds;
+ float radius = PropRadiusShare * mesh.size.x;
+ var disc = new GameObject(SpitfirePropellerName);
+ disc.transform.SetParent(airframe.transform, false);
+ disc.transform.localPosition = new Vector3(mesh.center.x, mesh.min.y + PropBehindNoseShare * mesh.size.y, mesh.max.z - radius);
+ disc.transform.localScale = Vector3.one * radius;
+ disc.AddComponent<MeshFilter>().sharedMesh = propMesh != null ? propMesh : propMesh = Own(PropellerDisc());
+ var r = disc.AddComponent<MeshRenderer>();
+ r.sharedMaterial = Blur(); r.shadowCastingMode = ShadowCastingMode.Off; r.receiveShadows = false;
+ r.localBounds = new Bounds(Vector3.zero, new Vector3(Mathf.Sqrt(2f), 2f * PropLayer, Mathf.Sqrt(2f)));
+ return disc.transform;
+ }
+
+ /// <summary>The aircraft's soft shadow on the ground (owner's report: "it doesnt look fliying"), placed by SpitfireLoop
+ /// where the map's sun casts it.</summary>
+ Transform Shadow(Transform parent)
+ {
+ var go = new GameObject(SpitfireShadowName);
+ go.transform.SetParent(parent, false);
+ go.AddComponent<MeshFilter>().sharedMesh = shadowMesh != null ? shadowMesh : shadowMesh = Own(ShadowDisc());
+ var r = go.AddComponent<MeshRenderer>();
+ r.sharedMaterial = Blur(); r.shadowCastingMode = ShadowCastingMode.Off; r.receiveShadows = false;
+ return go.transform;
+ }
+
+ /// <summary>DESIGN VALUE: the Spitfire's flag over the tokens' flag size (UnitBadge.FigureHeightM x UnitShowcase.FigureScale
+ /// a figure-height unit; the cloth 0.72 of it across): smaller, as the owner ruled on #2260 (2 November 2026, "Smaller
+ /// flag, no pole"), and still a readable green flag with its white crescent at the opening zoom (picked from captures
+ /// of 0.35, 0.5 and 0.65 at 90 and 30 km).</summary>
+ public const float SpitfireFlagScale = 0.5f;
+
+ /// <summary>Egypt's flag, as the Egyptian tokens fly it (owner's report: "it doesnt show its an egyptian unit"): the map
+ /// marks a unit's side by its side's sourced flag (UnitPlinth.Build, UnitFlags), turned to the camera (UnitFlagFacing).
+ /// Here, as the owner ruled on #2260 ("Smaller flag, no pole": "a small Egyptian flag pennant floating just above the
+ /// tail (no pole through the plane)"), the cloth alone, centred on its own middle so it turns in place, at
+ /// <see cref="SpitfireFlagScale"/> of the tokens' size; SpitfireLoop floats it over the tail. Null, with a warning, when
+ /// the units' materials are missing: the aircraft flies on without it.</summary>
+ Transform? Flag(Transform parent)
+ {
+ if (flagMesh == null)
+ {
+ if (flagMissing) return null; // warned once for this layer
+ var ring = Resources.Load<Material>(Statecraft.Game.Map.Units.UnitMaterials.RingResource);
+ if (ring == null)
+ {
+ Debug.LogWarning("SEA/AIR: the unit materials are missing (run UnitMaterialAssets.Create); the Spitfire flies without its flag.");
+ flagMissing = true;
+ return null;
+ }
+ flagCloth = Statecraft.Game.Map.Units.UnitFlags.ClothMaterials(Statecraft.Game.Map.Units.UnitFlags.Egypt, ring, m => Own(m));
+ flagMesh = Statecraft.Game.Map.Units.UnitPlinth.Upload(Own(ClothOnly(Statecraft.Game.Map.Units.UnitFlags.Build(Statecraft.Game.Map.Units.UnitFlags.Egypt)!)));
+ }
+ var flag = Statecraft.Game.Map.Units.UnitShowcase.Piece(parent, SpitfireFlagName, flagMesh, flagCloth![0], Vector3.zero, Quaternion.identity,
+ SpitfireFlagScale * Statecraft.Game.Map.Units.UnitBadge.FigureHeightM * Statecraft.Game.Map.Units.UnitShowcase.FigureScale);
+ var r = flag.GetComponent<MeshRenderer>();
+ r.sharedMaterials = flagCloth; r.shadowCastingMode = ShadowCastingMode.Off;
+ flag.AddComponent<Statecraft.Game.Map.Units.UnitFlagFacing>();
+ return flag.transform;
+ }
+
+ /// <summary>A flag built by UnitFlags (the pole in submesh 0, then one submesh a cloth colour) with the pole left out:
+ /// a new mesh of the cloth's submeshes and only the vertices they use (so its bounds are the cloth's), moved so the
+ /// cloth's middle is at the origin.</summary>
+ static Mesh ClothOnly(Mesh flag)
+ {
+ var verts = flag.vertices; var uv = flag.uv; var normals = flag.normals;
+ var keep = new Dictionary<int, int>();
+ var parts = new List<int[]>();
+ for (int k = 1; k < flag.subMeshCount; k++)
+ {
+ var tris = flag.GetTriangles(k);
+ for (int i = 0; i < tris.Length; i++)
+ {
+ if (!keep.TryGetValue(tris[i], out int to)) keep[tris[i]] = to = keep.Count;
+ tris[i] = to;
+ }
+ parts.Add(tris);
+ }
+ var at = new Vector3[keep.Count]; var uvs = new Vector2[keep.Count]; var ns = new Vector3[keep.Count];
+ foreach (var (from, to) in keep) { at[to] = verts[from]; if (uv.Length > 0) uvs[to] = uv[from]; if (normals.Length > 0) ns[to] = normals[from]; }
+ var cloth = new Bounds(at[0], Vector3.zero);
+ foreach (var v in at) cloth.Encapsulate(v);
+ for (int i = 0; i < at.Length; i++) at[i] -= cloth.center;
+ var mesh = new Mesh { name = flag.name, vertices = at };
+ if (uv.Length > 0) mesh.uv = uvs;
+ if (normals.Length > 0) mesh.normals = ns;
+ mesh.subMeshCount = parts.Count;
+ for (int k = 0; k < parts.Count; k++) mesh.SetTriangles(parts[k], k);
+ mesh.RecalculateBounds();
+ DestroyMesh(flag);
+ return mesh;
+ }
+
+ static void DestroyMesh(Mesh m) { if (Application.isPlaying) Destroy(m); else DestroyImmediate(m); }
+
+ MapRuntimeAssets? assets;
+ bool flagMissing;
+ Material? blur; Material[]? flagCloth; Mesh? propMesh, shadowMesh, flagMesh;
+
+ /// <summary>Takes <paramref name="o"/>, made once for this layer, to be destroyed with it.</summary>
+ T Own<T>(T o) where T : UnityEngine.Object
+ {
+ if (assets == null) { assets = GetComponent<MapRuntimeAssets>(); if (assets == null) assets = gameObject.AddComponent<MapRuntimeAssets>(); }
+ return assets.Own(o);
+ }
+
+ /// <summary>The propeller's and the shadow's material: alpha-blended, unlit, both faces, its colour the meshes' vertex
+ /// colours (HexMaterials' shipped under-attack border template, so a player build keeps the shader's variant).</summary>
+ Material Blur() => blur != null ? blur : blur = Own(Statecraft.HexTiles.HexMaterials.New(Statecraft.HexTiles.HexMaterials.AttackBorder));
+
+ /// <summary>A flat disc of radius 1 in the XZ plane (normal +y), one copy at each of <paramref name="layers"/> (its y): a
+ /// centre and rings of <paramref name="segments"/> vertices at <paramref name="rings"/>, coloured <paramref name="colour"/>
+ /// with the alpha <paramref name="alpha"/> gives at (radius, angle in degrees from +x towards +z).</summary>
+ static Mesh Disc(string name, int segments, float[] rings, float[] layers, Color colour, Func<float, float, float> alpha)
+ {
+ int per = 1 + segments * rings.Length, perTris = 3 * segments + 6 * segments * (rings.Length - 1);
+ var verts = new Vector3[per * layers.Length]; var colours = new Color32[verts.Length]; var tris = new int[perTris * layers.Length];
+ Color32 Paint(float a) { var c = colour; c.a = Mathf.Clamp01(a); return c; }
+ int t = 0;
+ for (int l = 0; l < layers.Length; l++)
+ {
+ int o = l * per;
+ verts[o] = new Vector3(0f, layers[l], 0f); colours[o] = Paint(alpha(0f, 0f));
+ for (int k = 0; k < rings.Length; k++)
+ for (int i = 0; i < segments; i++)
+ {
+ float deg = 360f * i / segments, rad = deg * Mathf.Deg2Rad;
+ verts[o + 1 + k * segments + i] = new Vector3(Mathf.Cos(rad) * rings[k], layers[l], Mathf.Sin(rad) * rings[k]);
+ colours[o + 1 + k * segments + i] = Paint(alpha(rings[k], deg));
+ }
+ for (int i = 0; i < segments; i++) { tris[t++] = o; tris[t++] = o + 1 + (i + 1) % segments; tris[t++] = o + 1 + i; }
+ for (int k = 0; k + 1 < rings.Length; k++)
+ for (int i = 0; i < segments; i++)
+ {
+ int a = o + 1 + k * segments + i, b = o + 1 + k * segments + (i + 1) % segments, c = a + segments, d = b + segments;
+ tris[t++] = a; tris[t++] = b; tris[t++] = c; tris[t++] = c; tris[t++] = b; tris[t++] = d;
+ }
+ }
+ var mesh = new Mesh { name = name, vertices = verts, colors32 = colours, triangles = tris };
+ mesh.RecalculateBounds();
+ return Statecraft.Game.Map.Units.UnitPlinth.Upload(mesh);
}
+ /// <summary>DESIGN VALUES: the propeller's blur, near-black (the units' propeller paint): three blades, each a dark
+ /// leading edge whose smear fades behind it (the way SpitfireLoop turns it), over a half-opaque whole disc that dims
+ /// the fused model's still blades, clear at the spinner and fading out at the rim; two layers (<see cref="PropLayer"/>).</summary>
+ static Mesh PropellerDisc() => Disc("SpitfirePropellerBlur", 72, new[] { 0.18f, 0.4f, 0.7f, 0.9f, 1f }, new[] { -PropLayer, PropLayer }, new Color(0.06f, 0.06f, 0.06f), (r, deg) =>
+ r >= 1f ? 0f : Mathf.Min(1f, r / 0.4f) * (0.45f + 0.45f * Mathf.Exp(-Mathf.Repeat(-deg, 120f) / 35f)));
+
+ /// <summary>DESIGN VALUES: the shadow, a dark warm grey (the map's shadows are warm under its sun), 0.42 opaque at its
+ /// middle and fading to nothing at its rim, (1 - r²)^1.5.</summary>
+ static Mesh ShadowDisc() => Disc("SpitfireShadow", 48, new[] { 0.3f, 0.55f, 0.75f, 0.9f, 1f }, new[] { 0f }, new Color(0.10f, 0.08f, 0.06f), (r, _) =>
+ 0.42f * Mathf.Pow(1f - r * r, 1.5f));
+
/// <summary>The ground the other 1948 Collection layers hold (GameRoot shows them first), for the C-54 to keep off, as
/// SpecialBuildingModels keeps off the people and the wildlife: the civilians (#666), the wildlife (#670), the farm
/// scenes drawn (#667) and the fort, barracks and factory drawn (#707). Show compares it, so the plane moves when they
diff --git a/unity/Assets/Scripts/Map/Collection/SpitfireLoop.cs b/unity/Assets/Scripts/Map/Collection/SpitfireLoop.cs
index 677d9331f..37023c557 100644
--- a/unity/Assets/Scripts/Map/Collection/SpitfireLoop.cs
+++ b/unity/Assets/Scripts/Map/Collection/SpitfireLoop.cs
@@ -5,15 +5,57 @@ using UnityEngine;
namespace Statecraft.Game.Map.Collection
{
/// <summary>Flies Tal Heuberger's Egyptian Spitfire round its loop (SeaAirCollection.LoopOffset, owner, 2 November 2026:
- /// "Fly a slow loop"), level, nose along the path. Presentation only: it reads the map's animation clock (Time.time, as
- /// the steam train and the showcase flight do), sets one transform per frame and allocates nothing. It lives on the
- /// aircraft's own object, so it stops when the layer drops the aircraft (its dates end, or the map is torn down) and
- /// does not run while the layer is inactive. The model is one fused mesh with no separate propeller, so nothing spins.
- /// Editor renders and screenshots (`?shot` / `-shot`) hold the loop's start, so they repeat exactly, as the train does
- /// (RouteLayer.ModeFor).</summary>
+ /// "Fly a slow loop"), nose along the path, banked into the turns (SeaAirCollection.LoopBankDegrees), its propeller
+ /// turning, its shadow on the ground and its side's flag over its tail (owner's report, 2 November 2026: "the gyptian plane's
+ /// propelor isn't moving and it doesnt look fliying, also it doesnt show its an egyptian unit"). Presentation only: it
+ /// reads the map's animation clock (Time.time, as the steam train and the showcase flight do), sets a few transforms per
+ /// frame and allocates nothing. It lives on the aircraft's own object, so it stops when the layer drops the aircraft (its
+ /// dates end, or the map is torn down) and does not run while the layer is inactive.
+ /// The model is one fused mesh, so the turning propeller is a separate translucent disc at its nose (<see cref="Attach"/>,
+ /// SeaAirCollection.Fly). Editor renders and screenshots (`?shot` / `-shot`) hold the loop's start, propeller included, so
+ /// they repeat exactly, as the train does (RouteLayer.ModeFor).</summary>
public sealed class SpitfireLoop : MonoBehaviour
{
+ /// <summary>DESIGN VALUE: the propeller's turn (degrees a second), as ShowcaseFlight turns the unit tokens' propellers:
+ /// about 4 turns a second, so its three blurred blades move a sixth of a turn or less between two frames at 30 fps
+ /// and never seem to turn backwards.</summary>
+ public const float PropDegreesPerSecond = 1500f;
+
+ /// <summary>DESIGN VALUE: the shadow's lift (m) over the highest of the five ground points sampled under it, so the flat
+ /// disc lies over the dunes rather than in them.</summary>
+ public const float ShadowLiftM = 30f;
+
+ /// <summary>The direction the map's sun shines (MapLighting.Apply), pointing down: the shadow's ray when the scene has
+ /// no directional sun, or one under 10 degrees.</summary>
+ public static readonly Vector3 SunRay = Quaternion.Euler(MapLighting.SunElevation, MapLighting.SunAzimuth - 180f, 0f) * Vector3.forward;
+
+ /// <summary>The ray the scene's sun casts now (RenderSettings.sun: MapLighting's, or the opt-in hex map's dusk or night
+ /// light, HexTimeOfDay), so the shadow lies with the real ones; <see cref="SunRay"/> without one, or with one under
+ /// 10 degrees, whose shadow would run off the board.</summary>
+ static Vector3 SunNow()
+ {
+ var sun = RenderSettings.sun;
+ if (sun != null && sun.type == LightType.Directional)
+ {
+ var ray = sun.transform.forward;
+ if (ray.y < -0.17f) return ray;
+ }
+ return SunRay;
+ }
+
Vector3 centre, offset; Quaternion level; bool still;
+ Transform? prop, shadow, flag; Terrain? ground; Vector2 shadowHalf; Vector3 half; float flagHalf, seaY;
+
+ /// <summary>DESIGN VALUE: the gap (m) between the aircraft's box top and the flag's lower edge.</summary>
+ public const float FlagClearM = 150f;
+
+ /// <summary>How far the top of the aircraft's box stands over its centre at <paramref name="bankDegrees"/>: its half box
+ /// <paramref name="half"/> (half its length, height and span) rolled about its length.</summary>
+ public static float TopOver(Vector3 half, float bankDegrees)
+ {
+ float b = bankDegrees * Mathf.Deg2Rad;
+ return half.z * Mathf.Abs(Mathf.Sin(b)) + half.y * Mathf.Cos(b);
+ }
/// <summary>The animation clock, Time.time. Test seam (internal; the tests see it through InternalsVisibleTo): an
/// EditMode test has no frame clock.</summary>
@@ -22,6 +64,17 @@ namespace Statecraft.Game.Map.Collection
/// <summary>True when the aircraft holds the loop's start (edit mode, screenshots).</summary>
public bool Still => still;
+ /// <summary>The turning propeller disc (a child of the aircraft's mesh), the shadow and the flag (each in world space,
+ /// beside the aircraft), the terrain the shadow lies on, the shadow's half size across and along the heading (m), and
+ /// the aircraft's half box at level (half its length, height and span, m), and the sea's surface (world y: the shadow
+ /// never lies under it). Before <see cref="Configure"/>, which places them all.</summary>
+ internal void Attach(Transform? prop, Transform? shadow, Transform? flag, Terrain? ground, Vector2 shadowHalf, Vector3 airframeHalf = default,
+ float seaY = float.NegativeInfinity)
+ {
+ this.prop = prop; this.shadow = shadow; this.flag = flag; this.ground = ground; this.shadowHalf = shadowHalf; half = airframeHalf; this.seaY = seaY;
+ flagHalf = flag != null ? flag.GetComponent<MeshFilter>().sharedMesh.bounds.extents.y : 0f;
+ }
+
/// <summary><paramref name="centre"/>: the loop's centre in the air. <paramref name="level"/>: the model's rotation
/// with its nose east. <paramref name="offset"/>: its drawn centre from its pivot at that rotation.</summary>
internal void Configure(Vector3 centre, Quaternion level, Vector3 offset, bool still)
@@ -36,15 +89,54 @@ namespace Statecraft.Game.Map.Collection
if (!still) Place(Clock());
}
- /// <summary>Puts the aircraft where it is <paramref name="seconds"/> into its loop, its drawn centre on the path and
- /// its nose along the path's tangent.</summary>
+ /// <summary>Puts the aircraft where it is <paramref name="seconds"/> into its loop: its drawn centre on the path, its
+ /// nose along the path's tangent, rolled into the turn about that tangent; the propeller at its angle then; the flag
+ /// over its tail; the shadow where the sun's ray through the drawn centre meets the ground.</summary>
public void Place(float seconds)
{
var at = SeaAirCollection.LoopOffset(seconds); var heading = SeaAirCollection.LoopHeading(seconds);
+ var forward = new Vector3(heading.x, 0f, heading.y);
// A turn about the vertical from east (+x) to the heading; Unity's yaw turns +x toward -z.
var yaw = Quaternion.Euler(0f, -Mathf.Atan2(heading.y, heading.x) * Mathf.Rad2Deg, 0f);
- transform.localRotation = yaw * level;
- transform.position = centre + new Vector3(at.x, 0f, at.y) - yaw * offset;
+ // The loop turns left (anticlockwise seen from above): a positive turn about the heading lowers the left wing.
+ float bank = SeaAirCollection.LoopBankDegrees(seconds);
+ var turn = Quaternion.AngleAxis(bank, forward) * yaw;
+ transform.localRotation = turn * level;
+ var drawn = centre + new Vector3(at.x, 0f, at.y);
+ transform.position = drawn - turn * offset;
+ // The angle in double: a float product with the clock loses whole degrees after hours (review of #2260).
+ if (prop != null) prop.localRotation = Quaternion.AngleAxis(-(float)((double)seconds * PropDegreesPerSecond % 360.0), Vector3.up);
+ // The flag over the tail, its lower edge FlagClearM over the top of the aircraft's box at this bank: clear of the
+ // airframe at every bank and heading.
+ if (flag != null) flag.position = drawn - forward * half.x + Vector3.up * (TopOver(half, bank) + FlagClearM + flagHalf * flag.lossyScale.y);
+ if (shadow != null && ground != null) PlaceShadow(drawn, forward, bank);
}
+
+ /// <summary>The scene sun's ray from <paramref name="drawn"/> to the ground (or the sea's surface), found in two steps (the ground's height where the
+ /// ray lands sets how far it travels); the disc flat, turned with the heading, narrowed across by the bank, lifted over
+ /// the highest ground under its middle and its four ends.</summary>
+ void PlaceShadow(Vector3 drawn, Vector3 forward, float bank)
+ {
+ var ray = SunNow();
+ var hit = drawn;
+ float floor = Surface(drawn);
+ for (int i = 0; i < 2; i++)
+ {
+ hit = drawn + ray * ((drawn.y - floor) / -ray.y);
+ floor = Surface(hit);
+ }
+ var across = new Vector3(forward.z, 0f, -forward.x);
+ float half = shadowHalf.x * Mathf.Cos(bank * Mathf.Deg2Rad);
+ float top = floor;
+ top = Mathf.Max(top, Surface(hit + across * half));
+ top = Mathf.Max(top, Surface(hit - across * half));
+ top = Mathf.Max(top, Surface(hit + forward * shadowHalf.y));
+ top = Mathf.Max(top, Surface(hit - forward * shadowHalf.y));
+ shadow!.SetPositionAndRotation(new Vector3(hit.x, top + ShadowLiftM, hit.z), Quaternion.LookRotation(forward, Vector3.up));
+ shadow.localScale = new Vector3(half, 1f, shadowHalf.y);
+ }
+
+ /// <summary>The ground's height under <paramref name="p"/>, or the sea's surface over the sea.</summary>
+ float Surface(Vector3 p) => Mathf.Max(ground!.SampleHeight(p) + ground.transform.position.y, seaY);
}
}
diff --git a/unity/Assets/Scripts/Map/Kits/KitGround.cs b/unity/Assets/Scripts/Map/Kits/KitGround.cs
index 358b83c62..892984c8a 100644
--- a/unity/Assets/Scripts/Map/Kits/KitGround.cs
+++ b/unity/Assets/Scripts/Map/Kits/KitGround.cs
@@ -54,6 +54,8 @@ namespace Statecraft.Game.Map.Kits
/// <summary>The terrain's world position (the hex grid's origin: HexGrid.ToWorld).</summary>
public Vector3 TerrainOrigin => terrain.transform.position;
+ /// <summary>The sea's surface (world y): the heightmap's 0 m.</summary>
+ public float SeaLevelY => seaLevelY;
public float Width => Frame.WidthM;
public float Length => Frame.LengthM;
diff --git a/unity/Assets/Tests/EditMode/SeaAirCollectionTests.cs b/unity/Assets/Tests/EditMode/SeaAirCollectionTests.cs
index 288f00cb9..8498129d2 100644
--- a/unity/Assets/Tests/EditMode/SeaAirCollectionTests.cs
+++ b/unity/Assets/Tests/EditMode/SeaAirCollectionTests.cs
@@ -11,6 +11,7 @@ using Statecraft.Sim;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
+using UnityEngine.Rendering;
using UnityEngine.TestTools;
using Object = UnityEngine.Object;
@@ -332,6 +333,348 @@ public class SeaAirCollectionTests
}
}
+ /// <summary>The Spitfire on the 15 June 1948 turn: the layer, the aircraft, its loop, and its loop's centre in the air.</summary>
+ (SeaAirCollection layer, Transform plane, SpitfireLoop loop, Vector3 centre) DrawnSpitfire(MapScene map)
+ {
+ var layer = CollectionGeometryFixture.Craft(map, new DateTime(1948, 6, 15), Array.Empty<Placement>(), C)!; AnswerAll();
+ var plane = layer.transform.Find("el-arish-spitfire")!;
+ Assert.IsNotNull(plane, "the Spitfire is drawn on 15 June 1948");
+ return (layer, plane, plane.GetComponent<SpitfireLoop>(), layer.Placed.Single(p => p.Model == SeaAirCollection.Spitfire).At);
+ }
+
+ static Transform? Marks(SeaAirCollection layer, string part) =>
+ layer.transform.Find("el-arish-spitfire" + SeaAirCollection.SpitfireMarksSuffix)?.Find(part);
+
+ /// <summary>The owner's report, 2 November 2026: "the gyptian plane's propelor isn't moving". The model is one fused mesh,
+ /// so a translucent disc at its nose turns instead: a child of the aircraft's mesh, its hub at the spinner (the mesh's
+ /// front-most vertices), about the size of the model's own blades, turning about the flight axis by the clock, a sixth of
+ /// a turn or less between frames at 30 fps (three blurred blades never seem to turn backwards). Its box stays inside the
+ /// airframe's at every angle, so the aircraft's measured box (the labels' keep-clear, the tests above) never moves with
+ /// it. Edit mode and screenshots (-shot) hold it at the loop's start, as they hold the aircraft; in play it turns.</summary>
+ [Test]
+ public void TheSpitfirePropellerTurnsAtItsNoseAboutTheFlightAxisAndHoldsStillInShots()
+ {
+ bool readable = Statecraft.Game.Map.Units.UnitPlinth.KeepMeshesReadable;
+ Statecraft.Game.Map.Units.UnitPlinth.KeepMeshesReadable = true; // the disc's vertices are read below
+ try { PropellerTurnsAtItsNose(); }
+ finally { Statecraft.Game.Map.Units.UnitPlinth.KeepMeshesReadable = readable; }
+ }
+
+ void PropellerTurnsAtItsNose()
+ {
+ var map = OpenMap();
+ var (_, plane, loop, centre) = DrawnSpitfire(map);
+ var airframe = plane.GetComponentInChildren<MeshFilter>();
+ var prop = airframe.transform.Find(SeaAirCollection.SpitfirePropellerName);
+ Assert.IsNotNull(prop, "a propeller disc, a child of the aircraft's mesh");
+ Assert.AreEqual(ShadowCastingMode.Off, prop.GetComponent<MeshRenderer>().shadowCastingMode, "a blur casts no shadow");
+ float span = SeaAirCollection.SizeOf(SeaAirCollection.Spitfire);
+ loop.Place(0f);
+ var nose = plane.TransformDirection(Vector3.down); // the mesh's -y, as the in-flight test reads it
+ var verts = airframe.sharedMesh.vertices.Select(airframe.transform.TransformPoint).ToList();
+ float front = verts.Max(v => Vector3.Dot(v, nose)), back = verts.Min(v => Vector3.Dot(v, nose));
+ var spinner = verts.Where(v => Vector3.Dot(v, nose) > front - 0.01f * (front - back)).ToList();
+ var tip = spinner.Aggregate(Vector3.zero, (a, v) => a + v) / spinner.Count;
+ Assert.Less((prop.position - tip).magnitude, 0.06f * span, $"the hub at the spinner ({prop.position} against {tip})");
+ Assert.Less(front - Vector3.Dot(prop.position, nose), 0.08f * (front - back), "at the nose");
+ Assert.AreEqual(prop.lossyScale.x, prop.lossyScale.z, 0.01f * span, "a round disc");
+ Assert.That(prop.lossyScale.x / span, Is.InRange(0.09f, 0.15f), "about the model's own blades (a real Spitfire's: 3.27 m across an 11.23 m span)");
+ Assert.Greater(Mathf.Abs(Vector3.Dot(prop.TransformDirection(Vector3.up), nose)), 0.999f, "it turns about the flight axis");
+
+ loop.Place(0f); var q0 = prop.localRotation;
+ loop.Place(0.02f); var q1 = prop.localRotation;
+ Assert.AreEqual(0.02f * SpitfireLoop.PropDegreesPerSecond, Quaternion.Angle(q0, q1), 0.5f, "it turns between two frames");
+ Assert.Less(SpitfireLoop.PropDegreesPerSecond / 30f, 60f, "under half a blade's spacing a frame at 30 fps");
+ for (int i = 0; i < 24; i++)
+ {
+ float t = i * 0.011f + (i % 4) * 10f; // every spin angle, on the passes and in the turns
+ loop.Place(t);
+ var all = WorldBounds(plane.gameObject); var own = airframe.GetComponent<Renderer>().bounds;
+ Assert.Less((all.min - own.min).magnitude + (all.max - own.max).magnitude, 0.5f, $"the disc's box stays inside the airframe's at {t:0.000} s");
+ // The geometry too, not only the renderer's box (review of #2260): every disc vertex inside the airframe's box.
+ var grown = own; grown.Expand(1f);
+ foreach (var v in prop.GetComponent<MeshFilter>().sharedMesh.vertices)
+ Assert.IsTrue(grown.Contains(prop.TransformPoint(v)), $"the disc's vertex {v} inside the airframe's box at {t:0.000} s");
+ }
+ // Long into a session the angle stays exact (review of #2260: the product with the clock lost whole degrees):
+ // 36000.25 s is 150,001 turns and a twenty-fourth, 15 degrees.
+ loop.Place(36000.25f);
+ Assert.Less(Quaternion.Angle(prop.localRotation, Quaternion.AngleAxis(-15f, Vector3.up)), 0.1f, "15 degrees round after ten hours");
+
+ Assert.IsTrue(loop.Still, "edit mode holds the loop's start");
+ var clock = SpitfireLoop.Clock;
+ var update = typeof(SpitfireLoop).GetMethod("Update", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!;
+ var flying = new GameObject("flying");
+ try
+ {
+ loop.Place(0f); var held = prop.localRotation;
+ SpitfireLoop.Clock = () => 12.34f;
+ update.Invoke(loop, null);
+ Assert.AreEqual(0f, Quaternion.Angle(held, prop.localRotation), 1e-3f, "held (edit mode, -shot): the propeller does not turn");
+ var disc = new GameObject("disc").transform; disc.SetParent(flying.transform, false);
+ var live = flying.AddComponent<SpitfireLoop>();
+ live.Attach(disc, null, null, null, Vector2.zero);
+ live.Configure(centre, Quaternion.identity, Vector3.zero, still: false);
+ var then = disc.localRotation;
+ SpitfireLoop.Clock = () => 12.36f;
+ update.Invoke(live, null);
+ Assert.AreEqual(0.02f * SpitfireLoop.PropDegreesPerSecond, Quaternion.Angle(then, disc.localRotation), 0.5f, "in play it turns with the clock");
+ }
+ finally { SpitfireLoop.Clock = clock; Object.DestroyImmediate(flying); }
+ }
+
+ /// <summary>The owner's report: "it doesnt look fliying". The aircraft flies well clear of the ground at every point of its
+ /// loop (UnitShowcase.AltitudeM over the highest ground under the loop), and a soft dark disc, as long and as wide as the
+ /// aircraft seen from above and fading to nothing at its rim, lies on the ground where the map's sun (MapLighting) casts
+ /// it: on the sun's ray through the aircraft, east-south-east of it, turned with its heading, a little over the ground
+ /// under it and inside the board.</summary>
+ [Test]
+ public void TheSpitfireFliesHighOverTheGroundAndItsSoftShadowLiesDownSunOnTheBoard()
+ {
+ var map = OpenMap();
+ bool readable = Statecraft.Game.Map.Units.UnitPlinth.KeepMeshesReadable;
+ Statecraft.Game.Map.Units.UnitPlinth.KeepMeshesReadable = true;
+ var sun = new GameObject("TEST ONLY sun").AddComponent<Light>();
+ var sunWas = RenderSettings.sun;
+ try
+ {
+ sun.type = LightType.Directional; MapLighting.Apply(sun);
+ Assert.Greater(Vector3.Dot(sun.transform.forward, SpitfireLoop.SunRay), 0.9999f, "the map's sun");
+ var (layer, plane, loop, centre) = DrawnSpitfire(map);
+ var shadow = Marks(layer, SeaAirCollection.SpitfireShadowName);
+ Assert.IsNotNull(shadow, "a ground shadow beside the aircraft");
+ var renderer = shadow!.GetComponent<MeshRenderer>();
+ Assert.AreEqual(ShadowCastingMode.Off, renderer.shadowCastingMode); Assert.IsFalse(renderer.receiveShadows);
+ var alpha = shadow.GetComponent<MeshFilter>().sharedMesh.colors32.Select(c => c.a / 255f).ToList();
+ Assert.That(alpha.Max(), Is.InRange(0.2f, 0.8f), "dark but see-through at its middle");
+ Assert.AreEqual(0f, alpha.Min(), 1e-3f, "nothing at its rim: a soft edge");
+ var ground = PlacementLayer.CampGround(map);
+ float span = SeaAirCollection.SizeOf(SeaAirCollection.Spitfire), y0 = map.Terrain.transform.position.y;
+ float Height(Vector3 p) => map.Terrain.SampleHeight(p) + y0;
+ var sunFlat = new Vector2(SpitfireLoop.SunRay.x, SpitfireLoop.SunRay.z).normalized;
+ for (int i = 0; i < 40; i++)
+ {
+ float t = i * SeaAirCollection.SpitfireLoopSeconds / 40f;
+ loop.Place(t);
+ var b = plane.GetComponentInChildren<Renderer>().bounds;
+ float under = Mathf.Max(Height(b.center), Height(b.min), Height(b.max), Height(new Vector3(b.min.x, 0f, b.max.z)), Height(new Vector3(b.max.x, 0f, b.min.z)));
+ Assert.Greater(b.min.y - under, 2000f, $"well clear of the ground at {t:0.0} s");
+ var at = SeaAirCollection.LoopOffset(t); var drawn = centre + new Vector3(at.x, 0f, at.y);
+ var s = shadow.position; float g = Height(s);
+ Assert.That(s.y - g, Is.InRange(0f, SpitfireLoop.ShadowLiftM + 400f), $"on the ground under it at {t:0.0} s");
+ var cast = drawn + SpitfireLoop.SunRay * ((drawn.y - g) / -SpitfireLoop.SunRay.y);
+ Assert.Less(new Vector2(s.x - cast.x, s.z - cast.z).magnitude, 0.03f * (drawn.y - g), $"on the sun's ray through the aircraft at {t:0.0} s");
+ Assert.Greater(Vector2.Dot(new Vector2(s.x - drawn.x, s.z - drawn.z), sunFlat), 0.9f * (drawn.y - g), "down-sun of it");
+ var heading = SeaAirCollection.LoopHeading(t);
+ Assert.Greater(Vector3.Dot(shadow.forward, new Vector3(heading.x, 0f, heading.y)), 0.999f, "turned with its heading");
+ Assert.That(shadow.lossyScale.z / span, Is.InRange(0.3f, 0.6f), "half as long as the aircraft, about");
+ Assert.That(shadow.lossyScale.x / span, Is.InRange(0.4f, 0.6f), "half as wide, about (narrower in a bank)");
+ float reach = Mathf.Max(shadow.lossyScale.x, shadow.lossyScale.z);
+ Assert.IsTrue(ground.Inside(s.x - reach, s.z - reach) && ground.Inside(s.x + reach, s.z + reach), $"on the board at {t:0.0} s ({s})");
+ Assert.GreaterOrEqual(s.y, ground.SeaLevelY + SpitfireLoop.ShadowLiftM - 0.01f, $"never under the sea's surface at {t:0.0} s");
+ }
+ // The scene's own sun casts it (the opt-in hex map's dusk and night presets turn the sun, HexTimeOfDay): a
+ // higher sun from the south-west puts it north-east of the aircraft, nearer.
+ sun.transform.rotation = Quaternion.Euler(48f, 215f - 180f, 0f);
+ loop.Place(0f);
+ var high = centre + new Vector3(SeaAirCollection.LoopOffset(0f).x, 0f, SeaAirCollection.LoopOffset(0f).y);
+ var landed = shadow.position; float under0 = Height(landed);
+ var cast0 = high + sun.transform.forward * ((high.y - under0) / -sun.transform.forward.y);
+ Assert.Less(new Vector2(landed.x - cast0.x, landed.z - cast0.z).magnitude, 0.03f * (high.y - under0), "on the scene sun's ray, not a fixed one");
+ }
+ finally { Statecraft.Game.Map.Units.UnitPlinth.KeepMeshesReadable = readable; RenderSettings.sun = sunWas; Object.DestroyImmediate(sun.gameObject); }
+ }
+
+ /// <summary>The owner's report: "it doesnt look fliying". The aircraft rolls into its turns by the path's curvature: no bank
+ /// on a straight, none on the loop's passes (its least curvature, in from el-Arish and back), the unit tokens' aircraft
+ /// bank (UnitShowcase.BankDegrees) at the turns at its ends (its most), and some all through the turns. The curvature is
+ /// the path's own (a finite difference of LoopOffset agrees). The drawn aircraft's inner wing is lower by that roll, and
+ /// its nose stays level.</summary>
+ [Test]
+ public void TheSpitfireBanksIntoItsTurnsByTheirCurvatureAndFliesLevelOnItsPasses()
+ {
+ float period = SeaAirCollection.SpitfireLoopSeconds, max = Statecraft.Game.Map.Units.UnitShowcase.BankDegrees;
+ Assert.AreEqual(0f, SeaAirCollection.BankFor(0f), "no bank on a straight");
+ Assert.AreEqual(0f, SeaAirCollection.LoopBankDegrees(0f), 1e-3f, "level on the pass in from el-Arish");
+ Assert.AreEqual(0f, SeaAirCollection.LoopBankDegrees(0.5f * period), 1e-3f, "level on the pass back");
+ Assert.AreEqual(max, SeaAirCollection.LoopBankDegrees(0.25f * period), 1e-3f, "the turn at the east end");
+ Assert.AreEqual(max, SeaAirCollection.LoopBankDegrees(0.75f * period), 1e-3f, "the turn at the west end");
+ float least = SeaAirCollection.LoopCurvature(0f);
+ for (int i = 0; i < 200; i++)
+ {
+ float t = i * period / 200f, h = 0.2f; // a step large enough for float positions of km, small for the curve
+ Vector2 p0 = SeaAirCollection.LoopOffset(t - h), p1 = SeaAirCollection.LoopOffset(t), p2 = SeaAirCollection.LoopOffset(t + h);
+ Vector2 d1 = (p2 - p0) / (2f * h), d2 = (p2 - 2f * p1 + p0) / (h * h);
+ float numeric = Mathf.Abs(d1.x * d2.y - d1.y * d2.x) / Mathf.Pow(d1.magnitude, 3f);
+ Assert.AreEqual(numeric, SeaAirCollection.LoopCurvature(t), 0.01f * numeric, $"the path's curvature at {t:0.0} s");
+ float bank = SeaAirCollection.LoopBankDegrees(t);
+ Assert.That(bank, Is.InRange(0f, max + 1e-3f), $"a gentle bank at {t:0.0} s");
+ if (SeaAirCollection.LoopCurvature(t) > 1.05f * least) Assert.Greater(bank, 0f, $"into the turn at {t:0.0} s");
+ }
+
+ var map = OpenMap();
+ bool readable = Statecraft.Game.Map.Units.UnitPlinth.KeepMeshesReadable;
+ Statecraft.Game.Map.Units.UnitPlinth.KeepMeshesReadable = true; // explicit, though only the model's own mesh is read
+ try { RollsIntoTheTurns(map, period); }
+ finally { Statecraft.Game.Map.Units.UnitPlinth.KeepMeshesReadable = readable; }
+ }
+
+ void RollsIntoTheTurns(MapScene map, float period)
+ {
+ var (_, plane, loop, centre) = DrawnSpitfire(map);
+ var mesh = plane.GetComponentInChildren<MeshFilter>(); var v = mesh.sharedMesh.vertices;
+ float tipX = v.Max(p => Mathf.Abs(p.x));
+ Vector3 Tip(float side) { var tip = v.Where(p => p.x * side > 0.96f * tipX).ToList(); return tip.Aggregate(Vector3.zero, (a, p) => a + p) / tip.Count; }
+ Vector3 left = Tip(-1f), right = Tip(1f);
+ var c = new Vector2(centre.x, centre.z);
+ // Densely over two periods, across the wrap at the period's end: the inner wing is never the higher one.
+ for (int i = 0; i <= 400; i++)
+ {
+ float t = i * 2f * period / 400f;
+ loop.Place(t);
+ Vector3 a = mesh.transform.TransformPoint(left), b = mesh.transform.TransformPoint(right);
+ bool aInner = Vector2.Distance(new Vector2(a.x, a.z), c) < Vector2.Distance(new Vector2(b.x, b.z), c);
+ Vector3 inner = aInner ? a : b, outer = aInner ? b : a;
+ float roll = Mathf.Asin((outer.y - inner.y) / (outer - inner).magnitude) * Mathf.Rad2Deg;
+ Assert.AreEqual(SeaAirCollection.LoopBankDegrees(t), roll, 1.5f, $"the inner wing down by the bank at {t:0.0} s");
+ Assert.AreEqual(0f, plane.TransformDirection(Vector3.down).y, 1e-3f, $"the nose level at {t:0.0} s");
+ }
+ }
+
+ /// <summary>The owner's report: "it doesnt show its an egyptian unit". The map marks a unit's side by its side's sourced
+ /// flag (UnitPlinth.Build, UnitFlags, owner ruling 31 October 2026), turned to the camera (UnitFlagFacing, owner ruling
+ /// 15 October 2026). The Spitfire flies the same flag, cloth and colours, but as the owner ruled on #2260 (2 November
+ /// 2026, "Smaller flag, no pole": "a small Egyptian flag pennant floating just above the tail (no pole through the
+ /// plane)"): the cloth alone, smaller than the tokens' flag, floating over the aircraft's tail. In every pose of the loop
+ /// and facing every way it stays upright, behind the aircraft's middle, wholly above the aircraft's box (so it never
+ /// meets the airframe, banked or not), and inside the box the labels keep clear of.</summary>
+ [Test]
+ public void TheSpitfireFliesEgyptsFlagAsTheEgyptianTokensDo()
+ {
+ Assert.IsTrue(Statecraft.Game.Map.Units.UnitData.Sides.Contains(Statecraft.Game.Map.Units.UnitFlags.Egypt), "Egypt is a side of the units' content");
+ Assert.IsTrue(Statecraft.Game.Map.Units.UnitFlags.Has(Statecraft.Game.Map.Units.UnitFlags.Egypt), "with the sourced flag its tokens fly");
+ var map = OpenMap();
+ var (layer, plane, loop, centre) = DrawnSpitfire(map);
+ var flag = Marks(layer, SeaAirCollection.SpitfireFlagName);
+ Assert.IsNotNull(flag, "a flag beside the aircraft");
+ var mesh = flag!.GetComponent<MeshFilter>().sharedMesh;
+ Assert.AreEqual(Statecraft.Game.Map.Units.UnitFlags.MeshName(Statecraft.Game.Map.Units.UnitFlags.Egypt), mesh.name, "Egypt's flag, built as the tokens' (UnitFlags.Build)");
+ var mats = flag.GetComponent<MeshRenderer>().sharedMaterials;
+ var cloth = Statecraft.Game.Map.Units.UnitFlags.Colours(Statecraft.Game.Map.Units.UnitFlags.Egypt);
+ Assert.AreEqual(cloth.Count, mesh.subMeshCount, "the cloth's colours only: no pole (owner, \"Smaller flag, no pole\")");
+ Assert.AreEqual(cloth.Count, mats.Length, "one cloth material a submesh");
+ for (int i = 0; i < cloth.Count; i++)
+ Assert.Less(Vector4.Distance(cloth[i], mats[i].color), 1e-4f, $"Egypt's cloth colour {i}, as UnitFlags.ClothMaterials gives the tokens");
+ Assert.IsNotNull(flag.GetComponent<Statecraft.Game.Map.Units.UnitFlagFacing>(), "the cloth turns to the camera, as the tokens' flags do");
+ float tokens = Statecraft.Game.Map.Units.UnitBadge.FigureHeightM * Statecraft.Game.Map.Units.UnitShowcase.FigureScale;
+ Assert.Less(flag.lossyScale.y, 0.75f * tokens, "clearly smaller than the tokens' flag");
+ Assert.AreEqual(ShadowCastingMode.Off, flag.GetComponent<MeshRenderer>().shadowCastingMode, "only the aircraft's own shadow on the ground");
+ var airframe = plane.GetComponentInChildren<MeshFilter>().GetComponent<Renderer>();
+ var keep = layer.KeepClear.Single(k => k[0].Contains(centre))[0];
+ for (int i = 0; i < 32; i++)
+ {
+ float t = i * SeaAirCollection.SpitfireLoopSeconds / 32f;
+ loop.Place(t);
+ var at = SeaAirCollection.LoopOffset(t); var heading = SeaAirCollection.LoopHeading(t);
+ var drawn = centre + new Vector3(at.x, 0f, at.y);
+ var body = airframe.bounds;
+ Assert.Less(Vector3.Dot(flag.position - drawn, new Vector3(heading.x, 0f, heading.y)), -0.3f * SeaAirCollection.SizeOf(SeaAirCollection.Spitfire),
+ $"over the tail, behind the aircraft's middle, at {t:0.0} s");
+ foreach (var look in new[] { Vector3.forward, Vector3.back, Vector3.left, Vector3.right, new Vector3(1f, 0f, 1f).normalized })
+ {
+ Statecraft.Game.Map.Units.UnitFlagFacing.Face(flag, flag.position + look * 50000f);
+ Assert.Greater(Vector3.Dot(flag.up, Vector3.up), 0.999f, $"upright at {t:0.0} s");
+ var fb = flag.GetComponent<Renderer>().bounds;
+ Assert.Greater(fb.min.y, body.max.y, $"wholly above the aircraft's box, clear of the airframe, at {t:0.0} s");
+ Assert.Less(fb.min.y - body.max.y, 0.25f * SeaAirCollection.SizeOf(SeaAirCollection.Spitfire), $"just above it, at {t:0.0} s");
+ Assert.IsTrue(keep.Contains(fb.min) && keep.Contains(fb.max), $"inside the labels' keep-clear box at {t:0.0} s");
+ }
+ }
+ }
+
+ /// <summary>The flight's per-frame work allocates nothing (the aircraft, its bank, its propeller, its shadow and its flag).</summary>
+ [Test]
+ public void TheSpitfireLoopAllocatesNothingPerFrame()
+ {
+ var map = OpenMap();
+ var (_, _, loop, _) = DrawnSpitfire(map);
+ loop.Place(1f);
+ int i = 0;
+ Assert.That(() => { for (int k = 0; k < 100; k++) loop.Place(++i * 0.137f); }, UnityEngine.TestTools.Constraints.ConstraintExtensions.AllocatingGCMemory(Is.Not));
+ // Update in play (not held), through the clock seam, and the flags turning to a camera (review of #2260).
+ typeof(SpitfireLoop).GetField("still", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.SetValue(loop, false);
+ var update = typeof(SpitfireLoop).GetMethod("Update", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!;
+ var clock = SpitfireLoop.Clock; float now = 3f;
+ try
+ {
+ SpitfireLoop.Clock = () => now;
+ var tick = (Action)Delegate.CreateDelegate(typeof(Action), loop, update); // a plain call, as the player loop's
+ tick();
+ Assert.That(() => { for (int k = 0; k < 100; k++) { now += 0.016f; tick(); } }, UnityEngine.TestTools.Constraints.ConstraintExtensions.AllocatingGCMemory(Is.Not));
+ }
+ finally { SpitfireLoop.Clock = clock; }
+ var eye = new Vector3(30000f, 40000f, 150000f);
+ Statecraft.Game.Map.Units.UnitFlagFacing.FaceAll(eye);
+ Assert.That(() => { for (int k = 0; k < 100; k++) { eye.x += 10f; Statecraft.Game.Map.Units.UnitFlagFacing.FaceAll(eye); } }, UnityEngine.TestTools.Constraints.ConstraintExtensions.AllocatingGCMemory(Is.Not));
+ }
+
+ /// <summary>Review of #2260: drawing, dropping and drawing the Spitfire again (its dates end and come back, the layer
+ /// redraws) makes no new propeller, shadow or flag meshes or materials past the first: the layer makes them once. When
+ /// its dates end under residency, the aircraft and its shadow-and-flag object both go, and the labels keep clear of
+ /// exactly the craft left.</summary>
+ [Test]
+ public void DrawingAndDroppingTheSpitfireAgainLeaksNoMeshesOrMaterials()
+ {
+ var map = OpenMap();
+ int Meshes() => Resources.FindObjectsOfTypeAll<Mesh>().Count(m => m.name == "SpitfirePropellerBlur" || m.name == "SpitfireShadow"
+ || m.name == Statecraft.Game.Map.Units.UnitFlags.MeshName(Statecraft.Game.Map.Units.UnitFlags.Egypt));
+ int Materials() => Resources.FindObjectsOfTypeAll<Material>().Count(m => m.name.StartsWith("UnitFlag (egypt", StringComparison.Ordinal)
+ || m.name == Statecraft.HexTiles.HexMaterials.AttackBorder);
+ SeaAirCollection Show(DateTime date) { var l = CollectionGeometryFixture.Craft(map, date, Array.Empty<Placement>(), C)!; AnswerAll(); return l; }
+ var layer = Show(new DateTime(1948, 6, 15));
+ Assert.IsNotNull(layer.transform.Find("el-arish-spitfire"));
+ int meshes = Meshes(), materials = Materials();
+ Assert.GreaterOrEqual(meshes, 3, "the blur, the shadow and the flag");
+ for (int i = 0; i < 3; i++)
+ {
+ layer = Show(new DateTime(1949, 8, 15));
+ Assert.IsNull(layer.transform.Find("el-arish-spitfire"), "no Spitfire on 15 August 1949");
+ Assert.IsNull(layer.transform.Find("el-arish-spitfire" + SeaAirCollection.SpitfireMarksSuffix), "and no shadow or flag");
+ Assert.AreEqual(layer.Placed.Count, layer.KeepClear.Count, "the labels keep clear of the craft left, and nothing else");
+ layer = Show(new DateTime(1948, 6, 15));
+ Assert.IsNotNull(layer.transform.Find("el-arish-spitfire" + SeaAirCollection.SpitfireMarksSuffix));
+ Assert.AreEqual(meshes, Meshes(), $"no new meshes after {i + 1} redraws");
+ Assert.AreEqual(materials, Materials(), $"no new materials after {i + 1} redraws");
+ }
+ }
+
+ /// <summary>Review of #2260: under residency, when the Spitfire's dates end its model's lease is released with both its
+ /// objects gone (the aircraft and its shadow-and-flag object), and their keep-clear entries with them.</summary>
+ [Test]
+ public void WhenItsWindowEndsTheSpitfireAndItsMarksAndTheirKeepClearGoTogether()
+ {
+ var map = OpenMap();
+ var go = new GameObject(SeaAirCollection.Name); go.transform.SetParent(map.Terrain.transform, false);
+ var layer = go.AddComponent<SeaAirCollection>();
+ typeof(SeaAirCollection).GetField("map", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.SetValue(layer, map);
+ var released = new List<(string id, bool plane, bool marks)>();
+ layer.ConfigureResidency(new CollectionResidencyPolicy(1000000, 1000001, 1000000, 1000001, int.MaxValue, "TEST ONLY"),
+ (id, detail, done) => { SeaAirCollection.Request(id, detail, done); return new ReleaseProbe(() => released.Add((id,
+ layer.transform.Find("el-arish-spitfire") != null, layer.transform.Find("el-arish-spitfire" + SeaAirCollection.SpitfireMarksSuffix) != null))); });
+ var keepOf = (System.Collections.IDictionary)typeof(SeaAirCollection).GetField("keepOf", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.GetValue(layer)!;
+ SeaAirCollection.ShowAt(map, new DateTime(1948, 12, 15), Array.Empty<Placement>(), C);
+ AnswerAll();
+ Assert.IsNotNull(layer.transform.Find("el-arish-spitfire" + SeaAirCollection.SpitfireMarksSuffix), "the shadow and flag drawn");
+ Assert.AreEqual(layer.Placed.Count, keepOf.Count, "one keep-clear entry a drawn craft (none for the shadow and flag)");
+ SeaAirCollection.ShowAt(map, new DateTime(1949, 1, 15), Array.Empty<Placement>(), C);
+ var spitfire = released.Single(r => r.id == SeaAirCollection.Spitfire);
+ Assert.IsFalse(spitfire.plane || spitfire.marks, "the aircraft and its shadow and flag are gone before the lease is released");
+ Assert.IsNull(layer.transform.Find("el-arish-spitfire" + SeaAirCollection.SpitfireMarksSuffix));
+ Assert.AreEqual(layer.Placed.Count, keepOf.Count, "and their keep-clear entries");
+ Assert.AreEqual(layer.Placed.Count, layer.KeepClear.Count);
+ foreach (System.Collections.DictionaryEntry e in keepOf) Assert.IsTrue((GameObject)e.Key != null, "no entry for a destroyed object");
+ }
+
/// <summary>Nothing is drawn until the stream answers, and only the far mesh, once per model. Then every craft is drawn,
/// each boat on the open sea (the heightmap's 0 m), its hull passing SeaCraft's own clearance (open sea round it, clear of
/// the harbour works and of SeaCraft's boats and each other) and at least SeaCraft.OffshoreNearM out from its shore point
@@ -495,7 +838,10 @@ public class SeaAirCollectionTests
var boxes = layers.Where(l => l != null).SelectMany(l => l!.GetComponentsInChildren<Renderer>(true).Select(r => (l!.GetType().Name, r.bounds))).ToList();
others = Math.Max(others, boxes.Count);
var craft = CollectionGeometryFixture.Craft(map, date, none, C)!; AnswerAll();
- foreach (Transform t in craft.transform)
+ // The drawn craft and the Spitfire's flag (its shadow sits beside it too, but a shadow may fall on a model).
+ var flagNow = craft.transform.Find("el-arish-spitfire" + SeaAirCollection.SpitfireMarksSuffix)?.Find(SeaAirCollection.SpitfireFlagName);
+ Assert.AreEqual(date.Year == 1948, flagNow != null, $"the Spitfire's flag on {date:d MMM yyyy}");
+ foreach (var t in craft.Placed.Select(p => craft.transform.Find(p.Key)).Concat(flagNow != null ? new[] { flagNow } : Array.Empty<Transform>()))
{
var b = WorldBounds(t.gameObject); checkedCraft++;
foreach (var (owner, o) in boxes)
@@ -504,7 +850,7 @@ public class SeaAirCollectionTests
}
}
Assert.Greater(others, 0, "the other layers drew");
- Assert.AreEqual(9, checkedCraft, "every craft checked, five on the first turn (the Spitfire too), four on the second");
+ Assert.AreEqual(10, checkedCraft, "every craft checked, five on the first turn (the Spitfire too) and its flag, four on the second");
}
finally
{
diff --git a/unity/Assets/Tests/EditMode/TalModelsShots.cs b/unity/Assets/Tests/EditMode/TalModelsShots.cs
index 69d17ffb0..2224ce1d6 100644
--- a/unity/Assets/Tests/EditMode/TalModelsShots.cs
+++ b/unity/Assets/Tests/EditMode/TalModelsShots.cs
@@ -457,6 +457,57 @@ public class TalModelsShots
[UnityTest] public IEnumerator SpitfireBeforeEnglish() { yield return Spitfire(false, false); }
[UnityTest] public IEnumerator SpitfireAfterEnglish() { yield return Spitfire(false, true); }
+ /// <summary>The owner's report of 2 November 2026 ("the gyptian plane's propelor isn't moving and it doesnt look fliying,
+ /// also it doesnt show its an egyptian unit"): the Spitfire on the opening turn from the player's camera (CameraRig.Pitch,
+ /// yaw 0), at the camera's opening distance and at 30 km, the look-at on the ground along the view ray through the plane
+ /// so the plane is mid-frame. Poses come from SpitfireLoop.Place, as play draws them: 0 s (the pass in from el-Arish,
+ /// straight), 10 s (the turn at the loop's east end, where the camera sees the propeller's disc face on), and each 0.02 s
+ /// later (the propeller's turn between two frames). The same
+ /// test on the base branch gives the "before" stills, on the PR branch the "after" ones (spitfire-flight-shots).</summary>
+ IEnumerator SpitfireFlight(bool hebrew)
+ {
+ var savedCraft = SeaAirCollection.Request;
+ try
+ {
+ Directory.CreateDirectory(Path.Combine(CivMovementShots.ShotDir, "..", "spitfire-flight-shots"));
+ yield return Boot(hebrew);
+ var map = Object.FindFirstObjectByType<MapScene>();
+ var state = root.Bridge!.State; var content = root.Bridge.Content;
+ SeaAirCollection.Request = Answer(Array.Empty<string>());
+ Drop(map, SeaAirCollection.Name);
+ var layer = CollectionGeometryFixture.Craft(map, state.Date, state.Placements, content)!;
+ var plane = layer.transform.Find("el-arish-spitfire");
+ var loop = plane.GetComponent<SpitfireLoop>();
+ var rig = Camera.main.GetComponent<CameraRig>(); var cc = rig.GetComponent<CameraController>();
+ float opening = rig.Distance;
+ Debug.Log($"SHOT spitfire-flight on {state.Date:yyyy-MM-dd}: opening distance {opening:F0} m, loop centre {layer.Placed.Single(p => p.Model == SeaAirCollection.Spitfire).At}");
+ var down = Quaternion.Euler(CameraRig.Pitch, 0f, 0f) * Vector3.forward;
+ foreach (var (zoom, distance) in new[] { ("opening", opening), ("close", 30000f) })
+ foreach (var (pose, seconds) in new[] { ("pass", 0f), ("pass-later", 0.02f), ("turn", 10f), ("turn-later", 10.02f) })
+ {
+ if (zoom == "opening" && pose.EndsWith("-later")) continue; // the propeller is a few pixels at the opening zoom
+ loop.Place(seconds);
+ var at = plane.GetComponentsInChildren<Renderer>(true).Select(r => r.bounds).Aggregate((a, b) => { a.Encapsulate(b); return a; }).center;
+ // The ground point on the view ray through the plane: the player's look-at that puts it mid-frame.
+ var ground = at + down * ((map.Terrain.SampleHeight(at) + map.Terrain.transform.position.y - at.y) / down.y);
+ Look(new Vector3(ground.x, 0f, ground.z), distance);
+ CameraController.Step(rig, default, 0f, cc.Bounds, cc.Ground, cc.GroundTop, true);
+ UnitFlagFacing.FaceAll(Camera.main.transform.position);
+ for (int i = 0; i < 5; i++) yield return null;
+ loop.Place(seconds); // again after the frames: nothing else moves it in edit mode, but the shot must be exact
+ CivMovementShots.Shot(rt!, Path.Combine("..", "spitfire-flight-shots", $"spitfire-{zoom}-{pose}-{(hebrew ? "he" : "en")}"));
+ Debug.Log($"SHOT spitfire-flight {zoom} {pose}: {distance:F0} m, plane at {at}, viewport {Camera.main.WorldToViewportPoint(at)}");
+ var vp = Camera.main.WorldToViewportPoint(at);
+ Assert.That(vp.x, Is.InRange(0.1f, 0.9f), $"the plane in frame across, {zoom} {pose}");
+ Assert.That(vp.y, Is.InRange(0.1f, 0.9f), $"the plane in frame up and down, {zoom} {pose}");
+ }
+ }
+ finally { SeaAirCollection.Request = savedCraft; }
+ }
+
+ [UnityTest] public IEnumerator SpitfireFlightEnglish() { yield return SpitfireFlight(false); }
+ [UnityTest] public IEnumerator SpitfireFlightHebrew() { yield return SpitfireFlight(true); }
+
[UnityTest] public IEnumerator MalikiyyaEnglish() { yield return Malikiyya(false); }
[UnityTest] public IEnumerator MalikiyyaHebrew() { yield return Malikiyya(true); }