A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Map: b21 workshop model at each built arms workshop, gdd-0.3 (#1701 slice F, stacked on #2270 and #2266) (#2281)
Eyal Golanee6c4e637973
diff --git a/changelog.d/1701-f-b21-workshop.md b/changelog.d/1701-f-b21-workshop.mdnew file mode 100644index 000000000..37f821fb2--- /dev/null+++ b/changelog.d/1701-f-b21-workshop.md@@ -0,0 +1,5 @@+- The arms workshop on the map (Refs #1701): under the gdd-0.3 ruleset, Tal Heuberger's artisan workshop model (b21)+ stands on the hex of each built arms workshop from the turn its build completes. It is placed clear of the towns, their+ names, the routes, the unit tokens and the other models; where a big town covers the whole hex (Jerusalem, Tel Aviv) it+ stands in a gap between the town's buildings. Like the other single buildings, it is drawn only at the close zoom. It+ streams in its own bundle after the first frame, as before. The current game (gdd-0.1) is unchanged.diff --git a/unity/Assets/Scripts/Map/Collection/HexPropModels.cs b/unity/Assets/Scripts/Map/Collection/HexPropModels.csindex ea30e0a1a..2963adca6 100644--- a/unity/Assets/Scripts/Map/Collection/HexPropModels.cs+++ b/unity/Assets/Scripts/Map/Collection/HexPropModels.cs@@ -227,6 +227,9 @@ namespace Statecraft.Game.Map.CollectionCollectionStream.Request(HexProps.Catalog, id, CollectionDetail.Near, done);MapScene? map; DateTime date; bool shown, requested;+ /// <summary>The b21 of each built arms workshop (#1701 slice F), kept clear of with the sourced buildings.</summary>+ IReadOnlyList<SpecialBuildingModels.Want> workshops = Array.Empty<SpecialBuildingModels.Want>();+ int ruralVersion;/// <summary>Whether a camera has come in to the close zoom: the standalone props are built only from then on (none of/// them draws further out, #2266 review).</summary>bool everClose;@@ -262,7 +265,16 @@ namespace Statecraft.Game.Map.Collection/// rest is the trees' pass; a test aid).</summary>public (long others, long search, long instances, long total) LastBuildMs { get; private set; }- public static HexPropModels? ShowAt(MapScene map, DateTime date)+ public static HexPropModels? ShowAt(MapScene map, DateTime date) => ShowAt(map, date, Array.Empty<SpecialBuildingModels.Want>());++ /// <summary>As <see cref="ShowAt(MapScene, DateTime)"/>, keeping clear of the b21 planned at each built arms workshop of the+ /// state too (SpecialBuildingModels.ArmsWorkshops; gdd-0.3 only, #1701 slice F).</summary>+ public static HexPropModels? ShowAt(MapScene map, DateTime date, Statecraft.Sim.Content content, IEnumerable<Statecraft.Sim.CityProject> projects) =>+ ShowAt(map, date, SpecialBuildingModels.ArmsWorkshops(content, projects));++ /// <summary>As <see cref="ShowAt(MapScene, DateTime)"/>, with <paramref name="workshops"/> (SpecialBuildingModels.ArmsWorkshops,+ /// computed once by the caller for both layers).</summary>+ internal static HexPropModels? ShowAt(MapScene map, DateTime date, IReadOnlyList<SpecialBuildingModels.Want> workshops){if (map == null || map.Terrain == null || map.Hexes == null) return null;var layer = map.Terrain.transform.Find(Name)?.GetComponent<HexPropModels>();@@ -271,10 +283,13 @@ namespace Statecraft.Game.Map.Collectionvar go = new GameObject(Name); go.transform.SetParent(map.Terrain.transform, false);layer = go.AddComponent<HexPropModels>(); layer.map = map;}- // GameRoot calls this on every refresh: rebuild only when the date changes (the dated stations and tokens follow it).- if (layer.shown && layer.date == date) return layer;+ // GameRoot calls this on every refresh: rebuild only when the date changes (the dated stations and tokens follow it),+ // the built arms workshops do, or the rural plan the props keep clear of does (RuralLife.VersionOf; the workshops' b21+ // rebuild on it too, so both stand on one plan).+ int rural = RuralLife.VersionOf(map);+ if (layer.shown && layer.date == date && SpecialBuildingModels.Same(layer.workshops, workshops) && layer.ruralVersion == rural) return layer;layer.fixedWants ??= FixedWants(map);- layer.shown = true; layer.date = date;+ layer.shown = true; layer.date = date; layer.workshops = workshops; layer.ruralVersion = rural;layer.wants = StationWants(map, date); layer.wants.AddRange(layer.fixedWants);layer.standaloneDirty = true; layer.BuildStandaloneIfDue(inRender: false);return layer;@@ -324,29 +339,24 @@ namespace Statecraft.Game.Map.Collection// ---- The keep-clear ground (#2266 review: planned, cached, indexed) ----- List<(Vector2 centre, float radius)>? ruralPlan; IReadOnlyList<RuralLife.Want>? ruralPlanWants; List<(Vector2, float)>? ruralPlanOthers;IReadOnlyList<(string Key, Vector2 Core, float Reach)>? seatsPlan; object? seatsPlanWants;/// <summary>The ground the other Collection layers hold or will hold, so no prop stands on them: the civilian figures/// and the wildlife (as RuralLife.OtherProps), and the rural scenes', special buildings' and whole-town models' PLANNED/// spots (their plans with every model available, which is also where each of them draws its streamed models), never/// what has streamed so far: the props stand in the same places whatever the camera has visited, and a scene or- /// building that streams in later never lands on one (#2266 review). The layers' own inputs are read when they are- /// shown (GameRoot shows them first); the date-independent plans are kept until their inputs change.</summary>+ /// building that streams in later never lands on one (#2266 review). The rural plan is the one RuralLife keeps for+ /// what it was last shown (RuralLife.PlanOf), the same one SpecialBuildingModels places the workshops' b21 against, so+ /// the props keep clear of the b21 that is drawn (#1701 slice F); the special buildings include the state's workshops.</summary>internal List<(Vector2 centre, float radius)> Others(MapScene map, DateTime date){- var otherProps = RuralLife.OtherProps(map);- var discs = new List<(Vector2 centre, float radius)>(otherProps);- var rural = map.Terrain.transform.Find(RuralLife.Name)?.GetComponent<RuralLife>();- IReadOnlyList<RuralLife.Want> rw = rural != null ? rural.Wanted : RuralLife.Wants(map);- var ro = rural != null && rural.OthersShown.Count > 0 ? rural.OthersShown : otherProps;- if (ruralPlan == null || !ReferenceEquals(rw, ruralPlanWants) && !rw.SequenceEqual(ruralPlanWants!) || !ro.SequenceEqual(ruralPlanOthers!))- {- ruralPlan = RuralLife.Plan(map, rw, ro, _ => true).Select(x => (x.spot, RuralLife.SceneRadiusM(x.want.Model))).ToList();- ruralPlanWants = rw; ruralPlanOthers = new List<(Vector2, float)>(ro);- }- discs.AddRange(ruralPlan);- foreach (var (w, at) in SpecialBuildingModels.Plan(map, date, SpecialBuildingModels.Placements(date), _ => true, log: false))+ var discs = new List<(Vector2 centre, float radius)>(RuralLife.OtherProps(map));+ var rural = RuralLife.PlanOf(map);+ foreach (var (want, spot) in rural) discs.Add((spot, RuralLife.SceneRadiusM(want.Model)));+ // With the b21 of each built arms workshop (#1701 slice F), after the sourced buildings as their layer orders them.+ var buildings = workshops.Count == 0 ? SpecialBuildingModels.Placements(date)+ : SpecialBuildingModels.Placements(date).Concat(workshops).ToList();+ foreach (var (w, at) in SpecialBuildingModels.Plan(map, date, buildings, _ => true, log: false, rural))discs.Add((at, SpecialBuildingModels.ClearanceOf(w.Model)));// The whole-town models (TownLandmarks, shown first by GameRoot) where they will stand, by the same plan.var towns = map.Terrain.transform.Find(TownLandmarks.Name)?.GetComponent<TownLandmarks>();diff --git a/unity/Assets/Scripts/Map/Collection/RuralLife.cs b/unity/Assets/Scripts/Map/Collection/RuralLife.csindex 54f45e3f6..abc96d845 100644--- a/unity/Assets/Scripts/Map/Collection/RuralLife.cs+++ b/unity/Assets/Scripts/Map/Collection/RuralLife.cs@@ -303,11 +303,44 @@ namespace Statecraft.Game.Map.Collection}List<(Vector2 centre, float radius)> others = new List<(Vector2, float)>();+ System.Collections.ObjectModel.ReadOnlyCollection<(Want want, Vector2 spot)>? fullPlan;+ bool everShown;+ int planVersion;++ /// <summary>#1701 slice F with #2266: the scenes' full plan (every model available) for what this layer was last shown,+ /// computed once per change of its wants or the ground it keeps clear of, read-only. It plans against exactly the+ /// layer's own inputs (<see cref="OthersShown"/>, never the map's current ground), the ones its own Rebuild plans+ /// against, so the scenes drawn and the ground the others keep clear of are one plan. Plan reads nothing else that+ /// changes on a map (its ground, routes and tokens are the map's build; no date). The other layers that keep clear of+ /// the scenes read it through <see cref="PlanOf"/> and rebuild when <see cref="VersionOf"/> moves.</summary>+ internal IReadOnlyList<(Want want, Vector2 spot)> FullPlan => fullPlan ??= Plan(map!, wants, others, _ => true).AsReadOnly();++ /// <summary>The rural plan the other layers keep clear of: the shown layer's <see cref="FullPlan"/>. Before a rural layer+ /// is shown (tests and editor tools; GameRoot shows it first), it is computed from the map's own wants and the other+ /// layers' current ground on each call: deterministic, not cached, and its version is 0.</summary>+ internal static IReadOnlyList<(Want want, Vector2 spot)> PlanOf(MapScene map)+ {+ var layer = Shown(map);+ return layer != null ? layer.FullPlan : Plan(map, Wants(map), OtherProps(map), _ => true);+ }++ /// <summary>A stamp of the plan <see cref="PlanOf"/> returns: it moves each time the shown layer's inputs change, so the+ /// layers built on the plan (SpecialBuildingModels' workshops, HexPropModels) rebuild together onto the new one.</summary>+ internal static int VersionOf(MapScene map) => Shown(map)?.planVersion ?? 0;++ static RuralLife? Shown(MapScene map)+ {+ var layer = map.Terrain != null ? map.Terrain.transform.Find(Name)?.GetComponent<RuralLife>() : null;+ return layer != null && layer.map != null && layer.everShown ? layer : null;+ }++ /// <summary>Shows exactly these wants and other layers' ground (a test seam, as Show(map) does with the map's own).</summary>+ internal void ShowForTest(List<Want> next, List<(Vector2 centre, float radius)> nextOthers) => Show(next, nextOthers);void Show(List<Want> next, List<(Vector2 centre, float radius)> nextOthers){- if (next.SequenceEqual(wants) && nextOthers.SequenceEqual(others)) return;- wants = next; others = nextOthers;+ if (everShown && next.SequenceEqual(wants) && nextOthers.SequenceEqual(others)) return;+ wants = next; others = nextOthers; fullPlan = null; everShown = true; planVersion++;OriginalModelRequests.WhenVisible(this, () =>{desiredDetails.Add(CollectionDetail.Far); desiredDetails.Add(CollectionDetail.Near);diff --git a/unity/Assets/Scripts/Map/Collection/SpecialBuildingModels.cs b/unity/Assets/Scripts/Map/Collection/SpecialBuildingModels.csindex f810130df..b133df28b 100644--- a/unity/Assets/Scripts/Map/Collection/SpecialBuildingModels.cs+++ b/unity/Assets/Scripts/Map/Collection/SpecialBuildingModels.cs@@ -9,7 +9,8 @@ namespace Statecraft.Game.Map.Collection{/// <summary>Issue #707: Tal Heuberger's single-building models at sourced places, and the tank stopped at Degania Alef. They use the collection stream after the/// first frame, draw only close up (#700's switch, TownModelLayer.CloseEnterM / CloseExitM), follow the game date and- /// fail open. b21 remains catalogued but unplaced until an artisan-workshop location is sourced.</summary>+ /// fail open. #1701 slice F (owner, 27 October 2026: "Arms workshops (Recommended)"): under gdd-0.3, b21 stands on the hex of+ /// each built arms workshop (<see cref="ArmsWorkshops"/>).</summary>[ExecuteAlways]public sealed class SpecialBuildingModels : MonoBehaviour{@@ -85,6 +86,31 @@ namespace Statecraft.Game.Map.Collectionpublic static IReadOnlyList<Want> Placements(DateTime date) => All.Where(x => date >= x.From).ToList();+ /// <summary>#1701 slice F: one b21 per built arms workshop (R-ARMS-004, Workshops.ArmsWorkshop), on its city project's+ /// hex from the day the build completed (CityProject.BuiltOn), in ascending project id. Under gdd-0.3 only; nothing for a+ /// project still being built, nor for one no longer in the state.</summary>+ public static IReadOnlyList<Want> ArmsWorkshops(Statecraft.Sim.Content content, IEnumerable<Statecraft.Sim.CityProject> projects)+ {+ var list = new List<Want>();+ if (content.Ruleset != Statecraft.Sim.SaveGame.Gdd03Ruleset) return list;+ foreach (var p in projects.OrderBy(x => x.Id))+ {+ if (p.Kind != Statecraft.Sim.Workshops.ArmsWorkshop || !(p.BuiltOn is DateTime on)) continue;+ var hex = content.HexAt(p.Q, p.R);+ if (hex == null) continue;+ list.Add(new Want(WorkshopKey(p.Id), Workshop, on, hex.Lon, hex.Lat,+ FormattableString.Invariant($"city project {p.Id}: {p.City}'s arms workshop on hex {p.Q},{p.R}")));+ }+ return list;+ }++ /// <summary>The layer key (and instance name) of the b21 standing for city project <paramref name="project"/>.</summary>+ public static string WorkshopKey(int project) => FormattableString.Invariant($"arms_workshop_{project}");++ /// <summary>How far from its hex's centre a workshop's model may reach (m): the hex's inner radius (HexScale.HexM is the+ /// circumradius), so the whole model stands on the project's own hex.</summary>+ public const float HexInnerRadiusM = 0.8660254f * Statecraft.HexTiles.HexScale.HexM;+/// <summary>How far inside a town's footprint <paramref name="anchor"/> lies (m, 0 outside every footprint): a sourced/// point at a town's edge (Netanya's entrance) is inside the kit's symbolic footprint, so the search starts that far/// out.</summary>@@ -248,6 +274,7 @@ namespace Statecraft.Game.Map.Collection}originals.Remove(key.id);Placed.RemoveAll(p => p.Model == key.id);+ if (key.id == Workshop) workshopBoxes = new List<Bounds[]>(); // a new list: the retired b21 leave the labels too}return removed;}@@ -264,7 +291,7 @@ namespace Statecraft.Game.Map.Collectionvar 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);}- renderers.Clear(); Placed.Clear();+ renderers.Clear(); Placed.Clear(); workshopBoxes = new List<Bounds[]>();originals.Clear();if (map != null) Statecraft.Game.Map.Units.UnitShowcase.HideTrees(map, Name, Array.Empty<(Vector2, float)>());}@@ -294,12 +321,42 @@ namespace Statecraft.Game.Map.Collectionvoid OnDestroy() { residency?.Dispose(); residency = null; }MapScene? map; DateTime date; bool shown;+ IReadOnlyList<Want> workshops = Array.Empty<Want>();+ int ruralVersion;++ internal static bool Same(IReadOnlyList<Want> a, IReadOnlyList<Want> b)+ {+ if (a.Count != b.Count) return false;+ for (int i = 0; i < a.Count; i++)+ if (a[i].Key != b[i].Key || a[i].From != b[i].From || a[i].Lon != b[i].Lon || a[i].Lat != b[i].Lat) return false;+ return true;+ }public readonly List<(string Key, string Model, Vector3 At)> Placed = new List<(string, string, Vector3)>();+ List<Bounds[]> workshopBoxes = new List<Bounds[]>();++ /// <summary>Review of #2281 (option 3, coordinator 3 November 2026): the drawn b21s' world boxes while they are drawn (the+ /// close zoom), for the name pills to keep clear of. GameRoot passes them to MapLabelsPresenter's keepClear with the+ /// units' and the craft's; a new list each rebuild, so the labels refresh when it changes.</summary>+ public IReadOnlyList<Bounds[]> KeepClear => isActiveAndEnabled && LastClose ? workshopBoxes : (IReadOnlyList<Bounds[]>)Array.Empty<Bounds[]>();++ /// <summary>As <see cref="KeepClear"/> for <paramref name="camera"/>: whether that camera last drew the b21 (its own+ /// close-zoom switch), not whichever camera rendered last (review of #2281, S4).</summary>+ public IReadOnlyList<Bounds[]> KeepClearFor(Camera camera) =>+ isActiveAndEnabled && closeFor.TryGetValue(camera.GetInstanceID(), out var close) && close ? workshopBoxes : (IReadOnlyList<Bounds[]>)Array.Empty<Bounds[]>();public bool FailedOpen { get; private set; }public bool LastClose { get; private set; }readonly Dictionary<string, List<GameObject>> originals = new Dictionary<string, List<GameObject>>(StringComparer.Ordinal);- public static SpecialBuildingModels? ShowAt(MapScene map, DateTime date)+ public static SpecialBuildingModels? ShowAt(MapScene map, DateTime date) => ShowAt(map, date, Array.Empty<Want>());++ /// <summary>As <see cref="ShowAt(MapScene, DateTime)"/>, with a b21 at each built arms workshop of the state+ /// (<see cref="ArmsWorkshops"/>; gdd-0.3 only).</summary>+ public static SpecialBuildingModels? ShowAt(MapScene map, DateTime date, Statecraft.Sim.Content content,+ IEnumerable<Statecraft.Sim.CityProject> projects) => ShowAt(map, date, ArmsWorkshops(content, projects));++ /// <summary>As <see cref="ShowAt(MapScene, DateTime)"/>, with <paramref name="workshops"/> (<see cref="ArmsWorkshops"/>,+ /// computed once by the caller for this layer and HexPropModels).</summary>+ internal static SpecialBuildingModels? ShowAt(MapScene map, DateTime date, IReadOnlyList<Want> workshops){if (map == null || map.Terrain == null || map.Hexes == null) return null;var layer = map.Terrain.transform.Find(Name)?.GetComponent<SpecialBuildingModels>();@@ -310,9 +367,13 @@ namespace Statecraft.Game.Map.Collection}if (layer.residencyView == null) layer.ConfigureResidency(map.Residency.Special, null);// GameRoot calls this on every refresh: rebuild only when the game date changes (the dated list and the dated- // tokens' clearance both follow it).- if (layer.shown && layer.date == date) return layer;- layer.shown = true; layer.date = date; layer.Show(Placements(date)); return layer;+ // tokens' clearance both follow it), the built arms workshops do (one completed, or one left the state), or, with+ // workshops, the rural plan they keep clear of (RuralLife.VersionOf: HexPropModels rebuilds on it too, so the props+ // keep clear of the b21 drawn).+ int rural = workshops.Count == 0 ? 0 : RuralLife.VersionOf(map);+ if (layer.shown && layer.date == date && Same(layer.workshops, workshops) && layer.ruralVersion == rural) return layer;+ layer.shown = true; layer.date = date; layer.workshops = workshops; layer.ruralVersion = rural;+ layer.Show(workshops.Count == 0 ? Placements(date) : Placements(date).Concat(workshops).ToList()); return layer;}internal void ShowForTest(IReadOnlyList<Want> wants) => Show(wants);@@ -326,11 +387,12 @@ namespace Statecraft.Game.Map.CollectionRebuild();}- /// <summary>Where the buildings stand: each want in order, of the models <paramref name="available"/> holds, at its- /// route-facing (Degania) or seeded spot, clear of the towns, the routes, the tokens of <paramref name="date"/>, the- /// civilians, the wildlife and each other. It reads only the map and the date, never what has streamed, so with every+ /// <summary>Where the buildings stand: each want in order at its route-facing (Degania) or seeded spot, clear of the towns,+ /// the routes, the tokens of <paramref name="date"/>, the civilians, the wildlife and each other (a workshop also of its+ /// hex's edge and the farm scenes' plan); the list keeps those whose model <paramref name="available"/> holds. It reads only the map and the date, never what has streamed, so with every/// model available it is the plan the layer draws once everything has arrived (HexPropModels keeps clear of it, #2266).</summary>- internal static List<(Want want, Vector2 at)> Plan(MapScene map, DateTime date, IReadOnlyList<Want> wants, Func<string, bool> available, bool log)+ internal static List<(Want want, Vector2 at)> Plan(MapScene map, DateTime date, IReadOnlyList<Want> wants, Func<string, bool> available, bool log,+ IReadOnlyList<(RuralLife.Want want, Vector2 spot)>? ruralPlan = null){var ground = PlacementLayer.CampGround(map);var footprints = map.KitFootprints.Select(f => (f.centre, f.radius)).ToList();@@ -339,14 +401,23 @@ namespace Statecraft.Game.Map.Collectionvar people = map.Terrain.transform.Find(CivilianPeople.Name)?.GetComponent<CivilianPeople>();if (people != null) foreach (var p in people.Wanted) taken.Add((new Vector2(p.At.x, p.At.z), CivilianPeople.FigureClearanceM));foreach (var a in WildlifeLayer.Wants(map)) taken.Add((a.At, 0.5f * WildlifeLayer.SizeM));- bool Free(Vector2 p, float r) => TownLandmarks.Clear(p, r, taken) && TownLandmarks.Clear(p, r, footprints)+ // A workshop (#1701 slice F) also keeps off the farm scenes (#667): where they WILL stand (RuralLife's plan with every+ // model available, RuralLife.PlanOf, the one HexPropModels.Others reads too), never what has streamed so far, so its+ // spot is the same whichever layer streams first and the props keep clear of the b21 that is drawn.+ var farms = new List<(Vector2 centre, float radius)>();+ if (wants.Any(w => w.Model == Workshop))+ foreach (var (want, spot) in ruralPlan ?? RuralLife.PlanOf(map))+ farms.Add((spot, RuralLife.SceneRadiusM(want.Model)));+ bool FreeOn(Vector2 p, float r, DateTime on) => TownLandmarks.Clear(p, r, taken) && TownLandmarks.Clear(p, r, footprints)&& ground.Inside(p.x - r, p.y - r) && ground.Inside(p.x + r, p.y + r)- && !ground.Water(p.x, p.y) && !ground.OnRoute(p, r) && !ground.OnToken(p, r, date);+ && !ground.Water(p.x, p.y) && !ground.OnRoute(p, r) && !ground.OnToken(p, r, on);+ bool Free(Vector2 p, float r) => FreeOn(p, r, date);var plan = new List<(Want, Vector2)>();var kits = map.transform.Find(Kits.KitLayer.RootName);foreach (var w in wants){- if (!available(w.Model)) continue;+ // Every want takes its ground whether or not its model has streamed (only the plan's output is filtered), so a+ // later want's spot, a workshop's included, never depends on what streamed first.var anchor3 = map.Frame.ToWorld(w.Lon, w.Lat, 0); var anchor = new Vector2(anchor3.x, anchor3.z);float clearance = ClearanceOf(w.Model);Vector2? at = null;@@ -357,19 +428,165 @@ namespace Statecraft.Game.Map.Collectionif (village is Bounds drawn && footprint.id != null) // no kit or no footprint: the seeded spot belowat = RouteFacingEdgeSpot(footprint.centre, drawn, clearance, map.KitRouteCorridors, Free);}- if (at == null)+ if (at == null && w.Model == Workshop){- if (w.Key == "degania_r35" && log)+ // On the project's own hex (its centre is the anchor), clear of the farm scenes, and as far out of a town's+ // footprint as the civilian figures keep from its label (CivilianPeople.LabelClearanceM). The units' tokens and+ // figures are those of the map's planned unit spots (MapScene.UnitClearings and UnitTokens, built with the map+ // from units_1948, not the units' live places) on the day the workshop was built (w.From), so its spot does not+ // move as the game's date passes a token's last day (review of #2281, S2).+ var built = w.From;+ bool OnHex(Vector2 p, float r) => (p - anchor).magnitude + r <= HexInnerRadiusM && TownLandmarks.Clear(p, r, farms)+ && ClearOfFigures(map, p, r, built) && FreeOn(p, r, built);+ float inside = Inside(anchor, footprints);+ at = SeededSpot(w.Key, anchor, clearance, OnHex, inside > 0f ? inside + CivilianPeople.LabelClearanceM : 0f);+ // A town whose footprint covers the whole hex (Jerusalem, Tel Aviv): a gap between its drawn buildings (owner,+ // 2 November 2026: "Among the houses").+ if (at == null && inside > 0f) at = TownGap(map, w.Key, anchor, clearance, (p, r) =>+ (p - anchor).magnitude + r <= HexInnerRadiusM && TownLandmarks.Clear(p, r, farms) && TownLandmarks.Clear(p, r, taken)+ && ClearOfFigures(map, p, r, built)+ && ground.Inside(p.x - r, p.y - r) && ground.Inside(p.x + r, p.y + r)+ && !ground.Water(p.x, p.y) && !ground.OnRoute(p, r) && !ground.OnToken(p, r, built));+ }+ else if (at == null)+ {+ if (w.Key == "degania_r35" && log && available(w.Model))Debug.LogWarning("BUILDINGS: route-facing spot unavailable for degania_r35; falling back to the seeded spot.");at = SeededSpot(w.Key, anchor, clearance, Free, Inside(anchor, footprints));}- if (at == null) { if (log) Debug.LogWarning($"BUILDINGS: no clear ground near {w.Key}; its {w.Model} is not drawn."); continue; }+ if (at == null) { if (log && available(w.Model)) Debug.LogWarning($"BUILDINGS: no clear ground near {w.Key}; its {w.Model} is not drawn."); continue; }taken.Add((at.Value, clearance));- plan.Add((w, at.Value));+ if (available(w.Model)) plan.Add((w, at.Value));}return plan;}+ /// <summary>The ground (m) a place's name pill can take, a workshop among a town's houses keeping off it: the band from the+ /// footprint's south edge to <see cref="TownLabelHeightM"/> past its north edge, <see cref="TownLabelHalfWidthM"/> either+ /// side of its centre. It models MapLabelsPresenter's Above spots (centred, or starting at the kit's centre to either+ /// side, as far as the half width reaches); a pill pushed Beside or Below its kit is not modelled, and the on-screen+ /// checks (MapLabelTests.NoNamePillCoversAWorkshopModel*) take the zooms and framings a player sees.+ /// Design values: a long locality pill is about 141 by 23 px at a 1280 px frame, some 18 m a pixel at the 30 km zoom+ /// and 27 m at the close zoom's 45 km exit, with the lift above the kit and a margin.</summary>+ public const float TownLabelHalfWidthM = 2000f, TownLabelHeightM = 1000f;++ /// <summary>Whether a disc of <paramref name="r"/> at <paramref name="p"/> keeps clear of the name pill of the place whose+ /// footprint is centred at <paramref name="centre"/> with <paramref name="radius"/>.</summary>+ public static bool ClearOfName(Vector2 p, float r, Vector2 centre, float radius) =>+ Mathf.Abs(p.x - centre.x) >= TownLabelHalfWidthM + r+ || p.y - centre.y <= -radius - r || p.y - centre.y >= radius + TownLabelHeightM + r;++ /// <summary>How far north on the ground a unit's figures hide what stands behind them (m): their height,+ /// UnitBadge.FigureHeightM times UnitShowcase.FigureScale (as UnitLayer sizes them, UnitLayer.cs:764), seen at the view's+ /// shallowest ray, CameraRig.Pitch - Fov/2, so height times cot(Pitch - Fov/2). (The flag's thin pole stands higher; keeping clear of its full height and+ /// its cloth's reach leaves Jerusalem's hex no ground, and ArmsWorkshopVisibilityTests checks the drawn tokens, flags+ /// included.)</summary>+ public static float FigureShadowM => Units.UnitBadge.FigureHeightM * Units.UnitShowcase.FigureScale+ / Mathf.Tan((CameraRig.Pitch - 0.5f * CameraRig.Fov) * Mathf.Deg2Rad);+ // The framing (review of #2281, S1): CameraRig turns the camera Euler(Pitch, Yaw, 0) (CameraRig.cs:72), so Pitch is the+ // view's depression below the horizon, exact on the screen's centre row; rows above it look down at less, to+ // Pitch - Fov/2 at the top edge, where a figure hides the most ground. The bound takes that shallowest ray: 2.49 km x+ // cot(32.5 deg) = 3.91 km (2.09 km at the centre row's 50 deg). The yaw is 0 under gdd-0.3, the only ruleset with+ // workshops (CameraHeadingPolicy.cs:6, fixed north), and FigureScale does not change with the zoom (UnitLayer.cs:738-768).++ /// <summary>Review of #2281 (the Jerusalem b21 hidden behind a garrison's figures): whether a model of clearance+ /// <paramref name="r"/> at <paramref name="p"/> stands clear of the ground a unit spot's figures hide in the map's oblique+ /// view: north of the spot (the camera looks north, CameraRig yaw 0), within the spot's disc either side, as far as+ /// <see cref="FigureShadowM"/> past it. The spots: the units' town clearings (MapScene.UnitClearings) and their rings+ /// out of town (MapScene.UnitTokens, while their dates last), the planned ground the figures stand on.</summary>+ public static bool ClearOfFigures(MapScene map, Vector2 p, float r, DateTime on)+ {+ foreach (var (c, radius) in map.UnitClearings) if (Hidden(p, r, c, radius)) return false;+ foreach (var (c, radius, until) in map.UnitTokens) if (until > on && Hidden(p, r, c, radius)) return false; // as KitGround.OnToken+ return true;+ }++ /// <summary>Whether a disc of <paramref name="r"/> at <paramref name="p"/> is on the ground the figures of a unit spot at+ /// <paramref name="c"/> (its disc <paramref name="radius"/>) hide: within the disc either side, from its south edge to+ /// <see cref="FigureShadowM"/> past its north edge.</summary>+ public static bool Hidden(Vector2 p, float r, Vector2 c, float radius) =>+ Mathf.Abs(p.x - c.x) < radius + r && p.y + r > c.y - radius && p.y - r < c.y + radius + FigureShadowM;++ /// <summary>Whether a disc of <paramref name="r"/> at <paramref name="p"/> keeps clear of the box centred at <paramref name="c"/>,+ /// turned <paramref name="yawDeg"/> anticlockwise in x-z (KitMesh.Corners), <paramref name="w"/> along its turn and+ /// <paramref name="d"/> across.</summary>+ public static bool ClearOfBox(Vector2 p, float r, Vector2 c, float yawDeg, float w, float d)+ {+ float a = yawDeg * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);+ var q = p - c; float u = q.x * ca + q.y * sa, v = -q.x * sa + q.y * ca;+ float du = Mathf.Max(0f, Mathf.Abs(u) - 0.5f * w), dv = Mathf.Max(0f, Mathf.Abs(v) - 0.5f * d);+ return du * du + dv * dv >= r * r;+ }++ /// <summary>Review of #2281: what else the kits drew on the hex about <paramref name="anchor"/>, which no house stands on by+ /// design: the walls, platforms, landmarks, harbour works and street palms the kits placed and each landmark's close copy+ /// (KitLayer.Stats.Landmarks), and the replaceable landmark parts' close boxes (KitLayer.Stats.LandmarkParts, #2266). All+ /// planned at map build.</summary>+ internal static List<(Vector2 c, float yaw, float w, float d)> TownLandmarkBoxes(MapScene map, Vector2 anchor)+ {+ var boxes = new List<(Vector2 c, float yaw, float w, float d)>();+ var stats = map.KitStats;+ if (stats == null) return boxes;+ foreach (var p in stats.Landmarks)+ if ((p.C - anchor).magnitude <= HexInnerRadiusM + 0.5f * (p.W + p.D)) boxes.Add((p.C, p.Yaw, p.W, p.D));+ foreach (var part in stats.LandmarkParts)+ {+ var c = new Vector2(part.Near.center.x, part.Near.center.z);+ if ((c - anchor).magnitude <= HexInnerRadiusM + 0.5f * (part.Near.size.x + part.Near.size.z)) boxes.Add((c, 0f, part.Near.size.x, part.Near.size.z));+ }+ return boxes;+ }++ /// <summary>The drawn buildings on the hex about <paramref name="anchor"/>: each town model instance the kit planned at+ /// map build (TownModelLayer.InstancesOf; never what has streamed) for every footprint that reaches the hex, as a disc of+ /// its half diagonal; <paramref name="names"/>: those footprints (their names stand above them).</summary>+ internal static List<(Vector2 centre, float radius)> TownBuildings(MapScene map, Vector2 anchor, out List<(Vector2 centre, float radius)> names)+ {+ var discs = new List<(Vector2 centre, float radius)>(); names = new List<(Vector2 centre, float radius)>();+ var layer = map.GetComponentInChildren<Kits.TownModelLayer>(true);+ foreach (var f in map.KitFootprints)+ {+ if ((anchor - f.centre).magnitude >= f.radius + HexInnerRadiusM) continue;+ names.Add((f.centre, f.radius));+ if (layer == null) continue;+ foreach (var b in layer.InstancesOf(f.id)) discs.Add((b.C, 0.5f * Mathf.Sqrt(b.W * b.W + b.D * b.D)));+ }+ return discs;+ }++ /// <summary>#1701 slice F, owner 2 November 2026 ("Among the houses"): a workshop on a hex a town's footprint covers stands+ /// in a gap between the drawn buildings on the hex (<see cref="TownBuildings"/>), off the kits' walls, platforms and+ /// landmarks (<see cref="TownLandmarkBoxes"/>), clear of every name there+ /// (<see cref="ClearOfName"/>) and <paramref name="free"/> (the hex, the routes, the tokens, the other models). A fixed search: rings+ /// half a clearance apart outward from the hex centre, each from an FNV-1a bearing of the key. Null when no gap is+ /// clear.</summary>+ internal static Vector2? TownGap(MapScene map, string key, Vector2 anchor, float clearance, Func<Vector2, float, bool> free)+ {+ var houses = TownBuildings(map, anchor, out var names);+ var landmarks = TownLandmarkBoxes(map, anchor);+ uint h = 2166136261;+ foreach (char c in key) { h ^= c; h *= 16777619; }+ float step = 0.5f * clearance;+ for (float radius = 0f; radius + clearance <= HexInnerRadiusM; radius += step)+ {+ int n = radius == 0f ? 1 : Mathf.Max(6, Mathf.CeilToInt(2f * Mathf.PI * radius / step));+ int start = (int)(h % (uint)n);+ for (int i = 0; i < n; i++)+ {+ float angle = 2f * Mathf.PI * ((start + i) % n) / n;+ var p = anchor + new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * radius;+ bool named = false;+ foreach (var (c, fr) in names) if (!ClearOfName(p, clearance, c, fr)) { named = true; break; }+ if (named || !TownLandmarks.Clear(p, clearance, houses)) continue;+ bool onLandmark = false;+ foreach (var (bc, yaw, bw, bd) in landmarks) if (!ClearOfBox(p, clearance, bc, yaw, bw, bd)) { onLandmark = true; break; }+ if (onLandmark || !free(p, clearance)) continue;+ return p;+ }+ }+ return null;+ }+void Rebuild(){CollectionResidencyMetrics.MarkDirty();@@ -377,6 +594,7 @@ namespace Statecraft.Game.Map.CollectionClearVisuals();var ground = PlacementLayer.CampGround(map);var holes = new List<(Vector2 centre, float radius)>();+ var boxes = new List<Bounds[]>();foreach (var (w, spot) in Plan(map, date, wants, m => prefabs.TryGetValue(m, out var p) && p != null, log: true)){var prefab = prefabs[w.Model]!;@@ -393,7 +611,10 @@ namespace Statecraft.Game.Map.Collectiongo.transform.position += new Vector3(pos.x - b.center.x, pos.y - b.min.y, pos.z - b.center.z);foreach (var r in go.GetComponentsInChildren<Renderer>(true)) { r.shadowCastingMode = ShadowCastingMode.On; r.forceRenderingOff = !LastClose; renderers.Add(r); }Placed.Add((w.Key, w.Model, pos));+ if (w.Model == Workshop) boxes.Add(new[] { Bounds(go) });}+ // Published once, whole (review of #2281, M1): a list handed to the labels is never changed after.+ workshopBoxes = boxes;// No kit tree stands on a building: the trees whose crowns reach its ground are left out at draw time, as under// the unit figures (Kits.VegetationLayer.Hide).Units.UnitShowcase.HideTrees(map, Name, holes);diff --git a/unity/Assets/Scripts/Map/Kits/KitLayer.cs b/unity/Assets/Scripts/Map/Kits/KitLayer.csindex 25f20a08a..b55b0128a 100644--- a/unity/Assets/Scripts/Map/Kits/KitLayer.cs+++ b/unity/Assets/Scripts/Map/Kits/KitLayer.cs@@ -40,6 +40,10 @@ namespace Statecraft.Game.Map.Kits/// kit and close renderers that draw it as their submesh 1 (the code-built fallback), its yaw and its boxes far off and/// up close.</summary>public IReadOnlyList<LandmarkPart> LandmarkParts = System.Array.Empty<LandmarkPart>();+ /// <summary>#1701 slice F: everything the kits placed that is not a building (walls, platforms, landmarks, harbour+ /// works, street palms: SettlementKits.Placed, its yaw as KitMesh.Corners), then each landmark's close copy as its+ /// world box (yaw 0), so a model placed among a town's houses (SpecialBuildingModels.TownGap) keeps off them.</summary>+ public IReadOnlyList<SettlementKits.Placed> Landmarks = System.Array.Empty<SettlementKits.Placed>();public override string ToString() =>$"KITS buildings={Buildings} vertices={Vertices} triangles={Triangles} trees={Trees} route_segments={CorridorSegments} build_ms={BuildMs:0} plant_ms={PlantMs:0} " +$"localities={Localities} locality_buildings={LocalityBuildings} camps={Camps} tents={Tents} boats={Boats} draws={Draws} models={Models} close_vertices={CloseVertices}";@@ -147,6 +151,10 @@ namespace Statecraft.Game.Map.Kitstowns.ConfigureProduction(residency.Towns);towns.Init(built.Models, townModels, swaps, nearTowns, rendererTownIds, rendererTileIds);stats.LandmarkParts = parts;+ var landmarks = new List<SettlementKits.Placed>();+ foreach (var p in placed) if (p.Kind != "building" && p.Kind != "wing") landmarks.Add(p);+ foreach (var p in built.CloseLandmarks) landmarks.Add(new SettlementKits.Placed(p.Id, p.Kind, p.C, 0f, p.W, p.D, p.H, p.Wall, p.Y));+ stats.Landmarks = landmarks;var localityIds = new HashSet<string>(System.StringComparer.Ordinal);foreach (var locality in localities) localityIds.Add(locality.Id);towns.ConfigureTownFootprints(stats.Footprints, localityIds);diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex 3dd0f01e3..ab9b5c596 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -531,19 +531,10 @@ namespace Statecraft.Game.UIlabels = Own(new MapLabelsPresenter(root, map, labelCamera, null,p => MapLabelsPresenter.TipOf(p, n => text.Format("map.today", n), text["map.mixed"], hebrew),() => // the names keep clear of the unit tokens (issue #197), their badges and flags as this camera will draw them,- { // and of the 1948 Collection's ships and C-54 (#669)+ { // of the 1948 Collection's ships and C-54 (#669), and of the arms workshops' b21 (#1701 slice F)IReadOnlyList<Bounds[]>? tokens = null;if (unitLayer != null) { unitLayer.FaceCamera(labelCamera); tokens = unitLayer.KeepClear; }- var craft = seaAir != null ? seaAir.KeepClear : null;- if (craft == null || craft.Count == 0) return tokens;- if (tokens == null || tokens.Count == 0) return craft;- // One merged list per pair of lists, so the labels see a new list only when either changes (they refresh then).- if (!ReferenceEquals(tokens, keptTokens) || !ReferenceEquals(craft, keptCraft))- {- keptTokens = tokens; keptCraft = craft;- var merged = new List<Bounds[]>(tokens); merged.AddRange(craft); keptBoth = merged;- }- return keptBoth;+ return keepClear.Merge(tokens, seaAir != null ? seaAir.KeepClear : null, special != null ? special.KeepClearFor(labelCamera) : null);},// Issue #710: the static 1948 tier from cities.yaml's people, not the sim's live count (owner, 15 October 2026).bridge.Content.Cities.Where(c => c.People != null).ToDictionary(c => c.Id, c => c.People!.Value),@@ -961,7 +952,33 @@ namespace Statecraft.Game.UI/// differs from what was drawn (every order and every turn raises Changed; rebuilding the markers each time would be/// wasted work). A project finishing redraws though State.Placements did not change.</summary>Statecraft.Game.Map.Collection.SeaAirCollection? seaAir; // the 1948 Collection's craft (#669), for the labels to keep clear of- IReadOnlyList<Bounds[]>? keptTokens, keptCraft, keptBoth;+ readonly KeepClearLists keepClear = new KeepClearLists();++ /// <summary>The names' keep-clear boxes (MapLabelsPresenter's keepClear): the unit tokens', the 1948 Collection's craft+ /// (#669) and the arms workshops' b21 (#1701 slice F). One list when only one has boxes; else one merged list, kept+ /// until one of them is a new list, so the labels see a new list (and refresh) exactly when one changes. The layers+ /// publish a new list on every change, never changing one already handed out.</summary>+ internal sealed class KeepClearLists+ {+ IReadOnlyList<Bounds[]>? keptTokens, keptCraft, keptWorkshops, kept;++ public IReadOnlyList<Bounds[]>? Merge(IReadOnlyList<Bounds[]>? tokens, IReadOnlyList<Bounds[]>? craft, IReadOnlyList<Bounds[]>? workshops)+ {+ bool t = tokens != null && tokens.Count > 0, c = craft != null && craft.Count > 0, w = workshops != null && workshops.Count > 0;+ if ((t ? 1 : 0) + (c ? 1 : 0) + (w ? 1 : 0) <= 1) return c ? craft : w ? workshops : tokens;+ if (kept == null || !ReferenceEquals(tokens, keptTokens) || !ReferenceEquals(craft, keptCraft) || !ReferenceEquals(workshops, keptWorkshops))+ {+ keptTokens = tokens; keptCraft = craft; keptWorkshops = workshops;+ var merged = new List<Bounds[]>();+ if (t) merged.AddRange(tokens!);+ if (c) merged.AddRange(craft!);+ if (w) merged.AddRange(workshops!);+ kept = merged;+ }+ return kept;+ }+ }+ Statecraft.Game.Map.Collection.SpecialBuildingModels? special; // the arms workshops' b21, for the labels to keep clear ofvoid RenderPlacementsIfChanged(){@@ -987,13 +1004,15 @@ namespace Statecraft.Game.UIBridge.State.Settlements, Bridge.State.CityProjects.Values);// Tal Heuberger's period-generic farm and village scenery, streamed after the first frame (#667); never game units.Statecraft.Game.Map.Collection.RuralLife.Show(map);- // Tal Heuberger's Tegart fort, barracks and factory at their sourced places and dates, close up only, streamed (#707).- Statecraft.Game.Map.Collection.SpecialBuildingModels.ShowAt(map, Bridge.State.Date);- // Tal Heuberger's hex-tile props (owner, 27 October 2026: "2+3"; 2 November 2026: "Every zoom" for the landmarks): his+ // Tal Heuberger's Tegart fort, barracks and factory at their sourced places and dates, close up only, streamed (#707);+ // under gdd-0.3 their artisan workshop (b21) on each built arms workshop's hex (#1701 slice F).+ var workshops = Statecraft.Game.Map.Collection.SpecialBuildingModels.ArmsWorkshops(Bridge.Content, Bridge.State.CityProjects.Values);+ special = Statecraft.Game.Map.Collection.SpecialBuildingModels.ShowAt(map, Bridge.State.Date, workshops);+ // Tal Heuberger's hex-tile props (owner, 27 October 2026: "2+3"; 2 November 2026: "Every zoom" for the landmarks): their// minarets, belfries and Jaffa's clock tower in place of the kit's at every zoom, so the bundle streams after the first// frame; the stations, camp tents, village hedges and hill scatter close up only, built at the first close camera.- // After the layers they keep clear of.- Statecraft.Game.Map.Collection.HexPropModels.ShowAt(map, Bridge.State.Date);+ // After the layers they keep clear of (the built arms workshops' b21 too, #1701 slice F).+ Statecraft.Game.Map.Collection.HexPropModels.ShowAt(map, Bridge.State.Date, workshops);// Tal Heuberger's ships off Haifa, Jaffa, Acre and (on the Altalena's turn) Tel Aviv, and the C-54 at Lod, streamed after the first frame (#669).seaAir = Statecraft.Game.Map.Collection.SeaAirCollection.ShowAt(map, Bridge.State.Date, Bridge.State.Placements, Bridge.Content);RenderSitesIfChanged();diff --git a/unity/Assets/Tests/EditMode/ArmsWorkshopVisibilityTests.cs b/unity/Assets/Tests/EditMode/ArmsWorkshopVisibilityTests.csnew file mode 100644index 000000000..ad7dd4952--- /dev/null+++ b/unity/Assets/Tests/EditMode/ArmsWorkshopVisibilityTests.cs@@ -0,0 +1,169 @@+#nullable enable+using System;+using System.Collections;+using System.IO;+using System.Collections.Generic;+using System.Linq;+using NUnit.Framework;+using Statecraft.Game.Map;+using Statecraft.Game.Map.Collection;+using Statecraft.Game.UI;+using Statecraft.Sim;+using UnityEditor.SceneManagement;+using UnityEngine;+using UnityEngine.TestTools;+using UnityEngine.UIElements;+using Object = UnityEngine.Object;++/// <summary>Review of #2281 (coordinator, 3 November 2026: the workshop must be VISIBLE): in a gdd-0.3 game, a b21 built on a+/// city's own hex is not hidden behind a unit's figures in the map's oblique view. The camera frames the b21 from 9 km, as the+/// PR's stills do; no unit renderer nearer the camera covers half or more of the b21's screen rectangle. The figures are the+/// ones GameRoot draws for the game's units (UnitLayer), not a model of them.</summary>+public class ArmsWorkshopVisibilityTests+{+ string saveDir = "";+ RenderTexture? rt; PanelSettings? ps;+ Action<string, CollectionDetail, Action<GameObject?>>? savedSpecial;++ [SetUp]+ public void Prepare()+ {+ saveDir = Path.Combine(Path.GetTempPath(), "statecraft-b21-visible-" + Guid.NewGuid().ToString("N"));+ savedSpecial = SpecialBuildingModels.Request;+ }++ [TearDown]+ public void Discard()+ {+ SpecialBuildingModels.Request = savedSpecial!;+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);+ if (ps != null) Object.DestroyImmediate(ps);+ if (rt != null) { rt.Release(); Object.DestroyImmediate(rt); }+ if (Directory.Exists(saveDir)) Directory.Delete(saveDir, true);+ }++ static Rect ScreenRect(Camera cam, Bounds b)+ {+ float x0 = float.MaxValue, y0 = float.MaxValue, x1 = float.MinValue, y1 = float.MinValue;+ for (int c = 0; c < 8; c++)+ {+ var corner = new Vector3((c & 1) == 0 ? b.min.x : b.max.x, (c & 2) == 0 ? b.min.y : b.max.y, (c & 4) == 0 ? b.min.z : b.max.z);+ var q = cam.WorldToScreenPoint(corner);+ x0 = Mathf.Min(x0, q.x); y0 = Mathf.Min(y0, q.y); x1 = Mathf.Max(x1, q.x); y1 = Mathf.Max(y1, q.y);+ }+ return Rect.MinMaxRect(x0, y0, x1, y1);+ }++ /// <summary>Whether every corner of <paramref name="b"/> is in front of the camera: a box reaching behind it does not project+ /// to a rectangle on screen.</summary>+ static bool InFront(Camera cam, Bounds b)+ {+ for (int c = 0; c < 8; c++)+ {+ var corner = new Vector3((c & 1) == 0 ? b.min.x : b.max.x, (c & 2) == 0 ? b.min.y : b.max.y, (c & 4) == 0 ? b.min.z : b.max.z);+ if (cam.WorldToScreenPoint(corner).z <= cam.nearClipPlane) return false;+ }+ return true;+ }++ /// <summary>The view depth of <paramref name="b"/>'s nearest corner (review of #2281, N1: by view depth, not by the+ /// distance to its centre, so a tall renderer whose centre lies beyond the b21 but whose front reaches over it counts).</summary>+ static float NearestDepth(Camera cam, Bounds b)+ {+ float near = float.MaxValue;+ for (int c = 0; c < 8; c++)+ near = Mathf.Min(near, cam.WorldToScreenPoint(new Vector3((c & 1) == 0 ? b.min.x : b.max.x, (c & 2) == 0 ? b.min.y : b.max.y, (c & 4) == 0 ? b.min.z : b.max.z)).z);+ return near;+ }++ static float Covered(Rect over, Rect model)+ {+ float w = Mathf.Min(over.xMax, model.xMax) - Mathf.Max(over.xMin, model.xMin), h = Mathf.Min(over.yMax, model.yMax) - Mathf.Max(over.yMin, model.yMin);+ return w <= 0f || h <= 0f ? 0f : w * h / (model.width * model.height);+ }++ IEnumerator Visible(string city)+ {+ var inputs = Statecraft.Game.Boot.GameInputs.FromDisk(Statecraft.Game.Paths.Content, Statecraft.Game.Paths.StreamingMap);+ foreach (var era in inputs.Content.Eras) { era.Systems.Ruleset = SaveGame.Gdd03Ruleset; era.Systems.Loop = EraSystems.Gdd; }+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);+ var doc = Object.FindFirstObjectByType<UIDocument>();+ if (rt != null) { rt.Release(); Object.DestroyImmediate(rt); }+ if (ps != null) Object.DestroyImmediate(ps);+ rt = new RenderTexture(CivMovementShots.Width, CivMovementShots.Height, 24, RenderTextureFormat.ARGB32);+ ps = Object.Instantiate(doc.panelSettings);+ ps.targetTexture = rt; ps.clearColor = true; ps.colorClearValue = Color.clear;+ doc.panelSettings = ps;+ var map = Object.FindFirstObjectByType<MapScene>();+ map.Build(inputs.Map);+ var root = Object.FindFirstObjectByType<GameRoot>();+ root.Store = new Statecraft.Game.SaveStore(saveDir);+ root.Begin(inputs, 0);+ var ui = doc.rootVisualElement;+ for (int i = 0; i < 30 && !(ui.Q("top-bar").worldBound.height > 0); i++) yield return null;+ for (int i = 0; i < 5; i++) yield return null;+ var state = root.Bridge!.State; var content = root.Bridge.Content;+ Assert.AreEqual(SaveGame.Gdd03Ruleset, content.Ruleset);+ Assert.IsNotNull(root.Units, "the game's units are drawn");+ var home = content.SettlementHexes.Single(h => h.Id == city);+ int id = state.NextId++;+ state.CityProjects.Add(id, new CityProject(id, Workshops.ArmsWorkshop, city, home.Q, home.R, 0, state.Date));+ SpecialBuildingModels.Request = TalModelsShots.Answer(Array.Empty<string>());+ var old = map.Terrain.transform.Find(SpecialBuildingModels.Name);+ if (old != null) Object.DestroyImmediate(old.gameObject);+ var layer = CollectionGeometryFixture.Special(map, state.Date, content, state.CityProjects.Values)!;+ var model = layer.transform.Find(SpecialBuildingModels.WorkshopKey(id));+ Assert.IsNotNull(model, city + " has its b21");+ var mb = model!.GetComponentsInChildren<Renderer>(true).Select(r => r.bounds).Aggregate((a, b) => { a.Encapsulate(b); return a; });+ var at = mb.center; at.y = map.Terrain.SampleHeight(at) + map.Terrain.transform.position.y;+ TalModelsShots.Look(at, 9000f);+ for (int i = 0; i < 5; i++) yield return null;+ var cam = Camera.main!;+ var modelRect = ScreenRect(cam, mb);+ float modelDepth = cam.WorldToScreenPoint(mb.center).z; // view depth+ float worst = 0f; string worstName = "none";+ foreach (var r in root.Units!.GetComponentsInChildren<Renderer>(false))+ {+ if (!r.enabled || r.forceRenderingOff || !r.gameObject.activeInHierarchy) continue;+ if (!InFront(cam, r.bounds)) continue; // behind the camera (or across its plane): not drawn over the b21+ if (NearestDepth(cam, r.bounds) >= modelDepth) continue; // wholly beyond the b21's centre: it cannot hide it+ float covered = Covered(ScreenRect(cam, r.bounds), modelRect);+ if (covered > worst) { worst = covered; worstName = r.name + " of " + (r.transform.parent != null ? r.transform.parent.name : "") + " at " + r.bounds.center; }+ }+ TestContext.WriteLine($"{city}: b21 at {mb.center}, screen {modelRect}; the most a nearer unit renderer covers: {worst:P0} ({worstName})");+ Assert.Less(worst, 0.5f, $"{city}'s b21 is hidden behind a unit's figures ({worstName} covers {worst:P0} of it)");+ }++ [UnityTest] public IEnumerator TheJerusalemWorkshopIsNotHiddenBehindAUnit() { yield return Visible("jerusalem"); }+ [UnityTest] public IEnumerator TheTelAvivWorkshopIsNotHiddenBehindAUnit() { yield return Visible("tel_aviv"); }+ [UnityTest] public IEnumerator TheRehovotWorkshopIsNotHiddenBehindAUnit() { yield return Visible("rehovot"); }+}++/// <summary>Review of #2281 (S3): GameRoot's merge of the names' keep-clear boxes (GameRoot.KeepClearLists): the units' tokens,+/// the craft and the workshops' b21; one list alone as it is; several merged into one list kept until one of them is a new+/// list (a growing workshop list arrives as a new list each time); back to one list.</summary>+public class KeepClearListsTests+{+ static List<Bounds[]> Boxes(int n) => Enumerable.Range(0, n).Select(i => new[] { new Bounds(new Vector3(i, 0, 0), Vector3.one) }).ToList();++ [Test]+ public void TokensCraftAndWorkshopsMergeAndFollowNewLists()+ {+ var merge = new GameRoot.KeepClearLists();+ var tokens = Boxes(2); var craft = Boxes(1); var none = new List<Bounds[]>();+ Assert.AreSame(tokens, merge.Merge(tokens, null, null), "one list alone, as it is");+ Assert.AreSame(tokens, merge.Merge(tokens, none, none), "empty lists do not count");+ var w1 = Boxes(1);+ var all = merge.Merge(tokens, craft, w1)!;+ Assert.AreEqual(4, all.Count, "tokens, craft and workshops together");+ Assert.AreSame(all, merge.Merge(tokens, craft, w1), "the same lists: the same merged list (the labels do not refresh)");+ var w2 = Boxes(2); // a second b21: the workshops publish a new list+ var grown = merge.Merge(tokens, craft, w2)!;+ Assert.AreNotSame(all, grown, "a new workshop list: a new merged list");+ Assert.AreEqual(5, grown.Count);+ Assert.AreSame(w2, merge.Merge(null, none, w2), "back to one list: that list");+ var again = merge.Merge(tokens, null, w2)!;+ Assert.AreEqual(4, again.Count, "one to several again");+ Assert.AreSame(tokens, merge.Merge(tokens, null, none), "and back to one");+ }+}diff --git a/unity/Assets/Tests/EditMode/ArmsWorkshopVisibilityTests.cs.meta b/unity/Assets/Tests/EditMode/ArmsWorkshopVisibilityTests.cs.metanew file mode 100644index 000000000..08542c9ed--- /dev/null+++ b/unity/Assets/Tests/EditMode/ArmsWorkshopVisibilityTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 8a6e3212d4b034e6badefd07baa050fa\ No newline at end of filediff --git a/unity/Assets/Tests/EditMode/CollectionGeometryFixture.cs b/unity/Assets/Tests/EditMode/CollectionGeometryFixture.csindex ba4760bdf..4986c4afa 100644--- a/unity/Assets/Tests/EditMode/CollectionGeometryFixture.cs+++ b/unity/Assets/Tests/EditMode/CollectionGeometryFixture.cs@@ -55,4 +55,18 @@ internal static class CollectionGeometryFixture(id, detail, done) => { SpecialBuildingModels.Request(id, detail, done); return new Lease(); }));var result = SpecialBuildingModels.ShowAt(map, date); Observe(result!); return result;}+ /// <summary>As GameRoot shows the layer, with <paramref name="workshops"/> already computed (or built by hand in a test).</summary>+ internal static SpecialBuildingModels? Special(MapScene map, DateTime date, IReadOnlyList<SpecialBuildingModels.Want> workshops)+ {+ Layer<SpecialBuildingModels>(map, SpecialBuildingModels.Name, x => x.ConfigureResidency(Wide,+ (id, detail, done) => { SpecialBuildingModels.Request(id, detail, done); return new Lease(); }));+ var result = SpecialBuildingModels.ShowAt(map, date, workshops); Observe(result!); return result;+ }+ /// <summary>As <see cref="Special(MapScene, DateTime)"/>, as GameRoot shows it: with the state's built arms workshops (#1701 slice F).</summary>+ internal static SpecialBuildingModels? Special(MapScene map, DateTime date, Content content, IEnumerable<CityProject> projects)+ {+ Layer<SpecialBuildingModels>(map, SpecialBuildingModels.Name, x => x.ConfigureResidency(Wide,+ (id, detail, done) => { SpecialBuildingModels.Request(id, detail, done); return new Lease(); }));+ var result = SpecialBuildingModels.ShowAt(map, date, content, projects); Observe(result!); return result;+ }}diff --git a/unity/Assets/Tests/EditMode/HexPropModelsTests.cs b/unity/Assets/Tests/EditMode/HexPropModelsTests.csindex b9ddc57c8..73d61bd78 100644--- a/unity/Assets/Tests/EditMode/HexPropModelsTests.cs+++ b/unity/Assets/Tests/EditMode/HexPropModelsTests.cs@@ -552,6 +552,107 @@ namespace Statecraft.Game.TestsCollectionAssert.AreEqual(propsFirst, after.Placed.Select(p => (p.Name, p.At)).ToList(), "the same places in either order");}+ /// <summary>#1701 slice F with #2266: the props keep clear of the b21 planned at each built arms workshop (gdd-0.3), as of+ /// the other special buildings' plan. Workshops stand on the hex nearest each prop's anchor, the props' own ground.</summary>+ [Test]+ public void PropsKeepClearOfTheBuiltArmsWorkshops()+ {+ var map = OpenMap();+ var c = Statecraft.Sim.ContentLoader.Load(Paths.Content);+ foreach (var era in c.Eras) { era.Systems.Ruleset = Statecraft.Sim.SaveGame.Gdd03Ruleset; era.Systems.Loop = Statecraft.Sim.EraSystems.Gdd; }+ var land = c.Hexes.Where(h => h.Land).Select(h => (h, at: map.Frame.ToWorld(h.Lon, h.Lat, 0))).ToList();+ var hexes = HexPropModels.Wants(map, Opening)+ .Select(w => land.OrderBy(x => (new Vector2(x.at.x, x.at.z) - w.Anchor).sqrMagnitude).First().h).Distinct().ToList();+ var projects = hexes.Select((h, i) => new Statecraft.Sim.CityProject(300 + i, Statecraft.Sim.Workshops.ArmsWorkshop, "rehovot", h.Q, h.R, 0, Opening)).ToList();+ CollectionGeometryFixture.People(map, Opening, Array.Empty<Statecraft.Sim.Placement>(), c);+ CollectionGeometryFixture.Rural(map);+ var special = CollectionGeometryFixture.Special(map, Opening, c, projects)!;+ var layer = HexPropModels.ShowAt(map, Opening, c, projects)!;+ layer.Choose(default, At(Statecraft.Game.Map.Kits.TownModelLayer.CloseEnterM));+ AnswerAll();+ var b21 = special.Placed.Where(p => p.Model == SpecialBuildingModels.Workshop)+ .Select(p => (new Vector2(p.At.x, p.At.z), SpecialBuildingModels.ClearanceOf(p.Model))).ToList();+ Assert.Greater(b21.Count, 0, "workshops stand by the props' places");+ Assert.Greater(layer.Placed.Count, 0);+ var kept = layer.Others(map, Opening);+ foreach (var (at, _) in b21)+ Assert.IsTrue(kept.Any(d => (d.centre - at).magnitude < 1f), $"the workshop at {at} is in the props' planned keep-clear ground");+ foreach (var p in layer.Placed)+ Assert.IsTrue(Statecraft.Game.Map.Collection.TownLandmarks.Clear(new Vector2(p.At.x, p.At.z), HexPropModels.ClearanceOf(p.Model), b21),+ p.Name + ": no prop stands on a workshop");+ }++ /// <summary>Review of #2281's merge with #2266 (C3): the hex props and the workshops' b21 stand on ONE rural plan, also+ /// after it changes. All three layers are shown as GameRoot shows them, with a b21 wanted at each farm scene; then the+ /// ground the rural scenes keep clear of+ /// changes so that a farm scene moves and a b21 with it (both asserted as the premise), the rural layer is shown again,+ /// and GameRoot's next refresh (the same date and workshops) rebuilds both consumers: every b21 is drawn where the new+ /// plan puts it, and no prop stands on one.</summary>+ [Test]+ public void ARuralPlanChangeRebuildsTheWorkshopsAndThePropsOntoTheNewPlan()+ {+ var map = OpenMap();+ var c = Statecraft.Sim.ContentLoader.Load(Paths.Content);+ foreach (var era in c.Eras) { era.Systems.Ruleset = Statecraft.Sim.SaveGame.Gdd03Ruleset; era.Systems.Loop = Statecraft.Sim.EraSystems.Gdd; }+ CollectionGeometryFixture.People(map, Opening, Array.Empty<Statecraft.Sim.Placement>(), c);+ var rural = CollectionGeometryFixture.Rural(map)!;+ var before = RuralLife.PlanOf(map);+ int version = RuralLife.VersionOf(map);+ Assert.Greater(before.Count, 0);+ Assert.AreSame(before, RuralLife.PlanOf(map), "the plan is computed once for what was shown");+ // A workshop's b21 wanted right at each farm scene's planned spot (the contested ground), passed as GameRoot passes+ // the state's workshops (ShowAt(map, date, workshops)).+ var workshops = before.Select((f, i) =>+ {+ var (lon, lat) = map.Frame.ToLonLat(new Vector3(f.spot.x, 0f, f.spot.y));+ return new SpecialBuildingModels.Want(SpecialBuildingModels.WorkshopKey(400 + i), SpecialBuildingModels.Workshop, Opening, lon, lat, "test: at a farm scene");+ }).ToList();+ var buildings = SpecialBuildingModels.Placements(Opening).Concat(workshops).ToList();+ Dictionary<string, Vector2> B21(IReadOnlyList<(RuralLife.Want want, Vector2 spot)> plan) =>+ SpecialBuildingModels.Plan(map, Opening, buildings, _ => true, log: false, plan)+ .Where(x => x.want.Model == SpecialBuildingModels.Workshop).ToDictionary(x => x.want.Key, x => x.at);+ var oldB21 = B21(before);+ // The change: other ground on one farm scene's planned spot, the first that moves a b21 when its scene moves.+ List<(Vector2 centre, float radius)>? nextOthers = null; List<(RuralLife.Want want, Vector2 spot)>? after = null;+ foreach (var (_, spot) in before)+ {+ var others = new List<(Vector2 centre, float radius)>(rural.OthersShown) { (spot, 50f) };+ var plan = RuralLife.Plan(map, rural.Wanted, others, _ => true);+ var moved = B21(plan);+ if (moved.Count == oldB21.Count && moved.All(kv => oldB21.TryGetValue(kv.Key, out var o) && (o - kv.Value).sqrMagnitude < 1e-6f)) continue;+ nextOthers = others; after = plan; break;+ }+ Assert.IsNotNull(nextOthers, "premise: some change of the farm scenes' ground moves a b21");+ var special = CollectionGeometryFixture.Special(map, Opening, workshops)!;+ var props = HexPropModels.ShowAt(map, Opening, workshops)!;+ props.Choose(default, At(Statecraft.Game.Map.Kits.TownModelLayer.CloseEnterM));+ AnswerAll();+ Dictionary<string, Vector2> Drawn() => special.Placed.Where(p => p.Model == SpecialBuildingModels.Workshop)+ .ToDictionary(p => p.Key, p => new Vector2(p.At.x, p.At.z));+ foreach (var kv in Drawn()) Assert.Less((oldB21[kv.Key] - kv.Value).magnitude, 1e-3f, kv.Key + " drawn on the shown plan");++ // The ground changes; the rural layer is shown again (GameRoot shows it on every refresh), then the next refresh.+ rural.ShowForTest(rural.Wanted.ToList(), nextOthers!);+ Assert.AreNotEqual(version, RuralLife.VersionOf(map), "the plan's version moved");+ var now = RuralLife.PlanOf(map);+ Assert.IsFalse(now.SequenceEqual(before), "premise: the shown plan changed");+ Assert.IsTrue(now.SequenceEqual(after!), "the new plan is the one the changed ground gives");+ CollectionGeometryFixture.Special(map, Opening, workshops);+ HexPropModels.ShowAt(map, Opening, workshops);+ AnswerAll();+ var newB21 = B21(now);+ var drawn = Drawn();+ CollectionAssert.AreEquivalent(newB21.Keys, drawn.Keys, "the workshops drawn are the new plan's");+ foreach (var kv in drawn) Assert.Less((newB21[kv.Key] - kv.Value).magnitude, 1e-3f, kv.Key + " rebuilt onto the new plan");+ var discs = drawn.Values.Select(at => (at, SpecialBuildingModels.ClearanceOf(SpecialBuildingModels.Workshop))).ToList();+ foreach (var p in props.Placed)+ Assert.IsTrue(Statecraft.Game.Map.Collection.TownLandmarks.Clear(new Vector2(p.At.x, p.At.z), HexPropModels.ClearanceOf(p.Model), discs),+ p.Name + ": no prop stands on a b21 drawn on the new plan");+ var kept = props.Others(map, Opening);+ foreach (var at in drawn.Values)+ Assert.IsTrue(kept.Any(d => (d.centre - at).magnitude < 1f), $"the b21 at {at} is in the props' keep-clear ground");+ }+sealed class Lease : IDisposable { public void Dispose() { } }/// <summary>Review of #2266's delta, C1, on today's map: with one model withheld and the rest streamed in later, everydiff --git a/unity/Assets/Tests/EditMode/MapLabelTests.cs b/unity/Assets/Tests/EditMode/MapLabelTests.csindex ab71c8e2a..ce1999cd1 100644--- a/unity/Assets/Tests/EditMode/MapLabelTests.cs+++ b/unity/Assets/Tests/EditMode/MapLabelTests.cs@@ -292,6 +292,114 @@ public class MapLabelTestsAssert.IsEmpty(failures, string.Join("\n", failures));}+ /// <summary>#1701 slice F: Tal Heuberger's workshop model (b21) at an arms workshop built on Rehovot's own hex (gdd-0.3) and+ /// the map's names do not cover each other. With the real prefab placed and the camera at 30 km over the model (inside its+ /// close zoom), no shown settlement, locality or location pill overlaps the model's projected bounds.</summary>+ [UnityTest] public IEnumerator NoNamePillCoversAWorkshopModel() { yield return NoPillCovers("rehovot"); }+ /// <summary>The same among a town's houses (owner, 2 November 2026: "Among the houses"): Tel Aviv and Jerusalem.</summary>+ [UnityTest] public IEnumerator NoNamePillCoversAWorkshopModelInTelAviv() { yield return NoPillCovers("tel_aviv"); }+ /// <summary>Jerusalem, every pill through the close zoom (15 to 45 km) but one: the "East Jerusalem / Old City"+ /// location's pill is checked up to the close zoom's entry (40 km) only. At its exit (45 km, reached only on the way out)+ /// that pill (263 px wide, about 7.6 km there, set above the Old City's kit) covers the b21: an open item on #2281.+ /// TownGap models the place names' bands, not a location pill at that zoom.</summary>+ [UnityTest] public IEnumerator NoNamePillCoversAWorkshopModelInJerusalem() { yield return NoPillCovers("jerusalem"); }++ /// <summary>Review of #2281 on main: every city's workshop model, not only these three, clear of every name pill through the+ /// close zoom (15 to 45 km), so keeping off the map locations' pills moved no overlap elsewhere.</summary>+ [UnityTest]+ public IEnumerator NoNamePillCoversAnyCitysWorkshopModel()+ {+ var cities = Statecraft.Sim.ContentLoader.Load(Statecraft.Game.Paths.Content).Cities.Select(c => c.Id).OrderBy(x => x, System.StringComparer.Ordinal).ToList();+ Assert.Greater(cities.Count, 5);+ foreach (var city in cities) yield return NoPillCovers(city);+ }++ /// <summary>The one pill, and the distances, the owner's ruling of 3 November 2026 accepts over the Jerusalem b21; that pill+ /// is not checked beyond the close zoom's entry (40 km).</summary>+ static readonly string OldCityPill = "slot-east_jerusalem_old_city";+ static readonly float[] OldCityPillAcceptedM = { 25000f, 30000f, 40000f };+ const float OldCityPillFarthestM = 40000f;++ IEnumerator NoPillCovers(string city)+ {+ var saved = Statecraft.Game.Map.Collection.SpecialBuildingModels.Request;+ Statecraft.Game.Map.Collection.SpecialBuildingModels.Request = (id, detail, done) =>+ done(AssetDatabase.LoadAssetAtPath<GameObject>(Statecraft.Game.Map.Collection.CollectionCatalog.PrefabPath(id, detail)));+ var hd = new HdPanel(cam);+ MapLabelsPresenter? labels = null;+ try+ {+ var content = Statecraft.Sim.ContentLoader.Load(Statecraft.Game.Paths.Content);+ foreach (var era in content.Eras) { era.Systems.Ruleset = Statecraft.Sim.SaveGame.Gdd03Ruleset; era.Systems.Loop = Statecraft.Sim.EraSystems.Gdd; }+ var home = content.SettlementHexes.Single(h => h.Id == city);+ var built = new System.DateTime(1949, 3, 1);+ var layer = CollectionGeometryFixture.Special(map, built, content,+ new[] { new Statecraft.Sim.CityProject(9, Statecraft.Sim.Workshops.ArmsWorkshop, city, home.Q, home.R, 0, built) })!;+ var model = layer.transform.Find(Statecraft.Game.Map.Collection.SpecialBuildingModels.WorkshopKey(9));+ Assert.IsNotNull(model, "the workshop model stands at " + city);+ // As GameRoot wires it (#1701 slice F, option 3): the names keep clear of the drawn b21 (SpecialBuildingModels.KeepClear).+ labels = new MapLabelsPresenter(hd.Root, map, cam, keepClear: () => layer.KeepClearFor(cam), locations: Locations());+ var all = labels.Labels.Concat(labels.LocalityLabels).Concat(labels.LocationLabels).ToList();+ var slots = labels.Slots.Concat(labels.LocalitySlots).Concat(labels.LocationSlots).ToList();+ var failures = new System.Collections.Generic.List<string>();+ // Review of #2281 (N1): not one framing only. The camera over the model, and 2.5 km to either side of it (the model+ // off the frame's centre), at 15 km, 25 km, 30 km, at 40 km (the close zoom's entry) and at 45 km (its exit: the model+ // is still drawn there on the way out). Not at the 6 km minimum (CameraController.MinDistance): owner, 3 November 2026,+ // verbatim: "Fine at 6 km (Recommended)": at the minimum zoom a city's own name may not be shown.+ foreach (var distance in new[] { 15000f, 25000f, 30000f, 40000f, 45000f })+ foreach (var offset in new[] { 0f, -2500f, 2500f })+ {+ rig.LookAt = model!.position + new Vector3(offset, 0f, 0f); rig.Distance = distance; rig.Yaw = 0; rig.TopInset = 0; rig.Apply();+ layer.Choose(default, cam); // the render callback's close-zoom switch, as a camera rendering would run it+ // Beyond the close zoom (the view ray's ground distance, TownModelLayer.ViewDistance) the b21 is not drawn.+ if (!layer.LastClose) { TestContext.WriteLine($"{distance:0} m, {offset:0} m: the b21 is not drawn here"); continue; }+ for (int i = 0; i < 20 && all.Any(l => float.IsNaN(l.resolvedStyle.width) || l.resolvedStyle.width <= 0); i++) yield return null;+ labels.Refresh(force: true); yield return null;+ labels.Refresh(force: true); yield return null;+ float x0 = float.MaxValue, y0 = float.MaxValue, x1 = float.MinValue, y1 = float.MinValue;+ foreach (var r in model.GetComponentsInChildren<Renderer>(true))+ {+ var b = r.bounds;+ for (int c = 0; c < 8; c++)+ {+ var corner = new Vector3((c & 1) == 0 ? b.min.x : b.max.x, (c & 2) == 0 ? b.min.y : b.max.y, (c & 4) == 0 ? b.min.z : b.max.z);+ var q = hd.ToPanel(corner, out bool front); Assert.IsTrue(front);+ x0 = Mathf.Min(x0, q.x); y0 = Mathf.Min(y0, q.y); x1 = Mathf.Max(x1, q.x); y1 = Mathf.Max(y1, q.y);+ }+ }+ var rect = Rect.MinMaxRect(x0, y0, x1, y1);+ var shown = slots.Where(Shown).ToList();+ if (shown.Count == 0) failures.Add($"{distance:0} m, {offset:0} m: no name shown over {city}");+ foreach (var slot in shown)+ {+ var pill = slot.Q<Label>().worldBound;+ TestContext.WriteLine($"{distance:0} m, {offset:0} m: {slot.name} pill {pill}; workshop model {rect}");+ // Owner, 3 November 2026 (~07:02), verbatim: "Accept it at 30-40 km (Recommended)", and later that day, verbatim:+ // "Accept at 25 km too (Recommended)": the "East Jerusalem / Old City" city pill may sit over the Jerusalem b21+ // at 25, 30 and 40 km (as at 45 km: "Accept it (Recommended)", 2 November 2026). Exactly that pill, at exactly+ // those distances; every other pill and distance is checked.+ if (city == "jerusalem" && slot.name == OldCityPill && distance > OldCityPillFarthestM)+ {+ TestContext.WriteLine($"{distance:0} m, {offset:0} m: {slot.name} not checked beyond {OldCityPillFarthestM:0} m (open item on #2281)");+ continue;+ }+ if (city == "jerusalem" && slot.name == OldCityPill && System.Array.IndexOf(OldCityPillAcceptedM, distance) >= 0)+ {+ if (pill.Overlaps(rect)) TestContext.WriteLine($"{distance:0} m, {offset:0} m: {slot.name} over the b21, accepted by the owner's ruling");+ continue;+ }+ if (pill.Overlaps(rect)) failures.Add($"{distance:0} m, {offset:0} m: {slot.name}'s pill {pill} covers the workshop model {rect}");+ }+ }+ Assert.IsEmpty(failures, string.Join("\n", failures));+ }+ finally+ {+ labels?.Dispose(); hd.Dispose();+ Statecraft.Game.Map.Collection.SpecialBuildingModels.Request = saved;+ }+ }+/// <summary>Issue #1008 beside #707: the Latrun police fort's pill and Tal Heuberger's Tegart fort model (SpecialBuildingModels,/// streamed close up from 15 May 1948) do not cover each other. With the real prefab placed and the camera at 30 km over/// Latrun (inside the model's close zoom), the pill is shown and its rectangle clears the model's projected bounds.</summary>diff --git a/unity/Assets/Tests/EditMode/SpecialBuildingModelsTests.cs b/unity/Assets/Tests/EditMode/SpecialBuildingModelsTests.csindex 4d2ce2eb5..a8a3775ba 100644--- a/unity/Assets/Tests/EditMode/SpecialBuildingModelsTests.cs+++ b/unity/Assets/Tests/EditMode/SpecialBuildingModelsTests.cs@@ -309,6 +309,452 @@ namespace Statecraft.Game.TestsAssert.AreEqual(1, layer.transform.childCount);}+ // ---- #1701 slice F (owner, 27 October 2026: "Arms workshops (Recommended)"): b21 on each built arms workshop, gdd-0.3 only ----++ /// <summary>The real content, fresh (the shared copy is never changed), with every era under <paramref name="ruleset"/>.</summary>+ static Statecraft.Sim.Content Rules(string ruleset)+ {+ var c = Statecraft.Sim.ContentLoader.Load(Statecraft.Game.Paths.Content);+ foreach (var era in c.Eras) { era.Systems.Ruleset = ruleset; era.Systems.Loop = Statecraft.Sim.EraSystems.Gdd; }+ return c;+ }++ static readonly DateTime Built = new DateTime(1949, 3, 1);++ /// <summary>City project <paramref name="id"/>: an arms workshop on <paramref name="city"/>'s own hex, built on+ /// <paramref name="builtOn"/> or (null) still being built.</summary>+ static Statecraft.Sim.CityProject Workshop(Statecraft.Sim.Content c, int id, string city, DateTime? builtOn)+ {+ var h = c.SettlementHexes.Single(x => x.Id == city);+ return new Statecraft.Sim.CityProject(id, Statecraft.Sim.Workshops.ArmsWorkshop, city, h.Q, h.R, builtOn == null ? 2 : 0, builtOn);+ }++ [Test]+ public void ArmsWorkshopsAreWantedUnderGdd03AtBuiltWorkshopsOnly()+ {+ var c = Rules(Statecraft.Sim.SaveGame.Gdd03Ruleset);+ var netanya = c.SettlementHexes.Single(x => x.Id == "netanya");+ var projects = new[]+ {+ Workshop(c, 9, "rehovot", Built), Workshop(c, 8, "hadera", null),+ new Statecraft.Sim.CityProject(7, "housing", "netanya", netanya.Q, netanya.R, 0, Built),+ };+ var wants = SpecialBuildingModels.ArmsWorkshops(c, projects);+ Assert.AreEqual(1, wants.Count, "one model per BUILT arms workshop: none for the one being built, none for housing");+ var w = wants[0]; var hex = c.HexAt(projects[0].Q, projects[0].R)!;+ Assert.AreEqual(("arms_workshop_9", SpecialBuildingModels.Workshop, Built), (w.Key, w.Model, w.From));+ Assert.AreEqual((hex.Lon, hex.Lat), (w.Lon, w.Lat), "anchored on the project's own hex");+ Assert.IsEmpty(SpecialBuildingModels.ArmsWorkshops(Rules(Statecraft.Sim.SaveGame.GddRuleset), projects), "never under gdd-0.1");+ }++ /// <summary>A built arms workshop on each city's own hex (the hardest ground: the town's footprint is there): every one+ /// but those of the two cities whose footprint covers the whole hex gets its b21, wholly on that hex, clear of the towns' footprints (and so their labels), the routes, the unit tokens,+ /// the civilians, the wildlife, the farm scenes and every other building model, upright, on the ground, hidden until the+ /// close zoom, and on the same spot when placed again.</summary>+ [Test]+ public void OnTheMapEachBuiltWorkshopStandsOnItsHexClearAndUpright()+ {+ var map = OpenMap();+ var c = Rules(Statecraft.Sim.SaveGame.Gdd03Ruleset);+ var cities = c.Cities.Select(x => x.Id).OrderBy(x => x, StringComparer.Ordinal).ToList();+ Assert.Greater(cities.Count, 5);+ var projects = cities.Select((city, i) => Workshop(c, 100 + i, city, Built)).ToList();+ var savedPeople = CivilianPeople.Request; var savedRural = RuralLife.Request;+ CivilianPeople.Request = (id, detail, done) => { };+ RuralLife.Request = (id, detail, done) => done(AssetDatabase.LoadAssetAtPath<GameObject>(CollectionCatalog.PrefabPath(id, detail)));+ CivilianPeople people; RuralLife rural;+ try+ {+ people = CollectionGeometryFixture.People(map, After, Array.Empty<Statecraft.Sim.Placement>(), c)!;+ rural = CollectionGeometryFixture.Rural(map)!;+ }+ finally { CivilianPeople.Request = savedPeople; RuralLife.Request = savedRural; }+ Assert.Greater(rural.Placed.Count, 0, "the farm scenes stand first, as GameRoot shows them");+ var props = people.Wanted.Select(w => (new Vector2(w.At.x, w.At.z), CivilianPeople.FigureClearanceM))+ .Concat(WildlifeLayer.Wants(map).Select(w => (w.At, 0.5f * WildlifeLayer.SizeM)))+ .Concat(rural.Placed.Select(p => (new Vector2(p.At.x, p.At.z), RuralLife.SceneRadiusM(p.Model)))).ToList();+ var layer = CollectionGeometryFixture.Special(map, After, c, projects)!;+ Assert.AreEqual(1, asked.Count(a => a.id == SpecialBuildingModels.Workshop), "b21 is asked for once, whatever the number of workshops");+ AnswerAll();+ var footprints = map.KitFootprints.Select(f => (f.centre, f.radius)).ToList();+ float r0 = SpecialBuildingModels.ClearanceOf(SpecialBuildingModels.Workshop);+ // A town whose footprint covers its own hex (Jerusalem and Tel Aviv today: footprints of several hexes,+ // FootprintRadiusM) leaves no ground there clear of it: the first ring of the search already leaves the hex, so its+ // b21 stands between the town's drawn buildings (owner, 2 November 2026: "Among the houses").+ var covered = new List<string>();+ foreach (var project in projects)+ {+ var hex = c.HexAt(project.Q, project.R)!; var w3 = map.Frame.ToWorld(hex.Lon, hex.Lat, 0);+ float inside = SpecialBuildingModels.Inside(new Vector2(w3.x, w3.z), footprints);+ TestContext.WriteLine($"{project.City}: hex centre {inside:0} m inside a town's footprint");+ if (inside > 0f && inside + CivilianPeople.LabelClearanceM + 1.5f * r0 + r0 > SpecialBuildingModels.HexInnerRadiusM) covered.Add(project.City);+ }+ CollectionAssert.AreEquivalent(new[] { "jerusalem", "tel_aviv" }, covered, "the cities whose footprint covers their own hex");+ var keys = projects.Select(p => SpecialBuildingModels.WorkshopKey(p.Id)).ToList();+ CollectionAssert.IsSubsetOf(keys, layer.Placed.Select(p => p.Key), "a b21 at every built workshop");+ Assert.AreEqual(keys.Count, layer.Placed.Count(p => p.Model == SpecialBuildingModels.Workshop), "exactly one b21 per built workshop");+ var ground = PlacementLayer.CampGround(map);+ var others = layer.Placed.Where(p => !keys.Contains(p.Key)).Select(p => (new Vector2(p.At.x, p.At.z), SpecialBuildingModels.ClearanceOf(p.Model))).ToList();+ var spots = new List<(Vector2, float)>();+ var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(CollectionCatalog.PrefabPath(SpecialBuildingModels.Workshop, CollectionDetail.Near));+ foreach (var project in projects)+ {+ var key = SpecialBuildingModels.WorkshopKey(project.Id);+ var p = layer.Placed.Single(x => x.Key == key);+ Assert.AreEqual(SpecialBuildingModels.Workshop, p.Model);+ var hex = c.HexAt(project.Q, project.R)!; var centre3 = map.Frame.ToWorld(hex.Lon, hex.Lat, 0);+ var flat = new Vector2(p.At.x, p.At.z); float r = SpecialBuildingModels.ClearanceOf(p.Model);+ float off = (flat - new Vector2(centre3.x, centre3.z)).magnitude;+ TestContext.WriteLine($"{key} ({project.City}): {off:0} m from its hex centre, clearance {r:0} m");+ Assert.LessOrEqual(off + r, SpecialBuildingModels.HexInnerRadiusM, key + " wholly on its project's hex");+ if (covered.Contains(project.City))+ AmongTheHouses(map, key, flat, r);+ else Assert.IsTrue(TownLandmarks.Clear(flat, r, footprints), key + " clear of the towns (and their labels)");+ Assert.IsFalse(ground.OnRoute(flat, r), key + " clear of the routes");+ Assert.IsFalse(ground.OnToken(flat, r, After), key + " clear of the unit tokens");+ Assert.IsTrue(TownLandmarks.Clear(flat, r, others), key + " clear of the sourced building models");+ Assert.IsTrue(TownLandmarks.Clear(flat, r, spots), key + " clear of the other workshops");+ Assert.IsTrue(TownLandmarks.Clear(flat, r, props), key + " clear of the civilians, the wildlife and the farm scenes");+ spots.Add((flat, r));+ var go = layer.transform.Find(key)!;+ Assert.Less(Quaternion.Angle(prefab.transform.localRotation, go.localRotation), 0.01f, key + " keeps the FBX axis conversion");+ var rs = go.GetComponentsInChildren<Renderer>(true);+ var b = rs.Select(x => x.bounds).Aggregate((x, y) => { x.Encapsulate(y); return x; });+ Assert.AreEqual(p.At.y, b.min.y, 1f, key + " stands on the ground");+ Assert.Less(b.size.y, Mathf.Max(b.size.x, b.size.z), key + " upright: lower than it is long");+ Assert.AreEqual(SpecialBuildingModels.SizeOf(SpecialBuildingModels.Workshop), Mathf.Max(b.size.x, b.size.z), 1f, key + " at the buildings' one world scale");+ Assert.IsTrue(rs.All(x => x.forceRenderingOff), key + " hidden until the close zoom");+ }+ // Deterministic: a second layer from nothing puts every workshop on the same spot.+ var first = layer.Placed.Where(p => keys.Contains(p.Key)).ToDictionary(p => p.Key, p => p.At);+ UnityEngine.Object.DestroyImmediate(layer.gameObject);+ var again = CollectionGeometryFixture.Special(map, After, c, cities.Select((city, i) => Workshop(c, 100 + i, city, Built)).ToList())!;+ AnswerAll();+ foreach (var key in keys) Assert.AreEqual(first[key], again.Placed.Single(p => p.Key == key).At, key + " on the same spot again");+ }++ /// <summary>Owner, 2 November 2026 ("Among the houses"): a b21 on a hex a town's footprint covers overlaps none of the town+ /// layer's drawn buildings, whatever they are (read from the layer, not listed here). The names' pills are checked on+ /// screen by MapLabelTests.NoNamePillCoversAWorkshopModelInTelAviv and ...InJerusalem.</summary>+ static void AmongTheHouses(MapScene map, string key, Vector2 flat, float r)+ {+ var layer = map.GetComponentInChildren<Statecraft.Game.Map.Kits.TownModelLayer>(true);+ Assert.IsNotNull(layer, "the town layer");+ int n = 0;+ foreach (var f in map.KitFootprints)+ {+ foreach (var b in layer!.InstancesOf(f.id))+ {+ n++;+ // The building's footprint, a W x D rectangle turned by its yaw: its nearest point to the model's centre.+ var local = Quaternion.Euler(0f, -b.Yaw, 0f) * new Vector3(flat.x - b.C.x, 0f, flat.y - b.C.y);+ var near = new Vector2(Mathf.Clamp(local.x, -0.5f * b.W, 0.5f * b.W), Mathf.Clamp(local.z, -0.5f * b.D, 0.5f * b.D));+ Assert.GreaterOrEqual((new Vector2(local.x, local.z) - near).magnitude, r, $"{key} overlaps {f.id}'s {b.Model} at {b.C}");+ }+ }+ Assert.Greater(n, 0, key + ": the town layer has drawn buildings to keep clear of");+ // Review of #2281 (B1): nor any wall, platform, landmark, harbour work or street palm the kits placed, any landmark's+ // close copy, or any replaceable landmark part (all house-free by design, so a gap search is drawn to them).+ var stats = map.KitStats;+ int m = 0;+ foreach (var l in stats.Landmarks)+ {+ if ((l.C - flat).magnitude > SpecialBuildingModels.HexInnerRadiusM + 0.5f * (l.W + l.D)) continue;+ m++;+ Assert.IsTrue(SpecialBuildingModels.ClearOfBox(flat, r, l.C, l.Yaw, l.W, l.D), $"{key} stands on {l.Id}'s {l.Kind} at {l.C}");+ }+ foreach (var part in stats.LandmarkParts)+ Assert.IsTrue(SpecialBuildingModels.ClearOfBox(flat, r, new Vector2(part.Near.center.x, part.Near.center.z), 0f, part.Near.size.x, part.Near.size.z),+ $"{key} stands on {part.Owner}'s {part.Kind}");+ TestContext.WriteLine($"{key}: clear of {n} drawn buildings and {m} kit landmarks near it");+ Assert.Greater(m, 0, key + ": the kits drew landmarks near it to keep clear of");+ }++ /// <summary>Owner, 2 November 2026 ("Among the houses"): a workshop built on Jerusalem's or Tel Aviv's own hex, which the+ /// town's footprint covers, gets its b21 in a gap between the town's drawn buildings, wholly on the hex, clear of the+ /// routes and the tokens, upright, and on the same spot when placed again.</summary>+ [Test]+ public void AWorkshopInJerusalemOrTelAvivStandsAmongTheHouses()+ {+ var map = OpenMap();+ var c = Rules(Statecraft.Sim.SaveGame.Gdd03Ruleset);+ var projects = new[] { Workshop(c, 21, "jerusalem", Built), Workshop(c, 22, "tel_aviv", Built) };+ var layer = CollectionGeometryFixture.Special(map, After, c, projects)!;+ AnswerAll();+ var ground = PlacementLayer.CampGround(map);+ var first = new Dictionary<string, Vector3>();+ foreach (var project in projects)+ {+ string key = SpecialBuildingModels.WorkshopKey(project.Id);+ CollectionAssert.Contains(layer.Placed.Select(p => p.Key), key, project.City + " gets its b21");+ var p = layer.Placed.Single(x => x.Key == key); first[key] = p.At;+ var hex = c.HexAt(project.Q, project.R)!; var centre3 = map.Frame.ToWorld(hex.Lon, hex.Lat, 0);+ var flat = new Vector2(p.At.x, p.At.z); float r = SpecialBuildingModels.ClearanceOf(p.Model);+ float off = (flat - new Vector2(centre3.x, centre3.z)).magnitude;+ TestContext.WriteLine($"{key} ({project.City}): {off:0} m from its hex centre");+ Assert.LessOrEqual(off + r, SpecialBuildingModels.HexInnerRadiusM, key + " wholly on its hex");+ AmongTheHouses(map, key, flat, r);+ if (project.City == "jerusalem")+ {+ var (oc, half) = Statecraft.Game.Map.Kits.SettlementKits.OldCityWalls(map.Frame);+ var d = flat - oc;+ TestContext.WriteLine($"{key}: {d.x:0} m east and {d.y:0} m north of the Old City's centre (walls' half side {half:0} m)");+ Assert.IsTrue(Mathf.Abs(d.x) >= half + r || Mathf.Abs(d.y) >= half + r, key + " outside the Old City's walls");+ }+ Assert.IsFalse(ground.OnRoute(flat, r), key + " clear of the routes");+ Assert.IsFalse(ground.OnToken(flat, r, After), key + " clear of the unit tokens");+ var b = layer.transform.Find(key)!.GetComponentsInChildren<Renderer>(true).Select(x => x.bounds).Aggregate((x, y) => { x.Encapsulate(y); return x; });+ Assert.Less(b.size.y, Mathf.Max(b.size.x, b.size.z), key + " upright");+ }+ UnityEngine.Object.DestroyImmediate(layer.gameObject);+ var again = CollectionGeometryFixture.Special(map, After, c, projects)!;+ AnswerAll();+ foreach (var kv in first) Assert.AreEqual(kv.Value, again.Placed.Single(p => p.Key == kv.Key).At, kv.Key + " on the same spot again");+ // The load gate's rebuild line: one full plan (the sourced buildings and both workshops among the houses), as each+ // Rebuild computes it.+ var wants = SpecialBuildingModels.Placements(After).Concat(SpecialBuildingModels.ArmsWorkshops(c, projects)).ToList();+ SpecialBuildingModels.Plan(map, After, wants, _ => true, log: false); // warm+ var clock = System.Diagnostics.Stopwatch.StartNew();+ const int Runs = 5;+ for (int i = 0; i < Runs; i++) SpecialBuildingModels.Plan(map, After, wants, _ => true, log: false);+ double ms = clock.Elapsed.TotalMilliseconds / Runs;+ TestContext.WriteLine($"PLAN-TIMING Jerusalem+Tel Aviv workshops: {ms:0.0} ms per plan");+ // A design bound, not a budget: a plan runs on a prefab answer or a change of date or workshops, never per frame.+ Assert.Less(ms, 50.0, "one plan with two workshops among the houses");+ }++ /// <summary>Review of #2281 (N3): every building takes its planned ground whether or not its model has streamed. A+ /// workshop model is wanted 400 m from the Tegart fort's planned spot, after the fort; with the fort's bundle failing+ /// (answered null), every building drawn stands exactly where the plan with every model puts it: the workshop does not+ /// slide onto the fort's ground.</summary>+ [Test]+ public void AFailedModelKeepsItsGroundSoNoOtherBuildingMoves()+ {+ var map = OpenMap();+ var layer = CollectionGeometryFixture.Special(map, After)!;+ var fortAt = SpecialBuildingModels.Plan(map, After, SpecialBuildingModels.Placements(After), _ => true, log: false).Single(x => x.want.Key == "latrun_tegart").at;+ // 400 m off the fort, on the first side (east, north, west, south) where the overlap is forced: planned with the fort+ // taking no ground (the fort's want left out), the workshop stands on the fort's ground; planned with every model, it+ // has ground elsewhere. So a layer that let a failed model's ground go would draw it on the fort's ground.+ float reach = SpecialBuildingModels.ClearanceOf(SpecialBuildingModels.Tegart) + SpecialBuildingModels.ClearanceOf(SpecialBuildingModels.Workshop);+ string key41 = SpecialBuildingModels.WorkshopKey(41);+ List<SpecialBuildingModels.Want> wants = null!;+ Dictionary<string, Vector2> full = null!;+ bool forced = false;+ foreach (var side in new[] { Vector2.right, Vector2.up, Vector2.left, Vector2.down })+ {+ var near = fortAt + 400f * side;+ var (lon, lat) = map.Frame.ToLonLat(new Vector3(near.x, 0f, near.y));+ wants = SpecialBuildingModels.Placements(After)+ .Append(new SpecialBuildingModels.Want(key41, SpecialBuildingModels.Workshop, Built, lon, lat, "test: by the fort's spot"))+ .ToList();+ full = SpecialBuildingModels.Plan(map, After, wants, _ => true, log: false).ToDictionary(x => x.want.Key, x => x.at);+ var withoutFort = SpecialBuildingModels.Plan(map, After, wants.Where(w => w.Key != "latrun_tegart").ToList(), _ => true, log: false)+ .Where(x => x.want.Key == key41).Select(x => (Vector2?)x.at).FirstOrDefault();+ if (!full.ContainsKey(key41) || withoutFort == null || (withoutFort.Value - fortAt).magnitude >= reach) continue;+ TestContext.WriteLine($"the workshop 400 m {side} of the fort: {(withoutFort.Value - fortAt).magnitude:0} m from it if the fort took no ground, {(full[key41] - fortAt).magnitude:0} m with it");+ forced = true; break;+ }+ Assert.IsTrue(forced, "a side where the workshop would stand on the fort's ground if the fort took none");+ layer.ShowForTest(wants);+ Assert.IsTrue(full.ContainsKey(SpecialBuildingModels.WorkshopKey(41)), "the workshop has ground in the full plan");+ LogAssert.Expect(LogType.Warning, new Regex("^BUILDINGS: " + SpecialBuildingModels.Tegart + " did not stream"));+ var pending = asked.ToList(); asked.Clear();+ foreach (var (id, done) in pending)+ done(id == SpecialBuildingModels.Tegart ? null : AssetDatabase.LoadAssetAtPath<GameObject>(CollectionCatalog.PrefabPath(id, CollectionDetail.Near)));+ CollectionAssert.DoesNotContain(layer.Placed.Select(p => p.Model), SpecialBuildingModels.Tegart);+ CollectionAssert.Contains(layer.Placed.Select(p => p.Key), SpecialBuildingModels.WorkshopKey(41));+ var drawn = layer.Placed.Single(p => p.Key == key41);+ Assert.GreaterOrEqual((new Vector2(drawn.At.x, drawn.At.z) - fortAt).magnitude, reach, "the workshop is not drawn on the failed fort's ground");+ foreach (var p in layer.Placed)+ {+ Assert.AreEqual(full[p.Key].x, p.At.x, 1e-3f, p.Key + " where the full plan puts it (x)");+ Assert.AreEqual(full[p.Key].y, p.At.z, 1e-3f, p.Key + " where the full plan puts it (z)");+ }+ }++ /// <summary>Review of #2281 (N1, N2): ClearOfName's band, edge by edge: from the footprint's south edge to+ /// TownLabelHeightM past its north edge, TownLabelHalfWidthM either side, widened by the model's clearance.</summary>+ [Test]+ public void ClearOfNameIsTheBandAboveAPlacesKit()+ {+ var c = new Vector2(1000f, 2000f); float fr = 800f, r = 200f;+ float w = SpecialBuildingModels.TownLabelHalfWidthM, h = SpecialBuildingModels.TownLabelHeightM;+ Assert.IsFalse(SpecialBuildingModels.ClearOfName(c, r, c, fr), "on the place");+ Assert.IsFalse(SpecialBuildingModels.ClearOfName(c + new Vector2(0f, fr + h), r, c, fr), "in the pill above it");+ Assert.IsFalse(SpecialBuildingModels.ClearOfName(c + new Vector2(w + r - 1f, 0f), r, c, fr), "just inside the side");+ Assert.IsTrue(SpecialBuildingModels.ClearOfName(c + new Vector2(w + r + 1f, 0f), r, c, fr), "just outside the side");+ Assert.IsTrue(SpecialBuildingModels.ClearOfName(c + new Vector2(-w - r - 1f, 0f), r, c, fr), "just outside the other side");+ Assert.IsFalse(SpecialBuildingModels.ClearOfName(c + new Vector2(0f, fr + h + r - 1f), r, c, fr), "just under the top");+ Assert.IsTrue(SpecialBuildingModels.ClearOfName(c + new Vector2(0f, fr + h + r + 1f), r, c, fr), "just over the top");+ Assert.IsFalse(SpecialBuildingModels.ClearOfName(c + new Vector2(0f, -fr - r + 1f), r, c, fr), "just over the bottom");+ Assert.IsTrue(SpecialBuildingModels.ClearOfName(c + new Vector2(0f, -fr - r - 1f), r, c, fr), "just under the bottom");+ }++ /// <summary>Review of #2281 (M1): the b21 boxes the labels keep clear of are published as a new list on every change and+ /// a list once handed out never changes. A b21 that streams in after the labels read the boxes, and a second workshop+ /// built later, each reach the labels as a new list; the earlier lists keep what they held.</summary>+ [Test]+ public void TheWorkshopBoxesReachTheLabelsAsNewListsAndNeverChangeAfter()+ {+ var map = OpenMap();+ var c = Rules(Statecraft.Sim.SaveGame.Gdd03Ruleset);+ var cam = Camera.main!;+ cam.transform.SetPositionAndRotation(new Vector3(0f, Statecraft.Game.Map.Kits.TownModelLayer.CloseEnterM - 1000f, 0f), Quaternion.Euler(90f, 0f, 0f));+ var one = new[] { Workshop(c, 51, "rehovot", Built) };+ var layer = CollectionGeometryFixture.Special(map, After, c, one)!; // b21 asked for, not answered yet+ layer.Choose(default, cam);+ var before = layer.KeepClearFor(cam);+ Assert.AreEqual(0, before.Count, "nothing drawn yet");+ AnswerAll(); // b21 streams in after the labels read the boxes+ var first = layer.KeepClearFor(cam);+ Assert.AreNotSame(before, first, "a new list once the b21 is drawn");+ Assert.AreEqual(1, first.Count);+ Assert.AreEqual(0, before.Count, "the list handed out before is unchanged");+ CollectionGeometryFixture.Special(map, After, c, new[] { one[0], Workshop(c, 52, "hadera", Built) }); // a second workshop+ AnswerAll();+ layer.Choose(default, cam);+ var second = layer.KeepClearFor(cam);+ Assert.AreNotSame(first, second, "a new list for the second b21");+ Assert.AreEqual(2, second.Count);+ Assert.AreEqual(1, first.Count, "the list handed out before is unchanged");+ }++ /// <summary>Review of #2281 (S2): a workshop's spot reads only planned data (the map's unit spots, the day it was built),+ /// never the game's later date, so it stands on the same spot at a later date (past the dated tokens' last days).</summary>+ [Test]+ public void AWorkshopStandsOnTheSameSpotAsTheGameDatePasses()+ {+ var map = OpenMap();+ var c = Rules(Statecraft.Sim.SaveGame.Gdd03Ruleset);+ var projects = c.Cities.Select(x => x.Id).OrderBy(x => x, StringComparer.Ordinal).Select((city, i) => Workshop(c, 600 + i, city, Built)).ToList();+ var wants = SpecialBuildingModels.ArmsWorkshops(c, projects);+ var tokens = map.UnitTokens.Count(t => t.until > Built && t.until <= After);+ TestContext.WriteLine($"{tokens} dated unit tokens end between the build and the later date");+ Assert.Greater(tokens, 0, "premise: some dated tokens end in between");+ var atBuilt = SpecialBuildingModels.Plan(map, Built, wants, _ => true, log: false).ToDictionary(x => x.want.Key, x => x.at);+ var later = SpecialBuildingModels.Plan(map, After, wants, _ => true, log: false).ToDictionary(x => x.want.Key, x => x.at);+ CollectionAssert.AreEquivalent(atBuilt.Keys, later.Keys, "the same workshops stand");+ foreach (var kv in atBuilt) Assert.AreEqual(kv.Value, later[kv.Key], kv.Key + " on the same spot at the later date");+ }++ /// <summary>Review of #2281 (N1): the ground a unit spot's figures hide (SpecialBuildingModels.Hidden), edge by edge: north+ /// of the spot to FigureShadowM past its disc, the disc's width either side, widened by the model's clearance.</summary>+ [Test]+ public void TheGroundAUnitsFiguresHideIsNorthOfItsSpot()+ {+ var c = new Vector2(1000f, 2000f); float R = 500f, r = 200f, s = SpecialBuildingModels.FigureShadowM;+ Assert.Greater(s, 2000f, "the figures are about 2.5 km tall, seen at 50 degrees");+ Assert.IsTrue(SpecialBuildingModels.Hidden(c + new Vector2(0f, R + s - 1f), 0f, c, R), "just inside the shadow's far end");+ Assert.IsFalse(SpecialBuildingModels.Hidden(c + new Vector2(0f, R + s + r + 1f), r, c, R), "just beyond it");+ Assert.IsTrue(SpecialBuildingModels.Hidden(c + new Vector2(R + r - 1f, R), r, c, R), "just inside its east side");+ Assert.IsFalse(SpecialBuildingModels.Hidden(c + new Vector2(R + r + 1f, R), r, c, R), "just outside its east side");+ Assert.IsFalse(SpecialBuildingModels.Hidden(c + new Vector2(-R - r - 1f, R), r, c, R), "just outside its west side");+ Assert.IsFalse(SpecialBuildingModels.Hidden(c + new Vector2(0f, -R - r - 1f), r, c, R), "south of the spot: in front of the figures");+ }++ /// <summary>The model stands from the turn the build completes (not while it is being built), stays put on GameRoot's+ /// refreshes at one state, leaves with its project, and never stands under gdd-0.1.</summary>+ [Test]+ public void TheWorkshopStandsFromItsCompletionAndLeavesWithItsProject()+ {+ var map = OpenMap();+ var c = Rules(Statecraft.Sim.SaveGame.Gdd03Ruleset);+ string key = SpecialBuildingModels.WorkshopKey(9);+ var layer = CollectionGeometryFixture.Special(map, Built, c, new[] { Workshop(c, 9, "rehovot", null) })!;+ AnswerAll();+ CollectionAssert.DoesNotContain(layer.Placed.Select(p => p.Key), key, "not while it is being built");+ Assert.IsNull(layer.transform.Find(key));+ // Built on this turn's date: the same date, a different state, so the layer redraws.+ var built = new[] { Workshop(c, 9, "rehovot", Built) };+ CollectionGeometryFixture.Special(map, Built, c, built);+ AnswerAll();+ CollectionAssert.Contains(layer.Placed.Select(p => p.Key), key, "from the turn the build completes");+ var model = layer.transform.Find(key)!.gameObject;+ CollectionGeometryFixture.Special(map, Built, c, new[] { Workshop(c, 9, "rehovot", Built) });+ Assert.IsTrue(model != null && model.transform.parent == layer.transform, "the same state keeps the same model");+ CollectionGeometryFixture.Special(map, Built, c, Array.Empty<Statecraft.Sim.CityProject>());+ AnswerAll();+ CollectionAssert.DoesNotContain(layer.Placed.Select(p => p.Key), key, "gone with its project");+ Assert.IsNull(layer.transform.Find(key));+ CollectionGeometryFixture.Special(map, Built.AddMonths(1), Rules(Statecraft.Sim.SaveGame.GddRuleset), built);+ AnswerAll();+ CollectionAssert.DoesNotContain(layer.Placed.Select(p => p.Model), SpecialBuildingModels.Workshop, "never under gdd-0.1");+ }++ /// <summary>Review of #2281 (blocking): a workshop's spot does not depend on what streamed first. Workshop models are+ /// wanted right at the farm scenes' planned spots (RuralLife.Plan), the most contested ground. With the farm scenes+ /// streamed first, or with b21 streamed alone first and the other buildings and the farm scenes after it, every b21+ /// stands on the same spot, clear of every farm scene drawn.</summary>+ [Test]+ public void AWorkshopsSpotIsTheSameWhateverStreamsFirst()+ {+ var map = OpenMap();+ var c = Rules(Statecraft.Sim.SaveGame.Gdd03Ruleset);+ var savedPeople = CivilianPeople.Request; var savedRural = RuralLife.Request;+ var rural = new List<(string id, CollectionDetail detail, Action<GameObject?> done)>();+ CivilianPeople.Request = (id, detail, done) => { };+ RuralLife.Request = (id, detail, done) => rural.Add((id, detail, done));+ void StreamRural()+ {+ for (int round = 0; round < 10 && rural.Count > 0; round++)+ {+ var now = rural.ToList(); rural.Clear();+ foreach (var (id, detail, done) in now) done(AssetDatabase.LoadAssetAtPath<GameObject>(CollectionCatalog.PrefabPath(id, detail)));+ }+ }+ try+ {+ CollectionGeometryFixture.People(map, After, Array.Empty<Statecraft.Sim.Placement>(), c);+ var farms = RuralLife.Plan(map, RuralLife.Wants(map), RuralLife.OtherProps(map), _ => true);+ Assert.Greater(farms.Count, 0);+ var wants = SpecialBuildingModels.Placements(After).ToList();+ for (int i = 0; i < farms.Count; i++)+ {+ var (lon, lat) = map.Frame.ToLonLat(new Vector3(farms[i].spot.x, 0f, farms[i].spot.y));+ wants.Add(new SpecialBuildingModels.Want(SpecialBuildingModels.WorkshopKey(500 + i), SpecialBuildingModels.Workshop, Built, lon, lat, "test: at a farm scene"));+ }+ SpecialBuildingModels Layer()+ {+ var l = CollectionGeometryFixture.Special(map, After)!;+ l.ShowForTest(wants);+ return l;+ }++ // The farm scenes first, then the buildings.+ var ruralLayer = CollectionGeometryFixture.Rural(map)!;+ StreamRural();+ Assert.Greater(ruralLayer.Placed.Count, 0);+ var first = Layer();+ AnswerAll();+ var spots = first.Placed.Where(p => p.Model == SpecialBuildingModels.Workshop).ToDictionary(p => p.Key, p => p.At);+ Assert.Greater(spots.Count, 0, "workshops stand by the farm scenes");+ UnityEngine.Object.DestroyImmediate(first.gameObject); UnityEngine.Object.DestroyImmediate(ruralLayer.gameObject);+ asked.Clear();++ // b21 alone first, then the other buildings, then the farm scenes.+ ruralLayer = CollectionGeometryFixture.Rural(map)!;+ var second = Layer();+ var b21 = asked.Where(a => a.id == SpecialBuildingModels.Workshop).ToList();+ Assert.AreEqual(1, b21.Count);+ asked.RemoveAll(a => a.id == SpecialBuildingModels.Workshop);+ b21[0].done(AssetDatabase.LoadAssetAtPath<GameObject>(CollectionCatalog.PrefabPath(SpecialBuildingModels.Workshop, CollectionDetail.Near)));+ AnswerAll();+ StreamRural();+ Assert.Greater(ruralLayer.Placed.Count, 0);+ var scenes = ruralLayer.Placed.Select(p => (new Vector2(p.At.x, p.At.z), RuralLife.SceneRadiusM(p.Model))).ToList();+ var again = second.Placed.Where(p => p.Model == SpecialBuildingModels.Workshop).ToList();+ CollectionAssert.AreEquivalent(spots.Keys, again.Select(p => p.Key), "the same workshops stand");+ foreach (var p in again)+ {+ Assert.AreEqual(spots[p.Key], p.At, p.Key + " on the same spot whatever streamed first");+ Assert.IsTrue(TownLandmarks.Clear(new Vector2(p.At.x, p.At.z), SpecialBuildingModels.ClearanceOf(p.Model), scenes),+ p.Key + " clear of the farm scenes that streamed in after it");+ }+ }+ finally { CivilianPeople.Request = savedPeople; RuralLife.Request = savedRural; }+ }+[Test]public void ABundleThatDoesNotStreamLeavesTheMapRunning(){diff --git a/unity/Assets/Tests/EditMode/TalModelsShots.cs b/unity/Assets/Tests/EditMode/TalModelsShots.csindex b1fc1ecf4..7ad8ea4de 100644--- a/unity/Assets/Tests/EditMode/TalModelsShots.cs+++ b/unity/Assets/Tests/EditMode/TalModelsShots.cs@@ -169,6 +169,94 @@ public class TalModelsShotsDebug.Log($"SHOT degania on {root.Bridge.State.Date:yyyy-MM-dd} at {point} from {CameraController.MinDistance:F0} m, event card display {card.resolvedStyle.display}: {string.Join(", ", layer.Placed.Select(p => p.Key))}");}+ /// <summary>#1701 slice F: a gdd-0.3 game (every era's ruleset set on fresh inputs, as FixedNorthGameRootTests does) with+ /// one arms workshop built on Rehovot's own hex, or on Tel Aviv's or Jerusalem's among its houses (owner, 2 November 2026: "Among the+ /// houses") (a fixture state: the project is put in the state, built on the game's date),+ /// from the close zoom, framed on the workshop and the town. "Before" withholds b21 (main draws nothing there); the frame is+ /// the one the answered model gives. The load lines count the special layer's instances, drawn renderers and their+ /// triangles at the far, middle and close zooms.</summary>+ IEnumerator ArmsWorkshop(bool hebrew, bool after, string city = "rehovot")+ {+ Directory.CreateDirectory(Path.Combine(CivMovementShots.ShotDir, "..", "b21-workshop-shots"));+ // The town's houses as the player's stream answers them, so the frame shows the drawn buildings the workshop keeps clear of.+ TownModelLayer.ModelAcquire = (model, detail, done) => { done(Prefab(model, detail)); return new NoLease(); };+ var inputs = Statecraft.Game.Boot.GameInputs.FromDisk(Statecraft.Game.Paths.Content, Statecraft.Game.Paths.StreamingMap);+ foreach (var era in inputs.Content.Eras) { era.Systems.Ruleset = SaveGame.Gdd03Ruleset; era.Systems.Loop = EraSystems.Gdd; }+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);+ var doc = Object.FindFirstObjectByType<UIDocument>();+ rt = new RenderTexture(CivMovementShots.Width, CivMovementShots.Height, 24, RenderTextureFormat.ARGB32);+ ps = Object.Instantiate(doc.panelSettings);+ ps.targetTexture = rt; ps.clearColor = true; ps.colorClearValue = Color.clear;+ doc.panelSettings = ps;+ var map = Object.FindFirstObjectByType<MapScene>();+ map.Build(inputs.Map);+ root = Object.FindFirstObjectByType<GameRoot>();+ root.Store = new Statecraft.Game.SaveStore(saveDir);+ if (hebrew) root.Language = UiLanguage.Hebrew;+ root.Begin(inputs, 0);+ var ui = doc.rootVisualElement;+ for (int i = 0; i < 30 && !(ui.Q("top-bar").worldBound.height > 0); i++) yield return null;+ for (int i = 0; i < 5; i++) yield return null;+ GameSceneTests.HideTheOpeningCard(ui);+ if (root.Advisor != null && root.Advisor.IsOpen) UiTestKit.Press(ui.Q<Button>("advisor-close"));+ for (int i = 0; i < 3; i++) yield return null;+ var state = root.Bridge!.State; var content = root.Bridge.Content;+ Assert.AreEqual(SaveGame.Gdd03Ruleset, content.Ruleset);+ var home = content.SettlementHexes.Single(h => h.Id == city);+ int id = state.NextId++;+ state.CityProjects.Add(id, new CityProject(id, Workshops.ArmsWorkshop, city, home.Q, home.R, 0, state.Date));+ SpecialBuildingModels Layer(ICollection<string> withheld)+ {+ SpecialBuildingModels.Request = Answer(withheld);+ Drop(map, SpecialBuildingModels.Name);+ return CollectionGeometryFixture.Special(map, state.Date, content, state.CityProjects.Values)!;+ }+ var layer = Layer(Array.Empty<string>());+ var workshop = layer.Placed.Single(p => p.Key == SpecialBuildingModels.WorkshopKey(id));+ if (!after) layer = Layer(new[] { SpecialBuildingModels.Workshop });+ var town = map.KitFootprints.First(f => f.id == city);+ bool among = Vector2.Distance(new Vector2(workshop.At.x, workshop.At.z), town.centre) < town.radius;+ // Among a big town's houses (Tel Aviv, Jerusalem: "Among the houses") the frame is the workshop and its neighbours;+ // beside a town, the workshop and the whole town.+ var mid = among ? new Vector3(workshop.At.x, 0f, workshop.At.z)+ : new Vector3(0.5f * (workshop.At.x + town.centre.x), 0f, 0.5f * (workshop.At.z + town.centre.y));+ mid.y = map.Terrain.SampleHeight(mid) + map.Terrain.transform.position.y;+ float span = Vector2.Distance(new Vector2(workshop.At.x, workshop.At.z), town.centre) + town.radius;+ float close = among ? 1.5f * CameraController.MinDistance : Mathf.Clamp(2.5f * span, CameraController.MinDistance, 0.9f * TownModelLayer.CloseEnterM);+ foreach (var (zoom, distance) in new[] { ("far", 150000f), ("middle", 60000f), ("close", close) })+ {+ Look(mid, distance);+ layer.Choose(default, Camera.main);+ var drawn = layer.GetComponentsInChildren<Renderer>(true).Where(r => !r.forceRenderingOff).ToList();+ long tris = 0;+ foreach (var r in drawn)+ {+ Mesh? mesh = r is SkinnedMeshRenderer skinned ? skinned.sharedMesh : r.TryGetComponent<MeshFilter>(out var filter) ? filter.sharedMesh : null;+ if (mesh != null) tris += mesh.triangles.Length / 3;+ }+ Debug.Log($"LOAD b21 {(after ? "after" : "before")} {zoom} ({distance:F0} m): {layer.transform.childCount} instances, " ++ $"{drawn.Count} renderers drawn, {tris} triangles drawn; placed: {string.Join(", ", layer.Placed.Select(p => p.Key))}");+ }+ Look(mid, close);+ layer.Choose(default, Camera.main);+ for (int i = 0; i < 5; i++) yield return null;+ CivMovementShots.Shot(rt!, Path.Combine("..", "b21-workshop-shots", $"{city}-workshop-{(after ? "after" : "before")}-{(hebrew ? "he" : "en")}"));+ Debug.Log($"SHOT b21 {city} {(after ? "after" : "before")} {(hebrew ? "he" : "en")} on {state.Date:yyyy-MM-dd}: workshop at {workshop.At}, camera on {mid} from {close:F0} m");+ }++ [UnityTest] public IEnumerator ArmsWorkshopBeforeEnglish() { yield return ArmsWorkshop(false, false); }+ [UnityTest] public IEnumerator ArmsWorkshopAfterEnglish() { yield return ArmsWorkshop(false, true); }+ [UnityTest] public IEnumerator ArmsWorkshopBeforeHebrew() { yield return ArmsWorkshop(true, false); }+ [UnityTest] public IEnumerator ArmsWorkshopAfterHebrew() { yield return ArmsWorkshop(true, true); }+ [UnityTest] public IEnumerator ArmsWorkshopTelAvivBeforeEnglish() { yield return ArmsWorkshop(false, false, "tel_aviv"); }+ [UnityTest] public IEnumerator ArmsWorkshopTelAvivAfterEnglish() { yield return ArmsWorkshop(false, true, "tel_aviv"); }+ [UnityTest] public IEnumerator ArmsWorkshopTelAvivBeforeHebrew() { yield return ArmsWorkshop(true, false, "tel_aviv"); }+ [UnityTest] public IEnumerator ArmsWorkshopTelAvivAfterHebrew() { yield return ArmsWorkshop(true, true, "tel_aviv"); }+ [UnityTest] public IEnumerator ArmsWorkshopJerusalemBeforeEnglish() { yield return ArmsWorkshop(false, false, "jerusalem"); }+ [UnityTest] public IEnumerator ArmsWorkshopJerusalemAfterEnglish() { yield return ArmsWorkshop(false, true, "jerusalem"); }+ [UnityTest] public IEnumerator ArmsWorkshopJerusalemBeforeHebrew() { yield return ArmsWorkshop(true, false, "jerusalem"); }+ [UnityTest] public IEnumerator ArmsWorkshopJerusalemAfterHebrew() { yield return ArmsWorkshop(true, true, "jerusalem"); }+sealed class NoLease : IDisposable { public void Dispose() { } }/// <summary>A town's houses from the closest zoom the player can reach, the camera on the centre of the town's placed