A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
GDD 0.3 workshop panel: the next cycle's price and length come from the sim (#1722 follow-up) (#2315)
Eyal Golanee66a1fb3c0c
diff --git a/changelog.d/1722-workshop-followup.md b/changelog.d/1722-workshop-followup.mdnew file mode 100644index 000000000..b7ff4e0a7--- /dev/null+++ b/changelog.d/1722-workshop-followup.md@@ -0,0 +1,5 @@+### Fixed++- GDD 0.3 arms workshops (Refs #1722, Refs #1701): a built workshop that was never staffed shows its next cycle's price+ on the hex panel, and the panel takes that price and the cycle's length from the sim, so it shows the price the next+ cycle would cost.diff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex f8978ddfd..6fc41b3bd 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -432,7 +432,7 @@ R-ARMS-003: Recruit training (R-TRAIN-001) takes `arms_per_recruit_group` (1) ArR-ARMS-004: Under gdd-0.3 only, the arms workshop (`projects.yaml` `arms_workshop`, #1701) is a city project kind: `StartProject` builds it as R-PROJ-001 to R-PROJ-003 build any kind, for IL 15m and 3 turns (owner, 2 November 2026, #1701 OQ2: "IL 15m, 3 turns (Recommended)"; the gdd-0.3 catalogue's `arms_workshop` cost 15 and work 3). Built, it gives one workshop worker slot (`worker_slots: 1`, the catalogue's `arms_workshop.parts.worker_slots`) and adds no housing, condition or job slots: a workshop gives no Industry job (`docs/gdd/cities.md`, "Arms workshops"). Its row carries `rulesets: [gdd-0.3]`, and the loader leaves it out of every other ruleset's kinds, so a gdd-0.1 game neither lists nor starts it (`StartProject` refuses it as an unknown kind) and its state does not change; the row still moves the content hash. The loader refuses an unknown ruleset id in `rulesets`, `worker_slots` other than 0 or 1, a kind with a worker slot that has capacity, condition or job slots or is not limited to exactly gdd-0.3, and, under gdd-0.3, an `arms_workshop` whose worker slots differ from the catalogue's. It pays no upkeep: R-MONEY-002 has no rate for it (the catalogue's 0.50 is a Default). Its Hebrew name סדנת נשק is a draft awaiting a native speaker's review (`name_he_review: agent-checked`, #564; owner, 2 November 2026, #1701 OQ8).-R-ARMS-005: Under gdd-0.3, `AssignWorkers(city, "workshop", n)` is a standing order that staffs the city's first `n` built arms workshops, in ascending project id, and leaves the rest unstaffed (27M-13, owner-approved 1 November 2026: "Any free civilian. The cost tier follows the worker (novice or ordinary / apprentice / expert)."). A newly staffed workshop takes one of the city's civilians and craftsmen who hold no job; the worker stays one of them, with no job, profession or qualification change, is not employed (R-CITY-001) and earns no job income (R-CITY-002). On the aggregate cities every worker is priced at the ordinary or novice tier until the population ledger's tiers are live (owner, 2 November 2026, #1701 OQ6: "Accept all four (Recommended)"; R-POP-004). It is refused, state unchanged, for an unknown city, a negative count, more than the city's built workshops ("Town A has 1 arms workshop"), or more newly staffed workshops than the city's people without a job ("... civilians and craftsmen without a job"); under every other ruleset the `workshop` role is refused as "There is no such role". While the city's job default is on (R-CITY-009), a newly staffed workshop may take its worker from the default's jobs instead: the order is refused only past the city's civilians and craftsmen less its staffed workshops ("... civilians and craftsmen"), the city's employed falls to at most its civilians and craftsmen less the staffed workshops (a `city` cause, "Town: N groups in work"), and the default stays on, filling one job fewer (R-CITY-001; #2270 review fix, 2 November 2026). A number of jobs the player set (default off) is never lowered: there the order needs people without a job. A staffed workshop's worker is not idle: `Train` (R-TRAIN-001) and `ReassignPioneers` (R-QUAL-005) cannot take them, and the Train panel's limit (`Training.Available`) counts a pending `workshop` order's newly staffed workers, never as jobs. An unstaffed workshop keeps its record, paid cost and progress (a pause, R-ARMS-007). There is no limit on workshops per city beyond one project a hex and the starts a turn (R-PROJ-001; #1701 OQ7). `GameState.Workshops` holds every workshop ever staffed, by project id, and is hashed as `wshop[...]` only when it has one (R-LOOP-002). The hex panel of a built workshop (#1722, #1701 slice E) queues it: `Workshops.Check(city, n, pending)` gives the order's own refusal and, with this turn's queue, also counts the city's pending `job` order and its Train and reassignment orders, so a count it accepts is accepted whichever runs first; the jobs stepper's limit (`Cities.MaxWorkers` with the queue) counts a pending `workshop` order's newly staffed workers, as `Training.Available` does.+R-ARMS-005: Under gdd-0.3, `AssignWorkers(city, "workshop", n)` is a standing order that staffs the city's first `n` built arms workshops, in ascending project id, and leaves the rest unstaffed (27M-13, owner-approved 1 November 2026: "Any free civilian. The cost tier follows the worker (novice or ordinary / apprentice / expert)."). A newly staffed workshop takes one of the city's civilians and craftsmen who hold no job; the worker stays one of them, with no job, profession or qualification change, is not employed (R-CITY-001) and earns no job income (R-CITY-002). On the aggregate cities every worker is priced at the ordinary or novice tier until the population ledger's tiers are live (owner, 2 November 2026, #1701 OQ6: "Accept all four (Recommended)"; R-POP-004). It is refused, state unchanged, for an unknown city, a negative count, more than the city's built workshops ("Town A has 1 arms workshop"), or more newly staffed workshops than the city's people without a job ("... civilians and craftsmen without a job"); under every other ruleset the `workshop` role is refused as "There is no such role". While the city's job default is on (R-CITY-009), a newly staffed workshop may take its worker from the default's jobs instead: the order is refused only past the city's civilians and craftsmen less its staffed workshops ("... civilians and craftsmen"), the city's employed falls to at most its civilians and craftsmen less the staffed workshops (a `city` cause, "Town: N groups in work"), and the default stays on, filling one job fewer (R-CITY-001; #2270 review fix, 2 November 2026). A number of jobs the player set (default off) is never lowered: there the order needs people without a job. A staffed workshop's worker is not idle: `Train` (R-TRAIN-001) and `ReassignPioneers` (R-QUAL-005) cannot take them, and the Train panel's limit (`Training.Available`) counts a pending `workshop` order's newly staffed workers, never as jobs. An unstaffed workshop keeps its record, paid cost and progress (a pause, R-ARMS-007). There is no limit on workshops per city beyond one project a hex and the starts a turn (R-PROJ-001; #1701 OQ7). `GameState.Workshops` holds every workshop ever staffed, by project id, and is hashed as `wshop[...]` only when it has one (R-LOOP-002). The hex panel of a built workshop (#1722, #1701 slice E) queues it: `Workshops.Check(city, n, pending)` gives the order's own refusal and, with this turn's queue, also counts the city's pending `job` order and its Train and reassignment orders, so a count it accepts is accepted whichever runs first; the jobs stepper's limit (`Cities.MaxWorkers` with the queue) counts a pending `workshop` order's newly staffed workers, as `Training.Available` does. The panel's next-cycle price is `Workshops.NextCyclePrice`, what the production step would charge (R-ARMS-006), shown for a workshop never staffed too, at the ordinary or novice tier, and its cycle length is `Workshops.CycleMonths`. A jobs order past the city's civilians and craftsmen less its staffed workshops is refused with the staffing order's people format, "Town A has N civilians and craftsmen" (#1722 review).R-ARMS-006: On step 6 of the turn, after the cities' job income, in ascending project id, each staffed arms workshop under gdd-0.3 works this month when its city is not held (R-CITY-010) and one of the city's people without a job is left for it (each workshop of the city takes one, in ascending project id; when none is left for it, it waits, and the Why screen says so). A workshop with no cycle under way first pays for one there (27M-11: "At the monthly production step."), at its worker's tier from the gdd-0.3 catalogue: `workshop.cost` IL 5m / 4m / 3m (ordinary or novice / apprentice / expert; `docs/GDD.md`'s balance ruling: "`workshop.cost` is Money per Arms and stays."), beside the IL 1m an Arms of R-ARMS-002 (owner, 2 November 2026, #1701 OQ1: "Keep as ruled"). A short Treasury borrows the rest (R-MONEY-003; 27M-12: "Automatic each month while the workshop is staffed, paid like any GDD cost."), but a cycle whose borrowing would take the debt past `debt_ceiling` is not paid: the workshop waits that month, the turn report says why (below), and nothing is borrowed (owner, 2 November 2026, #1701 OQ4: "Refuse past the ceiling (Recommended)"; exactly at the ceiling is allowed, and a Treasury that pays in full is never refused, as in R-ARMS-002). The month a cycle is paid is its first staffed month (#1701 OQ3: "Accept all four (Recommended)"). After `workshop.staffed_turns` (3) staffed months the cycle adds 1 Arms to the stock (R-ARMS-001) and ends, and the next month starts the next one by itself, with no order. A worker change keeps the cycle's paid cost and progress; only the next cycle is priced at the new worker's tier (27M-13). An unstaffed workshop, or one in a held city, keeps its cycle as it is and is not charged. The turn-report panel lists, in a row of its own after the stocks, each Arms a workshop made ("Workshop in Town: +1 Arms") and each ceiling pause ("Workshop in Town paused: debt ceiling") (owner, 2 November 2026, #1701 A1: "Yes, in the panel (Recommended)", the option "The turn-report panel shows 'Workshop in <city>: +1 Arms' and 'Workshop in <city> paused: debt ceiling'."); a no-worker pause is on the Why screen only. A city's Arms are one line and its ceiling pauses another, each with its count when there are two or more ("Workshops in Town (2): +2 Arms", "Workshops in Town (2) paused: debt ceiling"), in the order each first appears among the turn's causes (owner, 2 November 2026: "Combine per city (Recommended)", the option "'Workshops in Tel Aviv (6): +6 Arms'; pauses likewise combined with a count."). The option gives no wording for one workshop, so a city with one keeps A1's line. The count is the number of the sim's causes; the UI computes nothing else.diff --git a/sim/Statecraft.Sim.Tests/ArmsWorkshopTests.cs b/sim/Statecraft.Sim.Tests/ArmsWorkshopTests.csindex 81eaad66d..5e879a6b4 100644--- a/sim/Statecraft.Sim.Tests/ArmsWorkshopTests.cs+++ b/sim/Statecraft.Sim.Tests/ArmsWorkshopTests.cs@@ -221,7 +221,8 @@ public class ArmsWorkshopTestsAssert.Equal(reason, Assert.Single(Step(c, s, order).Rejected).Reason);}- // R-ARMS-005: an order Check accepts is accepted; unstaffing (a lower count) is always accepted.+ // R-ARMS-005: an order Check accepts is accepted: staffing one, unstaffing it again (a lower count is always accepted),+ // and, with two built and one staffed, staffing both.[Fact]public void CheckAcceptsWhatTheTurnAccepts(){@@ -229,8 +230,38 @@ public class ArmsWorkshopTestsAssert.Null(Workshops.Check(c, s, "town_a", 1, Array.Empty<Command>()));var staffed = Step(c, s, Staff(1));Assert.Empty(staffed.Rejected);+ Assert.Equal(1, Workshops.Staffed(staffed.State, "town_a"));Assert.Null(Workshops.Check(c, staffed.State, "town_a", 0, Array.Empty<Command>()));- Assert.Equal(1, Workshops.Built(c, s, "town_a"));+ var off = Step(c, staffed.State, Staff(0));+ Assert.Empty(off.Rejected);+ Assert.Equal(0, Workshops.Staffed(off.State, "town_a"));+ var two = staffed.State.Clone();+ SecondWorkshop(two);+ Assert.Null(Workshops.Check(c, two, "town_a", 2, Array.Empty<Command>()));+ var both = Step(c, two, Staff(2));+ Assert.Empty(both.Rejected);+ Assert.Equal(2, Workshops.Staffed(both.State, "town_a"));+ }++ /// <summary>A second built arms workshop for town_a, on (2, 0); its id, above the first's.</summary>+ static int SecondWorkshop(GameState s)+ {+ var id = s.NextId++;+ s.CityProjects.Add(id, new CityProject(id, Workshops.ArmsWorkshop, "town_a", 2, 0, 0, s.Date));+ return id;+ }++ // R-ARMS-005 (#1722 review, H1): Check does not count the pending workshop order itself, only the job, Train and+ // reassignment orders beside it, so with two built, two free and one staffing order queued, two is still offered.+ [Fact]+ public void CheckIgnoresThePendingWorkshopOrderItself()+ {+ var (c, s, first) = Built(civilians: 10, employed: 8, jobs: 10, jobsDefault: false);+ var second = SecondWorkshop(s);+ Assert.Null(Workshops.Check(c, s, "town_a", 2, new Command[] { Staff(1) }));+ var r = Step(c, s, Staff(2));+ Assert.Empty(r.Rejected);+ Assert.True(r.State.Workshops[first].Staffed && r.State.Workshops[second].Staffed);}// R-ARMS-005 with R-CITY-001 (#1722 slice E): with this turn's queue, Check counts a pending "job" order's jobs (which turn@@ -273,6 +304,83 @@ public class ArmsWorkshopTestsAssert.Equal("Town A has 0 civilians and craftsmen without a job", F(Workshops.RefusedPeopleNoJob, "Town A", 0));}+ // R-CITY-001 with R-ARMS-005 (#1722 review, H2): a jobs order past the city's civilians and craftsmen less its staffed+ // workshops is refused with the workshop order's own format, so the UI words both the same way (workshop.refused_people).+ [Fact]+ public void TheJobsOrdersPeopleRefusalIsTheWorkshopFormat()+ {+ var (c, s, _) = Built(civilians: 10, employed: 6, jobs: 10, jobsDefault: false);+ var staffed = Step(c, s, Staff(1)).State;+ var reason = Assert.Single(Step(c, staffed, new AssignWorkers("town_a", "job", 10)).Rejected).Reason;+ Assert.Equal(string.Format(System.Globalization.CultureInfo.InvariantCulture, Workshops.RefusedPeople, "Town A", 9), reason);+ }++ // ---- #1722 review (F1, C4): the hex panel's next-cycle price and cycle length come from the sim ----++ // R-ARMS-006: the price NextCyclePrice gives before a turn is the worker's tier price (gdd03-balance workshop.cost 5/4/3,+ // content/gdd03-balance.yaml:306) and what that turn's production step charges and records, at every worker tier.+ [Theory]+ [InlineData(SyntheticWorkshopTier.Ordinary, 5)]+ [InlineData(SyntheticWorkshopTier.Novice, 5)]+ [InlineData(SyntheticWorkshopTier.Apprentice, 4)]+ [InlineData(SyntheticWorkshopTier.Expert, 3)]+ public void NextCyclePriceIsWhatTheTurnCharges(SyntheticWorkshopTier tier, int price)+ {+ var (c, s, id) = Staffed(treasury: 100, tier: tier);+ var next = Workshops.NextCyclePrice(c, s, id);+ Assert.Equal((decimal?)price, next);+ var r = Step(c, s);+ Assert.Equal(next, r.State.Workshops[id].PaidCost);+ Assert.Equal(-(double)next!.Value, Assert.Single(Charges(r)).Delta, 12);+ Assert.DoesNotContain(r.Why, w => w.Key == CauseKeys.Borrowed);+ }++ // R-ARMS-005, R-ARMS-006 (#1701 OQ6: every aggregate worker is priced as ordinary): a built workshop never staffed has no+ // record; its next cycle is priced at the tier staffing it would give, which is what its first cycle then charges.+ [Fact]+ public void NextCyclePriceOfANeverStaffedWorkshopIsTheOrdinaryTier()+ {+ var (c, s, id) = Built(jobsDefault: false);+ s.Treasury = 100;+ Assert.False(s.Workshops.ContainsKey(id));+ var next = Workshops.NextCyclePrice(c, s, id);+ Assert.Equal(5m, next); // gdd03-balance workshop.cost, ordinary+ Assert.Equal(Rules.Price(SyntheticWorkshopTier.Ordinary), next);+ var r = Step(c, s, Staff(1));+ Assert.Equal(SyntheticWorkshopTier.Ordinary, r.State.Workshops[id].WorkerTier);+ Assert.Equal(next, r.State.Workshops[id].PaidCost);+ Assert.Equal(-(double)next!.Value, Assert.Single(Charges(r)).Delta, 12);+ }++ // NextCyclePrice is null, and changes nothing, where there is no next cycle to price: a cycle under way, a workshop still+ // being built, a project with no worker slot, an unknown id, and under gdd-0.1.+ [Theory]+ [InlineData("paid")]+ [InlineData("building")]+ [InlineData("industry")]+ [InlineData("unknown")]+ [InlineData("gdd-0.1")]+ public void NextCyclePriceIsNullWhileACycleIsUnderwayOrOffWorkshop(string why)+ {+ var (c, s, id) = why == "paid" ? Staffed(paid: 5m, progress: 1) : Built();+ if (why == "building") s.CityProjects[id] = new CityProject(id, Workshops.ArmsWorkshop, "town_a", 1, 1, 2);+ if (why == "industry") s.CityProjects[id] = new CityProject(id, "industry", "town_a", 1, 1, 0, s.Date);+ if (why == "unknown") id = s.NextId + 100;+ if (why == "gdd-0.1") c = Load(false);+ var before = s.Hash();+ Assert.Null(Workshops.NextCyclePrice(c, s, id));+ Assert.Equal(before, s.Hash());+ }++ // R-ARMS-006: a cycle's staffed months are the catalogue's workshop.staffed_turns (3) under gdd-0.3, and there is none+ // under gdd-0.1.+ [Fact]+ public void CycleMonthsIsTheCataloguesStaffedTurns()+ {+ Assert.Equal(3, Workshops.CycleMonths(Load(true)));+ Assert.Null(Workshops.CycleMonths(Load(false)));+ }+// R-ARMS-005, R-LOOP-002: the workshops are hashed as wshop[...] only when there is one, so a gdd-0.1 state hashes as before.[Fact]public void TheWorkshopsAreHashedOnlyWhenPresent()diff --git a/sim/Statecraft.Sim/Cities.cs b/sim/Statecraft.Sim/Cities.csindex f19c8bda8..7d72347da 100644--- a/sim/Statecraft.Sim/Cities.cs+++ b/sim/Statecraft.Sim/Cities.cs@@ -82,7 +82,7 @@ namespace Statecraft.Simif (count > MaxWorkers(s, x))return count > x.JobSlots? FormattableString.Invariant($"{PlayerText.Settlement(c, city)} has {x.JobSlots} jobs")- : FormattableString.Invariant($"{PlayerText.Settlement(c, city)} has {x.Civilians + x.Craftsmen - Workshops.Staffed(s, city)} civilians and craftsmen");+ : string.Format(System.Globalization.CultureInfo.InvariantCulture, Workshops.RefusedPeople, PlayerText.Settlement(c, city), x.Civilians + x.Craftsmen - Workshops.Staffed(s, city));s.Cities[city] = x.WithCounts(x.Civilians, count, x.Refugees).WithJobsDefault(false);why.Add(new Cause("city", city, count - x.Employed, FormattableString.Invariant($"{PlayerText.Settlement(c, city)}: {count} groups in work"), key: CauseKeys.WorkersAssigned, args: new[] { CauseKeys.Number(count) }));return null;diff --git a/sim/Statecraft.Sim/Workshops.cs b/sim/Statecraft.Sim/Workshops.csindex 8f1765536..e460338b4 100644--- a/sim/Statecraft.Sim/Workshops.cs+++ b/sim/Statecraft.Sim/Workshops.cs@@ -20,15 +20,42 @@ namespace Statecraft.Sim/// <summary>R-ARMS-005: a staffing order's refusals (Check), formats with the settlement's name ({0}) and a count ({1},/// invariant). The English is what a turn's Rejected list and a save carry; the UI words it in its language- /// (SimBridge.ReasonText, #1722).</summary>+ /// (SimBridge.ReasonText, #1722). <see cref="RefusedPeople"/> is also the jobs order's refusal past the city's+ /// civilians and craftsmen less its staffed workshops (Cities.Assign, R-CITY-001).</summary>public const string RefusedBuiltOne = "{0} has 1 arms workshop", RefusedBuilt = "{0} has {1} arms workshops",RefusedPeople = "{0} has {1} civilians and craftsmen", RefusedPeopleNoJob = "{0} has {1} civilians and craftsmen without a job";+ /// <summary>R-ARMS-005 (#1701 OQ6): the tier a newly staffed workshop's worker is priced at on the aggregate cities,+ /// until the population ledger's tiers are live (R-POP-004). Staff gives it, and NextCyclePrice prices a workshop+ /// never staffed at it.</summary>+ internal const SyntheticWorkshopTier AggregateTier = SyntheticWorkshopTier.Ordinary;+static string Refused(string format, params object[] values) => string.Format(System.Globalization.CultureInfo.InvariantCulture, format, values);/// <summary>R-ARMS-005: the number of the city's built arms workshops, the most AssignWorkers(city, "workshop", n) staffs.</summary>public static int Built(Content c, GameState s, string city) => BuiltIn(c, s, city).Count;+ /// <summary>R-ARMS-006 (#1722, the hex panel): what the production step would charge for the built workshop+ /// <paramref name="project"/>'s next cycle, at its worker's tier, or at <see cref="AggregateTier"/> for a workshop+ /// never staffed (the tier Staff would give it). Null while a cycle is under way (its price is the Workshop record's+ /// PaidCost), for an unknown id, a project still being built or with no worker slot, and outside gdd-0.3. Nothing+ /// changes.</summary>+ public static decimal? NextCyclePrice(Content c, GameState s, int project)+ {+ if (c.Ruleset != SaveGame.Gdd03Ruleset) return null;+ if (!s.CityProjects.TryGetValue(project, out var p) || !IsBuilt(c, p)) return null;+ s.Workshops.TryGetValue(project, out var w);+ return w?.PaidCost != null ? null : Price(Rules(c), w);+ }++ /// <summary>R-ARMS-006: a cycle's staffed months (gdd03-balance workshop.staffed_turns) under gdd-0.3, else null.</summary>+ public static int? CycleMonths(Content c) => c.Ruleset == SaveGame.Gdd03Ruleset ? Rules(c).StaffedTurns : (int?)null;++ static SyntheticWorkshopRules Rules(Content c) => SyntheticWorkshopRules.FromCatalogue(c.Gdd03Balance!); // the loader requires it under gdd-0.3++ /// <summary>R-ARMS-006 (27M-13): a cycle's price at the worker's tier; <see cref="AggregateTier"/> with no record.</summary>+ static decimal Price(SyntheticWorkshopRules rules, Workshop? w) => rules.Price(w?.WorkerTier ?? AggregateTier);+/// <summary>R-ARMS-005: why AssignWorkers(<paramref name="city"/>, "workshop", <paramref name="count"/>) would be/// refused, or null; nothing changes. With an empty <paramref name="pending"/> it is the order's own check. With this/// turn's queue (#1722 slice E, the hex panel) it also counts the city's pending "job" order (whose jobs then hold@@ -55,7 +82,10 @@ namespace Statecraft.Sim/// <summary>R-ARMS-005: the city's built workshops (a project whose kind has a worker slot, R-ARMS-004), in ascending id.</summary>static List<CityProject> BuiltIn(Content c, GameState s, string city) =>- s.CityProjects.Values.Where(p => p.City == city && p.BuiltOn != null && c.ProjectKinds.First(k => k.Id == p.Kind).WorkerSlots > 0).ToList();+ s.CityProjects.Values.Where(p => p.City == city && IsBuilt(c, p)).ToList();++ /// <summary>R-ARMS-004: a built project whose kind has a worker slot.</summary>+ static bool IsBuilt(Content c, CityProject p) => p.BuiltOn != null && c.ProjectKinds.First(k => k.Id == p.Kind).WorkerSlots > 0;/// <summary>R-ARMS-005: the city's staffed workshops, each worked by one of its people who holds no job. 0 outside gdd-0.3,/// which has no workshop record.</summary>@@ -86,7 +116,7 @@ namespace Statecraft.Sim{var on = i < count;if (s.Workshops.TryGetValue(built[i].Id, out var w)) { if (w.Staffed != on) s.Workshops[w.Project] = w.WithStaffed(on); }- else if (on) s.Workshops.Add(built[i].Id, new Workshop(built[i].Id, true, SyntheticWorkshopTier.Ordinary));+ else if (on) s.Workshops.Add(built[i].Id, new Workshop(built[i].Id, true, AggregateTier));}why.Add(new Cause("city", city, count - staffed, FormattableString.Invariant($"{name}: arms workshops staffed: {count}"),key: CauseKeys.WorkshopWorkers, args: new[] { CauseKeys.Number(count) }));@@ -107,7 +137,7 @@ namespace Statecraft.Sim{if (c.Ruleset != SaveGame.Gdd03Ruleset || s.Workshops.Count == 0) return;PopulationLedger.RefuseAggregate(s);- var rules = SyntheticWorkshopRules.FromCatalogue(c.Gdd03Balance!); // the loader requires it under gdd-0.3+ var rules = Rules(c);var ceiling = c.RulesAt(s.Date).Mvp!.DebtCeiling!.Value;var held = Cities.Held(c, s);var working = new Dictionary<string, int>(StringComparer.Ordinal);@@ -128,7 +158,7 @@ namespace Statecraft.Simvar cycle = w;if (cycle.PaidCost == null){- var price = rules.Price(cycle.WorkerTier);+ var price = Price(rules, cycle);var left = s.Treasury - (double)price; // R-MONEY-003's debt after: the debt plus what the Treasury lacksif (left < 0 && s.Debt - left > ceiling){diff --git a/unity/Assets/Scripts/UI/GddHexPanel.cs b/unity/Assets/Scripts/UI/GddHexPanel.csindex fec88ab17..b52e9d999 100644--- a/unity/Assets/Scripts/UI/GddHexPanel.cs+++ b/unity/Assets/Scripts/UI/GddHexPanel.cs@@ -398,9 +398,10 @@ namespace Statecraft.Game.UI/// order's) of Workshops.Built; stepping back to the current count withdraws the order. + is off where Workshops.Check,/// asked with this turn's queue, refuses one more, and while a workshop is left unstaffed that refusal shows in the UI's/// language (SimBridge.ReasonText). This workshop: staffed or not (its Workshop record), its cycle under way (staffed- /// months of workshop.staffed_turns and the Money paid) or the next cycle's price at its worker's tier, the pause while- /// the enemy holds its city (Cities.Held, R-CITY-010), and the last turn's pauses for its city as the Why screen words- /// them (CauseKeys.WorkshopPaused). Nothing is computed here.</summary>+ /// months of Workshops.CycleMonths and the Money paid) or, staffed before or not, the next cycle's price+ /// (Workshops.NextCyclePrice, what the production step would charge), the pause while the enemy holds its city+ /// (Cities.Held, R-CITY-010), and the last turn's pauses for its city as the Why screen words them+ /// (CauseKeys.WorkshopPaused). Nothing is computed here.</summary>static void WorkshopPart(VisualElement host, SimBridge bridge, UiText text, CityProject project, Func<string, string> townName){var c = bridge.Content; var s = bridge.State;@@ -419,13 +420,10 @@ namespace Statecraft.Game.UIs.Workshops.TryGetValue(project.Id, out var w);Line(host, "city-workshop-state", text[w?.Staffed == true ? "city.workshop_staffed" : "city.workshop_unstaffed"]);- if (w != null)- {- var rules = SyntheticWorkshopRules.FromCatalogue(c.Gdd03Balance!); // the loader requires it under gdd-0.3- Line(host, "city-workshop-cycle", w.PaidCost is decimal paid- ? text.Format("city.workshop_cycle", w.Progress, rules.StaffedTurns, PlayerText.Money(c, "treasury", (double)paid))- : text.Format("city.workshop_next", PlayerText.Money(c, "treasury", (double)rules.Price(w.WorkerTier))));- }+ if (w != null && w.PaidCost is decimal paid)+ Line(host, "city-workshop-cycle", text.Format("city.workshop_cycle", w.Progress, Workshops.CycleMonths(c)!.Value, PlayerText.Money(c, "treasury", (double)paid)));+ 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).Select(x => CauseText.Line(x, c, Array.Empty<Statecraft.Game.Map.Units.UnitEntry>(), text, bridge.TownNamesHe)).Distinct().ToList();diff --git a/unity/Assets/Scripts/UI/SimBridge.cs b/unity/Assets/Scripts/UI/SimBridge.csindex 207288d1c..c27601f54 100644--- a/unity/Assets/Scripts/UI/SimBridge.cs+++ b/unity/Assets/Scripts/UI/SimBridge.cs@@ -262,7 +262,8 @@ namespace Statecraft.Game.UI(Training.RefusedNoHakhshara, "unit.reinforce_refused.no_hakhshara"),(Training.RefusedIdle, "unit.reinforce_refused.idle"),(Training.RefusedArms, "unit.reinforce_refused.arms"),- // R-ARMS-005 (#1722): a workshop staffing order's refusals, the panel's and the end of turn's.+ // R-ARMS-005 (#1722): a workshop staffing order's refusals, the panel's and the end of turn's. RefusedPeople is+ // also the jobs order's refusal past its civilians and craftsmen less the staffed workshops (Cities.Assign).(Workshops.RefusedBuiltOne, "workshop.refused_built_one"),(Workshops.RefusedBuilt, "workshop.refused_built"),(Workshops.RefusedPeople, "workshop.refused_people"),diff --git a/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs b/unity/Assets/Tests/EditMode/CityProjectPanelTests.csindex bd332c4c5..3027011d9 100644--- a/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs+++ b/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs@@ -355,12 +355,25 @@ public class WorkshopPanelTestsreturn (new SimBridge(g, text) { TownNamesHe = TownsHe }, id);}+ /// <summary>Adds a second built arms workshop for Haifa, on another hex Haifa reaches (by the sim's own helper), with an+ /// id above the first's; returns its id.</summary>+ static int SecondWorkshop(Content c, GameState s)+ {+ var first = Hex(c);+ var hex = c.Hexes.Where(h => h.Land && (h.Q, h.R) != first && Projects.CitiesFor(c, s, h.Q, h.R).Contains(City)).OrderBy(h => h.Q).ThenBy(h => h.R).First();+ var id = s.NextId++;+ s.CityProjects.Add(id, new CityProject(id, Workshops.ArmsWorkshop, City, hex.Q, hex.R, 0).Built(s.Date));+ return id;+ }+static InfoPanelPresenter Panel(UiTestKit ui, SimBridge bridge, UiText text) => new InfoPanelPresenter(ui.Root, bridge, text, Towns, townNamesHe: TownsHe);static AssignWorkers? Queued(SimBridge b) => b.QueuedLike(new AssignWorkers(City, Workshops.Role, 0)) as AssignWorkers;// R-ARMS-005: the control shows on a built arms workshop under gdd-0.3, and nowhere else: not on a workshop being- // built, not on another built kind, and never under gdd-0.1 (whose content has no workshop kind).+ // built, and not on another built kind. The gdd-0.1 row shows that no gdd-0.1 kind shows it: the loader keeps every+ // kind with a worker slot out of gdd-0.1 (R-ARMS-004), so its industry has none. It does not prove WorkshopPart's+ // ruleset check, which real content cannot reach; that check stays as defence in depth.[Test]public void TheControlShowsOnABuiltArmsWorkshopUnderGdd03Only([Values] bool hebrew){@@ -382,7 +395,8 @@ public class WorkshopPanelTestsvar (q, r) = Hex(c);panel.Show(q, r);Assert.IsNotNull(ui.Root.Q("city-project-state"), $"{c.Ruleset} {kind} {turns}: precondition, the project's part shows");- Assert.AreEqual(shown, ui.Root.Q("city-workshops-row") != null, $"{c.Ruleset} {kind} {turns}");+ Assert.AreEqual(shown, ui.Root.Q("city-workshops-row") != null, $"{c.Ruleset} {kind} {turns}"+ + (c == C01 ? ": no gdd-0.1 kind has a worker slot (R-ARMS-004), so none shows the control" : ""));Assert.AreEqual(shown, ui.Root.Q("city-workshop-state") != null, $"{c.Ruleset} {kind} {turns}");if (!shown) continue;Assert.AreEqual(t.Format("city.workshops_staffed", 0, 1), ui.Q<Label>("city-workshops").text, "the sim's counts: none staffed of 1 built");@@ -505,13 +519,12 @@ public class WorkshopPanelTestspublic void AStaffedWorkshopShowsItsCycleAndWhyItWaits([Values] bool hebrew){var t = hebrew ? He : En;- var rules = SyntheticWorkshopRules.FromCatalogue(C03.Gdd03Balance!);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 });using (var ui = new UiTestKit()){var (bridge, _) = Game(C03, t, edit: (s, id) =>{- s.Workshops.Add(id, new Workshop(id, true, SyntheticWorkshopTier.Ordinary, rules.Price(SyntheticWorkshopTier.Ordinary), 1));+ s.Workshops.Add(id, new Workshop(id, true, SyntheticWorkshopTier.Ordinary, 5m, 1)); // a cycle paid IL 5m, 1 month invar 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++;@@ -522,23 +535,134 @@ public class WorkshopPanelTestspanel.Show(q, r);Assert.AreEqual(t.Format("city.workshops_staffed", 1, 1), ui.Q<Label>("city-workshops").text);Assert.AreEqual(t["city.workshop_staffed"], ui.Q<Label>("city-workshop-state").text);- Assert.AreEqual(t.Format("city.workshop_cycle", 1, rules.StaffedTurns, PlayerText.Money(C03, "treasury", (double)rules.Price(SyntheticWorkshopTier.Ordinary))),- ui.Q<Label>("city-workshop-cycle").text);+ Assert.AreEqual(t.Format("city.workshop_cycle", 1, Workshops.CycleMonths(C03)!.Value, PlayerText.Money(C03, "treasury", 5.0)),+ 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);}using (var ui = new UiTestKit()){- var (bridge, _) = Game(C03, t, edit: (s, id) => s.Workshops.Add(id, new Workshop(id, false, SyntheticWorkshopTier.Ordinary)));+ var (bridge, id) = Game(C03, t, edit: (s, id) => s.Workshops.Add(id, new Workshop(id, false, SyntheticWorkshopTier.Ordinary)));using var panel = Panel(ui, bridge, t);var (q, r) = Hex(C03);panel.Show(q, r);Assert.AreEqual(t["city.workshop_unstaffed"], ui.Q<Label>("city-workshop-state").text);- Assert.AreEqual(t.Format("city.workshop_next", PlayerText.Money(C03, "treasury", (double)rules.Price(SyntheticWorkshopTier.Ordinary))),- ui.Q<Label>("city-workshop-cycle").text);+ var next = Workshops.NextCyclePrice(C03, bridge.State, id);+ Assert.IsNotNull(next, "precondition: the sim prices the next cycle");+ Assert.AreEqual(t.Format("city.workshop_next", PlayerText.Money(C03, "treasury", (double)next!.Value)),+ ui.Q<Label>("city-workshop-cycle").text, "the price the production step would charge");Assert.IsNull(ui.Root.Q("city-workshop-held"), "Haifa is not held");Assert.IsNull(ui.Root.Q("city-workshop-paused-0"), "no turn has run: no pause to report");}}++ // R-ARMS-006 (#1722 review, C4): a built workshop never staffed has no Workshop record; the panel still shows its next+ // cycle's price, the sim's (Workshops.NextCyclePrice: the tier staffing would give it).+ [Test]+ public void ANeverStaffedWorkshopShowsTheNextCyclesPrice([Values] bool hebrew)+ {+ var t = hebrew ? He : En;+ using var ui = new UiTestKit();+ var (bridge, id) = Game(C03, t);+ Assert.IsFalse(bridge.State.Workshops.ContainsKey(id), "precondition: never staffed, no record");+ var next = Workshops.NextCyclePrice(C03, bridge.State, id);+ Assert.AreEqual(5m, next, "gdd03-balance workshop.cost, ordinary (content/gdd03-balance.yaml:306)");+ using var panel = Panel(ui, bridge, t);+ var (q, r) = Hex(C03);+ panel.Show(q, r);+ var line = ui.Root.Q<Label>("city-workshop-cycle");+ Assert.IsNotNull(line, "a never-staffed workshop shows its next cycle's price");+ Assert.AreEqual(t.Format("city.workshop_next", PlayerText.Money(C03, "treasury", (double)next!.Value)), line.text);+ // The value itself, whatever separator the currency prefix uses: "No cycle under way · next cycle: IL 5.0m" in English.+ Assert.IsTrue(line.text.IndexOf("5.0m", StringComparison.Ordinal) >= 0, line.text);+ }++ // #1722 review (F1, item 6): the UI prices nothing itself. The workshop rules (SyntheticWorkshopRules, the gdd-0.3+ // catalogue Gdd03Balance and its StaffedTurns) stay in the sim, so the price the panel shows and the one the turn charges+ // cannot differ. Every UI script is scanned, comments stripped first, so moving the pricing to another file or a partial+ // fails it and a comment naming a type does not.+ [Test]+ public void TheWorkshopPartHoldsNoWorkshopRule()+ {+ var files = Directory.GetFiles(Path.Combine(Application.dataPath, "Scripts/UI"), "*.cs", SearchOption.AllDirectories);+ var panel = files.SingleOrDefault(f => Path.GetFileName(f) == "GddHexPanel.cs");+ Assert.IsNotNull(panel, "not vacuous: the scan reads the workshop panel's source");+ foreach (var file in files)+ {+ var code = System.Text.RegularExpressions.Regex.Replace(File.ReadAllText(file), @"//[^\n]*|/\*.*?\*/", "",+ System.Text.RegularExpressions.RegexOptions.Singleline);+ if (file == panel) StringAssert.Contains("Workshops.NextCyclePrice", code, "not vacuous: the panel's code survives the comment strip");+ foreach (var rule in new[] { "SyntheticWorkshopRules", "Gdd03Balance", "StaffedTurns" })+ Assert.AreEqual(-1, code.IndexOf(rule, StringComparison.Ordinal), $"{Path.GetFileName(file)} reads the workshop rules ({rule}) itself");+ }+ }++ // R-CITY-001 with R-ARMS-005 (#1722 review, H2): a jobs order past the city's civilians and craftsmen less its staffed+ // workshop is refused with the workshop order's format (Workshops.RefusedPeople), so in Hebrew it reads with+ // workshop.refused_people: "Haifa: not enough civilians and craftsmen (there are 9)", which fits the jobs order too.+ [Test]+ public void TheJobsOrdersPeopleRefusalReadsAsTheWorkshopsInHebrew()+ {+ var (bridge, _) = Game(C03, He, edit: (s, id) => s.Workshops.Add(id, new Workshop(id, true, SyntheticWorkshopTier.Ordinary)));+ Assert.IsNull(bridge.Queue(new AssignWorkers(City, "job", 10)));+ var reason = bridge.EndTurn().Rejected.Single(x => x.Command is AssignWorkers w && w.Role == "job").Reason;+ Assert.AreEqual("Haifa has 9 civilians and craftsmen", reason);+ Assert.AreEqual(string.Format(System.Globalization.CultureInfo.InvariantCulture, Workshops.RefusedPeople, "Haifa", 9), reason);+ var he = SimBridge.ReasonText(He, reason, C03, TownsHe);+ // Ordinal: a culture compare ignores U+200E and may not tell U+00A0 from a plain space.+ var expected = TownsHe[City] + ": אין די אזרחים ובעלי מלאכה (יש\u00A0\u200E9\u200E)";+ Assert.IsTrue(string.Equals(expected, he, StringComparison.Ordinal), he);+ // The no-job form reads as its own string (workshop.refused_people_no_job), not as the plain one: ReasonText's+ // formats are anchored (^...$), so the plain format cannot match it.+ var noJob = SimBridge.ReasonText(He, string.Format(System.Globalization.CultureInfo.InvariantCulture, Workshops.RefusedPeopleNoJob, "Haifa", 1), C03, TownsHe);+ Assert.IsTrue(string.Equals(TownsHe[City] + ": אין די אזרחים ובעלי מלאכה ללא משרה (יש\u00A0\u200E1\u200E)", noJob, StringComparison.Ordinal), noJob);+ }++ // 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]+ public void TwoWorkshopsStepPastOneAndShowTheRefusalWithAnOrderQueued([Values] bool hebrew)+ {+ var t = hebrew ? He : En;+ using var ui = new UiTestKit();+ var (bridge, _) = Game(C03, t, employed: 9, edit: (s, _) => SecondWorkshop(C03, s));+ using var panel = Panel(ui, bridge, t);+ var (q, r) = Hex(C03);+ panel.Show(q, r);+ Assert.AreEqual(t.Format("city.workshops_staffed", 0, 2), ui.Q<Label>("city-workshops").text);+ Assert.IsTrue(ui.Q<Button>("city-workshops-more").enabledSelf, "1 person without a job: one may be staffed");+ ui.Press("city-workshops-more");+ Assert.AreEqual(1, Queued(bridge)!.Count);+ Assert.AreEqual(t.Format("city.workshops_ordered", 1, 2), ui.Q<Label>("city-workshops").text);+ var reason = Workshops.Check(C03, bridge.State, City, 2, bridge.Queued);+ Assert.AreEqual(string.Format(System.Globalization.CultureInfo.InvariantCulture, Workshops.RefusedPeopleNoJob, "Haifa", 1), reason,+ "precondition: the sim refuses a second");+ Assert.IsFalse(ui.Q<Button>("city-workshops-more").enabledSelf);+ Assert.AreEqual(SimBridge.ReasonText(t, reason!, C03, TownsHe), ui.Q<Label>("city-workshops-reason").text);+ }++ // R-ARMS-005 (#1722 review, H1, a regression pin): two built, two people free, one staffing order queued. Check does+ // not count the pending workshop order itself, so + stays on, and the turn staffs both.+ [Test]+ public void WithTwoFreeAndOneQueuedPlusStaysOn()+ {+ using var ui = new UiTestKit();+ var second = 0;+ var (bridge, first) = Game(C03, En, employed: 8, edit: (s, _) => second = SecondWorkshop(C03, s));+ using var panel = Panel(ui, bridge, En);+ var (q, r) = Hex(C03);+ panel.Show(q, r);+ ui.Press("city-workshops-more");+ Assert.AreEqual(1, Queued(bridge)!.Count);+ Assert.IsTrue(ui.Q<Button>("city-workshops-more").enabledSelf, "2 free, 1 ordered: a second may still be staffed");+ Assert.IsNull(ui.Root.Q("city-workshops-reason"));+ ui.Press("city-workshops-more");+ Assert.AreEqual(En.Format("city.workshops_ordered", 2, 2), ui.Q<Label>("city-workshops").text);+ Assert.IsFalse(ui.Q<Button>("city-workshops-more").enabledSelf, "both ordered staffed");+ Assert.IsNull(ui.Root.Q("city-workshops-reason"), "every workshop is ordered staffed: no refusal to explain");+ var turn = bridge.EndTurn();+ Assert.IsEmpty(turn.Rejected, "the sim accepts the order the panel queued");+ Assert.IsTrue(turn.State.Workshops[first].Staffed && turn.State.Workshops[second].Staffed);+ }}