diff --git a/game.py b/game.py index 3b6d093..ded8f53 100644 --- a/game.py +++ b/game.py @@ -2040,6 +2040,13 @@ def process_player(world: dict, player: dict, now: float, rng: random.Random | N summary["resumed"] = back else: stop(player) + if player["action"] is current and "enemy" not in action and not current.get("plot2"): + # Out of materials: stop now, not once the next bar has filled. + reason = can_start(world, player, growing(player)) + if reason: + stop(player, reason) + summary["stopped"] = reason + break if player["action"] and limit < now and current["start"] < now: current["start"] = now return summary diff --git a/tests/test_game.py b/tests/test_game.py index 5dd9d0a..3758751 100644 --- a/tests/test_game.py +++ b/tests/test_game.py @@ -91,6 +91,16 @@ class ActionTest(unittest.TestCase): self.assertIsNone(p["action"]) self.assertEqual(summary["stopped"], "Out of copper ore") + def test_crafting_stops_as_the_last_one_finishes(self): + world = world_with(("ann", "commoner")) + p = world["players"]["ann"] + p["bank"] = {"copper_ore": 1, "logs": 10} + game.start_action(world, p, "smith_copper_bar", T0) + duration = game.action_time(world, p, game.ACTION_BY_ID["smith_copper_bar"]) + summary = game.process_player(world, p, T0 + duration + 0.1, random.Random(1)) + self.assertIsNone(p["action"]) + self.assertEqual(summary["stopped"], "Out of copper ore") + def test_level_and_city_requirements(self): world = world_with(("ann", "commoner")) p = world["players"]["ann"]