From ec8b33ac004b93f2c1c65a84e7b350473dc0f4fa Mon Sep 17 00:00:00 2001 From: Nate Bowman Date: Sun, 8 Nov 2026 21:00:32 -0500 Subject: [PATCH] Add ability to automatically queue villagers --- aoe/gameplay.py | 8 ++++++++ tests/test.py | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/aoe/gameplay.py b/aoe/gameplay.py index db25496..b2879a2 100644 --- a/aoe/gameplay.py +++ b/aoe/gameplay.py @@ -55,6 +55,14 @@ class Gameplay(): (research,))) + def queue_villagers_over_time(self, from_time, until_time, initial_task): + train_time = self.world.build_times.build_times[Units.VILLAGER] + duration = max(0, until_time - from_time) + + for i in range(duration//train_time + 1): + self.queue_villager(from_time + i*train_time, initial_task) + + def queue_villager(self, action_time, initial_task): self._check_time(action_time) self.actions[action_time].append((self.world.queue_villager, diff --git a/tests/test.py b/tests/test.py index 6d0a8a3..0421e49 100644 --- a/tests/test.py +++ b/tests/test.py @@ -58,6 +58,17 @@ class TestWorld(unittest.TestCase): self.assertResourcesMatch([150, 200, 100, 200], game.world) + def test_build_villagers_regularly(self): + game = Gameplay() + game.world._add_building(Buildings.HOUSE, {}, {}) + + game.queue_villagers_over_time(0, 75, Tasks.IDLE) + game.play_until(100) + + self.assertEqual(8, game.world.population) + self.assertResourcesMatch([0, 200, 100, 200], game.world) + + def test_build_villager_leave_idle(self): game = Gameplay() game.queue_villager(5, Tasks.IDLE)