Randomize lobe types

This commit is contained in:
Tangent Wantwight 2024-01-13 12:19:17 -05:00
parent 4fc076d80c
commit f1c9d9ef07
2 changed files with 16 additions and 11 deletions

View File

@ -72,3 +72,6 @@ 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];

View File

@ -1,11 +1,6 @@
import { Prng, mulberry32 } from "../lib/prng";
import { BEACH, ICECAP, LIGHT_FOREST, MOUNTAIN, WATER } from "./data";
import {
BEACH_LOBE,
BIG_MOUNTAIN,
FOREST_LOBE,
LobeGenerator,
} from "./generators";
import { BEACH, ICECAP } from "./data";
import { ALL_ISLANDS, BIG_ISLANDS, LobeGenerator } from "./generators";
export class IslandGrid {
data: number[];
@ -19,9 +14,9 @@ export class IslandGrid {
this.data = Array(width * height).fill(0);
this.rng = mulberry32(seed);
this.generators.push(BIG_MOUNTAIN(this, this.data.length >> 1));
this.generators.push(this.choose(BIG_ISLANDS)(this, this.data.length >> 1));
this.generators.push(
FOREST_LOBE(
this.choose(ALL_ISLANDS)(
this,
this.xy(
(width >> 1) + (this.rng() % 48) - 24,
@ -30,7 +25,7 @@ export class IslandGrid {
)
);
this.generators.push(
BEACH_LOBE(
this.choose(ALL_ISLANDS)(
this,
this.xy(
(width >> 1) + (this.rng() % 48) - 24,
@ -119,9 +114,16 @@ export class IslandGrid {
}
}
public choose<T>(list: T[]) {
if (list.length == 0) {
throw new Error("Picking from empty list");
}
return list[this.rng() % list.length];
}
public dropWithin(tiles: number[]) {
if (tiles.length > 0) {
this.drop(tiles[this.rng() % tiles.length]);
this.drop(this.choose(tiles));
}
}