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.

Unity: the end-of-occupation dialog, refused options explained (GDD Phase 6 PR 10, Refs #802) (#1572)

Eyal Goland768fc448c39
diff --git a/changelog.d/802.md b/changelog.d/802.md
new file mode 100644
index 000000000..cfa6ea74a
--- /dev/null
+++ b/changelog.d/802.md
@@ -0,0 +1,7 @@
+- The capture dialog also answers the end of an occupation: when a held place's occupation period is over, it names the
+ place and lists Annex then Withdraw from the sim's `EndOptions`, each with a plain description and the sim's resource
+ preview, and queues `EndOccupation` for End turn. Captures and ends of occupation come in one pass in settlement order
+ (owner, 24 October 2026). A refused option now stays in its place, disabled, with its reason in English or draft Hebrew
+ from a stable refusal id the sim gives (`CaptureRefusal`), so the dialog never shows the sim's English; Deport stays out
+ of the dialog while `mvp.deport_in_play` is off. The new strings wait for the owner's sensitivity review and a native
+ Hebrew review before any shareable build (refs #802).
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 72d226559..c65c5bf80 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -44,7 +44,7 @@ R-CTRL-005: Capture writes the settlement state only. It changes no resident fie
R-CTRL-007: `ResolveCapture(settlement, outcome)` answers a capture. It is one command kind for every outcome, with one `attention_cost.resolve_capture` (Q-TECH-3, owner, 18 October 2026, #783 batch 1), set at 0 as a design value proposed on #797 (D-A6: unit orders are free). It is valid only for a settlement whose record is awaiting the choice, including the turn of its instant capture until it is answered, and only for an outcome that is built. The answer remains deferred and runs at End turn (owner, 23 October 2026; R-TURN-004). Otherwise it is refused with a reason, the state unchanged and the Attention refunded: the place is not awaiting a decision, the outcome is not known, or Deport is not in play: with `mvp.deport_in_play` off, as in the real content until the owner has reviewed Deport's cards and dialog (Phase 6 PRs 9 and 10), it is refused as "not built yet" (R-CTRL-018). The legacy loop refuses it before charging Attention.
-R-CTRL-008: `SettlementControl.CaptureOptions(content, state, settlement)` lists the outcomes in one fixed order, Raid and withdraw, Occupy, Deport, so Deport is never first (impact plan section 4.1 item 1). An option carries no default or selected flag. Each option has either the reason it is refused or a preview: the change resolving it makes at once to Attention, Money (the Treasury and the debt), Food, Arms, Social cohesion, International Support and the score, computed by resolving it on a copy of the state, so the preview is the outcome (spec section 2.6). A place not awaiting the choice offers no option. A capture the player does not answer waits, and the units stay (Q-HIST-1 (a), owner, 18 October 2026, #783 batch 3). On the turn that reaches the game's end, where resolver step 10 sits and before objectives and score, every capture still awaiting the choice counts as Raid, in ordinal id order (owner, 18 October 2026 on #797, "Counts as Raid"): the units leave as R-CTRL-010 says, nothing changes for the residents and the score gains nothing. A unit with nowhere to go stays while the others leave, and the record goes all the same. No unanswered choice ever resolves as Deport. A fled place's end-of-game raid keeps its ownerless fled record (R-CTRL-004) (OWNER QUESTION 2 (b), owner, 24 October 2026, #799).
+R-CTRL-008: `SettlementControl.CaptureOptions(content, state, settlement)` lists the outcomes in one fixed order, Raid and withdraw, Occupy, Deport, so Deport is never first (impact plan section 4.1 item 1). An option carries no default or selected flag. Each option has either the reason it is refused or a preview. A refusal carries a stable id from a fixed list and the values its line needs beyond the place itself (for Attention, what the option needs and what is left), so the dialog shows a reviewed line in the player's language and never reads the English reason the command returns (Q-TECH-5, #802). A preview is the change resolving it makes at once to Attention, Money (the Treasury and the debt), Food, Arms, Social cohesion, International Support and the score, computed by resolving it on a copy of the state, so the preview is the outcome (spec section 2.6). A place not awaiting the choice offers no option. A capture the player does not answer waits, and the units stay (Q-HIST-1 (a), owner, 18 October 2026, #783 batch 3). On the turn that reaches the game's end, where resolver step 10 sits and before objectives and score, every capture still awaiting the choice counts as Raid, in ordinal id order (owner, 18 October 2026 on #797, "Counts as Raid"): the units leave as R-CTRL-010 says, nothing changes for the residents and the score gains nothing. A unit with nowhere to go stays while the others leave, and the record goes all the same. No unanswered choice ever resolves as Deport. A fled place's end-of-game raid keeps its ownerless fled record (R-CTRL-004) (OWNER QUESTION 2 (b), owner, 24 October 2026, #799).
R-CTRL-009: `HistoricalAI` answers every capture awaiting the choice with Raid, in ordinal id order, leaving out a Raid the sim would refuse (a unit with nowhere to go), which then waits, and the reference player sends `HistoricalAI`'s orders, so it does too (Q-REF-1 (a), owner, 18 October 2026, #783 batch 3). Neither ever issues Deport, and nothing delegates a capture: `EventSystem.Delegate` answers events only (impact plan section 4.1 item 1).
diff --git a/sim/Statecraft.Sim.Tests/CaptureOptionsTests.cs b/sim/Statecraft.Sim.Tests/CaptureOptionsTests.cs
index c05acbe12..b41fb33e4 100644
--- a/sim/Statecraft.Sim.Tests/CaptureOptionsTests.cs
+++ b/sim/Statecraft.Sim.Tests/CaptureOptionsTests.cs
@@ -28,7 +28,7 @@ public class CaptureOptionsTests
var options = SettlementControl.CaptureOptions(c, Awaiting(c, "town_a"), "town_a");
Assert.Equal(new[] { SettlementControl.Raid, SettlementControl.Occupy, SettlementControl.Deport }, options.Select(o => o.Outcome).ToArray());
Assert.NotEqual(SettlementControl.Deport, options[0].Outcome);
- Assert.Equal(new[] { "Outcome", "Preview", "Refusal" },
+ Assert.Equal(new[] { "Outcome", "Preview", "Refusal", "Refused" },
typeof(CaptureOption).GetProperties().Select(p => p.Name).OrderBy(x => x, StringComparer.Ordinal).ToArray());
}
diff --git a/sim/Statecraft.Sim.Tests/CaptureRefusalTests.cs b/sim/Statecraft.Sim.Tests/CaptureRefusalTests.cs
new file mode 100644
index 000000000..7866a238c
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/CaptureRefusalTests.cs
@@ -0,0 +1,113 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Statecraft.Sim;
+
+/// <summary>R-CTRL-008, R-CTRL-015 (#802): each refused option carries a stable refusal id and the values its line needs, so
+/// the dialog shows a reviewed line in the player's language without reading the sim's English (Q-TECH-5); the English
+/// reason stays for the log and the commands. The places are CaptureTests' fixture values, not history.</summary>
+public class CaptureRefusalTests
+{
+ static Unit Soldier(int id, int q, int r) => CaptureTests.Soldier(id, q, r);
+ static Unit Enemy(int id, int q, int r) => CaptureTests.Enemy(id, q, r);
+
+ static GameState With(Content c, string state, params Unit[] units)
+ {
+ var s = CombatTests.With(c, units);
+ s.Settlements["town_a"] = new SettlementControl(Movement.PlayerSide, state, s.Date);
+ return s;
+ }
+
+ static CaptureOption Option(IReadOnlyList<CaptureOption> options, string outcome) => options.Single(o => o.Outcome == outcome);
+
+ /// <summary>The refused option's id, its values, and the English reason, which is the option's Refusal.</summary>
+ static void Refused(CaptureOption o, string id, string english, params object[] args)
+ {
+ Assert.NotNull(o.Refused);
+ Assert.Equal(id, o.Refused!.Id);
+ Assert.Equal(args, o.Refused.Args);
+ Assert.Equal(english, o.Refused.Text);
+ Assert.Equal(o.Refused.Text, o.Refusal);
+ Assert.Null(o.Preview);
+ }
+
+ // R-CTRL-008: the ids are a fixed, distinct list, and a refusal with an id outside it cannot be made.
+ [Fact]
+ public void TheIdsAreAFixedList()
+ {
+ Assert.Equal(new[] { "attention", "needs_unit", "no_free_hex", "no_one_to_deport", "not_in_play", "already_city", "not_awaiting", "unknown_outcome" },
+ CaptureRefusal.Ids);
+ Assert.Throws<ArgumentException>(() => new CaptureRefusal("made_up", "English"));
+ // The list cannot be cast back to an array and changed (Codex pre-review of #1572, should-fix 1).
+ Assert.IsNotType<string[]>(CaptureRefusal.Ids);
+ Assert.Throws<NotSupportedException>(() => ((IList<string>)CaptureRefusal.Ids)[0] = "made_up");
+ Assert.Equal("attention", CaptureRefusal.Ids[0]);
+ }
+
+ // R-CTRL-007, R-CTRL-008: with mvp.deport_in_play off, Deport's refusal is not_in_play, which the dialog uses to leave it
+ // out until the owner's review (R-CTRL-007).
+ [Fact]
+ public void DeportOutOfPlayIsNotInPlay()
+ {
+ var c = CaptureTests.Load(CaptureTests.AllTargets);
+ var s = With(c, SettlementControl.AwaitingChoice, Soldier(1, 1, 0));
+ Refused(Option(SettlementControl.CaptureOptions(c, s, "town_a"), SettlementControl.Deport), CaptureRefusal.NotInPlay, "Deport is not built yet");
+ Assert.Null(Option(SettlementControl.CaptureOptions(c, s, "town_a"), SettlementControl.Raid).Refused);
+ }
+
+ // R-CTRL-011, R-CTRL-014: Occupy, Annex and Withdraw without an Israeli military unit on the place are needs_unit; the
+ // place is the option's own, so the id carries no value for it (the UI names it in its language).
+ [Fact]
+ public void NoGarrisonIsNeedsUnit()
+ {
+ var c = CaptureTests.Load(CaptureTests.AllTargets);
+ var capture = With(c, SettlementControl.AwaitingChoice, Soldier(1, 2, 0));
+ Refused(Option(SettlementControl.CaptureOptions(c, capture, "town_a"), SettlementControl.Occupy), CaptureRefusal.NeedsUnit, "Occupy needs an Israeli military unit on TOWN A");
+ var end = With(c, SettlementControl.AwaitingEnd, Soldier(1, 2, 0));
+ var options = SettlementControl.EndOptions(c, end, "town_a");
+ Refused(Option(options, SettlementControl.Annex), CaptureRefusal.NeedsUnit, "Annex needs an Israeli military unit on TOWN A");
+ Refused(Option(options, SettlementControl.WithdrawOutcome), CaptureRefusal.NeedsUnit, "Withdraw needs an Israeli military unit on TOWN A");
+ Assert.Equal(options[0].Refusal, SettlementControl.End(c, end, "town_a", SettlementControl.Annex, new List<Cause>()));
+ }
+
+ // R-CTRL-010: a unit with nowhere to withdraw to is no_free_hex (RaidTests.RaidWithNowhereToGoIsRefused's board).
+ [Fact]
+ public void NowhereToGoIsNoFreeHex()
+ {
+ var c = CaptureTests.Load(CaptureTests.AllTargets);
+ var s = With(c, SettlementControl.AwaitingChoice, Soldier(1, 1, 0), Soldier(6, 1, 0), Soldier(7, 2, 0), Enemy(3, 0, 0), Enemy(4, 0, 1), Enemy(5, 1, 1));
+ var raid = Option(SettlementControl.CaptureOptions(c, s, "town_a"), SettlementControl.Raid);
+ Refused(raid, CaptureRefusal.NoFreeHex, "A unit has no free hex next to TOWN A to withdraw to");
+ Assert.Equal(raid.Refusal, SettlementControl.Resolve(c, s, "town_a", SettlementControl.Raid, new List<Cause>()));
+ }
+
+ // R-CTRL-018 (OWNER QUESTION 4 (a) on #799): Deport of a fled town is no_one_to_deport.
+ [Fact]
+ public void AFledTownIsNoOneToDeport()
+ {
+ var c = DeportTests.Load(fled: new[] { "town_a" });
+ var s = With(c, SettlementControl.AwaitingChoice, Soldier(1, 1, 0));
+ s.Settlements["town_a"] = new SettlementControl(Movement.PlayerSide, SettlementControl.AwaitingChoice, s.Date, fled: true);
+ Refused(Option(SettlementControl.CaptureOptions(c, s, "town_a"), SettlementControl.Deport), CaptureRefusal.NoOneToDeport,
+ "Its residents fled when it was captured, so there is no one to deport");
+ }
+
+ // R-CTRL-007, R-CTRL-014: an option the Attention left cannot pay for is attention, with what it needs and what is left.
+ [Fact]
+ public void TooLittleAttentionIsAttentionWithItsNumbers()
+ {
+ var c = CaptureTests.Load(files => files["rules.yaml"] = files["rules.yaml"]
+ .Replace("resolve_capture: 0,", "resolve_capture: 2,").Replace("end_occupation: 0 }", "end_occupation: 2 }"), CaptureTests.AllTargets);
+ var capture = With(c, SettlementControl.AwaitingChoice, Soldier(1, 1, 0));
+ capture.Attention = 1;
+ var need = AttentionSystem.Cost(c, capture, SettlementControl.ResolveKind); // 2 at the fixture's rung, raised by its step
+ Assert.True(need > 1);
+ foreach (var o in SettlementControl.CaptureOptions(c, capture, "town_a"))
+ Refused(o, CaptureRefusal.Attention, FormattableString.Invariant($"Not enough attention (need {need:0.0}, have 1.0)"), need, 1.0);
+ var end = With(c, SettlementControl.AwaitingEnd, Soldier(1, 1, 0));
+ end.Attention = 0.5;
+ Assert.Equal(need, AttentionSystem.Cost(c, end, SettlementControl.EndKind));
+ foreach (var o in SettlementControl.EndOptions(c, end, "town_a"))
+ Refused(o, CaptureRefusal.Attention, FormattableString.Invariant($"Not enough attention (need {need:0.0}, have 0.5)"), need, 0.5);
+ }
+}
diff --git a/sim/Statecraft.Sim/SettlementControl.cs b/sim/Statecraft.Sim/SettlementControl.cs
index 94ca4f8bd..ab7edb046 100644
--- a/sim/Statecraft.Sim/SettlementControl.cs
+++ b/sim/Statecraft.Sim/SettlementControl.cs
@@ -82,12 +82,20 @@ namespace Statecraft.Sim
foreach (var outcome in Outcomes)
{
var after = s.Clone();
- var refusal = AttentionSystem.TrySpend(c, after, ResolveKind) ?? Resolve(c, after, id, outcome, new List<Cause>());
+ var refusal = Spend(c, after, ResolveKind) ?? Resolved(c, after, id, outcome, new List<Cause>());
options.Add(new CaptureOption(outcome, refusal, refusal == null ? Preview(s, after) : null));
}
return options;
}
+ /// <summary>The option's Attention, as Step charges it (AttentionSystem.TrySpend): null when paid, else the refusal with
+ /// what it needs and what is left.</summary>
+ static CaptureRefusal? Spend(Content c, GameState s, string kind)
+ {
+ var need = AttentionSystem.Cost(c, s, kind); var have = s.Attention;
+ return AttentionSystem.TrySpend(c, s, kind) is string no ? new CaptureRefusal(CaptureRefusal.Attention, no, need, have) : null;
+ }
+
static CapturePreview Preview(GameState s, GameState after) => new CapturePreview(after.Attention - s.Attention,
after.Treasury - s.Treasury, after.Debt - s.Debt, after.Food - s.Food, after.Arms - s.Arms,
Indicator(after, "morale") - Indicator(s, "morale"), Indicator(after, "intl_standing") - Indicator(s, "intl_standing"), after.Score - s.Score);
@@ -97,25 +105,31 @@ namespace Statecraft.Sim
/// <summary>R-CTRL-007: carries out ResolveCapture. Null when done, else the reason, with the state unchanged: the place
/// is not awaiting the choice, the outcome is not known, or Deport is not in play (mvp.deport_in_play, off in the real
/// content until PR 10 lifts it).</summary>
- internal static string? Resolve(Content c, GameState s, string id, string outcome, List<Cause> why)
+ internal static string? Resolve(Content c, GameState s, string id, string outcome, List<Cause> why) =>
+ Resolved(c, s, id, outcome, why)?.Text;
+
+ /// <summary><see cref="Resolve"/> with the refusal's id and values, for the options helper (R-CTRL-008).</summary>
+ static CaptureRefusal? Resolved(Content c, GameState s, string id, string outcome, List<Cause> why)
{
- if (NotAwaiting(s, id) is string no) return no;
+ if (NotAwaiting(s, id) is CaptureRefusal no) return no;
switch (outcome)
{
case Raid: return Withdraw(c, s, id, why, false);
case Occupy: return StartOccupation(c, s, id, why);
case Deport:
- if (!c.RulesAt(s.Date).Mvp!.DeportInPlay) return "Deport is not built yet";
+ 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 ? NoOneToDeport : Depopulate(c, s, id, why);
- default: return "That outcome is not known";
+ return s.Settlements[id].Fled ? new CaptureRefusal(CaptureRefusal.NoOneToDeport, NoOneToDeport) : 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";
+ static CaptureRefusal UnknownOutcome => new CaptureRefusal(CaptureRefusal.UnknownOutcome, "That outcome is not known");
+
/// <summary>The kind of <see cref="EndOccupation"/>, with one attention_cost key (R-CTRL-014).</summary>
public const string EndKind = "end_occupation";
/// <summary>The outcomes of EndOccupation (R-CTRL-015; Q-PUP-1 (c): no puppet regime).</summary>
@@ -137,7 +151,7 @@ namespace Statecraft.Sim
foreach (var outcome in EndOutcomes)
{
var after = s.Clone();
- var refusal = AttentionSystem.TrySpend(c, after, EndKind) ?? End(c, after, id, outcome, new List<Cause>());
+ var refusal = Spend(c, after, EndKind) ?? Ended(c, after, id, outcome, new List<Cause>());
options.Add(new CaptureOption(outcome, refusal, refusal == null ? Preview(s, after) : null));
}
return options;
@@ -146,34 +160,40 @@ namespace Statecraft.Sim
/// <summary>R-CTRL-014 to R-CTRL-017: carries out EndOccupation. Null when done, else the reason, with the state
/// unchanged: the place is not awaiting the end (a depopulated place never is, R-CTRL-017), the outcome is not known,
/// or no Israeli military unit is on the place, for either outcome. Withdraw is the Raid withdrawal (R-CTRL-010).</summary>
- internal static string? End(Content c, GameState s, string id, string outcome, List<Cause> why)
+ internal static string? End(Content c, GameState s, string id, string outcome, List<Cause> why) => Ended(c, s, id, outcome, why)?.Text;
+
+ /// <summary><see cref="End"/> with the refusal's id and values, for the options helper (R-CTRL-015).</summary>
+ static CaptureRefusal? Ended(Content c, GameState s, string id, string outcome, List<Cause> why)
{
- if (NotEnding(s, id) is string no) return no;
+ if (NotEnding(s, id) is CaptureRefusal no) return no;
switch (outcome)
{
case Annex: return AnnexPlace(c, s, id, why);
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 $"Withdraw needs an Israeli military unit on {c.SettlementNames[id]}";
+ 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 Withdraw(c, s, id, why, false);
- default: return "That outcome is not known";
+ default: return UnknownOutcome;
}
}
- static string? NotEnding(GameState s, string id) =>
- s.Settlements.TryGetValue(id, out var x) && x.State == AwaitingEnd ? null : "That place is not awaiting the end of its occupation";
+ static CaptureRefusal? NotEnding(GameState s, string id) =>
+ s.Settlements.TryGetValue(id, out var x) && x.State == AwaitingEnd ? null
+ : new CaptureRefusal(CaptureRefusal.NotAwaiting, "That place is not awaiting the end of its occupation");
/// <summary>R-CTRL-016 (Q-ANNEX-1; OWNER QUESTIONS 1 (a) and 3 (a) on #799): the record becomes owner=israel,
/// state=annexed, keeping its capture date and fled, with no timer. A fled place adds nothing else ("Territory only, no
/// gain"). A stayed place adds one city by the starting-city rule (<see cref="Cities.Annex"/>). Step 10 ignores an
/// annexed record, so its upkeep stops and no unit has to stay. Needs the garrison, as Occupy does (R-CTRL-011).</summary>
- static string? AnnexPlace(Content c, GameState s, string id, List<Cause> why)
+ static CaptureRefusal? AnnexPlace(Content c, GameState s, string id, List<Cause> why)
{
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 $"Annex needs an Israeli military unit on {name}";
+ if (!Garrisoned(s, t)) return new CaptureRefusal(CaptureRefusal.NeedsUnit, $"Annex needs an Israeli military unit on {name}");
var x = s.Settlements[id];
- if (!x.Fled && Cities.Annex(c, s, t) is string refused) return refused;
+ // 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);
s.Settlements[id] = new SettlementControl(Movement.PlayerSide, Annexed, x.Since, x.Depopulated, x.Combatants, x.Buildings, 0, x.Fled);
why.Add(new Cause("map", id, 0, x.Fled
? $"{name} is annexed. Its residents fled when it was captured, so no people, homes or jobs are added"
@@ -181,8 +201,9 @@ namespace Statecraft.Sim
return null;
}
- static string? NotAwaiting(GameState s, string id) =>
- s.Settlements.TryGetValue(id, out var x) && x.State == AwaitingChoice ? null : "That place is not awaiting a decision on its capture";
+ static CaptureRefusal? NotAwaiting(GameState s, string id) =>
+ s.Settlements.TryGetValue(id, out var x) && x.State == AwaitingChoice ? null
+ : new CaptureRefusal(CaptureRefusal.NotAwaiting, "That place is not awaiting a decision on its capture");
/// <summary>R-CTRL-010, Raid and withdraw (Q-RAID-1 (a)): the player's units on the place's hex, soldiers and halutzim
/// alike, leave in id order, each to the first neighbouring hex in the fixed <see cref="Movement.Neighbours"/> order
@@ -190,12 +211,12 @@ namespace Statecraft.Sim
/// costs no movement points (the default proposed on #797). The record goes (a fled one stays ownerless, <see cref="Release"/>),
/// so the place is under enemy control again at once, and its residents are unchanged (or fled at capture). Refused, the state untouched, when a unit has nowhere to go, unless
/// <paramref name="atTheEnd"/>: then that unit stays, the others leave and the record still goes.</summary>
- static string? Withdraw(Content c, GameState s, string id, List<Cause> why, bool atTheEnd)
+ static CaptureRefusal? Withdraw(Content c, GameState s, string id, List<Cause> why, bool atTheEnd)
{
var t = c.SettlementTargets.First(x => x.Id == id); // only a target gets a record (R-CTRL-004)
var name = c.SettlementNames[id];
var moved = new List<(Unit From, Unit To)>();
- if (MoveOut(c, s, t, name, atTheEnd, moved) is string no) return no;
+ if (MoveOut(c, s, t, name, atTheEnd, moved) is CaptureRefusal no) return no;
var residents = Residents(s.Settlements[id]);
Release(s, id);
Withdrew(id, name, moved, why);
@@ -224,7 +245,7 @@ namespace Statecraft.Sim
/// <summary>R-CTRL-010's move: the units leave <paramref name="t"/>'s hex as <see cref="Withdraw"/> says, into
/// <paramref name="moved"/>. Raid and Deport share it (R-CTRL-018). The reason, with every unit back where it was, when
/// one has nowhere to go, unless <paramref name="atTheEnd"/>.</summary>
- static string? MoveOut(Content c, GameState s, SettlementTarget t, string name, bool atTheEnd, List<(Unit From, Unit To)> moved)
+ static CaptureRefusal? MoveOut(Content c, GameState s, SettlementTarget t, string name, bool atTheEnd, List<(Unit From, Unit To)> moved)
{
foreach (var u in s.Units.Values.Where(u => u.Q == t.Q && u.R == t.R && !IsEnemy(u)).ToList()) // ascending id
{
@@ -234,7 +255,7 @@ namespace Statecraft.Sim
{
foreach (var x in moved) s.Units[x.From.Id] = x.From; // back as it was
moved.Clear();
- return $"A unit has no free hex next to {name} to withdraw to";
+ return new CaptureRefusal(CaptureRefusal.NoFreeHex, $"A unit has no free hex next to {name} to withdraw to");
}
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);
s.Units[u.Id] = w;
@@ -257,12 +278,12 @@ namespace Statecraft.Sim
/// (a), no razing in the MVP). The place counts once in DisplacedByPlayer, its residents nowhere else (Q-DEP-2 (a),
/// Q-DEP-3 (a)). Social cohesion and International Support fall at once by the labelled costs, through the permanent
/// shift. It draws nothing from the RNG.</summary>
- static string? Depopulate(Content c, GameState s, string id, List<Cause> why)
+ static CaptureRefusal? Depopulate(Content c, GameState s, string id, List<Cause> why)
{
var t = c.SettlementTargets.First(x => x.Id == id); // only a target gets a record (R-CTRL-004)
var name = c.SettlementNames[id];
var moved = new List<(Unit From, Unit To)>();
- if (MoveOut(c, s, t, name, false, moved) is string no) return no;
+ if (MoveOut(c, s, t, name, false, moved) is CaptureRefusal no) return no;
s.Settlements[id] = new SettlementControl(since: s.Settlements[id].Since, depopulated: true);
s.DisplacedByPlayer++;
Withdrew(id, name, moved, why);
@@ -286,11 +307,11 @@ namespace Statecraft.Sim
/// starts its timer at mvp.occupation_turns, the one X for every place. It needs an Israeli military unit on the hex,
/// the one unit that stays (a halutz holds nothing, #796), and is refused with the state unchanged otherwise. It moves
/// no unit, and it changes no resident field (R-CTRL-003): only the record's state and timer.</summary>
- static string? StartOccupation(Content c, GameState s, string id, List<Cause> why)
+ static CaptureRefusal? StartOccupation(Content c, GameState s, string id, List<Cause> why)
{
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 $"Occupy needs an Israeli military unit on {name}";
+ if (!Garrisoned(s, t)) return new CaptureRefusal(CaptureRefusal.NeedsUnit, $"Occupy needs an Israeli military unit on {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);
@@ -376,14 +397,55 @@ namespace Statecraft.Sim
}
}
- /// <summary>One outcome of a capture as SettlementControl.CaptureOptions offers it (R-CTRL-008): the reason it is refused,
- /// or null and its <see cref="Preview"/>. It has no default or selected flag on purpose.</summary>
+ /// <summary>One outcome of a capture as SettlementControl.CaptureOptions offers it (R-CTRL-008), or of an occupation's end
+ /// as EndOptions does (R-CTRL-015): why it is refused, or null and its <see cref="Preview"/>. It has no default or selected
+ /// flag on purpose.</summary>
public sealed class CaptureOption
{
public string Outcome { get; }
- public string? Refusal { get; }
+ /// <summary>Why the option is refused, with a stable id the UI shows in the player's language, or null.</summary>
+ public CaptureRefusal? Refused { get; }
+ /// <summary>The refusal's English reason (the command's), for the log and tests, or null.</summary>
+ public string? Refusal => Refused?.Text;
public CapturePreview? Preview { get; }
- public CaptureOption(string outcome, string? refusal, CapturePreview? preview) { Outcome = outcome; Refusal = refusal; Preview = preview; }
+ public CaptureOption(string outcome, CaptureRefusal? refused, CapturePreview? preview) { Outcome = outcome; Refused = refused; Preview = preview; }
+ }
+
+ /// <summary>Why a capture or end-of-occupation option is refused (R-CTRL-008, R-CTRL-015; #802): a stable <see cref="Id"/>
+ /// from <see cref="Ids"/> and the values its line needs beyond the place itself, which is the option's own and which the UI
+ /// names in its language. The UI shows a reviewed line for the id and never reads <see cref="Text"/>, the English reason
+ /// the command returns (Q-TECH-5).</summary>
+ public sealed class CaptureRefusal
+ {
+ /// <summary>Not enough Attention left. Args: what the option needs, what is left.</summary>
+ public const string Attention = "attention";
+ /// <summary>No Israeli military unit on the place (Occupy, Annex, Withdraw; R-CTRL-011, R-CTRL-014).</summary>
+ public const string NeedsUnit = "needs_unit";
+ /// <summary>A unit has no free hex to withdraw to (Raid, Deport, Withdraw; R-CTRL-010).</summary>
+ public const string NoFreeHex = "no_free_hex";
+ /// <summary>Deport of a place whose residents fled at capture (R-CTRL-018, OWNER QUESTION 4 (a) on #799).</summary>
+ public const string NoOneToDeport = "no_one_to_deport";
+ /// <summary>Deport while mvp.deport_in_play is off: "not built yet" (R-CTRL-007).</summary>
+ public const string NotInPlay = "not_in_play";
+ /// <summary>A stayed place whose id is already a city (Cities.Annex).</summary>
+ public const string AlreadyCity = "already_city";
+ /// <summary>The place is not awaiting this decision. The helpers list no option then.</summary>
+ public const string NotAwaiting = "not_awaiting";
+ /// <summary>The outcome is not one the command knows. The helpers list only known ones.</summary>
+ public const string UnknownOutcome = "unknown_outcome";
+
+ /// <summary>Every id, in a fixed order. Read-only: it cannot be cast back to an array and changed.</summary>
+ public static IReadOnlyList<string> Ids { get; } = Array.AsReadOnly(new[] { Attention, NeedsUnit, NoFreeHex, NoOneToDeport, NotInPlay, AlreadyCity, NotAwaiting, UnknownOutcome });
+
+ public string Id { get; }
+ public IReadOnlyList<object> Args { get; }
+ public string Text { get; }
+
+ public CaptureRefusal(string id, string text, params object[] args)
+ {
+ if (!Ids.Contains(id)) throw new ArgumentException("Unknown refusal id '" + id + "'", nameof(id));
+ Id = id; Text = text; Args = args;
+ }
}
/// <summary>What resolving a capture option changes at once, as deltas: Attention, Money (the Treasury and the debt), Food,
diff --git a/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs b/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs
index 6a7e840b4..ef55b803e 100644
--- a/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs
+++ b/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs
@@ -7,17 +7,21 @@ using UnityEngine.UIElements;
namespace Statecraft.Game.UI
{
- /// <summary>The capture dialog (GDD Phase 6 PR 10, #802; docs/gdd/settlement-control.md): when a settlement's record
- /// awaits the player's choice (SettlementControl.AwaitingChoice), the first such place in the sim's ordinal order, with
- /// its name in the UI's language and one button per option that SettlementControl.CaptureOptions offers, in the
- /// helper's order: the option's name (the GDD's words, Q-UI-1 (b)), its plain description, and the helper's preview of
- /// what it changes at once (Q-UI-2 (a)). The target row's operation line is not shown (owner, 22 October 2026, #1317).
- /// An option the helper refuses (today Occupy, #798, and Deport, #800, "not built yet") is not shown, so a newly built
- /// one appears by itself. The dialog holds no order, cost or rule of its own (Q-TECH-5): it formats the sim's numbers
- /// as the top bar does, and nothing more.
+ /// <summary>The capture and end-of-occupation dialog (GDD Phase 6 PR 10, #802; docs/gdd/settlement-control.md): when a
+ /// settlement's record awaits the player's choice (SettlementControl.AwaitingChoice) or the end of its occupation
+ /// (AwaitingEnd, R-CTRL-014), the first such place in one ordinal pass over the places, whichever decision it has (owner,
+ /// 24 October 2026 on #802, "By settlement order"), with its name in the UI's language and one button per option that
+ /// SettlementControl.CaptureOptions or EndOptions lists, in the helper's order: the option's name (the GDD's words,
+ /// Q-UI-1 (b)), its plain description, and the helper's preview of what it changes at once (Q-UI-2 (a)). The target
+ /// row's operation line is not shown (owner, 22 October 2026, #1317). An option the helper refuses stays in its place,
+ /// disabled, with the reason for its refusal id in the UI's language (owner, 24 October 2026 on #799, "button explains";
+ /// never the sim's English), except one refused as out of play (Deport while mvp.deport_in_play is off, R-CTRL-007),
+ /// which is not shown until the owner's review. The dialog holds no order, cost or rule of its own (Q-TECH-5): it
+ /// formats the sim's numbers as the top bar does, and nothing more.
/// <para>It sits in the decision card's place and style (Game.uxml "capture-card"), modal like it (OpenClass; ScreenNav.
/// DisableCovered), and waits while a decision card is open: one window at a time. A choice is an order
- /// (ResolveCapture, through SimBridge.Queue): it takes effect at End Turn, and the dialog goes on to the next capture.
+ /// (ResolveCapture or EndOccupation, through SimBridge.Queue): it takes effect at End Turn, and the dialog goes on to the
+ /// next place.
/// Opening puts the focus on the dialog itself, so no option is lit as if recommended; Tab reaches the options in order,
/// then Hide. Hide, or Escape, collapses it to "Decision waiting: place" without choosing; an unanswered capture waits,
/// its units staying (R-CTRL-008). No picture, no sound, no video (impact plan section 4.1 item 6).</para></summary>
@@ -33,7 +37,7 @@ namespace Statecraft.Game.UI
readonly Button hide, reopen; readonly Button? endTurn;
readonly SimBridge bridge; readonly UiText text; readonly EventCardPresenter? eventCard;
readonly IReadOnlyDictionary<string, string>? namesHe;
- readonly Func<Content, GameState, string, IReadOnlyList<CaptureOption>> optionsFor;
+ readonly Func<Content, GameState, string, IReadOnlyList<CaptureOption>> optionsFor, endOptionsFor;
readonly Action onHide, onReopen, onUncovered, onRender;
readonly EventCallback<PointerDownEvent> onHidePointer;
readonly EventCallback<NavigationSubmitEvent> onHideSubmit;
@@ -52,13 +56,16 @@ namespace Statecraft.Game.UI
/// it (EventCardPresenter.Rendered). Null: no card (the dialog then follows SimBridge.Changed itself).</param>
/// <param name="namesHe">Each settlement's Hebrew name, by id (the map's parse of settlements_1948.yaml, as the info
/// panel gets it; ContentNames.Settlement).</param>
- /// <param name="helper">Test seam: the options helper; null is SettlementControl.CaptureOptions.</param>
+ /// <param name="helper">Test seam: the capture options helper; null is SettlementControl.CaptureOptions.</param>
+ /// <param name="endHelper">Test seam: the end-of-occupation options helper; null is SettlementControl.EndOptions.</param>
public CaptureDialogPresenter(VisualElement root, SimBridge bridge, UiText text, EventCardPresenter? eventCard,
IReadOnlyDictionary<string, string>? namesHe = null,
- Func<Content, GameState, string, IReadOnlyList<CaptureOption>>? helper = null)
+ Func<Content, GameState, string, IReadOnlyList<CaptureOption>>? helper = null,
+ Func<Content, GameState, string, IReadOnlyList<CaptureOption>>? endHelper = null)
{
this.bridge = bridge; this.text = text; this.eventCard = eventCard; this.namesHe = namesHe;
optionsFor = helper ?? SettlementControl.CaptureOptions;
+ endOptionsFor = endHelper ?? SettlementControl.EndOptions;
card = root.Q<VisualElement>("capture-card"); layer = card.parent; hudRoot = root.Q("root") ?? root;
endTurn = hudRoot.Q<Button>("end-turn");
title = card.Q<Label>("capture-title");
@@ -66,7 +73,6 @@ namespace Statecraft.Game.UI
options = card.Q<VisualElement>("capture-options");
hide = card.Q<Button>("capture-hide"); reopen = layer.Q<Button>("capture-reopen");
hide.text = text["event.hide"];
- none.text = text["capture.none"];
onHide = Collapse; onReopen = Reopen; onRender = Render;
onUncovered = () => { focusedFor = null; if (Showing) FocusCard(Shown!, force: true); };
onHidePointer = _ => hideByPointer = true;
@@ -83,15 +89,18 @@ namespace Statecraft.Game.UI
Render();
}
- /// <summary>The place awaiting the choice that the dialog is for (open or hidden), or null when every capture awaiting
- /// the choice has a queued answer, or there is none.</summary>
+ /// <summary>The place awaiting a decision that the dialog is for (open or hidden), or null when every place awaiting
+ /// one has a queued answer, or there is none.</summary>
public string? Shown { get; private set; }
+ /// <summary>True when <see cref="Shown"/> awaits the end of its occupation (EndOptions, EndOccupation), not a capture.</summary>
+ public bool Ending { get; private set; }
+
/// <summary>True while the dialog is hidden behind "Decision waiting: place" (Hide, Escape).</summary>
public bool Collapsed => Shown != null && collapsedFor == Shown;
- /// <summary>The options the dialog shows: the helper's, those it does not refuse, in its order.</summary>
- public IReadOnlyList<CaptureOption> Offered { get; private set; } = Array.Empty<CaptureOption>();
+ /// <summary>The options the dialog shows, offered or refused: the helper's, in its order, less one out of play.</summary>
+ public IReadOnlyList<CaptureOption> Listed { get; private set; } = Array.Empty<CaptureOption>();
/// <summary>The decision card is open: the dialog waits behind it.</summary>
bool CardOpen => eventCard?.Shown != null && !eventCard.Collapsed;
@@ -102,10 +111,11 @@ namespace Statecraft.Game.UI
{
var c = bridge.Content; var s = bridge.State;
if (bridge.Session != session) { session = bridge.Session; collapsedFor = null; focusedFor = null; }
- // The sim's order (Settlements is ordinal); a place with a queued answer has had its choice.
- var waiting = s.Settlements.Where(kv => kv.Value.State == SettlementControl.AwaitingChoice
- && bridge.QueuedLike(new ResolveCapture(kv.Key, "")) == null).Select(kv => kv.Key).ToList();
+ // One pass in the sim's order (Settlements is ordinal), captures and ends of occupation alike (owner, 24 October
+ // 2026 on #802, "By settlement order"); a place with a queued answer has had its choice.
+ var waiting = s.Settlements.Where(kv => Waits(kv.Key, kv.Value.State)).Select(kv => kv.Key).ToList();
Shown = waiting.FirstOrDefault();
+ Ending = Shown != null && s.Settlements[Shown].State == SettlementControl.AwaitingEnd;
if (Shown == null) collapsedFor = null;
var shown = Shown != null && !Collapsed && !CardOpen;
if (!shown) focusedFor = null; // hidden (behind the card, or by Hide): shown again, it takes the focus again
@@ -116,39 +126,66 @@ namespace Statecraft.Game.UI
hudRoot.EnableInClassList(OpenClass, shown);
ScreenNav.DisableCovered(hudRoot);
options.Clear();
- if (Shown == null) { Offered = Array.Empty<CaptureOption>(); return; }
- var id = Shown;
+ if (Shown == null) { Listed = Array.Empty<CaptureOption>(); return; }
+ var id = Shown; var ending = Ending;
+ var stem = ending ? EndStem : CaptureStem;
var name = ContentNames.Settlement(text, c, id, namesHe);
title.text = name;
- intro.text = text.Format("capture.intro", name);
+ intro.text = text.Format(stem + ".intro", name);
+ none.text = text[stem + ".none"];
reopen.text = text.Format("capture.reopen", name);
- Offered = optionsFor(c, s, id).Where(o => o.Refusal == null && o.Preview != null).ToList();
- foreach (var o in Offered)
+ Listed = (ending ? endOptionsFor : optionsFor)(c, s, id).Where(o => o.Refused?.Id != CaptureRefusal.NotInPlay).ToList();
+ foreach (var o in Listed)
{
var outcome = o.Outcome;
- var b = new Button(() => Choose(id, outcome)) { name = "capture-option-" + outcome, text = text["capture.option." + outcome] };
+ var b = new Button(() => Choose(id, outcome, ending)) { name = "capture-option-" + outcome, text = text[stem + ".option." + outcome] };
b.AddToClassList(EventCardPresenter.OptionClass); b.AddToClassList(OptionClass);
+ b.SetEnabled(o.Refused == null); // disabled: no Tab stop, no click, no submit
options.Add(b);
// Under the option, not in it: the button's label stays the choice itself, and a Label takes no Tab stop.
- var about = new Label(text["capture.about." + outcome]) { name = "capture-about-" + outcome };
+ var about = new Label(text[stem + ".about." + About(s, id, outcome, ending)]) { name = "capture-about-" + outcome };
about.AddToClassList("capture-about");
options.Add(about);
- var preview = new Label(PreviewText(c, s, o.Preview!, text)) { name = "capture-preview-" + outcome };
- preview.AddToClassList("muted"); preview.AddToClassList("capture-preview");
- options.Add(preview);
+ // Refused: why, in the UI's language, and no preview (the sim gives none). Else the sim's preview.
+ var line = o.Refused != null ? new Label(RefusalText(o.Refused, name, text)) { name = "capture-refusal-" + outcome }
+ : o.Preview != null ? new Label(PreviewText(c, s, o.Preview, text, ending)) { name = "capture-preview-" + outcome } : null;
+ if (line == null) continue;
+ line.AddToClassList("muted"); line.AddToClassList(o.Refused != null ? "capture-refusal" : "capture-preview");
+ options.Add(line);
}
- none.style.display = Offered.Count == 0 ? DisplayStyle.Flex : DisplayStyle.None;
+ none.style.display = Listed.All(o => o.Refused != null) ? DisplayStyle.Flex : DisplayStyle.None;
count.text = waiting.Count > 1 ? text.Format("event.more", waiting.Count - 1) : "";
if (shown && focusedFor != id) FocusCard(id, force: false);
}
+ const string CaptureStem = "capture", EndStem = "capture.end";
+
+ /// <summary>Whether <paramref name="id"/>, in <paramref name="state"/>, awaits a decision with no answer queued yet.</summary>
+ bool Waits(string id, string state) =>
+ state == SettlementControl.AwaitingChoice ? bridge.QueuedLike(new ResolveCapture(id, "")) == null
+ : state == SettlementControl.AwaitingEnd && bridge.QueuedLike(new EndOccupation(id, "")) == null;
+
+ /// <summary>The description's key under the stem: the outcome's own, except Annex, which says what the place adds,
+ /// nothing when its residents fled at capture (R-CTRL-016, "territory only, no gain") and its residents, homes and
+ /// jobs when they stayed. No number: those are the sim's (Q-UI-2 (a)).</summary>
+ static string About(GameState s, string id, string outcome, bool ending) =>
+ ending && outcome == SettlementControl.Annex ? (s.Settlements[id].Fled ? "annex_fled" : "annex_stayed") : outcome;
+
+ /// <summary>A refusal's line in the UI's language: capture.refusal.&lt;id&gt; with {0} the place's name and the sim's
+ /// values after it. Never the sim's English (Q-TECH-5).</summary>
+ public static string RefusalText(CaptureRefusal r, string place, UiText t) =>
+ t.Format("capture.refusal." + r.Id, new object[] { place }.Concat(r.Args).ToArray());
+
/// <summary>The preview's lines (Q-UI-2 (a)): a heading, then each quantity the option changes at once, in
/// CapturePreview's order, in the turn report's form (report.line: the caption, then the change as the top bar shows
/// it): Attention; Money, the net change of the Treasury less the debt, as the bar's "Money (net)"; Food; Arms; Social
/// cohesion and International support as the difference of the two shown 0-100 values; the score. A change the bar
- /// would show as nothing is left out, as there; with none left, capture.changes_none. Every number is the helper's.</summary>
- public static string PreviewText(Content c, GameState s, CapturePreview p, UiText t)
+ /// would show as nothing is left out, as there; with none left, capture.changes_none. Every number is the helper's.
+ /// <paramref name="ending"/>: the end dialog's heading, which names them as resources, since Annex's people, homes
+ /// and jobs are in its description, not here.</summary>
+ public static string PreviewText(Content c, GameState s, CapturePreview p, UiText t, bool ending = false)
{
+ var stem = ending ? EndStem : CaptureStem;
var lines = new List<string>();
void Line(string caption, string change) => lines.Add(t.Format("report.line", t[caption], change));
if (p.Attention != 0) Line("capture.caption.attention", t.Format("capture.delta_attention", p.Attention));
@@ -164,7 +201,7 @@ namespace Statecraft.Game.UI
Points("hud.caption.cohesion", "morale", p.SocialCohesion);
Points("hud.caption.standing", "intl_standing", p.InternationalSupport);
if (p.Score != 0) Line("capture.caption.score", t.Format("capture.delta_count", p.Score));
- return lines.Count == 0 ? t["capture.changes_none"] : t["capture.changes"] + "\n" + string.Join("\n", lines);
+ return lines.Count == 0 ? t[stem + ".changes_none"] : t[stem + ".changes"] + "\n" + string.Join("\n", lines);
}
/// <summary>Hide: the dialog gives the map back and waits behind "Decision waiting: place", which takes the focus when
@@ -214,11 +251,11 @@ namespace Statecraft.Game.UI
});
}
- void Choose(string id, string outcome)
+ void Choose(string id, string outcome, bool ending)
{
- // The bridge raises Refused (the toast shows it) or Changed (the dialog goes on to the next capture, which takes
- // the focus). Answered from the keyboard with no capture left, the focus goes to End turn (#41 M1).
- bridge.Queue(new ResolveCapture(id, outcome));
+ // The bridge raises Refused (the toast shows it) or Changed (the dialog goes on to the next place, which takes
+ // the focus). Answered from the keyboard with no place left, the focus goes to End turn (#41 M1).
+ bridge.Queue(ending ? new EndOccupation(id, outcome) : (Command)new ResolveCapture(id, outcome));
if (Shown == null && presses.ByKeyboard) FocusReturn.To(endTurn);
}
diff --git a/unity/Assets/Tests/EditMode/CaptureDialogTests.cs b/unity/Assets/Tests/EditMode/CaptureDialogTests.cs
index 669f74525..45426251a 100644
--- a/unity/Assets/Tests/EditMode/CaptureDialogTests.cs
+++ b/unity/Assets/Tests/EditMode/CaptureDialogTests.cs
@@ -12,10 +12,12 @@ using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.UIElements;
-/// <summary>The capture dialog (GDD Phase 6 PR 10, #802; plan 2026-10-15-gdd-phase-6.md, PR 10): when a settlement's record
-/// awaits the player's choice, the dialog names the place and lists exactly the options SettlementControl.CaptureOptions
-/// offers, in its order, each with the sim's preview; nothing is pre-selected; a choice queues ResolveCapture through
-/// SimBridge; Escape hides it without choosing; it plays no sound and shows no video; a decision card goes first. The
+/// <summary>The capture and end-of-occupation dialog (GDD Phase 6 PR 10, #802; plan 2026-10-15-gdd-phase-6.md, PR 10): when a
+/// settlement's record awaits the player's choice, or the end of its occupation, the dialog names the place and lists exactly
+/// the options SettlementControl.CaptureOptions or EndOptions lists, in its order, each with the sim's preview or, refused,
+/// disabled with its reason in the UI's language; nothing is pre-selected; a choice queues ResolveCapture or EndOccupation
+/// through SimBridge; the places go in one ordinal pass (owner, 24 October 2026, "By settlement order"); Escape hides it
+/// without choosing; it plays no sound and shows no video; a decision card goes first. The
/// target rows here are test fixtures on the real content (Lydda and Ramle, which share a hex), with a made-up operation
/// line (the content requires one; the dialog does not show it): the real target list ships empty until its research and
/// review are done.</summary>
@@ -24,8 +26,9 @@ public class CaptureDialogTests
const string Operation = "Fixture operation (a test value, not a source)";
/// <summary>The real content with Lydda and Ramle as targets; <paramref name="price"/> sets attention_cost.resolve_capture
- /// (0 in the content), so the sim's Attention preview has a number to show.</summary>
- static Content Targets(double price = 0)
+ /// and <paramref name="endPrice"/> attention_cost.end_occupation (0 in the content), so the sim's Attention preview has a
+ /// number to show.</summary>
+ static Content Targets(double price = 0, double endPrice = 0)
{
var dir = Paths.Content;
var events = Directory.GetFiles(Path.Combine(dir, "events"), "*.yaml").Select(f => "events/" + Path.GetFileName(f)).ToList();
@@ -41,6 +44,11 @@ public class CaptureDialogTests
Assert.IsTrue(text.Contains(" resolve_capture: 0 "), "rules.yaml prices resolve_capture at 0");
text = text.Replace(" resolve_capture: 0 ", " resolve_capture: " + price.ToString(System.Globalization.CultureInfo.InvariantCulture) + " ");
}
+ if (rel == "rules.yaml" && endPrice != 0)
+ {
+ Assert.IsTrue(text.Contains(" end_occupation: 0 "), "rules.yaml prices end_occupation at 0");
+ text = text.Replace(" end_occupation: 0 ", " end_occupation: " + endPrice.ToString(System.Globalization.CultureInfo.InvariantCulture) + " ");
+ }
return text;
}, events);
}
@@ -58,6 +66,17 @@ public class CaptureDialogTests
return g;
}
+ /// <summary>A new game with no event pending and each of <paramref name="places"/> awaiting the end of its occupation
+ /// (R-CTRL-012), <paramref name="fled"/> its record's flag; with <paramref name="garrison"/>, an Israeli soldier on Lydda
+ /// and Ramle's hex, the unit Annex and Withdraw need (R-CTRL-014).</summary>
+ static GameSession Ending(Content c, bool garrison, bool fled, params string[] places)
+ {
+ var g = Awaiting(c);
+ foreach (var id in places) g.State.Settlements[id] = new SettlementControl(Movement.PlayerSide, SettlementControl.AwaitingEnd, g.State.Date, fled: fled);
+ if (garrison) { var u = g.State.NextId++; g.State.Units.Add(u, new Unit(u, "veteran_soldier", -3, 21, side: Movement.PlayerSide, strength: 3)); }
+ return g;
+ }
+
/// <summary>The settlements' Hebrew names as GameRoot hands them over (the map's parse of settlements_1948.yaml).</summary>
static IReadOnlyDictionary<string, string> NamesHe() =>
Statecraft.Game.Map.SettlementPlacer.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", "settlements_1948.yaml"))).ToDictionary(s => s.Id, s => s.NameHe);
@@ -69,7 +88,8 @@ public class CaptureDialogTests
readonly GameObject go; readonly PanelSettings ps; readonly RenderTexture rt; readonly List<System.IDisposable> owned = new List<System.IDisposable>();
public Rig(GameSession g, UiText? text = null, int w = 1920, int h = 1080,
- System.Func<Content, GameState, string, IReadOnlyList<CaptureOption>>? options = null)
+ System.Func<Content, GameState, string, IReadOnlyList<CaptureOption>>? options = null,
+ System.Func<Content, GameState, string, IReadOnlyList<CaptureOption>>? endOptions = null)
{
Text = text ?? En;
rt = new RenderTexture(w, h, 0);
@@ -89,7 +109,7 @@ public class CaptureDialogTests
Nav = new ScreenNav(Root); owned.Add(Nav);
owned.Add(new InfoPanelPresenter(Root, Bridge, Text, g.Content.SettlementHexes.ToDictionary(x => x.Id, x => x.Id)));
Card = new EventCardPresenter(Root, Bridge, Text, null); owned.Add(Card); // as GameRoot: the card first
- Dialog = new CaptureDialogPresenter(Root, Bridge, Text, Card, NamesHe(), helper: options); owned.Add(Dialog);
+ Dialog = new CaptureDialogPresenter(Root, Bridge, Text, Card, NamesHe(), helper: options, endHelper: endOptions); owned.Add(Dialog);
}
public void Dispose()
@@ -124,13 +144,19 @@ public class CaptureDialogTests
using (var e = NavigationMoveEvent.GetPooled(NavigationMoveEvent.Direction.Next)) { e.target = from; from.SendEvent(e); }
}
- /// <summary>A stand-in for the options helper that offers every outcome with a preview, in <paramref name="order"/>, and
- /// refuses <paramref name="refused"/>: the dialog must render whatever the helper returns (Occupy, #798, and Deport, #800,
- /// are refused by the real helper today).</summary>
+ /// <summary>A stand-in for an options helper that offers every outcome with a preview, in <paramref name="order"/>, and
+ /// refuses <paramref name="refused"/> as needs_unit: the dialog must render whatever the helper returns.</summary>
static System.Func<Content, GameState, string, IReadOnlyList<CaptureOption>> Helper(string[] order, params string[] refused) =>
- (c, s, id) => order.Select(o => refused.Contains(o) ? new CaptureOption(o, "refused in this test", null)
+ Refusing(order, CaptureRefusal.NeedsUnit, refused);
+
+ /// <summary>As <see cref="Helper"/>, refusing <paramref name="refused"/> with the refusal <paramref name="id"/> and
+ /// <paramref name="args"/>.</summary>
+ static System.Func<Content, GameState, string, IReadOnlyList<CaptureOption>> Refusing(string[] order, string id, string[] refused, params object[] args) =>
+ (c, s, place) => order.Select(o => refused.Contains(o) ? new CaptureOption(o, new CaptureRefusal(id, "refused in this test", args), null)
: new CaptureOption(o, null, Full)).ToList();
+ static readonly string[] EndOrder = { SettlementControl.Annex, SettlementControl.WithdrawOutcome };
+
/// <summary>A preview that changes every quantity (seven lines): the most a preview can show.</summary>
static readonly CapturePreview Full = new CapturePreview(-1, -2, 0.5, -3, -4, -0.05, -0.1, -5);
@@ -199,27 +225,34 @@ public class CaptureDialogTests
// ---- The options: exactly the helper's, in its order ----
- /// <summary>Plan PR 10, CaptureDialogTests.TheOrderIsTheSims: the buttons are the options the real helper offers, in its
- /// order (today Raid alone: Occupy and Deport are refused as not built), named in the GDD's words.</summary>
+ /// <summary>Plan PR 10, CaptureDialogTests.TheOrderIsTheSims: the buttons are the options the real helper lists, in its
+ /// order, named in the GDD's words, those it refuses disabled; Deport, out of play (mvp.deport_in_play off, R-CTRL-007),
+ /// is left out until the owner's review. With no unit on Lydda, Occupy is refused (R-CTRL-011).</summary>
[UnityTest]
public IEnumerator TheOrderIsTheSims()
{
using var r = new Rig(Awaiting(C, "lod"));
yield return Frames(4);
- var offered = SettlementControl.CaptureOptions(r.Bridge.Content, r.Bridge.State, "lod").Where(o => o.Refusal == null).Select(o => o.Outcome).ToList();
- Assert.IsNotEmpty(offered, "precondition: the sim offers an option here");
- CollectionAssert.AreEqual(offered, r.Dialog.Offered.Select(o => o.Outcome).ToList(), "the dialog's options are the helper's offered ones");
- CollectionAssert.AreEqual(offered.Select(o => "capture-option-" + o).ToList(), r.Options.Select(b => b.name).ToList(), "one button each, in the helper's order");
- CollectionAssert.AreEqual(offered.Select(o => En["capture.option." + o]).ToList(), r.Options.Select(b => b.text).ToList());
- foreach (var o in offered)
+ var helper = SettlementControl.CaptureOptions(r.Bridge.Content, r.Bridge.State, "lod");
+ Assert.AreEqual(CaptureRefusal.NotInPlay, helper.Single(o => o.Outcome == SettlementControl.Deport).Refused?.Id, "precondition: Deport is out of play");
+ var listed = helper.Where(o => o.Refused?.Id != CaptureRefusal.NotInPlay).Select(o => o.Outcome).ToList();
+ CollectionAssert.AreEqual(new[] { SettlementControl.Raid, SettlementControl.Occupy }, listed, "precondition: Raid and Occupy");
+ CollectionAssert.AreEqual(listed, r.Dialog.Listed.Select(o => o.Outcome).ToList(), "the dialog's options are the helper's, less the one out of play");
+ CollectionAssert.AreEqual(listed.Select(o => "capture-option-" + o).ToList(), r.Options.Select(b => b.name).ToList(), "one button each, in the helper's order");
+ CollectionAssert.AreEqual(listed.Select(o => En["capture.option." + o]).ToList(), r.Options.Select(b => b.text).ToList());
+ foreach (var o in listed)
Assert.AreEqual(En["capture.about." + o], r.Root.Q<Label>("capture-about-" + o).text, $"{o}: its plain description");
+ CollectionAssert.AreEqual(helper.Where(o => listed.Contains(o.Outcome)).Select(o => o.Refused == null).ToList(), r.Options.Select(b => b.enabledSelf).ToList(),
+ "an option the helper refuses is disabled");
+ Assert.IsNull(r.Root.Q("capture-option-deport"), "Deport out of play is not shown");
Assert.IsFalse(r.Shows("capture-none"));
}
- /// <summary>The dialog renders whatever the helper returns: every offered outcome, in the helper's order whatever it is,
- /// and none it refuses. So Occupy and Deport appear by themselves once the sim builds them, and never before.</summary>
+ /// <summary>The dialog renders whatever the helper returns, in the helper's order whatever it is: an offered outcome as a
+ /// button with its preview, a refused one as a disabled button with its reason in the UI's language and no preview
+ /// (owner, 24 October 2026 on #799, "button explains"), never one refused as out of play.</summary>
[UnityTest]
- public IEnumerator ItShowsWhateverTheHelperOffersInItsOrder()
+ public IEnumerator ItShowsWhateverTheHelperListsInItsOrder()
{
foreach (var (order, refused) in new[]
{
@@ -231,20 +264,62 @@ public class CaptureDialogTests
{
using var r = new Rig(Awaiting(C, "lod"), options: Helper(order, refused));
yield return Frames(3);
- var want = order.Where(o => !refused.Contains(o)).ToList();
var where = $"[{string.Join(",", order)}] refusing [{string.Join(",", refused)}]";
- CollectionAssert.AreEqual(want.Select(o => "capture-option-" + o).ToList(), r.Options.Select(b => b.name).ToList(), where);
- foreach (var o in refused) Assert.IsNull(r.Root.Q("capture-option-" + o), $"{where}: a refused option is not shown");
+ CollectionAssert.AreEqual(order.Select(o => "capture-option-" + o).ToList(), r.Options.Select(b => b.name).ToList(), where);
+ foreach (var o in order)
+ {
+ var b = r.Root.Q<Button>("capture-option-" + o);
+ Assert.AreEqual(!refused.Contains(o), b.enabledSelf, $"{where}: {o} is enabled only when offered");
+ Assert.AreEqual(refused.Contains(o), r.Root.Q("capture-refusal-" + o) != null, $"{where}: {o} explains a refusal");
+ Assert.AreEqual(!refused.Contains(o), r.Root.Q("capture-preview-" + o) != null, $"{where}: {o} has the sim's preview only when offered");
+ if (refused.Contains(o)) Assert.AreEqual(En.Format("capture.refusal.needs_unit", "Lydda"), r.Root.Q<Label>("capture-refusal-" + o).text);
+ }
+ foreach (var o in refused) Press(r.Root.Q<Button>("capture-option-" + o));
+ yield return Frames(2);
+ Assert.IsEmpty(r.Bridge.Queued, $"{where}: a refused option cannot be chosen");
+ }
+ using (var r = new Rig(Awaiting(C, "lod"), options: Refusing(new[] { "raid", "occupy", "deport" }, CaptureRefusal.NotInPlay, new[] { "deport" })))
+ {
+ yield return Frames(3);
+ CollectionAssert.AreEqual(new[] { "capture-option-raid", "capture-option-occupy" }, r.Options.Select(b => b.name).ToList(), "an option out of play is not shown");
+ }
+ }
+
+ /// <summary>R-CTRL-018 (owner, 24 October 2026 on #799, "Hide it, button explains"): for a town whose residents fled at
+ /// capture, Deport stays third, disabled, and says why in the UI's language; the other refusals likewise, with the
+ /// sim's values (Attention: what it needs, what is left).</summary>
+ [UnityTest]
+ public IEnumerator ARefusedOptionSaysWhyInTheUisLanguage()
+ {
+ foreach (var text in new[] { En, He })
+ {
+ var name = text["ui.lang"] == UiLanguage.Hebrew ? "לוד" : "Lydda";
+ using (var r = new Rig(Awaiting(C, "lod"), text, options: Refusing(new[] { "raid", "occupy", "deport" }, CaptureRefusal.NoOneToDeport, new[] { "deport" })))
+ {
+ yield return Frames(3);
+ CollectionAssert.AreEqual(new[] { "capture-option-raid", "capture-option-occupy", "capture-option-deport" }, r.Options.Select(b => b.name).ToList());
+ Assert.IsFalse(r.Root.Q<Button>("capture-option-deport").enabledSelf);
+ Assert.AreEqual(text.Format("capture.refusal.no_one_to_deport", name), r.Root.Q<Label>("capture-refusal-deport").text);
+ }
+ using (var r = new Rig(Awaiting(C, "lod"), text, options: Refusing(new[] { "raid", "occupy", "deport" }, CaptureRefusal.Attention, new[] { "raid", "occupy", "deport" }, 2.0, 0.5)))
+ {
+ yield return Frames(3);
+ Assert.AreEqual(text.Format("capture.refusal.attention", name, 2.0, 0.5), r.Root.Q<Label>("capture-refusal-raid").text);
+ StringAssert.Contains("2.0", r.Root.Q<Label>("capture-refusal-raid").text, "the sim's numbers");
+ StringAssert.Contains("0.5", r.Root.Q<Label>("capture-refusal-raid").text);
+ }
}
}
- /// <summary>No option the sim offers can be chosen (a Raid with no free hex): the dialog says so, the capture waits.</summary>
+ /// <summary>No option the sim offers can be chosen (a Raid with no free hex): every option is disabled, the dialog says
+ /// the decision waits, and Hide is still there.</summary>
[UnityTest]
public IEnumerator WithNothingOfferedTheDialogSaysTheDecisionWaits()
{
using var r = new Rig(Awaiting(C, "lod"), options: Helper(new[] { "raid", "occupy", "deport" }, "raid", "occupy", "deport"));
yield return Frames(3);
- Assert.IsEmpty(r.Options);
+ Assert.AreEqual(3, r.Options.Count);
+ Assert.IsTrue(r.Options.All(b => !b.enabledSelf), "every option refused");
Assert.IsTrue(r.Shows("capture-none"));
Assert.AreEqual(En["capture.none"], r.Root.Q<Label>("capture-none").text);
Assert.IsTrue(r.Shows("capture-hide"), "Hide is still there");
@@ -507,6 +582,281 @@ public class CaptureDialogTests
Assert.AreEqual(LanguageDirection.RTL, r.Root.Q<TextElement>(name).languageDirection, $"{name} reads right to left");
}
+ // ---- The end of an occupation (R-CTRL-014, R-CTRL-015) ----
+
+ /// <summary>A record awaiting the end of its occupation opens the dialog for it: its own intro, Annex then Withdraw in
+ /// the GDD's words, a stayed or fled place's Annex description, the reopen line shared with the capture.</summary>
+ [UnityTest]
+ public IEnumerator TheDialogOpensForAnOccupationAwaitingItsEnd()
+ {
+ foreach (var fled in new[] { false, true })
+ {
+ using var r = new Rig(Ending(C, true, fled, "lod"), endOptions: Helper(EndOrder));
+ yield return Frames(4);
+ Assert.AreEqual("lod", r.Dialog.Shown);
+ Assert.IsTrue(r.Dialog.Ending, "the end of the occupation, not a capture");
+ Assert.IsTrue(r.Shows("capture-card"));
+ Assert.AreEqual("Lydda", r.Root.Q<Label>("capture-title").text);
+ Assert.AreEqual(En.Format("capture.end.intro", "Lydda"), r.Root.Q<Label>("capture-intro").text);
+ CollectionAssert.AreEqual(new[] { En["capture.end.option.annex"], En["capture.end.option.withdraw"] }, r.Options.Select(b => b.text).ToList());
+ Assert.AreEqual(En[fled ? "capture.end.about.annex_fled" : "capture.end.about.annex_stayed"], r.Root.Q<Label>("capture-about-annex").text,
+ "Annex says what it adds: nothing for a fled place (R-CTRL-016)");
+ Assert.AreEqual(En["capture.end.about.withdraw"], r.Root.Q<Label>("capture-about-withdraw").text);
+ Cancel(r.Element);
+ yield return Frames(2);
+ Assert.AreEqual(En.Format("capture.reopen", "Lydda"), r.Waiting.text);
+ }
+ }
+
+ /// <summary>Plan PR 10, TheEndOrderIsTheSims (R-CTRL-015): the buttons are the real EndOptions, Annex then Withdraw, no
+ /// puppet regime and nothing the UI made up; enabled with the garrison there.</summary>
+ [UnityTest]
+ public IEnumerator TheEndOrderIsTheSims()
+ {
+ using var r = new Rig(Ending(C, true, false, "lod"));
+ yield return Frames(4);
+ var helper = SettlementControl.EndOptions(r.Bridge.Content, r.Bridge.State, "lod");
+ CollectionAssert.AreEqual(EndOrder, helper.Select(o => o.Outcome).ToList(), "precondition: the sim's order");
+ Assert.IsTrue(helper.All(o => o.Refused == null), "precondition: the garrison is there: " + string.Join("; ", helper.Select(o => o.Refusal)));
+ CollectionAssert.AreEqual(EndOrder.Select(o => "capture-option-" + o).ToList(), r.Options.Select(b => b.name).ToList());
+ Assert.IsTrue(r.Options.All(b => b.enabledSelf));
+ }
+
+ /// <summary>Plan PR 10, EndNothingIsPreselected: the dialog itself has the focus, the options look alike, Tab reaches
+ /// Annex, Withdraw, then Hide.</summary>
+ [UnityTest]
+ public IEnumerator EndNothingIsPreselected()
+ {
+ using var r = new Rig(Ending(C, true, false, "lod"), endOptions: Helper(EndOrder));
+ yield return Frames(4);
+ Assert.AreSame(r.Element, r.Focused, "the dialog itself has the focus, not an option");
+ Assert.AreEqual(1, r.Options.Select(b => string.Join(" ", b.GetClasses().OrderBy(x => x))).Distinct().Count(), "no default style");
+ VisualElement at = r.Element;
+ foreach (var expected in r.Options.Cast<VisualElement>().Append(r.Hide))
+ {
+ Tab(at);
+ yield return Frames(1);
+ Assert.AreSame(expected, r.Focused, $"Tab from {at.name} reaches {expected.name}");
+ at = expected;
+ }
+ Assert.IsEmpty(r.Bridge.Queued);
+ }
+
+ /// <summary>Plan PR 10, TheEndPreviewIsTheSims: under each option, EndOptions' own preview, headed as the resources only
+ /// (the people, homes and jobs Annex adds are in its description, not in numbers the UI makes); priced at 1, the sim's
+ /// Attention change shows.</summary>
+ [UnityTest]
+ public IEnumerator TheEndPreviewIsTheSims()
+ {
+ var c = Targets(endPrice: 1);
+ using var r = new Rig(Ending(c, true, false, "lod"));
+ yield return Frames(4);
+ foreach (var o in SettlementControl.EndOptions(r.Bridge.Content, r.Bridge.State, "lod"))
+ {
+ Assert.IsNull(o.Refused, "precondition: " + o.Refusal);
+ var shown = r.Root.Q<Label>("capture-preview-" + o.Outcome).text;
+ Assert.AreEqual(CaptureDialogPresenter.PreviewText(r.Bridge.Content, r.Bridge.State, o.Preview!, En, ending: true), shown);
+ StringAssert.StartsWith(En["capture.end.changes"], shown);
+ StringAssert.Contains(En.Format("report.line", En["capture.caption.attention"], En.Format("capture.delta_attention", o.Preview!.Attention)), shown);
+ Assert.AreEqual(-r.Bridge.Price(new EndOccupation("lod", o.Outcome)), o.Preview.Attention, 1e-9);
+ }
+ using var free = new Rig(Ending(C, true, false, "lod"));
+ yield return Frames(3);
+ Assert.AreEqual(En["capture.end.changes_none"], free.Root.Q<Label>("capture-preview-annex").text);
+ }
+
+ /// <summary>Plan PR 10, ChoosingIssuesEndOccupation (R-CTRL-014): a choice queues EndOccupation(place, outcome), changes
+ /// nothing until End turn, goes on to the next place; End turn carries it out.</summary>
+ [UnityTest]
+ public IEnumerator ChoosingIssuesEndOccupation()
+ {
+ using var r = new Rig(Ending(C, true, false, "lod", "ramla"));
+ yield return Frames(4);
+ Assert.AreEqual("lod", r.Dialog.Shown);
+ Press(r.Root.Q<Button>("capture-option-annex"));
+ yield return Frames(3);
+ var queued = r.Bridge.Queued.OfType<EndOccupation>().Single();
+ Assert.AreEqual(("lod", SettlementControl.Annex), (queued.Settlement, queued.Outcome));
+ Assert.AreEqual(SettlementControl.AwaitingEnd, r.Bridge.State.Settlements["lod"].State, "nothing happens before End turn");
+ Assert.AreEqual("ramla", r.Dialog.Shown, "the next place");
+ Assert.IsTrue(r.Dialog.Ending);
+ Press(r.Root.Q<Button>("capture-option-withdraw"));
+ yield return Frames(3);
+ Assert.IsNull(r.Dialog.Shown);
+ Assert.AreSame(r.Root.Q<Button>("end-turn"), r.Focused, "answered from the keyboard, the focus goes to End turn");
+ var result = r.Bridge.EndTurn();
+ Assert.IsEmpty(result.Rejected.Where(x => x.Command is EndOccupation), string.Join("; ", result.Rejected.Select(x => x.Reason)));
+ Assert.AreEqual(SettlementControl.Annexed, r.Bridge.State.Settlements["lod"].State, "End turn annexed Lydda (R-CTRL-016)");
+ Assert.IsFalse(r.Bridge.State.Settlements.ContainsKey("ramla"), "and withdrew from Ramle (R-CTRL-010)");
+ }
+
+ /// <summary>Plan PR 10, AQueuedEndDecisionIsNotShownAgain: a place with an EndOccupation queued has had its choice; a new
+ /// answer replaces it in the one slot (SimBridge.Key).</summary>
+ [UnityTest]
+ public IEnumerator AQueuedEndDecisionIsNotShownAgain()
+ {
+ using var r = new Rig(Ending(C, true, false, "lod"));
+ yield return Frames(3);
+ Assert.IsNull(r.Bridge.Queue(new EndOccupation("lod", SettlementControl.Annex)));
+ yield return Frames(3);
+ Assert.IsNull(r.Dialog.Shown, "answered");
+ Assert.IsNull(r.Bridge.Queue(new EndOccupation("lod", SettlementControl.WithdrawOutcome)));
+ Assert.AreEqual(SettlementControl.WithdrawOutcome, r.Bridge.Queued.OfType<EndOccupation>().Single().Outcome, "one slot, the later answer");
+ }
+
+ /// <summary>Plan PR 10, EndEscapeHidesAndDoesNotChoose: Escape hides the end dialog, queues nothing, and Decision waiting
+ /// brings it back with the focus on it; the occupation keeps waiting (R-CTRL-014).</summary>
+ [UnityTest]
+ public IEnumerator EndEscapeHidesAndDoesNotChoose()
+ {
+ using var r = new Rig(Ending(C, true, false, "lod"), endOptions: Helper(EndOrder));
+ yield return Frames(4);
+ Cancel(r.Element);
+ yield return Frames(3);
+ Assert.IsTrue(r.Dialog.Collapsed);
+ Assert.IsEmpty(r.Bridge.Queued);
+ Assert.AreSame(r.Waiting, r.Focused);
+ Press(r.Waiting);
+ yield return Frames(3);
+ Assert.IsFalse(r.Dialog.Collapsed);
+ Assert.AreSame(r.Element, r.Focused);
+ Assert.AreEqual(SettlementControl.AwaitingEnd, r.Bridge.State.Settlements["lod"].State);
+ }
+
+ /// <summary>The decision card goes before the end dialog as before the capture dialog.</summary>
+ [UnityTest]
+ public IEnumerator TheDecisionCardGoesBeforeTheEndDialog()
+ {
+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
+ Assert.IsNotEmpty(g.State.PendingEvents, "precondition: an event is pending");
+ g.State.Settlements["lod"] = new SettlementControl(Movement.PlayerSide, SettlementControl.AwaitingEnd, g.State.Date);
+ using var r = new Rig(g, endOptions: Helper(EndOrder));
+ yield return Frames(4);
+ Assert.AreEqual("lod", r.Dialog.Shown);
+ Assert.IsFalse(r.Shows("capture-card") || r.Shows("capture-reopen"), "waits behind the card");
+ r.Card.Collapse();
+ yield return Frames(3);
+ Assert.IsTrue(r.Shows("capture-card"));
+ Assert.IsTrue(r.Dialog.Ending);
+ }
+
+ /// <summary>Owner, 24 October 2026 on #802, "By settlement order": captures and ends of occupation go in one ordinal pass
+ /// over the places, each showing the decision it has, whichever kind comes first.</summary>
+ [UnityTest]
+ public IEnumerator CaptureAndEndGoBySettlementOrder()
+ {
+ foreach (var lodEnds in new[] { true, false })
+ {
+ var g = Ending(C, true, false);
+ g.State.Settlements["lod"] = new SettlementControl(Movement.PlayerSide, lodEnds ? SettlementControl.AwaitingEnd : SettlementControl.AwaitingChoice, g.State.Date);
+ g.State.Settlements["ramla"] = new SettlementControl(Movement.PlayerSide, lodEnds ? SettlementControl.AwaitingChoice : SettlementControl.AwaitingEnd, g.State.Date);
+ using var r = new Rig(g, options: Helper(new[] { "raid", "occupy" }), endOptions: Helper(EndOrder));
+ yield return Frames(4);
+ Assert.AreEqual(("lod", lodEnds), (r.Dialog.Shown, r.Dialog.Ending), "Lydda first (ordinal), with its own decision");
+ Assert.AreEqual(En.Format("event.more", 1), r.Root.Q<Label>("capture-count").text, "both kinds count");
+ Press(r.Options[0]);
+ yield return Frames(3);
+ Assert.AreEqual(("ramla", !lodEnds), (r.Dialog.Shown, r.Dialog.Ending), "then Ramle, with its own");
+ Assert.AreEqual(1, lodEnds ? r.Bridge.Queued.OfType<EndOccupation>().Count() : r.Bridge.Queued.OfType<ResolveCapture>().Count());
+ }
+ }
+
+ /// <summary>Plan PR 10, RefusedOptionsStayInOrderAndExplainWhy and NoneEnabledStillWaits (R-CTRL-014): with no Israeli
+ /// unit on the place, the real EndOptions refuses both; both stay, disabled, in order, each saying why in the UI's
+ /// language, with no preview; the dialog says the decision waits; nothing can be queued.</summary>
+ [UnityTest]
+ public IEnumerator WithNoGarrisonTheEndWaitsAndSaysWhy()
+ {
+ foreach (var text in new[] { En, He })
+ {
+ using var r = new Rig(Ending(C, false, false, "lod"), text);
+ yield return Frames(4);
+ Assert.IsTrue(SettlementControl.EndOptions(r.Bridge.Content, r.Bridge.State, "lod").All(o => o.Refused?.Id == CaptureRefusal.NeedsUnit), "precondition");
+ CollectionAssert.AreEqual(EndOrder.Select(o => "capture-option-" + o).ToList(), r.Options.Select(b => b.name).ToList());
+ var name = text["ui.lang"] == UiLanguage.Hebrew ? "לוד" : "Lydda";
+ foreach (var o in EndOrder)
+ {
+ Assert.IsFalse(r.Root.Q<Button>("capture-option-" + o).enabledSelf);
+ Assert.AreEqual(text.Format("capture.refusal.needs_unit", name), r.Root.Q<Label>("capture-refusal-" + o).text);
+ Assert.IsNull(r.Root.Q("capture-preview-" + o));
+ Press(r.Root.Q<Button>("capture-option-" + o));
+ }
+ yield return Frames(2);
+ Assert.IsEmpty(r.Bridge.Queued);
+ Assert.IsTrue(r.Shows("capture-none"));
+ Assert.AreEqual(text["capture.end.none"], r.Root.Q<Label>("capture-none").text);
+ Assert.IsTrue(r.Shows("capture-hide"));
+ }
+ }
+
+ /// <summary>Plan PR 10, EndNoSoundAndNoVideo: opening the end dialog and choosing play nothing.</summary>
+ [UnityTest]
+ public IEnumerator EndNoSoundAndNoVideo()
+ {
+ var made = new List<AudioClip>();
+ var speaker = new Speaker();
+ using var r = new Rig(Ending(C, true, false, "lod"), endOptions: Helper(EndOrder));
+ var audio = new GameAudio(r.Bridge, r.Card, path => { var a = AudioClip.Create(path, 441, 1, 44100, false); made.Add(a); return a; }, speaker);
+ try
+ {
+ r.Dialog.Reopen();
+ yield return Frames(4);
+ Assert.IsTrue(r.Shows("capture-card") && r.Dialog.Ending);
+ Press(r.Root.Q<Button>("capture-option-annex"));
+ yield return Frames(3);
+ Assert.IsNotEmpty(r.Bridge.Queued);
+ Assert.IsEmpty(speaker.Played);
+ }
+ finally
+ {
+ audio.Dispose();
+ foreach (var a in made) Object.DestroyImmediate(a);
+ }
+ }
+
+ /// <summary>Plan PR 10, EveryEndOutcomeHasReviewedStringsInBothLanguages: every end outcome's name and description, the end
+ /// dialog's lines, and a line for every refusal id the dialog can show (all but not_in_play, which it never shows), in
+ /// English and Hebrew; the Hebrew ones are Hebrew. Occupy stays שחרור and the held state מוחזק / תקופת ההחזקה (owner,
+ /// #1317 and #803): the end dialog never calls the state שחרור.</summary>
+ [Test]
+ public void EveryEndOutcomeAndRefusalHasItsStringsInBothLanguages()
+ {
+ var g = Ending(C, true, false, "lod");
+ CollectionAssert.AreEqual(EndOrder, SettlementControl.EndOptions(C, g.State, "lod").Select(o => o.Outcome).ToList(), "precondition: Annex then Withdraw");
+ var keys = new[] { "capture.end.intro", "capture.end.option.annex", "capture.end.option.withdraw", "capture.end.about.annex_fled",
+ "capture.end.about.annex_stayed", "capture.end.about.withdraw", "capture.end.changes", "capture.end.changes_none", "capture.end.none" }
+ .Concat(CaptureRefusal.Ids.Where(id => id != CaptureRefusal.NotInPlay).Select(id => "capture.refusal." + id)).ToList();
+ foreach (var key in keys)
+ {
+ Assert.IsTrue(En.Has(key), $"strings.en.yaml: {key}");
+ Assert.IsTrue(He.Has(key), $"strings.he.yaml: {key}");
+ Assert.IsTrue(UiDirection.HasRightToLeft(He[key]), $"strings.he.yaml: {key} is Hebrew: {He[key]}");
+ StringAssert.DoesNotContain("שחרור", He[key], $"{key}: שחרור is Occupy's name only");
+ }
+ Assert.IsFalse(En.Has("capture.refusal.not_in_play") || He.Has("capture.refusal.not_in_play"), "an option out of play is never shown, so it has no line");
+ Assert.AreEqual("שחרור", He["capture.option.occupy"], "Occupy's name (owner, #1317)");
+ StringAssert.Contains("תקופת ההחזקה", He["capture.end.intro"], "the held state's words (owner, #803)");
+ Assert.AreEqual(En["capture.refusal.no_one_to_deport"].TrimEnd('.'), "Its residents fled when it was captured, so there is no one to deport",
+ "the owner's words for the fled town (R-CTRL-018)");
+ }
+
+ /// <summary>Plan PR 10, EndInHebrewIsHebrew: in Hebrew the end dialog names the place by its name_he, shows the Hebrew
+ /// strings, and reads right to left.</summary>
+ [UnityTest]
+ public IEnumerator EndInHebrewIsHebrew()
+ {
+ using var r = new Rig(Ending(C, true, false, "lod"), He);
+ using var direction = new UiDirection(r.Root, r.Bridge);
+ yield return Frames(4);
+ Assert.AreEqual("לוד", r.Root.Q<Label>("capture-title").text);
+ Assert.AreEqual(He.Format("capture.end.intro", "לוד"), r.Root.Q<Label>("capture-intro").text);
+ Assert.AreEqual(He["capture.end.option.annex"], r.Root.Q<Button>("capture-option-annex").text);
+ Assert.AreEqual(He["capture.end.about.annex_stayed"], r.Root.Q<Label>("capture-about-annex").text);
+ Assert.AreEqual(He["capture.end.changes_none"], r.Root.Q<Label>("capture-preview-annex").text);
+ foreach (var name in new[] { "capture-title", "capture-intro", "capture-option-annex", "capture-about-annex", "capture-preview-annex", "capture-option-withdraw" })
+ Assert.AreEqual(LanguageDirection.RTL, r.Root.Q<TextElement>(name).languageDirection, $"{name} reads right to left");
+ }
+
// ---- The layout ----
static bool Inside(Rect inner, Rect outer, float slack = 1f) =>
@@ -519,21 +869,24 @@ public class CaptureDialogTests
(1024, 1024), (960, 1080), (800, 1000), (390, 844), (960, 600), (1531, 784), (1568, 752), (2560, 1080), (1920, 900), (1366, 657),
};
- /// <summary>At every window shape the decision card is checked at, in English and Hebrew, with all three options: the
- /// dialog lies in the decision layer below the top bar, Hide inside it, every option and line no wider than the dialog,
- /// each option's text inside its button. With previews of the size the rules give (Plausible), a window logically at
- /// least EventCardPresenter.ScrollFallbackHeight tall shows everything without scrolling; with every quantity changed
- /// for every option (Full, seven lines each) the text and options scroll and Hide stays in view.</summary>
+ /// <summary>At every window shape the decision card is checked at, in English and Hebrew, with all three options, and
+ /// for the end dialog with a refused Withdraw: the dialog lies in the decision layer below the top bar, Hide inside it,
+ /// every option and line no wider than the dialog, each option's text inside its button. With previews of the size the
+ /// rules give (Plausible), a window logically at least EventCardPresenter.ScrollFallbackHeight tall shows everything
+ /// without scrolling; with every quantity changed for every offered option (Full, seven lines each) and a refused one's
+ /// reason, the text and options scroll and Hide stays in view.</summary>
[UnityTest]
public IEnumerator ItFitsEveryWindowInBothLanguages()
{
var problems = new List<string>();
foreach (var text in new[] { En, He })
foreach (var (w, h) in Windows)
- foreach (var full in new[] { false, true })
+ foreach (var (full, ending) in new[] { (false, false), (true, false), (true, true) })
{
- var at = $"{text["ui.lang"]} {w}x{h}{(full ? " full previews" : "")}";
- using var r = new Rig(Awaiting(C, "lod"), text, w, h, full ? Helper(new[] { "raid", "occupy", "deport" }) : Plausible);
+ var at = $"{text["ui.lang"]} {w}x{h}{(full ? " full previews" : "")}{(ending ? " end, Withdraw refused" : "")}";
+ using var r = ending
+ ? new Rig(Ending(C, true, true, "lod"), text, w, h, endOptions: Helper(EndOrder, SettlementControl.WithdrawOutcome))
+ : new Rig(Awaiting(C, "lod"), text, w, h, full ? Helper(new[] { "raid", "occupy", "deport" }, "deport") : Plausible);
yield return Frames(4);
var card = r.Element.worldBound; var layer = r.Root.Q("event-layer").worldBound; var bar = r.Root.Q("top-bar").worldBound;
if (!(card.width > 0 && card.height > 0)) { problems.Add($"{at}: the dialog is not shown"); continue; }
diff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.uss
index cb5b10c19..bed819f6e 100644
--- a/unity/Assets/UI/Statecraft.uss
+++ b/unity/Assets/UI/Statecraft.uss
@@ -363,6 +363,8 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);
it changes at once, in the muted ink; neither takes a Tab stop. */
.capture-about { white-space: normal; margin: 0 4px 2px 4px; }
.capture-preview { white-space: normal; margin: 0 4px 8px 4px; }
+/* A refused option's reason, in the preview's place and the same quiet ink (owner, 24 October 2026 on #799, "button explains"). */
+.capture-refusal { white-space: normal; margin: 0 4px 8px 4px; }
.draft { display: none; color: var(--down); -unity-font-definition: url("project://database/Assets/UI/Fonts/EBGaramond-SemiBold.ttf"); -unity-text-align: middle-center; }
/* The info panel: the hex's terrain sign (UiIcon on the biome's map colour, InfoPanelPresenter) beside its facts. It starts
right of the left icon lane (84 px, as the toast; #1236: Star, Report and Share sit at the lane's foot) and keeps its right
diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yaml
index 8312e151c..53f0ba1ec 100644
--- a/unity/Assets/UI/strings.en.yaml
+++ b/unity/Assets/UI/strings.en.yaml
@@ -208,6 +208,30 @@ capture.delta_count: "{0:+#,##0;-#,##0}"
capture.none: "None of the choices can be made this turn. The units stay, and the decision waits."
# The hidden dialog's button. {0} the place's name.
capture.reopen: "Decision waiting: {0}"
+# The end of an occupation in the same dialog (R-CTRL-014 to R-CTRL-016; #802). SENSITIVE, as above. Annex then Withdraw, no
+# puppet regime (Q-PUP-1 (c)). Annex has two descriptions, for a place whose residents fled at capture ("territory only, no
+# gain") and one where they stayed. The preview under each is the sim's resources only, so its heading says so; the people,
+# homes and jobs Annex adds are in the description, with no number. {0} the place's name.
+capture.end.intro: "The occupation period in {0} is over. Choose whether to annex the place or withdraw. Your choice takes effect at End turn; until you choose, the unit stays and the occupation upkeep continues."
+capture.end.option.annex: "Annex"
+capture.end.option.withdraw: "Withdraw"
+capture.end.about.annex_fled: "The place stays under Israeli control. Its residents fled when it was captured, so no people, homes or jobs are added. The occupation upkeep ends, and no unit has to stay."
+capture.end.about.annex_stayed: "The place stays under Israeli control, and its residents join the population with their homes and jobs. The occupation upkeep ends, and no unit has to stay."
+capture.end.about.withdraw: "The units leave, and the place is under enemy control again. The occupation upkeep ends."
+capture.end.changes: "Resource changes at once:"
+capture.end.changes_none: "Resource changes at once: none"
+capture.end.none: "Neither choice can be made this turn. The unit stays, the occupation upkeep continues, and the decision waits."
+# Why an option cannot be chosen, under its disabled button (owner, 24 October 2026 on #799, "button explains"), one line per
+# refusal id the sim gives (CaptureRefusal; Q-TECH-5: the dialog never shows the sim's English). SENSITIVE, as above. An
+# option out of play (not_in_play) is not shown, so it has no line. {0} the place's name; attention: {1} what the choice
+# needs, {2} what is left.
+capture.refusal.attention: "Not enough Attention this turn: this needs {1:0.0}, and {2:0.0} is left."
+capture.refusal.needs_unit: "An Israeli military unit must be in {0} for this."
+capture.refusal.no_free_hex: "A unit in {0} has no free hex next to it to withdraw to."
+capture.refusal.no_one_to_deport: "Its residents fled when it was captured, so there is no one to deport."
+capture.refusal.already_city: "{0} is already a city."
+capture.refusal.not_awaiting: "{0} is not waiting for this decision."
+capture.refusal.unknown_outcome: "This choice is not known."
start.listen: "Play the recording"
start.stop: "Stop the recording"
start.loading: "Loading the recording…"
diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yaml
index df5a0cb93..f0205bf7d 100644
--- a/unity/Assets/UI/strings.he.yaml
+++ b/unity/Assets/UI/strings.he.yaml
@@ -214,6 +214,25 @@ capture.delta_attention: "{0:+0.0;-0.0}"
capture.delta_count: "{0:+#,##0;-#,##0}"
capture.none: "אף אחת מהאפשרויות אינה זמינה בתור הזה. הכוחות נשארים במקום, וההחלטה ממתינה."
capture.reopen: "החלטה ממתינה: {0}"
+# The end of an occupation (#802). SENSITIVE, agent-drafted, for the native reviewer (#564). The state is "held" (מוחזק,
+# תקופת ההחזקה; owner, #803), never שחרור, which is Occupy's name only (owner, #1317). Direct option names: סיפוח, נסיגה.
+capture.end.intro: "תקופת ההחזקה ב־{0} הסתיימה. יש לבחור אם לספח את המקום או לסגת ממנו. הבחירה תיכנס לתוקף בסיום התור; עד שתיבחר אפשרות, היחידה נשארת במקום ועלות ההחזקה נמשכת."
+capture.end.option.annex: "סיפוח"
+capture.end.option.withdraw: "נסיגה"
+capture.end.about.annex_fled: "המקום נשאר בשליטה ישראלית. תושביו נמלטו בעת הכיבוש, ולכן לא מתווספים תושבים, בתים או מקומות עבודה. עלות ההחזקה מסתיימת, ואין צורך להשאיר יחידה במקום."
+capture.end.about.annex_stayed: "המקום נשאר בשליטה ישראלית, ותושביו מצטרפים לאוכלוסייה עם בתיהם ומקומות העבודה שלהם. עלות ההחזקה מסתיימת, ואין צורך להשאיר יחידה במקום."
+capture.end.about.withdraw: "הכוחות יוצאים, והמקום חוזר לשליטת האויב. עלות ההחזקה מסתיימת."
+capture.end.changes: "שינויים מיידיים במשאבים:"
+capture.end.changes_none: "שינויים מיידיים במשאבים: אין"
+capture.end.none: "אף אחת מהאפשרויות אינה זמינה בתור הזה. היחידה נשארת במקום, עלות ההחזקה נמשכת, וההחלטה ממתינה."
+# Why an option cannot be chosen (#802), by the sim's refusal id. SENSITIVE, agent-drafted, for the native reviewer (#564).
+capture.refusal.attention: "אין די תשומת לב בתור הזה: נדרש {1:0.0}, ונותר {2:0.0}."
+capture.refusal.needs_unit: "לשם כך נדרשת יחידה צבאית ישראלית ב־{0}."
+capture.refusal.no_free_hex: "ליחידה ב־{0} אין משבצת פנויה סמוכה לסגת אליה."
+capture.refusal.no_one_to_deport: "תושביו נמלטו בעת הכיבוש, ולכן אין את מי לגרש."
+capture.refusal.already_city: "{0} כבר עיר."
+capture.refusal.not_awaiting: "{0} אינו ממתין להחלטה הזו."
+capture.refusal.unknown_outcome: "האפשרות הזו אינה מוכרת."
start.listen: "השמעת ההקלטה"
start.stop: "עצירת ההקלטה"
start.loading: "טוען את ההקלטה…"