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.

Hex panel: a workshop's pause shows under that workshop only (Refs #2711) (#2908)

Beri895d90016d05
diff --git a/changelog.d/2711-workshop-pause-own.md b/changelog.d/2711-workshop-pause-own.md
new file mode 100644
index 000000000..87de4387c
--- /dev/null
+++ b/changelog.d/2711-workshop-pause-own.md
@@ -0,0 +1,4 @@
+### Fixed
+
+- Under the gdd-0.3 rules, when one of a city's arms workshops paused last turn, the hex panel now shows the pause under
+ that workshop only, not under every workshop in the city (R-ARMS-006, Refs #2711).
diff --git a/sim/Statecraft.Sim.Tests/ArmsWorkshopTests.cs b/sim/Statecraft.Sim.Tests/ArmsWorkshopTests.cs
index 7ee076907..b4bbf18eb 100644
--- a/sim/Statecraft.Sim.Tests/ArmsWorkshopTests.cs
+++ b/sim/Statecraft.Sim.Tests/ArmsWorkshopTests.cs
@@ -610,7 +610,7 @@ public class ArmsWorkshopTests
if (paid) { Assert.Empty(waits); return; }
var line = Assert.Single(waits);
Assert.Equal((Workshops.DebtCeiling, "Town A: an arms workshop's next cycle waits: paying for it would take the debt past its ceiling"),
- (line.Args.Single(), line.Message));
+ (line.Args[0], line.Message));
Assert.Null(r.State.Workshops[id].PaidCost);
Assert.DoesNotContain(r.Why, w => w.Key == CauseKeys.Borrowed && w.Args[0] == CauseKeys.Purpose.Workshop);
}
@@ -667,7 +667,7 @@ public class ArmsWorkshopTests
var r = Step(c, s);
Assert.Equal((5m, 1), (r.State.Workshops[id].PaidCost, r.State.Workshops[id].Progress));
var line = Assert.Single(r.Why, w => w.Key == CauseKeys.WorkshopPaused);
- Assert.Equal((Workshops.NoWorker, "Town A: an arms workshop has no worker without a job this month"), (line.Args.Single(), line.Message));
+ Assert.Equal((Workshops.NoWorker, "Town A: an arms workshop has no worker without a job this month"), (line.Args[0], line.Message));
}
// R-ARMS-006: the cycle runs under gdd-0.3 only. A gdd-0.1 state that somehow holds a staffed workshop one month from its
@@ -768,7 +768,9 @@ public class ArmsWorkshopTests
Assert.Single(Charges(r));
Assert.Equal((5m, 1), (r.State.Workshops[first].PaidCost, r.State.Workshops[first].Progress));
Assert.Equal(((decimal?)null, 0), (r.State.Workshops[second].PaidCost, r.State.Workshops[second].Progress));
- Assert.Equal(Workshops.NoWorker, Assert.Single(r.Why, w => w.Key == CauseKeys.WorkshopPaused).Args.Single());
+ var waits = Assert.Single(r.Why, w => w.Key == CauseKeys.WorkshopPaused);
+ // #2711: the cause names the workshop that waited, so the hex panel shows it under that workshop only.
+ Assert.Equal((Workshops.NoWorker, second.ToString(System.Globalization.CultureInfo.InvariantCulture)), (waits.Args[0], waits.Args[1]));
}
// R-TRAIN-001, R-QUAL-005 with R-ARMS-005: a staffed workshop's worker holds no job but is not idle, so neither Train
diff --git a/sim/Statecraft.Sim/Cause.cs b/sim/Statecraft.Sim/Cause.cs
index e2a869b80..8f7ee33d6 100644
--- a/sim/Statecraft.Sim/Cause.cs
+++ b/sim/Statecraft.Sim/Cause.cs
@@ -146,7 +146,7 @@ namespace Statecraft.Sim
public const string WorkshopWorkers = "workshop_workers";
/// <summary>R-ARMS-006: an arms workshop's cycle made 1 Arms. Args: none.</summary>
public const string WorkshopArms = "workshop_arms";
- /// <summary>R-ARMS-006: a staffed arms workshop did not work this month. Args: Workshops.NoWorker or Workshops.DebtCeiling.</summary>
+ /// <summary>R-ARMS-006: a staffed arms workshop did not work this month. Args: Workshops.NoWorker or Workshops.DebtCeiling, then the workshop's project id (invariant text).</summary>
public const string WorkshopPaused = "workshop_paused";
/// <summary>Args: CauseKeys.Number(amount), the US$ millions converted.</summary>
public const string DollarsConverted = "dollars_converted";
diff --git a/sim/Statecraft.Sim/Workshops.cs b/sim/Statecraft.Sim/Workshops.cs
index ccb7f0799..3ce577cdb 100644
--- a/sim/Statecraft.Sim/Workshops.cs
+++ b/sim/Statecraft.Sim/Workshops.cs
@@ -157,7 +157,7 @@ namespace Statecraft.Sim
if (!working.TryGetValue(city, out var taken)) taken = Projects.Builders(s, city);
if (taken >= x.Civilians + x.Craftsmen - x.Employed)
{
- why.Add(new Cause("city", city, 0, $"{name}: an arms workshop has no worker without a job this month", key: CauseKeys.WorkshopPaused, args: new[] { NoWorker }));
+ why.Add(new Cause("city", city, 0, $"{name}: an arms workshop has no worker without a job this month", key: CauseKeys.WorkshopPaused, args: new[] { NoWorker, w.Project.ToString(System.Globalization.CultureInfo.InvariantCulture) }));
continue;
}
working[city] = taken + 1;
@@ -168,7 +168,7 @@ namespace Statecraft.Sim
var left = s.Treasury - (double)price; // R-MONEY-003's debt after: the debt plus what the Treasury lacks
if (left < 0 && s.Debt - left > ceiling)
{
- why.Add(new Cause("city", city, 0, $"{name}: an arms workshop's next cycle waits: paying for it would take the debt past its ceiling", key: CauseKeys.WorkshopPaused, args: new[] { DebtCeiling }));
+ why.Add(new Cause("city", city, 0, $"{name}: an arms workshop's next cycle waits: paying for it would take the debt past its ceiling", key: CauseKeys.WorkshopPaused, args: new[] { DebtCeiling, w.Project.ToString(System.Globalization.CultureInfo.InvariantCulture) }));
continue;
}
EconomySystem.PayOrBorrow(c, s, (double)price, "for an arms workshop cycle", why, CauseKeys.Purpose.Workshop);
diff --git a/unity/Assets/Scripts/UI/GddHexPanel.cs b/unity/Assets/Scripts/UI/GddHexPanel.cs
index cfc8bd149..65b33c387 100644
--- a/unity/Assets/Scripts/UI/GddHexPanel.cs
+++ b/unity/Assets/Scripts/UI/GddHexPanel.cs
@@ -495,7 +495,7 @@ namespace Statecraft.Game.UI
else if (Workshops.NextCyclePrice(c, s, project.Id) is decimal next)
Line(host, "city-workshop-cycle", text.Format("city.workshop_next", PlayerText.Money(c, "treasury", (double)next)));
if (Cities.Held(c, s).Contains(city)) Line(host, "city-workshop-held", text.Format("city.workshop_held", townName(city)));
- var paused = (bridge.Session.Last?.Why ?? Array.Empty<Cause>()).Where(x => x.Key == CauseKeys.WorkshopPaused && x.Target == city)
+ var paused = (bridge.Session.Last?.Why ?? Array.Empty<Cause>()).Where(x => x.Key == CauseKeys.WorkshopPaused && x.Target == city && x.Args.Count > 1 && x.Args[1] == project.Id.ToString(CultureInfo.InvariantCulture))
.Select(x => CauseText.Line(x, c, Array.Empty<Statecraft.Game.Map.Units.UnitEntry>(), text, bridge.TownNamesHe)).Distinct().ToList();
for (int i = 0; i < paused.Count; i++) Line(host, "city-workshop-paused-" + i.ToString(CultureInfo.InvariantCulture), paused[i]);
}
diff --git a/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs b/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs
index 39641bd23..756863829 100644
--- a/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs
+++ b/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs
@@ -734,17 +734,19 @@ public class WorkshopPanelTests
public void AStaffedWorkshopShowsItsCycleAndWhyItWaits([Values] bool hebrew)
{
var t = hebrew ? He : En;
- var paused = new Cause("city", City, 0, "Haifa: an arms workshop has no worker without a job this month", key: CauseKeys.WorkshopPaused, args: new[] { Workshops.NoWorker });
+ Cause? paused = null;
using (var ui = new UiTestKit())
{
var (bridge, _) = Game(C03, t, edit: (s, id) =>
{
+ paused = new Cause("city", City, 0, "Haifa: an arms workshop has no worker without a job this month", key: CauseKeys.WorkshopPaused,
+ args: new[] { Workshops.NoWorker, id.ToString(System.Globalization.CultureInfo.InvariantCulture) }); // #2711: the cause names its workshop
s.Workshops.Add(id, new Workshop(id, true, SyntheticWorkshopTier.Ordinary, 5m, 1)); // a cycle paid IL 5m, 1 month in
var enemy = s.Units.Values.First(u => u.Side != "" && u.Side != Movement.PlayerSide);
var home = C03.SettlementHexes.First(h => h.Id == City);
var uid = s.NextId++;
s.Units.Add(uid, new Unit(uid, enemy.Type, home.Q, home.R, side: enemy.Side, strength: enemy.Strength));
- }, last: g => new StepResult(g.State, new[] { paused }, Array.Empty<Rejection>()));
+ }, last: g => new StepResult(g.State, new[] { paused! }, Array.Empty<Rejection>()));
using var panel = Panel(ui, bridge, t);
var (q, r) = Hex(C03);
panel.Show(q, r);
@@ -754,7 +756,7 @@ public class WorkshopPanelTests
ui.Q<Label>("city-workshop-cycle").text, "the record's paid cost and the sim's cycle length");
Assert.IsTrue(Cities.Held(C03, bridge.State).Contains(City), "precondition: the enemy holds Haifa");
Assert.AreEqual(t.Format("city.workshop_held", hebrew ? TownsHe[City] : Towns[City]), ui.Q<Label>("city-workshop-held").text);
- Assert.AreEqual(CauseText.Line(paused, C03, Array.Empty<Statecraft.Game.Map.Units.UnitEntry>(), t, TownsHe), ui.Q<Label>("city-workshop-paused-0").text);
+ Assert.AreEqual(CauseText.Line(paused!, C03, Array.Empty<Statecraft.Game.Map.Units.UnitEntry>(), t, TownsHe), ui.Q<Label>("city-workshop-paused-0").text);
}
using (var ui = new UiTestKit())
{
@@ -834,6 +836,34 @@ public class WorkshopPanelTests
Assert.IsTrue(string.Equals(TownsHe[City] + ": אין די אזרחים ובעלי מלאכה ללא משרה (יש\u00A0\u200E1\u200E)", noJob, StringComparison.Ordinal), noJob);
}
+ // #2711 item 2, R-ARMS-006: workshops pause one by one, so a city with two staffed workshops shows the pause under the one
+ // it names (the cause's second arg is the project id) and not under the other.
+ [Test]
+ public void APausedWorkshopShowsItsPauseUnderItselfAndNotUnderTheCitysOtherWorkshop([Values] bool hebrew)
+ {
+ var t = hebrew ? He : En;
+ var second = 0;
+ Cause Paused() => new Cause("city", City, 0, "Haifa: an arms workshop has no worker without a job this month", key: CauseKeys.WorkshopPaused,
+ args: new[] { Workshops.NoWorker, second.ToString(System.Globalization.CultureInfo.InvariantCulture) });
+ var (bridge, first) = Game(C03, t, employed: 8, edit: (s, id) =>
+ {
+ second = SecondWorkshop(C03, s);
+ foreach (var w in new[] { id, second }) s.Workshops.Add(w, new Workshop(w, true, SyntheticWorkshopTier.Ordinary));
+ },
+ last: g => new StepResult(g.State, new[] { Paused() }, Array.Empty<Rejection>()));
+ var line = CauseText.Line(Paused(), C03, Array.Empty<Statecraft.Game.Map.Units.UnitEntry>(), t, TownsHe);
+ foreach (var (id, shown) in new[] { (first, false), (second, true) })
+ {
+ using var ui = new UiTestKit();
+ using var panel = Panel(ui, bridge, t);
+ var hex = bridge.State.CityProjects[id];
+ panel.Show(hex.Q, hex.R);
+ Assert.AreEqual(t["city.workshop_staffed"], ui.Q<Label>("city-workshop-state").text, "precondition: this workshop's own panel");
+ if (shown) Assert.AreEqual(line, ui.Q<Label>("city-workshop-paused-0").text, "the workshop that paused");
+ else Assert.IsNull(ui.Root.Q("city-workshop-paused-0"), "the city's other workshop did not pause");
+ }
+ }
+
// R-ARMS-005 (#1722 review, C7): two built, one person free. + orders one; with that order queued, + is off and the
// sim's refusal for a second shows (one of two ordered, so a workshop is still left unstaffed).
[Test]