Ejemplo n.º 1
0
def generateTrainLine(matrix, wood_material, nb_stations, height_map, simple_height_map, h_min, h_max, x_min, x_max, z_min, z_max):
	logger = logging.getLogger("trainLine")
	logger.info("Preparation for Train Line generation")
	stations = []

	## Create train line height map
	logger.info("Creating Train Line rail network")
	rail_network = createRailNetwork(simple_height_map, x_min, x_max, z_min, z_max)
	logger.info("Creating Train Line smoothed height map")
	train_line_height_map = createTrainLineHeightMap(rail_network, simple_height_map, h_max, x_min, x_max, z_min, z_max)

	if train_line_height_map == -1:
		logger.error("Train Line height map smoothing failed")
		return
	wooden_materials_kit = utility.wood_IDs[wood_material] # wood_material instead of "urban" for an adaptative wooden rail network
	logger.info("Generating Train Line rails")
	(pillar_coordinates, stations_coordinates) = generateRails(logger, matrix, wooden_materials_kit, nb_stations, height_map, simple_height_map, train_line_height_map, x_min, x_max, z_min, z_max)
	logger.info("Clearing Train Line")
	clearAboveRailNetwork(matrix, train_line_height_map, h_max, x_min, x_max, z_min, z_max)

	for i in range(0, len(stations_coordinates)):
		s = toolbox.dotdict()
		s.type = "trainLine"
		s.lotArea = toolbox.dotdict({"y_min": h_min, "y_max": h_max, "x_min": stations_coordinates[i][0] - 2, "x_max": stations_coordinates[i][0] + 2, "z_min": stations_coordinates[i][1] - 2, "z_max": stations_coordinates[i][1] + 2})
		s.buildArea = toolbox.dotdict({"y_min": h_min, "y_max": h_max, "x_min": stations_coordinates[i][0], "x_max": stations_coordinates[i][0], "z_min": stations_coordinates[i][1], "z_max": stations_coordinates[i][1]})
		s.orientation = "S"
		s.entranceLot = (s.lotArea.x_min + 1, s.lotArea.z_min)
		stations.append(s)
		logger.info("Generating station {}".format(i + 1))
		generateStation(matrix, wooden_materials_kit, simple_height_map, train_line_height_map, stations_coordinates[i][0], stations_coordinates[i][1], stations_coordinates[i][2])

	logger.info("Train Line generaton successful")
	return (pillar_coordinates, stations)
Ejemplo n.º 2
0
def generateFountain(matrix, h_min, h_max, x_min, x_max, z_min, z_max):
	logger = logging.getLogger("fountain")
	logger.info("Preparation for Fountain generation")

	fountain_material = toolbox.getBlockID("double_stone_slab")

	x_center = (x_min + x_max) / 2
	z_center = (z_min + z_max) / 2
	if (h_min + FOUNTAIN_HEIGHT < h_max): h_max = h_min + FOUNTAIN_HEIGHT
	generateStructure(matrix, logger, fountain_material, h_min, h_max, x_center, z_center)

	f = toolbox.dotdict()
	f.type = "fountain"
	f.lotArea = toolbox.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})
	f.buildArea = toolbox.dotdict({"y_min": h_min, "y_max": h_max, "x_min": x_center - 6, "x_max": x_center + 7, "z_min": z_center - 6, "z_max": z_center + 7})
	f.orientation = "S"
	f.entranceLot = (f.lotArea.x_min, f.lotArea.z_min)
	return f
Ejemplo n.º 3
0
def generateRollerCoaster(matrix,
                          wood_material,
                          height_map,
                          h_max,
                          x_min,
                          x_max,
                          z_min,
                          z_max,
                          allowStraightRails=False):
    logger = logging.getLogger("rollerCoaster")
    logger.info("Preparation for Roller Coaster generation")

    cleanProperty(matrix, height_map, h_max, x_min, x_max, z_min, z_max)

    ## Generates the roller coaster
    wooden_materials_kit = utility.wood_IDs[wood_material]
    return_value = generateStructure(logger, matrix, wooden_materials_kit,
                                     height_map, h_max, x_min, x_max, z_min,
                                     z_max, allowStraightRails)
    if return_value == 0:
        return 0
    rc = toolbox.dotdict()
    rc.type = "rollerCoaster"
    rc.lotArea = toolbox.dotdict({
        "y_min": 0,
        "y_max": h_max,
        "x_min": x_min,
        "x_max": x_max,
        "z_min": z_min,
        "z_max": z_max
    })
    rc.buildArea = toolbox.dotdict({
        "y_min": 0,
        "y_max": h_max,
        "x_min": x_min,
        "x_max": x_max,
        "z_min": z_min,
        "z_max": z_max
    })
    rc.orientation = getOrientation()
    rc.entranceLot = (height_map[x_min][z_min], rc.lotArea.x_min,
                      rc.lotArea.z_min)
    return rc
Ejemplo n.º 4
0
def perform(level, box, options):
    logging.info("BoundingBox coordinates: ({},{}),({},{}),({},{})".format(
        box.miny, box.maxy, box.minx, box.maxx, box.minz, box.maxz))

    # ==== PREPARATION =====
    logging.info("Options : {}".format(options))
    logging.info("Preparation")
    (width, height, depth) = toolbox.getBoxSize(box)
    logging.info("Selection box dimensions {}, {}, {}".format(
        width, height, depth))
    world = toolbox.generateMatrix(level, box, width, depth, height)
    world_space = toolbox.dotdict({
        "y_min": 0,
        "y_max": height - 1,
        "x_min": 0,
        "x_max": width - 1,
        "z_min": 0,
        "z_max": depth - 1
    })
    logging.info("Generating simple height map")
    simple_height_map = toolbox.getSimpleHeightMap(
        level, box)  #no height = -1 when water like block
    logging.info("Saving and erasing the trees")
    tree_list = TreeGestion.prepareMap(
        world, simple_height_map
    )  #get a list of all trees and erase them, so we can put some of them back after
    logging.info("Generating normal height map")
    height_map = toolbox.getHeightMap(level, box)
    logging.info("Preparing settlement deck card")
    cityDeck = toolbox.generateCityDeck(options["Settlement type"], width,
                                        depth)
    logging.info("Setting the settlement type")
    tree_counter = TreeGestion.countTreeSpecies(tree_list)
    logging.info(
        "Counting the occurrence of the different tree species in the area")
    wood_material = TreeGestion.selectWoodFromTreeCounter(tree_counter)

    # ==== PARTITIONING OF NEIGHBOURHOODS ====
    logging.info(
        "Partitioning of the map, getting city center and neighbourhoods")
    (center,
     neighbourhoods) = generateCenterAndNeighbourhood(world_space, height_map)
    all_buildings = []

    # ====  GENERATING CITY CENTER ====
    logging.info("Generating city center")
    minimum_h = 50
    minimum_w = 25
    mininum_d = 25

    iterate = 100
    minimum_lots = 6
    available_lots = 0
    maximum_tries = 50
    current_try = 0
    threshold = 20
    partitioning_list = []
    temp_partitioning_list = []

    # run the partitioning algorithm for iterate times to get different partitionings of the same area
    logging.info(
        "Generating {} different partitionings for the the City Centre {}".
        format(iterate, center))
    while available_lots < minimum_lots and current_try < maximum_tries:

        for i in range(iterate):

            # generate a partitioning through some algorithm
            if RNG.random() < 0.5:
                partitioning = binarySpacePartitioning(center[0], center[1],
                                                       center[2], center[3],
                                                       center[4], center[5],
                                                       [])
            else:
                partitioning = quadtreeSpacePartitioning(
                    center[0], center[1], center[2], center[3], center[4],
                    center[5], [])

            # remove invalid partitions from the partitioning
            valid_partitioning = []
            for p in partitioning:
                (y_min, y_max, x_min, x_max, z_min, z_max) = (p[0], p[1], p[2],
                                                              p[3], p[4], p[5])
                failed_conditions = []
                cond1 = toolbox.hasValidGroundBlocks(x_min, x_max, z_min,
                                                     z_max, height_map)
                if cond1 == False: failed_conditions.append(1)
                cond2 = toolbox.hasMinimumSize(y_min, y_max, x_min, x_max,
                                               z_min, z_max, minimum_h,
                                               minimum_w, mininum_d)
                if cond2 == False: failed_conditions.append(2)
                cond3 = toolbox.hasAcceptableSteepness(
                    x_min, x_max, z_min, z_max, height_map,
                    toolbox.getScoreArea_type4, threshold)
                if cond3 == False: failed_conditions.append(3)
                if cond1 and cond2 and cond3:
                    score = toolbox.getScoreArea_type4(height_map, x_min,
                                                       x_max, z_min, z_max)
                    valid_partitioning.append((score, p))
                    logging.info("Passed the 3 conditions!")
                else:
                    logging.info(
                        "Failed Conditions {}".format(failed_conditions))

            partitioning_list.extend(valid_partitioning)
            logging.info(
                "Generated a partition with {} valid lots and {} invalids ones"
                .format(len(valid_partitioning),
                        len(partitioning) - len(valid_partitioning)))

        # sort partitions by steepness
        partitioning_list = sorted(partitioning_list)
        final_partitioning = toolbox.getNonIntersectingPartitions(
            partitioning_list)

        available_lots = len(final_partitioning)
        logging.info(
            "Current partitioning with most available_lots: {}, current threshold {}"
            .format(available_lots, threshold))

        threshold += 2
        current_try += 1

    logging.info("Final lots ({}) for the City Centre {}: ".format(
        len(final_partitioning), center))
    for (score, partition) in final_partitioning:
        logging.info("\t{}".format(partition))

    #for (score, partition) in final_partitioning:
    #	#building = generateBuilding(world, partition, height_map, simple_height_map)
    #	wood_material = TreeGestion.selectWoodFromTreeCounter(tree_counter)
    #	logging.info("Wood material used : {}".format(wood_material))
    #	building = generateStructureFromDeck(world, score, partition, height_map, simple_height_map, wood_material, cityDeck, "center")
    #	all_buildings.append(building)

    l = len(final_partitioning)
    fountain = generateFountain(world, final_partitioning[0][1], height_map,
                                simple_height_map)
    all_buildings.append(fountain)
    for i in range(1, l):
        wood_material = TreeGestion.selectWoodFromTreeCounter(tree_counter)
        logging.info("Wood material used : {}".format(wood_material))
        score = i / (l * 1.0)  # turns the result to float
        building = generateStructureFromDeck(world, score,
                                             final_partitioning[i][1],
                                             height_map, simple_height_map,
                                             wood_material, cityDeck, "center")
        all_buildings.append(building)

    # ==== GENERATING NEIGHBOURHOODS ====
    logging.info("Generating neighbourhoods")
    minimum_h = 10
    minimum_w = 16
    mininum_d = 16

    iterate = 100
    maximum_tries = 80
    current_try = 0
    minimum_lots = 50
    available_lots = 0
    threshold = 50
    partitioning_list = []
    final_partitioning = []

    while available_lots < minimum_lots and current_try < maximum_tries:
        partitioning_list = []
        for i in range(iterate):
            for neigh in neighbourhoods:
                logging.info(
                    "Generating {} different partitionings for the neighbourhood {}"
                    .format(iterate, neigh))

                if RNG.random() < 0.5:
                    partitioning = binarySpacePartitioning(
                        neigh[0], neigh[1], neigh[2], neigh[3], neigh[4],
                        neigh[5], [])
                else:
                    partitioning = quadtreeSpacePartitioning(
                        neigh[0], neigh[1], neigh[2], neigh[3], neigh[4],
                        neigh[5], [])

                valid_partitioning = []
                for p in partitioning:
                    (y_min, y_max, x_min, x_max, z_min,
                     z_max) = (p[0], p[1], p[2], p[3], p[4], p[5])
                    failed_conditions = []
                    cond1 = toolbox.hasValidGroundBlocks(
                        x_min, x_max, z_min, z_max, height_map)
                    if cond1 == False: failed_conditions.append(1)
                    cond2 = toolbox.hasMinimumSize(y_min, y_max, x_min, x_max,
                                                   z_min, z_max, minimum_h,
                                                   minimum_w, mininum_d)
                    if cond2 == False: failed_conditions.append(2)
                    cond3 = toolbox.hasAcceptableSteepness(
                        x_min, x_max, z_min, z_max, height_map,
                        toolbox.getScoreArea_type4, threshold)
                    if cond3 == False: failed_conditions.append(3)
                    if cond1 and cond2 and cond3:
                        score = toolbox.getScoreArea_type4(
                            height_map, x_min, x_max, z_min, z_max)
                        valid_partitioning.append((score, p))
                        logging.info("Passed the 3 conditions!")
                    else:
                        logging.info(
                            "Failed Conditions {}".format(failed_conditions))

                partitioning_list.extend(valid_partitioning)
                logging.info(
                    "Generated a partition with {} valid lots and {} invalids ones"
                    .format(len(valid_partitioning),
                            len(partitioning) - len(valid_partitioning)))

        temp_partitioning_list.extend(partitioning_list)

        # sort partitions by steepness
        temp_partitioning_list = sorted(temp_partitioning_list)
        final_partitioning = toolbox.getNonIntersectingPartitions(
            temp_partitioning_list)

        available_lots = len(final_partitioning)
        logging.info(
            "Current neighbourhood partitioning with most available_lots: {}, current threshold {}"
            .format(available_lots, threshold))

        threshold += 2
        current_try += 1

    logging.info("Final lots ({})for the neighbourhood {}: ".format(
        len(final_partitioning), neigh))
    for (score, partition) in final_partitioning:
        logging.info("\t{}".format(partition))

    logging.info("Building in the neighbourhood")

    #for (score, partition) in final_partitioning:
    #	wood_material = TreeGestion.selectWoodFromTreeCounter(tree_counter)
    #	logging.info("Wood material used : {}".format(wood_material))
    #	building = generateStructureFromDeck(world, score, partition, height_map, simple_height_map, wood_material, cityDeck, "neighbourhood")
    #	all_buildings.append(building)

    l = len(final_partitioning)
    for i in range(l):
        wood_material = TreeGestion.selectWoodFromTreeCounter(tree_counter)
        logging.info("Wood material used : {}".format(wood_material))
        score = i / (l * 1.0)  # turns the result to float
        building = generateStructureFromDeck(world, score,
                                             final_partitioning[i][1],
                                             height_map, simple_height_map,
                                             wood_material, cityDeck,
                                             "neighbourhood")
        all_buildings.append(building)

    #n = 0
    #for i in xrange(0, int(len(final_partitioning) * 0.50) + 1):
    #	house = generateHouse(world, final_partitioning[i], height_map, simple_height_map)
    #	all_buildings.append(house)
    #	logging.info("House number : {} built on lot number {}".format(n + 1, i + 1))
    #	n += 1
    #n = 0
    #for i in xrange(int(len(final_partitioning) * 0.50) + 1, int(len(final_partitioning) * 0.70) + 1):
    #	# generate either a regular farm or a smiley farm
    #	farm = generateFarm(world, final_partitioning[i], height_map, simple_height_map) if (RNG.randint(0, 2) == 0) else generateFarm(world, final_partitioning[i], height_map, simple_height_map, "smiley")
    #	all_buildings.append(farm)
    #	logging.info("Farm number : {} built on lot number {}".format(n + 1, i + 1))
    #	n += 1
    #n = 0
    #m = 0
    #for i in xrange(int(len(final_partitioning)*0.70)+1, len(final_partitioning)):
    #	RollerCoaster = generateRollerCoaster(world, final_partitioning[i], height_map, simple_height_map)
    #	if RollerCoaster.type == "tower":
    #		all_buildings.append(RollerCoaster)
    #		logging.info("Tower number : {} built on lot number {}".format(n + 1, i + 1))
    #		n += 1
    #	else:
    #		logging.info("RollerCoaster number : {} built on lot number {}".format(m + 1, i + 1))
    #		m += 1

    # ==== GENERATE THE TrainLine NETWORK ====
    if options["allow Train Line"] == True:
        wood_material = "urban" if options[
            "Train Line Style"] == "Urban" else TreeGestion.selectWoodFromTreeCounter(
                tree_counter)

        stations = generateTrainLine(world, center, height_map,
                                     simple_height_map, wood_material,
                                     cityDeck.getNbStations())
        for station in stations:
            all_buildings.append(station)

    # ==== GENERATE PATH MAP  ====
    # generate a path map that gives the cost of moving to each neighbouring cell
    logging.info("Generating path map and simple path map")
    pathMap = toolbox.getPathMap(height_map, width, depth)
    simple_pathMap = toolbox.getPathMap(simple_height_map, width,
                                        depth)  #not affected by water

    # ==== CONNECTING BUILDINGS WITH ROADS  ====
    logging.info("Calling MST on {} buildings".format(len(all_buildings)))
    MST = toolbox.getMST_Manhattan(all_buildings)

    for m in MST:
        p1 = m[1]
        p2 = m[2]
        if p1.type == "farm" or p2.type == "farm":
            pavement_Type = "Grass"
            bridge_Type = "Wood"
        else:
            pavement_Type = "Stone"
            bridge_Type = "Stone"

        try:
            logging.info(
                "Trying to find a path between {} and {}, finding potential bridges"
                .format(p1.entranceLot, p2.entranceLot))
            simple_path = toolbox.simpleAStar(
                p1.entranceLot, p2.entranceLot, simple_pathMap,
                simple_height_map)  #water and height are not important
            list_end_points = toolbox.findBridgeEndPoints(
                world, simple_path, simple_height_map)

            if list_end_points != []:
                for i in xrange(0, len(list_end_points), 2):
                    logging.info(
                        "Found water between {} and {}. Trying to generating a {} bridge..."
                        .format(list_end_points[i], list_end_points[i + 1],
                                bridge_Type))
                    Bridge.generateBridge(world, simple_height_map,
                                          list_end_points[i],
                                          list_end_points[i + 1], bridge_Type)
                list_end_points.insert(0, p1.entranceLot)
                list_end_points.append(p2.entranceLot)
                for i in xrange(0, len(list_end_points), 2):
                    path = toolbox.aStar(list_end_points[i],
                                         list_end_points[i + 1], pathMap,
                                         height_map)
                    logging.info(
                        "Connecting end points of the bridge(s), Generating {} road between {} and {}"
                        .format(pavement_Type, list_end_points[i],
                                list_end_points[i + 1]))
                    Path.generatePath(world, path, height_map, pavement_Type)
            else:
                logging.info(
                    "No potential bridge found, Generating road between {} and {}"
                    .format(list_end_points[i], list_end_points[i + 1]))
                Path.generatePath(world, simple_path, height_map,
                                  pavement_Type)

        except:
            logging.info(
                "Bridge found but is not buildable, Trying to find a path between {} and {} avoiding water"
                .format(p1.entranceLot, p2.entranceLot))
            path = toolbox.aStar(p1.entranceLot, p2.entranceLot, pathMap,
                                 height_map)
            if path != None:
                logging.info(
                    "Path found, Generating {} road between {} and {}".format(
                        pavement_Type, p1.entranceLot, p2.entranceLot))
                Path.generatePath(world, path, height_map, pavement_Type)
            else:
                logging.info(
                    "Couldnt find path between {} and {}. Generating a straight road"
                    .format(p1.entranceLot, p2.entranceLot))
                #Path.generatePath_StraightLine(world, p1.entranceLot[1], p1.entranceLot[2], p2.entranceLot[1], p2.entranceLot[2], height_map, pavement_Type)

    # ==== PUT BACK UNTOUCHED TREES ====
    logging.info("Putting back untouched trees")
    TreeGestion.putBackTrees(
        world, height_map, tree_list
    )  #put back the trees that are not cut buy the building and are not in unwanted places

    # ==== UPDATE WORLD ====
    if options["Generation"] == True:
        logging.info("Generating the world")
        world.updateWorld()
    else:
        logging.info("Generation set to false, stops here")
Ejemplo n.º 5
0
def generateFarm(matrix, wood_material, h_min, h_max, x_min, x_max, z_min,
                 z_max, farmType):
    logger = logging.getLogger("farm")

    farm = toolbox.dotdict()
    farm.type = "farm"
    farm.lotArea = toolbox.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
    })

    toolbox.cleanProperty(matrix, h_min + 1, h_max, x_min, x_max, z_min, z_max)

    (h_min, h_max, x_min, x_max, z_min,
     z_max) = getFarmAreaInsideLot(h_min, h_max, x_min, x_max, z_min, z_max,
                                   farmType)
    farm.buildArea = toolbox.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
    })

    logger.info("Generating Farm at area {}".format(farm.lotArea))
    logger.info("Construction area {}".format(farm.buildArea))

    farm.orientation = getOrientation(matrix, farm.lotArea)

    ## Generates the farm
    wooden_materials_kit = utility.wood_IDs[wood_material]
    if farmType == None:
        generateBasicPattern(matrix, wooden_materials_kit, h_min, x_min, x_max,
                             z_min, z_max)
    elif farmType == "smiley":
        generateSmileyPattern(matrix, wooden_materials_kit, h_min, x_min,
                              x_max, z_min, z_max)

    #create door and entrance path
    if farm.orientation == "S":
        door_x = x_max - 2
        door_z = z_max - 1
        farm.entranceLot = (door_x, farm.lotArea.z_max)
        generateEntrance(matrix, wooden_materials_kit, 0, h_min, door_x,
                         door_z, door_z + 1, farm.lotArea.z_max + 1)

    elif farm.orientation == "N":
        door_x = x_min + 2
        door_z = z_min + 1
        farm.entranceLot = (door_x, farm.lotArea.z_min)
        generateEntrance(matrix, wooden_materials_kit, 2, h_min, door_x,
                         door_z, farm.lotArea.z_min, door_z)

    elif farm.orientation == "W":
        door_x = x_min + 1
        door_z = z_max - 2
        farm.entranceLot = (farm.lotArea.x_min, door_z)
        generateEntrance(matrix, wooden_materials_kit, 1, h_min, door_x,
                         door_z, farm.lotArea.x_min, door_x)

    elif farm.orientation == "E":
        door_x = x_max - 1
        door_z = z_min + 2
        farm.entranceLot = (farm.lotArea.x_max, door_z)
        generateEntrance(matrix, wooden_materials_kit, 3, h_min, door_x,
                         door_z, door_x + 1, farm.lotArea.x_max + 1)

    return farm
Ejemplo n.º 6
0
def generateBuilding(matrix, h_min, h_max, x_min, x_max, z_min, z_max):
    logger = logging.getLogger("building")

    building = toolbox.dotdict()
    building.type = "building"
    building.lotArea = toolbox.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
    })

    toolbox.cleanProperty(matrix, h_min + 1, h_max, x_min, x_max, z_min, 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.buildArea = (h_min, h_max, x_min, x_max, z_min, z_max)

    logger.info("Generating Building at area {}".format(building.lotArea))
    logger.info("Construction area {}".format(building.buildArea))

    wall = (159, random.randint(0, 15))
    ceiling = wall
    floor = wall

    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

    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)

    building.orientation = getOrientation()

    if building.orientation == "S":
        door_x = RNG.randint(x_min + 1, x_max - 1)
        door_z = z_max
        generateDoor(matrix, h_min + 1, door_x, door_z, (64, 9), (64, 3))
        building.entranceLot = (door_x, building.lotArea.z_max)
        for z in range(door_z + 1, building.lotArea.z_max + 1):
            matrix.setValue(h_min, door_x, z, (1, 6))
            matrix.setValue(h_min, door_x - 1, z, (1, 6))
            matrix.setValue(h_min, door_x + 1, z, (1, 6))

        # apartment windows
        generateBuildingWindows_AlongZ(matrix, h_min, h_max, floor_size, x_min,
                                       x_max, z_min)
        # 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)
        generateFloorPlan(matrix, h_min, h_max, floor_size, x_min, x_max,
                          z_min, z_max, wall)

        generateStairs(matrix, h_min, h_max, floor_size, x_min, x_max, z_min,
                       z_max, wall)
        generateApartmentInterior(matrix, h_min, h_max, floor_size, x_min,
                                  x_max, z_min, z_max - 6)

    return building
Ejemplo n.º 7
0
def generateHouse(matrix,
                  wood_material,
                  h_min,
                  h_max,
                  x_min,
                  x_max,
                  z_min,
                  z_max,
                  ceiling=None):
    logger = logging.getLogger("house")

    house = toolbox.dotdict()
    house.type = "house"
    house.lotArea = toolbox.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
    })

    toolbox.cleanProperty(matrix, h_min + 1, h_max, 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 = toolbox.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
    })

    logger.info("Generating House at area {}".format(house.lotArea))
    logger.info("Construction area {}".format(house.buildArea))

    ## Generates the house
    wooden_materials_kit = utility.wood_IDs[wood_material]

    wall = toolbox.getBlockID("double_stone_slab", RNG.randint(11, 15))
    floor = wall
    ceiling = wooden_materials_kit["planks"] if ceiling == None else ceiling
    door_ID = wooden_materials_kit["door"][0]
    window = toolbox.getBlockID("glass")
    fence = wooden_materials_kit["fence"]
    fence_gate_ID = wooden_materials_kit["fence_gate"][0]
    path = toolbox.getBlockID("stone", 6)

    # 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)
    generateFloor(matrix, house.buildArea.y_min, house.buildArea.x_min,
                  house.buildArea.x_max, house.buildArea.z_min,
                  house.buildArea.z_max, floor)

    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_orientation = (9, 1)
        door_x = RNG.randint(house.buildArea.x_min + 4,
                             house.buildArea.x_max - 4)
        door_z = house.buildArea.z_min
        generateDoor(matrix, door_y, door_x, door_z,
                     (door_ID, door_orientation[0]),
                     (door_ID, door_orientation[1]))
        house.entranceLot = (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, path)
            matrix.setValue(h_min, door_x - 1, z, path)
            matrix.setValue(h_min, door_x + 1, z, path)

    elif house.orientation == "S":
        door_orientation = (9, 3)
        door_x = RNG.randint(house.buildArea.x_min + 4,
                             house.buildArea.x_max - 4)
        door_z = house.buildArea.z_max
        generateDoor(matrix, door_y, door_x, door_z,
                     (door_ID, door_orientation[0]),
                     (door_ID, door_orientation[1]))
        house.entranceLot = (door_x, house.lotArea.z_max)
        # entrance path
        for z in range(door_z + 1, house.lotArea.z_max + 1):
            matrix.setValue(h_min, door_x, z, path)
            matrix.setValue(h_min, door_x - 1, z, path)
            matrix.setValue(h_min, door_x + 1, z, path)

    elif house.orientation == "W":
        door_orientation = (8, 0)
        door_x = house.buildArea.x_min
        door_z = RNG.randint(house.buildArea.z_min + 4,
                             house.buildArea.z_max - 4)
        generateDoor(matrix, door_y, door_x, door_z,
                     (door_ID, door_orientation[0]),
                     (door_ID, door_orientation[1]))
        house.entranceLot = (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, path)
            matrix.setValue(h_min, x, door_z - 1, path)
            matrix.setValue(h_min, x, door_z + 1, path)

    elif house.orientation == "E":
        door_orientation = (9, 2)
        door_x = house.buildArea.x_max
        door_z = RNG.randint(house.buildArea.z_min + 4,
                             house.buildArea.z_max - 4)
        generateDoor(matrix, door_y, door_x, door_z,
                     (door_ID, door_orientation[0]),
                     (door_ID, door_orientation[1]))
        house.entranceLot = (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, path)
            matrix.setValue(h_min, x, door_z - 1, path)
            matrix.setValue(h_min, x, door_z + 1, path)

    if house.orientation == "N" or house.orientation == "S":
        generateWindow_alongX(matrix, window, window_y, house.buildArea.x_min,
                              house.buildArea.z_min, house.buildArea.z_max)
        generateWindow_alongX(matrix, window, 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, wall, 0)

    elif house.orientation == "E" or house.orientation == "W":
        generateWindow_alongZ(matrix, window, window_y, house.buildArea.z_min,
                              house.buildArea.x_min, house.buildArea.x_max)
        generateWindow_alongZ(matrix, window, 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, wall, 0)

    generateInterior(matrix, h_min, ceiling_bottom, house.buildArea.x_min,
                     house.buildArea.x_max, house.buildArea.z_min,
                     house.buildArea.z_max, ceiling)
    generateGarden(logger, matrix, house, fence, fence_gate_ID)

    return house
Ejemplo n.º 8
0
def generateTower(matrix, x_min, x_max, z_min, z_max, height_map):
    logger = logging.getLogger("tower")

    tower = toolbox.dotdict()
    tower.type = "tower"

    (h_tower, min_h, max_h, x_min, x_max, z_min,
     z_max) = getTowerAreaInsideLot(x_min, x_max, z_min, z_max, height_map)

    tower.buildArea = toolbox.dotdict({
        "y_min": min_h,
        "y_max": h_tower,
        "x_min": x_min,
        "x_max": x_max,
        "z_min": z_min,
        "z_max": z_max
    })
    (door_pos, door_y,
     tower.orientation) = getOrientationT(matrix, tower.buildArea, height_map)
    cleanTowerArea(matrix, door_y - 1, h_tower + 3, x_min, x_max, z_min, z_max)

    logger.info("Generating Tower at area {}".format(tower.buildArea))

    wall = (45, 0)
    floor = wall

    generateWalls(matrix, min_h + 1, h_tower, x_min, x_max, z_min, z_max, wall)
    generateCeiling(matrix, h_tower, x_min, x_max, z_min, z_max)

    if tower.orientation == "N":
        door_x = door_pos[0]
        door_z = door_pos[1]
        generateDoor(matrix, door_y, door_x, door_z, (64, 9), (64, 1))
        tower.entranceLot = (door_x, door_z - 1)
        matrix.setValue(door_y - 1, door_x, door_z - 1, (1, 6))

    elif tower.orientation == "S":
        door_x = door_pos[0]
        door_z = door_pos[1]
        generateDoor(matrix, door_y, door_x, door_z, (64, 9), (64, 3))
        tower.entranceLot = (door_x, door_z + 1)
        matrix.setValue(door_y - 1, door_x, door_z + 1, (1, 6))

    elif tower.orientation == "W":
        door_x = door_pos[0]
        door_z = door_pos[1]
        generateDoor(matrix, door_y, door_x, door_z, (64, 8), (64, 0))
        tower.entranceLot = (door_x - 1, door_z)
        matrix.setValue(door_y - 1, door_x - 1, door_z, (1, 6))

    elif tower.orientation == "E":
        door_x = door_pos[0]
        door_z = door_pos[1]
        generateDoor(matrix, door_y, door_x, door_z, (64, 9), (64, 2))
        tower.entranceLot = (door_x + 1, door_z)
        matrix.setValue(door_y - 1, door_x + 1, door_z, (1, 6))

    generateFloor(matrix, door_y - 1, x_min, x_max, z_min, z_max, floor)
    generateInside(matrix, door_y, h_tower, x_min, x_max, z_min, z_max,
                   tower.orientation)

    return tower