示例#1
0
文件: action.py 项目: bogolt/dclord
	def __init__(self, user_id, fleet_id, unit_id):
		Action.__init__(self, user_id)
		self.unit_id = unit_id
		self.fleet_id = fleet_id
		
		self.fleet_unit = store.get_object('fleet_unit', {'unit_id':unit_id})
		self.garrison_unit = store.get_object('garrison_unit', {'unit_id':unit_id})
示例#2
0
文件: map.py 项目: bogolt/dclord
	def selectUser(self, user_id):
		hw_pos = store.get_object('hw', {'user_id': user_id})
		self.selected_user_governers_count = 0
		if not hw_pos:
			print 'cannot get hw of %s'%user_id
			return
		self.selected_user_id = user_id
		self.centerAt( (int(hw_pos['x']), int(hw_pos['y'])) )
		self.selected_user_id = user_id
		try:
			self.user_race = store.get_object('race', {'user_id': self.selected_user_id})
			self.selected_user_governers_count = len(store.get_governers(self.selected_user_id))
		except:
			pass
		self.update()
示例#3
0
文件: map.py 项目: bogolt/dclord
	def showGood(self, show_good):
		self.show_good_planets = show_good
		if self.show_good_planets:
			self.user_race = store.get_object('race', {'user_id':self.selected_user_id})
			self.selected_user_governers_count = len(store.get_governers(self.selected_user_id))

		self.update()
示例#4
0
	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 []
示例#5
0
文件: action.py 项目: bogolt/dclord
	def get_action_string(self):
		unit_name = store.get_unit_name(self.unit_id)
		fleet_name = store.get_fleet_name(self.fleet_id)
		fleet = store.get_object('fleet', {'fleet_id':self.fleet_id})
		if not fleet:
			log.error('Unit move failed - fleet not found in db [user %s, fleet %s, unit: %s]'%(self.user_id, self.fleet_id, self.unit_id))
			return 'Fleet %s not found in db'%(self.fleet_id,)
		return 'Unit %s move to fleet %s[%s] at %d:%d'%(unit_name, fleet_name, store.get_user_name(self.user_id), fleet['x'], fleet['y'])
示例#6
0
def save_user_data(user_id, path):
	util.assureDirExist(path)
	log.info('saving user %s %s'%(user_id, path))
	
	user_filter = {'user_id':user_id}
	save_csv_table(path, 'user', user_filter)
	save_csv_table(path, 'open_planet', user_filter)
	save_csv_table(path, 'race', user_filter)
	save_csv_table(path, 'diplomacy', user_filter)
	save_csv_table(path, 'hw', user_filter)

	save_csv_table(path, 'flying_fleet', user_filter)
	save_csv_table(path, 'alien_flying_fleet', user_filter)
	save_csv_table(path, 'user_planet', user_filter)
	save_csv_table(path, 'fleet', user_filter)
	save_csv_table(path, 'proto', user_filter)
	
	save_csv_table(path, 'action', user_filter)
	
	fleet_unit_writer = csv_open( os.path.join(path, 'fleet_unit.csv'), store.keys('fleet_unit'))
	unit_writer = csv_open( os.path.join(path, 'unit.csv'), store.keys('unit'))
	for fleet in store.iter_objects_list('fleet', {'user_id':user_id}):
		for fleet_unit in store.iter_objects_list('fleet_unit', {'fleet_id':fleet['fleet_id']}):
			fleet_unit_writer.writerow(fleet_unit)
			unit_writer.writerow( store.get_object('unit', {'unit_id':fleet_unit['unit_id']}) )

	for fleet in store.iter_objects_list('flying_fleet', {'user_id':user_id}):
		for fleet_unit in store.iter_objects_list('fleet_unit', {'fleet_id':fleet['fleet_id']}):
			fleet_unit_writer.writerow(fleet_unit)
			unit_writer.writerow( store.get_object('unit', {'unit_id':fleet_unit['unit_id']}) )
			
	garrison_unit_writer = csv_open(os.path.join(path, 'garrison_unit.csv'), store.keys('garrison_unit'))
	garrison_queue_unit_writer = csv_open(os.path.join(path, 'garrison_queue_unit.csv'), store.keys('garrison_queue_unit'))
	#save_csv_table(path, 'garrison_queue_unit')
	for planet in store.iter_objects_list('user_planet', {'user_id':user_id}):
		for garrison_unit in store.iter_objects_list('garrison_unit', {'x':planet['x'], 'y':planet['y']}):
			garrison_unit_writer.writerow(garrison_unit)
			unit_writer.writerow( store.get_object('unit', {'unit_id':garrison_unit['unit_id']}) )
			
		for queue_unit in store.iter_objects_list('garrison_queue_unit', {'x':planet['x'], 'y':planet['y']}):
			garrison_queue_unit_writer.writerow( queue_unit )
	
	proto_actions_writer = csv_open(os.path.join(path, 'proto_action.csv'), store.keys('proto_action'))
	for proto in store.iter_objects_list('proto', {'user_id':user_id}):
		proto_actions_writer.writerows(store.get_objects_list('proto_action', {'proto_id':proto['proto_id']}))
示例#7
0
文件: action.py 项目: bogolt/dclord
	def get_action_string(self):
		fleet = store.get_object('fleet', {'fleet_id':self.fleet_id})
		if not fleet:
			log.error('Jump failed - fleet not found in db [user %s, fleet %s, coord: %s]'%(self.user_id, self.fleet_id, self.coord))
			return 'Jump failed - fleet not found in db [user %s, fleet %s, coord: %s]'%(self.user_id, self.fleet_id, self.coord)
		fromx,fromy = fleet['x'],fleet['y']
		fleet_name = fleet['name']
		x,y = self.coord
		return 'Fleet: "%s" [%s] %d:%d => %d:%d'%(fleet_name, store.get_user_name(self.user_id),  fromx, fromy, x, y)
示例#8
0
	def on_build_cancel(self, evt):
		units = evt.attr1
		coord = evt.attr2
		user_planet = store.get_object('user_planet', {'x':coord[0], 'y':coord[1]})
		if not user_planet:
			#print 'planet %s owner unknown'%(coord,)
			return
		self.actions.add_action(action.ActionCancelBuild(user_planet['user_id'], units[-1]['unit_id']))
		self.planet_panel.update()
示例#9
0
	def on_build_unit(self, evt):
		#print 'build unit %s on %s'%(evt.attr1, evt.attr2)
		coord = evt.attr2
		user_planet = store.get_object('user_planet', {'x':coord[0], 'y':coord[1]})
		if not user_planet:
			#print 'planet %s owner unknown'%(coord,)
			return
		self.actions.add_action(action.ActionBuild(user_planet['user_id'], coord, evt.attr1))
		self.planet_panel.update()
示例#10
0
文件: action.py 项目: bogolt/dclord
	def get_action_string(self):
		return 'Create fleet %s[%s] %d:%d'%(self.name, store.get_user_name(self.user_id), self.coord[0], self.coord[1])
		
		unit_name = store.get_unit_name(self.unit_id)
		fleet_name = store.get_fleet_name(self.fleet_id)
		fleet = store.get_object('fleet', {'fleet_id':self.fleet_id})
		if not fleet:
			#print 'oops, fleet %d not found in db, unit move failed'%(action.fleet_id,)
			return 'bad action'
		return 'Unit %s move to fleet %s[%s] at %d:%d'%(unit_name, fleet_name, store.get_user_name(self.user_id), fleet['x'], fleet['y'])
示例#11
0
	def update(self):
		coord = self.coord
		
		self.sizer.DeleteWindows()
		
		self.sizer.Add( wx.StaticText(self, wx.ID_ANY, '%s:%s'%coord) )
		
		planet = store.get_object('planet', {'x':coord[0], 'y':coord[1]})
		owner = None
		name = None
		if not planet:
			self.sizer.Layout()
			return

		if 'o' in planet and planet['o']:
			self.sizer.Add( wx.StaticText(self, wx.ID_ANY, 'o: %s, e: %s, m: %s, t: %s, s: %s'%(planet['o'], planet['e'], planet['m'], planet['t'], planet['s'])) )
		else:
			pl_sz = store.get_object('planet_size', {'x':coord[0], 'y':coord[1]})
			if pl_sz:
				self.sizer.Add( wx.StaticText(self, wx.ID_ANY, 's: %s'%(pl_sz['s'],)) )
		
		if 'name' in planet and planet['name']:
			self.sizer.Add( wx.StaticText(self, wx.ID_ANY, planet['name']) )
		
		if 'user_id' not in planet:
			self.sizer.Layout()
			return
		owner_id = planet['user_id']
		if not owner_id:
			self.sizer.Layout()
			return
		u = store.get_user(owner_id)
		if u:
			owner_name = u['name']
			self.sizer.Add( wx.StaticText(self, wx.ID_ANY, owner_name) )
		
		buildings = BuildingsWindows(self)
		buildings.set_coord(coord)
		self.sizer.Add(buildings)
		self.sizer.Layout()
		
		self.Bind(event.EVT_BUILD_UNIT, self.on_build_unit)
		self.Bind(event.EVT_BUILD_CANCEL, self.on_build_cancel)
示例#12
0
	def onObjectSelect(self, evt):
		self.planet_panel.select_coord(evt)
		self.garrison_panel.select_coord(evt)
		#self.info_panel.selectObject(evt)
		self.fleets.set_fleets(evt)
		self.map.select_pos( evt.attr1 )
		
		routes = []
		for fleet_id in self.jump_fleets:
			fleet = store.get_object('fleet', {'fleet_id':fleet_id})
			if not fleet:
				continue
			print 'calculate route for fleet %s'%(fleet,)
			route = self.calculate_route( fleet, evt.attr1 )
			if route:
				routes.append( route )
				fleet = store.get_object('fleet', {'fleet_id':fleet_id})
				
				self.actions.add_action( action.ActionJump(fleet['user_id'], fleet_id, evt.attr1))
			
		self.map.jump_fleets_routes = routes
		self.map.update()
示例#13
0
	def update_user(self, user_id):
		l = loader.AsyncLoader()
		
		out_dir = os.path.join(util.getTempDir(), config.options['data']['raw-dir'])
		user = store.get_object('user', {'user_id':user_id})
		if not user:
			print 'no user %s found'%(user_id,)
			return
		
		acc = config.users[user['login']]
		if not acc:
			print 'no login/password for user %s specified'%(user['name'],)
			return

		log.info('requesting user %s info'%(acc['login'],))
		l.getUserInfo(self, acc['login'], out_dir)
		l.start()
示例#14
0
	def on_fleet_create(self, evt):
		main_frame = self.GetParent()

		user_planet = store.get_object('user_planet', {'x':self.coord[0], 'y':self.coord[1]})
		if not user_planet:
			return
			
		user_id = user_planet['user_id']

		# get fleet name
		
		# create new fleet
		create_fleet_action = action.ActionCreateFleet(user_id, 'Fleet', self.coord)
		main_frame.actions.add_action(create_fleet_action)

		# move units there
		for proto_id, units in self.selected_units.iteritems():
			for unit in units:
				main_frame.actions.add_action(action.ActionUnitMove(user_id, create_fleet_action.fleet_id, unit['unit_id']))
		
		wx.PostEvent(self.GetParent(), event.SelectObject(attr1=self.coord))
示例#15
0
	def draw_build_stack(self, units):
		if len(units) == 0:
			return
		wsizer = wx.BoxSizer(wx.HORIZONTAL)
		self.sizer.Add(wsizer)
		
		proto = store.get_object('proto', {'proto_id':units[0]['proto_id']})
		img = image.getBcImage(units[0]['proto_id'], 20)
		if not img:
			img = image.getCarapaceImage(proto['carapace'], proto['color'], 20)

		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']))
		
		count_text = ''
		if len(units)>1:
			count_text = 'x%s '%(len(units),)
		txt = wx.StaticText(self, -1, '%s%s'%(count_text, name))
		wsizer.Add(txt)
		
		if 'max_count' in proto:
			if 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)

			build_less = wx.Button(self, label="-", size=(20,20))
			build_less.units = units
			build_less.Bind(wx.EVT_LEFT_DOWN, self.on_cancel_build)
			wsizer.Add(build_less)
示例#16
0
文件: request.py 项目: bogolt/dclord
	def fleetMove(self, fleetId, to):
		act = self.act('move_fleet', pos('move_to', to)+val('fleet_id',fleetId))
		
		# save fleet info
		fleet = store.get_object('fleet', {'fleet_id':fleetId})
		
		speed, rng = store.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))
		u = store.get_user(fleet['user_id'])
		cur_turn = u['turn']
		
		store.add_pending_action(self.act_id, 'fleet', 'erase', {'fleet_id':fleetId})
		store.add_pending_action(self.act_id, 'flying_fleet', 'insert', {'x':to[0], 'y':to[1], 'user_id':self.user_id, 'id':fleetId, 'from_x':fleet['x'], 'from_y':fleet['y'], 'arrival_turn':turns + cur_turn})
		
		#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
示例#17
0
	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()
示例#18
0
	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()
示例#19
0
	def add_fleet(self, fleet):
		nm = ''
		if 'arrival_turn' in fleet:
			nm = '[%d] '%(fleet['arrival_turn'] - store.max_turn(),)
		nm += fleet['name']
		cp = wx.CollapsiblePane(self, label=nm, style=wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE)
		self.sizer.Add(cp)
		pane = cp.GetPane()
		
		u = store.get_user(fleet['user_id'])
		if u:
			owner_name = u['name']
		else:
			owner_name = '<unknown>'
		sizer = wx.BoxSizer(wx.VERTICAL)
		sizer.Add(wx.StaticText(pane, label='owner: %s'%(owner_name,)), 1, wx.EXPAND)

		speed, rng = store.get_fleet_speed_range(fleet['fleet_id'])
		if speed and rng:
			sizer.Add(wx.StaticText(pane, label='%0.2f / %0.2f'%(speed, rng)), 1, wx.EXPAND)

		#can we contrl the fleet?
		is_controlled = 'login' in u and u['login'] in config.users
		
		if is_controlled and rng >= 1 and (not 'in_transit' in fleet or fleet['in_transit']==0):
			jump_button = wx.ToggleButton(pane, label='jump')
			jump_button.fleet_id = fleet['fleet_id']
			sizer.Add(jump_button, 1, wx.EXPAND)
			
			self.Bind(wx.EVT_TOGGLEBUTTON, self.on_jump, jump_button)
		#else:
		#	print 'user %s not controllable'%(u,)
		
		for unit in store.get_fleet_units(fleet['fleet_id']):
			hbox = wx.BoxSizer(wx.HORIZONTAL)
			sizer.Add(hbox, 1, wx.EXPAND)
			
			proto = store.get_object('proto', {'proto_id':unit['proto_id']})
			if not proto:
				print 'Prototype not found for %s'%(unit,)
				continue
			obj_carp = int(unit['proto_id']), int(proto['carapace']), int(proto['color'])
			
			if is_controlled:
				planet = store.get_object('planet', {'x':self.coord[0], 'y':self.coord[1]})
				inhabited = False
				if planet and planet['user_id'] and int(planet['user_id']) > 0:
					inhabited = True
					
				# get unit actions ( colony, kill-people )
				if not inhabited:
					for action_type in [action.Action.COLONY_COLONISE, action.Action.ARC_COLONISE, action.Action.OUTPOST_COLONISE]:
						action_colonize = store.get_object('proto_action', {'proto_id':proto['proto_id'], 'proto_action_id':action_type})
						if action_colonize:
							c_action = store.get_object('action', {'unit_id':unit['unit_id']})
							if c_action:
								# already colonizing
								cancel_button = wx.Button(pane, label='Cancel colonize %s'%(action.get_colony_population(action_type)))
								cancel_button.cancel_action = u['user_id'], unit['unit_id'], c_action['cancel_id']
								self.Bind(wx.EVT_BUTTON, self.on_cancel_action, cancel_button)
								sizer.Add( cancel_button , 1, wx.EXPAND )
							else:
								colonize_button = wx.Button(pane, label='Colonize %s'%(action.get_colony_population(action_type)))
								colonize_button.action = action_type, unit['unit_id'], fleet['fleet_id'], self.coord, u['user_id']
								self.Bind(wx.EVT_BUTTON, self.on_store_action, colonize_button)
								sizer.Add( colonize_button , 1, wx.EXPAND )

				if inhabited and planet['user_id'] != u['user_id']:
					#TODO: check if our mult, or ally, and notify user about it
					action_kill_people = store.get_object('proto_action', {'proto_id':proto['proto_id'], 'proto_action_id':action.Action.KILL_PEOPLE})
					if action_kill_people:
						c_action = store.get_object('action', {'unit_id':unit['unit_id']})
						if c_action:
							# already colonizing
							cancel_button = wx.Button(pane, label='Cancel kill people')
							cancel_button.cancel_action = u['user_id'], unit['unit_id'], c_action['cancel_id']
							self.Bind(wx.EVT_BUTTON, self.on_cancel_action, cancel_button)
							sizer.Add( cancel_button , 1, wx.EXPAND )
						else:
							colonize_button = wx.Button(pane, label='Kill people')
							colonize_button.action = action.Action.KILL_PEOPLE, unit['unit_id'], fleet['fleet_id'], self.coord, u['user_id']
							self.Bind(wx.EVT_BUTTON, self.on_store_action, colonize_button)
							sizer.Add( colonize_button , 1, wx.EXPAND )

			img = image.get_image( int(unit['proto_id']), int(proto['carapace']), int(proto['color']) )
			
			if img:
				bitmap = wx.StaticBitmap(pane)
				bitmap.SetBitmap(img)
				hbox.Add(bitmap, 1, wx.EXPAND)
			#else:
			#	print 'image not found for unit %s, bc %s, carp %s, color %s'%(unit['unit_id'], int(unit['proto_id']), int(proto['carapace']), int(proto['color']) )

			name = proto['name']
			if not name:
				name = get_unit_name(int(proto['carapace']))
			hbox.Add(wx.StaticText(pane, label=name), 1, wx.EXPAND)

		border = wx.BoxSizer()
		border.Add(sizer, 1, wx.EXPAND|wx.ALL)
		pane.SetSizer(border)
		
		self.sizer.Layout()
		
		self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnPaneChanged, cp)
		cp.Expand()
		
		cp.Bind(wx.EVT_LEFT_DOWN, self.onFleetSelect)
		self.fleets[cp] = fleet
示例#20
0
	def onFlyHomeScouts(self, _):
				
		for acc in config.accounts():
			if not 'id' in acc:
				continue
			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 store.iter_objects_list('fleet', {'user_id':user_id}):
				#print 'found fleet %s'%(fleet,)
				# if fleet over empty planet - jump back home
				coord = get_coord(fleet)
				coord_filter = {'x':coord[0], 'y':coord[1]}
				planet = store.get_object('planet', coord_filter )
				#TODO: allow jump on all open-planets ( not only owned by user )
				coord_filter['user_id'] = user_id
				user_open_planet = store.get_object('open_planet', coord_filter )
				if user_open_planet:
					continue

				#print 'fleet %s not at home'%(fleet['id'],)
				units = []
				for unit in store.get_fleet_units(fleet['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]['unit_id']) in self.manual_control_units:
					continue

				proto = store.get_object('proto', {'proto_id':units[0]['proto_id']})
				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 store.iter_objects_list('open_planet', {'user_id':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.actions.add_action( action.ActionJump(user_id, fleet['fleet_id'], closest_planet ))
示例#21
0
	def onExploreGeoAll(self, _):
		'upload pending events on server'
		
		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():
			if not 'id' in acc:
				continue
			user_id = int(acc['id'])
				
			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 store.iter_objects_list('fleet', {'user_id':acc['id']} ):
				#print 'got fleet %s'%(fleet,)
				coord = get_coord(fleet)
				
				if coord in pl:
					pl[coord].add(fleet['fleet_id'])
					continue

				planet = store.get_object('planet', {'x':coord[0], 'y':coord[1]})
				#check holes and stars
				if not planet:
					continue
				
				# check if already explored
				if 'o' in planet and planet['o']:
					continue
				
				if not coord in pl:
					pl[coord] = set()
				pl[ coord ].add(fleet['fleet_id'])
				#print 'Add to exploration list planet %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 store.get_fleet_units(fleet_id):
						#print '%s %s unit %s'%(coord, fleet_id, unit)
						# ok unit
						bc = unit['proto_id']
						
						#for proto in db.prototypes(['id=%s'%(bc,)]):
						#	print 'proto %s'%(proto,)

						#type 1 probably geo explore
						action_geo_explore = store.get_object('proto_action',{'proto_id':bc, 'proto_action_id':request.RequestMaker.GEO_EXPLORE})
						if action_geo_explore:
							acts[coord] = unit['unit_id']
							break
					# no need to request more then one explore of a single planet
					if coord in acts:
						break

			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():
				fleet_unit = store.get_object('fleet_unit', {'unit_id':unit_id})
				self.actions.add_action(action.ActionStore(user_id, unit_id, fleet_unit['fleet_id'], coord, action.Action.GEO_EXPLORE))
				#self.pending_actions.explore_planet( coord, unit_id )
				at_least_one = True
			
			if at_least_one:
				self.perform_actions()
示例#22
0
文件: action.py 项目: bogolt/dclord
	def __init__(self, user_id, unit_id):
		Action.__init__(self, user_id)
		self.unit_id = unit_id
		self.queue_unit = store.get_object('garrison_queue_unit', {'unit_id':self.unit_id})
示例#23
0
文件: action.py 项目: bogolt/dclord
	def __init__(self, user_id, action_id):
		Action.__init__(self, user_id)
		self.action_id = action_id
		self.action = store.get_object('action', {'cancel_id':self.action_id})