def find_route(self): planet_opts = {'x':self.start_pos[0], 'y':self.start_pos[1], 'user_id':self.user_id} start_planet = store.get_object('open_planet', planet_opts) if start_planet: r = self.route_next(self.start_pos) if r: return [self.start_pos] + r return [] print 'route: fleet needs landing' # fleet starts on non-jumpable planet for pl in store.iter_open_planets(self.fly_range, self.start_pos, self.dest_pos, self.exclude_planets): # it can appear here if pl in self.exclude_planets: continue self.exclude_planets.append(pl) print 'route: landing found %s'%(pl,) if pl == self.dest_pos: print 'route found: direct jump' return [self.start_pos, pl] r = self.route_next(pl) if r: return [self.start_pos, pl] + r # sorry, not route to host return []
def route_next(self, cur_pos): dist = util.distance(cur_pos, self.dest_pos) print 'route: looking from %s (%f left)'%(cur_pos, dist) # are we close enough for direct jump? if dist <= self.fly_range: print 'route found: direct jump from %s'%(cur_pos,) return [self.dest_pos] for pl in store.iter_open_planets(self.fly_range*2, cur_pos, self.dest_pos, self.exclude_planets): if pl in self.exclude_planets: continue d2 = util.distance(pl, self.dest_pos) if d2 >= dist: continue r = [] intermediate_pt = None jump_dist = util.distance(cur_pos, pl) if jump_dist > self.fly_range: intermediate_pt = self.find_intermediate_jump_point(cur_pos, pl) if not intermediate_pt: continue #intermediate_pt = cur_pos[0]+intermediate_pt[0], cur_pos[1]+intermediate_pt[1] r.append(intermediate_pt) self.exclude_planets.append(pl) #if intermediate_pt: # print 'route: jump to %s (though %s), distance: %s'%(pl, intermediate_pt, jump_dist) #else: # print 'route: jump to %s, distance: %s'%(pl, jump_dist) if cur_pos == self.dest_pos: print 'route found: %s'%(pl,) return r res = self.route_next(pl) if res: return r + [pl] + res return []