def _room_library(w, h, wall_material, floor_material): M = room_default(w, h, wall_type=wall_material, floor_type=floor_material) for x in range(1, w // 2 - 1): M[x, 1].put(T.furniture_bookcase()) for x in range(w // 2 + 1 + w % 2, w - 1): M[x, 1].put(T.furniture_bookcase()) for x in (1, w - 2): M[x, 2].put(T.furniture_bookcase()) M[x, h - 2] = C.column_antique() for x in (0, w - 1): M[x, 2] = C.door_open_stairs() M[x, h - 3] = C.door_closed() for x in range(w // 2 - 1, w // 2 + 1 + w % 2): M[x, 1].put(T.furniture_hearth()) M[x, 3].put(T.furniture_sofa()) M[x, h - 3].put(T.furniture_chair()) M[x, h - 1] = C.door_open_empty() items = [T.book(), T.book()] M.scatter(2, 2, w - 2, 3, items) for x in range(3, w - 3): M[x, h - 4].put(T.furniture_longtable()) for x in (2, w - 3): M[x, h - 4].put(T.furniture_chair()) for x in (3, w - 4): M[x, h - 5].put(T.furniture_chandelier()) return M
def room_storage(w, h): """ Construct small storage with horse food and some stuff for stableman. """ M = room_default(w, h, wall_type=C.wall_plank, floor_type=C.floor_dirt) number_of_items = (w - 1) * (h - 1) // 10 # Place horse food. all_coord = [] for item_class in (T.farm_mangler, T.furniture_barrel, T.furniture_box_filled): for _ in range(number_of_items): while True: x = random.randint(1, w - 2) y = random.randint(1, h * 2 // 3 - 1) if (x, y) not in all_coord: M[x, y].put(item_class()) all_coord.append((x, y)) break # Place horseman stuff. M[w // 2 - 1, h - 1] = C.door_closed() M[1, h - 2].put(T.light_torch()) M[1, h - 4].put(T.furniture_napsack()) M[w - 2, h - 2].put(T.furniture_table()) M[w - 2, h - 3].put(T.furniture_chair()) return M
def _room_jailer(w=5, h=5): M = Map(w, h, fill_cell=C.floor_flagged) # Create walls for x in range(0, w): M[x, 0] = C.wall_stone() M[x, h - 1] = C.wall_stone() for y in range(0, h): M[0, y] = C.wall_stone() M[w - 1, y] = C.wall_stone() M[w // 2, 0] = C.door_closed() # Place furniture and items in the room all_coord = [(w // 2, 1)] for item_class in (T.furniture_bed_single, T.furniture_chest, T.furniture_chair, T.furniture_table, T.furniture_torch): while True: x = random.randint(1, w - 2) y = random.randint(1, h - 2) if (x, y) not in all_coord: M[x, y].put(item_class()) all_coord.append((x, y)) break return M
def _room_torture(w=5, h=5): M = Map(w, h, fill_cell=C.floor_flagged) # Create walls for x in range(0, w): M[x, 0] = C.wall_stone() M[x, h - 1] = C.wall_stone() for y in range(0, h): M[0, y] = C.wall_stone() M[w - 1, y] = C.wall_stone() M[w // 2, h - 1] = C.door_closed() M[w // 2 + 1, h - 2] = C.stairs_up() # Place furniture and items in the room M[w // 2, h // 2].put(T.furniture_torture()) all_coord = [(w // 2, h - 2), (w // 2, h // 2), (w // 2 + 1, h - 2)] for item_class in (T.bones, T.bones_skull, T.tool_tongs): while True: x = random.randint(1, w - 2) y = random.randint(1, h - 2) if (x, y) not in all_coord: M[x, y].put(item_class()) all_coord.append((x, y)) break return M
def _room_private(w, h, orientation='left'): """ Construct private room. """ M = room_default(w, h, wall_type=C.wall_dungeon_smooth, floor_type=C.floor_plank) # Place some things. M[1, 1].put(T.book()) M[1, h // 2].put(T.furniture_longtable()) for x in range(1, w - 2): M[x, h // 2 + 1].put(T.furniture_chair()) M[w // 2 - 1, h // 2 - 1].put(T.furniture_chair()) if w > 5: for x in range(2, w - 3): M[x, h // 2].put(T.furniture_longtable()) M[w - 3, h // 2].put(T.furniture_longtable()) M[w - 2, 0] = C.door_closed() M[w - 2, h // 2].put(T.furniture_chandelier()) if orientation == 'right': M.hmirror() return M
def _room_main(w, h, wall_material, floor_material): M = room_default(w, h, wall_type=wall_material, floor_type=floor_material) M[1, h - 2].put(T.furniture_closet()) M[w - 2, 1].put(random.choice([T.furniture_chimney(), T.furniture_hearth()])) M[w - 2, 2].put(random.choice([T.food_meat(), T.food_egg()])) for x in (w - 3, w - 4): M[x, 1].put(T.furniture_longtable()) M[w - 5, 1].put(random.choice([T.bucket(), T.bag()])) M[w - 2, h - 2].put(T.furniture_chest_profile()) lantern_w = random.randint(5, w - 4) M[lantern_w, h - 2].put(T.light_lantern()) M[3, h - 1] = C.door_closed() if w >= 11: table_h = 1 if h <= 7 else h // 2 - 1 M[4, table_h].put(T.furniture_table()) M[3, table_h].put(T.furniture_stool()) M[5, table_h].put(T.furniture_stool()) M[4, table_h + 1].put(T.furniture_stool()) if table_h > 1: pantry = _interior_pantry(3, h // 3, wall_material, floor_material) M.meld(pantry, 1, 1) elif w < 11: pantry = _interior_pantry(3, h // 3, wall_material, floor_material) M.meld(pantry, 1, 1) return M
def _room_private(w, h, wall_material, floor_material): M = room_default(w, h, wall_type=wall_material, floor_type=floor_material) for x in (1, 4): M[x, 1].put(T.furniture_chair()) for x in (2, 3): M[x, 1].put(T.furniture_longtable()) M[5, 1].put(T.light_lantern_oil()) M[w-2, h-1] = C.door_closed() 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 _room_rich(w, h, wall_material, floor_material): M = room_default(w, h, wall_type=wall_material, floor_type=floor_material) M[random.randint(1, w-2), 1].put(T.furniture_bed_double()) items = [ T.furniture_chest_profile(), T.furniture_bookcase(), T.light_lantern_oil(), T.furniture_cabinet(), T.furniture_closet() ] M.scatter(1, 1, w-1, h-1, items, exclude=[(2, h-2), (2, h-3), (2, h-4), (1, h-3), (3, h-3)]) M[2, h-1] = C.door_closed() return M
def _create_doors(M, room_size): """Create door in every wall that connects two rooms.""" w, h = M.get_size() x_rooms = ((w - 1) // (room_size + 1)) y_rooms = ((h - 1) // (room_size + 1)) for i in range(1, y_rooms): for j in range(1, x_rooms): if i == 1: y = i * (room_size + 1) - random.randint(1, room_size) x = j * (room_size + 1) M[x, y] = C.door_closed() if j == 1: y = i * (room_size + 1) x = j * (room_size + 1) - random.randint(1, room_size) M[x, y] = C.door_closed() y = i * (room_size + 1) x = j * (room_size + 1) + random.randint(1, room_size) M[x, y] = C.door_closed() y = i * (room_size + 1) + random.randint(1, room_size) x = j * (room_size + 1) M[x, y] = C.door_closed()
def _room_poor(w, h, wall_material, floor_material, direction='right'): M = room_default(w, h, wall_type=wall_material, floor_type=floor_material) M[w-1, 1] = C.door_closed() room_items = { 'default_room': [T.furniture_bed_single(), T.furniture_chest_profile(), T.furniture_torch()], 'default_room_2': [T.furniture_bed_single(), T.furniture_cabinet(), T.furniture_torch()], 'poor_room': [T.furniture_napsack(), T.light_candle(), T.web()], 'poor_room_2': [T.furniture_napsack(), T.furniture_chair()] } M.scatter(1, 1, w-1, h-1, random.choice(list(room_items.values())), exclude=[(w-2, 1)]) if direction == 'left': M.hmirror() return M
def _room_second_bedroom(w, h, wall_material, floor_material): M = room_default(w, h, wall_type=wall_material, floor_type=floor_material) M[1, 1] = C.flora_flower() M[w - 3, 1].put(T.furniture_table()) M[w - 2, 1].put(T.furniture_chair()) M[1, h // 2].put(T.furniture_closet()) items = [ T.furniture_cabinet(), T.furniture_bed_single(), T.furniture_chandelier() ] M.scatter(1, h - 2, w - 1, h - 1, items) M[w - 1, h - 5] = C.door_closed() return M
def room_horse_box(w, h, orientation='left'): """ Construct small horse box. """ M = Map(w, h, fill_cell=C.floor_rocks) # Place watertrough and horse food. M[0, 0].put(T.water_trough()) M[w - 1, 0] = C.door_closed() M[0, h - 1].put(T.water_trough()) M[w - 1, h - 1] = C.wall_fence() if h > 2: for y in range(1, h - 1): M[0, y].put(T.water_trough()) M[w - 1, y] = C.wall_fence() # Create horse box with animal or without. stable_with_horse_chance = random.random() all_coord = [] while True: x = random.randint(1, w - 2) y = random.randint(0, h - 1) if (x, y) not in all_coord: M[x, y] = C.flora_grass() all_coord.append((x, y)) break if stable_with_horse_chance > 0.3: while True: x = random.randint(1, w - 2) y = random.randint(0, h - 1) if (x, y) not in all_coord: M[x, y].put(T.farm_mangler()) all_coord.append((x, y)) break while True: x = random.randint(1, w - 2) y = random.randint(0, h - 1) if (x, y) not in all_coord: M[x, y].put(A.animal_horse()) all_coord.append((x, y)) break if orientation == 'right': M.hmirror() return M
def _room_prison_center(w=5, h=5): M = Map(w, h, fill_cell=C.floor_flagged) if w > 8 and h > 4: jailer_room = _room_jailer(w // 2 + 1, h) M.meld(jailer_room, 0, 0) torture_room = _room_torture(w - w // 2, h) M.meld(torture_room, (w - w // 2) - 1, 0) elif h > 8 and w > 4: jailer_room = _room_jailer(w, h // 2 + 1) M.meld(jailer_room, 0, 0) torture_room = _room_torture(w, h - h // 2) M.meld(torture_room, 0, (h - h // 2) - 1) else: for x in range(0, w): M[x, 0] = C.wall_stone() M[x, h - 1] = C.wall_stone() for y in range(0, h): M[0, y] = C.wall_stone() M[w - 1, y] = C.wall_stone() M[w // 2, 0] = C.door_closed() M[w // 2, h // 2] = C.stairs_up() return M
def _room_poor_part(w, h): """ Construct poor part of the bank. It consists small office rooms for employees and hall for poors. """ M = room_default(w, h, wall_type=C.wall_dungeon_smooth, floor_type=C.floor_plank) # Every small office has width=5 (with walls), except the last, so each small office will occupy 4 cells in width. num_of_small_office = w // 4 # Calculate w-size of the last small office. shift_w = w % 4 if shift_w == 1: small_room_w = 5 elif shift_w == 2: small_room_w = 6 elif shift_w == 3: small_room_w = 7 elif shift_w == 0: small_room_w = 6 # Place small office rooms. if shift_w == 1: # All small offices has an equal width and fill all width of the room. for cell_index in range(num_of_small_office): cell_x = cell_index * 4 M_cell = _room_small_office(w=small_room_w, h=5) M.meld(M_cell, cell_x, 0) elif shift_w == 0: # The last small office is wider and there is the corridor to the main office in the end of the room. for cell_index in range(num_of_small_office - 1): cell_x = cell_index * 4 M_cell = _room_small_office(w=5, h=5) M.meld(M_cell, cell_x, 0) M_room = _room_small_office(w=small_room_w, h=5) M.meld(M_room, (num_of_small_office - 2) * 4, 0) M[w - 2, 0] = C.floor_plank() M[w - 2, 4] = C.door_closed() else: # The last small office is wider and small offices fill all width of the room. for cell_index in range(num_of_small_office - 1): cell_x = cell_index * 4 M_cell = _room_small_office(w=5, h=5) M.meld(M_cell, cell_x, 0) M_room = _room_small_office(w=small_room_w, h=5) M.meld(M_room, (num_of_small_office - 1) * 4, 0) # Place two longtables in right and left part of hall and some chairs. table_length = w // 3 for x in range(1, table_length): M[x, h - 4].put(T.furniture_longtable()) for x in range(1, table_length, 2): M[x, h - 3].put(T.furniture_stool()) for x in range(w - table_length, w - 1): M[x, h - 4].put(T.furniture_longtable()) for x in range(w - table_length, w - 1, 2): M[x, h - 3].put(T.furniture_stool()) M[w // 2, h - 1] = C.door_closed() return M
def _room_shop(w, h, shop_type, wall_material, floor_material): M = room_default(w, h, wall_type=wall_material, floor_type=floor_material) M[w // 2, h - 1] = C.door_closed() M[1, h - 2].put(T.light_lantern_oil()) shop_counter_h = h // 2 - 1 for x in range(w - 3): cell_x = 2 + x M[cell_x, shop_counter_h].put(T.furniture_longtable_showcase()) M[w - 2, shop_counter_h - 1].put(T.money_pile()) type_items = { 'food': [T.food_meat(), T.food_carrot(), T.food_apple()], 'jewelry': [T.necklace(), T.necklace_star(), T.ring()], 'clothe': [T.clothes_coat(), T.clothes_hat(), T.clothes_belt()], 'weapon': [T.weapon_sword_rapier(), T.weapon_naginata(), T.weapon_crossbow()], 'armor': [T.helmet(), T.armor_mail(), T.clothes_belt()], 'potion': [T.potion_health(), T.potion_mana_empty(), T.potion_magic()], 'tool': [T.tool_tongs(), T.tool_pickaxe(), T.tool_broom()], 'magic': [T.magic_orb(), T.weapon_stave(), T.potion_stamina()] } M.scatter(2, 1, w - 2, 2, type_items[shop_type]) type_items = { 'food': [ T.furniture_box_filled(), T.furniture_box_filled(), T.bag(), T.food_milk() ], 'jewelry': [T.mineral_crystal(), T.bag(), T.necklace(), T.ring()], 'clothe': [ T.clothes_boots_right(), T.clothes_shirt(), T.clothes_shirt_inverted(), T.clothes_sweater() ], 'weapon': [ T.weapon_sword(), T.weapon_sword_saber(), T.weapon_spear(), T.weapon_dagger() ], 'armor': [ T.helmet(), T.armor_mail(), T.furniture_mannequin(), T.shield_buckler() ], 'potion': [ T.potion_magic_empty(), T.potion_stamina(), T.dining_bottle(), T.potion_health_empty() ], 'tool': [ T.tool_nails(), T.tool_scissors(), T.tool_fishingrod(), T.tool_pitchfork() ], 'magic': [ T.weapon_stave(), T.book_magic(), T.scroll_magic(), T.scroll_curled() ] } coord_exclude = [(x, y) for x in range(2, w - 2) for y in range(shop_counter_h + 2, shop_counter_h + 4)] coord_exclude.append((w // 2, h - 2)) M.scatter(2, shop_counter_h + 1, w - 1, h - 1, type_items[shop_type], exclude=coord_exclude) cat_place_x = random.randint(1, 2) cat_place_y = random.randint(shop_counter_h + 1, h - 3) M[cat_place_x, cat_place_y].put(A.animal_cat()) return M
def building_prison_linear(w=21, h=12, orientation='horizontal'): """ Construct a linear prison building interior. Parameters ---------- w : int Map width h : int Map height """ # Initial checks. Don't accept: # - Too small prisons # - Too wide prisons (for both horizontal and vertical orientations) if w < 11 or h < 11: raise ValueError('Building is too small: w or h < 11') if h > 16 and orientation == 'horizontal': raise ValueError( 'Building is too big: h > 16 and orientation == "horizontal"') if w > 16 and orientation == 'vertical': raise ValueError( 'Building is too big: w > 16 and orientation == "vertical"') if orientation == 'vertical': w, h = h, w M = Map(w, h, fill_cell=C.void) # Randomly choose where torture room and jailer room are. torture_left, jailer_right = None, None torture_left = random.choice([True, False]) if torture_left: jailer_right = True else: jailer_right = False # Create jailer room. We have two situations: jailer room left/right. jailer_y_start = h // 4 jailer_y_end = h // 3 * 2 if jailer_right: # Create walls, floor and door for y in range(jailer_y_start, jailer_y_end + 1): M[w - 1, y] = C.wall_stone() M[w - 5, y] = C.wall_stone() for x in range(w - 5, w): M[x, jailer_y_start] = C.wall_stone() M[x, jailer_y_end] = C.wall_stone() for y in range(jailer_y_start + 1, jailer_y_end): for x in range(w - 4, w - 1): M[x, y] = C.floor_flagged() M[w - 5, h // 2] = C.door_closed() # Place some furniture M[w - 4, jailer_y_start + 1].put(T.furniture_table()) M[w - 3, jailer_y_start + 1].put(T.furniture_table()) M[w - 2, jailer_y_start + 1].put(T.furniture_chair()) M[w - 4, jailer_y_end - 1].put(T.furniture_torch()) M[w - 3, jailer_y_end - 1].put(T.furniture_bed_single()) M[w - 2, jailer_y_end - 1].put(T.furniture_chest()) else: # Create walls, floor and door for y in range(jailer_y_start, jailer_y_end + 1): M[0, y] = C.wall_stone() M[4, y] = C.wall_stone() for x in range(0, 5): M[x, jailer_y_start] = C.wall_stone() M[x, jailer_y_end] = C.wall_stone() for y in range(jailer_y_start + 1, jailer_y_end): for x in range(1, 4): M[x, y] = C.floor_flagged() M[4, h // 2] = C.door_closed() # Place some furniture M[1, jailer_y_start + 1].put(T.furniture_table()) M[2, jailer_y_start + 1].put(T.furniture_table()) M[3, jailer_y_start + 1].put(T.furniture_chair()) M[1, jailer_y_end - 1].put(T.furniture_chest()) M[2, jailer_y_end - 1].put(T.furniture_bed_single()) M[3, jailer_y_end - 1].put(T.furniture_torch()) # Create torture room. We have two situations: torture room left/right. torture_start and torture_end - x-coord. # If torture_end = 0 or 1, there is no place for room (only one or two walls) # So we expand torture room for a one cell's width (+4) if jailer_right: torture_start = 0 torture_end = (w - 1) % 4 if torture_end == 0: torture_end = 4 if torture_end == 1: torture_end = 5 # Create walls, floor and door for x in range(torture_start, torture_end + 1): M[x, 0] = C.wall_stone() M[x, h - 1] = C.wall_stone() for y in range(0, h - 1): M[torture_start, y] = C.wall_stone() M[torture_end, y] = C.wall_stone() for x in range(torture_start + 1, torture_end): for y in range(1, h - 1): M[x, y] = C.floor_flagged() M[torture_end, h // 2] = C.door_closed() # Place some furniture. If torture_end == 2 (just a corridor), then we set only stairs. M[torture_end - 1, h - 2] = C.stairs_up() if torture_end != 2: M[(torture_end - torture_start) // 2, h // 2].put(T.furniture_torture()) all_coord = [(torture_end - 1, h - 2), ((torture_end - torture_start) // 2, h // 2)] for item_class in (T.bones, T.bones_skull, T.tool_tongs): while True: x = random.randint(1, torture_end - 1) y = random.randint(1, h - 2) if (x, y) not in all_coord: M[x, y].put(item_class()) all_coord.append((x, y)) break else: # If torture room is right, we are using the torture room width for calculations. # If torture_width = 7, then we reduce torture room for a one cell's width (-4). torture_width = w % 4 + 4 if torture_width == 7: torture_width = 3 torture_end = w - 1 # Create walls, floor and door for x in range(w - torture_width, torture_end): M[x, 0] = C.wall_stone() M[x, h - 1] = C.wall_stone() for y in range(0, h): M[w - torture_width, y] = C.wall_stone() M[torture_end, y] = C.wall_stone() for x in range(w - torture_width + 1, torture_end): for y in range(1, h - 1): M[x, y] = C.floor_flagged() M[w - torture_width, h // 2] = C.door_closed() # Place some furniture. If torture_width = 3 (just a corridor), then we set only stairs. M[w - 2, h - 2] = C.stairs_up() if torture_width != 3: M[w - 2, h // 2].put(T.furniture_torture()) all_coord = [(w - 1, h - 2), (w - 2, h // 2)] for item_class in (T.bones, T.bones_skull, T.tool_tongs): while True: x = random.randint(w - torture_width + 1, w - 2) y = random.randint(1, h - 2) if (x, y) not in all_coord: M[x, y].put(item_class()) all_coord.append((x, y)) break # Fill corridor with a floor if jailer_right: cor_start = torture_end + 1 cor_end = w - 6 else: cor_start = 5 cor_end = w - torture_width - 1 if h % 2 == 1: for x in range(cor_start, cor_end + 1): M[x, h // 2] = C.floor_flagged() else: for x in range(cor_start, cor_end + 1): M[x, h // 2 - 1] = C.floor_flagged() M[x, h // 2] = C.floor_flagged() # Place prison cells number_of_cells = (cor_end - cor_start + 2) // 4 for cell_index in range(number_of_cells): cell_x = (cor_start - 1) + (cell_index * 4) # Place upper cell M_cell = room_prison_cell(w=5, h=(h - 1) // 2) M.meld(M_cell, cell_x, 0) # Place lower cell M_cell = room_prison_cell(w=5, h=(h - 1) // 2, direction='up') M.meld(M_cell, cell_x, h // 2 + 1) if orientation == 'vertical': M.transpose() return M
def room_shop(w, h, shop_type, wall_material, floor_material): M = room_default(w, h, wall_type=wall_material, floor_type=floor_material) M[w // 2, h - 1] = C.door_closed() M[1, h - 2].put(T.light_lantern_oil()) shop_counter_h = h // 2 - 1 for x in range(w - 3): cell_x = 2 + x M[cell_x, shop_counter_h].put(T.furniture_longtable_showcase()) M[w - 2, shop_counter_h - 1].put(T.money_pile()) type_items = { 'food': [T.food_meat, T.food_carrot, T.food_apple], 'jewelry': [T.necklace, T.necklace_star, T.ring], 'clothe': [T.clothes_coat, T.clothes_hat, T.clothes_belt], 'weapon': [T.weapon_sword_rapier, T.weapon_naginata, T.weapon_crossbow], 'armor': [T.helmet, T.armor_mail, T.clothes_belt], 'potion': [T.potion_health, T.potion_mana_empty, T.potion_magic], 'tool': [T.tool_tongs, T.tool_pickaxe, T.tool_broom], 'magic': [T.magic_orb, T.weapon_stave, T.potion_stamina] } all_coord = [] for item_class in type_items[shop_type]: while True: x = random.randint(1, w // 2) y = 1 if (x, y) not in all_coord: M[x, y].put(item_class()) all_coord.append((x, y)) break type_items = { 'food': [T.furniture_box_filled, T.furniture_box_filled, T.bag, T.food_milk], 'jewelry': [T.mineral_crystal, T.bag, T.necklace, T.ring], 'clothe': [ T.clothes_boots_right, T.clothes_shirt, T.clothes_shirt_inverted, T.clothes_sweater ], 'weapon': [ T.weapon_sword, T.weapon_sword_saber, T.weapon_spear, T.weapon_dagger ], 'armor': [T.helmet, T.armor_mail, T.furniture_mannequin, T.shield_buckler], 'potion': [ T.potion_magic_empty, T.potion_stamina, T.dining_bottle, T.potion_health_empty ], 'tool': [T.tool_nails, T.tool_scissors, T.tool_fishingrod, T.tool_pitchfork], 'magic': [T.weapon_stave, T.book_magic, T.scroll_magic, T.scroll_curled] } all_coord = [] for item_class in type_items[shop_type]: while True: x = random.randint(w // 2 + 1, w - 2) y = random.randint(shop_counter_h + 1, h - 2) if (x, y) not in all_coord: M[x, y].put(item_class()) all_coord.append((x, y)) break cat_place_x = random.randint(1, 2) cat_place_y = random.randint(shop_counter_h + 1, h - 3) M[cat_place_x, cat_place_y].put(A.animal_cat()) return M
def building_hunter_robber_house(size=10, material=None, house_type=None): """ Construct the hunter or robber house. Parameters ---------- size : int Square map size. This attribute will be applied for both `w` and `h`. material : string Wall material. Can be "wooden", "stone" or None. If None, a random material will be chosen. house_type : string Type of the house. Can be "hunter" or "robber". If None, a random type will be chosen. """ # Initial check. Don't accept too small/big building if size < 8 or size > 17: raise ValueError( 'Building is too small or too big: size < 8 or size > 17') # Choose materials 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 floor_cell_type = C.floor_flagged if material == 'stone' else C.floor_plank # Choose between robber house and hunter house if not house_type: house_type = random.choice(['robber', 'hunter']) if house_type not in ('robber', 'hunter'): raise ValueError('Type should be "robber" or "hunter"') M = Map(size, size, fill_cell=floor_cell_type) # Create outward walls for x in range(size): M[x, 0] = wall_cell_type() M[x, size - 1] = wall_cell_type() for y in range(size): M[0, y] = wall_cell_type() M[size - 1, y] = wall_cell_type() # Create door door_random = random.choice([True, False]) door_param = size // 3 * 2 if door_random: M[door_param, size - 1] = C.door_closed() else: M[0, door_param] = C.door_closed() # Place bonfire or hearth in the middle of the room. Place chairs M[size // 2 - 1, size // 2].put(T.furniture_chair()) M[size // 2 + 1, size // 2].put(T.furniture_chair()) if house_type == 'hunter': M[size // 2, size // 2].put(T.furniture_hearth()) else: M[size // 2, size // 2].put(T.bonfire()) # Randomly choose where escape is. Place stairs and wardrobes. escape = random.choice([True, False]) if escape: M[size - 2, 1] = C.stairs_down() if house_type == 'robber': M[size - 3, 1].put(T.furniture_closet()) M[size - 3, 2].put(T.furniture_closet()) M[size - 2, 2].put(T.furniture_closet()) elif house_type == 'hunter': M[size - 2, size - 2].put(T.furniture_closet()) else: M[1, 1] = C.stairs_down() if house_type == 'robber': M[2, 1].put(T.furniture_closet()) M[2, 2].put(T.furniture_closet()) M[1, 2].put(T.furniture_closet()) elif house_type == 'hunter': M[size - 2, size - 2].put(T.furniture_closet()) # Place beds near walls beds_start = 1 if escape else size // 3 + 1 beds_end = size // 2 if escape else size - 1 if escape: for x in range(beds_start, beds_end + 1, 2): M[x, 1].put(T.furniture_bed_single()) else: for x in range(beds_start + 1, beds_end, 2): M[x, 1].put(T.furniture_bed_single()) # Place chests M[size - 2, size // 2 - 1].put(T.furniture_chest()) M[size - 2, size // 2].put(T.furniture_chest()) # Place table with chairs for x in range(size // 5, size // 2): M[x, size - 2].put(T.furniture_longtable()) for x in range(size // 5 + 1, size // 2, 2): M[x, size - 3].put(T.furniture_chair()) return M