def building_stables(w=16, h=16): """ Construct stables with storage and two rows of horse boxes. Constraints: - Map width and map height must be >= 16 and <=23. Parameters ---------- w : int Map width h : int Map height """ # Initial checks. Don't accept too small/big stables if w < 16 or h < 16: raise ValueError('Building is too small: w or h < 16') elif w > 23 or h > 23: raise ValueError('Building is too big: w or h > 25') M = Map(w, h, fill_cell=C.floor_rocks) for x in range(w): for y in range(h): if random.random() > 0.75: M[x, y] = C.flora_grass() # Calculate w and h for storage, horse boxes and stables. horse_box_size_w = w // 2 - 4 horse_box_size_h = 2 stables_size_w = horse_box_size_w * 2 + 3 stables_shift_h = (h - 1) % 3 stables_size_h = h - stables_shift_h storage_size_w = w - stables_size_w + 1 storage_size_h = h * 2 // 3 storage_start_w = w - storage_size_w # Meld stables, storage, add dog. main_stables = room_horse_stables(stables_size_w, stables_size_h, horse_box_size_w, horse_box_size_h) M.meld(main_stables, 0, 0) main_storage = room_storage(storage_size_w, storage_size_h) M.meld(main_storage, storage_start_w, 0) M[w - (w - stables_size_w) // 2, storage_size_h].put(T.well()) dog_place_x = random.randint(stables_size_w, w - 1) dog_place_y = random.randint(storage_size_h + 1, h - 1) M[dog_place_x, dog_place_y].put(A.animal_dog()) if random.choice([True, False]): M.hmirror() 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 building_ruined_house(w=6, h=6, material=None): """ Construct ruined house. It contain chimney, barrel and some animal. Constraints: - Map width and map height must be >= 6 and <= 10. Parameters ---------- w : int Map width h : int Map height """ # Initial checks. Don't accept too small/big house. if w < 6 or h < 6: raise ValueError('Building is too small: w or h < 6') elif w > 10 or h > 10: raise ValueError('Building is too big: w or h > 10') # Choose materials wall_material = None if not material: wall_material = random.choice( [C.wall_block, C.wall_plank, C.wall_stone, C.wall_brick]) elif material not in (['block', 'plank', 'stone', 'brick']): raise ValueError( 'Material should be "block", "plank", "stone" or "brick"') if material == 'stone': wall_material = C.wall_stone elif material == 'block': wall_material = C.wall_block elif material == 'plank': wall_material = C.wall_plank elif material == 'brick': wall_material = C.wall_brick M = room_default(w, h, wall_type=wall_material, floor_type=C.floor_rocks) # Calculate % of replaced walls and added grass. 10% for walls and 20% for grass. grass_count = int((w - 2) * (h - 2) * 0.2) wall_ruined = int(w * h * 0.1) M[w // 2, h - 1] = C.door_open_dark() # Place some furniture and animals. all_coord = [(w // 2, h - 1), (w // 2, h - 2)] for item_class in (T.furniture_chimney, A.animal_bat, A.animal_spider, T.web, T.furniture_barrel): 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 # Place some grass. for _ in range(grass_count): while True: x = random.randint(0, w - 1) 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 # Replace some walls with rocks. for _ in range(wall_ruined): while True: x = random.randint(0, w - 1) y = random.choice([0, h - 1]) if (x, y) not in all_coord: M[x, y] = C.floor_rocks() all_coord.append((x, y)) break return M