From 780458f88f57da7272e72d5c088897092a6172a2 Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Sat, 13 Jan 2024 13:49:20 -0500 Subject: [PATCH] Add forest types --- island/generators.ts | 77 +++++++++++++++++++++++++++++++++++++++----- island/grid.ts | 13 +++++--- 2 files changed, 78 insertions(+), 12 deletions(-) diff --git a/island/generators.ts b/island/generators.ts index fc89887..9352278 100644 --- a/island/generators.ts +++ b/island/generators.ts @@ -49,8 +49,32 @@ export const BIG_BEACH: LobeGeneratorConstructor = ( }; }; -/** form forested zone */ -export const FOREST_LOBE: LobeGeneratorConstructor = +/** form forested zone wherever available */ +export const SCATTERED_FOREST: LobeGeneratorConstructor = + (islands: IslandGrid, basePos: number) => () => { + const islandTiles = islands.floodSearch(basePos, (tile) => tile > WATER); + + // grow shore + const shoreTiles = islandTiles.filter((pos) => islands.data[pos] == WATER); + islands.dropWithin(shoreTiles); + + // seed beach + const beachTiles = islandTiles.filter((pos) => islands.data[pos] == BEACH); + islands.dropWithin(beachTiles); + islands.dropWithin(beachTiles); + + // expand forest + const forestLobe = islands.floodSearch(basePos, (tile) => tile > WATER); + const forestTiles = forestLobe.filter( + (pos) => islands.data[pos] == LIGHT_FOREST + ); + islands.dropWithin(forestTiles); + + return true; + }; + +/** form forested zone that tries to grow as one mass */ +export const CONTIGUOUS_FOREST: LobeGeneratorConstructor = (islands: IslandGrid, basePos: number) => () => { const islandTiles = islands.floodSearch(basePos, (tile) => tile > WATER); @@ -62,20 +86,48 @@ export const FOREST_LOBE: LobeGeneratorConstructor = const beachTiles = islandTiles.filter((pos) => islands.data[pos] == BEACH); islands.dropWithin(beachTiles); - // expand forest + // locate & expand central forest edge const forestLobe = islands.floodSearch(basePos, (tile) => tile > BEACH); const forestTiles = forestLobe.filter( (pos) => islands.data[pos] == LIGHT_FOREST ); islands.dropWithin(forestTiles); islands.dropWithin(forestTiles); - islands.dropWithin(forestTiles); return true; }; +/** form forested zone that can raise additional peaks */ +export const HILLY_FOREST: LobeGeneratorConstructor = + (islands: IslandGrid, basePos: number) => () => { + const islandTiles = islands.floodSearch(basePos, (tile) => tile > WATER); + + // grow shore + const shoreTiles = islandTiles.filter((pos) => islands.data[pos] == WATER); + islands.dropWithin(shoreTiles); + + // seed beach + const beachTiles = islandTiles.filter((pos) => islands.data[pos] == BEACH); + islands.dropWithin(beachTiles); + + // locate central forest + const centralForest = islands.floodSearch(basePos, (tile) => tile > BEACH); + islands.dropWithin(centralForest); + + // expand edge + const edgeTiles = centralForest.filter( + (pos) => islands.data[pos] == LIGHT_FOREST + ); + islands.dropWithin(edgeTiles); + + const hillTiles = centralForest.filter( + (pos) => islands.data[pos] >= MOUNTAIN + ); + return hillTiles.length > 0; + }; + /** form low-lying beach with eroded sections */ -export const ERODED_LOBE: LobeGeneratorConstructor = +export const ERODED_BEACH: LobeGeneratorConstructor = (islands: IslandGrid, basePos: number) => () => { const islandTiles = islands.floodSearch(basePos, (tile) => tile > WATER); @@ -97,11 +149,20 @@ export const NO_ISLAND: LobeGeneratorConstructor = return true; }; -export const BIG_ISLANDS = [BIG_MOUNTAIN, BIG_BEACH]; +export const BIG_ISLANDS = [BIG_MOUNTAIN, BIG_BEACH, HILLY_FOREST]; +export const ROCKY_ISLANDS = [BIG_MOUNTAIN, HILLY_FOREST]; +export const GREEN_ISLANDS = [ + SCATTERED_FOREST, + CONTIGUOUS_FOREST, + HILLY_FOREST, +]; +export const SMALL_ISLANDS = [SMALL_BEACH, SCATTERED_FOREST, ERODED_BEACH]; export const ALL_ISLANDS = [ BIG_MOUNTAIN, SMALL_BEACH, BIG_BEACH, - FOREST_LOBE, - ERODED_LOBE, + SCATTERED_FOREST, + CONTIGUOUS_FOREST, + HILLY_FOREST, + ERODED_BEACH, ]; diff --git a/island/grid.ts b/island/grid.ts index 4a548db..0360224 100644 --- a/island/grid.ts +++ b/island/grid.ts @@ -3,8 +3,11 @@ import { BEACH, ICECAP } from "./data"; import { ALL_ISLANDS, BIG_ISLANDS, + GREEN_ISLANDS, LobeGenerator, NO_ISLAND, + ROCKY_ISLANDS, + SMALL_ISLANDS, } from "./generators"; export class IslandGrid { @@ -21,16 +24,18 @@ export class IslandGrid { const islandBag = this.shuffle([ this.choose(BIG_ISLANDS), - this.choose(BIG_ISLANDS), - this.choose(ALL_ISLANDS), - this.choose(ALL_ISLANDS), - this.choose(ALL_ISLANDS), + this.choose(ROCKY_ISLANDS), + this.choose(GREEN_ISLANDS), + this.choose(SMALL_ISLANDS), + this.choose(SMALL_ISLANDS), + this.choose(SMALL_ISLANDS), this.choose(ALL_ISLANDS), NO_ISLAND, NO_ISLAND, NO_ISLAND, NO_ISLAND, NO_ISLAND, + NO_ISLAND, ]); const islandCount = islandBag.length;