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.

Civ movement S5c and S6: withdrawal Why lines carry their unit, and a move captures where it ends (Refs #1398) (#1517)

Eyal Golanef62e9f1c948
diff --git a/changelog.d/1398-s6.md b/changelog.d/1398-s6.md
new file mode 100644
index 000000000..868bf1099
--- /dev/null
+++ b/changelog.d/1398-s6.md
@@ -0,0 +1,4 @@
+### Changed
+
+- Sim: a unit captures an undefended enemy-held target when its move or go-to step ends there, not at End turn; passing
+ through captures nothing. The answer to the capture still takes effect at End turn (R-CTRL-004, #1398).
diff --git a/changelog.d/1399-s5c.md b/changelog.d/1399-s5c.md
new file mode 100644
index 000000000..17dfc017f
--- /dev/null
+++ b/changelog.d/1399-s5c.md
@@ -0,0 +1,2 @@
+- Sim: the withdrawal Why lines for Raid and Deport carry their unit, place and destination hex, so the screen can name
+ the unit in the player's language (#1399). Their English text is unchanged.
diff --git a/docs/determinism.md b/docs/determinism.md
index 3917d34a2..ae3651c3d 100644
--- a/docs/determinism.md
+++ b/docs/determinism.md
@@ -18,10 +18,11 @@ The simulation must produce the same state, bit for bit, on .NET, Unity Mono and
Round-trip decimal formatting is only a display concern: .NET and Unity Mono can spell the same carry bits
differently. The Phase 7 minister carry correction re-pins hash1950, hash1952 and mvp-end for this representation
only; stored values, gameplay and completion dates are unchanged.
-- **Settlement control (resolver step 3):** targets resolve in ordinal id order, and the capture check reads only unit
- positions, with no RNG draw (R-CTRL-004; `CaptureTests.SettlementsResolveInOrdinalOrder` and `NoRngDraw`). The shipped
- list has six targets (#793), and only `mvp-occupy-cost` captures a place (Nazareth): player units may enter the five
- enemy-held ones since #1304 (R-MOVE-005), but the reference player sends no Move, so none of its units stands on one, and its unit on
+- **Settlement control:** the player capture check runs after the route step and each order, then again in resolver
+ step 3 after enemy combat. Each check visits targets in ordinal id order and reads only unit positions, with no RNG
+ draw (R-CTRL-004; `CaptureTests.SettlementsResolveInOrdinalOrder`, `NoRngDraw` and `TheInstantCheckDrawsNothing`).
+ The shipped list has six targets (#793), and only `mvp-occupy-cost` captures a place (Nazareth): player units may
+ enter the five enemy-held ones since #1304 (R-MOVE-005), but the reference player sends no Move, so none of its units stands on one, and its unit on
Jaffa's hex (shared with Tel Aviv) captures nothing, since Jaffa is not enemy-held at the start. The smoke-orders
move skips the lit hexes of enemy-held places on purpose (`GoldenRun.SmokeMove`), so it stays a plain move.
- **Answering a capture (Raid and withdraw):** the units on the place leave in ascending id, each to the first free hex in
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index d059c1bd8..53388cdbe 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -38,11 +38,11 @@ R-CTRL-002: Settlement control is an ordinal `SortedDictionary<string, Settlemen
R-CTRL-003: Residents and combatants are distinct fields. Residents are a state, inhabited or depopulated, not a count (Q-CAP-2 (b)). No rule reads residents as combatants, prisoners, refugee units, labour or a resource; annexation is the one place a later owner-approved rule may say otherwise.
-R-CTRL-004: Resolver step 3 is the capture check, after combat (step 2), in ordinal settlement id (Q-CAP-1 (a), Q-CAP-3 (a), owner rulings of 18 October 2026). A target that starts under enemy control, one listed in `mvp.enemy_held_localities` (owner, 21 October 2026, #796), is captured at turn end when Israeli military units are on its hex and no enemy military unit is; only enemy military units are combatants (Q-CAP-3 (a)), and a halutz holds nothing (#796). Its record names `israel` as owner, has the state `awaiting_choice` and starts on the turn's end (`Since`); the player's units stay on the hex. A captured target still awaiting the choice that only enemy military units are on is under enemy control again, and its record is removed (#796). A target not enemy-held at the start (Jaffa, owner ruling of 18 October 2026 on #793, "Only in a what-if") is never captured. The check is an integer rule on unit positions and draws nothing from the RNG. Enemy captures of the player's localities (Q-TGT-2 (c), the plan's R-CTRL-006) are not built yet: with the real starting forces a Syrian unit stands on Degania Alef's hex with no Israeli unit, so the rule would record a capture at the first turn's end (#796).
+R-CTRL-004: The capture check runs after the route step and each order, and still in resolver step 3 after enemy combat, in ordinal settlement id (Q-CAP-1 (a), Q-CAP-3 (a), owner rulings of 18 October 2026). A target that starts under enemy control, one listed in `mvp.enemy_held_localities` (owner, 21 October 2026, #796), is captured at once when Israeli military units are on its hex and no enemy military unit is; only enemy military units are combatants (Q-CAP-3 (a)), and a halutz holds nothing (#796). Passing through a target does not capture it; only a move's or go-to's stopping hex counts (owner, 23 October 2026, OQ-2: "Instant"). Its record names `israel` as owner and has the state `awaiting_choice`; the preview leaves `Since` unset, and Step stamps the turn's end before the resolver, preserving the date through a same-turn answer. The answer stays deferred until End turn (R-TURN-004). A capture remains when the unit leaves; the player's units stay on the hex. A captured target still awaiting the choice that only enemy military units are on is under enemy control again, and its record is removed (#796). A target not enemy-held at the start (Jaffa, owner ruling of 18 October 2026 on #793, "Only in a what-if") is never captured. The check is an integer rule on unit positions and draws nothing from the RNG. Enemy captures of the player's localities (Q-TGT-2 (c), the plan's R-CTRL-006) are not built yet: with the real starting forces a Syrian unit stands on Degania Alef's hex with no Israeli unit, so the rule would record a capture at the first turn's end (#796).
R-CTRL-005: Capture writes the settlement state only. It changes no resident field (the place stays inhabited), no unit, no resource, parameter, city or score, and counts towards no objective (constraint 6 of the Phase 6 plan; impact plan section 4.3).
-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, from the turn after its capture until it is answered, and only for an outcome that is built. 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-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.
diff --git a/sim/Statecraft.Sim.Tests/CaptureTests.cs b/sim/Statecraft.Sim.Tests/CaptureTests.cs
index be3603dcd..918bf09c9 100644
--- a/sim/Statecraft.Sim.Tests/CaptureTests.cs
+++ b/sim/Statecraft.Sim.Tests/CaptureTests.cs
@@ -243,4 +243,84 @@ public class CaptureTests
Assert.False(Reaches("gaza"));
Assert.True(Reaches("acre"));
}
+
+ // R-CTRL-004 (owner, 23 October 2026, OQ-2: "Instant"): a move that ends on an enemy-held target with no enemy unit
+ // there captures it at once, before End turn; End turn stamps the turn's end as Since, as step 3 does.
+ [Fact]
+ public void AMoveEndingOnATargetCapturesItAtOnce()
+ {
+ var c = Load(AllTargets);
+ var s = With(c, Soldier(1, 0, 1));
+ var now = Simulation.Preview(c, s, new Command[] { new Move(1, 1, 0) });
+ Assert.Equal(SettlementControl.AwaitingChoice, now.State.Settlements["town_a"].State);
+ Assert.Equal(default(DateTime), now.State.Settlements["town_a"].Since);
+ var ended = Simulation.Step(c, s, new Command[] { new Move(1, 1, 0) }).State;
+ Assert.Equal(ended.Date, ended.Settlements["town_a"].Since);
+ }
+
+ // R-CTRL-004: passing through a target captures nothing (R-MOVE-005 lets a path pass through it): 0,0 to 2,0 crosses 1,0.
+ [Fact]
+ public void PassingThroughATargetCapturesNothing()
+ {
+ var c = Load(AllTargets);
+ var s = With(c, Soldier(1, 0, 0));
+ Assert.Equal(new[] { (1, 0), (2, 0) }, Movement.Path(c, s, 1, 2, 0)); // precondition: the path crosses town_a
+ Assert.Empty(Simulation.Preview(c, s, new Command[] { new Move(1, 2, 0) }).State.Settlements);
+ }
+
+ // R-CTRL-004: a unit that captured and left keeps the capture; only enemy units alone on it take it back, in step 3.
+ [Fact]
+ public void ACaptureStaysWhenTheUnitLeaves()
+ {
+ var c = Load(AllTargets);
+ var s = With(c, Soldier(1, 0, 1));
+ var ended = Simulation.Step(c, s, new Command[] { new Move(1, 1, 0), new Move(1, 0, 1) }).State;
+ Assert.Equal(SettlementControl.AwaitingChoice, ended.Settlements["town_a"].State);
+ }
+
+ // R-CTRL-004: the check draws nothing.
+ [Fact]
+ public void TheInstantCheckDrawsNothing()
+ {
+ var c = Load(AllTargets);
+ var s = With(c, Soldier(1, 0, 1));
+ Assert.Equal(s.RngState, Simulation.Preview(c, s, new Command[] { new Move(1, 1, 0) }).State.RngState);
+ }
+
+ // R-CTRL-007: the answer stays deferred: given in the capture's turn, it runs at End turn after the capturing move.
+ [Fact]
+ public void TheAnswerGivenInTheCapturesTurnRunsAtEndTurn()
+ {
+ var c = Load(AllTargets);
+ var s = With(c, Soldier(1, 0, 1));
+ var ended = Simulation.Step(c, s, new Command[] { new Move(1, 1, 0), new ResolveCapture("town_a", SettlementControl.Raid) });
+ Assert.Empty(ended.Rejected);
+ Assert.False(ended.State.Settlements.ContainsKey("town_a"));
+ }
+
+ // R-CTRL-004: the automatic route stop is checked before any order (spec 4.4, 6.3).
+ [Fact]
+ public void ARouteStopCapturesBeforeAnyPlayerOrder()
+ {
+ var c = Load(AllTargets);
+ var s = With(c, new Unit(1, "soldier", 0, 1, side: "israel", strength: 2,
+ order: Movement.GoTo, orderTarget: "1,0"));
+ var now = Simulation.Preview(c, s, Array.Empty<Command>());
+ Assert.Equal((1, 0), (now.State.Units[1].Q, now.State.Units[1].R));
+ Assert.Equal(SettlementControl.AwaitingChoice, now.State.Settlements["town_a"].State);
+ Assert.Equal(default(DateTime), now.State.Settlements["town_a"].Since);
+ }
+
+ // R-CTRL-004: same-turn answers preserve the capture date, including Deport's ownerless record (#1327).
+ [Theory]
+ [InlineData(SettlementControl.Occupy)]
+ [InlineData(SettlementControl.Deport)]
+ public void ANewCaptureAnsweredInTheSameTurnKeepsItsCaptureDate(string outcome)
+ {
+ var c = DeportTests.Load();
+ var s = With(c, Soldier(1, 0, 1));
+ var ended = Simulation.Step(c, s, new Command[] { new Move(1, 1, 0), new ResolveCapture("town_a", outcome) });
+ Assert.Empty(ended.Rejected);
+ Assert.Equal(ended.State.Date, ended.State.Settlements["town_a"].Since);
+ }
}
diff --git a/sim/Statecraft.Sim.Tests/OccupyTests.cs b/sim/Statecraft.Sim.Tests/OccupyTests.cs
index 18c4b3160..3c5b478dc 100644
--- a/sim/Statecraft.Sim.Tests/OccupyTests.cs
+++ b/sim/Statecraft.Sim.Tests/OccupyTests.cs
@@ -150,7 +150,11 @@ public class OccupyTests
Assert.Empty(result.State.Settlements);
Assert.Contains(result.Why, x => x.Target == "town_a" && x.Message.Contains("under enemy control again"));
Assert.Contains(Movement.NoEntry(c, result.State), h => h == (1, 0));
- Assert.Equal(Step(c, Without(s), new Move(1, 2, 0)).State.Describe(), result.State.Describe());
+ // Spec 4.4 now captures a unit already on the target before orders. A never-captured twin must start outside.
+ var twin = Without(s);
+ Assert.Null(Movement.Move(c, twin, 1, 2, 0, new Dictionary<int, int>(), new List<Cause>()));
+ Assert.Equal((2, 0), (result.State.Units[1].Q, result.State.Units[1].R));
+ Assert.Equal(Step(c, twin).State.Describe(), result.State.Describe());
}
// R-CTRL-013: a halutz left on the hex holds nothing (#796), so the occupation still ends.
diff --git a/sim/Statecraft.Sim.Tests/RaidTests.cs b/sim/Statecraft.Sim.Tests/RaidTests.cs
index 29a942747..bbc2c56fd 100644
--- a/sim/Statecraft.Sim.Tests/RaidTests.cs
+++ b/sim/Statecraft.Sim.Tests/RaidTests.cs
@@ -79,7 +79,7 @@ public class RaidTests
var s = Awaiting(c, 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 before = s.Clone();
var why = new List<Cause>();
- Assert.Contains("Unit 6 has no free hex", SettlementControl.Resolve(c, s, "town_a", SettlementControl.Raid, why));
+ Assert.Contains("A unit has no free hex", SettlementControl.Resolve(c, s, "town_a", SettlementControl.Raid, why));
Assert.Empty(why);
Assert.Equal(before.Describe(), s.Describe());
Assert.Single(Step(c, before, Raid()).Rejected);
diff --git a/sim/Statecraft.Sim.Tests/UnitLinesTests.cs b/sim/Statecraft.Sim.Tests/UnitLinesTests.cs
index 51c720f3e..2f3c1b125 100644
--- a/sim/Statecraft.Sim.Tests/UnitLinesTests.cs
+++ b/sim/Statecraft.Sim.Tests/UnitLinesTests.cs
@@ -178,4 +178,15 @@ public class UnitLinesTests
var fire = held.Single(w => w.Key == WhyKeys.HoldsFire);
Assert.Equal((5, "2,0"), (fire.Units.Single().Id, fire.Args[0]));
}
+
+ [Fact]
+ public void AWithdrawalNamesTheUnit()
+ {
+ var c = CaptureTests.Load(CaptureTests.AllTargets);
+ var s = CombatTests.With(c, CaptureTests.Soldier(1, 1, 0));
+ s = Simulation.Step(c, s, new Command[0]).State; // captured at the turn's end
+ var raid = Simulation.Step(c, s, new Command[] { new ResolveCapture("town_a", SettlementControl.Raid) });
+ var line = raid.Why.Single(w => w.Key == WhyKeys.Withdrew);
+ Assert.Equal((1, "town_a"), (line.Units.Single().Id, line.Args[0]));
+ }
}
diff --git a/sim/Statecraft.Sim.Tests/scenarios/mvp-occupy-cost.yaml b/sim/Statecraft.Sim.Tests/scenarios/mvp-occupy-cost.yaml
index 70885d78d..a163adc34 100644
--- a/sim/Statecraft.Sim.Tests/scenarios/mvp-occupy-cost.yaml
+++ b/sim/Statecraft.Sim.Tests/scenarios/mvp-occupy-cost.yaml
@@ -1,6 +1,6 @@
# What an occupation costs (GDD Phase 6 PR 6, #798): from a capture in the real content, choose Occupy and run to the
# timer's end. Golani's unit (id 0) moves onto Nazareth's hex on the first turn (open to the player's units since #1304,
-# R-MOVE-005) and captures it at turn end (R-CTRL-004). The next turn the scenario answers with Occupy (R-CTRL-011).
+# R-MOVE-005) and captures it when the move ends (R-CTRL-004). The next turn the scenario answers with Occupy (R-CTRL-011).
# Step 10 charges the upkeep each turn and counts the timer down (R-CTRL-012), so the place waits for EndOccupation
# (#799) when the run stops on 15 December 1948: the timer has run out after six turn resolutions from the choice. It
# plays the real content, so it moves whenever a rule or value it reaches changes. The paired mvp-deport-cost is not
diff --git a/sim/Statecraft.Sim/SettlementControl.cs b/sim/Statecraft.Sim/SettlementControl.cs
index 9c1e318f6..6b9326e8f 100644
--- a/sim/Statecraft.Sim/SettlementControl.cs
+++ b/sim/Statecraft.Sim/SettlementControl.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
using System.Linq;
namespace Statecraft.Sim
@@ -17,32 +16,44 @@ namespace Statecraft.Sim
/// <summary>The <see cref="State"/> of an occupied place whose timer has ended: it awaits EndOccupation (Phase 6 PR 7).</summary>
public const string AwaitingEnd = "awaiting_end";
- /// <summary>Resolver step 3 (R-CTRL-004, R-CTRL-005), after combat, in ordinal settlement id. A curated target that
- /// starts under enemy control (on mvp.enemy_held_localities, owner, 21 October 2026, #796) is captured when the
- /// player's military units are on its hex and no enemy military unit is (Q-CAP-1 (a); Q-CAP-3 (a): only enemy military
- /// units are combatants; #796: a halutz holds nothing): its record names the player, awaits the player's choice and
- /// starts on <paramref name="next"/>, the turn's end. A captured target still awaiting the choice that only enemy
- /// military units are on is under enemy control again, and its record goes (#796). A target that is not enemy-held
- /// at the start (Jaffa, #793) is never captured. Capture writes the settlement state only: no resident field, unit,
- /// resource, score or objective (R-CTRL-005). It draws nothing from the RNG.</summary>
+ /// <summary>R-CTRL-004: the player's capture check, after the route step and each order, and in resolver step 3.
+ /// Only curated enemy-held targets held by Israeli military units alone gain a record. Passing through a hex
+ /// captures nothing. The preview has no capture date; Step stamps the turn's end before the resolver.</summary>
+ internal static void CaptureHeld(Content c, GameState s, List<Cause> why)
+ {
+ var enemyHeld = new HashSet<string>(c.RulesAt(s.Date).Mvp!.EnemyHeldLocalities, StringComparer.Ordinal);
+ foreach (var t in c.SettlementTargets.Where(x => enemyHeld.Contains(x.Id)).OrderBy(x => x.Id, StringComparer.Ordinal))
+ {
+ if (Holder(s, t.Q, t.R) != Movement.PlayerSide || s.Settlements.ContainsKey(t.Id)) continue;
+ s.Settlements[t.Id] = new SettlementControl(Movement.PlayerSide, AwaitingChoice);
+ why.Add(new Cause("map", t.Id, 0, $"{c.SettlementNames[t.Id]} is captured: Israeli units hold it and no enemy unit is there. It awaits a decision"));
+ }
+ }
+
+ /// <summary>R-CTRL-004: a new capture keeps the turn's end date even when its same-turn answer changed its state.
+ /// Deport keeps that date in its ownerless record (#1327); every other field is preserved.</summary>
+ internal static void Stamp(GameState s, DateTime next)
+ {
+ foreach (var id in s.Settlements.Where(x => x.Value.Since == default
+ && (x.Value.Owner == Movement.PlayerSide || x.Value.Depopulated)).Select(x => x.Key).ToList())
+ {
+ var x = s.Settlements[id];
+ s.Settlements[id] = new SettlementControl(x.Owner, x.State, next, x.Depopulated, x.Combatants, x.Buildings, x.Turns);
+ }
+ }
+
+ /// <summary>Resolver step 3, after enemy combat: perform any remaining player capture, stamp its date, then return
+ /// an awaiting-choice target held by enemy military units alone to enemy control. No resident field or RNG changes.</summary>
public static void Capture(Content c, GameState s, DateTime next, List<Cause> why)
{
+ CaptureHeld(c, s, why);
+ Stamp(s, next);
var enemyHeld = new HashSet<string>(c.RulesAt(s.Date).Mvp!.EnemyHeldLocalities, StringComparer.Ordinal);
foreach (var t in c.SettlementTargets.Where(x => enemyHeld.Contains(x.Id)).OrderBy(x => x.Id, StringComparer.Ordinal))
{
- var holder = Holder(s, t.Q, t.R);
- var record = s.Settlements.TryGetValue(t.Id, out var held) ? held : null;
- var name = c.SettlementNames[t.Id];
- if (holder == Movement.PlayerSide && record == null)
- {
- s.Settlements[t.Id] = new SettlementControl(Movement.PlayerSide, AwaitingChoice, next);
- why.Add(new Cause("map", t.Id, 0, $"{name} is captured: Israeli units hold it and no enemy unit is there. It awaits a decision"));
- }
- else if (holder == Enemy && record?.State == AwaitingChoice) // PR 5's outcomes decide what a later state returns to
- {
- s.Settlements.Remove(t.Id);
- why.Add(new Cause("map", t.Id, 0, $"{name} is under enemy control again: enemy units hold it and no Israeli unit is there"));
- }
+ if (Holder(s, t.Q, t.R) != Enemy || !s.Settlements.TryGetValue(t.Id, out var record) || record.State != AwaitingChoice) continue;
+ s.Settlements.Remove(t.Id);
+ why.Add(new Cause("map", t.Id, 0, $"{c.SettlementNames[t.Id]} is under enemy control again: enemy units hold it and no Israeli unit is there"));
}
}
@@ -106,10 +117,10 @@ 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];
- var moved = new List<Unit>();
+ var moved = new List<(Unit From, Unit To)>();
if (MoveOut(c, s, t, name, atTheEnd, moved) is string no) return no;
s.Settlements.Remove(id);
- Withdrew(name, moved, why);
+ Withdrew(id, name, moved, why);
why.Add(new Cause("map", id, 0, moved.Count > 0
? $"{name}: Israeli units withdrew and it is under enemy control again. Its residents are unchanged"
: $"{name} is under enemy control again. Its residents are unchanged"));
@@ -119,31 +130,31 @@ 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> moved)
+ static string? MoveOut(Content c, GameState s, SettlementTarget t, string name, bool atTheEnd, List<(Unit From, Unit To)> moved)
{
- var from = new List<Unit>();
foreach (var u in s.Units.Values.Where(u => u.Q == t.Q && u.R == t.R && !IsEnemy(u)).ToList()) // ascending id
{
var to = Movement.Neighbours.Select(d => ((int Q, int R)?)(t.Q + d.Q, t.R + d.R)).FirstOrDefault(h => Free(c, s, u, h!.Value.Q, h.Value.R));
if (to == null && atTheEnd) continue;
if (to == null)
{
- foreach (var x in from) s.Units[x.Id] = x; // back as it was
+ foreach (var x in moved) s.Units[x.From.Id] = x.From; // back as it was
moved.Clear();
- return $"Unit {u.Id} has no free hex next to {name} to withdraw to";
+ return $"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);
s.Units[u.Id] = w;
- from.Add(u);
- moved.Add(w);
+ moved.Add((u, w));
}
return null;
}
- static void Withdrew(string name, List<Unit> moved, List<Cause> why)
+ static void Withdrew(string id, string name, List<(Unit From, Unit To)> moved, List<Cause> why)
{
- foreach (var w in moved)
- why.Add(new Cause("map", w.Id.ToString(CultureInfo.InvariantCulture), 0, FormattableString.Invariant($"Unit {w.Id} withdrew from {name} to hex {w.Q},{w.R}")));
+ foreach (var (from, to) in moved)
+ why.Add(UnitLines.Line(WhyKeys.Withdrew,
+ FormattableString.Invariant($"Unit {from.Id} withdrew from {name} to hex {to.Q},{to.R}"),
+ new[] { from }, id, FormattableString.Invariant($"{to.Q},{to.R}")));
}
/// <summary>R-CTRL-018 to R-CTRL-021, Deport (impact plan section 4.1; Q-DEP-1 (a) to Q-DEP-5 (c), Q-DEP-7 (c)). The
@@ -156,11 +167,11 @@ 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];
- var moved = new List<Unit>();
+ var moved = new List<(Unit From, Unit To)>();
if (MoveOut(c, s, t, name, false, moved) is string no) return no;
s.Settlements[id] = new SettlementControl(since: s.Settlements[id].Since, depopulated: true);
s.DisplacedByPlayer++;
- Withdrew(name, moved, why);
+ Withdrew(id, name, moved, why);
why.Add(new Cause("map", id, 0, $"{name}: Deport. Its residents are displaced and the place is depopulated"));
var r = c.RulesAt(s.Date).Mvp!; // the loader requires both costs in the GDD loop
foreach (var (indicator, cost) in new[] { ("morale", r.DeportCohesionCost!.Value), (SupportIndicator, r.DeportSupportCost!.Value) })
diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.cs
index c66cf264d..cda7619e1 100644
--- a/sim/Statecraft.Sim/Simulation.cs
+++ b/sim/Statecraft.Sim/Simulation.cs
@@ -54,6 +54,7 @@ namespace Statecraft.Sim
var end = c.End;
var boundary = c.Eras.Select(e => e.From).Where(f => f > s.Date).Concat(new[] { end }).Min();
var next = SimTime.AdvanceTo(s.Date, len, boundary);
+ if (c.IsGdd) SettlementControl.Stamp(s, next); // R-CTRL-004: dates for captures made during the orders
var adjusted = next != SimTime.Advance(s.Date, len);
var days = (next - s.Date).Days;
var yf = adjusted ? days / 365.0 : SimTime.YearFraction(len);
@@ -123,6 +124,7 @@ namespace Statecraft.Sim
Dictionary<int, (int Q, int R)> attacked, List<Cause> why, List<Rejection> rejected)
{
if (c.IsGdd) Movement.ContinueRoutes(c, s, spent, why); // R-MOVE-009: the route step, before the turn's orders
+ if (c.IsGdd) SettlementControl.CaptureHeld(c, s, why);
var priceRung = s.Rung; // every command this turn is priced at the rung the turn started at
foreach (var cmd in commands)
{
@@ -135,6 +137,7 @@ namespace Statecraft.Sim
var before = s.Attention;
var error = AttentionSystem.TrySpend(c, s, cmd.Kind, priceRung) ?? Execute(c, s, cmd, spent, attacked, why);
if (error != null) { s.Attention = before; rejected.Add(new Rejection(cmd, error)); }
+ if (c.IsGdd) SettlementControl.CaptureHeld(c, s, why); // R-CTRL-004: only where an order ends
}
}