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.
36 lines
845 B
Python
36 lines
845 B
Python
from collections import defaultdict
|
|
|
|
from aoe.types import *
|
|
from aoe.exceptions import *
|
|
|
|
|
|
|
|
class Housing():
|
|
|
|
|
|
def check_housing(self, world, thing):
|
|
required = self.required[thing]
|
|
|
|
if required > 0:
|
|
pop_space = world.get_population_space()
|
|
if world.get_effective_population() + required > pop_space:
|
|
raise YallGotHousedException
|
|
|
|
|
|
def check_housing_safe(self, world, thing):
|
|
try:
|
|
self.check_housing(world, thing)
|
|
except YallGotHousedException:
|
|
return False
|
|
else:
|
|
return True
|
|
|
|
|
|
def __init__(self):
|
|
self.space = defaultdict(int, {
|
|
Buildings.HOUSE: 5,
|
|
Buildings.TOWNCENTER: 5,
|
|
})
|
|
|
|
self.required = defaultdict(int, {u: 1 for u in Units})
|