def moveUnitToFleet(self, fleetId, unitId): act = self.act('move_unit_to_fleet', val('fleet_id', fleetId)+val('unit_id', unitId)) u = None for unit in db.units(db.getTurn(), ['id=%s'%(unitId,)]): u = unit if not u: for unit in db.garrison_units(db.getTurn(), ['id=%s'%(unitId,)], ('x', 'y', 'class', 'hp')): u = unit if not u: print 'local unit %s not found'%(unitId,) return act print 'get garrison unit %s'%(u,) db.add_pending_action(self.act_id, db.Db.GARRISON_UNIT, 'erase', {'id':unitId}) del u['x'] del u['y'] u['fleet_id'] = fleetId db.add_pending_action(self.act_id, db.Db.UNIT, 'insert', u) else: print 'get fleet unit %s'%(u,) db.add_pending_action(self.act_id, db.Db.UNIT, 'update', ({'id':unitId}, {'fleet_id':fleetId})) return act
def addPlanets(self, players, buildings = None): self.sizer.DeleteWindows() for pl_id in players.player_ids(): for planet in db.planets(db.getTurn(), ['owner_id=%d'%(pl_id,)] ): coord = (int(planet['x']), int(planet['y'])) if buildings and not db.has_all_buildings(db.getTurn(), coord, buildings): continue p = planet_window.PlanetWindow(self, coord, db.getTurn()) self.planets[coord] = p self.sizer.Add( p ) self.sizer.Layout()
def cancel_jump(self, evt): turn = db.getTurn() out_dir = os.path.join(util.getTempDir(), config.options['data']['raw-dir']) util.assureDirClean(out_dir) for acc in config.accounts(): user_id = int(acc['id']) self.pending_actions.user_id = user_id fleets = [] fleet_flt = ['owner_id=%s'%(user_id,)] fleet_name = None #unicode('Fleet') # can also filter fleets by names #TODO: beware escapes if fleet_name: fleet_flt.append( 'name="%s"'%(fleet_name,) ) for fleet in db.flyingFleets(turn, fleet_flt): #print 'found fleet %s'%(fleet,) if fleet['in_transit'] != 0: continue print 'fleet %s can be stopped'%(fleet,) self.pending_actions.cancelJump(fleet['id']) self.perform_actions()
def __init__(self, parent): wx.Window.__init__(self, parent, -1, size=(120,200)) self.sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self.sizer) self.sizer.Layout() self.pos = (0,0) self.Bind(wx.EVT_SIZE, self.onSize, self) self.turn = db.getTurn()
def onMakeScoutFleets(self, _): # get all planets # get harrison units able to scout # create fleets # put units to fleets # get all scouting fleets ( available to jump ( on my planets ) ) # get unexplored planets # send nearest fleets to these planets # load size-map, use it to scout biggest first ( N > 70, descending ) # get all scouting fleets ( on other planets ) # geo-explore # send them back to nearest home planet #command_type, #move_command = ('move_to', #move_commands = [((x,y), fleet_id)] carapace = 11 # probe/zond fleet_name = 'scout:geo' turn = db.getTurn() for acc in config.accounts(): user_id = int(acc['id']) #if user_id < 601140: # continue units_classes = db.get_units_class(turn, ['carapace=%s'%(carapace,), 'owner_id=%s'%(user_id,)]) any_class = 'class in (%s)'%(','.join([str(cls) for cls in units_classes]),) print 'testing user %s with class %s'%(user_id, any_class) self.pending_actions.user_id = user_id pending_units = [] for planet in db.planets(turn, ['owner_id=%s'%(user_id,)]): coord = get_coord(planet) print 'checking harrison for planet %s'%(planet,) for unit in db.garrison_units(turn, filter_coord(coord) + [any_class]): print 'found unit %s on planet %s'%(unit, planet,) self.pending_actions.createNewFleet(coord, fleet_name) pending_units.append( (self.pending_actions.get_action_id(), coord, unit['id'] ) ) print 'found unit %s on planet %s'%(unit, coord ) if len(pending_units) == 0: continue self.recv_data_callback[acc['login']] = (self.cb_move_units_to_fleets, user_id, pending_units ) # exec actions to create fleets on the planets self.perform_actions()
def save(): log.info('saving data for turn %s'%(db.getTurn(),)) savePlanets() saveFleets() saveUnits() saveGarrisonUnits() saveAlienUnits() saveProto() saveUsers() savePlayers() save_sync_data()
def save_sync_data(): sync_path = config.options['data']['sync_path'] if not sync_path or sync_path == '': print 'sync path not specified, sync not performed' return turns_path = os.path.join(sync_path, 'turns/%s'%(db.getTurn(),)) nick = get_user_nickname() if not nick: print 'no users found, nothing to save' return print 'user nick is %s'%(nick,) outp = os.path.join(turns_path, nick) util.assureDirExist(outp) pt = os.path.join(config.options['data']['path'], str(db.getTurn())) if not os.path.exists(pt): return for f in os.listdir(pt): util.pack(os.path.join(pt, f), os.path.join(outp, f+".gz"))
def load_sync_data(): sync_path = config.options['data']['sync_path'] if not sync_path or sync_path == '': print 'sync path not specified, sync not performed' return turns_path = os.path.join(sync_path, 'turns') if not os.path.exists(turns_path): print 'sync path %s not exist'%(turns_path,) return available_turns = [] for f in os.listdir(turns_path): available_turns.append(int(f)) if not available_turns: print 'no sync data found in %s'%(turns_path,) return load_turn = db.getTurn() if not load_turn in available_turns: load_turn = max(available_turns) nick = get_user_nickname() turn_path = os.path.join(turns_path, str(load_turn)) for d in os.listdir(turn_path): if d == nick: continue acc_path = os.path.join(turn_path, d) print 'load %s turn: %s'%(d, load_turn) db.prepareTurn(load_turn) # do load unpack_dir = os.path.join(os.path.join(os.path.join( util.getTempDir(), 'unpack_sync' ), d), str(load_turn)) util.assureDirClean(unpack_dir) for gz_file in os.listdir(acc_path): outf = os.path.join(unpack_dir, gz_file) if outf.endswith('.gz'): outf = outf[:-len('.gz')] util.unpack(os.path.join(acc_path, gz_file), outf) table_name = os.path.basename(outf)[:-len('.csv')] if table_name == db.Db.PROTO or table_name == db.Db.PROTO_ACTION or table_name == db.Db.OPEN_PLANET or table_name == db.Db.USER: loadTable(table_name, None, load_turn, None, os.path.dirname(outf)) else: loadTable(table_name, load_turn, None, None, os.path.dirname(outf))
def harrison_units_to_fleets(self, user_id, coord, unit_type, fleets_ids): #TODO: check if fleet empty #add fleet new info to local-db turn = db.getTurn() self.pending_actions.user_id = user_id i = 0 if len(fleet_ids) < 1: return for unit in db.garrison_units(turn, ['x=%s'%(coord[0],), 'y=%s'%(coord[1],), 'class=%s'%(unit_type,)]): self.pending_actions.moveUnitToFleet(fleet_ids[i], unit['id']) i += 1 if i >= len(fleet_ids): break self.perform_actions( )
def harrison_units_to_fleets(self, user_id, coord, unit_type, fleets_ids): #TODO: check if fleet empty #add fleet new info to local-db turn = db.getTurn() self.pending_actions.user_id = user_id i = 0 if len(fleet_ids) < 1: return for unit in db.db.iter_objects_list(db.Db.UNIT, {'=':{'x':coord[0], 'y':coord[1], 'fleet_id':0, 'class':unit_type}}): self.pending_actions.moveUnitToFleet(fleet_ids[i], unit['id']) i += 1 if i >= len(fleet_ids): break self.perform_actions( )
def saveTable(table_name, keys, filters, turn_n = None): pt = config.options['data']['path'] pt = os.path.join(pt, str(db.getTurn())) util.assureDirExist(pt) path = os.path.join(pt, '%s.csv'%(table_name,)) try: f = open(path, 'wt') writer = csv.DictWriter(f, keys) writer.writeheader() for p in db.items(table_name, filters, keys, turn_n): try: for s in unicode_strings: if s in p and p[s]: p[s] = p[s].encode('utf-8') writer.writerow(p) except UnicodeEncodeError, e: log.error('failed convert data %s - %s'%(p, e)) except IOError, e: log.error('failed writing data to csv file %s: %s'%(path, e))
def __init__(self, parent, coord = None, turn = None, show_units = False): scrolled.ScrolledPanel.__init__(self, parent, wx.ID_ANY, size=(200,300)) self.turn = turn if turn else db.getTurn() self.sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self.sizer) self.coord = coord if not self.coord: self.sizer.Layout() return owner_id = 0 planet_name = '' for planet in db.planets(self.turn, ['x=%d'%(coord[0],), 'y=%d'%(coord[1],)], ('x','y','owner_id','o','e','m','t','s', 'name')): planet_name = planet.get('name', '') owner = planet['owner_id'] if not owner: break owner_id = int(owner) owner_name = 'unknown' if owner_id > 0: for res in db.players(self.turn, ['player_id=%s'%(owner_id,)]): owner_name = res['name'] else: owner_name = '<empty>' self.sizer.Add(wx.StaticText(self, wx.ID_ANY, '%s:%s %s'%(coord[0],coord[1], planet_name))) self.sizer.Add(wx.StaticText(self, wx.ID_ANY, owner_name)) if show_units: self.addUnits() #self.sizer.Layout() #self.SetSizer( self.vbox ) self.SetAutoLayout( 1 ) self.SetupScrolling() self.Bind(wx.EVT_SIZE, self.onSize, self)
def fleetMove(self, fleetId, to): act = self.act('move_fleet', pos('move_to', to)+val('fleet_id',fleetId)) # save fleet info fleet = None for f in db.fleets(db.getTurn(), ['id=%s'%(fleetId,)]): fleet = f break speed, rng = db.get_fleet_speed_range(fleetId) cur_pos = util.get_coord(fleet) dist = util.distance(to, cur_pos) # cannot move this far if dist > rng: print 'Error - attempt to move fleet %s to distance %s which is longer then fleet max range %s'%(fleetId, dist, rng) turns = int(math.ceil(dist / speed)) db.add_pending_action(self.act_id, db.Db.FLEET, 'erase', ['id=%s'%(fleetId,)]) db.add_pending_action(self.act_id, db.Db.FLYING_FLEET, 'insert', {'x':to[0], 'y':to[1], 'owner_id':self.user_id, 'id':fleetId, 'from_x':fleet['x'], 'from_y':fleet['y'], 'arrival_turn':turns + db.getTurn()}) return act
def cb_move_units_to_fleets(self, user_id, units): turn = db.getTurn() self.pending_actions.user_id = user_id at_least_one = False print 'executing move_units_to_fleets with user %s, units %s'%(user_id, units) for act_id, coord, unit_id in units: print 'action %s, coord %s, unit %s'%(act_id, coord, unit_id) # get fleet for these coords res = db.get_action_result(act_id) if not res: print 'oops no result' continue ret_id, is_ok = res print 'result is %s %s'%(ret_id, is_ok) if not is_ok: continue at_least_one = True print 'moving unit %s to fleet %s'%(unit_id, ret_id) self.pending_actions.moveUnitToFleet(ret_id, unit_id) if at_least_one: self.perform_actions()
def selectUser(self, user_id): pos = db.getUserHw(user_id, db.getTurn()) self.centerAt( pos ) serialization.load_geo_size_center( pos, 12 ) self.selected_user_id = user_id self.update()
def savePlanets(): saveTable(db.Db.PLANET, ('x','y','o','e','m','t','s','owner_id', 'name', 'is_open'), ['owner_id is not null'], db.getTurn()) saveTable(db.Db.OPEN_PLANET, ('x','y','user_id'), [], None)
def saveFleets(): saveTable(db.Db.FLEET, ('id', 'x','y','owner_id', 'is_hidden','name','weight'), None, db.getTurn()) saveTable(db.Db.FLYING_FLEET, ('id', 'x','y','in_transit', 'owner_id','from_x','from_y','weight', 'arrival_turn','is_hidden'), None, db.getTurn()) saveTable(db.Db.FLYING_ALIEN_FLEET, ('x','y','user_id','from_x','from_y','weight', 'arrival_turn','is_hidden'), None, db.getTurn())
def saveUnits(): saveTable(db.Db.UNIT, ('id', 'hp','class', 'fleet_id'), [], db.getTurn())
def saveGarrisonUnits(): saveTable(db.Db.GARRISON_UNIT, ('id', 'hp','class', 'x', 'y'), [], db.getTurn())
def onExploreGeoAll(self, _): 'upload pending events on server' turn = db.getTurn() explore_owned_planets = True out_dir = os.path.join(util.getTempDir(), config.options['data']['raw-dir']) util.assureDirClean(out_dir) for acc in config.accounts(): log.info('requesting user %s info'%(acc['login'],)) # find if there is any explore-capable fleets over unexplored planets # or simply tell explore to every unit =))) game server will do the rest #1. find all fleets above empty planets # get fleet position, check if planet geo is unknown fleet_planet = {} pl = {} for fleet in db.fleets(turn, ['owner_id=%s'%(acc['id'],)] ): print 'got fleet %s'%(fleet,) coord = get_coord(fleet) cfilter = filter_coord(coord) for planet in db.planets(turn, cfilter): # skip if occupied if planet['owner_id'] and not explore_owned_planets: continue if planet['o'] and planet['e'] and planet['m'] and planet['t']: continue #check holes and stars if not db.is_planet(coord): print '%s not a planet'%(coord,) continue if not coord in pl: pl[coord] = set() pl[ coord ].add(fleet['id']) print 'planet unexplored %s'%(planet,) acts = {} # get all fleet units, check if explore capable for coord, planet_fleets in pl.iteritems(): for fleet_id in planet_fleets: for unit in db.units(turn, ['fleet_id=%s'%(fleet_id,)]): print '%s %s unit %s'%(coord, fleet_id, unit) # ok unit bc = unit['class'] #for proto in db.prototypes(['id=%s'%(bc,)]): # print 'proto %s'%(proto,) #type 1 probably geo explore for act in db.proto_actions(['proto_id=%s'%(bc,), 'type=1']): #print 'ACTION: %s %s %s'%(coord, bc, act) acts[coord] = unit['id'] self.pending_actions.user_id = int(acc['id']) #self.pendingActions[int(acc['id'])] = actions #hw_planet = db.getUserHw(acc['id']) #actions.createNewFleet(hw_planet, 'a_new_shiny_fleet') at_least_one = False for coord, unit_id in acts.iteritems(): print 'explore (%s) %s'%(coord, unit_id) self.pending_actions.explore_planet( coord, unit_id ) at_least_one = True if at_least_one: self.perform_actions()
def onFlyHomeScouts(self, _): turn = db.getTurn() for acc in config.accounts(): user_id = int(acc['id']) self.pending_actions.user_id = user_id print 'fly home scouts for user %s %s'%(user_id, acc['login']) # fly scouts back to base fleets = [] fleet_flt = ['owner_id=%s'%(user_id,)] fleet_name = None #unicode('Fleet') # can also filter fleets by names #TODO: beware escapes if fleet_name: fleet_flt.append( 'name="%s"'%(fleet_name,) ) for fleet in db.fleets(turn, fleet_flt): print 'found fleet %s'%(fleet,) # if fleet over empty planet - jump back home coord = get_coord(fleet) planet = db.get_planet( coord ) if not planet or not planet['owner_id'] or int(planet['owner_id']) != user_id: print 'fleet %s not at home'%(fleet['id'],) units = [] for unit in db.units(turn, ['fleet_id=%s'%(fleet['id'],)]): print 'fleet %s has unit %s'%(fleet['id'], unit) units.append(unit) # not a scout fleet if more then one unit in fleet # if zero units - don't care about empty fleet as well if len(units) != 1: print 'fleet %s has %s units, while required 1'%(fleet['id'], len(units)) continue if int(units[0]['id']) in self.manual_control_units: continue proto = db.get_prototype(units[0]['class']) if proto['carapace'] != CARAPACE_PROBE: print 'fleet %s unit %s is not a probe'%(fleet['id'], units[0]) continue #jump back print 'fleet %s %s needs to get home'%(coord, fleet) fleets.append( (coord, fleet) ) if not fleets: print 'no scout fleets found not at home' continue coords = [] for planet in db.planets(turn, ['owner_id=%s'%(user_id,)]): coord = get_coord(planet) coords.append( coord ) print 'possible home planet %s'%(coord,) if coords == None or fleets == []: print 'oops %s %s'%(coords, fleets) continue print 'looking for best route for %s fleets' %(len(fleets,),) for coord, fleet in fleets: #find closest planet closest_planet = coords[0] min_distance = util.distance(coords[0], coord) for c in coords: if util.distance(coord, c) < min_distance: min_distance = util.distance(coord, c) closest_planet = c # ok, found then jump print 'Jump (%s) %s'%(closest_planet, fleet) self.pending_actions.fleetMove( fleet['id'], closest_planet ) self.perform_actions()
def saveAlienUnits(): saveTable(db.Db.ALIEN_UNIT, ('id', 'carapace','color','weight','fleet_id'), [], db.getTurn())
def saveUsers(): saveTable(db.Db.USER, ('id', 'name', 'race_id', 'login'), None) saveTable(db.Db.HW, ('hw_x', 'hw_y', 'player_id'), None, db.getTurn())
def __init__(self, parent): sz = int(config.options['window']['width']), int(config.options['window']['height']) wx.Frame.__init__(self, parent, -1, "dcLord (%s): Divide & Conquer client (www.the-game.ru)"%(version.getVersion(),), style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE, size=sz) if int(config.options['window']['is_maximized'])==1: self.Maximize() #import_raw.processAllUnpacked() #self.map.turn = db.db.max_turn self.log_dlg = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE) self.log_dlg.Disable() self.log_dlg.SetBackgroundColour('WHITE') serialization.load(ev_cb = self) self.info_panel = planet_window.InfoPanel(self) self.object_filter = object_filter.FilterPanel(self) self.planet_filter = object_filter.FilterFrame(self) #self.unit_list = unit_list.UnitPrototypeListWindow(self, 0) self.history = history.HistoryPanel(self) #self.area_list = area_panel.AreaListWindow(self) self.sync_path = config.options['data']['sync_path'] self.info_panel.turn = db.getTurn() print 'db max turn is %s'%(db.getTurn(),) self.map = map.Map(self) self.map.turn = db.getTurn() self.map.set_planet_filter(self.planet_filter) print 'map turn is set to %s'%(self.map.turn,) self.map.update() self.started = False self.actions_queue = [] self.pf = None if self.map.turn != 0: self.log('loaded data for turn %d'%(self.map.turn,)) self.pending_actions = request.RequestMaker() self._mgr = wx.aui.AuiManager(self) self.command_selected_user = False info = wx.aui.AuiPaneInfo() info.CenterPane() info.Fixed() info.DefaultPane() info.Resizable(True) info.CaptionVisible(False) self._mgr.AddPane(self.map, info) self._mgr.AddPane(self.history, wx.RIGHT, "Turn") self._mgr.AddPane(self.info_panel, wx.RIGHT, "Info") self._mgr.AddPane(self.planet_filter, wx.LEFT, "Planets") self._mgr.AddPane(self.object_filter, wx.LEFT, "Filter") #self._mgr.AddPane(self.unit_list, wx.RIGHT, "Units") self._mgr.AddPane(self.log_dlg, wx.BOTTOM, "Log") #self._mgr.AddPane(self.area_list, wx.RIGHT, "Areas") #self.map.set_planet_fileter(self.planet_filter) self._mgr.Update() #TODO: load from data self.manual_control_units = set() #unit id self.manual_control_units.add( 7906 ) self.manual_control_units.add( 7291 ) # probes over Othes planets #TODO: load from file self.exclude_fleet_names = [] #busy, taken, etc... #p = config.options['window']['pane-info'] #if p: # print 'load p %s'%(p,) # self._mgr.LoadPerspective( p ) self.recv_data_callback = {} self.makeMenu() self.Bind(event.EVT_DATA_DOWNLOAD, self.onDownloadRawData) self.Bind(event.EVT_MAP_UPDATE, self.onMapUpdate) self.Bind(event.EVT_USER_SELECT, self.onSelectUser) self.Bind(event.EVT_ACTIONS_REPLY, self.onActionsReply) self.Bind(event.EVT_SELECT_OBJECT, self.info_panel.selectObject) self.Bind(event.EVT_TURN_SELECTED, self.onTurnSelected) self.Bind(event.EVT_LOG_APPEND, self.onLog) #import_raw.processAllUnpacked() #serialization.save() #todo - restore previous state #self.Maximize() self.history.updateTurns(self.map.turn)
def savePlayers(): saveTable(db.Db.PLAYER, ('player_id', 'name'), None, db.getTurn())
def onSendScouts(self, _): turn = db.getTurn() 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 print 'send scouts %s size %s'%(user_id, 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 db.open_planets(user_id): print 'open planet %s'%(planet,) coord = get_coord(planet) for fleet in db.fleets(turn, filter_coord(coord)+['owner_id=%s'%(user_id,)]): if value_in(self.exclude_fleet_names, fleet['name']): continue units = db.get_units(turn, ['fleet_id=%s'%(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['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, self.get_unit_range(unit)) 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)) ready_scout_fleets.setdefault(coord, []).append((fleet, fly_range)) # get possible planets to explore in nearest distance for coord in ready_scout_fleets.keys(): serialization.load_geo_size_center(coord, 10) # jump to nearest/biggest unexplored planet exclude = set() for coord, fleets in ready_scout_fleets.iteritems(): lt = int(coord[0]-fly_range), int(coord[1]-fly_range) possible_planets = [] #s<=99 - skip stars for p in db.planets_size(['s>=%s'%(min_size,), 's<=%s'%(max_size,)] + planet_area_filter( lt, (int(fly_range*2), int(fly_range*2)))): dest = get_coord(p) if dest in exclude: continue dist = util.distance(dest, coord) if dist > fly_range: continue planet = db.get_planet(dest) if planet and 'o' in planet: continue has_flying_geo_scouts = False # get list of all flying fleets ( or our allies and mults ) to this planet for fleet in db.flyingFleets(turn, filter_coord(dest) + ['owner_id in(%s)'%','.join(friend_geo_scout_ids)]): # check if the fleet is geo-scout if self.is_geo_scout_fleet(turn, fleet['id']): has_flying_geo_scouts = True print 'found another scout %s, skip planet %s'%(fleet, dest) if has_flying_geo_scouts: exclude.add(dest) continue #TODO: can check if it will take too long for the other fleet, send ours possible_planets.append( (dist, dest) ) for fleet, fleet_range in fleets: for dist, planet in sorted(possible_planets): if dist > fleet_range: continue # ok fly to it 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 self.perform_actions()
def onMakeScoutFleets(self, _): # get all planets # get harrison units able to scout # create fleets # put units to fleets # get all scouting fleets ( available to jump ( on my planets ) ) # get unexplored planets # send nearest fleets to these planets # load size-map, use it to scout biggest first ( N > 70, descending ) # get all scouting fleets ( on other planets ) # geo-explore # send them back to nearest home planet #command_type, #move_command = ('move_to', #move_commands = [((x,y), fleet_id)] carapace = 11 # probe/zond fleet_name = 'scout:geo' turn = db.getTurn() for acc in config.accounts(): if not 'id' in acc: continue user_id = int(acc['id']) #if user_id < 601140: # continue probes_types = store.get_objects_list('proto', {'carapace':carapace, 'user_id':user_id}) #any_class = 'class in (%s)'%(','.join([str(cls) for cls in units_classes]),) #print 'testing user %s with class %s'%(user_id, any_class) probe_ids = [str(proto['proto_id']) for proto in probes_types] self.pending_actions.user_id = user_id pending_units = [] for planet in store.iter_objects_list('user_planet', {'user_id':user_id}): coord = get_coord(planet) #print 'checking harrison for planet %s'%(planet,) for unit in store.get_garrison_units(coord, value_in=('proto_id', probe_ids)): #print 'found unit %s on planet %s'%(unit, planet,) action_create = action.ActionCreateFleet(user_id, fleet_name, coord) self.actions.add_action(action_create) fleet_id = action_create.fleet_id self.actions.add_action(action.ActionUnitMove(user_id, fleet_id, unit['unit_id'])) #self.actions.add_action(action.Action('unit_move', user_id, {'planet':coord, 'unit_id':unit['unit_id'], 'fleet_id':fleet_id})) #self.actions.add_action(action.Action('unit_move', user_id, {'planet':coord, 'unit_id':unit['unit_id'], 'fleet_id':fleet_id})) #self.pending_actions.createNewFleet(coord, fleet_name) #pending_units.append( (self.pending_actions.get_action_id(), coord, unit['id'] ) ) #print 'found unit %s on planet %s'%(unit, coord ) if len(pending_units) == 0: continue