Allow queuing villagers via task list
This is helpful for testing build orders.
This commit is contained in:
@@ -55,6 +55,16 @@ class Gameplay():
|
|||||||
(research,)))
|
(research,)))
|
||||||
|
|
||||||
|
|
||||||
|
def queue_villagers_by_task_list(self, from_time, initial_tasks):
|
||||||
|
train_time = self.world.build_times.build_times[Units.VILLAGER]
|
||||||
|
|
||||||
|
if not isinstance(initial_tasks, list):
|
||||||
|
initial_tasks = [initial_tasks]
|
||||||
|
|
||||||
|
for i in range(len(initial_tasks)):
|
||||||
|
self.queue_villager(from_time + i*train_time, initial_tasks[i])
|
||||||
|
|
||||||
|
|
||||||
def queue_villagers_over_time(self, from_time, until_time, initial_task):
|
def queue_villagers_over_time(self, from_time, until_time, initial_task):
|
||||||
train_time = self.world.build_times.build_times[Units.VILLAGER]
|
train_time = self.world.build_times.build_times[Units.VILLAGER]
|
||||||
duration = max(0, until_time - from_time)
|
duration = max(0, until_time - from_time)
|
||||||
|
|||||||
@@ -899,3 +899,53 @@ class TestWorld(unittest.TestCase):
|
|||||||
100,
|
100,
|
||||||
200],
|
200],
|
||||||
game.world)
|
game.world)
|
||||||
|
|
||||||
|
|
||||||
|
def test_queue_with_task_list(self):
|
||||||
|
game = Gameplay()
|
||||||
|
|
||||||
|
task_build_lumber = (Tasks.BUILD,
|
||||||
|
{'building': Buildings.LUMBERCAMP,
|
||||||
|
'villagers_to': Tasks.WOOD})
|
||||||
|
|
||||||
|
build_order = [
|
||||||
|
Tasks.SHEEP,
|
||||||
|
Tasks.SHEEP,
|
||||||
|
Tasks.SHEEP,
|
||||||
|
task_build_lumber,
|
||||||
|
]
|
||||||
|
|
||||||
|
game.queue_villagers_by_task_list(0, build_order)
|
||||||
|
game.assign_villager(0, Tasks.IDLE, Tasks.SHEEP)
|
||||||
|
game.build(0, Buildings.HOUSE, Tasks.IDLE, Tasks.SHEEP)
|
||||||
|
game.build(0, Buildings.HOUSE, Tasks.IDLE, Tasks.SHEEP)
|
||||||
|
|
||||||
|
game.play_until_last_action(extra_time=(25 + 35 + 60))
|
||||||
|
|
||||||
|
self.assertEqual(4, len(game.world.buildings))
|
||||||
|
|
||||||
|
train = 25
|
||||||
|
build_lumber = 35
|
||||||
|
build_house = 25
|
||||||
|
|
||||||
|
duration = 4*train + build_lumber + 60
|
||||||
|
|
||||||
|
sheep_rate_per_60 = 19.8
|
||||||
|
|
||||||
|
vil0 = sheep_rate_per_60*(duration/60)
|
||||||
|
vil1 = sheep_rate_per_60*((duration - build_house)/60)
|
||||||
|
vil2 = vil1
|
||||||
|
vil3 = sheep_rate_per_60*((duration - train)/60)
|
||||||
|
vil4 = sheep_rate_per_60*((duration - 2*train)/60)
|
||||||
|
vil5 = sheep_rate_per_60*((duration - 3*train)/60)
|
||||||
|
|
||||||
|
gathered_food = vil0 + vil1 + vil2 + vil3 + vil4 + vil5
|
||||||
|
|
||||||
|
wood_rate_per_60 = 23.4
|
||||||
|
gathered_wood = wood_rate_per_60
|
||||||
|
|
||||||
|
self.assertResourcesMatch([gathered_food,
|
||||||
|
50 + gathered_wood,
|
||||||
|
100,
|
||||||
|
200],
|
||||||
|
game.world)
|
||||||
|
|||||||
Reference in New Issue
Block a user