pub fn make_lakes (width : usize, height : usize, liquid_type: TileType, floor : TileType, tiles: &mut Vec<TileType>, marked_regions : &Vec<Region>, min_size : usize, max_size : usize, number_generator: &mut StdRng) {
	use super::map::tile::{shallow_liquid_variant};
	info!("Forming Lakes...");

	let shallow_variant = shallow_liquid_variant(liquid_type);

	let mut lake_map : Vec<TileType> = tiles.clone();

	//fill place initial liquid tiles
	for x in 1..width-1 {
		for y in 1..height-1 {
			if lake_map[x+y*width] == floor {
				if number_generator.gen_range (0, 100) < 50 {
					lake_map[x+y*width] = shallow_variant;
				} 
			}
		}
	}

	// cellular automata
	for _i in 0..5 {
		for x in 1..width {
			for y in 1..height {
				let idx = x+y*width;
				let amount_of_liquid = get_surrounding_neighbor_count(width, height, &mut lake_map, shallow_variant, x as i32, y as i32);
				if lake_map[idx] == shallow_variant {
					if amount_of_liquid >= 4 {
						lake_map[idx] = shallow_variant;
					}
					if amount_of_liquid < 2 {
						lake_map[idx] = floor;
					}
				} else {
					if lake_map[idx] == floor && amount_of_liquid >= 5 {
						lake_map[idx] = shallow_variant;
					}
				}
			}
		}
	}

	//reject lakes if they dont make requirements
	let mut lakes = get_all_regions(width, height, liquid_type, &mut lake_map);

	debug!("{} lakes generated...", lakes.len());
	let mut bad_lake_counter = 0;
	lakes.retain(|a|
		if (a.size < min_size) || (a.size > max_size) {
			bad_lake_counter += 1;
			false
		} else {
			true
		}
	);

	let mut foo = 0;
	// reject lakes if they would intrude on feature regions
	lakes.retain(|a|
		{
			let mut retain = true;
			for edge_tile in &a.edge_tiles {
				for region in marked_regions {
					if region.is_tile_in_region(&edge_tile) {
						retain = false;
						bad_lake_counter += 1;
						foo += 1;
						break;
					} else {
						continue;
					}
				}
				if !retain {
					break;
				}
			}
			retain
		});

	debug!("{} lakes rejected...", bad_lake_counter);	

	//put lakes on actual map
	for lake in lakes {
		for tile in lake.tiles {
			let idx = (tile.0+tile.1*width as i32) as usize;
			tiles[idx] = lake_map[idx];
		}
	}
}
/// Forms lakes using cellular automata. Panics if the given type is not a liguid.
Forms lakes using cellular automata. Panics if the given type is not a liguid.
Forms lakes using cellular automata . Panics if the given type is not a liguid .
pub fn make_lakes (width : usize, height : usize, liquid_type: TileType, floor : TileType, tiles: &mut Vec<TileType>, marked_regions : &Vec<Region>, min_size : usize, max_size : usize, number_generator: &mut StdRng) {
	use super::map::tile::{shallow_liquid_variant};
	info!("Forming Lakes...");
	let shallow_variant = shallow_liquid_variant(liquid_type);
	let mut lake_map : Vec<TileType> = tiles.clone();
	//fill place initial liquid tiles
	for x in 1..width-1 {
		for y in 1..height-1 {
			if lake_map[x+y*width] == floor {
				if number_generator.gen_range (0, 100) < 50 {
					lake_map[x+y*width] = shallow_variant;
				} 
			}
		}
	}
	// cellular automata
	for _i in 0..5 {
		for x in 1..width {
			for y in 1..height {
				let idx = x+y*width;
				let amount_of_liquid = get_surrounding_neighbor_count(width, height, &mut lake_map, shallow_variant, x as i32, y as i32);
				if lake_map[idx] == shallow_variant {
					if amount_of_liquid >= 4 {
						lake_map[idx] = shallow_variant;
					}
					if amount_of_liquid < 2 {
						lake_map[idx] = floor;
					}
				} else {
					if lake_map[idx] == floor && amount_of_liquid >= 5 {
						lake_map[idx] = shallow_variant;
					}
				}
			}
		}
	}
	//reject lakes if they dont make requirements
	let mut lakes = get_all_regions(width, height, liquid_type, &mut lake_map);
	debug!("{} lakes generated...", lakes.len());
	let mut bad_lake_counter = 0;
	lakes.retain(|a|
		if (a.size < min_size) || (a.size > max_size) {
			bad_lake_counter += 1;
			false
		} else {
			true
		}
	);
	let mut foo = 0;
	// reject lakes if they would intrude on feature regions
	lakes.retain(|a|
		{
			let mut retain = true;
			for edge_tile in &a.edge_tiles {
				for region in marked_regions {
					if region.is_tile_in_region(&edge_tile) {
						retain = false;
						bad_lake_counter += 1;
						foo += 1;
						break;
					} else {
						continue;
					}
				}
				if !retain {
					break;
				}
			}
			retain
		});
	debug!("{} lakes rejected...", bad_lake_counter);	
	//put lakes on actual map
	for lake in lakes {
		for tile in lake.tiles {
			let idx = (tile.0+tile.1*width as i32) as usize;
			tiles[idx] = lake_map[idx];
		}
	}
}
pub fn make_lakes ( width : usize , height : usize , liquid_type : TileType , floor : TileType , tiles : & mut Vec < TileType > , marked_regions : & Vec < Region > , min_size : usize , max_size : usize , number_generator : & mut StdRng ) { use super :: map :: tile :: { shallow_liquid_variant } ; info ! ( " " ) ; let shallow_variant = shallow_liquid_variant ( liquid_type ) ; let mut lake_map : Vec < TileType > = tiles . clone ( ) ; //fill place initial liquid tiles for x in 1 .. width - 1 { for y in 1 .. height - 1 { if lake_map [ x + y * width ] == floor { if number_generator . gen_range ( 0 , 100 ) < 50 { lake_map [ x + y * width ] = shallow_variant ; } } } } // cellular automata for _i in 0 .. 5 { for x in 1 .. width { for y in 1 .. height { let idx = x + y * width ; let amount_of_liquid = get_surrounding_neighbor_count ( width , height , & mut lake_map , shallow_variant , x as i32 , y as i32 ) ; if lake_map [ idx ] == shallow_variant { if amount_of_liquid >= 4 { lake_map [ idx ] = shallow_variant ; } if amount_of_liquid < 2 { lake_map [ idx ] = floor ; } } else { if lake_map [ idx ] == floor && amount_of_liquid >= 5 { lake_map [ idx ] = shallow_variant ; } } } } } //reject lakes if they dont make requirements let mut lakes = get_all_regions ( width , height , liquid_type , & mut lake_map ) ; debug ! ( " " lakes len ( ) ) ; let mut bad_lake_counter = 0 ; lakes . retain ( | a | if ( a . size < min_size ) || ( a . size > max_size ) { bad_lake_counter += 1 ; false } else { true } ) ; let mut foo = 0 ; // reject lakes if they would intrude on feature regions lakes . retain ( | a | { let mut retain = true ; for edge_tile in & a . edge_tiles { for region in marked_regions { if region . is_tile_in_region ( & edge_tile ) { retain = false ; bad_lake_counter += 1 ; foo += 1 ; break ; } else { continue ; } } if ! retain { break ; } } retain } ) ; debug ! ( " " bad_lake_counter ) ; //put lakes on actual map for lake in lakes { for tile in lake . tiles { let idx = ( tile . 0 + tile . 1 * width as i32 ) as usize ; tiles [ idx ] = lake_map [ idx ] ; } } }
Forms lakes using cellular automata.
Forms lakes using cellular automata .
width
usize
height
usize
liquid_type
TileType
floor
TileType
tiles
&mut Vec<TileType>
marked_regions
&Vec<Region>
min_size
usize
max_size
usize
number_generator
&mut StdRng
width
usize
height
usize
liquid_type
TileType
floor
TileType
tiles
&mut Vec<TileType>
marked_regions
&Vec<Region>
min_size
usize
max_size
usize
number_generator
&mut StdRng