def world_test(w, h): heightmap = [] for y in range(h): line = [] for x in range(w): distance_corners = min([ sqrt(x**2 + y**2), sqrt((w-x)**2 + y**2), sqrt(x**2 + (h-y)**2), sqrt((w-x)**2 + (h-y)**2) ]) distance_edges = min([x*0.7, y*0.7, (w-x)*0.7, (h-y)*0.7]) minus = (w + h) / 3 c = random.randint(-w*0.7, -w*0.6) + distance_corners + distance_edges #print('{:> .1f}'.format(c), '', end='') line.append(c) heightmap.append(line) heightmap = diamond_square_2x(heightmap) heightmap = diamond_square_2x(heightmap, smooth_iteration=2) heightmap = diamond_square_2x(heightmap, smooth_iteration=3) heightmap = diamond_square_2x(heightmap, smooth_iteration=4) M = Map(len(heightmap[0]), len(heightmap), fill_cell=C.overworld_ocean) for y, line in enumerate(M.cells): for x, cell in enumerate(line): M[x, y] = C.overworld_ocean() if heightmap[y][x] < 0 else C.overworld_forest() M = _smooth_map(M) M = _smooth_map(M) return M
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_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_living(w, h, wall_material, floor_material): M = room_default(w, h, wall_type=wall_material, floor_type=floor_material) if h < 17: num_rooms = (h - 3) // 3 for i in range(num_rooms): room_y = i * 3 poor_room = _room_poor(4, 4, wall_material, floor_material, direction='right') M.meld(poor_room, 0, room_y) poor_room = _room_poor(4, 4, wall_material, floor_material, direction='left') M.meld(poor_room, 5, room_y) M[w-1, h-2] = C.door_open_empty() M[1, h-2].put(A.animal_spider()) corridor_h = h - num_rooms * 3 - 1 if corridor_h > 2: M[1, h-corridor_h].put(T.washtub()) M[2, h-corridor_h].put(T.washtub()) M[w-2, h-corridor_h].put(T.furniture_stool()) M.scatter(1, h-corridor_h, w-2, h-1, [(A.animal_cat())]) elif h >= 17: rich_room_h = 5 + (h - 2) % 3 rich_1 = _room_rich(5, rich_room_h, wall_material, floor_material) M.meld(rich_1, 0, 0) rich_2 = _room_rich(5, rich_room_h, wall_material, floor_material) M.meld(rich_2, 4, 0) M[w-1, rich_room_h+1] = C.door_open_empty() M[1, rich_room_h+1].put(A.animal_spider()) M.scatter(1, rich_room_h, w-1, rich_room_h+2, [(A.animal_cat())]) num_rooms = (h - rich_room_h - 3) // 3 for i in range(num_rooms): room_y = i * 3 poor_room = _room_poor(4, 4, wall_material, floor_material, direction='right') M.meld(poor_room, 0, rich_room_h+2+room_y) poor_room = _room_poor(4, 4, wall_material, floor_material, direction='left') M.meld(poor_room, 5, rich_room_h+2+room_y) return M
def _smooth_map(M): """ Smooth a map using cellular automata. If number of walls around the cell (including it) is more than number of floors, replace the cell with a wall. In other case replace the cell with a floor. """ # Already replaced cells must not affect current so we need a copy of the original map M2 = deepcopy(M) for y, line in enumerate(M2.cells[1:-1]): for x, _ in enumerate(line[1:-1]): true_x = x + 1 true_y = y + 1 # Check the number of walls in ORIGINAL map number_of_walls = sum(cell.__class__.__name__ == 'wall_cave' for cell in [ M.cells[true_y][true_x], M.cells[true_y + 1][true_x], M.cells[true_y - 1][true_x], M.cells[true_y][true_x + 1], M.cells[true_y + 1][true_x + 1], M.cells[true_y - 1][true_x + 1], M.cells[true_y][true_x - 1], M.cells[true_y + 1][true_x - 1], M.cells[true_y - 1][true_x - 1], ]) # And set them in smoothed map M2.cells[true_y][true_x] = (C.wall_cave() if number_of_walls >= 5 else C.floor_dirt()) return M2
def room_horse_stables(w, h, horse_box_size_w, horse_box_size_h): """ Construct big stable with horse boxes. The stable consits of some small horse boxes with animal or without. """ M = room_default(w, h, wall_type=C.wall_plank, floor_type=C.floor_rocks) number_of_horse_box = (h - 1) // 3 # Place left and right rows of horse boxes. for y in range(number_of_horse_box): cell_y = 1 + (y * 3) left_stable = room_horse_box(horse_box_size_w, horse_box_size_h) M.meld(left_stable, 1, cell_y) right_stable = room_horse_box(horse_box_size_w, horse_box_size_h, orientation='right') M.meld(right_stable, horse_box_size_w + 2, cell_y) # Place fence after every horse box, except the last. if y == 0: continue for x in range(1, horse_box_size_w + 1): M[x, cell_y - 1] = C.wall_fence() for x in range(horse_box_size_w + 2, w - 1): M[x, cell_y - 1] = C.wall_fence() M[w // 2, h - 1] = C.door_open_empty() return M
def _room_small_office(w, h): """ Construct small office for employees in poor part. """ M = room_default(w, h, wall_type=C.wall_dungeon_smooth, floor_type=C.floor_plank) # Place things and actor - employee. work_chance = random.choice([True, False]) M[w // 2, 0] = C.door_open_empty() M[1, h - 1] = C.wall_bars() M[w - 2, h - 1] = C.wall_bars() M[2, h - 1].put(T.furniture_longtable()) if w > 5: for x in range(2, w - 2): M[x, h - 1].put(T.furniture_longtable()) M[w // 2, h - 2].put(T.furniture_chair()) M[w - 2, 1].put(T.furniture_bookcase()) M[1, 1].put(T.money_pile()) if work_chance: M[1, h - 2].put(A.player_female()) M[w - 2, h - 2].put(T.book()) else: M[w - 2, h - 2].put(T.book_clear()) return M
def _room_cattle_pens(w, h, wall_material, floor_material): M = room_default(w, h, wall_type=C.wall_fence, floor_type=floor_material) M[w - 7, 0] = C.door_close_fence() for i in range(w * h // 3): grass_x = random.randint(1, w - 2) grass_y = random.randint(1, h - 2) M[grass_x, grass_y] = random.choice( [C.flora_grass, C.flora_cane, C.floor_grass])() num_cattles = h // 4 + 1 cowshed = Map(4, 3, fill_cell=floor_material) for y in (1, 2): cowshed[0, y] = C.wall_fence() for y in range(0, 3): cowshed[3, y].put(T.water_trough()) for x in (1, 2): cowshed[x, 2] = wall_material() cowshed[1, 1].put(T.bucket()) cowshed_y = 1 for x in range(num_cattles): copied_cowshed = deepcopy(cowshed) M.meld(copied_cowshed, w - 5, cowshed_y) cowshed_y += 3 cows = [A.animal_cow() for _ in range(num_cattles)] M.scatter(1, 1, w - 5, h - 1, cows) return M
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 select_tile_linear(M, xpos, ypos, metatile, metatile_type): name = metatile.name if metatile_type == 'cell': up = int(M.up_to(xpos, ypos).cname == name) down = int(M.down_to(xpos, ypos).cname == name) left = int(M.left_to(xpos, ypos).cname == name) right = int(M.right_to(xpos, ypos).cname == name) position = LINEAR_ORIENTATION_TABLE[(up, down, left, right)] try: tile = random.choice(metatile.get_tiles(orientation=position)) except ValueError: tile = C.unknown().metatile.get_tiles()[0] elif metatile_type == 'thing': up = int( M.up_to(xpos, ypos) != None and len(M.up_to(xpos, ypos).things) and M.up_to(xpos, ypos).things[0].cname == name) down = int( M.down_to(xpos, ypos) != None and len(M.down_to(xpos, ypos).things) and M.down_to(xpos, ypos).things[0].cname == name) left = int( M.left_to(xpos, ypos) != None and len(M.left_to(xpos, ypos).things) and M.left_to(xpos, ypos).things[0].cname == name) right = int( M.right_to(xpos, ypos) != None and len(M.right_to(xpos, ypos).things) and M.right_to(xpos, ypos).things[0].cname == name) position = LINEAR_ORIENTATION_TABLE[(up, down, left, right)] try: tile = random.choice(metatile.get_tiles(orientation=position)) except ValueError: tile = C.unknown().metatile.get_tiles()[0] elif metatile_type == 'actor': up = int( M.up_to(xpos, ypos) != None and len(M.up_to(xpos, ypos).actors) and M.up_to(xpos, ypos).actors[0].cname == name) down = int( M.down_to(xpos, ypos) != None and len(M.down_to(xpos, ypos).actors) and M.down_to(xpos, ypos).actors[0].cname == name) left = int( M.left_to(xpos, ypos) != None and len(M.left_to(xpos, ypos).actors) and M.left_to(xpos, ypos).actors[0].cname == name) right = int( M.right_to(xpos, ypos) != None and len(M.right_to(xpos, ypos).actors) and M.right_to(xpos, ypos).actors[0].cname == name) position = LINEAR_ORIENTATION_TABLE[(up, down, left, right)] try: tile = random.choice(metatile.get_tiles(orientation=position)) except ValueError: tile = C.unknown().metatile.get_tiles()[0] return tile
def _room_kitchen(w, h, wall_material, floor_material): M = room_default(w, h, wall_type=wall_material, floor_type=floor_material) storage = room_default(6, 6, wall_type=wall_material, floor_type=floor_material) M.meld(storage, 0, 0) M[5, h-3] = C.door_open_empty() M[10, h-1] = C.door_open_empty() M[7, 0] = C.door_closed_window() for x in range(1, 3): for y in range(1, 3): M[x, y] = C.flora_mushroom_button() storage_items = [ T.furniture_barrel(), T.furniture_barrel(), T.furniture_barrel(), T.furniture_barrel(), T.furniture_box_filled(), T.furniture_box_filled(), T.bag(), T.food_leaf() ] storage_w = 6 M.scatter(1, 1, 5, h-1, storage_items, exclude=[ (storage_w-2, h-3), (storage_w-3, h-3), (storage_w-4, h-3), (storage_w-3, h-4), (1, 1), (1, 2), (2, 1), (2, 2) ]) for x in range(8, 11): M[x, 1].put(T.furniture_hearth()) for x in range(8, 11): M[x, 3].put(T.furniture_table()) M[13, 1] = C.stairs_down() M[11, 1].put(T.bucket()) for y in range(1, 3): M[6, y].put(T.food_meat()) M[6, 4].put(T.food_egg()) M[11, 3].put(T.furniture_box_filled()) M.scatter(6, 1, 14, 5, [A.animal_cat()]) if w > 15: num_of_items = (w - 15) * 2 food_items = [ T.furniture_barrel(), T.furniture_barrel(), T.furniture_barrel(), T.furniture_box_filled(), T.furniture_box_filled(), T.bag() ] M.scatter(15, 1, w-1, h-1, random.sample(food_items, min(len(food_items), num_of_items))) return M
def _create_room_grid(M, room_size): """Create room grid and clear all cells that are out of the grid.""" w, h = M.get_size() x_border_index = ((w - 1) // (room_size + 1)) * (room_size + 1) y_border_index = ((h - 1) // (room_size + 1)) * (room_size + 1) for y, line in enumerate(M.cells): for x, cell in enumerate(line): if x > x_border_index or y > y_border_index: M[x, y] = C.void() elif x % (room_size + 1) == 0 or y % (room_size + 1) == 0: M[x, y] = C.wall_dungeon_smooth()
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_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_bedroom(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): M[x, 1].put(T.furniture_longtable()) M[2, 2].put(T.furniture_chair()) M[w - 2, 1].put(T.furniture_bookcase()) M[w - 2, h - 5].put(T.furniture_closet()) M[1, h - 5].put(T.furniture_chandelier()) M[2, h - 5].put(T.furniture_bed_double()) M[w - 2, h // 3].put(T.urn()) for x in range(1, w - 2): M[x, h - 4] = wall_material() M[w - 2, h - 4] = C.door_open_stairs() items = [ T.light_lantern_oil(), T.magic_alchemisttable(), T.book_magic(), T.furniture_chair() ] M.scatter(1, h - 3, w - 1, h - 1, items, exclude=[(2, h - 3), (3, h - 3), (4, h - 3)]) 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_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_outdoor(w, h): M = Map(w, h, fill_cell=C.floor_rocks) for i in range(w * h // 3): grass_x = random.randint(1, w - 1) grass_y = random.randint(0, h - 2) M[grass_x, grass_y] = random.choice( [C.flora_grass, C.flora_tree, C.floor_grass])() M[w - 1, 0].put(T.washtub()) for x in range(w): M[x, h - 1] = C.wall_fence_thin() for y in range(h - 1): M[0, y] = C.wall_fence_thin() for y in range(h - 1): M[3, y] = C.floor_rocks() M[3, h - 1] = C.door_close_fence() return M
def world_test2(w=400, h=200): M = Map(w, h, fill_cell=C.overworld_ocean) ''' plates = {i: (random.randint(0, w-1), random.randint(0, h-1)) for i in range(30)} for y, line in enumerate(M.cells): for x, cell in enumerate(line): intervals = {i: (plates[i][0] - x) ** 2 + (plates[i][1] - y) ** 2 for i in plates} #print(intervals) M[x, y].plate = min(intervals.items(), key=lambda item: item[1])[0] for y, line in enumerate(M.cells): for x, cell in enumerate(line): M[x, y] = P[M[x, y].plate]() for i in plates: M[plates[i]] = C.void() ''' for y, line in enumerate(M.cells): for x, cell in enumerate(line): distance_corners = min([ sqrt(x**2 + y**2), sqrt((w-x)**2 + y**2), sqrt(x**2 + (h-y)**2), sqrt((w-x)**2 + (h-y)**2) ]) distance_edges = min([x, y, (w-x), (h-y)]) minus = (w + h) / 3 c = random.randint(-w*0.8, -w*0.6) + distance_corners + distance_edges #print('{:> .1f}'.format(c), '', end='') M[x, y] = C.overworld_ocean() if c < 0 else C.overworld_forest() #print() #for y in [0, h-1]: # for x in range(M.w): # M[x, y] = C.overworld_ocean() #for x in [0, w-1]: # for y in range(M.h): # M[x, y] = C.overworld_ocean() #for x in range(w//2-2, w//2+3): # for y in range(h//2-2, h//2+3): # M[x, y] = C.overworld_forest() #for y, line in enumerate(M.cells): # for x, cell in enumerate(line): # if sum(c.cname == 'overworld_forest' for c in M.surrounding(x, y)) >= 7: # M[x, y] = C.overworld_forest() #M = _smooth_map(M) return M
def _room_storage(w, h, wall_material, floor_material, garden_beds_w): M = room_default(w, h, wall_type=wall_material, floor_type=floor_material) M[w - 1, h // 2] = C.door_closed_window() M[w - 2, h - 1] = C.door_closed_window() M[garden_beds_w - 3, h - 1] = C.door_open() M[w - 2, 1].put(T.light_torch()) M[w - 4, 1].put(T.dining_bottle()) M[w - 3, h - 2].put(T.furniture_napsack()) for x in range(1, w // 2): for y in range(1, h - 1): items = random.choice([ T.farm_mangler, T.furniture_box_filled, T.furniture_barrel, T.food_milk ])() M[x, y].put(items) 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 _fill_rooms(M, nodes): """ Fill map with rooms given from leaf nodes of BSP-tree. """ for node in nodes: for y in range(node.room_y1, node.room_y2): for x in range(node.room_x1, node.room_x2): M[x, y] = C.floor()
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 building_roadhouse(w=15, h=15, wall_material=None, floor_material=None): """ Construct roadhouse with living room for poor, kitchen/storage and saloon. Constraints: - Map width and map height must be >= 15. - Map width and map height must be <= 21. Parameters ---------- w : int Map width h : int Map height """ # Initial checks. Don't accept too small/big inn if w < 15 or h < 15: raise ValueError('Building is too small: w or h < 15') elif w > 21 or h > 21: raise ValueError('Building is too big: w or h > 21') # 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=floor_material) M[13, h-1] = C.door_closed_window() kitchen = _room_kitchen(w, 6, wall_material, floor_material) M.meld(kitchen, 0, 0) living_room = _room_living(9, h-5, wall_material, floor_material) M.meld(living_room, 0, 5) vending = _interior_vending(w-10, h-7, wall_material, floor_material) M.meld(vending, 9, 6) return M
def _create_corridors(M, nodes, edges): """ Create corridors between rooms that should be connected. """ for edge in edges: n1 = nodes[edge[0]] n2 = nodes[edge[1]] if max(n1.room_x1, n2.room_x1) < min(n1.room_x2, n2.room_x2): x = random.randint(max(n1.room_x1, n2.room_x1), min(n1.room_x2, n2.room_x2)) for y in range(min(n2.room_y2, n1.room_y1), max(n2.room_y2, n1.room_y1)): M[x, y] = C.floor() elif max(n1.room_y1, n2.room_y1) < min(n1.room_y2, n2.room_y2): y = random.randint(max(n1.room_y1, n2.room_y1), min(n1.room_y2, n2.room_y2)) for x in range(min(n2.room_x2, n1.room_x1), max(n2.room_x2, n1.room_x1)): M[x, y] = C.floor()
def _interior_pantry(w, h, wall_material, floor_material): M = Map(w, h, fill_cell=floor_material) if random.random() < 0.5: for y in range(h): M[2, y] = wall_material() items = [T.tool_wateringcan(), T.tool_pitchfork(), T.tool_fishingrod()] M.scatter(0, 0, w - 1, h, items) else: M[0, 0] = C.stairs_down() M[0, 1].put(T.furniture_box_filled()) return M
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 dungeon_drunkard(w, h, length=None, turn_chance=0.4): M = Map(w, h, fill_cell=C.wall_dungeon_smooth) if not length: length = int(w * h / 2) worm_x = random.randint(int(w * 0.3), int(w * 0.6)) worm_y = random.randint(int(h * 0.3), int(h * 0.6)) move = random.choice([NORTH, SOUTH, EAST, WEST]) for _ in range(length): M[worm_x, worm_y] = C.floor_flagged() worm_x, worm_y, move = _move_worm(M, worm_x, worm_y, move, turn_chance) 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 _interior_garden(w, h, wall_material, floor_material): M = Map(w, h, fill_cell=C.floor_flagged) garden_part = Map(w // 2, h, fill_cell=C.flora_grass) for y in range(0, h): garden_part[w // 2 - 1, y] = C.floor_flagged() for x in range(1, w // 2 - 1): for y in range(1, 4): garden_part[x, y] = C.floor_flagged() for x in range(2, w // 2): garden_part[x, 2].put(T.water_trough()) for y in range(h - 3, h): garden_part[0, y] = C.flora_tree() garden_part[1, y].put(T.water_trough()) garden_part[2, y] = C.flora_flower() garden_part[w // 2 - 2, 0] = C.flora_flower() garden_part[0, h - 5].put(T.furniture_sofa()) garden_part[1, h - 5].put(T.furniture_table_round()) garden_part[2, h - 6].put(T.urn()) M.meld(garden_part, 0, 0) garden_part2 = deepcopy(garden_part) garden_part2.hmirror() M.meld(garden_part2, w // 2 + w % 2, 0) for x in range(0, w // 2 - 1): M[x, h - 4] = C.floor_flagged() M.scatter(0, 0, w - 1, h - 1, [A.animal_cat()]) return M