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.

sim: an event's city effect keeps the city's housing condition (fixes #1000) (#1001)

Eyal Golanb81ea9dd4ebe
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a0f8a2b86..c2d75a6a2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
Mefalsim is built in March 1950 and the goldens move (refs #785, #782).
### Fixed
+- Event city effects preserve the city's housing condition when changing its housing capacity or job slots (#1000).
- The Cabinet's Hebrew "already holds" refusal uses the holder's office title, including the feminine form for a woman;
English is unchanged (#990).
- On a phone held upright (390x844) the top bar's small text keeps the owner's 12 px floor too: the seven captions,
diff --git a/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs b/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs
index 4b29de30c..897bd4d79 100644
--- a/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs
+++ b/sim/Statecraft.Sim.Tests/StructuredEffectTests.cs
@@ -95,6 +95,19 @@ from: 1948-05-15
Assert.Contains(why, w => w.System == "events" && w.Target == "town_a.job_slots" && w.Delta == x.Employed - x.JobSlots);
}
+ // R-EFX-004: changing a city's capacity or slots preserves its housing condition with every other unnamed field.
+ [Fact]
+ public void ACityEffectKeepsTheHousingCondition()
+ {
+ var c = Load(Event(Grants));
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ s.Cities["town_a"] = s.Cities["town_a"].WithCondition(0.73);
+
+ Assert.Null(EventSystem.Choose(c, s, "arms", "accept", new List<Cause>()));
+
+ Assert.Equal(0.73, s.Cities["town_a"].Condition);
+ }
+
// R-EFX-006: the structured effects apply after the numeric ones, in the option's list order (grants, then city effects).
[Fact]
public void TheyApplyAfterTheNumericEffectsInListOrder()
diff --git a/sim/Statecraft.Sim/EventSystem.cs b/sim/Statecraft.Sim/EventSystem.cs
index 847e987d8..bfac1a0f9 100644
--- a/sim/Statecraft.Sim/EventSystem.cs
+++ b/sim/Statecraft.Sim/EventSystem.cs
@@ -110,7 +110,7 @@ namespace Statecraft.Sim
var city = s.Cities[x.City];
var housing = x.Field == HousingField ? Math.Max(0, city.HousingCapacity + x.Delta) : city.HousingCapacity;
var jobs = x.Field == JobsField ? Math.Max(city.Employed, city.JobSlots + x.Delta) : city.JobSlots;
- s.Cities[x.City] = new City(city.Id, housing, jobs, city.Civilians, city.Employed, city.Refugees, city.Recruits);
+ s.Cities[x.City] = new City(city.Id, housing, jobs, city.Civilians, city.Employed, city.Refugees, city.Recruits, city.Condition);
var applied = housing - city.HousingCapacity + jobs - city.JobSlots;
why.Add(new Cause("events", x.City + "." + x.Field, applied, $"{CityChange(c, x.City, x.Field, applied)} ({title})"));
}