def __init__(self, mapFileName, cm=None, numPlayers = None, AIPlayers = None, seed = None): super(Map, self).__init__() self.cm = cm self.batchableNode = BatchableNode() self.batchableNode.position = 0,0 self.add(self.batchableNode,z=VERTEX_Z) # Initiliaze variables - these will be set in parse_map_file. self.vertexPositions = {} self.edgePositions = defaultdict( list) # key: vid of one end, v: vid of other end self.AS = {} # we can get list of vertices from here self.cores = {} # k: just the cores self.vertices = {} # k: all vertices and cores self.edges = [] # list of all edges self.startingUnits = defaultdict(lambda: defaultdict(list)) self.startingResearch = defaultdict(list) self.availResearch = [] self.w = - 1 # Width of map in terms of num of cells. set in parse_map_file self.h = - 1 # Height of map in terms of num of cells. set in parse_map_file self.players = [] # list of pids self.AIPlayers = [] self.pid = 0 if mapFileName == "random": # Generate a random map. Creates a map and writes it to the /maps/ directory. Returns the file name. # Set the seed. random.seed(seed) # Map Dimensions numRows = int(random.randint(6 * numPlayers, 14 * numPlayers)) # if 2 players, min of 12x12, max of 28x28 numCols = int(random.randint(6 * numPlayers, 14 * numPlayers)) # Number of ASes numASes = int(math.ceil((numCols * numRows) / 140.0)) # If 2 players, min of 2 ASes, max of 6. # Verts per AS minVertsPerAS = 2 maxVertsPerAS = 4 playerStartUnits = {0:[],1:[]} playerResearch = {0:[],1:[]} maxCoresPerAS = 2 mapFileName = self.generate_random_map(numPlayers, numCols, numRows, playerStartUnits, playerResearch, minVertsPerAS, maxVertsPerAS, numASes, maxCoresPerAS, AIPlayers, seed) # Parses the map file and sets all relevant information. self.parse_map_file(mapFileName) self.minimap = None # Starts as None. Eventually stores the instance of MiniMap built off this Map (happens in controller)
def getFakeObject(self, position, width = 2, height = 2): obj = BatchableNode() obj.cshape = cm.AARectShape(position, width // 2,height // 2) return obj