def startGL(width, height): """ Load continent data and textures and configure settings for background colour, depth testing, blending and shading models. """ global allData, locationPositions # Load all numerical data for continents print(DATA_LOADING) allData = Continent.generateFullContinentList() print(DONE) # Load all textures print(TEXTURES_LOADING) loadTextureImages() initialiseAllTextures() print(DONE) setCurrentValue() setArrowPosition() setDisplayedContinentText() # Display setting configuration glClearColor(0, 0, 0, 0) glClearDepth(1) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) resizeWindow(width, height)
def from_config_file(path_to_file): new_territories = {} new_paths = [] new_continents = {} continent_colors = [ '#EF6C00', '#9E9D24', '#689F38', '#00ACC1', '#6D4C41', '#F06292' ] with open(path_to_file) as f: continent_count, territory_count = map(int, f.readline().split()) # read continents and their respective territories for i in range(continent_count): continent_name = f.readline().strip() continent_bonus, continent_territory_count = map( int, f.readline().split()) new_continent = Continent(continent_name, [], continent_bonus) new_continents[continent_name] = new_continent for _ in range(continent_territory_count): name = f.readline().strip() board_pos, size_on_board = f.readline().strip().split() new_territory = Territory(name, board_pos, size_on_board, continent_colors[i]) new_continent.add_territory(new_territory) new_territories[name] = new_territory f.readline() # read territories and their neighbors for _ in range(territory_count): from_territory_name = f.readline().strip() from_territory = new_territories[from_territory_name] neighbor_count = int(f.readline()) for _ in range(neighbor_count): to_territory_name = f.readline().strip() to_territory = new_territories[to_territory_name] from_territory.add_neighbor(to_territory) new_path = Path(from_territory, to_territory) new_paths.append(new_path) f.readline() return Board(new_territories, new_paths, new_continents)
def add_moons(self): """ Generate a list of moons """ if not hasattr(self, 'moons'): self.moons = [] # Note that mooncount is a planet stat while len(self.moons) < self.mooncount['count']: self.moons.append(Continent(self.redis, {'planet': self}))
def __init__(self, num_continents, isp_per_continents, cities_per_isp, total_power_per_isp): self.continent_list = [] self.graph = Graph() for i in range(num_continents): self.continent_list.append( Continent(self.graph, isp_per_continents, cities_per_isp, total_power_per_isp)) if i != 0: self.continent_list[i].connect_continent( self.graph, self.continent_list[i - 1], 2, 2, 2, 2)
def form_continents(self): """ Continent_map dict holds all the land tile coords as keys to which continent they belong to. Continents holds the id #'s as keys to the corresponding continent dicts """ masses = {} mass_map = {} # get all ground tiles on map. Currently map is ground made from cellular automata, # water flood filled as a surrounding ocean, and holder tiles in any gaps that ocean # flood fill didn't reach - landlocked empty space. unclaimed_ground = self.find_ground() _id = 0 while unclaimed_ground: _id += 1 # Continent dict has 'id'= id#, 'points'= list of tiles, 'size'=num of tiles mass = {'id': _id, 'points': []} start_point = choice(unclaimed_ground) continent_points = self.flood_continent(start_point) for point in continent_points: try: unclaimed_ground.remove(point) except ValueError: pass mass['points'].append(point) mass_map[point] = _id mass['size'] = len(mass['points']) masses[_id] = mass c, i, d = self.sort_continents_islands_depths(masses) for _id in c: new = Continent(self, masses[_id]) self.continents[_id] = new self.landmass_list.append(new) for _id in i: self.islands[_id] = masses[_id] for _id in d: depth = masses[_id]['points'] self.add_tiles(depth, 'water') self.remove_diagonals('water', 'ground') self.adjust_continents()
def add_continents(self): """ Generate the continents for this planet""" # Ensure that we have a continents array if not hasattr(self, 'continents'): self.continents = [] # Ensure that we have a target number of continents if not hasattr(self, 'continentcount'): self.continentcount = random.randint(1, 5) while len(self.continents) < self.continentcount: self.continents.append(Continent(self.redis, {'planet': self}))
def createAllImages(continent): # Get years, data type getters and data type names directly from # Continent without an object being made from it years = Continent.getYearList() dataTypeFunctions = [1, 2, 3, 4] dataTypeNames = Continent.getStatisticNames() originalName = "maps/" + continent.getName() + "Blue.bmp" for f in dataTypeFunctions: valuesList = continent.getMedianValuesList(f) print(dataTypeNames[f - 1], ":", valuesList) gradient, intercept = ContinentImageCreator.calculateColourGradientAndIntercept( continent, f) for y in years: savedName = "maps/" + continent.getName() + dataTypeNames[ f - 1] + y + ".bmp" value = continent.getMedianValue(y, f) colourValue = ContinentImageCreator.calculateGreenChannel( value, gradient, intercept) ContinentImageCreator.generateImage(colourValue, originalName, savedName)
def initializeCountries( filename ): #reads in csv file with countries, creates them and continents. Adds them to worldstats with open(filename) as csvfile: readCSV = csv.reader(csvfile, delimiter=';') countriesOfContinent = list() #print("loading counties\n======================================================================") for row in readCSV: if row[0] == "#": #first time this gets skipped because it lists the countries first continentName = row[1] continentBonus = int(row[2]) continent = Continent(continentName, continentBonus, countriesOfContinent) worldstats.instance.addContinent( continent ) #adding them to worldstats so it's available to every class with an instance countriesOfContinent = [] else: countryName = row[0] #print("reading " + countryName) xCoordinaat = int(row[1]) yCoordinaat = int(row[2]) country = Country(countryName, xCoordinaat, yCoordinaat) countriesOfContinent.append(country) with open(filename) as csvfile: readCSV = csv.reader(csvfile, delimiter=';') for row in readCSV: #iterate csv again for adding references to neighbours (countries had to be created first) if row[0] != "#": country = worldstats.instance.getCountryByName(row[0]) #print("country:", country) i = 3 while i != 9: if row[i] != "": neighbour = worldstats.instance.getCountryByName( row[i]) #string to country object reference country.addNeighbour(neighbour) i += 1
def __init__(self): self.territories = [] self.continents = [] self.numTerritories = 0 # Lets create a list for all the continents # information from https://en.wikipedia.org/wiki/Risk_(game) self.continents.append( Continent([ "Congo", "East Africa", "Egypt", "Madagascar", "North Africa", "South Africa" ], 3, "Africa", self)) self.continents.append( Continent([ "Alaska", "Alberta", "Central America", "Eastern United States", "Greenland", "Northwest Territory", "Ontario", "Quebec", "Western United States" ], 5, "North America", self)) self.continents.append( Continent(["Venezuela", "Brazil", "Peru", "Argentina"], 2, "South America", self)) self.continents.append( Continent([ "Afghanistan", "China", "India", "Irkutsk", "Japan", "Kamchatka", "Middle East", "Mongolia", "Siam", "Siberia", "Ural", "Yakutsk" ], 7, "Asia", self)) self.continents.append( Continent([ "Great Britain", "Iceland", "Northern Europe", "Scandinavia", "Southern Europe", "Ukraine", "Western Europe" ], 5, "Europe", self)) self.continents.append( Continent([ "Eastern Australia", "Indonesia", "Papa New Guinea", "Western Australia" ], 2, "Australia", self)) # we need to hard code all the neighbors so looking at the map and wiki page the following is created. # Territory numbers # 1: Congo 16: Argentina 31: Yakutsk # 2: East Africa 17: Brazil 32: Great Britain # 3: Egypt 18: Peru 33: Iceland # 4: Madagascar 19: Venezuela 34: Northern Europe # 5: North Africa 20: Afghanistan 35: Scandinavia # 6: South Africa 21: China 36: Southern Europe # 7: Alaska 22: India 37: Ukraine (Eastern Europe, Russia) # 8: Alberta 23: Irkutsk 38: Western Europe # 9: Central America 24: Japan 39: Eastern Australia # 10: Eastern United States 25: Kamchatka 40: Indonesia # 11: Greenland 26: Middle East 41: New Guinea # 12: Northwest Territory 27: Mongolia 42: Western Australia # 13: Ontario (Central Canada) 28: Siam # 14: Quebec (Eastern Canada) 29: Siberia # 15: Western United States 30: Ural # Africa self.continents[0].territories[0].neighbors = [2, 5, 6] # Congo self.continents[0].territories[1].neighbors = [1, 3, 4, 5, 26] #East Africa self.continents[0].territories[2].neighbors = [2, 5, 36, 26] # Egypt self.continents[0].territories[3].neighbors = [2, 6] # Madagascar self.continents[0].territories[4].neighbors = [1, 2, 3, 17, 36, 38] # North Africa self.continents[0].territories[5].neighbors = [1, 2, 4] # South Africa # North america self.continents[1].territories[0].neighbors = [8, 12, 25] # Alaska self.continents[1].territories[1].neighbors = [7, 12, 13, 15] # Alberta self.continents[1].territories[2].neighbors = [15, 10, 19] # Central America self.continents[1].territories[3].neighbors = [ 9, 15, 13, 14 ] # Eastern United States self.continents[1].territories[4].neighbors = [12, 13, 14, 33] # Greenland self.continents[1].territories[5].neighbors = [7, 8, 13, 11 ] # Northwest Territory self.continents[1].territories[6].neighbors = [8, 15, 10, 14, 11, 12] # Ontario self.continents[1].territories[7].neighbors = [10, 13, 11] # Quebec self.continents[1].territories[8].neighbors = [ 9, 10, 8, 13 ] # Western United States # South America self.continents[2].territories[0].neighbors = [17, 18] # Venezuela self.continents[2].territories[1].neighbors = [16, 18, 19, 5] # Brazil self.continents[2].territories[2].neighbors = [16, 17, 19] # Peru self.continents[2].territories[3].neighbors = [18, 17, 9] # Argentine # Asia self.continents[3].territories[0].neighbors = [21, 22, 26, 30, 37] # Afghanistan self.continents[3].territories[1].neighbors = [20, 22, 28, 27, 29, 30] # China self.continents[3].territories[2].neighbors = [20, 21, 26, 28] # India self.continents[3].territories[3].neighbors = [29, 27, 25, 31] # Irkutsk self.continents[3].territories[4].neighbors = [27, 25] # Japan self.continents[3].territories[5].neighbors = [31, 23, 27, 24, 7] # Kamchatka self.continents[3].territories[6].neighbors = [20, 22, 37, 2, 3] # Middle East self.continents[3].territories[7].neighbors = [24, 21, 29, 25, 23] # Mongolia self.continents[3].territories[8].neighbors = [21, 22, 40] # Siam self.continents[3].territories[9].neighbors = [30, 21, 23, 31, 27] # Siberia self.continents[3].territories[10].neighbors = [20, 21, 29, 37] # Ural self.continents[3].territories[11].neighbors = [29, 23, 25] # Yakitsk # Europe self.continents[4].territories[0].neighbors = [33, 35, 34, 38] # Great Britain self.continents[4].territories[1].neighbors = [32, 35, 11] # Iceland self.continents[4].territories[2].neighbors = [32, 35, 37, 36, 38] # Northern Europe self.continents[4].territories[3].neighbors = [37, 32, 33, 34] # Scandinavia self.continents[4].territories[4].neighbors = [38, 34, 37, 3, 26, 5] # Southern Europe self.continents[4].territories[5].neighbors = [35, 34, 36, 20, 26, 30] # Ukraine self.continents[4].territories[6].neighbors = [32, 34, 36, 5] # Western Europe # Australia self.continents[5].territories[0].neighbors = [42, 41] # Eastern Australia self.continents[5].territories[1].neighbors = [42, 41, 28] # Indonesia self.continents[5].territories[2].neighbors = [42, 40, 39] # New Guinea self.continents[5].territories[3].neighbors = [39, 41, 40] # Western Australia
# Continent without an object being made from it years = Continent.getYearList() dataTypeFunctions = [1, 2, 3, 4] dataTypeNames = Continent.getStatisticNames() originalName = "maps/" + continent.getName() + "Blue.bmp" for f in dataTypeFunctions: valuesList = continent.getMedianValuesList(f) print(dataTypeNames[f - 1], ":", valuesList) gradient, intercept = ContinentImageCreator.calculateColourGradientAndIntercept( continent, f) for y in years: savedName = "maps/" + continent.getName() + dataTypeNames[ f - 1] + y + ".bmp" value = continent.getMedianValue(y, f) colourValue = ContinentImageCreator.calculateGreenChannel( value, gradient, intercept) ContinentImageCreator.generateImage(colourValue, originalName, savedName) if __name__ == "__main__": continentList = Continent.generateFullContinentList() print("Creating images...") for c in continentList: print(c.getName(), ":") print([x.getName() for x in c.getCountries()]) ContinentImageCreator.createAllImages(c) print("Done!")