diff --git a/configs/config.json.example b/configs/config.json.example index 3468ca7a99..5fe25d3291 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -59,11 +59,14 @@ } }, { - "type": "FollowSpiral" + "type": "FollowSpiral", + "config": { + "diameter": 4, + "step_size": 70 + } } ], "map_object_cache_time": 5, - "max_steps": 5, "forts": { "avoid_circles": true, "max_circle_size": 50 diff --git a/pokecli.py b/pokecli.py index d37bc16313..e0c982f5e3 100755 --- a/pokecli.py +++ b/pokecli.py @@ -225,16 +225,6 @@ def init_config(): type=str, default=None ) - add_config( - parser, - load, - short_flag="-ms", - long_flag="--max_steps", - help= - "Set the steps around your initial location(DEFAULT 5 mean 25 cells around your location)", - type=int, - default=50 - ) add_config( parser, @@ -367,7 +357,7 @@ def task_configuration_error(flag_name): """.format(flag_name)) old_flags = ['mode', 'catch_pokemon', 'spin_forts', 'forts_spin', 'hatch_eggs', 'release_pokemon', 'softban_fix', - 'longer_eggs_first', 'evolve_speed', 'use_lucky_egg', 'item_filter', 'evolve_all', 'evolve_cp_min'] + 'longer_eggs_first', 'evolve_speed', 'use_lucky_egg', 'item_filter', 'evolve_all', 'evolve_cp_min', 'max_steps'] for flag in old_flags: if flag in load: task_configuration_error(flag) diff --git a/pokemongo_bot/cell_workers/follow_spiral.py b/pokemongo_bot/cell_workers/follow_spiral.py index a77363403d..bda348490a 100644 --- a/pokemongo_bot/cell_workers/follow_spiral.py +++ b/pokemongo_bot/cell_workers/follow_spiral.py @@ -1,24 +1,30 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, unicode_literals + +import math + import pokemongo_bot.logger as logger from pokemongo_bot.cell_workers.utils import distance, format_dist from pokemongo_bot.step_walker import StepWalker from pokemongo_bot.cell_workers.base_task import BaseTask - class FollowSpiral(BaseTask): def initialize(self): - self.steplimit = self.bot.config.max_steps + self.steplimit = self.config.get("diameter", 4) + self.step_size = self.config.get("step_size", 70) self.origin_lat = self.bot.position[0] self.origin_lon = self.bot.position[1] + self.diameter_to_steps = (self.steplimit+1) ** 2 self.points = self._generate_spiral( - self.origin_lat, self.origin_lon, 0.0018, self.steplimit + self.origin_lat, self.origin_lon, self.step_size, self.diameter_to_steps ) + self.ptr = 0 self.direction = 1 self.cnt = 0 + @staticmethod def _generate_spiral(starting_lat, starting_lng, step_size, step_limit): """ @@ -34,18 +40,24 @@ def _generate_spiral(starting_lat, starting_lng, step_size, step_limit): coords = [{'lat': starting_lat, 'lng': starting_lng}] steps, x, y, d, m = 1, 0, 0, 1, 1 + rlat = starting_lat * math.pi + latdeg = 111132.93 - 559.82 * math.cos(2*rlat) + 1.175*math.cos(4*rlat) + lngdeg = 111412.84 * math.cos(rlat) - 93.5 * math.cos(3*rlat) + step_size_lat = step_size / latdeg + step_size_lng = step_size / lngdeg + while steps < step_limit: while 2 * x * d < m and steps < step_limit: x = x + d steps += 1 - lat = x * step_size + starting_lat - lng = y * step_size + starting_lng + lat = x * step_size_lat + starting_lat + lng = y * step_size_lng + starting_lng coords.append({'lat': lat, 'lng': lng}) while 2 * y * d < m and steps < step_limit: y = y + d steps += 1 - lat = x * step_size + starting_lat - lng = y * step_size + starting_lng + lat = x * step_size_lat + starting_lat + lng = y * step_size_lng + starting_lng coords.append({'lat': lat, 'lng': lng}) d *= -1 @@ -88,9 +100,12 @@ def work(self): point['lat'], point['lng'] ) <= 1 or (self.bot.config.walk > 0 and step_walker == None): - if self.ptr + self.direction == len(self.points) or self.ptr + self.direction == -1: + if self.ptr + self.direction >= len(self.points) or self.ptr + self.direction <= -1: self.direction *= -1 - self.ptr += self.direction + if len(self.points) != 1: + self.ptr += self.direction + else: + self.ptr = 0 self.cnt = 0 return [point['lat'], point['lng']]