def matches(self, order_set): ''' Whether the order is matched by the convoying unit(s). ''' def matching(fleet): counterpart = order_set.get_order(fleet) if counterpart: return (counterpart.is_convoying() and counterpart.supported == self.unit and counterpart.destination.matches(self.destination.key)) return False if self.path: return all(matching(unit) for unit in self.path) else: return True
def get_routes(self, convoyers, ignore_foreign): if self.unit.can_be_convoyed(): if self.path: path_list = [[fleet.location.province for fleet in self.path]] else: path_list = self.routes if path_list: key = self.unit.key def available(prov): return convoyers.get(prov.key, (None, None))[0] == key all_routes = [path for path in path_list if all(available(place) for place in path)] if ignore_foreign: # DPTG craziness: ignore foreign convoyers if we can go alone. nation = self.unit.nation def countryman(prov): return convoyers.get(prov.key, (None, None))[1] == nation solo_routes = [path for path in all_routes if all(countryman(place) for place in path)] else: solo_routes = None return (solo_routes or all_routes) return []
def check(f): return not all(f(unit) for unit in self.path) if check(real_prov): note = NSP
def is_valid(self): if self.homes and not self.key.is_supply(): return False if not self.locations: return False return all(location.is_valid() for location in self.locations)