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 return True def check_housing_safe(self, world, thing): try: return self.check_housing(world, thing) except YallGotHousedException: return False def __init__(self): self.space = defaultdict(int, { Buildings.HOUSE: 5, Buildings.TOWNCENTER: 5, }) self.required = defaultdict(int, {u: 1 for u in Units})