diff --git a/game.py b/game.py index 687f73a..565e720 100644 --- a/game.py +++ b/game.py @@ -5712,6 +5712,9 @@ def _tick_city(world: World, now: float, rng: random.Random) -> bool: construction = city["construction"] if construction and construction["labour"] >= construction["needed"]: _finish_construction(world, now) + changed = True + # Idle builders take the next funded job. Damage can queue one with nobody to start it. + if not city["construction"] and city["queue"]: _start_next(world, now) changed = True while city["tier"] + 1 < len(TIERS) and city["population"] >= TIERS[city["tier"] + 1]["pop"]: diff --git a/tests/test_game.py b/tests/test_game.py index 6a08caf..4a82fb9 100644 --- a/tests/test_game.py +++ b/tests/test_game.py @@ -453,6 +453,17 @@ class CityTest(unittest.TestCase): game.tick(world, T0 + 2, random.Random(1)) self.assertEqual(city["tier"], 1) + def test_damage_with_the_repair_already_funded_starts_on_the_next_tick(self): + world = world_with(("fred", "commoner")) + city = world["city"] + city["buildings"]["walls"].update(level=1, fund=game.repair_cost("walls", 1)) + self.assertEqual(game._damage_building(world, T0, random.Random(1)), "Walls") + self.assertEqual(city["queue"], ["walls"]) + self.assertIsNone(city["construction"]) + self.assertTrue(game.tick(world, T0 + 1, random.Random(1))) + self.assertEqual(city["queue"], []) + self.assertTrue(city["construction"]["repair"]) + def test_damage_turns_the_fund_towards_repairs_and_keeps_the_rest(self): world = world_with(("fred", "commoner")) p = world["players"]["fred"]