def create_tilelist(self, raw_sc2_data): """ Stores information about a tile. Args: raw_sc2_data (bytes): Uncompressed .sc2 file. """ for row in range(self.city_size): for col in range(self.city_size): tile = Tile(self.traffic, self.pollution, self.value, self.crime, self.police, self.fire, self.density, self.growth, self.labels) tile_idx = row * self.city_size + col tile_coords = (row, col) tile.coordinates = tile_coords if self.debug: print(f"index: {tile_idx} at {tile_coords}") # First start with parsing the terrain related features. altm = raw_sc2_data["ALTM"][tile_idx * 2:tile_idx * 2 + 2] xter = raw_sc2_data["XTER"][tile_idx:tile_idx + 1] altm_bits = int_to_bitstring(parse_uint16(altm), 16) tile.is_water = bool(int(altm_bits[7:8], 2)) tile.altitude_unknown = int(altm_bits[8:10], 2) tile.altitude = int(altm_bits[11:], 2) tile.terrain = parse_uint8(xter) if self.debug: print(f"altm: {altm_bits}, xter: {tile.terrain}") tile.altidue_tunnel = int(altm_bits[0:7], 2) # Next parse city stuff. # skip self.building for now, it's handled specially. xzon = raw_sc2_data["XZON"][tile_idx:tile_idx + 1] xzon_bits = int_to_bitstring(parse_uint8(xzon), 8) tile.zone_corners = xzon_bits[0:4] tile.zone = int(xzon_bits[4:], 2) xund = raw_sc2_data["XUND"][tile_idx:tile_idx + 1] tile.underground = parse_uint8(xund) if self.debug: print( f"zone: {tile.zone}, corners: {tile.zone_corners}, underground: {tile.underground}" ) # text/signs xtxt = raw_sc2_data["XTXT"][tile_idx:tile_idx + 1] tile.text_pointer = parse_uint8(xtxt) # bit flags xbit = raw_sc2_data["XBIT"][tile_idx:tile_idx + 1] tile.bit_flags = BitFlags(parse_uint8(xbit)) if self.debug: print( f"text pointer: {tile.text_pointer}, bit flags: {tile.bit_flags}" ) # Add the new tile to the tilelist self.tilelist[(row, col)] = tile
def parse_budget(self, raw_misc_data): """ Parses the budget data segment from MISC into budget data. Args: raw_misc_data (bytes): Raw segment from Misc """ # Ordinances ordinance_raw = raw_misc_data[0x0FA0:0x0FA0 + 4] self.ordinance_flags = int_to_bitstring(parse_uint32(ordinance_raw)) # bonds start_offset = 0x0610 bonds_len = 50 * 4 self.bonds = bytes_to_int32s(raw_misc_data[start_offset:start_offset + bonds_len]) # various sub-budgets sub_len = 27 * 4 for name, start_offset in self._sub_budget_indices.items(): chunk = raw_misc_data[start_offset:start_offset + sub_len] sub_budget = deepcopy(self._blank_budget) chunk_data = bytes_to_int32s(chunk) for idx, k in enumerate(self._blank_budget): sub_budget[k] = chunk_data[idx] self.budget_items[name] = sub_budget
def __str__(self): s = f"Tile at {self.coordinates}\n" s += f"Altitude:\n\ttunnel: {self.altitude_tunnel}, water: {self.is_water}, unknown: {self.altitude_unknown}, altitude: {self.altitude}\n" terr = int_to_bitstring(self.terrain) s += f"Terrain: {terr}\n" # City stuff try: b_id = self.building.building_id except: b_id = "None" s += f"Buildings:\n\tid: {b_id}, corners {self.zone_corners}, zone: {self.zone}, underground: {self.underground}\n" # text/signs sign_text = '' if self.text_pointer: sign_text = f", Sign: \"{self.text}\"" s += f"Text pointer: {self.text_pointer}{sign_text}\n" # bit flags s += f"Flags: {self.bit_flags}\n" # minimaps/simulation stuff s += f"Minimap:\n\tTraffic: {self.traffic}, pollution: {self.pollution}, value: {self.value}, crime: {self.crime}, police: {self.police}, fire: {self.fire}, density: {self.density}, growth: {self.growth}." return s