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: Train and corridor Build follow the sim's refusals; the depopulated reason is localized (Fixes #2573) (#2580)
Eyal Golan0b19001747ff
diff --git a/changelog.d/2573-hex-panel-refusals.md b/changelog.d/2573-hex-panel-refusals.mdnew file mode 100644index 000000000..691c6ffbb--- /dev/null+++ b/changelog.d/2573-hex-panel-refusals.md@@ -0,0 +1,4 @@+### Fixed++- Disabled Train and corridor Build when the simulation would refuse them for+ insufficient Arms or a depopulated crossing, and localized the depopulated-place reason.diff --git a/sim/Statecraft.Sim/Corridors.cs b/sim/Statecraft.Sim/Corridors.csindex 887adf059..0793d0802 100644--- a/sim/Statecraft.Sim/Corridors.cs+++ b/sim/Statecraft.Sim/Corridors.cs@@ -35,6 +35,21 @@ namespace Statecraft.Simreturn null;}+ /// <summary>Why this corridor segment cannot be started, or null when it can. The caller supplies a loaded corridor+ /// and a valid zero-based segment index.</summary>+ public static string? CheckStart(Content c, GameState s, string action, CorridorDef def, int index)+ {+ var wantRail = action == BuildRail;+ if ((def.Kind == Rail) != wantRail)+ return wantRail ? $"{def.Name} is not a railway" : $"{def.Name} is not a road";+ var name = SegmentName(def, index);+ if (def.Segments[index].Hexes.Any(h => SettlementControl.DepopulatedAt(c, s, h[0], h[1])))+ return $"{name} crosses a depopulated place, where nothing can be built";+ if (s.Corridors.TryGetValue(def.Id, out var work) && work.Segments[index] is SegmentWork segment)+ return segment.BuiltOn == null ? $"{name} is already being built" : $"{name} is already built";+ return null;+ }+/// <summary>R-COR-001: an idle halutz unit (Projects.Start has checked the unit) starts an unbuilt, unclaimed segment/// <paramref name="target"/> ("corridor:N", N from 1) of a corridor whose kind <paramref name="action"/> builds. The/// Treasury pays the kind's cost now and borrows what it lacks. Refused, state untouched, for an unknown corridor or@@ -46,15 +61,11 @@ namespace Statecraft.Simif (def == null || !int.TryParse(target.Substring(colon + 1), NumberStyles.None, CultureInfo.InvariantCulture, out var n)|| n < 1 || n > def.Segments.Count)return "There is no such corridor segment";- var wantRail = action == BuildRail;- if ((def.Kind == Rail) != wantRail) return wantRail ? $"{def.Name} is not a railway" : $"{def.Name} is not a road";var index = n - 1;var name = SegmentName(def, index);- if (def.Segments[index].Hexes.Any(h => SettlementControl.DepopulatedAt(c, s, h[0], h[1]))) // R-CTRL-020 (Q-DEP-7 (c))- return $"{name} crosses a depopulated place, where nothing can be built";+ var refusal = CheckStart(c, s, action, def, index); // R-CTRL-020 (Q-DEP-7 (c))+ if (refusal != null) return refusal;s.Corridors.TryGetValue(def.Id, out var work);- if (work?.Segments[index] is SegmentWork seg)- return seg.BuiltOn == null ? $"{name} is already being built" : $"{name} is already built";var r = c.RulesAt(s.Date).Mvp!; // the loader requires it in the GDD loopvar (cost, _) = Projects.Terms(r, action);EconomySystem.PayOrBorrow(c, s, cost, "to build a corridor segment", why, CauseKeys.Purpose.Corridor);diff --git a/sim/Statecraft.Sim/Projects.cs b/sim/Statecraft.Sim/Projects.csindex f00a53e44..040d6c712 100644--- a/sim/Statecraft.Sim/Projects.cs+++ b/sim/Statecraft.Sim/Projects.cs@@ -307,7 +307,7 @@ namespace Statecraft.Sim/// <summary><see cref="CheckCity"/>'s one validator (#1122, owner ruling 2): null when the project may be started, else a/// stable kind and invariant values for a UI to word in its language (the map actions' pattern), plus the English text./// The kinds, in check order: unknown_kind, unknown_city, locked (kind), maabarot_policy, no_resource (city, resource, kind), not_land,- /// too_far (distance, city), repair_city_hex (city; a housing repair off its city's own hex), occupied (the placement's+ /// depopulated, too_far (distance, city), repair_city_hex (city; a housing repair off its city's own hex), occupied (the placement's/// action), occupied_project (the project's kind), city_cap (city;/// gdd-0.3 only), turn_cap (cap).</summary>public static MapActionReason? CheckCityReason(Content c, GameState s, string kind, string city, int q, int r)diff --git a/tools/tests/test_hebrew_ui.py b/tools/tests/test_hebrew_ui.pyindex e464474cb..a602ad7d3 100644--- a/tools/tests/test_hebrew_ui.py+++ b/tools/tests/test_hebrew_ui.py@@ -22,7 +22,7 @@ def test_map_action_reasons_are_hebrew_and_their_english_action_names_are_the_rueach action by its rules.yaml name."""en, he = strings('strings.en.yaml'), strings('strings.he.yaml')keys = [key for key in en if key.startswith('info.map_action')]- assert len(keys) == 14 # 2 action names and 12 reasons+ assert len(keys) == 15 # 2 action names and 13 reasons (depopulated, #2573)assert all(not re.search('[A-Za-z]', he[key]) for key in keys)rules = yaml12.load((ROOT / 'content/rules.yaml').read_text(encoding='utf-8'))actions = rules['map_actions']diff --git a/unity/Assets/Scripts/UI/GddHexPanel.cs b/unity/Assets/Scripts/UI/GddHexPanel.csindex c11e8fbb7..227941913 100644--- a/unity/Assets/Scripts/UI/GddHexPanel.cs+++ b/unity/Assets/Scripts/UI/GddHexPanel.cs@@ -134,15 +134,35 @@ namespace Statecraft.Game.UI: text.Format("city.workers_ordered", Groups(text, target)));// Train, for each facility the city has (Training.HasFacility: its own, D-D5, or a built camp site's, R-CAMP-001):- // each press orders one more group; R-TRAIN-001 takes only civilians without work, and the sim counts every track's- // order and the Assign order in the queue against them.- var free = Training.Available(s, id, bridge.Queued);+ // each press orders one more group. The exact preview below asks whether End turn would refuse that order, and+ // R-TRAIN-001's idle-civilian limit is Training.Available's, over the queue less the orders End turn refuses anyway.+ // #1548 (owner, 24 October 2026: "Yes, count them"): every queued Train, Reinforce and reassignment still takes+ // its groups from the civilians without work, as Training.Available counts them (the sim does not take a+ // reassigned craftsman off them). "Refused anyway" is the current queue's preview, without the press: an order+ // the press itself would make End turn refuse (a reassignment queued after a Train that takes its civilian) still+ // counts. The old order's own count is in the queue, so one more group needs one free.+ var current = Simulation.Preview(c, bridge.TurnStart, bridge.Session.Committed.Concat(bridge.Queued).ToList());+ var free = Training.Available(s, id, bridge.Queued.Where(x => !current.Rejected.Any(r => ReferenceEquals(r.Command, x))));foreach (var type in c.UnitTypes.Where(t => t.Facility != "" && Training.HasFacility(c, s, id, t.Facility))){- var ordered = (bridge.QueuedLike(new Train(id, type.Id, 1)) as Train)?.Count ?? 0;+ var old = bridge.QueuedLike(new Train(id, type.Id, 1));+ var ordered = (old as Train)?.Count ?? 0;+ // #2573: the press queues Train(ordered + 1) where SimBridge.Queue puts it (the old order's slot, else last), so+ // the button asks End turn's own order runner (Simulation.Preview: queue order, conversions before Arms+ // purchases) whether that exact order would be refused, for a short Arms stock (R-ARMS-003) or any other reason.+ var press = new Train(id, type.Id, ordered + 1);+ var queue = bridge.Queued.ToList();+ var slot = old == null ? -1 : queue.IndexOf(old);+ if (slot >= 0) queue[slot] = press; else queue.Add(press);+ // As End turn runs it (GameSession.EndTurn: Step from the turn's start over the committed orders, then the+ // queue) and as ArmsPurchasePresenter asks it.+ var preview = Simulation.Preview(c, bridge.TurnStart, bridge.Session.Committed.Concat(queue).ToList());+ var accepted = !preview.Rejected.Any(x => ReferenceEquals(x.Command, press));+ // Nor may the press make End turn refuse a queued order it accepts now (its civilians, Arms or anything else).+ var causesNoNewRefusal = !bridge.Queued.Any(x => preview.Rejected.Any(r => ReferenceEquals(r.Command, x)) && !current.Rejected.Any(r => ReferenceEquals(r.Command, x)));var row = Row(host, $"city-train-{type.Id}-row");OrderButton(row, bridge, "city-train-" + type.Id, text.Format("city.train_" + type.Id, PlayerText.Money(c, "treasury", type.TrainingCost), Turns(text, type.TrainingTurns)),- free >= 1, () => bridge.Queue(new Train(id, type.Id, ordered + 1)));+ accepted && causesNoNewRefusal && free >= 1, () => bridge.Queue(new Train(id, type.Id, ordered + 1)));if (ordered > 0) Line(row, $"city-train-{type.Id}-ordered", text.Format("city.train_ordered", ordered));}@@ -297,13 +317,14 @@ namespace Statecraft.Game.UIif (idle.Count == 0) Line(host, "corridor-no-halutz", text["site.no_halutz"]);// One unit a segment (Q-COR-4): once a group is ordered here, the others' Build is off, as the sim would refuse it.var taken = bridge.Queued.OfType<PioneerWork>().Any(w => w.Site == target);+ var refusal = Corridors.CheckStart(c, s, action, d, index);foreach (var u in idle){var ordered = bridge.QueuedLike(new PioneerWork(u.Id, action, target)) is PioneerWork p && p.Site == target;OrderButton(host, bridge, $"corridor-build-{u.Id}", ordered ? text["site.ordered"]: text.Format("corridor.build_" + d.Kind, Group(text, s, u.Id), PlayerText.Money(c, "treasury", terms.Cost),Turns(text, Corridors.TurnsToBuild(c, s, u.Id, terms.Turns, 0))),- !ordered && !taken, () => bridge.Queue(new PioneerWork(u.Id, action, target)));+ refusal == null && !ordered && !taken, () => bridge.Queue(new PioneerWork(u.Id, action, target)));PioneerReturn(host, bridge, text, u.Id);}}@@ -491,7 +512,8 @@ namespace Statecraft.Game.UI{switch (reason.Kind){- case "maabarot_policy": case "not_land": return text["info.map_action_reason." + reason.Kind];+ case "maabarot_policy": case "not_land": case "depopulated":+ return text["info.map_action_reason." + reason.Kind];case "occupied": return text.Format("info.map_action_reason.occupied", text["info.map_action." + reason.Values[0]]);case "no_resource": return text.Format("city.project_reason.no_resource", townName(reason.Values[0]), ResourceName(text, reason.Values[1]),ContentNames.Of(text, c.ProjectKinds.First(x => x.Id == reason.Values[2])));diff --git a/unity/Assets/Tests/EditMode/CityPanelTests.cs b/unity/Assets/Tests/EditMode/CityPanelTests.csindex 2c8c0706f..824c0c3c9 100644--- a/unity/Assets/Tests/EditMode/CityPanelTests.cs+++ b/unity/Assets/Tests/EditMode/CityPanelTests.cs@@ -316,6 +316,229 @@ public class CityPanelTestsAssert.IsFalse(ui.Q<Button>("city-train-halutz").enabledSelf);}+ /// <summary>R-ARMS-003: the Arms one recruit group takes when its training starts (mvp.arms_per_recruit_group).</summary>+ static int RecruitGroupArms(GameState s) => C.RulesAt(s.Date).Mvp!.ArmsPerRecruitGroup!.Value;++ static void NearDebtCeilingForArmsPurchase(GameState s, int purchaseArms)+ {+ var m = C.RulesAt(s.Date).Mvp!;+ var convertedMoney = m.DollarsPerTurn!.Value * m.IlPerDollarOn(s.Date);+ s.Arms = RecruitGroupArms(s) - 1;+ s.Treasury = 0;+ s.Debt = m.DebtCeiling!.Value - purchaseArms * m.ArmsPrice!.Value + convertedMoney / 2;+ s.FxReserves = m.DollarsPerTurn.Value;+ }++ // Red-first prediction at 085944e62: the recruit button is enabled because the panel checks free civilians only.+ [Test]+ public void RecruitTrainingIsDisabledWithNoArms()+ {+ using var ui = new UiTestKit();+ var bridge = Bridge(En, s => s.Arms = 0);+ using var panel = Panel(ui, bridge, En);+ panel.Show(CityHex.q, CityHex.r);+ Assert.IsFalse(ui.Q<Button>("city-train-recruit").enabledSelf,+ "R-ARMS-003: the stock cannot cover one recruit group");+ }++ // Red-first prediction at 085944e62: the precondition fails, as the button is enabled on free civilians alone; with the+ // fix, a queued purchase that covers the group turns it back on (buy, then train, in one turn: R-TURN-004's queue order).+ [Test]+ public void RecruitTrainingIsEnabledWhenAQueuedPurchaseCoversIt()+ {+ using var ui = new UiTestKit();+ var bridge = Bridge(En, s => s.Arms = RecruitGroupArms(s) - 1);+ using var panel = Panel(ui, bridge, En);+ panel.Show(CityHex.q, CityHex.r);+ Assert.IsFalse(ui.Q<Button>("city-train-recruit").enabledSelf, "precondition: one Arms is missing");+ Assert.IsNull(bridge.Queue(new BuyArms(1)), "precondition: the bridge accepts the purchase");+ Assert.IsTrue(ui.Q<Button>("city-train-recruit").enabledSelf,+ "the purchase runs before a newly appended Train order");+ }++ // Training.Available counts every queued Train whether or not it will be accepted. Once the covering purchase is+ // withdrawn, the rejected Recruit is state-neutral, so the exact preview still accepts a zero-Arms Halutz Train.+ [Test]+ public void HalutzTrainingIsEnabledWhenAnEarlierRecruitWillBeRejected()+ {+ using var ui = new UiTestKit();+ var bridge = Bridge(En, s =>+ {+ Counts(50, 49)(s);+ s.Arms = 0;+ });+ using var panel = Panel(ui, bridge, En);+ panel.Show(CityHex.q, CityHex.r);+ var purchase = new BuyArms(RecruitGroupArms(bridge.State));+ var recruit = new Train(City, "recruit", 1);+ Assert.IsNull(bridge.Queue(purchase), "precondition: the purchase covers the Recruit");+ Assert.IsNull(bridge.Queue(recruit), "precondition: the Recruit follows its covering purchase");+ bridge.Withdraw(purchase);++ var halutz = new Train(City, "halutz", 1);+ var preview = Simulation.Preview(C, bridge.TurnStart,+ bridge.Session.Committed.Concat(bridge.Queued).Concat(new[] { halutz }).ToList());+ Assert.IsTrue(preview.Rejected.Any(x => ReferenceEquals(x.Command, recruit)),+ "precondition: without the purchase, the queued Recruit is rejected for its missing Arms");+ Assert.IsFalse(preview.Rejected.Any(x => ReferenceEquals(x.Command, halutz)),+ "precondition: the rejected Recruit leaves the one idle civilian for the zero-Arms Halutz course");+ Assert.Zero(Training.Available(bridge.State, City, bridge.Queued),+ "Training.Available deliberately counts the pending Recruit without previewing its refusal");+ Assert.IsTrue(ui.Q<Button>("city-train-halutz").enabledSelf,+ "the button follows the exact candidate preview, not the conservative queued-order count");+ }++ // #2580 (R-ARMS-002, R-MONEY-004): let A be the Arms cost and M the Money from the turn's full dollar conversion.+ // Treasury = 0 and Debt = ceiling - A + M/2, so Buy alone ends at ceiling + M/2 (refused), while conversion first+ // leaves Debt at ceiling - A + M/2 + max(0, A - M), at or below the ceiling. FxReserves supplies the full conversion.+ // Red-first at 085944e62: the enabled case passes for the wrong reason (free civilians only); the disabled control fails.+ [Test]+ public void RecruitTrainingFollowsDollarConversionsMovedBeforeArmsPurchases()+ {+ foreach (var convertAfterPurchase in new[] { true, false })+ {+ using var ui = new UiTestKit();+ var bridge = Bridge(En, s => NearDebtCeilingForArmsPurchase(s, RecruitGroupArms(s)));+ using var panel = Panel(ui, bridge, En);+ panel.Show(CityHex.q, CityHex.r);+ var m = C.RulesAt(bridge.State.Date).Mvp!;+ var dollars = m.DollarsPerTurn!.Value;+ var armsCost = RecruitGroupArms(bridge.State) * m.ArmsPrice!.Value;+ var convertedMoney = dollars * m.IlPerDollarOn(bridge.State.Date);+ Assert.Greater(bridge.State.Debt + armsCost, m.DebtCeiling!.Value,+ "precondition: BuyArms alone would borrow past the ceiling");+ Assert.LessOrEqual(bridge.State.Debt + Math.Max(0, armsCost - convertedMoney), m.DebtCeiling.Value,+ "precondition: converting first leaves the purchase within the ceiling");+ Assert.IsNull(bridge.Queue(new BuyArms(RecruitGroupArms(bridge.State))),+ "precondition: the bridge accepts BuyArms first");+ if (convertAfterPurchase)+ Assert.IsNull(bridge.Queue(new ConvertDollars(dollars)),+ "precondition: the bridge accepts ConvertDollars after BuyArms");+ Assert.AreEqual(convertAfterPurchase, ui.Q<Button>("city-train-recruit").enabledSelf,+ convertAfterPurchase+ ? "End turn moves the conversion before BuyArms, so the purchase stays within the ceiling"+ : "without the conversion, BuyArms would borrow past the ceiling and Train is refused");+ }+ }++ // Let G be one recruit group's Arms, P = (G + 1) * Arms price, and M the full conversion's Money. The stock starts+ // at G - 1, so Buy(G + 1) leaves exactly 2G Arms. Debt starts at ceiling - P + M/2: Buy alone would end at ceiling+ // + M/2 and be refused; moving Convert ahead of it ends at ceiling - P + M/2 + max(0, P - M), at most the ceiling.+ [Test]+ public void ReplacementRecruitTrainingFollowsAConversionQueuedAfterItsSlot()+ {+ var purchaseArms = 0;+ using var ui = new UiTestKit();+ var bridge = Bridge(En, s =>+ {+ purchaseArms = RecruitGroupArms(s) + 1;+ NearDebtCeilingForArmsPurchase(s, purchaseArms);+ });+ using var panel = Panel(ui, bridge, En);+ panel.Show(CityHex.q, CityHex.r);+ var m = C.RulesAt(bridge.State.Date).Mvp!;+ var dollars = m.DollarsPerTurn!.Value;+ var purchaseCost = purchaseArms * m.ArmsPrice!.Value;+ var convertedMoney = dollars * m.IlPerDollarOn(bridge.State.Date);+ var buy = new BuyArms(purchaseArms);+ var first = new Train(City, "recruit", 1);+ var convert = new ConvertDollars(dollars);+ Assert.Greater(bridge.State.Debt + purchaseCost, m.DebtCeiling!.Value,+ "precondition: without the later conversion, BuyArms would be refused at the debt ceiling");+ Assert.LessOrEqual(bridge.State.Debt + Math.Max(0, purchaseCost - convertedMoney), m.DebtCeiling.Value,+ "precondition: conversion before the purchase keeps it within the debt ceiling");+ Assert.IsNull(bridge.Queue(buy));+ Assert.IsNull(bridge.Queue(first));+ Assert.IsFalse(ui.Q<Button>("city-train-recruit").enabledSelf,+ "precondition: before the conversion, replacing Train(1) with Train(2) cannot use the refused purchase");+ Assert.IsNull(bridge.Queue(convert));+ CollectionAssert.AreEqual(new Command[] { buy, first, convert }, bridge.Queued,+ "precondition: the conversion was queued after the Train slot it will fund");++ var press = new Train(City, "recruit", 2);+ var preview = Simulation.Preview(C, bridge.TurnStart,+ bridge.Session.Committed.Concat(new Command[] { buy, press, convert }).ToList());+ var accepted = !preview.Rejected.Any(x => ReferenceEquals(x.Command, press));+ Assert.IsTrue(accepted,+ "End turn moves Convert before BuyArms; the accepted purchase leaves exactly two groups' Arms");+ Assert.AreEqual(accepted, ui.Q<Button>("city-train-recruit").enabledSelf,+ "the repeat press previews [BuyArms, Train(2), ConvertDollars] with Train replaced in its original slot");+ }++ // #2573: pressing Train again replaces the queued Train in its own slot (SimBridge.Queue), so a purchase queued after+ // it runs too late to pay for the extra group. Red-first at 085944e62: enabled, the panel checks free civilians only.+ [Test]+ public void ASecondRecruitGroupIsNotPaidByAPurchaseQueuedAfterTheFirst()+ {+ using var ui = new UiTestKit();+ var bridge = Bridge(En, s => s.Arms = RecruitGroupArms(s));+ using var panel = Panel(ui, bridge, En);+ panel.Show(CityHex.q, CityHex.r);+ Assert.IsNull(bridge.Queue(new Train(City, "recruit", 1)), "precondition: one group, the whole stock");+ Assert.IsNull(bridge.Queue(new BuyArms(RecruitGroupArms(bridge.State))), "precondition: a purchase after it");+ Assert.IsFalse(ui.Q<Button>("city-train-recruit").enabledSelf,+ "Train(2) would run in the first order's slot, before the purchase, with Arms for one group only");+ }++ // #2580 review: the press previews Train(2) in Train(1)'s slot, which takes both idle civilians, so End turn would refuse+ // the reassignment queued after it (R-QUAL-004). That refusal is caused by the press, so it must not free a civilian for+ // it: #1548 counts the queued reassignment. Red-first prediction at f28230b07: enabled, as the press preview's refusals+ // were left out of the count.+ [Test]+ public void ATrainPressCannotTakeTheCivilianALaterReassignmentNeeds()+ {+ using var ui = new UiTestKit();+ var bridge = Bridge(En, s => { Counts(50, 48)(s); Qualify(1, 0)(s); });+ using var panel = Panel(ui, bridge, En);+ panel.Show(CityHex.q, CityHex.r);+ Assert.AreEqual(2, Training.Idle(bridge.State, bridge.State.Cities[City]), "precondition: two civilians without work");+ var train = new Train(City, "halutz", 1);+ var reassign = new ReassignCraftsmen(City, 1);+ Assert.IsNull(bridge.Queue(train), "precondition: one halutz group takes one of them");+ Assert.IsNull(bridge.Queue(reassign), "precondition: the reassignment takes the other");+ CollectionAssert.AreEqual(new Command[] { train, reassign }, bridge.Queued, "precondition: the reassignment is after the Train");+ Assert.IsEmpty(Simulation.Preview(C, bridge.TurnStart, bridge.Session.Committed.Concat(bridge.Queued).ToList()).Rejected,+ "precondition: End turn accepts both queued orders");+ Assert.IsFalse(ui.Q<Button>("city-train-halutz").enabledSelf,+ "Train(2) would take the reassignment's civilian, and End turn would refuse the reassignment");+ }++ // #2580 review (auditenable): the press must not take the Arms a later queued Reinforce needs either. Three civilians+ // without work and Arms for two recruit groups: Train(1) and then Reinforce(1) are both accepted, but Train(2) in the+ // first order's slot takes both groups' Arms, and End turn would refuse the reinforcement (R-ARMS-003). The idle count+ // still has one civilian free, so only the previews can see it. Red-first prediction at d3b1fb6e0: enabled.+ [Test]+ public void ATrainPressCannotTakeTheArmsALaterReinforcementNeeds()+ {+ using var ui = new UiTestKit();+ var unit = -1;+ var bridge = Bridge(En, s =>+ {+ Counts(50, 47)(s);+ s.Arms = 2 * RecruitGroupArms(s);+ var recruit = C.UnitTypes.Single(t => t.Id == "recruit");+ var u = s.Units.Values.Where(x => x.Side == Movement.PlayerSide && x.Strength >= 2)+ .First(x => C.UnitTypes.First(t => t.Id == x.Type) is var t && C.UnitTypes.FirstOrDefault(k => k.Side == t.Side && k.Class == t.Class && k.Facility != "") == recruit);+ s.Units[u.Id] = new Unit(u.Id, u.Type, CityHex.q, CityHex.r, u.Service, u.Side, u.Strength - 1, u.Order, u.OrderTarget, u.HomeCity, u.Strength);+ unit = u.Id;+ });+ using var panel = Panel(ui, bridge, En);+ panel.Show(CityHex.q, CityHex.r);+ var train = new Train(City, "recruit", 1);+ var reinforce = new Reinforce(unit, City, 1);+ Assert.IsNull(bridge.Queue(train), "precondition: one recruit group takes one group's Arms");+ Assert.IsNull(bridge.Queue(reinforce), "precondition: the reinforcement, trained as recruits, takes the other");+ Assert.IsEmpty(Simulation.Preview(C, bridge.TurnStart, bridge.Session.Committed.Concat(bridge.Queued).ToList()).Rejected,+ "precondition: End turn accepts both queued orders");+ var pressed = Simulation.Preview(C, bridge.TurnStart,+ bridge.Session.Committed.Concat(new Command[] { new Train(City, "recruit", 2), reinforce }).ToList());+ StringAssert.Contains("Arms", pressed.Rejected.Single(x => ReferenceEquals(x.Command, reinforce)).Reason,+ "precondition: after Train(2), End turn refuses the reinforcement for its Arms");+ Assert.GreaterOrEqual(Training.Available(bridge.State, City, bridge.Queued), 1, "precondition: a civilian without work is left");+ Assert.IsFalse(ui.Q<Button>("city-train-recruit").enabledSelf,+ "Train(2) would take the reinforcement's Arms, and End turn would refuse the reinforcement");+ }+[Test]public void TrainingAcrossBothTracksStopsAtTheIdleCivilianLimit(){@@ -929,6 +1152,39 @@ public class CityPanelTestsAssert.AreEqual(a, result.State.Corridors["burma_road"].Segments[0]?.Unit);}+ // Red-first prediction at 085944e62: the Build button is enabled because the panel does not ask the depopulation rule.+ [Test]+ public void ADepopulatedPlaceCrossingDisablesCorridorBuild()+ {+ var segment = C.Corridors.Single(x => x.Id == "burma_road").Segments[0];+ var q = segment.Hexes[0][0];+ var r = segment.Hexes[0][1];+ var target = C.SettlementTargets.Single(x => x.Id == "jaffa");+ var old = (target.Q, target.R);+ try+ {+ target.Q = q;+ target.R = r;+ using var ui = new UiTestKit();+ int pioneer = -1;+ var bridge = Bridge(En, s =>+ {+ pioneer = AddHalutz(s);+ s.Settlements["jaffa"] = new SettlementControl(depopulated: true);+ });+ using var panel = Panel(ui, bridge, En);+ panel.Show(q, r);+ var button = SegmentBox(ui, "burma_road", 1).Q<Button>($"corridor-build-{pioneer}");+ Assert.IsFalse(button.enabledSelf,+ "R-CTRL-020: the sim refuses a segment crossing a depopulated place");+ }+ finally+ {+ target.Q = old.Q;+ target.R = old.R;+ }+ }+[Test]public void AHexOnARailwayOffersBuildRailwayAndShowsEverySegmentThroughIt(){diff --git a/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs b/unity/Assets/Tests/EditMode/CityProjectPanelTests.csindex 28e807c78..540b7f8dc 100644--- a/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs+++ b/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs@@ -314,6 +314,30 @@ public class CityProjectPanelTestsAssert.IsNull(ui.Root.Q("city-project-" + MapActions.TransitCamp + "-reason"));}+ // Red-first prediction at 085944e62: the first failure is the missing info.map_action_reason.depopulated text key.+ [Test]+ public void TheDepopulatedReasonShowsInThePanelsLanguage([Values] bool hebrew)+ {+ var text = hebrew ? He : En;+ var target = C.SettlementTargets.Single(x => x.Id == "jaffa");+ using var ui = new UiTestKit();+ // With the policy the transit camp is refused for the shared reason too, not for the policy first (as the tests above).+ var bridge = Bridge(text, s => { s.Settlements[target.Id] = new SettlementControl(depopulated: true); s.Policies[MapActions.MaabarotPolicy] = 1; });+ Assert.IsNotEmpty(Projects.CitiesFor(C, bridge.State, target.Q, target.R),+ "precondition: a city can otherwise build on the target hex");+ using var panel = Panel(ui, bridge, text);+ panel.Show(target.Q, target.R);++ Assert.AreEqual("depopulated", Projects.CheckCityReason(C, bridge.State, "housing",+ Projects.CitiesFor(C, bridge.State, target.Q, target.R)[0], target.Q, target.R)?.Kind);+ Assert.AreEqual(text["info.map_action_reason.depopulated"], ui.Q<Label>("city-project-reason").text);+ Assert.IsNull(ui.Root.Q("city-project-housing"), "the shared refusal replaces the Build buttons");+ if (hebrew)+ Assert.IsFalse(System.Text.RegularExpressions.Regex.IsMatch(+ ui.Q<Label>("city-project-reason").text, "[A-Za-z]"),+ "the Hebrew panel must not fall back to the sim's English");+ }+[Test]public void AnOrderTheAttentionCannotPayIsRefusedByTheBridge(){diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex a32a52991..7ff135df2 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -677,6 +677,7 @@ info.map_action_reason.action_until: "{0} could be placed until {1}"info.map_action_reason.all_from: "Transit camps and housing projects can be placed from {0}"info.map_action_reason.maabarot_policy: "Transit camps need the ma'abarot policy"info.map_action_reason.not_land: "This hex is not land"+info.map_action_reason.depopulated: "Nothing can be built on a depopulated place"info.map_action_reason.too_far_one: "This hex is more than {0} hex from a settlement"info.map_action_reason.too_far_many: "This hex is more than {0} hexes from a settlement"info.map_action_reason.occupied: "This hex already has {0}"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex db3cb3520..fde650c09 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -788,6 +788,8 @@ info.map_action_reason.action_until: "אפשר היה להקים {0} עד {1}"info.map_action_reason.all_from: "אפשר להקים מעברות ומיזמי דיור החל מ־{0}"info.map_action_reason.maabarot_policy: "הקמת מעברות מחייבת את מדיניות המעברות"info.map_action_reason.not_land: "המשבצת הזאת אינה יבשה"+# For the native reviewer (#564): agent-drafted, #2573+info.map_action_reason.depopulated: "אי אפשר לבנות במקום מרוקן מתושבים"info.map_action_reason.too_far_one: "המשבצת הזאת נמצאת במרחק של יותר מ־{0} משבצת מיישוב"info.map_action_reason.too_far_many: "המשבצת הזאת נמצאת במרחק של יותר מ־{0} משבצות מיישוב"info.map_action_reason.occupied: "במשבצת הזאת כבר יש {0}"