Allow hunting and building as initial tasks in a better way
This commit is contained in:
@@ -63,8 +63,9 @@ class Gameplay():
|
|||||||
self.queue_villager(from_time + i*train_time, initial_task)
|
self.queue_villager(from_time + i*train_time, initial_task)
|
||||||
|
|
||||||
|
|
||||||
def queue_villager(self, action_time, initial_task):
|
def queue_villager(self, action_time, initial_task, **kwargs):
|
||||||
self._check_time(action_time)
|
self._check_time(action_time)
|
||||||
|
initial_task = (initial_task, kwargs)
|
||||||
self.actions[action_time].append((self.world.queue_villager,
|
self.actions[action_time].append((self.world.queue_villager,
|
||||||
(initial_task,)))
|
(initial_task,)))
|
||||||
|
|
||||||
|
|||||||
30
aoe/world.py
30
aoe/world.py
@@ -484,9 +484,20 @@ class World():
|
|||||||
if thing == Units.VILLAGER:
|
if thing == Units.VILLAGER:
|
||||||
self.villagers += 1
|
self.villagers += 1
|
||||||
self.villager_tasks[Tasks.IDLE] += 1
|
self.villager_tasks[Tasks.IDLE] += 1
|
||||||
if not initial_task:
|
|
||||||
initial_task = Tasks.IDLE
|
initial_task, kwargs = self._parse_initial_task(initial_task)
|
||||||
self.assign_villager(Tasks.IDLE, initial_task)
|
|
||||||
|
if initial_task == Tasks.LURE:
|
||||||
|
self.lure_huntable_with_villager(Tasks.IDLE, **kwargs)
|
||||||
|
elif initial_task == Tasks.BUILD:
|
||||||
|
if 'building_task' not in kwargs.keys():
|
||||||
|
kwargs['building_task'] = None
|
||||||
|
self.build(kwargs['building'],
|
||||||
|
Tasks.IDLE,
|
||||||
|
kwargs['villagers_to'],
|
||||||
|
kwargs['building_task'])
|
||||||
|
else:
|
||||||
|
self.assign_villager(Tasks.IDLE, initial_task)
|
||||||
elif thing == Units.MONK:
|
elif thing == Units.MONK:
|
||||||
self.villager_tasks[Tasks.MONK_IDLE] += 1
|
self.villager_tasks[Tasks.MONK_IDLE] += 1
|
||||||
self._get_next_waiting_relic()
|
self._get_next_waiting_relic()
|
||||||
@@ -548,6 +559,19 @@ class World():
|
|||||||
self._queue_thing(Units.TRADECART)
|
self._queue_thing(Units.TRADECART)
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_initial_task(self, initial_task):
|
||||||
|
kwargs = {}
|
||||||
|
|
||||||
|
if isinstance(initial_task, tuple):
|
||||||
|
kwargs = initial_task[1]
|
||||||
|
initial_task = initial_task[0]
|
||||||
|
|
||||||
|
if not initial_task:
|
||||||
|
initial_task = Tasks.IDLE
|
||||||
|
|
||||||
|
return initial_task, kwargs
|
||||||
|
|
||||||
|
|
||||||
def _handle_events(self):
|
def _handle_events(self):
|
||||||
for func, args in self.events[self.current_time]:
|
for func, args in self.events[self.current_time]:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -251,6 +251,32 @@ class TestWorld(unittest.TestCase):
|
|||||||
self.assertResourcesMatch([200 + gathered, 200, 100, 200], game.world)
|
self.assertResourcesMatch([200 + gathered, 200, 100, 200], game.world)
|
||||||
|
|
||||||
|
|
||||||
|
def test_gather_boar_initial_lure(self):
|
||||||
|
walking = 30
|
||||||
|
|
||||||
|
game = Gameplay()
|
||||||
|
game.queue_villager(0, Tasks.LURE)
|
||||||
|
game.play_until(25 + walking + 60)
|
||||||
|
|
||||||
|
boar_rate_times_60 = 24.6
|
||||||
|
gathered = boar_rate_times_60
|
||||||
|
|
||||||
|
self.assertResourcesMatch([150 + gathered, 200, 100, 200], game.world)
|
||||||
|
|
||||||
|
|
||||||
|
def test_gather_boar_initial_lure_custom_time(self):
|
||||||
|
walking = 80
|
||||||
|
|
||||||
|
game = Gameplay()
|
||||||
|
game.queue_villager(0, Tasks.LURE, walking_time=walking)
|
||||||
|
game.play_until(25 + walking + 60)
|
||||||
|
|
||||||
|
boar_rate_times_60 = 24.6
|
||||||
|
gathered = boar_rate_times_60
|
||||||
|
|
||||||
|
self.assertResourcesMatch([150 + gathered, 200, 100, 200], game.world)
|
||||||
|
|
||||||
|
|
||||||
def test_gather_boar_limited(self):
|
def test_gather_boar_limited(self):
|
||||||
walking = 20
|
walking = 20
|
||||||
|
|
||||||
@@ -763,3 +789,29 @@ class TestWorld(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(4, len(game.world.buildings))
|
self.assertEqual(4, len(game.world.buildings))
|
||||||
self.assertResourcesMatch([200 + gathered, 50, 100, 200], game.world)
|
self.assertResourcesMatch([200 + gathered, 50, 100, 200], game.world)
|
||||||
|
|
||||||
|
|
||||||
|
def test_initial_build(self):
|
||||||
|
game = Gameplay()
|
||||||
|
|
||||||
|
game.queue_villager(0,
|
||||||
|
Tasks.BUILD,
|
||||||
|
building=Buildings.HOUSE,
|
||||||
|
villagers_to=Tasks.SHEEP)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
game.play_until(25 + 25 + 60)
|
||||||
|
self.assertEqual(2, len(game.world.buildings))
|
||||||
|
self.assertEqual(5, game.world.population)
|
||||||
|
|
||||||
|
sheep_rate_per_60 = 19.8
|
||||||
|
gathered = sheep_rate_per_60
|
||||||
|
|
||||||
|
self.assertResourcesMatch([150 + gathered, 175, 100, 200], game.world)
|
||||||
|
|||||||
Reference in New Issue
Block a user