pub fn grow (width : usize, height : usize, tiles: &mut Vec<TileType>, flora_type: TileType, floor : TileType) {
	use super::map::tile::{small_foliage_variant, large_foliage_variant};
	info!("Growing...");

	let large_variant = large_foliage_variant(flora_type);
	let small_variant = small_foliage_variant(flora_type);

	for x in 1..width-1 {
		for y in 1..height-1 {
			let amt_small_flora = get_surrounding_neighbor_count(width, height, tiles, small_variant, x as i32, y as i32);
			let amt_large_flora = get_surrounding_neighbor_count(width, height, tiles, large_variant, x as i32, y as i32);
			let idx = x+y*width;
			//Grass
			if small_variant == TileType::ShortGrass(0) {
				let amt_of_water = get_surrounding_neighbor_count(width, height, tiles, TileType::ShallowWater, x as i32, y as i32);
				if tiles[idx] == TileType::ShortGrass(0) {	
					if amt_small_flora + amt_large_flora >= 3 {
						tiles[idx] = TileType::TallGrass(0);
					}
					if amt_small_flora + amt_large_flora < 4 {
						tiles[idx] = floor;
					}
					if amt_of_water > 0 {
						tiles[idx] = TileType::TallGrass(0);
					}
				}
				if tiles[idx] == floor {
					if amt_large_flora >= 1 {
						tiles[idx] = TileType::ShortGrass(0);
					}
					if amt_small_flora >= 4 {
						tiles[idx] = TileType::ShortGrass(0);
					}
					if amt_small_flora > 0 && amt_of_water > 0 {
						tiles[idx] = TileType::ShortGrass(0);
					} 
				}
			// Mushrooms	
			} else if small_variant == TileType::SmallMushroom {
				if tiles[idx] == TileType::SmallMushroom {
					if amt_small_flora + amt_large_flora > 3 {
						tiles[idx] = TileType::LargeMushroom;
					}
					if amt_small_flora + amt_large_flora < 3 {
						tiles[idx] = floor;
					}
				}
			if tiles[idx] == floor {
					if amt_large_flora >= 1 {
						tiles[idx] = TileType::SmallMushroom;
					} 
				}
			}
		}
	}

	if small_variant == TileType::ShortGrass(0) {
		let shore_regions = get_all_regions(width, height, TileType::ShallowWater, tiles);

		let mut best_distance = 0;
		let mut possible_connection_found: bool;

		for x in 1..width {
			for y in 1..height {
				let idx = x+y*width;
				possible_connection_found = false;
				let current_type = tiles[idx];
				if current_type == small_variant || current_type == large_variant {
					for region in shore_regions.clone() {
						for shore_tile in region.tiles {
							let distance = ((shore_tile.0 as i32 - x as i32).pow(2) + (shore_tile.1 as i32 - y as i32).pow(2)) as f64;
							let distance = distance.sqrt() as i32 + 1;

							if distance < best_distance || !possible_connection_found {
								best_distance = distance;
								possible_connection_found = true;

								if distance < 10 {
									if current_type == TileType::ShortGrass(0) {
										tiles[idx] = TileType::ShortGrass(distance);
									} else if current_type == TileType::TallGrass(0) {
										tiles[idx] = TileType::TallGrass(distance);
									}
								}
							}	
						}
					}
				}
			}
		}
	}
}
/// Performs a cellular generation on a type of foilage. And calculates how far each grass tile is from water
/// Panics if the given flora_type is not actually foliage.
Performs a cellular generation on a type of foilage. And calculates how far each grass tile is from water
Panics if the given flora_type is not actually foliage.
Performs a cellular generation on a type of foilage . And calculates how far each grass tile is from water Panics if the given flora_type is not actually foliage .
pub fn grow (width : usize, height : usize, tiles: &mut Vec<TileType>, flora_type: TileType, floor : TileType) {
	use super::map::tile::{small_foliage_variant, large_foliage_variant};
	info!("Growing...");
	let large_variant = large_foliage_variant(flora_type);
	let small_variant = small_foliage_variant(flora_type);
	for x in 1..width-1 {
		for y in 1..height-1 {
			let amt_small_flora = get_surrounding_neighbor_count(width, height, tiles, small_variant, x as i32, y as i32);
			let amt_large_flora = get_surrounding_neighbor_count(width, height, tiles, large_variant, x as i32, y as i32);
			let idx = x+y*width;
			//Grass
			if small_variant == TileType::ShortGrass(0) {
				let amt_of_water = get_surrounding_neighbor_count(width, height, tiles, TileType::ShallowWater, x as i32, y as i32);
				if tiles[idx] == TileType::ShortGrass(0) {	
					if amt_small_flora + amt_large_flora >= 3 {
						tiles[idx] = TileType::TallGrass(0);
					}
					if amt_small_flora + amt_large_flora < 4 {
						tiles[idx] = floor;
					}
					if amt_of_water > 0 {
						tiles[idx] = TileType::TallGrass(0);
					}
				}
				if tiles[idx] == floor {
					if amt_large_flora >= 1 {
						tiles[idx] = TileType::ShortGrass(0);
					}
					if amt_small_flora >= 4 {
						tiles[idx] = TileType::ShortGrass(0);
					}
					if amt_small_flora > 0 && amt_of_water > 0 {
						tiles[idx] = TileType::ShortGrass(0);
					} 
				}
			// Mushrooms	
			} else if small_variant == TileType::SmallMushroom {
				if tiles[idx] == TileType::SmallMushroom {
					if amt_small_flora + amt_large_flora > 3 {
						tiles[idx] = TileType::LargeMushroom;
					}
					if amt_small_flora + amt_large_flora < 3 {
						tiles[idx] = floor;
					}
				}
			if tiles[idx] == floor {
					if amt_large_flora >= 1 {
						tiles[idx] = TileType::SmallMushroom;
					} 
				}
			}
		}
	}
	if small_variant == TileType::ShortGrass(0) {
		let shore_regions = get_all_regions(width, height, TileType::ShallowWater, tiles);
		let mut best_distance = 0;
		let mut possible_connection_found: bool;
		for x in 1..width {
			for y in 1..height {
				let idx = x+y*width;
				possible_connection_found = false;
				let current_type = tiles[idx];
				if current_type == small_variant || current_type == large_variant {
					for region in shore_regions.clone() {
						for shore_tile in region.tiles {
							let distance = ((shore_tile.0 as i32 - x as i32).pow(2) + (shore_tile.1 as i32 - y as i32).pow(2)) as f64;
							let distance = distance.sqrt() as i32 + 1;
							if distance < best_distance || !possible_connection_found {
								best_distance = distance;
								possible_connection_found = true;
								if distance < 10 {
									if current_type == TileType::ShortGrass(0) {
										tiles[idx] = TileType::ShortGrass(distance);
									} else if current_type == TileType::TallGrass(0) {
										tiles[idx] = TileType::TallGrass(distance);
									}
								}
							}	
						}
					}
				}
			}
		}
	}
}
pub fn grow ( width : usize , height : usize , tiles : & mut Vec < TileType > , flora_type : TileType , floor : TileType ) { use super :: map :: tile :: { small_foliage_variant , large_foliage_variant } ; info ! ( " " ) ; let large_variant = large_foliage_variant ( flora_type ) ; let small_variant = small_foliage_variant ( flora_type ) ; for x in 1 .. width - 1 { for y in 1 .. height - 1 { let amt_small_flora = get_surrounding_neighbor_count ( width , height , tiles , small_variant , x as i32 , y as i32 ) ; let amt_large_flora = get_surrounding_neighbor_count ( width , height , tiles , large_variant , x as i32 , y as i32 ) ; let idx = x + y * width ; //Grass if small_variant == TileType :: ShortGrass ( 0 ) { let amt_of_water = get_surrounding_neighbor_count ( width , height , tiles , TileType :: ShallowWater , x as i32 , y as i32 ) ; if tiles [ idx ] == TileType :: ShortGrass ( 0 ) { if amt_small_flora + amt_large_flora >= 3 { tiles [ idx ] = TileType :: TallGrass ( 0 ) ; } if amt_small_flora + amt_large_flora < 4 { tiles [ idx ] = floor ; } if amt_of_water > 0 { tiles [ idx ] = TileType :: TallGrass ( 0 ) ; } } if tiles [ idx ] == floor { if amt_large_flora >= 1 { tiles [ idx ] = TileType :: ShortGrass ( 0 ) ; } if amt_small_flora >= 4 { tiles [ idx ] = TileType :: ShortGrass ( 0 ) ; } if amt_small_flora > 0 && amt_of_water > 0 { tiles [ idx ] = TileType :: ShortGrass ( 0 ) ; } } // Mushrooms	 } else if small_variant == TileType :: SmallMushroom { if tiles [ idx ] == TileType :: SmallMushroom { if amt_small_flora + amt_large_flora > 3 { tiles [ idx ] = TileType :: LargeMushroom ; } if amt_small_flora + amt_large_flora < 3 { tiles [ idx ] = floor ; } } if tiles [ idx ] == floor { if amt_large_flora >= 1 { tiles [ idx ] = TileType :: SmallMushroom ; } } } } } if small_variant == TileType :: ShortGrass ( 0 ) { let shore_regions = get_all_regions ( width , height , TileType :: ShallowWater , tiles ) ; let mut best_distance = 0 ; let mut possible_connection_found : bool ; for x in 1 .. width { for y in 1 .. height { let idx = x + y * width ; possible_connection_found = false ; let current_type = tiles [ idx ] ; if current_type == small_variant || current_type == large_variant { for region in shore_regions . clone ( ) { for shore_tile in region . tiles { let distance = ( ( shore_tile . 0 as i32 - x as i32 ) . pow ( 2 ) + ( shore_tile . 1 as i32 - y as i32 ) . pow ( 2 ) ) as f64 ; let distance = distance . sqrt ( ) as i32 + 1 ; if distance < best_distance || ! possible_connection_found { best_distance = distance ; possible_connection_found = true ; if distance < 10 { if current_type == TileType :: ShortGrass ( 0 ) { tiles [ idx ] = TileType :: ShortGrass ( distance ) ; } else if current_type == TileType :: TallGrass ( 0 ) { tiles [ idx ] = TileType :: TallGrass ( distance ) ; } } } } } } } } } }
Performs a cellular generation on a type of foilage.
Performs a cellular generation on a type of foilage .
width
usize
height
usize
tiles
&mut Vec<TileType>
flora_type
TileType
floor
TileType
width
usize
height
usize
tiles
&mut Vec<TileType>
flora_type
TileType
floor
TileType