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.

Unit card: artillery attack odds show 0 attacker losses (Fixes #2040) (#2045)

Beri371559dc5bcf
diff --git a/changelog.d/2040.md b/changelog.d/2040.md
new file mode 100644
index 000000000..ce94e7be1
--- /dev/null
+++ b/changelog.d/2040.md
@@ -0,0 +1,3 @@
+### Fixed
+- The unit card's attack odds for an artillery unit no longer say "you lose" people: the guns fire from behind the line, so
+ the bands show 0 attacker losses, as the strike itself costs (#2040).
diff --git a/sim/Statecraft.Sim.Tests/CombatTests.cs b/sim/Statecraft.Sim.Tests/CombatTests.cs
index 0505d4915..46d405885 100644
--- a/sim/Statecraft.Sim.Tests/CombatTests.cs
+++ b/sim/Statecraft.Sim.Tests/CombatTests.cs
@@ -13,6 +13,7 @@ public class CombatTests
const string Types = Fixture.GddUnitTypes
+ " - { id: soldier, kind: unit, side: israel, class: infantry, movement_points: 3 }\n"
+ " - { id: enemy, kind: unit, side: egypt, class: infantry, movement_points: 3 }\n"
+ + " - { id: gun, kind: unit, side: israel, class: artillery, movement_points: 2, range: 2, arms_per_fire: 3 }\n"
+ " - { id: ally, kind: unit, side: jordan, class: infantry, movement_points: 3 }\n";
/// <summary>MovementTests' 6 x 3 coastal plain, with <paramref name="biomes"/> replacing hexes; town_a is on (1, 0).</summary>
@@ -284,6 +285,20 @@ public class CombatTests
Assert.Equal(new[] { (2, 2, 0, 10, true) }, Combat.Outcomes(c, s, 1));
}
+ // R-COMBAT-007 (#2040): the guns fire from behind the line, so a strike by an artillery unit costs it nothing and its
+ // bands say 0 attackers lose; an infantry unit's bands are the row's as before.
+ [Fact]
+ public void AnArtilleryUnitsBandsShowNoAttackerLosses()
+ {
+ var c = Load();
+ var s = With(c, new Unit(1, "gun", 4, 0, side: "israel", strength: 2), Soldier(3, 1, 1, 5));
+ Assert.Equal(new[] { (2, 2, 0, 10, false) }, Combat.Outcomes(c, s, 0, 1));
+ Assert.Equal(new[] { (2, 2, 0, 10, true) }, Combat.Outcomes(c, s, 1, 1));
+ Assert.Equal(new[] { (2, 2, 10, 10, false) }, Combat.Outcomes(c, s, 0, 3));
+ Assert.Equal(Combat.Outcomes(c, s, 0), Combat.Outcomes(c, s, 0, 3));
+ Assert.Equal(Combat.Outcomes(c, s, 0), Combat.Outcomes(c, s, 0, 999)); // no such unit: the row as it is
+ }
+
// Q-UI-1: on the real table every row's bands cover its faces exactly once, in the order each outcome first appears, and
// no two bands are the same outcome.
[Fact]
diff --git a/sim/Statecraft.Sim/Combat.cs b/sim/Statecraft.Sim/Combat.cs
index 969d46c39..e723442b5 100644
--- a/sim/Statecraft.Sim/Combat.cs
+++ b/sim/Statecraft.Sim/Combat.cs
@@ -163,16 +163,18 @@ namespace Statecraft.Sim
/// <summary>The outcome bands of combat_table row <paramref name="row"/> (Q-UI-1: the card shows them beside Preview's
/// ratio): the row's faces with the same outcome taken together, in the order each first appears, each with how many
/// faces of <c>Of</c> give it, the people the attackers and the defenders lose (population units times
- /// mvp.people_per_unit, as the engagement's report counts them) and whether the defenders retreat.</summary>
- public static IReadOnlyList<(int Faces, int Of, int AttackersLose, int DefendersLose, bool Retreat)> Outcomes(Content c, GameState s, int row)
+ /// mvp.people_per_unit, as the engagement's report counts them) and whether the defenders retreat. When <paramref name="unitId"/>
+ /// names an artillery unit its attackers lose nothing (R-COMBAT-007, as <c>Engage</c> counts it: #2040).</summary>
+ public static IReadOnlyList<(int Faces, int Of, int AttackersLose, int DefendersLose, bool Retreat)> Outcomes(Content c, GameState s, int row, int? unitId = null)
{
PopulationLedger.RefuseAggregate(s);
var mvp = c.RulesAt(s.Date).Mvp!;
var t = mvp.CombatTable[row];
+ var guns = unitId is int id && s.Units.TryGetValue(id, out var u) && Guns(c, u);
var bands = new List<(int Faces, int Of, int AttackersLose, int DefendersLose, bool Retreat)>();
for (int i = 0; i < t.AttackerLoss.Count; i++)
{
- var face = (t.AttackerLoss[i] * mvp.PeoplePerUnit, t.DefenderLoss[i] * mvp.PeoplePerUnit, t.DefenderRetreats[i] == 1);
+ var face = ((guns ? 0 : t.AttackerLoss[i]) * mvp.PeoplePerUnit, t.DefenderLoss[i] * mvp.PeoplePerUnit, t.DefenderRetreats[i] == 1);
var k = bands.FindIndex(b => (b.AttackersLose, b.DefendersLose, b.Retreat) == face);
if (k >= 0) bands[k] = (bands[k].Faces + 1, bands[k].Of, bands[k].AttackersLose, bands[k].DefendersLose, bands[k].Retreat);
else bands.Add((1, t.AttackerLoss.Count, face.Item1, face.Item2, face.Item3));
diff --git a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
index 73d55f399..443a749d4 100644
--- a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
+++ b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
@@ -363,7 +363,7 @@ namespace Statecraft.Game.UI
// The enemy units there (Combat's defenders: a side, not Israel's; Check has made sure there is one).
var names = s.Units.Values.Where(u => u.Q == q && u.R == r && u.Side != "" && u.Side != Movement.PlayerSide).Select(u => unitName?.Invoke(u.Id)).Where(n => !string.IsNullOrEmpty(n)).ToList();
var who = names.Count > 0 ? string.Join(", ", names) : string.Format(CultureInfo.InvariantCulture, "{0},{1}", q, r);
- var bands = Combat.Outcomes(c, s, p.Row).Select(b => text.Format(b.Retreat ? "unit.attack_band_retreat" : "unit.attack_band",
+ var bands = Combat.Outcomes(c, s, p.Row, unit).Select(b => text.Format(b.Retreat ? "unit.attack_band_retreat" : "unit.attack_band",
b.Faces, b.Of, b.AttackersLose, b.DefendersLose));
return text.Format("unit.attack_odds", who, p.RatioPercent) + "\n" + string.Join("\n", bands); // one band a line
}