From aaa165013e7b26220240c220735aaf0bbdd286db Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Sat, 13 Jan 2024 12:27:40 -0500 Subject: [PATCH] Add big beach --- island/generators.ts | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/island/generators.ts b/island/generators.ts index baf7495..5c0b884 100644 --- a/island/generators.ts +++ b/island/generators.ts @@ -21,7 +21,7 @@ export const BIG_MOUNTAIN: LobeGeneratorConstructor = }; /** form low-lying beach */ -export const BEACH_LOBE: LobeGeneratorConstructor = +export const SMALL_BEACH: LobeGeneratorConstructor = (islands: IslandGrid, basePos: number) => () => { const islandTiles = islands.floodSearch(basePos, (tile) => tile > WATER); @@ -31,6 +31,24 @@ export const BEACH_LOBE: LobeGeneratorConstructor = return true; }; +/** form low-lying beach that meets another island */ +export const BIG_BEACH: LobeGeneratorConstructor = ( + islands: IslandGrid, + basePos: number +) => { + let dropped = 0; + return () => { + const islandTiles = islands.floodSearch(basePos, (tile) => tile > WATER); + + const shoreTiles = islandTiles.filter((pos) => islands.data[pos] == WATER); + islands.dropWithin(shoreTiles); + dropped++; + + const landTiles = islandTiles.filter((pos) => islands.data[pos] > WATER); + return landTiles.length > dropped; + }; +}; + /** form forested zone */ export const FOREST_LOBE: LobeGeneratorConstructor = (islands: IslandGrid, basePos: number) => () => { @@ -73,5 +91,10 @@ export const ERODED_LOBE: LobeGeneratorConstructor = return true; }; -export const BIG_ISLANDS = [BIG_MOUNTAIN]; -export const ALL_ISLANDS = [BIG_MOUNTAIN, BEACH_LOBE, FOREST_LOBE, ERODED_LOBE]; +export const BIG_ISLANDS = [BIG_BEACH, BIG_MOUNTAIN]; +export const ALL_ISLANDS = [ + BIG_MOUNTAIN, + SMALL_BEACH, + FOREST_LOBE, + ERODED_LOBE, +];