Allow queuing villagers with more complex tasks
For instance, queuing a villager to build several buildings in a row is now possible. Also adds a task queue for villagers. Any idle villager will automatically grab the first task in the queue. The task queue is used to implement the more complex initial villager tasks, so it is possible that a different villager will do later tasks in the queued villager's chain of tasks, but only if there are already idle villagers. As long as the user does not wish to leave villagers idle for a long time, this should not affect accuracy too badly.
This commit is contained in:
@@ -815,3 +815,87 @@ class TestWorld(unittest.TestCase):
|
||||
gathered = sheep_rate_per_60
|
||||
|
||||
self.assertResourcesMatch([150 + gathered, 175, 100, 200], game.world)
|
||||
|
||||
|
||||
def test_work_queue_adding_villager(self):
|
||||
game = Gameplay()
|
||||
|
||||
build_house = (Tasks.BUILD,
|
||||
{'building': Buildings.HOUSE,
|
||||
'villagers_to': Tasks.IDLE})
|
||||
build_lumber = (Tasks.BUILD,
|
||||
{'building': Buildings.LUMBERCAMP,
|
||||
'villagers_to': Tasks.IDLE})
|
||||
build_house_to_wood = (Tasks.BUILD,
|
||||
{'building': Buildings.HOUSE,
|
||||
'villagers_to': Tasks.WOOD})
|
||||
|
||||
task_list = [
|
||||
build_house,
|
||||
build_house,
|
||||
build_lumber,
|
||||
build_house_to_wood,
|
||||
]
|
||||
|
||||
game.assign_villager(0, Tasks.IDLE, Tasks.SHEEP)
|
||||
game.assign_villager(0, Tasks.IDLE, Tasks.SHEEP)
|
||||
game.assign_villager(0, Tasks.IDLE, Tasks.SHEEP)
|
||||
game.queue_villager(0, task_list)
|
||||
|
||||
game.play_until(10)
|
||||
self.assertEqual(1, len(game.world.buildings))
|
||||
self.assertEqual(4, game.world.population)
|
||||
|
||||
game.play_until(30)
|
||||
self.assertEqual(1, len(game.world.buildings))
|
||||
self.assertEqual(5, game.world.population)
|
||||
|
||||
train_and_build_time = 25 + 25*2 + 35 + 25
|
||||
duration = train_and_build_time + 60
|
||||
game.play_until(duration)
|
||||
self.assertEqual(5, len(game.world.buildings))
|
||||
self.assertEqual(5, game.world.population)
|
||||
|
||||
sheep_rate_per_60 = 19.8
|
||||
gathered_food = sheep_rate_per_60*(duration/60)*3
|
||||
|
||||
wood_rate_per_60 = 23.4
|
||||
gathered_wood = wood_rate_per_60
|
||||
|
||||
self.assertResourcesMatch([150 + gathered_food,
|
||||
25 + gathered_wood,
|
||||
100,
|
||||
200],
|
||||
game.world)
|
||||
|
||||
|
||||
def test_add_tasks_to_work_queue(self):
|
||||
game = Gameplay()
|
||||
|
||||
task_list = [
|
||||
Tasks.WOOD,
|
||||
Tasks.WOOD,
|
||||
Tasks.SHEEP,
|
||||
]
|
||||
|
||||
game.world._add_building(Buildings.LUMBERCAMP, {}, {})
|
||||
|
||||
game.queue_villager(0, Tasks.WOOD)
|
||||
for t in task_list:
|
||||
game.add_task_to_work_queue(0, t)
|
||||
|
||||
duration = 25 + 60
|
||||
game.play_until(duration)
|
||||
|
||||
sheep_rate_per_60 = 19.8
|
||||
gathered_food = sheep_rate_per_60*(duration/60)
|
||||
|
||||
wood_rate_per_60 = 23.4
|
||||
gathered_wood = wood_rate_per_60*(duration/60)*2
|
||||
gathered_wood += wood_rate_per_60
|
||||
|
||||
self.assertResourcesMatch([150 + gathered_food,
|
||||
200 + gathered_wood,
|
||||
100,
|
||||
200],
|
||||
game.world)
|
||||
|
||||
Reference in New Issue
Block a user