diff --git a/.gitignore b/.gitignore index 8e872a7..b66adaf 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ target/ # IDEA .idea + +# EVE +eve.db diff --git a/dropbot/bot.py b/dropbot/bot.py index c31285d..734a01d 100644 --- a/dropbot/bot.py +++ b/dropbot/bot.py @@ -269,3 +269,39 @@ class DropBot(ClientXMPP): res[sys['region']] = 1 return '{} systems in JDC5 {} range of {}:\n'.format(len(systems), ship_class, self.map.get_system_name(system_id)) + '\n'.join(['{} - {}'.format(x, y) for x, y in res.items()]) + + def cmd_route(self, args, msg): + if len(args) != 2: + return '!route ' + source, dest = args + + source_systems = self.map.get_systems(source) + dest_systems = self.map.get_systems(dest) + + if len(source_systems) > 1: + if len(source_systems) > 10: + return 'More than 10 systems match {}, please provide a more complete name'.format(source) + return 'Did you mean: {}?'.format(', '.join([self.map.get_system_name(x) for x in source_systems])) + elif len(source_systems) == 0: + return 'No systems found matching {}'.format(source) + else: + source_system = source_systems[0] + + if len(dest_systems) > 1: + if len(dest_systems) > 10: + return 'More than 10 systems match {}, please provide a more complete name'.format(source) + return 'Did you mean: {}?'.format(', '.join([self.map.get_system_name(x) for x in dest_systems])) + elif len(dest_systems) == 0: + return 'No systems found matching {}'.format(dest) + else: + dest_system = dest_systems[0] + + route = self.map.route_gate(source_system, dest_system) + route_names = ' -> '.join(['{} ({})'.format(x['name'], round(x['security'], 2)) for x in [self.map.node[y] for y in route]]) + + return '{} jumps from {} to {}\n{}'.format( + len(route), + self.map.get_system_name(source_system), + self.map.get_system_name(dest_system), + route_names + ) \ No newline at end of file diff --git a/dropbot/map.py b/dropbot/map.py index 60bfe66..64d0324 100644 --- a/dropbot/map.py +++ b/dropbot/map.py @@ -105,15 +105,22 @@ class Map(networkx.Graph): for k, v in self.nodes_iter(data=True): if 'name' in v and v['name'].lower() == name.lower(): return k + + def get_systems(self, name): + """Returns a list of systems by a partial system name""" + return [k for k, v in self.nodes_iter(data=True) if name.lower() in v['name'].lower()] def system_distance(self, source, destination): """Calculates the distance in ly between two systems""" return calc_distance(self.node[source], self.node[destination]) - def route_gate(self, source, destination): + def route_gate(self, source, destination, filter=None): """Route between two systems using gates (fastest)""" + + # TODO: add EVE routing options (highsec/lowsec/fastest) + g = networkx.Graph(data=[(u, v) for u, v, d in self.edges_iter(data=True) if d['link_type'] == 'gate']) - return networkx.astar_path(g, source, destination) + return networkx.astar_path(self, source, destination) def route_jump(self, source, destination, range=None, hull=None, ship_class=None): """Route between two systems using jumps"""