From c6254e6d1e6e8c2a80ce8ae5092b8aa36014ebe9 Mon Sep 17 00:00:00 2001 From: Nate Bowman Date: Sun, 8 Nov 2026 20:26:38 -0500 Subject: [PATCH] Add fish traps Also likely fixes bugs in farming and fishing, which were not tested before --- aoe/dependencies.py | 2 +- aoe/exceptions.py | 15 ++- aoe/gather.py | 155 ++++++++++++++++++++++------- aoe/types.py | 3 +- aoe/world.py | 124 +++++++++++++++--------- tests/test.py | 230 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 439 insertions(+), 90 deletions(-) diff --git a/aoe/dependencies.py b/aoe/dependencies.py index 412345e..435ab94 100644 --- a/aoe/dependencies.py +++ b/aoe/dependencies.py @@ -270,6 +270,6 @@ class Dependencies(): Units.SKIRMISHER: [Ages.FEUDAL, Buildings.ARCHERYRANGE], Units.ARCHER: [Ages.FEUDAL, Buildings.ARCHERYRANGE], Units.MONK: [Ages.CASTLE, Buildings.MONASTERY], - Units.FISHINGSHIP: [Ages.FEUDAL, Buildings.DOCK], + Units.FISHINGSHIP: [Ages.DARK, Buildings.DOCK], Units.TRADECOG: [Ages.FEUDAL, Buildings.DOCK], } diff --git a/aoe/exceptions.py b/aoe/exceptions.py index edaffef..0468d61 100644 --- a/aoe/exceptions.py +++ b/aoe/exceptions.py @@ -1,8 +1,3 @@ -class InvalidMarketAmountException(Exception): - pass - - - class CannotChangeThePastException(Exception): pass @@ -23,6 +18,11 @@ class IllegalVillagerMoveException(Exception): +class InvalidMarketAmountException(Exception): + pass + + + class MissingDependencyException(Exception): pass @@ -33,6 +33,11 @@ class NotEnoughResourcesException(Exception): +class NotFarmEquivalentException(Exception): + pass + + + class ProductionBuildingNotAvailableException(Exception): pass diff --git a/aoe/gather.py b/aoe/gather.py index 10ef0f7..7bc67b3 100644 --- a/aoe/gather.py +++ b/aoe/gather.py @@ -139,6 +139,22 @@ class Gather(): BIG_NUMBER = 1e6 + NON_ASSIGNABLE_TASKS = [ + Tasks.MONK_GET_RELIC, + Tasks.MONK_IDLE, + Tasks.RELIC, + Tasks.TRADECART, + Tasks.TRADECOG, + ] + + FISHING_TASKS = [ + Tasks.FISH_SHIP_IDLE, + Tasks.FISH_SHIP_SHORE, + Tasks.FISH_SHIP_DEEP, + Tasks.FISH_SHIP_BUILD, + Tasks.FISH_SHIP_TRAP, + ] + def check_gather(self, world, task, count=1): if task in [ @@ -146,6 +162,8 @@ class Gather(): Tasks.BUILD, Tasks.MONK_IDLE, Tasks.LURE, + Tasks.FISH_SHIP_IDLE, + Tasks.FISH_SHIP_BUILD, ]: return @@ -157,9 +175,10 @@ class Gather(): if not match: raise GatherBuildingNotAvailableException - if task == task.FARM: - if world.villager_tasks[task] + count > len(self.unused_farms): - raise GatherBuildingNotAvailableException + if task in [Tasks.FARM, Tasks.FISH_SHIP_TRAP]: + self._check_consumable_gather_building_available(world, + task, + count) def spend_resources(self, cost): @@ -193,8 +212,13 @@ class Gather(): rate = self.gather_rates[task] decay = self.decay_rates[task] - if task == Tasks.FARM: - available = self.farms[0] + if task in [Tasks.FARM, Tasks.FISH_SHIP_TRAP]: + _, __, used, ___ = self._get_consumable_info(task) + try: + available = used[0] + except IndexError: + # this routine may be called even when there are no active farms + available = 0 villagers = min(villagers, 1) else: available = self.gatherable_amounts[task] @@ -210,7 +234,7 @@ class Gather(): def improve_gather_rate_by_building(self, building, tasks): - if building == Buildings.FARM: + if building in [Buildings.FARM, Buildings.FISHTRAP]: raise ValueError('Do not call this routine with a farm') if building not in self.buildings_gather_increase.keys(): @@ -233,46 +257,98 @@ class Gather(): def permanently_modify_consumable_capacity(self, building, increase): + _, __, used, unused = self._get_consumable_info(building) + current_initial_capacity = self.buildings_gather_increase[building] self.buildings_gather_increase[building] += increase modifier = increase/current_initial_capacity - if building == Buildings.FARM: - used = self.farms - unused = self.unused_farms - - for i in range(len(used)): - used[i] += used[i]*multiplier - for i in range(len(unused)): - unused[i] += unused[i]*multiplier + for consumable_list in [used, unused]: + for i in range(len(consumable_list)): + conusmable_list[i] += conusmable_list[i]*multiplier - def stop_using_farms(self, count): + def stop_using_consumable_buildings(self, task, count): + _, __, used, unused = self._get_consumable_info(task) + # remove villagers from farms with lowest remaining capacity - for i in range(count): - heapq.heappush_max(self.unused_farms, - heapq.heappop(self.farms)) + try: + for i in range(count): + heapq.heappush_max(unused, heapq.heappop(used)) + except IndexError: + # if we are stopping because a building has been used up, + # the building will no longer be in `used`, which is correct + pass - def start_using_farms(self, count): + def start_using_consumable_buildings(self, task, count): + _, __, used, unused = self._get_consumable_info(task) + # add villagers to farms with highest remaining capacity for i in range(count): - heapq.heappush(self.farms, - heapq.heappop_max(self.unused_farms)) + heapq.heappush(used, heapq.heappop_max(unused)) - def add_farm(self): - new_farm_value = self.buildings_gather_increase[Buildings.FARM][Tasks.FARM] - heapq.heappush(self.unused_farms, new_farm_value) + def _get_consumable_info(self, task_or_building): + if task_or_building in Buildings: + return self._get_consumable_info_from_building(task_or_building) + elif task_or_building in Tasks: + return self._get_consumable_info_from_task(task_or_building) + else: + raise ValueError - def remove_farm(self): - heapq.heappop(self.farms) + def _get_consumable_info_from_task(self, task): + match task: + case Tasks.FARM: + building = Buildings.FARM + case Tasks.FISH_SHIP_TRAP: + building = Buildings.FISHTRAP + case _: + raise NotFarmEquivalentException + + _, __, used, unused = self._get_consumable_info_from_building(building) + return task, building, used, unused - def get_num_working_farms(self): - return len(self.farms) + def _get_consumable_info_from_building(self, building): + match building: + case Buildings.FARM: + task = Tasks.FARM + used = self.farms + unused = self.unused_farms + case Buildings.FISHTRAP: + task = Tasks.FISH_SHIP_TRAP + used = self.fishtraps + unused = self.unused_fishtraps + case _: + raise NotFarmEquivalentException + + return task, building, used, unused + + + def add_consumable_building(self, building): + task, _, __, unused = self._get_consumable_info(building) + new_value = self.buildings_gather_increase[building][task] + heapq.heappush(unused, new_value) + + + def remove_consumable_building(self, building): + _, __, used, ___ = self._get_consumable_info(building) + heapq.heappop(used) + + + def _check_consumable_gather_building_available(self, world, task, count): + _, __, ___, unused = self._get_consumable_info(task) + if world.villager_tasks[task] + count > len(unused): + raise GatherBuildingNotAvailableException + + + def get_num_working_consumable_buildings(self, task): + _, __, used, ___ = self._get_consumable_info(task) + working = len(used) + return working def add_huntable(self): @@ -289,14 +365,16 @@ class Gather(): Tasks.MONK_IDLE, Tasks.MONK_GET_RELIC, Tasks.FISH_SHIP_IDLE, + Tasks.FISH_SHIP_BUILD, ]: continue rate = self.gather_rates[task] - if task == Tasks.FARM: - for i in range(len(self.farms)): - self.farms[i] -= rate*duration + if task in [Tasks.FARM, Tasks.FISH_SHIP_TRAP]: + _, __, used, unused = self._get_consumable_info(task) + for i in range(len(used)): + used[i] -= rate*duration else: self.gatherable_amounts[task] -= count*rate*duration @@ -315,6 +393,8 @@ class Gather(): self.farms = [] self.unused_farms = [] + self.fishtraps = [] + self.unused_fishtraps = [] self.gather_rates = { Tasks.BERRIES: 18.6/60, @@ -325,7 +405,8 @@ class Gather(): Tasks.FISH_VILLAGER: 25.8/60, Tasks.FISH_SHIP_SHORE: 16.8/60, Tasks.FISH_SHIP_DEEP: 29.4/60, - Tasks.FISHTRAP: 21/60, + Tasks.FISH_SHIP_BUILD: 0, + Tasks.FISH_SHIP_TRAP: 21/60, Tasks.WOOD: 23.4/60, Tasks.GOLD: 22.8/60, Tasks.TRADECART: 25.9/60, @@ -353,7 +434,7 @@ class Gather(): Tasks.FISH_VILLAGER: {Resources.FOOD: 1}, Tasks.FISH_SHIP_SHORE: {Resources.FOOD: 1}, Tasks.FISH_SHIP_DEEP: {Resources.FOOD: 1}, - Tasks.FISHTRAP: {Resources.FOOD: 1}, + Tasks.FISH_SHIP_TRAP: {Resources.FOOD: 1}, Tasks.WOOD: {Resources.WOOD: 1}, Tasks.GOLD: {Resources.GOLD: 1}, Tasks.TRADECART: {Resources.GOLD: 1}, @@ -380,7 +461,7 @@ class Gather(): set([Buildings.TOWNCENTER])], Tasks.FISH_SHIP_SHORE: [set([Buildings.DOCK])], Tasks.FISH_SHIP_DEEP: [set([Buildings.DOCK])], - Tasks.FISHTRAP: [set([Buildings.DOCK, Buildings.FISHTRAP])], + Tasks.FISH_SHIP_TRAP: [set([Buildings.DOCK, Buildings.FISHTRAP])], Tasks.WOOD: [set([Buildings.LUMBERCAMP]), set([Buildings.TOWNCENTER])], Tasks.GOLD: [set([Buildings.MININGCAMP]), @@ -410,7 +491,7 @@ class Gather(): Tasks.FISH_VILLAGER: 0, Tasks.FISH_SHIP_SHORE: 0, Tasks.FISH_SHIP_DEEP: 0, - Tasks.FISHTRAP: 0, + Tasks.FISH_SHIP_TRAP: 0, Tasks.WOOD: 0, Tasks.GOLD: 0, Tasks.TRADECART: Gather.BIG_NUMBER, @@ -434,7 +515,7 @@ class Gather(): Tasks.STONE: 4*350, Tasks.BERRIES: 6*125, Tasks.HUNT: 4*140}, - #Buildings.FISHTRAP: {Tasks.WOOD: 100}, + Buildings.FISHTRAP: {Tasks.FISH_SHIP_TRAP: 715}, Tasks.LURE: {Tasks.BOAR: 340}, } @@ -448,7 +529,7 @@ class Gather(): Tasks.FISH_VILLAGER: 0, Tasks.FISH_SHIP_SHORE: 0, Tasks.FISH_SHIP_DEEP: 0.5, - Tasks.FISHTRAP: 0, + Tasks.FISH_SHIP_TRAP: 0, Tasks.WOOD: 0.85, Tasks.GOLD: 0, Tasks.TRADECART: 1, diff --git a/aoe/types.py b/aoe/types.py index 7965833..768fcf7 100644 --- a/aoe/types.py +++ b/aoe/types.py @@ -59,7 +59,8 @@ class Tasks(Enum): FISH_SHIP_IDLE = auto() FISH_SHIP_SHORE = auto() FISH_SHIP_DEEP = auto() - FISHTRAP = auto() + FISH_SHIP_BUILD = auto() + FISH_SHIP_TRAP = auto() WOOD = auto() GOLD = auto() MONK_IDLE = auto() diff --git a/aoe/world.py b/aoe/world.py index cd6cc52..59cc99d 100644 --- a/aoe/world.py +++ b/aoe/world.py @@ -43,7 +43,10 @@ class World(): # to farms with the highest capacity. # We keep track of only the closest upcoming farm deletion. - # TODO fishtraps + # TODO make used* and unused* into single dict w/ task as key + # TODO gather.consumable_building_tasks + # TODO require market to use market buy/sell + # TODO what happens if you take away a builder while building? # TODO allow automation: # reseeding of farms # queuing of villagers @@ -103,7 +106,11 @@ class World(): def _schedule_next_gather_rate_decrease(self, task): - if task in [Tasks.IDLE, Tasks.BUILD, Tasks.LURE]: + if task in [Tasks.IDLE, + Tasks.BUILD, + Tasks.LURE, + Tasks.FISH_SHIP_IDLE, + Tasks.FISH_SHIP_BUILD]: return # remove old decrease @@ -115,8 +122,9 @@ class World(): if next_decrease is not None: next_decrease += self.current_time - if task == Tasks.FARM: - self.events[next_decrease].append((self._remove_farm, ())) + if task in [Tasks.FARM, Tasks.FISH_SHIP_TRAP]: + self.events[next_decrease].append((self._remove_consumable_building, + (task,))) else: self.events[next_decrease].append((self._decrease_gather_rate_by_overuse, (task,))) @@ -176,29 +184,7 @@ class World(): if self.villager_tasks[previous_task] < count: raise IllegalVillagerMoveException - non_assignable_tasks = [ - Tasks.MONK_GET_RELIC, - Tasks.MONK_IDLE, - Tasks.RELIC, - Tasks.TRADECART, - Tasks.TRADECOG, - ] - - fishing_tasks = [ - Tasks.FISH_SHIP_IDLE, - Tasks.FISH_SHIP_SHORE, - Tasks.FISH_SHIP_DEEP, - Tasks.FISHTRAP, - ] - - if new_task in non_assignable_tasks or \ - previous_task in non_assignable_tasks: - raise IllegalVillagerMoveException - - num_fishing_tasks = (int(new_task in non_assignable_tasks) + - int(previous_task in non_assignable_tasks)) - if num_fishing_tasks == 1: - raise IllegalVillagerMoveException + self._check_single_villager_move(previous_task, new_task) if new_task: self.gather.check_gather(self, new_task, count) @@ -208,26 +194,61 @@ class World(): self.villager_tasks[previous_task] -= count - if previous_task == Tasks.FARM: - self.gather.stop_using_farms(count) + if previous_task in [Tasks.FARM, Tasks.FISH_SHIP_TRAP]: + self.gather.stop_using_consumable_buildings(previous_task, count) - if new_task == Tasks.FARM: - self.gather.start_using_farms(count) + if new_task in [Tasks.FARM, Tasks.FISH_SHIP_TRAP]: + self.gather.start_using_consumable_buildings(new_task, count) self._schedule_next_gather_rate_decrease(previous_task) if new_task: self._schedule_next_gather_rate_decrease(new_task) - def _check_villager_move(self, villagers_from_count): + def _check_valid_builders(self, villagers_from, building): + # If building a fishtrap, at least one builder needs to be a fishing + # ship. If building anything else, no builders can be fishing ships + fish_builder = any([v in Gather.FISHING_TASKS for v in villagers_from]) + building_fishtrap = (building == Buildings.FISHTRAP) + + if fish_builder != building_fishtrap: + raise IllegalVillagerMoveException + + + def _check_single_villager_move(self, villager_from, villager_to): + for v in [villager_from, villager_to]: + if v in Gather.NON_ASSIGNABLE_TASKS: + raise IllegalVillagerMoveException + + from_fishing = (villager_from in Gather.FISHING_TASKS) + to_fishing = (villager_to in Gather.FISHING_TASKS) + if from_fishing != to_fishing: + raise IllegalVillagerMoveException + + + def _check_villager_move(self, + villagers_from_count, + villagers_from, + villagers_to): for task, count in villagers_from_count.items(): if self.villager_tasks[task] < count: raise IllegalVillagerMoveException + for v_from, v_to in zip(villagers_from, villagers_to): + self._check_single_villager_move(v_from, v_to) + def _move_villagers_to_build(self, villagers_from_count): for task, count in villagers_from_count.items(): - self.assign_villager(task, Tasks.BUILD, count) + build_task = self._get_build_task_from_task(task) + self.assign_villager(task, build_task, count) + + + def _get_build_task_from_task(self, task): + if task in Gather.FISHING_TASKS: + return Tasks.FISH_SHIP_BUILD + else: + return Tasks.BUILD def get_relic(self, walking_time=60): @@ -267,7 +288,11 @@ class World(): villagers_from_count = Counter(villagers_from) - self._check_villager_move(villagers_from_count) + self._check_villager_move(villagers_from_count, + villagers_from, + villagers_to) + + self._check_valid_builders(villagers_from, building) self.dependencies.check_dependencies(self, building) @@ -293,26 +318,33 @@ class World(): if building == Buildings.HOUSE: self._free_housing() - if building == Buildings.FARM: - self._add_farm() + if building in [Buildings.FARM, Buildings.FISHTRAP]: + self.gather.add_consumable_building(building) else: self._improve_gather_rate_by_building(building, tasks_improved) for task, count in villagers_to.items(): - self.assign_villager(Tasks.BUILD, task, count) + build_task = self._get_build_task_from_task(task) + self.assign_villager(build_task, task, count) - def _add_farm(self): - self.buildings.append(Buildings.FARM) - self.gather.add_farm() + def _remove_consumable_building(self, task): + match task: + case Tasks.FARM: + building = Buildings.FARM + next_task = Tasks.IDLE + case Tasks.FISH_SHIP_TRAP: + building = Buildings.FISHTRAP + next_task = Tasks.FISH_SHIP_DEEP + case _: + raise NotFarmEquivalentException + self.buildings.remove(building) + self.gather.remove_consumable_building(building) - def _remove_farm(self): - self.buildings.remove(Buildings.FARM) - self.gather.remove_farm() - - if self.villager_tasks[Tasks.FARM] > gather.get_num_working_farms(): - self.assign_villager(Tasks.FARM, Tasks.IDLE) + num_working_buildings = self.gather.get_num_working_consumable_buildings(task) + if self.villager_tasks[task] > num_working_buildings: + self.assign_villager(task, next_task) def advance_by_time(self, duration): diff --git a/tests/test.py b/tests/test.py index f04fac9..cd4b7b9 100644 --- a/tests/test.py +++ b/tests/test.py @@ -455,3 +455,233 @@ class TestWorld(unittest.TestCase): with self.assertRaises(InvalidMarketAmountException): game.market_sell(0, Resources.FOOD, 50) game.play_until(1) + + + def test_farm_simple(self): + game = Gameplay() + + game.world.age = Ages.DARK + game.world.gather.resources = [500, 500, 500, 500] + game.world._add_building(Buildings.MILL, {}, {}) + game.world._add_building(Buildings.FARM, {}, {}) + + game.assign_villager(0, Tasks.IDLE, Tasks.FARM) + + rate_per_60 = 20 + + game.play_until(60) + + new_food = 500 + rate_per_60 + + self.assertResourcesMatch([new_food, 500, 500, 500], game.world) + + + def test_farm_build(self): + game = Gameplay() + + game.world.age = Ages.DARK + game.world.gather.resources = [500, 500, 500, 500] + game.world._add_building(Buildings.MILL, {}, {}) + + game.build(0, Buildings.FARM, Tasks.IDLE, Tasks.IDLE) + game.assign_villager(30, Tasks.IDLE, Tasks.FARM) + + rate_per_60 = 20 + + game.play_until(90) + + new_food = 500 + rate_per_60 + + self.assertResourcesMatch([new_food, 440, 500, 500], game.world) + + + def test_farm_depleted(self): + game = Gameplay() + + game.world.age = Ages.DARK + game.world.gather.resources = [500, 500, 500, 500] + game.world._add_building(Buildings.MILL, {}, {}) + game.world._add_building(Buildings.FARM, {}, {}) + + game.assign_villager(0, Tasks.IDLE, Tasks.FARM) + + amount_per_farm = 175 + + game.play_until(1000) + + new_food = 500 + amount_per_farm + + self.assertResourcesMatch([new_food, 500, 500, 500], game.world) + self.assertEqual(0, len(game.world.gather.farms)) + self.assertEqual(0, len(game.world.gather.unused_farms)) + + + def test_farm_too_many_farmers(self): + game = Gameplay() + + game.world.age = Ages.DARK + game.world.gather.resources = [500, 500, 500, 500] + game.world._add_building(Buildings.MILL, {}, {}) + game.world._add_building(Buildings.FARM, {}, {}) + + game.assign_villager(0, Tasks.IDLE, Tasks.FARM) + game.assign_villager(0, Tasks.IDLE, Tasks.FARM) + + with self.assertRaises(GatherBuildingNotAvailableException): + game.play_until(1) + + + def test_farm_off_and_on(self): + game = Gameplay() + + game.world.age = Ages.DARK + game.world.gather.resources = [500, 500, 500, 500] + game.world._add_building(Buildings.MILL, {}, {}) + game.world._add_building(Buildings.FARM, {}, {}) + + game.assign_villager(0, Tasks.IDLE, Tasks.FARM) + game.assign_villager(30, Tasks.FARM, Tasks.IDLE) + game.assign_villager(60, Tasks.IDLE, Tasks.FARM) + + rate_per_60 = 20 + + game.play_until(90) + + new_food = 500 + rate_per_60 + + self.assertResourcesMatch([new_food, 500, 500, 500], game.world) + + + def test_fishing_ship(self): + game = Gameplay() + + game.world.age = Ages.DARK + game.world.gather.resources = [500, 500, 500, 500] + game.world._add_building(Buildings.DOCK, {}, {}) + + game.queue_fishing_ship(0) + + rate_per_60 = 29.4 + ship_training = 40 + + game.play_until(ship_training - 1) + self.assertResourcesMatch([500, 425, 500, 500], game.world) + + game.play_until(ship_training + 60) + new_food = 500 + rate_per_60 + + self.assertResourcesMatch([new_food, 425, 500, 500], game.world) + + + def test_fishtrap_simple(self): + game = Gameplay() + + game.world.age = Ages.FEUDAL + game.world.gather.resources = [500, 500, 500, 500] + game.world._add_building(Buildings.DOCK, {}, {}) + game.world._add_building(Buildings.FISHTRAP, {}, {}) + game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_TRAP) + + rate_per_60 = 21 + + game.play_until(60) + + new_food = 500 + rate_per_60 + + self.assertResourcesMatch([new_food, 500, 500, 500], game.world) + + + def test_fishtrap_build(self): + game = Gameplay() + + game.world.age = Ages.FEUDAL + game.world.gather.resources = [500, 500, 500, 500] + game.world._add_building(Buildings.DOCK, {}, {}) + game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_IDLE) + + game.build(0, + Buildings.FISHTRAP, + Tasks.FISH_SHIP_IDLE, + Tasks.FISH_SHIP_IDLE) + + game.play_until(10) + + game.assign_villager(50, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP) + + rate_per_60 = 21 + + game.play_until(110) + + new_food = 500 + rate_per_60 + + self.assertResourcesMatch([new_food, 400, 500, 500], game.world) + + + def test_fishtrap_depleted(self): + game = Gameplay() + + game.world.age = Ages.FEUDAL + game.world.gather.resources = [500, 500, 500, 500] + game.world._add_building(Buildings.DOCK, {}, {}) + game.world._add_building(Buildings.FISHTRAP, {}, {}) + game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_IDLE) + + game.assign_villager(0, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP) + + amount_per_fishtrap = 715 + rate_per_60 = 21 + duration = (amount_per_fishtrap/rate_per_60)*60 + 1 + + game.play_until(duration) + + new_food = 500 + amount_per_fishtrap + + self.assertResourcesMatch([new_food, 500, 500, 500], game.world) + self.assertEqual(0, len(game.world.gather.fishtraps)) + self.assertEqual(0, len(game.world.gather.unused_fishtraps)) + + # fishing ships go back to fishing after trap is depleted + deep_rate_per_60 = 29.4 + game.play_until(duration + 60) + new_food += deep_rate_per_60 + + self.assertResourcesMatch([new_food, 500, 500, 500], game.world) + + + def test_fishtrap_too_many_fish_ships(self): + game = Gameplay() + + game.world.age = Ages.FEUDAL + game.world.gather.resources = [500, 500, 500, 500] + game.world._add_building(Buildings.DOCK, {}, {}) + game.world._add_building(Buildings.FISHTRAP, {}, {}) + game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_IDLE) + game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_IDLE) + + game.assign_villager(0, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP) + game.assign_villager(0, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP) + + with self.assertRaises(GatherBuildingNotAvailableException): + game.play_until(1) + + + def test_fishtrap_off_and_on(self): + game = Gameplay() + + game.world.age = Ages.FEUDAL + game.world.gather.resources = [500, 500, 500, 500] + game.world._add_building(Buildings.DOCK, {}, {}) + game.world._add_building(Buildings.FISHTRAP, {}, {}) + game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_IDLE) + + game.assign_villager(0, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP) + game.assign_villager(30, Tasks.FISH_SHIP_TRAP, Tasks.FISH_SHIP_IDLE) + game.assign_villager(60, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP) + + rate_per_60 = 21 + + game.play_until(90) + + new_food = 500 + rate_per_60 + + self.assertResourcesMatch([new_food, 500, 500, 500], game.world)