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

Loiter new meaning #5697

Merged
merged 2 commits into from
Nov 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
16 changes: 15 additions & 1 deletion docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -880,14 +880,28 @@ This task is an upgrade version of the MoveToMapPokemon task. It will fetch poke
### Description
[[back to top](#table-of-contents)]

Walk to the specified locations loaded from .gpx or .json file. It is highly recommended to use website such as [GPSies](http://www.gpsies.com) which allow you to export your created track in JSON file. Note that you'll have to first convert its JSON file into the format that the bot can understand. See [Example of pier39.json] below for the content. I had created a simple python script to do the conversion.
Walk to the specified locations loaded from .gpx or .json file. It is highly
recommended to use website such as [GPSies](http://www.gpsies.com) which allow
you to export your created track in JSON file. Note that you'll have to first
convert its JSON file into the format that the bot can understand. See [Example
of pier39.json] below for the content. I had created a simple python script to
do the conversion.

The `location` fields in the `.json` file can also contain a street address. In
this case the `location` is interpreted by the Google Maps API.

The json file can contain for each point an optional `wander` field. This
indicated the number of seconds the bot should wander after reaching the point.
During this time, the next Task in the configuration file is executed, e.g. a
MoveToFort task. This allows the bot to walk around the waypoint looking for
forts for a limited time.

The `loiter` field, also optional for each point in the json file, works
similarly to the `wander` field. The difference is that with `loiter` the
next `Task` in the configuration file is /not/ executed, meaning the bot
will wait, without moving, at the point in the json file with the `loiter`
option.

### Options
[[back to top](#table-of-contents)]
* `path_mode` - linear, loop, single
Expand Down
27 changes: 17 additions & 10 deletions pokemongo_bot/cell_workers/follow_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
from datetime import datetime as dt, timedelta

STATUS_MOVING = 0
STATUS_WANDERING = 1
STATUS_FINISHED = 2
STATUS_LOITERING = 1
STATUS_WANDERING = 2
STATUS_FINISHED = 3

class FollowPath(BaseTask):
SUPPORTED_TASK_API_VERSION = 1
Expand All @@ -28,7 +29,7 @@ def initialize(self):
self._process_config()
self.points = self.load_path()
self.status = STATUS_MOVING
self.wander_end_time = 0
self.waiting_end_time = 0
self.distance_unit = self.bot.config.distance_unit
self.append_unit = False

Expand Down Expand Up @@ -143,8 +144,11 @@ def work(self):
if self.status == STATUS_FINISHED:
return WorkerResult.SUCCESS

if self.status == STATUS_WANDERING and time.time() < self.wander_end_time:
return WorkerResult.SUCCESS
if time.time() < self.waiting_end_time:
if self.status == STATUS_WANDERING:
return WorkerResult.SUCCESS
elif self.status == STATUS_LOITERING:
return WorkerResult.RUNNING

last_lat, last_lng, last_alt = self.bot.position

Expand Down Expand Up @@ -184,19 +188,22 @@ def work(self):
formatted="Walking from {last_position} to {current_position}, distance left: ({distance} {distance_unit}) ..",
data={
'last_position': (last_lat, last_lng, last_alt),
'current_position': (lat, lng, alt),
'current_position': point["location"],
'distance': format_dist(dist,self.distance_unit,self.append_unit),
'distance_unit': self.distance_unit
}
)

if (self.bot.config.walk_min > 0 and is_at_destination) or (self.status == STATUS_WANDERING and time.time() >= self.wander_end_time):
if "loiter" in point:
self.logger.warning("'loiter' is obsolete, please change to 'wander' in {}".format(self.path_file))
if (self.bot.config.walk_min > 0 and is_at_destination) or (self.status in [STATUS_WANDERING, STATUS_LOITERING] and time.time() >= self.waiting_end_time):
if "loiter" in point and self.status != STATUS_LOITERING:
self.logger.info("Loitering for {} seconds...".format(point["loiter"]))
self.status = STATUS_LOITERING
self.waiting_end_time = time.time() + point["loiter"]
return WorkerResult.RUNNING
if "wander" in point and self.status != STATUS_WANDERING:
self.logger.info("Wandering for {} seconds...".format(point["wander"]))
self.status = STATUS_WANDERING
self.wander_end_time = time.time() + point["wander"]
self.waiting_end_time = time.time() + point["wander"]
return WorkerResult.SUCCESS
if (self.ptr + 1) == len(self.points):
if self.path_mode == 'single':
Expand Down