A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Name an enemy attack order for the turn report's enemy-orders row (#2538)
agamrafaeli-instinct39dbacf1f68c
diff --git a/changelog.d/2534-enemy-attack-order.md b/changelog.d/2534-enemy-attack-order.mdnew file mode 100644index 000000000..1737ef384--- /dev/null+++ b/changelog.d/2534-enemy-attack-order.md@@ -0,0 +1,3 @@+### Fixed+- The turn report's enemy-orders row now names an enemy attack order on the turn it is given, not only once the attack+ engages (#2534).diff --git a/sim/Statecraft.Sim.Tests/EnemyAITests.cs b/sim/Statecraft.Sim.Tests/EnemyAITests.csindex a1d6f2da7..550f7fa6e 100644--- a/sim/Statecraft.Sim.Tests/EnemyAITests.cs+++ b/sim/Statecraft.Sim.Tests/EnemyAITests.cs@@ -515,7 +515,8 @@ public class EnemyAITests{var c = Load();var fought = Simulation.Step(c, CombatTests.With(c, Soldier(1, 3, 0, 5), Enemy(2, 2, 0, 10)), Array.Empty<Command>());- Assert.Equal(new[] { Combat.Attack }, fought.Why.Where(x => x.EnemyOrder != "").Select(x => x.EnemyOrder));+ // #2534: the new order's own cause names it too, ahead of the engagement's.+ Assert.Equal(new[] { Combat.Attack, Combat.Attack }, fought.Why.Where(x => x.EnemyOrder != "").Select(x => x.EnemyOrder));var mine = Simulation.Step(c, CombatTests.With(c, Soldier(1, 3, 0, 10), Enemy(2, 2, 0, 1)), new Command[] { new UnitOrder(1, Combat.Attack, 2, 0) });Assert.Contains(mine.Why, x => x.Message.StartsWith("The attack on hex 2,0", StringComparison.Ordinal));Assert.DoesNotContain(mine.Why, x => x.EnemyOrder == Combat.Attack);@@ -545,12 +546,24 @@ public class EnemyAITestsvar r = Simulation.Step(c, s, Array.Empty<Command>());Assert.Equal((Combat.Attack, "3,0"), (r.State.Units[2].Order, r.State.Units[2].OrderTarget));Assert.Equal(4 - turn, r.State.Units[1].Strength); // it engaged this turn- var attack = Assert.Single(r.Why, x => x.EnemyOrder == Combat.Attack);+ var attack = Assert.Single(r.Why, x => x.EnemyOrder == Combat.Attack && x.Key == WhyKeys.Engagement); // #2534: the order's own cause is marked tooAssert.Equal("3,0", attack.Target);Assert.Equal(new[] { 2 }, attack.EnemyAttackers);s = r.State;}}++ // #2534: a newly issued enemy attack order names itself on its own cause, so the turn report's enemy-orders row can+ // show it (the engagement names its attackers only when the attack engages, #1297).+ [Fact]+ public void ANewEnemyAttackOrderNamesItselfForTheReport()+ {+ var c = Load();+ var r = Simulation.Step(c, CombatTests.With(c, Soldier(1, 3, 0, 5), Enemy(2, 2, 0, 10)), Array.Empty<Command>());+ var order = Assert.Single(r.Why, x => x.Key == WhyKeys.AttackOrdered && x.EnemyOrder == Combat.Attack);+ Assert.Equal(new[] { 2 }, order.EnemyAttackers);+ Assert.Equal("2", order.Target);+ }// R-ENEMY-005 (Q-ENEMY-5; owner, 31 October 2026, #749): an operation card's option gives a go-to order to a unit of a// units_1948.yaml row, toward one of that row's own anchor hexes, through the player's own go-to (Movement.GiveGoTo).// The loader refuses a row it does not know, and a hex that is not one of the row's anchors; a card'sdiff --git a/sim/Statecraft.Sim.Tests/RemainingCauseKeysTests.cs b/sim/Statecraft.Sim.Tests/RemainingCauseKeysTests.csindex 54a75cc4f..a184de162 100644--- a/sim/Statecraft.Sim.Tests/RemainingCauseKeysTests.cs+++ b/sim/Statecraft.Sim.Tests/RemainingCauseKeysTests.cs@@ -115,7 +115,7 @@ public class RemainingCauseKeysTestssites++;}}- Assert.Equal(123, sites); // 123 with #2471's gdd-0.3 field Food line (R-FIELD-002); 122 with #2527's FoodImported and the conversion's fx_reserves line; 120 with #2457's event Debt line (R-EFX-009); 119 with #1700 slice B's ProjectBuilderFreed; 118 with #1700's builders (R-CITY-011: two ProjectBuilder lines, ProjectWaiting, the build order's job-default line); 114 with #1703's gdd-0.3 housing surcharge and housing cohesion lines; 112 with the arms workshops' five (R-ARMS-005 with its job-default line, R-ARMS-006; #1701); 107 with R-MONEY-004's DollarsConverted (#813); 106 since #2212: EconomySystem.OtherMoney's line (105 since #2199: PayOrBorrow's Paid line)+ Assert.Equal(124, sites); // 124 with #2534's enemy attack-order line (Combat.Give marks the order's own cause); 123 with #2471's gdd-0.3 field Food line (R-FIELD-002); 122 with #2527's FoodImported and the conversion's fx_reserves line; 120 with #2457's event Debt line (R-EFX-009); 119 with #1700 slice B's ProjectBuilderFreed; 118 with #1700's builders (R-CITY-011: two ProjectBuilder lines, ProjectWaiting, the build order's job-default line); 114 with #1703's gdd-0.3 housing surcharge and housing cohesion lines; 112 with the arms workshops' five (R-ARMS-005 with its job-default line, R-ARMS-006; #1701); 107 with R-MONEY-004's DollarsConverted (#813); 106 since #2212: EconomySystem.OtherMoney's line (105 since #2199: PayOrBorrow's Paid line)}[Fact]diff --git a/sim/Statecraft.Sim/Cause.cs b/sim/Statecraft.Sim/Cause.csindex 95fdef670..c5a7af837 100644--- a/sim/Statecraft.Sim/Cause.cs+++ b/sim/Statecraft.Sim/Cause.cs@@ -17,7 +17,7 @@ namespace Statecraft.Sim/// already has is kept with no cause (R-ENEMY-003), so it is named only on the turn it is given; an attack is named on/// every turn it engages, as a standing one still does.</summary>public string EnemyOrder { get; }- /// <summary>With EnemyOrder Combat.Attack: the enemy units that attacked in the engagement, in id order; else empty.</summary>+ /// <summary>With EnemyOrder Combat.Attack: the enemy units that attacked in the engagement, or the one unit a new attack order was given to (#2534), in id order; else empty.</summary>public IReadOnlyList<int> EnemyAttackers { get; }/// <summary>A stable localization key for a unit line (#1399) or report producer (CauseKeys); else empty.</summary>public string Key { get; }diff --git a/sim/Statecraft.Sim/Combat.cs b/sim/Statecraft.Sim/Combat.csindex 4abf708a2..9fea9cd74 100644--- a/sim/Statecraft.Sim/Combat.cs+++ b/sim/Statecraft.Sim/Combat.cs@@ -127,7 +127,13 @@ namespace Statecraft.Simif (refused != null) return refused;var u = s.Units[unitId]; var target = Hex(q!.Value, r!.Value);s.Units[unitId] = new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, u.Strength, Attack, target, u.HomeCity, u.Full, u.CombatXp);- why.Add(UnitLines.Line(WhyKeys.AttackOrdered, $"Unit {unitId} will attack hex {target}", new[] { u }, target));+ var line = UnitLines.Line(WhyKeys.AttackOrdered, $"Unit {unitId} will attack hex {target}", new[] { u }, target);+ // #2534: the enemy's attack order names itself for the turn report's enemy-orders row, as an engagement's does (#1297).+ // UnitLines.Line's system is always "map" (UnitLines.cs); name it as a literal so the Why-screen scan sees it.+ why.Add(enemy+ ? new Cause("map", line.Target, line.Delta, line.Message, enemyOrder: Attack, enemyAttackers: new[] { unitId },+ key: line.Key, units: line.Units, args: line.Args)+ : line);return null;}diff --git a/unity/Assets/Scripts/UI/TurnReportPresenter.cs b/unity/Assets/Scripts/UI/TurnReportPresenter.csindex 06f11d40e..c2a6844dc 100644--- a/unity/Assets/Scripts/UI/TurnReportPresenter.cs+++ b/unity/Assets/Scripts/UI/TurnReportPresenter.cs@@ -210,10 +210,13 @@ namespace Statecraft.Game.UIreturn text.Format("report.unit", id);}// An engagement (#1297) names its enemy attackers, one line each, and gives no line if it names none: its Target is- // a hex, not a unit. An order names its unit, Target.+ // a hex, not a unit. An order names its unit, Target. A new attack order that engages the same turn names its unit+ // on both causes (#2534): one line per order and unit, not two (#2538 review).return turn.Why.Where(w => w.EnemyOrder != "").SelectMany(w => (w.EnemyOrder == Combat.Attack ? w.EnemyAttackers : new[] { int.Parse(w.Target, CultureInfo.InvariantCulture) })- .Select(id => text.Format("report.enemy_" + w.EnemyOrder, Name(w, id)))).ToList();+ .Select(id => (cause: w, id)))+ .GroupBy(x => (x.cause.EnemyOrder, x.id))+ .Select(g => text.Format("report.enemy_" + g.Key.EnemyOrder, Name(g.First().cause, g.Key.id))).ToList();}void Show()diff --git a/unity/Assets/Tests/EditMode/TurnReportTests.cs b/unity/Assets/Tests/EditMode/TurnReportTests.csindex cf8fed536..b4a574f51 100644--- a/unity/Assets/Tests/EditMode/TurnReportTests.cs+++ b/unity/Assets/Tests/EditMode/TurnReportTests.cs@@ -359,6 +359,34 @@ public class TurnReportTestsAssert.IsFalse(TurnReportPresenter.Lines(k.Bridge, En).Any(l => l.Meter == TurnReportPresenter.EnemyRow));}+ /// <summary>#2534 review (#2538): a new enemy attack order that also engages on its turn names the attacker once in the+ /// enemy-orders row, not twice - the order's cause and the engagement's both carry the unit. The turn is replaced with+ /// both causes through Session.Last's private setter, as in AnAttackThatNamesNoAttackersGivesNoLine.</summary>+ [Test]+ public void ANewAttackOrderThatEngagesNamesTheAttackerOnce()+ {+ var rows = UnitData.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", UnitData.DefaultFileName)));+ int ala = C.StartingForces.ToList().FindIndex(f => f.Row == "arab_liberation_army");+ foreach (var hebrew in new[] { false, true })+ {+ var text = hebrew ? He : En;+ using var k = new Kit(text);+ var a = k.Bridge.Session.State.Units[ala];+ var order = new Cause("map", ala.ToString(System.Globalization.CultureInfo.InvariantCulture), 0, $"Unit {ala} will attack hex 3,0",+ Combat.Attack, new[] { ala }, WhyKeys.AttackOrdered, new[] { new UnitRef(a) });+ var engagement = new Cause("map", "3,0", 0, "The attack on hex 3,0",+ Combat.Attack, new[] { ala }, WhyKeys.Engagement, new[] { new UnitRef(a) });+ k.Bridge.EndTurn();+ var last = k.Bridge.Session.Last!;+ typeof(GameSession).GetProperty(nameof(GameSession.Last))!.SetValue(k.Bridge.Session,+ new StepResult(last.State, new[] { order, engagement }, last.Rejected));+ var row = TurnReportPresenter.Lines(k.Bridge, text, rows).Single(l => l.Meter == TurnReportPresenter.EnemyRow);+ CollectionAssert.AreEqual(+ new[] { hebrew ? "צבא ההצלה פתח בהתקפה על אחת היחידות שלכם" : "Arab Liberation Army launched an attack on one of your units" },+ row.Causes, "one line for the unit, though the order and the engagement both name it");+ }+ }+/// <summary>#2527 review: the Food shortage's line is informational (delta 0), and the turn report's Food row still/// names it, after the lines that have a number.</summary>[Test]