Skip to content

Commit

Permalink
Configurable altitude range (#4250)
Browse files Browse the repository at this point in the history
* Added alt_min/alt_max

* Changed default values

* Added alt

* Cleaned up speed calc

* Added altitude randomness

* Added altitude randomness

* Added altitude randomness

* Fixed import

* Added altitude randomness

* Added altitude randomness

* Fixed import

* Added alt_min/alt_max

* Added alt_min/alt_max

* Added alt_min/alt_max

* Switch to walk_min, walk_max

* Added alt_min/alt_max

* Added alt_min/alt_max
  • Loading branch information
mjmadsen authored and solderzzc committed Aug 19, 2016
1 parent 198510b commit 324b752
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 10 deletions.
2 changes: 2 additions & 0 deletions configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@
},
"walk_max": 4.16,
"walk_min": 2.16,
"alt_min": 0.75,
"alt_max": 2.5,
"debug": false,
"test": false,
"health_record": true,
Expand Down
2 changes: 2 additions & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@
},
"walk_max": 4.16,
"walk_min": 2.16,
"alt_min": 0.75,
"alt_max": 2.5,
"debug": false,
"test": false,
"health_record": true,
Expand Down
2 changes: 2 additions & 0 deletions configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@
},
"walk_max": 4.16,
"walk_min": 2.16,
"alt_min": 0.75,
"alt_max": 2.5,
"debug": false,
"test": false,
"health_record": true,
Expand Down
2 changes: 2 additions & 0 deletions configs/config.json.optimizer.example
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@
},
"walk_max": 4.16,
"walk_min": 2.16,
"alt_min": 0.75,
"alt_max": 2.5,
"debug": false,
"test": false,
"health_record": true,
Expand Down
2 changes: 2 additions & 0 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
},
"walk_max": 4.16,
"walk_min": 2.16,
"alt_min": 0.75,
"alt_max": 2.5,
"debug": false,
"test": false,
"health_record": true,
Expand Down
2 changes: 2 additions & 0 deletions configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@
},
"walk_max": 4.16,
"walk_min": 2.16,
"alt_min": 0.75,
"alt_max": 2.5,
"debug": false,
"test": false,
"health_record": true,
Expand Down
16 changes: 16 additions & 0 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,22 @@ def _json_loader(filename):
type=bool,
default=[]
)
add_config(
parser,
load,
long_flag="--alt_min",
help="Minimum random altitude",
type=float,
default=0.75
)
add_config(
parser,
load,
long_flag="--alt_max",
help="Maximum random altitude",
type=float,
default=2.5
)
# Start to parse other attrs
config = parser.parse_args()
if not config.username and 'username' not in load:
Expand Down
4 changes: 3 additions & 1 deletion pokemongo_bot/cell_workers/follow_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pokemongo_bot.cell_workers.utils import distance
from pokemongo_bot.cell_workers.utils import find_biggest_cluster
from pokemongo_bot.base_task import BaseTask
from random import uniform

class FollowCluster(BaseTask):
SUPPORTED_TASK_API_VERSION = 1
Expand Down Expand Up @@ -66,7 +67,8 @@ def work(self):
if step_walker.step():
self.is_at_destination = True
else:
self.bot.api.set_position(lat, lng)
alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max)
self.bot.api.set_position(lat, lng, alt)

elif not self.announced:
self.emit_event(
Expand Down
4 changes: 3 additions & 1 deletion pokemongo_bot/cell_workers/follow_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot.walkers.step_walker import StepWalker
from pgoapi.utilities import f2i
from random import uniform


class FollowPath(BaseTask):
Expand Down Expand Up @@ -117,7 +118,8 @@ def work(self):
is_at_destination = True

else:
self.bot.api.set_position(lat, lng, 0)
alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max)
self.bot.api.set_position(lat, lng, alt)

dist = distance(
last_lat,
Expand Down
4 changes: 3 additions & 1 deletion pokemongo_bot/cell_workers/follow_spiral.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pokemongo_bot.cell_workers.utils import distance, format_dist
from pokemongo_bot.walkers.step_walker import StepWalker
from pokemongo_bot.base_task import BaseTask
from random import uniform

class FollowSpiral(BaseTask):
SUPPORTED_TASK_API_VERSION = 1
Expand Down Expand Up @@ -101,7 +102,8 @@ def work(self):
if step_walker.step():
step_walker = None
else:
self.bot.api.set_position(point['lat'], point['lng'], 0)
alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max)
self.bot.api.set_position(point['lat'], point['lng'], alt)

self.emit_event(
'position_update',
Expand Down
6 changes: 4 additions & 2 deletions pokemongo_bot/cell_workers/move_to_map_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
from pokemongo_bot.worker_result import WorkerResult
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.cell_workers.pokemon_catch_worker import PokemonCatchWorker
from random import uniform


# Update the map if more than N meters away from the center. (AND'd with
Expand Down Expand Up @@ -99,6 +100,7 @@ def initialize(self):
self.caught = json.load(
open(data_file)
)
self.alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max)

def get_pokemon_from_map(self):
try:
Expand Down Expand Up @@ -226,7 +228,7 @@ def snipe(self, pokemon):
api_encounter_response = catch_worker.create_encounter_api_call()
time.sleep(SNIPE_SLEEP_SEC)
self._teleport_back(last_position)
self.bot.api.set_position(last_position[0], last_position[1], 0)
self.bot.api.set_position(last_position[0], last_position[1], alt)
time.sleep(SNIPE_SLEEP_SEC)
self.bot.heartbeat()
catch_worker.work(api_encounter_response)
Expand Down Expand Up @@ -334,7 +336,7 @@ def _teleport_to(self, pokemon):
formatted='Teleporting to {poke_name}. ({poke_dist})',
data=self._pokemon_event_data(pokemon)
)
self.bot.api.set_position(pokemon['latitude'], pokemon['longitude'], 0)
self.bot.api.set_position(pokemon['latitude'], pokemon['longitude'], alt)
self._encountered(pokemon)

def _encountered(self, pokemon):
Expand Down
3 changes: 2 additions & 1 deletion pokemongo_bot/walkers/polyline_walker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from random import uniform
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot.walkers.step_walker import StepWalker
from polyline_generator import PolylineObjectHandler
Expand Down Expand Up @@ -33,7 +34,7 @@ def step(self):
sleep(1)
self.polyline_walker.pause()
cLat, cLng = self.polyline_walker.get_pos()[0]
_, _, alt = self.api.get_position()
alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max)
self.api.set_position(cLat, cLng, alt)
self.bot.heartbeat()
return False
Expand Down
9 changes: 5 additions & 4 deletions pokemongo_bot/walkers/step_walker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from math import sqrt

from random import random
from random import random, uniform
from pokemongo_bot.cell_workers.utils import distance
from pokemongo_bot.human_behaviour import random_lat_long_delta, sleep

Expand All @@ -20,7 +20,8 @@ def __init__(self, bot, dest_lat, dest_lng):
dest_lng
)

self.speed = self.bot.config.walk_max - random() * (self.bot.config.walk_max - self.bot.config.walk_min)
self.alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max)
self.speed = uniform(self.bot.config.walk_min, self.bot.config.walk_max)

self.destLat = dest_lat
self.destLng = dest_lng
Expand All @@ -42,7 +43,7 @@ def __init__(self, bot, dest_lat, dest_lng):

def step(self):
if (self.dLat == 0 and self.dLng == 0) or self.dist < self.speed:
self.api.set_position(self.destLat + random_lat_long_delta(), self.destLng + random_lat_long_delta(), 0)
self.api.set_position(self.destLat + random_lat_long_delta(), self.destLng + random_lat_long_delta(), self.alt)
self.bot.event_manager.emit(
'position_update',
sender=self,
Expand All @@ -69,7 +70,7 @@ def step(self):
cLat = self.initLat + scaledDLat + random_lat_long_delta()
cLng = self.initLng + scaledDLng + random_lat_long_delta()

self.api.set_position(cLat, cLng, 0)
self.api.set_position(cLat, cLng, self.alt)
self.bot.event_manager.emit(
'position_update',
sender=self,
Expand Down

0 comments on commit 324b752

Please sign in to comment.