A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: Occupy, the occupation timer and withdrawal (GDD Phase 6 PR 6, refs #798) (#1324)
Beri030263e46813
diff --git a/changelog.d/sim-gdd-occupy-798.md b/changelog.d/sim-gdd-occupy-798.mdnew file mode 100644index 000000000..e6a166ebd--- /dev/null+++ b/changelog.d/sim-gdd-occupy-798.md@@ -0,0 +1,8 @@+- Occupy and the occupation timer, GDD Phase 6 PR 6 (#798; R-CTRL-011 to R-CTRL-013): `ResolveCapture(settlement,+ occupy)` now keeps a captured place under Israeli control, with no effect on its residents. It needs an Israeli+ military unit on the hex, and no unit moves. Each turn the occupation costs `mvp.occupation_upkeep_per_turn` (IL+ 0.005m), and resolver step 10 counts it down from `mvp.occupation_turns` (6 turns). At 0 the place waits for the+ end-of-occupation choice (PR 7). If no Israeli military unit is left on the hex, the occupation ends as a raid: the+ place is under enemy control again, its residents unchanged. Both numbers are design values, accepted by the owner on+ 22 October 2026 (#1324). With the garrison formation's own upkeep (IL 0.05m, R-UNIT-010), holding a place costs+ IL 0.055m a turn in all. No golden moves: no golden captures a place.diff --git a/content/rules.yaml b/content/rules.yamlindex 61b90102e..4d812d9f4 100644--- a/content/rules.yaml+++ b/content/rules.yaml@@ -219,6 +219,15 @@ mvp:prisoner_shortfall_cohesion: 0.01 # DESIGN VALUE: owner-set balance, not a historical figure (D-C1, Q-POW-5: Social cohesion lost per unit of the prisoners' Food not given)points_per_prisoner_unit_returned: 10 # DESIGN VALUE: owner-set balance, not a historical figure (D-B6, Q-POW-2: points per population unit of prisoners returned)held_soldier_cost_per_turn: 0.005 # DESIGN VALUE: owner-set balance, not a historical figure (D-C6, Q-POW-4: IL millions a turn per population unit of our soldiers held)+ # Occupation (R-CTRL-011, R-CTRL-012; Q-OCC-1 (a) and Q-OCC-3 (a), owner, 18 October 2026, #783 batches 3 and 4: one unit+ # stays with Money upkeep per turn, one X for every place, both "labelled design values proposed by agents for owner+ # override"). Accepted by the owner on 22 October 2026 (https://github.com/eyalgolan/statecraft-israel/pull/1324#issuecomment-6338594839).+ # X is 6 monthly turns, half a year, the length of+ # build_yishuv_turns and veteran_halutz_service, so an occupation begun in the war ends well inside the game. The upkeep+ # is derived as held_soldier_cost_per_turn is (#751): one month of income_per_job_per_year (0.06 / 12) for the one+ # population unit that stays. Neither is a historical figure.+ occupation_turns: 6 # DESIGN VALUE: owner-set balance, not a historical figure (D-F4, Q-OCC-3: X, the turns every occupation lasts)+ occupation_upkeep_per_turn: 0.005 # DESIGN VALUE: owner-set balance, not a historical figure (D-F4, Q-OCC-1: IL millions a turn per occupied place)# Coalition stability lost by replacing a minister (Cabinet.Appoint): a seat taken from the minister's party, or a# reshuffle within it.appoint_stability_cost_other_party: 0.06diff --git a/docs/determinism.md b/docs/determinism.mdindex d308c86f1..3a603477e 100644--- a/docs/determinism.md+++ b/docs/determinism.md@@ -27,6 +27,12 @@ The simulation must produce the same state, bit for bit, on .NET, Unity Mono and- **Answering a capture (Raid and withdraw):** the units on the place leave in ascending id, each to the first free hex inthe fixed neighbour order, and the captures still waiting at the game's end resolve in ordinal id order, with no RNGdraw (R-CTRL-008, R-CTRL-010; `RaidTests.RaidDrawsNothing`). No golden captures a place, so none answers one.+- **Occupation timers (resolver step 10):** after step 9's arrivals and before objectives and score, each occupied place+ in ordinal id order pays its upkeep and counts its `turns=` down, or ends as a Raid when no Israeli military unit holds+ its hex, with no RNG draw (R-CTRL-011 to R-CTRL-013; `OccupyTests.TheTimerCountsDownInStepTen` and+ `OccupationDrawsNothing`). No golden occupies a place, so none moves. The `mvp-occupy-cost` golden is deferred by the+ owner's ruling of 22 October 2026 (#1324), and it is the next step now that a capture can be reached in play (#1314; a+ manifest golden plays the real content); `OccupyTests` plays the same run on fixture content.## Combat drawsdiff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex 80eb42b11..33a9de38b 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -42,7 +42,7 @@ R-CTRL-004: Resolver step 3 is the capture check, after combat (step 2), in ordiR-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 Occupy or Deport is not built yet (Phase 6 PRs 6 and 8). 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, 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 built yet (Phase 6 PR 8). 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.@@ -50,6 +50,12 @@ R-CTRL-009: `HistoricalAI` answers every capture awaiting the choice with Raid,R-CTRL-010: Raid and withdraw (Q-RAID-1 (a), owner, 18 October 2026, #783 batch 3). The player's units on the place's hex, soldiers and halutzim alike, leave in ascending id, each to the first neighbouring hex in the fixed neighbour order (R-MOVE-002) that is land, holds no enemy unit, is not an enemy-held locality (R-MOVE-005) and has room under the stack limit (R-MOVE-003). Leaving costs no movement points, and the units keep their orders, as after a `Move` that ends on another hex: a fortify is lost at the turn's order step (R-ORDER-002); both are defaults proposed on #797. The record is removed, so the place is under enemy control again at once, and its residents are unchanged. Raid changes nothing else: no resource, parameter, city, score or objective, and no RNG draw. If a unit has no such hex, Raid is refused with a reason and the state is unchanged, so the choice waits.+R-CTRL-011: Occupy (Q-OCC-1 (a), owner, 18 October 2026, #783 batch 3): `ResolveCapture(settlement, occupy)` keeps the place under the player's control. It needs an Israeli military unit on the place's hex, the one unit that stays (a halutz holds nothing, #796), and is refused with a reason otherwise, the state unchanged. It moves no unit. It changes the record's state to `occupied` and starts its timer (R-CTRL-012), and nothing else: no resident field (the place stays inhabited, R-CTRL-003), unit, resource, parameter, city, score or objective, so its preview (R-CTRL-008) is all zeros. Each turn's step 10, while the place is occupied or awaiting `EndOccupation`, the Treasury pays `mvp.occupation_upkeep_per_turn` for it, borrowing what it lacks (R-MONEY-003); the Occupy turn pays too. The upkeep is a design value accepted by the owner on 22 October 2026 (https://github.com/eyalgolan/statecraft-israel/pull/1324#issuecomment-6338594839): IL 0.005m, one month of `income_per_job_per_year` for the one population unit that stays, derived as `held_soldier_cost_per_turn` is. It comes on top of the garrison formation's own `military_upkeep_per_turn` (IL 0.05m, R-UNIT-010), so holding a place costs IL 0.055m a turn in all (owner ruling, 22 October 2026, https://github.com/eyalgolan/statecraft-israel/pull/1324#issuecomment-6341877796). Money is shown to one decimal of IL millions, so when the Treasury has to borrow for it the Why line shows the borrowed amount, at most IL 0.005m, as "IL 0.0m".++R-CTRL-012: The occupation timer (Q-OCC-3 (a), owner, 18 October 2026, #783 batch 4: one X for every place). Occupy sets the record's `Turns` to `mvp.occupation_turns`, X, a design value accepted by the owner on 22 October 2026 (https://github.com/eyalgolan/statecraft-israel/pull/1324#issuecomment-6338594839): 6 monthly turns. Resolver step 10, after step 9's arrivals and before objectives and score (step 11), takes each occupied place in ordinal id order and counts one turn off, the Occupy turn included; at 0 the place's state is `awaiting_end`, where it awaits `EndOccupation` (Phase 6 PR 7) and the count stops. `Turns` is written to the hash as `turns=` only when non-zero (R-CTRL-002). The step draws nothing from the RNG.++R-CTRL-013: Withdrawal before the timer ends (Q-OCC-2 (a), owner, 18 October 2026, #783 batch 3: allowed, and it becomes a Raid). An occupation lasts while an Israeli military unit is on the place's hex. When step 10 finds none on an occupied or `awaiting_end` place (the player moved them out, or they were lost), the occupation ends as a Raid does: the record is removed, so the place is under enemy control again at once, its residents unchanged, and no upkeep is paid that turn. Nothing else changes, and nothing is refunded. A halutz left on the hex keeps nothing.+## SavesR-SAVE-001: A save names the ruleset it was played under (`ruleset legacy` or `ruleset gdd-0.1`, save schema 2). A game refuses a save made under another ruleset. A schema 1 save has no ruleset line and is legacy, so the GDD game refuses it as made under earlier rules. The refusal carries a code (`older_rules`) the UI translates, and the sim's reason does not itself ask for a new game: the player reads that once (N4).diff --git a/sim/Statecraft.Sim.Tests/CaptureOptionsTests.cs b/sim/Statecraft.Sim.Tests/CaptureOptionsTests.csindex 863528239..c05acbe12 100644--- a/sim/Statecraft.Sim.Tests/CaptureOptionsTests.cs+++ b/sim/Statecraft.Sim.Tests/CaptureOptionsTests.cs@@ -32,17 +32,17 @@ public class CaptureOptionsTeststypeof(CaptureOption).GetProperties().Select(p => p.Name).OrderBy(x => x, StringComparer.Ordinal).ToArray());}- // R-CTRL-007, R-CTRL-008: only Raid is built in this PR. Occupy (PR 6) and Deport (PR 8) carry the "not built yet"+ // R-CTRL-007, R-CTRL-008: Raid (PR 5) and Occupy (PR 6, #798) are built. Deport (PR 8) carries the "not built yet"// refusal and no preview; a place not awaiting the choice offers nothing.[Fact]- public void OnlyRaidIsBuiltYet()+ public void OnlyRaidAndOccupyAreBuiltYet(){var c = Load();var s = Awaiting(c, "town_a");var options = SettlementControl.CaptureOptions(c, s, "town_a");- Assert.Null(options[0].Refusal);- Assert.NotNull(options[0].Preview);- Assert.All(options.Skip(1), o => { Assert.Contains("not built yet", o.Refusal); Assert.Null(o.Preview); });+ Assert.All(options.Take(2), o => { Assert.Null(o.Refusal); Assert.NotNull(o.Preview); });+ Assert.Contains("not built yet", options[2].Refusal);+ Assert.Null(options[2].Preview);Assert.Empty(SettlementControl.CaptureOptions(c, s, "town_c"));Assert.Empty(SettlementControl.CaptureOptions(c, s, "nowhere"));}diff --git a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs b/sim/Statecraft.Sim.Tests/DesignValuesTests.csindex 4a7d2e63d..589035834 100644--- a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs+++ b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs@@ -189,6 +189,9 @@ public class DesignValuesTests("rules.yaml", "mvp.prisoner_shortfall_cohesion"),("rules.yaml", "mvp.points_per_prisoner_unit_returned"),("rules.yaml", "mvp.held_soldier_cost_per_turn"),+ // Occupation (Phase 6 PR 6, #798; Q-OCC-1 (a), Q-OCC-3 (a)): proposed on #798 and #1324, accepted by the owner on 22 October 2026 (#1324).+ ("rules.yaml", "mvp.occupation_turns"),+ ("rules.yaml", "mvp.occupation_upkeep_per_turn"),}.Concat(CombatTableCells()).ToArray();/// <summary>rules.yaml mvp.combat_table, every cell: its five rows (below 1:2, 1:2, 1:1, 2:1, 3:1) with their start ratio@@ -295,6 +298,7 @@ public class DesignValuesTestsAssert.Equal((0.05, 6), (m.MilitaryUpkeepPerTurn, m.VeteranSoldierService)); // Q-GEN-1: owner-accepted initial design values (19 October 2026), not history.Assert.Equal((1, 5, 6), (m.ArmsPerAttack, m.CombatTable.Count, m.CombatTable[0].AttackerLoss.Count)); // #747 (D-G6, D-G3), accepted by the owner 20 Oct 2026Assert.Equal((1, 0.01, 10, 0.005), (m.FoodPerPrisonerUnit, m.PrisonerShortfallCohesion, m.PointsPerPrisonerUnitReturned, m.HeldSoldierCostPerTurn)); // #751 (Q-POW-2, Q-POW-4, Q-POW-5), accepted by the owner (owner, 21 October 2026, #751)+ Assert.Equal((6, 0.005), (m.OccupationTurns, m.OccupationUpkeepPerTurn)); // #798 (Q-OCC-1 (a), Q-OCC-3 (a)): proposed, for owner overrideAssert.Equal(12, c.Cities.Count);foreach (var x in c.Cities) // the listed housing and job values are the ones Cities.Init starts fromAssert.Equal(((int)x.Housing!.Value, (int)x.Jobs!.Value), (x.HousingCapacity, x.JobSlots));diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.csindex bdae1066b..a66e68909 100644--- a/sim/Statecraft.Sim.Tests/Fixture.cs+++ b/sim/Statecraft.Sim.Tests/Fixture.cs@@ -300,6 +300,8 @@ mvp:prisoner_shortfall_cohesion: 0.05points_per_prisoner_unit_returned: 7held_soldier_cost_per_turn: 0.5+ occupation_turns: 3+ occupation_upkeep_per_turn: 0.25combat_terrain_percent: { coastal_plain: 100, hills: 150, desert: 100 }combat_table:- { min_ratio_percent: 0, attacker_loss: [1, 1], defender_loss: [1, 1], defender_retreats: [0, 0] }diff --git a/sim/Statecraft.Sim.Tests/OccupyTests.cs b/sim/Statecraft.Sim.Tests/OccupyTests.csnew file mode 100644index 000000000..fe683601f--- /dev/null+++ b/sim/Statecraft.Sim.Tests/OccupyTests.cs@@ -0,0 +1,234 @@+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++/// <summary>Occupy, the occupation timer and withdrawal (GDD Phase 6 PR 6, #798). The owner's rulings of 18 October 2026+/// (#783, batches 3 and 4): Q-OCC-1 (a), one unit stays on the hex, with Money upkeep per turn and no effect on residents;+/// Q-OCC-2 (a), withdrawal before the timer ends is allowed and becomes a Raid; Q-OCC-3 (a), one X for every place. X and+/// the upkeep are design values proposed on #798. The places are CaptureTests' fixture values, not history, and the+/// fixture's X is 3 turns and its upkeep IL 0.25m a turn.</summary>+public class OccupyTests+{+ static Content Load() => CaptureTests.Load(CaptureTests.AllTargets);+ static Unit Soldier(int id, int q, int r) => CaptureTests.Soldier(id, q, r);++ /// <summary>A new game with <paramref name="units"/> and town_a captured and awaiting the choice.</summary>+ static GameState Awaiting(Content c, params Unit[] units)+ {+ var s = CombatTests.With(c, units);+ s.Settlements["town_a"] = new SettlementControl(Movement.PlayerSide, SettlementControl.AwaitingChoice, s.Date);+ return s;+ }++ static StepResult Step(Content c, GameState s, params Command[] commands) => Simulation.Step(c, s, commands);++ static ResolveCapture Occupy(string id = "town_a") => new ResolveCapture(id, SettlementControl.Occupy);++ /// <summary>The Money a state holds, the debt taken off: borrowing moves Money between the two and changes neither.</summary>+ static double Net(GameState s) => s.Treasury - s.Debt;++ // R-CTRL-011 (Q-OCC-1 (a)), R-CTRL-012: Occupy keeps the place under the player's control and starts the timer at X,+ // and this turn's step 10 already counts one turn off. Occupy moves no unit: the soldier and the halutz stay.+ [Fact]+ public void OccupyKeepsControlAndStartsTheTimer()+ {+ var c = Load();+ var s = Awaiting(c, Soldier(1, 1, 0), new Unit(2, "halutz", 1, 0));+ var result = Step(c, s, Occupy());+ Assert.Empty(result.Rejected);+ var ctrl = result.State.Settlements["town_a"];+ Assert.Equal((Movement.PlayerSide, SettlementControl.Occupied, 2), (ctrl.Owner, ctrl.State, ctrl.Turns));+ Assert.Equal((1, 0), (result.State.Units[1].Q, result.State.Units[1].R));+ Assert.Equal((1, 0), (result.State.Units[2].Q, result.State.Units[2].R));+ Assert.Contains("town_a=owner=israel,state=occupied,since=1948-05-15,turns=2", result.State.Describe());+ Assert.Contains(result.Why, x => x.Target == "town_a" && x.Message.Contains("is occupied"));+ }++ // R-CTRL-011 (Q-OCC-1 (a), "one unit stays on the hex"): Occupy needs an Israeli military unit on the place's hex; a+ // halutz holds nothing (#796). Refused with a reason, the state unchanged and the Attention refunded.+ [Fact]+ public void OccupyNeedsAnIsraeliMilitaryUnitOnTheHex()+ {+ var c = Load();+ var s = Awaiting(c, new Unit(2, "halutz", 1, 0), Soldier(1, 2, 0));+ var before = s.Clone();+ var why = new List<Cause>();+ Assert.Contains("needs an Israeli military unit", SettlementControl.Resolve(c, s, "town_a", SettlementControl.Occupy, why));+ Assert.Empty(why);+ Assert.Equal(before.Describe(), s.Describe());+ Assert.Contains("needs an Israeli military unit", Assert.Single(Step(c, before, Occupy()).Rejected).Reason);+ }++ // R-CTRL-011 (Q-OCC-1 (a), "Money upkeep per turn"): every turn the occupation lasts, the waiting for EndOccupation+ // included, costs mvp.occupation_upkeep_per_turn, and nothing else: the turn ends as the twin's with no record, less+ // the upkeep.+ [Fact]+ public void OccupationCostsTheUpkeepEachTurn()+ {+ var c = Load();+ var s = Step(c, Awaiting(c, Soldier(1, 1, 0)), Occupy()).State;+ var twin = CombatTests.With(c, Soldier(1, 1, 0));+ twin.Date = s.Date;+ Assert.Equal(Net(Step(c, twin).State) - 0.25, Net(s), 9); // the Occupy turn pays too+ for (int turn = 0; turn < 4; turn++) // two more turns of the timer, then two waiting for EndOccupation+ {+ var next = Step(c, s).State;+ var other = Step(c, Without(s)).State;+ Assert.Equal(Net(other) - 0.25, Net(next), 9);+ Assert.Equal((other.Food, other.Arms, other.Score, other.Indicators.GetValueOrDefault("morale"), other.Indicators.GetValueOrDefault("intl_standing")),+ (next.Food, next.Arms, next.Score, next.Indicators.GetValueOrDefault("morale"), next.Indicators.GetValueOrDefault("intl_standing")));+ s = next;+ }+ Assert.Equal(SettlementControl.AwaitingEnd, s.Settlements["town_a"].State);+ }++ /// <summary>A copy of <paramref name="s"/> with no settlement record: the twin a capture never happened in.</summary>+ static GameState Without(GameState s)+ {+ var t = s.Clone();+ t.Settlements.Clear();+ return t;+ }++ // R-CTRL-012 (Q-OCC-3 (a)): one X for every place. Step 10 counts each occupation down once a turn, and at 0 the place+ // awaits EndOccupation (PR 7) and the timer stops.+ [Fact]+ public void EveryPlaceAwaitsEndOccupationAfterXTurns()+ {+ var c = Load();+ var s = Awaiting(c, Soldier(1, 1, 0), Soldier(2, 4, 0));+ s.Settlements["town_c"] = new SettlementControl(Movement.PlayerSide, SettlementControl.AwaitingChoice, s.Date);+ var turns = new List<(int, int)>();+ var first = Step(c, s, Occupy("town_c"), Occupy());+ Assert.Empty(first.Rejected);+ s = first.State;+ turns.Add((s.Settlements["town_a"].Turns, s.Settlements["town_c"].Turns));+ for (int i = 0; i < 3; i++)+ {+ s = Step(c, s).State;+ turns.Add((s.Settlements["town_a"].Turns, s.Settlements["town_c"].Turns));+ }+ Assert.Equal(new[] { (2, 2), (1, 1), (0, 0), (0, 0) }, turns);+ Assert.All(s.Settlements.Values, x => Assert.Equal(SettlementControl.AwaitingEnd, x.State));+ Assert.Contains("town_a=owner=israel,state=awaiting_end,since=1948-05-15", s.Describe());+ }++ // R-CTRL-012, the resolver's order (D-A6): the timer runs in step 10, after step 9's arrivals. The occupation's last+ // soldier leaves this turn, and a brigade dated to this turn's end arrives on the place's hex in step 9 (R-UNIT-009), so+ // step 10 finds the hex held and counts down; run before step 9, it would find the hex empty and end the occupation.+ // The places tick in ordinal id order.+ [Fact]+ public void TheTimerCountsDownInStepTen()+ {+ var c = Load();+ var s = Awaiting(c, Soldier(1, 1, 0), Soldier(2, 4, 0));+ s.Settlements["town_c"] = new SettlementControl(Movement.PlayerSide, SettlementControl.AwaitingChoice, s.Date);+ var first = Step(c, s, Occupy("town_c"), Occupy());+ Assert.Equal(new[] { "town_a", "town_c" }, first.Why.Where(x => x.Message.Contains("turns of occupation left")).Select(x => x.Target));+ s = first.State;+ var next = Step(c, s).State;+ var id = c.StartingForces.Count; // R-UNIT-009: a dated row's unit takes its row's index as id+ c.StartingForces.Add(new StartingForce { Row = "late", Type = "soldier", Side = Movement.PlayerSide, Strength = 2, Q = 1, R = 0, Arrives = next.Date });+ var result = Step(c, s, new Move(1, 2, 0));+ Assert.Equal((1, 0), (result.State.Units[id].Q, result.State.Units[id].R));+ var ctrl = result.State.Settlements["town_a"];+ Assert.Equal((SettlementControl.Occupied, 1), (ctrl.State, ctrl.Turns));+ }++ // R-CTRL-013 (Q-OCC-2 (a)): withdrawal before the timer ends is allowed and becomes a Raid. The occupation lasts while+ // an Israeli military unit is on the hex; when step 10 finds none (the player moved them out), the record goes, the+ // place is under enemy control again with its residents unchanged, no upkeep is paid that turn and nothing else+ // changes: the turn ends as the twin's that never captured it.+ [Fact]+ public void WithdrawalBeforeTheTimerEndsIsARaid()+ {+ var c = Load();+ var s = Step(c, Awaiting(c, Soldier(1, 1, 0)), Occupy()).State;+ var result = Step(c, s, new Move(1, 2, 0));+ Assert.Empty(result.Rejected);+ 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());+ }++ // R-CTRL-013: a halutz left on the hex holds nothing (#796), so the occupation still ends.+ [Fact]+ public void AHalutzLeftBehindDoesNotKeepTheOccupation()+ {+ var c = Load();+ var s = Step(c, Awaiting(c, Soldier(1, 1, 0), new Unit(2, "halutz", 1, 0)), Occupy()).State;+ Assert.Empty(Step(c, s, new Move(1, 2, 0)).State.Settlements);+ }++ // R-CTRL-003, R-CTRL-011 (Q-OCC-1 (a), "no effect on residents"): Occupy and the occupation change the record's state+ // and timer and nothing else in it: the residents stay inhabited, and the combatants, buildings, owner and the capture+ // date stay as they were. Occupy itself changes nothing outside the record.+ [Fact]+ public void OccupationTouchesResidentsOnlyAsRuled()+ {+ var c = Load();+ var s = Awaiting(c, Soldier(1, 1, 0));+ var captured = s.Settlements["town_a"];+ var resolved = s.Clone();+ Assert.Null(SettlementControl.Resolve(c, resolved, "town_a", SettlementControl.Occupy, new List<Cause>()));+ Assert.Equal(Without(s).Describe(), Without(resolved).Describe());+ for (int i = 0; i < 5; i++)+ {+ s = Step(c, s, i == 0 ? new Command[] { Occupy() } : Array.Empty<Command>()).State;+ var x = s.Settlements["town_a"];+ Assert.Equal((captured.Owner, captured.Since, captured.Depopulated, captured.Combatants, captured.Buildings),+ (x.Owner, x.Since, x.Depopulated, x.Combatants, x.Buildings));+ }+ }++ // R-CTRL-007, R-CTRL-008: Occupy is built, so the options helper offers it with a preview, which is all zeros: Occupy+ // costs nothing at once (the upkeep is paid in step 10). Deport is still refused as not built yet.+ [Fact]+ public void OccupyIsOfferedWithItsPreview()+ {+ var c = Load();+ var options = SettlementControl.CaptureOptions(c, Awaiting(c, Soldier(1, 1, 0)), "town_a");+ var occupy = options.Single(o => o.Outcome == SettlementControl.Occupy);+ Assert.Null(occupy.Refusal);+ var p = occupy.Preview!;+ Assert.Equal((0.0, 0.0, 0.0, 0, 0, 0.0, 0.0, 0), (p.Attention, p.Money, p.Debt, p.Food, p.Arms, p.SocialCohesion, p.InternationalSupport, p.Score));+ Assert.Contains("not built yet", options.Single(o => o.Outcome == SettlementControl.Deport).Refusal);+ }++ // R-CTRL-007: an occupied place is no longer awaiting the capture choice, so a second ResolveCapture is refused.+ [Fact]+ public void AnOccupiedPlaceIsNotAnsweredAgain()+ {+ var c = Load();+ var s = Step(c, Awaiting(c, Soldier(1, 1, 0)), Occupy()).State;+ Assert.Contains("not awaiting a decision", Assert.Single(Step(c, s, new ResolveCapture("town_a", SettlementControl.Raid)).Rejected).Reason);+ }++ // Determinism: Occupy and the timer draw nothing from the RNG.+ [Fact]+ public void OccupationDrawsNothing()+ {+ var c = Load();+ var s = Awaiting(c, Soldier(1, 1, 0));+ var rng = s.RngState;+ Assert.Null(SettlementControl.Resolve(c, s, "town_a", SettlementControl.Occupy, new List<Cause>()));+ SettlementControl.Tick(c, s, c.RulesAt(s.Date).Mvp!, new List<Cause>());+ Assert.Equal(rng, s.RngState);+ }++ [Theory]+ [InlineData("occupation_turns: 3", "", "mvp.occupation_turns", "required")]+ [InlineData("occupation_turns: 3", "occupation_turns: 0", "mvp.occupation_turns", "must be >= 1")]+ [InlineData("occupation_upkeep_per_turn: 0.25", "", "mvp.occupation_upkeep_per_turn", "required")]+ [InlineData("occupation_upkeep_per_turn: 0.25", "occupation_upkeep_per_turn: -1", "mvp.occupation_upkeep_per_turn", "must be a finite number >= 0")]+ public void BadValuesFailNamingTheField(string from, string to, string field, string message)+ {+ var files = Fixture.Gdd();+ files["rules.yaml"] = files["rules.yaml"].Replace(from, to);+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(files)));+ Assert.Equal(("rules.yaml", field), (ex.File, ex.Field));+ Assert.Contains(message, ex.Message);+ }+}diff --git a/sim/Statecraft.Sim.Tests/RaidTests.cs b/sim/Statecraft.Sim.Tests/RaidTests.csindex 45276d81a..29a942747 100644--- a/sim/Statecraft.Sim.Tests/RaidTests.cs+++ b/sim/Statecraft.Sim.Tests/RaidTests.cs@@ -91,7 +91,6 @@ public class RaidTests[InlineData("town_c", "raid", "not awaiting a decision")] // a target with no record[InlineData("nowhere", "raid", "not awaiting a decision")] // not a settlement[InlineData("town_a", "surrender", "not known")]- [InlineData("town_a", "occupy", "not built yet")][InlineData("town_a", "deport", "not built yet")]public void ResolveCaptureIsRefusedWithAReason(string id, string outcome, string reason){diff --git a/sim/Statecraft.Sim.Tests/SettlementStateTests.cs b/sim/Statecraft.Sim.Tests/SettlementStateTests.csindex 81935ede8..9651afac8 100644--- a/sim/Statecraft.Sim.Tests/SettlementStateTests.cs+++ b/sim/Statecraft.Sim.Tests/SettlementStateTests.cs@@ -48,9 +48,10 @@ public class SettlementStateTestspublic void ResidentsAreNotCombatants(){var properties = typeof(SettlementControl).GetProperties(BindingFlags.Instance | BindingFlags.Public);- // Q-CAP-2 (b): the residents are one yes/no state, not a count; the only count on the record is the combatants.+ // Q-CAP-2 (b): the residents are one yes/no state, not a count; the only count of people on the record is the+ // combatants. Turns is the occupation timer (R-CTRL-012), a count of turns.Assert.Equal(typeof(bool), properties.Single(x => x.Name == nameof(SettlementControl.Depopulated)).PropertyType);- Assert.Equal(new[] { nameof(SettlementControl.Combatants) },+ Assert.Equal(new[] { nameof(SettlementControl.Combatants), nameof(SettlementControl.Turns) },properties.Where(x => x.PropertyType == typeof(int) || x.PropertyType == typeof(long) || x.PropertyType == typeof(double)).Select(x => x.Name).ToArray());Assert.DoesNotContain(properties, x => x.Name.Contains("Resident", StringComparison.Ordinal) || x.Name.Contains("Population", StringComparison.Ordinal));}diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.csindex 17e88ee34..9fff2362b 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -653,6 +653,12 @@ namespace Statecraft.Sim/// <summary>IL millions the Treasury pays a turn for each population unit of the player's soldiers held (R-POW-005;/// Q-POW-4). Required in the GDD loop, >= 0.</summary>public double? HeldSoldierCostPerTurn { get; set; }+ /// <summary>X, the turns every occupation lasts before the place awaits EndOccupation (R-CTRL-012; Q-OCC-3 (a), one X+ /// for every place). Required in the GDD loop, >= 1.</summary>+ public int? OccupationTurns { get; set; }+ /// <summary>IL millions the Treasury pays a turn for each occupied place (R-CTRL-011; Q-OCC-1 (a)). Required in the GDD+ /// loop, >= 0.</summary>+ public double? OccupationUpkeepPerTurn { get; set; }}/// <summary>One row of rules.yaml mvp.combat_table (R-COMBAT-002, R-COMBAT-003): it applies from an attack : defencediff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex 587a041a8..f1a93cbad 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -1294,7 +1294,11 @@ namespace Statecraft.Simif (v == null) throw new ContentException(file, "mvp." + key, "required when eras.yaml systems.loop is gdd");if (v < 0) throw new ContentException(file, "mvp." + key, "must be >= 0");}- foreach (var (key, v) in new[] { ("prisoner_shortfall_cohesion", m.PrisonerShortfallCohesion), ("held_soldier_cost_per_turn", m.HeldSoldierCostPerTurn) })+ // R-CTRL-011, R-CTRL-012 (Q-OCC-1 (a), Q-OCC-3 (a)): required, so a missing key is never read as an occupation+ // that never ends or costs nothing.+ if (m.OccupationTurns == null) throw new ContentException(file, "mvp.occupation_turns", "required when eras.yaml systems.loop is gdd");+ if (m.OccupationTurns < 1) throw new ContentException(file, "mvp.occupation_turns", "must be >= 1");+ foreach (var (key, v) in new[] { ("prisoner_shortfall_cohesion", m.PrisonerShortfallCohesion), ("held_soldier_cost_per_turn", m.HeldSoldierCostPerTurn), ("occupation_upkeep_per_turn", m.OccupationUpkeepPerTurn) }){if (v == null) throw new ContentException(file, "mvp." + key, "required when eras.yaml systems.loop is gdd");if (!(v >= 0 && IsFinite(v.Value))) throw new ContentException(file, "mvp." + key, "must be a finite number >= 0");diff --git a/sim/Statecraft.Sim/GddState.cs b/sim/Statecraft.Sim/GddState.csindex 4a62dc134..0467ef9f7 100644--- a/sim/Statecraft.Sim/GddState.cs+++ b/sim/Statecraft.Sim/GddState.cs@@ -16,10 +16,13 @@ namespace Statecraft.Simpublic bool Depopulated { get; }public int Combatants { get; }public string Buildings { get; }+ /// <summary>The occupation's turns left (R-CTRL-012): X when Occupy is given, counted down in resolver step 10; 0 when+ /// the place is not occupied or its timer has ended.</summary>+ public int Turns { get; }- public SettlementControl(string owner = "", string state = "", DateTime since = default, bool depopulated = false, int combatants = 0, string buildings = "")+ public SettlementControl(string owner = "", string state = "", DateTime since = default, bool depopulated = false, int combatants = 0, string buildings = "", int turns = 0){- Owner = owner; State = state; Since = since; Depopulated = depopulated; Combatants = combatants; Buildings = buildings;+ Owner = owner; State = state; Since = since; Depopulated = depopulated; Combatants = combatants; Buildings = buildings; Turns = turns;}public string Canonical()@@ -31,6 +34,7 @@ namespace Statecraft.Simif (Depopulated) fields.Add("depopulated=1");if (Combatants != 0) fields.Add("combatants=" + Combatants.ToString(CultureInfo.InvariantCulture));if (Buildings != "") fields.Add("buildings=" + Buildings);+ if (Turns != 0) fields.Add("turns=" + Turns.ToString(CultureInfo.InvariantCulture));return string.Join(",", fields);}}diff --git a/sim/Statecraft.Sim/SettlementControl.cs b/sim/Statecraft.Sim/SettlementControl.csindex 156b05bdf..11c0a90d4 100644--- a/sim/Statecraft.Sim/SettlementControl.cs+++ b/sim/Statecraft.Sim/SettlementControl.cs@@ -12,6 +12,10 @@ namespace Statecraft.Sim{/// <summary>The <see cref="State"/> of a target the player has captured and has not yet chosen an outcome for.</summary>public const string AwaitingChoice = "awaiting_choice";+ /// <summary>The <see cref="State"/> of a place the player occupies while its timer runs (R-CTRL-011, R-CTRL-012).</summary>+ public const string Occupied = "occupied";+ /// <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@@ -75,14 +79,14 @@ namespace Statecraft.Simstatic double Indicator(GameState s, string id) => s.Indicators.TryGetValue(id, out var v) ? v : 0;/// <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 it is not built yet (Occupy is PR 6, Deport PR 8).</summary>+ /// is not awaiting the choice, the outcome is not known, or it is not built yet (Deport is PR 8).</summary>internal static string? Resolve(Content c, GameState s, string id, string outcome, List<Cause> why){if (NotAwaiting(s, id) is string no) return no;switch (outcome){case Raid: return Withdraw(c, s, id, why, false);- case Occupy: return "Occupy is not built yet";+ case Occupy: return StartOccupation(c, s, id, why);case Deport: return "Deport is not built yet";default: return "That outcome is not known";}@@ -124,6 +128,25 @@ namespace Statecraft.Simreturn null;}+ /// <summary>R-CTRL-011, R-CTRL-012 (Q-OCC-1 (a), Q-OCC-3 (a)): Occupy keeps the place under the player's control and+ /// 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)+ {+ 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}";+ 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);+ why.Add(new Cause("map", id, turns, FormattableString.Invariant($"{name} is occupied for {turns} turns: an Israeli unit stays there. Its residents are unchanged")));+ return null;+ }++ /// <summary>Whether an Israeli military unit is on <paramref name="t"/>'s hex (a halutz has no side, R-UNIT-001).</summary>+ static bool Garrisoned(GameState s, SettlementTarget t) => s.Units.Values.Any(u => u.Q == t.Q && u.R == t.R && u.Side == Movement.PlayerSide);+static bool IsEnemy(Unit u) => u.Side != "" && u.Side != Movement.PlayerSide;static bool Free(Content c, GameState s, Unit u, int q, int r) =>@@ -143,6 +166,34 @@ namespace Statecraft.Sim}}+ /// <summary>Resolver step 10, the occupation timers, in ordinal id order (R-CTRL-011 to R-CTRL-013). An occupied place+ /// with no Israeli military unit left on its hex has been withdrawn from before the timer ended, which is a Raid+ /// (Q-OCC-2 (a)): its record goes, so it is under enemy control again, its residents unchanged, and nothing is paid.+ /// Every other occupation pays mvp.occupation_upkeep_per_turn (Q-OCC-1 (a)), the wait for EndOccupation included, and a+ /// running timer counts one turn down; at 0 the place awaits EndOccupation (Phase 6 PR 7). It draws nothing from the+ /// RNG.</summary>+ internal static void Tick(Content c, GameState s, MvpRules r, List<Cause> why)+ {+ foreach (var id in s.Settlements.Where(kv => kv.Value.State == Occupied || kv.Value.State == AwaitingEnd).Select(kv => kv.Key).ToList()) // ordinal+ {+ var x = s.Settlements[id];+ var name = c.SettlementNames[id];+ if (!Garrisoned(s, c.SettlementTargets.First(t => t.Id == id)))+ {+ s.Settlements.Remove(id);+ why.Add(new Cause("map", id, 0, $"{name}: no Israeli unit holds it any more, so the occupation ended as a raid. It is under enemy control again. Its residents are unchanged"));+ continue;+ }+ EconomySystem.PayOrBorrow(c, s, r.OccupationUpkeepPerTurn!.Value, $"for the occupation of {name}", why);+ if (x.State == AwaitingEnd) continue;+ var left = x.Turns - 1;+ s.Settlements[id] = new SettlementControl(x.Owner, left == 0 ? AwaitingEnd : Occupied, x.Since, x.Depopulated, x.Combatants, x.Buildings, left);+ why.Add(new Cause("map", id, left, left == 0+ ? $"{name}: the occupation period has ended. It awaits a decision"+ : FormattableString.Invariant($"{name}: {left} turns of occupation left")));+ }+ }+const string Enemy = "enemy";/// <summary>Who holds (q, r): <see cref="Movement.PlayerSide"/> when only Israeli military units are on it,diff --git a/sim/Statecraft.Sim/TurnResolver.cs b/sim/Statecraft.Sim/TurnResolver.csindex fcdda6d2e..a06cca78f 100644--- a/sim/Statecraft.Sim/TurnResolver.cs+++ b/sim/Statecraft.Sim/TurnResolver.cs@@ -33,9 +33,8 @@ namespace Statecraft.SimCities.UpdateCondition(c, s, r, why);Cities.Arrive(c, s, r, next, why); // 9. arrivalsStartingForces.Arrive(c, s, next); // and the brigades dated after the start (R-UNIT-009)- // 10. Occupation timers: Phase 6 PR 6. On the turn that reaches the game's end, a capture still awaiting the choice- // counts as Raid (R-CTRL-008, #797).- if (next >= c.End) SettlementControl.EndPending(c, s, why);+ SettlementControl.Tick(c, s, r, why); // 10. occupation timers, in ordinal settlement id (R-CTRL-011 to R-CTRL-013)+ if (next >= c.End) SettlementControl.EndPending(c, s, why); // and on the turn that reaches the game's end, a capture still awaiting the choice counts as Raid (R-CTRL-008, #797)Objectives.Complete(c, s, r, next, why); // 11. objectives and scoreDefeat(s, r, why); // then the economic defeat (D-B5, R-END-002)WarLoss(c, s, why); // and the war loss (R-END-003)