Stop as soon as materials run out

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-10-20 19:43:45 +01:00
parent 16f0384483
commit 8dd33cbb40
2 changed files with 17 additions and 0 deletions

View file

@ -2040,6 +2040,13 @@ def process_player(world: dict, player: dict, now: float, rng: random.Random | N
summary["resumed"] = back summary["resumed"] = back
else: else:
stop(player) 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: if player["action"] and limit < now and current["start"] < now:
current["start"] = now current["start"] = now
return summary return summary

View file

@ -91,6 +91,16 @@ class ActionTest(unittest.TestCase):
self.assertIsNone(p["action"]) self.assertIsNone(p["action"])
self.assertEqual(summary["stopped"], "Out of copper ore") 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): def test_level_and_city_requirements(self):
world = world_with(("ann", "commoner")) world = world_with(("ann", "commoner"))
p = world["players"]["ann"] p = world["players"]["ann"]