Modify farm and fishtrap code slightly
This commit is contained in:
@@ -155,6 +155,16 @@ class Gather():
|
||||
Tasks.FISH_SHIP_TRAP,
|
||||
]
|
||||
|
||||
FARM_LIKE_TASKS = [
|
||||
Tasks.FARM,
|
||||
Tasks.FISH_SHIP_TRAP,
|
||||
]
|
||||
|
||||
FARM_LIKE_BUILDINGS = [
|
||||
Buildings.FARM,
|
||||
Buildings.FISHTRAP,
|
||||
]
|
||||
|
||||
|
||||
def check_gather(self, world, task, count=1):
|
||||
if task in [
|
||||
@@ -175,7 +185,7 @@ class Gather():
|
||||
if not match:
|
||||
raise GatherBuildingNotAvailableException
|
||||
|
||||
if task in [Tasks.FARM, Tasks.FISH_SHIP_TRAP]:
|
||||
if task in Gather.FARM_LIKE_TASKS:
|
||||
self._check_consumable_gather_building_available(world,
|
||||
task,
|
||||
count)
|
||||
@@ -212,8 +222,8 @@ class Gather():
|
||||
rate = self.gather_rates[task]
|
||||
decay = self.decay_rates[task]
|
||||
|
||||
if task in [Tasks.FARM, Tasks.FISH_SHIP_TRAP]:
|
||||
_, __, used, ___ = self._get_consumable_info(task)
|
||||
if task in Gather.FARM_LIKE_TASKS:
|
||||
used = self.consumable_buildings[task]['used']
|
||||
try:
|
||||
available = used[0]
|
||||
except IndexError:
|
||||
@@ -234,7 +244,7 @@ class Gather():
|
||||
|
||||
|
||||
def improve_gather_rate_by_building(self, building, tasks):
|
||||
if building in [Buildings.FARM, Buildings.FISHTRAP]:
|
||||
if building in Gather.FARM_LIKE_TASKS:
|
||||
raise ValueError('Do not call this routine with a farm')
|
||||
|
||||
if building not in self.buildings_gather_increase.keys():
|
||||
@@ -257,7 +267,8 @@ class Gather():
|
||||
|
||||
|
||||
def permanently_modify_consumable_capacity(self, building, increase):
|
||||
_, __, used, unused = self._get_consumable_info(building)
|
||||
task = self._get_task_from_consumable_building(building)
|
||||
used, unused = self.consumable_buildings[task].values()
|
||||
|
||||
current_initial_capacity = self.buildings_gather_increase[building]
|
||||
self.buildings_gather_increase[building] += increase
|
||||
@@ -270,7 +281,7 @@ class Gather():
|
||||
|
||||
|
||||
def stop_using_consumable_buildings(self, task, count):
|
||||
_, __, used, unused = self._get_consumable_info(task)
|
||||
used, unused = self.consumable_buildings[task].values()
|
||||
|
||||
# remove villagers from farms with lowest remaining capacity
|
||||
try:
|
||||
@@ -283,71 +294,46 @@ class Gather():
|
||||
|
||||
|
||||
def start_using_consumable_buildings(self, task, count):
|
||||
_, __, used, unused = self._get_consumable_info(task)
|
||||
used, unused = self.consumable_buildings[task].values()
|
||||
|
||||
# add villagers to farms with highest remaining capacity
|
||||
for i in range(count):
|
||||
heapq.heappush(used, heapq.heappop_max(unused))
|
||||
|
||||
|
||||
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 _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_consumable_info_from_building(self, building):
|
||||
def _get_task_from_consumable_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
|
||||
return task
|
||||
|
||||
|
||||
def add_consumable_building(self, building):
|
||||
task, _, __, unused = self._get_consumable_info(building)
|
||||
task = self._get_task_from_consumable_building(building)
|
||||
unused = self.consumable_buildings[task]['unused']
|
||||
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)
|
||||
task = self._get_task_from_consumable_building(building)
|
||||
used = self.consumable_buildings[task]['used']
|
||||
heapq.heappop(used)
|
||||
|
||||
|
||||
def _check_consumable_gather_building_available(self, world, task, count):
|
||||
_, __, ___, unused = self._get_consumable_info(task)
|
||||
unused = self.consumable_buildings[task]['unused']
|
||||
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)
|
||||
working = len(self.consumable_buildings[task]['used'])
|
||||
return working
|
||||
|
||||
|
||||
@@ -371,8 +357,8 @@ class Gather():
|
||||
|
||||
rate = self.gather_rates[task]
|
||||
|
||||
if task in [Tasks.FARM, Tasks.FISH_SHIP_TRAP]:
|
||||
_, __, used, unused = self._get_consumable_info(task)
|
||||
if task in Gather.FARM_LIKE_TASKS:
|
||||
used, unused = self.consumable_buildings[task].values()
|
||||
for i in range(len(used)):
|
||||
used[i] -= rate*duration
|
||||
else:
|
||||
@@ -391,10 +377,8 @@ class Gather():
|
||||
def __init__(self):
|
||||
self.resources = [200, 200, 100, 200]
|
||||
|
||||
self.farms = []
|
||||
self.unused_farms = []
|
||||
self.fishtraps = []
|
||||
self.unused_fishtraps = []
|
||||
self.consumable_buildings = {t: {'used': [], 'unused': []}
|
||||
for t in Gather.FARM_LIKE_TASKS}
|
||||
|
||||
self.gather_rates = {
|
||||
Tasks.BERRIES: 18.6/60,
|
||||
|
||||
Reference in New Issue
Block a user