A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
UI: the turn report lists what the Arab forces did (Fixes #1293) (#1295)
Beri1026ee9bff1d
diff --git a/changelog.d/1293.md b/changelog.d/1293.mdnew file mode 100644index 000000000..2c3541b49--- /dev/null+++ b/changelog.d/1293.md@@ -0,0 +1,3 @@+- The turn report lists what the Arab forces did after End turn (#1293): one line per order the enemy AI gave that turn,+ a move, an attack or a fortify (R-ENEMY-001), with the unit's name, in English and Hebrew. The sim names each such+ order on its cause (`Cause.EnemyOrder`); no golden moves.diff --git a/sim/Statecraft.Sim.Tests/EnemyAITests.cs b/sim/Statecraft.Sim.Tests/EnemyAITests.csindex 20e923e5a..87e49b1c5 100644--- a/sim/Statecraft.Sim.Tests/EnemyAITests.cs+++ b/sim/Statecraft.Sim.Tests/EnemyAITests.cs@@ -392,4 +392,21 @@ public class EnemyAITests}Assert.Empty(s.Settlements);}++ // R-ENEMY-001: each order the enemy AI gives is named on its cause (Cause.EnemyOrder), for the turn report (#1293): a+ // scripted move, an attack and a fortify. The player's own orders, through the same checks, name none.+ [Fact]+ public void EachEnemyOrderIsNamedOnItsCause()+ {+ var c = Load();+ var why = new List<Cause>();+ EnemyAI.Order(c, CombatTests.With(c, Soldier(1, 3, 0, 5), Enemy(2, 2, 0, 10)), why);+ Assert.Equal(Combat.Attack, Assert.Single(why).EnemyOrder);+ var r = Simulation.Step(c, CombatTests.With(c, Soldier(1, 0, 0, 5), Enemy(2, 5, 2, 1)),+ new Command[] { new Move(1, 1, 0), new UnitOrder(1, Orders.Hold) });+ Assert.Equal(new[] { "", "", Orders.Fortify }, r.Why.Where(x => x.System == "map").Select(x => x.EnemyOrder).ToArray());+ var first = Simulation.Step(Real, Simulation.NewGame(Real, 1, Mode.Historical), Array.Empty<Command>());+ var scripted = Real.StartingForces.Select((f, i) => (f, i)).Where(x => x.f.Script != null).Select(x => x.i.ToString(System.Globalization.CultureInfo.InvariantCulture));+ Assert.Equal(scripted, first.Why.Where(x => x.EnemyOrder == Movement.Kind).Select(x => x.Target));+ }}diff --git a/sim/Statecraft.Sim/Cause.cs b/sim/Statecraft.Sim/Cause.csindex 90c2f4bb5..fde95cc63 100644--- a/sim/Statecraft.Sim/Cause.cs+++ b/sim/Statecraft.Sim/Cause.cs@@ -7,8 +7,13 @@ namespace Statecraft.Simpublic string Target { get; }public double Delta { get; }public string Message { get; }- public Cause(string system, string target, double delta, string message)- { System = system; Target = target; Delta = delta; Message = PlayerText.Capitalised(message); } // sentence case (playtest 2, P2-6)+ /// <summary>The order the enemy AI gave unit Target, when this cause records one (R-ENEMY-001): Movement.Kind,+ /// Combat.Attack or Orders.Fortify; else empty. The turn report words it in the player's language (#1293), as Message+ /// is English only. An order the unit already has is kept with no cause (R-ENEMY-003), so it is named only on the turn+ /// it is given.</summary>+ public string EnemyOrder { get; }+ public Cause(string system, string target, double delta, string message, string enemyOrder = "")+ { System = system; Target = target; Delta = delta; Message = PlayerText.Capitalised(message); EnemyOrder = enemyOrder; } // sentence case (playtest 2, P2-6)public override string ToString() => $"[{System}] {Message}";}}diff --git a/sim/Statecraft.Sim/Combat.cs b/sim/Statecraft.Sim/Combat.csindex 16a0b912f..c6df9383c 100644--- a/sim/Statecraft.Sim/Combat.cs+++ b/sim/Statecraft.Sim/Combat.cs@@ -80,7 +80,7 @@ namespace Statecraft.Simvar committed = s.Units.Values.Where(x => x.Id != unitId && x.Order == Attack && Military(x) && Player(x)).Sum(x => Need(c, mvp, x));if (!enemy && 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}"));+ why.Add(new Cause("map", unitId.ToString(CultureInfo.InvariantCulture), 0, $"Unit {unitId} will attack hex {target}", enemy ? Attack : ""));return null;}diff --git a/sim/Statecraft.Sim/Movement.cs b/sim/Statecraft.Sim/Movement.csindex a6967891c..da630f5dd 100644--- a/sim/Statecraft.Sim/Movement.cs+++ b/sim/Statecraft.Sim/Movement.cs@@ -76,7 +76,7 @@ namespace Statecraft.Sims.Units[unitId] = new Unit(u.Id, u.Type, q, r, u.Service, u.Side, u.Strength, fortified ? "" : u.Order, fortified ? "" : u.OrderTarget);spent[unitId] = used + cost;why.Add(new Cause("map", unitId.ToString(CultureInfo.InvariantCulture), cost,- FormattableString.Invariant($"Unit {unitId} moved to hex {q},{r} for {cost} movement points")));+ FormattableString.Invariant($"Unit {unitId} moved to hex {q},{r} for {cost} movement points"), enemy ? Kind : ""));if (u.Order == "fortify")why.Add(new Cause("map", unitId.ToString(CultureInfo.InvariantCulture), 0,$"Unit {unitId} left hex {u.OrderTarget} and is no longer fortified"));diff --git a/sim/Statecraft.Sim/Orders.cs b/sim/Statecraft.Sim/Orders.csindex 8a683c0dd..e8501d247 100644--- a/sim/Statecraft.Sim/Orders.cs+++ b/sim/Statecraft.Sim/Orders.cs@@ -54,7 +54,7 @@ namespace Statecraft.Sims.Units[unitId] = order == Fortify ? With(u, Fortifying, here) : With(u, Hold, "");why.Add(new Cause("map", unitId.ToString(CultureInfo.InvariantCulture), 0, order == Fortify? $"Unit {unitId} is fortifying hex {here}; it is fortified from the end of the turn"- : $"Unit {unitId} holds hex {here}"));+ : $"Unit {unitId} holds hex {here}", enemy ? order : ""));return null;}diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex adfe3eba9..e8d3f4321 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -323,6 +323,7 @@ namespace Statecraft.Game.UIDiagLog.BootPhase("screens wired"); // issue #321: the splits of the units layer// The map's own parse of the unit file when it read this text (issue #321: it was parsed twice at boot).var unitData = map.UnitEntriesFor(inputs.Map.UnitsYaml, Debug.LogWarning);+ report.Units = unitData; // the turn report names the enemy's units by these rows (#1293)DiagLog.BootPhase("units layer data read");var unitLayer = units = Statecraft.Game.Map.Units.UnitLayer.Create(map,unitData, inputs.Content.Hexes,diff --git a/unity/Assets/Scripts/UI/TurnReportPresenter.cs b/unity/Assets/Scripts/UI/TurnReportPresenter.csindex 74728da68..fa90aca48 100644--- a/unity/Assets/Scripts/UI/TurnReportPresenter.cs+++ b/unity/Assets/Scripts/UI/TurnReportPresenter.cs@@ -1,6 +1,9 @@#nullable enableusing System;using System.Collections.Generic;+using System.Globalization;+using System.Linq;+using Statecraft.Game.Map.Units;using Statecraft.Sim;using UnityEngine.UIElements;@@ -20,6 +23,12 @@ namespace Statecraft.Game.UI/// <summary>On the "root" element while the report shows.</summary>public const string OpenClass = "turn-report-open";public const string ElementName = "turn-report";+ /// <summary>The id of the row after the meters' that lists the enemy's orders this turn (#1293).</summary>+ public const string EnemyRow = "enemy";++ /// <summary>The units_1948.yaml rows, which name the enemy's units in that row (GameRoot sets them once the map has read+ /// them); without a row a unit is named by its id (report.unit).</summary>+ public IReadOnlyList<UnitEntry>? Units { get; set; }readonly VisualElement hudRoot, report; readonly ScrollView rows; readonly SimBridge bridge; readonly UiText text;readonly ScreenNav nav; readonly Button close, all;@@ -83,8 +92,9 @@ namespace Statecraft.Game.UI}/// <summary>The report's lines for the session's last turn: each top-bar meter whose shown change is not empty, in- /// the bar's order (the meters have different units, so no order by size is given without a rule).</summary>- public static IReadOnlyList<Line> Lines(SimBridge bridge, UiText text)+ /// the bar's order (the meters have different units, so no order by size is given without a rule); then, under+ /// <see cref="EnemyRow"/>, the enemy's orders (#1293).</summary>+ public static IReadOnlyList<Line> Lines(SimBridge bridge, UiText text, IReadOnlyList<UnitEntry>? units = null){var m = HudModel.From(bridge, text); var lines = new List<Line>();foreach (var id in HudModel.MeterIds)@@ -94,13 +104,33 @@ namespace Statecraft.Game.UIif (meter.Delta.Length == 0) continue;lines.Add(new Line(id, text.Format("report.line", text["hud.caption." + id], meter.Delta), HudModel.Causes(bridge.Session.Last, id)));}+ var enemy = EnemyOrders(bridge, text, units);+ if (enemy.Count > 0) lines.Add(new Line(EnemyRow, text["report.enemy"], enemy));return lines;}+ /// <summary>#1293: every order the enemy AI gave in the last turn, as the sim names it on its cause (Cause.EnemyOrder,+ /// R-ENEMY-001), in the sim's order, in the player's language: Message is English only. The unit is named by its row+ /// (unit i of a new game is StartingForces[i], R-UNIT-006), in Hebrew by its name_he where it has one.</summary>+ static IReadOnlyList<string> EnemyOrders(SimBridge bridge, UiText text, IReadOnlyList<UnitEntry>? units)+ {+ var turn = bridge.Session.Last;+ if (turn == null) return Array.Empty<string>();+ var forces = bridge.Content.StartingForces; bool hebrew = text["ui.lang"] == UiLanguage.Hebrew;+ string Name(int id)+ {+ var row = id < forces.Count ? units?.FirstOrDefault(u => u.Id == forces[id].Row) : null;+ if (row == null) return text.Format("report.unit", id);+ return hebrew && !string.IsNullOrEmpty(row.NameHe) ? row.NameHe : row.Name;+ }+ return turn.Why.Where(w => w.EnemyOrder != "")+ .Select(w => text.Format("report.enemy_" + w.EnemyOrder, Name(int.Parse(w.Target, CultureInfo.InvariantCulture)))).ToList();+ }+void Show(){rows.Clear();- foreach (var line in Lines(bridge, text))+ foreach (var line in Lines(bridge, text, Units)){var row = new VisualElement { name = "turn-report-" + line.Meter };row.AddToClassList("turn-report-row");diff --git a/unity/Assets/Tests/EditMode/TurnReportTests.cs b/unity/Assets/Tests/EditMode/TurnReportTests.csindex ca5aeaedc..4e577d657 100644--- a/unity/Assets/Tests/EditMode/TurnReportTests.cs+++ b/unity/Assets/Tests/EditMode/TurnReportTests.cs@@ -1,9 +1,11 @@#nullable enableusing System.Collections;using System.Collections.Generic;+using System.IO;using System.Linq;using NUnit.Framework;using Statecraft.Game;+using Statecraft.Game.Map.Units;using Statecraft.Game.UI;using Statecraft.Sim;using UnityEditor;@@ -60,7 +62,8 @@ public class TurnReportTestsvar changed = HudModel.MeterIds.Where(id => m.For(id).Delta.Length > 0).ToArray();Assert.GreaterOrEqual(changed.Length, 3, "the opening turn moves at least three numbers in the bar");var rows = k.Ui.Q<ScrollView>("turn-report-rows").Children().ToList();- CollectionAssert.AreEqual(changed.Select(id => "turn-report-" + id), rows.Select(r => r.name), "every changed number, in the bar's order, and no other");+ CollectionAssert.AreEqual(changed.Select(id => "turn-report-" + id).Append("turn-report-" + TurnReportPresenter.EnemyRow), rows.Select(r => r.name),+ "every changed number, in the bar's order, and no other; then the enemy's orders (#1293)");var messages = new HashSet<string>(turn.Why.Select(w => w.Message));foreach (var id in changed){@@ -83,6 +86,33 @@ public class TurnReportTestsAssert.IsNull(k.Ui.Root.Q("turn-report-causes-support"), "no cause names Public support (an average of the indicators)");}+ /// <summary>#1293: the opening turn's enemy orders (R-ENEMY-001): the four scripted forces march (R-ENEMY-002) and the+ /// others fortify (R-ENEMY-003). After the bar's numbers the report lists each order, in the sim's order, its unit named+ /// by its units_1948.yaml row, in the player's language.</summary>+ [Test]+ public void TheEnemysOrdersAreReportedInBothLanguages()+ {+ var rows = UnitData.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", UnitData.DefaultFileName)));+ foreach (var hebrew in new[] { false, true })+ {+ var text = hebrew ? He : En;+ using var k = new Kit(text);+ k.Report.Units = rows;+ var turn = k.Bridge.EndTurn();+ var orders = turn.Why.Where(w => w.EnemyOrder != "").ToList();+ CollectionAssert.IsSupersetOf(orders.Select(w => w.EnemyOrder), new[] { Movement.Kind, Orders.Fortify }, "the opening turn has enemy moves and fortifies");+ var expected = orders.Select(w =>+ {+ var row = rows.First(u => u.Id == C.StartingForces[int.Parse(w.Target, System.Globalization.CultureInfo.InvariantCulture)].Row);+ return text.Format("report.enemy_" + w.EnemyOrder, hebrew ? row.NameHe : row.Name);+ }).ToList();+ Assert.AreEqual(text["report.enemy"], k.Ui.Q<Label>("turn-report-heading-" + TurnReportPresenter.EnemyRow).text);+ var lines = k.Ui.Q<Label>("turn-report-causes-" + TurnReportPresenter.EnemyRow).text.Split('\n');+ CollectionAssert.AreEqual(expected, lines);+ CollectionAssert.Contains(lines, hebrew ? "הלגיון הערבי עבר לעמדה חדשה" : "Arab Legion moved to a new position", "the Legion's march on Latrun");+ }+ }+[Test]public void ItCoversTheHudUntilClosedAndThenTheCardIsBack(){diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 425b47f0a..92930dd53 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -239,6 +239,12 @@ report.intro: "What changed in the top bar, and the main causes:"report.line: "{0}: {1}"report.all: "See all in Why?"report.close: "Close"+# The enemy's orders this turn (#1293): one line per order the enemy AI gave (R-ENEMY-001), {0} the unit's name.+report.enemy: "What the Arab forces did"+report.enemy_move: "{0} moved to a new position"+report.enemy_attack: "{0} launched an attack on one of your units"+report.enemy_fortify: "{0} fortified its position"+report.unit: "Force {0}"# The end screen (#812; D-H4): the sim's end report (EndReport.For, #810), formatted only. {0} the card's title, {1} the# player's date, {2} the historical date; the population's {1} is the date of its CBS anchor and {2} the anchor's count.end.title: "The game has ended"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex 0c157fd6a..f303924be 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -261,6 +261,14 @@ report.intro: "מה השתנה בסרגל העליון, ומה הסיבות העreport.line: "{0}: שינוי של {1}"report.all: "הכול במסך למה?"report.close: "סגירה"+# The enemy's orders this turn (#1293), {0} the unit's name: agent-drafted Hebrew, not yet read by a native speaker. The+# verbs are masculine, as every Arab force's name_he is (חיל, הלגיון, הצבא, צבא) and so is report.unit's כוח. For the+# native reviewer (#564).+report.enemy: "מה עשו הכוחות הערביים"+report.enemy_move: "{0} עבר לעמדה חדשה"+report.enemy_attack: "{0} פתח בהתקפה על אחת היחידות שלכם"+report.enemy_fortify: "{0} התבצר בעמדתו"+report.unit: "כוח {0}"# The end screen (#812; D-H4): the sim's end report, formatted only. For the native reviewer (#564).end.title: "המשחק הסתיים"end.outcome.mvp_ended: "המשחק הגיע לתורו האחרון."