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(content): map-action phrases come from content (fix round 2, R2-2)

eyalgolanf6f2964976c7
diff --git a/content/rules.yaml b/content/rules.yaml
index 5abff5792..4ef9aea42 100644
--- a/content/rules.yaml
+++ b/content/rules.yaml
@@ -13,9 +13,10 @@ appoint_stability_cost_same_party: 0.02
map_actions_from: 1950-01-01
map_action_max_distance: 1
map_actions_per_turn: 2
+# name: the phrase the player reads in a sentence ("a transit camp"); required.
map_actions:
- transit_camp: { cost: 1.5, housing: 0.02, morale: -0.005 }
- housing: { cost: 6, housing: 0.03, morale: 0.01 }
+ transit_camp: { cost: 1.5, housing: 0.02, morale: -0.005, name: a transit camp }
+ housing: { cost: 6, housing: 0.03, morale: 0.01, name: a housing project }
rung_attention_step: 0.25
rung_min_mobilization: [0.02, 0.05, 0.15, 0.4, 0.8]
ceasefire_weeks: 52 # long enough that the historical armistice events end the war first
diff --git a/sim/Statecraft.Sim.Tests/Fixture.cs b/sim/Statecraft.Sim.Tests/Fixture.cs
index 6a1bfcd8b..8b4264682 100644
--- a/sim/Statecraft.Sim.Tests/Fixture.cs
+++ b/sim/Statecraft.Sim.Tests/Fixture.cs
@@ -138,8 +138,8 @@ map_actions_from: 1948-06-01
map_action_max_distance: 1
map_actions_per_turn: 2
map_actions:
- transit_camp: { cost: 2, housing: 0.05, morale: -0.02 }
- housing: { cost: 8, housing: 0.08, morale: 0.01 }
+ transit_camp: { cost: 2, housing: 0.05, morale: -0.02, name: a transit camp }
+ housing: { cost: 8, housing: 0.08, morale: 0.01, name: a housing project }
rung_attention_step: 0.25
ceasefire_weeks: 4
rung_min_mobilization: [0.02, 0.05, 0.15, 0.4, 0.8]
diff --git a/sim/Statecraft.Sim.Tests/MapActionTests.cs b/sim/Statecraft.Sim.Tests/MapActionTests.cs
index 32006249a..c69023238 100644
--- a/sim/Statecraft.Sim.Tests/MapActionTests.cs
+++ b/sim/Statecraft.Sim.Tests/MapActionTests.cs
@@ -123,7 +123,8 @@ public class MapActionTests
[Fact]
public void AnActionTheContentDoesNotDefineIsNotAvailable()
{
- var rules = Fixture.Files["rules.yaml"].Replace(" housing: { cost: 8, housing: 0.08, morale: 0.01 }\n", "");
+ var rules = Fixture.Files["rules.yaml"].Replace(" housing: { cost: 8, housing: 0.08, morale: 0.01, name: a housing project }\n", "");
+ Assert.NotEqual(Fixture.Files["rules.yaml"], rules);
var c = ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["rules.yaml"] = rules }));
var s = Simulation.NewGame(c, 42, Mode.Historical);
s.Date = new DateTime(1948, 6, 1);
diff --git a/sim/Statecraft.Sim.Tests/PlayerTextTests.cs b/sim/Statecraft.Sim.Tests/PlayerTextTests.cs
index 570a74d86..31906811b 100644
--- a/sim/Statecraft.Sim.Tests/PlayerTextTests.cs
+++ b/sim/Statecraft.Sim.Tests/PlayerTextTests.cs
@@ -88,7 +88,7 @@ public class PlayerTextTests
static IEnumerable<string> ContentIds(Content c) =>
c.Indicators.Select(x => x.Id).Concat(c.Policies.Select(x => x.Id)).Concat(c.Effects.Select(x => x.Id))
.Concat(c.Situations.Select(x => x.Id)).Concat(c.Money.Select(x => x.Id)).Concat(c.Regions.Select(x => x.Id))
- .Concat(c.Offices.Select(x => x.Id)).Concat(c.Events.Select(x => x.Id)).Distinct();
+ .Concat(c.Offices.Select(x => x.Id)).Concat(c.Events.Select(x => x.Id)).Concat(c.Rules.MapActions.Keys).Distinct();
/// <summary>Where an id would appear in a Cause: a snake_case id anywhere as a whole word; a one-word id ("morale",
/// "treasury", "asia") at the start, alone in parentheses or a list, before a signed number, "set to", "=",
@@ -186,6 +186,7 @@ public class PlayerTextTests
[InlineData("14 immigrants arrived from asia", "asia")]
[InlineData("Morale +4.1% (homes_lift_morale)", "homes_lift_morale")]
[InlineData("Food supply +5.0% (austerity_1949)", "austerity_1949")]
+ [InlineData("transit_camp at (3, 4): cost IL 1.5m", "transit_camp")]
public void TheGuardCatchesOneWordIds(string message, string id) =>
Assert.Contains(Leaks(Real, new[] { message }), l => l.StartsWith($"'{id}'", StringComparison.Ordinal));
@@ -252,4 +253,33 @@ public class PlayerTextTests
Assert.Equal("model.yaml", ex.File);
Assert.Equal(field, ex.Field);
}
+
+ // ---- Fix round 2 (R2-2): map-action phrases come from content ----
+
+ [Theory]
+ [InlineData("transit_camp: { cost: 2, housing: 0.05, morale: -0.02, name: a transit camp }", "transit_camp: { cost: 2, housing: 0.05, morale: -0.02 }", "map_actions.transit_camp.name")]
+ [InlineData("housing: { cost: 8, housing: 0.08, morale: 0.01, name: a housing project }", "housing: { cost: 8, housing: 0.08, morale: 0.01, name: ' ' }", "map_actions.housing.name")]
+ public void MapActionNamesAreRequired(string from, string to, string field)
+ {
+ var ex = ValidationTests.Bad("rules.yaml", from, to);
+ Assert.Equal("rules.yaml", ex.File);
+ Assert.Equal(field, ex.Field);
+ }
+
+ [Fact]
+ public void MapActionCausesAndReasonsUseTheContentPhrase()
+ {
+ var rules = Fixture.Files["rules.yaml"].Replace("name: a transit camp", "name: a ma'abara");
+ var c = ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["rules.yaml"] = rules }));
+ Assert.Equal("a ma'abara", PlayerText.MapAction(c, MapActions.TransitCamp));
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ s.Policies[MapActions.MaabarotPolicy] = 1;
+ s.Date = c.Rules.MapActionsFrom;
+ var hex = c.Hexes.First(h => MapActions.Check(c, s, MapActions.TransitCamp, h.Q, h.R) == null);
+ var why = new List<Cause>();
+ Assert.Null(MapActions.Apply(c, s, MapActions.TransitCamp, hex.Q, hex.R, why));
+ Assert.Contains(why, w => w.System == "map" && w.Message.StartsWith($"A ma'abara at ({hex.Q}, {hex.R})", StringComparison.Ordinal));
+ Assert.Equal($"({hex.Q}, {hex.R}) already has a ma'abara", MapActions.Check(c, s, MapActions.TransitCamp, hex.Q, hex.R));
+ Assert.Throws<InvalidOperationException>(() => PlayerText.MapAction(c, "factory"));
+ }
}
diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.cs
index eb5a5775a..816807a07 100644
--- a/sim/Statecraft.Sim/Content.cs
+++ b/sim/Statecraft.Sim/Content.cs
@@ -166,6 +166,8 @@ namespace Statecraft.Sim
public double Housing { get; set; }
/// <summary>Change to the morale indicator (public support).</summary>
public double Morale { get; set; }
+ /// <summary>The phrase the player reads in a sentence ("a transit camp"); required.</summary>
+ public string Name { get; set; } = "";
}
/// <summary>Money the sim tracks (model.yaml money): treasury, debt and fx_reserves, each with the name and currency
diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.cs
index b0fd2714a..4b4791b8a 100644
--- a/sim/Statecraft.Sim/ContentLoader.cs
+++ b/sim/Statecraft.Sim/ContentLoader.cs
@@ -444,6 +444,7 @@ namespace Statecraft.Sim
{
if (!MapActions.Actions.Contains(kv.Key)) throw new ContentException("rules.yaml", $"map_actions.{kv.Key}", "unknown map action (transit_camp or housing)");
if (!(kv.Value.Cost >= 0 && IsFinite(kv.Value.Cost))) throw new ContentException("rules.yaml", $"map_actions.{kv.Key}.cost", "must be a finite number >= 0");
+ Named("rules.yaml", $"map_actions.{kv.Key}.name", kv.Value.Name);
foreach (var (key, v) in new[] { ("housing", kv.Value.Housing), ("morale", kv.Value.Morale) })
if (!(v >= -1 && v <= 1)) throw new ContentException("rules.yaml", $"map_actions.{kv.Key}.{key}", "must be a number from -1 to 1");
}
diff --git a/sim/Statecraft.Sim/MapActions.cs b/sim/Statecraft.Sim/MapActions.cs
index 443843256..cab5befc4 100644
--- a/sim/Statecraft.Sim/MapActions.cs
+++ b/sim/Statecraft.Sim/MapActions.cs
@@ -35,9 +35,6 @@ namespace Statecraft.Sim
static int ActionsThisTurn(GameState s) => s.MapActionsTurnDate == s.Date ? s.MapActionsThisTurn : 0;
- static string Name(string action) => action == TransitCamp ? "a transit camp" : "a housing project";
-
- static string Capitalised(string s) => char.ToUpperInvariant(s[0]) + s.Substring(1);
/// <summary>Null when <paramref name="action"/> may be placed on (q, r) now, else the reason shown to the player.</summary>
public static string? Check(Content c, GameState s, string action, int q, int r)
@@ -56,7 +53,7 @@ namespace Statecraft.Sim
return FormattableString.Invariant($"({q}, {r}) is more than {max} {(max == 1 ? "hex" : "hexes")} from a settlement");
var here = At(s, q, r);
if (here != null && !(action == Housing && here.Action == TransitCamp))
- return FormattableString.Invariant($"({q}, {r}) already has {Name(here.Action)}");
+ return FormattableString.Invariant($"({q}, {r}) already has {PlayerText.MapAction(c, here.Action)}");
// The cap comes last so a player who is over it still sees the specific reason an order is illegal. It counts
// accepted actions (not surviving placements): housing on a camp removes the camp but still used an action.
if (ActionsThisTurn(s) >= c.Rules.MapActionsPerTurn)
@@ -78,13 +75,13 @@ namespace Statecraft.Sim
if (s.Treasury < 0)
{
s.Debt += -s.Treasury;
- why.Add(new Cause("economy", "debt", -s.Treasury, $"borrowed {PlayerText.Money(c, "debt", -s.Treasury)} to build {Name(action)}"));
+ why.Add(new Cause("economy", "debt", -s.Treasury, $"borrowed {PlayerText.Money(c, "debt", -s.Treasury)} to build {PlayerText.MapAction(c, action)}"));
s.Treasury = 0;
}
var housing = rule.Housing == 0 ? 0 : EffectsSystem.Shift(c, s, "housing", rule.Housing);
var morale = rule.Morale == 0 ? 0 : EffectsSystem.Shift(c, s, "morale", rule.Morale);
why.Add(new Cause("map", action, 1, FormattableString.Invariant(
- $"{Capitalised(Name(action))} at ({q}, {r}): cost {PlayerText.Money(c, "treasury", rule.Cost)}, {PlayerText.Change(c, "housing", housing)}, {PlayerText.Change(c, "morale", morale)}")));
+ $"{PlayerText.Capitalised(PlayerText.MapAction(c, action))} at ({q}, {r}): cost {PlayerText.Money(c, "treasury", rule.Cost)}, {PlayerText.Change(c, "housing", housing)}, {PlayerText.Change(c, "morale", morale)}")));
return null;
}
}
diff --git a/sim/Statecraft.Sim/PlayerText.cs b/sim/Statecraft.Sim/PlayerText.cs
index 115bd27ee..938c0e67e 100644
--- a/sim/Statecraft.Sim/PlayerText.cs
+++ b/sim/Statecraft.Sim/PlayerText.cs
@@ -32,6 +32,14 @@ namespace Statecraft.Sim
c.Indicators.FirstOrDefault(i => i.Id == id)?.Name ?? c.Policies.FirstOrDefault(p => p.Id == id)?.Name
?? c.Money.FirstOrDefault(m => m.Id == id)?.Name ?? throw Unknown("indicator, policy or money", id);
+ /// <summary>The phrase a map action reads as in a sentence ("a transit camp"; rules.yaml map_actions name).</summary>
+ public static string MapAction(Content c, string id) =>
+ c.Rules.MapActions.TryGetValue(id, out var rule) ? rule.Name : throw Unknown("map action", id);
+
+ /// <summary>The phrase with a capital first letter, to start a sentence ("A transit camp").</summary>
+ public static string Capitalised(string phrase) =>
+ phrase.Length == 0 ? phrase : char.ToUpperInvariant(phrase[0]) + phrase.Substring(1);
+
public static bool IsMoney(Content c, string id) => c.Money.Any(m => m.Id == id);
static MoneyAccount Account(Content c, string id) => c.Money.FirstOrDefault(m => m.Id == id) ?? throw Unknown("money", id);
diff --git a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
index 15fe703ac..343773b09 100644
--- a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
+++ b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
@@ -62,8 +62,8 @@ namespace Statecraft.Game.UI
settlements.text = owned.Count > 0 ? text.Format("info.owned", string.Join(", ", owned)) : "";
var here = MapActions.At(s, q, r);
var queued = bridge.QueuedLike(new MapAction(MapActions.Housing, q, r)) as MapAction;
- placement.text = queued != null ? text.Format("info.queued", text["info." + queued.Action])
- : here != null ? text.Format("info.built", text["info." + here.Action], PlayerText.Month(here.Date)) : "";
+ placement.text = queued != null ? text.Format("info.queued", PlayerText.Capitalised(PlayerText.MapAction(c, queued.Action)))
+ : here != null ? text.Format("info.built", PlayerText.Capitalised(PlayerText.MapAction(c, here.Action)), PlayerText.Month(here.Date)) : "";
var campWhy = MapActions.Check(c, s, MapActions.TransitCamp, q, r);
var housingWhy = MapActions.Check(c, s, MapActions.Housing, q, r);
camp.style.display = DisplayStyle.Flex; housing.style.display = DisplayStyle.Flex;
diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yaml
index 5db3d5a12..4ecfb5ed7 100644
--- a/unity/Assets/UI/strings.en.yaml
+++ b/unity/Assets/UI/strings.en.yaml
@@ -72,8 +72,6 @@ info.hex: "{0} · hex ({1}, {2}) · {3:N0} m"
info.owned: "Settlements: {0}"
info.built: "{0} built here in {1}"
info.queued: "Ordered: {0}, at End Turn"
-info.transit_camp: "A transit camp"
-info.housing: "A housing project"
info.build_camp: "Place a transit camp ({0})"
info.build_housing: "Build housing ({0})"
info.build_camp_plain: "Place a transit camp"