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))
def draw_city(self, cursor, city_id): city_is_special = False # Handles the_city = self.city_dict[city_id] the_team = self.team_dict[the_city.team] # Test for 1 icon image_size = map_data.map_image_size(the_city.size) # Check it's within the picture size of the map if (the_city.x - image_size/2) < self.left: return if (the_city.x + image_size/2) > self.right: return if (the_city.y - image_size/2) < self.top: return if (the_city.y + image_size/2) > self.bottom: return output = {} # System type stuff output['pixel_x'] = (the_city.x - self.left) * 2.5 - (image_size/2.0) output['pixel_y'] = (the_city.y - self.top) * 2.5 - (image_size/2.0) # Owner output['team.id'] = the_team.id output['team.name'] = the_team.name # Key stats output['id'] = the_city.id output['name'] = the_city.name output['x'] = the_city.x output['y'] = the_city.y output['port'] = the_city.port output['nomadic'] = the_city.nomadic output['founded'] = the_city.founded # Walls output['harbour_walls'] = False if 18 in the_city.buildings_amount and the_city.buildings_amount[18] > 0:# Harbour walls id = 18 output['harbour_walls'] = True output['wall_count'] = 0 if the_city.walls != []: if len(the_city.walls) > 1: if output['harbour_walls']: output['wall_count'] = len(the_city.walls) - 1 else: output['wall_count'] = len(the_city.walls) elif not output['harbour_walls']: output['wall_count'] = len(the_city.walls) # Supplies and Terrain output['supplies'] = the_city.supplies output['terrain'] = map_data.terrain[mapper_q.get_terrain(cursor, the_city.x, the_city.y)].title() city_loc = (the_city.x - (the_city.x % 10), the_city.y - (the_city.y % 10)) output['continent'] = path_f.get_map_continent_tiles(cursor).get(city_loc, -1) # Overlap output['supplies'] = the_city.overlap # Population if the_city.team not in self.personalise: output['size'] = common.napprox(the_city.size) output['slaves'] = common.napprox(the_city.slaves) else: output['size'] = the_city.size output['population'] = the_city.population output['slaves'] = the_city.slaves # Artefact artefact_count = 0 if city_id in self.cities_with_artefact: for a, the_artefact in self.artefact_dict.items(): if the_artefact.city == city_id: artefact_count += 1 output['artefacts'] = artefact_count # Wonder output['wonder'] = "None" if city_id in self.cities_with_wonder: for w, the_wonder in self.wonder_dict.items(): if the_wonder.city == city_id: if the_wonder.completed: output['wonder'] = "Complete" else: output['wonder'] = "Incomplete" # Description output['description'] = the_city.description # # Info only for the team map # if the_city.team in self.personalise: # walls = [] # buildings = [] # in_progress = [] # # for b, a in the_city.buildings_amount.items(): # if self.building_dict[b].wall == True: walls.append(self.building_dict[b].name) # if self.building_dict[b].wall != True: buildings.append(self.building_dict[b].name) # # for b, p in the_city.buildings.items(): # if p > 0: # in_progress.append(self.building_dict[b].name) # # if len(buildings) > 0: # city_title.append("<br /><strong>Buildings</strong>: %s" % ", ".join(buildings)) # # if len(walls) > 0: # city_title.append("<br /><strong>Walls</strong>: %s" % ", ".join(walls)) # # if len(in_progress) > 0: # city_title.append("<br /><strong>In progress</strong>: %s" % ", ".join(in_progress)) # Now return it return output