From 324b752f031cdb39d52c396ea50e14a59841535e Mon Sep 17 00:00:00 2001 From: Matt J Madsen Date: Fri, 19 Aug 2016 01:35:49 -0500 Subject: [PATCH] Configurable altitude range (#4250) * 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 --- configs/config.json.cluster.example | 2 ++ configs/config.json.example | 2 ++ configs/config.json.map.example | 2 ++ configs/config.json.optimizer.example | 2 ++ configs/config.json.path.example | 2 ++ configs/config.json.pokemon.example | 2 ++ pokecli.py | 16 ++++++++++++++++ pokemongo_bot/cell_workers/follow_cluster.py | 4 +++- pokemongo_bot/cell_workers/follow_path.py | 4 +++- pokemongo_bot/cell_workers/follow_spiral.py | 4 +++- .../cell_workers/move_to_map_pokemon.py | 6 ++++-- pokemongo_bot/walkers/polyline_walker.py | 3 ++- pokemongo_bot/walkers/step_walker.py | 9 +++++---- 13 files changed, 48 insertions(+), 10 deletions(-) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 51d77338e9..4afae5e528 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -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, diff --git a/configs/config.json.example b/configs/config.json.example index d9e31b7394..77d6405380 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -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, diff --git a/configs/config.json.map.example b/configs/config.json.map.example index dad7221fa6..e589e4b9b6 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -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, diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index f4c249a553..e4b9708621 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -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, diff --git a/configs/config.json.path.example b/configs/config.json.path.example index d4ff29c380..f10dc67d4c 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -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, diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 23c330b3fa..55a66730cb 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -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, diff --git a/pokecli.py b/pokecli.py index 85f5c4a1c4..2e5647c437 100644 --- a/pokecli.py +++ b/pokecli.py @@ -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: diff --git a/pokemongo_bot/cell_workers/follow_cluster.py b/pokemongo_bot/cell_workers/follow_cluster.py index d080667784..274da202b5 100644 --- a/pokemongo_bot/cell_workers/follow_cluster.py +++ b/pokemongo_bot/cell_workers/follow_cluster.py @@ -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 @@ -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( diff --git a/pokemongo_bot/cell_workers/follow_path.py b/pokemongo_bot/cell_workers/follow_path.py index 0d3fe30b7b..e5dccdedb5 100644 --- a/pokemongo_bot/cell_workers/follow_path.py +++ b/pokemongo_bot/cell_workers/follow_path.py @@ -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): @@ -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, diff --git a/pokemongo_bot/cell_workers/follow_spiral.py b/pokemongo_bot/cell_workers/follow_spiral.py index 8c9ef87a93..4acd16038f 100644 --- a/pokemongo_bot/cell_workers/follow_spiral.py +++ b/pokemongo_bot/cell_workers/follow_spiral.py @@ -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 @@ -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', diff --git a/pokemongo_bot/cell_workers/move_to_map_pokemon.py b/pokemongo_bot/cell_workers/move_to_map_pokemon.py index 3de6d987bb..936fe1f72f 100644 --- a/pokemongo_bot/cell_workers/move_to_map_pokemon.py +++ b/pokemongo_bot/cell_workers/move_to_map_pokemon.py @@ -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 @@ -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: @@ -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) @@ -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): diff --git a/pokemongo_bot/walkers/polyline_walker.py b/pokemongo_bot/walkers/polyline_walker.py index 0b66efee0b..4b29f03866 100644 --- a/pokemongo_bot/walkers/polyline_walker.py +++ b/pokemongo_bot/walkers/polyline_walker.py @@ -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 @@ -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 diff --git a/pokemongo_bot/walkers/step_walker.py b/pokemongo_bot/walkers/step_walker.py index 1946351b8a..c034b7ca79 100644 --- a/pokemongo_bot/walkers/step_walker.py +++ b/pokemongo_bot/walkers/step_walker.py @@ -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 @@ -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 @@ -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, @@ -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,