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.

Why lines: the Food import and a conversion's reserves drop add their causes (Refs #2527) (#2529)

agamrafaeli-instinct0167dd981a71
diff --git a/changelog.d/2527-why-lines.md b/changelog.d/2527-why-lines.md
new file mode 100644
index 000000000..769c68301
--- /dev/null
+++ b/changelog.d/2527-why-lines.md
@@ -0,0 +1,4 @@
+### Fixed
+- The month's Food import and a dollar conversion each add their Why line, and a Food shortage's line is
+ informational, so the turn report's Food row and the HUD's foreign-currency meter no longer show a change without
+ its reason, and the Food row's lines add up to its change (#2527).
diff --git a/sim/Statecraft.Sim.Tests/DollarsTests.cs b/sim/Statecraft.Sim.Tests/DollarsTests.cs
index a920f77c1..b2acf0734 100644
--- a/sim/Statecraft.Sim.Tests/DollarsTests.cs
+++ b/sim/Statecraft.Sim.Tests/DollarsTests.cs
@@ -35,13 +35,28 @@ public class DollarsTests
var r = Orders(c, s, new ConvertDollars(3));
Assert.Empty(r.Rejected);
Assert.Equal((2.5, 0.0, 47.0, 3), (r.State.Treasury, r.State.Debt, r.State.FxReserves, r.State.DollarsConverted));
- var line = Assert.Single(r.Why, w => w.Key == CauseKeys.DollarsConverted);
+ var line = Assert.Single(r.Why, w => w.Key == CauseKeys.DollarsConverted && w.Target == "treasury");
Assert.Equal(("economy", "treasury", 1.5), (line.System, line.Target, line.Delta));
Assert.Equal(new[] { "3" }, line.Args);
Assert.Contains(CauseKeys.DollarsConverted, CauseKeys.All); // so the UI words it (CauseText)
Assert.Equal("Converted $3.0m of foreign currency into Money: " + PlayerText.MoneyChange(c, "treasury", 1.5), line.Message);
}
+ // #2527: the same conversion also explains the reserves' drop, so the HUD's foreign-currency meter (which lists the
+ // causes aimed at fx_reserves, HudModel.cs) shows its reason.
+ [Fact]
+ public void TheConversionAlsoExplainsTheReservesDrop()
+ {
+ var c = Gdd();
+ var s = War(c);
+ var r = Orders(c, s, new ConvertDollars(3));
+ Assert.Empty(r.Rejected);
+ var fx = Assert.Single(r.Why, w => w.Key == CauseKeys.DollarsConvertedFx);
+ Assert.Equal(("economy", -3.0), (fx.System, fx.Delta));
+ Assert.Equal(new[] { "3" }, fx.Args);
+ Assert.Equal("Foreign currency converted into Money: " + PlayerText.MoneyChange(c, "fx_reserves", -3.0), fx.Message);
+ }
+
// R-MONEY-004: the rate is the one in force on the turn's date (mvp.il_per_dollar, each rate from its day on).
[Theory]
[InlineData("1948-08-14", 1.0)] [InlineData("1948-08-15", 0.5)] [InlineData("1949-01-15", 0.5)]
diff --git a/sim/Statecraft.Sim.Tests/PoolsTests.cs b/sim/Statecraft.Sim.Tests/PoolsTests.cs
index cd8be04f0..065aea36e 100644
--- a/sim/Statecraft.Sim.Tests/PoolsTests.cs
+++ b/sim/Statecraft.Sim.Tests/PoolsTests.cs
@@ -62,6 +62,52 @@ public class PoolsTests
Assert.Equal(0.4, next.Indicators["food_supply"]);
}
+ // #2527: the month's eating and the import top-up add their own Why line, and the Food row's lines add up to the
+ // stock's change (the line nets the eating and the import, so it stays silent in a steady turn and matches the
+ // change when the stock starts under cover).
+ [Fact]
+ public void TheEatingAndImportAddTheirOwnWhyLineAndTheFoodLinesAddUp()
+ {
+ var c = Gdd();
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ s.Food = 150; // under the 300 of cover, so the month's eating and import show a net +150
+ var r = StepWithWhy(c, s);
+ Assert.Equal(300, r.State.Food);
+ var line = Assert.Single(r.Why, w => w.Key == CauseKeys.FoodImported);
+ Assert.Equal(("economy", "food", 150.0), (line.System, line.Target, line.Delta));
+ Assert.Equal(new[] { "300" }, line.Args);
+ Assert.Equal(r.State.Food - 150, r.Why.Where(w => w.System == "economy" && w.Target == "food").Sum(w => w.Delta));
+ }
+
+ // #2527 review: below the month's need the shortage line is informational (delta 0, the unmet in its args), so the
+ // Food row's lines still add up to the stock's change: +260 = 0 + 260 for Food 40, need 100, cover 300.
+ [Fact]
+ public void BelowTheNeedTheShortageIsInformationalAndTheFoodLinesStillAddUp()
+ {
+ var c = Gdd();
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ s.Food = 40; // below the month's need of 100: 60 go unmet, the import brings the stock to its cover
+ var r = StepWithWhy(c, s);
+ Assert.Equal(300, r.State.Food);
+ Assert.Equal(60, r.State.FoodUnmet);
+ var shortage = Assert.Single(r.Why, w => w.Key == CauseKeys.FoodShortage);
+ Assert.Equal(0.0, shortage.Delta);
+ Assert.Equal(new[] { "60", "100" }, shortage.Args);
+ Assert.Equal("Food ran out: 60 of 100 units of the month's need went unmet", shortage.Message);
+ Assert.Equal(r.State.Food - 40, r.Why.Where(w => w.System == "economy" && w.Target == "food").Sum(w => w.Delta));
+ }
+
+ // #2527: a steady turn (the stock already at its cover) nets to nothing, so no line is invented.
+ [Fact]
+ public void ASteadyTurnAddsNoImportLine()
+ {
+ var c = Gdd();
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ var r = StepWithWhy(c, s);
+ Assert.Equal(300, r.State.Food);
+ Assert.DoesNotContain(r.Why, w => w.Key == CauseKeys.FoodImported);
+ }
+
// R-FOOD-002 (Q-POOL-4: the fx crisis cuts the imports, not food_supply directly)
[Fact]
public void ACurrencyCrisisCutsTheImportsSoTheStockFalls()
@@ -455,8 +501,8 @@ public class PoolsTests
Pools.Consume(c, f, c.RulesAt(f.Date).Mvp!, why);
var keyed = why.Where(w => w.Key != "").ToList();
Assert.Equal(new[] { CauseKeys.FoodShortage, CauseKeys.FoodWithoutImports }, keyed.Select(w => w.Key));
- Assert.Equal(-60.0, keyed[0].Delta);
- Assert.Equal(new[] { "100" }, keyed[0].Args); // the need; unmet is -Delta
+ Assert.Equal(0.0, keyed[0].Delta); // informational (#2527): the unmet is in the args
+ Assert.Equal(new[] { "60", "100" }, keyed[0].Args); // the unmet, then the need
Assert.Equal("Food ran out: 60 of 100 units of the month's need went unmet", keyed[0].Message);
Assert.Equal(-40.0, keyed[1].Delta);
Assert.Equal(new[] { "0" }, keyed[1].Args); // the stock after eating
diff --git a/sim/Statecraft.Sim.Tests/RemainingCauseKeysTests.cs b/sim/Statecraft.Sim.Tests/RemainingCauseKeysTests.cs
index b3e505f03..3067b2bec 100644
--- a/sim/Statecraft.Sim.Tests/RemainingCauseKeysTests.cs
+++ b/sim/Statecraft.Sim.Tests/RemainingCauseKeysTests.cs
@@ -38,7 +38,7 @@ public class RemainingCauseKeysTests
yield return new object[] { "Projects.cs", "ProjectCompleted", "new Cause(\"city\", p.City, 1, $\"{PlayerText.Settlement(c, p.City)}: {k.Name} was finished\"" };
yield return new object[] { "Pools.cs", "ArmsBought", "new Cause(\"economy\", \"arms\", count, FormattableString.Invariant($\"Bought {count} Arms, cost {PlayerText.Money(c, \"treasury\", cost)}\")" };
yield return new object[] { "Pools.cs", "FoodHarvest", "new Cause(\"economy\", \"food\", yield, FormattableString.Invariant($\"{f.Name}: the plowed land yielded {yield} units of Food\")" };
- yield return new object[] { "Pools.cs", "FoodShortage", "new Cause(\"economy\", \"food\", -s.FoodUnmet, FormattableString.Invariant($\"Food ran out: {s.FoodUnmet} of {need} units of the month's need went unmet\")" };
+ yield return new object[] { "Pools.cs", "FoodShortage", "new Cause(\"economy\", \"food\", 0, FormattableString.Invariant($\"Food ran out: {s.FoodUnmet} of {need} units of the month's need went unmet\")" };
yield return new object[] { "Pools.cs", "FoodWithoutImports", "new Cause(\"economy\", \"food\", -eaten, FormattableString.Invariant($\"No Food imported (foreign currency crisis): the stock fell to {s.Food} units\")" };
yield return new object[] { "Prisoners.cs", "PrisonerFood", "new Cause(\"economy\", \"food\", -eaten, FormattableString.Invariant($\"The prisoners held ate {eaten} units of Food\")" };
yield return new object[] { "Prisoners.cs", "PrisonerFoodShortage", "new Cause(\"economy\", \"morale\", change, FormattableString.Invariant($\"The prisoners held went short of {unfed} units of Food: {PlayerText.Change(c, \"morale\", change)}\")" };
@@ -115,7 +115,7 @@ public class RemainingCauseKeysTests
sites++;
}
}
- Assert.Equal(120, sites); // 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(122, sites); // 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.cs
index 4cd885b15..452d1f1b3 100644
--- a/sim/Statecraft.Sim/Cause.cs
+++ b/sim/Statecraft.Sim/Cause.cs
@@ -150,12 +150,16 @@ namespace Statecraft.Sim
public const string WorkshopPaused = "workshop_paused";
/// <summary>Args: CauseKeys.Number(amount), the US$ millions converted.</summary>
public const string DollarsConverted = "dollars_converted";
+ /// <summary>The reserves side of the same conversion (#2527). Args: CauseKeys.Number(amount), the US$ millions converted.</summary>
+ public const string DollarsConvertedFx = "dollars_converted_fx";
/// <summary>Args: f.Id.</summary>
public const string FoodHarvest = "food_harvest";
/// <summary>Args: CauseKeys.Number(need).</summary>
public const string FoodShortage = "food_shortage";
/// <summary>Args: CauseKeys.Number(s.Food).</summary>
public const string FoodWithoutImports = "food_without_imports";
+ /// <summary>R-FOOD-002's import top-up. Args: CauseKeys.Number(s.Food), the stock the import brought it to.</summary>
+ public const string FoodImported = "food_imported";
/// <summary>Args: none.</summary>
public const string PrisonerFood = "prisoner_food";
/// <summary>Args: CauseKeys.Number(unfed).</summary>
@@ -271,7 +275,7 @@ namespace Statecraft.Sim
EventNew, EventChosen, EventDelegated, EventDelegatedPartial, EventAmount, EventStock, EventGrant, EventCity,
EventUnlock, EventPolicy, EventSetRung, EventRejoin, MilitaryUpkeep, HousingSurcharge, HousingCohesion,
ObjectiveCompleted, PrisonersReturned, SoldiersReturned,
- WorkersAssigned, WagesPaid, ImmigrantsHoused, HousingShortage, ImmigrantsWaiting, RecruitsVeteran, CorridorStarted, CorridorCancelled, CorridorCompleted, PioneersVeteran, MapBorrowed, MapBuilt, LandWorkStarted, SiteStarted, SiteCancelled, SiteCompleted, ProjectStarted, ProjectCancelled, ProjectCompleted, ProjectBuilder, ProjectBuilderFreed, ProjectWaiting, ArmsBought, WorkshopWorkers, WorkshopArms, WorkshopPaused, DollarsConverted, FoodHarvest, FoodShortage, FoodWithoutImports, PrisonerFood, PrisonerFoodShortage, CraftsmenReturned, CraftsmenReassigned, PioneerReturned, PioneersReassigned, TrainingStarted, TrainingArms, TrainingCancelled, TrainingArmsReturned, ReplacementsStopped, ReplacementsJoined, MilitaryTrained, PioneersTrained, CraftsmenTrained, Appointed, Reshuffle, AppointmentsEnded, ApprovalStability, CoalitionCollapsed, LegislatureConvened, GovernmentTookOffice, CoalitionChanged, EraEnded, AdvisoryPolicyRejected, PolicyRejected, PolicySet, AdvisoryBudgetRejected, BudgetRejected, PlaceCaptured, EnemyRegained, PlaceAnnexed, PlaceWithdrawn, PlaceDeported, DeportEffect, DeportCost, OccupationStarted, PendingBecameRaid, OccupationLostUnit, OccupationCountdown, DepopulationSupport,
+ WorkersAssigned, WagesPaid, ImmigrantsHoused, HousingShortage, ImmigrantsWaiting, RecruitsVeteran, CorridorStarted, CorridorCancelled, CorridorCompleted, PioneersVeteran, MapBorrowed, MapBuilt, LandWorkStarted, SiteStarted, SiteCancelled, SiteCompleted, ProjectStarted, ProjectCancelled, ProjectCompleted, ProjectBuilder, ProjectBuilderFreed, ProjectWaiting, ArmsBought, WorkshopWorkers, WorkshopArms, WorkshopPaused, DollarsConverted, DollarsConvertedFx, FoodHarvest, FoodShortage, FoodWithoutImports, FoodImported, PrisonerFood, PrisonerFoodShortage, CraftsmenReturned, CraftsmenReassigned, PioneerReturned, PioneersReassigned, TrainingStarted, TrainingArms, TrainingCancelled, TrainingArmsReturned, ReplacementsStopped, ReplacementsJoined, MilitaryTrained, PioneersTrained, CraftsmenTrained, Appointed, Reshuffle, AppointmentsEnded, ApprovalStability, CoalitionCollapsed, LegislatureConvened, GovernmentTookOffice, CoalitionChanged, EraEnded, AdvisoryPolicyRejected, PolicyRejected, PolicySet, AdvisoryBudgetRejected, BudgetRejected, PlaceCaptured, EnemyRegained, PlaceAnnexed, PlaceWithdrawn, PlaceDeported, DeportEffect, DeportCost, OccupationStarted, PendingBecameRaid, OccupationLostUnit, OccupationCountdown, DepopulationSupport,
};
/// <summary>A number as an Arg: invariant and round-trip, so the UI rounds exactly the value Message rounded.</summary>
diff --git a/sim/Statecraft.Sim/EconomySystem.cs b/sim/Statecraft.Sim/EconomySystem.cs
index c1dd8a9a4..f3f7e7828 100644
--- a/sim/Statecraft.Sim/EconomySystem.cs
+++ b/sim/Statecraft.Sim/EconomySystem.cs
@@ -114,6 +114,9 @@ namespace Statecraft.Sim
why.Add(new Cause("economy", "treasury", money,
$"Converted {PlayerText.Money(c, "fx_reserves", amount)} of foreign currency into Money: {PlayerText.MoneyChange(c, "treasury", money)}",
key: CauseKeys.DollarsConverted, args: new[] { CauseKeys.Number(amount) }));
+ why.Add(new Cause("economy", "fx_reserves", -amount,
+ $"Foreign currency converted into Money: {PlayerText.MoneyChange(c, "fx_reserves", -amount)}",
+ key: CauseKeys.DollarsConvertedFx, args: new[] { CauseKeys.Number(amount) }));
return null;
}
diff --git a/sim/Statecraft.Sim/Pools.cs b/sim/Statecraft.Sim/Pools.cs
index b3d9430fd..68a762922 100644
--- a/sim/Statecraft.Sim/Pools.cs
+++ b/sim/Statecraft.Sim/Pools.cs
@@ -120,14 +120,23 @@ namespace Statecraft.Sim
s.FoodNeed = need;
s.FoodUnmet = need - eaten;
if (s.FoodUnmet > 0)
- why.Add(new Cause("economy", "food", -s.FoodUnmet, FormattableString.Invariant($"Food ran out: {s.FoodUnmet} of {need} units of the month's need went unmet"), key: CauseKeys.FoodShortage, args: new[] { CauseKeys.Number(need) }));
+ // #2527 review: informational - the unmet count lives in the line and its args, not the delta, so the Food
+ // row's lines add up to the stock's change on a turn that starts below the need.
+ why.Add(new Cause("economy", "food", 0, FormattableString.Invariant($"Food ran out: {s.FoodUnmet} of {need} units of the month's need went unmet"), key: CauseKeys.FoodShortage, args: new[] { CauseKeys.Number(s.FoodUnmet), CauseKeys.Number(need) }));
if (s.ActiveSituations.Contains(EconomySystem.FxCrisis))
{
why.Add(new Cause("economy", "food", -eaten, FormattableString.Invariant($"No Food imported (foreign currency crisis): the stock fell to {s.Food} units"), key: CauseKeys.FoodWithoutImports, args: new[] { CauseKeys.Number(s.Food) }));
return;
}
var target = (long)r.CoverMonths!.Value * need;
- if (s.Food < target) s.Food = (int)target;
+ if (s.Food < target)
+ {
+ var before = s.Food + eaten; // the stock on entry: the line nets the eating and the import, so the Food row's lines add up to its change (#2527)
+ s.Food = (int)target;
+ var net = s.Food - before;
+ if (net != 0)
+ why.Add(new Cause("economy", "food", net, FormattableString.Invariant($"The month's eating and Food imports brought the stock to {s.Food} units"), key: CauseKeys.FoodImported, args: new[] { CauseKeys.Number(s.Food) }));
+ }
}
/// <summary>R-FOOD-003: food_supply's stock term, k_food * (stock - full) / full - unmet / need, where full is
diff --git a/unity/Assets/Scripts/UI/CauseText.cs b/unity/Assets/Scripts/UI/CauseText.cs
index ab3581995..24d2a58d0 100644
--- a/unity/Assets/Scripts/UI/CauseText.cs
+++ b/unity/Assets/Scripts/UI/CauseText.cs
@@ -89,7 +89,7 @@ namespace Statecraft.Game.UI
// #1682: these branches use captured ids, values and resident flags, never the live GameState.
static readonly HashSet<string> RemainingKeys = new HashSet<string>
{
- CauseKeys.WorkersAssigned, CauseKeys.WagesPaid, CauseKeys.ImmigrantsHoused, CauseKeys.HousingShortage, CauseKeys.ImmigrantsWaiting, CauseKeys.RecruitsVeteran, CauseKeys.CorridorStarted, CauseKeys.CorridorCancelled, CauseKeys.CorridorCompleted, CauseKeys.PioneersVeteran, CauseKeys.MapBorrowed, CauseKeys.MapBuilt, CauseKeys.LandWorkStarted, CauseKeys.SiteStarted, CauseKeys.SiteCancelled, CauseKeys.SiteCompleted, CauseKeys.ProjectStarted, CauseKeys.ProjectCancelled, CauseKeys.ProjectCompleted, CauseKeys.ProjectBuilder, CauseKeys.ProjectBuilderFreed, CauseKeys.ProjectWaiting, CauseKeys.ArmsBought, CauseKeys.WorkshopWorkers, CauseKeys.WorkshopArms, CauseKeys.WorkshopPaused, CauseKeys.DollarsConverted, CauseKeys.FoodHarvest, CauseKeys.FoodShortage, CauseKeys.FoodWithoutImports, CauseKeys.PrisonerFood, CauseKeys.PrisonerFoodShortage, CauseKeys.CraftsmenReturned, CauseKeys.CraftsmenReassigned, CauseKeys.PioneerReturned, CauseKeys.PioneersReassigned, CauseKeys.TrainingStarted, CauseKeys.TrainingArms, CauseKeys.TrainingCancelled, CauseKeys.TrainingArmsReturned, CauseKeys.ReplacementsStopped, CauseKeys.ReplacementsJoined, CauseKeys.MilitaryTrained, CauseKeys.PioneersTrained, CauseKeys.CraftsmenTrained, CauseKeys.Appointed, CauseKeys.Reshuffle, CauseKeys.AppointmentsEnded, CauseKeys.ApprovalStability, CauseKeys.CoalitionCollapsed, CauseKeys.LegislatureConvened, CauseKeys.GovernmentTookOffice, CauseKeys.CoalitionChanged, CauseKeys.EraEnded, CauseKeys.AdvisoryPolicyRejected, CauseKeys.PolicyRejected, CauseKeys.PolicySet, CauseKeys.AdvisoryBudgetRejected, CauseKeys.BudgetRejected, CauseKeys.PlaceCaptured, CauseKeys.EnemyRegained, CauseKeys.PlaceAnnexed, CauseKeys.PlaceWithdrawn, CauseKeys.PlaceDeported, CauseKeys.DeportEffect, CauseKeys.DeportCost, CauseKeys.OccupationStarted, CauseKeys.PendingBecameRaid, CauseKeys.OccupationLostUnit, CauseKeys.OccupationCountdown, CauseKeys.DepopulationSupport
+ CauseKeys.WorkersAssigned, CauseKeys.WagesPaid, CauseKeys.ImmigrantsHoused, CauseKeys.HousingShortage, CauseKeys.ImmigrantsWaiting, CauseKeys.RecruitsVeteran, CauseKeys.CorridorStarted, CauseKeys.CorridorCancelled, CauseKeys.CorridorCompleted, CauseKeys.PioneersVeteran, CauseKeys.MapBorrowed, CauseKeys.MapBuilt, CauseKeys.LandWorkStarted, CauseKeys.SiteStarted, CauseKeys.SiteCancelled, CauseKeys.SiteCompleted, CauseKeys.ProjectStarted, CauseKeys.ProjectCancelled, CauseKeys.ProjectCompleted, CauseKeys.ProjectBuilder, CauseKeys.ProjectBuilderFreed, CauseKeys.ProjectWaiting, CauseKeys.ArmsBought, CauseKeys.WorkshopWorkers, CauseKeys.WorkshopArms, CauseKeys.WorkshopPaused, CauseKeys.DollarsConverted, CauseKeys.DollarsConvertedFx, CauseKeys.FoodHarvest, CauseKeys.FoodShortage, CauseKeys.FoodWithoutImports, CauseKeys.FoodImported, CauseKeys.PrisonerFood, CauseKeys.PrisonerFoodShortage, CauseKeys.CraftsmenReturned, CauseKeys.CraftsmenReassigned, CauseKeys.PioneerReturned, CauseKeys.PioneersReassigned, CauseKeys.TrainingStarted, CauseKeys.TrainingArms, CauseKeys.TrainingCancelled, CauseKeys.TrainingArmsReturned, CauseKeys.ReplacementsStopped, CauseKeys.ReplacementsJoined, CauseKeys.MilitaryTrained, CauseKeys.PioneersTrained, CauseKeys.CraftsmenTrained, CauseKeys.Appointed, CauseKeys.Reshuffle, CauseKeys.AppointmentsEnded, CauseKeys.ApprovalStability, CauseKeys.CoalitionCollapsed, CauseKeys.LegislatureConvened, CauseKeys.GovernmentTookOffice, CauseKeys.CoalitionChanged, CauseKeys.EraEnded, CauseKeys.AdvisoryPolicyRejected, CauseKeys.PolicyRejected, CauseKeys.PolicySet, CauseKeys.AdvisoryBudgetRejected, CauseKeys.BudgetRejected, CauseKeys.PlaceCaptured, CauseKeys.EnemyRegained, CauseKeys.PlaceAnnexed, CauseKeys.PlaceWithdrawn, CauseKeys.PlaceDeported, CauseKeys.DeportEffect, CauseKeys.DeportCost, CauseKeys.OccupationStarted, CauseKeys.PendingBecameRaid, CauseKeys.OccupationLostUnit, CauseKeys.OccupationCountdown, CauseKeys.DepopulationSupport
};
static string Remaining(Cause cause, Content c, UiText text, IReadOnlyDictionary<string, string>? namesHe)
@@ -167,12 +167,16 @@ namespace Statecraft.Game.UI
return text.Format(key + "." + A(0), Settlement(cause.Target));
case CauseKeys.DollarsConverted:
return text.Format(key, Money(c, "fx_reserves", A(0)), PlayerText.MoneyChange(c, "treasury", cause.Delta));
+ case CauseKeys.DollarsConvertedFx: // #2527: the reserves drop, worded as foreign currency, not a Money change
+ return text.Format(key, Money(c, "fx_reserves", A(0)), PlayerText.MoneyChange(c, "fx_reserves", cause.Delta));
case CauseKeys.FoodHarvest:
return text.Format(key, Site(A(0)), cause.Delta);
case CauseKeys.FoodShortage:
- return text.Format(key, -cause.Delta, A(0));
+ return text.Format(key, A(0), A(1)); // the unmet, then the need: the line is informational (#2527)
case CauseKeys.FoodWithoutImports:
return text.Format(key, A(0));
+ case CauseKeys.FoodImported: // #2527
+ return text.Format(key, A(0));
case CauseKeys.PrisonerFood:
return text.Format(key, -cause.Delta);
case CauseKeys.PrisonerFoodShortage:
diff --git a/unity/Assets/Scripts/UI/TurnReportPresenter.cs b/unity/Assets/Scripts/UI/TurnReportPresenter.cs
index b00789c25..44a40ae8c 100644
--- a/unity/Assets/Scripts/UI/TurnReportPresenter.cs
+++ b/unity/Assets/Scripts/UI/TurnReportPresenter.cs
@@ -148,12 +148,17 @@ namespace Statecraft.Game.UI
return lines;
}
- /// <summary>The same largest-two and stable tie order as the report's indicators, matched to stock targets.</summary>
- public static IReadOnlyList<string> StockCauses(StepResult? turn, string target, Func<Cause, string> line) =>
- turn == null ? Array.Empty<string>() : turn.Why.Select((w, i) => (w, i))
- .Where(x => x.w.Target == target && x.w.Delta != 0)
- .OrderByDescending(x => Math.Abs(x.w.Delta)).ThenBy(x => x.i)
- .Take(HudModel.MaxCauses).Select(x => line(x.w)).ToList();
+ /// <summary>The same largest-two and stable tie order as the report's indicators, matched to stock targets. The
+ /// Food shortage's line is informational (delta 0, #2527) but still shows, after the lines that have one.</summary>
+ public static IReadOnlyList<string> StockCauses(StepResult? turn, string target, Func<Cause, string> line)
+ {
+ if (turn == null) return Array.Empty<string>();
+ var rows = turn.Why.Select((w, i) => (w, i)).Where(x => x.w.Target == target).ToList();
+ return rows.Where(x => x.w.Delta != 0).OrderByDescending(x => Math.Abs(x.w.Delta)).ThenBy(x => x.i)
+ .Take(HudModel.MaxCauses)
+ .Concat(rows.Where(x => x.w.Delta == 0 && x.w.Key == CauseKeys.FoodShortage).OrderBy(x => x.i))
+ .Select(x => line(x.w)).ToList();
+ }
/// <summary>#1701 A1 (owner, 2 November 2026: "Yes, in the panel (Recommended)"): the arms workshops that made Arms and
/// those whose next cycle waits at the debt ceiling this turn, as the sim's causes say (CauseKeys.WorkshopArms;
diff --git a/unity/Assets/Tests/EditMode/CauseTextTests.cs b/unity/Assets/Tests/EditMode/CauseTextTests.cs
index c2daa006d..e0a928345 100644
--- a/unity/Assets/Tests/EditMode/CauseTextTests.cs
+++ b/unity/Assets/Tests/EditMode/CauseTextTests.cs
@@ -462,9 +462,11 @@ public class CauseTextTests
new Cause("draft", "town", 1, "Town: an arms workshop made 1 Arms", key: CauseKeys.WorkshopArms),
new Cause("draft", "town", 0, "Town: an arms workshop has no worker without a job this month", key: CauseKeys.WorkshopPaused, args: new[] { Workshops.NoWorker }),
new Cause("draft", "treasury", 1.44, "Converted $4.0m of foreign currency into Money: IL\u00A0+1.4m", key: CauseKeys.DollarsConverted, args: new[] { "4" }),
+ new Cause("draft", "fx_reserves", -4, "Foreign currency converted into Money: $-4.0m", key: CauseKeys.DollarsConvertedFx, args: new[] { "4" }), // #2527
new Cause("draft", "food", 2000000000, "Site: the plowed land yielded 2000000000 units of Food", key: CauseKeys.FoodHarvest, args: new[] { "site" }),
- new Cause("draft", "food", -2000000000, "Food ran out: 2000000000 of 2000000001 units of the month's need went unmet", key: CauseKeys.FoodShortage, args: new[] { "2000000001" }),
+ new Cause("draft", "food", 0, "Food ran out: 2000000000 of 2000000001 units of the month's need went unmet", key: CauseKeys.FoodShortage, args: new[] { "2000000000", "2000000001" }), // informational (#2527): the unmet, then the need
new Cause("draft", "food", -1, "No Food imported (foreign currency crisis): the stock fell to 2000000000 units", key: CauseKeys.FoodWithoutImports, args: new[] { "2000000000" }),
+ new Cause("draft", "food", 150, "The month's eating and Food imports brought the stock to 2000000000 units", key: CauseKeys.FoodImported, args: new[] { "2000000000" }), // #2527
new Cause("draft", "food", -2000000000, "The prisoners held ate 2000000000 units of Food", key: CauseKeys.PrisonerFood),
new Cause("draft", "morale", -0.025, "The prisoners held went short of 2000000000 units of Food: Social cohesion -2.5%", key: CauseKeys.PrisonerFoodShortage, args: new[] { "2000000000" }),
new Cause("draft", "town", 1, "Town: 1 group of craftsmen returned to civilian life and keep their training", key: CauseKeys.CraftsmenReturned, args: new[] { "1" }),
diff --git a/unity/Assets/Tests/EditMode/DollarConversionTests.cs b/unity/Assets/Tests/EditMode/DollarConversionTests.cs
index e80cf953c..0eaf683c3 100644
--- a/unity/Assets/Tests/EditMode/DollarConversionTests.cs
+++ b/unity/Assets/Tests/EditMode/DollarConversionTests.cs
@@ -218,7 +218,7 @@ public class DollarConversionTests
public void TheCauseLineIsWordedInBothLanguages()
{
var b = Bridge(false, false);
- var line = Simulation.Step(b.Content, b.State, new Command[] { new ConvertDollars(4) }).Why.Single(w => w.Key == CauseKeys.DollarsConverted);
+ var line = Simulation.Step(b.Content, b.State, new Command[] { new ConvertDollars(4) }).Why.Single(w => w.Key == CauseKeys.DollarsConverted && w.Target == "treasury");
Assert.AreEqual(line.Message, CauseText.Line(line, b.Content, System.Array.Empty<Statecraft.Game.Map.Units.UnitEntry>(), En));
var he = CauseText.Line(line, b.Content, System.Array.Empty<Statecraft.Game.Map.Units.UnitEntry>(), He);
StringAssert.IsMatch("[א-ת]", he);
@@ -229,4 +229,19 @@ public class DollarConversionTests
Assert.GreaterOrEqual(at, 0, he); Assert.Greater(il, at, he);
StringAssert.DoesNotMatch("[A-Za-z]", he.Replace(dollars, "").Replace(money, ""), he);
}
+
+ // #2527: the reserves side of the conversion has its own key, worded as foreign currency, in both languages.
+ [Test]
+ public void TheReservesLineIsWordedAsForeignCurrencyInBothLanguages()
+ {
+ var b = Bridge(false, false);
+ var line = Simulation.Step(b.Content, b.State, new Command[] { new ConvertDollars(4) }).Why.Single(w => w.Key == CauseKeys.DollarsConvertedFx);
+ Assert.AreEqual("fx_reserves", line.Target);
+ Assert.AreEqual(line.Message, CauseText.Line(line, b.Content, System.Array.Empty<Statecraft.Game.Map.Units.UnitEntry>(), En));
+ var he = CauseText.Line(line, b.Content, System.Array.Empty<Statecraft.Game.Map.Units.UnitEntry>(), He);
+ StringAssert.IsMatch("[\u05D0-\u05EA]", he);
+ var drop = PlayerText.MoneyChange(b.Content, "fx_reserves", -4);
+ StringAssert.Contains(drop, he);
+ StringAssert.DoesNotMatch("[A-Za-z]", he.Replace(drop, ""), he);
+ }
}
diff --git a/unity/Assets/Tests/EditMode/FoodArmsReviewTests.cs b/unity/Assets/Tests/EditMode/FoodArmsReviewTests.cs
index c4e929da1..e7eb2101b 100644
--- a/unity/Assets/Tests/EditMode/FoodArmsReviewTests.cs
+++ b/unity/Assets/Tests/EditMode/FoodArmsReviewTests.cs
@@ -56,7 +56,15 @@ public class FoodArmsReviewTests
.OrderByDescending(w => Math.Abs(w.Delta)).Take(HudModel.MaxCauses)
.Select(w => CauseText.Line(w, b.Content, Array.Empty<Statecraft.Game.Map.Units.UnitEntry>(), t)).ToArray();
if (crisis) { Assert.IsNotEmpty(expected); StringAssert.Contains("No Food imported", b.Session.Last.Why.Single(w => w.Target == Pools.FoodTarget && w.Message.Contains("No Food imported")).Message); }
- else Assert.IsEmpty(expected, "do not invent causes for normal automatic imports");
+ else
+ {
+ // #2527/#2529 (R-FOOD-002): the sim's own import line is the one cause of a normal month and carries the whole real
+ // change; the UI still invents none (#1790): the rows below must equal the sim's lines exactly.
+ var food = b.Session.Last.Why.Where(w => w.Target == Pools.FoodTarget && w.Delta != 0).ToList();
+ Assert.AreEqual(1, food.Count, "only the sim's import line explains a normal month");
+ Assert.AreEqual(CauseKeys.FoodImported, food[0].Key);
+ Assert.AreEqual((double)delta, food[0].Delta, "the import line nets the eating and the top-up into the stock's change");
+ }
using var why = new WhyPresenter(ui.Root, b, t);
StringAssert.Contains(t.Format("hud.stock", b.State.Food), ui.Q<Label>("why-stock-food").text);
var row = TurnReportPresenter.Lines(b, t).Single(x => x.Meter == "food");
diff --git a/unity/Assets/Tests/EditMode/TurnReportTests.cs b/unity/Assets/Tests/EditMode/TurnReportTests.cs
index 50dbf3783..1e6922c1a 100644
--- a/unity/Assets/Tests/EditMode/TurnReportTests.cs
+++ b/unity/Assets/Tests/EditMode/TurnReportTests.cs
@@ -359,6 +359,25 @@ public class TurnReportTests
Assert.IsFalse(TurnReportPresenter.Lines(k.Bridge, En).Any(l => l.Meter == TurnReportPresenter.EnemyRow));
}
+ /// <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]
+ public void AShortageTurnStillNamesTheShortageInTheFoodRow()
+ {
+ using var k = new Kit(En);
+ k.Bridge.EndTurn();
+ var last = k.Bridge.Session.Last!;
+ var shortage = new Cause("economy", "food", 0, "Food ran out: 60 of 100 units of the month's need went unmet",
+ key: CauseKeys.FoodShortage, args: new[] { "60", "100" });
+ var import = new Cause("economy", "food", 260, "The month's eating and Food imports brought the stock to 300 units",
+ key: CauseKeys.FoodImported, args: new[] { "300" });
+ var turn = new StepResult(last.State, new[] { shortage, import }, last.Rejected);
+ CollectionAssert.AreEqual(
+ new[] { "The month's eating and Food imports brought the stock to 300 units",
+ "Food ran out: 60 of 100 units of the month's need went unmet" },
+ TurnReportPresenter.StockCauses(turn, Pools.FoodTarget, w => w.Message));
+ }
+
[Test]
public void ItCoversTheHudUntilClosedAndThenTheCardIsBack()
{
diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yaml
index 976c99a39..b53234d33 100644
--- a/unity/Assets/UI/strings.en.yaml
+++ b/unity/Assets/UI/strings.en.yaml
@@ -1125,6 +1125,7 @@ why.cause.workshop_paused.debt_ceiling: "{0}: an arms workshop's next cycle wait
why.cause.food_harvest: "{0}: the plowed land yielded {1} units of Food"
why.cause.food_shortage: "Food ran out: {0} of {1} units of the month's need went unmet"
why.cause.food_without_imports: "No Food imported (foreign currency crisis): the stock fell to {0} units"
+why.cause.food_imported: "The month's eating and Food imports brought the stock to {0} units"
why.cause.prisoner_food: "The prisoners held ate {0} units of Food"
why.cause.prisoner_food_shortage: "The prisoners held went short of {0} units of Food: {1} {2}"
why.cause.craftsmen_returned: "{0}: {1} of craftsmen returned to civilian life and keep their training"
@@ -1237,6 +1238,7 @@ dollars.refused_monthly: "That is more dollars than may be converted this month"
dollars.refused_total: "That would pass the total of dollars that may be converted"
dollars.refused_reserves: "There are not enough dollars in the reserves"
why.cause.dollars_converted: "Converted {0} of foreign currency into Money: {1}"
+why.cause.dollars_converted_fx: "Foreign currency converted into Money: {1}"
# Read-only WebGL companion (#1119); Hebrew additions await native review.
companion.title: "Game companion"
diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yaml
index 964095596..ac1717065 100644
--- a/unity/Assets/UI/strings.he.yaml
+++ b/unity/Assets/UI/strings.he.yaml
@@ -1364,6 +1364,8 @@ why.cause.workshop_paused.debt_ceiling: "{0}: המחזור הבא של סדנת
why.cause.food_harvest: "{0}: יחידות מזון שהניבה הקרקע החרושה: {1}"
why.cause.food_shortage: "המזון אזל: מחסור של {0} מתוך {1} יחידות שנדרשו החודש"
why.cause.food_without_imports: "לא יובא מזון (משבר מטבע חוץ): יחידות שנותרו במלאי: {0}"
+# For the native reviewer (#564): agent-drafted Hebrew.
+why.cause.food_imported: "אכילת החודש וייבוא המזון הביאו את המלאי ל-{0} יחידות"
why.cause.prisoner_food: "יחידות מזון שאכלו השבויים המוחזקים: {0}"
why.cause.prisoner_food_shortage: "לשבויים המוחזקים חסרו {0} יחידות מזון: {1}: שינוי {2}"
why.cause.craftsmen_returned: "{0}: חזרה לחיים אזרחיים תוך שמירת ההכשרה, בעלי מלאכה: {1}"
@@ -1480,6 +1482,8 @@ dollars.refused_monthly: "זה יותר מהסכום שמותר להמיר הח
dollars.refused_total: "ההמרה תעבור את הסכום הכולל שמותר להמיר"
dollars.refused_reserves: "אין די דולרים ביתרות מטבע החוץ"
why.cause.dollars_converted: "המרת מטבע חוץ לכסף: {0}; כסף: שינוי {1}"
+# For the native reviewer (#564): agent-drafted Hebrew.
+why.cause.dollars_converted_fx: "מטבע חוץ שהומר לכסף: {1}"
# Read-only WebGL companion (#1119); Hebrew additions await native review.
companion.title: "מלווה למשחק"