def cave_generator(map_draft, player_hd, generator_type, requests, theme, params): __gen_wall_square(map_draft, 0, 0, map_draft.width, map_draft.height) maputils.generate_border(map_draft, ft.fixed_wall) open_area_factor = float(randint(4, 6)) / 10 walls_left = int(map_draft.width * map_draft.height * open_area_factor) #we don't want this process to hang ticks = map_draft.width * map_draft.height x2, y2 = map_draft.width - 1, map_draft.height - 1 while walls_left > 0: if not ticks: print("Map generation takes too long - returning as is") break rand_x = randrange(1, x2) rand_y = randrange(1, y2) if map_draft.tile_at(rand_x, rand_y).type == ftype.wall: map_draft.replace_feature_atxy(rand_x, rand_y, ft.floor()) walls_left -= 1 ticks -= 1 count_walls = __count_neigh_walls for x in xrange(1, x2): for y in xrange(1, y2): wall_count = count_walls(map_draft, x, y) if tile_passable(map_draft.tile_at(x, y)): if wall_count > 5: map_draft.replace_feature_atxy(x, y, ft.rock_wall()) elif wall_count < 4: map_draft.replace_feature_atxy(x, y, ft.floor()) return map_draft
def __count_neigh_walls(MapDef, x, y): count = 0 for row in (-1, 0, 1): for col in (-1, 0, 1): if not tile_passable(MapDef.tile_at(x + row, y + col)) and not(row == 0 and col == 0): count += 1 return count
def __count_neigh_walls(MapDef, x, y): count = 0 for row in (-1, 0, 1): for col in (-1, 0, 1): if not tile_passable(MapDef.tile_at( x + row, y + col)) and not (row == 0 and col == 0): count += 1 return count