def _interior_garden(w, h, wall_material, floor_material): M = Map(w, h, fill_cell=C.floor_rocks) for x in range(w): M[x, h-1] = wall_material() M[w//2, h-1] = C.door_closed_wooden() M[w//2-1, h-1] = C.door_closed_wooden() return M
def _room_rich_hall(w, h): """ Construct luxury hall. """ M = room_default(w, h, wall_type=C.wall_dungeon_smooth, floor_type=C.floor_plank) # Place sofa, flowers, etc. M[1, 1] = C.flora_flower() M[w // 2, 1] = C.column_antique() M[w - 2, 1] = C.flora_flower() M[1, 2].put(T.furniture_sofa()) M[w - 2, 2].put(T.furniture_sofa()) M[w // 2 - 1, h - 2].put(T.furniture_chandelier()) M[w // 2 + 1, h - 2].put(T.furniture_chandelier()) M[2, 0] = C.door_closed() M[7, 0] = C.door_closed() M[w // 2, h - 1] = C.door_closed_wooden() return M
def building_mansion_symmetric(w=25, h=25, wall_material=None, floor_material=None, direction='down'): """ Construct medieval mansion with living rooms, kitchen, library, treasury, servant's room and outdoor. Constraints: - Map width and map height must be >= 20 - Map width and map height must be <= 25 - Wall material must be 'block', 'plank', 'brick' or 'stone'. - Floor material must be 'dirt', 'parquet' or 'cobblestone'. Parameters ---------- w : int Map width h : int Map height wall_material : str Wall's material. floor_material : str Floor's material. direction : str Direction of the house. Can be 'up', 'down', 'left' or 'right'. """ # Initial checks. Don't accept too small/big house if w < 20 or h < 20: raise ValueError('Building is too small: w or h < 20') elif w > 25 or h > 25: raise ValueError('Building is too big: w or h > 25') # Choose materials if not wall_material: wall_material = random.choice( [C.wall_block, C.wall_plank, C.wall_brick, C.wall_stone]) elif wall_material not in (['block', 'plank', 'brick', 'stone']): raise ValueError( 'Wall material should be "block", "plank", "brick" or "stone"') if wall_material == 'block': wall_material = C.wall_block elif wall_material == 'plank': wall_material = C.wall_plank elif wall_material == 'brick': wall_material = C.wall_brick elif wall_material == 'stone': wall_material = C.wall_stone if not floor_material: floor_material = random.choice( [C.floor_dirt, C.floor_parquet, C.floor_cobblestone]) elif floor_material not in (['dirt', 'parquet', 'cobblestone']): raise ValueError( 'Floor material should be "dirt", "parquet" or "cobblestone"') if floor_material == 'dirt': floor_material = C.floor_dirt elif floor_material == 'parquet': floor_material = C.floor_parquet elif floor_material == 'cobblestone': floor_material = C.floor_cobblestone M = room_default(w, h, wall_type=wall_material, floor_type=C.void) default_room_w = w // 4 + 1 default_room_h = h // 4 library_h = h // 2 - 1 second_bedroom_h = h // 4 + 2 treasury = _room_treasury(default_room_w, default_room_h, wall_material, floor_material) M.meld(treasury, 0, 0) bedroom = _room_bedroom(default_room_w, h - second_bedroom_h - default_room_h + 2, wall_material, floor_material) M.meld(bedroom, 0, default_room_h - 1) second_bedroom = _room_second_bedroom(default_room_w, second_bedroom_h, wall_material, floor_material) M.meld(second_bedroom, 0, h - second_bedroom_h) sacrifice = _room_of_sacrifice(default_room_w, default_room_h, wall_material, floor_material) M.meld(sacrifice, w - default_room_w, 0) kitchen = _room_kitchen(default_room_w, h - default_room_h * 2 + 1, wall_material, floor_material) M.meld(kitchen, w - default_room_w, default_room_h - 1) servant = _room_servant(default_room_w, default_room_h + 1, wall_material, floor_material) M.meld(servant, w - default_room_w, h - default_room_h - 1) library = _room_library(w - default_room_w * 2 + 2, library_h, wall_material, floor_material) M.meld(library, default_room_w - 1, 0) garden = _interior_garden(w - default_room_w * 2, h - library_h - 1, wall_material, floor_material) M.meld(garden, default_room_w, library_h) for x in range(w // 2 - 1, w // 2 + 1 + w % 2): M[x, h - 1] = C.door_closed_wooden() if random.choice([True, False]): M.hmirror() if direction == 'up': M.vmirror() elif direction == 'left': M.transpose() elif direction == 'right': M.transpose() M.hmirror() return M
def building_housebarn(w=30, h=15, material=None): """ Construct the housebarn (also known as longhouse) building interior. Parameters ---------- w : int Map width h : int Map height material : string Wall material. Can be "wooden", "stone" or None. If None, a random material will be chosen. """ # Initial checks. Don't accept: # - Too small buildings # - Too long/square buildings # - Wall types that are not "stone" or "wooden" if w < 10 or h < 10: raise ValueError('Building is too small: w/h < 10') if not material: material = random.choice(['wooden', 'stone']) if material not in ('wooden', 'stone'): raise ValueError('Material should be "stone" or "wooden"') wall_cell_type = C.wall_stone if material == 'stone' else C.wall_plank is_horizontal = True if w >= h else False if is_horizontal: if w < h * 2 or w > h * 3: raise ValueError('Building is too long or too short.') else: if h < w * 2 or h > w * 3: raise ValueError('Building is too long or too short.') # If parameters are vertial, we firstly construct horizontal building then transpose it. # It allows not to use two additional different subtypes of the building which will simplify the code. if not is_horizontal: w, h = h, w M = Map(w, h, fill_cell=C.floor_flagged) # Create outward walls for x in range(w): M[x, 0] = wall_cell_type() M[x, h - 1] = wall_cell_type() for y in range(h): M[0, y] = wall_cell_type() M[w - 1, y] = wall_cell_type() # Randomly choose where the living part is living_left = random.choice([True, False]) living_wall_x = None barn_wall_x = None # Place central doors/corridor and calculate X-positions for vertical walls if w % 2 == 0: M[w // 2, 0] = C.floor_flagged() M[w // 2 - 1, 0] = C.floor_flagged() M[w // 2, h - 1] = C.floor_flagged() M[w // 2 - 1, h - 1] = C.floor_flagged() living_wall_x = (w // 2 - 3) if living_left else (w // 2 + 2) barn_wall_x = (w // 2 + 2) if living_left else (w // 2 - 3) else: M[w // 2, 0] = C.door_closed_wooden() M[w // 2, h - 1] = C.door_closed_wooden() living_wall_x = (w // 2 - 2) if living_left else (w // 2 + 2) barn_wall_x = (w // 2 + 2) if living_left else (w // 2 - 2) # Place vertical walls for i in range(1, h // 3): M[living_wall_x, i] = wall_cell_type() M[living_wall_x, h - i - 1] = wall_cell_type() for i in range(1, h - 1): M[barn_wall_x, i] = C.wall_fence_thin() M[barn_wall_x, h // 2] = C.door_closed_wooden() # Create living room: # Set initial coordinates lx_start = 1 if living_left else living_wall_x + 1 lx_end = living_wall_x - 1 if living_left else w - 1 beds_dx = int((lx_end - lx_start) % 2 == 0 and not living_left) beds_dy = random.choice([0, 1]) # Place beds near walls or at 1 cell from walls for bed_x in range(lx_start + beds_dx, lx_end, 2): M[bed_x, 1 + beds_dy].put(T.furniture_bed_single()) M[bed_x, h - 2 - beds_dy].put(T.furniture_bed_single()) # Place bonfire in the middle of the room or hearth on the side of the room is_bonfire = random.choice([True, False]) if is_bonfire: M[(lx_start + lx_end) // 2, h // 2].put(T.bonfire()) elif living_left: M[1, h // 2].put(T.furniture_hearth()) else: M[w - 2, h // 2].put(T.furniture_hearth()) # Create barn: # Set initial coordinates bx_start = 1 if not living_left else barn_wall_x + 1 bx_end = barn_wall_x - 1 if not living_left else w - 2 # Fill the barn floor with dirt for x in range(bx_start, bx_end + 1): for y in range(1, h - 1): M[x, y] = C.floor_dirt() is_central_barn = random.choice([True, False]) if is_central_barn: # Central barn: stalls in the center, two waterthroughs on the side for y in range(h // 3, h * 2 // 3): M[bx_start + 2, y] = C.wall_fence_thin() for x in range(bx_start + 3, bx_end - 2, 2): M[x, h // 2] = C.wall_fence_thin() M[x, h // 2 - 1].put(T.farm_mangler()) M[x, h // 2 + 1].put(T.farm_mangler()) for y in range(h // 3, h * 2 // 3): M[x + 1, y] = C.wall_fence_thin() for x in range(bx_start + 1, bx_end): M[x, 1].put(T.water_trough()) M[x, h - 2].put(T.water_trough()) else: # Side barn: stalls on the side, one waterthrough in the center for x in range(bx_start, bx_end - 1, 2): M[x, 1].put(T.farm_mangler()) M[x, h - 2].put(T.farm_mangler()) for y in range(1, h // 3): M[x + 1, y] = C.wall_fence_thin() for y in range(h * 2 // 3, h - 1): M[x + 1, y] = C.wall_fence_thin() for x in range(bx_start + 2, bx_end - 1): M[x, h // 2].put(T.water_trough()) # Transpose the building if it should be vertical if not is_horizontal: M.transpose() return M