Пример #1
0
	def prep_for_oh(self):
		"""Runs a set of prep functions for the OH"""
		
		self.teams()
		team_q.mass_get_team_spells(self.cursor, self._teams)
		team_q.mass_get_team_techs(self.cursor, self._teams)		
		# team_q.mass_get_team_resources(self.cursor, self._teams)
		self.mass_get_team_resources()
		
		self.buildings()
		self.cities()
		city_q.mass_get_city_buildings(self.cursor, self._cities)
		city_q.mass_get_city_artefacts(self.cursor, self._cities)
		city_q.mass_get_city_wonders(self.cursor, self._cities)
		
		self.armies()
		# squad_q.mass_get_squads(self.cursor, self._armies)
		self.mass_get_army_squads()
		
		self.units()
		unit_q.mass_get_unit_equipment(self.cursor, self._units)
		
		for k, v in self._buildings.items():
			if v.upgrades > -1:
				if v.upgrades not in self._building_requirements:
					self._building_requirements[v.upgrades] = []
				
				self._building_requirements[v.upgrades].append(k)
Пример #2
0
	def prep_for_orders(self):
		"""Runs a set of prep functions for orders"""
		# player_q.mass_get_player_powers(self.cursor, self._players)
		mapper_q.get_terrain(self.cursor, 0, 0)
		
		self.teams()
		# team_q.mass_get_team_deities(self.cursor, self._teams)
		team_q.mass_get_team_spells(self.cursor, self._teams)
		team_q.mass_get_team_techs(self.cursor, self._teams)
		# team_q.mass_get_team_resources(self.cursor, self._teams)
		self.mass_get_team_resources()
		team_q.mass_get_team_evolutions(self.cursor, self._teams)
		
		self.buildings()
		self.cities()
		city_q.mass_get_city_buildings(self.cursor, self._cities)
		# city_q.mass_get_city_artefacts(self.cursor, self._cities)
		# city_q.mass_get_city_wonders(self.cursor, self._cities)
		
		# squad_q.mass_get_squads(self.cursor, self._armies)
		
		unit_q.mass_get_unit_equipment(self.cursor, self._units)
		
		for k, v in self._buildings.items():
			if v.upgrades > -1:
				if v.upgrades not in self._building_requirements:
					self._building_requirements[v.upgrades] = []
				
				self._building_requirements[v.upgrades].append(k)
Пример #3
0
	def __init__(self, cursor):
		super(Spy_world, self).__init__(cursor)
		
		# Spy specific things
		self._operatives_in_area = {}
		self._operatives_in_city = {}
		self._cities_in_area = {}
		self._armies_in_area = {}
		self._armies_by_base = {}
		self._diff_cache = {}
		
		# Prep for spy reports
		# player_q.mass_get_player_powers(self.cursor, self._players)
		# mapper_q.get_terrain(self.cursor, 0, 0)
		
		self.teams()
		# team_q.mass_get_team_deities(self.cursor, self._teams)
		# team_q.mass_get_team_spells(self.cursor, self._teams)
		team_q.mass_get_team_techs(self.cursor, self._teams)
		# team_q.mass_get_team_resources(self.cursor, self._teams)
		team_q.mass_get_team_evolutions(self.cursor, self._teams)
		
		self.buildings()
		self.cities()
		city_q.mass_get_city_buildings(self.cursor, self._cities)
		# city_q.mass_get_city_artefacts(self.cursor, self._cities)
		# city_q.mass_get_city_wonders(self.cursor, self._cities)
		
		self.armies()
		squad_q.mass_get_squads(self.cursor, self._armies)
		
		self.units()
		unit_q.mass_get_unit_equipment(self.cursor, self._units)
Пример #4
0
	def prep_for_ti(self):
		self.players()
		player_q.mass_get_player_powers(self.cursor, self._players)
		
		self.teams()
		team_q.mass_get_team_deities(self.cursor, self._teams)
		team_q.mass_get_team_spells(self.cursor, self._teams)
		team_q.mass_get_team_techs(self.cursor, self._teams)
		team_q.mass_get_team_stats(self.cursor, self._teams, common.current_turn())
		team_q.mass_get_team_stats(self.cursor, self._teams, common.current_turn()-1)
		team_q.mass_get_team_stats(self.cursor, self._teams, common.current_turn()-2)
		
		self.cities()
		city_q.mass_get_city_buildings(self.cursor, self._cities)
		city_q.mass_get_city_artefacts(self.cursor, self._cities)
		city_q.mass_get_city_wonders(self.cursor, self._cities)
		
		self.armies()
		# squad_q.mass_get_squads(self.cursor, self._armies)
		self.mass_get_army_squads()
		self.mass_get_army_monsters()
		
		self.units()
		unit_q.mass_get_unit_equipment(self.cursor, self._units)
Пример #5
0
def main(cursor, options):
	the_world = world.World(cursor)
	team_dict = the_world.teams()
	
	team_list = []
	
	# Work out our team
	try:
		t = options.team
		
		if t != "":
			for t, the_team in team_dict.items():
				if the_team.name.lower() == options.team.lower():
					team_list = [t]
			
			if team_list == []:
				raise Exception()
		else:
			raise Exception()
	except Exception as e:
		team_list = [t for t in team_dict.keys() if (team_dict[t].active and not team_dict[t].ir)]
	
	# Some caching stuff
	the_world.cities()
	the_world.armies()
	the_world.players()
	the_world.units()
	
	player_q.mass_get_player_powers(cursor, the_world._players)
	
	team_q.mass_get_team_deities(cursor, the_world._teams)
	team_q.mass_get_team_spells(cursor, the_world._teams)
	team_q.mass_get_team_techs(cursor, the_world._teams)
	team_q.mass_get_team_resources(cursor, the_world._teams)
	team_q.mass_get_team_evolutions(cursor, the_world._teams)
	
	city_q.mass_get_city_buildings(cursor, the_world._cities)
	city_q.mass_get_city_artefacts(cursor, the_world._cities)
	city_q.mass_get_city_wonders(cursor, the_world._cities)
	
	unit_q.mass_get_unit_equipment(cursor, the_world._units)
	
	squad_q.mass_get_squads(cursor, the_world._armies)
	
	print("Caches setup")
	
	t_output = []
	for t in team_list:
		the_team = the_world._teams[t]
		
		headers = ti_f.headers(the_team)
		footers = ti_f.footers(the_team)
		js = ti_f.javascript(the_team)
		
		try:
			team_start = time.time()
			
			ti_output = ti_f.make_ti(cursor, the_world, the_team)
			
			output = "".join([js, ti_output])
			
			md5_name = team_f.team_hash(the_team.name)
			try:
				f = open('%sti_%s.html' % (common.data['cache_path'], md5_name), 'w')
				f.write(output)
				f.close()
			except Exception as e:
				pass
			
			t_output.append(output)
			
			print("Made for %s in %s" % (the_world._teams[t].name, round(time.time() - team_start, 3)))
		except Exception as e:
			print("Error in making TI for team '%s'" % the_world._teams[t].name)
			raise
		
	
	return "".join(t_output)
Пример #6
0
def check_available(cursor, verbose):
	the_world = world.World(cursor)
	
	unit_dict				= the_world.units()
	unit_q.mass_get_unit_equipment(cursor, the_world._units)
	
	equipment_dict			= the_world.equipment()
	city_dict				= the_world.cities()
	terrain_tuples			= mapper_q.get_all_terrain(cursor)
	map_continent_tiles		= path_f.get_map_continent_tiles(cursor)
	
	# First we need to get the continents and terrains of each team
	team_dict = {}
	
	if verbose:
		it = cli_f.progressbar(city_dict.items(), "military_check.check_available: ", 40, with_eta = True)
	else:
		it = city_dict.items()
	
	for city_id, the_city in it:
		if the_city.dead > 0: continue
		if the_city.team not in team_dict: team_dict[the_city.team] = Team_lands(the_city.team)
		
		city_loc = (the_city.x - (the_city.x % 10), the_city.y - (the_city.y % 10))
		
		city_terrain, city_continent = 0, 0
		
		if city_loc in terrain_tuples: city_terrain = terrain_tuples[city_loc]
		if city_loc in map_continent_tiles: city_continent = map_continent_tiles[city_loc]
		
		team_dict[the_city.team].add_city(city_continent, city_terrain)
	
	# Next we'd get the techs too if possible
	
	
	# Now we go through each unit and find out if it's availiable
	not_available			= []
	for unit_id, the_unit in unit_dict.items():
		if the_unit.team < 2: continue# Skip units that are for all teams
		
		# If a team doesn't exist in the dictionary then it's because they've no cities
		if the_unit.team not in team_dict:
			# not_available.append(unit_id)
			continue
		
		checked_unit = False
		the_team = team_dict[the_unit.team]
		
		for e in the_unit.equipment:
			if checked_unit: continue
			the_equipment = equipment_dict[e]
			
			if the_equipment.continent > 0:
				if the_equipment.terrain > 0:
					# Need both
					if not the_team.check_matrix(the_equipment.continent, the_equipment.terrain):
						not_available.append(unit_id)
						checked_unit = True
				else:
					# Just continent
					if the_equipment.continent not in the_team.continents:
						not_available.append(unit_id)
						checked_unit = True
			else:
				if the_equipment.terrain > 0:
					# Just terrain
					if the_equipment.terrain not in the_team.terrain:
						not_available.append(unit_id)
						checked_unit = True
			
			# Now we can check tech level too
				
			# self.add_field("terrain",				"int")# 0 = Any terrain
			# self.add_field("tech",					"int")# 0 = No tech needed
			# self.add_field("tech_level",			"int")# 0 = No tech needed
	
	query = """UPDATE units SET available = True;"""
	try: cursor.execute(query)
	except Exception as e:
		raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
	
	if not_available != []:
		query = """UPDATE units
			SET available = False
				WHERE id IN (%s);""" % "".join([str(u) for u in not_available])
		
		try: cursor.execute(query)
		except Exception as e:
			raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
Пример #7
0
def check_unit_categories(cursor, verbose):
	queries = []
	unit_dict = unit_q.get_all_live_units(cursor)
	equipment_dict = equipment_q.get_all_equipment(cursor)
	
	unit_q.mass_get_unit_equipment(cursor, unit_dict)
	
	# Default
	query = """UPDATE units SET crew = 1;"""
	try: cursor.execute(query)
	except Exception as e:
		raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
	
	if verbose:
		it = cli_f.progressbar(unit_dict.items(), "military_check.check_unit_categories: ", 40, with_eta = True)
	else:
		it = unit_dict.items()
	
	for unit_id, the_unit in it:
		the_unit.transport = 0
		the_unit.move_type = 0
		the_unit.move_speed = 0
		the_unit.crew = 1
		
		the_unit.weapon_cat = 0
		the_unit.armour_cat = 0
		the_unit.move_cat = 0
		the_unit.training_cat = 0
		
		ranged = False
		melee = False
		
		# Loop through all it's equipment
		for e in the_unit.equipment:
			the_e = equipment_dict[e]
			
			if the_e.range > 2:
				ranged = True
			elif the_e.range == 0:
				melee = True
			
			the_unit.transport = max(the_e.transport, the_unit.transport)
			
			the_unit.crew = max(the_unit.crew, the_e.crew)
			
			# the_unit.move_type = 0
			# the_unit.move_speed = 0
			# the_unit.type_cat = 0
			
			the_unit.armour_cat = max(the_unit.armour_cat, the_e.armour_cat)
			the_unit.move_cat = max(the_unit.move_cat, the_e.move_cat)
			the_unit.training_cat = max(the_unit.training_cat, the_e.training_cat)
			
			if the_e.category == equipment.cat_list.index("Boat hull"):
				the_unit.type_cat = unit.categories.index("Ship")
			elif the_e.category == equipment.cat_list.index("Balloon"):
				the_unit.type_cat = unit.categories.index("Airship")
			else:
				pass
		
		# Work out categories
		if ranged and melee:
			the_unit.weapon_cat = unit.weapon_categories.index("Melee and Ranged")
		elif ranged and not melee:
			the_unit.weapon_cat = unit.weapon_categories.index("Ranged")
		elif melee and not ranged:
			the_unit.weapon_cat = unit.weapon_categories.index("Melee")
		else:
			the_unit.weapon_cat = unit.weapon_categories.index("Neither")
		
		# Query
		queries.append("""UPDATE units SET
			transport = {transport}, move_type = {move_type}, move_speed = {move_speed}, crew = {crew},
			type_cat = {type_cat}, weapon_cat = {weapon_cat}, armour_cat = {armour_cat}, move_cat = {move_cat}, training_cat = {training_cat}
				WHERE id = {id};""".format(
			transport = the_unit.transport,
			move_type = the_unit.move_type,
			move_speed = the_unit.move_speed,
			crew = the_unit.crew,
			type_cat = the_unit.type_cat,
			weapon_cat = the_unit.weapon_cat,
			armour_cat = the_unit.armour_cat,
			move_cat = the_unit.move_cat,
			training_cat = the_unit.training_cat,
			id = the_unit.id,
		))
	
	database.query(cursor, queries)