A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Attack and Reinforce refusals: a sim constant each, shown in the UI's language (Fixes #2072) (#2075)
Beri415abe37a9ce
diff --git a/changelog.d/laneOM-2072.md b/changelog.d/laneOM-2072.mdnew file mode 100644index 000000000..2f4ac8f4b--- /dev/null+++ b/changelog.d/laneOM-2072.md@@ -0,0 +1,8 @@+### Fixed+- The unit card's Attack and Reinforce refusals ("A truce is in force", "Jerusalem has no military camp" and the others+ `Combat.Check` and `Training.Reinforce` give) now read in the UI's language, and each shows once: every reason is a+ public `Combat.Refused*` / `Training.Refused*` constant in the sim (a format where it carries a number, a town or a+ course), with its English unchanged, and `SimBridge.ReasonText` maps it to a `unit.attack_refused.*` or+ `unit.reinforce_refused.*` string for the card, the order queue and the end-of-turn toast (on the card and in+ the toast the town in its Hebrew name).+ The Hebrew lines wait for the native-speaker read (#564). Saves and goldens did not move (Fixes #2072).diff --git a/sim/Statecraft.Sim/Combat.cs b/sim/Statecraft.Sim/Combat.csindex e723442b5..de2c026eb 100644--- a/sim/Statecraft.Sim/Combat.cs+++ b/sim/Statecraft.Sim/Combat.cs@@ -82,6 +82,17 @@ namespace Statecraft.Simstatic List<Unit> Defenders(GameState s, Unit attacker, int q, int r) =>s.Units.Values.Where(x => x.Q == q && x.R == r && Military(x) && Player(x) != Player(attacker)).ToList();+ /// <summary><see cref="Check"/>'s own refusals (#2072); the unit, side and existing-order ones are Orders.Refused*. The UI+ /// maps each to its own string (SimBridge.ReasonText). The English is the reason a turn's Rejected list and a save carry,+ /// so it does not change; <see cref="RefusedArms"/> is a format, its values filled in invariantly.</summary>+ public const string RefusedNoHex = "An attack names a hex";+ public const string RefusedTruce = "A truce is in force";+ public const string RefusedOutOfRange = "That hex is beyond the unit's range";+ public const string RefusedNotAdjacent = "That hex is not next to the unit";+ public const string RefusedNoEnemy = "There is no enemy unit on that hex";+ public const string RefusedNoPoints = "That unit has no movement points left this turn";+ public const string RefusedArms = "An attack needs {0} Arms and the stock has {1}";+/// <summary>R-COMBAT-001's refusals: null when the player may strike (q, r), else the reason shown to the player./// Changes nothing: the unit card asks it for each enemy hex before it offers that hex (#754). Refused for an unknown/// unit, a halutz, an enemy unit, no hex, a hex not next to it (artillery: beyond its range), a hex with no enemy unit,@@ -91,23 +102,23 @@ namespace Statecraft.Simpublic static string? Check(Content c, GameState s, int unitId, int? q, int? r, bool enemy = false,IReadOnlyDictionary<int, int>? spent = null){- if (!s.Units.TryGetValue(unitId, out var u)) return "There is no such unit";- if (!Military(u)) return "Only a military unit takes that order";- if (Player(u) == enemy) return "That unit is not yours";- if (q == null || r == null) return "An attack names a hex";- if (!enemy && TruceInForce(s)) return "A truce is in force"; // R-COMBAT-009+ if (!s.Units.TryGetValue(unitId, out var u)) return Orders.RefusedNoUnit;+ if (!Military(u)) return Orders.RefusedNotMilitary;+ if (Player(u) == enemy) return Orders.RefusedNotYours;+ if (q == null || r == null) return RefusedNoHex;+ if (!enemy && TruceInForce(s)) return RefusedTruce; // R-COMBAT-009var target = Hex(q.Value, r.Value);- if (enemy && u.Order == Attack && u.OrderTarget == target) return "That unit already has that order";- if (!InReach(c, u, q.Value, r.Value)) return Guns(c, u) ? "That hex is beyond the unit's range" : "That hex is not next to the unit";- if (Defenders(s, u, q.Value, r.Value).Count == 0) return "There is no enemy unit on that hex";+ if (enemy && u.Order == Attack && u.OrderTarget == target) return Orders.RefusedAlready;+ if (!InReach(c, u, q.Value, r.Value)) return Guns(c, u) ? RefusedOutOfRange : RefusedNotAdjacent;+ if (Defenders(s, u, q.Value, r.Value).Count == 0) return RefusedNoEnemy;if (!enemy && spent != null && (Gdd03Military.Applies(c) && Guns(c, u)? Movement.AttackPoints(c, u) <= (spent.TryGetValue(unitId, out var used) ? used : 0): Movement.PointsLeft(c, s, unitId, spent) == 0))- return "That unit has no movement points left this turn";+ return RefusedNoPoints;if (enemy || !SpendsArms(c)) return null; // before Need, so gdd-0.3 never reads a pricevar mvp = c.RulesAt(s.Date).Mvp!;var need = Need(c, mvp, u);- return s.Arms < need ? FormattableString.Invariant($"An attack needs {need} Arms and the stock has {s.Arms}") : null;+ return s.Arms < need ? string.Format(CultureInfo.InvariantCulture, RefusedArms, need, s.Arms) : null;}/// <summary>R-ENEMY-001: gives the enemy AI's military unit a standing attack on (q, r) for resolver step 2, replacingdiff --git a/sim/Statecraft.Sim/Training.cs b/sim/Statecraft.Sim/Training.csindex e6e05556a..cef30f47a 100644--- a/sim/Statecraft.Sim/Training.cs+++ b/sim/Statecraft.Sim/Training.cs@@ -23,17 +23,34 @@ namespace Statecraft.Sim/// <summary>The facility a craftsman trains at: a completed city project of this kind (projects.yaml; Q-CRAFT-1).</summary>public const string Industry = "industry";- /// <summary>The facility's name in text the player reads.</summary>- static string Place(string facility) => facility == "military_camp" ? "military camp" : facility == Industry ? "completed industry project" : "Hakhshara";+ /// <summary><see cref="Reinforce"/>'s and <see cref="Start"/>'s refusals (#2072); the unit and side ones are Orders.Refused*.+ /// The UI maps each to its own string (SimBridge.ReasonText). The English is the reason a turn's Rejected list and a save+ /// carry, so it does not change; one with {0} is a format, its values (a unit id, a settlement's or course's name, a+ /// number) filled in invariantly. A missing facility has one refusal per facility.</summary>+ public const string RefusedNoCity = "There is no such city";+ public const string RefusedNotInCity = "Unit {0} is not in {1}";+ public const string RefusedNoCourse = "Unit {0} cannot take replacements";+ public const string RefusedNoLosses = "Unit {0} has no losses to replace";+ public const string RefusedRoomOne = "Unit {0} can take {1} more group";+ public const string RefusedRoomMany = "Unit {0} can take {1} more groups";+ public const string RefusedNoTraining = "There is no such training";+ public const string RefusedCount = "Train at least one group";+ public const string RefusedNoCamp = "{0} has no military camp";+ public const string RefusedNoIndustry = "{0} has no completed industry project";+ public const string RefusedNoHakhshara = "{0} has no Hakhshara";+ public const string RefusedIdle = "{0} has {1} civilians without work";+ public const string RefusedArms = "{0}: not enough Arms for {1} (need {2}, have {3})";++ static string Refused(string format, params object[] values) => string.Format(System.Globalization.CultureInfo.InvariantCulture, format, values);/// <summary>The course a type trains in, in text the player reads: the facility's, or the guns' or the armoured cars' own/// at a military camp (R-UNIT-008).</summary>- static string Course(UnitType t) =>+ public static string Course(UnitType t) =>t.Class == Combat.ArtilleryClass ? "artillery training" : t.Class == Armour ? "armoured car training": t.Facility == "military_camp" ? "basic training" : t.Facility == Industry ? "craft training" : "pioneer training";/// <summary>The course of <see cref="Course"/> as a report Arg (#1682): the UI words it from why.cause.course.<id>.</summary>- static string CourseId(UnitType t) =>+ public static string CourseId(UnitType t) =>t.Class == Combat.ArtilleryClass ? "artillery" : t.Class == Armour ? "armour": t.Facility == "military_camp" ? "basic" : t.Facility == Industry ? "craft" : "pioneer";@@ -94,18 +111,18 @@ namespace Statecraft.Simpublic static string? Reinforce(Content c, GameState s, int unit, string city, int count, List<Cause> why){PopulationLedger.RefuseAggregate(s);- if (!s.Units.TryGetValue(unit, out var u)) return "There is no such unit";- if (u.Side == "") return "Only a military unit takes that order";- if (u.Side != Movement.PlayerSide) return "That unit is not yours";- if (!s.Cities.ContainsKey(city)) return "There is no such city";+ if (!s.Units.TryGetValue(unit, out var u)) return Orders.RefusedNoUnit;+ if (u.Side == "") return Orders.RefusedNotMilitary;+ if (u.Side != Movement.PlayerSide) return Orders.RefusedNotYours;+ if (!s.Cities.ContainsKey(city)) return RefusedNoCity;var hex = c.SettlementHexes.First(h => h.Id == city);- if ((u.Q, u.R) != (hex.Q, hex.R)) return FormattableString.Invariant($"Unit {unit} is not in {PlayerText.Settlement(c, city)}");+ if ((u.Q, u.R) != (hex.Q, hex.R)) return Refused(RefusedNotInCity, unit, PlayerText.Settlement(c, city));var type = c.UnitTypes.First(t => t.Id == u.Type);var course = c.UnitTypes.FirstOrDefault(t => t.Side == type.Side && t.Class == type.Class && t.Facility != "");- if (course == null) return FormattableString.Invariant($"Unit {unit} cannot take replacements");+ if (course == null) return Refused(RefusedNoCourse, unit);var room = Room(s, u);- if (room <= 0) return FormattableString.Invariant($"Unit {unit} has no losses to replace");- if (count > room) return FormattableString.Invariant($"Unit {unit} can take {room} more {(room == 1 ? "group" : "groups")}");+ if (room <= 0) return Refused(RefusedNoLosses, unit);+ if (count > room) return Refused(room == 1 ? RefusedRoomOne : RefusedRoomMany, unit, room);return Start(c, s, city, course.Id, count, why, unit);}@@ -118,19 +135,19 @@ namespace Statecraft.Simstatic string? Start(Content c, GameState s, string city, string track, int count, List<Cause> why, int? unit){PopulationLedger.RefuseAggregate(s);- if (!s.Cities.TryGetValue(city, out var x)) return "There is no such city";+ if (!s.Cities.TryGetValue(city, out var x)) return RefusedNoCity;var type = c.UnitTypes.FirstOrDefault(t => t.Id == track && t.Facility != "");- if (type == null) return "There is no such training";- if (count < 1) return "Train at least one group";+ if (type == null) return RefusedNoTraining;+ if (count < 1) return RefusedCount;var name = PlayerText.Settlement(c, city);- if (!HasFacility(c, s, city, type.Facility)) return $"{name} has no {Place(type.Facility)}";+ if (!HasFacility(c, s, city, type.Facility)) return Refused(type.Facility == "military_camp" ? RefusedNoCamp : type.Facility == Industry ? RefusedNoIndustry : RefusedNoHakhshara, name);var idle = Idle(x);- if (count > idle) return FormattableString.Invariant($"{name} has {idle} civilians without work");+ if (count > idle) return Refused(RefusedIdle, name, idle);// R-ARMS-003 (D-G6, Q-UNIT-3): a recruit group takes arms_per_recruit_group Arms when its training starts, a gun or// armoured car crew its type's training_arms (R-UNIT-008, Q-ARTY-3); a short stock refuses the order. Pioneer// training takes none. The cohort keeps the count, and cancelling (R-TRAIN-002) returns it.var arms = type.Id == "recruit" ? (long)count * c.RulesAt(s.Date).Mvp!.ArmsPerRecruitGroup!.Value : (long)count * (type.TrainingArms ?? 0);- if (arms > s.Arms) return FormattableString.Invariant($"{name}: not enough Arms for {Course(type)} (need {arms}, have {s.Arms})");+ if (arms > s.Arms) return Refused(RefusedArms, name, Course(type), arms, s.Arms);var cost = count * type.TrainingCost;// Owner decision "Allow borrowing" (2026-10-15, #468 question 1): a short Treasury borrows, as map actions do.EconomySystem.PayOrBorrow(c, s, cost, "for training", why, CauseKeys.Purpose.Training);diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex b64998ce1..95234de9d 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -404,7 +404,7 @@ namespace Statecraft.Game.UIunitName: id => unitLayer.Tokens.Where(p => UnitCard.SimUnit(bridge.Content, bridge.State, p.Token) == id).Select(p => UnitCard.For(p, bridge.State, text, bridge.Content.IsGdd, bridge.Content, townNamesHe).Title).FirstOrDefault(),unitDone: FocusNextUnit, showRoute: map.ShowRoute, selectPioneer: FocusPioneer, clearSelection: () => { unitLayer.Select(null); map.ClearSelection(); }));- toast.Units = unitData; toast.TownNamesHe = townNamesHe; why.TownNamesHe = townNamesHe;+ toast.Units = unitData; toast.TownNamesHe = townNamesHe; why.TownNamesHe = townNamesHe; bridge.TownNamesHe = townNamesHe;report.TownNamesHe = townNamesHe; hudPresenter.TownNamesHe = townNamesHe;// A smoke session never touches the player's save: no autosave, and no New Game (which deletes the autosave).// Leaving New Game out is safer than handing it a throwaway store: no file is ever deleted, no path has to bediff --git a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs b/unity/Assets/Scripts/UI/InfoPanelPresenter.csindex 73cb3902a..578aaff7b 100644--- a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs+++ b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs@@ -762,12 +762,14 @@ namespace Statecraft.Game.UI{var why = orderUnit is int ou ? Orders.Check(c, s, ou, order) : null;button.style.display = orderUnit != null && why == null ? DisplayStyle.Flex : DisplayStyle.None;- if (why != null && own && SimBridge.ReasonText(text, why) is var said && !refusals.Contains(said)) refusals.Add(said);+ if (why != null && own && SimBridge.ReasonText(text, why, c, townNamesHe) is var said && !refusals.Contains(said)) refusals.Add(said);}- // Attack (#754): offered where the sim's Combat.Check takes some hex; its refusals in reach show as the others'.+ // Attack (#754): offered where the sim's Combat.Check takes some hex; its refusals in reach show as the others', in the+ // UI's language too (#2072), each once.var attacks = AttackTargets();attackButton.style.display = attacks is { } at && at.hexes.Count > 0 ? DisplayStyle.Flex : DisplayStyle.None;- foreach (var why in attacks?.refused ?? new List<string>()) if (own && !refusals.Contains(why)) refusals.Add(why);+ foreach (var why in attacks?.refused ?? new List<string>())+ if (own && SimBridge.ReasonText(text, why, c, townNamesHe) is var said && !refusals.Contains(said)) refusals.Add(said);// Send home (#1309): Demobilization.Check is the complete eligibility rule. A refusal hides the order and adds// no card copy; the player sees it only after the relevant armistice makes the order available.var sendHomeWhy = orderUnit is int du ? Demobilization.Check(c, s, du, bridge.Session.Now.Attacked) : null;@@ -784,7 +786,7 @@ namespace Statecraft.Game.UIvar n = System.Math.Max(1, System.Math.Min(Training.Room(s, formation), Training.Available(s, home.Id, bridge.Queued)));var why = Training.Reinforce(c, s.Clone(), ru, home.Id, n, new List<Cause>());if (why == null) reinforce = new Reinforce(ru, home.Id, n);- else if (!refusals.Contains(why)) refusals.Add(why);+ else if (SimBridge.ReasonText(text, why, c, townNamesHe) is var said && !refusals.Contains(said)) refusals.Add(said);}reinforceButton.style.display = reinforce != null ? DisplayStyle.Flex : DisplayStyle.None;if (reinforce is Reinforce offer) reinforceButton.text = text.Format("unit.order.reinforce", offer.Count);diff --git a/unity/Assets/Scripts/UI/SimBridge.cs b/unity/Assets/Scripts/UI/SimBridge.csindex 65f0be270..ade65f914 100644--- a/unity/Assets/Scripts/UI/SimBridge.cs+++ b/unity/Assets/Scripts/UI/SimBridge.cs@@ -2,6 +2,7 @@using System;using System.Collections.Generic;using System.Linq;+using System.Text.RegularExpressions;using Statecraft.Sim;namespace Statecraft.Game.UI@@ -223,13 +224,62 @@ namespace Statecraft.Game.UI[Orders.RefusedNotYours] = "unit.order_refused.not_yours",[Orders.RefusedArtilleryHold] = "unit.order_refused.artillery_hold",[Orders.RefusedAlready] = "unit.order_refused.already",+ [Combat.RefusedNoHex] = "unit.attack_refused.no_hex",+ [Combat.RefusedTruce] = "unit.attack_refused.truce",+ [Combat.RefusedOutOfRange] = "unit.attack_refused.out_of_range",+ [Combat.RefusedNotAdjacent] = "unit.attack_refused.not_adjacent",+ [Combat.RefusedNoEnemy] = "unit.attack_refused.no_enemy",+ [Combat.RefusedNoPoints] = "unit.attack_refused.no_points",+ [Training.RefusedNoCity] = "unit.reinforce_refused.no_city",+ [Training.RefusedNoTraining] = "unit.reinforce_refused.no_training",+ [Training.RefusedCount] = "unit.reinforce_refused.count",};- /// <summary>A sim refusal in the UI's language where it has a string (<see cref="ReasonKeys"/>), else the sim's English as- /// given. The queue's refusals, the unit card's (InfoPanelPresenter) and the end of turn's (ToastPresenter) go through it.</summary>- public static string ReasonText(UiText text, string reason) => ReasonKeys.TryGetValue(reason, out var key) ? text[key] : reason;+ /// <summary>The sim's refusals that carry values (#2072: Combat.Check's Arms, Training.Reinforce's unit, settlement,+ /// course and counts): each format constant, read back from its English with its values in order, and its key.</summary>+ static readonly (Regex pattern, string key)[] ReasonFormats = new (string format, string key)[]+ {+ (Combat.RefusedArms, "unit.attack_refused.arms"),+ (Training.RefusedNotInCity, "unit.reinforce_refused.not_in_city"),+ (Training.RefusedNoCourse, "unit.reinforce_refused.no_course"),+ (Training.RefusedNoLosses, "unit.reinforce_refused.no_losses"),+ (Training.RefusedRoomOne, "unit.reinforce_refused.room_one"),+ (Training.RefusedRoomMany, "unit.reinforce_refused.room_many"),+ (Training.RefusedNoCamp, "unit.reinforce_refused.no_camp"),+ (Training.RefusedNoIndustry, "unit.reinforce_refused.no_industry"),+ (Training.RefusedNoHakhshara, "unit.reinforce_refused.no_hakhshara"),+ (Training.RefusedIdle, "unit.reinforce_refused.idle"),+ (Training.RefusedArms, "unit.reinforce_refused.arms"),+ }.Select(x => (new Regex("^" + string.Join("(.+?)", Regex.Split(x.format, @"\{\d+\}").Select(Regex.Escape)) + "$"), x.key)).ToArray();++ /// <summary>A sim refusal in the UI's language where it has a string (<see cref="ReasonKeys"/>, <see cref="ReasonFormats"/>),+ /// else the sim's English as given. The queue's refusals, the unit card's (InfoPanelPresenter) and the end of turn's+ /// (ToastPresenter) go through it. With <paramref name="c"/> a value that is a settlement's name reads as the UI names the+ /// town (its Hebrew name from <paramref name="townsHe"/> in Hebrew), and a course's English as why.cause.course.*.</summary>+ public static string ReasonText(UiText text, string reason, Content? c = null, IReadOnlyDictionary<string, string>? townsHe = null)+ {+ if (ReasonKeys.TryGetValue(reason, out var key)) return text[key];+ foreach (var (pattern, format) in ReasonFormats)+ if (pattern.Match(reason) is { Success: true } m)+ return text.Format(format, m.Groups.Cast<Group>().Skip(1).Select(v => (object)ReasonValue(text, v.Value, c, townsHe)).ToArray());+ return reason;+ }++ static string ReasonValue(UiText text, string value, Content? c, IReadOnlyDictionary<string, string>? townsHe)+ {+ if (c == null) return value;+ var town = c.SettlementNames.FirstOrDefault(n => n.Value == value).Key;+ if (town != null)+ return text["ui.lang"] == UiLanguage.Hebrew && townsHe != null && townsHe.TryGetValue(town, out var he) && !string.IsNullOrWhiteSpace(he) ? he : value;+ var course = c.UnitTypes.FirstOrDefault(t => t.Facility != "" && Training.Course(t) == value);+ return course != null ? text["why.cause.course." + Training.CourseId(course)] : value;+ }++ /// <summary>Each settlement's Hebrew name (name_he), by id, for <see cref="Refuse"/>'s Hebrew (#2072): GameRoot sets it, as+ /// it sets the card's and the toast's.</summary>+ public IReadOnlyDictionary<string, string>? TownNamesHe { get; set; }- string? Refuse(string reason) { reason = ReasonText(text, reason); Refused?.Invoke(reason); return reason; }+ string? Refuse(string reason) { reason = ReasonText(text, reason, Content, TownNamesHe); Refused?.Invoke(reason); return reason; }static void Notify(Action? handlers){diff --git a/unity/Assets/Scripts/UI/ToastPresenter.cs b/unity/Assets/Scripts/UI/ToastPresenter.csindex 9fc6d0a57..e03e4c0a3 100644--- a/unity/Assets/Scripts/UI/ToastPresenter.cs+++ b/unity/Assets/Scripts/UI/ToastPresenter.cs@@ -26,7 +26,7 @@ namespace Statecraft.Game.UIpublic ToastPresenter(VisualElement root, SimBridge bridge, UiText text){label = root.Q<Label>("toast"); this.text = text; this.bridge = bridge;- onTurnEnded = r => Show(r.Select(x => text.Format("toast.refused", SimBridge.ReasonText(text, x.Reason))));+ onTurnEnded = r => Show(r.Select(x => text.Format("toast.refused", SimBridge.ReasonText(text, x.Reason, bridge.Content, TownNamesHe))));onCommitted = why => Show(why.Where(x => WhyKeys.All.Contains(x.Key)) // unit lines only: a call-up order's line (B1 key) is no toast.Select(x => UnitNames.Line(x, bridge.Content, units, text, TownNamesHe)));onRouteStep = _ =>diff --git a/unity/Assets/Tests/EditMode/HebrewUiTests.cs b/unity/Assets/Tests/EditMode/HebrewUiTests.csindex 464132cc7..fc1919490 100644--- a/unity/Assets/Tests/EditMode/HebrewUiTests.cs+++ b/unity/Assets/Tests/EditMode/HebrewUiTests.cs@@ -90,6 +90,57 @@ public class HebrewUiTests}}+ // #2072: every Combat.Check and Training.Reinforce refusal (their Refused* constants) has a string in both files. Each+ // format is filled with distinct values as the sim fills it (a multi-word town, a real course, different numbers) and read+ // with content: the English is the sim's own text, the Hebrew is its line with the Hebrew town and course in their slots,+ // its placeholders in the English's order, and no Latin letter left (owner review item 2: "7"s everywhere caught no+ // swapped slot, no capture in the wrong order, no lazy capture splitting a town).+ [TestCase(typeof(Statecraft.Sim.Combat))]+ [TestCase(typeof(Statecraft.Sim.Training))]+ public void EveryAttackAndReinforceRefusalHasAStringInBothLanguages(System.Type check)+ {+ var c = Statecraft.Sim.ContentLoader.Load(Paths.Content);+ var namesHe = SettlementPlacer.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", SettlementPlacer.DefaultFileName))).ToDictionary(t => t.Id, t => t.NameHe);+ var place = c.SettlementNames.Single(x => x.Value == "Rishon LeZion");+ var recruit = c.UnitTypes.Single(t => t.Id == "recruit");+ object townSlot = new object(), courseSlot = new object();+ // Each format's values in the sim's order (Combat.Check, Training.Reinforce/Start), and the key it reads as.+ var filled = new Dictionary<string, (string key, object[] values)>+ {+ [Statecraft.Sim.Combat.RefusedArms] = ("unit.attack_refused.arms", new object[] { 12, 3 }),+ [Statecraft.Sim.Training.RefusedNotInCity] = ("unit.reinforce_refused.not_in_city", new object[] { 41, townSlot }),+ [Statecraft.Sim.Training.RefusedNoCourse] = ("unit.reinforce_refused.no_course", new object[] { 41 }),+ [Statecraft.Sim.Training.RefusedNoLosses] = ("unit.reinforce_refused.no_losses", new object[] { 41 }),+ [Statecraft.Sim.Training.RefusedRoomOne] = ("unit.reinforce_refused.room_one", new object[] { 41, 1 }),+ [Statecraft.Sim.Training.RefusedRoomMany] = ("unit.reinforce_refused.room_many", new object[] { 41, 5 }),+ [Statecraft.Sim.Training.RefusedNoCamp] = ("unit.reinforce_refused.no_camp", new object[] { townSlot }),+ [Statecraft.Sim.Training.RefusedNoIndustry] = ("unit.reinforce_refused.no_industry", new object[] { townSlot }),+ [Statecraft.Sim.Training.RefusedNoHakhshara] = ("unit.reinforce_refused.no_hakhshara", new object[] { townSlot }),+ [Statecraft.Sim.Training.RefusedIdle] = ("unit.reinforce_refused.idle", new object[] { townSlot, 6 }),+ [Statecraft.Sim.Training.RefusedArms] = ("unit.reinforce_refused.arms", new object[] { townSlot, courseSlot, 12, 3 }),+ };+ object English(object v) => v == townSlot ? place.Value : v == courseSlot ? Statecraft.Sim.Training.Course(recruit) : v;+ object Hebrew(object v) => v == townSlot ? namesHe[place.Key] : v == courseSlot ? He["why.cause.course." + Statecraft.Sim.Training.CourseId(recruit)] : v;+ string Slots(string line) => string.Join(",", Regex.Matches(line, @"\{\d+\}").Cast<Match>().Select(m => m.Value));+ var formats = check.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)+ .Where(f => f.IsLiteral && f.Name.StartsWith("Refused")).Select(f => (string)f.GetRawConstantValue()).ToList();+ Assert.That(formats, Is.Not.Empty, check.Name + " has no Refused* constants");+ foreach (var format in formats)+ {+ var hasValues = Slots(format) != "";+ Assert.AreEqual(hasValues, filled.ContainsKey(format), "a format and only a format is filled here: " + format);+ var reason = hasValues ? string.Format(System.Globalization.CultureInfo.InvariantCulture, format, filled[format].values.Select(English).ToArray()) : format;+ Assert.AreEqual(reason, SimBridge.ReasonText(En, reason, c, namesHe), "the English string is the sim's own");+ var he = SimBridge.ReasonText(He, reason, c, namesHe);+ StringAssert.IsMatch("[\u05D0-\u05EA]", he, "no Hebrew string for: " + reason);+ StringAssert.DoesNotMatch("[A-Za-z]", he, reason);+ if (!hasValues) continue;+ var (key, values) = filled[format];+ Assert.AreEqual(Slots(En[key]), Slots(He[key]), key + ": the Hebrew line takes its values in the English's order");+ Assert.AreEqual(He.Format(key, values.Select(Hebrew).ToArray()), he, "the values in their slots: " + reason);+ }+ }+[Test]public void TheGameIsEnglishUnlessHebrewIsAskedFor(){diff --git a/unity/Assets/Tests/EditMode/InfoPanelLayoutTests.cs b/unity/Assets/Tests/EditMode/InfoPanelLayoutTests.csindex 573a2f0b8..d4fe4e488 100644--- a/unity/Assets/Tests/EditMode/InfoPanelLayoutTests.cs+++ b/unity/Assets/Tests/EditMode/InfoPanelLayoutTests.cs@@ -938,4 +938,40 @@ public class InfoPanelLayoutTests},text:text,hebrew:hebrew,unit:()=>f.token);}+ // #2072: a unit's card with an attack refusal (a truce the player accepted, R-COMBAT-009, with an enemy next to it) and a+ // reinforce refusal (Training.Reinforce in the city it stands in) lists both in the UI's language: in English each is the+ // sim's own text, in Hebrew no refusal line has a Latin letter (the town in Hebrew too).+ [Test]+ public void CardRefusesAttackAndReinforceInTheUiLanguage([Values(false,true)] bool hebrew)+ {+ var f=MilitaryFixture("infantry");var g=f.session;var c=g.Content;var s=g.State;+ var namesHe=SettlementPlacer.Parse(MapFile(SettlementPlacer.DefaultFileName)).ToDictionary(t=>t.Id,t=>t.NameHe);+ var at=c.SettlementHexes.First(h=>s.Cities.ContainsKey(h.Id)&&namesHe.ContainsKey(h.Id));+ c.Hexes=c.Hexes.Concat(new[] { (at.Q,at.R),(at.Q+1,at.R) }.Where(x=>c.HexAt(x.Item1,x.Item2)==null) // the city's hex and the+ .Select(x=>new MapHex { Q=x.Item1,R=x.Item2,Biome="coastal_plain",Land=true })).ToList(); // enemy's, beside the board+ s.Units[f.id]=new Unit(f.id,s.Units[f.id].Type,at.Q,at.R,side:Movement.PlayerSide,strength:6,full:10);+ s.Units[9000]=new Unit(9000,c.UnitTypes.First(t=>t.Side!=""&&t.Side!=Movement.PlayerSide&&t.Class=="infantry").Id,at.Q+1,at.R,side:"egypt",strength:6);+ s.ChosenOptions["first_truce"]="accept";+ var text=hebrew?UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text,"strings.he.yaml"):Text;+ var bridge=new SimBridge(g,text);+ var attackWhy=Combat.Check(c,s,f.id,at.Q+1,at.R,spent:bridge.Spent);+ var home=c.SettlementHexes.First(h=>h.Q==at.Q&&h.R==at.R&&s.Cities.ContainsKey(h.Id)); // the city the card reinforces from+ var n=System.Math.Max(1,System.Math.Min(Training.Room(s,s.Units[f.id]),Training.Available(s,home.Id,bridge.Queued)));+ var reinforceWhy=Training.Reinforce(c,s.Clone(),f.id,home.Id,n,new List<Cause>());+ Assert.IsNotNull(attackWhy,"the truce refuses the attack");Assert.IsNotNull(reinforceWhy,"the city refuses the reinforcement");+ using var ui=new UiTestKit();+ var info=new InfoPanelPresenter(ui.Root,bridge,text,Names(),selectedUnit:()=>f.token,townNamesHe:namesHe);+ info.ShowUnit();+ var lines=ui.Q<Label>("info-reason").text.Split('\n');+ if (hebrew)+ {+ Assert.GreaterOrEqual(lines.Length,2,"both refusals are listed");+ CollectionAssert.Contains(lines,SimBridge.ReasonText(text,attackWhy!,c,namesHe),"the attack refusal, in Hebrew");+ CollectionAssert.Contains(lines,SimBridge.ReasonText(text,reinforceWhy!,c,namesHe),"the reinforce refusal, in Hebrew");+ foreach (var line in lines) StringAssert.DoesNotMatch("[A-Za-z]",line,"a refusal line in the sim's English");+ }+ else { CollectionAssert.Contains(lines,attackWhy);CollectionAssert.Contains(lines,reinforceWhy); }+ info.Dispose();+ }+}diff --git a/unity/Assets/Tests/EditMode/UnitOrdersTests.cs b/unity/Assets/Tests/EditMode/UnitOrdersTests.csindex ec66f5327..a84577f8e 100644--- a/unity/Assets/Tests/EditMode/UnitOrdersTests.cs+++ b/unity/Assets/Tests/EditMode/UnitOrdersTests.cs@@ -395,7 +395,7 @@ public class UnitOrdersTestspublic void ReinforceQueuesTheMissingStrengthFromTheCityTheUnitStandsIn(){var he = UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");- foreach (var (t, label) in new[] { (Text, "Reinforce +"), (he, "תגבור +") })+ foreach (var (t, label, arms) in new[] { (Text, "Reinforce +", "not enough Arms"), (he, "תגבור +", "אין די כלי נשק") }){using var ui = new UiTestKit();var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);@@ -414,7 +414,7 @@ public class UnitOrdersTestsg.State.Arms = 0;info.ShowUnit();Assert.AreEqual(DisplayStyle.None, button.style.display.value, "no Arms, no Reinforce");- StringAssert.Contains("not enough Arms", ui.Q<Label>("info-reason").text, "the sim's reason shows");+ StringAssert.Contains(arms, ui.Q<Label>("info-reason").text, "the sim's reason shows, in the UI's language (#2072)");g.State.Arms = 100;info.ShowUnit();@@ -430,6 +430,34 @@ public class UnitOrdersTests}}+ /// <summary>#2072, owner review item 1: a Reinforce the sim refuses for Arms ("Tel Aviv: not enough Arms for basic training+ /// (need ..)") reaches the player through SimBridge, in Hebrew whole: the town and the course in Hebrew too, no Latin+ /// letter. The bridge queues it (a Reinforce waits for End turn) and End turn raises the sim's refusal, which the toast+ /// reads. SimBridge.Refuse never sees it: a queue-time refusal (Orders, Combat, Movement) carries no town or course.</summary>+ [Test]+ public void AReinforceRefusedThroughTheBridgeReadsInHebrewWhole()+ {+ var he = UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");+ var namesHe = SettlementPlacer.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", SettlementPlacer.DefaultFileName))).ToDictionary(t => t.Id, t => t.NameHe);+ using var ui = new UiTestKit();+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ var bridge = new SimBridge(g, he) { TownNamesHe = namesHe };+ using var toast = new ToastPresenter(ui.Root, bridge, he) { TownNamesHe = namesHe };+ var token = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a).Single(x => x.Unit.Id == "golani");+ var id = UnitCard.SimUnit(C, g.State, token.Unit)!.Value;+ var u = g.State.Units[id];+ var city = C.SettlementHexes.Single(h => h.Id == "tel_aviv");+ g.State.Units[id] = new Unit(u.Id, u.Type, city.Q, city.R, u.Service, u.Side, u.Strength - 2, u.Order, u.OrderTarget, u.HomeCity, u.Strength);+ g.State.Arms = 0;+ Assert.IsNull(bridge.Queue(new Reinforce(id, "tel_aviv", 2)), "the bridge queues it");+ var rejected = bridge.EndTurn().Rejected.Single(x => x.Command is Reinforce).Reason;+ StringAssert.StartsWith("Tel Aviv: not enough Arms for basic training", rejected, "the sim's English, with a town and a course");+ var line = ui.Q<Label>("toast").text;+ StringAssert.Contains(namesHe["tel_aviv"], line, "the town in Hebrew");+ StringAssert.Contains(he["why.cause.course.basic"], line, "the course in Hebrew");+ StringAssert.DoesNotMatch("[A-Za-z]", line, "no English left in the refusal");+ }+/// <summary>Codex's review of #1527, finding 3, on the card: once Send home is queued for a unit, the card offers it no/// other order (Move, Fortify, Hold, Attack, Reinforce, Skip, nor Send home again) and says the unit goes home.</summary>[Test]diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 67daf9cdf..d39948a09 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -925,6 +925,29 @@ unit.order_refused.not_yours: "That unit is not yours"unit.order_refused.artillery_hold: "Artillery does not hold ground"unit.order_refused.already: "That unit already has that order"+# #2072 Attack and Reinforce refusals (Combat.Check, Training.Reinforce), shown on the unit card and in the toast. Each+# English line is the sim's own text; {0}, {1}... are the values it fills in.+unit.attack_refused.no_hex: "An attack names a hex"+unit.attack_refused.truce: "A truce is in force"+unit.attack_refused.out_of_range: "That hex is beyond the unit's range"+unit.attack_refused.not_adjacent: "That hex is not next to the unit"+unit.attack_refused.no_enemy: "There is no enemy unit on that hex"+unit.attack_refused.no_points: "That unit has no movement points left this turn"+unit.attack_refused.arms: "An attack needs {0} Arms and the stock has {1}"+unit.reinforce_refused.no_city: "There is no such city"+unit.reinforce_refused.not_in_city: "Unit {0} is not in {1}"+unit.reinforce_refused.no_course: "Unit {0} cannot take replacements"+unit.reinforce_refused.no_losses: "Unit {0} has no losses to replace"+unit.reinforce_refused.room_one: "Unit {0} can take {1} more group"+unit.reinforce_refused.room_many: "Unit {0} can take {1} more groups"+unit.reinforce_refused.no_training: "There is no such training"+unit.reinforce_refused.count: "Train at least one group"+unit.reinforce_refused.no_camp: "{0} has no military camp"+unit.reinforce_refused.no_industry: "{0} has no completed industry project"+unit.reinforce_refused.no_hakhshara: "{0} has no Hakhshara"+unit.reinforce_refused.idle: "{0} has {1} civilians without work"+unit.reinforce_refused.arms: "{0}: not enough Arms for {1} (need {2}, have {3})"+# #1682 remaining Cause producers. English report wording preserved.why.cause.workers_assigned: "{0}: {1} groups in work"why.cause.wages_paid: "{0}: jobs paid {1}"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex cac18198d..80ea04e32 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -1028,6 +1028,30 @@ unit.order_refused.not_yours: "היחידה אינה שלך"unit.order_refused.artillery_hold: "ארטילריה אינה מחזיקה בשטח"unit.order_refused.already: "היחידה כבר קיבלה פקודה זו"+# #2072 Attack and Reinforce refusals (Combat.Check, Training.Reinforce), shown on the unit card and in the toast. A+# settlement in {0}/{1} opens the line as its label or follows a prefix, so no verb agrees with its gender (HE-15).+# Approved by Beri, a native speaker, on #2072 (31 Oct 2026), all 20 lines as written. For the native reviewer (#564).+unit.attack_refused.no_hex: "יש לבחור משושה להתקפה"+unit.attack_refused.truce: "הפוגה בתוקף"+unit.attack_refused.out_of_range: "המשושה מחוץ לטווח של היחידה"+unit.attack_refused.not_adjacent: "המשושה אינו סמוך ליחידה"+unit.attack_refused.no_enemy: "אין יחידת אויב במשושה הזה"+unit.attack_refused.no_points: "ליחידה לא נותרו נקודות תנועה בתור הזה"+unit.attack_refused.arms: "להתקפה נדרשים {0} כלי נשק ובמלאי יש {1}"+unit.reinforce_refused.no_city: "אין עיר כזאת"+unit.reinforce_refused.not_in_city: "יחידה {0} אינה ב{1}"+unit.reinforce_refused.no_course: "יחידה {0} אינה יכולה לקבל תגבורת"+unit.reinforce_refused.no_losses: "ליחידה {0} אין אבדות להשלים"+unit.reinforce_refused.room_one: "יחידה {0} יכולה לקבל עוד קבוצות: {1}"+unit.reinforce_refused.room_many: "יחידה {0} יכולה לקבל עוד קבוצות: {1}"+unit.reinforce_refused.no_training: "אין אימון כזה"+unit.reinforce_refused.count: "יש לאמן לפחות קבוצה אחת"+unit.reinforce_refused.no_camp: "{0}: אין מחנה צבאי"+unit.reinforce_refused.no_industry: "{0}: אין מיזם תעשייה שהושלם"+unit.reinforce_refused.no_hakhshara: "{0}: אין מחנה הכשרה"+unit.reinforce_refused.idle: "{0}: אין די אזרחים ללא עבודה (יש {1})"+unit.reinforce_refused.arms: "{0}: אין די כלי נשק ל{1} (נדרשים {2}, יש {3})"+# #1682 remaining Cause producers. Agent-drafted Hebrew: native-review-pending (#564).# SENSITIVE: capture, displacement, Deport, annexation and occupation also await sensitivity review.why.cause.workers_assigned: "{0}: קבוצות בעבודה: {1}"