def drawPlanets(self, dc, rect): #cond = ['owner_id is not null'] ax,bx = self.offset_pos[0], self.offset_pos[0]+self.screen_size[0] ay,by = self.offset_pos[1], self.offset_pos[1]+self.screen_size[1] inhabitedOnly = int(config.options['filter']['inhabited_planets'])==1 ownedOnly = int(config.options['filter']['owned_planets'])==1 if not inhabitedOnly and not ownedOnly: for p in store.iter_planets_size((ax,bx,ay,by)): self.drawPlanet(dc, p) for p in store.iter_planets((ax,bx,ay,by), inhabited = inhabitedOnly, owned = ownedOnly): self.drawPlanet(dc, p) #if self.draw_geo: # self.drawPlanetGeo(dc, p) if self.selected_user_id: for p in store.iter_objects_list('open_planet', {'user_id':self.selected_user_id}): self.draw_open_planet(dc, p)
def onSendScouts(self, _): min_size = 70 max_size = 99 #helps avoid flying on the same planet with different accounts friend_geo_scout_ids = [] for user in db.users(): friend_geo_scout_ids.append(str(user['id'])) for acc in config.accounts(): user_id = int(acc['id']) if self.command_selected_user and user_id != self.map.selected_user_id: continue self.pending_actions.user_id = user_id #log.info('send scouts %s size %s'%(acc['login'], min_size)) # find units that can geo-explore # find the ones that are already in fleets in one of our planets fly_range = 0.0 ready_scout_fleets = {} # get all fleets over our planets for planet in store.iter_objects_list('open_planet', {'user_id':user_id}): #print 'open planet %s'%(planet,) coord = get_coord(planet) for fleet in store.iter_objects_list('fleet', {'user_id':user_id, 'x':coord[0], 'y':coord[1]}): if value_in(self.exclude_fleet_names, fleet['name']): continue units = store.get_fleet_units(fleet['fleet_id']) if len(units) != 1: #print 'fleet %s has wrong units count ( != 1 ) %s, skipping it'%(fleet, units) continue unit = units[0] if int(unit['unit_id']) in self.manual_control_units: #print 'unit %s reserved for manual control, skipping it'%(unit,) continue if not self.is_geo_scout(unit): #print 'unit %s is not geo-scout, skipping it'%(unit,) continue #fly_range = max(fly_range, ) #print 'unit %s on planet %s for fleet %s is geo-scout'%(unit, coord, fleet) # ok, this is geo-scout, single unit in fleet, on our planet #ready_scout_fleets.append((coord, fleet)) _,r = store.get_fleet_speed_range(fleet['fleet_id']) fly_range = max(fly_range, r) ready_scout_fleets.setdefault(coord, []).append((fleet, r)) # get possible planets to explore in nearest distance for coord in ready_scout_fleets.keys(): #print 'load geo size centered at %s with range %s'%(coord, int(fly_range)) save_load.load_geo_size_center(coord, int(fly_range)) # jump to nearest/biggest unexplored planet exclude = set() for coord, fleets in ready_scout_fleets.iteritems(): max_fly_range = 0 for f,r in fleets: max_fly_range = max(max_fly_range, r) possible_planets = [] #s<=99 - skip stars #dx = lt[0]-fly_range, lt[0]+fly_range #dy = lt[1]-fly_range, lt[1]+fly_range for p in store.iter_planets_size(pos=coord, fly_range=max_fly_range, size_min=min_size, bigger_first = True): if not (p['s']>=min_size and p['s']<=max_size): #print 'planet %s not fit the size'%(p,) continue dest = get_coord(p) if dest in exclude: continue dist = util.distance(dest, coord) if dist > fly_range: #print 'planet %s is too far away'%(p,) continue planet = db.get_planet(dest) if planet and 'o' in planet and planet['o']: #print 'planet %s already explored'%(p,) continue has_flying_geo_scouts = False # check if currently there is some explore fleet on planet, or explore fleet already fly there already_has_scout = False for fleet in store.iter_objects_list('fleet', {'x':dest[0], 'y':dest[1]}, controlled = True): if self.is_geo_scout_fleet(fleet['fleet_id']): already_has_scout = True break if already_has_scout: #print 'planet %s has scount fleet on it'%(p,) continue already_fly_geo_scouts = False for fleet in store.iter_objects_list('flying_fleet', {'x':dest[0], 'y':dest[1]}, controlled = True): if self.is_geo_scout_fleet(fleet['fleet_id']): already_fly_geo_scouts = True #self.actions.add_action( action.ActionGeoExplore(user_id, ':dest, 'fleet_id':fleet['fleet_id']})) break if already_fly_geo_scouts: #print 'planet %s has flying scount fleet'%(p,) continue possible_planets.append( (dist, dest) ) #print 'add possible planet %s'%(dest,) for fleet, fleet_range in fleets: #print 'check planets for fleet %s'%(fleet,) for dist, planet in sorted(possible_planets): if dist > fleet_range: #print 'planet %s too scary'%(p,) continue # ok fly to it self.actions.add_action( action.ActionJump(user_id, fleet['fleet_id'], planet )) #self.pending_actions.fleetMove(fleet['id'], planet) exclude.add( planet ) #print 'jump %s from %s to %s'%(fleet, coord, planet) possible_planets.remove( (dist, planet ) ) break