A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: artillery's combat role and the armoured car (GDD Phase 5 PR 9, part 1; refs #748) (#1245)
Berif5fbc9a127bb
diff --git a/changelog.d/sim-gdd-artillery-armour.md b/changelog.d/sim-gdd-artillery-armour.mdnew file mode 100644index 000000000..cacfe764e--- /dev/null+++ b/changelog.d/sim-gdd-artillery-armour.md@@ -0,0 +1,5 @@+- Artillery has its own combat role (GDD Phase 5 PR 9, part 1; #748). It supports an attack on an enemy hex up to two+ hexes away, fires only beside another attacking unit, spends 2 Arms a firing, counts at 200% of its strength and+ takes none of the attackers' losses; it cannot hold ground. The armoured car fights at 150%. The numbers are design+ values the owner accepted on 21 October 2026 (#748; R-COMBAT-007, R-COMBAT-008), together with three mechanics: the+ losses sparing the guns, no hold for artillery, and the 200% counting on defence too.diff --git a/content/unit_types.yaml b/content/unit_types.yamlindex c7b12eb6c..a0b2ae62f 100644--- a/content/unit_types.yaml+++ b/content/unit_types.yaml@@ -37,11 +37,21 @@ types:side: israelclass: artillerymovement_points: 2 # DESIGN VALUE: owner-set balance, not a historical figure (D-G2, Q-MOVE-1: points a turn)+ # Artillery's combat role (R-COMBAT-007; Q-ARTY-1, owner, 15 October 2026: "Take all recommendations"). Proposed on+ # #748 (https://github.com/eyalgolan/statecraft-israel/issues/748#issuecomment-6315145696) and accepted by the owner+ # as design values on 21 October 2026 (https://github.com/eyalgolan/statecraft-israel/issues/748#issuecomment-6317339304).+ # Range 2 is the smallest that differs from an infantry attack: the guns stand one hex behind the unit that attacks.+ # At about 8.7 km a hex it is a game value, not a gun's reach. A firing costs twice an infantry attack's Arms.+ range: 2 # DESIGN VALUE: owner-set balance, not a historical figure (D-G5, Q-ARTY-1: hexes to the hex it supports an attack on)+ arms_per_fire: 2 # DESIGN VALUE: owner-set balance, not a historical figure (D-G6, Q-ARTY-1: Arms each firing spends)+ combat_percent: 200 # DESIGN VALUE: owner-set balance, not a historical figure (D-G5, Q-ARTY-1: percent of its strength in combat)- id: armoured_carkind: unitside: israelclass: armourmovement_points: 5 # DESIGN VALUE: owner-set balance, not a historical figure (D-G2, Q-MOVE-1, Q-ARTY-2: points a turn)+ # R-COMBAT-008 (Q-ARTY-2): its own combat factor and no other rule. Accepted by the owner on #748, 21 October 2026.+ combat_percent: 150 # DESIGN VALUE: owner-set balance, not a historical figure (D-G5, Q-ARTY-2: percent of its strength in combat)# The Arab forces' types (Phase 5 PR 4, R-UNIT-006; #743, owner, 20 October 2026: "one labelled design-value infantry type# per Arab side that has a row, 3 movement points"). One type per side whose units_1948.yaml rows start a unit; the# Lebanese row is hidden, and the local forces have no row yet. The ids are the sim's, not names shown to the player (thosediff --git a/docs/rules/mvp.md b/docs/rules/mvp.mdindex ae6c49d18..414b915b6 100644--- a/docs/rules/mvp.md+++ b/docs/rules/mvp.md@@ -182,7 +182,7 @@ R-MOVE-007: Roads and rail are cheaper (D-G2; Phase 5 PR 6, #745). A step into aPhase 5 PR 7 (#746). Q-HOLD-1, "(a) 1 turn, free, lost on move", and Q-HOLD-2, "(a) Own hex, no interception" (owner, 15 October 2026, #375). The two percents are design values this PR proposes from avlco's option 1 on #746; the owner may override them.-R-ORDER-001: `UnitOrder(unit, order)` gives one of the player's military units the standing order `fortify` or `hold`, replacing the one it had. The unit keeps its order, turn after turn, until the player gives another; moving clears fortify (Q-HOLD-1): in the resolver after combat (step 2), in id order, a unit no longer on the hex its fortify names (`OrderTarget`, "q,r") loses the order. The order is refused with the state unchanged and a reason for an unknown order or unit, a unit with no side (a halutz), a unit of another side, or the order the unit already has (fortify on the hex it fortifies). It costs `attention_cost.unit_order` (0, D-A6) and is refused in the legacy loop.+R-ORDER-001: `UnitOrder(unit, order)` gives one of the player's military units the standing order `fortify` or `hold`, replacing the one it had. The unit keeps its order, turn after turn, until the player gives another; moving clears fortify (Q-HOLD-1): in the resolver after combat (step 2), in id order, a unit no longer on the hex its fortify names (`OrderTarget`, "q,r") loses the order. The order is refused with the state unchanged and a reason for an unknown order or unit, a unit with no side (a halutz), a unit of another side, a hold for artillery (R-COMBAT-007), or the order the unit already has (fortify on the hex it fortifies). It costs `attention_cost.unit_order` (0, D-A6) and is refused in the legacy loop.R-ORDER-002: Fortify takes one turn to set and costs no Arms or Money (Q-HOLD-1). Given, it reads `fortifying` and names the unit's hex; in the same resolver step it becomes `fortify`, so the combat of the turn it is given sees no bonus. A fortified unit on its hex defends at `mvp.fortify_defence_percent` of its strength (`Orders.DefencePercent`; real value 125), and from the moment it leaves the hex at 100.@@ -192,18 +192,24 @@ R-ORDER-003: Hold acts on the unit's own hex only and does not intercept or stopPhase 5 PR 8 (#747). Q-COMBAT-1 to Q-COMBAT-4 are the plan's recommendations (owner, 15 October 2026, #375: "Take all recommendations"); Q-CIV-2 is the owner's "Enemy units only, no effect" and Q-CIV-4 his "2+3". The numbers (`rules.yaml` `mvp.arms_per_attack`, `mvp.combat_terrain_percent`, `mvp.combat_table`), the loss order, the retreat order and the attack's standing are agent defaults asked on #747 (https://github.com/eyalgolan/statecraft-israel/issues/747#issuecomment-6297295556) and accepted by the owner on 20 October 2026, all six, as design values for the balance pass #813 (https://github.com/eyalgolan/statecraft-israel/issues/747#issuecomment-6299184133). The truce refusal (Q-WAR-3) is PR 11, prisoners PR 12, artillery PR 9 and the enemy's orders PR 10.-R-COMBAT-001: `UnitOrder(unit, attack, q, r)` gives one of the player's military units a standing attack on the hex (q, r), replacing its order (a fortify is lost). The hex must be next to the unit and hold an enemy military unit; enemy units on a hex with a locality and its residents may be attacked, and the residents are never a target (Q-CIV-2). The order is refused with the state unchanged and a reason for an unknown unit, a halutz, a unit of another side, no hex, the attack it already has, a hex not next to it or with no enemy unit, or a stock below the Arms of this attack plus the player's other attacks already ordered, this turn's included (Q-COMBAT-4). Fortify and hold name no hex: one that names a hex is refused. The order costs `attention_cost.unit_order` (0, D-A6) and resolves in the same turn's step 2. It stands, turn after turn, while its hex holds an enemy unit next to the unit; in step 2 an attack whose hex is empty or no longer next to the unit ends, with a line, and so does every attack whose hex step 2 leaves empty. A save writes it as `order <unit> attack <q> <r>`; a scenario takes `q` and `r`.+R-COMBAT-001: `UnitOrder(unit, attack, q, r)` gives one of the player's military units a standing attack on the hex (q, r), replacing its order (a fortify is lost). The hex must be next to the unit (artillery: within its range, R-COMBAT-007) and hold an enemy military unit; enemy units on a hex with a locality and its residents may be attacked, and the residents are never a target (Q-CIV-2). The order is refused with the state unchanged and a reason for an unknown unit, a halutz, a unit of another side, no hex, the attack it already has, a hex not next to it (artillery: beyond its range) or with no enemy unit, or a stock below the Arms of this attack plus the player's other attacks already ordered, this turn's included (Q-COMBAT-4). Fortify and hold name no hex: one that names a hex is refused. The order costs `attention_cost.unit_order` (0, D-A6) and resolves in the same turn's step 2. It stands, turn after turn, while its hex holds an enemy unit next to the unit (artillery: in its range, R-COMBAT-007); in step 2 an attack whose hex is empty or no longer next to the unit (artillery: in its range) ends, with a line, and so does every attack whose hex step 2 leaves empty. A save writes it as `order <unit> attack <q> <r>`; a scenario takes `q` and `r`.-R-COMBAT-002: Resolver step 2 resolves the attacks of both sides in ascending attacker id: the lowest-id unit with an attack not yet in an engagement leads one, with every unit of its side attacking the same hex (Israel on one side, every Arab side on the other). The attackers' strengths are summed (Q-COMBAT-2); each defender's strength is multiplied by its order's defence percent (`Orders.DefencePercent`: fortify 125, R-ORDER-002) and by `mvp.combat_terrain_percent` for its hex's biome (real values: hills 125, mountains 150, every other land biome 100). The ratio is attack over defence in whole percent, rounded down, in integers only; the row of `mvp.combat_table` is the last whose `min_ratio_percent` it reaches (real rows: below 1:2, 1:2, 1:1, 2:1, 3:1). Each engagement draws exactly one RNG value, a face of the row (six in the real table), whatever its outcome; a step 2 with no engagement draws nothing (docs/determinism.md, "Combat draws"). `Combat.Preview(c, s, unit, q, r)` gives the ratio and row the UI shows (Q-UI-1; spec §2.6), counting the unit and the units of its side already attacking that hex.+R-COMBAT-002: Resolver step 2 resolves the attacks of both sides in ascending attacker id: the lowest-id unit with an attack not yet in an engagement leads one, with every unit of its side attacking the same hex (Israel on one side, every Arab side on the other). Each unit's strength is first multiplied by its type's `combat_percent` (R-COMBAT-007, R-COMBAT-008). The attackers' strengths are summed (Q-COMBAT-2); each defender's strength is multiplied by its order's defence percent (`Orders.DefencePercent`: fortify 125, R-ORDER-002) and by `mvp.combat_terrain_percent` for its hex's biome (real values: hills 125, mountains 150, every other land biome 100). The ratio is attack over defence in whole percent, rounded down, in integers only; the row of `mvp.combat_table` is the last whose `min_ratio_percent` it reaches (real rows: below 1:2, 1:2, 1:1, 2:1, 3:1). Each engagement draws exactly one RNG value, a face of the row (six in the real table), whatever its outcome; a step 2 with no engagement draws nothing (docs/determinism.md, "Combat draws"). `Combat.Preview(c, s, unit, q, r)` gives the ratio and row the UI shows (Q-UI-1; spec §2.6), counting the unit and the units of its side already attacking that hex.-R-COMBAT-003: The face gives the population units each side loses and whether the defenders retreat. Losses fall one unit at a time on the side's strongest unit in the engagement (a tie on the lower id); a unit at 0 is destroyed and leaves the state, and its id is never reused (`NextId` does not move). When the face says retreat, each defender left, in id order, moves one hex to the first neighbour in the fixed order (R-MOVE-002) that is land, holds no unit of the other side, has room for its side under `mvp.stack_limit`, and, for a player's unit, is not an enemy-held locality (R-MOVE-005). A defender with no such hex surrenders and leaves the state: the only way a unit is captured (impact plan §4.3 item 1; its prisoners are PR 12). The attackers never advance into the hex (Q-COMBAT-3).+R-COMBAT-003: The face gives the population units each side loses and whether the defenders retreat. Losses fall one unit at a time on the side's strongest unit in the engagement (a tie on the lower id; the attackers' losses spare their artillery, R-COMBAT-007); a unit at 0 is destroyed and leaves the state, and its id is never reused (`NextId` does not move). When the face says retreat, each defender left, in id order, moves one hex to the first neighbour in the fixed order (R-MOVE-002) that is land, holds no unit of the other side, has room for its side under `mvp.stack_limit`, and, for a player's unit, is not an enemy-held locality (R-MOVE-005). A defender with no such hex surrenders and leaves the state: the only way a unit is captured (impact plan §4.3 item 1; its prisoners are PR 12). The attackers never advance into the hex (Q-COMBAT-3).-R-COMBAT-004: Each of the player's units pays `mvp.arms_per_attack` (real value 1) from the Arms stock when it joins an engagement; one the stock cannot pay for has its attack called off, with a line naming the need and the stock. Enemy units pay nothing (Q-ENEMY-4: no supply).+R-COMBAT-004: Each of the player's units pays `mvp.arms_per_attack` (real value 1; artillery pays its `arms_per_fire` instead, R-COMBAT-007) from the Arms stock when it joins an engagement; one the stock cannot pay for has its attack called off, with a line naming the need and the stock. Enemy units pay nothing (Q-ENEMY-4: no supply).R-COMBAT-005: Combat changes only combatant units and the Arms. No city, locality, resident, building, job or other resource, and no score, changes because of a combat outcome (Q-CIV-2; impact plan §4.3: kills and enemy losses never score). Halutzim are never attackers or targets.R-COMBAT-006: Each engagement's Why line names the hex, the units on each side and the ratio, and states "the attackers lost N people and the defenders lost M people", the strength each side lost times `people_per_unit`, in the same words whichever side attacks (Q-CIV-4; impact plan §4.2). A destroyed unit gets "Unit N was destroyed", a retreat the hex it went to, a surrender the people it surrendered with. No running count of losses is kept; the war's Israeli total is PR 13's.+Phase 5 PR 9, part 1 (#748): artillery's combat role and the armoured car. Q-ARTY-1 and Q-ARTY-2 are the plan's recommendations (owner, 15 October 2026, #375: "Take all recommendations"). The numbers in `unit_types.yaml` are agent defaults proposed on #748 and accepted by the owner as design values on 21 October 2026, together with three of R-COMBAT-007's mechanics that the Q-ARTY-1 text does not settle: the attackers' losses sparing the guns, the hold refused as "never holds ground", and the 200% counting on defence too (owner, 21 October 2026, #748, https://github.com/eyalgolan/statecraft-israel/issues/748#issuecomment-6317339304). How either type is acquired (R-UNIT-008) is part 2, on top of Phase 5 PR 3's training.++R-COMBAT-007: Artillery (a type of class `artillery`, which needs a `range` and an `arms_per_fire`; real values 2 and 2) supports attacks from range. Its `UnitOrder(unit, attack, q, r)` names an enemy hex at a hex distance of 1 to its `range`; a farther hex is refused with "That hex is beyond the unit's range". In step 2 it joins an engagement after the other attackers of its side, and only when at least one of them joins: otherwise it holds its fire, with a line, pays nothing and keeps its order. When it joins it pays its type's `arms_per_fire` in place of `mvp.arms_per_attack` (R-COMBAT-004 otherwise: refused at the order and called off in step 2 when the stock is short), and its strength counts at its `combat_percent` (real value 200). The attackers' losses fall on the other attackers only; artillery that is attacked defends and takes losses like any unit. It never holds ground: a hold order for it is refused with "Artillery does not hold ground" (fortify is allowed). As in any attack, residents are never a target (Q-CIV-2, R-COMBAT-005).++R-COMBAT-008: A military type may carry a `combat_percent` (at least 1; none is 100): its units' strength counts at that percent in the ratio, attacking and defending, in integers (R-COMBAT-002). The armoured car's is 150 (real value), with its 5 movement points (R-MOVE-001) and no other rule (Q-ARTY-2).+## ObjectivesR-OBJ-001: An objective (`objectives.yaml`) names its condition, `completes_when: { site_built: <site> }` (R-OBJ-004's `absorbed` has no site, so the site rules here apply only to `site_built`), a designated site of kind yishuv whose `founded` date must equal the objective's `reference_date`. In the last step of each GDD turn (spec §2.3, step 11; D-A6), in id order, an objective whose site is built and that is not yet recorded is recorded once, with the turn's end date (the site's `BuiltOn`). Recording it again, or in the legacy loop, changes nothing; a stopped build completes nothing.diff --git a/sim/Statecraft.Sim.Tests/ArtilleryTests.cs b/sim/Statecraft.Sim.Tests/ArtilleryTests.csnew file mode 100644index 000000000..7b44ce057--- /dev/null+++ b/sim/Statecraft.Sim.Tests/ArtilleryTests.cs@@ -0,0 +1,170 @@+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++/// <summary>Artillery's combat role and the armoured car (GDD Phase 5 PR 9, part 1; #748). Q-ARTY-1 and Q-ARTY-2 are the+/// plan's recommendations, taken by the owner on 15 October 2026 ("Take all recommendations", #375): artillery adds its+/// strength to an attack on a hex within its range, never attacks alone or holds ground, and spends Arms when it fires; the+/// armoured car has its own combat factor and no other special rule. The fixture's numbers are fixture values: a gun with+/// range 2, 3 Arms a firing and a factor of 200, a car with a factor of 150, and CombatTests' table (below 2:1 both sides+/// lose 1, from 2:1 the defenders lose 1 and retreat), so a test does not depend on the draw.</summary>+public class ArtilleryTests+{+ const string Types = Fixture.GddUnitTypes+ + " - { id: soldier, kind: unit, side: israel, class: infantry, movement_points: 3 }\n"+ + " - { id: gun, kind: unit, side: israel, class: artillery, movement_points: 2, range: 2, arms_per_fire: 3, combat_percent: 200 }\n"+ + " - { id: car, kind: unit, side: israel, class: armour, movement_points: 5, combat_percent: 150 }\n"+ + " - { id: enemy, kind: unit, side: egypt, class: infantry, movement_points: 3 }\n";++ /// <summary>MovementTests' 6 x 3 coastal plain; town_a is on (1, 0).</summary>+ static Content Load(string types = Types) => ContentLoader.Load(Fixture.Write(Fixture.Gdd(new Dictionary<string, string>+ {+ ["unit_types.yaml"] = types, ["map/hexes.json"] = MovementTests.Board(), ["corridors.yaml"] = "corridors: []\n"+ })));++ static Unit Of(string type, int id, int q, int r, int strength, string side = "israel") => new Unit(id, type, q, r, side: side, strength: strength);+ static Unit Enemy(int id, int q, int r, int strength) => Of("enemy", id, q, r, strength, "egypt");+ static Unit Attacking(Unit u, int q, int r) =>+ new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, Combat.Attack, FormattableString.Invariant($"{q},{r}"));++ static StepResult Step(Content c, GameState s, params Command[] cmds) => Simulation.Step(c, s, cmds);++ // R-COMBAT-007: the guns take an attack on an enemy hex within their range, two hexes here; beyond it the order is+ // refused, the state untouched. An infantry unit still needs the hex next to it.+ [Fact]+ public void ArtilleryTakesAnAttackOnAHexWithinItsRange()+ {+ var c = Load();+ var s = CombatTests.With(c, Of("gun", 1, 4, 0, 2), Of("soldier", 3, 4, 1, 2), Enemy(2, 2, 0, 3), Enemy(4, 1, 0, 3));+ Assert.Empty(Step(c, s, new UnitOrder(1, Combat.Attack, 2, 0)).Rejected);+ var refused = Step(c, s, new UnitOrder(1, Combat.Attack, 1, 0)); // three hexes away+ Assert.Equal("That hex is beyond the unit's range", Assert.Single(refused.Rejected).Reason);+ Assert.Equal(Step(c, s).State.Hash(), refused.State.Hash());+ Assert.Equal("That hex is not next to the unit", Assert.Single(Step(c, s, new UnitOrder(3, Combat.Attack, 2, 0)).Rejected).Reason);+ }++ // R-COMBAT-007: artillery never attacks alone. With no other unit of its side attacking the hex, it holds its fire: no+ // draw, no Arms, no loss, a line, and the order stands for a later turn.+ [Fact]+ public void ArtilleryAloneHoldsItsFire()+ {+ var c = Load();+ var s = CombatTests.With(c, Of("gun", 1, 4, 0, 2), Enemy(2, 2, 0, 3));+ var r = Step(c, s, new UnitOrder(1, Combat.Attack, 2, 0));+ Assert.Empty(r.Rejected);+ Assert.Equal(3, r.State.Units[2].Strength);+ Assert.Equal(s.Arms, r.State.Arms);+ Assert.Equal(Step(c, s).State.RngState, r.State.RngState);+ Assert.Equal((Combat.Attack, "2,0"), (r.State.Units[1].Order, r.State.Units[1].OrderTarget));+ Assert.Contains(r.Why, w => w.Message == "Unit 1 holds its fire: no attack on hex 2,0 to support");+ }++ // R-COMBAT-007: in support, the guns add their strength times their factor and pay their own Arms. 1 + 2 x 200% = 5+ // against 2 is 250 percent, the 2:1 row; the soldier alone would be at 50.+ [Fact]+ public void ArtilleryAddsItsStrengthTimesItsFactorToAnAttack()+ {+ var c = Load();+ var s = CombatTests.With(c, Attacking(Of("gun", 1, 4, 0, 2), 2, 0), Of("soldier", 3, 3, 0, 1), Enemy(2, 2, 0, 2));+ Assert.Equal(250, Combat.Preview(c, s, 3, 2, 0)!.Value.RatioPercent);+ var r = Step(c, s, new UnitOrder(3, Combat.Attack, 2, 0));+ Assert.Empty(r.Rejected);+ Assert.Equal(1, r.State.Units[2].Strength); // the 2:1 row: the defenders lose 1 and retreat, the attackers nothing+ Assert.NotEqual((2, 0), (r.State.Units[2].Q, r.State.Units[2].R));+ Assert.Equal(s.Arms - 2 - 3, r.State.Arms); // the soldier's attack and the guns' firing+ }++ // R-COMBAT-007: the guns fire from behind the line, so the attackers' losses fall on the other attackers only. 1 + 2 x+ // 200% = 5 against 3 is 166 percent: the attackers lose 1. The gun is the stronger attacker, so only this rule keeps it+ // whole and puts the loss on the soldier.+ [Fact]+ public void TheAttackersLossesSpareTheGuns()+ {+ var c = Load();+ var s = CombatTests.With(c, Attacking(Of("gun", 1, 4, 0, 2), 2, 0), Attacking(Of("soldier", 3, 3, 0, 1), 2, 0), Enemy(2, 2, 0, 3));+ var r = Step(c, s);+ Assert.Equal(2, r.State.Units[1].Strength);+ Assert.False(r.State.Units.ContainsKey(3)); // the soldier took the loss and was destroyed+ Assert.Equal(2, r.State.Units[2].Strength);+ Assert.Contains(r.Why, w => w.Message.StartsWith("The attack on hex 2,0 (units 1, 3 against unit 2,", StringComparison.Ordinal)); // id order, though the guns join last+ }++ // R-COMBAT-007: the guns pay after the other attackers; a stock that cannot pay for the firing calls it off, and the+ // attack goes ahead without them. At the order, the firing counts the attacks already ordered.+ [Fact]+ public void ArtilleryTheStockCannotPayForIsCalledOff()+ {+ var c = Load();+ var s = CombatTests.With(c, Attacking(Of("gun", 1, 4, 0, 2), 2, 0), Attacking(Of("soldier", 3, 3, 0, 1), 2, 0), Enemy(2, 2, 0, 2));+ s.Arms = 4; // the soldier's 2, then 2 left for the guns' 3+ var r = Step(c, s);+ Assert.Contains(r.Why, w => w.Message == "Unit 1's attack on hex 2,0 is called off: it needs 3 Arms and the stock has 2");+ Assert.Equal("", r.State.Units[1].Order);+ Assert.Equal(2, r.State.Arms);+ Assert.False(r.State.Units.ContainsKey(3)); // 1 against 2, the first row: both sides lose 1+ Assert.Equal(1, r.State.Units[2].Strength);++ var t = CombatTests.With(c, Of("gun", 1, 4, 0, 2), Attacking(Of("soldier", 3, 3, 0, 1), 2, 0), Enemy(2, 2, 0, 2));+ t.Arms = 4;+ Assert.Equal("An attack needs 3 Arms and the stock has 4, of which 2 go to attacks already ordered",+ Assert.Single(Step(c, t, new UnitOrder(1, Combat.Attack, 2, 0)).Rejected).Reason);++ // The other way round: a gun already ordered counts at its own 3 Arms, not at one attack's 2.+ var g = CombatTests.With(c, Attacking(Of("gun", 1, 4, 0, 2), 2, 0), Of("soldier", 3, 3, 0, 1), Enemy(2, 2, 0, 2));+ g.Arms = 4;+ Assert.Equal("An attack needs 2 Arms and the stock has 4, of which 3 go to attacks already ordered",+ Assert.Single(Step(c, g, new UnitOrder(3, Combat.Attack, 2, 0)).Rejected).Reason);+ }++ // R-COMBAT-007: artillery never holds ground. The hold order is refused with a reason; fortify is not.+ [Fact]+ public void ArtilleryDoesNotHoldGround()+ {+ var c = Load();+ var s = CombatTests.With(c, Of("gun", 1, 4, 0, 2));+ var refused = Step(c, s, new UnitOrder(1, Orders.Hold));+ Assert.Equal("Artillery does not hold ground", Assert.Single(refused.Rejected).Reason);+ Assert.Equal(Step(c, s).State.Hash(), refused.State.Hash());+ Assert.Empty(Step(c, s, new UnitOrder(1, Orders.Fortify)).Rejected);+ }++ // R-COMBAT-008: the armoured car's factor counts attacking and defending. 2 x 150% = 3 against 3 is 100 percent; 3+ // against the car's 3 is 100 too. Without the factor they would be 66 and 150.+ [Fact]+ public void TheArmouredCarFightsAtItsFactor()+ {+ var c = Load();+ var s = CombatTests.With(c, Of("car", 1, 3, 0, 2), Enemy(2, 2, 0, 3));+ Assert.Equal(100, Combat.Preview(c, s, 1, 2, 0)!.Value.RatioPercent);+ Assert.Equal(100, Combat.Preview(c, s, 2, 3, 0)!.Value.RatioPercent);+ }++ // R-COMBAT-007, R-COMBAT-008: range and Arms per firing belong to an artillery type, which needs both; a combat factor+ // belongs to a military type and is at least 1.+ [Theory]+ [InlineData(" - { id: g, kind: unit, side: israel, class: artillery, movement_points: 2, arms_per_fire: 1 }\n", "types[g].range", "required for an artillery type, at least 1")]+ [InlineData(" - { id: g, kind: unit, side: israel, class: artillery, movement_points: 2, range: 2 }\n", "types[g].arms_per_fire", "required for an artillery type, at least 1")]+ [InlineData(" - { id: g, kind: unit, side: israel, class: infantry, movement_points: 2, range: 2 }\n", "types[g].range", "only an artillery type has a range")]+ [InlineData(" - { id: g, kind: unit, side: israel, class: armour, movement_points: 2, arms_per_fire: 1 }\n", "types[g].arms_per_fire", "only an artillery type fires")]+ [InlineData(" - { id: g, kind: unit, combat_percent: 150 }\n", "types[g].combat_percent", "only a military type has a combat factor")]+ [InlineData(" - { id: g, kind: unit, side: israel, class: armour, movement_points: 2, combat_percent: 0 }\n", "types[g].combat_percent", "must be at least 1")]+ public void TheCombatValuesAreValidated(string row, string field, string message)+ {+ var ex = Assert.Throws<ContentException>(() => Load(Fixture.GddUnitTypes + row));+ Assert.Equal("unit_types.yaml", ex.File);+ Assert.Equal(field, ex.Field);+ Assert.Contains(message, ex.Message);+ }++ // R-COMBAT-007, R-COMBAT-008: the real types carry the values the owner accepted on #748 (21 October 2026).+ [Fact]+ public void TheRealTypesCarryTheirCombatValues()+ {+ var c = ContentLoader.Load(RealContentTests.ContentRoot());+ var gun = c.UnitTypes.Single(t => t.Id == "artillery");+ Assert.Equal((2, 2, 200), (gun.Range, gun.ArmsPerFire, gun.CombatPercent));+ Assert.Equal(150, c.UnitTypes.Single(t => t.Id == "armoured_car").CombatPercent);+ Assert.Null(c.UnitTypes.Single(t => t.Id == "veteran_soldier").CombatPercent);+ }+}diff --git a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs b/sim/Statecraft.Sim.Tests/DesignValuesTests.csindex c2cc1831b..28cede7af 100644--- a/sim/Statecraft.Sim.Tests/DesignValuesTests.cs+++ b/sim/Statecraft.Sim.Tests/DesignValuesTests.cs@@ -157,6 +157,11 @@ public class DesignValuesTests("unit_types.yaml", "types[veteran_soldier].movement_points"),("unit_types.yaml", "types[artillery].movement_points"),("unit_types.yaml", "types[armoured_car].movement_points"),+ // Artillery's combat role and the armoured car (Phase 5 PR 9, #748; Q-ARTY-1, Q-ARTY-2): owner, 21 October 2026.+ ("unit_types.yaml", "types[artillery].range"),+ ("unit_types.yaml", "types[artillery].arms_per_fire"),+ ("unit_types.yaml", "types[artillery].combat_percent"),+ ("unit_types.yaml", "types[armoured_car].combat_percent"),("unit_types.yaml", "types[egyptian_army].movement_points"), // #743, owner, 20 October 2026("unit_types.yaml", "types[arab_legion].movement_points"), // #743, owner, 20 October 2026("unit_types.yaml", "types[syrian_army].movement_points"), // #743, owner, 20 October 2026diff --git a/sim/Statecraft.Sim.Tests/OrdersTests.cs b/sim/Statecraft.Sim.Tests/OrdersTests.csindex 0ddf95935..1c276c8a4 100644--- a/sim/Statecraft.Sim.Tests/OrdersTests.cs+++ b/sim/Statecraft.Sim.Tests/OrdersTests.cs@@ -53,7 +53,7 @@ public class OrdersTestsvar c = Load();var s = With(c, Soldier(1, 2, 1));var given = s.Clone();- Assert.Null(Orders.Give(given, 1, Orders.Fortify, new List<Cause>()));+ Assert.Null(Orders.Give(c, given, 1, Orders.Fortify, new List<Cause>()));Assert.Equal(Orders.Fortifying, given.Units[1].Order);Assert.Equal(100, Defence(c, given, 1)); // the turn it is givendiff --git a/sim/Statecraft.Sim/Combat.cs b/sim/Statecraft.Sim/Combat.csindex 19ce0772e..807a919f4 100644--- a/sim/Statecraft.Sim/Combat.cs+++ b/sim/Statecraft.Sim/Combat.cs@@ -15,6 +15,9 @@ namespace Statecraft.Sim{public const string Attack = "attack";+ /// <summary>The unit_types.yaml class whose units support attacks from range (R-COMBAT-007; Q-ARTY-1).</summary>+ public const string ArtilleryClass = "artillery";+/// <summary>RNG values each engagement draws, whatever its outcome (docs/determinism.md, "Combat draws").</summary>public const int DrawsPerEngagement = 1;@@ -29,6 +32,27 @@ namespace Statecraft.Simstatic bool Adjacent(Unit u, int q, int r) => Movement.Neighbours.Any(d => u.Q + d.Q == q && u.R + d.R == r);+ static UnitType? TypeOf(Content c, Unit u) => c.UnitTypes.FirstOrDefault(t => t.Id == u.Type);++ /// <summary>R-COMBAT-007: a unit of the artillery class (Q-ARTY-1).</summary>+ static bool Guns(Content c, Unit u) => TypeOf(c, u)?.Class == ArtilleryClass;++ /// <summary>R-COMBAT-007: artillery reaches an enemy hex within its type's range; every other unit only the hex next+ /// to it (Q-COMBAT-2).</summary>+ static bool InReach(Content c, Unit u, int q, int r)+ {+ if (!Guns(c, u)) return Adjacent(u, q, r);+ var d = MapActions.Distance(u.Q, u.R, q, r);+ return d >= 1 && d <= TypeOf(c, u)!.Range!.Value; // the loader requires a range on an artillery type+ }++ /// <summary>The Arms the player's unit spends when it joins an engagement: its type's arms_per_fire for artillery+ /// (R-COMBAT-007), else mvp.arms_per_attack (R-COMBAT-004).</summary>+ static int Need(Content c, MvpRules mvp, Unit u) => Guns(c, u) ? TypeOf(c, u)!.ArmsPerFire!.Value : mvp.ArmsPerAttack!.Value;++ /// <summary>R-COMBAT-007, R-COMBAT-008: the percent of its strength a unit fights at, its type's combat_percent or 100.</summary>+ static long Factor(Content c, Unit u) => TypeOf(c, u)?.CombatPercent ?? 100;+/// <summary>The enemy military units on (q, r), seen from <paramref name="attacker"/>'s team, in id order.</summary>static List<Unit> Defenders(GameState s, Unit attacker, int q, int r) =>s.Units.Values.Where(x => x.Q == q && x.R == r && Military(x) && Player(x) != Player(attacker)).ToList();@@ -45,13 +69,14 @@ namespace Statecraft.Simif (q == null || r == null) return "An attack names a hex";var target = Hex(q.Value, r.Value);if (u.Order == Attack && u.OrderTarget == target) return "That unit already has that order";- if (!Adjacent(u, q.Value, r.Value)) return "That hex is not next to the unit";+ if (!InReach(c, u, q.Value, r.Value)) return Guns(c, u) ? "That hex is beyond the unit's range" : "That hex is not next to the unit";if (Defenders(s, u, q.Value, r.Value).Count == 0) return "There is no enemy unit on that hex";- var need = c.RulesAt(s.Date).Mvp!.ArmsPerAttack!.Value;+ var mvp = c.RulesAt(s.Date).Mvp!;+ var need = Need(c, mvp, u);// Arms are paid at resolution, so the stock must also cover the player's other standing attacks, this turn's// included; the unit's own attack, which this order replaces, is not counted.- var ordered = s.Units.Values.Count(x => x.Id != unitId && x.Order == Attack && Military(x) && Player(x));- if (s.Arms < need * (ordered + 1)) return Short(need, s.Arms, ordered * need);+ var committed = s.Units.Values.Where(x => x.Id != unitId && x.Order == Attack && Military(x) && Player(x)).Sum(x => Need(c, mvp, x));+ if (s.Arms < need + committed) return Short(need, s.Arms, committed);s.Units[unitId] = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, Attack, target);why.Add(new Cause("map", unitId.ToString(CultureInfo.InvariantCulture), 0, $"Unit {unitId} will attack hex {target}"));return null;@@ -63,29 +88,32 @@ namespace Statecraft.Sim/// <summary>The attack preview (spec section 2.6; Q-UI-1): the ratio, in percent and rounded down, of unit/// <paramref name="unitId"/>'s strength plus that of the units of its team already ordered to attack (q, r) from next to- /// it, against the enemy units there after fortify and terrain, and the combat_table row it falls in. Null when (q, r)- /// is not next to the unit or holds no enemy unit, or the unit is unknown or no military unit.</summary>+ /// it (artillery: from within its range), each at its combat factor, against the enemy units there after fortify and+ /// terrain, and the combat_table row it falls in. Null when (q, r) is out of the unit's reach or holds no enemy unit, or+ /// the unit is unknown or no military unit. A gun previewed with no other attacker still gets a ratio, though step 2+ /// would have it hold its fire (R-COMBAT-007); the UI that shows it is Phase 5 PR 15.</summary>public static (int RatioPercent, int Row)? Preview(Content c, GameState s, int unitId, int q, int r){- if (!s.Units.TryGetValue(unitId, out var u) || !Military(u) || !Adjacent(u, q, r)) return null;+ if (!s.Units.TryGetValue(unitId, out var u) || !Military(u) || !InReach(c, u, q, r)) return null;var defenders = Defenders(s, u, q, r);if (defenders.Count == 0) return null;var target = Hex(q, r);var attackers = s.Units.Values.Where(x => x.Id == unitId- || (x.Order == Attack && x.OrderTarget == target && Military(x) && Player(x) == Player(u) && Adjacent(x, q, r))).ToList();+ || (x.Order == Attack && x.OrderTarget == target && Military(x) && Player(x) == Player(u) && InReach(c, x, q, r))).ToList();var mvp = c.RulesAt(s.Date).Mvp!;var ratio = Ratio(c, mvp, attackers, defenders, q, r);return (ratio, Row(mvp, ratio));}- /// <summary>R-COMBAT-002: the attackers' summed strength over the defenders' summed strength, each defender's strength- /// times its order's defence percent (Orders.DefencePercent) and its hex's biome percent, in whole percent rounded down.- /// Integer arithmetic only, so it is the same on every runtime.</summary>+ /// <summary>R-COMBAT-002: the attackers' summed strength over the defenders' summed strength, each unit's strength times+ /// its type's combat factor (R-COMBAT-007, R-COMBAT-008) and each defender's also times its order's defence percent+ /// (Orders.DefencePercent) and its hex's biome percent, in whole percent rounded down. Integer arithmetic only, so it+ /// is the same on every runtime.</summary>static int Ratio(Content c, MvpRules mvp, List<Unit> attackers, List<Unit> defenders, int q, int r){- long attack = attackers.Sum(x => (long)x.Strength);+ long attack = attackers.Sum(x => x.Strength * Factor(c, x)); // in 1/100 of a strength unitvar terrain = mvp.CombatTerrainPercent[c.HexAt(q, r)!.Biome]; // a unit stands on land, and the loader requires every land biome- long defence = defenders.Sum(x => (long)x.Strength * Orders.DefencePercent(mvp, x) * terrain); // in 1/10,000 of a strength unit+ long defence = defenders.Sum(x => x.Strength * Factor(c, x) * Orders.DefencePercent(mvp, x) * terrain); // in 1/1,000,000 of a strength unitreturn defence == 0 ? int.MaxValue : (int)Math.Min(int.MaxValue, attack * 1_000_000 / defence); // 0: no real unit has no strength}@@ -99,9 +127,11 @@ namespace Statecraft.Sim/// <summary>Resolver step 2 (R-COMBAT-002 to R-COMBAT-006): in ascending attacker id, each unit with an attack order not/// yet in an engagement this turn leads one, with every unit of its team attacking the same hex. A unit no longer next- /// to its hex, or whose hex holds no enemy unit, ends its attack; a player's unit pays mvp.arms_per_attack when it- /// joins, and one the stock cannot pay for has its attack called off (Q-COMBAT-4). Enemy units pay nothing (Q-ENEMY-4:- /// no supply). An engagement with an attacker left draws once. Afterwards every attack whose hex is now empty ends.</summary>+ /// to its hex (artillery: within its range), or whose hex holds no enemy unit, ends its attack; a player's unit pays+ /// its Arms when it joins, and one the stock cannot pay for has its attack called off (Q-COMBAT-4). Enemy units pay+ /// nothing (Q-ENEMY-4: no supply). Artillery joins after the other attackers and only beside one of them: alone it+ /// holds its fire, pays nothing and keeps its order (R-COMBAT-007). An engagement with an attacker left draws once.+ /// Afterwards every attack whose hex is now empty ends.</summary>public static void Resolve(Content c, GameState s, List<Cause> why){var mvp = c.RulesAt(s.Date).Mvp!;@@ -110,16 +140,23 @@ namespace Statecraft.Sim{if (done.Contains(id) || !s.Units.TryGetValue(id, out var lead) || lead.Order != Attack) continue;var (q, r) = Target(lead);- var group = s.Units.Values.Where(x => !done.Contains(x.Id) && x.Order == Attack && x.OrderTarget == lead.OrderTarget && Player(x) == Player(lead)).ToList();+ // The guns last (a stable sort keeps id order on each side of it): they fire only beside another attacker.+ var group = s.Units.Values.Where(x => !done.Contains(x.Id) && x.Order == Attack && x.OrderTarget == lead.OrderTarget && Player(x) == Player(lead))+ .OrderBy(x => Guns(c, x) ? 1 : 0).ToList();var defenders = Defenders(s, lead, q, r);var attackers = new List<Unit>();foreach (var x in group){done.Add(x.Id);- if (defenders.Count == 0 || !Adjacent(x, q, r)) { End(s, x, $"Unit {x.Id}'s attack on hex {x.OrderTarget} ends: no enemy unit is there", why); continue; }+ if (defenders.Count == 0 || !InReach(c, x, q, r)) { End(s, x, $"Unit {x.Id}'s attack on hex {x.OrderTarget} ends: no enemy unit is there", why); continue; }+ if (Guns(c, x) && attackers.Count == 0)+ {+ why.Add(new Cause("map", x.Id.ToString(CultureInfo.InvariantCulture), 0, $"Unit {x.Id} holds its fire: no attack on hex {x.OrderTarget} to support"));+ continue;+ }if (Player(x)){- var need = mvp.ArmsPerAttack!.Value;+ var need = Need(c, mvp, x);if (s.Arms < need){End(s, x, $"Unit {x.Id}'s attack on hex {x.OrderTarget} is called off: it needs {need.ToString(CultureInfo.InvariantCulture)} Arms and the stock has {s.Arms.ToString(CultureInfo.InvariantCulture)}", why);@@ -135,7 +172,7 @@ namespace Statecraft.Simif (u.Order == Attack){var (q, r) = Target(u);- if (Defenders(s, u, q, r).Count == 0 || !Adjacent(u, q, r))+ if (Defenders(s, u, q, r).Count == 0 || !InReach(c, u, q, r))End(s, u, $"Unit {u.Id}'s attack on hex {u.OrderTarget} ends: no enemy unit is there", why);}}@@ -166,7 +203,8 @@ namespace Statecraft.Simvar target = Hex(q, r);var ppu = mvp.PeoplePerUnit;var removed = new List<int>();- var attackersLost = Take(s, attackers.Select(x => x.Id).ToList(), row.AttackerLoss[face], removed);+ // R-COMBAT-007: the guns fire from behind the line, so the attackers' losses fall on the others only.+ var attackersLost = Take(s, attackers.Where(x => !Guns(c, x)).Select(x => x.Id).ToList(), row.AttackerLoss[face], removed);var defendersLost = Take(s, defenders.Select(x => x.Id).ToList(), row.DefenderLoss[face], removed);why.Add(new Cause("map", target, 0, FormattableString.Invariant($"The attack on hex {target} ({Ids(attackers)} against {Ids(defenders)}, strength ratio {ratio}%): the attackers lost {attackersLost * ppu:N0} people and the defenders lost {defendersLost * ppu:N0} people")));@@ -191,7 +229,8 @@ namespace Statecraft.Sim}}- static string Ids(List<Unit> units) => (units.Count == 1 ? "unit " : "units ") + string.Join(", ", units.Select(x => x.Id.ToString(CultureInfo.InvariantCulture)));+ // Sorted for the text: step 2 puts the guns last (R-COMBAT-007), but the line names the units in id order.+ static string Ids(List<Unit> units) => (units.Count == 1 ? "unit " : "units ") + string.Join(", ", units.Select(x => x.Id).OrderBy(x => x).Select(x => x.ToString(CultureInfo.InvariantCulture)));/// <summary>Takes up to <paramref name="loss"/> population units from <paramref name="ids"/>, one at a time from the/// strongest unit left (a tie on the lower id; the list is in id order), removing each that reaches 0 (its id is neverdiff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.csindex 3c34daafa..3af6b6051 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -813,6 +813,15 @@ namespace Statecraft.Sim/// <summary>The movement points a unit of this type has each turn (R-MOVE-001; Q-MOVE-1), or 0 for a type that does not/// move. Required on a military type.</summary>public int MovementPoints { get; set; }+ /// <summary>The percent a unit of this military type's strength counts for in combat, attacking and defending+ /// (R-COMBAT-007, R-COMBAT-008; Q-ARTY-1, Q-ARTY-2), or null for 100.</summary>+ public int? CombatPercent { get; set; }+ /// <summary>An artillery type's range in hexes: it supports an attack on an enemy hex this far away (R-COMBAT-007;+ /// Q-ARTY-1). Required on an artillery type, null on any other.</summary>+ public int? Range { get; set; }+ /// <summary>The Arms a unit of an artillery type spends each time it fires (R-COMBAT-007; Q-ARTY-1). Required on an+ /// artillery type, null on any other.</summary>+ public int? ArmsPerFire { get; set; }}/// <summary>One stretch of a budget line's ownership (rules.yaml budget_owners): from this day (inclusive) the office owns the line.</summary>diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex 83d661c4f..b0eed8b27 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -1099,6 +1099,20 @@ namespace Statecraft.Simif (x.Kind == "population" && x.MovementPoints != 0) throw new ContentException(uf, at + ".movement_points", "only a unit moves");if (x.Side != "" && x.MovementPoints < 1) throw new ContentException(uf, at + ".movement_points", "required for a military type, at least 1");if (x.MovementPoints < 0) throw new ContentException(uf, at + ".movement_points", "must be >= 0");+ // R-COMBAT-007, R-COMBAT-008 (Q-ARTY-1, Q-ARTY-2): only a military type fights, so only it has a combat+ // factor; range and Arms per firing are artillery's support role and are read for nothing else.+ if (x.CombatPercent != null && x.Side == "") throw new ContentException(uf, at + ".combat_percent", "only a military type has a combat factor");+ if (x.CombatPercent < 1) throw new ContentException(uf, at + ".combat_percent", "must be at least 1");+ if (x.Class == Combat.ArtilleryClass)+ {+ if (!(x.Range >= 1)) throw new ContentException(uf, at + ".range", "required for an artillery type, at least 1");+ if (!(x.ArmsPerFire >= 1)) throw new ContentException(uf, at + ".arms_per_fire", "required for an artillery type, at least 1");+ }+ else+ {+ if (x.Range != null) throw new ContentException(uf, at + ".range", "only an artillery type has a range");+ if (x.ArmsPerFire != null) throw new ContentException(uf, at + ".arms_per_fire", "only an artillery type fires");+ }if (x.Facility == ""){// Training (R-TRAIN-001) needs a place to train; values without one would be read by nothing.diff --git a/sim/Statecraft.Sim/Orders.cs b/sim/Statecraft.Sim/Orders.csindex 9caf31e73..0151e3f65 100644--- a/sim/Statecraft.Sim/Orders.cs+++ b/sim/Statecraft.Sim/Orders.cs@@ -28,13 +28,15 @@ namespace Statecraft.Sim/// <summary>R-ORDER-001: gives the unit its standing order, replacing any other. Fortify names the unit's hex and starts/// as Fortifying; hold names nothing, as it acts where the unit is. Refused, state untouched, for an unknown order or- /// unit, a unit with no side (a halutz), an enemy unit, or the order it already has.</summary>- internal static string? Give(GameState s, int unitId, string order, List<Cause> why)+ /// unit, a unit with no side (a halutz), an enemy unit, hold for artillery (R-COMBAT-007: it never holds ground,+ /// Q-ARTY-1), or the order it already has.</summary>+ internal static string? Give(Content c, GameState s, int unitId, string order, List<Cause> why){if (order != Fortify && order != Hold) return "That order is not known";if (!s.Units.TryGetValue(unitId, out var u)) return "There is no such unit";if (u.Side == "") return "Only a military unit takes that order";if (u.Side != PlayerSide) return "That unit is not yours";+ if (order == Hold && c.UnitTypes.FirstOrDefault(t => t.Id == u.Type)?.Class == Combat.ArtilleryClass) return "Artillery does not hold ground";var here = Hex(u);var already = order == Hold ? u.Order == Hold : (u.Order == Fortify || u.Order == Fortifying) && u.OrderTarget == here;if (already) return "That unit already has that order";diff --git a/sim/Statecraft.Sim/Simulation.cs b/sim/Statecraft.Sim/Simulation.csindex 3779453d5..f868ae517 100644--- a/sim/Statecraft.Sim/Simulation.cs+++ b/sim/Statecraft.Sim/Simulation.cs@@ -176,7 +176,7 @@ namespace Statecraft.Simreturn Projects.Stop(c, s, w.Unit, why);case UnitOrder o:if (o.Order == Combat.Attack) return Combat.Give(c, s, o.Unit, o.Q, o.R, why);- return o.Q != null || o.R != null ? "That order names no hex" : Orders.Give(s, o.Unit, o.Order, why);+ return o.Q != null || o.R != null ? "That order names no hex" : Orders.Give(c, s, o.Unit, o.Order, why);case StartProject p:return Projects.StartCity(c, s, p.ProjectKind, p.City, p.Q, p.R, why);case CancelProject p: