Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a configuration option "path_startmode" (conflict merge #2489) #3270

Merged
merged 5 commits into from
Aug 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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