def __add_filler_blocks(self, rect: Rect, matrix: List[List], background_matrix: List[List]) -> None: """Add blocks to all unfilled places in the matrix and to the background matrix""" for row_i in range(int(rect.height / con.BLOCK_SIZE.height)): for col_i in range(int(rect.width / con.BLOCK_SIZE.width)): block_x_coord = int(rect.left / con.BLOCK_SIZE.width) + col_i block_y_coord = int(rect.top / con.BLOCK_SIZE.height) + row_i block = matrix[row_i][col_i] # determine biome based on coordinate biome_liklyhoods = self.__biome_liklyhoods_from_point( block_x_coord * con.BLOCK_SIZE.width, block_y_coord * con.BLOCK_SIZE.height) biome = choices(list(biome_liklyhoods.keys()), list(biome_liklyhoods.values()), k=1)[0] if block is None: filler_likelyhoods = biome.get_filler_lh_at_depth( block_y_coord) filler = choices(list(filler_likelyhoods.keys()), list(filler_likelyhoods.values()), k=1)[0] matrix[row_i][col_i] = block_util.MCD(filler) # reget the biome to get slightly different front and backgrounds biome = choices(list(biome_liklyhoods.keys()), list(biome_liklyhoods.values()), k=1)[0] background_likelyhoods = biome.get_background_lh_at_depth( block_y_coord) background_mat = choices(list(background_likelyhoods.keys()), list(background_likelyhoods.values()), k=1)[0] background_matrix[row_i][col_i] = block_util.MCD( background_mat)
class VaultStructure(StructurePart): FORM_DEFINITION: ClassVar[List[List[Union[ materials.MaterialCollection, str]]]] = [ [ IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection ], [ IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection ], [ IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection ], [ IronSheetCollection, IronSheetCollection, IronSheetCollection, block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), IronSheetCollection, IronSheetCollection, IronSheetCollection ], [ IronSheetCollection, IronSheetCollection, IronSheetCollection, VaultChestCollection, VaultChestCollection, VaultChestCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection ], [ IronSheetCollection, IronSheetCollection, IronSheetCollection, VaultChestCollection, VaultChestCollection, VaultChestCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection ], [ IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection ], [ IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection ], [ IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection, IronSheetCollection ], ] CONNECTION_DIRECIONS: ClassVar[Tuple[List[Tuple[str, int]], List[Tuple[str, int]], List[Tuple[str, int]], List[Tuple[str, int]]]] = ([], [], [], [])
class ChestCollection(materials.MaterialCollection): MATERIAL_PROBABILITIES: ClassVar[Dict[block_util.MCD, float]] = { block_util.MCD("StoneChestMaterial", needs_board_update=True, block_kwargs={ "starting_items": loot_pools.ItemLootPool(5, {ground_materials.IronIngot: 0.2, ground_materials.GoldIngot: 0.1, ground_materials.ZincIngot: 0.4, ground_materials.CopperIngot: 0.25, ground_materials.TitaniumIngot: 0.05}) }): 0.5, block_util.MCD("Air"): 0.5 }
def add(self, coord: Union[Tuple[int, int], List[int]], value: str, overwrite=True) -> None: if coord[1] in self.__internal_tree: # do not overwrite if requested if not overwrite and coord[0] in self.__internal_tree[coord[1]]: return self.__internal_tree[coord[1]][coord[0]] = block_util.MCD(value) else: if coord[1] > con.MAX_DEPTH and con.DEBUG.WARNINGS: print("Carefull {} is outside the board".format(coord)) return self.__internal_tree[coord[1]] = {coord[0]: block_util.MCD(value)}
class CornerNorthWestMinePart(StructurePart): FORM_DEFINITION: ClassVar[List[List[Union[materials.MaterialCollection, str]]]] = [ [StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection], [block_util.MCD("Air"), block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection], [HorizontalBeltCollection, HorizontalBeltCollection, HorizontalBeltCollection, StoneBrickCollection], [StoneBrickCollection, StoneBrickCollection, StoneBrickCollection, StoneBrickCollection] ] CONNECTION_DIRECIONS: ClassVar[Tuple[List[Tuple[str, int]], List[Tuple[str, int]], List[Tuple[str, int]], List[Tuple[str, int]]]] = ( [("VerticalMinePart", 0)], [], [], [("HorizontalMinePart", 0)] )
class VerticalMinePart(StructurePart): FORM_DEFINITION: ClassVar[List[List[Union[materials.MaterialCollection, str]]]] = [ [StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection], [StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection], [StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection], [StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection] ] CONNECTION_DIRECIONS: ClassVar[Tuple[List[Tuple[str, int]], List[Tuple[str, int]], List[Tuple[str, int]], List[Tuple[str, int]]]] = ( [("VerticalMinePart", 0), ("CornerSouthWestMinePart", 0), ("CornerSouthEastMinePart", 0), ("JunctionNorthEastSouth", 0), ("JunctionNorthSouthWest", 0), ("JunctionEastSouthWest", 0), ("JunctionNorthEastSouthWest", 0), ("MachineRoom", 0)], [], [("VerticalMinePart", 0), ("CornerNorthWestMinePart", 0), ("CornerNorthEastMinePart", 0), ("JunctionNorthEastSouth", 0), ("JunctionNorthSouthWest", 0), ("JunctionNorthEastWest", 0), ("JunctionNorthEastSouthWest", 0), ("MachineRoom", 0)], [] )
def __add_directional_border(self, matrix: List[List], direction: str) -> None: """Add a border for a certain direction""" if direction == "north": rows = matrix[0:self.MAX_BORDER_SPREAD_DISTANCE] for row_i in range(len(rows)): border_block_chance = self.BORDER_SPREAD_LIKELYHOOD.cumulative_probability( row_i) for col_i in range(len(matrix[row_i])): if uniform(0, 1) < border_block_chance: matrix[row_i][col_i] = block_util.MCD("BorderMaterial") elif direction == "south": rows = matrix[-(self.MAX_BORDER_SPREAD_DISTANCE + 1):-1] for row_i in range(len(rows)): border_block_chance = self.BORDER_SPREAD_LIKELYHOOD.cumulative_probability( row_i) for col_i in range(len(matrix[row_i])): if uniform(0, 1) < border_block_chance: matrix[-(row_i + 1)][-(col_i + 1)] = block_util.MCD( "BorderMaterial") elif direction == "west": for row_i in range(len(matrix)): for col_i in range( len(matrix[row_i][0:self.MAX_BORDER_SPREAD_DISTANCE])): border_block_chance = self.BORDER_SPREAD_LIKELYHOOD.cumulative_probability( col_i) if uniform(0, 1) < border_block_chance: matrix[row_i][col_i] = block_util.MCD("BorderMaterial") elif direction == "east": for row_i in range(len(matrix)): for col_i in range( len(matrix[row_i][-(self.MAX_BORDER_SPREAD_DISTANCE + 1):-1])): border_block_chance = self.BORDER_SPREAD_LIKELYHOOD.cumulative_probability( col_i) if uniform(0, 1) < border_block_chance: matrix[-(row_i + 1)][-(col_i + 1)] = block_util.MCD( "BorderMaterial") else: raise util.GameException( "Unrecognized direction for border: {}".format(direction))
def __adjust_foreground_string_matrix(self, matrix): # generate the air space at the start position for row_i in range(interface_util.p_to_r(self.START_RECTANGLE.top), interface_util.p_to_r(self.START_RECTANGLE.bottom)): for column_i in range(interface_util.p_to_c(self.START_RECTANGLE.left), interface_util.p_to_c(self.START_RECTANGLE.right)): matrix[row_i][column_i] = block_util.MCD("Air") return matrix
class StoneBrickCollection(materials.MaterialCollection): MATERIAL_PROBABILITIES: ClassVar[Dict[block_util.MCD, float]] = { block_util.MCD("StoneBrickMaterial"): 0.39, block_util.MCD("MossBrickMaterial"): 0.3, block_util.MCD("ManyMossBrickMaterial"): 0.3, block_util.MCD("Air"): 0.01 }
class MachineCollection(materials.MaterialCollection): MATERIAL_PROBABILITIES: ClassVar[Dict[block_util.MCD, float]] = { block_util.MCD("FurnaceMaterial", needs_board_update=True): 0.3, block_util.MCD("FactoryMaterial", needs_board_update=True): 0.3, block_util.MCD("Air"): 0.4 }
class MachineRoom(StructurePart): FORM_DEFINITION: ClassVar[List[List[Union[materials.MaterialCollection, str]]]] = [ [StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection, StoneBrickCollection, StoneBrickCollection, StoneBrickCollection, StoneBrickCollection, StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection], [StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection], [StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection], [StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection], [StoneBrickCollection, block_util.MCD("Air"), HorizontalBeltCollection, MachineCollection, block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection], [StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), ChestCollection, ChestCollection, HorizontalBeltCollection, StoneBrickCollection], [StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection, StoneBrickCollection, block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), StoneBrickCollection, StoneBrickCollection, VerticalBeltCollection, StoneBrickCollection], [StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection], [StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection], [block_util.MCD("Air"), block_util.MCD("Air"), VerticalBeltCollection, block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), block_util.MCD("Air"), VerticalBeltCollection, block_util.MCD("Air")], [HorizontalBeltCollection, HorizontalBeltCollection, VerticalBeltCollection, HorizontalBeltCollection, HorizontalBeltCollection, HorizontalBeltCollection, HorizontalBeltCollection, HorizontalBeltCollection, HorizontalBeltCollection, HorizontalBeltCollection, VerticalBeltCollection, HorizontalBeltCollection], [StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection, StoneBrickCollection, StoneBrickCollection, StoneBrickCollection, StoneBrickCollection, StoneBrickCollection, block_util.MCD("Air"), VerticalBeltCollection, StoneBrickCollection], ] CONNECTION_DIRECIONS: ClassVar[Tuple[List[Tuple[str, int]], List[Tuple[str, int]], List[Tuple[str, int]], List[Tuple[str, int]]]] = ( [("VerticalMinePart", 8)], [("HorizontalMinePart", 0), ("HorizontalMinePart", 8)], [("VerticalMinePart", 8)], [("HorizontalMinePart", 0), ("HorizontalMinePart", 8)], )
class VerticalBeltCollection(materials.MaterialCollection): MATERIAL_PROBABILITIES: ClassVar[Dict[block_util.MCD, float]] = { block_util.MCD("Air"): 0.9, block_util.MCD("BasicConveyorBelt", needs_board_update=True, image_key="1_0"): 0.1 }
class IronSheetCollection(materials.MaterialCollection): MATERIAL_PROBABILITIES: ClassVar[Dict[block_util.MCD, float]] = { block_util.MCD("IronSheetWall"): 0.8, block_util.MCD("RustedIronSheetWall"): 0.19, block_util.MCD("Air"): 0.01 }