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.

fix: a unit raised in play draws a token and can be selected and moved (Fixes #1396) (#1448)

Eyal Golan703d87cf467d
diff --git a/changelog.d/1396.md b/changelog.d/1396.md
new file mode 100644
index 000000000..47b1417dc
--- /dev/null
+++ b/changelog.d/1396.md
@@ -0,0 +1,3 @@
+### Fixed
+
+- Units raised during play now draw on the map and can be selected and ordered.
diff --git a/unity/Assets/Scripts/Map/Units/UnitFigures.cs b/unity/Assets/Scripts/Map/Units/UnitFigures.cs
index b4b0e9365..9b853e46d 100644
--- a/unity/Assets/Scripts/Map/Units/UnitFigures.cs
+++ b/unity/Assets/Scripts/Map/Units/UnitFigures.cs
@@ -29,7 +29,8 @@ namespace Statecraft.Game.Map.Units
public const string SabraPioneer = "figure-c04-sabra-pioneer-v3", PioneerVeteran = "figure-c05-pioneer-veteran-v2",
YoungRecruit = "figure-c06-young-recruit-v2", VeteranFighter = "figure-c07-veteran-fighter-v2",
PalmachScout = "figure-c12f-palmach-scout-v2", Soldier1948 = "figure-soldier-1948-v1", ArabLegion = "figure-c08-arab-legion-v2", Irregular = "figure-c09-irregular-v2",
- Napoleonchik = "figure-vehicle-napoleonchik-65mm-1948-v2", WillysJeep = "figure-vehicle-willys-jeep-1948-v2";
+ Napoleonchik = "figure-vehicle-napoleonchik-65mm-1948-v2", WillysJeep = "figure-vehicle-willys-jeep-1948-v2",
+ SandwichArmouredCar = "figure-vehicle-sandwich-convoy-1948-v2";
/// <summary>An Israeli rifleman's figure by his headgear (the sourced <see cref="UnitEntry.Headgear"/>, or the uniform
/// default), as Tal Heuberger's figures wear them and #507 paired them: the bush (slouch) hat is the sabra pioneer (C04), the
diff --git a/unity/Assets/Scripts/Map/Units/UnitRoster.cs b/unity/Assets/Scripts/Map/Units/UnitRoster.cs
index 5f05e8c7e..cbab9751d 100644
--- a/unity/Assets/Scripts/Map/Units/UnitRoster.cs
+++ b/unity/Assets/Scripts/Map/Units/UnitRoster.cs
@@ -17,6 +17,11 @@ namespace Statecraft.Game.Map.Units
public string ArtType { get; }
/// <summary>An air unit flies over its base (security level 4 or 5) or stands parked on it.</summary>
public bool Flying { get; }
+ /// <summary>The sim unit represented by this token in the GDD loop; null for legacy and token-only rows.</summary>
+ public Unit? StateUnit { get; }
+ public int? SimId => StateUnit?.Id;
+ /// <summary>True when the sim formed this unit in play rather than from a starting-forces row.</summary>
+ public bool Raised { get; }
/// <summary>An army token's riflemen's headgear, one per figure in the trio's order (<see cref="UnitData.Headgears"/>);
/// empty for aircraft and ships.</summary>
public IReadOnlyList<string> Headgear { get; }
@@ -25,16 +30,20 @@ namespace Statecraft.Game.Map.Units
public IReadOnlyList<string> Vehicles { get; }
public UnitToken(UnitEntry unit, UnitAnchor anchor, int figures, string artType, bool flying, IReadOnlyList<string>? headgear = null,
- IReadOnlyList<string>? vehicles = null)
+ IReadOnlyList<string>? vehicles = null, Unit? stateUnit = null, bool raised = false)
{
Unit = unit; Anchor = anchor; Figures = figures; ArtType = artType; Flying = flying;
Headgear = headgear ?? Array.Empty<string>();
Vehicles = vehicles ?? Array.Empty<string>();
+ StateUnit = stateUnit; Raised = raised;
}
- public bool Equals(UnitToken? o) => o != null && ReferenceEquals(Unit, o.Unit) && ReferenceEquals(Anchor, o.Anchor)
+ public bool Equals(UnitToken? o) => o != null && (ReferenceEquals(Unit, o.Unit) || Raised && o.Raised && Unit.Id == o.Unit.Id)
+ && ReferenceEquals(Anchor, o.Anchor)
&& Figures == o.Figures && ArtType == o.ArtType && Flying == o.Flying && Headgear.SequenceEqual(o.Headgear)
- && Vehicles.SequenceEqual(o.Vehicles);
+ && Vehicles.SequenceEqual(o.Vehicles) && SimId == o.SimId && Raised == o.Raised
+ && (StateUnit == null && o.StateUnit == null || StateUnit != null && o.StateUnit != null
+ && StateUnit.Type == o.StateUnit.Type && StateUnit.Strength == o.StateUnit.Strength && StateUnit.HomeCity == o.StateUnit.HomeCity);
public override bool Equals(object? o) => Equals(o as UnitToken);
public override int GetHashCode() => HashCode.Combine(Unit.Id, Anchor.Place, Figures, ArtType, Flying);
public override string ToString() => $"{Unit.Id}@{Anchor.Place}:{ArtType}x{Figures}{(Headgear.Count > 0 ? "[" + string.Join("/", Headgear) + "]" : "")}{(Vehicles.Count > 0 ? "+" + string.Join("+", Vehicles) : "")}{(Flying ? " flying" : "")}";
@@ -115,9 +124,10 @@ namespace Statecraft.Game.Map.Units
/// tokens only, Q-UNIT-5). The sim hex is authoritative: a unit on its starting hex stands on its row's starting
/// anchor (that anchor's spot, UnitPlacer's one-hex offset included); a unit that moved takes
/// <paramref name="moved"/>'s anchor for its row and hex (the layer caches it with its spot). Its figures follow
- /// Q-UI-3 (<see cref="FiguresForStrength"/>), not the call-up. A unit is drawn only from a row: unit i of a new game is
- /// <c>content.StartingForces[i]</c> (R-UNIT-006), whose row is its card, flag and figures, and a unit with no row (a
- /// halutz; a unit raised in play, which has no art yet) draws no token. An Arab force's token still waits for its
+ /// Q-UI-3 (<see cref="FiguresForStrength"/>), not the call-up. Unit i of a new game uses
+ /// <c>content.StartingForces[i]</c> (R-UNIT-006) for its card, flag and figures. A military unit raised in play reuses
+ /// the first Israeli starting row as its figure default, with the existing gun or sandwich armoured car for those
+ /// types; a halutz still draws no token. An Arab force's token still waits for its
/// Collection figure (<paramref name="arrived"/>), and a row off the map (<see cref="OnMap"/>) draws nothing.
/// Pure and read-only like Build.</summary>
public static List<UnitToken> FromState(IReadOnlyList<UnitEntry> units, Content content, GameState state, Func<string, bool>? arrived,
@@ -130,9 +140,13 @@ namespace Statecraft.Game.Map.Units
var list = new List<UnitToken>();
foreach (var unit in state.Units.Values.OrderBy(v => v.Q).ThenBy(v => v.R).ThenBy(v => v.Id))
{
- // Unit i of a new game is StartingForces[i] (R-UNIT-006); a unit raised in play takes the next id, at or above
- // the count, and has no row yet (UnitsFromStateTests.AUnitRaisedInPlayDrawsNoToken).
- if (unit.Side == "" || unit.Id >= content.StartingForces.Count) continue;
+ if (unit.Side == "") continue; // a halutz is not a military token (R-UNIT-001)
+ if (unit.Id >= content.StartingForces.Count)
+ {
+ var raised = RaisedToken(units, content, unit, moved);
+ if (raised != null) list.Add(raised);
+ continue;
+ }
var force = content.StartingForces[unit.Id];
var row = units.FirstOrDefault(u => u.Id == force.Row);
if (row == null || !OnMap(row) || row.Service != UnitData.Army) continue;
@@ -143,16 +157,42 @@ namespace Statecraft.Game.Map.Units
if (row.Side != UnitData.Israel)
{
var figure = UnitFigures.SideFigure(row.Side)!;
- if (arrived != null && arrived(figure)) list.Add(new UnitToken(row, anchor, figures, figure, false));
+ if (arrived != null && arrived(figure)) list.Add(new UnitToken(row, anchor, figures, figure, false, stateUnit: unit));
continue;
}
var hats = (row.Headgear ?? (IReadOnlyList<string>)UnitData.DefaultHeadgear).Take(figures).ToList();
- list.Add(new UnitToken(row, anchor, figures, RiflemanType(hats[0]), false, hats, UnitFigures.VehiclesAt(row, state.Date)));
+ list.Add(new UnitToken(row, anchor, figures, RiflemanType(hats[0]), false, hats, UnitFigures.VehiclesAt(row, state.Date), unit));
}
list.AddRange(Build(units, content, state, arrived).Where(t => t.Unit.Service != UnitData.Army));
return list;
}
+ /// <summary>A raised Israeli military unit's presentation-only token. The first Israeli starting army row is the
+ /// existing neutral figure default and its sourced strength (currently four) is Q-UI-3's full-strength denominator.
+ /// Type changes only the already shipped figure set/vehicle. The synthetic row and anchor never enter sim state.</summary>
+ static UnitToken? RaisedToken(IReadOnlyList<UnitEntry> units, Content content, Unit unit,
+ Func<UnitEntry, UnitAnchor, int, int, UnitAnchor> moved)
+ {
+ if (unit.Side != UnitData.Israel || unit.Type != "recruit" && unit.Type != StartingForces.IsraeliBrigadeType
+ && unit.Type != "artillery" && unit.Type != "armoured_car") return null;
+ var force = content.StartingForces.FirstOrDefault(f => f.Side == UnitData.Israel && f.Type == StartingForces.IsraeliBrigadeType);
+ if (force == null) return null;
+ var visual = units.FirstOrDefault(u => u.Id == force.Row);
+ if (visual == null || visual.Service != UnitData.Army) return null;
+ var start = AnchorAt(visual, force.Arrives ?? content.Rules.Start) ?? visual.Anchors.FirstOrDefault();
+ if (start == null) return null;
+ var row = new UnitEntry
+ {
+ Id = $"raised-{unit.Id}", Service = UnitData.Army, Side = UnitData.Israel,
+ Headgear = unit.Type == "recruit" ? new List<string> { UnitData.SteelHelmet, UnitData.SteelHelmet, UnitData.SteelHelmet } : null,
+ };
+ int figures = FiguresForStrength(unit.Strength, force.Strength);
+ var hats = (row.Headgear ?? (IReadOnlyList<string>)UnitData.DefaultHeadgear).Take(figures).ToList();
+ IReadOnlyList<string> vehicles = unit.Type == "artillery" ? new[] { UnitFigures.Napoleonchik }
+ : unit.Type == "armoured_car" ? new[] { UnitFigures.SandwichArmouredCar } : Array.Empty<string>();
+ return new UnitToken(row, moved(row, start, unit.Q, unit.R), figures, RiflemanType(hats[0]), false, hats, vehicles, unit, raised: true);
+ }
+
/// <summary>Q-UI-3 (owner, 15 October 2026, "Take all recommendations"; #226, 17 October 2026): "3 figures at two
/// thirds or more of the type's full strength, 2 at a third or more, 1 below that". A unit's full strength is the
/// sourced strength it started with (Q-UNIT-4: a starting unit's Strength is its row's), so a new game draws every
diff --git a/unity/Assets/Scripts/UI/FirstTurnGuidePresenter.cs b/unity/Assets/Scripts/UI/FirstTurnGuidePresenter.cs
index c429d9e9f..7ef7c2a01 100644
--- a/unity/Assets/Scripts/UI/FirstTurnGuidePresenter.cs
+++ b/unity/Assets/Scripts/UI/FirstTurnGuidePresenter.cs
@@ -385,6 +385,10 @@ namespace Statecraft.Game.UI
public static string? UnitToShow(Content c, GameState s, IEnumerable<UnitEntry> units) =>
units.FirstOrDefault(u => UnitCard.SimUnit(c, s, u) is int id && Movement.Reachable(c, s, id).Count > 0)?.Id;
+ /// <summary>The drawn-token form used by the game. A raised token carries its sim id even without a starting row.</summary>
+ public static string? UnitToShow(Content c, GameState s, IEnumerable<UnitToken> units) =>
+ units.FirstOrDefault(u => UnitCard.SimUnit(c, s, u) is int id && Movement.Reachable(c, s, id).Count > 0)?.Unit.Id;
+
public void Dispose()
{
if (disposed) return;
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
index 70c0980dc..b074b9cd0 100644
--- a/unity/Assets/Scripts/UI/GameRoot.cs
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -347,14 +347,15 @@ namespace Statecraft.Game.UI
showUnits();
DiagLog.BootPhase("units layer built");
var localitiesAt = LocalitiesAt(map);
+ var townNamesHe = map.SettlementsFor(inputs.Map.SettlementsYaml).ToDictionary(s => s.Id, s => s.NameHe);
var info = this.info = Own(new InfoPanelPresenter(root, bridge, text, names, nav: nav,
selectedUnit: () => unitLayer.Selected is string id ? unitLayer.Tokens.First(p => p.Token.Unit.Id == id) : (Statecraft.Game.Map.Units.PlacedToken?)null,
regions: regions, localitiesAt: localitiesAt,
townHex: InfoPanelPresenter.TownHex(map.SettlementsFor(inputs.Map.SettlementsYaml), map.Hexes),
- townNamesHe: map.SettlementsFor(inputs.Map.SettlementsYaml).ToDictionary(s => s.Id, s => s.NameHe),
+ townNamesHe: townNamesHe,
showReachable: map.ShowReachable,
- unitName: id => unitLayer.Tokens.Where(p => UnitCard.SimUnit(bridge.Content, bridge.State, p.Token.Unit) == id)
- .Select(p => UnitCard.For(p, bridge.State, text, bridge.Content.IsGdd).Title).FirstOrDefault()));
+ unitName: id => unitLayer.Tokens.Where(p => UnitCard.SimUnit(bridge.Content, bridge.State, p.Token) == id)
+ .Select(p => UnitCard.For(p, bridge.State, text, bridge.Content.IsGdd, bridge.Content, townNamesHe).Title).FirstOrDefault()));
// A smoke session never touches the player's save: no autosave, and no New Game (which deletes the autosave).
// Leaving New Game out is safer than handing it a throwaway store: no file is ever deleted, no path has to be
// right on every platform, and the scripted run never presses it.
@@ -478,7 +479,7 @@ namespace Statecraft.Game.UI
};
Action showUnit = () =>
{
- if (FirstTurnGuidePresenter.UnitToShow(bridge.Content, bridge.State, unitLayer.Tokens.Select(t => t.Token.Unit)) is not string id) return;
+ if (FirstTurnGuidePresenter.UnitToShow(bridge.Content, bridge.State, unitLayer.Tokens.Select(t => t.Token)) is not string id) return;
unitLayer.Select(id);
if (unitLayer.Selected != null)
{
@@ -497,7 +498,7 @@ namespace Statecraft.Game.UI
var hex = info.ShowsUnit ? null : info.Selected;
var unit = info.ShowsUnit ? unitLayer.Selected : null;
var city = FirstTurnGuidePresenter.CityHex(bridge.Content, bridge.State);
- var guideUnit = FirstTurnGuidePresenter.UnitToShow(bridge.Content, bridge.State, unitLayer.Tokens.Select(t => t.Token.Unit));
+ var guideUnit = FirstTurnGuidePresenter.UnitToShow(bridge.Content, bridge.State, unitLayer.Tokens.Select(t => t.Token));
return () =>
{
// Under a screen, or the player picked another than the guide's city or unit: kept.
@@ -843,7 +844,7 @@ namespace Statecraft.Game.UI
if (hud.ClassListContains(EventCardPresenter.OpenClass)) { log("SMOKE FAIL the event card did not hide"); yield break; }
}
var move = GoldenRun.SmokeMove(bridge.Content, bridge.State);
- var token = units.Tokens.Where(p => UnitCard.SimUnit(bridge.Content, bridge.State, p.Token.Unit) == move.Unit)
+ var token = units.Tokens.Where(p => UnitCard.SimUnit(bridge.Content, bridge.State, p.Token) == move.Unit)
.Select(p => (Statecraft.Game.Map.Units.PlacedToken?)p).FirstOrDefault();
if (!(token is { } t)) { log(FormattableString.Invariant($"SMOKE FAIL unit {move.Unit} has no token on the map")); yield break; }
log(FormattableString.Invariant($"SMOKE ORDERS move unit {move.Unit} to {move.Q},{move.R}"));
diff --git a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
index ea7f33f0b..7ea05f384 100644
--- a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
+++ b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
@@ -180,7 +180,7 @@ namespace Statecraft.Game.UI
(int unit, IReadOnlyDictionary<(int Q, int R), int> hexes)? MoveTargets()
{
var unit = unitMode ? selectedUnit() : null;
- if (unit == null || bridge.State.GameOver != null || !(UnitCard.SimUnit(bridge.Content, bridge.State, unit.Value.Token.Unit) is int id)) return null;
+ if (unit == null || bridge.State.GameOver != null || !(UnitCard.SimUnit(bridge.Content, bridge.State, unit.Value.Token) is int id)) return null;
var reach = Movement.Reachable(bridge.Content, bridge.State, id);
return reach.Count == 0 ? null : (id, reach);
}
@@ -241,7 +241,7 @@ namespace Statecraft.Game.UI
int? OrderUnit()
{
var unit = unitMode ? selectedUnit() : null;
- return unit == null || bridge.State.GameOver != null ? null : UnitCard.SimUnit(bridge.Content, bridge.State, unit.Value.Token.Unit);
+ return unit == null || bridge.State.GameOver != null ? null : UnitCard.SimUnit(bridge.Content, bridge.State, unit.Value.Token);
}
/// <summary>Fortify, Hold or Send home's button: queues the sim's order for the shown unit (one per unit: another
@@ -398,7 +398,7 @@ namespace Statecraft.Game.UI
defenceButton.style.display = unit != null ? DisplayStyle.Flex : DisplayStyle.None;
// A pick read on another turn or session, or for a unit no longer shown, is over: its hexes are not the sim's now.
if (pick is { } open
- && (open.session != bridge.Session || open.turn != s.Turn || unit == null || UnitCard.SimUnit(c, s, unit.Value.Token.Unit) != open.unit))
+ && (open.session != bridge.Session || open.turn != s.Turn || unit == null || UnitCard.SimUnit(c, s, unit.Value.Token) != open.unit))
EndPick();
var moves = MoveTargets();
moveButton.style.display = moves != null ? DisplayStyle.Flex : DisplayStyle.None;
@@ -424,7 +424,7 @@ namespace Statecraft.Game.UI
panel.EnableInClassList(UnitClass, unit != null);
if (unit != null)
{
- var card = UnitCard.For(unit.Value, s, text, c.IsGdd);
+ var card = UnitCard.For(unit.Value, s, text, c.IsGdd, c, townNamesHe);
panel.EnableInClassList("info-empty", false);
// The orders' state under the card's lines: the pick asks for a hex (an attack's with each lit hex's odds, Q-UI-1);
// a queued Move, Fortify, Hold, Attack or Send home waits for End turn (an attack's with its hex's odds).
diff --git a/unity/Assets/Scripts/UI/UnitCard.cs b/unity/Assets/Scripts/UI/UnitCard.cs
index 810ed1608..83278f0c2 100644
--- a/unity/Assets/Scripts/UI/UnitCard.cs
+++ b/unity/Assets/Scripts/UI/UnitCard.cs
@@ -29,7 +29,13 @@ namespace Statecraft.Game.UI
return null;
}
- public static UnitCard For(PlacedToken placed, GameState state, UiText text, bool gddLoop = false)
+ /// <summary>The sim unit a drawn token represents. GDD tokens carry the id directly, including units raised after
+ /// the starting forces; row lookup remains the fallback for callers that construct an older token by hand.</summary>
+ public static int? SimUnit(Content c, GameState s, UnitToken token) =>
+ token.SimId is int id ? s.Units.ContainsKey(id) ? id : (int?)null : SimUnit(c, s, token.Unit);
+
+ public static UnitCard For(PlacedToken placed, GameState state, UiText text, bool gddLoop = false, Content? content = null,
+ IReadOnlyDictionary<string, string>? settlementNamesHe = null)
{
var t = placed.Token; var u = t.Unit; var a = t.Anchor;
bool hebrew = text["ui.lang"] == UiLanguage.Hebrew;
@@ -47,6 +53,23 @@ namespace Statecraft.Game.UI
? text.Format("date.month_year", text["date.month_" + m.Month], m.Year) : english;
}
var lines = new List<string>();
+ string? raisedType = t.Raised && t.StateUnit != null ? t.StateUnit.Type switch
+ {
+ "recruit" => text["city.track_recruit"],
+ StartingForces.IsraeliBrigadeType => text["unit.type.veteran_soldier"],
+ "artillery" => text["city.track_artillery"],
+ "armoured_car" => text["city.track_armoured_car"],
+ _ => null,
+ } : null;
+ string home = t.StateUnit != null && t.StateUnit.HomeCity != "" && content != null
+ && 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));
+ }
if (u.Service == UnitData.Air)
{
var aircraft = text[t.ArtType == UnitShowcase.SpitfireType ? "unit.aircraft.spitfire" : "unit.aircraft.s199"];
@@ -62,7 +85,7 @@ namespace Statecraft.Game.UI
if (!string.IsNullOrEmpty(u.Formed)) lines.Add(text.Format("unit.formed", Local(When(u.Formed!), u.FormedHe)));
// 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)));
- lines.Add(Local(u.Sector, u.SectorHe));
+ if (!t.Raised) lines.Add(Local(u.Sector, u.SectorHe)); // a raised unit has no sourced sector
// Israel's call-up and security level set only Israel's tokens; an Arab force's token reflects neither (#665).
var national = u.Side != UnitData.Israel ? ""
: !gddLoop ? text.Format("unit.national", PlayerText.Percent(state.Mobilization), state.Rung)
@@ -70,12 +93,14 @@ namespace Statecraft.Game.UI
var hosts = u.AllSources().Select(s => new Uri(s.Url).Host).Distinct(StringComparer.Ordinal).OrderBy(h => h, StringComparer.Ordinal);
return new UnitCard
{
- Title = text["ui.lang"] == UiLanguage.Hebrew && !string.IsNullOrEmpty(u.NameHe) ? u.NameHe : u.Name,
- Subtitle = text.Format("unit.subtitle", u.Number, text["unit.service." + u.Service]),
+ // A raised unit has no name or number: its type is the title, the service the subtitle (#1396).
+ Title = raisedType ?? (hebrew && !string.IsNullOrEmpty(u.NameHe) ? u.NameHe : u.Name),
+ Subtitle = raisedType == null ? text.Format("unit.subtitle", u.Number, text["unit.service." + u.Service])
+ : text["unit.service." + u.Service],
Body = string.Join("\n", lines),
- Footer = (national == "" ? "" : national + "\n")
+ Footer = t.Raised ? "" : (national == "" ? "" : national + "\n")
+ text.Format("unit.sources", string.Join(", ", hosts)),
- Note = (sourced ? UnitData.IsWikipediaOnly(a.Sources) : UnitData.IsWikipediaOnly(u)) ? text["unit.draft_wikipedia"] : text["unit.draft"],
+ Note = t.Raised ? "" : (sourced ? UnitData.IsWikipediaOnly(a.Sources) : UnitData.IsWikipediaOnly(u)) ? text["unit.draft_wikipedia"] : text["unit.draft"],
};
}
}
diff --git a/unity/Assets/Tests/EditMode/FirstTurnGuideTests.cs b/unity/Assets/Tests/EditMode/FirstTurnGuideTests.cs
index e100f03c1..9cc1c8fd3 100644
--- a/unity/Assets/Tests/EditMode/FirstTurnGuideTests.cs
+++ b/unity/Assets/Tests/EditMode/FirstTurnGuideTests.cs
@@ -44,7 +44,7 @@ public class FirstTurnGuideTests
() => { if (FirstTurnGuidePresenter.CityHex(bridge.Content, bridge.State) is (int q, int r)) info.Show(q, r); }, closeScreens,
showUnit: () =>
{
- if (!(FirstTurnGuidePresenter.UnitToShow(bridge.Content, bridge.State, tokens.Select(t => t.Unit)) is string id)) return;
+ if (!(FirstTurnGuidePresenter.UnitToShow(bridge.Content, bridge.State, tokens) is string id)) return;
shown = new PlacedToken(tokens.First(t => t.Unit.Id == id), new AnchorSpot(0, 0, 0, 0, false));
info.ShowUnit();
});
@@ -368,7 +368,7 @@ public class FirstTurnGuideTests
var move = Array.IndexOf(FirstTurnGuidePresenter.Steps, "move");
for (int i = 0; i < move; i++) UiTestKit.Press(Ui.Q<Button>("guide-next"));
Assert.AreEqual(move, guide.Step);
- var id = FirstTurnGuidePresenter.UnitToShow(bridge.Content, bridge.State, units.Tokens.Select(t => t.Token.Unit));
+ var id = FirstTurnGuidePresenter.UnitToShow(bridge.Content, bridge.State, units.Tokens.Select(t => t.Token));
Assert.IsNotNull(id, "precondition: a drawn unit can move");
Assert.AreEqual(id, units.Selected, "the guide's unit, with its ring");
Assert.IsTrue(info.ShowsUnit, "its card in the info panel");
@@ -410,10 +410,10 @@ public class FirstTurnGuideTests
Assert.AreEqual(move, guide.Step, "precondition: the guide is on its move step");
for (int frame = 0; frame < 5; frame++) yield return null;
- var id = FirstTurnGuidePresenter.UnitToShow(bridge.Content, bridge.State, units.Tokens.Select(t => t.Token.Unit));
+ var id = FirstTurnGuidePresenter.UnitToShow(bridge.Content, bridge.State, units.Tokens.Select(t => t.Token));
Assert.IsNotNull(id, "precondition: a drawn unit can move");
var token = units.Tokens.Single(t => t.Token.Unit.Id == id);
- var simUnit = UnitCard.SimUnit(bridge.Content, bridge.State, token.Token.Unit);
+ var simUnit = UnitCard.SimUnit(bridge.Content, bridge.State, token.Token);
Assert.IsNotNull(simUnit, "precondition: the guide's token has a sim unit");
var reachable = Movement.Reachable(bridge.Content, bridge.State, simUnit!.Value).Keys.ToList();
Assert.IsNotEmpty(reachable, "precondition: the guide's unit has a destination");
diff --git a/unity/Assets/Tests/EditMode/UnitsFromStateTests.cs b/unity/Assets/Tests/EditMode/UnitsFromStateTests.cs
index c5001795d..e34fdfdcf 100644
--- a/unity/Assets/Tests/EditMode/UnitsFromStateTests.cs
+++ b/unity/Assets/Tests/EditMode/UnitsFromStateTests.cs
@@ -11,6 +11,7 @@ using Statecraft.Sim;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
+using UnityEngine.UIElements;
/// <summary>GDD Phase 5 PR 14 (#753; impact plan §2.6): in the GDD loop the map's army tokens come from the sim's units
/// (GameState.Units), one per unit on its sim hex, and a token's figures follow Q-UI-3, not the call-up. The squadron and
@@ -20,6 +21,7 @@ public class UnitsFromStateTests
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);
/// <summary>A moved unit's anchor as the layer makes it: the hex's centre, made once per row and hex.</summary>
sealed class Moved
@@ -154,20 +156,93 @@ public class UnitsFromStateTests
Assert.AreEqual(UnitData.IsWikipediaOnly(t.Unit) ? text["unit.draft_wikipedia"] : text["unit.draft"], card.Note);
}
- /// <summary>A unit raised in play takes the next id, at or above <c>StartingForces.Count</c>, so it has no row and no art
- /// yet: it draws no token (UnitRoster.FromState's id check).</summary>
+ static Unit Raise(GameState s, string type = "recruit", int strength = 2)
+ {
+ var like = s.Units.Values.First(x => x.Side == UnitData.Israel);
+ var to = FreeNeighbour(s, like.Q, like.R);
+ var unit = new Unit(s.NextId++, type, to.q, to.r, side: UnitData.Israel, strength: strength, homeCity: "tel_aviv");
+ s.Units.Add(unit.Id, unit);
+ return unit;
+ }
+
+ /// <summary>#1396: each military type raised after the starting forces gets an army token on its sim hex. Its reusable
+ /// type default supplies the existing figures and vehicle, and Q-UI-3 supplies the figure count from strength.</summary>
+ [TestCase("recruit", 1, 1, null)]
+ [TestCase("veteran_soldier", 4, 3, null)]
+ [TestCase("artillery", 2, 2, UnitFigures.Napoleonchik)]
+ [TestCase("armoured_car", 4, 3, UnitFigures.SandwichArmouredCar)]
+ public void ARaisedUnitDrawsItsTypeAndStrengthOnItsHex(string type, int strength, int figures, string vehicle)
+ {
+ var s = NewGame();
+ var raised = Raise(s, type, strength);
+ var tokens = UnitRoster.FromState(Units, C, s, _ => true, new Moved().At);
+ var token = tokens.Single(t => t.SimId == raised.Id);
+ Assert.AreEqual(UnitData.Army, token.Unit.Service);
+ Assert.AreEqual(figures, token.Figures, "Q-UI-3 against the reused four-strength Israeli army default");
+ Assert.AreEqual(figures, token.Headgear.Count, "one existing figure per strength band");
+ if (vehicle == null) CollectionAssert.IsEmpty(token.Vehicles); else CollectionAssert.Contains(token.Vehicles, vehicle);
+ var hexes = MapBuilder.LoadHexes(Path.Combine(Paths.Content, "map", "hexes.json"));
+ Assert.AreEqual((raised.Q, raised.R), HexPicker.FromLonLat(token.Anchor.Lon, token.Anchor.Lat, hexes.bounds, hexes.hex_size_km));
+ }
+
+ /// <summary>#1396: the raised token has its own stable map id, so the same UnitLayer path as a starting unit selects it.</summary>
+ [Test]
+ public void ARaisedUnitCanBeSelected()
+ {
+ EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);
+ var map = new GameObject("MapScene").AddComponent<MapScene>();
+ try
+ {
+ map.Configure(Load("Terrain"), Load("SettlementMarker"), Load("HexSelection"), Load("Sea"), Load("MapFrame"));
+ Statecraft.Game.Map.Kits.KitPopulation.Use(Statecraft.Game.Map.Kits.KitPopulation.Parse(
+ File.ReadAllText(Path.Combine(Paths.Content, "map", Statecraft.Game.Map.Kits.KitPopulation.FileName))));
+ map.Build();
+ var s = NewGame();
+ var raised = Raise(s);
+ var layer = UnitLayer.Create(map, Units, C.Hexes, still: true);
+ Assert.IsTrue(layer.Show(C, s));
+ var token = layer.Tokens.Single(t => t.Token.SimId == raised.Id);
+ Assert.AreEqual(token.Token.Unit.Id, layer.UnitToSelectAt(token.Q, token.R));
+ layer.Select(token.Token.Unit.Id);
+ Assert.AreEqual(token.Token.Unit.Id, layer.Selected);
+ }
+ finally { UnityEngine.Object.DestroyImmediate(map.gameObject); }
+ }
+
+ /// <summary>#1396: a raised formation's card names its type, strength and home city, and routes Move to its real sim id.</summary>
+ [Test]
+ public void ARaisedUnitShowsItsCardAndMove()
+ {
+ using var ui = new UiTestKit();
+ var game = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
+ var raised = Raise(game.State);
+ var bridge = new SimBridge(game, Text);
+ var token = UnitRoster.FromState(Units, C, game.State, _ => true, new Moved().At).Single(t => t.SimId == raised.Id);
+ Assert.IsNotEmpty(Movement.Reachable(C, game.State, raised.Id), "precondition: the raised recruits can move");
+ PlacedToken? selected = new PlacedToken(token, new AnchorSpot(raised.Q, raised.R, 0, 0, false));
+ var info = new InfoPanelPresenter(ui.Root, bridge, Text, C.SettlementNames, selectedUnit: () => selected);
+ info.ShowUnit();
+ Assert.AreEqual(Text["city.track_recruit"], ui.Q<Label>("info-title").text);
+ Assert.AreEqual(Text["unit.service.army"], ui.Q<Label>("info-subtitle").text);
+ Assert.AreEqual(Text.Format("unit.strength", raised.Strength) + "\n" + Text.Format("unit.home_city", C.SettlementNames[raised.HomeCity]),
+ ui.Q<Label>("info-settlements").text, "strength and home city, and no empty sector line");
+ Assert.AreEqual(DisplayStyle.Flex, ui.Q<Button>("info-move").style.display.value);
+ Assert.AreEqual(Text["unit.order.move"], ui.Q<Button>("info-move").text);
+ info.Dispose();
+ }
+
+ /// <summary>#1396 is additive: giving a raised unit a default token does not change any starting unit's row, art or anchor.</summary>
[Test]
- public void AUnitRaisedInPlayDrawsNoToken()
+ public void StartingUnitsAreUnchangedWhenARaisedUnitIsDrawn()
{
var s = NewGame();
- var units = Units;
- var before = Army(UnitRoster.FromState(units, C, s, _ => true, new Moved().At));
- Assert.IsNotEmpty(before);
- var like = s.Units.Values.First(x => x.Side == "israel");
- var to = FreeNeighbour(s, like.Q, like.R);
- Assert.GreaterOrEqual(s.NextId, C.StartingForces.Count, "ids below the count are the starting forces");
- s.Units.Add(s.NextId, new Unit(s.NextId, like.Type, to.q, to.r, side: like.Side, strength: like.Strength)); s.NextId++;
- CollectionAssert.AreEqual(before, Army(UnitRoster.FromState(units, C, s, _ => true, new Moved().At)), "the raised unit draws nothing");
+ var units = Units; // one parse: a token's row is compared by reference
+ var moved = new Moved();
+ var before = UnitRoster.FromState(units, C, s, _ => true, moved.At);
+ var raised = Raise(s);
+ var after = UnitRoster.FromState(units, C, s, _ => true, moved.At);
+ CollectionAssert.AreEqual(before, after.Where(t => t.SimId != raised.Id).ToList());
+ Assert.AreEqual(before.Count + 1, after.Count);
}
/// <summary>Review point 3 on #1205: in the GDD loop the call-up no longer sets the figures, so the card's footer does not
diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yaml
index e8b334ad6..800bceaaf 100644
--- a/unity/Assets/UI/strings.en.yaml
+++ b/unity/Assets/UI/strings.en.yaml
@@ -433,6 +433,10 @@ unit.subtitle: "{0} · {1}"
unit.service.army: "Army"
unit.service.air: "Air Force"
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}"
+unit.home_city: "Home city: {0}"
unit.position: "At {0} since {1}"
unit.position_plain: "At {0}"
unit.formed: "Formed {0}"
diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yaml
index 866b52781..355531455 100644
--- a/unity/Assets/UI/strings.he.yaml
+++ b/unity/Assets/UI/strings.he.yaml
@@ -452,6 +452,10 @@ unit.subtitle: "{0} · {1}"
unit.service.army: "צבא היבשה"
unit.service.air: "חיל האוויר"
unit.service.navy: "חיל הים"
+# טיוטות לכרטיס של יחידה שהוקמה במהלך המשחק (#1396); agent-checked, native review pending (#564).
+unit.type.veteran_soldier: "חיילים ותיקים"
+unit.strength: "כוח: {0}"
+unit.home_city: "עיר הבית: {0}"
unit.position: "מיקום: {0}, מאז {1}"
unit.position_plain: "מיקום: {0}"
unit.formed: "הוקמה: {0}"