diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 6e0e44f5fd..57b289ab90 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -58,3 +58,4 @@ * bigkraig * nikhil-pandey * thebigjc + * JaapMoolenaar diff --git a/configs/config.json.path.example b/configs/config.json.path.example index dec7457246..6f7b04c305 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -60,6 +60,7 @@ "type": "FollowPath", "config": { "path_mode": "loop", + "path_start_mode": "first", "path_file": "configs/path.example.json" } } diff --git a/pokemongo_bot/cell_workers/follow_path.py b/pokemongo_bot/cell_workers/follow_path.py index 6e183ed1d7..1532695bd8 100644 --- a/pokemongo_bot/cell_workers/follow_path.py +++ b/pokemongo_bot/cell_workers/follow_path.py @@ -14,13 +14,19 @@ class FollowPath(BaseTask): SUPPORTED_TASK_API_VERSION = 1 def initialize(self): - self.ptr = 0 self._process_config() self.points = self.load_path() + if self.path_start_mode == 'closest': + self.ptr = self.find_closest_point_idx(self.points) + + else: + self.ptr = 0 + def _process_config(self): self.path_file = self.config.get("path_file", None) self.path_mode = self.config.get("path_mode", "linear") + self.path_start_mode = self.config.get("path_start_mode", "first") def load_path(self): if self.path_file is None: @@ -67,6 +73,30 @@ def load_gpx(self): return points + def find_closest_point_idx(self, points): + + return_idx = 0 + min_distance = float("inf"); + for index in range(len(points)): + point = points[index] + botlat = self.bot.api._position_lat + botlng = self.bot.api._position_lng + lat = float(point['lat']) + lng = float(point['lng']) + + dist = distance( + botlat, + botlng, + lat, + lng + ) + + if dist < min_distance: + min_distance = dist + return_idx = index + + return return_idx + def work(self): point = self.points[self.ptr] lat = float(point['lat'])