Beispiel #1
0
 def construct(self, level, coords, door_coords, surface):
     # This is assumes box is already the size of the house
     minx = surface.to_real_x(coords[0][0])
     minz = surface.to_real_z(coords[0][1])
     maxx = surface.to_real_x(coords[1][0])
     maxz = surface.to_real_z(coords[1][1])
     block = surface.surface_map[coords[0][0]][coords[0][1]]
     door_coords = (surface.to_real_x(door_coords[0]),
                    surface.to_real_z(door_coords[1]))
     miny = block.height
     biome = block.biome_id
     wall_block = BlockUtils.get_wall_block(biome)
     door_block = BlockUtils.get_door_block(biome)
     pillar_block = BlockUtils.get_beam_block(biome)
     height_offset = RandUtils.rand_range(minx, miny, 10, 5)
     pillar_height = miny + height_offset
     level_coords = ((minx, minz, miny), (maxx, maxz, pillar_height))
     remove_blocks_in_box(level, level_coords)
     construct_pillars(level, level_coords, biome, pillar_height)
     construct_walls(level, level_coords, biome, pillar_height)
     construct_floor_and_flat_roof(level, level_coords, biome,
                                   pillar_height)
     construct_pointed_roof(level, level_coords, biome, pillar_height)
     place_door(level, level_coords, biome, door_coords)
     place_windows(level, level_coords, biome, height_offset)
     coords = shrink_building_lot(coords, miny)
     minx = surface.to_real_x(coords[0][0])
     minz = surface.to_real_z(coords[0][1])
     maxx = surface.to_real_x(coords[1][0])
     maxz = surface.to_real_z(coords[1][1])
     inside_coords = ((minx, minz, miny), (maxx, maxz))
     place_furniture(level, inside_coords, biome)
Beispiel #2
0
def construct_floor_and_flat_roof(level, coords, biome, height):
    minx, minz, miny, maxx, maxz = get_coords(coords)
    roof_block = BlockUtils.get_roof_block(biome)
    floor_block = BlockUtils.get_floor_block(biome)

    # roof and floor
    for x in range(minx, maxx):
        for z in range(minz, maxz):
            utilityFunctions.setBlock(level, roof_block, x, height, z)
            utilityFunctions.setBlock(level, floor_block, x, miny, z)
Beispiel #3
0
def construct_vaulted_roof(level, coords, biome, height):
    minx, minz, miny, maxx, maxz = get_coords(coords)
    roof_block = BlockUtils.get_roof_block(biome)
    for i in range(-1, abs(maxx - minx) / 3):
        for x in range(minx, maxx):
            for z in range(minz + i, maxz - i):
                utilityFunctions.setBlock(level, roof_block, x, height + i, z)
Beispiel #4
0
 def construct(self, level, coords, door_coords, surface):
     # This is assumes box is already the size of the house
     minx = surface.to_real_x(coords[0][0])
     minz = surface.to_real_z(coords[0][1])
     maxx = surface.to_real_x(coords[1][0])
     maxz = surface.to_real_z(coords[1][1])
     block = surface.surface_map[coords[0][0]][coords[0][1]]
     miny = block.height
     biome = block.biome_id
     crop_block = BlockUtils.get_crop_block(biome)
     spacer_block = BlockUtils.get_beam_block(biome)
     height_offset = RandUtils.rand_range(minx, miny, 10, 5)
     pillar_height = miny + height_offset
     level_coords = ((minx, minz, miny), (maxx, maxz, pillar_height))
     remove_blocks_in_box(level, level_coords)
     construct_farm(level, level_coords, biome)
Beispiel #5
0
def place_door(level, coords, biome, door_coords):
    minx, minz, miny, maxx, maxz = get_coords(coords)
    door_block = BlockUtils.get_door_block(biome)
    # Place door
    utilityFunctions.setBlock(level, door_block, door_coords[0], miny + 1,
                              door_coords[1])
    utilityFunctions.setBlock(level, door_block, door_coords[0], miny + 2,
                              door_coords[1])
Beispiel #6
0
def construct_pillars(level, coords, biome, height):
    minx, minz, miny, maxx, maxz = get_coords(coords)
    pillar_block = BlockUtils.get_beam_block(biome)
    for y in range(height, 0, -1):
        for x in [minx, maxx - 1]:
            for z in [minz, maxz - 1]:
                block = level.blockAt(x, y, z)
                if block in surface_blocks or block == 9:
                    utilityFunctions.setBlock(level, pillar_block, x, y, z)
Beispiel #7
0
    def generate_yards(self):
        """
        Generate yards, building lots, path doors, building doors and place them within the self.surface member
        :returns: void (sets self.surface)
        """
        new_surface = copy(self.surface)
        probability_generate_yard = 0.90  # Chance of partition being a yard
        for p in self.partitions:
            partition_prob = float(
                (lehmer_2(lehmer_2(self.seed, p[1][0] - p[0][0]),
                          p[1][1] - p[0][1])) % 100) / 100
            if partition_prob < probability_generate_yard:
                new_surface = self.run_ca_on_partition(new_surface, p)
                new_surface = self.generate_building_lots(new_surface, p)
                new_surface = self.generate_building_door_blocks(
                    new_surface, p)
                new_surface = self.generate_door_blocks(new_surface, p)

                # draw
                if __name__ != "__main__":
                    for i in range(p[0][0], p[1][0]):
                        for j in range(p[0][1], p[1][1]):
                            if self.surface.surface_map[i][j].type == Block.YARD \
                                    and self.count_neighbours(i, j, p[0][0], p[1][0], p[0][1], p[1][1], Block.UNASSIGNED) > 1:
                                utilityFunctions.setBlock(
                                    self.level,
                                    BlockUtils.get_fence_block(
                                        self.surface.surface_map[i]
                                        [j].biome_id),
                                    self.surface.to_real_x(i),
                                    self.surface.surface_map[i][j].height + 1,
                                    self.surface.to_real_z(j))
                            if self.surface.surface_map[i][
                                    j].type == Block.YARD and self.surface.surface_map[
                                        i][j].is_water:
                                utilityFunctions.setBlock(
                                    self.level,
                                    BlockUtils.get_bridge_block(
                                        self.surface.surface_map[i]
                                        [j].biome_id),
                                    self.surface.to_real_x(i),
                                    self.surface.surface_map[i][j].height,
                                    self.surface.to_real_z(j))
        self.surface = new_surface
Beispiel #8
0
def construct_farm(level, coords, biome):
    minx, minz, miny, maxx, maxz = get_coords(coords)
    water_block = blocks["Still Water"]
    crop_block = BlockUtils.get_crop_block(biome)
    soil_block = BlockUtils.get_soil_block(biome)
    wall_block = BlockUtils.get_wall_block(biome)

    for x in range(minx, maxx):
        for z in range(minz, maxz):
            if (z == minz or z == maxz - 1 or x == minx or x == maxx - 1):
                utilityFunctions.setBlock(level, wall_block, x, miny, z)
                utilityFunctions.setBlock(level, wall_block, x, miny - 1, z)
            else:
                if (z % 2 == 0):
                    utilityFunctions.setBlock(level, crop_block, x, miny + 1,
                                              z)
                    utilityFunctions.setBlock(level, soil_block, x, miny, z)
                else:
                    utilityFunctions.setBlock(level, water_block, x, miny, z)
                utilityFunctions.setBlock(level, soil_block, x, miny - 1, z)
Beispiel #9
0
def construct_walls(level, coords, biome, height):
    minx, minz, miny, maxx, maxz = get_coords(coords)
    wall_block = BlockUtils.get_wall_block(biome)
    # walls
    for y in range(height, miny, -1):
        for x in range(minx, maxx):
            for z in range(minz, maxz):
                # Skip columns since they should be a different block
                if (x == minx and z == minz) or (x == maxx-1 and z == minz) or \
                        (x == minx and z == maxz-1) or (x == maxx-1 and z == maxz-1):
                    continue
                if x == maxx - 1 or z == maxz - 1 or x == minx or z == minz:
                    utilityFunctions.setBlock(level, wall_block, x, y, z)
Beispiel #10
0
def construct_square_window(level, coords, biome, face=0):
    x = coords[0]
    y = coords[1]
    z = coords[2]
    window_block = BlockUtils.get_window_block(biome)
    if face == 0:
        for i in range(x, x + 2):
            for j in range(y, y - 2, -1):
                utilityFunctions.setBlock(level, window_block, i, j, z)
    elif face == 1:
        for i in range(z, z + 2):
            for j in range(y, y - 2, -1):
                utilityFunctions.setBlock(level, window_block, x, j, i)
Beispiel #11
0
 def construct(self, level, coords, door_coords, surface):
     minx = coords[0][0]
     minz = coords[0][1]
     maxx = coords[1][0]
     maxz = coords[1][1]
     block = surface.surface_map[coords[0][0]][coords[0][1]]
     miny = block.height
     biome = block.biome_id
     hedge_block = BlockUtils.get_hedge_block(biome)
     new_coords = shrink_building_lot(coords, miny)
     if door_coords[0] > minx:
         door_x = door_coords[0] - 1
     else:
         door_x = door_coords[0] + 1
     if door_coords[1] > minz:
         door_z = door_coords[1] - 1
     else:
         door_z = door_coords[1] + 1
     new_door_coords = (door_x, door_z)
     building = BasicBuilding()
     building.construct(level, new_coords, new_door_coords, surface)
     # ring basic building in hedge
     minx = surface.to_real_x(minx)
     minz = surface.to_real_z(minz)
     maxx = surface.to_real_x(maxx)
     maxz = surface.to_real_z(maxz)
     for x in range(minx, maxx):
         for z in range(minz, maxz):
             if x == maxx - 1 or z == maxz - 1 or x == minx or z == minz:
                 if x != surface.to_real_x(
                         door_coords[0]) or z != surface.to_real_z(
                             door_coords[1]):
                     utilityFunctions.setBlock(level, hedge_block, x,
                                               miny + 1, z)
                 else:
                     # Remove hedges around door to ensure there is an entrance
                     if level.blockAt(x + 1, miny + 1, z) == hedge_block[0]:
                         utilityFunctions.setBlock(level, blocks['Air'],
                                                   x + 1, miny + 1, z)
                     if level.blockAt(x, miny + 1, z + 1) == hedge_block[0]:
                         utilityFunctions.setBlock(level, blocks['Air'], x,
                                                   miny + 1, z + 1)
                     if level.blockAt(x - 1, miny + 1, z) == hedge_block[0]:
                         utilityFunctions.setBlock(level, blocks['Air'],
                                                   x - 1, miny + 1, z)
                     if level.blockAt(x, miny + 1, z - 1) == hedge_block[0]:
                         utilityFunctions.setBlock(level, blocks['Air'], x,
                                                   miny + 1, z - 1)
Beispiel #12
0
def construct_triangle_window(level, coords, biome, face=0):
    x = coords[0]
    y = coords[1]
    z = coords[2]
    window_block = BlockUtils.get_window_block(biome)
    if face == 0:
        for j in range(y, y - 2, -1):
            utilityFunctions.setBlock(level, window_block, x, j, z)
            if j == y - 1:
                utilityFunctions.setBlock(level, window_block, x - 1, j, z)
                utilityFunctions.setBlock(level, window_block, x + 1, j, z)
    elif face == 1:
        for j in range(y, y - 2, -1):
            utilityFunctions.setBlock(level, window_block, x, j, z)
            if j == y - 1:
                utilityFunctions.setBlock(level, window_block, x, j, z - 1)
                utilityFunctions.setBlock(level, window_block, x, j, z + 1)
Beispiel #13
0
    def find_paths_BFS(self, start, end):
        path = {}
        cell_queue = [start]
        path[start] = None
        while len(cell_queue) > 0:
            current = cell_queue.pop(0)
            if current == end:
                break
            for next in self.get_block_neighbors(current):
                if next not in path:
                    cell_queue.append(next)
                    path[next] = self.subtract(current, next)

        # Draw paths
        current = self.add(end, path[end])
        direction = path[end]
        prev = end
        while current != start:
            # find next in path
            x, z = current
            block = self.surface.surface_map[x][z]
            previous_block = self.surface.surface_map[prev[0]][prev[1]]
            block.type = Block.PATH
            steepness = previous_block.height - block.height
            new_height = block.height
            if steepness > 1:
                if steepness > 4:
                    new_height = self.surface.surface_map[prev[0]][
                        prev[1]].height
                else:
                    new_height = self.surface.surface_map[prev[0]][
                        prev[1]].height - 1
            elif previous_block.height - block.height < -1:
                new_height = self.surface.surface_map[prev[0]][
                    prev[1]].height + 1
            block.height = new_height
            # If path is moving horizontally, try to widen it by adding blocks above and below it
            if direction == (-1, 0) or direction == (1, 0):
                path_edges = [(x, z - 1), (x, z + 1)]
            # If path is moving vertically, try to widen it by adding blocks to the left and to the right of it
            else:
                path_edges = [(x - 1, z), (x + 1, z)]
            path_edges = filter(self.block_in_grid, path_edges)
            path_edges = filter(self.block_is_free, path_edges)
            for edge in path_edges:
                edge_block = self.surface.surface_map[edge[0]][edge[1]]
                edge_block.type = Block.PATH
                # Set path block in level
                level_block = BlockUtils.get_road_block(edge_block.biome_id)
                bridge_block = BlockUtils.get_bridge_block(edge_block.biome_id)
                if edge_block.is_water:
                    utilityFunctions.setBlock(
                        self.level, bridge_block,
                        self.surface.to_real_x(edge_block.x), new_height,
                        self.surface.to_real_z(edge_block.z))
                else:
                    utilityFunctions.setBlock(
                        self.level, level_block,
                        self.surface.to_real_x(edge_block.x), new_height,
                        self.surface.to_real_z(edge_block.z))
                # Remove all blocks above paths
                above = new_height + 1
                while self.level.blockAt(
                        self.surface.to_real_x(edge_block.x), above,
                        self.surface.to_real_z(edge_block.z)) != 0:
                    utilityFunctions.setBlock(
                        self.level, (0, 0),
                        self.surface.to_real_x(edge_block.x), above,
                        self.surface.to_real_z(edge_block.z))
                    above += 1
            # Set path block in level
            level_block = BlockUtils.get_road_block(block.biome_id)
            bridge_block = BlockUtils.get_bridge_block(block.biome_id)
            if block.is_water:
                utilityFunctions.setBlock(self.level, bridge_block,
                                          self.surface.to_real_x(block.x),
                                          new_height,
                                          self.surface.to_real_z(block.z))
            else:
                utilityFunctions.setBlock(self.level, level_block,
                                          self.surface.to_real_x(block.x),
                                          new_height,
                                          self.surface.to_real_z(block.z))
            above = new_height + 1
            # Remove all blocks above paths
            while self.level.blockAt(self.surface.to_real_x(x), above,
                                     self.surface.to_real_z(z)) != 0:
                utilityFunctions.setBlock(self.level, (0, 0),
                                          self.surface.to_real_x(block.x),
                                          above,
                                          self.surface.to_real_z(block.z))
                above += 1
            prev = current
            current = self.add(current, path[current])
            direction = path[current]