Randomize lobe types
This commit is contained in:
parent
4fc076d80c
commit
f1c9d9ef07
2 changed files with 16 additions and 11 deletions
|
@ -72,3 +72,6 @@ export const ERODED_LOBE: LobeGeneratorConstructor =
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const BIG_ISLANDS = [BIG_MOUNTAIN];
|
||||||
|
export const ALL_ISLANDS = [BIG_MOUNTAIN, BEACH_LOBE, FOREST_LOBE, ERODED_LOBE];
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
import { Prng, mulberry32 } from "../lib/prng";
|
import { Prng, mulberry32 } from "../lib/prng";
|
||||||
import { BEACH, ICECAP, LIGHT_FOREST, MOUNTAIN, WATER } from "./data";
|
import { BEACH, ICECAP } from "./data";
|
||||||
import {
|
import { ALL_ISLANDS, BIG_ISLANDS, LobeGenerator } from "./generators";
|
||||||
BEACH_LOBE,
|
|
||||||
BIG_MOUNTAIN,
|
|
||||||
FOREST_LOBE,
|
|
||||||
LobeGenerator,
|
|
||||||
} from "./generators";
|
|
||||||
|
|
||||||
export class IslandGrid {
|
export class IslandGrid {
|
||||||
data: number[];
|
data: number[];
|
||||||
|
@ -19,9 +14,9 @@ export class IslandGrid {
|
||||||
this.data = Array(width * height).fill(0);
|
this.data = Array(width * height).fill(0);
|
||||||
this.rng = mulberry32(seed);
|
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(
|
this.generators.push(
|
||||||
FOREST_LOBE(
|
this.choose(ALL_ISLANDS)(
|
||||||
this,
|
this,
|
||||||
this.xy(
|
this.xy(
|
||||||
(width >> 1) + (this.rng() % 48) - 24,
|
(width >> 1) + (this.rng() % 48) - 24,
|
||||||
|
@ -30,7 +25,7 @@ export class IslandGrid {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
this.generators.push(
|
this.generators.push(
|
||||||
BEACH_LOBE(
|
this.choose(ALL_ISLANDS)(
|
||||||
this,
|
this,
|
||||||
this.xy(
|
this.xy(
|
||||||
(width >> 1) + (this.rng() % 48) - 24,
|
(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[]) {
|
public dropWithin(tiles: number[]) {
|
||||||
if (tiles.length > 0) {
|
if (tiles.length > 0) {
|
||||||
this.drop(tiles[this.rng() % tiles.length]);
|
this.drop(this.choose(tiles));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue