A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
UI: offer the gdd-0.3 housing repair on a built-on city hex (Refs #1700) (#2499)
Eyal Golan32fde46bd625
diff --git a/changelog.d/1700-repair-occupied-hex.md b/changelog.d/1700-repair-occupied-hex.mdnew file mode 100644index 000000000..d221b518e--- /dev/null+++ b/changelog.d/1700-repair-occupied-hex.md@@ -0,0 +1,3 @@+- GDD 0.3 housing repair from a built-on city hex (Refs #1700): under the gdd-0.3 ruleset, when a city's own hex+ already holds a city project, the hex panel now offers the housing repair under that project's state, as the rules+ allow, instead of showing the project alone. The current game (gdd-0.1) is unchanged.diff --git a/unity/Assets/Scripts/UI/GddHexPanel.cs b/unity/Assets/Scripts/UI/GddHexPanel.csindex 35e577322..435c7117f 100644--- a/unity/Assets/Scripts/UI/GddHexPanel.cs+++ b/unity/Assets/Scripts/UI/GddHexPanel.cs@@ -316,7 +316,8 @@ namespace Statecraft.Game.UI}/// <summary>The city projects of hex (q, r) (#1122). A project there shows its state and, while it is built, Cancel- /// (R-PROJ-002). Else, for the cities in reach (Projects.CitiesFor; none: nothing shows), the city that builds: the one+ /// (R-PROJ-002); on a city's own hex the list below then holds only the gdd-0.3 housing repair (R-HOUSE-006, #1700),+ /// which the sim takes there whatever the hex holds. Else, for the cities in reach (Projects.CitiesFor; none: nothing shows), the city that builds: the one/// the player picked on this hex, else the queued order's, else the nearest. Build for each kind queues StartProject for/// that city and hex, one order a hex (SimBridge's key, so another kind or city replaces it); the Attention is the/// bridge's, which refuses an order it cannot pay for as for every order. On a city's own hex (<paramref name="cityHere"/>)@@ -326,22 +327,29 @@ namespace Statecraft.Game.UI{var c = bridge.Content; var s = bridge.State;string Kind(string id) => PlayerText.Capitalised(ContentNames.Of(text, c.ProjectKinds.First(x => x.Id == id)));+ var kinds = c.ProjectKinds;if (Projects.CityProjectAt(s, q, r) is CityProject project){if (project.BuiltOn is DateTime built){Line(host, "city-project-state", text.Format("city.project_built", Kind(project.Kind), townName(project.City), Date(text, built)));WorkshopPart(host, bridge, text, project, townName);- return;}- Line(host, "city-project-state", text.Format("city.project_building", Kind(project.Kind), townName(project.City), Turns(text, Projects.CityTurnsToBuild(c, s, project.Kind, project.TurnsLeft, project.Progress))));- var cancelled = bridge.QueuedLike(new CancelProject(project.Id)) != null;- Button(host, "city-project-cancel", text[cancelled ? "city.cancel_ordered" : "city.cancel"],- () => bridge.Queue(new CancelProject(project.Id))).SetEnabled(!cancelled);- return;+ else+ {+ Line(host, "city-project-state", text.Format("city.project_building", Kind(project.Kind), townName(project.City), Turns(text, Projects.CityTurnsToBuild(c, s, project.Kind, project.TurnsLeft, project.Progress))));+ var cancelled = bridge.QueuedLike(new CancelProject(project.Id)) != null;+ Button(host, "city-project-cancel", text[cancelled ? "city.cancel_ordered" : "city.cancel"],+ () => bridge.Queue(new CancelProject(project.Id))).SetEnabled(!cancelled);+ }+ // R-HOUSE-006 (#1700): the sim takes a gdd-0.3 housing repair on its city's own hex whatever that hex holds+ // (Projects.CheckCityReason), so on a city's own hex the repair is still offered under the project; every other+ // kind is refused for the project the line above names. No other ruleset loads the kind: nothing more shows.+ if (!cityHere) return;+ kinds = c.ProjectKinds.Where(k => k.Id == Projects.HousingRepair).ToList();}var cities = Projects.CitiesFor(c, s, q, r);- if (cities.Count == 0 || c.ProjectKinds.Count == 0) return;+ if (cities.Count == 0 || kinds.Count == 0) return;var queued = bridge.QueuedLike(new StartProject("", "", q, r)) as StartProject;// Owner ruling on #1150 (21 Oct 2026): under the city's own part the full list ran into the left column on a stacked// bar or a short window, so there it folds behind one toggle; a refusal is then one tap away. The open state is the@@ -349,7 +357,7 @@ namespace Statecraft.Game.UIvar list = host;if (cityHere){- Button(host, ToggleName, text.Format("city.projects_toggle", c.ProjectKinds.Count), () => host.ToggleInClassList(OpenClass));+ Button(host, ToggleName, text.Format("city.projects_toggle", kinds.Count), () => host.ToggleInClassList(OpenClass));list = new VisualElement { name = ListName };list.AddToClassList(ListName);host.Add(list);@@ -373,7 +381,7 @@ namespace Statecraft.Game.UIhost.Q("city-project-cities")?.Query<Button>().Where(b => b.enabledSelf).First()?.Focus();}).SetEnabled(id != city);}- var refusals = c.ProjectKinds.Select(k => Projects.CheckCityReason(c, s, k.Id, city, q, r)).ToList();+ var refusals = kinds.Select(k => Projects.CheckCityReason(c, s, k.Id, city, q, r)).ToList();var words = refusals.Select(x => x == null ? null : ReasonText(x, text, c, townName)).ToList();// Every kind refused for one reason (not land, a placement there, the turn's limit): said once, with no buttons,// as the map actions do (#398). A kind this city lacks the resource for (R-PROJ-005: the winery outside Rishon@@ -382,9 +390,9 @@ namespace Statecraft.Game.UIvar shared = words.Where((x, i) => refusals[i]?.Kind != "no_resource" && refusals[i]?.Kind != "repair_city_hex").ToList();if (words.All(x => x != null) && shared.Count > 0 && shared.Distinct().Count() == 1) { Line(list, "city-project-reason", shared[0]!); return; }// A kind the sim refuses shows its reason alone, which names the kind (no disabled Build above it: one line, not two).- for (int i = 0; i < c.ProjectKinds.Count; i++)+ for (int i = 0; i < kinds.Count; i++){- var k = c.ProjectKinds[i];+ var k = kinds[i];if (words[i] != null) { Line(list, $"city-project-{k.Id}-reason", words[i]!); continue; }var ordered = queued != null && queued.ProjectKind == k.Id && queued.City == city;Button(list, "city-project-" + k.Id, ordered ? text.Format("city.project_ordered", ContentNames.Of(text, k))diff --git a/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs b/unity/Assets/Tests/EditMode/CityProjectPanelTests.csindex 5e58e535f..12a89d41f 100644--- a/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs+++ b/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs@@ -198,6 +198,47 @@ public class CityProjectPanelTestsAssert.IsNull(ui.Root.Q("city-project-cancel"));}+ // R-HOUSE-006 (#1700): the sim takes a gdd-0.3 housing repair on its city's own hex whatever that hex holds+ // (Projects.CheckCityReason), so with a project there the panel shows that project's state and still offers the repair,+ // and no other kind (each is refused for the project, which the state line already says). gdd-0.1 has no repair kind,+ // so there the project's state is all, as before.+ [Test]+ public void ACitysOwnHexWithAProjectStillOffersTheRepair([Values] bool hebrew)+ {+ var t = hebrew ? He : En;+ foreach (var c in new[] { WorkshopPanelTests.Load03(), C })+ {+ var (q, r) = c.SettlementHexes.Where(x => x.Id == City).Select(x => (x.Q, x.R)).Single();+ var g = GameSession.New(c, GoldenRun.Seed, Mode.Historical);+ var id = g.State.NextId++;+ g.State.CityProjects.Add(id, new CityProject(id, "housing", City, q, r, 0).Built(g.State.Date));+ var bridge = new SimBridge(g, t);+ Assert.AreEqual(City, Projects.CitiesFor(c, bridge.State, q, r)[0], $"{c.Ruleset}: precondition, Haifa's own hex");+ using var ui = new UiTestKit();+ using var panel = Panel(ui, bridge, t);+ panel.Show(q, r);+ Assert.IsNotNull(ui.Root.Q("city-project-state"), $"{c.Ruleset}: the project's state shows");+ Assert.IsNull(ui.Root.Q("city-project-housing"), $"{c.Ruleset}: the hex is taken for every other kind");+ Assert.IsNull(ui.Root.Q("city-project-housing-reason"), $"{c.Ruleset}: not said twice");+ var repair = c.ProjectKinds.SingleOrDefault(k => k.Id == Projects.HousingRepair);+ if (c.Ruleset != SaveGame.Gdd03Ruleset)+ {+ Assert.IsNull(repair, "precondition: gdd-0.1 has no repair kind");+ Assert.IsNull(ui.Root.Q(GddHexPanel.ListName), "gdd-0.1: no list under the project");+ continue;+ }+ Assert.IsNull(Projects.CheckCityReason(c, bridge.State, Projects.HousingRepair, City, q, r), "precondition: the sim accepts the repair here");+ var button = ui.Q<Button>("city-project-" + Projects.HousingRepair);+ Assert.AreEqual(t.Format("city.project_start", ContentNames.Of(t, repair!), PlayerText.Money(c, "treasury", repair!.Cost),+ GddHexPanel.Turns(t, Projects.CityTurnsToBuild(c, bridge.State, repair.Id, repair.Turns, 0))), button.text);+ Assert.IsTrue(button.enabledSelf);+ ui.Press("city-project-" + Projects.HousingRepair);+ var order = (StartProject)bridge.Queued.Single();+ Assert.AreEqual((Projects.HousingRepair, City, q, r), (order.ProjectKind, order.City, order.Q, order.R));+ Assert.IsFalse(bridge.EndTurn().Rejected.Any(x => x.Command is StartProject), "the sim accepts the order the panel queued");+ }+ }+/// <summary>Each refusal the panel can meet, from the sim's validator, worded in the UI's language: one kind refused (the/// policy, a resource) under its own button; every kind refused for one reason (not land, a placement, the turn's limit)/// said once with no buttons.</summary>@@ -316,7 +357,7 @@ public class WorkshopPanelTestsconst string City = "haifa";/// <summary>The real content under gdd-0.3, as NoAttentionPresentationTests loads it.</summary>- static Content Load03()+ internal static Content Load03(){var dir = Paths.Content;return ContentLoader.Load(rel =>