Skip to content

Commit

Permalink
Added a configuration option "path_startmode" (conflict merge #2489) (#…
Browse files Browse the repository at this point in the history
…3270)

* Upstream update and merge, with path_startmode configuration

* Removed logger and fixed base task path

* As per request, path_startmode is now path_start_mode

* Removed all logging
  • Loading branch information
JaapMoolenaar authored and solderzzc committed Aug 9, 2016
1 parent e03f834 commit c8aaf4b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@
* bigkraig
* nikhil-pandey
* thebigjc
* JaapMoolenaar
1 change: 1 addition & 0 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"type": "FollowPath",
"config": {
"path_mode": "loop",
"path_start_mode": "first",
"path_file": "configs/path.example.json"
}
}
Expand Down
32 changes: 31 additions & 1 deletion pokemongo_bot/cell_workers/follow_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'])
Expand Down

0 comments on commit c8aaf4b

Please sign in to comment.