Skip to content

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

Map: built city projects are drawn through the placement layer (Fixes #1123, refs #739) (#1146)

Beri73373c55e466
diff --git a/changelog.d/map-built-city-projects-1123.md b/changelog.d/map-built-city-projects-1123.md
new file mode 100644
index 000000000..eb7675b06
--- /dev/null
+++ b/changelog.d/map-built-city-projects-1123.md
@@ -0,0 +1,3 @@
+- A finished city project shows on the map: a built housing project or transit camp is drawn on its hex the way the
+ map action of the same kind is (the box, or the ma'abara kit for a camp), and a project still being built is not.
+ `State.Placements` is unchanged; an industry project has no approved art yet and is not drawn (#1123, refs #739).
diff --git a/unity/Assets/Scripts/Map/PlacementLayer.cs b/unity/Assets/Scripts/Map/PlacementLayer.cs
index 584ea2438..3d24a3422 100644
--- a/unity/Assets/Scripts/Map/PlacementLayer.cs
+++ b/unity/Assets/Scripts/Map/PlacementLayer.cs
@@ -32,6 +32,17 @@ namespace Statecraft.Game.Map
Render(lastPlacements, lastContent, lastMap);
}
+ /// <summary>What the layer draws for a state (#1123): its placements, then each built city project whose kind has a look
+ /// here, as a placement of that kind on its hex dated the day it was built (project kind ids are the map actions' ids).
+ /// A project still being built is left out, so it never looks finished; so is a kind with no approved art (industry).</summary>
+ internal static List<Placement> Drawn(IEnumerable<Placement> placements, IEnumerable<CityProject> projects)
+ {
+ var list = new List<Placement>(placements);
+ foreach (var p in projects)
+ if (p.BuiltOn is System.DateTime on && Look.ContainsKey(p.Kind)) list.Add(new Placement(p.Kind, p.Q, p.R, on));
+ return list;
+ }
+
public void Render(IEnumerable<Placement> placements, Content content, MapScene map)
{
var cube = Resources.GetBuiltinResource<Mesh>("Cube.fbx");
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
index a97167516..9fc4e5896 100644
--- a/unity/Assets/Scripts/UI/GameRoot.cs
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -16,7 +16,7 @@ namespace Statecraft.Game.UI
/// <summary>Starts the game once GameBoot has loaded the inputs and built the map (GameBoot.Ready): continues the
/// autosave or starts a new game (GameStart.Begin, with its notes in the toast), creates every screen, autosaves each
/// turn, and wires the camera and the map pointer to the game panel (UiPointer.IsOverUi), map clicks to the info panel,
- /// the minimap to the camera, and State.Placements to the placement layer. Disabling it disposes all of that.
+ /// the minimap to the camera, and State.Placements with the built city projects to the placement layer. Disabling it disposes all of that.
/// With "smoke" in the page URL (WebGL, e.g. ?smoke=5) or -smoke N (desktop) it starts a fresh game with the golden
/// seed (the player's autosave is neither read nor written), plays N turns through the UI's own buttons and logs
/// "SMOKE OK ..." (or "SMOKE FAIL ..."). In a player, unless an automated run skips it (StartScreenPresenter.Skipped),
@@ -586,8 +586,9 @@ namespace Statecraft.Game.UI
if (map != null && map.Terrain != null) map.Terrain.heightmapPixelError = MapBuilder.TerrainPixelError;
}
- /// <summary>Draws the placements only when State.Placements differs from what was drawn (every order and every turn
- /// raises Changed; rebuilding the markers each time would be wasted work).</summary>
+ /// <summary>Draws the placements only when State.Placements with the built city projects (PlacementLayer.Drawn, #1123)
+ /// 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;
@@ -608,10 +609,11 @@ namespace Statecraft.Game.UI
// 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();
- var now = Bridge.State.Placements.Select(p => (p.Action, p.Q, p.R, p.Date)).ToList();
+ var shown = PlacementLayer.Drawn(Bridge.State.Placements, Bridge.State.CityProjects.Values);
+ var now = shown.Select(p => (p.Action, p.Q, p.R, p.Date)).ToList();
if (drawn != null && drawn.SequenceEqual(now)) return;
drawn = now;
- placements.Render(Bridge.State.Placements, Bridge.Content, map);
+ placements.Render(shown, Bridge.Content, map);
}
/// <summary>Draws the designated sites (#381) only when a site's state differs from what was drawn: being built, or
diff --git a/unity/Assets/Tests/EditMode/GameSceneTests.cs b/unity/Assets/Tests/EditMode/GameSceneTests.cs
index f74ca3463..ba368e0ef 100644
--- a/unity/Assets/Tests/EditMode/GameSceneTests.cs
+++ b/unity/Assets/Tests/EditMode/GameSceneTests.cs
@@ -608,6 +608,43 @@ public class GameSceneTests
Assert.IsNotNull(layer.Cast<Transform>().SingleOrDefault(t => t.name == $"{MapActions.Housing}_{tlv.Q}_{tlv.R}"));
}
+ // #1123: a built city project is drawn on its hex as its kind's placement; one still being built is not, and its
+ // completion redraws the layer though State.Placements did not change.
+ [Test]
+ public void BuiltCityProjectsAreDrawnAndUnfinishedOnesAreNot()
+ {
+ var root = Boot();
+ var c = Inputs.Content;
+ var g = GameSession.New(c, GoldenRun.Seed, Mode.Historical);
+ while (g.State.Date < new DateTime(1950, 8, 1)) g.Step(HistoricalAI.Commands(c, g.State));
+ var bridge = root.Bridge!;
+ bridge.Replace(g);
+ var layer = Object.FindFirstObjectByType<PlacementLayer>().transform;
+ bool Drawn(string kind, int q, int r) => layer.Cast<Transform>().Any(t => t.name == $"{kind}_{q}_{r}");
+ var placements = bridge.State.Placements.Count;
+ var tlv = c.SettlementHexes.Single(s => s.Id == "tel_aviv");
+ var near = c.Hexes.First(h => MapActions.Distance(h.Q, h.R, tlv.Q, tlv.R) == 1
+ && Projects.CheckCity(c, bridge.State, MapActions.Housing, "tel_aviv", h.Q, h.R) == null);
+ Assert.IsNull(bridge.Queue(new StartProject(MapActions.TransitCamp, "tel_aviv", tlv.Q, tlv.R)));
+ Assert.IsNull(bridge.Queue(new StartProject(MapActions.Housing, "tel_aviv", near.Q, near.R)));
+ bridge.EndTurn();
+ var camp = bridge.State.CityProjects.Values.Single(p => p.Kind == MapActions.TransitCamp && p.Q == tlv.Q && p.R == tlv.R);
+ var housing = bridge.State.CityProjects.Values.Single(p => p.Kind == MapActions.Housing && p.Q == near.Q && p.R == near.R);
+ // The minister multiplier scales the progress (#1147; 0.81 here), so the camp's one turn can take two: end turns until it is built.
+ for (int i = 0; i < 10 && bridge.State.CityProjects[camp.Id].BuiltOn == null; i++) bridge.EndTurn();
+ Assert.IsNotNull(bridge.State.CityProjects[camp.Id].BuiltOn, "the transit camp is built");
+ Assert.IsNull(bridge.State.CityProjects[housing.Id].BuiltOn, "the housing, six turns at the same multiplier, is not");
+ Assert.AreEqual(placements, bridge.State.Placements.Count, "a city project is not a legacy placement");
+ Assert.AreEqual(placements + 1, layer.childCount, "the built camp is drawn beside the placements");
+ Assert.IsTrue(Drawn(MapActions.TransitCamp, tlv.Q, tlv.R), "the built camp is drawn on its hex");
+ Assert.IsFalse(Drawn(MapActions.Housing, near.Q, near.R), "unfinished housing is not drawn as built");
+ for (int i = 0; i < 10 && bridge.State.CityProjects[housing.Id].BuiltOn == null; i++) bridge.EndTurn();
+ Assert.IsNotNull(bridge.State.CityProjects[housing.Id].BuiltOn);
+ Assert.AreEqual(placements, bridge.State.Placements.Count);
+ Assert.IsTrue(Drawn(MapActions.Housing, near.Q, near.R), "finishing the housing redraws the layer");
+ Assert.IsTrue(Drawn(MapActions.TransitCamp, tlv.Q, tlv.R));
+ }
+
// Amendment A2: the smoke run answers a pending event by pressing the card's option button.
[Test]
public void TheSmokeRunAnswersAPendingEventThroughTheCard()
diff --git a/unity/Assets/Tests/EditMode/MapActionUiTests.cs b/unity/Assets/Tests/EditMode/MapActionUiTests.cs
index 5fe78f7cb..7e403f806 100644
--- a/unity/Assets/Tests/EditMode/MapActionUiTests.cs
+++ b/unity/Assets/Tests/EditMode/MapActionUiTests.cs
@@ -190,6 +190,46 @@ public class MapActionUiTests
finally { EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); }
}
+ // #1123: a built city project is drawn on its recorded hex as its kind's placement; one still being built, and a kind
+ // with no approved art (industry), are not; the legacy placements are drawn as before.
+ [Test]
+ public void BuiltCityProjectsAreDrawnOnTheirHexes()
+ {
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ try
+ {
+ new GameObject("TestMainCamera") { tag = "MainCamera" }.AddComponent<Camera>();
+ var map = new GameObject("MapScene").AddComponent<MapScene>();
+ map.Configure(AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/Terrain.mat"),
+ AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/SettlementMarker.mat"),
+ AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/HexSelection.mat"),
+ AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/Sea.mat"),
+ AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/MapFrame.mat"));
+ map.Build();
+ var layer = new GameObject("Placements").AddComponent<PlacementLayer>();
+ var hexes = C.SettlementHexes.Select(s => (s.Id, s.Q, s.R)).GroupBy(h => (h.Q, h.R)).Select(g => g.First()).Take(5).ToList();
+ var built = new DateTime(1950, 9, 30);
+ var legacy = new[] { new Placement(MapActions.Housing, hexes[0].Q, hexes[0].R, new DateTime(1950, 8, 26)) };
+ var projects = new[]
+ {
+ new CityProject(1, MapActions.Housing, hexes[1].Id, hexes[1].Q, hexes[1].R, 0, built),
+ new CityProject(2, MapActions.TransitCamp, hexes[2].Id, hexes[2].Q, hexes[2].R, 0, built),
+ new CityProject(3, MapActions.Housing, hexes[3].Id, hexes[3].Q, hexes[3].R, 4), // being built
+ new CityProject(4, "industry", hexes[4].Id, hexes[4].Q, hexes[4].R, 0, built), // no approved art
+ };
+ CollectionAssert.AreEqual(legacy, PlacementLayer.Drawn(legacy, new CityProject[0]), "no projects: the placements as they are");
+ layer.Render(PlacementLayer.Drawn(legacy, projects), C, map);
+ CollectionAssert.AreEquivalent(new[]
+ {
+ $"housing_{hexes[0].Q}_{hexes[0].R}", $"housing_{hexes[1].Q}_{hexes[1].R}", $"transit_camp_{hexes[2].Q}_{hexes[2].R}",
+ }, layer.transform.Cast<Transform>().Select(t => t.name).ToList());
+ var box = layer.transform.Cast<Transform>().Single(t => t.name == $"housing_{hexes[1].Q}_{hexes[1].R}");
+ Assert.AreEqual((hexes[1].Q, hexes[1].R), MapPointer.Pick(map, box.position), "drawn on the project's recorded hex");
+ Assert.AreEqual(built, PlacementLayer.Drawn(legacy, projects)[1].Date, "dated the day it was built");
+ }
+ finally { EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); }
+ }
+
[Test]
public void TheInfoPanelShowsNoTileYields()
{