def generateApartmentInterior(matrix, h_min, h_max, floor_size, x_min, x_max, z_min, z_max, double_apartment_floor, usable_wood, biome, fence_id): cur_floor = h_min floor = 0 x_mid = x_max - int((x_max - x_min) / 2) z_mid = z_max - int((z_max - z_min) / 2) while cur_floor < h_max: cur_floor_ceiling = cur_floor + floor_size if cur_floor == h_min: #hall generateFurnitureHall(matrix, cur_floor, floor_size, x_min, x_mid, z_min, z_max, usable_wood, biome, fence_id) #apartment on the left side of the floor picked_wood = utilityFunctions.selectRandomWood(usable_wood) generateFurnitureSmallApartment(matrix, cur_floor, floor_size, x_mid, x_max, z_min, z_max, 2, fence_id, biome, picked_wood) elif cur_floor in double_apartment_floor: #first apartment picked_wood = utilityFunctions.selectRandomWood(usable_wood) generateFurnitureSmallApartment(matrix, cur_floor, floor_size, x_min, x_mid, z_min, z_max, 1, fence_id, biome, picked_wood) #second apartment picked_wood = utilityFunctions.selectRandomWood(usable_wood) generateFurnitureSmallApartment(matrix, cur_floor, floor_size, x_mid, x_max, z_min, z_max, 2, fence_id, biome, picked_wood) else: picked_wood = utilityFunctions.selectRandomWood(usable_wood) stairs_id = BlocksInfo.getStairsId(biome, picked_wood)[0] generateCarpet(matrix.matrix, cur_floor + 1, x_min + 1, x_max, z_min + 1, z_max) generateBed(matrix, cur_floor, x_max, z_min) generateCentralTable(matrix, cur_floor, x_mid, z_mid, stairs_id) generateBookshelf(matrix, cur_floor, x_max, z_max) generateCouch(matrix, cur_floor, x_min, z_max, stairs_id) x_mid = x_min + (x_max - x_min) / 2 z_mid = z_min + (z_max - z_min) / 2 generateChandelier(matrix, cur_floor_ceiling, x_mid - 5, z_mid, fence_id, 2) generateChandelier(matrix, cur_floor_ceiling, x_mid + 5, z_mid, fence_id, 2) cur_floor += floor_size
def generateFurnitureHall(matrix, h_min, floor_size, x_min, x_max, z_min, z_max, usable_wood, biome, fence_id): grounds = [(47, 0), (45, 0)] x_mid = x_max - (x_max - x_min) / 2 z_mid = z_max - (z_max - z_min) / 2 plant_ground_id = BlocksInfo.getPlantGroundId(biome) ground_id = grounds[random.randint(0, len(grounds) - 1)] plant_id = BlocksInfo.getPlantsId( biome, utilityFunctions.selectRandomWood(usable_wood)) generateCarpet(matrix.matrix, h_min + 1, x_min + 1, x_max, z_min + 1, z_max + 1) generateChandelier(matrix, h_min + floor_size, x_mid, z_mid, fence_id, 2) generatePlant(matrix, h_min, x_min + 2, z_max - 1, plant_id, plant_ground_id) generatePlant(matrix, h_min, x_max - 2, z_max - 1, plant_id, plant_ground_id) next_blank = 2 for z in range(z_max - 3, z_min + 1, -1): if next_blank == 0: next_blank = 3 generatePotWithPlant(matrix, h_min, x_mid, z, (47, 0), ground_id) if (x_max - x_min - 1) % 2 == 0: generatePotWithPlant(matrix, h_min, x_mid - 1, z, (47, 0), ground_id) else: next_blank -= 1 generateMailbox(matrix, h_min, x_min + 1, z, "E") generateMailbox(matrix, h_min, x_max - 1, z, "W")
def fillWithGarden(matrix, h, x_min, x_max, z_min, z_max, biome, usable_wood): flowers_id = BlocksInfo.getFlowerId(biome) flower_ground_id = BlocksInfo.getPlantGroundId(biome) bush_id = BlocksInfo.getBushId( biome, utilityFunctions.selectRandomWood(usable_wood)) for x in range(x_min, x_max + 1, 5): for z in range(z_max, z_min + 1, -5): if z - 5 >= z_min and x + 5 <= x_max: generateBushCorner(matrix, h, x, z, 0, bush_id) generateBushCorner(matrix, h, x, z - 5, 1, bush_id) generateBushCorner(matrix, h, x + 5, z - 5, 2, bush_id) generateBushCorner(matrix, h, x + 5, z, 3, bush_id) generateFlowerTray(matrix, h, x + 2, z - 2, flowers_id, flower_ground_id)
def generateHouse(matrix, h_min, h_max, x_min, x_max, z_min, z_max, biome, usable_wood): house = utilityFunctions.dotdict() house.type = "house" house.lotArea = utilityFunctions.dotdict({ "y_min": h_min, "y_max": h_max, "x_min": x_min, "x_max": x_max, "z_min": z_min, "z_max": z_max }) #generateFence(matrix, h_min, x_min, x_max, z_min, z_max) (h_min, h_max, x_min, x_max, z_min, z_max) = getHouseAreaInsideLot(h_min, h_max, x_min, x_max, z_min, z_max) # calculate the top height of the walls, i.e. where the first # row of blocks of the pitched roof will be placed ceiling_bottom = h_max - int((h_max - h_min) * 0.5) house.buildArea = utilityFunctions.dotdict({ "y_min": h_min, "y_max": ceiling_bottom, "x_min": x_min, "x_max": x_max, "z_min": z_min, "z_max": z_max }) logging.info("Generating house at area {}".format(house.lotArea)) logging.info("Construction area {}".format(house.buildArea)) utilityFunctions.cleanProperty2(matrix, house.lotArea.y_min + 1, house.lotArea.y_max, x_min - 1, x_max + 1, z_min - 1, z_max + 1) picked_wood = utilityFunctions.selectRandomWood(usable_wood) floor = BlocksInfo.getHouseFloorId(biome, picked_wood) wall = BlocksInfo.getHouseWallId(biome) wall = BlocksInfo.getPlankId(picked_wood) if wall[0] == -1 else wall pillar = BlocksInfo.getHousePillarId(wall, picked_wood) ceiling = BlocksInfo.getStairsId(biome, picked_wood) roof = BlocksInfo.getStructureBlockId(biome, picked_wood) pavement_block = BlocksInfo.getPavmentId(biome) house.orientation = getOrientation(matrix, house.lotArea) window_y = house.buildArea.y_min + 3 door_y = house.buildArea.y_min + 1 if house.orientation == "N": door_x = RNG.randint(house.buildArea.x_min + 4, house.buildArea.x_max - 4) door_z = house.buildArea.z_min utilityFunctions.cleanProperty2(matrix, h_min + 1, h_max, door_x - 1, door_x + 1, house.lotArea.z_min + 1, z_min - 1) # generate walls from x_min+1, x_max-1, etc to leave space for the roof generateWalls(matrix, house.buildArea.y_min, house.buildArea.y_max, house.buildArea.x_min, house.buildArea.x_max, house.buildArea.z_min, house.buildArea.z_max, wall, pillar) generateFloor(matrix, house.buildArea.y_min, house.buildArea.x_min, house.buildArea.x_max, house.buildArea.z_min, house.buildArea.z_max, floor) generateDoor(matrix, door_y, door_x, door_z, (64, 9), (64, 1)) house.entranceLot = (h_min + 1, door_x, house.lotArea.z_min) # entrance path for z in range(house.lotArea.z_min, door_z): matrix.setValue(h_min, door_x, z, pavement_block) matrix.setValue(h_min, door_x - 1, z, pavement_block) matrix.setValue(h_min, door_x + 1, z, pavement_block) elif house.orientation == "S": door_x = RNG.randint(house.buildArea.x_min + 4, house.buildArea.x_max - 4) door_z = house.buildArea.z_max utilityFunctions.cleanProperty2(matrix, h_min + 1, h_max, door_x - 1, door_x + 1, z_max + 1, house.lotArea.z_max - 1) # generate walls from x_min+1, x_max-1, etc to leave space for the roof generateWalls(matrix, house.buildArea.y_min, house.buildArea.y_max, house.buildArea.x_min, house.buildArea.x_max, house.buildArea.z_min, house.buildArea.z_max, wall, pillar) generateFloor(matrix, house.buildArea.y_min, house.buildArea.x_min, house.buildArea.x_max, house.buildArea.z_min, house.buildArea.z_max, floor) generateDoor(matrix, door_y, door_x, door_z, (64, 9), (64, 3)) house.entranceLot = (h_min + 1, door_x, house.lotArea.z_max) # entrance path for z in range(door_z + 1, house.lotArea.z_max): matrix.setValue(h_min, door_x, z, pavement_block) matrix.setValue(h_min, door_x - 1, z, pavement_block) matrix.setValue(h_min, door_x + 1, z, pavement_block) elif house.orientation == "W": door_x = house.buildArea.x_min door_z = RNG.randint(house.buildArea.z_min + 4, house.buildArea.z_max - 4) utilityFunctions.cleanProperty2(matrix, h_min + 1, h_max, house.lotArea.x_min + 1, x_min - 1, door_z - 1, door_z + 1) # generate walls from x_min+1, x_max-1, etc to leave space for the roof generateWalls(matrix, house.buildArea.y_min, house.buildArea.y_max, house.buildArea.x_min, house.buildArea.x_max, house.buildArea.z_min, house.buildArea.z_max, wall, pillar) generateFloor(matrix, house.buildArea.y_min, house.buildArea.x_min, house.buildArea.x_max, house.buildArea.z_min, house.buildArea.z_max, floor) generateDoor(matrix, door_y, door_x, door_z, (64, 8), (64, 0)) house.entranceLot = (h_min + 1, house.lotArea.x_min, door_z) # entrance path for x in range(house.lotArea.x_min, door_x): matrix.setValue(h_min, x, door_z, pavement_block) matrix.setValue(h_min, x, door_z - 1, pavement_block) matrix.setValue(h_min, x, door_z + 1, pavement_block) elif house.orientation == "E": door_x = house.buildArea.x_max door_z = RNG.randint(house.buildArea.z_min + 4, house.buildArea.z_max - 4) utilityFunctions.cleanProperty2(matrix, h_min + 1, h_max, x_max + 1, house.lotArea.x_max - 1, door_z - 1, door_z + 1) # generate walls from x_min+1, x_max-1, etc to leave space for the roof generateWalls(matrix, house.buildArea.y_min, house.buildArea.y_max, house.buildArea.x_min, house.buildArea.x_max, house.buildArea.z_min, house.buildArea.z_max, wall, pillar) generateFloor(matrix, house.buildArea.y_min, house.buildArea.x_min, house.buildArea.x_max, house.buildArea.z_min, house.buildArea.z_max, floor) generateDoor(matrix, door_y, door_x, door_z, (64, 9), (64, 2)) house.entranceLot = (h_min + 1, house.lotArea.x_max, door_z) # entrance path for x in range(door_x + 1, house.lotArea.x_max + 1): matrix.setValue(h_min, x, door_z, pavement_block) matrix.setValue(h_min, x, door_z - 1, pavement_block) matrix.setValue(h_min, x, door_z + 1, pavement_block) if house.orientation == "N" or house.orientation == "S": generateWindow_alongX(matrix, window_y, house.buildArea.x_min, house.buildArea.z_min, house.buildArea.z_max) generateWindow_alongX(matrix, window_y, house.buildArea.x_max, house.buildArea.z_min, house.buildArea.z_max) generateCeiling_x(matrix, ceiling_bottom, h_max, x_min - 1, x_max + 1, z_min - 1, z_max + 1, ceiling[0], roof, wall, 0) elif house.orientation == "E" or house.orientation == "W": generateWindow_alongZ(matrix, window_y, house.buildArea.z_min, house.buildArea.x_min, house.buildArea.x_max) generateWindow_alongZ(matrix, window_y, house.buildArea.z_max, house.buildArea.x_min, house.buildArea.x_max) generateCeiling_z(matrix, ceiling_bottom, h_max, x_min - 1, x_max + 1, z_min - 1, z_max + 1, ceiling[0], roof, wall, 0) generateInterior(matrix, h_min, ceiling_bottom, house.buildArea.x_min, house.buildArea.x_max, house.buildArea.z_min, house.buildArea.z_max, picked_wood, biome) return house
def generateGreenhouse(matrix, h_min, h_max, x_min, x_max, z_min, z_max, usable_wood, biome): greenhouse = utilityFunctions.dotdict() greenhouse.type = "greenhouse" greenhouse.lotArea = utilityFunctions.dotdict({ "y_min": h_min, "y_max": h_max, "x_min": x_min, "x_max": x_max, "z_min": z_min, "z_max": z_max }) (h_min, h_max, x_min, x_max, z_min, z_max) = getGreenHouseAreaInsideLot(h_min, h_max, x_min, x_max, z_min, z_max) greenhouse.buildArea = utilityFunctions.dotdict({ "y_min": h_min, "y_max": h_max, "x_min": x_min, "x_max": x_max, "z_min": z_min, "z_max": z_max }) greenhouse.orientation = getOrientation() door_z = greenhouse.buildArea.z_min door_x = greenhouse.buildArea.x_min + GREENHOUSE_WIDTH / 2 greenhouse.entranceLot = (greenhouse.lotArea.y_min + 1, door_x, greenhouse.lotArea.z_min) logging.info("Generating greenhouse at area {}".format(greenhouse.lotArea)) logging.info("Construction area {}".format(greenhouse.buildArea)) utilityFunctions.cleanProperty2(matrix, greenhouse.lotArea.y_min + 1, greenhouse.lotArea.y_max, x_min - 1, x_max + 1, z_min - 1, z_max + 1) utilityFunctions.cleanProperty2(matrix, h_min + 1, h_max, door_x - 1, door_x + 1, greenhouse.lotArea.z_min + 1, z_min - 1) picked_wood = utilityFunctions.selectRandomWood(usable_wood) foundation = BlocksInfo.getGreenhouseFundationId(biome, picked_wood) ground = BlocksInfo.getGreenhouseGroundId(biome) used_glass = BlocksInfo.getGreenhouseGlassId(biome) pavement_block = BlocksInfo.getPavmentId(biome) generateGroundAndCropse(matrix, greenhouse.buildArea.y_min, greenhouse.buildArea.x_min, greenhouse.buildArea.x_max, greenhouse.buildArea.z_min, greenhouse.buildArea.z_max, foundation, ground) generateGlassDome(matrix, greenhouse.buildArea.y_min + 1, greenhouse.buildArea.y_min + GREENHOUSE_HEIGHT, greenhouse.buildArea.x_min, greenhouse.buildArea.x_max, greenhouse.buildArea.z_min, greenhouse.buildArea.z_max, used_glass) generateFront(matrix, greenhouse.buildArea.y_min + 1, greenhouse.buildArea.y_min + GREENHOUSE_HEIGHT, greenhouse.buildArea.x_min, greenhouse.buildArea.x_max, greenhouse.buildArea.z_min, greenhouse.buildArea.z_max, used_glass) # entrance path for z in range(greenhouse.lotArea.z_min, door_z): matrix.setValue(h_min, door_x, z, pavement_block) matrix.setValue(h_min, door_x - 1, z, pavement_block) return greenhouse
def generateBuilding(matrix, h_min, h_max, x_min, x_max, z_min, z_max, usable_wood, biome): building = utilityFunctions.dotdict() building.type = "building" building.area = utilityFunctions.dotdict({ "y_min": h_min, "y_max": h_max, "x_min": x_min, "x_max": x_max, "z_min": z_min, "z_max": z_max }) (h_min, h_max, x_min, x_max, z_min, z_max) = getBuildingAreaInsideLot(h_min, h_max, x_min, x_max, z_min, z_max) building.constructionArea = (h_min, h_max, x_min, x_max, z_min, z_max) logging.info("Generating building at area {}".format(building.area)) logging.info("Construction area {}".format(building.constructionArea)) utilityFunctions.cleanProperty2( matrix, building.area.y_min + 1, building.area.y_max, x_min - 1, x_max + 1, z_min - 3 if z_min - 3 > building.area.z_min else building.area.z_min, z_max + 1) picked_wood = utilityFunctions.selectRandomWood(usable_wood) wall = (159, random.randint(0, 15)) ceiling = wall floor = wall pavement_block = BlocksInfo.getPavmentId(biome) slab = BlocksInfo.getSlabId(biome, picked_wood, "Upper") stairs = BlocksInfo.getStairsId(biome, picked_wood) fence = BlocksInfo.getFenceId(biome, picked_wood) structureBloc = BlocksInfo.getStructureBlockId(biome, picked_wood) floor_size = 8 max_height = h_max - h_min if max_height > 32: h_max = h_min + random.randint(32, 80 if max_height > 80 else max_height) while (h_max - h_min) % floor_size != 0: h_max -= 1 building.orientation = getOrientation() if building.orientation == "S": door_x = RNG.randint(x_min + 1, x_max - 1) door_z = z_max utilityFunctions.cleanProperty2(matrix, h_min + 1, h_max, door_x - 1, door_x + 1, z_max + 1, building.area.z_max - 1) generateBuildingWalls(matrix, h_min, h_max, floor_size, x_min, x_max, z_min, z_max, wall) generateFloorsDivision(matrix, h_min, h_max, floor_size, x_min, x_max, z_min, z_max, wall) generateDoor(matrix, h_min + 1, door_x, door_z, (64, 9), (64, 3)) building.entranceLot = (h_min + 1, door_x, building.area.z_max) for z in range(door_z + 1, building.area.z_max): matrix.setValue(h_min, door_x, z, pavement_block) matrix.setValue(h_min, door_x - 1, z, pavement_block) matrix.setValue(h_min, door_x + 1, z, pavement_block) # determine which floor have two apartment instead of one double_apartment_floor = pickDoubleapartmentFloor( h_min, h_max, floor_size) # apartment windows generateBuildingWindows_AlongZ(matrix, h_min, h_max, floor_size, x_min, x_max, z_min, double_apartment_floor) # corridor windows generateBuildingWindows_AlongZ(matrix, h_min, h_max, floor_size, x_min, x_max, z_max, []) generateCorridorInterior(matrix, h_min, h_max, floor_size, x_min, x_max, z_max - 6, z_max, fence) generateFloorPlan(matrix, h_min, h_max, floor_size, x_min, x_max, z_min, z_max, wall, double_apartment_floor) generateStairs(matrix, h_min, h_max, floor_size, x_min, x_max, z_min, z_max, wall) generateRoof(matrix, h_min, h_max, floor_size, x_min, x_max, z_min, z_max, biome, usable_wood, wall, stairs) generateApartmentInterior(matrix, h_min, h_max, floor_size, x_min, x_max, z_min, z_max - 6, double_apartment_floor, usable_wood, biome, fence) generateBalconySouth(matrix, h_min, h_max, floor_size, x_min, x_max, z_min, building.area.z_min, building.orientation, double_apartment_floor, wall, slab, stairs, fence, structureBloc) inhabitants = RNG.randint( 1, 2) * (h_max / floor_size) + len(double_apartment_floor) return (building, inhabitants)