Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Refs #792 (slice 2: item 3, camp and rural kits) (#1316)

Beri6cb0176443c2
diff --git a/changelog.d/gdd-p4-map-site-kits.md b/changelog.d/gdd-p4-map-site-kits.md
new file mode 100644
index 000000000..6bd003fd9
--- /dev/null
+++ b/changelog.d/gdd-p4-map-site-kits.md
@@ -0,0 +1,2 @@
+- A built training camp (Camp 80, Tzrifin) draws a camp kit on its site, a fenced yard with rows of barracks and an open
+ parade ground, instead of a kibbutz; a built yishuv keeps its rural kit (#792). No golden moves.
diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.Camp.cs b/unity/Assets/Scripts/Map/Kits/SettlementKits.Camp.cs
new file mode 100644
index 000000000..7fda1091e
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.Camp.cs
@@ -0,0 +1,60 @@
+#nullable enable
+using UnityEngine;
+
+namespace Statecraft.Game.Map.Kits
+{
+ /// <summary>The camp kit (GDD Phase 4 PR 8, #792): a built training camp (a sites.yaml site of kind military_camp,
+ /// SiteLayer) is drawn as a camp, not as a kibbutz: a fenced square yard with its gate, rows of long one-storey barracks
+ /// and an open parade ground by the gate. No source was read for the layout; the plan, sizes and colours are modelling
+ /// choices, kept as plain as the Negev outpost's (SettlementKits.Outpost.cs), whose yard pattern this follows.</summary>
+ public static partial class SettlementKits
+ {
+ /// <summary>The settlement type a camp's kit is built from (SiteLayer.KitOf). No settlements_1948.yaml row has it.</summary>
+ public const string CampType = "military_camp";
+
+ static bool MilitaryCamp(Settlement s) => s.Type == CampType;
+
+ /// <summary>The yard's side and the fence's height and thickness (real m, at the house scale).</summary>
+ const float CampSide = 30f, CampFenceH = 1.8f, CampFenceT = 0.4f;
+
+ /// <summary>A camp at <paramref name="heart"/>, on the settlement's grid angle: the fenced yard (the +v side broken by
+ /// the gate), two columns of three barracks on the -v two thirds, the parade ground left open on the gate side. One lot
+ /// for the whole yard; nothing is built when no free dry spot takes it. Returns how many things were built (the yard
+ /// and its barracks, or 0).</summary>
+ static int MilitaryCampKit(Settlement s, Vector2 heart, KitGround ground, KitMesh km, Lots lots)
+ {
+ float m = KitScale.Houses, half = 0.5f * CampSide * m;
+ if (!Claim(lots, heart, half * 1.4142f, s.Id, ground, out var c)) return 0;
+ float yaw = GridYaw(s.Id), a = yaw * Mathf.Deg2Rad, ca = Mathf.Cos(a), sa = Mathf.Sin(a);
+ Vector2 At(float u, float v) => c + new Vector2(u * ca - v * sa, u * sa + v * ca) * m;
+ var fence = C(0.55f, 0.52f, 0.46f); var timber = C(0.74f, 0.66f, 0.52f); var tin = C(0.58f, 0.60f, 0.58f);
+ // The fence: four sides, the +v one broken by a 4 m gate in its middle.
+ float h = 0.5f * CampSide, t = CampFenceT;
+ var pieces = new (float u, float v, float w, float d)[]
+ {
+ (0f, -h + 0.5f * t, CampSide, t), (-h + 0.5f * t, 0f, t, CampSide), (h - 0.5f * t, 0f, t, CampSide),
+ (-8.5f, h - 0.5f * t, 13f, t), (8.5f, h - 0.5f * t, 13f, t),
+ };
+ foreach (var (u, v, w, d) in pieces)
+ {
+ var p = At(u, v);
+ var (bottom, top) = GroundSpan(p, yaw, w * m, d * m, ground, m);
+ km.Box(p.x, p.y, yaw, w * m, d * m, bottom, top, CampFenceH * m, fence, fence, Facade.Plain, m);
+ }
+ Record(s.Id, "camp_yard", c, yaw, 2f * half, 2f * half, CampFenceH * m, fence);
+ // The barracks: 10 x 3.6 m, timber walls under tin roofs, in two columns (u = -7, 7) of three rows (v = -10, -4,
+ // 2), inside the fence and clear of each other; the yard's +v third, by the gate, is the parade ground.
+ int n = 1;
+ foreach (var u in new[] { -7f, 7f })
+ foreach (var v in new[] { -10f, -4f, 2f })
+ {
+ var p = At(u, v); float w = 10f * m, d = 3.6f * m, bh = 3f * m;
+ var (bottom, top) = GroundSpan(p, yaw, w, d, ground, m);
+ km.Box(p.x, p.y, yaw, w, d, bottom, top, bh, timber, tin, Facade.Plain, m);
+ Record(s.Id, "barracks", p, yaw, w, d, bh, timber);
+ n++;
+ }
+ return n;
+ }
+ }
+}
diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.Camp.cs.meta b/unity/Assets/Scripts/Map/Kits/SettlementKits.Camp.cs.meta
new file mode 100644
index 000000000..fcc29fbff
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.Camp.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: bbfa8d2df1c020472a0c590e7496d618
\ No newline at end of file
diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs b/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs
index cad6330bd..2e5a738ef 100644
--- a/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs
+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.Landmarks.cs
@@ -16,6 +16,7 @@ namespace Statecraft.Game.Map.Kits
float R = FootprintRadiusM(s, ground.HexSizeM);
var heart = DryNear(centre, ground, R * 0.3f, ref rnd);
if (NegevOutpost(s)) return NegevOutpostKit(s, heart, ground, km, lots); // a Negev lookout's yard (#32)
+ if (MilitaryCamp(s)) return MilitaryCampKit(s, heart, ground, km, lots); // a built camp's yard (#792)
switch (s.Id)
{
case "jaffa": return Jaffa(s, heart, ground, km, lots, ref rnd);
diff --git a/unity/Assets/Scripts/Map/Kits/SettlementKits.cs b/unity/Assets/Scripts/Map/Kits/SettlementKits.cs
index 60540c8e0..c2a16521f 100644
--- a/unity/Assets/Scripts/Map/Kits/SettlementKits.cs
+++ b/unity/Assets/Scripts/Map/Kits/SettlementKits.cs
@@ -221,8 +221,9 @@ namespace Statecraft.Game.Map.Kits
}
var km = townMeshes[s.Id];
// A Negev lookout's buildings stand in its walled yard, a landmark (SettlementKits.Outpost.cs, #32): no houses round it.
+ // Nor round a camp's barracks (SettlementKits.Camp.cs, #792).
System.Func<int>? scatter = null, palms = null;
- int n = landmarks[s.Id] + (NegevOutpost(s) ? 0
+ int n = landmarks[s.Id] + (NegevOutpost(s) || MilitaryCamp(s) ? 0
: PlaceHouses(s, centres[s.Id], ground, km, lots, ref rnd, merged, out scatter, out palms)); // towns round 2: plot lattices
gameTowns.Add((s, km, n, scatter, palms));
}
diff --git a/unity/Assets/Scripts/Map/SiteLayer.cs b/unity/Assets/Scripts/Map/SiteLayer.cs
index 1de1feb64..891ec2779 100644
--- a/unity/Assets/Scripts/Map/SiteLayer.cs
+++ b/unity/Assets/Scripts/Map/SiteLayer.cs
@@ -11,8 +11,9 @@ namespace Statecraft.Game.Map
/// <summary>GDD Phase 1 PR 8 (#381): the designated sites the player builds on (sites.yaml, State.Sites).
/// <list type="bullet">
/// <item>A built site is drawn as a rural kit on its hex (SettlementKits, as a kibbutz: the one archetype a new yishuv has
- /// in Phase 1), named <see cref="Prefix"/> + its id. With the map's "kits" toggle off, it is the kibbutz marker box, as the
- /// settlements are (KitLayer).</item>
+ /// in Phase 1), or a built camp as a camp kit (SettlementKits.Camp.cs, #792; <see cref="KitOf"/>), named
+ /// <see cref="Prefix"/> + its id. With the map's "kits" toggle off, it is the kibbutz marker box, as the settlements are
+ /// (KitLayer).</item>
/// <item>A site being built is a scaffold marker: an open frame of raw timber on its hex, named Prefix + id +
/// <see cref="ScaffoldSuffix"/>.</item>
/// <item>An available site, with no record, draws nothing.</item>
@@ -36,6 +37,9 @@ namespace Statecraft.Game.Map
/// <summary>The built sites as places (Prefix + id, the site's name, a kibbutz on its hex), for their name pills
/// (MapLabelsPresenter.SetSites).</summary>
public IReadOnlyList<Settlement> Places => places;
+ readonly List<SettlementKits.Placed> placed = new List<SettlementKits.Placed>();
+ /// <summary>What the built sites' kits placed (SettlementKits.Placed, by site place id), as Render drew them (tests).</summary>
+ internal IReadOnlyList<SettlementKits.Placed> Placed => placed;
List<SiteWork>? lastSites; Content? lastContent; MapScene? lastMap; bool kitsShown;
@@ -57,11 +61,11 @@ namespace Statecraft.Game.Map
if (Application.isPlaying) { old.transform.SetParent(null); Destroy(old); if (own != null) Destroy(own); }
else { DestroyImmediate(old); if (own != null) DestroyImmediate(own); }
}
- columns.Clear(); places.Clear();
+ columns.Clear(); places.Clear(); placed.Clear();
var list = sites.ToList();
lastSites = list; lastContent = content; lastMap = map; kitsShown = map.KitsShown;
var block = new MaterialPropertyBlock();
- var built = new List<Settlement>();
+ var built = new List<Settlement>(); var kitPlaces = new List<Settlement>();
foreach (var w in list)
{
var site = content.Sites.FirstOrDefault(x => x.Id == w.Site);
@@ -71,9 +75,10 @@ namespace Statecraft.Game.Map
at.y = map.Terrain.SampleHeight(at) + map.Terrain.transform.position.y;
if (w.BuiltOn == null) { Scaffold(Prefix + w.Site + ScaffoldSuffix, at, cube, map, block); continue; }
built.Add(new Settlement { Id = Prefix + w.Site, Name = site.Name, NameHe = site.NameHe, Type = "kibbutz", Lon = hex.Lon, Lat = hex.Lat });
+ kitPlaces.Add(KitOf(site, built[built.Count - 1]));
}
places.AddRange(built);
- var drawn = kitsShown && built.Count > 0 ? Kits(built, map) : new HashSet<string>();
+ var drawn = kitsShown && built.Count > 0 ? Kits(kitPlaces, map) : new HashSet<string>();
foreach (var s in built.Where(s => !drawn.Contains(s.Id)))
{
// No kit (toggle off, or no free ground): the kibbutz marker box, as SettlementPlacer draws the settlements.
@@ -86,10 +91,16 @@ namespace Statecraft.Game.Map
}
}
+ /// <summary>What a built site's kit is built from: a camp site's place as a camp (SettlementKits.CampType, its barracks
+ /// yard), any other built site's place as it is, a kibbutz (the rural kit). Its pill and its box stay the kibbutz's.</summary>
+ internal static Settlement KitOf(Site site, Settlement place) => !site.Kinds.Contains(SettlementKits.CampType) ? place
+ : new Settlement { Id = place.Id, Name = place.Name, NameHe = place.NameHe, Type = SettlementKits.CampType, Lon = place.Lon, Lat = place.Lat };
+
/// <summary>Draws the built sites as kits (one object each, Kit.mat), keeps their columns, and returns the ids drawn.</summary>
HashSet<string> Kits(List<Settlement> built, MapScene map)
{
- var kits = SettlementKits.Build(built, PlacementLayer.CampGround(map), out _, columns);
+ var kits = SettlementKits.Build(built, PlacementLayer.CampGround(map), out _, out var census, columns);
+ placed.AddRange(census);
var drawn = new HashSet<string>();
foreach (var (s, mesh, _) in kits)
{
diff --git a/unity/Assets/Tests/EditMode/SettlementPlacerTests.cs b/unity/Assets/Tests/EditMode/SettlementPlacerTests.cs
new file mode 100644
index 000000000..16caac353
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/SettlementPlacerTests.cs
@@ -0,0 +1,81 @@
+#nullable enable
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game;
+using Statecraft.Game.Map;
+using Statecraft.Game.Map.Kits;
+using Statecraft.Sim;
+using UnityEditor;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+using Object = UnityEngine.Object;
+
+/// <summary>GDD Phase 4 PR 8, item 3 (#792): a built site draws the kit of what was built there. A built yishuv is a rural kit
+/// (a kibbutz's houses and its dining hall), a built camp is a camp kit (a fenced yard of barracks), never the other's.</summary>
+public class SettlementPlacerTests
+{
+ static readonly Content C = ContentLoader.Load(Paths.Content);
+
+ /// <summary>The game's map scene (Map.unity, with its kit materials and town models), built: SiteLayer draws kits only
+ /// when the map does.</summary>
+ static MapScene Map()
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var map = Object.FindFirstObjectByType<MapScene>();
+ map.Build();
+ return map;
+ }
+
+ /// <summary>Renders <paramref name="id"/> built, checks a kit (not the marker box) stands on the site's hex, and returns the
+ /// kinds of what SiteLayer itself placed for that site (SiteLayer.Placed).</summary>
+ static List<string> BuiltKitKinds(string id)
+ {
+ var map = Map();
+ var layer = new GameObject("Sites").AddComponent<SiteLayer>();
+ layer.Render(new[] { SiteWork.Built(id, new DateTime(1949, 6, 30)) }, C, map);
+ var site = C.Sites.Single(x => x.Id == id);
+ var place = layer.Places.Single();
+ Assert.AreEqual(SiteLayer.Prefix + id, place.Id, "the site's place");
+ Assert.IsTrue(map.KitsShown, "the map draws kits, so the hex check below runs");
+ var drawn = layer.transform.GetChild(0);
+ Assert.AreNotEqual("Cube", drawn.GetComponent<MeshFilter>().sharedMesh.name, "a kit, not the marker box");
+ var b = drawn.GetComponent<MeshRenderer>().bounds;
+ Assert.AreEqual((site.Q, site.R), MapPointer.Pick(map, b.center), "the kit stands on the site's hex");
+ return layer.Placed.Where(p => p.Id == place.Id).Select(p => p.Kind).ToList();
+ }
+
+ [Test]
+ public void ABuiltYishuvDrawsAKit()
+ {
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ try
+ {
+ var kinds = BuiltKitKinds("mefalsim");
+ Assert.Contains("dining_hall", kinds, "a kibbutz's dining hall: the rural kit");
+ Assert.IsFalse(kinds.Contains("camp_yard") || kinds.Contains("barracks"), "no camp parts: " + string.Join(", ", kinds));
+ }
+ finally { EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); }
+ }
+
+ [Test]
+ public void ABuiltCampDrawsACampKit()
+ {
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ try
+ {
+ var camps = C.Sites.Where(s => s.Kinds.Contains("military_camp")).Select(s => s.Id).ToList();
+ CollectionAssert.IsSubsetOf(new[] { "camp_80", "tzrifin" }, camps, "sites.yaml's camp sites");
+ foreach (var id in camps)
+ {
+ var kinds = BuiltKitKinds(id);
+ Assert.AreEqual(1, kinds.Count(k => k == "camp_yard"), id + ": one fenced yard");
+ Assert.GreaterOrEqual(kinds.Count(k => k == "barracks"), 4, id + ": rows of barracks");
+ Assert.IsFalse(kinds.Contains("dining_hall") || kinds.Contains("building"), id + ": no kibbutz parts: " + string.Join(", ", kinds));
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ }
+ }
+ finally { EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); }
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/SettlementPlacerTests.cs.meta b/unity/Assets/Tests/EditMode/SettlementPlacerTests.cs.meta
new file mode 100644
index 000000000..17f2c7571
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/SettlementPlacerTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: fb23194340b686bc5ad5b20fd4d5b986
\ No newline at end of file