def set_coord(self, coord): self.coord = coord self.sizer.DeleteWindows() dsizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(dsizer) dups = {} protos = {} up = store.get_object('user_planet', {'x':coord[0], 'y':coord[1]}) if not up: return user_id = up['user_id'] # buildings if ours for building in store.get_garrison_units(coord): bc = building['proto_id'] p = store.get_object('proto', {'proto_id':bc, 'user_id':user_id}) if not p: print 'proto not found for %s'%(building,) continue if int(p['is_building']) != 1: continue if 'max_count' in p and int(p['max_count'])!=1: dups.setdefault(bc, []).append(building) continue img = image.getBcImage(bc, 20) if not img: wnd = wx.StaticText(self, -1, 'Unknown building %s'%(bc,)) else: wnd = wx.StaticBitmap(self, wx.ID_ANY) wnd.SetBitmap(img) dsizer.Add(wnd) for bc, builds in dups.iteritems(): img = image.getBcImage(bc, 20) wsizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(wsizer) wnd = wx.StaticBitmap(self, wx.ID_ANY) if img: wnd.SetBitmap(img) wsizer.Add(wnd) txt = wx.StaticText(self, -1, 'x %s'%(len(builds),)) build_more = wx.Button(self, label="+", size=(20,20)) build_more.proto_id = bc wsizer.Add(txt) wsizer.Add(build_more) build_more.Bind(wx.EVT_LEFT_DOWN, self.on_build) has_bq = None prev_units = [] for unit in store.get_building_queue(coord): if not has_bq: self.sizer.Add(wx.StaticText(self, label='build queue:')) has_bq = True if unit['done'] > 0: self.draw_build_stack(prev_units) prev_units = [] proto = store.get_object('proto', {'proto_id':unit['proto_id'], 'user_id':user_id}) img = image.getBcImage(unit['proto_id'], 20) if not img: img = image.getCarapaceImage(proto['carapace'], proto['color'], 20) wsizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(wsizer) wnd = wx.StaticBitmap(self, wx.ID_ANY) if img: wnd.SetBitmap(img) wsizer.Add(wnd) name = proto['name'] if not name: name = get_unit_name(int(proto['carapace'])) race = store.get_object('race', {'user_id':user_id}) build_modifier = 0 #if proto['is_war'] == 1: # build_modifier = race['modifier_build_war'] #else: # build_modifier = race['modifier_build_peace'] total_speed = proto['build_speed'] - proto['build_speed']*build_modifier/100.0 # if we're lucky? if proto['proto_id'] == 13: govs_count = len(store.get_governers(user_id)) total_speed = pow(1.5, govs_count) * proto['build_speed'] percent_done = int(unit['done']*100/total_speed) txt = wx.StaticText(self, -1, ' %d%% %s'%(percent_done, name)) wsizer.Add(txt) if 'max_count' in proto and int(proto['max_count'])!=1: build_more = wx.Button(self, label="+", size=(20,20)) build_more.proto_id = proto['proto_id'] build_more.Bind(wx.EVT_LEFT_DOWN, self.on_build) wsizer.Add(build_more) continue if prev_units == [] or unit['proto_id'] == prev_units[0]['proto_id']: prev_units.append(unit) continue # draw prev_units self.draw_build_stack(prev_units) prev_units = [unit] self.draw_build_stack(prev_units) self.sizer.Layout()
def set_coord(self, coord): self.coord = coord self.button_fleet.Disable() self.selected_units = {} self.units_sizer.DeleteWindows() user_planet = store.get_object('user_planet', {'x':coord[0], 'y':coord[1]}) if not user_planet: self.sizer.Layout() return item_windows = {} dups = {} protos = {} items = {} gu = store.get_garrison_units(coord) for unit in gu: bc = unit['proto_id'] if bc in items: items[bc].append(unit) continue p = store.get_object('proto', {'proto_id':bc}) if int(p['is_building']) == 1: continue items[bc] = [unit] protos[bc] = p for bc, item_list in items.iteritems(): p = protos[bc] wnd = wx.Window(self, style=wx.SUNKEN_BORDER) wnd.proto_id = bc wnd.units = item_list sz = wx.BoxSizer(wx.HORIZONTAL) wnd.SetSizer(sz) self.units_sizer.Add(wnd) if 'carapace' in p and p['carapace']: img = image.getCarapaceImage(int(p['carapace']), int(p['color'])) else: img = image.getBcImage(bc) bmp = wx.StaticBitmap(wnd) if img: bmp.SetBitmap(img) sz.Add(bmp) n_str = '' if len(item_list) > 1: n_str = ' x%s'%(len(item_list),) name = get_unit_name(bc) if not name: name = p['name'] fly='' transport = '' if int(p['is_spaceship'])==1: fly = '%.2f/%.2f'%(p['fly_speed'], p['fly_range']) tc = int(p['transport_capacity']) if tc > 0: transport = '[%s]'%(tc,) text = wx.StaticText(wnd, -1, '%s%s%s %s'%(fly, transport, n_str, name,)) sz.Add(text) sz.Layout() wnd.Bind(wx.EVT_LEFT_DOWN, self.onLeftDown) bmp.Bind(wx.EVT_LEFT_DOWN, self.onLeftDown) text.Bind(wx.EVT_LEFT_DOWN, self.onLeftDown) self.sizer.Layout()
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