Add fish traps
Also likely fixes bugs in farming and fishing, which were not tested before
This commit is contained in:
@@ -270,6 +270,6 @@ class Dependencies():
|
|||||||
Units.SKIRMISHER: [Ages.FEUDAL, Buildings.ARCHERYRANGE],
|
Units.SKIRMISHER: [Ages.FEUDAL, Buildings.ARCHERYRANGE],
|
||||||
Units.ARCHER: [Ages.FEUDAL, Buildings.ARCHERYRANGE],
|
Units.ARCHER: [Ages.FEUDAL, Buildings.ARCHERYRANGE],
|
||||||
Units.MONK: [Ages.CASTLE, Buildings.MONASTERY],
|
Units.MONK: [Ages.CASTLE, Buildings.MONASTERY],
|
||||||
Units.FISHINGSHIP: [Ages.FEUDAL, Buildings.DOCK],
|
Units.FISHINGSHIP: [Ages.DARK, Buildings.DOCK],
|
||||||
Units.TRADECOG: [Ages.FEUDAL, Buildings.DOCK],
|
Units.TRADECOG: [Ages.FEUDAL, Buildings.DOCK],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
class InvalidMarketAmountException(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CannotChangeThePastException(Exception):
|
class CannotChangeThePastException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -23,6 +18,11 @@ class IllegalVillagerMoveException(Exception):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidMarketAmountException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MissingDependencyException(Exception):
|
class MissingDependencyException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -33,6 +33,11 @@ class NotEnoughResourcesException(Exception):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class NotFarmEquivalentException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ProductionBuildingNotAvailableException(Exception):
|
class ProductionBuildingNotAvailableException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
155
aoe/gather.py
155
aoe/gather.py
@@ -139,6 +139,22 @@ class Gather():
|
|||||||
|
|
||||||
BIG_NUMBER = 1e6
|
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):
|
def check_gather(self, world, task, count=1):
|
||||||
if task in [
|
if task in [
|
||||||
@@ -146,6 +162,8 @@ class Gather():
|
|||||||
Tasks.BUILD,
|
Tasks.BUILD,
|
||||||
Tasks.MONK_IDLE,
|
Tasks.MONK_IDLE,
|
||||||
Tasks.LURE,
|
Tasks.LURE,
|
||||||
|
Tasks.FISH_SHIP_IDLE,
|
||||||
|
Tasks.FISH_SHIP_BUILD,
|
||||||
]:
|
]:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -157,9 +175,10 @@ class Gather():
|
|||||||
if not match:
|
if not match:
|
||||||
raise GatherBuildingNotAvailableException
|
raise GatherBuildingNotAvailableException
|
||||||
|
|
||||||
if task == task.FARM:
|
if task in [Tasks.FARM, Tasks.FISH_SHIP_TRAP]:
|
||||||
if world.villager_tasks[task] + count > len(self.unused_farms):
|
self._check_consumable_gather_building_available(world,
|
||||||
raise GatherBuildingNotAvailableException
|
task,
|
||||||
|
count)
|
||||||
|
|
||||||
|
|
||||||
def spend_resources(self, cost):
|
def spend_resources(self, cost):
|
||||||
@@ -193,8 +212,13 @@ class Gather():
|
|||||||
rate = self.gather_rates[task]
|
rate = self.gather_rates[task]
|
||||||
decay = self.decay_rates[task]
|
decay = self.decay_rates[task]
|
||||||
|
|
||||||
if task == Tasks.FARM:
|
if task in [Tasks.FARM, Tasks.FISH_SHIP_TRAP]:
|
||||||
available = self.farms[0]
|
_, __, 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)
|
villagers = min(villagers, 1)
|
||||||
else:
|
else:
|
||||||
available = self.gatherable_amounts[task]
|
available = self.gatherable_amounts[task]
|
||||||
@@ -210,7 +234,7 @@ class Gather():
|
|||||||
|
|
||||||
|
|
||||||
def improve_gather_rate_by_building(self, building, tasks):
|
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')
|
raise ValueError('Do not call this routine with a farm')
|
||||||
|
|
||||||
if building not in self.buildings_gather_increase.keys():
|
if building not in self.buildings_gather_increase.keys():
|
||||||
@@ -233,46 +257,98 @@ class Gather():
|
|||||||
|
|
||||||
|
|
||||||
def permanently_modify_consumable_capacity(self, building, increase):
|
def permanently_modify_consumable_capacity(self, building, increase):
|
||||||
|
_, __, used, unused = self._get_consumable_info(building)
|
||||||
|
|
||||||
current_initial_capacity = self.buildings_gather_increase[building]
|
current_initial_capacity = self.buildings_gather_increase[building]
|
||||||
self.buildings_gather_increase[building] += increase
|
self.buildings_gather_increase[building] += increase
|
||||||
|
|
||||||
modifier = increase/current_initial_capacity
|
modifier = increase/current_initial_capacity
|
||||||
|
|
||||||
if building == Buildings.FARM:
|
for consumable_list in [used, unused]:
|
||||||
used = self.farms
|
for i in range(len(consumable_list)):
|
||||||
unused = self.unused_farms
|
conusmable_list[i] += conusmable_list[i]*multiplier
|
||||||
|
|
||||||
for i in range(len(used)):
|
|
||||||
used[i] += used[i]*multiplier
|
|
||||||
for i in range(len(unused)):
|
|
||||||
unused[i] += unused[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
|
# remove villagers from farms with lowest remaining capacity
|
||||||
for i in range(count):
|
try:
|
||||||
heapq.heappush_max(self.unused_farms,
|
for i in range(count):
|
||||||
heapq.heappop(self.farms))
|
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
|
# add villagers to farms with highest remaining capacity
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
heapq.heappush(self.farms,
|
heapq.heappush(used, heapq.heappop_max(unused))
|
||||||
heapq.heappop_max(self.unused_farms))
|
|
||||||
|
|
||||||
|
|
||||||
def add_farm(self):
|
def _get_consumable_info(self, task_or_building):
|
||||||
new_farm_value = self.buildings_gather_increase[Buildings.FARM][Tasks.FARM]
|
if task_or_building in Buildings:
|
||||||
heapq.heappush(self.unused_farms, new_farm_value)
|
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):
|
def _get_consumable_info_from_task(self, task):
|
||||||
heapq.heappop(self.farms)
|
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):
|
def _get_consumable_info_from_building(self, building):
|
||||||
return len(self.farms)
|
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):
|
def add_huntable(self):
|
||||||
@@ -289,14 +365,16 @@ class Gather():
|
|||||||
Tasks.MONK_IDLE,
|
Tasks.MONK_IDLE,
|
||||||
Tasks.MONK_GET_RELIC,
|
Tasks.MONK_GET_RELIC,
|
||||||
Tasks.FISH_SHIP_IDLE,
|
Tasks.FISH_SHIP_IDLE,
|
||||||
|
Tasks.FISH_SHIP_BUILD,
|
||||||
]:
|
]:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
rate = self.gather_rates[task]
|
rate = self.gather_rates[task]
|
||||||
|
|
||||||
if task == Tasks.FARM:
|
if task in [Tasks.FARM, Tasks.FISH_SHIP_TRAP]:
|
||||||
for i in range(len(self.farms)):
|
_, __, used, unused = self._get_consumable_info(task)
|
||||||
self.farms[i] -= rate*duration
|
for i in range(len(used)):
|
||||||
|
used[i] -= rate*duration
|
||||||
else:
|
else:
|
||||||
self.gatherable_amounts[task] -= count*rate*duration
|
self.gatherable_amounts[task] -= count*rate*duration
|
||||||
|
|
||||||
@@ -315,6 +393,8 @@ class Gather():
|
|||||||
|
|
||||||
self.farms = []
|
self.farms = []
|
||||||
self.unused_farms = []
|
self.unused_farms = []
|
||||||
|
self.fishtraps = []
|
||||||
|
self.unused_fishtraps = []
|
||||||
|
|
||||||
self.gather_rates = {
|
self.gather_rates = {
|
||||||
Tasks.BERRIES: 18.6/60,
|
Tasks.BERRIES: 18.6/60,
|
||||||
@@ -325,7 +405,8 @@ class Gather():
|
|||||||
Tasks.FISH_VILLAGER: 25.8/60,
|
Tasks.FISH_VILLAGER: 25.8/60,
|
||||||
Tasks.FISH_SHIP_SHORE: 16.8/60,
|
Tasks.FISH_SHIP_SHORE: 16.8/60,
|
||||||
Tasks.FISH_SHIP_DEEP: 29.4/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.WOOD: 23.4/60,
|
||||||
Tasks.GOLD: 22.8/60,
|
Tasks.GOLD: 22.8/60,
|
||||||
Tasks.TRADECART: 25.9/60,
|
Tasks.TRADECART: 25.9/60,
|
||||||
@@ -353,7 +434,7 @@ class Gather():
|
|||||||
Tasks.FISH_VILLAGER: {Resources.FOOD: 1},
|
Tasks.FISH_VILLAGER: {Resources.FOOD: 1},
|
||||||
Tasks.FISH_SHIP_SHORE: {Resources.FOOD: 1},
|
Tasks.FISH_SHIP_SHORE: {Resources.FOOD: 1},
|
||||||
Tasks.FISH_SHIP_DEEP: {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.WOOD: {Resources.WOOD: 1},
|
||||||
Tasks.GOLD: {Resources.GOLD: 1},
|
Tasks.GOLD: {Resources.GOLD: 1},
|
||||||
Tasks.TRADECART: {Resources.GOLD: 1},
|
Tasks.TRADECART: {Resources.GOLD: 1},
|
||||||
@@ -380,7 +461,7 @@ class Gather():
|
|||||||
set([Buildings.TOWNCENTER])],
|
set([Buildings.TOWNCENTER])],
|
||||||
Tasks.FISH_SHIP_SHORE: [set([Buildings.DOCK])],
|
Tasks.FISH_SHIP_SHORE: [set([Buildings.DOCK])],
|
||||||
Tasks.FISH_SHIP_DEEP: [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]),
|
Tasks.WOOD: [set([Buildings.LUMBERCAMP]),
|
||||||
set([Buildings.TOWNCENTER])],
|
set([Buildings.TOWNCENTER])],
|
||||||
Tasks.GOLD: [set([Buildings.MININGCAMP]),
|
Tasks.GOLD: [set([Buildings.MININGCAMP]),
|
||||||
@@ -410,7 +491,7 @@ class Gather():
|
|||||||
Tasks.FISH_VILLAGER: 0,
|
Tasks.FISH_VILLAGER: 0,
|
||||||
Tasks.FISH_SHIP_SHORE: 0,
|
Tasks.FISH_SHIP_SHORE: 0,
|
||||||
Tasks.FISH_SHIP_DEEP: 0,
|
Tasks.FISH_SHIP_DEEP: 0,
|
||||||
Tasks.FISHTRAP: 0,
|
Tasks.FISH_SHIP_TRAP: 0,
|
||||||
Tasks.WOOD: 0,
|
Tasks.WOOD: 0,
|
||||||
Tasks.GOLD: 0,
|
Tasks.GOLD: 0,
|
||||||
Tasks.TRADECART: Gather.BIG_NUMBER,
|
Tasks.TRADECART: Gather.BIG_NUMBER,
|
||||||
@@ -434,7 +515,7 @@ class Gather():
|
|||||||
Tasks.STONE: 4*350,
|
Tasks.STONE: 4*350,
|
||||||
Tasks.BERRIES: 6*125,
|
Tasks.BERRIES: 6*125,
|
||||||
Tasks.HUNT: 4*140},
|
Tasks.HUNT: 4*140},
|
||||||
#Buildings.FISHTRAP: {Tasks.WOOD: 100},
|
Buildings.FISHTRAP: {Tasks.FISH_SHIP_TRAP: 715},
|
||||||
Tasks.LURE: {Tasks.BOAR: 340},
|
Tasks.LURE: {Tasks.BOAR: 340},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -448,7 +529,7 @@ class Gather():
|
|||||||
Tasks.FISH_VILLAGER: 0,
|
Tasks.FISH_VILLAGER: 0,
|
||||||
Tasks.FISH_SHIP_SHORE: 0,
|
Tasks.FISH_SHIP_SHORE: 0,
|
||||||
Tasks.FISH_SHIP_DEEP: 0.5,
|
Tasks.FISH_SHIP_DEEP: 0.5,
|
||||||
Tasks.FISHTRAP: 0,
|
Tasks.FISH_SHIP_TRAP: 0,
|
||||||
Tasks.WOOD: 0.85,
|
Tasks.WOOD: 0.85,
|
||||||
Tasks.GOLD: 0,
|
Tasks.GOLD: 0,
|
||||||
Tasks.TRADECART: 1,
|
Tasks.TRADECART: 1,
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ class Tasks(Enum):
|
|||||||
FISH_SHIP_IDLE = auto()
|
FISH_SHIP_IDLE = auto()
|
||||||
FISH_SHIP_SHORE = auto()
|
FISH_SHIP_SHORE = auto()
|
||||||
FISH_SHIP_DEEP = auto()
|
FISH_SHIP_DEEP = auto()
|
||||||
FISHTRAP = auto()
|
FISH_SHIP_BUILD = auto()
|
||||||
|
FISH_SHIP_TRAP = auto()
|
||||||
WOOD = auto()
|
WOOD = auto()
|
||||||
GOLD = auto()
|
GOLD = auto()
|
||||||
MONK_IDLE = auto()
|
MONK_IDLE = auto()
|
||||||
|
|||||||
124
aoe/world.py
124
aoe/world.py
@@ -43,7 +43,10 @@ class World():
|
|||||||
# to farms with the highest capacity.
|
# to farms with the highest capacity.
|
||||||
# We keep track of only the closest upcoming farm deletion.
|
# 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:
|
# TODO allow automation:
|
||||||
# reseeding of farms
|
# reseeding of farms
|
||||||
# queuing of villagers
|
# queuing of villagers
|
||||||
@@ -103,7 +106,11 @@ class World():
|
|||||||
|
|
||||||
|
|
||||||
def _schedule_next_gather_rate_decrease(self, task):
|
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
|
return
|
||||||
|
|
||||||
# remove old decrease
|
# remove old decrease
|
||||||
@@ -115,8 +122,9 @@ class World():
|
|||||||
|
|
||||||
if next_decrease is not None:
|
if next_decrease is not None:
|
||||||
next_decrease += self.current_time
|
next_decrease += self.current_time
|
||||||
if task == Tasks.FARM:
|
if task in [Tasks.FARM, Tasks.FISH_SHIP_TRAP]:
|
||||||
self.events[next_decrease].append((self._remove_farm, ()))
|
self.events[next_decrease].append((self._remove_consumable_building,
|
||||||
|
(task,)))
|
||||||
else:
|
else:
|
||||||
self.events[next_decrease].append((self._decrease_gather_rate_by_overuse,
|
self.events[next_decrease].append((self._decrease_gather_rate_by_overuse,
|
||||||
(task,)))
|
(task,)))
|
||||||
@@ -176,29 +184,7 @@ class World():
|
|||||||
if self.villager_tasks[previous_task] < count:
|
if self.villager_tasks[previous_task] < count:
|
||||||
raise IllegalVillagerMoveException
|
raise IllegalVillagerMoveException
|
||||||
|
|
||||||
non_assignable_tasks = [
|
self._check_single_villager_move(previous_task, new_task)
|
||||||
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
|
|
||||||
|
|
||||||
if new_task:
|
if new_task:
|
||||||
self.gather.check_gather(self, new_task, count)
|
self.gather.check_gather(self, new_task, count)
|
||||||
@@ -208,26 +194,61 @@ class World():
|
|||||||
|
|
||||||
self.villager_tasks[previous_task] -= count
|
self.villager_tasks[previous_task] -= count
|
||||||
|
|
||||||
if previous_task == Tasks.FARM:
|
if previous_task in [Tasks.FARM, Tasks.FISH_SHIP_TRAP]:
|
||||||
self.gather.stop_using_farms(count)
|
self.gather.stop_using_consumable_buildings(previous_task, count)
|
||||||
|
|
||||||
if new_task == Tasks.FARM:
|
if new_task in [Tasks.FARM, Tasks.FISH_SHIP_TRAP]:
|
||||||
self.gather.start_using_farms(count)
|
self.gather.start_using_consumable_buildings(new_task, count)
|
||||||
|
|
||||||
self._schedule_next_gather_rate_decrease(previous_task)
|
self._schedule_next_gather_rate_decrease(previous_task)
|
||||||
if new_task:
|
if new_task:
|
||||||
self._schedule_next_gather_rate_decrease(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():
|
for task, count in villagers_from_count.items():
|
||||||
if self.villager_tasks[task] < count:
|
if self.villager_tasks[task] < count:
|
||||||
raise IllegalVillagerMoveException
|
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):
|
def _move_villagers_to_build(self, villagers_from_count):
|
||||||
for task, count in villagers_from_count.items():
|
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):
|
def get_relic(self, walking_time=60):
|
||||||
@@ -267,7 +288,11 @@ class World():
|
|||||||
|
|
||||||
villagers_from_count = Counter(villagers_from)
|
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)
|
self.dependencies.check_dependencies(self, building)
|
||||||
|
|
||||||
@@ -293,26 +318,33 @@ class World():
|
|||||||
if building == Buildings.HOUSE:
|
if building == Buildings.HOUSE:
|
||||||
self._free_housing()
|
self._free_housing()
|
||||||
|
|
||||||
if building == Buildings.FARM:
|
if building in [Buildings.FARM, Buildings.FISHTRAP]:
|
||||||
self._add_farm()
|
self.gather.add_consumable_building(building)
|
||||||
else:
|
else:
|
||||||
self._improve_gather_rate_by_building(building, tasks_improved)
|
self._improve_gather_rate_by_building(building, tasks_improved)
|
||||||
|
|
||||||
for task, count in villagers_to.items():
|
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):
|
def _remove_consumable_building(self, task):
|
||||||
self.buildings.append(Buildings.FARM)
|
match task:
|
||||||
self.gather.add_farm()
|
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):
|
num_working_buildings = self.gather.get_num_working_consumable_buildings(task)
|
||||||
self.buildings.remove(Buildings.FARM)
|
if self.villager_tasks[task] > num_working_buildings:
|
||||||
self.gather.remove_farm()
|
self.assign_villager(task, next_task)
|
||||||
|
|
||||||
if self.villager_tasks[Tasks.FARM] > gather.get_num_working_farms():
|
|
||||||
self.assign_villager(Tasks.FARM, Tasks.IDLE)
|
|
||||||
|
|
||||||
|
|
||||||
def advance_by_time(self, duration):
|
def advance_by_time(self, duration):
|
||||||
|
|||||||
230
tests/test.py
230
tests/test.py
@@ -455,3 +455,233 @@ class TestWorld(unittest.TestCase):
|
|||||||
with self.assertRaises(InvalidMarketAmountException):
|
with self.assertRaises(InvalidMarketAmountException):
|
||||||
game.market_sell(0, Resources.FOOD, 50)
|
game.market_sell(0, Resources.FOOD, 50)
|
||||||
game.play_until(1)
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user