def calc_path(self, destination, destination_in_building=False, check_only=False, source=None): """Calculates a path to destination @param destination: a destination supported by pathfinding @param destination_in_building: bool, whether destination is in a building. this makes the unit "enter the building" @param check_only: if True the path isn't saved @param source: use this as source of movement instead of self.unit.position @return: True iff movement is possible or the path if check_only==True""" # calculate our source if source is None: source = self._get_position() # call algorithm # to use a different pathfinding code, just change the following line path = FindPath()(source, destination, self._get_path_nodes(), self._get_blocked_coords(), self.move_diagonal, self.make_target_walkable) if path is None: return False if not check_only: # prepare movement self.move_on_path(path, source, destination_in_building) else: return path return True
def get_path_on_roads(cls, island, source, destination): """Returns a path that runs only on roads. @param island: island to search path on @param source, destination: Point or anything supported by FindPath @return: list of tuples or None in case no path is found""" return FindPath()(source, destination, island.path_nodes.road_nodes)