コード例 #1
0
ファイル: main_frame.py プロジェクト: bogolt/dclord
	def calculate_route(self, fleet, dest_point):
		
		open_planets = store.get_objects_list('open_planet', {'user_id':fleet['user_id']})
		start_point = int(fleet['x']), int(fleet['y'])
		
		spd,rng = store.get_fleet_speed_range(fleet['fleet_id'])
		return algorithm.route_find(fleet, rng, dest_point)
コード例 #2
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
コード例 #3
0
ファイル: planet_window.py プロジェクト: bogolt/dclord
	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
コード例 #4
0
ファイル: main_frame.py プロジェクト: bogolt/dclord
	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