Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Units: the card states every military unit's strength, "of" its full once damaged (#2432, PR 1) (#2960)

Eyal Golanebda274ff09a
diff --git a/changelog.d/c30-2432-damaged-units.md b/changelog.d/c30-2432-damaged-units.md
new file mode 100644
index 000000000..4c54295e4
--- /dev/null
+++ b/changelog.d/c30-2432-damaged-units.md
@@ -0,0 +1,2 @@
+- The unit card states every military unit's strength on both sides, and once a unit has lost strength it reads
+ "Strength: 3 of 4", from the live state, so it clears when the unit is reinforced to full (#2432).
diff --git a/unity/Assets/Scripts/Map/Units/UnitDamage.cs b/unity/Assets/Scripts/Map/Units/UnitDamage.cs
new file mode 100644
index 000000000..28665b4c9
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Units/UnitDamage.cs
@@ -0,0 +1,30 @@
+#nullable enable
+using Statecraft.Sim;
+
+namespace Statecraft.Game.Map.Units
+{
+ /// <summary>#2432: whether a military unit has lost strength, and against what, for the map's damaged look and the unit
+ /// card. Presentation only: it reads the sim's state and writes nothing to the sim or a save. A player's unit stores the
+ /// strength it had before its first loss as its <see cref="Unit.Full"/> (R-COMBAT-003 with R-TRAIN-004) and a refill to
+ /// full clears it, so the look clears when the unit is reinforced; the sim's own <see cref="Training.Room"/> reads the
+ /// same "Full, or the strength while it has lost none". An enemy's unit stores no Full (no rule reads one), so its full
+ /// strength is its starting force's (unit i of a new game is <c>StartingForces[i]</c>, R-UNIT-006), which is also Q-UI-3's
+ /// denominator for its figures (<see cref="UnitRoster.FiguresForStrength"/>).</summary>
+ public static class UnitDamage
+ {
+ /// <summary><paramref name="u"/>'s full strength: its Full once it has lost strength, else for an enemy's unit its
+ /// starting force's strength (never below its strength now), else its strength. <paramref name="c"/> may be null (the
+ /// legacy loop's callers): an enemy's unit then reads as full.</summary>
+ public static int FullStrength(Content? c, Unit u)
+ {
+ if (u.Full > 0) return u.Full;
+ if (c != null && u.Side != "" && u.Side != Movement.PlayerSide && u.Id >= 0 && u.Id < c.StartingForces.Count
+ && c.StartingForces[u.Id].Side == u.Side)
+ return System.Math.Max(u.Strength, c.StartingForces[u.Id].Strength);
+ return u.Strength;
+ }
+
+ /// <summary>True for a military unit (a halutz is not one, R-UNIT-001) below its <see cref="FullStrength"/>.</summary>
+ public static bool Damaged(Content? c, Unit u) => u.Side != "" && u.Strength < FullStrength(c, u);
+ }
+}
diff --git a/unity/Assets/Scripts/Map/Units/UnitDamage.cs.meta b/unity/Assets/Scripts/Map/Units/UnitDamage.cs.meta
new file mode 100644
index 000000000..07fdcaf04
--- /dev/null
+++ b/unity/Assets/Scripts/Map/Units/UnitDamage.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 0ceff0df4f1f449793aeabae19e34eb5
\ No newline at end of file
diff --git a/unity/Assets/Scripts/UI/UnitCard.cs b/unity/Assets/Scripts/UI/UnitCard.cs
index d92c9c5f9..c2d86bd5c 100644
--- a/unity/Assets/Scripts/UI/UnitCard.cs
+++ b/unity/Assets/Scripts/UI/UnitCard.cs
@@ -10,7 +10,8 @@ using Statecraft.Sim;
namespace Statecraft.Game.UI
{
/// <summary>The info panel's text for a selected unit (its orders so far, Move, Fortify, Hold and Attack, are the panel's: InfoPanelPresenter; the panel also links to the Defence screen):
- /// its name, number (Hebrew where the row has a sourced one, #1219) and service; where it stands, and since when only from a sourced start (the anchor's `since`,
+ /// its name, number (Hebrew where the row has a sourced one, #1219) and service; a military sim unit's strength, "of" its
+ /// full strength once it has lost some (#2432, UnitDamage), on the Formed line where the row has one; where it stands, and since when only from a sourced start (the anchor's `since`,
/// never the game's first day: review I1); its formation and first commander where sourced; the sector in the
/// source's words; on Israel's units, the national values its token reflects (legacy loop: the reserve call-up sets an
/// army token's figures, the security level whether the aircraft fly; GDD loop: the unit's strength sets the figures,
@@ -73,11 +74,19 @@ namespace Statecraft.Game.UI
&& content.SettlementNames.TryGetValue(t.StateUnit.HomeCity, out var city) ? city : "";
if (hebrew && t.StateUnit != null && settlementNamesHe != null
&& settlementNamesHe.TryGetValue(t.StateUnit.HomeCity, out var cityHe) && !string.IsNullOrWhiteSpace(cityHe)) home = cityHe;
- if (raisedType != null && t.StateUnit != null)
- {
- lines.Add(text.Format("unit.strength", t.StateUnit.Strength));
- if (home != "") lines.Add(text.Format("unit.home_city", home));
- }
+ // Every military sim unit, on both sides, states its strength, read from the live state rather than the token's
+ // copy (a token is redrawn only when the map rebuilds); once it has lost strength, against its full strength
+ // (#2432), so the keyboard path and a screen reader get the number the map's look shows. A row with a Formed
+ // date takes it on that line, not a line of its own: a new line made the panel one line taller, and on a phone
+ // upright it covered the advisor's move-step unit (AdvisorOpeningParityTests.TheMoveStepShowsTheUnitAndAReachableHexOnTheMap).
+ var live = t.SimId is int sid && state.Units.TryGetValue(sid, out var now) ? now : t.StateUnit;
+ string strength = live == null || live.Side == "" ? ""
+ : UnitDamage.Damaged(content, live)
+ ? text.Format("unit.strength_of", live.Strength, UnitDamage.FullStrength(content, live))
+ : text.Format("unit.strength", live.Strength);
+ bool formed = !string.IsNullOrEmpty(u.Formed);
+ if (strength != "" && (raisedType != null || !formed)) lines.Add(strength);
+ if (raisedType != null && home != "") lines.Add(text.Format("unit.home_city", home));
if (u.Service == UnitData.Air)
{
var aircraft = text[t.ArtType == UnitShowcase.SpitfireType ? "unit.aircraft.spitfire" : "unit.aircraft.s199"];
@@ -90,7 +99,11 @@ namespace Statecraft.Game.UI
var place = Local(a.Place, a.PlaceHe);
lines.Add(string.IsNullOrWhiteSpace(a.Since) ? text.Format("unit.position_plain", place) : text.Format("unit.position", place, Local(When(a.Since!), a.SinceHe)));
}
- if (!string.IsNullOrEmpty(u.Formed)) lines.Add(text.Format("unit.formed", Local(When(u.Formed!), u.FormedHe)));
+ if (formed)
+ {
+ var when = text.Format("unit.formed", Local(When(u.Formed!), u.FormedHe));
+ lines.Add(strength != "" && raisedType == null ? text.Format("unit.formed_strength", when, strength) : when);
+ }
// The English decides whether the line exists: a Hebrew commander never adds one (owner, #558).
if (!string.IsNullOrEmpty(u.FirstCommander)) lines.Add(text.Format("unit.commander", Local(u.FirstCommander!, u.FirstCommanderHe)));
// A raised unit has no sourced sector. A Hebrew sector can name a ship or an agency in Latin ("HMCS Norsyd",
diff --git a/unity/Assets/Tests/EditMode/UnitDamageTests.cs b/unity/Assets/Tests/EditMode/UnitDamageTests.cs
new file mode 100644
index 000000000..4d7934f06
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/UnitDamageTests.cs
@@ -0,0 +1,175 @@
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game;
+using Statecraft.Game.Map;
+using Statecraft.Game.Map.Units;
+using Statecraft.Game.UI;
+using Statecraft.Sim;
+using UnityEditor;
+using UnityEngine;
+
+/// <summary>#2432 PR 1: what the map and the unit card read to show that a formation is damaged and how badly. Presentation
+/// only: <see cref="UnitDamage"/> reads <see cref="Unit.Strength"/> and <see cref="Unit.Full"/> (R-TRAIN-004's "the strength
+/// it had before its first loss", cleared by a refill to full) and the starting force's strength for an enemy unit, which
+/// stores no Full (R-COMBAT-003); it writes nothing to the sim or a save. The card states the strength for every military unit
+/// on both sides, in English and Hebrew, so the keyboard path and a screen reader get the number too.</summary>
+public class UnitDamageTests
+{
+ static readonly Content C = ContentLoader.Load(Paths.Content);
+ static List<UnitEntry> Units => UnitData.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", UnitData.DefaultFileName)));
+ static GameState NewGame() => Simulation.NewGame(C, GoldenRun.Seed, Mode.Historical).Clone();
+ static UiText Text => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);
+ static UiText He => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");
+
+ static Unit WithStrength(Unit u, int strength, int full) =>
+ new Unit(u.Id, u.Type, u.Q, u.R, u.Service, u.Side, strength, u.Order, u.OrderTarget, u.HomeCity, full, u.CombatXp);
+
+ /// <summary>A new game: every military unit, on both sides, stands at its full strength, which is its strength.</summary>
+ [Test]
+ public void EveryUnitStartsAtFullStrength()
+ {
+ var s = NewGame();
+ var military = s.Units.Values.Where(u => u.Side != "").ToList();
+ Assert.That(military.Any(u => u.Side == Movement.PlayerSide) && military.Any(u => u.Side != Movement.PlayerSide), "precondition: both sides");
+ foreach (var u in military)
+ {
+ Assert.AreEqual(u.Strength, UnitDamage.FullStrength(C, u), $"unit {u.Id} ({u.Side})");
+ Assert.IsFalse(UnitDamage.Damaged(C, u), $"unit {u.Id} ({u.Side})");
+ }
+ }
+
+ /// <summary>R-COMBAT-003 with R-TRAIN-004: a player's unit that lost strength keeps the strength it had as its Full; the
+ /// look reads that as its full strength. An enemy's stores none, so its starting force's strength is its full.</summary>
+ [Test]
+ public void ALossReadsAsDamagedOnBothSides()
+ {
+ var s = NewGame();
+ var own = s.Units.Values.First(u => u.Side == Movement.PlayerSide && u.Strength >= 2);
+ var lost = WithStrength(own, own.Strength - 1, own.Strength);
+ Assert.AreEqual((own.Strength - 1, own.Strength), (lost.Strength, UnitDamage.FullStrength(C, lost)));
+ Assert.IsTrue(UnitDamage.Damaged(C, lost));
+
+ var enemy = s.Units.Values.First(u => u.Side != "" && u.Side != Movement.PlayerSide && u.Strength >= 2);
+ var hit = WithStrength(enemy, enemy.Strength - 1, 0); // Combat.Lose stores no Full for an enemy
+ Assert.AreEqual(C.StartingForces[enemy.Id].Strength, UnitDamage.FullStrength(C, hit));
+ Assert.IsTrue(UnitDamage.Damaged(C, hit));
+ }
+
+ /// <summary>A halutz group is not a military unit (R-UNIT-001): never damaged. A unit raised in play is at its full
+ /// strength until its first loss (its Full is 0 until then, as Training.Room reads it).</summary>
+ [Test]
+ public void AHalutzAndAFreshRaisedUnitAreNotDamaged()
+ {
+ Assert.IsFalse(UnitDamage.Damaged(C, new Unit(999, "halutz", 0, 0)));
+ var raised = new Unit(998, "recruit", 0, 0, side: Movement.PlayerSide, strength: 1, homeCity: "tel_aviv");
+ Assert.AreEqual(1, UnitDamage.FullStrength(C, raised));
+ Assert.IsFalse(UnitDamage.Damaged(C, raised));
+ }
+
+ /// <summary>The look follows the sim through a reinforce (#2432, "clear when the unit is reinforced"): the sim's own
+ /// Reinforce and training progress refill the unit, and it reads as full again.</summary>
+ [Test]
+ public void AReinforceClearsTheDamage()
+ {
+ var s = NewGame();
+ var city = C.SettlementHexes.Single(h => h.Id == "tel_aviv");
+ var u = s.Units.Values.First(x => x.Side == Movement.PlayerSide && x.Strength >= 3);
+ s.Units[u.Id] = new Unit(u.Id, u.Type, city.Q, city.R, u.Service, u.Side, u.Strength - 2, "", "", u.HomeCity, u.Strength, u.CombatXp);
+ s.Arms = 100;
+ Assert.IsTrue(UnitDamage.Damaged(C, s.Units[u.Id]));
+ Assert.IsNull(Training.Reinforce(C, s, u.Id, city.Id, 2, new List<Cause>()), "the sim takes the reinforce");
+ for (int turn = 0; turn < 20 && s.Units[u.Id].Full != 0; turn++) Training.Progress(C, s, new List<Cause>());
+ Assert.AreEqual((u.Strength, 0), (s.Units[u.Id].Strength, s.Units[u.Id].Full), "precondition: refilled to full");
+ Assert.IsFalse(UnitDamage.Damaged(C, s.Units[u.Id]));
+ }
+
+ /// <summary>The guards in <see cref="UnitDamage.FullStrength"/>: a Full of 0 or below is unset; a player's unit with no
+ /// Full reads its own strength (Training.Room's reading), never its starting force's; an enemy's unit reads its starting
+ /// force's strength only for a known content, an id inside StartingForces and a row of its own side, and never below its
+ /// strength now (the Max). Each assert goes red if its guard is removed.</summary>
+ [Test]
+ public void TheFullStrengthGuardsHold()
+ {
+ var s = NewGame();
+ var own = s.Units.Values.First(u => u.Side == Movement.PlayerSide && u.Strength >= 2);
+ Assert.AreEqual(own.Strength - 1, UnitDamage.FullStrength(C, WithStrength(own, own.Strength - 1, 0)),
+ "a player's unit with Full unset reads its strength, not its starting force's");
+ Assert.AreEqual(own.Strength - 1, UnitDamage.FullStrength(C, WithStrength(own, own.Strength - 1, -1)),
+ "a negative Full is unset");
+ Assert.IsFalse(UnitDamage.Damaged(C, WithStrength(own, own.Strength - 1, 0)));
+
+ var enemy = s.Units.Values.First(u => u.Side != "" && u.Side != Movement.PlayerSide && u.Strength >= 2);
+ int start = C.StartingForces[enemy.Id].Strength;
+ var over = WithStrength(enemy, start + 1, 0);
+ Assert.AreEqual(start + 1, UnitDamage.FullStrength(C, over), "an enemy above its start reads its strength (the Max)");
+ Assert.IsFalse(UnitDamage.Damaged(C, over));
+
+ var hit = WithStrength(enemy, enemy.Strength - 1, 0);
+ Assert.AreEqual(enemy.Strength - 1, UnitDamage.FullStrength(null, hit), "no content: an enemy reads as full");
+ Assert.IsFalse(UnitDamage.Damaged(null, hit));
+
+ var past = new Unit(C.StartingForces.Count, enemy.Type, 0, 0, side: enemy.Side, strength: 1);
+ Assert.AreEqual(1, UnitDamage.FullStrength(C, past), "an id past StartingForces reads its strength");
+ var negative = new Unit(-1, enemy.Type, 0, 0, side: enemy.Side, strength: 1);
+ Assert.AreEqual(1, UnitDamage.FullStrength(C, negative), "a negative id reads its strength");
+
+ int ownRow = Enumerable.Range(0, C.StartingForces.Count)
+ .First(i => C.StartingForces[i].Side == Movement.PlayerSide && C.StartingForces[i].Strength >= 2);
+ var mismatch = new Unit(ownRow, enemy.Type, 0, 0, side: enemy.Side, strength: 1);
+ Assert.AreEqual(1, UnitDamage.FullStrength(C, mismatch), "an enemy unit on a player's row reads its own strength");
+ Assert.IsFalse(UnitDamage.Damaged(C, mismatch));
+ }
+
+ /// <summary>The card states the strength for every military unit, from the live state (not the token's copy): the plain
+ /// text at full strength, "of" its full strength once damaged, in English and Hebrew. A row with a Formed date takes it
+ /// at the end of that line, so the card gets no new line (a new one covered the advisor's move-step unit on a phone,
+ /// AdvisorOpeningParityTests); a row without one has it as its first line. Each side's rows of each kind are checked.</summary>
+ [Test]
+ public void TheCardStatesTheStrengthOnBothSides()
+ {
+ var kinds = new HashSet<(bool side, bool formed)>();
+ foreach (var t in new[] { Text, He })
+ {
+ var s = NewGame();
+ var formedPrefix = t.Format("unit.formed", "");
+ foreach (var side in new[] { true, false })
+ foreach (var formed in new[] { true, false })
+ {
+ var token = UnitRoster.FromState(Units, C, s, _ => true, (row, a, q, r) => a)
+ .FirstOrDefault(x => !x.Raised && x.StateUnit is Unit d && (d.Side == Movement.PlayerSide) == side && d.Strength >= 2
+ && !string.IsNullOrEmpty(x.Unit.Formed) == formed);
+ if (token == null) continue; // no row of this kind on this side
+ kinds.Add((side, formed));
+ var u = s.Units[token.SimId!.Value];
+ string[] Lines() => UnitCard.For(new PlacedToken(token, default), s, t, true, C).Body.Split('\n');
+ void States(string strength, string what)
+ {
+ var lines = Lines();
+ if (!formed) { Assert.AreEqual(strength, lines[0], what); return; }
+ CollectionAssert.DoesNotContain(lines, strength, what + ": no strength line of its own");
+ var line = lines.Single(l => l.StartsWith(formedPrefix, System.StringComparison.Ordinal));
+ StringAssert.EndsWith(" · " + strength, line, what + ": on the Formed line");
+ }
+ States(t.Format("unit.strength", u.Strength), $"{u.Side} at full strength (formed: {formed})");
+ s.Units[u.Id] = WithStrength(u, u.Strength - 1, side ? u.Strength : 0);
+ States(t.Format("unit.strength_of", u.Strength - 1, UnitDamage.FullStrength(C, u)),
+ $"{u.Side} damaged (formed: {formed}): the card reads the state, the token is the one drawn before the loss");
+ s.Units[u.Id] = u;
+ }
+ }
+ Assert.IsTrue(kinds.Contains((true, true)), "precondition: a player's row with a Formed date was checked");
+ Assert.IsTrue(kinds.Contains((false, true)) || kinds.Contains((false, false)), "precondition: an enemy's row was checked");
+ }
+
+ /// <summary>The squadron and the ships are tokens only (Q-UNIT-5): no sim unit, so no strength line.</summary>
+ [Test]
+ public void ATokenOnlyRowHasNoStrengthLine()
+ {
+ var s = NewGame(); s.Date = new System.DateTime(1948, 7, 1);
+ var air = UnitRoster.FromState(Units, C, s, _ => true, (row, a, q, r) => a).First(t => t.Unit.Service == UnitData.Air);
+ var body = UnitCard.For(new PlacedToken(air, default), s, Text, true, C).Body;
+ StringAssert.DoesNotContain("Strength", body);
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/UnitDamageTests.cs.meta b/unity/Assets/Tests/EditMode/UnitDamageTests.cs.meta
new file mode 100644
index 000000000..998bcdbac
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/UnitDamageTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: f2d2f920989f4cdca0577f682d2fd048
\ No newline at end of file
diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yaml
index b615e469d..e18646d8d 100644
--- a/unity/Assets/UI/strings.en.yaml
+++ b/unity/Assets/UI/strings.en.yaml
@@ -730,10 +730,16 @@ unit.service.navy: "Navy"
# A formation raised in play has no historical unit row: its card uses the sim's type, strength and home city (#1396).
unit.type.veteran_soldier: "Veteran soldiers"
unit.strength: "Strength: {0}"
+# A damaged formation (#2432): {0} its strength now, {1} its full strength (R-TRAIN-004: the strength before its first loss;
+# an enemy unit's, its starting force's), in population units as unit.strength.
+unit.strength_of: "Strength: {0} of {1}"
unit.home_city: "Home city: {0}"
unit.position: "At {0} since {1}"
unit.position_plain: "At {0}"
unit.formed: "Formed {0}"
+# A unit's Formed line with its strength (#2432): {0} unit.formed, {1} unit.strength or unit.strength_of, on one line so the
+# card is no taller than before the strength was shown.
+unit.formed_strength: "{0} · {1}"
unit.commander: "First commander: {0}"
unit.aircraft.s199: "Avia S-199"
unit.aircraft.spitfire: "Supermarine Spitfire LF Mk IXe"
diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yaml
index 28cb30f7b..4e0aef3d0 100644
--- a/unity/Assets/UI/strings.he.yaml
+++ b/unity/Assets/UI/strings.he.yaml
@@ -851,11 +851,15 @@ unit.service.navy: "חיל הים"
# native review: owner, 3 Nov 2026 (HE batch 4: "Approve all as they are").
unit.type.veteran_soldier: "חיילים ותיקים"
unit.strength: "כוח: {0}"
+# For the native reviewer (#564): agent-drafted (#2432), as unit.points' "{0} מתוך {1}".
+unit.strength_of: "כוח: {0} מתוך {1}"
unit.home_city: "עיר הבית: {0}"
# Agent-checked; native review pending (#564).
unit.position: "מיקום: {0}, מאז {1}"
unit.position_plain: "מיקום: {0}"
unit.formed: "הוקמה: {0}"
+# For the native reviewer (#564): agent-drafted (#2432), as unit.subtitle's "{0} · {1}".
+unit.formed_strength: "{0} · {1}"
unit.commander: "מפקד ראשון: {0}"
unit.aircraft.s199: "אוויה S-199"
unit.aircraft.spitfire: "ספיטפייר LF Mk IXe"