Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Hebrew refusals, batch 3: capture answers reuse the reviewed capture.refusal.* lines (Refs #2707) (#2931)

Beri3ef200afb06e
diff --git a/changelog.d/2707-refusals-batch-3.md b/changelog.d/2707-refusals-batch-3.md
new file mode 100644
index 000000000..6fc57e8f4
--- /dev/null
+++ b/changelog.d/2707-refusals-batch-3.md
@@ -0,0 +1,5 @@
+### Fixed
+
+- A capture or end-of-occupation answer that the end of turn refuses (no Israeli unit left on the place, no free hex to
+ withdraw to, no one to deport, already a city, an unknown choice) now reads in the toast as the capture dialog says it,
+ in Hebrew with the place's Hebrew name. Before, it showed the sim's English in a Hebrew game.
diff --git a/sim/Statecraft.Sim/Cities.cs b/sim/Statecraft.Sim/Cities.cs
index dbacce2cb..7ea043c06 100644
--- a/sim/Statecraft.Sim/Cities.cs
+++ b/sim/Statecraft.Sim/Cities.cs
@@ -42,6 +42,9 @@ namespace Statecraft.Sim
public static int NearestUnit(decimal people, int peoplePerUnit) =>
(int)Math.Round(people / peoplePerUnit, MidpointRounding.AwayFromZero);
+ /// <summary><see cref="Annex"/>'s refusal, {0} the place's name: a constant for the UI's string (#2707).</summary>
+ public const string RefusedAlreadyCity = "{0} is already a city";
+
/// <summary>R-CTRL-016 (OWNER QUESTION 1 (a) on #799, the starting-city rule): a stayed target joins the player's
/// population as one new city: its approved people in units (R-CITY-007), homes equal to them, jobs equal to the
/// employed (people times employed_share to the nearest unit), the usual start condition, and no refugees, recruits or
@@ -49,7 +52,7 @@ namespace Statecraft.Sim
/// reason with the state unchanged (the id is already a city).</summary>
internal static string? Annex(Content c, GameState s, SettlementTarget t)
{
- if (s.Cities.ContainsKey(t.Id)) return $"{c.SettlementNames[t.Id]} is already a city";
+ if (s.Cities.ContainsKey(t.Id)) return string.Format(System.Globalization.CultureInfo.InvariantCulture, RefusedAlreadyCity, c.SettlementNames[t.Id]);
var r = c.RulesAt(s.Date).Mvp!;
var people = t.Annexation!.People!.Value; // the loader requires both values on a stayed row
var units = StartUnits(people, r.PeoplePerUnit);
diff --git a/sim/Statecraft.Sim/SettlementControl.cs b/sim/Statecraft.Sim/SettlementControl.cs
index 26e5e0e49..184198fa1 100644
--- a/sim/Statecraft.Sim/SettlementControl.cs
+++ b/sim/Statecraft.Sim/SettlementControl.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
namespace Statecraft.Sim
@@ -120,15 +121,23 @@ namespace Statecraft.Sim
if (!c.RulesAt(s.Date).Mvp!.DeportInPlay) return new CaptureRefusal(CaptureRefusal.NotInPlay, "Deport is not built yet");
// R-CTRL-018, OWNER QUESTION 4 (a) on #799: a fled town has no one left to deport, so Deport stays listed
// third but is refused with this reason, which the options helper shows on its button.
- return s.Settlements[id].Fled ? new CaptureRefusal(CaptureRefusal.NoOneToDeport, NoOneToDeport) : Depopulate(c, s, id, why);
+ return s.Settlements[id].Fled ? new CaptureRefusal(CaptureRefusal.NoOneToDeport, RefusedNoOneToDeport) : Depopulate(c, s, id, why);
default: return UnknownOutcome;
}
}
/// <summary>Deport's refusal for a fled town (OWNER QUESTION 4 (a) on #799; in the owner's sensitivity packet).</summary>
- const string NoOneToDeport = "Its residents fled when it was captured, so there is no one to deport";
+ public const string RefusedNoOneToDeport = "Its residents fled when it was captured, so there is no one to deport";
- static CaptureRefusal UnknownOutcome => new CaptureRefusal(CaptureRefusal.UnknownOutcome, "That outcome is not known");
+ /// <summary>The capture and end-of-occupation refusals the end of turn reports that the UI shows as a reviewed
+ /// capture.refusal.* line, as constants (#2707). {0} is the place's name.</summary>
+ public const string RefusedUnknownOutcome = "That outcome is not known",
+ RefusedOccupyNeedsUnit = "Occupy needs an Israeli military unit on {0}",
+ RefusedAnnexNeedsUnit = "Annex needs an Israeli military unit on {0}",
+ RefusedWithdrawNeedsUnit = "Withdraw needs an Israeli military unit on {0}",
+ RefusedNoFreeHex = "A unit has no free hex next to {0} to withdraw to";
+
+ static CaptureRefusal UnknownOutcome => new CaptureRefusal(CaptureRefusal.UnknownOutcome, RefusedUnknownOutcome);
/// <summary>The kind of <see cref="EndOccupation"/>, with one attention_cost key (R-CTRL-014).</summary>
public const string EndKind = "end_occupation";
@@ -172,7 +181,7 @@ namespace Statecraft.Sim
case WithdrawOutcome:
// R-CTRL-014: withdrawing needs the unit that holds the place too, as annexing does.
if (!Garrisoned(s, c.SettlementTargets.First(x => x.Id == id)))
- return new CaptureRefusal(CaptureRefusal.NeedsUnit, $"Withdraw needs an Israeli military unit on {c.SettlementNames[id]}");
+ return new CaptureRefusal(CaptureRefusal.NeedsUnit, string.Format(CultureInfo.InvariantCulture, RefusedWithdrawNeedsUnit, c.SettlementNames[id]));
return Withdraw(c, s, id, why, false);
default: return UnknownOutcome;
}
@@ -190,7 +199,7 @@ namespace Statecraft.Sim
{
var t = c.SettlementTargets.First(x => x.Id == id); // only a target gets a record (R-CTRL-004)
var name = c.SettlementNames[id];
- if (!Garrisoned(s, t)) return new CaptureRefusal(CaptureRefusal.NeedsUnit, $"Annex needs an Israeli military unit on {name}");
+ if (!Garrisoned(s, t)) return new CaptureRefusal(CaptureRefusal.NeedsUnit, string.Format(CultureInfo.InvariantCulture, RefusedAnnexNeedsUnit, name));
var x = s.Settlements[id];
// Cities.Annex's one refusal: the id is already a city.
if (!x.Fled && Cities.Annex(c, s, t) is string refused) return new CaptureRefusal(CaptureRefusal.AlreadyCity, refused);
@@ -255,7 +264,7 @@ namespace Statecraft.Sim
{
foreach (var x in moved) s.Units[x.From.Id] = x.From; // back as it was
moved.Clear();
- return new CaptureRefusal(CaptureRefusal.NoFreeHex, $"A unit has no free hex next to {name} to withdraw to");
+ return new CaptureRefusal(CaptureRefusal.NoFreeHex, string.Format(CultureInfo.InvariantCulture, RefusedNoFreeHex, name));
}
var w = new Unit(u.Id, u.Type, to.Value.Q, to.Value.R, u.Service, u.Side, u.Strength, u.Order, u.OrderTarget, u.HomeCity, u.Full, u.CombatXp);
s.Units[u.Id] = w;
@@ -311,7 +320,7 @@ namespace Statecraft.Sim
{
var t = c.SettlementTargets.First(x => x.Id == id); // only a target gets a record (R-CTRL-004)
var name = c.SettlementNames[id];
- if (!Garrisoned(s, t)) return new CaptureRefusal(CaptureRefusal.NeedsUnit, $"Occupy needs an Israeli military unit on {name}");
+ if (!Garrisoned(s, t)) return new CaptureRefusal(CaptureRefusal.NeedsUnit, string.Format(CultureInfo.InvariantCulture, RefusedOccupyNeedsUnit, name));
var x = s.Settlements[id];
var turns = c.RulesAt(s.Date).Mvp!.OccupationTurns!.Value;
s.Settlements[id] = new SettlementControl(x.Owner, Occupied, x.Since, x.Depopulated, x.Combatants, x.Buildings, turns, x.Fled);
diff --git a/unity/Assets/Scripts/UI/SimBridge.cs b/unity/Assets/Scripts/UI/SimBridge.cs
index 7fedf3b6d..f23b519ce 100644
--- a/unity/Assets/Scripts/UI/SimBridge.cs
+++ b/unity/Assets/Scripts/UI/SimBridge.cs
@@ -310,6 +310,11 @@ namespace Statecraft.Game.UI
[EconomySystem.RefusedBudgetSum] = "budget.refused.sum",
[EconomySystem.RefusedBudgetNegative] = "budget.refused.negative",
[Orders.RefusedNamesNoHex] = "unit.order_refused.names_no_hex",
+ // #2707, batch 3 (the owner's option (b)): a capture answer the end of turn refuses reads as the capture dialog's
+ // reviewed capture.refusal.* line. "Deport is not built yet" and the two "not awaiting" answers have no reviewed line
+ // that fits (capture.refusal.not_awaiting names the place, these do not), so they stay the sim's English.
+ [SettlementControl.RefusedNoOneToDeport] = "capture.refusal.no_one_to_deport",
+ [SettlementControl.RefusedUnknownOutcome] = "capture.refusal.unknown_outcome",
};
/// <summary>The sim's refusals that carry values (#2072: Combat.Check's Arms, Training.Reinforce's unit, settlement,
@@ -342,6 +347,13 @@ namespace Statecraft.Game.UI
(Movement.RefusedFull, "unit.move_refused.full"),
(AttentionSystem.RefusedAttention, "order.no_attention"),
(Projects.RefusedRepairCityHex, "city.project_reason.repair_city_hex"),
+ // #2707, batch 3 (option (b)): the capture and end-of-occupation answers that need a unit or a free hex, and an
+ // annexed place that is already a city, as the capture dialog's reviewed lines; {0} is the place.
+ (SettlementControl.RefusedOccupyNeedsUnit, "capture.refusal.needs_unit"),
+ (SettlementControl.RefusedAnnexNeedsUnit, "capture.refusal.needs_unit"),
+ (SettlementControl.RefusedWithdrawNeedsUnit, "capture.refusal.needs_unit"),
+ (SettlementControl.RefusedNoFreeHex, "capture.refusal.no_free_hex"),
+ (Cities.RefusedAlreadyCity, "capture.refusal.already_city"),
}.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"/>),
diff --git a/unity/Assets/Tests/EditMode/HebrewUiTests.cs b/unity/Assets/Tests/EditMode/HebrewUiTests.cs
index 9832ab941..999d24d34 100644
--- a/unity/Assets/Tests/EditMode/HebrewUiTests.cs
+++ b/unity/Assets/Tests/EditMode/HebrewUiTests.cs
@@ -219,12 +219,46 @@ public class HebrewUiTests
var slots = Regex.Matches(format, @"\{(\d+)").Cast<Match>().Select(m => int.Parse(m.Groups[1].Value) + 1).DefaultIfEmpty(0).Max();
var reason = string.Format(System.Globalization.CultureInfo.InvariantCulture, format,
Enumerable.Range(0, slots).Select(i => (object)(i + 2)).ToArray());
- Assert.AreEqual(reason, SimBridge.ReasonText(En, reason), name + ": the English string is the sim's own");
+ // The capture answers read as the capture dialog's reviewed line in English too (TheCaptureAnswersReadAsTheReviewedLines).
+ if (!CaptureAnswers.ContainsKey(format))
+ Assert.AreEqual(reason, SimBridge.ReasonText(En, reason), name + ": the English string is the sim's own");
if (!Regex.IsMatch(SimBridge.ReasonText(He, reason, c), "[א-ת]")) missing.Add(name + " \"" + reason + "\"");
}
Assert.IsEmpty(missing, "no Hebrew string for:\n" + string.Join("\n", missing));
}
+ // #2707 batch 3, the owner's option (b): a capture or end-of-occupation answer the end of turn refuses reuses the capture
+ // dialog's reviewed capture.refusal.* line in both languages (settlement-control-strings-review.yaml gains nothing), with
+ // the place's Hebrew name in its slot. The answers with no reviewed line that fits stay the sim's English.
+ static readonly Dictionary<string, string> CaptureAnswers = new Dictionary<string, string>
+ {
+ [Statecraft.Sim.SettlementControl.RefusedNoOneToDeport] = "capture.refusal.no_one_to_deport",
+ [Statecraft.Sim.SettlementControl.RefusedUnknownOutcome] = "capture.refusal.unknown_outcome",
+ [Statecraft.Sim.SettlementControl.RefusedOccupyNeedsUnit] = "capture.refusal.needs_unit",
+ [Statecraft.Sim.SettlementControl.RefusedAnnexNeedsUnit] = "capture.refusal.needs_unit",
+ [Statecraft.Sim.SettlementControl.RefusedWithdrawNeedsUnit] = "capture.refusal.needs_unit",
+ [Statecraft.Sim.SettlementControl.RefusedNoFreeHex] = "capture.refusal.no_free_hex",
+ [Statecraft.Sim.Cities.RefusedAlreadyCity] = "capture.refusal.already_city",
+ };
+
+ [Test]
+ public void TheCaptureAnswersReadAsTheReviewedLines()
+ {
+ 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");
+ foreach (var (format, key) in CaptureAnswers)
+ {
+ var reason = string.Format(System.Globalization.CultureInfo.InvariantCulture, format, place.Value);
+ Assert.AreEqual(En.Format(key, place.Value), SimBridge.ReasonText(En, reason, c, namesHe), reason);
+ Assert.AreEqual(He.Format(key, namesHe[place.Key]), SimBridge.ReasonText(He, reason, c, namesHe), reason);
+ StringAssert.DoesNotMatch("[A-Za-z]", SimBridge.ReasonText(He, reason, c, namesHe), reason);
+ }
+ foreach (var reason in new[] { "Deport is not built yet", "That place is not awaiting a decision on its capture",
+ "That place is not awaiting the end of its occupation" })
+ Assert.AreEqual(reason, SimBridge.ReasonText(He, reason, c, namesHe), "no reviewed line fits, so the sim's English");
+ }
+
[Test]
public void TheGameIsEnglishUnlessHebrewIsAskedFor()
{