Skip to content

Commit

Permalink
Fixes in PolylineWalker (#5135)
Browse files Browse the repository at this point in the history
* Fix altitude 0 in PolylineWalker

* use the speed as randomized in PolylineWalker

* Polyline Walker should return False if final destination not reached

* Fixed cache validation...
  • Loading branch information
th3w4y authored and mjmadsen committed Sep 3, 2016
1 parent 83c1546 commit e7a94ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pokemongo_bot/walkers/polyline_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def cached_polyline(origin, destination, speed, google_map_api_key=None):
abs_offset = haversine.haversine(tuple(origin), PolylineObjectHandler._cache.get_last_pos())*1000
else:
abs_offset = float("inf")
is_old_cache = lambda : abs_offset < 8 # Consider cache old if we identified an offset more then 8 m
is_old_cache = lambda : abs_offset > 8 # Consider cache old if we identified an offset more then 8 m
new_dest_set = lambda : tuple(destination) != PolylineObjectHandler._cache.destination

if PolylineObjectHandler._run and (not is_old_cache()):
Expand Down
15 changes: 12 additions & 3 deletions pokemongo_bot/walkers/polyline_walker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from random import uniform

from pokemongo_bot.cell_workers.utils import distance
from pokemongo_bot.walkers.step_walker import StepWalker
from polyline_generator import PolylineObjectHandler

Expand All @@ -8,13 +9,21 @@ class PolylineWalker(StepWalker):

def __init__(self, bot, dest_lat, dest_lng):
self.bot = bot
self.speed = self.bot.config.walk_min
self.speed = uniform(self.bot.config.walk_min, self.bot.config.walk_max)
self.dest_lat, self.dest_lng = dest_lat, dest_lng
self.actual_pos = tuple(self.bot.position[:2])
self.actual_alt = self.bot.position[-1]
self.polyline = PolylineObjectHandler.cached_polyline(self.actual_pos,
(self.dest_lat, self.dest_lng),
self.speed, google_map_api_key=self.bot.config.gmapkey)
self.pol_lat, self.pol_lon = self.polyline.get_pos()
self.pol_alt = self.polyline.get_alt() or uniform(self.bot.config.alt_min, self.bot.config.alt_max)
self.pol_alt = self.polyline.get_alt() or self.actual_alt
super(PolylineWalker, self).__init__(self.bot, self.pol_lat, self.pol_lon,
self.pol_alt, fixed_speed=True)
self.pol_alt, fixed_speed=self.speed)

def step(self):
step = super(PolylineWalker, self).step()
if not (distance(self.pol_lat, self.pol_lon, self.dest_lat, self.dest_lng) > 10 and step):
return False
else:
return True
6 changes: 3 additions & 3 deletions pokemongo_bot/walkers/step_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class StepWalker(object):

def __init__(self, bot, dest_lat, dest_lng, dest_alt=None, fixed_speed=False):
def __init__(self, bot, dest_lat, dest_lng, dest_alt=None, fixed_speed=None):
self.bot = bot
self.api = bot.api

Expand All @@ -25,9 +25,9 @@ def __init__(self, bot, dest_lat, dest_lng, dest_alt=None, fixed_speed=False):
else:
self.alt = dest_alt

if fixed_speed:
if fixed_speed != None:
# PolylineWalker uses a fixed speed!
self.speed = self.bot.config.walk_min
self.speed = fixed_speed
else:
self.speed = uniform(self.bot.config.walk_min, self.bot.config.walk_max)

Expand Down

0 comments on commit e7a94ab

Please sign in to comment.