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" #2489

Closed
wants to merge 1 commit into from
Closed
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 @@ -51,3 +51,4 @@
* matheussampaio
* Abraxas000
* lucasfevi
* JaapMoolenaar
1 change: 1 addition & 0 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"type": "FollowPath",
"config": {
"path_mode": "loop",
"path_startmode": "first",
"path_file": "configs/path.example.json"
}
}
Expand Down
40 changes: 39 additions & 1 deletion pokemongo_bot/cell_workers/follow_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@

class FollowPath(BaseTask):
def initialize(self):
self.ptr = 0
self._process_config()
self.points = self.load_path()

if self.path_startmode == '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_startmode = self.config.get("path_startmode", "first")

def load_path(self):
if self.path_file is None:
Expand Down Expand Up @@ -60,6 +66,36 @@ def load_gpx(self):

return points

def find_closest_point_idx(self, points):
logger.log("Finding closest point in path")

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'])

if self.bot.config.debug:
logger.log("Checking if point {}, {} is closest to {}, {}".format(lat, lng, botlat, botlng))

dist = distance(
botlat,
botlng,
lat,
lng
)

if dist < min_distance:
min_distance = dist
return_idx = index

logger.log("Chose closest point in path #{}: {}, {}".format(return_idx+1, points[return_idx]['lat'], points[return_idx]['lng']))

return return_idx

def work(self):
point = self.points[self.ptr]
lat = float(point['lat'])
Expand Down Expand Up @@ -95,4 +131,6 @@ def work(self):
else:
self.ptr += 1

logger.log("Moving to next point in path #{}".format(self.ptr+1))

return [lat, lng]