Allow user to choose whether getting housed is an error
Previously, the simulation would automatically end whenever it determined you were housed. That is still the default, but the user can now choose to have the simulation continue instead. Also, this likely fixes a bug whereby an error could have been thrown for an unavailable production building when searching the production queue.
This commit is contained in:
34
aoe/world.py
34
aoe/world.py
@@ -248,6 +248,14 @@ class World():
|
||||
self.assign_villager(task, build_task, count)
|
||||
|
||||
|
||||
def _get_house_check_function(self):
|
||||
if self.housed_is_error:
|
||||
house_check = self.housing.check_housing
|
||||
else:
|
||||
house_check = self.housing.check_housing_safe
|
||||
return house_check
|
||||
|
||||
|
||||
def _get_build_task_from_task(self, task):
|
||||
if task in Gather.FISHING_TASKS:
|
||||
return Tasks.FISH_SHIP_BUILD
|
||||
@@ -382,6 +390,10 @@ class World():
|
||||
self._handle_events()
|
||||
|
||||
|
||||
def set_housed_is_error(self, is_error=True):
|
||||
self.housed_is_error = is_error
|
||||
|
||||
|
||||
def get_population_space(self):
|
||||
space = sum([self.housing.space[building] for building in self.buildings])
|
||||
return min(space, World.POPULATION_CAP)
|
||||
@@ -394,13 +406,15 @@ class World():
|
||||
def _free_housing(self):
|
||||
pop_space = self.get_population_space()
|
||||
|
||||
house_check = self._get_house_check_function()
|
||||
|
||||
i = 0
|
||||
while (self.get_effective_population() < pop_space and
|
||||
i < len(self.production_queue)):
|
||||
|
||||
thing, task = self.production_queue[i]
|
||||
if self.housing.check_housing(self, thing) and \
|
||||
self.production.check_production(self, thing):
|
||||
if house_check(self, thing) and \
|
||||
self.production.check_production_safe(self, thing):
|
||||
self._start_producing(thing, task)
|
||||
del self.production_queue[i]
|
||||
else:
|
||||
@@ -421,11 +435,13 @@ class World():
|
||||
# production queue as a shared pool, and I don't really care.
|
||||
self.production_available[building] += 1
|
||||
|
||||
house_check = self._get_house_check_function()
|
||||
|
||||
i = 0
|
||||
while i < len(self.production_queue):
|
||||
thing, task = self.production_queue[i]
|
||||
if self.production.building[thing] == building and \
|
||||
self.housing.check_housing(self, thing):
|
||||
house_check(self, thing):
|
||||
self._start_producing(thing, task)
|
||||
del self.production_queue[i]
|
||||
break
|
||||
@@ -487,8 +503,14 @@ class World():
|
||||
def _start_producing(self, thing, initial_task):
|
||||
try:
|
||||
self._use_housing_and_production(thing)
|
||||
except ProductionBuildingNotAvailableException:
|
||||
self.production_queue.append((thing, initial_task))
|
||||
except Exception as e:
|
||||
is_prod = isinstance(e, ProductionBuildingNotAvailableException)
|
||||
is_housing = isinstance(e, YallGotHousedException)
|
||||
|
||||
if is_prod or (is_housing and not self.housed_is_error):
|
||||
self.production_queue.append((thing, initial_task))
|
||||
else:
|
||||
raise(e)
|
||||
else:
|
||||
update_time = self.current_time + self.build_times.build_times[thing]
|
||||
self.events[update_time].append((self._add_thing, (thing, initial_task,)))
|
||||
@@ -594,4 +616,6 @@ class World():
|
||||
self.production = Production()
|
||||
self.gather = Gather()
|
||||
|
||||
self.housed_is_error = True
|
||||
|
||||
self._deal_with_civ()
|
||||
|
||||
Reference in New Issue
Block a user