Add forest types

This commit is contained in:
Tangent Wantwight 2024-01-13 13:49:20 -05:00
parent 9b56235de8
commit 780458f88f
2 changed files with 78 additions and 12 deletions

View file

@ -49,8 +49,32 @@ export const BIG_BEACH: LobeGeneratorConstructor = (
}; };
}; };
/** form forested zone */ /** form forested zone wherever available */
export const FOREST_LOBE: LobeGeneratorConstructor = 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) => () => { (islands: IslandGrid, basePos: number) => () => {
const islandTiles = islands.floodSearch(basePos, (tile) => tile > WATER); 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); const beachTiles = islandTiles.filter((pos) => islands.data[pos] == BEACH);
islands.dropWithin(beachTiles); islands.dropWithin(beachTiles);
// expand forest // locate & expand central forest edge
const forestLobe = islands.floodSearch(basePos, (tile) => tile > BEACH); const forestLobe = islands.floodSearch(basePos, (tile) => tile > BEACH);
const forestTiles = forestLobe.filter( const forestTiles = forestLobe.filter(
(pos) => islands.data[pos] == LIGHT_FOREST (pos) => islands.data[pos] == LIGHT_FOREST
); );
islands.dropWithin(forestTiles); islands.dropWithin(forestTiles);
islands.dropWithin(forestTiles); islands.dropWithin(forestTiles);
islands.dropWithin(forestTiles);
return true; 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 */ /** form low-lying beach with eroded sections */
export const ERODED_LOBE: LobeGeneratorConstructor = export const ERODED_BEACH: LobeGeneratorConstructor =
(islands: IslandGrid, basePos: number) => () => { (islands: IslandGrid, basePos: number) => () => {
const islandTiles = islands.floodSearch(basePos, (tile) => tile > WATER); const islandTiles = islands.floodSearch(basePos, (tile) => tile > WATER);
@ -97,11 +149,20 @@ export const NO_ISLAND: LobeGeneratorConstructor =
return true; 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 = [ export const ALL_ISLANDS = [
BIG_MOUNTAIN, BIG_MOUNTAIN,
SMALL_BEACH, SMALL_BEACH,
BIG_BEACH, BIG_BEACH,
FOREST_LOBE, SCATTERED_FOREST,
ERODED_LOBE, CONTIGUOUS_FOREST,
HILLY_FOREST,
ERODED_BEACH,
]; ];

View file

@ -3,8 +3,11 @@ import { BEACH, ICECAP } from "./data";
import { import {
ALL_ISLANDS, ALL_ISLANDS,
BIG_ISLANDS, BIG_ISLANDS,
GREEN_ISLANDS,
LobeGenerator, LobeGenerator,
NO_ISLAND, NO_ISLAND,
ROCKY_ISLANDS,
SMALL_ISLANDS,
} from "./generators"; } from "./generators";
export class IslandGrid { export class IslandGrid {
@ -21,16 +24,18 @@ export class IslandGrid {
const islandBag = this.shuffle([ const islandBag = this.shuffle([
this.choose(BIG_ISLANDS), this.choose(BIG_ISLANDS),
this.choose(BIG_ISLANDS), this.choose(ROCKY_ISLANDS),
this.choose(ALL_ISLANDS), this.choose(GREEN_ISLANDS),
this.choose(ALL_ISLANDS), this.choose(SMALL_ISLANDS),
this.choose(ALL_ISLANDS), this.choose(SMALL_ISLANDS),
this.choose(SMALL_ISLANDS),
this.choose(ALL_ISLANDS), this.choose(ALL_ISLANDS),
NO_ISLAND, NO_ISLAND,
NO_ISLAND, NO_ISLAND,
NO_ISLAND, NO_ISLAND,
NO_ISLAND, NO_ISLAND,
NO_ISLAND, NO_ISLAND,
NO_ISLAND,
]); ]);
const islandCount = islandBag.length; const islandCount = islandBag.length;