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 Dakotas bomb Tel Aviv on 15 July 1948 too; an illustrative 101 S-199 attack and the sourced anti-aircraft kill (Refs #2482) (#2649)

Eyal Golan0752803a4bca
diff --git a/changelog.d/dakota-101-july.md b/changelog.d/dakota-101-july.md
new file mode 100644
index 000000000..c6bdba34f
--- /dev/null
+++ b/changelog.d/dakota-101-july.md
@@ -0,0 +1,9 @@
+- On the 15 July 1948 turn, the second Egyptian bombing period (8 to 17 July 1948), the two Egyptian Dakotas bomb Tel Aviv
+ again, as on 15 May, and Tel Aviv's air defence fights them. Two of 101 Squadron's Avia S-199s dive on the lead Dakota
+ in turn, the first as the pair bombs Tel Aviv and the second on the pass back out to sea; each fires (a muzzle flash and
+ tracer) and hits it (puffs of smoke), then pulls away, never bringing it down. Between the two attacks, anti-aircraft
+ fire from Tel Aviv bursts round the second Dakota, which trails smoke, falls out of the loop and goes down in a blast,
+ and a fresh one joins the loop out at sea before the next pass. The anti-aircraft kill is sourced (17 July
+ 1948, JTA); no source shows 101 Squadron intercepting the Dakotas over Tel Aviv in July, so the fighters' attack is an
+ illustration (owner: "do 1+2"). Looks only: the game's numbers do not change. The S-199 is the map's own code-built
+ model.
diff --git a/research_notes/GDD phase 7/tel-aviv-bombing-july-1948.md b/research_notes/GDD phase 7/tel-aviv-bombing-july-1948.md
new file mode 100644
index 000000000..9200392d7
--- /dev/null
+++ b/research_notes/GDD phase 7/tel-aviv-bombing-july-1948.md
@@ -0,0 +1,90 @@
+# The Egyptian bombing of Tel Aviv in July 1948: which aircraft, and who fought them (research note, 2026-11-05)
+
+Status: **AI draft, not checked by a person.** Research only: it backs a looks-only map change (the Dakotas and Tel Aviv's
+air defence on the 15 July 1948 turn) and changes nothing in `content/` or `sim/`. This note was read and written by an AI
+agent. A person should open each source and confirm what it supports; `reviewed_by` and `reviewed_on` stay empty.
+
+## Question
+
+The owner asked: "we will need an animation of the 101 attacking the dakotas", then chose "(a) Add the Dakotas to the 15
+July 1948 turn, the second bombing period, with 101 Squadron's fighters attacking them over Tel Aviv. Both sides are
+historically present that turn." Two facts need a source before that is drawn: which aircraft bombed Tel Aviv in the second
+bombing period, 8 to 17 July 1948, and whether 101 Squadron intercepted them over Tel Aviv then.
+
+## Short answer
+
+- **The second bombing period, 8 to 17 July 1948, is sourced** (he.wiki, row S1). The game's monthly turn of 15 July 1948
+ falls inside it.
+- **Dakotas in that period: [S], and [C] inside one article.** en.wiki "1948 Arab–Israeli War" (citing Morris 2008, pp.
+ 294-295) has Egyptian raids on Tel Aviv "by Dakota aircraft accompanied by a Spitfire fighter escort" after the Israeli B-17
+ raid of 15 July, and "One Egyptian Dakota was lost" (row S2). The same article says, in its 3 June paragraph, that there
+ were "no more raids by bombers for the rest of the war" (row S3). he.wiki's 13 July paragraph has two bombers and two
+ fighters but does not name the bombers' type (row S4). Morris itself was not opened (see "Not read").
+- **One Egyptian Dakota shot down by anti-aircraft fire over Tel Aviv on 17 July 1948: [S]**, JTA 19 July 1948, already in
+ the repo (row S5).
+- **101 Squadron intercepting the Dakotas over Tel Aviv in July: [GAP].** No source read says so. en.wiki says only that
+ Israeli fighters "on occasion intercepted Egyptian aircraft" in the Ten Days, with no place, day or type (row S6). 101
+ Squadron was flying the Avia S-199 then, and was the IAF's fighter squadron (rows S7, S8), so the type is right for the
+ turn; the interception itself is not sourced. The only sourced 101 fight with the Dakotas is Modi Alon's of 3 June 1948
+ (row S9).
+- **A 101 Squadron shoot-down of a Dakota in July: none found.** The only July Dakota loss sourced is the anti-aircraft
+ kill of 17 July (row S5); "One Egyptian Dakota was lost" (row S2) does not say how.
+
+## What was built from this (owner's answer "do 1+2")
+
+The owner was offered two options and answered "do 1+2":
+
+1. On the 15 July 1948 turn the Dakotas bomb Tel Aviv and 101 Squadron's S-199s attack them **with hits but no 101
+ shoot-down**, shown as an illustration of that turn's air defence (rows S6 to S8; the interception itself is [GAP]).
+2. **One Dakota goes down to anti-aircraft fire**, the sourced 17 July 1948 event (row S5): flak bursts near Tel Aviv, then
+ the Dakota smoking and falling out of the loop. Where it fell is not sourced; the fall's path is a design value.
+
+## Conventions
+
+- Every source below was opened on **2026-11-05** unless the row says otherwise.
+- Tags as in `research_notes/GDD phase 7/squadron-101-dates-1948.md`: **[V]** two or more independent sources agree, or one
+ authoritative primary source; **[S]** one source, or several that copy one another; **[C]** sources disagree, every
+ version kept; **[GAP]** nothing reachable settles it.
+- Wikipedia is a pointer, read at the revision given (`oldid`). Quotation marks are verbatim.
+
+## Sources
+
+| Short name | What it is | Where read |
+| --- | --- | --- |
+| he.wiki bombing | הפצצת תל אביב במלחמת העצמאות | https://he.wikipedia.org/w/index.php?oldid=43856594 |
+| en.wiki war | 1948 Arab–Israeli War | https://en.wikipedia.org/w/index.php?oldid=1375001749 |
+| he.wiki Tel Aviv | תל אביב במלחמת העצמאות | https://he.wikipedia.org/w/index.php?oldid=43556405 |
+| JTA 19 July 1948 | JTA Daily News Bulletin, as read for the repo note | `research_notes/GDD phase 7/egyptian-air-bases-and-raids-1948-1872.md`, row R11 (read 2026-10-28; not re-opened here) |
+| he.wiki 101 | טייסת 101 | https://he.wikipedia.org/w/index.php?oldid=44131461 |
+| en.wiki 101 | 101 Squadron (Israel) | https://en.wikipedia.org/w/index.php?oldid=1379560417 |
+| 101squadron.com | Fan site, the S-199 page | https://101squadron.com/101/s-199s.html |
+| Repo note 101 | 101 Squadron's 1948 dates | `research_notes/GDD phase 7/squadron-101-dates-1948.md` |
+
+## Findings
+
+| Row | Claim | Source and exact words | Tag |
+| --- | --- | --- | --- |
+| S1 | The second bombing period ran 8 to 17 July 1948; the last bombing of Tel Aviv was on 17 July. | he.wiki bombing, section "תקופת ההפצצות השנייה": "תקופת ההפצצות השנייה על תל אביב התרחשה במהלך קרבות עשרת הימים (8 עד 17 ביולי)"; "ב-17 ביולי הופצצה תל אביב בפעם האחרונה בשתי גיחות מצריות" (no footnote on either sentence) | [S] |
+| S2 | After the Israeli B-17 raid of 15 July, Egypt raided Tel Aviv with Dakotas escorted by a Spitfire; one Dakota was lost. | en.wiki war, section on the Ten Days' air operations, footnoted to Morris, 2008, pp. 294-295: "The Egyptians responded with raids on Tel Aviv by Dakota aircraft accompanied by a Spitfire fighter escort, killing at least 15 people. One Egyptian Dakota was lost." | [S] (a pointer to Morris, not read) |
+| S3 | No bomber raids on Tel Aviv after 3 June. | en.wiki war, 3 June paragraph: "Although Tel Aviv would see additional raids by fighter aircraft, there would be no more raids by bombers for the rest of the war." he.wiki Tel Aviv calls the 3 June raid "המתקפה האווירית האחרונה של הצבא המצרי על תל אביב" (footnote: "תולדות מלחמת הקוממיות, 232"), then adds "גם בעת קרבות עשרת הימים הופצצה העיר מספר פעמים". | [C] with S2 and S4 |
+| S4 | On 13 July two bombers and two fighters bombed Tel Aviv; the bombers' type is not named. The usual Egyptian sortie was two bombers, usually Dakotas, with one or two Spitfires. | he.wiki bombing: "ביום שלישי, 13 ביולי, ספגה תל אביב הפצצה כבדה על ידי שני מפציצים ושני מטוסי קרב מצרים"; and, for the war as a whole, "שיטת התקיפה המצרית הייתה בדרך כלל גיחה של שני מטוסי הפצצה, בדרך כלל מטוסי דקוטה, שלוו במטוס קרב אחד או שניים מדגם ספיטפייר." | [S] |
+| S5 | On 17 July Tel Aviv had six Egyptian air raids; one Egyptian Dakota was shot down by anti-aircraft fire. | JTA 19 July 1948, bulletin image PDF p. 3, dateline "TEL AVIV, July 18. (JTA)", as recorded in row R11 of the repo note: "Six Jews were killed and at least 20 wounded yesterday when Tel Aviv was subjected to six Egyptian air raids"; the same row records the Dakota "shot down by anti-aircraft fire". | [S]; agent-read 2026-10-28, a person's check pending |
+| S6 | Israeli fighters sometimes intercepted Egyptian aircraft in the Ten Days. | en.wiki war, same section as S2 (same footnote): "In addition, Israeli Air Force fighter aircraft flew ground support missions and on occasion intercepted Egyptian aircraft." No place, day or aircraft type. | [S] for "on occasion"; [GAP] for an interception over Tel Aviv |
+| S7 | 101 Squadron flew the Avia S-199 in July 1948, few of them serviceable. | 101squadron.com: "By the time fighting intensified on July 9, 101 Squadron had achieved a 1:1 pilot to plane ratio on paper, although the number of serviceable S-199s was almost always limited to four or fewer." Repo note 101: the S-199 from 20 May to mid-October 1948. | [S] |
+| S8 | On 8 July Modi Alon, flying from Herzliya, shot down an Egyptian Spitfire on the way back from a strike in the Negev, not a Dakota and not over Tel Aviv. | he.wiki 101: "ב-8 ביולי המריא אלון משדה התעופה בהרצליה כדי לתקוף טור משוריין מצרי בביר עסלוג' שבנגב. בדרכו חזרה הבחין המבנה שבו טס בשני מטוסי ספיטפייר מצריים, ואלון הפיל אחד מהם." | [S] |
+| S9 | The only sourced 101 Squadron fight with Egyptian Dakotas: 3 June 1948, Modi Alon shot down two over Tel Aviv. | en.wiki 101: "Modi Alon, after taking off from Herzliya Airport, shot down a pair of Royal Egyptian Air Force C-47s which had just bombed Tel Aviv." he.wiki bombing: "מטוס קרב ישראלי שהוטס על ידי הטייס מודי אלון המריא והצליח להפיל שני מטוסי דקוטה מצרים ששימשו כמפציצים." | [V] (two articles, each footnoted; already used by `SeaAirCollection.Dakota.cs`) |
+
+## Disagreements kept side by side
+
+| Point | Version 1 | Version 2 |
+| --- | --- | --- |
+| Bombers over Tel Aviv after 3 June | No more bomber raids (en.wiki war, 3 June paragraph; he.wiki Tel Aviv, "the last air attack", citing תולדות מלחמת הקוממיות p. 232) | Dakota raids after 15 July, one Dakota lost (en.wiki war, Ten Days section, citing Morris 2008); "two bombers" on 13 July (he.wiki bombing); a Dakota shot down by anti-aircraft fire on 17 July (JTA 19 July 1948) |
+
+## Not read
+
+- **Morris, *1948: A History of the First Arab-Israeli War* (2008), pp. 294-295**: the source of row S2. archive.org holds
+ it only as a lending copy (`1948historyoffir00morr`); it was not opened. A person should read those two pages.
+- **The Davar article of 14 July 1948** that he.wiki cites for 13 July ("התקפת טרור קשה על תל אביב"): the NLI newspaper
+ site answered with a browser check and could not be read from this machine.
+- **Scanned aviation histories** (Cull et al., *Spitfires over Israel*; the Helion Middle East@War volumes): third-party
+ scans were not downloaded. A person with the books could settle rows S3 and S6.
diff --git a/unity/Assets/Scripts/Map/Collection/DakotaLoop.cs b/unity/Assets/Scripts/Map/Collection/DakotaLoop.cs
index d3ebecbd0..0db89c8c3 100644
--- a/unity/Assets/Scripts/Map/Collection/DakotaLoop.cs
+++ b/unity/Assets/Scripts/Map/Collection/DakotaLoop.cs
@@ -272,7 +272,7 @@ namespace Statecraft.Game.Map.Collection
/// <summary>One quad mesh per frame of a <paramref name="grid"/> x <paramref name="grid"/> flipbook, its UVs on that
/// frame (frame 0 top left, then along the rows, as Unity's texture sheet animation), facing -z as the built-in quad,
/// white (the particle shaders multiply the vertex colour).</summary>
- static Mesh[] Frames(MapRuntimeAssets owned, int grid)
+ internal static Mesh[] Frames(MapRuntimeAssets owned, int grid)
{
var frames = new Mesh[grid * grid];
float k = 1f / grid;
diff --git a/unity/Assets/Scripts/Map/Collection/SeaAirCollection.AirDefence.cs b/unity/Assets/Scripts/Map/Collection/SeaAirCollection.AirDefence.cs
new file mode 100644
index 000000000..8813d529d
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Collection/SeaAirCollection.AirDefence.cs
@@ -0,0 +1,387 @@
+#nullable enable
+using System;
+using System.Collections.Generic;
+using Statecraft.Game.Map.Kits;
+using Statecraft.Game.Map.Units;
+using UnityEngine;
+using UnityEngine.Rendering;
+
+namespace Statecraft.Game.Map.Collection
+{
+ /// <summary>Tel Aviv's air defence against the two Egyptian Dakotas on the turns of the second bombing period, 8 to 17 July
+ /// 1948 (<see cref="DakotaSecondFrom"/>; on the game's monthly turns, the 15 July 1948 turn). The owner asked: "we will need
+ /// an animation of the 101 attacking the dakotas", chose "(a) Add the Dakotas to the 15 July 1948 turn, the second bombing
+ /// period, with 101 Squadron's fighters attacking them over Tel Aviv. Both sides are historically present that turn.", and
+ /// then answered "do 1+2" to two options: (1) 101 Squadron's Avia S-199s attack the Dakotas with hits but no 101 shoot-down,
+ /// shown as an illustration of that turn's air defence; (2) one Dakota goes down to anti-aircraft fire, the sourced event of
+ /// 17 July 1948.
+ ///
+ /// What is sourced, and what is not (research_notes/GDD phase 7/tel-aviv-bombing-july-1948.md, agent-read, a person's
+ /// check pending): the second period itself, 8 to 17 July (he.wiki "הפצצת תל אביב במלחמת העצמאות", rev 43856594); Egyptian
+ /// raids on Tel Aviv by Dakotas with a Spitfire escort after the Israeli B-17 raid of 15 July, "One Egyptian Dakota was
+ /// lost" (en.wiki "1948 Arab–Israeli War", rev 1375001749, citing Morris 2008, pp. 294-295; the same article says elsewhere
+ /// there were no more bomber raids after 3 June, so [C]); one Egyptian Dakota shot down by anti-aircraft fire over Tel Aviv
+ /// on 17 July (JTA 19 July 1948, row R11 of research_notes/GDD phase 7/egyptian-air-bases-and-raids-1948-1872.md). No
+ /// source read shows 101 Squadron intercepting the Dakotas over Tel Aviv in July: the fighters' attack is an illustration,
+ /// so they hit but never bring a Dakota down. The only sourced 101-against-Dakota fight is Modi Alon's, 3 June 1948.
+ ///
+ /// The fighters are the Avia S-199, 101 Squadron's type from 20 May to mid-October 1948 (content/map/units_1948.yaml,
+ /// squadron_101), the map's own code-built model (UnitModels.AviaS199, sourced in docs/units.md), at the unit tokens'
+ /// aircraft scale. No model file is added or changed. Everything here is drawn by <see cref="TelAvivAirDefence"/> on the
+ /// Dakotas' own loop clock, a pure function of it. Presentation only: no sim, content, save or hash change.</summary>
+ public sealed partial class SeaAirCollection
+ {
+ /// <summary>The air defence's object key: it is drawn beside the Dakotas and goes with them.</summary>
+ public const string AirDefenceKey = DakotaKey + "-air-defence";
+
+ /// <summary>The two fighters' object names, under the air defence's object.</summary>
+ public static readonly string[] FighterKeys = { "s199-1", "s199-2" };
+
+ /// <summary>True on the dates the S-199s and the anti-aircraft fire show: the second bombing period (the Dakotas' second
+ /// window, <see cref="DakotaSecondFrom"/>). Never in the first period: the 15 May turn shows the Dakotas alone.</summary>
+ public static bool AirDefenceWanted(DateTime date) => date >= DakotaSecondFrom && date <= DakotaSecondTo;
+
+ /// <summary>DESIGN VALUES for the fighters' choreography, in the lead Dakota's loop time (s): fighter i dives on the
+ /// lead from <see cref="FighterAttackStartS"/>[i] for <see cref="FighterAttackS"/>, the first as the pair bombs Tel Aviv
+ /// (on the loop's southern pass), the second on the pass back out to sea (the northern pass), both where the Dakotas fly
+ /// level. The heights keep every fighter's box, at any bank and pitch, over the box of a Dakota under it, banked in its
+ /// turn or not (sampled with the two models' sizes, with a margin of about 500 m). On the lead's track the fighter starts <see cref="FighterBehindS"/> of the loop behind it and
+ /// <see cref="FighterTopM"/> above, closes, passes <see cref="FighterPassSideM"/> to the inside and
+ /// <see cref="FighterPassUpM"/> above at the middle of the attack, and ends <see cref="FighterAheadS"/> ahead, climbing
+ /// back to <see cref="FighterTopM"/> (it dives in, passes and pulls away). For the rest of the loop it falls back to its
+ /// start, flying up to <see cref="FighterOutsideM"/> outside the Dakotas' track, slower than they are. Smoothsteps join the
+ /// pieces, so the path and its speed are continuous, and the path closes every loop.</summary>
+ public static readonly float[] FighterAttackStartS = { -6f, 54f };
+ public const float FighterAttackS = 16f, FighterBehindS = 12.7f, FighterAheadS = 7.6f, FighterPassSideM = 2500f, FighterOutsideM = 3000f,
+ FighterPassUpM = 3900f, FighterTopM = 5400f;
+
+ /// <summary>DESIGN VALUES: the share of its attack over which a fighter fires (its gun's flash and tracer), and over which
+ /// its rounds hit the lead (puffs of smoke on the Dakota, <see cref="FighterHits"/> of them). Hits, never a kill: no source
+ /// shows 101 Squadron bringing down a Dakota over Tel Aviv in July.</summary>
+ public const float FighterFireFrom = 0.28f, FighterFireTo = 0.5f, FighterHitFrom = 0.34f, FighterHitTo = 0.56f;
+ public const int FighterHits = 4, FighterTracers = 3;
+
+ /// <summary>DESIGN VALUES for the gun: a tracer dash <see cref="TracerLengthM"/> long and <see cref="TracerWidthM"/>
+ /// wide runs from the muzzle to the Dakota <see cref="TracerRate"/> times a second; the muzzle flash, the gun's
+ /// (UnitGunFire.Flash), <see cref="MuzzleFlashM"/> across, every <see cref="MuzzleFlashGapS"/>; a hit is a flash
+ /// <see cref="HitFlashM"/> across and a puff of the smoke flipbook <see cref="HitPuffM"/> across, living
+ /// <see cref="HitPuffS"/>, left behind where it was struck.</summary>
+ public const float TracerLengthM = 1400f, TracerWidthM = 260f, TracerRate = 2.5f, MuzzleFlashM = 900f, MuzzleFlashGapS = 0.15f,
+ HitFlashM = 900f, HitPuffM = 1300f, HitPuffS = 2.2f;
+
+ /// <summary>DESIGN VALUES for the anti-aircraft fire (option 2, the sourced 17 July shoot-down): in the wing Dakota's own
+ /// loop time, after its bombs, <see cref="FlakAtS"/> are the bursts, each fired from one of <see cref="FlakSites"/> gun
+ /// sites on Tel Aviv's hex (a flash on the ground <see cref="FlakFlightS"/> before the burst), bursting near the wing:
+ /// a flash and a dark puff, <see cref="FlakBurstM"/> across, living <see cref="FlakBurstS"/>. The last burst, at
+ /// <see cref="WingHitS"/>, is on it.</summary>
+ public static readonly float[] FlakAtS = { 2.5f, 4.5f, 6.5f, 8.5f, 10.5f, 12f };
+ public static readonly Vector3[] FlakMissM =
+ {
+ new Vector3(-2600f, 700f, 1900f), new Vector3(2200f, -500f, -2400f), new Vector3(-1500f, 900f, -2000f),
+ new Vector3(1800f, 400f, 2300f), new Vector3(-900f, -300f, 1500f), Vector3.zero,
+ };
+ public const int FlakSites = 3;
+ public const float FlakFlightS = 1.2f, FlakBurstM = 1500f, FlakBurstS = 2.6f, FlakSiteM = 1100f, GunFlashM = 700f;
+
+ /// <summary>DESIGN VALUES for the wing's fall: hit at <see cref="WingHitS"/> of its own loop, it trails smoke and goes down
+ /// over <see cref="WingFallS"/>, turning left by <see cref="WingFallTurnDeg"/> (back toward the sea), its nose down at
+ /// most <see cref="WingFallPitchDeg"/>, rolling to <see cref="WingFallBankDeg"/> and level again, its speed easing to
+ /// <see cref="WingFallSpeedShare"/>; where it reaches the ground a blast of the bombs' flipbook goes up, and it is gone.
+ /// Where it fell is not sourced: the path is a design value. The loop repeats every <see cref="DakotaLoopSeconds"/>, so
+ /// one loop is one raid: a fresh wing joins the loop out over the sea at <see cref="WingRejoinS"/>, before the next
+ /// pass, and the same raid plays again. One anti-aircraft kill a loop, as on 17 July; the lead is never brought down.</summary>
+ public const float WingHitS = 12f, WingFallS = 18f, WingFallTurnDeg = 150f, WingFallPitchDeg = 25f, WingFallBankDeg = 35f, WingFallSpeedShare = 0.75f,
+ WingRejoinS = 80f;
+
+ /// <summary>DESIGN VALUE: the falling wing's centre ends this share of its span over the highest ground under its fall,
+ /// its wings levelled again over the last 40 per cent of the fall, so that with its nose down at
+ /// <see cref="WingFallPitchDeg"/> it reaches the ground (the aircraft is drawn 336 times its size, so a deeper fall would
+ /// bury a wing in the hills first).</summary>
+ public const float WingFallEndShare = 0.1f;
+
+ /// <summary>DESIGN VALUES for the smoke the falling wing trails: a puff of the smoke flipbook every
+ /// <see cref="TrailGapS"/>, <see cref="TrailPuffM"/> across, living <see cref="TrailPuffS"/>, at most
+ /// <see cref="TrailPuffs"/> showing.</summary>
+ public const float TrailGapS = 0.6f, TrailPuffM = 1500f, TrailPuffS = 6f;
+ public static readonly int TrailPuffs = Mathf.CeilToInt(TrailPuffS / TrailGapS) + 1;
+
+ static float Smooth(float x) { x = Mathf.Clamp01(x); return x * x * (3f - 2f * x); }
+
+ /// <summary>Fighter <paramref name="fighter"/>'s share of its attack at the lead's loop time <paramref name="seconds"/>:
+ /// in [0, 1) during the attack, negative otherwise.</summary>
+ public static float FighterAttackShare(int fighter, float seconds)
+ {
+ float phase = Mathf.Repeat(seconds - FighterAttackStartS[fighter], DakotaLoopSeconds);
+ return phase < FighterAttackS ? phase / FighterAttackS : -1f;
+ }
+
+ /// <summary>Fighter <paramref name="fighter"/>'s drawn centre from the Dakotas' loop centre in the air (world x, height, z;
+ /// m) at the lead's loop time <paramref name="seconds"/> (<see cref="FighterAttackStartS"/>): on the lead's track, a
+ /// lag behind or ahead of it, to one side of it, above it. A pure function of the time, closed every loop.</summary>
+ public static Vector3 FighterOffset(int fighter, float seconds)
+ {
+ float phase = Mathf.Repeat(seconds - FighterAttackStartS[fighter], DakotaLoopSeconds);
+ float lag, side, up;
+ if (phase < FighterAttackS)
+ {
+ float p = phase / FighterAttackS, c = Mathf.Cos(Mathf.PI * p);
+ lag = FighterBehindS - (FighterBehindS + FighterAheadS) * Smooth(p);
+ side = FighterPassSideM * Mathf.Sin(Mathf.PI * p);
+ up = FighterPassUpM + (FighterTopM - FighterPassUpM) * c * c;
+ }
+ else
+ {
+ float q = (phase - FighterAttackS) / (DakotaLoopSeconds - FighterAttackS);
+ lag = -FighterAheadS + (FighterBehindS + FighterAheadS) * Smooth(q);
+ side = -FighterOutsideM * Mathf.Sin(Mathf.PI * q);
+ up = FighterTopM;
+ }
+ float track = seconds - lag;
+ var at = DakotaLoopOffset(track); var h = DakotaLoopHeading(track);
+ var inside = new Vector2(-h.y, h.x); // the loop turns left: its inside is to the left of the heading
+ var xz = at + inside * side;
+ return new Vector3(xz.x, up, xz.y);
+ }
+
+ /// <summary>The step (s) of the finite differences that give a fighter's velocity and turn.</summary>
+ internal const float FighterStepS = 0.05f;
+
+ /// <summary>Fighter <paramref name="fighter"/>'s velocity (world, m/s) at <paramref name="seconds"/>: a central difference
+ /// of <see cref="FighterOffset"/>.</summary>
+ public static Vector3 FighterVelocity(int fighter, float seconds) =>
+ (FighterOffset(fighter, seconds + FighterStepS) - FighterOffset(fighter, seconds - FighterStepS)) / (2f * FighterStepS);
+
+ /// <summary>Fighter <paramref name="fighter"/>'s bank (degrees, positive for its left wing down in a left turn, as
+ /// DakotaLoop's): <see cref="BankFor"/> its path's curvature seen from above at the Dakotas' loop scale, as the Dakotas'
+ /// own (<see cref="DakotaBankDegrees"/>), signed by the turn's side.</summary>
+ public static float FighterBankDegrees(int fighter, float seconds)
+ {
+ var a = FighterOffset(fighter, seconds - FighterStepS); var b = FighterOffset(fighter, seconds); var c = FighterOffset(fighter, seconds + FighterStepS);
+ var v = new Vector2(c.x - a.x, c.z - a.z) / (2f * FighterStepS);
+ var acc = new Vector2(c.x - 2f * b.x + a.x, c.z - 2f * b.z + a.z) / (FighterStepS * FighterStepS);
+ float speed = v.magnitude;
+ if (speed < 1f) return 0f;
+ float cross = v.x * acc.y - v.y * acc.x, curvature = cross / (speed * speed * speed);
+ return Mathf.Sign(curvature) * BankFor(DakotaLoopScale * Mathf.Abs(curvature));
+ }
+
+ /// <summary>DESIGN VALUE: the steepest a fighter's nose points down in its dive or up in its pull-out (degrees).</summary>
+ public const float FighterPitchMaxDeg = 20f;
+
+ /// <summary>The falling wing's drawn centre from where it was hit (world x, z; m), its heading's angle (radians from east,
+ /// anticlockwise from above) and its height lost (as a share of the whole drop), <paramref name="s"/> seconds after the
+ /// hit, for a wing that was flying at <paramref name="speed"/> (m/s) on <paramref name="heading0"/> (radians) when hit:
+ /// a left turn of <see cref="WingFallTurnDeg"/> at a speed easing to <see cref="WingFallSpeedShare"/> of it, the height
+ /// lost growing with the square of the time. Its turn radius is its speed over its turn rate.</summary>
+ public static Vector2 WingFall(float s, float speed, float heading0, out float heading, out float dropShare)
+ {
+ float t = Mathf.Clamp(s, 0f, WingFallS), w = WingFallTurnDeg * Mathf.Deg2Rad / WingFallS;
+ // The distance flown with the speed easing linearly to WingFallSpeedShare, expressed as an angle turned: the turn
+ // rate eases with the speed, so the radius stays the speed at the hit over the full turn rate.
+ float k = 1f - WingFallSpeedShare, eased = t - 0.5f * k * t * t / WingFallS;
+ heading = heading0 + w * eased;
+ float r = speed / w;
+ dropShare = (t / WingFallS) * (t / WingFallS);
+ return new Vector2(r * (Mathf.Sin(heading) - Mathf.Sin(heading0)), -r * (Mathf.Cos(heading) - Mathf.Cos(heading0)));
+ }
+
+ /// <summary>The wing's state at its own loop time <paramref name="u"/>: 0 on the loop, 1 falling (its seconds since the
+ /// hit in <paramref name="since"/>), 2 gone (shot down, until the fresh wing joins at <see cref="WingRejoinS"/>).</summary>
+ public static int WingState(float u, out float since)
+ {
+ since = Mathf.Repeat(u - WingHitS, DakotaLoopSeconds);
+ if (since < WingFallS) return 1;
+ return since < WingRejoinS - WingHitS ? 2 : 0;
+ }
+
+ /// <summary>The ground points (world x, z) of the anti-aircraft guns: <see cref="FlakSites"/> spots
+ /// <see cref="FlakSiteM"/> from the middle of Tel Aviv's hex (its first hex), inside its edge.</summary>
+ internal static Vector2[] FlakSitesAt(Vector2 hex)
+ {
+ var sites = new Vector2[FlakSites];
+ for (int i = 0; i < FlakSites; i++)
+ {
+ float a = (90f + 120f * i) * Mathf.Deg2Rad;
+ sites[i] = hex + new Vector2(Mathf.Cos(a), Mathf.Sin(a)) * FlakSiteM;
+ }
+ return sites;
+ }
+
+ /// <summary>The air defence's director, or null when it is not drawn (a test aid).</summary>
+ public TelAvivAirDefence? AirDefence { get; private set; }
+
+ /// <summary>On the second bombing period's turns, once both Dakotas are drawn: the air defence beside them
+ /// (<see cref="TelAvivAirDefence"/>), with the two S-199s built from the map's own model (UnitModels.AviaS199, its
+ /// propeller UnitModels.S199Propeller) at the unit tokens' aircraft scale, each with its propeller, its shadow and
+ /// Israel's flag over its tail, as the Dakotas carry Egypt's. It is one of the Dakotas' originals, so it goes when they
+ /// go. The labels keep clear of each fighter where it is now, a <see cref="DakotaKeepStepS"/> step at a time
+ /// (<see cref="FollowAirDefence"/>).</summary>
+ void FlyAirDefence(KitGround ground)
+ {
+ AirDefence = null; airDefenceKeeps.Clear();
+ if (!AirDefenceWanted(date) || map == null || content == null) return;
+ var lead = transform.Find(DakotaKeys[0]); var wing = transform.Find(DakotaKeys[1]);
+ var leadLoop = lead != null ? lead.GetComponent<DakotaLoop>() : null; var wingLoop = wing != null ? wing.GetComponent<DakotaLoop>() : null;
+ if (leadLoop == null || wingLoop == null || DakotaCentre() is not Vector2 c) return;
+ var targets = DakotaTargets(ground, content);
+ if (targets.Count == 0) return;
+ float size = SizeOf(Dakota);
+ var centre = new Vector3(c.x, UnitShowcase.LoopFloor(map, new Vector3(c.x, 0f, c.y), DakotaLoopHalfLengthM + size) + UnitShowcase.AltitudeM, c.y);
+
+ var go = new GameObject(AirDefenceKey);
+ go.transform.SetParent(transform, false);
+ originals[Dakota].Add(go);
+ var owned = go.AddComponent<MapRuntimeAssets>();
+ var template = Resources.Load<Material>(UnitMaterials.MiniatureResource);
+ if (template == null) { Debug.LogWarning("SEA/AIR: the unit materials are missing (run UnitMaterialAssets.Create); the S-199s are not drawn."); return; }
+ if (fighterPaint == null)
+ {
+ fighterPaint = Own(new Material(template) { name = "UnitMiniature (palette, S-199)" });
+ fighterPaint.SetTexture("_BaseMap", Own(UnitPalette.MakeTexture(readable: false)));
+ }
+ if (s199Mesh == null) s199Mesh = UnitPlinth.Upload(Own(UnitModels.AviaS199("S199-1948-air-defence")));
+ if (s199PropMesh == null) s199PropMesh = UnitPlinth.Upload(Own(UnitModels.S199Propeller("S199-propeller-air-defence")));
+
+ var fighters = new TelAvivAirDefence.Fighter[FighterKeys.Length];
+ for (int i = 0; i < FighterKeys.Length; i++)
+ {
+ var plane = UnitShowcase.Piece(go.transform, FighterKeys[i], s199Mesh, fighterPaint, centre, Quaternion.identity, UnitShowcase.AircraftScale);
+ plane.GetComponent<MeshRenderer>().shadowCastingMode = ShadowCastingMode.On;
+ var prop = UnitShowcase.Piece(plane.transform, "Propeller", s199PropMesh, fighterPaint, Vector3.zero, Quaternion.identity, 1f);
+ prop.transform.localPosition = UnitModels.S199PropellerHub;
+ var b = Bounds(plane); // nose north (+z) at identity: its length along z, its span along x
+ var half = 0.5f * new Vector3(b.size.z, b.size.y, b.size.x); // half its length, height and span, as DakotaLoop's
+ var marks = new GameObject(FighterKeys[i] + DakotaMarksSuffix);
+ marks.transform.SetParent(go.transform, false);
+ var flag = FighterFlag(marks.transform);
+ fighters[i] = new TelAvivAirDefence.Fighter(plane.transform, prop.transform, Shadow(marks.transform), flag, half,
+ 0.5f * ShadowShare * new Vector2(b.size.x, b.size.z));
+ }
+
+ var looks = AirDefenceLooks();
+ var defence = go.AddComponent<TelAvivAirDefence>();
+ var wingShadow = transform.Find(DakotaKeys[1] + DakotaMarksSuffix)?.Find(DakotaShadowName);
+ // The Dakota's length over its span, off its mesh (its -y the nose, x across), for where the hits and the trail sit.
+ var dm = wing!.GetComponentInChildren<MeshFilter>();
+ float lengthShare = dm != null && dm.sharedMesh != null && dm.sharedMesh.bounds.size.x > 1e-3f ? dm.sharedMesh.bounds.size.y / dm.sharedMesh.bounds.size.x : 0.667f;
+ defence.Configure(centre, fighters, leadLoop, wingLoop, wingShadow, FlakSitesAt(targets[0]), ground, map.Terrain, looks,
+ !Application.isPlaying || VisualShots.Requested(), lengthShare);
+ AirDefence = defence;
+ var cam = Camera.main;
+ if (cam != null) foreach (var f in fighters) if (f.Flag != null) UnitFlagFacing.Face(f.Flag, cam.transform.position);
+
+ // The labels keep clear of each fighter where it is now, as of the Dakotas (owner, 4 November 2026, on #2490: "Shrink
+ // the keep-clear area (Recommended)").
+ for (int i = 0; i < fighters.Length; i++)
+ {
+ var f = fighters[i];
+ float reach = FighterReach(f.Plane, f.Prop) + 1f, up = reach;
+ if (f.Flag != null)
+ {
+ var fb = f.Flag.GetComponent<MeshFilter>().sharedMesh.bounds; float k = f.Flag.lossyScale.y;
+ up = Mathf.Max(up, f.Half.magnitude + DakotaLoop.FlagClearM + 2f * fb.extents.y * k + 1f);
+ }
+ var keep = new FighterKeep(f.Plane.gameObject, defence, i, centre, reach, up);
+ keep.Step = DakotaKeepStep(defence.PlacedAt);
+ airDefenceKeeps.Add(keep);
+ Keep(f.Plane.gameObject, FighterKeepBox(i, centre, keep.Step, reach, up));
+ }
+ }
+
+ Material? fighterPaint; Mesh? s199Mesh, s199PropMesh;
+
+ /// <summary>The farthest any part of a fighter can be from its pivot (world m), at any attitude and any turn of its
+ /// propeller: the airframe mesh's farthest bounds corner from its origin (the centre of gravity, UnitModels.AviaS199),
+ /// and the propeller hub's distance plus the propeller mesh's farthest corner from its own origin (it turns about it),
+ /// times the aircraft's scale. The fighter turns about its pivot, not about its bounds' centre, which lies about a metre
+ /// of the model aft of it (the tail is longer than the nose), so half the bounds' diagonal fell short at some attitudes.</summary>
+ internal static float FighterReach(Transform plane, Transform prop)
+ {
+ static float Far(Bounds b) => new Vector3(Mathf.Abs(b.center.x) + b.extents.x, Mathf.Abs(b.center.y) + b.extents.y, Mathf.Abs(b.center.z) + b.extents.z).magnitude;
+ static float Largest(Vector3 v) => Mathf.Max(Mathf.Abs(v.x), Mathf.Max(Mathf.Abs(v.y), Mathf.Abs(v.z)));
+ float airframe = Far(plane.GetComponent<MeshFilter>().sharedMesh.bounds) * Largest(plane.lossyScale);
+ float blades = Far(prop.GetComponent<MeshFilter>().sharedMesh.bounds) * Largest(prop.lossyScale);
+ float hub = Vector3.Scale(prop.localPosition, plane.lossyScale).magnitude;
+ return Mathf.Max(airframe, hub + blades);
+ }
+
+ /// <summary>The box (world) the names keep clear of for fighter <paramref name="fighter"/> through the clock step
+ /// <paramref name="step"/> (<see cref="DakotaKeepStepS"/>): its path in that step, sampled, with <paramref name="reach"/>
+ /// round it and <paramref name="up"/> above it (its flag), as <see cref="DakotaKeepBox"/>.</summary>
+ internal static Bounds FighterKeepBox(int fighter, Vector3 centre, long step, float reach, float up)
+ {
+ const int Samples = 8; const float Pad = 10f;
+ var box = new Bounds();
+ for (int i = 0; i <= Samples; i++)
+ {
+ var at = centre + FighterOffset(fighter, (float)(step * (double)DakotaKeepStepS + i * (double)DakotaKeepStepS / Samples));
+ var b = new Bounds(); b.SetMinMax(at - new Vector3(reach, reach, reach), at + new Vector3(reach, up, reach));
+ if (i == 0) box = b; else box.Encapsulate(b);
+ }
+ box.Expand(2f * Pad);
+ return box;
+ }
+
+ sealed class FighterKeep
+ {
+ public readonly GameObject Go; public readonly TelAvivAirDefence Defence; public readonly int Fighter; public readonly Vector3 Centre; public readonly float Reach, Up;
+ public long Step;
+ public FighterKeep(GameObject go, TelAvivAirDefence defence, int fighter, Vector3 centre, float reach, float up)
+ { Go = go; Defence = defence; Fighter = fighter; Centre = centre; Reach = reach; Up = up; }
+ }
+ readonly List<FighterKeep> airDefenceKeeps = new List<FighterKeep>();
+
+ /// <summary>Moves each fighter's keep-clear box to the clock step where the air defence last placed it, as
+ /// FollowDakotas does the Dakotas'. Cheap: a comparison a fighter a call, and a box and a list once a step.</summary>
+ void FollowAirDefence()
+ {
+ bool moved = false;
+ for (int i = 0; i < airDefenceKeeps.Count; i++)
+ {
+ var d = airDefenceKeeps[i];
+ if (d.Go == null || d.Defence == null || !keepOf.ContainsKey(d.Go)) continue;
+ long step = DakotaKeepStep(d.Defence.PlacedAt);
+ if (step == d.Step) continue;
+ d.Step = step;
+ keepOf[d.Go] = new[] { FighterKeepBox(d.Fighter, d.Centre, step, d.Reach, d.Up) };
+ moved = true;
+ }
+ if (moved) RebuildKeepAll();
+ }
+
+ /// <summary>The textures the air defence draws with: the gun's flash (made once for the layer, as the bombs'), and the
+ /// bombs' two Unity Labs flipbooks (the blast and the smoke), or the drawn flash and puff when they are missing.</summary>
+ TelAvivAirDefence.Looks AirDefenceLooks()
+ {
+ if (flashTexture == null) flashTexture = Own(UnitGunFire.FlashTexture());
+ if (puffTexture == null) puffTexture = Own(Statecraft.HexTiles.HexUnderAttackLook.PuffTexture());
+ var blast = Resources.Load<Texture2D>(DakotaBlastTexture); var smoke = Resources.Load<Texture2D>(DakotaSmokeTexture);
+ return new TelAvivAirDefence.Looks(flashTexture, blast != null ? blast : flashTexture, blast != null ? DakotaBlastGrid : 1,
+ smoke != null ? smoke : puffTexture, smoke != null ? DakotaSmokeGrid : 1);
+ }
+
+ /// <summary>Israel's flag over a fighter's tail, as Egypt's floats over each Dakota's (<see cref="DakotaFlag"/>; owner on
+ /// #2260, "Smaller flag, no pole"): the cloth alone (UnitFlags.BuildCloth), the flag the map's Israeli tokens fly
+ /// (UnitFlags, UnitData.Israel), at <see cref="DakotaFlagScale"/> of the tokens' size, turned to the camera. Null, with a
+ /// warning, when the units' materials are missing.</summary>
+ static Transform? FighterFlag(Transform parent)
+ {
+ var ring = Resources.Load<Material>(UnitMaterials.RingResource);
+ if (ring == null)
+ {
+ Debug.LogWarning("SEA/AIR: the unit materials are missing (run UnitMaterialAssets.Create); the S-199 flies without its flag.");
+ return null;
+ }
+ var go = new GameObject(DakotaFlagName);
+ go.transform.SetParent(parent, false);
+ go.transform.localScale = Vector3.one * (DakotaFlagScale * UnitBadge.FigureHeightM * UnitShowcase.FigureScale);
+ var owned = go.AddComponent<MapRuntimeAssets>();
+ go.AddComponent<MeshFilter>().sharedMesh = UnitPlinth.Upload(owned.Own(UnitFlags.BuildCloth(UnitData.Israel)!));
+ var r = go.AddComponent<MeshRenderer>();
+ r.sharedMaterials = UnitFlags.ClothMaterials(UnitData.Israel, ring, m => owned.Own(m));
+ r.shadowCastingMode = ShadowCastingMode.Off;
+ go.AddComponent<UnitFlagFacing>();
+ return go.transform;
+ }
+ }
+}
diff --git a/unity/Assets/Scripts/Map/Collection/SeaAirCollection.AirDefence.cs.meta b/unity/Assets/Scripts/Map/Collection/SeaAirCollection.AirDefence.cs.meta
new file mode 100644
index 000000000..8f9f36854
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Collection/SeaAirCollection.AirDefence.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: e3514372616b41b992f546f0a085a839
diff --git a/unity/Assets/Scripts/Map/Collection/SeaAirCollection.Dakota.cs b/unity/Assets/Scripts/Map/Collection/SeaAirCollection.Dakota.cs
index d18d21f5f..9fab00e1f 100644
--- a/unity/Assets/Scripts/Map/Collection/SeaAirCollection.Dakota.cs
+++ b/unity/Assets/Scripts/Map/Collection/SeaAirCollection.Dakota.cs
@@ -40,9 +40,22 @@ namespace Statecraft.Game.Map.Collection
/// הפצצות המצריות בכיכר מסריק" and Modi Alon shot down "שני מטוסי דקוטה מצרים ששימשו כמפציצים". he.wiki "מודי אלון",
/// revision 43744773, calls them "זוג מטוסי DC-3 דקוטה מצריים"; en.wiki "Modi Alon", revision 1375428559, "a pair of
/// Egyptian C-47s and their two Spitfire escorts" (all agent-read 4 November 2026). On the game's monthly turns (the
- /// 15th) the Dakotas show on the 15 May 1948 turn only.</summary>
+ /// 15th) the Dakotas show on the 15 May 1948 turn only in this period (and again in the second, DakotaSecondFrom).</summary>
public static readonly DateTime DakotaFrom = new DateTime(1948, 5, 15), DakotaTo = new DateTime(1948, 6, 11);
+ /// <summary>The second Egyptian bombing period over Tel Aviv, the Ten Days, 8 to 17 July 1948: the same he.wiki article and
+ /// revision, section "תקופת ההפצצות השנייה": "תקופת ההפצצות השנייה על תל אביב התרחשה במהלך קרבות עשרת הימים (8 עד 17
+ /// ביולי)" and "ב-17 ביולי הופצצה תל אביב בפעם האחרונה". That the bombers were Dakotas this time: en.wiki "1948
+ /// Arab–Israeli War", revision 1375001749, section on the Ten Days, citing Morris 2008, pp. 294-295: "The Egyptians
+ /// responded with raids on Tel Aviv by Dakota aircraft accompanied by a Spitfire fighter escort"; he.wiki's 13 July
+ /// paragraph has "שני מפציצים ושני מטוסי קרב מצרים", the type not named (all agent-read 5 November 2026, a person's
+ /// check pending; research_notes/GDD phase 7/tel-aviv-bombing-july-1948.md). On the game's monthly turns the Dakotas
+ /// show again on the 15 July 1948 turn, as on 15 May, with Tel Aviv's air defence (SeaAirCollection.AirDefence.cs).</summary>
+ public static readonly DateTime DakotaSecondFrom = new DateTime(1948, 7, 8), DakotaSecondTo = new DateTime(1948, 7, 17);
+
+ /// <summary>True in either bombing period (<see cref="DakotaFrom"/>, <see cref="DakotaSecondFrom"/>).</summary>
+ public static bool DakotaWanted(DateTime date) => (date >= DakotaFrom && date <= DakotaTo) || (date >= DakotaSecondFrom && date <= DakotaSecondTo);
+
/// <summary>The C-47's wingspan, 95 ft 6 in (29.11 m): en.wiki "Douglas C-47 Skytrain", Specifications (C-47B-DK),
/// revision 1383378030, agent-read 2 November 2026. At the unit tokens' aircraft scale (420x, as the Spitfire, #2014)
/// it is 12.2 km across; each of the two is drawn at <see cref="DakotaScale"/> of that.</summary>
diff --git a/unity/Assets/Scripts/Map/Collection/SeaAirCollection.cs b/unity/Assets/Scripts/Map/Collection/SeaAirCollection.cs
index 8fd690e35..4ecd8b9ab 100644
--- a/unity/Assets/Scripts/Map/Collection/SeaAirCollection.cs
+++ b/unity/Assets/Scripts/Map/Collection/SeaAirCollection.cs
@@ -25,7 +25,10 @@ namespace Statecraft.Game.Map.Collection
/// <item>two Egyptian Dakotas, a pair on one loop over Tel Aviv, bombing the city (<see cref="DakotaLoop"/>; owner, 4
/// November 2026, #2482: "1 + make the visual 2 slightly smaller planes and not 0ne big one"), banked into their turns,
/// their propellers turning, their shadows on the ground and Egypt's flag over each tail, on the turns of the first
- /// bombing period, 15 May to 11 June 1948 (<see cref="DakotaFrom"/>, <see cref="DakotaTo"/>; SeaAirCollection.Dakota.cs).</item>
+ /// bombing period, 15 May to 11 June 1948 (<see cref="DakotaFrom"/>, <see cref="DakotaTo"/>; SeaAirCollection.Dakota.cs), and
+ /// of the second, 8 to 17 July 1948 (<see cref="DakotaSecondFrom"/>), when Tel Aviv's air defence flies against them: two
+ /// of 101 Squadron's Avia S-199s attack the lead, hitting it but never bringing it down, and anti-aircraft fire brings
+ /// the wing down (<see cref="TelAvivAirDefence"/>; SeaAirCollection.AirDefence.cs).</item>
/// </list>
/// The boats lie on the open sea past the surf, where SeaCraft's own boats sail (SeaCraft.OffshoreNearM to OffshoreM out
/// from the same shore points), each hull clear of the harbour works, of SeaCraft's boats and of each other
@@ -129,7 +132,7 @@ namespace Statecraft.Game.Map.Collection
wants.Add(new Want("tel-aviv-altalena", Altalena, "tel_aviv"));
if (date >= C54From && date <= C54To) wants.Add(new Want("lod-c54", C54, "lod"));
if (date >= SpitfireFrom && date <= SpitfireTo) wants.Add(new Want("el-arish-spitfire", Spitfire, "el_arish"));
- if (date >= DakotaFrom && date <= DakotaTo) foreach (var key in DakotaKeys) wants.Add(new Want(key, Dakota, DakotaTown));
+ if (DakotaWanted(date)) foreach (var key in DakotaKeys) wants.Add(new Want(key, Dakota, DakotaTown));
return wants;
}
@@ -344,7 +347,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[]>(); keepOf.Clear(); dakotaKeeps.Clear();
+ Placed.Clear(); Missing.Clear(); keepAll = new List<Bounds[]>(); keepOf.Clear(); dakotaKeeps.Clear(); airDefenceKeeps.Clear(); AirDefence = null;
originals.Clear();
if (map != null) Statecraft.Game.Map.Units.UnitShowcase.HideTrees(map, Name, Array.Empty<(Vector2, float)>());
}
@@ -373,6 +376,7 @@ namespace Statecraft.Game.Map.Collection
List<(Vector2 centre, float radius)> taken = new List<(Vector2, float)>();
List<WildlifeLayer.Want>? wildlife;
DateTime date;
+ bool airDefenceShown; // AirDefenceWanted at the last rebuild: 15 May and 15 July want the same craft, so the date alone must rebuild (#2649)
/// <summary>The craft drawn (key, model, spot at the water's or ground's height; the centre of the Spitfire's loop, in the air): a test aid.</summary>
public readonly List<(string Key, string Model, Vector3 At)> Placed = new List<(string, string, Vector3)>();
@@ -389,12 +393,20 @@ namespace Statecraft.Game.Map.Collection
{
if (!isActiveAndEnabled) return Array.Empty<Bounds[]>();
FollowDakotas();
+ FollowAirDefence();
return keepAll;
}
}
- /// <summary>A new <see cref="KeepClear"/> list from every drawn craft's own boxes.</summary>
- void RebuildKeepAll() =>
- keepAll = originals.Values.SelectMany(list => list).Where(go => go != null && keepOf.ContainsKey(go)).Select(go => keepOf[go]).ToList();
+ /// <summary>A new <see cref="KeepClear"/> list from every drawn craft's own boxes, and the air defence's fighters' (keyed
+ /// by each fighter's plane, a child of the air defence, which is one of the Dakotas' originals: kept while it is).</summary>
+ void RebuildKeepAll()
+ {
+ var drawn = originals.Values.SelectMany(list => list).Where(go => go != null).ToList();
+ keepAll = drawn.Where(keepOf.ContainsKey).Select(go => keepOf[go])
+ .Concat(airDefenceKeeps.Where(k => k.Go != null && k.Defence != null && keepOf.ContainsKey(k.Go) && drawn.Contains(k.Defence.gameObject))
+ .Select(k => keepOf[k.Go]))
+ .ToList();
+ }
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; }
@@ -419,8 +431,9 @@ namespace Statecraft.Game.Map.Collection
{
date = at;
var others = next.Any(w => w.Model == C54) ? Taken() : new List<(Vector2, float)>();
- if (next.SequenceEqual(wants) && placed.SequenceEqual(placements) && others.SequenceEqual(taken)) return;
- wants = next; placements = placed; taken = others;
+ bool defence = AirDefenceWanted(at);
+ if (next.SequenceEqual(wants) && placed.SequenceEqual(placements) && others.SequenceEqual(taken) && defence == airDefenceShown) return;
+ wants = next; placements = placed; taken = others; airDefenceShown = defence;
OriginalModelRequests.WhenVisible(this, () => RefreshResidency());
}
@@ -471,6 +484,7 @@ namespace Statecraft.Game.Map.Collection
Placed.Add((w.Key, w.Model, pos));
Keep(go, Bounds(go));
}
+ FlyAirDefence(ground); // the S-199s and the anti-aircraft fire beside the Dakotas, on the second period's turns
// 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();
Statecraft.Game.Map.Units.UnitShowcase.HideTrees(map, Name, plane);
diff --git a/unity/Assets/Scripts/Map/Collection/TelAvivAirDefence.cs b/unity/Assets/Scripts/Map/Collection/TelAvivAirDefence.cs
new file mode 100644
index 000000000..cccb6add8
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Collection/TelAvivAirDefence.cs
@@ -0,0 +1,435 @@
+#nullable enable
+using System;
+using Statecraft.Game.Map.Kits;
+using Statecraft.Game.Map.Units;
+using Statecraft.HexTiles;
+using UnityEngine;
+using UnityEngine.Rendering;
+
+namespace Statecraft.Game.Map.Collection
+{
+ /// <summary>Draws Tel Aviv's air defence on the second bombing period's turns (SeaAirCollection.AirDefence.cs; owner, "do
+ /// 1+2"): (1) two of 101 Squadron's Avia S-199s, each diving on the lead Dakota once a loop, firing (the gun's flash and
+ /// a tracer) and hitting it (puffs of smoke left where it was struck), then pulling away, never bringing it down: an
+ /// illustration, as no source read shows a July interception over Tel Aviv; and (2) the anti-aircraft fire of 17 July
+ /// 1948 (JTA 19 July 1948): flashes from gun sites on Tel Aviv's hex, flak bursting round the wing Dakota after its bombs,
+ /// the last burst on it; it trails smoke, falls out of the loop and is gone in a blast on the ground; a fresh wing joins
+ /// the loop out over the sea before the next pass (SeaAirCollection.WingRejoinS), so one loop is one raid.
+ ///
+ /// Everything is a pure function of the Dakotas' loop clock (SpitfireLoop.Clock, the lead's time; the wing's is
+ /// SeaAirCollection.DakotaTrailSeconds behind), so a held shot repeats exactly. It runs after the Dakotas' own loops
+ /// (DefaultExecutionOrder), and while the wing falls it moves the wing (and its flag and shadow) off the loop where
+ /// DakotaLoop put it; DakotaLoop itself is unchanged. All the effects are camera-facing quads made once, hidden until used,
+ /// their materials and frame meshes owned by this object; placing a frame allocates nothing. Editor renders and
+ /// screenshots hold the loop's start, as the Dakotas do. Presentation only: no sim, content or hash change.</summary>
+ [DefaultExecutionOrder(100)]
+ public sealed class TelAvivAirDefence : MonoBehaviour
+ {
+ /// <summary>One S-199: its airframe (nose +z, at the tokens' aircraft scale), its propeller (turns about its +z), its
+ /// shadow and flag (beside it), half its length, height and span, and its shadow's half size across and along.</summary>
+ internal sealed class Fighter
+ {
+ public readonly Transform Plane, Prop; public readonly Transform? Shadow, Flag; public readonly Vector3 Half; public readonly Vector2 ShadowHalf;
+ /// <summary>Half the flag's height (m), or 0.</summary>
+ public readonly float FlagHalf;
+ public Fighter(Transform plane, Transform prop, Transform? shadow, Transform? flag, Vector3 half, Vector2 shadowHalf)
+ {
+ Plane = plane; Prop = prop; Shadow = shadow; Flag = flag; Half = half; ShadowHalf = shadowHalf;
+ FlagHalf = flag != null ? flag.GetComponent<MeshFilter>().sharedMesh.bounds.extents.y * flag.localScale.y : 0f;
+ }
+ }
+
+ /// <summary>The textures: the gun's flash, the blast flipbook and the smoke flipbook (grids of frames each way; 1 for a
+ /// single picture).</summary>
+ internal readonly struct Looks
+ {
+ public readonly Texture2D Flash, Blast, Smoke; public readonly int BlastGrid, SmokeGrid;
+ public Looks(Texture2D flash, Texture2D blast, int blastGrid, Texture2D smoke, int smokeGrid)
+ { Flash = flash; Blast = blast; BlastGrid = blastGrid; Smoke = smoke; SmokeGrid = smokeGrid; }
+ }
+
+ static readonly int BaseColor = Shader.PropertyToID("_BaseColor"), BaseMap = Shader.PropertyToID("_BaseMap"), Cull = Shader.PropertyToID("_Cull");
+ /// <summary>DESIGN VALUES: the gun's and the guns' flashes the muzzle flash's colour (UnitGunFire); the tracer a hot
+ /// orange; the hits' and the trail's smoke dark grey, as burning oil; the flak's bursts near black, as flak's
+ /// smoke reads in photographs, thinning paler.</summary>
+ static readonly Color FlashColour = new Color(1f, 0.85f, 0.5f), TracerColour = new Color(1f, 0.7f, 0.3f);
+ static readonly Color HitSmoke = new Color(0.36f, 0.33f, 0.30f), TrailSmoke = new Color(0.30f, 0.28f, 0.26f), FlakSmoke = new Color(0.16f, 0.15f, 0.14f), SmokeThin = new Color(0.7f, 0.68f, 0.65f);
+ /// <summary>DESIGN VALUES: where on the lead the hits land, as shares of its half length (forward), of a fifth of its span
+ /// (up from its centre) and of its half span (to its right), one a hit.</summary>
+ static readonly Vector3[] HitSpot = { new Vector3(0.10f, 0.25f, 0.30f), new Vector3(-0.15f, -0.35f, 0.25f), new Vector3(0.25f, 0.05f, 0.35f), new Vector3(-0.30f, 0.45f, 0.30f) };
+ /// <summary>DESIGN VALUE: a C-47's length over its span, read off the Dakota mesh's bounds when drawn
+ /// (SeaAirCollection.FlyAirDefence passes it); this is the fallback.</summary>
+ float dakotaLengthShare = 0.667f;
+
+ Vector3 centre; bool still; Fighter[] fighters = Array.Empty<Fighter>();
+ DakotaLoop? lead, wing; Transform? wingFlag, wingShadow; Renderer[] wingRenderers = Array.Empty<Renderer>(); Renderer? wingFlagR, wingShadowR;
+ Quaternion wingLevel = Quaternion.identity; Vector3 wingOffset; float wingFlagUp; Vector2 wingShadowHalf;
+ Vector3 wingHitAt; float wingHitHeading, wingHitSpeed, wingDrop; Vector3 crashAt; bool wingShown = true;
+ Terrain? terrain; float seaY;
+ Vector2[] sites = Array.Empty<Vector2>(); Vector3[] siteAt = Array.Empty<Vector3>(); Vector3[] burstAt = Array.Empty<Vector3>();
+ Mesh[] blastFrames = Array.Empty<Mesh>(), smokeFrames = Array.Empty<Mesh>();
+ Quaternion view = Quaternion.identity;
+
+ // The pools: per fighter its tracers, its muzzle flash, its hits (a flash and a puff each); per burst a gun flash on
+ // the ground, a flash and a puff in the air; the falling wing's trail and its blast on the ground.
+ Part[] tracer = Array.Empty<Part>(), muzzle = Array.Empty<Part>(), hitFlash = Array.Empty<Part>(), hitPuff = Array.Empty<Part>();
+ Part[] gunFlash = Array.Empty<Part>(), burstFlash = Array.Empty<Part>(), burstPuff = Array.Empty<Part>(), trail = Array.Empty<Part>();
+ Part crash;
+
+ /// <summary>One pooled quad: its transform, renderer, frame filter and own material.</summary>
+ internal struct Part
+ {
+ public Transform T; public Renderer R; public MeshFilter F; public Material M;
+ }
+
+ /// <summary>The loop clock's seconds where <see cref="Place"/> last put it (the fighters' keep-clear boxes follow it).</summary>
+ public float PlacedAt { get; private set; }
+ /// <summary>True when everything holds the loop's start (edit mode, screenshots).</summary>
+ public bool Still => still;
+ /// <summary>The fighters' airframes (tests).</summary>
+ public Transform[] FighterPlanes { get; private set; } = Array.Empty<Transform>();
+ /// <summary>The pools' renderers (tests).</summary>
+ internal Renderer[] TracerRenderers => Renderers(tracer);
+ internal Renderer[] HitRenderers => Renderers(hitPuff);
+ internal Renderer[] FlakRenderers => Renderers(burstPuff);
+ internal Renderer[] TrailRenderers => Renderers(trail);
+ internal Renderer CrashRenderer => crash.R;
+ /// <summary>The falling wing's drawn centre where <see cref="Place"/> last put it while it fell (tests).</summary>
+ internal Vector3 WingAt { get; private set; }
+ /// <summary>True while the wing Dakota is drawn (on the loop or falling), false once shot down until the fresh wing joins.</summary>
+ public bool WingShown => wingShown;
+ static Renderer[] Renderers(Part[] parts) { var r = new Renderer[parts.Length]; for (int i = 0; i < parts.Length; i++) r[i] = parts[i].R; return r; }
+
+ /// <summary><paramref name="centre"/>: the Dakotas' loop centre in the air. The fighters, the two Dakotas' loops, the
+ /// wing's shadow (beside it, DakotaLoop lays it), the anti-aircraft gun sites (world x, z, on Tel Aviv's hex), the
+ /// ground, the terrain and the looks. <paramref name="lengthShare"/>: the Dakota's length over its span.</summary>
+ internal void Configure(Vector3 centre, Fighter[] fighters, DakotaLoop lead, DakotaLoop wing, Transform? wingShadow, Vector2[] sites,
+ KitGround ground, Terrain? terrain, Looks looks, bool still, float lengthShare = 0.667f)
+ {
+ this.centre = centre; this.fighters = fighters; this.lead = lead; this.wing = wing; this.wingShadow = wingShadow; this.sites = sites;
+ this.terrain = terrain; seaY = ground.SeaLevelY; this.still = still; dakotaLengthShare = lengthShare;
+ FighterPlanes = new Transform[fighters.Length];
+ for (int i = 0; i < fighters.Length; i++) FighterPlanes[i] = fighters[i].Plane;
+ wingFlag = wing.Flag; wingFlagR = wingFlag != null ? wingFlag.GetComponent<Renderer>() : null; wingShadowR = wingShadow != null ? wingShadow.GetComponent<Renderer>() : null;
+ wingRenderers = wing.GetComponentsInChildren<Renderer>(true);
+
+ // The wing's model rotation and drawn-centre offset, read back from where its loop placed it (DakotaLoop.Place: the
+ // rotation is the loop's turn times the model's level rotation; the position its drawn centre less the turn of
+ // the offset), so the fall below draws it exactly as its loop does.
+ float u0 = wing.PlacedAt - wing.Lag;
+ var turn0 = LoopTurn(u0);
+ wingLevel = Quaternion.Inverse(turn0) * wing.transform.localRotation;
+ var drawn0 = centre + Flat(SeaAirCollection.DakotaLoopOffset(u0));
+ wingOffset = Quaternion.Inverse(turn0) * (drawn0 - wing.transform.position);
+ wingFlagUp = wingFlag != null ? wingFlag.position.y - drawn0.y : 0f;
+ float span = SeaAirCollection.SizeOf(SeaAirCollection.Dakota);
+ wingShadowHalf = 0.5f * SeaAirCollection.ShadowShare * new Vector2(span, span * dakotaLengthShare);
+
+ // Where it is hit, and its fall: from the loop at WingHitS, at its speed and heading there, down to the highest
+ // ground under its path (so it never flies into a hill before its end), its blast on the ground under its end.
+ var h = SeaAirCollection.DakotaLoopHeading(SeaAirCollection.WingHitS);
+ wingHitAt = centre + Flat(SeaAirCollection.DakotaLoopOffset(SeaAirCollection.WingHitS));
+ wingHitHeading = Mathf.Atan2(h.y, h.x);
+ wingHitSpeed = (SeaAirCollection.DakotaLoopOffset(SeaAirCollection.WingHitS + 0.05f) - SeaAirCollection.DakotaLoopOffset(SeaAirCollection.WingHitS - 0.05f)).magnitude / 0.1f;
+ float floor = float.NegativeInfinity;
+ for (int i = 0; i <= 16; i++)
+ {
+ var p = SeaAirCollection.WingFall(i * SeaAirCollection.WingFallS / 16f, wingHitSpeed, wingHitHeading, out _, out _);
+ floor = Mathf.Max(floor, ground.Y(wingHitAt.x + p.x, wingHitAt.z + p.y));
+ }
+ // Its centre comes down to WingFallEndShare of its span over that ground: it levels its wings as it goes in
+ // (FallPoint), so at the end only its nose, pitched down, reaches the ground, where the blast goes up.
+ float clear = SeaAirCollection.WingFallEndShare * span;
+ wingDrop = Mathf.Max(0f, centre.y - (floor + clear));
+ var end = SeaAirCollection.WingFall(SeaAirCollection.WingFallS, wingHitSpeed, wingHitHeading, out _, out _);
+ crashAt = new Vector3(wingHitAt.x + end.x, ground.Y(wingHitAt.x + end.x, wingHitAt.z + end.y), wingHitAt.z + end.y);
+
+ // The guns on the ground and the bursts in the air (each at a set miss from the wing where it is then, on its loop).
+ siteAt = new Vector3[sites.Length];
+ for (int i = 0; i < sites.Length; i++) siteAt[i] = new Vector3(sites[i].x, ground.Y(sites[i].x, sites[i].y), sites[i].y);
+ burstAt = new Vector3[SeaAirCollection.FlakAtS.Length];
+ for (int i = 0; i < burstAt.Length; i++) burstAt[i] = centre + Flat(SeaAirCollection.DakotaLoopOffset(SeaAirCollection.FlakAtS[i])) + SeaAirCollection.FlakMissM[i];
+
+ Build(looks);
+ var cam = Camera.main;
+ if (cam != null) view = cam.transform.rotation;
+ Place(still ? 0f : SpitfireLoop.Clock());
+ }
+
+ void Build(Looks looks)
+ {
+ var owned = GetComponent<MapRuntimeAssets>(); // not ??: a missing component is Unity's fake null in the editor
+ if (owned == null) owned = gameObject.AddComponent<MapRuntimeAssets>();
+ var quad = Resources.GetBuiltinResource<Mesh>("Quad.fbx");
+ blastFrames = DakotaBombRun.Frames(owned, looks.BlastGrid); smokeFrames = DakotaBombRun.Frames(owned, looks.SmokeGrid);
+ Part Make(string name, Mesh mesh, string template, Texture2D texture)
+ {
+ var go = new GameObject(name, typeof(MeshFilter), typeof(MeshRenderer));
+ go.transform.SetParent(transform, false);
+ var f = go.GetComponent<MeshFilter>(); f.sharedMesh = mesh;
+ var r = go.GetComponent<MeshRenderer>();
+ var m = owned.Own(HexMaterials.New(template)); m.SetTexture(BaseMap, texture); m.SetFloat(Cull, (float)CullMode.Off);
+ r.sharedMaterial = m; r.enabled = false;
+ r.shadowCastingMode = ShadowCastingMode.Off; r.receiveShadows = false;
+ r.lightProbeUsage = LightProbeUsage.Off; r.reflectionProbeUsage = ReflectionProbeUsage.Off;
+ return new Part { T = go.transform, R = r, F = f, M = m };
+ }
+ int n = fighters.Length;
+ tracer = new Part[n * SeaAirCollection.FighterTracers]; muzzle = new Part[n];
+ hitFlash = new Part[n * SeaAirCollection.FighterHits]; hitPuff = new Part[n * SeaAirCollection.FighterHits];
+ for (int i = 0; i < tracer.Length; i++) tracer[i] = Make("Tracer", quad, HexMaterials.AttackGlow, looks.Flash);
+ for (int i = 0; i < n; i++) muzzle[i] = Make("GunFlash", quad, HexMaterials.AttackGlow, looks.Flash);
+ for (int i = 0; i < hitPuff.Length; i++)
+ {
+ hitFlash[i] = Make("HitFlash", quad, HexMaterials.AttackGlow, looks.Flash);
+ hitPuff[i] = Make("HitSmoke", smokeFrames[0], HexMaterials.AttackSmoke, looks.Smoke);
+ }
+ int bursts = SeaAirCollection.FlakAtS.Length;
+ gunFlash = new Part[bursts]; burstFlash = new Part[bursts]; burstPuff = new Part[bursts];
+ for (int i = 0; i < bursts; i++)
+ {
+ gunFlash[i] = Make("FlakGunFlash", quad, HexMaterials.AttackGlow, looks.Flash);
+ burstFlash[i] = Make("FlakFlash", quad, HexMaterials.AttackGlow, looks.Flash);
+ burstPuff[i] = Make("FlakBurst", smokeFrames[0], HexMaterials.AttackSmoke, looks.Smoke);
+ }
+ trail = new Part[SeaAirCollection.TrailPuffs];
+ for (int i = 0; i < trail.Length; i++) trail[i] = Make("WingSmoke", smokeFrames[0], HexMaterials.AttackSmoke, looks.Smoke);
+ // The blast is alpha-blended, as the bombs' (DakotaBombRun): its fire glows by its own colours, its smoke stays dark.
+ crash = Make("WingCrash", blastFrames[0], HexMaterials.AttackBorder, looks.Blast);
+ }
+
+ void Update()
+ {
+ if (!still) Place(SpitfireLoop.Clock());
+ }
+
+ void OnEnable() => RenderPipelineManager.beginCameraRendering += Face;
+ void OnDisable() => RenderPipelineManager.beginCameraRendering -= Face;
+
+ /// <summary>Keeps the camera's rotation for the quads and turns those showing to it, as DakotaLoop does the bombs'.</summary>
+ void Face(ScriptableRenderContext _, Camera cam)
+ {
+ if (cam.cameraType == CameraType.Preview || cam.cameraType == CameraType.Reflection) return;
+ view = cam.transform.rotation;
+ Place(PlacedAt);
+ }
+
+ static Vector3 Flat(Vector2 v) => new Vector3(v.x, 0f, v.y);
+ static int Mod(int a, int n) { int m = a % n; return m < 0 ? m + n : m; }
+
+ /// <summary>DakotaLoop's turn at the loop time <paramref name="u"/>: the yaw from east to the heading, then the bank about it.</summary>
+ static Quaternion LoopTurn(float u)
+ {
+ var h = SeaAirCollection.DakotaLoopHeading(u);
+ var yaw = Quaternion.Euler(0f, -Mathf.Atan2(h.y, h.x) * Mathf.Rad2Deg, 0f);
+ return Quaternion.AngleAxis(SeaAirCollection.DakotaBankDegrees(u), new Vector3(h.x, 0f, h.y)) * yaw;
+ }
+
+ /// <summary>Puts everything where it is <paramref name="seconds"/> into the loop's clock (the lead's time).</summary>
+ public void Place(float seconds)
+ {
+ PlacedAt = seconds;
+ for (int i = 0; i < fighters.Length; i++) PlaceFighter(i, seconds);
+ float u = seconds - SeaAirCollection.DakotaTrailSeconds; // the wing's own time
+ PlaceFlak(u);
+ PlaceWing(u);
+ }
+
+ void PlaceFighter(int i, float seconds)
+ {
+ var f = fighters[i];
+ var drawn = centre + SeaAirCollection.FighterOffset(i, seconds);
+ var v = SeaAirCollection.FighterVelocity(i, seconds);
+ float speed = new Vector2(v.x, v.z).magnitude;
+ var flat = speed > 1f ? new Vector3(v.x / speed, 0f, v.z / speed) : Vector3.right;
+ float pitch = Mathf.Clamp(Mathf.Atan2(v.y, Mathf.Max(speed, 1f)) * Mathf.Rad2Deg, -SeaAirCollection.FighterPitchMaxDeg, SeaAirCollection.FighterPitchMaxDeg);
+ var nose = flat * Mathf.Cos(pitch * Mathf.Deg2Rad) + Vector3.up * Mathf.Sin(pitch * Mathf.Deg2Rad);
+ float bank = SeaAirCollection.FighterBankDegrees(i, seconds);
+ f.Plane.SetPositionAndRotation(drawn, Quaternion.AngleAxis(bank, nose) * Quaternion.LookRotation(nose, Vector3.up));
+ f.Prop.localRotation = Quaternion.AngleAxis(-(float)((double)seconds * SpitfireLoop.PropDegreesPerSecond % 360.0), Vector3.forward);
+ if (f.Flag != null)
+ {
+ f.Flag.position = drawn - flat * f.Half.x + Vector3.up * (SpitfireLoop.TopOver(f.Half, bank) + f.Half.x * Mathf.Abs(Mathf.Sin(pitch * Mathf.Deg2Rad))
+ + DakotaLoop.FlagClearM + f.FlagHalf);
+ }
+ if (f.Shadow != null && terrain != null) SpitfireLoop.LayShadow(f.Shadow, terrain, seaY, f.ShadowHalf, drawn, flat, bank, converge: true);
+
+ // The gun: flashes and tracers from the nose to the lead while it fires; hits on the lead, left where they struck.
+ float share = SeaAirCollection.FighterAttackShare(i, seconds);
+ bool firing = share >= SeaAirCollection.FighterFireFrom && share < SeaAirCollection.FighterFireTo;
+ var gun = drawn + nose * f.Half.x;
+ var aim = centre + Flat(SeaAirCollection.DakotaLoopOffset(seconds)); // the lead's drawn centre (its lag is 0)
+ var line = aim - gun; float length = line.magnitude;
+ var dir = length > 1f ? line / length : nose;
+ var camForward = view * Vector3.forward;
+ var face = camForward - dir * Vector3.Dot(camForward, dir);
+ if (face.sqrMagnitude < 1e-6f) face = Vector3.Cross(dir, Vector3.up);
+ face.Normalize();
+ var along = Quaternion.LookRotation(face, Vector3.Cross(face, dir)); // its local x along the line, its face to the camera
+ float fireStart = SeaAirCollection.FighterAttackStartS[i] + SeaAirCollection.FighterFireFrom * SeaAirCollection.FighterAttackS;
+ for (int k = 0; k < SeaAirCollection.FighterTracers; k++)
+ {
+ ref var t = ref tracer[i * SeaAirCollection.FighterTracers + k];
+ t.R.enabled = firing;
+ if (!firing) continue;
+ float run = (float)(((double)seconds - fireStart) * SeaAirCollection.TracerRate + (double)k / SeaAirCollection.FighterTracers);
+ run -= Mathf.Floor(run);
+ t.T.SetPositionAndRotation(gun + dir * (run * length), along);
+ t.T.localScale = new Vector3(SeaAirCollection.TracerLengthM, SeaAirCollection.TracerWidthM, 1f);
+ var c = TracerColour; c.a = 1f - 0.6f * run; t.M.SetColor(BaseColor, c);
+ }
+ ref var mz = ref muzzle[i];
+ float flash = firing ? UnitGunFire.Flash(Mathf.Repeat(seconds - fireStart, SeaAirCollection.MuzzleFlashGapS)) : 0f;
+ mz.R.enabled = flash > 0f;
+ if (flash > 0f)
+ {
+ mz.T.SetPositionAndRotation(gun, view * Quaternion.Euler(0f, 0f, 37f));
+ mz.T.localScale = Vector3.one * SeaAirCollection.MuzzleFlashM;
+ var c = FlashColour; c.a = flash; mz.M.SetColor(BaseColor, c);
+ }
+
+ float phase = Mathf.Repeat(seconds - SeaAirCollection.FighterAttackStartS[i], SeaAirCollection.DakotaLoopSeconds);
+ double cycle = (double)seconds - phase; // this loop's attack start
+ float span = SeaAirCollection.SizeOf(SeaAirCollection.Dakota);
+ for (int j = 0; j < SeaAirCollection.FighterHits; j++)
+ {
+ ref var hf = ref hitFlash[i * SeaAirCollection.FighterHits + j]; ref var hp = ref hitPuff[i * SeaAirCollection.FighterHits + j];
+ float at = SeaAirCollection.FighterHitFrom + (SeaAirCollection.FighterHitTo - SeaAirCollection.FighterHitFrom) * j / (SeaAirCollection.FighterHits - 1f);
+ double born = cycle + at * SeaAirCollection.FighterAttackS;
+ float age = (float)((double)seconds - born);
+ bool on = age >= 0f && age < SeaAirCollection.HitPuffS;
+ hp.R.enabled = on;
+ hf.R.enabled = on && age < UnitGunFire.FlashS * 2f;
+ if (!on) continue;
+ float b = (float)born;
+ var hd = SeaAirCollection.DakotaLoopHeading(b);
+ var fwd = Flat(hd); var right = new Vector3(hd.y, 0f, -hd.x);
+ var s = HitSpot[j % HitSpot.Length];
+ var spot = centre + Flat(SeaAirCollection.DakotaLoopOffset(b)) + fwd * (s.x * 0.5f * span * dakotaLengthShare) + right * (s.z * 0.5f * span)
+ + Vector3.up * (s.y * 0.2f * span);
+ if (hf.R.enabled)
+ {
+ hf.T.SetPositionAndRotation(spot, view * Quaternion.Euler(0f, 0f, 37f + 50f * j));
+ hf.T.localScale = Vector3.one * SeaAirCollection.HitFlashM;
+ var c = FlashColour; c.a = UnitGunFire.Flash(0.5f * age); hf.M.SetColor(BaseColor, c);
+ }
+ float life = age / SeaAirCollection.HitPuffS;
+ UnitGunFire.Puff(life, out _, out float rise, out float radius, out float alpha);
+ hp.F.sharedMesh = smokeFrames[Mathf.Min((int)(life * smokeFrames.Length), smokeFrames.Length - 1)];
+ hp.T.SetPositionAndRotation(spot + Vector3.up * (rise * SeaAirCollection.HitPuffM), view * Quaternion.Euler(0f, 0f, 70f * j));
+ hp.T.localScale = Vector3.one * (SeaAirCollection.HitPuffM * radius / (UnitGunFire.PuffRadiusShare + UnitGunFire.PuffGrowShare)); // grows to HitPuffM
+ var sc = Color.Lerp(HitSmoke, SmokeThin, life); sc.a = alpha; hp.M.SetColor(BaseColor, sc);
+ }
+ }
+
+ /// <summary>The flak at the wing's own loop time <paramref name="u"/>: each burst's gun flashes on the ground its flight
+ /// time before; the burst flashes and leaves a dark puff that swells and thins.</summary>
+ void PlaceFlak(float u)
+ {
+ float flight = SeaAirCollection.FlakFlightS;
+ for (int i = 0; i < burstAt.Length; i++)
+ {
+ float since = Mathf.Repeat(u - SeaAirCollection.FlakAtS[i] + flight, SeaAirCollection.DakotaLoopSeconds) - flight;
+ ref var g = ref gunFlash[i]; ref var bf = ref burstFlash[i]; ref var bp = ref burstPuff[i];
+ float fromGun = since + flight;
+ g.R.enabled = fromGun < UnitGunFire.FlashS * 2f && siteAt.Length > 0;
+ if (g.R.enabled)
+ {
+ g.T.SetPositionAndRotation(siteAt[i % siteAt.Length] + Vector3.up * (0.4f * SeaAirCollection.GunFlashM), view * Quaternion.Euler(0f, 0f, 20f * i));
+ g.T.localScale = Vector3.one * SeaAirCollection.GunFlashM;
+ var c = FlashColour; c.a = UnitGunFire.Flash(0.5f * fromGun); g.M.SetColor(BaseColor, c);
+ }
+ bf.R.enabled = since >= 0f && since < UnitGunFire.FlashS * 2.5f;
+ if (bf.R.enabled)
+ {
+ bf.T.SetPositionAndRotation(burstAt[i], view * Quaternion.Euler(0f, 0f, 37f + 40f * i));
+ bf.T.localScale = Vector3.one * (0.8f * SeaAirCollection.FlakBurstM);
+ var c = FlashColour; c.a = UnitGunFire.Flash(since / 2.5f); bf.M.SetColor(BaseColor, c);
+ }
+ float life = since / SeaAirCollection.FlakBurstS;
+ bp.R.enabled = life >= 0f && life < 1f;
+ if (!bp.R.enabled) continue;
+ bp.F.sharedMesh = smokeFrames[Mathf.Min((int)(life * smokeFrames.Length), smokeFrames.Length - 1)];
+ bp.T.SetPositionAndRotation(burstAt[i] + Vector3.up * (0.15f * life * SeaAirCollection.FlakBurstM), view * Quaternion.Euler(0f, 0f, 55f * i));
+ bp.T.localScale = Vector3.one * (SeaAirCollection.FlakBurstM * (0.45f + 0.55f * Mathf.Sqrt(life)));
+ var sc = Color.Lerp(FlakSmoke, SmokeThin, life * life);
+ sc.a = Mathf.SmoothStep(0f, 1f, life / 0.06f) * (1f - Mathf.SmoothStep(0f, 1f, (life - 0.45f) / 0.55f));
+ bp.M.SetColor(BaseColor, sc);
+ }
+ }
+
+ /// <summary>The wing at its own loop time <paramref name="u"/>: on its loop (DakotaLoop placed it), falling (moved here,
+ /// with its flag and shadow, its smoke trailing), or gone (hidden, the blast on the ground, the trail thinning).</summary>
+ void PlaceWing(float u)
+ {
+ int state = SeaAirCollection.WingState(u, out float since);
+ bool show = state != 2;
+ if (show != wingShown)
+ {
+ wingShown = show;
+ for (int i = 0; i < wingRenderers.Length; i++) if (wingRenderers[i] != null) wingRenderers[i].enabled = show;
+ if (wingFlagR != null) wingFlagR.enabled = show;
+ if (wingShadowR != null) wingShadowR.enabled = show;
+ }
+ if (state == 1 && wing != null)
+ {
+ var drawn = WingAt = FallPoint(since, out var flat, out float pitch, out float bank);
+ var nose = flat * Mathf.Cos(pitch * Mathf.Deg2Rad) - Vector3.up * Mathf.Sin(pitch * Mathf.Deg2Rad);
+ var yaw = Quaternion.Euler(0f, -Mathf.Atan2(flat.z, flat.x) * Mathf.Rad2Deg, 0f);
+ var turn = Quaternion.AngleAxis(bank, nose) * Quaternion.AngleAxis(-pitch, Vector3.Cross(flat, Vector3.up)) * yaw;
+ wing.transform.localRotation = turn * wingLevel;
+ wing.transform.position = drawn - turn * wingOffset;
+ if (wingFlag != null) wingFlag.position = drawn + Vector3.up * wingFlagUp;
+ if (wingShadow != null && terrain != null) SpitfireLoop.LayShadow(wingShadow, terrain, seaY, wingShadowHalf, drawn, flat, bank, converge: true);
+ }
+
+ // The smoke it trails from the hit, left in the air where it was let out.
+ int newest = state == 0 ? -1 : (int)Mathf.Floor(Mathf.Min(since, SeaAirCollection.WingFallS) / SeaAirCollection.TrailGapS);
+ for (int slot = 0; slot < trail.Length; slot++)
+ {
+ ref var p = ref trail[slot];
+ int j = newest - Mod(newest - slot, trail.Length);
+ float born = j * SeaAirCollection.TrailGapS, age = since - born;
+ bool on = newest >= 0 && j >= 0 && age >= 0f && age < SeaAirCollection.TrailPuffS;
+ p.R.enabled = on;
+ if (!on) continue;
+ var at = FallPoint(born, out var flat, out _, out _);
+ float life = age / SeaAirCollection.TrailPuffS;
+ float span = SeaAirCollection.SizeOf(SeaAirCollection.Dakota);
+ p.F.sharedMesh = smokeFrames[Mod((int)Mathf.Floor(age * SeaAirCollection.DakotaColumnFps + slot * 7), smokeFrames.Length)];
+ p.T.SetPositionAndRotation(at - flat * (0.15f * span * dakotaLengthShare) + Vector3.up * (0.25f * life * SeaAirCollection.TrailPuffM),
+ view * Quaternion.Euler(0f, 0f, 47f * slot));
+ p.T.localScale = Vector3.one * (SeaAirCollection.TrailPuffM * (0.5f + 0.8f * Mathf.Sqrt(life)));
+ var c = Color.Lerp(TrailSmoke, SmokeThin, life);
+ c.a = 0.9f * Mathf.SmoothStep(0f, 1f, life / 0.05f) * (1f - Mathf.SmoothStep(0f, 1f, (life - 0.4f) / 0.6f));
+ p.M.SetColor(BaseColor, c);
+ }
+
+ // Its blast where it comes down.
+ float b = (since - SeaAirCollection.WingFallS) / SeaAirCollection.DakotaBlastS;
+ crash.R.enabled = state == 2 && b >= 0f && b < 1f;
+ if (crash.R.enabled)
+ {
+ crash.F.sharedMesh = blastFrames[Mathf.Min((int)(b * blastFrames.Length), blastFrames.Length - 1)];
+ float size = SeaAirCollection.DakotaBlastM * DakotaBombRun.BlastSwell(b);
+ crash.T.SetPositionAndRotation(crashAt + Vector3.up * (0.4f * size), view);
+ crash.T.localScale = Vector3.one * size;
+ var c = Color.white; c.a = DakotaBombRun.BlastAlpha(b); crash.M.SetColor(BaseColor, c);
+ }
+ }
+
+ /// <summary>The falling wing's drawn centre <paramref name="since"/> seconds after the hit, its heading seen from above,
+ /// its nose-down pitch and its roll (degrees).</summary>
+ Vector3 FallPoint(float since, out Vector3 flat, out float pitch, out float bank)
+ {
+ float t = Mathf.Clamp(since, 0f, SeaAirCollection.WingFallS);
+ var xz = SeaAirCollection.WingFall(t, wingHitSpeed, wingHitHeading, out float heading, out float drop);
+ flat = new Vector3(Mathf.Cos(heading), 0f, Mathf.Sin(heading));
+ float speed = wingHitSpeed * (1f - (1f - SeaAirCollection.WingFallSpeedShare) * t / SeaAirCollection.WingFallS);
+ float sink = wingDrop * 2f * t / (SeaAirCollection.WingFallS * SeaAirCollection.WingFallS);
+ pitch = Mathf.Min(Mathf.Atan2(sink, Mathf.Max(speed, 1f)) * Mathf.Rad2Deg, SeaAirCollection.WingFallPitchDeg);
+ bank = SeaAirCollection.WingFallBankDeg * Mathf.SmoothStep(0f, 1f, t / 3f) * (1f - Mathf.SmoothStep(0f, 1f, (t - 0.6f * SeaAirCollection.WingFallS) / (0.4f * SeaAirCollection.WingFallS)));
+ return new Vector3(wingHitAt.x + xz.x, centre.y - wingDrop * drop, wingHitAt.z + xz.y);
+ }
+ }
+}
diff --git a/unity/Assets/Scripts/Map/Collection/TelAvivAirDefence.cs.meta b/unity/Assets/Scripts/Map/Collection/TelAvivAirDefence.cs.meta
new file mode 100644
index 000000000..ff5fae4e1
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Collection/TelAvivAirDefence.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: ef5e35649cfd4dc8a6c06dbc1c70c0ef
diff --git a/unity/Assets/Tests/EditMode/SeaAirCollectionTests.cs b/unity/Assets/Tests/EditMode/SeaAirCollectionTests.cs
index 7eb26588a..620bf7f62 100644
--- a/unity/Assets/Tests/EditMode/SeaAirCollectionTests.cs
+++ b/unity/Assets/Tests/EditMode/SeaAirCollectionTests.cs
@@ -343,9 +343,11 @@ public class SeaAirCollectionTests
/// the 15 May turn only, at Tel Aviv's place. #2482 (owner, 4 November 2026: "make the visual 2 slightly smaller planes and
/// not 0ne big one"; the sourced sortie was "גיחה של שני מטוסי הפצצה", two bombers): two Dakotas, each with its own stable
/// key made from DakotaKey, the lead first, each slightly smaller than the one 12.2 km Dakota of #2274 (DakotaScale of the
- /// unit tokens' aircraft scale). Changed from #2274's one-key test: it asserted one want and the full 420x size.</summary>
+ /// unit tokens' aircraft scale). Changed from #2274's one-key test: it asserted one want and the full 420x size. Changed
+ /// again for the second bombing period, 8 to 17 July 1948 (DakotaSecondFrom; owner: "(a) Add the Dakotas to the 15 July
+ /// 1948 turn, the second bombing period"): it asserted the 15 May turn only and no Dakota after 11 June.</summary>
[Test]
- public void TheTwoDakotasAreWantedOnlyInTheFirstBombingPeriod()
+ public void TheTwoDakotasAreWantedOnlyInTheTwoBombingPeriods()
{
bool Wanted(DateTime d)
{
@@ -363,9 +365,13 @@ public class SeaAirCollectionTests
Assert.IsTrue(Wanted(new DateTime(1948, 6, 11)));
Assert.IsFalse(Wanted(new DateTime(1948, 6, 12)), "the first truce");
Assert.IsFalse(Wanted(new DateTime(1948, 6, 15)));
+ Assert.IsFalse(Wanted(new DateTime(1948, 7, 7)), "the first truce, to 8 July");
+ Assert.IsTrue(Wanted(new DateTime(1948, 7, 8)), "the Ten Days: the second bombing period begins");
+ Assert.IsTrue(Wanted(new DateTime(1948, 7, 17)), "the last bombing of Tel Aviv");
+ Assert.IsFalse(Wanted(new DateTime(1948, 7, 18)), "the second truce");
var turns = new List<DateTime>();
for (var d = C.Rules.Start; d < C.End; d = d.AddMonths(1)) turns.Add(d);
- CollectionAssert.AreEqual(new[] { new DateTime(1948, 5, 15) }, turns.Where(Wanted), "the 15 May 1948 turn only");
+ CollectionAssert.AreEqual(new[] { new DateTime(1948, 5, 15), new DateTime(1948, 7, 15) }, turns.Where(Wanted), "the 15 May and 15 July 1948 turns only");
Assert.AreEqual(29.11f, SeaAirCollection.RealLengthM(SeaAirCollection.Dakota), 0.01f, "95 ft 6 in, en.wiki Douglas C-47 Skytrain");
float old = 29.11f * Statecraft.Game.Map.Units.UnitShowcase.AircraftScale; // #2274's one Dakota, 12.2 km across
Assert.That(SeaAirCollection.DakotaScale, Is.InRange(0.6f, 0.95f), "slightly smaller, not a different kind of piece");
@@ -538,9 +544,9 @@ public class SeaAirCollectionTests
return C.SettlementHexes.Any(h => h.Id == SeaAirCollection.DakotaTown && h.Q == q && h.R == r);
}
- /// <summary>Two Dakotas in the window, none outside it (#2482): on the turns of 14 May, 12 June and 15 June 1948 no Dakota,
- /// no loop, and no marks object (flag, shadow, bombs) is drawn; on the 15 May turn exactly two looping Dakotas, each at
- /// the smaller size.</summary>
+ /// <summary>Two Dakotas in the windows, none outside them (#2482): on the turns of 14 May, 12 June, 15 June, 7 July and 18
+ /// July 1948 no Dakota, no loop, and no marks object (flag, shadow, bombs) is drawn; on the 15 May and 15 July turns exactly
+ /// two looping Dakotas. Changed for the second bombing period (DakotaSecondFrom), which added 7, 15 and 18 July.</summary>
[Test]
public void TwoDakotasFlyInTheWindowAndNoneOutsideIt()
{
@@ -549,6 +555,7 @@ public class SeaAirCollectionTests
{
(new DateTime(1948, 5, 14), false), (new DateTime(1948, 5, 15), true), (new DateTime(1948, 6, 11), true),
(new DateTime(1948, 6, 12), false), (new DateTime(1948, 6, 15), false),
+ (new DateTime(1948, 7, 7), false), (new DateTime(1948, 7, 15), true), (new DateTime(1948, 7, 18), false),
})
{
var layer = CollectionGeometryFixture.Craft(map, date, Array.Empty<Placement>(), C)!; AnswerAll();
diff --git a/unity/Assets/Tests/EditMode/TelAvivAirDefenceTests.cs b/unity/Assets/Tests/EditMode/TelAvivAirDefenceTests.cs
new file mode 100644
index 000000000..7bca72edd
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/TelAvivAirDefenceTests.cs
@@ -0,0 +1,305 @@
+#nullable enable
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game.Map;
+using Statecraft.Game.Map.Collection;
+using Statecraft.Game.Map.Kits;
+using Statecraft.Sim;
+using UnityEditor;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+using Object = UnityEngine.Object;
+
+/// <summary>Tel Aviv's air defence on the second bombing period's turns (SeaAirCollection.AirDefence.cs, TelAvivAirDefence).
+/// Owner: "we will need an animation of the 101 attacking the dakotas"; "(a) Add the Dakotas to the 15 July 1948 turn, the
+/// second bombing period, with 101 Squadron's fighters attacking them over Tel Aviv. Both sides are historically present that
+/// turn."; then "do 1+2": (1) the S-199s attack with hits and no 101 shoot-down, an illustration; (2) one Dakota goes down to
+/// anti-aircraft fire, the sourced 17 July 1948 event (JTA 19 July 1948, agent-read, a person's check pending).</summary>
+public class TelAvivAirDefenceTests
+{
+ Action<string, CollectionDetail, Action<GameObject?>> saved = null!;
+ readonly List<(string id, CollectionDetail detail, Action<GameObject?> done)> asked = new List<(string, CollectionDetail, Action<GameObject?>)>();
+ static readonly Content C = ContentLoader.Load(Statecraft.Game.Paths.Content);
+ static readonly DateTime July15 = new DateTime(1948, 7, 15), May15 = new DateTime(1948, 5, 15);
+
+ [SetUp]
+ public void Seam()
+ {
+ saved = SeaAirCollection.Request; asked.Clear();
+ SeaAirCollection.Request = (id, d, done) => asked.Add((id, d, done));
+ }
+
+ [TearDown]
+ public void Reset()
+ {
+ SeaAirCollection.Request = saved;
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ }
+
+ static MapScene OpenMap()
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var map = Object.FindFirstObjectByType<MapScene>(); map.Build(); return map;
+ }
+
+ void AnswerAll()
+ {
+ var pending = asked.ToList(); asked.Clear();
+ foreach (var (id, _, done) in pending) done(AssetDatabase.LoadAssetAtPath<GameObject>(CollectionCatalog.PrefabPath(id, CollectionDetail.Far)));
+ }
+
+ static Bounds WorldBounds(GameObject go) =>
+ go.GetComponentsInChildren<Renderer>(true).Select(x => x.bounds).Aggregate((a, x) => { a.Encapsulate(x); return a; });
+
+ SeaAirCollection Drawn(MapScene map, DateTime date)
+ {
+ var layer = CollectionGeometryFixture.Craft(map, date, Array.Empty<Placement>(), C)!; AnswerAll();
+ return layer;
+ }
+
+ static DakotaLoop[] Loops(SeaAirCollection layer) => SeaAirCollection.DakotaKeys.Select(k => layer.transform.Find(k)!.GetComponent<DakotaLoop>()).ToArray();
+
+ /// <summary>Places the Dakotas and then the air defence at the loop clock's <paramref name="t"/>, in the order they run.</summary>
+ static void PlaceAll(DakotaLoop[] loops, TelAvivAirDefence defence, float t)
+ {
+ foreach (var loop in loops) loop.Place(t);
+ defence.Place(t);
+ }
+
+ /// <summary>The fighters and the anti-aircraft fire only in the second bombing period, 8 to 17 July 1948: on the game's
+ /// monthly turns the 15 July 1948 turn only, never the 15 May turn (the first period shows the Dakotas alone).</summary>
+ [Test]
+ public void TheAirDefenceIsWantedOnlyInTheSecondBombingPeriod()
+ {
+ Assert.AreEqual(new DateTime(1948, 7, 8), SeaAirCollection.DakotaSecondFrom);
+ Assert.AreEqual(new DateTime(1948, 7, 17), SeaAirCollection.DakotaSecondTo);
+ Assert.IsFalse(SeaAirCollection.AirDefenceWanted(new DateTime(1948, 7, 7)));
+ Assert.IsTrue(SeaAirCollection.AirDefenceWanted(new DateTime(1948, 7, 8)));
+ Assert.IsTrue(SeaAirCollection.AirDefenceWanted(new DateTime(1948, 7, 17)));
+ Assert.IsFalse(SeaAirCollection.AirDefenceWanted(new DateTime(1948, 7, 18)));
+ Assert.IsFalse(SeaAirCollection.AirDefenceWanted(May15), "no fighters on 15 May");
+ Assert.IsFalse(SeaAirCollection.AirDefenceWanted(new DateTime(1948, 6, 3)), "not even on 3 June: the first period shows the Dakotas alone");
+ var turns = new List<DateTime>();
+ for (var d = C.Rules.Start; d < C.End; d = d.AddMonths(1)) turns.Add(d);
+ CollectionAssert.AreEqual(new[] { July15 }, turns.Where(SeaAirCollection.AirDefenceWanted), "the 15 July 1948 turn only");
+ foreach (var d in turns.Where(SeaAirCollection.AirDefenceWanted)) Assert.IsTrue(SeaAirCollection.DakotaWanted(d), "the fighters only with the Dakotas");
+ Assert.IsFalse(SeaAirCollection.Wants(July15, C).Any(w => w.Key.Contains("s199")), "the fighters are code-built, not a streamed Collection craft");
+ }
+
+ /// <summary>On the 15 July 1948 turn: the two Dakotas and, beside them, the air defence with two Avia S-199s (the map's
+ /// code-built UnitModels.AviaS199, not a Collection model: no request for it), each with its propeller, its shadow and
+ /// Israel's flag; on 15 May the Dakotas fly alone: no air defence object, no fighters.</summary>
+ [Test]
+ public void TheJulyTurnShowsTheDakotasAndTwoS199sAndMayShowsNoFighters()
+ {
+ var map = OpenMap();
+ var july = Drawn(map, July15);
+ Assert.AreEqual(2, july.Placed.Count(p => p.Model == SeaAirCollection.Dakota), "both Dakotas on 15 July");
+ var defence = july.AirDefence;
+ Assert.IsNotNull(defence, "the air defence on 15 July");
+ Assert.AreEqual(july.transform.Find(SeaAirCollection.AirDefenceKey), defence!.transform, "beside the Dakotas, under its key");
+ Assert.AreEqual(2, defence.FighterPlanes.Length, "two fighters");
+ foreach (var plane in defence.FighterPlanes)
+ {
+ StringAssert.Contains("S199", plane.GetComponent<MeshFilter>().sharedMesh.name, $"{plane.name} is the S-199 model");
+ Assert.IsNotNull(plane.Find("Propeller"), $"{plane.name}'s propeller");
+ var marks = defence.transform.Find(plane.name + SeaAirCollection.DakotaMarksSuffix);
+ Assert.IsNotNull(marks?.Find(SeaAirCollection.DakotaFlagName), $"{plane.name}'s flag");
+ Assert.IsNotNull(marks?.Find(SeaAirCollection.DakotaShadowName), $"{plane.name}'s shadow");
+ }
+ Assert.IsTrue(defence.Still, "edit mode holds the loop's start");
+ Assert.AreEqual(1, july.Placed.Count(p => p.Model == SeaAirCollection.Spitfire), "the only Spitfire is el-Arish's: no Spitfire stands in for a fighter");
+
+ var may = Drawn(map, May15);
+ Assert.AreEqual(2, may.Placed.Count(p => p.Model == SeaAirCollection.Dakota), "both Dakotas on 15 May");
+ Assert.IsNull(may.AirDefence, "no air defence on 15 May");
+ Assert.IsNull(may.transform.Find(SeaAirCollection.AirDefenceKey), "no air defence object on 15 May");
+ Assert.AreEqual(0, Object.FindObjectsByType<TelAvivAirDefence>(FindObjectsInactive.Include, FindObjectsSortMode.None).Length, "no fighters anywhere on 15 May");
+ }
+
+ /// <summary>#2649 review: 15 May and 15 July want the same two Dakotas, so a direct change between them must still add or
+ /// remove the air defence on the same layer (ShowAt reuses it), in both directions.</summary>
+ [Test]
+ public void ADirectChangeBetweenMayAndJulyAddsAndRemovesTheAirDefence()
+ {
+ var map = OpenMap();
+ var may = Drawn(map, May15);
+ Assert.IsNull(may.AirDefence, "no air defence on 15 May");
+ var july = Drawn(map, July15);
+ Assert.AreSame(may, july, "the same layer, reused");
+ Assert.IsNotNull(july.AirDefence, "15 May -> 15 July adds the air defence");
+ Assert.AreEqual(2, july.AirDefence!.FighterPlanes.Length, "with its two fighters");
+ var back = Drawn(map, May15);
+ Assert.IsNull(back.AirDefence, "15 July -> 15 May removes it");
+ Assert.IsNull(back.transform.Find(SeaAirCollection.AirDefenceKey), "and its object");
+ }
+
+ /// <summary>The fighters stay in their sector: at every point of the loop each fighter, at every heading, bank and pitch,
+ /// is inside the box the Dakotas fly through (SeaAirCollection.DakotaSweptHalf about their loop centre, which DakotaSpot
+ /// keeps on the board), above the Dakotas, never in a Dakota's box, and inside the box the names keep clear of for it.</summary>
+ [Test]
+ public void TheFightersStayInTheirSectorClearOfTheDakotasAndTheLabels()
+ {
+ var map = OpenMap();
+ var layer = Drawn(map, July15);
+ var defence = layer.AirDefence!; var loops = Loops(layer);
+ var centre = layer.Placed.First(p => p.Model == SeaAirCollection.Dakota).At;
+ var half = SeaAirCollection.DakotaSweptHalf;
+ var ground = PlacementLayer.CampGround(map);
+ Assert.IsTrue(ground.Inside(centre.x - half.x, centre.z - half.y) && ground.Inside(centre.x + half.x, centre.z + half.y), "premise: the sector is on the board");
+ var keepOf = (System.Collections.IDictionary)typeof(SeaAirCollection).GetField("keepOf", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.GetValue(layer)!;
+ float period = SeaAirCollection.DakotaLoopSeconds;
+ for (int i = 0; i < 480; i++)
+ {
+ float t = i * period / 480f;
+ PlaceAll(loops, defence, t);
+ var all = layer.KeepClear; // moves the boxes
+ var lead = WorldBounds(loops[0].gameObject); var wing = WorldBounds(loops[1].gameObject);
+ foreach (var plane in defence.FighterPlanes)
+ {
+ var b = WorldBounds(plane.gameObject);
+ Assert.IsTrue(b.min.x >= centre.x - half.x && b.max.x <= centre.x + half.x && b.min.z >= centre.z - half.y && b.max.z <= centre.z + half.y,
+ $"{plane.name} inside its sector at {t:0.00} s ({b.center - centre})");
+ Assert.Greater(b.min.y, lead.min.y, $"{plane.name} above the Dakotas at {t:0.00} s");
+ Assert.IsFalse(b.Intersects(lead), $"{plane.name} clear of the lead at {t:0.00} s");
+ if (defence.WingShown && SeaAirCollection.WingState(t - SeaAirCollection.DakotaTrailSeconds, out _) == 0)
+ Assert.IsFalse(b.Intersects(wing), $"{plane.name} clear of the wing at {t:0.00} s");
+ var keep = ((Bounds[])keepOf[plane.gameObject]!)[0];
+ Assert.IsTrue(all.Any(x => ReferenceEquals(x, keepOf[plane.gameObject])), $"{plane.name}'s box is in the list the labels read");
+ Assert.IsTrue(keep.Contains(b.min) && keep.Contains(b.max), $"{plane.name} inside its keep-clear box at {t:0.00} s");
+ }
+ }
+ }
+
+ /// <summary>The choreography, deterministic on the Dakotas' loop clock: each fighter dives in (from FighterTopM over the
+ /// lead to FighterPassUpM at the middle of its attack), passes it and pulls away; it fires only in its firing share (the
+ /// tracers and the gun's flash), and its hits show on the lead in its hit share; never outside its attack. The same
+ /// time gives the same frame, a loop later too. The lead is never brought down by the fighters: drawn at every time.</summary>
+ [Test]
+ public void EachFighterDivesFiresHitsAndPullsAwayAndTheLeadFliesOn()
+ {
+ var map = OpenMap();
+ var layer = Drawn(map, July15);
+ var defence = layer.AirDefence!; var loops = Loops(layer);
+ var leadRenderers = loops[0].GetComponentsInChildren<Renderer>(true);
+ var tracers = defence.TracerRenderers; var hits = defence.HitRenderers;
+ int perTracer = SeaAirCollection.FighterTracers, perHit = SeaAirCollection.FighterHits;
+ for (int f = 0; f < 2; f++)
+ {
+ float start = SeaAirCollection.FighterAttackStartS[f], a = SeaAirCollection.FighterAttackS;
+ float Up(float p) => SeaAirCollection.FighterOffset(f, start + p * a).y;
+ Assert.AreEqual(SeaAirCollection.FighterTopM, Up(0f), 1f, "it starts high over the lead");
+ Assert.AreEqual(SeaAirCollection.FighterPassUpM, Up(0.5f), 1f, "dives to its pass");
+ Assert.AreEqual(SeaAirCollection.FighterTopM, Up(0.999f), 5f, "and pulls up away");
+ float Gap(float p)
+ {
+ var o = SeaAirCollection.FighterOffset(f, start + p * a); var d = SeaAirCollection.DakotaLoopOffset(start + p * a);
+ return new Vector2(o.x - d.x, o.z - d.y).magnitude;
+ }
+ Assert.Greater(Gap(0f), 5000f, "it starts well behind the lead");
+ Assert.Less(Gap(0.5f), 4000f, "closes on it");
+ Assert.Greater(Gap(0.999f), 5000f, "and passes it, pulling away ahead");
+ var lead = SeaAirCollection.DakotaLoopHeading(start + a);
+ var o1 = SeaAirCollection.FighterOffset(f, start + a); var d1 = SeaAirCollection.DakotaLoopOffset(start + a);
+ Assert.Greater(Vector2.Dot(new Vector2(o1.x - d1.x, o1.z - d1.y), lead), 0f, "ahead of the lead at its attack's end");
+
+ foreach (var (p, firing, hit) in new[] { (0.1f, false, false), (0.3f, true, false), (0.4f, true, true), (0.6f, false, true), (0.9f, false, false) })
+ {
+ float t = start + p * a;
+ PlaceAll(loops, defence, t);
+ Assert.AreEqual(firing, Enumerable.Range(f * perTracer, perTracer).Any(k => tracers[k].enabled), $"fighter {f} firing at {p:0.0} of its attack");
+ Assert.AreEqual(hit, Enumerable.Range(f * perHit, perHit).Any(k => hits[k].enabled), $"fighter {f}'s hits on the lead at {p:0.0} of its attack");
+ }
+ }
+ // Outside every attack: no tracer.
+ PlaceAll(loops, defence, 30f);
+ Assert.IsFalse(tracers.Any(r => r.enabled), "no fire between the attacks");
+
+ // Deterministic: the same time, the same frame, also a loop later; the lead drawn throughout.
+ foreach (var t in new[] { 0f, 1.3f, 33.3f, 61.7f, 97.2f })
+ {
+ PlaceAll(loops, defence, t);
+ var first = defence.FighterPlanes.Select(p => (p.position, p.rotation)).ToArray();
+ PlaceAll(loops, defence, t + SeaAirCollection.DakotaLoopSeconds);
+ var again = defence.FighterPlanes.Select(p => (p.position, p.rotation)).ToArray();
+ for (int i = 0; i < first.Length; i++)
+ {
+ Assert.Less((first[i].position - again[i].position).magnitude, 2f, $"fighter {i} at the same place a loop after {t} s");
+ Assert.Greater(Quaternion.Dot(first[i].rotation, again[i].rotation), 0.9999f, $"fighter {i} the same way a loop after {t} s");
+ }
+ }
+ for (int i = 0; i < 240; i++)
+ {
+ PlaceAll(loops, defence, i * 0.5f);
+ Assert.IsTrue(leadRenderers.All(r => r.enabled), $"the lead is never shot down (at {i * 0.5f:0.0} s)");
+ }
+ }
+
+ /// <summary>Option 2, the sourced 17 July shoot-down by anti-aircraft fire: flak bursts near the wing after its bombs, the
+ /// last on it at WingHitS; it then trails smoke and falls, away from its loop and lower, and is gone with a blast on the
+ /// ground; a fresh wing joins the loop at WingRejoinS. One kill a loop: the same again a loop later.</summary>
+ [Test]
+ public void AntiAircraftFireBringsTheWingDownOnceALoopAndAFreshWingJoins()
+ {
+ var map = OpenMap();
+ var layer = Drawn(map, July15);
+ var defence = layer.AirDefence!; var loops = Loops(layer);
+ var centre = layer.Placed.First(p => p.Model == SeaAirCollection.Dakota).At;
+ var ground = PlacementLayer.CampGround(map);
+ float lag = SeaAirCollection.DakotaTrailSeconds, period = SeaAirCollection.DakotaLoopSeconds;
+ foreach (var loopsOn in new[] { 0f, period })
+ {
+ float T(float u) => u + lag + loopsOn; // the clock for the wing's own time u
+ PlaceAll(loops, defence, T(SeaAirCollection.FlakAtS[0] - 1f));
+ Assert.IsFalse(defence.FlakRenderers.Any(r => r.enabled), "no flak before the first burst");
+ PlaceAll(loops, defence, T(SeaAirCollection.FlakAtS[0] + 0.5f));
+ Assert.IsTrue(defence.FlakRenderers.Any(r => r.enabled), "flak bursting near the wing");
+ Assert.IsTrue(defence.WingShown);
+ Assert.IsFalse(defence.TrailRenderers.Any(r => r.enabled), "no smoke trail before the hit");
+ // Falling: off its loop, lower, trailing smoke, still over the ground.
+ float last = centre.y;
+ for (int i = 1; i <= 10; i++)
+ {
+ float s = i * SeaAirCollection.WingFallS / 10.5f;
+ PlaceAll(loops, defence, T(SeaAirCollection.WingHitS + s));
+ Assert.IsTrue(defence.WingShown, $"drawn while it falls ({s:0.0} s)");
+ var at = defence.WingAt;
+ Assert.Less(at.y, last + 1f, $"lower and lower ({s:0.0} s)");
+ last = at.y;
+ Assert.Greater(at.y, ground.Y(at.x, at.z), $"over the ground until it comes down ({s:0.0} s)");
+ Assert.IsTrue(defence.TrailRenderers.Any(r => r.enabled), $"trailing smoke ({s:0.0} s)");
+ var onLoop = centre + new Vector3(SeaAirCollection.DakotaLoopOffset(SeaAirCollection.WingHitS + s).x, 0f, SeaAirCollection.DakotaLoopOffset(SeaAirCollection.WingHitS + s).y);
+ if (i >= 4) Assert.Greater((at - onLoop).magnitude, 1000f, $"out of the loop ({s:0.0} s)");
+ }
+ Assert.Less(last, centre.y - 0.5f * (centre.y - ground.Y(centre.x, centre.z)), "most of the way down");
+ PlaceAll(loops, defence, T(SeaAirCollection.WingHitS + SeaAirCollection.WingFallS + 0.3f));
+ Assert.IsFalse(defence.WingShown, "gone once down");
+ Assert.IsTrue(defence.CrashRenderer.enabled, "a blast where it comes down");
+ Assert.IsTrue(loops[1].GetComponentsInChildren<Renderer>(true).All(r => !r.enabled), "none of it drawn");
+ PlaceAll(loops, defence, T(SeaAirCollection.WingRejoinS - 1f));
+ Assert.IsFalse(defence.WingShown, "still gone just before the fresh wing joins");
+ PlaceAll(loops, defence, T(SeaAirCollection.WingRejoinS + 1f));
+ Assert.IsTrue(defence.WingShown, "a fresh wing on the loop");
+ Assert.IsTrue(loops[1].GetComponentsInChildren<Renderer>(true).All(r => r.enabled), "all of it drawn again");
+ var back = WorldBounds(loops[1].gameObject).center; var path = SeaAirCollection.DakotaLoopOffset(SeaAirCollection.WingRejoinS + 1f);
+ Assert.Less((new Vector2(back.x - centre.x, back.z - centre.z) - path).magnitude, 1f, "on its loop");
+ Assert.IsTrue(ground.Water(back.x, back.z), "joining out over the sea");
+ }
+ }
+
+ /// <summary>A frame of the whole raid allocates nothing: the Dakotas' loops and the air defence (fighters, gun, hits, flak,
+ /// the falling wing and its trail), over every part of the loop, after a warm-up.</summary>
+ [Test]
+ public void PlacingTheAirDefenceAllocatesNothingPerFrame()
+ {
+ var map = OpenMap();
+ var layer = Drawn(map, July15);
+ var defence = layer.AirDefence!; var loops = Loops(layer);
+ for (int i = 0; i < 400; i++) PlaceAll(loops, defence, i * 0.3f); // warm up, through every state
+ long before = GC.GetAllocatedBytesForCurrentThread();
+ for (int i = 0; i < 2000; i++) PlaceAll(loops, defence, i * 0.061f);
+ Assert.AreEqual(0, GC.GetAllocatedBytesForCurrentThread() - before, "no allocation per frame");
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/TelAvivAirDefenceTests.cs.meta b/unity/Assets/Tests/EditMode/TelAvivAirDefenceTests.cs.meta
new file mode 100644
index 000000000..b31268980
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/TelAvivAirDefenceTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 56625e98fefb46fcaf14ea5f3225df8f