pub fn connect_floor_regions (width : usize, height : usize, tiles: &mut Vec<TileType>, floor : TileType) -> bool {
	use bracket_lib::prelude::{Bresenham, Point};

	let mut reject_level = false;

	let mut regions = get_all_regions(width, height, floor, tiles);
	regions.sort_by(|a,b| b.size.cmp(&a.size));

	if regions.len() > 1 {
		let current_largest = regions.remove(0);
		let mut closest_distance = 0;
		let mut point_a : (i32, i32) = (0,0);
		let mut point_b : (i32, i32) = (0,0);
		let mut looking_for_closest = false;

		//find the closest point in another region other than itself
		for region in regions {
			for edge_tile_b in region.edge_tiles {
				for edge_tile_a in &current_largest.edge_tiles {
					let distance = (edge_tile_a.0 - edge_tile_b.0).pow(2) + (edge_tile_a.1 - edge_tile_b.1).pow(2);

					if distance < closest_distance || !looking_for_closest {
						looking_for_closest = true;
						closest_distance = distance;
						point_a = *edge_tile_a;
						point_b = edge_tile_b;
					}
				}
			}
		}

		// the path is too far; just regen the level
		if closest_distance > 10000 {
			return true;
		}

		let path = Bresenham::new(Point::from_tuple(point_a), Point::from_tuple(point_b));
		
		// connect the two regions
		path.for_each(|x| dig_circle(width, height, x.to_tuple(), 2, tiles, floor));
		
		//recurse
		reject_level = connect_floor_regions(width, height, tiles, floor);
	}
	return reject_level;
}
/// Attempts to connect separated floor regions. Returns true if successful, returns false
/// if the paths calculated are too long.
Attempts to connect separated floor regions. Returns true if successful, returns false
if the paths calculated are too long.
Attempts to connect separated floor regions . Returns true if successful returns false if the paths calculated are too long .
pub fn connect_floor_regions (width : usize, height : usize, tiles: &mut Vec<TileType>, floor : TileType) -> bool {
	use bracket_lib::prelude::{Bresenham, Point};
	let mut reject_level = false;
	let mut regions = get_all_regions(width, height, floor, tiles);
	regions.sort_by(|a,b| b.size.cmp(&a.size));
	if regions.len() > 1 {
		let current_largest = regions.remove(0);
		let mut closest_distance = 0;
		let mut point_a : (i32, i32) = (0,0);
		let mut point_b : (i32, i32) = (0,0);
		let mut looking_for_closest = false;
		//find the closest point in another region other than itself
		for region in regions {
			for edge_tile_b in region.edge_tiles {
				for edge_tile_a in &current_largest.edge_tiles {
					let distance = (edge_tile_a.0 - edge_tile_b.0).pow(2) + (edge_tile_a.1 - edge_tile_b.1).pow(2);
					if distance < closest_distance || !looking_for_closest {
						looking_for_closest = true;
						closest_distance = distance;
						point_a = *edge_tile_a;
						point_b = edge_tile_b;
					}
				}
			}
		}
		// the path is too far; just regen the level
		if closest_distance > 10000 {
			return true;
		}
		let path = Bresenham::new(Point::from_tuple(point_a), Point::from_tuple(point_b));
		// connect the two regions
		path.for_each(|x| dig_circle(width, height, x.to_tuple(), 2, tiles, floor));
		//recurse
		reject_level = connect_floor_regions(width, height, tiles, floor);
	}
	return reject_level;
}
pub fn connect_floor_regions ( width : usize , height : usize , tiles : & mut Vec < TileType > , floor : TileType ) -> bool { use bracket_lib :: prelude :: { Bresenham , Point } ; let mut reject_level = false ; let mut regions = get_all_regions ( width , height , floor , tiles ) ; regions . sort_by ( | a , b | b . size . cmp ( & a . size ) ) ; if regions . len ( ) > 1 { let current_largest = regions . remove ( 0 ) ; let mut closest_distance = 0 ; let mut point_a : ( i32 , i32 ) = ( 0 , 0 ) ; let mut point_b : ( i32 , i32 ) = ( 0 , 0 ) ; let mut looking_for_closest = false ; //find the closest point in another region other than itself for region in regions { for edge_tile_b in region . edge_tiles { for edge_tile_a in & current_largest . edge_tiles { let distance = ( edge_tile_a . 0 - edge_tile_b . 0 ) . pow ( 2 ) + ( edge_tile_a . 1 - edge_tile_b . 1 ) . pow ( 2 ) ; if distance < closest_distance || ! looking_for_closest { looking_for_closest = true ; closest_distance = distance ; point_a = * edge_tile_a ; point_b = edge_tile_b ; } } } } // the path is too far; just regen the level if closest_distance > 10000 { return true ; } let path = Bresenham :: new ( Point :: from_tuple ( point_a ) , Point :: from_tuple ( point_b ) ) ; // connect the two regions path . for_each ( | x | dig_circle ( width , height , x . to_tuple ( ) , 2 , tiles , floor ) ) ; //recurse reject_level = connect_floor_regions ( width , height , tiles , floor ) ; } return reject_level ; }
Attempts to connect separated floor regions.
Attempts to connect separated floor regions .
width
usize
height
usize
tiles
&mut Vec<TileType>
floor
TileType
width
usize
height
usize
tiles
&mut Vec<TileType>
floor
TileType